tdf#154285 Check upper bound of arguments in SbRtl_Minute function
[LibreOffice.git] / include / svtools / ruler.hxx
blob2cabded3b1be79f99955a8dee4b24fe0f97e8057
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 .
20 #pragma once
22 #include <memory>
23 #include <map>
24 #include <vector>
25 #include <svtools/svtdllapi.h>
26 #include <rtl/ref.hxx>
27 #include <tools/fldunit.hxx>
28 #include <tools/link.hxx>
29 #include <tools/fract.hxx>
30 #include <vcl/window.hxx>
31 #include <vcl/glyphitem.hxx>
33 class MouseEvent;
34 class TrackingEvent;
35 class DataChangedEvent;
36 class SvtRulerAccessible;
38 /*************************************************************************
40 Description
41 ============
43 class Ruler
45 This class is used for displaying a ruler, but it can also be used
46 for setting or moving tabs and margins.
48 --------------------------------------------------------------------------
50 WinBits
52 WB_HORZ ruler is displayed horizontally
53 WB_VERT ruler is displayed vertically
54 WB_3DLOOK 3D look
55 WB_BORDER border at the bottom/right margin
56 WB_EXTRAFIELD Field in the upper left corner for
57 displaying and selecting tabs, origin of coordinates, ...
58 WB_RIGHT_ALIGNED Marks the vertical ruler as right aligned
60 --------------------------------------------------------------------------
62 All ruler parameters are set in pixel units. This way double conversions
63 and rounding errors are avoided and the ruler displays the margins
64 at their actual position in the document. Because of this, the application can,
65 for example in tables, do its own roundings and the positions on the ruler will
66 still match those in the document. However, for the ruler to know how the
67 document is displayed on the screen, some additional values have to be configured
69 SetWinPos() sets the offset of the ruler's edit window. In doing so,
70 the width of the window can also be configured. If there is a 0 among the
71 values passed to the function, the position/width is automatically set to
72 the width of the ruler.
74 SetPagePos() sets the offset of the page relative to the edit window and the
75 width of the page. If there is a 0 among the values passed to the function,
76 the position/width is automatically set as if the page filled the whole edit window.
78 SetBorderPos() sets the offset of the border. The position is relative to
79 the upper/left margin of the window. This is needed when there are a horizontal
80 and a vertical ruler visible at the same time. Example:
81 aHRuler.SetBorderPos( aVRuler.GetSizePixel().Width()-1 );
83 SetNullOffset() sets the origin relative to the page.
85 All the other values (margins, indentation, tabs, ...) refer to the origin,
86 which is set with SetNullOffset().
88 The values are computed as described below:
90 - WinPos (if both windows have the same parent)
92 Point aHRulerPos = aHRuler.GetPosPixel();
93 Point aEditWinPos = aEditWin.GetPosPixel();
94 aHRuler.SetWinPos( aEditWinPos().X() - aHRulerPos.X() );
96 - PagePos
98 Point aPagePos = aEditWin.LogicToPixel( aEditWin.GetPagePos() );
99 aHRuler.SetPagePos( aPagePos().X() );
101 - All other values
103 Add the logical values, recompute as position and subtract the
104 previously saved pixel positions (of PagePos and Null Offset).
106 --------------------------------------------------------------------------
108 SetUnit() and SetZoom() configure which unit is used to display
109 the values on the ruler. The following units are accepted:
111 FieldUnit::MM
112 FieldUnit::CM (Default)
113 FieldUnit::M
114 FieldUnit::KM
115 FieldUnit::INCH
116 FieldUnit::FOOT
117 FieldUnit::MILE
118 FieldUnit::POINT
119 FieldUnit::PICA
121 --------------------------------------------------------------------------
123 SetMargin1() sets the upper/left margin and SetMargin2() sets the
124 bottom/right margin. If these methods are called without arguments,
125 no margins are displayed. Otherwise, the following arguments can be passed:
127 long nPos - offset in pixels relative to the origin
128 sal_uInt16 nStyle - bit style:
129 RULER_MARGIN_SIZEABLE
130 margin size can be changed
132 The following bits can be set in addition
133 to these styles:
134 RULER_STYLE_INVISIBLE
137 SetBorders() sets an array of margins. To do this, an array of type RulerBorder
138 has to be passed. In the array, the following values have to be initialized:
140 long nPos - offset in pixels relative to the origin
141 long nWidth - column spacing in pixels (can also be 0, for example,
142 for table columns)
143 sal_uInt16 nStyle - bit style:
144 RulerBorderStyle::Sizeable
145 Column spacing can be changed. This flag should
146 only be set if the size of the spacing is changed,
147 not that of a cell.
148 RulerBorderStyle::Moveable
149 Column spacing/border can be moved. Whenever
150 table borders are to be moved, this flag should
151 be set instead of SIZEABLE (SIZEABLE indicates
152 that the size of a spacing, not that of a single
153 cell can be changed).
154 RulerBorderStyle::Variable
155 Not all of the column spacings are equal
156 RulerBorderStyle::Table
157 Table border. Whenever this style is set, the column
158 width must be 0.
159 RulerBorderStyle::Snap
160 Auxiliary line. Whenever this style is set, the
161 column width must be 0.
162 RulerBorderStyle::Margin
163 Margin. Whenever this style is set, the column
164 width must be 0.
166 The following bits can be set in addition
167 to these styles:
168 RULER_STYLE_INVISIBLE
170 SetIndents() sets an array of indents. This method may only be used for horizontal
171 rulers. A Ruler Indent must be passed as an argument, with the following values
172 initialized:
174 long nPos - offset relative to the origin in pixels
175 sal_uInt16 nStyle - bit style:
176 RulerIndentStyle::Top (indent of the first line)
177 RulerIndentStyle::Bottom (left/right indent)
178 RulerIndentStyle::Border (Vertical line that shows the border distance)
179 The following bits can be set in addition
180 to these styles:
181 RULER_STYLE_DONTKNOW (for old position or for
182 ambiguity)
183 RULER_STYLE_INVISIBLE
185 SetTabs() sets an array of tabs. This method may only be used for horizontal rulers.
186 An array of type RulerTab must be passed as an argument, with the following values
187 initialized:
189 long nPos - offset relative to the origin in pixels
190 sal_uInt16 nStyle - bit style:
191 RULER_TAB_DEFAULT (can't be selected)
192 RULER_TAB_LEFT
193 RULER_TAB_CENTER
194 RULER_TAB_RIGHT
195 RULER_TAB_DECIMAL
196 The following bits can be set in addition
197 to these styles:
198 RULER_STYLE_DONTKNOW (for old position of for
199 ambiguity)
200 RULER_STYLE_INVISIBLE
202 SetLines() displays position lines in the ruler. An array of type RulerLine must be passed, with
203 the following values initialized:
205 long nPos - offset relative to the origin in pixels
206 sal_uInt16 nStyle - bit style (has to be 0 currently)
208 --------------------------------------------------------------------------
210 If the user should also be able to change the margins tabs, borders, ...
211 in the ruler, a bit more effort is necessary. In this case, the StartDrag(),
212 Drag() and EndDrag() methods have to be overridden. For the StartDrag() method
213 it is possible to prevent dragging by returning FALSE. In the drag handler,
214 the drag position must be queried and the values must be moved to the new
215 position. This is done by calling the particular Set methods. While in the
216 drag handler, the values are just cached and only afterward the ruler is redrawn.
217 All the handlers can also be set as links with the particular Set..Hdl() methods.
219 - StartDrag()
220 Is called when dragging is started. If FALSE is returned, the dragging.
221 won't be executed. If TRUE is returned, the dragging will be permitted.
222 If the handler isn't overridden, FALSE will be returned.
224 - EndDrag()
225 Is called at the end of dragging.
227 - Drag()
228 Is called when dragging takes place.
230 - Click()
231 This handler is called when no element has been clicked on.
232 The position can be queried with GetClickPos(). This way it is possible
233 to, for example, ser tabs in the ruler. After calling the click handler,
234 the drag, if any, is immediately triggered. This makes it possible to
235 set a new tab in the click handler and then immediately move it.
237 - DoubleClick()
238 This handler is called when a double-click has been performed outside
239 the special panel. The methods GetClickType(), GetClickAryPos() and
240 GetClickPos() can be used to query what has been clicked on.
241 This way you can, for example, show the tab dialog when a double-click
242 is performed on a tab.
244 In the drag handler it is possible to query what has been dragged and where
245 it has been dragged. There are the following query methods:
247 - GetDragType()
248 Returns what has been dragged.
249 RulerType::Margin1
250 RulerType::Margin2
251 RulerType::Border
252 RulerType::Indent
253 RulerType::Tab
255 - GetDragPos()
256 Returns the pixel position to which the user has moved the mouse
257 relative to the set zero-offset.
259 - GetDragAryPos()
260 Returns the index in the array if a border, an indent or a tab
261 is being dragged. Attention: During a drag process, the array position
262 of the item that has been set before the drag is returned.
263 Therefore, it is for example also possible, to no longer show a tab
264 if the mouse is dragged out of the ruler in bottom/right direction.
266 - GetDragSize()
267 If Borders are dragged, this can be used to query whether the size
268 resp. which side or the position should be changed.
269 RulerDragSize::Move or 0 - Move
270 RulerDragSize::N1 - left/upper border
271 RulerDragSize::N2 - right/bottom border
273 - IsDragDelete()
274 This method can be used to query whether the mouse has been
275 moved out of the window at the bottom/right while dragging.
276 By this, it can for example be determined whether the user
277 wants to delete a tab.
279 - IsDragCanceled()
280 Using this Handler, it can be queried in the EndDrag handler
281 whether the action was canceled by the user releasing the
282 mouse at the top/left of the window or by pressing ESC.
283 In this case, the values are not applied. If during the
284 dragging, the mouse is dragged out of the window at the
285 top/left, the old values are displayed automatically without
286 the Drag handler being called.
287 But if the user has moved the value to the old position, the
288 method returns 'false' nevertheless.
289 If this should be avoided, the application must remember the
290 old value in the StartDrag handler and compare the value in the
291 EndDrag handler.
293 - GetDragModifier()
294 Returns the modifier keys that were pressed when the Drag process
295 was started. See MouseEvent.
297 - GetClickPos()
298 Returns the pixel position at which the user has pressed the mouse
299 with respect to the configured null-offset.
301 - GetClickType()
302 Returns what is applied by double click:
303 RulerType::DontKnow (no element in the ruler area)
304 RulerType::Outside (outside of the ruler area)
305 RulerType::Margin1 (only Margin1 border)
306 RulerType::Margin2 (only Margin2 border)
307 RulerType::Border (Border: GetClickAryPos())
308 RulerType::Indent (indent: GetClickAryPos())
309 RulerType::Tab (Tab: GetClickAryPos())
311 - GetClickAryPos()
312 Returns the index in the array if a Border, an Indent or a Tab
313 is applied via DoubleClick.
315 - GetType()
316 This method can be used to carry out a HitTest,
317 in order to possibly also apply sth to an Item using the right
318 mouse button by catching the MouseButtonDown handler. As
319 parameters, the window position and possibly a pointer to a
320 sal_uInt16 are passed, in order to determine the array position
321 of a Tab, an Indent, or a Border. The following values are
322 returned as type:
323 RulerType::DontKnow (no element in the ruler area)
324 RulerType::Outside (outside of the ruler area)
325 RulerType::Margin1 (only Margin1 border)
326 RulerType::Margin2 (only Margin2 border)
327 RulerType::Border (Border: GetClickAryPos())
328 RulerType::Indent (indent: GetClickAryPos())
329 RulerType::Tab (Tab: GetClickAryPos())
331 If the drag process should be canceled, this can be done using CancelDrag().
332 There are the following methods for controlling the Drag:
334 - IsDrag()
335 Returns 'true' if the ruler is in a drag process.
337 - CancelDrag()
338 Cancels the drag process, if one is being carried out. During this,
339 the old values are restored and the Drag and the EndDrag handlers
340 are called.
342 In order to trigger a Drag from the document, there are the following
343 methods:
345 - StartDocDrag()
346 This method is passed the MouseEvent of the document window
347 and what should be dragged. If RulerType::DontKnow is passed
348 as DragType, the ruler decides what should be dragged. In case
349 of the other types, the Drag is only started if a respective
350 element was found at the given position.
351 This is for example necessary if indents and columns are located
352 at the same X position.
353 The return value indicates whether the Drag has been triggered.
354 If a Drag is triggered, the ruler takes over the normal drag
355 control and behaves as if the ruler had been clicked directly.
356 Thus, the ruler captures the mouse and also takes over control
357 of the Cancel (via keyboard, or if the mouse is moved outside
358 of the ruler above it or left of it). All handlers are called,
359 too (including the StartDrag handler). If a MouseEvent with
360 ClickCount 2 is passed, the DoubleClick handler is also called,
361 respectively.
363 --------------------------------------------------------------------------
365 For the extra field, the content can be determined and there are handlers
366 that can be used to handle specific actions.
368 - ExtraDown()
369 This handler is called when the mouse is pressed in the extra field.
371 - SetExtraType()
372 With this method, it can be defined what should be displayed in
373 the extra field.
374 - ExtraType what should be displayed in the extra field
375 RulerExtra::DontKnow (nothing)
376 RulerExtra::NullOffset (coordinate axes)
377 RulerExtra::Tab (Tab)
378 - sal_uInt16 nStyle bit field as style:
379 RULER_STYLE_HIGHLIGHT (selected)
380 RULER_TAB_... (a Tab style)
382 - GetExtraClick()
383 Returns the number of mouse clicks. By this, it is for example
384 also possible to trigger an action by a DoubleClick in the
385 extra field.
387 - GetExtraModifier()
388 Returns the modifier keys that were pressed when the extra field
389 was clicked. See MouseEvent.
391 --------------------------------------------------------------------------
393 Further helper functions:
395 - static Ruler::DrawTab()
396 With this method, a Tab can be output on an OutputDevice.
397 By this, it is also possible to show the Tabs in dialogs like
398 they are drawn in the ruler.
400 This method outputs the Tab centred at the given position. The size
401 of the tabs can be defined by the defines RULER_TAB_WIDTH and
402 RULER_TAB_HEIGHT.
404 --------------------------------------------------------------------------
406 Tips for the use of the ruler:
408 - For the ruler, neither in the Drag mode nor elsewhere, the setting
409 of the values must be bracketed in SetUpdateMode(). The ruler itself
410 takes care that, if multiple values are set, they are automatically
411 grouped together and output flicker-free.
413 - Initially, the sizes, positions and values should be set first for the
414 ruler, before it is displayed. This is important because otherwise
415 many values are calculated unnecessarily.
417 - When the document window, in which the ruler resides, becomes active
418 resp. unactive, the methods Activate() and Deactivate() should be
419 called by the ruler. That is so because the display is switched according
420 to the settings and the system.
422 - For example, while dragging Tabs and Indents, the old positions should
423 also be shown if possible. For that, while setting the Tabs and Indents,
424 the old positions should be inserted first into the array in addition
425 and be linked with the style RULER_STYLE_DONTKNOW. After that, the
426 remaining values should be set in the array.
428 - In case of multiple selected paragraphs and table cells, the Tabs and
429 Indents should be displayed in grey in front of the first cell resp.
430 the first paragraph. This can also be achieved by the style
431 RULER_STYLE_DONTKNOW.
433 - The measuring arrow should always be shown when the Alt key (WW-Like)
434 is pressed during the drag. Maybe, this setting should be configurable
435 always and possibly the measuring arrows always be shown while
436 dragging. For all settings, the values should always be rounded to the
437 multiple of one value because the screen resolution is very imprecise.
439 - DoubleClicks should be handled in the following way (GetClickType()):
440 - RulerType::DontKnow
441 RulerType::Margin1
442 RulerType::Margin2
443 If the conditions GetClickPos() <= GetMargin1() or
444 GetClickPos() >= GetMargin2() are met or the type is equal to
445 RulerType::Margin1 or RulerType::Margin2, a side dialog should
446 be displayed in which the focus is at the respective border.
447 - RulerType::Border
448 A column or table dialog should be shown in which the focus
449 is at the respective column that can be queried using
450 GetClickAryPos().
451 - RulerType::Indent
452 The dialog, in which the indents can be configured, should be
453 shown. In this, the focus should be on the indent which can
454 be queried using GetClickAryPos().
455 - RulerType::Tab
456 A TabDialog should be displayed in which the Tab, that can be
457 queried using GetClickAryPos(), should be selected.
459 *************************************************************************/
462 constexpr WinBits WB_EXTRAFIELD = 0x00004000;
463 constexpr WinBits WB_RIGHT_ALIGNED = 0x00008000;
464 constexpr auto WB_STDRULER = WB_HORZ;
467 enum class RulerType { DontKnow, Outside,
468 Margin1, Margin2,
469 Border, Indent, Tab };
471 enum class RulerExtra { DontKnow, NullOffset, Tab };
473 constexpr sal_uInt16 RULER_STYLE_HIGHLIGHT = 0x8000;
474 constexpr sal_uInt16 RULER_STYLE_DONTKNOW = 0x4000;
475 constexpr sal_uInt16 RULER_STYLE_INVISIBLE = 0x2000;
477 enum class RulerDragSize {
478 Move,
483 constexpr auto RULER_MOUSE_BORDERMOVE = 5;
484 constexpr auto RULER_MOUSE_BORDERWIDTH = 5;
485 constexpr auto RULER_MOUSE_MARGINWIDTH = 3;
488 enum class RulerMarginStyle {
489 NONE = 0x0000,
490 Sizeable = 0x0001,
491 Invisible = 0x0002
493 namespace o3tl {
494 template<> struct typed_flags<RulerMarginStyle> : is_typed_flags<RulerMarginStyle, 0x0003> {};
498 enum class RulerBorderStyle {
499 Sizeable = 0x0001,
500 Moveable = 0x0002,
501 Variable = 0x0004,
502 Invisible = 0x0008
504 namespace o3tl {
505 template<> struct typed_flags<RulerBorderStyle> : is_typed_flags<RulerBorderStyle, 0x000f> {};
508 struct RulerBorder
510 tools::Long nPos;
511 tools::Long nWidth;
512 RulerBorderStyle nStyle;
513 tools::Long nMinPos; //minimum/maximum position, supported for table borders/rows
514 tools::Long nMaxPos;
517 enum class RulerIndentStyle {
518 Top, Bottom
521 struct RulerIndent
523 tools::Long nPos;
524 RulerIndentStyle nStyle;
525 bool bInvisible;
529 constexpr sal_uInt16 RULER_TAB_LEFT = 0x0000;
530 constexpr sal_uInt16 RULER_TAB_RIGHT = 0x0001;
531 constexpr sal_uInt16 RULER_TAB_CENTER = 0x0002;
532 constexpr sal_uInt16 RULER_TAB_DECIMAL = 0x0003;
533 constexpr sal_uInt16 RULER_TAB_DEFAULT = 0x0004;
534 constexpr sal_uInt16 RULER_TAB_STYLE = 0x000F;
535 constexpr sal_uInt16 RULER_TAB_RTL = 0x0010;
537 struct RulerTab
539 tools::Long nPos;
540 sal_uInt16 nStyle;
544 struct RulerLine
546 tools::Long nPos;
550 struct RulerSelection
552 tools::Long nPos;
553 RulerType eType;
554 sal_uInt16 nAryPos;
555 RulerDragSize mnDragSize;
556 bool bSize;
557 bool bSizeBar;
558 bool bExpandTest;
560 RulerSelection()
561 : nPos(0)
562 , eType(RulerType::DontKnow)
563 , nAryPos(0)
564 , mnDragSize(RulerDragSize::Move)
565 , bSize(false)
566 , bSizeBar(false)
567 , bExpandTest( false )
572 struct RulerUnitData
574 MapUnit eMapUnit; // MAP_UNIT for calculation
575 tools::Long nTickUnit; // Unit divider
576 double nTick1; // Minimal step
577 double nTick2; // Tick quarter unit
578 double nTick3; // Tick half unit
579 double nTick4; // Tick whole unit
580 char aUnitStr[8]; // Unit string
584 // Data for drawing ruler tabstops
585 struct RulerTabData
587 sal_uInt16 DPIScaleFactor;
588 sal_uInt16 width;
589 sal_uInt16 height;
590 sal_uInt16 height2;
591 sal_uInt16 width2;
592 sal_uInt16 cwidth;
593 sal_uInt16 cwidth2;
594 sal_uInt16 cwidth3;
595 sal_uInt16 cwidth4;
596 sal_uInt16 dheight;
597 sal_uInt16 dheight2;
598 sal_uInt16 dwidth;
599 sal_uInt16 dwidth2;
600 sal_uInt16 dwidth3;
601 sal_uInt16 dwidth4;
602 sal_uInt16 textoff;
606 class ImplRulerData;
608 class SVT_DLLPUBLIC Ruler : public vcl::Window
610 private:
611 ScopedVclPtr<VirtualDevice> maVirDev;
612 MapMode maMapMode;
613 tools::Long mnBorderOff;
614 tools::Long mnWinOff;
615 tools::Long mnWinWidth;
616 tools::Long mnWidth;
617 tools::Long mnHeight;
618 tools::Long mnVirOff;
619 tools::Long mnVirWidth;
620 tools::Long mnVirHeight;
621 tools::Long mnBorderWidth;
622 tools::Long mnStartDragPos;
623 tools::Long mnDragPos;
624 std::unique_ptr<ImplRulerData> mpSaveData;
625 ImplRulerData* mpData;
626 std::unique_ptr<ImplRulerData> mpDragData;
627 tools::Rectangle maExtraRect;
628 WinBits mnWinStyle;
629 sal_uInt16 mnUnitIndex;
630 sal_uInt16 mnDragAryPos;
631 RulerDragSize mnDragSize;
632 sal_uInt16 mnDragModifier;
633 sal_uInt16 mnExtraStyle;
634 tools::Long mnCharWidth;
635 tools::Long mnLineHeight;
637 RulerExtra meExtraType;
638 RulerType meDragType;
639 FieldUnit meUnit;
640 Fraction maZoom;
641 bool mbCalc;
642 bool mbFormat;
643 bool mbDrag;
644 bool mbDragDelete;
645 bool mbDragCanceled;
646 bool mbAutoWinWidth;
647 bool mbActive;
648 sal_uInt8 mnUpdateFlags;
650 RulerSelection maHoverSelection;
652 Link<Ruler*,void> maDoubleClickHdl;
654 std::unique_ptr<RulerSelection> mxCurrentHitTest;
655 std::unique_ptr<RulerSelection> mxPreviousHitTest;
657 std::map<OUString, SalLayoutGlyphs> maTextGlyphs;
659 SVT_DLLPRIVATE void ImplVDrawLine(vcl::RenderContext& rRenderContext, tools::Long nX1, tools::Long nY1, tools::Long nX2, tools::Long nY2 );
660 SVT_DLLPRIVATE void ImplVDrawRect(vcl::RenderContext& rRenderContext, tools::Long nX1, tools::Long nY1, tools::Long nX2, tools::Long nY2 );
661 SVT_DLLPRIVATE void ImplVDrawText(vcl::RenderContext& rRenderContext, tools::Long nX, tools::Long nY, const OUString& rText,
662 tools::Long nMin = LONG_MIN, tools::Long nMax = LONG_MAX );
664 SVT_DLLPRIVATE void ImplDrawTicks(vcl::RenderContext& rRenderContext,
665 tools::Long nMin, tools::Long nMax, tools::Long nStart, tools::Long nVirTop, tools::Long nVirBottom);
666 SVT_DLLPRIVATE void ImplDrawBorders(vcl::RenderContext& rRenderContext,
667 tools::Long nMin, tools::Long nMax, tools::Long nVirTop, tools::Long nVirBottom);
668 SVT_DLLPRIVATE static void ImplDrawIndent(vcl::RenderContext& rRenderContext,
669 const tools::Polygon& rPoly, bool bIsHit);
670 SVT_DLLPRIVATE void ImplDrawIndents(vcl::RenderContext& rRenderContext,
671 tools::Long nMin, tools::Long nMax, tools::Long nVirTop, tools::Long nVirBottom);
672 SVT_DLLPRIVATE void ImplDrawTab(vcl::RenderContext& rRenderContext, const Point& rPos, sal_uInt16 nStyle);
673 SVT_DLLPRIVATE void ImplDrawTabs(vcl::RenderContext& rRenderContext,
674 tools::Long nMin, tools::Long nMax, tools::Long nVirTop, tools::Long nVirBottom);
676 using Window::ImplInit;
677 SVT_DLLPRIVATE void ImplInit( WinBits nWinBits );
678 SVT_DLLPRIVATE void ImplInitSettings( bool bFont, bool bForeground, bool bBackground );
679 SVT_DLLPRIVATE void ImplCalc();
680 SVT_DLLPRIVATE void ImplFormat(vcl::RenderContext const & rRenderContext);
681 SVT_DLLPRIVATE void ImplInitExtraField( bool bUpdate );
682 SVT_DLLPRIVATE void ImplInvertLines(vcl::RenderContext& rRenderContext);
683 SVT_DLLPRIVATE void ImplDraw(vcl::RenderContext& rRenderContext);
684 SVT_DLLPRIVATE void ImplDrawExtra(vcl::RenderContext& rRenderContext);
685 SVT_DLLPRIVATE void ImplUpdate( bool bMustCalc = false );
687 virtual void ApplySettings(vcl::RenderContext& rRenderContext) override;
689 SVT_DLLPRIVATE bool ImplDoHitTest( const Point& rPosition,
690 RulerSelection* pHitTest,
691 bool bRequiredStyle = false,
692 RulerIndentStyle nRequiredStyle = RulerIndentStyle::Top,
693 tools::Long nTolerance = 1 ) const;
694 SVT_DLLPRIVATE bool ImplDocHitTest( const Point& rPos,
695 RulerType eDragType,
696 RulerSelection* pHitTest,
697 tools::Long nTolerance = 1 ) const;
698 SVT_DLLPRIVATE bool ImplStartDrag( RulerSelection const * pHitTest, sal_uInt16 nModifier );
699 SVT_DLLPRIVATE void ImplDrag( const Point& rPos );
700 SVT_DLLPRIVATE void ImplEndDrag();
702 Ruler (const Ruler &) = delete;
703 Ruler& operator= (const Ruler &) = delete;
705 protected:
706 tools::Long GetRulerVirHeight() const { return mnVirHeight;}
707 const MapMode& GetCurrentMapMode() const { return maMapMode; }
708 const RulerUnitData& GetCurrentRulerUnit() const;
710 public:
711 Ruler( vcl::Window* pParent, WinBits nWinStyle = WB_STDRULER );
712 virtual ~Ruler() override;
713 virtual void dispose() override;
715 virtual void MouseButtonDown( const MouseEvent& rMEvt ) override;
716 virtual void MouseMove( const MouseEvent& rMEvt ) override;
717 virtual void Tracking( const TrackingEvent& rTEvt ) override;
718 virtual void Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect) override;
719 virtual void Resize() override;
720 virtual void StateChanged( StateChangedType nStateChange ) override;
721 virtual void DataChanged( const DataChangedEvent& rDCEvt ) override;
723 virtual bool StartDrag();
724 virtual void Drag();
725 virtual void EndDrag();
726 virtual void Click();
727 void DoubleClick();
728 virtual void ExtraDown();
730 void Activate() override;
731 void Deactivate() override;
733 void SetWinPos( tools::Long nOff, tools::Long nWidth = 0 );
734 tools::Long GetWinOffset() const { return mnWinOff; }
735 void SetPagePos( tools::Long nOff = 0, tools::Long nWidth = 0 );
736 tools::Long GetPageOffset() const;
737 void SetBorderPos( tools::Long nOff = 0 );
738 tools::Long GetBorderOffset() const { return mnBorderOff; }
739 const tools::Rectangle& GetExtraRect() const { return maExtraRect; }
741 void SetUnit( FieldUnit eNewUnit );
742 FieldUnit GetUnit() const { return meUnit; }
743 void SetZoom( const Fraction& rNewZoom );
745 void SetExtraType( RulerExtra eNewExtraType, sal_uInt16 nStyle = 0 );
747 bool StartDocDrag( const MouseEvent& rMEvt,
748 RulerType eDragType,
749 tools::Long nTolerance = 1 );
750 RulerType GetDragType() const { return meDragType; }
751 tools::Long GetDragPos() const { return mnDragPos; }
752 sal_uInt16 GetDragAryPos() const { return mnDragAryPos; }
753 RulerDragSize GetDragSize() const { return mnDragSize; }
754 bool IsDragDelete() const { return mbDragDelete; }
755 bool IsDragCanceled() const { return mbDragCanceled; }
756 sal_uInt16 GetDragModifier() const { return mnDragModifier; }
757 bool IsDrag() const { return mbDrag; }
758 void CancelDrag();
759 tools::Long GetClickPos() const { return mnDragPos; }
760 RulerType GetClickType() const { return meDragType; }
762 const RulerSelection& GetHoverSelection() const { return maHoverSelection; }
764 RulerType GetRulerType( const Point& rPos, sal_uInt16* pAryPos = nullptr );
766 void SetNullOffset( tools::Long nPos );
767 tools::Long GetNullOffset() const;
768 void SetMargin1() { SetMargin1( 0, RulerMarginStyle::Invisible ); }
769 void SetMargin1( tools::Long nPos, RulerMarginStyle nMarginStyle = RulerMarginStyle::Sizeable );
770 tools::Long GetMargin1() const;
771 void SetMargin2() { SetMargin2( 0, RulerMarginStyle::Invisible ); }
772 void SetMargin2( tools::Long nPos, RulerMarginStyle nMarginStyle = RulerMarginStyle::Sizeable );
773 tools::Long GetMargin2() const;
775 void SetLeftFrameMargin( tools::Long nPos );
776 void SetRightFrameMargin( tools::Long nPos );
777 void SetLines( sal_uInt32 n = 0, const RulerLine* pLineAry = nullptr );
778 void SetBorders( sal_uInt32 n = 0, const RulerBorder* pBrdAry = nullptr );
779 void SetIndents( sal_uInt32 n = 0, const RulerIndent* pIndentAry = nullptr );
781 void SetTabs( sal_uInt32 n = 0, const RulerTab* pTabAry = nullptr );
782 const std::vector<RulerTab>& GetTabs() const;
784 static void DrawTab(vcl::RenderContext& rRenderContext, const Color &rFillColor,
785 const Point& rPos, sal_uInt16 nStyle);
787 void SetStyle( WinBits nStyle );
788 WinBits GetStyle() const { return mnWinStyle; }
790 void SetDoubleClickHdl( const Link<Ruler*,void>& rLink ) { maDoubleClickHdl = rLink; }
792 void SetTextRTL(bool bRTL);
793 void SetCharWidth( tools::Long nWidth ) { mnCharWidth = nWidth ; }
794 void SetLineHeight( tools::Long nHeight ) { mnLineHeight = nHeight ; }
796 void DrawTicks();
798 virtual css::uno::Reference< css::accessibility::XAccessible > CreateAccessible() override;
801 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */