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/svapp.hxx>
24 #include <vcl/settings.hxx>
25 #include <i18nlangtag/lang.h>
26 #include <svx/svxids.hrc>
27 #include <svtools/colorcfg.hxx>
29 #include <numcategories.hrc>
30 #include <strings.hrc>
32 #include <svx/numinf.hxx>
35 #include <svx/numfmtsh.hxx>
36 #include <dialmgr.hxx>
37 #include <sfx2/basedlgs.hxx>
38 #include <svx/flagsdef.hxx>
40 #include <com/sun/star/lang/XServiceInfo.hpp>
43 using ::com::sun::star::uno::Reference
;
44 using ::com::sun::star::lang::XServiceInfo
;
45 using ::com::sun::star::uno::UNO_QUERY
;
47 #define NUMKEY_UNDEFINED SAL_MAX_UINT32
49 // static ----------------------------------------------------------------
51 const sal_uInt16
SvxNumberFormatTabPage::pRanges
[] =
53 SID_ATTR_NUMBERFORMAT_VALUE
,
54 SID_ATTR_NUMBERFORMAT_INFO
,
55 SID_ATTR_NUMBERFORMAT_NOLANGUAGE
,
56 SID_ATTR_NUMBERFORMAT_NOLANGUAGE
,
57 SID_ATTR_NUMBERFORMAT_ONE_AREA
,
58 SID_ATTR_NUMBERFORMAT_ONE_AREA
,
59 SID_ATTR_NUMBERFORMAT_SOURCE
,
60 SID_ATTR_NUMBERFORMAT_SOURCE
,
64 /*************************************************************************
65 #* Method: SvxNumberPreview
66 #*------------------------------------------------------------------------
68 #* Class: SvxNumberPreview
69 #* Function: Constructor of the class SvxNumberPreview
70 #* Input: Window, Resource-ID
73 #************************************************************************/
75 SvxNumberPreview::SvxNumberPreview()
81 /*************************************************************************
82 #* Method: NotifyChange
83 #*------------------------------------------------------------------------
85 #* Class: SvxNumberPreview
86 #* Function: Function for changing the preview string
87 #* Input: String, color
90 #************************************************************************/
92 void SvxNumberPreview::NotifyChange( const OUString
& rPrevStr
,
95 // detect and strip out '*' related placeholders
97 mnPos
= aPrevStr
.indexOf( 0x1B );
100 // Right during user input the star symbol is the very
101 // last character before the user enters another one.
102 if (mnPos
< aPrevStr
.getLength() - 1)
104 mnChar
= aPrevStr
[ mnPos
+ 1 ];
105 // delete placeholder and char to repeat
106 aPrevStr
= aPrevStr
.replaceAt( mnPos
, 2, "" );
110 // delete placeholder
111 aPrevStr
= aPrevStr
.replaceAt( mnPos
, 1, "" );
112 // do not attempt to draw a 0 fill character
116 svtools::ColorConfig aColorConfig
;
117 Color
aWindowTextColor( aColorConfig
.GetColorValue( svtools::FONTCOLOR
).nColor
);
118 aPrevCol
= pColor
? *pColor
: aWindowTextColor
;
122 /*************************************************************************
124 #*------------------------------------------------------------------------
126 #* Class: SvxNumberPreview
127 #* Function: Function for repainting the window.
131 #************************************************************************/
133 void SvxNumberPreview::Paint(vcl::RenderContext
& rRenderContext
, const ::tools::Rectangle
&)
135 rRenderContext
.Push(PushFlags::ALL
);
137 svtools::ColorConfig aColorConfig
;
138 rRenderContext
.SetTextColor(aColorConfig
.GetColorValue( svtools::FONTCOLOR
).nColor
);
139 const StyleSettings
& rStyleSettings
= Application::GetSettings().GetStyleSettings();
140 rRenderContext
.SetBackground(rStyleSettings
.GetWindowColor());
142 vcl::Font aDrawFont
= rRenderContext
.GetFont();
143 Size
aSzWnd(GetOutputSizePixel());
144 OUString
aTmpStr( aPrevStr
);
145 long nLeadSpace
= (aSzWnd
.Width() - rRenderContext
.GetTextWidth(aTmpStr
)) / 2;
147 aDrawFont
.SetTransparent(true);
148 aDrawFont
.SetColor(aPrevCol
);
149 rRenderContext
.SetFont(aDrawFont
);
153 long nCharWidth
= rRenderContext
.GetTextWidth(OUString(mnChar
));
155 int nNumCharsToInsert
= 0;
157 nNumCharsToInsert
= nLeadSpace
/ nCharWidth
;
159 if (nNumCharsToInsert
> 0)
161 for (int i
= 0; i
< nNumCharsToInsert
; ++i
)
162 aTmpStr
= aTmpStr
.replaceAt(mnPos
, 0, OUString(mnChar
));
167 if (mnPos
== -1 && nLeadSpace
> 0) //tdf#122120 if it won't fit anyway, then left align it
172 Point
aPosText(nX
, (aSzWnd
.Height() - GetTextHeight()) / 2);
173 rRenderContext
.DrawText(aPosText
, aTmpStr
);
174 rRenderContext
.Pop();
177 // class SvxNumberFormatTabPage ------------------------------------------
179 #define REMOVE_DONTKNOW() \
180 if (!m_xFtLanguage->get_sensitive()) \
182 m_xFtLanguage->set_sensitive(true); \
183 m_xLbLanguage->set_sensitive(true); \
184 m_xLbLanguage->set_active_id(pNumFmtShell->GetCurLanguage()); \
187 #define HDL(hdl) LINK( this, SvxNumberFormatTabPage, hdl )
189 SvxNumberFormatTabPage::SvxNumberFormatTabPage(weld::Container
* pPage
, weld::DialogController
* pController
,
190 const SfxItemSet
& rCoreAttrs
)
191 : SfxTabPage(pPage
, pController
, "cui/ui/numberingformatpage.ui", "NumberingFormatPage", &rCoreAttrs
)
192 , nInitFormat(ULONG_MAX
)
193 , bLegacyAutomaticCurrency(false)
194 , sAutomaticLangEntry(CuiResId(RID_SVXSTR_AUTO_ENTRY
))
195 , m_xFtCategory(m_xBuilder
->weld_label("categoryft"))
196 , m_xLbCategory(m_xBuilder
->weld_tree_view("categorylb"))
197 , m_xFtFormat(m_xBuilder
->weld_label("formatft"))
198 , m_xLbCurrency(m_xBuilder
->weld_combo_box("currencylb"))
199 , m_xLbFormat(m_xBuilder
->weld_tree_view("formatlb"))
200 , m_xFtLanguage(m_xBuilder
->weld_label("languageft"))
201 , m_xCbSourceFormat(m_xBuilder
->weld_check_button("sourceformat"))
202 , m_xFtOptions(m_xBuilder
->weld_label("optionsft"))
203 , m_xFtDecimals(m_xBuilder
->weld_label("decimalsft"))
204 , m_xEdDecimals(m_xBuilder
->weld_spin_button("decimalsed"))
205 , m_xFtDenominator(m_xBuilder
->weld_label("denominatorft"))
206 , m_xEdDenominator(m_xBuilder
->weld_spin_button("denominatored"))
207 , m_xBtnNegRed(m_xBuilder
->weld_check_button("negnumred"))
208 , m_xFtLeadZeroes(m_xBuilder
->weld_label("leadzerosft"))
209 , m_xEdLeadZeroes(m_xBuilder
->weld_spin_button("leadzerosed"))
210 , m_xBtnThousand(m_xBuilder
->weld_check_button("thousands"))
211 , m_xBtnEngineering(m_xBuilder
->weld_check_button("engineering"))
212 , m_xFormatCodeFrame(m_xBuilder
->weld_widget("formatcode"))
213 , m_xEdFormat(m_xBuilder
->weld_entry("formatted"))
214 , m_xIbAdd(m_xBuilder
->weld_button("add"))
215 , m_xIbInfo(m_xBuilder
->weld_button("edit"))
216 , m_xIbRemove(m_xBuilder
->weld_button("delete"))
217 , m_xFtComment(m_xBuilder
->weld_label("commentft"))
218 , m_xEdComment(m_xBuilder
->weld_entry("commented"))
219 , m_xLbLanguage(new SvxLanguageBox(m_xBuilder
->weld_combo_box("languagelb")))
220 , m_xWndPreview(new weld::CustomWeld(*m_xBuilder
, "preview", m_aWndPreview
))
222 for (size_t i
= 0; i
< SAL_N_ELEMENTS(NUM_CATEGORIES
); ++i
)
223 m_xLbCategory
->append_text(CuiResId(NUM_CATEGORIES
[i
]));
225 auto nWidth
= m_xLbCategory
->get_approximate_digit_width() * 22;
226 m_xLbCategory
->set_size_request(nWidth
, m_xLbCategory
->get_height_rows(7));
227 m_xLbFormat
->set_size_request(nWidth
, m_xLbFormat
->get_height_rows(5));
228 m_xLbCurrency
->set_size_request(nWidth
, -1); // force using (narrower) width of its LbFormat sibling
230 // Initially remove the "Automatically" entry.
231 m_xLbCurrency
->set_active(-1); // First ensure that nothing is selected.
232 sAutomaticCurrencyEntry
= m_xLbCurrency
->get_text(0);
233 m_xLbCurrency
->remove(0);
236 SetExchangeSupport(); // this page needs ExchangeSupport
240 SvxNumberFormatTabPage::~SvxNumberFormatTabPage()
242 pNumFmtShell
.reset();
244 m_xWndPreview
.reset();
245 m_xLbLanguage
.reset();
248 void SvxNumberFormatTabPage::Init_Impl()
253 m_xIbAdd
->set_sensitive(false );
254 m_xIbRemove
->set_sensitive(false );
255 m_xIbInfo
->set_sensitive(false );
257 m_xEdComment
->set_text(m_xLbCategory
->get_text(1)); // string for user defined
259 m_xEdComment
->hide();
261 m_xCbSourceFormat
->set_active( false );
262 m_xCbSourceFormat
->set_sensitive(false);
263 m_xCbSourceFormat
->hide();
265 Link
<weld::TreeView
&,void> aLink2
= LINK(this, SvxNumberFormatTabPage
, SelFormatTreeListBoxHdl_Impl
);
266 Link
<weld::ComboBox
&,void> aLink3
= LINK(this, SvxNumberFormatTabPage
, SelFormatListBoxHdl_Impl
);
267 m_xLbCategory
->connect_changed(aLink2
);
268 m_xLbCategory
->connect_focus_in(LINK(this, SvxNumberFormatTabPage
, LostFocusHdl_Impl
));
269 m_xLbFormat
->connect_changed(aLink2
);
270 m_xLbFormat
->connect_focus_in(LINK(this, SvxNumberFormatTabPage
, LostFocusHdl_Impl
));
271 m_xLbLanguage
->connect_changed(aLink3
);
272 m_xLbLanguage
->connect_focus_in(LINK(this, SvxNumberFormatTabPage
, LostFocusHdl_Impl
));
273 m_xLbCurrency
->connect_changed(aLink3
);
274 m_xLbCurrency
->connect_focus_in(LINK(this, SvxNumberFormatTabPage
, LostFocusHdl_Impl
));
275 m_xCbSourceFormat
->connect_clicked(LINK(this, SvxNumberFormatTabPage
, SelFormatClickHdl_Impl
));
276 m_xCbSourceFormat
->connect_focus_in(LINK(this, SvxNumberFormatTabPage
, LostFocusHdl_Impl
));
278 Link
<weld::SpinButton
&,void> aLink
= LINK( this, SvxNumberFormatTabPage
, OptEditHdl_Impl
);
280 m_xEdDecimals
->connect_value_changed(aLink
);
281 m_xEdDecimals
->connect_focus_in(LINK(this, SvxNumberFormatTabPage
, LostFocusHdl_Impl
));
282 m_xEdDenominator
->connect_value_changed(aLink
);
283 m_xEdDenominator
->connect_focus_in(LINK(this, SvxNumberFormatTabPage
, LostFocusHdl_Impl
));
284 m_xEdLeadZeroes
->connect_value_changed(aLink
);
285 m_xEdLeadZeroes
->connect_focus_in(LINK(this, SvxNumberFormatTabPage
, LostFocusHdl_Impl
));
287 m_xBtnNegRed
->connect_clicked(LINK(this, SvxNumberFormatTabPage
, OptClickHdl_Impl
));
288 m_xBtnNegRed
->connect_focus_in(LINK(this, SvxNumberFormatTabPage
, LostFocusHdl_Impl
));
289 m_xBtnThousand
->connect_clicked(LINK(this, SvxNumberFormatTabPage
, OptClickHdl_Impl
));
290 m_xBtnThousand
->connect_focus_in(LINK(this, SvxNumberFormatTabPage
, LostFocusHdl_Impl
));
291 m_xBtnEngineering
->connect_clicked(LINK(this, SvxNumberFormatTabPage
, OptClickHdl_Impl
));
292 m_xBtnEngineering
->connect_focus_in(LINK(this, SvxNumberFormatTabPage
, LostFocusHdl_Impl
));
293 m_xLbFormat
->connect_row_activated(HDL(DoubleClickHdl_Impl
));
294 m_xEdFormat
->connect_changed(HDL(EditModifyHdl_Impl
));
295 m_xEdFormat
->connect_focus_in(LINK(this, SvxNumberFormatTabPage
, LostFocusHdl_Impl
));
296 m_xIbAdd
->connect_clicked(HDL(ClickHdl_Impl
));
297 m_xIbAdd
->connect_focus_in(LINK(this, SvxNumberFormatTabPage
, LostFocusHdl_Impl
));
298 m_xIbRemove
->connect_clicked(HDL(ClickHdl_Impl
));
299 m_xIbRemove
->connect_focus_in(LINK(this, SvxNumberFormatTabPage
, LostFocusHdl_Impl
));
300 m_xIbInfo
->connect_clicked(HDL(ClickHdl_Impl
));
301 UpdateThousandEngineeringCheckBox();
302 UpdateDecimalsDenominatorEditBox();
304 // initialize language ListBox
306 m_xLbLanguage
->SetLanguageList( SvxLanguageListFlags::ALL
| SvxLanguageListFlags::ONLY_KNOWN
, false);
307 m_xLbLanguage
->InsertLanguage( LANGUAGE_SYSTEM
);
310 std::unique_ptr
<SfxTabPage
> SvxNumberFormatTabPage::Create( weld::Container
* pPage
, weld::DialogController
* pController
,
311 const SfxItemSet
* rAttrSet
)
313 return std::make_unique
<SvxNumberFormatTabPage
>(pPage
, pController
, *rAttrSet
);
317 /*************************************************************************
319 #*------------------------------------------------------------------------
321 #* Class: SvxNumberFormatTabPage
322 #* Function: The dialog's attributes are reset
323 #* using the Itemset.
327 #************************************************************************/
329 void SvxNumberFormatTabPage::set_active_currency(sal_Int32 nPos
)
331 static_assert(SELPOS_NONE
== -1, "SELPOS_NONE was -1 at time of writing");
332 if (nPos
== 0 && !bLegacyAutomaticCurrency
)
334 // Insert "Automatically" if currently used so it is selectable.
335 m_xLbCurrency
->insert_text(0, sAutomaticCurrencyEntry
);
336 bLegacyAutomaticCurrency
= true;
338 if (nPos
!= -1 && !bLegacyAutomaticCurrency
)
340 m_xLbCurrency
->set_active(nPos
);
343 sal_uInt32
SvxNumberFormatTabPage::get_active_currency() const
345 static_assert(SELPOS_NONE
== -1, "SELPOS_NONE was -1 at time of writing");
346 sal_Int32 nCurrencyPos
= m_xLbCurrency
->get_active();
347 if (nCurrencyPos
!= -1 && !bLegacyAutomaticCurrency
)
352 void SvxNumberFormatTabPage::Reset( const SfxItemSet
* rSet
)
354 const SfxUInt32Item
* pValFmtAttr
= nullptr;
355 const SfxPoolItem
* pItem
= nullptr;
356 const SfxBoolItem
* pAutoEntryAttr
= nullptr;
358 sal_uInt16 nCatLbSelPos
= 0;
359 sal_uInt16 nFmtLbSelPos
= 0;
360 LanguageType eLangType
= LANGUAGE_DONTKNOW
;
361 std::vector
<OUString
> aFmtEntryList
;
362 SvxNumberValueType eValType
= SvxNumberValueType::Undefined
;
363 double nValDouble
= 0;
366 SfxItemState eState
= rSet
->GetItemState( GetWhich( SID_ATTR_NUMBERFORMAT_NOLANGUAGE
),true,&pItem
);
368 if(eState
==SfxItemState::SET
)
370 const SfxBoolItem
* pBoolLangItem
= static_cast<const SfxBoolItem
*>(
371 GetItem( *rSet
, SID_ATTR_NUMBERFORMAT_NOLANGUAGE
));
373 if(pBoolLangItem
!=nullptr && pBoolLangItem
->GetValue())
384 eState
= rSet
->GetItemState( GetWhich( SID_ATTR_NUMBERFORMAT_INFO
),true,&pItem
);
386 if(eState
==SfxItemState::SET
)
388 if(pNumItem
==nullptr)
391 pNumItem
.reset( static_cast<SvxNumberInfoItem
*>(pItem
->Clone()) );
404 eState
= rSet
->GetItemState( GetWhich( SID_ATTR_NUMBERFORMAT_ONE_AREA
));
406 if(eState
==SfxItemState::SET
)
408 const SfxBoolItem
* pBoolItem
= static_cast<const SfxBoolItem
*>(
409 GetItem( *rSet
, SID_ATTR_NUMBERFORMAT_ONE_AREA
));
411 if(pBoolItem
!=nullptr)
413 bOneAreaFlag
= pBoolItem
->GetValue();
417 eState
= rSet
->GetItemState( GetWhich( SID_ATTR_NUMBERFORMAT_SOURCE
) );
419 if ( eState
== SfxItemState::SET
)
421 const SfxBoolItem
* pBoolItem
= static_cast<const SfxBoolItem
*>(
422 GetItem( *rSet
, SID_ATTR_NUMBERFORMAT_SOURCE
));
424 m_xCbSourceFormat
->set_active(pBoolItem
->GetValue());
426 m_xCbSourceFormat
->set_active( false );
427 m_xCbSourceFormat
->set_sensitive(true);
428 m_xCbSourceFormat
->show();
432 bool bInit
= false; // set to sal_True for debug test
433 m_xCbSourceFormat
->set_active( bInit
);
434 m_xCbSourceFormat
->set_sensitive( bInit
);
435 m_xCbSourceFormat
->set_visible( bInit
);
438 // pNumItem must have been set from outside!
439 DBG_ASSERT( pNumItem
, "No NumberInfo, no NumberFormatter, goodbye. CRASH. :-(" );
441 eState
= rSet
->GetItemState( GetWhich( SID_ATTR_NUMBERFORMAT_VALUE
) );
443 if ( SfxItemState::DONTCARE
!= eState
)
444 pValFmtAttr
= GetItem( *rSet
, SID_ATTR_NUMBERFORMAT_VALUE
);
446 eValType
= pNumItem
->GetValueType();
450 case SvxNumberValueType::String
:
451 aValString
= pNumItem
->GetValueString();
453 case SvxNumberValueType::Number
:
454 // #50441# string may be set in addition to the value
455 aValString
= pNumItem
->GetValueString();
456 nValDouble
= pNumItem
->GetValueDouble();
458 case SvxNumberValueType::Undefined
:
463 pNumFmtShell
.reset(); // delete old shell if applicable (== reset)
465 nInitFormat
= pValFmtAttr
// memorize init key
466 ? pValFmtAttr
->GetValue() // (for FillItemSet())
467 : ULONG_MAX
; // == DONT_KNOW
470 if ( eValType
== SvxNumberValueType::String
)
471 pNumFmtShell
.reset( SvxNumberFormatShell::Create(
472 pNumItem
->GetNumberFormatter(),
473 pValFmtAttr
? nInitFormat
: 0,
477 pNumFmtShell
.reset( SvxNumberFormatShell::Create(
478 pNumItem
->GetNumberFormatter(),
479 pValFmtAttr
? nInitFormat
: 0,
485 bool bUseStarFormat
= false;
486 SfxObjectShell
* pDocSh
= SfxObjectShell::Current();
489 // is this a calc document
490 Reference
< XServiceInfo
> xSI( pDocSh
->GetModel(), UNO_QUERY
);
492 bUseStarFormat
= xSI
->supportsService("com.sun.star.sheet.SpreadsheetDocument");
494 pNumFmtShell
->SetUseStarFormat( bUseStarFormat
);
498 OUString aPrevString
;
499 Color
* pDummy
= nullptr;
500 pNumFmtShell
->GetInitSettings( nCatLbSelPos
, eLangType
, nFmtLbSelPos
,
501 aFmtEntryList
, aPrevString
, pDummy
);
503 if (nCatLbSelPos
==CAT_CURRENCY
)
504 set_active_currency(pNumFmtShell
->GetCurrencySymbol());
506 nFixedCategory
=nCatLbSelPos
;
509 OUString sFixedCategory
= m_xLbCategory
->get_text(nFixedCategory
);
510 m_xLbCategory
->clear();
511 m_xLbCategory
->append_text(sFixedCategory
);
516 SetCategory(nCatLbSelPos
);
518 eState
= rSet
->GetItemState( GetWhich( SID_ATTR_NUMBERFORMAT_ADD_AUTO
) );
519 if(SfxItemState::SET
== eState
)
520 pAutoEntryAttr
= static_cast<const SfxBoolItem
*>(
521 GetItem( *rSet
, SID_ATTR_NUMBERFORMAT_ADD_AUTO
));
522 // no_NO is an alias for nb_NO and normally isn't listed, we need it for
523 // backwards compatibility, but only if the format passed is of
524 // LanguageType no_NO.
525 if ( eLangType
== LANGUAGE_NORWEGIAN
)
527 m_xLbLanguage
->remove_id(eLangType
); // in case we're already called
528 m_xLbLanguage
->InsertLanguage( eLangType
);
530 m_xLbLanguage
->set_active_id(eLangType
);
532 AddAutomaticLanguage_Impl(eLangType
, pAutoEntryAttr
->GetValue());
533 UpdateFormatListBox_Impl(false,true);
535 //! This spoils everything because it rematches currency formats based on
536 //! the selected m_xLbCurrency entry instead of the current format.
537 //! Besides that everything seems to be initialized by now, so why call it?
538 // SelFormatHdl_Impl(m_xLbCategory.get());
542 EditHdl_Impl(m_xEdFormat
.get()); // UpdateOptions_Impl() as a side effect
546 // everything disabled except direct input or changing the category
550 if ( m_xCbSourceFormat
->get_active() )
552 // everything disabled except SourceFormat checkbox
553 EnableBySourceFormat_Impl();
557 /*************************************************************************
558 #* Method: Obstructing
559 #*------------------------------------------------------------------------
561 #* Class: SvxNumberFormatTabPage
562 #* Function: Disable the controls except from changing the category
567 #************************************************************************/
568 void SvxNumberFormatTabPage::Obstructing()
570 m_xLbFormat
->select(-1);
571 m_xLbLanguage
->set_active(-1);
572 m_xFtLanguage
->set_sensitive(false);
573 m_xLbLanguage
->set_sensitive(false);
575 m_xIbAdd
->set_sensitive(false );
576 m_xIbRemove
->set_sensitive(false );
577 m_xIbInfo
->set_sensitive(false );
579 m_xBtnNegRed
->set_sensitive(false);
580 m_xBtnThousand
->set_sensitive(false);
581 m_xBtnEngineering
->set_sensitive(false);
582 m_xFtLeadZeroes
->set_sensitive(false);
583 m_xFtDecimals
->set_sensitive(false);
584 m_xFtDenominator
->set_sensitive(false);
585 m_xEdLeadZeroes
->set_sensitive(false);
586 m_xEdDecimals
->set_sensitive(false);
587 m_xEdDenominator
->set_sensitive(false);
588 m_xFtOptions
->set_sensitive(false);
589 m_xEdDecimals
->set_text( OUString() );
590 m_xEdLeadZeroes
->set_text( OUString() );
591 m_xBtnNegRed
->set_active( false );
592 m_xBtnThousand
->set_active( false );
593 m_xBtnEngineering
->set_active( false );
594 m_aWndPreview
.NotifyChange( OUString() );
596 m_xLbCategory
->select(0);
597 m_xEdFormat
->set_text( OUString() );
598 m_xFtComment
->set_label( OUString() );
599 m_xEdComment
->set_text(m_xLbCategory
->get_text(1)); // string for user defined
601 m_xEdFormat
->grab_focus();
605 /*************************************************************************
606 #* Enable/Disable dialog parts depending on the value of the SourceFormat
608 #************************************************************************/
609 void SvxNumberFormatTabPage::EnableBySourceFormat_Impl()
611 bool bEnable
= !m_xCbSourceFormat
->get_active();
613 m_xCbSourceFormat
->grab_focus();
614 m_xFtCategory
->set_sensitive( bEnable
);
615 m_xLbCategory
->set_sensitive( bEnable
);
616 m_xFtFormat
->set_sensitive( bEnable
);
617 m_xLbCurrency
->set_sensitive( bEnable
);
618 m_xLbFormat
->set_sensitive( bEnable
);
619 m_xFtLanguage
->set_sensitive( bEnable
);
620 m_xLbLanguage
->set_sensitive( bEnable
);
621 m_xFtDecimals
->set_sensitive( bEnable
);
622 m_xEdDecimals
->set_sensitive( bEnable
);
623 m_xFtDenominator
->set_sensitive( bEnable
);
624 m_xEdDenominator
->set_sensitive( bEnable
);
625 m_xFtLeadZeroes
->set_sensitive( bEnable
);
626 m_xEdLeadZeroes
->set_sensitive( bEnable
);
627 m_xBtnNegRed
->set_sensitive( bEnable
);
628 m_xBtnThousand
->set_sensitive( bEnable
);
629 m_xBtnEngineering
->set_sensitive( bEnable
);
630 m_xFtOptions
->set_sensitive( bEnable
);
631 m_xFormatCodeFrame
->set_sensitive( bEnable
);
635 /*************************************************************************
636 #* Method: HideLanguage
637 #*------------------------------------------------------------------------
639 #* Class: SvxNumberFormatTabPage
640 #* Function: Hides the language settings:
641 #* Input: sal_Bool nFlag
644 #************************************************************************/
646 void SvxNumberFormatTabPage::HideLanguage(bool bFlag
)
648 m_xFtLanguage
->set_visible(!bFlag
);
649 m_xLbLanguage
->set_visible(!bFlag
);
652 /*************************************************************************
653 #* Method: FillItemSet
654 #*------------------------------------------------------------------------
656 #* Class: SvxNumberFormatTabPage
657 #* Function: Adjusts the attributes in the ItemSet,
658 #* and - if bNumItemFlag is not set - the
659 #* numItem in the DocShell.
663 #************************************************************************/
665 bool SvxNumberFormatTabPage::FillItemSet( SfxItemSet
* rCoreAttrs
)
667 bool bDataChanged
= m_xFtLanguage
->get_sensitive() || m_xCbSourceFormat
->get_sensitive();
670 const SfxItemSet
& rMyItemSet
= GetItemSet();
671 sal_uInt16 nWhich
= GetWhich( SID_ATTR_NUMBERFORMAT_VALUE
);
672 SfxItemState eItemState
= rMyItemSet
.GetItemState( nWhich
, false );
674 // OK chosen - Is format code input entered already taken over?
675 // If not, simulate Add. Upon syntax error ignore input and prevent Put.
676 OUString aFormat
= m_xEdFormat
->get_text();
677 sal_uInt32 nCurKey
= pNumFmtShell
->GetCurNumFmtKey();
679 if ( m_xIbAdd
->get_sensitive() || pNumFmtShell
->IsTmpCurrencyFormat(aFormat
) )
680 { // #79599# It is not sufficient to just add the format code (or
681 // delete it in case of bOneAreaFlag and resulting category change).
682 // Upon switching tab pages we need all settings to be consistent
683 // in case this page will be redisplayed later.
684 bDataChanged
= Click_Impl(*m_xIbAdd
);
685 nCurKey
= pNumFmtShell
->GetCurNumFmtKey();
687 else if(nCurKey
== NUMKEY_UNDEFINED
)
688 { // something went wrong, e.g. in Writer #70281#
689 pNumFmtShell
->FindEntry(aFormat
, &nCurKey
);
697 bDataChanged
= ( nInitFormat
!= nCurKey
);
701 rCoreAttrs
->Put( SfxUInt32Item( nWhich
, nCurKey
) );
703 else if(SfxItemState::DEFAULT
== eItemState
)
705 rCoreAttrs
->ClearItem( nWhich
);
710 // List of changed user defined formats:
712 std::vector
<sal_uInt32
> const & aDelFormats
= pNumFmtShell
->GetUpdateData();
714 if ( !aDelFormats
.empty() )
717 pNumItem
->SetDelFormats( aDelFormats
);
721 rCoreAttrs
->Put( *pNumItem
);
725 SfxObjectShell
* pDocSh
= SfxObjectShell::Current();
727 DBG_ASSERT( pDocSh
, "DocShell not found!" );
731 pDocSh
->PutItem( *pNumItem
);
736 // Whether source format is to be taken or not:
738 if ( m_xCbSourceFormat
->get_sensitive() )
740 sal_uInt16 _nWhich
= GetWhich( SID_ATTR_NUMBERFORMAT_SOURCE
);
741 SfxItemState _eItemState
= rMyItemSet
.GetItemState( _nWhich
, false );
742 const SfxBoolItem
* pBoolItem
= static_cast<const SfxBoolItem
*>(
743 GetItem( rMyItemSet
, SID_ATTR_NUMBERFORMAT_SOURCE
));
744 bool bOld
= pBoolItem
&& pBoolItem
->GetValue();
745 rCoreAttrs
->Put( SfxBoolItem( _nWhich
, m_xCbSourceFormat
->get_active() ) );
747 bDataChanged
= (bOld
!= m_xCbSourceFormat
->get_active() ||
748 _eItemState
!= SfxItemState::SET
);
751 // FillItemSet is only called on OK, here we can notify the
752 // NumberFormatShell that all new user defined formats are valid.
753 pNumFmtShell
->ValidateNewEntries();
754 if(m_xLbLanguage
->get_visible() &&
755 m_xLbLanguage
->find_text(sAutomaticLangEntry
) != -1)
756 rCoreAttrs
->Put(SfxBoolItem(SID_ATTR_NUMBERFORMAT_ADD_AUTO
,
757 m_xLbLanguage
->get_active_text() == sAutomaticLangEntry
));
764 DeactivateRC
SvxNumberFormatTabPage::DeactivatePage( SfxItemSet
* _pSet
)
767 FillItemSet( _pSet
);
768 return DeactivateRC::LeavePage
;
771 void SvxNumberFormatTabPage::FillFormatListBox_Impl( std::vector
<OUString
>& rEntries
)
778 m_xLbFormat
->clear();
779 if (rEntries
.empty())
782 m_xLbFormat
->freeze();
786 nTmpCatPos
=nFixedCategory
;
790 nTmpCatPos
=m_xLbCategory
->get_selected_index();
797 case CAT_NUMBER
: i
=1;
799 if (nTmpCatPos
== CAT_TEXT
)
802 aTmpString
= pNumFmtShell
->GetStandardName();
803 m_xLbFormat
->append_text(aTmpString
);
809 if(pNumFmtShell
!=nullptr)
811 for ( ; i
< rEntries
.size(); ++i
)
813 aEntry
= rEntries
[i
];
814 short aPrivCat
= pNumFmtShell
->GetCategory4Entry( static_cast<short>(i
) );
815 if(aPrivCat
!=CAT_TEXT
)
817 Color
* pPreviewColor
= nullptr;
818 OUString
aPreviewString( GetExpColorString( pPreviewColor
, aEntry
, aPrivCat
) );
819 m_xLbFormat
->append_text(aPreviewString
);
821 m_xLbFormat
->set_font_color(m_xLbFormat
->n_children() - 1, *pPreviewColor
);
825 m_xLbFormat
->append_text(aEntry
);
833 /*************************************************************************
834 #* Method: UpdateOptions_Impl
835 #*------------------------------------------------------------------------
837 #* Class: SvxNumberFormatTabPage
838 #* Function: Adjusts the options attributes
839 #* depending on the selected format.
840 #* Input: Flag, whether the category has changed.
843 #************************************************************************/
845 void SvxNumberFormatTabPage::UpdateOptions_Impl( bool bCheckCatChange
/*= sal_False*/ )
847 OUString theFormat
= m_xEdFormat
->get_text();
848 sal_Int32 nCurCategory
= m_xLbCategory
->get_selected_index();
849 sal_uInt16 nCategory
= static_cast<sal_uInt16
>(nCurCategory
);
850 sal_uInt16 nDecimals
= 0;
851 sal_uInt16 nZeroes
= 0;
852 bool bNegRed
= false;
853 bool bThousand
= false;
854 sal_Int32 nCurrencyPos
= get_active_currency();
857 nCurCategory
=nFixedCategory
;
860 pNumFmtShell
->GetOptions( theFormat
,
865 if(nCategory
==CAT_CURRENCY
)
867 sal_uInt16 nTstPos
=pNumFmtShell
->FindCurrencyFormat(theFormat
);
868 if(nCurrencyPos
!=static_cast<sal_Int32
>(nTstPos
) && nTstPos
!=sal_uInt16(-1))
870 set_active_currency(nTstPos
);
871 pNumFmtShell
->SetCurrencySymbol(nTstPos
);
876 if ( nCategory
!= nCurCategory
|| bDoIt
)
878 if ( bCheckCatChange
)
883 SetCategory(nCategory
);
885 UpdateFormatListBox_Impl( true, false );
888 else if ( m_xLbFormat
->n_children() > 0 )
890 sal_uInt32 nCurEntryKey
=NUMKEY_UNDEFINED
;
891 if(!pNumFmtShell
->FindEntry( m_xEdFormat
->get_text(),&nCurEntryKey
))
893 m_xLbFormat
->select(-1);
898 nCategory
=nFixedCategory
;
901 UpdateThousandEngineeringCheckBox();
902 UpdateDecimalsDenominatorEditBox();
905 case CAT_SCIENTIFIC
: // bThousand is for Engineering notation
907 sal_uInt16 nIntDigits
= pNumFmtShell
->GetFormatIntegerDigits(theFormat
);
908 bThousand
= (nIntDigits
> 0) && (nIntDigits
% 3 == 0);
909 m_xBtnEngineering
->set_sensitive(true);
910 m_xBtnEngineering
->set_active( bThousand
);
917 m_xFtOptions
->set_sensitive(true);
918 if ( nCategory
== CAT_FRACTION
)
920 m_xFtDenominator
->set_sensitive(true);
921 m_xEdDenominator
->set_sensitive(true);
925 m_xFtDecimals
->set_sensitive(true);
926 m_xEdDecimals
->set_sensitive(true);
928 m_xFtLeadZeroes
->set_sensitive(true);
929 m_xEdLeadZeroes
->set_sensitive(true);
930 m_xBtnNegRed
->set_sensitive(true);
931 if ( nCategory
== CAT_NUMBER
&& m_xLbFormat
->get_selected_index() == 0 )
932 m_xEdDecimals
->set_text( "" ); //General format tdf#44399
934 if ( nCategory
== CAT_FRACTION
)
935 m_xEdDenominator
->set_value( nDecimals
);
937 m_xEdDecimals
->set_value( nDecimals
);
938 m_xEdLeadZeroes
->set_value( nZeroes
);
939 m_xBtnNegRed
->set_active( bNegRed
);
940 if ( nCategory
!= CAT_SCIENTIFIC
)
942 m_xBtnThousand
->set_sensitive(true);
943 m_xBtnThousand
->set_active( bThousand
);
948 case CAT_USERDEFINED
:
954 m_xFtOptions
->set_sensitive(false);
955 m_xFtDecimals
->set_sensitive(false);
956 m_xEdDecimals
->set_sensitive(false);
957 m_xFtDenominator
->set_sensitive(false);
958 m_xEdDenominator
->set_sensitive(false);
959 m_xFtLeadZeroes
->set_sensitive(false);
960 m_xEdLeadZeroes
->set_sensitive(false);
961 m_xBtnNegRed
->set_sensitive(false);
962 m_xBtnThousand
->set_sensitive(false);
963 m_xBtnEngineering
->set_sensitive(false);
964 m_xEdDecimals
->set_text( OUString() );
965 m_xEdLeadZeroes
->set_text( OUString() );
966 m_xBtnNegRed
->set_active( false );
967 m_xBtnThousand
->set_active( false );
968 m_xBtnEngineering
->set_active( false );
973 /*************************************************************************
974 #* Method: UpdateFormatListBox_Impl
975 #*------------------------------------------------------------------------
977 #* Class: SvxNumberFormatTabPage
978 #* Function: Updates the format listbox and additionally the
979 #* string in the editbox is changed depending on
980 #* the bUpdateEdit flag.
981 #* Input: Flags for category and editbox.
984 #************************************************************************/
986 void SvxNumberFormatTabPage::UpdateFormatListBox_Impl
988 bool bCat
, // Category or country/language ListBox?
992 std::vector
<OUString
> aEntryList
;
993 short nFmtLbSelPos
= 0;
998 nTmpCatPos
=nFixedCategory
;
1002 nTmpCatPos
=m_xLbCategory
->get_selected_index();
1008 if(nTmpCatPos
!=CAT_CURRENCY
)
1009 m_xLbCurrency
->hide();
1011 m_xLbCurrency
->show();
1013 pNumFmtShell
->CategoryChanged(nTmpCatPos
,nFmtLbSelPos
, aEntryList
);
1016 pNumFmtShell
->LanguageChanged(m_xLbLanguage
->get_active_id(),
1017 nFmtLbSelPos
,aEntryList
);
1019 REMOVE_DONTKNOW() // possibly UI-Enable
1022 if ( (!aEntryList
.empty()) && (nFmtLbSelPos
!= SELPOS_NONE
) )
1026 OUString aFormat
=aEntryList
[nFmtLbSelPos
];
1027 m_xEdFormat
->set_text(aFormat
);
1028 m_xFtComment
->set_label(pNumFmtShell
->GetComment4Entry(nFmtLbSelPos
));
1031 if(!bOneAreaFlag
|| !bCat
)
1033 FillFormatListBox_Impl( aEntryList
);
1034 m_xLbFormat
->select(nFmtLbSelPos
);
1036 m_xFtComment
->set_label(pNumFmtShell
->GetComment4Entry(nFmtLbSelPos
));
1037 if(pNumFmtShell
->GetUserDefined4Entry(nFmtLbSelPos
))
1039 if(pNumFmtShell
->GetComment4Entry(nFmtLbSelPos
).isEmpty())
1041 m_xFtComment
->set_label(m_xLbCategory
->get_text(1));
1044 ChangePreviewText( static_cast<sal_uInt16
>(nFmtLbSelPos
) );
1050 FillFormatListBox_Impl( aEntryList
);
1051 if(nFmtLbSelPos
!= SELPOS_NONE
)
1053 m_xLbFormat
->select(static_cast<sal_uInt16
>(nFmtLbSelPos
));
1055 m_xFtComment
->set_label(pNumFmtShell
->GetComment4Entry(nFmtLbSelPos
));
1056 if(pNumFmtShell
->GetUserDefined4Entry(nFmtLbSelPos
))
1058 if(pNumFmtShell
->GetComment4Entry(nFmtLbSelPos
).isEmpty())
1060 m_xFtComment
->set_label(m_xLbCategory
->get_text(1));
1066 m_xLbFormat
->select(-1);
1071 m_xEdFormat
->set_text( OUString() );
1072 m_aWndPreview
.NotifyChange( OUString() );
1081 * Change visible checkbox according to category format
1082 * if scientific format "Engineering notation"
1083 * else "Thousands separator"
1086 void SvxNumberFormatTabPage::UpdateThousandEngineeringCheckBox()
1088 bool bIsScientific
= m_xLbCategory
->get_selected_index() == CAT_SCIENTIFIC
;
1089 m_xBtnThousand
->set_visible( !bIsScientific
);
1090 m_xBtnEngineering
->set_visible( bIsScientific
);
1095 * Change visible Edit box and Fixed text according to category format
1096 * if fraction format "Denominator places"
1097 * else "Decimal places"
1100 void SvxNumberFormatTabPage::UpdateDecimalsDenominatorEditBox()
1102 bool bIsFraction
= m_xLbCategory
->get_selected_index() == CAT_FRACTION
;
1103 m_xFtDecimals
->set_visible( !bIsFraction
);
1104 m_xEdDecimals
->set_visible( !bIsFraction
);
1105 m_xFtDenominator
->set_visible( bIsFraction
);
1106 m_xEdDenominator
->set_visible( bIsFraction
);
1110 /*************************************************************************
1111 #* Handle: DoubleClickHdl_Impl
1112 #*------------------------------------------------------------------------
1114 #* Class: SvxNumberFormatTabPage
1115 #* Function: On a double click in the format listbox the
1116 #* value is adopted and the OK button pushed.
1117 #* Input: Pointer on the Listbox
1120 #************************************************************************/
1121 IMPL_LINK(SvxNumberFormatTabPage
, DoubleClickHdl_Impl
, weld::TreeView
&, rLb
, bool)
1123 SelFormatHdl_Impl(&rLb
);
1125 SfxOkDialogController
* pController
= GetDialogController();
1126 assert(pController
);
1127 weld::Button
& rOkButton
= pController
->GetOKButton();
1128 rOkButton
.clicked();
1133 /*************************************************************************
1134 #* Method: SelFormatHdl_Impl
1135 #*------------------------------------------------------------------------
1137 #* Class: SvxNumberFormatTabPage
1138 #* Function: Is called when the language, the category or the format
1139 #* is changed. Accordingly the settings are adjusted.
1140 #* Input: Pointer on the Listbox
1143 #************************************************************************/
1145 IMPL_LINK(SvxNumberFormatTabPage
, SelFormatClickHdl_Impl
, weld::Button
&, rLb
, void)
1147 SelFormatHdl_Impl(&rLb
);
1150 IMPL_LINK(SvxNumberFormatTabPage
, SelFormatTreeListBoxHdl_Impl
, weld::TreeView
&, rLb
, void)
1152 SelFormatHdl_Impl(&rLb
);
1155 IMPL_LINK(SvxNumberFormatTabPage
, SelFormatListBoxHdl_Impl
, weld::ComboBox
&, rLb
, void)
1157 SelFormatHdl_Impl(&rLb
);
1160 void SvxNumberFormatTabPage::SelFormatHdl_Impl(weld::Widget
* pLb
)
1162 if (pLb
== m_xCbSourceFormat
.get())
1164 EnableBySourceFormat_Impl(); // enable/disable everything else
1165 if ( m_xCbSourceFormat
->get_active() )
1166 return; // just disabled everything else
1168 // Reinit options enable/disable for current selection.
1170 // Current category may be UserDefined with no format entries defined.
1171 if (m_xLbFormat
->get_selected_index() == -1)
1172 pLb
= m_xLbCategory
.get(); // continue with the current category selected
1174 pLb
= m_xLbFormat
.get(); // continue with the current format selected
1177 sal_Int32 nTmpCatPos
;
1181 nTmpCatPos
=nFixedCategory
;
1185 nTmpCatPos
=m_xLbCategory
->get_selected_index();
1188 if (nTmpCatPos
==CAT_CURRENCY
&& pLb
== m_xLbCurrency
.get())
1189 pNumFmtShell
->SetCurrencySymbol(get_active_currency());
1191 // Format-ListBox ----------------------------------------------------
1192 if (pLb
== m_xLbFormat
.get())
1194 sal_uLong nSelPos
= m_xLbFormat
->get_selected_index();
1195 short nFmtLbSelPos
= static_cast<short>(nSelPos
);
1197 OUString aFormat
= pNumFmtShell
->GetFormat4Entry(nFmtLbSelPos
);
1198 OUString aComment
= pNumFmtShell
->GetComment4Entry(nFmtLbSelPos
);
1200 if(pNumFmtShell
->GetUserDefined4Entry(nFmtLbSelPos
))
1202 if(aComment
.isEmpty())
1204 aComment
= m_xLbCategory
->get_text(1);
1208 if ( !aFormat
.isEmpty() )
1210 if (!m_xEdFormat
->has_focus())
1211 m_xEdFormat
->set_text( aFormat
);
1212 m_xFtComment
->set_label(aComment
);
1213 ChangePreviewText( static_cast<sal_uInt16
>(nSelPos
) );
1216 REMOVE_DONTKNOW() // possibly UI-Enable
1218 if ( pNumFmtShell
->FindEntry( aFormat
) )
1220 m_xIbAdd
->set_sensitive(false );
1221 bool bIsUserDef
=pNumFmtShell
->IsUserDefined( aFormat
);
1222 m_xIbRemove
->set_sensitive(bIsUserDef
);
1223 m_xIbInfo
->set_sensitive(bIsUserDef
);
1228 m_xIbAdd
->set_sensitive(true);
1229 m_xIbInfo
->set_sensitive(true);
1230 m_xIbRemove
->set_sensitive(false );
1231 m_xFtComment
->set_label(m_xEdComment
->get_text());
1234 UpdateOptions_Impl( false );
1240 // category-ListBox -------------------------------------------------
1241 if (pLb
== m_xLbCategory
.get() || pLb
== m_xLbCurrency
.get())
1243 UpdateFormatListBox_Impl( true, true );
1244 EditHdl_Impl( nullptr );
1245 UpdateOptions_Impl( false );
1251 // language/country-ListBox ----------------------------------------------
1252 if (pLb
== m_xLbLanguage
->get_widget())
1254 UpdateFormatListBox_Impl( false, true );
1255 EditHdl_Impl(m_xEdFormat
.get());
1262 /*************************************************************************
1263 #* Method: ClickHdl_Impl, weld::Button& rIB
1264 #*------------------------------------------------------------------------
1266 #* Class: SvxNumberFormatTabPage
1267 #* Function: Called when the add or delete button is pushed,
1268 #* adjusts the number format list.
1269 #* Input: Toolbox- Button
1272 #************************************************************************/
1274 IMPL_LINK( SvxNumberFormatTabPage
, ClickHdl_Impl
, weld::Button
&, rIB
, void)
1279 bool SvxNumberFormatTabPage::Click_Impl(weld::Button
& rIB
)
1281 sal_uLong nReturn
= 0;
1282 const sal_uLong nReturnChanged
= 0x1; // THE boolean return value
1283 const sal_uLong nReturnAdded
= 0x2; // temp: format added
1284 const sal_uLong nReturnOneArea
= 0x4; // temp: one area but category changed => ignored
1286 if (&rIB
== m_xIbAdd
.get())
1287 { // Also called from FillItemSet() if a temporary currency format has
1288 // to be added, not only if the Add button is enabled.
1289 OUString aFormat
= m_xEdFormat
->get_text();
1290 std::vector
<OUString
> aEntryList
;
1291 std::vector
<OUString
> a2EntryList
;
1292 sal_uInt16 nCatLbSelPos
= 0;
1293 short nFmtLbSelPos
= SELPOS_NONE
;
1294 sal_Int32 nErrPos
=0;
1296 pNumFmtShell
->SetCurCurrencyEntry(nullptr);
1297 bool bAdded
= pNumFmtShell
->AddFormat( aFormat
, nErrPos
,
1298 nCatLbSelPos
, nFmtLbSelPos
,
1301 nReturn
|= nReturnChanged
| nReturnAdded
;
1303 if (m_xEdComment
->get_visible())
1305 m_xEdFormat
->grab_focus();
1306 m_xEdComment
->hide();
1307 m_xFtComment
->show();
1308 m_xFtComment
->set_label(m_xEdComment
->get_text());
1311 if ( !nErrPos
) // Syntax ok?
1313 // May be sorted under a different locale if LCID was parsed.
1315 m_xLbLanguage
->set_active_id(pNumFmtShell
->GetCurLanguage());
1317 if (nCatLbSelPos
==CAT_CURRENCY
)
1318 set_active_currency(pNumFmtShell
->GetCurrencySymbol());
1320 if(bOneAreaFlag
&& (nFixedCategory
!=nCatLbSelPos
))
1322 if(bAdded
) aEntryList
.clear();
1323 pNumFmtShell
->RemoveFormat( aFormat
,
1327 a2EntryList
.clear();
1328 m_xEdFormat
->grab_focus();
1329 m_xEdFormat
->select_region(0, -1);
1330 nReturn
|= nReturnOneArea
;
1334 if ( bAdded
&& (nFmtLbSelPos
!= SELPOS_NONE
) )
1336 // everything all right
1337 if(bOneAreaFlag
) //@@ ???
1340 SetCategory(nCatLbSelPos
);
1342 FillFormatListBox_Impl( aEntryList
);
1343 if (m_xEdComment
->get_text()!=m_xLbCategory
->get_text(1))
1345 pNumFmtShell
->SetComment4Entry(nFmtLbSelPos
,
1346 m_xEdComment
->get_text());
1350 pNumFmtShell
->SetComment4Entry(nFmtLbSelPos
,
1353 m_xLbFormat
->select(static_cast<sal_uInt16
>(nFmtLbSelPos
));
1354 m_xEdFormat
->set_text( aFormat
);
1356 m_xEdComment
->set_text(m_xLbCategory
->get_text(1)); // String for user defined
1358 ChangePreviewText( static_cast<sal_uInt16
>(nFmtLbSelPos
) );
1362 else // syntax error
1364 m_xEdFormat
->grab_focus();
1365 m_xEdFormat
->select_region(nErrPos
== -1 ? m_xEdFormat
->get_text().getLength() : nErrPos
, -1);
1367 EditHdl_Impl(m_xEdFormat
.get());
1368 nReturn
= ((nReturn
& nReturnOneArea
) ? 0 : (nReturn
& nReturnChanged
));
1371 a2EntryList
.clear();
1373 else if (&rIB
== m_xIbRemove
.get())
1375 OUString aFormat
= m_xEdFormat
->get_text();
1376 std::vector
<OUString
> aEntryList
;
1377 sal_uInt16 nCatLbSelPos
= 0;
1378 short nFmtLbSelPos
= SELPOS_NONE
;
1380 pNumFmtShell
->RemoveFormat( aFormat
,
1385 m_xEdComment
->set_text(m_xLbCategory
->get_text(1));
1387 if( nFmtLbSelPos
>=0 && static_cast<size_t>(nFmtLbSelPos
)<aEntryList
.size() )
1389 aFormat
= aEntryList
[nFmtLbSelPos
];
1392 FillFormatListBox_Impl( aEntryList
);
1394 if ( nFmtLbSelPos
!= SELPOS_NONE
)
1396 if(bOneAreaFlag
) //@@ ???
1399 SetCategory(nCatLbSelPos
);
1401 m_xLbFormat
->select(static_cast<sal_uInt16
>(nFmtLbSelPos
));
1402 m_xEdFormat
->set_text( aFormat
);
1403 ChangePreviewText( static_cast<sal_uInt16
>(nFmtLbSelPos
) );
1407 // set to "all/standard"
1409 SelFormatHdl_Impl(m_xLbCategory
.get());
1412 EditHdl_Impl(m_xEdFormat
.get());
1416 else if (&rIB
== m_xIbInfo
.get())
1418 if (!m_xEdComment
->get_visible())
1420 m_xEdComment
->set_text(m_xFtComment
->get_label());
1421 m_xEdComment
->show();
1422 m_xFtComment
->hide();
1423 m_xEdComment
->grab_focus();
1427 m_xEdFormat
->grab_focus();
1428 m_xEdComment
->hide();
1429 m_xFtComment
->show();
1437 /*************************************************************************
1438 #* Method: EditHdl_Impl
1439 #*------------------------------------------------------------------------
1441 #* Class: SvxNumberFormatTabPage
1442 #* Function: When the entry in the edit field is changed
1443 #* the preview is updated and
1444 #* Input: Pointer on Editbox
1447 #************************************************************************/
1449 IMPL_LINK(SvxNumberFormatTabPage
, EditModifyHdl_Impl
, weld::Entry
&, rEdit
, void)
1451 EditHdl_Impl(&rEdit
);
1454 void SvxNumberFormatTabPage::EditHdl_Impl(const weld::Entry
* pEdFormat
)
1456 sal_uInt32 nCurKey
= NUMKEY_UNDEFINED
;
1458 if ( m_xEdFormat
->get_text().isEmpty() )
1460 m_xIbAdd
->set_sensitive(false );
1461 m_xIbRemove
->set_sensitive(false );
1462 m_xIbInfo
->set_sensitive(false );
1463 m_xFtComment
->set_label(OUString());
1467 OUString aFormat
= m_xEdFormat
->get_text();
1468 MakePreviewText( aFormat
);
1470 if ( pNumFmtShell
->FindEntry( aFormat
, &nCurKey
) )
1472 m_xIbAdd
->set_sensitive(false );
1473 bool bUserDef
=pNumFmtShell
->IsUserDefined( aFormat
);
1475 m_xIbRemove
->set_sensitive(bUserDef
);
1476 m_xIbInfo
->set_sensitive(bUserDef
);
1480 sal_uInt16 nTmpCurPos
=pNumFmtShell
->FindCurrencyFormat(aFormat
);
1481 if (nTmpCurPos
!= sal_uInt16(-1))
1482 set_active_currency(nTmpCurPos
);
1484 short nPosi
=pNumFmtShell
->GetListPos4Entry( nCurKey
, aFormat
);
1486 m_xLbFormat
->select(static_cast<sal_uInt16
>(nPosi
));
1492 m_xIbAdd
->set_sensitive(true);
1493 m_xIbInfo
->set_sensitive(true);
1494 m_xIbRemove
->set_sensitive(false );
1496 m_xFtComment
->set_label(m_xEdComment
->get_text());
1503 pNumFmtShell
->SetCurNumFmtKey( nCurKey
);
1504 UpdateOptions_Impl( true );
1509 /*************************************************************************
1510 #* Method: NotifyChange
1511 #*------------------------------------------------------------------------
1513 #* Class: SvxNumberFormatTabPage
1514 #* Function: Does changes in the number attributes.
1515 #* Input: Options- Controls
1518 #************************************************************************/
1520 IMPL_LINK(SvxNumberFormatTabPage
, OptClickHdl_Impl
, weld::Button
&, rOptCtrl
, void)
1522 OptHdl_Impl(&rOptCtrl
);
1525 IMPL_LINK(SvxNumberFormatTabPage
, OptEditHdl_Impl
, weld::SpinButton
&, rEdit
, void)
1527 OptHdl_Impl(&rEdit
);
1530 void SvxNumberFormatTabPage::OptHdl_Impl(const weld::Widget
* pOptCtrl
)
1532 if ( pOptCtrl
== m_xEdLeadZeroes
.get()
1533 || pOptCtrl
== m_xEdDecimals
.get()
1534 || pOptCtrl
== m_xEdDenominator
.get()
1535 || pOptCtrl
== m_xBtnNegRed
.get()
1536 || pOptCtrl
== m_xBtnThousand
.get()
1537 || pOptCtrl
== m_xBtnEngineering
.get())
1540 bool bThousand
= ( m_xBtnThousand
->get_visible() && m_xBtnThousand
->get_sensitive() && m_xBtnThousand
->get_active() )
1541 || ( m_xBtnEngineering
->get_visible() && m_xBtnEngineering
->get_sensitive() && m_xBtnEngineering
->get_active() );
1542 bool bNegRed
= m_xBtnNegRed
->get_sensitive() && m_xBtnNegRed
->get_active();
1543 sal_uInt16 nPrecision
= (m_xEdDecimals
->get_sensitive() && m_xEdDecimals
->get_visible())
1544 ? static_cast<sal_uInt16
>(m_xEdDecimals
->get_value())
1545 : ( (m_xEdDenominator
->get_sensitive() && m_xEdDenominator
->get_visible())
1546 ? static_cast<sal_uInt16
>(m_xEdDenominator
->get_value())
1548 sal_uInt16 nLeadZeroes
= (m_xEdLeadZeroes
->get_sensitive())
1549 ? static_cast<sal_uInt16
>(m_xEdLeadZeroes
->get_value())
1551 if ( pNumFmtShell
->GetStandardName() == m_xEdFormat
->get_text() )
1553 m_xEdDecimals
->set_value(nPrecision
);
1556 pNumFmtShell
->MakeFormat( aFormat
,
1558 nPrecision
, nLeadZeroes
,
1559 static_cast<sal_uInt16
>(m_xLbFormat
->get_selected_index()) );
1561 m_xEdFormat
->set_text( aFormat
);
1562 MakePreviewText( aFormat
);
1564 if ( pNumFmtShell
->FindEntry( aFormat
) )
1566 m_xIbAdd
->set_sensitive(false );
1567 bool bUserDef
=pNumFmtShell
->IsUserDefined( aFormat
);
1568 m_xIbRemove
->set_sensitive(bUserDef
);
1569 m_xIbInfo
->set_sensitive(bUserDef
);
1570 EditHdl_Impl(m_xEdFormat
.get());
1575 EditHdl_Impl( nullptr );
1576 m_xLbFormat
->select(-1);
1581 /*************************************************************************
1582 #* Method: LostFocusHdl_Impl
1583 #*------------------------------------------------------------------------
1585 #* Class: SvxNumberFormatTabPage
1586 #* Function: Does changes in the number attributes.
1587 #* Input: Options- Controls
1590 #************************************************************************/
1592 IMPL_LINK_NOARG(SvxNumberFormatTabPage
, LostFocusHdl_Impl
, weld::Widget
&, void)
1596 m_xFtComment
->set_label(m_xEdComment
->get_text());
1597 m_xEdComment
->hide();
1598 m_xFtComment
->show();
1599 if(!m_xIbAdd
->get_sensitive())
1601 sal_uInt16 nSelPos
= m_xLbFormat
->get_selected_index();
1602 pNumFmtShell
->SetComment4Entry(nSelPos
, m_xEdComment
->get_text());
1603 // String for user defined, if present
1604 OUString sEntry
= m_xLbCategory
->n_children() > 1 ? m_xLbCategory
->get_text(1) : OUString();
1605 m_xEdComment
->set_text(sEntry
);
1609 /*************************************************************************
1610 #* Method: NotifyChange
1611 #*------------------------------------------------------------------------
1613 #* Class: SvxNumberFormatTabPage
1614 #* Function: Does changes in the number attributes.
1615 #* Input: Options- Controls
1618 #************************************************************************/
1620 OUString
SvxNumberFormatTabPage::GetExpColorString(
1621 Color
*& rpPreviewColor
, const OUString
& rFormatStr
, short nTmpCatPos
)
1623 SvxNumValCategory i
;
1626 case CAT_ALL
: i
=SvxNumValCategory::Standard
; break;
1628 case CAT_NUMBER
: i
=SvxNumValCategory::Standard
; break;
1630 case CAT_PERCENT
: i
=SvxNumValCategory::Percent
; break;
1632 case CAT_CURRENCY
: i
=SvxNumValCategory::Currency
; break;
1634 case CAT_DATE
: i
=SvxNumValCategory::Date
; break;
1636 case CAT_TIME
: i
=SvxNumValCategory::Time
; break;
1638 case CAT_SCIENTIFIC
: i
=SvxNumValCategory::Scientific
; break;
1640 case CAT_FRACTION
: i
=SvxNumValCategory::Fraction
; break;
1642 case CAT_BOOLEAN
: i
=SvxNumValCategory::Boolean
; break;
1644 case CAT_USERDEFINED
: i
=SvxNumValCategory::Standard
; break;
1647 default: i
=SvxNumValCategory::NoValue
;break;
1649 double fVal
= fSvxNumValConst
[i
];
1651 OUString aPreviewString
;
1652 pNumFmtShell
->MakePrevStringFromVal( rFormatStr
, aPreviewString
, rpPreviewColor
, fVal
);
1653 return aPreviewString
;
1656 void SvxNumberFormatTabPage::MakePreviewText( const OUString
& rFormat
)
1658 OUString aPreviewString
;
1659 Color
* pPreviewColor
= nullptr;
1660 pNumFmtShell
->MakePreviewString( rFormat
, aPreviewString
, pPreviewColor
);
1661 m_aWndPreview
.NotifyChange( aPreviewString
, pPreviewColor
);
1664 void SvxNumberFormatTabPage::ChangePreviewText( sal_uInt16 nPos
)
1666 OUString aPreviewString
;
1667 Color
* pPreviewColor
= nullptr;
1668 pNumFmtShell
->FormatChanged( nPos
, aPreviewString
, pPreviewColor
);
1669 m_aWndPreview
.NotifyChange( aPreviewString
, pPreviewColor
);
1672 void SvxNumberFormatTabPage::FillCurrencyBox()
1674 std::vector
<OUString
> aList
;
1676 sal_uInt16 nSelPos
=0;
1677 pNumFmtShell
->GetCurrencySymbols(aList
, &nSelPos
);
1679 m_xLbCurrency
->freeze();
1680 m_xLbCurrency
->clear();
1681 bLegacyAutomaticCurrency
= false;
1682 for (std::vector
<OUString
>::iterator i
= aList
.begin() + 1;i
!= aList
.end(); ++i
)
1683 m_xLbCurrency
->append_text(*i
);
1684 m_xLbCurrency
->thaw();
1686 set_active_currency(nSelPos
);
1689 void SvxNumberFormatTabPage::SetCategory(sal_uInt16 nPos
)
1691 int nCurCategory
= m_xLbCategory
->get_selected_index();
1692 sal_uInt16 nTmpCatPos
;
1696 nTmpCatPos
=nFixedCategory
;
1703 if(m_xLbCategory
->n_children()==1 || nCurCategory
!=nPos
)
1705 if(nTmpCatPos
!=CAT_CURRENCY
)
1706 m_xLbCurrency
->hide();
1708 m_xLbCurrency
->show();
1710 m_xLbCategory
->select(nPos
);
1713 /* to support Writer text field language handling an
1714 additional entry needs to be inserted into the ListBox
1715 which marks a certain language as automatically detected
1716 Additionally the "Default" language is removed
1718 void SvxNumberFormatTabPage::AddAutomaticLanguage_Impl(LanguageType eAutoLang
, bool bSelect
)
1720 m_xLbLanguage
->remove_id(LANGUAGE_SYSTEM
);
1721 m_xLbLanguage
->append(eAutoLang
, sAutomaticLangEntry
);
1723 m_xLbLanguage
->set_active_id(eAutoLang
);
1726 void SvxNumberFormatTabPage::PageCreated(const SfxAllItemSet
& aSet
)
1728 const SvxNumberInfoItem
* pNumberInfoItem
= aSet
.GetItem
<SvxNumberInfoItem
>(SID_ATTR_NUMBERFORMAT_INFO
, false);
1729 if (pNumberInfoItem
&& !pNumItem
)
1730 pNumItem
.reset( static_cast<SvxNumberInfoItem
*>(pNumberInfoItem
->Clone()) );
1733 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */