1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include <tools/debug.hxx>
22 #include <vcl/svapp.hxx>
23 #include <tools/poly.hxx>
24 #include <vcl/i18nhelp.hxx>
25 #include <vcl/settings.hxx>
27 #include <svtools/ruler.hxx>
28 #include <svtools/svtresid.hxx>
29 #include <svtools/svtools.hrc>
30 #include <svtools/colorcfg.hxx>
32 #include <boost/scoped_array.hpp>
36 using namespace ::com::sun::star
;
37 using namespace ::com::sun::star::uno
;
38 using namespace ::com::sun::star::lang
;
39 using namespace ::com::sun::star::accessibility
;
42 #define RULER_RESIZE_OFF 4
43 #define RULER_MIN_SIZE 3
45 #define RULER_VAR_SIZE 8
47 #define RULER_UPDATE_LINES 0x01
49 #define RULER_CLIP 150
51 #define RULER_UNIT_MM 0
52 #define RULER_UNIT_CM 1
53 #define RULER_UNIT_M 2
54 #define RULER_UNIT_KM 3
55 #define RULER_UNIT_INCH 4
56 #define RULER_UNIT_FOOT 5
57 #define RULER_UNIT_MILE 6
58 #define RULER_UNIT_POINT 7
59 #define RULER_UNIT_PICA 8
60 #define RULER_UNIT_CHAR 9
61 #define RULER_UNIT_LINE 10
62 #define RULER_UNIT_COUNT 11
69 vector
<RulerLine
> pLines
;
70 vector
<RulerBorder
> pBorders
;
71 vector
<RulerIndent
> pIndents
;
72 vector
<RulerTab
> pTabs
;
82 long nLeftFrameMargin
;
83 long nRightFrameMargin
;
84 sal_uInt16 nMargin1Style
;
85 sal_uInt16 nMargin2Style
;
93 ImplRulerData
& operator=( const ImplRulerData
& rData
);
96 ImplRulerData::ImplRulerData() :
105 nLeftFrameMargin (0),
106 nRightFrameMargin (0),
109 bAutoPageWidth (true), // Page width == EditWin width
114 ImplRulerData::~ImplRulerData()
117 ImplRulerData
& ImplRulerData::operator=( const ImplRulerData
& rData
)
122 nNullVirOff
= rData
.nNullVirOff
;
123 nRulVirOff
= rData
.nRulVirOff
;
124 nRulWidth
= rData
.nRulWidth
;
125 nPageOff
= rData
.nPageOff
;
126 nPageWidth
= rData
.nPageWidth
;
127 nNullOff
= rData
.nNullOff
;
128 nMargin1
= rData
.nMargin1
;
129 nMargin2
= rData
.nMargin2
;
130 nLeftFrameMargin
= rData
.nLeftFrameMargin
;
131 nRightFrameMargin
= rData
.nRightFrameMargin
;
132 nMargin1Style
= rData
.nMargin1Style
;
133 nMargin2Style
= rData
.nMargin2Style
;
134 bAutoPageWidth
= rData
.bAutoPageWidth
;
135 bTextRTL
= rData
.bTextRTL
;
137 if ( !rData
.pLines
.empty() )
139 pLines
.resize(rData
.pLines
.size());
140 std::copy(rData
.pLines
.begin(), rData
.pLines
.end(), pLines
.begin());
147 if ( !rData
.pBorders
.empty() )
149 pBorders
.resize(rData
.pBorders
.size());
150 std::copy(rData
.pBorders
.begin(), rData
.pBorders
.end(), pBorders
.begin());
157 if ( !rData
.pIndents
.empty() )
159 pIndents
.resize(rData
.pIndents
.size());
160 std::copy(rData
.pIndents
.begin(), rData
.pIndents
.end(), pIndents
.begin());
167 if ( !rData
.pTabs
.empty() )
169 pTabs
.resize(rData
.pTabs
.size());
170 std::copy(rData
.pTabs
.begin(), rData
.pTabs
.end(), pTabs
.begin());
180 static const RulerUnitData aImplRulerUnitTab
[RULER_UNIT_COUNT
] =
182 { MAP_100TH_MM
, 100, 25.0, 25.0, 50.0, 100.0, 100, 3, " mm" }, // MM
183 { MAP_100TH_MM
, 1000, 100.0, 500.0, 1000.0, 1000.0, 1000, 3, " cm" }, // CM
184 { MAP_MM
, 1000, 10.0, 250.0, 500.0, 1000.0, 10000, 4, " m" }, // M
185 { MAP_CM
, 100000, 12500.0, 25000.0, 50000.0, 100000.0, 100000, 6, " km" }, // KM
186 { MAP_1000TH_INCH
, 1000, 62.5, 125.0, 500.0, 1000.0, 25400, 3, "\"" }, // INCH
187 { MAP_100TH_INCH
, 1200, 120.0, 120.0, 600.0, 1200.0, 30480, 3, "'" }, // FOOT
188 { MAP_10TH_INCH
, 633600, 63360.0, 63360.0, 316800.0, 633600.0, 1609344, 4, " miles" }, // MILE
189 { MAP_POINT
, 1, 12.0, 12.0, 12.0, 36.0, 353, 2, " pt" }, // POINT
190 { MAP_100TH_MM
, 423, 423.0, 423.0, 423.0, 846.0, 423, 3, " pi" }, // PICA
191 { MAP_100TH_MM
, 371, 371.0, 371.0, 371.0, 743.0, 371, 3, " ch" }, // CHAR
192 { MAP_100TH_MM
, 551, 551.0, 551.0, 551.0, 1102.0, 551, 3, " li" } // LINE
195 static RulerTabData ruler_tab
=
197 0, // DPIScaleFactor to be set
198 7, // ruler_tab_width
199 6, // ruler_tab_height
200 2, // ruler_tab_height2
201 2, // ruler_tab_width2
202 8, // ruler_tab_cwidth
203 4, // ruler_tab_cwidth2
204 4, // ruler_tab_cwidth3
205 2, // ruler_tab_cwidth4
206 4, // ruler_tab_dheight
207 1, // ruler_tab_dheight2
208 5, // ruler_tab_dwidth
209 3, // ruler_tab_dwidth2
210 3, // ruler_tab_dwidth3
211 1, // ruler_tab_dwidth4
212 5 // ruler_tab_textoff
215 void Ruler::ImplInit( WinBits nWinBits
)
217 // Default WinBits setzen
218 if ( !(nWinBits
& WB_VERT
) )
222 // --- RTL --- no UI mirroring for horizontal rulers, because
223 // the document is also not mirrored
227 // Initialize variables
228 mnWinStyle
= nWinBits
; // Window-Style
229 mnBorderOff
= 0; // Border-Offset
230 mnWinOff
= 0; // EditWinOffset
231 mnWinWidth
= 0; // EditWinWidth
232 mnWidth
= 0; // Window width
233 mnHeight
= 0; // Window height
234 mnVirOff
= 0; // Offset of VirtualDevice from top-left corner
235 mnVirWidth
= 0; // width or height from VirtualDevice
236 mnVirHeight
= 0; // height of width from VirtualDevice
237 mnDragPos
= 0; // Drag-Position (Null point)
238 mnUpdateEvtId
= 0; // Update event was not sent yet
239 mnDragAryPos
= 0; // Drag-Array-Index
240 mnDragSize
= 0; // Did size change at dragging
241 mnDragModifier
= 0; // Modifier key at dragging
242 mnExtraStyle
= 0; // Style of Extra field
243 mnExtraClicks
= 0; // No. of clicks for Extra field
244 mnExtraModifier
= 0; // Modifier key at click in extra field
247 mbCalc
= true; // Should recalculate page width
248 mbFormat
= true; // Should redraw
249 mbDrag
= false; // Currently at dragging
250 mbDragDelete
= false; // Has mouse left the dragging area
251 mbDragCanceled
= false; // Dragging cancelled?
252 mbAutoWinWidth
= true; // EditWinWidth == RulerWidth
253 mbActive
= true; // Is ruler active
254 mnUpdateFlags
= 0; // What needs to be updated
255 mpData
= mpSaveData
; // Pointer to normal data
256 meExtraType
= RULER_EXTRA_DONTKNOW
; // What is in extra field
257 meDragType
= RULER_TYPE_DONTKNOW
; // Which element is dragged
260 mnUnitIndex
= RULER_UNIT_CM
;
262 maZoom
= Fraction( 1, 1 );
263 meSourceUnit
= MAP_100TH_MM
;
265 // Recalculate border widths
266 if ( nWinBits
& WB_BORDER
)
272 ImplInitSettings( true, true, true );
274 // Setup the default size
276 GetTextBoundRect( aRect
, OUString( "0123456789" ) );
277 long nDefHeight
= aRect
.GetHeight() + RULER_OFF
* 2 + ruler_tab
.textoff
* 2 + mnBorderWidth
;
280 if ( nWinBits
& WB_HORZ
)
281 aDefSize
.Height() = nDefHeight
;
283 aDefSize
.Width() = nDefHeight
;
284 SetOutputSizePixel( aDefSize
);
285 SetType(WINDOW_RULER
);
289 Ruler::Ruler( vcl::Window
* pParent
, WinBits nWinStyle
) :
290 Window( pParent
, nWinStyle
& WB_3DLOOK
),
291 maVirDev( VclPtr
<VirtualDevice
>::Create(*this) ),
292 maMapMode( MAP_100TH_MM
),
293 mpSaveData(new ImplRulerData
),
295 mpDragData(new ImplRulerData
)
297 // Check to see if the ruler constructor has
298 // already been called before otherwise
299 // we end up with over-scaled elements
300 if (ruler_tab
.DPIScaleFactor
== 0)
302 ruler_tab
.DPIScaleFactor
= GetDPIScaleFactor();
303 ruler_tab
.width
*= ruler_tab
.DPIScaleFactor
;
304 ruler_tab
.height
*= ruler_tab
.DPIScaleFactor
;
305 ruler_tab
.height2
*= ruler_tab
.DPIScaleFactor
;
306 ruler_tab
.width2
*= ruler_tab
.DPIScaleFactor
;
307 ruler_tab
.cwidth
*= ruler_tab
.DPIScaleFactor
;
308 ruler_tab
.cwidth2
*= ruler_tab
.DPIScaleFactor
;
309 ruler_tab
.cwidth3
*= ruler_tab
.DPIScaleFactor
;
310 ruler_tab
.cwidth4
*= ruler_tab
.DPIScaleFactor
;
311 ruler_tab
.dheight
*= ruler_tab
.DPIScaleFactor
;
312 ruler_tab
.dheight2
*= ruler_tab
.DPIScaleFactor
;
313 ruler_tab
.dwidth
*= ruler_tab
.DPIScaleFactor
;
314 ruler_tab
.dwidth2
*= ruler_tab
.DPIScaleFactor
;
315 ruler_tab
.dwidth3
*= ruler_tab
.DPIScaleFactor
;
316 ruler_tab
.dwidth4
*= ruler_tab
.DPIScaleFactor
;
317 ruler_tab
.textoff
*= ruler_tab
.DPIScaleFactor
;
321 ImplInit( nWinStyle
);
329 void Ruler::dispose()
332 Application::RemoveUserEvent( mnUpdateEvtId
);
339 pAccContext
->release();
345 void Ruler::ImplVDrawLine(vcl::RenderContext
& rRenderContext
, long nX1
, long nY1
, long nX2
, long nY2
)
347 if ( nX1
< -RULER_CLIP
)
350 if ( nX2
< -RULER_CLIP
)
353 long nClip
= mnVirWidth
+ RULER_CLIP
;
361 if ( mnWinStyle
& WB_HORZ
)
362 rRenderContext
.DrawLine( Point( nX1
, nY1
), Point( nX2
, nY2
) );
364 rRenderContext
.DrawLine( Point( nY1
, nX1
), Point( nY2
, nX2
) );
367 void Ruler::ImplVDrawRect(vcl::RenderContext
& rRenderContext
, long nX1
, long nY1
, long nX2
, long nY2
)
369 if ( nX1
< -RULER_CLIP
)
372 if ( nX2
< -RULER_CLIP
)
375 long nClip
= mnVirWidth
+ RULER_CLIP
;
383 if ( mnWinStyle
& WB_HORZ
)
384 rRenderContext
.DrawRect(Rectangle(nX1
, nY1
, nX2
, nY2
));
386 rRenderContext
.DrawRect(Rectangle(nY1
, nX1
, nY2
, nX2
));
389 void Ruler::ImplVDrawText(vcl::RenderContext
& rRenderContext
, long nX
, long nY
, const OUString
& rText
, long nMin
, long nMax
)
392 rRenderContext
.GetTextBoundRect(aRect
, rText
);
394 long nShiftX
= ( aRect
.GetWidth() / 2 ) + aRect
.Left();
395 long nShiftY
= ( aRect
.GetHeight() / 2 ) + aRect
.Top();
397 if ( (nX
> -RULER_CLIP
) && (nX
< mnVirWidth
+ RULER_CLIP
) && ( nX
< nMax
- nShiftX
) && ( nX
> nMin
+ nShiftX
) )
399 if ( mnWinStyle
& WB_HORZ
)
400 rRenderContext
.DrawText(Point(nX
- nShiftX
, nY
- nShiftY
), rText
);
402 rRenderContext
.DrawText(Point(nY
- nShiftX
, nX
- nShiftY
), rText
);
406 void Ruler::ImplInvertLines(vcl::RenderContext
& rRenderContext
, bool bErase
)
409 if (!mpData
->pLines
.empty() && mbActive
&& !mbDrag
&& !mbFormat
&& !(mnUpdateFlags
& RULER_UPDATE_LINES
) )
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 // Calculate rectangle
418 if (mnWinStyle
& WB_HORZ
)
424 for (sal_uInt32 i
= 0; i
< mpData
->pLines
.size(); i
++)
426 const long n
= mpData
->pLines
[i
].nPos
+ nNullWinOff
;
427 if ((n
>= nRulX1
) && (n
< nRulX2
))
429 if (mnWinStyle
& WB_HORZ
)
441 Rectangle aTempRect
= aRect
;
443 if (mnWinStyle
& WB_HORZ
)
444 aTempRect
.Bottom() = RULER_OFF
- 1;
446 aTempRect
.Right() = RULER_OFF
- 1;
448 rRenderContext
.Erase(aTempRect
);
450 if (mnWinStyle
& WB_HORZ
)
452 aTempRect
.Bottom() = aRect
.Bottom();
453 aTempRect
.Top() = aTempRect
.Bottom() - RULER_OFF
+ 1;
457 aTempRect
.Right() = aRect
.Right();
458 aTempRect
.Left() = aTempRect
.Right() - RULER_OFF
+ 1;
460 rRenderContext
.Erase(aTempRect
);
469 void Ruler::ImplDrawTicks(vcl::RenderContext
& rRenderContext
, long nMin
, long nMax
, long nStart
, long nTop
, long nBottom
)
471 double nCenter
= nTop
+ ((nBottom
- nTop
) / 2);
473 long nTickLength3
= (nBottom
- nTop
) * 0.5;
474 long nTickLength2
= nTickLength3
* 0.66;
475 long nTickLength1
= nTickLength2
* 0.66;
477 long nScale
= ruler_tab
.DPIScaleFactor
;
478 long DPIOffset
= nScale
- 1;
480 double nTick4
= aImplRulerUnitTab
[mnUnitIndex
].nTick4
;
482 double nTickCount
= aImplRulerUnitTab
[mnUnitIndex
].nTick1
/ nScale
;
483 double nTickUnit
= 0;
485 bool bNoTicks
= false;
487 double nAcceptanceDelta
= 0.0001;
489 Size aPixSize
= rRenderContext
.LogicToPixel(Size(nTick4
, nTick4
), maMapMode
);
491 if (mnUnitIndex
== RULER_UNIT_CHAR
)
493 if (mnCharWidth
== 0)
495 nTick4
= mnCharWidth
* 2;
496 nTick2
= mnCharWidth
;
497 nTickCount
= mnCharWidth
;
498 nTickUnit
= mnCharWidth
;
500 else if (mnUnitIndex
== RULER_UNIT_LINE
)
502 if (mnLineHeight
== 0)
504 nTick4
= mnLineHeight
* 2;
505 nTick2
= mnLineHeight
;
506 nTickUnit
= mnLineHeight
;
507 nTickCount
= mnLineHeight
;
510 if (mnWinStyle
& WB_HORZ
)
512 nTickWidth
= aPixSize
.Width();
516 vcl::Font aFont
= rRenderContext
.GetFont();
517 if (mnWinStyle
& WB_RIGHT_ALIGNED
)
518 aFont
.SetOrientation(2700);
520 aFont
.SetOrientation(900);
521 rRenderContext
.SetFont(aFont
);
522 nTickWidth
= aPixSize
.Height();
525 long nMaxWidth
= rRenderContext
.PixelToLogic(Size(mpData
->nPageWidth
, 0), maMapMode
).Width();
527 nMaxWidth
= -nMaxWidth
;
529 if ((mnUnitIndex
== RULER_UNIT_CHAR
) || (mnUnitIndex
== RULER_UNIT_LINE
))
530 nMaxWidth
/= nTickUnit
;
532 nMaxWidth
/= aImplRulerUnitTab
[mnUnitIndex
].nTickUnit
;
534 OUString aNumString
= OUString::number(nMaxWidth
);
535 long nTxtWidth
= rRenderContext
.GetTextWidth( aNumString
);
536 const long nTextOff
= 4;
538 // Determine the number divider for ruler drawn numbers - means which numbers
539 // should be shown on the ruler and which should be skipped because the ruler
540 // is not big enough to draw them
541 if (nTickWidth
< nTxtWidth
+ nTextOff
)
543 // Calculate the scale of the ruler
545 long nOrgTick4
= nTick4
;
547 while (nTickWidth
< nTxtWidth
+ nTextOff
)
549 long nOldMulti
= nMulti
;
552 else if (nMulti
< 10)
554 else if (nMulti
< 100)
556 else if (nMulti
< 1000)
561 // Overflow - in this case don't draw ticks and exit
562 if (nMulti
< nOldMulti
)
568 nTick4
= nOrgTick4
* nMulti
;
569 aPixSize
= rRenderContext
.LogicToPixel(Size(nTick4
, nTick4
), maMapMode
);
570 if (mnWinStyle
& WB_HORZ
)
571 nTickWidth
= aPixSize
.Width();
573 nTickWidth
= aPixSize
.Height();
579 rRenderContext
.SetLineColor(rRenderContext
.GetSettings().GetStyleSettings().GetShadowColor());
588 if ((mnUnitIndex
!= RULER_UNIT_CHAR
) && (mnUnitIndex
!= RULER_UNIT_LINE
))
590 nTick2
= aImplRulerUnitTab
[mnUnitIndex
].nTick2
;
591 nTick3
= aImplRulerUnitTab
[mnUnitIndex
].nTick3
;
596 nTickGapSize
= rRenderContext
.LogicToPixel(Size(nTickCount
, nTickCount
), maMapMode
);
597 long nTickGap1
= mnWinStyle
& WB_HORZ
? nTickGapSize
.Width() : nTickGapSize
.Height();
598 nTickGapSize
= rRenderContext
.LogicToPixel(Size(nTick2
, nTick2
), maMapMode
);
599 long nTickGap2
= mnWinStyle
& WB_HORZ
? nTickGapSize
.Width() : nTickGapSize
.Height();
600 nTickGapSize
= rRenderContext
.LogicToPixel(Size(nTick3
, nTick3
), maMapMode
);
601 long nTickGap3
= mnWinStyle
& WB_HORZ
? nTickGapSize
.Width() : nTickGapSize
.Height();
603 while (((nStart
- n
) >= nMin
) || ((nStart
+ n
) <= nMax
))
610 // 0 is only painted when Margin1 is not equal to zero
611 if ((mpData
->nMargin1Style
& RULER_STYLE_INVISIBLE
) || (mpData
->nMargin1
!= 0))
614 ImplVDrawText(rRenderContext
, nStart
, nCenter
, aNumString
);
620 aPixSize
= rRenderContext
.LogicToPixel(Size(nTick
, nTick
), maMapMode
);
622 if (mnWinStyle
& WB_HORZ
)
623 n
= aPixSize
.Width();
625 n
= aPixSize
.Height();
627 // Tick4 - Output (Text)
628 double aStep
= (nTick
/ nTick4
);
629 double aRest
= std::abs(aStep
- std::floor(aStep
));
631 if (aRest
< nAcceptanceDelta
)
633 if ((mnUnitIndex
== RULER_UNIT_CHAR
) || (mnUnitIndex
== RULER_UNIT_LINE
))
634 aNumString
= OUString::number(nTick
/ nTickUnit
);
636 aNumString
= OUString::number(nTick
/ aImplRulerUnitTab
[mnUnitIndex
].nTickUnit
);
638 long nHorizontalLocation
= nStart
+ n
;
639 ImplVDrawText(rRenderContext
, nHorizontalLocation
, nCenter
, aNumString
, nMin
, nMax
);
641 if (nMin
< nHorizontalLocation
&& nHorizontalLocation
< nMax
)
643 ImplVDrawRect(rRenderContext
, nHorizontalLocation
, nBottom
, nHorizontalLocation
+ DPIOffset
, nBottom
- 1 * nScale
);
644 ImplVDrawRect(rRenderContext
, nHorizontalLocation
, nTop
, nHorizontalLocation
+ DPIOffset
, nTop
+ 1 * nScale
);
647 nHorizontalLocation
= nStart
- n
;
648 ImplVDrawText(rRenderContext
, nHorizontalLocation
, nCenter
, aNumString
, nMin
, nMax
);
650 if (nMin
< nHorizontalLocation
&& nHorizontalLocation
< nMax
)
652 ImplVDrawRect(rRenderContext
, nHorizontalLocation
, nBottom
,
653 nHorizontalLocation
+ DPIOffset
, nBottom
- 1 * nScale
);
654 ImplVDrawRect(rRenderContext
, nHorizontalLocation
, nTop
,
655 nHorizontalLocation
+ DPIOffset
, nTop
+ 1 * nScale
);
658 // Tick/Tick2 - Output (Strokes)
661 long nTickLength
= nTickLength1
;
663 aStep
= (nTick
/ nTick2
);
664 aRest
= std::abs(aStep
- std::floor(aStep
));
665 if (aRest
< nAcceptanceDelta
)
666 nTickLength
= nTickLength2
;
668 aStep
= (nTick
/ nTick3
);
669 aRest
= std::abs(aStep
- std::floor(aStep
));
670 if (aRest
< nAcceptanceDelta
)
671 nTickLength
= nTickLength3
;
673 if ((nTickLength
== nTickLength1
&& nTickGap1
> 6) ||
674 (nTickLength
== nTickLength2
&& nTickGap2
> 6) ||
675 (nTickLength
== nTickLength3
&& nTickGap3
> 6))
677 long nT1
= nCenter
- (nTickLength
/ 2.0);
678 long nT2
= nT1
+ nTickLength
- 1;
684 ImplVDrawRect(rRenderContext
, nT
, nT1
, nT
+ DPIOffset
, nT2
);
687 ImplVDrawRect(rRenderContext
, nT
, nT1
, nT
+ DPIOffset
, nT2
);
696 void Ruler::ImplDrawBorders(vcl::RenderContext
& rRenderContext
, long nMin
, long nMax
, long nVirTop
, long nVirBottom
)
698 const StyleSettings
& rStyleSettings
= rRenderContext
.GetSettings().GetStyleSettings();
706 for (i
= 0; i
< mpData
->pBorders
.size(); i
++)
708 if (mpData
->pBorders
[i
].nStyle
& RULER_STYLE_INVISIBLE
)
711 n1
= mpData
->pBorders
[i
].nPos
+ mpData
->nNullVirOff
;
712 n2
= n1
+ mpData
->pBorders
[i
].nWidth
;
714 if (((n1
>= nMin
) && (n1
<= nMax
)) || ((n2
>= nMin
) && (n2
<= nMax
)))
718 rRenderContext
.SetLineColor();
719 rRenderContext
.SetFillColor(rStyleSettings
.GetFaceColor());
720 ImplVDrawRect(rRenderContext
, n1
, nVirTop
, n2
, nVirBottom
);
722 rRenderContext
.SetLineColor(rStyleSettings
.GetLightColor());
723 ImplVDrawLine(rRenderContext
, n1
+ 1, nVirTop
, n1
+ 1, nVirBottom
);
724 ImplVDrawLine(rRenderContext
, n1
, nVirTop
, n2
, nVirTop
);
726 rRenderContext
.SetLineColor(rStyleSettings
.GetShadowColor());
727 ImplVDrawLine(rRenderContext
, n1
, nVirTop
, n1
, nVirBottom
);
728 ImplVDrawLine(rRenderContext
, n1
, nVirBottom
, n2
, nVirBottom
);
729 ImplVDrawLine(rRenderContext
, n2
- 1, nVirTop
, n2
- 1, nVirBottom
);
731 rRenderContext
.SetLineColor(rStyleSettings
.GetDarkShadowColor());
732 ImplVDrawLine(rRenderContext
, n2
, nVirTop
, n2
, nVirBottom
);
734 if (mpData
->pBorders
[i
].nStyle
& RULER_BORDER_VARIABLE
)
736 if (n2
- n1
> RULER_VAR_SIZE
+ 4)
738 nTemp1
= n1
+ (((n2
- n1
+ 1) - RULER_VAR_SIZE
) / 2);
739 nTemp2
= nVirTop
+ (((nVirBottom
- nVirTop
+ 1) - RULER_VAR_SIZE
) / 2);
740 long nTemp3
= nTemp1
+ RULER_VAR_SIZE
- 1;
741 long nTemp4
= nTemp2
+ RULER_VAR_SIZE
- 1;
742 long nTempY
= nTemp2
;
744 rRenderContext
.SetLineColor(rStyleSettings
.GetLightColor());
745 while (nTempY
<= nTemp4
)
747 ImplVDrawLine(rRenderContext
, nTemp1
, nTempY
, nTemp3
, nTempY
);
752 rRenderContext
.SetLineColor(rStyleSettings
.GetShadowColor());
753 while (nTempY
<= nTemp4
)
755 ImplVDrawLine(rRenderContext
, nTemp1
, nTempY
, nTemp3
, nTempY
);
761 if (mpData
->pBorders
[i
].nStyle
& RULER_BORDER_SIZEABLE
)
763 if (n2
- n1
> RULER_VAR_SIZE
+ 10)
765 rRenderContext
.SetLineColor(rStyleSettings
.GetShadowColor());
766 ImplVDrawLine(rRenderContext
, n1
+ 4, nVirTop
+ 3, n1
+ 4, nVirBottom
- 3);
767 ImplVDrawLine(rRenderContext
, n2
- 5, nVirTop
+ 3, n2
- 5, nVirBottom
- 3);
768 rRenderContext
.SetLineColor(rStyleSettings
.GetLightColor());
769 ImplVDrawLine(rRenderContext
, n1
+ 5, nVirTop
+ 3, n1
+ 5, nVirBottom
- 3);
770 ImplVDrawLine(rRenderContext
, n2
- 4, nVirTop
+ 3, n2
- 4, nVirBottom
- 3);
776 n
= n1
+ ((n2
- n1
) / 2);
777 rRenderContext
.SetLineColor(rStyleSettings
.GetShadowColor());
779 if (mpData
->pBorders
[i
].nStyle
& RULER_BORDER_SNAP
)
780 ImplVDrawLine(rRenderContext
, n
, nVirTop
, n
, nVirBottom
);
781 else if (mpData
->pBorders
[i
].nStyle
& RULER_BORDER_MARGIN
)
782 ImplVDrawLine(rRenderContext
, n
, nVirTop
, n
, nVirBottom
);
785 ImplVDrawLine(rRenderContext
, n
- 1, nVirTop
, n
- 1, nVirBottom
);
786 ImplVDrawLine(rRenderContext
, n
+ 1, nVirTop
, n
+ 1, nVirBottom
);
787 rRenderContext
.SetLineColor();
788 rRenderContext
.SetFillColor(rStyleSettings
.GetWindowColor());
789 ImplVDrawRect(rRenderContext
, n
, nVirTop
, n
, nVirBottom
);
796 void Ruler::ImplDrawIndent(vcl::RenderContext
& rRenderContext
, const Polygon
& rPoly
, sal_uInt16 nStyle
, bool bIsHit
)
798 const StyleSettings
& rStyleSettings
= rRenderContext
.GetSettings().GetStyleSettings();
800 if (nStyle
& RULER_STYLE_INVISIBLE
)
803 rRenderContext
.SetLineColor(rStyleSettings
.GetDarkShadowColor());
804 rRenderContext
.SetFillColor(bIsHit
? rStyleSettings
.GetDarkShadowColor() : rStyleSettings
.GetWorkspaceColor());
805 rRenderContext
.DrawPolygon(rPoly
);
808 void Ruler::ImplDrawIndents(vcl::RenderContext
& rRenderContext
, long nMin
, long nMax
, long nVirTop
, long nVirBottom
)
812 long nIndentHeight
= (mnVirHeight
/ 2) - 1;
813 long nIndentWidth2
= nIndentHeight
-3;
817 for (j
= 0; j
< mpData
->pIndents
.size(); j
++)
819 if (mpData
->pIndents
[j
].nStyle
& RULER_STYLE_INVISIBLE
)
822 sal_uInt16 nStyle
= mpData
->pIndents
[j
].nStyle
;
823 sal_uInt16 nIndentStyle
= nStyle
& RULER_INDENT_STYLE
;
825 n
= mpData
->pIndents
[j
].nPos
+mpData
->nNullVirOff
;
827 if ((n
>= nMin
) && (n
<= nMax
))
829 if (nIndentStyle
== RULER_INDENT_BORDER
)
831 const StyleSettings
& rStyleSettings
= rRenderContext
.GetSettings().GetStyleSettings();
832 rRenderContext
.SetLineColor(rStyleSettings
.GetShadowColor());
833 ImplVDrawLine(rRenderContext
, n
, nVirTop
+ 1, n
, nVirBottom
- 1);
835 else if (nIndentStyle
== RULER_INDENT_BOTTOM
)
837 aPoly
.SetPoint(Point(n
+ 0, nVirBottom
- nIndentHeight
), 0);
838 aPoly
.SetPoint(Point(n
- nIndentWidth2
, nVirBottom
- 3), 1);
839 aPoly
.SetPoint(Point(n
- nIndentWidth2
, nVirBottom
), 2);
840 aPoly
.SetPoint(Point(n
+ nIndentWidth2
, nVirBottom
), 3);
841 aPoly
.SetPoint(Point(n
+ nIndentWidth2
, nVirBottom
- 3), 4);
845 aPoly
.SetPoint(Point(n
+ 0, nVirTop
+ nIndentHeight
), 0);
846 aPoly
.SetPoint(Point(n
- nIndentWidth2
, nVirTop
+ 3), 1);
847 aPoly
.SetPoint(Point(n
- nIndentWidth2
, nVirTop
), 2);
848 aPoly
.SetPoint(Point(n
+ nIndentWidth2
, nVirTop
), 3);
849 aPoly
.SetPoint(Point(n
+ nIndentWidth2
, nVirTop
+ 3), 4);
852 if (0 == (mnWinStyle
& WB_HORZ
))
855 for (sal_uInt16 i
= 0; i
< 5; i
++)
858 Point
aSet(nVirBottom
- aTmp
.Y(), aTmp
.X());
862 if (RULER_INDENT_BORDER
!= nIndentStyle
)
865 if(mxCurrentHitTest
.get() != NULL
&& mxCurrentHitTest
->eType
== RULER_TYPE_INDENT
)
867 bIsHit
= mxCurrentHitTest
->nAryPos
== j
;
869 else if(mbDrag
&& meDragType
== RULER_TYPE_INDENT
)
871 bIsHit
= mnDragAryPos
== j
;
873 ImplDrawIndent(rRenderContext
, aPoly
, nStyle
, bIsHit
);
879 static void ImplCenterTabPos(Point
& rPos
, sal_uInt16 nTabStyle
)
881 bool bRTL
= 0 != (nTabStyle
& RULER_TAB_RTL
);
882 nTabStyle
&= RULER_TAB_STYLE
;
883 rPos
.Y() += ruler_tab
.height
/2;
885 if ( (!bRTL
&& nTabStyle
== RULER_TAB_LEFT
) ||
886 ( bRTL
&& nTabStyle
== RULER_TAB_RIGHT
) )
888 rPos
.X() -= ruler_tab
.width
/ 2;
890 else if ( (!bRTL
&& nTabStyle
== RULER_TAB_RIGHT
) ||
891 ( bRTL
&& nTabStyle
== RULER_TAB_LEFT
) )
893 rPos
.X() += ruler_tab
.width
/ 2;
897 static void lcl_RotateRect_Impl(Rectangle
& rRect
, const long nReference
, bool bRightAligned
)
899 if (!rRect
.IsEmpty())
901 Rectangle
aTmp(rRect
);
902 rRect
.Top() = aTmp
.Left();
903 rRect
.Bottom() = aTmp
.Right();
904 rRect
.Left() = aTmp
.Top();
905 rRect
.Right() = aTmp
.Bottom();
909 long nRef
= 2 * nReference
;
910 rRect
.Left() = nRef
- rRect
.Left();
911 rRect
.Right() = nRef
- rRect
.Right();
916 static void ImplDrawRulerTab(vcl::RenderContext
& rRenderContext
, const Point
& rPos
,
917 sal_uInt16 nStyle
, WinBits nWinBits
)
919 if (nStyle
& RULER_STYLE_INVISIBLE
)
922 sal_uInt16 nTabStyle
= nStyle
& RULER_TAB_STYLE
;
923 bool bRTL
= 0 != (nStyle
& RULER_TAB_RTL
);
925 // Scale by the screen DPI scaling factor
926 // However when doing this some of the rectangles
927 // drawn become asymmetric due to the +1 offsets
928 sal_uInt16 DPIOffset
= rRenderContext
.GetDPIScaleFactor() - 1;
936 if (nTabStyle
== RULER_TAB_DEFAULT
)
938 aRect1
.Left() = rPos
.X() - ruler_tab
.dwidth2
+ 1;
939 aRect1
.Top() = rPos
.Y() - ruler_tab
.dheight2
+ 1;
940 aRect1
.Right() = rPos
.X() - ruler_tab
.dwidth2
+ ruler_tab
.dwidth
+ DPIOffset
;
941 aRect1
.Bottom() = rPos
.Y();
943 aRect2
.Left() = rPos
.X() - ruler_tab
.dwidth2
+ ruler_tab
.dwidth3
;
944 aRect2
.Top() = rPos
.Y() - ruler_tab
.dheight
+ 1;
945 aRect2
.Right() = rPos
.X() - ruler_tab
.dwidth2
+ ruler_tab
.dwidth3
+ ruler_tab
.dwidth4
- 1;
946 aRect2
.Bottom() = rPos
.Y();
949 else if ((!bRTL
&& nTabStyle
== RULER_TAB_LEFT
) || (bRTL
&& nTabStyle
== RULER_TAB_RIGHT
))
951 aRect1
.Left() = rPos
.X();
952 aRect1
.Top() = rPos
.Y() - ruler_tab
.height2
+ 1;
953 aRect1
.Right() = rPos
.X() + ruler_tab
.width
- 1;
954 aRect1
.Bottom() = rPos
.Y();
956 aRect2
.Left() = rPos
.X();
957 aRect2
.Top() = rPos
.Y() - ruler_tab
.height
+ 1;
958 aRect2
.Right() = rPos
.X() + ruler_tab
.width2
- 1;
959 aRect2
.Bottom() = rPos
.Y();
961 else if ((!bRTL
&& nTabStyle
== RULER_TAB_RIGHT
) || (bRTL
&& nTabStyle
== RULER_TAB_LEFT
))
963 aRect1
.Left() = rPos
.X() - ruler_tab
.width
+ 1;
964 aRect1
.Top() = rPos
.Y() - ruler_tab
.height2
+ 1;
965 aRect1
.Right() = rPos
.X();
966 aRect1
.Bottom() = rPos
.Y();
968 aRect2
.Left() = rPos
.X() - ruler_tab
.width2
+ 1;
969 aRect2
.Top() = rPos
.Y() - ruler_tab
.height
+ 1;
970 aRect2
.Right() = rPos
.X();
971 aRect2
.Bottom() = rPos
.Y();
975 aRect1
.Left() = rPos
.X() - ruler_tab
.cwidth2
+ 1;
976 aRect1
.Top() = rPos
.Y() - ruler_tab
.height2
+ 1;
977 aRect1
.Right() = rPos
.X() - ruler_tab
.cwidth2
+ ruler_tab
.cwidth
+ DPIOffset
;
978 aRect1
.Bottom() = rPos
.Y();
980 aRect2
.Left() = rPos
.X() - ruler_tab
.cwidth2
+ ruler_tab
.cwidth3
;
981 aRect2
.Top() = rPos
.Y() - ruler_tab
.height
+ 1;
982 aRect2
.Right() = rPos
.X() - ruler_tab
.cwidth2
+ ruler_tab
.cwidth3
+ ruler_tab
.cwidth4
- 1;
983 aRect2
.Bottom() = rPos
.Y();
985 if (nTabStyle
== RULER_TAB_DECIMAL
)
987 aRect3
.Left() = rPos
.X() - ruler_tab
.cwidth2
+ ruler_tab
.cwidth
- 1;
988 aRect3
.Top() = rPos
.Y() - ruler_tab
.height
+ 1 + 1 - DPIOffset
;
989 aRect3
.Right() = rPos
.X() - ruler_tab
.cwidth2
+ ruler_tab
.cwidth
+ DPIOffset
;
990 aRect3
.Bottom() = rPos
.Y() - ruler_tab
.height
+ 1 + 2;
993 if (0 == (nWinBits
& WB_HORZ
))
995 bool bRightAligned
= 0 != (nWinBits
& WB_RIGHT_ALIGNED
);
996 lcl_RotateRect_Impl(aRect1
, rPos
.Y(), bRightAligned
);
997 lcl_RotateRect_Impl(aRect2
, rPos
.Y(), bRightAligned
);
998 lcl_RotateRect_Impl(aRect3
, rPos
.Y(), bRightAligned
);
1000 rRenderContext
.DrawRect(aRect1
);
1001 rRenderContext
.DrawRect(aRect2
);
1003 if (!aRect3
.IsEmpty())
1004 rRenderContext
.DrawRect(aRect3
);
1007 void Ruler::ImplDrawTab(vcl::RenderContext
& rRenderContext
, const Point
& rPos
, sal_uInt16 nStyle
)
1009 if (nStyle
& RULER_STYLE_INVISIBLE
)
1012 rRenderContext
.SetLineColor();
1014 if (nStyle
& RULER_STYLE_DONTKNOW
)
1015 rRenderContext
.SetFillColor(rRenderContext
.GetSettings().GetStyleSettings().GetFaceColor());
1017 rRenderContext
.SetFillColor(rRenderContext
.GetSettings().GetStyleSettings().GetDarkShadowColor());
1019 if (mpData
->bTextRTL
)
1020 nStyle
|= RULER_TAB_RTL
;
1022 ImplDrawRulerTab(rRenderContext
, rPos
, nStyle
, GetStyle());
1025 void Ruler::ImplDrawTabs(vcl::RenderContext
& rRenderContext
, long nMin
, long nMax
, long nVirTop
, long nVirBottom
)
1027 for (sal_uInt32 i
= 0; i
< mpData
->pTabs
.size(); i
++)
1029 if (mpData
->pTabs
[i
].nStyle
& RULER_STYLE_INVISIBLE
)
1033 aPosition
= mpData
->pTabs
[i
].nPos
;
1034 aPosition
+= +mpData
->nNullVirOff
;
1035 long nTopBottom
= (GetStyle() & WB_RIGHT_ALIGNED
) ? nVirTop
: nVirBottom
;
1036 if (nMin
<= aPosition
&& aPosition
<= nMax
)
1037 ImplDrawTab(rRenderContext
, Point( aPosition
, nTopBottom
), mpData
->pTabs
[i
].nStyle
);
1041 static int adjustSize(int nOrig
)
1046 // make sure we return an odd number, that looks better in the ruler
1047 return ( (3*nOrig
) / 8) * 2 + 1;
1050 void Ruler::ApplySettings(vcl::RenderContext
& rRenderContext
)
1052 const StyleSettings
& rStyleSettings
= rRenderContext
.GetSettings().GetStyleSettings();
1054 vcl::Font aFont
= rStyleSettings
.GetToolFont();
1055 // make the font a bit smaller than default
1056 Size
aSize(adjustSize(aFont
.GetSize().Width()), adjustSize(aFont
.GetSize().Height()));
1057 aFont
.SetSize(aSize
);
1059 ApplyControlFont(rRenderContext
, aFont
);
1061 ApplyControlForeground(*this, rStyleSettings
.GetDarkShadowColor());
1065 svtools::ColorConfig aColorConfig
;
1066 aColor
= Color(aColorConfig
.GetColorValue(svtools::APPBACKGROUND
).nColor
);
1067 ApplyControlBackground(rRenderContext
, aColor
);
1070 void Ruler::ImplInitSettings(bool bFont
, bool bForeground
, bool bBackground
)
1072 const StyleSettings
& rStyleSettings
= GetSettings().GetStyleSettings();
1076 vcl::Font aFont
= rStyleSettings
.GetToolFont();
1077 // make the font a bit smaller than default
1078 Size
aSize(adjustSize(aFont
.GetSize().Width()), adjustSize(aFont
.GetSize().Height()));
1079 aFont
.SetSize(aSize
);
1081 ApplyControlFont(*this, aFont
);
1084 if (bForeground
|| bFont
)
1086 ApplyControlForeground(*this, rStyleSettings
.GetDarkShadowColor());
1093 svtools::ColorConfig aColorConfig
;
1094 aColor
= Color(aColorConfig
.GetColorValue(svtools::APPBACKGROUND
).nColor
);
1095 ApplyControlBackground(*this, aColor
);
1098 maVirDev
->SetSettings( GetSettings() );
1099 maVirDev
->SetBackground( GetBackground() );
1100 vcl::Font aFont
= GetFont();
1102 if (mnWinStyle
& WB_VERT
)
1103 aFont
.SetOrientation(900);
1105 maVirDev
->SetFont(aFont
);
1106 maVirDev
->SetTextColor(GetTextColor());
1107 maVirDev
->SetTextFillColor(GetTextFillColor());
1110 void Ruler::ImplCalc()
1113 mpData
->nRulVirOff
= mnWinOff
+ mpData
->nPageOff
;
1114 if ( mpData
->nRulVirOff
> mnVirOff
)
1115 mpData
->nRulVirOff
-= mnVirOff
;
1117 mpData
->nRulVirOff
= 0;
1118 long nRulWinOff
= mpData
->nRulVirOff
+mnVirOff
;
1120 // calculate non-visual part of the page
1121 long nNotVisPageWidth
;
1122 if ( mpData
->nPageOff
< 0 )
1124 nNotVisPageWidth
= -(mpData
->nPageOff
);
1125 if ( nRulWinOff
< mnWinOff
)
1126 nNotVisPageWidth
-= mnWinOff
-nRulWinOff
;
1129 nNotVisPageWidth
= 0;
1132 if ( mnWinStyle
& WB_HORZ
)
1134 if ( mbAutoWinWidth
)
1135 mnWinWidth
= mnWidth
- mnVirOff
;
1136 if ( mpData
->bAutoPageWidth
)
1137 mpData
->nPageWidth
= mnWinWidth
;
1138 mpData
->nRulWidth
= std::min( mnWinWidth
, mpData
->nPageWidth
-nNotVisPageWidth
);
1139 if ( nRulWinOff
+mpData
->nRulWidth
> mnWidth
)
1140 mpData
->nRulWidth
= mnWidth
-nRulWinOff
;
1144 if ( mbAutoWinWidth
)
1145 mnWinWidth
= mnHeight
- mnVirOff
;
1146 if ( mpData
->bAutoPageWidth
)
1147 mpData
->nPageWidth
= mnWinWidth
;
1148 mpData
->nRulWidth
= std::min( mnWinWidth
, mpData
->nPageWidth
-nNotVisPageWidth
);
1149 if ( nRulWinOff
+mpData
->nRulWidth
> mnHeight
)
1150 mpData
->nRulWidth
= mnHeight
-nRulWinOff
;
1156 void Ruler::ImplFormat(vcl::RenderContext
& rRenderContext
)
1158 // if already formatted, don't do it again
1162 // don't do anything if the window still has no size
1166 const StyleSettings
& rStyleSettings
= rRenderContext
.GetSettings().GetStyleSettings();
1167 long nP1
; // pixel position of Page1
1168 long nP2
; // pixel position of Page2
1169 long nM1
; // pixel position of Margin1
1170 long nM2
; // pixel position of Margin2
1171 long nVirTop
; // top/left corner
1172 long nVirBottom
; // bottom/right corner
1173 long nVirLeft
; // left/top corner
1174 long nVirRight
; // right/bottom corner
1175 long nNullVirOff
; // for faster calculation
1181 mpData
->nNullVirOff
= mnWinOff
+ mpData
->nPageOff
+ mpData
->nNullOff
- mnVirOff
;
1183 nNullVirOff
= mpData
->nNullVirOff
;
1184 nVirLeft
= mpData
->nRulVirOff
;
1185 nVirRight
= nVirLeft
+ mpData
->nRulWidth
- 1;
1187 nVirBottom
= mnVirHeight
- 1;
1189 if (!IsReallyVisible())
1194 // initialize VirtualDevice
1195 if (mnWinStyle
& WB_HORZ
)
1197 aVirDevSize
.Width() = mnVirWidth
;
1198 aVirDevSize
.Height() = mnVirHeight
;
1202 aVirDevSize
.Height() = mnVirWidth
;
1203 aVirDevSize
.Width() = mnVirHeight
;
1205 if (aVirDevSize
!= maVirDev
->GetOutputSizePixel())
1206 maVirDev
->SetOutputSizePixel(aVirDevSize
, true);
1210 // calculate margins
1211 if (!(mpData
->nMargin1Style
& RULER_STYLE_INVISIBLE
))
1213 nM1
= mpData
->nMargin1
+ nNullVirOff
;
1214 if (mpData
->bAutoPageWidth
)
1221 nP1
= nNullVirOff
- mpData
->nNullOff
;
1228 if (!(mpData
->nMargin2Style
& RULER_STYLE_INVISIBLE
))
1230 nM2
= mpData
->nMargin2
+ nNullVirOff
;
1231 if (mpData
->bAutoPageWidth
)
1234 if (nM2
> nVirRight
)
1238 nP2
= nNullVirOff
- mpData
->nNullOff
+ mpData
->nPageWidth
;
1248 // top/bottom border
1249 maVirDev
->SetLineColor(rStyleSettings
.GetShadowColor());
1250 ImplVDrawLine(*maVirDev
.get(), nVirLeft
, nVirTop
+ 1, nM1
, nVirTop
+ 1); //top left line
1251 ImplVDrawLine(*maVirDev
.get(), nM2
, nVirTop
+ 1, nP2
- 1, nVirTop
+ 1); //top right line
1256 // draw margin1, margin2 and in-between
1257 maVirDev
->SetLineColor();
1258 maVirDev
->SetFillColor(rStyleSettings
.GetDialogColor());
1260 ImplVDrawRect(*maVirDev
.get(), nP1
, nVirTop
+ 1, nM1
, nVirBottom
); //left gray rectangle
1262 ImplVDrawRect(*maVirDev
.get(), nM2
, nVirTop
+ 1, nP2
, nVirBottom
); //right gray rectangle
1265 maVirDev
->SetFillColor(rStyleSettings
.GetWindowColor());
1266 ImplVDrawRect(*maVirDev
.get(), nM1
+ 1, nVirTop
, nM2
- 1, nVirBottom
); //center rectangle
1268 maVirDev
->SetLineColor(rStyleSettings
.GetShadowColor());
1271 ImplVDrawLine(*maVirDev
.get(), nM1
, nVirTop
+ 1, nM1
, nVirBottom
); //right line of the left rectangle
1272 ImplVDrawLine(*maVirDev
.get(), nP1
, nVirBottom
, nM1
, nVirBottom
); //bottom line of the left rectangle
1273 if (nP1
>= nVirLeft
)
1275 ImplVDrawLine(*maVirDev
.get(), nP1
, nVirTop
+ 1, nP1
, nVirBottom
); //left line of the left rectangle
1276 ImplVDrawLine(*maVirDev
.get(), nP1
, nVirBottom
, nP1
+ 1, nVirBottom
); //?
1281 ImplVDrawLine(*maVirDev
.get(), nM2
, nVirBottom
, nP2
- 1, nVirBottom
); //bottom line of the right rectangle
1282 ImplVDrawLine(*maVirDev
.get(), nM2
, nVirTop
+ 1, nM2
, nVirBottom
); //left line of the right rectangle
1283 if (nP2
<= nVirRight
+ 1)
1284 ImplVDrawLine(*maVirDev
.get(), nP2
- 1, nVirTop
+ 1, nP2
- 1, nVirBottom
); //right line of the right rectangle
1287 long nMin
= nVirLeft
;
1291 if (mpData
->bTextRTL
)
1292 nStart
= mpData
->nRightFrameMargin
+ nNullVirOff
;
1294 nStart
= mpData
->nLeftFrameMargin
+ nNullVirOff
;
1299 if (nP2
< nVirRight
)
1303 ImplDrawTicks(*maVirDev
.get(), nMin
, nMax
, nStart
, nVirTop
, nVirBottom
);
1306 if (!mpData
->pBorders
.empty())
1307 ImplDrawBorders(*maVirDev
.get(), nVirLeft
, nP2
, nVirTop
, nVirBottom
);
1310 if (!mpData
->pIndents
.empty())
1311 ImplDrawIndents(*maVirDev
.get(), nVirLeft
, nP2
, nVirTop
- 1, nVirBottom
+ 1);
1314 if (!mpData
->pTabs
.empty())
1315 ImplDrawTabs(*maVirDev
.get(), nVirLeft
, nP2
, nVirTop
-1, nVirBottom
+ 1);
1320 void Ruler::ImplInitExtraField( bool bUpdate
)
1322 Size aWinSize
= GetOutputSizePixel();
1324 // extra field evaluate
1325 if ( mnWinStyle
& WB_EXTRAFIELD
)
1327 maExtraRect
.Left() = RULER_OFF
;
1328 maExtraRect
.Top() = RULER_OFF
;
1329 maExtraRect
.Right() = RULER_OFF
+ mnVirHeight
- 1;
1330 maExtraRect
.Bottom() = RULER_OFF
+ mnVirHeight
- 1;
1331 if(mpData
->bTextRTL
)
1333 if(mnWinStyle
& WB_HORZ
)
1334 maExtraRect
.Move(aWinSize
.Width() - maExtraRect
.GetWidth() - maExtraRect
.Left(), 0);
1336 maExtraRect
.Move(0, aWinSize
.Height() - maExtraRect
.GetHeight() - maExtraRect
.Top());
1340 mnVirOff
= maExtraRect
.Right()+1;
1345 maExtraRect
.SetEmpty();
1349 // mnVirWidth depends on mnVirOff
1350 if ( (mnVirWidth
> RULER_MIN_SIZE
) ||
1351 ((aWinSize
.Width() > RULER_MIN_SIZE
) && (aWinSize
.Height() > RULER_MIN_SIZE
)) )
1353 if ( mnWinStyle
& WB_HORZ
)
1354 mnVirWidth
= aWinSize
.Width()-mnVirOff
;
1356 mnVirWidth
= aWinSize
.Height()-mnVirOff
;
1358 if ( mnVirWidth
< RULER_MIN_SIZE
)
1370 void Ruler::ImplDraw(vcl::RenderContext
& rRenderContext
)
1374 ImplFormat(rRenderContext
);
1377 if (IsReallyVisible())
1379 // output the ruler to the virtual device
1381 Size aVirDevSize
= maVirDev
->GetOutputSizePixel();
1383 if (mnWinStyle
& WB_HORZ
)
1385 aOffPos
.X() = mnVirOff
;
1386 if (mpData
->bTextRTL
)
1387 aVirDevSize
.Width() -= maExtraRect
.GetWidth();
1389 aOffPos
.Y() = RULER_OFF
;
1393 aOffPos
.X() = RULER_OFF
;
1394 aOffPos
.Y() = mnVirOff
;
1396 rRenderContext
.DrawOutDev(aOffPos
, aVirDevSize
, Point(), aVirDevSize
, *maVirDev
.get());
1398 // redraw positionlines
1399 ImplInvertLines(rRenderContext
, true);
1403 void Ruler::ImplDrawExtra(vcl::RenderContext
& rRenderContext
, bool bPaint
)
1405 const StyleSettings
& rStyleSettings
= rRenderContext
.GetSettings().GetStyleSettings();
1406 Rectangle aRect
= maExtraRect
;
1407 bool bEraseRect
= false;
1412 aRect
.Bottom() -= 2;
1414 if (!bPaint
&& !(mnExtraStyle
& RULER_STYLE_HIGHLIGHT
))
1416 rRenderContext
.SetFillColor(rStyleSettings
.GetWorkspaceColor());
1421 if (mnExtraStyle
& RULER_STYLE_HIGHLIGHT
)
1423 rRenderContext
.SetFillColor(rStyleSettings
.GetCheckedColor());
1430 rRenderContext
.SetLineColor();
1431 rRenderContext
.DrawRect(aRect
);
1435 if (meExtraType
== RULER_EXTRA_NULLOFFSET
)
1437 rRenderContext
.SetLineColor(rStyleSettings
.GetButtonTextColor());
1438 rRenderContext
.DrawLine(Point(aRect
.Left() + 1, aRect
.Top() + 4),
1439 Point(aRect
.Right() - 1, aRect
.Top() + 4));
1440 rRenderContext
.DrawLine(Point(aRect
.Left() + 4, aRect
.Top() + 1),
1441 Point(aRect
.Left() + 4, aRect
.Bottom() - 1));
1443 else if (meExtraType
== RULER_EXTRA_TAB
)
1445 sal_uInt16 nTabStyle
= mnExtraStyle
& RULER_TAB_STYLE
;
1446 if (mpData
->bTextRTL
)
1447 nTabStyle
|= RULER_TAB_RTL
;
1448 Point aCenter
= aRect
.Center();
1449 Point
aDraw(aCenter
);
1450 ImplCenterTabPos(aDraw
, nTabStyle
);
1451 WinBits nWinBits
= GetStyle();
1452 if (0 == (nWinBits
& WB_HORZ
))
1454 if ((nWinBits
& WB_RIGHT_ALIGNED
) != 0)
1455 aDraw
.Y() = 2 * aCenter
.Y() - aDraw
.Y();
1457 if (mpData
->bTextRTL
)
1459 long nTemp
= aDraw
.X();
1460 aDraw
.X() = aDraw
.Y();
1464 ImplDrawTab(rRenderContext
, aDraw
, nTabStyle
);
1468 void Ruler::ImplUpdate( bool bMustCalc
)
1470 // clear lines in this place so they aren't considered at recalculation
1472 Invalidate(INVALIDATE_NOERASE
);
1479 // abort if we are dragging as drag-handler will update the ruler after drag is finished
1483 // otherwise trigger update
1484 if (IsReallyVisible() && IsUpdateMode())
1486 Invalidate(INVALIDATE_NOERASE
);
1490 bool Ruler::ImplHitTest( const Point
& rPos
, RulerSelection
* pHitTest
,
1491 bool bRequireStyle
, sal_uInt16 nRequiredStyle
) const
1503 // determine positions
1504 bool bIsHori
= 0 != (mnWinStyle
& WB_HORZ
);
1515 nHitBottom
= mnVirHeight
+ (RULER_OFF
* 2);
1518 pHitTest
->nAryPos
= 0;
1519 pHitTest
->mnDragSize
= 0;
1520 pHitTest
->bSize
= false;
1521 pHitTest
->bSizeBar
= false;
1523 // so that leftover tabs and indents are taken into account
1525 if ( !mpData
->pTabs
.empty() || !mpData
->pIndents
.empty() )
1526 nXExtraOff
= (mnVirHeight
/ 2) - 4;
1533 if ( (nX
< mpData
->nRulVirOff
- nXExtraOff
) ||
1534 (nX
> mpData
->nRulVirOff
+ mpData
->nRulWidth
+ nXExtraOff
) ||
1539 pHitTest
->eType
= RULER_TYPE_OUTSIDE
;
1543 nX
-= mpData
->nNullVirOff
;
1544 pHitTest
->nPos
= nX
;
1545 pHitTest
->eType
= RULER_TYPE_DONTKNOW
;
1547 // first test the tabs
1549 if ( !mpData
->pTabs
.empty() )
1551 aRect
.Bottom() = nHitBottom
;
1552 aRect
.Top() = aRect
.Bottom() - ruler_tab
.height
- RULER_OFF
;
1554 for ( i
= mpData
->pTabs
.size() - 1; i
>= 0; i
-- )
1556 nStyle
= mpData
->pTabs
[i
].nStyle
;
1557 if ( !(nStyle
& RULER_STYLE_INVISIBLE
) )
1559 nStyle
&= RULER_TAB_STYLE
;
1561 // default tabs are only shown (no action)
1562 if ( nStyle
!= RULER_TAB_DEFAULT
)
1564 n1
= mpData
->pTabs
[i
].nPos
;
1566 if ( nStyle
== RULER_TAB_LEFT
)
1569 aRect
.Right() = n1
+ ruler_tab
.width
- 1;
1571 else if ( nStyle
== RULER_TAB_RIGHT
)
1574 aRect
.Left() = n1
- ruler_tab
.width
- 1;
1578 aRect
.Left() = n1
- ruler_tab
.cwidth2
+ 1;
1579 aRect
.Right() = n1
- ruler_tab
.cwidth2
+ ruler_tab
.cwidth
;
1582 if ( aRect
.IsInside( Point( nX
, nY
) ) )
1584 pHitTest
->eType
= RULER_TYPE_TAB
;
1585 pHitTest
->nAryPos
= i
;
1594 if ( !mpData
->pIndents
.empty() )
1596 long nIndentHeight
= (mnVirHeight
/ 2) - 1;
1597 long nIndentWidth2
= nIndentHeight
- 3;
1599 for ( i
= mpData
->pIndents
.size(); i
; i
-- )
1601 nStyle
= mpData
->pIndents
[i
-1].nStyle
;
1602 if ( (! bRequireStyle
|| nStyle
== nRequiredStyle
) &&
1603 !(nStyle
& RULER_STYLE_INVISIBLE
) )
1605 nStyle
&= RULER_INDENT_STYLE
;
1606 n1
= mpData
->pIndents
[i
-1].nPos
;
1608 if ( (nStyle
== RULER_INDENT_BOTTOM
) != !bIsHori
)
1610 aRect
.Left() = n1
-nIndentWidth2
;
1611 aRect
.Right() = n1
+nIndentWidth2
;
1612 aRect
.Top() = nHitBottom
-nIndentHeight
-RULER_OFF
+1;
1613 aRect
.Bottom() = nHitBottom
;
1617 aRect
.Left() = n1
-nIndentWidth2
;
1618 aRect
.Right() = n1
+nIndentWidth2
;
1620 aRect
.Bottom() = nIndentHeight
+RULER_OFF
-1;
1623 if ( aRect
.IsInside( Point( nX
, nY
) ) )
1625 pHitTest
->eType
= RULER_TYPE_INDENT
;
1626 pHitTest
->nAryPos
= i
-1;
1633 // everything left and right is outside and don't take this into account
1634 if ( (nXTemp
< mpData
->nRulVirOff
) || (nXTemp
> mpData
->nRulVirOff
+mpData
->nRulWidth
) )
1637 pHitTest
->eType
= RULER_TYPE_OUTSIDE
;
1642 int nBorderTolerance
= 1;
1643 if(pHitTest
->bExpandTest
)
1648 for ( i
= mpData
->pBorders
.size(); i
; i
-- )
1650 n1
= mpData
->pBorders
[i
-1].nPos
;
1651 long n2
= n1
+ mpData
->pBorders
[i
-1].nWidth
;
1653 // borders have at least 3 pixel padding
1654 if ( !mpData
->pBorders
[i
-1].nWidth
)
1656 n1
-= nBorderTolerance
;
1657 n2
+= nBorderTolerance
;
1661 if ( (nX
>= n1
) && (nX
<= n2
) )
1663 nStyle
= mpData
->pBorders
[i
-1].nStyle
;
1664 if ( !(nStyle
& RULER_STYLE_INVISIBLE
) )
1666 pHitTest
->eType
= RULER_TYPE_BORDER
;
1667 pHitTest
->nAryPos
= i
-1;
1669 if ( !(nStyle
& RULER_BORDER_SIZEABLE
) )
1671 if ( nStyle
& RULER_BORDER_MOVEABLE
)
1673 pHitTest
->bSizeBar
= true;
1674 pHitTest
->mnDragSize
= RULER_DRAGSIZE_MOVE
;
1679 long nMOff
= RULER_MOUSE_BORDERWIDTH
;
1680 while ( nMOff
*2 >= (n2
-n1
-RULER_MOUSE_BORDERMOVE
) )
1691 if ( nX
<= n1
+nMOff
)
1693 pHitTest
->bSize
= true;
1694 pHitTest
->mnDragSize
= RULER_DRAGSIZE_1
;
1696 else if ( nX
>= n2
-nMOff
)
1698 pHitTest
->bSize
= true;
1699 pHitTest
->mnDragSize
= RULER_DRAGSIZE_2
;
1703 if ( nStyle
& RULER_BORDER_MOVEABLE
)
1705 pHitTest
->bSizeBar
= true;
1706 pHitTest
->mnDragSize
= RULER_DRAGSIZE_MOVE
;
1717 int nMarginTolerance
= pHitTest
->bExpandTest
? nBorderTolerance
: RULER_MOUSE_MARGINWIDTH
;
1719 if ( (mpData
->nMargin1Style
& (RULER_MARGIN_SIZEABLE
| RULER_STYLE_INVISIBLE
)) == RULER_MARGIN_SIZEABLE
)
1721 n1
= mpData
->nMargin1
;
1722 if ( (nX
>= n1
- nMarginTolerance
) && (nX
<= n1
+ nMarginTolerance
) )
1724 pHitTest
->eType
= RULER_TYPE_MARGIN1
;
1725 pHitTest
->bSize
= true;
1729 if ( (mpData
->nMargin2Style
& (RULER_MARGIN_SIZEABLE
| RULER_STYLE_INVISIBLE
)) == RULER_MARGIN_SIZEABLE
)
1731 n1
= mpData
->nMargin2
;
1732 if ( (nX
>= n1
- nMarginTolerance
) && (nX
<= n1
+ nMarginTolerance
) )
1734 pHitTest
->eType
= RULER_TYPE_MARGIN2
;
1735 pHitTest
->bSize
= true;
1741 if ( !mpData
->pTabs
.empty() )
1743 aRect
.Top() = RULER_OFF
;
1744 aRect
.Bottom() = nHitBottom
;
1746 for ( i
= mpData
->pTabs
.size() - 1; i
>= 0; i
-- )
1748 nStyle
= mpData
->pTabs
[i
].nStyle
;
1749 if ( !(nStyle
& RULER_STYLE_INVISIBLE
) )
1751 nStyle
&= RULER_TAB_STYLE
;
1753 // default tabs are only shown (no action)
1754 if ( nStyle
!= RULER_TAB_DEFAULT
)
1756 n1
= mpData
->pTabs
[i
].nPos
;
1758 if ( nStyle
== RULER_TAB_LEFT
)
1761 aRect
.Right() = n1
+ ruler_tab
.width
- 1;
1763 else if ( nStyle
== RULER_TAB_RIGHT
)
1766 aRect
.Left() = n1
- ruler_tab
.width
- 1;
1770 aRect
.Left() = n1
- ruler_tab
.cwidth2
+ 1;
1771 aRect
.Right() = n1
- ruler_tab
.cwidth2
+ ruler_tab
.cwidth
;
1777 if ( aRect
.IsInside( Point( nX
, nY
) ) )
1779 pHitTest
->eType
= RULER_TYPE_TAB
;
1780 pHitTest
->nAryPos
= i
;
1791 bool Ruler::ImplDocHitTest( const Point
& rPos
, RulerType eDragType
,
1792 RulerSelection
* pHitTest
) const
1795 bool bRequiredStyle
= false;
1796 sal_uInt16 nRequiredStyle
= 0;
1798 if (eDragType
== RULER_TYPE_INDENT
)
1800 bRequiredStyle
= true;
1801 nRequiredStyle
= RULER_INDENT_BOTTOM
;
1804 if ( mnWinStyle
& WB_HORZ
)
1805 aPos
.X() += mnWinOff
;
1807 aPos
.Y() += mnWinOff
;
1809 if ( (eDragType
== RULER_TYPE_INDENT
) || (eDragType
== RULER_TYPE_DONTKNOW
) )
1811 if ( mnWinStyle
& WB_HORZ
)
1812 aPos
.Y() = RULER_OFF
+ 1;
1814 aPos
.X() = RULER_OFF
+ 1;
1816 if ( ImplHitTest( aPos
, pHitTest
, bRequiredStyle
, nRequiredStyle
) )
1818 if ( (pHitTest
->eType
== eDragType
) || (eDragType
== RULER_TYPE_DONTKNOW
) )
1823 if ( (eDragType
== RULER_TYPE_INDENT
) ||
1824 (eDragType
== RULER_TYPE_TAB
) ||
1825 (eDragType
== RULER_TYPE_DONTKNOW
) )
1827 if ( mnWinStyle
& WB_HORZ
)
1828 aPos
.Y() = mnHeight
- RULER_OFF
- 1;
1830 aPos
.X() = mnWidth
- RULER_OFF
- 1;
1832 if ( ImplHitTest( aPos
, pHitTest
, bRequiredStyle
, nRequiredStyle
) )
1834 if ( (pHitTest
->eType
== eDragType
) || (eDragType
== RULER_TYPE_DONTKNOW
) )
1839 if ( (eDragType
== RULER_TYPE_MARGIN1
) || (eDragType
== RULER_TYPE_MARGIN2
) ||
1840 (eDragType
== RULER_TYPE_BORDER
) || (eDragType
== RULER_TYPE_DONTKNOW
) )
1842 if ( mnWinStyle
& WB_HORZ
)
1843 aPos
.Y() = RULER_OFF
+ (mnVirHeight
/ 2);
1845 aPos
.X() = RULER_OFF
+ (mnVirHeight
/ 2);
1847 if ( ImplHitTest( aPos
, pHitTest
) )
1849 if ( (pHitTest
->eType
== eDragType
) || (eDragType
== RULER_TYPE_DONTKNOW
) )
1854 pHitTest
->eType
= RULER_TYPE_DONTKNOW
;
1859 bool Ruler::ImplStartDrag( RulerSelection
* pHitTest
, sal_uInt16 nModifier
)
1861 // don't trigger drag if a border that was clicked can not be changed
1862 if ( (pHitTest
->eType
== RULER_TYPE_BORDER
) &&
1863 !pHitTest
->bSize
&& !pHitTest
->bSizeBar
)
1867 meDragType
= pHitTest
->eType
;
1868 mnDragPos
= pHitTest
->nPos
;
1869 mnDragAryPos
= pHitTest
->nAryPos
;
1870 mnDragSize
= pHitTest
->mnDragSize
;
1871 mnDragModifier
= nModifier
;
1872 *mpDragData
= *mpSaveData
;
1873 mpData
= mpDragData
;
1878 // if the handler allows dragging, initialize dragging
1880 mnStartDragPos
= mnDragPos
;
1882 Invalidate(INVALIDATE_NOERASE
);
1887 // otherwise reset the data
1888 meDragType
= RULER_TYPE_DONTKNOW
;
1893 mpData
= mpSaveData
;
1899 void Ruler::ImplDrag( const Point
& rPos
)
1905 if ( mnWinStyle
& WB_HORZ
)
1909 nOutHeight
= mnHeight
;
1915 nOutHeight
= mnWidth
;
1918 // calculate and fit X
1920 if ( nX
< mpData
->nRulVirOff
)
1922 nX
= mpData
->nRulVirOff
;
1924 else if ( nX
> mpData
->nRulVirOff
+mpData
->nRulWidth
)
1926 nX
= mpData
->nRulVirOff
+mpData
->nRulWidth
;
1928 nX
-= mpData
->nNullVirOff
;
1930 // if upper or left from ruler, then consider old values
1931 mbDragDelete
= false;
1934 if ( !mbDragCanceled
)
1937 mbDragCanceled
= true;
1938 ImplRulerData aTempData
;
1939 aTempData
= *mpDragData
;
1940 *mpDragData
= *mpSaveData
;
1945 mnDragPos
= mnStartDragPos
;
1949 Invalidate(INVALIDATE_NOERASE
);
1951 // reset the data as before cancel
1952 *mpDragData
= aTempData
;
1957 mbDragCanceled
= false;
1959 // +2, so the tabs are not cleared too quickly
1960 if ( nY
> nOutHeight
+ 2 )
1961 mbDragDelete
= true;
1970 Invalidate(INVALIDATE_NOERASE
);
1974 void Ruler::ImplEndDrag()
1977 if ( mbDragCanceled
)
1978 *mpDragData
= *mpSaveData
;
1980 *mpSaveData
= *mpDragData
;
1982 mpData
= mpSaveData
;
1988 // reset drag values
1989 meDragType
= RULER_TYPE_DONTKNOW
;
1993 mbDragCanceled
= false;
1994 mbDragDelete
= false;
1999 Invalidate(INVALIDATE_NOERASE
);
2002 void Ruler::MouseButtonDown( const MouseEvent
& rMEvt
)
2004 if ( rMEvt
.IsLeft() && !IsTracking() )
2006 Point aMousePos
= rMEvt
.GetPosPixel();
2007 sal_uInt16 nMouseClicks
= rMEvt
.GetClicks();
2008 sal_uInt16 nMouseModifier
= rMEvt
.GetModifier();
2013 Invalidate(INVALIDATE_NOERASE
);
2016 if ( maExtraRect
.IsInside( aMousePos
) )
2018 mnExtraClicks
= nMouseClicks
;
2019 mnExtraModifier
= nMouseModifier
;
2022 mnExtraModifier
= 0;
2026 boost::scoped_ptr
<RulerSelection
> pHitTest(new RulerSelection
);
2027 bool bHitTestResult
= ImplHitTest(aMousePos
, pHitTest
.get());
2029 if ( nMouseClicks
== 1 )
2031 if ( bHitTestResult
)
2033 ImplStartDrag( pHitTest
.get(), nMouseModifier
);
2037 // calculate position inside of ruler area
2038 if ( pHitTest
->eType
== RULER_TYPE_DONTKNOW
)
2040 mnDragPos
= pHitTest
->nPos
;
2044 // call HitTest again as a click, for example, could set a new tab
2045 if ( ImplHitTest(aMousePos
, pHitTest
.get()) )
2046 ImplStartDrag(pHitTest
.get(), nMouseModifier
);
2054 mnDragPos
= pHitTest
->nPos
;
2055 mnDragAryPos
= pHitTest
->nAryPos
;
2057 meDragType
= pHitTest
->eType
;
2061 meDragType
= RULER_TYPE_DONTKNOW
;
2069 void Ruler::MouseMove( const MouseEvent
& rMEvt
)
2071 PointerStyle ePtrStyle
= PointerStyle::Arrow
;
2073 mxPreviousHitTest
.swap(mxCurrentHitTest
);
2075 mxCurrentHitTest
.reset(new RulerSelection
);
2077 maHoverSelection
.eType
= RULER_TYPE_DONTKNOW
;
2079 if (ImplHitTest( rMEvt
.GetPosPixel(), mxCurrentHitTest
.get() ))
2081 maHoverSelection
= *mxCurrentHitTest
.get();
2083 if (mxCurrentHitTest
->bSize
)
2085 if (mnWinStyle
& WB_HORZ
)
2087 if (mxCurrentHitTest
->mnDragSize
== RULER_DRAGSIZE_1
)
2088 ePtrStyle
= PointerStyle::TabSelectW
;
2089 else if (mxCurrentHitTest
->mnDragSize
== RULER_DRAGSIZE_2
)
2090 ePtrStyle
= PointerStyle::TabSelectE
;
2092 ePtrStyle
= PointerStyle::ESize
;
2096 if (mxCurrentHitTest
->mnDragSize
== RULER_DRAGSIZE_1
)
2097 ePtrStyle
= PointerStyle::WindowNSize
;
2098 else if (mxCurrentHitTest
->mnDragSize
== RULER_DRAGSIZE_2
)
2099 ePtrStyle
= PointerStyle::WindowSSize
;
2101 ePtrStyle
= PointerStyle::SSize
;
2104 else if (mxCurrentHitTest
->bSizeBar
)
2106 if (mnWinStyle
& WB_HORZ
)
2107 ePtrStyle
= PointerStyle::HSizeBar
;
2109 ePtrStyle
= PointerStyle::VSizeBar
;
2113 if (mxPreviousHitTest
.get() != NULL
&& mxPreviousHitTest
->eType
!= mxCurrentHitTest
->eType
)
2118 SetPointer( Pointer(ePtrStyle
) );
2122 Invalidate(INVALIDATE_NOERASE
);
2126 void Ruler::Tracking( const TrackingEvent
& rTEvt
)
2128 if ( rTEvt
.IsTrackingEnded() )
2130 // reset the old state at cancel
2131 if ( rTEvt
.IsTrackingCanceled() )
2133 mbDragCanceled
= true;
2140 ImplDrag( rTEvt
.GetMouseEvent().GetPosPixel() );
2143 void Ruler::Paint(vcl::RenderContext
& rRenderContext
, const Rectangle
&)
2145 ImplDraw(rRenderContext
);
2147 // consider extra field
2148 if (mnWinStyle
& WB_EXTRAFIELD
)
2149 ImplDrawExtra(rRenderContext
, true);
2152 void Ruler::Resize()
2154 Size aWinSize
= GetOutputSizePixel();
2157 if ( mnWinStyle
& WB_HORZ
)
2159 if ( aWinSize
.Height() != mnHeight
)
2160 nNewHeight
= aWinSize
.Height();
2166 if ( aWinSize
.Width() != mnWidth
)
2167 nNewHeight
= aWinSize
.Width();
2175 bool bVisible
= IsReallyVisible();
2176 if ( bVisible
&& !mpData
->pLines
.empty() )
2178 mnUpdateFlags
|= RULER_UPDATE_LINES
;
2179 Invalidate(INVALIDATE_NOERASE
);
2182 // recalculate some values if the height/width changes
2183 // extra field should always be updated
2184 ImplInitExtraField( mpData
->bTextRTL
);
2188 mnVirHeight
= nNewHeight
- mnBorderWidth
- ( RULER_OFF
* 2 );
2192 if ( mpData
->bAutoPageWidth
)
2194 else if ( mbAutoWinWidth
)
2198 // clear part of the border
2202 Invalidate(INVALIDATE_NOERASE
);
2203 else if ( mpData
->bAutoPageWidth
)
2205 // only at AutoPageWidth muss we redraw
2208 if ( mnWinStyle
& WB_HORZ
)
2210 if ( mnWidth
< aWinSize
.Width() )
2211 aRect
.Left() = mnWidth
- RULER_RESIZE_OFF
;
2213 aRect
.Left() = aWinSize
.Width() - RULER_RESIZE_OFF
;
2214 aRect
.Right() = aRect
.Left() + RULER_RESIZE_OFF
;
2215 aRect
.Top() = RULER_OFF
;
2216 aRect
.Bottom() = RULER_OFF
+ mnVirHeight
;
2220 if ( mnHeight
< aWinSize
.Height() )
2221 aRect
.Top() = mnHeight
-RULER_RESIZE_OFF
;
2223 aRect
.Top() = aWinSize
.Height()-RULER_RESIZE_OFF
;
2224 aRect
.Bottom() = aRect
.Top() + RULER_RESIZE_OFF
;
2225 aRect
.Left() = RULER_OFF
;
2226 aRect
.Right() = RULER_OFF
+ mnVirHeight
;
2229 Invalidate(aRect
, INVALIDATE_NOERASE
);
2233 mnWidth
= aWinSize
.Width();
2234 mnHeight
= aWinSize
.Height();
2237 void Ruler::StateChanged( StateChangedType nType
)
2239 Window::StateChanged( nType
);
2241 if ( nType
== StateChangedType::InitShow
)
2243 else if ( nType
== StateChangedType::UpdateMode
)
2245 if ( IsReallyVisible() && IsUpdateMode() )
2248 else if ( (nType
== StateChangedType::Zoom
) ||
2249 (nType
== StateChangedType::ControlFont
) )
2251 ImplInitSettings( true, false, false );
2254 else if ( nType
== StateChangedType::ControlForeground
)
2256 ImplInitSettings( false, true, false );
2259 else if ( nType
== StateChangedType::ControlBackground
)
2261 ImplInitSettings( false, false, true );
2266 void Ruler::DataChanged( const DataChangedEvent
& rDCEvt
)
2268 Window::DataChanged( rDCEvt
);
2270 if ( (rDCEvt
.GetType() == DataChangedEventType::FONTS
) ||
2271 (rDCEvt
.GetType() == DataChangedEventType::DISPLAY
) ||
2272 (rDCEvt
.GetType() == DataChangedEventType::FONTSUBSTITUTION
) ||
2273 ((rDCEvt
.GetType() == DataChangedEventType::SETTINGS
) &&
2274 (rDCEvt
.GetFlags() & AllSettingsFlags::STYLE
)) )
2277 ImplInitSettings( true, true, true );
2282 bool Ruler::StartDrag()
2284 if ( maStartDragHdl
.IsSet() )
2285 return maStartDragHdl
.Call( this );
2292 maDragHdl
.Call( this );
2295 void Ruler::EndDrag()
2297 maEndDragHdl
.Call( this );
2302 maClickHdl
.Call( this );
2305 void Ruler::DoubleClick()
2307 maDoubleClickHdl
.Call( this );
2310 void Ruler::ExtraDown()
2312 maExtraDownHdl
.Call( this );
2315 void Ruler::Activate()
2319 // update positionlies - draw is delayed
2320 mnUpdateFlags
|= RULER_UPDATE_LINES
;
2321 Invalidate(INVALIDATE_NOERASE
);
2324 void Ruler::Deactivate()
2326 // clear positionlines
2327 Invalidate(INVALIDATE_NOERASE
);
2332 bool Ruler::StartDocDrag( const MouseEvent
& rMEvt
, RulerType eDragType
)
2336 Point aMousePos
= rMEvt
.GetPosPixel();
2337 sal_uInt16 nMouseClicks
= rMEvt
.GetClicks();
2338 sal_uInt16 nMouseModifier
= rMEvt
.GetModifier();
2339 RulerSelection aHitTest
;
2341 if(eDragType
!= RULER_TYPE_DONTKNOW
)
2342 aHitTest
.bExpandTest
= true;
2347 if (!IsReallyVisible())
2349 // set mpData for ImplDocHitTest()
2353 Invalidate(INVALIDATE_NOERASE
);
2356 if ( nMouseClicks
== 1 )
2358 if ( ImplDocHitTest( aMousePos
, eDragType
, &aHitTest
) )
2362 if ( aHitTest
.bSize
)
2364 if ( mnWinStyle
& WB_HORZ
)
2365 aPtr
= Pointer( PointerStyle::ESize
);
2367 aPtr
= Pointer( PointerStyle::SSize
);
2369 else if ( aHitTest
.bSizeBar
)
2371 if ( mnWinStyle
& WB_HORZ
)
2372 aPtr
= Pointer( PointerStyle::HSizeBar
);
2374 aPtr
= Pointer( PointerStyle::VSizeBar
);
2377 return ImplStartDrag( &aHitTest
, nMouseModifier
);
2380 else if ( nMouseClicks
== 2 )
2382 if ( ImplDocHitTest( aMousePos
, eDragType
, &aHitTest
) )
2384 mnDragPos
= aHitTest
.nPos
;
2385 mnDragAryPos
= aHitTest
.nAryPos
;
2387 eDragType
= aHitTest
.eType
;
2391 eDragType
= RULER_TYPE_DONTKNOW
;
2402 void Ruler::CancelDrag()
2406 ImplDrag( Point( -1, -1 ) );
2411 RulerType
Ruler::GetType( const Point
& rPos
, sal_uInt16
* pAryPos
)
2413 RulerSelection aHitTest
;
2416 if ( IsReallyVisible() && mbFormat
)
2418 Invalidate(INVALIDATE_NOERASE
);
2421 (void)ImplHitTest(rPos
, &aHitTest
);
2425 *pAryPos
= aHitTest
.nAryPos
;
2426 return aHitTest
.eType
;
2429 void Ruler::SetWinPos( long nNewOff
, long nNewWidth
)
2431 // should widths be automatically calculated
2433 mbAutoWinWidth
= true;
2435 mbAutoWinWidth
= false;
2438 mnWinWidth
= nNewWidth
;
2442 void Ruler::SetPagePos( long nNewOff
, long nNewWidth
)
2444 // should we do anything?
2445 if ( (mpData
->nPageOff
== nNewOff
) && (mpData
->nPageWidth
== nNewWidth
) )
2448 // should widths be automatically calculated
2450 mpData
->bAutoPageWidth
= true;
2452 mpData
->bAutoPageWidth
= false;
2454 mpData
->nPageOff
= nNewOff
;
2455 mpData
->nPageWidth
= nNewWidth
;
2459 void Ruler::SetBorderPos( long nOff
)
2461 if ( mnWinStyle
& WB_BORDER
)
2463 if ( mnBorderOff
!= nOff
)
2467 if ( IsReallyVisible() && IsUpdateMode() )
2468 Invalidate(INVALIDATE_NOERASE
);
2473 void Ruler::SetUnit( FieldUnit eNewUnit
)
2475 if ( meUnit
!= eNewUnit
)
2481 mnUnitIndex
= RULER_UNIT_MM
;
2484 mnUnitIndex
= RULER_UNIT_CM
;
2487 mnUnitIndex
= RULER_UNIT_M
;
2490 mnUnitIndex
= RULER_UNIT_KM
;
2493 mnUnitIndex
= RULER_UNIT_INCH
;
2496 mnUnitIndex
= RULER_UNIT_FOOT
;
2499 mnUnitIndex
= RULER_UNIT_MILE
;
2502 mnUnitIndex
= RULER_UNIT_POINT
;
2505 mnUnitIndex
= RULER_UNIT_PICA
;
2508 mnUnitIndex
= RULER_UNIT_CHAR
;
2511 mnUnitIndex
= RULER_UNIT_LINE
;
2514 SAL_WARN( "svtools.control", "Ruler::SetUnit() - Wrong Unit" );
2518 maMapMode
.SetMapUnit( aImplRulerUnitTab
[mnUnitIndex
].eMapUnit
);
2523 void Ruler::SetZoom( const Fraction
& rNewZoom
)
2525 DBG_ASSERT( rNewZoom
.GetNumerator(), "Ruler::SetZoom() with scale 0 is not allowed" );
2527 if ( maZoom
!= rNewZoom
)
2530 maMapMode
.SetScaleX( maZoom
);
2531 maMapMode
.SetScaleY( maZoom
);
2536 void Ruler::SetExtraType( RulerExtra eNewExtraType
, sal_uInt16 nStyle
)
2538 if ( mnWinStyle
& WB_EXTRAFIELD
)
2540 meExtraType
= eNewExtraType
;
2541 mnExtraStyle
= nStyle
;
2542 if (IsReallyVisible() && IsUpdateMode())
2547 void Ruler::SetNullOffset( long nPos
)
2549 if ( mpData
->nNullOff
!= nPos
)
2551 mpData
->nNullOff
= nPos
;
2556 void Ruler::SetLeftFrameMargin( long nPos
)
2558 if ( (mpData
->nLeftFrameMargin
!= nPos
) )
2560 mpData
->nLeftFrameMargin
= nPos
;
2565 void Ruler::SetRightFrameMargin( long nPos
)
2567 if ( (mpData
->nRightFrameMargin
!= nPos
) )
2569 mpData
->nRightFrameMargin
= nPos
;
2574 void Ruler::SetMargin1( long nPos
, sal_uInt16 nMarginStyle
)
2576 if ( (mpData
->nMargin1
!= nPos
) || (mpData
->nMargin1Style
!= nMarginStyle
) )
2578 mpData
->nMargin1
= nPos
;
2579 mpData
->nMargin1Style
= nMarginStyle
;
2584 void Ruler::SetMargin2( long nPos
, sal_uInt16 nMarginStyle
)
2586 DBG_ASSERT( (nPos
>= mpData
->nMargin1
) ||
2587 (mpData
->nMargin1Style
& RULER_STYLE_INVISIBLE
) ||
2588 (mpData
->nMargin2Style
& RULER_STYLE_INVISIBLE
),
2589 "Ruler::SetMargin2() - Margin2 < Margin1" );
2591 if ( (mpData
->nMargin2
!= nPos
) || (mpData
->nMargin2Style
!= nMarginStyle
) )
2593 mpData
->nMargin2
= nPos
;
2594 mpData
->nMargin2Style
= nMarginStyle
;
2599 void Ruler::SetLines( sal_uInt32 aLineArraySize
, const RulerLine
* pLineArray
)
2601 // To determine if what has changed
2602 if ( mpData
->pLines
.size() == aLineArraySize
)
2604 sal_uInt32 i
= aLineArraySize
;
2605 vector
<RulerLine
>::const_iterator aItr1
= mpData
->pLines
.begin();
2606 const RulerLine
* pAry2
= pLineArray
;
2609 if ( (aItr1
->nPos
!= pAry2
->nPos
) ||
2610 (aItr1
->nStyle
!= pAry2
->nStyle
) )
2620 // New values and new share issue
2622 if ( IsReallyVisible() && IsUpdateMode() )
2625 bMustUpdate
= false;
2629 Invalidate(INVALIDATE_NOERASE
);
2632 if ( !aLineArraySize
|| !pLineArray
)
2634 if ( mpData
->pLines
.empty() )
2636 mpData
->pLines
.clear();
2640 if ( mpData
->pLines
.size() != aLineArraySize
)
2642 mpData
->pLines
.resize(aLineArraySize
);
2645 std::copy( pLineArray
,
2646 pLineArray
+ aLineArraySize
,
2647 mpData
->pLines
.begin() );
2650 Invalidate(INVALIDATE_NOERASE
);
2654 void Ruler::SetBorders( sal_uInt32 aBorderArraySize
, const RulerBorder
* pBorderArray
)
2656 if ( !aBorderArraySize
|| !pBorderArray
)
2658 if ( mpData
->pBorders
.empty() )
2660 mpData
->pBorders
.clear();
2664 if ( mpData
->pBorders
.size() != aBorderArraySize
)
2666 mpData
->pBorders
.resize(aBorderArraySize
);
2670 sal_uInt32 i
= aBorderArraySize
;
2671 const RulerBorder
* pAry1
= &mpData
->pBorders
[0];
2672 const RulerBorder
* pAry2
= pBorderArray
;
2675 if ( (pAry1
->nPos
!= pAry2
->nPos
) ||
2676 (pAry1
->nWidth
!= pAry2
->nWidth
) ||
2677 (pAry1
->nStyle
!= pAry2
->nStyle
) )
2686 std::copy( pBorderArray
,
2687 pBorderArray
+ aBorderArraySize
,
2688 mpData
->pBorders
.begin() );
2694 void Ruler::SetIndents( sal_uInt32 aIndentArraySize
, const RulerIndent
* pIndentArray
)
2697 if ( !aIndentArraySize
|| !pIndentArray
)
2699 if ( mpData
->pIndents
.empty() )
2701 mpData
->pIndents
.clear();
2705 if ( mpData
->pIndents
.size() != aIndentArraySize
)
2707 mpData
->pIndents
.resize(aIndentArraySize
);
2711 sal_uInt32 i
= aIndentArraySize
;
2712 const RulerIndent
* pAry1
= &mpData
->pIndents
[0];
2713 const RulerIndent
* pAry2
= pIndentArray
;
2716 if ( (pAry1
->nPos
!= pAry2
->nPos
) ||
2717 (pAry1
->nStyle
!= pAry2
->nStyle
) )
2727 std::copy( pIndentArray
,
2728 pIndentArray
+ aIndentArraySize
,
2729 mpData
->pIndents
.begin() );
2735 void Ruler::SetTabs( sal_uInt32 aTabArraySize
, const RulerTab
* pTabArray
)
2737 if ( aTabArraySize
== 0 || pTabArray
== NULL
)
2739 if ( mpData
->pTabs
.empty() )
2741 mpData
->pTabs
.clear();
2745 if ( mpData
->pTabs
.size() != aTabArraySize
)
2747 mpData
->pTabs
.resize(aTabArraySize
);
2751 sal_uInt32 i
= aTabArraySize
;
2752 vector
<RulerTab
>::iterator aTabIterator
= mpData
->pTabs
.begin();
2753 const RulerTab
* pInputArray
= pTabArray
;
2756 RulerTab
& aCurrent
= *aTabIterator
;
2757 if ( aCurrent
.nPos
!= pInputArray
->nPos
||
2758 aCurrent
.nStyle
!= pInputArray
->nStyle
)
2769 std::copy(pTabArray
, pTabArray
+ aTabArraySize
, mpData
->pTabs
.begin());
2775 void Ruler::SetStyle( WinBits nStyle
)
2777 if ( mnWinStyle
!= nStyle
)
2779 mnWinStyle
= nStyle
;
2780 ImplInitExtraField( true );
2784 void Ruler::DrawTab(vcl::RenderContext
& rRenderContext
, const Color
&rFillColor
, const Point
& rPos
, sal_uInt16 nStyle
)
2787 sal_uInt16 nTabStyle
= nStyle
& (RULER_TAB_STYLE
| RULER_TAB_RTL
);
2789 rRenderContext
.Push(PushFlags::LINECOLOR
| PushFlags::FILLCOLOR
);
2790 rRenderContext
.SetLineColor();
2791 rRenderContext
.SetFillColor(rFillColor
);
2792 ImplCenterTabPos(aPos
, nTabStyle
);
2793 ImplDrawRulerTab(rRenderContext
, aPos
, nTabStyle
, nStyle
);
2794 rRenderContext
.Pop();
2797 void Ruler::SetTextRTL(bool bRTL
)
2799 if(mpData
->bTextRTL
!= (bool) bRTL
)
2801 mpData
->bTextRTL
= bRTL
;
2802 if ( IsReallyVisible() && IsUpdateMode() )
2803 ImplInitExtraField( true );
2808 long Ruler::GetPageOffset() const
2810 return mpData
->nPageOff
;
2813 long Ruler::GetNullOffset() const
2815 return mpData
->nNullOff
;
2818 long Ruler::GetMargin1() const
2820 return mpData
->nMargin1
;
2823 long Ruler::GetMargin2() const
2825 return mpData
->nMargin2
;
2829 bool Ruler::GetTextRTL()
2831 return mpData
->bTextRTL
;
2834 RulerUnitData
Ruler::GetCurrentRulerUnit() const
2836 return aImplRulerUnitTab
[mnUnitIndex
];
2839 void Ruler::DrawTicks()
2842 Invalidate(INVALIDATE_NOERASE
);
2845 uno::Reference
< XAccessible
> Ruler::CreateAccessible()
2847 vcl::Window
* pParent
= GetAccessibleParentWindow();
2848 OSL_ENSURE( pParent
, "-SvxRuler::CreateAccessible(): No Parent!" );
2849 uno::Reference
< XAccessible
> xAccParent
= pParent
->GetAccessible();
2850 if( xAccParent
.is() )
2852 // MT: Fixed compiler issue because the address from a temporary object was used.
2853 // BUT: Should it really be a Pointer, instead of const&???
2855 if ( mnWinStyle
& WB_HORZ
)
2857 aStr
= SvtResId(STR_SVT_ACC_RULER_HORZ_NAME
);
2861 aStr
= SvtResId(STR_SVT_ACC_RULER_VERT_NAME
);
2863 pAccContext
= new SvtRulerAccessible( xAccParent
, *this, aStr
);
2864 pAccContext
->acquire();
2865 this->SetAccessible(pAccContext
);
2869 return uno::Reference
< XAccessible
>();
2872 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */