fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / sc / source / ui / condformat / condformatdlgentry.cxx
blob79cf58f1c5a3320efb8fbdc786b790e3718f6d44
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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 */
10 #include "condformatdlg.hxx"
11 #include "condformatdlgentry.hxx"
12 #include "condformatdlg.hrc"
13 #include "conditio.hxx"
15 #include "document.hxx"
17 #include <vcl/vclevent.hxx>
18 #include <svl/style.hxx>
19 #include <sfx2/dispatch.hxx>
20 #include <svl/stritem.hxx>
21 #include <svl/intitem.hxx>
22 #include <svx/xtable.hxx>
23 #include <svx/drawitem.hxx>
24 #include <vcl/msgbox.hxx>
25 #include <vcl/settings.hxx>
26 #include <formula/token.hxx>
27 #include "tokenarray.hxx"
28 #include "stlpool.hxx"
29 #include "tabvwsh.hxx"
30 #include "simpleformulacalc.hxx"
32 #include "colorformat.hxx"
34 #include "globstr.hrc"
36 #include <set>
38 ScCondFrmtEntry::ScCondFrmtEntry(vcl::Window* pParent, ScDocument* pDoc, const ScAddress& rPos):
39 Control(pParent, ScResId( RID_COND_ENTRY ) ),
40 mbActive(false),
41 maFtCondNr( VclPtr<FixedText>::Create( this, ScResId( FT_COND_NR ) ) ),
42 maFtCondition( VclPtr<FixedText>::Create( this, ScResId( FT_CONDITION ) ) ),
43 mnIndex(0),
44 maStrCondition(ScResId( STR_CONDITION ).toString()),
45 maLbType( VclPtr<ListBox>::Create( this, ScResId( LB_TYPE ) ) ),
46 mpDoc(pDoc),
47 maPos(rPos)
49 Color aBack(GetSettings().GetStyleSettings().GetWindowColor());
51 SetControlBackground(aBack);
52 SetBackground(GetControlBackground());
54 maFtCondNr->SetControlBackground(aBack);
55 maFtCondNr->SetBackground(maFtCondNr->GetControlBackground());
57 maFtCondition->SetControlBackground(aBack);
58 maFtCondition->SetBackground(maFtCondition->GetControlBackground());
60 maLbType->SetSelectHdl( LINK( pParent, ScCondFormatList, TypeListHdl ) );
61 maClickHdl = LINK( pParent, ScCondFormatList, EntrySelectHdl );
64 ScCondFrmtEntry::~ScCondFrmtEntry()
66 disposeOnce();
69 void ScCondFrmtEntry::dispose()
71 maFtCondNr.disposeAndClear();
72 maFtCondition.disposeAndClear();
73 maLbType.disposeAndClear();
74 Control::dispose();
77 bool ScCondFrmtEntry::Notify( NotifyEvent& rNEvt )
79 if( rNEvt.GetType() == MouseNotifyEvent::MOUSEBUTTONDOWN )
81 ImplCallEventListenersAndHandler( VCLEVENT_WINDOW_MOUSEBUTTONDOWN, maClickHdl, this );
83 return Control::Notify(rNEvt);
86 void ScCondFrmtEntry::SetIndex(sal_Int32 nIndex)
88 mnIndex = nIndex;
89 OUStringBuffer aBuffer(maStrCondition);
90 aBuffer.append(OUString::number(nIndex));
91 maFtCondNr->SetText(aBuffer.makeStringAndClear());
94 void ScCondFrmtEntry::SetHeight()
96 long nPad = LogicToPixel(Size(42,2), MapMode(MAP_APPFONT)).getHeight();
98 // Calculate maximum height we need from visible widgets
99 sal_uInt16 nChildren = GetChildCount();
101 long nMaxHeight = 0;
102 for(sal_uInt16 i = 0; i < nChildren; i++)
104 vcl::Window *pChild = GetChild(i);
105 if(!pChild || !pChild->IsVisible())
106 continue;
107 Point aPos = pChild->GetPosPixel();
108 Size aSize = pChild->GetSizePixel();
109 nMaxHeight = std::max(aPos.Y() + aSize.Height(), nMaxHeight);
111 Size aSize = GetSizePixel();
112 if(nMaxHeight > 0)
114 aSize.Height() = nMaxHeight + nPad;
115 SetSizePixel(aSize);
119 void ScCondFrmtEntry::Select()
121 maFtCondition->SetText(OUString());
122 maFtCondition->Hide();
123 maLbType->Show();
124 mbActive = true;
125 SetHeight();
128 void ScCondFrmtEntry::Deselect()
130 OUString maCondText = GetExpressionString();
131 maFtCondition->SetText(maCondText);
132 maFtCondition->Show();
133 maLbType->Hide();
134 mbActive = false;
135 SetHeight();
138 //condition
140 namespace {
142 void FillStyleListBox( ScDocument* pDoc, ListBox& rLbStyle )
144 rLbStyle.SetSeparatorPos(0);
145 std::set<OUString> aStyleNames;
146 SfxStyleSheetIterator aStyleIter( pDoc->GetStyleSheetPool(), SFX_STYLE_FAMILY_PARA );
147 for ( SfxStyleSheetBase* pStyle = aStyleIter.First(); pStyle; pStyle = aStyleIter.Next() )
149 OUString aName = pStyle->GetName();
150 aStyleNames.insert(aName);
152 for(std::set<OUString>::const_iterator itr = aStyleNames.begin(), itrEnd = aStyleNames.end();
153 itr != itrEnd; ++itr)
155 rLbStyle.InsertEntry( *itr );
161 const ScConditionMode ScConditionFrmtEntry::mpEntryToCond[ScConditionFrmtEntry::NUM_COND_ENTRIES] = {
162 SC_COND_EQUAL,
163 SC_COND_LESS,
164 SC_COND_GREATER,
165 SC_COND_EQLESS,
166 SC_COND_EQGREATER,
167 SC_COND_NOTEQUAL,
168 SC_COND_BETWEEN,
169 SC_COND_NOTBETWEEN,
170 SC_COND_DUPLICATE,
171 SC_COND_NOTDUPLICATE,
172 SC_COND_TOP10,
173 SC_COND_BOTTOM10,
174 SC_COND_TOP_PERCENT,
175 SC_COND_BOTTOM_PERCENT,
176 SC_COND_ABOVE_AVERAGE,
177 SC_COND_BELOW_AVERAGE,
178 SC_COND_ABOVE_EQUAL_AVERAGE,
179 SC_COND_BELOW_EQUAL_AVERAGE,
180 SC_COND_ERROR,
181 SC_COND_NOERROR,
182 SC_COND_BEGINS_WITH,
183 SC_COND_ENDS_WITH,
184 SC_COND_CONTAINS_TEXT,
185 SC_COND_NOT_CONTAINS_TEXT
188 ScConditionFrmtEntry::ScConditionFrmtEntry( vcl::Window* pParent, ScDocument* pDoc, ScCondFormatDlg* pDialogParent,
189 const ScAddress& rPos, const ScCondFormatEntry* pFormatEntry ):
190 ScCondFrmtEntry( pParent, pDoc, rPos ),
191 maLbCondType( VclPtr<ListBox>::Create( this, ScResId( LB_CELLIS_TYPE ) ) ),
192 maEdVal1( VclPtr<formula::RefEdit>::Create( this, nullptr, nullptr, ScResId( ED_VAL1 ) ) ),
193 maEdVal2( VclPtr<formula::RefEdit>::Create( this, nullptr, nullptr, ScResId( ED_VAL2 ) ) ),
194 maFtVal( VclPtr<FixedText>::Create( this, ScResId( FT_VAL ) ) ),
195 maFtStyle( VclPtr<FixedText>::Create( this, ScResId( FT_STYLE ) ) ),
196 maLbStyle( VclPtr<ListBox>::Create( this, ScResId( LB_STYLE ) ) ),
197 maWdPreview( VclPtr<SvxFontPrevWindow>::Create( this, ScResId( WD_PREVIEW ) ) ),
198 mbIsInStyleCreate(false)
201 FreeResource();
202 maLbType->SelectEntryPos(1);
204 Init(pDialogParent);
206 StartListening(*pDoc->GetStyleSheetPool(), true);
208 if(pFormatEntry)
210 OUString aStyleName = pFormatEntry->GetStyle();
211 maLbStyle->SelectEntry(aStyleName);
212 StyleSelectHdl(NULL);
213 ScConditionMode eMode = pFormatEntry->GetOperation();
215 maLbCondType->SelectEntryPos(ConditionModeToEntryPos(eMode));
217 switch(GetNumberEditFields(eMode))
219 case 0:
220 maEdVal1->Hide();
221 maEdVal2->Hide();
222 break;
223 case 1:
224 maEdVal1->Show();
225 maEdVal1->SetText(pFormatEntry->GetExpression(maPos, 0));
226 maEdVal2->Hide();
227 OnEdChanged(maEdVal1);
228 break;
229 case 2:
230 maEdVal1->Show();
231 maEdVal1->SetText(pFormatEntry->GetExpression(maPos, 0));
232 OnEdChanged(maEdVal1);
233 maEdVal2->Show();
234 maEdVal2->SetText(pFormatEntry->GetExpression(maPos, 1));
235 OnEdChanged(maEdVal2);
236 break;
239 else
241 maLbCondType->SelectEntryPos(0);
242 maEdVal2->Hide();
243 maLbStyle->SelectEntryPos(1);
247 ScConditionFrmtEntry::~ScConditionFrmtEntry()
249 disposeOnce();
252 void ScConditionFrmtEntry::dispose()
254 maLbCondType.disposeAndClear();
255 maEdVal1.disposeAndClear();
256 maEdVal2.disposeAndClear();
257 maFtVal.disposeAndClear();
258 maFtStyle.disposeAndClear();
259 maLbStyle.disposeAndClear();
260 maWdPreview.disposeAndClear();
261 ScCondFrmtEntry::dispose();
264 void ScConditionFrmtEntry::Init(ScCondFormatDlg* pDialogParent)
266 maEdVal1->SetGetFocusHdl( LINK( pDialogParent, ScCondFormatDlg, RangeGetFocusHdl ) );
267 maEdVal2->SetGetFocusHdl( LINK( pDialogParent, ScCondFormatDlg, RangeGetFocusHdl ) );
268 maEdVal1->SetLoseFocusHdl( LINK( pDialogParent, ScCondFormatDlg, RangeLoseFocusHdl ) );
269 maEdVal2->SetLoseFocusHdl( LINK( pDialogParent, ScCondFormatDlg, RangeLoseFocusHdl ) );
271 maEdVal1->SetStyle( maEdVal1->GetStyle() | WB_FORCECTRLBACKGROUND );
272 maEdVal2->SetStyle( maEdVal2->GetStyle() | WB_FORCECTRLBACKGROUND );
274 maEdVal1->SetModifyHdl( LINK( this, ScConditionFrmtEntry, OnEdChanged ) );
275 maEdVal2->SetModifyHdl( LINK( this, ScConditionFrmtEntry, OnEdChanged ) );
277 FillStyleListBox( mpDoc, *maLbStyle.get() );
278 maLbStyle->SetSelectHdl( LINK( this, ScConditionFrmtEntry, StyleSelectHdl ) );
280 maLbCondType->SetSelectHdl( LINK( this, ScConditionFrmtEntry, ConditionTypeSelectHdl ) );
283 ScFormatEntry* ScConditionFrmtEntry::createConditionEntry() const
285 ScConditionMode eMode = EntryPosToConditionMode(maLbCondType->GetSelectEntryPos());
286 OUString aExpr1 = maEdVal1->GetText();
287 OUString aExpr2;
288 if (GetNumberEditFields(eMode) == 2)
290 aExpr2 = maEdVal2->GetText();
291 if (aExpr2.isEmpty())
293 return NULL;
297 ScFormatEntry* pEntry = new ScCondFormatEntry(eMode, aExpr1, aExpr2, mpDoc, maPos, maLbStyle->GetSelectEntry());
298 return pEntry;
301 IMPL_LINK(ScConditionFrmtEntry, OnEdChanged, Edit*, pEdit)
303 OUString aFormula = pEdit->GetText();
305 if( aFormula.isEmpty() )
307 maFtVal->SetText(ScGlobal::GetRscString(STR_ENTER_VALUE));
308 return 0;
311 ScCompiler aComp( mpDoc, maPos );
312 aComp.SetGrammar( mpDoc->GetGrammar() );
313 boost::scoped_ptr<ScTokenArray> ta(aComp.CompileString(aFormula));
315 // Error, warn the user
316 if( ta->GetCodeError() || ( ta->GetLen() == 0 ) )
318 pEdit->SetControlBackground(COL_LIGHTRED);
319 maFtVal->SetText(ScGlobal::GetRscString(STR_VALID_DEFERROR));
320 return 0;
323 // Recognized col/row name or string token, warn the user
324 formula::FormulaToken* token = ta->First();
325 formula::StackVar t = token->GetType();
326 OpCode op = token->GetOpCode();
327 if( ( op == ocColRowName ) ||
328 ( ( op == ocBad ) && ( t == formula::svString ) )
331 pEdit->SetControlBackground(COL_YELLOW);
332 maFtVal->SetText(ScGlobal::GetRscString(STR_UNQUOTED_STRING));
333 return 0;
336 pEdit->SetControlBackground(GetSettings().GetStyleSettings().GetWindowColor());
337 maFtVal->SetText("");
338 return 0;
341 void ScConditionFrmtEntry::Select()
343 maFtVal->Show();
344 ScCondFrmtEntry::Select();
347 void ScConditionFrmtEntry::Deselect()
349 maFtVal->Hide();
350 ScCondFrmtEntry::Deselect();
354 sal_Int32 ScConditionFrmtEntry::ConditionModeToEntryPos( ScConditionMode eMode )
356 for ( sal_Int32 i = 0; i < NUM_COND_ENTRIES; ++i )
358 if (mpEntryToCond[i] == eMode)
360 return i;
363 assert(false); // should never get here
364 return 0;
367 ScConditionMode ScConditionFrmtEntry::EntryPosToConditionMode( sal_Int32 aEntryPos )
369 assert( 0 <= aEntryPos && aEntryPos < NUM_COND_ENTRIES );
370 return mpEntryToCond[aEntryPos];
373 sal_Int32 ScConditionFrmtEntry::GetNumberEditFields( ScConditionMode eMode )
375 switch(eMode)
377 case SC_COND_EQUAL:
378 case SC_COND_LESS:
379 case SC_COND_GREATER:
380 case SC_COND_EQLESS:
381 case SC_COND_EQGREATER:
382 case SC_COND_NOTEQUAL:
383 case SC_COND_TOP10:
384 case SC_COND_BOTTOM10:
385 case SC_COND_TOP_PERCENT:
386 case SC_COND_BOTTOM_PERCENT:
387 case SC_COND_BEGINS_WITH:
388 case SC_COND_ENDS_WITH:
389 case SC_COND_CONTAINS_TEXT:
390 case SC_COND_NOT_CONTAINS_TEXT:
391 case SC_COND_ERROR:
392 case SC_COND_NOERROR:
393 return 1;
394 case SC_COND_ABOVE_AVERAGE:
395 case SC_COND_BELOW_AVERAGE:
396 case SC_COND_ABOVE_EQUAL_AVERAGE:
397 case SC_COND_BELOW_EQUAL_AVERAGE:
398 case SC_COND_DUPLICATE:
399 case SC_COND_NOTDUPLICATE:
400 return 0;
401 case SC_COND_BETWEEN:
402 case SC_COND_NOTBETWEEN:
403 return 2;
404 default:
405 assert(false); // should never get here
406 return 0;
410 OUString ScConditionFrmtEntry::GetExpressionString()
412 return ScCondFormatHelper::GetExpression(CONDITION, maLbCondType->GetSelectEntryPos(), maEdVal1->GetText(), maEdVal2->GetText());
415 ScFormatEntry* ScConditionFrmtEntry::GetEntry() const
417 return createConditionEntry();
420 void ScConditionFrmtEntry::SetActive()
422 ScConditionMode eMode = EntryPosToConditionMode(maLbCondType->GetSelectEntryPos());
423 maLbCondType->Show();
424 switch(GetNumberEditFields(eMode))
426 case 1:
427 maEdVal1->Show();
428 break;
429 case 2:
430 maEdVal1->Show();
431 maEdVal2->Show();
432 break;
434 maFtStyle->Show();
435 maLbStyle->Show();
436 maWdPreview->Show();
438 Select();
441 void ScConditionFrmtEntry::SetInactive()
443 maLbCondType->Hide();
444 maEdVal1->Hide();
445 maEdVal2->Hide();
446 maFtStyle->Hide();
447 maLbStyle->Hide();
448 maWdPreview->Hide();
450 Deselect();
453 namespace {
455 void UpdateStyleList(ListBox& rLbStyle, ScDocument* pDoc)
457 OUString aSelectedStyle = rLbStyle.GetSelectEntry();
458 for(sal_Int32 i = rLbStyle.GetEntryCount(); i >= 1; --i)
460 rLbStyle.RemoveEntry(i);
462 FillStyleListBox(pDoc, rLbStyle);
463 rLbStyle.SelectEntry(aSelectedStyle);
468 void ScConditionFrmtEntry::Notify(SfxBroadcaster&, const SfxHint& rHint)
470 const SfxStyleSheetHint* pHint = dynamic_cast<const SfxStyleSheetHint*>(&rHint);
471 if(!pHint)
472 return;
474 sal_uInt16 nHint = pHint->GetHint();
475 if(nHint == SfxStyleSheetHintId::MODIFIED)
477 if(!mbIsInStyleCreate)
478 UpdateStyleList(*maLbStyle.get(), mpDoc);
482 namespace {
484 void StyleSelect( ListBox& rLbStyle, ScDocument* pDoc, SvxFontPrevWindow& rWdPreview )
486 if(rLbStyle.GetSelectEntryPos() == 0)
488 // call new style dialog
489 SfxUInt16Item aFamilyItem( SID_STYLE_FAMILY, SFX_STYLE_FAMILY_PARA );
490 SfxStringItem aRefItem( SID_STYLE_REFERENCE, ScGlobal::GetRscString(STR_STYLENAME_STANDARD) );
492 // unlock the dispatcher so SID_STYLE_NEW can be executed
493 // (SetDispatcherLock would affect all Calc documents)
494 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
495 SfxDispatcher* pDisp = pViewShell->GetDispatcher();
496 bool bLocked = pDisp->IsLocked();
497 if (bLocked)
498 pDisp->Lock(false);
500 // Execute the "new style" slot, complete with undo and all necessary updates.
501 // The return value (SfxUInt16Item) is ignored, look for new styles instead.
502 pDisp->Execute( SID_STYLE_NEW, SfxCallMode::SYNCHRON | SfxCallMode::RECORD | SfxCallMode::MODAL,
503 &aFamilyItem,
504 &aRefItem,
505 0L );
507 if (bLocked)
508 pDisp->Lock(true);
510 // Find the new style and add it into the style list boxes
511 SfxStyleSheetIterator aStyleIter( pDoc->GetStyleSheetPool(), SFX_STYLE_FAMILY_PARA );
512 bool bFound = false;
513 for ( SfxStyleSheetBase* pStyle = aStyleIter.First(); pStyle && !bFound; pStyle = aStyleIter.Next() )
515 OUString aName = pStyle->GetName();
516 if ( rLbStyle.GetEntryPos(aName) == LISTBOX_ENTRY_NOTFOUND ) // all lists contain the same entries
518 for( sal_uInt16 i = 1, n = rLbStyle.GetEntryCount(); i <= n && !bFound; ++i)
520 OUString aStyleName = ScGlobal::pCharClass->uppercase(OUString(rLbStyle.GetEntry(i)));
521 if( i == n )
523 rLbStyle.InsertEntry(aName);
524 rLbStyle.SelectEntry(aName);
525 bFound = true;
527 else if( aStyleName > ScGlobal::pCharClass->uppercase(aName) )
529 rLbStyle.InsertEntry(aName, i);
530 rLbStyle.SelectEntry(aName);
531 bFound = true;
538 OUString aStyleName = rLbStyle.GetSelectEntry();
539 SfxStyleSheetBase* pStyleSheet = pDoc->GetStyleSheetPool()->Find( aStyleName, SFX_STYLE_FAMILY_PARA );
540 if(pStyleSheet)
542 const SfxItemSet& rSet = pStyleSheet->GetItemSet();
543 rWdPreview.Init( rSet );
549 IMPL_LINK_NOARG(ScConditionFrmtEntry, StyleSelectHdl)
551 mbIsInStyleCreate = true;
552 StyleSelect( *maLbStyle.get(), mpDoc, *maWdPreview.get() );
553 mbIsInStyleCreate = false;
554 return 0;
557 // formula
559 ScFormulaFrmtEntry::ScFormulaFrmtEntry( vcl::Window* pParent, ScDocument* pDoc, ScCondFormatDlg* pDialogParent, const ScAddress& rPos, const ScCondFormatEntry* pFormat ):
560 ScCondFrmtEntry( pParent, pDoc, rPos ),
561 maFtStyle( VclPtr<FixedText>::Create( this, ScResId( FT_STYLE ) ) ),
562 maLbStyle( VclPtr<ListBox>::Create( this, ScResId( LB_STYLE ) ) ),
563 maWdPreview( VclPtr<SvxFontPrevWindow>::Create( this, ScResId( WD_PREVIEW ) ) ),
564 maEdFormula( VclPtr<formula::RefEdit>::Create(this, nullptr, nullptr, ScResId( ED_FORMULA ) ) )
566 Init(pDialogParent);
568 FreeResource();
569 maLbType->SelectEntryPos(2);
571 if(pFormat)
573 maEdFormula->SetText(pFormat->GetExpression(rPos, 0, 0, pDoc->GetGrammar()));
574 maLbStyle->SelectEntry(pFormat->GetStyle());
576 else
578 maLbStyle->SelectEntryPos(1);
581 StyleSelectHdl(NULL);
584 ScFormulaFrmtEntry::~ScFormulaFrmtEntry()
586 disposeOnce();
589 void ScFormulaFrmtEntry::dispose()
591 maFtStyle.disposeAndClear();
592 maLbStyle.disposeAndClear();
593 maWdPreview.disposeAndClear();
594 maEdFormula.disposeAndClear();
595 ScCondFrmtEntry::dispose();
598 void ScFormulaFrmtEntry::Init(ScCondFormatDlg* pDialogParent)
600 maEdFormula->SetGetFocusHdl( LINK( pDialogParent, ScCondFormatDlg, RangeGetFocusHdl ) );
601 maEdFormula->SetLoseFocusHdl( LINK( pDialogParent, ScCondFormatDlg, RangeLoseFocusHdl ) );
603 FillStyleListBox( mpDoc, *maLbStyle.get() );
604 maLbStyle->SetSelectHdl( LINK( this, ScFormulaFrmtEntry, StyleSelectHdl ) );
607 IMPL_LINK_NOARG(ScFormulaFrmtEntry, StyleSelectHdl)
609 StyleSelect( *maLbStyle.get(), mpDoc, *maWdPreview.get() );
611 return 0;
614 ScFormatEntry* ScFormulaFrmtEntry::createFormulaEntry() const
616 ScConditionMode eMode = SC_COND_DIRECT;
617 OUString aFormula = maEdFormula->GetText();
618 if(aFormula.isEmpty())
619 return NULL;
621 OUString aExpr2;
622 ScFormatEntry* pEntry = new ScCondFormatEntry(eMode, aFormula, aExpr2, mpDoc, maPos, maLbStyle->GetSelectEntry());
623 return pEntry;
626 ScFormatEntry* ScFormulaFrmtEntry::GetEntry() const
628 return createFormulaEntry();
631 OUString ScFormulaFrmtEntry::GetExpressionString()
633 return ScCondFormatHelper::GetExpression(FORMULA, 0, maEdFormula->GetText());
636 void ScFormulaFrmtEntry::SetActive()
638 maWdPreview->Show();
639 maFtStyle->Show();
640 maLbStyle->Show();
641 maEdFormula->Show();
643 Select();
646 void ScFormulaFrmtEntry::SetInactive()
648 maWdPreview->Hide();
649 maFtStyle->Hide();
650 maLbStyle->Hide();
651 maEdFormula->Hide();
653 Deselect();
656 //color scale
658 namespace {
660 OUString convertNumberToString(double nVal, ScDocument* pDoc)
662 SvNumberFormatter* pNumberFormatter = pDoc->GetFormatTable();
663 OUString aText;
664 pNumberFormatter->GetInputLineString(nVal, 0, aText);
665 return aText;
668 void SetColorScaleEntryTypes( const ScColorScaleEntry& rEntry, ListBox& rLbType, Edit& rEdit, ColorListBox& rLbCol, ScDocument* pDoc )
670 // entry Automatic is not available for color scales
671 sal_Int32 nIndex = static_cast<sal_Int32>(rEntry.GetType());
672 assert(nIndex > 0);
673 rLbType.SelectEntryPos(nIndex - 1);
674 switch(rEntry.GetType())
676 case COLORSCALE_MIN:
677 case COLORSCALE_MAX:
678 break;
679 case COLORSCALE_PERCENTILE:
680 case COLORSCALE_VALUE:
681 case COLORSCALE_PERCENT:
683 double nVal = rEntry.GetValue();
684 rEdit.SetText(convertNumberToString(nVal, pDoc));
686 break;
687 case COLORSCALE_FORMULA:
688 rEdit.SetText(rEntry.GetFormula(formula::FormulaGrammar::GRAM_DEFAULT));
689 break;
690 case COLORSCALE_AUTO:
691 abort();
692 break;
694 rLbCol.SelectEntry(rEntry.GetColor());
697 void SetColorScaleEntry( ScColorScaleEntry* pEntry, const ListBox& rType, const Edit& rValue, ScDocument* pDoc, const ScAddress& rPos, bool bDataBar )
700 // color scale does not have the automatic entry
701 sal_Int32 nPos = rType.GetSelectEntryPos();
702 if(!bDataBar)
703 ++nPos;
705 pEntry->SetType(static_cast<ScColorScaleEntryType>(nPos));
706 switch(nPos)
708 case COLORSCALE_AUTO:
709 case COLORSCALE_MIN:
710 case COLORSCALE_MAX:
711 break;
712 case COLORSCALE_PERCENTILE:
713 case COLORSCALE_VALUE:
714 case COLORSCALE_PERCENT:
716 sal_uInt32 nIndex = 0;
717 double nVal = 0;
718 SvNumberFormatter* pNumberFormatter = pDoc->GetFormatTable();
719 (void)pNumberFormatter->IsNumberFormat(rValue.GetText(), nIndex, nVal);
720 pEntry->SetValue(nVal);
722 break;
723 case COLORSCALE_FORMULA:
724 pEntry->SetFormula(rValue.GetText(), pDoc, rPos);
725 break;
726 default:
727 break;
731 ScColorScaleEntry* createColorScaleEntry( const ListBox& rType, const ColorListBox& rColor, const Edit& rValue, ScDocument* pDoc, const ScAddress& rPos )
733 ScColorScaleEntry* pEntry = new ScColorScaleEntry();
735 SetColorScaleEntry( pEntry, rType, rValue, pDoc, rPos, false );
736 Color aColor = rColor.GetSelectEntryColor();
737 pEntry->SetColor(aColor);
738 return pEntry;
743 ScColorScale2FrmtEntry::ScColorScale2FrmtEntry( vcl::Window* pParent, ScDocument* pDoc, const ScAddress& rPos, const ScColorScaleFormat* pFormat ):
744 ScCondFrmtEntry( pParent, pDoc, rPos ),
745 maLbColorFormat( VclPtr<ListBox>::Create( this, ScResId( LB_COLOR_FORMAT ) ) ),
746 maLbEntryTypeMin( VclPtr<ListBox>::Create( this, ScResId( LB_TYPE_COL_SCALE_MIN ) ) ),
747 maLbEntryTypeMax( VclPtr<ListBox>::Create( this, ScResId( LB_TYPE_COL_SCALE_MAX ) ) ),
748 maEdMin( VclPtr<Edit>::Create( this, ScResId( ED_COL_SCALE_MIN ) ) ),
749 maEdMax( VclPtr<Edit>::Create( this, ScResId( ED_COL_SCALE_MAX ) ) ),
750 maLbColMin( VclPtr<ColorListBox>::Create( this, ScResId( LB_COL_MIN ) ) ),
751 maLbColMax( VclPtr<ColorListBox>::Create( this, ScResId( LB_COL_MAX ) ) )
753 // remove the automatic entry from color scales
754 maLbEntryTypeMin->RemoveEntry(0);
755 maLbEntryTypeMax->RemoveEntry(0);
757 maLbType->SelectEntryPos(0);
758 maLbColorFormat->SelectEntryPos(0);
759 Init();
760 if(pFormat)
762 ScColorScaleFormat::const_iterator itr = pFormat->begin();
763 SetColorScaleEntryTypes(*itr, *maLbEntryTypeMin.get(), *maEdMin.get(), *maLbColMin.get(), pDoc);
764 ++itr;
765 SetColorScaleEntryTypes(*itr, *maLbEntryTypeMax.get(), *maEdMax.get(), *maLbColMax.get(), pDoc);
767 else
769 maLbEntryTypeMin->SelectEntryPos(0);
770 maLbEntryTypeMax->SelectEntryPos(1);
772 FreeResource();
774 maLbColorFormat->SetSelectHdl( LINK( pParent, ScCondFormatList, ColFormatTypeHdl ) );
776 EntryTypeHdl(maLbEntryTypeMin.get());
777 EntryTypeHdl(maLbEntryTypeMax.get());
780 ScColorScale2FrmtEntry::~ScColorScale2FrmtEntry()
782 disposeOnce();
785 void ScColorScale2FrmtEntry::dispose()
787 maLbColorFormat.disposeAndClear();
788 maLbEntryTypeMin.disposeAndClear();
789 maLbEntryTypeMax.disposeAndClear();
790 maEdMin.disposeAndClear();
791 maEdMax.disposeAndClear();
792 maLbColMin.disposeAndClear();
793 maLbColMax.disposeAndClear();
794 ScCondFrmtEntry::dispose();
797 void ScColorScale2FrmtEntry::Init()
799 maLbEntryTypeMin->SetSelectHdl( LINK( this, ScColorScale2FrmtEntry, EntryTypeHdl ) );
800 maLbEntryTypeMax->SetSelectHdl( LINK( this, ScColorScale2FrmtEntry, EntryTypeHdl ) );
802 SfxObjectShell* pDocSh = SfxObjectShell::Current();
803 XColorListRef pColorTable;
805 DBG_ASSERT( pDocSh, "DocShell not found!" );
807 if ( pDocSh )
809 const SfxPoolItem* pItem = pDocSh->GetItem( SID_COLOR_TABLE );
810 if ( pItem != NULL )
811 pColorTable = static_cast<const SvxColorListItem*>(pItem) ->GetColorList();
813 if ( pColorTable.is() )
815 // filling the line color box
816 maLbColMin->SetUpdateMode( false );
817 maLbColMax->SetUpdateMode( false );
819 for ( long i = 0; i < pColorTable->Count(); ++i )
821 XColorEntry* pEntry = pColorTable->GetColor(i);
822 maLbColMin->InsertEntry( pEntry->GetColor(), pEntry->GetName() );
823 maLbColMax->InsertEntry( pEntry->GetColor(), pEntry->GetName() );
825 if(pEntry->GetColor() == Color(COL_LIGHTRED))
826 maLbColMin->SelectEntryPos(i);
827 if(pEntry->GetColor() == Color(COL_LIGHTBLUE))
828 maLbColMax->SelectEntryPos(i);
830 maLbColMin->SetUpdateMode( true );
831 maLbColMax->SetUpdateMode( true );
835 ScFormatEntry* ScColorScale2FrmtEntry::createColorscaleEntry() const
837 ScColorScaleFormat* pColorScale = new ScColorScaleFormat(mpDoc);
838 pColorScale->AddEntry(createColorScaleEntry(*maLbEntryTypeMin.get(), *maLbColMin.get(), *maEdMin.get(), mpDoc, maPos));
839 pColorScale->AddEntry(createColorScaleEntry(*maLbEntryTypeMax.get(), *maLbColMax.get(), *maEdMax.get(), mpDoc, maPos));
840 return pColorScale;
843 OUString ScColorScale2FrmtEntry::GetExpressionString()
845 return ScCondFormatHelper::GetExpression( COLORSCALE, 0 );
848 ScFormatEntry* ScColorScale2FrmtEntry::GetEntry() const
850 return createColorscaleEntry();
853 void ScColorScale2FrmtEntry::SetActive()
855 maLbColorFormat->Show();
857 maLbEntryTypeMin->Show();
858 maLbEntryTypeMax->Show();
860 maEdMin->Show();
861 maEdMax->Show();
863 maLbColMin->Show();
864 maLbColMax->Show();
866 Select();
869 void ScColorScale2FrmtEntry::SetInactive()
871 maLbColorFormat->Hide();
873 maLbEntryTypeMin->Hide();
874 maLbEntryTypeMax->Hide();
876 maEdMin->Hide();
877 maEdMax->Hide();
879 maLbColMin->Hide();
880 maLbColMax->Hide();
882 Deselect();
885 IMPL_LINK( ScColorScale2FrmtEntry, EntryTypeHdl, ListBox*, pBox )
887 Edit* pEd = NULL;
888 if (pBox == maLbEntryTypeMin.get())
889 pEd = maEdMin;
890 else if (pBox == maLbEntryTypeMax.get())
891 pEd = maEdMax.get();
893 if (!pEd)
894 return 0;
896 bool bEnableEdit = true;
897 sal_Int32 nPos = pBox->GetSelectEntryPos();
898 if(nPos < 2)
900 bEnableEdit = false;
903 if (bEnableEdit)
904 pEd->Enable();
905 else
906 pEd->Disable();
908 return 0;
911 ScColorScale3FrmtEntry::ScColorScale3FrmtEntry( vcl::Window* pParent, ScDocument* pDoc, const ScAddress& rPos, const ScColorScaleFormat* pFormat ):
912 ScCondFrmtEntry( pParent, pDoc, rPos ),
913 maLbColorFormat( VclPtr<ListBox>::Create( this, ScResId( LB_COLOR_FORMAT ) ) ),
914 maLbEntryTypeMin( VclPtr<ListBox>::Create( this, ScResId( LB_TYPE_COL_SCALE_MIN ) ) ),
915 maLbEntryTypeMiddle( VclPtr<ListBox>::Create( this, ScResId( LB_TYPE_COL_SCALE_MIDDLE ) ) ),
916 maLbEntryTypeMax( VclPtr<ListBox>::Create( this, ScResId( LB_TYPE_COL_SCALE_MAX ) ) ),
917 maEdMin( VclPtr<Edit>::Create( this, ScResId( ED_COL_SCALE_MIN ) ) ),
918 maEdMiddle( VclPtr<Edit>::Create( this, ScResId( ED_COL_SCALE_MIDDLE ) ) ),
919 maEdMax( VclPtr<Edit>::Create( this, ScResId( ED_COL_SCALE_MAX ) ) ),
920 maLbColMin( VclPtr<ColorListBox>::Create( this, ScResId( LB_COL_MIN ) ) ),
921 maLbColMiddle( VclPtr<ColorListBox>::Create( this, ScResId( LB_COL_MIDDLE ) ) ),
922 maLbColMax( VclPtr<ColorListBox>::Create( this, ScResId( LB_COL_MAX ) ) )
924 // remove the automatic entry from color scales
925 maLbEntryTypeMin->RemoveEntry(0);
926 maLbEntryTypeMiddle->RemoveEntry(0);
927 maLbEntryTypeMax->RemoveEntry(0);
928 maLbColorFormat->SelectEntryPos(1);
930 Init();
931 maLbType->SelectEntryPos(0);
932 if(pFormat)
934 ScColorScaleFormat::const_iterator itr = pFormat->begin();
935 SetColorScaleEntryTypes(*itr, *maLbEntryTypeMin.get(), *maEdMin.get(), *maLbColMin.get(), pDoc);
936 assert(pFormat->size() == 3);
937 ++itr;
938 SetColorScaleEntryTypes(*itr, *maLbEntryTypeMiddle.get(), *maEdMiddle.get(), *maLbColMiddle.get(), pDoc);
939 ++itr;
940 SetColorScaleEntryTypes(*itr, *maLbEntryTypeMax.get(), *maEdMax.get(), *maLbColMax.get(), pDoc);
942 else
944 maLbColorFormat->SelectEntryPos(1);
945 maLbEntryTypeMin->SelectEntryPos(0);
946 maLbEntryTypeMiddle->SelectEntryPos(2);
947 maLbEntryTypeMax->SelectEntryPos(1);
948 maEdMiddle->SetText(OUString::number(50));
950 FreeResource();
952 maLbColorFormat->SetSelectHdl( LINK( pParent, ScCondFormatList, ColFormatTypeHdl ) );
953 EntryTypeHdl(maLbEntryTypeMin.get());
954 EntryTypeHdl(maLbEntryTypeMiddle.get());
955 EntryTypeHdl(maLbEntryTypeMax.get());
958 ScColorScale3FrmtEntry::~ScColorScale3FrmtEntry()
960 disposeOnce();
963 void ScColorScale3FrmtEntry::dispose()
965 maLbColorFormat.disposeAndClear();
966 maLbEntryTypeMin.disposeAndClear();
967 maLbEntryTypeMiddle.disposeAndClear();
968 maLbEntryTypeMax.disposeAndClear();
969 maEdMin.disposeAndClear();
970 maEdMiddle.disposeAndClear();
971 maEdMax.disposeAndClear();
972 maLbColMin.disposeAndClear();
973 maLbColMiddle.disposeAndClear();
974 maLbColMax.disposeAndClear();
975 ScCondFrmtEntry::dispose();
978 void ScColorScale3FrmtEntry::Init()
980 maLbEntryTypeMin->SetSelectHdl( LINK( this, ScColorScale3FrmtEntry, EntryTypeHdl ) );
981 maLbEntryTypeMax->SetSelectHdl( LINK( this, ScColorScale3FrmtEntry, EntryTypeHdl ) );
982 maLbEntryTypeMiddle->SetSelectHdl( LINK( this, ScColorScale3FrmtEntry, EntryTypeHdl ) );
984 SfxObjectShell* pDocSh = SfxObjectShell::Current();
985 XColorListRef pColorTable;
987 DBG_ASSERT( pDocSh, "DocShell not found!" );
989 if ( pDocSh )
991 const SfxPoolItem* pItem = pDocSh->GetItem( SID_COLOR_TABLE );
992 if ( pItem != NULL )
993 pColorTable = static_cast<const SvxColorListItem*>(pItem)->GetColorList();
995 if ( pColorTable.is() )
997 // filling the line color box
998 maLbColMin->SetUpdateMode( false );
999 maLbColMiddle->SetUpdateMode( false );
1000 maLbColMax->SetUpdateMode( false );
1002 for ( long i = 0; i < pColorTable->Count(); ++i )
1004 XColorEntry* pEntry = pColorTable->GetColor(i);
1005 maLbColMin->InsertEntry( pEntry->GetColor(), pEntry->GetName() );
1006 maLbColMiddle->InsertEntry( pEntry->GetColor(), pEntry->GetName() );
1007 maLbColMax->InsertEntry( pEntry->GetColor(), pEntry->GetName() );
1009 if(pEntry->GetColor() == Color(COL_LIGHTRED))
1010 maLbColMin->SelectEntryPos(i);
1011 if(pEntry->GetColor() == Color(COL_GREEN))
1012 maLbColMiddle->SelectEntryPos(i);
1013 if(pEntry->GetColor() == Color(COL_LIGHTBLUE))
1014 maLbColMax->SelectEntryPos(i);
1016 maLbColMin->SetUpdateMode( true );
1017 maLbColMiddle->SetUpdateMode( true );
1018 maLbColMax->SetUpdateMode( true );
1022 ScFormatEntry* ScColorScale3FrmtEntry::createColorscaleEntry() const
1024 ScColorScaleFormat* pColorScale = new ScColorScaleFormat(mpDoc);
1025 pColorScale->AddEntry(createColorScaleEntry(*maLbEntryTypeMin.get(), *maLbColMin.get(), *maEdMin.get(), mpDoc, maPos));
1026 if(maLbColorFormat->GetSelectEntryPos() == 1)
1027 pColorScale->AddEntry(createColorScaleEntry(*maLbEntryTypeMiddle.get(), *maLbColMiddle.get(), *maEdMiddle.get(), mpDoc, maPos));
1028 pColorScale->AddEntry(createColorScaleEntry(*maLbEntryTypeMax.get(), *maLbColMax.get(), *maEdMax.get(), mpDoc, maPos));
1029 return pColorScale;
1032 OUString ScColorScale3FrmtEntry::GetExpressionString()
1034 return ScCondFormatHelper::GetExpression( COLORSCALE, 0 );
1037 ScFormatEntry* ScColorScale3FrmtEntry::GetEntry() const
1039 return createColorscaleEntry();
1042 void ScColorScale3FrmtEntry::SetActive()
1044 maLbColorFormat->Show();
1045 maLbEntryTypeMin->Show();
1046 maLbEntryTypeMiddle->Show();
1047 maLbEntryTypeMax->Show();
1049 maEdMin->Show();
1050 maEdMiddle->Show();
1051 maEdMax->Show();
1053 maLbColMin->Show();
1054 maLbColMiddle->Show();
1055 maLbColMax->Show();
1057 Select();
1060 void ScColorScale3FrmtEntry::SetInactive()
1062 maLbColorFormat->Hide();
1064 maLbEntryTypeMin->Hide();
1065 maLbEntryTypeMiddle->Hide();
1066 maLbEntryTypeMax->Hide();
1068 maEdMin->Hide();
1069 maEdMiddle->Hide();
1070 maEdMax->Hide();
1072 maLbColMin->Hide();
1073 maLbColMiddle->Hide();
1074 maLbColMax->Hide();
1076 Deselect();
1079 IMPL_LINK( ScColorScale3FrmtEntry, EntryTypeHdl, ListBox*, pBox )
1081 Edit* pEd = NULL;
1082 if(pBox == maLbEntryTypeMin.get())
1083 pEd = maEdMin.get();
1084 else if(pBox == maLbEntryTypeMiddle.get())
1085 pEd = maEdMiddle.get();
1086 else if(pBox == maLbEntryTypeMax.get())
1087 pEd = maEdMax.get();
1089 if (!pEd)
1090 return 0;
1092 bool bEnableEdit = true;
1093 sal_Int32 nPos = pBox->GetSelectEntryPos();
1094 if(nPos < 2)
1096 bEnableEdit = false;
1099 if(bEnableEdit)
1100 pEd->Enable();
1101 else
1102 pEd->Disable();
1104 return 0;
1107 IMPL_LINK_NOARG( ScConditionFrmtEntry, ConditionTypeSelectHdl )
1109 sal_Int32 nSelectPos = maLbCondType->GetSelectEntryPos();
1110 ScConditionMode eMode = EntryPosToConditionMode(nSelectPos);
1111 switch(GetNumberEditFields(eMode))
1113 case 0:
1114 maEdVal1->Hide();
1115 maEdVal2->Hide();
1116 maFtVal->Hide();
1117 break;
1118 case 1:
1119 maEdVal1->Show();
1120 maEdVal2->Hide();
1121 maFtVal->Show();
1122 break;
1123 case 2:
1124 maEdVal1->Show();
1125 maEdVal2->Show();
1126 maFtVal->Show();
1127 break;
1130 return 0;
1133 //databar
1135 namespace {
1137 void SetDataBarEntryTypes( const ScColorScaleEntry& rEntry, ListBox& rLbType, Edit& rEdit, ScDocument* pDoc )
1139 rLbType.SelectEntryPos(rEntry.GetType());
1140 switch(rEntry.GetType())
1142 case COLORSCALE_AUTO:
1143 case COLORSCALE_MIN:
1144 case COLORSCALE_MAX:
1145 break;
1146 case COLORSCALE_VALUE:
1147 case COLORSCALE_PERCENT:
1148 case COLORSCALE_PERCENTILE:
1150 double nVal = rEntry.GetValue();
1151 SvNumberFormatter* pNumberFormatter = pDoc->GetFormatTable();
1152 OUString aText;
1153 pNumberFormatter->GetInputLineString(nVal, 0, aText);
1154 rEdit.SetText(aText);
1156 break;
1157 case COLORSCALE_FORMULA:
1158 rEdit.SetText(rEntry.GetFormula(formula::FormulaGrammar::GRAM_DEFAULT));
1159 break;
1165 ScDataBarFrmtEntry::ScDataBarFrmtEntry( vcl::Window* pParent, ScDocument* pDoc, const ScAddress& rPos, const ScDataBarFormat* pFormat ):
1166 ScCondFrmtEntry( pParent, pDoc, rPos ),
1167 maLbColorFormat( VclPtr<ListBox>::Create( this, ScResId( LB_COLOR_FORMAT ) ) ),
1168 maLbDataBarMinType( VclPtr<ListBox>::Create( this, ScResId( LB_TYPE_COL_SCALE_MIN ) ) ),
1169 maLbDataBarMaxType( VclPtr<ListBox>::Create( this, ScResId( LB_TYPE_COL_SCALE_MAX ) ) ),
1170 maEdDataBarMin( VclPtr<Edit>::Create( this, ScResId( ED_COL_SCALE_MIN ) ) ),
1171 maEdDataBarMax( VclPtr<Edit>::Create( this, ScResId( ED_COL_SCALE_MAX ) ) ),
1172 maBtOptions( VclPtr<PushButton>::Create( this, ScResId( BTN_OPTIONS ) ) )
1174 maLbColorFormat->SelectEntryPos(2);
1175 maLbType->SelectEntryPos(0);
1176 if(pFormat)
1178 mpDataBarData.reset(new ScDataBarFormatData(*pFormat->GetDataBarData()));
1179 SetDataBarEntryTypes(*mpDataBarData->mpLowerLimit, *maLbDataBarMinType.get(), *maEdDataBarMin.get(), pDoc);
1180 SetDataBarEntryTypes(*mpDataBarData->mpUpperLimit, *maLbDataBarMaxType.get(), *maEdDataBarMax.get(), pDoc);
1181 DataBarTypeSelectHdl(NULL);
1183 else
1185 maLbDataBarMinType->SelectEntryPos(0);
1186 maLbDataBarMaxType->SelectEntryPos(0);
1187 DataBarTypeSelectHdl(NULL);
1189 Init();
1191 maLbColorFormat->SetSelectHdl( LINK( pParent, ScCondFormatList, ColFormatTypeHdl ) );
1193 FreeResource();
1196 ScDataBarFrmtEntry::~ScDataBarFrmtEntry()
1198 disposeOnce();
1201 void ScDataBarFrmtEntry::dispose()
1203 maLbColorFormat.disposeAndClear();
1204 maLbDataBarMinType.disposeAndClear();
1205 maLbDataBarMaxType.disposeAndClear();
1206 maEdDataBarMin.disposeAndClear();
1207 maEdDataBarMax.disposeAndClear();
1208 maBtOptions.disposeAndClear();
1209 ScCondFrmtEntry::dispose();
1212 ScFormatEntry* ScDataBarFrmtEntry::GetEntry() const
1214 return createDatabarEntry();
1217 void ScDataBarFrmtEntry::Init()
1219 maLbDataBarMinType->SetSelectHdl( LINK( this, ScDataBarFrmtEntry, DataBarTypeSelectHdl ) );
1220 maLbDataBarMaxType->SetSelectHdl( LINK( this, ScDataBarFrmtEntry, DataBarTypeSelectHdl ) );
1222 maBtOptions->SetClickHdl( LINK( this, ScDataBarFrmtEntry, OptionBtnHdl ) );
1224 if(!mpDataBarData)
1226 mpDataBarData.reset(new ScDataBarFormatData());
1227 mpDataBarData->mpUpperLimit.reset(new ScColorScaleEntry());
1228 mpDataBarData->mpLowerLimit.reset(new ScColorScaleEntry());
1229 mpDataBarData->mpLowerLimit->SetType(COLORSCALE_AUTO);
1230 mpDataBarData->mpUpperLimit->SetType(COLORSCALE_AUTO);
1231 mpDataBarData->maPositiveColor = COL_LIGHTBLUE;
1235 ScFormatEntry* ScDataBarFrmtEntry::createDatabarEntry() const
1237 SetColorScaleEntry(mpDataBarData->mpLowerLimit.get(), *maLbDataBarMinType.get(), *maEdDataBarMin.get(), mpDoc, maPos, true);
1238 SetColorScaleEntry(mpDataBarData->mpUpperLimit.get(), *maLbDataBarMaxType.get(), *maEdDataBarMax.get(), mpDoc, maPos, true);
1239 ScDataBarFormat* pDataBar = new ScDataBarFormat(mpDoc);
1240 pDataBar->SetDataBarData(new ScDataBarFormatData(*mpDataBarData.get()));
1241 return pDataBar;
1244 OUString ScDataBarFrmtEntry::GetExpressionString()
1246 return ScCondFormatHelper::GetExpression( DATABAR, 0 );
1249 void ScDataBarFrmtEntry::SetActive()
1251 maLbColorFormat->Show();
1253 maLbDataBarMinType->Show();
1254 maLbDataBarMaxType->Show();
1255 maEdDataBarMin->Show();
1256 maEdDataBarMax->Show();
1257 maBtOptions->Show();
1259 Select();
1262 void ScDataBarFrmtEntry::SetInactive()
1264 maLbColorFormat->Hide();
1266 maLbDataBarMinType->Hide();
1267 maLbDataBarMaxType->Hide();
1268 maEdDataBarMin->Hide();
1269 maEdDataBarMax->Hide();
1270 maBtOptions->Hide();
1272 Deselect();
1275 IMPL_LINK_NOARG( ScDataBarFrmtEntry, DataBarTypeSelectHdl )
1277 sal_Int32 nSelectPos = maLbDataBarMinType->GetSelectEntryPos();
1278 if(nSelectPos <= COLORSCALE_MAX)
1279 maEdDataBarMin->Disable();
1280 else
1281 maEdDataBarMin->Enable();
1283 nSelectPos = maLbDataBarMaxType->GetSelectEntryPos();
1284 if(nSelectPos <= COLORSCALE_MAX)
1285 maEdDataBarMax->Disable();
1286 else
1287 maEdDataBarMax->Enable();
1289 return 0;
1292 IMPL_LINK_NOARG( ScDataBarFrmtEntry, OptionBtnHdl )
1294 SetColorScaleEntry(mpDataBarData->mpLowerLimit.get(), *maLbDataBarMinType.get(), *maEdDataBarMin.get(), mpDoc, maPos, true);
1295 SetColorScaleEntry(mpDataBarData->mpUpperLimit.get(), *maLbDataBarMaxType.get(), *maEdDataBarMax.get(), mpDoc, maPos, true);
1296 ScopedVclPtrInstance<ScDataBarSettingsDlg> pDlg(this, *mpDataBarData, mpDoc, maPos);
1297 if( pDlg->Execute() == RET_OK)
1299 mpDataBarData.reset(pDlg->GetData());
1300 SetDataBarEntryTypes(*mpDataBarData->mpLowerLimit, *maLbDataBarMinType, *maEdDataBarMin.get(), mpDoc);
1301 SetDataBarEntryTypes(*mpDataBarData->mpUpperLimit, *maLbDataBarMaxType.get(), *maEdDataBarMax.get(), mpDoc);
1302 DataBarTypeSelectHdl(NULL);
1304 return 0;
1307 ScDateFrmtEntry::ScDateFrmtEntry( vcl::Window* pParent, ScDocument* pDoc, const ScCondDateFormatEntry* pFormat ):
1308 ScCondFrmtEntry( pParent, pDoc, ScAddress() ),
1309 maLbDateEntry( VclPtr<ListBox>::Create( this, ScResId( LB_DATE_TYPE ) ) ),
1310 maFtStyle( VclPtr<FixedText>::Create( this, ScResId( FT_STYLE ) ) ),
1311 maLbStyle( VclPtr<ListBox>::Create( this, ScResId( LB_STYLE ) ) ),
1312 maWdPreview( VclPtr<SvxFontPrevWindow>::Create( this, ScResId( WD_PREVIEW ) ) ),
1313 mbIsInStyleCreate(false)
1315 Init();
1316 FreeResource();
1318 StartListening(*pDoc->GetStyleSheetPool(), true);
1320 if(pFormat)
1322 sal_Int32 nPos = static_cast<sal_Int32>(pFormat->GetDateType());
1323 maLbDateEntry->SelectEntryPos(nPos);
1325 OUString aStyleName = pFormat->GetStyleName();
1326 maLbStyle->SelectEntry(aStyleName);
1329 StyleSelectHdl(NULL);
1332 ScDateFrmtEntry::~ScDateFrmtEntry()
1334 disposeOnce();
1337 void ScDateFrmtEntry::dispose()
1339 maLbDateEntry.disposeAndClear();
1340 maFtStyle.disposeAndClear();
1341 maLbStyle.disposeAndClear();
1342 maWdPreview.disposeAndClear();
1343 ScCondFrmtEntry::dispose();
1346 void ScDateFrmtEntry::Init()
1348 maLbDateEntry->SelectEntryPos(0);
1349 maLbType->SelectEntryPos(3);
1351 FillStyleListBox( mpDoc, *maLbStyle.get() );
1352 maLbStyle->SetSelectHdl( LINK( this, ScDateFrmtEntry, StyleSelectHdl ) );
1353 maLbStyle->SelectEntryPos(1);
1356 void ScDateFrmtEntry::SetActive()
1358 maLbDateEntry->Show();
1359 maFtStyle->Show();
1360 maWdPreview->Show();
1361 maLbStyle->Show();
1363 Select();
1366 void ScDateFrmtEntry::SetInactive()
1368 maLbDateEntry->Hide();
1369 maFtStyle->Hide();
1370 maWdPreview->Hide();
1371 maLbStyle->Hide();
1373 Deselect();
1376 void ScDateFrmtEntry::Notify( SfxBroadcaster&, const SfxHint& rHint )
1378 const SfxStyleSheetHint* pHint = dynamic_cast<const SfxStyleSheetHint*>(&rHint);
1379 if(!pHint)
1380 return;
1382 sal_uInt16 nHint = pHint->GetHint();
1383 if(nHint == SfxStyleSheetHintId::MODIFIED)
1385 if(!mbIsInStyleCreate)
1386 UpdateStyleList(*maLbStyle.get(), mpDoc);
1390 ScFormatEntry* ScDateFrmtEntry::GetEntry() const
1392 ScCondDateFormatEntry* pNewEntry = new ScCondDateFormatEntry(mpDoc);
1393 condformat::ScCondFormatDateType eType = static_cast<condformat::ScCondFormatDateType>(maLbDateEntry->GetSelectEntryPos());
1394 pNewEntry->SetDateType(eType);
1395 pNewEntry->SetStyleName(maLbStyle->GetSelectEntry());
1396 return pNewEntry;
1399 OUString ScDateFrmtEntry::GetExpressionString()
1401 return ScCondFormatHelper::GetExpression(DATE, 0);
1404 IMPL_LINK_NOARG( ScDateFrmtEntry, StyleSelectHdl )
1406 mbIsInStyleCreate = true;
1407 StyleSelect( *maLbStyle.get(), mpDoc, *maWdPreview.get() );
1408 mbIsInStyleCreate = false;
1410 return 0;
1413 class ScIconSetFrmtDataEntry : public Control
1415 private:
1416 VclPtr<FixedImage> maImgIcon;
1417 VclPtr<FixedText> maFtEntry;
1418 VclPtr<Edit> maEdEntry;
1419 VclPtr<ListBox> maLbEntryType;
1421 public:
1422 ScIconSetFrmtDataEntry( vcl::Window* pParent, ScIconSetType eType, ScDocument* pDoc,
1423 sal_Int32 i, const ScColorScaleEntry* pEntry = NULL );
1424 virtual ~ScIconSetFrmtDataEntry();
1425 virtual void dispose() SAL_OVERRIDE;
1427 ScColorScaleEntry* CreateEntry(ScDocument* pDoc, const ScAddress& rPos) const;
1429 void SetFirstEntry();
1432 ScIconSetFrmtDataEntry::ScIconSetFrmtDataEntry( vcl::Window* pParent, ScIconSetType eType, ScDocument* pDoc, sal_Int32 i, const ScColorScaleEntry* pEntry ):
1433 Control( pParent, ScResId( RID_ICON_SET_ENTRY ) ),
1434 maImgIcon( VclPtr<FixedImage>::Create( this, ScResId( IMG_ICON ) ) ),
1435 maFtEntry( VclPtr<FixedText>::Create( this, ScResId( FT_ICON_SET_ENTRY_TEXT ) ) ),
1436 maEdEntry( VclPtr<Edit>::Create( this, ScResId( ED_ICON_SET_ENTRY_VALUE ) ) ),
1437 maLbEntryType( VclPtr<ListBox>::Create( this, ScResId( LB_ICON_SET_ENTRY_TYPE ) ) )
1439 maImgIcon->SetImage(Image(ScIconSetFormat::getBitmap(eType, i)));
1440 if(pEntry)
1442 switch(pEntry->GetType())
1444 case COLORSCALE_VALUE:
1445 maLbEntryType->SelectEntryPos(0);
1446 maEdEntry->SetText(convertNumberToString(pEntry->GetValue(), pDoc));
1447 break;
1448 case COLORSCALE_PERCENTILE:
1449 maLbEntryType->SelectEntryPos(2);
1450 maEdEntry->SetText(convertNumberToString(pEntry->GetValue(), pDoc));
1451 break;
1452 case COLORSCALE_PERCENT:
1453 maLbEntryType->SelectEntryPos(1);
1454 maEdEntry->SetText(convertNumberToString(pEntry->GetValue(), pDoc));
1455 break;
1456 case COLORSCALE_FORMULA:
1457 maLbEntryType->SelectEntryPos(3);
1458 maEdEntry->SetText(pEntry->GetFormula(formula::FormulaGrammar::GRAM_DEFAULT));
1459 break;
1460 default:
1461 assert(false);
1464 else
1466 maLbEntryType->SelectEntryPos(1);
1468 FreeResource();
1471 ScIconSetFrmtDataEntry::~ScIconSetFrmtDataEntry()
1473 disposeOnce();
1476 void ScIconSetFrmtDataEntry::dispose()
1478 maImgIcon.disposeAndClear();
1479 maFtEntry.disposeAndClear();
1480 maEdEntry.disposeAndClear();
1481 maLbEntryType.disposeAndClear();
1482 Control::dispose();
1485 ScColorScaleEntry* ScIconSetFrmtDataEntry::CreateEntry(ScDocument* pDoc, const ScAddress& rPos) const
1487 sal_Int32 nPos = maLbEntryType->GetSelectEntryPos();
1488 OUString aText = maEdEntry->GetText();
1489 ScColorScaleEntry* pEntry = new ScColorScaleEntry();
1491 sal_uInt32 nIndex = 0;
1492 double nVal = 0;
1493 SvNumberFormatter* pNumberFormatter = pDoc->GetFormatTable();
1494 (void)pNumberFormatter->IsNumberFormat(aText, nIndex, nVal);
1495 pEntry->SetValue(nVal);
1497 switch(nPos)
1499 case 0:
1500 pEntry->SetType(COLORSCALE_VALUE);
1501 break;
1502 case 1:
1503 pEntry->SetType(COLORSCALE_PERCENT);
1504 break;
1505 case 2:
1506 pEntry->SetType(COLORSCALE_PERCENTILE);
1507 break;
1508 case 3:
1509 pEntry->SetType(COLORSCALE_FORMULA);
1510 pEntry->SetFormula(aText, pDoc, rPos, pDoc->GetGrammar());
1511 break;
1512 default:
1513 assert(false);
1516 return pEntry;
1519 void ScIconSetFrmtDataEntry::SetFirstEntry()
1521 maEdEntry->Hide();
1522 maLbEntryType->Hide();
1523 maFtEntry->Hide();
1524 maEdEntry->SetText(OUString("0"));
1525 maLbEntryType->SelectEntryPos(1);
1528 ScIconSetFrmtEntry::ScIconSetFrmtEntry( vcl::Window* pParent, ScDocument* pDoc, const ScAddress& rPos, const ScIconSetFormat* pFormat ):
1529 ScCondFrmtEntry( pParent, pDoc, rPos ),
1530 maLbColorFormat( VclPtr<ListBox>::Create( this, ScResId( LB_COLOR_FORMAT ) ) ),
1531 maLbIconSetType( VclPtr<ListBox>::Create( this, ScResId( LB_ICONSET_TYPE ) ) )
1533 Init();
1534 FreeResource();
1535 maLbColorFormat->SetSelectHdl( LINK( pParent, ScCondFormatList, ColFormatTypeHdl ) );
1537 if(pFormat)
1539 const ScIconSetFormatData* pIconSetFormatData = pFormat->GetIconSetData();
1540 ScIconSetType eType = pIconSetFormatData->eIconSetType;
1541 sal_Int32 nType = static_cast<sal_Int32>(eType);
1542 maLbIconSetType->SelectEntryPos(nType);
1544 for(size_t i = 0, n = pIconSetFormatData->maEntries.size();
1545 i < n; ++i)
1547 maEntries.push_back( VclPtr<ScIconSetFrmtDataEntry>::Create( this, eType, pDoc, i, &pIconSetFormatData->maEntries[i] ) );
1548 Point aPos = maEntries[0]->GetPosPixel();
1549 aPos.Y() += maEntries[0]->GetSizePixel().Height() * i * 1.2;
1550 maEntries[i]->SetPosPixel( aPos );
1552 maEntries[0]->SetFirstEntry();
1554 else
1555 IconSetTypeHdl(NULL);
1558 ScIconSetFrmtEntry::~ScIconSetFrmtEntry()
1560 disposeOnce();
1563 void ScIconSetFrmtEntry::dispose()
1565 for (auto it = maEntries.begin(); it != maEntries.end(); ++it)
1566 it->disposeAndClear();
1567 maEntries.clear();
1568 maLbColorFormat.disposeAndClear();
1569 maLbIconSetType.disposeAndClear();
1570 ScCondFrmtEntry::dispose();
1573 void ScIconSetFrmtEntry::Init()
1575 maLbColorFormat->SelectEntryPos(3);
1576 maLbType->SelectEntryPos(0);
1577 maLbIconSetType->SelectEntryPos(0);
1579 maLbIconSetType->SetSelectHdl( LINK( this, ScIconSetFrmtEntry, IconSetTypeHdl ) );
1582 IMPL_LINK_NOARG( ScIconSetFrmtEntry, IconSetTypeHdl )
1584 ScIconSetMap* pMap = ScIconSetFormat::getIconSetMap();
1586 sal_Int32 nPos = maLbIconSetType->GetSelectEntryPos();
1587 sal_uInt32 nElements = pMap[nPos].nElements;
1589 for (auto it = maEntries.begin(); it != maEntries.end(); ++it)
1590 it->disposeAndClear();
1591 maEntries.clear();
1593 for(size_t i = 0; i < nElements; ++i)
1595 maEntries.push_back( VclPtr<ScIconSetFrmtDataEntry>::Create( this, static_cast<ScIconSetType>(nPos), mpDoc, i ) );
1596 Point aPos = maEntries[0]->GetPosPixel();
1597 aPos.Y() += maEntries[0]->GetSizePixel().Height() * i * 1.2;
1598 maEntries[i]->SetPosPixel( aPos );
1599 maEntries[i]->Show();
1601 maEntries[0]->SetFirstEntry();
1603 SetHeight();
1605 return 0;
1608 OUString ScIconSetFrmtEntry::GetExpressionString()
1610 return ScCondFormatHelper::GetExpression(ICONSET, 0);
1613 void ScIconSetFrmtEntry::SetActive()
1615 maLbColorFormat->Show();
1616 maLbIconSetType->Show();
1617 for(ScIconSetFrmtDataEntriesType::iterator itr = maEntries.begin(),
1618 itrEnd = maEntries.end(); itr != itrEnd; ++itr)
1620 (*itr)->Show();
1623 Select();
1626 void ScIconSetFrmtEntry::SetInactive()
1628 maLbColorFormat->Hide();
1629 maLbIconSetType->Hide();
1630 for(ScIconSetFrmtDataEntriesType::iterator itr = maEntries.begin(),
1631 itrEnd = maEntries.end(); itr != itrEnd; ++itr)
1633 (*itr)->Hide();
1636 Deselect();
1639 ScFormatEntry* ScIconSetFrmtEntry::GetEntry() const
1641 ScIconSetFormat* pFormat = new ScIconSetFormat(mpDoc);
1643 ScIconSetFormatData* pData = new ScIconSetFormatData;
1644 pData->eIconSetType = static_cast<ScIconSetType>(maLbIconSetType->GetSelectEntryPos());
1645 for(ScIconSetFrmtDataEntriesType::const_iterator itr = maEntries.begin(),
1646 itrEnd = maEntries.end(); itr != itrEnd; ++itr)
1648 pData->maEntries.push_back((*itr)->CreateEntry(mpDoc, maPos));
1650 pFormat->SetIconSetData(pData);
1652 return pFormat;
1655 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */