1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/.
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"
38 ScCondFrmtEntry::ScCondFrmtEntry(vcl::Window
* pParent
, ScDocument
* pDoc
, const ScAddress
& rPos
):
39 Control(pParent
, ScResId( RID_COND_ENTRY
) ),
41 maFtCondNr( VclPtr
<FixedText
>::Create( this, ScResId( FT_COND_NR
) ) ),
42 maFtCondition( VclPtr
<FixedText
>::Create( this, ScResId( FT_CONDITION
) ) ),
44 maStrCondition(ScResId( STR_CONDITION
).toString()),
45 maLbType( VclPtr
<ListBox
>::Create( this, ScResId( LB_TYPE
) ) ),
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()
69 void ScCondFrmtEntry::dispose()
71 maFtCondNr
.disposeAndClear();
72 maFtCondition
.disposeAndClear();
73 maLbType
.disposeAndClear();
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
)
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();
102 for(sal_uInt16 i
= 0; i
< nChildren
; i
++)
104 vcl::Window
*pChild
= GetChild(i
);
105 if(!pChild
|| !pChild
->IsVisible())
107 Point aPos
= pChild
->GetPosPixel();
108 Size aSize
= pChild
->GetSizePixel();
109 nMaxHeight
= std::max(aPos
.Y() + aSize
.Height(), nMaxHeight
);
111 Size aSize
= GetSizePixel();
114 aSize
.Height() = nMaxHeight
+ nPad
;
119 void ScCondFrmtEntry::Select()
121 maFtCondition
->SetText(OUString());
122 maFtCondition
->Hide();
128 void ScCondFrmtEntry::Deselect()
130 OUString maCondText
= GetExpressionString();
131 maFtCondition
->SetText(maCondText
);
132 maFtCondition
->Show();
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
] = {
171 SC_COND_NOTDUPLICATE
,
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
,
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)
202 maLbType
->SelectEntryPos(1);
206 StartListening(*pDoc
->GetStyleSheetPool(), true);
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
))
225 maEdVal1
->SetText(pFormatEntry
->GetExpression(maPos
, 0));
227 OnEdChanged(maEdVal1
);
231 maEdVal1
->SetText(pFormatEntry
->GetExpression(maPos
, 0));
232 OnEdChanged(maEdVal1
);
234 maEdVal2
->SetText(pFormatEntry
->GetExpression(maPos
, 1));
235 OnEdChanged(maEdVal2
);
241 maLbCondType
->SelectEntryPos(0);
243 maLbStyle
->SelectEntryPos(1);
247 ScConditionFrmtEntry::~ScConditionFrmtEntry()
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();
288 if (GetNumberEditFields(eMode
) == 2)
290 aExpr2
= maEdVal2
->GetText();
291 if (aExpr2
.isEmpty())
297 ScFormatEntry
* pEntry
= new ScCondFormatEntry(eMode
, aExpr1
, aExpr2
, mpDoc
, maPos
, maLbStyle
->GetSelectEntry());
301 IMPL_LINK(ScConditionFrmtEntry
, OnEdChanged
, Edit
*, pEdit
)
303 OUString aFormula
= pEdit
->GetText();
305 if( aFormula
.isEmpty() )
307 maFtVal
->SetText(ScGlobal::GetRscString(STR_ENTER_VALUE
));
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
));
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
));
336 pEdit
->SetControlBackground(GetSettings().GetStyleSettings().GetWindowColor());
337 maFtVal
->SetText("");
341 void ScConditionFrmtEntry::Select()
344 ScCondFrmtEntry::Select();
347 void ScConditionFrmtEntry::Deselect()
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
)
363 assert(false); // should never get here
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
)
379 case SC_COND_GREATER
:
381 case SC_COND_EQGREATER
:
382 case SC_COND_NOTEQUAL
:
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
:
392 case SC_COND_NOERROR
:
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
:
401 case SC_COND_BETWEEN
:
402 case SC_COND_NOTBETWEEN
:
405 assert(false); // should never get here
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
))
441 void ScConditionFrmtEntry::SetInactive()
443 maLbCondType
->Hide();
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
);
474 sal_uInt16 nHint
= pHint
->GetHint();
475 if(nHint
== SfxStyleSheetHintId::MODIFIED
)
477 if(!mbIsInStyleCreate
)
478 UpdateStyleList(*maLbStyle
.get(), mpDoc
);
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();
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
,
510 // Find the new style and add it into the style list boxes
511 SfxStyleSheetIterator
aStyleIter( pDoc
->GetStyleSheetPool(), SFX_STYLE_FAMILY_PARA
);
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
)));
523 rLbStyle
.InsertEntry(aName
);
524 rLbStyle
.SelectEntry(aName
);
527 else if( aStyleName
> ScGlobal::pCharClass
->uppercase(aName
) )
529 rLbStyle
.InsertEntry(aName
, i
);
530 rLbStyle
.SelectEntry(aName
);
538 OUString aStyleName
= rLbStyle
.GetSelectEntry();
539 SfxStyleSheetBase
* pStyleSheet
= pDoc
->GetStyleSheetPool()->Find( aStyleName
, SFX_STYLE_FAMILY_PARA
);
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;
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
) ) )
569 maLbType
->SelectEntryPos(2);
573 maEdFormula
->SetText(pFormat
->GetExpression(rPos
, 0, 0, pDoc
->GetGrammar()));
574 maLbStyle
->SelectEntry(pFormat
->GetStyle());
578 maLbStyle
->SelectEntryPos(1);
581 StyleSelectHdl(NULL
);
584 ScFormulaFrmtEntry::~ScFormulaFrmtEntry()
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() );
614 ScFormatEntry
* ScFormulaFrmtEntry::createFormulaEntry() const
616 ScConditionMode eMode
= SC_COND_DIRECT
;
617 OUString aFormula
= maEdFormula
->GetText();
618 if(aFormula
.isEmpty())
622 ScFormatEntry
* pEntry
= new ScCondFormatEntry(eMode
, aFormula
, aExpr2
, mpDoc
, maPos
, maLbStyle
->GetSelectEntry());
626 ScFormatEntry
* ScFormulaFrmtEntry::GetEntry() const
628 return createFormulaEntry();
631 OUString
ScFormulaFrmtEntry::GetExpressionString()
633 return ScCondFormatHelper::GetExpression(FORMULA
, 0, maEdFormula
->GetText());
636 void ScFormulaFrmtEntry::SetActive()
646 void ScFormulaFrmtEntry::SetInactive()
660 OUString
convertNumberToString(double nVal
, ScDocument
* pDoc
)
662 SvNumberFormatter
* pNumberFormatter
= pDoc
->GetFormatTable();
664 pNumberFormatter
->GetInputLineString(nVal
, 0, 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());
673 rLbType
.SelectEntryPos(nIndex
- 1);
674 switch(rEntry
.GetType())
679 case COLORSCALE_PERCENTILE
:
680 case COLORSCALE_VALUE
:
681 case COLORSCALE_PERCENT
:
683 double nVal
= rEntry
.GetValue();
684 rEdit
.SetText(convertNumberToString(nVal
, pDoc
));
687 case COLORSCALE_FORMULA
:
688 rEdit
.SetText(rEntry
.GetFormula(formula::FormulaGrammar::GRAM_DEFAULT
));
690 case COLORSCALE_AUTO
:
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();
705 pEntry
->SetType(static_cast<ScColorScaleEntryType
>(nPos
));
708 case COLORSCALE_AUTO
:
712 case COLORSCALE_PERCENTILE
:
713 case COLORSCALE_VALUE
:
714 case COLORSCALE_PERCENT
:
716 sal_uInt32 nIndex
= 0;
718 SvNumberFormatter
* pNumberFormatter
= pDoc
->GetFormatTable();
719 (void)pNumberFormatter
->IsNumberFormat(rValue
.GetText(), nIndex
, nVal
);
720 pEntry
->SetValue(nVal
);
723 case COLORSCALE_FORMULA
:
724 pEntry
->SetFormula(rValue
.GetText(), pDoc
, rPos
);
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
);
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);
762 ScColorScaleFormat::const_iterator itr
= pFormat
->begin();
763 SetColorScaleEntryTypes(*itr
, *maLbEntryTypeMin
.get(), *maEdMin
.get(), *maLbColMin
.get(), pDoc
);
765 SetColorScaleEntryTypes(*itr
, *maLbEntryTypeMax
.get(), *maEdMax
.get(), *maLbColMax
.get(), pDoc
);
769 maLbEntryTypeMin
->SelectEntryPos(0);
770 maLbEntryTypeMax
->SelectEntryPos(1);
774 maLbColorFormat
->SetSelectHdl( LINK( pParent
, ScCondFormatList
, ColFormatTypeHdl
) );
776 EntryTypeHdl(maLbEntryTypeMin
.get());
777 EntryTypeHdl(maLbEntryTypeMax
.get());
780 ScColorScale2FrmtEntry::~ScColorScale2FrmtEntry()
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!" );
809 const SfxPoolItem
* pItem
= pDocSh
->GetItem( SID_COLOR_TABLE
);
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
));
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();
869 void ScColorScale2FrmtEntry::SetInactive()
871 maLbColorFormat
->Hide();
873 maLbEntryTypeMin
->Hide();
874 maLbEntryTypeMax
->Hide();
885 IMPL_LINK( ScColorScale2FrmtEntry
, EntryTypeHdl
, ListBox
*, pBox
)
888 if (pBox
== maLbEntryTypeMin
.get())
890 else if (pBox
== maLbEntryTypeMax
.get())
896 bool bEnableEdit
= true;
897 sal_Int32 nPos
= pBox
->GetSelectEntryPos();
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);
931 maLbType
->SelectEntryPos(0);
934 ScColorScaleFormat::const_iterator itr
= pFormat
->begin();
935 SetColorScaleEntryTypes(*itr
, *maLbEntryTypeMin
.get(), *maEdMin
.get(), *maLbColMin
.get(), pDoc
);
936 assert(pFormat
->size() == 3);
938 SetColorScaleEntryTypes(*itr
, *maLbEntryTypeMiddle
.get(), *maEdMiddle
.get(), *maLbColMiddle
.get(), pDoc
);
940 SetColorScaleEntryTypes(*itr
, *maLbEntryTypeMax
.get(), *maEdMax
.get(), *maLbColMax
.get(), pDoc
);
944 maLbColorFormat
->SelectEntryPos(1);
945 maLbEntryTypeMin
->SelectEntryPos(0);
946 maLbEntryTypeMiddle
->SelectEntryPos(2);
947 maLbEntryTypeMax
->SelectEntryPos(1);
948 maEdMiddle
->SetText(OUString::number(50));
952 maLbColorFormat
->SetSelectHdl( LINK( pParent
, ScCondFormatList
, ColFormatTypeHdl
) );
953 EntryTypeHdl(maLbEntryTypeMin
.get());
954 EntryTypeHdl(maLbEntryTypeMiddle
.get());
955 EntryTypeHdl(maLbEntryTypeMax
.get());
958 ScColorScale3FrmtEntry::~ScColorScale3FrmtEntry()
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!" );
991 const SfxPoolItem
* pItem
= pDocSh
->GetItem( SID_COLOR_TABLE
);
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
));
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();
1054 maLbColMiddle
->Show();
1060 void ScColorScale3FrmtEntry::SetInactive()
1062 maLbColorFormat
->Hide();
1064 maLbEntryTypeMin
->Hide();
1065 maLbEntryTypeMiddle
->Hide();
1066 maLbEntryTypeMax
->Hide();
1073 maLbColMiddle
->Hide();
1079 IMPL_LINK( ScColorScale3FrmtEntry
, EntryTypeHdl
, ListBox
*, pBox
)
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();
1092 bool bEnableEdit
= true;
1093 sal_Int32 nPos
= pBox
->GetSelectEntryPos();
1096 bEnableEdit
= false;
1107 IMPL_LINK_NOARG( ScConditionFrmtEntry
, ConditionTypeSelectHdl
)
1109 sal_Int32 nSelectPos
= maLbCondType
->GetSelectEntryPos();
1110 ScConditionMode eMode
= EntryPosToConditionMode(nSelectPos
);
1111 switch(GetNumberEditFields(eMode
))
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
:
1146 case COLORSCALE_VALUE
:
1147 case COLORSCALE_PERCENT
:
1148 case COLORSCALE_PERCENTILE
:
1150 double nVal
= rEntry
.GetValue();
1151 SvNumberFormatter
* pNumberFormatter
= pDoc
->GetFormatTable();
1153 pNumberFormatter
->GetInputLineString(nVal
, 0, aText
);
1154 rEdit
.SetText(aText
);
1157 case COLORSCALE_FORMULA
:
1158 rEdit
.SetText(rEntry
.GetFormula(formula::FormulaGrammar::GRAM_DEFAULT
));
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);
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
);
1185 maLbDataBarMinType
->SelectEntryPos(0);
1186 maLbDataBarMaxType
->SelectEntryPos(0);
1187 DataBarTypeSelectHdl(NULL
);
1191 maLbColorFormat
->SetSelectHdl( LINK( pParent
, ScCondFormatList
, ColFormatTypeHdl
) );
1196 ScDataBarFrmtEntry::~ScDataBarFrmtEntry()
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
) );
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()));
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();
1262 void ScDataBarFrmtEntry::SetInactive()
1264 maLbColorFormat
->Hide();
1266 maLbDataBarMinType
->Hide();
1267 maLbDataBarMaxType
->Hide();
1268 maEdDataBarMin
->Hide();
1269 maEdDataBarMax
->Hide();
1270 maBtOptions
->Hide();
1275 IMPL_LINK_NOARG( ScDataBarFrmtEntry
, DataBarTypeSelectHdl
)
1277 sal_Int32 nSelectPos
= maLbDataBarMinType
->GetSelectEntryPos();
1278 if(nSelectPos
<= COLORSCALE_MAX
)
1279 maEdDataBarMin
->Disable();
1281 maEdDataBarMin
->Enable();
1283 nSelectPos
= maLbDataBarMaxType
->GetSelectEntryPos();
1284 if(nSelectPos
<= COLORSCALE_MAX
)
1285 maEdDataBarMax
->Disable();
1287 maEdDataBarMax
->Enable();
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
);
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)
1318 StartListening(*pDoc
->GetStyleSheetPool(), true);
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()
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();
1360 maWdPreview
->Show();
1366 void ScDateFrmtEntry::SetInactive()
1368 maLbDateEntry
->Hide();
1370 maWdPreview
->Hide();
1376 void ScDateFrmtEntry::Notify( SfxBroadcaster
&, const SfxHint
& rHint
)
1378 const SfxStyleSheetHint
* pHint
= dynamic_cast<const SfxStyleSheetHint
*>(&rHint
);
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());
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;
1413 class ScIconSetFrmtDataEntry
: public Control
1416 VclPtr
<FixedImage
> maImgIcon
;
1417 VclPtr
<FixedText
> maFtEntry
;
1418 VclPtr
<Edit
> maEdEntry
;
1419 VclPtr
<ListBox
> maLbEntryType
;
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
)));
1442 switch(pEntry
->GetType())
1444 case COLORSCALE_VALUE
:
1445 maLbEntryType
->SelectEntryPos(0);
1446 maEdEntry
->SetText(convertNumberToString(pEntry
->GetValue(), pDoc
));
1448 case COLORSCALE_PERCENTILE
:
1449 maLbEntryType
->SelectEntryPos(2);
1450 maEdEntry
->SetText(convertNumberToString(pEntry
->GetValue(), pDoc
));
1452 case COLORSCALE_PERCENT
:
1453 maLbEntryType
->SelectEntryPos(1);
1454 maEdEntry
->SetText(convertNumberToString(pEntry
->GetValue(), pDoc
));
1456 case COLORSCALE_FORMULA
:
1457 maLbEntryType
->SelectEntryPos(3);
1458 maEdEntry
->SetText(pEntry
->GetFormula(formula::FormulaGrammar::GRAM_DEFAULT
));
1466 maLbEntryType
->SelectEntryPos(1);
1471 ScIconSetFrmtDataEntry::~ScIconSetFrmtDataEntry()
1476 void ScIconSetFrmtDataEntry::dispose()
1478 maImgIcon
.disposeAndClear();
1479 maFtEntry
.disposeAndClear();
1480 maEdEntry
.disposeAndClear();
1481 maLbEntryType
.disposeAndClear();
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;
1493 SvNumberFormatter
* pNumberFormatter
= pDoc
->GetFormatTable();
1494 (void)pNumberFormatter
->IsNumberFormat(aText
, nIndex
, nVal
);
1495 pEntry
->SetValue(nVal
);
1500 pEntry
->SetType(COLORSCALE_VALUE
);
1503 pEntry
->SetType(COLORSCALE_PERCENT
);
1506 pEntry
->SetType(COLORSCALE_PERCENTILE
);
1509 pEntry
->SetType(COLORSCALE_FORMULA
);
1510 pEntry
->SetFormula(aText
, pDoc
, rPos
, pDoc
->GetGrammar());
1519 void ScIconSetFrmtDataEntry::SetFirstEntry()
1522 maLbEntryType
->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
) ) )
1535 maLbColorFormat
->SetSelectHdl( LINK( pParent
, ScCondFormatList
, ColFormatTypeHdl
) );
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();
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();
1555 IconSetTypeHdl(NULL
);
1558 ScIconSetFrmtEntry::~ScIconSetFrmtEntry()
1563 void ScIconSetFrmtEntry::dispose()
1565 for (auto it
= maEntries
.begin(); it
!= maEntries
.end(); ++it
)
1566 it
->disposeAndClear();
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();
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();
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
)
1626 void ScIconSetFrmtEntry::SetInactive()
1628 maLbColorFormat
->Hide();
1629 maLbIconSetType
->Hide();
1630 for(ScIconSetFrmtDataEntriesType::iterator itr
= maEntries
.begin(),
1631 itrEnd
= maEntries
.end(); itr
!= itrEnd
; ++itr
)
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
);
1655 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */