1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: backingwindow.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // autogen include statement, do not remove
32 #include "precompiled_framework.hxx"
34 #include "backingwindow.hxx"
35 #include "framework.hrc"
36 #include "classes/fwkresid.hxx"
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
)
82 SetPaintTransparent( TRUE
);
85 void DecoToolBox::DataChanged( const DataChangedEvent
& rDCEvt
)
87 Window::DataChanged( rDCEvt
);
89 if ( rDCEvt
.GetFlags() & SETTINGS_STYLE
)
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()
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 ),
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
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
);
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" ) ) ) );
221 BackingWindow::~BackingWindow()
226 class ImageContainerRes
: public Resource
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
)
243 void BackingWindow::initBackground()
245 SetBackground( GetSettings().GetStyleSettings().GetWorkspaceGradient() );
247 bool bDark
= GetSettings().GetStyleSettings().GetWindowColor().IsDark();
248 maWelcomeTextColor
= maLabelTextColor
= bDark
? Color( COL_WHITE
) : Color( 0x26, 0x35, 0x42 );
249 Color
aTextBGColor( bDark
? COL_BLACK
: COL_WHITE
);
252 ImageContainerRes
aRes( FwkResId( bDark
? RES_BACKING_IMAGES_HC
: RES_BACKING_IMAGES
) );
254 // scale middle segment
256 if( !! maBackgroundMiddle
)
257 aMiddleSize
= maBackgroundMiddle
.GetSizePixel();
258 // load middle segment
259 maBackgroundMiddle
= BitmapEx( FwkResId( BMP_BACKING_BACKGROUND_MIDDLE
) );
260 // and scale it to previous size
261 if( aMiddleSize
.Width() && aMiddleSize
.Height() )
262 maBackgroundMiddle
.Scale( aMiddleSize
);
264 if( GetSettings().GetLayoutRTL() )
266 // replace images by RTL versions
267 maBackgroundLeft
= BitmapEx( FwkResId( BMP_BACKING_BACKGROUND_RTL_RIGHT
) );
268 maBackgroundRight
= BitmapEx( FwkResId( BMP_BACKING_BACKGROUND_RTL_LEFT
) );
272 maBackgroundLeft
= BitmapEx( FwkResId( BMP_BACKING_BACKGROUND_LEFT
) );
273 maBackgroundRight
= BitmapEx( FwkResId( BMP_BACKING_BACKGROUND_RIGHT
) );
276 maWelcome
.SetControlForeground( maWelcomeTextColor
);
277 maWelcome
.SetBackground();
278 maProduct
.SetControlForeground( maWelcomeTextColor
);
279 maProduct
.SetBackground();
280 maCreateText
.SetControlForeground( maLabelTextColor
);
281 maCreateText
.SetControlBackground( aTextBGColor
);
282 maWriterText
.SetControlForeground( maLabelTextColor
);
283 maWriterText
.SetControlBackground( aTextBGColor
);
284 maCalcText
.SetControlForeground( maLabelTextColor
);
285 maCalcText
.SetControlBackground( aTextBGColor
);
286 maImpressText
.SetControlForeground( maLabelTextColor
);
287 maImpressText
.SetControlBackground( aTextBGColor
);
288 maDrawText
.SetControlForeground( maLabelTextColor
);
289 maDrawText
.SetControlBackground( aTextBGColor
);
290 maDBText
.SetControlForeground( maLabelTextColor
);
291 maDBText
.SetControlBackground( aTextBGColor
);
292 maMathText
.SetControlForeground( maLabelTextColor
);
293 maMathText
.SetControlBackground( aTextBGColor
);
294 maTemplateText
.SetControlForeground( maLabelTextColor
);
295 maTemplateText
.SetControlBackground( aTextBGColor
);
296 maOpenText
.SetControlForeground( maLabelTextColor
);
297 maOpenText
.SetControlBackground( aTextBGColor
);
300 void BackingWindow::initControls()
305 mbInitControls
= true;
307 // calculate dialog size
308 // begin with background bitmap
309 maControlRect
= Rectangle( Point(), maBackgroundLeft
.GetSizePixel() );
310 maControlRect
.Left() += nShadowLeft
;
311 maControlRect
.Right() -= nShadowRight
;
312 maControlRect
.Top() += nShadowTop
;
313 maControlRect
.Bottom() -= nShadowBottom
;
316 // set bigger welcome string
317 maWelcome
.SetText( maWelcomeString
);
318 maTextFont
= GetSettings().GetStyleSettings().GetLabelFont();
319 maTextFont
.SetSize( Size( 0, 18 ) );
320 maTextFont
.SetWeight( WEIGHT_BOLD
);
321 maWelcome
.SetFont( maTextFont
);
322 // get metric to get correct width factor and adjust
323 long nW
= (maWelcome
.GetFontMetric().GetWidth()*95)/100;
324 maTextFont
.SetSize( Size( nW
, 18 ) );
326 maWelcome
.SetFont( maTextFont
);
327 maWelcome
.SetControlFont( maTextFont
);
328 maWelcomeSize
= Size( maWelcome
.GetTextWidth( maWelcomeString
), maWelcome
.GetTextHeight() );
329 maWelcomeSize
.Width() = (maWelcomeSize
.Width() * 20)/19;
331 nYPos
+= (maWelcomeSize
.Height()*3)/2;
333 if( maControlRect
.GetWidth() < nBtnPos
+ maWelcomeSize
.Width() + 20 )
334 maControlRect
.Right() = maControlRect
.Left() + maWelcomeSize
.Width() + nBtnPos
+ 20;
338 nYPos
+= maWelcomeSize
.Height();
340 // set product string
341 maTextFont
.SetSize( Size( 0, 30 ) );
342 maProduct
.SetFont( maTextFont
);
344 // get metric to get correct width factor and adjust
345 nW
= (maProduct
.GetFontMetric().GetWidth()*95)/100;
346 maTextFont
.SetSize( Size( nW
, 28 ) );
348 maProduct
.SetFont( maTextFont
);
349 maProduct
.SetControlFont( maTextFont
);
350 maProduct
.SetText( maProductString
);
351 maProductSize
= Size( maProduct
.GetTextWidth( maProductString
), maProduct
.GetTextHeight() );
352 maProductSize
.Width() = (maProductSize
.Width() * 20)/19;
354 if( maControlRect
.GetWidth() < maProductSize
.Width() + nBtnPos
+ 10 )
355 maControlRect
.Right() = maControlRect
.Left() + maProductSize
.Width() + nBtnPos
+ 10;
359 nYPos
+= (maProductSize
.Height()*3)/2;
361 // set a slighly larger font than normal labels on the texts
362 maTextFont
.SetSize( Size( 0, 11 ) );
363 maTextFont
.SetWeight( WEIGHT_NORMAL
);
365 maCreateText
.SetText( maCreateString
);
366 maCreateText
.SetFont( maTextFont
);
367 maCreateText
.SetControlFont( maTextFont
);
368 maCreateSize
= Size( maCreateText
.GetTextWidth( maCreateString
), maCreateText
.GetTextHeight() );
371 nYPos
+= (maCreateSize
.Height()*3)/2;
373 // collect the URLs of the entries in the File/New menu
374 SvtModuleOptions aModuleOptions
;
375 std::set
< rtl::OUString
> aFileNewAppsAvailable
;
376 SvtDynamicMenuOptions aOpt
;
377 Sequence
< Sequence
< PropertyValue
> > aNewMenu
= aOpt
.GetMenu( E_NEWMENU
);
378 const rtl::OUString
sURLKey( RTL_CONSTASCII_USTRINGPARAM( "URL" ) );
380 const Sequence
< PropertyValue
>* pNewMenu
= aNewMenu
.getConstArray();
381 const Sequence
< PropertyValue
>* pNewMenuEnd
= aNewMenu
.getConstArray() + aNewMenu
.getLength();
382 for ( ; pNewMenu
!= pNewMenuEnd
; ++pNewMenu
)
384 comphelper::SequenceAsHashMap
aEntryItems( *pNewMenu
);
385 rtl::OUString
sURL( aEntryItems
.getUnpackedValueOrDefault( sURLKey
, rtl::OUString() ) );
386 if ( sURL
.getLength() )
387 aFileNewAppsAvailable
.insert( sURL
);
390 // create mnemonics on the fly, preregister the mnemonics of the menu
391 MnemonicGenerator aMnemns
;
392 maTemplateString
= MnemonicGenerator::EraseAllMnemonicChars( maTemplateString
);
393 maOpenString
= MnemonicGenerator::EraseAllMnemonicChars( maOpenString
);
395 SystemWindow
* pSysWin
= GetSystemWindow();
398 MenuBar
* pMBar
= pSysWin
->GetMenuBar();
401 for( USHORT i
= 0; i
< pMBar
->GetItemCount(); i
++ )
403 USHORT nItemId
= pMBar
->GetItemId( i
);
404 String
aItemText( pMBar
->GetItemText( nItemId
) );
405 if( aItemText
.Len() )
406 aMnemns
.RegisterMnemonic( aItemText
);
411 // layout the buttons
412 layoutButtonAndText( WRITER_URL
, 0, aFileNewAppsAvailable
,
413 aModuleOptions
, SvtModuleOptions::E_SWRITER
,
414 maWriterButton
, maWriterText
, aMnemns
);
415 layoutButtonAndText( CALC_URL
, 1, aFileNewAppsAvailable
,
416 aModuleOptions
, SvtModuleOptions::E_SCALC
,
417 maCalcButton
, maCalcText
, aMnemns
);
418 nYPos
+= maButtonImageSize
.Height() + 10;
419 layoutButtonAndText( IMPRESS_WIZARD_URL
, 0, aFileNewAppsAvailable
,
420 aModuleOptions
, SvtModuleOptions::E_SIMPRESS
,
421 maImpressButton
, maImpressText
, aMnemns
);
422 layoutButtonAndText( DRAW_URL
, 1, aFileNewAppsAvailable
,
423 aModuleOptions
, SvtModuleOptions::E_SDRAW
,
424 maDrawButton
, maDrawText
, aMnemns
);
425 nYPos
+= maButtonImageSize
.Height() + 10;
426 layoutButtonAndText( BASE_URL
, 0, aFileNewAppsAvailable
,
427 aModuleOptions
, SvtModuleOptions::E_SDATABASE
,
428 maDBButton
, maDBText
, aMnemns
);
429 layoutButtonAndText( MATH_URL
, 1, aFileNewAppsAvailable
,
430 aModuleOptions
, SvtModuleOptions::E_SMATH
,
431 maMathButton
, maMathText
, aMnemns
);
433 nYPos
+= 3*maButtonImageSize
.Height() / 2;
434 layoutButtonAndText( NULL
, -1, aFileNewAppsAvailable
,
435 aModuleOptions
, SvtModuleOptions::E_SWRITER
,
436 maTemplateButton
, maTemplateText
, aMnemns
, maTemplateString
);
439 layoutButtonAndText( NULL
, -1, aFileNewAppsAvailable
,
440 aModuleOptions
, SvtModuleOptions::E_SWRITER
,
441 maOpenButton
, maOpenText
, aMnemns
, maOpenString
);
444 DBG_ASSERT( nYPos
< maControlRect
.GetHeight(), "misformatting !" );
445 if( mnColumnWidth
[0] + mnColumnWidth
[1] + nBtnPos
+ 20 > maControlRect
.GetWidth() )
446 maControlRect
.Right() = maControlRect
.Left() + mnColumnWidth
[0] + mnColumnWidth
[1] + nBtnPos
+ 20;
448 maToolbox
.SetSelectHdl( LINK( this, BackingWindow
, ToolboxHdl
) );
451 // scale middle map to formatted width
452 Size
aMiddleSegmentSize( maControlRect
.GetSize().Width() + nShadowLeft
+ nShadowRight
,
453 maBackgroundMiddle
.GetSizePixel().Height() );
455 long nLW
= maBackgroundLeft
.GetSizePixel().Width();
456 long nRW
= maBackgroundRight
.GetSizePixel().Width();
457 if( aMiddleSegmentSize
.Width() > nLW
+ nRW
)
459 aMiddleSegmentSize
.Width() -= nLW
;
460 aMiddleSegmentSize
.Width() -= nRW
;
461 maBackgroundMiddle
.Scale( aMiddleSegmentSize
);
464 maBackgroundMiddle
= BitmapEx();
469 void BackingWindow::loadImage( const ResId
& i_rId
, ImageButton
& i_rButton
)
471 BitmapEx
aBmp( i_rId
);
472 Size
aImgSize( aBmp
.GetSizePixel() );
473 if( aImgSize
.Width() > maButtonImageSize
.Width() )
474 maButtonImageSize
.Width() = aImgSize
.Width();
475 if( aImgSize
.Height() > maButtonImageSize
.Height() )
476 maButtonImageSize
.Height() = aImgSize
.Height();
477 i_rButton
.SetModeImage( aBmp
);
480 void BackingWindow::layoutButtonAndText(
481 const char* i_pURL
, int nColumn
,
482 const std::set
<rtl::OUString
>& i_rURLS
,
483 SvtModuleOptions
& i_rOpt
, SvtModuleOptions::EModule i_eMod
,
484 ImageButton
& i_rBtn
, FixedText
& i_rText
,
485 MnemonicGenerator
& i_rMnemns
,
489 rtl::OUString
aURL( rtl::OUString::createFromAscii( i_pURL
? i_pURL
: "" ) );
491 i_rBtn
.SetPaintTransparent( TRUE
);
492 i_rBtn
.SetClickHdl( LINK( this, BackingWindow
, ClickHdl
) );
493 if( i_pURL
&& (! i_rOpt
.IsModuleInstalled( i_eMod
) || i_rURLS
.find( aURL
) == i_rURLS
.end()) )
495 i_rBtn
.Enable( FALSE
);
499 i_rText
.SetFont( maTextFont
);
500 i_rText
.SetControlFont( maTextFont
);
501 String
aText( i_rStr
.Len() ? i_rStr
: SvFileInformationManager::GetDescription( INetURLObject( aURL
) ) );
502 i_rMnemns
.CreateMnemonic( aText
);
503 i_rText
.SetText( aText
);
505 long nTextWidth
= i_rText
.GetTextWidth( i_rText
.GetText() );
506 i_rText
.SetPaintTransparent( TRUE
);
508 nTextWidth
+= maButtonImageSize
.Width() + 30;
509 if( nColumn
>= 0 && nColumn
< static_cast<int>(sizeof(mnColumnWidth
)/sizeof(mnColumnWidth
[0])) )
511 if( nTextWidth
> mnColumnWidth
[nColumn
] )
512 mnColumnWidth
[nColumn
] = nTextWidth
;
520 void BackingWindow::Paint( const Rectangle
& )
522 bool bDark
= GetSettings().GetStyleSettings().GetWindowColor().IsDark();
524 Color
aBackColor( bDark
? COL_BLACK
: COL_WHITE
);
528 SetFillColor( aBackColor
);
529 DrawRect( maControlRect
);
532 if( GetSettings().GetLayoutRTL() )
534 Point
aTL( maControlRect
.TopLeft() );
535 aTL
.X() -= nShadowRight
;
536 aTL
.Y() -= nShadowTop
;
537 DrawBitmapEx( aTL
, maBackgroundLeft
);
538 aTL
.X() += maBackgroundLeft
.GetSizePixel().Width();
539 if( !!maBackgroundMiddle
)
541 DrawBitmapEx( aTL
, maBackgroundMiddle
);
542 aTL
.X() += maBackgroundMiddle
.GetSizePixel().Width();
544 DrawBitmapEx( aTL
, maBackgroundRight
);
548 Point
aTL( maControlRect
.TopLeft() );
549 aTL
.X() -= nShadowLeft
;
550 aTL
.Y() -= nShadowTop
;
551 DrawBitmapEx( aTL
, maBackgroundLeft
);
552 aTL
.X() += maBackgroundLeft
.GetSizePixel().Width();
553 if( !!maBackgroundMiddle
)
555 DrawBitmapEx( aTL
, maBackgroundMiddle
);
556 aTL
.X() += maBackgroundMiddle
.GetSizePixel().Width();
558 DrawBitmapEx( aTL
, maBackgroundRight
);
562 long BackingWindow::Notify( NotifyEvent
& rNEvt
)
564 if( rNEvt
.GetType() == EVENT_KEYINPUT
)
568 mpAccExec
= svt::AcceleratorExecute::createAcceleratorHelper();
569 mpAccExec
->init( comphelper::getProcessServiceFactory(), mxFrame
);
572 const KeyEvent
* pEvt
= rNEvt
.GetKeyEvent();
573 if( pEvt
&& mpAccExec
->execute(pEvt
->GetKeyCode()) )
576 return Window::Notify( rNEvt
);
579 void BackingWindow::setOwningFrame( const com::sun::star::uno::Reference
< com::sun::star::frame::XFrame
>& xFrame
)
582 if( ! mbInitControls
)
586 void BackingWindow::Resize()
588 Size
aWindowSize( GetSizePixel() );
589 Size aControlSize
= maControlRect
.GetSize();
590 maControlRect
= Rectangle( Point( (aWindowSize
.Width() - aControlSize
.Width()) / 2,
591 (aWindowSize
.Height() - aControlSize
.Height()) / 2 ),
594 maToolbox
.calcMinSize();
595 Size
aTBSize( maToolbox
.getMinSize() );
596 Point
aTBPos( maControlRect
.Right() - aTBSize
.Width() - 10,
597 maControlRect
.Bottom() - aTBSize
.Height() - 10 );
598 maToolbox
.SetPosSizePixel( aTBPos
, aTBSize
);
600 // #i93631# squeeze controls so they fit into the box
601 // this can be necessary due to application font height which has small deviations
603 const long nWDelta
= maWelcomeSize
.Height();
604 const long nW2Delta
= (maWelcomeSize
.Height()*3)/2;
605 const long nPDelta
= (maProductSize
.Height()*3)/2;
606 const long nCDelta
= (maCreateSize
.Height()*3)/2;
607 const long nBDelta
= maButtonImageSize
.Height() + 10;
608 const long nB2Delta
= 3*maButtonImageSize
.Height()/2;
609 const long nLastDelta
= maButtonImageSize
.Height();
611 while( ( maControlRect
.Top() +
616 3 * (nBDelta
- nDiff
) +
624 long nYPos
= maControlRect
.Top();
625 nYPos
+= nW2Delta
- nDiff
;
626 maWelcome
.SetPosSizePixel( Point( maControlRect
.Left() + nBtnPos
, nYPos
),
627 Size( maControlRect
.GetWidth() - nBtnPos
- 5, (maWelcomeSize
.Height()*20)/19 ) );
628 nYPos
+= nWDelta
- nDiff
;
629 maProduct
.SetPosSizePixel( Point( maControlRect
.Left() + nBtnPos
, nYPos
), Size( maControlRect
.GetWidth() - nBtnPos
- 5, (maProductSize
.Height()*20)/19 ) );
630 nYPos
+= nPDelta
- nDiff
;
632 maCreateText
.SetPosSizePixel( Point( maControlRect
.Left() + nBtnPos
, nYPos
),
633 Size( maControlRect
.GetWidth() - nBtnPos
- 5, maCreateSize
.Height() ) );
635 nYPos
+= nCDelta
- nDiff
;
637 maWriterButton
.SetPosSizePixel( Point( maControlRect
.Left() + nBtnPos
, nYPos
), maButtonImageSize
);
638 maWriterText
.SetPosSizePixel( Point( maControlRect
.Left() + nBtnPos
+ maButtonImageSize
.Width() + 10, nYPos
),
639 Size( mnColumnWidth
[0] - maButtonImageSize
.Width() - 10, maButtonImageSize
.Height() ) );
640 maCalcButton
.SetPosSizePixel( Point( maControlRect
.Left() + nBtnPos
+ mnColumnWidth
[0], nYPos
), maButtonImageSize
);
641 maCalcText
.SetPosSizePixel( Point( maControlRect
.Left() + nBtnPos
+ maButtonImageSize
.Width() + 10 + mnColumnWidth
[0], nYPos
),
642 Size( mnColumnWidth
[1] - maButtonImageSize
.Width() - 10, maButtonImageSize
.Height() ) );
643 nYPos
+= nBDelta
- nDiff
;
644 maImpressButton
.SetPosSizePixel( Point( maControlRect
.Left() + nBtnPos
, nYPos
), maButtonImageSize
);
645 maImpressText
.SetPosSizePixel( Point( maControlRect
.Left() + nBtnPos
+ maButtonImageSize
.Width() + 10, nYPos
),
646 Size( mnColumnWidth
[0] - maButtonImageSize
.Width() - 10, maButtonImageSize
.Height() ) );
647 maDrawButton
.SetPosSizePixel( Point( maControlRect
.Left() + nBtnPos
+ mnColumnWidth
[0], nYPos
), maButtonImageSize
);
648 maDrawText
.SetPosSizePixel( Point( maControlRect
.Left() + nBtnPos
+ maButtonImageSize
.Width() + 10 + mnColumnWidth
[0], nYPos
),
649 Size( mnColumnWidth
[1] - maButtonImageSize
.Width() - 10, maButtonImageSize
.Height() ) );
650 nYPos
+= nBDelta
- nDiff
;
651 maDBButton
.SetPosSizePixel( Point( maControlRect
.Left() + nBtnPos
, nYPos
), maButtonImageSize
);
652 maDBText
.SetPosSizePixel( Point( maControlRect
.Left() + nBtnPos
+ maButtonImageSize
.Width() + 10, nYPos
),
653 Size( mnColumnWidth
[0] - maButtonImageSize
.Width() - 10, maButtonImageSize
.Height() ) );
654 maMathButton
.SetPosSizePixel( Point( maControlRect
.Left() + nBtnPos
+ mnColumnWidth
[0], nYPos
), maButtonImageSize
);
655 maMathText
.SetPosSizePixel( Point( maControlRect
.Left() + nBtnPos
+ maButtonImageSize
.Width() + 10 + mnColumnWidth
[0], nYPos
),
656 Size( mnColumnWidth
[1] - maButtonImageSize
.Width() - 10, maButtonImageSize
.Height() ) );
658 nYPos
+= nB2Delta
- nDiff
;
659 maTemplateButton
.SetPosSizePixel( Point( maControlRect
.Left() + nBtnPos
, nYPos
), maButtonImageSize
);
660 maTemplateText
.SetPosSizePixel( Point( maControlRect
.Left() + nBtnPos
+ maButtonImageSize
.Width() + 10, nYPos
),
661 Size( mnColumnWidth
[0]+mnColumnWidth
[1] - maButtonImageSize
.Width() - 10, maButtonImageSize
.Height() ) );
662 nYPos
+= nBDelta
- nDiff
;
663 maOpenButton
.SetPosSizePixel( Point( maControlRect
.Left() + nBtnPos
, nYPos
), maButtonImageSize
);
664 maOpenText
.SetPosSizePixel( Point( maControlRect
.Left() + nBtnPos
+ maButtonImageSize
.Width() + 10, nYPos
),
665 Size( mnColumnWidth
[0]+mnColumnWidth
[1] - maButtonImageSize
.Width() - 10, maButtonImageSize
.Height() ) );
666 nYPos
+= nBDelta
- nDiff
;
669 IMPL_LINK( BackingWindow
, ToolboxHdl
, void*, EMPTYARG
)
671 const char* pNodePath
= NULL
;
672 const char* pNode
= NULL
;
674 switch( maToolbox
.GetCurItemId() )
676 case nItemId_Extensions
:
677 pNodePath
= "/org.openoffice.Office.Common/Help/StartCenter";
678 pNode
= "AddFeatureURL";
683 // create the Desktop component which can load components
684 Reference
< lang::XMultiServiceFactory
> xFactory
= ::comphelper::getProcessServiceFactory();
687 Reference
< task::XJobExecutor
> xProductRegistration(
688 xFactory
->createInstance( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.setup.ProductRegistration" ) ) ),
691 // tell it that the user wants to register
692 xProductRegistration
->trigger( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "RegistrationRequired" ) ) );
695 catch( const Exception
& )
700 pNodePath
= "/org.openoffice.Office.Common/Help/StartCenter";
704 pNodePath
= "/org.openoffice.Office.Common/Help/StartCenter";
705 pNode
= "TemplateRepositoryURL";
710 if( pNodePath
&& pNode
)
714 Reference
<lang::XMultiServiceFactory
> xConfig( comphelper::getProcessServiceFactory()->createInstance(SERVICENAME_CFGPROVIDER
),UNO_QUERY
);
717 Sequence
<Any
> args(1);
719 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("nodepath") ),
721 Any(rtl::OUString::createFromAscii(pNodePath
)),
722 PropertyState_DIRECT_VALUE
);
723 args
.getArray()[0] <<= val
;
724 Reference
<container::XNameAccess
> xNameAccess(xConfig
->createInstanceWithArguments(SERVICENAME_CFGREADACCESS
,args
), UNO_QUERY
);
725 if( xNameAccess
.is() )
728 //throws css::container::NoSuchElementException, css::lang::WrappedTargetException
729 Any
value( xNameAccess
->getByName(rtl::OUString::createFromAscii(pNode
)) );
730 sURL
= value
.get
<rtl::OUString
> ();
732 Reference
< com::sun::star::system::XSystemShellExecute
> xSystemShellExecute(
733 comphelper::getProcessServiceFactory()->createInstance(
734 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.system.SystemShellExecute" ) ) ),
736 //throws css::lang::IllegalArgumentException, css::system::SystemShellExecuteException
737 xSystemShellExecute
->execute( sURL
, rtl::OUString(), com::sun::star::system::SystemShellExecuteFlags::DEFAULTS
);
749 IMPL_LINK( BackingWindow
, ClickHdl
, Button
*, pButton
)
751 // dispatch the appropriate URL and end the dialog
752 if( pButton
== &maWriterButton
)
753 dispatchURL( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(WRITER_URL
) ) );
754 else if( pButton
== &maCalcButton
)
755 dispatchURL( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(CALC_URL
) ) );
756 else if( pButton
== &maImpressButton
)
757 dispatchURL( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(IMPRESS_WIZARD_URL
) ) );
758 else if( pButton
== &maDrawButton
)
759 dispatchURL( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(DRAW_URL
) ) );
760 else if( pButton
== &maDBButton
)
761 dispatchURL( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(BASE_URL
) ) );
762 else if( pButton
== &maMathButton
)
763 dispatchURL( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(MATH_URL
) ) );
764 else if( pButton
== &maOpenButton
)
766 Reference
< XDispatchProvider
> xFrame( mxFrame
, UNO_QUERY
);
768 Sequence
< com::sun::star::beans::PropertyValue
> aArgs(1);
769 PropertyValue
* pArg
= aArgs
.getArray();
770 pArg
[0].Name
= rtl::OUString::createFromAscii("Referer");
771 pArg
[0].Value
<<= rtl::OUString::createFromAscii("private:user");
773 dispatchURL( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(OPEN_URL
) ), rtl::OUString(), xFrame
, aArgs
);
775 else if( pButton
== &maTemplateButton
)
777 Reference
< XDispatchProvider
> xFrame( mxFrame
, UNO_QUERY
);
779 Sequence
< com::sun::star::beans::PropertyValue
> aArgs(1);
780 PropertyValue
* pArg
= aArgs
.getArray();
781 pArg
[0].Name
= rtl::OUString::createFromAscii("Referer");
782 pArg
[0].Value
<<= rtl::OUString::createFromAscii("private:user");
784 dispatchURL( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(TEMPLATE_URL
) ), rtl::OUString(), xFrame
, aArgs
);
789 Window
* BackingWindow::GetParentLabelFor( const Window
* pLabel
) const
791 const Window
* pRet
= NULL
;
793 if( pLabel
== &maWriterText
)
794 pRet
= &maWriterButton
;
795 else if( pLabel
== &maCalcText
)
796 pRet
= &maCalcButton
;
797 else if( pLabel
== &maImpressText
)
798 pRet
= &maImpressButton
;
799 else if( pLabel
== &maDrawText
)
800 pRet
= &maDrawButton
;
801 else if( pLabel
== &maDBText
)
803 else if( pLabel
== &maMathText
)
804 pRet
= &maMathButton
;
805 else if( pLabel
== &maTemplateText
)
806 pRet
= &maTemplateButton
;
807 else if( pLabel
== &maOpenText
)
808 pRet
= &maOpenButton
;
810 return const_cast<Window
*>(pRet
);
813 Window
* BackingWindow::GetParentLabeledBy( const Window
* pLabeled
) const
815 const Window
*pRet
= NULL
;
817 if( pLabeled
== &maWriterButton
)
818 pRet
= &maWriterText
;
819 else if( pLabeled
== &maCalcButton
)
821 else if( pLabeled
== &maImpressButton
)
822 pRet
= &maImpressText
;
823 else if( pLabeled
== &maDrawButton
)
825 else if( pLabeled
== &maDBButton
)
827 else if( pLabeled
== &maMathButton
)
829 else if( pLabeled
== &maTemplateButton
)
830 pRet
= &maTemplateText
;
831 else if( pLabeled
== &maOpenButton
)
834 return const_cast<Window
*>(pRet
);
837 struct ImplDelayedDispatch
839 Reference
< XDispatch
> xDispatch
;
840 com::sun::star::util::URL aDispatchURL
;
841 Sequence
< PropertyValue
> aArgs
;
843 ImplDelayedDispatch( const Reference
< XDispatch
>& i_xDispatch
,
844 const com::sun::star::util::URL
& i_rURL
,
845 const Sequence
< PropertyValue
>& i_rArgs
)
846 : xDispatch( i_xDispatch
),
847 aDispatchURL( i_rURL
),
851 ~ImplDelayedDispatch() {}
854 static long implDispatchDelayed( void*, void* pArg
)
856 struct ImplDelayedDispatch
* pDispatch
= reinterpret_cast<ImplDelayedDispatch
*>(pArg
);
859 pDispatch
->xDispatch
->dispatch( pDispatch
->aDispatchURL
, pDispatch
->aArgs
);
871 void BackingWindow::dispatchURL( const rtl::OUString
& i_rURL
,
872 const rtl::OUString
& rTarget
,
873 const Reference
< XDispatchProvider
>& i_xProv
,
874 const Sequence
< PropertyValue
>& i_rArgs
)
876 // if no special dispatch provider is given, get the desktop
877 Reference
< XDispatchProvider
> xProvider( i_xProv
.is() ? i_xProv
: mxDesktopDispatchProvider
);
879 // check for dispatch provider
883 // get an URL transformer to clean up the URL
884 com::sun::star::util::URL aDispatchURL
;
885 aDispatchURL
.Complete
= i_rURL
;
887 Reference
< com::sun::star::util::XURLTransformer
> xURLTransformer(
888 comphelper::getProcessServiceFactory()->createInstance( rtl::OUString::createFromAscii("com.sun.star.util.URLTransformer") ),
889 com::sun::star::uno::UNO_QUERY
);
890 if ( xURLTransformer
.is() )
895 xURLTransformer
->parseStrict( aDispatchURL
);
896 // get a Dispatch for the URL and target
897 Reference
< XDispatch
> xDispatch(
898 xProvider
->queryDispatch( aDispatchURL
, rTarget
, 0 )
901 if ( xDispatch
.is() )
903 ImplDelayedDispatch
* pDisp
= new ImplDelayedDispatch( xDispatch
, aDispatchURL
, i_rArgs
);
905 if( ! Application::PostUserEvent( nEventId
, Link( NULL
, implDispatchDelayed
), pDisp
) )
906 delete pDisp
; // event could not be posted for unknown reason, at least don't leak
909 catch ( com::sun::star::uno::RuntimeException
& )
913 catch ( com::sun::star::uno::Exception
& )