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