diff options
author | Markus Mohrhard <markus.mohrhard@googlemail.com> | 2012-10-08 13:55:26 +0200 |
---|---|---|
committer | Markus Mohrhard <markus.mohrhard@googlemail.com> | 2012-10-09 06:33:17 +0200 |
commit | ee93051d46db4332f779bac9cb2b75850afc98b0 (patch) | |
tree | 82341ba7cbf823f023654f3a2ddad78389a54c28 /sc | |
parent | d7a27f400fa148037822e93857a2b6d9d37750b8 (diff) |
add own class for formula type cond formats
Change-Id: I0348797babb9e94e1d552dce341504144c837325
Diffstat (limited to 'sc')
-rw-r--r-- | sc/source/ui/condformat/condformatdlg.cxx | 6 | ||||
-rw-r--r-- | sc/source/ui/condformat/condformatdlgentry.cxx | 138 | ||||
-rw-r--r-- | sc/source/ui/inc/condformatdlg.hrc | 2 | ||||
-rw-r--r-- | sc/source/ui/inc/condformatdlgentry.hxx | 20 | ||||
-rw-r--r-- | sc/source/ui/src/condformatdlg.src | 6 |
5 files changed, 157 insertions, 15 deletions
diff --git a/sc/source/ui/condformat/condformatdlg.cxx b/sc/source/ui/condformat/condformatdlg.cxx index a3be0032dfcd..e9234e696601 100644 --- a/sc/source/ui/condformat/condformatdlg.cxx +++ b/sc/source/ui/condformat/condformatdlg.cxx @@ -190,13 +190,15 @@ IMPL_LINK(ScCondFormatList, TypeListHdl, ListBox*, pBox) { case 0: maEntries.replace( itr, new ScColorScaleFrmtEntry(this, mpDoc, maPos)); - itr->SetHeight(); + itr->SetActive(); break; case 1: maEntries.replace( itr, new ScConditionFrmtEntry(this, mpDoc, maPos)); - itr->SetHeight(); + itr->SetActive(); break; case 2: + maEntries.replace( itr, new ScFormulaFrmtEntry(this, mpDoc, maPos)); + itr->SetActive(); break; } RecalcAll(); diff --git a/sc/source/ui/condformat/condformatdlgentry.cxx b/sc/source/ui/condformat/condformatdlgentry.cxx index f1d43794bb25..00c5b3ea56c8 100644 --- a/sc/source/ui/condformat/condformatdlgentry.cxx +++ b/sc/source/ui/condformat/condformatdlgentry.cxx @@ -1,6 +1,7 @@ #include "condformatdlg.hxx" #include "condformatdlgentry.hxx" #include "condformatdlg.hrc" +#include "conditio.hxx" #include "document.hxx" @@ -139,18 +140,6 @@ IMPL_LINK(ScCondFrmtEntry, EdModifyHdl, Edit*, pEdit) // //condition -ScFormatEntry* ScConditionFrmtEntry::createFormulaEntry() const -{ - ScConditionMode eMode = SC_COND_DIRECT; - rtl::OUString aFormula = maEdVal1.GetText(); - if(aFormula.isEmpty()) - return NULL; - - rtl::OUString aExpr2; - ScFormatEntry* pEntry = new ScCondFormatEntry(eMode, aFormula, aExpr2, mpDoc, maPos, maLbStyle.GetSelectEntry()); - return pEntry; -} - ScConditionFrmtEntry::ScConditionFrmtEntry( Window* pParent, ScDocument* pDoc, const ScAddress& rPos, const ScCondFormatEntry* pFormatEntry ): ScCondFrmtEntry( pParent, pDoc, rPos ), maLbCondType( this, ScResId( LB_CELLIS_TYPE ) ), @@ -377,6 +366,131 @@ IMPL_LINK_NOARG(ScConditionFrmtEntry, StyleSelectHdl) return 0; } +// formula + +ScFormulaFrmtEntry::ScFormulaFrmtEntry( Window* pParent, ScDocument* pDoc, const ScAddress& rPos, const ScCondFormatEntry* pFormat ): + ScCondFrmtEntry( pParent, pDoc, rPos ), + maFtStyle( this, ScResId( FT_STYLE ) ), + maLbStyle( this, ScResId( LB_STYLE ) ), + maWdPreview( this, ScResId( WD_PREVIEW ) ), + maEdFormula( this, ScResId( ED_FORMULA ) ) +{ + Init(); + + FreeResource(); + + if(pFormat) + { + maEdFormula.SetText(pFormat->GetExpression(rPos, 0, 0, pDoc->GetGrammar())); + maLbStyle.SelectEntry(pFormat->GetStyle()); + } + else + { + maLbStyle.SelectEntryPos(1); + } +} + +void ScFormulaFrmtEntry::Init() +{ + maLbStyle.SetSeparatorPos(0); + + SfxStyleSheetIterator aStyleIter( mpDoc->GetStyleSheetPool(), SFX_STYLE_FAMILY_PARA ); + for ( SfxStyleSheetBase* pStyle = aStyleIter.First(); pStyle; pStyle = aStyleIter.Next() ) + { + rtl::OUString aName = pStyle->GetName(); + maLbStyle.InsertEntry( aName ); + } + maLbStyle.SetSelectHdl( LINK( this, ScFormulaFrmtEntry, StyleSelectHdl ) ); +} + +IMPL_LINK_NOARG(ScFormulaFrmtEntry, StyleSelectHdl) +{ + if(maLbStyle.GetSelectEntryPos() == 0) + { + // call new style dialog + SfxUInt16Item aFamilyItem( SID_STYLE_FAMILY, SFX_STYLE_FAMILY_PARA ); + SfxStringItem aRefItem( SID_STYLE_REFERENCE, ScGlobal::GetRscString(STR_STYLENAME_STANDARD) ); + + // unlock the dispatcher so SID_STYLE_NEW can be executed + // (SetDispatcherLock would affect all Calc documents) + ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell(); + SfxDispatcher* pDisp = pViewShell->GetDispatcher(); + sal_Bool bLocked = pDisp->IsLocked(); + if (bLocked) + pDisp->Lock(false); + + // Execute the "new style" slot, complete with undo and all necessary updates. + // The return value (SfxUInt16Item) is ignored, look for new styles instead. + pDisp->Execute( SID_STYLE_NEW, SFX_CALLMODE_SYNCHRON | SFX_CALLMODE_RECORD | SFX_CALLMODE_MODAL, + &aFamilyItem, + &aRefItem, + 0L ); + + if (bLocked) + pDisp->Lock(sal_True); + + // Find the new style and add it into the style list boxes + rtl::OUString aNewStyle; + SfxStyleSheetIterator aStyleIter( mpDoc->GetStyleSheetPool(), SFX_STYLE_FAMILY_PARA ); + for ( SfxStyleSheetBase* pStyle = aStyleIter.First(); pStyle; pStyle = aStyleIter.Next() ) + { + rtl::OUString aName = pStyle->GetName(); + if ( maLbStyle.GetEntryPos(aName) == LISTBOX_ENTRY_NOTFOUND ) // all lists contain the same entries + { + maLbStyle.InsertEntry(aName); + maLbStyle.SelectEntry(aName); + } + } + } + + rtl::OUString aStyleName = maLbStyle.GetSelectEntry(); + SfxStyleSheetBase* pStyleSheet = mpDoc->GetStyleSheetPool()->Find( aStyleName, SFX_STYLE_FAMILY_PARA ); + if(pStyleSheet) + { + const SfxItemSet& rSet = pStyleSheet->GetItemSet(); + maWdPreview.Init( rSet ); + } + + return 0; +} + +ScFormatEntry* ScFormulaFrmtEntry::createFormulaEntry() const +{ + ScConditionMode eMode = SC_COND_DIRECT; + rtl::OUString aFormula = maEdFormula.GetText(); + if(aFormula.isEmpty()) + return NULL; + + rtl::OUString aExpr2; + ScFormatEntry* pEntry = new ScCondFormatEntry(eMode, aFormula, aExpr2, mpDoc, maPos, maLbStyle.GetSelectEntry()); + return pEntry; +} + +ScFormatEntry* ScFormulaFrmtEntry::GetEntry() const +{ + return createFormulaEntry(); +} + +void ScFormulaFrmtEntry::SetActive() +{ + maWdPreview.Show(); + maFtStyle.Show(); + maLbStyle.Show(); + maEdFormula.Show(); + + Select(); +} + +void ScFormulaFrmtEntry::SetInactive() +{ + maWdPreview.Hide(); + maFtStyle.Hide(); + maLbStyle.Hide(); + maEdFormula.Hide(); + + Deselect(); +} + //color scale namespace { diff --git a/sc/source/ui/inc/condformatdlg.hrc b/sc/source/ui/inc/condformatdlg.hrc index 960faec13048..f0258567f0f5 100644 --- a/sc/source/ui/inc/condformatdlg.hrc +++ b/sc/source/ui/inc/condformatdlg.hrc @@ -59,4 +59,6 @@ #define ED_RANGE 33 #define RB_RANGE 34 +#define ED_FORMULA 35 + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/inc/condformatdlgentry.hxx b/sc/source/ui/inc/condformatdlgentry.hxx index 4484b0a7856f..75f45022ea30 100644 --- a/sc/source/ui/inc/condformatdlgentry.hxx +++ b/sc/source/ui/inc/condformatdlgentry.hxx @@ -55,7 +55,6 @@ class ScConditionFrmtEntry : public ScCondFrmtEntry SvxFontPrevWindow maWdPreview; ScFormatEntry* createConditionEntry() const; - ScFormatEntry* createFormulaEntry() const; void Init(); DECL_LINK( StyleSelectHdl, void* ); @@ -68,6 +67,25 @@ public: virtual void SetInactive(); }; +class ScFormulaFrmtEntry : public ScCondFrmtEntry +{ + FixedText maFtStyle; + ListBox maLbStyle; + SvxFontPrevWindow maWdPreview; + Edit maEdFormula; + + ScFormatEntry* createFormulaEntry() const; + void Init(); + + DECL_LINK( StyleSelectHdl, void* ); +public: + ScFormulaFrmtEntry( Window* pParent, ScDocument* PDoc, const ScAddress& rPos, const ScCondFormatEntry* pFormatEntry = NULL ); + + virtual ScFormatEntry* GetEntry() const; + virtual void SetActive(); + virtual void SetInactive(); +}; + class ScColorScaleFrmtEntry : public ScCondFrmtEntry { diff --git a/sc/source/ui/src/condformatdlg.src b/sc/source/ui/src/condformatdlg.src index e7fa731144b9..16b26509f40f 100644 --- a/sc/source/ui/src/condformatdlg.src +++ b/sc/source/ui/src/condformatdlg.src @@ -149,6 +149,12 @@ Control RID_COND_ENTRY Size = MAP_APPFONT( 50, 12 ); Border = TRUE; }; + Edit ED_FORMULA + { + Pos = MAP_APPFONT( 90, 15 ); + Size = MAP_APPFONT( 135, 12 ); + Border = TRUE; + }; Edit ED_VAL2 { Pos = MAP_APPFONT( 230, 15 ); |