diff options
Diffstat (limited to 'sw/source/uibase/app/appopt.cxx')
-rw-r--r-- | sw/source/uibase/app/appopt.cxx | 207 |
1 files changed, 89 insertions, 118 deletions
diff --git a/sw/source/uibase/app/appopt.cxx b/sw/source/uibase/app/appopt.cxx index 1ab2a7823092..f21fc733c92a 100644 --- a/sw/source/uibase/app/appopt.cxx +++ b/sw/source/uibase/app/appopt.cxx @@ -56,12 +56,12 @@ #include <swabstdlg.hxx> #include <swwrtshitem.hxx> -#include <ndtxt.hxx> +#include <sfx2/dispatch.hxx> using namespace ::com::sun::star::uno; using namespace ::com::sun::star::lang; -std::unique_ptr<SfxItemSet> SwModule::CreateItemSet( sal_uInt16 nId ) +std::optional<SfxItemSet> SwModule::CreateItemSet( sal_uInt16 nId ) { bool bTextDialog = (nId == SID_SW_EDITOPTIONS); @@ -70,7 +70,7 @@ std::unique_ptr<SfxItemSet> SwModule::CreateItemSet( sal_uInt16 nId ) SwMasterUsrPref* pPref = bTextDialog ? m_pUsrPref.get() : m_pWebUsrPref.get(); // no MakeUsrPref, because only options from textdoks can be used here SwView* pAppView = GetView(); - if(pAppView && pAppView->GetViewFrame() != SfxViewFrame::Current()) + if(pAppView && &pAppView->GetViewFrame() != SfxViewFrame::Current()) pAppView = nullptr; if(pAppView) { @@ -85,9 +85,7 @@ std::unique_ptr<SfxItemSet> SwModule::CreateItemSet( sal_uInt16 nId ) } // Options/Edit - auto pRet = std::make_unique<SfxItemSet>( - GetPool(), - svl::Items< + SfxItemSetFixed< RES_BACKGROUND, RES_BACKGROUND, XATTR_FILL_FIRST, XATTR_FILL_LAST, SID_PRINTPREVIEW, SID_PRINTPREVIEW, @@ -104,14 +102,17 @@ std::unique_ptr<SfxItemSet> SwModule::CreateItemSet( sal_uInt16 nId ) FN_PARAM_PRINTER, FN_PARAM_STDFONTS, FN_PARAM_WRTSHELL, FN_PARAM_WRTSHELL, FN_PARAM_SHADOWCURSOR, FN_PARAM_SHADOWCURSOR, - FN_PARAM_CRSR_IN_PROTECTED, FN_PARAM_CRSR_IN_PROTECTED>{}); + FN_PARAM_CRSR_IN_PROTECTED, FN_PARAM_CRSR_IN_PROTECTED, + FN_PARAM_FMT_AIDS_AUTOCOMPL, FN_PARAM_FMT_AIDS_AUTOCOMPL> + aRet(GetPool()); - pRet->Put( SwDocDisplayItem( aViewOpt ) ); - pRet->Put( SwElemItem( aViewOpt ) ); + aRet.Put( SwDocDisplayItem( aViewOpt ) ); + aRet.Put( SwElemItem( aViewOpt ) ); if( bTextDialog ) { - pRet->Put( SwShadowCursorItem( aViewOpt )); - pRet->Put( SfxBoolItem(FN_PARAM_CRSR_IN_PROTECTED, aViewOpt.IsCursorInProtectedArea())); + aRet.Put( SwShadowCursorItem( aViewOpt )); + aRet.Put( SfxBoolItem(FN_PARAM_CRSR_IN_PROTECTED, aViewOpt.IsCursorInProtectedArea())); + aRet.Put(SwFmtAidsAutoComplItem(aViewOpt)); } if( pAppView ) @@ -120,12 +121,12 @@ std::unique_ptr<SfxItemSet> SwModule::CreateItemSet( sal_uInt16 nId ) SfxPrinter* pPrt = rWrtShell.getIDocumentDeviceAccess().getPrinter( false ); if( pPrt ) - pRet->Put(SwPtrItem(FN_PARAM_PRINTER, pPrt)); - pRet->Put(SwPtrItem(FN_PARAM_WRTSHELL, &rWrtShell)); + aRet.Put(SwPtrItem(FN_PARAM_PRINTER, pPrt)); + aRet.Put(SwPtrItem(FN_PARAM_WRTSHELL, &rWrtShell)); - pRet->Put(rWrtShell.GetDefault(RES_CHRATR_LANGUAGE).CloneSetWhich(SID_ATTR_LANGUAGE)); - pRet->Put(rWrtShell.GetDefault(RES_CHRATR_CJK_LANGUAGE).CloneSetWhich(SID_ATTR_CHAR_CJK_LANGUAGE)); - pRet->Put(rWrtShell.GetDefault(RES_CHRATR_CTL_LANGUAGE).CloneSetWhich(SID_ATTR_CHAR_CTL_LANGUAGE)); + aRet.Put(rWrtShell.GetDefault(RES_CHRATR_LANGUAGE).CloneSetWhich(SID_ATTR_LANGUAGE)); + aRet.Put(rWrtShell.GetDefault(RES_CHRATR_CJK_LANGUAGE).CloneSetWhich(SID_ATTR_CHAR_CJK_LANGUAGE)); + aRet.Put(rWrtShell.GetDefault(RES_CHRATR_CTL_LANGUAGE).CloneSetWhich(SID_ATTR_CHAR_CTL_LANGUAGE)); } else { @@ -135,50 +136,50 @@ std::unique_ptr<SfxItemSet> SwModule::CreateItemSet( sal_uInt16 nId ) using namespace ::com::sun::star::i18n::ScriptType; - Any aLang = aLinguCfg.GetProperty("DefaultLocale"); + Any aLang = aLinguCfg.GetProperty(u"DefaultLocale"); aLang >>= aLocale; nLang = MsLangId::resolveSystemLanguageByScriptType(LanguageTag::convertToLanguageType( aLocale, false), LATIN); - pRet->Put(SvxLanguageItem(nLang, SID_ATTR_LANGUAGE)); + aRet.Put(SvxLanguageItem(nLang, SID_ATTR_LANGUAGE)); - aLang = aLinguCfg.GetProperty("DefaultLocale_CJK"); + aLang = aLinguCfg.GetProperty(u"DefaultLocale_CJK"); aLang >>= aLocale; nLang = MsLangId::resolveSystemLanguageByScriptType(LanguageTag::convertToLanguageType( aLocale, false), ASIAN); - pRet->Put(SvxLanguageItem(nLang, SID_ATTR_CHAR_CJK_LANGUAGE)); + aRet.Put(SvxLanguageItem(nLang, SID_ATTR_CHAR_CJK_LANGUAGE)); - aLang = aLinguCfg.GetProperty("DefaultLocale_CTL"); + aLang = aLinguCfg.GetProperty(u"DefaultLocale_CTL"); aLang >>= aLocale; nLang = MsLangId::resolveSystemLanguageByScriptType(LanguageTag::convertToLanguageType( aLocale, false), COMPLEX); - pRet->Put(SvxLanguageItem(nLang, SID_ATTR_CHAR_CTL_LANGUAGE)); + aRet.Put(SvxLanguageItem(nLang, SID_ATTR_CHAR_CTL_LANGUAGE)); } if(bTextDialog) - pRet->Put(SwPtrItem(FN_PARAM_STDFONTS, GetStdFontConfig())); + aRet.Put(SwPtrItem(FN_PARAM_STDFONTS, GetStdFontConfig())); if( dynamic_cast<SwPagePreview*>( SfxViewShell::Current())!=nullptr ) { SfxBoolItem aBool(SfxBoolItem(SID_PRINTPREVIEW, true)); - pRet->Put(aBool); + aRet.Put(aBool); } FieldUnit eUnit = pPref->GetHScrollMetric(); if(pAppView) pAppView->GetHRulerMetric(eUnit); - pRet->Put(SfxUInt16Item( FN_HSCROLL_METRIC, static_cast< sal_uInt16 >(eUnit))); + aRet.Put(SfxUInt16Item( FN_HSCROLL_METRIC, static_cast< sal_uInt16 >(eUnit))); eUnit = pPref->GetVScrollMetric(); if(pAppView) pAppView->GetVRulerMetric(eUnit); - pRet->Put(SfxUInt16Item( FN_VSCROLL_METRIC, static_cast< sal_uInt16 >(eUnit) )); - pRet->Put(SfxUInt16Item( SID_ATTR_METRIC, static_cast< sal_uInt16 >(pPref->GetMetric()) )); - pRet->Put(SfxBoolItem(SID_ATTR_APPLYCHARUNIT, pPref->IsApplyCharUnit())); + aRet.Put(SfxUInt16Item( FN_VSCROLL_METRIC, static_cast< sal_uInt16 >(eUnit) )); + aRet.Put(SfxUInt16Item( SID_ATTR_METRIC, static_cast< sal_uInt16 >(pPref->GetMetric()) )); + aRet.Put(SfxBoolItem(SID_ATTR_APPLYCHARUNIT, pPref->IsApplyCharUnit())); if(bTextDialog) { if(pAppView) { const SvxTabStopItem& rDefTabs = pAppView->GetWrtShell().GetDefault(RES_PARATR_TABSTOP); - pRet->Put( SfxUInt16Item( SID_ATTR_DEFTABSTOP, static_cast<sal_uInt16>(::GetTabDist(rDefTabs)))); + aRet.Put( SfxUInt16Item( SID_ATTR_DEFTABSTOP, o3tl::narrowing<sal_uInt16>(::GetTabDist(rDefTabs)))); } else - pRet->Put(SfxUInt16Item( SID_ATTR_DEFTABSTOP, static_cast<sal_uInt16>(convertMm100ToTwip(pPref->GetDefTabInMm100())))); + aRet.Put(SfxUInt16Item( SID_ATTR_DEFTABSTOP, o3tl::toTwips(pPref->GetDefTabInMm100(), o3tl::Length::mm100))); } // Options for GridTabPage @@ -189,34 +190,34 @@ std::unique_ptr<SfxItemSet> SwModule::CreateItemSet( sal_uInt16 nId ) aGridItem.SetGridVisible( aViewOpt.IsGridVisible()); const Size& rSnapSize = aViewOpt.GetSnapSize(); - aGridItem.SetFieldDrawX( static_cast<sal_uInt16>(rSnapSize.Width() )); - aGridItem.SetFieldDrawY( static_cast<sal_uInt16>(rSnapSize.Height())); + aGridItem.SetFieldDrawX( o3tl::narrowing<sal_uInt16>(rSnapSize.Width() )); + aGridItem.SetFieldDrawY( o3tl::narrowing<sal_uInt16>(rSnapSize.Height())); aGridItem.SetFieldDivisionX( aViewOpt.GetDivisionX()); aGridItem.SetFieldDivisionY( aViewOpt.GetDivisionY()); - pRet->Put(aGridItem); + aRet.Put(aGridItem); // Options for PrintTabPage const SwPrintData* pOpt = GetPrtOptions(!bTextDialog); SwAddPrinterItem aAddPrinterItem(*pOpt ); - pRet->Put(aAddPrinterItem); + aRet.Put(aAddPrinterItem); // Options for Web if(!bTextDialog) { - pRet->Put(SvxBrushItem(aViewOpt.GetRetoucheColor(), RES_BACKGROUND)); - pRet->Put(SfxUInt16Item(SID_HTML_MODE, HTMLMODE_ON)); + aRet.Put(SvxBrushItem(aViewOpt.GetRetoucheColor(), RES_BACKGROUND)); + aRet.Put(SfxUInt16Item(SID_HTML_MODE, HTMLMODE_ON)); } - return pRet; + return aRet; } void SwModule::ApplyItemSet( sal_uInt16 nId, const SfxItemSet& rSet ) { bool bTextDialog = nId == SID_SW_EDITOPTIONS; SwView* pAppView = GetView(); - if(pAppView && pAppView->GetViewFrame() != SfxViewFrame::Current()) + if(pAppView && &pAppView->GetViewFrame() != SfxViewFrame::Current()) pAppView = nullptr; if(pAppView) { @@ -229,15 +230,12 @@ void SwModule::ApplyItemSet( sal_uInt16 nId, const SfxItemSet& rSet ) SwViewOption aViewOpt = *GetUsrPref(!bTextDialog); SwMasterUsrPref* pPref = bTextDialog ? m_pUsrPref.get() : m_pWebUsrPref.get(); - const SfxPoolItem* pItem; - SfxBindings *pBindings = pAppView ? &pAppView->GetViewFrame()->GetBindings() + SfxBindings *pBindings = pAppView ? &pAppView->GetViewFrame().GetBindings() : nullptr; // Interpret the page Documentview - if( SfxItemState::SET == rSet.GetItemState( FN_PARAM_DOCDISP, false, &pItem )) + if( const SwDocDisplayItem* pDocDispItem = rSet.GetItemIfSet( FN_PARAM_DOCDISP, false )) { - const SwDocDisplayItem* pDocDispItem = static_cast<const SwDocDisplayItem*>(pItem); - if(!aViewOpt.IsViewMetaChars()) { if( (!aViewOpt.IsTab( true ) && pDocDispItem->m_bTab) || @@ -261,90 +259,69 @@ void SwModule::ApplyItemSet( sal_uInt16 nId, const SfxItemSet& rSet ) } // Elements - interpret Item - std::vector<SwNode*> aFoldedOutlineNdsArray; - bool bShow = false; - if( SfxItemState::SET == rSet.GetItemState( FN_PARAM_ELEM, false, &pItem ) ) + bool bReFoldOutlineFolding = false; + if( const SwElemItem* pElemItem = rSet.GetItemIfSet( FN_PARAM_ELEM, false ) ) { - const SwElemItem* pElemItem = static_cast<const SwElemItem*>(pItem); pElemItem->FillViewOptions( aViewOpt ); - SwWrtShell* pWrtShell = GetActiveWrtShell(); - bShow = pWrtShell->GetViewOptions()->IsShowOutlineContentVisibilityButton(); - bool bTreatSubsChanged = aViewOpt.IsTreatSubOutlineLevelsAsContent() - != pWrtShell->GetViewOptions()->IsTreatSubOutlineLevelsAsContent(); - - // move cursor to top if something with the outline mode changed - if ((bShow != aViewOpt.IsShowOutlineContentVisibilityButton()) || - (pWrtShell->GetViewOptions()->IsTreatSubOutlineLevelsAsContent() != - aViewOpt.IsTreatSubOutlineLevelsAsContent())) + // Outline-folding options + if (SwWrtShell* pWrtShell = GetActiveWrtShell()) { - // move cursor to top of document - if (pWrtShell->IsSelFrameMode()) + bool bIsOutlineFoldingOn = pWrtShell->GetViewOptions()->IsShowOutlineContentVisibilityButton(); + bool bTreatSubsChanged = aViewOpt.IsTreatSubOutlineLevelsAsContent() + != pWrtShell->GetViewOptions()->IsTreatSubOutlineLevelsAsContent(); + if (bIsOutlineFoldingOn && + (!aViewOpt.IsShowOutlineContentVisibilityButton() || bTreatSubsChanged)) { - pWrtShell->UnSelectFrame(); - pWrtShell->LeaveSelFrameMode(); + // Outline-folding options have change which require to show all content. + // Either outline-folding is being switched off or outline-folding is currently on + // and the treat subs option has changed. + pWrtShell->GetView().GetViewFrame().GetDispatcher()->Execute(FN_SHOW_OUTLINECONTENTVISIBILITYBUTTON); + if (bTreatSubsChanged) + bReFoldOutlineFolding = true; // folding method changed, set flag to refold below } - pWrtShell->EnterStdMode(); - pWrtShell->SttEndDoc(true); - } - - if (bShow && (!aViewOpt.IsShowOutlineContentVisibilityButton() || bTreatSubsChanged)) - { - // outline mode options have change which require to show all content - const SwOutlineNodes& rOutlineNds = pWrtShell->GetNodes().GetOutLineNds(); - for (SwOutlineNodes::size_type nPos = 0; nPos < rOutlineNds.size(); ++nPos) + else { - SwNode* pNd = rOutlineNds[nPos]; - if (pNd->IsTextNode()) // should always be true - { - bool bOutlineContentVisibleAttr = true; - pNd->GetTextNode()->GetAttrOutlineContentVisible(bOutlineContentVisibleAttr); - if (!bOutlineContentVisibleAttr) - { - aFoldedOutlineNdsArray.push_back(pNd); - pWrtShell->ToggleOutlineContentVisibility(nPos); - } - } + // Refold needs to be done when outline-folding is being turned on or off + bReFoldOutlineFolding = + pWrtShell->GetViewOptions()->IsShowOutlineContentVisibilityButton() != + aViewOpt.IsShowOutlineContentVisibilityButton(); } } } - if( SfxItemState::SET == rSet.GetItemState(SID_ATTR_METRIC, false, &pItem ) ) + if( const SfxUInt16Item* pMetricItem = rSet.GetItemIfSet(SID_ATTR_METRIC, false ) ) { - SfxGetpApp()->SetOptions(rSet); - PutItem(*pItem); - const SfxUInt16Item* pMetricItem = static_cast<const SfxUInt16Item*>(pItem); + SfxApplication::SetOptions(rSet); + PutItem(*pMetricItem); ::SetDfltMetric(static_cast<FieldUnit>(pMetricItem->GetValue()), !bTextDialog); } - if( SfxItemState::SET == rSet.GetItemState(SID_ATTR_APPLYCHARUNIT, - false, &pItem ) ) + if( const SfxBoolItem* pCharItem = rSet.GetItemIfSet(SID_ATTR_APPLYCHARUNIT, + false ) ) { - SfxGetpApp()->SetOptions(rSet); - const SfxBoolItem* pCharItem = static_cast<const SfxBoolItem*>(pItem); + SfxApplication::SetOptions(rSet); ::SetApplyCharUnit(pCharItem->GetValue(), !bTextDialog); } - if( SfxItemState::SET == rSet.GetItemState(FN_HSCROLL_METRIC, false, &pItem ) ) + if( const SfxUInt16Item* pMetricItem = rSet.GetItemIfSet(FN_HSCROLL_METRIC, false ) ) { - const SfxUInt16Item* pMetricItem = static_cast<const SfxUInt16Item*>(pItem); FieldUnit eUnit = static_cast<FieldUnit>(pMetricItem->GetValue()); pPref->SetHScrollMetric(eUnit); if(pAppView) pAppView->ChangeTabMetric(eUnit); } - if( SfxItemState::SET == rSet.GetItemState(FN_VSCROLL_METRIC, false, &pItem ) ) + if( const SfxUInt16Item* pMetricItem = rSet.GetItemIfSet(FN_VSCROLL_METRIC, false ) ) { - const SfxUInt16Item* pMetricItem = static_cast<const SfxUInt16Item*>(pItem); FieldUnit eUnit = static_cast<FieldUnit>(pMetricItem->GetValue()); pPref->SetVScrollMetric(eUnit); if(pAppView) pAppView->ChangeVRulerMetric(eUnit); } - if( SfxItemState::SET == rSet.GetItemState(SID_ATTR_DEFTABSTOP, false, &pItem ) ) + if( const SfxUInt16Item* pItem = rSet.GetItemIfSet(SID_ATTR_DEFTABSTOP, false ) ) { - sal_uInt16 nTabDist = static_cast<const SfxUInt16Item*>(pItem)->GetValue(); + sal_uInt16 nTabDist = pItem->GetValue(); pPref->SetDefTabInMm100(convertTwipToMm100(nTabDist)); if(pAppView) { @@ -362,10 +339,8 @@ void SwModule::ApplyItemSet( sal_uInt16 nId, const SfxItemSet& rSet ) } // Interpret page Grid Settings - if( SfxItemState::SET == rSet.GetItemState( SID_ATTR_GRID_OPTIONS, false, &pItem )) + if( const SvxGridItem* pGridItem = rSet.GetItemIfSet( SID_ATTR_GRID_OPTIONS, false )) { - const SvxGridItem* pGridItem = static_cast<const SvxGridItem*>(pItem); - aViewOpt.SetSnap( pGridItem->GetUseGridSnap() ); aViewOpt.SetSynchronize(pGridItem->GetSynchronize()); if( aViewOpt.IsGridVisible() != pGridItem->GetGridVisible() ) @@ -388,20 +363,18 @@ void SwModule::ApplyItemSet( sal_uInt16 nId, const SfxItemSet& rSet ) } // Interpret Writer Printer Options - if( SfxItemState::SET == rSet.GetItemState( FN_PARAM_ADDPRINTER, false, &pItem )) + if( const SwAddPrinterItem* pAddPrinterAttr = rSet.GetItemIfSet( FN_PARAM_ADDPRINTER, false ) ) { SwPrintOptions* pOpt = GetPrtOptions(!bTextDialog); if (pOpt) { - const SwAddPrinterItem* pAddPrinterAttr = static_cast<const SwAddPrinterItem*>(pItem); *pOpt = *pAddPrinterAttr; } - } - if( SfxItemState::SET == rSet.GetItemState( FN_PARAM_SHADOWCURSOR, false, &pItem )) + if( const SwShadowCursorItem* pItem = rSet.GetItemIfSet( FN_PARAM_SHADOWCURSOR, false )) { - static_cast<const SwShadowCursorItem*>(pItem)->FillViewOptions( aViewOpt ); + pItem->FillViewOptions( aViewOpt ); if(pBindings) pBindings->Invalidate(FN_SHADOWCURSOR); } @@ -417,31 +390,29 @@ void SwModule::ApplyItemSet( sal_uInt16 nId, const SfxItemSet& rSet ) rWrtSh.AlignAllFormulasToBaseline(); } - if( SfxItemState::SET == rSet.GetItemState( FN_PARAM_CRSR_IN_PROTECTED, false, &pItem )) + if( const SfxBoolItem* pItem = rSet.GetItemIfSet( FN_PARAM_CRSR_IN_PROTECTED, false )) + { + aViewOpt.SetCursorInProtectedArea(pItem->GetValue()); + } + + if (const SwFmtAidsAutoComplItem* pItem = rSet.GetItemIfSet(FN_PARAM_FMT_AIDS_AUTOCOMPL, false)) { - aViewOpt.SetCursorInProtectedArea(static_cast<const SfxBoolItem*>(pItem)->GetValue()); + aViewOpt.SetEncloseWithCharactersOn(pItem->IsEncloseWithCharactersOn()); } // set elements for the current view and shell ApplyUsrPref( aViewOpt, pAppView, bTextDialog? SvViewOpt::DestText : SvViewOpt::DestWeb); // must be done after ApplyUsrPref - if (SfxItemState::SET == rSet.GetItemState(FN_PARAM_ELEM, false)) + if (SfxItemState::SET != rSet.GetItemState(FN_PARAM_ELEM, false)) + return; + + if (bReFoldOutlineFolding) { - if (!GetActiveWrtShell()->GetViewOptions()->IsShowOutlineContentVisibilityButton()) - { - // outline mode is no longer active - // set outline content visible attribute to false for nodes in the array - for (SwNode* pNd : aFoldedOutlineNdsArray) - pNd->GetTextNode()->SetAttrOutlineContentVisible(false); - } - else if (bShow) + if (SwWrtShell* pWrtShell = GetActiveWrtShell()) { - // outline mode remained active - // sub level treatment might have changed - // ToggleOutlineContentVisibility only knows sub level treatment after ApplyUserPref - for (SwNode* pNd : aFoldedOutlineNdsArray) - GetActiveWrtShell()->ToggleOutlineContentVisibility(pNd, true); + pWrtShell->GetView().GetViewFrame().GetDispatcher()->Execute(FN_SHOW_OUTLINECONTENTVISIBILITYBUTTON); + pWrtShell->GetView().GetViewFrame().GetDispatcher()->Execute(FN_SHOW_OUTLINECONTENTVISIBILITYBUTTON); } } } |