diff options
-rw-r--r-- | include/sfx2/mgetempl.hxx | 1 | ||||
-rw-r--r-- | include/sfx2/styledlg.hxx | 19 | ||||
-rw-r--r-- | include/sfx2/tabdlg.hxx | 6 | ||||
-rw-r--r-- | sfx2/source/dialog/mgetempl.cxx | 2 | ||||
-rw-r--r-- | sfx2/source/dialog/styledlg.cxx | 84 | ||||
-rw-r--r-- | sfx2/source/dialog/tabdlg.cxx | 88 | ||||
-rw-r--r-- | sw/source/uibase/app/docst.cxx | 2 |
7 files changed, 191 insertions, 11 deletions
diff --git a/include/sfx2/mgetempl.hxx b/include/sfx2/mgetempl.hxx index 4a2c906ca9c2..238d662c33f5 100644 --- a/include/sfx2/mgetempl.hxx +++ b/include/sfx2/mgetempl.hxx @@ -64,6 +64,7 @@ class SfxManageStyleSheetPage final : public SfxTabPage std::unique_ptr<weld::Label> m_xNameFt; friend class SfxStyleDialog; +friend class SfxStyleDialogController; DECL_LINK(GetFocusHdl, weld::Widget&, void); DECL_LINK(LoseFocusHdl, weld::Widget&, void); diff --git a/include/sfx2/styledlg.hxx b/include/sfx2/styledlg.hxx index 5abf6c653d22..e86c6450e355 100644 --- a/include/sfx2/styledlg.hxx +++ b/include/sfx2/styledlg.hxx @@ -21,7 +21,6 @@ #include <sal/config.h> #include <sfx2/dllapi.h> - #include <sfx2/tabdlg.hxx> class SfxStyleSheetBase; @@ -45,6 +44,24 @@ public: const SfxStyleSheetBase& GetStyleSheet() const { return *pStyle; } virtual short Ok() override; +}; + +class SFX2_DLLPUBLIC SfxStyleDialogController : public SfxTabDialogController +{ +private: + SfxStyleSheetBase& m_rStyle; + DECL_DLLPRIVATE_LINK(CancelHdl, weld::Button&, void); + +public: + SfxStyleDialogController(weld::Window* pParent, + const OUString& rUIXMLDescription, const OString& rID, SfxStyleSheetBase&); + + virtual ~SfxStyleDialogController() override; + + SfxStyleSheetBase& GetStyleSheet() { return m_rStyle; } + const SfxStyleSheetBase& GetStyleSheet() const { return m_rStyle; } + + virtual short Ok() override; static OUString GenerateUnusedName(SfxStyleSheetBasePool &rPool); }; diff --git a/include/sfx2/tabdlg.hxx b/include/sfx2/tabdlg.hxx index 64a8ebc5d6ae..ebcaf8c17268 100644 --- a/include/sfx2/tabdlg.hxx +++ b/include/sfx2/tabdlg.hxx @@ -230,6 +230,7 @@ protected: DECL_LINK(OkHdl, weld::Button&, void); DECL_LINK(ResetHdl, weld::Button&, void); + DECL_LINK(BaseFmtHdl, weld::Button&, void); DECL_LINK(UserHdl, weld::Button&, void); DECL_LINK(CancelHdl, weld::Button&, void); private: @@ -238,6 +239,7 @@ private: std::unique_ptr<weld::Button> m_xUserBtn; std::unique_ptr<weld::Button> m_xCancelBtn; std::unique_ptr<weld::Button> m_xResetBtn; + std::unique_ptr<weld::Button> m_xBaseFmtBtn; std::unique_ptr<weld::SizeGroup> m_xSizeGroup; std::unique_ptr<SfxItemSet> m_pSet; @@ -245,6 +247,7 @@ private: std::unique_ptr<TabDlg_Impl> m_pImpl; std::unique_ptr<sal_uInt16[]> m_pRanges; OString m_sAppPageId; + bool m_bStandardPushed; DECL_DLLPRIVATE_LINK(ActivatePageHdl, const OString&, void); DECL_DLLPRIVATE_LINK(DeactivatePageHdl, const OString&, bool); @@ -273,7 +276,7 @@ protected: void Start_Impl(); public: SfxTabDialogController(weld::Window* pParent, const OUString& rUIXMLDescription, const OString& rID, - const SfxItemSet * = nullptr); + const SfxItemSet * = nullptr, bool bEditFmt = false); virtual ~SfxTabDialogController() override; void AddTabPage( const OString& rName, // Name of the label for the page in the notebook .ui @@ -298,6 +301,7 @@ public: const weld::Button* GetUserButton() const { return m_xUserBtn.get(); } weld::Button* GetUserButton() { return m_xUserBtn.get(); } void RemoveResetButton(); + void RemoveStandardButton(); short execute(); static bool runAsync(const std::shared_ptr<SfxTabDialogController>& rController, diff --git a/sfx2/source/dialog/mgetempl.cxx b/sfx2/source/dialog/mgetempl.cxx index b5d9634588ef..663a26295453 100644 --- a/sfx2/source/dialog/mgetempl.cxx +++ b/sfx2/source/dialog/mgetempl.cxx @@ -111,7 +111,7 @@ SfxManageStyleSheetPage::SfxManageStyleSheetPage(TabPageParent pParent, const Sf if ( pStyle->GetName().isEmpty() && pPool ) { // NullString as Name -> generate Name - OUString aNoName(SfxStyleDialog::GenerateUnusedName(*pPool)); + OUString aNoName(SfxStyleDialogController::GenerateUnusedName(*pPool)); pStyle->SetName( aNoName ); aName = aNoName; aFollow = pStyle->GetFollow(); diff --git a/sfx2/source/dialog/styledlg.cxx b/sfx2/source/dialog/styledlg.cxx index baa1368d7c5b..00ccaff9a7c2 100644 --- a/sfx2/source/dialog/styledlg.cxx +++ b/sfx2/source/dialog/styledlg.cxx @@ -131,7 +131,89 @@ IMPL_LINK_NOARG( SfxStyleDialog, CancelHdl, Button *, void ) EndDialog(); } -OUString SfxStyleDialog::GenerateUnusedName(SfxStyleSheetBasePool &rPool) +/* [Description] + + Constructor: Add Manage TabPage, set ExampleSet from style. +*/ +SfxStyleDialogController::SfxStyleDialogController +( + weld::Window* pParent, // Parent + const OUString& rUIXMLDescription, const OString& rID, + SfxStyleSheetBase& rStyle // stylesheet to be processed +) + : SfxTabDialogController(pParent, rUIXMLDescription, rID, &rStyle.GetItemSet(), true) + , m_rStyle(rStyle) +{ + // without ParentSupport suppress the standardButton + if (!rStyle.HasParentSupport()) + RemoveStandardButton(); + + AddTabPage("organizer", SfxManageStyleSheetPage::Create, nullptr); + + // With new template always set the management page as the current page + if (rStyle.GetName().isEmpty()) + SetCurPageId("organizer"); + else + { + OUString sTxt = m_xDialog->get_title() + ": " + rStyle.GetName(); + m_xDialog->set_title(sTxt); + } + m_xExampleSet.reset(&m_rStyle.GetItemSet()); // in SfxTabDialog::Ctor() already created, reset will delete it + + GetCancelButton().connect_clicked(LINK(this, SfxStyleDialogController, CancelHdl)); +} + +/* [Description] + + Destructor: set ExampleSet to NULL, so that SfxTabDialog does not delete + the Set from Style. +*/ +SfxStyleDialogController::~SfxStyleDialogController() +{ + m_xExampleSet.release(); +} + +/* [Description] + + Override so that always RET_OK is returned. +*/ +short SfxStyleDialogController::Ok() +{ + SfxTabDialogController::Ok(); + return RET_OK; +} + +/* [Description] + + If the dialogue was canceled, then all selected attributes must be reset + again. +*/ +IMPL_LINK_NOARG(SfxStyleDialogController, CancelHdl, weld::Button&, void) +{ + SfxTabPage* pPage = GetTabPage("organizer"); + + const SfxItemSet* pInSet = GetInputSetImpl(); + SfxWhichIter aIter(*pInSet); + sal_uInt16 nWhich = aIter.FirstWhich(); + + while (nWhich) + { + SfxItemState eState = pInSet->GetItemState(nWhich, false); + + if (SfxItemState::DEFAULT == eState) + m_xExampleSet->ClearItem(nWhich); + else + m_xExampleSet->Put(pInSet->Get(nWhich)); + nWhich = aIter.NextWhich(); + } + + if (pPage) + pPage->Reset(GetInputSetImpl()); + + m_xDialog->response(RET_CANCEL); +} + +OUString SfxStyleDialogController::GenerateUnusedName(SfxStyleSheetBasePool &rPool) { OUString aNo(SfxResId(STR_NONAME)); sal_uInt16 i = 1; diff --git a/sfx2/source/dialog/tabdlg.cxx b/sfx2/source/dialog/tabdlg.cxx index 87b414b6fed2..57c3f291084e 100644 --- a/sfx2/source/dialog/tabdlg.cxx +++ b/sfx2/source/dialog/tabdlg.cxx @@ -1448,8 +1448,9 @@ SfxTabDialogController::SfxTabDialogController ( weld::Window* pParent, // Parent Window const OUString& rUIXMLDescription, const OString& rID, // Dialog .ui path, Dialog Name - const SfxItemSet* pItemSet // Itemset with the data; + const SfxItemSet* pItemSet, // Itemset with the data; // can be NULL, when Pages are onDemand + bool bEditFmt // when yes -> additional Button for standard ) : GenericDialogController(pParent, rUIXMLDescription, rID) , m_xTabCtrl(m_xBuilder->weld_notebook("tabcontrol")) @@ -1458,7 +1459,9 @@ SfxTabDialogController::SfxTabDialogController , m_xUserBtn(m_xBuilder->weld_button("user")) , m_xCancelBtn(m_xBuilder->weld_button("cancel")) , m_xResetBtn(m_xBuilder->weld_button("reset")) + , m_xBaseFmtBtn(m_xBuilder->weld_button("standard")) , m_pSet(pItemSet ? new SfxItemSet(*pItemSet) : nullptr) + , m_bStandardPushed(false) { m_pImpl.reset(new TabDlg_Impl(m_xTabCtrl->get_n_pages())); m_pImpl->bHideResetBtn = !m_xResetBtn->get_visible(); @@ -1470,6 +1473,14 @@ SfxTabDialogController::SfxTabDialogController m_xTabCtrl->connect_leave_page(LINK(this, SfxTabDialogController, DeactivatePageHdl)); m_xResetBtn->set_help_id(HID_TABDLG_RESET_BTN); + if (bEditFmt) + { + m_xBaseFmtBtn->set_label(SfxResId(STR_STANDARD_SHORTCUT)); + m_xBaseFmtBtn->connect_clicked(LINK(this, SfxTabDialogController, BaseFmtHdl)); + m_xBaseFmtBtn->set_help_id(HID_TABDLG_STANDARD_BTN); + m_xBaseFmtBtn->show(); + } + if (m_xUserBtn) m_xUserBtn->connect_clicked(LINK(this, SfxTabDialogController, UserHdl)); @@ -1532,11 +1543,10 @@ IMPL_LINK_NOARG(SfxTabDialogController, ResetHdl, weld::Button&, void) */ { - const OString sId = m_xTabCtrl->get_current_page_ident(); - Data_Impl* pDataObject = Find( m_pImpl->aData, sId ); - DBG_ASSERT( pDataObject, "Id not known" ); + Data_Impl* pDataObject = Find(m_pImpl->aData, m_xTabCtrl->get_current_page_ident()); + assert(pDataObject && "Id not known"); - pDataObject->pTabPage->Reset( m_pSet.get() ); + pDataObject->pTabPage->Reset(m_pSet.get()); // Also reset relevant items of ExampleSet and OutSet to initial state if (pDataObject->fnGetRanges) { @@ -1583,6 +1593,63 @@ IMPL_LINK_NOARG(SfxTabDialogController, ResetHdl, weld::Button&, void) } } +/* [Description] + + Handler behind the Standard-Button. + This button is available when editing style sheets. All the set attributes + in the edited stylesheet are deleted. +*/ +IMPL_LINK_NOARG(SfxTabDialogController, BaseFmtHdl, weld::Button&, void) +{ + m_bStandardPushed = true; + + Data_Impl* pDataObject = Find(m_pImpl->aData, m_xTabCtrl->get_current_page_ident()); + assert(pDataObject && "Id not known"); + + if (pDataObject->fnGetRanges) + { + if (!m_xExampleSet) + m_xExampleSet.reset(new SfxItemSet(*m_pSet)); + + const SfxItemPool* pPool = m_pSet->GetPool(); + const sal_uInt16* pTmpRanges = (pDataObject->fnGetRanges)(); + SfxItemSet aTmpSet(*m_xExampleSet); + + while (*pTmpRanges) + { + const sal_uInt16* pU = pTmpRanges + 1; + + // Correct Range with multiple values + sal_uInt16 nTmp = *pTmpRanges, nTmpEnd = *pU; + DBG_ASSERT( nTmp <= nTmpEnd, "Range is sorted the wrong way" ); + + if ( nTmp > nTmpEnd ) + { + // If really sorted wrongly, then set new + std::swap(nTmp, nTmpEnd); + } + + while ( nTmp && nTmp <= nTmpEnd ) // guard against overflow + { + // Iterate over the Range and set the Items + sal_uInt16 nWh = pPool->GetWhich(nTmp); + m_xExampleSet->ClearItem(nWh); + aTmpSet.ClearItem(nWh); + // At the Outset of InvalidateItem, + // so that the change takes effect + m_pOutSet->InvalidateItem(nWh); + nTmp++; + } + // Go to the next pair + pTmpRanges += 2; + } + // Set all Items as new -> the call the current Page Reset() + assert(pDataObject->pTabPage && "the Page is gone"); + pDataObject->pTabPage->Reset( &aTmpSet ); + pDataObject->pTabPage->pImpl->mbStandard = true; + } +} + IMPL_LINK(SfxTabDialogController, ActivatePageHdl, const OString&, rPage, void) /* [Description] @@ -1869,7 +1936,10 @@ short SfxTabDialogController::Ok() } } - if ( m_pOutSet && m_pOutSet->Count() > 0 ) + if (m_pOutSet && m_pOutSet->Count() > 0) + bModified = true; + + if (m_bStandardPushed) bModified = true; return bModified ? RET_OK : RET_CANCEL; @@ -2099,6 +2169,12 @@ void SfxTabDialogController::RemoveResetButton() m_pImpl->bHideResetBtn = true; } +void SfxTabDialogController::RemoveStandardButton() +{ + m_xBaseFmtBtn->hide(); + m_pImpl->bHideResetBtn = true; +} + SfxTabPage* SfxTabDialogController::GetTabPage(const OString& rPageId) const /* [Description] diff --git a/sw/source/uibase/app/docst.cxx b/sw/source/uibase/app/docst.cxx index 95d3cc936aa9..6c748709b94e 100644 --- a/sw/source/uibase/app/docst.cxx +++ b/sw/source/uibase/app/docst.cxx @@ -320,7 +320,7 @@ void SwDocShell::ExecStyleSheet( SfxRequest& rReq ) sParent = static_cast<const SfxStringItem*>(pItem)->GetValue(); if (sName.isEmpty() && m_xBasePool.get()) - sName = SfxStyleDialog::GenerateUnusedName(*m_xBasePool); + sName = SfxStyleDialogController::GenerateUnusedName(*m_xBasePool); Edit(sName, sParent, nFamily, nMask, true, OString(), nullptr, &rReq, nSlot); } |