LibreOffice Module sc (master)  1
CellLineStyleControl.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 
20 #include "CellLineStyleControl.hxx"
22 #include <vcl/i18nhelp.hxx>
23 #include <vcl/settings.hxx>
24 #include <vcl/svapp.hxx>
25 #include <editeng/borderline.hxx>
26 #include <editeng/lineitem.hxx>
27 #include <sfx2/bindings.hxx>
28 #include <sfx2/dispatch.hxx>
29 #include <svx/svxids.hrc>
30 
31 namespace sc::sidebar {
32 
33 CellLineStylePopup::CellLineStylePopup(weld::Toolbar* pParent, const OString& rId, SfxDispatcher* pDispatcher)
34  : WeldToolbarPopup(nullptr, pParent, "modules/scalc/ui/floatinglinestyle.ui", "FloatingLineStyle")
35  , maToolButton(pParent, rId)
36  , mpDispatcher(pDispatcher)
37  , mxCellLineStyleValueSet(new sc::sidebar::CellLineStyleValueSet)
38  , mxCellLineStyleValueSetWin(new weld::CustomWeld(*m_xBuilder, "linestylevalueset", *mxCellLineStyleValueSet))
39  , mxPushButtonMoreOptions(m_xBuilder->weld_button("more"))
40 {
41  Initialize();
42 }
43 
45 {
46 }
47 
49 {
50  mxPushButtonMoreOptions->connect_clicked(LINK(this, CellLineStylePopup, PBClickHdl));
51 
53 
54  for(sal_uInt16 i = 1 ; i <= 9 ; i++)
55  {
56  mxCellLineStyleValueSet->InsertItem(i);
57  }
58 
59 
61  maStr[0] = rI18nHelper.GetNum( 5, 2 ) + "pt";
62  maStr[1] = rI18nHelper.GetNum( 250, 2 ) + "pt";
63  maStr[2] = rI18nHelper.GetNum( 400, 2 ) + "pt";
64  maStr[3] = rI18nHelper.GetNum( 500, 2 ) + "pt";
65  maStr[4] = rI18nHelper.GetNum( 110, 2 ) + "pt";
66  maStr[5] = rI18nHelper.GetNum( 260, 2 ) + "pt";
67  maStr[6] = rI18nHelper.GetNum( 450, 2 ) + "pt";
68  maStr[7] = rI18nHelper.GetNum( 505, 2 ) + "pt";
69  maStr[8] = rI18nHelper.GetNum( 750, 2 ) + "pt";
70  mxCellLineStyleValueSet->SetUnit(&maStr[0]);
71 
72  for (sal_uInt16 i = 1; i <= CELL_LINE_STYLE_ENTRIES; ++i)
73  {
74  mxCellLineStyleValueSet->SetItemText(i, maStr[i-1]);
75  }
76 
77  SetAllNoSel();
78  mxCellLineStyleValueSet->SetSelectHdl(LINK(this, CellLineStylePopup, VSSelectHdl));
79 }
80 
82 {
83  mxCellLineStyleValueSet->GrabFocus();
84 }
85 
87 {
88  mxCellLineStyleValueSet->SelectItem(0);
89  mxCellLineStyleValueSet->SetNoSelection();
90  mxCellLineStyleValueSet->SetFormat();
91  mxCellLineStyleValueSet->Invalidate();
92 }
93 
95 {
96  const sal_uInt16 iPos(mxCellLineStyleValueSet->GetSelectedItemId());
97  SvxLineItem aLineItem(SID_FRAME_LINESTYLE);
98  SvxBorderLineStyle nStyle = SvxBorderLineStyle::SOLID;
99  sal_uInt16 n1 = 0;
100  sal_uInt16 n2 = 0;
101  sal_uInt16 n3 = 0;
102 
103  //FIXME: fully for new border line possibilities
104 
105  switch(iPos)
106  {
107  case 1:
108  n1 = DEF_LINE_WIDTH_0;
109  break;
110  case 2:
111  n1 = DEF_LINE_WIDTH_2;
112  break;
113  case 3:
114  n1 = DEF_LINE_WIDTH_3;
115  break;
116  case 4:
117  n1 = DEF_LINE_WIDTH_4;
118  break;
119  case 5:
120  n1 = DEF_LINE_WIDTH_0;
121  n2 = DEF_LINE_WIDTH_0;
122  n3 = DEF_LINE_WIDTH_1;
123  nStyle = SvxBorderLineStyle::DOUBLE;
124  break;
125  case 6:
126  n1 = DEF_LINE_WIDTH_0;
127  n2 = DEF_LINE_WIDTH_0;
128  n3 = DEF_LINE_WIDTH_2;
129  nStyle = SvxBorderLineStyle::DOUBLE;
130  break;
131  case 7:
132  n1 = DEF_LINE_WIDTH_1;
133  n2 = DEF_LINE_WIDTH_2;
134  n3 = DEF_LINE_WIDTH_1;
135  nStyle = SvxBorderLineStyle::DOUBLE;
136  break;
137  case 8:
138  n1 = DEF_LINE_WIDTH_2;
139  n2 = DEF_LINE_WIDTH_0;
140  n3 = DEF_LINE_WIDTH_2;
141  nStyle = SvxBorderLineStyle::DOUBLE;
142  break;
143  case 9:
144  n1 = DEF_LINE_WIDTH_2;
145  n2 = DEF_LINE_WIDTH_2;
146  n3 = DEF_LINE_WIDTH_2;
147  nStyle = SvxBorderLineStyle::DOUBLE;
148  break;
149  default:
150  break;
151  }
152 
154  aTmp.GuessLinesWidths(nStyle, n1, n2, n3);
155  aLineItem.SetLine( &aTmp );
156  mpDispatcher->ExecuteList(
157  SID_FRAME_LINESTYLE, SfxCallMode::RECORD, { &aLineItem });
158  SetAllNoSel();
159 
160  maToolButton.set_inactive();
161 }
162 
164 {
165  mpDispatcher->Execute(SID_CELL_FORMAT_BORDER, SfxCallMode::ASYNCHRON);
166  maToolButton.set_inactive();
167 }
168 
169 void CellLineStylePopup::SetLineStyleSelect(sal_uInt16 out, sal_uInt16 in, sal_uInt16 dis)
170 {
171  mxCellLineStyleValueSet->GrabFocus();
172  SetAllNoSel();
173 
174  //FIXME: fully for new border line possibilities
175 
176  if(out == DEF_LINE_WIDTH_0 && in == 0 && dis == 0) //1
177  {
178  mxCellLineStyleValueSet->SetSelItem(1);
179  }
180  else if(out == DEF_LINE_WIDTH_2 && in == 0 && dis == 0) //2
181  {
182  mxCellLineStyleValueSet->SetSelItem(2);
183  }
184  else if(out == DEF_LINE_WIDTH_3 && in == 0 && dis == 0) //3
185  {
186  mxCellLineStyleValueSet->SetSelItem(3);
187  }
188  else if(out == DEF_LINE_WIDTH_4 && in == 0 && dis == 0) //4
189  {
190  mxCellLineStyleValueSet->SetSelItem(4);
191  }
192  else if(out == DEF_LINE_WIDTH_0 && in == DEF_LINE_WIDTH_0 && dis == DEF_LINE_WIDTH_1) //5
193  {
194  mxCellLineStyleValueSet->SetSelItem(5);
195  }
196  else if(out == DEF_LINE_WIDTH_0 && in == DEF_LINE_WIDTH_0 && dis == DEF_LINE_WIDTH_2) //6
197  {
198  mxCellLineStyleValueSet->SetSelItem(6);
199  }
200  else if(out == DEF_LINE_WIDTH_1 && in == DEF_LINE_WIDTH_2 && dis == DEF_LINE_WIDTH_1) //7
201  {
202  mxCellLineStyleValueSet->SetSelItem(7);
203  }
204  else if(out == DEF_LINE_WIDTH_2 && in == DEF_LINE_WIDTH_0 && dis == DEF_LINE_WIDTH_2) //8
205  {
206  mxCellLineStyleValueSet->SetSelItem(8);
207  }
208  else if(out == DEF_LINE_WIDTH_2 && in == DEF_LINE_WIDTH_2 && dis == DEF_LINE_WIDTH_2) //9
209  {
210  mxCellLineStyleValueSet->SetSelItem(9);
211  }
212  else
213  {
214  mxCellLineStyleValueSet->SetSelItem(0);
215  mxPushButtonMoreOptions->grab_focus();
216  }
217  mxCellLineStyleValueSet->SetFormat();
218  mxCellLineStyleValueSet->Invalidate();
219 }
220 
221 } // end of namespace sc::sidebar
222 
223 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
#define CELL_LINE_STYLE_ENTRIES
int n1
static const AllSettings & GetSettings()
CellLineStylePopup(weld::Toolbar *pParent, const OString &rId, SfxDispatcher *pDispatcher)
#define DEF_LINE_WIDTH_1
SvxBorderLineStyle
OUString maStr[CELL_LINE_STYLE_ENTRIES]
int n2
#define DEF_LINE_WIDTH_3
std::unique_ptr< CellLineStyleValueSet > mxCellLineStyleValueSet
int i
#define DEF_LINE_WIDTH_4
const vcl::I18nHelper & GetLocaleI18nHelper() const
WinBits const WB_3DLOOK
#define WB_NO_DIRECTSELECT
void GuessLinesWidths(SvxBorderLineStyle nStyle, sal_uInt16 nOut, sal_uInt16 nIn=0, sal_uInt16 nDist=0)
OUString GetNum(tools::Long nNumber, sal_uInt16 nDecimals, bool bUseThousandSep=true, bool bTrailingZeros=true) const
#define DEF_LINE_WIDTH_2
void SetLineStyleSelect(sal_uInt16 out, sal_uInt16 in, sal_uInt16 dis)
IMPL_LINK_NOARG(AlignmentPropertyPanel, AngleModifiedHdl, weld::MetricSpinButton &, void)
#define DEF_LINE_WIDTH_0
std::unique_ptr< weld::Button > mxPushButtonMoreOptions