1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 #ifndef INCLUDED_SVX_RULER_HXX
20 #define INCLUDED_SVX_RULER_HXX
22 #include <svtools/ruler.hxx>
23 #include <svl/lstner.hxx>
24 #include <svx/svxdllapi.h>
25 #include <o3tl/typed_flags_set.hxx>
33 class SvxLongLRSpaceItem
;
34 class SvxLongULSpaceItem
;
37 class SvxPagePosSizeItem
;
39 class SfxRectangleItem
;
44 enum class RulerChangeType
50 enum class SvxRulerDragFlags
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
60 OBJECT_LEFT_INDENT_ONLY
= OBJECT_SIZE_PROPORTIONAL
,
64 template<> struct typed_flags
<SvxRulerDragFlags
> : is_typed_flags
<SvxRulerDragFlags
, 0x0f> {};
67 enum class SvxRulerSupportFlags
70 PARAGRAPH_MARGINS
= 0x0002,
73 SET_NULLOFFSET
= 0x0010,
74 NEGATIVE_MARGINS
= 0x0020,
75 PARAGRAPH_MARGINS_VERTICAL
= 0x0040,
76 REDUCED_METRIC
= 0x0080, //shorten the context menu to select metric
80 template<> struct typed_flags
<SvxRulerSupportFlags
> : is_typed_flags
<SvxRulerSupportFlags
, 0x00ff> {};
83 class SVX_DLLPUBLIC SvxRuler
: public Ruler
, public SfxListener
85 friend class SvxRulerItem
;
87 std::vector
<std::unique_ptr
<SvxRulerItem
> > pCtrlItems
;
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
<SvxLRSpaceItem
> mxParaBorderItem
; // border distance
95 std::unique_ptr
<SvxPagePosSizeItem
> mxPagePosItem
; // page distance to the rule
96 std::unique_ptr
<SvxColumnItem
> mxColumnItem
; // columns
97 std::unique_ptr
<SvxObjectItem
> mxObjectItem
; // object
99 VclPtr
<vcl::Window
> pEditWin
;
101 std::unique_ptr
<SvxRuler_Impl
> mxRulerImpl
;
103 bool bAppSetNullOffset
:1;
105 long lLogicNullOffset
; // in logic coordinates
106 long lAppNullOffset
; // in logic coordinates
107 long lInitialDragPos
;
108 SvxRulerSupportFlags
const nFlags
;
109 SvxRulerDragFlags nDragType
;
110 sal_uInt16 nDefTabType
;
111 sal_uInt16 nTabCount
;
112 sal_uInt16 nTabBufSize
;
116 std::vector
<RulerTab
> mpTabs
; // tab positions in pixel
117 std::vector
<RulerIndent
> mpIndents
; // paragraph margins in pixel
118 std::vector
<RulerBorder
> mpBorders
;
119 std::vector
<RulerBorder
> mpObjectBorders
;
121 SfxBindings
* pBindings
;
129 bool mbCoarseSnapping
;
132 void StartListening_Impl();
133 long GetCorrectedDragPos(bool bLeft
= true, bool bRight
= true );
134 void DrawLine_Impl(long &lTabPos
, int, bool Horizontal
);
135 sal_uInt16
GetObjectBordersOff(sal_uInt16 nIdx
) const;
137 // page borders or surrounding frame
138 void UpdateFrame(const SvxLongLRSpaceItem
* pItem
);
139 void UpdateFrame(const SvxLongULSpaceItem
* pItem
);
140 void UpdateFrameMinMax(const SfxRectangleItem
* pItem
);
141 // paragraph indentations
142 void UpdatePara(const SvxLRSpaceItem
* pItem
);
144 void UpdateParaBorder(const SvxLRSpaceItem
* pItem
);
146 void Update(const SvxTabStopItem
* pItem
);
147 // page position and width
148 void Update(const SvxPagePosSizeItem
* pItem
);
150 void Update(const SvxColumnItem
* pItem
, sal_uInt16 nSID
);
152 void Update(const SvxObjectItem
* pItem
);
154 void Update(const SvxProtectItem
* pItem
);
155 // left-to-right text
156 void UpdateTextRTL(const SfxBoolItem
* pItem
);
157 // paragraph indentations
162 void UpdateColumns();
165 // Convert position to stick to ruler ticks
166 long MakePositionSticky(long rValue
, long aPointOfReference
, bool aSnapToFrameMargin
= true) const;
168 long PixelHAdjust(long lPos
, long lPos2
) const;
169 long PixelVAdjust(long lPos
, long lPos2
) const;
170 long PixelAdjust(long lPos
, long lPos2
) const;
172 long ConvertHPosPixel(long lPos
) const;
173 long ConvertVPosPixel(long lPos
) const;
174 long ConvertHSizePixel(long lSize
) const;
175 long ConvertVSizePixel(long lSize
) const;
177 long ConvertPosPixel(long lPos
) const;
178 long ConvertSizePixel(long lSize
) const;
180 long ConvertHPosLogic(long lPos
) const;
181 long ConvertVPosLogic(long lPos
) const;
182 long ConvertHSizeLogic(long lSize
) const;
183 long ConvertVSizeLogic(long lSize
) const;
185 long ConvertPosLogic(long lPos
) const;
186 long ConvertSizeLogic(long lSize
) const;
188 long RoundToCurrentMapMode(long lValue
) const;
190 long GetFirstLineIndent() const;
191 long GetLeftIndent() const;
192 long GetRightIndent() const;
193 long GetLogicRightIndent() const;
195 long GetLeftFrameMargin() const;
196 long GetRightFrameMargin() const;
202 //adjust the left margin either after DragMargin1() or after DragBorders()
203 void AdjustMargin1(long lDiff
);
208 void DragObjectBorder();
216 long GetFrameLeft() const;
218 long GetLeftMin() const;
219 long GetRightMax() const;
221 DECL_LINK( TabMenuSelect
, Menu
*, bool );
222 DECL_LINK( MenuSelect
, Menu
*, bool );
223 void PrepareProportional_Impl(RulerType
);
225 enum class UpdateType
230 void UpdateParaContents_Impl(long lDiff
, UpdateType
);
233 virtual void Command( const CommandEvent
& rCEvt
) override
;
234 virtual void Click() override
;
235 virtual bool StartDrag() override
;
236 virtual void Drag() override
;
237 virtual void EndDrag() override
;
238 virtual void ExtraDown() override
;
239 virtual void MouseMove( const MouseEvent
& rMEvt
) override
;
241 virtual void Notify( SfxBroadcaster
& rBC
, const SfxHint
& rHint
) override
;
243 virtual void Update();
245 bool IsActLastColumn(
246 bool bForceDontConsiderHidden
= false,
247 sal_uInt16 nAct
=USHRT_MAX
) const;
248 bool IsActFirstColumn(
249 bool bForceDontConsiderHidden
= false,
250 sal_uInt16 nAct
=USHRT_MAX
) const;
251 sal_uInt16
GetActLeftColumn(
252 bool bForceDontConsiderHidden
= false,
253 sal_uInt16 nAct
=USHRT_MAX
) const;
254 sal_uInt16
GetActRightColumn (
255 bool bForceDontConsiderHidden
= false,
256 sal_uInt16 nAct
=USHRT_MAX
) const;
257 long CalcPropMaxRight(sal_uInt16 nCol
= USHRT_MAX
) const;
261 SvxRuler(vcl::Window
* pParent
, vcl::Window
*pEditWin
, SvxRulerSupportFlags nRulerFlags
,
262 SfxBindings
&rBindings
, WinBits nWinStyle
);
263 virtual ~SvxRuler() override
;
264 virtual void dispose() override
;
266 void SetDefTabDist(long);
268 // set/get NullOffset in logic units
269 void SetNullOffsetLogic(long lOff
);
271 void SetActive(bool bOn
= true);
278 //#i24363# tab stops relative to indent
279 void SetTabsRelativeToIndent( bool bRel
);
280 void SetValues(RulerChangeType type
, long value
);
281 long GetPageWidth() const;
286 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */