1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 #include "precompiled_sc.hxx" 23 24 #include <sfx2/sidebar/propertypanel.hrc> 25 #include <sfx2/sidebar/Theme.hxx> 26 #include <sfx2/sidebar/ControlFactory.hxx> 27 #include <NumberFormatPropertyPanel.hxx> 28 #include <NumberFormatPropertyPanel.hrc> 29 #include "sc.hrc" 30 #include "scresid.hxx" 31 #include <sfx2/bindings.hxx> 32 #include <sfx2/dispatch.hxx> 33 #include <sfx2/imagemgr.hxx> 34 #include <vcl/fixed.hxx> 35 #include <vcl/lstbox.hxx> 36 #include <vcl/field.hxx> 37 #include <vcl/toolbox.hxx> 38 #include <svl/intitem.hxx> 39 #include <svl/stritem.hxx> 40 41 using namespace css; 42 using namespace cssu; 43 using ::sfx2::sidebar::Theme; 44 45 #define A2S(pString) (::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(pString))) 46 47 ////////////////////////////////////////////////////////////////////////////// 48 // namespace open 49 50 namespace sc { namespace sidebar { 51 52 ////////////////////////////////////////////////////////////////////////////// 53 54 NumberFormatPropertyPanel::NumberFormatPropertyPanel( 55 Window* pParent, 56 const cssu::Reference<css::frame::XFrame>& rxFrame, 57 SfxBindings* pBindings) 58 : Control( 59 pParent, 60 ScResId(RID_PROPERTYPANEL_SC_NUMBERFORMAT)), 61 mpFtCategory(new FixedText(this, ScResId(FT_CATEGORY))), 62 mpLbCategory(new ListBox(this, ScResId(LB_CATEGORY))), 63 mpTBCategoryBackground(sfx2::sidebar::ControlFactory::CreateToolBoxBackground(this)), 64 mpTBCategory(sfx2::sidebar::ControlFactory::CreateToolBox(mpTBCategoryBackground.get(), ScResId(TBX_CATEGORY))), 65 mpFtDecimals(new FixedText(this, ScResId(FT_DECIMALS))), 66 mpEdDecimals(new NumericField(this, ScResId(ED_DECIMALS))), 67 mpFtLeadZeroes(new FixedText(this, ScResId(FT_LEADZEROES))), 68 mpEdLeadZeroes(new NumericField(this, ScResId(ED_LEADZEROES))), 69 mpBtnNegRed(new CheckBox(this, ScResId(BTN_NEGRED))), 70 mpBtnThousand(new CheckBox(this, ScResId(BTN_THOUSAND))), 71 maNumFormatControl(SID_NUMBER_TYPE_FORMAT, *pBindings, *this), 72 73 // Caution! SID_NUMBER_FORMAT is reworked in symphony code, may be needed (!) If 74 // yes, grep for it in SC and symphony (!) 75 maFormatControl(SID_NUMBER_FORMAT, *pBindings, *this), 76 77 mnCategorySelected(0), 78 mxFrame(rxFrame), 79 maContext(), 80 mpBindings(pBindings) 81 { 82 Initialize(); 83 FreeResource(); 84 } 85 86 ////////////////////////////////////////////////////////////////////////////// 87 88 NumberFormatPropertyPanel::~NumberFormatPropertyPanel() 89 { 90 // Destroy the toolboxes, then their background windows. 91 mpTBCategory.reset(); 92 mpTBCategoryBackground.reset(); 93 } 94 95 ////////////////////////////////////////////////////////////////////////////// 96 97 void NumberFormatPropertyPanel::Initialize() 98 { 99 Link aLink = LINK(this, NumberFormatPropertyPanel, NumFormatSelectHdl); 100 mpLbCategory->SetSelectHdl ( aLink ); 101 mpLbCategory->SelectEntryPos(0); 102 mpLbCategory->SetAccessibleName(::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Category"))); //wj acc 103 mpLbCategory->SetDropDownLineCount(mpLbCategory->GetEntryCount()); 104 105 // Note that we use icons from UNO commands that are not in every case the commands 106 // that are really dispatched. They just look right. 107 mpTBCategory->SetItemImage( 108 ID_NUMBER, 109 GetImage(mxFrame, A2S(".uno:NumericField"), sal_False, Theme::IsHighContrastMode())); 110 mpTBCategory->SetItemImage( 111 ID_PERCENT, 112 GetImage(mxFrame, A2S(".uno:NumberFormatPercent"), sal_False, Theme::IsHighContrastMode())); 113 mpTBCategory->SetItemImage( 114 ID_CURRENCY, 115 GetImage(mxFrame, A2S(".uno:NumberFormatCurrency"), sal_False, Theme::IsHighContrastMode())); 116 mpTBCategory->SetItemImage( 117 ID_DATE, 118 GetImage(mxFrame, A2S(".uno:NumberFormatDate"), sal_False, Theme::IsHighContrastMode())); 119 mpTBCategory->SetItemImage( 120 ID_TEXT, 121 GetImage(mxFrame, A2S(".uno:InsertFixedText"), sal_False, Theme::IsHighContrastMode())); 122 123 Size aTbxSize( mpTBCategory->CalcWindowSizePixel() ); 124 mpTBCategory->SetOutputSizePixel( aTbxSize ); 125 mpTBCategory->SetBackground(Wallpaper()); 126 mpTBCategory->SetPaintTransparent(true); 127 aLink = LINK(this, NumberFormatPropertyPanel, NumFormatHdl); 128 mpTBCategory->SetSelectHdl ( aLink ); 129 130 aLink = LINK(this, NumberFormatPropertyPanel, NumFormatValueHdl); 131 132 mpEdDecimals->SetModifyHdl( aLink ); 133 mpEdLeadZeroes->SetModifyHdl( aLink ); 134 mpEdDecimals->SetAccessibleName(::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Decimal Places"))); //wj acc 135 mpEdLeadZeroes->SetAccessibleName(::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Leading Zeroes"))); //wj acc 136 mpBtnNegRed->SetClickHdl( aLink ); 137 mpBtnThousand->SetClickHdl( aLink ); 138 139 mpLbCategory->SetAccessibleRelationLabeledBy(mpFtCategory.get()); 140 mpTBCategory->SetAccessibleRelationLabeledBy(mpTBCategory.get()); 141 mpEdDecimals->SetAccessibleRelationLabeledBy(mpFtDecimals.get()); 142 mpEdLeadZeroes->SetAccessibleRelationLabeledBy(mpFtLeadZeroes.get()); 143 } 144 145 ////////////////////////////////////////////////////////////////////////////// 146 147 IMPL_LINK( NumberFormatPropertyPanel, NumFormatHdl, ToolBox*, pBox ) 148 { 149 sal_uInt16 nVal = pBox->GetCurItemId(); 150 sal_uInt16 nId = 0; 151 switch(nVal) 152 { 153 case ID_NUMBER: 154 nId = 1; 155 break; 156 case ID_PERCENT: 157 nId = 2; 158 break; 159 case ID_CURRENCY: 160 nId = 3; 161 break; 162 case ID_DATE: 163 nId = 4; 164 break; 165 case ID_TEXT: 166 nId = 9; 167 break; 168 default: 169 ; 170 } 171 if( nId != mnCategorySelected ) 172 { 173 SfxUInt16Item aItem( SID_NUMBER_TYPE_FORMAT, nId ); 174 GetBindings()->GetDispatcher()->Execute(SID_NUMBER_TYPE_FORMAT, SFX_CALLMODE_RECORD, &aItem, 0L); 175 } 176 return 0L; 177 } 178 179 ////////////////////////////////////////////////////////////////////////////// 180 181 IMPL_LINK( NumberFormatPropertyPanel, NumFormatSelectHdl, ListBox*, pBox ) 182 { 183 sal_uInt16 nVal = pBox->GetSelectEntryPos(); 184 if( nVal != mnCategorySelected ) 185 { 186 SfxUInt16Item aItem( SID_NUMBER_TYPE_FORMAT, nVal ); 187 GetBindings()->GetDispatcher()->Execute(SID_NUMBER_TYPE_FORMAT, SFX_CALLMODE_RECORD, &aItem, 0L); 188 mnCategorySelected = nVal; 189 } 190 return 0L; 191 } 192 193 ////////////////////////////////////////////////////////////////////////////// 194 195 IMPL_LINK( NumberFormatPropertyPanel, NumFormatValueHdl, void*, EMPTYARG ) 196 { 197 String aFormat; 198 String sBreak = String::CreateFromAscii(","); 199 bool bThousand = mpBtnThousand->IsEnabled() 200 && mpBtnThousand->IsChecked(); 201 bool bNegRed = mpBtnNegRed->IsEnabled() 202 && mpBtnNegRed->IsChecked(); 203 sal_uInt16 nPrecision = (mpEdDecimals->IsEnabled()) 204 ? (sal_uInt16)mpEdDecimals->GetValue() 205 : (sal_uInt16)0; 206 sal_uInt16 nLeadZeroes = (mpEdLeadZeroes->IsEnabled()) 207 ? (sal_uInt16)mpEdLeadZeroes->GetValue() 208 : (sal_uInt16)0; 209 210 String sThousand = String::CreateFromInt32(bThousand); 211 String sNegRed = String::CreateFromInt32(bNegRed); 212 String sPrecision = String::CreateFromInt32(nPrecision); 213 String sLeadZeroes = String::CreateFromInt32(nLeadZeroes); 214 215 aFormat += sThousand; 216 aFormat += sBreak; 217 aFormat += sNegRed; 218 aFormat += sBreak; 219 aFormat += sPrecision; 220 aFormat += sBreak; 221 aFormat += sLeadZeroes; 222 aFormat += sBreak; 223 224 SfxStringItem aItem( SID_NUMBER_FORMAT, aFormat ); 225 GetBindings()->GetDispatcher()->Execute(SID_NUMBER_FORMAT, SFX_CALLMODE_RECORD, &aItem, 0L); 226 return 0L; 227 } 228 229 ////////////////////////////////////////////////////////////////////////////// 230 231 NumberFormatPropertyPanel* NumberFormatPropertyPanel::Create ( 232 Window* pParent, 233 const cssu::Reference<css::frame::XFrame>& rxFrame, 234 SfxBindings* pBindings) 235 { 236 if (pParent == NULL) 237 throw lang::IllegalArgumentException(A2S("no parent Window given to NumberFormatPropertyPanel::Create"), NULL, 0); 238 if ( ! rxFrame.is()) 239 throw lang::IllegalArgumentException(A2S("no XFrame given to NumberFormatPropertyPanel::Create"), NULL, 1); 240 if (pBindings == NULL) 241 throw lang::IllegalArgumentException(A2S("no SfxBindings given to NumberFormatPropertyPanel::Create"), NULL, 2); 242 243 return new NumberFormatPropertyPanel( 244 pParent, 245 rxFrame, 246 pBindings); 247 } 248 249 ////////////////////////////////////////////////////////////////////////////// 250 251 void NumberFormatPropertyPanel::DataChanged( 252 const DataChangedEvent& rEvent) 253 { 254 (void)rEvent; 255 } 256 257 ////////////////////////////////////////////////////////////////////////////// 258 259 void NumberFormatPropertyPanel::HandleContextChange( 260 const ::sfx2::sidebar::EnumContext aContext) 261 { 262 if(maContext == aContext) 263 { 264 // Nothing to do. 265 return; 266 } 267 268 maContext = aContext; 269 270 271 272 // todo 273 } 274 275 ////////////////////////////////////////////////////////////////////////////// 276 277 void NumberFormatPropertyPanel::NotifyItemUpdate( 278 sal_uInt16 nSID, 279 SfxItemState eState, 280 const SfxPoolItem* pState, 281 const bool bIsEnabled) 282 { 283 (void)bIsEnabled; 284 285 switch(nSID) 286 { 287 case SID_NUMBER_TYPE_FORMAT: 288 { 289 if( eState >= SFX_ITEM_AVAILABLE) 290 { 291 const SfxInt16Item* pItem = (const SfxInt16Item*)pState; 292 sal_uInt16 nVal = pItem->GetValue(); 293 mnCategorySelected = nVal; 294 mpLbCategory->SelectEntryPos(nVal); 295 if( nVal < 4 ) 296 { 297 mpBtnThousand->Enable(); 298 mpBtnNegRed->Enable(); 299 mpEdDecimals->Enable(); 300 mpEdLeadZeroes->Enable(); 301 } 302 else 303 { 304 mpBtnThousand->Disable(); 305 mpBtnNegRed->Disable(); 306 mpEdDecimals->Disable(); 307 mpEdLeadZeroes->Disable(); 308 } 309 } 310 else 311 { 312 mpLbCategory->SetNoSelection(); 313 mnCategorySelected = 0; 314 mpBtnThousand->Disable(); 315 mpBtnNegRed->Disable(); 316 mpEdDecimals->Disable(); 317 mpEdLeadZeroes->Disable(); 318 } 319 } 320 break; 321 case SID_NUMBER_FORMAT: 322 { 323 bool bThousand = 0; 324 bool bNegRed = 0; 325 sal_uInt16 nPrecision = 0; 326 sal_uInt16 nLeadZeroes = 0; 327 if( eState >= SFX_ITEM_AVAILABLE) 328 { 329 const SfxStringItem* pItem = (const SfxStringItem*)pState; 330 String aCode = pItem->GetValue(); 331 /* if(aCode.Equals(String::CreateFromAscii("General"))) 332 { 333 mnCategorySelected = 0; 334 mpLbCategory->SelectEntryPos(0); 335 mpBtnThousand->Check(0); 336 mpBtnNegRed->Check(0); 337 mpEdDecimals->SetValue(0); 338 mpEdLeadZeroes->SetValue(1); 339 break; 340 } 341 else if( mpLbCategory->GetSelectEntryPos() == 0 ) 342 { 343 mnCategorySelected = 1; 344 mpLbCategory->SelectEntryPos(1); 345 }*/ 346 sal_uInt16 aLen = aCode.Len(); 347 String* sFormat = new String[4]; 348 String sTmpStr = String::CreateFromAscii(""); 349 sal_uInt16 nCount = 0; 350 sal_uInt16 nStrCount = 0; 351 while( nCount < aLen ) 352 { 353 sal_Unicode cChar = aCode.GetChar(nCount); 354 if(cChar == sal_Unicode(',')) 355 { 356 sFormat[nStrCount] = sTmpStr; 357 sTmpStr = String::CreateFromAscii(""); 358 nStrCount++; 359 } 360 else 361 { 362 sTmpStr += cChar; 363 } 364 nCount++; 365 } 366 bThousand = sFormat[0].ToInt32(); 367 bNegRed = sFormat[1].ToInt32(); 368 nPrecision = (sal_uInt16)sFormat[2].ToInt32(); 369 nLeadZeroes = (sal_uInt16)sFormat[3].ToInt32(); 370 delete[] sFormat; 371 } 372 else 373 { 374 bThousand = 0; 375 bNegRed = 0; 376 nPrecision = 0; 377 nLeadZeroes = 1; 378 } 379 mpBtnThousand->Check(bThousand); 380 mpBtnNegRed->Check(bNegRed); 381 mpEdDecimals->SetValue(nPrecision); 382 mpEdLeadZeroes->SetValue(nLeadZeroes); 383 } 384 default: 385 ; 386 } 387 } 388 389 ////////////////////////////////////////////////////////////////////////////// 390 391 SfxBindings* NumberFormatPropertyPanel::GetBindings() 392 { 393 return mpBindings; 394 } 395 396 ////////////////////////////////////////////////////////////////////////////// 397 // namespace close 398 399 }} // end of namespace ::sc::sidebar 400 401 ////////////////////////////////////////////////////////////////////////////// 402 // eof 403