xref: /AOO41X/main/framework/source/services/backingwindow.cxx (revision 5ae32f778489116071ff3fac614ad337bcb97962)
16d739b60SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
36d739b60SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
46d739b60SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
56d739b60SAndrew Rist  * distributed with this work for additional information
66d739b60SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
76d739b60SAndrew Rist  * to you under the Apache License, Version 2.0 (the
86d739b60SAndrew Rist  * "License"); you may not use this file except in compliance
96d739b60SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
116d739b60SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
136d739b60SAndrew Rist  * Unless required by applicable law or agreed to in writing,
146d739b60SAndrew Rist  * software distributed under the License is distributed on an
156d739b60SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
166d739b60SAndrew Rist  * KIND, either express or implied.  See the License for the
176d739b60SAndrew Rist  * specific language governing permissions and limitations
186d739b60SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
206d739b60SAndrew Rist  *************************************************************/
216d739b60SAndrew Rist 
22cdf0e10cSrcweir // autogen include statement, do not remove
23cdf0e10cSrcweir #include "precompiled_framework.hxx"
24cdf0e10cSrcweir 
25cdf0e10cSrcweir #include "backingwindow.hxx"
26cdf0e10cSrcweir #include "classes/resource.hrc"
27cdf0e10cSrcweir #include "framework.hrc"
28cdf0e10cSrcweir #include "classes/fwkresid.hxx"
29cdf0e10cSrcweir #include <services.h>
30cdf0e10cSrcweir 
31cdf0e10cSrcweir #include "vcl/metric.hxx"
32cdf0e10cSrcweir #include "vcl/mnemonic.hxx"
33cdf0e10cSrcweir #include "vcl/menu.hxx"
34cdf0e10cSrcweir #include "vcl/svapp.hxx"
35cdf0e10cSrcweir 
36cdf0e10cSrcweir #include "tools/urlobj.hxx"
37cdf0e10cSrcweir 
38cdf0e10cSrcweir #include "unotools/dynamicmenuoptions.hxx"
39cdf0e10cSrcweir #include "unotools/historyoptions.hxx"
40cdf0e10cSrcweir #include "svtools/imagemgr.hxx"
41cdf0e10cSrcweir #include "svtools/svtools.hrc"
42cdf0e10cSrcweir 
43cdf0e10cSrcweir #include "comphelper/processfactory.hxx"
44cdf0e10cSrcweir #include "comphelper/sequenceashashmap.hxx"
45cdf0e10cSrcweir #include "comphelper/configurationhelper.hxx"
46cdf0e10cSrcweir 
47f7882915SAriel Constenla-Haile #include <toolkit/awt/vclxmenu.hxx>
48f7882915SAriel Constenla-Haile 
49cdf0e10cSrcweir #include "cppuhelper/implbase1.hxx"
50cdf0e10cSrcweir 
51cdf0e10cSrcweir #include "rtl/strbuf.hxx"
52cdf0e10cSrcweir #include "rtl/ustrbuf.hxx"
53cdf0e10cSrcweir #include "osl/file.h"
54cdf0e10cSrcweir 
55cdf0e10cSrcweir #include "com/sun/star/lang/XMultiServiceFactory.hpp"
56cdf0e10cSrcweir #include "com/sun/star/container/XNameAccess.hpp"
579807c9deSAriel Constenla-Haile #include "com/sun/star/system/SystemShellExecute.hpp"
58cdf0e10cSrcweir #include "com/sun/star/system/SystemShellExecuteFlags.hpp"
59cdf0e10cSrcweir #include "com/sun/star/task/XJobExecutor.hpp"
60cdf0e10cSrcweir #include "com/sun/star/util/XStringWidth.hpp"
61f7882915SAriel Constenla-Haile #include <com/sun/star/frame/PopupMenuControllerFactory.hpp>
62cdf0e10cSrcweir 
63cdf0e10cSrcweir using namespace ::com::sun::star::beans;
64cdf0e10cSrcweir using namespace ::com::sun::star::frame;
65cdf0e10cSrcweir using namespace ::com::sun::star::uno;
66cdf0e10cSrcweir using namespace ::com::sun::star;
67cdf0e10cSrcweir using namespace framework;
68cdf0e10cSrcweir 
69f7882915SAriel Constenla-Haile #define RECENT_FILE_LIST    ".uno:RecentFileList"
70f7882915SAriel Constenla-Haile 
71cdf0e10cSrcweir #define WRITER_URL      "private:factory/swriter"
72cdf0e10cSrcweir #define CALC_URL        "private:factory/scalc"
73cdf0e10cSrcweir #define IMPRESS_WIZARD_URL     "private:factory/simpress?slot=6686"
74cdf0e10cSrcweir #define DRAW_URL        "private:factory/sdraw"
75cdf0e10cSrcweir #define BASE_URL        "private:factory/sdatabase?Interactive"
76cdf0e10cSrcweir #define MATH_URL        "private:factory/smath"
77cdf0e10cSrcweir #define TEMPLATE_URL    "slot:5500"
78cdf0e10cSrcweir #define OPEN_URL        ".uno:Open"
79cdf0e10cSrcweir 
DecoToolBox(Window * pParent,WinBits nStyle)80cdf0e10cSrcweir DecoToolBox::DecoToolBox( Window* pParent, WinBits nStyle ) :
81cdf0e10cSrcweir     ToolBox( pParent, nStyle )
82cdf0e10cSrcweir {
83cdf0e10cSrcweir         SetBackground();
84cdf0e10cSrcweir         SetPaintTransparent( sal_True );
85cdf0e10cSrcweir }
86cdf0e10cSrcweir 
DataChanged(const DataChangedEvent & rDCEvt)87cdf0e10cSrcweir void DecoToolBox::DataChanged( const DataChangedEvent& rDCEvt )
88cdf0e10cSrcweir {
89cdf0e10cSrcweir     Window::DataChanged( rDCEvt );
90cdf0e10cSrcweir 
91cdf0e10cSrcweir     if ( rDCEvt.GetFlags() & SETTINGS_STYLE )
92cdf0e10cSrcweir     {
93cdf0e10cSrcweir         calcMinSize();
94cdf0e10cSrcweir         SetBackground();
95cdf0e10cSrcweir         SetPaintTransparent( sal_True );
96cdf0e10cSrcweir     }
97cdf0e10cSrcweir }
98cdf0e10cSrcweir 
calcMinSize()99cdf0e10cSrcweir void DecoToolBox::calcMinSize()
100cdf0e10cSrcweir {
101cdf0e10cSrcweir     ToolBox aTbx( GetParent() );
102cdf0e10cSrcweir     sal_uInt16 nItems = GetItemCount();
103cdf0e10cSrcweir     for( sal_uInt16 i = 0; i < nItems; i++ )
104cdf0e10cSrcweir     {
105cdf0e10cSrcweir         sal_uInt16 nId = GetItemId( i );
106cdf0e10cSrcweir         aTbx.InsertItem( nId, GetItemImage( nId ) );
107cdf0e10cSrcweir     }
108cdf0e10cSrcweir     aTbx.SetOutStyle( TOOLBOX_STYLE_FLAT );
109cdf0e10cSrcweir     maMinSize = aTbx.CalcWindowSizePixel();
110cdf0e10cSrcweir }
111cdf0e10cSrcweir 
getMinSize()112cdf0e10cSrcweir Size DecoToolBox::getMinSize()
113cdf0e10cSrcweir {
114cdf0e10cSrcweir     return maMinSize;
115cdf0e10cSrcweir }
116cdf0e10cSrcweir 
117cdf0e10cSrcweir class RecentFilesStringLength : public ::cppu::WeakImplHelper1< ::com::sun::star::util::XStringWidth >
118cdf0e10cSrcweir {
119cdf0e10cSrcweir 	public:
RecentFilesStringLength()120cdf0e10cSrcweir 		RecentFilesStringLength() {}
~RecentFilesStringLength()121cdf0e10cSrcweir 		virtual ~RecentFilesStringLength() {}
122cdf0e10cSrcweir 
123cdf0e10cSrcweir 		// XStringWidth
queryStringWidth(const::rtl::OUString & aString)124cdf0e10cSrcweir 		sal_Int32 SAL_CALL queryStringWidth( const ::rtl::OUString& aString )
125cdf0e10cSrcweir 			throw (::com::sun::star::uno::RuntimeException)
126cdf0e10cSrcweir 		{
127cdf0e10cSrcweir 			return aString.getLength();
128cdf0e10cSrcweir 		}
129cdf0e10cSrcweir };
130cdf0e10cSrcweir 
131cdf0e10cSrcweir #define STC_BUTTON_STYLE  (WB_LEFT | WB_VCENTER | WB_FLATBUTTON | WB_BEVELBUTTON)
132cdf0e10cSrcweir 
BackingWindow(Window * i_pParent)133cdf0e10cSrcweir BackingWindow::BackingWindow( Window* i_pParent ) :
134cdf0e10cSrcweir     Window( i_pParent, FwkResId( DLG_BACKING ) ),
135cdf0e10cSrcweir     maWelcome( this, WB_LEFT ),
136cdf0e10cSrcweir     maProduct( this, WB_LEFT ),
137cdf0e10cSrcweir     maWriterButton( this, STC_BUTTON_STYLE ),
138cdf0e10cSrcweir     maCalcButton( this, STC_BUTTON_STYLE ),
139cdf0e10cSrcweir     maImpressButton( this, STC_BUTTON_STYLE ),
140cdf0e10cSrcweir     maOpenButton( this, STC_BUTTON_STYLE ),
141cdf0e10cSrcweir     maDrawButton( this, STC_BUTTON_STYLE ),
142cdf0e10cSrcweir     maDBButton( this, STC_BUTTON_STYLE ),
143cdf0e10cSrcweir     maMathButton( this, STC_BUTTON_STYLE ),
144cdf0e10cSrcweir     maTemplateButton( this, STC_BUTTON_STYLE ),
145cdf0e10cSrcweir     maToolbox( this, WB_DIALOGCONTROL ),
146cdf0e10cSrcweir     maWelcomeString( FwkResId( STR_BACKING_WELCOME ) ),
147cdf0e10cSrcweir     maProductString( FwkResId( STR_BACKING_WELCOMEPRODUCT ) ),
148cdf0e10cSrcweir     maOpenString( FwkResId( STR_BACKING_FILE ) ),
149cdf0e10cSrcweir     maTemplateString( FwkResId( STR_BACKING_TEMPLATE ) ),
150cdf0e10cSrcweir     maButtonImageSize( 10, 10 ),
151cdf0e10cSrcweir     mbInitControls( false ),
152cdf0e10cSrcweir     mnLayoutStyle( 0 ),
153cdf0e10cSrcweir     mpAccExec( NULL ),
154cdf0e10cSrcweir     mnBtnPos( 120 ),
155f7882915SAriel Constenla-Haile     mnBtnTop( 150 )
156cdf0e10cSrcweir {
157cdf0e10cSrcweir     mnColumnWidth[0] = mnColumnWidth[1] = 0;
158cdf0e10cSrcweir     mnTextColumnWidth[0] = mnTextColumnWidth[1] = 0;
159cdf0e10cSrcweir 
160cdf0e10cSrcweir     try
161cdf0e10cSrcweir     {
162f7882915SAriel Constenla-Haile         mxContext.set( ::comphelper::getProcessComponentContext(), uno::UNO_SET_THROW );
163f7882915SAriel Constenla-Haile 
164f7882915SAriel Constenla-Haile         Reference<lang::XMultiServiceFactory> xConfig(
165f7882915SAriel Constenla-Haile             mxContext->getServiceManager()->createInstanceWithContext(
166f7882915SAriel Constenla-Haile                 SERVICENAME_CFGPROVIDER, mxContext), UNO_QUERY);
167cdf0e10cSrcweir         if( xConfig.is() )
168cdf0e10cSrcweir         {
169cdf0e10cSrcweir             Sequence<Any> args(1);
170cdf0e10cSrcweir             PropertyValue val(
171cdf0e10cSrcweir                 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("nodepath") ),
172cdf0e10cSrcweir                 0,
173cdf0e10cSrcweir                 Any(rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("/org.openoffice.Office.Common/Help/StartCenter"))),
174cdf0e10cSrcweir                 PropertyState_DIRECT_VALUE);
175cdf0e10cSrcweir             args.getArray()[0] <<= val;
176cdf0e10cSrcweir             Reference<container::XNameAccess> xNameAccess(xConfig->createInstanceWithArguments(SERVICENAME_CFGREADACCESS,args), UNO_QUERY);
177cdf0e10cSrcweir             if( xNameAccess.is() )
178cdf0e10cSrcweir             {
179cdf0e10cSrcweir                 //throws css::container::NoSuchElementException, css::lang::WrappedTargetException
180cdf0e10cSrcweir                 Any value( xNameAccess->getByName(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("StartCenterLayoutStyle"))) );
181cdf0e10cSrcweir                 mnLayoutStyle = value.get<sal_Int32>();
182cdf0e10cSrcweir             }
183cdf0e10cSrcweir         }
184f7882915SAriel Constenla-Haile 
185f7882915SAriel Constenla-Haile         mxPopupMenuFactory.set(
186f7882915SAriel Constenla-Haile             frame::PopupMenuControllerFactory::create( mxContext ) );
187f7882915SAriel Constenla-Haile         // TODO If there is no PopupMenuController, the button should be a nomral one not a MenuButton
188f7882915SAriel Constenla-Haile         if ( mxPopupMenuFactory->hasController(
189f7882915SAriel Constenla-Haile             DECLARE_ASCII( RECENT_FILE_LIST ) , SERVICENAME_STARTMODULE ) )
190cdf0e10cSrcweir         {
191f7882915SAriel Constenla-Haile             mxPopupMenu.set( mxContext->getServiceManager()->createInstanceWithContext(
192f7882915SAriel Constenla-Haile                 DECLARE_ASCII( "com.sun.star.awt.PopupMenu" ), mxContext ), uno::UNO_QUERY_THROW );
193f7882915SAriel Constenla-Haile         }
194f7882915SAriel Constenla-Haile     }
195f7882915SAriel Constenla-Haile     catch (const Exception& e)
196f7882915SAriel Constenla-Haile     {
197f7882915SAriel Constenla-Haile         OSL_TRACE( "BackingWindow - caught an exception! %s",
198f7882915SAriel Constenla-Haile                    rtl::OUStringToOString( e.Message, RTL_TEXTENCODING_UTF8 ).getStr() );
199f7882915SAriel Constenla-Haile         (void) e;
200cdf0e10cSrcweir     }
201cdf0e10cSrcweir 
202cdf0e10cSrcweir     String aExtHelpText( FwkResId( STR_BACKING_EXTHELP ) );
203*5ae32f77Smseidel //	String aRegHelpText( FwkResId( STR_BACKING_REGHELP ) );
204cdf0e10cSrcweir     String aInfoHelpText( FwkResId( STR_BACKING_INFOHELP ) );
205cdf0e10cSrcweir     String aTplRepHelpText( FwkResId( STR_BACKING_TPLREP ) );
206cdf0e10cSrcweir 
207cdf0e10cSrcweir     // clean up resource stack
208cdf0e10cSrcweir     FreeResource();
209cdf0e10cSrcweir 
210cdf0e10cSrcweir     maWelcome.SetPaintTransparent( sal_True );
211cdf0e10cSrcweir     maProduct.SetPaintTransparent( sal_True );
212cdf0e10cSrcweir     EnableChildTransparentMode();
213cdf0e10cSrcweir 
214cdf0e10cSrcweir     SetStyle( GetStyle() | WB_DIALOGCONTROL );
215cdf0e10cSrcweir 
216cdf0e10cSrcweir     // force tab cycling in toolbox
217cdf0e10cSrcweir     maToolbox.SetStyle( maToolbox.GetStyle() | WB_FORCETABCYCLE );
218cdf0e10cSrcweir 
219cdf0e10cSrcweir     // insert toolbox items
220cdf0e10cSrcweir     maToolbox.InsertItem( nItemId_TplRep, Image() );
221cdf0e10cSrcweir     maToolbox.SetItemText( nItemId_TplRep, aTplRepHelpText );
222cdf0e10cSrcweir     maToolbox.SetQuickHelpText( nItemId_TplRep, aTplRepHelpText );
223cdf0e10cSrcweir     maToolbox.SetItemCommand( nItemId_TplRep, String( RTL_CONSTASCII_USTRINGPARAM( ".HelpId:StartCenter:TemplateRepository" ) ) );
224cdf0e10cSrcweir     maToolbox.ShowItem( nItemId_TplRep );
225cdf0e10cSrcweir 
226cdf0e10cSrcweir     maToolbox.InsertItem( nItemId_Extensions, Image() );
227cdf0e10cSrcweir     maToolbox.SetQuickHelpText( nItemId_Extensions, aExtHelpText );
228cdf0e10cSrcweir     maToolbox.SetItemText( nItemId_Extensions, aExtHelpText );
229cdf0e10cSrcweir     maToolbox.SetItemCommand( nItemId_Extensions, String( RTL_CONSTASCII_USTRINGPARAM( ".HelpId:StartCenter:Extensions" ) ) );
230cdf0e10cSrcweir     maToolbox.ShowItem( nItemId_Extensions );
231cdf0e10cSrcweir 
232cdf0e10cSrcweir     maToolbox.InsertItem( nItemId_Info, Image() );
233cdf0e10cSrcweir     maToolbox.SetItemText( nItemId_Info, aInfoHelpText );
234cdf0e10cSrcweir     maToolbox.SetQuickHelpText( nItemId_Info, aInfoHelpText );
235cdf0e10cSrcweir     maToolbox.SetItemCommand( nItemId_Info, String( RTL_CONSTASCII_USTRINGPARAM( ".HelpId:StartCenter:Info" ) ) );
236cdf0e10cSrcweir     maToolbox.ShowItem( nItemId_Info );
237cdf0e10cSrcweir 
238cdf0e10cSrcweir     // get dispatch provider
239cdf0e10cSrcweir     mxDesktop = Reference<XDesktop>( comphelper::getProcessServiceFactory()->createInstance(SERVICENAME_DESKTOP ),UNO_QUERY );
240cdf0e10cSrcweir     if( mxDesktop.is() )
241cdf0e10cSrcweir         mxDesktopDispatchProvider = Reference< XDispatchProvider >( mxDesktop, UNO_QUERY );
242cdf0e10cSrcweir 
243cdf0e10cSrcweir     maWriterButton.SetHelpId( ".HelpId:StartCenter:WriterButton" );
244cdf0e10cSrcweir     maCalcButton.SetHelpId( ".HelpId:StartCenter:CalcButton" );
245cdf0e10cSrcweir     maImpressButton.SetHelpId( ".HelpId:StartCenter:ImpressButton" );
246cdf0e10cSrcweir     maDrawButton.SetHelpId( ".HelpId:StartCenter:DrawButton" );
247cdf0e10cSrcweir     maDBButton.SetHelpId( ".HelpId:StartCenter:DBButton" );
248cdf0e10cSrcweir     maMathButton.SetHelpId( ".HelpId:StartCenter:MathButton" );
249cdf0e10cSrcweir     maTemplateButton.SetHelpId( ".HelpId:StartCenter:TemplateButton" );
250cdf0e10cSrcweir     maOpenButton.SetHelpId( ".HelpId:StartCenter:OpenButton" );
251cdf0e10cSrcweir     maToolbox.SetHelpId( ".HelpId:StartCenter:Toolbox" );
252cdf0e10cSrcweir 
253cdf0e10cSrcweir     // init background
254cdf0e10cSrcweir     initBackground();
255cdf0e10cSrcweir 
256cdf0e10cSrcweir     // add some breathing space for the images
257cdf0e10cSrcweir     maButtonImageSize.Width() += 12;
258cdf0e10cSrcweir     maButtonImageSize.Height() += 12;
259cdf0e10cSrcweir 
260cdf0e10cSrcweir }
261cdf0e10cSrcweir 
262cdf0e10cSrcweir 
~BackingWindow()263cdf0e10cSrcweir BackingWindow::~BackingWindow()
264cdf0e10cSrcweir {
265cdf0e10cSrcweir     delete mpAccExec;
266f7882915SAriel Constenla-Haile 
267f7882915SAriel Constenla-Haile     if( mxPopupMenuController.is() )
268f7882915SAriel Constenla-Haile     {
269f7882915SAriel Constenla-Haile         Reference< lang::XComponent > xComponent( mxPopupMenuController, UNO_QUERY );
270f7882915SAriel Constenla-Haile         if( xComponent.is() )
271f7882915SAriel Constenla-Haile         {
272f7882915SAriel Constenla-Haile             try
273f7882915SAriel Constenla-Haile             {
274f7882915SAriel Constenla-Haile                 xComponent->dispose();
275f7882915SAriel Constenla-Haile             }
276f7882915SAriel Constenla-Haile             catch (...)
277f7882915SAriel Constenla-Haile             {}
278f7882915SAriel Constenla-Haile         }
279f7882915SAriel Constenla-Haile         mxPopupMenuController.clear();
280f7882915SAriel Constenla-Haile     }
281f7882915SAriel Constenla-Haile     mxPopupMenuFactory.clear();
282f7882915SAriel Constenla-Haile     mxPopupMenu.clear();
283cdf0e10cSrcweir }
284cdf0e10cSrcweir 
GetFocus()285cdf0e10cSrcweir void BackingWindow::GetFocus()
286cdf0e10cSrcweir {
287cdf0e10cSrcweir     if( IsVisible() )
288cdf0e10cSrcweir         maWriterButton.GrabFocus();
289cdf0e10cSrcweir     Window::GetFocus();
290cdf0e10cSrcweir }
291cdf0e10cSrcweir 
292cdf0e10cSrcweir class ImageContainerRes : public Resource
293cdf0e10cSrcweir {
294cdf0e10cSrcweir     public:
ImageContainerRes(const ResId & i_rId)295cdf0e10cSrcweir     ImageContainerRes( const ResId& i_rId ) : Resource( i_rId ) {}
~ImageContainerRes()296cdf0e10cSrcweir     ~ImageContainerRes() { FreeResource(); }
297cdf0e10cSrcweir };
298cdf0e10cSrcweir 
DataChanged(const DataChangedEvent & rDCEvt)299cdf0e10cSrcweir void BackingWindow::DataChanged( const DataChangedEvent& rDCEvt )
300cdf0e10cSrcweir {
301cdf0e10cSrcweir     Window::DataChanged( rDCEvt );
302cdf0e10cSrcweir 
303cdf0e10cSrcweir     if ( rDCEvt.GetFlags() & SETTINGS_STYLE )
304cdf0e10cSrcweir     {
305cdf0e10cSrcweir         initBackground();
306cdf0e10cSrcweir         Invalidate();
307cdf0e10cSrcweir     }
308cdf0e10cSrcweir }
309cdf0e10cSrcweir 
prepareRecentFileMenu()310cdf0e10cSrcweir void BackingWindow::prepareRecentFileMenu()
311cdf0e10cSrcweir {
312f7882915SAriel Constenla-Haile     if( ! mxPopupMenu.is() )
313f7882915SAriel Constenla-Haile         return;
314cdf0e10cSrcweir 
315f7882915SAriel Constenla-Haile     if ( !mxPopupMenuController.is() )
316f7882915SAriel Constenla-Haile     {
317f7882915SAriel Constenla-Haile         uno::Sequence< uno::Any > aArgs( 2 );
318f7882915SAriel Constenla-Haile         beans::PropertyValue aProp;
319cdf0e10cSrcweir 
320f7882915SAriel Constenla-Haile         aProp.Name = DECLARE_ASCII( "Frame" );
321f7882915SAriel Constenla-Haile         aProp.Value <<= mxFrame;
322f7882915SAriel Constenla-Haile         aArgs[0] <<= aProp;
323cdf0e10cSrcweir 
324f7882915SAriel Constenla-Haile         aProp.Name = DECLARE_ASCII( "ModuleIdentifier" );
325f7882915SAriel Constenla-Haile         aProp.Value <<= SERVICENAME_STARTMODULE;
326f7882915SAriel Constenla-Haile         aArgs[1] <<= aProp;
327f7882915SAriel Constenla-Haile         try
328cdf0e10cSrcweir         {
329f7882915SAriel Constenla-Haile             mxPopupMenuController.set(
330f7882915SAriel Constenla-Haile                 mxPopupMenuFactory->createInstanceWithArgumentsAndContext(
331f7882915SAriel Constenla-Haile                     DECLARE_ASCII( RECENT_FILE_LIST ), aArgs, mxContext),
332f7882915SAriel Constenla-Haile                         uno::UNO_QUERY_THROW );
333f7882915SAriel Constenla-Haile             mxPopupMenuController->setPopupMenu( mxPopupMenu );
334cdf0e10cSrcweir         }
335f7882915SAriel Constenla-Haile         catch ( const Exception &e )
336cdf0e10cSrcweir         {
337f7882915SAriel Constenla-Haile             OSL_TRACE( "BackingWindow - caught an exception! %s",
338f7882915SAriel Constenla-Haile                        rtl::OUStringToOString( e.Message, RTL_TEXTENCODING_UTF8 ).getStr() );
339f7882915SAriel Constenla-Haile             (void) e;
340cdf0e10cSrcweir         }
341cdf0e10cSrcweir 
342f7882915SAriel Constenla-Haile         PopupMenu *pRecentMenu = NULL;
343f7882915SAriel Constenla-Haile         VCLXMenu* pTKMenu = VCLXMenu::GetImplementation( mxPopupMenu );
344f7882915SAriel Constenla-Haile         if ( pTKMenu )
345f7882915SAriel Constenla-Haile             pRecentMenu = dynamic_cast< PopupMenu * >( pTKMenu->GetMenu() );
346f7882915SAriel Constenla-Haile         maOpenButton.SetPopupMenu( pRecentMenu );
347cdf0e10cSrcweir     }
348cdf0e10cSrcweir }
349cdf0e10cSrcweir 
initBackground()350cdf0e10cSrcweir void BackingWindow::initBackground()
351cdf0e10cSrcweir {
352cdf0e10cSrcweir     SetBackground();
353cdf0e10cSrcweir 
354cdf0e10cSrcweir     bool bDark = GetSettings().GetStyleSettings().GetHighContrastMode();
355cdf0e10cSrcweir     if( bDark )
356cdf0e10cSrcweir         maWelcomeTextColor = maLabelTextColor = Color( COL_WHITE );
357cdf0e10cSrcweir     else if( mnLayoutStyle == 1 )
358cdf0e10cSrcweir         maWelcomeTextColor = maLabelTextColor = Color( COL_BLACK );
359cdf0e10cSrcweir     else
360cdf0e10cSrcweir         maWelcomeTextColor = maLabelTextColor = Color( 0x26, 0x35, 0x42 );
361cdf0e10cSrcweir 
362cdf0e10cSrcweir     Color aTextBGColor( bDark ? COL_BLACK : COL_WHITE );
363cdf0e10cSrcweir 
364cdf0e10cSrcweir     // select image set
365cdf0e10cSrcweir     ImageContainerRes aRes( FwkResId( bDark ? RES_BACKING_IMAGES_HC : RES_BACKING_IMAGES ) );
366cdf0e10cSrcweir 
367cdf0e10cSrcweir     // scale middle segment
368cdf0e10cSrcweir     Size aMiddleSize;
369cdf0e10cSrcweir     if( !! maBackgroundMiddle )
370cdf0e10cSrcweir         aMiddleSize = maBackgroundMiddle.GetSizePixel();
371cdf0e10cSrcweir     // load middle segment
372cdf0e10cSrcweir     maBackgroundMiddle = BitmapEx( FwkResId( BMP_BACKING_BACKGROUND_MIDDLE ) );
373cdf0e10cSrcweir     // and scale it to previous size
374cdf0e10cSrcweir     if( aMiddleSize.Width() && aMiddleSize.Height() )
375cdf0e10cSrcweir         maBackgroundMiddle.Scale( aMiddleSize );
376cdf0e10cSrcweir 
377cdf0e10cSrcweir     if( GetSettings().GetLayoutRTL() )
378cdf0e10cSrcweir     {
379cdf0e10cSrcweir         // replace images by RTL versions
380cdf0e10cSrcweir         maBackgroundLeft = BitmapEx( FwkResId( BMP_BACKING_BACKGROUND_RTL_RIGHT ) );
381cdf0e10cSrcweir         maBackgroundRight = BitmapEx( FwkResId( BMP_BACKING_BACKGROUND_RTL_LEFT) );
382cdf0e10cSrcweir     }
383cdf0e10cSrcweir     else
384cdf0e10cSrcweir     {
385cdf0e10cSrcweir         maBackgroundLeft = BitmapEx( FwkResId( BMP_BACKING_BACKGROUND_LEFT ) );
386cdf0e10cSrcweir         maBackgroundRight = BitmapEx( FwkResId( BMP_BACKING_BACKGROUND_RIGHT ) );
387cdf0e10cSrcweir     }
388cdf0e10cSrcweir     maToolbox.SetItemImage( nItemId_Extensions, BitmapEx( FwkResId( BMP_BACKING_EXT ) ) );
389*5ae32f77Smseidel //	maToolbox.SetItemImage( nItemId_Reg, BitmapEx( FwkResId( BMP_BACKING_REG ) ) );
390cdf0e10cSrcweir     maToolbox.SetItemImage( nItemId_Info, BitmapEx( FwkResId( BMP_BACKING_INFO ) ) );
391cdf0e10cSrcweir     maToolbox.SetItemImage( nItemId_TplRep, BitmapEx( FwkResId( BMP_BACKING_TPLREP ) ) );
392cdf0e10cSrcweir 
393cdf0e10cSrcweir     maWelcome.SetControlForeground( maWelcomeTextColor );
394cdf0e10cSrcweir     maWelcome.SetBackground();
395cdf0e10cSrcweir     maProduct.SetControlForeground( maWelcomeTextColor );
396cdf0e10cSrcweir     maProduct.SetBackground();
397cdf0e10cSrcweir 
398cdf0e10cSrcweir     if( mnLayoutStyle == 1 )
399cdf0e10cSrcweir     {
400cdf0e10cSrcweir         if( Application::GetSettings().GetLayoutRTL() )
401cdf0e10cSrcweir             mnBtnPos = maBackgroundRight.GetSizePixel().Width() + 40;
402cdf0e10cSrcweir         else
403cdf0e10cSrcweir             mnBtnPos = maBackgroundLeft.GetSizePixel().Width() + 40;
404cdf0e10cSrcweir     }
405cdf0e10cSrcweir 
406cdf0e10cSrcweir     // get icon images from fwk resource and set them on the appropriate buttons
407cdf0e10cSrcweir     loadImage( FwkResId( BMP_BACKING_WRITER ), maWriterButton );
408cdf0e10cSrcweir     loadImage( FwkResId( BMP_BACKING_CALC ), maCalcButton );
409cdf0e10cSrcweir     loadImage( FwkResId( BMP_BACKING_IMPRESS ), maImpressButton );
410cdf0e10cSrcweir     loadImage( FwkResId( BMP_BACKING_DRAW ), maDrawButton );
411cdf0e10cSrcweir     loadImage( FwkResId( BMP_BACKING_DATABASE ), maDBButton );
412cdf0e10cSrcweir     loadImage( FwkResId( BMP_BACKING_FORMULA ), maMathButton );
413cdf0e10cSrcweir     loadImage( FwkResId( BMP_BACKING_OPENFILE ), maOpenButton );
414cdf0e10cSrcweir     loadImage( FwkResId( BMP_BACKING_OPENTEMPLATE ), maTemplateButton );
415cdf0e10cSrcweir 
416cdf0e10cSrcweir     maOpenButton.SetMenuMode( MENUBUTTON_MENUMODE_TIMED );
417cdf0e10cSrcweir     maOpenButton.SetActivateHdl( LINK( this, BackingWindow, ActivateHdl ) );
418cdf0e10cSrcweir }
419cdf0e10cSrcweir 
initControls()420cdf0e10cSrcweir void BackingWindow::initControls()
421cdf0e10cSrcweir {
422cdf0e10cSrcweir     if( mbInitControls )
423cdf0e10cSrcweir         return;
424cdf0e10cSrcweir 
425cdf0e10cSrcweir     mbInitControls = true;
426cdf0e10cSrcweir 
427cdf0e10cSrcweir     // calculate dialog size
428cdf0e10cSrcweir     // begin with background bitmap
429cdf0e10cSrcweir     maControlRect = Rectangle( Point(), maBackgroundLeft.GetSizePixel() );
430cdf0e10cSrcweir     maControlRect.Left() += nShadowLeft;
431cdf0e10cSrcweir     maControlRect.Right() -= nShadowRight;
432cdf0e10cSrcweir     maControlRect.Top() += nShadowTop;
433cdf0e10cSrcweir     maControlRect.Bottom() -= nShadowBottom;
434cdf0e10cSrcweir 
435cdf0e10cSrcweir     long nYPos = 0;
436cdf0e10cSrcweir     // set bigger welcome string
437cdf0e10cSrcweir     maWelcome.SetText( maWelcomeString );
438cdf0e10cSrcweir     maTextFont = GetSettings().GetStyleSettings().GetLabelFont();
439cdf0e10cSrcweir     maTextFont.SetSize( Size( 0, 18 ) );
440cdf0e10cSrcweir     maTextFont.SetWeight( WEIGHT_BOLD );
441cdf0e10cSrcweir     maWelcome.SetFont( maTextFont );
442cdf0e10cSrcweir     // get metric to get correct width factor and adjust
443cdf0e10cSrcweir     long nW = (maWelcome.GetFontMetric().GetWidth()*95)/100;
444cdf0e10cSrcweir     maTextFont.SetSize( Size( nW, 18 ) );
445cdf0e10cSrcweir 
446cdf0e10cSrcweir     maWelcome.SetFont( maTextFont );
447cdf0e10cSrcweir     maWelcome.SetControlFont( maTextFont );
448cdf0e10cSrcweir     maWelcomeSize = Size( maWelcome.GetTextWidth( maWelcomeString ), maWelcome.GetTextHeight() );
449cdf0e10cSrcweir     maWelcomeSize.Width() = (maWelcomeSize.Width() * 20)/19;
450cdf0e10cSrcweir 
451cdf0e10cSrcweir     nYPos += (maWelcomeSize.Height()*3)/2;
452cdf0e10cSrcweir 
453cdf0e10cSrcweir     if( maControlRect.GetWidth() < mnBtnPos + maWelcomeSize.Width() + 20 )
454cdf0e10cSrcweir         maControlRect.Right() = maControlRect.Left() + maWelcomeSize.Width() + mnBtnPos + 20;
455cdf0e10cSrcweir 
456cdf0e10cSrcweir     nYPos += maWelcomeSize.Height();
457cdf0e10cSrcweir 
458cdf0e10cSrcweir     // set product string
459cdf0e10cSrcweir     maTextFont.SetSize( Size( 0, 30 ) );
460cdf0e10cSrcweir     maProduct.SetFont( maTextFont );
461cdf0e10cSrcweir 
462cdf0e10cSrcweir     // get metric to get correct width factor and adjust
463cdf0e10cSrcweir     nW = (maProduct.GetFontMetric().GetWidth()*95)/100;
464cdf0e10cSrcweir     maTextFont.SetSize( Size( nW, 28 ) );
465cdf0e10cSrcweir 
466cdf0e10cSrcweir     maProduct.SetFont( maTextFont );
467cdf0e10cSrcweir     maProduct.SetControlFont( maTextFont );
468cdf0e10cSrcweir     maProduct.SetText( maProductString );
469cdf0e10cSrcweir     maProductSize = Size( maProduct.GetTextWidth( maProductString ), maProduct.GetTextHeight() );
470cdf0e10cSrcweir     maProductSize.Width() = (maProductSize.Width() * 20)/19;
471cdf0e10cSrcweir 
472cdf0e10cSrcweir     if( maControlRect.GetWidth() < maProductSize.Width() + mnBtnPos + 10 )
473cdf0e10cSrcweir         maControlRect.Right() = maControlRect.Left() + maProductSize.Width() + mnBtnPos + 10;
474cdf0e10cSrcweir 
475cdf0e10cSrcweir     if( mnLayoutStyle == 1 )
476cdf0e10cSrcweir     {
477cdf0e10cSrcweir         maWelcome.Show();
478cdf0e10cSrcweir         maProduct.Show();
479cdf0e10cSrcweir     }
480cdf0e10cSrcweir 
481cdf0e10cSrcweir     nYPos += (maProductSize.Height()*3)/2;
482cdf0e10cSrcweir 
483cdf0e10cSrcweir     // set a slighly larger font than normal labels on the texts
484cdf0e10cSrcweir     maTextFont.SetSize( Size( 0, 11 ) );
485cdf0e10cSrcweir     maTextFont.SetWeight( WEIGHT_NORMAL );
486cdf0e10cSrcweir 
487cdf0e10cSrcweir     // collect the URLs of the entries in the File/New menu
488cdf0e10cSrcweir     SvtModuleOptions	aModuleOptions;
489cdf0e10cSrcweir     std::set< rtl::OUString > aFileNewAppsAvailable;
490cdf0e10cSrcweir     SvtDynamicMenuOptions aOpt;
491cdf0e10cSrcweir     Sequence < Sequence < PropertyValue > > aNewMenu = aOpt.GetMenu( E_NEWMENU );
492cdf0e10cSrcweir     const rtl::OUString sURLKey( RTL_CONSTASCII_USTRINGPARAM( "URL" ) );
493cdf0e10cSrcweir 
494cdf0e10cSrcweir     const Sequence< PropertyValue >* pNewMenu = aNewMenu.getConstArray();
495cdf0e10cSrcweir     const Sequence< PropertyValue >* pNewMenuEnd = aNewMenu.getConstArray() + aNewMenu.getLength();
496cdf0e10cSrcweir     for ( ; pNewMenu != pNewMenuEnd; ++pNewMenu )
497cdf0e10cSrcweir     {
498cdf0e10cSrcweir         comphelper::SequenceAsHashMap aEntryItems( *pNewMenu );
499cdf0e10cSrcweir         rtl::OUString sURL( aEntryItems.getUnpackedValueOrDefault( sURLKey, rtl::OUString() ) );
500cdf0e10cSrcweir         if ( sURL.getLength() )
501cdf0e10cSrcweir             aFileNewAppsAvailable.insert( sURL );
502cdf0e10cSrcweir     }
503cdf0e10cSrcweir 
504cdf0e10cSrcweir     // create mnemonics on the fly, preregister the mnemonics of the menu
505cdf0e10cSrcweir     MnemonicGenerator aMnemns;
506cdf0e10cSrcweir     maTemplateString = MnemonicGenerator::EraseAllMnemonicChars( maTemplateString );
507cdf0e10cSrcweir     maOpenString = MnemonicGenerator::EraseAllMnemonicChars( maOpenString );
508cdf0e10cSrcweir 
509cdf0e10cSrcweir     SystemWindow* pSysWin = GetSystemWindow();
510cdf0e10cSrcweir     if( pSysWin )
511cdf0e10cSrcweir     {
512cdf0e10cSrcweir         MenuBar* pMBar = pSysWin->GetMenuBar();
513cdf0e10cSrcweir         if( pMBar )
514cdf0e10cSrcweir         {
515cdf0e10cSrcweir             for( sal_uInt16 i = 0; i < pMBar->GetItemCount(); i++ )
516cdf0e10cSrcweir             {
517cdf0e10cSrcweir                 sal_uInt16 nItemId = pMBar->GetItemId( i );
518cdf0e10cSrcweir                 String aItemText( pMBar->GetItemText( nItemId ) );
519cdf0e10cSrcweir                 if( aItemText.Len() )
520cdf0e10cSrcweir                     aMnemns.RegisterMnemonic( aItemText );
521cdf0e10cSrcweir             }
522cdf0e10cSrcweir         }
523cdf0e10cSrcweir     }
524cdf0e10cSrcweir 
525cdf0e10cSrcweir     // layout the buttons
526cdf0e10cSrcweir     layoutButton( WRITER_URL, 0, aFileNewAppsAvailable,
527cdf0e10cSrcweir                   aModuleOptions, SvtModuleOptions::E_SWRITER,
528cdf0e10cSrcweir                   maWriterButton, aMnemns );
529cdf0e10cSrcweir     layoutButton( DRAW_URL, 1, aFileNewAppsAvailable,
530cdf0e10cSrcweir                   aModuleOptions, SvtModuleOptions::E_SDRAW,
531cdf0e10cSrcweir                   maDrawButton, aMnemns );
532cdf0e10cSrcweir     nYPos += maButtonImageSize.Height() + 10;
533cdf0e10cSrcweir     layoutButton( CALC_URL, 0, aFileNewAppsAvailable,
534cdf0e10cSrcweir                   aModuleOptions, SvtModuleOptions::E_SCALC,
535cdf0e10cSrcweir                   maCalcButton, aMnemns );
536cdf0e10cSrcweir     layoutButton( BASE_URL, 1, aFileNewAppsAvailable,
537cdf0e10cSrcweir                   aModuleOptions, SvtModuleOptions::E_SDATABASE,
538cdf0e10cSrcweir                   maDBButton, aMnemns );
539cdf0e10cSrcweir     nYPos += maButtonImageSize.Height() + 10;
540cdf0e10cSrcweir     layoutButton( IMPRESS_WIZARD_URL, 0, aFileNewAppsAvailable,
541cdf0e10cSrcweir                   aModuleOptions, SvtModuleOptions::E_SIMPRESS,
542cdf0e10cSrcweir                   maImpressButton, aMnemns );
543cdf0e10cSrcweir     layoutButton( MATH_URL, 1, aFileNewAppsAvailable,
544cdf0e10cSrcweir                   aModuleOptions, SvtModuleOptions::E_SMATH,
545cdf0e10cSrcweir                   maMathButton, aMnemns );
546cdf0e10cSrcweir 
547cdf0e10cSrcweir     nYPos += 3*maButtonImageSize.Height() / 2;
548cdf0e10cSrcweir 
549cdf0e10cSrcweir     layoutButton( NULL, 0, aFileNewAppsAvailable,
550cdf0e10cSrcweir                   aModuleOptions, SvtModuleOptions::E_SWRITER,
551cdf0e10cSrcweir                   maOpenButton, aMnemns, maOpenString );
552cdf0e10cSrcweir     layoutButton( NULL, 1, aFileNewAppsAvailable,
553cdf0e10cSrcweir                   aModuleOptions, SvtModuleOptions::E_SWRITER,
554cdf0e10cSrcweir                   maTemplateButton, aMnemns, maTemplateString );
555cdf0e10cSrcweir     nYPos += 10;
556cdf0e10cSrcweir 
557cdf0e10cSrcweir     DBG_ASSERT( nYPos < maControlRect.GetHeight(), "misformatting !" );
558cdf0e10cSrcweir     if( mnColumnWidth[0] + mnColumnWidth[1] + mnBtnPos + 20 > maControlRect.GetWidth() )
559cdf0e10cSrcweir         maControlRect.Right() = maControlRect.Left() + mnColumnWidth[0] + mnColumnWidth[1] + mnBtnPos + 20;
560cdf0e10cSrcweir 
561cdf0e10cSrcweir     mnTextColumnWidth[0] = mnColumnWidth[0];
562cdf0e10cSrcweir     mnTextColumnWidth[1] = mnColumnWidth[1];
563cdf0e10cSrcweir 
564cdf0e10cSrcweir     if( mnTextColumnWidth[1] > mnTextColumnWidth[0] )
565cdf0e10cSrcweir     {
566cdf0e10cSrcweir         mnColumnWidth[0]     = mnColumnWidth[1];
567cdf0e10cSrcweir         mnTextColumnWidth[0] = mnTextColumnWidth[1];
568cdf0e10cSrcweir     }
569cdf0e10cSrcweir     else
570cdf0e10cSrcweir     {
571cdf0e10cSrcweir         mnColumnWidth[1]     = mnColumnWidth[0];
572cdf0e10cSrcweir         mnTextColumnWidth[1] = mnTextColumnWidth[0];
573cdf0e10cSrcweir     }
574cdf0e10cSrcweir     if( maControlRect.GetWidth() < maControlRect.GetHeight() * 3 / 2 )
575cdf0e10cSrcweir     {
576cdf0e10cSrcweir         maControlRect.Right() = maControlRect.Left() + maControlRect.GetHeight() * 3 / 2;
577cdf0e10cSrcweir         long nDelta = (maControlRect.GetWidth() - mnBtnPos - mnColumnWidth[1] - mnColumnWidth[0] - 20);
578cdf0e10cSrcweir         mnColumnWidth[0] += nDelta/2;
579cdf0e10cSrcweir         mnColumnWidth[1] += nDelta/2;
580cdf0e10cSrcweir     }
581cdf0e10cSrcweir 
582cdf0e10cSrcweir     maToolbox.SetSelectHdl( LINK( this, BackingWindow, ToolboxHdl ) );
583cdf0e10cSrcweir     if( mnLayoutStyle == 0 )
584cdf0e10cSrcweir         maToolbox.Show();
585cdf0e10cSrcweir 
586cdf0e10cSrcweir     // scale middle map to formatted width
587cdf0e10cSrcweir     Size aMiddleSegmentSize( maControlRect.GetSize().Width() + nShadowLeft + nShadowRight,
588cdf0e10cSrcweir                              maBackgroundMiddle.GetSizePixel().Height() );
589cdf0e10cSrcweir 
590cdf0e10cSrcweir     long nLW = maBackgroundLeft.GetSizePixel().Width();
591cdf0e10cSrcweir     long nRW = maBackgroundRight.GetSizePixel().Width();
592cdf0e10cSrcweir     if( aMiddleSegmentSize.Width() > nLW + nRW )
593cdf0e10cSrcweir     {
594cdf0e10cSrcweir         aMiddleSegmentSize.Width() -= nLW;
595cdf0e10cSrcweir         aMiddleSegmentSize.Width() -= nRW;
596cdf0e10cSrcweir         maBackgroundMiddle.Scale( aMiddleSegmentSize );
597cdf0e10cSrcweir     }
598cdf0e10cSrcweir     else
599cdf0e10cSrcweir         maBackgroundMiddle = BitmapEx();
600cdf0e10cSrcweir 
601cdf0e10cSrcweir     Resize();
602cdf0e10cSrcweir 
603cdf0e10cSrcweir     maWriterButton.GrabFocus();
604cdf0e10cSrcweir }
605cdf0e10cSrcweir 
loadImage(const ResId & i_rId,PushButton & i_rButton)606cdf0e10cSrcweir void BackingWindow::loadImage( const ResId& i_rId, PushButton& i_rButton )
607cdf0e10cSrcweir {
608cdf0e10cSrcweir     BitmapEx aBmp( i_rId );
609cdf0e10cSrcweir     Size aImgSize( aBmp.GetSizePixel() );
610cdf0e10cSrcweir     if( aImgSize.Width() > maButtonImageSize.Width() )
611cdf0e10cSrcweir         maButtonImageSize.Width() = aImgSize.Width();
612cdf0e10cSrcweir     if( aImgSize.Height() > maButtonImageSize.Height() )
613cdf0e10cSrcweir         maButtonImageSize.Height() = aImgSize.Height();
614cdf0e10cSrcweir     i_rButton.SetModeImage( aBmp );
615cdf0e10cSrcweir }
616cdf0e10cSrcweir 
layoutButton(const char * i_pURL,int nColumn,const std::set<rtl::OUString> & i_rURLS,SvtModuleOptions & i_rOpt,SvtModuleOptions::EModule i_eMod,PushButton & i_rBtn,MnemonicGenerator & i_rMnemns,const String & i_rStr)617cdf0e10cSrcweir void BackingWindow::layoutButton(
618cdf0e10cSrcweir                           const char* i_pURL, int nColumn,
619cdf0e10cSrcweir                           const std::set<rtl::OUString>& i_rURLS,
620cdf0e10cSrcweir                           SvtModuleOptions& i_rOpt, SvtModuleOptions::EModule i_eMod,
621cdf0e10cSrcweir                           PushButton& i_rBtn,
622cdf0e10cSrcweir                           MnemonicGenerator& i_rMnemns,
623cdf0e10cSrcweir                           const String& i_rStr
624cdf0e10cSrcweir                           )
625cdf0e10cSrcweir {
626cdf0e10cSrcweir     rtl::OUString aURL( rtl::OUString::createFromAscii( i_pURL ? i_pURL : "" ) );
627cdf0e10cSrcweir     // setup button
628cdf0e10cSrcweir     i_rBtn.SetPaintTransparent( sal_True );
629cdf0e10cSrcweir     i_rBtn.SetClickHdl( LINK( this, BackingWindow, ClickHdl ) );
630cdf0e10cSrcweir     if( i_pURL && (! i_rOpt.IsModuleInstalled( i_eMod ) || i_rURLS.find( aURL ) == i_rURLS.end()) )
631cdf0e10cSrcweir     {
632cdf0e10cSrcweir         i_rBtn.Enable( sal_False );
633cdf0e10cSrcweir     }
634cdf0e10cSrcweir 
635cdf0e10cSrcweir     // setup text
636cdf0e10cSrcweir     i_rBtn.SetFont( maTextFont );
637cdf0e10cSrcweir     i_rBtn.SetControlFont( maTextFont );
638cdf0e10cSrcweir     String aText( i_rStr.Len() ? i_rStr : SvFileInformationManager::GetDescription( INetURLObject( aURL ) ) );
639cdf0e10cSrcweir     i_rMnemns.CreateMnemonic( aText );
640cdf0e10cSrcweir     i_rBtn.SetText( aText );
641cdf0e10cSrcweir 
642cdf0e10cSrcweir     long nTextWidth = i_rBtn.GetTextWidth( i_rBtn.GetText() );
643cdf0e10cSrcweir 
644cdf0e10cSrcweir     nTextWidth += maButtonImageSize.Width() + 8; // add some fuzz to be on the safe side
645cdf0e10cSrcweir     if( nColumn >= 0 && nColumn < static_cast<int>(sizeof(mnColumnWidth)/sizeof(mnColumnWidth[0])) )
646cdf0e10cSrcweir     {
647cdf0e10cSrcweir         if( nTextWidth > mnColumnWidth[nColumn] )
648cdf0e10cSrcweir             mnColumnWidth[nColumn] = nTextWidth;
649cdf0e10cSrcweir     }
650cdf0e10cSrcweir 
651cdf0e10cSrcweir     i_rBtn.SetImageAlign( IMAGEALIGN_LEFT );
652cdf0e10cSrcweir     // show the controls
653cdf0e10cSrcweir     i_rBtn.Show();
654cdf0e10cSrcweir }
655cdf0e10cSrcweir 
Paint(const Rectangle &)656cdf0e10cSrcweir void BackingWindow::Paint( const Rectangle& )
657cdf0e10cSrcweir {
6586e2074bdSHerbert Dürr 	Resize();
6596e2074bdSHerbert Dürr 
660cdf0e10cSrcweir     Wallpaper aBack( GetSettings().GetStyleSettings().GetWorkspaceGradient() );
661cdf0e10cSrcweir     Region aClip( Rectangle( Point( 0, 0 ), GetOutputSizePixel() ) );
662cdf0e10cSrcweir     Rectangle aBmpRect(maControlRect);
663cdf0e10cSrcweir     aBmpRect.Left()   -= nShadowLeft;
664cdf0e10cSrcweir     aBmpRect.Top()    -= nShadowTop;
665cdf0e10cSrcweir     aBmpRect.Right()  += nShadowRight;
666cdf0e10cSrcweir     aBmpRect.Bottom() += nShadowBottom;
667cdf0e10cSrcweir     aClip.Exclude( aBmpRect );
668cdf0e10cSrcweir     Push( PUSH_CLIPREGION );
669cdf0e10cSrcweir     IntersectClipRegion( aClip );
670cdf0e10cSrcweir     DrawWallpaper( Rectangle( Point( 0, 0 ), GetOutputSizePixel() ), aBack );
671cdf0e10cSrcweir     Pop();
672cdf0e10cSrcweir 
673cdf0e10cSrcweir     VirtualDevice aDev( *this );
674cdf0e10cSrcweir     aDev.EnableRTL( IsRTLEnabled() );
675cdf0e10cSrcweir     aDev.SetOutputSizePixel( aBmpRect.GetSize() );
676cdf0e10cSrcweir     Point aOffset( Point( 0, 0 ) - aBmpRect.TopLeft() );
677cdf0e10cSrcweir     aDev.DrawWallpaper( Rectangle( aOffset, GetOutputSizePixel() ), aBack );
678cdf0e10cSrcweir 
679cdf0e10cSrcweir     // draw bitmap
680cdf0e10cSrcweir     Point aTL( 0, 0 );
681cdf0e10cSrcweir     aDev.DrawBitmapEx( aTL, maBackgroundLeft );
682cdf0e10cSrcweir     aTL.X() += maBackgroundLeft.GetSizePixel().Width();
683cdf0e10cSrcweir     if( !!maBackgroundMiddle )
684cdf0e10cSrcweir     {
685cdf0e10cSrcweir         aDev.DrawBitmapEx( aTL, maBackgroundMiddle );
686cdf0e10cSrcweir         aTL.X() += maBackgroundMiddle.GetSizePixel().Width();
687cdf0e10cSrcweir     }
688cdf0e10cSrcweir     aDev.DrawBitmapEx( aTL, maBackgroundRight );
689cdf0e10cSrcweir 
690cdf0e10cSrcweir     DrawOutDev( aBmpRect.TopLeft(), aBmpRect.GetSize(),
691cdf0e10cSrcweir                 Point( 0, 0 ), aBmpRect.GetSize(),
692cdf0e10cSrcweir                 aDev );
693cdf0e10cSrcweir }
694cdf0e10cSrcweir 
Notify(NotifyEvent & rNEvt)695cdf0e10cSrcweir long BackingWindow::Notify( NotifyEvent& rNEvt )
696cdf0e10cSrcweir {
697cdf0e10cSrcweir     if( rNEvt.GetType() == EVENT_KEYINPUT )
698cdf0e10cSrcweir     {
699cdf0e10cSrcweir         if( ! mpAccExec )
700cdf0e10cSrcweir         {
701cdf0e10cSrcweir             mpAccExec = svt::AcceleratorExecute::createAcceleratorHelper();
702cdf0e10cSrcweir             mpAccExec->init( comphelper::getProcessServiceFactory(), mxFrame);
703cdf0e10cSrcweir         }
704cdf0e10cSrcweir 
705cdf0e10cSrcweir         const KeyEvent* pEvt = rNEvt.GetKeyEvent();
706cdf0e10cSrcweir         const KeyCode& rKeyCode(pEvt->GetKeyCode());
707cdf0e10cSrcweir         if( pEvt && mpAccExec->execute(rKeyCode) )
708cdf0e10cSrcweir             return 1;
709cdf0e10cSrcweir         // #i110344# extrawurst: specialized arrow key control
710cdf0e10cSrcweir         if( rKeyCode.GetModifier() == 0 )
711cdf0e10cSrcweir         {
712cdf0e10cSrcweir             if( rKeyCode.GetCode() == KEY_RIGHT )
713cdf0e10cSrcweir             {
714cdf0e10cSrcweir                 if( maWriterButton.HasFocus() )
715cdf0e10cSrcweir                     maDrawButton.GrabFocus();
716cdf0e10cSrcweir                 else if( maCalcButton.HasFocus() )
717cdf0e10cSrcweir                     maDBButton.GrabFocus();
718cdf0e10cSrcweir                 else if( maImpressButton.HasFocus() )
719cdf0e10cSrcweir                     maMathButton.GrabFocus();
720cdf0e10cSrcweir                 else if( maOpenButton.HasFocus() )
721cdf0e10cSrcweir                     maTemplateButton.GrabFocus();
722cdf0e10cSrcweir                 return 1;
723cdf0e10cSrcweir             }
724cdf0e10cSrcweir             else if( rKeyCode.GetCode() == KEY_LEFT )
725cdf0e10cSrcweir             {
726cdf0e10cSrcweir                 if( maDrawButton.HasFocus() )
727cdf0e10cSrcweir                     maWriterButton.GrabFocus();
728cdf0e10cSrcweir                 else if( maDBButton.HasFocus() )
729cdf0e10cSrcweir                     maCalcButton.GrabFocus();
730cdf0e10cSrcweir                 else if( maMathButton.HasFocus() )
731cdf0e10cSrcweir                     maImpressButton.GrabFocus();
732cdf0e10cSrcweir                 else if( maTemplateButton.HasFocus() )
733cdf0e10cSrcweir                     maOpenButton.GrabFocus();
734cdf0e10cSrcweir                 return 1;
735cdf0e10cSrcweir             }
736cdf0e10cSrcweir             else if( rKeyCode.GetCode() == KEY_UP )
737cdf0e10cSrcweir             {
738cdf0e10cSrcweir                 // first column
739cdf0e10cSrcweir                 if( maOpenButton.HasFocus() )
740cdf0e10cSrcweir                     maImpressButton.GrabFocus();
741cdf0e10cSrcweir                 else if( maImpressButton.HasFocus() )
742cdf0e10cSrcweir                     maCalcButton.GrabFocus();
743cdf0e10cSrcweir                 else if( maCalcButton.HasFocus() )
744cdf0e10cSrcweir                     maWriterButton.GrabFocus();
745cdf0e10cSrcweir                 // second column
746cdf0e10cSrcweir                 else if( maTemplateButton.HasFocus() )
747cdf0e10cSrcweir                     maMathButton.GrabFocus();
748cdf0e10cSrcweir                 else if( maMathButton.HasFocus() )
749cdf0e10cSrcweir                     maDBButton.GrabFocus();
750cdf0e10cSrcweir                 else if( maDBButton.HasFocus() )
751cdf0e10cSrcweir                     maDrawButton.GrabFocus();
752cdf0e10cSrcweir                 return 1;
753cdf0e10cSrcweir             }
754cdf0e10cSrcweir             else if( rKeyCode.GetCode() == KEY_DOWN )
755cdf0e10cSrcweir             {
756cdf0e10cSrcweir                 // first column
757cdf0e10cSrcweir                 if( maWriterButton.HasFocus() )
758cdf0e10cSrcweir                     maCalcButton.GrabFocus();
759cdf0e10cSrcweir                 else if( maCalcButton.HasFocus() )
760cdf0e10cSrcweir                     maImpressButton.GrabFocus();
761cdf0e10cSrcweir                 else if( maImpressButton.HasFocus() )
762cdf0e10cSrcweir                     maOpenButton.GrabFocus();
763cdf0e10cSrcweir                 // second column
764cdf0e10cSrcweir                 else if( maDrawButton.HasFocus() )
765cdf0e10cSrcweir                     maDBButton.GrabFocus();
766cdf0e10cSrcweir                 else if( maDBButton.HasFocus() )
767cdf0e10cSrcweir                     maMathButton.GrabFocus();
768cdf0e10cSrcweir                 else if( maMathButton.HasFocus() )
769cdf0e10cSrcweir                     maTemplateButton.GrabFocus();
770cdf0e10cSrcweir                 return 1;
771cdf0e10cSrcweir             }
772cdf0e10cSrcweir         }
773cdf0e10cSrcweir     }
774cdf0e10cSrcweir     return Window::Notify( rNEvt );
775cdf0e10cSrcweir }
776cdf0e10cSrcweir 
setOwningFrame(const com::sun::star::uno::Reference<com::sun::star::frame::XFrame> & xFrame)777cdf0e10cSrcweir void BackingWindow::setOwningFrame( const com::sun::star::uno::Reference< com::sun::star::frame::XFrame >& xFrame )
778cdf0e10cSrcweir {
779cdf0e10cSrcweir     mxFrame = xFrame;
780cdf0e10cSrcweir     if( ! mbInitControls )
781cdf0e10cSrcweir         initControls();
782cdf0e10cSrcweir }
783cdf0e10cSrcweir 
Resize()784cdf0e10cSrcweir void BackingWindow::Resize()
785cdf0e10cSrcweir {
786cdf0e10cSrcweir     Size aWindowSize( GetSizePixel() );
787cdf0e10cSrcweir     Size aControlSize = maControlRect.GetSize();
788cdf0e10cSrcweir     maControlRect = Rectangle( Point( (aWindowSize.Width() - aControlSize.Width()) / 2,
789cdf0e10cSrcweir                                       (aWindowSize.Height() - aControlSize.Height()) / 2 ),
790cdf0e10cSrcweir                                aControlSize );
791cdf0e10cSrcweir 
792cdf0e10cSrcweir     maToolbox.calcMinSize();
793cdf0e10cSrcweir     Size aTBSize( maToolbox.getMinSize() );
794cdf0e10cSrcweir     Point aTBPos( maControlRect.Left() + mnBtnPos,
795cdf0e10cSrcweir                   maControlRect.Bottom() - aTBSize.Height() - 10 );
796cdf0e10cSrcweir     if( Application::GetSettings().GetLayoutRTL() )
797cdf0e10cSrcweir         aTBPos.X() = maControlRect.Right() - aTBSize.Width() - mnBtnPos;
798cdf0e10cSrcweir     maToolbox.SetPosSizePixel( aTBPos, aTBSize );
799cdf0e10cSrcweir 
800cdf0e10cSrcweir     // #i93631# squeeze controls so they fit into the box
801cdf0e10cSrcweir     // this can be necessary due to application font height which has small deviations
802cdf0e10cSrcweir     // from the size set
803cdf0e10cSrcweir     const long nWDelta    = maWelcomeSize.Height();
804cdf0e10cSrcweir     const long nW2Delta   = (maWelcomeSize.Height()*3)/2;
805cdf0e10cSrcweir     const long nPDelta    = (maProductSize.Height()*3)/2;
806cdf0e10cSrcweir     const long nBDelta    = maButtonImageSize.Height() + 10;
807cdf0e10cSrcweir     const long nB2Delta   = 3*maButtonImageSize.Height()/2;
808cdf0e10cSrcweir     const long nLastDelta = maButtonImageSize.Height();
809cdf0e10cSrcweir     long nDiff = 0;
810cdf0e10cSrcweir     while( ( maControlRect.Top()   +
811cdf0e10cSrcweir                  (nWDelta - nDiff) +
812cdf0e10cSrcweir                  (nW2Delta- nDiff) +
813cdf0e10cSrcweir                  (nPDelta - nDiff) +
814cdf0e10cSrcweir              3 * (nBDelta - nDiff) +
815cdf0e10cSrcweir                  (nB2Delta- nDiff) +
816cdf0e10cSrcweir                  nLastDelta
817cdf0e10cSrcweir             ) > aTBPos.Y() )
818cdf0e10cSrcweir     {
819cdf0e10cSrcweir         nDiff++;
820cdf0e10cSrcweir     }
821cdf0e10cSrcweir 
822cdf0e10cSrcweir     long nYPos = maControlRect.Top();
823cdf0e10cSrcweir     nYPos += nW2Delta - nDiff;
824cdf0e10cSrcweir     maWelcome.SetPosSizePixel( Point( maControlRect.Left() + mnBtnPos, nYPos ),
825cdf0e10cSrcweir                                 Size( maControlRect.GetWidth() - mnBtnPos - 5, (maWelcomeSize.Height()*20)/19 ) );
826cdf0e10cSrcweir     nYPos += nWDelta - nDiff;
827cdf0e10cSrcweir     maProduct.SetPosSizePixel( Point( maControlRect.Left() + mnBtnPos, nYPos ), Size( maControlRect.GetWidth() - mnBtnPos - 5, (maProductSize.Height()*20)/19 ) );
828cdf0e10cSrcweir     nYPos += nPDelta - nDiff;
829cdf0e10cSrcweir 
830cdf0e10cSrcweir     nYPos += nWDelta/2 - nDiff;
831cdf0e10cSrcweir 
832cdf0e10cSrcweir     if( mnLayoutStyle != 1 )
833cdf0e10cSrcweir         nYPos = maControlRect.Top() + mnBtnTop;
834cdf0e10cSrcweir 
835cdf0e10cSrcweir     maWriterButton.SetPosSizePixel( Point( maControlRect.Left() + mnBtnPos, nYPos ), Size( mnTextColumnWidth[0], maButtonImageSize.Height() ) );
836cdf0e10cSrcweir     maDrawButton.SetPosSizePixel( Point( maControlRect.Left() + mnBtnPos + mnColumnWidth[0], nYPos ), Size( mnTextColumnWidth[1], maButtonImageSize.Height() ) );
837cdf0e10cSrcweir     nYPos += nBDelta - nDiff;
838cdf0e10cSrcweir     maCalcButton.SetPosSizePixel( Point( maControlRect.Left() + mnBtnPos, nYPos ), Size( mnTextColumnWidth[0], maButtonImageSize.Height() ) );
839cdf0e10cSrcweir     maDBButton.SetPosSizePixel( Point( maControlRect.Left() + mnBtnPos + mnColumnWidth[0], nYPos ), Size( mnTextColumnWidth[1], maButtonImageSize.Height() ) );
840cdf0e10cSrcweir     nYPos += nBDelta - nDiff;
841cdf0e10cSrcweir     maImpressButton.SetPosSizePixel( Point( maControlRect.Left() + mnBtnPos, nYPos ), Size( mnTextColumnWidth[0], maButtonImageSize.Height() ) );
842cdf0e10cSrcweir     maMathButton.SetPosSizePixel( Point( maControlRect.Left() + mnBtnPos + mnColumnWidth[0], nYPos ), Size( mnTextColumnWidth[1], maButtonImageSize.Height() ) );
843cdf0e10cSrcweir 
844cdf0e10cSrcweir     nYPos += nB2Delta - nDiff;
845cdf0e10cSrcweir     maOpenButton.SetPosSizePixel( Point( maControlRect.Left() + mnBtnPos, nYPos ), Size( mnTextColumnWidth[0], maButtonImageSize.Height() ) );
846cdf0e10cSrcweir     maTemplateButton.SetPosSizePixel( Point( maControlRect.Left() + mnBtnPos + mnColumnWidth[0], nYPos ), Size( mnTextColumnWidth[1], maButtonImageSize.Height() ) );
8476e2074bdSHerbert Dürr 
8486e2074bdSHerbert Dürr 	if( !IsInPaint())
8496e2074bdSHerbert Dürr 		Invalidate();
850cdf0e10cSrcweir }
851cdf0e10cSrcweir 
IMPL_LINK(BackingWindow,ToolboxHdl,void *,EMPTYARG)852cdf0e10cSrcweir IMPL_LINK( BackingWindow, ToolboxHdl, void*, EMPTYARG )
853cdf0e10cSrcweir {
854cdf0e10cSrcweir     const char* pNodePath = NULL;
855cdf0e10cSrcweir     const char* pNode = NULL;
856cdf0e10cSrcweir 
857cdf0e10cSrcweir     switch( maToolbox.GetCurItemId() )
858cdf0e10cSrcweir     {
859cdf0e10cSrcweir     case nItemId_Extensions:
860cdf0e10cSrcweir         pNodePath = "/org.openoffice.Office.Common/Help/StartCenter";
861cdf0e10cSrcweir         pNode = "AddFeatureURL";
862cdf0e10cSrcweir         break;
863cdf0e10cSrcweir     case nItemId_Info:
864cdf0e10cSrcweir         pNodePath = "/org.openoffice.Office.Common/Help/StartCenter";
865cdf0e10cSrcweir         pNode = "InfoURL";
866cdf0e10cSrcweir         break;
867cdf0e10cSrcweir     case nItemId_TplRep:
868cdf0e10cSrcweir         pNodePath = "/org.openoffice.Office.Common/Help/StartCenter";
869cdf0e10cSrcweir         pNode = "TemplateRepositoryURL";
870cdf0e10cSrcweir         break;
871cdf0e10cSrcweir     default:
872cdf0e10cSrcweir         break;
873cdf0e10cSrcweir     }
874cdf0e10cSrcweir     if( pNodePath && pNode )
875cdf0e10cSrcweir     {
876cdf0e10cSrcweir         try
877cdf0e10cSrcweir         {
878cdf0e10cSrcweir             Reference<lang::XMultiServiceFactory> xConfig( comphelper::getProcessServiceFactory()->createInstance(SERVICENAME_CFGPROVIDER),UNO_QUERY);
879cdf0e10cSrcweir             if( xConfig.is() )
880cdf0e10cSrcweir             {
881cdf0e10cSrcweir                 Sequence<Any> args(1);
882cdf0e10cSrcweir                 PropertyValue val(
883cdf0e10cSrcweir                     rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("nodepath") ),
884cdf0e10cSrcweir                     0,
885cdf0e10cSrcweir                     Any(rtl::OUString::createFromAscii(pNodePath)),
886cdf0e10cSrcweir                     PropertyState_DIRECT_VALUE);
887cdf0e10cSrcweir                 args.getArray()[0] <<= val;
888cdf0e10cSrcweir                 Reference<container::XNameAccess> xNameAccess(xConfig->createInstanceWithArguments(SERVICENAME_CFGREADACCESS,args), UNO_QUERY);
889cdf0e10cSrcweir                 if( xNameAccess.is() )
890cdf0e10cSrcweir                 {
891cdf0e10cSrcweir                     rtl::OUString sURL;
892cdf0e10cSrcweir                     //throws css::container::NoSuchElementException, css::lang::WrappedTargetException
893cdf0e10cSrcweir                     Any value( xNameAccess->getByName(rtl::OUString::createFromAscii(pNode)) );
894cdf0e10cSrcweir                     sURL = value.get<rtl::OUString> ();
895cdf0e10cSrcweir 
896cdf0e10cSrcweir                     // extend the URLs with Office locale argument
897cdf0e10cSrcweir                     INetURLObject aURLObj( sURL );
898cdf0e10cSrcweir 
899cdf0e10cSrcweir                     rtl::OUString sParam = aURLObj.GetParam();
900cdf0e10cSrcweir                     rtl::OUStringBuffer aURLBuf( sParam );
901cdf0e10cSrcweir                     if ( sParam.getLength() > 0 )
902cdf0e10cSrcweir                         aURLBuf.appendAscii( "&" );
903cdf0e10cSrcweir                     aURLBuf.appendAscii( "lang=" );
904cdf0e10cSrcweir 
905cdf0e10cSrcweir                     // read locale from configuration
906cdf0e10cSrcweir                     ::rtl::OUString sLocale;
907cdf0e10cSrcweir                     ::rtl::OUString sPackage = ::rtl::OUString::createFromAscii("org.openoffice.Setup");
908cdf0e10cSrcweir                     ::rtl::OUString sRelPath = ::rtl::OUString::createFromAscii("L10N");
909cdf0e10cSrcweir                     ::rtl::OUString sKey     = ::rtl::OUString::createFromAscii("ooLocale");
910cdf0e10cSrcweir 
911cdf0e10cSrcweir                     try
912cdf0e10cSrcweir                     {
913cdf0e10cSrcweir                         ::comphelper::ConfigurationHelper::readDirectKey(comphelper::getProcessServiceFactory(),
914cdf0e10cSrcweir                                                                          sPackage,
915cdf0e10cSrcweir                                                                          sRelPath,
916cdf0e10cSrcweir                                                                          sKey,
917cdf0e10cSrcweir                                                                          ::comphelper::ConfigurationHelper::E_READONLY) >>= sLocale;
918cdf0e10cSrcweir                     }
919cdf0e10cSrcweir                     catch(const com::sun::star::uno::RuntimeException& exRun)
920cdf0e10cSrcweir                         { throw exRun; }
921cdf0e10cSrcweir                     catch(const com::sun::star::uno::Exception&)
922cdf0e10cSrcweir                     { sLocale = ::rtl::OUString::createFromAscii("en-US"); }
923cdf0e10cSrcweir 
924cdf0e10cSrcweir                     aURLBuf.append(sLocale);
925cdf0e10cSrcweir 
926cdf0e10cSrcweir                     sParam = aURLBuf.makeStringAndClear();
927cdf0e10cSrcweir 
928cdf0e10cSrcweir                     aURLObj.SetParam( sParam );
929cdf0e10cSrcweir                     sURL = aURLObj.GetMainURL( INetURLObject::NO_DECODE );
930cdf0e10cSrcweir 
931cdf0e10cSrcweir                     Reference< com::sun::star::system::XSystemShellExecute > xSystemShellExecute(
9329807c9deSAriel Constenla-Haile                         com::sun::star::system::SystemShellExecute::create(
9339807c9deSAriel Constenla-Haile                             ::comphelper::getProcessComponentContext() ) );
934cdf0e10cSrcweir                     //throws css::lang::IllegalArgumentException, css::system::SystemShellExecuteException
935cdf0e10cSrcweir                     xSystemShellExecute->execute( sURL, rtl::OUString(), com::sun::star::system::SystemShellExecuteFlags::DEFAULTS);
936cdf0e10cSrcweir                 }
937cdf0e10cSrcweir             }
938cdf0e10cSrcweir         }
939cdf0e10cSrcweir         catch (Exception& )
940cdf0e10cSrcweir         {
941cdf0e10cSrcweir         }
942cdf0e10cSrcweir     }
943cdf0e10cSrcweir 
944cdf0e10cSrcweir     return 0;
945cdf0e10cSrcweir }
946cdf0e10cSrcweir 
IMPL_LINK(BackingWindow,ClickHdl,Button *,pButton)947cdf0e10cSrcweir IMPL_LINK( BackingWindow, ClickHdl, Button*, pButton )
948cdf0e10cSrcweir {
949cdf0e10cSrcweir     // dispatch the appropriate URL and end the dialog
950cdf0e10cSrcweir     if( pButton == &maWriterButton )
951cdf0e10cSrcweir         dispatchURL( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(WRITER_URL) ) );
952cdf0e10cSrcweir     else if( pButton == &maCalcButton )
953cdf0e10cSrcweir         dispatchURL( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(CALC_URL) ) );
954cdf0e10cSrcweir     else if( pButton == &maImpressButton )
955cdf0e10cSrcweir         dispatchURL( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(IMPRESS_WIZARD_URL) ) );
956cdf0e10cSrcweir     else if( pButton == &maDrawButton )
957cdf0e10cSrcweir         dispatchURL( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(DRAW_URL) ) );
958cdf0e10cSrcweir     else if( pButton == &maDBButton )
959cdf0e10cSrcweir         dispatchURL( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(BASE_URL) ) );
960cdf0e10cSrcweir     else if( pButton == &maMathButton )
961cdf0e10cSrcweir         dispatchURL( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(MATH_URL) ) );
962cdf0e10cSrcweir     else if( pButton == &maOpenButton )
963cdf0e10cSrcweir     {
964cdf0e10cSrcweir         Reference< XDispatchProvider > xFrame( mxFrame, UNO_QUERY );
965cdf0e10cSrcweir 
966cdf0e10cSrcweir         Sequence< com::sun::star::beans::PropertyValue > aArgs(1);
967cdf0e10cSrcweir         PropertyValue* pArg = aArgs.getArray();
968cdf0e10cSrcweir         pArg[0].Name = rtl::OUString::createFromAscii("Referer");
969cdf0e10cSrcweir         pArg[0].Value <<= rtl::OUString::createFromAscii("private:user");
970cdf0e10cSrcweir 
971cdf0e10cSrcweir         dispatchURL( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(OPEN_URL) ), rtl::OUString(), xFrame, aArgs );
972cdf0e10cSrcweir     }
973cdf0e10cSrcweir     else if( pButton == &maTemplateButton )
974cdf0e10cSrcweir     {
975cdf0e10cSrcweir         Reference< XDispatchProvider > xFrame( mxFrame, UNO_QUERY );
976cdf0e10cSrcweir 
977cdf0e10cSrcweir         Sequence< com::sun::star::beans::PropertyValue > aArgs(1);
978cdf0e10cSrcweir         PropertyValue* pArg = aArgs.getArray();
979cdf0e10cSrcweir         pArg[0].Name = rtl::OUString::createFromAscii("Referer");
980cdf0e10cSrcweir         pArg[0].Value <<= rtl::OUString::createFromAscii("private:user");
981cdf0e10cSrcweir 
982cdf0e10cSrcweir         dispatchURL( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(TEMPLATE_URL) ), rtl::OUString(), xFrame, aArgs );
983cdf0e10cSrcweir     }
984cdf0e10cSrcweir     return 0;
985cdf0e10cSrcweir }
986cdf0e10cSrcweir 
987cdf0e10cSrcweir 
IMPL_LINK(BackingWindow,ActivateHdl,Button *,pButton)988cdf0e10cSrcweir IMPL_LINK( BackingWindow, ActivateHdl, Button*, pButton )
989cdf0e10cSrcweir {
990cdf0e10cSrcweir     if( pButton == &maOpenButton )
991cdf0e10cSrcweir         prepareRecentFileMenu();
992cdf0e10cSrcweir     return 0;
993cdf0e10cSrcweir }
994cdf0e10cSrcweir 
995cdf0e10cSrcweir struct ImplDelayedDispatch
996cdf0e10cSrcweir {
997cdf0e10cSrcweir     Reference< XDispatch >      xDispatch;
998cdf0e10cSrcweir     com::sun::star::util::URL   aDispatchURL;
999cdf0e10cSrcweir     Sequence< PropertyValue >   aArgs;
1000cdf0e10cSrcweir 
ImplDelayedDispatchImplDelayedDispatch1001cdf0e10cSrcweir     ImplDelayedDispatch( const Reference< XDispatch >& i_xDispatch,
1002cdf0e10cSrcweir                          const com::sun::star::util::URL& i_rURL,
1003cdf0e10cSrcweir                          const Sequence< PropertyValue >& i_rArgs )
1004cdf0e10cSrcweir     : xDispatch( i_xDispatch ),
1005cdf0e10cSrcweir       aDispatchURL( i_rURL ),
1006cdf0e10cSrcweir       aArgs( i_rArgs )
1007cdf0e10cSrcweir     {
1008cdf0e10cSrcweir     }
~ImplDelayedDispatchImplDelayedDispatch1009cdf0e10cSrcweir     ~ImplDelayedDispatch() {}
1010cdf0e10cSrcweir };
1011cdf0e10cSrcweir 
implDispatchDelayed(void *,void * pArg)1012cdf0e10cSrcweir static long implDispatchDelayed( void*, void* pArg )
1013cdf0e10cSrcweir {
1014cdf0e10cSrcweir     struct ImplDelayedDispatch* pDispatch = reinterpret_cast<ImplDelayedDispatch*>(pArg);
1015cdf0e10cSrcweir     try
1016cdf0e10cSrcweir     {
1017cdf0e10cSrcweir         pDispatch->xDispatch->dispatch( pDispatch->aDispatchURL, pDispatch->aArgs );
1018cdf0e10cSrcweir     }
1019cdf0e10cSrcweir     catch( Exception )
1020cdf0e10cSrcweir     {
1021cdf0e10cSrcweir     }
1022cdf0e10cSrcweir 
1023cdf0e10cSrcweir     // clean up
1024cdf0e10cSrcweir     delete pDispatch;
1025cdf0e10cSrcweir 
1026cdf0e10cSrcweir     return 0;
1027cdf0e10cSrcweir }
1028cdf0e10cSrcweir 
dispatchURL(const rtl::OUString & i_rURL,const rtl::OUString & rTarget,const Reference<XDispatchProvider> & i_xProv,const Sequence<PropertyValue> & i_rArgs)1029cdf0e10cSrcweir void BackingWindow::dispatchURL( const rtl::OUString& i_rURL,
1030cdf0e10cSrcweir                                  const rtl::OUString& rTarget,
1031cdf0e10cSrcweir                                  const Reference< XDispatchProvider >& i_xProv,
1032cdf0e10cSrcweir                                  const Sequence< PropertyValue >& i_rArgs )
1033cdf0e10cSrcweir {
1034cdf0e10cSrcweir     // if no special dispatch provider is given, get the desktop
1035cdf0e10cSrcweir     Reference< XDispatchProvider > xProvider( i_xProv.is() ? i_xProv : mxDesktopDispatchProvider );
1036cdf0e10cSrcweir 
1037cdf0e10cSrcweir     // check for dispatch provider
1038cdf0e10cSrcweir     if( !xProvider.is())
1039cdf0e10cSrcweir         return;
1040cdf0e10cSrcweir 
1041cdf0e10cSrcweir     // get an URL transformer to clean up the URL
1042cdf0e10cSrcweir     com::sun::star::util::URL aDispatchURL;
1043cdf0e10cSrcweir     aDispatchURL.Complete = i_rURL;
1044cdf0e10cSrcweir 
1045cdf0e10cSrcweir     Reference < com::sun::star::util::XURLTransformer > xURLTransformer(
1046cdf0e10cSrcweir         comphelper::getProcessServiceFactory()->createInstance( rtl::OUString::createFromAscii("com.sun.star.util.URLTransformer") ),
1047cdf0e10cSrcweir         com::sun::star::uno::UNO_QUERY );
1048cdf0e10cSrcweir     if ( xURLTransformer.is() )
1049cdf0e10cSrcweir     {
1050cdf0e10cSrcweir         try
1051cdf0e10cSrcweir         {
1052cdf0e10cSrcweir             // clean up the URL
1053cdf0e10cSrcweir             xURLTransformer->parseStrict( aDispatchURL );
1054cdf0e10cSrcweir             // get a Dispatch for the URL and target
1055cdf0e10cSrcweir             Reference< XDispatch > xDispatch(
1056cdf0e10cSrcweir                 xProvider->queryDispatch( aDispatchURL, rTarget, 0 )
1057cdf0e10cSrcweir                 );
1058cdf0e10cSrcweir             // dispatch the URL
1059cdf0e10cSrcweir             if ( xDispatch.is() )
1060cdf0e10cSrcweir             {
1061cdf0e10cSrcweir                 ImplDelayedDispatch* pDisp = new ImplDelayedDispatch( xDispatch, aDispatchURL, i_rArgs );
1062cdf0e10cSrcweir                 sal_uLong nEventId = 0;
1063cdf0e10cSrcweir                 if( ! Application::PostUserEvent( nEventId, Link( NULL, implDispatchDelayed ), pDisp ) )
1064cdf0e10cSrcweir                     delete pDisp; // event could not be posted for unknown reason, at least don't leak
1065cdf0e10cSrcweir             }
1066cdf0e10cSrcweir         }
1067cdf0e10cSrcweir         catch ( com::sun::star::uno::RuntimeException& )
1068cdf0e10cSrcweir         {
1069cdf0e10cSrcweir             throw;
1070cdf0e10cSrcweir         }
1071cdf0e10cSrcweir         catch ( com::sun::star::uno::Exception& )
1072cdf0e10cSrcweir         {
1073cdf0e10cSrcweir         }
1074cdf0e10cSrcweir     }
1075cdf0e10cSrcweir }
1076cdf0e10cSrcweir 
1077