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>
25 #include "scresid.hxx"
26 #include <sfx2/bindings.hxx>
27 #include <sfx2/dispatch.hxx>
28 #include <sfx2/imagemgr.hxx>
29 #include <vcl/fixed.hxx>
30 #include <vcl/lstbox.hxx>
31 #include <vcl/field.hxx>
32 #include <vcl/toolbox.hxx>
33 #include <svl/intitem.hxx>
34 #include <svl/stritem.hxx>
38 using ::sfx2::sidebar::Theme
;
40 const char UNO_NUMERICFIELD
[] = ".uno:NumericField";
41 const char UNO_NUMBERFORMATPERCENT
[] = ".uno:NumberFormatPercent";
42 const char UNO_NUMBERFORMATCURRENCY
[] = ".uno:NumberFormatCurrency";
43 const char UNO_NUMBERFORMATDATE
[] = ".uno:NumberFormatDate";
44 const char UNO_INSERTFIXEDTEXT
[] = ".uno:InsertFixedText";
46 //////////////////////////////////////////////////////////////////////////////
49 namespace sc
{ namespace sidebar
{
51 //////////////////////////////////////////////////////////////////////////////
53 NumberFormatPropertyPanel::NumberFormatPropertyPanel(
55 const cssu::Reference
<css::frame::XFrame
>& rxFrame
,
56 SfxBindings
* pBindings
)
57 : PanelLayout(pParent
,"NumberFormatPropertyPanel", "modules/scalc/ui/sidebarnumberformat.ui", rxFrame
),
58 maNumFormatControl(SID_NUMBER_TYPE_FORMAT
, *pBindings
, *this),
60 // Caution! SID_NUMBER_FORMAT is reworked in symphony code, may be needed (!) If
61 // yes, grep for it in SC and symphony (!)
62 maFormatControl(SID_NUMBER_FORMAT
, *pBindings
, *this),
64 mnCategorySelected(0),
69 get(mpLbCategory
, "category");
70 get(mpTBCategory
, "numberformat");
71 get(mpEdDecimals
, "decimalplaces");
72 get(mpEdLeadZeroes
, "leadingzeroes");
73 get(mpBtnNegRed
, "negativenumbersred");
74 get(mpBtnThousand
, "thousandseparator");
79 //////////////////////////////////////////////////////////////////////////////
81 NumberFormatPropertyPanel::~NumberFormatPropertyPanel()
85 //////////////////////////////////////////////////////////////////////////////
87 void NumberFormatPropertyPanel::Initialize()
89 Link aLink
= LINK(this, NumberFormatPropertyPanel
, NumFormatSelectHdl
);
90 mpLbCategory
->SetSelectHdl ( aLink
);
91 mpLbCategory
->SelectEntryPos(0);
92 mpLbCategory
->SetAccessibleName(OUString( "Category")); //wj acc
93 mpLbCategory
->SetDropDownLineCount(mpLbCategory
->GetEntryCount());
95 aLink
= LINK(this, NumberFormatPropertyPanel
, NumFormatHdl
);
96 mpTBCategory
->SetSelectHdl ( aLink
);
98 aLink
= LINK(this, NumberFormatPropertyPanel
, NumFormatValueHdl
);
100 mpEdDecimals
->SetModifyHdl( aLink
);
101 mpEdLeadZeroes
->SetModifyHdl( aLink
);
102 mpEdDecimals
->SetAccessibleName(OUString( "Decimal Places")); //wj acc
103 mpEdLeadZeroes
->SetAccessibleName(OUString( "Leading Zeroes")); //wj acc
104 mpBtnNegRed
->SetClickHdl( aLink
);
105 mpBtnThousand
->SetClickHdl( aLink
);
107 mpTBCategory
->SetAccessibleRelationLabeledBy(mpTBCategory
);
110 //////////////////////////////////////////////////////////////////////////////
112 IMPL_LINK( NumberFormatPropertyPanel
, NumFormatHdl
, ToolBox
*, pBox
)
114 const OUString
aCommand(pBox
->GetItemCommand(pBox
->GetCurItemId()));
117 if(aCommand
== UNO_NUMERICFIELD
)
119 else if(aCommand
== UNO_NUMBERFORMATPERCENT
)
121 else if(aCommand
== UNO_NUMBERFORMATCURRENCY
)
123 else if(aCommand
== UNO_NUMBERFORMATDATE
)
125 else if(aCommand
== UNO_INSERTFIXEDTEXT
)
128 if( nId
!= mnCategorySelected
)
130 SfxUInt16Item
aItem( SID_NUMBER_TYPE_FORMAT
, nId
);
131 GetBindings()->GetDispatcher()->Execute(SID_NUMBER_TYPE_FORMAT
, SFX_CALLMODE_RECORD
, &aItem
, 0L);
136 //////////////////////////////////////////////////////////////////////////////
138 IMPL_LINK( NumberFormatPropertyPanel
, NumFormatSelectHdl
, ListBox
*, pBox
)
140 sal_uInt16 nVal
= pBox
->GetSelectEntryPos();
141 if( nVal
!= mnCategorySelected
)
143 SfxUInt16Item
aItem( SID_NUMBER_TYPE_FORMAT
, nVal
);
144 GetBindings()->GetDispatcher()->Execute(SID_NUMBER_TYPE_FORMAT
, SFX_CALLMODE_RECORD
, &aItem
, 0L);
145 mnCategorySelected
= nVal
;
150 //////////////////////////////////////////////////////////////////////////////
152 IMPL_LINK( NumberFormatPropertyPanel
, NumFormatValueHdl
, void*, EMPTYARG
)
155 OUString sBreak
= ",";
156 bool bThousand
= mpBtnThousand
->IsEnabled()
157 && mpBtnThousand
->IsChecked();
158 bool bNegRed
= mpBtnNegRed
->IsEnabled()
159 && mpBtnNegRed
->IsChecked();
160 sal_uInt16 nPrecision
= (mpEdDecimals
->IsEnabled())
161 ? (sal_uInt16
)mpEdDecimals
->GetValue()
163 sal_uInt16 nLeadZeroes
= (mpEdLeadZeroes
->IsEnabled())
164 ? (sal_uInt16
)mpEdLeadZeroes
->GetValue()
167 OUString sThousand
= OUString::number(static_cast<sal_Int32
>(bThousand
));
168 OUString sNegRed
= OUString::number(static_cast<sal_Int32
>(bNegRed
));
169 OUString sPrecision
= OUString::number(nPrecision
);
170 OUString sLeadZeroes
= OUString::number(nLeadZeroes
);
172 aFormat
+= sThousand
;
176 aFormat
+= sPrecision
;
178 aFormat
+= sLeadZeroes
;
181 SfxStringItem
aItem( SID_NUMBER_FORMAT
, aFormat
);
182 GetBindings()->GetDispatcher()->Execute(SID_NUMBER_FORMAT
, SFX_CALLMODE_RECORD
, &aItem
, 0L);
186 //////////////////////////////////////////////////////////////////////////////
188 NumberFormatPropertyPanel
* NumberFormatPropertyPanel::Create (
190 const cssu::Reference
<css::frame::XFrame
>& rxFrame
,
191 SfxBindings
* pBindings
)
194 throw lang::IllegalArgumentException("no parent Window given to NumberFormatPropertyPanel::Create", NULL
, 0);
196 throw lang::IllegalArgumentException("no XFrame given to NumberFormatPropertyPanel::Create", NULL
, 1);
197 if (pBindings
== NULL
)
198 throw lang::IllegalArgumentException("no SfxBindings given to NumberFormatPropertyPanel::Create", NULL
, 2);
200 return new NumberFormatPropertyPanel(
206 //////////////////////////////////////////////////////////////////////////////
208 void NumberFormatPropertyPanel::DataChanged(
209 const DataChangedEvent
& rEvent
)
214 //////////////////////////////////////////////////////////////////////////////
216 void NumberFormatPropertyPanel::HandleContextChange(
217 const ::sfx2::sidebar::EnumContext aContext
)
219 if(maContext
== aContext
)
225 maContext
= aContext
;
232 //////////////////////////////////////////////////////////////////////////////
234 void NumberFormatPropertyPanel::NotifyItemUpdate(
237 const SfxPoolItem
* pState
,
238 const bool bIsEnabled
)
244 case SID_NUMBER_TYPE_FORMAT
:
246 if( eState
>= SFX_ITEM_AVAILABLE
)
248 const SfxInt16Item
* pItem
= (const SfxInt16Item
*)pState
;
249 sal_uInt16 nVal
= pItem
->GetValue();
250 mnCategorySelected
= nVal
;
251 mpLbCategory
->SelectEntryPos(nVal
);
254 mpBtnThousand
->Enable();
255 mpBtnNegRed
->Enable();
256 mpEdDecimals
->Enable();
257 mpEdLeadZeroes
->Enable();
261 mpBtnThousand
->Disable();
262 mpBtnNegRed
->Disable();
263 mpEdDecimals
->Disable();
264 mpEdLeadZeroes
->Disable();
269 mpLbCategory
->SetNoSelection();
270 mnCategorySelected
= 0;
271 mpBtnThousand
->Disable();
272 mpBtnNegRed
->Disable();
273 mpEdDecimals
->Disable();
274 mpEdLeadZeroes
->Disable();
278 case SID_NUMBER_FORMAT
:
282 sal_uInt16 nPrecision
= 0;
283 sal_uInt16 nLeadZeroes
= 0;
284 if( eState
>= SFX_ITEM_AVAILABLE
)
286 const SfxStringItem
* pItem
= (const SfxStringItem
*)pState
;
287 OUString aCode
= pItem
->GetValue();
288 /* if(aCode.Equals(String::CreateFromAscii("General")))
290 mnCategorySelected = 0;
291 mpLbCategory->SelectEntryPos(0);
292 mpBtnThousand->Check(0);
293 mpBtnNegRed->Check(0);
294 mpEdDecimals->SetValue(0);
295 mpEdLeadZeroes->SetValue(1);
298 else if( mpLbCategory->GetSelectEntryPos() == 0 )
300 mnCategorySelected = 1;
301 mpLbCategory->SelectEntryPos(1);
303 sal_uInt16 aLen
= aCode
.getLength();
304 OUString
* sFormat
= new OUString
[4];
305 OUString sTmpStr
= "";
306 sal_uInt16 nCount
= 0;
307 sal_uInt16 nStrCount
= 0;
308 while( nCount
< aLen
)
310 sal_Unicode cChar
= aCode
[nCount
];
313 sFormat
[nStrCount
] = sTmpStr
;
319 sTmpStr
+= OUString(cChar
);
323 bThousand
= sFormat
[0].toInt32();
324 bNegRed
= sFormat
[1].toInt32();
325 nPrecision
= (sal_uInt16
)sFormat
[2].toInt32();
326 nLeadZeroes
= (sal_uInt16
)sFormat
[3].toInt32();
336 mpBtnThousand
->Check(bThousand
);
337 mpBtnNegRed
->Check(bNegRed
);
338 mpEdDecimals
->SetValue(nPrecision
);
339 mpEdLeadZeroes
->SetValue(nLeadZeroes
);
346 //////////////////////////////////////////////////////////////////////////////
348 SfxBindings
* NumberFormatPropertyPanel::GetBindings()
353 //////////////////////////////////////////////////////////////////////////////
356 }} // end of namespace ::sc::sidebar
358 //////////////////////////////////////////////////////////////////////////////
361 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */