LibreOffice Module sc (master) 1
CellBorderStyleControl.cxx
Go to the documentation of this file.
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
21#include <editeng/boxitem.hxx>
23#include <sfx2/bindings.hxx>
24#include <sfx2/dispatch.hxx>
25#include <svx/svxids.hrc>
26#include <vcl/settings.hxx>
27#include <editeng/lineitem.hxx>
28#include <memory>
29
30namespace sc::sidebar {
31
32#define FRM_VALID_LEFT 0x01
33#define FRM_VALID_RIGHT 0x02
34#define FRM_VALID_TOP 0x04
35#define FRM_VALID_BOTTOM 0x08
36#define FRM_VALID_HINNER 0x10
37#define FRM_VALID_VINNER 0x20
38#define FRM_VALID_OUTER 0x0f
39#define FRM_VALID_ALL 0xff
40
42 : WeldToolbarPopup(nullptr, pParent, "modules/scalc/ui/floatingborderstyle.ui", "FloatingBorderStyle")
43 , maToolButton(pParent, rId)
44 , mpDispatcher(pDispatcher)
45 , mxTBBorder1(m_xBuilder->weld_toolbar("border1"))
46 , mxTBBorder2(m_xBuilder->weld_toolbar("border2"))
47 , mxTBBorder3(m_xBuilder->weld_toolbar("border3"))
48 , mxTBBorder4(m_xBuilder->weld_toolbar("border4"))
49{
50 Initialize();
51}
52
54{
55 mxTBBorder1->grab_focus();
56}
57
59{
60}
61
63{
64 mxTBBorder1->connect_clicked ( LINK(this, CellBorderStylePopup, TB1SelectHdl) );
65
66 mxTBBorder2->connect_clicked ( LINK(this, CellBorderStylePopup, TB2and3SelectHdl) );
67 mxTBBorder3->connect_clicked ( LINK(this, CellBorderStylePopup, TB2and3SelectHdl) );
68
69 mxTBBorder4->connect_clicked ( LINK(this, CellBorderStylePopup, TB4SelectHdl) );
70}
71
72IMPL_LINK(CellBorderStylePopup, TB1SelectHdl, const OUString&, rId, void)
73{
74 SvxBoxItem aBorderOuter( SID_ATTR_BORDER_OUTER );
75 SvxBoxInfoItem aBorderInner( SID_ATTR_BORDER_INNER );
77 editeng::SvxBorderLine *pLeft = nullptr, *pRight = nullptr, *pTop = nullptr, *pBottom = nullptr;
78 sal_uInt8 nValidFlags = 0;
79
80 if (rId == "none")
81 {
82 nValidFlags |= FRM_VALID_ALL;
83 SvxLineItem aLineItem1( SID_ATTR_BORDER_DIAG_BLTR );
84 SvxLineItem aLineItem2( SID_ATTR_BORDER_DIAG_TLBR );
85 aLineItem1.SetLine( nullptr ); //modify
86 aLineItem2.SetLine( nullptr ); //modify
87 mpDispatcher->ExecuteList(
88 SID_ATTR_BORDER_DIAG_BLTR, SfxCallMode::RECORD, { &aLineItem1 });
89 mpDispatcher->ExecuteList(
90 SID_ATTR_BORDER_DIAG_TLBR, SfxCallMode::RECORD, { &aLineItem2 });
91 }
92 else if (rId == "all")
93 {
94 pLeft = pRight = pTop = pBottom = &theDefLine;
95 aBorderInner.SetLine( &theDefLine, SvxBoxInfoItemLine::HORI );
96 aBorderInner.SetLine( &theDefLine, SvxBoxInfoItemLine::VERT );
97 nValidFlags |= FRM_VALID_ALL;
98 }
99 else if (rId == "outside")
100 {
101 pLeft = pRight = pTop = pBottom = &theDefLine;
102 nValidFlags |= FRM_VALID_OUTER;
103 }
104 else if (rId == "thickbox")
105 {
107 pLeft = pRight = pTop = pBottom = &theDefLine;
108 nValidFlags |= FRM_VALID_OUTER;
109 }
110
111 aBorderOuter.SetLine( pLeft, SvxBoxItemLine::LEFT );
112 aBorderOuter.SetLine( pRight, SvxBoxItemLine::RIGHT );
113 aBorderOuter.SetLine( pTop, SvxBoxItemLine::TOP );
114 aBorderOuter.SetLine( pBottom, SvxBoxItemLine::BOTTOM );
115
116 aBorderInner.SetValid( SvxBoxInfoItemValidFlags::TOP, 0 != (nValidFlags&FRM_VALID_TOP ));
117 aBorderInner.SetValid( SvxBoxInfoItemValidFlags::BOTTOM, 0 != (nValidFlags&FRM_VALID_BOTTOM ));
118 aBorderInner.SetValid( SvxBoxInfoItemValidFlags::LEFT, 0 != (nValidFlags&FRM_VALID_LEFT));
119 aBorderInner.SetValid( SvxBoxInfoItemValidFlags::RIGHT, 0 != (nValidFlags&FRM_VALID_RIGHT ));
120 aBorderInner.SetValid( SvxBoxInfoItemValidFlags::HORI, 0 != (nValidFlags&FRM_VALID_HINNER ));
121 aBorderInner.SetValid( SvxBoxInfoItemValidFlags::VERT, 0 != (nValidFlags&FRM_VALID_VINNER));
122 aBorderInner.SetValid( SvxBoxInfoItemValidFlags::DISTANCE );
123 aBorderInner.SetValid( SvxBoxInfoItemValidFlags::DISABLE, false );
124
125 mpDispatcher->ExecuteList(
126 SID_ATTR_BORDER, SfxCallMode::RECORD, { &aBorderOuter, &aBorderInner });
127
128 maToolButton.set_inactive();
129}
130
131IMPL_LINK(CellBorderStylePopup, TB2and3SelectHdl, const OUString&, rId, void)
132{
133 if (rId == "diagup")
134 {
136 SvxLineItem aLineItem( SID_ATTR_BORDER_DIAG_BLTR );
137 aLineItem.SetLine( &aTmp );
138 mpDispatcher->ExecuteList(
139 SID_ATTR_BORDER_DIAG_BLTR, SfxCallMode::RECORD, { &aLineItem });
140 }
141 else if (rId == "diagdown")
142 {
144 SvxLineItem aLineItem( SID_ATTR_BORDER_DIAG_TLBR );
145 aLineItem.SetLine( &aTmp );
146 mpDispatcher->ExecuteList(
147 SID_ATTR_BORDER_DIAG_TLBR, SfxCallMode::RECORD, { &aLineItem });
148 }
149 else
150 {
151 SvxBoxItem aBorderOuter( SID_ATTR_BORDER_OUTER );
152 SvxBoxInfoItem aBorderInner( SID_ATTR_BORDER_INNER );
154 editeng::SvxBorderLine *pLeft = nullptr,
155 *pRight = nullptr,
156 *pTop = nullptr,
157 *pBottom = nullptr;
158 sal_uInt8 nValidFlags = 0;
159 if (rId == "left")
160 {
161 pLeft = &theDefLine;
162 nValidFlags |= FRM_VALID_LEFT;
163 }
164 else if (rId == "right")
165 {
167 {
168 pRight = &theDefLine;
169 nValidFlags |= FRM_VALID_RIGHT;
170 }
171 else
172 {
173 pLeft = &theDefLine;
174 nValidFlags |= FRM_VALID_LEFT;
175 }
176 }
177 else if (rId == "top")
178 {
179 pTop = &theDefLine;
180 nValidFlags |= FRM_VALID_TOP;
181 }
182 else if (rId == "bottom")
183 {
184 pBottom = &theDefLine;
185 nValidFlags |= FRM_VALID_BOTTOM;
186 }
187 else if (rId == "topbottom")
188 {
189 pTop = pBottom = &theDefLine;
190 nValidFlags |= FRM_VALID_BOTTOM|FRM_VALID_TOP;
191 }
192 else if (rId == "leftright")
193 {
194 pLeft = pRight = &theDefLine;
195 nValidFlags |= FRM_VALID_RIGHT|FRM_VALID_LEFT;
196 }
197 aBorderOuter.SetLine( pLeft, SvxBoxItemLine::LEFT );
198 aBorderOuter.SetLine( pRight, SvxBoxItemLine::RIGHT );
199 aBorderOuter.SetLine( pTop, SvxBoxItemLine::TOP );
200 aBorderOuter.SetLine( pBottom, SvxBoxItemLine::BOTTOM );
201
202 aBorderInner.SetValid( SvxBoxInfoItemValidFlags::TOP, 0 != (nValidFlags&FRM_VALID_TOP ));
203 aBorderInner.SetValid( SvxBoxInfoItemValidFlags::BOTTOM, 0 != (nValidFlags&FRM_VALID_BOTTOM ));
204 aBorderInner.SetValid( SvxBoxInfoItemValidFlags::LEFT, 0 != (nValidFlags&FRM_VALID_LEFT));
205 aBorderInner.SetValid( SvxBoxInfoItemValidFlags::RIGHT, 0 != (nValidFlags&FRM_VALID_RIGHT ));
206 aBorderInner.SetValid( SvxBoxInfoItemValidFlags::HORI, 0 != (nValidFlags&FRM_VALID_HINNER ));
207 aBorderInner.SetValid( SvxBoxInfoItemValidFlags::VERT, 0 != (nValidFlags&FRM_VALID_VINNER));
208 aBorderInner.SetValid( SvxBoxInfoItemValidFlags::DISTANCE );
209 aBorderInner.SetValid( SvxBoxInfoItemValidFlags::DISABLE, false );
210
211 mpDispatcher->ExecuteList(
212 SID_ATTR_BORDER, SfxCallMode::RECORD, { &aBorderOuter, &aBorderInner});
213 }
214
215 maToolButton.set_inactive();
216}
217
218IMPL_LINK(CellBorderStylePopup, TB4SelectHdl, const OUString&, rId, void)
219{
220 SvxBoxItem aBorderOuter( SID_ATTR_BORDER_OUTER );
221 SvxBoxInfoItem aBorderInner( SID_ATTR_BORDER_INNER );
222 std::unique_ptr<editeng::SvxBorderLine> pTop;
223 std::unique_ptr<editeng::SvxBorderLine> pBottom;
224 sal_uInt8 nValidFlags = 0;
225 using namespace ::com::sun::star::table::BorderLineStyle;
226
227 //FIXME: properly adapt to new line border model
228
229 if (rId == "thickbottom")
230 {
231 pBottom.reset(new editeng::SvxBorderLine(nullptr, SvxBorderLineWidth::Thick));
232 nValidFlags |= FRM_VALID_BOTTOM;
233 }
234 else if (rId == "doublebottom")
235 {
236 pBottom.reset(new editeng::SvxBorderLine(nullptr));
237 pBottom->GuessLinesWidths(SvxBorderLineStyle::DOUBLE, SvxBorderLineWidth::Hairline,
239 nValidFlags |= FRM_VALID_BOTTOM;
240 }
241 else if (rId == "topthickbottom")
242 {
243 pBottom.reset(new editeng::SvxBorderLine(nullptr, SvxBorderLineWidth::Thick));
244 pTop.reset(new editeng::SvxBorderLine(nullptr, SvxBorderLineWidth::Thin));
245 nValidFlags |= FRM_VALID_BOTTOM|FRM_VALID_TOP;
246 }
247 else if (rId == "topdoublebottom")
248 {
249 pBottom.reset(new editeng::SvxBorderLine(nullptr));
250 pBottom->GuessLinesWidths(SvxBorderLineStyle::DOUBLE, SvxBorderLineWidth::Hairline,
252 pTop.reset(new editeng::SvxBorderLine(nullptr, SvxBorderLineWidth::Thin));
253 nValidFlags |= FRM_VALID_BOTTOM|FRM_VALID_TOP;
254 }
255
256 aBorderOuter.SetLine( pTop.get(), SvxBoxItemLine::TOP );
257 aBorderOuter.SetLine( pBottom.get(), SvxBoxItemLine::BOTTOM );
258 aBorderOuter.SetLine( nullptr, SvxBoxItemLine::LEFT );
259 aBorderOuter.SetLine( nullptr, SvxBoxItemLine::RIGHT );
260
261 aBorderInner.SetValid( SvxBoxInfoItemValidFlags::TOP, 0 != (nValidFlags&FRM_VALID_TOP ));
262 aBorderInner.SetValid( SvxBoxInfoItemValidFlags::BOTTOM, 0 != (nValidFlags&FRM_VALID_BOTTOM ));
263 aBorderInner.SetValid( SvxBoxInfoItemValidFlags::LEFT, 0 != (nValidFlags&FRM_VALID_LEFT ));
264 aBorderInner.SetValid( SvxBoxInfoItemValidFlags::RIGHT, 0 != (nValidFlags&FRM_VALID_RIGHT ));
265 aBorderInner.SetValid( SvxBoxInfoItemValidFlags::HORI, 0 != (nValidFlags&FRM_VALID_HINNER ));
266 aBorderInner.SetValid( SvxBoxInfoItemValidFlags::VERT, 0 != (nValidFlags&FRM_VALID_VINNER));
267 aBorderInner.SetValid( SvxBoxInfoItemValidFlags::DISTANCE );
268 aBorderInner.SetValid( SvxBoxInfoItemValidFlags::DISABLE, false );
269
270 mpDispatcher->ExecuteList(
271 SID_ATTR_BORDER, SfxCallMode::RECORD, { &aBorderOuter, &aBorderInner });
272
273 pTop.reset();
274 pBottom.reset();
275
276 maToolButton.set_inactive();
277}
278
279} // end of namespace sc::sidebar
280
281/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
#define FRM_VALID_HINNER
#define FRM_VALID_VINNER
#define FRM_VALID_TOP
#define FRM_VALID_BOTTOM
#define FRM_VALID_ALL
#define FRM_VALID_LEFT
#define FRM_VALID_RIGHT
#define FRM_VALID_OUTER
static bool GetLayoutRTL()
static const sal_Int16 Thin
static const sal_Int16 Hairline
static const sal_Int16 Thick
void SetValid(SvxBoxInfoItemValidFlags nValid, bool bValid=true)
void SetLine(const editeng::SvxBorderLine *pNew, SvxBoxInfoItemLine nLine)
void SetLine(const editeng::SvxBorderLine *pNew, SvxBoxItemLine nLine)
void SetLine(const editeng::SvxBorderLine *pNew)
void SetWidth(tools::Long nWidth)
std::unique_ptr< weld::Toolbar > mxTBBorder4
std::unique_ptr< weld::Toolbar > mxTBBorder3
std::unique_ptr< weld::Toolbar > mxTBBorder2
CellBorderStylePopup(weld::Toolbar *pParent, const OUString &rId, SfxDispatcher *pDispatcher)
std::unique_ptr< weld::Toolbar > mxTBBorder1
IMPL_LINK(AlignmentPropertyPanel, ReferenceEdgeHdl, weld::Button &, rToggle, void)
unsigned char sal_uInt8