Update ooo320-m1
[ooovba.git] / sw / source / core / text / pormulti.hxx
blob54395bf5c6500760bc708609b7d77abf0b392275
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: pormulti.hxx,v $
10 * $Revision: 1.26.112.1 $
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 _PORMULTI_HXX
31 #define _PORMULTI_HXX
33 #include "porlay.hxx"
34 #include "porexp.hxx"
36 class SwTxtFormatInfo;
37 class SwFldPortion;
38 class SwTxtCursor;
39 class SwLineLayout;
40 class SwTxtPaintInfo;
41 class SwTxtAttr;
42 class SfxPoolItem;
43 class SwFont;
45 /*-----------------02.02.01 15:01-------------------
46 * SwMultiCreator is a small structur to create a multiportion.
47 * It contains the kind of multiportion and a textattribute
48 * or a poolitem.
49 * The GetMultiCreator-function fills this structur and
50 * the Ctor of the SwMultiPortion uses it.
51 * --------------------------------------------------*/
53 #define SW_MC_DOUBLE 0
54 #define SW_MC_RUBY 1
55 #define SW_MC_ROTATE 2
56 #define SW_MC_BIDI 3
58 struct SwMultiCreator
60 const SwTxtAttr* pAttr;
61 const SfxPoolItem* pItem;
62 BYTE nId;
63 BYTE nLevel;
66 /*-----------------25.10.00 16:19-------------------
67 * A two-line-portion (SwMultiPortion) could have surrounding brackets,
68 * in this case the structur SwBracket will be used.
69 * --------------------------------------------------*/
71 struct SwBracket
73 xub_StrLen nStart; // Start of text attribute determins the font
74 KSHORT nAscent; // Ascent of the brackets
75 KSHORT nHeight; // Height of them
76 KSHORT nPreWidth; // Width of the opening bracket
77 KSHORT nPostWidth; // Width of the closing bracket
78 sal_Unicode cPre; // Initial character, e.g. '('
79 sal_Unicode cPost; // Final character, e.g. ')'
80 BYTE nPreScript; // Script of the initial character
81 BYTE nPostScript; // Script of the final character
84 /*-----------------16.10.00 12:45-------------------
85 * The SwMultiPortion is line portion inside a line portion,
86 * it's a group of portions,
87 * e.g. a double line portion in a line
88 * or phonetics (ruby)
89 * or combined characters
90 * or a rotated portion.
91 * --------------------------------------------------*/
93 class SwMultiPortion : public SwLinePortion
95 SwLineLayout aRoot; // One or more lines
96 SwFldPortion *pFldRest; // Field rest from the previous line
97 sal_Bool bTab1 :1; // First line tabulator
98 sal_Bool bTab2 :1; // Second line includes tabulator
99 sal_Bool bDouble :1; // Double line
100 sal_Bool bRuby :1; // Phonetics
101 sal_Bool bBidi :1;
102 sal_Bool bTop :1; // Phonetic position
103 sal_Bool bFormatted :1; // Already formatted
104 sal_Bool bFollowFld :1; // Field follow inside
105 sal_uInt8 nDirection:2; // Direction (0/90/180/270 degrees)
106 sal_Bool bFlyInCntnt:1; // Fly as character inside
107 protected:
108 SwMultiPortion( xub_StrLen nEnd ) : pFldRest( 0 ), bTab1( sal_False ),
109 bTab2( sal_False ), bDouble( sal_False ), bRuby( sal_False ),
110 bBidi( sal_False ), bFormatted( sal_False ), bFollowFld( sal_False ),
111 nDirection( 0 ), bFlyInCntnt( sal_False )
112 { SetWhichPor( POR_MULTI ); SetLen( nEnd ); }
113 inline void SetDouble() { bDouble = sal_True; }
114 inline void SetRuby() { bRuby = sal_True; }
115 inline void SetBidi() { bBidi = sal_True; }
116 inline void SetTop( sal_Bool bNew ) { bTop = bNew; }
117 inline void SetTab1( sal_Bool bNew ) { bTab1 = bNew; }
118 inline void SetTab2( sal_Bool bNew ) { bTab2 = bNew; }
119 inline void SetDirection( sal_uInt8 nNew ) { nDirection = nNew; }
120 inline sal_Bool GetTab1() const { return bTab1; }
121 inline sal_Bool GetTab2() const { return bTab2; }
122 public:
123 ~SwMultiPortion();
124 const SwLineLayout& GetRoot() const { return aRoot; }
125 SwLineLayout& GetRoot() { return aRoot; }
126 SwFldPortion* GetFldRest() { return pFldRest; }
127 void SetFldRest( SwFldPortion* pNew ) { pFldRest = pNew; }
129 inline sal_Bool HasTabulator() const { return bTab1 || bTab2; }
130 inline sal_Bool IsFormatted() const { return bFormatted; }
131 inline void SetFormatted() { bFormatted = sal_True; }
132 inline sal_Bool IsFollowFld() const { return bFollowFld; }
133 inline void SetFollowFld() { bFollowFld = sal_True; }
134 inline sal_Bool HasFlyInCntnt() const { return bFlyInCntnt; }
135 inline void SetFlyInCntnt( sal_Bool bNew ) { bFlyInCntnt = bNew; }
136 inline sal_Bool IsDouble() const { return bDouble; }
137 inline sal_Bool IsRuby() const { return bRuby; }
138 inline sal_Bool IsBidi() const { return bBidi; }
139 inline sal_Bool OnTop() const { return bTop; }
140 void ActualizeTabulator();
142 virtual void Paint( const SwTxtPaintInfo &rInf ) const;
143 virtual long CalcSpacing( long nSpaceAdd, const SwTxtSizeInfo &rInf ) const;
144 virtual sal_Bool ChgSpaceAdd( SwLineLayout* pCurr, long nSpaceAdd ) const;
146 // Summarize the internal lines to calculate the (external) size
147 void CalcSize( SwTxtFormatter& rLine, SwTxtFormatInfo &rInf );
149 inline sal_Bool HasBrackets() const;
150 inline sal_Bool HasRotation() const { return 0 != (1 & nDirection); }
151 inline sal_Bool IsRevers() const { return 0 != (2 & nDirection); }
152 inline sal_uInt8 GetDirection() const { return nDirection; }
153 inline USHORT GetFontRotation() const
154 { return ( HasRotation() ? ( IsRevers() ? 2700 : 900 ) : 0 ); }
156 // Accessibility: pass information about this portion to the PortionHandler
157 virtual void HandlePortion( SwPortionHandler& rPH ) const;
159 OUTPUT_OPERATOR
162 class SwDoubleLinePortion : public SwMultiPortion
164 SwBracket* pBracket; // Surrounding brackets
165 SwTwips nLineDiff; // Difference of the width of the both lines
166 xub_StrLen nBlank1; // Number of blanks in the first line
167 xub_StrLen nBlank2; // Number of blanks in the second line
168 public:
169 SwDoubleLinePortion( SwDoubleLinePortion& rDouble, xub_StrLen nEnd );
170 SwDoubleLinePortion( const SwMultiCreator& rCreate, xub_StrLen nEnd );
171 ~SwDoubleLinePortion();
173 inline SwBracket* GetBrackets() const { return pBracket; }
174 void SetBrackets( const SwDoubleLinePortion& rDouble );
175 void PaintBracket( SwTxtPaintInfo& rInf, long nSpaceAdd, sal_Bool bOpen ) const;
176 void FormatBrackets( SwTxtFormatInfo &rInf, SwTwips& nMaxWidth );
177 inline KSHORT PreWidth() const { return pBracket->nPreWidth; };
178 inline KSHORT PostWidth() const { return pBracket->nPostWidth; }
179 inline void ClearBrackets()
180 { pBracket->nPreWidth = pBracket->nPostWidth=0; Width( 0 ); }
181 inline KSHORT BracketWidth(){ return PreWidth() + PostWidth(); }
183 void CalcBlanks( SwTxtFormatInfo &rInf );
184 static void ResetSpaceAdd( SwLineLayout* pCurr );
185 inline SwTwips GetLineDiff() const { return nLineDiff; }
186 inline xub_StrLen GetSpaceCnt() const
187 { return ( nLineDiff < 0 ) ? nBlank2 : nBlank1; }
188 inline xub_StrLen GetSmallerSpaceCnt() const
189 { return ( nLineDiff < 0 ) ? nBlank1 : nBlank2; }
190 inline xub_StrLen GetBlank1() const { return nBlank1; }
191 inline xub_StrLen GetBlank2() const { return nBlank2; }
193 virtual long CalcSpacing( long nSpaceAdd, const SwTxtSizeInfo &rInf ) const;
194 virtual sal_Bool ChgSpaceAdd( SwLineLayout* pCurr, long nSpaceAdd ) const;
197 class SwRubyPortion : public SwMultiPortion
199 xub_StrLen nRubyOffset;
200 USHORT nAdjustment;
201 void _Adjust( SwTxtFormatInfo &rInf);
202 public:
203 SwRubyPortion( const SwRubyPortion& rRuby, xub_StrLen nEnd );
205 SwRubyPortion( const SwMultiCreator& rCreate, const SwFont& rFnt,
206 const IDocumentSettingAccess& rIDocumentSettingAccess,
207 xub_StrLen nEnd, xub_StrLen nOffs,
208 const sal_Bool* pForceRubyPos );
210 void CalcRubyOffset();
211 inline void Adjust( SwTxtFormatInfo &rInf )
212 { if(nAdjustment && GetRoot().GetNext()) _Adjust(rInf); }
213 inline USHORT GetAdjustment() const { return nAdjustment; }
214 inline xub_StrLen GetRubyOffset() const { return nRubyOffset; }
217 class SwRotatedPortion : public SwMultiPortion
219 public:
220 SwRotatedPortion( xub_StrLen nEnd, sal_uInt8 nDir = 1 )
221 : SwMultiPortion( nEnd ) { SetDirection( nDir ); }
222 SwRotatedPortion( const SwMultiCreator& rCreate, xub_StrLen nEnd,
223 sal_Bool bRTL );
226 class SwBidiPortion : public SwMultiPortion
228 BYTE nLevel;
230 public:
231 SwBidiPortion( xub_StrLen nEnd, BYTE nLv );
233 inline BYTE GetLevel() const { return nLevel; }
234 // Get number of blanks for justified alignment
235 xub_StrLen GetSpaceCnt( const SwTxtSizeInfo &rInf ) const;
236 // Calculates extra spacing based on number of blanks
237 virtual long CalcSpacing( long nSpaceAdd, const SwTxtSizeInfo &rInf ) const;
238 // Manipulate the spacing array at pCurr
239 virtual sal_Bool ChgSpaceAdd( SwLineLayout* pCurr, long nSpaceAdd ) const;
242 // For cursor travelling in multiportions
244 class SwTxtCursorSave
246 SwTxtCursor* pTxtCrsr;
247 SwLineLayout* pCurr;
248 SwTwips nWidth;
249 xub_StrLen nStart;
250 BYTE nOldProp;
251 sal_Bool bSpaceChg;
252 public:
253 SwTxtCursorSave( SwTxtCursor* pTxtCursor, SwMultiPortion* pMulti,
254 SwTwips nY, USHORT& nX, xub_StrLen nCurrStart, long nSpaceAdd );
255 ~SwTxtCursorSave();
258 /*************************************************************************
259 * inline - Implementations
260 *************************************************************************/
262 inline sal_Bool SwMultiPortion::HasBrackets() const
264 return sal::static_int_cast< sal_Bool >( IsDouble() ?
265 0 != ((SwDoubleLinePortion*)this)->GetBrackets() :
266 sal_False );
269 CLASSIO( SwMultiPortion )
271 #endif