fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / sc / source / ui / sidebar / NumberFormatPropertyPanel.cxx
blob4ec8606c41b306e1508cef867ac4f18a69b96355
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
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>
37 using namespace css;
38 using namespace css::uno;
39 using ::sfx2::sidebar::Theme;
41 const char UNO_NUMERICFIELD[] = ".uno:NumericField";
42 const char UNO_NUMBERFORMATPERCENT[] = ".uno:NumberFormatPercent";
43 const char UNO_NUMBERFORMATCURRENCY[] = ".uno:NumberFormatCurrency";
45 namespace sc { namespace sidebar {
47 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),
57 mnCategorySelected(0),
58 mxFrame(rxFrame),
59 maContext(),
60 mpBindings(pBindings)
62 get(mpLbCategory, "category");
63 get(mpTBCategory, "numberformat");
64 get(mpEdDecimals, "decimalplaces");
65 get(mpEdLeadZeroes, "leadingzeroes");
66 get(mpBtnNegRed, "negativenumbersred");
67 get(mpBtnThousand, "thousandseparator");
69 Initialize();
72 NumberFormatPropertyPanel::~NumberFormatPropertyPanel()
74 disposeOnce();
77 void NumberFormatPropertyPanel::dispose()
79 mpLbCategory.clear();
80 mpTBCategory.clear();
81 mpEdDecimals.clear();
82 mpEdLeadZeroes.clear();
83 mpBtnNegRed.clear();
84 mpBtnThousand.clear();
86 maNumFormatControl.dispose();
87 maFormatControl.dispose();
89 PanelLayout::dispose();
92 void NumberFormatPropertyPanel::Initialize()
94 Link<> aLink = LINK(this, NumberFormatPropertyPanel, NumFormatSelectHdl);
95 mpLbCategory->SetSelectHdl ( aLink );
96 mpLbCategory->SelectEntryPos(0);
97 mpLbCategory->SetAccessibleName(OUString( "Category"));
98 mpLbCategory->SetDropDownLineCount(mpLbCategory->GetEntryCount());
100 mpTBCategory->SetSelectHdl ( LINK(this, NumberFormatPropertyPanel, NumFormatHdl) );
102 aLink = LINK(this, NumberFormatPropertyPanel, NumFormatValueHdl);
104 mpEdDecimals->SetModifyHdl( aLink );
105 mpEdLeadZeroes->SetModifyHdl( aLink );
106 mpEdDecimals->SetAccessibleName(OUString( "Decimal Places"));
107 mpEdLeadZeroes->SetAccessibleName(OUString( "Leading Zeroes"));
109 mpBtnNegRed->SetClickHdl( aLink );
110 mpBtnThousand->SetClickHdl( aLink );
112 mpTBCategory->SetAccessibleRelationLabeledBy(mpTBCategory);
115 IMPL_LINK_TYPED( NumberFormatPropertyPanel, NumFormatHdl, ToolBox*, pBox, void )
117 const OUString aCommand(pBox->GetItemCommand(pBox->GetCurItemId()));
118 sal_uInt16 nId = 0;
120 if(aCommand == UNO_NUMERICFIELD)
121 nId = 1;
122 else if(aCommand == UNO_NUMBERFORMATPERCENT)
123 nId = 2;
124 else if(aCommand == UNO_NUMBERFORMATCURRENCY)
125 nId = 3;
127 if( nId != mnCategorySelected )
129 SfxUInt16Item aItem( SID_NUMBER_TYPE_FORMAT, nId );
130 GetBindings()->GetDispatcher()->Execute(SID_NUMBER_TYPE_FORMAT, SfxCallMode::RECORD, &aItem, 0L);
134 IMPL_LINK( NumberFormatPropertyPanel, NumFormatSelectHdl, ListBox*, pBox )
136 sal_uInt16 nVal = pBox->GetSelectEntryPos();
137 if( nVal != mnCategorySelected )
139 SfxUInt16Item aItem( SID_NUMBER_TYPE_FORMAT, nVal );
140 GetBindings()->GetDispatcher()->Execute(SID_NUMBER_TYPE_FORMAT, SfxCallMode::RECORD, &aItem, 0L);
141 mnCategorySelected = nVal;
143 return 0L;
146 IMPL_LINK_NOARG( NumberFormatPropertyPanel, NumFormatValueHdl )
148 OUString aFormat;
149 OUString sBreak = ",";
150 bool bThousand = mpBtnThousand->IsEnabled()
151 && mpBtnThousand->IsChecked();
152 bool bNegRed = mpBtnNegRed->IsEnabled()
153 && mpBtnNegRed->IsChecked();
154 sal_uInt16 nPrecision = (mpEdDecimals->IsEnabled())
155 ? (sal_uInt16)mpEdDecimals->GetValue()
156 : (sal_uInt16)0;
157 sal_uInt16 nLeadZeroes = (mpEdLeadZeroes->IsEnabled())
158 ? (sal_uInt16)mpEdLeadZeroes->GetValue()
159 : (sal_uInt16)0;
161 OUString sThousand = OUString::number(static_cast<sal_Int32>(bThousand));
162 OUString sNegRed = OUString::number(static_cast<sal_Int32>(bNegRed));
163 OUString sPrecision = OUString::number(nPrecision);
164 OUString sLeadZeroes = OUString::number(nLeadZeroes);
166 aFormat += sThousand;
167 aFormat += sBreak;
168 aFormat += sNegRed;
169 aFormat += sBreak;
170 aFormat += sPrecision;
171 aFormat += sBreak;
172 aFormat += sLeadZeroes;
173 aFormat += sBreak;
175 SfxStringItem aItem( SID_NUMBER_FORMAT, aFormat );
176 GetBindings()->GetDispatcher()->Execute(SID_NUMBER_FORMAT, SfxCallMode::RECORD, &aItem, 0L);
177 return 0L;
180 VclPtr<vcl::Window> NumberFormatPropertyPanel::Create (
181 vcl::Window* pParent,
182 const css::uno::Reference<css::frame::XFrame>& rxFrame,
183 SfxBindings* pBindings)
185 if (pParent == NULL)
186 throw lang::IllegalArgumentException("no parent Window given to NumberFormatPropertyPanel::Create", NULL, 0);
187 if ( ! rxFrame.is())
188 throw lang::IllegalArgumentException("no XFrame given to NumberFormatPropertyPanel::Create", NULL, 1);
189 if (pBindings == NULL)
190 throw lang::IllegalArgumentException("no SfxBindings given to NumberFormatPropertyPanel::Create", NULL, 2);
192 return VclPtr<NumberFormatPropertyPanel>::Create(
193 pParent, rxFrame, pBindings);
196 void NumberFormatPropertyPanel::DataChanged(
197 const DataChangedEvent& rEvent)
199 (void)rEvent;
202 void NumberFormatPropertyPanel::HandleContextChange(
203 const ::sfx2::sidebar::EnumContext& rContext)
205 if(maContext == rContext)
207 // Nothing to do.
208 return;
211 maContext = rContext;
214 void NumberFormatPropertyPanel::NotifyItemUpdate(
215 sal_uInt16 nSID,
216 SfxItemState eState,
217 const SfxPoolItem* pState,
218 const bool bIsEnabled)
220 (void)bIsEnabled;
222 switch(nSID)
224 case SID_NUMBER_TYPE_FORMAT:
226 if( eState >= SfxItemState::DEFAULT)
228 const SfxInt16Item* pItem = static_cast<const SfxInt16Item*>(pState);
229 sal_uInt16 nVal = pItem->GetValue();
230 mnCategorySelected = nVal;
231 mpLbCategory->SelectEntryPos(nVal);
232 if( nVal < 4 || // General, Number, Percent and Currency
233 nVal == 6 ) // scientific also
235 mpBtnThousand->Enable();
236 mpBtnNegRed->Enable();
237 mpEdDecimals->Enable();
238 mpEdLeadZeroes->Enable();
240 else
242 mpBtnThousand->Disable();
243 mpBtnNegRed->Disable();
244 mpEdDecimals->Disable();
245 mpEdLeadZeroes->Disable();
247 if( nVal == 6 ) // For scientific, Thousand separator is replaced by Engineering notation
248 mpBtnThousand->SetText( maEngineeringNotation );
249 else
250 mpBtnThousand->SetText( maThousandSeparator );
252 else
254 mpLbCategory->SetNoSelection();
255 mnCategorySelected = 0;
256 mpBtnThousand->Disable();
257 mpBtnNegRed->Disable();
258 mpEdDecimals->Disable();
259 mpEdLeadZeroes->Disable();
262 break;
263 case SID_NUMBER_FORMAT:
265 bool bThousand = false;
266 bool bNegRed = false;
267 sal_uInt16 nPrecision = 0;
268 sal_uInt16 nLeadZeroes = 0;
269 if( eState >= SfxItemState::DEFAULT)
271 const SfxStringItem* pItem = static_cast<const SfxStringItem*>(pState);
272 OUString aCode = pItem->GetValue();
273 /* if(aCode.Equals(String::CreateFromAscii("General")))
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;
283 else if( mpLbCategory->GetSelectEntryPos() == 0 )
285 mnCategorySelected = 1;
286 mpLbCategory->SelectEntryPos(1);
288 sal_uInt16 aLen = aCode.getLength();
289 OUString* sFormat = new OUString[4];
290 OUString sTmpStr = "";
291 sal_uInt16 nCount = 0;
292 sal_uInt16 nStrCount = 0;
293 while( nCount < aLen )
295 sal_Unicode cChar = aCode[nCount];
296 if(cChar == ',')
298 sFormat[nStrCount] = sTmpStr;
299 sTmpStr.clear();
300 nStrCount++;
302 else
304 sTmpStr += OUString(cChar);
306 nCount++;
308 bThousand = sFormat[0].toInt32();
309 bNegRed = sFormat[1].toInt32();
310 nPrecision = (sal_uInt16)sFormat[2].toInt32();
311 nLeadZeroes = (sal_uInt16)sFormat[3].toInt32();
312 delete[] sFormat;
314 else
316 bThousand = false;
317 bNegRed = false;
318 nPrecision = 0;
319 nLeadZeroes = 1;
321 mpBtnThousand->Check(bThousand);
322 mpBtnNegRed->Check(bNegRed);
323 if ( mpLbCategory->GetSelectEntryPos() == 0 )
324 mpEdDecimals->SetText(""); // tdf#44399
325 else
326 mpEdDecimals->SetValue(nPrecision);
327 mpEdLeadZeroes->SetValue(nLeadZeroes);
329 default:
334 }} // end of namespace ::sc::sidebar
336 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */