LCOV - code coverage report
Current view: top level - libreoffice/framework/source/services - backingwindow.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 561 0.0 %
Date: 2012-12-27 Functions: 0 38 0.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10