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