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