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