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 ************************************************************************/
44 #define ATTR_BOLD 0x0001
45 #define ATTR_ITALIC 0x0002
47 #define FNTSIZ_ABSOLUT 1
49 #define FNTSIZ_MINUS 3
50 #define FNTSIZ_MULTIPLY 4
51 #define FNTSIZ_DIVIDE 5
53 // flags to interdict respective status changes
54 #define FLG_FONT 0x0001
55 #define FLG_SIZE 0x0002
56 #define FLG_BOLD 0x0004
57 #define FLG_ITALIC 0x0008
58 #define FLG_COLOR 0x0010
59 #define FLG_VISIBLE 0x0020
60 #define FLG_HORALIGN 0x0040
63 extern SmFormat
*pActiveFormat
;
67 class SmStructureNode
;
69 typedef std::vector
< SmNode
* > SmNodeArray
;
70 typedef std::vector
< SmStructureNode
* > SmStructureNodeArray
;
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 ToggleDebug() const;
152 void SetRectHorAlign(RectHorAlign eHorAlign
, BOOL bApplyToSubTree
= TRUE
);
153 RectHorAlign
GetRectHorAlign() const { return eRectHorAlign
; }
155 const SmRect
& GetRect() const { return *this; }
156 SmRect
& GetRect() { return *this; }
158 virtual void Move(const Point
&rPosition
);
159 void MoveTo(const Point
&rPosition
) { Move(rPosition
- GetTopLeft()); }
160 virtual void Arrange(const OutputDevice
&rDev
, const SmFormat
&rFormat
);
161 virtual void CreateTextFromNode(String
&rText
);
166 virtual void Draw(OutputDevice
&rDev
, const Point
&rPosition
) const;
168 virtual void GetAccessibleText( String
&rText
) const;
169 sal_Int32
GetAccessibleIndex() const { return nAccIndex
; }
170 const SmNode
* FindNodeWithAccessibleIndex(xub_StrLen nAccIndex
) const;
172 USHORT
GetRow() const { return (USHORT
)aNodeToken
.nRow
; }
173 USHORT
GetColumn() const { return (USHORT
)aNodeToken
.nCol
; }
175 SmScaleMode
GetScaleMode() const { return eScaleMode
; }
176 void SetScaleMode(SmScaleMode eMode
) { eScaleMode
= eMode
; }
178 virtual void AdaptToX(const OutputDevice
&rDev
, ULONG nWidth
);
179 virtual void AdaptToY(const OutputDevice
&rDev
, ULONG nHeight
);
181 SmNodeType
GetType() const { return eType
; }
182 const SmToken
& GetToken() const { return aNodeToken
; }
184 const SmNode
* FindTokenAt(USHORT nRow
, USHORT nCol
) const;
185 const SmNode
* FindRectClosestTo(const Point
&rPoint
) const;
189 ////////////////////////////////////////////////////////////////////////////////
192 class SmStructureNode
: public SmNode
194 SmNodeArray aSubNodes
;
197 SmStructureNode(SmNodeType eNodeType
, const SmToken
&rNodeToken
)
198 : SmNode(eNodeType
, rNodeToken
)
202 SmStructureNode( const SmStructureNode
&rNode
);
203 virtual ~SmStructureNode();
205 virtual BOOL
IsVisible() const;
207 virtual USHORT
GetNumSubNodes() const;
208 void SetNumSubNodes(USHORT nSize
) { aSubNodes
.resize(nSize
); }
210 using SmNode::GetSubNode
;
211 virtual SmNode
* GetSubNode(USHORT nIndex
);
212 void SetSubNodes(SmNode
*pFirst
, SmNode
*pSecond
, SmNode
*pThird
= NULL
);
213 void SetSubNodes(const SmNodeArray
&rNodeArray
);
215 virtual SmStructureNode
& operator = ( const SmStructureNode
&rNode
);
217 virtual void GetAccessibleText( String
&rText
) const;
221 ////////////////////////////////////////////////////////////////////////////////
224 class SmVisibleNode
: public SmNode
227 SmVisibleNode(SmNodeType eNodeType
, const SmToken
&rNodeToken
)
228 : SmNode(eNodeType
, rNodeToken
)
233 virtual BOOL
IsVisible() const;
234 virtual USHORT
GetNumSubNodes() const;
235 using SmNode::GetSubNode
;
236 virtual SmNode
* GetSubNode(USHORT nIndex
);
240 ////////////////////////////////////////////////////////////////////////////////
243 class SmGraphicNode
: public SmVisibleNode
246 SmGraphicNode(SmNodeType eNodeType
, const SmToken
&rNodeToken
)
247 : SmVisibleNode(eNodeType
, rNodeToken
)
252 virtual void GetAccessibleText( String
&rText
) const;
256 ////////////////////////////////////////////////////////////////////////////////
259 class SmRectangleNode
: public SmGraphicNode
264 SmRectangleNode(const SmToken
&rNodeToken
)
265 : SmGraphicNode(NRECTANGLE
, rNodeToken
)
268 virtual void AdaptToX(const OutputDevice
&rDev
, ULONG nWidth
);
269 virtual void AdaptToY(const OutputDevice
&rDev
, ULONG nHeight
);
271 virtual void Arrange(const OutputDevice
&rDev
, const SmFormat
&rFormat
);
276 virtual void Draw(OutputDevice
&rDev
, const Point
&rPosition
) const;
278 void CreateTextFromNode(String
&rText
);
282 ////////////////////////////////////////////////////////////////////////////////
285 class SmPolyLineNode
: public SmGraphicNode
292 SmPolyLineNode(const SmToken
&rNodeToken
);
294 long GetWidth() const { return nWidth
; }
296 virtual void AdaptToX(const OutputDevice
&rDev
, ULONG nWidth
);
297 virtual void AdaptToY(const OutputDevice
&rDev
, ULONG nHeight
);
299 virtual void Arrange(const OutputDevice
&rDev
, const SmFormat
&rFormat
);
304 virtual void Draw(OutputDevice
&rDev
, const Point
&rPosition
) const;
308 ////////////////////////////////////////////////////////////////////////////////
311 class SmTextNode
: public SmVisibleNode
317 SmTextNode(SmNodeType eNodeType
, const SmToken
&rNodeToken
, USHORT nFontDescP
)
318 : SmVisibleNode(eNodeType
, rNodeToken
)
320 nFontDesc
= nFontDescP
;
324 SmTextNode(const SmToken
&rNodeToken
, USHORT nFontDescP
)
325 : SmVisibleNode(NTEXT
, rNodeToken
)
327 nFontDesc
= nFontDescP
;
331 USHORT
GetFontDesc() const { return nFontDesc
; }
332 void SetText(const XubString
&rText
) { aText
= rText
; }
333 const XubString
& GetText() const { return aText
; }
335 virtual void Prepare(const SmFormat
&rFormat
, const SmDocShell
&rDocShell
);
336 virtual void Arrange(const OutputDevice
&rDev
, const SmFormat
&rFormat
);
337 virtual void CreateTextFromNode(String
&rText
);
342 virtual void Draw(OutputDevice
&rDev
, const Point
&rPosition
) const;
344 virtual void GetAccessibleText( String
&rText
) const;
348 ////////////////////////////////////////////////////////////////////////////////
351 class SmSpecialNode
: public SmTextNode
354 SmSpecialNode(SmNodeType eNodeType
, const SmToken
&rNodeToken
, USHORT _nFontDesc
)
355 : SmTextNode(eNodeType
, rNodeToken
, _nFontDesc
)
359 SmSpecialNode(const SmToken
&rNodeToken
)
360 : SmTextNode(NSPECIAL
, rNodeToken
, FNT_MATH
) //! default Font nicht immer richtig
363 virtual void Prepare(const SmFormat
&rFormat
, const SmDocShell
&rDocShell
);
364 virtual void Arrange(const OutputDevice
&rDev
, const SmFormat
&rFormat
);
369 virtual void Draw(OutputDevice
&rDev
, const Point
&rPosition
) const;
373 ////////////////////////////////////////////////////////////////////////////////
376 class SmGlyphSpecialNode
: public SmSpecialNode
379 SmGlyphSpecialNode(const SmToken
&rNodeToken
)
380 : SmSpecialNode(NGLYPH_SPECIAL
, rNodeToken
, FNT_MATH
)
383 virtual void Arrange(const OutputDevice
&rDev
, const SmFormat
&rFormat
);
387 ////////////////////////////////////////////////////////////////////////////////
390 class SmMathSymbolNode
: public SmSpecialNode
393 SmMathSymbolNode(SmNodeType eNodeType
, const SmToken
&rNodeToken
)
394 : SmSpecialNode(eNodeType
, rNodeToken
, FNT_MATH
)
396 xub_Unicode cChar
= GetToken().cMathChar
;
397 if ((xub_Unicode
) '\0' != cChar
)
402 SmMathSymbolNode(const SmToken
&rNodeToken
);
404 virtual void AdaptToX(const OutputDevice
&rDev
, ULONG nWidth
);
405 virtual void AdaptToY(const OutputDevice
&rDev
, ULONG nHeight
);
407 virtual void Prepare(const SmFormat
&rFormat
, const SmDocShell
&rDocShell
);
408 virtual void Arrange(const OutputDevice
&rDev
, const SmFormat
&rFormat
);
409 void CreateTextFromNode(String
&rText
);
413 ////////////////////////////////////////////////////////////////////////////////
416 class SmRootSymbolNode
: public SmMathSymbolNode
418 ULONG nBodyWidth
; // width of body (argument) of root sign
421 SmRootSymbolNode(const SmToken
&rNodeToken
)
422 : SmMathSymbolNode(NROOTSYMBOL
, rNodeToken
)
425 virtual void AdaptToX(const OutputDevice
&rDev
, ULONG nWidth
);
426 virtual void AdaptToY(const OutputDevice
&rDev
, ULONG nHeight
);
431 virtual void Draw(OutputDevice
&rDev
, const Point
&rPosition
) const;
435 ////////////////////////////////////////////////////////////////////////////////
438 class SmPlaceNode
: public SmMathSymbolNode
441 SmPlaceNode(const SmToken
&rNodeToken
)
442 : SmMathSymbolNode(NPLACE
, rNodeToken
)
446 virtual void Prepare(const SmFormat
&rFormat
, const SmDocShell
&rDocShell
);
447 virtual void Arrange(const OutputDevice
&rDev
, const SmFormat
&rFormat
);
451 ////////////////////////////////////////////////////////////////////////////////
454 class SmErrorNode
: public SmMathSymbolNode
457 SmErrorNode(SmParseError
/*eError*/, const SmToken
&rNodeToken
)
458 : SmMathSymbolNode(NERROR
, rNodeToken
)
460 SetText((xub_Unicode
) MS_ERROR
);
463 virtual void Prepare(const SmFormat
&rFormat
, const SmDocShell
&rDocShell
);
464 virtual void Arrange(const OutputDevice
&rDev
, const SmFormat
&rFormat
);
468 ////////////////////////////////////////////////////////////////////////////////
471 class SmTableNode
: public SmStructureNode
474 SmTableNode(const SmToken
&rNodeToken
)
475 : SmStructureNode(NTABLE
, rNodeToken
)
478 using SmNode::GetLeftMost
;
479 virtual SmNode
* GetLeftMost();
481 virtual void Arrange(const OutputDevice
&rDev
, const SmFormat
&rFormat
);
485 ////////////////////////////////////////////////////////////////////////////////
488 class SmLineNode
: public SmStructureNode
491 SmLineNode(SmNodeType eNodeType
, const SmToken
&rNodeToken
)
492 : SmStructureNode(eNodeType
, rNodeToken
)
496 SmLineNode(const SmToken
&rNodeToken
)
497 : SmStructureNode(NLINE
, rNodeToken
)
500 virtual void Prepare(const SmFormat
&rFormat
, const SmDocShell
&rDocShell
);
501 virtual void Arrange(const OutputDevice
&rDev
, const SmFormat
&rFormat
);
505 ////////////////////////////////////////////////////////////////////////////////
508 class SmExpressionNode
: public SmLineNode
511 SmExpressionNode(const SmToken
&rNodeToken
)
512 : SmLineNode(NEXPRESSION
, rNodeToken
)
515 virtual void Arrange(const OutputDevice
&rDev
, const SmFormat
&rFormat
);
516 void CreateTextFromNode(String
&rText
);
520 ////////////////////////////////////////////////////////////////////////////////
523 class SmUnHorNode
: public SmStructureNode
526 SmUnHorNode(const SmToken
&rNodeToken
)
527 : SmStructureNode(NUNHOR
, rNodeToken
)
532 virtual void Arrange(const OutputDevice
&rDev
, const SmFormat
&rFormat
);
536 ////////////////////////////////////////////////////////////////////////////////
539 class SmRootNode
: public SmStructureNode
542 void GetHeightVerOffset(const SmRect
&rRect
,
543 long &rHeight
, long &rVerOffset
) const;
544 Point
GetExtraPos(const SmRect
&rRootSymbol
, const SmRect
&rExtra
) const;
547 SmRootNode(const SmToken
&rNodeToken
)
548 : SmStructureNode(NROOT
, rNodeToken
)
553 virtual void Arrange(const OutputDevice
&rDev
, const SmFormat
&rFormat
);
554 void CreateTextFromNode(String
&rText
);
558 ////////////////////////////////////////////////////////////////////////////////
561 class SmBinHorNode
: public SmStructureNode
564 SmBinHorNode(const SmToken
&rNodeToken
)
565 : SmStructureNode(NBINHOR
, rNodeToken
)
570 virtual void Arrange(const OutputDevice
&rDev
, const SmFormat
&rFormat
);
574 ////////////////////////////////////////////////////////////////////////////////
577 class SmBinVerNode
: public SmStructureNode
580 SmBinVerNode(const SmToken
&rNodeToken
)
581 : SmStructureNode(NBINVER
, rNodeToken
)
586 using SmNode::GetLeftMost
;
587 virtual SmNode
* GetLeftMost();
589 virtual void Arrange(const OutputDevice
&rDev
, const SmFormat
&rFormat
);
590 void CreateTextFromNode(String
&rText
);
594 ////////////////////////////////////////////////////////////////////////////////
597 class SmBinDiagonalNode
: public SmStructureNode
601 void GetOperPosSize(Point
&rPos
, Size
&rSize
,
602 const Point
&rDiagPoint
, double fAngleDeg
) const;
605 SmBinDiagonalNode(const SmToken
&rNodeToken
);
607 BOOL
IsAscending() const { return bAscending
; }
608 void SetAscending(BOOL bVal
) { bAscending
= bVal
; }
610 virtual void Arrange(const OutputDevice
&rDev
, const SmFormat
&rFormat
);
614 ////////////////////////////////////////////////////////////////////////////////
617 // enums used to index sub-/supscripts in the 'aSubNodes' array
619 // See graphic for positions at char:
632 { CSUB
, CSUP
, RSUB
, RSUP
, LSUB
, LSUP
635 // numbers of entries in the above enum (that is: the number of possible
637 #define SUBSUP_NUM_ENTRIES 6
640 class SmSubSupNode
: public SmStructureNode
645 SmSubSupNode(const SmToken
&rNodeToken
)
646 : SmStructureNode(NSUBSUP
, rNodeToken
)
648 SetNumSubNodes(1 + SUBSUP_NUM_ENTRIES
);
652 SmNode
* GetBody() { return GetSubNode(0); }
653 const SmNode
* GetBody() const
655 return ((SmSubSupNode
*) this)->GetBody();
658 void SetUseLimits(BOOL bVal
) { bUseLimits
= bVal
; }
659 BOOL
IsUseLimits() const { return bUseLimits
; };
661 SmNode
* GetSubSup(SmSubSup eSubSup
) { return GetSubNode( sal::static_int_cast
< USHORT
>(1 + eSubSup
) ); };
663 virtual void Arrange(const OutputDevice
&rDev
, const SmFormat
&rFormat
);
664 void CreateTextFromNode(String
&rText
);
669 ////////////////////////////////////////////////////////////////////////////////
672 class SmBraceNode
: public SmStructureNode
675 SmBraceNode(const SmToken
&rNodeToken
)
676 : SmStructureNode(NBRACE
, rNodeToken
)
681 virtual void Arrange(const OutputDevice
&rDev
, const SmFormat
&rFormat
);
682 void CreateTextFromNode(String
&rText
);
686 ////////////////////////////////////////////////////////////////////////////////
689 class SmBracebodyNode
: public SmStructureNode
694 inline SmBracebodyNode(const SmToken
&rNodeToken
);
696 virtual void Arrange(const OutputDevice
&rDev
, const SmFormat
&rFormat
);
697 long GetBodyHeight() const { return nBodyHeight
; }
701 inline SmBracebodyNode::SmBracebodyNode(const SmToken
&rNodeToken
) :
702 SmStructureNode(NBRACEBODY
, rNodeToken
)
708 ////////////////////////////////////////////////////////////////////////////////
711 class SmVerticalBraceNode
: public SmStructureNode
714 inline SmVerticalBraceNode(const SmToken
&rNodeToken
);
716 virtual void Arrange(const OutputDevice
&rDev
, const SmFormat
&rFormat
);
720 inline SmVerticalBraceNode::SmVerticalBraceNode(const SmToken
&rNodeToken
) :
721 SmStructureNode(NVERTICAL_BRACE
, rNodeToken
)
727 ////////////////////////////////////////////////////////////////////////////////
730 class SmOperNode
: public SmStructureNode
733 SmOperNode(const SmToken
&rNodeToken
)
734 : SmStructureNode(NOPER
, rNodeToken
)
739 SmNode
* GetSymbol();
740 const SmNode
* GetSymbol() const
742 return ((SmOperNode
*) this)->GetSymbol();
745 long CalcSymbolHeight(const SmNode
&rSymbol
, const SmFormat
&rFormat
) const;
747 virtual void Arrange(const OutputDevice
&rDev
, const SmFormat
&rFormat
);
751 ////////////////////////////////////////////////////////////////////////////////
754 class SmAlignNode
: public SmStructureNode
757 SmAlignNode(const SmToken
&rNodeToken
)
758 : SmStructureNode(NALIGN
, rNodeToken
)
761 virtual void Arrange(const OutputDevice
&rDev
, const SmFormat
&rFormat
);
765 ////////////////////////////////////////////////////////////////////////////////
768 class SmAttributNode
: public SmStructureNode
771 SmAttributNode(const SmToken
&rNodeToken
)
772 : SmStructureNode(NATTRIBUT
, rNodeToken
)
775 virtual void Arrange(const OutputDevice
&rDev
, const SmFormat
&rFormat
);
776 void CreateTextFromNode(String
&rText
);
780 ////////////////////////////////////////////////////////////////////////////////
783 class SmFontNode
: public SmStructureNode
789 SmFontNode(const SmToken
&rNodeToken
)
790 : SmStructureNode(NFONT
, rNodeToken
)
792 nSizeType
= FNTSIZ_MULTIPLY
;
793 aFontSize
= Fraction(1L);
796 void SetSizeParameter(const Fraction
&rValue
, USHORT nType
);
797 const Fraction
& GetSizeParameter() const {return aFontSize
;}
798 const USHORT
& GetSizeType() const {return nSizeType
;}
800 virtual void Prepare(const SmFormat
&rFormat
, const SmDocShell
&rDocShell
);
801 virtual void Arrange(const OutputDevice
&rDev
, const SmFormat
&rFormat
);
802 void CreateTextFromNode(String
&rText
);
806 ////////////////////////////////////////////////////////////////////////////////
809 class SmMatrixNode
: public SmStructureNode
815 SmMatrixNode(const SmToken
&rNodeToken
)
816 : SmStructureNode(NMATRIX
, rNodeToken
)
818 nNumRows
= nNumCols
= 0;
821 USHORT
GetNumRows() const {return nNumRows
;}
822 USHORT
GetNumCols() const {return nNumCols
;}
823 void SetRowCol(USHORT nMatrixRows
, USHORT nMatrixCols
);
825 using SmNode::GetLeftMost
;
826 virtual SmNode
* GetLeftMost();
828 virtual void Arrange(const OutputDevice
&rDev
, const SmFormat
&rFormat
);
829 void CreateTextFromNode(String
&rText
);
833 ////////////////////////////////////////////////////////////////////////////////
836 class SmBlankNode
: public SmGraphicNode
841 SmBlankNode(const SmToken
&rNodeToken
)
842 : SmGraphicNode(NBLANK
, rNodeToken
)
847 void IncreaseBy(const SmToken
&rToken
);
848 void Clear() { nNum
= 0; }
850 virtual void Prepare(const SmFormat
&rFormat
, const SmDocShell
&rDocShell
);
851 virtual void Arrange(const OutputDevice
&rDev
, const SmFormat
&rFormat
);
855 ////////////////////////////////////////////////////////////////////////////////