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
> mxBorderItem
; // 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 tools::Long lLogicNullOffset
; // in logic coordinates
106 tools::Long lAppNullOffset
; // in logic coordinates
107 tools::Long lInitialDragPos
;
108 SvxRulerSupportFlags nFlags
;
109 SvxRulerDragFlags nDragType
;
110 sal_uInt16 nDefTabType
;
111 sal_uInt16 nTabCount
;
112 sal_uInt16 nTabBufSize
;
113 tools::Long lDefTabDist
;
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
;
122 tools::Long nDragOffset
;
123 tools::Long nMaxLeft
;
124 tools::Long nMaxRight
;
129 bool mbCoarseSnapping
;
132 void StartListening_Impl();
133 tools::Long
GetCorrectedDragPos(bool bLeft
= true, bool bRight
= true );
134 void DrawLine_Impl(tools::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 UpdateBorder(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 tools::Long
MakePositionSticky(tools::Long rValue
, tools::Long aPointOfReference
, bool aSnapToFrameMargin
= true) const;
168 tools::Long
PixelHAdjust(tools::Long lPos
, tools::Long lPos2
) const;
169 tools::Long
PixelVAdjust(tools::Long lPos
, tools::Long lPos2
) const;
170 tools::Long
PixelAdjust(tools::Long lPos
, tools::Long lPos2
) const;
172 tools::Long
ConvertHPosPixel(tools::Long lPos
) const;
173 tools::Long
ConvertVPosPixel(tools::Long lPos
) const;
174 tools::Long
ConvertHSizePixel(tools::Long lSize
) const;
175 tools::Long
ConvertVSizePixel(tools::Long lSize
) const;
177 tools::Long
ConvertPosPixel(tools::Long lPos
) const;
178 tools::Long
ConvertSizePixel(tools::Long lSize
) const;
180 tools::Long
ConvertHPosLogic(tools::Long lPos
) const;
181 tools::Long
ConvertVPosLogic(tools::Long lPos
) const;
182 tools::Long
ConvertHSizeLogic(tools::Long lSize
) const;
183 tools::Long
ConvertVSizeLogic(tools::Long lSize
) const;
185 tools::Long
ConvertPosLogic(tools::Long lPos
) const;
186 tools::Long
ConvertSizeLogic(tools::Long lSize
) const;
188 tools::Long
RoundToCurrentMapMode(tools::Long lValue
) const;
190 tools::Long
GetFirstLineIndent() const;
191 tools::Long
GetLeftIndent() const;
192 tools::Long
GetRightIndent() const;
193 tools::Long
GetLogicRightIndent() const;
195 tools::Long
GetLeftFrameMargin() const;
196 tools::Long
GetRightFrameMargin() const;
202 //adjust the left margin either after DragMargin1() or after DragBorders()
203 void AdjustMargin1(tools::Long lDiff
);
208 void DragObjectBorder();
216 tools::Long
GetFrameLeft() const;
218 tools::Long
GetLeftMin() const;
219 tools::Long
GetRightMax() const;
221 void TabMenuSelect(std::u16string_view rIdent
);
222 void MenuSelect(std::u16string_view ident
);
223 void PrepareProportional_Impl(RulerType
);
225 enum class UpdateType
230 void UpdateParaContents_Impl(tools::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 tools::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(tools::Long
);
268 // set/get NullOffset in logic units
269 void SetNullOffsetLogic(tools::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
, tools::Long value
);
281 tools::Long
GetPageWidth() const;
286 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */