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