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