Stop leaking all ScPostIt instances.
[LibreOffice.git] / sc / source / ui / condformat / condformatdlgentry.cxx
blob8566dbdff5c01de42fefb732d0e90bfca07d0523
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 "tokenarray.hxx"
26 #include "stlpool.hxx"
27 #include "tabvwsh.hxx"
29 #include "colorformat.hxx"
31 #include "globstr.hrc"
33 #include <set>
35 ScCondFrmtEntry::ScCondFrmtEntry(Window* pParent, ScDocument* pDoc, const ScAddress& rPos):
36 Control(pParent, ScResId( RID_COND_ENTRY ) ),
37 mbActive(false),
38 maFtCondNr( this, ScResId( FT_COND_NR ) ),
39 maFtCondition( this, ScResId( FT_CONDITION ) ),
40 mnIndex(0),
41 maStrCondition(ScResId( STR_CONDITION ).toString()),
42 maLbType( this, ScResId( LB_TYPE ) ),
43 mpDoc(pDoc),
44 maPos(rPos)
46 SetControlBackground(GetSettings().GetStyleSettings().GetDialogColor());
48 maLbType.SetSelectHdl( LINK( pParent, ScCondFormatList, TypeListHdl ) );
49 maClickHdl = LINK( pParent, ScCondFormatList, EntrySelectHdl );
52 ScCondFrmtEntry::~ScCondFrmtEntry()
56 long ScCondFrmtEntry::Notify( NotifyEvent& rNEvt )
58 if( rNEvt.GetType() == EVENT_MOUSEBUTTONDOWN )
60 ImplCallEventListenersAndHandler( VCLEVENT_WINDOW_MOUSEBUTTONDOWN, maClickHdl, this );
62 return Control::Notify(rNEvt);
65 void ScCondFrmtEntry::SetIndex(sal_Int32 nIndex)
67 mnIndex = nIndex;
68 OUStringBuffer aBuffer(maStrCondition);
69 aBuffer.append(OUString::number(nIndex));
70 maFtCondNr.SetText(aBuffer.makeStringAndClear());
73 void ScCondFrmtEntry::SetHeight()
75 long nPad = LogicToPixel(Size(42,2), MapMode(MAP_APPFONT)).getHeight();
77 // Calculate maximum height we need from visible widgets
78 sal_uInt16 nChildren = GetChildCount();
80 long nMaxHeight = 0;
81 for(sal_uInt16 i = 0; i < nChildren; i++)
83 Window *pChild = GetChild(i);
84 if(!pChild || !pChild->IsVisible())
85 continue;
86 Point aPos = pChild->GetPosPixel();
87 Size aSize = pChild->GetSizePixel();
88 nMaxHeight = std::max(aPos.Y() + aSize.Height(), nMaxHeight);
90 Size aSize = GetSizePixel();
91 if(nMaxHeight > 0)
93 aSize.Height() = nMaxHeight + nPad;
94 SetSizePixel(aSize);
98 void ScCondFrmtEntry::Select()
100 maFtCondition.SetText(OUString());
101 maFtCondition.Hide();
102 maLbType.Show();
103 mbActive = true;
104 SetHeight();
107 void ScCondFrmtEntry::Deselect()
109 OUString maCondText = GetExpressionString();
110 maFtCondition.SetText(maCondText);
111 maFtCondition.Show();
112 maLbType.Hide();
113 mbActive = false;
114 SetHeight();
117 bool ScCondFrmtEntry::IsSelected() const
119 return mbActive;
122 IMPL_LINK(ScCondFrmtEntry, EdModifyHdl, Edit*, pEdit)
124 OUString aFormula = pEdit->GetText();
125 ScCompiler aComp( mpDoc, maPos );
126 aComp.SetGrammar( mpDoc->GetGrammar() );
127 boost::scoped_ptr<ScTokenArray> mpCode(aComp.CompileString(aFormula));
128 if(mpCode->GetCodeError())
130 pEdit->SetControlBackground(COL_LIGHTRED);
132 else
134 pEdit->SetControlBackground(GetSettings().GetStyleSettings().GetWindowColor());
136 return 0;
140 //condition
142 namespace {
144 void FillStyleListBox( ScDocument* pDoc, ListBox& rLbStyle )
146 rLbStyle.SetSeparatorPos(0);
147 std::set<OUString> aStyleNames;
148 SfxStyleSheetIterator aStyleIter( pDoc->GetStyleSheetPool(), SFX_STYLE_FAMILY_PARA );
149 for ( SfxStyleSheetBase* pStyle = aStyleIter.First(); pStyle; pStyle = aStyleIter.Next() )
151 OUString aName = pStyle->GetName();
152 aStyleNames.insert(aName);
154 for(std::set<OUString>::const_iterator itr = aStyleNames.begin(), itrEnd = aStyleNames.end();
155 itr != itrEnd; ++itr)
157 rLbStyle.InsertEntry( *itr );
163 ScConditionFrmtEntry::ScConditionFrmtEntry( Window* pParent, ScDocument* pDoc, const ScAddress& rPos, const ScCondFormatEntry* pFormatEntry ):
164 ScCondFrmtEntry( pParent, pDoc, rPos ),
165 maLbCondType( this, ScResId( LB_CELLIS_TYPE ) ),
166 maEdVal1( this, NULL, NULL, ScResId( ED_VAL1 ) ),
167 maEdVal2( this, NULL, NULL, ScResId( ED_VAL2 ) ),
168 maFtStyle( this, ScResId( FT_STYLE ) ),
169 maLbStyle( this, ScResId( LB_STYLE ) ),
170 maWdPreview( this, ScResId( WD_PREVIEW ) ),
171 mbIsInStyleCreate(false)
174 FreeResource();
175 maLbType.SelectEntryPos(1);
177 Init();
179 StartListening(*pDoc->GetStyleSheetPool(), true);
181 if(pFormatEntry)
183 OUString aStyleName = pFormatEntry->GetStyle();
184 maLbStyle.SelectEntry(aStyleName);
185 StyleSelectHdl(NULL);
186 ScConditionMode eMode = pFormatEntry->GetOperation();
187 maEdVal1.SetText(pFormatEntry->GetExpression(maPos, 0));
188 maEdVal2.Hide();
189 switch(eMode)
191 case SC_COND_EQUAL:
192 maLbCondType.SelectEntryPos(0);
193 break;
194 case SC_COND_LESS:
195 maLbCondType.SelectEntryPos(1);
196 break;
197 case SC_COND_GREATER:
198 maLbCondType.SelectEntryPos(2);
199 break;
200 case SC_COND_EQLESS:
201 maLbCondType.SelectEntryPos(3);
202 break;
203 case SC_COND_EQGREATER:
204 maLbCondType.SelectEntryPos(4);
205 break;
206 case SC_COND_NOTEQUAL:
207 maLbCondType.SelectEntryPos(5);
208 break;
209 case SC_COND_BETWEEN:
210 maEdVal2.Show();
211 maEdVal2.SetText(pFormatEntry->GetExpression(maPos, 1));
212 maLbCondType.SelectEntryPos(6);
213 break;
214 case SC_COND_NOTBETWEEN:
215 maEdVal2.Show();
216 maEdVal2.SetText(pFormatEntry->GetExpression(maPos, 1));
217 maLbCondType.SelectEntryPos(7);
218 break;
219 case SC_COND_DUPLICATE:
220 maLbCondType.SelectEntryPos(8);
221 break;
222 case SC_COND_NOTDUPLICATE:
223 maLbCondType.SelectEntryPos(9);
224 break;
225 case SC_COND_DIRECT:
226 assert(false);
227 //maLbType.SelectEntryPos(2);
228 break;
229 case SC_COND_TOP10:
230 maLbCondType.SelectEntryPos(10);
231 break;
232 case SC_COND_BOTTOM10:
233 maLbCondType.SelectEntryPos(11);
234 break;
235 case SC_COND_TOP_PERCENT:
236 maLbCondType.SelectEntryPos(12);
237 break;
238 case SC_COND_BOTTOM_PERCENT:
239 maLbCondType.SelectEntryPos(13);
240 break;
241 case SC_COND_ABOVE_AVERAGE:
242 maEdVal1.Hide();
243 maLbCondType.SelectEntryPos(14);
244 break;
245 case SC_COND_BELOW_AVERAGE:
246 maEdVal1.Hide();
247 maLbCondType.SelectEntryPos(15);
248 break;
249 case SC_COND_ABOVE_EQUAL_AVERAGE:
250 maEdVal1.Hide();
251 maLbCondType.SelectEntryPos(16);
252 break;
253 case SC_COND_BELOW_EQUAL_AVERAGE:
254 maEdVal1.Hide();
255 maLbCondType.SelectEntryPos(17);
256 break;
257 case SC_COND_ERROR:
258 maEdVal1.Hide();
259 maLbCondType.SelectEntryPos(18);
260 break;
261 case SC_COND_NOERROR:
262 maEdVal1.Hide();
263 maLbCondType.SelectEntryPos(19);
264 break;
265 case SC_COND_BEGINS_WITH:
266 maLbCondType.SelectEntryPos(20);
267 break;
268 case SC_COND_ENDS_WITH:
269 maLbCondType.SelectEntryPos(21);
270 break;
271 case SC_COND_CONTAINS_TEXT:
272 maLbCondType.SelectEntryPos(22);
273 break;
274 case SC_COND_NOT_CONTAINS_TEXT:
275 maLbCondType.SelectEntryPos(23);
276 break;
277 case SC_COND_NONE:
278 break;
281 else
283 maLbCondType.SelectEntryPos(0);
284 maEdVal2.Hide();
285 maLbStyle.SelectEntryPos(1);
287 maLbType.SelectEntryPos(1);
290 void ScConditionFrmtEntry::Init()
292 maEdVal1.SetGetFocusHdl( LINK( GetParent()->GetParent(), ScCondFormatDlg, RangeGetFocusHdl ) );
293 maEdVal2.SetGetFocusHdl( LINK( GetParent()->GetParent(), ScCondFormatDlg, RangeGetFocusHdl ) );
294 maEdVal1.SetLoseFocusHdl( LINK( GetParent()->GetParent(), ScCondFormatDlg, RangeLoseFocusHdl ) );
295 maEdVal2.SetLoseFocusHdl( LINK( GetParent()->GetParent(), ScCondFormatDlg, RangeLoseFocusHdl ) );
297 maEdVal1.SetStyle( maEdVal1.GetStyle() | WB_FORCECTRLBACKGROUND );
298 maEdVal2.SetStyle( maEdVal2.GetStyle() | WB_FORCECTRLBACKGROUND );
300 maEdVal1.SetModifyHdl( LINK( this, ScCondFrmtEntry, EdModifyHdl ) );
301 maEdVal2.SetModifyHdl( LINK( this, ScCondFrmtEntry, EdModifyHdl ) );
303 FillStyleListBox( mpDoc, maLbStyle );
304 maLbStyle.SetSelectHdl( LINK( this, ScConditionFrmtEntry, StyleSelectHdl ) );
306 maLbCondType.SetSelectHdl( LINK( this, ScConditionFrmtEntry, ConditionTypeSelectHdl ) );
309 ScFormatEntry* ScConditionFrmtEntry::createConditionEntry() const
311 ScConditionMode eMode;
312 OUString aExpr2;
313 switch(maLbCondType.GetSelectEntryPos())
315 case 0:
316 eMode = SC_COND_EQUAL;
317 break;
318 case 1:
319 eMode = SC_COND_LESS;
320 break;
321 case 2:
322 eMode = SC_COND_GREATER;
323 break;
324 case 3:
325 eMode = SC_COND_EQLESS;
326 break;
327 case 4:
328 eMode = SC_COND_EQGREATER;
329 break;
330 case 5:
331 eMode = SC_COND_NOTEQUAL;
332 break;
333 case 6:
334 aExpr2 = maEdVal2.GetText();
335 eMode = SC_COND_BETWEEN;
336 if(aExpr2.isEmpty())
337 return NULL;
338 break;
339 case 7:
340 eMode = SC_COND_NOTBETWEEN;
341 aExpr2 = maEdVal2.GetText();
342 if(aExpr2.isEmpty())
343 return NULL;
344 break;
345 case 8:
346 eMode = SC_COND_DUPLICATE;
347 break;
348 case 9:
349 eMode = SC_COND_NOTDUPLICATE;
350 break;
351 case 10:
352 eMode = SC_COND_TOP10;
353 break;
354 case 11:
355 eMode = SC_COND_BOTTOM10;
356 break;
357 case 12:
358 eMode = SC_COND_TOP_PERCENT;
359 break;
360 case 13:
361 eMode = SC_COND_BOTTOM_PERCENT;
362 break;
363 case 14:
364 eMode = SC_COND_ABOVE_AVERAGE;
365 break;
366 case 15:
367 eMode = SC_COND_BELOW_AVERAGE;
368 break;
369 case 16:
370 eMode = SC_COND_ABOVE_EQUAL_AVERAGE;
371 break;
372 case 17:
373 eMode = SC_COND_BELOW_EQUAL_AVERAGE;
374 break;
375 case 18:
376 eMode = SC_COND_ERROR;
377 break;
378 case 19:
379 eMode = SC_COND_NOERROR;
380 break;
381 case 20:
382 eMode = SC_COND_BEGINS_WITH;
383 break;
384 case 21:
385 eMode = SC_COND_ENDS_WITH;
386 break;
387 case 22:
388 eMode = SC_COND_CONTAINS_TEXT;
389 break;
390 case 23:
391 eMode = SC_COND_NOT_CONTAINS_TEXT;
392 break;
393 default:
394 assert(false); // this cannot happen
395 return NULL;
398 OUString aExpr1 = maEdVal1.GetText();
400 ScFormatEntry* pEntry = new ScCondFormatEntry(eMode, aExpr1, aExpr2, mpDoc, maPos, maLbStyle.GetSelectEntry());
402 return pEntry;
405 OUString ScConditionFrmtEntry::GetExpressionString()
407 return ScCondFormatHelper::GetExpression(CONDITION, maLbCondType.GetSelectEntryPos(), maEdVal1.GetText(), maEdVal2.GetText());
410 ScFormatEntry* ScConditionFrmtEntry::GetEntry() const
412 return createConditionEntry();
415 void ScConditionFrmtEntry::SetActive()
417 maLbCondType.Show();
418 maEdVal1.Show();
419 if(maLbCondType.GetSelectEntryPos() == 6 || maLbCondType.GetSelectEntryPos() == 7)
420 maEdVal2.Show();
421 maFtStyle.Show();
422 maLbStyle.Show();
423 maWdPreview.Show();
425 Select();
428 void ScConditionFrmtEntry::SetInactive()
430 maLbCondType.Hide();
431 maEdVal1.Hide();
432 maEdVal2.Hide();
433 maFtStyle.Hide();
434 maLbStyle.Hide();
435 maWdPreview.Hide();
437 Deselect();
440 namespace {
442 void UpdateStyleList(ListBox& rLbStyle, ScDocument* pDoc)
444 OUString aSelectedStyle = rLbStyle.GetSelectEntry();
445 for(sal_Int32 i = rLbStyle.GetEntryCount(); i >= 1; --i)
447 rLbStyle.RemoveEntry(i);
449 FillStyleListBox(pDoc, rLbStyle);
450 rLbStyle.SelectEntry(aSelectedStyle);
455 void ScConditionFrmtEntry::Notify(SfxBroadcaster&, const SfxHint& rHint)
457 SfxStyleSheetHint* pHint = PTR_CAST(SfxStyleSheetHint, &rHint);
458 if(!pHint)
459 return;
461 sal_uInt16 nHint = pHint->GetHint();
462 if(nHint == SFX_STYLESHEET_MODIFIED)
464 if(!mbIsInStyleCreate)
465 UpdateStyleList(maLbStyle, mpDoc);
469 namespace {
471 void StyleSelect( ListBox& rLbStyle, ScDocument* pDoc, SvxFontPrevWindow& rWdPreview )
473 if(rLbStyle.GetSelectEntryPos() == 0)
475 // call new style dialog
476 SfxUInt16Item aFamilyItem( SID_STYLE_FAMILY, SFX_STYLE_FAMILY_PARA );
477 SfxStringItem aRefItem( SID_STYLE_REFERENCE, ScGlobal::GetRscString(STR_STYLENAME_STANDARD) );
479 // unlock the dispatcher so SID_STYLE_NEW can be executed
480 // (SetDispatcherLock would affect all Calc documents)
481 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
482 SfxDispatcher* pDisp = pViewShell->GetDispatcher();
483 sal_Bool bLocked = pDisp->IsLocked();
484 if (bLocked)
485 pDisp->Lock(false);
487 // Execute the "new style" slot, complete with undo and all necessary updates.
488 // The return value (SfxUInt16Item) is ignored, look for new styles instead.
489 pDisp->Execute( SID_STYLE_NEW, SFX_CALLMODE_SYNCHRON | SFX_CALLMODE_RECORD | SFX_CALLMODE_MODAL,
490 &aFamilyItem,
491 &aRefItem,
492 0L );
494 if (bLocked)
495 pDisp->Lock(sal_True);
497 // Find the new style and add it into the style list boxes
498 SfxStyleSheetIterator aStyleIter( pDoc->GetStyleSheetPool(), SFX_STYLE_FAMILY_PARA );
499 bool bFound = false;
500 for ( SfxStyleSheetBase* pStyle = aStyleIter.First(); pStyle && !bFound; pStyle = aStyleIter.Next() )
502 OUString aName = pStyle->GetName();
503 if ( rLbStyle.GetEntryPos(aName) == LISTBOX_ENTRY_NOTFOUND ) // all lists contain the same entries
505 for( sal_uInt16 i = 1, n = rLbStyle.GetEntryCount(); i <= n && !bFound; ++i)
507 OUString aStyleName = ScGlobal::pCharClass->uppercase(OUString(rLbStyle.GetEntry(i)));
508 if( i == n )
510 rLbStyle.InsertEntry(aName);
511 rLbStyle.SelectEntry(aName);
512 bFound = true;
514 else if( aStyleName > ScGlobal::pCharClass->uppercase(aName) )
516 rLbStyle.InsertEntry(aName, i);
517 rLbStyle.SelectEntry(aName);
518 bFound = true;
525 OUString aStyleName = rLbStyle.GetSelectEntry();
526 SfxStyleSheetBase* pStyleSheet = pDoc->GetStyleSheetPool()->Find( aStyleName, SFX_STYLE_FAMILY_PARA );
527 if(pStyleSheet)
529 const SfxItemSet& rSet = pStyleSheet->GetItemSet();
530 rWdPreview.Init( rSet );
536 IMPL_LINK_NOARG(ScConditionFrmtEntry, StyleSelectHdl)
538 mbIsInStyleCreate = true;
539 StyleSelect( maLbStyle, mpDoc, maWdPreview );
540 mbIsInStyleCreate = false;
541 return 0;
544 // formula
546 ScFormulaFrmtEntry::ScFormulaFrmtEntry( Window* pParent, ScDocument* pDoc, const ScAddress& rPos, const ScCondFormatEntry* pFormat ):
547 ScCondFrmtEntry( pParent, pDoc, rPos ),
548 maFtStyle( this, ScResId( FT_STYLE ) ),
549 maLbStyle( this, ScResId( LB_STYLE ) ),
550 maWdPreview( this, ScResId( WD_PREVIEW ) ),
551 maEdFormula( this, NULL, NULL, ScResId( ED_FORMULA ) )
553 Init();
555 FreeResource();
556 maLbType.SelectEntryPos(2);
558 if(pFormat)
560 maEdFormula.SetText(pFormat->GetExpression(rPos, 0, 0, pDoc->GetGrammar()));
561 maLbStyle.SelectEntry(pFormat->GetStyle());
563 else
565 maLbStyle.SelectEntryPos(1);
568 StyleSelectHdl(NULL);
571 void ScFormulaFrmtEntry::Init()
573 maEdFormula.SetGetFocusHdl( LINK( GetParent()->GetParent(), ScCondFormatDlg, RangeGetFocusHdl ) );
574 maEdFormula.SetLoseFocusHdl( LINK( GetParent()->GetParent(), ScCondFormatDlg, RangeLoseFocusHdl ) );
576 FillStyleListBox( mpDoc, maLbStyle );
577 maLbStyle.SetSelectHdl( LINK( this, ScFormulaFrmtEntry, StyleSelectHdl ) );
580 IMPL_LINK_NOARG(ScFormulaFrmtEntry, StyleSelectHdl)
582 StyleSelect( maLbStyle, mpDoc, maWdPreview );
584 return 0;
587 ScFormatEntry* ScFormulaFrmtEntry::createFormulaEntry() const
589 ScConditionMode eMode = SC_COND_DIRECT;
590 OUString aFormula = maEdFormula.GetText();
591 if(aFormula.isEmpty())
592 return NULL;
594 OUString aExpr2;
595 ScFormatEntry* pEntry = new ScCondFormatEntry(eMode, aFormula, aExpr2, mpDoc, maPos, maLbStyle.GetSelectEntry());
596 return pEntry;
599 ScFormatEntry* ScFormulaFrmtEntry::GetEntry() const
601 return createFormulaEntry();
604 OUString ScFormulaFrmtEntry::GetExpressionString()
606 return ScCondFormatHelper::GetExpression(FORMULA, 0, maEdFormula.GetText());
609 void ScFormulaFrmtEntry::SetActive()
611 maWdPreview.Show();
612 maFtStyle.Show();
613 maLbStyle.Show();
614 maEdFormula.Show();
616 Select();
619 void ScFormulaFrmtEntry::SetInactive()
621 maWdPreview.Hide();
622 maFtStyle.Hide();
623 maLbStyle.Hide();
624 maEdFormula.Hide();
626 Deselect();
629 //color scale
631 namespace {
633 OUString convertNumberToString(double nVal, ScDocument* pDoc)
635 SvNumberFormatter* pNumberFormatter = pDoc->GetFormatTable();
636 OUString aText;
637 pNumberFormatter->GetInputLineString(nVal, 0, aText);
638 return aText;
641 void SetColorScaleEntryTypes( const ScColorScaleEntry& rEntry, ListBox& rLbType, Edit& rEdit, ColorListBox& rLbCol, ScDocument* pDoc )
643 // entry Automatic is not available for color scales
644 sal_Int32 nIndex = static_cast<sal_Int32>(rEntry.GetType());
645 assert(nIndex > 0);
646 rLbType.SelectEntryPos(nIndex - 1);
647 switch(rEntry.GetType())
649 case COLORSCALE_MIN:
650 case COLORSCALE_MAX:
651 break;
652 case COLORSCALE_PERCENTILE:
653 case COLORSCALE_VALUE:
654 case COLORSCALE_PERCENT:
656 double nVal = rEntry.GetValue();
657 rEdit.SetText(convertNumberToString(nVal, pDoc));
659 break;
660 case COLORSCALE_FORMULA:
661 rEdit.SetText(rEntry.GetFormula(formula::FormulaGrammar::GRAM_DEFAULT));
662 break;
663 case COLORSCALE_AUTO:
664 abort();
665 break;
667 rLbCol.SelectEntry(rEntry.GetColor());
670 void SetColorScaleEntry( ScColorScaleEntry* pEntry, const ListBox& rType, const Edit& rValue, ScDocument* pDoc, const ScAddress& rPos, bool bDataBar )
672 sal_uInt32 nIndex = 0;
673 double nVal = 0;
674 SvNumberFormatter* pNumberFormatter = pDoc->GetFormatTable();
675 pNumberFormatter->IsNumberFormat(rValue.GetText(), nIndex, nVal);
677 // color scale does not have the automatic entry
678 sal_Int32 nPos = rType.GetSelectEntryPos();
679 if(!bDataBar)
680 ++nPos;
682 pEntry->SetType(static_cast<ScColorScaleEntryType>(nPos));
683 switch(nPos)
685 case COLORSCALE_AUTO:
686 case COLORSCALE_MIN:
687 case COLORSCALE_MAX:
688 break;
689 case COLORSCALE_PERCENTILE:
690 case COLORSCALE_VALUE:
691 case COLORSCALE_PERCENT:
692 pEntry->SetValue(nVal);
693 break;
694 case COLORSCALE_FORMULA:
695 pEntry->SetFormula(rValue.GetText(), pDoc, rPos);
696 break;
697 default:
698 break;
702 ScColorScaleEntry* createColorScaleEntry( const ListBox& rType, const ColorListBox& rColor, const Edit& rValue, ScDocument* pDoc, const ScAddress& rPos )
704 ScColorScaleEntry* pEntry = new ScColorScaleEntry();
706 SetColorScaleEntry( pEntry, rType, rValue, pDoc, rPos, false );
707 Color aColor = rColor.GetSelectEntryColor();
708 pEntry->SetColor(aColor);
709 return pEntry;
714 ScColorScale2FrmtEntry::ScColorScale2FrmtEntry( Window* pParent, ScDocument* pDoc, const ScAddress& rPos, const ScColorScaleFormat* pFormat ):
715 ScCondFrmtEntry( pParent, pDoc, rPos ),
716 maLbColorFormat( this, ScResId( LB_COLOR_FORMAT ) ),
717 maLbEntryTypeMin( this, ScResId( LB_TYPE_COL_SCALE_MIN ) ),
718 maLbEntryTypeMax( this, ScResId( LB_TYPE_COL_SCALE_MAX ) ),
719 maEdMin( this, ScResId( ED_COL_SCALE_MIN ) ),
720 maEdMax( this, ScResId( ED_COL_SCALE_MAX ) ),
721 maLbColMin( this, ScResId( LB_COL_MIN ) ),
722 maLbColMax( this, ScResId( LB_COL_MAX ) )
724 // remove the automatic entry from color scales
725 maLbEntryTypeMin.RemoveEntry(0);
726 maLbEntryTypeMax.RemoveEntry(0);
728 maLbType.SelectEntryPos(0);
729 maLbColorFormat.SelectEntryPos(0);
730 Init();
731 if(pFormat)
733 ScColorScaleFormat::const_iterator itr = pFormat->begin();
734 SetColorScaleEntryTypes(*itr, maLbEntryTypeMin, maEdMin, maLbColMin, pDoc);
735 ++itr;
736 SetColorScaleEntryTypes(*itr, maLbEntryTypeMax, maEdMax, maLbColMax, pDoc);
738 else
740 maLbEntryTypeMin.SelectEntryPos(0);
741 maLbEntryTypeMax.SelectEntryPos(1);
743 FreeResource();
745 maLbColorFormat.SetSelectHdl( LINK( pParent, ScCondFormatList, ColFormatTypeHdl ) );
747 EntryTypeHdl(&maLbEntryTypeMin);
748 EntryTypeHdl(&maLbEntryTypeMax);
751 void ScColorScale2FrmtEntry::Init()
753 maLbEntryTypeMin.SetSelectHdl( LINK( this, ScColorScale2FrmtEntry, EntryTypeHdl ) );
754 maLbEntryTypeMax.SetSelectHdl( LINK( this, ScColorScale2FrmtEntry, EntryTypeHdl ) );
756 SfxObjectShell* pDocSh = SfxObjectShell::Current();
757 XColorListRef pColorTable;
759 DBG_ASSERT( pDocSh, "DocShell not found!" );
761 if ( pDocSh )
763 const SfxPoolItem* pItem = pDocSh->GetItem( SID_COLOR_TABLE );
764 if ( pItem != NULL )
765 pColorTable = ( (SvxColorListItem*)pItem )->GetColorList();
767 if ( pColorTable.is() )
769 // filling the line color box
770 maLbColMin.SetUpdateMode( false );
771 maLbColMax.SetUpdateMode( false );
773 for ( long i = 0; i < pColorTable->Count(); ++i )
775 XColorEntry* pEntry = pColorTable->GetColor(i);
776 maLbColMin.InsertEntry( pEntry->GetColor(), pEntry->GetName() );
777 maLbColMax.InsertEntry( pEntry->GetColor(), pEntry->GetName() );
779 if(pEntry->GetColor() == Color(COL_LIGHTRED))
780 maLbColMin.SelectEntryPos(i);
781 if(pEntry->GetColor() == Color(COL_LIGHTBLUE))
782 maLbColMax.SelectEntryPos(i);
784 maLbColMin.SetUpdateMode( sal_True );
785 maLbColMax.SetUpdateMode( sal_True );
789 ScFormatEntry* ScColorScale2FrmtEntry::createColorscaleEntry() const
791 ScColorScaleFormat* pColorScale = new ScColorScaleFormat(mpDoc);
792 pColorScale->AddEntry(createColorScaleEntry(maLbEntryTypeMin, maLbColMin, maEdMin, mpDoc, maPos));
793 pColorScale->AddEntry(createColorScaleEntry(maLbEntryTypeMax, maLbColMax, maEdMax, mpDoc, maPos));
794 return pColorScale;
797 OUString ScColorScale2FrmtEntry::GetExpressionString()
799 return ScCondFormatHelper::GetExpression( COLORSCALE, 0 );
802 ScFormatEntry* ScColorScale2FrmtEntry::GetEntry() const
804 return createColorscaleEntry();
807 void ScColorScale2FrmtEntry::SetActive()
809 maLbColorFormat.Show();
811 maLbEntryTypeMin.Show();
812 maLbEntryTypeMax.Show();
814 maEdMin.Show();
815 maEdMax.Show();
817 maLbColMin.Show();
818 maLbColMax.Show();
820 Select();
823 void ScColorScale2FrmtEntry::SetInactive()
825 maLbColorFormat.Hide();
827 maLbEntryTypeMin.Hide();
828 maLbEntryTypeMax.Hide();
830 maEdMin.Hide();
831 maEdMax.Hide();
833 maLbColMin.Hide();
834 maLbColMax.Hide();
836 Deselect();
839 IMPL_LINK( ScColorScale2FrmtEntry, EntryTypeHdl, ListBox*, pBox )
841 bool bEnableEdit = true;
842 sal_Int32 nPos = pBox->GetSelectEntryPos();
843 if(nPos < 2)
845 bEnableEdit = false;
848 Edit* pEd = NULL;
849 if(pBox == &maLbEntryTypeMin)
850 pEd = &maEdMin;
851 else if(pBox == &maLbEntryTypeMax)
852 pEd = &maEdMax;
854 if(bEnableEdit)
855 pEd->Enable();
856 else
857 pEd->Disable();
859 return 0;
862 ScColorScale3FrmtEntry::ScColorScale3FrmtEntry( Window* pParent, ScDocument* pDoc, const ScAddress& rPos, const ScColorScaleFormat* pFormat ):
863 ScCondFrmtEntry( pParent, pDoc, rPos ),
864 maLbColorFormat( this, ScResId( LB_COLOR_FORMAT ) ),
865 maLbEntryTypeMin( this, ScResId( LB_TYPE_COL_SCALE_MIN ) ),
866 maLbEntryTypeMiddle( this, ScResId( LB_TYPE_COL_SCALE_MIDDLE ) ),
867 maLbEntryTypeMax( this, ScResId( LB_TYPE_COL_SCALE_MAX ) ),
868 maEdMin( this, ScResId( ED_COL_SCALE_MIN ) ),
869 maEdMiddle( this, ScResId( ED_COL_SCALE_MIDDLE ) ),
870 maEdMax( this, ScResId( ED_COL_SCALE_MAX ) ),
871 maLbColMin( this, ScResId( LB_COL_MIN ) ),
872 maLbColMiddle( this, ScResId( LB_COL_MIDDLE ) ),
873 maLbColMax( this, ScResId( LB_COL_MAX ) )
875 // remove the automatic entry from color scales
876 maLbEntryTypeMin.RemoveEntry(0);
877 maLbEntryTypeMiddle.RemoveEntry(0);
878 maLbEntryTypeMax.RemoveEntry(0);
879 maLbColorFormat.SelectEntryPos(1);
881 Init();
882 maLbType.SelectEntryPos(0);
883 if(pFormat)
885 ScColorScaleFormat::const_iterator itr = pFormat->begin();
886 SetColorScaleEntryTypes(*itr, maLbEntryTypeMin, maEdMin, maLbColMin, pDoc);
887 assert(pFormat->size() == 3);
888 ++itr;
889 SetColorScaleEntryTypes(*itr, maLbEntryTypeMiddle, maEdMiddle, maLbColMiddle, pDoc);
890 ++itr;
891 SetColorScaleEntryTypes(*itr, maLbEntryTypeMax, maEdMax, maLbColMax, pDoc);
893 else
895 maLbColorFormat.SelectEntryPos(1);
896 maLbEntryTypeMin.SelectEntryPos(0);
897 maLbEntryTypeMiddle.SelectEntryPos(2);
898 maLbEntryTypeMax.SelectEntryPos(1);
899 maEdMiddle.SetText(OUString::number(50));
901 FreeResource();
903 maLbColorFormat.SetSelectHdl( LINK( pParent, ScCondFormatList, ColFormatTypeHdl ) );
904 EntryTypeHdl(&maLbEntryTypeMin);
905 EntryTypeHdl(&maLbEntryTypeMiddle);
906 EntryTypeHdl(&maLbEntryTypeMax);
909 void ScColorScale3FrmtEntry::Init()
911 maLbEntryTypeMin.SetSelectHdl( LINK( this, ScColorScale3FrmtEntry, EntryTypeHdl ) );
912 maLbEntryTypeMax.SetSelectHdl( LINK( this, ScColorScale3FrmtEntry, EntryTypeHdl ) );
913 maLbEntryTypeMiddle.SetSelectHdl( LINK( this, ScColorScale3FrmtEntry, EntryTypeHdl ) );
915 SfxObjectShell* pDocSh = SfxObjectShell::Current();
916 XColorListRef pColorTable;
918 DBG_ASSERT( pDocSh, "DocShell not found!" );
920 if ( pDocSh )
922 const SfxPoolItem* pItem = pDocSh->GetItem( SID_COLOR_TABLE );
923 if ( pItem != NULL )
924 pColorTable = ( (SvxColorListItem*)pItem )->GetColorList();
926 if ( pColorTable.is() )
928 // filling the line color box
929 maLbColMin.SetUpdateMode( false );
930 maLbColMiddle.SetUpdateMode( false );
931 maLbColMax.SetUpdateMode( false );
933 for ( long i = 0; i < pColorTable->Count(); ++i )
935 XColorEntry* pEntry = pColorTable->GetColor(i);
936 maLbColMin.InsertEntry( pEntry->GetColor(), pEntry->GetName() );
937 maLbColMiddle.InsertEntry( pEntry->GetColor(), pEntry->GetName() );
938 maLbColMax.InsertEntry( pEntry->GetColor(), pEntry->GetName() );
940 if(pEntry->GetColor() == Color(COL_LIGHTRED))
941 maLbColMin.SelectEntryPos(i);
942 if(pEntry->GetColor() == Color(COL_GREEN))
943 maLbColMiddle.SelectEntryPos(i);
944 if(pEntry->GetColor() == Color(COL_LIGHTBLUE))
945 maLbColMax.SelectEntryPos(i);
947 maLbColMin.SetUpdateMode( sal_True );
948 maLbColMiddle.SetUpdateMode( sal_True );
949 maLbColMax.SetUpdateMode( sal_True );
953 ScFormatEntry* ScColorScale3FrmtEntry::createColorscaleEntry() const
955 ScColorScaleFormat* pColorScale = new ScColorScaleFormat(mpDoc);
956 pColorScale->AddEntry(createColorScaleEntry(maLbEntryTypeMin, maLbColMin, maEdMin, mpDoc, maPos));
957 if(maLbColorFormat.GetSelectEntryPos() == 1)
958 pColorScale->AddEntry(createColorScaleEntry(maLbEntryTypeMiddle, maLbColMiddle, maEdMiddle, mpDoc, maPos));
959 pColorScale->AddEntry(createColorScaleEntry(maLbEntryTypeMax, maLbColMax, maEdMax, mpDoc, maPos));
960 return pColorScale;
963 OUString ScColorScale3FrmtEntry::GetExpressionString()
965 return ScCondFormatHelper::GetExpression( COLORSCALE, 0 );
968 ScFormatEntry* ScColorScale3FrmtEntry::GetEntry() const
970 return createColorscaleEntry();
973 void ScColorScale3FrmtEntry::SetActive()
975 maLbColorFormat.Show();
976 maLbEntryTypeMin.Show();
977 maLbEntryTypeMiddle.Show();
978 maLbEntryTypeMax.Show();
980 maEdMin.Show();
981 maEdMiddle.Show();
982 maEdMax.Show();
984 maLbColMin.Show();
985 maLbColMiddle.Show();
986 maLbColMax.Show();
988 Select();
991 void ScColorScale3FrmtEntry::SetInactive()
993 maLbColorFormat.Hide();
995 maLbEntryTypeMin.Hide();
996 maLbEntryTypeMiddle.Hide();
997 maLbEntryTypeMax.Hide();
999 maEdMin.Hide();
1000 maEdMiddle.Hide();
1001 maEdMax.Hide();
1003 maLbColMin.Hide();
1004 maLbColMiddle.Hide();
1005 maLbColMax.Hide();
1007 Deselect();
1010 IMPL_LINK( ScColorScale3FrmtEntry, EntryTypeHdl, ListBox*, pBox )
1012 bool bEnableEdit = true;
1013 sal_Int32 nPos = pBox->GetSelectEntryPos();
1014 if(nPos < 2)
1016 bEnableEdit = false;
1019 Edit* pEd = NULL;
1020 if(pBox == &maLbEntryTypeMin)
1021 pEd = &maEdMin;
1022 else if(pBox == &maLbEntryTypeMiddle)
1023 pEd = &maEdMiddle;
1024 else if(pBox == &maLbEntryTypeMax)
1025 pEd = &maEdMax;
1027 if(bEnableEdit)
1028 pEd->Enable();
1029 else
1030 pEd->Disable();
1032 return 0;
1035 IMPL_LINK_NOARG( ScConditionFrmtEntry, ConditionTypeSelectHdl )
1037 sal_Int32 nSelectPos = maLbCondType.GetSelectEntryPos();
1038 if(nSelectPos == 6 || nSelectPos == 7)
1040 maEdVal1.Show();
1041 maEdVal2.Show();
1043 else if(nSelectPos == 8 || nSelectPos == 9)
1045 maEdVal2.Hide();
1046 maEdVal1.Hide();
1048 else if(nSelectPos <= 5 || (nSelectPos >= 10 && nSelectPos <= 13)
1049 || nSelectPos >= 18)
1051 maEdVal1.Show();
1052 maEdVal2.Hide();
1054 else
1056 maEdVal1.Hide();
1057 maEdVal2.Hide();
1060 return 0;
1063 //databar
1065 namespace {
1067 void SetDataBarEntryTypes( const ScColorScaleEntry& rEntry, ListBox& rLbType, Edit& rEdit, ScDocument* pDoc )
1069 rLbType.SelectEntryPos(rEntry.GetType());
1070 switch(rEntry.GetType())
1072 case COLORSCALE_AUTO:
1073 case COLORSCALE_MIN:
1074 case COLORSCALE_MAX:
1075 break;
1076 case COLORSCALE_VALUE:
1077 case COLORSCALE_PERCENT:
1078 case COLORSCALE_PERCENTILE:
1080 double nVal = rEntry.GetValue();
1081 SvNumberFormatter* pNumberFormatter = pDoc->GetFormatTable();
1082 OUString aText;
1083 pNumberFormatter->GetInputLineString(nVal, 0, aText);
1084 rEdit.SetText(aText);
1086 break;
1087 case COLORSCALE_FORMULA:
1088 rEdit.SetText(rEntry.GetFormula(formula::FormulaGrammar::GRAM_DEFAULT));
1089 break;
1095 ScDataBarFrmtEntry::ScDataBarFrmtEntry( Window* pParent, ScDocument* pDoc, const ScAddress& rPos, const ScDataBarFormat* pFormat ):
1096 ScCondFrmtEntry( pParent, pDoc, rPos ),
1097 maLbColorFormat( this, ScResId( LB_COLOR_FORMAT ) ),
1098 maLbDataBarMinType( this, ScResId( LB_TYPE_COL_SCALE_MIN ) ),
1099 maLbDataBarMaxType( this, ScResId( LB_TYPE_COL_SCALE_MAX ) ),
1100 maEdDataBarMin( this, ScResId( ED_COL_SCALE_MIN ) ),
1101 maEdDataBarMax( this, ScResId( ED_COL_SCALE_MAX ) ),
1102 maBtOptions( this, ScResId( BTN_OPTIONS ) )
1104 maLbColorFormat.SelectEntryPos(2);
1105 maLbType.SelectEntryPos(0);
1106 if(pFormat)
1108 mpDataBarData.reset(new ScDataBarFormatData(*pFormat->GetDataBarData()));
1109 SetDataBarEntryTypes(*mpDataBarData->mpLowerLimit, maLbDataBarMinType, maEdDataBarMin, pDoc);
1110 SetDataBarEntryTypes(*mpDataBarData->mpUpperLimit, maLbDataBarMaxType, maEdDataBarMax, pDoc);
1111 DataBarTypeSelectHdl(NULL);
1113 else
1115 maLbDataBarMinType.SelectEntryPos(0);
1116 maLbDataBarMaxType.SelectEntryPos(0);
1117 DataBarTypeSelectHdl(NULL);
1119 Init();
1121 maLbColorFormat.SetSelectHdl( LINK( pParent, ScCondFormatList, ColFormatTypeHdl ) );
1123 FreeResource();
1126 ScFormatEntry* ScDataBarFrmtEntry::GetEntry() const
1128 return createDatabarEntry();
1131 void ScDataBarFrmtEntry::Init()
1133 maLbDataBarMinType.SetSelectHdl( LINK( this, ScDataBarFrmtEntry, DataBarTypeSelectHdl ) );
1134 maLbDataBarMaxType.SetSelectHdl( LINK( this, ScDataBarFrmtEntry, DataBarTypeSelectHdl ) );
1136 maBtOptions.SetClickHdl( LINK( this, ScDataBarFrmtEntry, OptionBtnHdl ) );
1138 if(!mpDataBarData)
1140 mpDataBarData.reset(new ScDataBarFormatData());
1141 mpDataBarData->mpUpperLimit.reset(new ScColorScaleEntry());
1142 mpDataBarData->mpLowerLimit.reset(new ScColorScaleEntry());
1143 mpDataBarData->mpLowerLimit->SetType(COLORSCALE_AUTO);
1144 mpDataBarData->mpUpperLimit->SetType(COLORSCALE_AUTO);
1145 mpDataBarData->maPositiveColor = COL_LIGHTBLUE;
1149 ScFormatEntry* ScDataBarFrmtEntry::createDatabarEntry() const
1151 SetColorScaleEntry(mpDataBarData->mpLowerLimit.get(), maLbDataBarMinType, maEdDataBarMin, mpDoc, maPos, true);
1152 SetColorScaleEntry(mpDataBarData->mpUpperLimit.get(), maLbDataBarMaxType, maEdDataBarMax, mpDoc, maPos, true);
1153 ScDataBarFormat* pDataBar = new ScDataBarFormat(mpDoc);
1154 pDataBar->SetDataBarData(new ScDataBarFormatData(*mpDataBarData.get()));
1155 return pDataBar;
1158 OUString ScDataBarFrmtEntry::GetExpressionString()
1160 return ScCondFormatHelper::GetExpression( DATABAR, 0 );
1163 void ScDataBarFrmtEntry::SetActive()
1165 maLbColorFormat.Show();
1167 maLbDataBarMinType.Show();
1168 maLbDataBarMaxType.Show();
1169 maEdDataBarMin.Show();
1170 maEdDataBarMax.Show();
1171 maBtOptions.Show();
1173 Select();
1176 void ScDataBarFrmtEntry::SetInactive()
1178 maLbColorFormat.Hide();
1180 maLbDataBarMinType.Hide();
1181 maLbDataBarMaxType.Hide();
1182 maEdDataBarMin.Hide();
1183 maEdDataBarMax.Hide();
1184 maBtOptions.Hide();
1186 Deselect();
1189 IMPL_LINK_NOARG( ScDataBarFrmtEntry, DataBarTypeSelectHdl )
1191 sal_Int32 nSelectPos = maLbDataBarMinType.GetSelectEntryPos();
1192 if(nSelectPos <= COLORSCALE_MAX)
1193 maEdDataBarMin.Disable();
1194 else
1195 maEdDataBarMin.Enable();
1197 nSelectPos = maLbDataBarMaxType.GetSelectEntryPos();
1198 if(nSelectPos <= COLORSCALE_MAX)
1199 maEdDataBarMax.Disable();
1200 else
1201 maEdDataBarMax.Enable();
1203 return 0;
1206 IMPL_LINK_NOARG( ScDataBarFrmtEntry, OptionBtnHdl )
1208 SetColorScaleEntry(mpDataBarData->mpLowerLimit.get(), maLbDataBarMinType, maEdDataBarMin, mpDoc, maPos, true);
1209 SetColorScaleEntry(mpDataBarData->mpUpperLimit.get(), maLbDataBarMaxType, maEdDataBarMax, mpDoc, maPos, true);
1210 ScDataBarSettingsDlg* pDlg = new ScDataBarSettingsDlg(this, *mpDataBarData, mpDoc, maPos);
1211 if( pDlg->Execute() == RET_OK)
1213 mpDataBarData.reset(pDlg->GetData());
1214 SetDataBarEntryTypes(*mpDataBarData->mpLowerLimit, maLbDataBarMinType, maEdDataBarMin, mpDoc);
1215 SetDataBarEntryTypes(*mpDataBarData->mpUpperLimit, maLbDataBarMaxType, maEdDataBarMax, mpDoc);
1216 DataBarTypeSelectHdl(NULL);
1218 return 0;
1221 ScDateFrmtEntry::ScDateFrmtEntry( Window* pParent, ScDocument* pDoc, const ScCondDateFormatEntry* pFormat ):
1222 ScCondFrmtEntry( pParent, pDoc, ScAddress() ),
1223 maLbDateEntry( this, ScResId( LB_DATE_TYPE ) ),
1224 maFtStyle( this, ScResId( FT_STYLE ) ),
1225 maLbStyle( this, ScResId( LB_STYLE ) ),
1226 maWdPreview( this, ScResId( WD_PREVIEW ) ),
1227 mbIsInStyleCreate(false)
1229 Init();
1230 FreeResource();
1232 StartListening(*pDoc->GetStyleSheetPool(), sal_True);
1234 if(pFormat)
1236 sal_Int32 nPos = static_cast<sal_Int32>(pFormat->GetDateType());
1237 maLbDateEntry.SelectEntryPos(nPos);
1239 OUString aStyleName = pFormat->GetStyleName();
1240 maLbStyle.SelectEntry(aStyleName);
1243 StyleSelectHdl(NULL);
1246 void ScDateFrmtEntry::Init()
1248 maLbDateEntry.SelectEntryPos(0);
1249 maLbType.SelectEntryPos(3);
1251 FillStyleListBox( mpDoc, maLbStyle );
1252 maLbStyle.SetSelectHdl( LINK( this, ScDateFrmtEntry, StyleSelectHdl ) );
1253 maLbStyle.SelectEntryPos(1);
1256 void ScDateFrmtEntry::SetActive()
1258 maLbDateEntry.Show();
1259 maFtStyle.Show();
1260 maWdPreview.Show();
1261 maLbStyle.Show();
1263 Select();
1266 void ScDateFrmtEntry::SetInactive()
1268 maLbDateEntry.Hide();
1269 maFtStyle.Hide();
1270 maWdPreview.Hide();
1271 maLbStyle.Hide();
1273 Deselect();
1276 void ScDateFrmtEntry::Notify( SfxBroadcaster&, const SfxHint& rHint )
1278 SfxStyleSheetHint* pHint = PTR_CAST(SfxStyleSheetHint, &rHint);
1279 if(!pHint)
1280 return;
1282 sal_uInt16 nHint = pHint->GetHint();
1283 if(nHint == SFX_STYLESHEET_MODIFIED)
1285 if(!mbIsInStyleCreate)
1286 UpdateStyleList(maLbStyle, mpDoc);
1290 ScFormatEntry* ScDateFrmtEntry::GetEntry() const
1292 ScCondDateFormatEntry* pNewEntry = new ScCondDateFormatEntry(mpDoc);
1293 condformat::ScCondFormatDateType eType = static_cast<condformat::ScCondFormatDateType>(maLbDateEntry.GetSelectEntryPos());
1294 pNewEntry->SetDateType(eType);
1295 pNewEntry->SetStyleName(maLbStyle.GetSelectEntry());
1296 return pNewEntry;
1299 OUString ScDateFrmtEntry::GetExpressionString()
1301 return ScCondFormatHelper::GetExpression(DATE, 0);
1304 IMPL_LINK_NOARG( ScDateFrmtEntry, StyleSelectHdl )
1306 mbIsInStyleCreate = true;
1307 StyleSelect( maLbStyle, mpDoc, maWdPreview );
1308 mbIsInStyleCreate = false;
1310 return 0;
1313 class ScIconSetFrmtDataEntry : public Control
1315 private:
1316 FixedImage maImgIcon;
1317 FixedText maFtEntry;
1318 Edit maEdEntry;
1319 ListBox maLbEntryType;
1321 public:
1322 ScIconSetFrmtDataEntry( Window* pParent, ScIconSetType eType, ScDocument* pDoc,
1323 sal_Int32 i, const ScColorScaleEntry* pEntry = NULL );
1325 ScColorScaleEntry* CreateEntry(ScDocument* pDoc, const ScAddress& rPos) const;
1327 void SetFirstEntry();
1330 ScIconSetFrmtDataEntry::ScIconSetFrmtDataEntry( Window* pParent, ScIconSetType eType, ScDocument* pDoc, sal_Int32 i, const ScColorScaleEntry* pEntry ):
1331 Control( pParent, ScResId( RID_ICON_SET_ENTRY ) ),
1332 maImgIcon( this, ScResId( IMG_ICON ) ),
1333 maFtEntry( this, ScResId( FT_ICON_SET_ENTRY_TEXT ) ),
1334 maEdEntry( this, ScResId( ED_ICON_SET_ENTRY_VALUE ) ),
1335 maLbEntryType( this, ScResId( LB_ICON_SET_ENTRY_TYPE ) )
1337 maImgIcon.SetImage(Image(ScIconSetFormat::getBitmap(eType, i)));
1338 if(pEntry)
1340 switch(pEntry->GetType())
1342 case COLORSCALE_VALUE:
1343 maLbEntryType.SelectEntryPos(0);
1344 maEdEntry.SetText(convertNumberToString(pEntry->GetValue(), pDoc));
1345 break;
1346 case COLORSCALE_PERCENTILE:
1347 maLbEntryType.SelectEntryPos(2);
1348 maEdEntry.SetText(convertNumberToString(pEntry->GetValue(), pDoc));
1349 break;
1350 case COLORSCALE_PERCENT:
1351 maLbEntryType.SelectEntryPos(1);
1352 maEdEntry.SetText(convertNumberToString(pEntry->GetValue(), pDoc));
1353 break;
1354 case COLORSCALE_FORMULA:
1355 maLbEntryType.SelectEntryPos(3);
1356 maEdEntry.SetText(pEntry->GetFormula(formula::FormulaGrammar::GRAM_DEFAULT));
1357 break;
1358 default:
1359 assert(false);
1362 else
1364 maLbEntryType.SelectEntryPos(1);
1366 FreeResource();
1369 ScColorScaleEntry* ScIconSetFrmtDataEntry::CreateEntry(ScDocument* pDoc, const ScAddress& rPos) const
1371 sal_Int32 nPos = maLbEntryType.GetSelectEntryPos();
1372 OUString aText = maEdEntry.GetText();
1373 ScColorScaleEntry* pEntry = new ScColorScaleEntry();
1375 sal_uInt32 nIndex = 0;
1376 double nVal = 0;
1377 SvNumberFormatter* pNumberFormatter = pDoc->GetFormatTable();
1378 pNumberFormatter->IsNumberFormat(aText, nIndex, nVal);
1379 pEntry->SetValue(nVal);
1381 switch(nPos)
1383 case 0:
1384 pEntry->SetType(COLORSCALE_VALUE);
1385 break;
1386 case 1:
1387 pEntry->SetType(COLORSCALE_PERCENT);
1388 break;
1389 case 2:
1390 pEntry->SetType(COLORSCALE_PERCENTILE);
1391 break;
1392 case 3:
1393 pEntry->SetType(COLORSCALE_FORMULA);
1394 pEntry->SetFormula(aText, pDoc, rPos, pDoc->GetGrammar());
1395 break;
1396 default:
1397 assert(false);
1400 return pEntry;
1403 void ScIconSetFrmtDataEntry::SetFirstEntry()
1405 maEdEntry.Hide();
1406 maLbEntryType.Hide();
1407 maFtEntry.Hide();
1408 maEdEntry.SetText(OUString("0"));
1409 maLbEntryType.SelectEntryPos(1);
1412 ScIconSetFrmtEntry::ScIconSetFrmtEntry( Window* pParent, ScDocument* pDoc, const ScAddress& rPos, const ScIconSetFormat* pFormat ):
1413 ScCondFrmtEntry( pParent, pDoc, rPos ),
1414 maLbColorFormat( this, ScResId( LB_COLOR_FORMAT ) ),
1415 maLbIconSetType( this, ScResId( LB_ICONSET_TYPE ) )
1417 Init();
1418 FreeResource();
1419 maLbColorFormat.SetSelectHdl( LINK( pParent, ScCondFormatList, ColFormatTypeHdl ) );
1421 if(pFormat)
1423 const ScIconSetFormatData* pIconSetFormatData = pFormat->GetIconSetData();
1424 ScIconSetType eType = pIconSetFormatData->eIconSetType;
1425 sal_Int32 nType = static_cast<sal_Int32>(eType);
1426 maLbIconSetType.SelectEntryPos(nType);
1428 for(size_t i = 0, n = pIconSetFormatData->maEntries.size();
1429 i < n; ++i)
1431 maEntries.push_back( new ScIconSetFrmtDataEntry( this, eType, pDoc, i, &pIconSetFormatData->maEntries[i] ) );
1432 Point aPos = maEntries[0].GetPosPixel();
1433 aPos.Y() += maEntries[0].GetSizePixel().Height() * i * 1.2;
1434 maEntries[i].SetPosPixel( aPos );
1436 maEntries.begin()->SetFirstEntry();
1438 else
1439 IconSetTypeHdl(NULL);
1442 void ScIconSetFrmtEntry::Init()
1444 maLbColorFormat.SelectEntryPos(3);
1445 maLbType.SelectEntryPos(0);
1446 maLbIconSetType.SelectEntryPos(0);
1448 maLbIconSetType.SetSelectHdl( LINK( this, ScIconSetFrmtEntry, IconSetTypeHdl ) );
1451 IMPL_LINK_NOARG( ScIconSetFrmtEntry, IconSetTypeHdl )
1453 ScIconSetMap* pMap = ScIconSetFormat::getIconSetMap();
1455 sal_Int32 nPos = maLbIconSetType.GetSelectEntryPos();
1456 sal_uInt32 nElements = pMap[nPos].nElements;
1457 maEntries.clear();
1459 for(size_t i = 0; i < nElements; ++i)
1461 maEntries.push_back( new ScIconSetFrmtDataEntry( this, static_cast<ScIconSetType>(nPos), mpDoc, i ) );
1462 Point aPos = maEntries[0].GetPosPixel();
1463 aPos.Y() += maEntries[0].GetSizePixel().Height() * i * 1.2;
1464 maEntries[i].SetPosPixel( aPos );
1465 maEntries[i].Show();
1467 maEntries.begin()->SetFirstEntry();
1469 SetHeight();
1470 static_cast<ScCondFormatList*>(GetParent())->RecalcAll();
1472 return 0;
1475 OUString ScIconSetFrmtEntry::GetExpressionString()
1477 return ScCondFormatHelper::GetExpression(ICONSET, 0);
1480 void ScIconSetFrmtEntry::SetActive()
1482 maLbColorFormat.Show();
1483 maLbIconSetType.Show();
1484 for(ScIconSetFrmtDataEntriesType::iterator itr = maEntries.begin(),
1485 itrEnd = maEntries.end(); itr != itrEnd; ++itr)
1487 itr->Show();
1490 Select();
1493 void ScIconSetFrmtEntry::SetInactive()
1495 maLbColorFormat.Hide();
1496 maLbIconSetType.Hide();
1497 for(ScIconSetFrmtDataEntriesType::iterator itr = maEntries.begin(),
1498 itrEnd = maEntries.end(); itr != itrEnd; ++itr)
1500 itr->Hide();
1503 Deselect();
1506 ScFormatEntry* ScIconSetFrmtEntry::GetEntry() const
1508 ScIconSetFormat* pFormat = new ScIconSetFormat(mpDoc);
1510 ScIconSetFormatData* pData = new ScIconSetFormatData;
1511 pData->eIconSetType = static_cast<ScIconSetType>(maLbIconSetType.GetSelectEntryPos());
1512 for(ScIconSetFrmtDataEntriesType::const_iterator itr = maEntries.begin(),
1513 itrEnd = maEntries.end(); itr != itrEnd; ++itr)
1515 pData->maEntries.push_back(itr->CreateEntry(mpDoc, maPos));
1517 pFormat->SetIconSetData(pData);
1519 return pFormat;
1522 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */