merge the formfield patch from ooo-build
[ooovba.git] / svx / source / cui / numfmt.cxx
blob614cd5259fdf232fba005746f691c802b43922e9
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 sAutomaticEntry ( THIS_SVX_RES( STR_AUTO_ENTRY)),
296 pLastActivWindow( NULL )
298 #if ENABLE_LAYOUT
299 aLbFormat.Clear ();
300 #endif /* ENABLE_LAYOUT */
302 Init_Impl();
303 SetExchangeSupport(); // diese Page braucht ExchangeSupport
304 FreeResource();
305 nFixedCategory=-1;
308 SvxNumberFormatTabPage::~SvxNumberFormatTabPage()
310 delete pNumFmtShell;
311 delete pNumItem;
314 void SvxNumberFormatTabPage::Init_Impl()
316 ImageList aIconList( SVX_RES_PLAIN ( IL_ICON ) );
317 ImageList aIconListHC( SVX_RES_PLAIN ( IL_ICON_HC ) );
319 bNumItemFlag=TRUE;
320 bOneAreaFlag=FALSE;
322 nCatHeight=aLbCategory.GetSizePixel().Height();
324 nCurFormatY =aLbFormat.GetPosPixel().Y();
325 nCurFormatHeight=aLbFormat.GetSizePixel().Height();
326 nStdFormatY =aLbCurrency.GetPosPixel().Y();
327 nStdFormatHeight=nCurFormatY-nStdFormatY+nCurFormatHeight;
329 aIbAdd. SetModeImage( aIconList.GetImage( IID_ADD ) );
330 aIbAdd. SetModeImage( aIconListHC.GetImage( IID_ADD ), BMP_COLOR_HIGHCONTRAST );
332 aIbRemove. SetModeImage( aIconList.GetImage( IID_REMOVE ) );
333 aIbRemove. SetModeImage( aIconListHC.GetImage( IID_REMOVE ), BMP_COLOR_HIGHCONTRAST );
335 aIbInfo. SetModeImage( aIconList.GetImage( IID_INFO ) );
336 aIbInfo. SetModeImage( aIconListHC.GetImage( IID_INFO ), BMP_COLOR_HIGHCONTRAST );
338 aIbAdd.Enable(FALSE );
339 aIbRemove.Enable(FALSE );
340 aIbInfo.Enable(FALSE );
342 aEdComment.SetText(aLbCategory.GetEntry(1)); //String fuer Benutzerdefiniert
343 //holen
344 aEdComment.Hide();
346 aCbSourceFormat.Check( FALSE );
347 aCbSourceFormat.Disable();
348 aCbSourceFormat.Hide();
350 // Handler verbinden
351 Link aLink = LINK( this, SvxNumberFormatTabPage, SelFormatHdl_Impl );
353 aLbCategory .SetSelectHdl( aLink );
354 aLbFormat .SetSelectHdl( aLink );
355 aLbLanguage .SetSelectHdl( aLink );
356 aLbCurrency .SetSelectHdl( aLink );
357 aCbSourceFormat .SetClickHdl( aLink );
359 aLink = LINK( this, SvxNumberFormatTabPage, OptHdl_Impl );
361 aEdDecimals .SetModifyHdl( aLink );
362 aEdLeadZeroes .SetModifyHdl( aLink );
363 aBtnNegRed .SetClickHdl( aLink );
364 aBtnThousand .SetClickHdl( aLink );
365 aLbFormat .SetDoubleClickHdl( HDL( DoubleClickHdl_Impl ) );
366 aEdFormat .SetModifyHdl( HDL( EditHdl_Impl ) );
367 aIbAdd.SetClickHdl( HDL( ClickHdl_Impl ) );
368 aIbRemove.SetClickHdl( HDL( ClickHdl_Impl ) );
369 aIbInfo.SetClickHdl( HDL( ClickHdl_Impl ) );
371 aLink = LINK( this, SvxNumberFormatTabPage, LostFocusHdl_Impl);
373 aEdComment .SetLoseFocusHdl( aLink);
374 aResetWinTimer .SetTimeoutHdl(LINK( this, SvxNumberFormatTabPage, TimeHdl_Impl));
375 aResetWinTimer .SetTimeout( 10);
377 // Sprachen-ListBox initialisieren
379 aLbLanguage.InsertLanguage( LANGUAGE_SYSTEM );
380 // Don't list ambiguous locales where we won't be able to convert the
381 // LanguageType back to an identical Language_Country name and therefore
382 // couldn't load the i18n LocaleData. Show DebugMsg in non-PRODUCT version.
383 ::com::sun::star::uno::Sequence< sal_uInt16 > xLang =
384 LocaleDataWrapper::getInstalledLanguageTypes();
385 sal_Int32 nCount = xLang.getLength();
386 for ( sal_Int32 i=0; i<nCount; i++ )
388 aLbLanguage.InsertLanguage( xLang[i] );
392 /*************************************************************************
393 #* Methode: GetRanges Datum:02.10.97
394 #*------------------------------------------------------------------------
396 #* Klasse: SvxNumberFormatTabPage
398 #* Funktion: Liefert Bereichsangaben zurueck.
400 #* Input: ---
402 #* Output: Bereich
404 #************************************************************************/
406 USHORT* SvxNumberFormatTabPage::GetRanges()
408 return pRanges;
412 /*************************************************************************
413 #* Methode: Create Datum:02.10.97
414 #*------------------------------------------------------------------------
416 #* Klasse: SvxNumberFormatTabPage
418 #* Funktion: Erzeugt eine neue Zahlenformat- Seite.
420 #* Input: Fenster, SfxItemSet
422 #* Output: neue TabPage
424 #************************************************************************/
426 SfxTabPage* SvxNumberFormatTabPage::Create( Window* pParent,
427 const SfxItemSet& rAttrSet )
429 return ( new SvxNumberFormatTabPage( pParent, rAttrSet ) );
433 /*************************************************************************
434 #* Methode: Reset Datum:02.10.97
435 #*------------------------------------------------------------------------
437 #* Klasse: SvxNumberFormatTabPage
439 #* Funktion: Die Attribute des Dialogs werden mit Hilfe
440 #* des Itemsets neu eingestellt.
442 #* Input: SfxItemSet
444 #* Output: ---
446 #************************************************************************/
448 void SvxNumberFormatTabPage::Reset( const SfxItemSet& rSet )
450 const SfxUInt32Item* pValFmtAttr = NULL;
451 const SfxPoolItem* pItem = NULL;
452 const SfxBoolItem* pAutoEntryAttr = NULL;
454 USHORT nCatLbSelPos = 0;
455 USHORT nFmtLbSelPos = 0;
456 LanguageType eLangType = LANGUAGE_DONTKNOW;
457 SvxDelStrgs aFmtEntryList;
458 SvxNumberValueType eValType = SVX_VALUE_TYPE_UNDEFINED;
459 double nValDouble = 0;
460 String aValString;
461 SfxItemState eState = SFX_ITEM_DONTCARE;
464 eState = rSet.GetItemState( GetWhich( SID_ATTR_NUMBERFORMAT_NOLANGUAGE ),TRUE,&pItem);
466 if(eState==SFX_ITEM_SET)
468 const SfxBoolItem* pBoolLangItem = (const SfxBoolItem*)
469 GetItem( rSet, SID_ATTR_NUMBERFORMAT_NOLANGUAGE);
471 if(pBoolLangItem!=NULL && pBoolLangItem->GetValue())
473 HideLanguage();
475 else
477 HideLanguage(FALSE);
482 eState = rSet.GetItemState( GetWhich( SID_ATTR_NUMBERFORMAT_INFO ),TRUE,&pItem);
484 if(eState==SFX_ITEM_SET)
486 if(pNumItem==NULL)
488 bNumItemFlag=TRUE;
489 pNumItem= (SvxNumberInfoItem *) pItem->Clone();
491 else
493 bNumItemFlag=FALSE;
496 else
498 bNumItemFlag=FALSE;
502 eState = rSet.GetItemState( GetWhich( SID_ATTR_NUMBERFORMAT_ONE_AREA ));
504 if(eState==SFX_ITEM_SET)
506 const SfxBoolItem* pBoolItem = (const SfxBoolItem*)
507 GetItem( rSet, SID_ATTR_NUMBERFORMAT_ONE_AREA);
509 if(pBoolItem!=NULL)
511 bOneAreaFlag= pBoolItem->GetValue();
514 //bOneAreaFlag=TRUE; //@@ Debug-Test
516 eState = rSet.GetItemState( GetWhich( SID_ATTR_NUMBERFORMAT_SOURCE ) );
518 if ( eState == SFX_ITEM_SET )
520 const SfxBoolItem* pBoolItem = (const SfxBoolItem*)
521 GetItem( rSet, SID_ATTR_NUMBERFORMAT_SOURCE );
522 if ( pBoolItem )
523 aCbSourceFormat.Check( pBoolItem->GetValue() );
524 else
525 aCbSourceFormat.Check( FALSE );
526 aCbSourceFormat.Enable();
527 aCbSourceFormat.Show();
529 else
531 BOOL bInit = FALSE; // set to TRUE for debug test
532 aCbSourceFormat.Check( bInit );
533 aCbSourceFormat.Enable( bInit );
534 aCbSourceFormat.Show( bInit );
537 // pNumItem muss von aussen gesetzt worden sein!
538 DBG_ASSERT( pNumItem, "No NumberInfo, no NumberFormatter, good bye.CRASH. :-(" );
540 // aktuellen Zahlenformat-Tabellenindex holen
541 eState = rSet.GetItemState( GetWhich( SID_ATTR_NUMBERFORMAT_VALUE ) );
543 if ( SFX_ITEM_DONTCARE != eState )
544 pValFmtAttr = (const SfxUInt32Item*)
545 GetItem( rSet, SID_ATTR_NUMBERFORMAT_VALUE );
547 eValType = pNumItem->GetValueType();
549 switch ( eValType )
551 case SVX_VALUE_TYPE_STRING:
552 aValString = pNumItem->GetValueString();
553 break;
554 case SVX_VALUE_TYPE_NUMBER:
555 // #50441# string may be set in addition to the value
556 aValString = pNumItem->GetValueString();
557 nValDouble = pNumItem->GetValueDouble();
558 break;
559 case SVX_VALUE_TYPE_UNDEFINED:
560 default:
561 break;
564 // nun sind alle Informationen fuer die Formatierer-Shell beisammen:
566 if ( pNumFmtShell )
567 delete pNumFmtShell; // ggF. alte Shell loeschen (==Reset)
569 nInitFormat = ( pValFmtAttr ) // Init-Key merken
570 ? pValFmtAttr->GetValue() // (fuer FillItemSet())
571 : ULONG_MAX; // == DONT_KNOW
574 if ( eValType == SVX_VALUE_TYPE_STRING )
575 pNumFmtShell =SvxNumberFormatShell::Create(
576 pNumItem->GetNumberFormatter(),
577 (pValFmtAttr) ? nInitFormat : 0L,
578 eValType,
579 aValString );
580 else
581 pNumFmtShell =SvxNumberFormatShell::Create(
582 pNumItem->GetNumberFormatter(),
583 (pValFmtAttr) ? nInitFormat : 0L,
584 eValType,
585 nValDouble,
586 &aValString );
588 FillCurrencyBox();
590 String aPrevString;
591 Color* pDummy = NULL;
592 pNumFmtShell->GetInitSettings( nCatLbSelPos, eLangType, nFmtLbSelPos,
593 aFmtEntryList, aPrevString, pDummy );
595 aLbCurrency.SelectEntryPos((USHORT)pNumFmtShell->GetCurrencySymbol());
597 nFixedCategory=nCatLbSelPos;
598 if(bOneAreaFlag)
600 String sFixedCategory=aLbCategory.GetEntry(nFixedCategory);
601 aLbCategory.Clear();
602 aLbCategory.InsertEntry(sFixedCategory);
603 SetCategory(0);
605 else
607 SetCategory(nCatLbSelPos );
609 eState = rSet.GetItemState( GetWhich( SID_ATTR_NUMBERFORMAT_ADD_AUTO ) );
610 if(SFX_ITEM_SET == eState)
611 pAutoEntryAttr = (const SfxBoolItem*)
612 GetItem( rSet, SID_ATTR_NUMBERFORMAT_ADD_AUTO );
613 // no_NO is an alias for nb_NO and normally isn't listed, we need it for
614 // backwards compatibility, but only if the format passed is of
615 // LanguageType no_NO.
616 if ( eLangType == LANGUAGE_NORWEGIAN )
618 aLbLanguage.RemoveLanguage( eLangType ); // in case we're already called
619 aLbLanguage.InsertLanguage( eLangType );
621 aLbLanguage.SelectLanguage( eLangType );
622 if(pAutoEntryAttr)
623 AddAutomaticLanguage_Impl(eLangType, pAutoEntryAttr->GetValue());
624 UpdateFormatListBox_Impl(FALSE,TRUE);
626 //! erAck 26.01.01
627 //! This spoils everything because it rematches currency formats based on
628 //! the selected aLbCurrency entry instead of the current format.
629 //! Besides that everything seems to be initialized by now, so why call it?
630 // SelFormatHdl_Impl( &aLbCategory );
632 if ( pValFmtAttr )
634 EditHdl_Impl( &aEdFormat ); // UpdateOptions_Impl() als Seiteneffekt
636 else // DONT_KNOW
638 // Kategoriewechsel und direkte Eingabe sind moeglich, sonst nix:
639 Obstructing();
642 if ( aCbSourceFormat.IsChecked() )
644 // everything disabled except SourceFormat checkbox
645 EnableBySourceFormat_Impl();
648 DeleteEntryList_Impl(aFmtEntryList);
651 /*************************************************************************
652 #* Methode: Obstructing Datum:02.10.97
653 #*------------------------------------------------------------------------
655 #* Klasse: SvxNumberFormatTabPage
657 #* Funktion: Sperren der Controls mit Ausnahme von Kategoriewechsel
658 #* und direkter Eingabe.
660 #* Input: ---
662 #* Output: ---
664 #************************************************************************/
665 void SvxNumberFormatTabPage::Obstructing()
667 aLbFormat .SetNoSelection();
668 aLbLanguage .SetNoSelection();
669 aFtLanguage .Disable();
670 aLbLanguage .Disable();
672 aIbAdd.Enable(FALSE );
673 aIbRemove.Enable(FALSE );
674 aIbInfo.Enable(FALSE );
676 aBtnNegRed .Disable();
677 aBtnThousand .Disable();
678 aFtLeadZeroes .Disable();
679 aFtDecimals .Disable();
680 aEdLeadZeroes .Disable();
681 aEdDecimals .Disable();
682 aFlOptions .Disable();
683 aEdDecimals .SetText( String() );
684 aEdLeadZeroes .SetText( String() );
685 aBtnNegRed .Check( FALSE );
686 aBtnThousand .Check( FALSE );
687 aWndPreview .NotifyChange( String() );
689 aLbCategory .SelectEntryPos( 0 );
690 aEdFormat .SetText( String() );
691 aFtComment .SetText( String() );
692 aEdComment .SetText(aLbCategory.GetEntry(1)); //String fuer Benutzerdefiniert
693 //holen
695 aEdFormat .GrabFocus();
699 /*************************************************************************
700 #* Enable/Disable dialog parts depending on the value of the SourceFormat
701 #* checkbox.
702 #************************************************************************/
703 void SvxNumberFormatTabPage::EnableBySourceFormat_Impl()
705 BOOL bEnable = !aCbSourceFormat.IsChecked();
706 if ( !bEnable )
707 aCbSourceFormat.GrabFocus();
708 aFtCategory .Enable( bEnable );
709 aLbCategory .Enable( bEnable );
710 aFtFormat .Enable( bEnable );
711 aLbCurrency .Enable( bEnable );
712 aLbFormat .Enable( bEnable );
713 aFtLanguage .Enable( bEnable );
714 aLbLanguage .Enable( bEnable );
715 aFtDecimals .Enable( bEnable );
716 aEdDecimals .Enable( bEnable );
717 aFtLeadZeroes .Enable( bEnable );
718 aEdLeadZeroes .Enable( bEnable );
719 aBtnNegRed .Enable( bEnable );
720 aBtnThousand .Enable( bEnable );
721 aFlOptions .Enable( bEnable );
722 aFtEdFormat .Enable( bEnable );
723 aEdFormat .Enable( bEnable );
724 aIbAdd .Enable( bEnable );
725 aIbRemove .Enable( bEnable );
726 aIbInfo .Enable( bEnable );
727 aFtComment .Enable( bEnable );
728 aEdComment .Enable( bEnable );
729 aLbFormat.Invalidate(); // #i43322#
733 /*************************************************************************
734 #* Methode: HideLanguage Datum:14.05.98
735 #*------------------------------------------------------------------------
737 #* Klasse: SvxNumberFormatTabPage
739 #* Funktion: Versteckt die Spracheinstellung:
741 #* Input: BOOL nFlag
743 #* Output: ---
745 #************************************************************************/
747 void SvxNumberFormatTabPage::HideLanguage(BOOL nFlag)
749 Size aSize=aLbCategory.GetSizePixel();
751 if(nFlag)
753 aSize.Height()=aLbFormat.GetSizePixel().Height();
755 else
757 aSize.Height()=nCatHeight;
760 aLbCategory.SetSizePixel(aSize);
762 aFtLanguage.Show(!nFlag);
763 aLbLanguage.Show(!nFlag);
766 /*************************************************************************
767 #* Methode: FillItemSet Datum:02.10.97
768 #*------------------------------------------------------------------------
770 #* Klasse: SvxNumberFormatTabPage
772 #* Funktion: Stellt die Attribute im ItemSet ein,
773 #* sowie in der DocShell den numItem, wenn
774 #* bNumItemFlag nicht gesetzt ist.
776 #* Input: SfxItemSet
778 #* Output: ---
780 #************************************************************************/
782 BOOL SvxNumberFormatTabPage::FillItemSet( SfxItemSet& rCoreAttrs )
784 BOOL bDataChanged = aFtLanguage.IsEnabled() || aCbSourceFormat.IsEnabled();
785 if ( bDataChanged )
787 const SfxItemSet& rMyItemSet = GetItemSet();
788 USHORT nWhich = GetWhich( SID_ATTR_NUMBERFORMAT_VALUE );
789 SfxItemState eItemState = rMyItemSet.GetItemState( nWhich, FALSE );
791 // OK chosen - Is format code input entered already taken over?
792 // If not, simulate Add. Upon syntax error ignore input and prevent Put.
793 String aFormat = aEdFormat.GetText();
794 sal_uInt32 nCurKey = pNumFmtShell->GetCurNumFmtKey();
796 if ( aIbAdd.IsEnabled() || pNumFmtShell->IsTmpCurrencyFormat(aFormat) )
797 { // #79599# It is not sufficient to just add the format code (or
798 // delete it in case of bOneAreaFlag and resulting category change).
799 // Upon switching tab pages we need all settings to be consistent
800 // in case this page will be redisplayed later.
801 bDataChanged = (ClickHdl_Impl( &aIbAdd ) != 0);
802 nCurKey = pNumFmtShell->GetCurNumFmtKey();
804 else if(nCurKey == NUMKEY_UNDEFINED)
805 { // something went wrong, e.g. in Writer #70281#
806 pNumFmtShell->FindEntry(aFormat, &nCurKey);
809 //---------------------------------------------------------------
810 // Chosen format:
811 // --------------
812 if ( bDataChanged )
814 bDataChanged = ( nInitFormat != nCurKey );
816 if (bDataChanged)
818 rCoreAttrs.Put( SfxUInt32Item( nWhich, nCurKey ) );
820 else if(SFX_ITEM_DEFAULT == eItemState)
822 rCoreAttrs.ClearItem( nWhich );
826 // --------------------------------------------------------------
827 // List of changed user defined formats:
828 // -------------------------------------
829 const sal_uInt32 nDelCount = pNumFmtShell->GetUpdateDataCount();
831 if ( nDelCount > 0 )
833 sal_uInt32* pDelArr = new sal_uInt32[nDelCount];
835 pNumFmtShell->GetUpdateData( pDelArr, nDelCount );
836 pNumItem->SetDelFormatArray( pDelArr, nDelCount );
838 if(bNumItemFlag==TRUE)
840 rCoreAttrs.Put( *pNumItem );
842 else
844 SfxObjectShell* pDocSh = SfxObjectShell::Current();
846 DBG_ASSERT( pDocSh, "DocShell not found!" );
849 if ( pDocSh )
850 pDocSh->PutItem( *pNumItem );
852 delete [] pDelArr;
855 //---------------------------------------------------------------
856 // Whether source format is to be taken or not:
857 // --------------------------------------------
858 if ( aCbSourceFormat.IsEnabled() )
860 USHORT _nWhich = GetWhich( SID_ATTR_NUMBERFORMAT_SOURCE );
861 SfxItemState _eItemState = rMyItemSet.GetItemState( _nWhich, FALSE );
862 const SfxBoolItem* pBoolItem = (const SfxBoolItem*)
863 GetItem( rMyItemSet, SID_ATTR_NUMBERFORMAT_SOURCE );
864 BOOL bOld = (pBoolItem ? pBoolItem->GetValue() : FALSE);
865 rCoreAttrs.Put( SfxBoolItem( _nWhich, aCbSourceFormat.IsChecked() ) );
866 if ( !bDataChanged )
867 bDataChanged = (bOld != (BOOL) aCbSourceFormat.IsChecked() ||
868 _eItemState != SFX_ITEM_SET);
871 // FillItemSet is only called on OK, here we can notify the
872 // NumberFormatShell that all new user defined formats are valid.
873 pNumFmtShell->ValidateNewEntries();
874 if(aLbLanguage.IsVisible() &&
875 LISTBOX_ENTRY_NOTFOUND != aLbLanguage.GetEntryPos(sAutomaticEntry))
876 rCoreAttrs.Put(SfxBoolItem(SID_ATTR_NUMBERFORMAT_ADD_AUTO,
877 aLbLanguage.GetSelectEntry() == sAutomaticEntry));
880 return bDataChanged;
884 int SvxNumberFormatTabPage::DeactivatePage( SfxItemSet* _pSet )
886 /* if ( (ULONG_MAX != nInitFormat) && _pSet )
888 const ULONG nCurKey = pNumFmtShell->GetCurNumFmtKey();
889 const USHORT nWhich = GetWhich( SID_ATTR_NUMBERFORMAT_VALUE );
890 SfxItemState eItemState = GetItemSet().GetItemState( nWhich, FALSE );
892 if ( (nInitFormat == nCurKey) && (SFX_ITEM_DEFAULT == eItemState) )
893 _pSet->ClearItem( nWhich );
894 else
895 _pSet->Put( SfxUInt32Item( nWhich, nCurKey ) );
898 if ( _pSet )
899 FillItemSet( *_pSet );
900 return LEAVE_PAGE;
903 void SvxNumberFormatTabPage::SetInfoItem( const SvxNumberInfoItem& rItem )
905 if(pNumItem==NULL)
907 pNumItem = (SvxNumberInfoItem*)rItem.Clone();
911 void SvxNumberFormatTabPage::FillFormatListBox_Impl( SvxDelStrgs& rEntries )
913 String* pEntry;
914 String aTmpString;
915 String aTmpCatString;
916 Font aFont=aLbCategory.GetFont();
917 USHORT i = 0;
918 short nTmpCatPos;
919 short aPrivCat;
921 aLbFormat.Clear();
922 aLbFormat.SetUpdateMode( FALSE );
924 USHORT nCount = rEntries.Count();
926 if(nCount<1) return;
928 if(bOneAreaFlag)
930 nTmpCatPos=nFixedCategory;
932 else
934 nTmpCatPos=aLbCategory.GetSelectEntryPos();
937 switch (nTmpCatPos)
939 case CAT_ALL:
940 case CAT_TEXT:
941 case CAT_NUMBER: i=1;
942 pEntry=rEntries[0];
943 if(pEntry!=NULL)
945 if (nTmpCatPos == CAT_TEXT)
946 aTmpString=*pEntry;
947 else
948 aTmpString = pNumFmtShell->GetStandardName();
949 aPrivCat=pNumFmtShell->GetCategory4Entry(0);
950 aLbFormat.InsertFontEntry( aTmpString, aFont );
952 break;
954 default: break;
957 if(pNumFmtShell!=NULL)
959 for ( ; i < nCount; ++i )
961 pEntry = rEntries[i];
962 aPrivCat=pNumFmtShell->GetCategory4Entry(i);
963 if(aPrivCat!=CAT_TEXT)
965 Color* pPreviewColor = NULL;
966 String aPreviewString( GetExpColorString( pPreviewColor, *pEntry, aPrivCat ) );
967 Font aEntryFont( aLbFormat.GetFont() );
968 aLbFormat.InsertFontEntry( aPreviewString, aEntryFont, pPreviewColor );
970 else
972 aLbFormat.InsertFontEntry(*pEntry,aFont);
976 aLbFormat.SetUpdateMode( TRUE );
977 DeleteEntryList_Impl(rEntries);
981 /*************************************************************************
982 #* Methode: DeleteEntryList_Impl Datum:02.10.97
983 #*------------------------------------------------------------------------
985 #* Klasse: SvxNumberFormatTabPage
987 #* Funktion: Loescht eine SvStrings- Liste
989 #* Input: String-liste
991 #* Output: ---
993 #************************************************************************/
995 void SvxNumberFormatTabPage::DeleteEntryList_Impl( SvxDelStrgs& rEntries )
997 USHORT nCount = rEntries.Count();
998 rEntries.DeleteAndDestroy(0,nCount);
1002 /*************************************************************************
1003 #* Methode: UpdateOptions_Impl Datum:02.10.97
1004 #*------------------------------------------------------------------------
1006 #* Klasse: SvxNumberFormatTabPage
1008 #* Funktion: Stellt je nach eingestelltem Format die Options-
1009 #* attribute neu ein.
1011 #* Input: Flag, ob sich die Kategorie geaendert hat.
1013 #* Output: ---
1015 #***?********************************************************************/
1017 void SvxNumberFormatTabPage::UpdateOptions_Impl( BOOL bCheckCatChange /*= FALSE*/ )
1019 SvxDelStrgs aEntryList;
1020 String theFormat = aEdFormat.GetText();
1021 USHORT nCurCategory = aLbCategory.GetSelectEntryPos();
1022 USHORT nCategory = nCurCategory;
1023 USHORT nDecimals = 0;
1024 USHORT nZeroes = 0;
1025 BOOL bNegRed = FALSE;
1026 BOOL bThousand = FALSE;
1027 short nTmpCatPos;
1028 USHORT nCurrencyPos =aLbCurrency.GetSelectEntryPos();
1030 if(bOneAreaFlag)
1032 nTmpCatPos=nFixedCategory;
1033 nCurCategory=nFixedCategory;
1035 else
1037 nTmpCatPos=nCurCategory;
1041 pNumFmtShell->GetOptions( theFormat,
1042 bThousand, bNegRed,
1043 nDecimals, nZeroes,
1044 nCategory );
1045 BOOL bDoIt=FALSE;
1046 if(nCategory==CAT_CURRENCY)
1048 USHORT nTstPos=pNumFmtShell->FindCurrencyFormat(theFormat);
1049 if(nCurrencyPos!=nTstPos && nTstPos!=(USHORT)-1)
1051 aLbCurrency.SelectEntryPos(nTstPos);
1052 pNumFmtShell->SetCurrencySymbol(nTstPos);
1053 bDoIt=TRUE;
1059 if ( nCategory != nCurCategory || bDoIt)
1061 if ( bCheckCatChange )
1063 if(bOneAreaFlag)
1064 SetCategory(0);
1065 else
1066 SetCategory(nCategory );
1068 UpdateFormatListBox_Impl( TRUE, FALSE );
1071 else if ( aLbFormat.GetEntryCount() > 0 )
1073 sal_uInt32 nCurEntryKey=NUMKEY_UNDEFINED;
1074 if(!pNumFmtShell->FindEntry( aEdFormat.GetText(),&nCurEntryKey))
1076 aLbFormat.SetNoSelection();
1079 if(bOneAreaFlag)
1081 nCategory=nFixedCategory;
1084 switch ( nCategory )
1086 case CAT_NUMBER:
1087 case CAT_PERCENT:
1088 case CAT_CURRENCY:
1089 aFlOptions.Enable();
1090 aFtDecimals.Enable();
1091 aEdDecimals.Enable();
1092 aFtLeadZeroes.Enable();
1093 aEdLeadZeroes.Enable();
1094 aBtnNegRed.Enable();
1095 aBtnThousand.Enable();
1097 aEdDecimals .SetValue( nDecimals );
1098 aEdLeadZeroes.SetValue( nZeroes );
1100 aEdDecimals .SetText( UniString::CreateFromInt32( nDecimals ) );
1101 aEdLeadZeroes.SetText( UniString::CreateFromInt32( nZeroes ) );
1102 aBtnNegRed .Check( bNegRed );
1103 aBtnThousand .Check( bThousand );
1104 break;
1106 case CAT_ALL:
1107 case CAT_USERDEFINED:
1108 case CAT_TEXT:
1109 case CAT_DATE:
1110 case CAT_TIME:
1111 case CAT_BOOLEAN:
1112 case CAT_SCIENTIFIC:
1113 case CAT_FRACTION:
1114 default:
1115 aFlOptions .Disable();
1116 aFtDecimals .Disable();
1117 aEdDecimals .Disable();
1118 aFtLeadZeroes .Disable();
1119 aEdLeadZeroes .Disable();
1120 aBtnNegRed .Disable();
1121 aBtnThousand .Disable();
1122 aEdDecimals .SetText( UniString::CreateFromInt32( 0 ) );
1123 aEdLeadZeroes .SetText( UniString::CreateFromInt32( 0 ) );
1124 aBtnNegRed .Check( FALSE );
1125 aBtnThousand .Check( FALSE );
1130 /*************************************************************************
1131 #* Methode: UpdateFormatListBox_Impl Datum:02.10.97
1132 #*------------------------------------------------------------------------
1134 #* Klasse: SvxNumberFormatTabPage
1136 #* Funktion: Aktualisiert die Format- Listbox und zusaetzlich
1137 #* wird abhaengig vom bUpdateEdit- Flag der String
1138 #* in der Editbox geaendert.
1140 #* Input: Flags fuer Kategorie und Editbox
1142 #* Output: ---
1144 #************************************************************************/
1146 void SvxNumberFormatTabPage::UpdateFormatListBox_Impl
1148 USHORT bCat, // Category oder Land/Sprache ListBox?
1149 BOOL bUpdateEdit // Format-Edit aktualisieren?
1152 SvxDelStrgs aEntryList;
1153 short nFmtLbSelPos = 0;
1154 short nTmpCatPos;
1156 if(bOneAreaFlag)
1158 nTmpCatPos=nFixedCategory;
1160 else
1162 nTmpCatPos=aLbCategory.GetSelectEntryPos();
1166 if ( bCat )
1168 Point aPos=aLbFormat.GetPosPixel();
1169 Size aSize=aLbFormat.GetSizePixel();
1171 if(nTmpCatPos!=CAT_CURRENCY)
1173 aPos.Y()=nStdFormatY;
1174 aSize.Height()=nStdFormatHeight;
1175 aLbFormat.SetPosSizePixel(aPos,aSize);
1176 #if ENABLE_LAYOUT
1177 aLbCurrency.Disable();
1178 #else /* !ENABLE_LAYOUT */
1179 aLbCurrency.Hide();
1180 #endif /* !ENABLE_LAYOUT */
1182 else
1184 aPos.Y()=nCurFormatY;
1185 aSize.Height()=nCurFormatHeight;
1186 aLbFormat.SetPosSizePixel(aPos,aSize);
1187 #if ENABLE_LAYOUT
1188 aLbCurrency.Enable();
1189 #else /* !ENABLE_LAYOUT */
1190 aLbCurrency.Show();
1191 #endif /* !ENABLE_LAYOUT */
1194 pNumFmtShell->CategoryChanged( nTmpCatPos,nFmtLbSelPos, aEntryList );
1196 else
1197 pNumFmtShell->LanguageChanged( aLbLanguage.GetSelectLanguage(),
1198 nFmtLbSelPos,aEntryList );
1200 REMOVE_DONTKNOW() // ggF. UI-Enable
1203 if ( (aEntryList.Count() > 0) && (nFmtLbSelPos != SELPOS_NONE) )
1205 if(bUpdateEdit)
1207 String aFormat=*aEntryList[nFmtLbSelPos];
1208 aEdFormat.SetText(aFormat);
1209 aFtComment.SetText(pNumFmtShell->GetComment4Entry(nFmtLbSelPos));
1211 //@23.09.97 aEdFormat.SetText( aLbFormat.GetSelectEntry() );
1214 if(!bOneAreaFlag || !bCat)
1216 FillFormatListBox_Impl( aEntryList );
1217 aLbFormat.SelectEntryPos( nFmtLbSelPos );
1219 aFtComment.SetText(pNumFmtShell->GetComment4Entry(nFmtLbSelPos));
1220 if(pNumFmtShell->GetUserDefined4Entry(nFmtLbSelPos))
1222 if(pNumFmtShell->GetComment4Entry(nFmtLbSelPos).Len()==0)
1224 aFtComment.SetText(aLbCategory.GetEntry(1));
1227 ChangePreviewText( (USHORT)nFmtLbSelPos );
1231 else
1233 FillFormatListBox_Impl( aEntryList );
1234 if(nFmtLbSelPos != SELPOS_NONE)
1236 aLbFormat.SelectEntryPos( (USHORT)nFmtLbSelPos );
1238 aFtComment.SetText(pNumFmtShell->GetComment4Entry(nFmtLbSelPos));
1239 if(pNumFmtShell->GetUserDefined4Entry(nFmtLbSelPos))
1241 if(pNumFmtShell->GetComment4Entry(nFmtLbSelPos).Len()==0)
1243 aFtComment.SetText(aLbCategory.GetEntry(1));
1247 else
1249 aLbFormat.SetNoSelection();
1252 if ( bUpdateEdit )
1254 aEdFormat.SetText( String() );
1255 aWndPreview.NotifyChange( String() );
1261 /*************************************************************************
1262 #* Handle: DoubleClickHdl_Impl Datum:02.10.97
1263 #*------------------------------------------------------------------------
1265 #* Klasse: SvxNumberFormatTabPage
1267 #* Funktion: Bei einem Doppelklick in die Format- Listbox
1268 #* wird der Wert uebernommen und der OK-Button
1269 #* ausgeloest
1271 #* Input: Pointer auf Listbox
1273 #* Output: ---
1275 #************************************************************************/
1277 IMPL_LINK( SvxNumberFormatTabPage, DoubleClickHdl_Impl, SvxFontListBox*, pLb )
1279 if ( pLb == &aLbFormat )
1281 SelFormatHdl_Impl( pLb );
1283 if ( fnOkHdl.IsSet() )
1284 { // Uebergangsloesung, sollte von SfxTabPage angeboten werden
1285 fnOkHdl.Call( NULL );
1287 else
1289 SfxSingleTabDialog* pParent = dynamic_cast< SfxSingleTabDialog* >( GetParent() );
1290 OKButton* pOKButton = pParent ? pParent->GetOKButton() : NULL;
1291 if ( pOKButton )
1292 pOKButton->Click();
1295 return 0;
1299 /*************************************************************************
1300 #* Methode: SelFormatHdl_Impl Datum:02.10.97
1301 #*------------------------------------------------------------------------
1303 #* Klasse: SvxNumberFormatTabPage
1305 #* Funktion: Wird aufgerufen, wenn sich die Sprache, die Kategorie
1306 #* oder das Format aendert. Dem entsprechend werden die
1307 #* Einstellungen geaendert.
1309 #* Input: Pointer auf Listbox
1311 #* Output: ---
1313 #************************************************************************/
1315 IMPL_LINK( SvxNumberFormatTabPage, SelFormatHdl_Impl, void *, pLb )
1317 if ( (CheckBox*)pLb == &aCbSourceFormat )
1319 EnableBySourceFormat_Impl(); // enable/disable everything else
1320 if ( aCbSourceFormat.IsChecked() )
1321 return 0; // just disabled everything else
1323 // Reinit options enable/disable for current selection.
1325 #if ENABLE_LAYOUT
1326 if (aLbFormat.GetSelectEntryPos () == LISTBOX_ENTRY_NOTFOUND)
1327 #else /* !ENABLE_LAYOUT */
1328 // Current category may be UserDefined with no format entries defined.
1329 // And yes, aLbFormat is a SvxFontListBox with ULONG list positions,
1330 // implementation returns a LIST_APPEND if empty, comparison with
1331 // USHORT LISTBOX_ENTRY_NOTFOUND wouldn't match.
1332 if ( aLbFormat.GetSelectEntryPos() == LIST_APPEND )
1333 #endif /* !ENABLE_LAYOUT */
1334 pLb = &aLbCategory; // continue with the current category selected
1335 else
1336 pLb = &aLbFormat; // continue with the current format selected
1339 short nTmpCatPos;
1341 if(bOneAreaFlag)
1343 nTmpCatPos=nFixedCategory;
1345 else
1347 nTmpCatPos=aLbCategory.GetSelectEntryPos();
1350 USHORT nCurrencyPos=LISTBOX_ENTRY_NOTFOUND ;
1352 if(nTmpCatPos==CAT_CURRENCY && (ListBox *)pLb == &aLbCurrency )
1354 nCurrencyPos=aLbCurrency.GetSelectEntryPos();
1355 pNumFmtShell->SetCurrencySymbol(nCurrencyPos);
1358 //--------------------------------------------------------------------
1359 // Format-ListBox ----------------------------------------------------
1360 if ( (SvxFontListBox *)pLb == &aLbFormat )
1362 USHORT nSelPos = (USHORT) aLbFormat.GetSelectEntryPos();
1363 String aFormat = aLbFormat.GetSelectEntry();
1364 String aComment;
1365 SvxDelStrgs aEntryList;
1367 short nFmtLbSelPos = nSelPos;
1369 aFormat=pNumFmtShell->GetFormat4Entry(nSelPos);
1370 aComment=pNumFmtShell->GetComment4Entry(nSelPos);
1371 if(pNumFmtShell->GetUserDefined4Entry(nFmtLbSelPos))
1373 if(pNumFmtShell->GetComment4Entry(nFmtLbSelPos).Len()==0)
1375 aComment=aLbCategory.GetEntry(1);
1379 if ( aFormat.Len() > 0 )
1381 if(!aEdFormat.HasFocus()) aEdFormat.SetText( aFormat );
1382 aFtComment.SetText(aComment);
1383 ChangePreviewText( nSelPos );
1386 REMOVE_DONTKNOW() // ggF. UI-Enable
1388 if ( pNumFmtShell->FindEntry( aFormat) )
1390 aIbAdd.Enable(FALSE );
1391 BOOL bIsUserDef=pNumFmtShell->IsUserDefined( aFormat );
1392 aIbRemove.Enable(bIsUserDef);
1393 aIbInfo.Enable(bIsUserDef);
1396 else
1398 aIbAdd.Enable(TRUE );
1399 aIbInfo.Enable(TRUE );
1400 aIbRemove.Enable(FALSE );
1401 aFtComment.SetText(aEdComment.GetText());
1404 UpdateOptions_Impl( FALSE );
1406 //-------
1407 return 0;
1408 //-------
1411 //--------------------------------------------------------------------
1412 // Kategorie-ListBox -------------------------------------------------
1413 if ( pLb == &aLbCategory || pLb == &aLbCurrency)
1415 UpdateFormatListBox_Impl( TRUE, TRUE );
1416 EditHdl_Impl( NULL );
1417 UpdateOptions_Impl( FALSE );
1419 //-------
1420 return 0;
1421 //-------
1424 //--------------------------------------------------------------------
1425 // Sprache/Land-ListBox ----------------------------------------------
1426 if ( pLb == &aLbLanguage )
1428 UpdateFormatListBox_Impl( FALSE, TRUE );
1429 EditHdl_Impl( &aEdFormat );
1431 //-------
1432 return 0;
1433 //-------
1435 return 0;
1439 /*************************************************************************
1440 #* Methode: ClickHdl_Impl, ImageButton* pIB Datum:02.10.97
1441 #*------------------------------------------------------------------------
1443 #* Klasse: SvxNumberFormatTabPage
1445 #* Funktion: Wenn, der Hinzufuegen- oder Entfernen- Button
1446 #* wird diese Funktion aufgerufen und die Zahlenformat-
1447 #* Liste den entsprechend geaendert.
1449 #* Input: Toolbox- Button
1451 #* Output: ---
1453 #************************************************************************/
1455 IMPL_LINK( SvxNumberFormatTabPage, ClickHdl_Impl, ImageButton*, pIB)
1457 BOOL bAdded = FALSE;
1458 BOOL bDeleted = FALSE;
1459 ULONG nReturn = 0;
1460 const ULONG nReturnChanged = 0x1; // THE boolean return value
1461 const ULONG nReturnAdded = 0x2; // temp: format added
1462 const ULONG nReturnOneArea = 0x4; // temp: one area but category changed => ignored
1464 if(pIB==&aIbAdd)
1465 { // Also called from FillItemSet() if a temporary currency format has
1466 // to be added, not only if the Add button is enabled.
1467 String aFormat = aEdFormat.GetText();
1468 SvxDelStrgs aEntryList;
1469 SvxDelStrgs a2EntryList;
1470 USHORT nCatLbSelPos = 0;
1471 short nFmtLbSelPos = SELPOS_NONE;
1472 xub_StrLen nErrPos=0;
1474 pNumFmtShell->SetCurCurrencyEntry(NULL);
1475 bAdded = pNumFmtShell->AddFormat( aFormat, nErrPos,
1476 nCatLbSelPos, nFmtLbSelPos,
1477 aEntryList);
1478 if ( bAdded )
1479 nReturn |= nReturnChanged | nReturnAdded;
1481 if(pLastActivWindow== (Window *) &aEdComment)
1483 aEdFormat.GrabFocus();
1484 aEdComment.Hide();
1485 aFtComment.Show();
1486 aFtComment.SetText(aEdComment.GetText());
1489 if ( !nErrPos ) // Syntax ok?
1491 if(nCatLbSelPos==CAT_CURRENCY)
1493 aLbCurrency.SelectEntryPos((USHORT)pNumFmtShell->GetCurrencySymbol());
1496 if(bOneAreaFlag && (nFixedCategory!=nCatLbSelPos))
1498 if(bAdded) DeleteEntryList_Impl(aEntryList);
1499 bDeleted = pNumFmtShell->RemoveFormat( aFormat,
1500 nCatLbSelPos,
1501 nFmtLbSelPos,
1502 a2EntryList);
1503 if(bDeleted) DeleteEntryList_Impl(a2EntryList);
1504 aEdFormat.GrabFocus();
1505 aEdFormat.SetSelection( Selection( (short)nErrPos, SELECTION_MAX ) );
1506 nReturn |= nReturnOneArea;
1508 else
1510 if ( bAdded && (nFmtLbSelPos != SELPOS_NONE) )
1512 // Alles klar
1513 if(bOneAreaFlag) //@@ ???
1514 SetCategory(0);
1515 else
1516 SetCategory(nCatLbSelPos );
1518 FillFormatListBox_Impl( aEntryList );
1519 if(aEdComment.GetText()!=aLbCategory.GetEntry(1))
1521 pNumFmtShell->SetComment4Entry(nFmtLbSelPos,
1522 aEdComment.GetText());
1524 else
1526 pNumFmtShell->SetComment4Entry(nFmtLbSelPos,
1527 String());
1529 aLbFormat.SelectEntryPos( (USHORT)nFmtLbSelPos );
1530 aEdFormat.SetText( aFormat );
1532 //aEdComment.SetText(String()); //@@ ???
1533 aEdComment.SetText(aLbCategory.GetEntry(1)); //String fuer Benutzerdefiniert
1534 //holen
1535 ChangePreviewText( (USHORT)nFmtLbSelPos );
1539 else // Syntaxfehler
1541 aEdFormat.GrabFocus();
1542 aEdFormat.SetSelection( Selection( (short)nErrPos, SELECTION_MAX ) );
1544 EditHdl_Impl( &aEdFormat );
1545 nReturn = ((nReturn & nReturnOneArea) ? 0 : (nReturn & nReturnChanged));
1547 else if(pIB==&aIbRemove)
1549 String aFormat = aEdFormat.GetText();
1550 SvxDelStrgs aEntryList;
1551 USHORT nCatLbSelPos = 0;
1552 short nFmtLbSelPos = SELPOS_NONE;
1554 bDeleted = pNumFmtShell->RemoveFormat( aFormat,
1555 nCatLbSelPos,
1556 nFmtLbSelPos,
1557 aEntryList );
1559 aEdComment.SetText(aLbCategory.GetEntry(1));
1560 if ( bDeleted )
1562 if(nFmtLbSelPos>=0 && nFmtLbSelPos<aEntryList.Count())
1564 aFormat = *aEntryList[nFmtLbSelPos];
1567 FillFormatListBox_Impl( aEntryList );
1569 if ( nFmtLbSelPos != SELPOS_NONE )
1571 if(bOneAreaFlag) //@@ ???
1572 SetCategory(0);
1573 else
1574 SetCategory(nCatLbSelPos );
1576 aLbFormat.SelectEntryPos( (USHORT)nFmtLbSelPos );
1577 aEdFormat.SetText( aFormat );
1578 ChangePreviewText( (USHORT)nFmtLbSelPos );
1580 else
1582 // auf "Alle/Standard" setzen
1583 SetCategory(0 );
1584 SelFormatHdl_Impl( &aLbCategory );
1587 EditHdl_Impl( &aEdFormat );
1589 else if(pIB==&aIbInfo)
1591 if(!(pLastActivWindow== (Window *) &aEdComment))
1593 aEdComment.SetText(aFtComment.GetText());
1594 aEdComment.Show();
1595 aFtComment.Hide();
1596 aEdComment.GrabFocus();
1598 else
1600 aEdFormat.GrabFocus();
1601 aEdComment.Hide();
1602 aFtComment.Show();
1606 return nReturn;
1610 /*************************************************************************
1611 #* Methode: EditHdl_Impl Datum:02.10.97
1612 #*------------------------------------------------------------------------
1614 #* Klasse: SvxNumberFormatTabPage
1616 #* Funktion: Wenn der Eintrag im Eingabefeld geaendert wird,
1617 #* so wird die Vorschau aktualisiert und
1619 #* Input: Pointer auf Editbox
1621 #* Output: ---
1623 #************************************************************************/
1625 IMPL_LINK( SvxNumberFormatTabPage, EditHdl_Impl, Edit*, pEdFormat )
1627 sal_uInt32 nCurKey = NUMKEY_UNDEFINED;
1629 if ( aEdFormat.GetText().Len() == 0 )
1631 aIbAdd.Enable(FALSE );
1632 aIbRemove.Enable(FALSE );
1633 aIbInfo.Enable(FALSE );
1634 aFtComment.SetText(String());
1636 else
1638 String aFormat = aEdFormat.GetText();
1639 //aFtComment.SetText(String());
1640 MakePreviewText( aFormat );
1642 if ( pNumFmtShell->FindEntry( aFormat, &nCurKey ) )
1644 aIbAdd.Enable(FALSE );
1645 BOOL bUserDef=pNumFmtShell->IsUserDefined( aFormat );
1647 aIbRemove.Enable(bUserDef);
1648 aIbInfo.Enable(bUserDef);
1650 if(bUserDef)
1652 USHORT nTmpCurPos=pNumFmtShell->FindCurrencyFormat(aFormat );
1654 if(nTmpCurPos!=(USHORT)-1)
1655 aLbCurrency.SelectEntryPos(nTmpCurPos);
1657 short nPosi=pNumFmtShell->GetListPos4Entry(aFormat);
1658 if(nPosi>=0)
1659 aLbFormat.SelectEntryPos( (USHORT)nPosi);
1662 else
1665 aIbAdd.Enable(TRUE );
1666 aIbInfo.Enable(TRUE);
1667 aIbRemove.Enable(FALSE );
1669 aFtComment.SetText(aEdComment.GetText());
1674 if ( pEdFormat )
1676 pNumFmtShell->SetCurNumFmtKey( nCurKey );
1677 UpdateOptions_Impl( TRUE );
1680 return 0;
1684 /*************************************************************************
1685 #* Methode: NotifyChange Datum:02.10.97
1686 #*------------------------------------------------------------------------
1688 #* Klasse: SvxNumberFormatTabPage
1690 #* Funktion: Fuehrt Aenderungen in den Zahlen- Attributen durch.
1692 #* Input: Options- Controls
1694 #* Output: ---
1696 #************************************************************************/
1698 IMPL_LINK( SvxNumberFormatTabPage, OptHdl_Impl, void *, pOptCtrl )
1700 if ( ((NumericField*)pOptCtrl == &aEdLeadZeroes)
1701 || ((NumericField*)pOptCtrl == &aEdDecimals)
1702 || ((CheckBox*) pOptCtrl == &aBtnNegRed)
1703 || ((CheckBox*) pOptCtrl == &aBtnThousand) )
1705 String aFormat;
1706 BOOL bThousand = aBtnThousand.IsEnabled()
1707 && aBtnThousand.IsChecked();
1708 BOOL bNegRed = aBtnNegRed.IsEnabled()
1709 && aBtnNegRed.IsChecked();
1710 USHORT nPrecision = (aEdDecimals.IsEnabled())
1711 ? (USHORT)aEdDecimals.GetValue()
1712 : (USHORT)0;
1713 USHORT nLeadZeroes = (aEdLeadZeroes.IsEnabled())
1714 ? (USHORT)aEdLeadZeroes.GetValue()
1715 : (USHORT)0;
1717 pNumFmtShell->MakeFormat( aFormat,
1718 bThousand, bNegRed,
1719 nPrecision, nLeadZeroes,
1720 (USHORT)aLbFormat.GetSelectEntryPos() );
1722 aEdFormat.SetText( aFormat );
1723 //aFtComment.SetText(String());
1724 MakePreviewText( aFormat );
1726 if ( pNumFmtShell->FindEntry( aFormat ) )
1728 aIbAdd.Enable(FALSE );
1729 BOOL bUserDef=pNumFmtShell->IsUserDefined( aFormat );
1730 aIbRemove.Enable(bUserDef);
1731 aIbInfo.Enable(bUserDef);
1732 EditHdl_Impl( &aEdFormat);
1735 else
1737 EditHdl_Impl( NULL );
1738 aLbFormat.SetNoSelection();
1741 return 0;
1744 IMPL_LINK( SvxNumberFormatTabPage, TimeHdl_Impl, Timer*, EMPTYARG)
1746 pLastActivWindow=NULL;
1747 return 0;
1751 /*************************************************************************
1752 #* Methode: LostFocusHdl_Impl Datum:30.10.97
1753 #*------------------------------------------------------------------------
1755 #* Klasse: SvxNumberFormatTabPage
1757 #* Funktion: Fuehrt Aenderungen in den Zahlen- Attributen durch.
1759 #* Input: Options- Controls
1761 #* Output: ---
1763 #************************************************************************/
1765 IMPL_LINK( SvxNumberFormatTabPage, LostFocusHdl_Impl, Edit *, pEd)
1767 if (pEd==&aEdComment)
1769 aResetWinTimer.Start();
1770 aFtComment.SetText(aEdComment.GetText());
1771 aEdComment.Hide();
1772 aFtComment.Show();
1773 if(!aIbAdd.IsEnabled())
1775 USHORT nSelPos = (USHORT) aLbFormat.GetSelectEntryPos();
1776 pNumFmtShell->SetComment4Entry(nSelPos,
1777 aEdComment.GetText());
1778 aEdComment.SetText(aLbCategory.GetEntry(1)); //String fuer Benutzerdefiniert
1779 //holen
1782 return 0;
1785 /*************************************************************************
1786 #* Methode: NotifyChange Datum:02.10.97
1787 #*------------------------------------------------------------------------
1789 #* Klasse: SvxNumberFormatTabPage
1791 #* Funktion: Fuehrt Aenderungen in den Zahlen- Attributen durch.
1793 #* Input: Options- Controls
1795 #* Output: ---
1797 #************************************************************************/
1799 String SvxNumberFormatTabPage::GetExpColorString(
1800 Color*& rpPreviewColor, const String& rFormatStr, short nTmpCatPos)
1802 double nVal = 0;
1803 switch (nTmpCatPos)
1805 case CAT_CURRENCY: nVal=SVX_NUMVAL_CURRENCY; break;
1807 case CAT_SCIENTIFIC:
1808 case CAT_FRACTION:
1809 case CAT_NUMBER: nVal=SVX_NUMVAL_STANDARD; break;
1811 case CAT_PERCENT: nVal=SVX_NUMVAL_PERCENT; break;
1813 case CAT_ALL: nVal=SVX_NUMVAL_STANDARD; break;
1815 case CAT_TIME: nVal=SVX_NUMVAL_TIME; break;
1816 case CAT_DATE: nVal=SVX_NUMVAL_DATE; break;
1818 case CAT_BOOLEAN: nVal=SVX_NUMVAL_BOOLEAN; break;
1820 case CAT_USERDEFINED:
1821 case CAT_TEXT:
1822 default: nVal=0;break;
1825 String aPreviewString;
1826 pNumFmtShell->MakePrevStringFromVal( rFormatStr, aPreviewString, rpPreviewColor, nVal );
1827 return aPreviewString;
1830 void SvxNumberFormatTabPage::MakePreviewText( const String& rFormat )
1832 String aPreviewString;
1833 Color* pPreviewColor = NULL;
1834 pNumFmtShell->MakePreviewString( rFormat, aPreviewString, pPreviewColor );
1835 aWndPreview.NotifyChange( aPreviewString, pPreviewColor );
1838 void SvxNumberFormatTabPage::ChangePreviewText( USHORT nPos )
1840 String aPreviewString;
1841 Color* pPreviewColor = NULL;
1842 pNumFmtShell->FormatChanged( nPos, aPreviewString, pPreviewColor );
1843 aWndPreview.NotifyChange( aPreviewString, pPreviewColor );
1846 long SvxNumberFormatTabPage::PreNotify( NotifyEvent& rNEvt )
1848 if(rNEvt.GetType()==EVENT_LOSEFOCUS)
1850 if ( rNEvt.GetWindow() == dynamic_cast< Window* >( &aEdComment ) && !aEdComment.IsVisible() )
1852 pLastActivWindow = NULL;
1854 else
1856 pLastActivWindow = rNEvt.GetWindow();
1860 return SfxTabPage::PreNotify( rNEvt );
1862 /*************************************************************************
1863 #* Methode: SetOkHdl Datum:01.11.97
1864 #*------------------------------------------------------------------------
1866 #* Klasse: SvxNumberFormatTabPage
1868 #* Funktion: Setzt den OkHandler neu.
1870 #* Input: Neuer OkHandler
1872 #* Output: ---
1874 #************************************************************************/
1876 void SvxNumberFormatTabPage::SetOkHdl( const Link& rOkHandler )
1878 fnOkHdl = rOkHandler;
1881 void SvxNumberFormatTabPage::FillCurrencyBox()
1883 SvStringsDtor aList;
1884 NfShCurrencyEntries rEntries;
1885 XubString* pEntry = NULL;
1886 USHORT nPos=0;
1887 USHORT nSelPos=0;
1889 pNumFmtShell->GetCurrencySymbols( aList, &nSelPos);
1891 for(USHORT i=1;i<aList.Count();i++)
1893 pEntry=aList[i];
1894 nPos=aLbCurrency.InsertEntry( *pEntry);
1896 aLbCurrency.SelectEntryPos(nSelPos);
1899 void SvxNumberFormatTabPage::SetCategory(USHORT nPos)
1901 USHORT nCurCategory = aLbCategory.GetSelectEntryPos();
1902 Point aPos=aLbFormat.GetPosPixel();
1903 Size aSize=aLbFormat.GetSizePixel();
1904 USHORT nTmpCatPos;
1906 if(bOneAreaFlag)
1908 nTmpCatPos=nFixedCategory;
1910 else
1912 nTmpCatPos=nPos;
1915 if(aLbCategory.GetEntryCount()==1 || nCurCategory!=nPos)
1917 if(nTmpCatPos!=CAT_CURRENCY)
1919 aPos.Y()=nStdFormatY;
1920 aSize.Height()=nStdFormatHeight;
1921 aLbFormat.SetPosSizePixel(aPos,aSize);
1922 aLbCurrency.Hide();
1924 else
1926 aPos.Y()=nCurFormatY;
1927 aSize.Height()=nCurFormatHeight;
1928 aLbFormat.SetPosSizePixel(aPos,aSize);
1929 aLbCurrency.Show();
1932 aLbCategory.SelectEntryPos(nPos);
1934 /* -----------------12.11.2002 14:35-----------------
1935 * to support Writer text field language handling an
1936 * additional entry needs to be inserted into the ListBox
1937 * which marks a certain language as automatically detected
1938 * Additionally the "Default" language is removed
1939 * --------------------------------------------------*/
1940 void SvxNumberFormatTabPage::AddAutomaticLanguage_Impl(LanguageType eAutoLang, BOOL bSelect)
1942 aLbLanguage.RemoveLanguage(LANGUAGE_SYSTEM);
1943 USHORT nPos = aLbLanguage.InsertEntry(sAutomaticEntry);
1944 aLbLanguage.SetEntryData(nPos, (void*)(ULONG)eAutoLang);
1945 if(bSelect)
1946 aLbLanguage.SelectEntryPos(nPos);
1949 void SvxNumberFormatTabPage::PageCreated (SfxAllItemSet aSet) //add CHINA001
1951 SFX_ITEMSET_ARG (&aSet,pNumberInfoItem,SvxNumberInfoItem,SID_ATTR_NUMBERFORMAT_INFO,sal_False);
1952 SFX_ITEMSET_ARG (&aSet,pLinkItem,SfxLinkItem,SID_LINK_TYPE,sal_False);
1953 if (pNumberInfoItem)
1954 SetNumberFormatList(*pNumberInfoItem);
1955 if (pLinkItem)
1956 SetOkHdl(pLinkItem->GetValue());