LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/sw/source/ui/app - apphdl.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 104 388 26.8 %
Date: 2013-07-09 Functions: 14 34 41.2 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include <hintids.hxx>
      21             : 
      22             : #include <osl/diagnose.h>
      23             : #include <tools/link.hxx>
      24             : #include <svl/urihelper.hxx>
      25             : #include <unotools/pathoptions.hxx>
      26             : #include <svtools/accessibilityoptions.hxx>
      27             : #include <sfx2/dispatch.hxx>
      28             : #include <sfx2/event.hxx>
      29             : #include <sfx2/objitem.hxx>
      30             : #include <svx/dataaccessdescriptor.hxx>
      31             : #include <svl/srchitem.hxx>
      32             : #include <svtools/colorcfg.hxx>
      33             : #include <svl/eitem.hxx>
      34             : #include <svl/whiter.hxx>
      35             : #include <svl/isethint.hxx>
      36             : #include <sfx2/request.hxx>
      37             : #include <sfx2/fcontnr.hxx>
      38             : #include <svl/stritem.hxx>
      39             : #include <svl/ctloptions.hxx>
      40             : #include <unotools/useroptions.hxx>
      41             : #include <vcl/msgbox.hxx>
      42             : #include <vcl/wrkwin.hxx>
      43             : #include <svx/insctrl.hxx>
      44             : #include <svx/selctrl.hxx>
      45             : #include <com/sun/star/document/UpdateDocMode.hpp>
      46             : #include <sfx2/docfile.hxx>
      47             : #include <svx/xmlsecctrl.hxx>
      48             : #include <navicfg.hxx>
      49             : 
      50             : #include <sfx2/objface.hxx>
      51             : #include <sfx2/app.hxx>
      52             : 
      53             : #include <view.hxx>
      54             : #include <pview.hxx>
      55             : #include <srcview.hxx>
      56             : #include <wrtsh.hxx>
      57             : #include <docsh.hxx>
      58             : #include <cmdid.h>          // Function-Ids
      59             : #include <initui.hxx>
      60             : #include <uitool.hxx>
      61             : #include <swmodule.hxx>
      62             : #include <wdocsh.hxx>
      63             : #include <wview.hxx>
      64             : #include <usrpref.hxx>
      65             : #include <gloslst.hxx>      // SwGlossaryList
      66             : #include <glosdoc.hxx>      // SwGlossaryList
      67             : #include <doc.hxx>
      68             : #include <IDocumentUndoRedo.hxx>
      69             : #include <cfgitems.hxx>
      70             : #include <prtopt.hxx>
      71             : #include <modcfg.hxx>
      72             : #include <globals.h>        // e.g. global Constants
      73             : #include <app.hrc>
      74             : #include <fontcfg.hxx>
      75             : #include <barcfg.hxx>
      76             : #include <uinums.hxx>
      77             : #include <dbconfig.hxx>
      78             : #include <mmconfigitem.hxx>
      79             : #include <mailmergechildwindow.hxx>
      80             : #include <linguistic/lngprops.hxx>
      81             : #include <editeng/unolingu.hxx>
      82             : #include <com/sun/star/beans/XMultiPropertySet.hpp>
      83             : #include <com/sun/star/beans/XFastPropertySet.hpp>
      84             : #include <com/sun/star/beans/XPropertyState.hpp>
      85             : #include <com/sun/star/beans/XPropertyStateChangeListener.hpp>
      86             : #include <com/sun/star/beans/PropertyAttribute.hpp>
      87             : #include <com/sun/star/beans/XPropertyAccess.hpp>
      88             : #include <com/sun/star/beans/XPropertyContainer.hpp>
      89             : #include <com/sun/star/container/XChild.hpp>
      90             : #include <com/sun/star/sdbc/XConnection.hpp>
      91             : #include <com/sun/star/sdbc/XDataSource.hpp>
      92             : #include <swabstdlg.hxx>
      93             : 
      94             : 
      95             : #include <vcl/status.hxx>
      96             : 
      97             : #include "salhelper/simplereferenceobject.hxx"
      98             : #include "rtl/ref.hxx"
      99             : 
     100             : #include <unomid.h>
     101             : 
     102             : using namespace ::com::sun::star;
     103             : 
     104             : 
     105             : // Slotmaps for the application's methods
     106             : 
     107             : // here are the SlotID's being included
     108             : // see Idl-file
     109             : #define SwModule
     110             : #include <sfx2/msg.hxx>
     111             : #include "swslots.hxx"
     112             : #include <cfgid.h>
     113             : 
     114             : #include <shells.hrc>
     115             : 
     116        9901 : SFX_IMPL_INTERFACE( SwModule, SfxModule, SW_RES(RID_SW_NAME) )
     117             : {
     118          33 :     SFX_STATUSBAR_REGISTRATION(SW_RES(CFG_STATUSBAR));
     119          66 :     SFX_OBJECTBAR_REGISTRATION( SFX_OBJECTBAR_APPLICATION |
     120             :             SFX_VISIBILITY_DESKTOP | SFX_VISIBILITY_STANDARD | SFX_VISIBILITY_CLIENT | SFX_VISIBILITY_VIEWER,
     121          33 :             SW_RES(RID_MODULE_TOOLBOX) );
     122          33 : }
     123             : 
     124             : // other states
     125           0 : void SwModule::StateOther(SfxItemSet &rSet)
     126             : {
     127           0 :     SfxWhichIter aIter(rSet);
     128           0 :     sal_uInt16 nWhich = aIter.FirstWhich();
     129             : 
     130           0 :     SwView* pActView = ::GetActiveView();
     131           0 :     sal_Bool bWebView = 0 != PTR_CAST(SwWebView, pActView);
     132             : 
     133           0 :     while(nWhich)
     134             :     {
     135           0 :         switch(nWhich)
     136             :         {
     137             :             case FN_BUSINESS_CARD:
     138             :             case FN_LABEL:
     139             :             case FN_ENVELOP:
     140             :             {
     141           0 :                 bool bDisable = false;
     142           0 :                 SfxViewShell* pCurrView = SfxViewShell::Current();
     143           0 :                 if( !pCurrView || (pCurrView && !pCurrView->ISA(SwView)) )
     144           0 :                     bDisable = true;
     145           0 :                 SwDocShell *pDocSh = (SwDocShell*) SfxObjectShell::Current();
     146           0 :                 if ( bDisable ||
     147           0 :                     (pDocSh &&    (pDocSh->IsReadOnly() ||
     148           0 :                                   pDocSh->GetCreateMode() == SFX_CREATE_MODE_EMBEDDED)) )
     149           0 :                     rSet.DisableItem( nWhich );
     150             : 
     151             :             }
     152           0 :             break;
     153             :             case FN_XFORMS_INIT:
     154             :                 // slot is always active!
     155           0 :                 break;
     156             :             case FN_EDIT_FORMULA:
     157             :                 {
     158           0 :                     SwWrtShell* pSh = 0;
     159           0 :                     int nSelection = 0;
     160           0 :                     if( pActView )
     161           0 :                         pSh = &pActView->GetWrtShell();
     162           0 :                     if( pSh )
     163           0 :                         nSelection = pSh->GetSelectionType();
     164             : 
     165           0 :                     if( (pSh && pSh->HasSelection()) ||
     166           0 :                         !(nSelection & (nsSelectionType::SEL_TXT | nsSelectionType::SEL_TBL)))
     167           0 :                         rSet.DisableItem(nWhich);
     168             :                 }
     169           0 :             break;
     170             :             case SID_ATTR_METRIC:
     171           0 :                 rSet.Put( SfxUInt16Item( SID_ATTR_METRIC, static_cast< sal_uInt16 >(::GetDfltMetric(bWebView))));
     172           0 :             break;
     173             :             case FN_SET_MODOPT_TBLNUMFMT:
     174             :                 rSet.Put( SfxBoolItem( nWhich, pModuleConfig->
     175           0 :                                             IsInsTblFormatNum( bWebView )));
     176           0 :             break;
     177             :             default:
     178             :                 OSL_FAIL("::StateOther: default");
     179             :         }
     180           0 :         nWhich = aIter.NextWhich();
     181           0 :     }
     182           0 : }
     183             : 
     184           0 : static SwView* lcl_LoadDoc(SwView* pView, const String& rURL)
     185             : {
     186           0 :     SwView* pNewView = 0;
     187           0 :     if(rURL.Len())
     188             :     {
     189           0 :         SfxStringItem aURL(SID_FILE_NAME, rURL);
     190           0 :         SfxStringItem aTargetFrameName( SID_TARGETNAME, OUString("_blank") );
     191           0 :         SfxBoolItem aHidden( SID_HIDDEN, sal_True );
     192           0 :         SfxStringItem aReferer(SID_REFERER, pView->GetDocShell()->GetTitle());
     193             :         SfxObjectItem* pItem = (SfxObjectItem*)pView->GetViewFrame()->GetDispatcher()->
     194             :                 Execute(SID_OPENDOC, SFX_CALLMODE_SYNCHRON,
     195           0 :                             &aURL, &aHidden, &aReferer, &aTargetFrameName, 0L);
     196           0 :         SfxShell* pShell = pItem ? pItem->GetShell() : 0;
     197             : 
     198           0 :         if(pShell)
     199             :         {
     200           0 :             SfxViewShell* pViewShell = pShell->GetViewShell();
     201           0 :             if(pViewShell)
     202             :             {
     203           0 :                 if( pViewShell->ISA(SwView) )
     204             :                 {
     205           0 :                     pNewView = PTR_CAST(SwView,pViewShell);
     206           0 :                     pNewView->GetViewFrame()->GetFrame().Appear();
     207             :                 }
     208             :                 else
     209             :                 {
     210           0 :                     pViewShell->GetViewFrame()->DoClose();
     211             :                 }
     212             :             }
     213           0 :         }
     214             :     }
     215             :     else
     216             :     {
     217           0 :         SfxStringItem aFactory(SID_NEWDOCDIRECT, SwDocShell::Factory().GetFilterContainer()->GetName());
     218             :         const SfxFrameItem* pItem = (SfxFrameItem*)
     219             :                             pView->GetViewFrame()->GetDispatcher()->Execute(SID_NEWDOCDIRECT,
     220           0 :                                 SFX_CALLMODE_SYNCHRON, &aFactory, 0L);
     221           0 :         SfxFrame* pFrm = pItem ? pItem->GetFrame() : 0;
     222           0 :         SfxViewFrame* pFrame = pFrm ? pFrm->GetCurrentViewFrame() : 0;
     223           0 :         pNewView = pFrame ? PTR_CAST(SwView, pFrame->GetViewShell()) : 0;
     224             :     }
     225             : 
     226           0 :     return pNewView;
     227             : }
     228             : 
     229             : // start field dialog
     230             : void NewXForms( SfxRequest& rReq ); // implementation: below
     231             : 
     232             : namespace
     233             : {
     234             : 
     235             : class SwMailMergeWizardExecutor : public salhelper::SimpleReferenceObject
     236             : {
     237             :     SwView*                  m_pView;       // never owner
     238             :     SwView*                  m_pView2Close; // never owner
     239             :     SwMailMergeConfigItem*   m_pMMConfig;   // sometimes owner
     240             :     AbstractMailMergeWizard* m_pWizard;     // always owner
     241             : 
     242             :     DECL_LINK( EndDialogHdl, AbstractMailMergeWizard* );
     243             :     DECL_LINK( DestroyDialogHdl, void* );
     244             :     DECL_LINK( DestroyWizardHdl, AbstractMailMergeWizard* );
     245             :     DECL_LINK( CancelHdl, void* );
     246             :     DECL_LINK( CloseFrameHdl, void* );
     247             : 
     248             :     void ExecutionFinished( bool bDeleteConfigItem );
     249             :     void ExecuteWizard();
     250             : 
     251             : public:
     252             :     SwMailMergeWizardExecutor();
     253             :     ~SwMailMergeWizardExecutor();
     254             : 
     255             :     void ExecuteMailMergeWizard( const SfxItemSet * pArgs );
     256             : };
     257             : 
     258           0 : SwMailMergeWizardExecutor::SwMailMergeWizardExecutor()
     259             :     : m_pView( 0 ),
     260             :       m_pView2Close( NULL ),
     261             :       m_pMMConfig( 0 ),
     262           0 :       m_pWizard( 0 )
     263             : {
     264           0 : }
     265             : 
     266           0 : SwMailMergeWizardExecutor::~SwMailMergeWizardExecutor()
     267             : {
     268             :     OSL_ENSURE( m_pWizard == 0, "SwMailMergeWizardExecutor: m_pWizard must be Null!" );
     269             :     OSL_ENSURE( m_pMMConfig == 0, "SwMailMergeWizardExecutor: m_pMMConfig must be Null!" );
     270           0 : }
     271             : 
     272           0 : void SwMailMergeWizardExecutor::ExecuteMailMergeWizard( const SfxItemSet * pArgs )
     273             : {
     274           0 :     if ( m_pView )
     275             :     {
     276             :         OSL_FAIL("SwMailMergeWizardExecutor::ExecuteMailMergeWizard: Already executing the wizard!" );
     277           0 :         return;
     278             :     }
     279             : 
     280           0 :     m_pView = ::GetActiveView(); // not owner!
     281             :     OSL_ENSURE(m_pView, "no current view?");
     282           0 :     if(m_pView)
     283             :     {
     284             :         // keep self alive until done.
     285           0 :         acquire();
     286             : 
     287             :         // if called from the child window - get the config item and close the ChildWindow, then restore
     288             :         // the wizard
     289             :         SwMailMergeChildWindow* pChildWin =
     290           0 :             static_cast<SwMailMergeChildWindow*>(m_pView->GetViewFrame()->GetChildWindow(FN_MAILMERGE_CHILDWINDOW));
     291           0 :         bool bRestoreWizard = false;
     292           0 :         sal_uInt16 nRestartPage = 0;
     293           0 :         if(pChildWin && pChildWin->IsVisible())
     294             :         {
     295           0 :             m_pMMConfig = m_pView->GetMailMergeConfigItem();
     296           0 :             nRestartPage = m_pView->GetMailMergeRestartPage();
     297           0 :             if(m_pView->IsMailMergeSourceView())
     298           0 :                 m_pMMConfig->SetSourceView( m_pView );
     299           0 :             m_pView->SetMailMergeConfigItem(0, 0, sal_True);
     300           0 :             SfxViewFrame* pViewFrame = m_pView->GetViewFrame();
     301           0 :             pViewFrame->ShowChildWindow(FN_MAILMERGE_CHILDWINDOW, sal_False);
     302             :             OSL_ENSURE(m_pMMConfig, "no MailMergeConfigItem available");
     303           0 :             bRestoreWizard = true;
     304             :         }
     305             :         // to make it bullet proof ;-)
     306           0 :         if(!m_pMMConfig)
     307             :         {
     308           0 :             m_pMMConfig = new SwMailMergeConfigItem;
     309           0 :             m_pMMConfig->SetSourceView(m_pView);
     310             : 
     311             :             //set the first used database as default source on the config item
     312           0 :             const SfxPoolItem* pItem = 0;
     313           0 :             if(pArgs && SFX_ITEM_SET == pArgs->GetItemState(
     314           0 :                    FN_PARAM_DATABASE_PROPERTIES, sal_False, &pItem))
     315             :             {
     316             :                 //mailmerge has been called from the database beamer
     317           0 :                 uno::Sequence< beans::PropertyValue> aDBValues;
     318           0 :                 if(static_cast<const SfxUsrAnyItem*>(pItem)->GetValue() >>= aDBValues)
     319             :                 {
     320           0 :                     SwDBData aDBData;
     321           0 :                     svx::ODataAccessDescriptor aDescriptor(aDBValues);
     322           0 :                     aDescriptor[svx::daDataSource]   >>= aDBData.sDataSource;
     323           0 :                     aDescriptor[svx::daCommand]      >>= aDBData.sCommand;
     324           0 :                     aDescriptor[svx::daCommandType]  >>= aDBData.nCommandType;
     325             : 
     326           0 :                     uno::Sequence< uno::Any >                   aSelection;
     327           0 :                     uno::Reference< sdbc::XConnection>          xConnection;
     328           0 :                     uno::Reference< sdbc::XDataSource>          xSource;
     329           0 :                     uno::Reference< sdbcx::XColumnsSupplier>    xColumnsSupplier;
     330           0 :                     if ( aDescriptor.has(svx::daSelection) )
     331           0 :                         aDescriptor[svx::daSelection] >>= aSelection;
     332           0 :                     if ( aDescriptor.has(svx::daConnection) )
     333           0 :                         aDescriptor[svx::daConnection] >>= xConnection;
     334           0 :                     uno::Reference<container::XChild> xChild(xConnection, uno::UNO_QUERY);
     335           0 :                     if(xChild.is())
     336           0 :                         xSource = uno::Reference<sdbc::XDataSource>(
     337           0 :                             xChild->getParent(), uno::UNO_QUERY);
     338             :                     m_pMMConfig->SetCurrentConnection(
     339             :                         xSource, SharedConnection( xConnection, SharedConnection::NoTakeOwnership ),
     340           0 :                         xColumnsSupplier, aDBData);
     341           0 :                 }
     342             :             }
     343             :             else
     344             :             {
     345           0 :                 std::vector<String> aDBNameList;
     346           0 :                 std::vector<String> aAllDBNames;
     347           0 :                 m_pView->GetWrtShell().GetAllUsedDB( aDBNameList, &aAllDBNames );
     348           0 :                 if(!aDBNameList.empty())
     349             :                 {
     350           0 :                     String sDBName(aDBNameList[0]);
     351           0 :                     SwDBData aDBData;
     352           0 :                     aDBData.sDataSource = sDBName.GetToken(0, DB_DELIM);
     353           0 :                     aDBData.sCommand = sDBName.GetToken(1, DB_DELIM);
     354           0 :                     aDBData.nCommandType = sDBName.GetToken(2, DB_DELIM ).ToInt32();
     355             :                     //set the currently used database for the wizard
     356           0 :                     m_pMMConfig->SetCurrentDBData( aDBData );
     357           0 :                 }
     358             :             }
     359             :         }
     360             : 
     361           0 :         SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
     362           0 :         m_pWizard = pFact->CreateMailMergeWizard(*m_pView, *m_pMMConfig);
     363             : 
     364           0 :         if(bRestoreWizard)
     365             :         {
     366           0 :             m_pWizard->ShowPage( nRestartPage );
     367             :         }
     368             : 
     369           0 :         ExecuteWizard();
     370             :     }
     371             : }
     372             : 
     373           0 : void SwMailMergeWizardExecutor::ExecutionFinished( bool bDeleteConfigItem )
     374             : {
     375           0 :     m_pMMConfig->Commit();
     376           0 :     if ( bDeleteConfigItem ) // owner?
     377           0 :         delete m_pMMConfig;
     378             : 
     379           0 :     m_pMMConfig = 0;
     380             : 
     381             :     // release/destroy asynchronously
     382           0 :     Application::PostUserEvent( LINK( this, SwMailMergeWizardExecutor, DestroyDialogHdl ) );
     383           0 : }
     384             : 
     385           0 : void SwMailMergeWizardExecutor::ExecuteWizard()
     386             : {
     387             :     m_pWizard->StartExecuteModal(
     388           0 :         LINK( this, SwMailMergeWizardExecutor, EndDialogHdl ) );
     389           0 : }
     390             : 
     391           0 : IMPL_LINK( SwMailMergeWizardExecutor, EndDialogHdl, AbstractMailMergeWizard*, pDialog )
     392             : {
     393             :     OSL_ENSURE( pDialog == m_pWizard, "wrong dialog passed to EndDialogHdl!" );
     394             :     (void) pDialog;
     395             : 
     396           0 :     long nRet = m_pWizard->GetResult();
     397           0 :     sal_uInt16 nRestartPage = m_pWizard->GetRestartPage();
     398             : 
     399           0 :     switch ( nRet )
     400             :     {
     401             :     case RET_LOAD_DOC:
     402             :         {
     403           0 :             SwView* pNewView = lcl_LoadDoc(m_pView, m_pWizard->GetReloadDocument());
     404             : 
     405             :             // destroy wizard asynchronously
     406             :             Application::PostUserEvent(
     407           0 :                 LINK( this, SwMailMergeWizardExecutor, DestroyWizardHdl ), m_pWizard );
     408             : 
     409           0 :             SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
     410           0 :             if(pNewView)
     411             :             {
     412           0 :                 m_pView = pNewView;
     413           0 :                 m_pMMConfig->DocumentReloaded();
     414             :                 //new source view!
     415           0 :                 m_pMMConfig->SetSourceView( m_pView );
     416           0 :                 m_pWizard = pFact->CreateMailMergeWizard(*m_pView, *m_pMMConfig);
     417           0 :                 m_pWizard->ShowPage( nRestartPage );
     418             :             }
     419             :             else
     420             :             {
     421           0 :                 m_pWizard = pFact->CreateMailMergeWizard(*m_pView, *m_pMMConfig);
     422             :             }
     423             : 
     424             :             // execute the wizard again
     425           0 :             ExecuteWizard();
     426           0 :             break;
     427             :         }
     428             :     case RET_TARGET_CREATED:
     429             :         {
     430           0 :             SwView* pTargetView = m_pMMConfig->GetTargetView();
     431             :             uno::Reference< frame::XFrame > xFrame =
     432           0 :                 m_pView->GetViewFrame()->GetFrame().GetFrameInterface();
     433           0 :             xFrame->getContainerWindow()->setVisible(sal_False);
     434             :             OSL_ENSURE(pTargetView, "No target view has been created");
     435           0 :             if(pTargetView)
     436             :             {
     437             :                 // destroy wizard asynchronously
     438             :                 Application::PostUserEvent(
     439           0 :                     LINK( this, SwMailMergeWizardExecutor, DestroyWizardHdl ), m_pWizard );
     440             : 
     441           0 :                 SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
     442           0 :                 m_pWizard = pFact->CreateMailMergeWizard(*pTargetView, *m_pMMConfig);
     443           0 :                 m_pWizard->ShowPage( nRestartPage );
     444             : 
     445             :                 // execute the wizard again
     446           0 :                 ExecuteWizard();
     447             :             }
     448             :             else
     449             :             {
     450             :                 // should not happen - just in case no target view has been created
     451           0 :                 ExecutionFinished( true );
     452             :             }
     453           0 :             break;
     454             :         }
     455             :     case RET_EDIT_DOC:
     456             :     case RET_EDIT_RESULT_DOC:
     457             :         {
     458             :             //create a non-modal dialog that allows to return to the wizard
     459             :             //the ConfigItem ownership moves to this dialog
     460           0 :             bool bResult = nRet == RET_EDIT_RESULT_DOC && m_pMMConfig->GetTargetView();
     461           0 :             SwView* pTempView = bResult ? m_pMMConfig->GetTargetView() : m_pMMConfig->GetSourceView();
     462           0 :             pTempView->SetMailMergeConfigItem(m_pMMConfig, m_pWizard->GetRestartPage(), !bResult);
     463           0 :             SfxViewFrame* pViewFrame = pTempView->GetViewFrame();
     464             :             pViewFrame->GetDispatcher()->Execute(
     465           0 :                 FN_MAILMERGE_CHILDWINDOW, SFX_CALLMODE_SYNCHRON);
     466           0 :             ExecutionFinished( false );
     467           0 :             break;
     468             :         }
     469             :     case RET_REMOVE_TARGET:
     470             :         {
     471           0 :             SwView* pTargetView = m_pMMConfig->GetTargetView();
     472           0 :             SwView* pSourceView = m_pMMConfig->GetSourceView();
     473             :             OSL_ENSURE(pTargetView && pSourceView, "source or target view not available" );
     474           0 :             if(pTargetView && pSourceView)
     475             :             {
     476           0 :                 m_pView2Close = pTargetView;
     477           0 :                 pTargetView->GetViewFrame()->GetTopViewFrame()->GetWindow().Hide();
     478           0 :                 pSourceView->GetViewFrame()->GetFrame().AppearWithUpdate();
     479             :                 // the current view has be be set when the target is destroyed
     480           0 :                 m_pView = pSourceView;
     481           0 :                 m_pMMConfig->SetTargetView(0);
     482             : 
     483             :                 // destroy wizard asynchronously
     484             :                 Application::PostUserEvent(
     485           0 :                     LINK( this, SwMailMergeWizardExecutor, CloseFrameHdl ), m_pWizard );
     486             : 
     487           0 :                 SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
     488           0 :                 m_pWizard = pFact->CreateMailMergeWizard(*pSourceView, *m_pMMConfig);
     489           0 :                 m_pWizard->ShowPage( nRestartPage );
     490             : 
     491             :                 // execute the wizard again
     492           0 :                 ExecuteWizard();
     493             :             }
     494             :             else
     495             :             {
     496             :                 // should not happen - just in case no target view has been created
     497           0 :                 ExecutionFinished( true );
     498             :             }
     499           0 :             break;
     500             :         }
     501             :     case RET_CANCEL:
     502             :         {
     503             :             // close frame and destroy wizard asynchronously
     504             :             Application::PostUserEvent(
     505           0 :                 LINK( this, SwMailMergeWizardExecutor, CancelHdl ), m_pWizard );
     506           0 :             break;
     507             :         }
     508             :     default: // finish
     509             :         {
     510           0 :             SwView* pSourceView = m_pMMConfig->GetSourceView();
     511           0 :             if(pSourceView)
     512             :             {
     513           0 :                 SwDocShell* pDocShell = pSourceView->GetDocShell();
     514           0 :                 if(pDocShell->HasName() && !pDocShell->IsModified())
     515           0 :                     m_pMMConfig->GetSourceView()->GetViewFrame()->DoClose();
     516             :                 else
     517           0 :                     m_pMMConfig->GetSourceView()->GetViewFrame()->GetFrame().Appear();
     518             :             }
     519           0 :             ExecutionFinished( true );
     520           0 :             break;
     521             :         }
     522             : 
     523             :     } // switch
     524             : 
     525           0 :     return 0L;
     526             : }
     527             : 
     528           0 : IMPL_LINK_NOARG(SwMailMergeWizardExecutor, DestroyDialogHdl)
     529             : {
     530           0 :     delete m_pWizard;
     531           0 :     m_pWizard = 0;
     532             : 
     533           0 :     release();
     534           0 :     return 0L;
     535             : }
     536             : 
     537           0 : IMPL_LINK( SwMailMergeWizardExecutor, DestroyWizardHdl, AbstractMailMergeWizard*, pDialog )
     538             : {
     539           0 :     delete pDialog;
     540           0 :     return 0L;
     541             : }
     542             : 
     543           0 : IMPL_LINK_NOARG(SwMailMergeWizardExecutor, CancelHdl)
     544             : {
     545           0 :     if(m_pMMConfig->GetTargetView())
     546             :     {
     547           0 :         m_pMMConfig->GetTargetView()->GetViewFrame()->DoClose();
     548           0 :         m_pMMConfig->SetTargetView(0);
     549             :     }
     550           0 :     if(m_pMMConfig->GetSourceView())
     551           0 :         m_pMMConfig->GetSourceView()->GetViewFrame()->GetFrame().AppearWithUpdate();
     552             : 
     553           0 :     m_pMMConfig->Commit();
     554           0 :     delete m_pMMConfig;
     555           0 :     m_pMMConfig = 0;
     556             :     // m_pWizard already deleted by closing the target view
     557           0 :     m_pWizard = 0;
     558           0 :     release();
     559             : 
     560           0 :     return 0L;
     561             : }
     562             : 
     563           0 : IMPL_LINK_NOARG(SwMailMergeWizardExecutor, CloseFrameHdl)
     564             : {
     565           0 :     if ( m_pView2Close )
     566             :     {
     567           0 :         m_pView2Close->GetViewFrame()->DoClose();
     568           0 :         m_pView2Close = NULL;
     569             :     }
     570             : 
     571           0 :     return 0L;
     572             : }
     573             : 
     574             : } // namespace
     575             : 
     576           0 : void SwModule::ExecOther(SfxRequest& rReq)
     577             : {
     578           0 :     const SfxItemSet *pArgs = rReq.GetArgs();
     579           0 :     const SfxPoolItem* pItem = 0;
     580             : 
     581           0 :     sal_uInt16 nWhich = rReq.GetSlot();
     582           0 :     switch (nWhich)
     583             :     {
     584             :         case FN_ENVELOP:
     585           0 :             InsertEnv( rReq );
     586           0 :             break;
     587             : 
     588             :         case FN_BUSINESS_CARD:
     589             :         case FN_LABEL:
     590           0 :             InsertLab(rReq, nWhich == FN_LABEL);
     591           0 :             break;
     592             : 
     593             :         case FN_XFORMS_INIT:
     594           0 :             NewXForms( rReq );
     595           0 :             break;
     596             : 
     597             :         case SID_ATTR_METRIC:
     598           0 :         if(pArgs && SFX_ITEM_SET == pArgs->GetItemState(nWhich, sal_False, &pItem))
     599             :         {
     600           0 :             FieldUnit eUnit = (FieldUnit)((const SfxUInt16Item*)pItem)->GetValue();
     601           0 :             switch( eUnit )
     602             :             {
     603             :                 case FUNIT_MM:
     604             :                 case FUNIT_CM:
     605             :                 case FUNIT_INCH:
     606             :                 case FUNIT_PICA:
     607             :                 case FUNIT_POINT:
     608             :                 {
     609           0 :                     SwView* pActView = ::GetActiveView();
     610           0 :                     sal_Bool bWebView = 0 != PTR_CAST(SwWebView, pActView);
     611           0 :                     ::SetDfltMetric(eUnit, bWebView);
     612             :                 }
     613           0 :                 break;
     614             :                 default:;//prevent warning
     615             :             }
     616             :         }
     617           0 :         break;
     618             : 
     619             :         case FN_SET_MODOPT_TBLNUMFMT:
     620             :             {
     621           0 :                 sal_Bool bWebView = 0 != PTR_CAST(SwWebView, ::GetActiveView() ),
     622             :                      bSet;
     623             : 
     624           0 :                 if( pArgs && SFX_ITEM_SET == pArgs->GetItemState(
     625           0 :                         nWhich, sal_False, &pItem ))
     626           0 :                     bSet = ((SfxBoolItem*)pItem)->GetValue();
     627             :                 else
     628           0 :                     bSet = !pModuleConfig->IsInsTblFormatNum( bWebView );
     629             : 
     630           0 :                 pModuleConfig->SetInsTblFormatNum( bWebView, bSet );
     631             :             }
     632           0 :             break;
     633             :         case FN_MAILMERGE_WIZARD:
     634             :         {
     635           0 :             rtl::Reference< SwMailMergeWizardExecutor > xEx( new SwMailMergeWizardExecutor );
     636           0 :             xEx->ExecuteMailMergeWizard( pArgs );
     637             :         }
     638           0 :         break;
     639             :     }
     640           0 : }
     641             : 
     642             : // Catch notifications
     643             : 
     644             : // Catch hint for DocInfo
     645        9100 : void SwModule::Notify( SfxBroadcaster& /*rBC*/, const SfxHint& rHint )
     646             : {
     647        9100 :     if( rHint.ISA( SfxEventHint ) )
     648             :     {
     649        8587 :         SfxEventHint& rEvHint = (SfxEventHint&) rHint;
     650        8587 :         SwDocShell* pDocSh = PTR_CAST( SwDocShell, rEvHint.GetObjShell() );
     651        8587 :         if( pDocSh )
     652             :         {
     653        6770 :             SwWrtShell* pWrtSh = pDocSh->GetWrtShell();
     654        6770 :             switch( rEvHint.GetEventId() )
     655             :             {
     656             :             case SFX_EVENT_LOADFINISHED:
     657             :                 OSL_ASSERT(!pWrtSh);
     658             :                 // if it is a new document created from a template,
     659             :                 // update fixed fields
     660         446 :                 if (pDocSh->GetMedium())
     661             :                 {
     662         446 :                     SFX_ITEMSET_ARG( pDocSh->GetMedium()->GetItemSet(),
     663             :                         pTemplateItem, SfxBoolItem,
     664             :                         SID_TEMPLATE, sal_False);
     665         446 :                     if (pTemplateItem && pTemplateItem->GetValue())
     666             :                     {
     667          13 :                         pDocSh->GetDoc()->SetFixFields(false, 0);
     668             :                     }
     669             :                 }
     670             :             case SFX_EVENT_CREATEDOC:
     671             :                 // Update all FIX-Date/Time fields
     672         818 :                 if( pWrtSh )
     673             :                 {
     674         372 :                     SFX_ITEMSET_ARG( pDocSh->GetMedium()->GetItemSet(), pUpdateDocItem, SfxUInt16Item, SID_UPDATEDOCMODE, sal_False);
     675         372 :                     bool bUpdateFields = true;
     676         372 :                     if( pUpdateDocItem &&  pUpdateDocItem->GetValue() == document::UpdateDocMode::NO_UPDATE)
     677         372 :                         bUpdateFields = false;
     678         372 :                     if(bUpdateFields)
     679             :                     {
     680           0 :                         pWrtSh->UpdateInputFlds();
     681             : 
     682             :                         // Are database fields contained?
     683             :                         // Get all used databases for the first time
     684           0 :                         SwDoc *pDoc = pDocSh->GetDoc();
     685           0 :                         std::vector<String> aDBNameList;
     686           0 :                         pDoc->GetAllUsedDB( aDBNameList );
     687           0 :                         if(!aDBNameList.empty())
     688             :                         {   // Open database beamer
     689           0 :                             ShowDBObj(pWrtSh->GetView(), pDoc->GetDBData());
     690           0 :                         }
     691             :                     }
     692             :                 }
     693         818 :                 break;
     694             :             }
     695             :         }
     696             :     }
     697         513 :     else if(rHint.ISA(SfxItemSetHint))
     698             :     {
     699           0 :         if( SFX_ITEM_SET == ((SfxItemSetHint&)rHint).GetItemSet().GetItemState(SID_ATTR_PATHNAME))
     700             :         {
     701           0 :             ::GetGlossaries()->UpdateGlosPath( sal_False );
     702           0 :             SwGlossaryList* pList = ::GetGlossaryList();
     703           0 :             if(pList->IsActive())
     704           0 :                 pList->Update();
     705             :         }
     706             :     }
     707         513 :     else if(rHint.ISA(SfxSimpleHint))
     708             :     {
     709         513 :         sal_uInt16 nHintId = ((SfxSimpleHint&)rHint).GetId();
     710         513 :         if(SFX_HINT_DEINITIALIZING == nHintId)
     711             :         {
     712          20 :             DELETEZ(pWebUsrPref);
     713          20 :             DELETEZ(pUsrPref)   ;
     714          20 :             DELETEZ(pModuleConfig);
     715          20 :             DELETEZ(pPrtOpt)      ;
     716          20 :             DELETEZ(pWebPrtOpt)   ;
     717          20 :             DELETEZ(pChapterNumRules);
     718          20 :             DELETEZ(pStdFontConfig)     ;
     719          20 :             DELETEZ(pNavigationConfig)  ;
     720          20 :             DELETEZ(pToolbarConfig)     ;
     721          20 :             DELETEZ(pWebToolbarConfig)  ;
     722          20 :             DELETEZ(pAuthorNames)       ;
     723          20 :             DELETEZ(pDBConfig);
     724          20 :             if( pColorConfig )
     725             :             {
     726          20 :                 pColorConfig->RemoveListener(this);
     727          20 :                 DELETEZ(pColorConfig);
     728             :             }
     729          20 :             if( pAccessibilityOptions )
     730             :             {
     731          20 :                 pAccessibilityOptions->RemoveListener(this);
     732          20 :                 DELETEZ(pAccessibilityOptions);
     733             :             }
     734          20 :             if( pCTLOptions )
     735             :             {
     736          20 :                 pCTLOptions->RemoveListener(this);
     737          20 :                 DELETEZ(pCTLOptions);
     738             :             }
     739          20 :             if( pUserOptions )
     740             :             {
     741          20 :                 pUserOptions->RemoveListener(this);
     742          20 :                 DELETEZ(pUserOptions);
     743             :             }
     744             :         }
     745             :     }
     746        9100 : }
     747             : 
     748          24 : void SwModule::ConfigurationChanged( utl::ConfigurationBroadcaster* pBrdCst, sal_uInt32 )
     749             : {
     750          24 :     if( pBrdCst == pUserOptions )
     751             :     {
     752           0 :         bAuthorInitialised = sal_False;
     753             :     }
     754          24 :     else if ( pBrdCst == pColorConfig || pBrdCst == pAccessibilityOptions )
     755             :     {
     756          24 :         bool bAccessibility = false;
     757          24 :         if( pBrdCst == pColorConfig )
     758          24 :             SwViewOption::ApplyColorConfigValues(*pColorConfig);
     759             :         else
     760           0 :             bAccessibility = true;
     761             : 
     762             :         //invalidate all edit windows
     763          24 :         const TypeId aSwViewTypeId = TYPE(SwView);
     764          24 :         const TypeId aSwPreViewTypeId = TYPE(SwPagePreView);
     765          24 :         const TypeId aSwSrcViewTypeId = TYPE(SwSrcView);
     766          24 :         SfxViewShell* pViewShell = SfxViewShell::GetFirst();
     767          72 :         while(pViewShell)
     768             :         {
     769          24 :             if(pViewShell->GetWindow())
     770             :             {
     771          48 :                 if((pViewShell->IsA(aSwViewTypeId) ||
     772          24 :                     pViewShell->IsA(aSwPreViewTypeId) ||
     773           0 :                     pViewShell->IsA(aSwSrcViewTypeId)))
     774             :                 {
     775          24 :                     if(bAccessibility)
     776             :                     {
     777           0 :                         if(pViewShell->IsA(aSwViewTypeId))
     778           0 :                             ((SwView*)pViewShell)->ApplyAccessiblityOptions(*pAccessibilityOptions);
     779           0 :                         else if(pViewShell->IsA(aSwPreViewTypeId))
     780           0 :                             ((SwPagePreView*)pViewShell)->ApplyAccessiblityOptions(*pAccessibilityOptions);
     781             :                     }
     782          24 :                     pViewShell->GetWindow()->Invalidate();
     783             :                 }
     784             :             }
     785          24 :             pViewShell = SfxViewShell::GetNext( *pViewShell );
     786          24 :         }
     787             :     }
     788           0 :     else if( pBrdCst == pCTLOptions )
     789             :     {
     790           0 :         const SfxObjectShell* pObjSh = SfxObjectShell::GetFirst();
     791           0 :         while( pObjSh )
     792             :         {
     793           0 :             if( pObjSh->IsA(TYPE(SwDocShell)) )
     794             :             {
     795           0 :                 const SwDoc* pDoc = ((SwDocShell*)pObjSh)->GetDoc();
     796           0 :                 ViewShell* pVSh = 0;
     797           0 :                 pDoc->GetEditShell( &pVSh );
     798           0 :                 if ( pVSh )
     799           0 :                     pVSh->ChgNumberDigits();
     800             :             }
     801           0 :             pObjSh = SfxObjectShell::GetNext(*pObjSh);
     802             :         }
     803             :     }
     804             : 
     805          24 : }
     806             : 
     807         195 : SwDBConfig* SwModule::GetDBConfig()
     808             : {
     809         195 :     if(!pDBConfig)
     810          17 :         pDBConfig = new SwDBConfig;
     811         195 :     return pDBConfig;
     812             : }
     813             : 
     814          33 : svtools::ColorConfig& SwModule::GetColorConfig()
     815             : {
     816          33 :     if(!pColorConfig)
     817             :     {
     818          33 :         pColorConfig = new svtools::ColorConfig;
     819          33 :         SwViewOption::ApplyColorConfigValues(*pColorConfig);
     820          33 :         pColorConfig->AddListener(this);
     821             :     }
     822          33 :     return *pColorConfig;
     823             : }
     824             : 
     825        1635 : SvtAccessibilityOptions& SwModule::GetAccessibilityOptions()
     826             : {
     827        1635 :     if(!pAccessibilityOptions)
     828             :     {
     829          33 :         pAccessibilityOptions = new SvtAccessibilityOptions;
     830          33 :         pAccessibilityOptions->AddListener(this);
     831             :     }
     832        1635 :     return *pAccessibilityOptions;
     833             : }
     834             : 
     835       38627 : SvtCTLOptions& SwModule::GetCTLOptions()
     836             : {
     837       38627 :     if(!pCTLOptions)
     838             :     {
     839          32 :         pCTLOptions = new SvtCTLOptions;
     840          32 :         pCTLOptions->AddListener(this);
     841             :     }
     842       38627 :     return *pCTLOptions;
     843             : }
     844             : 
     845         965 : SvtUserOptions& SwModule::GetUserOptions()
     846             : {
     847         965 :     if(!pUserOptions)
     848             :     {
     849          31 :         pUserOptions = new SvtUserOptions;
     850          31 :         pUserOptions->AddListener(this);
     851             :     }
     852         965 :     return *pUserOptions;
     853             : }
     854             : 
     855        5269 : const SwMasterUsrPref *SwModule::GetUsrPref(sal_Bool bWeb) const
     856             : {
     857        5269 :     SwModule* pNonConstModule = (SwModule*)this;
     858        5269 :     if(bWeb && !pWebUsrPref)
     859             :     {
     860             :         // The SpellChecker is needed in SwMasterUsrPref's Load, but it must not
     861             :         // be created there #58256#
     862           1 :         pNonConstModule->pWebUsrPref = new SwMasterUsrPref(sal_True);
     863             :     }
     864        5268 :     else if(!bWeb && !pUsrPref)
     865             :     {
     866          33 :         pNonConstModule->pUsrPref = new SwMasterUsrPref(sal_False);
     867             :     }
     868        5269 :     return  bWeb ? pWebUsrPref : pUsrPref;
     869             : }
     870             : 
     871             : 
     872             : 
     873           0 : void NewXForms( SfxRequest& rReq )
     874             : {
     875             :     // copied & excerpted from SwModule::InsertLab(..)
     876             : 
     877             :     // create new document
     878           0 :     SfxObjectShellLock xDocSh( new SwDocShell( SFX_CREATE_MODE_STANDARD) );
     879           0 :     xDocSh->DoInitNew( 0 );
     880             : 
     881             :     // initialize XForms
     882           0 :     static_cast<SwDocShell*>( &xDocSh )->GetDoc()->initXForms( true );
     883             : 
     884             :     // load document into frame
     885           0 :     SfxViewFrame::DisplayNewDocument( *xDocSh, rReq );
     886             : 
     887             :     // set return value
     888           0 :     rReq.SetReturnValue( SfxVoidItem( rReq.GetSlot() ) );
     889          99 : }
     890             : 
     891             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10