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 <sal/config.h>
22 #include <o3tl/safeint.hxx>
23 #include <svl/eitem.hxx>
24 #include <svl/intitem.hxx>
25 #include <sfx2/objsh.hxx>
26 #include <vcl/outdev.hxx>
27 #include <i18nlangtag/lang.h>
28 #include <svx/svxids.hrc>
29 #include <svtools/colorcfg.hxx>
31 #include <numcategories.hrc>
32 #include <strings.hrc>
34 #include <svx/numinf.hxx>
37 #include <svx/numfmtsh.hxx>
38 #include <dialmgr.hxx>
39 #include <sfx2/basedlgs.hxx>
40 #include <svx/flagsdef.hxx>
42 #include <com/sun/star/frame/XModel.hpp>
43 #include <com/sun/star/lang/XServiceInfo.hpp>
47 using ::com::sun::star::uno::Reference
;
48 using ::com::sun::star::lang::XServiceInfo
;
49 using ::com::sun::star::uno::UNO_QUERY
;
51 #define NUMKEY_UNDEFINED SAL_MAX_UINT32
53 // static ----------------------------------------------------------------
55 const WhichRangesContainer
SvxNumberFormatTabPage::pRanges(
57 SID_ATTR_NUMBERFORMAT_VALUE
, SID_ATTR_NUMBERFORMAT_INFO
, // 10085 - 10086
58 SID_ATTR_NUMBERFORMAT_ONE_AREA
, SID_ATTR_NUMBERFORMAT_ONE_AREA
, // 10580 - 10580
59 SID_ATTR_NUMBERFORMAT_NOLANGUAGE
, SID_ATTR_NUMBERFORMAT_NOLANGUAGE
, // 10700 - 10700
60 SID_ATTR_NUMBERFORMAT_SOURCE
, SID_ATTR_NUMBERFORMAT_SOURCE
>); // 10932 - 10932
62 /*************************************************************************
63 #* Method: SvxNumberPreview
64 #*------------------------------------------------------------------------
66 #* Class: SvxNumberPreview
67 #* Function: Constructor of the class SvxNumberPreview
68 #* Input: Window, Resource-ID
71 #************************************************************************/
73 SvxNumberPreview::SvxNumberPreview()
79 /*************************************************************************
80 #* Method: NotifyChange
81 #*------------------------------------------------------------------------
83 #* Class: SvxNumberPreview
84 #* Function: Function for changing the preview string
85 #* Input: String, color
88 #************************************************************************/
90 void SvxNumberPreview::NotifyChange( const OUString
& rPrevStr
,
93 // detect and strip out '*' related placeholders
95 mnPos
= aPrevStr
.indexOf( 0x1B );
98 // Right during user input the star symbol is the very
99 // last character before the user enters another one.
100 if (mnPos
< aPrevStr
.getLength() - 1)
102 mnChar
= aPrevStr
[ mnPos
+ 1 ];
103 // delete placeholder and char to repeat
104 aPrevStr
= aPrevStr
.replaceAt( mnPos
, 2, u
"" );
108 // delete placeholder
109 aPrevStr
= aPrevStr
.replaceAt( mnPos
, 1, u
"" );
110 // do not attempt to draw a 0 fill character
118 svtools::ColorConfig aColorConfig
;
119 Color aFgColor
= aColorConfig
.GetColorValue(svtools::FONTCOLOR
, false).nColor
;
120 if (aFgColor
== COL_AUTO
)
122 Color aBgColor
= aColorConfig
.GetColorValue(svtools::DOCCOLOR
).nColor
;
123 aFgColor
= aBgColor
.IsDark() ? COL_WHITE
: COL_BLACK
;
130 /*************************************************************************
132 #*------------------------------------------------------------------------
134 #* Class: SvxNumberPreview
135 #* Function: Function for repainting the window.
139 #************************************************************************/
141 void SvxNumberPreview::Paint(vcl::RenderContext
& rRenderContext
, const ::tools::Rectangle
&)
143 rRenderContext
.Push(vcl::PushFlags::ALL
);
145 svtools::ColorConfig aColorConfig
;
146 Color aBgColor
= aColorConfig
.GetColorValue(svtools::DOCCOLOR
).nColor
;
147 Color aFgColor
= aColorConfig
.GetColorValue(svtools::FONTCOLOR
, false).nColor
;
148 if (aFgColor
== COL_AUTO
)
149 aFgColor
= aBgColor
.IsDark() ? COL_WHITE
: COL_BLACK
;
150 rRenderContext
.SetBackground(aBgColor
);
151 rRenderContext
.SetTextColor(aFgColor
);
152 rRenderContext
.Erase();
154 vcl::Font aDrawFont
= rRenderContext
.GetFont();
155 Size
aSzWnd(GetOutputSizePixel());
156 OUString
aTmpStr(aPrevStr
);
157 tools::Long nLeadSpace
= (aSzWnd
.Width() - rRenderContext
.GetTextWidth(aTmpStr
)) / 2;
159 aDrawFont
.SetTransparent(true);
160 aDrawFont
.SetColor(aPrevCol
);
161 rRenderContext
.SetFont(aDrawFont
);
165 tools::Long nCharWidth
= rRenderContext
.GetTextWidth(OUString(mnChar
));
167 int nNumCharsToInsert
= 0;
169 nNumCharsToInsert
= nLeadSpace
/ nCharWidth
;
171 if (nNumCharsToInsert
> 0)
173 for (int i
= 0; i
< nNumCharsToInsert
; ++i
)
174 aTmpStr
= aTmpStr
.replaceAt(mnPos
, 0, rtl::OUStringChar(mnChar
));
179 if (mnPos
== -1 && nLeadSpace
> 0) //tdf#122120 if it won't fit anyway, then left align it
184 Point
aPosText(nX
, (aSzWnd
.Height() - GetTextHeight()) / 2);
185 rRenderContext
.DrawText(aPosText
, aTmpStr
);
186 rRenderContext
.Pop();
189 // class SvxNumberFormatTabPage ------------------------------------------
191 #define REMOVE_DONTKNOW() \
192 if (!m_xFtLanguage->get_sensitive()) \
194 m_xFtLanguage->set_sensitive(true); \
195 m_xLbLanguage->set_sensitive(true); \
196 m_xLbLanguage->set_active_id(pNumFmtShell->GetCurLanguage()); \
199 SvxNumberFormatTabPage::SvxNumberFormatTabPage(weld::Container
* pPage
, weld::DialogController
* pController
,
200 const SfxItemSet
& rCoreAttrs
)
201 : SfxTabPage(pPage
, pController
, "cui/ui/numberingformatpage.ui", "NumberingFormatPage", &rCoreAttrs
)
202 , nInitFormat(std::numeric_limits
<sal_uInt32
>::max())
203 , m_nLbFormatSelPosEdComment(SELPOS_NONE
)
204 , bLegacyAutomaticCurrency(false)
205 , sAutomaticLangEntry(CuiResId(RID_CUISTR_AUTO_ENTRY
))
206 , m_xFtCategory(m_xBuilder
->weld_label("categoryft"))
207 , m_xLbCategory(m_xBuilder
->weld_tree_view("categorylb"))
208 , m_xFtFormat(m_xBuilder
->weld_label("formatft"))
209 , m_xLbCurrency(m_xBuilder
->weld_combo_box("currencylb"))
210 , m_xLbFormat(m_xBuilder
->weld_tree_view("formatlb"))
211 , m_xFtLanguage(m_xBuilder
->weld_label("languageft"))
212 , m_xCbSourceFormat(m_xBuilder
->weld_check_button("sourceformat"))
213 , m_xFtOptions(m_xBuilder
->weld_label("optionsft"))
214 , m_xFtDecimals(m_xBuilder
->weld_label("decimalsft"))
215 , m_xEdDecimals(m_xBuilder
->weld_spin_button("decimalsed"))
216 , m_xFtDenominator(m_xBuilder
->weld_label("denominatorft"))
217 , m_xEdDenominator(m_xBuilder
->weld_spin_button("denominatored"))
218 , m_xBtnNegRed(m_xBuilder
->weld_check_button("negnumred"))
219 , m_xFtLeadZeroes(m_xBuilder
->weld_label("leadzerosft"))
220 , m_xEdLeadZeroes(m_xBuilder
->weld_spin_button("leadzerosed"))
221 , m_xBtnThousand(m_xBuilder
->weld_check_button("thousands"))
222 , m_xBtnEngineering(m_xBuilder
->weld_check_button("engineering"))
223 , m_xFormatCodeFrame(m_xBuilder
->weld_widget("formatcode"))
224 , m_xEdFormat(m_xBuilder
->weld_entry("formatted"))
225 , m_xIbAdd(m_xBuilder
->weld_button("add"))
226 , m_xIbInfo(m_xBuilder
->weld_button("edit"))
227 , m_xIbRemove(m_xBuilder
->weld_button("delete"))
228 , m_xFtComment(m_xBuilder
->weld_label("commentft"))
229 , m_xEdComment(m_xBuilder
->weld_entry("commented"))
230 , m_xLbLanguage(new SvxLanguageBox(m_xBuilder
->weld_combo_box("languagelb")))
231 , m_xWndPreview(new weld::CustomWeld(*m_xBuilder
, "preview", m_aWndPreview
))
233 for (size_t i
= 0; i
< std::size(NUM_CATEGORIES
); ++i
)
234 m_xLbCategory
->append_text(CuiResId(NUM_CATEGORIES
[i
]));
236 auto nWidth
= m_xLbCategory
->get_approximate_digit_width() * 22;
237 m_xLbCategory
->set_size_request(nWidth
, m_xLbCategory
->get_height_rows(7));
238 m_xLbFormat
->set_size_request(nWidth
, m_xLbFormat
->get_height_rows(5));
239 m_xLbCurrency
->set_size_request(nWidth
, -1); // force using (narrower) width of its LbFormat sibling
241 // Initially remove the "Automatically" entry.
242 m_xLbCurrency
->set_active(-1); // First ensure that nothing is selected.
243 sAutomaticCurrencyEntry
= m_xLbCurrency
->get_text(0);
244 m_xLbCurrency
->remove(0);
247 SetExchangeSupport(); // this page needs ExchangeSupport
251 SvxNumberFormatTabPage::~SvxNumberFormatTabPage()
253 pNumFmtShell
.reset();
255 m_xWndPreview
.reset();
256 m_xLbLanguage
.reset();
259 void SvxNumberFormatTabPage::Init_Impl()
264 m_xIbAdd
->set_sensitive(false );
265 m_xIbRemove
->set_sensitive(false );
266 m_xIbInfo
->set_sensitive(false );
268 m_xEdComment
->set_text(m_xLbCategory
->get_text(1)); // string for user defined
270 m_xEdComment
->hide();
272 m_xCbSourceFormat
->set_active( false );
273 m_xCbSourceFormat
->set_sensitive(false);
274 m_xCbSourceFormat
->hide();
276 Link
<weld::TreeView
&,void> aLink2
= LINK(this, SvxNumberFormatTabPage
, SelFormatTreeListBoxHdl_Impl
);
277 Link
<weld::ComboBox
&,void> aLink3
= LINK(this, SvxNumberFormatTabPage
, SelFormatListBoxHdl_Impl
);
278 m_xLbCategory
->connect_changed(aLink2
);
279 m_xLbCategory
->connect_focus_in(LINK(this, SvxNumberFormatTabPage
, LostFocusHdl_Impl
));
280 m_xLbFormat
->connect_changed(aLink2
);
281 m_xLbFormat
->connect_focus_in(LINK(this, SvxNumberFormatTabPage
, LostFocusHdl_Impl
));
282 m_xLbLanguage
->connect_changed(aLink3
);
283 m_xLbLanguage
->connect_focus_in(LINK(this, SvxNumberFormatTabPage
, LostFocusHdl_Impl
));
284 m_xLbCurrency
->connect_changed(aLink3
);
285 m_xLbCurrency
->connect_focus_in(LINK(this, SvxNumberFormatTabPage
, LostFocusHdl_Impl
));
286 m_xCbSourceFormat
->connect_toggled(LINK(this, SvxNumberFormatTabPage
, SelFormatClickHdl_Impl
));
287 m_xCbSourceFormat
->connect_focus_in(LINK(this, SvxNumberFormatTabPage
, LostFocusHdl_Impl
));
289 Link
<weld::SpinButton
&,void> aLink
= LINK( this, SvxNumberFormatTabPage
, OptEditHdl_Impl
);
291 m_xEdDecimals
->connect_value_changed(aLink
);
292 m_xEdDecimals
->connect_focus_in(LINK(this, SvxNumberFormatTabPage
, LostFocusHdl_Impl
));
293 m_xEdDenominator
->connect_value_changed(aLink
);
294 m_xEdDenominator
->connect_focus_in(LINK(this, SvxNumberFormatTabPage
, LostFocusHdl_Impl
));
295 m_xEdLeadZeroes
->connect_value_changed(aLink
);
296 m_xEdLeadZeroes
->connect_focus_in(LINK(this, SvxNumberFormatTabPage
, LostFocusHdl_Impl
));
298 m_xBtnNegRed
->connect_toggled(LINK(this, SvxNumberFormatTabPage
, OptClickHdl_Impl
));
299 m_xBtnNegRed
->connect_focus_in(LINK(this, SvxNumberFormatTabPage
, LostFocusHdl_Impl
));
300 m_xBtnThousand
->connect_toggled(LINK(this, SvxNumberFormatTabPage
, OptClickHdl_Impl
));
301 m_xBtnThousand
->connect_focus_in(LINK(this, SvxNumberFormatTabPage
, LostFocusHdl_Impl
));
302 m_xBtnEngineering
->connect_toggled(LINK(this, SvxNumberFormatTabPage
, OptClickHdl_Impl
));
303 m_xBtnEngineering
->connect_focus_in(LINK(this, SvxNumberFormatTabPage
, LostFocusHdl_Impl
));
304 m_xLbFormat
->connect_row_activated(LINK(this, SvxNumberFormatTabPage
, DoubleClickHdl_Impl
));
305 m_xEdFormat
->connect_changed(LINK(this, SvxNumberFormatTabPage
, EditModifyHdl_Impl
));
306 m_xEdFormat
->connect_focus_in(LINK(this, SvxNumberFormatTabPage
, LostFocusHdl_Impl
));
307 m_xIbAdd
->connect_clicked(LINK(this, SvxNumberFormatTabPage
, ClickHdl_Impl
));
308 m_xIbAdd
->connect_focus_in(LINK(this, SvxNumberFormatTabPage
, LostFocusHdl_Impl
));
309 m_xIbRemove
->connect_clicked(LINK(this, SvxNumberFormatTabPage
, ClickHdl_Impl
));
310 m_xIbRemove
->connect_focus_in(LINK(this, SvxNumberFormatTabPage
, LostFocusHdl_Impl
));
311 m_xIbInfo
->connect_clicked(LINK(this, SvxNumberFormatTabPage
, ClickHdl_Impl
));
312 UpdateThousandEngineeringCheckBox();
313 UpdateDecimalsDenominatorEditBox();
315 // initialize language ListBox
317 m_xLbLanguage
->SetLanguageList(SvxLanguageListFlags::ALL
| SvxLanguageListFlags::ONLY_KNOWN
,
318 false, false, false, true, LANGUAGE_SYSTEM
,
319 css::i18n::ScriptType::WEAK
);
322 std::unique_ptr
<SfxTabPage
> SvxNumberFormatTabPage::Create( weld::Container
* pPage
, weld::DialogController
* pController
,
323 const SfxItemSet
* rAttrSet
)
325 return std::make_unique
<SvxNumberFormatTabPage
>(pPage
, pController
, *rAttrSet
);
329 /*************************************************************************
331 #*------------------------------------------------------------------------
333 #* Class: SvxNumberFormatTabPage
334 #* Function: The dialog's attributes are reset
335 #* using the Itemset.
339 #************************************************************************/
341 void SvxNumberFormatTabPage::set_active_currency(sal_Int32 nPos
)
343 static_assert(SELPOS_NONE
== -1, "SELPOS_NONE was -1 at time of writing");
344 if (nPos
== 0 && !bLegacyAutomaticCurrency
)
346 // Insert "Automatically" if currently used so it is selectable.
347 m_xLbCurrency
->insert_text(0, sAutomaticCurrencyEntry
);
348 bLegacyAutomaticCurrency
= true;
350 if (nPos
!= -1 && !bLegacyAutomaticCurrency
)
352 m_xLbCurrency
->set_active(nPos
);
355 sal_uInt32
SvxNumberFormatTabPage::get_active_currency() const
357 static_assert(SELPOS_NONE
== -1, "SELPOS_NONE was -1 at time of writing");
358 sal_Int32 nCurrencyPos
= m_xLbCurrency
->get_active();
359 if (nCurrencyPos
!= -1 && !bLegacyAutomaticCurrency
)
364 void SvxNumberFormatTabPage::Reset( const SfxItemSet
* rSet
)
366 const SfxUInt32Item
* pValFmtAttr
= nullptr;
367 const SfxPoolItem
* pItem
= nullptr;
368 const SfxBoolItem
* pAutoEntryAttr
= nullptr;
370 sal_uInt16 nCatLbSelPos
= 0;
371 sal_uInt16 nFmtLbSelPos
= 0;
372 LanguageType eLangType
= LANGUAGE_DONTKNOW
;
373 std::vector
<OUString
> aFmtEntryList
;
374 SvxNumberValueType eValType
= SvxNumberValueType::Undefined
;
375 double nValDouble
= 0;
378 if(const SfxBoolItem
* pBoolLangItem
= rSet
->GetItemIfSet( SID_ATTR_NUMBERFORMAT_NOLANGUAGE
))
380 if(pBoolLangItem
->GetValue())
391 SfxItemState eState
= rSet
->GetItemState( GetWhich( SID_ATTR_NUMBERFORMAT_INFO
),true,&pItem
);
393 if(eState
==SfxItemState::SET
)
395 if(pNumItem
==nullptr)
398 pNumItem
.reset( static_cast<SvxNumberInfoItem
*>(pItem
->Clone()) );
411 eState
= rSet
->GetItemState( GetWhich( SID_ATTR_NUMBERFORMAT_ONE_AREA
));
413 if(eState
==SfxItemState::SET
)
415 const SfxBoolItem
* pBoolItem
= GetItem( *rSet
, SID_ATTR_NUMBERFORMAT_ONE_AREA
);
417 if(pBoolItem
!=nullptr)
419 bOneAreaFlag
= pBoolItem
->GetValue();
423 eState
= rSet
->GetItemState( SID_ATTR_NUMBERFORMAT_SOURCE
);
425 if ( eState
== SfxItemState::SET
)
427 const SfxBoolItem
* pBoolItem
=
428 GetItem( *rSet
, SID_ATTR_NUMBERFORMAT_SOURCE
);
430 m_xCbSourceFormat
->set_active(pBoolItem
->GetValue());
432 m_xCbSourceFormat
->set_active( false );
433 m_xCbSourceFormat
->set_sensitive(true);
434 m_xCbSourceFormat
->show();
438 bool bInit
= false; // set to sal_True for debug test
439 m_xCbSourceFormat
->set_active( bInit
);
440 m_xCbSourceFormat
->set_sensitive( bInit
);
441 m_xCbSourceFormat
->set_visible( bInit
);
444 // pNumItem must have been set from outside!
445 DBG_ASSERT( pNumItem
, "No NumberInfo, no NumberFormatter, goodbye. CRASH. :-(" );
447 eState
= rSet
->GetItemState( GetWhich( SID_ATTR_NUMBERFORMAT_VALUE
) );
449 if ( SfxItemState::DONTCARE
!= eState
)
450 pValFmtAttr
= GetItem( *rSet
, SID_ATTR_NUMBERFORMAT_VALUE
);
452 eValType
= pNumItem
->GetValueType();
456 case SvxNumberValueType::String
:
457 aValString
= pNumItem
->GetValueString();
459 case SvxNumberValueType::Number
:
460 // #50441# string may be set in addition to the value
461 aValString
= pNumItem
->GetValueString();
462 nValDouble
= pNumItem
->GetValueDouble();
464 case SvxNumberValueType::Undefined
:
469 pNumFmtShell
.reset(); // delete old shell if applicable (== reset)
471 nInitFormat
= pValFmtAttr
// memorize init key
472 ? pValFmtAttr
->GetValue() // (for FillItemSet())
473 : std::numeric_limits
<sal_uInt32
>::max(); // == DONT_KNOW
476 if ( eValType
== SvxNumberValueType::String
)
477 pNumFmtShell
.reset( SvxNumberFormatShell::Create(
478 pNumItem
->GetNumberFormatter(),
479 pValFmtAttr
? nInitFormat
: 0,
483 pNumFmtShell
.reset( SvxNumberFormatShell::Create(
484 pNumItem
->GetNumberFormatter(),
485 pValFmtAttr
? nInitFormat
: 0,
491 bool bUseStarFormat
= false;
492 if (SfxObjectShell
* pDocSh
= SfxObjectShell::Current())
494 // is this a calc document
495 Reference
< XServiceInfo
> xSI( pDocSh
->GetModel(), UNO_QUERY
);
497 bUseStarFormat
= xSI
->supportsService("com.sun.star.sheet.SpreadsheetDocument");
499 pNumFmtShell
->SetUseStarFormat( bUseStarFormat
);
503 OUString aPrevString
;
504 const Color
* pDummy
= nullptr;
505 pNumFmtShell
->GetInitSettings( nCatLbSelPos
, eLangType
, nFmtLbSelPos
,
506 aFmtEntryList
, aPrevString
, pDummy
);
508 if (nCatLbSelPos
==CAT_CURRENCY
)
509 set_active_currency(pNumFmtShell
->GetCurrencySymbol());
511 nFixedCategory
=nCatLbSelPos
;
514 OUString sFixedCategory
= m_xLbCategory
->get_text(nFixedCategory
);
515 m_xLbCategory
->clear();
516 m_xLbCategory
->append_text(sFixedCategory
);
521 SetCategory(nCatLbSelPos
);
523 eState
= rSet
->GetItemState( SID_ATTR_NUMBERFORMAT_ADD_AUTO
);
524 if(SfxItemState::SET
== eState
)
525 pAutoEntryAttr
= GetItem( *rSet
, SID_ATTR_NUMBERFORMAT_ADD_AUTO
);
526 // no_NO is an alias for nb_NO and normally isn't listed, we need it for
527 // backwards compatibility, but only if the format passed is of
528 // LanguageType no_NO.
529 if ( eLangType
== LANGUAGE_NORWEGIAN
)
531 m_xLbLanguage
->remove_id(eLangType
); // in case we're already called
532 m_xLbLanguage
->InsertLanguage( eLangType
);
534 m_xLbLanguage
->set_active_id(eLangType
);
536 AddAutomaticLanguage_Impl(eLangType
, pAutoEntryAttr
->GetValue());
537 UpdateFormatListBox_Impl(false,true);
539 //! This spoils everything because it rematches currency formats based on
540 //! the selected m_xLbCurrency entry instead of the current format.
541 //! Besides that everything seems to be initialized by now, so why call it?
542 // SelFormatHdl_Impl(m_xLbCategory.get());
546 EditHdl_Impl(m_xEdFormat
.get()); // UpdateOptions_Impl() as a side effect
550 // everything disabled except direct input or changing the category
554 if ( m_xCbSourceFormat
->get_active() )
556 // everything disabled except SourceFormat checkbox
557 EnableBySourceFormat_Impl();
561 /*************************************************************************
562 #* Method: Obstructing
563 #*------------------------------------------------------------------------
565 #* Class: SvxNumberFormatTabPage
566 #* Function: Disable the controls except from changing the category
571 #************************************************************************/
572 void SvxNumberFormatTabPage::Obstructing()
574 m_xLbFormat
->select(-1);
575 m_xLbLanguage
->set_active(-1);
576 m_xFtLanguage
->set_sensitive(false);
577 m_xLbLanguage
->set_sensitive(false);
579 m_xIbAdd
->set_sensitive(false );
580 m_xIbRemove
->set_sensitive(false );
581 m_xIbInfo
->set_sensitive(false );
583 m_xBtnNegRed
->set_sensitive(false);
584 m_xBtnThousand
->set_sensitive(false);
585 m_xBtnEngineering
->set_sensitive(false);
586 m_xFtLeadZeroes
->set_sensitive(false);
587 m_xFtDecimals
->set_sensitive(false);
588 m_xFtDenominator
->set_sensitive(false);
589 m_xEdLeadZeroes
->set_sensitive(false);
590 m_xEdDecimals
->set_sensitive(false);
591 m_xEdDenominator
->set_sensitive(false);
592 m_xFtOptions
->set_sensitive(false);
593 m_xEdDecimals
->set_text( OUString() );
594 m_xEdLeadZeroes
->set_text( OUString() );
595 m_xBtnNegRed
->set_active( false );
596 m_xBtnThousand
->set_active( false );
597 m_xBtnEngineering
->set_active( false );
598 m_aWndPreview
.NotifyChange( OUString() );
600 m_xLbCategory
->select(0);
601 m_xEdFormat
->set_text( OUString() );
602 m_xFtComment
->set_label( OUString() );
603 m_xEdComment
->set_text(m_xLbCategory
->get_text(1)); // string for user defined
605 m_xEdFormat
->grab_focus();
609 /*************************************************************************
610 #* Enable/Disable dialog parts depending on the value of the SourceFormat
612 #************************************************************************/
613 void SvxNumberFormatTabPage::EnableBySourceFormat_Impl()
615 bool bEnable
= !m_xCbSourceFormat
->get_active();
617 m_xCbSourceFormat
->grab_focus();
618 m_xFtCategory
->set_sensitive( bEnable
);
619 m_xLbCategory
->set_sensitive( bEnable
);
620 m_xFtFormat
->set_sensitive( bEnable
);
621 m_xLbCurrency
->set_sensitive( bEnable
);
622 m_xLbFormat
->set_sensitive( bEnable
);
623 m_xFtLanguage
->set_sensitive( bEnable
);
624 m_xLbLanguage
->set_sensitive( bEnable
);
625 m_xFtDecimals
->set_sensitive( bEnable
);
626 m_xEdDecimals
->set_sensitive( bEnable
);
627 m_xFtDenominator
->set_sensitive( bEnable
);
628 m_xEdDenominator
->set_sensitive( bEnable
);
629 m_xFtLeadZeroes
->set_sensitive( bEnable
);
630 m_xEdLeadZeroes
->set_sensitive( bEnable
);
631 m_xBtnNegRed
->set_sensitive( bEnable
);
632 m_xBtnThousand
->set_sensitive( bEnable
);
633 m_xBtnEngineering
->set_sensitive( bEnable
);
634 m_xFtOptions
->set_sensitive( bEnable
);
635 m_xFormatCodeFrame
->set_sensitive( bEnable
);
639 /*************************************************************************
640 #* Method: HideLanguage
641 #*------------------------------------------------------------------------
643 #* Class: SvxNumberFormatTabPage
644 #* Function: Hides the language settings:
645 #* Input: sal_Bool nFlag
648 #************************************************************************/
650 void SvxNumberFormatTabPage::HideLanguage(bool bFlag
)
652 m_xFtLanguage
->set_visible(!bFlag
);
653 m_xLbLanguage
->set_visible(!bFlag
);
656 /*************************************************************************
657 #* Method: FillItemSet
658 #*------------------------------------------------------------------------
660 #* Class: SvxNumberFormatTabPage
661 #* Function: Adjusts the attributes in the ItemSet,
662 #* and - if bNumItemFlag is not set - the
663 #* numItem in the DocShell.
667 #************************************************************************/
669 bool SvxNumberFormatTabPage::FillItemSet( SfxItemSet
* rCoreAttrs
)
671 bool bDataChanged
= m_xFtLanguage
->get_sensitive() || m_xCbSourceFormat
->get_sensitive();
674 const SfxItemSet
& rMyItemSet
= GetItemSet();
675 TypedWhichId
<SfxUInt32Item
> nWhich
= GetWhich( SID_ATTR_NUMBERFORMAT_VALUE
);
676 SfxItemState eItemState
= rMyItemSet
.GetItemState( nWhich
, false );
678 // OK chosen - Is format code input entered already taken over?
679 // If not, simulate Add. Upon syntax error ignore input and prevent Put.
680 OUString aFormat
= m_xEdFormat
->get_text();
681 sal_uInt32 nCurKey
= pNumFmtShell
->GetCurNumFmtKey();
683 if ( m_xIbAdd
->get_sensitive() || pNumFmtShell
->IsTmpCurrencyFormat(aFormat
) )
684 { // #79599# It is not sufficient to just add the format code (or
685 // delete it in case of bOneAreaFlag and resulting category change).
686 // Upon switching tab pages we need all settings to be consistent
687 // in case this page will be redisplayed later.
688 bDataChanged
= Click_Impl(*m_xIbAdd
);
689 nCurKey
= pNumFmtShell
->GetCurNumFmtKey();
691 else if(nCurKey
== NUMKEY_UNDEFINED
)
692 { // something went wrong, e.g. in Writer #70281#
693 pNumFmtShell
->FindEntry(aFormat
, &nCurKey
);
701 bDataChanged
= ( nInitFormat
!= nCurKey
);
705 rCoreAttrs
->Put( SfxUInt32Item( nWhich
, nCurKey
) );
707 else if(SfxItemState::DEFAULT
== eItemState
)
709 rCoreAttrs
->ClearItem( nWhich
);
714 // List of changed user defined formats:
716 std::vector
<sal_uInt32
> const & aDelFormats
= pNumFmtShell
->GetUpdateData();
718 if ( !aDelFormats
.empty() )
721 pNumItem
->SetDelFormats( std::vector(aDelFormats
) );
725 rCoreAttrs
->Put( *pNumItem
);
729 SfxObjectShell
* pDocSh
= SfxObjectShell::Current();
730 DBG_ASSERT( pDocSh
, "DocShell not found!" );
732 pDocSh
->PutItem( *pNumItem
);
737 // Whether source format is to be taken or not:
739 if ( m_xCbSourceFormat
->get_sensitive() )
741 SfxItemState _eItemState
= rMyItemSet
.GetItemState( SID_ATTR_NUMBERFORMAT_SOURCE
, false );
742 const SfxBoolItem
* pBoolItem
=
743 GetItem( rMyItemSet
, SID_ATTR_NUMBERFORMAT_SOURCE
);
744 bool bOld
= pBoolItem
&& pBoolItem
->GetValue();
745 rCoreAttrs
->Put( SfxBoolItem( SID_ATTR_NUMBERFORMAT_SOURCE
, 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 const 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
);
918 m_xFtOptions
->set_sensitive(true);
919 if ( nCategory
== CAT_FRACTION
)
921 m_xFtDenominator
->set_sensitive(true);
922 m_xEdDenominator
->set_sensitive(true);
926 m_xFtDecimals
->set_sensitive(true);
927 m_xEdDecimals
->set_sensitive(true);
929 m_xFtLeadZeroes
->set_sensitive( nCategory
!= CAT_TIME
);
930 m_xEdLeadZeroes
->set_sensitive( nCategory
!= CAT_TIME
);
931 m_xBtnNegRed
->set_sensitive(true);
932 if ( nCategory
== CAT_NUMBER
&& m_xLbFormat
->get_selected_index() == 0 )
933 m_xEdDecimals
->set_text( "" ); //General format tdf#44399
935 if ( nCategory
== CAT_FRACTION
)
936 m_xEdDenominator
->set_value( nDecimals
);
938 m_xEdDecimals
->set_value( nDecimals
);
939 if ( nCategory
!= CAT_TIME
)
940 m_xEdLeadZeroes
->set_value( nZeroes
);
941 m_xBtnNegRed
->set_active( bNegRed
);
942 if ( nCategory
!= CAT_SCIENTIFIC
)
944 m_xBtnThousand
->set_sensitive( nCategory
!= CAT_TIME
945 && !pNumFmtShell
->IsNatNum12( theFormat
) );
946 m_xBtnThousand
->set_active( bThousand
&& nCategory
!= CAT_TIME
);
951 case CAT_USERDEFINED
:
956 m_xFtOptions
->set_sensitive(false);
957 m_xFtDecimals
->set_sensitive(false);
958 m_xEdDecimals
->set_sensitive(false);
959 m_xFtDenominator
->set_sensitive(false);
960 m_xEdDenominator
->set_sensitive(false);
961 m_xFtLeadZeroes
->set_sensitive(false);
962 m_xEdLeadZeroes
->set_sensitive(false);
963 m_xBtnNegRed
->set_sensitive(false);
964 m_xBtnThousand
->set_sensitive(false);
965 m_xBtnEngineering
->set_sensitive(false);
966 m_xEdDecimals
->set_text( OUString() );
967 m_xEdLeadZeroes
->set_text( OUString() );
968 m_xBtnNegRed
->set_active( false );
969 m_xBtnThousand
->set_active( false );
970 m_xBtnEngineering
->set_active( false );
975 /*************************************************************************
976 #* Method: UpdateFormatListBox_Impl
977 #*------------------------------------------------------------------------
979 #* Class: SvxNumberFormatTabPage
980 #* Function: Updates the format listbox and additionally the
981 #* string in the editbox is changed depending on
982 #* the bUpdateEdit flag.
983 #* Input: Flags for category and editbox.
986 #************************************************************************/
988 void SvxNumberFormatTabPage::UpdateFormatListBox_Impl
990 bool bCat
, // Category or country/language ListBox?
994 std::vector
<OUString
> aEntryList
;
995 short nFmtLbSelPos
= 0;
1000 nTmpCatPos
=nFixedCategory
;
1004 nTmpCatPos
=m_xLbCategory
->get_selected_index();
1010 if(nTmpCatPos
!=CAT_CURRENCY
)
1011 m_xLbCurrency
->hide();
1013 m_xLbCurrency
->show();
1015 pNumFmtShell
->CategoryChanged(nTmpCatPos
,nFmtLbSelPos
, aEntryList
);
1018 pNumFmtShell
->LanguageChanged(m_xLbLanguage
->get_active_id(),
1019 nFmtLbSelPos
,aEntryList
);
1021 REMOVE_DONTKNOW() // possibly UI-Enable
1024 if ( (!aEntryList
.empty()) && (nFmtLbSelPos
!= SELPOS_NONE
) )
1028 OUString aFormat
=aEntryList
[nFmtLbSelPos
];
1029 m_xEdFormat
->set_text(aFormat
);
1030 m_xFtComment
->set_label(pNumFmtShell
->GetComment4Entry(nFmtLbSelPos
));
1033 if(!bOneAreaFlag
|| !bCat
)
1035 FillFormatListBox_Impl( aEntryList
);
1036 m_xLbFormat
->select(nFmtLbSelPos
);
1038 m_xFtComment
->set_label(pNumFmtShell
->GetComment4Entry(nFmtLbSelPos
));
1039 if(pNumFmtShell
->GetUserDefined4Entry(nFmtLbSelPos
))
1041 if(pNumFmtShell
->GetComment4Entry(nFmtLbSelPos
).isEmpty())
1043 m_xFtComment
->set_label(m_xLbCategory
->get_text(1));
1046 ChangePreviewText( static_cast<sal_uInt16
>(nFmtLbSelPos
) );
1052 FillFormatListBox_Impl( aEntryList
);
1053 if(nFmtLbSelPos
!= SELPOS_NONE
)
1055 m_xLbFormat
->select(static_cast<sal_uInt16
>(nFmtLbSelPos
));
1057 m_xFtComment
->set_label(pNumFmtShell
->GetComment4Entry(nFmtLbSelPos
));
1058 if(pNumFmtShell
->GetUserDefined4Entry(nFmtLbSelPos
))
1060 if(pNumFmtShell
->GetComment4Entry(nFmtLbSelPos
).isEmpty())
1062 m_xFtComment
->set_label(m_xLbCategory
->get_text(1));
1068 m_xLbFormat
->select(-1);
1073 m_xEdFormat
->set_text( OUString() );
1074 m_aWndPreview
.NotifyChange( OUString() );
1083 * Change visible checkbox according to category format
1084 * if scientific format "Engineering notation"
1085 * else "Thousands separator"
1088 void SvxNumberFormatTabPage::UpdateThousandEngineeringCheckBox()
1090 bool bIsScientific
= m_xLbCategory
->get_selected_index() == CAT_SCIENTIFIC
;
1091 m_xBtnThousand
->set_visible( !bIsScientific
);
1092 m_xBtnEngineering
->set_visible( bIsScientific
);
1097 * Change visible Edit box and Fixed text according to category format
1098 * if fraction format "Denominator places"
1099 * else "Decimal places"
1102 void SvxNumberFormatTabPage::UpdateDecimalsDenominatorEditBox()
1104 bool bIsFraction
= m_xLbCategory
->get_selected_index() == CAT_FRACTION
;
1105 m_xFtDecimals
->set_visible( !bIsFraction
);
1106 m_xEdDecimals
->set_visible( !bIsFraction
);
1107 m_xFtDenominator
->set_visible( bIsFraction
);
1108 m_xEdDenominator
->set_visible( bIsFraction
);
1112 /*************************************************************************
1113 #* Handle: DoubleClickHdl_Impl
1114 #*------------------------------------------------------------------------
1116 #* Class: SvxNumberFormatTabPage
1117 #* Function: On a double click in the format listbox the
1118 #* value is adopted and the OK button pushed.
1119 #* Input: Pointer on the Listbox
1122 #************************************************************************/
1123 IMPL_LINK(SvxNumberFormatTabPage
, DoubleClickHdl_Impl
, weld::TreeView
&, rLb
, bool)
1125 SelFormatHdl_Impl(&rLb
);
1127 SfxOkDialogController
* pController
= GetDialogController();
1128 assert(pController
);
1129 weld::Button
& rOkButton
= pController
->GetOKButton();
1130 rOkButton
.clicked();
1135 /*************************************************************************
1136 #* Method: SelFormatHdl_Impl
1137 #*------------------------------------------------------------------------
1139 #* Class: SvxNumberFormatTabPage
1140 #* Function: Is called when the language, the category or the format
1141 #* is changed. Accordingly the settings are adjusted.
1142 #* Input: Pointer on the Listbox
1145 #************************************************************************/
1147 IMPL_LINK(SvxNumberFormatTabPage
, SelFormatClickHdl_Impl
, weld::Toggleable
&, rLb
, void)
1149 SelFormatHdl_Impl(&rLb
);
1152 IMPL_LINK(SvxNumberFormatTabPage
, SelFormatTreeListBoxHdl_Impl
, weld::TreeView
&, rLb
, void)
1154 SelFormatHdl_Impl(&rLb
);
1157 IMPL_LINK(SvxNumberFormatTabPage
, SelFormatListBoxHdl_Impl
, weld::ComboBox
&, rLb
, void)
1159 SelFormatHdl_Impl(&rLb
);
1162 void SvxNumberFormatTabPage::SelFormatHdl_Impl(weld::Widget
* pLb
)
1164 if (m_nLbFormatSelPosEdComment
!= SELPOS_NONE
)
1166 // Click handler is called before focus change handler, so finish
1167 // comment editing of previous format, otherwise a new format will have
1168 // the old comment displayed after LostFocusHdl_Impl() is called
1169 // later. Also, clicking into another category invalidates the format
1170 // list and SvxNumberFormatShell::SetComment4Entry() could either
1171 // access a wrong format from aCurEntryList[nEntry] or crash there if
1172 // the new vector has less elements.
1173 LostFocusHdl_Impl(*pLb
);
1176 if (pLb
== m_xCbSourceFormat
.get())
1178 EnableBySourceFormat_Impl(); // enable/disable everything else
1179 if ( m_xCbSourceFormat
->get_active() )
1180 return; // just disabled everything else
1182 // Reinit options enable/disable for current selection.
1184 // Current category may be UserDefined with no format entries defined.
1185 if (m_xLbFormat
->get_selected_index() == -1)
1186 pLb
= m_xLbCategory
.get(); // continue with the current category selected
1188 pLb
= m_xLbFormat
.get(); // continue with the current format selected
1191 sal_Int32 nTmpCatPos
;
1195 nTmpCatPos
=nFixedCategory
;
1199 nTmpCatPos
=m_xLbCategory
->get_selected_index();
1202 if (nTmpCatPos
==CAT_CURRENCY
&& pLb
== m_xLbCurrency
.get())
1203 pNumFmtShell
->SetCurrencySymbol(get_active_currency());
1205 // Format-ListBox ----------------------------------------------------
1206 if (pLb
== m_xLbFormat
.get())
1208 int nSelPos
= m_xLbFormat
->get_selected_index();
1209 short nFmtLbSelPos
= static_cast<short>(nSelPos
);
1211 OUString aFormat
= pNumFmtShell
->GetFormat4Entry(nFmtLbSelPos
);
1212 OUString aComment
= pNumFmtShell
->GetComment4Entry(nFmtLbSelPos
);
1214 if(pNumFmtShell
->GetUserDefined4Entry(nFmtLbSelPos
))
1216 if(aComment
.isEmpty())
1218 aComment
= m_xLbCategory
->get_text(1);
1222 if ( !aFormat
.isEmpty() )
1224 if (!m_xEdFormat
->has_focus())
1225 m_xEdFormat
->set_text( aFormat
);
1226 m_xFtComment
->set_label(aComment
);
1227 ChangePreviewText( static_cast<sal_uInt16
>(nSelPos
) );
1230 REMOVE_DONTKNOW() // possibly UI-Enable
1232 if ( pNumFmtShell
->FindEntry( aFormat
) )
1234 m_xIbAdd
->set_sensitive(false );
1235 bool bIsUserDef
=pNumFmtShell
->IsUserDefined( aFormat
);
1236 m_xIbRemove
->set_sensitive(bIsUserDef
);
1237 m_xIbInfo
->set_sensitive(bIsUserDef
);
1242 m_xIbAdd
->set_sensitive(true);
1243 m_xIbInfo
->set_sensitive(true);
1244 m_xIbRemove
->set_sensitive(false );
1245 m_xFtComment
->set_label(m_xEdComment
->get_text());
1248 UpdateOptions_Impl( false );
1254 // category-ListBox -------------------------------------------------
1255 if (pLb
== m_xLbCategory
.get() || pLb
== m_xLbCurrency
.get())
1257 UpdateFormatListBox_Impl( true, true );
1258 EditHdl_Impl( nullptr );
1259 UpdateOptions_Impl( false );
1265 // language/country-ListBox ----------------------------------------------
1266 if (pLb
== m_xLbLanguage
->get_widget())
1268 UpdateFormatListBox_Impl( false, true );
1269 EditHdl_Impl(m_xEdFormat
.get());
1276 /*************************************************************************
1277 #* Method: ClickHdl_Impl, weld::Button& rIB
1278 #*------------------------------------------------------------------------
1280 #* Class: SvxNumberFormatTabPage
1281 #* Function: Called when the add or delete button is pushed,
1282 #* adjusts the number format list.
1283 #* Input: Toolbox- Button
1286 #************************************************************************/
1288 IMPL_LINK( SvxNumberFormatTabPage
, ClickHdl_Impl
, weld::Button
&, rIB
, void)
1293 bool SvxNumberFormatTabPage::Click_Impl(const weld::Button
& rIB
)
1295 sal_uInt8 nReturn
= 0;
1296 constexpr sal_uInt8 nReturnChanged
= 0x1; // THE boolean return value
1297 constexpr sal_uInt8 nReturnAdded
= 0x2; // temp: format added
1298 constexpr sal_uInt8 nReturnOneArea
= 0x4; // temp: one area but category changed => ignored
1300 if (&rIB
== m_xIbAdd
.get())
1301 { // Also called from FillItemSet() if a temporary currency format has
1302 // to be added, not only if the Add button is enabled.
1303 OUString aFormat
= m_xEdFormat
->get_text();
1304 std::vector
<OUString
> aEntryList
;
1305 std::vector
<OUString
> a2EntryList
;
1306 sal_uInt16 nCatLbSelPos
= 0;
1307 short nFmtLbSelPos
= SELPOS_NONE
;
1308 sal_Int32 nErrPos
=0;
1310 pNumFmtShell
->SetCurCurrencyEntry(nullptr);
1311 bool bAdded
= pNumFmtShell
->AddFormat( aFormat
, nErrPos
,
1312 nCatLbSelPos
, nFmtLbSelPos
,
1315 nReturn
|= nReturnChanged
| nReturnAdded
;
1317 if (m_xEdComment
->get_visible())
1319 m_xEdFormat
->grab_focus();
1320 m_xEdComment
->hide();
1321 m_xFtComment
->show();
1322 m_xFtComment
->set_label(m_xEdComment
->get_text());
1325 if ( !nErrPos
) // Syntax ok?
1327 // May be sorted under a different locale if LCID was parsed.
1329 m_xLbLanguage
->set_active_id(pNumFmtShell
->GetCurLanguage());
1331 if (nCatLbSelPos
==CAT_CURRENCY
)
1332 set_active_currency(pNumFmtShell
->GetCurrencySymbol());
1334 if(bOneAreaFlag
&& (nFixedCategory
!=nCatLbSelPos
))
1336 if(bAdded
) aEntryList
.clear();
1337 pNumFmtShell
->RemoveFormat( aFormat
,
1341 a2EntryList
.clear();
1342 m_xEdFormat
->grab_focus();
1343 m_xEdFormat
->select_region(0, -1);
1344 nReturn
|= nReturnOneArea
;
1348 if ( bAdded
&& (nFmtLbSelPos
!= SELPOS_NONE
) )
1350 // everything all right
1351 if(bOneAreaFlag
) //@@ ???
1354 SetCategory(nCatLbSelPos
);
1356 FillFormatListBox_Impl( aEntryList
);
1357 if (m_xEdComment
->get_text()!=m_xLbCategory
->get_text(1))
1359 pNumFmtShell
->SetComment4Entry(nFmtLbSelPos
,
1360 m_xEdComment
->get_text());
1364 pNumFmtShell
->SetComment4Entry(nFmtLbSelPos
,
1367 m_xLbFormat
->select(static_cast<sal_uInt16
>(nFmtLbSelPos
));
1368 m_xEdFormat
->set_text( aFormat
);
1370 m_xEdComment
->set_text(m_xLbCategory
->get_text(1)); // String for user defined
1372 ChangePreviewText( static_cast<sal_uInt16
>(nFmtLbSelPos
) );
1376 else // syntax error
1378 m_xEdFormat
->grab_focus();
1379 m_xEdFormat
->select_region(nErrPos
== -1 ? m_xEdFormat
->get_text().getLength() : nErrPos
, -1);
1381 EditHdl_Impl(m_xEdFormat
.get());
1382 nReturn
= ((nReturn
& nReturnOneArea
) ? 0 : (nReturn
& nReturnChanged
));
1385 a2EntryList
.clear();
1387 else if (&rIB
== m_xIbRemove
.get())
1389 OUString aFormat
= m_xEdFormat
->get_text();
1390 std::vector
<OUString
> aEntryList
;
1391 sal_uInt16 nCatLbSelPos
= 0;
1392 short nFmtLbSelPos
= SELPOS_NONE
;
1394 pNumFmtShell
->RemoveFormat( aFormat
,
1399 m_xEdComment
->set_text(m_xLbCategory
->get_text(1));
1401 if( nFmtLbSelPos
>=0 && o3tl::make_unsigned(nFmtLbSelPos
)<aEntryList
.size() )
1403 aFormat
= aEntryList
[nFmtLbSelPos
];
1406 FillFormatListBox_Impl( aEntryList
);
1408 if ( nFmtLbSelPos
!= SELPOS_NONE
)
1410 if(bOneAreaFlag
) //@@ ???
1413 SetCategory(nCatLbSelPos
);
1415 m_xLbFormat
->select(static_cast<sal_uInt16
>(nFmtLbSelPos
));
1416 m_xEdFormat
->set_text( aFormat
);
1417 ChangePreviewText( static_cast<sal_uInt16
>(nFmtLbSelPos
) );
1421 // set to "all/standard"
1423 SelFormatHdl_Impl(m_xLbCategory
.get());
1426 EditHdl_Impl(m_xEdFormat
.get());
1430 else if (&rIB
== m_xIbInfo
.get())
1432 if (!m_xEdComment
->get_visible())
1434 if (!m_xIbAdd
->get_sensitive())
1435 // Editing for existing format.
1436 m_nLbFormatSelPosEdComment
= m_xLbFormat
->get_selected_index();
1438 m_xEdComment
->set_text(m_xFtComment
->get_label());
1439 m_xEdComment
->show();
1440 m_xFtComment
->hide();
1441 m_xEdComment
->grab_focus();
1445 m_xEdFormat
->grab_focus();
1446 m_xFtComment
->set_label( m_xEdComment
->get_text());
1447 m_xEdComment
->hide();
1448 m_xFtComment
->show();
1456 /*************************************************************************
1457 #* Method: EditHdl_Impl
1458 #*------------------------------------------------------------------------
1460 #* Class: SvxNumberFormatTabPage
1461 #* Function: When the entry in the edit field is changed
1462 #* the preview is updated and
1463 #* Input: Pointer on Editbox
1466 #************************************************************************/
1468 IMPL_LINK(SvxNumberFormatTabPage
, EditModifyHdl_Impl
, weld::Entry
&, rEdit
, void)
1470 EditHdl_Impl(&rEdit
);
1473 void SvxNumberFormatTabPage::EditHdl_Impl(const weld::Entry
* pEdFormat
)
1475 sal_uInt32 nCurKey
= NUMKEY_UNDEFINED
;
1477 if ( m_xEdFormat
->get_text().isEmpty() )
1479 m_xIbAdd
->set_sensitive(false );
1480 m_xIbRemove
->set_sensitive(false );
1481 m_xIbInfo
->set_sensitive(false );
1482 m_xFtComment
->set_label(OUString());
1486 OUString aFormat
= m_xEdFormat
->get_text();
1487 MakePreviewText( aFormat
);
1489 if ( pNumFmtShell
->FindEntry( aFormat
, &nCurKey
) )
1491 m_xIbAdd
->set_sensitive(false );
1492 bool bUserDef
=pNumFmtShell
->IsUserDefined( aFormat
);
1494 m_xIbRemove
->set_sensitive(bUserDef
);
1495 m_xIbInfo
->set_sensitive(bUserDef
);
1499 sal_uInt16 nTmpCurPos
=pNumFmtShell
->FindCurrencyFormat(aFormat
);
1500 if (nTmpCurPos
!= sal_uInt16(-1))
1501 set_active_currency(nTmpCurPos
);
1503 short nPosi
=pNumFmtShell
->GetListPos4Entry( nCurKey
, aFormat
);
1505 m_xLbFormat
->select(static_cast<sal_uInt16
>(nPosi
));
1511 m_xIbAdd
->set_sensitive(true);
1512 m_xIbInfo
->set_sensitive(true);
1513 m_xIbRemove
->set_sensitive(false );
1515 m_xFtComment
->set_label(m_xEdComment
->get_text());
1522 pNumFmtShell
->SetCurNumFmtKey( nCurKey
);
1523 UpdateOptions_Impl( true );
1528 /*************************************************************************
1529 #* Method: NotifyChange
1530 #*------------------------------------------------------------------------
1532 #* Class: SvxNumberFormatTabPage
1533 #* Function: Does changes in the number attributes.
1534 #* Input: Options- Controls
1537 #************************************************************************/
1539 IMPL_LINK(SvxNumberFormatTabPage
, OptClickHdl_Impl
, weld::Toggleable
&, rOptCtrl
, void)
1541 OptHdl_Impl(&rOptCtrl
);
1544 IMPL_LINK(SvxNumberFormatTabPage
, OptEditHdl_Impl
, weld::SpinButton
&, rEdit
, void)
1546 OptHdl_Impl(&rEdit
);
1549 void SvxNumberFormatTabPage::OptHdl_Impl(const weld::Widget
* pOptCtrl
)
1551 if ( !(pOptCtrl
== m_xEdLeadZeroes
.get()
1552 || pOptCtrl
== m_xEdDecimals
.get()
1553 || pOptCtrl
== m_xEdDenominator
.get()
1554 || pOptCtrl
== m_xBtnNegRed
.get()
1555 || pOptCtrl
== m_xBtnThousand
.get()
1556 || pOptCtrl
== m_xBtnEngineering
.get()))
1560 bool bThousand
= ( m_xBtnThousand
->get_visible() && m_xBtnThousand
->get_sensitive() && m_xBtnThousand
->get_active() )
1561 || ( m_xBtnEngineering
->get_visible() && m_xBtnEngineering
->get_sensitive() && m_xBtnEngineering
->get_active() );
1562 bool bNegRed
= m_xBtnNegRed
->get_sensitive() && m_xBtnNegRed
->get_active();
1563 sal_uInt16 nPrecision
= (m_xEdDecimals
->get_sensitive() && m_xEdDecimals
->get_visible())
1564 ? static_cast<sal_uInt16
>(m_xEdDecimals
->get_value())
1565 : ( (m_xEdDenominator
->get_sensitive() && m_xEdDenominator
->get_visible())
1566 ? static_cast<sal_uInt16
>(m_xEdDenominator
->get_value())
1568 sal_uInt16 nLeadZeroes
= (m_xEdLeadZeroes
->get_sensitive())
1569 ? static_cast<sal_uInt16
>(m_xEdLeadZeroes
->get_value())
1571 if ( pNumFmtShell
->GetStandardName() == m_xEdFormat
->get_text() )
1573 m_xEdDecimals
->set_value(nPrecision
);
1576 pNumFmtShell
->MakeFormat( aFormat
,
1578 nPrecision
, nLeadZeroes
,
1579 static_cast<sal_uInt16
>(m_xLbFormat
->get_selected_index()) );
1581 m_xEdFormat
->set_text( aFormat
);
1582 MakePreviewText( aFormat
);
1584 if ( pNumFmtShell
->FindEntry( aFormat
) )
1586 m_xIbAdd
->set_sensitive(false );
1587 bool bUserDef
=pNumFmtShell
->IsUserDefined( aFormat
);
1588 m_xIbRemove
->set_sensitive(bUserDef
);
1589 m_xIbInfo
->set_sensitive(bUserDef
);
1590 EditHdl_Impl(m_xEdFormat
.get());
1595 EditHdl_Impl( nullptr );
1596 m_xLbFormat
->select(-1);
1600 /*************************************************************************
1601 #* Method: LostFocusHdl_Impl
1602 #*------------------------------------------------------------------------
1604 #* Class: SvxNumberFormatTabPage
1605 #* Function: Does changes in the number attributes.
1606 #* Input: Options- Controls
1609 #************************************************************************/
1611 IMPL_LINK_NOARG(SvxNumberFormatTabPage
, LostFocusHdl_Impl
, weld::Widget
&, void)
1616 const bool bAddSensitive
= m_xIbAdd
->get_sensitive();
1617 if (bAddSensitive
|| m_nLbFormatSelPosEdComment
!= SELPOS_NONE
)
1618 // Comment editing was possible.
1619 m_xFtComment
->set_label(m_xEdComment
->get_text());
1621 m_xEdComment
->hide();
1622 m_xFtComment
->show();
1623 if (m_nLbFormatSelPosEdComment
!= SELPOS_NONE
)
1625 // Save edited comment of existing format.
1626 pNumFmtShell
->SetComment4Entry( m_nLbFormatSelPosEdComment
, m_xEdComment
->get_text());
1627 m_nLbFormatSelPosEdComment
= SELPOS_NONE
;
1631 // String for user defined, if present
1632 OUString sEntry
= m_xLbCategory
->n_children() > 1 ? m_xLbCategory
->get_text(1) : OUString();
1633 m_xEdComment
->set_text(sEntry
);
1637 /*************************************************************************
1638 #* Method: NotifyChange
1639 #*------------------------------------------------------------------------
1641 #* Class: SvxNumberFormatTabPage
1642 #* Function: Does changes in the number attributes.
1643 #* Input: Options- Controls
1646 #************************************************************************/
1648 OUString
SvxNumberFormatTabPage::GetExpColorString(
1649 const Color
*& rpPreviewColor
, const OUString
& rFormatStr
, short nTmpCatPos
)
1651 SvxNumValCategory i
;
1654 case CAT_ALL
: i
=SvxNumValCategory::Standard
; break;
1656 case CAT_NUMBER
: i
=SvxNumValCategory::Standard
; break;
1658 case CAT_PERCENT
: i
=SvxNumValCategory::Percent
; break;
1660 case CAT_CURRENCY
: i
=SvxNumValCategory::Currency
; break;
1662 case CAT_DATE
: i
=SvxNumValCategory::Date
; break;
1664 case CAT_TIME
: i
=SvxNumValCategory::Time
; break;
1666 case CAT_SCIENTIFIC
: i
=SvxNumValCategory::Scientific
; break;
1668 case CAT_FRACTION
: i
=SvxNumValCategory::Fraction
; break;
1670 case CAT_BOOLEAN
: i
=SvxNumValCategory::Boolean
; break;
1672 case CAT_USERDEFINED
: i
=SvxNumValCategory::Standard
; break;
1675 default: i
=SvxNumValCategory::NoValue
;break;
1677 double fVal
= fSvxNumValConst
[i
];
1679 // use lower number for long NatNum12 transliteration
1680 if ( ( CAT_CURRENCY
== nTmpCatPos
|| CAT_NUMBER
== nTmpCatPos
) &&
1681 rFormatStr
.indexOf("NatNum12") >= 0 )
1683 if ( CAT_CURRENCY
== nTmpCatPos
)
1686 fVal
= 100; // show also title case for English: One Hundred
1689 OUString aPreviewString
;
1690 pNumFmtShell
->MakePrevStringFromVal( rFormatStr
, aPreviewString
, rpPreviewColor
, fVal
);
1691 return aPreviewString
;
1694 void SvxNumberFormatTabPage::MakePreviewText( const OUString
& rFormat
)
1696 OUString aPreviewString
;
1697 const Color
* pPreviewColor
= nullptr;
1698 pNumFmtShell
->MakePreviewString( rFormat
, aPreviewString
, pPreviewColor
);
1699 m_aWndPreview
.NotifyChange( aPreviewString
, pPreviewColor
);
1702 void SvxNumberFormatTabPage::ChangePreviewText( sal_uInt16 nPos
)
1704 OUString aPreviewString
;
1705 const Color
* pPreviewColor
= nullptr;
1706 pNumFmtShell
->FormatChanged( nPos
, aPreviewString
, pPreviewColor
);
1707 m_aWndPreview
.NotifyChange( aPreviewString
, pPreviewColor
);
1710 void SvxNumberFormatTabPage::FillCurrencyBox()
1712 std::vector
<OUString
> aList
;
1714 sal_uInt16 nSelPos
=0;
1715 pNumFmtShell
->GetCurrencySymbols(aList
, &nSelPos
);
1717 m_xLbCurrency
->freeze();
1718 m_xLbCurrency
->clear();
1719 bLegacyAutomaticCurrency
= false;
1720 for (std::vector
<OUString
>::iterator i
= aList
.begin() + 1;i
!= aList
.end(); ++i
)
1721 m_xLbCurrency
->append_text(*i
);
1722 m_xLbCurrency
->thaw();
1724 set_active_currency(nSelPos
);
1727 void SvxNumberFormatTabPage::SetCategory(sal_uInt16 nPos
)
1729 int nCurCategory
= m_xLbCategory
->get_selected_index();
1730 sal_uInt16 nTmpCatPos
;
1734 nTmpCatPos
=nFixedCategory
;
1741 if(m_xLbCategory
->n_children()==1 || nCurCategory
!=nPos
)
1743 if(nTmpCatPos
!=CAT_CURRENCY
)
1744 m_xLbCurrency
->hide();
1746 m_xLbCurrency
->show();
1748 m_xLbCategory
->select(nPos
);
1751 /* to support Writer text field language handling an
1752 additional entry needs to be inserted into the ListBox
1753 which marks a certain language as automatically detected
1754 Additionally the "Default" language is removed
1756 void SvxNumberFormatTabPage::AddAutomaticLanguage_Impl(LanguageType eAutoLang
, bool bSelect
)
1758 m_xLbLanguage
->remove_id(LANGUAGE_SYSTEM
);
1759 m_xLbLanguage
->append(eAutoLang
, sAutomaticLangEntry
);
1761 m_xLbLanguage
->set_active_id(eAutoLang
);
1764 void SvxNumberFormatTabPage::PageCreated(const SfxAllItemSet
& aSet
)
1766 const SvxNumberInfoItem
* pNumberInfoItem
= aSet
.GetItem
<SvxNumberInfoItem
>(SID_ATTR_NUMBERFORMAT_INFO
, false);
1767 if (pNumberInfoItem
&& !pNumItem
)
1768 pNumItem
.reset(pNumberInfoItem
->Clone());
1771 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */