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