LibreOffice Module sc (master)  1
condformatdlgentry.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 
10 #include <memory>
11 #include <condformatdlg.hxx>
12 #include <condformatdlgentry.hxx>
13 #include <conditio.hxx>
14 #include <compiler.hxx>
15 #include <colorscale.hxx>
16 #include <condformathelper.hxx>
17 
18 #include <document.hxx>
19 
20 #include <o3tl/string_view.hxx>
21 #include <svl/style.hxx>
22 #include <sfx2/dispatch.hxx>
23 #include <sfx2/frame.hxx>
24 #include <svl/stritem.hxx>
25 #include <svl/intitem.hxx>
26 #include <svl/numformat.hxx>
27 #include <svx/colorbox.hxx>
28 #include <vcl/svapp.hxx>
29 #include <formula/token.hxx>
30 #include <formula/errorcodes.hxx>
31 #include <tokenarray.hxx>
32 #include <stlpool.hxx>
33 #include <tabvwsh.hxx>
34 #include <unotools/charclass.hxx>
35 
36 #include <colorformat.hxx>
37 #include <scresid.hxx>
38 #include <globstr.hrc>
39 #include <strings.hrc>
40 
41 #include <set>
42 
43 // set the widget width to something to override their auto-width calc and
44 // force them to take a 1/3 of the available space
45 #define CommonWidgetWidth 10
46 
48  : mpParent(pParent)
49  , mxBuilder(Application::CreateBuilder(pParent->GetContainer(), (SfxViewShell::Current() && SfxViewShell::Current()->isLOKMobilePhone())?OUString("modules/scalc/ui/conditionalentrymobile.ui"):OUString("modules/scalc/ui/conditionalentry.ui")))
50  , mxBorder(mxBuilder->weld_widget("border"))
51  , mxGrid(mxBuilder->weld_container("grid"))
52  , mxFtCondNr(mxBuilder->weld_label("number"))
53  , mxFtCondition(mxBuilder->weld_label("condition"))
54  , mbActive(false)
55  , maStrCondition(ScResId(SCSTR_CONDITION))
56  , mxLbType(mxBuilder->weld_combo_box("type"))
57  , mpDoc(pDoc)
58  , maPos(rPos)
59 {
60  mxLbType->set_size_request(CommonWidgetWidth, -1);
61  mxLbType->connect_changed(LINK(pParent, ScCondFormatList, TypeListHdl));
62  mxGrid->connect_mouse_press(LINK(this, ScCondFrmtEntry, EntrySelectHdl));
63  maClickHdl = LINK( pParent, ScCondFormatList, EntrySelectHdl );
64 
65  Show();
66 }
67 
69 {
70  mpParent->GetContainer()->move(mxBorder.get(), nullptr);
71 }
72 
73 IMPL_LINK_NOARG(ScCondFrmtEntry, EntrySelectHdl, const MouseEvent&, bool)
74 {
75  maClickHdl.Call(*this);
76  return false;
77 }
78 
79 void ScCondFrmtEntry::SetIndex(sal_Int32 nIndex)
80 {
81  OUString sLabel = maStrCondition + OUString::number(nIndex);
82  mxFtCondNr->set_label(sLabel);
83 
84  // tdf#124412: uitest
85  mxFtCondition->set_buildable_name(sLabel.toUtf8());
86 }
87 
89 {
90  mxFtCondition->set_label(OUString());
91  mxFtCondition->hide();
92  mxLbType->show();
93  mbActive = true;
94 }
95 
97 {
98  OUString aCondText = GetExpressionString();
99  mxFtCondition->set_label(aCondText);
100  mxFtCondition->show();
101  mxLbType->hide();
102  mbActive = false;
103 }
104 
105 //condition
106 
107 namespace {
108 
109 void FillStyleListBox( const ScDocument* pDoc, weld::ComboBox& rLbStyle )
110 {
111  std::set<OUString> aStyleNames;
112  SfxStyleSheetIterator aStyleIter( pDoc->GetStyleSheetPool(), SfxStyleFamily::Para );
113  for ( SfxStyleSheetBase* pStyle = aStyleIter.First(); pStyle; pStyle = aStyleIter.Next() )
114  {
115  aStyleNames.insert(pStyle->GetName());
116  }
117  for(const auto& rStyleName : aStyleNames)
118  {
119  rLbStyle.append_text(rStyleName);
120  }
121 }
122 
123 }
124 
150 };
151 
153  const ScAddress& rPos, const ScCondFormatEntry* pFormatEntry)
154  : ScCondFrmtEntry(pParent, pDoc, rPos)
155  , mxLbCondType(mxBuilder->weld_combo_box("typeis"))
156  , mxEdVal1(new formula::RefEdit(mxBuilder->weld_entry("val1")))
157  , mxEdVal2(new formula::RefEdit(mxBuilder->weld_entry("val2")))
158  , mxFtVal(mxBuilder->weld_label("valueft"))
159  , mxFtStyle(mxBuilder->weld_label("styleft"))
160  , mxLbStyle(mxBuilder->weld_combo_box("style"))
161  , mxWdPreviewWin(mxBuilder->weld_widget("previewwin"))
162  , mxWdPreview(new weld::CustomWeld(*mxBuilder, "preview", maWdPreview))
163  , mbIsInStyleCreate(false)
164 {
165  mxLbCondType->set_size_request(CommonWidgetWidth, -1);
166  mxLbType->set_size_request(CommonWidgetWidth, -1);
167  mxWdPreview->set_size_request(-1, mxLbStyle->get_preferred_size().Height());
168 
169  mxLbType->set_active(1);
170 
171  Init(pDialogParent);
172 
173  StartListening(*pDoc->GetStyleSheetPool(), DuplicateHandling::Prevent);
174 
175  if(pFormatEntry)
176  {
177  mxLbStyle->set_active_text(pFormatEntry->GetStyle());
178  StyleSelectHdl(*mxLbStyle);
179  ScConditionMode eMode = pFormatEntry->GetOperation();
180 
181  mxLbCondType->set_active(ConditionModeToEntryPos(eMode));
182 
183  switch(GetNumberEditFields(eMode))
184  {
185  case 0:
186  mxEdVal1->GetWidget()->hide();
187  mxEdVal2->GetWidget()->hide();
188  break;
189  case 1:
190  mxEdVal1->GetWidget()->show();
191  mxEdVal1->SetText(pFormatEntry->GetExpression(maPos, 0));
192  mxEdVal2->GetWidget()->hide();
193  OnEdChanged(*mxEdVal1);
194  break;
195  case 2:
196  mxEdVal1->GetWidget()->show();
197  mxEdVal1->SetText(pFormatEntry->GetExpression(maPos, 0));
198  OnEdChanged(*mxEdVal1);
199  mxEdVal2->GetWidget()->show();
200  mxEdVal2->SetText(pFormatEntry->GetExpression(maPos, 1));
201  OnEdChanged(*mxEdVal2);
202  break;
203  }
204  }
205  else
206  {
207  mxLbCondType->set_active(0);
208  mxEdVal2->GetWidget()->hide();
209  mxLbStyle->set_active(1);
210  }
211 }
212 
214 {
215 }
216 
218 {
219  mxEdVal1->SetGetFocusHdl( LINK( pDialogParent, ScCondFormatDlg, RangeGetFocusHdl ) );
220  mxEdVal2->SetGetFocusHdl( LINK( pDialogParent, ScCondFormatDlg, RangeGetFocusHdl ) );
221 
222  mxEdVal1->SetModifyHdl( LINK( this, ScConditionFrmtEntry, OnEdChanged ) );
223  mxEdVal2->SetModifyHdl( LINK( this, ScConditionFrmtEntry, OnEdChanged ) );
224 
225  FillStyleListBox( mpDoc, *mxLbStyle );
226  mxLbStyle->connect_changed( LINK( this, ScConditionFrmtEntry, StyleSelectHdl ) );
227 
228  mxLbCondType->connect_changed( LINK( this, ScConditionFrmtEntry, ConditionTypeSelectHdl ) );
229 }
230 
232 {
234  OUString aExpr1 = mxEdVal1->GetText();
235  OUString aExpr2;
236  if (GetNumberEditFields(eMode) == 2)
237  {
238  aExpr2 = mxEdVal2->GetText();
239  if (aExpr2.isEmpty())
240  {
241  return nullptr;
242  }
243  }
244 
245  ScFormatEntry* pEntry = new ScCondFormatEntry(eMode, aExpr1, aExpr2, *mpDoc, maPos, mxLbStyle->get_active_text());
246  return pEntry;
247 }
248 
249 IMPL_LINK(ScConditionFrmtEntry, OnEdChanged, formula::RefEdit&, rRefEdit, void)
250 {
251  weld::Entry& rEdit = *rRefEdit.GetWidget();
252  OUString aFormula = rEdit.get_text();
253 
254  if( aFormula.isEmpty() )
255  {
256  mxFtVal->set_label(ScResId(STR_ENTER_VALUE));
257  return;
258  }
259 
260  ScCompiler aComp( *mpDoc, maPos, mpDoc->GetGrammar() );
261  std::unique_ptr<ScTokenArray> ta(aComp.CompileString(aFormula));
262 
263  // Error, warn the user
264  if( ta->GetCodeError() != FormulaError::NONE || ( ta->GetLen() == 0 ) )
265  {
267  mxFtVal->set_label(ScResId(STR_VALID_DEFERROR));
268  return;
269  }
270 
271  // Recognized col/row name or string token, warn the user
272  formula::FormulaToken* token = ta->FirstToken();
273  formula::StackVar t = token->GetType();
274  OpCode op = token->GetOpCode();
275  if( ( op == ocColRowName ) ||
276  ( ( op == ocBad ) && ( t == formula::svString ) )
277  )
278  {
280  mxFtVal->set_label(ScResId(STR_UNQUOTED_STRING));
281  return;
282  }
283 
285  mxFtVal->set_label("");
286 }
287 
289 {
290  mxFtVal->show();
292 }
293 
295 {
296  mxFtVal->hide();
298 }
299 
301 {
302  for ( sal_Int32 i = 0; i < NUM_COND_ENTRIES; ++i )
303  {
304  if (mpEntryToCond[i] == eMode)
305  {
306  return i;
307  }
308  }
309  assert(false); // should never get here
310  return 0;
311 }
312 
314 {
315  assert( 0 <= aEntryPos && aEntryPos < NUM_COND_ENTRIES );
316  return mpEntryToCond[aEntryPos];
317 }
318 
320 {
321  switch(eMode)
322  {
339  return 1;
346  return 0;
349  return 2;
350  default:
351  assert(false); // should never get here
352  return 0;
353  }
354 }
355 
357 {
358  return ScCondFormatHelper::GetExpression(CONDITION, mxLbCondType->get_active(), mxEdVal1->GetText(), mxEdVal2->GetText());
359 }
360 
362 {
363  return createConditionEntry();
364 }
365 
367 {
369  mxLbCondType->show();
370  switch(GetNumberEditFields(eMode))
371  {
372  case 1:
373  mxEdVal1->GetWidget()->show();
374  break;
375  case 2:
376  mxEdVal1->GetWidget()->show();
377  mxEdVal2->GetWidget()->show();
378  break;
379  }
380  mxFtStyle->show();
381  mxLbStyle->show();
382  mxWdPreviewWin->show();
383 
384  Select();
385 }
386 
388 {
389  mxLbCondType->hide();
390  mxEdVal1->GetWidget()->hide();
391  mxEdVal2->GetWidget()->hide();
392  mxFtStyle->hide();
393  mxLbStyle->hide();
394  mxWdPreviewWin->hide();
395 
396  Deselect();
397 }
398 
399 namespace {
400 
401 void UpdateStyleList(weld::ComboBox& rLbStyle, const ScDocument* pDoc)
402 {
403  OUString aSelectedStyle = rLbStyle.get_active_text();
404  for (sal_Int32 i = rLbStyle.get_count(); i > 1; --i)
405  rLbStyle.remove(i - 1);
406  FillStyleListBox(pDoc, rLbStyle);
407  rLbStyle.set_active_text(aSelectedStyle);
408 }
409 
410 }
411 
413 {
414  if(rHint.GetId() == SfxHintId::StyleSheetModified)
415  {
416  if(!mbIsInStyleCreate)
417  UpdateStyleList(*mxLbStyle, mpDoc);
418  }
419 }
420 
421 namespace {
422 
423 void StyleSelect(weld::Window* pDialogParent, weld::ComboBox& rLbStyle, const ScDocument* pDoc, SvxFontPrevWindow& rWdPreview)
424 {
425  if (rLbStyle.get_active() == 0)
426  {
427  // call new style dialog
428  SfxUInt16Item aFamilyItem( SID_STYLE_FAMILY, sal_uInt16(SfxStyleFamily::Para) );
429  SfxStringItem aRefItem( SID_STYLE_REFERENCE, ScResId(STR_STYLENAME_STANDARD) );
430  css::uno::Any aAny(pDialogParent->GetXWindow());
431  SfxUnoAnyItem aDialogParent( SID_DIALOG_PARENT, aAny );
432 
433  // unlock the dispatcher so SID_STYLE_NEW can be executed
434  // (SetDispatcherLock would affect all Calc documents)
436  SfxDispatcher* pDisp = pViewShell->GetDispatcher();
437  bool bLocked = pDisp->IsLocked();
438  if (bLocked)
439  pDisp->Lock(false);
440 
441  // Execute the "new style" slot, complete with undo and all necessary updates.
442  // The return value (SfxUInt16Item) is ignored, look for new styles instead.
443  pDisp->ExecuteList(SID_STYLE_NEW,
444  SfxCallMode::SYNCHRON | SfxCallMode::RECORD,
445  { &aFamilyItem, &aRefItem }, { &aDialogParent });
446 
447  if (bLocked)
448  pDisp->Lock(true);
449 
450  // Find the new style and add it into the style list boxes
451  SfxStyleSheetIterator aStyleIter( pDoc->GetStyleSheetPool(), SfxStyleFamily::Para );
452  bool bFound = false;
453  for ( SfxStyleSheetBase* pStyle = aStyleIter.First(); pStyle && !bFound; pStyle = aStyleIter.Next() )
454  {
455  const OUString& aName = pStyle->GetName();
456  if (rLbStyle.find_text(aName) == -1) // all lists contain the same entries
457  {
458  for( sal_Int32 i = 1, n = rLbStyle.get_count(); i <= n && !bFound; ++i)
459  {
460  OUString aStyleName = ScGlobal::getCharClass().uppercase(rLbStyle.get_text(i));
461  if( i == n )
462  {
463  rLbStyle.append_text(aName);
464  rLbStyle.set_active_text(aName);
465  bFound = true;
466  }
467  else if( aStyleName > ScGlobal::getCharClass().uppercase(aName) )
468  {
469  rLbStyle.insert_text(i, aName);
470  rLbStyle.set_active_text(aName);
471  bFound = true;
472  }
473  }
474  }
475  }
476  }
477 
478  OUString aStyleName = rLbStyle.get_active_text();
479  SfxStyleSheetBase* pStyleSheet = pDoc->GetStyleSheetPool()->Find( aStyleName, SfxStyleFamily::Para );
480  if(pStyleSheet)
481  {
482  const SfxItemSet& rSet = pStyleSheet->GetItemSet();
483  rWdPreview.SetFromItemSet(rSet, false);
484  }
485 }
486 
487 }
488 
490 {
491  mbIsInStyleCreate = true;
492  StyleSelect(mpParent->GetFrameWeld(), *mxLbStyle, mpDoc, maWdPreview);
493  mbIsInStyleCreate = false;
494 }
495 
496 // formula
497 
499  : ScCondFrmtEntry(pParent, pDoc, rPos)
500  , mxFtStyle(mxBuilder->weld_label("styleft"))
501  , mxLbStyle(mxBuilder->weld_combo_box("style"))
502  , mxWdPreviewWin(mxBuilder->weld_widget("previewwin"))
503  , mxWdPreview(new weld::CustomWeld(*mxBuilder, "preview", maWdPreview))
504  , mxEdFormula(new formula::RefEdit(mxBuilder->weld_entry("formula")))
505 {
506  mxLbType->set_size_request(CommonWidgetWidth, -1);
507  mxWdPreview->set_size_request(-1, mxLbStyle->get_preferred_size().Height());
508 
509  Init(pDialogParent);
510 
511  mxLbType->set_active(2);
512 
513  if(pFormat)
514  {
515  mxEdFormula->SetText(pFormat->GetExpression(rPos, 0, 0, pDoc->GetGrammar()));
516  mxLbStyle->set_active_text(pFormat->GetStyle());
517  }
518  else
519  {
520  mxLbStyle->set_active(1);
521  }
522 
523  StyleSelectHdl(*mxLbStyle);
524 }
525 
527 {
528 }
529 
531 {
532  mxEdFormula->SetGetFocusHdl( LINK( pDialogParent, ScCondFormatDlg, RangeGetFocusHdl ) );
533 
534  FillStyleListBox( mpDoc, *mxLbStyle );
535  mxLbStyle->connect_changed( LINK( this, ScFormulaFrmtEntry, StyleSelectHdl ) );
536 }
537 
539 {
540  StyleSelect(mpParent->GetFrameWeld(), *mxLbStyle, mpDoc, maWdPreview);
541 }
542 
544 {
545  OUString aFormula = mxEdFormula->GetText();
546  if(aFormula.isEmpty())
547  return nullptr;
548 
549  ScFormatEntry* pEntry = new ScCondFormatEntry(ScConditionMode::Direct, aFormula, OUString(), *mpDoc, maPos, mxLbStyle->get_active_text());
550  return pEntry;
551 }
552 
554 {
555  return createFormulaEntry();
556 }
557 
559 {
560  return ScCondFormatHelper::GetExpression(FORMULA, 0, mxEdFormula->GetText());
561 }
562 
564 {
565  mxWdPreviewWin->show();
566  mxFtStyle->show();
567  mxLbStyle->show();
568  mxEdFormula->GetWidget()->show();
569 
570  Select();
571 }
572 
574 {
575  mxWdPreviewWin->hide();
576  mxFtStyle->hide();
577  mxLbStyle->hide();
578  mxEdFormula->GetWidget()->hide();
579 
580  Deselect();
581 }
582 
583 //color scale
584 
585 namespace {
586 
587 OUString convertNumberToString(double nVal, const ScDocument* pDoc)
588 {
589  SvNumberFormatter* pNumberFormatter = pDoc->GetFormatTable();
590  OUString aText;
591  pNumberFormatter->GetInputLineString(nVal, 0, aText);
592  return aText;
593 }
594 
595 const struct
596 {
598  const char* sId;
599 } TypeIdMap[] = {
600  { COLORSCALE_AUTO, "auto" },
601  { COLORSCALE_MIN, "min" },
602  { COLORSCALE_MAX, "max" },
603  { COLORSCALE_PERCENTILE, "percentil" },
604  { COLORSCALE_VALUE, "value" },
605  { COLORSCALE_PERCENT, "percent" },
606  { COLORSCALE_FORMULA, "formula" },
607 };
608 
609 ScColorScaleEntryType getTypeForId(std::u16string_view sId)
610 {
611  for (auto& r : TypeIdMap)
612  {
613  if (o3tl::equalsAscii(sId, r.sId))
614  return r.eType;
615  }
616  assert(false); // The id is not in TypeIdMap - something not in sync?
617  return COLORSCALE_AUTO; // invalid id - use default
618 }
619 
620 // Item ids are imported from .ui into OUString* and are referenced by entry data.
621 // See commit 83cefb5ceb4428d61a5b9fae80d1e673131e9bfe
622 
623 ScColorScaleEntryType getSelectedType(const weld::ComboBox& rListBox)
624 {
625  return getTypeForId(rListBox.get_active_id());
626 }
627 
628 sal_Int32 getEntryPos(const weld::ComboBox& rListBox, ScColorScaleEntryType eType)
629 {
630  const sal_Int32 nSize = rListBox.get_count();
631  for (sal_Int32 i = 0; i < nSize; ++i)
632  {
633  if (getTypeForId(rListBox.get_id(i)) == eType)
634  return i;
635  }
636  return -1;
637 }
638 
639 void selectType(weld::ComboBox& rListBox, ScColorScaleEntryType eType)
640 {
641  const sal_Int32 nPos = getEntryPos(rListBox, eType);
642  if (nPos >= 0)
643  rListBox.set_active(nPos);
644 }
645 
646 void removeType(weld::ComboBox& rListBox, ScColorScaleEntryType eType)
647 {
648  const sal_Int32 nPos = getEntryPos(rListBox, eType);
649  if (nPos >= 0)
650  rListBox.remove(nPos);
651 }
652 
653 void SetColorScaleEntryTypes( const ScColorScaleEntry& rEntry, weld::ComboBox& rLbType, weld::Entry& rEdit, ColorListBox& rLbCol, const ScDocument* pDoc )
654 {
655  // entry Automatic is not available for color scales
656  assert(rEntry.GetType() > COLORSCALE_AUTO);
657  selectType(rLbType, rEntry.GetType());
658  switch(rEntry.GetType())
659  {
660  case COLORSCALE_MIN:
661  case COLORSCALE_MAX:
662  break;
664  case COLORSCALE_VALUE:
665  case COLORSCALE_PERCENT:
666  {
667  double nVal = rEntry.GetValue();
668  rEdit.set_text(convertNumberToString(nVal, pDoc));
669  }
670  break;
671  case COLORSCALE_FORMULA:
673  break;
674  case COLORSCALE_AUTO:
675  abort();
676  break;
677  }
678  rLbCol.SelectEntry(rEntry.GetColor());
679 }
680 
681 void SetColorScaleEntry(ScColorScaleEntry* pEntry, const weld::ComboBox& rType, const weld::Entry& rValue,
682  ScDocument* pDoc, const ScAddress& rPos)
683 {
684  ScColorScaleEntryType eType = getSelectedType(rType);
685 
686  pEntry->SetType(eType);
687  switch (eType)
688  {
689  case COLORSCALE_AUTO:
690  case COLORSCALE_MIN:
691  case COLORSCALE_MAX:
692  break;
694  case COLORSCALE_VALUE:
695  case COLORSCALE_PERCENT:
696  {
697  sal_uInt32 nIndex = 0;
698  double nVal = 0;
699  SvNumberFormatter* pNumberFormatter = pDoc->GetFormatTable();
700  (void)pNumberFormatter->IsNumberFormat(rValue.get_text(), nIndex, nVal);
701  pEntry->SetValue(nVal);
702  }
703  break;
704  case COLORSCALE_FORMULA:
705  pEntry->SetFormula(rValue.get_text(), *pDoc, rPos);
706  break;
707  default:
708  break;
709  }
710 }
711 
712 ScColorScaleEntry* createColorScaleEntry( const weld::ComboBox& rType, const ColorListBox& rColor, const weld::Entry& rValue, ScDocument* pDoc, const ScAddress& rPos )
713 {
714  ScColorScaleEntry* pEntry = new ScColorScaleEntry();
715 
716  SetColorScaleEntry(pEntry, rType, rValue, pDoc, rPos);
717  Color aColor = rColor.GetSelectEntryColor();
718  pEntry->SetColor(aColor);
719  return pEntry;
720 }
721 
722 }
723 
725  : ScCondFrmtEntry(pParent, pDoc, rPos)
726  , mxLbColorFormat(mxBuilder->weld_combo_box("colorformat"))
727  , mxLbEntryTypeMin(mxBuilder->weld_combo_box("colscalemin"))
728  , mxLbEntryTypeMax(mxBuilder->weld_combo_box("colscalemax"))
729  , mxEdMin(mxBuilder->weld_entry("edcolscalemin"))
730  , mxEdMax(mxBuilder->weld_entry("edcolscalemax"))
731  , mxLbColMin(new ColorListBox(mxBuilder->weld_menu_button("lbcolmin"), [this]{ return mpParent->GetFrameWeld(); }))
732  , mxLbColMax(new ColorListBox(mxBuilder->weld_menu_button("lbcolmax"), [this]{ return mpParent->GetFrameWeld(); }))
733  , mxFtMin(mxBuilder->weld_label("Label_minimum"))
734  , mxFtMax(mxBuilder->weld_label("Label_maximum"))
735 {
736  mxLbColorFormat->set_size_request(CommonWidgetWidth, -1);
737  mxLbEntryTypeMin->set_size_request(CommonWidgetWidth, -1);
738  mxLbEntryTypeMax->set_size_request(CommonWidgetWidth, -1);
739  mxLbColMin->get_widget().set_size_request(CommonWidgetWidth, -1);
740  mxLbColMax->get_widget().set_size_request(CommonWidgetWidth, -1);
741 
742  mxFtMin->show();
743  mxFtMax->show();
744 
745  // remove the automatic entry from color scales
746  removeType(*mxLbEntryTypeMin, COLORSCALE_AUTO);
747  removeType(*mxLbEntryTypeMax, COLORSCALE_AUTO);
748  // "min" selector doesn't need "max" entry, and vice versa
749  removeType(*mxLbEntryTypeMin, COLORSCALE_MAX);
750  removeType(*mxLbEntryTypeMax, COLORSCALE_MIN);
751 
752  mxLbType->set_active(0);
753  mxLbColorFormat->set_active(0);
754  Init();
755  if(pFormat)
756  {
757  ScColorScaleEntries::const_iterator itr = pFormat->begin();
758  SetColorScaleEntryTypes(*itr[0], *mxLbEntryTypeMin, *mxEdMin, *mxLbColMin, pDoc);
759  ++itr;
760  SetColorScaleEntryTypes(*itr[0], *mxLbEntryTypeMax, *mxEdMax, *mxLbColMax, pDoc);
761  }
762  else
763  {
764  selectType(*mxLbEntryTypeMin, COLORSCALE_MIN);
765  selectType(*mxLbEntryTypeMax, COLORSCALE_MAX);
766  }
767 
768  mxLbColorFormat->connect_changed( LINK( pParent, ScCondFormatList, ColFormatTypeHdl ) );
769 
770  EntryTypeHdl(*mxLbEntryTypeMin);
771  EntryTypeHdl(*mxLbEntryTypeMax);
772 }
773 
775 {
776 }
777 
779 {
780  mxLbEntryTypeMin->connect_changed( LINK( this, ScColorScale2FrmtEntry, EntryTypeHdl ) );
781  mxLbEntryTypeMax->connect_changed( LINK( this, ScColorScale2FrmtEntry, EntryTypeHdl ) );
782  mxLbColMin->SelectEntry(Color(0xffff6d)); // Light Yellow 2
783  mxLbColMax->SelectEntry(Color(0x77bc65)); // Light Green 2
784 }
785 
787 {
788  ScColorScaleFormat* pColorScale = new ScColorScaleFormat(mpDoc);
789  pColorScale->AddEntry(createColorScaleEntry(*mxLbEntryTypeMin, *mxLbColMin, *mxEdMin, mpDoc, maPos));
790  pColorScale->AddEntry(createColorScaleEntry(*mxLbEntryTypeMax, *mxLbColMax, *mxEdMax, mpDoc, maPos));
791  return pColorScale;
792 }
793 
795 {
797 }
798 
800 {
801  return createColorscaleEntry();
802 }
803 
805 {
806  mxLbColorFormat->show();
807 
808  mxLbEntryTypeMin->show();
809  mxLbEntryTypeMax->show();
810 
811  mxEdMin->show();
812  mxEdMax->show();
813 
814  mxLbColMin->show();
815  mxLbColMax->show();
816 
817  Select();
818 }
819 
821 {
822  mxLbColorFormat->hide();
823 
824  mxLbEntryTypeMin->hide();
825  mxLbEntryTypeMax->hide();
826 
827  mxEdMin->hide();
828  mxEdMax->hide();
829 
830  mxLbColMin->hide();
831  mxLbColMax->hide();
832 
833  Deselect();
834 }
835 
836 IMPL_LINK( ScColorScale2FrmtEntry, EntryTypeHdl, weld::ComboBox&, rBox, void )
837 {
838  weld::Entry* pEd = nullptr;
839  if (&rBox == mxLbEntryTypeMin.get())
840  pEd = mxEdMin.get();
841  else if (&rBox == mxLbEntryTypeMax.get())
842  pEd = mxEdMax.get();
843 
844  if (!pEd)
845  return;
846 
847  bool bEnableEdit = true;
848  if (getSelectedType(rBox) <= COLORSCALE_MAX)
849  {
850  bEnableEdit = false;
851  }
852 
853  if (bEnableEdit)
854  pEd->set_sensitive(true);
855  else
856  pEd->set_sensitive(false);
857 }
858 
860  : ScCondFrmtEntry(pParent, pDoc, rPos)
861  , mxLbColorFormat(mxBuilder->weld_combo_box("colorformat"))
862  , mxLbEntryTypeMin(mxBuilder->weld_combo_box("colscalemin"))
863  , mxLbEntryTypeMiddle(mxBuilder->weld_combo_box("colscalemiddle"))
864  , mxLbEntryTypeMax(mxBuilder->weld_combo_box("colscalemax"))
865  , mxEdMin(mxBuilder->weld_entry("edcolscalemin"))
866  , mxEdMiddle(mxBuilder->weld_entry("edcolscalemiddle"))
867  , mxEdMax(mxBuilder->weld_entry("edcolscalemax"))
868  , mxLbColMin(new ColorListBox(mxBuilder->weld_menu_button("lbcolmin"), [this]{ return mpParent->GetFrameWeld(); }))
869  , mxLbColMiddle(new ColorListBox(mxBuilder->weld_menu_button("lbcolmiddle"), [this]{ return mpParent->GetFrameWeld(); }))
870  , mxLbColMax(new ColorListBox(mxBuilder->weld_menu_button("lbcolmax"), [this]{ return mpParent->GetFrameWeld(); }))
871  , mxFtMin(mxBuilder->weld_label("Label_minimum"))
872  , mxFtMax(mxBuilder->weld_label("Label_maximum"))
873 {
874  mxLbColorFormat->set_size_request(CommonWidgetWidth, -1);
875  mxLbEntryTypeMin->set_size_request(CommonWidgetWidth, -1);
876  mxLbEntryTypeMiddle->set_size_request(CommonWidgetWidth, -1);
877  mxLbEntryTypeMax->set_size_request(CommonWidgetWidth, -1);
878  mxLbColMin->get_widget().set_size_request(CommonWidgetWidth, -1);
879  mxLbColMiddle->get_widget().set_size_request(CommonWidgetWidth, -1);
880  mxLbColMax->get_widget().set_size_request(CommonWidgetWidth, -1);
881  mxFtMin->show();
882  mxFtMax->show();
883 
884  // remove the automatic entry from color scales
885  removeType(*mxLbEntryTypeMin, COLORSCALE_AUTO);
886  removeType(*mxLbEntryTypeMiddle, COLORSCALE_AUTO);
887  removeType(*mxLbEntryTypeMax, COLORSCALE_AUTO);
888  // "min" selector doesn't need "max" entry, and vice versa
889  removeType(*mxLbEntryTypeMin, COLORSCALE_MAX);
890  removeType(*mxLbEntryTypeMax, COLORSCALE_MIN);
891  mxLbColorFormat->set_active(1);
892 
893  Init();
894  mxLbType->set_active(0);
895  if(pFormat)
896  {
897  ScColorScaleEntries::const_iterator itr = pFormat->begin();
898  SetColorScaleEntryTypes(*itr[0], *mxLbEntryTypeMin, *mxEdMin, *mxLbColMin, pDoc);
899  assert(pFormat->size() == 3);
900  ++itr;
901  SetColorScaleEntryTypes(*itr[0], *mxLbEntryTypeMiddle, *mxEdMiddle, *mxLbColMiddle, pDoc);
902  ++itr;
903  SetColorScaleEntryTypes(*itr[0], *mxLbEntryTypeMax, *mxEdMax, *mxLbColMax, pDoc);
904  }
905  else
906  {
907  mxLbColorFormat->set_active(1);
908  selectType(*mxLbEntryTypeMin, COLORSCALE_MIN);
909  selectType(*mxLbEntryTypeMiddle, COLORSCALE_PERCENTILE);
910  selectType(*mxLbEntryTypeMax, COLORSCALE_MAX);
911  mxEdMiddle->set_text(OUString::number(50));
912  }
913 
914  mxLbColorFormat->connect_changed( LINK( pParent, ScCondFormatList, ColFormatTypeHdl ) );
915  EntryTypeHdl(*mxLbEntryTypeMin);
916  EntryTypeHdl(*mxLbEntryTypeMiddle);
917  EntryTypeHdl(*mxLbEntryTypeMax);
918 }
919 
921 {
922 }
923 
925 {
926  mxLbEntryTypeMin->connect_changed( LINK( this, ScColorScale3FrmtEntry, EntryTypeHdl ) );
927  mxLbEntryTypeMax->connect_changed( LINK( this, ScColorScale3FrmtEntry, EntryTypeHdl ) );
928  mxLbEntryTypeMiddle->connect_changed( LINK( this, ScColorScale3FrmtEntry, EntryTypeHdl ) );
929  mxLbColMin->SelectEntry(COL_LIGHTRED);
930  mxLbColMiddle->SelectEntry(COL_YELLOW);
931  mxLbColMax->SelectEntry(Color(0x00a933));
932 }
933 
935 {
936  ScColorScaleFormat* pColorScale = new ScColorScaleFormat(mpDoc);
937  pColorScale->AddEntry(createColorScaleEntry(*mxLbEntryTypeMin, *mxLbColMin, *mxEdMin, mpDoc, maPos));
938  if (mxLbColorFormat->get_active() == 1)
939  pColorScale->AddEntry(createColorScaleEntry(*mxLbEntryTypeMiddle, *mxLbColMiddle, *mxEdMiddle, mpDoc, maPos));
940  pColorScale->AddEntry(createColorScaleEntry(*mxLbEntryTypeMax, *mxLbColMax, *mxEdMax, mpDoc, maPos));
941  return pColorScale;
942 }
943 
945 {
947 }
948 
950 {
951  return createColorscaleEntry();
952 }
953 
955 {
956  mxLbColorFormat->show();
957  mxLbEntryTypeMin->show();
958  mxLbEntryTypeMiddle->show();
959  mxLbEntryTypeMax->show();
960 
961  mxEdMin->show();
962  mxEdMiddle->show();
963  mxEdMax->show();
964 
965  mxLbColMin->show();
966  mxLbColMiddle->show();
967  mxLbColMax->show();
968 
969  Select();
970 }
971 
973 {
974  mxLbColorFormat->hide();
975 
976  mxLbEntryTypeMin->hide();
977  mxLbEntryTypeMiddle->hide();
978  mxLbEntryTypeMax->hide();
979 
980  mxEdMin->hide();
981  mxEdMiddle->hide();
982  mxEdMax->hide();
983 
984  mxLbColMin->hide();
985  mxLbColMiddle->hide();
986  mxLbColMax->hide();
987 
988  Deselect();
989 }
990 
991 IMPL_LINK( ScColorScale3FrmtEntry, EntryTypeHdl, weld::ComboBox&, rBox, void )
992 {
993  weld::Entry* pEd = nullptr;
994  if(&rBox == mxLbEntryTypeMin.get())
995  pEd = mxEdMin.get();
996  else if(&rBox == mxLbEntryTypeMiddle.get())
997  pEd = mxEdMiddle.get();
998  else if(&rBox == mxLbEntryTypeMax.get())
999  pEd = mxEdMax.get();
1000 
1001  if (!pEd)
1002  return;
1003 
1004  bool bEnableEdit = true;
1005  if (getSelectedType(rBox) <= COLORSCALE_MAX)
1006  {
1007  bEnableEdit = false;
1008  }
1009 
1010  if(bEnableEdit)
1011  pEd->set_sensitive(true);
1012  else
1013  pEd->set_sensitive(false);
1014 }
1015 
1016 IMPL_LINK_NOARG(ScConditionFrmtEntry, ConditionTypeSelectHdl, weld::ComboBox&, void)
1017 {
1018  sal_Int32 nSelectPos = mxLbCondType->get_active();
1019  ScConditionMode eMode = EntryPosToConditionMode(nSelectPos);
1020  switch(GetNumberEditFields(eMode))
1021  {
1022  case 0:
1023  mxEdVal1->GetWidget()->hide();
1024  mxEdVal2->GetWidget()->hide();
1025  mxFtVal->hide();
1026  break;
1027  case 1:
1028  mxEdVal1->GetWidget()->show();
1029  mxEdVal2->GetWidget()->hide();
1030  mxFtVal->show();
1031  break;
1032  case 2:
1033  mxEdVal1->GetWidget()->show();
1034  mxEdVal2->GetWidget()->show();
1035  mxFtVal->show();
1036  break;
1037  }
1038 }
1039 
1040 //databar
1041 
1042 namespace {
1043 
1044 void SetDataBarEntryTypes( const ScColorScaleEntry& rEntry, weld::ComboBox& rLbType, weld::Entry& rEdit, const ScDocument* pDoc )
1045 {
1046  selectType(rLbType, rEntry.GetType());
1047  switch(rEntry.GetType())
1048  {
1049  case COLORSCALE_AUTO:
1050  case COLORSCALE_MIN:
1051  case COLORSCALE_MAX:
1052  break;
1053  case COLORSCALE_VALUE:
1054  case COLORSCALE_PERCENT:
1055  case COLORSCALE_PERCENTILE:
1056  {
1057  double nVal = rEntry.GetValue();
1058  SvNumberFormatter* pNumberFormatter = pDoc->GetFormatTable();
1059  OUString aText;
1060  pNumberFormatter->GetInputLineString(nVal, 0, aText);
1061  rEdit.set_text(aText);
1062  }
1063  break;
1064  case COLORSCALE_FORMULA:
1066  break;
1067  }
1068 }
1069 
1070 }
1071 
1073  : ScCondFrmtEntry(pParent, pDoc, rPos)
1074  , mxLbColorFormat(mxBuilder->weld_combo_box("colorformat"))
1075  , mxLbDataBarMinType(mxBuilder->weld_combo_box("colscalemin"))
1076  , mxLbDataBarMaxType(mxBuilder->weld_combo_box("colscalemax"))
1077  , mxEdDataBarMin(mxBuilder->weld_entry("edcolscalemin"))
1078  , mxEdDataBarMax(mxBuilder->weld_entry("edcolscalemax"))
1079  , mxBtOptions(mxBuilder->weld_button("options"))
1080  , mxFtMin(mxBuilder->weld_label("Label_minimum"))
1081  , mxFtMax(mxBuilder->weld_label("Label_maximum"))
1082 {
1083  mxLbColorFormat->set_size_request(CommonWidgetWidth, -1);
1084  mxLbDataBarMinType->set_size_request(CommonWidgetWidth, -1);
1085  mxLbDataBarMaxType->set_size_request(CommonWidgetWidth, -1);
1086 
1087  // "min" selector doesn't need "max" entry, and vice versa
1088  removeType(*mxLbDataBarMinType, COLORSCALE_MAX);
1089  removeType(*mxLbDataBarMaxType, COLORSCALE_MIN);
1090 
1091  mxFtMin->show();
1092  mxFtMax->show();
1093 
1094  mxLbColorFormat->set_active(2);
1095  mxLbType->set_active(0);
1096  if(pFormat)
1097  {
1098  mpDataBarData.reset(new ScDataBarFormatData(*pFormat->GetDataBarData()));
1099  SetDataBarEntryTypes(*mpDataBarData->mpLowerLimit, *mxLbDataBarMinType, *mxEdDataBarMin, pDoc);
1100  SetDataBarEntryTypes(*mpDataBarData->mpUpperLimit, *mxLbDataBarMaxType, *mxEdDataBarMax, pDoc);
1101  DataBarTypeSelectHdl(*mxLbDataBarMinType);
1102  }
1103  else
1104  {
1105  selectType(*mxLbDataBarMinType, COLORSCALE_AUTO);
1106  selectType(*mxLbDataBarMaxType, COLORSCALE_AUTO);
1107  DataBarTypeSelectHdl(*mxLbDataBarMinType);
1108  }
1109  Init();
1110 
1111  mxLbColorFormat->connect_changed( LINK( pParent, ScCondFormatList, ColFormatTypeHdl ) );
1112 }
1113 
1115 {
1116 }
1117 
1119 {
1120  return createDatabarEntry();
1121 }
1122 
1124 {
1125  mxLbDataBarMinType->connect_changed( LINK( this, ScDataBarFrmtEntry, DataBarTypeSelectHdl ) );
1126  mxLbDataBarMaxType->connect_changed( LINK( this, ScDataBarFrmtEntry, DataBarTypeSelectHdl ) );
1127 
1128  mxBtOptions->connect_clicked( LINK( this, ScDataBarFrmtEntry, OptionBtnHdl ) );
1129 
1130  if(!mpDataBarData)
1131  {
1132  mpDataBarData.reset(new ScDataBarFormatData());
1133  mpDataBarData->mpUpperLimit.reset(new ScColorScaleEntry());
1134  mpDataBarData->mpLowerLimit.reset(new ScColorScaleEntry());
1135  mpDataBarData->mpLowerLimit->SetType(COLORSCALE_AUTO);
1136  mpDataBarData->mpUpperLimit->SetType(COLORSCALE_AUTO);
1137  mpDataBarData->maPositiveColor = 0x2a6099;
1138  }
1139 }
1140 
1142 {
1143  SetColorScaleEntry(mpDataBarData->mpLowerLimit.get(), *mxLbDataBarMinType,
1145  SetColorScaleEntry(mpDataBarData->mpUpperLimit.get(), *mxLbDataBarMaxType,
1147  ScDataBarFormat* pDataBar = new ScDataBarFormat(mpDoc);
1148  pDataBar->SetDataBarData(new ScDataBarFormatData(*mpDataBarData));
1149  return pDataBar;
1150 }
1151 
1153 {
1155 }
1156 
1158 {
1159  mxLbColorFormat->show();
1160 
1161  mxLbDataBarMinType->show();
1162  mxLbDataBarMaxType->show();
1163  mxEdDataBarMin->show();
1164  mxEdDataBarMax->show();
1165  mxBtOptions->show();
1166 
1167  Select();
1168 }
1169 
1171 {
1172  mxLbColorFormat->hide();
1173 
1174  mxLbDataBarMinType->hide();
1175  mxLbDataBarMaxType->hide();
1176  mxEdDataBarMin->hide();
1177  mxEdDataBarMax->hide();
1178  mxBtOptions->hide();
1179 
1180  Deselect();
1181 }
1182 
1183 IMPL_LINK_NOARG( ScDataBarFrmtEntry, DataBarTypeSelectHdl, weld::ComboBox&, void )
1184 {
1185  if (getSelectedType(*mxLbDataBarMinType) <= COLORSCALE_MAX)
1186  mxEdDataBarMin->set_sensitive(false);
1187  else
1188  mxEdDataBarMin->set_sensitive(true);
1189 
1190  if (getSelectedType(*mxLbDataBarMaxType) <= COLORSCALE_MAX)
1191  mxEdDataBarMax->set_sensitive(false);
1192  else
1193  mxEdDataBarMax->set_sensitive(true);
1194 }
1195 
1197 {
1198  SetColorScaleEntry(mpDataBarData->mpLowerLimit.get(), *mxLbDataBarMinType,
1199  *mxEdDataBarMin, mpDoc, maPos);
1200  SetColorScaleEntry(mpDataBarData->mpUpperLimit.get(), *mxLbDataBarMaxType,
1201  *mxEdDataBarMax, mpDoc, maPos);
1202  ScDataBarSettingsDlg aDlg(mpParent->GetFrameWeld(), *mpDataBarData, mpDoc, maPos);
1203  if (aDlg.run() == RET_OK)
1204  {
1205  mpDataBarData.reset(aDlg.GetData());
1206  SetDataBarEntryTypes(*mpDataBarData->mpLowerLimit, *mxLbDataBarMinType, *mxEdDataBarMin, mpDoc);
1207  SetDataBarEntryTypes(*mpDataBarData->mpUpperLimit, *mxLbDataBarMaxType, *mxEdDataBarMax, mpDoc);
1208  DataBarTypeSelectHdl(*mxLbDataBarMinType);
1209  }
1210 }
1211 
1213  : ScCondFrmtEntry(pParent, pDoc, ScAddress())
1214  , mxLbDateEntry(mxBuilder->weld_combo_box("datetype"))
1215  , mxFtStyle(mxBuilder->weld_label("styleft"))
1216  , mxLbStyle(mxBuilder->weld_combo_box("style"))
1217  , mxWdPreviewWin(mxBuilder->weld_widget("previewwin"))
1218  , mxWdPreview(new weld::CustomWeld(*mxBuilder, "preview", maWdPreview))
1219  , mbIsInStyleCreate(false)
1220 {
1221  mxLbDateEntry->set_size_request(CommonWidgetWidth, -1);
1222  mxLbStyle->set_size_request(CommonWidgetWidth, -1);
1223 
1224  mxWdPreview->set_size_request(mxLbStyle->get_preferred_size().Height(), -1);
1225 
1226  Init();
1227 
1228  StartListening(*pDoc->GetStyleSheetPool(), DuplicateHandling::Prevent);
1229 
1230  if(pFormat)
1231  {
1232  sal_Int32 nPos = static_cast<sal_Int32>(pFormat->GetDateType());
1233  mxLbDateEntry->set_active(nPos);
1234 
1235  mxLbStyle->set_active_text(pFormat->GetStyleName());
1236  }
1237 
1238  StyleSelectHdl(*mxLbStyle);
1239 }
1240 
1242 {
1243 }
1244 
1246 {
1247  mxLbDateEntry->set_active(0);
1248  mxLbType->set_active(3);
1249 
1250  FillStyleListBox( mpDoc, *mxLbStyle );
1251  mxLbStyle->connect_changed( LINK( this, ScDateFrmtEntry, StyleSelectHdl ) );
1252  mxLbStyle->set_active(1);
1253 }
1254 
1256 {
1257  mxLbDateEntry->show();
1258  mxFtStyle->show();
1259  mxWdPreviewWin->show();
1260  mxLbStyle->show();
1261 
1262  Select();
1263 }
1264 
1266 {
1267  mxLbDateEntry->hide();
1268  mxFtStyle->hide();
1269  mxWdPreviewWin->hide();
1270  mxLbStyle->hide();
1271 
1272  Deselect();
1273 }
1274 
1276 {
1277  if(rHint.GetId() == SfxHintId::StyleSheetModified)
1278  {
1279  if(!mbIsInStyleCreate)
1280  UpdateStyleList(*mxLbStyle, mpDoc);
1281  }
1282 }
1283 
1285 {
1288  pNewEntry->SetDateType(eType);
1289  pNewEntry->SetStyleName(mxLbStyle->get_active_text());
1290  return pNewEntry;
1291 }
1292 
1294 {
1295  // tdf#124412 - set actual condition for an inactive date entry
1296  return ScCondFormatHelper::GetExpression(DATE, mxLbDateEntry->get_active());
1297 }
1298 
1300 {
1301  mbIsInStyleCreate = true;
1302  StyleSelect(mpParent->GetFrameWeld(), *mxLbStyle, mpDoc, maWdPreview);
1303  mbIsInStyleCreate = false;
1304 }
1305 
1307 {
1308 protected:
1309  std::unique_ptr<weld::Builder> mxBuilder;
1310 private:
1311  std::unique_ptr<weld::Container> mxGrid;
1312  std::unique_ptr<weld::Image> mxImgIcon;
1313  std::unique_ptr<weld::Label> mxFtEntry;
1314  std::unique_ptr<weld::Entry> mxEdEntry;
1315  std::unique_ptr<weld::ComboBox> mxLbEntryType;
1317 
1318 public:
1319  ScIconSetFrmtDataEntry(weld::Container* pParent, ScIconSetType eType, const ScDocument* pDoc,
1320  sal_Int32 i, const ScColorScaleEntry* pEntry = nullptr);
1322  void Show() { mxGrid->show(); }
1323  void Hide() { mxGrid->hide(); }
1324  void set_grid_top_attach(int nTop)
1325  {
1326  mxGrid->set_grid_left_attach(0);
1327  mxGrid->set_grid_top_attach(nTop);
1328  }
1329 
1330  ScColorScaleEntry* CreateEntry(ScDocument& rDoc, const ScAddress& rPos) const;
1331 
1332  void SetFirstEntry();
1333 };
1334 
1336  : mxBuilder(Application::CreateBuilder(pParent, "modules/scalc/ui/conditionaliconset.ui"))
1337  , mxGrid(mxBuilder->weld_container("ConditionalIconSet"))
1338  , mxImgIcon(mxBuilder->weld_image("icon"))
1339  , mxFtEntry(mxBuilder->weld_label("label"))
1340  , mxEdEntry(mxBuilder->weld_entry("entry"))
1341  , mxLbEntryType(mxBuilder->weld_combo_box("listbox"))
1342  , mpContainer(pParent)
1343 {
1344  mxImgIcon->set_from_icon_name(ScIconSetFormat::getIconName(eType, i));
1345  if(pEntry)
1346  {
1347  switch(pEntry->GetType())
1348  {
1349  case COLORSCALE_VALUE:
1350  mxLbEntryType->set_active(0);
1351  mxEdEntry->set_text(convertNumberToString(pEntry->GetValue(), pDoc));
1352  break;
1353  case COLORSCALE_PERCENTILE:
1354  mxLbEntryType->set_active(2);
1355  mxEdEntry->set_text(convertNumberToString(pEntry->GetValue(), pDoc));
1356  break;
1357  case COLORSCALE_PERCENT:
1358  mxLbEntryType->set_active(1);
1359  mxEdEntry->set_text(convertNumberToString(pEntry->GetValue(), pDoc));
1360  break;
1361  case COLORSCALE_FORMULA:
1362  mxLbEntryType->set_active(3);
1364  break;
1365  default:
1366  assert(false);
1367  }
1368  }
1369  else
1370  {
1371  mxLbEntryType->set_active(1);
1372  }
1373 }
1374 
1376 {
1377  mpContainer->move(mxGrid.get(), nullptr);
1378 }
1379 
1381 {
1382  sal_Int32 nPos = mxLbEntryType->get_active();
1383  OUString aText = mxEdEntry->get_text();
1384  ScColorScaleEntry* pEntry = new ScColorScaleEntry();
1385 
1386  sal_uInt32 nIndex = 0;
1387  double nVal = 0;
1388  SvNumberFormatter* pNumberFormatter = rDoc.GetFormatTable();
1389  (void)pNumberFormatter->IsNumberFormat(aText, nIndex, nVal);
1390  pEntry->SetValue(nVal);
1391 
1392  switch(nPos)
1393  {
1394  case 0:
1395  pEntry->SetType(COLORSCALE_VALUE);
1396  break;
1397  case 1:
1398  pEntry->SetType(COLORSCALE_PERCENT);
1399  break;
1400  case 2:
1401  pEntry->SetType(COLORSCALE_PERCENTILE);
1402  break;
1403  case 3:
1404  pEntry->SetType(COLORSCALE_FORMULA);
1405  pEntry->SetFormula(aText, rDoc, rPos, rDoc.GetGrammar());
1406  break;
1407  default:
1408  assert(false);
1409  }
1410 
1411  return pEntry;
1412 }
1413 
1415 {
1416  mxEdEntry->hide();
1417  mxLbEntryType->hide();
1418  mxFtEntry->hide();
1419  mxEdEntry->set_text("0");
1420  mxLbEntryType->set_active(1);
1421 }
1422 
1424  : ScCondFrmtEntry(pParent, pDoc, rPos)
1425  , mxLbColorFormat(mxBuilder->weld_combo_box("colorformat"))
1426  , mxLbIconSetType(mxBuilder->weld_combo_box("iconsettype"))
1427  , mxIconParent(mxBuilder->weld_container("iconparent"))
1428 {
1429  mxLbColorFormat->set_size_request(CommonWidgetWidth, -1);
1430  mxLbIconSetType->set_size_request(CommonWidgetWidth, -1);
1431 
1432  Init();
1433  mxLbColorFormat->connect_changed(LINK(pParent, ScCondFormatList, ColFormatTypeHdl));
1434 
1435  if(pFormat)
1436  {
1437  const ScIconSetFormatData* pIconSetFormatData = pFormat->GetIconSetData();
1438  ScIconSetType eType = pIconSetFormatData->eIconSetType;
1439  sal_Int32 nType = static_cast<sal_Int32>(eType);
1440  mxLbIconSetType->set_active(nType);
1441 
1442  for (size_t i = 0, n = pIconSetFormatData->m_Entries.size();
1443  i < n; ++i)
1444  {
1445  maEntries.emplace_back(new ScIconSetFrmtDataEntry(
1446  mxIconParent.get(), eType, pDoc, i, pIconSetFormatData->m_Entries[i].get()));
1447  maEntries[i]->set_grid_top_attach(i);
1448  }
1449  maEntries[0]->SetFirstEntry();
1450  }
1451  else
1452  IconSetTypeHdl(*mxLbIconSetType);
1453 }
1454 
1456 {
1457 }
1458 
1460 {
1461  mxLbColorFormat->set_active(3);
1462  mxLbType->set_active(0);
1463  mxLbIconSetType->set_active(0);
1464 
1465  mxLbIconSetType->connect_changed(LINK(this, ScIconSetFrmtEntry, IconSetTypeHdl));
1466 }
1467 
1469 {
1471 
1472  sal_Int32 nPos = mxLbIconSetType->get_active();
1473  sal_uInt32 nElements = pMap[nPos].nElements;
1474 
1475  maEntries.clear();
1476 
1477  for(size_t i = 0; i < nElements; ++i)
1478  {
1479  maEntries.emplace_back(new ScIconSetFrmtDataEntry(mxIconParent.get(), static_cast<ScIconSetType>(nPos), mpDoc, i));
1480  maEntries[i]->set_grid_top_attach(i);
1481  maEntries[i]->Show();
1482  }
1483  maEntries[0]->SetFirstEntry();
1484 }
1485 
1487 {
1489 }
1490 
1492 {
1493  mxLbColorFormat->show();
1494  mxLbIconSetType->show();
1495  for(auto& rxEntry : maEntries)
1496  {
1497  rxEntry->Show();
1498  }
1499 
1500  Select();
1501 }
1502 
1504 {
1505  mxLbColorFormat->hide();
1506  mxLbIconSetType->hide();
1507  for(auto& rxEntry : maEntries)
1508  {
1509  rxEntry->Hide();
1510  }
1511 
1512  Deselect();
1513 }
1514 
1516 {
1517  ScIconSetFormat* pFormat = new ScIconSetFormat(mpDoc);
1518 
1520  pData->eIconSetType = static_cast<ScIconSetType>(mxLbIconSetType->get_active());
1521  for(const auto& rxEntry : maEntries)
1522  {
1523  pData->m_Entries.emplace_back(rxEntry->CreateEntry(*mpDoc, maPos));
1524  }
1525  pFormat->SetIconSetData(pData);
1526 
1527  return pFormat;
1528 }
1529 
1530 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual void SetActive() override
virtual void SetActive() override
void Init(ScCondFormatDlg *pDialogParent)
std::unique_ptr< ScDataBarFormatData > mpDataBarData
const SfxPoolItem * ExecuteList(sal_uInt16 nSlot, SfxCallMode nCall, std::initializer_list< SfxPoolItem const * > args, std::initializer_list< SfxPoolItem const * > internalargs=std::initializer_list< SfxPoolItem const * >())
virtual void Select() override
sal_Int32 nIndex
virtual css::uno::Reference< css::awt::XWindow > GetXWindow()=0
std::unique_ptr< weld::ComboBox > mxLbType
std::unique_ptr< weld::ComboBox > mxLbEntryTypeMax
static sal_Int32 GetNumberEditFields(ScConditionMode eMode)
ScFormatEntry * createConditionEntry() const
void Init()
OUString ScResId(TranslateId aId)
Definition: scdll.cxx:90
std::unique_ptr< formula::RefEdit > mxEdVal2
std::unique_ptr< weld::Entry > mxEdDataBarMin
static const sal_Int32 NUM_COND_ENTRIES
ScFormatEntry * createFormulaEntry() const
virtual ~ScColorScale3FrmtEntry() override
void insert_text(int pos, const OUString &rStr)
virtual ~ScColorScale2FrmtEntry() override
void SetIndex(sal_Int32 nIndex)
std::unique_ptr< sal_Int32[]> pData
virtual OUString get_text(int pos) const =0
std::unique_ptr< ColorListBox > mxLbColMax
ScColorScale3FrmtEntry(ScCondFormatList *pParent, ScDocument *pDoc, const ScAddress &rPos, const ScColorScaleFormat *pFormat=nullptr)
std::unique_ptr< weld::ComboBox > mxLbEntryTypeMiddle
std::unique_ptr< weld::CustomWeld > mxWdPreview
sal_Int64 n
std::unique_ptr< weld::Label > mxFtEntry
std::unique_ptr< weld::ComboBox > mxLbDataBarMaxType
const OUString & GetStyle() const
Definition: conditio.hxx:472
virtual int find_text(const OUString &rStr) const =0
virtual void SetActive() override
virtual ScFormatEntry * GetEntry() const override
virtual OUString GetExpressionString() override
std::unique_ptr< ColorListBox > mxLbColMax
condformat::ScCondFormatDateType GetDateType() const
Definition: conditio.hxx:511
virtual OUString GetExpressionString()=0
OpCode GetOpCode() const
ScColorScale2FrmtEntry(ScCondFormatList *pParent, ScDocument *pDoc, const ScAddress &rPos, const ScColorScaleFormat *pFormat=nullptr)
std::unique_ptr< weld::Entry > mxEdMiddle
virtual SfxItemSet & GetItemSet()
void SetValue(double nValue)
Definition: colorscale.cxx:250
ScCondFormatDateType
Definition: conditio.hxx:483
std::unique_ptr< weld::Entry > mxEdEntry
SC_DLLPUBLIC formula::FormulaGrammar::Grammar GetGrammar() const
Definition: document.hxx:1007
static const ScIconSetMap g_IconSetMap[]
Definition: colorscale.hxx:380
virtual OUString get_active_id() const =0
virtual void SetActive() override
virtual int get_active() const =0
std::unique_ptr< ColorListBox > mxLbColMin
virtual void set_text(const OUString &rText)=0
ScConditionMode GetOperation() const
Definition: conditio.hxx:368
SfxHintId GetId() const
virtual int get_count() const =0
IMPL_LINK_NOARG(ScCondFrmtEntry, EntrySelectHdl, const MouseEvent &, bool)
std::unique_ptr< weld::Entry > mxEdMax
std::unique_ptr< weld::ComboBox > mxLbCondType
virtual OUString GetExpressionString() override
bool equalsAscii(std::u16string_view s1, const char *s2)
virtual ~ScIconSetFrmtEntry() override
virtual ScFormatEntry * GetEntry() const override
const ScTokenArray * GetFormula() const
Definition: colorscale.cxx:216
ScDataBarFrmtEntry(ScCondFormatList *pParemt, ScDocument *pDoc, const ScAddress &rPos, const ScDataBarFormat *pFormat=nullptr)
weld::Container * GetContainer()
virtual void SetActive() override
virtual ScFormatEntry * GetEntry() const override
Link< ScCondFrmtEntry &, void > maClickHdl
OpCode
#define CommonWidgetWidth
void SetColor(const Color &)
Definition: colorscale.cxx:310
std::unique_ptr< weld::ComboBox > mxLbColorFormat
ScIconSetType eIconSetType
Definition: colorscale.hxx:333
ScFormatEntry * createDatabarEntry() const
ScColorScaleEntryType GetType() const
Definition: colorscale.hxx:76
std::unique_ptr< weld::Widget > mxBorder
static SC_DLLPUBLIC OUString GetExpression(const ScConditionalFormat &rFormat, const ScAddress &rPos)
ScConditionMode
Definition: conditio.hxx:59
Mode eMode
virtual void Notify(SfxBroadcaster &rBC, const SfxHint &rHint) override
std::unique_ptr< weld::Widget > mxWdPreviewWin
virtual OUString GetExpressionString() override
virtual void Deselect() override
virtual ScFormatEntry * GetEntry() const override
std::unique_ptr< weld::ComboBox > mxLbColorFormat
bool mbActive
std::unique_ptr< weld::Label > mxFtCondition
virtual void Deselect()
sal_Int32 nElements
virtual void Notify(SfxBroadcaster &rBC, const SfxHint &rHint) override
const ::std::vector< Color > ImpSvNumberformatScan::StandardColor COL_LIGHTRED
std::unique_ptr< weld::CustomWeld > mxWdPreview
DocumentType eType
std::unique_ptr< weld::Entry > mxEdMin
void SelectEntry(const NamedColor &rColor)
std::unique_ptr< weld::Widget > mxWdPreviewWin
ScColorScaleEntryType
Definition: colorscale.hxx:31
std::unique_ptr< weld::CustomWeld > mxWdPreview
void set_active_text(const OUString &rStr)
virtual OUString GetExpressionString() override
SC_DLLPUBLIC SvNumberFormatter * GetFormatTable() const
Definition: documen2.cxx:459
virtual ScFormatEntry * GetEntry() const override
std::unique_ptr< weld::Label > mxFtMax
ScConditionFrmtEntry(ScCondFormatList *pParent, ScDocument *pDoc, ScCondFormatDlg *pDialogParent, const ScAddress &rPos, const ScCondFormatEntry *pFormatEntry=nullptr)
SfxDispatcher * GetDispatcher() const
int i
const Color & GetColor() const
Definition: colorscale.hxx:61
ScFormatEntry * createColorscaleEntry() const
std::unique_ptr< weld::ComboBox > mxLbDateEntry
ScCondFormatList * mpParent
void AddEntry(ScColorScaleEntry *pEntry)
Definition: colorscale.cxx:401
OUString GetExpression(const ScAddress &rCursor, sal_uInt16 nPos, sal_uInt32 nNumFmt=0, const formula::FormulaGrammar::Grammar eGrammar=formula::FormulaGrammar::GRAM_DEFAULT) const
Definition: conditio.cxx:1239
virtual OUString GetExpressionString() override
static SC_DLLPUBLIC const CharClass & getCharClass()
Definition: global.cxx:1024
std::unique_ptr< weld::Label > mxFtStyle
OUString uppercase(const OUString &rStr, sal_Int32 nPos, sal_Int32 nCount) const
std::unique_ptr< weld::Label > mxFtStyle
bool IsNumberFormat(const OUString &sString, sal_uInt32 &F_Index, double &fOutNumber, SvNumInputOptions eInputOptions=SvNumInputOptions::NONE)
std::unique_ptr< weld::Label > mxFtMin
const ScIconSetFormatData * GetIconSetData() const
ocBad
virtual void move(weld::Widget *pWidget, weld::Container *pNewParent)=0
static OUString getIconName(ScIconSetType eType, sal_Int32 nIndex)
virtual void SetInactive() override
ScCondFrmtEntry(ScCondFormatList *pParent, ScDocument *pDoc, const ScAddress &rPos)
void Lock(bool bLock)
virtual void set_active(int pos)=0
void StartListening(SfxBroadcaster &rBroadcaster, DuplicateHandling eDuplicateHanding=DuplicateHandling::Unexpected)
std::unique_ptr< weld::ComboBox > mxLbStyle
virtual void SetInactive() override
ScDateFrmtEntry(ScCondFormatList *pParent, ScDocument *pDoc, const ScCondDateFormatEntry *pFormat=nullptr)
std::unique_ptr< weld::ComboBox > mxLbIconSetType
std::unique_ptr< weld::Container > mxGrid
void SetFormula(const OUString &rFormula, ScDocument &rDoc, const ScAddress &rAddr, formula::FormulaGrammar::Grammar eGrammar=formula::FormulaGrammar::GRAM_DEFAULT)
Definition: colorscale.cxx:207
virtual ScFormatEntry * GetEntry() const override
std::unique_ptr< weld::Entry > mxEdDataBarMax
static const ScConditionMode mpEntryToCond[NUM_COND_ENTRIES]
virtual OUString get_text() const =0
std::unique_ptr< weld::ComboBox > mxLbStyle
XPropertyListType t
std::unique_ptr< weld::Image > mxImgIcon
std::unique_ptr< ColorListBox > mxLbColMin
virtual void SetInactive() override
RegionData_Impl * mpParent
virtual void SetInactive() override
virtual void set_message_type(EntryMessageType eType)=0
std::unique_ptr< weld::ComboBox > mxLbColorFormat
virtual ~ScDateFrmtEntry() override
Color const & GetSelectEntryColor() const
void GetInputLineString(const double &fOutNumber, sal_uInt32 nFIndex, OUString &rOutString, bool bFiltering=false, bool bForceSystemLocale=false)
ScFormatEntry * createColorscaleEntry() const
static ScTabViewShell * GetActiveViewShell()
Definition: tabvwsh4.cxx:1075
weld::Entry & rEdit
std::unique_ptr< weld::Label > mxFtCondNr
virtual void Select()
void SetIconSetData(ScIconSetFormatData *pData)
const OUString & GetStyleName() const
Definition: conditio.hxx:513
std::unique_ptr< formula::RefEdit > mxEdVal1
weld::Window * GetFrameWeld()
IMPL_LINK(ScConditionFrmtEntry, OnEdChanged, formula::RefEdit &, rRefEdit, void)
std::unique_ptr< weld::ComboBox > mxLbDataBarMinType
OUString const maStrCondition
OUString aName
virtual void SetInactive() override
std::unique_ptr< weld::ComboBox > mxLbEntryTypeMin
RET_OK
virtual OUString GetExpressionString() override
static sal_Int32 ConditionModeToEntryPos(ScConditionMode eMode)
ocColRowName
void SetDateType(condformat::ScCondFormatDateType eType)
Definition: conditio.cxx:1676
virtual ~ScFormulaFrmtEntry() override
QPRO_FUNC_TYPE nType
Definition: qproform.cxx:398
const ::std::vector< Color > ImpSvNumberformatScan::StandardColor COL_YELLOW
std::unique_ptr< weld::Label > mxFtVal
virtual OUString get_id(int pos) const =0
std::unique_ptr< weld::Container > mxGrid
SC_DLLPUBLIC ScStyleSheetPool * GetStyleSheetPool() const
Definition: document.cxx:6161
static ScConditionMode EntryPosToConditionMode(sal_Int32 aEntryPos)
const ScDataBarFormatData * GetDataBarData() const
Definition: colorscale.cxx:735
std::unique_ptr< weld::ComboBox > mxLbStyle
std::unique_ptr< weld::ComboBox > mxLbEntryType
ScIconSetType
Definition: colorscale.hxx:188
bool IsLocked() const
virtual ~ScConditionFrmtEntry() override
virtual void SetInactive() override
ScIconSetFrmtDataEntriesType maEntries
void SetFromItemSet(const SfxItemSet &rSet, bool bPreviewBackgroundToCharacter)
std::unique_ptr< weld::ComboBox > mxLbEntryTypeMax
virtual ~ScDataBarFrmtEntry() override
virtual void remove(int pos)=0
void append_text(const OUString &rStr)
std::unique_ptr< formula::RefEdit > mxEdFormula
void SetType(ScColorScaleEntryType eType)
Definition: colorscale.cxx:323
ScFormulaFrmtEntry(ScCondFormatList *pParent, ScDocument *PDoc, ScCondFormatDlg *pDialogParent, const ScAddress &rPos, const ScCondFormatEntry *pFormatEntry=nullptr)
ScColorScaleEntry * CreateEntry(ScDocument &rDoc, const ScAddress &rPos) const
std::unique_ptr< ColorListBox > mxLbColMiddle
virtual ScFormatEntry * GetEntry() const override
ScIconSetFrmtEntry(ScCondFormatList *pParent, ScDocument *pDoc, const ScAddress &rPos, const ScIconSetFormat *pFormat=nullptr)
std::unique_ptr< weld::Button > mxBtOptions
std::unique_ptr< weld::Label > mxFtStyle
std::unique_ptr< weld::Container > mxIconParent
virtual void SetActive() override
std::unique_ptr< weld::Entry > mxEdMax
virtual SfxStyleSheetBase * Find(const OUString &, SfxStyleFamily eFam, SfxStyleSearchBits n=SfxStyleSearchBits::All)
std::unique_ptr< weld::Widget > mxWdPreviewWin
ScIconSetFrmtDataEntry(weld::Container *pParent, ScIconSetType eType, const ScDocument *pDoc, sal_Int32 i, const ScColorScaleEntry *pEntry=nullptr)
void Init(ScCondFormatDlg *pDialogParent)
StackVar GetType() const
virtual void SetActive() override
virtual void SetInactive() override
double GetValue() const
Definition: colorscale.cxx:236
void SetStyleName(const OUString &rStyleName)
Definition: conditio.cxx:1681
sal_uInt16 nPos
virtual void set_sensitive(bool sensitive)=0
virtual OUString GetExpressionString() override
sal_Int32 nElements
Definition: colorscale.hxx:217
virtual OUString get_active_text() const =0
bool m_bDetectedRangeSegmentation false
std::unique_ptr< weld::ComboBox > mxLbEntryTypeMin
std::unique_ptr< weld::ComboBox > mxLbColorFormat
std::unique_ptr< weld::Entry > mxEdMin
std::unique_ptr< weld::Builder > mxBuilder
OUString sId
typedef void(CALLTYPE *GetFuncDataPtr)(sal_uInt16 &nNo