Impress: Implement getPartName.
[LibreOffice.git] / include / svtools / ruler.hxx
blob67eb55d8403542c4f12c9c6971b596f63094251e
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 #ifndef INCLUDED_SVTOOLS_RULER_HXX
21 #define INCLUDED_SVTOOLS_RULER_HXX
23 #include <svtools/svtdllapi.h>
24 #include <tools/link.hxx>
25 #include <vcl/window.hxx>
26 #include <vcl/virdev.hxx>
27 #include <vcl/field.hxx>
29 #include <boost/scoped_ptr.hpp>
31 #include <svtools/accessibleruler.hxx>
33 class MouseEvent;
34 class TrackingEvent;
35 class DataChangedEvent;
37 /*************************************************************************
39 Description
40 ============
42 class Ruler
44 This class is used for displaying a ruler, but it can also be used
45 for setting or moving tabs and margins.
47 --------------------------------------------------------------------------
49 WinBits
51 WB_HORZ ruler is displayed horizontally
52 WB_VERT ruler is displayed vertically
53 WB_3DLOOK 3D look
54 WB_BORDER border at the bottom/right margin
55 WB_EXTRAFIELD Field in the upper left corner for
56 displaying and selecting tabs, origin of coordinates, ...
57 WB_RIGHT_ALIGNED Marks the vertical ruler as right aligned
59 --------------------------------------------------------------------------
61 All ruler parameters are set in pixel units. This way double conversions
62 and rounding errors are avoided and the ruler displays the margins
63 at their actual position in the document. Because of this, the application can,
64 for example in tables, do its own roundings and the positions on the ruler will
65 still match those in the document. However, for the ruler to know how the
66 document is displayed on the screen, some additional values have to be configured
68 SetWinPos() sets the offset of the ruler's edit window. In doing so,
69 the width of the window can also be configured. If there is a 0 among the
70 values passed to the function, the position/width is automatically set to
71 the width of the ruler.
73 SetPagePos() sets the offset of the page relative to the edit window and the
74 width of the page. If there is a 0 among the values passed to the function,
75 the position/width is automatically set as if the page filled the whole edit window.
77 SetBorderPos() sets the offset of the border. The position is relative to
78 the upper/left margin of the window. This is needed when there are a horizontal
79 and a vertical ruler visible at the same time. Example:
80 aHRuler.SetBorderPos( aVRuler.GetSizePixel().Width()-1 );
82 SetNullOffset() sets the origin relative to the page.
84 All the other values (margins, indentation, tabs, ...) refer to the origin,
85 which is set with SetNullOffset().
87 The values are computed as described below:
89 - WinPos (if both windows have the same parent)
91 Point aHRulerPos = aHRuler.GetPosPixel();
92 Point aEditWinPos = aEditWin.GetPosPixel();
93 aHRuler.SetWinPos( aEditWinPos().X() - aHRulerPos.X() );
95 - PagePos
97 Point aPagePos = aEditWin.LogicToPixel( aEditWin.GetPagePos() );
98 aHRuler.SetPagePos( aPagePos().X() );
100 - All other values
102 Add the logical values, recompute as position and subtract the
103 previously saved pixel positions (of PagePos and Null Offset).
105 --------------------------------------------------------------------------
107 SetUnit() and SetZoom() configure which unit is used to display
108 the values on the ruler. The following units are accepted:
110 FUNIT_MM
111 FUNIT_CM (Default)
112 FUNIT_M
113 FUNIT_KM
114 FUNIT_INCH
115 FUNIT_FOOT
116 FUNIT_MILE
117 FUNIT_POINT
118 FUNIT_PICA
120 --------------------------------------------------------------------------
122 SetMargin1() sets the upper/left margin and SetMargin2() sets the
123 bottom/right margin. If these methods are called without arguments,
124 no margins are displayed. Otherwise, the following arguments can be passed:
126 long nPos - offset in pixels relative to the origin
127 sal_uInt16 nStyle - bit style:
128 RULER_MARGIN_SIZEABLE
129 margin size can be changed
131 The following bits can be set in addition
132 to these styles:
133 RULER_STYLE_INVISIBLE
136 SetBorders() sets an array of margins. To do this, an array of type RulerBorder
137 has to be passed. In the array, the following values have to be initialized:
139 long nPos - offset in pixels relative to the origin
140 long nWidth - column spacing in pixels (can also be 0, for example,
141 for table columns)
142 sal_uInt16 nStyle - bit style:
143 RULER_BORDER_SIZEABLE
144 Column spacing can be changed. This flag should
145 only be set if the size of the spacing is changed,
146 not that of a cell.
147 RULER_BORDER_MOVEABLE
148 Column spacing/border can be moved. Whenever
149 table borders are to be moved, this flag should
150 be set instead of SIZEABLE (SIZEABLE indicates
151 that the size of a spacing, not that of a single
152 cell can be changed).
153 RULER_BORDER_VARIABLE
154 Not all of the column spacings are equal
155 RULER_BORDER_TABLE
156 Table border. Whenever this style is set, the column
157 width must be 0.
158 RULER_BORDER_SNAP
159 Auxiliary line. Whenever this style is set, the
160 column width must be 0.
161 RULER_BORDER_MARGIN
162 Margin. Whenever this style is set, the column
163 width must be 0.
165 The following bits can be set in addition
166 to these styles:
167 RULER_STYLE_INVISIBLE
169 SetIndents() sets an array of indents. This method may only be used for horizontal
170 rulers. A Ruler Indent must be passed as an argument, with the following values
171 initialized:
173 long nPos - offset relative to the origin in pixels
174 sal_uInt16 nStyle - bit style:
175 RULER_INDENT_TOP (indent of the first line)
176 RULER_INDENT_BOTTOM (left/right indent)
177 RULER_INDENT_BORDER (Vertical line that shows the border distance)
178 The following bits can be set in addition
179 to these styles:
180 RULER_STYLE_DONTKNOW (for old position or for
181 ambiguity)
182 RULER_STYLE_INVISIBLE
184 SetTabs() sets an array of tabs. This method may only be used for horizontal rulers.
185 An array of type RulerTab must be passed as an argument, with the following values
186 initialized:
188 long nPos - offset relative to the origin in pixels
189 sal_uInt16 nStyle - bit style:
190 RULER_TAB_DEFAULT (can't be selected)
191 RULER_TAB_LEFT
192 RULER_TAB_CENTER
193 RULER_TAB_RIGHT
194 RULER_TAB_DECIMAL
195 The following bits can be set in addition
196 to these styles:
197 RULER_STYLE_DONTKNOW (for old position of for
198 ambiguity)
199 RULER_STYLE_INVISIBLE
201 SetLines() displays position lines in the ruler. An array of type RulerLine must be passed, with
202 the following values initialized:
204 long nPos - offset relative to the origin in pixels
205 sal_uInt16 nStyle - bit style (has to be 0 currently)
207 --------------------------------------------------------------------------
209 If the user should also be able to change the margins tabs, borders, ...
210 in the ruler, a bit more effort is necessary. In this case, the StartDrag(),
211 Drag() and EndDrag() methods have to be overridden. For the StartDrag() method
212 it is possible to prevent dragging by returning FALSE. In the drag handler,
213 the drag position must be queried and the values must be moved to the new
214 position. This is done by calling the particular Set methods. While in the
215 drag handler, the values are just cached and only afterward the ruler is redrawn.
216 All the handlers can also be set as links with the particular Set..Hdl() methods.
218 - StartDrag()
219 Is called when dragging is started. If FALSE is returned, the dragging.
220 won't be executed. If TRUE is returned, the dragging will be permitted.
221 If the handler isn't overridden, FALSE will be returned.
223 - EndDrag()
224 Is called at the end of dragging.
226 - Drag()
227 Is called when dragging takes place.
229 - Click()
230 This handler is called when no element has been clicked on.
231 The position can be queried with GetClickPos(). This way it is possible
232 to, for example, ser tabs in the ruler. After calling the click handler,
233 the drag, if any, is immediately triggered. This makes it possible to
234 set a new tab in the click handler and then immediately move it.
236 - DoubleClick()
237 This handler is called when a double-click has been performed outside
238 the special panel. The methods GetClickType(), GetClickAryPos() and
239 GetClickPos() can be used to query what has been clicked on.
240 This way you can, for example, show the tab dialog when a double-click
241 is performed on a tab.
243 In the drag handler it is possible to query what has been dragged and where
244 it has been dragged. There are the following query methods:
246 - GetDragType()
247 Returns what has been dragged.
248 RULER_TYPE_MARGIN1
249 RULER_TYPE_MARGIN2
250 RULER_TYPE_BORDER
251 RULER_TYPE_INDENT
252 RULER_TYPE_TAB
254 - GetDragPos()
255 Returns the pixel position to which the user has moved the mouse
256 relative to the set zero-offset.
258 - GetDragAryPos()
259 Liefert den Index im Array zurueck, wenn ein Border, Indent oder ein
260 Tab gedragt wird. Achtung: Es wird die Array-Position waehrend des
261 gesammten Drag-Vorgangs von dem Item im Array was vor dem Drag gesetzt
262 war zurueckgeben. Dadurch ist es zum Beispiel auch moeglich, einen
263 Tab nicht mehr anzuzeigen, wenn die Maus nach unten/rechts aus dem
264 Lineal gezogen wird.
266 - GetDragSize()
267 Wenn Borders gedragt werden, kann hierueber abgefragt werden, ob
268 die Groesse bzw. welche Seite oder die Position geaendert werden soll.
269 RULER_DRAGSIZE_MOVE oder 0 - Move
270 RULER_DRAGSIZE_1 - Linke/obere Kante
271 RULER_DRAGSIZE_2 - Rechte/untere Kante
273 - IsDragDelete()
274 Mit dieser Methode kann abgefragt werden, ob beim Draggen die
275 Maus unten/rechts aus dem Fenster gezogen wurde. Damit kann
276 zum Beispiel festgestellt werden, ob der Benutzer einen Tab
277 loeschen will.
279 - IsDragCanceled()
280 Mit dieser Methode kann im EndDrag-Handler abgefragt werden,
281 ob die Aktion abgebrochen wurde, indem der Anwender die
282 Maus oben/links vom Fenster losgelassen hat oder ESC gedrueckt
283 hat. In diesem Fall werden die Werte nicht uebernommen. Wird
284 waehrend des Draggings die Maus oben/links aus dem Fenster
285 gezogen, werden automatisch die alten Werte dargestellt, ohne das
286 der Drag-Handler gerufen wird.
287 Falls der Benutzer jedoch den Wert auf die alte Position
288 zurueckgeschoben hat, liefert die Methode trotzdem sal_False. Falls
289 dies vermieden werden soll, muss sich die Applikation im StartDrag-
290 Handler den alten Wert merken und im EndDrag-Handler den Wert
291 vergleichen.
293 - GetDragScroll()
294 Mit dieser Methode kann abgefragt werden, ob gescrollt werden
295 soll. Es wird einer der folgenden Werte zurueckgegeben:
296 RULER_SCROLL_NO - Drag-Position befindet sich
297 an keinem Rand und somit
298 muss nicht gescrollt werden.
299 RULER_SCROLL_1 - Drag-Position befindet sich
300 am linken/oberen Rand und
301 somit sollte das Programm evt.
302 ein Srcoll ausloesen.
303 RULER_SCROLL_2 - Drag-Position befindet sich
304 am rechten/unteren Rand und
305 somit sollte das Programm evt.
306 ein Srcoll ausloesen.
308 - GetDragModifier()
309 Liefert die Modifier-Tasten zurueck, die beim Starten des Drag-
310 Vorgangs gedrueckt waren. Siehe MouseEvent.
312 - GetClickPos()
313 Liefert die Pixel-Position bezogen auf den eingestellten Null-Offset
314 zurueck, wo der Anwender die Maus gedrueckt hat.
316 - GetClickType()
317 Liefert zurueck, was per DoubleClick betaetigt wird:
318 RULER_TYPE_DONTKNOW (kein Element im Linealbereich)
319 RULER_TYPE_OUTSIDE (ausserhalb des Linealbereichs)
320 RULER_TYPE_MARGIN1 (nur Margin1-Kante)
321 RULER_TYPE_MARGIN2 (nur Margin2-Kante)
322 RULER_TYPE_BORDER (Border: GetClickAryPos())
323 RULER_TYPE_INDENT (Einzug: GetClickAryPos())
324 RULER_TYPE_TAB (Tab: GetClickAryPos())
326 - GetClickAryPos()
327 Liefert den Index im Array zurueck, wenn ein Border, Indent oder ein
328 Tab per DoubleClick betaetigt wird.
330 - GetType()
331 Mit dieser Methode kann man einen HitTest durchfuehren, um
332 gegebenenfalls ueber das Abfangen des MouseButtonDown-Handlers
333 auch ueber die rechte Maustaste etwas auf ein Item anzuwenden. Als
334 Paramter ueber gibt man die Fensterposition und gegebenenfalls
335 einen Pointer auf einen sal_uInt16, um die Array-Position eines
336 Tabs, Indent oder Borders mitzubekommen. Als Type werden folgende
337 Werte zurueckgegeben:
338 RULER_TYPE_DONTKNOW (kein Element im Linealbereich)
339 RULER_TYPE_OUTSIDE (ausserhalb des Linealbereichs)
340 RULER_TYPE_MARGIN1 (nur Margin1-Kante)
341 RULER_TYPE_MARGIN2 (nur Margin2-Kante)
342 RULER_TYPE_BORDER (Border: GetClickAryPos())
343 RULER_TYPE_INDENT (Einzug: GetClickAryPos())
344 RULER_TYPE_TAB (Tab: GetClickAryPos())
346 Wenn der Drag-Vorgang abgebrochen werden soll, kann der Drag-Vorgang
347 mit CancelDrag() abgebrochen werden. Folgende Methoden gibt es fuer die
348 Drag-Steuerung:
350 - IsDrag()
351 Liefert sal_True zurueck, wenn sich das Lineal im Drag-Vorgang befindet.
353 - CancelDrag()
354 Bricht den Drag-Vorgang ab, falls einer durchgefuehrt wird. Dabei
355 werden die alten Werte wieder hergestellt und der Drag und der
356 EndDrag-Handler gerufen.
358 Um vom Dokument ein Drag auszuloesen, gibt es folgende Methoden:
360 - StartDocDrag()
361 Dieser Methode werden der MouseEvent vom Dokumentfenster und
362 was gedragt werden soll uebergeben. Wenn als DragType
363 RULER_TYPE_DONTKNOW uebergeben wird, bestimmt das Lineal, was
364 verschoben werden soll. Bei den anderen, wird der Drag nur dann
365 gestartet, wenn auch an der uebergebenen Position ein entsprechendes
366 Element gefunden wurde. Dies ist zun Beispiel dann notwendig, wenn
367 zum Beispiel Einzuege und Spalten an der gleichen X-Position liegen.
368 Der Rueckgabewert gibt an, ob der Drag ausgeloest wurde. Wenn ein
369 Drag ausgeloest wird, uebernimmt das Lineal die normale Drag-Steuerung
370 und verhaelt sich dann so, wie als wenn direkt in das Lineal geklickt
371 wurde. So captured das Lineal die Mouse und uebernimmt auch die
372 Steuerung des Cancel (ueber Tastatur, oder wenn die Mouse ueber
373 oder links vom Lineal ruasgeschoben wird). Auch alle Handler werden
374 gerufen (inkl. des StartDrag-Handlers). Wenn ein MouseEvent mit
375 Click-Count 2 uebergeben wird auch der DoubleClick-Handler
376 entsprechend gerufen.
378 --------------------------------------------------------------------------
380 Fuer das Extra-Feld kann der Inhalt bestimmt werden und es gibt Handler,
381 womit man bestimmte Aktionen abfangen kann.
383 - ExtraDown()
384 Dieser Handler wird gerufen, wenn im Extra-Feld die Maus
385 gedrueckt wird.
387 - SetExtraType()
388 Mit dieser Methode kann festgelegt werden, was im ExtraFeld
389 dargestellt werden soll.
390 - ExtraType Was im Extrafeld dargestellt werden soll
391 RULER_EXTRA_DONTKNOW (Nichts)
392 RULER_EXTRA_NULLOFFSET (Koordinaaten-Kreuz)
393 RULER_EXTRA_TAB (Tab)
394 - sal_uInt16 nStyle Bitfeld als Style:
395 RULER_STYLE_HIGHLIGHT (selektiert)
396 RULER_TAB_... (ein Tab-Style)
398 - GetExtraClick()
399 Liefert die Anzahl der Mausclicks zurueck. Dadurch ist es zum
400 Beispiel auch moeglich, auch durch einen DoubleClick im Extrafeld
401 eine Aktion auszuloesen.
403 - GetExtraModifier()
404 Liefert die Modifier-Tasten zurueck, die beim Klicken in das Extra-
405 Feld gedrueckt waren. Siehe MouseEvent.
407 --------------------------------------------------------------------------
409 Weitere Hilfsfunktionen:
411 - static Ruler::DrawTab()
412 Mit dieser Methode kann ein Tab auf einem OutputDevice ausgegeben
413 werden. Dadurch ist es moeglich, auch in Dialogen die Tabs so
414 anzuzeigen, wie Sie im Lineal gemalt werden.
416 Diese Methode gibt den Tab zentriert an der uebergebenen Position
417 aus. Die Groesse der Tabs kann ueber die Defines RULER_TAB_WIDTH und
418 RULER_TAB_HEIGHT bestimmt werden.
420 --------------------------------------------------------------------------
422 Tips zur Benutzung des Lineals:
424 - Bei dem Lineal muss weder im Drag-Modus noch sonst das Setzen der Werte
425 in SetUpdateMode() geklammert werden. Denn das Lineal sorgt von sich
426 aus dafuer, das wenn mehrere Werte gesetzt werden, diese automatisch
427 zusammengefast werden und flackerfrei ausgegeben werden.
429 - Initial sollten beim Lineal zuerst die Groessen, Positionen und Werte
430 gesetzt werden, bevor es angezeigt wird. Dies ist deshalb wichtig, da
431 ansonsten viele Werte unnoetig berechnet werden.
433 - Wenn das Dokumentfenster, in dem sich das Lineal befindet aktiv bzw.
434 deaktiv wird, sollten die Methoden Activate() und Deactivate() vom
435 Lineal gerufen werden. Denn je nach Einstellungen und System wird die
436 Anzeige entsprechend umgeschaltet.
438 - Zum Beispiel sollte beim Drag von Tabs und Einzuegen nach Moeglichkeit die
439 alten Positionen noch mit angezeigt werden. Dazu sollte zusaetzlich beim
440 Setzen der Tabs und Einzuege als erstes im Array die alten Positionen
441 eingetragen werden und mit dem Style RULER_STYLE_DONTKNOW verknuepft
442 werden. Danach sollte im Array die restlichen Werte eingetragen werden.
444 - Bei mehreren markierten Absaetzen und Tabellen-Zellen, sollten die Tabs
445 und Einzuege in grau von der ersten Zelle, bzw. vom ersten Absatz
446 angezeigt werden. Dies kann man auch ueber den Style RULER_STYLE_DONTKNOW
447 erreichen.
449 - Die Bemassungspfeile sollten immer dann angezeigt, wenn beim Drag die
450 Alt-Taste (WW-Like) gedrueckt wird. Vielleicht sollte diese Einstellung
451 auch immer vornehmbar sein und vielleicht beim Drag immer die
452 Bemassungspfeile dargestellt werden. Bei allen Einstellung sollten die
453 Werte immer auf ein vielfaches eines Wertes gerundet werden, da die
454 Bildschirmausloesung sehr ungenau ist.
456 - DoppelKlicks sollten folgendermassen behandelt werden (GetClickType()):
457 - RULER_TYPE_DONTKNOW
458 RULER_TYPE_MARGIN1
459 RULER_TYPE_MARGIN2
460 Wenn die Bedingunden GetClickPos() <= GetMargin1() oder
461 GetClickPos() >= GetMargin2() oder der Type gleich
462 RULER_TYPE_MARGIN1 oder RULER_TYPE_MARGIN2 ist, sollte
463 ein SeitenDialog angezeigt werden, wo der Focus auf dem
464 entsprechenden Rand steht
465 - RULER_TYPE_BORDER
466 Es sollte ein Spalten- oder Tabellen-Dialog angezeigt werden,
467 wo der Focus auf der entsprechenden Spalte steht, die mit
468 GetClickAryPos() abgefragt werden kann.
469 - RULER_TYPE_INDENT
470 Es sollte der Dialog angezeigt werden, wo die Einzuege eingestellt
471 werden koennen. Dabei sollte der Focus auf dem Einzug stehen, der
472 mit GetClickAryPos() ermittelt werden kann.
473 - RULER_TYPE_TAB
474 Es sollte ein TabDialog angezeigt werden, wo der Tab selektiert
475 sein sollte, der ueber GetClickAryPos() abgefragt werden kann.
477 *************************************************************************/
479 // - WinBits -
481 #define WB_EXTRAFIELD ((WinBits)0x00004000)
482 #define WB_RIGHT_ALIGNED ((WinBits)0x00008000)
483 #define WB_STDRULER WB_HORZ
485 // - Ruler-Type -
487 enum RulerType { RULER_TYPE_DONTKNOW, RULER_TYPE_OUTSIDE,
488 RULER_TYPE_MARGIN1, RULER_TYPE_MARGIN2,
489 RULER_TYPE_BORDER, RULER_TYPE_INDENT, RULER_TYPE_TAB };
491 enum RulerExtra { RULER_EXTRA_DONTKNOW,
492 RULER_EXTRA_NULLOFFSET, RULER_EXTRA_TAB };
494 #define RULER_STYLE_HIGHLIGHT ((sal_uInt16)0x8000)
495 #define RULER_STYLE_DONTKNOW ((sal_uInt16)0x4000)
496 #define RULER_STYLE_INVISIBLE ((sal_uInt16)0x2000)
498 #define RULER_DRAGSIZE_MOVE 0
499 #define RULER_DRAGSIZE_1 1
500 #define RULER_DRAGSIZE_2 2
502 #define RULER_MOUSE_BORDERMOVE 5
503 #define RULER_MOUSE_BORDERWIDTH 5
504 #define RULER_MOUSE_MARGINWIDTH 3
506 #define RULER_SCROLL_NO 0
507 #define RULER_SCROLL_1 1
508 #define RULER_SCROLL_2 2
510 // - RulerMargin -
512 #define RULER_MARGIN_SIZEABLE ((sal_uInt16)0x0001)
514 // - RulerBorder -
516 #define RULER_BORDER_SIZEABLE ((sal_uInt16)0x0001)
517 #define RULER_BORDER_MOVEABLE ((sal_uInt16)0x0002)
518 #define RULER_BORDER_VARIABLE ((sal_uInt16)0x0004)
519 #define RULER_BORDER_TABLE ((sal_uInt16)0x0008)
520 #define RULER_BORDER_SNAP ((sal_uInt16)0x0010)
521 #define RULER_BORDER_MARGIN ((sal_uInt16)0x0020)
523 struct RulerBorder
525 long nPos;
526 long nWidth;
527 sal_uInt16 nStyle;
528 long nMinPos; //minimum/maximum position, supported for table borders/rows
529 long nMaxPos;
532 // - RulerIndent -
534 #define RULER_INDENT_TOP ((sal_uInt16)0x0000)
535 #define RULER_INDENT_BOTTOM ((sal_uInt16)0x0001)
536 #define RULER_INDENT_BORDER ((sal_uInt16)0x0002)
537 #define RULER_INDENT_STYLE ((sal_uInt16)0x000F)
539 struct RulerIndent
541 long nPos;
542 sal_uInt16 nStyle;
545 // - RulerTab -
547 #define RULER_TAB_LEFT ((sal_uInt16)0x0000)
548 #define RULER_TAB_RIGHT ((sal_uInt16)0x0001)
549 #define RULER_TAB_CENTER ((sal_uInt16)0x0002)
550 #define RULER_TAB_DECIMAL ((sal_uInt16)0x0003)
551 #define RULER_TAB_DEFAULT ((sal_uInt16)0x0004)
552 #define RULER_TAB_STYLE ((sal_uInt16)0x000F)
553 #define RULER_TAB_RTL ((sal_uInt16)0x0010)
555 struct RulerTab
557 long nPos;
558 sal_uInt16 nStyle;
561 #define RULER_TAB_WIDTH 7
562 #define RULER_TAB_HEIGHT 6
564 // - RulerLine -
566 struct RulerLine
568 long nPos;
569 sal_uInt16 nStyle;
572 struct RulerSelection
574 long nPos;
575 RulerType eType;
576 sal_uInt16 nAryPos;
577 sal_uInt16 mnDragSize;
578 bool bSize;
579 bool bSizeBar;
580 bool bExpandTest;
582 RulerSelection()
583 : nPos(0)
584 , eType(RULER_TYPE_DONTKNOW)
585 , nAryPos(0)
586 , mnDragSize(0)
587 , bSize(false)
588 , bSizeBar(false)
589 , bExpandTest( false )
593 struct RulerUnitData
595 MapUnit eMapUnit; // MAP_UNIT for calculaion
596 long nTickUnit; // Unit divider
597 double nTick1; // Minimal step
598 double nTick2; // Tick quarter unit
599 double nTick3; // Tick half unit
600 double nTick4; // Tick whole unit
601 long n100THMM; // 100mm Unit divider
602 sal_uInt16 nUnitDigits; // Number of digits
603 sal_Char aUnitStr[8]; // Unit string
606 // - Ruler -
608 class ImplRulerData;
610 class SVT_DLLPUBLIC Ruler : public Window
612 private:
613 VirtualDevice maVirDev;
614 MapMode maMapMode;
615 long mnBorderOff;
616 long mnWinOff;
617 long mnWinWidth;
618 long mnWidth;
619 long mnHeight;
620 long mnVirOff;
621 long mnVirWidth;
622 long mnVirHeight;
623 long mnBorderWidth;
624 long mnStartDragPos;
625 long mnDragPos;
626 ImplSVEvent * mnUpdateEvtId;
627 ImplRulerData* mpSaveData;
628 ImplRulerData* mpData;
629 ImplRulerData* mpDragData;
630 Rectangle maExtraRect;
631 WinBits mnWinStyle;
632 sal_uInt16 mnUnitIndex;
633 sal_uInt16 mnDragAryPos;
634 sal_uInt16 mnDragSize;
635 sal_uInt16 mnDragScroll;
636 sal_uInt16 mnDragModifier;
637 sal_uInt16 mnExtraStyle;
638 sal_uInt16 mnExtraClicks;
639 sal_uInt16 mnExtraModifier;
640 long mnCharWidth;
641 long mnLineHeight;
643 RulerExtra meExtraType;
644 RulerType meDragType;
645 MapUnit meSourceUnit;
646 FieldUnit meUnit;
647 Fraction maZoom;
648 bool mbCalc;
649 bool mbFormat;
650 bool mbDrag;
651 bool mbDragDelete;
652 bool mbDragCanceled;
653 bool mbAutoWinWidth;
654 bool mbActive;
655 sal_uInt8 mnUpdateFlags;
657 RulerSelection maHoverSelection;
659 Link maStartDragHdl;
660 Link maDragHdl;
661 Link maEndDragHdl;
662 Link maClickHdl;
663 Link maDoubleClickHdl;
664 Link maExtraDownHdl;
666 boost::scoped_ptr<RulerSelection> mpCurrentHitTest;
667 boost::scoped_ptr<RulerSelection> mpPreviousHitTest;
669 SvtRulerAccessible* pAccContext;
671 SVT_DLLPRIVATE void ImplVDrawLine( long nX1, long nY1, long nX2, long nY2 );
672 SVT_DLLPRIVATE void ImplVDrawRect( long nX1, long nY1, long nX2, long nY2 );
673 SVT_DLLPRIVATE void ImplVDrawText( long nX, long nY, const OUString& rText, long nMin = LONG_MIN, long nMax = LONG_MAX );
675 SVT_DLLPRIVATE void ImplDrawTicks( long nMin, long nMax, long nStart, long nVirTop, long nVirBottom );
676 SVT_DLLPRIVATE void ImplDrawBorders( long nMin, long nMax, long nVirTop, long nVirBottom );
677 SVT_DLLPRIVATE void ImplDrawIndent( const Polygon& rPoly, sal_uInt16 nStyle, bool bIsHit = false );
678 SVT_DLLPRIVATE void ImplDrawIndents( long nMin, long nMax, long nVirTop, long nVirBottom );
679 SVT_DLLPRIVATE void ImplDrawTab( OutputDevice* pDevice, const Point& rPos, sal_uInt16 nStyle );
680 SVT_DLLPRIVATE void ImplDrawTabs( long nMin, long nMax, long nVirTop, long nVirBottom );
682 using Window::ImplInit;
683 SVT_DLLPRIVATE void ImplInit( WinBits nWinBits );
684 SVT_DLLPRIVATE void ImplInitSettings( bool bFont, bool bForeground, bool bBackground );
685 SVT_DLLPRIVATE void ImplCalc();
686 SVT_DLLPRIVATE void ImplFormat();
687 SVT_DLLPRIVATE void ImplInitExtraField( bool bUpdate );
688 SVT_DLLPRIVATE void ImplInvertLines( bool bErase = false );
689 SVT_DLLPRIVATE void ImplDraw();
690 SVT_DLLPRIVATE void ImplDrawExtra( bool bPaint = false );
691 SVT_DLLPRIVATE void ImplUpdate( bool bMustCalc = false );
693 using Window::ImplHitTest;
694 SVT_DLLPRIVATE bool ImplHitTest( const Point& rPosition,
695 RulerSelection* pHitTest,
696 bool bRequiredStyle = false,
697 sal_uInt16 nRequiredStyle = 0 ) const;
698 SVT_DLLPRIVATE bool ImplDocHitTest( const Point& rPos, RulerType eDragType, RulerSelection* pHitTest ) const;
699 SVT_DLLPRIVATE bool ImplStartDrag( RulerSelection* pHitTest, sal_uInt16 nModifier );
700 SVT_DLLPRIVATE void ImplDrag( const Point& rPos );
701 SVT_DLLPRIVATE void ImplEndDrag();
703 DECL_DLLPRIVATE_LINK( ImplUpdateHdl, void* );
705 // Forbidden and not implemented.
706 Ruler (const Ruler &);
707 Ruler& operator= (const Ruler &);
709 protected:
710 long GetRulerVirHeight() const { return mnVirHeight;}
711 MapMode GetCurrentMapMode() const { return maMapMode; }
712 RulerUnitData GetCurrentRulerUnit() const;
714 public:
715 Ruler( Window* pParent, WinBits nWinStyle = WB_STDRULER );
716 virtual ~Ruler();
718 virtual void MouseButtonDown( const MouseEvent& rMEvt ) SAL_OVERRIDE;
719 virtual void MouseMove( const MouseEvent& rMEvt ) SAL_OVERRIDE;
720 virtual void Tracking( const TrackingEvent& rTEvt ) SAL_OVERRIDE;
721 virtual void Paint( const Rectangle& rRect ) SAL_OVERRIDE;
722 virtual void Resize() SAL_OVERRIDE;
723 virtual void StateChanged( StateChangedType nStateChange ) SAL_OVERRIDE;
724 virtual void DataChanged( const DataChangedEvent& rDCEvt ) SAL_OVERRIDE;
726 virtual long StartDrag();
727 virtual void Drag();
728 virtual void EndDrag();
729 virtual void Click();
730 virtual void DoubleClick();
731 virtual void ExtraDown();
733 void Activate() SAL_OVERRIDE;
734 void Deactivate() SAL_OVERRIDE;
735 bool IsActive() const { return mbActive; }
737 void SetWinPos( long nOff = 0, long nWidth = 0 );
738 long GetWinOffset() const { return mnWinOff; }
739 long GetWinWidth() const { return mnWinWidth; }
740 void SetPagePos( long nOff = 0, long nWidth = 0 );
741 long GetPageOffset() const;
742 void SetBorderPos( long nOff = 0 );
743 long GetBorderOffset() const { return mnBorderOff; }
744 Rectangle GetExtraRect() const { return maExtraRect; }
746 void SetUnit( FieldUnit eNewUnit );
747 FieldUnit GetUnit() const { return meUnit; }
748 void SetZoom( const Fraction& rNewZoom );
749 Fraction GetZoom() const { return maZoom; }
751 void SetSourceUnit( MapUnit eNewUnit ) { meSourceUnit = eNewUnit; }
752 MapUnit GetSourceUnit() const { return meSourceUnit; }
754 void SetExtraType( RulerExtra eNewExtraType, sal_uInt16 nStyle = 0 );
755 RulerExtra GetExtraType() const { return meExtraType; }
756 sal_uInt16 GetExtraStyle() const { return mnExtraStyle; }
757 sal_uInt16 GetExtraClicks() const { return mnExtraClicks; }
758 sal_uInt16 GetExtraModifier() const { return mnExtraModifier; }
760 bool StartDocDrag( const MouseEvent& rMEvt,
761 RulerType eDragType = RULER_TYPE_DONTKNOW );
762 RulerType GetDragType() const { return meDragType; }
763 long GetDragPos() const { return mnDragPos; }
764 sal_uInt16 GetDragAryPos() const { return mnDragAryPos; }
765 sal_uInt16 GetDragSize() const { return mnDragSize; }
766 bool IsDragDelete() const { return mbDragDelete; }
767 bool IsDragCanceled() const { return mbDragCanceled; }
768 sal_uInt16 GetDragScroll() const { return mnDragScroll; }
769 sal_uInt16 GetDragModifier() const { return mnDragModifier; }
770 bool IsDrag() const { return mbDrag; }
771 void CancelDrag();
772 long GetClickPos() const { return mnDragPos; }
773 RulerType GetClickType() const { return meDragType; }
774 sal_uInt16 GetClickAryPos() const { return mnDragAryPos; }
776 RulerSelection GetHoverSelection() const { return maHoverSelection; }
778 using Window::GetType;
779 RulerType GetType( const Point& rPos, sal_uInt16* pAryPos = NULL );
781 void SetNullOffset( long nPos );
782 long GetNullOffset() const;
783 void SetMargin1() { SetMargin1( 0, RULER_STYLE_INVISIBLE ); }
784 void SetMargin1( long nPos, sal_uInt16 nMarginStyle = RULER_MARGIN_SIZEABLE );
785 long GetMargin1() const;
786 void SetMargin2() { SetMargin2( 0, RULER_STYLE_INVISIBLE ); }
787 void SetMargin2( long nPos, sal_uInt16 nMarginStyle = RULER_MARGIN_SIZEABLE );
788 long GetMargin2() const;
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 );
796 void SetTabs( sal_uInt32 n = 0, const RulerTab* pTabAry = NULL );
797 sal_uInt32 GetTabCount() const;
798 const RulerTab* GetTabs() const;
800 static void DrawTab( OutputDevice* pDevice, const Color &rFillColor,
801 const Point& rPos, sal_uInt16 nStyle );
803 void SetStyle( WinBits nStyle );
804 WinBits GetStyle() const { return mnWinStyle; }
806 void SetStartDragHdl( const Link& rLink ) { maStartDragHdl = rLink; }
807 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 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; }
819 void SetTextRTL(bool bRTL);
820 bool GetTextRTL();
821 void SetCharWidth( long nWidth ) { mnCharWidth = nWidth ; }
822 void SetLineHeight( long nHeight ) { mnLineHeight = nHeight ; }
824 void DrawTicks();
826 virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > CreateAccessible() SAL_OVERRIDE;
829 #endif // INCLUDED_SVTOOLS_RULER_HXX
831 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */