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