update dev300-m58
[ooovba.git] / svx / source / cui / numfmt.cxx
blob716dafc2fcc11310ad67e6104a1c4ee3bb036139
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: numfmt.cxx,v $
10 * $Revision: 1.32.128.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #if !ENABLE_LAYOUT_EXPERIMENTAL
32 //#undef ENABLE_LAYOUT
33 #endif
35 // MARKER(update_precomp.py): autogen include statement, do not remove
36 #include "precompiled_svx.hxx"
38 #ifdef SVX_DLLIMPLEMENTATION
39 #undef SVX_DLLIMPLEMENTATION
40 #endif
42 // include ---------------------------------------------------------------
43 #include <svtools/eitem.hxx>
44 #include <svtools/intitem.hxx>
45 #include <sfx2/objsh.hxx>
46 #include <vcl/svapp.hxx>
47 #include <unotools/localedatawrapper.hxx>
48 #include <i18npool/lang.h>
50 #define _SVSTDARR_STRINGS
51 #define _SVSTDARR_STRINGSDTOR
52 #include <svtools/svstdarr.hxx>
53 #include <svtools/colorcfg.hxx>
55 #define _SVX_NUMFMT_CXX
57 #include <svx/dialogs.hrc>
58 #include "numfmt.hrc"
60 #include <svx/numinf.hxx>
62 #include "numfmt.hxx"
63 #include <svx/numfmtsh.hxx>
64 #include <svx/dialmgr.hxx>
65 #include <sfx2/request.hxx> //CHINA001
66 #include <sfx2/app.hxx> //CHINA001
67 #include <sfx2/basedlgs.hxx>
68 #include "flagsdef.hxx" //CHINA001
70 #define NUMKEY_UNDEFINED SAL_MAX_UINT32
72 // static ----------------------------------------------------------------
74 static USHORT pRanges[] =
76 SID_ATTR_NUMBERFORMAT_VALUE,
77 SID_ATTR_NUMBERFORMAT_INFO,
78 SID_ATTR_NUMBERFORMAT_NOLANGUAGE,
79 SID_ATTR_NUMBERFORMAT_NOLANGUAGE,
80 SID_ATTR_NUMBERFORMAT_ONE_AREA,
81 SID_ATTR_NUMBERFORMAT_ONE_AREA,
82 SID_ATTR_NUMBERFORMAT_SOURCE,
83 SID_ATTR_NUMBERFORMAT_SOURCE,
87 /*************************************************************************
88 #* Methode: SvxNumberPreviewImpl Datum:02.10.97
89 #*------------------------------------------------------------------------
91 #* Klasse: SvxNumberPreview
93 #* Funktion: Konstruktor der Klasse SvxNumberPreviewImpl
95 #* Input: Fenster, Resource-ID
97 #* Output: ---
99 #************************************************************************/
101 SvxNumberPreviewImpl::SvxNumberPreviewImpl( Window* pParent, const ResId& rResId ) :
103 Window( pParent, rResId )
106 Font aFont( GetFont() );
107 aFont.SetTransparent( TRUE );
108 aFont.SetColor( Application::GetSettings().GetStyleSettings().GetFieldColor() );
109 SetFont( aFont );
110 InitSettings( TRUE, TRUE );
111 SetBorderStyle( WINDOW_BORDER_MONO );
114 /*************************************************************************
115 #* Methode: SvxNumberPreviewImpl Datum:02.10.97
116 #*------------------------------------------------------------------------
118 #* Klasse: SvxNumberPreview
120 #* Funktion: Destruktor der Klasse SvxNumberPreviewImpl
122 #* Input: ---
124 #* Output: ---
126 #************************************************************************/
128 SvxNumberPreviewImpl::~SvxNumberPreviewImpl()
132 /*************************************************************************
133 #* Methode: NotifyChange Datum:02.10.97
134 #*------------------------------------------------------------------------
136 #* Klasse: SvxNumberPreviewImpl
138 #* Funktion: Funktion fuer das Aendern des Preview- Strings
140 #* Input: String, Farbe
142 #* Output: ---
144 #************************************************************************/
146 void SvxNumberPreviewImpl::NotifyChange( const String& rPrevStr,
147 const Color* pColor )
149 aPrevStr = rPrevStr;
150 svtools::ColorConfig aColorConfig;
151 Color aWindowTextColor( aColorConfig.GetColorValue( svtools::FONTCOLOR ).nColor );
152 aPrevCol = pColor ? *pColor : aWindowTextColor;
153 Invalidate();
154 Update();
157 /*************************************************************************
158 #* Methode: Paint Datum:02.10.97
159 #*------------------------------------------------------------------------
161 #* Klasse: SvxNumberPreviewImpl
163 #* Funktion: Funktion fuer das neu zeichnen des Fensters.
165 #* Input: ---
167 #* Output: ---
169 #************************************************************************/
171 void SvxNumberPreviewImpl::Paint( const Rectangle& )
173 Font aDrawFont = GetFont();
174 Size aSzWnd = GetOutputSizePixel();
175 Point aPosText = Point( (aSzWnd.Width() - GetTextWidth( aPrevStr )) /2,
176 (aSzWnd.Height() - GetTextHeight())/2 );
178 aDrawFont.SetColor( aPrevCol );
179 SetFont( aDrawFont );
180 DrawText( aPosText, aPrevStr );
183 // -----------------------------------------------------------------------
185 void SvxNumberPreviewImpl::InitSettings( BOOL bForeground, BOOL bBackground )
187 const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
189 if ( bForeground )
191 svtools::ColorConfig aColorConfig;
192 Color aTextColor( aColorConfig.GetColorValue( svtools::FONTCOLOR ).nColor );
194 if ( IsControlForeground() )
195 aTextColor = GetControlForeground();
196 SetTextColor( aTextColor );
199 if ( bBackground )
201 if ( IsControlBackground() )
202 SetBackground( GetControlBackground() );
203 else
204 SetBackground( rStyleSettings.GetWindowColor() );
206 Invalidate();
209 // -----------------------------------------------------------------------
211 void SvxNumberPreviewImpl::StateChanged( StateChangedType nType )
213 if ( nType == STATE_CHANGE_CONTROLFOREGROUND )
214 InitSettings( TRUE, FALSE );
215 else if ( nType == STATE_CHANGE_CONTROLBACKGROUND )
216 InitSettings( FALSE, TRUE );
218 Window::StateChanged( nType );
221 // -----------------------------------------------------------------------
223 void SvxNumberPreviewImpl::DataChanged( const DataChangedEvent& rDCEvt )
225 Window::DataChanged( rDCEvt );
227 if ( ( rDCEvt.GetType() == DATACHANGED_SETTINGS ) && ( rDCEvt.GetFlags() & SETTINGS_STYLE ) )
228 InitSettings( TRUE, TRUE );
231 // class SvxNumberFormatTabPage ------------------------------------------
233 #define REMOVE_DONTKNOW() \
234 if ( !aFtLanguage.IsEnabled() ) \
236 aFtLanguage .Enable(); \
237 aLbLanguage .Enable(); \
238 aLbLanguage .SelectLanguage( pNumFmtShell->GetCurLanguage() ); \
241 #define HDL(hdl) LINK( this, SvxNumberFormatTabPage, hdl )
243 #include <layout/layout-pre.hxx>
245 #if ENABLE_LAYOUT
246 #undef SVX_RES
247 #define SVX_RES(x) #x
248 #define SVX_RES_PLAIN(x) ResId (x, DIALOG_MGR ())
249 #define THIS_SVX_RES(x) this, #x
250 #undef SfxTabPage
251 #define SfxTabPage( parent, id, args ) SfxTabPage( parent, "number-format.xml", id, &args )
252 #else /* !ENABLE_LAYOUT */
253 #define SVX_RES_PLAIN SVX_RES
254 #define THIS_SVX_RES SVX_RES
255 #endif /* !ENABLE_LAYOUT */
257 SvxNumberFormatTabPage::SvxNumberFormatTabPage( Window* pParent,
258 const SfxItemSet& rCoreAttrs )
260 : SfxTabPage( pParent, SVX_RES( RID_SVXPAGE_NUMBERFORMAT ), rCoreAttrs ),
262 aFtCategory ( this, SVX_RES( FT_CATEGORY ) ),
263 aLbCategory ( this, SVX_RES( LB_CATEGORY ) ),
264 aFtFormat ( this, SVX_RES( FT_FORMAT ) ),
265 aLbCurrency ( this, SVX_RES( LB_CURRENCY) ),
266 aLbFormat ( this, SVX_RES( LB_FORMAT ) ),
267 aFtLanguage ( this, SVX_RES( FT_LANGUAGE ) ),
268 aLbLanguage ( this, SVX_RES( LB_LANGUAGE ), FALSE ),
269 aCbSourceFormat ( this, SVX_RES( CB_SOURCEFORMAT ) ),
270 aFtDecimals ( this, SVX_RES( FT_DECIMALS ) ),
271 aEdDecimals ( this, SVX_RES( ED_DECIMALS ) ),
272 aFtLeadZeroes ( this, SVX_RES( FT_LEADZEROES ) ),
273 aEdLeadZeroes ( this, SVX_RES( ED_LEADZEROES ) ),
274 aBtnNegRed ( this, SVX_RES( BTN_NEGRED ) ),
275 aBtnThousand ( this, SVX_RES( BTN_THOUSAND ) ),
276 aFlOptions ( this, SVX_RES( FL_OPTIONS ) ),
278 aFtEdFormat ( this, SVX_RES( FT_EDFORMAT ) ),
279 aEdFormat ( this, SVX_RES( ED_FORMAT ) ),
280 aIbAdd ( this, SVX_RES( IB_ADD ) ),
281 aIbInfo ( this, SVX_RES( IB_INFO ) ),
282 aIbRemove ( this, SVX_RES( IB_REMOVE ) ),
283 aFtComment ( this, SVX_RES( FT_COMMENT ) ),
284 aEdComment ( this, SVX_RES( ED_COMMENT ) ),
286 #if ENABLE_LAYOUT
287 aWndPreview ( LAYOUT_THIS_WINDOW(this), SVX_RES_PLAIN( WND_NUMBER_PREVIEW ) ),
288 #else
289 aWndPreview ( this, SVX_RES_PLAIN( WND_NUMBER_PREVIEW ) ),
290 #endif
291 pNumItem ( NULL ),
292 pNumFmtShell ( NULL ),
293 nInitFormat ( ULONG_MAX ),
295 aStrEurope ( THIS_SVX_RES( STR_EUROPE) ),
296 sAutomaticEntry ( THIS_SVX_RES( STR_AUTO_ENTRY)),
297 pLastActivWindow( NULL )
299 #if ENABLE_LAYOUT
300 aLbFormat.Clear ();
301 #endif /* ENABLE_LAYOUT */
303 Init_Impl();
304 SetExchangeSupport(); // diese Page braucht ExchangeSupport
305 FreeResource();
306 nFixedCategory=-1;
309 SvxNumberFormatTabPage::~SvxNumberFormatTabPage()
311 delete pNumFmtShell;
312 delete pNumItem;
315 void SvxNumberFormatTabPage::Init_Impl()
317 ImageList aIconList( SVX_RES_PLAIN ( IL_ICON ) );
318 ImageList aIconListHC( SVX_RES_PLAIN ( IL_ICON_HC ) );
320 bNumItemFlag=TRUE;
321 bOneAreaFlag=FALSE;
323 nCatHeight=aLbCategory.GetSizePixel().Height();
325 nCurFormatY =aLbFormat.GetPosPixel().Y();
326 nCurFormatHeight=aLbFormat.GetSizePixel().Height();
327 nStdFormatY =aLbCurrency.GetPosPixel().Y();
328 nStdFormatHeight=nCurFormatY-nStdFormatY+nCurFormatHeight;
330 aIbAdd. SetModeImage( aIconList.GetImage( IID_ADD ) );
331 aIbAdd. SetModeImage( aIconListHC.GetImage( IID_ADD ), BMP_COLOR_HIGHCONTRAST );
333 aIbRemove. SetModeImage( aIconList.GetImage( IID_REMOVE ) );
334 aIbRemove. SetModeImage( aIconListHC.GetImage( IID_REMOVE ), BMP_COLOR_HIGHCONTRAST );
336 aIbInfo. SetModeImage( aIconList.GetImage( IID_INFO ) );
337 aIbInfo. SetModeImage( aIconListHC.GetImage( IID_INFO ), BMP_COLOR_HIGHCONTRAST );
339 aIbAdd.Enable(FALSE );
340 aIbRemove.Enable(FALSE );
341 aIbInfo.Enable(FALSE );
343 aEdComment.SetText(aLbCategory.GetEntry(1)); //String fuer Benutzerdefiniert
344 //holen
345 aEdComment.Hide();
347 aCbSourceFormat.Check( FALSE );
348 aCbSourceFormat.Disable();
349 aCbSourceFormat.Hide();
351 // Handler verbinden
352 Link aLink = LINK( this, SvxNumberFormatTabPage, SelFormatHdl_Impl );
354 aLbCategory .SetSelectHdl( aLink );
355 aLbFormat .SetSelectHdl( aLink );
356 aLbLanguage .SetSelectHdl( aLink );
357 aLbCurrency .SetSelectHdl( aLink );
358 aCbSourceFormat .SetClickHdl( aLink );
360 aLink = LINK( this, SvxNumberFormatTabPage, OptHdl_Impl );
362 aEdDecimals .SetModifyHdl( aLink );
363 aEdLeadZeroes .SetModifyHdl( aLink );
364 aBtnNegRed .SetClickHdl( aLink );
365 aBtnThousand .SetClickHdl( aLink );
366 aLbFormat .SetDoubleClickHdl( HDL( DoubleClickHdl_Impl ) );
367 aEdFormat .SetModifyHdl( HDL( EditHdl_Impl ) );
368 aIbAdd.SetClickHdl( HDL( ClickHdl_Impl ) );
369 aIbRemove.SetClickHdl( HDL( ClickHdl_Impl ) );
370 aIbInfo.SetClickHdl( HDL( ClickHdl_Impl ) );
372 aLink = LINK( this, SvxNumberFormatTabPage, LostFocusHdl_Impl);
374 aEdComment .SetLoseFocusHdl( aLink);
375 aResetWinTimer .SetTimeoutHdl(LINK( this, SvxNumberFormatTabPage, TimeHdl_Impl));
376 aResetWinTimer .SetTimeout( 10);
378 // Sprachen-ListBox initialisieren
380 aLbLanguage.InsertLanguage( LANGUAGE_SYSTEM );
381 // Don't list ambiguous locales where we won't be able to convert the
382 // LanguageType back to an identical Language_Country name and therefore
383 // couldn't load the i18n LocaleData. Show DebugMsg in non-PRODUCT version.
384 ::com::sun::star::uno::Sequence< sal_uInt16 > xLang =
385 LocaleDataWrapper::getInstalledLanguageTypes();
386 sal_Int32 nCount = xLang.getLength();
387 for ( sal_Int32 i=0; i<nCount; i++ )
389 aLbLanguage.InsertLanguage( xLang[i] );
393 /*************************************************************************
394 #* Methode: GetRanges Datum:02.10.97
395 #*------------------------------------------------------------------------
397 #* Klasse: SvxNumberFormatTabPage
399 #* Funktion: Liefert Bereichsangaben zurueck.
401 #* Input: ---
403 #* Output: Bereich
405 #************************************************************************/
407 USHORT* SvxNumberFormatTabPage::GetRanges()
409 return pRanges;
413 /*************************************************************************
414 #* Methode: Create Datum:02.10.97
415 #*------------------------------------------------------------------------
417 #* Klasse: SvxNumberFormatTabPage
419 #* Funktion: Erzeugt eine neue Zahlenformat- Seite.
421 #* Input: Fenster, SfxItemSet
423 #* Output: neue TabPage
425 #************************************************************************/
427 SfxTabPage* SvxNumberFormatTabPage::Create( Window* pParent,
428 const SfxItemSet& rAttrSet )
430 return ( new SvxNumberFormatTabPage( pParent, rAttrSet ) );
434 /*************************************************************************
435 #* Methode: Reset Datum:02.10.97
436 #*------------------------------------------------------------------------
438 #* Klasse: SvxNumberFormatTabPage
440 #* Funktion: Die Attribute des Dialogs werden mit Hilfe
441 #* des Itemsets neu eingestellt.
443 #* Input: SfxItemSet
445 #* Output: ---
447 #************************************************************************/
449 void SvxNumberFormatTabPage::Reset( const SfxItemSet& rSet )
451 const SfxUInt32Item* pValFmtAttr = NULL;
452 const SfxPoolItem* pItem = NULL;
453 const SfxBoolItem* pAutoEntryAttr = NULL;
455 USHORT nCatLbSelPos = 0;
456 USHORT nFmtLbSelPos = 0;
457 LanguageType eLangType = LANGUAGE_DONTKNOW;
458 SvxDelStrgs aFmtEntryList;
459 SvxNumberValueType eValType = SVX_VALUE_TYPE_UNDEFINED;
460 double nValDouble = 0;
461 String aValString;
462 SfxItemState eState = SFX_ITEM_DONTCARE;
465 eState = rSet.GetItemState( GetWhich( SID_ATTR_NUMBERFORMAT_NOLANGUAGE ),TRUE,&pItem);
467 if(eState==SFX_ITEM_SET)
469 const SfxBoolItem* pBoolLangItem = (const SfxBoolItem*)
470 GetItem( rSet, SID_ATTR_NUMBERFORMAT_NOLANGUAGE);
472 if(pBoolLangItem!=NULL && pBoolLangItem->GetValue())
474 HideLanguage();
476 else
478 HideLanguage(FALSE);
483 eState = rSet.GetItemState( GetWhich( SID_ATTR_NUMBERFORMAT_INFO ),TRUE,&pItem);
485 if(eState==SFX_ITEM_SET)
487 if(pNumItem==NULL)
489 bNumItemFlag=TRUE;
490 pNumItem= (SvxNumberInfoItem *) pItem->Clone();
492 else
494 bNumItemFlag=FALSE;
497 else
499 bNumItemFlag=FALSE;
503 eState = rSet.GetItemState( GetWhich( SID_ATTR_NUMBERFORMAT_ONE_AREA ));
505 if(eState==SFX_ITEM_SET)
507 const SfxBoolItem* pBoolItem = (const SfxBoolItem*)
508 GetItem( rSet, SID_ATTR_NUMBERFORMAT_ONE_AREA);
510 if(pBoolItem!=NULL)
512 bOneAreaFlag= pBoolItem->GetValue();
515 //bOneAreaFlag=TRUE; //@@ Debug-Test
517 eState = rSet.GetItemState( GetWhich( SID_ATTR_NUMBERFORMAT_SOURCE ) );
519 if ( eState == SFX_ITEM_SET )
521 const SfxBoolItem* pBoolItem = (const SfxBoolItem*)
522 GetItem( rSet, SID_ATTR_NUMBERFORMAT_SOURCE );
523 if ( pBoolItem )
524 aCbSourceFormat.Check( pBoolItem->GetValue() );
525 else
526 aCbSourceFormat.Check( FALSE );
527 aCbSourceFormat.Enable();
528 aCbSourceFormat.Show();
530 else
532 BOOL bInit = FALSE; // set to TRUE for debug test
533 aCbSourceFormat.Check( bInit );
534 aCbSourceFormat.Enable( bInit );
535 aCbSourceFormat.Show( bInit );
538 // pNumItem muss von aussen gesetzt worden sein!
539 DBG_ASSERT( pNumItem, "No NumberInfo, no NumberFormatter, good bye.CRASH. :-(" );
541 // aktuellen Zahlenformat-Tabellenindex holen
542 eState = rSet.GetItemState( GetWhich( SID_ATTR_NUMBERFORMAT_VALUE ) );
544 if ( SFX_ITEM_DONTCARE != eState )
545 pValFmtAttr = (const SfxUInt32Item*)
546 GetItem( rSet, SID_ATTR_NUMBERFORMAT_VALUE );
548 eValType = pNumItem->GetValueType();
550 switch ( eValType )
552 case SVX_VALUE_TYPE_STRING:
553 aValString = pNumItem->GetValueString();
554 break;
555 case SVX_VALUE_TYPE_NUMBER:
556 // #50441# string may be set in addition to the value
557 aValString = pNumItem->GetValueString();
558 nValDouble = pNumItem->GetValueDouble();
559 break;
560 case SVX_VALUE_TYPE_UNDEFINED:
561 default:
562 break;
565 // nun sind alle Informationen fuer die Formatierer-Shell beisammen:
567 if ( pNumFmtShell )
568 delete pNumFmtShell; // ggF. alte Shell loeschen (==Reset)
570 nInitFormat = ( pValFmtAttr ) // Init-Key merken
571 ? pValFmtAttr->GetValue() // (fuer FillItemSet())
572 : ULONG_MAX; // == DONT_KNOW
575 if ( eValType == SVX_VALUE_TYPE_STRING )
576 pNumFmtShell =SvxNumberFormatShell::Create(
577 pNumItem->GetNumberFormatter(),
578 (pValFmtAttr) ? nInitFormat : 0L,
579 eValType,
580 aValString );
581 else
582 pNumFmtShell =SvxNumberFormatShell::Create(
583 pNumItem->GetNumberFormatter(),
584 (pValFmtAttr) ? nInitFormat : 0L,
585 eValType,
586 nValDouble,
587 &aValString );
589 FillCurrencyBox();
591 String aPrevString;
592 Color* pDummy = NULL;
593 pNumFmtShell->GetInitSettings( nCatLbSelPos, eLangType, nFmtLbSelPos,
594 aFmtEntryList, aPrevString, pDummy );
596 aLbCurrency.SelectEntryPos((USHORT)pNumFmtShell->GetCurrencySymbol());
598 nFixedCategory=nCatLbSelPos;
599 if(bOneAreaFlag)
601 String sFixedCategory=aLbCategory.GetEntry(nFixedCategory);
602 aLbCategory.Clear();
603 aLbCategory.InsertEntry(sFixedCategory);
604 SetCategory(0);
606 else
608 SetCategory(nCatLbSelPos );
610 eState = rSet.GetItemState( GetWhich( SID_ATTR_NUMBERFORMAT_ADD_AUTO ) );
611 if(SFX_ITEM_SET == eState)
612 pAutoEntryAttr = (const SfxBoolItem*)
613 GetItem( rSet, SID_ATTR_NUMBERFORMAT_ADD_AUTO );
614 // no_NO is an alias for nb_NO and normally isn't listed, we need it for
615 // backwards compatibility, but only if the format passed is of
616 // LanguageType no_NO.
617 if ( eLangType == LANGUAGE_NORWEGIAN )
619 aLbLanguage.RemoveLanguage( eLangType ); // in case we're already called
620 aLbLanguage.InsertLanguage( eLangType );
622 aLbLanguage.SelectLanguage( eLangType );
623 if(pAutoEntryAttr)
624 AddAutomaticLanguage_Impl(eLangType, pAutoEntryAttr->GetValue());
625 UpdateFormatListBox_Impl(FALSE,TRUE);
627 //! erAck 26.01.01
628 //! This spoils everything because it rematches currency formats based on
629 //! the selected aLbCurrency entry instead of the current format.
630 //! Besides that everything seems to be initialized by now, so why call it?
631 // SelFormatHdl_Impl( &aLbCategory );
633 if ( pValFmtAttr )
635 EditHdl_Impl( &aEdFormat ); // UpdateOptions_Impl() als Seiteneffekt
637 else // DONT_KNOW
639 // Kategoriewechsel und direkte Eingabe sind moeglich, sonst nix:
640 Obstructing();
643 if ( aCbSourceFormat.IsChecked() )
645 // everything disabled except SourceFormat checkbox
646 EnableBySourceFormat_Impl();
649 DeleteEntryList_Impl(aFmtEntryList);
652 /*************************************************************************
653 #* Methode: Obstructing Datum:02.10.97
654 #*------------------------------------------------------------------------
656 #* Klasse: SvxNumberFormatTabPage
658 #* Funktion: Sperren der Controls mit Ausnahme von Kategoriewechsel
659 #* und direkter Eingabe.
661 #* Input: ---
663 #* Output: ---
665 #************************************************************************/
666 void SvxNumberFormatTabPage::Obstructing()
668 aLbFormat .SetNoSelection();
669 aLbLanguage .SetNoSelection();
670 aFtLanguage .Disable();
671 aLbLanguage .Disable();
673 aIbAdd.Enable(FALSE );
674 aIbRemove.Enable(FALSE );
675 aIbInfo.Enable(FALSE );
677 aBtnNegRed .Disable();
678 aBtnThousand .Disable();
679 aFtLeadZeroes .Disable();
680 aFtDecimals .Disable();
681 aEdLeadZeroes .Disable();
682 aEdDecimals .Disable();
683 aFlOptions .Disable();
684 aEdDecimals .SetText( String() );
685 aEdLeadZeroes .SetText( String() );
686 aBtnNegRed .Check( FALSE );
687 aBtnThousand .Check( FALSE );
688 aWndPreview .NotifyChange( String() );
690 aLbCategory .SelectEntryPos( 0 );
691 aEdFormat .SetText( String() );
692 aFtComment .SetText( String() );
693 aEdComment .SetText(aLbCategory.GetEntry(1)); //String fuer Benutzerdefiniert
694 //holen
696 aEdFormat .GrabFocus();
700 /*************************************************************************
701 #* Enable/Disable dialog parts depending on the value of the SourceFormat
702 #* checkbox.
703 #************************************************************************/
704 void SvxNumberFormatTabPage::EnableBySourceFormat_Impl()
706 BOOL bEnable = !aCbSourceFormat.IsChecked();
707 if ( !bEnable )
708 aCbSourceFormat.GrabFocus();
709 aFtCategory .Enable( bEnable );
710 aLbCategory .Enable( bEnable );
711 aFtFormat .Enable( bEnable );
712 aLbCurrency .Enable( bEnable );
713 aLbFormat .Enable( bEnable );
714 aFtLanguage .Enable( bEnable );
715 aLbLanguage .Enable( bEnable );
716 aFtDecimals .Enable( bEnable );
717 aEdDecimals .Enable( bEnable );
718 aFtLeadZeroes .Enable( bEnable );
719 aEdLeadZeroes .Enable( bEnable );
720 aBtnNegRed .Enable( bEnable );
721 aBtnThousand .Enable( bEnable );
722 aFlOptions .Enable( bEnable );
723 aFtEdFormat .Enable( bEnable );
724 aEdFormat .Enable( bEnable );
725 aIbAdd .Enable( bEnable );
726 aIbRemove .Enable( bEnable );
727 aIbInfo .Enable( bEnable );
728 aFtComment .Enable( bEnable );
729 aEdComment .Enable( bEnable );
730 aLbFormat.Invalidate(); // #i43322#
734 /*************************************************************************
735 #* Methode: HideLanguage Datum:14.05.98
736 #*------------------------------------------------------------------------
738 #* Klasse: SvxNumberFormatTabPage
740 #* Funktion: Versteckt die Spracheinstellung:
742 #* Input: BOOL nFlag
744 #* Output: ---
746 #************************************************************************/
748 void SvxNumberFormatTabPage::HideLanguage(BOOL nFlag)
750 Size aSize=aLbCategory.GetSizePixel();
752 if(nFlag)
754 aSize.Height()=aLbFormat.GetSizePixel().Height();
756 else
758 aSize.Height()=nCatHeight;
761 aLbCategory.SetSizePixel(aSize);
763 aFtLanguage.Show(!nFlag);
764 aLbLanguage.Show(!nFlag);
767 /*************************************************************************
768 #* Methode: FillItemSet Datum:02.10.97
769 #*------------------------------------------------------------------------
771 #* Klasse: SvxNumberFormatTabPage
773 #* Funktion: Stellt die Attribute im ItemSet ein,
774 #* sowie in der DocShell den numItem, wenn
775 #* bNumItemFlag nicht gesetzt ist.
777 #* Input: SfxItemSet
779 #* Output: ---
781 #************************************************************************/
783 BOOL SvxNumberFormatTabPage::FillItemSet( SfxItemSet& rCoreAttrs )
785 BOOL bDataChanged = aFtLanguage.IsEnabled() || aCbSourceFormat.IsEnabled();
786 if ( bDataChanged )
788 const SfxItemSet& rMyItemSet = GetItemSet();
789 USHORT nWhich = GetWhich( SID_ATTR_NUMBERFORMAT_VALUE );
790 SfxItemState eItemState = rMyItemSet.GetItemState( nWhich, FALSE );
792 // OK chosen - Is format code input entered already taken over?
793 // If not, simulate Add. Upon syntax error ignore input and prevent Put.
794 String aFormat = aEdFormat.GetText();
795 sal_uInt32 nCurKey = pNumFmtShell->GetCurNumFmtKey();
797 if ( aIbAdd.IsEnabled() || pNumFmtShell->IsTmpCurrencyFormat(aFormat) )
798 { // #79599# It is not sufficient to just add the format code (or
799 // delete it in case of bOneAreaFlag and resulting category change).
800 // Upon switching tab pages we need all settings to be consistent
801 // in case this page will be redisplayed later.
802 bDataChanged = (ClickHdl_Impl( &aIbAdd ) != 0);
803 nCurKey = pNumFmtShell->GetCurNumFmtKey();
805 else if(nCurKey == NUMKEY_UNDEFINED)
806 { // something went wrong, e.g. in Writer #70281#
807 pNumFmtShell->FindEntry(aFormat, &nCurKey);
810 //---------------------------------------------------------------
811 // Chosen format:
812 // --------------
813 if ( bDataChanged )
815 bDataChanged = ( nInitFormat != nCurKey );
817 if (bDataChanged)
819 rCoreAttrs.Put( SfxUInt32Item( nWhich, nCurKey ) );
821 else if(SFX_ITEM_DEFAULT == eItemState)
823 rCoreAttrs.ClearItem( nWhich );
827 // --------------------------------------------------------------
828 // List of changed user defined formats:
829 // -------------------------------------
830 const sal_uInt32 nDelCount = pNumFmtShell->GetUpdateDataCount();
832 if ( nDelCount > 0 )
834 sal_uInt32* pDelArr = new sal_uInt32[nDelCount];
836 pNumFmtShell->GetUpdateData( pDelArr, nDelCount );
837 pNumItem->SetDelFormatArray( pDelArr, nDelCount );
839 if(bNumItemFlag==TRUE)
841 rCoreAttrs.Put( *pNumItem );
843 else
845 SfxObjectShell* pDocSh = SfxObjectShell::Current();
847 DBG_ASSERT( pDocSh, "DocShell not found!" );
850 if ( pDocSh )
851 pDocSh->PutItem( *pNumItem );
853 delete [] pDelArr;
856 //---------------------------------------------------------------
857 // Whether source format is to be taken or not:
858 // --------------------------------------------
859 if ( aCbSourceFormat.IsEnabled() )
861 USHORT _nWhich = GetWhich( SID_ATTR_NUMBERFORMAT_SOURCE );
862 SfxItemState _eItemState = rMyItemSet.GetItemState( _nWhich, FALSE );
863 const SfxBoolItem* pBoolItem = (const SfxBoolItem*)
864 GetItem( rMyItemSet, SID_ATTR_NUMBERFORMAT_SOURCE );
865 BOOL bOld = (pBoolItem ? pBoolItem->GetValue() : FALSE);
866 rCoreAttrs.Put( SfxBoolItem( _nWhich, aCbSourceFormat.IsChecked() ) );
867 if ( !bDataChanged )
868 bDataChanged = (bOld != (BOOL) aCbSourceFormat.IsChecked() ||
869 _eItemState != SFX_ITEM_SET);
872 // FillItemSet is only called on OK, here we can notify the
873 // NumberFormatShell that all new user defined formats are valid.
874 pNumFmtShell->ValidateNewEntries();
875 if(aLbLanguage.IsVisible() &&
876 LISTBOX_ENTRY_NOTFOUND != aLbLanguage.GetEntryPos(sAutomaticEntry))
877 rCoreAttrs.Put(SfxBoolItem(SID_ATTR_NUMBERFORMAT_ADD_AUTO,
878 aLbLanguage.GetSelectEntry() == sAutomaticEntry));
881 return bDataChanged;
885 int SvxNumberFormatTabPage::DeactivatePage( SfxItemSet* _pSet )
887 /* if ( (ULONG_MAX != nInitFormat) && _pSet )
889 const ULONG nCurKey = pNumFmtShell->GetCurNumFmtKey();
890 const USHORT nWhich = GetWhich( SID_ATTR_NUMBERFORMAT_VALUE );
891 SfxItemState eItemState = GetItemSet().GetItemState( nWhich, FALSE );
893 if ( (nInitFormat == nCurKey) && (SFX_ITEM_DEFAULT == eItemState) )
894 _pSet->ClearItem( nWhich );
895 else
896 _pSet->Put( SfxUInt32Item( nWhich, nCurKey ) );
899 if ( _pSet )
900 FillItemSet( *_pSet );
901 return LEAVE_PAGE;
904 void SvxNumberFormatTabPage::SetInfoItem( const SvxNumberInfoItem& rItem )
906 if(pNumItem==NULL)
908 pNumItem = (SvxNumberInfoItem*)rItem.Clone();
912 void SvxNumberFormatTabPage::FillFormatListBox_Impl( SvxDelStrgs& rEntries )
914 String* pEntry;
915 String aTmpString;
916 String aTmpCatString;
917 Font aFont=aLbCategory.GetFont();
918 USHORT i = 0;
919 short nTmpCatPos;
920 short aPrivCat;
922 aLbFormat.Clear();
923 aLbFormat.SetUpdateMode( FALSE );
925 USHORT nCount = rEntries.Count();
927 if(nCount<1) return;
929 if(bOneAreaFlag)
931 nTmpCatPos=nFixedCategory;
933 else
935 nTmpCatPos=aLbCategory.GetSelectEntryPos();
938 switch (nTmpCatPos)
940 case CAT_ALL:
941 case CAT_TEXT:
942 case CAT_NUMBER: i=1;
943 pEntry=rEntries[0];
944 if(pEntry!=NULL)
946 if (nTmpCatPos == CAT_TEXT)
947 aTmpString=*pEntry;
948 else
949 aTmpString = pNumFmtShell->GetStandardName();
950 aPrivCat=pNumFmtShell->GetCategory4Entry(0);
951 aLbFormat.InsertFontEntry( aTmpString, aFont );
953 break;
955 default: break;
958 if(pNumFmtShell!=NULL)
960 for ( ; i < nCount; ++i )
962 pEntry = rEntries[i];
963 aPrivCat=pNumFmtShell->GetCategory4Entry(i);
964 if(aPrivCat!=CAT_TEXT)
966 Color* pPreviewColor = NULL;
967 String aPreviewString( GetExpColorString( pPreviewColor, *pEntry, aPrivCat ) );
968 Font aEntryFont( aLbFormat.GetFont() );
969 aLbFormat.InsertFontEntry( aPreviewString, aEntryFont, pPreviewColor );
971 else
973 aLbFormat.InsertFontEntry(*pEntry,aFont);
977 aLbFormat.SetUpdateMode( TRUE );
978 DeleteEntryList_Impl(rEntries);
982 /*************************************************************************
983 #* Methode: DeleteEntryList_Impl Datum:02.10.97
984 #*------------------------------------------------------------------------
986 #* Klasse: SvxNumberFormatTabPage
988 #* Funktion: Loescht eine SvStrings- Liste
990 #* Input: String-liste
992 #* Output: ---
994 #************************************************************************/
996 void SvxNumberFormatTabPage::DeleteEntryList_Impl( SvxDelStrgs& rEntries )
998 USHORT nCount = rEntries.Count();
999 rEntries.DeleteAndDestroy(0,nCount);
1003 /*************************************************************************
1004 #* Methode: UpdateOptions_Impl Datum:02.10.97
1005 #*------------------------------------------------------------------------
1007 #* Klasse: SvxNumberFormatTabPage
1009 #* Funktion: Stellt je nach eingestelltem Format die Options-
1010 #* attribute neu ein.
1012 #* Input: Flag, ob sich die Kategorie geaendert hat.
1014 #* Output: ---
1016 #***?********************************************************************/
1018 void SvxNumberFormatTabPage::UpdateOptions_Impl( BOOL bCheckCatChange /*= FALSE*/ )
1020 SvxDelStrgs aEntryList;
1021 String theFormat = aEdFormat.GetText();
1022 USHORT nCurCategory = aLbCategory.GetSelectEntryPos();
1023 USHORT nCategory = nCurCategory;
1024 USHORT nDecimals = 0;
1025 USHORT nZeroes = 0;
1026 BOOL bNegRed = FALSE;
1027 BOOL bThousand = FALSE;
1028 short nTmpCatPos;
1029 USHORT nCurrencyPos =aLbCurrency.GetSelectEntryPos();
1031 if(bOneAreaFlag)
1033 nTmpCatPos=nFixedCategory;
1034 nCurCategory=nFixedCategory;
1036 else
1038 nTmpCatPos=nCurCategory;
1042 pNumFmtShell->GetOptions( theFormat,
1043 bThousand, bNegRed,
1044 nDecimals, nZeroes,
1045 nCategory );
1046 BOOL bDoIt=FALSE;
1047 if(nCategory==CAT_CURRENCY)
1049 USHORT nTstPos=pNumFmtShell->FindCurrencyFormat(theFormat);
1050 if(nCurrencyPos!=nTstPos && nTstPos!=(USHORT)-1)
1052 aLbCurrency.SelectEntryPos(nTstPos);
1053 pNumFmtShell->SetCurrencySymbol(nTstPos);
1054 bDoIt=TRUE;
1060 if ( nCategory != nCurCategory || bDoIt)
1062 if ( bCheckCatChange )
1064 if(bOneAreaFlag)
1065 SetCategory(0);
1066 else
1067 SetCategory(nCategory );
1069 UpdateFormatListBox_Impl( TRUE, FALSE );
1072 else if ( aLbFormat.GetEntryCount() > 0 )
1074 sal_uInt32 nCurEntryKey=NUMKEY_UNDEFINED;
1075 if(!pNumFmtShell->FindEntry( aEdFormat.GetText(),&nCurEntryKey))
1077 aLbFormat.SetNoSelection();
1080 if(bOneAreaFlag)
1082 nCategory=nFixedCategory;
1085 switch ( nCategory )
1087 case CAT_NUMBER:
1088 case CAT_PERCENT:
1089 case CAT_CURRENCY:
1090 aFlOptions.Enable();
1091 aFtDecimals.Enable();
1092 aEdDecimals.Enable();
1093 aFtLeadZeroes.Enable();
1094 aEdLeadZeroes.Enable();
1095 aBtnNegRed.Enable();
1096 aBtnThousand.Enable();
1098 aEdDecimals .SetValue( nDecimals );
1099 aEdLeadZeroes.SetValue( nZeroes );
1101 aEdDecimals .SetText( UniString::CreateFromInt32( nDecimals ) );
1102 aEdLeadZeroes.SetText( UniString::CreateFromInt32( nZeroes ) );
1103 aBtnNegRed .Check( bNegRed );
1104 aBtnThousand .Check( bThousand );
1105 break;
1107 case CAT_ALL:
1108 case CAT_USERDEFINED:
1109 case CAT_TEXT:
1110 case CAT_DATE:
1111 case CAT_TIME:
1112 case CAT_BOOLEAN:
1113 case CAT_SCIENTIFIC:
1114 case CAT_FRACTION:
1115 default:
1116 aFlOptions .Disable();
1117 aFtDecimals .Disable();
1118 aEdDecimals .Disable();
1119 aFtLeadZeroes .Disable();
1120 aEdLeadZeroes .Disable();
1121 aBtnNegRed .Disable();
1122 aBtnThousand .Disable();
1123 aEdDecimals .SetText( UniString::CreateFromInt32( 0 ) );
1124 aEdLeadZeroes .SetText( UniString::CreateFromInt32( 0 ) );
1125 aBtnNegRed .Check( FALSE );
1126 aBtnThousand .Check( FALSE );
1131 /*************************************************************************
1132 #* Methode: UpdateFormatListBox_Impl Datum:02.10.97
1133 #*------------------------------------------------------------------------
1135 #* Klasse: SvxNumberFormatTabPage
1137 #* Funktion: Aktualisiert die Format- Listbox und zusaetzlich
1138 #* wird abhaengig vom bUpdateEdit- Flag der String
1139 #* in der Editbox geaendert.
1141 #* Input: Flags fuer Kategorie und Editbox
1143 #* Output: ---
1145 #************************************************************************/
1147 void SvxNumberFormatTabPage::UpdateFormatListBox_Impl
1149 USHORT bCat, // Category oder Land/Sprache ListBox?
1150 BOOL bUpdateEdit // Format-Edit aktualisieren?
1153 SvxDelStrgs aEntryList;
1154 short nFmtLbSelPos = 0;
1155 short nTmpCatPos;
1157 if(bOneAreaFlag)
1159 nTmpCatPos=nFixedCategory;
1161 else
1163 nTmpCatPos=aLbCategory.GetSelectEntryPos();
1167 if ( bCat )
1169 Point aPos=aLbFormat.GetPosPixel();
1170 Size aSize=aLbFormat.GetSizePixel();
1172 if(nTmpCatPos!=CAT_CURRENCY)
1174 aPos.Y()=nStdFormatY;
1175 aSize.Height()=nStdFormatHeight;
1176 aLbFormat.SetPosSizePixel(aPos,aSize);
1177 #if ENABLE_LAYOUT
1178 aLbCurrency.Disable();
1179 #else /* !ENABLE_LAYOUT */
1180 aLbCurrency.Hide();
1181 #endif /* !ENABLE_LAYOUT */
1183 else
1185 aPos.Y()=nCurFormatY;
1186 aSize.Height()=nCurFormatHeight;
1187 aLbFormat.SetPosSizePixel(aPos,aSize);
1188 #if ENABLE_LAYOUT
1189 aLbCurrency.Enable();
1190 #else /* !ENABLE_LAYOUT */
1191 aLbCurrency.Show();
1192 #endif /* !ENABLE_LAYOUT */
1195 pNumFmtShell->CategoryChanged( nTmpCatPos,nFmtLbSelPos, aEntryList );
1197 else
1198 pNumFmtShell->LanguageChanged( aLbLanguage.GetSelectLanguage(),
1199 nFmtLbSelPos,aEntryList );
1201 REMOVE_DONTKNOW() // ggF. UI-Enable
1204 if ( (aEntryList.Count() > 0) && (nFmtLbSelPos != SELPOS_NONE) )
1206 if(bUpdateEdit)
1208 String aFormat=*aEntryList[nFmtLbSelPos];
1209 aEdFormat.SetText(aFormat);
1210 aFtComment.SetText(pNumFmtShell->GetComment4Entry(nFmtLbSelPos));
1212 //@23.09.97 aEdFormat.SetText( aLbFormat.GetSelectEntry() );
1215 if(!bOneAreaFlag || !bCat)
1217 FillFormatListBox_Impl( aEntryList );
1218 aLbFormat.SelectEntryPos( nFmtLbSelPos );
1220 aFtComment.SetText(pNumFmtShell->GetComment4Entry(nFmtLbSelPos));
1221 if(pNumFmtShell->GetUserDefined4Entry(nFmtLbSelPos))
1223 if(pNumFmtShell->GetComment4Entry(nFmtLbSelPos).Len()==0)
1225 aFtComment.SetText(aLbCategory.GetEntry(1));
1228 ChangePreviewText( (USHORT)nFmtLbSelPos );
1232 else
1234 FillFormatListBox_Impl( aEntryList );
1235 if(nFmtLbSelPos != SELPOS_NONE)
1237 aLbFormat.SelectEntryPos( (USHORT)nFmtLbSelPos );
1239 aFtComment.SetText(pNumFmtShell->GetComment4Entry(nFmtLbSelPos));
1240 if(pNumFmtShell->GetUserDefined4Entry(nFmtLbSelPos))
1242 if(pNumFmtShell->GetComment4Entry(nFmtLbSelPos).Len()==0)
1244 aFtComment.SetText(aLbCategory.GetEntry(1));
1248 else
1250 aLbFormat.SetNoSelection();
1253 if ( bUpdateEdit )
1255 aEdFormat.SetText( String() );
1256 aWndPreview.NotifyChange( String() );
1262 /*************************************************************************
1263 #* Handle: DoubleClickHdl_Impl Datum:02.10.97
1264 #*------------------------------------------------------------------------
1266 #* Klasse: SvxNumberFormatTabPage
1268 #* Funktion: Bei einem Doppelklick in die Format- Listbox
1269 #* wird der Wert uebernommen und der OK-Button
1270 #* ausgeloest
1272 #* Input: Pointer auf Listbox
1274 #* Output: ---
1276 #************************************************************************/
1278 IMPL_LINK( SvxNumberFormatTabPage, DoubleClickHdl_Impl, SvxFontListBox*, pLb )
1280 if ( pLb == &aLbFormat )
1282 SelFormatHdl_Impl( pLb );
1284 if ( fnOkHdl.IsSet() )
1285 { // Uebergangsloesung, sollte von SfxTabPage angeboten werden
1286 fnOkHdl.Call( NULL );
1288 else
1290 SfxSingleTabDialog* pParent = dynamic_cast< SfxSingleTabDialog* >( GetParent() );
1291 OKButton* pOKButton = pParent ? pParent->GetOKButton() : NULL;
1292 if ( pOKButton )
1293 pOKButton->Click();
1296 return 0;
1300 /*************************************************************************
1301 #* Methode: SelFormatHdl_Impl Datum:02.10.97
1302 #*------------------------------------------------------------------------
1304 #* Klasse: SvxNumberFormatTabPage
1306 #* Funktion: Wird aufgerufen, wenn sich die Sprache, die Kategorie
1307 #* oder das Format aendert. Dem entsprechend werden die
1308 #* Einstellungen geaendert.
1310 #* Input: Pointer auf Listbox
1312 #* Output: ---
1314 #************************************************************************/
1316 IMPL_LINK( SvxNumberFormatTabPage, SelFormatHdl_Impl, void *, pLb )
1318 if ( (CheckBox*)pLb == &aCbSourceFormat )
1320 EnableBySourceFormat_Impl(); // enable/disable everything else
1321 if ( aCbSourceFormat.IsChecked() )
1322 return 0; // just disabled everything else
1324 // Reinit options enable/disable for current selection.
1326 #if ENABLE_LAYOUT
1327 if (aLbFormat.GetSelectEntryPos () == LISTBOX_ENTRY_NOTFOUND)
1328 #else /* !ENABLE_LAYOUT */
1329 // Current category may be UserDefined with no format entries defined.
1330 // And yes, aLbFormat is a SvxFontListBox with ULONG list positions,
1331 // implementation returns a LIST_APPEND if empty, comparison with
1332 // USHORT LISTBOX_ENTRY_NOTFOUND wouldn't match.
1333 if ( aLbFormat.GetSelectEntryPos() == LIST_APPEND )
1334 #endif /* !ENABLE_LAYOUT */
1335 pLb = &aLbCategory; // continue with the current category selected
1336 else
1337 pLb = &aLbFormat; // continue with the current format selected
1340 short nTmpCatPos;
1342 if(bOneAreaFlag)
1344 nTmpCatPos=nFixedCategory;
1346 else
1348 nTmpCatPos=aLbCategory.GetSelectEntryPos();
1351 USHORT nCurrencyPos=LISTBOX_ENTRY_NOTFOUND ;
1353 if(nTmpCatPos==CAT_CURRENCY && (ListBox *)pLb == &aLbCurrency )
1355 nCurrencyPos=aLbCurrency.GetSelectEntryPos();
1356 pNumFmtShell->SetCurrencySymbol(nCurrencyPos);
1359 //--------------------------------------------------------------------
1360 // Format-ListBox ----------------------------------------------------
1361 if ( (SvxFontListBox *)pLb == &aLbFormat )
1363 USHORT nSelPos = (USHORT) aLbFormat.GetSelectEntryPos();
1364 String aFormat = aLbFormat.GetSelectEntry();
1365 String aComment;
1366 SvxDelStrgs aEntryList;
1368 short nFmtLbSelPos = nSelPos;
1370 aFormat=pNumFmtShell->GetFormat4Entry(nSelPos);
1371 aComment=pNumFmtShell->GetComment4Entry(nSelPos);
1372 if(pNumFmtShell->GetUserDefined4Entry(nFmtLbSelPos))
1374 if(pNumFmtShell->GetComment4Entry(nFmtLbSelPos).Len()==0)
1376 aComment=aLbCategory.GetEntry(1);
1380 if ( aFormat.Len() > 0 )
1382 if(!aEdFormat.HasFocus()) aEdFormat.SetText( aFormat );
1383 aFtComment.SetText(aComment);
1384 ChangePreviewText( nSelPos );
1387 REMOVE_DONTKNOW() // ggF. UI-Enable
1389 if ( pNumFmtShell->FindEntry( aFormat) )
1391 aIbAdd.Enable(FALSE );
1392 BOOL bIsUserDef=pNumFmtShell->IsUserDefined( aFormat );
1393 aIbRemove.Enable(bIsUserDef);
1394 aIbInfo.Enable(bIsUserDef);
1397 else
1399 aIbAdd.Enable(TRUE );
1400 aIbInfo.Enable(TRUE );
1401 aIbRemove.Enable(FALSE );
1402 aFtComment.SetText(aEdComment.GetText());
1405 UpdateOptions_Impl( FALSE );
1407 //-------
1408 return 0;
1409 //-------
1412 //--------------------------------------------------------------------
1413 // Kategorie-ListBox -------------------------------------------------
1414 if ( pLb == &aLbCategory || pLb == &aLbCurrency)
1416 UpdateFormatListBox_Impl( TRUE, TRUE );
1417 EditHdl_Impl( NULL );
1418 UpdateOptions_Impl( FALSE );
1420 //-------
1421 return 0;
1422 //-------
1425 //--------------------------------------------------------------------
1426 // Sprache/Land-ListBox ----------------------------------------------
1427 if ( pLb == &aLbLanguage )
1429 UpdateFormatListBox_Impl( FALSE, TRUE );
1430 EditHdl_Impl( &aEdFormat );
1432 //-------
1433 return 0;
1434 //-------
1436 return 0;
1440 /*************************************************************************
1441 #* Methode: ClickHdl_Impl, ImageButton* pIB Datum:02.10.97
1442 #*------------------------------------------------------------------------
1444 #* Klasse: SvxNumberFormatTabPage
1446 #* Funktion: Wenn, der Hinzufuegen- oder Entfernen- Button
1447 #* wird diese Funktion aufgerufen und die Zahlenformat-
1448 #* Liste den entsprechend geaendert.
1450 #* Input: Toolbox- Button
1452 #* Output: ---
1454 #************************************************************************/
1456 IMPL_LINK( SvxNumberFormatTabPage, ClickHdl_Impl, ImageButton*, pIB)
1458 BOOL bAdded = FALSE;
1459 BOOL bDeleted = FALSE;
1460 ULONG nReturn = 0;
1461 const ULONG nReturnChanged = 0x1; // THE boolean return value
1462 const ULONG nReturnAdded = 0x2; // temp: format added
1463 const ULONG nReturnOneArea = 0x4; // temp: one area but category changed => ignored
1465 if(pIB==&aIbAdd)
1466 { // Also called from FillItemSet() if a temporary currency format has
1467 // to be added, not only if the Add button is enabled.
1468 String aFormat = aEdFormat.GetText();
1469 SvxDelStrgs aEntryList;
1470 SvxDelStrgs a2EntryList;
1471 USHORT nCatLbSelPos = 0;
1472 short nFmtLbSelPos = SELPOS_NONE;
1473 xub_StrLen nErrPos=0;
1475 pNumFmtShell->SetCurCurrencyEntry(NULL);
1476 bAdded = pNumFmtShell->AddFormat( aFormat, nErrPos,
1477 nCatLbSelPos, nFmtLbSelPos,
1478 aEntryList);
1479 if ( bAdded )
1480 nReturn |= nReturnChanged | nReturnAdded;
1482 if(pLastActivWindow== (Window *) &aEdComment)
1484 aEdFormat.GrabFocus();
1485 aEdComment.Hide();
1486 aFtComment.Show();
1487 aFtComment.SetText(aEdComment.GetText());
1490 if ( !nErrPos ) // Syntax ok?
1492 if(nCatLbSelPos==CAT_CURRENCY)
1494 aLbCurrency.SelectEntryPos((USHORT)pNumFmtShell->GetCurrencySymbol());
1497 if(bOneAreaFlag && (nFixedCategory!=nCatLbSelPos))
1499 if(bAdded) DeleteEntryList_Impl(aEntryList);
1500 bDeleted = pNumFmtShell->RemoveFormat( aFormat,
1501 nCatLbSelPos,
1502 nFmtLbSelPos,
1503 a2EntryList);
1504 if(bDeleted) DeleteEntryList_Impl(a2EntryList);
1505 aEdFormat.GrabFocus();
1506 aEdFormat.SetSelection( Selection( (short)nErrPos, SELECTION_MAX ) );
1507 nReturn |= nReturnOneArea;
1509 else
1511 if ( bAdded && (nFmtLbSelPos != SELPOS_NONE) )
1513 // Alles klar
1514 if(bOneAreaFlag) //@@ ???
1515 SetCategory(0);
1516 else
1517 SetCategory(nCatLbSelPos );
1519 FillFormatListBox_Impl( aEntryList );
1520 if(aEdComment.GetText()!=aLbCategory.GetEntry(1))
1522 pNumFmtShell->SetComment4Entry(nFmtLbSelPos,
1523 aEdComment.GetText());
1525 else
1527 pNumFmtShell->SetComment4Entry(nFmtLbSelPos,
1528 String());
1530 aLbFormat.SelectEntryPos( (USHORT)nFmtLbSelPos );
1531 aEdFormat.SetText( aFormat );
1533 //aEdComment.SetText(String()); //@@ ???
1534 aEdComment.SetText(aLbCategory.GetEntry(1)); //String fuer Benutzerdefiniert
1535 //holen
1536 ChangePreviewText( (USHORT)nFmtLbSelPos );
1540 else // Syntaxfehler
1542 aEdFormat.GrabFocus();
1543 aEdFormat.SetSelection( Selection( (short)nErrPos, SELECTION_MAX ) );
1545 EditHdl_Impl( &aEdFormat );
1546 nReturn = ((nReturn & nReturnOneArea) ? 0 : (nReturn & nReturnChanged));
1548 else if(pIB==&aIbRemove)
1550 String aFormat = aEdFormat.GetText();
1551 SvxDelStrgs aEntryList;
1552 USHORT nCatLbSelPos = 0;
1553 short nFmtLbSelPos = SELPOS_NONE;
1555 bDeleted = pNumFmtShell->RemoveFormat( aFormat,
1556 nCatLbSelPos,
1557 nFmtLbSelPos,
1558 aEntryList );
1560 aEdComment.SetText(aLbCategory.GetEntry(1));
1561 if ( bDeleted )
1563 if(nFmtLbSelPos>=0 && nFmtLbSelPos<aEntryList.Count())
1565 aFormat = *aEntryList[nFmtLbSelPos];
1568 FillFormatListBox_Impl( aEntryList );
1570 if ( nFmtLbSelPos != SELPOS_NONE )
1572 if(bOneAreaFlag) //@@ ???
1573 SetCategory(0);
1574 else
1575 SetCategory(nCatLbSelPos );
1577 aLbFormat.SelectEntryPos( (USHORT)nFmtLbSelPos );
1578 aEdFormat.SetText( aFormat );
1579 ChangePreviewText( (USHORT)nFmtLbSelPos );
1581 else
1583 // auf "Alle/Standard" setzen
1584 SetCategory(0 );
1585 SelFormatHdl_Impl( &aLbCategory );
1588 EditHdl_Impl( &aEdFormat );
1590 else if(pIB==&aIbInfo)
1592 if(!(pLastActivWindow== (Window *) &aEdComment))
1594 aEdComment.SetText(aFtComment.GetText());
1595 aEdComment.Show();
1596 aFtComment.Hide();
1597 aEdComment.GrabFocus();
1599 else
1601 aEdFormat.GrabFocus();
1602 aEdComment.Hide();
1603 aFtComment.Show();
1607 return nReturn;
1611 /*************************************************************************
1612 #* Methode: EditHdl_Impl Datum:02.10.97
1613 #*------------------------------------------------------------------------
1615 #* Klasse: SvxNumberFormatTabPage
1617 #* Funktion: Wenn der Eintrag im Eingabefeld geaendert wird,
1618 #* so wird die Vorschau aktualisiert und
1620 #* Input: Pointer auf Editbox
1622 #* Output: ---
1624 #************************************************************************/
1626 IMPL_LINK( SvxNumberFormatTabPage, EditHdl_Impl, Edit*, pEdFormat )
1628 sal_uInt32 nCurKey = NUMKEY_UNDEFINED;
1630 if ( aEdFormat.GetText().Len() == 0 )
1632 aIbAdd.Enable(FALSE );
1633 aIbRemove.Enable(FALSE );
1634 aIbInfo.Enable(FALSE );
1635 aFtComment.SetText(String());
1637 else
1639 String aFormat = aEdFormat.GetText();
1640 //aFtComment.SetText(String());
1641 MakePreviewText( aFormat );
1643 if ( pNumFmtShell->FindEntry( aFormat, &nCurKey ) )
1645 aIbAdd.Enable(FALSE );
1646 BOOL bUserDef=pNumFmtShell->IsUserDefined( aFormat );
1648 aIbRemove.Enable(bUserDef);
1649 aIbInfo.Enable(bUserDef);
1651 if(bUserDef)
1653 USHORT nTmpCurPos=pNumFmtShell->FindCurrencyFormat(aFormat );
1655 if(nTmpCurPos!=(USHORT)-1)
1656 aLbCurrency.SelectEntryPos(nTmpCurPos);
1658 short nPosi=pNumFmtShell->GetListPos4Entry(aFormat);
1659 if(nPosi>=0)
1660 aLbFormat.SelectEntryPos( (USHORT)nPosi);
1663 else
1666 aIbAdd.Enable(TRUE );
1667 aIbInfo.Enable(TRUE);
1668 aIbRemove.Enable(FALSE );
1670 aFtComment.SetText(aEdComment.GetText());
1675 if ( pEdFormat )
1677 pNumFmtShell->SetCurNumFmtKey( nCurKey );
1678 UpdateOptions_Impl( TRUE );
1681 return 0;
1685 /*************************************************************************
1686 #* Methode: NotifyChange Datum:02.10.97
1687 #*------------------------------------------------------------------------
1689 #* Klasse: SvxNumberFormatTabPage
1691 #* Funktion: Fuehrt Aenderungen in den Zahlen- Attributen durch.
1693 #* Input: Options- Controls
1695 #* Output: ---
1697 #************************************************************************/
1699 IMPL_LINK( SvxNumberFormatTabPage, OptHdl_Impl, void *, pOptCtrl )
1701 if ( ((NumericField*)pOptCtrl == &aEdLeadZeroes)
1702 || ((NumericField*)pOptCtrl == &aEdDecimals)
1703 || ((CheckBox*) pOptCtrl == &aBtnNegRed)
1704 || ((CheckBox*) pOptCtrl == &aBtnThousand) )
1706 String aFormat;
1707 BOOL bThousand = aBtnThousand.IsEnabled()
1708 && aBtnThousand.IsChecked();
1709 BOOL bNegRed = aBtnNegRed.IsEnabled()
1710 && aBtnNegRed.IsChecked();
1711 USHORT nPrecision = (aEdDecimals.IsEnabled())
1712 ? (USHORT)aEdDecimals.GetValue()
1713 : (USHORT)0;
1714 USHORT nLeadZeroes = (aEdLeadZeroes.IsEnabled())
1715 ? (USHORT)aEdLeadZeroes.GetValue()
1716 : (USHORT)0;
1718 pNumFmtShell->MakeFormat( aFormat,
1719 bThousand, bNegRed,
1720 nPrecision, nLeadZeroes,
1721 (USHORT)aLbFormat.GetSelectEntryPos() );
1723 aEdFormat.SetText( aFormat );
1724 //aFtComment.SetText(String());
1725 MakePreviewText( aFormat );
1727 if ( pNumFmtShell->FindEntry( aFormat ) )
1729 aIbAdd.Enable(FALSE );
1730 BOOL bUserDef=pNumFmtShell->IsUserDefined( aFormat );
1731 aIbRemove.Enable(bUserDef);
1732 aIbInfo.Enable(bUserDef);
1733 EditHdl_Impl( &aEdFormat);
1736 else
1738 EditHdl_Impl( NULL );
1739 aLbFormat.SetNoSelection();
1742 return 0;
1745 IMPL_LINK( SvxNumberFormatTabPage, TimeHdl_Impl, Timer*, EMPTYARG)
1747 pLastActivWindow=NULL;
1748 return 0;
1752 /*************************************************************************
1753 #* Methode: LostFocusHdl_Impl Datum:30.10.97
1754 #*------------------------------------------------------------------------
1756 #* Klasse: SvxNumberFormatTabPage
1758 #* Funktion: Fuehrt Aenderungen in den Zahlen- Attributen durch.
1760 #* Input: Options- Controls
1762 #* Output: ---
1764 #************************************************************************/
1766 IMPL_LINK( SvxNumberFormatTabPage, LostFocusHdl_Impl, Edit *, pEd)
1768 if (pEd==&aEdComment)
1770 aResetWinTimer.Start();
1771 aFtComment.SetText(aEdComment.GetText());
1772 aEdComment.Hide();
1773 aFtComment.Show();
1774 if(!aIbAdd.IsEnabled())
1776 USHORT nSelPos = (USHORT) aLbFormat.GetSelectEntryPos();
1777 pNumFmtShell->SetComment4Entry(nSelPos,
1778 aEdComment.GetText());
1779 aEdComment.SetText(aLbCategory.GetEntry(1)); //String fuer Benutzerdefiniert
1780 //holen
1783 return 0;
1786 /*************************************************************************
1787 #* Methode: NotifyChange Datum:02.10.97
1788 #*------------------------------------------------------------------------
1790 #* Klasse: SvxNumberFormatTabPage
1792 #* Funktion: Fuehrt Aenderungen in den Zahlen- Attributen durch.
1794 #* Input: Options- Controls
1796 #* Output: ---
1798 #************************************************************************/
1800 String SvxNumberFormatTabPage::GetExpColorString(
1801 Color*& rpPreviewColor, const String& rFormatStr, short nTmpCatPos)
1803 double nVal = 0;
1804 switch (nTmpCatPos)
1806 case CAT_CURRENCY: nVal=SVX_NUMVAL_CURRENCY; break;
1808 case CAT_SCIENTIFIC:
1809 case CAT_FRACTION:
1810 case CAT_NUMBER: nVal=SVX_NUMVAL_STANDARD; break;
1812 case CAT_PERCENT: nVal=SVX_NUMVAL_PERCENT; break;
1814 case CAT_ALL: nVal=SVX_NUMVAL_STANDARD; break;
1816 case CAT_TIME: nVal=SVX_NUMVAL_TIME; break;
1817 case CAT_DATE: nVal=SVX_NUMVAL_DATE; break;
1819 case CAT_BOOLEAN: nVal=SVX_NUMVAL_BOOLEAN; break;
1821 case CAT_USERDEFINED:
1822 case CAT_TEXT:
1823 default: nVal=0;break;
1826 String aPreviewString;
1827 pNumFmtShell->MakePrevStringFromVal( rFormatStr, aPreviewString, rpPreviewColor, nVal );
1828 return aPreviewString;
1831 void SvxNumberFormatTabPage::MakePreviewText( const String& rFormat )
1833 String aPreviewString;
1834 Color* pPreviewColor = NULL;
1835 pNumFmtShell->MakePreviewString( rFormat, aPreviewString, pPreviewColor );
1836 aWndPreview.NotifyChange( aPreviewString, pPreviewColor );
1839 void SvxNumberFormatTabPage::ChangePreviewText( USHORT nPos )
1841 String aPreviewString;
1842 Color* pPreviewColor = NULL;
1843 pNumFmtShell->FormatChanged( nPos, aPreviewString, pPreviewColor );
1844 aWndPreview.NotifyChange( aPreviewString, pPreviewColor );
1847 long SvxNumberFormatTabPage::PreNotify( NotifyEvent& rNEvt )
1849 if(rNEvt.GetType()==EVENT_LOSEFOCUS)
1851 if ( rNEvt.GetWindow() == dynamic_cast< Window* >( &aEdComment ) && !aEdComment.IsVisible() )
1853 pLastActivWindow = NULL;
1855 else
1857 pLastActivWindow = rNEvt.GetWindow();
1861 return SfxTabPage::PreNotify( rNEvt );
1863 /*************************************************************************
1864 #* Methode: SetOkHdl Datum:01.11.97
1865 #*------------------------------------------------------------------------
1867 #* Klasse: SvxNumberFormatTabPage
1869 #* Funktion: Setzt den OkHandler neu.
1871 #* Input: Neuer OkHandler
1873 #* Output: ---
1875 #************************************************************************/
1877 void SvxNumberFormatTabPage::SetOkHdl( const Link& rOkHandler )
1879 fnOkHdl = rOkHandler;
1882 void SvxNumberFormatTabPage::FillCurrencyBox()
1884 SvStringsDtor aList;
1885 NfShCurrencyEntries rEntries;
1886 XubString* pEntry = NULL;
1887 USHORT nPos=0;
1888 USHORT nSelPos=0;
1890 pNumFmtShell->GetCurrencySymbols(aList,aStrEurope,&nSelPos);
1892 for(USHORT i=1;i<aList.Count();i++)
1894 pEntry=aList[i];
1895 nPos=aLbCurrency.InsertEntry( *pEntry);
1897 aLbCurrency.SelectEntryPos(nSelPos);
1900 void SvxNumberFormatTabPage::SetCategory(USHORT nPos)
1902 USHORT nCurCategory = aLbCategory.GetSelectEntryPos();
1903 Point aPos=aLbFormat.GetPosPixel();
1904 Size aSize=aLbFormat.GetSizePixel();
1905 USHORT nTmpCatPos;
1907 if(bOneAreaFlag)
1909 nTmpCatPos=nFixedCategory;
1911 else
1913 nTmpCatPos=nPos;
1916 if(aLbCategory.GetEntryCount()==1 || nCurCategory!=nPos)
1918 if(nTmpCatPos!=CAT_CURRENCY)
1920 aPos.Y()=nStdFormatY;
1921 aSize.Height()=nStdFormatHeight;
1922 aLbFormat.SetPosSizePixel(aPos,aSize);
1923 aLbCurrency.Hide();
1925 else
1927 aPos.Y()=nCurFormatY;
1928 aSize.Height()=nCurFormatHeight;
1929 aLbFormat.SetPosSizePixel(aPos,aSize);
1930 aLbCurrency.Show();
1933 aLbCategory.SelectEntryPos(nPos);
1935 /* -----------------12.11.2002 14:35-----------------
1936 * to support Writer text field language handling an
1937 * additional entry needs to be inserted into the ListBox
1938 * which marks a certain language as automatically detected
1939 * Additionally the "Default" language is removed
1940 * --------------------------------------------------*/
1941 void SvxNumberFormatTabPage::AddAutomaticLanguage_Impl(LanguageType eAutoLang, BOOL bSelect)
1943 aLbLanguage.RemoveLanguage(LANGUAGE_SYSTEM);
1944 USHORT nPos = aLbLanguage.InsertEntry(sAutomaticEntry);
1945 aLbLanguage.SetEntryData(nPos, (void*)(ULONG)eAutoLang);
1946 if(bSelect)
1947 aLbLanguage.SelectEntryPos(nPos);
1950 void SvxNumberFormatTabPage::PageCreated (SfxAllItemSet aSet) //add CHINA001
1952 SFX_ITEMSET_ARG (&aSet,pNumberInfoItem,SvxNumberInfoItem,SID_ATTR_NUMBERFORMAT_INFO,sal_False);
1953 SFX_ITEMSET_ARG (&aSet,pLinkItem,SfxLinkItem,SID_LINK_TYPE,sal_False);
1954 if (pNumberInfoItem)
1955 SetNumberFormatList(*pNumberInfoItem);
1956 if (pLinkItem)
1957 SetOkHdl(pLinkItem->GetValue());