bump product version to 5.0.4.1
[LibreOffice.git] / cui / source / tabpages / numfmt.cxx
blob09bb1a641fa1f552ad85abc55aa6ca28186580c7
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 <svl/eitem.hxx>
21 #include <svl/intitem.hxx>
22 #include <sfx2/objsh.hxx>
23 #include <vcl/builder.hxx>
24 #include <vcl/svapp.hxx>
25 #include <vcl/settings.hxx>
26 #include <vcl/builderfactory.hxx>
27 #include <unotools/localedatawrapper.hxx>
28 #include <i18nlangtag/lang.h>
29 #include <i18nlangtag/mslangid.hxx>
30 #include <svx/dialogs.hrc>
31 #include <svtools/colorcfg.hxx>
33 #include <cuires.hrc>
35 #include <svx/numinf.hxx>
37 #include "numfmt.hxx"
38 #include <svx/numfmtsh.hxx>
39 #include <dialmgr.hxx>
40 #include <sfx2/request.hxx>
41 #include <sfx2/app.hxx>
42 #include <sfx2/basedlgs.hxx>
43 #include "svx/flagsdef.hxx"
44 #include <vector>
45 #include <com/sun/star/lang/XServiceInfo.hpp>
46 #include <boost/scoped_array.hpp>
48 using ::com::sun::star::uno::Reference;
49 using ::com::sun::star::lang::XServiceInfo;
50 using ::com::sun::star::uno::UNO_QUERY;
52 #define NUMKEY_UNDEFINED SAL_MAX_UINT32
54 // static ----------------------------------------------------------------
56 const sal_uInt16 SvxNumberFormatTabPage::pRanges[] =
58 SID_ATTR_NUMBERFORMAT_VALUE,
59 SID_ATTR_NUMBERFORMAT_INFO,
60 SID_ATTR_NUMBERFORMAT_NOLANGUAGE,
61 SID_ATTR_NUMBERFORMAT_NOLANGUAGE,
62 SID_ATTR_NUMBERFORMAT_ONE_AREA,
63 SID_ATTR_NUMBERFORMAT_ONE_AREA,
64 SID_ATTR_NUMBERFORMAT_SOURCE,
65 SID_ATTR_NUMBERFORMAT_SOURCE,
69 /*************************************************************************
70 #* Method: SvxNumberPreview
71 #*------------------------------------------------------------------------
73 #* Class: SvxNumberPreview
74 #* Function: Constructor of the class SvxNumberPreview
75 #* Input: Window, Resource-ID
76 #* Output: ---
78 #************************************************************************/
80 SvxNumberPreview::SvxNumberPreview(vcl::Window* pParent, WinBits nStyle)
81 : Window(pParent, nStyle)
82 , mnPos(-1)
83 , mnChar(0x0)
85 vcl::Font aFont( GetFont() );
86 aFont.SetTransparent( true );
87 aFont.SetColor( Application::GetSettings().GetStyleSettings().GetFieldColor() );
88 SetFont( aFont );
89 InitSettings( true, true );
90 SetBorderStyle( WindowBorderStyle::MONO );
93 VCL_BUILDER_FACTORY(SvxNumberPreview)
95 /*************************************************************************
96 #* Method: NotifyChange
97 #*------------------------------------------------------------------------
99 #* Class: SvxNumberPreview
100 #* Function: Function for changing the preview string
101 #* Input: String, color
102 #* Output: ---
104 #************************************************************************/
106 void SvxNumberPreview::NotifyChange( const OUString& rPrevStr,
107 const Color* pColor )
109 // detect and strip out '*' related placeholders
110 aPrevStr = rPrevStr;
111 mnPos = aPrevStr.indexOf( 0x1B );
112 if ( mnPos != -1 )
114 // Right during user input the star symbol is the very
115 // last character before the user enters another one.
116 if (mnPos < aPrevStr.getLength() - 1)
118 mnChar = aPrevStr[ mnPos + 1 ];
119 // delete placeholder and char to repeat
120 aPrevStr = aPrevStr.replaceAt( mnPos, 2, "" );
122 else
124 // delete placeholder
125 aPrevStr = aPrevStr.replaceAt( mnPos, 1, "" );
126 // do not attempt to draw a 0 fill character
127 mnPos = -1;
130 svtools::ColorConfig aColorConfig;
131 Color aWindowTextColor( aColorConfig.GetColorValue( svtools::FONTCOLOR ).nColor );
132 aPrevCol = pColor ? *pColor : aWindowTextColor;
133 Invalidate();
134 Update();
137 /*************************************************************************
138 #* Method: Paint
139 #*------------------------------------------------------------------------
141 #* Class: SvxNumberPreview
142 #* Function: Function for repainting the window.
143 #* Input: ---
144 #* Output: ---
146 #************************************************************************/
148 void SvxNumberPreview::Paint(vcl::RenderContext& rRenderContext, const Rectangle&)
150 vcl::Font aDrawFont = rRenderContext.GetFont();
151 Size aSzWnd(GetOutputSizePixel());
152 OUString aTmpStr( aPrevStr );
153 long nLeadSpace = (aSzWnd.Width() - rRenderContext.GetTextWidth(aTmpStr)) / 2;
155 aDrawFont.SetColor(aPrevCol);
156 rRenderContext.SetFont(aDrawFont);
158 if (mnPos != -1)
160 long nCharWidth = rRenderContext.GetTextWidth(OUString(mnChar));
162 int nNumCharsToInsert = 0;
163 if (nCharWidth > 0)
164 nNumCharsToInsert = nLeadSpace / nCharWidth;
166 if (nNumCharsToInsert > 0)
168 for (int i = 0; i < nNumCharsToInsert; ++i)
169 aTmpStr = aTmpStr.replaceAt(mnPos, 0, OUString(mnChar));
172 Point aPosText = Point((mnPos != -1) ? 0 : nLeadSpace,
173 (aSzWnd.Height() - GetTextHeight()) / 2);
174 rRenderContext.DrawText(aPosText, aTmpStr);
177 void SvxNumberPreview::InitSettings( bool bForeground, bool bBackground )
179 const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
181 if ( bForeground )
183 svtools::ColorConfig aColorConfig;
184 Color aTextColor( aColorConfig.GetColorValue( svtools::FONTCOLOR ).nColor );
186 if ( IsControlForeground() )
187 aTextColor = GetControlForeground();
188 SetTextColor( aTextColor );
191 if ( bBackground )
193 if ( IsControlBackground() )
194 SetBackground( GetControlBackground() );
195 else
196 SetBackground( rStyleSettings.GetWindowColor() );
198 Invalidate();
203 void SvxNumberPreview::StateChanged( StateChangedType nType )
205 if ( nType == StateChangedType::ControlForeground )
206 InitSettings( true, false );
207 else if ( nType == StateChangedType::ControlBackground )
208 InitSettings( false, true );
210 Window::StateChanged( nType );
215 void SvxNumberPreview::DataChanged( const DataChangedEvent& rDCEvt )
217 Window::DataChanged( rDCEvt );
219 if ( ( rDCEvt.GetType() == DataChangedEventType::SETTINGS ) && ( rDCEvt.GetFlags() & AllSettingsFlags::STYLE ) )
220 InitSettings( true, true );
223 // class SvxNumberFormatTabPage ------------------------------------------
225 #define REMOVE_DONTKNOW() \
226 if ( !m_pFtLanguage->IsEnabled() ) \
228 m_pFtLanguage->Enable(); \
229 m_pLbLanguage->Enable(); \
230 m_pLbLanguage->SelectLanguage( pNumFmtShell->GetCurLanguage() ); \
233 #define HDL(hdl) LINK( this, SvxNumberFormatTabPage, hdl )
235 SvxNumberFormatTabPage::SvxNumberFormatTabPage(vcl::Window* pParent,
236 const SfxItemSet& rCoreAttrs)
237 : SfxTabPage(pParent, "NumberingFormatPage",
238 "cui/ui/numberingformatpage.ui", &rCoreAttrs)
239 , pNumItem(NULL)
240 , pNumFmtShell(NULL)
241 , nInitFormat(ULONG_MAX)
242 , sAutomaticEntry(CUI_RES(RID_SVXSTR_AUTO_ENTRY))
243 , sThousandSeparator(CUI_RES(RID_SVXSTR_THOUSAND_SEP))
244 , sEngineeringNotation(CUI_RES(RID_SVXSTR_ENGINEERING))
245 , pLastActivWindow(NULL)
247 get(m_pFtCategory, "categoryft");
248 get(m_pLbCategory, "categorylb");
249 get(m_pFtFormat, "formatft");
250 get(m_pLbCurrency, "currencylb");
251 get(m_pLbFormat, "formatlb");
252 long nWidth = approximate_char_width() * 26;
253 m_pLbFormat->set_width_request(nWidth);
254 m_pLbCurrency->set_width_request(nWidth);
255 get(m_pFtLanguage, "languageft");
256 get(m_pLbLanguage, "languagelb");
257 get(m_pCbSourceFormat, "sourceformat");
258 get(m_pWndPreview, "preview");
259 get(m_pFtOptions, "optionsft");
260 get(m_pFtDecimals, "decimalsft");
261 get(m_pEdDecimals, "decimalsed");
262 get(m_pBtnNegRed, "negnumred");
263 get(m_pFtLeadZeroes, "leadzerosft");
264 get(m_pEdLeadZeroes, "leadzerosed");
265 get(m_pBtnThousand, "thousands");
266 get(m_pFormatCodeFrame, "formatcode");
267 get(m_pEdFormat, "formatted");
268 get(m_pIbAdd, "add");
269 get(m_pIbInfo, "edit");
270 get(m_pIbRemove, "delete");
271 get(m_pFtComment, "commentft");
272 get(m_pEdComment, "commented");
274 m_pLbCategory->SetDropDownLineCount(8);
275 m_pWndPreview->set_height_request(GetTextHeight()*3);
277 Init_Impl();
278 SetExchangeSupport(); // this page needs ExchangeSupport
279 nFixedCategory=-1;
282 SvxNumberFormatTabPage::~SvxNumberFormatTabPage()
284 disposeOnce();
288 void SvxNumberFormatTabPage::dispose()
290 delete pNumFmtShell;
291 pNumFmtShell = NULL;
292 delete pNumItem;
293 pNumItem = NULL;
294 m_pFtCategory.clear();
295 m_pLbCategory.clear();
296 m_pFtFormat.clear();
297 m_pLbCurrency.clear();
298 m_pLbFormat.clear();
299 m_pFtLanguage.clear();
300 m_pLbLanguage.clear();
301 m_pCbSourceFormat.clear();
302 m_pWndPreview.clear();
303 m_pFtOptions.clear();
304 m_pFtDecimals.clear();
305 m_pEdDecimals.clear();
306 m_pBtnNegRed.clear();
307 m_pFtLeadZeroes.clear();
308 m_pEdLeadZeroes.clear();
309 m_pBtnThousand.clear();
310 m_pFormatCodeFrame.clear();
311 m_pEdFormat.clear();
312 m_pIbAdd.clear();
313 m_pIbInfo.clear();
314 m_pIbRemove.clear();
315 m_pFtComment.clear();
316 m_pEdComment.clear();
317 pLastActivWindow.clear();
318 SfxTabPage::dispose();
321 void SvxNumberFormatTabPage::Init_Impl()
323 bNumItemFlag=true;
324 bOneAreaFlag=false;
326 m_pIbAdd->Enable(false );
327 m_pIbRemove->Enable(false );
328 m_pIbInfo->Enable(false );
330 m_pEdComment->SetText(m_pLbCategory->GetEntry(1)); // string for user defined
332 m_pEdComment->Hide();
334 m_pCbSourceFormat->Check( false );
335 m_pCbSourceFormat->Disable();
336 m_pCbSourceFormat->Hide();
338 Link<> aLink = LINK( this, SvxNumberFormatTabPage, SelFormatHdl_Impl );
340 m_pLbCategory->SetSelectHdl( aLink );
341 m_pLbFormat->SetSelectHdl( aLink );
342 m_pLbLanguage->SetSelectHdl( aLink );
343 m_pLbCurrency->SetSelectHdl( aLink );
344 m_pCbSourceFormat->SetClickHdl( aLink );
346 aLink = LINK( this, SvxNumberFormatTabPage, OptHdl_Impl );
348 m_pEdDecimals->SetModifyHdl( aLink );
349 m_pEdLeadZeroes->SetModifyHdl( aLink );
350 m_pBtnNegRed->SetClickHdl( aLink );
351 m_pBtnThousand->SetClickHdl( aLink );
352 m_pLbFormat->SetDoubleClickHdl( HDL( DoubleClickHdl_Impl ) );
353 m_pEdFormat->SetModifyHdl( HDL( EditHdl_Impl ) );
354 m_pIbAdd->SetClickHdl( HDL( ClickHdl_Impl ) );
355 m_pIbRemove->SetClickHdl( HDL( ClickHdl_Impl ) );
356 m_pIbInfo->SetClickHdl( HDL( ClickHdl_Impl ) );
357 UpdateThousandEngineeringText();
359 aLink = LINK( this, SvxNumberFormatTabPage, LostFocusHdl_Impl);
361 m_pEdComment->SetLoseFocusHdl( aLink);
362 aResetWinTimer.SetTimeoutHdl(LINK( this, SvxNumberFormatTabPage, TimeHdl_Impl));
363 aResetWinTimer.SetTimeout( 10);
365 // initialize language ListBox
367 m_pLbLanguage->InsertLanguage( LANGUAGE_SYSTEM );
368 /* TODO: any reason we're doing a manual init here instead of using
369 * SvxLanguageBoxBase::SetLanguageList( SvxLanguageListFlags::ONLY_KNOWN, ...)? */
370 // Don't list ambiguous locales where we won't be able to convert the
371 // LanguageType back to an identical Language_Country name and therefore
372 // couldn't load the i18n LocaleData. Show DebugMsg in non-PRODUCT version.
373 ::com::sun::star::uno::Sequence< sal_uInt16 > xLang =
374 LocaleDataWrapper::getInstalledLanguageTypes();
375 sal_Int32 nCount = xLang.getLength();
376 for ( sal_Int32 i=0; i<nCount; i++ )
378 if (!MsLangId::isLegacy( xLang[i]))
379 m_pLbLanguage->InsertLanguage( xLang[i] );
383 VclPtr<SfxTabPage> SvxNumberFormatTabPage::Create( vcl::Window* pParent,
384 const SfxItemSet* rAttrSet )
386 return VclPtr<SvxNumberFormatTabPage>::Create( pParent, *rAttrSet );
390 /*************************************************************************
391 #* Method: Reset
392 #*------------------------------------------------------------------------
394 #* Class: SvxNumberFormatTabPage
395 #* Function: The dialog's attributes are reset
396 #* using the Itemset.
397 #* Input: SfxItemSet
398 #* Output: ---
400 #************************************************************************/
402 void SvxNumberFormatTabPage::Reset( const SfxItemSet* rSet )
404 const SfxUInt32Item* pValFmtAttr = NULL;
405 const SfxPoolItem* pItem = NULL;
406 const SfxBoolItem* pAutoEntryAttr = NULL;
408 sal_uInt16 nCatLbSelPos = 0;
409 sal_uInt16 nFmtLbSelPos = 0;
410 LanguageType eLangType = LANGUAGE_DONTKNOW;
411 std::vector<OUString> aFmtEntryList;
412 SvxNumberValueType eValType = SVX_VALUE_TYPE_UNDEFINED;
413 double nValDouble = 0;
414 OUString aValString;
416 SfxItemState eState = rSet->GetItemState( GetWhich( SID_ATTR_NUMBERFORMAT_NOLANGUAGE ),true,&pItem);
418 if(eState==SfxItemState::SET)
420 const SfxBoolItem* pBoolLangItem = static_cast<const SfxBoolItem*>(
421 GetItem( *rSet, SID_ATTR_NUMBERFORMAT_NOLANGUAGE));
423 if(pBoolLangItem!=NULL && pBoolLangItem->GetValue())
425 HideLanguage();
427 else
429 HideLanguage(false);
434 eState = rSet->GetItemState( GetWhich( SID_ATTR_NUMBERFORMAT_INFO ),true,&pItem);
436 if(eState==SfxItemState::SET)
438 if(pNumItem==NULL)
440 bNumItemFlag=true;
441 pNumItem= static_cast<SvxNumberInfoItem *>(pItem->Clone());
443 else
445 bNumItemFlag=false;
448 else
450 bNumItemFlag=false;
454 eState = rSet->GetItemState( GetWhich( SID_ATTR_NUMBERFORMAT_ONE_AREA ));
456 if(eState==SfxItemState::SET)
458 const SfxBoolItem* pBoolItem = static_cast<const SfxBoolItem*>(
459 GetItem( *rSet, SID_ATTR_NUMBERFORMAT_ONE_AREA));
461 if(pBoolItem!=NULL)
463 bOneAreaFlag= pBoolItem->GetValue();
467 eState = rSet->GetItemState( GetWhich( SID_ATTR_NUMBERFORMAT_SOURCE ) );
469 if ( eState == SfxItemState::SET )
471 const SfxBoolItem* pBoolItem = static_cast<const SfxBoolItem*>(
472 GetItem( *rSet, SID_ATTR_NUMBERFORMAT_SOURCE ));
473 if ( pBoolItem )
474 m_pCbSourceFormat->Check( pBoolItem->GetValue() );
475 else
476 m_pCbSourceFormat->Check( false );
477 m_pCbSourceFormat->Enable();
478 m_pCbSourceFormat->Show();
480 else
482 bool bInit = false; // set to sal_True for debug test
483 m_pCbSourceFormat->Check( bInit );
484 m_pCbSourceFormat->Enable( bInit );
485 m_pCbSourceFormat->Show( bInit );
488 // pNumItem must have been set from outside!
489 DBG_ASSERT( pNumItem, "No NumberInfo, no NumberFormatter, good bye.CRASH. :-(" );
491 eState = rSet->GetItemState( GetWhich( SID_ATTR_NUMBERFORMAT_VALUE ) );
493 if ( SfxItemState::DONTCARE != eState )
494 pValFmtAttr = static_cast<const SfxUInt32Item*>(
495 GetItem( *rSet, SID_ATTR_NUMBERFORMAT_VALUE ));
497 eValType = pNumItem->GetValueType();
499 switch ( eValType )
501 case SVX_VALUE_TYPE_STRING:
502 aValString = pNumItem->GetValueString();
503 break;
504 case SVX_VALUE_TYPE_NUMBER:
505 // #50441# string may be set in addition to the value
506 aValString = pNumItem->GetValueString();
507 nValDouble = pNumItem->GetValueDouble();
508 break;
509 case SVX_VALUE_TYPE_UNDEFINED:
510 default:
511 break;
514 if ( pNumFmtShell )
515 delete pNumFmtShell; // delete old shell if applicable (== reset)
517 nInitFormat = ( pValFmtAttr ) // memorize init key
518 ? pValFmtAttr->GetValue() // (for FillItemSet())
519 : ULONG_MAX; // == DONT_KNOW
522 if ( eValType == SVX_VALUE_TYPE_STRING )
523 pNumFmtShell =SvxNumberFormatShell::Create(
524 pNumItem->GetNumberFormatter(),
525 (pValFmtAttr) ? nInitFormat : 0L,
526 eValType,
527 aValString );
528 else
529 pNumFmtShell =SvxNumberFormatShell::Create(
530 pNumItem->GetNumberFormatter(),
531 (pValFmtAttr) ? nInitFormat : 0L,
532 eValType,
533 nValDouble,
534 &aValString );
537 bool bUseStarFormat = false;
538 SfxObjectShell* pDocSh = SfxObjectShell::Current();
539 if ( pDocSh )
541 // is this a calc document
542 Reference< XServiceInfo > xSI( pDocSh->GetModel(), UNO_QUERY );
543 if ( xSI.is() )
544 bUseStarFormat = xSI->supportsService("com.sun.star.sheet.SpreadsheetDocument");
546 pNumFmtShell->SetUseStarFormat( bUseStarFormat );
548 FillCurrencyBox();
550 OUString aPrevString;
551 Color* pDummy = NULL;
552 pNumFmtShell->GetInitSettings( nCatLbSelPos, eLangType, nFmtLbSelPos,
553 aFmtEntryList, aPrevString, pDummy );
555 if (nCatLbSelPos==CAT_CURRENCY)
557 sal_Int32 nPos = pNumFmtShell->GetCurrencySymbol();
558 if (nPos == 0)
559 // Enable "Automatically" if currently used so it is selectable.
560 m_pLbCurrency->SetEntryFlags( nPos, ListBoxEntryFlags::NONE );
562 m_pLbCurrency->SelectEntryPos(nPos);
565 nFixedCategory=nCatLbSelPos;
566 if(bOneAreaFlag)
568 OUString sFixedCategory = m_pLbCategory->GetEntry(nFixedCategory);
569 m_pLbCategory->Clear();
570 m_pLbCategory->InsertEntry(sFixedCategory);
571 SetCategory(0);
573 else
575 SetCategory(nCatLbSelPos );
577 eState = rSet->GetItemState( GetWhich( SID_ATTR_NUMBERFORMAT_ADD_AUTO ) );
578 if(SfxItemState::SET == eState)
579 pAutoEntryAttr = static_cast<const SfxBoolItem*>(
580 GetItem( *rSet, SID_ATTR_NUMBERFORMAT_ADD_AUTO ));
581 // no_NO is an alias for nb_NO and normally isn't listed, we need it for
582 // backwards compatibility, but only if the format passed is of
583 // LanguageType no_NO.
584 if ( eLangType == LANGUAGE_NORWEGIAN )
586 m_pLbLanguage->RemoveLanguage( eLangType ); // in case we're already called
587 m_pLbLanguage->InsertLanguage( eLangType );
589 m_pLbLanguage->SelectLanguage( eLangType );
590 if(pAutoEntryAttr)
591 AddAutomaticLanguage_Impl(eLangType, pAutoEntryAttr->GetValue());
592 UpdateFormatListBox_Impl(false,true);
594 //! This spoils everything because it rematches currency formats based on
595 //! the selected m_pLbCurrency entry instead of the current format.
596 //! Besides that everything seems to be initialized by now, so why call it?
597 // SelFormatHdl_Impl( m_pLbCategory );
599 if ( pValFmtAttr )
601 EditHdl_Impl(m_pEdFormat); // UpdateOptions_Impl() als Seiteneffekt
603 else // DONT_KNOW
605 // everything disabled except direct input or changing the category
606 Obstructing();
609 if ( m_pCbSourceFormat->IsChecked() )
611 // everything disabled except SourceFormat checkbox
612 EnableBySourceFormat_Impl();
616 /*************************************************************************
617 #* Method: Obstructing
618 #*------------------------------------------------------------------------
620 #* Class: SvxNumberFormatTabPage
621 #* Function: Disable the controls except from changing the category
622 #* and direct input.
623 #* Input: ---
624 #* Output: ---
626 #************************************************************************/
627 void SvxNumberFormatTabPage::Obstructing()
629 m_pLbFormat->SetNoSelection();
630 m_pLbLanguage->SetNoSelection();
631 m_pFtLanguage->Disable();
632 m_pLbLanguage->Disable();
634 m_pIbAdd->Enable(false );
635 m_pIbRemove->Enable(false );
636 m_pIbInfo->Enable(false );
638 m_pBtnNegRed->Disable();
639 m_pBtnThousand->Disable();
640 m_pFtLeadZeroes->Disable();
641 m_pFtDecimals->Disable();
642 m_pEdLeadZeroes->Disable();
643 m_pEdDecimals->Disable();
644 m_pFtOptions->Disable();
645 m_pEdDecimals->SetText( OUString() );
646 m_pEdLeadZeroes->SetText( OUString() );
647 m_pBtnNegRed->Check( false );
648 m_pBtnThousand->Check( false );
649 m_pWndPreview->NotifyChange( OUString() );
651 m_pLbCategory->SelectEntryPos( 0 );
652 m_pEdFormat->SetText( OUString() );
653 m_pFtComment->SetText( OUString() );
654 m_pEdComment->SetText(m_pLbCategory->GetEntry(1)); // string for user defined
656 m_pEdFormat->GrabFocus();
660 /*************************************************************************
661 #* Enable/Disable dialog parts depending on the value of the SourceFormat
662 #* checkbox.
663 #************************************************************************/
664 void SvxNumberFormatTabPage::EnableBySourceFormat_Impl()
666 bool bEnable = !m_pCbSourceFormat->IsChecked();
667 if ( !bEnable )
668 m_pCbSourceFormat->GrabFocus();
669 m_pFtCategory->Enable( bEnable );
670 m_pLbCategory->Enable( bEnable );
671 m_pFtFormat->Enable( bEnable );
672 m_pLbCurrency->Enable( bEnable );
673 m_pLbFormat->Enable( bEnable );
674 m_pFtLanguage->Enable( bEnable );
675 m_pLbLanguage->Enable( bEnable );
676 m_pFtDecimals->Enable( bEnable );
677 m_pEdDecimals->Enable( bEnable );
678 m_pFtLeadZeroes->Enable( bEnable );
679 m_pEdLeadZeroes->Enable( bEnable );
680 m_pBtnNegRed->Enable( bEnable );
681 m_pBtnThousand->Enable( bEnable );
682 m_pFtOptions->Enable( bEnable );
683 m_pFormatCodeFrame->Enable( bEnable );
684 m_pLbFormat->Invalidate(); // #i43322#
688 /*************************************************************************
689 #* Method: HideLanguage
690 #*------------------------------------------------------------------------
692 #* Class: SvxNumberFormatTabPage
693 #* Function: Hides the language settings:
694 #* Input: sal_Bool nFlag
695 #* Output: ---
697 #************************************************************************/
699 void SvxNumberFormatTabPage::HideLanguage(bool nFlag)
701 m_pFtLanguage->Show(!nFlag);
702 m_pLbLanguage->Show(!nFlag);
705 /*************************************************************************
706 #* Method: FillItemSet
707 #*------------------------------------------------------------------------
709 #* Class: SvxNumberFormatTabPage
710 #* Function: Adjusts the attributes in the ItemSet,
711 #* and - if bNumItemFlag is not set - the
712 #* numItem in the DocShell.
713 #* Input: SfxItemSet
714 #* Output: ---
716 #************************************************************************/
718 bool SvxNumberFormatTabPage::FillItemSet( SfxItemSet* rCoreAttrs )
720 bool bDataChanged = m_pFtLanguage->IsEnabled() || m_pCbSourceFormat->IsEnabled();
721 if ( bDataChanged )
723 const SfxItemSet& rMyItemSet = GetItemSet();
724 sal_uInt16 nWhich = GetWhich( SID_ATTR_NUMBERFORMAT_VALUE );
725 SfxItemState eItemState = rMyItemSet.GetItemState( nWhich, false );
727 // OK chosen - Is format code input entered already taken over?
728 // If not, simulate Add. Upon syntax error ignore input and prevent Put.
729 OUString aFormat = m_pEdFormat->GetText();
730 sal_uInt32 nCurKey = pNumFmtShell->GetCurNumFmtKey();
732 if ( m_pIbAdd->IsEnabled() || pNumFmtShell->IsTmpCurrencyFormat(aFormat) )
733 { // #79599# It is not sufficient to just add the format code (or
734 // delete it in case of bOneAreaFlag and resulting category change).
735 // Upon switching tab pages we need all settings to be consistent
736 // in case this page will be redisplayed later.
737 bDataChanged = (ClickHdl_Impl(m_pIbAdd) != 0);
738 nCurKey = pNumFmtShell->GetCurNumFmtKey();
740 else if(nCurKey == NUMKEY_UNDEFINED)
741 { // something went wrong, e.g. in Writer #70281#
742 pNumFmtShell->FindEntry(aFormat, &nCurKey);
746 // Chosen format:
748 if ( bDataChanged )
750 bDataChanged = ( nInitFormat != nCurKey );
752 if (bDataChanged)
754 rCoreAttrs->Put( SfxUInt32Item( nWhich, nCurKey ) );
756 else if(SfxItemState::DEFAULT == eItemState)
758 rCoreAttrs->ClearItem( nWhich );
763 // List of changed user defined formats:
765 const size_t nDelCount = pNumFmtShell->GetUpdateDataCount();
767 if ( nDelCount > 0 )
769 boost::scoped_array<sal_uInt32> pDelArr(new sal_uInt32[nDelCount]);
771 pNumFmtShell->GetUpdateData( pDelArr.get(), nDelCount );
772 pNumItem->SetDelFormatArray( pDelArr.get(), nDelCount );
774 if(bNumItemFlag)
776 rCoreAttrs->Put( *pNumItem );
778 else
780 SfxObjectShell* pDocSh = SfxObjectShell::Current();
782 DBG_ASSERT( pDocSh, "DocShell not found!" );
785 if ( pDocSh )
786 pDocSh->PutItem( *pNumItem );
791 // Whether source format is to be taken or not:
793 if ( m_pCbSourceFormat->IsEnabled() )
795 sal_uInt16 _nWhich = GetWhich( SID_ATTR_NUMBERFORMAT_SOURCE );
796 SfxItemState _eItemState = rMyItemSet.GetItemState( _nWhich, false );
797 const SfxBoolItem* pBoolItem = static_cast<const SfxBoolItem*>(
798 GetItem( rMyItemSet, SID_ATTR_NUMBERFORMAT_SOURCE ));
799 bool bOld = pBoolItem && pBoolItem->GetValue();
800 rCoreAttrs->Put( SfxBoolItem( _nWhich, m_pCbSourceFormat->IsChecked() ) );
801 if ( !bDataChanged )
802 bDataChanged = (bOld != m_pCbSourceFormat->IsChecked() ||
803 _eItemState != SfxItemState::SET);
806 // FillItemSet is only called on OK, here we can notify the
807 // NumberFormatShell that all new user defined formats are valid.
808 pNumFmtShell->ValidateNewEntries();
809 if(m_pLbLanguage->IsVisible() &&
810 LISTBOX_ENTRY_NOTFOUND != m_pLbLanguage->GetEntryPos(sAutomaticEntry))
811 rCoreAttrs->Put(SfxBoolItem(SID_ATTR_NUMBERFORMAT_ADD_AUTO,
812 m_pLbLanguage->GetSelectEntry() == sAutomaticEntry));
815 return bDataChanged;
819 SfxTabPage::sfxpg SvxNumberFormatTabPage::DeactivatePage( SfxItemSet* _pSet )
821 if ( _pSet )
822 FillItemSet( _pSet );
823 return LEAVE_PAGE;
826 void SvxNumberFormatTabPage::SetInfoItem( const SvxNumberInfoItem& rItem )
828 if(pNumItem==NULL)
830 pNumItem = static_cast<SvxNumberInfoItem*>(rItem.Clone());
834 void SvxNumberFormatTabPage::FillFormatListBox_Impl( std::vector<OUString>& rEntries )
836 OUString aEntry;
837 OUString aTmpString;
838 vcl::Font aFont=m_pLbCategory->GetFont();
839 size_t i = 0;
840 short nTmpCatPos;
842 m_pLbFormat->Clear();
843 m_pLbFormat->SetUpdateMode( false );
845 if( rEntries.empty() )
846 return;
848 if(bOneAreaFlag)
850 nTmpCatPos=nFixedCategory;
852 else
854 nTmpCatPos=m_pLbCategory->GetSelectEntryPos();
857 switch (nTmpCatPos)
859 case CAT_ALL:
860 case CAT_TEXT:
861 case CAT_NUMBER: i=1;
862 aEntry=rEntries[0];
863 if (nTmpCatPos == CAT_TEXT)
864 aTmpString=aEntry;
865 else
866 aTmpString = pNumFmtShell->GetStandardName();
867 m_pLbFormat->InsertFontEntry( aTmpString, aFont );
868 break;
870 default: break;
873 if(pNumFmtShell!=NULL)
875 for ( ; i < rEntries.size(); ++i )
877 aEntry = rEntries[i];
878 short aPrivCat = pNumFmtShell->GetCategory4Entry( static_cast<short>(i) );
879 if(aPrivCat!=CAT_TEXT)
881 Color* pPreviewColor = NULL;
882 OUString aPreviewString( GetExpColorString( pPreviewColor, aEntry, aPrivCat ) );
883 vcl::Font aEntryFont( m_pLbFormat->GetFont() );
884 m_pLbFormat->InsertFontEntry( aPreviewString, aEntryFont, pPreviewColor );
886 else
888 m_pLbFormat->InsertFontEntry(aEntry,aFont);
892 m_pLbFormat->SetUpdateMode( true );
893 rEntries.clear();
896 /*************************************************************************
897 #* Method: UpdateOptions_Impl
898 #*------------------------------------------------------------------------
900 #* Class: SvxNumberFormatTabPage
901 #* Function: Adjusts the options attributes
902 #* depending on the selected format.
903 #* Input: Flag, whether the category has changed.
904 #* Output: ---
906 #************************************************************************/
908 void SvxNumberFormatTabPage::UpdateOptions_Impl( bool bCheckCatChange /*= sal_False*/ )
910 OUString theFormat = m_pEdFormat->GetText();
911 sal_Int32 nCurCategory = m_pLbCategory->GetSelectEntryPos();
912 sal_uInt16 nCategory = static_cast<sal_uInt16>(nCurCategory);
913 sal_uInt16 nDecimals = 0;
914 sal_uInt16 nZeroes = 0;
915 bool bNegRed = false;
916 bool bThousand = false;
917 sal_Int32 nCurrencyPos =m_pLbCurrency->GetSelectEntryPos();
919 if(bOneAreaFlag)
920 nCurCategory=nFixedCategory;
923 pNumFmtShell->GetOptions( theFormat,
924 bThousand, bNegRed,
925 nDecimals, nZeroes,
926 nCategory );
927 bool bDoIt=false;
928 if(nCategory==CAT_CURRENCY)
930 sal_uInt16 nTstPos=pNumFmtShell->FindCurrencyFormat(theFormat);
931 if(nCurrencyPos!=static_cast<sal_Int32>(nTstPos) && nTstPos!=(sal_uInt16)-1)
933 m_pLbCurrency->SelectEntryPos(nTstPos);
934 pNumFmtShell->SetCurrencySymbol(nTstPos);
935 bDoIt=true;
941 if ( nCategory != nCurCategory || bDoIt)
943 if ( bCheckCatChange )
945 if(bOneAreaFlag)
946 SetCategory(0);
947 else
948 SetCategory(nCategory );
950 UpdateFormatListBox_Impl( true, false );
953 else if ( m_pLbFormat->GetEntryCount() > 0 )
955 sal_uInt32 nCurEntryKey=NUMKEY_UNDEFINED;
956 if(!pNumFmtShell->FindEntry( m_pEdFormat->GetText(),&nCurEntryKey))
958 m_pLbFormat->SetNoSelection();
961 if(bOneAreaFlag)
963 nCategory=nFixedCategory;
966 switch ( nCategory )
968 case CAT_SCIENTIFIC: // bThousand is for Engineering notation
970 sal_uInt16 nIntDigits = pNumFmtShell->GetFormatIntegerDigits(theFormat);
971 if ( (nIntDigits > 0) && (nIntDigits % 3 == 0) )
972 bThousand = true;
973 else
974 bThousand = false;
976 // fallthru
977 case CAT_NUMBER:
978 case CAT_PERCENT:
979 case CAT_CURRENCY:
980 m_pFtOptions->Enable();
981 m_pFtDecimals->Enable();
982 m_pEdDecimals->Enable();
983 m_pFtLeadZeroes->Enable();
984 m_pEdLeadZeroes->Enable();
985 m_pBtnNegRed->Enable();
986 m_pBtnThousand->Enable();
987 if ( nCategory == CAT_NUMBER && m_pLbFormat->GetSelectEntryPos() == 0 )
988 m_pEdDecimals->SetText( "" ); //General format tdf#44399
989 else
990 m_pEdDecimals->SetText( OUString::number( nDecimals ) );
991 m_pEdLeadZeroes->SetText( OUString::number( nZeroes ) );
992 m_pBtnNegRed->Check( bNegRed );
993 m_pBtnThousand->Check( bThousand );
994 break;
996 case CAT_ALL:
997 case CAT_USERDEFINED:
998 case CAT_TEXT:
999 case CAT_DATE:
1000 case CAT_TIME:
1001 case CAT_BOOLEAN:
1002 case CAT_FRACTION:
1003 default:
1004 m_pFtOptions->Disable();
1005 m_pFtDecimals->Disable();
1006 m_pEdDecimals->Disable();
1007 m_pFtLeadZeroes->Disable();
1008 m_pEdLeadZeroes->Disable();
1009 m_pBtnNegRed->Disable();
1010 m_pBtnThousand->Disable();
1011 m_pEdDecimals->SetText( OUString::number( 0 ) );
1012 m_pEdLeadZeroes->SetText( OUString::number( 0 ) );
1013 m_pBtnNegRed->Check( false );
1014 m_pBtnThousand->Check( false );
1016 UpdateThousandEngineeringText();
1020 /*************************************************************************
1021 #* Method: UpdateFormatListBox_Impl
1022 #*------------------------------------------------------------------------
1024 #* Class: SvxNumberFormatTabPage
1025 #* Function: Updates the format lisbox and additionally the
1026 #* string in the editbox is changed depending on
1027 #* the bUpdateEdit flag.
1028 #* Input: Flags for category and editbox.
1029 #* Output: ---
1031 #************************************************************************/
1033 void SvxNumberFormatTabPage::UpdateFormatListBox_Impl
1035 bool bCat, // Category or country/language ListBox?
1036 bool bUpdateEdit
1039 std::vector<OUString> aEntryList;
1040 short nFmtLbSelPos = 0;
1041 short nTmpCatPos;
1043 if(bOneAreaFlag)
1045 nTmpCatPos=nFixedCategory;
1047 else
1049 nTmpCatPos=m_pLbCategory->GetSelectEntryPos();
1053 if ( bCat )
1055 if(nTmpCatPos!=CAT_CURRENCY)
1056 m_pLbCurrency->Hide();
1057 else
1058 m_pLbCurrency->Show();
1060 pNumFmtShell->CategoryChanged( nTmpCatPos,nFmtLbSelPos, aEntryList );
1062 else
1063 pNumFmtShell->LanguageChanged( m_pLbLanguage->GetSelectLanguage(),
1064 nFmtLbSelPos,aEntryList );
1066 REMOVE_DONTKNOW() // possibly UI-Enable
1069 if ( (!aEntryList.empty()) && (nFmtLbSelPos != SELPOS_NONE) )
1071 if(bUpdateEdit)
1073 OUString aFormat=aEntryList[nFmtLbSelPos];
1074 m_pEdFormat->SetText(aFormat);
1075 m_pFtComment->SetText(pNumFmtShell->GetComment4Entry(nFmtLbSelPos));
1078 if(!bOneAreaFlag || !bCat)
1080 FillFormatListBox_Impl( aEntryList );
1081 m_pLbFormat->SelectEntryPos( nFmtLbSelPos );
1083 m_pFtComment->SetText(pNumFmtShell->GetComment4Entry(nFmtLbSelPos));
1084 if(pNumFmtShell->GetUserDefined4Entry(nFmtLbSelPos))
1086 if(pNumFmtShell->GetComment4Entry(nFmtLbSelPos).isEmpty())
1088 m_pFtComment->SetText(m_pLbCategory->GetEntry(1));
1091 ChangePreviewText( (sal_uInt16)nFmtLbSelPos );
1095 else
1097 FillFormatListBox_Impl( aEntryList );
1098 if(nFmtLbSelPos != SELPOS_NONE)
1100 m_pLbFormat->SelectEntryPos( (sal_uInt16)nFmtLbSelPos );
1102 m_pFtComment->SetText(pNumFmtShell->GetComment4Entry(nFmtLbSelPos));
1103 if(pNumFmtShell->GetUserDefined4Entry(nFmtLbSelPos))
1105 if(pNumFmtShell->GetComment4Entry(nFmtLbSelPos).isEmpty())
1107 m_pFtComment->SetText(m_pLbCategory->GetEntry(1));
1111 else
1113 m_pLbFormat->SetNoSelection();
1116 if ( bUpdateEdit )
1118 m_pEdFormat->SetText( OUString() );
1119 m_pWndPreview->NotifyChange( OUString() );
1123 aEntryList.clear();
1127 /*************************************************************************
1128 #* Method: UpdateThousandEngineeringText
1129 #*------------------------------------------------------------------------
1131 #* Class: SvxNumberFormatTabPage
1132 #* Function: Updates the text of Thousands seprator checkbox
1133 #* if scientific format "Engineering notation"
1134 #* else "Thousands separator"
1135 #* Input: ---
1136 #* Output: ---
1138 #************************************************************************/
1140 void SvxNumberFormatTabPage::UpdateThousandEngineeringText()
1142 if ( m_pLbCategory->GetSelectEntryPos() == CAT_SCIENTIFIC )
1143 m_pBtnThousand->SetText(sEngineeringNotation);
1144 else
1145 m_pBtnThousand->SetText(sThousandSeparator);
1149 /*************************************************************************
1150 #* Handle: DoubleClickHdl_Impl
1151 #*------------------------------------------------------------------------
1153 #* Class: SvxNumberFormatTabPage
1154 #* Function: On a double click in the format lisbox the
1155 #* value is adopted and the OK button pushed.
1156 #* Input: Pointer on the Listbox
1157 #* Output: ---
1159 #************************************************************************/
1161 IMPL_LINK( SvxNumberFormatTabPage, DoubleClickHdl_Impl, SvxFontListBox*, pLb )
1163 if (pLb == m_pLbFormat)
1165 SelFormatHdl_Impl( pLb );
1167 if ( fnOkHdl.IsSet() )
1168 { // temporary solution, should be offered by SfxTabPage
1169 fnOkHdl.Call( NULL );
1171 else
1173 SfxSingleTabDialog* pParent = dynamic_cast< SfxSingleTabDialog* >( GetParentDialog() );
1174 OKButton* pOKButton = pParent ? pParent->GetOKButton() : NULL;
1175 if ( pOKButton )
1176 pOKButton->Click();
1179 return 0;
1183 /*************************************************************************
1184 #* Method: SelFormatHdl_Impl
1185 #*------------------------------------------------------------------------
1187 #* Class: SvxNumberFormatTabPage
1188 #* Function: Is called when the language, the category or the format
1189 #* is changed. Accordingly the settings are adjusted.
1190 #* Input: Pointer on the Listbox
1191 #* Output: ---
1193 #************************************************************************/
1195 IMPL_LINK( SvxNumberFormatTabPage, SelFormatHdl_Impl, void *, pLb )
1197 if (pLb == m_pCbSourceFormat)
1199 EnableBySourceFormat_Impl(); // enable/disable everything else
1200 if ( m_pCbSourceFormat->IsChecked() )
1201 return 0; // just disabled everything else
1203 // Reinit options enable/disable for current selection.
1205 // Current category may be UserDefined with no format entries defined.
1206 // And yes, m_pLbFormat is a SvxFontListBox with sal_uLong list positions,
1207 // implementation returns a TREELIST_ENTRY_NOTFOUND if empty,
1208 // comparison with sal_Int32 LISTBOX_ENTRY_NOTFOUND wouldn't match.
1209 if ( m_pLbFormat->GetSelectEntryPos() == TREELIST_ENTRY_NOTFOUND )
1210 pLb = m_pLbCategory; // continue with the current category selected
1211 else
1212 pLb = m_pLbFormat; // continue with the current format selected
1215 sal_Int32 nTmpCatPos;
1217 if(bOneAreaFlag)
1219 nTmpCatPos=nFixedCategory;
1221 else
1223 nTmpCatPos=m_pLbCategory->GetSelectEntryPos();
1226 if (nTmpCatPos==CAT_CURRENCY && pLb == m_pLbCurrency )
1228 sal_Int32 nCurrencyPos = m_pLbCurrency->GetSelectEntryPos();
1229 pNumFmtShell->SetCurrencySymbol(static_cast<sal_uInt32>(nCurrencyPos));
1233 // Format-ListBox ----------------------------------------------------
1234 if (pLb == m_pLbFormat)
1236 sal_uLong nSelPos = m_pLbFormat->GetSelectEntryPos();
1237 short nFmtLbSelPos = static_cast<short>(nSelPos);
1239 OUString aFormat = pNumFmtShell->GetFormat4Entry(nFmtLbSelPos);
1240 OUString aComment = pNumFmtShell->GetComment4Entry(nFmtLbSelPos);
1242 if(pNumFmtShell->GetUserDefined4Entry(nFmtLbSelPos))
1244 if(aComment.isEmpty())
1246 aComment = m_pLbCategory->GetEntry(1);
1250 if ( !aFormat.isEmpty() )
1252 if(!m_pEdFormat->HasFocus()) m_pEdFormat->SetText( aFormat );
1253 m_pFtComment->SetText(aComment);
1254 ChangePreviewText( static_cast<sal_uInt16>(nSelPos) );
1257 REMOVE_DONTKNOW() // possibly UI-Enable
1259 if ( pNumFmtShell->FindEntry( aFormat) )
1261 m_pIbAdd->Enable(false );
1262 bool bIsUserDef=pNumFmtShell->IsUserDefined( aFormat );
1263 m_pIbRemove->Enable(bIsUserDef);
1264 m_pIbInfo->Enable(bIsUserDef);
1267 else
1269 m_pIbAdd->Enable(true );
1270 m_pIbInfo->Enable(true );
1271 m_pIbRemove->Enable(false );
1272 m_pFtComment->SetText(m_pEdComment->GetText());
1275 UpdateOptions_Impl( false );
1277 return 0;
1281 // category-ListBox -------------------------------------------------
1282 if (pLb == m_pLbCategory || pLb == m_pLbCurrency)
1284 UpdateFormatListBox_Impl( true, true );
1285 EditHdl_Impl( NULL );
1286 UpdateOptions_Impl( false );
1288 return 0;
1292 // language/country-ListBox ----------------------------------------------
1293 if (pLb == m_pLbLanguage)
1295 UpdateFormatListBox_Impl( false, true );
1296 EditHdl_Impl(m_pEdFormat);
1298 return 0;
1300 return 0;
1304 /*************************************************************************
1305 #* Method: ClickHdl_Impl, PushButton* pIB
1306 #*------------------------------------------------------------------------
1308 #* Class: SvxNumberFormatTabPage
1309 #* Function: Called when the add or delete button is pushed,
1310 #* adjusts the number format list.
1311 #* Input: Toolbox- Button
1312 #* Output: ---
1314 #************************************************************************/
1316 IMPL_LINK( SvxNumberFormatTabPage, ClickHdl_Impl, PushButton*, pIB)
1318 bool bDeleted = false;
1319 sal_uLong nReturn = 0;
1320 const sal_uLong nReturnChanged = 0x1; // THE boolean return value
1321 const sal_uLong nReturnAdded = 0x2; // temp: format added
1322 const sal_uLong nReturnOneArea = 0x4; // temp: one area but category changed => ignored
1324 if (pIB == m_pIbAdd)
1325 { // Also called from FillItemSet() if a temporary currency format has
1326 // to be added, not only if the Add button is enabled.
1327 OUString aFormat = m_pEdFormat->GetText();
1328 std::vector<OUString> aEntryList;
1329 std::vector<OUString> a2EntryList;
1330 sal_uInt16 nCatLbSelPos = 0;
1331 short nFmtLbSelPos = SELPOS_NONE;
1332 sal_Int32 nErrPos=0;
1334 pNumFmtShell->SetCurCurrencyEntry(NULL);
1335 bool bAdded = pNumFmtShell->AddFormat( aFormat, nErrPos,
1336 nCatLbSelPos, nFmtLbSelPos,
1337 aEntryList);
1338 if ( bAdded )
1339 nReturn |= nReturnChanged | nReturnAdded;
1341 if (pLastActivWindow == m_pEdComment)
1343 m_pEdFormat->GrabFocus();
1344 m_pEdComment->Hide();
1345 m_pFtComment->Show();
1346 m_pFtComment->SetText(m_pEdComment->GetText());
1349 if ( !nErrPos ) // Syntax ok?
1351 // May be sorted under a different locale if LCID was parsed.
1352 if (bAdded)
1353 m_pLbLanguage->SelectLanguage( pNumFmtShell->GetCurLanguage() );
1355 if(nCatLbSelPos==CAT_CURRENCY)
1357 m_pLbCurrency->SelectEntryPos((sal_uInt16)pNumFmtShell->GetCurrencySymbol());
1360 if(bOneAreaFlag && (nFixedCategory!=nCatLbSelPos))
1362 if(bAdded) aEntryList.clear();
1363 bDeleted = pNumFmtShell->RemoveFormat( aFormat,
1364 nCatLbSelPos,
1365 nFmtLbSelPos,
1366 a2EntryList);
1367 if(bDeleted) a2EntryList.clear();
1368 m_pEdFormat->GrabFocus();
1369 m_pEdFormat->SetSelection( Selection( 0, SELECTION_MAX ) );
1370 nReturn |= nReturnOneArea;
1372 else
1374 if ( bAdded && (nFmtLbSelPos != SELPOS_NONE) )
1376 // everything alright
1377 if(bOneAreaFlag) //@@ ???
1378 SetCategory(0);
1379 else
1380 SetCategory(nCatLbSelPos );
1382 FillFormatListBox_Impl( aEntryList );
1383 if(m_pEdComment->GetText()!=OUString(m_pLbCategory->GetEntry(1)))
1385 pNumFmtShell->SetComment4Entry(nFmtLbSelPos,
1386 m_pEdComment->GetText());
1388 else
1390 pNumFmtShell->SetComment4Entry(nFmtLbSelPos,
1391 OUString());
1393 m_pLbFormat->SelectEntryPos( (sal_uInt16)nFmtLbSelPos );
1394 m_pEdFormat->SetText( aFormat );
1396 m_pEdComment->SetText(m_pLbCategory->GetEntry(1)); // String for user defined
1398 ChangePreviewText( (sal_uInt16)nFmtLbSelPos );
1402 else // syntax error
1404 m_pEdFormat->GrabFocus();
1405 m_pEdFormat->SetSelection( Selection( nErrPos == -1 ? SELECTION_MAX : nErrPos, SELECTION_MAX ) );
1407 EditHdl_Impl(m_pEdFormat);
1408 nReturn = ((nReturn & nReturnOneArea) ? 0 : (nReturn & nReturnChanged));
1410 aEntryList.clear();
1411 a2EntryList.clear();
1413 else if (pIB == m_pIbRemove)
1415 OUString aFormat = m_pEdFormat->GetText();
1416 std::vector<OUString> aEntryList;
1417 sal_uInt16 nCatLbSelPos = 0;
1418 short nFmtLbSelPos = SELPOS_NONE;
1420 bDeleted = pNumFmtShell->RemoveFormat( aFormat,
1421 nCatLbSelPos,
1422 nFmtLbSelPos,
1423 aEntryList );
1425 m_pEdComment->SetText(m_pLbCategory->GetEntry(1));
1426 if ( bDeleted )
1428 if( nFmtLbSelPos>=0 && static_cast<size_t>(nFmtLbSelPos)<aEntryList.size() )
1430 aFormat = aEntryList[nFmtLbSelPos];
1433 FillFormatListBox_Impl( aEntryList );
1435 if ( nFmtLbSelPos != SELPOS_NONE )
1437 if(bOneAreaFlag) //@@ ???
1438 SetCategory(0);
1439 else
1440 SetCategory(nCatLbSelPos );
1442 m_pLbFormat->SelectEntryPos( (sal_uInt16)nFmtLbSelPos );
1443 m_pEdFormat->SetText( aFormat );
1444 ChangePreviewText( (sal_uInt16)nFmtLbSelPos );
1446 else
1448 // set to "all/standard"
1449 SetCategory(0);
1450 SelFormatHdl_Impl(m_pLbCategory);
1453 EditHdl_Impl(m_pEdFormat);
1455 aEntryList.clear();
1457 else if (pIB == m_pIbInfo)
1459 if(!(pLastActivWindow == m_pEdComment))
1461 m_pEdComment->SetText(m_pFtComment->GetText());
1462 m_pEdComment->Show();
1463 m_pFtComment->Hide();
1464 m_pEdComment->GrabFocus();
1466 else
1468 m_pEdFormat->GrabFocus();
1469 m_pEdComment->Hide();
1470 m_pFtComment->Show();
1474 return nReturn;
1478 /*************************************************************************
1479 #* Method: EditHdl_Impl
1480 #*------------------------------------------------------------------------
1482 #* Class: SvxNumberFormatTabPage
1483 #* Function: When the entry in the edit field is changed
1484 #* the preview is updated and
1485 #* Input: Pointer on Editbox
1486 #* Output: ---
1488 #************************************************************************/
1490 IMPL_LINK( SvxNumberFormatTabPage, EditHdl_Impl, Edit*, pEdFormat )
1492 sal_uInt32 nCurKey = NUMKEY_UNDEFINED;
1494 if ( m_pEdFormat->GetText().isEmpty() )
1496 m_pIbAdd->Enable(false );
1497 m_pIbRemove->Enable(false );
1498 m_pIbInfo->Enable(false );
1499 m_pFtComment->SetText(OUString());
1501 else
1503 OUString aFormat = m_pEdFormat->GetText();
1504 MakePreviewText( aFormat );
1506 if ( pNumFmtShell->FindEntry( aFormat, &nCurKey ) )
1508 m_pIbAdd->Enable(false );
1509 bool bUserDef=pNumFmtShell->IsUserDefined( aFormat );
1511 m_pIbRemove->Enable(bUserDef);
1512 m_pIbInfo->Enable(bUserDef);
1514 if(bUserDef)
1516 sal_uInt16 nTmpCurPos=pNumFmtShell->FindCurrencyFormat(aFormat );
1518 if(nTmpCurPos!=(sal_uInt16)-1)
1519 m_pLbCurrency->SelectEntryPos(nTmpCurPos);
1521 short nPosi=pNumFmtShell->GetListPos4Entry(aFormat);
1522 if(nPosi>=0)
1523 m_pLbFormat->SelectEntryPos( (sal_uInt16)nPosi);
1526 else
1529 m_pIbAdd->Enable(true );
1530 m_pIbInfo->Enable(true);
1531 m_pIbRemove->Enable(false );
1533 m_pFtComment->SetText(m_pEdComment->GetText());
1538 if ( pEdFormat )
1540 pNumFmtShell->SetCurNumFmtKey( nCurKey );
1541 UpdateOptions_Impl( true );
1544 return 0;
1548 /*************************************************************************
1549 #* Method: NotifyChange
1550 #*------------------------------------------------------------------------
1552 #* Class: SvxNumberFormatTabPage
1553 #* Function: Does changes in the number attributes.
1554 #* Input: Options- Controls
1555 #* Output: ---
1557 #************************************************************************/
1559 IMPL_LINK( SvxNumberFormatTabPage, OptHdl_Impl, void *, pOptCtrl )
1561 if ( (pOptCtrl == m_pEdLeadZeroes)
1562 || (pOptCtrl == m_pEdDecimals)
1563 || (pOptCtrl == m_pBtnNegRed)
1564 || (pOptCtrl == m_pBtnThousand) )
1566 OUString aFormat;
1567 bool bThousand = m_pBtnThousand->IsEnabled()
1568 && m_pBtnThousand->IsChecked();
1569 bool bNegRed = m_pBtnNegRed->IsEnabled()
1570 && m_pBtnNegRed->IsChecked();
1571 sal_uInt16 nPrecision = (m_pEdDecimals->IsEnabled())
1572 ? (sal_uInt16)m_pEdDecimals->GetValue()
1573 : (sal_uInt16)0;
1574 sal_uInt16 nLeadZeroes = (m_pEdLeadZeroes->IsEnabled())
1575 ? (sal_uInt16)m_pEdLeadZeroes->GetValue()
1576 : (sal_uInt16)0;
1577 if ( pNumFmtShell->GetStandardName() == m_pEdFormat->GetText() )
1579 m_pEdDecimals->SetValue( nPrecision );
1582 pNumFmtShell->MakeFormat( aFormat,
1583 bThousand, bNegRed,
1584 nPrecision, nLeadZeroes,
1585 (sal_uInt16)m_pLbFormat->GetSelectEntryPos() );
1587 m_pEdFormat->SetText( aFormat );
1588 MakePreviewText( aFormat );
1590 if ( pNumFmtShell->FindEntry( aFormat ) )
1592 m_pIbAdd->Enable(false );
1593 bool bUserDef=pNumFmtShell->IsUserDefined( aFormat );
1594 m_pIbRemove->Enable(bUserDef);
1595 m_pIbInfo->Enable(bUserDef);
1596 EditHdl_Impl(m_pEdFormat);
1599 else
1601 EditHdl_Impl( NULL );
1602 m_pLbFormat->SetNoSelection();
1605 return 0;
1608 IMPL_LINK_NOARG_TYPED(SvxNumberFormatTabPage, TimeHdl_Impl, Timer *, void)
1610 pLastActivWindow=NULL;
1614 /*************************************************************************
1615 #* Method: LostFocusHdl_Impl
1616 #*------------------------------------------------------------------------
1618 #* Class: SvxNumberFormatTabPage
1619 #* Function: Does changes in the number attributes.
1620 #* Input: Options- Controls
1621 #* Output: ---
1623 #************************************************************************/
1625 IMPL_LINK( SvxNumberFormatTabPage, LostFocusHdl_Impl, Edit *, pEd)
1627 if (pEd == m_pEdComment)
1629 aResetWinTimer.Start();
1630 m_pFtComment->SetText(m_pEdComment->GetText());
1631 m_pEdComment->Hide();
1632 m_pFtComment->Show();
1633 if(!m_pIbAdd->IsEnabled())
1635 sal_uInt16 nSelPos = (sal_uInt16) m_pLbFormat->GetSelectEntryPos();
1636 pNumFmtShell->SetComment4Entry(nSelPos,
1637 m_pEdComment->GetText());
1638 m_pEdComment->SetText(m_pLbCategory->GetEntry(1)); // String for user defined
1641 return 0;
1644 /*************************************************************************
1645 #* Method: NotifyChange
1646 #*------------------------------------------------------------------------
1648 #* Class: SvxNumberFormatTabPage
1649 #* Function: Does changes in the number attributes.
1650 #* Input: Options- Controls
1651 #* Output: ---
1653 #************************************************************************/
1655 OUString SvxNumberFormatTabPage::GetExpColorString(
1656 Color*& rpPreviewColor, const OUString& rFormatStr, short nTmpCatPos)
1658 double nVal = 0;
1659 switch (nTmpCatPos)
1661 case CAT_CURRENCY: nVal=SVX_NUMVAL_CURRENCY; break;
1663 case CAT_SCIENTIFIC:
1664 case CAT_FRACTION:
1665 case CAT_NUMBER: nVal=SVX_NUMVAL_STANDARD; break;
1667 case CAT_PERCENT: nVal=SVX_NUMVAL_PERCENT; break;
1669 case CAT_ALL: nVal=SVX_NUMVAL_STANDARD; break;
1671 case CAT_TIME: nVal=SVX_NUMVAL_TIME; break;
1672 case CAT_DATE: nVal=SVX_NUMVAL_DATE; break;
1674 case CAT_BOOLEAN: nVal=SVX_NUMVAL_BOOLEAN; break;
1676 case CAT_USERDEFINED:
1677 case CAT_TEXT:
1678 default: nVal=0;break;
1681 OUString aPreviewString;
1682 pNumFmtShell->MakePrevStringFromVal( rFormatStr, aPreviewString, rpPreviewColor, nVal );
1683 return aPreviewString;
1686 void SvxNumberFormatTabPage::MakePreviewText( const OUString& rFormat )
1688 OUString aPreviewString;
1689 Color* pPreviewColor = NULL;
1690 pNumFmtShell->MakePreviewString( rFormat, aPreviewString, pPreviewColor );
1691 m_pWndPreview->NotifyChange( aPreviewString, pPreviewColor );
1694 void SvxNumberFormatTabPage::ChangePreviewText( sal_uInt16 nPos )
1696 OUString aPreviewString;
1697 Color* pPreviewColor = NULL;
1698 pNumFmtShell->FormatChanged( nPos, aPreviewString, pPreviewColor );
1699 m_pWndPreview->NotifyChange( aPreviewString, pPreviewColor );
1702 bool SvxNumberFormatTabPage::PreNotify( NotifyEvent& rNEvt )
1704 if(rNEvt.GetType()==MouseNotifyEvent::LOSEFOCUS)
1706 if ( rNEvt.GetWindow() == dynamic_cast< vcl::Window* >( m_pEdComment.get() ) && !m_pEdComment->IsVisible() )
1708 pLastActivWindow = NULL;
1710 else
1712 pLastActivWindow = rNEvt.GetWindow();
1716 return SfxTabPage::PreNotify( rNEvt );
1718 /*************************************************************************
1719 #* Method: SetOkHdl
1720 #*------------------------------------------------------------------------
1722 #* Class: SvxNumberFormatTabPage
1723 #* Function: Resets the OkHandler.
1724 #* Input: new OkHandler
1725 #* Output: ---
1727 #************************************************************************/
1729 void SvxNumberFormatTabPage::SetOkHdl( const Link<>& rOkHandler )
1731 fnOkHdl = rOkHandler;
1734 void SvxNumberFormatTabPage::FillCurrencyBox()
1736 std::vector<OUString> aList;
1738 sal_uInt16 nSelPos=0;
1739 pNumFmtShell->GetCurrencySymbols(aList, &nSelPos);
1741 for(std::vector<OUString>::iterator i = aList.begin() + 1;i != aList.end(); ++i)
1742 m_pLbCurrency->InsertEntry(*i);
1744 // Initially disable the "Automatically" entry. First ensure that nothing
1745 // is selected, else if the to be disabled (first) entry was selected it
1746 // would be sticky when disabled and could not be deselected!
1747 m_pLbCurrency->SetNoSelection();
1748 m_pLbCurrency->SetEntryFlags( 0, ListBoxEntryFlags::DisableSelection | ListBoxEntryFlags::DrawDisabled);
1749 m_pLbCurrency->SelectEntryPos(nSelPos);
1752 void SvxNumberFormatTabPage::SetCategory(sal_uInt16 nPos)
1754 sal_uInt16 nCurCategory = m_pLbCategory->GetSelectEntryPos();
1755 sal_uInt16 nTmpCatPos;
1757 if(bOneAreaFlag)
1759 nTmpCatPos=nFixedCategory;
1761 else
1763 nTmpCatPos=nPos;
1766 if(m_pLbCategory->GetEntryCount()==1 || nCurCategory!=nPos)
1768 if(nTmpCatPos!=CAT_CURRENCY)
1769 m_pLbCurrency->Hide();
1770 else
1771 m_pLbCurrency->Show();
1773 m_pLbCategory->SelectEntryPos(nPos);
1775 /* to support Writer text field language handling an
1776 additional entry needs to be inserted into the ListBox
1777 which marks a certain language as automatically detected
1778 Additionally the "Default" language is removed
1780 void SvxNumberFormatTabPage::AddAutomaticLanguage_Impl(LanguageType eAutoLang, bool bSelect)
1782 m_pLbLanguage->RemoveLanguage(LANGUAGE_SYSTEM);
1783 sal_uInt16 nPos = m_pLbLanguage->InsertEntry(sAutomaticEntry);
1784 m_pLbLanguage->SetEntryData(nPos, reinterpret_cast<void*>((sal_uLong)eAutoLang));
1785 if(bSelect)
1786 m_pLbLanguage->SelectEntryPos(nPos);
1789 void SvxNumberFormatTabPage::PageCreated(const SfxAllItemSet& aSet)
1791 SFX_ITEMSET_ARG (&aSet,pNumberInfoItem,SvxNumberInfoItem,SID_ATTR_NUMBERFORMAT_INFO,false);
1792 SFX_ITEMSET_ARG (&aSet,pLinkItem,SfxLinkItem,SID_LINK_TYPE,false);
1793 if (pNumberInfoItem)
1794 SetNumberFormatList(*pNumberInfoItem);
1795 if (pLinkItem)
1796 SetOkHdl(pLinkItem->GetValue());
1799 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */