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
<SvxPagePosSizeItem
> mxPagePosItem
; // page distance to the rule
95 std::unique_ptr
<SvxColumnItem
> mxColumnItem
; // columns
96 std::unique_ptr
<SvxObjectItem
> mxObjectItem
; // object
98 VclPtr
<vcl::Window
> pEditWin
;
100 std::unique_ptr
<SvxRuler_Impl
> mxRulerImpl
;
102 bool bAppSetNullOffset
:1;
104 tools::Long lLogicNullOffset
; // in logic coordinates
105 tools::Long lAppNullOffset
; // in logic coordinates
106 tools::Long lInitialDragPos
;
107 SvxRulerSupportFlags nFlags
;
108 SvxRulerDragFlags nDragType
;
109 sal_uInt16 nDefTabType
;
110 sal_uInt16 nTabCount
;
111 sal_uInt16 nTabBufSize
;
112 tools::Long lDefTabDist
;
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
;
120 SfxBindings
* pBindings
;
121 tools::Long nDragOffset
;
122 tools::Long nMaxLeft
;
123 tools::Long nMaxRight
;
128 bool mbCoarseSnapping
;
131 void StartListening_Impl();
132 tools::Long
GetCorrectedDragPos(bool bLeft
= true, bool bRight
= true );
133 void DrawLine_Impl(tools::Long
&lTabPos
, int, bool Horizontal
);
134 sal_uInt16
GetObjectBordersOff(sal_uInt16 nIdx
) const;
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
);
143 void UpdateParaBorder();
145 void Update(const SvxTabStopItem
* pItem
);
146 // page position and width
147 void Update(const SvxPagePosSizeItem
* pItem
);
149 void Update(const SvxColumnItem
* pItem
, sal_uInt16 nSID
);
151 void Update(const SvxObjectItem
* pItem
);
153 void Update(const SvxProtectItem
* pItem
);
154 // left-to-right text
155 void UpdateTextRTL(const SfxBoolItem
* pItem
);
156 // paragraph indentations
161 void UpdateColumns();
164 // Convert position to stick to ruler ticks
165 tools::Long
MakePositionSticky(tools::Long rValue
, tools::Long aPointOfReference
, bool aSnapToFrameMargin
= true) const;
167 tools::Long
PixelHAdjust(tools::Long lPos
, tools::Long lPos2
) const;
168 tools::Long
PixelVAdjust(tools::Long lPos
, tools::Long lPos2
) const;
169 tools::Long
PixelAdjust(tools::Long lPos
, tools::Long lPos2
) const;
171 tools::Long
ConvertHPosPixel(tools::Long lPos
) const;
172 tools::Long
ConvertVPosPixel(tools::Long lPos
) const;
173 tools::Long
ConvertHSizePixel(tools::Long lSize
) const;
174 tools::Long
ConvertVSizePixel(tools::Long lSize
) const;
176 tools::Long
ConvertPosPixel(tools::Long lPos
) const;
177 tools::Long
ConvertSizePixel(tools::Long lSize
) const;
179 tools::Long
ConvertHPosLogic(tools::Long lPos
) const;
180 tools::Long
ConvertVPosLogic(tools::Long lPos
) const;
181 tools::Long
ConvertHSizeLogic(tools::Long lSize
) const;
182 tools::Long
ConvertVSizeLogic(tools::Long lSize
) const;
184 tools::Long
ConvertPosLogic(tools::Long lPos
) const;
185 tools::Long
ConvertSizeLogic(tools::Long lSize
) const;
187 tools::Long
RoundToCurrentMapMode(tools::Long lValue
) const;
189 tools::Long
GetFirstLineIndent() const;
190 tools::Long
GetLeftIndent() const;
191 tools::Long
GetRightIndent() const;
192 tools::Long
GetLogicRightIndent() const;
194 tools::Long
GetLeftFrameMargin() const;
195 tools::Long
GetRightFrameMargin() const;
201 //adjust the left margin either after DragMargin1() or after DragBorders()
202 void AdjustMargin1(tools::Long lDiff
);
207 void DragObjectBorder();
215 tools::Long
GetFrameLeft() const;
217 tools::Long
GetLeftMin() const;
218 tools::Long
GetRightMax() const;
220 DECL_LINK( TabMenuSelect
, Menu
*, bool );
221 DECL_LINK( MenuSelect
, Menu
*, bool );
222 void PrepareProportional_Impl(RulerType
);
224 enum class UpdateType
229 void UpdateParaContents_Impl(tools::Long lDiff
, UpdateType
);
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
;
240 virtual void Notify( SfxBroadcaster
& rBC
, const SfxHint
& rHint
) override
;
242 virtual void Update();
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 tools::Long
CalcPropMaxRight(sal_uInt16 nCol
= USHRT_MAX
) const;
260 SvxRuler(vcl::Window
* pParent
, vcl::Window
*pEditWin
, SvxRulerSupportFlags nRulerFlags
,
261 SfxBindings
&rBindings
, WinBits nWinStyle
);
262 virtual ~SvxRuler() override
;
263 virtual void dispose() override
;
265 void SetDefTabDist(tools::Long
);
267 // set/get NullOffset in logic units
268 void SetNullOffsetLogic(tools::Long lOff
);
270 void SetActive(bool bOn
= true);
277 //#i24363# tab stops relative to indent
278 void SetTabsRelativeToIndent( bool bRel
);
279 void SetValues(RulerChangeType type
, tools::Long value
);
280 tools::Long
GetPageWidth() const;
282 void MoveTabstop(int nTabstop
, int nAmount
);
287 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */