LCOV - code coverage report
Current view: top level - svx/source/gallery2 - galbrws1.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 1 314 0.3 %
Date: 2014-04-11 Functions: 2 41 4.9 %
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             : #include "sal/config.h"
      21             : 
      22             : #include <comphelper/processfactory.hxx>
      23             : #include <tools/datetime.hxx>
      24             : #include <unotools/datetime.hxx>
      25             : #include <vcl/msgbox.hxx>
      26             : #include <vcl/settings.hxx>
      27             : #include <ucbhelper/content.hxx>
      28             : #include <sfx2/app.hxx>
      29             : #include "helpid.hrc"
      30             : #include "svx/gallery1.hxx"
      31             : #include "svx/galtheme.hxx"
      32             : #include "svx/galmisc.hxx"
      33             : #include "galbrws1.hxx"
      34             : #include <com/sun/star/util/DateTime.hpp>
      35             : #include "gallery.hrc"
      36             : #include <algorithm>
      37             : #include <svx/dialogs.hrc>
      38             : #include <svx/dialmgr.hxx>
      39             : 
      40             : #include <svx/svxdlg.hxx>
      41             : 
      42             : // - Namespaces -
      43             : 
      44             : using namespace ::rtl;
      45             : using namespace ::com::sun::star;
      46             : 
      47             : // - GalleryButton -
      48             : 
      49           0 : GalleryButton::GalleryButton( GalleryBrowser1* pParent, WinBits nWinBits ) :
      50           0 :     PushButton( pParent, nWinBits )
      51             : {
      52           0 : }
      53             : 
      54           0 : GalleryButton::~GalleryButton()
      55             : {
      56           0 : }
      57             : 
      58           0 : void GalleryButton::KeyInput( const KeyEvent& rKEvt )
      59             : {
      60           0 :     if( !static_cast< GalleryBrowser1* >( GetParent() )->KeyInput( rKEvt, this ) )
      61           0 :         PushButton::KeyInput( rKEvt );
      62           0 : }
      63             : 
      64             : // - GalleryThemeListBox -
      65             : 
      66           0 : GalleryThemeListBox::GalleryThemeListBox( GalleryBrowser1* pParent, WinBits nWinBits ) :
      67           0 :     ListBox( pParent, nWinBits )
      68             : {
      69           0 :     InitSettings();
      70           0 : }
      71             : 
      72           0 : GalleryThemeListBox::~GalleryThemeListBox()
      73             : {
      74           0 : }
      75             : 
      76           0 : void GalleryThemeListBox::InitSettings()
      77             : {
      78           0 :     SetBackground( Wallpaper( GALLERY_BG_COLOR ) );
      79           0 :     SetControlBackground( GALLERY_BG_COLOR );
      80           0 :     SetControlForeground( GALLERY_FG_COLOR );
      81           0 : }
      82             : 
      83           0 : void GalleryThemeListBox::DataChanged( const DataChangedEvent& rDCEvt )
      84             : {
      85           0 :     if ( ( rDCEvt.GetType() == DATACHANGED_SETTINGS ) && ( rDCEvt.GetFlags() & SETTINGS_STYLE ) )
      86           0 :         InitSettings();
      87             :     else
      88           0 :         ListBox::DataChanged( rDCEvt );
      89           0 : }
      90             : 
      91           0 : bool GalleryThemeListBox::PreNotify( NotifyEvent& rNEvt )
      92             : {
      93           0 :     bool bDone = false;
      94             : 
      95           0 :     if( rNEvt.GetType() == EVENT_COMMAND )
      96             :     {
      97           0 :         const CommandEvent* pCEvt = rNEvt.GetCommandEvent();
      98             : 
      99           0 :         if( pCEvt && pCEvt->GetCommand() == COMMAND_CONTEXTMENU )
     100           0 :             static_cast< GalleryBrowser1* >( GetParent() )->ShowContextMenu();
     101             :     }
     102           0 :     else if( rNEvt.GetType() == EVENT_KEYINPUT )
     103             :     {
     104           0 :         const KeyEvent* pKEvt = rNEvt.GetKeyEvent();
     105             : 
     106           0 :         if( pKEvt )
     107           0 :             bDone = static_cast< GalleryBrowser1* >( GetParent() )->KeyInput( *pKEvt, this );
     108             :     }
     109             : 
     110           0 :     return( bDone || ListBox::PreNotify( rNEvt ) );
     111             : }
     112             : 
     113             : // - GalleryBrowser1 -
     114             : 
     115           0 : GalleryBrowser1::GalleryBrowser1(
     116             :     Window* pParent,
     117             :     const ResId& rResId,
     118             :     Gallery* pGallery,
     119             :     const ::boost::function<sal_Bool(const KeyEvent&,Window*)>& rKeyInputHandler,
     120             :     const ::boost::function<void(void)>& rThemeSlectionHandler)
     121             :     :
     122             :     Control               ( pParent, rResId ),
     123             :     maNewTheme            ( this, WB_3DLOOK ),
     124           0 :     mpThemes              ( new GalleryThemeListBox( this, WB_TABSTOP | WB_3DLOOK | WB_BORDER | WB_HSCROLL | WB_VSCROLL | WB_AUTOHSCROLL | WB_SORT ) ),
     125             :     mpGallery             ( pGallery ),
     126           0 :     mpExchangeData        ( new ExchangeData ),
     127             :     mpThemePropsDlgItemSet( NULL ),
     128             :     aImgNormal            ( GalleryResGetBitmapEx( RID_SVXBMP_THEME_NORMAL ) ),
     129             :     aImgDefault           ( GalleryResGetBitmapEx( RID_SVXBMP_THEME_DEFAULT ) ),
     130             :     aImgReadOnly          ( GalleryResGetBitmapEx( RID_SVXBMP_THEME_READONLY ) ),
     131             :     maKeyInputHandler(rKeyInputHandler),
     132           0 :     maThemeSlectionHandler(rThemeSlectionHandler)
     133             : {
     134           0 :     StartListening( *mpGallery );
     135             : 
     136           0 :     maNewTheme.SetHelpId( HID_GALLERY_NEWTHEME );
     137           0 :     maNewTheme.SetText( GAL_RESSTR(RID_SVXSTR_GALLERY_CREATETHEME));
     138           0 :     maNewTheme.SetClickHdl( LINK( this, GalleryBrowser1, ClickNewThemeHdl ) );
     139             : 
     140             :     // disable creation of new themes if a writable directory is not available
     141           0 :     if( mpGallery->GetUserURL().GetProtocol() == INET_PROT_NOT_VALID )
     142           0 :         maNewTheme.Disable();
     143             : 
     144           0 :     mpThemes->SetHelpId( HID_GALLERY_THEMELIST );
     145           0 :     mpThemes->SetSelectHdl( LINK( this, GalleryBrowser1, SelectThemeHdl ) );
     146           0 :     mpThemes->SetAccessibleName(SVX_RESSTR(RID_SVXSTR_GALLERYPROPS_GALTHEME));
     147             : 
     148           0 :     for( sal_uIntPtr i = 0, nCount = mpGallery->GetThemeCount(); i < nCount; i++ )
     149           0 :         ImplInsertThemeEntry( mpGallery->GetThemeInfo( i ) );
     150             : 
     151           0 :     ImplAdjustControls();
     152           0 :     maNewTheme.Show( true );
     153           0 :     mpThemes->Show( true );
     154           0 : }
     155             : 
     156           0 : GalleryBrowser1::~GalleryBrowser1()
     157             : {
     158           0 :     EndListening( *mpGallery );
     159           0 :     delete mpThemes;
     160           0 :     mpThemes = NULL;
     161           0 :     delete mpExchangeData;
     162           0 :     mpExchangeData = NULL;
     163           0 : }
     164             : 
     165           0 : sal_uIntPtr GalleryBrowser1::ImplInsertThemeEntry( const GalleryThemeEntry* pEntry )
     166             : {
     167           0 :     static const sal_Bool bShowHiddenThemes = ( getenv( "GALLERY_SHOW_HIDDEN_THEMES" ) != NULL );
     168             : 
     169           0 :     sal_uIntPtr nRet = LISTBOX_ENTRY_NOTFOUND;
     170             : 
     171           0 :     if( pEntry && ( !pEntry->IsHidden() || bShowHiddenThemes ) )
     172             :     {
     173             :         const Image* pImage;
     174             : 
     175           0 :         if( pEntry->IsReadOnly() )
     176           0 :             pImage = &aImgReadOnly;
     177           0 :         else if( pEntry->IsDefault() )
     178           0 :             pImage = &aImgDefault;
     179             :         else
     180           0 :             pImage = &aImgNormal;
     181             : 
     182           0 :         nRet = mpThemes->InsertEntry( pEntry->GetThemeName(), *pImage );
     183             :     }
     184             : 
     185           0 :     return nRet;
     186             : }
     187             : 
     188           0 : void GalleryBrowser1::ImplAdjustControls()
     189             : {
     190           0 :     const Size  aOutSize( GetOutputSizePixel() );
     191           0 :     const long  nNewThemeHeight = LogicToPixel( Size( 0, 14 ), MAP_APPFONT ).Height();
     192           0 :     const long  nStartY = nNewThemeHeight + 4;
     193             : 
     194             :     maNewTheme.SetPosSizePixel( Point(),
     195           0 :                                 Size( aOutSize.Width(), nNewThemeHeight ) );
     196             : 
     197             :     mpThemes->SetPosSizePixel( Point( 0, nStartY ),
     198           0 :                                Size( aOutSize.Width(), aOutSize.Height() - nStartY ) );
     199           0 : }
     200             : 
     201           0 : void GalleryBrowser1::ImplFillExchangeData( const GalleryTheme* pThm, ExchangeData& rData )
     202             : {
     203           0 :     rData.pTheme = (GalleryTheme*) pThm;
     204           0 :     rData.aEditedTitle = pThm->GetName();
     205             : 
     206             :     try
     207             :     {
     208           0 :         ::ucbhelper::Content aCnt( pThm->GetThmURL().GetMainURL( INetURLObject::NO_DECODE ), uno::Reference< ucb::XCommandEnvironment >(), comphelper::getProcessComponentContext() );
     209           0 :         util::DateTime  aDateTimeModified;
     210           0 :         DateTime        aDateTime( DateTime::EMPTY );
     211             : 
     212           0 :         aCnt.getPropertyValue("DateModified") >>= aDateTimeModified;
     213           0 :         ::utl::typeConvert( aDateTimeModified, aDateTime );
     214           0 :         rData.aThemeChangeDate = aDateTime;
     215           0 :         rData.aThemeChangeTime = aDateTime;
     216             :     }
     217           0 :     catch( const ucb::ContentCreationException& )
     218             :     {
     219             :     }
     220           0 :     catch( const uno::RuntimeException& )
     221             :     {
     222             :     }
     223           0 :     catch( const uno::Exception& )
     224             :     {
     225             :     }
     226           0 : }
     227             : 
     228           0 : void GalleryBrowser1::ImplGetExecuteVector(::std::vector< sal_uInt16 >& o_aExec)
     229             : {
     230           0 :     GalleryTheme*           pTheme = mpGallery->AcquireTheme( GetSelectedTheme(), *this );
     231             : 
     232           0 :     if( pTheme )
     233             :     {
     234             :         sal_Bool                bUpdateAllowed, bRenameAllowed, bRemoveAllowed;
     235           0 :         static const sal_Bool   bIdDialog = ( getenv( "GALLERY_ENABLE_ID_DIALOG" ) != NULL );
     236             : 
     237           0 :         if( pTheme->IsReadOnly() )
     238           0 :             bUpdateAllowed = bRenameAllowed = bRemoveAllowed = sal_False;
     239           0 :         else if( pTheme->IsDefault() )
     240             :         {
     241           0 :             bUpdateAllowed = bRenameAllowed = sal_True;
     242           0 :             bRemoveAllowed = sal_False;
     243             :         }
     244             :         else
     245           0 :             bUpdateAllowed = bRenameAllowed = bRemoveAllowed = sal_True;
     246             : 
     247           0 :         if( bUpdateAllowed && pTheme->GetObjectCount() )
     248           0 :             o_aExec.push_back( MN_ACTUALIZE );
     249             : 
     250           0 :         if( bRenameAllowed )
     251           0 :             o_aExec.push_back( MN_RENAME );
     252             : 
     253           0 :         if( bRemoveAllowed )
     254           0 :             o_aExec.push_back( MN_DELETE );
     255             : 
     256           0 :         if( bIdDialog && !pTheme->IsReadOnly() )
     257           0 :             o_aExec.push_back( MN_ASSIGN_ID );
     258             : 
     259           0 :         o_aExec.push_back( MN_PROPERTIES );
     260             : 
     261           0 :         mpGallery->ReleaseTheme( pTheme, *this );
     262             :     }
     263           0 : }
     264             : 
     265           0 : void GalleryBrowser1::ImplGalleryThemeProperties( const OUString & rThemeName, bool bCreateNew )
     266             : {
     267             :     DBG_ASSERT(!mpThemePropsDlgItemSet, "mpThemePropsDlgItemSet already set!");
     268           0 :     mpThemePropsDlgItemSet = new SfxItemSet( SFX_APP()->GetPool() );
     269           0 :     GalleryTheme*   pTheme = mpGallery->AcquireTheme( rThemeName, *this );
     270             : 
     271           0 :     ImplFillExchangeData( pTheme, *mpExchangeData );
     272             : 
     273           0 :     SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
     274             :     DBG_ASSERT(pFact, "Got no AbstractDialogFactory!");
     275           0 :     VclAbstractDialog2* pThemeProps = pFact->CreateGalleryThemePropertiesDialog( NULL, mpExchangeData, mpThemePropsDlgItemSet );
     276             :     DBG_ASSERT(pThemeProps, "Got no GalleryThemePropertiesDialog!");
     277             : 
     278           0 :     if ( bCreateNew )
     279             :     {
     280             :         pThemeProps->StartExecuteModal(
     281           0 :             LINK( this, GalleryBrowser1, EndNewThemePropertiesDlgHdl ) );
     282             :     }
     283             :     else
     284             :     {
     285             :         pThemeProps->StartExecuteModal(
     286           0 :             LINK( this, GalleryBrowser1, EndThemePropertiesDlgHdl ) );
     287             :     }
     288           0 : }
     289             : 
     290           0 : void GalleryBrowser1::ImplEndGalleryThemeProperties( VclAbstractDialog2* pDialog, bool bCreateNew )
     291             : {
     292           0 :     long nRet = pDialog->GetResult();
     293             : 
     294           0 :     if( nRet == RET_OK )
     295             :     {
     296           0 :         OUString aName( mpExchangeData->pTheme->GetName() );
     297             : 
     298           0 :         if( !mpExchangeData->aEditedTitle.isEmpty() && aName != mpExchangeData->aEditedTitle )
     299             :         {
     300           0 :             const OUString      aOldName( aName );
     301           0 :             OUString            aTitle( mpExchangeData->aEditedTitle );
     302           0 :             sal_uInt16          nCount = 0;
     303             : 
     304           0 :             while( mpGallery->HasTheme( aTitle ) && ( nCount++ < 16000 ) )
     305             :             {
     306           0 :                 aTitle = mpExchangeData->aEditedTitle;
     307           0 :                 aTitle += " ";
     308           0 :                 aTitle += OUString::number( nCount );
     309             :             }
     310             : 
     311           0 :             mpGallery->RenameTheme( aOldName, aTitle );
     312             :         }
     313             : 
     314           0 :         if ( bCreateNew )
     315             :         {
     316           0 :             mpThemes->SelectEntry( mpExchangeData->pTheme->GetName() );
     317           0 :             SelectThemeHdl( NULL );
     318           0 :         }
     319             :     }
     320             : 
     321           0 :     OUString aThemeName( mpExchangeData->pTheme->GetName() );
     322           0 :     mpGallery->ReleaseTheme( mpExchangeData->pTheme, *this );
     323             : 
     324           0 :     if ( bCreateNew && ( nRet != RET_OK ) )
     325             :     {
     326           0 :         mpGallery->RemoveTheme( aThemeName );
     327             :     }
     328             : 
     329             :     // destroy mpThemeProps asynchronously
     330           0 :     Application::PostUserEvent( LINK( this, GalleryBrowser1, DestroyThemePropertiesDlgHdl ), pDialog );
     331           0 : }
     332             : 
     333           0 : IMPL_LINK( GalleryBrowser1, EndNewThemePropertiesDlgHdl, VclAbstractDialog2*, pDialog )
     334             : {
     335           0 :     ImplEndGalleryThemeProperties( pDialog, true );
     336           0 :     return 0L;
     337             : }
     338             : 
     339           0 : IMPL_LINK( GalleryBrowser1, EndThemePropertiesDlgHdl, VclAbstractDialog2*, pDialog )
     340             : {
     341           0 :     ImplEndGalleryThemeProperties( pDialog, false );
     342           0 :     return 0L;
     343             : }
     344             : 
     345           0 : IMPL_LINK( GalleryBrowser1, DestroyThemePropertiesDlgHdl, VclAbstractDialog2*, pDialog )
     346             : {
     347           0 :     delete pDialog;
     348           0 :     delete mpThemePropsDlgItemSet;
     349           0 :     mpThemePropsDlgItemSet = 0;
     350           0 :     return 0L;
     351             : }
     352             : 
     353           0 : void GalleryBrowser1::ImplExecute( sal_uInt16 nId )
     354             : {
     355           0 :     switch( nId )
     356             :     {
     357             :         case( MN_ACTUALIZE ):
     358             :         {
     359           0 :             GalleryTheme*       pTheme = mpGallery->AcquireTheme( GetSelectedTheme(), *this );
     360             : 
     361           0 :             SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
     362           0 :             if(pFact)
     363             :             {
     364           0 :                 VclAbstractRefreshableDialog* aActualizeProgress = pFact->CreateActualizeProgressDialog( this, pTheme );
     365             :                 DBG_ASSERT(aActualizeProgress, "Dialogdiet fail!");
     366             : 
     367           0 :                 aActualizeProgress->Update();
     368           0 :                 aActualizeProgress->Execute();
     369           0 :                 mpGallery->ReleaseTheme( pTheme, *this );
     370           0 :                 delete aActualizeProgress;
     371             :             }
     372             :         }
     373           0 :         break;
     374             : 
     375             :         case( MN_DELETE  ):
     376             :         {
     377           0 :             if( MessageDialog( NULL, "QueryDeleteThemeDialog","svx/ui/querydeletethemedialog.ui").Execute() == RET_YES )
     378           0 :                 mpGallery->RemoveTheme( mpThemes->GetSelectEntry() );
     379             :         }
     380           0 :         break;
     381             : 
     382             :         case( MN_RENAME ):
     383             :         {
     384           0 :             GalleryTheme*   pTheme = mpGallery->AcquireTheme( GetSelectedTheme(), *this );
     385           0 :             const OUString  aOldName( pTheme->GetName() );
     386             : 
     387           0 :             SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
     388             :             DBG_ASSERT(pFact, "Dialogdiet fail!");
     389           0 :             AbstractTitleDialog* aDlg = pFact->CreateTitleDialog( this, aOldName );
     390             :             DBG_ASSERT(aDlg, "Dialogdiet fail!");
     391             : 
     392           0 :             if( aDlg->Execute() == RET_OK )
     393             :             {
     394           0 :                 const OUString aNewName( aDlg->GetTitle() );
     395             : 
     396           0 :                 if( !aNewName.isEmpty() && ( aNewName != aOldName ) )
     397             :                 {
     398           0 :                     OUString  aName( aNewName );
     399           0 :                     sal_uInt16  nCount = 0;
     400             : 
     401           0 :                     while( mpGallery->HasTheme( aName ) && ( nCount++ < 16000 ) )
     402             :                     {
     403           0 :                         aName = aNewName;
     404           0 :                         aName += " ";
     405           0 :                         aName += OUString::number( nCount );
     406             :                     }
     407             : 
     408           0 :                     mpGallery->RenameTheme( aOldName, aName );
     409           0 :                 }
     410             :             }
     411           0 :             mpGallery->ReleaseTheme( pTheme, *this );
     412           0 :             delete aDlg;
     413             :         }
     414           0 :         break;
     415             : 
     416             :         case( MN_ASSIGN_ID ):
     417             :         {
     418           0 :             GalleryTheme* pTheme = mpGallery->AcquireTheme( GetSelectedTheme(), *this );
     419             : 
     420           0 :             if (pTheme && !pTheme->IsReadOnly())
     421             :             {
     422             : 
     423           0 :                 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
     424           0 :                 if(pFact)
     425             :                 {
     426           0 :                     AbstractGalleryIdDialog* aDlg = pFact->CreateGalleryIdDialog( this, pTheme );
     427             :                     DBG_ASSERT(aDlg, "Dialogdiet fail!");
     428             : 
     429           0 :                     if( aDlg->Execute() == RET_OK )
     430           0 :                         pTheme->SetId( aDlg->GetId(), true );
     431           0 :                     delete aDlg;
     432             :                 }
     433             :             }
     434             : 
     435           0 :             mpGallery->ReleaseTheme( pTheme, *this );
     436             :         }
     437           0 :         break;
     438             : 
     439             :         case( MN_PROPERTIES ):
     440             :         {
     441           0 :             ImplGalleryThemeProperties( GetSelectedTheme(), false );
     442             :         }
     443           0 :         break;
     444             :     }
     445           0 : }
     446             : 
     447           0 : void GalleryBrowser1::Resize()
     448             : {
     449           0 :     Control::Resize();
     450           0 :     ImplAdjustControls();
     451           0 : }
     452             : 
     453           0 : void GalleryBrowser1::GetFocus()
     454             : {
     455           0 :     Control::GetFocus();
     456           0 :     if( mpThemes )
     457           0 :         mpThemes->GrabFocus();
     458           0 : }
     459             : 
     460           0 : void GalleryBrowser1::Notify( SfxBroadcaster&, const SfxHint& rHint )
     461             : {
     462           0 :     const GalleryHint& rGalleryHint = (const GalleryHint&) rHint;
     463             : 
     464           0 :     switch( rGalleryHint.GetType() )
     465             :     {
     466             :         case( GALLERY_HINT_THEME_CREATED ):
     467           0 :             ImplInsertThemeEntry( mpGallery->GetThemeInfo( rGalleryHint.GetThemeName() ) );
     468           0 :         break;
     469             : 
     470             :         case( GALLERY_HINT_THEME_RENAMED ):
     471             :         {
     472           0 :             const sal_uInt16 nCurSelectPos = mpThemes->GetSelectEntryPos();
     473           0 :             const sal_uInt16 nRenameEntryPos = mpThemes->GetEntryPos( rGalleryHint.GetThemeName() );
     474             : 
     475           0 :             mpThemes->RemoveEntry( rGalleryHint.GetThemeName() );
     476           0 :             ImplInsertThemeEntry( mpGallery->GetThemeInfo( rGalleryHint.GetStringData() ) );
     477             : 
     478           0 :             if( nCurSelectPos == nRenameEntryPos )
     479             :             {
     480           0 :                 mpThemes->SelectEntry( rGalleryHint.GetStringData() );
     481           0 :                 SelectThemeHdl( NULL );
     482             :             }
     483             :         }
     484           0 :         break;
     485             : 
     486             :         case( GALLERY_HINT_THEME_REMOVED ):
     487             :         {
     488           0 :             mpThemes->RemoveEntry( rGalleryHint.GetThemeName() );
     489             :         }
     490           0 :         break;
     491             : 
     492             :         case( GALLERY_HINT_CLOSE_THEME ):
     493             :         {
     494           0 :             const sal_uInt16 nCurSelectPos = mpThemes->GetSelectEntryPos();
     495           0 :             const sal_uInt16 nCloseEntryPos = mpThemes->GetEntryPos( rGalleryHint.GetThemeName() );
     496             : 
     497           0 :             if( nCurSelectPos == nCloseEntryPos )
     498             :             {
     499           0 :                 if( nCurSelectPos < ( mpThemes->GetEntryCount() - 1 ) )
     500           0 :                     mpThemes->SelectEntryPos( nCurSelectPos + 1 );
     501           0 :                 else if( nCurSelectPos )
     502           0 :                     mpThemes->SelectEntryPos( nCurSelectPos - 1 );
     503             :                 else
     504           0 :                     mpThemes->SetNoSelection();
     505             : 
     506           0 :                 SelectThemeHdl( NULL );
     507             :             }
     508             :         }
     509           0 :         break;
     510             : 
     511             :         default:
     512           0 :         break;
     513             :     }
     514           0 : }
     515             : 
     516           0 : void GalleryBrowser1::ShowContextMenu()
     517             : {
     518           0 :     Application::PostUserEvent( LINK( this, GalleryBrowser1, ShowContextMenuHdl ), this );
     519           0 : }
     520             : 
     521           0 : sal_Bool GalleryBrowser1::KeyInput( const KeyEvent& rKEvt, Window* pWindow )
     522             : {
     523           0 :     sal_Bool bRet (sal_False);
     524           0 :     if (maKeyInputHandler)
     525           0 :         bRet = maKeyInputHandler(rKEvt, pWindow);
     526             : 
     527           0 :     if( !bRet )
     528             :     {
     529           0 :         ::std::vector< sal_uInt16 > aExecVector;
     530           0 :         ImplGetExecuteVector(aExecVector);
     531           0 :         sal_uInt16                  nExecuteId = 0;
     532           0 :         sal_Bool                    bMod1 = rKEvt.GetKeyCode().IsMod1();
     533             : 
     534           0 :         switch( rKEvt.GetKeyCode().GetCode() )
     535             :         {
     536             :             case( KEY_INSERT ):
     537           0 :                 ClickNewThemeHdl( NULL );
     538           0 :             break;
     539             : 
     540             :             case( KEY_I ):
     541             :             {
     542           0 :                 if( bMod1 )
     543           0 :                    ClickNewThemeHdl( NULL );
     544             :             }
     545           0 :             break;
     546             : 
     547             :             case( KEY_U ):
     548             :             {
     549           0 :                 if( bMod1 )
     550           0 :                     nExecuteId = MN_ACTUALIZE;
     551             :             }
     552           0 :             break;
     553             : 
     554             :             case( KEY_DELETE ):
     555           0 :                 nExecuteId = MN_DELETE;
     556           0 :             break;
     557             : 
     558             :             case( KEY_D ):
     559             :             {
     560           0 :                 if( bMod1 )
     561           0 :                     nExecuteId = MN_DELETE;
     562             :             }
     563           0 :             break;
     564             : 
     565             :             case( KEY_R ):
     566             :             {
     567           0 :                 if( bMod1 )
     568           0 :                     nExecuteId = MN_RENAME;
     569             :             }
     570           0 :             break;
     571             : 
     572             :             case( KEY_RETURN ):
     573             :             {
     574           0 :                 if( bMod1 )
     575           0 :                     nExecuteId = MN_PROPERTIES;
     576             :             }
     577           0 :             break;
     578             :         }
     579             : 
     580           0 :         if( nExecuteId && ( ::std::find( aExecVector.begin(), aExecVector.end(), nExecuteId ) != aExecVector.end() ) )
     581             :         {
     582           0 :             ImplExecute( nExecuteId );
     583           0 :             bRet = sal_True;
     584           0 :         }
     585             :     }
     586             : 
     587           0 :     return bRet;
     588             : }
     589             : 
     590           0 : IMPL_LINK_NOARG(GalleryBrowser1, ShowContextMenuHdl)
     591             : {
     592           0 :     ::std::vector< sal_uInt16 > aExecVector;
     593           0 :     ImplGetExecuteVector(aExecVector);
     594             : 
     595           0 :     if( !aExecVector.empty() )
     596             :     {
     597           0 :         PopupMenu aMenu( GAL_RES( RID_SVXMN_GALLERY1 ) );
     598             : 
     599           0 :         aMenu.EnableItem( MN_ACTUALIZE, ::std::find( aExecVector.begin(), aExecVector.end(), MN_ACTUALIZE ) != aExecVector.end() );
     600           0 :         aMenu.EnableItem( MN_RENAME, ::std::find( aExecVector.begin(), aExecVector.end(), MN_RENAME ) != aExecVector.end() );
     601           0 :         aMenu.EnableItem( MN_DELETE, ::std::find( aExecVector.begin(), aExecVector.end(), MN_DELETE ) != aExecVector.end() );
     602           0 :         aMenu.EnableItem( MN_ASSIGN_ID, ::std::find( aExecVector.begin(), aExecVector.end(), MN_ASSIGN_ID ) != aExecVector.end() );
     603           0 :         aMenu.EnableItem( MN_PROPERTIES, ::std::find( aExecVector.begin(), aExecVector.end(), MN_PROPERTIES ) != aExecVector.end() );
     604           0 :         aMenu.SetSelectHdl( LINK( this, GalleryBrowser1, PopupMenuHdl ) );
     605           0 :         aMenu.RemoveDisabledEntries();
     606             : 
     607           0 :         const Rectangle aThemesRect( mpThemes->GetPosPixel(), mpThemes->GetOutputSizePixel() );
     608           0 :         Point           aSelPos( mpThemes->GetBoundingRectangle( mpThemes->GetSelectEntryPos() ).Center() );
     609             : 
     610           0 :         aSelPos.X() = std::max( std::min( aSelPos.X(), aThemesRect.Right() ), aThemesRect.Left() );
     611           0 :         aSelPos.Y() = std::max( std::min( aSelPos.Y(), aThemesRect.Bottom() ), aThemesRect.Top() );
     612             : 
     613           0 :         aMenu.Execute( this, aSelPos );
     614             :     }
     615             : 
     616           0 :     return 0L;
     617             : }
     618             : 
     619           0 : IMPL_LINK( GalleryBrowser1, PopupMenuHdl, Menu*, pMenu )
     620             : {
     621           0 :     ImplExecute( pMenu->GetCurItemId() );
     622           0 :     return 0L;
     623             : }
     624             : 
     625           0 : IMPL_LINK_NOARG(GalleryBrowser1, SelectThemeHdl)
     626             : {
     627           0 :     if (maThemeSlectionHandler)
     628           0 :         maThemeSlectionHandler();
     629           0 :     return 0L;
     630             : }
     631             : 
     632           0 : IMPL_LINK_NOARG(GalleryBrowser1, ClickNewThemeHdl)
     633             : {
     634           0 :     OUString  aNewTheme( GAL_RESSTR(RID_SVXSTR_GALLERY_NEWTHEME) );
     635           0 :     OUString  aName( aNewTheme );
     636           0 :     sal_uIntPtr nCount = 0;
     637             : 
     638           0 :     while( mpGallery->HasTheme( aName ) && ( nCount++ < 16000 ) )
     639             :     {
     640           0 :         aName = aNewTheme;
     641           0 :         aName += " ";
     642           0 :         aName += OUString::number( nCount );
     643             :     }
     644             : 
     645           0 :     if( !mpGallery->HasTheme( aName ) && mpGallery->CreateTheme( aName ) )
     646             :     {
     647           0 :         ImplGalleryThemeProperties( aName, true );
     648             :     }
     649             : 
     650           0 :     return 0L;
     651         297 : }
     652             : 
     653             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10