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