xref: /trunk/main/sfx2/source/appl/appchild.cxx (revision d119d52d)
1*d119d52dSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*d119d52dSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*d119d52dSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*d119d52dSAndrew Rist  * distributed with this work for additional information
6*d119d52dSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*d119d52dSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*d119d52dSAndrew Rist  * "License"); you may not use this file except in compliance
9*d119d52dSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*d119d52dSAndrew Rist  *
11*d119d52dSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*d119d52dSAndrew Rist  *
13*d119d52dSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*d119d52dSAndrew Rist  * software distributed under the License is distributed on an
15*d119d52dSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*d119d52dSAndrew Rist  * KIND, either express or implied.  See the License for the
17*d119d52dSAndrew Rist  * specific language governing permissions and limitations
18*d119d52dSAndrew Rist  * under the License.
19*d119d52dSAndrew Rist  *
20*d119d52dSAndrew Rist  *************************************************************/
21*d119d52dSAndrew Rist 
22*d119d52dSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sfx2.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #ifndef GCC
28cdf0e10cSrcweir #endif
29cdf0e10cSrcweir #include <svl/whiter.hxx>
30cdf0e10cSrcweir #include <svl/eitem.hxx>
31cdf0e10cSrcweir 
32cdf0e10cSrcweir #include <sfx2/app.hxx>
33cdf0e10cSrcweir #include "appdata.hxx"
34cdf0e10cSrcweir #include "workwin.hxx"
35cdf0e10cSrcweir #include <sfx2/childwin.hxx>
36cdf0e10cSrcweir #include "arrdecl.hxx"
37cdf0e10cSrcweir #include <sfx2/templdlg.hxx>
38cdf0e10cSrcweir #include <sfx2/request.hxx>
39cdf0e10cSrcweir #include <sfx2/bindings.hxx>
40cdf0e10cSrcweir #include <sfx2/dispatch.hxx>
41cdf0e10cSrcweir #include "sfxtypes.hxx"
42cdf0e10cSrcweir #include <sfx2/module.hxx>
43cdf0e10cSrcweir #include <sfx2/sfxsids.hrc>
44cdf0e10cSrcweir 
45cdf0e10cSrcweir //=========================================================================
46cdf0e10cSrcweir 
47cdf0e10cSrcweir 
RegisterChildWindow_Impl(SfxModule * pMod,SfxChildWinFactory * pFact)48cdf0e10cSrcweir void SfxApplication::RegisterChildWindow_Impl( SfxModule *pMod, SfxChildWinFactory *pFact )
49cdf0e10cSrcweir {
50cdf0e10cSrcweir 	if ( pMod )
51cdf0e10cSrcweir 	{
52cdf0e10cSrcweir 		pMod->RegisterChildWindow( pFact );
53cdf0e10cSrcweir 		return;
54cdf0e10cSrcweir 	}
55cdf0e10cSrcweir 
56cdf0e10cSrcweir 	if (!pAppData_Impl->pFactArr)
57cdf0e10cSrcweir 		pAppData_Impl->pFactArr = new SfxChildWinFactArr_Impl;
58cdf0e10cSrcweir 
59cdf0e10cSrcweir //#ifdef DBG_UTIL
60cdf0e10cSrcweir 	for (sal_uInt16 nFactory=0; nFactory<pAppData_Impl->pFactArr->Count(); ++nFactory)
61cdf0e10cSrcweir 	{
62cdf0e10cSrcweir 		if (pFact->nId ==  (*pAppData_Impl->pFactArr)[nFactory]->nId)
63cdf0e10cSrcweir 		{
64cdf0e10cSrcweir 			pAppData_Impl->pFactArr->Remove( nFactory );
65cdf0e10cSrcweir //			DBG_ERROR("ChildWindow mehrfach registriert!");
66cdf0e10cSrcweir //			return;
67cdf0e10cSrcweir 		}
68cdf0e10cSrcweir 	}
69cdf0e10cSrcweir //#endif
70cdf0e10cSrcweir 
71cdf0e10cSrcweir 	pAppData_Impl->pFactArr->C40_INSERT(
72cdf0e10cSrcweir 		SfxChildWinFactory, pFact, pAppData_Impl->pFactArr->Count() );
73cdf0e10cSrcweir }
74cdf0e10cSrcweir 
RegisterChildWindowContext_Impl(SfxModule * pMod,sal_uInt16 nId,SfxChildWinContextFactory * pFact)75cdf0e10cSrcweir void SfxApplication::RegisterChildWindowContext_Impl( SfxModule *pMod, sal_uInt16 nId,
76cdf0e10cSrcweir 		SfxChildWinContextFactory *pFact)
77cdf0e10cSrcweir {
78cdf0e10cSrcweir 	SfxChildWinFactArr_Impl *pFactories;
79cdf0e10cSrcweir 	SfxChildWinFactory *pF = NULL;
80cdf0e10cSrcweir 	if ( pMod )
81cdf0e10cSrcweir 	{
82cdf0e10cSrcweir 		// Modul "ubergeben, ChildwindowFactory dort suchen
83cdf0e10cSrcweir 		pFactories = pMod->GetChildWinFactories_Impl();
84cdf0e10cSrcweir 		if ( pFactories )
85cdf0e10cSrcweir 		{
86cdf0e10cSrcweir 			sal_uInt16 nCount = pFactories->Count();
87cdf0e10cSrcweir 			for (sal_uInt16 nFactory=0; nFactory<nCount; ++nFactory)
88cdf0e10cSrcweir 			{
89cdf0e10cSrcweir 				SfxChildWinFactory *pFac = (*pFactories)[nFactory];
90cdf0e10cSrcweir 				if ( nId == pFac->nId )
91cdf0e10cSrcweir 				{
92cdf0e10cSrcweir 					// Factory gefunden, Context dort registrieren
93cdf0e10cSrcweir 					pF = pFac;
94cdf0e10cSrcweir 					break;
95cdf0e10cSrcweir 				}
96cdf0e10cSrcweir 			}
97cdf0e10cSrcweir 		}
98cdf0e10cSrcweir 	}
99cdf0e10cSrcweir 
100cdf0e10cSrcweir 	if ( !pF )
101cdf0e10cSrcweir 	{
102cdf0e10cSrcweir 		// Factory an der Application suchen
103cdf0e10cSrcweir 		DBG_ASSERT( pAppData_Impl, "Keine AppDaten!" );
104cdf0e10cSrcweir 		DBG_ASSERT( pAppData_Impl->pFactArr, "Keine Factories!" );
105cdf0e10cSrcweir 
106cdf0e10cSrcweir 		pFactories = pAppData_Impl->pFactArr;
107cdf0e10cSrcweir 		sal_uInt16 nCount = pFactories->Count();
108cdf0e10cSrcweir 		for (sal_uInt16 nFactory=0; nFactory<nCount; ++nFactory)
109cdf0e10cSrcweir 		{
110cdf0e10cSrcweir 			SfxChildWinFactory *pFac = (*pFactories)[nFactory];
111cdf0e10cSrcweir 			if ( nId == pFac->nId )
112cdf0e10cSrcweir 			{
113cdf0e10cSrcweir 				if ( pMod )
114cdf0e10cSrcweir 				{
115cdf0e10cSrcweir 					// Wenn der Context von einem Modul registriert wurde,
116cdf0e10cSrcweir 					// mu\s die ChildwindowFactory auch dort zur Verf"ugung
117cdf0e10cSrcweir 					// stehen, sonst m"u\ste sich die Contextfactory im DLL-Exit
118cdf0e10cSrcweir 					// wieder abmelden !
119cdf0e10cSrcweir 					pF = new SfxChildWinFactory( pFac->pCtor, pFac->nId,
120cdf0e10cSrcweir 							pFac->nPos );
121cdf0e10cSrcweir 					pMod->RegisterChildWindow( pF );
122cdf0e10cSrcweir 				}
123cdf0e10cSrcweir 				else
124cdf0e10cSrcweir 					pF = pFac;
125cdf0e10cSrcweir 				break;
126cdf0e10cSrcweir 			}
127cdf0e10cSrcweir 		}
128cdf0e10cSrcweir 	}
129cdf0e10cSrcweir 
130cdf0e10cSrcweir 	if ( pF )
131cdf0e10cSrcweir 	{
132cdf0e10cSrcweir 		if ( !pF->pArr )
133cdf0e10cSrcweir 			pF->pArr = new SfxChildWinContextArr_Impl;
134cdf0e10cSrcweir 		pF->pArr->C40_INSERT( SfxChildWinContextFactory, pFact, pF->pArr->Count() );
135cdf0e10cSrcweir 		return;
136cdf0e10cSrcweir 	}
137cdf0e10cSrcweir 
138cdf0e10cSrcweir 	DBG_ERROR( "Kein ChildWindow fuer diesen Context!" );
139cdf0e10cSrcweir }
140cdf0e10cSrcweir 
141cdf0e10cSrcweir //--------------------------------------------------------------------
142cdf0e10cSrcweir 
GetChildWinFactories_Impl() const143cdf0e10cSrcweir SfxChildWinFactArr_Impl& SfxApplication::GetChildWinFactories_Impl() const
144cdf0e10cSrcweir {
145cdf0e10cSrcweir 	return ( *(pAppData_Impl->pFactArr));
146cdf0e10cSrcweir }
147cdf0e10cSrcweir 
148cdf0e10cSrcweir //--------------------------------------------------------------------
149cdf0e10cSrcweir 
GetTemplateDialog()150cdf0e10cSrcweir SfxTemplateDialog* SfxApplication::GetTemplateDialog()
151cdf0e10cSrcweir {
152cdf0e10cSrcweir     if ( pAppData_Impl->pViewFrame )
153cdf0e10cSrcweir     {
154cdf0e10cSrcweir         SfxChildWindow *pChild = pAppData_Impl->pViewFrame->GetChildWindow(SfxTemplateDialogWrapper::GetChildWindowId());
155cdf0e10cSrcweir         return pChild ? (SfxTemplateDialog*) pChild->GetWindow() : 0;
156cdf0e10cSrcweir     }
157cdf0e10cSrcweir 
158cdf0e10cSrcweir     return NULL;
159cdf0e10cSrcweir }
160cdf0e10cSrcweir 
161cdf0e10cSrcweir //--------------------------------------------------------------------
162cdf0e10cSrcweir 
GetWorkWindow_Impl(const SfxViewFrame * pFrame) const163cdf0e10cSrcweir SfxWorkWindow* SfxApplication::GetWorkWindow_Impl(const SfxViewFrame *pFrame) const
164cdf0e10cSrcweir {
165cdf0e10cSrcweir     if ( pFrame )
166cdf0e10cSrcweir         return pFrame->GetFrame().GetWorkWindow_Impl();
167cdf0e10cSrcweir     else if ( pAppData_Impl->pViewFrame )
168cdf0e10cSrcweir         return pAppData_Impl->pViewFrame->GetFrame().GetWorkWindow_Impl();
169cdf0e10cSrcweir     else
170cdf0e10cSrcweir         return NULL;
171cdf0e10cSrcweir }
172cdf0e10cSrcweir 
173