Update ooo320-m1
[ooovba.git] / svx / source / cui / cuigaldlg.cxx
blob3c3bb1364e73f091edb0bfe44cdedb14d3165e6b
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: cuigaldlg.cxx,v $
10 * $Revision: 1.15 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svx.hxx"
34 #ifdef SVX_DLLIMPLEMENTATION
35 #undef SVX_DLLIMPLEMENTATION
36 #endif
38 #include <algorithm>
39 #include <ucbhelper/content.hxx>
40 #include <vos/mutex.hxx>
41 #include <vcl/svapp.hxx>
42 #include <vcl/msgbox.hxx>
43 #include <avmedia/mediawindow.hxx>
44 #include <svtools/pathoptions.hxx>
45 #include <avmedia/mediawindow.hxx>
46 #include "opengrf.hxx"
47 #include "impgrf.hxx"
48 #include "gallery1.hxx"
49 #include "galtheme.hxx"
50 #include "galbrws2.hxx"
51 #include "galdlg.hxx"
52 #include "cuigaldlg.hxx" //CHINA001
53 #include <svtools/pickerhelper.hxx>
54 #ifndef _SVX_HELPID_HRC
55 #include "helpid.hrc"
56 #endif
57 #include <svtools/syslocale.hxx>
58 #include <cppuhelper/implbase1.hxx>
59 #include <com/sun/star/uno/Reference.hxx>
60 #include <com/sun/star/lang/XInitialization.hpp>
61 #include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp>
62 #include <comphelper/processfactory.hxx>
63 #include <com/sun/star/sdbc/XResultSet.hpp>
64 #include <com/sun/star/sdbc/XRow.hpp>
65 #include <com/sun/star/ucb/XContentAccess.hpp>
66 #include <com/sun/star/ui/dialogs/XAsynchronousExecutableDialog.hpp>
68 // --------------
69 // - Namespaces -
70 // --------------
72 using namespace ::ucbhelper;
73 using namespace ::rtl;
74 using namespace ::cppu;
75 using namespace ::com::sun::star::lang;
76 using namespace ::com::sun::star::sdbc;
77 using namespace ::com::sun::star::ucb;
78 using namespace ::com::sun::star::ui::dialogs;
79 using namespace ::com::sun::star::uno;
82 // -----------
83 // - Defines -
84 // -----------
86 #define MAXPATH 1024
88 // ----------------
89 // - SearchThread -
90 // ----------------
92 SearchThread::SearchThread( SearchProgress* pProgess,
93 TPGalleryThemeProperties* pBrowser,
94 const INetURLObject& rStartURL ) :
95 mpProgress ( pProgess ),
96 mpBrowser ( pBrowser ),
97 maStartURL ( rStartURL )
101 // ------------------------------------------------------------------------
103 SearchThread::~SearchThread()
107 // ------------------------------------------------------------------------
109 void SAL_CALL SearchThread::run()
111 const String aFileType( mpBrowser->aCbbFileType.GetText() );
113 if( aFileType.Len() )
115 const sal_uInt16 nFileNumber = mpBrowser->aCbbFileType.GetEntryPos( aFileType );
116 sal_uInt16 nBeginFormat, nEndFormat;
117 ::std::vector< String > aFormats;
119 if( !nFileNumber || ( nFileNumber >= mpBrowser->aCbbFileType.GetEntryCount() ) )
121 nBeginFormat = 1;
122 nEndFormat = mpBrowser->aCbbFileType.GetEntryCount() - 1;
124 else
125 nBeginFormat = nEndFormat = nFileNumber;
127 for( sal_uInt16 i = nBeginFormat; i <= nEndFormat; ++i )
128 aFormats.push_back( ( (FilterEntry*) mpBrowser->aFilterEntryList.GetObject( i ) )->aFilterName.ToLowerAscii() );
130 ImplSearch( maStartURL, aFormats, mpBrowser->bSearchRecursive );
134 // ------------------------------------------------------------------------
136 void SAL_CALL SearchThread::onTerminated()
138 Application::PostUserEvent( LINK( mpProgress, SearchProgress, CleanUpHdl ) );
141 // ------------------------------------------------------------------------
143 void SearchThread::ImplSearch( const INetURLObject& rStartURL,
144 const ::std::vector< String >& rFormats,
145 BOOL bRecursive )
148 ::vos::OGuard aGuard( Application::GetSolarMutex() );
150 mpProgress->SetDirectory( rStartURL );
151 mpProgress->Sync();
156 ::com::sun::star::uno::Reference< XCommandEnvironment > xEnv;
157 Content aCnt( rStartURL.GetMainURL( INetURLObject::NO_DECODE ), xEnv );
158 Sequence< OUString > aProps( 2 );
160 aProps.getArray()[ 0 ] = OUString::createFromAscii( "IsFolder" );
161 aProps.getArray()[ 1 ] = OUString::createFromAscii( "IsDocument" );
162 ::com::sun::star::uno::Reference< XResultSet > xResultSet(
163 aCnt.createCursor( aProps, INCLUDE_FOLDERS_AND_DOCUMENTS ) );
165 if( xResultSet.is() )
167 ::com::sun::star::uno::Reference< XContentAccess > xContentAccess( xResultSet, UNO_QUERY_THROW );
168 ::com::sun::star::uno::Reference< XRow > xRow( xResultSet, UNO_QUERY_THROW );
170 while( xResultSet->next() && schedule() )
172 INetURLObject aFoundURL( xContentAccess->queryContentIdentifierString() );
173 DBG_ASSERT( aFoundURL.GetProtocol() != INET_PROT_NOT_VALID, "invalid URL" );
175 sal_Bool bFolder = xRow->getBoolean( 1 ); // property "IsFolder"
176 if ( xRow->wasNull() )
177 bFolder = sal_False;
179 if( bRecursive && bFolder )
180 ImplSearch( aFoundURL, rFormats, TRUE );
181 else
183 sal_Bool bDocument = xRow->getBoolean( 2 ); // property "IsDocument"
184 if ( xRow->wasNull() )
185 bDocument = sal_False;
187 if( bDocument )
189 GraphicDescriptor aDesc( aFoundURL );
190 String aFileName;
192 if( ( aDesc.Detect() &&
193 ::std::find( rFormats.begin(),
194 rFormats.end(),
195 aDesc.GetImportFormatShortName(
196 aDesc.GetFileFormat() ).ToLowerAscii() )
197 != rFormats.end() ) ||
198 ::std::find( rFormats.begin(),
199 rFormats.end(),
200 String(aFoundURL.GetExtension().toAsciiLowerCase()) )
201 != rFormats.end() )
203 ::vos::OGuard aGuard( Application::GetSolarMutex() );
205 mpBrowser->aFoundList.Insert(
206 new String( aFoundURL.GetMainURL( INetURLObject::NO_DECODE ) ),
207 LIST_APPEND );
208 mpBrowser->aLbxFound.InsertEntry(
209 GetReducedString( aFoundURL, 50 ),
210 (USHORT) mpBrowser->aFoundList.Count() - 1 );
217 catch( const ContentCreationException& )
220 catch( const ::com::sun::star::uno::RuntimeException& )
223 catch( const ::com::sun::star::uno::Exception& )
228 // ------------------
229 // - SearchProgress -
230 // ------------------
232 SearchProgress::SearchProgress( Window* pParent, const INetURLObject& rStartURL ) :
233 ModalDialog ( pParent, GAL_RESID(RID_SVXDLG_GALLERY_SEARCH_PROGRESS ) ),
234 aFtSearchDir ( this, GAL_RESID( FT_SEARCH_DIR ) ),
235 aFLSearchDir ( this, GAL_RESID( FL_SEARCH_DIR ) ),
236 aFtSearchType ( this, GAL_RESID( FT_SEARCH_TYPE ) ),
237 aFLSearchType ( this, GAL_RESID( FL_SEARCH_TYPE ) ),
238 aBtnCancel ( this, GAL_RESID( BTN_CANCEL ) ),
239 maSearchThread ( this, (TPGalleryThemeProperties*) pParent, rStartURL )
241 FreeResource();
242 aBtnCancel.SetClickHdl( LINK( this, SearchProgress, ClickCancelBtn ) );
245 // ------------------------------------------------------------------------
247 void SearchProgress::Terminate()
249 maSearchThread.terminate();
252 // ------------------------------------------------------------------------
254 IMPL_LINK( SearchProgress, ClickCancelBtn, void*, EMPTYARG )
256 Terminate();
257 return 0L;
260 // ------------------------------------------------------------------------
262 IMPL_LINK( SearchProgress, CleanUpHdl, void*, EMPTYARG )
264 EndDialog( RET_OK );
265 delete this;
266 return 0L;
269 // ------------------------------------------------------------------------
271 short SearchProgress::Execute()
273 DBG_ERROR( "SearchProgress cannot be executed via Dialog::Execute!\n"
274 "It creates a thread that will call back to VCL apartment => deadlock!\n"
275 "Use Dialog::StartExecuteModal to execute the dialog!" );
276 return RET_CANCEL;
279 // ------------------------------------------------------------------------
281 void SearchProgress::StartExecuteModal( const Link& rEndDialogHdl )
283 maSearchThread.create();
284 ModalDialog::StartExecuteModal( rEndDialogHdl );
287 // --------------
288 // - TakeThread -
289 // --------------
291 TakeThread::TakeThread( TakeProgress* pProgess, TPGalleryThemeProperties* pBrowser, List& rTakenList ) :
292 mpProgress ( pProgess ),
293 mpBrowser ( pBrowser ),
294 mrTakenList ( rTakenList )
298 // ------------------------------------------------------------------------
300 TakeThread::~TakeThread()
304 // ------------------------------------------------------------------------
306 void SAL_CALL TakeThread::run()
308 String aName;
309 INetURLObject aURL;
310 USHORT nEntries;
311 GalleryTheme* pThm = mpBrowser->GetXChgData()->pTheme;
312 USHORT nPos;
313 GalleryProgress* pStatusProgress;
316 ::vos::OGuard aGuard( Application::GetSolarMutex() );
317 pStatusProgress = new GalleryProgress;
318 nEntries = mpBrowser->bTakeAll ? mpBrowser->aLbxFound.GetEntryCount() : mpBrowser->aLbxFound.GetSelectEntryCount();
319 pThm->LockBroadcaster();
322 for( USHORT i = 0; i < nEntries && schedule(); i++ )
324 // kompletten Filenamen aus FoundList holen
325 if( mpBrowser->bTakeAll )
326 aURL = INetURLObject(*mpBrowser->aFoundList.GetObject( nPos = i ));
327 else
328 aURL = INetURLObject(*mpBrowser->aFoundList.GetObject( nPos = mpBrowser->aLbxFound.GetSelectEntryPos( i ) ));
330 // Position in Taken-Liste uebernehmen
331 mrTakenList.Insert( (void*) (ULONG)nPos, LIST_APPEND );
334 ::vos::OGuard aGuard( Application::GetSolarMutex() );
336 mpProgress->SetFile( aURL.GetMainURL( INetURLObject::DECODE_UNAMBIGUOUS ) );
337 pStatusProgress->Update( i, nEntries - 1 );
338 mpProgress->Sync();
339 pThm->InsertURL( aURL );
344 ::vos::OGuard aGuard( Application::GetSolarMutex() );
346 pThm->UnlockBroadcaster();
347 delete pStatusProgress;
351 // ------------------------------------------------------------------------
353 void SAL_CALL TakeThread::onTerminated()
355 Application::PostUserEvent( LINK( mpProgress, TakeProgress, CleanUpHdl ) );
358 // ----------------
359 // - TakeProgress -
360 // ----------------
362 TakeProgress::TakeProgress( Window* pWindow ) :
363 ModalDialog ( pWindow, GAL_RESID( RID_SVXDLG_GALLERY_TAKE_PROGRESS ) ),
364 aFtTakeFile ( this, GAL_RESID( FT_TAKE_FILE ) ),
365 aFLTakeProgress( this, GAL_RESID( FL_TAKE_PROGRESS ) ),
366 aBtnCancel ( this, GAL_RESID( BTN_CANCEL ) ),
367 maTakeThread ( this, (TPGalleryThemeProperties*) pWindow, maTakenList )
370 FreeResource();
371 aBtnCancel.SetClickHdl( LINK( this, TakeProgress, ClickCancelBtn ) );
374 // ------------------------------------------------------------------------
377 void TakeProgress::Terminate()
379 maTakeThread.terminate();
382 // ------------------------------------------------------------------------
384 IMPL_LINK( TakeProgress, ClickCancelBtn, void*, EMPTYARG )
386 Terminate();
387 return 0L;
390 // ------------------------------------------------------------------------
392 IMPL_LINK( TakeProgress, CleanUpHdl, void*, EMPTYARG )
394 TPGalleryThemeProperties* mpBrowser = (TPGalleryThemeProperties*) GetParent();
395 ::std::bit_vector aRemoveEntries( mpBrowser->aFoundList.Count(), false );
396 ::std::vector< String > aRemainingVector;
397 sal_uInt32 i, nCount;
399 GetParent()->EnterWait();
400 mpBrowser->aLbxFound.SetUpdateMode( FALSE );
401 mpBrowser->aLbxFound.SetNoSelection();
403 // mark all taken positions in aRemoveEntries
404 for( i = 0UL, nCount = maTakenList.Count(); i < nCount; ++i )
405 aRemoveEntries[ (ULONG) maTakenList.GetObject( i ) ] = true;
407 maTakenList.Clear();
409 // refill found list
410 for( i = 0, nCount = aRemoveEntries.size(); i < nCount; ++i )
411 if( !aRemoveEntries[ i ] )
412 aRemainingVector.push_back( *mpBrowser->aFoundList.GetObject( i ) );
414 for( String* pStr = mpBrowser->aFoundList.First(); pStr; pStr = mpBrowser->aFoundList.Next() )
415 delete pStr;
417 mpBrowser->aFoundList.Clear();
419 for( i = 0, nCount = aRemainingVector.size(); i < nCount; ++i )
420 mpBrowser->aFoundList.Insert( new String( aRemainingVector[ i ] ), LIST_APPEND );
422 aRemainingVector.clear();
424 // refill list box
425 for( i = 0, nCount = aRemoveEntries.size(); i < nCount; ++i )
426 if( !aRemoveEntries[ i ] )
427 aRemainingVector.push_back( mpBrowser->aLbxFound.GetEntry( (sal_uInt16) i ) );
429 mpBrowser->aLbxFound.Clear();
431 for( i = 0, nCount = aRemainingVector.size(); i < nCount; ++i )
432 mpBrowser->aLbxFound.InsertEntry( aRemainingVector[ i ] );
434 aRemainingVector.clear();
436 mpBrowser->aLbxFound.SetUpdateMode( TRUE );
437 mpBrowser->SelectFoundHdl( NULL );
438 GetParent()->LeaveWait();
440 EndDialog( RET_OK );
441 delete this;
442 return 0L;
445 // ------------------------------------------------------------------------
447 short TakeProgress::Execute()
449 DBG_ERROR( "TakeProgress cannot be executed via Dialog::Execute!\n"
450 "It creates a thread that will call back to VCL apartment => deadlock!\n"
451 "Use Dialog::StartExecuteModal to execute the dialog!" );
452 return RET_CANCEL;
455 // ------------------------------------------------------------------------
457 void TakeProgress::StartExecuteModal( const Link& rEndDialogHdl )
459 maTakeThread.create();
460 ModalDialog::StartExecuteModal( rEndDialogHdl );
463 // ---------------------
464 // - ActualizeProgress -
465 // ---------------------
467 ActualizeProgress::ActualizeProgress( Window* pWindow, GalleryTheme* pThm ) :
468 ModalDialog ( pWindow, GAL_RESID( RID_SVXDLG_GALLERY_ACTUALIZE_PROGRESS ) ),
469 aFtActualizeFile ( this, GAL_RESID( FT_ACTUALIZE_FILE ) ),
470 aFLActualizeProgress ( this, GAL_RESID( FL_ACTUALIZE_PROGRESS ) ),
471 aBtnCancel ( this, GAL_RESID( BTN_CANCEL ) ),
472 pTheme ( pThm )
474 FreeResource();
475 aBtnCancel.SetClickHdl( LINK( this, ActualizeProgress, ClickCancelBtn ) );
478 // ------------------------------------------------------------------------
480 short ActualizeProgress::Execute()
482 short nRet;
484 pTimer = new Timer;
486 if ( pTimer )
488 pTimer->SetTimeoutHdl( LINK( this, ActualizeProgress, TimeoutHdl ) );
489 pTimer->SetTimeout( 500 );
490 pTimer->Start();
493 nRet = ModalDialog::Execute();
495 return nRet;
498 // ------------------------------------------------------------------------
500 IMPL_LINK( ActualizeProgress, ClickCancelBtn, void*, EMPTYARG )
502 pTheme->AbortActualize();
503 EndDialog( RET_OK );
505 return 0L;
508 // ------------------------------------------------------------------------
510 IMPL_LINK( ActualizeProgress, TimeoutHdl, Timer*, _pTimer )
512 if ( _pTimer )
514 _pTimer->Stop();
515 delete _pTimer;
518 pTheme->Actualize( LINK( this, ActualizeProgress, ActualizeHdl ), &aStatusProgress );
519 ClickCancelBtn( NULL );
521 return 0;
524 // ------------------------------------------------------------------------
526 IMPL_LINK( ActualizeProgress, ActualizeHdl, INetURLObject*, pURL )
528 for( long i = 0; i < 128; i++ )
529 Application::Reschedule();
531 Flush();
532 Sync();
534 if( pURL )
536 aFtActualizeFile.SetText( GetReducedString( *pURL, 30 ) );
537 aFtActualizeFile.Flush();
538 aFtActualizeFile.Sync();
541 return 0;
544 // ---------------
545 // - TitleDialog -
546 // ---------------
548 TitleDialog::TitleDialog( Window* pParent, const String& rOldTitle ) :
549 ModalDialog ( pParent, GAL_RESID( RID_SVXDLG_GALLERY_TITLE ) ),
550 maOk ( this, GAL_RESID( BTN_OK ) ),
551 maCancel ( this, GAL_RESID( BTN_CANCEL ) ),
552 maHelp ( this, GAL_RESID( BTN_HELP ) ),
553 maFL ( this, GAL_RESID( FL_TITLE ) ),
554 maEdit ( this, GAL_RESID( EDT_TITLE ) )
556 FreeResource();
557 maEdit.SetText( rOldTitle );
558 maEdit.GrabFocus();
561 // -------------------
562 // - GalleryIdDialog -
563 // -------------------
565 GalleryIdDialog::GalleryIdDialog( Window* pParent, GalleryTheme* _pThm ) :
566 ModalDialog ( pParent, GAL_RESID( RID_SVXDLG_GALLERY_THEMEID ) ),
567 aBtnOk ( this, GAL_RESID( BTN_OK ) ),
568 aBtnCancel ( this, GAL_RESID( BTN_CANCEL ) ),
569 aFLId ( this, GAL_RESID( FL_ID ) ),
570 aLbResName ( this, GAL_RESID( LB_RESNAME ) ),
571 pThm ( _pThm )
573 FreeResource();
575 aLbResName.InsertEntry( String( RTL_CONSTASCII_USTRINGPARAM( "!!! No Id !!!" ) ) );
577 for( USHORT i = RID_GALLERYSTR_THEME_FIRST; i <= RID_GALLERYSTR_THEME_LAST; i++ )
578 aLbResName.InsertEntry( String( GAL_RESID( i ) ) );
580 aLbResName.SelectEntryPos( (USHORT) pThm->GetId() );
581 aLbResName.GrabFocus();
583 aBtnOk.SetClickHdl( LINK( this, GalleryIdDialog, ClickOkHdl ) );
586 // -----------------------------------------------------------------------------
588 IMPL_LINK( GalleryIdDialog, ClickOkHdl, void*, EMPTYARG )
590 Gallery* pGal = pThm->GetParent();
591 const ULONG nId = GetId();
592 BOOL bDifferentThemeExists = FALSE;
594 for( ULONG i = 0, nCount = pGal->GetThemeCount(); i < nCount && !bDifferentThemeExists; i++ )
596 const GalleryThemeEntry* pInfo = pGal->GetThemeInfo( i );
598 if( ( pInfo->GetId() == nId ) && ( pInfo->GetThemeName() != pThm->GetName() ) )
600 String aStr( GAL_RESID( RID_SVXSTR_GALLERY_ID_EXISTS ) );
602 aStr += String( RTL_CONSTASCII_USTRINGPARAM( " (" ) );
603 aStr += pInfo->GetThemeName();
604 aStr += ')';
606 InfoBox aBox( this, aStr );
607 aBox.Execute();
608 aLbResName.GrabFocus();
609 bDifferentThemeExists = TRUE;
613 if( !bDifferentThemeExists )
614 EndDialog( RET_OK );
616 return 0L;
620 // --------------------------
621 // - GalleryThemeProperties -
622 // --------------------------
624 GalleryThemeProperties::GalleryThemeProperties( Window* pParent, ExchangeData* _pData, SfxItemSet* pItemSet ) :
625 SfxTabDialog ( pParent, GAL_RESID( RID_SVXTABDLG_GALLERYTHEME ), pItemSet ),
626 pData ( _pData )
628 FreeResource();
630 AddTabPage( RID_SVXTABPAGE_GALLERY_GENERAL, TPGalleryThemeGeneral::Create, 0 );
631 AddTabPage( RID_SVXTABPAGE_GALLERYTHEME_FILES, TPGalleryThemeProperties::Create, 0 );
633 if( pData->pTheme->IsReadOnly() )
634 RemoveTabPage( RID_SVXTABPAGE_GALLERYTHEME_FILES );
636 String aText( GetText() );
638 aText += pData->pTheme->GetName();
640 if( pData->pTheme->IsReadOnly() )
641 aText += String( GAL_RESID( RID_SVXSTR_GALLERY_READONLY ) );
643 SetText( aText );
646 // ------------------------------------------------------------------------
648 void GalleryThemeProperties::PageCreated( USHORT nId, SfxTabPage &rPage )
650 if( RID_SVXTABPAGE_GALLERY_GENERAL == nId )
651 ( (TPGalleryThemeGeneral&) rPage ).SetXChgData( pData );
652 else
653 ( (TPGalleryThemeProperties&) rPage ).SetXChgData( pData );
656 // -------------------------
657 // - TPGalleryThemeGeneral -
658 // -------------------------
660 TPGalleryThemeGeneral::TPGalleryThemeGeneral( Window* pParent, const SfxItemSet& rSet ) :
661 SfxTabPage ( pParent, GAL_RESID( RID_SVXTABPAGE_GALLERY_GENERAL ), rSet ),
662 aFiMSImage ( this, GAL_RESID( FI_MS_IMAGE ) ),
663 aEdtMSName ( this, GAL_RESID( EDT_MS_NAME ) ),
664 aFlMSGeneralFirst ( this, GAL_RESID( FL_MS_GENERAL_FIRST ) ),
665 aFtMSType ( this, GAL_RESID( FT_MS_TYPE ) ),
666 aFtMSShowType ( this, GAL_RESID( FT_MS_SHOW_TYPE ) ),
667 aFtMSPath ( this, GAL_RESID( FT_MS_PATH ) ),
668 aFtMSShowPath ( this, GAL_RESID( FT_MS_SHOW_PATH ) ),
669 aFtMSContent ( this, GAL_RESID( FT_MS_CONTENT ) ),
670 aFtMSShowContent ( this, GAL_RESID( FT_MS_SHOW_CONTENT ) ),
671 aFlMSGeneralSecond ( this, GAL_RESID( FL_MS_GENERAL_SECOND ) ),
672 aFtMSChangeDate ( this, GAL_RESID( FT_MS_CHANGEDATE ) ),
673 aFtMSShowChangeDate ( this, GAL_RESID( FT_MS_SHOW_CHANGEDATE ) )
675 FreeResource();
678 // ------------------------------------------------------------------------
680 void TPGalleryThemeGeneral::SetXChgData( ExchangeData* _pData )
682 pData = _pData;
684 GalleryTheme* pThm = pData->pTheme;
685 String aOutStr( String::CreateFromInt32( pThm->GetObjectCount() ) );
686 String aObjStr( GAL_RESID( RID_SVXSTR_GALLERYPROPS_OBJECT ) );
687 String aAccess;
688 String aType( GAL_RESID( RID_SVXSTR_GALLERYPROPS_GALTHEME ) );
689 BOOL bReadOnly = pThm->IsReadOnly() && !pThm->IsImported();
691 aEdtMSName.SetHelpId( HID_GALLERY_EDIT_MSNAME );
692 aEdtMSName.SetText( pThm->GetName() );
693 aEdtMSName.SetReadOnly( bReadOnly );
695 if( bReadOnly )
696 aEdtMSName.Disable();
697 else
698 aEdtMSName.Enable();
700 if( pThm->IsReadOnly() )
701 aType += String( GAL_RESID( RID_SVXSTR_GALLERY_READONLY ) );
703 aFtMSShowType.SetText( aType );
704 aFtMSShowPath.SetText( pThm->GetSdgURL().GetMainURL( INetURLObject::DECODE_UNAMBIGUOUS ) );
706 // Ein- oder Mehrzahl?
707 if ( 1 == pThm->GetObjectCount() )
708 aObjStr = aObjStr.GetToken( 0 );
709 else
710 aObjStr = aObjStr.GetToken( 1 );
712 aOutStr += ' ';
713 aOutStr += aObjStr;
715 aFtMSShowContent.SetText( aOutStr );
717 // get locale wrapper (singleton)
718 const LocaleDataWrapper& aLocaleData = SvtSysLocale().GetLocaleData();
720 // ChangeDate/Time
721 aAccess = aLocaleData.getDate( pData->aThemeChangeDate );
722 aAccess += String( RTL_CONSTASCII_USTRINGPARAM( ", " ) );
723 aAccess += aLocaleData.getTime( pData->aThemeChangeTime );
724 aFtMSShowChangeDate.SetText( aAccess );
726 // Image setzen
727 USHORT nId;
729 if( pThm->IsImported() )
730 nId = RID_SVXBMP_THEME_IMPORTED_BIG;
731 else if( pThm->IsReadOnly() )
732 nId = RID_SVXBMP_THEME_READONLY_BIG;
733 else if( pThm->IsDefault() )
734 nId = RID_SVXBMP_THEME_DEFAULT_BIG;
735 else
736 nId = RID_SVXBMP_THEME_NORMAL_BIG;
738 aFiMSImage.SetImage( Image( Bitmap( GAL_RESID( nId ) ), COL_LIGHTMAGENTA ) );
741 // ------------------------------------------------------------------------
743 BOOL TPGalleryThemeGeneral::FillItemSet( SfxItemSet& /*rSet*/ )
745 pData->aEditedTitle = aEdtMSName.GetText();
746 return TRUE;
749 // ------------------------------------------------------------------------
751 SfxTabPage* TPGalleryThemeGeneral::Create( Window* pParent, const SfxItemSet& rSet )
753 return new TPGalleryThemeGeneral( pParent, rSet );
756 // ----------------------------
757 // - TPGalleryThemeProperties -
758 // ----------------------------
760 TPGalleryThemeProperties::TPGalleryThemeProperties( Window* pWindow, const SfxItemSet& rSet ) :
761 SfxTabPage ( pWindow, GAL_RESID( RID_SVXTABPAGE_GALLERYTHEME_FILES ), rSet ),
762 aBtnSearch ( this, GAL_RESID(BTN_SEARCH ) ),
763 aBtnTake ( this, GAL_RESID(BTN_TAKE ) ),
764 aBtnTakeAll ( this, GAL_RESID(BTN_TAKEALL ) ),
765 aCbxPreview ( this, GAL_RESID(CBX_PREVIEW ) ),
766 aCbbFileType ( this, GAL_RESID(CBB_FILETYPE ) ),
767 aLbxFound ( this, GAL_RESID(LBX_FOUND ) ),
768 aFtFileType ( this, GAL_RESID(FT_FILETYPE ) ),
769 aWndPreview ( this, GAL_RESID( WND_BRSPRV ) ),
770 nCurFilterPos (0),
771 nFirstExtFilterPos (0),
772 bEntriesFound (FALSE),
773 bInputAllowed (TRUE),
774 bSearchRecursive (FALSE),
775 xDialogListener ( new ::svt::DialogClosedListener() )
777 FreeResource();
779 xDialogListener->SetDialogClosedLink( LINK( this, TPGalleryThemeProperties, DialogClosedHdl ) );
782 // ------------------------------------------------------------------------
784 void TPGalleryThemeProperties::SetXChgData( ExchangeData* _pData )
786 pData = _pData;
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(GAL_RESID(RID_SVXSTR_GALLERY_NOFILES)));
799 aLbxFound.Show();
801 FillFilterList();
803 aBtnTake.Enable();
804 aBtnTakeAll.Disable();
805 aCbxPreview.Disable();
808 // ------------------------------------------------------------------------
810 void TPGalleryThemeProperties::StartSearchFiles( const String& _rFolderURL, short _nDlgResult )
812 if ( RET_OK == _nDlgResult )
814 aURL = INetURLObject( _rFolderURL );
815 bSearchRecursive = sal_True; // UI choice no longer possible, windows file picker allows no user controls
816 SearchFiles();
819 nCurFilterPos = aCbbFileType.GetEntryPos( aCbbFileType.GetText() );
822 // ------------------------------------------------------------------------
824 TPGalleryThemeProperties::~TPGalleryThemeProperties()
826 xMediaPlayer.clear();
827 xDialogListener.clear();
829 for( String* pStr = aFoundList.First(); pStr; pStr = aFoundList.Next() )
830 delete pStr;
832 for( void* pEntry = aFilterEntryList.First(); pEntry; pEntry = aFilterEntryList.Next() )
833 delete (FilterEntry*) pEntry;
836 // ------------------------------------------------------------------------
838 SfxTabPage* TPGalleryThemeProperties::Create( Window* pParent, const SfxItemSet& rSet )
840 return new TPGalleryThemeProperties( pParent, rSet );
843 // ------------------------------------------------------------------------
845 ::rtl::OUString TPGalleryThemeProperties::addExtension( const ::rtl::OUString& _rDisplayText, const ::rtl::OUString& _rExtension )
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;
852 if ( sRet.indexOf( sAllFilter ) == -1 )
854 String sExt = _rExtension;
855 sRet += sOpenBracket;
856 sRet += sExt;
857 sRet += sCloseBracket;
859 return sRet;
862 // ------------------------------------------------------------------------
864 void TPGalleryThemeProperties::FillFilterList()
866 GraphicFilter* pFilter = GetGrfFilter();
867 String aExt;
868 String aName;
869 FilterEntry* pFilterEntry;
870 FilterEntry* pTestEntry;
871 sal_uInt16 i, nKeyCount;
872 BOOL bInList;
874 // graphic filters
875 for( i = 0, nKeyCount = pFilter->GetImportFormatCount(); i < nKeyCount; i++ )
877 aExt = pFilter->GetImportFormatShortName( i );
878 aName = pFilter->GetImportFormatName( i );
879 pTestEntry = (FilterEntry*) aFilterEntryList.First();
880 bInList = FALSE;
882 String aExtensions;
883 int j = 0;
884 String sWildcard;
885 while( TRUE )
887 sWildcard = pFilter->GetImportWildcard( i, j++ );
888 if ( !sWildcard.Len() )
889 break;
890 if ( aExtensions.Search( sWildcard ) == STRING_NOTFOUND )
892 if ( aExtensions.Len() )
893 aExtensions += sal_Unicode(';');
894 aExtensions += sWildcard;
897 aName = addExtension( aName, aExtensions );
899 while( pTestEntry )
901 if ( pTestEntry->aFilterName == aExt )
903 bInList = TRUE;
904 break;
906 pTestEntry = (FilterEntry*) aFilterEntryList.Next();
908 if ( !bInList )
910 pFilterEntry = new FilterEntry;
911 pFilterEntry->aFilterName = aExt;
912 aFilterEntryList.Insert( pFilterEntry, aCbbFileType.InsertEntry( aName ) );
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;
922 ::avmedia::MediaWindow::getMediaFilters( aFilters );
924 for( unsigned long l = 0; l < aFilters.size(); ++l )
926 for( sal_Int32 nIndex = 0; nIndex >= 0; )
928 ::rtl::OUString aFilterWildcard( aWildcard );
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 );
938 // 'All' filters
939 String aExtensions;
941 // graphic filters
942 for ( i = 0; i < nKeyCount; ++i )
944 int j = 0;
945 String sWildcard;
946 while( TRUE )
948 sWildcard = pFilter->GetImportWildcard( i, j++ );
949 if ( !sWildcard.Len() )
950 break;
951 if ( aExtensions.Search( sWildcard ) == STRING_NOTFOUND )
953 if ( aExtensions.Len() )
954 aExtensions += sal_Unicode( ';' );
956 aExtensions += sWildcard;
961 // media filters
962 for( unsigned long k = 0; k < aFilters.size(); ++k )
964 for( sal_Int32 nIndex = 0; nIndex >= 0; )
966 if ( aExtensions.Len() )
967 aExtensions += sal_Unicode( ';' );
968 ( aExtensions += String( aWildcard ) ) += String( aFilters[ k ].second.getToken( 0, ';', nIndex ) );
972 #if defined(WIN) || defined(WNT)
973 if ( aExtensions.Len() > 240 )
974 aExtensions = DEFINE_CONST_UNICODE( "*.*" );
975 #endif
977 pFilterEntry = new FilterEntry;
978 pFilterEntry->aFilterName = String( GAL_RESID( RID_SVXSTR_GALLERY_ALLFILES ) );
979 pFilterEntry->aFilterName = addExtension( pFilterEntry->aFilterName, aExtensions );
980 aFilterEntryList.Insert(pFilterEntry, aCbbFileType. InsertEntry( pFilterEntry->aFilterName, 0 ) );
982 aCbbFileType.SetText( pFilterEntry->aFilterName );
985 // ------------------------------------------------------------------------
987 IMPL_LINK( TPGalleryThemeProperties, SelectFileTypeHdl, void *, EMPTYARG )
989 String aText( aCbbFileType.GetText() );
991 if( bInputAllowed && ( aLastFilterName != aText ) )
993 aLastFilterName = aText;
995 if( QueryBox( this, WB_YES_NO, String( GAL_RESID( RID_SVXSTR_GALLERY_SEARCH ) ) ).Execute() == RET_YES )
996 SearchFiles();
999 return 0L;
1002 // ------------------------------------------------------------------------
1004 void TPGalleryThemeProperties::SearchFiles()
1006 SearchProgress* pProgress = new SearchProgress( this, aURL );
1008 for( String* pStr = aFoundList.First(); pStr; pStr = aFoundList.Next() )
1009 delete pStr;
1011 aFoundList.Clear();
1012 aLbxFound.Clear();
1014 pProgress->SetFileType( aCbbFileType.GetText() );
1015 pProgress->SetDirectory( rtl::OUString() );
1016 pProgress->Update();
1018 pProgress->StartExecuteModal( LINK( this, TPGalleryThemeProperties, EndSearchProgressHdl ) );
1021 // ------------------------------------------------------------------------
1023 IMPL_LINK( TPGalleryThemeProperties, ClickCloseBrowserHdl, void *, EMPTYARG )
1025 if( bInputAllowed )
1026 aPreviewTimer.Stop();
1028 return 0L;
1031 // ------------------------------------------------------------------------
1033 IMPL_LINK( TPGalleryThemeProperties, ClickSearchHdl, void *, EMPTYARG )
1035 if( bInputAllowed )
1039 // setup folder picker
1040 ::com::sun::star::uno::Reference< XMultiServiceFactory > xMgr( ::comphelper::getProcessServiceFactory() );
1041 if( xMgr.is() )
1043 xFolderPicker = ::com::sun::star::uno::Reference< XFolderPicker >(
1044 xMgr->createInstance( OUString::createFromAscii( "com.sun.star.ui.dialogs.FolderPicker" )), UNO_QUERY );
1046 if ( xFolderPicker.is() )
1048 // svt::SetDialogHelpId( xFolderPicker, HID_GALLERY_NEWTHEME_FINDFILES );
1049 String aDlgPathName( SvtPathOptions().GetGraphicPath() );
1050 xFolderPicker->setDisplayDirectory(aDlgPathName);
1052 aPreviewTimer.Stop();
1054 ::com::sun::star::uno::Reference< XAsynchronousExecutableDialog > xAsyncDlg( xFolderPicker, UNO_QUERY );
1055 if ( xAsyncDlg.is() )
1056 xAsyncDlg->startExecuteModal( xDialogListener.get() );
1057 else
1059 if( xFolderPicker->execute() == RET_OK )
1061 aURL = INetURLObject( xFolderPicker->getDirectory() );
1062 bSearchRecursive = sal_True; // UI choice no longer possible, windows file picker allows no user controls
1063 SearchFiles();
1066 nCurFilterPos = aCbbFileType.GetEntryPos( aCbbFileType.GetText() );
1071 catch(IllegalArgumentException)
1073 #ifdef DBG_UTIL
1074 DBG_ERROR( "Folder picker failed with illegal arguments" );
1075 #endif
1079 return 0L;
1082 // ------------------------------------------------------------------------
1084 void TPGalleryThemeProperties::TakeFiles()
1086 if( aLbxFound.GetSelectEntryCount() || ( bTakeAll && bEntriesFound ) )
1088 TakeProgress* pTakeProgress = new TakeProgress( this );
1089 pTakeProgress->Update();
1091 pTakeProgress->StartExecuteModal(
1092 Link() /* no postprocessing needed, pTakeProgress
1093 will be deleted in TakeProgress::CleanupHdl */ );
1097 // ------------------------------------------------------------------------
1099 IMPL_LINK( TPGalleryThemeProperties, ClickPreviewHdl, void *, EMPTYARG )
1101 if ( bInputAllowed )
1103 aPreviewTimer.Stop();
1104 aPreviewString.Erase();
1106 if( !aCbxPreview.IsChecked() )
1108 xMediaPlayer.clear();
1109 aWndPreview.SetGraphic( Graphic() );
1110 aWndPreview.Invalidate();
1112 else
1113 DoPreview();
1116 return 0;
1119 // ------------------------------------------------------------------------
1121 void TPGalleryThemeProperties::DoPreview()
1123 String aString( aLbxFound.GetSelectEntry() );
1125 if( aString != aPreviewString )
1127 Graphic aGraphic;
1128 INetURLObject _aURL( *aFoundList.GetObject( aLbxFound.GetEntryPos( aString ) ) );
1130 bInputAllowed = FALSE;
1132 if( ::avmedia::MediaWindow::isMediaURL( _aURL.GetMainURL( INetURLObject::DECODE_UNAMBIGUOUS ) ) )
1134 aGraphic = BitmapEx( GAL_RESID( RID_SVXBMP_GALLERY_MEDIA ) );
1135 xMediaPlayer = ::avmedia::MediaWindow::createPlayer( _aURL.GetMainURL( INetURLObject::NO_DECODE ) );
1136 if( xMediaPlayer.is() )
1137 xMediaPlayer->start();
1139 else
1141 GraphicFilter* pFilter = GetGrfFilter();
1142 GalleryProgress aProgress( pFilter );
1144 if( pFilter->ImportGraphic( aGraphic, _aURL, GRFILTER_FORMAT_DONTKNOW ) )
1146 GetParent()->LeaveWait();
1147 ErrorHandler::HandleError( ERRCODE_IO_NOTEXISTSPATH );
1148 GetParent()->EnterWait();
1152 aWndPreview.SetGraphic( aGraphic );
1153 aWndPreview.Invalidate();
1154 bInputAllowed = TRUE;
1155 aPreviewString = aString;
1159 // ------------------------------------------------------------------------
1161 IMPL_LINK( TPGalleryThemeProperties, ClickTakeHdl, void*, EMPTYARG )
1163 if( bInputAllowed )
1165 aPreviewTimer.Stop();
1167 if( !aLbxFound.GetSelectEntryCount() || !bEntriesFound )
1169 SvxOpenGraphicDialog aDlg(String( RTL_CONSTASCII_USTRINGPARAM( "Gallery" ) ) );
1170 // aDlg.SetDialogHelpId( HID_GALLERY_NEWTHEME_ADDFILES );
1171 aDlg.EnableLink(sal_False);
1172 aDlg.AsLink(sal_False);
1174 if( !aDlg.Execute() )
1175 pData->pTheme->InsertURL( INetURLObject( aDlg.GetPath() ) );
1177 else
1179 bTakeAll = FALSE;
1180 TakeFiles();
1184 return 0L;
1187 // ------------------------------------------------------------------------
1189 IMPL_LINK( TPGalleryThemeProperties, ClickTakeAllHdl, void *, EMPTYARG )
1191 if( bInputAllowed )
1193 aPreviewTimer.Stop();
1194 bTakeAll = TRUE;
1195 TakeFiles();
1198 return 0L;
1201 // ------------------------------------------------------------------------
1203 IMPL_LINK( TPGalleryThemeProperties, SelectFoundHdl, void *, EMPTYARG )
1205 if( bInputAllowed )
1207 BOOL bPreviewPossible = FALSE;
1209 aPreviewTimer.Stop();
1211 if( bEntriesFound )
1213 if( aLbxFound.GetSelectEntryCount() == 1 )
1215 aCbxPreview.Enable();
1216 bPreviewPossible = TRUE;
1218 else
1219 aCbxPreview.Disable();
1221 if( aFoundList.Count() )
1222 aBtnTakeAll.Enable();
1223 else
1224 aBtnTakeAll.Disable();
1227 if( bPreviewPossible && aCbxPreview.IsChecked() )
1228 aPreviewTimer.Start();
1231 return 0;
1234 // ------------------------------------------------------------------------
1236 IMPL_LINK( TPGalleryThemeProperties, DClickFoundHdl, void *, EMPTYARG )
1238 if( bInputAllowed )
1240 aPreviewTimer.Stop();
1242 return (aLbxFound.GetSelectEntryCount() == 1 && bEntriesFound) ?
1243 ClickTakeHdl(NULL) : 0;
1245 else
1246 return 0;
1249 // ------------------------------------------------------------------------
1251 IMPL_LINK( TPGalleryThemeProperties, PreviewTimerHdl, void *, EMPTYARG )
1253 aPreviewTimer.Stop();
1254 DoPreview();
1255 return 0L;
1258 // ------------------------------------------------------------------------
1260 IMPL_LINK( TPGalleryThemeProperties, EndSearchProgressHdl, SearchProgress *, EMPTYARG )
1262 if( aFoundList.Count() )
1264 aLbxFound.SelectEntryPos( 0 );
1265 aBtnTakeAll.Enable();
1266 aCbxPreview.Enable();
1267 bEntriesFound = TRUE;
1269 else
1271 aLbxFound.InsertEntry( String( GAL_RESID( RID_SVXSTR_GALLERY_NOFILES ) ) );
1272 aBtnTakeAll.Disable();
1273 aCbxPreview.Disable();
1274 bEntriesFound = FALSE;
1276 return 0L;
1279 // ------------------------------------------------------------------------
1281 IMPL_LINK( TPGalleryThemeProperties, DialogClosedHdl, ::com::sun::star::ui::dialogs::DialogClosedEvent*, pEvt )
1283 DBG_ASSERT( xFolderPicker.is() == sal_True, "TPGalleryThemeProperties::DialogClosedHdl(): no folder picker" );
1285 String sURL = String( xFolderPicker->getDirectory() );
1286 StartSearchFiles( sURL, pEvt->DialogResult );
1288 return 0L;