Line data Source code
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 <sfx2/sidebar/ResourceDefinitions.hrc>
21 : #include <sfx2/sidebar/Theme.hxx>
22 : #include <sfx2/sidebar/ControlFactory.hxx>
23 : #include "NumberFormatPropertyPanel.hxx"
24 : #include <NumberFormatPropertyPanel.hrc>
25 : #include "sc.hrc"
26 : #include "scresid.hxx"
27 : #include <sfx2/bindings.hxx>
28 : #include <sfx2/dispatch.hxx>
29 : #include <sfx2/imagemgr.hxx>
30 : #include <vcl/fixed.hxx>
31 : #include <vcl/lstbox.hxx>
32 : #include <vcl/field.hxx>
33 : #include <vcl/toolbox.hxx>
34 : #include <svl/intitem.hxx>
35 : #include <svl/stritem.hxx>
36 :
37 : using namespace css;
38 : using namespace css::uno;
39 : using ::sfx2::sidebar::Theme;
40 :
41 : const char UNO_NUMERICFIELD[] = ".uno:NumericField";
42 : const char UNO_NUMBERFORMATPERCENT[] = ".uno:NumberFormatPercent";
43 : const char UNO_NUMBERFORMATCURRENCY[] = ".uno:NumberFormatCurrency";
44 :
45 : namespace sc { namespace sidebar {
46 :
47 176 : NumberFormatPropertyPanel::NumberFormatPropertyPanel(
48 : vcl::Window* pParent,
49 : const css::uno::Reference<css::frame::XFrame>& rxFrame,
50 : SfxBindings* pBindings)
51 : : PanelLayout(pParent,"NumberFormatPropertyPanel", "modules/scalc/ui/sidebarnumberformat.ui", rxFrame),
52 : maThousandSeparator(ScResId(RID_SFX_STR_THOUSAND_SEP)),
53 : maEngineeringNotation(ScResId(RID_SFX_STR_ENGINEERING)),
54 : maNumFormatControl(SID_NUMBER_TYPE_FORMAT, *pBindings, *this),
55 : maFormatControl(SID_NUMBER_FORMAT, *pBindings, *this),
56 :
57 : mnCategorySelected(0),
58 : mxFrame(rxFrame),
59 : maContext(),
60 201 : mpBindings(pBindings)
61 : {
62 151 : get(mpLbCategory, "category");
63 151 : get(mpTBCategory, "numberformat");
64 151 : get(mpEdDecimals, "decimalplaces");
65 151 : get(mpEdLeadZeroes, "leadingzeroes");
66 151 : get(mpBtnNegRed, "negativenumbersred");
67 151 : get(mpBtnThousand, "thousandseparator");
68 :
69 151 : Initialize();
70 151 : }
71 :
72 0 : NumberFormatPropertyPanel::~NumberFormatPropertyPanel()
73 : {
74 0 : disposeOnce();
75 0 : }
76 :
77 151 : void NumberFormatPropertyPanel::dispose()
78 : {
79 151 : mpLbCategory.clear();
80 151 : mpTBCategory.clear();
81 151 : mpEdDecimals.clear();
82 151 : mpEdLeadZeroes.clear();
83 151 : mpBtnNegRed.clear();
84 151 : mpBtnThousand.clear();
85 :
86 151 : maNumFormatControl.dispose();
87 151 : maFormatControl.dispose();
88 :
89 151 : PanelLayout::dispose();
90 151 : }
91 :
92 151 : void NumberFormatPropertyPanel::Initialize()
93 : {
94 151 : Link<> aLink = LINK(this, NumberFormatPropertyPanel, NumFormatSelectHdl);
95 151 : mpLbCategory->SetSelectHdl ( aLink );
96 151 : mpLbCategory->SelectEntryPos(0);
97 151 : mpLbCategory->SetAccessibleName(OUString( "Category"));
98 151 : mpLbCategory->SetDropDownLineCount(mpLbCategory->GetEntryCount());
99 :
100 151 : mpTBCategory->SetSelectHdl ( LINK(this, NumberFormatPropertyPanel, NumFormatHdl) );
101 :
102 151 : aLink = LINK(this, NumberFormatPropertyPanel, NumFormatValueHdl);
103 :
104 151 : mpEdDecimals->SetModifyHdl( aLink );
105 151 : mpEdLeadZeroes->SetModifyHdl( aLink );
106 151 : mpEdDecimals->SetAccessibleName(OUString( "Decimal Places"));
107 151 : mpEdLeadZeroes->SetAccessibleName(OUString( "Leading Zeroes"));
108 :
109 151 : mpBtnNegRed->SetClickHdl( aLink );
110 151 : mpBtnThousand->SetClickHdl( aLink );
111 :
112 151 : mpTBCategory->SetAccessibleRelationLabeledBy(mpTBCategory);
113 151 : }
114 :
115 0 : IMPL_LINK_TYPED( NumberFormatPropertyPanel, NumFormatHdl, ToolBox*, pBox, void )
116 : {
117 0 : const OUString aCommand(pBox->GetItemCommand(pBox->GetCurItemId()));
118 0 : sal_uInt16 nId = 0;
119 :
120 0 : if(aCommand == UNO_NUMERICFIELD)
121 0 : nId = 1;
122 0 : else if(aCommand == UNO_NUMBERFORMATPERCENT)
123 0 : nId = 2;
124 0 : else if(aCommand == UNO_NUMBERFORMATCURRENCY)
125 0 : nId = 3;
126 :
127 0 : if( nId != mnCategorySelected )
128 : {
129 0 : SfxUInt16Item aItem( SID_NUMBER_TYPE_FORMAT, nId );
130 0 : GetBindings()->GetDispatcher()->Execute(SID_NUMBER_TYPE_FORMAT, SfxCallMode::RECORD, &aItem, 0L);
131 0 : }
132 0 : }
133 :
134 0 : IMPL_LINK( NumberFormatPropertyPanel, NumFormatSelectHdl, ListBox*, pBox )
135 : {
136 0 : sal_uInt16 nVal = pBox->GetSelectEntryPos();
137 0 : if( nVal != mnCategorySelected )
138 : {
139 0 : SfxUInt16Item aItem( SID_NUMBER_TYPE_FORMAT, nVal );
140 0 : GetBindings()->GetDispatcher()->Execute(SID_NUMBER_TYPE_FORMAT, SfxCallMode::RECORD, &aItem, 0L);
141 0 : mnCategorySelected = nVal;
142 : }
143 0 : return 0L;
144 : }
145 :
146 0 : IMPL_LINK_NOARG( NumberFormatPropertyPanel, NumFormatValueHdl )
147 : {
148 0 : OUString aFormat;
149 0 : OUString sBreak = ",";
150 0 : bool bThousand = mpBtnThousand->IsEnabled()
151 0 : && mpBtnThousand->IsChecked();
152 0 : bool bNegRed = mpBtnNegRed->IsEnabled()
153 0 : && mpBtnNegRed->IsChecked();
154 0 : sal_uInt16 nPrecision = (mpEdDecimals->IsEnabled())
155 0 : ? (sal_uInt16)mpEdDecimals->GetValue()
156 0 : : (sal_uInt16)0;
157 0 : sal_uInt16 nLeadZeroes = (mpEdLeadZeroes->IsEnabled())
158 0 : ? (sal_uInt16)mpEdLeadZeroes->GetValue()
159 0 : : (sal_uInt16)0;
160 :
161 0 : OUString sThousand = OUString::number(static_cast<sal_Int32>(bThousand));
162 0 : OUString sNegRed = OUString::number(static_cast<sal_Int32>(bNegRed));
163 0 : OUString sPrecision = OUString::number(nPrecision);
164 0 : OUString sLeadZeroes = OUString::number(nLeadZeroes);
165 :
166 0 : aFormat += sThousand;
167 0 : aFormat += sBreak;
168 0 : aFormat += sNegRed;
169 0 : aFormat += sBreak;
170 0 : aFormat += sPrecision;
171 0 : aFormat += sBreak;
172 0 : aFormat += sLeadZeroes;
173 0 : aFormat += sBreak;
174 :
175 0 : SfxStringItem aItem( SID_NUMBER_FORMAT, aFormat );
176 0 : GetBindings()->GetDispatcher()->Execute(SID_NUMBER_FORMAT, SfxCallMode::RECORD, &aItem, 0L);
177 0 : return 0L;
178 : }
179 :
180 176 : VclPtr<vcl::Window> NumberFormatPropertyPanel::Create (
181 : vcl::Window* pParent,
182 : const css::uno::Reference<css::frame::XFrame>& rxFrame,
183 : SfxBindings* pBindings)
184 : {
185 176 : if (pParent == NULL)
186 0 : throw lang::IllegalArgumentException("no parent Window given to NumberFormatPropertyPanel::Create", NULL, 0);
187 176 : if ( ! rxFrame.is())
188 0 : throw lang::IllegalArgumentException("no XFrame given to NumberFormatPropertyPanel::Create", NULL, 1);
189 176 : if (pBindings == NULL)
190 0 : throw lang::IllegalArgumentException("no SfxBindings given to NumberFormatPropertyPanel::Create", NULL, 2);
191 :
192 : return VclPtr<NumberFormatPropertyPanel>::Create(
193 176 : pParent, rxFrame, pBindings);
194 : }
195 :
196 0 : void NumberFormatPropertyPanel::DataChanged(
197 : const DataChangedEvent& rEvent)
198 : {
199 : (void)rEvent;
200 0 : }
201 :
202 165 : void NumberFormatPropertyPanel::HandleContextChange(
203 : const ::sfx2::sidebar::EnumContext& rContext)
204 : {
205 165 : if(maContext == rContext)
206 : {
207 : // Nothing to do.
208 165 : return;
209 : }
210 :
211 165 : maContext = rContext;
212 : }
213 :
214 72 : void NumberFormatPropertyPanel::NotifyItemUpdate(
215 : sal_uInt16 nSID,
216 : SfxItemState eState,
217 : const SfxPoolItem* pState,
218 : const bool bIsEnabled)
219 : {
220 : (void)bIsEnabled;
221 :
222 72 : switch(nSID)
223 : {
224 : case SID_NUMBER_TYPE_FORMAT:
225 : {
226 36 : if( eState >= SfxItemState::DEFAULT)
227 : {
228 31 : const SfxInt16Item* pItem = static_cast<const SfxInt16Item*>(pState);
229 31 : sal_uInt16 nVal = pItem->GetValue();
230 31 : mnCategorySelected = nVal;
231 31 : mpLbCategory->SelectEntryPos(nVal);
232 31 : if( nVal < 4 || // General, Number, Percent and Currency
233 : nVal == 6 ) // scientific also
234 : {
235 31 : mpBtnThousand->Enable();
236 31 : mpBtnNegRed->Enable();
237 31 : mpEdDecimals->Enable();
238 31 : mpEdLeadZeroes->Enable();
239 : }
240 : else
241 : {
242 0 : mpBtnThousand->Disable();
243 0 : mpBtnNegRed->Disable();
244 0 : mpEdDecimals->Disable();
245 0 : mpEdLeadZeroes->Disable();
246 : }
247 31 : if( nVal == 6 ) // For scientific, Thousand separator is replaced by Engineering notation
248 0 : mpBtnThousand->SetText( maEngineeringNotation );
249 : else
250 31 : mpBtnThousand->SetText( maThousandSeparator );
251 : }
252 : else
253 : {
254 5 : mpLbCategory->SetNoSelection();
255 5 : mnCategorySelected = 0;
256 5 : mpBtnThousand->Disable();
257 5 : mpBtnNegRed->Disable();
258 5 : mpEdDecimals->Disable();
259 5 : mpEdLeadZeroes->Disable();
260 : }
261 : }
262 36 : break;
263 : case SID_NUMBER_FORMAT:
264 : {
265 36 : bool bThousand = false;
266 36 : bool bNegRed = false;
267 36 : sal_uInt16 nPrecision = 0;
268 36 : sal_uInt16 nLeadZeroes = 0;
269 36 : if( eState >= SfxItemState::DEFAULT)
270 : {
271 31 : const SfxStringItem* pItem = static_cast<const SfxStringItem*>(pState);
272 31 : OUString aCode = pItem->GetValue();
273 : /* if(aCode.Equals(String::CreateFromAscii("General")))
274 : {
275 : mnCategorySelected = 0;
276 : mpLbCategory->SelectEntryPos(0);
277 : mpBtnThousand->Check(0);
278 : mpBtnNegRed->Check(0);
279 : mpEdDecimals->SetValue(0);
280 : mpEdLeadZeroes->SetValue(1);
281 : break;
282 : }
283 : else if( mpLbCategory->GetSelectEntryPos() == 0 )
284 : {
285 : mnCategorySelected = 1;
286 : mpLbCategory->SelectEntryPos(1);
287 : }*/
288 31 : sal_uInt16 aLen = aCode.getLength();
289 31 : OUString* sFormat = new OUString[4];
290 62 : OUString sTmpStr = "";
291 31 : sal_uInt16 nCount = 0;
292 31 : sal_uInt16 nStrCount = 0;
293 310 : while( nCount < aLen )
294 : {
295 248 : sal_Unicode cChar = aCode[nCount];
296 248 : if(cChar == ',')
297 : {
298 124 : sFormat[nStrCount] = sTmpStr;
299 124 : sTmpStr.clear();
300 124 : nStrCount++;
301 : }
302 : else
303 : {
304 124 : sTmpStr += OUString(cChar);
305 : }
306 248 : nCount++;
307 : }
308 31 : bThousand = sFormat[0].toInt32();
309 31 : bNegRed = sFormat[1].toInt32();
310 31 : nPrecision = (sal_uInt16)sFormat[2].toInt32();
311 31 : nLeadZeroes = (sal_uInt16)sFormat[3].toInt32();
312 62 : delete[] sFormat;
313 : }
314 : else
315 : {
316 5 : bThousand = false;
317 5 : bNegRed = false;
318 5 : nPrecision = 0;
319 5 : nLeadZeroes = 1;
320 : }
321 36 : mpBtnThousand->Check(bThousand);
322 36 : mpBtnNegRed->Check(bNegRed);
323 36 : mpEdDecimals->SetValue(nPrecision);
324 36 : mpEdLeadZeroes->SetValue(nLeadZeroes);
325 : }
326 : default:
327 : ;
328 : }
329 72 : }
330 :
331 156 : }} // end of namespace ::sc::sidebar
332 :
333 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|