xref: /aoo42x/main/cui/source/dialogs/cuigaldlg.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_cui.hxx"
30 
31 #include <algorithm>
32 #include <ucbhelper/content.hxx>
33 #include <vos/mutex.hxx>
34 #include <vcl/svapp.hxx>
35 #include <vcl/msgbox.hxx>
36 #include <avmedia/mediawindow.hxx>
37 #include <unotools/pathoptions.hxx>
38 #include <sfx2/opengrf.hxx>
39 #include <svtools/filter.hxx>
40 #include <svx/gallery1.hxx>
41 #include <svx/galtheme.hxx>
42 #include "cuigaldlg.hxx"
43 #include "helpid.hrc"
44 #include <unotools/syslocale.hxx>
45 #include <cppuhelper/implbase1.hxx>
46 #include <com/sun/star/uno/Reference.hxx>
47 #include <com/sun/star/lang/XInitialization.hpp>
48 #include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp>
49 #include <comphelper/processfactory.hxx>
50 #include <com/sun/star/sdbc/XResultSet.hpp>
51 #include <com/sun/star/sdbc/XRow.hpp>
52 #include <com/sun/star/ucb/XContentAccess.hpp>
53 #include <com/sun/star/ui/dialogs/XAsynchronousExecutableDialog.hpp>
54 #include <sfx2/sfxuno.hxx>
55 #include "dialmgr.hxx"
56 #include "gallery.hrc"
57 #include <svx/dialogs.hrc>
58 #include <svx/dialmgr.hxx>
59 
60 
61 // --------------
62 // - Namespaces -
63 // --------------
64 
65 using namespace ::ucbhelper;
66 using namespace ::rtl;
67 using namespace ::cppu;
68 using namespace ::com::sun::star::lang;
69 using namespace ::com::sun::star::sdbc;
70 using namespace ::com::sun::star::ucb;
71 using namespace ::com::sun::star::ui::dialogs;
72 using namespace ::com::sun::star::uno;
73 
74 
75 // -----------
76 // - Defines -
77 // -----------
78 
79 #define MAXPATH 1024
80 
81 // ----------------
82 // - SearchThread -
83 // ----------------
84 
85 SearchThread::SearchThread( SearchProgress* pProgess,
86 							TPGalleryThemeProperties* pBrowser,
87 							const INetURLObject& rStartURL ) :
88 		mpProgress	( pProgess ),
89 		mpBrowser	( pBrowser ),
90         maStartURL  ( rStartURL )
91 {
92 }
93 
94 // ------------------------------------------------------------------------
95 
96 SearchThread::~SearchThread()
97 {
98 }
99 
100 // ------------------------------------------------------------------------
101 
102 void SAL_CALL SearchThread::run()
103 {
104 	const String aFileType( mpBrowser->aCbbFileType.GetText() );
105 
106 	if( aFileType.Len() )
107 	{
108 	    const sal_uInt16        nFileNumber = mpBrowser->aCbbFileType.GetEntryPos( aFileType );
109         sal_uInt16              nBeginFormat, nEndFormat;
110         ::std::vector< String > aFormats;
111 
112 	    if( !nFileNumber || ( nFileNumber >= mpBrowser->aCbbFileType.GetEntryCount() ) )
113 	    {
114 		    nBeginFormat = 1;
115 		    nEndFormat = mpBrowser->aCbbFileType.GetEntryCount() - 1;
116 	    }
117 	    else
118 		    nBeginFormat = nEndFormat = nFileNumber;
119 
120 	    for( sal_uInt16 i = nBeginFormat; i <= nEndFormat; ++i )
121 	        aFormats.push_back( ( (FilterEntry*) mpBrowser->aFilterEntryList.GetObject( i ) )->aFilterName.ToLowerAscii() );
122 
123 	    ImplSearch( maStartURL, aFormats, mpBrowser->bSearchRecursive );
124     }
125 }
126 
127 // ------------------------------------------------------------------------
128 
129 void SAL_CALL SearchThread::onTerminated()
130 {
131 	Application::PostUserEvent( LINK( mpProgress, SearchProgress, CleanUpHdl ) );
132 }
133 
134 // ------------------------------------------------------------------------
135 
136 void SearchThread::ImplSearch( const INetURLObject& rStartURL,
137                                const ::std::vector< String >& rFormats,
138                                sal_Bool bRecursive )
139 {
140     {
141         ::vos::OGuard aGuard( Application::GetSolarMutex() );
142 
143         mpProgress->SetDirectory( rStartURL );
144         mpProgress->Sync();
145     }
146 
147 	try
148 	{
149 		::com::sun::star::uno::Reference< XCommandEnvironment >	xEnv;
150 		Content	aCnt( rStartURL.GetMainURL( INetURLObject::NO_DECODE ), xEnv );
151         Sequence< OUString > aProps( 2 );
152 
153         aProps.getArray()[ 0 ] = OUString::createFromAscii( "IsFolder" );
154         aProps.getArray()[ 1 ] = OUString::createFromAscii( "IsDocument" );
155         ::com::sun::star::uno::Reference< XResultSet > xResultSet(
156 			aCnt.createCursor( aProps, INCLUDE_FOLDERS_AND_DOCUMENTS ) );
157 
158 		if( xResultSet.is() )
159 		{
160             ::com::sun::star::uno::Reference< XContentAccess > xContentAccess( xResultSet, UNO_QUERY_THROW );
161             ::com::sun::star::uno::Reference< XRow > xRow( xResultSet, UNO_QUERY_THROW );
162 
163             while( xResultSet->next() && schedule() )
164             {
165                 INetURLObject   aFoundURL( xContentAccess->queryContentIdentifierString() );
166                 DBG_ASSERT( aFoundURL.GetProtocol() != INET_PROT_NOT_VALID, "invalid URL" );
167 
168                 sal_Bool bFolder = xRow->getBoolean( 1 ); // property "IsFolder"
169                 if ( xRow->wasNull() )
170                     bFolder = sal_False;
171 
172                 if( bRecursive && bFolder )
173                     ImplSearch( aFoundURL, rFormats, sal_True );
174                 else
175                 {
176                     sal_Bool bDocument = xRow->getBoolean( 2 ); // property "IsDocument"
177                     if ( xRow->wasNull() )
178                         bDocument = sal_False;
179 
180                     if( bDocument )
181                     {
182                         GraphicDescriptor   aDesc( aFoundURL );
183                         String              aFileName;
184 
185                         if( ( aDesc.Detect() &&
186                               ::std::find( rFormats.begin(),
187                                            rFormats.end(),
188                                            aDesc.GetImportFormatShortName(
189                                                aDesc.GetFileFormat() ).ToLowerAscii() )
190                               != rFormats.end() ) ||
191                             ::std::find( rFormats.begin(),
192                                          rFormats.end(),
193                                          String(aFoundURL.GetExtension().toAsciiLowerCase()) )
194                             != rFormats.end() )
195                         {
196                             ::vos::OGuard aGuard( Application::GetSolarMutex() );
197 
198                             mpBrowser->aFoundList.Insert(
199                                 new String( aFoundURL.GetMainURL( INetURLObject::NO_DECODE ) ),
200                                 LIST_APPEND );
201                             mpBrowser->aLbxFound.InsertEntry(
202                                 GetReducedString( aFoundURL, 50 ),
203                                 (sal_uInt16) mpBrowser->aFoundList.Count() - 1 );
204                         }
205                     }
206                 }
207             }
208         }
209 	}
210 	catch( const ContentCreationException& )
211 	{
212 	}
213 	catch( const ::com::sun::star::uno::RuntimeException& )
214 	{
215 	}
216     	catch( const ::com::sun::star::uno::Exception& )
217 	{
218 	}
219 }
220 
221 // ------------------
222 // - SearchProgress -
223 // ------------------
224 
225 SearchProgress::SearchProgress( Window* pParent, const INetURLObject& rStartURL ) :
226 	ModalDialog     ( pParent, CUI_RES(RID_SVXDLG_GALLERY_SEARCH_PROGRESS ) ),
227 	aFtSearchDir    ( this, CUI_RES( FT_SEARCH_DIR ) ),
228     aFLSearchDir   ( this, CUI_RES( FL_SEARCH_DIR ) ),
229 	aFtSearchType   ( this, CUI_RES( FT_SEARCH_TYPE ) ),
230     aFLSearchType  ( this, CUI_RES( FL_SEARCH_TYPE ) ),
231 	aBtnCancel      ( this, CUI_RES( BTN_CANCEL ) ),
232 	maSearchThread	( this, (TPGalleryThemeProperties*) pParent, rStartURL )
233 {
234 	FreeResource();
235 	aBtnCancel.SetClickHdl( LINK( this, SearchProgress, ClickCancelBtn ) );
236 }
237 
238 // ------------------------------------------------------------------------
239 
240 void SearchProgress::Terminate()
241 {
242 	maSearchThread.terminate();
243 }
244 
245 // ------------------------------------------------------------------------
246 
247 IMPL_LINK( SearchProgress, ClickCancelBtn, void*, EMPTYARG )
248 {
249 	Terminate();
250 	return 0L;
251 }
252 
253 // ------------------------------------------------------------------------
254 
255 IMPL_LINK( SearchProgress, CleanUpHdl, void*, EMPTYARG )
256 {
257 	EndDialog( RET_OK );
258     delete this;
259 	return 0L;
260 }
261 
262 // ------------------------------------------------------------------------
263 
264 short SearchProgress::Execute()
265 {
266     DBG_ERROR( "SearchProgress cannot be executed via Dialog::Execute!\n"
267                "It creates a thread that will call back to VCL apartment => deadlock!\n"
268                "Use Dialog::StartExecuteModal to execute the dialog!" );
269     return RET_CANCEL;
270 }
271 
272 // ------------------------------------------------------------------------
273 
274 void SearchProgress::StartExecuteModal( const Link& rEndDialogHdl )
275 {
276     maSearchThread.create();
277     ModalDialog::StartExecuteModal( rEndDialogHdl );
278 }
279 
280 // --------------
281 // - TakeThread -
282 // --------------
283 
284 TakeThread::TakeThread( TakeProgress* pProgess, TPGalleryThemeProperties* pBrowser, List& rTakenList ) :
285 		mpProgress	( pProgess ),
286 		mpBrowser	( pBrowser ),
287         mrTakenList ( rTakenList )
288 {
289 }
290 
291 // ------------------------------------------------------------------------
292 
293 TakeThread::~TakeThread()
294 {
295 }
296 
297 // ------------------------------------------------------------------------
298 
299 void SAL_CALL TakeThread::run()
300 {
301 	String				aName;
302 	INetURLObject		aURL;
303 	sal_uInt16				nEntries;
304 	GalleryTheme* 		pThm = mpBrowser->GetXChgData()->pTheme;
305 	sal_uInt16				nPos;
306 	GalleryProgress*	pStatusProgress;
307 
308     {
309         ::vos::OGuard aGuard( Application::GetSolarMutex() );
310         pStatusProgress = new GalleryProgress;
311         nEntries = mpBrowser->bTakeAll ? mpBrowser->aLbxFound.GetEntryCount() : mpBrowser->aLbxFound.GetSelectEntryCount();
312         pThm->LockBroadcaster();
313     }
314 
315 	for( sal_uInt16 i = 0; i < nEntries && schedule(); i++ )
316 	{
317 		// kompletten Filenamen aus FoundList holen
318 		if( mpBrowser->bTakeAll )
319 			aURL = INetURLObject(*mpBrowser->aFoundList.GetObject( nPos = i ));
320 		else
321 			aURL = INetURLObject(*mpBrowser->aFoundList.GetObject( nPos = mpBrowser->aLbxFound.GetSelectEntryPos( i ) ));
322 
323 		// Position in Taken-Liste uebernehmen
324         mrTakenList.Insert( (void*) (sal_uLong)nPos, LIST_APPEND );
325 
326         {
327             ::vos::OGuard aGuard( Application::GetSolarMutex() );
328 
329             mpProgress->SetFile( aURL.GetMainURL( INetURLObject::DECODE_UNAMBIGUOUS ) );
330             pStatusProgress->Update( i, nEntries - 1 );
331             mpProgress->Sync();
332             pThm->InsertURL( aURL );
333         }
334 	}
335 
336     {
337         ::vos::OGuard aGuard( Application::GetSolarMutex() );
338 
339         pThm->UnlockBroadcaster();
340         delete pStatusProgress;
341     }
342 }
343 
344 // ------------------------------------------------------------------------
345 
346 void SAL_CALL TakeThread::onTerminated()
347 {
348 	Application::PostUserEvent( LINK( mpProgress, TakeProgress, CleanUpHdl ) );
349 }
350 
351 // ----------------
352 // - TakeProgress -
353 // ----------------
354 
355 TakeProgress::TakeProgress( Window* pWindow ) :
356 	ModalDialog     ( pWindow, CUI_RES( RID_SVXDLG_GALLERY_TAKE_PROGRESS ) ),
357     aFtTakeFile     ( this, CUI_RES( FT_TAKE_FILE ) ),
358     aFLTakeProgress( this, CUI_RES( FL_TAKE_PROGRESS ) ),
359     aBtnCancel      ( this, CUI_RES( BTN_CANCEL ) ),
360     maTakeThread    ( this, (TPGalleryThemeProperties*) pWindow, maTakenList )
361 
362 {
363 	FreeResource();
364 	aBtnCancel.SetClickHdl( LINK( this, TakeProgress, ClickCancelBtn ) );
365 }
366 
367 // ------------------------------------------------------------------------
368 
369 
370 void TakeProgress::Terminate()
371 {
372     maTakeThread.terminate();
373 }
374 
375 // ------------------------------------------------------------------------
376 
377 IMPL_LINK( TakeProgress, ClickCancelBtn, void*, EMPTYARG )
378 {
379 	Terminate();
380 	return 0L;
381 }
382 
383 // ------------------------------------------------------------------------
384 
385 IMPL_LINK( TakeProgress, CleanUpHdl, void*, EMPTYARG )
386 {
387 	TPGalleryThemeProperties*	mpBrowser = (TPGalleryThemeProperties*) GetParent();
388 	::std::bit_vector           aRemoveEntries( mpBrowser->aFoundList.Count(), false );
389 	::std::vector< String >     aRemainingVector;
390 	sal_uInt32                  i, nCount;
391 
392 	GetParent()->EnterWait();
393 	mpBrowser->aLbxFound.SetUpdateMode( sal_False );
394 	mpBrowser->aLbxFound.SetNoSelection();
395 
396 	// mark all taken positions in aRemoveEntries
397 	for( i = 0UL, nCount = maTakenList.Count(); i < nCount; ++i )
398 	    aRemoveEntries[ (sal_uLong) maTakenList.GetObject( i ) ] = true;
399 
400 	maTakenList.Clear();
401 
402     // refill found list
403     for( i = 0, nCount = aRemoveEntries.size(); i < nCount; ++i )
404         if( !aRemoveEntries[ i ] )
405             aRemainingVector.push_back( *mpBrowser->aFoundList.GetObject( i ) );
406 
407     for( String* pStr = mpBrowser->aFoundList.First(); pStr; pStr = mpBrowser->aFoundList.Next() )
408 	    delete pStr;
409 
410 	mpBrowser->aFoundList.Clear();
411 
412 	for( i = 0, nCount = aRemainingVector.size(); i < nCount; ++i )
413 	    mpBrowser->aFoundList.Insert( new String( aRemainingVector[ i ] ), LIST_APPEND );
414 
415 	aRemainingVector.clear();
416 
417     // refill list box
418     for( i = 0, nCount = aRemoveEntries.size(); i < nCount; ++i )
419         if( !aRemoveEntries[ i ] )
420             aRemainingVector.push_back( mpBrowser->aLbxFound.GetEntry( (sal_uInt16) i ) );
421 
422     mpBrowser->aLbxFound.Clear();
423 
424 	for( i = 0, nCount = aRemainingVector.size(); i < nCount; ++i )
425 	    mpBrowser->aLbxFound.InsertEntry( aRemainingVector[ i ] );
426 
427 	aRemainingVector.clear();
428 
429 	mpBrowser->aLbxFound.SetUpdateMode( sal_True );
430 	mpBrowser->SelectFoundHdl( NULL );
431 	GetParent()->LeaveWait();
432 
433 	EndDialog( RET_OK );
434     delete this;
435 	return 0L;
436 }
437 
438 // ------------------------------------------------------------------------
439 
440 short TakeProgress::Execute()
441 {
442     DBG_ERROR( "TakeProgress cannot be executed via Dialog::Execute!\n"
443                "It creates a thread that will call back to VCL apartment => deadlock!\n"
444                "Use Dialog::StartExecuteModal to execute the dialog!" );
445     return RET_CANCEL;
446 }
447 
448 // ------------------------------------------------------------------------
449 
450 void TakeProgress::StartExecuteModal( const Link& rEndDialogHdl )
451 {
452     maTakeThread.create();
453     ModalDialog::StartExecuteModal( rEndDialogHdl );
454 }
455 
456 // ---------------------
457 // - ActualizeProgress -
458 // ---------------------
459 
460 ActualizeProgress::ActualizeProgress( Window* pWindow, GalleryTheme* pThm ) :
461 	ModalDialog				( pWindow, CUI_RES( RID_SVXDLG_GALLERY_ACTUALIZE_PROGRESS ) ),
462 	aFtActualizeFile		( this, CUI_RES( FT_ACTUALIZE_FILE ) ),
463     aFLActualizeProgress   ( this, CUI_RES( FL_ACTUALIZE_PROGRESS ) ),
464 	aBtnCancel				( this, CUI_RES( BTN_CANCEL ) ),
465 	pTheme					( pThm )
466 {
467 	FreeResource();
468 	aBtnCancel.SetClickHdl( LINK( this, ActualizeProgress, ClickCancelBtn ) );
469 }
470 
471 // ------------------------------------------------------------------------
472 
473 short ActualizeProgress::Execute()
474 {
475 	short nRet;
476 
477 	pTimer = new Timer;
478 
479 	if ( pTimer )
480 	{
481 		pTimer->SetTimeoutHdl( LINK( this, ActualizeProgress, TimeoutHdl ) );
482 		pTimer->SetTimeout( 500 );
483 		pTimer->Start();
484 	}
485 
486 	nRet = ModalDialog::Execute();
487 
488 	return nRet;
489 }
490 
491 // ------------------------------------------------------------------------
492 
493 IMPL_LINK( ActualizeProgress, ClickCancelBtn, void*, EMPTYARG )
494 {
495 	pTheme->AbortActualize();
496 	EndDialog( RET_OK );
497 
498 	return 0L;
499 }
500 
501 // ------------------------------------------------------------------------
502 
503 IMPL_LINK( ActualizeProgress, TimeoutHdl, Timer*, _pTimer )
504 {
505     if ( _pTimer )
506 	{
507         _pTimer->Stop();
508         delete _pTimer;
509 	}
510 
511 	pTheme->Actualize( LINK( this, ActualizeProgress, ActualizeHdl ), &aStatusProgress );
512 	ClickCancelBtn( NULL );
513 
514 	return 0;
515 }
516 
517 // ------------------------------------------------------------------------
518 
519 IMPL_LINK( ActualizeProgress, ActualizeHdl, INetURLObject*, pURL )
520 {
521   for( long i = 0; i < 128; i++ )
522 	Application::Reschedule();
523 
524     Flush();
525     Sync();
526 
527     if( pURL )
528     {
529         aFtActualizeFile.SetText( GetReducedString( *pURL, 30 ) );
530         aFtActualizeFile.Flush();
531         aFtActualizeFile.Sync();
532     }
533 
534 	return 0;
535 }
536 
537 // ---------------
538 // - TitleDialog -
539 // ---------------
540 
541 TitleDialog::TitleDialog( Window* pParent, const String& rOldTitle ) :
542 	ModalDialog	( pParent, CUI_RES( RID_SVXDLG_GALLERY_TITLE ) ),
543 	maOk		( this, CUI_RES( BTN_OK ) ),
544 	maCancel	( this, CUI_RES( BTN_CANCEL ) ),
545 	maHelp		( this, CUI_RES( BTN_HELP ) ),
546     maFL       ( this, CUI_RES( FL_TITLE ) ),
547 	maEdit		( this, CUI_RES( EDT_TITLE ) )
548 {
549 	FreeResource();
550 	maEdit.SetText( rOldTitle );
551 	maEdit.GrabFocus();
552 }
553 
554 // -------------------
555 // - GalleryIdDialog -
556 // -------------------
557 
558 GalleryIdDialog::GalleryIdDialog( Window* pParent, GalleryTheme* _pThm ) :
559 			ModalDialog	( pParent, CUI_RES( RID_SVXDLG_GALLERY_THEMEID ) ),
560 			aBtnOk		( this, CUI_RES( BTN_OK ) ),
561 			aBtnCancel	( this, CUI_RES( BTN_CANCEL ) ),
562             aFLId      ( this, CUI_RES( FL_ID ) ),
563 			aLbResName	( this, CUI_RES( LB_RESNAME ) ),
564 			pThm		( _pThm )
565 {
566 	FreeResource();
567 
568 	aLbResName.InsertEntry( String( RTL_CONSTASCII_USTRINGPARAM( "!!! No Id !!!" ) ) );
569 
570 	GalleryTheme::InsertAllThemes( aLbResName );
571 
572 	aLbResName.SelectEntryPos( (sal_uInt16) pThm->GetId() );
573 	aLbResName.GrabFocus();
574 
575 	aBtnOk.SetClickHdl( LINK( this, GalleryIdDialog, ClickOkHdl ) );
576 }
577 
578 // -----------------------------------------------------------------------------
579 
580 IMPL_LINK( GalleryIdDialog, ClickOkHdl, void*, EMPTYARG )
581 {
582 	Gallery*	pGal = pThm->GetParent();
583 	const sal_uLong	nId = GetId();
584 	sal_Bool		bDifferentThemeExists = sal_False;
585 
586 	for( sal_uLong i = 0, nCount = pGal->GetThemeCount(); i < nCount && !bDifferentThemeExists; i++ )
587 	{
588 		const GalleryThemeEntry* pInfo = pGal->GetThemeInfo( i );
589 
590 		if( ( pInfo->GetId() == nId ) && ( pInfo->GetThemeName() != pThm->GetName() ) )
591 		{
592 			String aStr( CUI_RES( RID_SVXSTR_GALLERY_ID_EXISTS ) );
593 
594 			aStr += String( RTL_CONSTASCII_USTRINGPARAM( " (" ) );
595 			aStr += pInfo->GetThemeName();
596 			aStr += ')';
597 
598 			InfoBox aBox( this, aStr );
599 			aBox.Execute();
600 			aLbResName.GrabFocus();
601 			bDifferentThemeExists = sal_True;
602 		}
603 	}
604 
605 	if( !bDifferentThemeExists )
606 		EndDialog( RET_OK );
607 
608 	return 0L;
609 }
610 
611 
612 // --------------------------
613 // - GalleryThemeProperties -
614 // --------------------------
615 
616 GalleryThemeProperties::GalleryThemeProperties( Window* pParent, ExchangeData* _pData, SfxItemSet* pItemSet  ) :
617 			SfxTabDialog    ( pParent, CUI_RES( RID_SVXTABDLG_GALLERYTHEME ), pItemSet ),
618 			pData			( _pData )
619 {
620 	FreeResource();
621 
622 	AddTabPage( RID_SVXTABPAGE_GALLERY_GENERAL, TPGalleryThemeGeneral::Create, 0 );
623 	AddTabPage( RID_SVXTABPAGE_GALLERYTHEME_FILES, TPGalleryThemeProperties::Create, 0 );
624 
625 	if( pData->pTheme->IsReadOnly() )
626 		RemoveTabPage( RID_SVXTABPAGE_GALLERYTHEME_FILES );
627 
628 	String aText( GetText() );
629 
630 	aText += pData->pTheme->GetName();
631 
632 	if( pData->pTheme->IsReadOnly() )
633 		aText += String( CUI_RES( RID_SVXSTR_GALLERY_READONLY ) );
634 
635 	SetText( aText );
636 }
637 
638 // ------------------------------------------------------------------------
639 
640 void GalleryThemeProperties::PageCreated( sal_uInt16 nId, SfxTabPage &rPage )
641 {
642 	if( RID_SVXTABPAGE_GALLERY_GENERAL == nId )
643 		( (TPGalleryThemeGeneral&) rPage ).SetXChgData( pData );
644 	else
645 		( (TPGalleryThemeProperties&) rPage ).SetXChgData( pData );
646 }
647 
648 // -------------------------
649 // - TPGalleryThemeGeneral -
650 // -------------------------
651 
652 TPGalleryThemeGeneral::TPGalleryThemeGeneral( Window* pParent, const SfxItemSet& rSet ) :
653 			SfxTabPage              ( pParent, CUI_RES( RID_SVXTABPAGE_GALLERY_GENERAL ), rSet ),
654 			aFiMSImage              ( this, CUI_RES( FI_MS_IMAGE ) ),
655 			aEdtMSName              ( this, CUI_RES( EDT_MS_NAME ) ),
656 			aFlMSGeneralFirst       ( this, CUI_RES( FL_MS_GENERAL_FIRST ) ),
657 			aFtMSType               ( this, CUI_RES( FT_MS_TYPE ) ),
658 			aFtMSShowType           ( this, CUI_RES( FT_MS_SHOW_TYPE ) ),
659 			aFtMSPath               ( this, CUI_RES( FT_MS_PATH ) ),
660 			aFtMSShowPath           ( this, CUI_RES( FT_MS_SHOW_PATH ) ),
661 			aFtMSContent            ( this, CUI_RES( FT_MS_CONTENT ) ),
662 			aFtMSShowContent        ( this, CUI_RES( FT_MS_SHOW_CONTENT ) ),
663 			aFlMSGeneralSecond      ( this, CUI_RES( FL_MS_GENERAL_SECOND ) ),
664 			aFtMSChangeDate         ( this, CUI_RES( FT_MS_CHANGEDATE ) ),
665 			aFtMSShowChangeDate     ( this, CUI_RES( FT_MS_SHOW_CHANGEDATE ) )
666 {
667 	FreeResource();
668 
669 	String aAccName(SVX_RES(RID_SVXSTR_GALLERY_THEMENAME));
670 	aEdtMSName.SetAccessibleName(aAccName);
671 	aFiMSImage.SetAccessibleName(aAccName);
672 	aEdtMSName.SetAccessibleRelationLabeledBy( &aFiMSImage );
673 }
674 
675 // ------------------------------------------------------------------------
676 
677 void TPGalleryThemeGeneral::SetXChgData( ExchangeData* _pData )
678 {
679 	pData = _pData;
680 
681 	GalleryTheme*		pThm = pData->pTheme;
682 	String              aOutStr( String::CreateFromInt32( pThm->GetObjectCount() ) );
683 	String              aObjStr( CUI_RES( RID_SVXSTR_GALLERYPROPS_OBJECT ) );
684 	String              aAccess;
685 	String				aType( SVX_RES( RID_SVXSTR_GALLERYPROPS_GALTHEME ) );
686 	sal_Bool			bReadOnly = pThm->IsReadOnly() && !pThm->IsImported();
687 
688 	aEdtMSName.SetHelpId( HID_GALLERY_EDIT_MSNAME );
689 	aEdtMSName.SetText( pThm->GetName() );
690 	aEdtMSName.SetReadOnly( bReadOnly );
691 
692 	if( bReadOnly )
693 		aEdtMSName.Disable();
694 	else
695 		aEdtMSName.Enable();
696 
697 	if( pThm->IsReadOnly() )
698 		aType += String( CUI_RES( RID_SVXSTR_GALLERY_READONLY ) );
699 
700 	aFtMSShowType.SetText( aType );
701 	aFtMSShowPath.SetText( pThm->GetSdgURL().GetMainURL( INetURLObject::DECODE_UNAMBIGUOUS ) );
702 
703 	// Ein- oder Mehrzahl?
704 	if ( 1 == pThm->GetObjectCount() )
705 		aObjStr = aObjStr.GetToken( 0 );
706 	else
707 		aObjStr = aObjStr.GetToken( 1 );
708 
709 	aOutStr += ' ';
710 	aOutStr += aObjStr;
711 
712 	aFtMSShowContent.SetText( aOutStr );
713 
714 	// get locale wrapper (singleton)
715 	const LocaleDataWrapper&    aLocaleData = SvtSysLocale().GetLocaleData();
716 
717 	// ChangeDate/Time
718 	aAccess = aLocaleData.getDate( pData->aThemeChangeDate );
719 	aAccess += String( RTL_CONSTASCII_USTRINGPARAM( ", " ) );
720 	aAccess += aLocaleData.getTime( pData->aThemeChangeTime );
721 	aFtMSShowChangeDate.SetText( aAccess );
722 
723 	// Image setzen
724 	sal_uInt16 nId;
725 
726 	if( pThm->IsImported() )
727 		nId = RID_SVXBMP_THEME_IMPORTED_BIG;
728 	else if( pThm->IsReadOnly() )
729 		nId = RID_SVXBMP_THEME_READONLY_BIG;
730 	else if( pThm->IsDefault() )
731 		nId = RID_SVXBMP_THEME_DEFAULT_BIG;
732 	else
733 		nId = RID_SVXBMP_THEME_NORMAL_BIG;
734 
735 	aFiMSImage.SetImage( Image( Bitmap( CUI_RES( nId ) ), COL_LIGHTMAGENTA ) );
736 }
737 
738 // ------------------------------------------------------------------------
739 
740 sal_Bool TPGalleryThemeGeneral::FillItemSet( SfxItemSet& /*rSet*/ )
741 {
742 	pData->aEditedTitle = aEdtMSName.GetText();
743 	return sal_True;
744 }
745 
746 // ------------------------------------------------------------------------
747 
748 SfxTabPage* TPGalleryThemeGeneral::Create( Window* pParent, const SfxItemSet& rSet )
749 {
750 	return new TPGalleryThemeGeneral( pParent, rSet );
751 }
752 
753 // ----------------------------
754 // - TPGalleryThemeProperties -
755 // ----------------------------
756 
757 TPGalleryThemeProperties::TPGalleryThemeProperties( Window* pWindow, const SfxItemSet& rSet ) :
758 		SfxTabPage			( pWindow, CUI_RES( RID_SVXTABPAGE_GALLERYTHEME_FILES ), rSet ),
759         aFtFileType         ( this, CUI_RES(FT_FILETYPE ) ),
760         aCbbFileType        ( this, CUI_RES(CBB_FILETYPE ) ),
761         aLbxFound           ( this, CUI_RES(LBX_FOUND ) ),
762         aBtnSearch          ( this, CUI_RES(BTN_SEARCH ) ),
763         aBtnTake            ( this, CUI_RES(BTN_TAKE ) ),
764         aBtnTakeAll         ( this, CUI_RES(BTN_TAKEALL ) ),
765         aCbxPreview         ( this, CUI_RES(CBX_PREVIEW ) ),
766         aWndPreview         ( this, CUI_RES( WND_BRSPRV ) ),
767         nCurFilterPos       (0),
768         nFirstExtFilterPos  (0),
769         bEntriesFound       (sal_False),
770         bInputAllowed       (sal_True),
771         bSearchRecursive    (sal_False),
772         xDialogListener     ( new ::svt::DialogClosedListener() )
773 {
774 	FreeResource();
775 
776     xDialogListener->SetDialogClosedLink( LINK( this, TPGalleryThemeProperties, DialogClosedHdl ) );
777 	aLbxFound.SetAccessibleName(String(SVX_RES(RID_SVXSTR_GALLERY_FILESFOUND)));
778     aWndPreview.SetAccessibleName(aCbxPreview.GetText());
779 	aLbxFound.SetAccessibleRelationLabeledBy(&aLbxFound);
780 }
781 
782 // ------------------------------------------------------------------------
783 
784 void TPGalleryThemeProperties::SetXChgData( ExchangeData* _pData )
785 {
786 	pData = _pData;
787 
788 	aPreviewTimer.SetTimeoutHdl( LINK( this, TPGalleryThemeProperties, PreviewTimerHdl ) );
789 	aPreviewTimer.SetTimeout( 500 );
790 	aBtnSearch.SetClickHdl(LINK(this, TPGalleryThemeProperties, ClickSearchHdl));
791 	aBtnTake.SetClickHdl(LINK(this, TPGalleryThemeProperties, ClickTakeHdl));
792 	aBtnTakeAll.SetClickHdl(LINK(this, TPGalleryThemeProperties, ClickTakeAllHdl));
793 	aCbxPreview.SetClickHdl(LINK(this, TPGalleryThemeProperties, ClickPreviewHdl));
794 	aCbbFileType.SetSelectHdl(LINK(this, TPGalleryThemeProperties, SelectFileTypeHdl));
795 	aCbbFileType.EnableDDAutoWidth( sal_False );
796 	aLbxFound.SetDoubleClickHdl(LINK(this, TPGalleryThemeProperties, DClickFoundHdl));
797 	aLbxFound.SetSelectHdl(LINK(this, TPGalleryThemeProperties, SelectFoundHdl));
798 	aLbxFound.InsertEntry(String(CUI_RES(RID_SVXSTR_GALLERY_NOFILES)));
799 	aLbxFound.Show();
800 
801 	FillFilterList();
802 
803 	aBtnTake.Enable();
804 	aBtnTakeAll.Disable();
805 	aCbxPreview.Disable();
806 }
807 
808 // ------------------------------------------------------------------------
809 
810 void TPGalleryThemeProperties::StartSearchFiles( const String& _rFolderURL, short _nDlgResult )
811 {
812     if ( RET_OK == _nDlgResult )
813     {
814         aURL = INetURLObject( _rFolderURL );
815         bSearchRecursive = sal_True;    // UI choice no longer possible, windows file picker allows no user controls
816         SearchFiles();
817     }
818 
819     nCurFilterPos = aCbbFileType.GetEntryPos( aCbbFileType.GetText() );
820 }
821 
822 // ------------------------------------------------------------------------
823 
824 TPGalleryThemeProperties::~TPGalleryThemeProperties()
825 {
826     xMediaPlayer.clear();
827     xDialogListener.clear();
828 
829 	for( String* pStr = aFoundList.First(); pStr; pStr = aFoundList.Next() )
830 		delete pStr;
831 
832 	for( void* pEntry = aFilterEntryList.First(); pEntry; pEntry = aFilterEntryList.Next() )
833 		delete (FilterEntry*) pEntry;
834 }
835 
836 // ------------------------------------------------------------------------
837 
838 SfxTabPage* TPGalleryThemeProperties::Create( Window* pParent, const SfxItemSet& rSet )
839 {
840 	return new TPGalleryThemeProperties( pParent, rSet );
841 }
842 
843 // ------------------------------------------------------------------------
844 
845 ::rtl::OUString TPGalleryThemeProperties::addExtension( const ::rtl::OUString& _rDisplayText, const ::rtl::OUString& _rExtension )
846 {
847     ::rtl::OUString sAllFilter( RTL_CONSTASCII_USTRINGPARAM( "(*.*)" ) );
848     ::rtl::OUString sOpenBracket( RTL_CONSTASCII_USTRINGPARAM( " (" ) );
849     ::rtl::OUString sCloseBracket( RTL_CONSTASCII_USTRINGPARAM( ")" ) );
850     ::rtl::OUString sRet = _rDisplayText;
851 
852     if ( sRet.indexOf( sAllFilter ) == -1 )
853     {
854         String sExt = _rExtension;
855         sRet += sOpenBracket;
856         sRet += sExt;
857         sRet += sCloseBracket;
858     }
859     return sRet;
860 }
861 
862 // ------------------------------------------------------------------------
863 
864 void TPGalleryThemeProperties::FillFilterList()
865 {
866 	GraphicFilter*		pFilter = GraphicFilter::GetGraphicFilter();
867 	String				aExt;
868     String				aName;
869 	FilterEntry*		pFilterEntry;
870 	FilterEntry*		pTestEntry;
871     sal_uInt16 			i, nKeyCount;
872 	sal_Bool				bInList;
873 
874 	// graphic filters
875 	for( i = 0, nKeyCount = pFilter->GetImportFormatCount(); i < nKeyCount; i++ )
876 	{
877 		aExt = pFilter->GetImportFormatShortName( i );
878         aName = pFilter->GetImportFormatName( i );
879 		pTestEntry = (FilterEntry*) aFilterEntryList.First();
880 		bInList = sal_False;
881 
882 		String aExtensions;
883 		int j = 0;
884 		String sWildcard;
885         while( sal_True )
886         {
887             sWildcard = pFilter->GetImportWildcard( i, j++ );
888             if ( !sWildcard.Len() )
889                 break;
890             if ( aExtensions.Search( sWildcard ) == STRING_NOTFOUND )
891             {
892                 if ( aExtensions.Len() )
893                     aExtensions += sal_Unicode(';');
894                 aExtensions += sWildcard;
895             }
896         }
897         aName = addExtension( aName, aExtensions );
898 
899 		while( pTestEntry )
900 		{
901 			if ( pTestEntry->aFilterName == aExt )
902 			{
903 				bInList = sal_True;
904 				break;
905 			}
906 			pTestEntry = (FilterEntry*) aFilterEntryList.Next();
907 		}
908 		if ( !bInList )
909 		{
910 			pFilterEntry = new FilterEntry;
911 			pFilterEntry->aFilterName = aExt;
912 			aFilterEntryList.Insert( pFilterEntry, aCbbFileType.InsertEntry( aName ) );
913 		}
914 	}
915 
916 	// media filters
917    	static const ::rtl::OUString	aWildcard( RTL_CONSTASCII_USTRINGPARAM( "*." ) );
918 	::avmedia::FilterNameVector		aFilters;
919 	const ::rtl::OUString			aSeparator( RTL_CONSTASCII_USTRINGPARAM( ";" ) );
920 	::rtl::OUString					aAllTypes;
921 
922 	::avmedia::MediaWindow::getMediaFilters( aFilters );
923 
924     for( unsigned long l = 0; l < aFilters.size(); ++l )
925 	{
926 		for( sal_Int32 nIndex = 0; nIndex >= 0; )
927         {
928 			::rtl::OUString aFilterWildcard( aWildcard );
929 
930 			pFilterEntry = new FilterEntry;
931             pFilterEntry->aFilterName = aFilters[ l ].second.getToken( 0, ';', nIndex );
932             nFirstExtFilterPos = aCbbFileType.InsertEntry( addExtension( aFilters[ l ].first,
933                                                            aFilterWildcard += pFilterEntry->aFilterName ) );
934 			aFilterEntryList.Insert( pFilterEntry, nFirstExtFilterPos );
935         }
936 	}
937 
938 	// 'All' filters
939 	String aExtensions;
940 
941 	// graphic filters
942 	for ( i = 0; i < nKeyCount; ++i )
943 	{
944 		int j = 0;
945 		String sWildcard;
946 		while( sal_True )
947 		{
948 			sWildcard = pFilter->GetImportWildcard( i, j++ );
949 			if ( !sWildcard.Len() )
950 				break;
951 			if ( aExtensions.Search( sWildcard ) == STRING_NOTFOUND )
952 			{
953 				if ( aExtensions.Len() )
954 					aExtensions += sal_Unicode( ';' );
955 
956 				aExtensions += sWildcard;
957 			}
958 		}
959 	}
960 
961 	// media filters
962     for( unsigned long k = 0; k < aFilters.size(); ++k )
963 	{
964 		for( sal_Int32 nIndex = 0; nIndex >= 0; )
965         {
966 		    if ( aExtensions.Len() )
967         		aExtensions += sal_Unicode( ';' );
968             ( aExtensions += String( aWildcard ) ) += String( aFilters[ k ].second.getToken( 0, ';', nIndex ) );
969 		}
970 	 }
971 
972 #if defined(WNT)
973 	if ( aExtensions.Len() > 240 )
974 		aExtensions = DEFINE_CONST_UNICODE( "*.*" );
975 #endif
976 
977     pFilterEntry = new FilterEntry;
978     pFilterEntry->aFilterName = String( CUI_RES( RID_SVXSTR_GALLERY_ALLFILES ) );
979     pFilterEntry->aFilterName = addExtension( pFilterEntry->aFilterName, aExtensions );
980     aFilterEntryList.Insert(pFilterEntry, aCbbFileType. InsertEntry( pFilterEntry->aFilterName, 0 ) );
981 
982     aCbbFileType.SetText( pFilterEntry->aFilterName );
983 }
984 
985 // ------------------------------------------------------------------------
986 
987 IMPL_LINK( TPGalleryThemeProperties, SelectFileTypeHdl, void *, EMPTYARG )
988 {
989 	String aText( aCbbFileType.GetText() );
990 
991 	if( bInputAllowed && ( aLastFilterName != aText ) )
992 	{
993 		aLastFilterName = aText;
994 
995 		if( QueryBox( this, WB_YES_NO, String( CUI_RES( RID_SVXSTR_GALLERY_SEARCH ) ) ).Execute() == RET_YES )
996 			SearchFiles();
997 	}
998 
999 	return 0L;
1000 }
1001 
1002 // ------------------------------------------------------------------------
1003 
1004 void TPGalleryThemeProperties::SearchFiles()
1005 {
1006 	SearchProgress*	pProgress = new SearchProgress( this, aURL );
1007 
1008 	for( String* pStr = aFoundList.First(); pStr; pStr = aFoundList.Next() )
1009 		delete pStr;
1010 
1011 	aFoundList.Clear();
1012 	aLbxFound.Clear();
1013 
1014 	pProgress->SetFileType( aCbbFileType.GetText() );
1015 	pProgress->SetDirectory( rtl::OUString() );
1016 	pProgress->Update();
1017 
1018     pProgress->StartExecuteModal( LINK( this, TPGalleryThemeProperties, EndSearchProgressHdl ) );
1019 }
1020 
1021 // ------------------------------------------------------------------------
1022 
1023 IMPL_LINK( TPGalleryThemeProperties, ClickCloseBrowserHdl, void *, EMPTYARG )
1024 {
1025 	if( bInputAllowed )
1026 		aPreviewTimer.Stop();
1027 
1028 	return 0L;
1029 }
1030 
1031 // ------------------------------------------------------------------------
1032 
1033 IMPL_LINK( TPGalleryThemeProperties, ClickSearchHdl, void *, EMPTYARG )
1034 {
1035 	if( bInputAllowed )
1036 	{
1037 		try
1038 		{
1039 			// setup folder picker
1040 			::com::sun::star::uno::Reference< XMultiServiceFactory > xMgr( ::comphelper::getProcessServiceFactory() );
1041 			if( xMgr.is() )
1042 			{
1043                 xFolderPicker = ::com::sun::star::uno::Reference< XFolderPicker >(
1044 					xMgr->createInstance( OUString::createFromAscii( "com.sun.star.ui.dialogs.FolderPicker" )), UNO_QUERY );
1045 
1046                 if ( xFolderPicker.is() )
1047 				{
1048 					String	aDlgPathName( SvtPathOptions().GetGraphicPath() );
1049                     xFolderPicker->setDisplayDirectory(aDlgPathName);
1050 
1051 					aPreviewTimer.Stop();
1052 
1053                     ::com::sun::star::uno::Reference< XAsynchronousExecutableDialog > xAsyncDlg( xFolderPicker, UNO_QUERY );
1054                     if ( xAsyncDlg.is() )
1055                         xAsyncDlg->startExecuteModal( xDialogListener.get() );
1056                     else
1057                     {
1058                         if( xFolderPicker->execute() == RET_OK )
1059                         {
1060                             aURL = INetURLObject( xFolderPicker->getDirectory() );
1061                             bSearchRecursive = sal_True;    // UI choice no longer possible, windows file picker allows no user controls
1062                             SearchFiles();
1063                         }
1064 
1065                         nCurFilterPos = aCbbFileType.GetEntryPos( aCbbFileType.GetText() );
1066                     }
1067 				}
1068 			}
1069 		}
1070 		catch(IllegalArgumentException)
1071 		{
1072 #ifdef DBG_UTIL
1073 			DBG_ERROR( "Folder picker failed with illegal arguments" );
1074 #endif
1075 		}
1076 	}
1077 
1078 	return 0L;
1079 }
1080 
1081 // ------------------------------------------------------------------------
1082 
1083 void TPGalleryThemeProperties::TakeFiles()
1084 {
1085 	if( aLbxFound.GetSelectEntryCount() || ( bTakeAll && bEntriesFound ) )
1086 	{
1087 		TakeProgress* pTakeProgress = new TakeProgress( this );
1088 		pTakeProgress->Update();
1089 
1090         pTakeProgress->StartExecuteModal(
1091             Link() /* no postprocessing needed, pTakeProgress
1092                       will be deleted in TakeProgress::CleanupHdl */ );
1093 	}
1094 }
1095 
1096 // ------------------------------------------------------------------------
1097 
1098 IMPL_LINK( TPGalleryThemeProperties, ClickPreviewHdl, void *, EMPTYARG )
1099 {
1100 	if ( bInputAllowed )
1101 	{
1102 		aPreviewTimer.Stop();
1103 		aPreviewString.Erase();
1104 
1105 		if( !aCbxPreview.IsChecked() )
1106 		{
1107 		    xMediaPlayer.clear();
1108 			aWndPreview.SetGraphic( Graphic() );
1109 			aWndPreview.Invalidate();
1110 		}
1111 		else
1112 			DoPreview();
1113 	}
1114 
1115 	return 0;
1116 }
1117 
1118 // ------------------------------------------------------------------------
1119 
1120 void TPGalleryThemeProperties::DoPreview()
1121 {
1122 	String aString( aLbxFound.GetSelectEntry() );
1123 
1124 	if( aString != aPreviewString )
1125 	{
1126         INetURLObject   _aURL( *aFoundList.GetObject( aLbxFound.GetEntryPos( aString ) ) );
1127 		bInputAllowed = sal_False;
1128 
1129 		if ( !aWndPreview.SetGraphic( _aURL ) )
1130 		{
1131 			GetParent()->LeaveWait();
1132 			ErrorHandler::HandleError( ERRCODE_IO_NOTEXISTSPATH );
1133 			GetParent()->EnterWait();
1134 		}
1135 		else if( ::avmedia::MediaWindow::isMediaURL( _aURL.GetMainURL( INetURLObject::DECODE_UNAMBIGUOUS ) ) )
1136 		{
1137             xMediaPlayer = ::avmedia::MediaWindow::createPlayer( _aURL.GetMainURL( INetURLObject::NO_DECODE ) );
1138 			if( xMediaPlayer.is() )
1139 			    xMediaPlayer->start();
1140 		}
1141 
1142 		bInputAllowed = sal_True;
1143 		aPreviewString = aString;
1144 	}
1145 }
1146 
1147 // ------------------------------------------------------------------------
1148 
1149 IMPL_LINK( TPGalleryThemeProperties, ClickTakeHdl, void*, EMPTYARG )
1150 {
1151 	if( bInputAllowed )
1152 	{
1153 		aPreviewTimer.Stop();
1154 
1155 		if( !aLbxFound.GetSelectEntryCount() || !bEntriesFound )
1156 		{
1157 			SvxOpenGraphicDialog aDlg(String( RTL_CONSTASCII_USTRINGPARAM( "Gallery" ) ) );
1158 			aDlg.EnableLink(sal_False);
1159 			aDlg.AsLink(sal_False);
1160 
1161 			if( !aDlg.Execute() )
1162 				pData->pTheme->InsertURL( INetURLObject( aDlg.GetPath() ) );
1163 		}
1164 		else
1165 		{
1166 			bTakeAll = sal_False;
1167 			TakeFiles();
1168 		}
1169 	}
1170 
1171 	return 0L;
1172 }
1173 
1174 // ------------------------------------------------------------------------
1175 
1176 IMPL_LINK( TPGalleryThemeProperties, ClickTakeAllHdl, void *, EMPTYARG )
1177 {
1178 	if( bInputAllowed )
1179 	{
1180 		aPreviewTimer.Stop();
1181 		bTakeAll = sal_True;
1182 		TakeFiles();
1183 	}
1184 
1185 	return 0L;
1186 }
1187 
1188 // ------------------------------------------------------------------------
1189 
1190 IMPL_LINK( TPGalleryThemeProperties, SelectFoundHdl, void *, EMPTYARG )
1191 {
1192 	if( bInputAllowed )
1193 	{
1194 		sal_Bool bPreviewPossible = sal_False;
1195 
1196 		aPreviewTimer.Stop();
1197 
1198 		if( bEntriesFound )
1199 		{
1200 			if( aLbxFound.GetSelectEntryCount() == 1 )
1201 			{
1202 				aCbxPreview.Enable();
1203 				bPreviewPossible = sal_True;
1204 			}
1205 			else
1206 				aCbxPreview.Disable();
1207 
1208 			if( aFoundList.Count() )
1209 				aBtnTakeAll.Enable();
1210 			else
1211 				aBtnTakeAll.Disable();
1212 		}
1213 
1214 		if( bPreviewPossible && aCbxPreview.IsChecked() )
1215 			aPreviewTimer.Start();
1216 	}
1217 
1218 	return 0;
1219 }
1220 
1221 // ------------------------------------------------------------------------
1222 
1223 IMPL_LINK( TPGalleryThemeProperties, DClickFoundHdl, void *, EMPTYARG )
1224 {
1225 	if( bInputAllowed )
1226 	{
1227 		aPreviewTimer.Stop();
1228 
1229 		return (aLbxFound.GetSelectEntryCount() == 1 && bEntriesFound) ?
1230 			ClickTakeHdl(NULL) : 0;
1231 	}
1232 	else
1233 		return 0;
1234 }
1235 
1236 // ------------------------------------------------------------------------
1237 
1238 IMPL_LINK( TPGalleryThemeProperties, PreviewTimerHdl, void *, EMPTYARG )
1239 {
1240 	aPreviewTimer.Stop();
1241 	DoPreview();
1242 	return 0L;
1243 }
1244 
1245 // ------------------------------------------------------------------------
1246 
1247 IMPL_LINK( TPGalleryThemeProperties, EndSearchProgressHdl, SearchProgress *, EMPTYARG )
1248 {
1249   if( aFoundList.Count() )
1250   {
1251       aLbxFound.SelectEntryPos( 0 );
1252       aBtnTakeAll.Enable();
1253       aCbxPreview.Enable();
1254       bEntriesFound = sal_True;
1255   }
1256   else
1257   {
1258       aLbxFound.InsertEntry( String( CUI_RES( RID_SVXSTR_GALLERY_NOFILES ) ) );
1259       aBtnTakeAll.Disable();
1260       aCbxPreview.Disable();
1261       bEntriesFound = sal_False;
1262   }
1263   return 0L;
1264 }
1265 
1266 // ------------------------------------------------------------------------
1267 
1268 IMPL_LINK( TPGalleryThemeProperties, DialogClosedHdl, ::com::sun::star::ui::dialogs::DialogClosedEvent*, pEvt )
1269 {
1270     DBG_ASSERT( xFolderPicker.is() == sal_True, "TPGalleryThemeProperties::DialogClosedHdl(): no folder picker" );
1271 
1272     String sURL = String( xFolderPicker->getDirectory() );
1273     StartSearchFiles( sURL, pEvt->DialogResult );
1274 
1275     return 0L;
1276 }
1277 
1278