xref: /AOO41X/main/framework/source/application/framework.cxx (revision 6d739b60ff8f4ed2134ae1442e284f9da90334b4)
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_framework.hxx"
26 
27 //_________________________________________________________________________________________________________________
28 //  my own includes
29 //_________________________________________________________________________________________________________________
30 
31 #ifndef __FRAMEWORK_HELPER_OINSTANCEPROVIDER_HXX_
32 #include <helper/oinstanceprovider.hxx>
33 #endif
34 #include <classes/servicemanager.hxx>
35 #include <macros/debug.hxx>
36 
37 #ifndef __FRAMEWORK_DEFINES_HXX_
38 #include <defines.hxx>
39 #endif
40 
41 //_________________________________________________________________________________________________________________
42 //  interface includes
43 //_________________________________________________________________________________________________________________
44 #include <com/sun/star/frame/XDesktop.hpp>
45 #include <com/sun/star/frame/XFrame.hpp>
46 #include <com/sun/star/awt/XWindow.hpp>
47 #include <com/sun/star/frame/XFrameLoader.hpp>
48 #include <com/sun/star/beans/PropertyValue.hpp>
49 #include <com/sun/star/frame/XLoadEventListener.hpp>
50 #include <com/sun/star/frame/XDispatchProvider.hpp>
51 #include <com/sun/star/util/URL.hpp>
52 #include <com/sun/star/frame/FrameSearchFlag.hpp>
53 #include <com/sun/star/frame/XFrames.hpp>
54 
55 #ifndef _COM_SUN_STAR_CONNECTION_XConnection_HPP_
56 #include <com/sun/star/connection/XConnection.hpp>
57 #endif
58 
59 #ifndef _COM_SUN_STAR_BRIDGE_XBridgeFactory_HPP_
60 #include <com/sun/star/bridge/XBridgeFactory.hpp>
61 #endif
62 
63 //_________________________________________________________________________________________________________________
64 //  other includes
65 //_________________________________________________________________________________________________________________
66 #include <comphelper/processfactory.hxx>
67 #include <com/sun/star/uno/Reference.hxx>
68 #include <rtl/ustring.hxx>
69 #include <rtl/ustrbuf.hxx>
70 #include <toolkit/helper/vclunohelper.hxx>
71 #include <svtools/unoiface.hxx>
72 #include <vcl/svapp.hxx>
73 #include <vcl/wrkwin.hxx>
74 #include <vos/process.hxx>
75 
76 //_________________________________________________________________________________________________________________
77 //  namespace
78 //_________________________________________________________________________________________________________________
79 
80 using namespace ::rtl                           ;
81 using namespace ::vos                           ;
82 using namespace ::comphelper                    ;
83 using namespace ::framework                     ;
84 using namespace ::com::sun::star::uno           ;
85 using namespace ::com::sun::star::lang          ;
86 using namespace ::com::sun::star::frame         ;
87 using namespace ::com::sun::star::awt           ;
88 using namespace ::com::sun::star::beans         ;
89 using namespace ::com::sun::star::util          ;
90 using namespace ::com::sun::star::connection    ;
91 using namespace ::com::sun::star::bridge        ;
92 
93 //_________________________________________________________________________________________________________________
94 //  const
95 //_________________________________________________________________________________________________________________
96 
97 #define APPLICATIONNAME                         "FrameWork"
98 #define COMMANDARGUMENT_PLUGIN                  DECLARE_ASCII("-plugin"                 )
99 #define NAME_PLUGINBRIDGE                       DECLARE_ASCII("mozilla plugin bridge"   )
100 #define PROTOCOL_PLUGINBRIDGE                   DECLARE_ASCII("urp"                     )
101 
102 //_________________________________________________________________________________________________________________
103 //  declarations
104 //_________________________________________________________________________________________________________________
105 
106 /*-************************************************************************************************************//**
107     @short      normal application
108     @descr      An instance of these class can be a normal node in frame tree only. The highest level to be allowed is 3!
109                 On 1 stand the desktop himself as the only one, on 2 are all tasks present ... and then comes frames only.
110                 A frame support influencing of his subtree, find of subframes, activate- and deactivate-mechanism as well as
111                 set/get of a frame window, component or controller.
112 
113     @implements XInterface
114                 XTypeProvider
115                 XServiceInfo
116                 XFramesSupplier
117                 XFrame
118                 XComponent
119                 XStatusIndicatorSupplier
120                 XDispatchProvider
121                 XDispatchProviderInterception
122                 XBrowseHistoryRegistry
123                 XLoadEventListener
124                 XEventListener
125                 XWindowListener
126                 XTopWindowListener
127                 [ XDebugging, if TEST_TREE is defined! ]
128     @base       OMutexMember
129                 OWeakObject
130 
131     @devstatus  deprecated
132 *//*-*************************************************************************************************************/
133 class FrameWork : public Application
134 {
135     //-------------------------------------------------------------------------------------------------------------
136     //  public methods
137     //-------------------------------------------------------------------------------------------------------------
138 
139     public:
140         void Main();
141 
142     private:
143         void impl_analyzeCommandArguments();
144 
145     private:
146         sal_Bool    m_bUsePlugIn    ;
147 
148 };  //  class FrameWork
149 
150 //_________________________________________________________________________________________________________________
151 //  definitions
152 //_________________________________________________________________________________________________________________
153 
154 //_________________________________________________________________________________________________________________
155 //  global variables
156 //_________________________________________________________________________________________________________________
157 
158 FrameWork   aFrameWork  ;
159 
160 //_________________________________________________________________________________________________________________
161 //  definitions
162 //_________________________________________________________________________________________________________________
163 
164 //*****************************************************************************************************************
165 //  private methods
166 //*****************************************************************************************************************
impl_analyzeCommandArguments()167 void FrameWork::impl_analyzeCommandArguments()
168 {
169     // First reset all member variables which present states of incoming arguments!
170     m_bUsePlugIn = sal_False;   // depends from "/plugin"
171 
172     // Then step over all given arguments and search for supported one.
173     OStartupInfo    aInfo       ;
174     OUString        sArgument   ;
175     sal_uInt32      nCount      = aInfo.getCommandArgCount();
176     for ( sal_uInt32 nArgument=0; nArgument<nCount; ++nArgument )
177     {
178         // If extraction of current argument successfull ...
179         if ( aInfo.getCommandArg( nArgument, sArgument ) == osl_Process_E_None )
180         {
181             // ... search for matching with supported values.
182             if ( sArgument == COMMANDARGUMENT_PLUGIN )
183             {
184                 // We found "/plugin" => set internal equivalent.
185                 m_bUsePlugIn = sal_True;
186             }
187         }
188     }
189 }
190 
191 //_________________________________________________________________________________________________________________
192 //  main
193 //_________________________________________________________________________________________________________________
194 
Main()195 void FrameWork::Main()
196 {
197     //-------------------------------------------------------------------------------------------------------------
198     // a) Initialize ouer application
199 
200     // Analyze command arguments.
201     impl_analyzeCommandArguments();
202 
203     // Create new global servicemanager.
204     ServiceManager aManager;
205     Reference< XMultiServiceFactory > xGlobalServiceManager = aManager.getGlobalUNOServiceManager();
206 
207     if ( xGlobalServiceManager.is() == sal_True )
208     {
209         // If it was successful - set in as static value in UNOTOOLS!
210         setProcessServiceFactory( xGlobalServiceManager );
211 
212         //---------------------------------------------------------------------------------------------------------
213         // b) Create root of ouer frame tree
214 
215         // Create top of frame hierarchy - the desktop.
216         Reference< XDesktop > xDesktop( xGlobalServiceManager->createInstance( SERVICENAME_DESKTOP ), UNO_QUERY );
217         // Safe impossible cases
218         // We need the desktop for working.
219         LOG_ASSERT( !(xDesktop.is()==sal_False), "FrameWork::Main()\nCan't instanciate desktop!Servicename unknown?\n" )
220 
221         //---------------------------------------------------------------------------------------------------------
222         // c) Initialize connection to possible PlugIn dll.
223 
224 // OPipeConnection removed, connection to plugin now uses acceptor service
225 #if 0
226         if ( m_bUsePlugIn == sal_True )
227         {
228             Reference< XConnection >    xConnection         = new OPipeConnection( xGlobalServiceManager );
229             Reference< XBridgeFactory > xBridgeFactory      ( xGlobalServiceManager->createInstance( SERVICENAME_BRIDGEFACTORY  ), UNO_QUERY );
230             if  (
231                     ( xConnection.is()          == sal_True )   &&
232                     ( xBridgeFactory.is()       == sal_True )
233                 )
234             {
235                 Reference< XBridge > xBridge = xBridgeFactory->createBridge(    NAME_PLUGINBRIDGE                               ,
236                                                                                 PROTOCOL_PLUGINBRIDGE                           ,
237                                                                                 xConnection                                     ,
238                                                                                 new OInstanceProvider( xGlobalServiceManager )  );
239             }
240             else
241             {
242                 // Error handling ... !?
243                 LOG_ASSERT( sal_False, "FrameWork::Main()\nNo connection to plugin. Initialization of bridge failed.\n" )
244             }
245         }
246 #endif
247         //---------------------------------------------------------------------------------------------------------
248         // d) Initialize new task with a HTML-URL in it.
249 
250         // Cast desktop to right interface to do this.
251         Reference< XDispatchProvider > xDispatchProvider( xDesktop, UNO_QUERY );
252         // Safe impossible cases.
253         // Desktop MUST support these interface!
254         LOG_ASSERT( !(xDispatchProvider.is()==sal_False), "FrameWork::Main()\nDesktop don't support XDispatchProvider interface.\n" )
255         if ( xDispatchProvider.is() == sal_True )
256         {
257             // Build URL ...
258             OUString sURL( RTL_CONSTASCII_USTRINGPARAM( "file://e|/dokumentation/Documentation/projekte/services/inimanager/inimanager/index.html" ));
259             URL aURL;
260             aURL.Complete = sURL;
261             // ... and dispatch it.
262             Reference< XDispatch > xDispatch = xDispatchProvider->queryDispatch( aURL, FRAMETYPE_BLANK, 0 );
263             xDispatch->dispatch( aURL, Sequence< PropertyValue >() );
264 
265             // Use special feature of desktop service and log current tree state in file.
266 //          LOG_TREE( xDesktop )
267 
268             // Build URL ...
269             sURL = OUString( RTL_CONSTASCII_USTRINGPARAM( "file://d|/menu.htm" ));
270             aURL.Complete = sURL;
271             // ... and dispatch it.
272             xDispatch = xDispatchProvider->queryDispatch( aURL, FRAMETYPE_BLANK, 0 );
273             xDispatch->dispatch( aURL, Sequence< PropertyValue >() );
274 
275             // Use special feature of desktop service and log current tree state in file.
276 //          LOG_TREE( xDesktop )
277         }
278 
279         // Set running-mode for application.
280         Execute();
281     }
282 }
283