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