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 <vcl/menu.hxx>
23 #include <svtools/ruler.hxx>
24 #include <svl/lstner.hxx>
25 #include <svx/svxdllapi.h>
26 #include <o3tl/typed_flags_set.hxx>
28 #include <boost/scoped_array.hpp>
34 class SvxLongLRSpaceItem
;
35 class SvxLongULSpaceItem
;
38 class SvxPagePosSizeItem
;
40 class SfxRectangleItem
;
45 enum class SvxRulerDragFlags
49 // reduce size of the last column, shift
50 OBJECT_SIZE_LINEAR
= 0x02,
51 OBJECT_SIZE_PROPORTIONAL
= 0x04, // proportional, Ctrl
52 // only current line (table; Shift-Ctrl)
53 OBJECT_ACTLINE_ONLY
= 0x08,
54 // currently same key assignment
55 OBJECT_LEFT_INDENT_ONLY
= OBJECT_SIZE_PROPORTIONAL
,
59 template<> struct typed_flags
<SvxRulerDragFlags
> : is_typed_flags
<SvxRulerDragFlags
, 0x0f> {};
62 enum class SvxRulerSupportFlags
65 PARAGRAPH_MARGINS
= 0x0002,
68 SET_NULLOFFSET
= 0x0010,
69 NEGATIVE_MARGINS
= 0x0020,
70 PARAGRAPH_MARGINS_VERTICAL
= 0x0040,
71 REDUCED_METRIC
= 0x0080, //shorten the context menu to select metric
75 template<> struct typed_flags
<SvxRulerSupportFlags
> : is_typed_flags
<SvxRulerSupportFlags
, 0x00ff> {};
78 class SVX_DLLPUBLIC SvxRuler
: public Ruler
, public SfxListener
80 friend class SvxRulerItem
;
83 SvxRulerItem
** pCtrlItem
;
84 std::unique_ptr
<SvxLongLRSpaceItem
> mxLRSpaceItem
; // left and right edge
85 std::unique_ptr
<SfxRectangleItem
> mxMinMaxItem
; // maxima for dragging
86 std::unique_ptr
<SvxLongULSpaceItem
> mxULSpaceItem
; // upper and lower edge
87 std::unique_ptr
<SvxTabStopItem
> mxTabStopItem
; // tab stops
88 std::unique_ptr
<SvxLRSpaceItem
> mxParaItem
; // paragraphs
89 std::unique_ptr
<SvxLRSpaceItem
> mxParaBorderItem
; // border distance
90 std::unique_ptr
<SvxPagePosSizeItem
> mxPagePosItem
; // page distance to the rule
91 std::unique_ptr
<SvxColumnItem
> mxColumnItem
; // columns
92 std::unique_ptr
<SvxObjectItem
> mxObjectItem
; // object
94 VclPtr
<vcl::Window
> pEditWin
;
96 std::unique_ptr
<SvxRuler_Impl
> mxRulerImpl
;
98 bool bAppSetNullOffset
:1;
100 long lLogicNullOffset
; // in logic coordinates
101 long lAppNullOffset
; // in logic coordinates
102 long lMinFrame
; // minimal frame width in pixels
103 long lInitialDragPos
;
104 SvxRulerSupportFlags nFlags
;
105 SvxRulerDragFlags nDragType
;
106 sal_uInt16 nDefTabType
;
107 sal_uInt16 nTabCount
;
108 sal_uInt16 nTabBufSize
;
112 std::vector
<RulerTab
> mpTabs
; // tab positions in pixel
113 std::vector
<RulerIndent
> mpIndents
; // paragraph margins in pixel
114 std::vector
<RulerBorder
> mpBorders
;
115 std::vector
<RulerBorder
> mpObjectBorders
;
117 SfxBindings
* pBindings
;
125 bool mbCoarseSnapping
;
128 void StartListening_Impl();
129 long GetCorrectedDragPos(bool bLeft
= true, bool bRight
= true );
130 void DrawLine_Impl(long &lTabPos
, int, bool Horizontal
= true);
131 sal_uInt16
GetObjectBordersOff(sal_uInt16 nIdx
) const;
133 // page borders or surrounding frame
134 void UpdateFrame(const SvxLongLRSpaceItem
* pItem
);
135 void UpdateFrame(const SvxLongULSpaceItem
* pItem
);
136 void UpdateFrameMinMax(const SfxRectangleItem
* pItem
);
137 // paragraph indentations
138 void UpdatePara(const SvxLRSpaceItem
* pItem
);
140 void UpdateParaBorder(const SvxLRSpaceItem
* pItem
);
142 void Update(const SvxTabStopItem
* pItem
);
143 // page position and width
144 void Update(const SvxPagePosSizeItem
* pItem
);
146 void Update(const SvxColumnItem
* pItem
, sal_uInt16 nSID
);
148 void Update(const SvxObjectItem
* pItem
);
150 void Update(const SvxProtectItem
* pItem
);
151 // left-to-right text
152 void UpdateTextRTL(const SfxBoolItem
* pItem
);
153 // paragraph indentations
158 void UpdateColumns();
161 // Convert position to stick to ruler ticks
162 long MakePositionSticky(long rValue
, long aPointOfReference
, bool aSnapToFrameMargin
= true) const;
164 long PixelHAdjust(long lPos
, long lPos2
) const;
165 long PixelVAdjust(long lPos
, long lPos2
) const;
166 long PixelAdjust(long lPos
, long lPos2
) const;
168 long ConvertHPosPixel(long lPos
) const;
169 long ConvertVPosPixel(long lPos
) const;
170 long ConvertHSizePixel(long lSize
) const;
171 long ConvertVSizePixel(long lSize
) const;
173 long ConvertPosPixel(long lPos
) const;
174 long ConvertSizePixel(long lSize
) const;
176 long ConvertHPosLogic(long lPos
) const;
177 long ConvertVPosLogic(long lPos
) const;
178 long ConvertHSizeLogic(long lSize
) const;
179 long ConvertVSizeLogic(long lSize
) const;
181 long ConvertPosLogic(long lPos
) const;
182 long ConvertSizeLogic(long lSize
) const;
184 long RoundToCurrentMapMode(long lValue
) const;
186 long GetFirstLineIndent() const;
187 long GetLeftIndent() const;
188 long GetRightIndent() const;
189 long GetLogicRightIndent() const;
191 long GetLeftFrameMargin() const;
192 long GetRightFrameMargin() const;
198 //adjust the left margin either after DragMargin1() or after DragBorders()
199 void AdjustMargin1(long lDiff
);
204 void DragObjectBorder();
212 long GetFrameLeft() const;
213 void SetFrameLeft(long);
215 long GetLeftMin() const;
216 long GetRightMax() const;
218 DECL_LINK( TabMenuSelect
, Menu
* );
219 DECL_LINK( MenuSelect
, Menu
* );
220 void PrepareProportional_Impl(RulerType
);
222 sal_uInt16
GetNextVisible(sal_uInt16 nColumn
);
223 sal_uInt16
GetPrevVisible(sal_uInt16 nColumn
);
231 void UpdateParaContents_Impl(long lDiff
, UpdateType
= MOVE_ALL
);
234 virtual void Command( const CommandEvent
& rCEvt
) SAL_OVERRIDE
;
235 virtual void Click() SAL_OVERRIDE
;
236 virtual bool StartDrag() SAL_OVERRIDE
;
237 virtual void Drag() SAL_OVERRIDE
;
238 virtual void EndDrag() SAL_OVERRIDE
;
239 virtual void ExtraDown() SAL_OVERRIDE
;
240 virtual void MouseMove( const MouseEvent
& rMEvt
) SAL_OVERRIDE
;
242 virtual void Notify( SfxBroadcaster
& rBC
, const SfxHint
& rHint
) SAL_OVERRIDE
;
244 virtual void Update();
246 // calculation of boundary values for object borders
247 // values refer to the page
248 static bool CalcLimits(long &nMax1
, long &nMax2
, bool bFirst
);
249 bool IsActLastColumn(
250 bool bForceDontConsiderHidden
= false,
251 sal_uInt16 nAct
=USHRT_MAX
) const;
252 bool IsActFirstColumn(
253 bool bForceDontConsiderHidden
= false,
254 sal_uInt16 nAct
=USHRT_MAX
) const;
255 sal_uInt16
GetActLeftColumn(
256 bool bForceDontConsiderHidden
= false,
257 sal_uInt16 nAct
=USHRT_MAX
) const;
258 sal_uInt16
GetActRightColumn (
259 bool bForceDontConsiderHidden
= false,
260 sal_uInt16 nAct
=USHRT_MAX
) const;
261 long CalcPropMaxRight(sal_uInt16 nCol
= USHRT_MAX
) const;
262 long GetPageWidth() const;
266 SvxRuler(vcl::Window
* pParent
, vcl::Window
*pEditWin
, SvxRulerSupportFlags nRulerFlags
,
267 SfxBindings
&rBindings
, WinBits nWinStyle
= WB_STDRULER
);
269 virtual void dispose() SAL_OVERRIDE
;
271 void SetMinFrameSize(long lSize
);
272 long GetMinFrameSize() const ;
274 SvxRulerSupportFlags
GetRulerFlags() const
279 void SetDefTabDist(long);
281 // set/get NullOffset in logic units
282 void SetNullOffsetLogic(long lOff
= 0);
283 long GetNullOffsetLogic() const
285 return lAppNullOffset
;
288 void SetActive(bool bOn
= true);
289 bool IsActive() const
299 //#i24363# tab stops relative to indent
300 void SetTabsRelativeToIndent( bool bRel
= true );
305 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */