xref: /aoo41x/main/svtools/source/control/ruler.cxx (revision 5900e8ec)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_svtools.hxx"
26 
27 #include <string.h>
28 #include <tools/debug.hxx>
29 #include <vcl/svapp.hxx>
30 #include <tools/poly.hxx>
31 #include <vcl/i18nhelp.hxx>
32 
33 #define _SV_RULER_CXX
34 #include <svtools/ruler.hxx>
35 
36 // =======================================================================
37 
38 #define RULER_OFF           3
39 #define RULER_TEXTOFF       2
40 #define RULER_RESIZE_OFF    4
41 #define RULER_LINE_WIDTH    7
42 #define RULER_MIN_SIZE      3
43 
44 #define RULER_TICK1_WIDTH   1
45 #define RULER_TICK2_WIDTH   3
46 #define RULER_TICK3_WIDTH   5
47 
48 #define RULER_VAR_SIZE      8
49 
50 #define RULER_TAB_HEIGHT2   2
51 #define RULER_TAB_WIDTH2    2
52 #define RULER_TAB_CWIDTH    8
53 #define RULER_TAB_CWIDTH2   4
54 #define RULER_TAB_CWIDTH3   4
55 #define RULER_TAB_CWIDTH4   2
56 #define RULER_TAB_DHEIGHT   4
57 #define RULER_TAB_DHEIGHT2  1
58 #define RULER_TAB_DWIDTH    5
59 #define RULER_TAB_DWIDTH2   3
60 #define RULER_TAB_DWIDTH3   3
61 #define RULER_TAB_DWIDTH4   1
62 
63 #define RULER_UPDATE_LINES  0x01
64 #define RULER_UPDATE_DRAW   0x02
65 
66 #define RULER_CLIP          150
67 
68 // =======================================================================
69 
70 #define RULER_UNIT_MM       0
71 #define RULER_UNIT_CM       1
72 #define RULER_UNIT_M        2
73 #define RULER_UNIT_KM       3
74 #define RULER_UNIT_INCH     4
75 #define RULER_UNIT_FOOT     5
76 #define RULER_UNIT_MILE     6
77 #define RULER_UNIT_POINT    7
78 #define RULER_UNIT_PICA     8
79 #define RULER_UNIT_COUNT    9
80 
81 // -----------------
82 // - ImplRulerData -
83 // -----------------
84 class ImplRulerData
85 {
86     friend              class Ruler;
87 
88 private:
89     RulerLine*          pLines;
90     RulerArrow*         pArrows;
91     RulerBorder*        pBorders;
92     RulerIndent*        pIndents;
93     RulerTab*           pTabs;
94     long                nNullVirOff;
95     long                nRulVirOff;
96     long                nRulWidth;
97     long                nPageOff;
98     long                nPageWidth;
99     long                nNullOff;
100     long                nMargin1;
101     long                nMargin2;
102     sal_uInt16              nLines;
103     sal_uInt16              nArrows;
104     sal_uInt16              nBorders;
105     sal_uInt16              nIndents;
106     sal_uInt16              nTabs;
107     sal_uInt16              nMargin1Style;
108     sal_uInt16              nMargin2Style;
109     sal_Bool                bAutoPageWidth;
110     sal_Bool                bTextRTL;
111 
112 #ifdef _SV_RULER_CXX
113 public:
114                         ImplRulerData();
115                         ~ImplRulerData();
116     ImplRulerData&      operator=( const ImplRulerData& rData );
117 #endif
118 };
119 
120 
121 struct ImplRulerUnitData
122 {
123     MapUnit         eMapUnit;           // MAP_UNIT zum Umrechnen
124     long            nTickUnit;          // Teiler fuer Einheit
125     long            nTick1;             // Schrittweite
126     long            nTick2;             // Tick fuer halbe Werte
127     long            nTick3;             // Tick fuer Zahlenausgabe
128     long            n100THMM;           // Teiler fuer Einheit
129     sal_uInt16          nUnitDigits;        // Anzahl Nachkommastellen
130     sal_Char        aUnitStr[8];        // Einheiten-String
131 };
132 
133 static ImplRulerUnitData aImplRulerUnitTab[RULER_UNIT_COUNT] =
134 {
135 { MAP_100TH_MM,        100,    25,     50,    100,     100, 3, " mm"    }, // MM
136 { MAP_100TH_MM,       1000,   250,    500,   1000,    1000, 3, " cm"    }, // CM
137 { MAP_MM,             1000,   250,    500,   1000,   10000, 4, " m"     }, // M
138 { MAP_CM,           100000, 25000,  50000, 100000,  100000, 6, " km"    }, // KM
139 { MAP_100TH_INCH,      100,    10,     50,    100,    2540, 3, "\""     }, // INCH
140 { MAP_100TH_INCH,     1200,   120,    600,   1200,   30480, 3, "'"      }, // FOOT
141 { MAP_10TH_INCH,    633600, 63360, 316800, 633600, 1609344, 4, " miles" }, // MILE
142 { MAP_POINT,             1,    12,     12,     36,     353, 2, " pt"    }, // POINT
143 { MAP_100TH_MM,        423,   423,    423,    846,     423, 3, " pi"    }  // PICA
144 };
145 
146 // =======================================================================
147 
148 struct ImplRulerHitTest
149 {
150     long        nPos;
151     RulerType   eType;
152     sal_uInt16      nAryPos;
153     sal_uInt16      mnDragSize;
154     sal_Bool        bSize;
155     sal_Bool        bSizeBar;
156     sal_Bool        bExpandTest;
157     ImplRulerHitTest() :
158         bExpandTest( sal_False ) {}
159 };
160 
161 // =======================================================================
162 
163 ImplRulerData::ImplRulerData()
164 {
165     memset( this, 0, sizeof( ImplRulerData ) );
166 
167     // PageBreite == EditWinBreite
168     bAutoPageWidth   = sal_True;
169 }
170 
171 // -----------------------------------------------------------------------
172 
173 ImplRulerData::~ImplRulerData()
174 {
175     delete[] pLines;
176     delete[] pArrows;
177     delete[] pBorders;
178     delete[] pIndents;
179     delete[] pTabs;
180 }
181 
182 // -----------------------------------------------------------------------
183 
184 ImplRulerData& ImplRulerData::operator=( const ImplRulerData& rData )
185 {
186     delete[] pLines;
187     delete[] pArrows;
188     delete[] pBorders;
189     delete[] pIndents;
190     delete[] pTabs;
191 
192     memcpy( this, &rData, sizeof( ImplRulerData ) );
193 
194     if ( rData.pLines )
195     {
196         pLines = new RulerLine[nLines];
197         memcpy( pLines, rData.pLines, nLines*sizeof( RulerLine ) );
198     }
199 
200     if ( rData.pArrows )
201     {
202         pArrows = new RulerArrow[nArrows];
203         memcpy( pArrows, rData.pArrows, nArrows*sizeof( RulerArrow ) );
204     }
205 
206     if ( rData.pBorders )
207     {
208         pBorders = new RulerBorder[nBorders];
209         memcpy( pBorders, rData.pBorders, nBorders*sizeof( RulerBorder ) );
210     }
211 
212     if ( rData.pIndents )
213     {
214         pIndents = new RulerIndent[nIndents];
215         memcpy( pIndents, rData.pIndents, nIndents*sizeof( RulerIndent ) );
216     }
217 
218     if ( rData.pTabs )
219     {
220         pTabs = new RulerTab[nTabs];
221         memcpy( pTabs, rData.pTabs, nTabs*sizeof( RulerTab ) );
222     }
223 
224     return *this;
225 }
226 
227 // =======================================================================
228 
229 void Ruler::ImplInit( WinBits nWinBits )
230 {
231     const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
232 
233     // Default WinBits setzen
234     if ( !(nWinBits & WB_VERT) )
235     {
236         nWinBits |= WB_HORZ;
237 
238         // --- RTL --- no UI mirroring for horizontal rulers, because
239         // the document is also not mirrored
240         EnableRTL( sal_False );
241     }
242 
243     // Variablen initialisieren
244     mnWinStyle      = nWinBits;             // Window-Style
245     mnBorderOff     = 0;                    // Border-Offset
246     mnWinOff        = 0;                    // EditWinOffset
247     mnWinWidth      = 0;                    // EditWinWidth
248     mnWidth         = 0;                    // Fensterbreite
249     mnHeight        = 0;                    // Fensterhoehe
250     mnVirOff        = 0;                    // Offset des VirtualDeice vom linke/oberen Rand
251     mnVirWidth      = 0;                    // Breite bzw. Hoehe vom VirtualDevice
252     mnVirHeight     = 0;                    // Hoehe bzw. Breite vom VirtualDevice
253     mnDragPos       = 0;                    // Drag-Position (NullPunkt)
254     mnUpdateEvtId   = 0;                    // Noch kein Update-Event verschickt
255     mnDragAryPos    = 0;                    // Drag-Array-Index
256     mnDragSize      = 0;                    // Wird beim Draggen die Groesse geaendert
257     mnDragScroll    = 0;                    // Soll beim Draggen gescrollt werden
258     mnDragModifier  = 0;                    // Modifier-Tasten beim Draggen
259     mnExtraStyle    = 0;                    // Style des Extra-Feldes
260     mnExtraClicks   = 0;                    // Click-Anzahl fuer Extra-Feld
261     mnExtraModifier = 0;                    // Modifier-Tasten beim Click im Extrafeld
262     mbCalc          = sal_True;                 // Muessen Pagebreiten neu berechnet werden
263     mbFormat        = sal_True;                 // Muss neu ausgegeben werden
264     mbDrag          = sal_False;                // Sind wir im Drag-Modus
265     mbDragDelete    = sal_False;                // Wird Maus beim Draggen unten rausgezogen
266     mbDragCanceled  = sal_False;                // Wurde Dragging abgebrochen
267     mbAutoWinWidth  = sal_True;                 // EditWinBreite == RulerBreite
268     mbActive        = sal_True;                 // Ist Lineal aktiv
269     mnUpdateFlags   = 0;                    // Was soll im Update-Handler upgedatet werden
270     mpData          = mpSaveData;           // Wir zeigen auf die normalen Daten
271     meExtraType     = RULER_EXTRA_DONTKNOW; // Was im ExtraFeld dargestellt wird
272     meDragType      = RULER_TYPE_DONTKNOW;  // Gibt an, was gedragt wird
273 
274     // Units initialisieren
275     mnUnitIndex     = RULER_UNIT_CM;
276     meUnit          = FUNIT_CM;
277     maZoom          = Fraction( 1, 1 );
278     meSourceUnit    = MAP_100TH_MM;
279 
280     // Border-Breiten berechnen
281     if ( nWinBits & WB_BORDER )
282     {
283         if ( !(rStyleSettings.GetOptions() & STYLE_OPTION_MONO) )
284             mnBorderWidth = 2;
285         else
286             mnBorderWidth = 1;
287     }
288     else
289         mnBorderWidth = 0;
290 
291     // Einstellungen setzen
292     ImplInitSettings( sal_True, sal_True, sal_True );
293 
294     // Default-Groesse setzen
295     long nDefHeight = GetTextHeight() + RULER_OFF*2 + RULER_TEXTOFF*2 + mnBorderWidth;
296     Size aDefSize;
297     if ( nWinBits & WB_HORZ )
298         aDefSize.Height() = nDefHeight;
299     else
300         aDefSize.Width() = nDefHeight;
301     SetOutputSizePixel( aDefSize );
302 	SetType(WINDOW_RULER);
303 }
304 
305 // -----------------------------------------------------------------------
306 
307 Ruler::Ruler( Window* pParent, WinBits nWinStyle ) :
308     Window( pParent, nWinStyle & WB_3DLOOK ),
309     maVirDev( *this ),
310     maMapMode( MAP_100TH_MM ),
311     mpSaveData(new ImplRulerData),
312     mpData(0),
313     mpDragData(new ImplRulerData)
314 {
315     ImplInit( nWinStyle );
316 }
317 
318 // -----------------------------------------------------------------------
319 
320 Ruler::~Ruler()
321 {
322     if ( mnUpdateEvtId )
323         Application::RemoveUserEvent( mnUpdateEvtId );
324     delete mpSaveData;
325     delete mpDragData;
326 }
327 
328 // -----------------------------------------------------------------------
329 
330 void Ruler::ImplVDrawLine( long nX1, long nY1, long nX2, long nY2 )
331 {
332     if ( nX1 < -RULER_CLIP )
333     {
334         nX1 = -RULER_CLIP;
335         if ( nX2 < -RULER_CLIP )
336             return;
337     }
338     long nClip = mnVirWidth+RULER_CLIP;
339     if ( nX2 > nClip )
340     {
341         nX2 = nClip;
342         if ( nX1 > nClip )
343             return;
344     }
345 
346     if ( mnWinStyle & WB_HORZ )
347         maVirDev.DrawLine( Point( nX1, nY1 ), Point( nX2, nY2 ) );
348     else
349         maVirDev.DrawLine( Point( nY1, nX1 ), Point( nY2, nX2 ) );
350 }
351 
352 // -----------------------------------------------------------------------
353 
354 void Ruler::ImplVDrawRect( long nX1, long nY1, long nX2, long nY2 )
355 {
356     if ( nX1 < -RULER_CLIP )
357     {
358         nX1 = -RULER_CLIP;
359         if ( nX2 < -RULER_CLIP )
360             return;
361     }
362     long nClip = mnVirWidth+RULER_CLIP;
363     if ( nX2 > nClip )
364     {
365         nX2 = nClip;
366         if ( nX1 > nClip )
367             return;
368     }
369 
370     if ( mnWinStyle & WB_HORZ )
371         maVirDev.DrawRect( Rectangle( nX1, nY1, nX2, nY2 ) );
372     else
373         maVirDev.DrawRect( Rectangle( nY1, nX1, nY2, nX2 ) );
374 }
375 
376 // -----------------------------------------------------------------------
377 
378 void Ruler::ImplVDrawText( long nX, long nY, const String& rText )
379 {
380     if ( (nX > -RULER_CLIP) && (nX < mnVirWidth+RULER_CLIP) )
381     {
382         if ( mnWinStyle & WB_HORZ )
383             maVirDev.DrawText( Point( nX, nY ), rText );
384         else
385             maVirDev.DrawText( Point( nY, nX ), rText );
386     }
387 }
388 
389 // -----------------------------------------------------------------------
390 
391 void Ruler::ImplInvertLines( sal_Bool bErase )
392 {
393     // Positionslinien
394     if ( mpData->nLines && mbActive && !mbDrag && !mbFormat &&
395          !(mnUpdateFlags & RULER_UPDATE_LINES) )
396     {
397         long n;
398         long nNullWinOff = mpData->nNullVirOff+mnVirOff;
399         long nRulX1 = mpData->nRulVirOff+mnVirOff;
400         long nRulX2 = nRulX1+mpData->nRulWidth;
401         long nY = (RULER_OFF*2)+mnVirHeight-1;
402 
403         // Rectangle berechnen
404         Rectangle aRect;
405         if ( mnWinStyle & WB_HORZ )
406             aRect.Bottom() = nY;
407         else
408             aRect.Right() = nY;
409 
410         // Linien ausgeben
411         for ( sal_uInt16 i = 0; i < mpData->nLines; i++ )
412         {
413             n = mpData->pLines[i].nPos+nNullWinOff;
414             if ( (n >= nRulX1) && (n < nRulX2) )
415             {
416                 if ( mnWinStyle & WB_HORZ )
417                 {
418                     aRect.Left()   = n;
419                     aRect.Right()  = n;
420                 }
421                 else
422                 {
423                     aRect.Top()    = n;
424                     aRect.Bottom() = n;
425                 }
426                 if ( bErase )
427                 {
428                     Rectangle aTempRect = aRect;
429                     if ( mnWinStyle & WB_HORZ )
430                         aTempRect.Bottom() = RULER_OFF-1;
431                     else
432                         aTempRect.Right() = RULER_OFF-1;
433                     Erase( aTempRect );
434                     if ( mnWinStyle & WB_HORZ )
435                     {
436                         aTempRect.Bottom() = aRect.Bottom();
437                         aTempRect.Top()    = aTempRect.Bottom()-RULER_OFF+1;
438                     }
439                     else
440                     {
441                         aTempRect.Right()  = aRect.Right();
442                         aTempRect.Left()   = aTempRect.Right()-RULER_OFF+1;
443                     }
444                     Erase( aTempRect );
445                 }
446                 Invert( aRect );
447             }
448         }
449     }
450 }
451 
452 // -----------------------------------------------------------------------
453 
454 void Ruler::ImplDrawTicks( long nMin, long nMax, long nStart, long nCenter )
455 {
456     long    n = 0;
457     long    nTick = 0;
458     long    nTick3 = aImplRulerUnitTab[mnUnitIndex].nTick3;
459     long    nTickCount = aImplRulerUnitTab[mnUnitIndex].nTick1;
460     Size    aPixSize = maVirDev.LogicToPixel( Size( nTick3, nTick3 ), maMapMode );
461     long    nTickWidth;
462     long    nX;
463     long    nY;
464     sal_Bool    bNoTicks = sal_False;
465 
466     // Groessenvorberechnung
467     // Sizes calculation
468     sal_Bool bVertRight = sal_False;
469     if ( mnWinStyle & WB_HORZ )
470         nTickWidth = aPixSize.Width();
471     else
472     {
473         Font aFont = GetFont();
474         if ( mnWinStyle & WB_RIGHT_ALIGNED )
475         {
476             aFont.SetOrientation( 2700 );
477             bVertRight = sal_True;
478         }
479         else
480             aFont.SetOrientation( 900 );
481         maVirDev.SetFont( aFont );
482         nTickWidth = aPixSize.Height();
483     }
484     long nMaxWidth = maVirDev.PixelToLogic( Size( mpData->nPageWidth, 0 ), maMapMode ).Width();
485     if ( nMaxWidth < 0 )
486         nMaxWidth = -nMaxWidth;
487     nMaxWidth /= aImplRulerUnitTab[mnUnitIndex].nTickUnit;
488     UniString aNumStr( UniString::CreateFromInt32( nMaxWidth ) );
489     long nTxtWidth = GetTextWidth( aNumStr );
490 
491     const long nTextOff   = 4;
492     if ( nTickWidth < nTxtWidth+nTextOff )
493     {
494         // Calculate the scale of the ruler
495         long nMulti     = 1;
496         long nOrgTick3  = nTick3;
497         while ( nTickWidth < nTxtWidth+nTextOff )
498         {
499             long nOldMulti = nMulti;
500             if ( !nTickWidth ) //If nTickWidth equals 0
501                 nMulti *= 10;
502             else if ( nMulti < 10 )
503                 nMulti++;
504             else if ( nMulti < 100 )
505                 nMulti += 10;
506             else if ( nMulti < 1000 )
507                 nMulti += 100;
508             else
509                 nMulti += 1000;
510             // Ueberlauf, dann geben wir nichts aus, da wir bei so einem
511             // unsinnigen Massstab sowieso nichts vernuenftiges anzeigen
512             // koennen
513             if ( nMulti < nOldMulti )
514             {
515                 bNoTicks = sal_True;
516                 break;
517             }
518 
519             nTick3 = nOrgTick3 * nMulti;
520             aPixSize = maVirDev.LogicToPixel( Size( nTick3, nTick3 ), maMapMode );
521             if ( mnWinStyle & WB_HORZ )
522                 nTickWidth = aPixSize.Width();
523             else
524                 nTickWidth = aPixSize.Height();
525         }
526         nTickCount = nTick3;
527     }
528     else
529         maVirDev.SetLineColor( GetSettings().GetStyleSettings().GetWindowTextColor() );
530 
531     if ( !bNoTicks )
532     {
533         long nTxtWidth2;
534         long nTxtHeight2 = GetTextHeight()/2;
535         while ( ((nStart-n) >= nMin) || ((nStart+n) <= nMax) )
536         {
537             // Null-Punkt
538             if ( !nTick )
539             {
540                 if ( nStart > nMin )
541                 {
542                     // 0 is only painted when Margin1 is not equal to zero
543                     if ( (mpData->nMargin1Style & RULER_STYLE_INVISIBLE) || (mpData->nMargin1 != 0) )
544                     {
545                         aNumStr = (sal_Unicode)'0';
546                         nTxtWidth2 = maVirDev.GetTextWidth( aNumStr )/2;
547                         if ( (mnWinStyle & WB_HORZ)^mpData->bTextRTL )
548                             nX = nStart-nTxtWidth2;
549                         else
550                             nX = nStart+nTxtWidth2;
551                         long n_Y = bVertRight ? nCenter+nTxtHeight2 : nCenter-nTxtHeight2;
552 						ImplVDrawText( nX, n_Y, aNumStr );
553                     }
554                 }
555             }
556             else
557             {
558                 aPixSize = maVirDev.LogicToPixel( Size( nTick, nTick ), maMapMode );
559 
560                 if ( mnWinStyle & WB_HORZ )
561                     n = aPixSize.Width();
562                 else
563                     n = aPixSize.Height();
564 
565                 // Tick3 - Output (Text)
566                 if ( !(nTick % nTick3) )
567                 {
568                     aNumStr = UniString::CreateFromInt32( nTick / aImplRulerUnitTab[mnUnitIndex].nTickUnit );
569                     nTxtWidth2 = GetTextWidth( aNumStr )/2;
570 
571                     nX = nStart+n;
572                     //different orientation needs a different starting position
573                     nY = bVertRight ? nCenter+nTxtHeight2 : nCenter-nTxtHeight2;
574 
575                     // Check if we can display full number
576                     if ( nX < (nMax-nTxtWidth2) )
577                     {
578                         if ( mnWinStyle & WB_HORZ )
579                             nX -= nTxtWidth2;
580                         else
581                             nX += nTxtWidth2;
582                         ImplVDrawText( nX, nY, aNumStr );
583                     }
584                     nX = nStart-n;
585                     if ( nX > (nMin+nTxtWidth2) )
586                     {
587                         if ( mnWinStyle & WB_HORZ )
588                             nX -= nTxtWidth2;
589                         else
590                             nX += nTxtWidth2;
591                         ImplVDrawText( nX, nY, aNumStr );
592                     }
593                 }
594                 // Tick/Tick2 - Output (Strokes)
595                 else
596                 {
597                     if ( !(nTick % aImplRulerUnitTab[mnUnitIndex].nTick2) )
598                         nTickWidth = RULER_TICK2_WIDTH;
599                     else
600                         nTickWidth = RULER_TICK1_WIDTH;
601                     long nT1 = nCenter-(nTickWidth/2);
602                     long nT2 = nT1+nTickWidth-1;
603                     long nT;
604 
605                     nT = nStart+n;
606                     if ( nT < nMax )
607                         ImplVDrawLine( nT, nT1, nT, nT2 );
608                     nT = nStart-n;
609                     if ( nT > nMin )
610                         ImplVDrawLine( nT, nT1, nT, nT2 );
611                 }
612             }
613             // #i49017# with some zoom factors the value nTick can overflow
614             if( ((sal_uLong)nTick + (sal_uLong)nTickCount) > (sal_uLong)LONG_MAX)
615                 break;
616             nTick += nTickCount;
617         }
618     }
619 }
620 
621 // -----------------------------------------------------------------------
622 
623 void Ruler::ImplDrawArrows( long nCenter )
624 {
625     sal_uInt16          i;
626     long            n1;
627     long            n2;
628     long            n3;
629     long            n4;
630     long            nLogWidth;
631     String          aStr;
632     String          aStr2;
633     sal_Bool            bDrawUnit;
634     long            nTxtWidth;
635     long            nTxtHeight2 = GetTextHeight()/2;
636 
637     const vcl::I18nHelper& rI18nHelper = GetSettings().GetLocaleI18nHelper();
638 
639     maVirDev.SetLineColor( GetSettings().GetStyleSettings().GetWindowTextColor() );
640     for ( i = 0; i < mpData->nArrows; i++ )
641     {
642         n1 = mpData->pArrows[i].nPos+mpData->nNullVirOff+1;
643         n2 = n1+mpData->pArrows[i].nWidth-2;
644 
645         // Einheit umrechnen
646         nLogWidth = mpData->pArrows[i].nLogWidth;
647         if ( meSourceUnit == MAP_TWIP )
648         {
649             if ( nLogWidth >= 100000 )
650                 nLogWidth = (nLogWidth*254)/144;
651             else
652                 nLogWidth = (nLogWidth*2540)/1440;
653         }
654         if ( nLogWidth >= 1000000 )
655             nLogWidth = (nLogWidth / aImplRulerUnitTab[mnUnitIndex].n100THMM) * 1000;
656         else
657             nLogWidth = (nLogWidth*1000) / aImplRulerUnitTab[mnUnitIndex].n100THMM;
658 		aStr = rI18nHelper.GetNum( nLogWidth, aImplRulerUnitTab[mnUnitIndex].nUnitDigits, sal_True, sal_False );
659 
660         // Einheit an den String haengen
661         aStr2 = aStr;
662         aStr2.AppendAscii( aImplRulerUnitTab[mnUnitIndex].aUnitStr );
663 
664         // Textbreite ermitteln
665         bDrawUnit = sal_True;
666         nTxtWidth = GetTextWidth( aStr2 );
667         if ( nTxtWidth < mpData->pArrows[i].nWidth-10 )
668             aStr = aStr2;
669         else
670         {
671             nTxtWidth = GetTextWidth( aStr );
672             if ( nTxtWidth > mpData->pArrows[i].nWidth-10 )
673                 bDrawUnit = sal_False;
674         }
675 
676         // Ist genuegen Platz fuer Einheiten-String vorhanden
677         if ( bDrawUnit )
678         {
679             n3 = n1 + ((n2-n1)/2) - 1;
680             if ( mnWinStyle & WB_HORZ )
681                 n3 -= nTxtWidth/2;
682             else
683                 n3 += nTxtWidth/2;
684             if ( mnWinStyle & WB_HORZ )
685             {
686                 n4 = n3 + nTxtWidth + 2;
687                 ImplVDrawLine( n1, nCenter, n3, nCenter );
688                 ImplVDrawLine( n4, nCenter, n2, nCenter );
689             }
690             else
691             {
692                 n4 = n3 - nTxtWidth - 2;
693                 ImplVDrawLine( n1, nCenter, n4, nCenter );
694                 ImplVDrawLine( n3, nCenter, n2, nCenter );
695             }
696             ImplVDrawText( n3, nCenter-nTxtHeight2, aStr );
697         }
698         else
699             ImplVDrawLine( n1, nCenter, n2, nCenter );
700         ImplVDrawLine( n1+1, nCenter-1, n1+1, nCenter+1 );
701         ImplVDrawLine( n1+2, nCenter-2, n1+2, nCenter+2 );
702         ImplVDrawLine( n2-1, nCenter-1, n2-1, nCenter+1 );
703         ImplVDrawLine( n2-2, nCenter-2, n2-2, nCenter+2 );
704     }
705 }
706 
707 // -----------------------------------------------------------------------
708 
709 void Ruler::ImplDrawBorders( long nMin, long nMax, long nVirTop, long nVirBottom )
710 {
711     const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
712     long    n;
713     long    n1;
714     long    n2;
715     long    nTemp1;
716     long    nTemp2;
717     sal_uInt16  i;
718 
719     for ( i = 0; i < mpData->nBorders; i++ )
720     {
721         if ( mpData->pBorders[i].nStyle & RULER_STYLE_INVISIBLE )
722             continue;
723 
724         n1 = mpData->pBorders[i].nPos+mpData->nNullVirOff;
725         n2 = n1+mpData->pBorders[i].nWidth;
726 
727         if ( ((n1 >= nMin) && (n1 <= nMax)) || ((n2 >= nMin) && (n2 <= nMax)) )
728         {
729             if ( (n2-n1) > 3 )
730             {
731                 maVirDev.SetLineColor();
732                 if ( !(rStyleSettings.GetOptions() & STYLE_OPTION_MONO) )
733                     maVirDev.SetFillColor( rStyleSettings.GetFaceColor() );
734                 else
735                     maVirDev.SetFillColor( rStyleSettings.GetWindowColor() );
736                 ImplVDrawRect( n1, nVirTop, n2, nVirBottom );
737                 if ( !(rStyleSettings.GetOptions() & STYLE_OPTION_MONO) )
738                 {
739                     maVirDev.SetLineColor( rStyleSettings.GetLightColor() );
740                     ImplVDrawLine( n1+1, nVirTop, n1+1, nVirBottom );
741                     ImplVDrawLine( n1, nVirTop, n2, nVirTop );
742                     maVirDev.SetLineColor( rStyleSettings.GetShadowColor() );
743                     ImplVDrawLine( n1, nVirTop, n1, nVirBottom );
744                     ImplVDrawLine( n1, nVirBottom, n2, nVirBottom );
745                     ImplVDrawLine( n2-1, nVirTop, n2-1, nVirBottom );
746                     maVirDev.SetLineColor( rStyleSettings.GetWindowTextColor() );
747                     ImplVDrawLine( n2, nVirTop, n2, nVirBottom );
748                 }
749                 else
750                 {
751                     maVirDev.SetLineColor( rStyleSettings.GetWindowTextColor() );
752                     ImplVDrawLine( n1, nVirTop, n1, nVirBottom );
753                     ImplVDrawLine( n2, nVirTop, n2, nVirBottom );
754                 }
755 
756                 if ( mpData->pBorders[i].nStyle & RULER_BORDER_VARIABLE )
757                 {
758                     if ( n2-n1 > RULER_VAR_SIZE+4 )
759                     {
760                         nTemp1 = n1 + (((n2-n1+1)-RULER_VAR_SIZE) / 2);
761                         nTemp2 = nVirTop + (((nVirBottom-nVirTop+1)-RULER_VAR_SIZE) / 2);
762                         long nTemp3 = nTemp1+RULER_VAR_SIZE-1;
763                         long nTemp4 = nTemp2+RULER_VAR_SIZE-1;
764                         long nTempY = nTemp2;
765                         if ( !(rStyleSettings.GetOptions() & STYLE_OPTION_MONO) )
766                             maVirDev.SetLineColor( rStyleSettings.GetLightColor() );
767                         else
768                             maVirDev.SetLineColor( rStyleSettings.GetWindowTextColor() );
769                         while ( nTempY <= nTemp4 )
770                         {
771                             ImplVDrawLine( nTemp1, nTempY, nTemp3, nTempY );
772                             nTempY += 2;
773                         }
774                         if ( !(rStyleSettings.GetOptions() & STYLE_OPTION_MONO) )
775                         {
776                             nTempY = nTemp2+1;
777                             maVirDev.SetLineColor( rStyleSettings.GetShadowColor() );
778                             while ( nTempY <= nTemp4 )
779                             {
780                                 ImplVDrawLine( nTemp1, nTempY, nTemp3, nTempY );
781                                 nTempY += 2;
782                             }
783                         }
784                     }
785                 }
786 
787                 if ( mpData->pBorders[i].nStyle & RULER_BORDER_SIZEABLE )
788                 {
789                     if ( n2-n1 > RULER_VAR_SIZE+10 )
790                     {
791                         if ( !(rStyleSettings.GetOptions() & STYLE_OPTION_MONO) )
792                         {
793                             maVirDev.SetLineColor( rStyleSettings.GetShadowColor() );
794                             ImplVDrawLine( n1+4, nVirTop+3, n1+4, nVirBottom-3 );
795                             ImplVDrawLine( n2-5, nVirTop+3, n2-5, nVirBottom-3 );
796                             maVirDev.SetLineColor( rStyleSettings.GetLightColor() );
797                             ImplVDrawLine( n1+5, nVirTop+3, n1+5, nVirBottom-3 );
798                             ImplVDrawLine( n2-4, nVirTop+3, n2-4, nVirBottom-3 );
799                         }
800                         else
801                         {
802                             maVirDev.SetLineColor( rStyleSettings.GetWindowTextColor() );
803                             ImplVDrawLine( n1+4, nVirTop+3, n1+4, nVirBottom-3 );
804                             ImplVDrawLine( n2-4, nVirTop+3, n2-4, nVirBottom-3 );
805                         }
806                     }
807                 }
808             }
809             else
810             {
811                 n = n1+((n2-n1)/2);
812                 if ( !(rStyleSettings.GetOptions() & STYLE_OPTION_MONO) )
813                     maVirDev.SetLineColor( rStyleSettings.GetShadowColor() );
814                 else
815                     maVirDev.SetLineColor( rStyleSettings.GetWindowTextColor() );
816                 if ( mpData->pBorders[i].nStyle & RULER_BORDER_SNAP )
817                     ImplVDrawLine( n, nVirTop, n, nVirBottom );
818                 else if ( mpData->pBorders[i].nStyle & RULER_BORDER_MARGIN )
819                     ImplVDrawLine( n, nVirTop, n, nVirBottom );
820                 else
821                 {
822                     ImplVDrawLine( n-1, nVirTop, n-1, nVirBottom );
823                     ImplVDrawLine( n+1, nVirTop, n+1, nVirBottom );
824                     maVirDev.SetLineColor();
825                     maVirDev.SetFillColor( rStyleSettings.GetWindowColor() );
826                     ImplVDrawRect( n, nVirTop, n, nVirBottom );
827                 }
828             }
829         }
830     }
831 }
832 
833 // -----------------------------------------------------------------------
834 
835 void Ruler::ImplDrawIndent( const Polygon& rPoly, sal_uInt16 nStyle )
836 {
837     const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
838     Point   aPos1;
839     Point   aPos2;
840     sal_uInt16  nIndentStyle = nStyle & RULER_INDENT_STYLE;
841 
842     if ( nStyle & RULER_STYLE_INVISIBLE )
843         return;
844 
845     if ( nStyle & RULER_STYLE_DONTKNOW )
846     {
847         maVirDev.SetLineColor( rStyleSettings.GetShadowColor() );
848         maVirDev.SetFillColor( rStyleSettings.GetFaceColor() );
849     }
850     else
851     {
852         maVirDev.SetLineColor( rStyleSettings.GetDarkShadowColor() );
853         maVirDev.SetFillColor( rStyleSettings.GetFaceColor() );
854     }
855 
856     maVirDev.DrawPolygon( rPoly );
857 
858     if ( !(rStyleSettings.GetOptions() & STYLE_OPTION_MONO) && !(nStyle & RULER_STYLE_DONTKNOW) )
859     {
860         if ( nIndentStyle == RULER_INDENT_BOTTOM )
861         {
862             maVirDev.SetLineColor( rStyleSettings.GetLightColor() );
863             aPos1 = rPoly.GetPoint( 2 );
864             aPos1.X()++;
865             aPos2 = rPoly.GetPoint( 1 );
866             aPos2.X()++;
867             maVirDev.DrawLine( aPos2, aPos1 );
868             aPos2.X()--;
869             aPos2.Y()++;
870             aPos1 = rPoly.GetPoint( 0 );
871             aPos1.Y()++;
872             maVirDev.DrawLine( aPos2, aPos1 );
873             maVirDev.SetLineColor( rStyleSettings.GetShadowColor() );
874             aPos2 = rPoly.GetPoint( 4 );
875             aPos2.Y()++;
876             maVirDev.DrawLine( aPos1, aPos2 );
877             aPos2.X()--;
878             aPos1 = rPoly.GetPoint( 3 );
879             aPos1.X()--;
880             maVirDev.DrawLine( aPos2, aPos1 );
881             aPos1.Y()--;
882             aPos2 = rPoly.GetPoint( 2 );
883             aPos2.X()++;
884             aPos2.Y()--;
885             maVirDev.DrawLine( aPos2, aPos1 );
886         }
887         else
888         {
889             maVirDev.SetLineColor( rStyleSettings.GetLightColor() );
890             aPos1 = rPoly.GetPoint( 2 );
891             aPos1.X()++;
892             aPos1.Y()++;
893             aPos2 = rPoly.GetPoint( 3 );
894             aPos2.Y()++;
895             maVirDev.DrawLine( aPos1, aPos2 );
896             aPos2 = rPoly.GetPoint( 1 );
897             aPos2.X()++;
898             maVirDev.DrawLine( aPos1, aPos2 );
899             aPos2.X()--;
900             aPos2.Y()--;
901             aPos1 = rPoly.GetPoint( 0 );
902             aPos1.Y()--;
903             maVirDev.DrawLine( aPos2, aPos1 );
904             maVirDev.SetLineColor( rStyleSettings.GetShadowColor() );
905             aPos2 = rPoly.GetPoint( 4 );
906             aPos2.Y()--;
907             maVirDev.DrawLine( aPos1, aPos2 );
908             aPos2.X()--;
909             aPos1 = rPoly.GetPoint( 3 );
910             aPos1.X()--;
911             maVirDev.DrawLine( aPos2, aPos1 );
912         }
913 
914         maVirDev.SetLineColor( rStyleSettings.GetDarkShadowColor() );
915         maVirDev.SetFillColor();
916         maVirDev.DrawPolygon( rPoly );
917     }
918 }
919 
920 // -----------------------------------------------------------------------
921 
922 void Ruler::ImplDrawIndents( long nMin, long nMax, long nVirTop, long nVirBottom )
923 {
924     sal_uInt16  j;
925     long    n;
926     long    nIndentHeight = (mnVirHeight/2) - 1;
927     long    nIndentWidth2 = nIndentHeight-3;
928     Polygon aPoly( 5 );
929 
930     for ( j = 0; j < mpData->nIndents; j++ )
931     {
932         if ( mpData->pIndents[j].nStyle & RULER_STYLE_INVISIBLE )
933             continue;
934 
935         sal_uInt16  nStyle = mpData->pIndents[j].nStyle;
936         sal_uInt16  nIndentStyle = nStyle & RULER_INDENT_STYLE;
937 
938         n = mpData->pIndents[j].nPos+mpData->nNullVirOff;
939 
940         if ( (n >= nMin) && (n <= nMax) )
941         {
942             if(nIndentStyle == RULER_INDENT_BORDER)
943             {
944 				const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
945 				maVirDev.SetLineColor( rStyleSettings.GetShadowColor() );
946                 ImplVDrawLine( n, nVirTop, n, nVirBottom );
947             }
948             else if ( nIndentStyle == RULER_INDENT_BOTTOM )
949             {
950                 aPoly.SetPoint( Point( n+0, nVirBottom-nIndentHeight ), 0 );
951                 aPoly.SetPoint( Point( n-nIndentWidth2, nVirBottom-3 ), 1 );
952                 aPoly.SetPoint( Point( n-nIndentWidth2, nVirBottom ), 2 );
953                 aPoly.SetPoint( Point( n+nIndentWidth2, nVirBottom ), 3 );
954                 aPoly.SetPoint( Point( n+nIndentWidth2, nVirBottom-3 ), 4 );
955             }
956             else
957             {
958                 aPoly.SetPoint( Point( n+0, nVirTop+nIndentHeight ), 0 );
959                 aPoly.SetPoint( Point( n-nIndentWidth2, nVirTop+3 ), 1 );
960                 aPoly.SetPoint( Point( n-nIndentWidth2, nVirTop ), 2 );
961                 aPoly.SetPoint( Point( n+nIndentWidth2, nVirTop ), 3 );
962                 aPoly.SetPoint( Point( n+nIndentWidth2, nVirTop+3 ), 4 );
963             }
964 
965             if(0 == (mnWinStyle & WB_HORZ))
966             {
967                 Point aTmp;
968                 for(sal_uInt16 i = 0; i < 5; i++)
969                 {
970                     aTmp = aPoly[i];
971                     Point aSet(nVirBottom - aTmp.Y(), aTmp.X());
972                     aPoly[i] = aSet;
973                 }
974             }
975             if(RULER_INDENT_BORDER != nIndentStyle)
976 				ImplDrawIndent( aPoly, nStyle );
977         }
978     }
979 }
980 
981 // -----------------------------------------------------------------------
982 
983 static void ImplCenterTabPos( Point& rPos, sal_uInt16 nTabStyle )
984 {
985     sal_Bool bRTL  = 0 != (nTabStyle & RULER_TAB_RTL);
986     nTabStyle &= RULER_TAB_STYLE;
987     rPos.Y() += RULER_TAB_HEIGHT/2;
988     if ( (!bRTL && nTabStyle == RULER_TAB_LEFT) ||( bRTL && nTabStyle == RULER_TAB_RIGHT))
989         rPos.X() -= RULER_TAB_WIDTH/2;
990     else if ( (!bRTL && nTabStyle == RULER_TAB_RIGHT) ||( bRTL && nTabStyle == RULER_TAB_LEFT))
991         rPos.X() += RULER_TAB_WIDTH/2;
992 }
993 
994 // -----------------------------------------------------------------------
995 void lcl_RotateRect_Impl(Rectangle& rRect, const long nReference, sal_Bool bRightAligned)
996 {
997     if(!rRect.IsEmpty())
998     {
999         Rectangle aTmp(rRect);
1000         rRect.Top() = aTmp.Left();
1001         rRect.Bottom() = aTmp.Right();
1002         rRect.Left() = aTmp.Top();
1003         rRect.Right() = aTmp.Bottom();
1004         if(bRightAligned)
1005         {
1006             long nRef = 2 * nReference;
1007 			rRect.Left() = nRef - rRect.Left();
1008             rRect.Right() = nRef - rRect.Right();
1009         }
1010     }
1011 }
1012 // -----------------------------------------------------------------------
1013 
1014 static void ImplDrawRulerTab( OutputDevice* pDevice,
1015                              const Point& rPos, sal_uInt16 nStyle, WinBits nWinBits )
1016 {
1017     if ( nStyle & RULER_STYLE_INVISIBLE )
1018         return;
1019 
1020     sal_uInt16 nTabStyle = nStyle & RULER_TAB_STYLE;
1021     sal_Bool bRTL = 0 != (nStyle & RULER_TAB_RTL);
1022     Rectangle aRect1, aRect2, aRect3;
1023     aRect3.SetEmpty();
1024     if ( nTabStyle == RULER_TAB_DEFAULT )
1025     {
1026         aRect1.Left() =     rPos.X() - RULER_TAB_DWIDTH2 + 1                ;
1027         aRect1.Top() =      rPos.Y() - RULER_TAB_DHEIGHT2 + 1               ;
1028         aRect1.Right() =    rPos.X() - RULER_TAB_DWIDTH2 + RULER_TAB_DWIDTH ;
1029         aRect1.Bottom() =   rPos.Y();
1030         aRect2.Left() =     rPos.X() - RULER_TAB_DWIDTH2 + RULER_TAB_DWIDTH3;
1031         aRect2.Top() =      rPos.Y() - RULER_TAB_DHEIGHT + 1;
1032         aRect2.Right() =    rPos.X() - RULER_TAB_DWIDTH2 + RULER_TAB_DWIDTH3 + RULER_TAB_DWIDTH4 - 1;
1033         aRect2.Bottom() =   rPos.Y();
1034 
1035     }
1036     else if ( (!bRTL && nTabStyle == RULER_TAB_LEFT) ||( bRTL && nTabStyle == RULER_TAB_RIGHT))
1037     {
1038         aRect1.Left() =     rPos.X();
1039         aRect1.Top() =      rPos.Y() - RULER_TAB_HEIGHT2 + 1;
1040         aRect1.Right() =    rPos.X() + RULER_TAB_WIDTH - 1;
1041         aRect1.Bottom() =   rPos.Y();
1042         aRect2.Left() =     rPos.X();
1043         aRect2.Top() =      rPos.Y() - RULER_TAB_HEIGHT + 1;
1044         aRect2.Right() =    rPos.X() + RULER_TAB_WIDTH2 - 1;
1045         aRect2.Bottom() =   rPos.Y();
1046     }
1047     else if ( (!bRTL && nTabStyle == RULER_TAB_RIGHT) ||( bRTL && nTabStyle == RULER_TAB_LEFT))
1048     {
1049         aRect1.Left() =     rPos.X() - RULER_TAB_WIDTH + 1;
1050         aRect1.Top() =      rPos.Y() - RULER_TAB_HEIGHT2 + 1;
1051         aRect1.Right() =    rPos.X();
1052         aRect1.Bottom() =   rPos.Y();
1053         aRect2.Left() =     rPos.X() - RULER_TAB_WIDTH2 + 1;
1054         aRect2.Top() =      rPos.Y() - RULER_TAB_HEIGHT + 1;
1055         aRect2.Right() =    rPos.X();
1056         aRect2.Bottom() =   rPos.Y();
1057     }
1058     else
1059     {
1060         aRect1.Left() =     rPos.X() - RULER_TAB_CWIDTH2 + 1;
1061         aRect1.Top() =      rPos.Y() - RULER_TAB_HEIGHT2 + 1;
1062         aRect1.Right() =    rPos.X() - RULER_TAB_CWIDTH2 + RULER_TAB_CWIDTH;
1063         aRect1.Bottom() =   rPos.Y();
1064         aRect2.Left() =     rPos.X() - RULER_TAB_CWIDTH2 + RULER_TAB_CWIDTH3;
1065         aRect2.Top() =      rPos.Y() - RULER_TAB_HEIGHT + 1;
1066         aRect2.Right() =    rPos.X() - RULER_TAB_CWIDTH2 + RULER_TAB_CWIDTH3 + RULER_TAB_CWIDTH4 - 1;
1067         aRect2.Bottom() =   rPos.Y();
1068 
1069         if ( nTabStyle == RULER_TAB_DECIMAL )
1070         {
1071             aRect3.Left() = rPos.X() - RULER_TAB_CWIDTH2 + RULER_TAB_CWIDTH - 1;
1072             aRect3.Top()  = rPos.Y() - RULER_TAB_HEIGHT + 1 + 1;
1073             aRect3.Right() = rPos.X() - RULER_TAB_CWIDTH2 + RULER_TAB_CWIDTH;
1074             aRect3.Bottom()= rPos.Y() - RULER_TAB_HEIGHT + 1 + 2 ;
1075         }
1076     }
1077     if( 0 == (nWinBits&WB_HORZ) )
1078     {
1079         sal_Bool bRightAligned = 0 != (nWinBits&WB_RIGHT_ALIGNED);
1080         lcl_RotateRect_Impl(aRect1, rPos.Y(), bRightAligned);
1081         lcl_RotateRect_Impl(aRect2, rPos.Y(), bRightAligned);
1082         lcl_RotateRect_Impl(aRect3, rPos.Y(), bRightAligned);
1083     }
1084     pDevice->DrawRect( aRect1 );
1085     pDevice->DrawRect( aRect2 );
1086     if(!aRect2.IsEmpty())
1087         pDevice->DrawRect( aRect3 );
1088 
1089 }
1090 
1091 // -----------------------------------------------------------------------
1092 
1093 void Ruler::ImplDrawTab( OutputDevice* pDevice, const Point& rPos, sal_uInt16 nStyle )
1094 {
1095     if ( nStyle & RULER_STYLE_INVISIBLE )
1096         return;
1097 
1098     pDevice->SetLineColor();
1099     if ( nStyle & RULER_STYLE_DONTKNOW )
1100         pDevice->SetFillColor( GetSettings().GetStyleSettings().GetFaceColor() );
1101     else
1102         pDevice->SetFillColor( GetSettings().GetStyleSettings().GetWindowTextColor() );
1103 
1104     if(mpData->bTextRTL)
1105         nStyle |= RULER_TAB_RTL;
1106     ImplDrawRulerTab( pDevice, rPos, nStyle, GetStyle());
1107 }
1108 
1109 // -----------------------------------------------------------------------
1110 
1111 void Ruler::ImplDrawTabs( long nMin, long nMax, long nVirTop, long nVirBottom )
1112 {
1113     for ( sal_uInt16 i = 0; i < mpData->nTabs; i++ )
1114     {
1115         if ( mpData->pTabs[i].nStyle & RULER_STYLE_INVISIBLE )
1116             continue;
1117 
1118         long n;
1119             n = mpData->pTabs[i].nPos;
1120 		n += +mpData->nNullVirOff;
1121         long nTopBottom = GetStyle() & WB_RIGHT_ALIGNED ? nVirTop : nVirBottom;
1122         if ( (n >= nMin) && (n <= nMax) )
1123             ImplDrawTab( &maVirDev, Point( n, nTopBottom ), mpData->pTabs[i].nStyle );
1124     }
1125 }
1126 
1127 // -----------------------------------------------------------------------
1128 
1129 void Ruler::ImplInitSettings( sal_Bool bFont,
1130                               sal_Bool bForeground, sal_Bool bBackground )
1131 {
1132     const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
1133 
1134     if ( bFont )
1135     {
1136         Font aFont;
1137         aFont = rStyleSettings.GetToolFont();
1138         if ( IsControlFont() )
1139             aFont.Merge( GetControlFont() );
1140         SetZoomedPointFont( aFont );
1141     }
1142 
1143     if ( bForeground || bFont )
1144     {
1145         Color aColor;
1146         if ( IsControlForeground() )
1147             aColor = GetControlForeground();
1148         else
1149             aColor = rStyleSettings.GetWindowTextColor();
1150         SetTextColor( aColor );
1151         SetTextFillColor();
1152     }
1153 
1154     if ( bBackground )
1155     {
1156         Color aColor;
1157         if ( IsControlBackground() )
1158             aColor = GetControlBackground();
1159         else
1160             aColor = rStyleSettings.GetFaceColor();
1161         SetBackground( aColor );
1162     }
1163 
1164     maVirDev.SetSettings( GetSettings() );
1165     maVirDev.SetBackground( GetBackground() );
1166     Font aFont = GetFont();
1167     if ( mnWinStyle & WB_VERT )
1168         aFont.SetOrientation( 900 );
1169     maVirDev.SetFont( aFont );
1170     maVirDev.SetTextColor( GetTextColor() );
1171     maVirDev.SetTextFillColor( GetTextFillColor() );
1172 }
1173 
1174 // -----------------------------------------------------------------------
1175 
1176 void Ruler::ImplCalc()
1177 {
1178     // Offset berechnen
1179     mpData->nRulVirOff = mnWinOff + mpData->nPageOff;
1180     if ( mpData->nRulVirOff > mnVirOff )
1181         mpData->nRulVirOff -= mnVirOff;
1182     else
1183         mpData->nRulVirOff = 0;
1184     long nRulWinOff = mpData->nRulVirOff+mnVirOff;
1185 
1186     // Nicht sichtbaren Bereich der Page berechnen
1187     long nNotVisPageWidth;
1188     if ( mpData->nPageOff < 0 )
1189     {
1190         nNotVisPageWidth = -(mpData->nPageOff);
1191         if ( nRulWinOff < mnWinOff )
1192             nNotVisPageWidth -= mnWinOff-nRulWinOff;
1193     }
1194     else
1195         nNotVisPageWidth = 0;
1196 
1197     // Breite berechnen
1198     if ( mnWinStyle & WB_HORZ )
1199     {
1200         if ( mbAutoWinWidth )
1201             mnWinWidth = mnWidth - mnVirOff;
1202         if ( mpData->bAutoPageWidth )
1203             mpData->nPageWidth = mnWinWidth;
1204         mpData->nRulWidth = Min( mnWinWidth, mpData->nPageWidth-nNotVisPageWidth );
1205         if ( nRulWinOff+mpData->nRulWidth > mnWidth )
1206             mpData->nRulWidth = mnWidth-nRulWinOff;
1207     }
1208     else
1209     {
1210         if ( mbAutoWinWidth )
1211             mnWinWidth = mnHeight - mnVirOff;
1212         if ( mpData->bAutoPageWidth )
1213             mpData->nPageWidth = mnWinWidth;
1214         mpData->nRulWidth = Min( mnWinWidth, mpData->nPageWidth-nNotVisPageWidth );
1215         if ( nRulWinOff+mpData->nRulWidth > mnHeight )
1216             mpData->nRulWidth = mnHeight-nRulWinOff;
1217     }
1218 
1219     mbCalc = sal_False;
1220 }
1221 
1222 // -----------------------------------------------------------------------
1223 
1224 void Ruler::ImplFormat()
1225 {
1226     // Wenn schon formatiert ist, brauchen wir es nicht nochmal
1227     if ( !mbFormat )
1228         return;
1229 
1230     // Wenn Fenster noch keine Groesse hat, brauchen wir noch nichts machen
1231     if ( !mnVirWidth )
1232         return;
1233 
1234     const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
1235     long    nP1;            // Pixel-Position von Page1
1236     long    nP2;            // Pixel-Position von Page2
1237     long    nM1;            // Pixel-Position von Margin1
1238     long    nM2;            // Pixel-Position von Margin2
1239     long    nVirTop;        // Obere/Linke-Kante bei Ausgabe
1240     long    nVirBottom;     // Untere/Rechte-Kante bei Ausgabe
1241     long    nVirLeft;       // Linke/Obere-Kante bei Ausgabe
1242     long    nVirRight;      // Rechte/Untere-Kante bei Ausgabe
1243     long    nNullVirOff;    // Fuer schnellere Berechnung
1244 
1245     // Werte berechnen
1246     if ( mbCalc )
1247         ImplCalc();
1248     mpData->nNullVirOff = mnWinOff+mpData->nPageOff+mpData->nNullOff-mnVirOff;
1249     nNullVirOff = mpData->nNullVirOff;
1250     nVirLeft    = mpData->nRulVirOff;
1251     nVirRight   = nVirLeft+mpData->nRulWidth-1;
1252     nVirTop     = 0;
1253     nVirBottom  = mnVirHeight-1;
1254 
1255     if ( !IsReallyVisible() )
1256         return;
1257 
1258     Size    aVirDevSize;
1259     sal_Bool    b3DLook = !(rStyleSettings.GetOptions() & STYLE_OPTION_MONO);
1260 
1261     // VirtualDevice initialize
1262     if ( mnWinStyle & WB_HORZ )
1263     {
1264         aVirDevSize.Width() = mnVirWidth;
1265         aVirDevSize.Height() = mnVirHeight;
1266     }
1267     else
1268     {
1269         aVirDevSize.Height() = mnVirWidth;
1270         aVirDevSize.Width() = mnVirHeight;
1271     }
1272     if ( aVirDevSize != maVirDev.GetOutputSizePixel() )
1273         maVirDev.SetOutputSizePixel( aVirDevSize, sal_True );
1274     else
1275         maVirDev.Erase();
1276 
1277     // Raender berechnen
1278     if ( !(mpData->nMargin1Style & RULER_STYLE_INVISIBLE) )
1279     {
1280         nM1 = mpData->nMargin1+nNullVirOff;
1281         if ( mpData->bAutoPageWidth )
1282         {
1283             nP1 = nVirLeft;
1284             if ( nM1 < nVirLeft )
1285                 nP1--;
1286         }
1287         else
1288             nP1 = nNullVirOff-mpData->nNullOff;
1289     }
1290     else
1291     {
1292         nM1 = nVirLeft-1;
1293         nP1 = nM1;
1294     }
1295     if ( !(mpData->nMargin2Style & RULER_STYLE_INVISIBLE) )
1296     {
1297         nM2 = mpData->nMargin2+nNullVirOff;
1298         if ( mpData->bAutoPageWidth )
1299         {
1300             nP2 = nVirRight;
1301             if ( nM2 > nVirRight )
1302                 nP2++;
1303         }
1304         else
1305             nP2 = nNullVirOff-mpData->nNullOff+mpData->nPageWidth;
1306         if ( nM2 > nP2 )
1307             nM2 = nP2;
1308     }
1309     else
1310     {
1311         nM2 = nVirRight+1;
1312         nP2 = nM2;
1313     }
1314 
1315     // Obere/untere Kante ausgeben
1316     if ( b3DLook )
1317         maVirDev.SetLineColor( rStyleSettings.GetShadowColor() );
1318     else
1319         maVirDev.SetLineColor( rStyleSettings.GetWindowTextColor() );
1320     ImplVDrawLine( nVirLeft, nVirTop, nM1 - 1, nVirTop ); //top left line
1321     ImplVDrawLine( nM2 +1, nVirTop, nP2 -1, nVirTop );      //top right line
1322 
1323     // Jetzt wird zwischen dem Schatten ausgegeben
1324     nVirTop++;
1325     nVirBottom--;
1326 
1327     // Margin1, Margin2 und Zwischenraum ausgeben
1328     maVirDev.SetLineColor();
1329     if ( b3DLook )
1330         maVirDev.SetFillColor( rStyleSettings.GetFaceColor() );
1331     else
1332         maVirDev.SetFillColor( rStyleSettings.GetWindowColor() );
1333     if ( nM1 > nVirLeft )
1334         ImplVDrawRect( nP1, nVirTop, nM1-1, nVirBottom ); //left gray rectangle
1335     if ( nM2 < nP2 )
1336         ImplVDrawRect( nM2+1, nVirTop, nP2, nVirBottom ); //right gray rectangle
1337     if ( nM2-nM1 > 0 )
1338     {
1339         maVirDev.SetFillColor( rStyleSettings.GetWindowColor() );
1340         ImplVDrawRect( nM1, nVirTop, nM2-1, nVirBottom ); //center rectangle
1341     }
1342     if ( b3DLook )
1343     {
1344         maVirDev.SetLineColor( rStyleSettings.GetShadowColor() );
1345         if ( nM1 > nVirLeft )
1346         {
1347             ImplVDrawLine( nM1-1, nVirTop, nM1-1, nVirBottom );//right line of the left rectangle
1348             ImplVDrawLine( nP1, nVirBottom, nM1-1, nVirBottom );//bottom line of the left rectangle
1349             if ( nP1 >= nVirLeft )
1350             {
1351                 ImplVDrawLine( nP1, nVirTop, nP1, nVirBottom );//left line of the left rectangle
1352                 ImplVDrawLine( nP1, nVirBottom, nP1+1, nVirBottom );//?
1353             }
1354         }
1355         if ( nM2 < nP2 )
1356         {
1357             ImplVDrawLine( nM2+1, nVirBottom, nP2-1, nVirBottom );//bottom line of the right rectangle
1358             ImplVDrawLine( nM2+1, nVirTop, nM2+1, nVirBottom );//left line of the right rectangle
1359             if ( nP2 <= nVirRight+1 )
1360                 ImplVDrawLine( nP2-1, nVirTop, nP2-1, nVirBottom );//right line of the right rectangle
1361         }
1362     }
1363     else
1364     {
1365         maVirDev.SetLineColor( rStyleSettings.GetWindowTextColor() );
1366         if ( nP1 >= nVirLeft )
1367             ImplVDrawLine( nP1, nVirTop, nP1, nVirBottom+1 );
1368         if ( nM1 > nP1 )
1369             ImplVDrawLine( nM1, nVirTop, nM1, nVirBottom );
1370         if ( nM2 < nP2 )
1371             ImplVDrawLine( nM2, nVirTop, nM2, nVirBottom );
1372         if ( nP2 <= nVirRight+1 )
1373             ImplVDrawLine( nP2, nVirTop, nP2, nVirBottom+1 );
1374     }
1375 
1376     // Lineal-Beschriftung (nur wenn keine Bemassungspfeile)
1377     if ( !mpData->pArrows )
1378     {
1379         long    nMin = nVirLeft;
1380         long    nMax = nP2;
1381         long    nStart = mpData->bTextRTL ? mpData->nMargin2 + nNullVirOff : nNullVirOff;
1382         long    nCenter = nVirTop+((nVirBottom-nVirTop)/2);
1383 
1384         // Nicht Schatten uebermalen
1385         if ( nP1 > nVirLeft )
1386             nMin++;
1387         if ( nP2 < nVirRight )
1388             nMax--;
1389 
1390         // Draw captions
1391         ImplDrawTicks( nMin, nMax, nStart, nCenter );
1392     }
1393 
1394     // Draw borders
1395     if ( mpData->pBorders )
1396         ImplDrawBorders( nVirLeft, nP2, nVirTop, nVirBottom );
1397 
1398     // Draw indents
1399     if ( mpData->pIndents )
1400         ImplDrawIndents( nVirLeft, nP2, nVirTop-1, nVirBottom+1 );
1401 
1402     // Tabs
1403     if ( mpData->pTabs )
1404     {
1405         ImplDrawTabs( nVirLeft, nP2, nVirTop-1, nVirBottom+1 );
1406     }
1407 
1408     // Bemassungspfeile
1409     if ( mpData->pArrows )
1410         ImplDrawArrows( nVirTop+((nVirBottom-nVirTop)/2) );
1411 
1412     // Wir haben formatiert
1413     mbFormat = sal_False;
1414 }
1415 
1416 // -----------------------------------------------------------------------
1417 
1418 void Ruler::ImplInitExtraField( sal_Bool bUpdate )
1419 {
1420     // Extra-Field beruecksichtigen
1421     if ( mnWinStyle & WB_EXTRAFIELD )
1422     {
1423         maExtraRect.Left()   = RULER_OFF;
1424         maExtraRect.Top()    = RULER_OFF;
1425         maExtraRect.Right()  = RULER_OFF+mnVirHeight-1;
1426         maExtraRect.Bottom() = RULER_OFF+mnVirHeight-1;
1427         if(mpData->bTextRTL)
1428         {
1429             Size aWinSize = GetOutputSizePixel();
1430             if(mnWinStyle & WB_HORZ)
1431 				maExtraRect.Move(aWinSize.Width() - maExtraRect.GetWidth() - maExtraRect.Left(), 0);
1432 			else
1433 				maExtraRect.Move(0, aWinSize.Height() - maExtraRect.GetHeight() - maExtraRect.Top());
1434 			mnVirOff = 0;
1435         }
1436 		else
1437 	        mnVirOff = maExtraRect.Right()+1;
1438 
1439     }
1440     else
1441     {
1442         maExtraRect.SetEmpty();
1443         mnVirOff = 0;
1444     }
1445 
1446     if ( bUpdate )
1447     {
1448         mbCalc      = sal_True;
1449         mbFormat    = sal_True;
1450         Invalidate();
1451     }
1452 }
1453 
1454 // -----------------------------------------------------------------------
1455 
1456 void Ruler::ImplDraw()
1457 {
1458     if ( mbFormat )
1459         ImplFormat();
1460 
1461     if ( IsReallyVisible() )
1462     {
1463         // Lineal ueber das VirtualDevice ausgeben
1464         Point   aOffPos;
1465         Size    aVirDevSize = maVirDev.GetOutputSizePixel();
1466 //        Size    aVirDevSize2 = maVirDev.GetOutputSizePixel();
1467         if ( mnWinStyle & WB_HORZ )
1468         {
1469 			aOffPos.X() = mnVirOff;
1470 			if(mpData->bTextRTL)
1471 				aVirDevSize.Width() -= maExtraRect.GetWidth();
1472 
1473 //	else
1474 //		aVirDevSize.Width() -= mnVirOff;
1475             aOffPos.Y() = RULER_OFF;
1476         }
1477         else
1478         {
1479             aOffPos.X() = RULER_OFF;
1480 			aOffPos.Y() = mnVirOff;
1481 //	else
1482 //		aVirDevSize.Height() -= mnVirOff;
1483         }
1484         DrawOutDev( aOffPos, aVirDevSize, Point(), aVirDevSize, maVirDev );
1485 
1486         // Positionslinien neu malen
1487         ImplInvertLines( sal_True );
1488     }
1489 }
1490 
1491 // -----------------------------------------------------------------------
1492 
1493 void Ruler::ImplDrawExtra( sal_Bool bPaint )
1494 {
1495     const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
1496     Rectangle   aRect = maExtraRect;
1497     sal_Bool        bEraseRect = sal_False;
1498 
1499     if ( !(rStyleSettings.GetOptions() & STYLE_OPTION_MONO) )
1500     {
1501         aRect.Left()    += 2;
1502         aRect.Top()     += 2;
1503         aRect.Right()   -= 2;
1504         aRect.Bottom()  -= 2;
1505     }
1506     else
1507     {
1508         aRect.Left()    += 1;
1509         aRect.Top()     += 1;
1510         aRect.Right()   -= 1;
1511         aRect.Bottom()  -= 1;
1512     }
1513 
1514     if ( !bPaint && !(mnExtraStyle & RULER_STYLE_HIGHLIGHT) )
1515     {
1516         if ( !(rStyleSettings.GetOptions() & STYLE_OPTION_MONO) )
1517             SetFillColor( rStyleSettings.GetFaceColor() );
1518         else
1519             SetFillColor( rStyleSettings.GetWindowColor() );
1520         bEraseRect = sal_True;
1521     }
1522     else
1523     {
1524         if ( !(rStyleSettings.GetOptions() & STYLE_OPTION_MONO) && (mnExtraStyle & RULER_STYLE_HIGHLIGHT) )
1525         {
1526             SetFillColor( rStyleSettings.GetCheckedColor() );
1527             bEraseRect = sal_True;
1528         }
1529     }
1530 
1531     if ( bEraseRect )
1532     {
1533         SetLineColor();
1534         DrawRect( aRect );
1535     }
1536 
1537     // Inhalt ausgeben
1538     if ( meExtraType == RULER_EXTRA_NULLOFFSET )
1539     {
1540         if ( !(rStyleSettings.GetOptions() & STYLE_OPTION_MONO) )
1541             SetLineColor( rStyleSettings.GetButtonTextColor() );
1542         else
1543             SetLineColor( rStyleSettings.GetWindowTextColor() );
1544         DrawLine( Point( aRect.Left()+1, aRect.Top()+4 ),
1545                   Point( aRect.Right()-1, aRect.Top()+4 ) );
1546         DrawLine( Point( aRect.Left()+4, aRect.Top()+1 ),
1547                   Point( aRect.Left()+4, aRect.Bottom()-1 ) );
1548     }
1549     else if ( meExtraType == RULER_EXTRA_TAB )
1550     {
1551         sal_uInt16 nTabStyle = mnExtraStyle & RULER_TAB_STYLE;
1552         if(mpData->bTextRTL)
1553             nTabStyle |= RULER_TAB_RTL;
1554         Point aCenter = aRect.Center();
1555 		Point aDraw(aCenter);
1556         ImplCenterTabPos( aDraw, nTabStyle );
1557         WinBits nWinBits = GetStyle();
1558         if(0 == (nWinBits&WB_HORZ) )
1559 		{
1560 			if(0 != (nWinBits&WB_RIGHT_ALIGNED))
1561 				aDraw.Y() = 2 * aCenter.Y() - aDraw.Y();
1562 			if(mpData->bTextRTL)
1563 			{
1564 				long nTemp = aDraw.X();
1565 				aDraw.X() = aDraw.Y();
1566 				aDraw.Y() = nTemp;
1567 			}
1568 		}
1569         ImplDrawTab( this, aDraw, nTabStyle );
1570     }
1571 
1572     if ( (rStyleSettings.GetOptions() & STYLE_OPTION_MONO) && (mnExtraStyle & RULER_STYLE_HIGHLIGHT) )
1573         Invert( aRect );
1574 }
1575 
1576 // -----------------------------------------------------------------------
1577 
1578 void Ruler::ImplUpdate( sal_Bool bMustCalc )
1579 {
1580     // Hier schon Linien loeschen, damit Sie vor dem Neuberechnen schon
1581     // geloscht sind, da danach die alten Positionen nicht mehr bestimmt
1582     // werden koennen
1583     if ( !mbFormat )
1584         ImplInvertLines();
1585 
1586     // Flags setzen
1587     if ( bMustCalc )
1588         mbCalc = sal_True;
1589     mbFormat = sal_True;
1590 
1591     // Wenn wir am Draggen sind, wird nach dem Drag-Handler automatisch
1592     // das Lineal neu upgedatet
1593     if ( mbDrag )
1594         return;
1595 
1596     // Gegebenenfalls Update ausloesen
1597     if ( IsReallyVisible() && IsUpdateMode() )
1598     {
1599         mnUpdateFlags |= RULER_UPDATE_DRAW;
1600         if ( !mnUpdateEvtId )
1601             mnUpdateEvtId = Application::PostUserEvent( LINK( this, Ruler, ImplUpdateHdl ), NULL );
1602     }
1603 }
1604 
1605 // -----------------------------------------------------------------------
1606 
1607 sal_Bool Ruler::ImplHitTest( const Point& rPos, ImplRulerHitTest* pHitTest,
1608                          sal_Bool bRequireStyle, sal_uInt16 nRequiredStyle ) const
1609 {
1610     sal_uInt16      i;
1611     sal_uInt16      nStyle;
1612     long        nHitBottom;
1613     long        nX;
1614     long        nY;
1615     long        n1;
1616     long        n2;
1617 
1618     if ( !mbActive )
1619         return sal_False;
1620 
1621     // Position ermitteln
1622 	sal_Bool bIsHori = 0 != (mnWinStyle & WB_HORZ);
1623     if ( bIsHori )
1624     {
1625         nX = rPos.X();
1626         nY = rPos.Y();
1627     }
1628     else
1629     {
1630         nX = rPos.Y();
1631         nY = rPos.X();
1632     }
1633     nHitBottom = mnVirHeight+(RULER_OFF*2);
1634 
1635     // --> FME 2004-08-05 #i32608#
1636     pHitTest->nAryPos = 0;
1637     pHitTest->mnDragSize = 0;
1638     pHitTest->bSize = sal_False;
1639     pHitTest->bSizeBar = sal_False;
1640     // <--
1641 
1642     // Damit ueberstehende Tabs und Einzuege mit beruecksichtigt werden
1643     long nXExtraOff;
1644     if ( mpData->pTabs || mpData->pIndents )
1645         nXExtraOff = (mnVirHeight/2) - 4;
1646     else
1647         nXExtraOff = 0;
1648 
1649     // Test auf ausserhalb
1650     nX -= mnVirOff;
1651     long nXTemp = nX;
1652     if ( (nX < mpData->nRulVirOff-nXExtraOff) || (nX > mpData->nRulVirOff+mpData->nRulWidth+nXExtraOff) ||
1653          (nY < 0) || (nY > nHitBottom) )
1654     {
1655         pHitTest->nPos = 0;
1656         pHitTest->eType = RULER_TYPE_OUTSIDE;
1657         return sal_False;
1658     }
1659 
1660     nX -= mpData->nNullVirOff;
1661     pHitTest->nPos  = nX;
1662     pHitTest->eType = RULER_TYPE_DONTKNOW;
1663 
1664     // Zuerst die Tabs testen
1665     Rectangle aRect;
1666     if ( mpData->pTabs )
1667     {
1668         aRect.Bottom()  = nHitBottom;
1669         aRect.Top()     = aRect.Bottom()-RULER_TAB_HEIGHT-RULER_OFF;
1670 
1671         for ( i = mpData->nTabs; i; i-- )
1672         {
1673             nStyle = mpData->pTabs[i-1].nStyle;
1674             if ( !(nStyle & RULER_STYLE_INVISIBLE) )
1675             {
1676                 nStyle &= RULER_TAB_STYLE;
1677 
1678                 // Default-Tabs werden nur angezeigt
1679                 if ( nStyle != RULER_TAB_DEFAULT )
1680                 {
1681                     n1 = mpData->pTabs[i-1].nPos;
1682 
1683                     if ( nStyle == RULER_TAB_LEFT )
1684                     {
1685                         aRect.Left()    = n1;
1686                         aRect.Right()   = n1+RULER_TAB_WIDTH-1;
1687                     }
1688                     else if ( nStyle == RULER_TAB_RIGHT )
1689                     {
1690                         aRect.Right()   = n1;
1691                         aRect.Left()    = n1-RULER_TAB_WIDTH-1;
1692                     }
1693                     else
1694                     {
1695                         aRect.Left()    = n1-RULER_TAB_CWIDTH2+1;
1696                         aRect.Right()   = n1-RULER_TAB_CWIDTH2+RULER_TAB_CWIDTH;
1697                     }
1698 
1699 					if ( aRect.IsInside( Point( nX, nY ) ) )
1700                     {
1701                         pHitTest->eType     = RULER_TYPE_TAB;
1702                         pHitTest->nAryPos   = i-1;
1703                         return sal_True;
1704                     }
1705                 }
1706             }
1707         }
1708     }
1709 
1710     // Dann die Einzuege
1711     if ( mpData->pIndents )
1712     {
1713         long nIndentHeight = (mnVirHeight/2) - 1;
1714         long nIndentWidth2 = nIndentHeight-3;
1715 
1716         for ( i = mpData->nIndents; i; i-- )
1717         {
1718             nStyle = mpData->pIndents[i-1].nStyle;
1719             if ( (! bRequireStyle || nStyle == nRequiredStyle) &&
1720                  !(nStyle & RULER_STYLE_INVISIBLE) )
1721             {
1722                 nStyle &= RULER_INDENT_STYLE;
1723                 n1 = mpData->pIndents[i-1].nPos;
1724 
1725                 if ( (nStyle == RULER_INDENT_BOTTOM) ^ (!bIsHori) )
1726                 {
1727                     aRect.Left()    = n1-nIndentWidth2;
1728                     aRect.Right()   = n1+nIndentWidth2;
1729                     aRect.Top()     = nHitBottom-nIndentHeight-RULER_OFF+1;
1730                     aRect.Bottom()  = nHitBottom;
1731                 }
1732                 else
1733                 {
1734                     aRect.Left()    = n1-nIndentWidth2;
1735                     aRect.Right()   = n1+nIndentWidth2;
1736                     aRect.Top()     = 0;
1737                     aRect.Bottom()  = nIndentHeight+RULER_OFF-1;
1738                 }
1739 
1740                 if ( aRect.IsInside( Point( nX, nY ) ) )
1741                 {
1742                     pHitTest->eType     = RULER_TYPE_INDENT;
1743                     pHitTest->nAryPos   = i-1;
1744                     return sal_True;
1745                 }
1746             }
1747         }
1748     }
1749 
1750     // Jetzt zaehlt nichts mehr, was links oder rechts uebersteht
1751     if ( (nXTemp < mpData->nRulVirOff) || (nXTemp > mpData->nRulVirOff+mpData->nRulWidth) )
1752     {
1753         pHitTest->nPos = 0;
1754         pHitTest->eType = RULER_TYPE_OUTSIDE;
1755         return sal_False;
1756     }
1757 
1758     // Danach die Spalten testen
1759     int nBorderTolerance = 1;
1760     if(pHitTest->bExpandTest)
1761     {
1762         nBorderTolerance++;
1763     }
1764 
1765     for ( i = mpData->nBorders; i; i-- )
1766     {
1767         n1 = mpData->pBorders[i-1].nPos;
1768         n2 = n1 + mpData->pBorders[i-1].nWidth;
1769 
1770         // Spalten werden mit mindestens 3 Pixel breite gezeichnet
1771         if ( !mpData->pBorders[i-1].nWidth )
1772         {
1773              n1 -= nBorderTolerance;
1774              n2 += nBorderTolerance;
1775 
1776         }
1777 
1778         if ( (nX >= n1) && (nX <= n2) )
1779         {
1780             nStyle = mpData->pBorders[i-1].nStyle;
1781             if ( !(nStyle & RULER_STYLE_INVISIBLE) )
1782             {
1783                 pHitTest->eType     = RULER_TYPE_BORDER;
1784                 pHitTest->nAryPos   = i-1;
1785 
1786                 if ( !(nStyle & RULER_BORDER_SIZEABLE) )
1787                 {
1788                     if ( nStyle & RULER_BORDER_MOVEABLE )
1789                     {
1790                         pHitTest->bSizeBar = sal_True;
1791                         pHitTest->mnDragSize = RULER_DRAGSIZE_MOVE;
1792                     }
1793                 }
1794                 else
1795                 {
1796                     long nMOff = RULER_MOUSE_BORDERWIDTH;
1797                     while ( nMOff*2 >= (n2-n1-RULER_MOUSE_BORDERMOVE) )
1798                     {
1799                         if ( nMOff < 2 )
1800                         {
1801                             nMOff = 0;
1802                             break;
1803                         }
1804                         else
1805                             nMOff--;
1806                     }
1807 
1808                     if ( nX <= n1+nMOff )
1809                     {
1810                         pHitTest->bSize = sal_True;
1811                         pHitTest->mnDragSize = RULER_DRAGSIZE_1;
1812                     }
1813                     else if ( nX >= n2-nMOff )
1814                     {
1815                         pHitTest->bSize = sal_True;
1816                         pHitTest->mnDragSize = RULER_DRAGSIZE_2;
1817                     }
1818                     else
1819                     {
1820                         if ( nStyle & RULER_BORDER_MOVEABLE )
1821                         {
1822                             pHitTest->bSizeBar = sal_True;
1823                             pHitTest->mnDragSize = RULER_DRAGSIZE_MOVE;
1824                         }
1825                     }
1826                 }
1827 
1828                 return sal_True;
1829             }
1830         }
1831     }
1832 
1833     // Und zum Schluss die Raender
1834     int nMarginTolerance = pHitTest->bExpandTest ? nBorderTolerance : RULER_MOUSE_MARGINWIDTH;
1835 
1836     if ( (mpData->nMargin1Style & (RULER_MARGIN_SIZEABLE | RULER_STYLE_INVISIBLE)) == RULER_MARGIN_SIZEABLE )
1837     {
1838         n1 = mpData->nMargin1;
1839         if ( (nX >= n1 - nMarginTolerance) && (nX <= n1 + nMarginTolerance) )
1840         {
1841             pHitTest->eType = RULER_TYPE_MARGIN1;
1842             pHitTest->bSize = sal_True;
1843             return sal_True;
1844         }
1845     }
1846     if ( (mpData->nMargin2Style & (RULER_MARGIN_SIZEABLE | RULER_STYLE_INVISIBLE)) == RULER_MARGIN_SIZEABLE )
1847     {
1848         n1 = mpData->nMargin2;
1849         if ( (nX >= n1 - nMarginTolerance) && (nX <= n1 + nMarginTolerance) )
1850         {
1851             pHitTest->eType = RULER_TYPE_MARGIN2;
1852             pHitTest->bSize = sal_True;
1853             return sal_True;
1854         }
1855     }
1856 
1857     // Jetzt nocheinmal die Tabs testen, nur mit etwas mehr spielraum
1858     if ( mpData->pTabs )
1859     {
1860         aRect.Top()     = RULER_OFF;
1861         aRect.Bottom()  = nHitBottom;
1862 
1863         for ( i = mpData->nTabs; i; i-- )
1864         {
1865             nStyle = mpData->pTabs[i-1].nStyle;
1866             if ( !(nStyle & RULER_STYLE_INVISIBLE) )
1867             {
1868                 nStyle &= RULER_TAB_STYLE;
1869 
1870                 // Default-Tabs werden nur angezeigt
1871                 if ( nStyle != RULER_TAB_DEFAULT )
1872                 {
1873                     n1 = mpData->pTabs[i-1].nPos;
1874 
1875                     if ( nStyle == RULER_TAB_LEFT )
1876                     {
1877                         aRect.Left()    = n1;
1878                         aRect.Right()   = n1+RULER_TAB_WIDTH-1;
1879                     }
1880                     else if ( nStyle == RULER_TAB_RIGHT )
1881                     {
1882                         aRect.Right()   = n1;
1883                         aRect.Left()    = n1-RULER_TAB_WIDTH-1;
1884                     }
1885                     else
1886                     {
1887                         aRect.Left()    = n1-RULER_TAB_CWIDTH2+1;
1888                         aRect.Right()   = n1-RULER_TAB_CWIDTH2+RULER_TAB_CWIDTH;
1889                     }
1890 
1891                     aRect.Left()--;
1892                     aRect.Right()++;
1893 
1894                     if ( aRect.IsInside( Point( nX, nY ) ) )
1895                     {
1896                         pHitTest->eType     = RULER_TYPE_TAB;
1897                         pHitTest->nAryPos   = i-1;
1898                         return sal_True;
1899                     }
1900                 }
1901             }
1902         }
1903     }
1904 
1905     return sal_False;
1906 }
1907 
1908 // -----------------------------------------------------------------------
1909 
1910 sal_Bool Ruler::ImplDocHitTest( const Point& rPos, RulerType eDragType,
1911                             ImplRulerHitTest* pHitTest ) const
1912 {
1913     Point aPos = rPos;
1914     sal_Bool bRequiredStyle = sal_False;
1915     sal_uInt16 nRequiredStyle = 0;
1916 
1917     if (eDragType == RULER_TYPE_INDENT)
1918     {
1919         bRequiredStyle = sal_True;
1920         nRequiredStyle = RULER_INDENT_BOTTOM;
1921     }
1922 
1923     if ( mnWinStyle & WB_HORZ )
1924         aPos.X() += mnWinOff;
1925     else
1926         aPos.Y() += mnWinOff;
1927 
1928     if ( (eDragType == RULER_TYPE_INDENT) || (eDragType == RULER_TYPE_DONTKNOW) )
1929     {
1930         if ( mnWinStyle & WB_HORZ )
1931             aPos.Y() = RULER_OFF+1;
1932         else
1933             aPos.X() = RULER_OFF+1;
1934 
1935         // HitTest durchfuehren
1936         if ( ImplHitTest( aPos, pHitTest, bRequiredStyle, nRequiredStyle ) )
1937         {
1938             if ( (pHitTest->eType == eDragType) || (eDragType == RULER_TYPE_DONTKNOW) )
1939                 return sal_True;
1940         }
1941     }
1942 
1943     if ( (eDragType == RULER_TYPE_INDENT) || (eDragType == RULER_TYPE_TAB) ||
1944          (eDragType == RULER_TYPE_DONTKNOW) )
1945     {
1946         if ( mnWinStyle & WB_HORZ )
1947             aPos.Y() = mnHeight-RULER_OFF-1;
1948         else
1949             aPos.X() = mnWidth-RULER_OFF-1;
1950 
1951         // HitTest durchfuehren
1952         if ( ImplHitTest( aPos, pHitTest, bRequiredStyle, nRequiredStyle ) )
1953         {
1954             if ( (pHitTest->eType == eDragType) || (eDragType == RULER_TYPE_DONTKNOW) )
1955                 return sal_True;
1956         }
1957     }
1958 
1959     if ( (eDragType == RULER_TYPE_MARGIN1) || (eDragType == RULER_TYPE_MARGIN2) ||
1960          (eDragType == RULER_TYPE_BORDER) || (eDragType == RULER_TYPE_DONTKNOW) )
1961     {
1962         if ( mnWinStyle & WB_HORZ )
1963             aPos.Y() = RULER_OFF + (mnVirHeight/2);
1964         else
1965             aPos.X() = RULER_OFF + (mnVirHeight/2);
1966 
1967         // HitTest durchfuehren
1968         if ( ImplHitTest( aPos, pHitTest ) )
1969         {
1970             if ( (pHitTest->eType == eDragType) || (eDragType == RULER_TYPE_DONTKNOW) )
1971                 return sal_True;
1972         }
1973     }
1974 
1975     // Auf DontKnow setzen
1976     pHitTest->eType = RULER_TYPE_DONTKNOW;
1977 
1978     return sal_False;
1979 }
1980 
1981 // -----------------------------------------------------------------------
1982 
1983 sal_Bool Ruler::ImplStartDrag( ImplRulerHitTest* pHitTest, sal_uInt16 nModifier )
1984 {
1985     // Wenn eine Spalte angeklick wurde, die weder verschiebar noch
1986     // in der Groesse aenderbar ist, brauchen wir auch kein Drag ausloesen
1987     if ( (pHitTest->eType == RULER_TYPE_BORDER) &&
1988          !pHitTest->bSize && !pHitTest->bSizeBar )
1989         return sal_False;
1990 
1991     // Dragdaten setzen
1992     meDragType      = pHitTest->eType;
1993     mnDragPos       = pHitTest->nPos;
1994     mnDragAryPos    = pHitTest->nAryPos;
1995     mnDragSize      = pHitTest->mnDragSize;
1996     mnDragModifier  = nModifier;
1997     *mpDragData     = *mpSaveData;
1998     mpData          = mpDragData;
1999 
2000     // Handler rufen
2001     if ( StartDrag() )
2002     {
2003         // Wenn der Handler das Draggen erlaubt, dann das Draggen
2004         // initialisieren
2005         ImplInvertLines();
2006         mbDrag = sal_True;
2007         mnStartDragPos = mnDragPos;
2008         StartTracking();
2009         return sal_True;
2010     }
2011     else
2012     {
2013         // Ansonsten muessen wir die Daten zuruecksetzen
2014         meDragType      = RULER_TYPE_DONTKNOW;
2015         mnDragPos       = 0;
2016         mnDragAryPos    = 0;
2017         mnDragSize      = 0;
2018         mnDragModifier  = 0;
2019         mpData          = mpSaveData;
2020     }
2021 
2022     return sal_False;
2023 }
2024 
2025 // -----------------------------------------------------------------------
2026 
2027 void Ruler::ImplDrag( const Point& rPos )
2028 {
2029     long  nX;
2030     long  nY;
2031     long  nOutHeight;
2032 
2033     if ( mnWinStyle & WB_HORZ )
2034     {
2035         nX          = rPos.X();
2036         nY          = rPos.Y();
2037         nOutHeight  = mnHeight;
2038     }
2039     else
2040     {
2041         nX          = rPos.Y();
2042         nY          = rPos.X();
2043         nOutHeight  = mnWidth;
2044     }
2045 
2046     // X berechnen und einpassen
2047     nX -= mnVirOff;
2048     if ( nX < mpData->nRulVirOff )
2049     {
2050         nX = mpData->nRulVirOff;
2051         mnDragScroll = RULER_SCROLL_1;
2052     }
2053     else if ( nX > mpData->nRulVirOff+mpData->nRulWidth )
2054     {
2055         nX = mpData->nRulVirOff+mpData->nRulWidth;
2056         mnDragScroll = RULER_SCROLL_2;
2057     }
2058     nX -= mpData->nNullVirOff;
2059 
2060     // Wenn oberhalb oder links vom Lineal, dann alte Werte
2061     mbDragDelete = sal_False;
2062     if ( nY < 0 )
2063     {
2064         if ( !mbDragCanceled )
2065         {
2066             // Daten wiederherstellen
2067             mbDragCanceled = sal_True;
2068             ImplRulerData aTempData;
2069             aTempData = *mpDragData;
2070             *mpDragData = *mpSaveData;
2071             mbCalc = sal_True;
2072             mbFormat = sal_True;
2073 
2074             // Handler rufen
2075             mnDragPos = mnStartDragPos;
2076             Drag();
2077 
2078             // Und neu ausgeben (zeitverzoegert)
2079 /*
2080             mnUpdateFlags |= RULER_UPDATE_DRAW;
2081             if ( mnUpdateEvtId )
2082                 Application::RemoveUserEvent( mnUpdateEvtId );
2083             mnUpdateEvtId = Application::PostUserEvent( LINK( this, Ruler, ImplUpdateHdl ), NULL );
2084 */
2085             ImplDraw();
2086 
2087             // Daten wieder wie vor dem Cancel herstellen
2088             *mpDragData = aTempData;
2089         }
2090     }
2091     else
2092     {
2093         mbDragCanceled = sal_False;
2094 
2095         // +2, damit nicht so schnell die Tabs geloescht werden
2096         if ( nY > nOutHeight+2 )
2097             mbDragDelete = sal_True;
2098 
2099         mnDragPos = nX;
2100 
2101         // Handler rufen
2102         Drag();
2103 
2104         // Und neu ausgeben
2105         if ( mbFormat )
2106             ImplDraw();
2107     }
2108 
2109     mnDragScroll = 0;
2110 }
2111 
2112 // -----------------------------------------------------------------------
2113 
2114 void Ruler::ImplEndDrag()
2115 {
2116     // Werte uebernehmen
2117     if ( mbDragCanceled )
2118         *mpDragData = *mpSaveData;
2119     else
2120         *mpSaveData = *mpDragData;
2121     mpData = mpSaveData;
2122     mbDrag = sal_False;
2123 
2124     // Handler rufen
2125     EndDrag();
2126 
2127     // Drag-Werte zuruecksetzen
2128     meDragType      = RULER_TYPE_DONTKNOW;
2129     mnDragPos       = 0;
2130     mnDragAryPos    = 0;
2131     mnDragSize      = 0;
2132     mbDragCanceled  = sal_False;
2133     mbDragDelete    = sal_False;
2134     mnDragModifier  = 0;
2135     mnDragScroll    = 0;
2136     mnStartDragPos  = 0;
2137 
2138     // Und neu ausgeben
2139     ImplDraw();
2140 }
2141 
2142 // -----------------------------------------------------------------------
2143 
2144 IMPL_LINK( Ruler, ImplUpdateHdl, void*, EMPTYARG )
2145 {
2146     mnUpdateEvtId = 0;
2147 
2148     // Feststellen, was upgedatet werden muss
2149     if ( mnUpdateFlags & RULER_UPDATE_DRAW )
2150     {
2151         mnUpdateFlags = 0;
2152         ImplDraw();
2153     }
2154     else if ( mnUpdateFlags & RULER_UPDATE_LINES )
2155     {
2156         mnUpdateFlags = 0;
2157         ImplInvertLines();
2158     }
2159 
2160     return 0;
2161 }
2162 
2163 // -----------------------------------------------------------------------
2164 
2165 void Ruler::MouseButtonDown( const MouseEvent& rMEvt )
2166 {
2167     if ( rMEvt.IsLeft() && !IsTracking() )
2168     {
2169         Point   aMousePos = rMEvt.GetPosPixel();
2170         sal_uInt16  nMouseClicks = rMEvt.GetClicks();
2171         sal_uInt16  nMouseModifier = rMEvt.GetModifier();
2172 
2173         // Gegebenenfalls Lineal updaten (damit mit den richtigen Daten
2174         // gearbeitet wird und die Anzeige auch zur Bearbeitung passt)
2175         if ( mbFormat )
2176         {
2177             ImplDraw();
2178             mnUpdateFlags &= ~RULER_UPDATE_DRAW;
2179         }
2180 
2181         if ( maExtraRect.IsInside( aMousePos ) )
2182         {
2183             mnExtraClicks = nMouseClicks;
2184             mnExtraModifier = nMouseModifier;
2185             ExtraDown();
2186             mnExtraClicks = 0;
2187             mnExtraModifier = 0;
2188         }
2189         else
2190         {
2191             ImplRulerHitTest aHitTest;
2192 
2193             if ( nMouseClicks == 1 )
2194             {
2195                 if ( ImplHitTest( aMousePos, &aHitTest ) )
2196                     ImplStartDrag( &aHitTest, nMouseModifier );
2197                 else
2198                 {
2199                     // Position innerhalb des Lineal-Bereiches
2200                     if ( aHitTest.eType == RULER_TYPE_DONTKNOW )
2201                     {
2202                         mnDragPos = aHitTest.nPos;
2203                         Click();
2204                         mnDragPos = 0;
2205 
2206                         // Nocheinmal HitTest durchfuehren, da durch den Click
2207                         // zum Beispiel ein neuer Tab gesetzt werden konnte
2208                         if ( ImplHitTest( aMousePos, &aHitTest ) )
2209                             ImplStartDrag( &aHitTest, nMouseModifier );
2210                     }
2211                 }
2212             }
2213             else
2214             {
2215                 if ( ImplHitTest( aMousePos, &aHitTest ) )
2216                 {
2217                     mnDragPos    = aHitTest.nPos;
2218                     mnDragAryPos = aHitTest.nAryPos;
2219                 }
2220                 meDragType = aHitTest.eType;
2221 
2222                 DoubleClick();
2223 
2224                 meDragType      = RULER_TYPE_DONTKNOW;
2225                 mnDragPos       = 0;
2226                 mnDragAryPos    = 0;
2227             }
2228         }
2229     }
2230 }
2231 
2232 // -----------------------------------------------------------------------
2233 
2234 void Ruler::MouseMove( const MouseEvent& rMEvt )
2235 {
2236     PointerStyle ePtrStyle = POINTER_ARROW;
2237 
2238     // Gegebenenfalls Lineal updaten (damit mit den richtigen Daten
2239     // gearbeitet wird und die Anzeige auch zur Bearbeitung passt)
2240     if ( mbFormat )
2241     {
2242         ImplDraw();
2243         mnUpdateFlags &= ~RULER_UPDATE_DRAW;
2244     }
2245 
2246     ImplRulerHitTest aHitTest;
2247     if ( ImplHitTest( rMEvt.GetPosPixel(), &aHitTest ) )
2248     {
2249         if ( aHitTest.bSize )
2250         {
2251             if ( mnWinStyle & WB_HORZ )
2252                 ePtrStyle = POINTER_ESIZE;
2253             else
2254                 ePtrStyle = POINTER_SSIZE;
2255         }
2256         else if ( aHitTest.bSizeBar )
2257         {
2258             if ( mnWinStyle & WB_HORZ )
2259                 ePtrStyle = POINTER_HSIZEBAR;
2260             else
2261                 ePtrStyle = POINTER_VSIZEBAR;
2262         }
2263     }
2264 
2265     SetPointer( Pointer( ePtrStyle ) );
2266 }
2267 
2268 // -----------------------------------------------------------------------
2269 
2270 void Ruler::Tracking( const TrackingEvent& rTEvt )
2271 {
2272     if ( rTEvt.IsTrackingEnded() )
2273     {
2274         // Bei Abbruch, den alten Status wieder herstellen
2275         if ( rTEvt.IsTrackingCanceled() )
2276         {
2277             mbDragCanceled = sal_True;
2278             mbFormat       = sal_True;
2279         }
2280 
2281         ImplEndDrag();
2282     }
2283     else
2284         ImplDrag( rTEvt.GetMouseEvent().GetPosPixel() );
2285 }
2286 
2287 // -----------------------------------------------------------------------
2288 
2289 void Ruler::Paint( const Rectangle& )
2290 {
2291     ImplDraw();
2292 
2293     const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
2294 
2295     // Extra-Field beruecksichtigen
2296     if ( mnWinStyle & WB_EXTRAFIELD )
2297     {
2298         if ( !(rStyleSettings.GetOptions() & STYLE_OPTION_MONO) )
2299         {
2300             SetLineColor( rStyleSettings.GetShadowColor() );
2301             DrawLine( Point( maExtraRect.Left(), maExtraRect.Top() ),
2302                       Point( maExtraRect.Right()-1, maExtraRect.Top() ) );
2303             DrawLine( Point( maExtraRect.Left(), maExtraRect.Top() ),
2304                       Point( maExtraRect.Left(), maExtraRect.Bottom()-1 ) );
2305             DrawLine( Point( maExtraRect.Left(), maExtraRect.Bottom()-1 ),
2306                       Point( maExtraRect.Right()-1, maExtraRect.Bottom()-1 ) );
2307             DrawLine( Point( maExtraRect.Right()-1, maExtraRect.Top() ),
2308                       Point( maExtraRect.Right()-1, maExtraRect.Bottom()-1 ) );
2309             SetLineColor( rStyleSettings.GetLightColor() );
2310             DrawLine( Point( maExtraRect.Left()+1, maExtraRect.Top()+1 ),
2311                       Point( maExtraRect.Right()-2, maExtraRect.Top()+1 ) );
2312             DrawLine( Point( maExtraRect.Left()+1, maExtraRect.Top()+1 ),
2313                       Point( maExtraRect.Left()+1, maExtraRect.Bottom()-2 ) );
2314             DrawLine( Point( maExtraRect.Left(), maExtraRect.Bottom() ),
2315                       Point( maExtraRect.Right(), maExtraRect.Bottom() ) );
2316             DrawLine( Point( maExtraRect.Right(), maExtraRect.Top() ),
2317                       Point( maExtraRect.Right(), maExtraRect.Bottom() ) );
2318         }
2319         else
2320         {
2321             SetLineColor( rStyleSettings.GetWindowTextColor() );
2322             SetFillColor( rStyleSettings.GetWindowColor() );
2323             DrawRect( maExtraRect );
2324         }
2325 
2326         // Imhalt vom Extrafeld ausgeben
2327         ImplDrawExtra( sal_True );
2328     }
2329 
2330     if ( mnWinStyle & WB_BORDER )
2331     {
2332         if ( mnWinStyle & WB_HORZ )
2333         {
2334             if ( !(rStyleSettings.GetOptions() & STYLE_OPTION_MONO) )
2335             {
2336                 SetLineColor( rStyleSettings.GetShadowColor() );
2337                 DrawLine( Point( mnBorderOff, mnHeight-2 ),
2338                           Point( mnWidth, mnHeight-2 ) );
2339                 if ( mnBorderOff )
2340                 {
2341                     DrawLine( Point( mnBorderOff-1, mnHeight-2 ),
2342                               Point( mnBorderOff-1, mnHeight-1 ) );
2343                 }
2344             }
2345             SetLineColor( rStyleSettings.GetWindowTextColor() );
2346             DrawLine( Point( mnBorderOff, mnHeight-1 ),
2347                       Point( mnWidth, mnHeight-1 ) );
2348         }
2349         else
2350         {
2351             if ( !(rStyleSettings.GetOptions() & STYLE_OPTION_MONO) )
2352             {
2353                 SetLineColor( rStyleSettings.GetShadowColor() );
2354                 DrawLine( Point( mnWidth-2, mnBorderOff ),
2355                           Point( mnWidth-2, mnHeight ) );
2356                 if ( mnBorderOff )
2357                 {
2358                     DrawLine( Point( mnWidth-2, mnBorderOff-1 ),
2359                               Point( mnWidth-1, mnBorderOff-1 ) );
2360                 }
2361             }
2362             SetLineColor( rStyleSettings.GetWindowTextColor() );
2363             DrawLine( Point( mnWidth-1, mnBorderOff ),
2364                       Point( mnWidth-1, mnHeight ) );
2365         }
2366     }
2367 }
2368 
2369 // -----------------------------------------------------------------------
2370 
2371 void Ruler::Resize()
2372 {
2373     Size aWinSize = GetOutputSizePixel();
2374 
2375     long nNewHeight;
2376     if ( mnWinStyle & WB_HORZ )
2377     {
2378         if ( aWinSize.Height() != mnHeight )
2379             nNewHeight = aWinSize.Height();
2380         else
2381             nNewHeight = 0;
2382     }
2383     else
2384     {
2385         if ( aWinSize.Width() != mnWidth )
2386             nNewHeight = aWinSize.Width();
2387         else
2388             nNewHeight = 0;
2389     }
2390 
2391     // Hier schon Linien loeschen
2392     sal_Bool bVisible = IsReallyVisible();
2393     if ( bVisible && mpData->nLines )
2394     {
2395         ImplInvertLines();
2396         mnUpdateFlags |= RULER_UPDATE_LINES;
2397         if ( !mnUpdateEvtId )
2398             mnUpdateEvtId = Application::PostUserEvent( LINK( this, Ruler, ImplUpdateHdl ), NULL );
2399     }
2400     mbFormat = sal_True;
2401 
2402     // Wenn sich die Hoehe bzw. Breite aendert, dann muessen besimmte Werte
2403     // neu berechnet werden
2404     //extra field should always be updated
2405     ImplInitExtraField( mpData->bTextRTL );
2406     if ( nNewHeight )
2407     {
2408         mbCalc = sal_True;
2409         mnVirHeight = nNewHeight - mnBorderWidth - (RULER_OFF*2);
2410     }
2411     else
2412     {
2413         if ( mpData->bAutoPageWidth )
2414             ImplUpdate( sal_True );
2415         else if ( mbAutoWinWidth )
2416             mbCalc = sal_True;
2417     }
2418 
2419     // Wenn Ruler eine Groesse hat, dann Groesse vom VirtualDevice setzen
2420     if ( (mnVirWidth > RULER_MIN_SIZE) ||
2421          ((aWinSize.Width() > RULER_MIN_SIZE) && (aWinSize.Height() > RULER_MIN_SIZE)) )
2422     {
2423         if ( mnWinStyle & WB_HORZ )
2424             mnVirWidth = aWinSize.Width()-mnVirOff;
2425         else
2426             mnVirWidth = aWinSize.Height()-mnVirOff;
2427         if ( mnVirWidth < RULER_MIN_SIZE )
2428             mnVirWidth = 0;
2429     }
2430 
2431     // Gegebenenfalls ein Teil vom Rand loeschen, da 3D-Effekt/Trennlinie am
2432     // Fensterrand
2433     if ( bVisible )
2434     {
2435         if ( nNewHeight )
2436             Invalidate();
2437         else if ( mpData->bAutoPageWidth )
2438         {
2439             // Nur bei AutoPageWidth haben wir rechts einen 3D-Effekt,
2440             // der sich der Fensterbreite anpasst und deshalb neu gezeichnet
2441             // werden muss
2442             Rectangle aRect;
2443 
2444             if ( mnWinStyle & WB_HORZ )
2445             {
2446                 if ( mnWidth < aWinSize.Width() )
2447                     aRect.Left() = mnWidth-RULER_RESIZE_OFF;
2448                 else
2449                     aRect.Left() = aWinSize.Width()-RULER_RESIZE_OFF;
2450                 aRect.Right()   = aRect.Left()+RULER_RESIZE_OFF;
2451                 aRect.Top()     = RULER_OFF;
2452                 aRect.Bottom()  = RULER_OFF+mnVirHeight;
2453             }
2454             else
2455             {
2456                 if ( mnHeight < aWinSize.Height() )
2457                     aRect.Top() = mnHeight-RULER_RESIZE_OFF;
2458                 else
2459                     aRect.Top() = aWinSize.Height()-RULER_RESIZE_OFF;
2460                 aRect.Bottom() = aRect.Top()+RULER_RESIZE_OFF;
2461                 aRect.Left()    = RULER_OFF;
2462                 aRect.Right()   = RULER_OFF+mnVirHeight;
2463             }
2464 
2465             Invalidate( aRect );
2466         }
2467     }
2468 
2469     // Neue Groesse merken
2470     mnWidth  = aWinSize.Width();
2471     mnHeight = aWinSize.Height();
2472 }
2473 
2474 // -----------------------------------------------------------------------
2475 
2476 void Ruler::StateChanged( StateChangedType nType )
2477 {
2478     Window::StateChanged( nType );
2479 
2480     if ( nType == STATE_CHANGE_INITSHOW )
2481         ImplFormat();
2482     else if ( nType == STATE_CHANGE_UPDATEMODE )
2483     {
2484         if ( IsReallyVisible() && IsUpdateMode() )
2485             ImplDraw();
2486     }
2487     else if ( (nType == STATE_CHANGE_ZOOM) ||
2488               (nType == STATE_CHANGE_CONTROLFONT) )
2489     {
2490         ImplInitSettings( sal_True, sal_False, sal_False );
2491         Invalidate();
2492     }
2493     else if ( nType == STATE_CHANGE_CONTROLFOREGROUND )
2494     {
2495         ImplInitSettings( sal_False, sal_True, sal_False );
2496         Invalidate();
2497     }
2498     else if ( nType == STATE_CHANGE_CONTROLBACKGROUND )
2499     {
2500         ImplInitSettings( sal_False, sal_False, sal_True );
2501         Invalidate();
2502     }
2503 }
2504 
2505 // -----------------------------------------------------------------------
2506 
2507 void Ruler::DataChanged( const DataChangedEvent& rDCEvt )
2508 {
2509     Window::DataChanged( rDCEvt );
2510 
2511     if ( (rDCEvt.GetType() == DATACHANGED_FONTS) ||
2512          (rDCEvt.GetType() == DATACHANGED_DISPLAY) ||
2513          (rDCEvt.GetType() == DATACHANGED_FONTSUBSTITUTION) ||
2514          ((rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
2515           (rDCEvt.GetFlags() & SETTINGS_STYLE)) )
2516     {
2517         mbFormat = sal_True;
2518         ImplInitSettings( sal_True, sal_True, sal_True );
2519         Invalidate();
2520     }
2521 }
2522 
2523 // -----------------------------------------------------------------------
2524 
2525 long Ruler::StartDrag()
2526 {
2527     if ( maStartDragHdl.IsSet() )
2528         return maStartDragHdl.Call( this );
2529     else
2530         return sal_False;
2531 }
2532 
2533 // -----------------------------------------------------------------------
2534 
2535 void Ruler::Drag()
2536 {
2537     maDragHdl.Call( this );
2538 }
2539 
2540 // -----------------------------------------------------------------------
2541 
2542 void Ruler::EndDrag()
2543 {
2544     maEndDragHdl.Call( this );
2545 }
2546 
2547 // -----------------------------------------------------------------------
2548 
2549 void Ruler::Click()
2550 {
2551     maClickHdl.Call( this );
2552 }
2553 
2554 // -----------------------------------------------------------------------
2555 
2556 void Ruler::DoubleClick()
2557 {
2558     maDoubleClickHdl.Call( this );
2559 }
2560 
2561 // -----------------------------------------------------------------------
2562 
2563 void Ruler::ExtraDown()
2564 {
2565     maExtraDownHdl.Call( this );
2566 }
2567 
2568 // -----------------------------------------------------------------------
2569 
2570 void Ruler::Activate()
2571 {
2572     mbActive = sal_True;
2573 
2574     // Positionslinien wieder anzeigen (erst hinter mbActive=sal_True rufen, da
2575     // von ImplInvertLines() ausgewertet wird). Das Zeichnen der Linien
2576     // wird verzoegert, damit im vermutlich noch nicht gepainteten Zustand
2577     // Linien gezeichnet werden.
2578     mnUpdateFlags |= RULER_UPDATE_LINES;
2579     if ( !mnUpdateEvtId )
2580         mnUpdateEvtId = Application::PostUserEvent( LINK( this, Ruler, ImplUpdateHdl ), NULL );
2581 }
2582 
2583 // -----------------------------------------------------------------------
2584 
2585 void Ruler::Deactivate()
2586 {
2587     // Positionslinien loeschen (schon vor mbActive=sal_False rufen, da
2588     // von ImplInvertLines() ausgewertet wird)
2589     ImplInvertLines();
2590 
2591     mbActive = sal_False;
2592 }
2593 
2594 // -----------------------------------------------------------------------
2595 
2596 sal_Bool Ruler::StartDocDrag( const MouseEvent& rMEvt, RulerType eDragType )
2597 {
2598     if ( !mbDrag )
2599     {
2600         Point               aMousePos = rMEvt.GetPosPixel();
2601         sal_uInt16              nMouseClicks = rMEvt.GetClicks();
2602         sal_uInt16              nMouseModifier = rMEvt.GetModifier();
2603         ImplRulerHitTest    aHitTest;
2604         if(eDragType != RULER_TYPE_DONTKNOW)
2605             aHitTest.bExpandTest = sal_True;
2606 
2607         // Gegebenenfalls Lineal updaten (damit mit den richtigen Daten
2608         // gearbeitet wird und die Anzeige auch zur Bearbeitung passt)
2609         if ( mbFormat )
2610         {
2611             ImplDraw();
2612             mnUpdateFlags &= ~RULER_UPDATE_DRAW;
2613         }
2614 
2615         if ( nMouseClicks == 1 )
2616         {
2617             if ( ImplDocHitTest( aMousePos, eDragType, &aHitTest ) )
2618             {
2619                 Pointer aPtr;
2620 
2621                 if ( aHitTest.bSize )
2622                 {
2623                     if ( mnWinStyle & WB_HORZ )
2624                         aPtr = Pointer( POINTER_ESIZE );
2625                     else
2626                         aPtr = Pointer( POINTER_SSIZE );
2627                 }
2628                 else if ( aHitTest.bSizeBar )
2629                 {
2630                     if ( mnWinStyle & WB_HORZ )
2631                         aPtr = Pointer( POINTER_HSIZEBAR );
2632                     else
2633                         aPtr = Pointer( POINTER_VSIZEBAR );
2634                 }
2635                 SetPointer( aPtr );
2636                 return ImplStartDrag( &aHitTest, nMouseModifier );
2637             }
2638         }
2639         else if ( nMouseClicks == 2 )
2640         {
2641             if ( ImplDocHitTest( aMousePos, eDragType, &aHitTest ) )
2642             {
2643                 mnDragPos    = aHitTest.nPos;
2644                 mnDragAryPos = aHitTest.nAryPos;
2645             }
2646             eDragType = aHitTest.eType;
2647 
2648             DoubleClick();
2649 
2650             eDragType       = RULER_TYPE_DONTKNOW;
2651             mnDragPos       = 0;
2652             mnDragAryPos    = 0;
2653 
2654             return sal_True;
2655         }
2656     }
2657 
2658     return sal_False;
2659 }
2660 
2661 // -----------------------------------------------------------------------
2662 
2663 RulerType Ruler::GetDocType( const Point& rPos, RulerType eDragType,
2664                              sal_uInt16* pAryPos ) const
2665 {
2666     ImplRulerHitTest aHitTest;
2667 
2668     // Gegebenenfalls Lineal updaten (damit mit den richtigen Daten
2669     // gearbeitet wird und die Anzeige auch zur Bearbeitung passt)
2670     if ( IsReallyVisible() && mbFormat )
2671     {
2672         ((Ruler*)this)->ImplDraw();
2673         ((Ruler*)this)->mnUpdateFlags &= ~RULER_UPDATE_DRAW;
2674     }
2675 
2676     // HitTest durchfuehren
2677     ImplDocHitTest( rPos, eDragType, &aHitTest );
2678 
2679     // Werte zurueckgeben
2680     if ( pAryPos )
2681         *pAryPos = aHitTest.nAryPos;
2682     return aHitTest.eType;
2683 }
2684 
2685 // -----------------------------------------------------------------------
2686 
2687 void Ruler::CancelDrag()
2688 {
2689     if ( mbDrag )
2690     {
2691         ImplDrag( Point( -1, -1 ) );
2692         ImplEndDrag();
2693     }
2694 }
2695 
2696 // -----------------------------------------------------------------------
2697 
2698 RulerType Ruler::GetType( const Point& rPos, sal_uInt16* pAryPos ) const
2699 {
2700     ImplRulerHitTest aHitTest;
2701 
2702     // Gegebenenfalls Lineal updaten (damit mit den richtigen Daten
2703     // gearbeitet wird und die Anzeige auch zur Bearbeitung passt)
2704     if ( IsReallyVisible() && mbFormat )
2705     {
2706         ((Ruler*)this)->ImplDraw();
2707         ((Ruler*)this)->mnUpdateFlags &= ~RULER_UPDATE_DRAW;
2708     }
2709 
2710     // HitTest durchfuehren
2711     ImplHitTest( rPos, &aHitTest );
2712 
2713     // Werte zurueckgeben
2714     if ( pAryPos )
2715         *pAryPos = aHitTest.nAryPos;
2716     return aHitTest.eType;
2717 }
2718 
2719 // -----------------------------------------------------------------------
2720 
2721 void Ruler::SetWinPos( long nNewOff, long nNewWidth )
2722 {
2723     // Gegebenenfalls werden die Breiten automatisch berechnet
2724     if ( !nNewWidth )
2725         mbAutoWinWidth = sal_True;
2726     else
2727         mbAutoWinWidth = sal_False;
2728 
2729     // Werte setzen (werden in ImplFormat gegebenenfalls mitberechnet)
2730     mnWinOff = nNewOff;
2731     mnWinWidth = nNewWidth;
2732     ImplUpdate( sal_True );
2733 }
2734 
2735 // -----------------------------------------------------------------------
2736 
2737 void Ruler::SetPagePos( long nNewOff, long nNewWidth )
2738 {
2739     // Muessen wir ueberhaupt was machen
2740     if ( (mpData->nPageOff == nNewOff) && (mpData->nPageWidth == nNewWidth) )
2741         return;
2742 
2743     // Gegebenenfalls werden die Breiten automatisch berechnet
2744     if ( !nNewWidth )
2745         mpData->bAutoPageWidth = sal_True;
2746     else
2747         mpData->bAutoPageWidth = sal_False;
2748 
2749     // Werte setzen (werden in ImplFormat gegebenenfalls mitberechnet)
2750     mpData->nPageOff     = nNewOff;
2751     mpData->nPageWidth   = nNewWidth;
2752     ImplUpdate( sal_True );
2753 }
2754 
2755 // -----------------------------------------------------------------------
2756 
2757 void Ruler::SetBorderPos( long nOff )
2758 {
2759     if ( mnWinStyle & WB_BORDER )
2760     {
2761         if ( mnBorderOff != nOff )
2762         {
2763             mnBorderOff = nOff;
2764 
2765             if ( IsReallyVisible() && IsUpdateMode() )
2766                 Invalidate();
2767         }
2768     }
2769 }
2770 
2771 // -----------------------------------------------------------------------
2772 
2773 void Ruler::SetUnit( FieldUnit eNewUnit )
2774 {
2775     if ( meUnit != eNewUnit )
2776     {
2777         meUnit = eNewUnit;
2778         switch ( meUnit )
2779         {
2780             case FUNIT_MM:
2781                 mnUnitIndex = RULER_UNIT_MM;
2782                 break;
2783             case FUNIT_CM:
2784                 mnUnitIndex = RULER_UNIT_CM;
2785                 break;
2786             case FUNIT_M:
2787                 mnUnitIndex = RULER_UNIT_M;
2788                 break;
2789             case FUNIT_KM:
2790                 mnUnitIndex = RULER_UNIT_KM;
2791                 break;
2792             case FUNIT_INCH:
2793                 mnUnitIndex = RULER_UNIT_INCH;
2794                 break;
2795             case FUNIT_FOOT:
2796                 mnUnitIndex = RULER_UNIT_FOOT;
2797                 break;
2798             case FUNIT_MILE:
2799                 mnUnitIndex = RULER_UNIT_MILE;
2800                 break;
2801             case FUNIT_POINT:
2802                 mnUnitIndex = RULER_UNIT_POINT;
2803                 break;
2804             case FUNIT_PICA:
2805                 mnUnitIndex = RULER_UNIT_PICA;
2806                 break;
2807             default:
2808 #ifdef DBG_UTIL
2809                 DBG_ERRORFILE( "Ruler::SetUnit() - Wrong Unit" );
2810 #endif
2811                 break;
2812         }
2813 
2814         maMapMode.SetMapUnit( aImplRulerUnitTab[mnUnitIndex].eMapUnit );
2815         ImplUpdate();
2816     }
2817 }
2818 
2819 // -----------------------------------------------------------------------
2820 
2821 void Ruler::SetZoom( const Fraction& rNewZoom )
2822 {
2823     DBG_ASSERT( rNewZoom.GetNumerator(), "Ruler::SetZoom() with scale 0 is not allowed" );
2824 
2825     if ( maZoom != rNewZoom )
2826     {
2827         maZoom = rNewZoom;
2828         maMapMode.SetScaleX( maZoom );
2829         maMapMode.SetScaleY( maZoom );
2830         ImplUpdate();
2831     }
2832 }
2833 
2834 // -----------------------------------------------------------------------
2835 
2836 void Ruler::SetExtraType( RulerExtra eNewExtraType, sal_uInt16 nStyle )
2837 {
2838     if ( mnWinStyle & WB_EXTRAFIELD )
2839     {
2840         meExtraType  = eNewExtraType;
2841         mnExtraStyle = nStyle;
2842         if ( IsReallyVisible() && IsUpdateMode() )
2843             ImplDrawExtra( sal_False );
2844     }
2845 }
2846 
2847 // -----------------------------------------------------------------------
2848 
2849 void Ruler::SetNullOffset( long nPos )
2850 {
2851     if ( mpData->nNullOff != nPos )
2852     {
2853         mpData->nNullOff = nPos;
2854         ImplUpdate();
2855     }
2856 }
2857 
2858 // -----------------------------------------------------------------------
2859 
2860 void Ruler::SetMargin1( long nPos, sal_uInt16 nMarginStyle )
2861 {
2862     if ( (mpData->nMargin1 != nPos) || (mpData->nMargin1Style != nMarginStyle) )
2863     {
2864         mpData->nMargin1      = nPos;
2865         mpData->nMargin1Style = nMarginStyle;
2866         ImplUpdate();
2867     }
2868 }
2869 
2870 // -----------------------------------------------------------------------
2871 
2872 void Ruler::SetMargin2( long nPos, sal_uInt16 nMarginStyle )
2873 {
2874     DBG_ASSERT( (nPos >= mpData->nMargin1) ||
2875                 (mpData->nMargin1Style & RULER_STYLE_INVISIBLE) ||
2876                 (mpData->nMargin2Style & RULER_STYLE_INVISIBLE),
2877                 "Ruler::SetMargin2() - Margin2 < Margin1" );
2878 
2879     if ( (mpData->nMargin2 != nPos) || (mpData->nMargin2Style != nMarginStyle) )
2880     {
2881         mpData->nMargin2      = nPos;
2882         mpData->nMargin2Style = nMarginStyle;
2883         ImplUpdate();
2884     }
2885 }
2886 
2887 // -----------------------------------------------------------------------
2888 
2889 void Ruler::SetLines( sal_uInt16 n, const RulerLine* pLineAry )
2890 {
2891     // To determine if what has changed
2892     if ( mpData->nLines == n )
2893     {
2894         sal_uInt16           i = n;
2895         const RulerLine* pAry1 = mpData->pLines;
2896         const RulerLine* pAry2 = pLineAry;
2897         while ( i )
2898         {
2899             if ( (pAry1->nPos   != pAry2->nPos)   ||
2900                  (pAry1->nStyle != pAry2->nStyle) )
2901                 break;
2902             pAry1++;
2903             pAry2++;
2904             i--;
2905         }
2906         if ( !i )
2907             return;
2908     }
2909 
2910     // New values and new share issue
2911     sal_Bool bMustUpdate;
2912     if ( IsReallyVisible() && IsUpdateMode() )
2913         bMustUpdate = sal_True;
2914     else
2915         bMustUpdate = sal_False;
2916 
2917     // Delete old lines
2918     if ( bMustUpdate )
2919         ImplInvertLines();
2920 
2921     // New data set
2922     if ( !n || !pLineAry )
2923     {
2924         if ( !mpData->pLines )
2925             return;
2926         delete[] mpData->pLines;
2927         mpData->nLines = 0;
2928         mpData->pLines = NULL;
2929     }
2930     else
2931     {
2932         if ( mpData->nLines != n )
2933         {
2934             delete[] mpData->pLines;
2935             mpData->nLines = n;
2936             mpData->pLines = new RulerLine[n];
2937         }
2938 
2939         memcpy( mpData->pLines, pLineAry, n*sizeof( RulerLine ) );
2940 
2941         // Linien neu ausgeben
2942         if ( bMustUpdate )
2943             ImplInvertLines();
2944     }
2945 }
2946 
2947 // -----------------------------------------------------------------------
2948 
2949 void Ruler::SetArrows( sal_uInt16 n, const RulerArrow* pArrowAry )
2950 {
2951     if ( !n || !pArrowAry )
2952     {
2953         if ( !mpData->pArrows )
2954             return;
2955         delete[] mpData->pArrows;
2956         mpData->nArrows = 0;
2957         mpData->pArrows = NULL;
2958     }
2959     else
2960     {
2961         if ( mpData->nArrows != n )
2962         {
2963             delete[] mpData->pArrows;
2964             mpData->nArrows = n;
2965             mpData->pArrows = new RulerArrow[n];
2966         }
2967         else
2968         {
2969             sal_uInt16            i = n;
2970             const RulerArrow* pAry1 = mpData->pArrows;
2971             const RulerArrow* pAry2 = pArrowAry;
2972             while ( i )
2973             {
2974                 if ( (pAry1->nPos      != pAry2->nPos)      ||
2975                      (pAry1->nWidth    != pAry2->nWidth)    ||
2976                      (pAry1->nLogWidth != pAry2->nLogWidth) ||
2977                      (pAry1->nStyle    != pAry2->nStyle) )
2978                     break;
2979                 pAry1++;
2980                 pAry2++;
2981                 i--;
2982             }
2983             if ( !i )
2984                 return;
2985         }
2986 
2987         memcpy( mpData->pArrows, pArrowAry, n*sizeof( RulerArrow ) );
2988     }
2989 
2990     ImplUpdate();
2991 }
2992 
2993 // -----------------------------------------------------------------------
2994 
2995 void Ruler::SetBorders( sal_uInt16 n, const RulerBorder* pBrdAry )
2996 {
2997     if ( !n || !pBrdAry )
2998     {
2999         if ( !mpData->pBorders )
3000             return;
3001         delete[] mpData->pBorders;
3002         mpData->nBorders = 0;
3003         mpData->pBorders = NULL;
3004     }
3005     else
3006     {
3007         if ( mpData->nBorders != n )
3008         {
3009             delete[] mpData->pBorders;
3010             mpData->nBorders = n;
3011             mpData->pBorders = new RulerBorder[n];
3012         }
3013         else
3014         {
3015             sal_uInt16             i = n;
3016             const RulerBorder* pAry1 = mpData->pBorders;
3017             const RulerBorder* pAry2 = pBrdAry;
3018             while ( i )
3019             {
3020                 if ( (pAry1->nPos   != pAry2->nPos)   ||
3021                      (pAry1->nWidth != pAry2->nWidth) ||
3022                      (pAry1->nStyle != pAry2->nStyle) )
3023                     break;
3024                 pAry1++;
3025                 pAry2++;
3026                 i--;
3027             }
3028             if ( !i )
3029                 return;
3030         }
3031 
3032         memcpy( mpData->pBorders, pBrdAry, n*sizeof( RulerBorder ) );
3033     }
3034 
3035     ImplUpdate();
3036 }
3037 
3038 // -----------------------------------------------------------------------
3039 
3040 void Ruler::SetIndents( sal_uInt16 n, const RulerIndent* pIndentAry )
3041 {
3042 
3043     if ( !n || !pIndentAry )
3044     {
3045         if ( !mpData->pIndents )
3046             return;
3047         delete[] mpData->pIndents;
3048         mpData->nIndents = 0;
3049         mpData->pIndents = NULL;
3050     }
3051     else
3052     {
3053         if ( mpData->nIndents != n )
3054         {
3055             delete[] mpData->pIndents;
3056             mpData->nIndents = n;
3057             mpData->pIndents = new RulerIndent[n];
3058         }
3059         else
3060         {
3061             sal_uInt16             i = n;
3062             const RulerIndent* pAry1 = mpData->pIndents;
3063             const RulerIndent* pAry2 = pIndentAry;
3064             while ( i )
3065             {
3066                 if ( (pAry1->nPos   != pAry2->nPos) ||
3067                      (pAry1->nStyle != pAry2->nStyle) )
3068                     break;
3069                 pAry1++;
3070                 pAry2++;
3071                 i--;
3072             }
3073             if ( !i )
3074                 return;
3075         }
3076 
3077         memcpy( mpData->pIndents, pIndentAry, n*sizeof( RulerIndent ) );
3078     }
3079 
3080     ImplUpdate();
3081 }
3082 
3083 // -----------------------------------------------------------------------
3084 
3085 void Ruler::SetTabs( sal_uInt16 n, const RulerTab* pTabAry )
3086 {
3087     if ( !n || !pTabAry )
3088     {
3089         if ( !mpData->pTabs )
3090             return;
3091         delete[] mpData->pTabs;
3092         mpData->nTabs = 0;
3093         mpData->pTabs = NULL;
3094     }
3095     else
3096     {
3097         if ( mpData->nTabs != n )
3098         {
3099             delete[] mpData->pTabs;
3100             mpData->nTabs = n;
3101             mpData->pTabs = new RulerTab[n];
3102         }
3103         else
3104         {
3105             sal_uInt16          i = n;
3106             const RulerTab* pAry1 = mpData->pTabs;
3107             const RulerTab* pAry2 = pTabAry;
3108             while ( i )
3109             {
3110                 if ( (pAry1->nPos   != pAry2->nPos) ||
3111                      (pAry1->nStyle != pAry2->nStyle) )
3112                     break;
3113                 pAry1++;
3114                 pAry2++;
3115                 i--;
3116             }
3117             if ( !i )
3118                 return;
3119         }
3120 
3121         memcpy( mpData->pTabs, pTabAry, n*sizeof( RulerTab ) );
3122     }
3123 
3124     ImplUpdate();
3125 }
3126 
3127 // -----------------------------------------------------------------------
3128 
3129 void Ruler::SetStyle( WinBits nStyle )
3130 {
3131     if ( mnWinStyle != nStyle )
3132     {
3133         mnWinStyle = nStyle;
3134         ImplInitExtraField( sal_True );
3135     }
3136 }
3137 
3138 // -----------------------------------------------------------------------
3139 
3140 void Ruler::DrawTab( OutputDevice* pDevice, const Point& rPos, sal_uInt16 nStyle )
3141 {
3142     /*const StyleSettings&    rStyleSettings =*/ pDevice->GetSettings().GetStyleSettings();
3143     Point                   aPos( rPos );
3144     sal_uInt16                  nTabStyle = nStyle & (RULER_TAB_STYLE | RULER_TAB_RTL);
3145 
3146     pDevice->Push( PUSH_LINECOLOR | PUSH_FILLCOLOR );
3147     pDevice->SetLineColor();
3148     pDevice->SetFillColor( pDevice->GetSettings().GetStyleSettings().GetWindowTextColor() );
3149     ImplCenterTabPos( aPos, nTabStyle );
3150     ImplDrawRulerTab( pDevice, aPos, nTabStyle, nStyle  );
3151     pDevice->Pop();
3152 }
3153 /* -----------------16.10.2002 15:17-----------------
3154  *
3155  * --------------------------------------------------*/
3156 void Ruler::SetTextRTL(sal_Bool bRTL)
3157 {
3158     if(mpData->bTextRTL != bRTL)
3159     {
3160         mpData->bTextRTL = bRTL;
3161         if ( IsReallyVisible() && IsUpdateMode() )
3162             ImplInitExtraField( sal_True );
3163     }
3164 
3165 }
3166 long Ruler::GetPageOffset() const { return mpData->nPageOff; }
3167 long                Ruler::GetPageWidth() const { return mpData->nPageWidth; }
3168 long                Ruler::GetNullOffset() const { return mpData->nNullOff; }
3169 long                Ruler::GetMargin1() const { return mpData->nMargin1; }
3170 sal_uInt16              Ruler::GetMargin1Style() const { return mpData->nMargin1Style; }
3171 long                Ruler::GetMargin2() const { return mpData->nMargin2; }
3172 sal_uInt16              Ruler::GetMargin2Style() const { return mpData->nMargin2Style; }
3173 sal_uInt16              Ruler::GetLineCount() const { return mpData->nLines; }
3174 const RulerLine*    Ruler::GetLines() const { return mpData->pLines; }
3175 sal_uInt16              Ruler::GetArrowCount() const { return mpData->nArrows; }
3176 const RulerArrow*   Ruler::GetArrows() const { return mpData->pArrows; }
3177 sal_uInt16              Ruler::GetBorderCount() const { return mpData->nBorders; }
3178 const RulerBorder*  Ruler::GetBorders() const { return mpData->pBorders; }
3179 sal_uInt16              Ruler::GetIndentCount() const { return mpData->nIndents; }
3180 const RulerIndent*  Ruler::GetIndents() const { return mpData->pIndents; }
3181 
3182