xref: /aoo42x/main/sfx2/source/appl/appchild.cxx (revision cdf0e10c)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_sfx2.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #ifndef GCC
32*cdf0e10cSrcweir #endif
33*cdf0e10cSrcweir #include <svl/whiter.hxx>
34*cdf0e10cSrcweir #include <svl/eitem.hxx>
35*cdf0e10cSrcweir 
36*cdf0e10cSrcweir #include <sfx2/app.hxx>
37*cdf0e10cSrcweir #include "appdata.hxx"
38*cdf0e10cSrcweir #include "workwin.hxx"
39*cdf0e10cSrcweir #include <sfx2/childwin.hxx>
40*cdf0e10cSrcweir #include "arrdecl.hxx"
41*cdf0e10cSrcweir #include <sfx2/templdlg.hxx>
42*cdf0e10cSrcweir #include <sfx2/request.hxx>
43*cdf0e10cSrcweir #include <sfx2/bindings.hxx>
44*cdf0e10cSrcweir #include <sfx2/dispatch.hxx>
45*cdf0e10cSrcweir #include "sfxtypes.hxx"
46*cdf0e10cSrcweir #include <sfx2/module.hxx>
47*cdf0e10cSrcweir #include <sfx2/sfxsids.hrc>
48*cdf0e10cSrcweir 
49*cdf0e10cSrcweir //=========================================================================
50*cdf0e10cSrcweir 
51*cdf0e10cSrcweir 
52*cdf0e10cSrcweir void SfxApplication::RegisterChildWindow_Impl( SfxModule *pMod, SfxChildWinFactory *pFact )
53*cdf0e10cSrcweir {
54*cdf0e10cSrcweir 	if ( pMod )
55*cdf0e10cSrcweir 	{
56*cdf0e10cSrcweir 		pMod->RegisterChildWindow( pFact );
57*cdf0e10cSrcweir 		return;
58*cdf0e10cSrcweir 	}
59*cdf0e10cSrcweir 
60*cdf0e10cSrcweir 	if (!pAppData_Impl->pFactArr)
61*cdf0e10cSrcweir 		pAppData_Impl->pFactArr = new SfxChildWinFactArr_Impl;
62*cdf0e10cSrcweir 
63*cdf0e10cSrcweir //#ifdef DBG_UTIL
64*cdf0e10cSrcweir 	for (sal_uInt16 nFactory=0; nFactory<pAppData_Impl->pFactArr->Count(); ++nFactory)
65*cdf0e10cSrcweir 	{
66*cdf0e10cSrcweir 		if (pFact->nId ==  (*pAppData_Impl->pFactArr)[nFactory]->nId)
67*cdf0e10cSrcweir 		{
68*cdf0e10cSrcweir 			pAppData_Impl->pFactArr->Remove( nFactory );
69*cdf0e10cSrcweir //			DBG_ERROR("ChildWindow mehrfach registriert!");
70*cdf0e10cSrcweir //			return;
71*cdf0e10cSrcweir 		}
72*cdf0e10cSrcweir 	}
73*cdf0e10cSrcweir //#endif
74*cdf0e10cSrcweir 
75*cdf0e10cSrcweir 	pAppData_Impl->pFactArr->C40_INSERT(
76*cdf0e10cSrcweir 		SfxChildWinFactory, pFact, pAppData_Impl->pFactArr->Count() );
77*cdf0e10cSrcweir }
78*cdf0e10cSrcweir 
79*cdf0e10cSrcweir void SfxApplication::RegisterChildWindowContext_Impl( SfxModule *pMod, sal_uInt16 nId,
80*cdf0e10cSrcweir 		SfxChildWinContextFactory *pFact)
81*cdf0e10cSrcweir {
82*cdf0e10cSrcweir 	SfxChildWinFactArr_Impl *pFactories;
83*cdf0e10cSrcweir 	SfxChildWinFactory *pF = NULL;
84*cdf0e10cSrcweir 	if ( pMod )
85*cdf0e10cSrcweir 	{
86*cdf0e10cSrcweir 		// Modul "ubergeben, ChildwindowFactory dort suchen
87*cdf0e10cSrcweir 		pFactories = pMod->GetChildWinFactories_Impl();
88*cdf0e10cSrcweir 		if ( pFactories )
89*cdf0e10cSrcweir 		{
90*cdf0e10cSrcweir 			sal_uInt16 nCount = pFactories->Count();
91*cdf0e10cSrcweir 			for (sal_uInt16 nFactory=0; nFactory<nCount; ++nFactory)
92*cdf0e10cSrcweir 			{
93*cdf0e10cSrcweir 				SfxChildWinFactory *pFac = (*pFactories)[nFactory];
94*cdf0e10cSrcweir 				if ( nId == pFac->nId )
95*cdf0e10cSrcweir 				{
96*cdf0e10cSrcweir 					// Factory gefunden, Context dort registrieren
97*cdf0e10cSrcweir 					pF = pFac;
98*cdf0e10cSrcweir 					break;
99*cdf0e10cSrcweir 				}
100*cdf0e10cSrcweir 			}
101*cdf0e10cSrcweir 		}
102*cdf0e10cSrcweir 	}
103*cdf0e10cSrcweir 
104*cdf0e10cSrcweir 	if ( !pF )
105*cdf0e10cSrcweir 	{
106*cdf0e10cSrcweir 		// Factory an der Application suchen
107*cdf0e10cSrcweir 		DBG_ASSERT( pAppData_Impl, "Keine AppDaten!" );
108*cdf0e10cSrcweir 		DBG_ASSERT( pAppData_Impl->pFactArr, "Keine Factories!" );
109*cdf0e10cSrcweir 
110*cdf0e10cSrcweir 		pFactories = pAppData_Impl->pFactArr;
111*cdf0e10cSrcweir 		sal_uInt16 nCount = pFactories->Count();
112*cdf0e10cSrcweir 		for (sal_uInt16 nFactory=0; nFactory<nCount; ++nFactory)
113*cdf0e10cSrcweir 		{
114*cdf0e10cSrcweir 			SfxChildWinFactory *pFac = (*pFactories)[nFactory];
115*cdf0e10cSrcweir 			if ( nId == pFac->nId )
116*cdf0e10cSrcweir 			{
117*cdf0e10cSrcweir 				if ( pMod )
118*cdf0e10cSrcweir 				{
119*cdf0e10cSrcweir 					// Wenn der Context von einem Modul registriert wurde,
120*cdf0e10cSrcweir 					// mu\s die ChildwindowFactory auch dort zur Verf"ugung
121*cdf0e10cSrcweir 					// stehen, sonst m"u\ste sich die Contextfactory im DLL-Exit
122*cdf0e10cSrcweir 					// wieder abmelden !
123*cdf0e10cSrcweir 					pF = new SfxChildWinFactory( pFac->pCtor, pFac->nId,
124*cdf0e10cSrcweir 							pFac->nPos );
125*cdf0e10cSrcweir 					pMod->RegisterChildWindow( pF );
126*cdf0e10cSrcweir 				}
127*cdf0e10cSrcweir 				else
128*cdf0e10cSrcweir 					pF = pFac;
129*cdf0e10cSrcweir 				break;
130*cdf0e10cSrcweir 			}
131*cdf0e10cSrcweir 		}
132*cdf0e10cSrcweir 	}
133*cdf0e10cSrcweir 
134*cdf0e10cSrcweir 	if ( pF )
135*cdf0e10cSrcweir 	{
136*cdf0e10cSrcweir 		if ( !pF->pArr )
137*cdf0e10cSrcweir 			pF->pArr = new SfxChildWinContextArr_Impl;
138*cdf0e10cSrcweir 		pF->pArr->C40_INSERT( SfxChildWinContextFactory, pFact, pF->pArr->Count() );
139*cdf0e10cSrcweir 		return;
140*cdf0e10cSrcweir 	}
141*cdf0e10cSrcweir 
142*cdf0e10cSrcweir 	DBG_ERROR( "Kein ChildWindow fuer diesen Context!" );
143*cdf0e10cSrcweir }
144*cdf0e10cSrcweir 
145*cdf0e10cSrcweir //--------------------------------------------------------------------
146*cdf0e10cSrcweir 
147*cdf0e10cSrcweir SfxChildWinFactArr_Impl& SfxApplication::GetChildWinFactories_Impl() const
148*cdf0e10cSrcweir {
149*cdf0e10cSrcweir 	return ( *(pAppData_Impl->pFactArr));
150*cdf0e10cSrcweir }
151*cdf0e10cSrcweir 
152*cdf0e10cSrcweir //--------------------------------------------------------------------
153*cdf0e10cSrcweir 
154*cdf0e10cSrcweir SfxTemplateDialog* SfxApplication::GetTemplateDialog()
155*cdf0e10cSrcweir {
156*cdf0e10cSrcweir     if ( pAppData_Impl->pViewFrame )
157*cdf0e10cSrcweir     {
158*cdf0e10cSrcweir         SfxChildWindow *pChild = pAppData_Impl->pViewFrame->GetChildWindow(SfxTemplateDialogWrapper::GetChildWindowId());
159*cdf0e10cSrcweir         return pChild ? (SfxTemplateDialog*) pChild->GetWindow() : 0;
160*cdf0e10cSrcweir     }
161*cdf0e10cSrcweir 
162*cdf0e10cSrcweir     return NULL;
163*cdf0e10cSrcweir }
164*cdf0e10cSrcweir 
165*cdf0e10cSrcweir //--------------------------------------------------------------------
166*cdf0e10cSrcweir 
167*cdf0e10cSrcweir SfxWorkWindow* SfxApplication::GetWorkWindow_Impl(const SfxViewFrame *pFrame) const
168*cdf0e10cSrcweir {
169*cdf0e10cSrcweir     if ( pFrame )
170*cdf0e10cSrcweir         return pFrame->GetFrame().GetWorkWindow_Impl();
171*cdf0e10cSrcweir     else if ( pAppData_Impl->pViewFrame )
172*cdf0e10cSrcweir         return pAppData_Impl->pViewFrame->GetFrame().GetWorkWindow_Impl();
173*cdf0e10cSrcweir     else
174*cdf0e10cSrcweir         return NULL;
175*cdf0e10cSrcweir }
176*cdf0e10cSrcweir 
177