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 long lLogicNullOffset
; // in logic coordinates
105 long lAppNullOffset
; // in logic coordinates
106 long lInitialDragPos
;
107 SvxRulerSupportFlags
const nFlags
;
108 SvxRulerDragFlags nDragType
;
109 sal_uInt16 nDefTabType
;
110 sal_uInt16 nTabCount
;
111 sal_uInt16 nTabBufSize
;
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
;
128 bool mbCoarseSnapping
;
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;
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 long MakePositionSticky(long rValue
, long aPointOfReference
, bool aSnapToFrameMargin
= true) const;
167 long PixelHAdjust(long lPos
, long lPos2
) const;
168 long PixelVAdjust(long lPos
, long lPos2
) const;
169 long PixelAdjust(long lPos
, long lPos2
) const;
171 long ConvertHPosPixel(long lPos
) const;
172 long ConvertVPosPixel(long lPos
) const;
173 long ConvertHSizePixel(long lSize
) const;
174 long ConvertVSizePixel(long lSize
) const;
176 long ConvertPosPixel(long lPos
) const;
177 long ConvertSizePixel(long lSize
) const;
179 long ConvertHPosLogic(long lPos
) const;
180 long ConvertVPosLogic(long lPos
) const;
181 long ConvertHSizeLogic(long lSize
) const;
182 long ConvertVSizeLogic(long lSize
) const;
184 long ConvertPosLogic(long lPos
) const;
185 long ConvertSizeLogic(long lSize
) const;
187 long RoundToCurrentMapMode(long lValue
) const;
189 long GetFirstLineIndent() const;
190 long GetLeftIndent() const;
191 long GetRightIndent() const;
192 long GetLogicRightIndent() const;
194 long GetLeftFrameMargin() const;
195 long GetRightFrameMargin() const;
201 //adjust the left margin either after DragMargin1() or after DragBorders()
202 void AdjustMargin1(long lDiff
);
207 void DragObjectBorder();
215 long GetFrameLeft() const;
217 long GetLeftMin() const;
218 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(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 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(long);
267 // set/get NullOffset in logic units
268 void SetNullOffsetLogic(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
, long value
);
280 long GetPageWidth() const;
282 void MoveTabstop(int nTabstop
, int nAmount
);
287 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */