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