merge the formfield patch from ooo-build
[ooovba.git] / framework / source / services / backingwindow.cxx
blob0531478ce1cb00baf95853b37334f11f9dfbcb37
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: backingwindow.cxx,v $
10 * $Revision: 1.12 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // autogen include statement, do not remove
32 #include "precompiled_framework.hxx"
34 #include "backingwindow.hxx"
35 #include "framework.hrc"
36 #include "classes/fwkresid.hxx"
37 #include <services.h>
39 #include "vcl/metric.hxx"
40 #include "vcl/mnemonic.hxx"
41 #include "vcl/menu.hxx"
42 #include "vcl/svapp.hxx"
44 #include "tools/urlobj.hxx"
46 #include "svtools/dynamicmenuoptions.hxx"
47 #include "svtools/imagemgr.hxx"
48 #include "svtools/svtools.hrc"
50 #include "comphelper/processfactory.hxx"
51 #include "comphelper/sequenceashashmap.hxx"
53 #include "rtl/strbuf.hxx"
54 #include "rtl/ustrbuf.hxx"
56 #include "com/sun/star/lang/XMultiServiceFactory.hpp"
57 #include "com/sun/star/container/XNameAccess.hpp"
58 #include "com/sun/star/system/XSystemShellExecute.hpp"
59 #include "com/sun/star/system/SystemShellExecuteFlags.hpp"
60 #include "com/sun/star/task/XJobExecutor.hpp"
63 using namespace ::com::sun::star::beans;
64 using namespace ::com::sun::star::frame;
65 using namespace ::com::sun::star::uno;
66 using namespace ::com::sun::star;
67 using namespace framework;
69 #define WRITER_URL "private:factory/swriter"
70 #define CALC_URL "private:factory/scalc"
71 #define IMPRESS_WIZARD_URL "private:factory/simpress?slot=6686"
72 #define DRAW_URL "private:factory/sdraw"
73 #define BASE_URL "private:factory/sdatabase?Interactive"
74 #define MATH_URL "private:factory/smath"
75 #define TEMPLATE_URL "slot:5500"
76 #define OPEN_URL ".uno:Open"
78 DecoToolBox::DecoToolBox( Window* pParent, WinBits nStyle ) :
79 ToolBox( pParent, nStyle )
81 SetBackground();
82 SetPaintTransparent( TRUE );
85 void DecoToolBox::DataChanged( const DataChangedEvent& rDCEvt )
87 Window::DataChanged( rDCEvt );
89 if ( rDCEvt.GetFlags() & SETTINGS_STYLE )
91 calcMinSize();
92 SetBackground();
93 SetPaintTransparent( TRUE );
97 void DecoToolBox::calcMinSize()
99 ToolBox aTbx( GetParent() );
100 USHORT nItems = GetItemCount();
101 for( USHORT i = 0; i < nItems; i++ )
103 USHORT nId = GetItemId( i );
104 aTbx.InsertItem( nId, GetItemImage( nId ) );
106 aTbx.SetOutStyle( TOOLBOX_STYLE_FLAT );
107 maMinSize = aTbx.CalcWindowSizePixel();
110 Size DecoToolBox::getMinSize()
112 return maMinSize;
116 BackingWindow::BackingWindow( Window* i_pParent ) :
117 Window( i_pParent, FwkResId( DLG_BACKING ) ),
118 maWelcome( this, WB_LEFT ),
119 maProduct( this, WB_LEFT ),
120 maCreateText( this, WB_LEFT ),
121 maWriterText( this, WB_WORDBREAK | WB_VCENTER ),
122 maWriterButton( this, WB_CENTER | WB_BEVELBUTTON ),
123 maCalcText( this, WB_WORDBREAK | WB_VCENTER ),
124 maCalcButton( this, WB_CENTER | WB_BEVELBUTTON ),
125 maImpressText( this, WB_WORDBREAK | WB_VCENTER ),
126 maImpressButton( this, WB_CENTER | WB_BEVELBUTTON ),
127 maDrawText( this, WB_WORDBREAK | WB_VCENTER ),
128 maDrawButton( this, WB_CENTER | WB_BEVELBUTTON ),
129 maDBText( this, WB_WORDBREAK | WB_VCENTER ),
130 maDBButton( this, WB_CENTER | WB_BEVELBUTTON ),
131 maMathText( this, WB_WORDBREAK | WB_VCENTER ),
132 maMathButton( this, WB_CENTER | WB_BEVELBUTTON ),
133 maTemplateText( this, WB_WORDBREAK | WB_VCENTER ),
134 maTemplateButton( this, WB_CENTER | WB_BEVELBUTTON ),
135 maOpenText( this, WB_WORDBREAK | WB_VCENTER ),
136 maOpenButton( this, WB_CENTER | WB_BEVELBUTTON ),
137 maToolbox( this, WB_DIALOGCONTROL ),
138 maWelcomeString( FwkResId( STR_BACKING_WELCOME ) ),
139 maProductString( FwkResId( STR_BACKING_WELCOMEPRODUCT ) ),
140 maCreateString( FwkResId( STR_BACKING_CREATE ) ),
141 maOpenString( FwkResId( STR_BACKING_FILE ) ),
142 maTemplateString( FwkResId( STR_BACKING_TEMPLATE ) ),
143 maButtonImageSize( 10, 10 ),
144 mbInitControls( false ),
145 mpAccExec( NULL )
147 mnColumnWidth[0] = mnColumnWidth[1] = 0;
149 // get icon images from vcl resource and set them on the appropriate buttons
150 loadImage( FwkResId( BMP_BACKING_WRITER ), maWriterButton );
151 loadImage( FwkResId( BMP_BACKING_CALC ), maCalcButton );
152 loadImage( FwkResId( BMP_BACKING_IMPRESS ), maImpressButton );
153 loadImage( FwkResId( BMP_BACKING_DRAW ), maDrawButton );
154 loadImage( FwkResId( BMP_BACKING_DATABASE ), maDBButton );
155 loadImage( FwkResId( BMP_BACKING_FORMULA ), maMathButton );
156 loadImage( FwkResId( BMP_BACKING_OPENFILE ), maOpenButton );
157 loadImage( FwkResId( BMP_BACKING_OPENTEMPLATE ), maTemplateButton );
159 BitmapEx aExtImage( FwkResId( BMP_BACKING_EXT ) );
160 String aExtHelpText( FwkResId( STR_BACKING_EXTHELP ) );
161 BitmapEx aInfoImage( FwkResId( BMP_BACKING_INFO ) );
162 String aInfoHelpText( FwkResId( STR_BACKING_INFOHELP ) );
163 BitmapEx aTplRepImage( FwkResId( BMP_BACKING_TPLREP ) );
164 String aTplRepHelpText( FwkResId( STR_BACKING_TPLREP ) );
166 // clean up resource stack
167 FreeResource();
169 maWelcome.SetPaintTransparent( TRUE );
170 maProduct.SetPaintTransparent( TRUE );
171 EnableChildTransparentMode();
173 SetStyle( GetStyle() | WB_DIALOGCONTROL );
175 // add some breathing space for the images
176 maButtonImageSize.Width() += 12;
177 maButtonImageSize.Height() += 12;
179 // force tab cycling in toolbox
180 maToolbox.SetStyle( maToolbox.GetStyle() | WB_FORCETABCYCLE );
182 // insert toolbox items
183 maToolbox.InsertItem( nItemId_TplRep, Image( aTplRepImage ) );
184 maToolbox.SetItemText( nItemId_TplRep, aTplRepHelpText );
185 maToolbox.SetQuickHelpText( nItemId_TplRep, aTplRepHelpText );
186 maToolbox.SetItemCommand( nItemId_TplRep, String( RTL_CONSTASCII_USTRINGPARAM( ".HelpId:StartCenter:TemplateRepository" ) ) );
187 maToolbox.ShowItem( nItemId_TplRep );
189 maToolbox.InsertItem( nItemId_Extensions, Image( aExtImage ) );
190 maToolbox.SetQuickHelpText( nItemId_Extensions, aExtHelpText );
191 maToolbox.SetItemText( nItemId_Extensions, aExtHelpText );
192 maToolbox.SetItemCommand( nItemId_Extensions, String( RTL_CONSTASCII_USTRINGPARAM( ".HelpId:StartCenter:Extensions" ) ) );
193 maToolbox.ShowItem( nItemId_Extensions );
195 maToolbox.InsertItem( nItemId_Info, Image( aInfoImage ) );
196 maToolbox.SetItemText( nItemId_Info, aInfoHelpText );
197 maToolbox.SetQuickHelpText( nItemId_Info, aInfoHelpText );
198 maToolbox.SetItemCommand( nItemId_Info, String( RTL_CONSTASCII_USTRINGPARAM( ".HelpId:StartCenter:Info" ) ) );
199 maToolbox.ShowItem( nItemId_Info );
201 // get dispatch provider
202 mxDesktop = Reference<XDesktop>( comphelper::getProcessServiceFactory()->createInstance(SERVICENAME_DESKTOP ),UNO_QUERY );
203 if( mxDesktop.is() )
204 mxDesktopDispatchProvider = Reference< XDispatchProvider >( mxDesktop, UNO_QUERY );
206 maWriterButton.SetSmartHelpId( SmartId( String( RTL_CONSTASCII_USTRINGPARAM( ".HelpId:StartCenter:WriterButton" ) ) ) );
207 maCalcButton.SetSmartHelpId( SmartId( String( RTL_CONSTASCII_USTRINGPARAM( ".HelpId:StartCenter:CalcButton" ) ) ) );
208 maImpressButton.SetSmartHelpId( SmartId( String( RTL_CONSTASCII_USTRINGPARAM( ".HelpId:StartCenter:ImpressButton" ) ) ) );
209 maDrawButton.SetSmartHelpId( SmartId( String( RTL_CONSTASCII_USTRINGPARAM( ".HelpId:StartCenter:DrawButton" ) ) ) );
210 maDBButton.SetSmartHelpId( SmartId( String( RTL_CONSTASCII_USTRINGPARAM( ".HelpId:StartCenter:DBButton" ) ) ) );
211 maMathButton.SetSmartHelpId( SmartId( String( RTL_CONSTASCII_USTRINGPARAM( ".HelpId:StartCenter:MathButton" ) ) ) );
212 maTemplateButton.SetSmartHelpId( SmartId( String( RTL_CONSTASCII_USTRINGPARAM( ".HelpId:StartCenter:TemplateButton" ) ) ) );
213 maOpenButton.SetSmartHelpId( SmartId( String( RTL_CONSTASCII_USTRINGPARAM( ".HelpId:StartCenter:OpenButton" ) ) ) );
214 maToolbox.SetSmartHelpId( SmartId( String( RTL_CONSTASCII_USTRINGPARAM( ".HelpId:StartCenter:Toolbox" ) ) ) );
216 // init background
217 initBackground();
221 BackingWindow::~BackingWindow()
223 delete mpAccExec;
226 class ImageContainerRes : public Resource
228 public:
229 ImageContainerRes( const ResId& i_rId ) : Resource( i_rId ) {}
230 ~ImageContainerRes() { FreeResource(); }
233 void BackingWindow::DataChanged( const DataChangedEvent& rDCEvt )
235 Window::DataChanged( rDCEvt );
237 if ( rDCEvt.GetFlags() & SETTINGS_STYLE )
239 initBackground();
240 Invalidate();
244 void BackingWindow::initBackground()
246 SetBackground( GetSettings().GetStyleSettings().GetWorkspaceGradient() );
248 bool bDark = GetSettings().GetStyleSettings().GetHighContrastMode();
249 maWelcomeTextColor = maLabelTextColor = bDark ? Color( COL_WHITE ) : Color( 0x26, 0x35, 0x42 );
250 Color aTextBGColor( bDark ? COL_BLACK : COL_WHITE );
252 // select image set
253 ImageContainerRes aRes( FwkResId( bDark ? RES_BACKING_IMAGES_HC : RES_BACKING_IMAGES ) );
255 // scale middle segment
256 Size aMiddleSize;
257 if( !! maBackgroundMiddle )
258 aMiddleSize = maBackgroundMiddle.GetSizePixel();
259 // load middle segment
260 maBackgroundMiddle = BitmapEx( FwkResId( BMP_BACKING_BACKGROUND_MIDDLE ) );
261 // and scale it to previous size
262 if( aMiddleSize.Width() && aMiddleSize.Height() )
263 maBackgroundMiddle.Scale( aMiddleSize );
265 if( GetSettings().GetLayoutRTL() )
267 // replace images by RTL versions
268 maBackgroundLeft = BitmapEx( FwkResId( BMP_BACKING_BACKGROUND_RTL_RIGHT ) );
269 maBackgroundRight = BitmapEx( FwkResId( BMP_BACKING_BACKGROUND_RTL_LEFT) );
271 else
273 maBackgroundLeft = BitmapEx( FwkResId( BMP_BACKING_BACKGROUND_LEFT ) );
274 maBackgroundRight = BitmapEx( FwkResId( BMP_BACKING_BACKGROUND_RIGHT ) );
277 maWelcome.SetControlForeground( maWelcomeTextColor );
278 maWelcome.SetBackground();
279 maProduct.SetControlForeground( maWelcomeTextColor );
280 maProduct.SetBackground();
281 maCreateText.SetControlForeground( maLabelTextColor );
282 maCreateText.SetControlBackground( aTextBGColor );
283 maWriterText.SetControlForeground( maLabelTextColor );
284 maWriterText.SetControlBackground( aTextBGColor );
285 maCalcText.SetControlForeground( maLabelTextColor );
286 maCalcText.SetControlBackground( aTextBGColor );
287 maImpressText.SetControlForeground( maLabelTextColor );
288 maImpressText.SetControlBackground( aTextBGColor );
289 maDrawText.SetControlForeground( maLabelTextColor );
290 maDrawText.SetControlBackground( aTextBGColor );
291 maDBText.SetControlForeground( maLabelTextColor );
292 maDBText.SetControlBackground( aTextBGColor );
293 maMathText.SetControlForeground( maLabelTextColor );
294 maMathText.SetControlBackground( aTextBGColor );
295 maTemplateText.SetControlForeground( maLabelTextColor );
296 maTemplateText.SetControlBackground( aTextBGColor );
297 maOpenText.SetControlForeground( maLabelTextColor );
298 maOpenText.SetControlBackground( aTextBGColor );
301 void BackingWindow::initControls()
303 if( mbInitControls )
304 return;
306 mbInitControls = true;
308 // calculate dialog size
309 // begin with background bitmap
310 maControlRect = Rectangle( Point(), maBackgroundLeft.GetSizePixel() );
311 maControlRect.Left() += nShadowLeft;
312 maControlRect.Right() -= nShadowRight;
313 maControlRect.Top() += nShadowTop;
314 maControlRect.Bottom() -= nShadowBottom;
316 long nYPos = 0;
317 // set bigger welcome string
318 maWelcome.SetText( maWelcomeString );
319 maTextFont = GetSettings().GetStyleSettings().GetLabelFont();
320 maTextFont.SetSize( Size( 0, 18 ) );
321 maTextFont.SetWeight( WEIGHT_BOLD );
322 maWelcome.SetFont( maTextFont );
323 // get metric to get correct width factor and adjust
324 long nW = (maWelcome.GetFontMetric().GetWidth()*95)/100;
325 maTextFont.SetSize( Size( nW, 18 ) );
327 maWelcome.SetFont( maTextFont );
328 maWelcome.SetControlFont( maTextFont );
329 maWelcomeSize = Size( maWelcome.GetTextWidth( maWelcomeString ), maWelcome.GetTextHeight() );
330 maWelcomeSize.Width() = (maWelcomeSize.Width() * 20)/19;
332 nYPos += (maWelcomeSize.Height()*3)/2;
334 if( maControlRect.GetWidth() < nBtnPos + maWelcomeSize.Width() + 20 )
335 maControlRect.Right() = maControlRect.Left() + maWelcomeSize.Width() + nBtnPos + 20;
337 maWelcome.Show();
339 nYPos += maWelcomeSize.Height();
341 // set product string
342 maTextFont.SetSize( Size( 0, 30 ) );
343 maProduct.SetFont( maTextFont );
345 // get metric to get correct width factor and adjust
346 nW = (maProduct.GetFontMetric().GetWidth()*95)/100;
347 maTextFont.SetSize( Size( nW, 28 ) );
349 maProduct.SetFont( maTextFont );
350 maProduct.SetControlFont( maTextFont );
351 maProduct.SetText( maProductString );
352 maProductSize = Size( maProduct.GetTextWidth( maProductString ), maProduct.GetTextHeight() );
353 maProductSize.Width() = (maProductSize.Width() * 20)/19;
355 if( maControlRect.GetWidth() < maProductSize.Width() + nBtnPos + 10 )
356 maControlRect.Right() = maControlRect.Left() + maProductSize.Width() + nBtnPos + 10;
358 maProduct.Show();
360 nYPos += (maProductSize.Height()*3)/2;
362 // set a slighly larger font than normal labels on the texts
363 maTextFont.SetSize( Size( 0, 11 ) );
364 maTextFont.SetWeight( WEIGHT_NORMAL );
366 maCreateText.SetText( maCreateString );
367 maCreateText.SetFont( maTextFont );
368 maCreateText.SetControlFont( maTextFont );
369 maCreateSize = Size( maCreateText.GetTextWidth( maCreateString ), maCreateText.GetTextHeight() );
370 maCreateText.Show();
372 nYPos += (maCreateSize.Height()*3)/2;
374 // collect the URLs of the entries in the File/New menu
375 SvtModuleOptions aModuleOptions;
376 std::set< rtl::OUString > aFileNewAppsAvailable;
377 SvtDynamicMenuOptions aOpt;
378 Sequence < Sequence < PropertyValue > > aNewMenu = aOpt.GetMenu( E_NEWMENU );
379 const rtl::OUString sURLKey( RTL_CONSTASCII_USTRINGPARAM( "URL" ) );
381 const Sequence< PropertyValue >* pNewMenu = aNewMenu.getConstArray();
382 const Sequence< PropertyValue >* pNewMenuEnd = aNewMenu.getConstArray() + aNewMenu.getLength();
383 for ( ; pNewMenu != pNewMenuEnd; ++pNewMenu )
385 comphelper::SequenceAsHashMap aEntryItems( *pNewMenu );
386 rtl::OUString sURL( aEntryItems.getUnpackedValueOrDefault( sURLKey, rtl::OUString() ) );
387 if ( sURL.getLength() )
388 aFileNewAppsAvailable.insert( sURL );
391 // create mnemonics on the fly, preregister the mnemonics of the menu
392 MnemonicGenerator aMnemns;
393 maTemplateString = MnemonicGenerator::EraseAllMnemonicChars( maTemplateString );
394 maOpenString = MnemonicGenerator::EraseAllMnemonicChars( maOpenString );
396 SystemWindow* pSysWin = GetSystemWindow();
397 if( pSysWin )
399 MenuBar* pMBar = pSysWin->GetMenuBar();
400 if( pMBar )
402 for( USHORT i = 0; i < pMBar->GetItemCount(); i++ )
404 USHORT nItemId = pMBar->GetItemId( i );
405 String aItemText( pMBar->GetItemText( nItemId ) );
406 if( aItemText.Len() )
407 aMnemns.RegisterMnemonic( aItemText );
412 // layout the buttons
413 layoutButtonAndText( WRITER_URL, 0, aFileNewAppsAvailable,
414 aModuleOptions, SvtModuleOptions::E_SWRITER,
415 maWriterButton, maWriterText, aMnemns );
416 layoutButtonAndText( CALC_URL, 1, aFileNewAppsAvailable,
417 aModuleOptions, SvtModuleOptions::E_SCALC,
418 maCalcButton, maCalcText, aMnemns );
419 nYPos += maButtonImageSize.Height() + 10;
420 layoutButtonAndText( IMPRESS_WIZARD_URL, 0, aFileNewAppsAvailable,
421 aModuleOptions, SvtModuleOptions::E_SIMPRESS,
422 maImpressButton, maImpressText, aMnemns );
423 layoutButtonAndText( DRAW_URL, 1, aFileNewAppsAvailable,
424 aModuleOptions, SvtModuleOptions::E_SDRAW,
425 maDrawButton, maDrawText, aMnemns );
426 nYPos += maButtonImageSize.Height() + 10;
427 layoutButtonAndText( BASE_URL, 0, aFileNewAppsAvailable,
428 aModuleOptions, SvtModuleOptions::E_SDATABASE,
429 maDBButton, maDBText, aMnemns );
430 layoutButtonAndText( MATH_URL, 1, aFileNewAppsAvailable,
431 aModuleOptions, SvtModuleOptions::E_SMATH,
432 maMathButton, maMathText, aMnemns );
434 nYPos += 3*maButtonImageSize.Height() / 2;
435 layoutButtonAndText( NULL, -1, aFileNewAppsAvailable,
436 aModuleOptions, SvtModuleOptions::E_SWRITER,
437 maTemplateButton, maTemplateText, aMnemns, maTemplateString );
439 nYPos += 10;
440 layoutButtonAndText( NULL, -1, aFileNewAppsAvailable,
441 aModuleOptions, SvtModuleOptions::E_SWRITER,
442 maOpenButton, maOpenText, aMnemns, maOpenString );
443 nYPos += 10;
445 DBG_ASSERT( nYPos < maControlRect.GetHeight(), "misformatting !" );
446 if( mnColumnWidth[0] + mnColumnWidth[1] + nBtnPos + 20 > maControlRect.GetWidth() )
447 maControlRect.Right() = maControlRect.Left() + mnColumnWidth[0] + mnColumnWidth[1] + nBtnPos + 20;
449 maToolbox.SetSelectHdl( LINK( this, BackingWindow, ToolboxHdl ) );
450 maToolbox.Show();
452 // scale middle map to formatted width
453 Size aMiddleSegmentSize( maControlRect.GetSize().Width() + nShadowLeft + nShadowRight,
454 maBackgroundMiddle.GetSizePixel().Height() );
456 long nLW = maBackgroundLeft.GetSizePixel().Width();
457 long nRW = maBackgroundRight.GetSizePixel().Width();
458 if( aMiddleSegmentSize.Width() > nLW + nRW )
460 aMiddleSegmentSize.Width() -= nLW;
461 aMiddleSegmentSize.Width() -= nRW;
462 maBackgroundMiddle.Scale( aMiddleSegmentSize );
464 else
465 maBackgroundMiddle = BitmapEx();
467 Resize();
470 void BackingWindow::loadImage( const ResId& i_rId, ImageButton& i_rButton )
472 BitmapEx aBmp( i_rId );
473 Size aImgSize( aBmp.GetSizePixel() );
474 if( aImgSize.Width() > maButtonImageSize.Width() )
475 maButtonImageSize.Width() = aImgSize.Width();
476 if( aImgSize.Height() > maButtonImageSize.Height() )
477 maButtonImageSize.Height() = aImgSize.Height();
478 i_rButton.SetModeImage( aBmp );
481 void BackingWindow::layoutButtonAndText(
482 const char* i_pURL, int nColumn,
483 const std::set<rtl::OUString>& i_rURLS,
484 SvtModuleOptions& i_rOpt, SvtModuleOptions::EModule i_eMod,
485 ImageButton& i_rBtn, FixedText& i_rText,
486 MnemonicGenerator& i_rMnemns,
487 const String& i_rStr
490 rtl::OUString aURL( rtl::OUString::createFromAscii( i_pURL ? i_pURL : "" ) );
491 // setup button
492 i_rBtn.SetPaintTransparent( TRUE );
493 i_rBtn.SetClickHdl( LINK( this, BackingWindow, ClickHdl ) );
494 if( i_pURL && (! i_rOpt.IsModuleInstalled( i_eMod ) || i_rURLS.find( aURL ) == i_rURLS.end()) )
496 i_rBtn.Enable( FALSE );
499 // setup text
500 i_rText.SetFont( maTextFont );
501 i_rText.SetControlFont( maTextFont );
502 String aText( i_rStr.Len() ? i_rStr : SvFileInformationManager::GetDescription( INetURLObject( aURL ) ) );
503 i_rMnemns.CreateMnemonic( aText );
504 i_rText.SetText( aText );
506 long nTextWidth = i_rText.GetTextWidth( i_rText.GetText() );
507 i_rText.SetPaintTransparent( TRUE );
509 nTextWidth += maButtonImageSize.Width() + 30;
510 if( nColumn >= 0 && nColumn < static_cast<int>(sizeof(mnColumnWidth)/sizeof(mnColumnWidth[0])) )
512 if( nTextWidth > mnColumnWidth[nColumn] )
513 mnColumnWidth[nColumn] = nTextWidth;
516 // show the controls
517 i_rBtn.Show();
518 i_rText.Show();
521 void BackingWindow::Paint( const Rectangle& )
523 bool bDark = GetSettings().GetStyleSettings().GetHighContrastMode();
525 Color aBackColor( bDark ? COL_BLACK : COL_WHITE );
527 // fill control rect
528 SetLineColor();
529 SetFillColor( aBackColor );
530 DrawRect( maControlRect );
532 // draw bitmap
533 if( GetSettings().GetLayoutRTL() )
535 Point aTL( maControlRect.TopLeft() );
536 aTL.X() -= nShadowRight;
537 aTL.Y() -= nShadowTop;
538 DrawBitmapEx( aTL, maBackgroundLeft );
539 aTL.X() += maBackgroundLeft.GetSizePixel().Width();
540 if( !!maBackgroundMiddle )
542 DrawBitmapEx( aTL, maBackgroundMiddle );
543 aTL.X() += maBackgroundMiddle.GetSizePixel().Width();
545 DrawBitmapEx( aTL, maBackgroundRight );
547 else
549 Point aTL( maControlRect.TopLeft() );
550 aTL.X() -= nShadowLeft;
551 aTL.Y() -= nShadowTop;
552 DrawBitmapEx( aTL, maBackgroundLeft );
553 aTL.X() += maBackgroundLeft.GetSizePixel().Width();
554 if( !!maBackgroundMiddle )
556 DrawBitmapEx( aTL, maBackgroundMiddle );
557 aTL.X() += maBackgroundMiddle.GetSizePixel().Width();
559 DrawBitmapEx( aTL, maBackgroundRight );
563 long BackingWindow::Notify( NotifyEvent& rNEvt )
565 if( rNEvt.GetType() == EVENT_KEYINPUT )
567 if( ! mpAccExec )
569 mpAccExec = svt::AcceleratorExecute::createAcceleratorHelper();
570 mpAccExec->init( comphelper::getProcessServiceFactory(), mxFrame);
573 const KeyEvent* pEvt = rNEvt.GetKeyEvent();
574 if( pEvt && mpAccExec->execute(pEvt->GetKeyCode()) )
575 return 1;
577 return Window::Notify( rNEvt );
580 void BackingWindow::setOwningFrame( const com::sun::star::uno::Reference< com::sun::star::frame::XFrame >& xFrame )
582 mxFrame = xFrame;
583 if( ! mbInitControls )
584 initControls();
587 void BackingWindow::Resize()
589 Size aWindowSize( GetSizePixel() );
590 Size aControlSize = maControlRect.GetSize();
591 maControlRect = Rectangle( Point( (aWindowSize.Width() - aControlSize.Width()) / 2,
592 (aWindowSize.Height() - aControlSize.Height()) / 2 ),
593 aControlSize );
595 maToolbox.calcMinSize();
596 Size aTBSize( maToolbox.getMinSize() );
597 Point aTBPos( maControlRect.Right() - aTBSize.Width() - 10,
598 maControlRect.Bottom() - aTBSize.Height() - 10 );
599 maToolbox.SetPosSizePixel( aTBPos, aTBSize );
601 // #i93631# squeeze controls so they fit into the box
602 // this can be necessary due to application font height which has small deviations
603 // from the size set
604 const long nWDelta = maWelcomeSize.Height();
605 const long nW2Delta = (maWelcomeSize.Height()*3)/2;
606 const long nPDelta = (maProductSize.Height()*3)/2;
607 const long nCDelta = (maCreateSize.Height()*3)/2;
608 const long nBDelta = maButtonImageSize.Height() + 10;
609 const long nB2Delta = 3*maButtonImageSize.Height()/2;
610 const long nLastDelta = maButtonImageSize.Height();
611 long nDiff = 0;
612 while( ( maControlRect.Top() +
613 (nWDelta - nDiff) +
614 (nW2Delta- nDiff) +
615 (nPDelta - nDiff) +
616 (nCDelta - nDiff) +
617 3 * (nBDelta - nDiff) +
618 (nB2Delta- nDiff) +
619 nLastDelta
620 ) > aTBPos.Y() )
622 nDiff++;
625 long nYPos = maControlRect.Top();
626 nYPos += nW2Delta - nDiff;
627 maWelcome.SetPosSizePixel( Point( maControlRect.Left() + nBtnPos, nYPos ),
628 Size( maControlRect.GetWidth() - nBtnPos - 5, (maWelcomeSize.Height()*20)/19 ) );
629 nYPos += nWDelta - nDiff;
630 maProduct.SetPosSizePixel( Point( maControlRect.Left() + nBtnPos, nYPos ), Size( maControlRect.GetWidth() - nBtnPos - 5, (maProductSize.Height()*20)/19 ) );
631 nYPos += nPDelta - nDiff;
633 maCreateText.SetPosSizePixel( Point( maControlRect.Left() + nBtnPos, nYPos ),
634 Size( maControlRect.GetWidth() - nBtnPos - 5, maCreateSize.Height() ) );
636 nYPos += nCDelta - nDiff;
638 maWriterButton.SetPosSizePixel( Point( maControlRect.Left() + nBtnPos, nYPos ), maButtonImageSize );
639 maWriterText.SetPosSizePixel( Point( maControlRect.Left() + nBtnPos + maButtonImageSize.Width() + 10, nYPos ),
640 Size( mnColumnWidth[0] - maButtonImageSize.Width() - 10, maButtonImageSize.Height() ) );
641 maCalcButton.SetPosSizePixel( Point( maControlRect.Left() + nBtnPos + mnColumnWidth[0], nYPos ), maButtonImageSize );
642 maCalcText.SetPosSizePixel( Point( maControlRect.Left() + nBtnPos + maButtonImageSize.Width() + 10 + mnColumnWidth[0], nYPos ),
643 Size( mnColumnWidth[1] - maButtonImageSize.Width() - 10, maButtonImageSize.Height() ) );
644 nYPos += nBDelta - nDiff;
645 maImpressButton.SetPosSizePixel( Point( maControlRect.Left() + nBtnPos, nYPos ), maButtonImageSize );
646 maImpressText.SetPosSizePixel( Point( maControlRect.Left() + nBtnPos + maButtonImageSize.Width() + 10, nYPos ),
647 Size( mnColumnWidth[0] - maButtonImageSize.Width() - 10, maButtonImageSize.Height() ) );
648 maDrawButton.SetPosSizePixel( Point( maControlRect.Left() + nBtnPos + mnColumnWidth[0], nYPos ), maButtonImageSize );
649 maDrawText.SetPosSizePixel( Point( maControlRect.Left() + nBtnPos + maButtonImageSize.Width() + 10 + mnColumnWidth[0], nYPos ),
650 Size( mnColumnWidth[1] - maButtonImageSize.Width() - 10, maButtonImageSize.Height() ) );
651 nYPos += nBDelta - nDiff;
652 maDBButton.SetPosSizePixel( Point( maControlRect.Left() + nBtnPos, nYPos ), maButtonImageSize );
653 maDBText.SetPosSizePixel( Point( maControlRect.Left() + nBtnPos + maButtonImageSize.Width() + 10, nYPos ),
654 Size( mnColumnWidth[0] - maButtonImageSize.Width() - 10, maButtonImageSize.Height() ) );
655 maMathButton.SetPosSizePixel( Point( maControlRect.Left() + nBtnPos + mnColumnWidth[0], nYPos ), maButtonImageSize );
656 maMathText.SetPosSizePixel( Point( maControlRect.Left() + nBtnPos + maButtonImageSize.Width() + 10 + mnColumnWidth[0], nYPos ),
657 Size( mnColumnWidth[1] - maButtonImageSize.Width() - 10, maButtonImageSize.Height() ) );
659 nYPos += nB2Delta - nDiff;
660 maTemplateButton.SetPosSizePixel( Point( maControlRect.Left() + nBtnPos, nYPos ), maButtonImageSize );
661 maTemplateText.SetPosSizePixel( Point( maControlRect.Left() + nBtnPos + maButtonImageSize.Width() + 10, nYPos ),
662 Size( mnColumnWidth[0]+mnColumnWidth[1] - maButtonImageSize.Width() - 10, maButtonImageSize.Height() ) );
663 nYPos += nBDelta - nDiff;
664 maOpenButton.SetPosSizePixel( Point( maControlRect.Left() + nBtnPos, nYPos ), maButtonImageSize );
665 maOpenText.SetPosSizePixel( Point( maControlRect.Left() + nBtnPos + maButtonImageSize.Width() + 10, nYPos ),
666 Size( mnColumnWidth[0]+mnColumnWidth[1] - maButtonImageSize.Width() - 10, maButtonImageSize.Height() ) );
667 nYPos += nBDelta - nDiff;
670 IMPL_LINK( BackingWindow, ToolboxHdl, void*, EMPTYARG )
672 const char* pNodePath = NULL;
673 const char* pNode = NULL;
675 switch( maToolbox.GetCurItemId() )
677 case nItemId_Extensions:
678 pNodePath = "/org.openoffice.Office.Common/Help/StartCenter";
679 pNode = "AddFeatureURL";
680 break;
681 case nItemId_Reg:
684 // create the Desktop component which can load components
685 Reference < lang::XMultiServiceFactory > xFactory = ::comphelper::getProcessServiceFactory();
686 if( xFactory.is() )
688 Reference< task::XJobExecutor > xProductRegistration(
689 xFactory->createInstance( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.setup.ProductRegistration" ) ) ),
690 UNO_QUERY_THROW );
692 // tell it that the user wants to register
693 xProductRegistration->trigger( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "RegistrationRequired" ) ) );
696 catch( const Exception& )
699 break;
700 case nItemId_Info:
701 pNodePath = "/org.openoffice.Office.Common/Help/StartCenter";
702 pNode = "InfoURL";
703 break;
704 case nItemId_TplRep:
705 pNodePath = "/org.openoffice.Office.Common/Help/StartCenter";
706 pNode = "TemplateRepositoryURL";
707 break;
708 default:
709 break;
711 if( pNodePath && pNode )
715 Reference<lang::XMultiServiceFactory> xConfig( comphelper::getProcessServiceFactory()->createInstance(SERVICENAME_CFGPROVIDER),UNO_QUERY);
716 if( xConfig.is() )
718 Sequence<Any> args(1);
719 PropertyValue val(
720 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("nodepath") ),
722 Any(rtl::OUString::createFromAscii(pNodePath)),
723 PropertyState_DIRECT_VALUE);
724 args.getArray()[0] <<= val;
725 Reference<container::XNameAccess> xNameAccess(xConfig->createInstanceWithArguments(SERVICENAME_CFGREADACCESS,args), UNO_QUERY);
726 if( xNameAccess.is() )
728 rtl::OUString sURL;
729 //throws css::container::NoSuchElementException, css::lang::WrappedTargetException
730 Any value( xNameAccess->getByName(rtl::OUString::createFromAscii(pNode)) );
731 sURL = value.get<rtl::OUString> ();
733 Reference< com::sun::star::system::XSystemShellExecute > xSystemShellExecute(
734 comphelper::getProcessServiceFactory()->createInstance(
735 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.system.SystemShellExecute" ) ) ),
736 UNO_QUERY_THROW);
737 //throws css::lang::IllegalArgumentException, css::system::SystemShellExecuteException
738 xSystemShellExecute->execute( sURL, rtl::OUString(), com::sun::star::system::SystemShellExecuteFlags::DEFAULTS);
742 catch (Exception& )
747 return 0;
750 IMPL_LINK( BackingWindow, ClickHdl, Button*, pButton )
752 // dispatch the appropriate URL and end the dialog
753 if( pButton == &maWriterButton )
754 dispatchURL( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(WRITER_URL) ) );
755 else if( pButton == &maCalcButton )
756 dispatchURL( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(CALC_URL) ) );
757 else if( pButton == &maImpressButton )
758 dispatchURL( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(IMPRESS_WIZARD_URL) ) );
759 else if( pButton == &maDrawButton )
760 dispatchURL( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(DRAW_URL) ) );
761 else if( pButton == &maDBButton )
762 dispatchURL( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(BASE_URL) ) );
763 else if( pButton == &maMathButton )
764 dispatchURL( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(MATH_URL) ) );
765 else if( pButton == &maOpenButton )
767 Reference< XDispatchProvider > xFrame( mxFrame, UNO_QUERY );
769 Sequence< com::sun::star::beans::PropertyValue > aArgs(1);
770 PropertyValue* pArg = aArgs.getArray();
771 pArg[0].Name = rtl::OUString::createFromAscii("Referer");
772 pArg[0].Value <<= rtl::OUString::createFromAscii("private:user");
774 dispatchURL( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(OPEN_URL) ), rtl::OUString(), xFrame, aArgs );
776 else if( pButton == &maTemplateButton )
778 Reference< XDispatchProvider > xFrame( mxFrame, UNO_QUERY );
780 Sequence< com::sun::star::beans::PropertyValue > aArgs(1);
781 PropertyValue* pArg = aArgs.getArray();
782 pArg[0].Name = rtl::OUString::createFromAscii("Referer");
783 pArg[0].Value <<= rtl::OUString::createFromAscii("private:user");
785 dispatchURL( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(TEMPLATE_URL) ), rtl::OUString(), xFrame, aArgs );
787 return 0;
790 Window* BackingWindow::GetParentLabelFor( const Window* pLabel ) const
792 const Window* pRet = NULL;
794 if( pLabel == &maWriterText )
795 pRet = &maWriterButton;
796 else if( pLabel == &maCalcText )
797 pRet = &maCalcButton;
798 else if( pLabel == &maImpressText )
799 pRet = &maImpressButton;
800 else if( pLabel == &maDrawText )
801 pRet = &maDrawButton;
802 else if( pLabel == &maDBText )
803 pRet = &maDBButton;
804 else if( pLabel == &maMathText )
805 pRet = &maMathButton;
806 else if( pLabel == &maTemplateText )
807 pRet = &maTemplateButton;
808 else if( pLabel == &maOpenText )
809 pRet = &maOpenButton;
811 return const_cast<Window*>(pRet);
814 Window* BackingWindow::GetParentLabeledBy( const Window* pLabeled ) const
816 const Window *pRet = NULL;
818 if( pLabeled == &maWriterButton )
819 pRet = &maWriterText;
820 else if( pLabeled == &maCalcButton )
821 pRet = &maCalcText;
822 else if( pLabeled == &maImpressButton )
823 pRet = &maImpressText;
824 else if( pLabeled == &maDrawButton )
825 pRet = &maDrawText;
826 else if( pLabeled == &maDBButton )
827 pRet = &maDBText;
828 else if( pLabeled == &maMathButton )
829 pRet = &maMathText;
830 else if( pLabeled == &maTemplateButton )
831 pRet = &maTemplateText;
832 else if( pLabeled == &maOpenButton )
833 pRet = &maOpenText;
835 return const_cast<Window*>(pRet);
838 struct ImplDelayedDispatch
840 Reference< XDispatch > xDispatch;
841 com::sun::star::util::URL aDispatchURL;
842 Sequence< PropertyValue > aArgs;
844 ImplDelayedDispatch( const Reference< XDispatch >& i_xDispatch,
845 const com::sun::star::util::URL& i_rURL,
846 const Sequence< PropertyValue >& i_rArgs )
847 : xDispatch( i_xDispatch ),
848 aDispatchURL( i_rURL ),
849 aArgs( i_rArgs )
852 ~ImplDelayedDispatch() {}
855 static long implDispatchDelayed( void*, void* pArg )
857 struct ImplDelayedDispatch* pDispatch = reinterpret_cast<ImplDelayedDispatch*>(pArg);
860 pDispatch->xDispatch->dispatch( pDispatch->aDispatchURL, pDispatch->aArgs );
862 catch( Exception )
866 // clean up
867 delete pDispatch;
869 return 0;
872 void BackingWindow::dispatchURL( const rtl::OUString& i_rURL,
873 const rtl::OUString& rTarget,
874 const Reference< XDispatchProvider >& i_xProv,
875 const Sequence< PropertyValue >& i_rArgs )
877 // if no special dispatch provider is given, get the desktop
878 Reference< XDispatchProvider > xProvider( i_xProv.is() ? i_xProv : mxDesktopDispatchProvider );
880 // check for dispatch provider
881 if( !xProvider.is())
882 return;
884 // get an URL transformer to clean up the URL
885 com::sun::star::util::URL aDispatchURL;
886 aDispatchURL.Complete = i_rURL;
888 Reference < com::sun::star::util::XURLTransformer > xURLTransformer(
889 comphelper::getProcessServiceFactory()->createInstance( rtl::OUString::createFromAscii("com.sun.star.util.URLTransformer") ),
890 com::sun::star::uno::UNO_QUERY );
891 if ( xURLTransformer.is() )
895 // clean up the URL
896 xURLTransformer->parseStrict( aDispatchURL );
897 // get a Dispatch for the URL and target
898 Reference< XDispatch > xDispatch(
899 xProvider->queryDispatch( aDispatchURL, rTarget, 0 )
901 // dispatch the URL
902 if ( xDispatch.is() )
904 ImplDelayedDispatch* pDisp = new ImplDelayedDispatch( xDispatch, aDispatchURL, i_rArgs );
905 ULONG nEventId = 0;
906 if( ! Application::PostUserEvent( nEventId, Link( NULL, implDispatchDelayed ), pDisp ) )
907 delete pDisp; // event could not be posted for unknown reason, at least don't leak
910 catch ( com::sun::star::uno::RuntimeException& )
912 throw;
914 catch ( com::sun::star::uno::Exception& )