merge the formfield patch from ooo-build
[ooovba.git] / svtools / source / control / ruler.cxx
blobe9753c06801c1e9282c5a0f1c84cb5f431b48a71
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ruler.cxx,v $
10 * $Revision: 1.27 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svtools.hxx"
34 #include <string.h>
35 #include <tools/debug.hxx>
36 #include <vcl/svapp.hxx>
37 #include <tools/poly.hxx>
39 #include <vcl/i18nhelp.hxx>
41 #define _SV_RULER_CXX
42 #include <ruler.hxx>
44 // =======================================================================
46 #define RULER_OFF 3
47 #define RULER_TEXTOFF 2
48 #define RULER_RESIZE_OFF 4
49 #define RULER_LINE_WIDTH 7
50 #define RULER_MIN_SIZE 3
52 #define RULER_TICK1_WIDTH 1
53 #define RULER_TICK2_WIDTH 3
54 #define RULER_TICK3_WIDTH 5
56 #define RULER_VAR_SIZE 8
58 #define RULER_TAB_HEIGHT2 2
59 #define RULER_TAB_WIDTH2 2
60 #define RULER_TAB_CWIDTH 8
61 #define RULER_TAB_CWIDTH2 4
62 #define RULER_TAB_CWIDTH3 4
63 #define RULER_TAB_CWIDTH4 2
64 #define RULER_TAB_DHEIGHT 4
65 #define RULER_TAB_DHEIGHT2 1
66 #define RULER_TAB_DWIDTH 5
67 #define RULER_TAB_DWIDTH2 3
68 #define RULER_TAB_DWIDTH3 3
69 #define RULER_TAB_DWIDTH4 1
71 #define RULER_UPDATE_LINES 0x01
72 #define RULER_UPDATE_DRAW 0x02
74 #define RULER_CLIP 150
76 // =======================================================================
78 #define RULER_UNIT_MM 0
79 #define RULER_UNIT_CM 1
80 #define RULER_UNIT_M 2
81 #define RULER_UNIT_KM 3
82 #define RULER_UNIT_INCH 4
83 #define RULER_UNIT_FOOT 5
84 #define RULER_UNIT_MILE 6
85 #define RULER_UNIT_POINT 7
86 #define RULER_UNIT_PICA 8
87 #define RULER_UNIT_CHAR 9
88 #define RULER_UNIT_LINE 10
89 #define RULER_UNIT_COUNT 11
91 // -----------------
92 // - ImplRulerData -
93 // -----------------
94 class ImplRulerData
96 friend class Ruler;
98 private:
99 RulerLine* pLines;
100 RulerArrow* pArrows;
101 RulerBorder* pBorders;
102 RulerIndent* pIndents;
103 RulerTab* pTabs;
104 long nNullVirOff;
105 long nRulVirOff;
106 long nRulWidth;
107 long nPageOff;
108 long nPageWidth;
109 long nNullOff;
110 long nMargin1;
111 long nMargin2;
112 USHORT nLines;
113 USHORT nArrows;
114 USHORT nBorders;
115 USHORT nIndents;
116 USHORT nTabs;
117 USHORT nMargin1Style;
118 USHORT nMargin2Style;
119 BOOL bAutoPageWidth;
120 BOOL bTextRTL;
122 #ifdef _SV_RULER_CXX
123 public:
124 ImplRulerData();
125 ~ImplRulerData();
126 ImplRulerData& operator=( const ImplRulerData& rData );
127 #endif
131 struct ImplRulerUnitData
133 MapUnit eMapUnit; // MAP_UNIT zum Umrechnen
134 long nTickUnit; // Teiler fuer Einheit
135 long nTick1; // Schrittweite
136 long nTick2; // Tick fuer halbe Werte
137 long nTick3; // Tick fuer Zahlenausgabe
138 long n100THMM; // Teiler fuer Einheit
139 USHORT nUnitDigits; // Anzahl Nachkommastellen
140 sal_Char aUnitStr[8]; // Einheiten-String
143 static ImplRulerUnitData aImplRulerUnitTab[RULER_UNIT_COUNT] =
145 { MAP_100TH_MM, 100, 25, 50, 100, 100, 3, " mm" }, // MM
146 { MAP_100TH_MM, 1000, 250, 500, 1000, 1000, 3, " cm" }, // CM
147 { MAP_MM, 1000, 250, 500, 1000, 10000, 4, " m" }, // M
148 { MAP_CM, 100000, 25000, 50000, 100000, 100000, 6, " km" }, // KM
149 { MAP_100TH_INCH, 100, 10, 50, 100, 2540, 3, "\"" }, // INCH
150 { MAP_100TH_INCH, 1200, 120, 600, 1200, 30480, 3, "'" }, // FOOT
151 { MAP_10TH_INCH, 633600, 63360, 316800, 633600, 1609344, 4, " miles" }, // MILE
152 { MAP_POINT, 1, 12, 12, 36, 353, 2, " pt" }, // POINT
153 { MAP_100TH_MM, 423, 423, 423, 846, 423, 3, " pi" }, // PICA
154 { MAP_100TH_MM, 371, 371, 371, 743, 371, 3, " ch" }, // CHAR
155 { MAP_100TH_MM, 551, 551, 551, 1102, 551, 3, " li" } // LINE
158 // =======================================================================
160 struct ImplRulerHitTest
162 long nPos;
163 RulerType eType;
164 USHORT nAryPos;
165 USHORT mnDragSize;
166 BOOL bSize;
167 BOOL bSizeBar;
168 BOOL bExpandTest;
169 ImplRulerHitTest() :
170 bExpandTest( FALSE ) {}
173 // =======================================================================
175 ImplRulerData::ImplRulerData()
177 memset( this, 0, sizeof( ImplRulerData ) );
179 // PageBreite == EditWinBreite
180 bAutoPageWidth = TRUE;
183 // -----------------------------------------------------------------------
185 ImplRulerData::~ImplRulerData()
187 delete[] pLines;
188 delete[] pArrows;
189 delete[] pBorders;
190 delete[] pIndents;
191 delete[] pTabs;
194 // -----------------------------------------------------------------------
196 ImplRulerData& ImplRulerData::operator=( const ImplRulerData& rData )
198 delete[] pLines;
199 delete[] pArrows;
200 delete[] pBorders;
201 delete[] pIndents;
202 delete[] pTabs;
204 memcpy( this, &rData, sizeof( ImplRulerData ) );
206 if ( rData.pLines )
208 pLines = new RulerLine[nLines];
209 memcpy( pLines, rData.pLines, nLines*sizeof( RulerLine ) );
212 if ( rData.pArrows )
214 pArrows = new RulerArrow[nArrows];
215 memcpy( pArrows, rData.pArrows, nArrows*sizeof( RulerArrow ) );
218 if ( rData.pBorders )
220 pBorders = new RulerBorder[nBorders];
221 memcpy( pBorders, rData.pBorders, nBorders*sizeof( RulerBorder ) );
224 if ( rData.pIndents )
226 pIndents = new RulerIndent[nIndents];
227 memcpy( pIndents, rData.pIndents, nIndents*sizeof( RulerIndent ) );
230 if ( rData.pTabs )
232 pTabs = new RulerTab[nTabs];
233 memcpy( pTabs, rData.pTabs, nTabs*sizeof( RulerTab ) );
236 return *this;
239 // =======================================================================
241 void Ruler::ImplInit( WinBits nWinBits )
243 const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
245 // Default WinBits setzen
246 if ( !(nWinBits & WB_VERT) )
248 nWinBits |= WB_HORZ;
250 // --- RTL --- no UI mirroring for horizontal rulers, because
251 // the document is also not mirrored
252 EnableRTL( FALSE );
255 // Variablen initialisieren
256 mnWinStyle = nWinBits; // Window-Style
257 mnBorderOff = 0; // Border-Offset
258 mnWinOff = 0; // EditWinOffset
259 mnWinWidth = 0; // EditWinWidth
260 mnWidth = 0; // Fensterbreite
261 mnHeight = 0; // Fensterhoehe
262 mnVirOff = 0; // Offset des VirtualDeice vom linke/oberen Rand
263 mnVirWidth = 0; // Breite bzw. Hoehe vom VirtualDevice
264 mnVirHeight = 0; // Hoehe bzw. Breite vom VirtualDevice
265 mnDragPos = 0; // Drag-Position (NullPunkt)
266 mnUpdateEvtId = 0; // Noch kein Update-Event verschickt
267 mnDragAryPos = 0; // Drag-Array-Index
268 mnDragSize = 0; // Wird beim Draggen die Groesse geaendert
269 mnDragScroll = 0; // Soll beim Draggen gescrollt werden
270 mnDragModifier = 0; // Modifier-Tasten beim Draggen
271 mnExtraStyle = 0; // Style des Extra-Feldes
272 mnExtraClicks = 0; // Click-Anzahl fuer Extra-Feld
273 mnExtraModifier = 0; // Modifier-Tasten beim Click im Extrafeld
274 mnCharWidth = 371;
275 mnLineHeight = 551;
276 mbCalc = TRUE; // Muessen Pagebreiten neu berechnet werden
277 mbFormat = TRUE; // Muss neu ausgegeben werden
278 mbDrag = FALSE; // Sind wir im Drag-Modus
279 mbDragDelete = FALSE; // Wird Maus beim Draggen unten rausgezogen
280 mbDragCanceled = FALSE; // Wurde Dragging abgebrochen
281 mbAutoWinWidth = TRUE; // EditWinBreite == RulerBreite
282 mbActive = TRUE; // Ist Lineal aktiv
283 mnUpdateFlags = 0; // Was soll im Update-Handler upgedatet werden
284 mpData = mpSaveData; // Wir zeigen auf die normalen Daten
285 meExtraType = RULER_EXTRA_DONTKNOW; // Was im ExtraFeld dargestellt wird
286 meDragType = RULER_TYPE_DONTKNOW; // Gibt an, was gedragt wird
288 // Units initialisieren
289 mnUnitIndex = RULER_UNIT_CM;
290 meUnit = FUNIT_CM;
291 maZoom = Fraction( 1, 1 );
292 meSourceUnit = MAP_100TH_MM;
294 // Border-Breiten berechnen
295 if ( nWinBits & WB_BORDER )
297 if ( !(rStyleSettings.GetOptions() & STYLE_OPTION_MONO) )
298 mnBorderWidth = 2;
299 else
300 mnBorderWidth = 1;
302 else
303 mnBorderWidth = 0;
305 // Einstellungen setzen
306 ImplInitSettings( TRUE, TRUE, TRUE );
308 // Default-Groesse setzen
309 long nDefHeight = GetTextHeight() + RULER_OFF*2 + RULER_TEXTOFF*2 + mnBorderWidth;
310 Size aDefSize;
311 if ( nWinBits & WB_HORZ )
312 aDefSize.Height() = nDefHeight;
313 else
314 aDefSize.Width() = nDefHeight;
315 SetOutputSizePixel( aDefSize );
318 // -----------------------------------------------------------------------
320 Ruler::Ruler( Window* pParent, WinBits nWinStyle ) :
321 Window( pParent, nWinStyle & WB_3DLOOK ),
322 maVirDev( *this ),
323 maMapMode( MAP_100TH_MM ),
324 mpSaveData(new ImplRulerData),
325 mpData(0),
326 mpDragData(new ImplRulerData)
328 ImplInit( nWinStyle );
331 // -----------------------------------------------------------------------
333 Ruler::~Ruler()
335 if ( mnUpdateEvtId )
336 Application::RemoveUserEvent( mnUpdateEvtId );
337 delete mpSaveData;
338 delete mpDragData;
341 // -----------------------------------------------------------------------
343 void Ruler::ImplVDrawLine( long nX1, long nY1, long nX2, long nY2 )
345 if ( nX1 < -RULER_CLIP )
347 nX1 = -RULER_CLIP;
348 if ( nX2 < -RULER_CLIP )
349 return;
351 long nClip = mnVirWidth+RULER_CLIP;
352 if ( nX2 > nClip )
354 nX2 = nClip;
355 if ( nX1 > nClip )
356 return;
359 if ( mnWinStyle & WB_HORZ )
360 maVirDev.DrawLine( Point( nX1, nY1 ), Point( nX2, nY2 ) );
361 else
362 maVirDev.DrawLine( Point( nY1, nX1 ), Point( nY2, nX2 ) );
365 // -----------------------------------------------------------------------
367 void Ruler::ImplVDrawRect( long nX1, long nY1, long nX2, long nY2 )
369 if ( nX1 < -RULER_CLIP )
371 nX1 = -RULER_CLIP;
372 if ( nX2 < -RULER_CLIP )
373 return;
375 long nClip = mnVirWidth+RULER_CLIP;
376 if ( nX2 > nClip )
378 nX2 = nClip;
379 if ( nX1 > nClip )
380 return;
383 if ( mnWinStyle & WB_HORZ )
384 maVirDev.DrawRect( Rectangle( nX1, nY1, nX2, nY2 ) );
385 else
386 maVirDev.DrawRect( Rectangle( nY1, nX1, nY2, nX2 ) );
389 // -----------------------------------------------------------------------
391 void Ruler::ImplVDrawText( long nX, long nY, const String& rText )
393 if ( (nX > -RULER_CLIP) && (nX < mnVirWidth+RULER_CLIP) )
395 if ( mnWinStyle & WB_HORZ )
396 maVirDev.DrawText( Point( nX, nY ), rText );
397 else
398 maVirDev.DrawText( Point( nY, nX ), rText );
402 // -----------------------------------------------------------------------
404 void Ruler::ImplInvertLines( BOOL bErase )
406 // Positionslinien
407 if ( mpData->nLines && mbActive && !mbDrag && !mbFormat &&
408 !(mnUpdateFlags & RULER_UPDATE_LINES) )
410 long n;
411 long nNullWinOff = mpData->nNullVirOff+mnVirOff;
412 long nRulX1 = mpData->nRulVirOff+mnVirOff;
413 long nRulX2 = nRulX1+mpData->nRulWidth;
414 long nY = (RULER_OFF*2)+mnVirHeight-1;
416 // Rectangle berechnen
417 Rectangle aRect;
418 if ( mnWinStyle & WB_HORZ )
419 aRect.Bottom() = nY;
420 else
421 aRect.Right() = nY;
423 // Linien ausgeben
424 for ( USHORT i = 0; i < mpData->nLines; i++ )
426 n = mpData->pLines[i].nPos+nNullWinOff;
427 if ( (n >= nRulX1) && (n < nRulX2) )
429 if ( mnWinStyle & WB_HORZ )
431 aRect.Left() = n;
432 aRect.Right() = n;
434 else
436 aRect.Top() = n;
437 aRect.Bottom() = n;
439 if ( bErase )
441 Rectangle aTempRect = aRect;
442 if ( mnWinStyle & WB_HORZ )
443 aTempRect.Bottom() = RULER_OFF-1;
444 else
445 aTempRect.Right() = RULER_OFF-1;
446 Erase( aTempRect );
447 if ( mnWinStyle & WB_HORZ )
449 aTempRect.Bottom() = aRect.Bottom();
450 aTempRect.Top() = aTempRect.Bottom()-RULER_OFF+1;
452 else
454 aTempRect.Right() = aRect.Right();
455 aTempRect.Left() = aTempRect.Right()-RULER_OFF+1;
457 Erase( aTempRect );
459 Invert( aRect );
465 // -----------------------------------------------------------------------
467 void Ruler::ImplDrawTicks( long nMin, long nMax, long nStart, long nCenter )
469 long n = 0;
470 long nTick = 0;
471 long nTick3 = aImplRulerUnitTab[mnUnitIndex].nTick3;
472 long nTickCount = aImplRulerUnitTab[mnUnitIndex].nTick1;
473 Size aPixSize = maVirDev.LogicToPixel( Size( nTick3, nTick3 ), maMapMode );
474 long nTickWidth;
475 long nX;
476 long nY;
477 BOOL bNoTicks = FALSE;
479 //Amelia
480 long nTickUnit ;
481 long nTick2 ;
482 if ( mnUnitIndex == RULER_UNIT_CHAR )
484 if ( mnCharWidth == 0 )
485 mnCharWidth = 371;
486 nTick3 = mnCharWidth*2;
487 nTickCount = mnCharWidth;
488 nTickUnit = mnCharWidth;
489 nTick2 = mnCharWidth;
491 else if ( mnUnitIndex == RULER_UNIT_LINE )
493 if ( mnLineHeight == 0 )
494 mnLineHeight = 551;
495 nTick3 = mnLineHeight*2;
496 nTickCount = mnLineHeight;
497 nTickUnit = mnLineHeight;
498 nTick2 = mnLineHeight;
500 aPixSize = maVirDev.LogicToPixel( Size( nTick3, nTick3 ), maMapMode );
502 // Groessenvorberechnung
503 BOOL bVertRight = FALSE;
504 if ( mnWinStyle & WB_HORZ )
505 nTickWidth = aPixSize.Width();
506 else
508 Font aFont = GetFont();
509 if ( mnWinStyle & WB_RIGHT_ALIGNED )
511 aFont.SetOrientation( 2700 );
512 bVertRight = TRUE;
514 else
515 aFont.SetOrientation( 900 );
516 maVirDev.SetFont( aFont );
517 nTickWidth = aPixSize.Height();
519 long nMaxWidth = maVirDev.PixelToLogic( Size( mpData->nPageWidth, 0 ), maMapMode ).Width();
520 if ( nMaxWidth < 0 )
521 nMaxWidth *= -1;
522 // Amelia
523 if (( mnUnitIndex == RULER_UNIT_CHAR ) || ( mnUnitIndex == RULER_UNIT_LINE ))
524 nMaxWidth /= nTickUnit;
525 else
526 nMaxWidth /= aImplRulerUnitTab[mnUnitIndex].nTickUnit;
527 UniString aNumStr( UniString::CreateFromInt32( nMaxWidth ) );
528 long nTxtWidth = GetTextWidth( aNumStr );
529 if ( (nTxtWidth*2) > nTickWidth )
531 long nMulti = 1;
532 long nOrgTick3 = nTick3;
533 long nTextOff = 2;
534 while ( nTickWidth < nTxtWidth+nTextOff )
536 long nOldMulti = nMulti;
537 if ( !nTickWidth )
538 nMulti *= 10;
539 else if ( nMulti < 10 )
540 nMulti++;
541 else if ( nMulti < 100 )
542 nMulti += 10;
543 else if ( nMulti < 1000 )
544 nMulti += 100;
545 else
546 nMulti += 1000;
547 // Ueberlauf, dann geben wir nichts aus, da wir bei so einem
548 // unsinnigen Massstab sowieso nichts vernuenftiges anzeigen
549 // koennen
550 if ( nMulti < nOldMulti )
552 bNoTicks = TRUE;
553 break;
555 if ( nMulti >= 100 )
556 nTextOff = 4;
557 nTick3 = nOrgTick3 * nMulti;
558 aPixSize = maVirDev.LogicToPixel( Size( nTick3, nTick3 ), maMapMode );
559 if ( mnWinStyle & WB_HORZ )
560 nTickWidth = aPixSize.Width();
561 else
562 nTickWidth = aPixSize.Height();
564 nTickCount = nTick3;
566 else
567 maVirDev.SetLineColor( GetSettings().GetStyleSettings().GetWindowTextColor() );
569 if ( !bNoTicks )
571 long nTxtWidth2;
572 long nTxtHeight2 = GetTextHeight()/2;
573 while ( ((nStart-n) >= nMin) || ((nStart+n) <= nMax) )
575 // Null-Punkt
576 if ( !nTick )
578 if ( nStart > nMin )
580 // Nur 0 malen, wenn Margin1 nicht gleich dem NullPunkt ist
581 if ( (mpData->nMargin1Style & RULER_STYLE_INVISIBLE) || (mpData->nMargin1 != 0) )
583 aNumStr = (sal_Unicode)'0';
584 nTxtWidth2 = maVirDev.GetTextWidth( aNumStr )/2;
585 if ( (mnWinStyle & WB_HORZ)^mpData->bTextRTL )
586 nX = nStart-nTxtWidth2;
587 else
588 nX = nStart+nTxtWidth2;
589 long n_Y = bVertRight ? nCenter+nTxtHeight2 : nCenter-nTxtHeight2;
590 ImplVDrawText( nX, n_Y, aNumStr );
594 else
596 aPixSize = maVirDev.LogicToPixel( Size( nTick, nTick ), maMapMode );
598 if ( mnWinStyle & WB_HORZ )
599 n = aPixSize.Width();
600 else
601 n = aPixSize.Height();
603 // Tick3 - Ausgabe (Text)
604 if ( !(nTick % nTick3) )
606 //aNumStr = UniString::CreateFromInt32( nTick / aImplRulerUnitTab[mnUnitIndex].nTickUnit );
607 if ( ( mnUnitIndex == RULER_UNIT_CHAR ) || ( mnUnitIndex == RULER_UNIT_LINE ) )
608 aNumStr = UniString::CreateFromInt32( nTick / nTickUnit );
609 else
610 aNumStr = UniString::CreateFromInt32( nTick / aImplRulerUnitTab[mnUnitIndex].nTickUnit );
611 nTxtWidth2 = GetTextWidth( aNumStr )/2;
613 nX = nStart+n;
614 //different orientation needs a different starting position
615 nY = bVertRight ? nCenter+nTxtHeight2 : nCenter-nTxtHeight2;
616 if ( nX < nMax )
618 if ( mnWinStyle & WB_HORZ )
619 nX -= nTxtWidth2;
620 else
621 nX += nTxtWidth2;
622 ImplVDrawText( nX, nY, aNumStr );
624 nX = nStart-n;
625 if ( nX > nMin )
627 if ( mnWinStyle & WB_HORZ )
628 nX -= nTxtWidth2;
629 else
630 nX += nTxtWidth2;
631 ImplVDrawText( nX, nY, aNumStr );
634 // Tick/Tick2 - Ausgabe (Striche)
635 else
637 /// Amelia
638 if ( ( mnUnitIndex != RULER_UNIT_CHAR ) && ( mnUnitIndex != RULER_UNIT_LINE ) )
639 nTick2 = aImplRulerUnitTab[mnUnitIndex].nTick2;
640 if ( !(nTick % nTick2 ) )
641 nTickWidth = RULER_TICK2_WIDTH;
642 else
643 nTickWidth = RULER_TICK1_WIDTH;
644 long nT1 = nCenter-(nTickWidth/2);
645 long nT2 = nT1+nTickWidth-1;
646 long nT;
648 nT = nStart+n;
649 if ( nT < nMax )
650 ImplVDrawLine( nT, nT1, nT, nT2 );
651 nT = nStart-n;
652 if ( nT > nMin )
653 ImplVDrawLine( nT, nT1, nT, nT2 );
656 // #i49017# with some zoom factors the value nTick can overflow
657 if( ((ULONG)nTick + (ULONG)nTickCount) > (ULONG)LONG_MAX)
658 break;
659 nTick += nTickCount;
664 // -----------------------------------------------------------------------
666 void Ruler::ImplDrawArrows( long nCenter )
668 USHORT i;
669 long n1;
670 long n2;
671 long n3;
672 long n4;
673 long nLogWidth;
674 String aStr;
675 String aStr2;
676 BOOL bDrawUnit;
677 long nTxtWidth;
678 long nTxtHeight2 = GetTextHeight()/2;
680 const vcl::I18nHelper& rI18nHelper = GetSettings().GetLocaleI18nHelper();
682 maVirDev.SetLineColor( GetSettings().GetStyleSettings().GetWindowTextColor() );
683 for ( i = 0; i < mpData->nArrows; i++ )
685 n1 = mpData->pArrows[i].nPos+mpData->nNullVirOff+1;
686 n2 = n1+mpData->pArrows[i].nWidth-2;
688 // Einheit umrechnen
689 nLogWidth = mpData->pArrows[i].nLogWidth;
690 if ( meSourceUnit == MAP_TWIP )
692 if ( nLogWidth >= 100000 )
693 nLogWidth = (nLogWidth*254)/144;
694 else
695 nLogWidth = (nLogWidth*2540)/1440;
697 if ( nLogWidth >= 1000000 )
698 nLogWidth = (nLogWidth / aImplRulerUnitTab[mnUnitIndex].n100THMM) * 1000;
699 else
700 nLogWidth = (nLogWidth*1000) / aImplRulerUnitTab[mnUnitIndex].n100THMM;
701 aStr = rI18nHelper.GetNum( nLogWidth, aImplRulerUnitTab[mnUnitIndex].nUnitDigits, TRUE, FALSE );
703 // Einheit an den String haengen
704 aStr2 = aStr;
705 aStr2.AppendAscii( aImplRulerUnitTab[mnUnitIndex].aUnitStr );
707 // Textbreite ermitteln
708 bDrawUnit = TRUE;
709 nTxtWidth = GetTextWidth( aStr2 );
710 if ( nTxtWidth < mpData->pArrows[i].nWidth-10 )
711 aStr = aStr2;
712 else
714 nTxtWidth = GetTextWidth( aStr );
715 if ( nTxtWidth > mpData->pArrows[i].nWidth-10 )
716 bDrawUnit = FALSE;
719 // Ist genuegen Platz fuer Einheiten-String vorhanden
720 if ( bDrawUnit )
722 n3 = n1 + ((n2-n1)/2) - 1;
723 if ( mnWinStyle & WB_HORZ )
724 n3 -= nTxtWidth/2;
725 else
726 n3 += nTxtWidth/2;
727 if ( mnWinStyle & WB_HORZ )
729 n4 = n3 + nTxtWidth + 2;
730 ImplVDrawLine( n1, nCenter, n3, nCenter );
731 ImplVDrawLine( n4, nCenter, n2, nCenter );
733 else
735 n4 = n3 - nTxtWidth - 2;
736 ImplVDrawLine( n1, nCenter, n4, nCenter );
737 ImplVDrawLine( n3, nCenter, n2, nCenter );
739 ImplVDrawText( n3, nCenter-nTxtHeight2, aStr );
741 else
742 ImplVDrawLine( n1, nCenter, n2, nCenter );
743 ImplVDrawLine( n1+1, nCenter-1, n1+1, nCenter+1 );
744 ImplVDrawLine( n1+2, nCenter-2, n1+2, nCenter+2 );
745 ImplVDrawLine( n2-1, nCenter-1, n2-1, nCenter+1 );
746 ImplVDrawLine( n2-2, nCenter-2, n2-2, nCenter+2 );
750 // -----------------------------------------------------------------------
752 void Ruler::ImplDrawBorders( long nMin, long nMax, long nVirTop, long nVirBottom )
754 const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
755 long n;
756 long n1;
757 long n2;
758 long nTemp1;
759 long nTemp2;
760 USHORT i;
762 for ( i = 0; i < mpData->nBorders; i++ )
764 if ( mpData->pBorders[i].nStyle & RULER_STYLE_INVISIBLE )
765 continue;
767 n1 = mpData->pBorders[i].nPos+mpData->nNullVirOff;
768 n2 = n1+mpData->pBorders[i].nWidth;
770 if ( ((n1 >= nMin) && (n1 <= nMax)) || ((n2 >= nMin) && (n2 <= nMax)) )
772 if ( (n2-n1) > 3 )
774 maVirDev.SetLineColor();
775 if ( !(rStyleSettings.GetOptions() & STYLE_OPTION_MONO) )
776 maVirDev.SetFillColor( rStyleSettings.GetFaceColor() );
777 else
778 maVirDev.SetFillColor( rStyleSettings.GetWindowColor() );
779 ImplVDrawRect( n1, nVirTop, n2, nVirBottom );
780 if ( !(rStyleSettings.GetOptions() & STYLE_OPTION_MONO) )
782 maVirDev.SetLineColor( rStyleSettings.GetLightColor() );
783 ImplVDrawLine( n1+1, nVirTop, n1+1, nVirBottom );
784 ImplVDrawLine( n1, nVirTop, n2, nVirTop );
785 maVirDev.SetLineColor( rStyleSettings.GetShadowColor() );
786 ImplVDrawLine( n1, nVirTop, n1, nVirBottom );
787 ImplVDrawLine( n1, nVirBottom, n2, nVirBottom );
788 ImplVDrawLine( n2-1, nVirTop, n2-1, nVirBottom );
789 maVirDev.SetLineColor( rStyleSettings.GetWindowTextColor() );
790 ImplVDrawLine( n2, nVirTop, n2, nVirBottom );
792 else
794 maVirDev.SetLineColor( rStyleSettings.GetWindowTextColor() );
795 ImplVDrawLine( n1, nVirTop, n1, nVirBottom );
796 ImplVDrawLine( n2, nVirTop, n2, nVirBottom );
799 if ( mpData->pBorders[i].nStyle & RULER_BORDER_VARIABLE )
801 if ( n2-n1 > RULER_VAR_SIZE+4 )
803 nTemp1 = n1 + (((n2-n1+1)-RULER_VAR_SIZE) / 2);
804 nTemp2 = nVirTop + (((nVirBottom-nVirTop+1)-RULER_VAR_SIZE) / 2);
805 long nTemp3 = nTemp1+RULER_VAR_SIZE-1;
806 long nTemp4 = nTemp2+RULER_VAR_SIZE-1;
807 long nTempY = nTemp2;
808 if ( !(rStyleSettings.GetOptions() & STYLE_OPTION_MONO) )
809 maVirDev.SetLineColor( rStyleSettings.GetLightColor() );
810 else
811 maVirDev.SetLineColor( rStyleSettings.GetWindowTextColor() );
812 while ( nTempY <= nTemp4 )
814 ImplVDrawLine( nTemp1, nTempY, nTemp3, nTempY );
815 nTempY += 2;
817 if ( !(rStyleSettings.GetOptions() & STYLE_OPTION_MONO) )
819 nTempY = nTemp2+1;
820 maVirDev.SetLineColor( rStyleSettings.GetShadowColor() );
821 while ( nTempY <= nTemp4 )
823 ImplVDrawLine( nTemp1, nTempY, nTemp3, nTempY );
824 nTempY += 2;
830 if ( mpData->pBorders[i].nStyle & RULER_BORDER_SIZEABLE )
832 if ( n2-n1 > RULER_VAR_SIZE+10 )
834 if ( !(rStyleSettings.GetOptions() & STYLE_OPTION_MONO) )
836 maVirDev.SetLineColor( rStyleSettings.GetShadowColor() );
837 ImplVDrawLine( n1+4, nVirTop+3, n1+4, nVirBottom-3 );
838 ImplVDrawLine( n2-5, nVirTop+3, n2-5, nVirBottom-3 );
839 maVirDev.SetLineColor( rStyleSettings.GetLightColor() );
840 ImplVDrawLine( n1+5, nVirTop+3, n1+5, nVirBottom-3 );
841 ImplVDrawLine( n2-4, nVirTop+3, n2-4, nVirBottom-3 );
843 else
845 maVirDev.SetLineColor( rStyleSettings.GetWindowTextColor() );
846 ImplVDrawLine( n1+4, nVirTop+3, n1+4, nVirBottom-3 );
847 ImplVDrawLine( n2-4, nVirTop+3, n2-4, nVirBottom-3 );
852 else
854 n = n1+((n2-n1)/2);
855 if ( !(rStyleSettings.GetOptions() & STYLE_OPTION_MONO) )
856 maVirDev.SetLineColor( rStyleSettings.GetShadowColor() );
857 else
858 maVirDev.SetLineColor( rStyleSettings.GetWindowTextColor() );
859 if ( mpData->pBorders[i].nStyle & RULER_BORDER_SNAP )
860 ImplVDrawLine( n, nVirTop, n, nVirBottom );
861 else if ( mpData->pBorders[i].nStyle & RULER_BORDER_MARGIN )
862 ImplVDrawLine( n, nVirTop, n, nVirBottom );
863 else
865 ImplVDrawLine( n-1, nVirTop, n-1, nVirBottom );
866 ImplVDrawLine( n+1, nVirTop, n+1, nVirBottom );
867 maVirDev.SetLineColor();
868 maVirDev.SetFillColor( rStyleSettings.GetWindowColor() );
869 ImplVDrawRect( n, nVirTop, n, nVirBottom );
876 // -----------------------------------------------------------------------
878 void Ruler::ImplDrawIndent( const Polygon& rPoly, USHORT nStyle )
880 const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
881 Point aPos1;
882 Point aPos2;
883 USHORT nIndentStyle = nStyle & RULER_INDENT_STYLE;
885 if ( nStyle & RULER_STYLE_INVISIBLE )
886 return;
888 if ( nStyle & RULER_STYLE_DONTKNOW )
890 maVirDev.SetLineColor( rStyleSettings.GetShadowColor() );
891 maVirDev.SetFillColor( rStyleSettings.GetFaceColor() );
893 else
895 maVirDev.SetLineColor( rStyleSettings.GetDarkShadowColor() );
896 maVirDev.SetFillColor( rStyleSettings.GetFaceColor() );
899 maVirDev.DrawPolygon( rPoly );
901 if ( !(rStyleSettings.GetOptions() & STYLE_OPTION_MONO) && !(nStyle & RULER_STYLE_DONTKNOW) )
903 if ( nIndentStyle == RULER_INDENT_BOTTOM )
905 maVirDev.SetLineColor( rStyleSettings.GetLightColor() );
906 aPos1 = rPoly.GetPoint( 2 );
907 aPos1.X()++;
908 aPos2 = rPoly.GetPoint( 1 );
909 aPos2.X()++;
910 maVirDev.DrawLine( aPos2, aPos1 );
911 aPos2.X()--;
912 aPos2.Y()++;
913 aPos1 = rPoly.GetPoint( 0 );
914 aPos1.Y()++;
915 maVirDev.DrawLine( aPos2, aPos1 );
916 maVirDev.SetLineColor( rStyleSettings.GetShadowColor() );
917 aPos2 = rPoly.GetPoint( 4 );
918 aPos2.Y()++;
919 maVirDev.DrawLine( aPos1, aPos2 );
920 aPos2.X()--;
921 aPos1 = rPoly.GetPoint( 3 );
922 aPos1.X()--;
923 maVirDev.DrawLine( aPos2, aPos1 );
924 aPos1.Y()--;
925 aPos2 = rPoly.GetPoint( 2 );
926 aPos2.X()++;
927 aPos2.Y()--;
928 maVirDev.DrawLine( aPos2, aPos1 );
930 else
932 maVirDev.SetLineColor( rStyleSettings.GetLightColor() );
933 aPos1 = rPoly.GetPoint( 2 );
934 aPos1.X()++;
935 aPos1.Y()++;
936 aPos2 = rPoly.GetPoint( 3 );
937 aPos2.Y()++;
938 maVirDev.DrawLine( aPos1, aPos2 );
939 aPos2 = rPoly.GetPoint( 1 );
940 aPos2.X()++;
941 maVirDev.DrawLine( aPos1, aPos2 );
942 aPos2.X()--;
943 aPos2.Y()--;
944 aPos1 = rPoly.GetPoint( 0 );
945 aPos1.Y()--;
946 maVirDev.DrawLine( aPos2, aPos1 );
947 maVirDev.SetLineColor( rStyleSettings.GetShadowColor() );
948 aPos2 = rPoly.GetPoint( 4 );
949 aPos2.Y()--;
950 maVirDev.DrawLine( aPos1, aPos2 );
951 aPos2.X()--;
952 aPos1 = rPoly.GetPoint( 3 );
953 aPos1.X()--;
954 maVirDev.DrawLine( aPos2, aPos1 );
957 maVirDev.SetLineColor( rStyleSettings.GetDarkShadowColor() );
958 maVirDev.SetFillColor();
959 maVirDev.DrawPolygon( rPoly );
963 // -----------------------------------------------------------------------
965 void Ruler::ImplDrawIndents( long nMin, long nMax, long nVirTop, long nVirBottom )
967 USHORT j;
968 long n;
969 long nIndentHeight = (mnVirHeight/2) - 1;
970 long nIndentWidth2 = nIndentHeight-3;
971 Polygon aPoly( 5 );
973 for ( j = 0; j < mpData->nIndents; j++ )
975 if ( mpData->pIndents[j].nStyle & RULER_STYLE_INVISIBLE )
976 continue;
978 USHORT nStyle = mpData->pIndents[j].nStyle;
979 USHORT nIndentStyle = nStyle & RULER_INDENT_STYLE;
981 n = mpData->pIndents[j].nPos+mpData->nNullVirOff;
983 if ( (n >= nMin) && (n <= nMax) )
985 if(nIndentStyle == RULER_INDENT_BORDER)
987 const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
988 maVirDev.SetLineColor( rStyleSettings.GetShadowColor() );
989 ImplVDrawLine( n, nVirTop, n, nVirBottom );
991 else if ( nIndentStyle == RULER_INDENT_BOTTOM )
993 aPoly.SetPoint( Point( n+0, nVirBottom-nIndentHeight ), 0 );
994 aPoly.SetPoint( Point( n-nIndentWidth2, nVirBottom-3 ), 1 );
995 aPoly.SetPoint( Point( n-nIndentWidth2, nVirBottom ), 2 );
996 aPoly.SetPoint( Point( n+nIndentWidth2, nVirBottom ), 3 );
997 aPoly.SetPoint( Point( n+nIndentWidth2, nVirBottom-3 ), 4 );
999 else
1001 aPoly.SetPoint( Point( n+0, nVirTop+nIndentHeight ), 0 );
1002 aPoly.SetPoint( Point( n-nIndentWidth2, nVirTop+3 ), 1 );
1003 aPoly.SetPoint( Point( n-nIndentWidth2, nVirTop ), 2 );
1004 aPoly.SetPoint( Point( n+nIndentWidth2, nVirTop ), 3 );
1005 aPoly.SetPoint( Point( n+nIndentWidth2, nVirTop+3 ), 4 );
1008 if(0 == (mnWinStyle & WB_HORZ))
1010 Point aTmp;
1011 for(USHORT i = 0; i < 5; i++)
1013 aTmp = aPoly[i];
1014 Point aSet(nVirBottom - aTmp.Y(), aTmp.X());
1015 aPoly[i] = aSet;
1018 if(RULER_INDENT_BORDER != nIndentStyle)
1019 ImplDrawIndent( aPoly, nStyle );
1024 // -----------------------------------------------------------------------
1026 static void ImplCenterTabPos( Point& rPos, USHORT nTabStyle )
1028 BOOL bRTL = 0 != (nTabStyle & RULER_TAB_RTL);
1029 nTabStyle &= RULER_TAB_STYLE;
1030 rPos.Y() += RULER_TAB_HEIGHT/2;
1031 if ( (!bRTL && nTabStyle == RULER_TAB_LEFT) ||( bRTL && nTabStyle == RULER_TAB_RIGHT))
1032 rPos.X() -= RULER_TAB_WIDTH/2;
1033 else if ( (!bRTL && nTabStyle == RULER_TAB_RIGHT) ||( bRTL && nTabStyle == RULER_TAB_LEFT))
1034 rPos.X() += RULER_TAB_WIDTH/2;
1037 // -----------------------------------------------------------------------
1038 void lcl_RotateRect_Impl(Rectangle& rRect, const long nReference, BOOL bRightAligned)
1040 if(!rRect.IsEmpty())
1042 Rectangle aTmp(rRect);
1043 rRect.Top() = aTmp.Left();
1044 rRect.Bottom() = aTmp.Right();
1045 rRect.Left() = aTmp.Top();
1046 rRect.Right() = aTmp.Bottom();
1047 if(bRightAligned)
1049 long nRef = 2 * nReference;
1050 rRect.Left() = nRef - rRect.Left();
1051 rRect.Right() = nRef - rRect.Right();
1055 // -----------------------------------------------------------------------
1057 static void ImplDrawRulerTab( OutputDevice* pDevice,
1058 const Point& rPos, USHORT nStyle, WinBits nWinBits )
1060 if ( nStyle & RULER_STYLE_INVISIBLE )
1061 return;
1063 USHORT nTabStyle = nStyle & RULER_TAB_STYLE;
1064 BOOL bRTL = 0 != (nStyle & RULER_TAB_RTL);
1065 Rectangle aRect1, aRect2, aRect3;
1066 aRect3.SetEmpty();
1067 if ( nTabStyle == RULER_TAB_DEFAULT )
1069 aRect1.Left() = rPos.X() - RULER_TAB_DWIDTH2 + 1 ;
1070 aRect1.Top() = rPos.Y() - RULER_TAB_DHEIGHT2 + 1 ;
1071 aRect1.Right() = rPos.X() - RULER_TAB_DWIDTH2 + RULER_TAB_DWIDTH ;
1072 aRect1.Bottom() = rPos.Y();
1073 aRect2.Left() = rPos.X() - RULER_TAB_DWIDTH2 + RULER_TAB_DWIDTH3;
1074 aRect2.Top() = rPos.Y() - RULER_TAB_DHEIGHT + 1;
1075 aRect2.Right() = rPos.X() - RULER_TAB_DWIDTH2 + RULER_TAB_DWIDTH3 + RULER_TAB_DWIDTH4 - 1;
1076 aRect2.Bottom() = rPos.Y();
1079 else if ( (!bRTL && nTabStyle == RULER_TAB_LEFT) ||( bRTL && nTabStyle == RULER_TAB_RIGHT))
1081 aRect1.Left() = rPos.X();
1082 aRect1.Top() = rPos.Y() - RULER_TAB_HEIGHT2 + 1;
1083 aRect1.Right() = rPos.X() + RULER_TAB_WIDTH - 1;
1084 aRect1.Bottom() = rPos.Y();
1085 aRect2.Left() = rPos.X();
1086 aRect2.Top() = rPos.Y() - RULER_TAB_HEIGHT + 1;
1087 aRect2.Right() = rPos.X() + RULER_TAB_WIDTH2 - 1;
1088 aRect2.Bottom() = rPos.Y();
1090 else if ( (!bRTL && nTabStyle == RULER_TAB_RIGHT) ||( bRTL && nTabStyle == RULER_TAB_LEFT))
1092 aRect1.Left() = rPos.X() - RULER_TAB_WIDTH + 1;
1093 aRect1.Top() = rPos.Y() - RULER_TAB_HEIGHT2 + 1;
1094 aRect1.Right() = rPos.X();
1095 aRect1.Bottom() = rPos.Y();
1096 aRect2.Left() = rPos.X() - RULER_TAB_WIDTH2 + 1;
1097 aRect2.Top() = rPos.Y() - RULER_TAB_HEIGHT + 1;
1098 aRect2.Right() = rPos.X();
1099 aRect2.Bottom() = rPos.Y();
1101 else
1103 aRect1.Left() = rPos.X() - RULER_TAB_CWIDTH2 + 1;
1104 aRect1.Top() = rPos.Y() - RULER_TAB_HEIGHT2 + 1;
1105 aRect1.Right() = rPos.X() - RULER_TAB_CWIDTH2 + RULER_TAB_CWIDTH;
1106 aRect1.Bottom() = rPos.Y();
1107 aRect2.Left() = rPos.X() - RULER_TAB_CWIDTH2 + RULER_TAB_CWIDTH3;
1108 aRect2.Top() = rPos.Y() - RULER_TAB_HEIGHT + 1;
1109 aRect2.Right() = rPos.X() - RULER_TAB_CWIDTH2 + RULER_TAB_CWIDTH3 + RULER_TAB_CWIDTH4 - 1;
1110 aRect2.Bottom() = rPos.Y();
1112 if ( nTabStyle == RULER_TAB_DECIMAL )
1114 aRect3.Left() = rPos.X() - RULER_TAB_CWIDTH2 + RULER_TAB_CWIDTH - 1;
1115 aRect3.Top() = rPos.Y() - RULER_TAB_HEIGHT + 1 + 1;
1116 aRect3.Right() = rPos.X() - RULER_TAB_CWIDTH2 + RULER_TAB_CWIDTH;
1117 aRect3.Bottom()= rPos.Y() - RULER_TAB_HEIGHT + 1 + 2 ;
1120 if( 0 == (nWinBits&WB_HORZ) )
1122 BOOL bRightAligned = 0 != (nWinBits&WB_RIGHT_ALIGNED);
1123 lcl_RotateRect_Impl(aRect1, rPos.Y(), bRightAligned);
1124 lcl_RotateRect_Impl(aRect2, rPos.Y(), bRightAligned);
1125 lcl_RotateRect_Impl(aRect3, rPos.Y(), bRightAligned);
1127 pDevice->DrawRect( aRect1 );
1128 pDevice->DrawRect( aRect2 );
1129 if(!aRect2.IsEmpty())
1130 pDevice->DrawRect( aRect3 );
1134 // -----------------------------------------------------------------------
1136 void Ruler::ImplDrawTab( OutputDevice* pDevice, const Point& rPos, USHORT nStyle )
1138 if ( nStyle & RULER_STYLE_INVISIBLE )
1139 return;
1141 pDevice->SetLineColor();
1142 if ( nStyle & RULER_STYLE_DONTKNOW )
1143 pDevice->SetFillColor( GetSettings().GetStyleSettings().GetFaceColor() );
1144 else
1145 pDevice->SetFillColor( GetSettings().GetStyleSettings().GetWindowTextColor() );
1147 if(mpData->bTextRTL)
1148 nStyle |= RULER_TAB_RTL;
1149 ImplDrawRulerTab( pDevice, rPos, nStyle, GetStyle());
1152 // -----------------------------------------------------------------------
1154 void Ruler::ImplDrawTabs( long nMin, long nMax, long nVirTop, long nVirBottom )
1156 for ( USHORT i = 0; i < mpData->nTabs; i++ )
1158 if ( mpData->pTabs[i].nStyle & RULER_STYLE_INVISIBLE )
1159 continue;
1161 long n;
1162 n = mpData->pTabs[i].nPos;
1163 n += +mpData->nNullVirOff;
1164 long nTopBottom = GetStyle() & WB_RIGHT_ALIGNED ? nVirTop : nVirBottom;
1165 if ( (n >= nMin) && (n <= nMax) )
1166 ImplDrawTab( &maVirDev, Point( n, nTopBottom ), mpData->pTabs[i].nStyle );
1170 // -----------------------------------------------------------------------
1172 void Ruler::ImplInitSettings( BOOL bFont,
1173 BOOL bForeground, BOOL bBackground )
1175 const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
1177 if ( bFont )
1179 Font aFont;
1180 aFont = rStyleSettings.GetToolFont();
1181 if ( IsControlFont() )
1182 aFont.Merge( GetControlFont() );
1183 SetZoomedPointFont( aFont );
1186 if ( bForeground || bFont )
1188 Color aColor;
1189 if ( IsControlForeground() )
1190 aColor = GetControlForeground();
1191 else
1192 aColor = rStyleSettings.GetWindowTextColor();
1193 SetTextColor( aColor );
1194 SetTextFillColor();
1197 if ( bBackground )
1199 Color aColor;
1200 if ( IsControlBackground() )
1201 aColor = GetControlBackground();
1202 else
1203 aColor = rStyleSettings.GetFaceColor();
1204 SetBackground( aColor );
1207 maVirDev.SetSettings( GetSettings() );
1208 maVirDev.SetBackground( GetBackground() );
1209 Font aFont = GetFont();
1210 if ( mnWinStyle & WB_VERT )
1211 aFont.SetOrientation( 900 );
1212 maVirDev.SetFont( aFont );
1213 maVirDev.SetTextColor( GetTextColor() );
1214 maVirDev.SetTextFillColor( GetTextFillColor() );
1217 // -----------------------------------------------------------------------
1219 void Ruler::ImplCalc()
1221 // Offset berechnen
1222 mpData->nRulVirOff = mnWinOff + mpData->nPageOff;
1223 if ( mpData->nRulVirOff > mnVirOff )
1224 mpData->nRulVirOff -= mnVirOff;
1225 else
1226 mpData->nRulVirOff = 0;
1227 long nRulWinOff = mpData->nRulVirOff+mnVirOff;
1229 // Nicht sichtbaren Bereich der Page berechnen
1230 long nNotVisPageWidth;
1231 if ( mpData->nPageOff < 0 )
1233 nNotVisPageWidth = -(mpData->nPageOff);
1234 if ( nRulWinOff < mnWinOff )
1235 nNotVisPageWidth -= mnWinOff-nRulWinOff;
1237 else
1238 nNotVisPageWidth = 0;
1240 // Breite berechnen
1241 if ( mnWinStyle & WB_HORZ )
1243 if ( mbAutoWinWidth )
1244 mnWinWidth = mnWidth - mnVirOff;
1245 if ( mpData->bAutoPageWidth )
1246 mpData->nPageWidth = mnWinWidth;
1247 mpData->nRulWidth = Min( mnWinWidth, mpData->nPageWidth-nNotVisPageWidth );
1248 if ( nRulWinOff+mpData->nRulWidth > mnWidth )
1249 mpData->nRulWidth = mnWidth-nRulWinOff;
1251 else
1253 if ( mbAutoWinWidth )
1254 mnWinWidth = mnHeight - mnVirOff;
1255 if ( mpData->bAutoPageWidth )
1256 mpData->nPageWidth = mnWinWidth;
1257 mpData->nRulWidth = Min( mnWinWidth, mpData->nPageWidth-nNotVisPageWidth );
1258 if ( nRulWinOff+mpData->nRulWidth > mnHeight )
1259 mpData->nRulWidth = mnHeight-nRulWinOff;
1262 mbCalc = FALSE;
1265 // -----------------------------------------------------------------------
1267 void Ruler::ImplFormat()
1269 // Wenn schon formatiert ist, brauchen wir es nicht nochmal
1270 if ( !mbFormat )
1271 return;
1273 // Wenn Fenster noch keine Groesse hat, brauchen wir noch nichts machen
1274 if ( !mnVirWidth )
1275 return;
1277 const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
1278 long nP1; // Pixel-Position von Page1
1279 long nP2; // Pixel-Position von Page2
1280 long nM1; // Pixel-Position von Margin1
1281 long nM2; // Pixel-Position von Margin2
1282 long nVirTop; // Obere/Linke-Kante bei Ausgabe
1283 long nVirBottom; // Untere/Rechte-Kante bei Ausgabe
1284 long nVirLeft; // Linke/Obere-Kante bei Ausgabe
1285 long nVirRight; // Rechte/Untere-Kante bei Ausgabe
1286 long nNullVirOff; // Fuer schnellere Berechnung
1288 // Werte berechnen
1289 if ( mbCalc )
1290 ImplCalc();
1291 mpData->nNullVirOff = mnWinOff+mpData->nPageOff+mpData->nNullOff-mnVirOff;
1292 nNullVirOff = mpData->nNullVirOff;
1293 nVirLeft = mpData->nRulVirOff;
1294 nVirRight = nVirLeft+mpData->nRulWidth-1;
1295 nVirTop = 0;
1296 nVirBottom = mnVirHeight-1;
1298 if ( !IsReallyVisible() )
1299 return;
1301 Size aVirDevSize;
1302 BOOL b3DLook = !(rStyleSettings.GetOptions() & STYLE_OPTION_MONO);
1304 // VirtualDevice initialisieren
1305 if ( mnWinStyle & WB_HORZ )
1307 aVirDevSize.Width() = mnVirWidth;
1308 aVirDevSize.Height() = mnVirHeight;
1310 else
1312 aVirDevSize.Height() = mnVirWidth;
1313 aVirDevSize.Width() = mnVirHeight;
1315 if ( aVirDevSize != maVirDev.GetOutputSizePixel() )
1316 maVirDev.SetOutputSizePixel( aVirDevSize, TRUE );
1317 else
1318 maVirDev.Erase();
1320 // Raender berechnen
1321 if ( !(mpData->nMargin1Style & RULER_STYLE_INVISIBLE) )
1323 nM1 = mpData->nMargin1+nNullVirOff;
1324 if ( mpData->bAutoPageWidth )
1326 nP1 = nVirLeft;
1327 if ( nM1 < nVirLeft )
1328 nP1--;
1330 else
1331 nP1 = nNullVirOff-mpData->nNullOff;
1333 else
1335 nM1 = nVirLeft-1;
1336 nP1 = nM1;
1338 if ( !(mpData->nMargin2Style & RULER_STYLE_INVISIBLE) )
1340 nM2 = mpData->nMargin2+nNullVirOff;
1341 if ( mpData->bAutoPageWidth )
1343 nP2 = nVirRight;
1344 if ( nM2 > nVirRight )
1345 nP2++;
1347 else
1348 nP2 = nNullVirOff-mpData->nNullOff+mpData->nPageWidth;
1349 if ( nM2 > nP2 )
1350 nM2 = nP2;
1352 else
1354 nM2 = nVirRight+1;
1355 nP2 = nM2;
1358 // Obere/untere Kante ausgeben
1359 if ( b3DLook )
1360 maVirDev.SetLineColor( rStyleSettings.GetShadowColor() );
1361 else
1362 maVirDev.SetLineColor( rStyleSettings.GetWindowTextColor() );
1363 ImplVDrawLine( nVirLeft, nVirTop, nM1 - 1, nVirTop ); //top left line
1364 ImplVDrawLine( nM2 +1, nVirTop, nP2 -1, nVirTop ); //top right line
1366 // Jetzt wird zwischen dem Schatten ausgegeben
1367 nVirTop++;
1368 nVirBottom--;
1370 // Margin1, Margin2 und Zwischenraum ausgeben
1371 maVirDev.SetLineColor();
1372 if ( b3DLook )
1373 maVirDev.SetFillColor( rStyleSettings.GetFaceColor() );
1374 else
1375 maVirDev.SetFillColor( rStyleSettings.GetWindowColor() );
1376 if ( nM1 > nVirLeft )
1377 ImplVDrawRect( nP1, nVirTop, nM1-1, nVirBottom ); //left gray rectangle
1378 if ( nM2 < nP2 )
1379 ImplVDrawRect( nM2+1, nVirTop, nP2, nVirBottom ); //right gray rectangle
1380 if ( nM2-nM1 > 0 )
1382 maVirDev.SetFillColor( rStyleSettings.GetWindowColor() );
1383 ImplVDrawRect( nM1, nVirTop, nM2-1, nVirBottom ); //center rectangle
1385 if ( b3DLook )
1387 maVirDev.SetLineColor( rStyleSettings.GetShadowColor() );
1388 if ( nM1 > nVirLeft )
1390 ImplVDrawLine( nM1-1, nVirTop, nM1-1, nVirBottom );//right line of the left rectangle
1391 ImplVDrawLine( nP1, nVirBottom, nM1-1, nVirBottom );//bottom line of the left rectangle
1392 if ( nP1 >= nVirLeft )
1394 ImplVDrawLine( nP1, nVirTop, nP1, nVirBottom );//left line of the left rectangle
1395 ImplVDrawLine( nP1, nVirBottom, nP1+1, nVirBottom );//?
1398 if ( nM2 < nP2 )
1400 ImplVDrawLine( nM2+1, nVirBottom, nP2-1, nVirBottom );//bottom line of the right rectangle
1401 ImplVDrawLine( nM2+1, nVirTop, nM2+1, nVirBottom );//left line of the right rectangle
1402 if ( nP2 <= nVirRight+1 )
1403 ImplVDrawLine( nP2-1, nVirTop, nP2-1, nVirBottom );//right line of the right rectangle
1406 else
1408 maVirDev.SetLineColor( rStyleSettings.GetWindowTextColor() );
1409 if ( nP1 >= nVirLeft )
1410 ImplVDrawLine( nP1, nVirTop, nP1, nVirBottom+1 );
1411 if ( nM1 > nP1 )
1412 ImplVDrawLine( nM1, nVirTop, nM1, nVirBottom );
1413 if ( nM2 < nP2 )
1414 ImplVDrawLine( nM2, nVirTop, nM2, nVirBottom );
1415 if ( nP2 <= nVirRight+1 )
1416 ImplVDrawLine( nP2, nVirTop, nP2, nVirBottom+1 );
1419 // Lineal-Beschriftung (nur wenn keine Bemassungspfeile)
1420 if ( !mpData->pArrows )
1422 long nMin = nVirLeft;
1423 long nMax = nP2;
1424 long nStart = mpData->bTextRTL ? mpData->nMargin2 + nNullVirOff : nNullVirOff;
1425 long nCenter = nVirTop+((nVirBottom-nVirTop)/2);
1427 // Nicht Schatten uebermalen
1428 if ( nP1 > nVirLeft )
1429 nMin++;
1430 if ( nP2 < nVirRight )
1431 nMax--;
1433 // Beschriftung ausgeben
1434 ImplDrawTicks( nMin, nMax, nStart, nCenter );
1437 // Spalten ausgeben
1438 if ( mpData->pBorders )
1439 ImplDrawBorders( nVirLeft, nP2, nVirTop, nVirBottom );
1441 // Einzuege ausgeben
1442 if ( mpData->pIndents )
1443 ImplDrawIndents( nVirLeft, nP2, nVirTop-1, nVirBottom+1 );
1445 // Tabs
1446 if ( mpData->pTabs )
1448 ImplDrawTabs( nVirLeft, nP2, nVirTop-1, nVirBottom+1 );
1451 // Bemassungspfeile
1452 if ( mpData->pArrows )
1453 ImplDrawArrows( nVirTop+((nVirBottom-nVirTop)/2) );
1455 // Wir haben formatiert
1456 mbFormat = FALSE;
1459 // -----------------------------------------------------------------------
1461 void Ruler::ImplInitExtraField( BOOL bUpdate )
1463 // Extra-Field beruecksichtigen
1464 if ( mnWinStyle & WB_EXTRAFIELD )
1466 maExtraRect.Left() = RULER_OFF;
1467 maExtraRect.Top() = RULER_OFF;
1468 maExtraRect.Right() = RULER_OFF+mnVirHeight-1;
1469 maExtraRect.Bottom() = RULER_OFF+mnVirHeight-1;
1470 if(mpData->bTextRTL)
1472 Size aWinSize = GetOutputSizePixel();
1473 if(mnWinStyle & WB_HORZ)
1474 maExtraRect.Move(aWinSize.Width() - maExtraRect.GetWidth() - maExtraRect.Left(), 0);
1475 else
1476 maExtraRect.Move(0, aWinSize.Height() - maExtraRect.GetHeight() - maExtraRect.Top());
1477 mnVirOff = 0;
1479 else
1480 mnVirOff = maExtraRect.Right()+1;
1483 else
1485 maExtraRect.SetEmpty();
1486 mnVirOff = 0;
1489 if ( bUpdate )
1491 mbCalc = TRUE;
1492 mbFormat = TRUE;
1493 Invalidate();
1497 // -----------------------------------------------------------------------
1499 void Ruler::ImplDraw()
1501 if ( mbFormat )
1502 ImplFormat();
1504 if ( IsReallyVisible() )
1506 // Lineal ueber das VirtualDevice ausgeben
1507 Point aOffPos;
1508 Size aVirDevSize = maVirDev.GetOutputSizePixel();
1509 // Size aVirDevSize2 = maVirDev.GetOutputSizePixel();
1510 if ( mnWinStyle & WB_HORZ )
1512 aOffPos.X() = mnVirOff;
1513 if(mpData->bTextRTL)
1514 aVirDevSize.Width() -= maExtraRect.GetWidth();
1516 // else
1517 // aVirDevSize.Width() -= mnVirOff;
1518 aOffPos.Y() = RULER_OFF;
1520 else
1522 aOffPos.X() = RULER_OFF;
1523 aOffPos.Y() = mnVirOff;
1524 // else
1525 // aVirDevSize.Height() -= mnVirOff;
1527 DrawOutDev( aOffPos, aVirDevSize, Point(), aVirDevSize, maVirDev );
1529 // Positionslinien neu malen
1530 ImplInvertLines( TRUE );
1534 // -----------------------------------------------------------------------
1536 void Ruler::ImplDrawExtra( BOOL bPaint )
1538 const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
1539 Rectangle aRect = maExtraRect;
1540 BOOL bEraseRect = FALSE;
1542 if ( !(rStyleSettings.GetOptions() & STYLE_OPTION_MONO) )
1544 aRect.Left() += 2;
1545 aRect.Top() += 2;
1546 aRect.Right() -= 2;
1547 aRect.Bottom() -= 2;
1549 else
1551 aRect.Left() += 1;
1552 aRect.Top() += 1;
1553 aRect.Right() -= 1;
1554 aRect.Bottom() -= 1;
1557 if ( !bPaint && !(mnExtraStyle & RULER_STYLE_HIGHLIGHT) )
1559 if ( !(rStyleSettings.GetOptions() & STYLE_OPTION_MONO) )
1560 SetFillColor( rStyleSettings.GetFaceColor() );
1561 else
1562 SetFillColor( rStyleSettings.GetWindowColor() );
1563 bEraseRect = TRUE;
1565 else
1567 if ( !(rStyleSettings.GetOptions() & STYLE_OPTION_MONO) && (mnExtraStyle & RULER_STYLE_HIGHLIGHT) )
1569 SetFillColor( rStyleSettings.GetCheckedColor() );
1570 bEraseRect = TRUE;
1574 if ( bEraseRect )
1576 SetLineColor();
1577 DrawRect( aRect );
1580 // Inhalt ausgeben
1581 if ( meExtraType == RULER_EXTRA_NULLOFFSET )
1583 if ( !(rStyleSettings.GetOptions() & STYLE_OPTION_MONO) )
1584 SetLineColor( rStyleSettings.GetButtonTextColor() );
1585 else
1586 SetLineColor( rStyleSettings.GetWindowTextColor() );
1587 DrawLine( Point( aRect.Left()+1, aRect.Top()+4 ),
1588 Point( aRect.Right()-1, aRect.Top()+4 ) );
1589 DrawLine( Point( aRect.Left()+4, aRect.Top()+1 ),
1590 Point( aRect.Left()+4, aRect.Bottom()-1 ) );
1592 else if ( meExtraType == RULER_EXTRA_TAB )
1594 USHORT nTabStyle = mnExtraStyle & RULER_TAB_STYLE;
1595 if(mpData->bTextRTL)
1596 nTabStyle |= RULER_TAB_RTL;
1597 Point aCenter = aRect.Center();
1598 Point aDraw(aCenter);
1599 ImplCenterTabPos( aDraw, nTabStyle );
1600 WinBits nWinBits = GetStyle();
1601 if(0 == (nWinBits&WB_HORZ) )
1603 if(0 != (nWinBits&WB_RIGHT_ALIGNED))
1604 aDraw.Y() = 2 * aCenter.Y() - aDraw.Y();
1605 if(mpData->bTextRTL)
1607 long nTemp = aDraw.X();
1608 aDraw.X() = aDraw.Y();
1609 aDraw.Y() = nTemp;
1612 ImplDrawTab( this, aDraw, nTabStyle );
1615 if ( (rStyleSettings.GetOptions() & STYLE_OPTION_MONO) && (mnExtraStyle & RULER_STYLE_HIGHLIGHT) )
1616 Invert( aRect );
1619 // -----------------------------------------------------------------------
1621 void Ruler::ImplUpdate( BOOL bMustCalc )
1623 // Hier schon Linien loeschen, damit Sie vor dem Neuberechnen schon
1624 // geloscht sind, da danach die alten Positionen nicht mehr bestimmt
1625 // werden koennen
1626 if ( !mbFormat )
1627 ImplInvertLines();
1629 // Flags setzen
1630 if ( bMustCalc )
1631 mbCalc = TRUE;
1632 mbFormat = TRUE;
1634 // Wenn wir am Draggen sind, wird nach dem Drag-Handler automatisch
1635 // das Lineal neu upgedatet
1636 if ( mbDrag )
1637 return;
1639 // Gegebenenfalls Update ausloesen
1640 if ( IsReallyVisible() && IsUpdateMode() )
1642 mnUpdateFlags |= RULER_UPDATE_DRAW;
1643 if ( !mnUpdateEvtId )
1644 mnUpdateEvtId = Application::PostUserEvent( LINK( this, Ruler, ImplUpdateHdl ), NULL );
1648 // -----------------------------------------------------------------------
1650 BOOL Ruler::ImplHitTest( const Point& rPos, ImplRulerHitTest* pHitTest,
1651 BOOL bRequireStyle, USHORT nRequiredStyle ) const
1653 USHORT i;
1654 USHORT nStyle;
1655 long nHitBottom;
1656 long nX;
1657 long nY;
1658 long n1;
1659 long n2;
1661 if ( !mbActive )
1662 return FALSE;
1664 // Position ermitteln
1665 BOOL bIsHori = 0 != (mnWinStyle & WB_HORZ);
1666 if ( bIsHori )
1668 nX = rPos.X();
1669 nY = rPos.Y();
1671 else
1673 nX = rPos.Y();
1674 nY = rPos.X();
1676 nHitBottom = mnVirHeight+(RULER_OFF*2);
1678 // --> FME 2004-08-05 #i32608#
1679 pHitTest->nAryPos = 0;
1680 pHitTest->mnDragSize = 0;
1681 pHitTest->bSize = FALSE;
1682 pHitTest->bSizeBar = FALSE;
1683 // <--
1685 // Damit ueberstehende Tabs und Einzuege mit beruecksichtigt werden
1686 long nXExtraOff;
1687 if ( mpData->pTabs || mpData->pIndents )
1688 nXExtraOff = (mnVirHeight/2) - 4;
1689 else
1690 nXExtraOff = 0;
1692 // Test auf ausserhalb
1693 nX -= mnVirOff;
1694 long nXTemp = nX;
1695 if ( (nX < mpData->nRulVirOff-nXExtraOff) || (nX > mpData->nRulVirOff+mpData->nRulWidth+nXExtraOff) ||
1696 (nY < 0) || (nY > nHitBottom) )
1698 pHitTest->nPos = 0;
1699 pHitTest->eType = RULER_TYPE_OUTSIDE;
1700 return FALSE;
1703 nX -= mpData->nNullVirOff;
1704 pHitTest->nPos = nX;
1705 pHitTest->eType = RULER_TYPE_DONTKNOW;
1707 // Zuerst die Tabs testen
1708 Rectangle aRect;
1709 if ( mpData->pTabs )
1711 aRect.Bottom() = nHitBottom;
1712 aRect.Top() = aRect.Bottom()-RULER_TAB_HEIGHT-RULER_OFF;
1714 for ( i = mpData->nTabs; i; i-- )
1716 nStyle = mpData->pTabs[i-1].nStyle;
1717 if ( !(nStyle & RULER_STYLE_INVISIBLE) )
1719 nStyle &= RULER_TAB_STYLE;
1721 // Default-Tabs werden nur angezeigt
1722 if ( nStyle != RULER_TAB_DEFAULT )
1724 n1 = mpData->pTabs[i-1].nPos;
1726 if ( nStyle == RULER_TAB_LEFT )
1728 aRect.Left() = n1;
1729 aRect.Right() = n1+RULER_TAB_WIDTH-1;
1731 else if ( nStyle == RULER_TAB_RIGHT )
1733 aRect.Right() = n1;
1734 aRect.Left() = n1-RULER_TAB_WIDTH-1;
1736 else
1738 aRect.Left() = n1-RULER_TAB_CWIDTH2+1;
1739 aRect.Right() = n1-RULER_TAB_CWIDTH2+RULER_TAB_CWIDTH;
1742 if ( aRect.IsInside( Point( nX, nY ) ) )
1744 pHitTest->eType = RULER_TYPE_TAB;
1745 pHitTest->nAryPos = i-1;
1746 return TRUE;
1753 // Dann die Einzuege
1754 if ( mpData->pIndents )
1756 long nIndentHeight = (mnVirHeight/2) - 1;
1757 long nIndentWidth2 = nIndentHeight-3;
1759 for ( i = mpData->nIndents; i; i-- )
1761 nStyle = mpData->pIndents[i-1].nStyle;
1762 if ( (! bRequireStyle || nStyle == nRequiredStyle) &&
1763 !(nStyle & RULER_STYLE_INVISIBLE) )
1765 nStyle &= RULER_INDENT_STYLE;
1766 n1 = mpData->pIndents[i-1].nPos;
1768 if ( (nStyle == RULER_INDENT_BOTTOM) ^ (!bIsHori) )
1770 aRect.Left() = n1-nIndentWidth2;
1771 aRect.Right() = n1+nIndentWidth2;
1772 aRect.Top() = nHitBottom-nIndentHeight-RULER_OFF+1;
1773 aRect.Bottom() = nHitBottom;
1775 else
1777 aRect.Left() = n1-nIndentWidth2;
1778 aRect.Right() = n1+nIndentWidth2;
1779 aRect.Top() = 0;
1780 aRect.Bottom() = nIndentHeight+RULER_OFF-1;
1783 if ( aRect.IsInside( Point( nX, nY ) ) )
1785 pHitTest->eType = RULER_TYPE_INDENT;
1786 pHitTest->nAryPos = i-1;
1787 return TRUE;
1793 // Jetzt zaehlt nichts mehr, was links oder rechts uebersteht
1794 if ( (nXTemp < mpData->nRulVirOff) || (nXTemp > mpData->nRulVirOff+mpData->nRulWidth) )
1796 pHitTest->nPos = 0;
1797 pHitTest->eType = RULER_TYPE_OUTSIDE;
1798 return FALSE;
1801 // Danach die Spalten testen
1802 int nBorderTolerance = 1;
1803 if(pHitTest->bExpandTest)
1805 nBorderTolerance++;
1808 for ( i = mpData->nBorders; i; i-- )
1810 n1 = mpData->pBorders[i-1].nPos;
1811 n2 = n1 + mpData->pBorders[i-1].nWidth;
1813 // Spalten werden mit mindestens 3 Pixel breite gezeichnet
1814 if ( !mpData->pBorders[i-1].nWidth )
1816 n1 -= nBorderTolerance;
1817 n2 += nBorderTolerance;
1821 if ( (nX >= n1) && (nX <= n2) )
1823 nStyle = mpData->pBorders[i-1].nStyle;
1824 if ( !(nStyle & RULER_STYLE_INVISIBLE) )
1826 pHitTest->eType = RULER_TYPE_BORDER;
1827 pHitTest->nAryPos = i-1;
1829 if ( !(nStyle & RULER_BORDER_SIZEABLE) )
1831 if ( nStyle & RULER_BORDER_MOVEABLE )
1833 pHitTest->bSizeBar = TRUE;
1834 pHitTest->mnDragSize = RULER_DRAGSIZE_MOVE;
1837 else
1839 long nMOff = RULER_MOUSE_BORDERWIDTH;
1840 while ( nMOff*2 >= (n2-n1-RULER_MOUSE_BORDERMOVE) )
1842 if ( nMOff < 2 )
1844 nMOff = 0;
1845 break;
1847 else
1848 nMOff--;
1851 if ( nX <= n1+nMOff )
1853 pHitTest->bSize = TRUE;
1854 pHitTest->mnDragSize = RULER_DRAGSIZE_1;
1856 else if ( nX >= n2-nMOff )
1858 pHitTest->bSize = TRUE;
1859 pHitTest->mnDragSize = RULER_DRAGSIZE_2;
1861 else
1863 if ( nStyle & RULER_BORDER_MOVEABLE )
1865 pHitTest->bSizeBar = TRUE;
1866 pHitTest->mnDragSize = RULER_DRAGSIZE_MOVE;
1871 return TRUE;
1876 // Und zum Schluss die Raender
1877 int nMarginTolerance = pHitTest->bExpandTest ? nBorderTolerance : RULER_MOUSE_MARGINWIDTH;
1879 if ( (mpData->nMargin1Style & (RULER_MARGIN_SIZEABLE | RULER_STYLE_INVISIBLE)) == RULER_MARGIN_SIZEABLE )
1881 n1 = mpData->nMargin1;
1882 if ( (nX >= n1 - nMarginTolerance) && (nX <= n1 + nMarginTolerance) )
1884 pHitTest->eType = RULER_TYPE_MARGIN1;
1885 pHitTest->bSize = TRUE;
1886 return TRUE;
1889 if ( (mpData->nMargin2Style & (RULER_MARGIN_SIZEABLE | RULER_STYLE_INVISIBLE)) == RULER_MARGIN_SIZEABLE )
1891 n1 = mpData->nMargin2;
1892 if ( (nX >= n1 - nMarginTolerance) && (nX <= n1 + nMarginTolerance) )
1894 pHitTest->eType = RULER_TYPE_MARGIN2;
1895 pHitTest->bSize = TRUE;
1896 return TRUE;
1900 // Jetzt nocheinmal die Tabs testen, nur mit etwas mehr spielraum
1901 if ( mpData->pTabs )
1903 aRect.Top() = RULER_OFF;
1904 aRect.Bottom() = nHitBottom;
1906 for ( i = mpData->nTabs; i; i-- )
1908 nStyle = mpData->pTabs[i-1].nStyle;
1909 if ( !(nStyle & RULER_STYLE_INVISIBLE) )
1911 nStyle &= RULER_TAB_STYLE;
1913 // Default-Tabs werden nur angezeigt
1914 if ( nStyle != RULER_TAB_DEFAULT )
1916 n1 = mpData->pTabs[i-1].nPos;
1918 if ( nStyle == RULER_TAB_LEFT )
1920 aRect.Left() = n1;
1921 aRect.Right() = n1+RULER_TAB_WIDTH-1;
1923 else if ( nStyle == RULER_TAB_RIGHT )
1925 aRect.Right() = n1;
1926 aRect.Left() = n1-RULER_TAB_WIDTH-1;
1928 else
1930 aRect.Left() = n1-RULER_TAB_CWIDTH2+1;
1931 aRect.Right() = n1-RULER_TAB_CWIDTH2+RULER_TAB_CWIDTH;
1934 aRect.Left()--;
1935 aRect.Right()++;
1937 if ( aRect.IsInside( Point( nX, nY ) ) )
1939 pHitTest->eType = RULER_TYPE_TAB;
1940 pHitTest->nAryPos = i-1;
1941 return TRUE;
1948 return FALSE;
1951 // -----------------------------------------------------------------------
1953 BOOL Ruler::ImplDocHitTest( const Point& rPos, RulerType eDragType,
1954 ImplRulerHitTest* pHitTest ) const
1956 Point aPos = rPos;
1957 BOOL bRequiredStyle = FALSE;
1958 USHORT nRequiredStyle = 0;
1960 if (eDragType == RULER_TYPE_INDENT)
1962 bRequiredStyle = TRUE;
1963 nRequiredStyle = RULER_INDENT_BOTTOM;
1966 if ( mnWinStyle & WB_HORZ )
1967 aPos.X() += mnWinOff;
1968 else
1969 aPos.Y() += mnWinOff;
1971 if ( (eDragType == RULER_TYPE_INDENT) || (eDragType == RULER_TYPE_DONTKNOW) )
1973 if ( mnWinStyle & WB_HORZ )
1974 aPos.Y() = RULER_OFF+1;
1975 else
1976 aPos.X() = RULER_OFF+1;
1978 // HitTest durchfuehren
1979 if ( ImplHitTest( aPos, pHitTest, bRequiredStyle, nRequiredStyle ) )
1981 if ( (pHitTest->eType == eDragType) || (eDragType == RULER_TYPE_DONTKNOW) )
1982 return TRUE;
1986 if ( (eDragType == RULER_TYPE_INDENT) || (eDragType == RULER_TYPE_TAB) ||
1987 (eDragType == RULER_TYPE_DONTKNOW) )
1989 if ( mnWinStyle & WB_HORZ )
1990 aPos.Y() = mnHeight-RULER_OFF-1;
1991 else
1992 aPos.X() = mnWidth-RULER_OFF-1;
1994 // HitTest durchfuehren
1995 if ( ImplHitTest( aPos, pHitTest, bRequiredStyle, nRequiredStyle ) )
1997 if ( (pHitTest->eType == eDragType) || (eDragType == RULER_TYPE_DONTKNOW) )
1998 return TRUE;
2002 if ( (eDragType == RULER_TYPE_MARGIN1) || (eDragType == RULER_TYPE_MARGIN2) ||
2003 (eDragType == RULER_TYPE_BORDER) || (eDragType == RULER_TYPE_DONTKNOW) )
2005 if ( mnWinStyle & WB_HORZ )
2006 aPos.Y() = RULER_OFF + (mnVirHeight/2);
2007 else
2008 aPos.X() = RULER_OFF + (mnVirHeight/2);
2010 // HitTest durchfuehren
2011 if ( ImplHitTest( aPos, pHitTest ) )
2013 if ( (pHitTest->eType == eDragType) || (eDragType == RULER_TYPE_DONTKNOW) )
2014 return TRUE;
2018 // Auf DontKnow setzen
2019 pHitTest->eType = RULER_TYPE_DONTKNOW;
2021 return FALSE;
2024 // -----------------------------------------------------------------------
2026 BOOL Ruler::ImplStartDrag( ImplRulerHitTest* pHitTest, USHORT nModifier )
2028 // Wenn eine Spalte angeklick wurde, die weder verschiebar noch
2029 // in der Groesse aenderbar ist, brauchen wir auch kein Drag ausloesen
2030 if ( (pHitTest->eType == RULER_TYPE_BORDER) &&
2031 !pHitTest->bSize && !pHitTest->bSizeBar )
2032 return FALSE;
2034 // Dragdaten setzen
2035 meDragType = pHitTest->eType;
2036 mnDragPos = pHitTest->nPos;
2037 mnDragAryPos = pHitTest->nAryPos;
2038 mnDragSize = pHitTest->mnDragSize;
2039 mnDragModifier = nModifier;
2040 *mpDragData = *mpSaveData;
2041 mpData = mpDragData;
2043 // Handler rufen
2044 if ( StartDrag() )
2046 // Wenn der Handler das Draggen erlaubt, dann das Draggen
2047 // initialisieren
2048 ImplInvertLines();
2049 mbDrag = TRUE;
2050 mnStartDragPos = mnDragPos;
2051 StartTracking();
2052 return TRUE;
2054 else
2056 // Ansonsten muessen wir die Daten zuruecksetzen
2057 meDragType = RULER_TYPE_DONTKNOW;
2058 mnDragPos = 0;
2059 mnDragAryPos = 0;
2060 mnDragSize = 0;
2061 mnDragModifier = 0;
2062 mpData = mpSaveData;
2065 return FALSE;
2068 // -----------------------------------------------------------------------
2070 void Ruler::ImplDrag( const Point& rPos )
2072 long nX;
2073 long nY;
2074 long nOutHeight;
2076 if ( mnWinStyle & WB_HORZ )
2078 nX = rPos.X();
2079 nY = rPos.Y();
2080 nOutHeight = mnHeight;
2082 else
2084 nX = rPos.Y();
2085 nY = rPos.X();
2086 nOutHeight = mnWidth;
2089 // X berechnen und einpassen
2090 nX -= mnVirOff;
2091 if ( nX < mpData->nRulVirOff )
2093 nX = mpData->nRulVirOff;
2094 mnDragScroll = RULER_SCROLL_1;
2096 else if ( nX > mpData->nRulVirOff+mpData->nRulWidth )
2098 nX = mpData->nRulVirOff+mpData->nRulWidth;
2099 mnDragScroll = RULER_SCROLL_2;
2101 nX -= mpData->nNullVirOff;
2103 // Wenn oberhalb oder links vom Lineal, dann alte Werte
2104 mbDragDelete = FALSE;
2105 if ( nY < 0 )
2107 if ( !mbDragCanceled )
2109 // Daten wiederherstellen
2110 mbDragCanceled = TRUE;
2111 ImplRulerData aTempData;
2112 aTempData = *mpDragData;
2113 *mpDragData = *mpSaveData;
2114 mbCalc = TRUE;
2115 mbFormat = TRUE;
2117 // Handler rufen
2118 mnDragPos = mnStartDragPos;
2119 Drag();
2121 // Und neu ausgeben (zeitverzoegert)
2123 mnUpdateFlags |= RULER_UPDATE_DRAW;
2124 if ( mnUpdateEvtId )
2125 Application::RemoveUserEvent( mnUpdateEvtId );
2126 mnUpdateEvtId = Application::PostUserEvent( LINK( this, Ruler, ImplUpdateHdl ), NULL );
2128 ImplDraw();
2130 // Daten wieder wie vor dem Cancel herstellen
2131 *mpDragData = aTempData;
2134 else
2136 mbDragCanceled = FALSE;
2138 // +2, damit nicht so schnell die Tabs geloescht werden
2139 if ( nY > nOutHeight+2 )
2140 mbDragDelete = TRUE;
2142 mnDragPos = nX;
2144 // Handler rufen
2145 Drag();
2147 // Und neu ausgeben
2148 if ( mbFormat )
2149 ImplDraw();
2152 mnDragScroll = 0;
2155 // -----------------------------------------------------------------------
2157 void Ruler::ImplEndDrag()
2159 // Werte uebernehmen
2160 if ( mbDragCanceled )
2161 *mpDragData = *mpSaveData;
2162 else
2163 *mpSaveData = *mpDragData;
2164 mpData = mpSaveData;
2165 mbDrag = FALSE;
2167 // Handler rufen
2168 EndDrag();
2170 // Drag-Werte zuruecksetzen
2171 meDragType = RULER_TYPE_DONTKNOW;
2172 mnDragPos = 0;
2173 mnDragAryPos = 0;
2174 mnDragSize = 0;
2175 mbDragCanceled = FALSE;
2176 mbDragDelete = FALSE;
2177 mnDragModifier = 0;
2178 mnDragScroll = 0;
2179 mnStartDragPos = 0;
2181 // Und neu ausgeben
2182 ImplDraw();
2185 // -----------------------------------------------------------------------
2187 IMPL_LINK( Ruler, ImplUpdateHdl, void*, EMPTYARG )
2189 mnUpdateEvtId = 0;
2191 // Feststellen, was upgedatet werden muss
2192 if ( mnUpdateFlags & RULER_UPDATE_DRAW )
2194 mnUpdateFlags = 0;
2195 ImplDraw();
2197 else if ( mnUpdateFlags & RULER_UPDATE_LINES )
2199 mnUpdateFlags = 0;
2200 ImplInvertLines();
2203 return 0;
2206 // -----------------------------------------------------------------------
2208 void Ruler::MouseButtonDown( const MouseEvent& rMEvt )
2210 if ( rMEvt.IsLeft() && !IsTracking() )
2212 Point aMousePos = rMEvt.GetPosPixel();
2213 USHORT nMouseClicks = rMEvt.GetClicks();
2214 USHORT nMouseModifier = rMEvt.GetModifier();
2216 // Gegebenenfalls Lineal updaten (damit mit den richtigen Daten
2217 // gearbeitet wird und die Anzeige auch zur Bearbeitung passt)
2218 if ( mbFormat )
2220 ImplDraw();
2221 mnUpdateFlags &= ~RULER_UPDATE_DRAW;
2224 if ( maExtraRect.IsInside( aMousePos ) )
2226 mnExtraClicks = nMouseClicks;
2227 mnExtraModifier = nMouseModifier;
2228 ExtraDown();
2229 mnExtraClicks = 0;
2230 mnExtraModifier = 0;
2232 else
2234 ImplRulerHitTest aHitTest;
2236 if ( nMouseClicks == 1 )
2238 if ( ImplHitTest( aMousePos, &aHitTest ) )
2239 ImplStartDrag( &aHitTest, nMouseModifier );
2240 else
2242 // Position innerhalb des Lineal-Bereiches
2243 if ( aHitTest.eType == RULER_TYPE_DONTKNOW )
2245 mnDragPos = aHitTest.nPos;
2246 Click();
2247 mnDragPos = 0;
2249 // Nocheinmal HitTest durchfuehren, da durch den Click
2250 // zum Beispiel ein neuer Tab gesetzt werden konnte
2251 if ( ImplHitTest( aMousePos, &aHitTest ) )
2252 ImplStartDrag( &aHitTest, nMouseModifier );
2256 else
2258 if ( ImplHitTest( aMousePos, &aHitTest ) )
2260 mnDragPos = aHitTest.nPos;
2261 mnDragAryPos = aHitTest.nAryPos;
2263 meDragType = aHitTest.eType;
2265 DoubleClick();
2267 meDragType = RULER_TYPE_DONTKNOW;
2268 mnDragPos = 0;
2269 mnDragAryPos = 0;
2275 // -----------------------------------------------------------------------
2277 void Ruler::MouseMove( const MouseEvent& rMEvt )
2279 PointerStyle ePtrStyle = POINTER_ARROW;
2281 // Gegebenenfalls Lineal updaten (damit mit den richtigen Daten
2282 // gearbeitet wird und die Anzeige auch zur Bearbeitung passt)
2283 if ( mbFormat )
2285 ImplDraw();
2286 mnUpdateFlags &= ~RULER_UPDATE_DRAW;
2289 ImplRulerHitTest aHitTest;
2290 if ( ImplHitTest( rMEvt.GetPosPixel(), &aHitTest ) )
2292 if ( aHitTest.bSize )
2294 if ( mnWinStyle & WB_HORZ )
2295 ePtrStyle = POINTER_ESIZE;
2296 else
2297 ePtrStyle = POINTER_SSIZE;
2299 else if ( aHitTest.bSizeBar )
2301 if ( mnWinStyle & WB_HORZ )
2302 ePtrStyle = POINTER_HSIZEBAR;
2303 else
2304 ePtrStyle = POINTER_VSIZEBAR;
2308 SetPointer( Pointer( ePtrStyle ) );
2311 // -----------------------------------------------------------------------
2313 void Ruler::Tracking( const TrackingEvent& rTEvt )
2315 if ( rTEvt.IsTrackingEnded() )
2317 // Bei Abbruch, den alten Status wieder herstellen
2318 if ( rTEvt.IsTrackingCanceled() )
2320 mbDragCanceled = TRUE;
2321 mbFormat = TRUE;
2324 ImplEndDrag();
2326 else
2327 ImplDrag( rTEvt.GetMouseEvent().GetPosPixel() );
2330 // -----------------------------------------------------------------------
2332 void Ruler::Paint( const Rectangle& )
2334 ImplDraw();
2336 const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
2338 // Extra-Field beruecksichtigen
2339 if ( mnWinStyle & WB_EXTRAFIELD )
2341 if ( !(rStyleSettings.GetOptions() & STYLE_OPTION_MONO) )
2343 SetLineColor( rStyleSettings.GetShadowColor() );
2344 DrawLine( Point( maExtraRect.Left(), maExtraRect.Top() ),
2345 Point( maExtraRect.Right()-1, maExtraRect.Top() ) );
2346 DrawLine( Point( maExtraRect.Left(), maExtraRect.Top() ),
2347 Point( maExtraRect.Left(), maExtraRect.Bottom()-1 ) );
2348 DrawLine( Point( maExtraRect.Left(), maExtraRect.Bottom()-1 ),
2349 Point( maExtraRect.Right()-1, maExtraRect.Bottom()-1 ) );
2350 DrawLine( Point( maExtraRect.Right()-1, maExtraRect.Top() ),
2351 Point( maExtraRect.Right()-1, maExtraRect.Bottom()-1 ) );
2352 SetLineColor( rStyleSettings.GetLightColor() );
2353 DrawLine( Point( maExtraRect.Left()+1, maExtraRect.Top()+1 ),
2354 Point( maExtraRect.Right()-2, maExtraRect.Top()+1 ) );
2355 DrawLine( Point( maExtraRect.Left()+1, maExtraRect.Top()+1 ),
2356 Point( maExtraRect.Left()+1, maExtraRect.Bottom()-2 ) );
2357 DrawLine( Point( maExtraRect.Left(), maExtraRect.Bottom() ),
2358 Point( maExtraRect.Right(), maExtraRect.Bottom() ) );
2359 DrawLine( Point( maExtraRect.Right(), maExtraRect.Top() ),
2360 Point( maExtraRect.Right(), maExtraRect.Bottom() ) );
2362 else
2364 SetLineColor( rStyleSettings.GetWindowTextColor() );
2365 SetFillColor( rStyleSettings.GetWindowColor() );
2366 DrawRect( maExtraRect );
2369 // Imhalt vom Extrafeld ausgeben
2370 ImplDrawExtra( TRUE );
2373 if ( mnWinStyle & WB_BORDER )
2375 if ( mnWinStyle & WB_HORZ )
2377 if ( !(rStyleSettings.GetOptions() & STYLE_OPTION_MONO) )
2379 SetLineColor( rStyleSettings.GetShadowColor() );
2380 DrawLine( Point( mnBorderOff, mnHeight-2 ),
2381 Point( mnWidth, mnHeight-2 ) );
2382 if ( mnBorderOff )
2384 DrawLine( Point( mnBorderOff-1, mnHeight-2 ),
2385 Point( mnBorderOff-1, mnHeight-1 ) );
2388 SetLineColor( rStyleSettings.GetWindowTextColor() );
2389 DrawLine( Point( mnBorderOff, mnHeight-1 ),
2390 Point( mnWidth, mnHeight-1 ) );
2392 else
2394 if ( !(rStyleSettings.GetOptions() & STYLE_OPTION_MONO) )
2396 SetLineColor( rStyleSettings.GetShadowColor() );
2397 DrawLine( Point( mnWidth-2, mnBorderOff ),
2398 Point( mnWidth-2, mnHeight ) );
2399 if ( mnBorderOff )
2401 DrawLine( Point( mnWidth-2, mnBorderOff-1 ),
2402 Point( mnWidth-1, mnBorderOff-1 ) );
2405 SetLineColor( rStyleSettings.GetWindowTextColor() );
2406 DrawLine( Point( mnWidth-1, mnBorderOff ),
2407 Point( mnWidth-1, mnHeight ) );
2412 // -----------------------------------------------------------------------
2414 void Ruler::Resize()
2416 Size aWinSize = GetOutputSizePixel();
2418 long nNewHeight;
2419 if ( mnWinStyle & WB_HORZ )
2421 if ( aWinSize.Height() != mnHeight )
2422 nNewHeight = aWinSize.Height();
2423 else
2424 nNewHeight = 0;
2426 else
2428 if ( aWinSize.Width() != mnWidth )
2429 nNewHeight = aWinSize.Width();
2430 else
2431 nNewHeight = 0;
2434 // Hier schon Linien loeschen
2435 BOOL bVisible = IsReallyVisible();
2436 if ( bVisible && mpData->nLines )
2438 ImplInvertLines();
2439 mnUpdateFlags |= RULER_UPDATE_LINES;
2440 if ( !mnUpdateEvtId )
2441 mnUpdateEvtId = Application::PostUserEvent( LINK( this, Ruler, ImplUpdateHdl ), NULL );
2443 mbFormat = TRUE;
2445 // Wenn sich die Hoehe bzw. Breite aendert, dann muessen besimmte Werte
2446 // neu berechnet werden
2447 //extra field should always be updated
2448 ImplInitExtraField( mpData->bTextRTL );
2449 if ( nNewHeight )
2451 mbCalc = TRUE;
2452 mnVirHeight = nNewHeight - mnBorderWidth - (RULER_OFF*2);
2454 else
2456 if ( mpData->bAutoPageWidth )
2457 ImplUpdate( TRUE );
2458 else if ( mbAutoWinWidth )
2459 mbCalc = TRUE;
2462 // Wenn Ruler eine Groesse hat, dann Groesse vom VirtualDevice setzen
2463 if ( (mnVirWidth > RULER_MIN_SIZE) ||
2464 ((aWinSize.Width() > RULER_MIN_SIZE) && (aWinSize.Height() > RULER_MIN_SIZE)) )
2466 if ( mnWinStyle & WB_HORZ )
2467 mnVirWidth = aWinSize.Width()-mnVirOff;
2468 else
2469 mnVirWidth = aWinSize.Height()-mnVirOff;
2470 if ( mnVirWidth < RULER_MIN_SIZE )
2471 mnVirWidth = 0;
2474 // Gegebenenfalls ein Teil vom Rand loeschen, da 3D-Effekt/Trennlinie am
2475 // Fensterrand
2476 if ( bVisible )
2478 if ( nNewHeight )
2479 Invalidate();
2480 else if ( mpData->bAutoPageWidth )
2482 // Nur bei AutoPageWidth haben wir rechts einen 3D-Effekt,
2483 // der sich der Fensterbreite anpasst und deshalb neu gezeichnet
2484 // werden muss
2485 Rectangle aRect;
2487 if ( mnWinStyle & WB_HORZ )
2489 if ( mnWidth < aWinSize.Width() )
2490 aRect.Left() = mnWidth-RULER_RESIZE_OFF;
2491 else
2492 aRect.Left() = aWinSize.Width()-RULER_RESIZE_OFF;
2493 aRect.Right() = aRect.Left()+RULER_RESIZE_OFF;
2494 aRect.Top() = RULER_OFF;
2495 aRect.Bottom() = RULER_OFF+mnVirHeight;
2497 else
2499 if ( mnHeight < aWinSize.Height() )
2500 aRect.Top() = mnHeight-RULER_RESIZE_OFF;
2501 else
2502 aRect.Top() = aWinSize.Height()-RULER_RESIZE_OFF;
2503 aRect.Bottom() = aRect.Top()+RULER_RESIZE_OFF;
2504 aRect.Left() = RULER_OFF;
2505 aRect.Right() = RULER_OFF+mnVirHeight;
2508 Invalidate( aRect );
2512 // Neue Groesse merken
2513 mnWidth = aWinSize.Width();
2514 mnHeight = aWinSize.Height();
2517 // -----------------------------------------------------------------------
2519 void Ruler::StateChanged( StateChangedType nType )
2521 Window::StateChanged( nType );
2523 if ( nType == STATE_CHANGE_INITSHOW )
2524 ImplFormat();
2525 else if ( nType == STATE_CHANGE_UPDATEMODE )
2527 if ( IsReallyVisible() && IsUpdateMode() )
2528 ImplDraw();
2530 else if ( (nType == STATE_CHANGE_ZOOM) ||
2531 (nType == STATE_CHANGE_CONTROLFONT) )
2533 ImplInitSettings( TRUE, FALSE, FALSE );
2534 Invalidate();
2536 else if ( nType == STATE_CHANGE_CONTROLFOREGROUND )
2538 ImplInitSettings( FALSE, TRUE, FALSE );
2539 Invalidate();
2541 else if ( nType == STATE_CHANGE_CONTROLBACKGROUND )
2543 ImplInitSettings( FALSE, FALSE, TRUE );
2544 Invalidate();
2548 // -----------------------------------------------------------------------
2550 void Ruler::DataChanged( const DataChangedEvent& rDCEvt )
2552 Window::DataChanged( rDCEvt );
2554 if ( (rDCEvt.GetType() == DATACHANGED_FONTS) ||
2555 (rDCEvt.GetType() == DATACHANGED_DISPLAY) ||
2556 (rDCEvt.GetType() == DATACHANGED_FONTSUBSTITUTION) ||
2557 ((rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
2558 (rDCEvt.GetFlags() & SETTINGS_STYLE)) )
2560 mbFormat = TRUE;
2561 ImplInitSettings( TRUE, TRUE, TRUE );
2562 Invalidate();
2566 // -----------------------------------------------------------------------
2568 long Ruler::StartDrag()
2570 if ( maStartDragHdl.IsSet() )
2571 return maStartDragHdl.Call( this );
2572 else
2573 return FALSE;
2576 // -----------------------------------------------------------------------
2578 void Ruler::Drag()
2580 maDragHdl.Call( this );
2583 // -----------------------------------------------------------------------
2585 void Ruler::EndDrag()
2587 maEndDragHdl.Call( this );
2590 // -----------------------------------------------------------------------
2592 void Ruler::Click()
2594 maClickHdl.Call( this );
2597 // -----------------------------------------------------------------------
2599 void Ruler::DoubleClick()
2601 maDoubleClickHdl.Call( this );
2604 // -----------------------------------------------------------------------
2606 void Ruler::ExtraDown()
2608 maExtraDownHdl.Call( this );
2611 // -----------------------------------------------------------------------
2613 void Ruler::Activate()
2615 mbActive = TRUE;
2617 // Positionslinien wieder anzeigen (erst hinter mbActive=TRUE rufen, da
2618 // von ImplInvertLines() ausgewertet wird). Das Zeichnen der Linien
2619 // wird verzoegert, damit im vermutlich noch nicht gepainteten Zustand
2620 // Linien gezeichnet werden.
2621 mnUpdateFlags |= RULER_UPDATE_LINES;
2622 if ( !mnUpdateEvtId )
2623 mnUpdateEvtId = Application::PostUserEvent( LINK( this, Ruler, ImplUpdateHdl ), NULL );
2626 // -----------------------------------------------------------------------
2628 void Ruler::Deactivate()
2630 // Positionslinien loeschen (schon vor mbActive=FALSE rufen, da
2631 // von ImplInvertLines() ausgewertet wird)
2632 ImplInvertLines();
2634 mbActive = FALSE;
2637 // -----------------------------------------------------------------------
2639 BOOL Ruler::StartDocDrag( const MouseEvent& rMEvt, RulerType eDragType )
2641 if ( !mbDrag )
2643 Point aMousePos = rMEvt.GetPosPixel();
2644 USHORT nMouseClicks = rMEvt.GetClicks();
2645 USHORT nMouseModifier = rMEvt.GetModifier();
2646 ImplRulerHitTest aHitTest;
2647 if(eDragType != RULER_TYPE_DONTKNOW)
2648 aHitTest.bExpandTest = TRUE;
2650 // Gegebenenfalls Lineal updaten (damit mit den richtigen Daten
2651 // gearbeitet wird und die Anzeige auch zur Bearbeitung passt)
2652 if ( mbFormat )
2654 ImplDraw();
2655 mnUpdateFlags &= ~RULER_UPDATE_DRAW;
2658 if ( nMouseClicks == 1 )
2660 if ( ImplDocHitTest( aMousePos, eDragType, &aHitTest ) )
2662 Pointer aPtr;
2664 if ( aHitTest.bSize )
2666 if ( mnWinStyle & WB_HORZ )
2667 aPtr = Pointer( POINTER_ESIZE );
2668 else
2669 aPtr = Pointer( POINTER_SSIZE );
2671 else if ( aHitTest.bSizeBar )
2673 if ( mnWinStyle & WB_HORZ )
2674 aPtr = Pointer( POINTER_HSIZEBAR );
2675 else
2676 aPtr = Pointer( POINTER_VSIZEBAR );
2678 SetPointer( aPtr );
2679 return ImplStartDrag( &aHitTest, nMouseModifier );
2682 else if ( nMouseClicks == 2 )
2684 if ( ImplDocHitTest( aMousePos, eDragType, &aHitTest ) )
2686 mnDragPos = aHitTest.nPos;
2687 mnDragAryPos = aHitTest.nAryPos;
2689 eDragType = aHitTest.eType;
2691 DoubleClick();
2693 eDragType = RULER_TYPE_DONTKNOW;
2694 mnDragPos = 0;
2695 mnDragAryPos = 0;
2697 return TRUE;
2701 return FALSE;
2704 // -----------------------------------------------------------------------
2706 RulerType Ruler::GetDocType( const Point& rPos, RulerType eDragType,
2707 USHORT* pAryPos ) const
2709 ImplRulerHitTest aHitTest;
2711 // Gegebenenfalls Lineal updaten (damit mit den richtigen Daten
2712 // gearbeitet wird und die Anzeige auch zur Bearbeitung passt)
2713 if ( IsReallyVisible() && mbFormat )
2715 ((Ruler*)this)->ImplDraw();
2716 ((Ruler*)this)->mnUpdateFlags &= ~RULER_UPDATE_DRAW;
2719 // HitTest durchfuehren
2720 ImplDocHitTest( rPos, eDragType, &aHitTest );
2722 // Werte zurueckgeben
2723 if ( pAryPos )
2724 *pAryPos = aHitTest.nAryPos;
2725 return aHitTest.eType;
2728 // -----------------------------------------------------------------------
2730 void Ruler::CancelDrag()
2732 if ( mbDrag )
2734 ImplDrag( Point( -1, -1 ) );
2735 ImplEndDrag();
2739 // -----------------------------------------------------------------------
2741 RulerType Ruler::GetType( const Point& rPos, USHORT* pAryPos ) const
2743 ImplRulerHitTest aHitTest;
2745 // Gegebenenfalls Lineal updaten (damit mit den richtigen Daten
2746 // gearbeitet wird und die Anzeige auch zur Bearbeitung passt)
2747 if ( IsReallyVisible() && mbFormat )
2749 ((Ruler*)this)->ImplDraw();
2750 ((Ruler*)this)->mnUpdateFlags &= ~RULER_UPDATE_DRAW;
2753 // HitTest durchfuehren
2754 ImplHitTest( rPos, &aHitTest );
2756 // Werte zurueckgeben
2757 if ( pAryPos )
2758 *pAryPos = aHitTest.nAryPos;
2759 return aHitTest.eType;
2762 // -----------------------------------------------------------------------
2764 void Ruler::SetWinPos( long nNewOff, long nNewWidth )
2766 // Gegebenenfalls werden die Breiten automatisch berechnet
2767 if ( !nNewWidth )
2768 mbAutoWinWidth = TRUE;
2769 else
2770 mbAutoWinWidth = FALSE;
2772 // Werte setzen (werden in ImplFormat gegebenenfalls mitberechnet)
2773 mnWinOff = nNewOff;
2774 mnWinWidth = nNewWidth;
2775 ImplUpdate( TRUE );
2778 // -----------------------------------------------------------------------
2780 void Ruler::SetPagePos( long nNewOff, long nNewWidth )
2782 // Muessen wir ueberhaupt was machen
2783 if ( (mpData->nPageOff == nNewOff) && (mpData->nPageWidth == nNewWidth) )
2784 return;
2786 // Gegebenenfalls werden die Breiten automatisch berechnet
2787 if ( !nNewWidth )
2788 mpData->bAutoPageWidth = TRUE;
2789 else
2790 mpData->bAutoPageWidth = FALSE;
2792 // Werte setzen (werden in ImplFormat gegebenenfalls mitberechnet)
2793 mpData->nPageOff = nNewOff;
2794 mpData->nPageWidth = nNewWidth;
2795 ImplUpdate( TRUE );
2798 // -----------------------------------------------------------------------
2800 void Ruler::SetBorderPos( long nOff )
2802 if ( mnWinStyle & WB_BORDER )
2804 if ( mnBorderOff != nOff )
2806 mnBorderOff = nOff;
2808 if ( IsReallyVisible() && IsUpdateMode() )
2809 Invalidate();
2814 // -----------------------------------------------------------------------
2816 void Ruler::SetUnit( FieldUnit eNewUnit )
2818 if ( meUnit != eNewUnit )
2820 meUnit = eNewUnit;
2821 switch ( meUnit )
2823 case FUNIT_MM:
2824 mnUnitIndex = RULER_UNIT_MM;
2825 break;
2826 case FUNIT_CM:
2827 mnUnitIndex = RULER_UNIT_CM;
2828 break;
2829 case FUNIT_M:
2830 mnUnitIndex = RULER_UNIT_M;
2831 break;
2832 case FUNIT_KM:
2833 mnUnitIndex = RULER_UNIT_KM;
2834 break;
2835 case FUNIT_INCH:
2836 mnUnitIndex = RULER_UNIT_INCH;
2837 break;
2838 case FUNIT_FOOT:
2839 mnUnitIndex = RULER_UNIT_FOOT;
2840 break;
2841 case FUNIT_MILE:
2842 mnUnitIndex = RULER_UNIT_MILE;
2843 break;
2844 case FUNIT_POINT:
2845 mnUnitIndex = RULER_UNIT_POINT;
2846 break;
2847 case FUNIT_PICA:
2848 mnUnitIndex = RULER_UNIT_PICA;
2849 break;
2850 case FUNIT_CHAR:
2851 mnUnitIndex = RULER_UNIT_CHAR;
2852 break;
2853 case FUNIT_LINE:
2854 mnUnitIndex = RULER_UNIT_LINE;
2855 break;
2856 default:
2857 #ifdef DBG_UTIL
2858 DBG_ERRORFILE( "Ruler::SetUnit() - Wrong Unit" );
2859 #endif
2860 break;
2863 maMapMode.SetMapUnit( aImplRulerUnitTab[mnUnitIndex].eMapUnit );
2864 ImplUpdate();
2868 // -----------------------------------------------------------------------
2870 void Ruler::SetZoom( const Fraction& rNewZoom )
2872 DBG_ASSERT( rNewZoom.GetNumerator(), "Ruler::SetZoom() with scale 0 is not allowed" );
2874 if ( maZoom != rNewZoom )
2876 maZoom = rNewZoom;
2877 maMapMode.SetScaleX( maZoom );
2878 maMapMode.SetScaleY( maZoom );
2879 ImplUpdate();
2883 // -----------------------------------------------------------------------
2885 void Ruler::SetExtraType( RulerExtra eNewExtraType, USHORT nStyle )
2887 if ( mnWinStyle & WB_EXTRAFIELD )
2889 meExtraType = eNewExtraType;
2890 mnExtraStyle = nStyle;
2891 if ( IsReallyVisible() && IsUpdateMode() )
2892 ImplDrawExtra( FALSE );
2896 // -----------------------------------------------------------------------
2898 void Ruler::SetNullOffset( long nPos )
2900 if ( mpData->nNullOff != nPos )
2902 mpData->nNullOff = nPos;
2903 ImplUpdate();
2907 // -----------------------------------------------------------------------
2909 void Ruler::SetMargin1( long nPos, USHORT nMarginStyle )
2911 if ( (mpData->nMargin1 != nPos) || (mpData->nMargin1Style != nMarginStyle) )
2913 mpData->nMargin1 = nPos;
2914 mpData->nMargin1Style = nMarginStyle;
2915 ImplUpdate();
2919 // -----------------------------------------------------------------------
2921 void Ruler::SetMargin2( long nPos, USHORT nMarginStyle )
2923 DBG_ASSERT( (nPos >= mpData->nMargin1) ||
2924 (mpData->nMargin1Style & RULER_STYLE_INVISIBLE) ||
2925 (mpData->nMargin2Style & RULER_STYLE_INVISIBLE),
2926 "Ruler::SetMargin2() - Margin2 < Margin1" );
2928 if ( (mpData->nMargin2 != nPos) || (mpData->nMargin2Style != nMarginStyle) )
2930 mpData->nMargin2 = nPos;
2931 mpData->nMargin2Style = nMarginStyle;
2932 ImplUpdate();
2936 // -----------------------------------------------------------------------
2938 void Ruler::SetLines( USHORT n, const RulerLine* pLineAry )
2940 // Testen, ob sich was geaendert hat
2941 if ( mpData->nLines == n )
2943 USHORT i = n;
2944 const RulerLine* pAry1 = mpData->pLines;
2945 const RulerLine* pAry2 = pLineAry;
2946 while ( i )
2948 if ( (pAry1->nPos != pAry2->nPos) ||
2949 (pAry1->nStyle != pAry2->nStyle) )
2950 break;
2951 pAry1++;
2952 pAry2++;
2953 i--;
2955 if ( !i )
2956 return;
2959 // Neue Werte setzen und neu ausgeben
2960 BOOL bMustUpdate;
2961 if ( IsReallyVisible() && IsUpdateMode() )
2962 bMustUpdate = TRUE;
2963 else
2964 bMustUpdate = FALSE;
2966 // Alte Linien loeschen
2967 if ( bMustUpdate )
2968 ImplInvertLines();
2970 // Neue Daten setzen
2971 if ( !n || !pLineAry )
2973 if ( !mpData->pLines )
2974 return;
2975 delete[] mpData->pLines;
2976 mpData->nLines = 0;
2977 mpData->pLines = NULL;
2979 else
2981 if ( mpData->nLines != n )
2983 delete[] mpData->pLines;
2984 mpData->nLines = n;
2985 mpData->pLines = new RulerLine[n];
2988 memcpy( mpData->pLines, pLineAry, n*sizeof( RulerLine ) );
2990 // Linien neu ausgeben
2991 if ( bMustUpdate )
2992 ImplInvertLines();
2996 // -----------------------------------------------------------------------
2998 void Ruler::SetArrows( USHORT n, const RulerArrow* pArrowAry )
3000 if ( !n || !pArrowAry )
3002 if ( !mpData->pArrows )
3003 return;
3004 delete[] mpData->pArrows;
3005 mpData->nArrows = 0;
3006 mpData->pArrows = NULL;
3008 else
3010 if ( mpData->nArrows != n )
3012 delete[] mpData->pArrows;
3013 mpData->nArrows = n;
3014 mpData->pArrows = new RulerArrow[n];
3016 else
3018 USHORT i = n;
3019 const RulerArrow* pAry1 = mpData->pArrows;
3020 const RulerArrow* pAry2 = pArrowAry;
3021 while ( i )
3023 if ( (pAry1->nPos != pAry2->nPos) ||
3024 (pAry1->nWidth != pAry2->nWidth) ||
3025 (pAry1->nLogWidth != pAry2->nLogWidth) ||
3026 (pAry1->nStyle != pAry2->nStyle) )
3027 break;
3028 pAry1++;
3029 pAry2++;
3030 i--;
3032 if ( !i )
3033 return;
3036 memcpy( mpData->pArrows, pArrowAry, n*sizeof( RulerArrow ) );
3039 ImplUpdate();
3042 // -----------------------------------------------------------------------
3044 void Ruler::SetBorders( USHORT n, const RulerBorder* pBrdAry )
3046 if ( !n || !pBrdAry )
3048 if ( !mpData->pBorders )
3049 return;
3050 delete[] mpData->pBorders;
3051 mpData->nBorders = 0;
3052 mpData->pBorders = NULL;
3054 else
3056 if ( mpData->nBorders != n )
3058 delete[] mpData->pBorders;
3059 mpData->nBorders = n;
3060 mpData->pBorders = new RulerBorder[n];
3062 else
3064 USHORT i = n;
3065 const RulerBorder* pAry1 = mpData->pBorders;
3066 const RulerBorder* pAry2 = pBrdAry;
3067 while ( i )
3069 if ( (pAry1->nPos != pAry2->nPos) ||
3070 (pAry1->nWidth != pAry2->nWidth) ||
3071 (pAry1->nStyle != pAry2->nStyle) )
3072 break;
3073 pAry1++;
3074 pAry2++;
3075 i--;
3077 if ( !i )
3078 return;
3081 memcpy( mpData->pBorders, pBrdAry, n*sizeof( RulerBorder ) );
3084 ImplUpdate();
3087 // -----------------------------------------------------------------------
3089 void Ruler::SetIndents( USHORT n, const RulerIndent* pIndentAry )
3092 if ( !n || !pIndentAry )
3094 if ( !mpData->pIndents )
3095 return;
3096 delete[] mpData->pIndents;
3097 mpData->nIndents = 0;
3098 mpData->pIndents = NULL;
3100 else
3102 if ( mpData->nIndents != n )
3104 delete[] mpData->pIndents;
3105 mpData->nIndents = n;
3106 mpData->pIndents = new RulerIndent[n];
3108 else
3110 USHORT i = n;
3111 const RulerIndent* pAry1 = mpData->pIndents;
3112 const RulerIndent* pAry2 = pIndentAry;
3113 while ( i )
3115 if ( (pAry1->nPos != pAry2->nPos) ||
3116 (pAry1->nStyle != pAry2->nStyle) )
3117 break;
3118 pAry1++;
3119 pAry2++;
3120 i--;
3122 if ( !i )
3123 return;
3126 memcpy( mpData->pIndents, pIndentAry, n*sizeof( RulerIndent ) );
3129 ImplUpdate();
3132 // -----------------------------------------------------------------------
3134 void Ruler::SetTabs( USHORT n, const RulerTab* pTabAry )
3136 if ( !n || !pTabAry )
3138 if ( !mpData->pTabs )
3139 return;
3140 delete[] mpData->pTabs;
3141 mpData->nTabs = 0;
3142 mpData->pTabs = NULL;
3144 else
3146 if ( mpData->nTabs != n )
3148 delete[] mpData->pTabs;
3149 mpData->nTabs = n;
3150 mpData->pTabs = new RulerTab[n];
3152 else
3154 USHORT i = n;
3155 const RulerTab* pAry1 = mpData->pTabs;
3156 const RulerTab* pAry2 = pTabAry;
3157 while ( i )
3159 if ( (pAry1->nPos != pAry2->nPos) ||
3160 (pAry1->nStyle != pAry2->nStyle) )
3161 break;
3162 pAry1++;
3163 pAry2++;
3164 i--;
3166 if ( !i )
3167 return;
3170 memcpy( mpData->pTabs, pTabAry, n*sizeof( RulerTab ) );
3173 ImplUpdate();
3176 // -----------------------------------------------------------------------
3178 void Ruler::SetStyle( WinBits nStyle )
3180 if ( mnWinStyle != nStyle )
3182 mnWinStyle = nStyle;
3183 ImplInitExtraField( TRUE );
3187 // -----------------------------------------------------------------------
3189 void Ruler::DrawTab( OutputDevice* pDevice, const Point& rPos, USHORT nStyle )
3191 /*const StyleSettings& rStyleSettings =*/ pDevice->GetSettings().GetStyleSettings();
3192 Point aPos( rPos );
3193 USHORT nTabStyle = nStyle & (RULER_TAB_STYLE | RULER_TAB_RTL);
3195 pDevice->Push( PUSH_LINECOLOR | PUSH_FILLCOLOR );
3196 pDevice->SetLineColor();
3197 pDevice->SetFillColor( pDevice->GetSettings().GetStyleSettings().GetWindowTextColor() );
3198 ImplCenterTabPos( aPos, nTabStyle );
3199 ImplDrawRulerTab( pDevice, aPos, nTabStyle, nStyle );
3200 pDevice->Pop();
3202 /* -----------------16.10.2002 15:17-----------------
3204 * --------------------------------------------------*/
3205 void Ruler::SetTextRTL(BOOL bRTL)
3207 if(mpData->bTextRTL != bRTL)
3209 mpData->bTextRTL = bRTL;
3210 if ( IsReallyVisible() && IsUpdateMode() )
3211 ImplInitExtraField( TRUE );
3215 long Ruler::GetPageOffset() const { return mpData->nPageOff; }
3216 long Ruler::GetPageWidth() const { return mpData->nPageWidth; }
3217 long Ruler::GetNullOffset() const { return mpData->nNullOff; }
3218 long Ruler::GetMargin1() const { return mpData->nMargin1; }
3219 USHORT Ruler::GetMargin1Style() const { return mpData->nMargin1Style; }
3220 long Ruler::GetMargin2() const { return mpData->nMargin2; }
3221 USHORT Ruler::GetMargin2Style() const { return mpData->nMargin2Style; }
3222 USHORT Ruler::GetLineCount() const { return mpData->nLines; }
3223 const RulerLine* Ruler::GetLines() const { return mpData->pLines; }
3224 USHORT Ruler::GetArrowCount() const { return mpData->nArrows; }
3225 const RulerArrow* Ruler::GetArrows() const { return mpData->pArrows; }
3226 USHORT Ruler::GetBorderCount() const { return mpData->nBorders; }
3227 const RulerBorder* Ruler::GetBorders() const { return mpData->pBorders; }
3228 USHORT Ruler::GetIndentCount() const { return mpData->nIndents; }
3229 const RulerIndent* Ruler::GetIndents() const { return mpData->pIndents; }
3231 /* ---------------------------------------------------
3233 * ---------------------------------------------------*/
3234 void Ruler::DrawTicks()
3236 mbFormat = TRUE;
3237 ImplDraw();