1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
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>
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(
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),
62 get(mpLbCategory
, "category");
63 get(mpTBCategory
, "numberformat");
64 get(mpEdDecimals
, "decimalplaces");
65 get(mpEdLeadZeroes
, "leadingzeroes");
66 get(mpBtnNegRed
, "negativenumbersred");
67 get(mpBtnThousand
, "thousandseparator");
72 NumberFormatPropertyPanel::~NumberFormatPropertyPanel()
77 void NumberFormatPropertyPanel::dispose()
82 mpEdLeadZeroes
.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()));
120 if(aCommand
== UNO_NUMERICFIELD
)
122 else if(aCommand
== UNO_NUMBERFORMATPERCENT
)
124 else if(aCommand
== UNO_NUMBERFORMATCURRENCY
)
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
;
146 IMPL_LINK_NOARG( NumberFormatPropertyPanel
, NumFormatValueHdl
)
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()
157 sal_uInt16 nLeadZeroes
= (mpEdLeadZeroes
->IsEnabled())
158 ? (sal_uInt16
)mpEdLeadZeroes
->GetValue()
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
;
170 aFormat
+= sPrecision
;
172 aFormat
+= sLeadZeroes
;
175 SfxStringItem
aItem( SID_NUMBER_FORMAT
, aFormat
);
176 GetBindings()->GetDispatcher()->Execute(SID_NUMBER_FORMAT
, SfxCallMode::RECORD
, &aItem
, 0L);
180 VclPtr
<vcl::Window
> NumberFormatPropertyPanel::Create (
181 vcl::Window
* pParent
,
182 const css::uno::Reference
<css::frame::XFrame
>& rxFrame
,
183 SfxBindings
* pBindings
)
186 throw lang::IllegalArgumentException("no parent Window given to NumberFormatPropertyPanel::Create", NULL
, 0);
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
)
202 void NumberFormatPropertyPanel::HandleContextChange(
203 const ::sfx2::sidebar::EnumContext
& rContext
)
205 if(maContext
== rContext
)
211 maContext
= rContext
;
214 void NumberFormatPropertyPanel::NotifyItemUpdate(
217 const SfxPoolItem
* pState
,
218 const bool bIsEnabled
)
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();
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
);
250 mpBtnThousand
->SetText( maThousandSeparator
);
254 mpLbCategory
->SetNoSelection();
255 mnCategorySelected
= 0;
256 mpBtnThousand
->Disable();
257 mpBtnNegRed
->Disable();
258 mpEdDecimals
->Disable();
259 mpEdLeadZeroes
->Disable();
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);
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
];
298 sFormat
[nStrCount
] = sTmpStr
;
304 sTmpStr
+= OUString(cChar
);
308 bThousand
= sFormat
[0].toInt32();
309 bNegRed
= sFormat
[1].toInt32();
310 nPrecision
= (sal_uInt16
)sFormat
[2].toInt32();
311 nLeadZeroes
= (sal_uInt16
)sFormat
[3].toInt32();
321 mpBtnThousand
->Check(bThousand
);
322 mpBtnNegRed
->Check(bNegRed
);
323 if ( mpLbCategory
->GetSelectEntryPos() == 0 )
324 mpEdDecimals
->SetText(""); // tdf#44399
326 mpEdDecimals
->SetValue(nPrecision
);
327 mpEdLeadZeroes
->SetValue(nLeadZeroes
);
334 }} // end of namespace ::sc::sidebar
336 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */