Coverage Report

Created: 2026-02-14 09:37

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/include/svx/ruler.hxx
Line
Count
Source
1
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
/*
3
 * This file is part of the LibreOffice project.
4
 *
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/.
8
 *
9
 * This file incorporates work covered by the following license notice:
10
 *
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 .
18
 */
19
#ifndef INCLUDED_SVX_RULER_HXX
20
#define INCLUDED_SVX_RULER_HXX
21
22
#include <svtools/ruler.hxx>
23
#include <svl/lstner.hxx>
24
#include <svx/svxdllapi.h>
25
#include <o3tl/typed_flags_set.hxx>
26
27
#include <memory>
28
29
class SvxProtectItem;
30
class SvxRulerItem;
31
class SfxBindings;
32
class SvxLongLRSpaceItem;
33
class SvxLongULSpaceItem;
34
class SvxTabStopItem;
35
class SvxLRSpaceItem;
36
class SvxPagePosSizeItem;
37
class SvxColumnItem;
38
class SfxRectangleItem;
39
class SvxObjectItem;
40
class SfxBoolItem;
41
struct SvxRuler_Impl;
42
namespace tools { class JsonWriter; }
43
44
enum class RulerChangeType
45
{
46
    MARGIN1,
47
    MARGIN2
48
};
49
50
enum class SvxRulerDragFlags
51
{
52
    NONE                       = 0x00,
53
    OBJECT                     = 0x01,
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,
61
};
62
namespace o3tl
63
{
64
    template<> struct typed_flags<SvxRulerDragFlags> : is_typed_flags<SvxRulerDragFlags, 0x0f> {};
65
}
66
67
enum class SvxRulerSupportFlags
68
{
69
    TABS                       = 0x0001,
70
    PARAGRAPH_MARGINS          = 0x0002,
71
    BORDERS                    = 0x0004,
72
    OBJECT                     = 0x0008,
73
    SET_NULLOFFSET             = 0x0010,
74
    NEGATIVE_MARGINS           = 0x0020,
75
    PARAGRAPH_MARGINS_VERTICAL = 0x0040,
76
    REDUCED_METRIC             = 0x0080, //shorten the context menu to select metric
77
};
78
namespace o3tl
79
{
80
    template<> struct typed_flags<SvxRulerSupportFlags> : is_typed_flags<SvxRulerSupportFlags, 0x00ff> {};
81
}
82
83
class SVX_DLLPUBLIC SvxRuler: public Ruler, public SfxListener
84
{
85
    friend class SvxRulerItem;
86
87
    std::vector<std::unique_ptr<SvxRulerItem> > pCtrlItems;
88
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
98
99
    VclPtr<vcl::Window>         pEditWin;
100
101
    std::unique_ptr<SvxRuler_Impl> mxRulerImpl;
102
103
    bool            bAppSetNullOffset :1;
104
    bool            bHorz :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;
114
    tools::Long            lTabPos;
115
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;
120
121
    SfxBindings*    pBindings;
122
    tools::Long            nDragOffset;
123
    tools::Long            nMaxLeft;
124
    tools::Long            nMaxRight;
125
    bool            bValid;
126
    bool            bListening;
127
    bool            bActive;
128
129
    bool mbCoarseSnapping;
130
    bool mbSnapping;
131
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;
136
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);
143
    // Border distance
144
    void UpdateBorder(const SvxLRSpaceItem* pItem);
145
    // Tabs
146
    void Update(const SvxTabStopItem* pItem);
147
    // page position and width
148
    void Update(const SvxPagePosSizeItem* pItem);
149
    // columns
150
    void Update(const SvxColumnItem* pItem, sal_uInt16 nSID);
151
    // object selection
152
    void Update(const SvxObjectItem* pItem);
153
    // protect
154
    void Update(const SvxProtectItem* pItem );
155
    // left-to-right text
156
    void UpdateTextRTL(const SfxBoolItem* pItem);
157
    // paragraph indentations
158
    void UpdatePara();
159
    void UpdateTabs();
160
    void UpdatePage();
161
    void UpdateFrame();
162
    void UpdateColumns();
163
    void UpdateObject();
164
165
    void NotifyKit();
166
167
    // Convert position to stick to ruler ticks
168
    tools::Long MakePositionSticky(tools::Long rValue, tools::Long aPointOfReference, bool aSnapToFrameMargin = true) const;
