LibreOffice Module svx (master)  1
ruler.hxx
Go to the documentation of this file.
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 #ifndef INCLUDED_SVX_RULER_HXX
20 #define INCLUDED_SVX_RULER_HXX
21 
22 #include <svtools/ruler.hxx>
23 #include <svl/lstner.hxx>
24 #include <svx/svxdllapi.h>
25 #include <o3tl/typed_flags_set.hxx>
26 
27 #include <memory>
28 
29 class Menu;
30 class SvxProtectItem;
31 class SvxRulerItem;
32 class SfxBindings;
33 class SvxLongLRSpaceItem;
34 class SvxLongULSpaceItem;
35 class SvxTabStopItem;
36 class SvxLRSpaceItem;
37 class SvxPagePosSizeItem;
38 class SvxColumnItem;
39 class SfxRectangleItem;
40 class SvxObjectItem;
41 class SfxBoolItem;
42 struct SvxRuler_Impl;
43 
44 enum class RulerChangeType
45 {
46  MARGIN1,
47  MARGIN2
48 };
49 
51 {
52  NONE = 0x00,
53  OBJECT = 0x01,
54  // reduce size of the last column, shift
55  OBJECT_SIZE_LINEAR = 0x02,
56  OBJECT_SIZE_PROPORTIONAL = 0x04, // proportional, Ctrl
57  // only current line (table; Shift-Ctrl)
58  OBJECT_ACTLINE_ONLY = 0x08,
59  // currently same key assignment
61 };
62 namespace o3tl
63 {
64  template<> struct typed_flags<SvxRulerDragFlags> : is_typed_flags<SvxRulerDragFlags, 0x0f> {};
65 }
66 
68 {
69  TABS = 0x0001,
70  PARAGRAPH_MARGINS = 0x0002,
71  BORDERS = 0x0004,
72  OBJECT = 0x0008,
73  SET_NULLOFFSET = 0x0010,
74  NEGATIVE_MARGINS = 0x0020,
76  REDUCED_METRIC = 0x0080, //shorten the context menu to select metric
77 };
78 namespace o3tl
79 {
80  template<> struct typed_flags<SvxRulerSupportFlags> : is_typed_flags<SvxRulerSupportFlags, 0x00ff> {};
81 }
82 
83 class SVX_DLLPUBLIC SvxRuler: public Ruler, public SfxListener
84 {
85  friend class SvxRulerItem;
86 
87  std::vector<std::unique_ptr<SvxRulerItem> > pCtrlItems;
88 
89  std::unique_ptr<SvxLongLRSpaceItem> mxLRSpaceItem; // left and right edge
90  std::unique_ptr<SfxRectangleItem> mxMinMaxItem; // maxima for dragging
91  std::unique_ptr<SvxLongULSpaceItem> mxULSpaceItem; // upper and lower edge
92  std::unique_ptr<SvxTabStopItem> mxTabStopItem; // tab stops
93  std::unique_ptr<SvxLRSpaceItem> mxParaItem; // paragraphs
94  std::unique_ptr<SvxPagePosSizeItem> mxPagePosItem; // page distance to the rule
95  std::unique_ptr<SvxColumnItem> mxColumnItem; // columns
96  std::unique_ptr<SvxObjectItem> mxObjectItem; // object
97 
99 
100  std::unique_ptr<SvxRuler_Impl> mxRulerImpl;
101 
102  bool bAppSetNullOffset :1;
103  bool bHorz :1;
104  long lLogicNullOffset; // in logic coordinates
105  long lAppNullOffset; // in logic coordinates
109  sal_uInt16 nDefTabType;
110  sal_uInt16 nTabCount;
111  sal_uInt16 nTabBufSize;
113  long lTabPos;
114 
115  std::vector<RulerTab> mpTabs; // tab positions in pixel
116  std::vector<RulerIndent> mpIndents; // paragraph margins in pixel
117  std::vector<RulerBorder> mpBorders;
118  std::vector<RulerBorder> mpObjectBorders;
119 
122  long nMaxLeft;
123  long nMaxRight;
124  bool bValid;
126  bool bActive;
127 
130 
131  void StartListening_Impl();
132  long GetCorrectedDragPos(bool bLeft = true, bool bRight = true );
133  void DrawLine_Impl(long &lTabPos, int, bool Horizontal);
134  sal_uInt16 GetObjectBordersOff(sal_uInt16 nIdx) const;
135 
136  // page borders or surrounding frame
137  void UpdateFrame(const SvxLongLRSpaceItem* pItem);
138  void UpdateFrame(const SvxLongULSpaceItem* pItem);
139  void UpdateFrameMinMax(const SfxRectangleItem* pItem);
140  // paragraph indentations
141  void UpdatePara(const SvxLRSpaceItem* pItem);
142  // Border distance
143  void UpdateParaBorder();
144  // Tabs
145  void Update(const SvxTabStopItem* pItem);
146  // page position and width
147  void Update(const SvxPagePosSizeItem* pItem);
148  // columns
149  void Update(const SvxColumnItem* pItem, sal_uInt16 nSID);
150  // object selection
151  void Update(const SvxObjectItem* pItem);
152  // protect
153  void Update(const SvxProtectItem* pItem );
154  // left-to-right text
155  void UpdateTextRTL(const SfxBoolItem* pItem);
156  // paragraph indentations
157  void UpdatePara();
158  void UpdateTabs();
159  void UpdatePage();
160  void UpdateFrame();
161  void UpdateColumns();
162  void UpdateObject();
163 
164  // Convert position to stick to ruler ticks
165  long MakePositionSticky(long rValue, long aPointOfReference, bool aSnapToFrameMargin = true) const;
166 
167  long PixelHAdjust(long lPos, long lPos2) const;
168  long PixelVAdjust(long lPos, long lPos2) const;
169  long PixelAdjust(long lPos, long lPos2) const;
170 
171  long ConvertHPosPixel(long lPos) const;
172  long ConvertVPosPixel(long lPos) const;
173  long ConvertHSizePixel(long lSize) const;
174  long ConvertVSizePixel(long lSize) const;
175 
176  long ConvertPosPixel(long lPos) const;
177  long ConvertSizePixel(long lSize) const;
178 
179  long ConvertHPosLogic(long lPos) const;
180  long ConvertVPosLogic(long lPos) const;
181  long ConvertHSizeLogic(long lSize) const;
182  long ConvertVSizeLogic(long lSize) const;
183 
184  long ConvertPosLogic(long lPos) const;
185  long ConvertSizeLogic(long lSize) const;
186 
187  long RoundToCurrentMapMode(long lValue) const;
188 
189  long GetFirstLineIndent() const;
190  long GetLeftIndent() const;
191  long GetRightIndent() const;
192  long GetLogicRightIndent() const;
193 
194  long GetLeftFrameMargin() const;
195  long GetRightFrameMargin() const;
196 
197  void CalcMinMax();
198 
199  void EvalModifier();
200  void DragMargin1();
201  //adjust the left margin either after DragMargin1() or after DragBorders()
202  void AdjustMargin1(long lDiff);
203  void DragMargin2();
204  void DragIndents();
205  void DragTabs();
206  void DragBorders();
207  void DragObjectBorder();
208 
209  void ApplyMargins();
210  void ApplyIndents();
211  void ApplyTabs();
212  void ApplyBorders();
213  void ApplyObject();
214 
215  long GetFrameLeft() const;
216 
217  long GetLeftMin() const;
218  long GetRightMax() const;
219 
220  DECL_LINK( TabMenuSelect, Menu *, bool );
221  DECL_LINK( MenuSelect, Menu *, bool );
222  void PrepareProportional_Impl(RulerType);
223 
224  enum class UpdateType
225  {
226  MoveLeft,
227  MoveRight
228  };
229  void UpdateParaContents_Impl(long lDiff, UpdateType);
230 
231 protected:
232  virtual void Command( const CommandEvent& rCEvt ) override;
233  virtual void Click() override;
234  virtual bool StartDrag() override;
235  virtual void Drag() override;
236  virtual void EndDrag() override;
237  virtual void ExtraDown() override;
238  virtual void MouseMove( const MouseEvent& rMEvt ) override;
239 
240  virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) override;
241 
242  virtual void Update();
243 
244  bool IsActLastColumn(
245  bool bForceDontConsiderHidden = false,
246  sal_uInt16 nAct=USHRT_MAX) const;
247  bool IsActFirstColumn(
248  bool bForceDontConsiderHidden = false,
249  sal_uInt16 nAct=USHRT_MAX) const;
250  sal_uInt16 GetActLeftColumn(
251  bool bForceDontConsiderHidden = false,
252  sal_uInt16 nAct=USHRT_MAX ) const;
253  sal_uInt16 GetActRightColumn (
254  bool bForceDontConsiderHidden = false,
255  sal_uInt16 nAct=USHRT_MAX ) const;
256  long CalcPropMaxRight(sal_uInt16 nCol = USHRT_MAX) const;
257 
258 public:
259 
260  SvxRuler(vcl::Window* pParent, vcl::Window *pEditWin, SvxRulerSupportFlags nRulerFlags,
261  SfxBindings &rBindings, WinBits nWinStyle);
262  virtual ~SvxRuler() override;
263  virtual void dispose() override;
264 
265  void SetDefTabDist(long);
266 
267  // set/get NullOffset in logic units
268  void SetNullOffsetLogic(long lOff);
269 
270  void SetActive(bool bOn = true);
271 
272  void ForceUpdate()
273  {
274  Update();
275  }
276 
277  //#i24363# tab stops relative to indent
278  void SetTabsRelativeToIndent( bool bRel );
279  void SetValues(RulerChangeType type, long value);
280  long GetPageWidth() const;
281 };
282 
283 #endif
284 
285 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
RulerChangeType
Definition: ruler.hxx:44
long nDragOffset
Definition: ruler.hxx:121
SvxRulerSupportFlags
Definition: ruler.hxx:67
SvxRulerDragFlags
Definition: ruler.hxx:50
std::vector< std::unique_ptr< SvxRulerItem > > pCtrlItems
Definition: ruler.hxx:87
std::unique_ptr< SvxLongULSpaceItem > mxULSpaceItem
Definition: ruler.hxx:91
virtual void Click()
bool mbCoarseSnapping
Definition: ruler.hxx:128
std::vector< RulerTab > mpTabs
Definition: ruler.hxx:115
std::unique_ptr< SfxRectangleItem > mxMinMaxItem
Definition: ruler.hxx:90
sal_uInt16 nTabCount
Definition: ruler.hxx:110
bool bValid
Definition: ruler.hxx:124
#define SVX_DLLPUBLIC
Definition: svxdllapi.h:28
virtual void EndDrag()
RulerType
long lInitialDragPos
Definition: ruler.hxx:106
MoveRight
sal_Int64 WinBits
virtual void Drag()
std::unique_ptr< SvxTabStopItem > mxTabStopItem
Definition: ruler.hxx:92
long nMaxLeft
Definition: ruler.hxx:122
MoveLeft
bool mbSnapping
Definition: ruler.hxx:129
long lLogicNullOffset
Definition: ruler.hxx:104
std::vector< RulerBorder > mpObjectBorders
Definition: ruler.hxx:118
VclPtr< vcl::Window > pEditWin
Definition: ruler.hxx:98
std::vector< RulerIndent > mpIndents
Definition: ruler.hxx:116
virtual bool StartDrag()
sal_uInt16 nDefTabType
Definition: ruler.hxx:109
bool bActive
Definition: ruler.hxx:126
sal_uInt16 nTabBufSize
Definition: ruler.hxx:111
std::unique_ptr< SvxPagePosSizeItem > mxPagePosItem
Definition: ruler.hxx:94
SfxBindings * pBindings
Definition: ruler.hxx:120
std::unique_ptr< SvxColumnItem > mxColumnItem
Definition: ruler.hxx:95
UpdateType
Definition: ruler.hxx:224
long lTabPos
Definition: ruler.hxx:113
SvxRulerDragFlags nDragType
Definition: ruler.hxx:108
std::unique_ptr< SvxLRSpaceItem > mxParaItem
Definition: ruler.hxx:93
virtual void Notify(SfxBroadcaster &rBC, const SfxHint &rHint)
long lDefTabDist
Definition: ruler.hxx:112
std::vector< RulerBorder > mpBorders
Definition: ruler.hxx:117
std::unique_ptr< SvxRuler_Impl > mxRulerImpl
Definition: ruler.hxx:100
std::unique_ptr< SvxObjectItem > mxObjectItem
Definition: ruler.hxx:96
std::unique_ptr< SvxLongLRSpaceItem > mxLRSpaceItem
Definition: ruler.hxx:89
virtual void MouseMove(const MouseEvent &rMEvt) override
virtual void dispose() override
SvxRulerSupportFlags nFlags
Definition: ruler.hxx:107
bool bListening
Definition: ruler.hxx:125
long nMaxRight
Definition: ruler.hxx:123
virtual void ExtraDown()
void ForceUpdate()
Definition: ruler.hxx:272
long lAppNullOffset
Definition: ruler.hxx:105