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