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