From 6030a11ce58761a9b3399c1152da76779d1e88b4 Mon Sep 17 00:00:00 2001 From: Markus Mohrhard Date: Sun, 3 Jun 2012 04:33:07 +0200 Subject: handle styles correctly in the new cond format dialog Change-Id: I285efa3ec455fd35afd00aa5daa2c722fe7d277b --- sc/source/ui/condformat/condformatdlg.cxx | 58 +++++++++++++++++++++++++++++++ sc/source/ui/inc/condformatdlg.hxx | 1 + 2 files changed, 59 insertions(+) diff --git a/sc/source/ui/condformat/condformatdlg.cxx b/sc/source/ui/condformat/condformatdlg.cxx index 648debbaa2ca..f7bbbfb0b98a 100644 --- a/sc/source/ui/condformat/condformatdlg.cxx +++ b/sc/source/ui/condformat/condformatdlg.cxx @@ -31,11 +31,17 @@ #include #include +#include +#include +#include #include "anyrefdg.hxx" #include "document.hxx" #include "conditio.hxx" #include "stlpool.hxx" +#include "tabvwsh.hxx" + +#include "globstr.hrc" #include @@ -84,6 +90,7 @@ ScCondFrmtEntry::ScCondFrmtEntry(Window* pParent, ScDocument* pDoc): } maLbStyle.SetSeparatorPos(0); maLbStyle.SelectEntryPos(1); + maLbStyle.SetSelectHdl( LINK( this, ScCondFrmtEntry, StyleSelectHdl ) ); //disable entries for color formats maLbColorFormat.SelectEntryPos(0); @@ -344,6 +351,57 @@ IMPL_LINK_NOARG(ScCondFrmtEntry, ColFormatTypeHdl) return 0; } +IMPL_LINK_NOARG(ScCondFrmtEntry, 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; +} + ScCondFormatList::ScCondFormatList(Window* pParent, const ResId& rResId, ScDocument* pDoc): Control(pParent, rResId), mbHasScrollBar(false), diff --git a/sc/source/ui/inc/condformatdlg.hxx b/sc/source/ui/inc/condformatdlg.hxx index b9c113239a94..4a804e4e4b9c 100644 --- a/sc/source/ui/inc/condformatdlg.hxx +++ b/sc/source/ui/inc/condformatdlg.hxx @@ -102,6 +102,7 @@ private: DECL_LINK( TypeListHdl, void*); DECL_LINK( ColFormatTypeHdl, void*); + DECL_LINK( StyleSelectHdl, void* ); public: ScCondFrmtEntry( Window* pParent, ScDocument* pDoc ); -- cgit