1*f6e50924SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*f6e50924SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*f6e50924SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*f6e50924SAndrew Rist * distributed with this work for additional information 6*f6e50924SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*f6e50924SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*f6e50924SAndrew Rist * "License"); you may not use this file except in compliance 9*f6e50924SAndrew Rist * with the License. You may obtain a copy of the License at 10*f6e50924SAndrew Rist * 11*f6e50924SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*f6e50924SAndrew Rist * 13*f6e50924SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*f6e50924SAndrew Rist * software distributed under the License is distributed on an 15*f6e50924SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*f6e50924SAndrew Rist * KIND, either express or implied. See the License for the 17*f6e50924SAndrew Rist * specific language governing permissions and limitations 18*f6e50924SAndrew Rist * under the License. 19*f6e50924SAndrew Rist * 20*f6e50924SAndrew Rist *************************************************************/ 21*f6e50924SAndrew Rist 22*f6e50924SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_svx.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include <tools/datetime.hxx> 28cdf0e10cSrcweir #include <unotools/datetime.hxx> 29cdf0e10cSrcweir #include <vcl/msgbox.hxx> 30cdf0e10cSrcweir #include <ucbhelper/content.hxx> 31cdf0e10cSrcweir #include <sfx2/app.hxx> 32cdf0e10cSrcweir #include "helpid.hrc" 33cdf0e10cSrcweir #include "svx/gallery1.hxx" 34cdf0e10cSrcweir #include "svx/galtheme.hxx" 35cdf0e10cSrcweir #include "svx/galmisc.hxx" 36cdf0e10cSrcweir #include "galbrws1.hxx" 37cdf0e10cSrcweir #include <com/sun/star/util/DateTime.hpp> 38cdf0e10cSrcweir #include "gallery.hrc" 39cdf0e10cSrcweir #include <algorithm> 40cdf0e10cSrcweir #include <svx/dialogs.hrc> 41cdf0e10cSrcweir #include <svx/dialmgr.hxx> 42cdf0e10cSrcweir 43cdf0e10cSrcweir #include <svx/svxdlg.hxx> //CHINA001 44cdf0e10cSrcweir //CHINA001 #include <svx/dialogs.hrc> //CHINA001 45cdf0e10cSrcweir 46cdf0e10cSrcweir // -------------- 47cdf0e10cSrcweir // - Namespaces - 48cdf0e10cSrcweir // -------------- 49cdf0e10cSrcweir 50cdf0e10cSrcweir using namespace ::rtl; 51cdf0e10cSrcweir using namespace ::com::sun::star; 52cdf0e10cSrcweir 53cdf0e10cSrcweir // ----------------- 54cdf0e10cSrcweir // - GalleryButton - 55cdf0e10cSrcweir // ----------------- 56cdf0e10cSrcweir DBG_NAME(GalleryButton) 57cdf0e10cSrcweir 58cdf0e10cSrcweir GalleryButton::GalleryButton( GalleryBrowser1* pParent, WinBits nWinBits ) : 59cdf0e10cSrcweir PushButton( pParent, nWinBits ) 60cdf0e10cSrcweir { 61cdf0e10cSrcweir DBG_CTOR(GalleryButton,NULL); 62cdf0e10cSrcweir 63cdf0e10cSrcweir } 64cdf0e10cSrcweir 65cdf0e10cSrcweir // ----------------------------------------------------------------------------- 66cdf0e10cSrcweir 67cdf0e10cSrcweir GalleryButton::~GalleryButton() 68cdf0e10cSrcweir { 69cdf0e10cSrcweir 70cdf0e10cSrcweir DBG_DTOR(GalleryButton,NULL); 71cdf0e10cSrcweir } 72cdf0e10cSrcweir 73cdf0e10cSrcweir // ----------------------------------------------------------------------------- 74cdf0e10cSrcweir 75cdf0e10cSrcweir void GalleryButton::KeyInput( const KeyEvent& rKEvt ) 76cdf0e10cSrcweir { 77cdf0e10cSrcweir if( !static_cast< GalleryBrowser1* >( GetParent() )->KeyInput( rKEvt, this ) ) 78cdf0e10cSrcweir PushButton::KeyInput( rKEvt ); 79cdf0e10cSrcweir } 80cdf0e10cSrcweir 81cdf0e10cSrcweir // ----------------------- 82cdf0e10cSrcweir // - GalleryThemeListBox - 83cdf0e10cSrcweir // ----------------------- 84cdf0e10cSrcweir DBG_NAME(GalleryThemeListBox) 85cdf0e10cSrcweir 86cdf0e10cSrcweir GalleryThemeListBox::GalleryThemeListBox( GalleryBrowser1* pParent, WinBits nWinBits ) : 87cdf0e10cSrcweir ListBox( pParent, nWinBits ) 88cdf0e10cSrcweir { 89cdf0e10cSrcweir DBG_CTOR(GalleryThemeListBox,NULL); 90cdf0e10cSrcweir 91cdf0e10cSrcweir InitSettings(); 92cdf0e10cSrcweir } 93cdf0e10cSrcweir 94cdf0e10cSrcweir // ----------------------------------------------------------------------------- 95cdf0e10cSrcweir 96cdf0e10cSrcweir GalleryThemeListBox::~GalleryThemeListBox() 97cdf0e10cSrcweir { 98cdf0e10cSrcweir 99cdf0e10cSrcweir DBG_DTOR(GalleryThemeListBox,NULL); 100cdf0e10cSrcweir } 101cdf0e10cSrcweir 102cdf0e10cSrcweir // ------------------------------------------------------------------------ 103cdf0e10cSrcweir 104cdf0e10cSrcweir void GalleryThemeListBox::InitSettings() 105cdf0e10cSrcweir { 106cdf0e10cSrcweir SetBackground( Wallpaper( GALLERY_BG_COLOR ) ); 107cdf0e10cSrcweir SetControlBackground( GALLERY_BG_COLOR ); 108cdf0e10cSrcweir SetControlForeground( GALLERY_FG_COLOR ); 109cdf0e10cSrcweir } 110cdf0e10cSrcweir 111cdf0e10cSrcweir // ----------------------------------------------------------------------- 112cdf0e10cSrcweir 113cdf0e10cSrcweir void GalleryThemeListBox::DataChanged( const DataChangedEvent& rDCEvt ) 114cdf0e10cSrcweir { 115cdf0e10cSrcweir if ( ( rDCEvt.GetType() == DATACHANGED_SETTINGS ) && ( rDCEvt.GetFlags() & SETTINGS_STYLE ) ) 116cdf0e10cSrcweir InitSettings(); 117cdf0e10cSrcweir else 118cdf0e10cSrcweir ListBox::DataChanged( rDCEvt ); 119cdf0e10cSrcweir } 120cdf0e10cSrcweir 121cdf0e10cSrcweir // ----------------------------------------------------------------------------- 122cdf0e10cSrcweir 123cdf0e10cSrcweir long GalleryThemeListBox::PreNotify( NotifyEvent& rNEvt ) 124cdf0e10cSrcweir { 125cdf0e10cSrcweir long nDone = 0; 126cdf0e10cSrcweir 127cdf0e10cSrcweir if( rNEvt.GetType() == EVENT_COMMAND ) 128cdf0e10cSrcweir { 129cdf0e10cSrcweir const CommandEvent* pCEvt = rNEvt.GetCommandEvent(); 130cdf0e10cSrcweir 131cdf0e10cSrcweir if( pCEvt && pCEvt->GetCommand() == COMMAND_CONTEXTMENU ) 132cdf0e10cSrcweir static_cast< GalleryBrowser1* >( GetParent() )->ShowContextMenu(); 133cdf0e10cSrcweir } 134cdf0e10cSrcweir else if( rNEvt.GetType() == EVENT_KEYINPUT ) 135cdf0e10cSrcweir { 136cdf0e10cSrcweir const KeyEvent* pKEvt = rNEvt.GetKeyEvent(); 137cdf0e10cSrcweir 138cdf0e10cSrcweir if( pKEvt ) 139cdf0e10cSrcweir nDone = static_cast< GalleryBrowser1* >( GetParent() )->KeyInput( *pKEvt, this ); 140cdf0e10cSrcweir } 141cdf0e10cSrcweir 142cdf0e10cSrcweir return( nDone ? nDone : ListBox::PreNotify( rNEvt ) ); 143cdf0e10cSrcweir } 144cdf0e10cSrcweir 145cdf0e10cSrcweir // ------------------- 146cdf0e10cSrcweir // - GalleryBrowser1 - 147cdf0e10cSrcweir // ------------------- 148cdf0e10cSrcweir DBG_NAME(GalleryBrowser1) 149cdf0e10cSrcweir 150cdf0e10cSrcweir GalleryBrowser1::GalleryBrowser1( GalleryBrowser* pParent, const ResId& rResId, Gallery* pGallery ) : 151cdf0e10cSrcweir Control ( pParent, rResId ), 152cdf0e10cSrcweir maNewTheme ( this, WB_3DLOOK ), 153cdf0e10cSrcweir mpThemes ( new GalleryThemeListBox( this, WB_TABSTOP | WB_3DLOOK | WB_BORDER | WB_HSCROLL | WB_VSCROLL | WB_AUTOHSCROLL | WB_SORT ) ), 154cdf0e10cSrcweir mpGallery ( pGallery ), 155cdf0e10cSrcweir mpExchangeData ( new ExchangeData ), 156cdf0e10cSrcweir mpThemePropsDlgItemSet( NULL ), 157cdf0e10cSrcweir aImgNormal ( GalleryResGetBitmapEx( RID_SVXBMP_THEME_NORMAL ) ), 158cdf0e10cSrcweir aImgDefault ( GalleryResGetBitmapEx( RID_SVXBMP_THEME_DEFAULT ) ), 159cdf0e10cSrcweir aImgReadOnly ( GalleryResGetBitmapEx( RID_SVXBMP_THEME_READONLY ) ), 160cdf0e10cSrcweir aImgImported ( GalleryResGetBitmapEx( RID_SVXBMP_THEME_IMPORTED ) ) 161cdf0e10cSrcweir { 162cdf0e10cSrcweir DBG_CTOR(GalleryBrowser1,NULL); 163cdf0e10cSrcweir 164cdf0e10cSrcweir StartListening( *mpGallery ); 165cdf0e10cSrcweir 166cdf0e10cSrcweir maNewTheme.SetHelpId( HID_GALLERY_NEWTHEME ); 167cdf0e10cSrcweir maNewTheme.SetText( String( GAL_RESID( RID_SVXSTR_GALLERY_CREATETHEME ) ) ); 168cdf0e10cSrcweir maNewTheme.SetClickHdl( LINK( this, GalleryBrowser1, ClickNewThemeHdl ) ); 169cdf0e10cSrcweir 170cdf0e10cSrcweir // disable creation of new themes if a writable directory is not available 171cdf0e10cSrcweir if( mpGallery->GetUserURL().GetProtocol() == INET_PROT_NOT_VALID ) 172cdf0e10cSrcweir maNewTheme.Disable(); 173cdf0e10cSrcweir 174cdf0e10cSrcweir mpThemes->SetHelpId( HID_GALLERY_THEMELIST ); 175cdf0e10cSrcweir mpThemes->SetSelectHdl( LINK( this, GalleryBrowser1, SelectThemeHdl ) ); 176cdf0e10cSrcweir mpThemes->SetAccessibleName(String(SVX_RES( RID_SVXSTR_GALLERYPROPS_GALTHEME ) ) ); 177cdf0e10cSrcweir 178cdf0e10cSrcweir for( sal_uIntPtr i = 0, nCount = mpGallery->GetThemeCount(); i < nCount; i++ ) 179cdf0e10cSrcweir ImplInsertThemeEntry( mpGallery->GetThemeInfo( i ) ); 180cdf0e10cSrcweir 181cdf0e10cSrcweir ImplAdjustControls(); 182cdf0e10cSrcweir maNewTheme.Show( sal_True ); 183cdf0e10cSrcweir mpThemes->Show( sal_True ); 184cdf0e10cSrcweir } 185cdf0e10cSrcweir 186cdf0e10cSrcweir // ----------------------------------------------------------------------------- 187cdf0e10cSrcweir 188cdf0e10cSrcweir GalleryBrowser1::~GalleryBrowser1() 189cdf0e10cSrcweir { 190cdf0e10cSrcweir EndListening( *mpGallery ); 191cdf0e10cSrcweir delete mpThemes; 192cdf0e10cSrcweir mpThemes = NULL; 193cdf0e10cSrcweir delete mpExchangeData; 194cdf0e10cSrcweir mpExchangeData = NULL; 195cdf0e10cSrcweir 196cdf0e10cSrcweir DBG_DTOR(GalleryBrowser1,NULL); 197cdf0e10cSrcweir } 198cdf0e10cSrcweir 199cdf0e10cSrcweir // ----------------------------------------------------------------------------- 200cdf0e10cSrcweir 201cdf0e10cSrcweir sal_uIntPtr GalleryBrowser1::ImplInsertThemeEntry( const GalleryThemeEntry* pEntry ) 202cdf0e10cSrcweir { 203cdf0e10cSrcweir static const sal_Bool bShowHiddenThemes = ( getenv( "GALLERY_SHOW_HIDDEN_THEMES" ) != NULL ); 204cdf0e10cSrcweir 205cdf0e10cSrcweir sal_uIntPtr nRet = LISTBOX_ENTRY_NOTFOUND; 206cdf0e10cSrcweir 207cdf0e10cSrcweir if( pEntry && ( !pEntry->IsHidden() || bShowHiddenThemes ) ) 208cdf0e10cSrcweir { 209cdf0e10cSrcweir const Image* pImage; 210cdf0e10cSrcweir 211cdf0e10cSrcweir if( pEntry->IsImported() ) 212cdf0e10cSrcweir pImage = &aImgImported; 213cdf0e10cSrcweir else if( pEntry->IsReadOnly() ) 214cdf0e10cSrcweir pImage = &aImgReadOnly; 215cdf0e10cSrcweir else if( pEntry->IsDefault() ) 216cdf0e10cSrcweir pImage = &aImgDefault; 217cdf0e10cSrcweir else 218cdf0e10cSrcweir pImage = &aImgNormal; 219cdf0e10cSrcweir 220cdf0e10cSrcweir nRet = mpThemes->InsertEntry( pEntry->GetThemeName(), *pImage ); 221cdf0e10cSrcweir } 222cdf0e10cSrcweir 223cdf0e10cSrcweir return nRet; 224cdf0e10cSrcweir } 225cdf0e10cSrcweir 226cdf0e10cSrcweir // ----------------------------------------------------------------------------- 227cdf0e10cSrcweir 228cdf0e10cSrcweir void GalleryBrowser1::ImplAdjustControls() 229cdf0e10cSrcweir { 230cdf0e10cSrcweir const Size aOutSize( GetOutputSizePixel() ); 231cdf0e10cSrcweir const long nNewThemeHeight = LogicToPixel( Size( 0, 14 ), MAP_APPFONT ).Height(); 232cdf0e10cSrcweir const long nStartY = nNewThemeHeight + 4; 233cdf0e10cSrcweir 234cdf0e10cSrcweir maNewTheme.SetPosSizePixel( Point(), 235cdf0e10cSrcweir Size( aOutSize.Width(), nNewThemeHeight ) ); 236cdf0e10cSrcweir 237cdf0e10cSrcweir mpThemes->SetPosSizePixel( Point( 0, nStartY ), 238cdf0e10cSrcweir Size( aOutSize.Width(), aOutSize.Height() - nStartY ) ); 239cdf0e10cSrcweir } 240cdf0e10cSrcweir 241cdf0e10cSrcweir // ----------------------------------------------------------------------------- 242cdf0e10cSrcweir 243cdf0e10cSrcweir void GalleryBrowser1::ImplFillExchangeData( const GalleryTheme* pThm, ExchangeData& rData ) 244cdf0e10cSrcweir { 245cdf0e10cSrcweir rData.pTheme = (GalleryTheme*) pThm; 246cdf0e10cSrcweir rData.aEditedTitle = pThm->GetName(); 247cdf0e10cSrcweir 248cdf0e10cSrcweir try 249cdf0e10cSrcweir { 250cdf0e10cSrcweir ::ucbhelper::Content aCnt( pThm->GetThmURL().GetMainURL( INetURLObject::NO_DECODE ), uno::Reference< ucb::XCommandEnvironment >() ); 251cdf0e10cSrcweir util::DateTime aDateTimeModified; 252cdf0e10cSrcweir DateTime aDateTime; 253cdf0e10cSrcweir 254cdf0e10cSrcweir aCnt.getPropertyValue( OUString::createFromAscii( "DateModified" ) ) >>= aDateTimeModified; 255cdf0e10cSrcweir ::utl::typeConvert( aDateTimeModified, aDateTime ); 256cdf0e10cSrcweir rData.aThemeChangeDate = aDateTime; 257cdf0e10cSrcweir rData.aThemeChangeTime = aDateTime; 258cdf0e10cSrcweir } 259cdf0e10cSrcweir catch( const ucb::ContentCreationException& ) 260cdf0e10cSrcweir { 261cdf0e10cSrcweir } 262cdf0e10cSrcweir catch( const uno::RuntimeException& ) 263cdf0e10cSrcweir { 264cdf0e10cSrcweir } 265cdf0e10cSrcweir catch( const uno::Exception& ) 266cdf0e10cSrcweir { 267cdf0e10cSrcweir } 268cdf0e10cSrcweir } 269cdf0e10cSrcweir 270cdf0e10cSrcweir // ----------------------------------------------------------------------------- 271cdf0e10cSrcweir 272cdf0e10cSrcweir void GalleryBrowser1::ImplGetExecuteVector(::std::vector< sal_uInt16 >& o_aExec) 273cdf0e10cSrcweir { 274cdf0e10cSrcweir GalleryTheme* pTheme = mpGallery->AcquireTheme( GetSelectedTheme(), *this ); 275cdf0e10cSrcweir 276cdf0e10cSrcweir if( pTheme ) 277cdf0e10cSrcweir { 278cdf0e10cSrcweir sal_Bool bUpdateAllowed, bRenameAllowed, bRemoveAllowed; 279cdf0e10cSrcweir static const sal_Bool bIdDialog = ( getenv( "GALLERY_ENABLE_ID_DIALOG" ) != NULL ); 280cdf0e10cSrcweir 281cdf0e10cSrcweir if( pTheme->IsReadOnly() ) 282cdf0e10cSrcweir bUpdateAllowed = bRenameAllowed = bRemoveAllowed = sal_False; 283cdf0e10cSrcweir else if( pTheme->IsImported() ) 284cdf0e10cSrcweir { 285cdf0e10cSrcweir bUpdateAllowed = sal_False; 286cdf0e10cSrcweir bRenameAllowed = bRemoveAllowed = sal_True; 287cdf0e10cSrcweir } 288cdf0e10cSrcweir else if( pTheme->IsDefault() ) 289cdf0e10cSrcweir { 290cdf0e10cSrcweir bUpdateAllowed = bRenameAllowed = sal_True; 291cdf0e10cSrcweir bRemoveAllowed = sal_False; 292cdf0e10cSrcweir } 293cdf0e10cSrcweir else 294cdf0e10cSrcweir bUpdateAllowed = bRenameAllowed = bRemoveAllowed = sal_True; 295cdf0e10cSrcweir 296cdf0e10cSrcweir if( bUpdateAllowed && pTheme->GetObjectCount() ) 297cdf0e10cSrcweir o_aExec.push_back( MN_ACTUALIZE ); 298cdf0e10cSrcweir 299cdf0e10cSrcweir if( bRenameAllowed ) 300cdf0e10cSrcweir o_aExec.push_back( MN_RENAME ); 301cdf0e10cSrcweir 302cdf0e10cSrcweir if( bRemoveAllowed ) 303cdf0e10cSrcweir o_aExec.push_back( MN_DELETE ); 304cdf0e10cSrcweir 305cdf0e10cSrcweir if( bIdDialog && !pTheme->IsReadOnly() && !pTheme->IsImported() ) 306cdf0e10cSrcweir o_aExec.push_back( MN_ASSIGN_ID ); 307cdf0e10cSrcweir 308cdf0e10cSrcweir o_aExec.push_back( MN_PROPERTIES ); 309cdf0e10cSrcweir 310cdf0e10cSrcweir mpGallery->ReleaseTheme( pTheme, *this ); 311cdf0e10cSrcweir } 312cdf0e10cSrcweir } 313cdf0e10cSrcweir 314cdf0e10cSrcweir // ----------------------------------------------------------------------------- 315cdf0e10cSrcweir 316cdf0e10cSrcweir void GalleryBrowser1::ImplGalleryThemeProperties( const String & rThemeName, bool bCreateNew ) 317cdf0e10cSrcweir { 318cdf0e10cSrcweir DBG_ASSERT(!mpThemePropsDlgItemSet, "mpThemePropsDlgItemSet already set!"); 319cdf0e10cSrcweir mpThemePropsDlgItemSet = new SfxItemSet( SFX_APP()->GetPool() ); 320cdf0e10cSrcweir GalleryTheme* pTheme = mpGallery->AcquireTheme( rThemeName, *this ); 321cdf0e10cSrcweir 322cdf0e10cSrcweir ImplFillExchangeData( pTheme, *mpExchangeData ); 323cdf0e10cSrcweir 324cdf0e10cSrcweir SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create(); 325cdf0e10cSrcweir DBG_ASSERT(pFact, "Got no AbstractDialogFactory!"); 326cdf0e10cSrcweir VclAbstractDialog2* pThemeProps = pFact->CreateGalleryThemePropertiesDialog( NULL, mpExchangeData, mpThemePropsDlgItemSet ); 327cdf0e10cSrcweir DBG_ASSERT(pThemeProps, "Got no GalleryThemePropertiesDialog!"); 328cdf0e10cSrcweir 329cdf0e10cSrcweir if ( bCreateNew ) 330cdf0e10cSrcweir { 331cdf0e10cSrcweir pThemeProps->StartExecuteModal( 332cdf0e10cSrcweir LINK( this, GalleryBrowser1, EndNewThemePropertiesDlgHdl ) ); 333cdf0e10cSrcweir } 334cdf0e10cSrcweir else 335cdf0e10cSrcweir { 336cdf0e10cSrcweir pThemeProps->StartExecuteModal( 337cdf0e10cSrcweir LINK( this, GalleryBrowser1, EndThemePropertiesDlgHdl ) ); 338cdf0e10cSrcweir } 339cdf0e10cSrcweir } 340cdf0e10cSrcweir 341cdf0e10cSrcweir // ----------------------------------------------------------------------------- 342cdf0e10cSrcweir 343cdf0e10cSrcweir void GalleryBrowser1::ImplEndGalleryThemeProperties( VclAbstractDialog2* pDialog, bool bCreateNew ) 344cdf0e10cSrcweir { 345cdf0e10cSrcweir long nRet = pDialog->GetResult(); 346cdf0e10cSrcweir 347cdf0e10cSrcweir if( nRet == RET_OK ) 348cdf0e10cSrcweir { 349cdf0e10cSrcweir String aName( mpExchangeData->pTheme->GetName() ); 350cdf0e10cSrcweir 351cdf0e10cSrcweir if( mpExchangeData->aEditedTitle.Len() && aName != mpExchangeData->aEditedTitle ) 352cdf0e10cSrcweir { 353cdf0e10cSrcweir const String aOldName( aName ); 354cdf0e10cSrcweir String aTitle( mpExchangeData->aEditedTitle ); 355cdf0e10cSrcweir sal_uInt16 nCount = 0; 356cdf0e10cSrcweir 357cdf0e10cSrcweir while( mpGallery->HasTheme( aTitle ) && ( nCount++ < 16000 ) ) 358cdf0e10cSrcweir { 359cdf0e10cSrcweir aTitle = mpExchangeData->aEditedTitle; 360cdf0e10cSrcweir aTitle += ' '; 361cdf0e10cSrcweir aTitle += String::CreateFromInt32( nCount ); 362cdf0e10cSrcweir } 363cdf0e10cSrcweir 364cdf0e10cSrcweir mpGallery->RenameTheme( aOldName, aTitle ); 365cdf0e10cSrcweir } 366cdf0e10cSrcweir 367cdf0e10cSrcweir if ( bCreateNew ) 368cdf0e10cSrcweir { 369cdf0e10cSrcweir mpThemes->SelectEntry( mpExchangeData->pTheme->GetName() ); 370cdf0e10cSrcweir SelectThemeHdl( NULL ); 371cdf0e10cSrcweir } 372cdf0e10cSrcweir } 373cdf0e10cSrcweir 374cdf0e10cSrcweir String aThemeName( mpExchangeData->pTheme->GetName() ); 375cdf0e10cSrcweir mpGallery->ReleaseTheme( mpExchangeData->pTheme, *this ); 376cdf0e10cSrcweir 377cdf0e10cSrcweir if ( bCreateNew && ( nRet != RET_OK ) ) 378cdf0e10cSrcweir { 379cdf0e10cSrcweir mpGallery->RemoveTheme( aThemeName ); 380cdf0e10cSrcweir } 381cdf0e10cSrcweir 382cdf0e10cSrcweir // destroy mpThemeProps asynchronously 383cdf0e10cSrcweir Application::PostUserEvent( LINK( this, GalleryBrowser1, DestroyThemePropertiesDlgHdl ) ); 384cdf0e10cSrcweir } 385cdf0e10cSrcweir 386cdf0e10cSrcweir // ----------------------------------------------------------------------------- 387cdf0e10cSrcweir 388cdf0e10cSrcweir IMPL_LINK( GalleryBrowser1, EndNewThemePropertiesDlgHdl, VclAbstractDialog2*, pDialog ) 389cdf0e10cSrcweir { 390cdf0e10cSrcweir ImplEndGalleryThemeProperties( pDialog, true ); 391cdf0e10cSrcweir return 0L; 392cdf0e10cSrcweir } 393cdf0e10cSrcweir 394cdf0e10cSrcweir // ----------------------------------------------------------------------------- 395cdf0e10cSrcweir 396cdf0e10cSrcweir IMPL_LINK( GalleryBrowser1, EndThemePropertiesDlgHdl, VclAbstractDialog2*, pDialog ) 397cdf0e10cSrcweir { 398cdf0e10cSrcweir ImplEndGalleryThemeProperties( pDialog, false ); 399cdf0e10cSrcweir return 0L; 400cdf0e10cSrcweir } 401cdf0e10cSrcweir 402cdf0e10cSrcweir // ----------------------------------------------------------------------------- 403cdf0e10cSrcweir 404cdf0e10cSrcweir IMPL_LINK( GalleryBrowser1, DestroyThemePropertiesDlgHdl, VclAbstractDialog2*, pDialog ) 405cdf0e10cSrcweir { 406cdf0e10cSrcweir delete pDialog; 407cdf0e10cSrcweir delete mpThemePropsDlgItemSet; 408cdf0e10cSrcweir mpThemePropsDlgItemSet = 0; 409cdf0e10cSrcweir return 0L; 410cdf0e10cSrcweir } 411cdf0e10cSrcweir 412cdf0e10cSrcweir // ----------------------------------------------------------------------------- 413cdf0e10cSrcweir 414cdf0e10cSrcweir void GalleryBrowser1::ImplExecute( sal_uInt16 nId ) 415cdf0e10cSrcweir { 416cdf0e10cSrcweir switch( nId ) 417cdf0e10cSrcweir { 418cdf0e10cSrcweir case( MN_ACTUALIZE ): 419cdf0e10cSrcweir { 420cdf0e10cSrcweir GalleryTheme* pTheme = mpGallery->AcquireTheme( GetSelectedTheme(), *this ); 421cdf0e10cSrcweir //CHINA001 ActualizeProgress aActualizeProgress( this, pTheme ); 422cdf0e10cSrcweir SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create(); 423cdf0e10cSrcweir if(pFact) 424cdf0e10cSrcweir { 425cdf0e10cSrcweir VclAbstractRefreshableDialog* aActualizeProgress = pFact->CreateActualizeProgressDialog( this, pTheme ); 426cdf0e10cSrcweir DBG_ASSERT(aActualizeProgress, "Dialogdiet fail!");//CHINA001 427cdf0e10cSrcweir 428cdf0e10cSrcweir aActualizeProgress->Update(); //CHINA001 aActualizeProgress.Update(); 429cdf0e10cSrcweir aActualizeProgress->Execute(); //CHINA001 aActualizeProgress.Execute(); 430cdf0e10cSrcweir mpGallery->ReleaseTheme( pTheme, *this ); 431cdf0e10cSrcweir delete aActualizeProgress; //add CHINA001 432cdf0e10cSrcweir } 433cdf0e10cSrcweir } 434cdf0e10cSrcweir break; 435cdf0e10cSrcweir 436cdf0e10cSrcweir case( MN_DELETE ): 437cdf0e10cSrcweir { 438cdf0e10cSrcweir if( QueryBox( NULL, WB_YES_NO, String( GAL_RESID( RID_SVXSTR_GALLERY_DELETETHEME ) ) ).Execute() == RET_YES ) 439cdf0e10cSrcweir mpGallery->RemoveTheme( mpThemes->GetSelectEntry() ); 440cdf0e10cSrcweir } 441cdf0e10cSrcweir break; 442cdf0e10cSrcweir 443cdf0e10cSrcweir case( MN_RENAME ): 444cdf0e10cSrcweir { 445cdf0e10cSrcweir GalleryTheme* pTheme = mpGallery->AcquireTheme( GetSelectedTheme(), *this ); 446cdf0e10cSrcweir const String aOldName( pTheme->GetName() ); 447cdf0e10cSrcweir //CHINA001 TitleDialog aDlg( this, aOldName ); 448cdf0e10cSrcweir SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create(); 449cdf0e10cSrcweir DBG_ASSERT(pFact, "Dialogdiet fail!");//CHINA001 450cdf0e10cSrcweir AbstractTitleDialog* aDlg = pFact->CreateTitleDialog( this, aOldName ); 451cdf0e10cSrcweir DBG_ASSERT(aDlg, "Dialogdiet fail!");//CHINA001 452cdf0e10cSrcweir 453cdf0e10cSrcweir if( aDlg->Execute() == RET_OK ) //CHINA001 if( aDlg.Execute() == RET_OK ) 454cdf0e10cSrcweir { 455cdf0e10cSrcweir const String aNewName( aDlg->GetTitle() ); //CHINA001 aDlg.GetTitle() ); 456cdf0e10cSrcweir 457cdf0e10cSrcweir if( aNewName.Len() && ( aNewName != aOldName ) ) 458cdf0e10cSrcweir { 459cdf0e10cSrcweir String aName( aNewName ); 460cdf0e10cSrcweir sal_uInt16 nCount = 0; 461cdf0e10cSrcweir 462cdf0e10cSrcweir while( mpGallery->HasTheme( aName ) && ( nCount++ < 16000 ) ) 463cdf0e10cSrcweir { 464cdf0e10cSrcweir aName = aNewName; 465cdf0e10cSrcweir aName += ' '; 466cdf0e10cSrcweir aName += String::CreateFromInt32( nCount ); 467cdf0e10cSrcweir } 468cdf0e10cSrcweir 469cdf0e10cSrcweir mpGallery->RenameTheme( aOldName, aName ); 470cdf0e10cSrcweir } 471cdf0e10cSrcweir } 472cdf0e10cSrcweir mpGallery->ReleaseTheme( pTheme, *this ); 473cdf0e10cSrcweir delete aDlg; //add CHINA001 474cdf0e10cSrcweir } 475cdf0e10cSrcweir break; 476cdf0e10cSrcweir 477cdf0e10cSrcweir case( MN_ASSIGN_ID ): 478cdf0e10cSrcweir { 479cdf0e10cSrcweir GalleryTheme* pTheme = mpGallery->AcquireTheme( GetSelectedTheme(), *this ); 480cdf0e10cSrcweir 481cdf0e10cSrcweir if( pTheme && !pTheme->IsReadOnly() && !pTheme->IsImported() ) 482cdf0e10cSrcweir { 483cdf0e10cSrcweir //CHINA001 GalleryIdDialog aDlg( this, pTheme ); 484cdf0e10cSrcweir SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create(); 485cdf0e10cSrcweir if(pFact) 486cdf0e10cSrcweir { 487cdf0e10cSrcweir AbstractGalleryIdDialog* aDlg = pFact->CreateGalleryIdDialog( this, pTheme ); 488cdf0e10cSrcweir DBG_ASSERT(aDlg, "Dialogdiet fail!");//CHINA001 489cdf0e10cSrcweir 490cdf0e10cSrcweir if( aDlg->Execute() == RET_OK ) //CHINA001 if( aDlg.Execute() == RET_OK ) 491cdf0e10cSrcweir pTheme->SetId( aDlg->GetId(), sal_True ); //CHINA001 pTheme->SetId( aDlg.GetId(), sal_True ); 492cdf0e10cSrcweir delete aDlg; //add CHINA001 493cdf0e10cSrcweir } 494cdf0e10cSrcweir } 495cdf0e10cSrcweir 496cdf0e10cSrcweir mpGallery->ReleaseTheme( pTheme, *this ); 497cdf0e10cSrcweir } 498cdf0e10cSrcweir break; 499cdf0e10cSrcweir 500cdf0e10cSrcweir case( MN_PROPERTIES ): 501cdf0e10cSrcweir { 502cdf0e10cSrcweir ImplGalleryThemeProperties( GetSelectedTheme(), false ); 503cdf0e10cSrcweir } 504cdf0e10cSrcweir break; 505cdf0e10cSrcweir } 506cdf0e10cSrcweir } 507cdf0e10cSrcweir 508cdf0e10cSrcweir // ----------------------------------------------------------------------------- 509cdf0e10cSrcweir 510cdf0e10cSrcweir void GalleryBrowser1::Resize() 511cdf0e10cSrcweir { 512cdf0e10cSrcweir Control::Resize(); 513cdf0e10cSrcweir ImplAdjustControls(); 514cdf0e10cSrcweir } 515cdf0e10cSrcweir 516cdf0e10cSrcweir // ----------------------------------------------------------------------------- 517cdf0e10cSrcweir 518cdf0e10cSrcweir void GalleryBrowser1::GetFocus() 519cdf0e10cSrcweir { 520cdf0e10cSrcweir Control::GetFocus(); 521cdf0e10cSrcweir if( mpThemes ) 522cdf0e10cSrcweir mpThemes->GrabFocus(); 523cdf0e10cSrcweir } 524cdf0e10cSrcweir 525cdf0e10cSrcweir // ----------------------------------------------------------------------------- 526cdf0e10cSrcweir 527cdf0e10cSrcweir void GalleryBrowser1::Notify( SfxBroadcaster&, const SfxHint& rHint ) 528cdf0e10cSrcweir { 529cdf0e10cSrcweir const GalleryHint& rGalleryHint = (const GalleryHint&) rHint; 530cdf0e10cSrcweir 531cdf0e10cSrcweir switch( rGalleryHint.GetType() ) 532cdf0e10cSrcweir { 533cdf0e10cSrcweir case( GALLERY_HINT_THEME_CREATED ): 534cdf0e10cSrcweir ImplInsertThemeEntry( mpGallery->GetThemeInfo( rGalleryHint.GetThemeName() ) ); 535cdf0e10cSrcweir break; 536cdf0e10cSrcweir 537cdf0e10cSrcweir case( GALLERY_HINT_THEME_RENAMED ): 538cdf0e10cSrcweir { 539cdf0e10cSrcweir const sal_uInt16 nCurSelectPos = mpThemes->GetSelectEntryPos(); 540cdf0e10cSrcweir const sal_uInt16 nRenameEntryPos = mpThemes->GetEntryPos( rGalleryHint.GetThemeName() ); 541cdf0e10cSrcweir 542cdf0e10cSrcweir mpThemes->RemoveEntry( rGalleryHint.GetThemeName() ); 543cdf0e10cSrcweir ImplInsertThemeEntry( mpGallery->GetThemeInfo( rGalleryHint.GetStringData() ) ); 544cdf0e10cSrcweir 545cdf0e10cSrcweir if( nCurSelectPos == nRenameEntryPos ) 546cdf0e10cSrcweir { 547cdf0e10cSrcweir mpThemes->SelectEntry( rGalleryHint.GetStringData() ); 548cdf0e10cSrcweir SelectThemeHdl( NULL ); 549cdf0e10cSrcweir } 550cdf0e10cSrcweir } 551cdf0e10cSrcweir break; 552cdf0e10cSrcweir 553cdf0e10cSrcweir case( GALLERY_HINT_THEME_REMOVED ): 554cdf0e10cSrcweir { 555cdf0e10cSrcweir mpThemes->RemoveEntry( rGalleryHint.GetThemeName() ); 556cdf0e10cSrcweir } 557cdf0e10cSrcweir break; 558cdf0e10cSrcweir 559cdf0e10cSrcweir case( GALLERY_HINT_CLOSE_THEME ): 560cdf0e10cSrcweir { 561cdf0e10cSrcweir const sal_uInt16 nCurSelectPos = mpThemes->GetSelectEntryPos(); 562cdf0e10cSrcweir const sal_uInt16 nCloseEntryPos = mpThemes->GetEntryPos( rGalleryHint.GetThemeName() ); 563cdf0e10cSrcweir 564cdf0e10cSrcweir if( nCurSelectPos == nCloseEntryPos ) 565cdf0e10cSrcweir { 566cdf0e10cSrcweir if( nCurSelectPos < ( mpThemes->GetEntryCount() - 1 ) ) 567cdf0e10cSrcweir mpThemes->SelectEntryPos( nCurSelectPos + 1 ); 568cdf0e10cSrcweir else if( nCurSelectPos ) 569cdf0e10cSrcweir mpThemes->SelectEntryPos( nCurSelectPos - 1 ); 570cdf0e10cSrcweir else 571cdf0e10cSrcweir mpThemes->SetNoSelection(); 572cdf0e10cSrcweir 573cdf0e10cSrcweir SelectThemeHdl( NULL ); 574cdf0e10cSrcweir } 575cdf0e10cSrcweir } 576cdf0e10cSrcweir break; 577cdf0e10cSrcweir 578cdf0e10cSrcweir default: 579cdf0e10cSrcweir break; 580cdf0e10cSrcweir } 581cdf0e10cSrcweir } 582cdf0e10cSrcweir 583cdf0e10cSrcweir // ----------------------------------------------------------------------------- 584cdf0e10cSrcweir 585cdf0e10cSrcweir void GalleryBrowser1::ShowContextMenu() 586cdf0e10cSrcweir { 587cdf0e10cSrcweir Application::PostUserEvent( LINK( this, GalleryBrowser1, ShowContextMenuHdl ), this ); 588cdf0e10cSrcweir } 589cdf0e10cSrcweir 590cdf0e10cSrcweir // ----------------------------------------------------------------------------- 591cdf0e10cSrcweir 592cdf0e10cSrcweir sal_Bool GalleryBrowser1::KeyInput( const KeyEvent& rKEvt, Window* pWindow ) 593cdf0e10cSrcweir { 594cdf0e10cSrcweir sal_Bool bRet = static_cast< GalleryBrowser* >( GetParent() )->KeyInput( rKEvt, pWindow ); 595cdf0e10cSrcweir 596cdf0e10cSrcweir if( !bRet ) 597cdf0e10cSrcweir { 598cdf0e10cSrcweir ::std::vector< sal_uInt16 > aExecVector; 599cdf0e10cSrcweir ImplGetExecuteVector(aExecVector); 600cdf0e10cSrcweir sal_uInt16 nExecuteId = 0; 601cdf0e10cSrcweir sal_Bool bMod1 = rKEvt.GetKeyCode().IsMod1(); 602cdf0e10cSrcweir 603cdf0e10cSrcweir switch( rKEvt.GetKeyCode().GetCode() ) 604cdf0e10cSrcweir { 605cdf0e10cSrcweir case( KEY_INSERT ): 606cdf0e10cSrcweir ClickNewThemeHdl( NULL ); 607cdf0e10cSrcweir break; 608cdf0e10cSrcweir 609cdf0e10cSrcweir case( KEY_I ): 610cdf0e10cSrcweir { 611cdf0e10cSrcweir if( bMod1 ) 612cdf0e10cSrcweir ClickNewThemeHdl( NULL ); 613cdf0e10cSrcweir } 614cdf0e10cSrcweir break; 615cdf0e10cSrcweir 616cdf0e10cSrcweir case( KEY_U ): 617cdf0e10cSrcweir { 618cdf0e10cSrcweir if( bMod1 ) 619cdf0e10cSrcweir nExecuteId = MN_ACTUALIZE; 620cdf0e10cSrcweir } 621cdf0e10cSrcweir break; 622cdf0e10cSrcweir 623cdf0e10cSrcweir case( KEY_DELETE ): 624cdf0e10cSrcweir nExecuteId = MN_DELETE; 625cdf0e10cSrcweir break; 626cdf0e10cSrcweir 627cdf0e10cSrcweir case( KEY_D ): 628cdf0e10cSrcweir { 629cdf0e10cSrcweir if( bMod1 ) 630cdf0e10cSrcweir nExecuteId = MN_DELETE; 631cdf0e10cSrcweir } 632cdf0e10cSrcweir break; 633cdf0e10cSrcweir 634cdf0e10cSrcweir case( KEY_R ): 635cdf0e10cSrcweir { 636cdf0e10cSrcweir if( bMod1 ) 637cdf0e10cSrcweir nExecuteId = MN_RENAME; 638cdf0e10cSrcweir } 639cdf0e10cSrcweir break; 640cdf0e10cSrcweir 641cdf0e10cSrcweir case( KEY_RETURN ): 642cdf0e10cSrcweir { 643cdf0e10cSrcweir if( bMod1 ) 644cdf0e10cSrcweir nExecuteId = MN_PROPERTIES; 645cdf0e10cSrcweir } 646cdf0e10cSrcweir break; 647cdf0e10cSrcweir } 648cdf0e10cSrcweir 649cdf0e10cSrcweir if( nExecuteId && ( ::std::find( aExecVector.begin(), aExecVector.end(), nExecuteId ) != aExecVector.end() ) ) 650cdf0e10cSrcweir { 651cdf0e10cSrcweir ImplExecute( nExecuteId ); 652cdf0e10cSrcweir bRet = sal_True; 653cdf0e10cSrcweir } 654cdf0e10cSrcweir } 655cdf0e10cSrcweir 656cdf0e10cSrcweir return bRet; 657cdf0e10cSrcweir } 658cdf0e10cSrcweir 659cdf0e10cSrcweir // ----------------------------------------------------------------------------- 660cdf0e10cSrcweir 661cdf0e10cSrcweir IMPL_LINK( GalleryBrowser1, ShowContextMenuHdl, void*, EMPTYARG ) 662cdf0e10cSrcweir { 663cdf0e10cSrcweir ::std::vector< sal_uInt16 > aExecVector; 664cdf0e10cSrcweir ImplGetExecuteVector(aExecVector); 665cdf0e10cSrcweir 666cdf0e10cSrcweir if( !aExecVector.empty() ) 667cdf0e10cSrcweir { 668cdf0e10cSrcweir PopupMenu aMenu( GAL_RESID( RID_SVXMN_GALLERY1 ) ); 669cdf0e10cSrcweir 670cdf0e10cSrcweir aMenu.EnableItem( MN_ACTUALIZE, ::std::find( aExecVector.begin(), aExecVector.end(), MN_ACTUALIZE ) != aExecVector.end() ); 671cdf0e10cSrcweir aMenu.EnableItem( MN_RENAME, ::std::find( aExecVector.begin(), aExecVector.end(), MN_RENAME ) != aExecVector.end() ); 672cdf0e10cSrcweir aMenu.EnableItem( MN_DELETE, ::std::find( aExecVector.begin(), aExecVector.end(), MN_DELETE ) != aExecVector.end() ); 673cdf0e10cSrcweir aMenu.EnableItem( MN_ASSIGN_ID, ::std::find( aExecVector.begin(), aExecVector.end(), MN_ASSIGN_ID ) != aExecVector.end() ); 674cdf0e10cSrcweir aMenu.EnableItem( MN_PROPERTIES, ::std::find( aExecVector.begin(), aExecVector.end(), MN_PROPERTIES ) != aExecVector.end() ); 675cdf0e10cSrcweir aMenu.SetSelectHdl( LINK( this, GalleryBrowser1, PopupMenuHdl ) ); 676cdf0e10cSrcweir aMenu.RemoveDisabledEntries(); 677cdf0e10cSrcweir 678cdf0e10cSrcweir const Rectangle aThemesRect( mpThemes->GetPosPixel(), mpThemes->GetOutputSizePixel() ); 679cdf0e10cSrcweir Point aSelPos( mpThemes->GetBoundingRectangle( mpThemes->GetSelectEntryPos() ).Center() ); 680cdf0e10cSrcweir 681cdf0e10cSrcweir aSelPos.X() = Max( Min( aSelPos.X(), aThemesRect.Right() ), aThemesRect.Left() ); 682cdf0e10cSrcweir aSelPos.Y() = Max( Min( aSelPos.Y(), aThemesRect.Bottom() ), aThemesRect.Top() ); 683cdf0e10cSrcweir 684cdf0e10cSrcweir aMenu.Execute( this, aSelPos ); 685cdf0e10cSrcweir } 686cdf0e10cSrcweir 687cdf0e10cSrcweir return 0L; 688cdf0e10cSrcweir } 689cdf0e10cSrcweir 690cdf0e10cSrcweir // ----------------------------------------------------------------------------- 691cdf0e10cSrcweir 692cdf0e10cSrcweir IMPL_LINK( GalleryBrowser1, PopupMenuHdl, Menu*, pMenu ) 693cdf0e10cSrcweir { 694cdf0e10cSrcweir ImplExecute( pMenu->GetCurItemId() ); 695cdf0e10cSrcweir return 0L; 696cdf0e10cSrcweir } 697cdf0e10cSrcweir 698cdf0e10cSrcweir // ----------------------------------------------------------------------------- 699cdf0e10cSrcweir 700cdf0e10cSrcweir IMPL_LINK( GalleryBrowser1, SelectThemeHdl, void*, EMPTYARG ) 701cdf0e10cSrcweir { 702cdf0e10cSrcweir ( (GalleryBrowser*) GetParent() )->ThemeSelectionHasChanged(); 703cdf0e10cSrcweir return 0L; 704cdf0e10cSrcweir } 705cdf0e10cSrcweir 706cdf0e10cSrcweir // ----------------------------------------------------------------------------- 707cdf0e10cSrcweir 708cdf0e10cSrcweir IMPL_LINK( GalleryBrowser1, ClickNewThemeHdl, void*, EMPTYARG ) 709cdf0e10cSrcweir { 710cdf0e10cSrcweir String aNewTheme( GAL_RESID( RID_SVXSTR_GALLERY_NEWTHEME ) ); 711cdf0e10cSrcweir String aName( aNewTheme ); 712cdf0e10cSrcweir sal_uIntPtr nCount = 0; 713cdf0e10cSrcweir 714cdf0e10cSrcweir while( mpGallery->HasTheme( aName ) && ( nCount++ < 16000 ) ) 715cdf0e10cSrcweir { 716cdf0e10cSrcweir aName = aNewTheme; 717cdf0e10cSrcweir aName += ' '; 718cdf0e10cSrcweir aName += String::CreateFromInt32( nCount ); 719cdf0e10cSrcweir } 720cdf0e10cSrcweir 721cdf0e10cSrcweir if( !mpGallery->HasTheme( aName ) && mpGallery->CreateTheme( aName ) ) 722cdf0e10cSrcweir { 723cdf0e10cSrcweir ImplGalleryThemeProperties( aName, true ); 724cdf0e10cSrcweir } 725cdf0e10cSrcweir 726cdf0e10cSrcweir return 0L; 727cdf0e10cSrcweir } 728cdf0e10cSrcweir 729