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