1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: node.hxx,v $
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 ************************************************************************/
36 #ifndef _DYNARY_HXX //autogen
37 #include <tools/dynary.hxx>
47 #define ATTR_BOLD 0x0001
48 #define ATTR_ITALIC 0x0002
50 #define FNTSIZ_ABSOLUT 1
52 #define FNTSIZ_MINUS 3
53 #define FNTSIZ_MULTIPLY 4
54 #define FNTSIZ_DIVIDE 5
56 // flags to interdict respective status changes
57 #define FLG_FONT 0x0001
58 #define FLG_SIZE 0x0002
59 #define FLG_BOLD 0x0004
60 #define FLG_ITALIC 0x0008
61 #define FLG_COLOR 0x0010
62 #define FLG_VISIBLE 0x0020
63 #define FLG_HORALIGN 0x0040
66 extern SmFormat
*pActiveFormat
;
71 DECLARE_DYNARRAY(SmNodeArray
, SmNode
*)//STRIP008 ;
73 ////////////////////////////////////////////////////////////////////////////////
75 enum SmScaleMode
{ SCALE_NONE
, SCALE_WIDTH
, SCALE_HEIGHT
};
79 NTABLE
, NBRACE
, NBRACEBODY
, NOPER
, NALIGN
,
80 NATTRIBUT
, NFONT
, NUNHOR
, NBINHOR
, NBINVER
,
81 NBINDIAGONAL
, NSUBSUP
, NMATRIX
, NPLACE
, NTEXT
,
82 NSPECIAL
, NGLYPH_SPECIAL
, NMATH
, NBLANK
, NERROR
,
83 NLINE
, NEXPRESSION
, NPOLYLINE
, NROOT
, NROOTSYMBOL
,
84 NRECTANGLE
, NVERTICAL_BRACE
88 ////////////////////////////////////////////////////////////////////////////////
91 class SmNode
: public SmRect
97 SmScaleMode eScaleMode
;
98 RectHorAlign eRectHorAlign
;
104 SmNode(SmNodeType eNodeType
, const SmToken
&rNodeToken
);
106 // index in accessible text -1 if not (yet) applicable
112 virtual BOOL
IsVisible() const;
114 virtual USHORT
GetNumSubNodes() const;
115 virtual SmNode
* GetSubNode(USHORT nIndex
);
116 const SmNode
* GetSubNode(USHORT nIndex
) const
118 return ((SmNode
*) this)->GetSubNode(nIndex
);
121 virtual SmNode
* GetLeftMost();
122 const SmNode
* GetLeftMost() const
124 return ((SmNode
*) this)->GetLeftMost();
127 USHORT
& Flags() { return nFlags
; }
128 USHORT
& Attributes() { return nAttributes
; }
130 BOOL
IsDebug() const { return bIsDebug
; }
131 BOOL
IsPhantom() const { return bIsPhantom
; }
132 void SetPhantom(BOOL bIsPhantom
);
133 void SetColor(const Color
&rColor
);
135 void SetAttribut(USHORT nAttrib
);
136 void ClearAttribut(USHORT nAttrib
);
138 const SmFace
& GetFont() const { return aFace
; };
139 SmFace
& GetFont() { return aFace
; };
141 void SetFont(const SmFace
&rFace
);
142 void SetFontSize(const Fraction
&rRelSize
, USHORT nType
);
143 void SetSize(const Fraction
&rScale
);
145 virtual void Prepare(const SmFormat
&rFormat
, const SmDocShell
&rDocShell
);
146 virtual void PrepareAttributes();
149 void SetRectHorAlign(RectHorAlign eHorAlign
, BOOL bApplyToSubTree
= TRUE
);
150 RectHorAlign
GetRectHorAlign() const { return eRectHorAlign
; }
152 const SmRect
& GetRect() const { return *this; }
153 SmRect
& GetRect() { return *this; }
155 virtual void Move(const Point
&rPosition
);
156 void MoveTo(const Point
&rPosition
) { Move(rPosition
- GetTopLeft()); }
157 virtual void Arrange(const OutputDevice
&rDev
, const SmFormat
&rFormat
);
158 virtual void CreateTextFromNode(String
&rText
);
160 virtual void Draw(OutputDevice
&rDev
, const Point
&rPosition
) const;
163 USHORT
GetRow() const { return (USHORT
)aNodeToken
.nRow
; }
164 USHORT
GetColumn() const { return (USHORT
)aNodeToken
.nCol
; }
166 SmScaleMode
GetScaleMode() const { return eScaleMode
; }
167 void SetScaleMode(SmScaleMode eMode
) { eScaleMode
= eMode
; }
169 virtual void AdaptToX(const OutputDevice
&rDev
, ULONG nWidth
);
170 virtual void AdaptToY(const OutputDevice
&rDev
, ULONG nHeight
);
172 SmNodeType
GetType() const { return eType
; }
173 const SmToken
& GetToken() const { return aNodeToken
; }
175 const SmNode
* FindTokenAt(USHORT nRow
, USHORT nCol
) const;
179 ////////////////////////////////////////////////////////////////////////////////
181 class SmStructureNode
;
183 DECLARE_DYNARRAY(SmStructureNodeArray
, SmStructureNode
*)//STRIP008 ;
185 class SmStructureNode
: public SmNode
187 SmNodeArray aSubNodes
;
190 SmStructureNode(SmNodeType eNodeType
, const SmToken
&rNodeToken
)
191 : SmNode(eNodeType
, rNodeToken
)
195 SmStructureNode( const SmStructureNode
&rNode
);
196 virtual ~SmStructureNode();
198 virtual BOOL
IsVisible() const;
200 virtual USHORT
GetNumSubNodes() const;
201 void SetNumSubNodes(USHORT nSize
) { aSubNodes
.SetSize(nSize
); }
203 virtual SmNode
* GetSubNode(USHORT nIndex
);
204 void SetSubNodes(SmNode
*pFirst
, SmNode
*pSecond
,
205 SmNode
*pThird
= NULL
);
206 void SetSubNodes(const SmNodeArray
&rNodeArray
);
208 virtual SmStructureNode
& operator = ( const SmStructureNode
&rNode
);
213 ////////////////////////////////////////////////////////////////////////////////
216 class SmVisibleNode
: public SmNode
219 SmVisibleNode(SmNodeType eNodeType
, const SmToken
&rNodeToken
)
220 : SmNode(eNodeType
, rNodeToken
)
225 virtual BOOL
IsVisible() const;
226 virtual USHORT
GetNumSubNodes() const;
227 virtual SmNode
* GetSubNode(USHORT nIndex
);
231 ////////////////////////////////////////////////////////////////////////////////
234 class SmGraphicNode
: public SmVisibleNode
237 SmGraphicNode(SmNodeType eNodeType
, const SmToken
&rNodeToken
)
238 : SmVisibleNode(eNodeType
, rNodeToken
)
246 ////////////////////////////////////////////////////////////////////////////////
249 class SmRectangleNode
: public SmGraphicNode
254 SmRectangleNode(const SmToken
&rNodeToken
)
255 : SmGraphicNode(NRECTANGLE
, rNodeToken
)
258 virtual void AdaptToX(const OutputDevice
&rDev
, ULONG nWidth
);
259 virtual void AdaptToY(const OutputDevice
&rDev
, ULONG nHeight
);
261 virtual void Arrange(const OutputDevice
&rDev
, const SmFormat
&rFormat
);
262 virtual void Draw(OutputDevice
&rDev
, const Point
&rPosition
) const;
266 ////////////////////////////////////////////////////////////////////////////////
269 class SmPolyLineNode
: public SmGraphicNode
276 SmPolyLineNode(const SmToken
&rNodeToken
);
278 long GetWidth() const { return nWidth
; }
280 virtual void AdaptToX(const OutputDevice
&rDev
, ULONG nWidth
);
281 virtual void AdaptToY(const OutputDevice
&rDev
, ULONG nHeight
);
283 virtual void Arrange(const OutputDevice
&rDev
, const SmFormat
&rFormat
);
284 virtual void Draw(OutputDevice
&rDev
, const Point
&rPosition
) const;
288 ////////////////////////////////////////////////////////////////////////////////
291 class SmTextNode
: public SmVisibleNode
297 SmTextNode(SmNodeType eNodeType
, const SmToken
&rNodeToken
, USHORT nFontDescP
)
298 : SmVisibleNode(eNodeType
, rNodeToken
)
300 nFontDesc
= nFontDescP
;
304 SmTextNode(const SmToken
&rNodeToken
, USHORT nFontDescP
)
305 : SmVisibleNode(NTEXT
, rNodeToken
)
307 nFontDesc
= nFontDescP
;
311 USHORT
GetFontDesc() const { return nFontDesc
; }
312 void SetText(const XubString
&rText
) { aText
= rText
; }
313 const XubString
& GetText() const { return aText
; }
315 virtual void Prepare(const SmFormat
&rFormat
, const SmDocShell
&rDocShell
);
316 virtual void Arrange(const OutputDevice
&rDev
, const SmFormat
&rFormat
);
318 virtual void Draw(OutputDevice
&rDev
, const Point
&rPosition
) const;
323 ////////////////////////////////////////////////////////////////////////////////
326 class SmSpecialNode
: public SmTextNode
329 SmSpecialNode(SmNodeType eNodeType
, const SmToken
&rNodeToken
, USHORT nFontDesc
)
330 : SmTextNode(eNodeType
, rNodeToken
, nFontDesc
)
334 SmSpecialNode(const SmToken
&rNodeToken
)
335 : SmTextNode(NSPECIAL
, rNodeToken
, FNT_MATH
) //! default Font nicht immer richtig
338 virtual void Prepare(const SmFormat
&rFormat
, const SmDocShell
&rDocShell
);
339 virtual void Arrange(const OutputDevice
&rDev
, const SmFormat
&rFormat
);
340 virtual void Draw(OutputDevice
&rDev
, const Point
&rPosition
) const;
344 ////////////////////////////////////////////////////////////////////////////////
347 class SmGlyphSpecialNode
: public SmSpecialNode
350 SmGlyphSpecialNode(const SmToken
&rNodeToken
)
351 : SmSpecialNode(NGLYPH_SPECIAL
, rNodeToken
, FNT_MATH
)
354 virtual void Arrange(const OutputDevice
&rDev
, const SmFormat
&rFormat
);
358 ////////////////////////////////////////////////////////////////////////////////
361 class SmMathSymbolNode
: public SmSpecialNode
364 SmMathSymbolNode(SmNodeType eNodeType
, const SmToken
&rNodeToken
)
365 : SmSpecialNode(eNodeType
, rNodeToken
, FNT_MATH
)
367 xub_Unicode cChar
= GetToken().cMathChar
;
368 if ((xub_Unicode
) '\0' != cChar
)
373 SmMathSymbolNode(const SmToken
&rNodeToken
);
375 virtual void AdaptToX(const OutputDevice
&rDev
, ULONG nWidth
);
376 virtual void AdaptToY(const OutputDevice
&rDev
, ULONG nHeight
);
378 virtual void Prepare(const SmFormat
&rFormat
, const SmDocShell
&rDocShell
);
379 virtual void Arrange(const OutputDevice
&rDev
, const SmFormat
&rFormat
);
383 ////////////////////////////////////////////////////////////////////////////////
386 class SmRootSymbolNode
: public SmMathSymbolNode
388 ULONG nBodyWidth
; // width of body (argument) of root sign
391 SmRootSymbolNode(const SmToken
&rNodeToken
)
392 : SmMathSymbolNode(NROOTSYMBOL
, rNodeToken
)
395 virtual void AdaptToX(const OutputDevice
&rDev
, ULONG nWidth
);
396 virtual void AdaptToY(const OutputDevice
&rDev
, ULONG nHeight
);
398 virtual void Draw(OutputDevice
&rDev
, const Point
&rPosition
) const;
402 ////////////////////////////////////////////////////////////////////////////////
405 class SmPlaceNode
: public SmMathSymbolNode
408 SmPlaceNode(const SmToken
&rNodeToken
)
409 : SmMathSymbolNode(NPLACE
, rNodeToken
)
411 SetText((xub_Unicode
) MS_PLACE
);
414 virtual void Prepare(const SmFormat
&rFormat
, const SmDocShell
&rDocShell
);
415 virtual void Arrange(const OutputDevice
&rDev
, const SmFormat
&rFormat
);
419 ////////////////////////////////////////////////////////////////////////////////
422 class SmErrorNode
: public SmMathSymbolNode
425 SmErrorNode(SmParseError eError
, const SmToken
&rNodeToken
)
426 : SmMathSymbolNode(NERROR
, rNodeToken
)
428 SetText((xub_Unicode
) MS_ERROR
);
431 virtual void Prepare(const SmFormat
&rFormat
, const SmDocShell
&rDocShell
);
432 virtual void Arrange(const OutputDevice
&rDev
, const SmFormat
&rFormat
);
436 ////////////////////////////////////////////////////////////////////////////////
439 class SmTableNode
: public SmStructureNode
442 SmTableNode(const SmToken
&rNodeToken
)
443 : SmStructureNode(NTABLE
, rNodeToken
)
446 virtual SmNode
* GetLeftMost();
448 virtual void Arrange(const OutputDevice
&rDev
, const SmFormat
&rFormat
);
452 ////////////////////////////////////////////////////////////////////////////////
455 class SmLineNode
: public SmStructureNode
458 SmLineNode(SmNodeType eNodeType
, const SmToken
&rNodeToken
)
459 : SmStructureNode(eNodeType
, rNodeToken
)
463 SmLineNode(const SmToken
&rNodeToken
)
464 : SmStructureNode(NLINE
, rNodeToken
)
467 virtual void Prepare(const SmFormat
&rFormat
, const SmDocShell
&rDocShell
);
468 virtual void Arrange(const OutputDevice
&rDev
, const SmFormat
&rFormat
);
472 ////////////////////////////////////////////////////////////////////////////////
475 class SmExpressionNode
: public SmLineNode
478 SmExpressionNode(const SmToken
&rNodeToken
)
479 : SmLineNode(NEXPRESSION
, rNodeToken
)
482 virtual void Arrange(const OutputDevice
&rDev
, const SmFormat
&rFormat
);
486 ////////////////////////////////////////////////////////////////////////////////
489 class SmUnHorNode
: public SmStructureNode
492 SmUnHorNode(const SmToken
&rNodeToken
)
493 : SmStructureNode(NUNHOR
, rNodeToken
)
498 virtual void Arrange(const OutputDevice
&rDev
, const SmFormat
&rFormat
);
502 ////////////////////////////////////////////////////////////////////////////////
505 class SmRootNode
: public SmStructureNode
508 void GetHeightVerOffset(const SmRect
&rRect
,
509 long &rHeight
, long &rVerOffset
) const;
510 Point
GetExtraPos(const SmRect
&rRootSymbol
, const SmRect
&rExtra
) const;
513 SmRootNode(const SmToken
&rNodeToken
)
514 : SmStructureNode(NROOT
, rNodeToken
)
519 virtual void Arrange(const OutputDevice
&rDev
, const SmFormat
&rFormat
);
523 ////////////////////////////////////////////////////////////////////////////////
526 class SmBinHorNode
: public SmStructureNode
529 SmBinHorNode(const SmToken
&rNodeToken
)
530 : SmStructureNode(NBINHOR
, rNodeToken
)
535 virtual void Arrange(const OutputDevice
&rDev
, const SmFormat
&rFormat
);
539 ////////////////////////////////////////////////////////////////////////////////
542 class SmBinVerNode
: public SmStructureNode
545 SmBinVerNode(const SmToken
&rNodeToken
)
546 : SmStructureNode(NBINVER
, rNodeToken
)
551 virtual SmNode
* GetLeftMost();
553 virtual void Arrange(const OutputDevice
&rDev
, const SmFormat
&rFormat
);
557 ////////////////////////////////////////////////////////////////////////////////
560 class SmBinDiagonalNode
: public SmStructureNode
564 void GetOperPosSize(Point
&rPos
, Size
&rSize
,
565 const Point
&rDiagPoint
, double fAngleDeg
) const;
568 SmBinDiagonalNode(const SmToken
&rNodeToken
);
570 BOOL
IsAscending() const { return bAscending
; }
571 void SetAscending(BOOL bVal
) { bAscending
= bVal
; }
573 virtual void Arrange(const OutputDevice
&rDev
, const SmFormat
&rFormat
);
577 ////////////////////////////////////////////////////////////////////////////////
580 // enums used to index sub-/supscripts in the 'aSubNodes' array
582 // See graphic for positions at char:
595 { CSUB
, CSUP
, RSUB
, RSUP
, LSUB
, LSUP
598 // numbers of entries in the above enum (that is: the number of possible
600 #define SUBSUP_NUM_ENTRIES 6
603 class SmSubSupNode
: public SmStructureNode
608 SmSubSupNode(const SmToken
&rNodeToken
)
609 : SmStructureNode(NSUBSUP
, rNodeToken
)
611 SetNumSubNodes(1 + SUBSUP_NUM_ENTRIES
);
615 SmNode
* GetBody() { return GetSubNode(0); }
616 const SmNode
* GetBody() const
618 return ((SmSubSupNode
*) this)->GetBody();
621 void SetUseLimits(BOOL bVal
) { bUseLimits
= bVal
; }
622 BOOL
IsUseLimits() const { return bUseLimits
; };
624 SmNode
* GetSubSup(SmSubSup eSubSup
) { return GetSubNode(1 + eSubSup
); };
626 virtual void Arrange(const OutputDevice
&rDev
, const SmFormat
&rFormat
);
631 ////////////////////////////////////////////////////////////////////////////////
634 class SmBraceNode
: public SmStructureNode
637 SmBraceNode(const SmToken
&rNodeToken
)
638 : SmStructureNode(NBRACE
, rNodeToken
)
643 virtual void Arrange(const OutputDevice
&rDev
, const SmFormat
&rFormat
);
647 ////////////////////////////////////////////////////////////////////////////////
650 class SmBracebodyNode
: public SmStructureNode
655 inline SmBracebodyNode(const SmToken
&rNodeToken
);
657 virtual void Arrange(const OutputDevice
&rDev
, const SmFormat
&rFormat
);
658 long GetBodyHeight() const { return nBodyHeight
; }
662 inline SmBracebodyNode::SmBracebodyNode(const SmToken
&rNodeToken
) :
663 SmStructureNode(NBRACEBODY
, rNodeToken
)
669 ////////////////////////////////////////////////////////////////////////////////
672 class SmVerticalBraceNode
: public SmStructureNode
675 inline SmVerticalBraceNode(const SmToken
&rNodeToken
);
677 virtual void Arrange(const OutputDevice
&rDev
, const SmFormat
&rFormat
);
681 inline SmVerticalBraceNode::SmVerticalBraceNode(const SmToken
&rNodeToken
) :
682 SmStructureNode(NVERTICAL_BRACE
, rNodeToken
)
688 ////////////////////////////////////////////////////////////////////////////////
691 class SmOperNode
: public SmStructureNode
694 SmOperNode(const SmToken
&rNodeToken
)
695 : SmStructureNode(NOPER
, rNodeToken
)
700 SmNode
* GetSymbol();
701 const SmNode
* GetSymbol() const
703 return ((SmOperNode
*) this)->GetSymbol();
706 long CalcSymbolHeight(const SmNode
&rSymbol
, const SmFormat
&rFormat
) const;
708 virtual void Arrange(const OutputDevice
&rDev
, const SmFormat
&rFormat
);
712 ////////////////////////////////////////////////////////////////////////////////
715 class SmAlignNode
: public SmStructureNode
718 SmAlignNode(const SmToken
&rNodeToken
)
719 : SmStructureNode(NALIGN
, rNodeToken
)
722 virtual void Arrange(const OutputDevice
&rDev
, const SmFormat
&rFormat
);
726 ////////////////////////////////////////////////////////////////////////////////
729 class SmAttributNode
: public SmStructureNode
732 SmAttributNode(const SmToken
&rNodeToken
)
733 : SmStructureNode(NATTRIBUT
, rNodeToken
)
736 virtual void Arrange(const OutputDevice
&rDev
, const SmFormat
&rFormat
);
740 ////////////////////////////////////////////////////////////////////////////////
743 class SmFontNode
: public SmStructureNode
749 SmFontNode(const SmToken
&rNodeToken
)
750 : SmStructureNode(NFONT
, rNodeToken
)
752 nSizeType
= FNTSIZ_MULTIPLY
;
753 aFontSize
= Fraction(1L);
756 void SetSizeParameter(const Fraction
&rValue
, USHORT nType
);
757 const Fraction
& GetSizeParameter() const {return aFontSize
;}
758 const USHORT
& GetSizeType() const {return nSizeType
;}
760 virtual void Prepare(const SmFormat
&rFormat
, const SmDocShell
&rDocShell
);
761 virtual void Arrange(const OutputDevice
&rDev
, const SmFormat
&rFormat
);
765 ////////////////////////////////////////////////////////////////////////////////
768 class SmMatrixNode
: public SmStructureNode
774 SmMatrixNode(const SmToken
&rNodeToken
)
775 : SmStructureNode(NMATRIX
, rNodeToken
)
777 nNumRows
= nNumCols
= 0;
780 USHORT
GetNumRows() const {return nNumRows
;}
781 USHORT
GetNumCols() const {return nNumCols
;}
782 void SetRowCol(USHORT nMatrixRows
, USHORT nMatrixCols
);
784 virtual SmNode
* GetLeftMost();
786 virtual void Arrange(const OutputDevice
&rDev
, const SmFormat
&rFormat
);
790 ////////////////////////////////////////////////////////////////////////////////
793 class SmBlankNode
: public SmGraphicNode
798 SmBlankNode(const SmToken
&rNodeToken
)
799 : SmGraphicNode(NBLANK
, rNodeToken
)
804 void IncreaseBy(const SmToken
&rToken
);
805 void Clear() { nNum
= 0; }
807 virtual void Prepare(const SmFormat
&rFormat
, const SmDocShell
&rDocShell
);
808 virtual void Arrange(const OutputDevice
&rDev
, const SmFormat
&rFormat
);
812 ////////////////////////////////////////////////////////////////////////////////
814 } //namespace binfilter