Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #ifndef INCLUDED_SVTOOLS_RULER_HXX
21 : #define INCLUDED_SVTOOLS_RULER_HXX
22 :
23 : #include <svtools/svtdllapi.h>
24 : #include <tools/link.hxx>
25 : #include <tools/fract.hxx>
26 : #include <vcl/window.hxx>
27 : #include <vcl/virdev.hxx>
28 : #include <vcl/field.hxx>
29 :
30 : #include <svtools/accessibleruler.hxx>
31 :
32 : class MouseEvent;
33 : class TrackingEvent;
34 : class DataChangedEvent;
35 :
36 : /*************************************************************************
37 :
38 : Description
39 : ============
40 :
41 : class Ruler
42 :
43 : This class is used for displaying a ruler, but it can also be used
44 : for setting or moving tabs and margins.
45 :
46 : --------------------------------------------------------------------------
47 :
48 : WinBits
49 :
50 : WB_HORZ ruler is displayed horizontally
51 : WB_VERT ruler is displayed vertically
52 : WB_3DLOOK 3D look
53 : WB_BORDER border at the bottom/right margin
54 : WB_EXTRAFIELD Field in the upper left corner for
55 : displaying and selecting tabs, origin of coordinates, ...
56 : WB_RIGHT_ALIGNED Marks the vertical ruler as right aligned
57 :
58 : --------------------------------------------------------------------------
59 :
60 : All ruler parameters are set in pixel units. This way double conversions
61 : and rounding errors are avoided and the ruler displays the margins
62 : at their actual position in the document. Because of this, the application can,
63 : for example in tables, do its own roundings and the positions on the ruler will
64 : still match those in the document. However, for the ruler to know how the
65 : document is displayed on the screen, some additional values have to be configured
66 :
67 : SetWinPos() sets the offset of the ruler's edit window. In doing so,
68 : the width of the window can also be configured. If there is a 0 among the
69 : values passed to the function, the position/width is automatically set to
70 : the width of the ruler.
71 :
72 : SetPagePos() sets the offset of the page relative to the edit window and the
73 : width of the page. If there is a 0 among the values passed to the function,
74 : the position/width is automatically set as if the page filled the whole edit window.
75 :
76 : SetBorderPos() sets the offset of the border. The position is relative to
77 : the upper/left margin of the window. This is needed when there are a horizontal
78 : and a vertical ruler visible at the same time. Example:
79 : aHRuler.SetBorderPos( aVRuler.GetSizePixel().Width()-1 );
80 :
81 : SetNullOffset() sets the origin relative to the page.
82 :
83 : All the other values (margins, indentation, tabs, ...) refer to the origin,
84 : which is set with SetNullOffset().
85 :
86 : The values are computed as described below:
87 :
88 : - WinPos (if both windows have the same parent)
89 :
90 : Point aHRulerPos = aHRuler.GetPosPixel();
91 : Point aEditWinPos = aEditWin.GetPosPixel();
92 : aHRuler.SetWinPos( aEditWinPos().X() - aHRulerPos.X() );
93 :
94 : - PagePos
95 :
96 : Point aPagePos = aEditWin.LogicToPixel( aEditWin.GetPagePos() );
97 : aHRuler.SetPagePos( aPagePos().X() );
98 :
99 : - All other values
100 :
101 : Add the logical values, recompute as position and subtract the
102 : previously saved pixel positions (of PagePos and Null Offset).
103 :
104 : --------------------------------------------------------------------------
105 :
106 : SetUnit() and SetZoom() configure which unit is used to display
107 : the values on the ruler. The following units are accepted:
108 :
109 : FUNIT_MM
110 : FUNIT_CM (Default)
111 : FUNIT_M
112 : FUNIT_KM
113 : FUNIT_INCH
114 : FUNIT_FOOT
115 : FUNIT_MILE
116 : FUNIT_POINT
117 : FUNIT_PICA
118 :
119 : --------------------------------------------------------------------------
120 :
121 : SetMargin1() sets the upper/left margin and SetMargin2() sets the
122 : bottom/right margin. If these methods are called without arguments,
123 : no margins are displayed. Otherwise, the following arguments can be passed:
124 :
125 : long nPos - offset in pixels relative to the origin
126 : sal_uInt16 nStyle - bit style:
127 : RULER_MARGIN_SIZEABLE
128 : margin size can be changed
129 :
130 : The following bits can be set in addition
131 : to these styles:
132 : RULER_STYLE_INVISIBLE
133 :
134 :
135 : SetBorders() sets an array of margins. To do this, an array of type RulerBorder
136 : has to be passed. In the array, the following values have to be initialized:
137 :
138 : long nPos - offset in pixels relative to the origin
139 : long nWidth - column spacing in pixels (can also be 0, for example,
140 : for table columns)
141 : sal_uInt16 nStyle - bit style:
142 : RULER_BORDER_SIZEABLE
143 : Column spacing can be changed. This flag should
144 : only be set if the size of the spacing is changed,
145 : not that of a cell.
146 : RULER_BORDER_MOVEABLE
147 : Column spacing/border can be moved. Whenever
148 : table borders are to be moved, this flag should
149 : be set instead of SIZEABLE (SIZEABLE indicates
150 : that the size of a spacing, not that of a single
151 : cell can be changed).
152 : RULER_BORDER_VARIABLE
153 : Not all of the column spacings are equal
154 : RULER_BORDER_TABLE
155 : Table border. Whenever this style is set, the column
156 : width must be 0.
157 : RULER_BORDER_SNAP
158 : Auxiliary line. Whenever this style is set, the
159 : column width must be 0.
160 : RULER_BORDER_MARGIN
161 : Margin. Whenever this style is set, the column
162 : width must be 0.
163 :
164 : The following bits can be set in addition
165 : to these styles:
166 : RULER_STYLE_INVISIBLE
167 :
168 : SetIndents() sets an array of indents. This method may only be used for horizontal
169 : rulers. A Ruler Indent must be passed as an argument, with the following values
170 : initialized:
171 :
172 : long nPos - offset relative to the origin in pixels
173 : sal_uInt16 nStyle - bit style:
174 : RULER_INDENT_TOP (indent of the first line)
175 : RULER_INDENT_BOTTOM (left/right indent)
176 : RULER_INDENT_BORDER (Vertical line that shows the border distance)
177 : The following bits can be set in addition
178 : to these styles:
179 : RULER_STYLE_DONTKNOW (for old position or for
180 : ambiguity)
181 : RULER_STYLE_INVISIBLE
182 :
183 : SetTabs() sets an array of tabs. This method may only be used for horizontal rulers.
184 : An array of type RulerTab must be passed as an argument, with the following values
185 : initialized:
186 :
187 : long nPos - offset relative to the origin in pixels
188 : sal_uInt16 nStyle - bit style:
189 : RULER_TAB_DEFAULT (can't be selected)
190 : RULER_TAB_LEFT
191 : RULER_TAB_CENTER
192 : RULER_TAB_RIGHT
193 : RULER_TAB_DECIMAL
194 : The following bits can be set in addition
195 : to these styles:
196 : RULER_STYLE_DONTKNOW (for old position of for
197 : ambiguity)
198 : RULER_STYLE_INVISIBLE
199 :
200 : SetLines() displays position lines in the ruler. An array of type RulerLine must be passed, with
201 : the following values initialized:
202 :
203 : long nPos - offset relative to the origin in pixels
204 : sal_uInt16 nStyle - bit style (has to be 0 currently)
205 :
206 : --------------------------------------------------------------------------
207 :
208 : If the user should also be able to change the margins tabs, borders, ...
209 : in the ruler, a bit more effort is necessary. In this case, the StartDrag(),
210 : Drag() and EndDrag() methods have to be overridden. For the StartDrag() method
211 : it is possible to prevent dragging by returning FALSE. In the drag handler,
212 : the drag position must be queried and the values must be moved to the new
213 : position. This is done by calling the particular Set methods. While in the
214 : drag handler, the values are just cached and only afterward the ruler is redrawn.
215 : All the handlers can also be set as links with the particular Set..Hdl() methods.
216 :
217 : - StartDrag()
218 : Is called when dragging is started. If FALSE is returned, the dragging.
219 : won't be executed. If TRUE is returned, the dragging will be permitted.
220 : If the handler isn't overridden, FALSE will be returned.
221 :
222 : - EndDrag()
223 : Is called at the end of dragging.
224 :
225 : - Drag()
226 : Is called when dragging takes place.
227 :
228 : - Click()
229 : This handler is called when no element has been clicked on.
230 : The position can be queried with GetClickPos(). This way it is possible
231 : to, for example, ser tabs in the ruler. After calling the click handler,
232 : the drag, if any, is immediately triggered. This makes it possible to
233 : set a new tab in the click handler and then immediately move it.
234 :
235 : - DoubleClick()
236 : This handler is called when a double-click has been performed outside
237 : the special panel. The methods GetClickType(), GetClickAryPos() and
238 : GetClickPos() can be used to query what has been clicked on.
239 : This way you can, for example, show the tab dialog when a double-click
240 : is performed on a tab.
241 :
242 : In the drag handler it is possible to query what has been dragged and where
243 : it has been dragged. There are the following query methods:
244 :
245 : - GetDragType()
246 : Returns what has been dragged.
247 : RULER_TYPE_MARGIN1
248 : RULER_TYPE_MARGIN2
249 : RULER_TYPE_BORDER
250 : RULER_TYPE_INDENT
251 : RULER_TYPE_TAB
252 :
253 : - GetDragPos()
254 : Returns the pixel position to which the user has moved the mouse
255 : relative to the set zero-offset.
256 :
257 : - GetDragAryPos()
258 : Returns the index in the array if a border, an indent or a tab
259 : is being dragged. Attention: During a drag process, the array position
260 : of the item that has been set before the drag is returned.
261 : Therefore, it is for example also possible, to no longer show a tab
262 : if the mouse is dragged out of the ruler in bottom/right direction.
263 :
264 : - GetDragSize()
265 : If Borders are dragged, this can be used to query whether the size
266 : resp. which side or the position should be changed.
267 : RULER_DRAGSIZE_MOVE oder 0 - Move
268 : RULER_DRAGSIZE_1 - left/upper border
269 : RULER_DRAGSIZE_2 - right/bottom border
270 :
271 : - IsDragDelete()
272 : This method can be used to query whether the mouse has been
273 : moved out of the window at the bottom/right while dragging.
274 : By this, it can for example be determined whether the user
275 : wants to delete a tab.
276 :
277 : - IsDragCanceled()
278 : Using this Handler, it can be queried in the EndDrag handler
279 : whether the action was canceled by the user releasing the
280 : mouse at the top/left of the window or by pressing ESC.
281 : In this case, the values are not applied. If during the
282 : dragging, the mouse is dragged out of the window at the
283 : top/left, the old values are displayed automatically without
284 : the Drag handler being called.
285 : But if the user has moved the value to the old position, the
286 : method returns 'false' nevertheless.
287 : If this should be avoided, the application must remember the
288 : old value in the StartDrag handler and compare the value in the
289 : EndDrag handler.
290 :
291 : - GetDragModifier()
292 : Returns the modifier keys that were pressed when the Drag process
293 : was started. See MouseEvent.
294 :
295 : - GetClickPos()
296 : Returns the pixel position at which the user has pressed the mouse
297 : with respect to the configured null-offset.
298 :
299 : - GetClickType()
300 : Returns what is applied by double click:
301 : RULER_TYPE_DONTKNOW (no element in the ruler area)
302 : RULER_TYPE_OUTSIDE (outside of the ruler area)
303 : RULER_TYPE_MARGIN1 (only Margin1 border)
304 : RULER_TYPE_MARGIN2 (only Margin2 border)
305 : RULER_TYPE_BORDER (Border: GetClickAryPos())
306 : RULER_TYPE_INDENT (indent: GetClickAryPos())
307 : RULER_TYPE_TAB (Tab: GetClickAryPos())
308 :
309 : - GetClickAryPos()
310 : Returns the index in the array if a Border, an Indent or a Tab
311 : is applied via DoubleClick.
312 :
313 : - GetType()
314 : This method can be used to carry out a HitTest,
315 : in order to possibly also apply sth to an Item using the right
316 : mouse button by catching the MouseButtonDown handler. As
317 : parameters, the window position and possibly a pointer to a
318 : sal_uInt16 are passed, in order to determine the array position
319 : of a Tab, an Indent, or a Border. The following values are
320 : returned as type:
321 : RULER_TYPE_DONTKNOW (no element in the ruler area)
322 : RULER_TYPE_OUTSIDE (outside of the ruler area)
323 : RULER_TYPE_MARGIN1 (only Margin1 border)
324 : RULER_TYPE_MARGIN2 (only Margin2 border)
325 : RULER_TYPE_BORDER (Border: GetClickAryPos())
326 : RULER_TYPE_INDENT (indent: GetClickAryPos())
327 : RULER_TYPE_TAB (Tab: GetClickAryPos())
328 :
329 : If the drag process should be canceled, this can be done using CancelDrag().
330 : There are the following methods for controlling the Drag:
331 :
332 : - IsDrag()
333 : Returns 'true' if the ruler is in a drag process.
334 :
335 : - CancelDrag()
336 : Cancels the drag process, if one is being carried out. During this,
337 : the old values are restored and the Drag and the EndDrag handlers
338 : are called.
339 :
340 : In order to trigger a Drag from the document, there are the following
341 : methods:
342 :
343 : - StartDocDrag()
344 : This method is passed the MouseEvent of the document window
345 : and what should be dragged. If RULER_TYPE_DONTKNOW is passed
346 : as DragType, the ruler decides what should be dragged. In case
347 : of the other types, the Drag is only started if a respective
348 : element was found at the given position.
349 : This is for example necessary if indents and columns are located
350 : at the same X position.
351 : The return value indicates whether the Drag has been triggered.
352 : If a Drag is triggered, the ruler takes over the normal drag
353 : control and behaves as if the ruler had been clicked directly.
354 : Thus, the ruler captures the mouse and also takes over control
355 : of the Cancel (via keyboard, or if the mouse is moved outside
356 : of the ruler above it or left of it). All handlers are called,
357 : too (including the StartDrag handler). If a MouseEvent with
358 : ClickCount 2 is passed, the DoubleClick handler is also called,
359 : respectively.
360 :
361 : --------------------------------------------------------------------------
362 :
363 : For the extra field, the content can be determined and there are handlers
364 : that can be used to handle specific actions.
365 :
366 : - ExtraDown()
367 : This handler is called when the mouse is pressed in the extra field.
368 :
369 : - SetExtraType()
370 : With this method, it can be defined what should be displayed in
371 : the extra field.
372 : - ExtraType what should be displayed in the extra field
373 : RULER_EXTRA_DONTKNOW (nothing)
374 : RULER_EXTRA_NULLOFFSET (coordinate axes)
375 : RULER_EXTRA_TAB (Tab)
376 : - sal_uInt16 nStyle bit field as style:
377 : RULER_STYLE_HIGHLIGHT (selected)
378 : RULER_TAB_... (a Tab style)
379 :
380 : - GetExtraClick()
381 : Returns the number of mouse clicks. By this, it is for example
382 : also possible to trigger an action by a DoubleClick in the
383 : extra field.
384 :
385 : - GetExtraModifier()
386 : Returns the modifier keys that were pressed when the extra field
387 : was clicked. See MouseEvent.
388 :
389 : --------------------------------------------------------------------------
390 :
391 : Further helper functions:
392 :
393 : - static Ruler::DrawTab()
394 : With this method, a Tab can be output on an OutputDevice.
395 : By this, it is also possible to show the Tabs in dialogs like
396 : they are drawn in the ruler.
397 :
398 : This method outputs the Tab centred at the given position. The size
399 : of the tabs can be defined by the defines RULER_TAB_WIDTH and
400 : RULER_TAB_HEIGHT.
401 :
402 : --------------------------------------------------------------------------
403 :
404 : Tips for the use of the ruler:
405 :
406 : - For the ruler, neither in the Drag mode nor elsewhere, the setting
407 : of the values must be bracketed in SetUpdateMode(). The ruler itself
408 : takes care that, if multiple values are set, they are automatically
409 : grouped together and output flicker-free.
410 :
411 : - Initially, the sizes, positions and values should be set first for the
412 : ruler, before it is displayed. This is important because otherwise
413 : many values are calculated unnecessarily.
414 :
415 : - When the document window, in which the ruler resides, becomes active
416 : resp. unactive, the methods Activate() and Deactivate() should be
417 : called by the ruler. That is so because the display is switched according
418 : to the settings and the system.
419 :
420 : - For example, while dragging Tabs and Indents, the old positions should
421 : also be shown if possible. For that, while setting the Tabs and Indents,
422 : the old positions should be inserted first into the array in addition
423 : and be linked with the style RULER_STYLE_DONTKNOW. After that, the
424 : remaining values should be set in the array.
425 :
426 : - In case of multiple selected paragraphs and table cells, the Tabs and
427 : Indents should be displayed in grey in front of the first cell resp.
428 : the first paragraph. This can also be achieved by the style
429 : RULER_STYLE_DONTKNOW.
430 :
431 : - The measuring arrow should always be shown when the Alt key (WW-Like)
432 : is pressed during the drag. Maybe, this setting should be configurable
433 : always and possibly the measuring arrows always be shown while
434 : dragging. For all settings, the values should always be rounded to the
435 : multiple of one value because the screen resolution is very unprecise.
436 :
437 : - DoubleClicks should be handled in the following way (GetClickType()):
438 : - RULER_TYPE_DONTKNOW
439 : RULER_TYPE_MARGIN1
440 : RULER_TYPE_MARGIN2
441 : If the conditions GetClickPos() <= GetMargin1() or
442 : GetClickPos() >= GetMargin2() are met or the type is equal to
443 : RULER_TYPE_MARGIN1 or RULER_TYPE_MARGIN2, a side dialog should
444 : be displayed in which the focus is at the respective border.
445 : - RULER_TYPE_BORDER
446 : A column or table dialog should be shown in which the focus
447 : is at the respective column that can be queried using
448 : GetClickAryPos().
449 : - RULER_TYPE_INDENT
450 : The dialog, in which the indents can be configured, should be
451 : shown. In this, the focus should be on the indent which can
452 : be queried using GetClickAryPos().
453 : - RULER_TYPE_TAB
454 : A TabDialog should be displayed in which the Tab, that can be
455 : queried using GetClickAryPos(), should be selected.
456 :
457 : *************************************************************************/
458 :
459 : // - WinBits -
460 :
461 : #define WB_EXTRAFIELD ((WinBits)0x00004000)
462 : #define WB_RIGHT_ALIGNED ((WinBits)0x00008000)
463 : #define WB_STDRULER WB_HORZ
464 :
465 : // - Ruler-Type -
466 :
467 : enum RulerType { RULER_TYPE_DONTKNOW, RULER_TYPE_OUTSIDE,
468 : RULER_TYPE_MARGIN1, RULER_TYPE_MARGIN2,
469 : RULER_TYPE_BORDER, RULER_TYPE_INDENT, RULER_TYPE_TAB };
470 :
471 : enum RulerExtra { RULER_EXTRA_DONTKNOW,
472 : RULER_EXTRA_NULLOFFSET, RULER_EXTRA_TAB };
473 :
474 : #define RULER_STYLE_HIGHLIGHT ((sal_uInt16)0x8000)
475 : #define RULER_STYLE_DONTKNOW ((sal_uInt16)0x4000)
476 : #define RULER_STYLE_INVISIBLE ((sal_uInt16)0x2000)
477 :
478 : #define RULER_DRAGSIZE_MOVE 0
479 : #define RULER_DRAGSIZE_1 1
480 : #define RULER_DRAGSIZE_2 2
481 :
482 : #define RULER_MOUSE_BORDERMOVE 5
483 : #define RULER_MOUSE_BORDERWIDTH 5
484 : #define RULER_MOUSE_MARGINWIDTH 3
485 :
486 : // - RulerMargin -
487 :
488 : #define RULER_MARGIN_SIZEABLE ((sal_uInt16)0x0001)
489 :
490 : // - RulerBorder -
491 :
492 : #define RULER_BORDER_SIZEABLE ((sal_uInt16)0x0001)
493 : #define RULER_BORDER_MOVEABLE ((sal_uInt16)0x0002)
494 : #define RULER_BORDER_VARIABLE ((sal_uInt16)0x0004)
495 : #define RULER_BORDER_TABLE ((sal_uInt16)0x0008)
496 : #define RULER_BORDER_SNAP ((sal_uInt16)0x0010)
497 : #define RULER_BORDER_MARGIN ((sal_uInt16)0x0020)
498 :
499 : struct RulerBorder
500 : {
501 : long nPos;
502 : long nWidth;
503 : sal_uInt16 nStyle;
504 : long nMinPos; //minimum/maximum position, supported for table borders/rows
505 : long nMaxPos;
506 : };
507 :
508 : // - RulerIndent -
509 :
510 : #define RULER_INDENT_TOP ((sal_uInt16)0x0000)
511 : #define RULER_INDENT_BOTTOM ((sal_uInt16)0x0001)
512 : #define RULER_INDENT_BORDER ((sal_uInt16)0x0002)
513 : #define RULER_INDENT_STYLE ((sal_uInt16)0x000F)
514 :
515 : struct RulerIndent
516 : {
517 : long nPos;
518 : sal_uInt16 nStyle;
519 : };
520 :
521 : // - RulerTab -
522 :
523 : #define RULER_TAB_LEFT ((sal_uInt16)0x0000)
524 : #define RULER_TAB_RIGHT ((sal_uInt16)0x0001)
525 : #define RULER_TAB_CENTER ((sal_uInt16)0x0002)
526 : #define RULER_TAB_DECIMAL ((sal_uInt16)0x0003)
527 : #define RULER_TAB_DEFAULT ((sal_uInt16)0x0004)
528 : #define RULER_TAB_STYLE ((sal_uInt16)0x000F)
529 : #define RULER_TAB_RTL ((sal_uInt16)0x0010)
530 :
531 : struct RulerTab
532 : {
533 : long nPos;
534 : sal_uInt16 nStyle;
535 : };
536 :
537 :
538 :
539 : // - RulerLine -
540 :
541 : struct RulerLine
542 : {
543 : long nPos;
544 : sal_uInt16 nStyle;
545 : };
546 :
547 : struct RulerSelection
548 : {
549 : long nPos;
550 : RulerType eType;
551 : sal_uInt16 nAryPos;
552 : sal_uInt16 mnDragSize;
553 : bool bSize;
554 : bool bSizeBar;
555 : bool bExpandTest;
556 :
557 5694 : RulerSelection()
558 : : nPos(0)
559 : , eType(RULER_TYPE_DONTKNOW)
560 : , nAryPos(0)
561 : , mnDragSize(0)
562 : , bSize(false)
563 : , bSizeBar(false)
564 5694 : , bExpandTest( false )
565 5694 : {}
566 : };
567 :
568 : struct RulerUnitData
569 : {
570 : MapUnit eMapUnit; // MAP_UNIT for calculaion
571 : long nTickUnit; // Unit divider
572 : double nTick1; // Minimal step
573 : double nTick2; // Tick quarter unit
574 : double nTick3; // Tick half unit
575 : double nTick4; // Tick whole unit
576 : long n100THMM; // 100mm Unit divider
577 : sal_uInt16 nUnitDigits; // Number of digits
578 : sal_Char aUnitStr[8]; // Unit string
579 : };
580 :
581 : // Data for drawing ruler tabstops
582 : struct RulerTabData
583 : {
584 : sal_uInt16 DPIScaleFactor;
585 : sal_uInt16 width;
586 : sal_uInt16 height;
587 : sal_uInt16 height2;
588 : sal_uInt16 width2;
589 : sal_uInt16 cwidth;
590 : sal_uInt16 cwidth2;
591 : sal_uInt16 cwidth3;
592 : sal_uInt16 cwidth4;
593 : sal_uInt16 dheight;
594 : sal_uInt16 dheight2;
595 : sal_uInt16 dwidth;
596 : sal_uInt16 dwidth2;
597 : sal_uInt16 dwidth3;
598 : sal_uInt16 dwidth4;
599 : sal_uInt16 textoff;
600 : };
601 :
602 : // - Ruler -
603 :
604 : class ImplRulerData;
605 :
606 : class SVT_DLLPUBLIC Ruler : public vcl::Window
607 : {
608 : private:
609 : ScopedVclPtr<VirtualDevice> maVirDev;
610 : MapMode maMapMode;
611 : long mnBorderOff;
612 : long mnWinOff;
613 : long mnWinWidth;
614 : long mnWidth;
615 : long mnHeight;
616 : long mnVirOff;
617 : long mnVirWidth;
618 : long mnVirHeight;
619 : long mnBorderWidth;
620 : long mnStartDragPos;
621 : long mnDragPos;
622 : ImplSVEvent * mnUpdateEvtId;
623 : ImplRulerData* mpSaveData;
624 : ImplRulerData* mpData;
625 : ImplRulerData* mpDragData;
626 : Rectangle maExtraRect;
627 : WinBits mnWinStyle;
628 : sal_uInt16 mnUnitIndex;
629 : sal_uInt16 mnDragAryPos;
630 : sal_uInt16 mnDragSize;
631 : sal_uInt16 mnDragModifier;
632 : sal_uInt16 mnExtraStyle;
633 : sal_uInt16 mnExtraClicks;
634 : sal_uInt16 mnExtraModifier;
635 : long mnCharWidth;
636 : long mnLineHeight;
637 :
638 : RulerExtra meExtraType;
639 : RulerType meDragType;
640 : MapUnit meSourceUnit;
641 : FieldUnit meUnit;
642 : Fraction maZoom;
643 : bool mbCalc;
644 : bool mbFormat;
645 : bool mbDrag;
646 : bool mbDragDelete;
647 : bool mbDragCanceled;
648 : bool mbAutoWinWidth;
649 : bool mbActive;
650 : sal_uInt8 mnUpdateFlags;
651 :
652 : RulerSelection maHoverSelection;
653 :
654 : Link<> maStartDragHdl;
655 : Link<> maDragHdl;
656 : Link<> maEndDragHdl;
657 : Link<> maClickHdl;
658 : Link<> maDoubleClickHdl;
659 : Link<> maExtraDownHdl;
660 :
661 : std::unique_ptr<RulerSelection> mxCurrentHitTest;
662 : std::unique_ptr<RulerSelection> mxPreviousHitTest;
663 :
664 : SvtRulerAccessible* pAccContext;
665 :
666 : SVT_DLLPRIVATE void ImplVDrawLine(vcl::RenderContext& rRenderContext, long nX1, long nY1, long nX2, long nY2 );
667 : SVT_DLLPRIVATE void ImplVDrawRect(vcl::RenderContext& rRenderContext, long nX1, long nY1, long nX2, long nY2 );
668 : SVT_DLLPRIVATE void ImplVDrawText(vcl::RenderContext& rRenderContext, long nX, long nY, const OUString& rText,
669 : long nMin = LONG_MIN, long nMax = LONG_MAX );
670 :
671 : SVT_DLLPRIVATE void ImplDrawTicks(vcl::RenderContext& rRenderContext,
672 : long nMin, long nMax, long nStart, long nVirTop, long nVirBottom);
673 : SVT_DLLPRIVATE void ImplDrawBorders(vcl::RenderContext& rRenderContext,
674 : long nMin, long nMax, long nVirTop, long nVirBottom);
675 : SVT_DLLPRIVATE void ImplDrawIndent(vcl::RenderContext& rRenderContext,
676 : const Polygon& rPoly, sal_uInt16 nStyle, bool bIsHit = false);
677 : SVT_DLLPRIVATE void ImplDrawIndents(vcl::RenderContext& rRenderContext,
678 : long nMin, long nMax, long nVirTop, long nVirBottom);
679 : SVT_DLLPRIVATE void ImplDrawTab(vcl::RenderContext& rRenderContext, const Point& rPos, sal_uInt16 nStyle);
680 : SVT_DLLPRIVATE void ImplDrawTabs(vcl::RenderContext& rRenderContext,
681 : long nMin, long nMax, long nVirTop, long nVirBottom);
682 :
683 : using Window::ImplInit;
684 : SVT_DLLPRIVATE void ImplInit( WinBits nWinBits );
685 : SVT_DLLPRIVATE void ImplInitSettings( bool bFont, bool bForeground, bool bBackground );
686 : SVT_DLLPRIVATE void ImplCalc();
687 : SVT_DLLPRIVATE void ImplFormat(vcl::RenderContext& rRenderContext);
688 : SVT_DLLPRIVATE void ImplInitExtraField( bool bUpdate );
689 : SVT_DLLPRIVATE void ImplInvertLines(vcl::RenderContext& rRenderContext, bool bErase = false);
690 : SVT_DLLPRIVATE void ImplDraw(vcl::RenderContext& rRenderContext);
691 : SVT_DLLPRIVATE void ImplDrawExtra(vcl::RenderContext& rRenderContext, bool bPaint = false);
692 : SVT_DLLPRIVATE void ImplUpdate( bool bMustCalc = false );
693 :
694 : virtual void ApplySettings(vcl::RenderContext& rRenderContext) SAL_OVERRIDE;
695 :
696 : using Window::ImplHitTest;
697 : SVT_DLLPRIVATE bool ImplHitTest( const Point& rPosition,
698 : RulerSelection* pHitTest,
699 : bool bRequiredStyle = false,
700 : sal_uInt16 nRequiredStyle = 0 ) const;
701 : SVT_DLLPRIVATE bool ImplDocHitTest( const Point& rPos, RulerType eDragType, RulerSelection* pHitTest ) const;
702 : SVT_DLLPRIVATE bool ImplStartDrag( RulerSelection* pHitTest, sal_uInt16 nModifier );
703 : SVT_DLLPRIVATE void ImplDrag( const Point& rPos );
704 : SVT_DLLPRIVATE void ImplEndDrag();
705 :
706 : Ruler (const Ruler &) SAL_DELETED_FUNCTION;
707 : Ruler& operator= (const Ruler &) SAL_DELETED_FUNCTION;
708 :
709 : protected:
710 55915 : long GetRulerVirHeight() const { return mnVirHeight;}
711 0 : MapMode GetCurrentMapMode() const { return maMapMode; }
712 : RulerUnitData GetCurrentRulerUnit() const;
713 :
714 : public:
715 : Ruler( vcl::Window* pParent, WinBits nWinStyle = WB_STDRULER );
716 : virtual ~Ruler();
717 : virtual void dispose() SAL_OVERRIDE;
718 :
719 : virtual void MouseButtonDown( const MouseEvent& rMEvt ) SAL_OVERRIDE;
720 : virtual void MouseMove( const MouseEvent& rMEvt ) SAL_OVERRIDE;
721 : virtual void Tracking( const TrackingEvent& rTEvt ) SAL_OVERRIDE;
722 : virtual void Paint(vcl::RenderContext& rRenderContext, const Rectangle& rRect) SAL_OVERRIDE;
723 : virtual void Resize() SAL_OVERRIDE;
724 : virtual void StateChanged( StateChangedType nStateChange ) SAL_OVERRIDE;
725 : virtual void DataChanged( const DataChangedEvent& rDCEvt ) SAL_OVERRIDE;
726 :
727 : virtual bool StartDrag();
728 : virtual void Drag();
729 : virtual void EndDrag();
730 : virtual void Click();
731 : void DoubleClick();
732 : virtual void ExtraDown();
733 :
734 : void Activate() SAL_OVERRIDE;
735 : void Deactivate() SAL_OVERRIDE;
736 : bool IsActive() const { return mbActive; }
737 :
738 : void SetWinPos( long nOff = 0, long nWidth = 0 );
739 55915 : long GetWinOffset() const { return mnWinOff; }
740 : long GetWinWidth() const { return mnWinWidth; }
741 : void SetPagePos( long nOff = 0, long nWidth = 0 );
742 : long GetPageOffset() const;
743 : void SetBorderPos( long nOff = 0 );
744 0 : long GetBorderOffset() const { return mnBorderOff; }
745 0 : Rectangle GetExtraRect() const { return maExtraRect; }
746 :
747 : void SetUnit( FieldUnit eNewUnit );
748 4 : FieldUnit GetUnit() const { return meUnit; }
749 : void SetZoom( const Fraction& rNewZoom );
750 : Fraction GetZoom() const { return maZoom; }
751 :
752 172 : void SetSourceUnit( MapUnit eNewUnit ) { meSourceUnit = eNewUnit; }
753 : MapUnit GetSourceUnit() const { return meSourceUnit; }
754 :
755 : void SetExtraType( RulerExtra eNewExtraType, sal_uInt16 nStyle = 0 );
756 : RulerExtra GetExtraType() const { return meExtraType; }
757 : sal_uInt16 GetExtraStyle() const { return mnExtraStyle; }
758 : sal_uInt16 GetExtraClicks() const { return mnExtraClicks; }
759 : sal_uInt16 GetExtraModifier() const { return mnExtraModifier; }
760 :
761 : bool StartDocDrag( const MouseEvent& rMEvt,
762 : RulerType eDragType = RULER_TYPE_DONTKNOW );
763 0 : RulerType GetDragType() const { return meDragType; }
764 0 : long GetDragPos() const { return mnDragPos; }
765 0 : sal_uInt16 GetDragAryPos() const { return mnDragAryPos; }
766 0 : sal_uInt16 GetDragSize() const { return mnDragSize; }
767 0 : bool IsDragDelete() const { return mbDragDelete; }
768 0 : bool IsDragCanceled() const { return mbDragCanceled; }
769 0 : sal_uInt16 GetDragModifier() const { return mnDragModifier; }
770 114375 : bool IsDrag() const { return mbDrag; }
771 : void CancelDrag();
772 0 : long GetClickPos() const { return mnDragPos; }
773 0 : RulerType GetClickType() const { return meDragType; }
774 : sal_uInt16 GetClickAryPos() const { return mnDragAryPos; }
775 :
776 0 : RulerSelection GetHoverSelection() const { return maHoverSelection; }
777 :
778 : using Window::GetType;
779 : RulerType GetType( const Point& rPos, sal_uInt16* pAryPos = NULL );
780 :
781 : void SetNullOffset( long nPos );
782 : long GetNullOffset() const;
783 56383 : void SetMargin1() { SetMargin1( 0, RULER_STYLE_INVISIBLE ); }
784 : void SetMargin1( long nPos, sal_uInt16 nMarginStyle = RULER_MARGIN_SIZEABLE );
785 : long GetMargin1() const;
786 56383 : void SetMargin2() { SetMargin2( 0, RULER_STYLE_INVISIBLE ); }
787 : void SetMargin2( long nPos, sal_uInt16 nMarginStyle = RULER_MARGIN_SIZEABLE );
788 : long GetMargin2() const;
789 :
790 : void SetLeftFrameMargin( long nPos );
791 : void SetRightFrameMargin( long nPos );
792 : void SetLines( sal_uInt32 n = 0, const RulerLine* pLineAry = NULL );
793 : void SetBorders( sal_uInt32 n = 0, const RulerBorder* pBrdAry = NULL );
794 : void SetIndents( sal_uInt32 n = 0, const RulerIndent* pIndentAry = NULL );
795 :
796 : void SetTabs( sal_uInt32 n = 0, const RulerTab* pTabAry = NULL );
797 : sal_uInt32 GetTabCount() const;
798 : const RulerTab* GetTabs() const;
799 :
800 : static void DrawTab(vcl::RenderContext& rRenderContext, const Color &rFillColor,
801 : const Point& rPos, sal_uInt16 nStyle);
802 :
803 : void SetStyle( WinBits nStyle );
804 47504 : WinBits GetStyle() const { return mnWinStyle; }
805 :
806 : void SetStartDragHdl( const Link<>& rLink ) { maStartDragHdl = rLink; }
807 0 : const Link<>& GetStartDragHdl() const { return maStartDragHdl; }
808 : void SetDragHdl( const Link<>& rLink ) { maDragHdl = rLink; }
809 : const Link<>& GetDragHdl() const { return maDragHdl; }
810 : void SetEndDragHdl( const Link<>& rLink ) { maEndDragHdl = rLink; }
811 : const Link<>& GetEndDragHdl() const { return maEndDragHdl; }
812 : void SetClickHdl( const Link<>& rLink ) { maClickHdl = rLink; }
813 : const Link<>& GetClickHdl() const { return maClickHdl; }
814 2761 : void SetDoubleClickHdl( const Link<>& rLink ) { maDoubleClickHdl = rLink; }
815 : const Link<>& GetDoubleClickHdl() const { return maDoubleClickHdl; }
816 : void SetExtraDownHdl( const Link<>& rLink ) { maExtraDownHdl = rLink; }
817 : const Link<>& GetExtraDownHdl() const { return maExtraDownHdl; }
818 :
819 : void SetTextRTL(bool bRTL);
820 : bool GetTextRTL();
821 2761 : void SetCharWidth( long nWidth ) { mnCharWidth = nWidth ; }
822 2761 : void SetLineHeight( long nHeight ) { mnLineHeight = nHeight ; }
823 :
824 : void DrawTicks();
825 :
826 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > CreateAccessible() SAL_OVERRIDE;
827 : };
828 :
829 : #endif // INCLUDED_SVTOOLS_RULER_HXX
830 :
831 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|