169
170
    tools::Long PixelHAdjust(tools::Long lPos, tools::Long lPos2) const;
171
    tools::Long PixelVAdjust(tools::Long lPos, tools::Long lPos2) const;
172
    tools::Long PixelAdjust(tools::Long lPos, tools::Long lPos2) const;
173
174
    tools::Long ConvertHPosPixel(tools::Long lPos) const;
175
    tools::Long ConvertVPosPixel(tools::Long lPos) const;
176
    tools::Long ConvertHSizePixel(tools::Long lSize) const;
177
    tools::Long ConvertVSizePixel(tools::Long lSize) const;
178
179
    tools::Long ConvertPosPixel(tools::Long lPos) const;
180
    tools::Long ConvertSizePixel(tools::Long lSize) const;
181
182
    tools::Long ConvertHPosLogic(tools::Long lPos) const;
183
    tools::Long ConvertVPosLogic(tools::Long lPos) const;
184
    tools::Long ConvertHSizeLogic(tools::Long lSize) const;
185
    tools::Long ConvertVSizeLogic(tools::Long lSize) const;
186
187
    tools::Long ConvertPosLogic(tools::Long lPos) const;
188
    tools::Long ConvertSizeLogic(tools::Long lSize) const;
189
190
    tools::Long RoundToCurrentMapMode(tools::Long lValue) const;
191
192
    tools::Long GetFirstLineIndent() const;
193
    tools::Long GetLeftIndent() const;
194
    tools::Long GetRightIndent() const;
195
    tools::Long GetLogicRightIndent() const;
196
197
    tools::Long GetLeftFrameMargin() const;
198
    tools::Long GetRightFrameMargin() const;
199
200
    void CalcMinMax();
201
202
    void EvalModifier();
203
    void DragMargin1();
204
    //adjust the left margin either after DragMargin1() or after DragBorders()
205
    void AdjustMargin1(tools::Long lDiff);
206
    void DragMargin2();
207
    void DragIndents();
208
    void DragTabs();
209
    void DragBorders();
210
    void DragObjectBorder();
211
212
    void ApplyMargins();
213
    void ApplyIndents();
214
    void ApplyTabs();
215
    void ApplyBorders();
216
    void ApplyObject();
217
218
    tools::Long GetFrameLeft() const;
219
220
    tools::Long GetLeftMin() const;
221
    tools::Long GetRightMax() const;
222
223
    void TabMenuSelect(std::u16string_view rIdent);
224
    void MenuSelect(std::u16string_view ident);
225
    void PrepareProportional_Impl(RulerType);
226
227
    enum class UpdateType
228
    {
229
        MoveLeft,
230
        MoveRight
231
    };
232
    void UpdateParaContents_Impl(tools::Long lDiff, UpdateType);
233
234
protected:
235
0
    bool isHorizontal() { return bHorz; }
236
237
    virtual void    Command( const CommandEvent& rCEvt ) override;
238
    virtual void    Click() override;
239
    virtual bool    StartDrag() override;
240
    virtual void    Drag() override;
241
    virtual void    EndDrag() override;
242
    virtual void    ExtraDown() override;
243
    virtual void    MouseMove( const MouseEvent& rMEvt ) override;
244
245
    virtual void    Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) override;
246
247
    virtual void    Update();
248
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
    tools::Long CalcPropMaxRight(sal_uInt16 nCol = USHRT_MAX) const;
262
263
public:
264
265
    SvxRuler(vcl::Window* pParent, vcl::Window *pEditWin, SvxRulerSupportFlags nRulerFlags,
266
             SfxBindings &rBindings, WinBits nWinStyle);
267
    virtual ~SvxRuler() override;
268
    virtual void dispose() override;
269
270
    void SetDefTabDist(tools::Long);
271
272
    // set/get NullOffset in logic units
273
    void SetNullOffsetLogic(tools::Long lOff);
274
275
    void SetActive(bool bOn = true);
276
277
    void ForceUpdate()
278
692
    {
279
692
        Update();
280
692
    }
281
282
    void CreateJsonNotification(tools::JsonWriter& rJsonWriter);
283
284
    //#i24363# tab stops relative to indent
285
    void SetTabsRelativeToIndent( bool bRel );
286
    void SetValues(RulerChangeType type, tools::Long value);
287
    tools::Long GetPageWidth() const;
288
};
289
290
#endif
291
292
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */