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 #include <scresid.hxx>
31 #include <strings.hrc>
32 
33 namespace sc::sidebar {
34 
35 CellLineStylePopup::CellLineStylePopup(weld::Toolbar* pParent, const OString& rId, SfxDispatcher* pDispatcher)
36  : WeldToolbarPopup(nullptr, pParent, "modules/scalc/ui/floatinglinestyle.ui", "FloatingLineStyle")
37  , maToolButton(pParent, rId)
38  , mpDispatcher(pDispatcher)
39  , mxCellLineStyleValueSet(new sc::sidebar::CellLineStyleValueSet)
40  , mxCellLineStyleValueSetWin(new weld::CustomWeld(*m_xBuilder, "linestylevalueset", *mxCellLineStyleValueSet))
41  , mxPushButtonMoreOptions(m_xBuilder->weld_button("more"))
42 {
43  Initialize();
44 }
45 
47 {
48 }
49 
51 {
52  mxPushButtonMoreOptions->connect_clicked(LINK(this, CellLineStylePopup, PBClickHdl));
53 
55 
56  for(sal_uInt16 i = 1 ; i <= CELL_LINE_STYLE_ENTRIES ; i++)
57  {
58  mxCellLineStyleValueSet->InsertItem(i);
59  }
60 
62  maStr[0] = ScResId(STR_BORDER_HAIRLINE).replaceFirst("%s", rI18nHelper.GetNum(5, 2));
63  maStr[1] = ScResId(STR_BORDER_VERY_THIN).replaceFirst("%s", rI18nHelper.GetNum(50, 2));
64  maStr[2] = ScResId(STR_BORDER_THIN).replaceFirst("%s", rI18nHelper.GetNum(75, 2));
65  maStr[3] = ScResId(STR_BORDER_MEDIUM).replaceFirst("%s", rI18nHelper.GetNum(150, 2));
66  maStr[4] = ScResId(STR_BORDER_THICK).replaceFirst("%s", rI18nHelper.GetNum(225, 2));
67  maStr[5] = ScResId(STR_BORDER_EXTRA_THICK).replaceFirst("%s", rI18nHelper.GetNum(450, 2));
68 
69  // Numbers in pt are the total width of the double line (inner + outer + distance)
70  maStr[6] = ScResId(STR_BORDER_DOUBLE_1).replaceFirst("%s", rI18nHelper.GetNum(110, 2));
71  maStr[7] = ScResId(STR_BORDER_DOUBLE_1).replaceFirst("%s", rI18nHelper.GetNum(235, 2));
72  maStr[8] = ScResId(STR_BORDER_DOUBLE_2).replaceFirst("%s", rI18nHelper.GetNum(300, 2));
73  maStr[9] = ScResId(STR_BORDER_DOUBLE_3).replaceFirst("%s", rI18nHelper.GetNum(305, 2));
74  maStr[10] = ScResId(STR_BORDER_DOUBLE_4).replaceFirst("%s", rI18nHelper.GetNum(450, 2));
75  mxCellLineStyleValueSet->SetUnit(&maStr[0]);
76 
77  for (sal_uInt16 i = 1; i <= CELL_LINE_STYLE_ENTRIES; ++i)
78  {
79  mxCellLineStyleValueSet->SetItemText(i, maStr[i-1]);
80  }
81 
82  SetAllNoSel();
83  mxCellLineStyleValueSet->SetSelectHdl(LINK(this, CellLineStylePopup, VSSelectHdl));
84 }
85 
87 {
88  mxCellLineStyleValueSet->GrabFocus();
89 }
90 
92 {
93  mxCellLineStyleValueSet->SelectItem(0);
94  mxCellLineStyleValueSet->SetNoSelection();
95  mxCellLineStyleValueSet->SetFormat();
96  mxCellLineStyleValueSet->Invalidate();
97 }
98 
100 {
101  const sal_uInt16 iPos(mxCellLineStyleValueSet->GetSelectedItemId());
102  SvxLineItem aLineItem(SID_FRAME_LINESTYLE);
103  SvxBorderLineStyle nStyle = SvxBorderLineStyle::SOLID;
104  sal_uInt16 n1 = 0;
105  sal_uInt16 n2 = 0;
106  sal_uInt16 n3 = 0;
107 
108  //FIXME: fully for new border line possibilities
109 
110  switch(iPos)
111  {
112  case 1:
114  break;
115  case 2:
117  break;
118  case 3:
120  break;
121  case 4:
123  break;
124  case 5:
126  break;
127  case 6:
129  break;
130  case 7:
134  nStyle = SvxBorderLineStyle::DOUBLE;
135  break;
136  case 8:
140  nStyle = SvxBorderLineStyle::DOUBLE;
141  break;
142  case 9:
146  nStyle = SvxBorderLineStyle::DOUBLE;
147  break;
148  case 10:
152  nStyle = SvxBorderLineStyle::DOUBLE;
153  break;
154  case 11:
158  nStyle = SvxBorderLineStyle::DOUBLE;
159  break;
160  default:
161  break;
162  }
163 
165  aTmp.GuessLinesWidths(nStyle, n1, n2, n3);
166  aLineItem.SetLine( &aTmp );
167  mpDispatcher->ExecuteList(
168  SID_FRAME_LINESTYLE, SfxCallMode::RECORD, { &aLineItem });
169  SetAllNoSel();
170 
171  maToolButton.set_inactive();
172 }
173 
175 {
176  mpDispatcher->Execute(SID_CELL_FORMAT_BORDER, SfxCallMode::ASYNCHRON);
177  maToolButton.set_inactive();
178 }
179 
180 void CellLineStylePopup::SetLineStyleSelect(sal_uInt16 out, sal_uInt16 in, sal_uInt16 dis)
181 {
182  mxCellLineStyleValueSet->GrabFocus();
183  SetAllNoSel();
184 
185  //FIXME: fully for new border line possibilities
186 
187  if(out == SvxBorderLineWidth::Hairline && in == 0 && dis == 0) //1
188  {
189  mxCellLineStyleValueSet->SetSelItem(1);
190  }
191  else if(out == SvxBorderLineWidth::VeryThin && in == 0 && dis == 0) //2
192  {
193  mxCellLineStyleValueSet->SetSelItem(2);
194  }
195  else if(out == SvxBorderLineWidth::Thin && in == 0 && dis == 0) //3
196  {
197  mxCellLineStyleValueSet->SetSelItem(3);
198  }
199  else if(out == SvxBorderLineWidth::Medium && in == 0 && dis == 0) //4
200  {
201  mxCellLineStyleValueSet->SetSelItem(4);
202  }
203  else if(out == SvxBorderLineWidth::Thick && in == 0 && dis == 0) //5
204  {
205  mxCellLineStyleValueSet->SetSelItem(5);
206  }
207  else if(out == SvxBorderLineWidth::ExtraThick && in == 0 && dis == 0) //6
208  {
209  mxCellLineStyleValueSet->SetSelItem(6);
210  }
212  {
213  mxCellLineStyleValueSet->SetSelItem(7);
214  }
216  {
217  mxCellLineStyleValueSet->SetSelItem(8);
218  }
220  {
221  mxCellLineStyleValueSet->SetSelItem(9);
222  }
224  {
225  mxCellLineStyleValueSet->SetSelItem(10);
226  }
228  {
229  mxCellLineStyleValueSet->SetSelItem(11);
230  }
231 
232  else
233  {
234  mxCellLineStyleValueSet->SetSelItem(0);
235  mxPushButtonMoreOptions->grab_focus();
236  }
237  mxCellLineStyleValueSet->SetFormat();
238  mxCellLineStyleValueSet->Invalidate();
239 }
240 
241 } // end of namespace sc::sidebar
242 
243 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static const sal_Int16 VeryThin
#define CELL_LINE_STYLE_ENTRIES
OUString ScResId(TranslateId aId)
Definition: scdll.cxx:90
int n1
static const AllSettings & GetSettings()
CellLineStylePopup(weld::Toolbar *pParent, const OString &rId, SfxDispatcher *pDispatcher)
SvxBorderLineStyle
OUString maStr[CELL_LINE_STYLE_ENTRIES]
int n2
static const sal_Int16 Medium
std::unique_ptr< CellLineStyleValueSet > mxCellLineStyleValueSet
int i
CAUTION! The following defines must be in the same namespace as the respective type.
const vcl::I18nHelper & GetLocaleI18nHelper() const
WinBits const WB_3DLOOK
static const sal_Int16 Hairline
#define WB_NO_DIRECTSELECT
void GuessLinesWidths(SvxBorderLineStyle nStyle, sal_uInt16 nOut, sal_uInt16 nIn=0, sal_uInt16 nDist=0)
static const sal_Int16 Thin
static const sal_Int16 ExtraThick
OUString GetNum(tools::Long nNumber, sal_uInt16 nDecimals, bool bUseThousandSep=true, bool bTrailingZeros=true) const
void SetLineStyleSelect(sal_uInt16 out, sal_uInt16 in, sal_uInt16 dis)
IMPL_LINK_NOARG(AlignmentPropertyPanel, AngleModifiedHdl, weld::MetricSpinButton &, void)
std::unique_ptr< weld::Button > mxPushButtonMoreOptions
static const sal_Int16 Thick