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/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 
30 namespace 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 
41 CellBorderStylePopup::CellBorderStylePopup(weld::Toolbar* pParent, const OString& rId, SfxDispatcher* pDispatcher)
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 
72 IMPL_LINK(CellBorderStylePopup, TB1SelectHdl, const OString&, rId, void)
73 {
74  SvxBoxItem aBorderOuter( SID_ATTR_BORDER_OUTER );
75  SvxBoxInfoItem aBorderInner( SID_ATTR_BORDER_INNER );
76  editeng::SvxBorderLine theDefLine(nullptr, 1);
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  {
106  theDefLine.SetWidth(DEF_LINE_WIDTH_2);
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 
131 IMPL_LINK(CellBorderStylePopup, TB2and3SelectHdl, const OString&, rId, void)
132 {
133  if (rId == "diagup")
134  {
135  editeng::SvxBorderLine aTmp( nullptr, 1 );
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  {
143  editeng::SvxBorderLine aTmp( nullptr, 1 );
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 );
153  editeng::SvxBorderLine theDefLine(nullptr, 1);
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 
218 IMPL_LINK(CellBorderStylePopup, TB4SelectHdl, const OString&, 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, DEF_LINE_WIDTH_2 ));
232  nValidFlags |= FRM_VALID_BOTTOM;
233  }
234  else if (rId == "doublebottom")
235  {
236  pBottom.reset(new editeng::SvxBorderLine(nullptr));
237  pBottom->GuessLinesWidths(SvxBorderLineStyle::DOUBLE, DEF_LINE_WIDTH_0, DEF_LINE_WIDTH_0, DEF_LINE_WIDTH_1);
238  nValidFlags |= FRM_VALID_BOTTOM;
239  }
240  else if (rId == "topthickbottom")
241  {
242  pBottom.reset(new editeng::SvxBorderLine(nullptr, DEF_LINE_WIDTH_2 ));
243  pTop.reset(new editeng::SvxBorderLine(nullptr, 1));
244  nValidFlags |= FRM_VALID_BOTTOM|FRM_VALID_TOP;
245  }
246  else if (rId == "topdoublebottom")
247  {
248  pBottom.reset(new editeng::SvxBorderLine(nullptr));
249  pBottom->GuessLinesWidths(SvxBorderLineStyle::DOUBLE, DEF_LINE_WIDTH_0, DEF_LINE_WIDTH_0, DEF_LINE_WIDTH_1);
250  pTop.reset(new editeng::SvxBorderLine(nullptr, 1));
251  nValidFlags |= FRM_VALID_BOTTOM|FRM_VALID_TOP;
252  }
253 
254  aBorderOuter.SetLine( pTop.get(), SvxBoxItemLine::TOP );
255  aBorderOuter.SetLine( pBottom.get(), SvxBoxItemLine::BOTTOM );
256  aBorderOuter.SetLine( nullptr, SvxBoxItemLine::LEFT );
257  aBorderOuter.SetLine( nullptr, SvxBoxItemLine::RIGHT );
258 
259  aBorderInner.SetValid( SvxBoxInfoItemValidFlags::TOP, 0 != (nValidFlags&FRM_VALID_TOP ));
260  aBorderInner.SetValid( SvxBoxInfoItemValidFlags::BOTTOM, 0 != (nValidFlags&FRM_VALID_BOTTOM ));
261  aBorderInner.SetValid( SvxBoxInfoItemValidFlags::LEFT, 0 != (nValidFlags&FRM_VALID_LEFT ));
262  aBorderInner.SetValid( SvxBoxInfoItemValidFlags::RIGHT, 0 != (nValidFlags&FRM_VALID_RIGHT ));
263  aBorderInner.SetValid( SvxBoxInfoItemValidFlags::HORI, 0 != (nValidFlags&FRM_VALID_HINNER ));
264  aBorderInner.SetValid( SvxBoxInfoItemValidFlags::VERT, 0 != (nValidFlags&FRM_VALID_VINNER));
265  aBorderInner.SetValid( SvxBoxInfoItemValidFlags::DISTANCE );
266  aBorderInner.SetValid( SvxBoxInfoItemValidFlags::DISABLE, false );
267 
268  mpDispatcher->ExecuteList(
269  SID_ATTR_BORDER, SfxCallMode::RECORD, { &aBorderOuter, &aBorderInner });
270 
271  pTop.reset();
272  pBottom.reset();
273 
274  maToolButton.set_inactive();
275 }
276 
277 } // end of namespace sc::sidebar
278 
279 /* 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
std::unique_ptr< weld::Toolbar > mxTBBorder3
#define FRM_VALID_TOP
IMPL_LINK(AlignmentPropertyPanel, ReferenceEdgeHdl, weld::Button &, rToggle, void)
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)