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 <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 <unotools/localedatawrapper.hxx>
26 #include <i18nlangtag/lang.h>
27 #include <svx/dialogs.hrc>
28 #include <svtools/colorcfg.hxx>
32 #include <svx/numinf.hxx>
35 #include <svx/numfmtsh.hxx>
36 #include <dialmgr.hxx>
37 #include <sfx2/request.hxx>
38 #include <sfx2/app.hxx>
39 #include <sfx2/basedlgs.hxx>
40 #include "svx/flagsdef.hxx"
42 #include <com/sun/star/lang/XServiceInfo.hpp>
44 using ::com::sun::star::uno::Reference
;
45 using ::com::sun::star::lang::XServiceInfo
;
46 using ::com::sun::star::uno::UNO_QUERY
;
48 #define NUMKEY_UNDEFINED SAL_MAX_UINT32
50 // static ----------------------------------------------------------------
52 static sal_uInt16 pRanges
[] =
54 SID_ATTR_NUMBERFORMAT_VALUE
,
55 SID_ATTR_NUMBERFORMAT_INFO
,
56 SID_ATTR_NUMBERFORMAT_NOLANGUAGE
,
57 SID_ATTR_NUMBERFORMAT_NOLANGUAGE
,
58 SID_ATTR_NUMBERFORMAT_ONE_AREA
,
59 SID_ATTR_NUMBERFORMAT_ONE_AREA
,
60 SID_ATTR_NUMBERFORMAT_SOURCE
,
61 SID_ATTR_NUMBERFORMAT_SOURCE
,
65 /*************************************************************************
66 #* Method: SvxNumberPreview
67 #*------------------------------------------------------------------------
69 #* Class: SvxNumberPreview
70 #* Function: Constructor of the class SvxNumberPreview
71 #* Input: Window, Resource-ID
74 #************************************************************************/
76 SvxNumberPreview::SvxNumberPreview(Window
* pParent
, WinBits nStyle
)
77 : Window(pParent
, nStyle
)
78 , mnPos(STRING_NOTFOUND
)
81 Font
aFont( GetFont() );
82 aFont
.SetTransparent( sal_True
);
83 aFont
.SetColor( Application::GetSettings().GetStyleSettings().GetFieldColor() );
85 InitSettings( sal_True
, sal_True
);
86 SetBorderStyle( WINDOW_BORDER_MONO
);
89 extern "C" SAL_DLLPUBLIC_EXPORT Window
* SAL_CALL
makeSvxNumberPreview(Window
*pParent
, VclBuilder::stringmap
&)
91 return new SvxNumberPreview(pParent
);
94 /*************************************************************************
95 #* Method: NotifyChange
96 #*------------------------------------------------------------------------
98 #* Class: SvxNumberPreview
99 #* Function: Function for changing the preview string
100 #* Input: String, color
103 #************************************************************************/
105 void SvxNumberPreview::NotifyChange( const String
& rPrevStr
,
106 const Color
* pColor
)
108 // detect and strip out '*' related placeholders
110 mnPos
= aPrevStr
.Search( 0x1B );
111 if ( mnPos
!= STRING_NOTFOUND
)
113 mnChar
= aPrevStr
.GetChar( mnPos
+ 1 );
114 // delete placeholder and char to repeat
115 aPrevStr
.Erase( mnPos
, 2 );
117 svtools::ColorConfig aColorConfig
;
118 Color
aWindowTextColor( aColorConfig
.GetColorValue( svtools::FONTCOLOR
).nColor
);
119 aPrevCol
= pColor
? *pColor
: aWindowTextColor
;
124 /*************************************************************************
126 #*------------------------------------------------------------------------
128 #* Class: SvxNumberPreview
129 #* Function: Function for repainting the window.
133 #************************************************************************/
135 void SvxNumberPreview::Paint( const Rectangle
& )
137 Font aDrawFont
= GetFont();
138 Size aSzWnd
= GetOutputSizePixel();
139 String
aTmpStr( aPrevStr
);
140 long nLeadSpace
= (aSzWnd
.Width() - GetTextWidth( aTmpStr
)) /2;
142 aDrawFont
.SetColor( aPrevCol
);
143 SetFont( aDrawFont
);
145 if ( mnPos
!= STRING_NOTFOUND
)
147 long nCharWidth
= GetTextWidth( OUString::valueOf( mnChar
) );
149 int nNumCharsToInsert
= 0;
150 if (nCharWidth
> 0) nNumCharsToInsert
= nLeadSpace
/ nCharWidth
;
152 if ( nNumCharsToInsert
> 0)
154 for ( int i
= 0; i
< nNumCharsToInsert
; ++i
)
155 aTmpStr
.Insert( mnChar
, mnPos
);
158 Point aPosText
= Point( ( mnPos
!= STRING_NOTFOUND
) ? 0 : nLeadSpace
,
159 (aSzWnd
.Height() - GetTextHeight())/2 );
160 DrawText( aPosText
, aTmpStr
);
163 // -----------------------------------------------------------------------
165 void SvxNumberPreview::InitSettings( sal_Bool bForeground
, sal_Bool bBackground
)
167 const StyleSettings
& rStyleSettings
= Application::GetSettings().GetStyleSettings();
171 svtools::ColorConfig aColorConfig
;
172 Color
aTextColor( aColorConfig
.GetColorValue( svtools::FONTCOLOR
).nColor
);
174 if ( IsControlForeground() )
175 aTextColor
= GetControlForeground();
176 SetTextColor( aTextColor
);
181 if ( IsControlBackground() )
182 SetBackground( GetControlBackground() );
184 SetBackground( rStyleSettings
.GetWindowColor() );
189 // -----------------------------------------------------------------------
191 void SvxNumberPreview::StateChanged( StateChangedType nType
)
193 if ( nType
== STATE_CHANGE_CONTROLFOREGROUND
)
194 InitSettings( sal_True
, sal_False
);
195 else if ( nType
== STATE_CHANGE_CONTROLBACKGROUND
)
196 InitSettings( sal_False
, sal_True
);
198 Window::StateChanged( nType
);
201 // -----------------------------------------------------------------------
203 void SvxNumberPreview::DataChanged( const DataChangedEvent
& rDCEvt
)
205 Window::DataChanged( rDCEvt
);
207 if ( ( rDCEvt
.GetType() == DATACHANGED_SETTINGS
) && ( rDCEvt
.GetFlags() & SETTINGS_STYLE
) )
208 InitSettings( sal_True
, sal_True
);
211 // class SvxNumberFormatTabPage ------------------------------------------
213 #define REMOVE_DONTKNOW() \
214 if ( !m_pFtLanguage->IsEnabled() ) \
216 m_pFtLanguage->Enable(); \
217 m_pLbLanguage->Enable(); \
218 m_pLbLanguage->SelectLanguage( pNumFmtShell->GetCurLanguage() ); \
221 #define HDL(hdl) LINK( this, SvxNumberFormatTabPage, hdl )
223 SvxNumberFormatTabPage::SvxNumberFormatTabPage(Window
* pParent
,
224 const SfxItemSet
& rCoreAttrs
)
225 : SfxTabPage(pParent
, "NumberingFormatPage",
226 "cui/ui/numberingformatpage.ui", rCoreAttrs
)
229 , nInitFormat(ULONG_MAX
)
230 , sAutomaticEntry(CUI_RES(RID_SVXSTR_AUTO_ENTRY
))
231 , pLastActivWindow(NULL
)
233 get(m_pFtCategory
, "categoryft");
234 get(m_pLbCategory
, "categorylb");
235 get(m_pFtFormat
, "formatft");
236 get(m_pLbCurrency
, "currencylb");
237 get(m_pLbFormat
, "formatlb");
238 long nWidth
= approximate_char_width() * 26;
239 m_pLbFormat
->set_width_request(nWidth
);
240 m_pLbCurrency
->set_width_request(nWidth
);
241 get(m_pFtLanguage
, "languageft");
242 get(m_pLbLanguage
, "languagelb");
243 get(m_pCbSourceFormat
, "sourceformat");
244 get(m_pWndPreview
, "preview");
245 get(m_pFtOptions
, "optionsft");
246 get(m_pFtDecimals
, "decimalsft");
247 get(m_pEdDecimals
, "decimalsed");
248 get(m_pBtnNegRed
, "negnumred");
249 get(m_pFtLeadZeroes
, "leadzerosft");
250 get(m_pEdLeadZeroes
, "leadzerosed");
251 get(m_pBtnThousand
, "thousands");
252 get(m_pFormatCodeFrame
, "formatcode");
253 get(m_pEdFormat
, "formated");
254 get(m_pIbAdd
, "add");
255 get(m_pIbInfo
, "edit");
256 get(m_pIbRemove
, "delete");
257 get(m_pFtComment
, "commentft");
258 get(m_pEdComment
, "commented");
260 m_pLbCategory
->SetDropDownLineCount(8);
261 m_pWndPreview
->set_height_request(GetTextHeight()*3);
264 SetExchangeSupport(); // this page needs ExchangeSupport
268 SvxNumberFormatTabPage::~SvxNumberFormatTabPage()
274 void SvxNumberFormatTabPage::Init_Impl()
276 bNumItemFlag
=sal_True
;
277 bOneAreaFlag
=sal_False
;
279 m_pIbAdd
->Enable(sal_False
);
280 m_pIbRemove
->Enable(sal_False
);
281 m_pIbInfo
->Enable(sal_False
);
283 m_pEdComment
->SetText(m_pLbCategory
->GetEntry(1)); // string for user defined
285 m_pEdComment
->Hide();
287 m_pCbSourceFormat
->Check( sal_False
);
288 m_pCbSourceFormat
->Disable();
289 m_pCbSourceFormat
->Hide();
291 Link aLink
= LINK( this, SvxNumberFormatTabPage
, SelFormatHdl_Impl
);
293 m_pLbCategory
->SetSelectHdl( aLink
);
294 m_pLbFormat
->SetSelectHdl( aLink
);
295 m_pLbLanguage
->SetSelectHdl( aLink
);
296 m_pLbCurrency
->SetSelectHdl( aLink
);
297 m_pCbSourceFormat
->SetClickHdl( aLink
);
299 aLink
= LINK( this, SvxNumberFormatTabPage
, OptHdl_Impl
);
301 m_pEdDecimals
->SetModifyHdl( aLink
);
302 m_pEdLeadZeroes
->SetModifyHdl( aLink
);
303 m_pBtnNegRed
->SetClickHdl( aLink
);
304 m_pBtnThousand
->SetClickHdl( aLink
);
305 m_pLbFormat
->SetDoubleClickHdl( HDL( DoubleClickHdl_Impl
) );
306 m_pEdFormat
->SetModifyHdl( HDL( EditHdl_Impl
) );
307 m_pIbAdd
->SetClickHdl( HDL( ClickHdl_Impl
) );
308 m_pIbRemove
->SetClickHdl( HDL( ClickHdl_Impl
) );
309 m_pIbInfo
->SetClickHdl( HDL( ClickHdl_Impl
) );
311 aLink
= LINK( this, SvxNumberFormatTabPage
, LostFocusHdl_Impl
);
313 m_pEdComment
->SetLoseFocusHdl( aLink
);
314 aResetWinTimer
.SetTimeoutHdl(LINK( this, SvxNumberFormatTabPage
, TimeHdl_Impl
));
315 aResetWinTimer
.SetTimeout( 10);
317 // initialize language ListBox
319 m_pLbLanguage
->InsertLanguage( LANGUAGE_SYSTEM
);
320 // Don't list ambiguous locales where we won't be able to convert the
321 // LanguageType back to an identical Language_Country name and therefore
322 // couldn't load the i18n LocaleData. Show DebugMsg in non-PRODUCT version.
323 ::com::sun::star::uno::Sequence
< sal_uInt16
> xLang
=
324 LocaleDataWrapper::getInstalledLanguageTypes();
325 sal_Int32 nCount
= xLang
.getLength();
326 for ( sal_Int32 i
=0; i
<nCount
; i
++ )
328 m_pLbLanguage
->InsertLanguage( xLang
[i
] );
332 /*************************************************************************
334 #*------------------------------------------------------------------------
336 #* Class: SvxNumberFormatTabPage
337 #* Function: Returns area information.
341 #************************************************************************/
343 sal_uInt16
* SvxNumberFormatTabPage::GetRanges()
349 /*************************************************************************
351 #*------------------------------------------------------------------------
353 #* Class: SvxNumberFormatTabPage
354 #* Function: Creates a new number format page.
355 #* Input: Window, SfxItemSet
356 #* Output: new TabPage
358 #************************************************************************/
360 SfxTabPage
* SvxNumberFormatTabPage::Create( Window
* pParent
,
361 const SfxItemSet
& rAttrSet
)
363 return ( new SvxNumberFormatTabPage( pParent
, rAttrSet
) );
367 /*************************************************************************
369 #*------------------------------------------------------------------------
371 #* Class: SvxNumberFormatTabPage
372 #* Function: The dialog's attributes are reset
373 #* using the Itemset.
377 #************************************************************************/
379 void SvxNumberFormatTabPage::Reset( const SfxItemSet
& rSet
)
381 const SfxUInt32Item
* pValFmtAttr
= NULL
;
382 const SfxPoolItem
* pItem
= NULL
;
383 const SfxBoolItem
* pAutoEntryAttr
= NULL
;
385 sal_uInt16 nCatLbSelPos
= 0;
386 sal_uInt16 nFmtLbSelPos
= 0;
387 LanguageType eLangType
= LANGUAGE_DONTKNOW
;
388 std::vector
<String
*> aFmtEntryList
;
389 SvxNumberValueType eValType
= SVX_VALUE_TYPE_UNDEFINED
;
390 double nValDouble
= 0;
393 SfxItemState eState
= rSet
.GetItemState( GetWhich( SID_ATTR_NUMBERFORMAT_NOLANGUAGE
),sal_True
,&pItem
);
395 if(eState
==SFX_ITEM_SET
)
397 const SfxBoolItem
* pBoolLangItem
= (const SfxBoolItem
*)
398 GetItem( rSet
, SID_ATTR_NUMBERFORMAT_NOLANGUAGE
);
400 if(pBoolLangItem
!=NULL
&& pBoolLangItem
->GetValue())
406 HideLanguage(sal_False
);
411 eState
= rSet
.GetItemState( GetWhich( SID_ATTR_NUMBERFORMAT_INFO
),sal_True
,&pItem
);
413 if(eState
==SFX_ITEM_SET
)
417 bNumItemFlag
=sal_True
;
418 pNumItem
= (SvxNumberInfoItem
*) pItem
->Clone();
422 bNumItemFlag
=sal_False
;
427 bNumItemFlag
=sal_False
;
431 eState
= rSet
.GetItemState( GetWhich( SID_ATTR_NUMBERFORMAT_ONE_AREA
));
433 if(eState
==SFX_ITEM_SET
)
435 const SfxBoolItem
* pBoolItem
= (const SfxBoolItem
*)
436 GetItem( rSet
, SID_ATTR_NUMBERFORMAT_ONE_AREA
);
440 bOneAreaFlag
= pBoolItem
->GetValue();
444 eState
= rSet
.GetItemState( GetWhich( SID_ATTR_NUMBERFORMAT_SOURCE
) );
446 if ( eState
== SFX_ITEM_SET
)
448 const SfxBoolItem
* pBoolItem
= (const SfxBoolItem
*)
449 GetItem( rSet
, SID_ATTR_NUMBERFORMAT_SOURCE
);
451 m_pCbSourceFormat
->Check( pBoolItem
->GetValue() );
453 m_pCbSourceFormat
->Check( sal_False
);
454 m_pCbSourceFormat
->Enable();
455 m_pCbSourceFormat
->Show();
459 sal_Bool bInit
= sal_False
; // set to sal_True for debug test
460 m_pCbSourceFormat
->Check( bInit
);
461 m_pCbSourceFormat
->Enable( bInit
);
462 m_pCbSourceFormat
->Show( bInit
);
465 // pNumItem must have been set from outside!
466 DBG_ASSERT( pNumItem
, "No NumberInfo, no NumberFormatter, good bye.CRASH. :-(" );
468 eState
= rSet
.GetItemState( GetWhich( SID_ATTR_NUMBERFORMAT_VALUE
) );
470 if ( SFX_ITEM_DONTCARE
!= eState
)
471 pValFmtAttr
= (const SfxUInt32Item
*)
472 GetItem( rSet
, SID_ATTR_NUMBERFORMAT_VALUE
);
474 eValType
= pNumItem
->GetValueType();
478 case SVX_VALUE_TYPE_STRING
:
479 aValString
= pNumItem
->GetValueString();
481 case SVX_VALUE_TYPE_NUMBER
:
482 // #50441# string may be set in addition to the value
483 aValString
= pNumItem
->GetValueString();
484 nValDouble
= pNumItem
->GetValueDouble();
486 case SVX_VALUE_TYPE_UNDEFINED
:
492 delete pNumFmtShell
; // delete old shell if applicable (== reset)
494 nInitFormat
= ( pValFmtAttr
) // memorize init key
495 ? pValFmtAttr
->GetValue() // (for FillItemSet())
496 : ULONG_MAX
; // == DONT_KNOW
499 if ( eValType
== SVX_VALUE_TYPE_STRING
)
500 pNumFmtShell
=SvxNumberFormatShell::Create(
501 pNumItem
->GetNumberFormatter(),
502 (pValFmtAttr
) ? nInitFormat
: 0L,
506 pNumFmtShell
=SvxNumberFormatShell::Create(
507 pNumItem
->GetNumberFormatter(),
508 (pValFmtAttr
) ? nInitFormat
: 0L,
514 bool bUseStarFormat
= false;
515 SfxObjectShell
* pDocSh
= SfxObjectShell::Current();
518 // is this a calc document
519 Reference
< XServiceInfo
> xSI( pDocSh
->GetModel(), UNO_QUERY
);
521 bUseStarFormat
= xSI
->supportsService( OUString( "com.sun.star.sheet.SpreadsheetDocument" ) );
523 pNumFmtShell
->SetUseStarFormat( bUseStarFormat
);
528 Color
* pDummy
= NULL
;
529 pNumFmtShell
->GetInitSettings( nCatLbSelPos
, eLangType
, nFmtLbSelPos
,
530 aFmtEntryList
, aPrevString
, pDummy
);
532 m_pLbCurrency
->SelectEntryPos((sal_uInt16
)pNumFmtShell
->GetCurrencySymbol());
534 nFixedCategory
=nCatLbSelPos
;
537 String sFixedCategory
=m_pLbCategory
->GetEntry(nFixedCategory
);
538 m_pLbCategory
->Clear();
539 m_pLbCategory
->InsertEntry(sFixedCategory
);
544 SetCategory(nCatLbSelPos
);
546 eState
= rSet
.GetItemState( GetWhich( SID_ATTR_NUMBERFORMAT_ADD_AUTO
) );
547 if(SFX_ITEM_SET
== eState
)
548 pAutoEntryAttr
= (const SfxBoolItem
*)
549 GetItem( rSet
, SID_ATTR_NUMBERFORMAT_ADD_AUTO
);
550 // no_NO is an alias for nb_NO and normally isn't listed, we need it for
551 // backwards compatibility, but only if the format passed is of
552 // LanguageType no_NO.
553 if ( eLangType
== LANGUAGE_NORWEGIAN
)
555 m_pLbLanguage
->RemoveLanguage( eLangType
); // in case we're already called
556 m_pLbLanguage
->InsertLanguage( eLangType
);
558 m_pLbLanguage
->SelectLanguage( eLangType
);
560 AddAutomaticLanguage_Impl(eLangType
, pAutoEntryAttr
->GetValue());
561 UpdateFormatListBox_Impl(sal_False
,sal_True
);
563 //! This spoils everything because it rematches currency formats based on
564 //! the selected m_pLbCurrency entry instead of the current format.
565 //! Besides that everything seems to be initialized by now, so why call it?
566 // SelFormatHdl_Impl( m_pLbCategory );
570 EditHdl_Impl(m_pEdFormat
); // UpdateOptions_Impl() als Seiteneffekt
574 // everything disabled except direct input or changing the category
578 if ( m_pCbSourceFormat
->IsChecked() )
580 // everything disabled except SourceFormat checkbox
581 EnableBySourceFormat_Impl();
584 DeleteEntryList_Impl(aFmtEntryList
);
587 /*************************************************************************
588 #* Method: Obstructing
589 #*------------------------------------------------------------------------
591 #* Class: SvxNumberFormatTabPage
592 #* Function: Disable the controls except from changing the category
597 #************************************************************************/
598 void SvxNumberFormatTabPage::Obstructing()
600 m_pLbFormat
->SetNoSelection();
601 m_pLbLanguage
->SetNoSelection();
602 m_pFtLanguage
->Disable();
603 m_pLbLanguage
->Disable();
605 m_pIbAdd
->Enable(sal_False
);
606 m_pIbRemove
->Enable(sal_False
);
607 m_pIbInfo
->Enable(sal_False
);
609 m_pBtnNegRed
->Disable();
610 m_pBtnThousand
->Disable();
611 m_pFtLeadZeroes
->Disable();
612 m_pFtDecimals
->Disable();
613 m_pEdLeadZeroes
->Disable();
614 m_pEdDecimals
->Disable();
615 m_pFtOptions
->Disable();
616 m_pEdDecimals
->SetText( String() );
617 m_pEdLeadZeroes
->SetText( String() );
618 m_pBtnNegRed
->Check( sal_False
);
619 m_pBtnThousand
->Check( sal_False
);
620 m_pWndPreview
->NotifyChange( String() );
622 m_pLbCategory
->SelectEntryPos( 0 );
623 m_pEdFormat
->SetText( String() );
624 m_pFtComment
->SetText( String() );
625 m_pEdComment
->SetText(m_pLbCategory
->GetEntry(1)); // string for user defined
627 m_pEdFormat
->GrabFocus();
631 /*************************************************************************
632 #* Enable/Disable dialog parts depending on the value of the SourceFormat
634 #************************************************************************/
635 void SvxNumberFormatTabPage::EnableBySourceFormat_Impl()
637 sal_Bool bEnable
= !m_pCbSourceFormat
->IsChecked();
639 m_pCbSourceFormat
->GrabFocus();
640 m_pFtCategory
->Enable( bEnable
);
641 m_pLbCategory
->Enable( bEnable
);
642 m_pFtFormat
->Enable( bEnable
);
643 m_pLbCurrency
->Enable( bEnable
);
644 m_pLbFormat
->Enable( bEnable
);
645 m_pFtLanguage
->Enable( bEnable
);
646 m_pLbLanguage
->Enable( bEnable
);
647 m_pFtDecimals
->Enable( bEnable
);
648 m_pEdDecimals
->Enable( bEnable
);
649 m_pFtLeadZeroes
->Enable( bEnable
);
650 m_pEdLeadZeroes
->Enable( bEnable
);
651 m_pBtnNegRed
->Enable( bEnable
);
652 m_pBtnThousand
->Enable( bEnable
);
653 m_pFtOptions
->Enable( bEnable
);
654 m_pFormatCodeFrame
->Enable( bEnable
);
655 m_pLbFormat
->Invalidate(); // #i43322#
659 /*************************************************************************
660 #* Method: HideLanguage
661 #*------------------------------------------------------------------------
663 #* Class: SvxNumberFormatTabPage
664 #* Function: Hides the language settings:
665 #* Input: sal_Bool nFlag
668 #************************************************************************/
670 void SvxNumberFormatTabPage::HideLanguage(sal_Bool nFlag
)
672 m_pFtLanguage
->Show(!nFlag
);
673 m_pLbLanguage
->Show(!nFlag
);
676 /*************************************************************************
677 #* Method: FillItemSet
678 #*------------------------------------------------------------------------
680 #* Class: SvxNumberFormatTabPage
681 #* Function: Adjusts the attributes in the ItemSet,
682 #* and - if bNumItemFlag is not set - the
683 #* numItem in the DocShell.
687 #************************************************************************/
689 sal_Bool
SvxNumberFormatTabPage::FillItemSet( SfxItemSet
& rCoreAttrs
)
691 sal_Bool bDataChanged
= m_pFtLanguage
->IsEnabled() || m_pCbSourceFormat
->IsEnabled();
694 const SfxItemSet
& rMyItemSet
= GetItemSet();
695 sal_uInt16 nWhich
= GetWhich( SID_ATTR_NUMBERFORMAT_VALUE
);
696 SfxItemState eItemState
= rMyItemSet
.GetItemState( nWhich
, sal_False
);
698 // OK chosen - Is format code input entered already taken over?
699 // If not, simulate Add. Upon syntax error ignore input and prevent Put.
700 String aFormat
= m_pEdFormat
->GetText();
701 sal_uInt32 nCurKey
= pNumFmtShell
->GetCurNumFmtKey();
703 if ( m_pIbAdd
->IsEnabled() || pNumFmtShell
->IsTmpCurrencyFormat(aFormat
) )
704 { // #79599# It is not sufficient to just add the format code (or
705 // delete it in case of bOneAreaFlag and resulting category change).
706 // Upon switching tab pages we need all settings to be consistent
707 // in case this page will be redisplayed later.
708 bDataChanged
= (ClickHdl_Impl(m_pIbAdd
) != 0);
709 nCurKey
= pNumFmtShell
->GetCurNumFmtKey();
711 else if(nCurKey
== NUMKEY_UNDEFINED
)
712 { // something went wrong, e.g. in Writer #70281#
713 pNumFmtShell
->FindEntry(aFormat
, &nCurKey
);
716 //---------------------------------------------------------------
721 bDataChanged
= ( nInitFormat
!= nCurKey
);
725 rCoreAttrs
.Put( SfxUInt32Item( nWhich
, nCurKey
) );
727 else if(SFX_ITEM_DEFAULT
== eItemState
)
729 rCoreAttrs
.ClearItem( nWhich
);
733 // --------------------------------------------------------------
734 // List of changed user defined formats:
735 // -------------------------------------
736 const size_t nDelCount
= pNumFmtShell
->GetUpdateDataCount();
740 sal_uInt32
* pDelArr
= new sal_uInt32
[nDelCount
];
742 pNumFmtShell
->GetUpdateData( pDelArr
, nDelCount
);
743 pNumItem
->SetDelFormatArray( pDelArr
, nDelCount
);
745 if(bNumItemFlag
==sal_True
)
747 rCoreAttrs
.Put( *pNumItem
);
751 SfxObjectShell
* pDocSh
= SfxObjectShell::Current();
753 DBG_ASSERT( pDocSh
, "DocShell not found!" );
757 pDocSh
->PutItem( *pNumItem
);
762 //---------------------------------------------------------------
763 // Whether source format is to be taken or not:
764 // --------------------------------------------
765 if ( m_pCbSourceFormat
->IsEnabled() )
767 sal_uInt16 _nWhich
= GetWhich( SID_ATTR_NUMBERFORMAT_SOURCE
);
768 SfxItemState _eItemState
= rMyItemSet
.GetItemState( _nWhich
, sal_False
);
769 const SfxBoolItem
* pBoolItem
= (const SfxBoolItem
*)
770 GetItem( rMyItemSet
, SID_ATTR_NUMBERFORMAT_SOURCE
);
771 sal_Bool bOld
= (pBoolItem
? pBoolItem
->GetValue() : sal_False
);
772 rCoreAttrs
.Put( SfxBoolItem( _nWhich
, m_pCbSourceFormat
->IsChecked() ) );
774 bDataChanged
= (bOld
!= (sal_Bool
) m_pCbSourceFormat
->IsChecked() ||
775 _eItemState
!= SFX_ITEM_SET
);
778 // FillItemSet is only called on OK, here we can notify the
779 // NumberFormatShell that all new user defined formats are valid.
780 pNumFmtShell
->ValidateNewEntries();
781 if(m_pLbLanguage
->IsVisible() &&
782 LISTBOX_ENTRY_NOTFOUND
!= m_pLbLanguage
->GetEntryPos(sAutomaticEntry
))
783 rCoreAttrs
.Put(SfxBoolItem(SID_ATTR_NUMBERFORMAT_ADD_AUTO
,
784 m_pLbLanguage
->GetSelectEntry() == sAutomaticEntry
));
791 int SvxNumberFormatTabPage::DeactivatePage( SfxItemSet
* _pSet
)
794 FillItemSet( *_pSet
);
798 void SvxNumberFormatTabPage::SetInfoItem( const SvxNumberInfoItem
& rItem
)
802 pNumItem
= (SvxNumberInfoItem
*)rItem
.Clone();
806 void SvxNumberFormatTabPage::FillFormatListBox_Impl( std::vector
<String
*>& rEntries
)
810 Font aFont
=m_pLbCategory
->GetFont();
815 m_pLbFormat
->Clear();
816 m_pLbFormat
->SetUpdateMode( sal_False
);
818 if( rEntries
.empty() )
823 nTmpCatPos
=nFixedCategory
;
827 nTmpCatPos
=m_pLbCategory
->GetSelectEntryPos();
834 case CAT_NUMBER
: i
=1;
838 if (nTmpCatPos
== CAT_TEXT
)
841 aTmpString
= pNumFmtShell
->GetStandardName();
842 aPrivCat
=pNumFmtShell
->GetCategory4Entry(0);
843 m_pLbFormat
->InsertFontEntry( aTmpString
, aFont
);
850 if(pNumFmtShell
!=NULL
)
852 for ( ; i
< rEntries
.size(); ++i
)
854 pEntry
= rEntries
[i
];
855 aPrivCat
=pNumFmtShell
->GetCategory4Entry( static_cast<sal_uInt16
>(i
) );
856 if(aPrivCat
!=CAT_TEXT
)
858 Color
* pPreviewColor
= NULL
;
859 String
aPreviewString( GetExpColorString( pPreviewColor
, *pEntry
, aPrivCat
) );
860 Font
aEntryFont( m_pLbFormat
->GetFont() );
861 m_pLbFormat
->InsertFontEntry( aPreviewString
, aEntryFont
, pPreviewColor
);
865 m_pLbFormat
->InsertFontEntry(*pEntry
,aFont
);
869 m_pLbFormat
->SetUpdateMode( sal_True
);
870 DeleteEntryList_Impl(rEntries
);
874 void SvxNumberFormatTabPage::DeleteEntryList_Impl( std::vector
<String
*>& rEntries
)
876 for( std::vector
<String
*>::const_iterator
it(rEntries
.begin()); it
!= rEntries
.end(); ++it
)
882 /*************************************************************************
883 #* Method: UpdateOptions_Impl
884 #*------------------------------------------------------------------------
886 #* Class: SvxNumberFormatTabPage
887 #* Function: Adjusts the options attributes
888 #* depending on the selected format.
889 #* Input: Flag, whether the category has changed.
892 #************************************************************************/
894 void SvxNumberFormatTabPage::UpdateOptions_Impl( sal_Bool bCheckCatChange
/*= sal_False*/ )
896 String theFormat
= m_pEdFormat
->GetText();
897 sal_uInt16 nCurCategory
= m_pLbCategory
->GetSelectEntryPos();
898 sal_uInt16 nCategory
= nCurCategory
;
899 sal_uInt16 nDecimals
= 0;
900 sal_uInt16 nZeroes
= 0;
901 bool bNegRed
= false;
902 bool bThousand
= false;
903 sal_uInt16 nCurrencyPos
=m_pLbCurrency
->GetSelectEntryPos();
906 nCurCategory
=nFixedCategory
;
909 pNumFmtShell
->GetOptions( theFormat
,
913 sal_Bool bDoIt
=sal_False
;
914 if(nCategory
==CAT_CURRENCY
)
916 sal_uInt16 nTstPos
=pNumFmtShell
->FindCurrencyFormat(theFormat
);
917 if(nCurrencyPos
!=nTstPos
&& nTstPos
!=(sal_uInt16
)-1)
919 m_pLbCurrency
->SelectEntryPos(nTstPos
);
920 pNumFmtShell
->SetCurrencySymbol(nTstPos
);
927 if ( nCategory
!= nCurCategory
|| bDoIt
)
929 if ( bCheckCatChange
)
934 SetCategory(nCategory
);
936 UpdateFormatListBox_Impl( sal_True
, sal_False
);
939 else if ( m_pLbFormat
->GetEntryCount() > 0 )
941 sal_uInt32 nCurEntryKey
=NUMKEY_UNDEFINED
;
942 if(!pNumFmtShell
->FindEntry( m_pEdFormat
->GetText(),&nCurEntryKey
))
944 m_pLbFormat
->SetNoSelection();
949 nCategory
=nFixedCategory
;
957 m_pFtOptions
->Enable();
958 m_pFtDecimals
->Enable();
959 m_pEdDecimals
->Enable();
960 m_pFtLeadZeroes
->Enable();
961 m_pEdLeadZeroes
->Enable();
962 m_pBtnNegRed
->Enable();
963 m_pBtnThousand
->Enable();
964 m_pEdDecimals
->SetText( OUString::number( nDecimals
) );
965 m_pEdLeadZeroes
->SetText( OUString::number( nZeroes
) );
966 m_pBtnNegRed
->Check( bNegRed
);
967 m_pBtnThousand
->Check( bThousand
);
971 case CAT_USERDEFINED
:
979 m_pFtOptions
->Disable();
980 m_pFtDecimals
->Disable();
981 m_pEdDecimals
->Disable();
982 m_pFtLeadZeroes
->Disable();
983 m_pEdLeadZeroes
->Disable();
984 m_pBtnNegRed
->Disable();
985 m_pBtnThousand
->Disable();
986 m_pEdDecimals
->SetText( OUString::number( 0 ) );
987 m_pEdLeadZeroes
->SetText( OUString::number( 0 ) );
988 m_pBtnNegRed
->Check( sal_False
);
989 m_pBtnThousand
->Check( sal_False
);
994 /*************************************************************************
995 #* Method: UpdateFormatListBox_Impl
996 #*------------------------------------------------------------------------
998 #* Class: SvxNumberFormatTabPage
999 #* Function: Updates the format lisbox and additionally the
1000 #* string in the editbox is changed depending on
1001 #* the bUpdateEdit flag.
1002 #* Input: Flags for category and editbox.
1005 #************************************************************************/
1007 void SvxNumberFormatTabPage::UpdateFormatListBox_Impl
1009 sal_uInt16 bCat
, // Category or country/language ListBox?
1010 sal_Bool bUpdateEdit
1013 std::vector
<String
*> aEntryList
;
1014 short nFmtLbSelPos
= 0;
1019 nTmpCatPos
=nFixedCategory
;
1023 nTmpCatPos
=m_pLbCategory
->GetSelectEntryPos();
1029 if(nTmpCatPos
!=CAT_CURRENCY
)
1030 m_pLbCurrency
->Hide();
1032 m_pLbCurrency
->Show();
1034 pNumFmtShell
->CategoryChanged( nTmpCatPos
,nFmtLbSelPos
, aEntryList
);
1037 pNumFmtShell
->LanguageChanged( m_pLbLanguage
->GetSelectLanguage(),
1038 nFmtLbSelPos
,aEntryList
);
1040 REMOVE_DONTKNOW() // possibly UI-Enable
1043 if ( (!aEntryList
.empty()) && (nFmtLbSelPos
!= SELPOS_NONE
) )
1047 String aFormat
=*aEntryList
[nFmtLbSelPos
];
1048 m_pEdFormat
->SetText(aFormat
);
1049 m_pFtComment
->SetText(pNumFmtShell
->GetComment4Entry(nFmtLbSelPos
));
1052 if(!bOneAreaFlag
|| !bCat
)
1054 FillFormatListBox_Impl( aEntryList
);
1055 m_pLbFormat
->SelectEntryPos( nFmtLbSelPos
);
1057 m_pFtComment
->SetText(pNumFmtShell
->GetComment4Entry(nFmtLbSelPos
));
1058 if(pNumFmtShell
->GetUserDefined4Entry(nFmtLbSelPos
))
1060 if(pNumFmtShell
->GetComment4Entry(nFmtLbSelPos
).Len()==0)
1062 m_pFtComment
->SetText(m_pLbCategory
->GetEntry(1));
1065 ChangePreviewText( (sal_uInt16
)nFmtLbSelPos
);
1071 FillFormatListBox_Impl( aEntryList
);
1072 if(nFmtLbSelPos
!= SELPOS_NONE
)
1074 m_pLbFormat
->SelectEntryPos( (sal_uInt16
)nFmtLbSelPos
);
1076 m_pFtComment
->SetText(pNumFmtShell
->GetComment4Entry(nFmtLbSelPos
));
1077 if(pNumFmtShell
->GetUserDefined4Entry(nFmtLbSelPos
))
1079 if(pNumFmtShell
->GetComment4Entry(nFmtLbSelPos
).Len()==0)
1081 m_pFtComment
->SetText(m_pLbCategory
->GetEntry(1));
1087 m_pLbFormat
->SetNoSelection();
1092 m_pEdFormat
->SetText( String() );
1093 m_pWndPreview
->NotifyChange( String() );
1097 DeleteEntryList_Impl( aEntryList
);
1101 /*************************************************************************
1102 #* Handle: DoubleClickHdl_Impl
1103 #*------------------------------------------------------------------------
1105 #* Class: SvxNumberFormatTabPage
1106 #* Function: On a double click in the format lisbox the
1107 #* value is adopted and the OK button pushed.
1108 #* Input: Pointer on the Listbox
1111 #************************************************************************/
1113 IMPL_LINK( SvxNumberFormatTabPage
, DoubleClickHdl_Impl
, SvxFontListBox
*, pLb
)
1115 if (pLb
== m_pLbFormat
)
1117 SelFormatHdl_Impl( pLb
);
1119 if ( fnOkHdl
.IsSet() )
1120 { // temporary solution, should be offered by SfxTabPage
1121 fnOkHdl
.Call( NULL
);
1125 SfxNoLayoutSingleTabDialog
* pParent
= dynamic_cast< SfxNoLayoutSingleTabDialog
* >( GetParentDialog() );
1126 OKButton
* pOKButton
= pParent
? pParent
->GetOKButton() : NULL
;
1135 /*************************************************************************
1136 #* Method: SelFormatHdl_Impl
1137 #*------------------------------------------------------------------------
1139 #* Class: SvxNumberFormatTabPage
1140 #* Function: Is called when the language, the category or the format
1141 #* is changed. Accordingly the settings are adjusted.
1142 #* Input: Pointer on the Listbox
1145 #************************************************************************/
1147 IMPL_LINK( SvxNumberFormatTabPage
, SelFormatHdl_Impl
, void *, pLb
)
1149 if (pLb
== m_pCbSourceFormat
)
1151 EnableBySourceFormat_Impl(); // enable/disable everything else
1152 if ( m_pCbSourceFormat
->IsChecked() )
1153 return 0; // just disabled everything else
1155 // Reinit options enable/disable for current selection.
1157 // Current category may be UserDefined with no format entries defined.
1158 // And yes, m_pLbFormat is a SvxFontListBox with sal_uLong list positions,
1159 // implementation returns a LIST_APPEND if empty, comparison with
1160 // sal_uInt16 LISTBOX_ENTRY_NOTFOUND wouldn't match.
1161 if ( m_pLbFormat
->GetSelectEntryPos() == LIST_APPEND
)
1162 pLb
= m_pLbCategory
; // continue with the current category selected
1164 pLb
= m_pLbFormat
; // continue with the current format selected
1171 nTmpCatPos
=nFixedCategory
;
1175 nTmpCatPos
=m_pLbCategory
->GetSelectEntryPos();
1178 sal_uInt16 nCurrencyPos
=LISTBOX_ENTRY_NOTFOUND
;
1180 if (nTmpCatPos
==CAT_CURRENCY
&& pLb
== m_pLbCurrency
)
1182 nCurrencyPos
= m_pLbCurrency
->GetSelectEntryPos();
1183 pNumFmtShell
->SetCurrencySymbol(nCurrencyPos
);
1186 //--------------------------------------------------------------------
1187 // Format-ListBox ----------------------------------------------------
1188 if (pLb
== m_pLbFormat
)
1190 sal_uInt16 nSelPos
= (sal_uInt16
) m_pLbFormat
->GetSelectEntryPos();
1191 String aFormat
= m_pLbFormat
->GetSelectEntry();
1194 short nFmtLbSelPos
= nSelPos
;
1196 aFormat
=pNumFmtShell
->GetFormat4Entry(nSelPos
);
1197 aComment
=pNumFmtShell
->GetComment4Entry(nSelPos
);
1198 if(pNumFmtShell
->GetUserDefined4Entry(nFmtLbSelPos
))
1200 if(pNumFmtShell
->GetComment4Entry(nFmtLbSelPos
).Len()==0)
1202 aComment
= m_pLbCategory
->GetEntry(1);
1206 if ( aFormat
.Len() > 0 )
1208 if(!m_pEdFormat
->HasFocus()) m_pEdFormat
->SetText( aFormat
);
1209 m_pFtComment
->SetText(aComment
);
1210 ChangePreviewText( nSelPos
);
1213 REMOVE_DONTKNOW() // possibly UI-Enable
1215 if ( pNumFmtShell
->FindEntry( aFormat
) )
1217 m_pIbAdd
->Enable(sal_False
);
1218 sal_Bool bIsUserDef
=pNumFmtShell
->IsUserDefined( aFormat
);
1219 m_pIbRemove
->Enable(bIsUserDef
);
1220 m_pIbInfo
->Enable(bIsUserDef
);
1225 m_pIbAdd
->Enable(sal_True
);
1226 m_pIbInfo
->Enable(sal_True
);
1227 m_pIbRemove
->Enable(sal_False
);
1228 m_pFtComment
->SetText(m_pEdComment
->GetText());
1231 UpdateOptions_Impl( sal_False
);
1236 //--------------------------------------------------------------------
1237 // category-ListBox -------------------------------------------------
1238 if (pLb
== m_pLbCategory
|| pLb
== m_pLbCurrency
)
1240 UpdateFormatListBox_Impl( sal_True
, sal_True
);
1241 EditHdl_Impl( NULL
);
1242 UpdateOptions_Impl( sal_False
);
1247 //--------------------------------------------------------------------
1248 // language/country-ListBox ----------------------------------------------
1249 if (pLb
== m_pLbLanguage
)
1251 UpdateFormatListBox_Impl( sal_False
, sal_True
);
1252 EditHdl_Impl(m_pEdFormat
);
1260 /*************************************************************************
1261 #* Method: ClickHdl_Impl, PushButton* pIB
1262 #*------------------------------------------------------------------------
1264 #* Class: SvxNumberFormatTabPage
1265 #* Function: Called when the add or delete button is pushed,
1266 #* adjusts the number format list.
1267 #* Input: Toolbox- Button
1270 #************************************************************************/
1272 IMPL_LINK( SvxNumberFormatTabPage
, ClickHdl_Impl
, PushButton
*, pIB
)
1274 sal_Bool bAdded
= sal_False
;
1275 sal_Bool bDeleted
= sal_False
;
1276 sal_uLong nReturn
= 0;
1277 const sal_uLong nReturnChanged
= 0x1; // THE boolean return value
1278 const sal_uLong nReturnAdded
= 0x2; // temp: format added
1279 const sal_uLong nReturnOneArea
= 0x4; // temp: one area but category changed => ignored
1281 if (pIB
== m_pIbAdd
)
1282 { // Also called from FillItemSet() if a temporary currency format has
1283 // to be added, not only if the Add button is enabled.
1284 String aFormat
= m_pEdFormat
->GetText();
1285 std::vector
<String
*> aEntryList
;
1286 std::vector
<String
*> a2EntryList
;
1287 sal_uInt16 nCatLbSelPos
= 0;
1288 short nFmtLbSelPos
= SELPOS_NONE
;
1289 xub_StrLen nErrPos
=0;
1291 pNumFmtShell
->SetCurCurrencyEntry(NULL
);
1292 bAdded
= pNumFmtShell
->AddFormat( aFormat
, nErrPos
,
1293 nCatLbSelPos
, nFmtLbSelPos
,
1296 nReturn
|= nReturnChanged
| nReturnAdded
;
1298 if (pLastActivWindow
== m_pEdComment
)
1300 m_pEdFormat
->GrabFocus();
1301 m_pEdComment
->Hide();
1302 m_pFtComment
->Show();
1303 m_pFtComment
->SetText(m_pEdComment
->GetText());
1306 if ( !nErrPos
) // Syntax ok?
1308 // May be sorted under a different locale if LCID was parsed.
1310 m_pLbLanguage
->SelectLanguage( pNumFmtShell
->GetCurLanguage() );
1312 if(nCatLbSelPos
==CAT_CURRENCY
)
1314 m_pLbCurrency
->SelectEntryPos((sal_uInt16
)pNumFmtShell
->GetCurrencySymbol());
1317 if(bOneAreaFlag
&& (nFixedCategory
!=nCatLbSelPos
))
1319 if(bAdded
) DeleteEntryList_Impl(aEntryList
);
1320 bDeleted
= pNumFmtShell
->RemoveFormat( aFormat
,
1324 if(bDeleted
) DeleteEntryList_Impl(a2EntryList
);
1325 m_pEdFormat
->GrabFocus();
1326 m_pEdFormat
->SetSelection( Selection( (short)nErrPos
, SELECTION_MAX
) );
1327 nReturn
|= nReturnOneArea
;
1331 if ( bAdded
&& (nFmtLbSelPos
!= SELPOS_NONE
) )
1333 // everything alright
1334 if(bOneAreaFlag
) //@@ ???
1337 SetCategory(nCatLbSelPos
);
1339 FillFormatListBox_Impl( aEntryList
);
1340 if(m_pEdComment
->GetText()!=OUString(m_pLbCategory
->GetEntry(1)))
1342 pNumFmtShell
->SetComment4Entry(nFmtLbSelPos
,
1343 m_pEdComment
->GetText());
1347 pNumFmtShell
->SetComment4Entry(nFmtLbSelPos
,
1350 m_pLbFormat
->SelectEntryPos( (sal_uInt16
)nFmtLbSelPos
);
1351 m_pEdFormat
->SetText( aFormat
);
1353 m_pEdComment
->SetText(m_pLbCategory
->GetEntry(1)); // String for user defined
1355 ChangePreviewText( (sal_uInt16
)nFmtLbSelPos
);
1359 else // syntax error
1361 m_pEdFormat
->GrabFocus();
1362 m_pEdFormat
->SetSelection( Selection( (short)nErrPos
, SELECTION_MAX
) );
1364 EditHdl_Impl(m_pEdFormat
);
1365 nReturn
= ((nReturn
& nReturnOneArea
) ? 0 : (nReturn
& nReturnChanged
));
1367 DeleteEntryList_Impl( aEntryList
);
1368 DeleteEntryList_Impl( a2EntryList
);
1370 else if (pIB
== m_pIbRemove
)
1372 String aFormat
= m_pEdFormat
->GetText();
1373 std::vector
<String
*> aEntryList
;
1374 sal_uInt16 nCatLbSelPos
= 0;
1375 short nFmtLbSelPos
= SELPOS_NONE
;
1377 bDeleted
= pNumFmtShell
->RemoveFormat( aFormat
,
1382 m_pEdComment
->SetText(m_pLbCategory
->GetEntry(1));
1385 if( nFmtLbSelPos
>=0 && static_cast<size_t>(nFmtLbSelPos
)<aEntryList
.size() )
1387 aFormat
= *aEntryList
[nFmtLbSelPos
];
1390 FillFormatListBox_Impl( aEntryList
);
1392 if ( nFmtLbSelPos
!= SELPOS_NONE
)
1394 if(bOneAreaFlag
) //@@ ???
1397 SetCategory(nCatLbSelPos
);
1399 m_pLbFormat
->SelectEntryPos( (sal_uInt16
)nFmtLbSelPos
);
1400 m_pEdFormat
->SetText( aFormat
);
1401 ChangePreviewText( (sal_uInt16
)nFmtLbSelPos
);
1405 // set to "all/standard"
1407 SelFormatHdl_Impl(m_pLbCategory
);
1410 EditHdl_Impl(m_pEdFormat
);
1412 DeleteEntryList_Impl( aEntryList
);
1414 else if (pIB
== m_pIbInfo
)
1416 if(!(pLastActivWindow
== m_pEdComment
))
1418 m_pEdComment
->SetText(m_pFtComment
->GetText());
1419 m_pEdComment
->Show();
1420 m_pFtComment
->Hide();
1421 m_pEdComment
->GrabFocus();
1425 m_pEdFormat
->GrabFocus();
1426 m_pEdComment
->Hide();
1427 m_pFtComment
->Show();
1435 /*************************************************************************
1436 #* Method: EditHdl_Impl
1437 #*------------------------------------------------------------------------
1439 #* Class: SvxNumberFormatTabPage
1440 #* Function: When the entry in the edit field is changed
1441 #* the preview is updated and
1442 #* Input: Pointer on Editbox
1445 #************************************************************************/
1447 IMPL_LINK( SvxNumberFormatTabPage
, EditHdl_Impl
, Edit
*, pEdFormat
)
1449 sal_uInt32 nCurKey
= NUMKEY_UNDEFINED
;
1451 if ( m_pEdFormat
->GetText().isEmpty() )
1453 m_pIbAdd
->Enable(sal_False
);
1454 m_pIbRemove
->Enable(sal_False
);
1455 m_pIbInfo
->Enable(sal_False
);
1456 m_pFtComment
->SetText(OUString());
1460 String aFormat
= m_pEdFormat
->GetText();
1461 MakePreviewText( aFormat
);
1463 if ( pNumFmtShell
->FindEntry( aFormat
, &nCurKey
) )
1465 m_pIbAdd
->Enable(sal_False
);
1466 sal_Bool bUserDef
=pNumFmtShell
->IsUserDefined( aFormat
);
1468 m_pIbRemove
->Enable(bUserDef
);
1469 m_pIbInfo
->Enable(bUserDef
);
1473 sal_uInt16 nTmpCurPos
=pNumFmtShell
->FindCurrencyFormat(aFormat
);
1475 if(nTmpCurPos
!=(sal_uInt16
)-1)
1476 m_pLbCurrency
->SelectEntryPos(nTmpCurPos
);
1478 short nPosi
=pNumFmtShell
->GetListPos4Entry(aFormat
);
1480 m_pLbFormat
->SelectEntryPos( (sal_uInt16
)nPosi
);
1486 m_pIbAdd
->Enable(sal_True
);
1487 m_pIbInfo
->Enable(sal_True
);
1488 m_pIbRemove
->Enable(sal_False
);
1490 m_pFtComment
->SetText(m_pEdComment
->GetText());
1497 pNumFmtShell
->SetCurNumFmtKey( nCurKey
);
1498 UpdateOptions_Impl( sal_True
);
1505 /*************************************************************************
1506 #* Method: NotifyChange
1507 #*------------------------------------------------------------------------
1509 #* Class: SvxNumberFormatTabPage
1510 #* Function: Does changes in the number attributes.
1511 #* Input: Options- Controls
1514 #************************************************************************/
1516 IMPL_LINK( SvxNumberFormatTabPage
, OptHdl_Impl
, void *, pOptCtrl
)
1518 if ( (pOptCtrl
== m_pEdLeadZeroes
)
1519 || (pOptCtrl
== m_pEdDecimals
)
1520 || (pOptCtrl
== m_pBtnNegRed
)
1521 || (pOptCtrl
== m_pBtnThousand
) )
1524 sal_Bool bThousand
= m_pBtnThousand
->IsEnabled()
1525 && m_pBtnThousand
->IsChecked();
1526 sal_Bool bNegRed
= m_pBtnNegRed
->IsEnabled()
1527 && m_pBtnNegRed
->IsChecked();
1528 sal_uInt16 nPrecision
= (m_pEdDecimals
->IsEnabled())
1529 ? (sal_uInt16
)m_pEdDecimals
->GetValue()
1531 sal_uInt16 nLeadZeroes
= (m_pEdLeadZeroes
->IsEnabled())
1532 ? (sal_uInt16
)m_pEdLeadZeroes
->GetValue()
1535 pNumFmtShell
->MakeFormat( aFormat
,
1537 nPrecision
, nLeadZeroes
,
1538 (sal_uInt16
)m_pLbFormat
->GetSelectEntryPos() );
1540 m_pEdFormat
->SetText( aFormat
);
1541 MakePreviewText( aFormat
);
1543 if ( pNumFmtShell
->FindEntry( aFormat
) )
1545 m_pIbAdd
->Enable(sal_False
);
1546 sal_Bool bUserDef
=pNumFmtShell
->IsUserDefined( aFormat
);
1547 m_pIbRemove
->Enable(bUserDef
);
1548 m_pIbInfo
->Enable(bUserDef
);
1549 EditHdl_Impl(m_pEdFormat
);
1554 EditHdl_Impl( NULL
);
1555 m_pLbFormat
->SetNoSelection();
1561 IMPL_LINK_NOARG(SvxNumberFormatTabPage
, TimeHdl_Impl
)
1563 pLastActivWindow
=NULL
;
1568 /*************************************************************************
1569 #* Method: LostFocusHdl_Impl
1570 #*------------------------------------------------------------------------
1572 #* Class: SvxNumberFormatTabPage
1573 #* Function: Does changes in the number attributes.
1574 #* Input: Options- Controls
1577 #************************************************************************/
1579 IMPL_LINK( SvxNumberFormatTabPage
, LostFocusHdl_Impl
, Edit
*, pEd
)
1581 if (pEd
== m_pEdComment
)
1583 aResetWinTimer
.Start();
1584 m_pFtComment
->SetText(m_pEdComment
->GetText());
1585 m_pEdComment
->Hide();
1586 m_pFtComment
->Show();
1587 if(!m_pIbAdd
->IsEnabled())
1589 sal_uInt16 nSelPos
= (sal_uInt16
) m_pLbFormat
->GetSelectEntryPos();
1590 pNumFmtShell
->SetComment4Entry(nSelPos
,
1591 m_pEdComment
->GetText());
1592 m_pEdComment
->SetText(m_pLbCategory
->GetEntry(1)); // String for user defined
1598 /*************************************************************************
1599 #* Method: NotifyChange
1600 #*------------------------------------------------------------------------
1602 #* Class: SvxNumberFormatTabPage
1603 #* Function: Does changes in the number attributes.
1604 #* Input: Options- Controls
1607 #************************************************************************/
1609 String
SvxNumberFormatTabPage::GetExpColorString(
1610 Color
*& rpPreviewColor
, const String
& rFormatStr
, short nTmpCatPos
)
1615 case CAT_CURRENCY
: nVal
=SVX_NUMVAL_CURRENCY
; break;
1617 case CAT_SCIENTIFIC
:
1619 case CAT_NUMBER
: nVal
=SVX_NUMVAL_STANDARD
; break;
1621 case CAT_PERCENT
: nVal
=SVX_NUMVAL_PERCENT
; break;
1623 case CAT_ALL
: nVal
=SVX_NUMVAL_STANDARD
; break;
1625 case CAT_TIME
: nVal
=SVX_NUMVAL_TIME
; break;
1626 case CAT_DATE
: nVal
=SVX_NUMVAL_DATE
; break;
1628 case CAT_BOOLEAN
: nVal
=SVX_NUMVAL_BOOLEAN
; break;
1630 case CAT_USERDEFINED
:
1632 default: nVal
=0;break;
1635 String aPreviewString
;
1636 pNumFmtShell
->MakePrevStringFromVal( rFormatStr
, aPreviewString
, rpPreviewColor
, nVal
);
1637 return aPreviewString
;
1640 void SvxNumberFormatTabPage::MakePreviewText( const String
& rFormat
)
1642 String aPreviewString
;
1643 Color
* pPreviewColor
= NULL
;
1644 pNumFmtShell
->MakePreviewString( rFormat
, aPreviewString
, pPreviewColor
);
1645 m_pWndPreview
->NotifyChange( aPreviewString
, pPreviewColor
);
1648 void SvxNumberFormatTabPage::ChangePreviewText( sal_uInt16 nPos
)
1650 String aPreviewString
;
1651 Color
* pPreviewColor
= NULL
;
1652 pNumFmtShell
->FormatChanged( nPos
, aPreviewString
, pPreviewColor
);
1653 m_pWndPreview
->NotifyChange( aPreviewString
, pPreviewColor
);
1656 long SvxNumberFormatTabPage::PreNotify( NotifyEvent
& rNEvt
)
1658 if(rNEvt
.GetType()==EVENT_LOSEFOCUS
)
1660 if ( rNEvt
.GetWindow() == dynamic_cast< Window
* >( m_pEdComment
) && !m_pEdComment
->IsVisible() )
1662 pLastActivWindow
= NULL
;
1666 pLastActivWindow
= rNEvt
.GetWindow();
1670 return SfxTabPage::PreNotify( rNEvt
);
1672 /*************************************************************************
1674 #*------------------------------------------------------------------------
1676 #* Class: SvxNumberFormatTabPage
1677 #* Function: Resets the OkHandler.
1678 #* Input: new OkHandler
1681 #************************************************************************/
1683 void SvxNumberFormatTabPage::SetOkHdl( const Link
& rOkHandler
)
1685 fnOkHdl
= rOkHandler
;
1688 void SvxNumberFormatTabPage::FillCurrencyBox()
1690 std::vector
<OUString
> aList
;
1692 sal_uInt16 nSelPos
=0;
1693 pNumFmtShell
->GetCurrencySymbols(aList
, &nSelPos
);
1695 for(std::vector
<OUString
>::iterator i
= aList
.begin() + 1;i
!= aList
.end(); ++i
)
1696 m_pLbCurrency
->InsertEntry(*i
);
1698 m_pLbCurrency
->SelectEntryPos(nSelPos
);
1701 void SvxNumberFormatTabPage::SetCategory(sal_uInt16 nPos
)
1703 sal_uInt16 nCurCategory
= m_pLbCategory
->GetSelectEntryPos();
1704 sal_uInt16 nTmpCatPos
;
1708 nTmpCatPos
=nFixedCategory
;
1715 if(m_pLbCategory
->GetEntryCount()==1 || nCurCategory
!=nPos
)
1717 if(nTmpCatPos
!=CAT_CURRENCY
)
1718 m_pLbCurrency
->Hide();
1720 m_pLbCurrency
->Show();
1722 m_pLbCategory
->SelectEntryPos(nPos
);
1724 /* to support Writer text field language handling an
1725 additional entry needs to be inserted into the ListBox
1726 which marks a certain language as automatically detected
1727 Additionally the "Default" language is removed
1729 void SvxNumberFormatTabPage::AddAutomaticLanguage_Impl(LanguageType eAutoLang
, sal_Bool bSelect
)
1731 m_pLbLanguage
->RemoveLanguage(LANGUAGE_SYSTEM
);
1732 sal_uInt16 nPos
= m_pLbLanguage
->InsertEntry(sAutomaticEntry
);
1733 m_pLbLanguage
->SetEntryData(nPos
, (void*)(sal_uLong
)eAutoLang
);
1735 m_pLbLanguage
->SelectEntryPos(nPos
);
1738 void SvxNumberFormatTabPage::PageCreated (SfxAllItemSet aSet
)
1740 SFX_ITEMSET_ARG (&aSet
,pNumberInfoItem
,SvxNumberInfoItem
,SID_ATTR_NUMBERFORMAT_INFO
,sal_False
);
1741 SFX_ITEMSET_ARG (&aSet
,pLinkItem
,SfxLinkItem
,SID_LINK_TYPE
,sal_False
);
1742 if (pNumberInfoItem
)
1743 SetNumberFormatList(*pNumberInfoItem
);
1745 SetOkHdl(pLinkItem
->GetValue());
1748 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */