diff options
author | Caolán McNamara <caolanm@redhat.com> | 2018-08-29 17:05:28 +0100 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2018-08-30 09:06:34 +0200 |
commit | 923c14135c21ffde2a19ca7875be6ebb79197740 (patch) | |
tree | 72ed31d9f814702d866611a2a9d1e1defa9603e5 /sfx2/source/dialog | |
parent | 6c99bca30449589a2904891939e12e6a474464eb (diff) |
add SfxStyleDialogController
Change-Id: I5b55b8adb46d894f87dcf68c97f6fd56059354a2
Reviewed-on: https://gerrit.libreoffice.org/59768
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Tested-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'sfx2/source/dialog')
-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 |
3 files changed, 166 insertions, 8 deletions
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] |