update dev300-m58
[ooovba.git] / sfx2 / source / appl / appquit.cxx
blob213abbb8df59511f7504030c90ca3cf810235fe7
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: appquit.cxx,v $
10 * $Revision: 1.45 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sfx2.hxx"
33 #include <basic/basmgr.hxx>
34 #include <basic/sbstar.hxx>
36 #ifdef WIN
37 #define _TL_LANG_SPECIAL
38 #endif
39 #include <svtools/svdde.hxx>
40 #ifndef _MSGBOX_HXX //autogen
41 #include <vcl/msgbox.hxx>
42 #endif
43 #include <svtools/eitem.hxx>
45 #include <svtools/saveopt.hxx>
46 #include <svtools/misccfg.hxx>
48 #ifndef GCC
49 #endif
51 #include "app.hrc"
52 #include <sfx2/app.hxx>
53 #include <sfx2/unoctitm.hxx>
54 #include "appdata.hxx"
55 #include <sfx2/viewsh.hxx>
56 #include <sfx2/dispatch.hxx>
57 #include <sfx2/printer.hxx>
58 #include "arrdecl.hxx"
59 #include "sfxresid.hxx"
60 #include <sfx2/event.hxx>
61 #include <sfx2/macrconf.hxx>
62 #include <sfx2/mnumgr.hxx>
63 #include <sfx2/templdlg.hxx>
64 #include <sfx2/msgpool.hxx>
65 #include <sfx2/docfile.hxx>
66 #include "sfxtypes.hxx"
67 #include "sfxlocal.hrc"
68 #include <sfx2/fcontnr.hxx>
69 #include "nochaos.hxx"
70 #include <sfx2/appuno.hxx>
71 #include <sfx2/doctempl.hxx>
72 #include <sfx2/viewfrm.hxx>
73 #include <sfx2/objsh.hxx>
74 #include <sfx2/docfac.hxx>
75 #include "appbaslib.hxx"
76 #include <basic/basicmanagerrepository.hxx>
78 using ::basic::BasicManagerRepository;
80 #ifndef PRODUCT
81 DECLARE_LIST( SfxFrameWindowFactoryArray_Impl, SfxFrameWindowFactory* )
82 SV_DECL_PTRARR(SfxInitLinkList, Link*, 2, 2)
83 #endif
85 //===================================================================
86 BOOL SfxApplication::QueryExit_Impl()
88 BOOL bQuit = TRUE;
91 BOOL bPrinting = FALSE;
92 for ( SfxViewShell *pViewSh = SfxViewShell::GetFirst();
93 !bPrinting && pViewSh;
94 pViewSh = SfxViewShell::GetNext(*pViewSh) )
96 SfxPrinter *pPrinter = pViewSh->GetPrinter();
97 bPrinting = pPrinter && pPrinter->IsPrinting();
100 if ( bPrinting )
102 // Benutzer fragen, ob abgebrochen werden soll
103 if ( RET_OK == QueryBox( 0, SfxResId( MSG_ISPRINTING_QUERYABORT ) ).Execute() )
105 // alle Jobs canceln
106 for ( SfxViewShell *pViewSh = SfxViewShell::GetFirst();
107 !bPrinting && pViewSh;
108 pViewSh = SfxViewShell::GetNext(*pViewSh) )
110 SfxPrinter *pPrinter = pViewSh->GetPrinter();
111 if ( pPrinter && pPrinter->IsPrinting() )
112 pPrinter->AbortJob();
115 // da das Canceln asynchron ist, Quit erstmal wieder verlassen
116 GetDispatcher_Impl()->Execute( SID_QUITAPP, SFX_CALLMODE_ASYNCHRON );
117 DBG_TRACE( "QueryExit => FALSE (printing)" );
118 return FALSE;
122 // alles canceln was zu canceln ist
123 GetCancelManager()->Cancel(TRUE);
126 SfxObjectShell *pLastDocSh = SfxObjectShell::GetFirst();
127 if ( bQuit )
129 // Jetzt zur Sicherheit auch hidden Frames abr"aumen
130 SfxViewFrame::CloseHiddenFrames_Impl();
131 pLastDocSh = SfxObjectShell::GetFirst();
134 // will trotzdem noch jemand, den man nicht abschiessen kann, die App haben?
135 if ( !bQuit )
137 // nicht wirklich beenden, nur minimieren
138 InfoBox aInfoBox( NULL, SfxResId(MSG_CANT_QUIT) );
139 aInfoBox.Execute();
140 DBG_TRACE( "QueryExit => FALSE (in use)" );
141 return FALSE;
144 return TRUE;
147 //-------------------------------------------------------------------------
149 void SfxApplication::Deinitialize()
151 if ( pAppData_Impl->bDowning )
152 return;
154 StarBASIC::Stop();
156 // ggf. BASIC speichern
157 BasicManager* pBasMgr = BasicManagerRepository::getApplicationBasicManager( false );
158 if ( pBasMgr && pBasMgr->IsModified() )
159 SaveBasicManager();
161 SaveBasicAndDialogContainer();
163 pAppData_Impl->bDowning = TRUE; // wegen Timer aus DecAliveCount und QueryExit
165 DELETEZ( pAppData_Impl->pTemplates );
167 // By definition there shouldn't be any open view frames when we reach
168 // this method. Therefore this call makes no sense and is the source of
169 // some stack traces, which we don't understand.
170 // For more information see:
171 // #123501#
172 //SetViewFrame(0);
173 pAppData_Impl->bDowning = FALSE;
174 DBG_ASSERT( !SfxViewFrame::GetFirst(),
175 "existing SfxViewFrame after Execute" );
176 DBG_ASSERT( !SfxObjectShell::GetFirst(),
177 "existing SfxObjectShell after Execute" );
178 pAppData_Impl->pAppDispat->Pop( *this, SFX_SHELL_POP_UNTIL );
179 pAppData_Impl->pAppDispat->Flush();
180 pAppData_Impl->bDowning = TRUE;
181 pAppData_Impl->pAppDispat->DoDeactivate_Impl( TRUE, NULL );
183 // call derived application-exit
184 Exit();
186 // Controller u."a. freigeben
187 // dabei sollten auch restliche Komponenten ( Beamer! ) verschwinden
188 BasicManagerRepository::resetApplicationBasicManager();
189 pAppData_Impl->pBasicManager->reset( NULL );
190 // this will also delete pBasMgr
192 DBG_ASSERT( pAppData_Impl->pViewFrame == 0, "active foreign ViewFrame" );
194 delete[] pAppData_Impl->pInterfaces, pAppData_Impl->pInterfaces = 0;
196 // free administration managers
197 DELETEZ(pAppData_Impl->pAppDispat);
198 SfxResId::DeleteResMgr();
199 DELETEZ(pAppData_Impl->pOfaResMgr);
201 // ab hier d"urfen keine SvObjects mehr existieren
202 DELETEZ(pAppData_Impl->pMatcher);
204 delete pAppData_Impl->pLabelResMgr;
206 #ifndef PRODUCT
207 DELETEX(pAppData_Impl->pSlotPool);
208 DELETEX(pAppData_Impl->pEventConfig);
209 DELETEX(pAppData_Impl->pMiscConfig);
210 SfxMacroConfig::Release_Impl();
211 DELETEX(pAppData_Impl->pFactArr);
212 DELETEX(pAppData_Impl->pInitLinkList);
213 #endif
215 #ifndef PRODUCT
216 DELETEX(pAppData_Impl->pTbxCtrlFac);
217 DELETEX(pAppData_Impl->pStbCtrlFac);
218 DELETEX(pAppData_Impl->pMenuCtrlFac);
219 DELETEX(pAppData_Impl->pViewFrames);
220 DELETEX(pAppData_Impl->pViewShells);
221 DELETEX(pAppData_Impl->pObjShells);
222 #endif
224 //TODO/CLEANTUP
225 //ReleaseArgs could be used instead!
226 /* This leak is intended !
227 Otherwise the TestTool cant use .uno:QuitApp ...
228 because every destructed ItemSet work's on an already
229 released pool pointer .-)
231 NoChaos::ReleaseItemPool();
233 pAppData_Impl->pPool = NULL;