diff options
Diffstat (limited to 'sw/source/ui/app')
-rw-r--r-- | sw/source/ui/app/appenv.cxx | 10 | ||||
-rw-r--r-- | sw/source/ui/app/apphdl.cxx | 67 | ||||
-rw-r--r-- | sw/source/ui/app/applab.cxx | 8 | ||||
-rw-r--r-- | sw/source/ui/app/appopt.cxx | 56 |
4 files changed, 80 insertions, 61 deletions
diff --git a/sw/source/ui/app/appenv.cxx b/sw/source/ui/app/appenv.cxx index 63b614a6637a..1f4862a5dece 100644 --- a/sw/source/ui/app/appenv.cxx +++ b/sw/source/ui/app/appenv.cxx @@ -144,7 +144,7 @@ void SwModule::InsertEnv( SfxRequest& rReq ) SwDocShell *pMyDocSh; SfxViewFrame *pFrame; - SwView *pNewView; + rtl::Reference< SwView > pNewView; SwWrtShell *pOldSh, *pSh; @@ -156,7 +156,13 @@ void SwModule::InsertEnv( SfxRequest& rReq ) SfxObjectShellLock xDocSh( new SwDocShell( SFX_CREATE_MODE_STANDARD ) ); xDocSh->DoInitNew( 0 ); pFrame = SfxViewFrame::LoadHiddenDocument( *xDocSh, 0 ); - pNewView = (SwView*) pFrame->GetViewShell(); +#if OSL_DEBUG_LEVEL > 0 + pNewView = dynamic_cast<SwView*>(pFrame->GetViewShell().get()); + assert( ( pNewView.is() && pFrame->GetViewShell().is() ) || + ( !pNewView.is() && !pFrame->GetViewShell().is() )); +#else + pNewView = static_cast<SwView*>(pFrame->GetViewShell().get()); +#endif pNewView->AttrChangedNotify( &pNewView->GetWrtShell() ); // so that SelectShell is being called pSh = pNewView->GetWrtShellPtr(); diff --git a/sw/source/ui/app/apphdl.cxx b/sw/source/ui/app/apphdl.cxx index 8582adb97e48..8eec13f1713f 100644 --- a/sw/source/ui/app/apphdl.cxx +++ b/sw/source/ui/app/apphdl.cxx @@ -101,6 +101,9 @@ using namespace ::com::sun::star; +// TODO: move to rtl/ref.hxx +#define REF_CAST( T, pObj ) \ + ( pObj.is() && (pObj)->IsA( TYPE(T) ) ? (static_cast<T*>(pObj.get())) : 0 ) // Slotmaps for the application's methods @@ -127,8 +130,8 @@ void SwModule::StateOther(SfxItemSet &rSet) SfxWhichIter aIter(rSet); sal_uInt16 nWhich = aIter.FirstWhich(); - SwView* pActView = ::GetActiveView(); - sal_Bool bWebView = 0 != PTR_CAST(SwWebView, pActView); + rtl::Reference< SwView > pActView = ::GetActiveView(); + sal_Bool bWebView = 0 != REF_CAST(SwWebView, pActView); while(nWhich) { @@ -139,8 +142,8 @@ void SwModule::StateOther(SfxItemSet &rSet) case FN_ENVELOP: { bool bDisable = false; - SfxViewShell* pCurrView = SfxViewShell::Current(); - if( !pCurrView || (pCurrView && !pCurrView->ISA(SwView)) ) + rtl::Reference< SfxViewShell > pCurrView = SfxViewShell::Current(); + if( !pCurrView.is() || !pCurrView->ISA(SwView) ) bDisable = true; SwDocShell *pDocSh = (SwDocShell*) SfxObjectShell::Current(); if ( bDisable || @@ -157,7 +160,7 @@ void SwModule::StateOther(SfxItemSet &rSet) { SwWrtShell* pSh = 0; int nSelection = 0; - if( pActView ) + if( pActView.is() ) pSh = &pActView->GetWrtShell(); if( pSh ) nSelection = pSh->GetSelectionType(); @@ -181,9 +184,9 @@ void SwModule::StateOther(SfxItemSet &rSet) } } -static SwView* lcl_LoadDoc(SwView* pView, const OUString& rURL) +static rtl::Reference< SwView > lcl_LoadDoc(rtl::Reference< SwView > pView, const OUString& rURL) { - SwView* pNewView = 0; + rtl::Reference< SwView > pNewView = 0; if(!rURL.isEmpty()) { SfxStringItem aURL(SID_FILE_NAME, rURL); @@ -197,12 +200,12 @@ static SwView* lcl_LoadDoc(SwView* pView, const OUString& rURL) if(pShell) { - SfxViewShell* pViewShell = pShell->GetViewShell(); - if(pViewShell) + rtl::Reference< SfxViewShell > pViewShell = pShell->GetViewShell(); + if(pViewShell.is()) { if( pViewShell->ISA(SwView) ) { - pNewView = PTR_CAST(SwView,pViewShell); + pNewView = REF_CAST(SwView,pViewShell); pNewView->GetViewFrame()->GetFrame().Appear(); } else @@ -220,7 +223,7 @@ static SwView* lcl_LoadDoc(SwView* pView, const OUString& rURL) SFX_CALLMODE_SYNCHRON, &aFactory, 0L); SfxFrame* pFrm = pItem ? pItem->GetFrame() : 0; SfxViewFrame* pFrame = pFrm ? pFrm->GetCurrentViewFrame() : 0; - pNewView = pFrame ? PTR_CAST(SwView, pFrame->GetViewShell()) : 0; + pNewView = pFrame ? REF_CAST(SwView, pFrame->GetViewShell()) : 0; } return pNewView; @@ -234,8 +237,8 @@ namespace class SwMailMergeWizardExecutor : public salhelper::SimpleReferenceObject { - SwView* m_pView; // never owner - SwView* m_pView2Close; // never owner + rtl::Reference< SwView > m_pView; // never owner + rtl::Reference< SwView > m_pView2Close; // never owner SwMailMergeConfigItem* m_pMMConfig; // sometimes owner AbstractMailMergeWizard* m_pWizard; // always owner @@ -271,15 +274,15 @@ SwMailMergeWizardExecutor::~SwMailMergeWizardExecutor() void SwMailMergeWizardExecutor::ExecuteMailMergeWizard( const SfxItemSet * pArgs ) { - if ( m_pView ) + if ( m_pView.is() ) { OSL_FAIL("SwMailMergeWizardExecutor::ExecuteMailMergeWizard: Already executing the wizard!" ); return; } m_pView = ::GetActiveView(); // not owner! - OSL_ENSURE(m_pView, "no current view?"); - if(m_pView) + OSL_ENSURE(m_pView.is(), "no current view?"); + if(m_pView.is()) { // keep self alive until done. acquire(); @@ -400,14 +403,14 @@ IMPL_LINK( SwMailMergeWizardExecutor, EndDialogHdl, AbstractMailMergeWizard*, pD { case RET_LOAD_DOC: { - SwView* pNewView = lcl_LoadDoc(m_pView, m_pWizard->GetReloadDocument()); + rtl::Reference< SwView > pNewView = lcl_LoadDoc(m_pView, m_pWizard->GetReloadDocument()); // destroy wizard asynchronously Application::PostUserEvent( LINK( this, SwMailMergeWizardExecutor, DestroyWizardHdl ), m_pWizard ); SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create(); - if(pNewView) + if(pNewView.is()) { m_pView = pNewView; m_pMMConfig->DocumentReloaded(); @@ -427,11 +430,11 @@ IMPL_LINK( SwMailMergeWizardExecutor, EndDialogHdl, AbstractMailMergeWizard*, pD } case RET_TARGET_CREATED: { - SwView* pTargetView = m_pMMConfig->GetTargetView(); + rtl::Reference< SwView > pTargetView = m_pMMConfig->GetTargetView(); uno::Reference< frame::XFrame > xFrame = m_pView->GetViewFrame()->GetFrame().GetFrameInterface(); xFrame->getContainerWindow()->setVisible(sal_False); - OSL_ENSURE(pTargetView, "No target view has been created"); + OSL_ENSURE(pTargetView.is(), "No target view has been created"); if(pTargetView) { // destroy wizard asynchronously @@ -458,7 +461,7 @@ IMPL_LINK( SwMailMergeWizardExecutor, EndDialogHdl, AbstractMailMergeWizard*, pD //create a non-modal dialog that allows to return to the wizard //the ConfigItem ownership moves to this dialog bool bResult = nRet == RET_EDIT_RESULT_DOC && m_pMMConfig->GetTargetView(); - SwView* pTempView = bResult ? m_pMMConfig->GetTargetView() : m_pMMConfig->GetSourceView(); + rtl::Reference< SwView > pTempView = bResult ? m_pMMConfig->GetTargetView() : m_pMMConfig->GetSourceView(); pTempView->SetMailMergeConfigItem(m_pMMConfig, m_pWizard->GetRestartPage(), !bResult); SfxViewFrame* pViewFrame = pTempView->GetViewFrame(); pViewFrame->GetDispatcher()->Execute( @@ -468,9 +471,9 @@ IMPL_LINK( SwMailMergeWizardExecutor, EndDialogHdl, AbstractMailMergeWizard*, pD } case RET_REMOVE_TARGET: { - SwView* pTargetView = m_pMMConfig->GetTargetView(); - SwView* pSourceView = m_pMMConfig->GetSourceView(); - OSL_ENSURE(pTargetView && pSourceView, "source or target view not available" ); + rtl::Reference< SwView > pTargetView = m_pMMConfig->GetTargetView(); + rtl::Reference< SwView > pSourceView = m_pMMConfig->GetSourceView(); + OSL_ENSURE(pTargetView.is() && pSourceView.is(), "source or target view not available" ); if(pTargetView && pSourceView) { m_pView2Close = pTargetView; @@ -507,7 +510,7 @@ IMPL_LINK( SwMailMergeWizardExecutor, EndDialogHdl, AbstractMailMergeWizard*, pD } default: // finish { - SwView* pSourceView = m_pMMConfig->GetSourceView(); + rtl::Reference< SwView > pSourceView = m_pMMConfig->GetSourceView(); if(pSourceView) { SwDocShell* pDocShell = pSourceView->GetDocShell(); @@ -606,8 +609,8 @@ void SwModule::ExecOther(SfxRequest& rReq) case FUNIT_PICA: case FUNIT_POINT: { - SwView* pActView = ::GetActiveView(); - sal_Bool bWebView = 0 != PTR_CAST(SwWebView, pActView); + rtl::Reference< SwView > pActView = ::GetActiveView(); + sal_Bool bWebView = 0 != REF_CAST(SwWebView, pActView); ::SetDfltMetric(eUnit, bWebView); } break; @@ -618,7 +621,7 @@ void SwModule::ExecOther(SfxRequest& rReq) case FN_SET_MODOPT_TBLNUMFMT: { - sal_Bool bWebView = 0 != PTR_CAST(SwWebView, ::GetActiveView() ), + sal_Bool bWebView = 0 != REF_CAST(SwWebView, ::GetActiveView() ), bSet; if( pArgs && SFX_ITEM_SET == pArgs->GetItemState( @@ -763,8 +766,8 @@ void SwModule::ConfigurationChanged( utl::ConfigurationBroadcaster* pBrdCst, sal const TypeId aSwViewTypeId = TYPE(SwView); const TypeId aSwPreviewTypeId = TYPE(SwPagePreview); const TypeId aSwSrcViewTypeId = TYPE(SwSrcView); - SfxViewShell* pViewShell = SfxViewShell::GetFirst(); - while(pViewShell) + rtl::Reference< SfxViewShell > pViewShell = SfxViewShell::GetFirst(); + while(pViewShell.is()) { if(pViewShell->GetWindow()) { @@ -775,9 +778,9 @@ void SwModule::ConfigurationChanged( utl::ConfigurationBroadcaster* pBrdCst, sal if(bAccessibility) { if(pViewShell->IsA(aSwViewTypeId)) - ((SwView*)pViewShell)->ApplyAccessiblityOptions(*pAccessibilityOptions); + ((SwView*)pViewShell.get())->ApplyAccessiblityOptions(*pAccessibilityOptions); else if(pViewShell->IsA(aSwPreviewTypeId)) - ((SwPagePreview*)pViewShell)->ApplyAccessiblityOptions(*pAccessibilityOptions); + ((SwPagePreview*)pViewShell.get())->ApplyAccessiblityOptions(*pAccessibilityOptions); } pViewShell->GetWindow()->Invalidate(); } diff --git a/sw/source/ui/app/applab.cxx b/sw/source/ui/app/applab.cxx index 9c2574230757..97ab60952aef 100644 --- a/sw/source/ui/app/applab.cxx +++ b/sw/source/ui/app/applab.cxx @@ -194,7 +194,13 @@ void SwModule::InsertLab(SfxRequest& rReq, sal_Bool bLabel) SfxViewFrame* pViewFrame = SfxViewFrame::DisplayNewDocument( *xDocSh, rReq ); - SwView *pNewView = (SwView*) pViewFrame->GetViewShell(); +#if OSL_DEBUG_LEVEL > 0 + rtl::Reference< SwView > pNewView = dynamic_cast<SwView*>(pViewFrame->GetViewShell().get()); + assert( ( pNewView.is() && pViewFrame->GetViewShell().is() ) || + ( !pNewView.is() && !pViewFrame->GetViewShell().is() )); +#else + rtl::Reference< SwView > pNewView = static_cast<SwView*>(pViewFrame->GetViewShell().get()); +#endif pNewView->AttrChangedNotify( &pNewView->GetWrtShell() );// So that SelectShell is being called. // Set document title diff --git a/sw/source/ui/app/appopt.cxx b/sw/source/ui/app/appopt.cxx index 4c1c2415afe2..d52a96d0decb 100644 --- a/sw/source/ui/app/appopt.cxx +++ b/sw/source/ui/app/appopt.cxx @@ -72,6 +72,10 @@ using namespace ::com::sun::star::uno; using namespace ::com::sun::star::lang; +// TODO: move to rtl/ref.hxx +#define REF_CAST( T, pObj ) \ + ( pObj.is() && (pObj)->IsA( TYPE(T) ) ? (static_cast<T*>(pObj.get())) : 0 ) + SfxItemSet* SwModule::CreateItemSet( sal_uInt16 nId ) { bool bTextDialog = (nId == SID_SW_EDITOPTIONS); @@ -80,13 +84,13 @@ SfxItemSet* SwModule::CreateItemSet( sal_uInt16 nId ) SwViewOption aViewOpt = *GetUsrPref(!bTextDialog); SwMasterUsrPref* pPref = bTextDialog ? pUsrPref : pWebUsrPref; // no MakeUsrPref, because only options from textdoks can be used here - SwView* pAppView = GetView(); - if(pAppView && pAppView->GetViewFrame() != SfxViewFrame::Current()) - pAppView = 0; - if(pAppView) + rtl::Reference< SwView > pAppView = GetView(); + if(pAppView.is() && pAppView->GetViewFrame() != SfxViewFrame::Current()) + pAppView.clear(); + if(pAppView.is()) { // if Text then no WebView and vice versa - bool bWebView = 0 != PTR_CAST(SwWebView, pAppView); + bool bWebView = 0 != REF_CAST(SwWebView, pAppView); if( (bWebView && !bTextDialog) ||(!bWebView && bTextDialog)) { aViewOpt = *pAppView->GetWrtShell().GetViewOptions(); @@ -126,7 +130,7 @@ SfxItemSet* SwModule::CreateItemSet( sal_uInt16 nId ) pRet->Put( SfxBoolItem(FN_PARAM_CRSR_IN_PROTECTED, aViewOpt.IsCursorInProtectedArea())); } - if( pAppView ) + if( pAppView.is() ) { SwWrtShell& rWrtShell = pAppView->GetWrtShell(); @@ -169,26 +173,26 @@ SfxItemSet* SwModule::CreateItemSet( sal_uInt16 nId ) } if(bTextDialog) pRet->Put(SwPtrItem(FN_PARAM_STDFONTS, GetStdFontConfig())); - if( PTR_CAST( SwPagePreview, SfxViewShell::Current())!=0) + if( REF_CAST( SwPagePreview, SfxViewShell::Current())!=0) { SfxBoolItem aBool(SfxBoolItem(SID_PRINTPREVIEW, sal_True)); pRet->Put(aBool); } FieldUnit eUnit = pPref->GetHScrollMetric(); - if(pAppView) + if(pAppView.is()) pAppView->GetHRulerMetric(eUnit); pRet->Put(SfxUInt16Item( FN_HSCROLL_METRIC, static_cast< sal_uInt16 >(eUnit))); eUnit = pPref->GetVScrollMetric(); - if(pAppView) + if(pAppView.is()) 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())); if(bTextDialog) { - if(pAppView) + if(pAppView.is()) { const SvxTabStopItem& rDefTabs = (const SvxTabStopItem&)pAppView->GetWrtShell(). @@ -216,7 +220,7 @@ SfxItemSet* SwModule::CreateItemSet( sal_uInt16 nId ) pRet->Put(aGridItem); // Options for PrintTabPage - const SwPrintData* pOpt = pAppView ? + const SwPrintData* pOpt = pAppView.is() ? &pAppView->GetWrtShell().getIDocumentDeviceAccess()->getPrintData() : 0; @@ -240,13 +244,13 @@ SfxItemSet* SwModule::CreateItemSet( sal_uInt16 nId ) void SwModule::ApplyItemSet( sal_uInt16 nId, const SfxItemSet& rSet ) { bool bTextDialog = nId == SID_SW_EDITOPTIONS; - SwView* pAppView = GetView(); - if(pAppView && pAppView->GetViewFrame() != SfxViewFrame::Current()) + rtl::Reference< SwView > pAppView = GetView(); + if(pAppView.is() && pAppView->GetViewFrame() != SfxViewFrame::Current()) pAppView = 0; - if(pAppView) + if(pAppView.is()) { // the text dialog mustn't apply data to the web view and vice versa - bool bWebView = 0 != PTR_CAST(SwWebView, pAppView); + bool bWebView = 0 != REF_CAST(SwWebView, pAppView); if(bWebView == bTextDialog) pAppView = 0; } @@ -255,7 +259,7 @@ void SwModule::ApplyItemSet( sal_uInt16 nId, const SfxItemSet& rSet ) SwMasterUsrPref* pPref = bTextDialog ? pUsrPref : pWebUsrPref; const SfxPoolItem* pItem; - SfxBindings *pBindings = pAppView ? &pAppView->GetViewFrame()->GetBindings() + SfxBindings *pBindings = pAppView.is() ? &pAppView->GetViewFrame()->GetBindings() : NULL; @@ -313,7 +317,7 @@ void SwModule::ApplyItemSet( sal_uInt16 nId, const SfxItemSet& rSet ) const SfxUInt16Item* pMetricItem = (const SfxUInt16Item*)pItem; FieldUnit eUnit = (FieldUnit)pMetricItem->GetValue(); pPref->SetHScrollMetric(eUnit); - if(pAppView) + if(pAppView.is()) pAppView->ChangeTabMetric(eUnit); } @@ -322,7 +326,7 @@ void SwModule::ApplyItemSet( sal_uInt16 nId, const SfxItemSet& rSet ) const SfxUInt16Item* pMetricItem = (const SfxUInt16Item*)pItem; FieldUnit eUnit = (FieldUnit)pMetricItem->GetValue(); pPref->SetVScrollMetric(eUnit); - if(pAppView) + if(pAppView.is()) pAppView->ChangeVRulerMetric(eUnit); } @@ -330,7 +334,7 @@ void SwModule::ApplyItemSet( sal_uInt16 nId, const SfxItemSet& rSet ) { sal_uInt16 nTabDist = ((const SfxUInt16Item*)pItem)->GetValue(); pPref->SetDefTab(nTabDist); - if(pAppView) + if(pAppView.is()) { SvxTabStopItem aDefTabs( 0, 0, SVX_TAB_ADJUST_DEFAULT, RES_PARATR_TABSTOP ); MakeDefTabs( nTabDist, aDefTabs ); @@ -382,7 +386,7 @@ void SwModule::ApplyItemSet( sal_uInt16 nId, const SfxItemSet& rSet ) const SwAddPrinterItem* pAddPrinterAttr = (const SwAddPrinterItem*)pItem; *pOpt = *pAddPrinterAttr; - if(pAppView) + if(pAppView.is()) pAppView->GetWrtShell().getIDocumentDeviceAccess()->setPrintData( *pOpt ); } @@ -395,7 +399,7 @@ void SwModule::ApplyItemSet( sal_uInt16 nId, const SfxItemSet& rSet ) pBindings->Invalidate(FN_SHADOWCURSOR); } - if( pAppView ) + if( pAppView.is() ) { SwWrtShell &rWrtSh = pAppView->GetWrtShell(); const bool bAlignFormulas = rWrtSh.GetDoc()->get( IDocumentSettingAccess::MATH_BASELINE_ALIGNMENT ); @@ -481,11 +485,11 @@ SfxTabPage* SwModule::CreateTabPage( sal_uInt16 nId, Window* pParent, const SfxI if ( fnCreatePage ) pRet = (*fnCreatePage)( pParent, rSet ); } - SwView* pCurrView = GetView(); - if(pCurrView) + rtl::Reference< SwView > pCurrView = GetView(); + if(pCurrView.is()) { // if text then not WebView and vice versa - bool bWebView = 0 != PTR_CAST(SwWebView, pCurrView); + bool bWebView = 0 != REF_CAST(SwWebView, pCurrView); if( (bWebView && RID_SW_TP_HTML_OPTTABLE_PAGE == nId) || (!bWebView && RID_SW_TP_HTML_OPTTABLE_PAGE != nId) ) { @@ -512,8 +516,8 @@ SfxTabPage* SwModule::CreateTabPage( sal_uInt16 nId, Window* pParent, const SfxI } if (pRet && (nId == RID_SW_TP_OPTSHDWCRSR || nId == RID_SW_TP_HTML_OPTSHDWCRSR)) { - SwView* pCurrView = GetView(); - if(pCurrView) + rtl::Reference< SwView > pCurrView = GetView(); + if(pCurrView.is()) { aSet.Put( SwWrtShellItem( SID_WRT_SHELL, pCurrView->GetWrtShellPtr() ) ); pRet->PageCreated(aSet); |