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