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