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