1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: framework.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_framework.hxx"
34 //_________________________________________________________________________________________________________________
36 //_________________________________________________________________________________________________________________
38 #ifndef __FRAMEWORK_HELPER_OINSTANCEPROVIDER_HXX_
39 #include <helper/oinstanceprovider.hxx>
41 #include <classes/servicemanager.hxx>
42 #include <macros/debug.hxx>
44 #ifndef __FRAMEWORK_DEFINES_HXX_
45 #include <defines.hxx>
48 //_________________________________________________________________________________________________________________
50 //_________________________________________________________________________________________________________________
51 #include <com/sun/star/frame/XDesktop.hpp>
52 #include <com/sun/star/frame/XFrame.hpp>
53 #include <com/sun/star/awt/XWindow.hpp>
54 #include <com/sun/star/frame/XFrameLoader.hpp>
55 #include <com/sun/star/beans/PropertyValue.hpp>
56 #include <com/sun/star/frame/XLoadEventListener.hpp>
57 #include <com/sun/star/frame/XDispatchProvider.hpp>
58 #include <com/sun/star/util/URL.hpp>
59 #include <com/sun/star/frame/FrameSearchFlag.hpp>
60 #include <com/sun/star/frame/XFrames.hpp>
62 #ifndef _COM_SUN_STAR_CONNECTION_XConnection_HPP_
63 #include <com/sun/star/connection/XConnection.hpp>
66 #ifndef _COM_SUN_STAR_BRIDGE_XBridgeFactory_HPP_
67 #include <com/sun/star/bridge/XBridgeFactory.hpp>
70 //_________________________________________________________________________________________________________________
72 //_________________________________________________________________________________________________________________
73 #include <comphelper/processfactory.hxx>
74 #include <com/sun/star/uno/Reference.hxx>
75 #include <rtl/ustring.hxx>
76 #include <rtl/ustrbuf.hxx>
77 #include <toolkit/helper/vclunohelper.hxx>
78 #include <svtools/unoiface.hxx>
79 #include <vcl/svapp.hxx>
80 #include <vcl/wrkwin.hxx>
81 #include <vos/process.hxx>
83 //_________________________________________________________________________________________________________________
85 //_________________________________________________________________________________________________________________
87 using namespace ::rtl
;
88 using namespace ::vos
;
89 using namespace ::comphelper
;
90 using namespace ::framework
;
91 using namespace ::com::sun::star::uno
;
92 using namespace ::com::sun::star::lang
;
93 using namespace ::com::sun::star::frame
;
94 using namespace ::com::sun::star::awt
;
95 using namespace ::com::sun::star::beans
;
96 using namespace ::com::sun::star::util
;
97 using namespace ::com::sun::star::connection
;
98 using namespace ::com::sun::star::bridge
;
100 //_________________________________________________________________________________________________________________
102 //_________________________________________________________________________________________________________________
104 #define APPLICATIONNAME "FrameWork"
105 #define COMMANDARGUMENT_PLUGIN DECLARE_ASCII("-plugin" )
106 #define NAME_PLUGINBRIDGE DECLARE_ASCII("mozilla plugin bridge" )
107 #define PROTOCOL_PLUGINBRIDGE DECLARE_ASCII("urp" )
109 //_________________________________________________________________________________________________________________
111 //_________________________________________________________________________________________________________________
113 /*-************************************************************************************************************//**
114 @short normal application
115 @descr An instance of these class can be a normal node in frame tree only. The highest level to be allowed is 3!
116 On 1 stand the desktop himself as the only one, on 2 are all tasks present ... and then comes frames only.
117 A frame support influencing of his subtree, find of subframes, activate- and deactivate-mechanism as well as
118 set/get of a frame window, component or controller.
120 @implements XInterface
126 XStatusIndicatorSupplier
128 XDispatchProviderInterception
129 XBrowseHistoryRegistry
134 [ XDebugging, if TEST_TREE is defined! ]
138 @devstatus deprecated
139 *//*-*************************************************************************************************************/
140 class FrameWork
: public Application
142 //-------------------------------------------------------------------------------------------------------------
144 //-------------------------------------------------------------------------------------------------------------
150 void impl_analyzeCommandArguments();
153 sal_Bool m_bUsePlugIn
;
155 }; // class FrameWork
157 //_________________________________________________________________________________________________________________
159 //_________________________________________________________________________________________________________________
161 //_________________________________________________________________________________________________________________
163 //_________________________________________________________________________________________________________________
165 FrameWork aFrameWork
;
167 //_________________________________________________________________________________________________________________
169 //_________________________________________________________________________________________________________________
171 //*****************************************************************************************************************
173 //*****************************************************************************************************************
174 void FrameWork::impl_analyzeCommandArguments()
176 // First reset all member variables which present states of incoming arguments!
177 m_bUsePlugIn
= sal_False
; // depends from "/plugin"
179 // Then step over all given arguments and search for supported one.
182 sal_uInt32 nCount
= aInfo
.getCommandArgCount();
183 for ( sal_uInt32 nArgument
=0; nArgument
<nCount
; ++nArgument
)
185 // If extraction of current argument successfull ...
186 if ( aInfo
.getCommandArg( nArgument
, sArgument
) == osl_Process_E_None
)
188 // ... search for matching with supported values.
189 if ( sArgument
== COMMANDARGUMENT_PLUGIN
)
191 // We found "/plugin" => set internal equivalent.
192 m_bUsePlugIn
= sal_True
;
198 //_________________________________________________________________________________________________________________
200 //_________________________________________________________________________________________________________________
202 void FrameWork::Main()
204 //-------------------------------------------------------------------------------------------------------------
205 // a) Initialize ouer application
207 // Analyze command arguments.
208 impl_analyzeCommandArguments();
210 // Create new global servicemanager.
211 ServiceManager aManager
;
212 Reference
< XMultiServiceFactory
> xGlobalServiceManager
= aManager
.getGlobalUNOServiceManager();
214 if ( xGlobalServiceManager
.is() == sal_True
)
216 // If it was successful - set in as static value in UNOTOOLS!
217 setProcessServiceFactory( xGlobalServiceManager
);
219 //---------------------------------------------------------------------------------------------------------
220 // b) Create root of ouer frame tree
222 // Create top of frame hierarchy - the desktop.
223 Reference
< XDesktop
> xDesktop( xGlobalServiceManager
->createInstance( SERVICENAME_DESKTOP
), UNO_QUERY
);
224 // Safe impossible cases
225 // We need the desktop for working.
226 LOG_ASSERT( !(xDesktop
.is()==sal_False
), "FrameWork::Main()\nCan't instanciate desktop!Servicename unknown?\n" )
228 //---------------------------------------------------------------------------------------------------------
229 // c) Initialize connection to possible PlugIn dll.
231 // OPipeConnection removed, connection to plugin now uses acceptor service
233 if ( m_bUsePlugIn
== sal_True
)
235 Reference
< XConnection
> xConnection
= new OPipeConnection( xGlobalServiceManager
);
236 Reference
< XBridgeFactory
> xBridgeFactory ( xGlobalServiceManager
->createInstance( SERVICENAME_BRIDGEFACTORY
), UNO_QUERY
);
238 ( xConnection
.is() == sal_True
) &&
239 ( xBridgeFactory
.is() == sal_True
)
242 Reference
< XBridge
> xBridge
= xBridgeFactory
->createBridge( NAME_PLUGINBRIDGE
,
243 PROTOCOL_PLUGINBRIDGE
,
245 new OInstanceProvider( xGlobalServiceManager
) );
249 // Error handling ... !?
250 LOG_ASSERT( sal_False
, "FrameWork::Main()\nNo connection to plugin. Initialization of bridge failed.\n" )
254 //---------------------------------------------------------------------------------------------------------
255 // d) Initialize new task with a HTML-URL in it.
257 // Cast desktop to right interface to do this.
258 Reference
< XDispatchProvider
> xDispatchProvider( xDesktop
, UNO_QUERY
);
259 // Safe impossible cases.
260 // Desktop MUST support these interface!
261 LOG_ASSERT( !(xDispatchProvider
.is()==sal_False
), "FrameWork::Main()\nDesktop don't support XDispatchProvider interface.\n" )
262 if ( xDispatchProvider
.is() == sal_True
)
265 OUString
sURL( RTL_CONSTASCII_USTRINGPARAM( "file://e|/dokumentation/Documentation/projekte/services/inimanager/inimanager/index.html" ));
267 aURL
.Complete
= sURL
;
268 // ... and dispatch it.
269 Reference
< XDispatch
> xDispatch
= xDispatchProvider
->queryDispatch( aURL
, FRAMETYPE_BLANK
, 0 );
270 xDispatch
->dispatch( aURL
, Sequence
< PropertyValue
>() );
272 // Use special feature of desktop service and log current tree state in file.
273 // LOG_TREE( xDesktop )
276 sURL
= OUString( RTL_CONSTASCII_USTRINGPARAM( "file://d|/menu.htm" ));
277 aURL
.Complete
= sURL
;
278 // ... and dispatch it.
279 xDispatch
= xDispatchProvider
->queryDispatch( aURL
, FRAMETYPE_BLANK
, 0 );
280 xDispatch
->dispatch( aURL
, Sequence
< PropertyValue
>() );
282 // Use special feature of desktop service and log current tree state in file.
283 // LOG_TREE( xDesktop )
286 // Set running-mode for application.