Coverage Report

Created: 2026-04-09 11:41

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/sc/source/ui/sidebar/CellBorderStyleControl.cxx
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
20
#include "CellBorderStyleControl.hxx"
21
#include <editeng/boxitem.hxx>
22
#include <editeng/borderline.hxx>
23
#include <sfx2/bindings.hxx>
24
#include <sfx2/dispatch.hxx>
25
#include <svx/dialmgr.hxx>
26
#include <svx/strings.hrc>
27
#include <svx/svxids.hrc>
28
#include <vcl/settings.hxx>
29
#include <vcl/weld/Builder.hxx>
30
#include <editeng/lineitem.hxx>
31
#include <svl/itemset.hxx>
32
#include <memory>
33
34
namespace sc::sidebar {
35
36
0
#define FRM_VALID_LEFT      0x01
37
0
#define FRM_VALID_RIGHT     0x02
38
0
#define FRM_VALID_TOP       0x04
39
0
#define FRM_VALID_BOTTOM    0x08
40
0
#define FRM_VALID_HINNER    0x10
41
0
#define FRM_VALID_VINNER    0x20
42
0
#define FRM_VALID_OUTER     0x0f
43
0
#define FRM_VALID_ALL       0xff
44
45
CellBorderStylePopup::CellBorderStylePopup(weld::Toolbar* pParent, const OUString& rId, SfxDispatcher* pDispatcher)
46
0
    : WeldToolbarPopup(nullptr, pParent, u"modules/scalc/ui/floatingborderstyle.ui"_ustr, u"FloatingBorderStyle"_ustr)
47
0
    , maToolButton(pParent, rId)
48
0
    , mpDispatcher(pDispatcher)
49
0
    , mxTBBorder1(m_xBuilder->weld_toolbar(u"border1"_ustr))
50
0
    , mxTBBorder2(m_xBuilder->weld_toolbar(u"border2"_ustr))
51
0
    , mxTBBorder3(m_xBuilder->weld_toolbar(u"border3"_ustr))
52
0
{
53
0
    Initialize();
54
0
}
55
56
void CellBorderStylePopup::GrabFocus()
57
0
{
58
0
    mxTBBorder1->grab_focus();
59
0
}
60
61
CellBorderStylePopup::~CellBorderStylePopup()
62
0
{
63
0
}
64
65
void CellBorderStylePopup::Initialize()
66
0
{
67
0
    mxTBBorder1->connect_clicked ( LINK(this, CellBorderStylePopup, TB1SelectHdl) );
68
0
    mxTBBorder1->set_item_tooltip_text(0, SvxResId(RID_SVXSTR_TABLE_PRESET_NONE));
69
0
    mxTBBorder1->set_item_accessible_name(0, SvxResId(RID_SVXSTR_TABLE_PRESET_NONE));
70
0
    mxTBBorder1->set_item_tooltip_text(1, SvxResId(RID_SVXSTR_TABLE_PRESET_OUTER));
71
0
    mxTBBorder1->set_item_accessible_name(1, SvxResId(RID_SVXSTR_TABLE_PRESET_OUTER));
72
0
    mxTBBorder1->set_item_tooltip_text(2, SvxResId(RID_SVXSTR_TABLE_PRESET_OUTERALL));
73
0
    mxTBBorder1->set_item_accessible_name(2, SvxResId(RID_SVXSTR_TABLE_PRESET_OUTERALL));
74
0
    mxTBBorder1->set_item_tooltip_text(3, SvxResId(RID_SVXSTR_PARA_PRESET_CRISSCROSS));
75
0
    mxTBBorder1->set_item_accessible_name(3, SvxResId(RID_SVXSTR_PARA_PRESET_CRISSCROSS));
76
77
0
    mxTBBorder2->connect_clicked ( LINK(this, CellBorderStylePopup, TB2and3SelectHdl) );
78
0
    mxTBBorder2->set_item_tooltip_text(0, SvxResId(RID_SVXSTR_PARA_PRESET_ONLYLEFT));
79
0
    mxTBBorder2->set_item_accessible_name(0, SvxResId(RID_SVXSTR_PARA_PRESET_ONLYLEFT));
80
0
    mxTBBorder2->set_item_tooltip_text(1, SvxResId(RID_SVXSTR_PARA_PRESET_ONLYRIGHT));
81
0
    mxTBBorder2->set_item_accessible_name(1, SvxResId(RID_SVXSTR_PARA_PRESET_ONLYRIGHT));
82
0
    mxTBBorder2->set_item_tooltip_text(2, SvxResId(RID_SVXSTR_PARA_PRESET_ONLYTOP));
83
0
    mxTBBorder2->set_item_accessible_name(2, SvxResId(RID_SVXSTR_PARA_PRESET_ONLYTOP));
84
0
    mxTBBorder2->set_item_tooltip_text(3, SvxResId(RID_SVXSTR_PARA_PRESET_ONLYBOTTOM));
85
0
    mxTBBorder2->set_item_accessible_name(3, SvxResId(RID_SVXSTR_PARA_PRESET_ONLYBOTTOM));
86
87
0
    mxTBBorder3->connect_clicked ( LINK(this, CellBorderStylePopup, TB2and3SelectHdl) );
88
0
    mxTBBorder3->set_item_tooltip_text(0, SvxResId(RID_SVXSTR_PARA_PRESET_DIAGONALDOWN));
89
0
    mxTBBorder3->set_item_accessible_name(0, SvxResId(RID_SVXSTR_PARA_PRESET_DIAGONALDOWN));
90
0
    mxTBBorder3->set_item_tooltip_text(1, SvxResId(RID_SVXSTR_PARA_PRESET_DIAGONALUP));
91
0
    mxTBBorder3->set_item_accessible_name(1, SvxResId(RID_SVXSTR_PARA_PRESET_DIAGONALUP));
92
0
    mxTBBorder3->set_item_tooltip_text(2, SvxResId(RID_SVXSTR_PARA_PRESET_TOPBOTTOM));
93
0
    mxTBBorder3->set_item_accessible_name(2, SvxResId(RID_SVXSTR_PARA_PRESET_TOPBOTTOM));
94
0
    mxTBBorder3->set_item_tooltip_text(3, SvxResId(RID_SVXSTR_PARA_PRESET_LEFTRIGHT));
95
0
    mxTBBorder3->set_item_accessible_name(3, SvxResId(RID_SVXSTR_PARA_PRESET_LEFTRIGHT));
96
0
}
97
98
IMPL_LINK(CellBorderStylePopup, TB1SelectHdl, const OUString&, rId, void)
99
0
{
100
0
    SvxBoxItem          aBorderOuter( SID_ATTR_BORDER_OUTER );
101
0
    SvxBoxInfoItem      aBorderInner( SID_ATTR_BORDER_INNER );
102
0
    editeng::SvxBorderLine theDefLine(nullptr, SvxBorderLineWidth::Thin);
103
0
    editeng::SvxBorderLine *pLeft = nullptr, *pRight = nullptr, *pTop = nullptr, *pBottom = nullptr;
104
0
    sal_uInt8 nValidFlags = 0;
105
106
0
    if (rId == "none")
107
0
    {
108
0
        nValidFlags |= FRM_VALID_ALL;
109
0
        SvxLineItem     aLineItem1( SID_ATTR_BORDER_DIAG_BLTR );
110
0
        SvxLineItem     aLineItem2( SID_ATTR_BORDER_DIAG_TLBR );
111
0
        aLineItem1.SetLine( nullptr );     //modify
112
0
        aLineItem2.SetLine( nullptr );     //modify
113
0
        mpDispatcher->ExecuteList(
114
0
            SID_ATTR_BORDER_DIAG_BLTR, SfxCallMode::RECORD, { &aLineItem1 });
115
0
        mpDispatcher->ExecuteList(
116
0
            SID_ATTR_BORDER_DIAG_TLBR, SfxCallMode::RECORD, { &aLineItem2 });
117
0
    }
118
0
    else if (rId == "all")
119
0
    {
120
0
        pLeft = pRight = pTop = pBottom = &theDefLine;
121
0
        aBorderInner.SetLine( &theDefLine, SvxBoxInfoItemLine::HORI );
122
0
        aBorderInner.SetLine( &theDefLine, SvxBoxInfoItemLine::VERT );
123
0
        nValidFlags |= FRM_VALID_ALL;
124
0
    }
125
0
    else if (rId == "outside")
126
0
    {
127
0
        pLeft = pRight = pTop = pBottom = &theDefLine;
128
0
        nValidFlags |= FRM_VALID_OUTER;
129
0
    }
130
0
    else if (rId == "crisscross")
131
0
    {
132
0
        editeng::SvxBorderLine aThinLine(nullptr, SvxBorderLineWidth::Thin);
133
0
        SvxLineItem aDiagUpItem(SID_ATTR_BORDER_DIAG_BLTR);
134
0
        aDiagUpItem.SetLine(&aThinLine);
135
0
        SvxLineItem aDiagDownItem(SID_ATTR_BORDER_DIAG_TLBR);
136
0
        aDiagDownItem.SetLine(&aThinLine);
137
0
        mpDispatcher->ExecuteList(SID_ATTR_BORDER_DIAG_BLTR, SfxCallMode::RECORD, { &aDiagUpItem });
138
0
        mpDispatcher->ExecuteList(SID_ATTR_BORDER_DIAG_TLBR, SfxCallMode::RECORD,
139
0
                                  { &aDiagDownItem });
140
0
    }
141
142
0
    aBorderOuter.SetLine( pLeft, SvxBoxItemLine::LEFT );
143
0
    aBorderOuter.SetLine( pRight, SvxBoxItemLine::RIGHT );
144
0
    aBorderOuter.SetLine( pTop, SvxBoxItemLine::TOP );
145
0
    aBorderOuter.SetLine( pBottom, SvxBoxItemLine::BOTTOM );
146
147
0
    aBorderInner.SetValid( SvxBoxInfoItemValidFlags::TOP,       0 != (nValidFlags&FRM_VALID_TOP ));
148
0
    aBorderInner.SetValid( SvxBoxInfoItemValidFlags::BOTTOM,    0 != (nValidFlags&FRM_VALID_BOTTOM ));
149
0
    aBorderInner.SetValid( SvxBoxInfoItemValidFlags::LEFT,      0 != (nValidFlags&FRM_VALID_LEFT));
150
0
    aBorderInner.SetValid( SvxBoxInfoItemValidFlags::RIGHT,     0 != (nValidFlags&FRM_VALID_RIGHT ));
151
0
    aBorderInner.SetValid( SvxBoxInfoItemValidFlags::HORI,      0 != (nValidFlags&FRM_VALID_HINNER ));
152
0
    aBorderInner.SetValid( SvxBoxInfoItemValidFlags::VERT,      0 != (nValidFlags&FRM_VALID_VINNER));
153
0
    aBorderInner.SetValid( SvxBoxInfoItemValidFlags::DISTANCE );
154
0
    aBorderInner.SetValid( SvxBoxInfoItemValidFlags::DISABLE, false );
155
156
0
    mpDispatcher->ExecuteList(
157
0
        SID_ATTR_BORDER, SfxCallMode::RECORD, { &aBorderOuter, &aBorderInner });
158
159
0
    maToolButton.set_inactive();
160
0
}
161
162
IMPL_LINK(CellBorderStylePopup, TB2and3SelectHdl, const OUString&, rId, void)
163
0
{
164
0
    if (rId == "diagup")
165
0
    {
166
0
        editeng::SvxBorderLine aTmp( nullptr, SvxBorderLineWidth::Thin );
167
0
        SvxLineItem     aLineItem( SID_ATTR_BORDER_DIAG_BLTR );
168
0
        aLineItem.SetLine( &aTmp );
169
0
        mpDispatcher->ExecuteList(
170
0
            SID_ATTR_BORDER_DIAG_BLTR, SfxCallMode::RECORD, { &aLineItem });
171
0
    }
172
0
    else if (rId == "diagdown")
173
0
    {
174
0
        editeng::SvxBorderLine aTmp( nullptr, SvxBorderLineWidth::Thin );
175
0
        SvxLineItem     aLineItem( SID_ATTR_BORDER_DIAG_TLBR );
176
0
        aLineItem.SetLine( &aTmp );
177
0
        mpDispatcher->ExecuteList(
178
0
            SID_ATTR_BORDER_DIAG_TLBR, SfxCallMode::RECORD, { &aLineItem });
179
0
    }
180
0
    else
181
0
    {
182
0
        SvxBoxItem          aBorderOuter( SID_ATTR_BORDER_OUTER );
183
0
        SvxBoxInfoItem      aBorderInner( SID_ATTR_BORDER_INNER );
184
0
        editeng::SvxBorderLine theDefLine(nullptr, SvxBorderLineWidth::Thin);
185
0
        editeng::SvxBorderLine       *pLeft = nullptr,
186
0
                            *pRight = nullptr,
187
0
                            *pTop = nullptr,
188
0
                            *pBottom = nullptr;
189
0
        sal_uInt8               nValidFlags = 0;
190
0
        if (rId == "left")
191
0
        {
192
0
            pLeft = &theDefLine;
193
0
            nValidFlags |= FRM_VALID_LEFT;
194
0
        }
195
0
        else if (rId == "right")
196
0
        {
197
0
            if(!AllSettings::GetLayoutRTL())
198
0
            {
199
0
                pRight = &theDefLine;
200
0
                nValidFlags |= FRM_VALID_RIGHT;
201
0
            }
202
0
            else
203
0
            {
204
0
                pLeft = &theDefLine;
205
0
                nValidFlags |= FRM_VALID_LEFT;
206
0
            }
207
0
        }
208
0
        else if (rId == "top")
209
0
        {
210
0
            pTop = &theDefLine;
211
0
            nValidFlags |= FRM_VALID_TOP;
212
0
        }
213
0
        else if (rId == "bottom")
214
0
        {
215
0
            pBottom = &theDefLine;
216
0
            nValidFlags |= FRM_VALID_BOTTOM;
217
0
        }
218
0
        else if (rId == "topbottom")
219
0
        {
220
0
            pTop =  pBottom = &theDefLine;
221
0
            nValidFlags |= FRM_VALID_BOTTOM|FRM_VALID_TOP;
222
0
        }
223
0
        else if (rId == "leftright")
224
0
        {
225
0
            pLeft = pRight = &theDefLine;
226
0
            nValidFlags |=  FRM_VALID_RIGHT|FRM_VALID_LEFT;
227
0
        }
228
0
        aBorderOuter.SetLine( pLeft, SvxBoxItemLine::LEFT );
229
0
        aBorderOuter.SetLine( pRight, SvxBoxItemLine::RIGHT );
230
0
        aBorderOuter.SetLine( pTop, SvxBoxItemLine::TOP );
231
0
        aBorderOuter.SetLine( pBottom, SvxBoxItemLine::BOTTOM );
232
233
0
        aBorderInner.SetValid( SvxBoxInfoItemValidFlags::TOP,       0 != (nValidFlags&FRM_VALID_TOP ));
234
0
        aBorderInner.SetValid( SvxBoxInfoItemValidFlags::BOTTOM,    0 != (nValidFlags&FRM_VALID_BOTTOM ));
235
0
        aBorderInner.SetValid( SvxBoxInfoItemValidFlags::LEFT,      0 != (nValidFlags&FRM_VALID_LEFT));
236
0
        aBorderInner.SetValid( SvxBoxInfoItemValidFlags::RIGHT,     0 != (nValidFlags&FRM_VALID_RIGHT ));
237
0
        aBorderInner.SetValid( SvxBoxInfoItemValidFlags::HORI,      0 != (nValidFlags&FRM_VALID_HINNER ));
238
0
        aBorderInner.SetValid( SvxBoxInfoItemValidFlags::VERT,      0 != (nValidFlags&FRM_VALID_VINNER));
239
0
        aBorderInner.SetValid( SvxBoxInfoItemValidFlags::DISTANCE );
240
0
        aBorderInner.SetValid( SvxBoxInfoItemValidFlags::DISABLE, false );
241
242
0
        mpDispatcher->ExecuteList(
243
0
            SID_ATTR_BORDER, SfxCallMode::RECORD, { &aBorderOuter, &aBorderInner});
244
0
    }
245
246
0
    maToolButton.set_inactive();
247
0
}
248
249
} // end of namespace sc::sidebar
250
251
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */