LibreOffice Module sw (master)  1
numfmtlb.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
19 
20 #include <hintids.hxx>
21 #include <editeng/unolingu.hxx>
23 #include <i18nlangtag/lang.h>
24 #include <svl/zformat.hxx>
25 #include <svl/eitem.hxx>
26 #include <svx/svxids.hrc>
27 #include <svx/numinf.hxx>
28 #include <svx/flagsdef.hxx>
29 #include <svl/itemset.hxx>
30 #include <docsh.hxx>
31 #include <swtypes.hxx>
32 #include <swmodule.hxx>
33 #include <view.hxx>
34 #include <wrtsh.hxx>
35 #include <numfmtlb.hxx>
36 #include <strings.hrc>
37 #include <swabstdlg.hxx>
38 #include <unomid.h>
39 #include <sfx2/viewfrm.hxx>
40 #include <memory>
41 
42 using namespace ::com::sun::star::uno;
43 using namespace ::com::sun::star::lang;
44 
52  ListBox ( pWin, nStyle ),
53  nCurrFormatType (SvNumFormatType::ALL),
54  mbCurrFormatTypeNeedsInit(true),
55  nStdEntry (0),
56  bOneArea (false),
57  nDefFormat (0),
58  bShowLanguageControl(false),
59  bUseAutomaticLanguage(true)
60 {
61  Init();
62 }
63 
64 extern "C" SAL_DLLPUBLIC_EXPORT void makeNumFormatListBox(VclPtr<vcl::Window> & rRet, const VclPtr<vcl::Window> & pParent, VclBuilder::stringmap & rMap)
65 {
66  static_assert(std::is_same_v<std::remove_pointer_t<VclBuilder::customMakeWidget>,
67  decltype(makeNumFormatListBox)>);
69 
70  bool bDropdown = BuilderUtils::extractDropdown(rMap);
71 
72  if (bDropdown)
73  nBits |= WB_DROPDOWN;
74  else
75  nBits |= WB_BORDER;
76 
77  VclPtrInstance<NumFormatListBox> pListBox(pParent, nBits|WB_SIMPLEMODE);
78 
79  if (bDropdown)
80  pListBox->EnableAutoSize(true);
81 
82  rRet = pListBox;
83 }
84 
86 {
87  SwView *pView = GetActiveView();
88 
89  if (pView)
90  eCurLanguage = pView->GetWrtShell().GetCurLang();
91  else
93 
94  SetFormatType(SvNumFormatType::NUMBER);
96 
97  SetSelectHdl(LINK(this, NumFormatListBox, SelectHdl));
98 }
99 
101 {
102  disposeOnce();
103 }
104 
106 {
108  (nCurrFormatType & nFormatType)) // there are mixed formats, like for example DateTime
109  return;
110 
111  SwView *pView = GetActiveView();
112  OSL_ENSURE(pView, "no view found");
113  if(!pView)
114  return;
115  SwWrtShell &rSh = pView->GetWrtShell();
116  SvNumberFormatter* pFormatter = rSh.GetNumberFormatter();
117 
118  Clear(); // Remove all entries from the Listbox
119 
120  NfIndexTableOffset eOffsetStart = NF_NUMBER_START;
121  NfIndexTableOffset eOffsetEnd = NF_NUMBER_START;
122 
123  switch( nFormatType )
124  {
125  case SvNumFormatType::NUMBER:
126  eOffsetStart=NF_NUMBER_START;
127  eOffsetEnd=NF_NUMBER_END;
128  break;
129 
130  case SvNumFormatType::PERCENT:
131  eOffsetStart=NF_PERCENT_START;
132  eOffsetEnd=NF_PERCENT_END;
133  break;
134 
135  case SvNumFormatType::CURRENCY:
136  eOffsetStart=NF_CURRENCY_START;
137  eOffsetEnd=NF_CURRENCY_END;
138  break;
139 
140  case SvNumFormatType::DATETIME:
141  eOffsetStart=NF_DATE_START;
142  eOffsetEnd=NF_TIME_END;
143  break;
144 
145  case SvNumFormatType::DATE:
146  eOffsetStart=NF_DATE_START;
147  eOffsetEnd=NF_DATE_END;
148  break;
149 
150  case SvNumFormatType::TIME:
151  eOffsetStart=NF_TIME_START;
152  eOffsetEnd=NF_TIME_END;
153  break;
154 
155  case SvNumFormatType::SCIENTIFIC:
156  eOffsetStart=NF_SCIENTIFIC_START;
157  eOffsetEnd=NF_SCIENTIFIC_END;
158  break;
159 
160  case SvNumFormatType::FRACTION:
161  eOffsetStart=NF_FRACTION_START;
162  eOffsetEnd=NF_FRACTION_END;
163  break;
164 
165  case SvNumFormatType::LOGICAL:
166  eOffsetStart=NF_BOOLEAN;
167  eOffsetEnd=NF_BOOLEAN;
168  break;
169 
170  case SvNumFormatType::TEXT:
171  eOffsetStart=NF_TEXT;
172  eOffsetEnd=NF_TEXT;
173  break;
174 
175  case SvNumFormatType::ALL:
176  eOffsetStart=NF_NUMERIC_START;
177  eOffsetEnd = NfIndexTableOffset( NF_INDEX_TABLE_ENTRIES - 1 );
178  break;
179 
180  default:
181  OSL_FAIL("what a format?");
182  break;
183  }
184 
185  const SvNumberformat* pFormat;
186  sal_Int32 i = 0;
187  Color* pCol;
188  double fVal = GetDefValue( nFormatType );
189  OUString sValue;
190 
191  const sal_uInt32 nSysNumFormat = pFormatter->GetFormatIndex(
193  const sal_uInt32 nSysShortDateFormat = pFormatter->GetFormatIndex(
195  const sal_uInt32 nSysLongDateFormat = pFormatter->GetFormatIndex(
197 
198  for( long nIndex = eOffsetStart; nIndex <= eOffsetEnd; ++nIndex )
199  {
200  const sal_uInt32 nFormat = pFormatter->GetFormatIndex(
201  static_cast<NfIndexTableOffset>(nIndex), eCurLanguage );
202  pFormat = pFormatter->GetEntry( nFormat );
203 
204  if( nFormat == pFormatter->GetFormatIndex( NF_NUMBER_STANDARD,
205  eCurLanguage )
206  || const_cast<SvNumberformat*>(pFormat)->GetOutputString( fVal, sValue, &pCol )
207  || nFormatType == SvNumFormatType::UNDEFINED )
208  {
209  sValue = pFormat->GetFormatstring();
210  }
211  else if( nFormatType == SvNumFormatType::TEXT )
212  {
213  pFormatter->GetOutputString( "\"ABC\"", nFormat, sValue, &pCol);
214  }
215 
216  if (nFormat != nSysNumFormat &&
217  nFormat != nSysShortDateFormat &&
218  nFormat != nSysLongDateFormat)
219  {
220  const sal_Int32 nPos = InsertEntry( sValue );
221  SetEntryData( nPos, reinterpret_cast<void*>(nFormat) );
222 
223  if( nFormat == pFormatter->GetStandardFormat(
224  nFormatType, eCurLanguage ) )
225  nStdEntry = i;
226  ++i;
227  }
228  }
229 
230  const sal_Int32 nPos = InsertEntry(SwResId( STR_DEFINE_NUMBERFORMAT ));
231  SetEntryData( nPos, nullptr );
232 
234 
235  nCurrFormatType = nFormatType;
237 
238 }
239 
240 namespace
241 {
242 
243 bool lcl_isSystemFormat(sal_uInt32 nDefaultFormat, SvNumberFormatter* pFormatter, LanguageType eCurLanguage)
244 {
245  const sal_uInt32 nSysNumFormat = pFormatter->GetFormatIndex(NF_NUMBER_SYSTEM, eCurLanguage);
246  if (nDefaultFormat == nSysNumFormat)
247  return true;
248  const sal_uInt32 nSysShortDateFormat = pFormatter->GetFormatIndex(NF_DATE_SYSTEM_SHORT, eCurLanguage);
249  if (nDefaultFormat == nSysShortDateFormat)
250  return true;
251  const sal_uInt32 nSysLongDateFormat = pFormatter->GetFormatIndex(NF_DATE_SYSTEM_LONG, eCurLanguage);
252  if (nDefaultFormat == nSysLongDateFormat)
253  return true;
254 
255  if ( eCurLanguage != GetAppLanguage() )
256  return false;
257 
258  if (nDefaultFormat == pFormatter->GetFormatForLanguageIfBuiltIn(nSysNumFormat, LANGUAGE_SYSTEM))
259  return true;
260  if (nDefaultFormat == pFormatter->GetFormatForLanguageIfBuiltIn(nSysShortDateFormat, LANGUAGE_SYSTEM))
261  return true;
262  if (nDefaultFormat == pFormatter->GetFormatForLanguageIfBuiltIn(nSysLongDateFormat, LANGUAGE_SYSTEM))
263  return true;
264 
265  return false;
266 }
267 
268 }
269 
270 void NumFormatListBox::SetDefFormat(const sal_uInt32 nDefaultFormat)
271 {
272  if (nDefaultFormat == NUMBERFORMAT_ENTRY_NOT_FOUND)
273  {
274  nDefFormat = nDefaultFormat;
275  return;
276  }
277 
278  SwView *pView = GetActiveView();
279  OSL_ENSURE(pView, "no view found");
280  if(!pView)
281  return;
282  SwWrtShell &rSh = pView->GetWrtShell();
283  SvNumberFormatter* pFormatter = rSh.GetNumberFormatter();
284 
285  SvNumFormatType nType = pFormatter->GetType(nDefaultFormat);
286 
287  SetFormatType(nType);
288 
289  sal_uInt32 nFormat = pFormatter->GetFormatForLanguageIfBuiltIn(nDefaultFormat, eCurLanguage);
290 
291  for (sal_Int32 i = 0; i < GetEntryCount(); i++)
292  {
293  if (nFormat == static_cast<sal_uInt32>(reinterpret_cast<sal_uIntPtr>(GetEntryData(i))))
294  {
295  SelectEntryPos(i);
296  nStdEntry = i;
297  nDefFormat = GetFormat();
298  return;
299  }
300  }
301 
302  // No entry found:
303  OUString sValue;
304  Color* pCol = nullptr;
305 
306  if (nType == SvNumFormatType::TEXT)
307  {
308  pFormatter->GetOutputString("\"ABC\"", nDefaultFormat, sValue, &pCol);
309  }
310  else
311  {
312  pFormatter->GetOutputString(GetDefValue(nType), nDefaultFormat, sValue, &pCol);
313  }
314 
315  sal_Int32 nPos = 0;
316  while (static_cast<sal_uInt32>(reinterpret_cast<sal_uIntPtr>(GetEntryData(nPos))) == NUMBERFORMAT_ENTRY_NOT_FOUND)
317  nPos++;
318 
319  if ( lcl_isSystemFormat(nDefaultFormat, pFormatter, eCurLanguage) )
320  {
321  sValue += SwResId(RID_STR_SYSTEM);
322  }
323 
324  nPos = InsertEntry(sValue, nPos); // Insert as first numeric entry
325  SetEntryData(nPos, reinterpret_cast<void*>(nDefaultFormat));
326  SelectEntryPos(nPos);
327  nDefFormat = GetFormat();
328 }
329 
330 sal_uInt32 NumFormatListBox::GetFormat() const
331 {
332  sal_Int32 nPos = GetSelectedEntryPos();
333 
334  return static_cast<sal_uInt32>(reinterpret_cast<sal_uIntPtr>(GetEntryData(nPos)));
335 }
336 
337 IMPL_LINK( NumFormatListBox, SelectHdl, ListBox&, rBox, void )
338 {
339  const sal_Int32 nPos = rBox.GetSelectedEntryPos();
340  OUString sDefine(SwResId( STR_DEFINE_NUMBERFORMAT ));
341  SwView *pView = GetActiveView();
342 
343  if( !pView || nPos != rBox.GetEntryCount() - 1 ||
344  rBox.GetEntry( nPos ) != sDefine )
345  return;
346 
347  SwWrtShell &rSh = pView->GetWrtShell();
348  SvNumberFormatter* pFormatter = rSh.GetNumberFormatter();
349 
350  SfxItemSet aCoreSet(
351  rSh.GetAttrPool(),
352  svl::Items<
353  SID_ATTR_NUMBERFORMAT_VALUE, SID_ATTR_NUMBERFORMAT_INFO,
354  SID_ATTR_NUMBERFORMAT_ONE_AREA, SID_ATTR_NUMBERFORMAT_ONE_AREA,
355  SID_ATTR_NUMBERFORMAT_NOLANGUAGE,
356  SID_ATTR_NUMBERFORMAT_NOLANGUAGE,
357  SID_ATTR_NUMBERFORMAT_ADD_AUTO,
358  SID_ATTR_NUMBERFORMAT_ADD_AUTO>{});
359 
360  double fValue = GetDefValue( nCurrFormatType);
361 
362  sal_uInt32 nFormat = pFormatter->GetStandardFormat( nCurrFormatType, eCurLanguage);
363  aCoreSet.Put( SfxUInt32Item( SID_ATTR_NUMBERFORMAT_VALUE, nFormat ));
364 
365  aCoreSet.Put( SvxNumberInfoItem( pFormatter, fValue,
366  SID_ATTR_NUMBERFORMAT_INFO ) );
367 
368  if( (SvNumFormatType::DATE | SvNumFormatType::TIME) & nCurrFormatType )
369  aCoreSet.Put(SfxBoolItem(SID_ATTR_NUMBERFORMAT_ONE_AREA, bOneArea));
370 
371  aCoreSet.Put(SfxBoolItem(SID_ATTR_NUMBERFORMAT_NOLANGUAGE, !bShowLanguageControl));
372  aCoreSet.Put(SfxBoolItem(SID_ATTR_NUMBERFORMAT_ADD_AUTO, bUseAutomaticLanguage));
373 
376 
377  if (RET_OK == pDlg->Execute())
378  {
379  const SfxPoolItem* pItem = pView->GetDocShell()->
380  GetItem( SID_ATTR_NUMBERFORMAT_INFO );
381 
382  if( pItem )
383  {
384  for ( sal_uInt32 key : static_cast<const SvxNumberInfoItem*>(pItem)->GetDelFormats() )
385  pFormatter->DeleteEntry( key );
386  }
387 
388  const SfxItemSet* pOutSet = pDlg->GetOutputItemSet();
389  if( SfxItemState::SET == pOutSet->GetItemState(
390  SID_ATTR_NUMBERFORMAT_VALUE, false, &pItem ))
391  {
392  sal_uInt32 nNumberFormat = static_cast<const SfxUInt32Item*>(pItem)->GetValue();
393  // oj #105473# change order of calls
394  const SvNumberformat* pFormat = pFormatter->GetEntry(nNumberFormat);
395  if( pFormat )
396  eCurLanguage = pFormat->GetLanguage();
397  // SetDefFormat uses eCurLanguage to look for if this format already in the list
398  SetDefFormat(nNumberFormat);
399  }
400  if( bShowLanguageControl && SfxItemState::SET == pOutSet->GetItemState(
401  SID_ATTR_NUMBERFORMAT_ADD_AUTO, false, &pItem ))
402  {
403  bUseAutomaticLanguage = static_cast<const SfxBoolItem*>(pItem)->GetValue();
404  }
405  }
406  else
407  SetDefFormat(nFormat);
408 
409 }
410 
412 {
413  SvxNumValCategory nDefValue = SvxNumValCategory::Standard;
414 
415  switch (nFormatType)
416  {
417  case SvNumFormatType::DATE:
418  case SvNumFormatType::DATE|SvNumFormatType::TIME:
419  nDefValue = SvxNumValCategory::Date;
420  break;
421 
422  case SvNumFormatType::TIME:
423  nDefValue = SvxNumValCategory::Time;
424  break;
425 
426  case SvNumFormatType::TEXT:
427  case SvNumFormatType::UNDEFINED:
428  nDefValue = SvxNumValCategory::Standard;
429  break;
430 
431  case SvNumFormatType::CURRENCY:
432  nDefValue = SvxNumValCategory::Currency;
433  break;
434 
435  case SvNumFormatType::PERCENT:
436  nDefValue = SvxNumValCategory::Percent;
437  break;
438 
439  case SvNumFormatType::LOGICAL:
440  nDefValue = SvxNumValCategory::Boolean;
441  break;
442 
443  default:
444  nDefValue = SvxNumValCategory::Standard;
445  break;
446  }
447 
448  return fSvxNumValConst[nDefValue];
449 }
450 
452 {
453  ListBox::Clear();
455  nCurrFormatType = SvNumFormatType::ALL;
456 }
457 
459  : nCurrFormatType(SvNumFormatType::ALL)
460  , mbCurrFormatTypeNeedsInit(true)
461  , nStdEntry(0)
462  , bOneArea(false)
463  , nDefFormat(0)
464  , bShowLanguageControl(false)
465  , bUseAutomaticLanguage(true)
466 {
467 }
468 
469 SwNumFormatListBox::SwNumFormatListBox(std::unique_ptr<weld::ComboBox> xControl)
470  : mxControl(std::move(xControl))
471 {
472  Init();
473 }
474 
475 SwNumFormatTreeView::SwNumFormatTreeView(std::unique_ptr<weld::TreeView> xControl)
476  : mxControl(std::move(xControl))
477 {
478  Init();
479 }
480 
482 {
483  SwView *pView = GetActiveView();
484 
485  if (pView)
486  eCurLanguage = pView->GetWrtShell().GetCurLang();
487  else
488  eCurLanguage = SvtSysLocale().GetLanguageTag().getLanguageType();
489 
490  SetFormatType(SvNumFormatType::NUMBER);
492 }
493 
495 {
497 
498  mxControl->connect_changed(LINK(this, SwNumFormatListBox, SelectHdl));
499 }
500 
502 {
504 
505  mxControl->connect_changed(LINK(this, SwNumFormatTreeView, SelectHdl));
506 }
507 
509 {
511  (nCurrFormatType & nFormatType)) // there are mixed formats, like for example DateTime
512  return;
513 
514  SwView *pView = GetActiveView();
515  OSL_ENSURE(pView, "no view found");
516  if(!pView)
517  return;
518  SwWrtShell &rSh = pView->GetWrtShell();
519  SvNumberFormatter* pFormatter = rSh.GetNumberFormatter();
520 
521  clear(); // Remove all entries from the Listbox
522 
523  NfIndexTableOffset eOffsetStart = NF_NUMBER_START;
524  NfIndexTableOffset eOffsetEnd = NF_NUMBER_START;
525 
526  switch( nFormatType )
527  {
528  case SvNumFormatType::NUMBER:
529  eOffsetStart=NF_NUMBER_START;
530  eOffsetEnd=NF_NUMBER_END;
531  break;
532 
533  case SvNumFormatType::PERCENT:
534  eOffsetStart=NF_PERCENT_START;
535  eOffsetEnd=NF_PERCENT_END;
536  break;
537 
538  case SvNumFormatType::CURRENCY:
539  eOffsetStart=NF_CURRENCY_START;
540  eOffsetEnd=NF_CURRENCY_END;
541  break;
542 
543  case SvNumFormatType::DATETIME:
544  eOffsetStart=NF_DATE_START;
545  eOffsetEnd=NF_TIME_END;
546  break;
547 
548  case SvNumFormatType::DATE:
549  eOffsetStart=NF_DATE_START;
550  eOffsetEnd=NF_DATE_END;
551  break;
552 
553  case SvNumFormatType::TIME:
554  eOffsetStart=NF_TIME_START;
555  eOffsetEnd=NF_TIME_END;
556  break;
557 
558  case SvNumFormatType::SCIENTIFIC:
559  eOffsetStart=NF_SCIENTIFIC_START;
560  eOffsetEnd=NF_SCIENTIFIC_END;
561  break;
562 
563  case SvNumFormatType::FRACTION:
564  eOffsetStart=NF_FRACTION_START;
565  eOffsetEnd=NF_FRACTION_END;
566  break;
567 
568  case SvNumFormatType::LOGICAL:
569  eOffsetStart=NF_BOOLEAN;
570  eOffsetEnd=NF_BOOLEAN;
571  break;
572 
573  case SvNumFormatType::TEXT:
574  eOffsetStart=NF_TEXT;
575  eOffsetEnd=NF_TEXT;
576  break;
577 
578  case SvNumFormatType::ALL:
579  eOffsetStart=NF_NUMERIC_START;
580  eOffsetEnd = NfIndexTableOffset( NF_INDEX_TABLE_ENTRIES - 1 );
581  break;
582 
583  default:
584  OSL_FAIL("what a format?");
585  break;
586  }
587 
588  const SvNumberformat* pFormat;
589  sal_Int32 i = 0;
590  Color* pCol;
591  double fVal = NumFormatListBox::GetDefValue(nFormatType);
592  OUString sValue;
593 
594  const sal_uInt32 nSysNumFormat = pFormatter->GetFormatIndex(
595  NF_NUMBER_SYSTEM, eCurLanguage );
596  const sal_uInt32 nSysShortDateFormat = pFormatter->GetFormatIndex(
597  NF_DATE_SYSTEM_SHORT, eCurLanguage );
598  const sal_uInt32 nSysLongDateFormat = pFormatter->GetFormatIndex(
599  NF_DATE_SYSTEM_LONG, eCurLanguage );
600 
601  for( long nIndex = eOffsetStart; nIndex <= eOffsetEnd; ++nIndex )
602  {
603  const sal_uInt32 nFormat = pFormatter->GetFormatIndex(
604  static_cast<NfIndexTableOffset>(nIndex), eCurLanguage );
605  pFormat = pFormatter->GetEntry( nFormat );
606 
607  if( nFormat == pFormatter->GetFormatIndex( NF_NUMBER_STANDARD,
608  eCurLanguage )
609  || const_cast<SvNumberformat*>(pFormat)->GetOutputString( fVal, sValue, &pCol )
610  || nFormatType == SvNumFormatType::UNDEFINED )
611  {
612  sValue = pFormat->GetFormatstring();
613  }
614  else if( nFormatType == SvNumFormatType::TEXT )
615  {
616  pFormatter->GetOutputString( "\"ABC\"", nFormat, sValue, &pCol);
617  }
618 
619  if (nFormat != nSysNumFormat &&
620  nFormat != nSysShortDateFormat &&
621  nFormat != nSysLongDateFormat)
622  {
623  append(OUString::number(nFormat), sValue);
624 
625  if( nFormat == pFormatter->GetStandardFormat(
626  nFormatType, eCurLanguage ) )
627  nStdEntry = i;
628  ++i;
629  }
630  }
631 
632  append_text(SwResId(STR_DEFINE_NUMBERFORMAT));
633 
635 
636  nCurrFormatType = nFormatType;
638 
639 }
640 
641 void SwNumFormatBase::SetDefFormat(const sal_uInt32 nDefaultFormat)
642 {
643  if (nDefaultFormat == NUMBERFORMAT_ENTRY_NOT_FOUND)
644  {
645  nDefFormat = nDefaultFormat;
646  return;
647  }
648 
649  SwView *pView = GetActiveView();
650  OSL_ENSURE(pView, "no view found");
651  if(!pView)
652  return;
653  SwWrtShell &rSh = pView->GetWrtShell();
654  SvNumberFormatter* pFormatter = rSh.GetNumberFormatter();
655 
656  SvNumFormatType nType = pFormatter->GetType(nDefaultFormat);
657 
658  SetFormatType(nType);
659 
660  sal_uInt32 nFormat = pFormatter->GetFormatForLanguageIfBuiltIn(nDefaultFormat, eCurLanguage);
661 
662  for (sal_Int32 i = 0, nCount = get_count(); i < nCount; ++i)
663  {
664  if (nFormat == get_id(i).toUInt32())
665  {
666  set_active(i);
667  nStdEntry = i;
668  nDefFormat = GetFormat();
669  return;
670  }
671  }
672 
673  // No entry found:
674  OUString sValue;
675  Color* pCol = nullptr;
676 
677  if (nType == SvNumFormatType::TEXT)
678  {
679  pFormatter->GetOutputString("\"ABC\"", nDefaultFormat, sValue, &pCol);
680  }
681  else
682  {
683  pFormatter->GetOutputString(NumFormatListBox::GetDefValue(nType), nDefaultFormat, sValue, &pCol);
684  }
685 
686  sal_Int32 nPos = 0;
687  while (get_id(nPos).toUInt32() == NUMBERFORMAT_ENTRY_NOT_FOUND)
688  nPos++;
689 
690  if ( lcl_isSystemFormat(nDefaultFormat, pFormatter, eCurLanguage) )
691  {
692  sValue += SwResId(RID_STR_SYSTEM);
693  }
694 
695  insert_text(nPos, sValue); // Insert as first numeric entry
696  set_id(nPos, OUString::number(nDefaultFormat));
697  set_active(nPos);
698  nDefFormat = GetFormat();
699 }
700 
702 {
703  return mxControl->get_active_id().toUInt32();
704 }
705 
707 {
708  return mxControl->get_selected_id().toUInt32();
709 }
710 
712 {
713  const sal_Int32 nPos = get_active();
714  OUString sDefine(SwResId( STR_DEFINE_NUMBERFORMAT ));
715  SwView *pView = GetActiveView();
716 
717  if (!pView || nPos != get_count() - 1 || get_text(nPos) != sDefine)
718  return;
719 
720  SwWrtShell &rSh = pView->GetWrtShell();
721  SvNumberFormatter* pFormatter = rSh.GetNumberFormatter();
722 
723  SfxItemSet aCoreSet(
724  rSh.GetAttrPool(),
725  svl::Items<
726  SID_ATTR_NUMBERFORMAT_VALUE, SID_ATTR_NUMBERFORMAT_INFO,
727  SID_ATTR_NUMBERFORMAT_ONE_AREA, SID_ATTR_NUMBERFORMAT_ONE_AREA,
728  SID_ATTR_NUMBERFORMAT_NOLANGUAGE,
729  SID_ATTR_NUMBERFORMAT_NOLANGUAGE,
730  SID_ATTR_NUMBERFORMAT_ADD_AUTO,
731  SID_ATTR_NUMBERFORMAT_ADD_AUTO>{});
732 
734 
735  sal_uInt32 nFormat = pFormatter->GetStandardFormat( nCurrFormatType, eCurLanguage);
736  aCoreSet.Put( SfxUInt32Item( SID_ATTR_NUMBERFORMAT_VALUE, nFormat ));
737 
738  aCoreSet.Put( SvxNumberInfoItem( pFormatter, fValue,
739  SID_ATTR_NUMBERFORMAT_INFO ) );
740 
741  if( (SvNumFormatType::DATE | SvNumFormatType::TIME) & nCurrFormatType )
742  aCoreSet.Put(SfxBoolItem(SID_ATTR_NUMBERFORMAT_ONE_AREA, bOneArea));
743 
744  aCoreSet.Put(SfxBoolItem(SID_ATTR_NUMBERFORMAT_NOLANGUAGE, !bShowLanguageControl));
745  aCoreSet.Put(SfxBoolItem(SID_ATTR_NUMBERFORMAT_ADD_AUTO, bUseAutomaticLanguage));
746 
747  // force deselect to break mouse lock on selected entry
748  set_active(-1);
749 
752 
753  if (RET_OK == pDlg->Execute())
754  {
755  const SfxPoolItem* pItem = pView->GetDocShell()->
756  GetItem( SID_ATTR_NUMBERFORMAT_INFO );
757 
758  if( pItem )
759  {
760  for ( sal_uInt32 key : static_cast<const SvxNumberInfoItem*>(pItem)->GetDelFormats() )
761  pFormatter->DeleteEntry( key );
762  }
763 
764  const SfxItemSet* pOutSet = pDlg->GetOutputItemSet();
765  if( SfxItemState::SET == pOutSet->GetItemState(
766  SID_ATTR_NUMBERFORMAT_VALUE, false, &pItem ))
767  {
768  sal_uInt32 nNumberFormat = static_cast<const SfxUInt32Item*>(pItem)->GetValue();
769  // oj #105473# change order of calls
770  const SvNumberformat* pFormat = pFormatter->GetEntry(nNumberFormat);
771  if( pFormat )
772  eCurLanguage = pFormat->GetLanguage();
773  // SetDefFormat uses eCurLanguage to look for if this format already in the list
774  SetDefFormat(nNumberFormat);
775  }
776  if( bShowLanguageControl && SfxItemState::SET == pOutSet->GetItemState(
777  SID_ATTR_NUMBERFORMAT_ADD_AUTO, false, &pItem ))
778  {
779  bUseAutomaticLanguage = static_cast<const SfxBoolItem*>(pItem)->GetValue();
780  }
781  }
782  else
783  SetDefFormat(nFormat);
784 
785 }
786 
788 {
789  CallSelectHdl();
790 }
791 
793 {
794  CallSelectHdl();
795 }
796 
798 {
800  nCurrFormatType = SvNumFormatType::ALL;
801 }
802 
804 {
805  mxControl->clear();
807 }
808 
810 {
811  mxControl->clear();
813 }
814 
815 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
sal_uInt32 GetFormatForLanguageIfBuiltIn(sal_uInt32 nFormat, LanguageType eLnge=LANGUAGE_DONTKNOW)
sal_Int32 nStdEntry
Definition: numfmtlb.hxx:75
virtual void Init() override
Definition: numfmtlb.cxx:501
bool mbCurrFormatTypeNeedsInit
Definition: numfmtlb.hxx:32
sal_Int32 GetSelectedEntryPos(sal_Int32 nSelIndex=0) const
virtual sal_uInt32 GetFormat() const override
Definition: numfmtlb.cxx:701
SwView * GetActiveView()
Definition: swmodul1.cxx:123
NF_CURRENCY_START
void SetDefFormat(const sal_uInt32 nDefFormat)
Definition: numfmtlb.cxx:270
NF_NUMBER_END
sal_uInt32 nDefFormat
Definition: numfmtlb.hxx:77
virtual void insert_text(int nPos, const OUString &rText)=0
std::string GetValue
NF_INDEX_TABLE_ENTRIES
sal_uInt32 GetFormatIndex(NfIndexTableOffset, LanguageType eLnge=LANGUAGE_DONTKNOW)
NF_SCIENTIFIC_START
LanguageType getLanguageType(bool bResolveSystem=true) const
NF_PERCENT_END
const SfxPoolItem * GetItem(const SwTextAttr &rAttr, sal_uInt16 nWhich)
Extracts pool item of type nWhich from rAttr.
Definition: atrstck.cxx:157
void GetOutputString(const double &fOutNumber, sal_uInt32 nFIndex, OUString &sOutString, Color **ppColor, bool bUseStarFormat=false)
virtual void clear()
Definition: numfmtlb.cxx:797
SvNumFormatType GetType(sal_uInt32 nFIndex) const
void CallSelectHdl()
Definition: numfmtlb.cxx:711
virtual sal_uInt32 GetFormat() const =0
void Clear()
NF_FRACTION_END
virtual weld::Widget & get_widget() const =0
const OUString & GetFormatstring() const
virtual int get_count() const =0
virtual void set_active(int nPos)=0
SwWrtShell & GetWrtShell() const
Definition: view.hxx:400
LanguageType GetCurLang() const
Definition: edattr.cxx:813
Used by the UI to modify the document model.
Definition: wrtsh.hxx:88
std::unique_ptr< weld::ComboBox > mxControl
Definition: numfmtlb.hxx:116
sal_Int64 WinBits
NF_NUMBER_STANDARD
virtual void clear() override
Definition: numfmtlb.cxx:803
void EnableAutoSize(bool bAuto)
sal_Int32 GetEntryCount() const
FUNC_TYPE const nType
SAL_DLLPUBLIC_EXPORT void makeNumFormatListBox(VclPtr< vcl::Window > &rRet, const VclPtr< vcl::Window > &pParent, VclBuilder::stringmap &rMap)
Definition: numfmtlb.cxx:64
constexpr sal_uInt32 NUMBERFORMAT_ENTRY_NOT_FOUND
bool mbCurrFormatTypeNeedsInit
Definition: numfmtlb.hxx:74
virtual OUString get_id(int nPos) const =0
void SetDefFormat(const sal_uInt32 nDefFormat)
Definition: numfmtlb.cxx:641
virtual sal_uInt32 GetFormat() const override
Definition: numfmtlb.cxx:706
NfIndexTableOffset
void * GetEntryData(sal_Int32 nPos) const
NF_CURRENCY_END
virtual void append(const OUString &rId, const OUString &rText)=0
NF_DATE_END
SvNumFormatType nCurrFormatType
Definition: numfmtlb.hxx:73
NF_PERCENT_START
void SetFormatType(const SvNumFormatType nFormatType)
Definition: numfmtlb.cxx:105
std::unique_ptr< weld::TreeView > mxControl
Definition: numfmtlb.hxx:147
const SfxItemPool & GetAttrPool() const
Definition: viewsh.hxx:614
NF_BOOLEAN
void SetFormatType(const SvNumFormatType nFormatType)
Definition: numfmtlb.cxx:508
SfxItemState GetItemState(sal_uInt16 nWhich, bool bSrchInParent=true, const SfxPoolItem **ppItem=nullptr) const
NF_TIME_START
virtual ~NumFormatListBox() override
Definition: numfmtlb.cxx:100
LanguageType eCurLanguage
Definition: numfmtlb.hxx:36
const o3tl::enumarray< SvxNumValCategory, double > fSvxNumValConst
bool bShowLanguageControl
Definition: numfmtlb.hxx:79
void SelectEntryPos(sal_Int32 nPos, bool bSelect=true)
WinBits const WB_SIMPLEMODE
int i
WinBits const WB_VCENTER
virtual VclPtr< SfxAbstractDialog > CreateNumFormatDialog(weld::Widget *pParent, const SfxItemSet &rAttr)=0
SwNumFormatListBox(std::unique_ptr< weld::ComboBox > xControl)
Definition: numfmtlb.cxx:469
NF_SCIENTIFIC_END
IMPL_LINK(NumFormatListBox, SelectHdl, ListBox &, rBox, void)
Definition: numfmtlb.cxx:337
std::map< OString, OUString > stringmap
weld::Window * GetFrameWeld(SfxFrame *pFrame)
Definition: dialoghelp.cxx:20
NF_TEXT
SvNumFormatType nCurrFormatType
Definition: numfmtlb.hxx:31
sal_Int32 InsertEntry(const OUString &rStr, sal_Int32 nPos=LISTBOX_APPEND)
SvNumFormatType
static SwAbstractDialogFactory * Create()
Definition: swabstdlg.cxx:36
WinBits const WB_DROPDOWN
OUString SwResId(const char *pId)
Definition: swmodule.cxx:191
void DeleteEntry(sal_uInt32 nKey)
virtual void append_text(const OUString &rText)=0
void SetSelectHdl(const Link< ListBox &, void > &rLink)
virtual void Init() override
Definition: numfmtlb.cxx:494
WinBits const WB_LEFT
SwDocShell * GetDocShell()
Definition: view.cxx:1127
NF_NUMBER_SYSTEM
virtual OUString get_text(int nPos) const =0
WinBits const WB_3DLOOK
NF_TIME_END
NF_DATE_START
static SAL_DLLPRIVATE double GetDefValue(const SvNumFormatType nFormatType)
Definition: numfmtlb.cxx:411
sal_uInt32 GetFormat() const
Definition: numfmtlb.cxx:330
SwNumFormatTreeView(std::unique_ptr< weld::TreeView > xControl)
Definition: numfmtlb.cxx:475
SAL_DLLPRIVATE void Init()
Definition: numfmtlb.cxx:85
NF_DATE_SYSTEM_LONG
sal_uInt32 nDefFormat
Definition: numfmtlb.hxx:35
WinBits const WB_BORDER
const SvNumberformat * GetEntry(sal_uInt32 nKey) const
sal_uInt32 GetStandardFormat(SvNumFormatType eType, LanguageType eLnge=LANGUAGE_DONTKNOW)
NF_FRACTION_START
LanguageType GetAppLanguage()
Definition: init.cxx:765
RET_OK
virtual int get_active() const =0
NF_DATE_SYSTEM_SHORT
bool bUseAutomaticLanguage
Definition: numfmtlb.hxx:81
bool extractDropdown(VclBuilder::stringmap &rMap)
IMPL_LINK_NOARG(SwNumFormatListBox, SelectHdl, weld::ComboBox &, void)
Definition: numfmtlb.cxx:787
const LanguageTag & GetLanguageTag() const
NF_NUMBER_START
SvxNumValCategory
NumFormatListBox(vcl::Window *pWin, WinBits nStyle)
Description: nFormatType: Display the formats of this Type nDefaultFormat: Select this format and pos...
Definition: numfmtlb.cxx:51
void SetEntryData(sal_Int32 nPos, void *pNewData)
virtual void Init()
Definition: numfmtlb.cxx:481
sal_Int32 nPos
NF_NUMERIC_START
SvNumberFormatter * GetNumberFormatter()
Query NumberFormatter from document.
Definition: editsh.cxx:750
sal_Int32 nStdEntry
Definition: numfmtlb.hxx:33
virtual void clear() override
Definition: numfmtlb.cxx:809
LanguageType GetLanguage() const
Definition: view.hxx:146
virtual void set_id(int nPos, const OUString &rId)=0