xref: /aoo41x/main/svx/source/gallery2/galbrws1.cxx (revision 02c50d82)
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 // -----------------
DBG_NAME(GalleryButton)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 
~GalleryButton()67 GalleryButton::~GalleryButton()
68 {
69 
70     DBG_DTOR(GalleryButton,NULL);
71 }
72 
73 // -----------------------------------------------------------------------------
74 
KeyInput(const KeyEvent & rKEvt)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 // -----------------------
DBG_NAME(GalleryThemeListBox)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 
~GalleryThemeListBox()96 GalleryThemeListBox::~GalleryThemeListBox()
97 {
98 
99     DBG_DTOR(GalleryThemeListBox,NULL);
100 }
101 
102 // ------------------------------------------------------------------------
103 
InitSettings()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 
DataChanged(const DataChangedEvent & rDCEvt)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 
PreNotify(NotifyEvent & rNEvt)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 // -------------------
DBG_NAME(GalleryBrowser1)148 DBG_NAME(GalleryBrowser1)
149 
150 GalleryBrowser1::GalleryBrowser1(
151     Window* pParent,
152     const ResId& rResId,
153     Gallery* pGallery,
154     const ::boost::function<sal_Bool(const KeyEvent&,Window*)>& rKeyInputHandler,
155     const ::boost::function<void(void)>& rThemeSlectionHandler)
156     :
157     Control               ( pParent, rResId ),
158     maNewTheme            ( this, WB_3DLOOK ),
159     mpThemes              ( new GalleryThemeListBox( this, WB_TABSTOP | WB_3DLOOK | WB_BORDER | WB_HSCROLL | WB_VSCROLL | WB_AUTOHSCROLL | WB_SORT ) ),
160     mpGallery             ( pGallery ),
161     mpExchangeData        ( new ExchangeData ),
162     mpThemePropsDlgItemSet( NULL ),
163     aImgNormal            ( GalleryResGetBitmapEx( RID_SVXBMP_THEME_NORMAL ) ),
164     aImgDefault           ( GalleryResGetBitmapEx( RID_SVXBMP_THEME_DEFAULT ) ),
165     aImgReadOnly          ( GalleryResGetBitmapEx( RID_SVXBMP_THEME_READONLY ) ),
166     aImgImported          ( GalleryResGetBitmapEx( RID_SVXBMP_THEME_IMPORTED ) ),
167     maKeyInputHandler(rKeyInputHandler),
168     maThemeSlectionHandler(rThemeSlectionHandler)
169 {
170     DBG_CTOR(GalleryBrowser1,NULL);
171 
172 	StartListening( *mpGallery );
173 
174 	maNewTheme.SetHelpId( HID_GALLERY_NEWTHEME );
175 	maNewTheme.SetText( String( GAL_RESID( RID_SVXSTR_GALLERY_CREATETHEME ) ) );
176 	maNewTheme.SetClickHdl( LINK( this, GalleryBrowser1, ClickNewThemeHdl ) );
177 
178 	// disable creation of new themes if a writable directory is not available
179 	if( mpGallery->GetUserURL().GetProtocol() == INET_PROT_NOT_VALID )
180 	    maNewTheme.Disable();
181 
182 	mpThemes->SetHelpId( HID_GALLERY_THEMELIST );
183 	mpThemes->SetSelectHdl( LINK( this, GalleryBrowser1, SelectThemeHdl ) );
184 	mpThemes->SetAccessibleName(String(SVX_RES( RID_SVXSTR_GALLERYPROPS_GALTHEME ) ) );
185 
186 	for( sal_uIntPtr i = 0, nCount = mpGallery->GetThemeCount(); i < nCount; i++ )
187 		ImplInsertThemeEntry( mpGallery->GetThemeInfo( i ) );
188 
189 	ImplAdjustControls();
190 	maNewTheme.Show( sal_True );
191 	mpThemes->Show( sal_True );
192 }
193 
194 // -----------------------------------------------------------------------------
195 
~GalleryBrowser1()196 GalleryBrowser1::~GalleryBrowser1()
197 {
198 	EndListening( *mpGallery );
199 	delete mpThemes;
200 	mpThemes = NULL;
201     delete mpExchangeData;
202     mpExchangeData = NULL;
203 
204     DBG_DTOR(GalleryBrowser1,NULL);
205 }
206 
207 // -----------------------------------------------------------------------------
208 
ImplInsertThemeEntry(const GalleryThemeEntry * pEntry)209 sal_uIntPtr GalleryBrowser1::ImplInsertThemeEntry( const GalleryThemeEntry* pEntry )
210 {
211 	static const sal_Bool bShowHiddenThemes = ( getenv( "GALLERY_SHOW_HIDDEN_THEMES" ) != NULL );
212 
213 	sal_uIntPtr nRet = LISTBOX_ENTRY_NOTFOUND;
214 
215 	if( pEntry && ( !pEntry->IsHidden() || bShowHiddenThemes ) )
216 	{
217 		const Image* pImage;
218 
219 		if( pEntry->IsImported() )
220 			pImage = &aImgImported;
221 		else if( pEntry->IsReadOnly() )
222 			pImage = &aImgReadOnly;
223 		else if( pEntry->IsDefault() )
224 			pImage = &aImgDefault;
225 		else
226 			pImage = &aImgNormal;
227 
228 		nRet = mpThemes->InsertEntry( pEntry->GetThemeName(), *pImage );
229 	}
230 
231 	return nRet;
232 }
233 
234 // -----------------------------------------------------------------------------
235 
ImplAdjustControls()236 void GalleryBrowser1::ImplAdjustControls()
237 {
238 	const Size	aOutSize( GetOutputSizePixel() );
239 	const long	nNewThemeHeight = LogicToPixel( Size( 0, 14 ), MAP_APPFONT ).Height();
240     const long  nStartY = nNewThemeHeight + 4;
241 
242 	maNewTheme.SetPosSizePixel( Point(),
243 								Size( aOutSize.Width(), nNewThemeHeight ) );
244 
245 	mpThemes->SetPosSizePixel( Point( 0, nStartY ),
246 							   Size( aOutSize.Width(), aOutSize.Height() - nStartY ) );
247 }
248 
249 // -----------------------------------------------------------------------------
250 
ImplFillExchangeData(const GalleryTheme * pThm,ExchangeData & rData)251 void GalleryBrowser1::ImplFillExchangeData( const GalleryTheme* pThm, ExchangeData& rData )
252 {
253 	rData.pTheme = (GalleryTheme*) pThm;
254 	rData.aEditedTitle = pThm->GetName();
255 
256 	try
257 	{
258 		::ucbhelper::Content aCnt( pThm->GetThmURL().GetMainURL( INetURLObject::NO_DECODE ), uno::Reference< ucb::XCommandEnvironment >() );
259 		util::DateTime	aDateTimeModified;
260 		DateTime		aDateTime;
261 
262 		aCnt.getPropertyValue( OUString::createFromAscii( "DateModified" ) ) >>= aDateTimeModified;
263 		::utl::typeConvert( aDateTimeModified, aDateTime );
264 		rData.aThemeChangeDate = aDateTime;
265 		rData.aThemeChangeTime = aDateTime;
266 	}
267 	catch( const ucb::ContentCreationException& )
268 	{
269 	}
270 	catch( const uno::RuntimeException& )
271 	{
272 	}
273 	catch( const uno::Exception& )
274 	{
275 	}
276 }
277 
278 // -----------------------------------------------------------------------------
279 
ImplGetExecuteVector(::std::vector<sal_uInt16> & o_aExec)280 void GalleryBrowser1::ImplGetExecuteVector(::std::vector< sal_uInt16 >& o_aExec)
281 {
282 	GalleryTheme*           pTheme = mpGallery->AcquireTheme( GetSelectedTheme(), *this );
283 
284 	if( pTheme )
285 	{
286 		sal_Bool                bUpdateAllowed, bRenameAllowed, bRemoveAllowed;
287 		static const sal_Bool	bIdDialog = ( getenv( "GALLERY_ENABLE_ID_DIALOG" ) != NULL );
288 
289 		if( pTheme->IsReadOnly() )
290 			bUpdateAllowed = bRenameAllowed = bRemoveAllowed = sal_False;
291 		else if( pTheme->IsImported() )
292 		{
293 			bUpdateAllowed = sal_False;
294 			bRenameAllowed = bRemoveAllowed = sal_True;
295 		}
296 		else if( pTheme->IsDefault() )
297 		{
298 			bUpdateAllowed = bRenameAllowed = sal_True;
299 			bRemoveAllowed = sal_False;
300 		}
301 		else
302 			bUpdateAllowed = bRenameAllowed = bRemoveAllowed = sal_True;
303 
304         if( bUpdateAllowed && pTheme->GetObjectCount() )
305             o_aExec.push_back( MN_ACTUALIZE );
306 
307         if( bRenameAllowed )
308             o_aExec.push_back( MN_RENAME );
309 
310         if( bRemoveAllowed )
311             o_aExec.push_back( MN_DELETE );
312 
313         if( bIdDialog && !pTheme->IsReadOnly() && !pTheme->IsImported() )
314             o_aExec.push_back( MN_ASSIGN_ID );
315 
316         o_aExec.push_back( MN_PROPERTIES );
317 
318 		mpGallery->ReleaseTheme( pTheme, *this );
319     }
320 }
321 
322 // -----------------------------------------------------------------------------
323 
ImplGalleryThemeProperties(const String & rThemeName,bool bCreateNew)324 void GalleryBrowser1::ImplGalleryThemeProperties( const String & rThemeName, bool bCreateNew )
325 {
326     DBG_ASSERT(!mpThemePropsDlgItemSet, "mpThemePropsDlgItemSet already set!");
327     mpThemePropsDlgItemSet = new SfxItemSet( SFX_APP()->GetPool() );
328     GalleryTheme*   pTheme = mpGallery->AcquireTheme( rThemeName, *this );
329 
330     ImplFillExchangeData( pTheme, *mpExchangeData );
331 
332     SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
333     DBG_ASSERT(pFact, "Got no AbstractDialogFactory!");
334     VclAbstractDialog2* pThemeProps = pFact->CreateGalleryThemePropertiesDialog( NULL, mpExchangeData, mpThemePropsDlgItemSet );
335     DBG_ASSERT(pThemeProps, "Got no GalleryThemePropertiesDialog!");
336 
337     if ( bCreateNew )
338     {
339         pThemeProps->StartExecuteModal(
340             LINK( this, GalleryBrowser1, EndNewThemePropertiesDlgHdl ) );
341     }
342     else
343     {
344         pThemeProps->StartExecuteModal(
345             LINK( this, GalleryBrowser1, EndThemePropertiesDlgHdl ) );
346     }
347 }
348 
349 // -----------------------------------------------------------------------------
350 
ImplEndGalleryThemeProperties(VclAbstractDialog2 * pDialog,bool bCreateNew)351 void GalleryBrowser1::ImplEndGalleryThemeProperties( VclAbstractDialog2* pDialog, bool bCreateNew )
352 {
353     long nRet = pDialog->GetResult();
354 
355     if( nRet == RET_OK )
356     {
357         String aName( mpExchangeData->pTheme->GetName() );
358 
359         if( mpExchangeData->aEditedTitle.Len() && aName != mpExchangeData->aEditedTitle )
360         {
361             const String    aOldName( aName );
362             String          aTitle( mpExchangeData->aEditedTitle );
363             sal_uInt16          nCount = 0;
364 
365             while( mpGallery->HasTheme( aTitle ) && ( nCount++ < 16000 ) )
366             {
367                 aTitle = mpExchangeData->aEditedTitle;
368                 aTitle += ' ';
369                 aTitle += String::CreateFromInt32( nCount );
370             }
371 
372             mpGallery->RenameTheme( aOldName, aTitle );
373         }
374 
375         if ( bCreateNew )
376         {
377             mpThemes->SelectEntry( mpExchangeData->pTheme->GetName() );
378             SelectThemeHdl( NULL );
379         }
380     }
381 
382     String aThemeName( mpExchangeData->pTheme->GetName() );
383     mpGallery->ReleaseTheme( mpExchangeData->pTheme, *this );
384 
385     if ( bCreateNew && ( nRet != RET_OK ) )
386     {
387         mpGallery->RemoveTheme( aThemeName );
388     }
389 
390     // destroy mpThemeProps asynchronously
391     Application::PostUserEvent( LINK( this, GalleryBrowser1, DestroyThemePropertiesDlgHdl ) );
392 }
393 
394 // -----------------------------------------------------------------------------
395 
IMPL_LINK(GalleryBrowser1,EndNewThemePropertiesDlgHdl,VclAbstractDialog2 *,pDialog)396 IMPL_LINK( GalleryBrowser1, EndNewThemePropertiesDlgHdl, VclAbstractDialog2*, pDialog )
397 {
398     ImplEndGalleryThemeProperties( pDialog, true );
399     return 0L;
400 }
401 
402 // -----------------------------------------------------------------------------
403 
IMPL_LINK(GalleryBrowser1,EndThemePropertiesDlgHdl,VclAbstractDialog2 *,pDialog)404 IMPL_LINK( GalleryBrowser1, EndThemePropertiesDlgHdl, VclAbstractDialog2*, pDialog )
405 {
406     ImplEndGalleryThemeProperties( pDialog, false );
407     return 0L;
408 }
409 
410 // -----------------------------------------------------------------------------
411 
IMPL_LINK(GalleryBrowser1,DestroyThemePropertiesDlgHdl,VclAbstractDialog2 *,pDialog)412 IMPL_LINK( GalleryBrowser1, DestroyThemePropertiesDlgHdl, VclAbstractDialog2*, pDialog )
413 {
414     delete pDialog;
415     delete mpThemePropsDlgItemSet;
416     mpThemePropsDlgItemSet = 0;
417     return 0L;
418 }
419 
420 // -----------------------------------------------------------------------------
421 
ImplExecute(sal_uInt16 nId)422 void GalleryBrowser1::ImplExecute( sal_uInt16 nId )
423 {
424 	switch( nId )
425 	{
426 		case( MN_ACTUALIZE ):
427 		{
428 			GalleryTheme*		pTheme = mpGallery->AcquireTheme( GetSelectedTheme(), *this );
429 			//CHINA001 ActualizeProgress	aActualizeProgress( this, pTheme );
430 			SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
431 			if(pFact)
432 			{
433 				VclAbstractRefreshableDialog* aActualizeProgress = pFact->CreateActualizeProgressDialog( this, pTheme );
434 				DBG_ASSERT(aActualizeProgress, "Dialogdiet fail!");//CHINA001
435 
436 				aActualizeProgress->Update();  //CHINA001 aActualizeProgress.Update();
437 				aActualizeProgress->Execute(); //CHINA001 aActualizeProgress.Execute();
438 				mpGallery->ReleaseTheme( pTheme, *this );
439 				delete aActualizeProgress;		//add CHINA001
440 			}
441 		}
442 		break;
443 
444 		case( MN_DELETE  ):
445 		{
446 			if( QueryBox( NULL, WB_YES_NO, String( GAL_RESID( RID_SVXSTR_GALLERY_DELETETHEME ) ) ).Execute() == RET_YES )
447 				mpGallery->RemoveTheme( mpThemes->GetSelectEntry() );
448 		}
449 		break;
450 
451 		case( MN_RENAME ):
452 		{
453 			GalleryTheme*	pTheme = mpGallery->AcquireTheme( GetSelectedTheme(), *this );
454 			const String	aOldName( pTheme->GetName() );
455 			//CHINA001 TitleDialog		aDlg( this, aOldName );
456 			SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
457 			DBG_ASSERT(pFact, "Dialogdiet fail!");//CHINA001
458 			AbstractTitleDialog* aDlg = pFact->CreateTitleDialog( this, aOldName );
459 			DBG_ASSERT(aDlg, "Dialogdiet fail!");//CHINA001
460 
461 			if( aDlg->Execute() == RET_OK ) //CHINA001 if( aDlg.Execute() == RET_OK )
462 			{
463 				const String aNewName( aDlg->GetTitle() ); //CHINA001 aDlg.GetTitle() );
464 
465 				if( aNewName.Len() && ( aNewName != aOldName ) )
466 				{
467 					String	aName( aNewName );
468 					sal_uInt16	nCount = 0;
469 
470 					while( mpGallery->HasTheme( aName ) && ( nCount++ < 16000 ) )
471 					{
472 						aName = aNewName;
473 						aName += ' ';
474 						aName += String::CreateFromInt32( nCount );
475 					}
476 
477 					mpGallery->RenameTheme( aOldName, aName );
478 				}
479 			}
480 			mpGallery->ReleaseTheme( pTheme, *this );
481 			delete aDlg; //add CHINA001
482 		}
483 		break;
484 
485 		case( MN_ASSIGN_ID ):
486 		{
487 			GalleryTheme* pTheme = mpGallery->AcquireTheme( GetSelectedTheme(), *this );
488 
489 			if( pTheme && !pTheme->IsReadOnly() && !pTheme->IsImported() )
490 			{
491 				//CHINA001 GalleryIdDialog aDlg( this, pTheme );
492 				SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
493 				if(pFact)
494 				{
495 					AbstractGalleryIdDialog* aDlg = pFact->CreateGalleryIdDialog( this, pTheme );
496 					DBG_ASSERT(aDlg, "Dialogdiet fail!");//CHINA001
497 
498 					if( aDlg->Execute() == RET_OK ) //CHINA001 if( aDlg.Execute() == RET_OK )
499 						pTheme->SetId( aDlg->GetId(), sal_True ); //CHINA001 pTheme->SetId( aDlg.GetId(), sal_True );
500 					delete aDlg; //add CHINA001
501 				}
502 			}
503 
504 			mpGallery->ReleaseTheme( pTheme, *this );
505 		}
506 		break;
507 
508 		case( MN_PROPERTIES ):
509 		{
510             ImplGalleryThemeProperties( GetSelectedTheme(), false );
511 		}
512 		break;
513 	}
514 }
515 
516 // -----------------------------------------------------------------------------
517 
Resize()518 void GalleryBrowser1::Resize()
519 {
520 	Control::Resize();
521 	ImplAdjustControls();
522 }
523 
524 // -----------------------------------------------------------------------------
525 
GetFocus()526 void GalleryBrowser1::GetFocus()
527 {
528 	Control::GetFocus();
529 	if( mpThemes )
530 		mpThemes->GrabFocus();
531 }
532 
533 // -----------------------------------------------------------------------------
534 
Notify(SfxBroadcaster &,const SfxHint & rHint)535 void GalleryBrowser1::Notify( SfxBroadcaster&, const SfxHint& rHint )
536 {
537 	const GalleryHint& rGalleryHint = (const GalleryHint&) rHint;
538 
539 	switch( rGalleryHint.GetType() )
540 	{
541 		case( GALLERY_HINT_THEME_CREATED ):
542 			ImplInsertThemeEntry( mpGallery->GetThemeInfo( rGalleryHint.GetThemeName() ) );
543 		break;
544 
545 		case( GALLERY_HINT_THEME_RENAMED ):
546 		{
547 			const sal_uInt16 nCurSelectPos = mpThemes->GetSelectEntryPos();
548 			const sal_uInt16 nRenameEntryPos = mpThemes->GetEntryPos( rGalleryHint.GetThemeName() );
549 
550 			mpThemes->RemoveEntry( rGalleryHint.GetThemeName() );
551 			ImplInsertThemeEntry( mpGallery->GetThemeInfo( rGalleryHint.GetStringData() ) );
552 
553 			if( nCurSelectPos == nRenameEntryPos )
554 			{
555 				mpThemes->SelectEntry( rGalleryHint.GetStringData() );
556 				SelectThemeHdl( NULL );
557 			}
558 		}
559 		break;
560 
561 		case( GALLERY_HINT_THEME_REMOVED ):
562 		{
563 			mpThemes->RemoveEntry( rGalleryHint.GetThemeName() );
564 		}
565 		break;
566 
567 		case( GALLERY_HINT_CLOSE_THEME ):
568 		{
569 			const sal_uInt16 nCurSelectPos = mpThemes->GetSelectEntryPos();
570 			const sal_uInt16 nCloseEntryPos = mpThemes->GetEntryPos( rGalleryHint.GetThemeName() );
571 
572 			if( nCurSelectPos == nCloseEntryPos )
573 			{
574 				if( nCurSelectPos < ( mpThemes->GetEntryCount() - 1 ) )
575 					mpThemes->SelectEntryPos( nCurSelectPos + 1 );
576 				else if( nCurSelectPos )
577 					mpThemes->SelectEntryPos( nCurSelectPos - 1 );
578 				else
579 					mpThemes->SetNoSelection();
580 
581 				SelectThemeHdl( NULL );
582 			}
583 		}
584 		break;
585 
586 		default:
587 		break;
588 	}
589 }
590 
591 // -----------------------------------------------------------------------------
592 
ShowContextMenu()593 void GalleryBrowser1::ShowContextMenu()
594 {
595 	Application::PostUserEvent( LINK( this, GalleryBrowser1, ShowContextMenuHdl ), this );
596 }
597 
598 // -----------------------------------------------------------------------------
599 
KeyInput(const KeyEvent & rKEvt,Window * pWindow)600 sal_Bool GalleryBrowser1::KeyInput( const KeyEvent& rKEvt, Window* pWindow )
601 {
602     sal_Bool bRet (sal_False);
603     if (maKeyInputHandler)
604         bRet = maKeyInputHandler(rKEvt, pWindow);
605 
606     if( !bRet )
607     {
608         ::std::vector< sal_uInt16 > aExecVector;
609         ImplGetExecuteVector(aExecVector);
610         sal_uInt16                  nExecuteId = 0;
611         sal_Bool                    bMod1 = rKEvt.GetKeyCode().IsMod1();
612 
613         switch( rKEvt.GetKeyCode().GetCode() )
614         {
615             case( KEY_INSERT ):
616                 ClickNewThemeHdl( NULL );
617             break;
618 
619             case( KEY_I ):
620             {
621                 if( bMod1 )
622                    ClickNewThemeHdl( NULL );
623             }
624             break;
625 
626             case( KEY_U ):
627             {
628                 if( bMod1 )
629                     nExecuteId = MN_ACTUALIZE;
630             }
631             break;
632 
633             case( KEY_DELETE ):
634                 nExecuteId = MN_DELETE;
635             break;
636 
637             case( KEY_D ):
638             {
639                 if( bMod1 )
640                     nExecuteId = MN_DELETE;
641             }
642             break;
643 
644             case( KEY_R ):
645             {
646                 if( bMod1 )
647                     nExecuteId = MN_RENAME;
648             }
649             break;
650 
651             case( KEY_RETURN ):
652             {
653                 if( bMod1 )
654                     nExecuteId = MN_PROPERTIES;
655             }
656             break;
657         }
658 
659         if( nExecuteId && ( ::std::find( aExecVector.begin(), aExecVector.end(), nExecuteId ) != aExecVector.end() ) )
660         {
661             ImplExecute( nExecuteId );
662             bRet = sal_True;
663         }
664     }
665 
666     return bRet;
667 }
668 
669 // -----------------------------------------------------------------------------
670 
IMPL_LINK(GalleryBrowser1,ShowContextMenuHdl,void *,EMPTYARG)671 IMPL_LINK( GalleryBrowser1, ShowContextMenuHdl, void*, EMPTYARG )
672 {
673     ::std::vector< sal_uInt16 > aExecVector;
674     ImplGetExecuteVector(aExecVector);
675 
676     if( !aExecVector.empty() )
677     {
678 		PopupMenu aMenu( GAL_RESID( RID_SVXMN_GALLERY1 ) );
679 
680 		aMenu.EnableItem( MN_ACTUALIZE, ::std::find( aExecVector.begin(), aExecVector.end(), MN_ACTUALIZE ) != aExecVector.end() );
681 		aMenu.EnableItem( MN_RENAME, ::std::find( aExecVector.begin(), aExecVector.end(), MN_RENAME ) != aExecVector.end() );
682 		aMenu.EnableItem( MN_DELETE, ::std::find( aExecVector.begin(), aExecVector.end(), MN_DELETE ) != aExecVector.end() );
683 		aMenu.EnableItem( MN_ASSIGN_ID, ::std::find( aExecVector.begin(), aExecVector.end(), MN_ASSIGN_ID ) != aExecVector.end() );
684 		aMenu.EnableItem( MN_PROPERTIES, ::std::find( aExecVector.begin(), aExecVector.end(), MN_PROPERTIES ) != aExecVector.end() );
685 		aMenu.SetSelectHdl( LINK( this, GalleryBrowser1, PopupMenuHdl ) );
686 		aMenu.RemoveDisabledEntries();
687 
688 		const Rectangle aThemesRect( mpThemes->GetPosPixel(), mpThemes->GetOutputSizePixel() );
689 		Point			aSelPos( mpThemes->GetBoundingRectangle( mpThemes->GetSelectEntryPos() ).Center() );
690 
691 		aSelPos.X() = Max( Min( aSelPos.X(), aThemesRect.Right() ), aThemesRect.Left() );
692 		aSelPos.Y() = Max( Min( aSelPos.Y(), aThemesRect.Bottom() ), aThemesRect.Top() );
693 
694 		aMenu.Execute( this, aSelPos );
695 	}
696 
697 	return 0L;
698 }
699 
700 // -----------------------------------------------------------------------------
701 
IMPL_LINK(GalleryBrowser1,PopupMenuHdl,Menu *,pMenu)702 IMPL_LINK( GalleryBrowser1, PopupMenuHdl, Menu*, pMenu )
703 {
704     ImplExecute( pMenu->GetCurItemId() );
705     return 0L;
706 }
707 
708 // -----------------------------------------------------------------------------
709 
IMPL_LINK(GalleryBrowser1,SelectThemeHdl,void *,EMPTYARG)710 IMPL_LINK( GalleryBrowser1, SelectThemeHdl, void*, EMPTYARG )
711 {
712     if (maThemeSlectionHandler)
713         maThemeSlectionHandler();
714 	return 0L;
715 }
716 
717 // -----------------------------------------------------------------------------
718 
IMPL_LINK(GalleryBrowser1,ClickNewThemeHdl,void *,EMPTYARG)719 IMPL_LINK( GalleryBrowser1, ClickNewThemeHdl, void*, EMPTYARG )
720 {
721 	String	aNewTheme( GAL_RESID( RID_SVXSTR_GALLERY_NEWTHEME ) );
722 	String	aName( aNewTheme );
723 	sal_uIntPtr	nCount = 0;
724 
725 	while( mpGallery->HasTheme( aName ) && ( nCount++ < 16000 ) )
726 	{
727 		aName = aNewTheme;
728 		aName += ' ';
729 		aName += String::CreateFromInt32( nCount );
730 	}
731 
732 	if( !mpGallery->HasTheme( aName ) && mpGallery->CreateTheme( aName ) )
733 	{
734         ImplGalleryThemeProperties( aName, true );
735 	}
736 
737 	return 0L;
738 }
739 
740