merge the formfield patch from ooo-build
[ooovba.git] / binfilter / inc / bf_sch / chaxis.hxx
blob8b0b7139f9403e2d49474005f1911c347efa5e57
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: chaxis.hxx,v $
10 * $Revision: 1.7 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
30 #ifndef SCH_CHART_AXIS_HXX
31 #define SCH_CHART_AXIS_HXX
33 //STRIP008 class ChartModel;
34 //STRIP008 class SdrObject;
35 //STRIP008 class SdrObjList;
36 //STRIP008 class XPolygon;
37 //STRIP008 class SdrRectObj;
38 //STRIP008 class SchAxisObj;
40 #ifndef _SVX_CHRTITEM_HXX //autogen
41 #include <bf_svx/chrtitem.hxx>
42 #endif
43 #ifndef _SV_GEN_HXX //autogen
44 #include <tools/gen.hxx>
45 #endif
46 #ifndef _SFXITEMSET_HXX //autogen
47 #include <bf_svtools/itemset.hxx>
48 #endif
49 #ifndef _STREAM_HXX //autogen
50 #include <tools/stream.hxx>
51 #endif
52 #ifndef _SFXINTITEM_HXX //autogen
53 #include <bf_svtools/intitem.hxx>
54 #endif
56 #ifndef _COM_SUN_STAR_DRAWING_XSHAPE_HPP_
57 #include <com/sun/star/drawing/XShape.hpp>
58 #endif
60 #include "defines.hxx"
61 #include "schattr.hxx"
62 #include "float.h"
63 #include <math.h>
65 namespace binfilter {
67 class SvNumberFormatter;
68 class SvNumberFormatterIndexTable;
69 class ChartModel;
70 class SdrObject;
71 class SdrObjList;
72 class XPolygon;
73 class SdrRectObj;
74 class SchAxisObj;
76 #define CHAXIS_POS_A -1 //Top or Right (normale Position)
77 #define CHAXIS_POS_B -2 //Bottom or Left (Position der 2.Achse)
79 #define CHAXIS_MARK_BOTH 3 //eigentlich sind es flags....
80 #define CHAXIS_MARK_OUTER 2
81 #define CHAXIS_MARK_INNER 1
82 #define CHAXIS_MARK_NONE 0
83 #define CHAXIS_MARK_ASMAIN 4 //Flag indiziert, da?Helpticks wie mainticks ausgerichtete werden sollen
85 #define CHAXIS_AXIS_UNKNOWN 0
86 #define CHAXIS_AXIS_X 1
87 #define CHAXIS_AXIS_Y 2
88 #define CHAXIS_AXIS_Z 3
89 #define CHAXIS_AXIS_B 4 // secondary Y axis
90 #define CHAXIS_AXIS_A 5 // secondary X axis
92 class ChartAxis
94 protected:
96 BOOL mbInnerPos;
97 long mnInnerPos;
98 BOOL mbColText; // Texte aus Datenspalte statt per Numberformatter generieren
99 BOOL mbCenterText; // mbCenterText: FALSE -> Beschriftung wie z.B. Barchart, d.h. unter
100 // der ganzen Spalte, TRUE: wie z.B. Area, zentriert unter Datenpunkt
102 long mnMaxTextWidth;
104 long mnAlternateId;
105 long mbAlternativIdUsed;
107 //Statistik bzw. Daten in Prozent: Summe je Spalte der Elemente, die an der Achse skalieren
108 BOOL mbPercentCol;
109 BOOL mbTextOverlap;
110 double *mpTotal;
111 long mnTotalSize;
112 BOOL mbTotalActual;
113 BOOL mbTotalAlloc;
114 void ResizeTotal(long nSize);
115 void CreateTotal();
117 double *mpColStack;
118 BOOL mbColStackOK;
120 long mnUId;
121 BOOL mbShowDescr;
122 SfxItemSet* mpAllAxisAttr;
123 SvNumberFormatter* mpNumFormatter;
125 SdrObjList* mpAxisList;
126 SchAxisObj* mpAxisObj;
128 SdrObjList* mpMainGridList;
129 SdrObjList* mpHelpGridList;
130 SfxItemSet* mpMainGridAttr;
131 SfxItemSet* mpHelpGridAttr;
133 long mnIdMainGrid;
134 long mnIdHelpGrid;
136 SfxItemSet* mpGridAttr;
137 SfxItemSet* mpTextAttr;
139 Rectangle maRectA,maRectB;
141 long mnTicks;
142 long mnHelpTicks;
143 long mnTickLen;
144 long mnHelpTickLen;
145 long mnPos;
146 long mnTextPos;
147 BOOL mbSecondary;
149 BOOL mbStepValue;
150 BOOL mbValueDown;
152 void RecalcTextPos();
154 Size maMaxTextSize;
155 long meStackMode;
157 long mnId; //X,Y oder Z, (CHOBJID)
158 BOOL mbFlippedXY; //TRUE: X vertikal, Y horizontal; (entspricht in etwa bSwitchColRow...)
159 long mnPosition; //links/rechts bzw. oben/unten
161 BOOL mbRadial; //NetChart, evtl. einmal auch für PolarPlots
162 Rectangle maArea; //Dieser Bereich wird von den Achsen umschlossen
163 Rectangle maRefArea;
165 BOOL mbPercent;
167 SfxItemSet* mpAxisAttr;
168 ChartModel* mpModel;
170 //Elementare Groessen: Min,Max,Markierung,Ursprung
171 double mfMin;
172 double mfMax;
173 double mfStep;
174 double mfStepHelp;
175 double mfOrigin;
178 double mfDataBottom; //stacked Charts
179 double mfDataTop;
182 BOOL mbAutoMin;
183 BOOL mbAutoMax;
184 BOOL mbAutoOrigin;
186 BOOL mbAutoStep;
187 BOOL mbAutoStepHelp;
189 BOOL mbLogarithm;
191 SvxChartTextOrient meTextOrient;
193 void CalcMinMaxValue();
194 void SetDefaults();
196 long GetLength() const;
198 inline double GetRowError(long nRow);
199 inline BOOL IsDataOnAxis(long nRow);
201 void CreateTextAttr();
202 void InitColStacking(long nColCnt);
204 public:
207 long GetDescrWidth();
208 void SetColTextMode(BOOL bColText,BOOL bCenterText)
210 mbColText = bColText;
211 mbCenterText = bCenterText;
213 //Hilfsfunktion für X-Achse, nur in Create2DBackplane
214 void InsertHelpTick(long nPos) {InsertMark(nPos,mnHelpTickLen,mnHelpTicks);}
215 BOOL HasHelpTicks() {return mnHelpTicks!=0;}
217 BOOL AttachIfNoOwnData(const ChartAxis* pAxis);
219 void SetPercentMode(BOOL bPercentCol=TRUE)
221 if(mbPercentCol!=bPercentCol)
222 mbTotalActual=FALSE;
223 mbPercentCol=bPercentCol;
226 void IfNoDataLookAt(long nAlternateAxisId) { mnAlternateId = nAlternateAxisId; }
228 const Rectangle& GetArea() { return maRefArea; }
229 double StackColData(double fData,long nCol,long nColCnt);
231 inline double GetData(long nCol,long nRow);
232 double Data2Percent(double fData,long nCol,long nRow);
233 double GetTotal(long n);
235 void Update() { ReadAutoAttr(); ReadAttr(); }
236 void FillItemSet() { GetMembersAsAttr(*mpAxisAttr); }
238 BOOL IsVertical();
239 BOOL IsNegative() { return (mfMax <= 0.0 && mfMin < 0.0 ); }
241 // Stack stapelt den Wert an der entsprechenden Achse
242 // und gibt die Position (Start und Ende) relativ zum Koordinatensystem zurück
243 // Pair::A() für Top/Left, B() für Bottom/Right
244 Pair Stack(double fData,BOOL bConstrained=TRUE);//stacked Charts
245 void InitStacking() { mfDataBottom=mfDataTop=0.0; }
246 //void Create();
247 //void PreDestruct();
249 // Top/Right Position
250 long GetUpper(double fData,BOOL bConstrained=TRUE);
251 // Bottom/Left Position
252 long GetLower(double fData,BOOL bConstrained=TRUE);
254 long GetPos(double fData);
255 long GetPosOrigin() { return GetPos(mfOrigin); }
256 BOOL SetArea(const Rectangle& rRect);
257 void LoadMemberCompat(SvStream& rIn);
258 void StoreMemberCompat(SvStream& rOut) const;
260 ChartAxis(ChartModel* pModel,long nId,long nUid);
261 virtual ~ChartAxis();
263 BOOL IsOriginInRange() const;
266 double NumStepsMain();
268 void SetAttributes(const SfxItemSet &rAttr);
269 void SetAttributes(SfxItemSet *pSet);
270 SfxItemSet* GetItemSet() const { return mpAxisAttr; }
271 double GetMax() const { return mfMax; }
272 double GetMin() const { return mfMin; }
273 double GetStep() const { return mfStep; }
274 double GetOrigin() const { return mfOrigin; }
275 double GetHelpStep() const { return mfStepHelp; }
276 void SetMax(double f) { mfMax = f; }
277 void SetMin(double f) { mfMin = f; }
278 BOOL IsLogarithm() const { return mbLogarithm; }
279 /* Freischalten, wenn benötigt:
281 BOOL IsAutoMin() const {return mbAutoMin;}
282 BOOL IsAutoMax() const {return mbAutoMax;}
283 BOOL IsAutoOrigin()const {return mbAutoOrigin;}
285 void SetOrigin(double f); {mfOrigin=f;}
286 void SetStep(double f); {mfStep=f;}
287 void SetHelpStep(double f); {mfStepHelp=f;}
288 void SetLogarithmic(BOOL b) {mbLogarithm=b;}
289 void SetAutoMin(BOOL b) {mbAutoMin=b;}
290 void SetAutoMax(BOOL b) {mbAutoMax=b;}
291 void SetAutoOrigin(BOOL b) {mbAutoOrigin=b;}
293 void Initialise(const Rectangle &rRect,BOOL bFlippedXY=FALSE,long eStackmode=CHSTACK_NONE,BOOL bPercent=FALSE,BOOL bRadial=FALSE,BOOL bPercentCol=TRUE);
295 void VerifySteps();
296 void CalcValueSteps();
297 BOOL GetMinMaxFromData();
299 inline double CalcFact(const double fValue) const
301 if (fValue == DBL_MIN)
303 return DBL_MIN;
305 else if (mfMin == mfMax)
307 return 0.0;
309 else if (mbLogarithm)
311 double fVal = (fValue > 0.0) ? log10(fValue) : log10(mfMin);
312 return (fVal - log10(mfMin)) / (log10(mfMax) - log10(mfMin));
314 else
316 return (fValue - mfMin) / (mfMax - mfMin);
320 double CalcFactOrigin() { return CalcFact(mfOrigin); }
322 //ToDo: Zusammenfassen:
323 void ReadAutoAttr();
324 void ReadAttr();
326 inline BOOL IsVisible() const
328 return static_cast< const SfxBoolItem& >( mpAxisAttr->Get( SCHATTR_AXIS_SHOWAXIS ) ).GetValue();
330 inline BOOL HasDescription() const
332 // meaning should description be displayed, so necessary is IsVisible()
333 return static_cast< const SfxBoolItem& >( mpAxisAttr->Get( SCHATTR_AXIS_SHOWDESCR ) ).GetValue() &&
334 IsVisible();
337 void GetMembersAsAttr(SfxItemSet& rSet) const;
339 void InsertMark(long nPos,long nLen,long nWhichTicks);
340 UINT32 GetNumFormat() { return GetNumFormat( mbPercent ); }
341 UINT32 GetNumFormat(BOOL bPercent);
343 void GridLine(XPolygon& aLine,long nPos);
345 void ShowDescr(BOOL b);
346 void ShowAxis(BOOL b);
348 void DrawGrids();
349 void SetMainGrid(SdrObjList* pList,SfxItemSet*pAttr);
350 void SetHelpGrid(SdrObjList* pList,SfxItemSet*pAttr);
352 long CreateAxis();
353 void CreateAxis(const long nPos,BOOL bBorderAxis,BOOL bInnerAxis);
354 void CreateAxis(SdrObjList& rList,long nChObjId);
355 void SetAllAxisAttr(SfxItemSet *pSet) { mpAllAxisAttr = pSet; }
356 void SetNumberFormatter( SvNumberFormatter* pFormatter ) { mpNumFormatter = pFormatter; }
357 void SubtractDescrSize(Rectangle& rRect);
358 void SubtractDescrSize_X(Rectangle& rRect,const Rectangle& rOldRect); //X-Richtung ist leider etwas anders
359 void InitDescr_X();
360 void InitDescr(SvxChartTextOrient &rValueOrient,long nMaxTextWidth=-1);
361 void InitDescr();
363 Size CalcMaxTextSize(SvxChartTextOrient eOrient);
364 Size CalcMaxTextSize();
366 void CreateMarkDescr(const String& rString, long nPosition, Color *); // #60999# BM
367 void CreateMarkDescr(double fData,long nPosition);
368 void CreateMarkDescr(SdrRectObj *pTextObj,long nPosition);
369 void SetAxisList( SdrObjList *pList );
370 void SetGridAttrList(SfxItemSet* pList) { mpGridAttr = pList; }
371 void SetTextAttrList(SfxItemSet* pList) { mpTextAttr = pList; }
373 //nach Initialise und SetRefArea (ChartAxis) setzen!!!!!
374 //nPos ist entweder eine echte Position (bei Y-Achse der X Wert u.U.)
375 //oder ein define für Standardposition (CHAXIS_POS_A) bzw. sekundäre
376 //(CHAXIS_POS_B) Achse (= oben bzw. Rechts)
377 void SetPosition(long nPos);
378 //nDir ist Flag, kann sein CHAXIS_MARK_INNER und CHAXIS_MARK_OUTER (oder beides)
379 SdrObject *CreateMarks(long nPosition,long nLen,long nWhichTicks);
381 BOOL TranslateMergedNumFormat( SvNumberFormatterIndexTable* pTransTable );
382 long GetUniqueId() const { return mnUId; }
384 /** Converts a CHOBJID into an axis UId.
386 @return CHAXIS_AXIS_X, CHAXIS_AXIS_Y, CHAXIS_AXIS_Z, CHAXIS_AXIS_A or
387 CHAXIS_AXIS_B or CHAXIS_AXIS_UNKNOWN if nObjectId does not refer
388 to any valid axis object.
390 static long GetUniqueIdByObjectId( long nObjectId );
392 private:
394 @descr Calculate the size of the bounding box of a text string. The
395 size is measured with respect to the coordinate axes.
397 @param rAttr Attributes of the font to use.
398 @param aString The "typical" description.
400 @return Returns the size of the bounding box of the text.
402 Size CalcDescriptionSize (const SfxItemSet * rAttr,
403 const String & aString);
406 @descr Calculate the expected size of a "typical" description. The
407 size is measured along the axis. The axis orientation is taken
408 into account.
409 @precond CalcMinMaxValue() has to have been called already.
411 @param rAttr Attributes of the font to use.
413 @return Returns the size of the text projected onto the axis.
415 long int CalcTypicalDescriptionSize (const SfxItemSet * rAttr);
418 } //namespace binfilter
419 #endif