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