Update ooo320-m1
[ooovba.git] / svtools / source / contnr / templwin.cxx
blobe98e926d461bcf647c175b5dd84d690154306dc9
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: templwin.cxx,v $
10 * $Revision: 1.82.58.2 $
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_svtools.hxx"
33 #include "templwin.hxx"
34 #include "templdlg.hxx"
35 #include <svtools/svtdata.hxx>
36 #include <svtools/pathoptions.hxx>
37 #include <svtools/dynamicmenuoptions.hxx>
38 #include <svtools/extendedsecurityoptions.hxx>
39 #include <svtools/xtextedt.hxx>
40 #include <svtools/inettype.hxx>
41 #include "imagemgr.hxx"
42 #include <svtools/miscopt.hxx>
43 #include "templatefoldercache.hxx"
44 #include "imgdef.hxx"
45 #include "txtattr.hxx"
46 #ifndef _SVTOOLS_HRC
47 #include <svtools/svtools.hrc>
48 #endif
49 #ifndef _SVTOOLS_TEMPLWIN_HRC
50 #include "templwin.hrc"
51 #endif
52 #ifndef _SVT_HELPID_HRC
53 #include <svtools/helpid.hrc>
54 #endif
55 #include <svtools/pathoptions.hxx>
56 #include <svtools/viewoptions.hxx>
57 #include <unotools/ucbhelper.hxx>
59 #include "unotools/configmgr.hxx"
60 #include <com/sun/star/awt/XWindow.hpp>
61 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
62 #include <com/sun/star/frame/XFrame.hpp>
63 #include <toolkit/helper/vclunohelper.hxx>
64 #include <com/sun/star/util/URL.hpp>
65 #include <com/sun/star/util/XURLTransformer.hpp>
66 #include <com/sun/star/util/XOfficeInstallationDirectories.hpp>
67 #include <com/sun/star/frame/XDispatchProvider.hpp>
68 #include <com/sun/star/frame/XDocumentTemplates.hpp>
69 #include <com/sun/star/frame/XComponentLoader.hpp>
70 #include <com/sun/star/beans/PropertyValue.hpp>
71 #include <com/sun/star/ucb/XContent.hpp>
72 #include <com/sun/star/ucb/XCommandEnvironment.hpp>
73 #include <com/sun/star/view/XPrintable.hpp>
74 #include <com/sun/star/awt/XWindow.hpp>
75 #include <com/sun/star/document/XDocumentProperties.hpp>
76 #include <com/sun/star/beans/XPropertySet.hpp>
77 #include <com/sun/star/beans/XMultiPropertySet.hpp>
78 #include <com/sun/star/beans/XPropertySetInfo.hpp>
79 #include <com/sun/star/io/IOException.hpp>
80 #include <com/sun/star/util/DateTime.hpp>
81 #include <com/sun/star/script/XTypeConverter.hpp>
82 #include <com/sun/star/system/XSystemShellExecute.hpp>
83 #include <com/sun/star/system/SystemShellExecuteFlags.hpp>
84 #include <unotools/localedatawrapper.hxx>
85 #include <com/sun/star/container/XNameContainer.hpp>
86 #include <vcl/waitobj.hxx>
87 #include <comphelper/processfactory.hxx>
88 #include <tools/urlobj.hxx>
89 #include <tools/datetime.hxx>
90 #include <vcl/svapp.hxx>
91 #include <vcl/split.hxx>
92 #include <vcl/msgbox.hxx>
93 #include "DocumentInfoPreview.hxx"
94 #include <vcl/mnemonic.hxx>
96 #include <ucbhelper/content.hxx>
97 #include <comphelper/string.hxx>
100 using namespace ::com::sun::star;
101 using namespace ::com::sun::star::beans;
102 using namespace ::com::sun::star::container;
103 using namespace ::com::sun::star::frame;
104 using namespace ::com::sun::star::document;
105 using namespace ::com::sun::star::lang;
106 using namespace ::com::sun::star::ucb;
107 using namespace ::com::sun::star::uno;
108 using namespace ::com::sun::star::view;
109 using namespace svtools;
111 extern ::rtl::OUString CreateExactSizeText_Impl( sal_Int64 nSize ); // fileview.cxx
112 #define aSeparatorStr "----------------------------------"
114 #define SPLITSET_ID 0
115 #define COLSET_ID 1
116 #define ICONWIN_ID 2
117 #define FILEWIN_ID 3
118 #define FRAMEWIN_ID 4
120 #define ICON_POS_NEWDOC 0
121 #define ICON_POS_TEMPLATES 1
122 #define ICON_POS_MYDOCS 2
123 #define ICON_POS_SAMPLES 3
125 #define ASCII_STR(s) ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(s) )
126 #define VIEWSETTING_NEWFROMTEMPLATE ASCII_STR("NewFromTemplate")
127 #define VIEWSETTING_SELECTEDGROUP ASCII_STR("SelectedGroup")
128 #define VIEWSETTING_SELECTEDVIEW ASCII_STR("SelectedView")
129 #define VIEWSETTING_SPLITRATIO ASCII_STR("SplitRatio")
130 #define VIEWSETTING_LASTFOLDER ASCII_STR("LastFolder")
132 struct FolderHistory
134 String m_sURL;
135 ULONG m_nGroup;
137 FolderHistory( const String& _rURL, sal_Int32 _nGroup ) :
138 m_sURL( _rURL ), m_nGroup( _nGroup ) {}
141 DECLARE_LIST( HistoryList_Impl, FolderHistory* )
142 DECLARE_LIST( NewDocList_Impl, ::rtl::OUString* )
144 ODocumentInfoPreview::ODocumentInfoPreview( Window* pParent ,WinBits _nBits) : Window(pParent,WB_DIALOGCONTROL)
146 m_pEditWin = new SvtExtendedMultiLineEdit_Impl(this,_nBits);
147 m_pEditWin->Show();
148 m_pEditWin->EnableCursor( FALSE );
149 m_pInfoTable = new SvtDocInfoTable_Impl();
150 // detect application language
151 m_aLocale = SvtPathOptions().GetLocale();
153 // -----------------------------------------------------------------------------
154 ODocumentInfoPreview::~ODocumentInfoPreview()
156 delete m_pEditWin;
157 delete m_pInfoTable;
159 // -----------------------------------------------------------------------------
160 void ODocumentInfoPreview::Resize()
162 Size aOutputSize( GetOutputSize() );
163 m_pEditWin->SetPosSizePixel( Point(0,0),aOutputSize);
165 // -----------------------------------------------------------------------------
166 void ODocumentInfoPreview::Clear()
168 m_pEditWin->Clear();
170 // -----------------------------------------------------------------------------
172 void lcl_insertDateTimeEntry(SvtExtendedMultiLineEdit_Impl* i_pEditWin,
173 const ::rtl::OUString & i_rName, const util::DateTime & i_rUDT)
175 DateTime aToolsDT =
176 DateTime( Date( i_rUDT.Day, i_rUDT.Month, i_rUDT.Year ),
177 Time( i_rUDT.Hours, i_rUDT.Minutes,
178 i_rUDT.Seconds, i_rUDT.HundredthSeconds ) );
179 if ( aToolsDT.IsValid() )
181 LocaleDataWrapper aLocaleWrapper(
182 ::comphelper::getProcessServiceFactory(),
183 Application::GetSettings().GetLocale() );
184 String aDateStr = aLocaleWrapper.getDate( aToolsDT );
185 aDateStr += String( RTL_CONSTASCII_STRINGPARAM(", ") );
186 aDateStr += aLocaleWrapper.getTime( aToolsDT );
187 i_pEditWin->InsertEntry( i_rName, aDateStr );
191 void ODocumentInfoPreview::fill(
192 const Reference< XDocumentProperties >& i_xDocProps, const String& i_rURL)
194 if (!i_xDocProps.is()) throw RuntimeException();
196 ::rtl::OUString aStr;
197 m_pEditWin->SetAutoScroll( FALSE );
199 aStr = i_xDocProps->getTitle();
200 if (aStr.getLength()) {
201 m_pEditWin->InsertEntry( m_pInfoTable->GetString( DI_TITLE ), aStr );
204 aStr = i_xDocProps->getAuthor();
205 if (aStr.getLength()) {
206 m_pEditWin->InsertEntry( m_pInfoTable->GetString( DI_FROM ), aStr );
209 lcl_insertDateTimeEntry(m_pEditWin,
210 m_pInfoTable->GetString( DI_DATE ),
211 i_xDocProps->getCreationDate());
213 aStr = i_xDocProps->getModifiedBy();
214 if (aStr.getLength()) {
215 m_pEditWin->InsertEntry( m_pInfoTable->GetString(DI_MODIFIEDBY), aStr );
218 lcl_insertDateTimeEntry(m_pEditWin,
219 m_pInfoTable->GetString( DI_MODIFIEDDATE ),
220 i_xDocProps->getModificationDate());
222 aStr = i_xDocProps->getPrintedBy();
223 if (aStr.getLength()) {
224 m_pEditWin->InsertEntry( m_pInfoTable->GetString( DI_PRINTBY ), aStr );
227 lcl_insertDateTimeEntry(m_pEditWin,
228 m_pInfoTable->GetString( DI_PRINTDATE ),
229 i_xDocProps->getPrintDate());
231 aStr = i_xDocProps->getSubject();
232 if (aStr.getLength()) {
233 m_pEditWin->InsertEntry( m_pInfoTable->GetString( DI_THEME ), aStr );
236 aStr =
237 ::comphelper::string::convertCommaSeparated(i_xDocProps->getKeywords());
238 if (aStr.getLength()) {
239 m_pEditWin->InsertEntry( m_pInfoTable->GetString( DI_KEYWORDS ), aStr );
242 aStr = i_xDocProps->getDescription();
243 if (aStr.getLength()) {
244 m_pEditWin->InsertEntry( m_pInfoTable->GetString( DI_DESCRIPTION ),
245 aStr );
248 // size
249 if ( i_rURL.Len() > 0 )
251 ULONG nDocSize = ::utl::UCBContentHelper::GetSize( i_rURL );
252 m_pEditWin->InsertEntry(
253 m_pInfoTable->GetString( DI_SIZE ),
254 CreateExactSizeText_Impl( nDocSize ) );
257 // MIMEType
258 if ( i_rURL.Len() > 0 )
260 INetContentType eTypeID =
261 INetContentTypes::GetContentTypeFromURL( i_rURL );
262 if ( eTypeID != CONTENT_TYPE_APP_OCTSTREAM ) {
263 aStr = INetContentTypes::GetPresentation( eTypeID, m_aLocale );
264 } else {
265 aStr = SvFileInformationManager::GetDescription(
266 INetURLObject(i_rURL) );
268 if (aStr.getLength()) {
269 m_pEditWin->InsertEntry( m_pInfoTable->GetString( DI_MIMETYPE ),
270 aStr );
274 // user-defined (custom) properties
275 Reference< XPropertySet > xUserDefined(
276 i_xDocProps->getUserDefinedProperties(), UNO_QUERY_THROW );
277 Reference< XPropertySetInfo > xUDInfo = xUserDefined->getPropertySetInfo();
278 Sequence< Property > props = xUDInfo->getProperties();
279 for (sal_Int32 i = 0; i < props.getLength(); ++i) {
280 const ::rtl::OUString name = props[i].Name;
281 uno::Any aAny;
282 try {
283 aAny = xUserDefined->getPropertyValue(name);
284 uno::Reference < script::XTypeConverter > xConverter(
285 comphelper::getProcessServiceFactory()->createInstance(
286 ASCII_STR("com.sun.star.script.Converter")),
287 UNO_QUERY );
288 uno::Any aNew;
289 aNew = xConverter->convertToSimpleType( aAny, TypeClass_STRING );
290 if ((aNew >>= aStr) && aStr.getLength()) {
291 m_pEditWin->InsertEntry( name, aStr);
293 } catch (uno::Exception &) {
294 // ignore
298 m_pEditWin->SetSelection( Selection( 0, 0 ) );
299 m_pEditWin->SetAutoScroll( TRUE );
302 // -----------------------------------------------------------------------------
303 void ODocumentInfoPreview::InsertEntry( const String& rTitle, const String& rValue )
305 m_pEditWin->InsertEntry( rTitle, rValue);
307 // -----------------------------------------------------------------------------
309 // class SvtDummyHeaderBar_Impl ------------------------------------------
311 void SvtDummyHeaderBar_Impl::UpdateBackgroundColor()
313 SetBackground( Wallpaper( GetSettings().GetStyleSettings().GetWindowColor() ) );
316 SvtDummyHeaderBar_Impl::SvtDummyHeaderBar_Impl( Window* pPar ) : Window( pPar )
318 SetSizePixel( HeaderBar( this, 0 ).CalcWindowSizePixel() ); // HeaderBar used only to calculate size
320 UpdateBackgroundColor();
323 SvtDummyHeaderBar_Impl::~SvtDummyHeaderBar_Impl()
327 void SvtDummyHeaderBar_Impl::DataChanged( const DataChangedEvent& r )
329 Window::DataChanged( r );
330 if( r.GetType() == DATACHANGED_SETTINGS )
331 UpdateBackgroundColor();
334 // class SvtIconWindow_Impl ----------------------------------------------
336 SvtIconWindow_Impl::SvtIconWindow_Impl( Window* pParent ) :
338 Window( pParent, WB_DIALOGCONTROL | WB_BORDER | WB_3DLOOK ),
340 aDummyHeaderBar( this ),
341 aIconCtrl( this, WB_ICON | WB_NOCOLUMNHEADER | WB_HIGHLIGHTFRAME | /*!WB_NOSELECTION |*/
342 WB_NODRAGSELECTION | WB_TABSTOP | WB_CLIPCHILDREN ),
343 aNewDocumentRootURL( ASCII_STR("private:newdoc") ),
344 aMyDocumentsRootURL( SvtPathOptions().GetWorkPath() ),
345 aSamplesFolderRootURL( SvtPathOptions().
346 SubstituteVariable( String( ASCII_STR("$(insturl)/share/samples/$(vlang)") ) ) ),
347 nMaxTextLength( 0 )
350 aDummyHeaderBar.Show();
352 aIconCtrl.SetAccessibleName( String( RTL_CONSTASCII_USTRINGPARAM("Groups") ) );
353 aIconCtrl.SetHelpId( HID_TEMPLATEDLG_ICONCTRL );
354 aIconCtrl.SetChoiceWithCursor( TRUE );
355 aIconCtrl.SetSelectionMode( SINGLE_SELECTION );
356 aIconCtrl.Show();
358 // detect the root URL of templates
359 Reference< XDocumentTemplates > xTemplates( ::comphelper::getProcessServiceFactory()->
360 createInstance( ASCII_STR("com.sun.star.frame.DocumentTemplates") ), UNO_QUERY );
362 if ( xTemplates.is() )
364 Reference < XContent > aRootContent = xTemplates->getContent();
365 Reference < XCommandEnvironment > aCmdEnv;
367 if ( aRootContent.is() )
368 aTemplateRootURL = aRootContent->getIdentifier()->getContentIdentifier();
371 // insert the categories
372 // "New Document"
373 sal_Bool bHiContrast = GetBackground().GetColor().IsDark();
374 Image aImage( SvtResId( bHiContrast ? IMG_SVT_NEWDOC_HC : IMG_SVT_NEWDOC ) );
375 nMaxTextLength = aImage.GetSizePixel().Width();
376 String aEntryStr = String( SvtResId( STR_SVT_NEWDOC ) );
377 SvxIconChoiceCtrlEntry* pEntry =
378 aIconCtrl.InsertEntry( aEntryStr, aImage, ICON_POS_NEWDOC );
379 pEntry->SetUserData( new String( aNewDocumentRootURL ) );
380 pEntry->SetQuickHelpText( String( SvtResId( STR_SVT_NEWDOC_HELP ) ) );
381 DBG_ASSERT( !pEntry->GetBoundRect().IsEmpty(), "empty rectangle" );
382 long nTemp = pEntry->GetBoundRect().GetSize().Width();
383 if (nTemp > nMaxTextLength)
384 nMaxTextLength = nTemp;
386 // "Templates"
387 if( aTemplateRootURL.Len() > 0 )
389 aEntryStr = String( SvtResId( STR_SVT_TEMPLATES ) );
390 pEntry = aIconCtrl.InsertEntry(
391 aEntryStr, Image( SvtResId( bHiContrast ? IMG_SVT_TEMPLATES_HC : IMG_SVT_TEMPLATES ) ), ICON_POS_TEMPLATES );
392 pEntry->SetUserData( new String( aTemplateRootURL ) );
393 pEntry->SetQuickHelpText( String( SvtResId( STR_SVT_TEMPLATES_HELP ) ) );
394 DBG_ASSERT( !pEntry->GetBoundRect().IsEmpty(), "empty rectangle" );
395 nTemp = pEntry->GetBoundRect().GetSize().Width();
396 if (nTemp > nMaxTextLength)
397 nMaxTextLength = nTemp;
400 // "My Documents"
401 aEntryStr = String( SvtResId( STR_SVT_MYDOCS ) );
402 pEntry = aIconCtrl.InsertEntry(
403 aEntryStr, Image( SvtResId( bHiContrast ? IMG_SVT_MYDOCS_HC : IMG_SVT_MYDOCS ) ), ICON_POS_MYDOCS );
404 pEntry->SetUserData( new String( aMyDocumentsRootURL ) );
405 pEntry->SetQuickHelpText( String( SvtResId( STR_SVT_MYDOCS_HELP ) ) );
406 DBG_ASSERT( !pEntry->GetBoundRect().IsEmpty(), "empty rectangle" );
407 nTemp = pEntry->GetBoundRect().GetSize().Width();
408 if( nTemp > nMaxTextLength )
409 nMaxTextLength = nTemp;
411 // "Samples"
412 aEntryStr = String( SvtResId( STR_SVT_SAMPLES ) );
413 pEntry = aIconCtrl.InsertEntry(
414 aEntryStr, Image( SvtResId( bHiContrast ? IMG_SVT_SAMPLES_HC : IMG_SVT_SAMPLES ) ), ICON_POS_SAMPLES );
415 pEntry->SetUserData( new String( aSamplesFolderRootURL ) );
416 pEntry->SetQuickHelpText( String( SvtResId( STR_SVT_SAMPLES_HELP ) ) );
417 DBG_ASSERT( !pEntry->GetBoundRect().IsEmpty(), "empty rectangle" );
418 nTemp = pEntry->GetBoundRect().GetSize().Width();
419 if (nTemp > nMaxTextLength)
420 nMaxTextLength = nTemp;
422 aIconCtrl.CreateAutoMnemonics();
425 SvtIconWindow_Impl::~SvtIconWindow_Impl()
427 for ( ULONG i = 0; i < aIconCtrl.GetEntryCount(); ++i )
429 SvxIconChoiceCtrlEntry* pEntry = aIconCtrl.GetEntry( i );
430 delete (String*)pEntry->GetUserData();
434 SvxIconChoiceCtrlEntry* SvtIconWindow_Impl::GetEntry( const String& rURL ) const
436 SvxIconChoiceCtrlEntry* pEntry = NULL;
437 for ( ULONG i = 0; i < aIconCtrl.GetEntryCount(); ++i )
439 SvxIconChoiceCtrlEntry* pTemp = aIconCtrl.GetEntry( i );
440 String aURL( *( (String*)pTemp->GetUserData() ) );
441 if ( aURL == rURL )
443 pEntry = pTemp;
444 break;
448 return pEntry;
451 void SvtIconWindow_Impl::Resize()
453 Size aWinSize = GetOutputSizePixel();
454 Size aHeaderSize = aDummyHeaderBar.GetSizePixel();
455 aHeaderSize.Width() = aWinSize.Width();
456 aDummyHeaderBar.SetSizePixel( aHeaderSize );
457 long nHeaderHeight = aHeaderSize.Height();
458 aWinSize.Height() -= nHeaderHeight;
459 aIconCtrl.SetPosSizePixel( Point( 0, nHeaderHeight ), aWinSize );
460 aIconCtrl.ArrangeIcons();
463 String SvtIconWindow_Impl::GetCursorPosIconURL() const
465 String aURL;
466 SvxIconChoiceCtrlEntry* pEntry = aIconCtrl.GetCursor( );
467 if ( pEntry )
468 aURL = *static_cast<String*>(pEntry->GetUserData());
469 return aURL;
473 String SvtIconWindow_Impl::GetSelectedIconURL() const
475 ULONG nPos;
476 SvxIconChoiceCtrlEntry* pEntry = aIconCtrl.GetSelectedEntry( nPos );
477 String aURL;
478 if ( pEntry )
479 aURL = *static_cast<String*>(pEntry->GetUserData());
480 return aURL;
483 String SvtIconWindow_Impl::GetSelectedIconText() const
485 ULONG nPos;
486 return MnemonicGenerator::EraseAllMnemonicChars( aIconCtrl.GetSelectedEntry( nPos )->GetText() );
489 String SvtIconWindow_Impl::GetIconText( const String& rURL ) const
491 String aText;
492 SvxIconChoiceCtrlEntry* pEntry = GetEntry( rURL );
493 if ( pEntry )
494 aText = MnemonicGenerator::EraseAllMnemonicChars( pEntry->GetText() );
495 return aText;
498 void SvtIconWindow_Impl::InvalidateIconControl()
500 aIconCtrl.Invalidate();
503 ULONG SvtIconWindow_Impl::GetCursorPos() const
505 ULONG nPos = ~ULONG(0);
507 SvxIconChoiceCtrlEntry* pCursorEntry = aIconCtrl.GetCursor( );
508 if ( pCursorEntry )
509 nPos = aIconCtrl.GetEntryListPos( pCursorEntry );
511 return nPos;
514 ULONG SvtIconWindow_Impl::GetSelectEntryPos() const
516 ULONG nPos;
517 if ( !aIconCtrl.GetSelectedEntry( nPos ) )
518 nPos = ~ULONG(0);
519 return nPos;
522 void SvtIconWindow_Impl::SetCursorPos( ULONG nPos )
524 SvxIconChoiceCtrlEntry* pEntry = aIconCtrl.GetEntry( nPos );
525 aIconCtrl.SetCursor( pEntry );
526 aIconCtrl.Invalidate();
527 aIconCtrl.Update();
530 void SvtIconWindow_Impl::SetFocus()
532 aIconCtrl.GrabFocus();
535 long SvtIconWindow_Impl::CalcHeight() const
537 // calculate the required height of the IconControl
538 long nHeight = 0;
539 ULONG nCount = aIconCtrl.GetEntryCount();
540 if ( nCount > 0 )
541 // bottom of the last icon
542 nHeight = aIconCtrl.GetEntry(nCount-1)->GetBoundRect().Bottom();
544 // + headerbar height
545 nHeight += aDummyHeaderBar.GetSizePixel().Height();
547 return nHeight;
550 sal_Bool SvtIconWindow_Impl::IsRootURL( const String& rURL ) const
552 return rURL == aNewDocumentRootURL ||
553 rURL == aTemplateRootURL ||
554 rURL == aMyDocumentsRootURL ||
555 rURL == aSamplesFolderRootURL;
558 ULONG SvtIconWindow_Impl::GetRootPos( const String& rURL ) const
560 ULONG nPos = ~ULONG(0);
561 if ( aNewDocumentRootURL.Match( rURL ) == STRING_MATCH )
562 nPos = 0;
563 else if ( aTemplateRootURL.Match( rURL ) == STRING_MATCH )
564 nPos = 1;
565 else if ( aMyDocumentsRootURL.Match( rURL ) == STRING_MATCH )
566 nPos = 2;
567 else if ( aSamplesFolderRootURL.Match( rURL ) == STRING_MATCH )
568 nPos = 3;
569 else if ( rURL.Match( aMyDocumentsRootURL ) == STRING_MATCH )
570 nPos = 2;
571 else
573 DBG_WARNING( "SvtIconWindow_Impl::GetRootPos(): invalid position" );
574 nPos = 2;
577 return nPos;
580 void SvtIconWindow_Impl::UpdateIcons( sal_Bool _bHiContrast )
582 aIconCtrl.GetEntry( ICON_POS_NEWDOC )->SetImage(
583 Image( SvtResId( _bHiContrast ? IMG_SVT_NEWDOC_HC : IMG_SVT_NEWDOC ) ) );
584 aIconCtrl.GetEntry( ICON_POS_TEMPLATES )->SetImage(
585 Image( SvtResId( _bHiContrast ? IMG_SVT_TEMPLATES_HC : IMG_SVT_TEMPLATES ) ) );
586 aIconCtrl.GetEntry( ICON_POS_MYDOCS )->SetImage(
587 Image( SvtResId( _bHiContrast ? IMG_SVT_MYDOCS_HC : IMG_SVT_MYDOCS ) ) );
588 aIconCtrl.GetEntry( ICON_POS_SAMPLES )->SetImage(
589 Image( SvtResId( _bHiContrast ? IMG_SVT_SAMPLES_HC : IMG_SVT_SAMPLES ) ) );
591 /* -----------------27.11.2002 16:58-----------------
593 * --------------------------------------------------*/
594 void SvtIconWindow_Impl::SelectFolder(sal_Int32 nFolderPosition)
596 SvxIconChoiceCtrlEntry* pEntry = aIconCtrl.GetEntry( nFolderPosition );
597 if(pEntry)
599 aIconCtrl.SetCursor( pEntry );
600 aIconCtrl.GetClickHdl().Call(&aIconCtrl);
604 // class SvtFileViewWindow_Impl -----------------------------------------_
606 SvtFileViewWindow_Impl::SvtFileViewWindow_Impl( SvtTemplateWindow* pParent ) :
608 Window( pParent, WB_DIALOGCONTROL | WB_TABSTOP | WB_BORDER | WB_3DLOOK ),
610 rParent ( *pParent ),
611 aFileView ( this, SvtResId( CTRL_FILEVIEW ), FILEVIEW_SHOW_NONE ),
612 bIsTemplateFolder ( sal_False )
615 aFileView.SetStyle( aFileView.GetStyle() | WB_DIALOGCONTROL | WB_TABSTOP );
616 aFileView.SetHelpId( HID_TEMPLATEDLG_FILEVIEW );
617 aFileView.Show();
618 aFileView.SetPosPixel( Point( 0, 0 ) );
619 aFileView.EnableAutoResize();
620 aFileView.EnableContextMenu( sal_False );
621 aFileView.EnableDelete( sal_False );
624 SvtFileViewWindow_Impl::~SvtFileViewWindow_Impl()
628 void GetMenuEntry_Impl
630 Sequence< PropertyValue >& aDynamicMenuEntry,
631 ::rtl::OUString& rTitle,
632 ::rtl::OUString& rURL,
633 ::rtl::OUString& rFrame,
634 ::rtl::OUString& rImageId
637 for ( int i = 0; i < aDynamicMenuEntry.getLength(); i++ )
639 if ( aDynamicMenuEntry[i].Name == DYNAMICMENU_PROPERTYNAME_URL )
640 aDynamicMenuEntry[i].Value >>= rURL;
641 else if ( aDynamicMenuEntry[i].Name == DYNAMICMENU_PROPERTYNAME_TITLE )
642 aDynamicMenuEntry[i].Value >>= rTitle;
643 else if ( aDynamicMenuEntry[i].Name == DYNAMICMENU_PROPERTYNAME_IMAGEIDENTIFIER )
644 aDynamicMenuEntry[i].Value >>= rImageId;
645 else if ( aDynamicMenuEntry[i].Name == DYNAMICMENU_PROPERTYNAME_TARGETNAME )
646 aDynamicMenuEntry[i].Value >>= rFrame;
649 Sequence< ::rtl::OUString > SvtFileViewWindow_Impl::GetNewDocContents() const
651 NewDocList_Impl aNewDocs;
652 Sequence< Sequence< PropertyValue > > aDynamicMenuEntries;
653 aDynamicMenuEntries = SvtDynamicMenuOptions().GetMenu( E_NEWMENU );
655 ::rtl::OUString aTitle;
656 ::rtl::OUString aURL;
657 ::rtl::OUString aImageURL;
658 ::rtl::OUString aTargetFrame;
660 UINT32 i, nCount = aDynamicMenuEntries.getLength();
661 ::rtl::OUString sSeparator( ASCII_STR("private:separator") );
662 ::rtl::OUString sSlotURL( ASCII_STR("slot:5500") );
664 for ( i = 0; i < nCount; ++i )
666 GetMenuEntry_Impl( aDynamicMenuEntries[i], aTitle, aURL, aTargetFrame, aImageURL );
667 if( aURL == sSlotURL )
668 continue;
669 if( aURL == sSeparator )
671 String aSeparator( ASCII_STR( aSeparatorStr ) );
672 ::rtl::OUString* pSeparator = new ::rtl::OUString( aSeparator );
673 aNewDocs.Insert( pSeparator, LIST_APPEND );
675 else
677 // title
678 String aRow = MnemonicGenerator::EraseAllMnemonicChars( String( aTitle ) );
679 aRow += '\t';
680 // no type
681 aRow += '\t';
682 // no size
683 aRow += '\t';
684 // no date
685 aRow += '\t';
686 // url
687 aRow += String( aURL );
688 aRow += '\t';
689 // folder == false
690 aRow += '0';
691 // image url?
692 if ( aImageURL.getLength() > 0 )
694 aRow += '\t';
695 aRow += String( aImageURL );
698 ::rtl::OUString* pRow = new ::rtl::OUString( aRow );
699 aNewDocs.Insert( pRow, LIST_APPEND );
703 nCount = aNewDocs.Count();
704 Sequence < ::rtl::OUString > aRet( nCount );
705 ::rtl::OUString* pRet = aRet.getArray();
706 for ( i = 0; i < nCount; ++i )
708 ::rtl::OUString* pNewDoc = aNewDocs.GetObject(i);
709 pRet[i] = *( pNewDoc );
710 delete pNewDoc;
713 return aRet;
716 void SvtFileViewWindow_Impl::Resize()
718 Size aWinSize = GetOutputSizePixel();
720 static int x = 0;
721 static int y = 0;
723 aWinSize.nA += x;
724 aWinSize.nB += y;
725 aFileView.SetSizePixel( aWinSize );
728 String SvtFileViewWindow_Impl::GetSelectedFile() const
730 return aFileView.GetCurrentURL();
733 void SvtFileViewWindow_Impl::OpenFolder( const String& rURL )
735 aFolderURL = rURL;
737 rParent.SetPrevLevelButtonState( rURL );
739 aFileView.SetUrlFilter( &aURLFilter );
741 INetProtocol eProt = INetURLObject( rURL ).GetProtocol();
742 bIsTemplateFolder = ( eProt == INET_PROT_VND_SUN_STAR_HIER );
743 bool isNewDocumentFolder = ( eProt == INET_PROT_PRIVATE );
745 aURLFilter.enableFilter( !bIsTemplateFolder && !isNewDocumentFolder );
747 if ( isNewDocumentFolder )
749 aFileView.EnableNameReplacing( sal_False );
750 aFileView.Initialize( GetNewDocContents() );
752 else
754 xub_StrLen nSampFoldLen = aSamplesFolderURL.Len();
755 aFileView.EnableNameReplacing(
756 nSampFoldLen && rURL.CompareTo( aSamplesFolderURL, nSampFoldLen ) == COMPARE_EQUAL );
757 aFileView.Initialize( rURL, String(), NULL );
759 aNewFolderLink.Call( this );
762 sal_Bool SvtFileViewWindow_Impl::HasPreviousLevel( String& rURL ) const
764 INetURLObject aViewObj( aFileView.GetViewURL() );
765 INetURLObject aRootObj( aCurrentRootURL );
766 INetURLObject aMyDocObj( aMyDocumentsURL );
768 return ( ( aViewObj != aRootObj || aRootObj == aMyDocObj ) && aFileView.GetParentURL( rURL ) );
771 String SvtFileViewWindow_Impl::GetFolderTitle() const
773 String aTitle;
774 ::utl::UCBContentHelper::GetTitle( aFolderURL, aTitle );
775 return aTitle;
778 void SvtFileViewWindow_Impl::SetFocus()
780 aFileView.SetFocus();
783 // class SvtDocInfoTable_Impl --------------------------------------------
785 SvtDocInfoTable_Impl::SvtDocInfoTable_Impl() :
787 ResStringArray( SvtResId( STRARY_SVT_DOCINFO ) )
791 // -----------------------------------------------------------------------------
792 // class SvtExtendedMultiLineEdit_Impl --------------------------------------------
793 SvtExtendedMultiLineEdit_Impl::SvtExtendedMultiLineEdit_Impl( Window* pParent,WinBits _nBits ) :
795 ExtMultiLineEdit( pParent, _nBits )
798 SetLeftMargin( 10 );
800 // -----------------------------------------------------------------------------
801 void SvtExtendedMultiLineEdit_Impl::InsertEntry( const String& rTitle, const String& rValue )
803 String aText( '\n' );
804 aText += rTitle;
805 aText += ':';
806 InsertText( aText );
807 ULONG nPara = GetParagraphCount() - 1;
808 SetAttrib( TextAttribFontWeight( WEIGHT_BOLD ), nPara, 0, aText.Len() );
810 aText = '\n';
811 aText += rValue;
812 InsertText( aText );
813 nPara = GetParagraphCount() - 1;
814 SetAttrib( TextAttribFontWeight( WEIGHT_NORMAL ), nPara, 0, aText.Len() );
816 InsertText( String( '\n' ) );
818 // -----------------------------------------------------------------------------
820 // -----------------------------------------------------------------------
822 const String& SvtDocInfoTable_Impl::GetString( long nId ) const
824 sal_uInt32 nPos( FindIndex( nId ) );
826 if ( RESARRAY_INDEX_NOTFOUND != nPos )
827 return ResStringArray::GetString( nPos );
828 else
829 return aEmptyString;
832 // class SvtFrameWindow_Impl ---------------------------------------------
834 SvtFrameWindow_Impl::SvtFrameWindow_Impl( Window* pParent ) :
836 Window( pParent )
839 // detect application language
840 aLocale= SvtPathOptions().GetLocale();
842 // create windows and frame
843 pEditWin = new ODocumentInfoPreview( this ,WB_LEFT | WB_VSCROLL | WB_READONLY | WB_BORDER | WB_3DLOOK);
844 pTextWin = new Window( this );
845 xFrame = Reference < XFrame > ( ::comphelper::getProcessServiceFactory()->
846 createInstance( ASCII_STR("com.sun.star.frame.Frame") ), UNO_QUERY );
847 xWindow = VCLUnoHelper::GetInterface( pTextWin );
848 xFrame->initialize( xWindow );
850 // create docinfo instance
851 m_xDocProps.set( ::comphelper::getProcessServiceFactory()->createInstance(
852 ASCII_STR("com.sun.star.document.DocumentProperties") ),
853 UNO_QUERY );
855 pEmptyWin = new Window( this, WB_BORDER | WB_3DLOOK );
858 SvtFrameWindow_Impl::~SvtFrameWindow_Impl()
860 delete pEditWin;
861 delete pEmptyWin;
862 xFrame->dispose();
865 void SvtFrameWindow_Impl::ViewEditWin()
867 pEmptyWin->Hide();
868 xWindow->setVisible( sal_False );
869 pTextWin->Hide();
870 pEditWin->Show();
873 void SvtFrameWindow_Impl::ViewTextWin()
875 pEmptyWin->Hide();
876 pEditWin->Hide();
877 xWindow->setVisible( sal_True );
878 pTextWin->Show();
881 void SvtFrameWindow_Impl::ViewEmptyWin()
883 xWindow->setVisible( sal_False );
884 pTextWin->Hide();
885 pEditWin->Hide();
886 pEmptyWin->Show();
889 void SvtFrameWindow_Impl::ViewNonEmptyWin()
891 if( bDocInfo )
892 ViewEditWin();
893 else
894 ViewTextWin();
897 IMPL_STATIC_LINK_NOINSTANCE( SvtFrameWindow_Impl, ExecuteHdl_Impl, SvtExecuteInfo*, pExecuteInfo )
901 pExecuteInfo->xDispatch->dispatch( pExecuteInfo->aTargetURL, Sequence < PropertyValue >() );
903 catch ( Exception& )
907 delete pExecuteInfo;
908 return 0;
911 void SvtFrameWindow_Impl::ShowDocInfo( const String& rURL )
915 uno::Reference < task::XInteractionHandler > xInteractionHandler( ::comphelper::getProcessServiceFactory()->createInstance(
916 ::rtl::OUString::createFromAscii("com.sun.star.task.InteractionHandler") ), uno::UNO_QUERY );
917 uno::Sequence < beans::PropertyValue> aProps(1);
918 aProps[0].Name = ::rtl::OUString::createFromAscii("InteractionHandler");
919 aProps[0].Value <<= xInteractionHandler;
920 m_xDocProps->loadFromMedium( rURL, aProps );
921 pEditWin->fill( m_xDocProps, rURL );
923 catch ( UnknownPropertyException& ) {}
924 catch ( Exception& ) {}
927 void SvtFrameWindow_Impl::Resize()
929 Size aWinSize = GetOutputSizePixel();
930 pEditWin->SetSizePixel( aWinSize );
931 pTextWin->SetSizePixel( aWinSize );
932 pEmptyWin->SetSizePixel( aWinSize );
935 void SvtFrameWindow_Impl::OpenFile( const String& rURL, sal_Bool bPreview, sal_Bool bIsTemplate, sal_Bool bAsTemplate )
937 if ( bPreview )
938 aCurrentURL = rURL;
940 ViewNonEmptyWin();
941 pEditWin->Clear();
943 if ( rURL.Len() > 0 && bPreview && m_xDocProps.is() )
944 ShowDocInfo( rURL );
946 if ( rURL.Len() == 0 )
948 xFrame->setComponent( Reference < com::sun::star::awt::XWindow >(), Reference < XController >() );
949 ViewEmptyWin();
951 else if ( !::utl::UCBContentHelper::IsFolder( rURL ) )
953 com::sun::star::util::URL aURL;
954 aURL.Complete = rURL;
955 Reference < com::sun::star::util::XURLTransformer > xTrans( ::comphelper::getProcessServiceFactory()->
956 createInstance( ASCII_STR("com.sun.star.util.URLTransformer" ) ), UNO_QUERY );
957 xTrans->parseStrict( aURL );
959 String aTarget;
960 Reference < XDispatchProvider > xProv( xFrame, UNO_QUERY );
961 if ( bPreview )
962 aTarget = ASCII_STR("_self");
963 else
965 // can be removed if the database application change its URL
966 String sServiceScheme( RTL_CONSTASCII_STRINGPARAM( "service:" ) );
967 if ( rURL.Match( sServiceScheme ) != sServiceScheme.Len() )
968 // service URL has no default target
969 aTarget = ASCII_STR("_default");
970 xProv = Reference < XDispatchProvider >( ::comphelper::getProcessServiceFactory()->
971 createInstance( ASCII_STR("com.sun.star.frame.Desktop") ), UNO_QUERY );
974 Reference < XDispatch > xDisp = xProv.is() ?
975 xProv->queryDispatch( aURL, aTarget, 0 ) : Reference < XDispatch >();
977 if ( xDisp.is() )
979 if ( bPreview )
981 if ( m_aOpenURL != aURL.Complete )
983 WaitObject aWaitCursor( GetParent() );
984 // disabling must be done here, does not work in ctor because
985 // execute of the dialog will overwrite it
986 // ( own execute method would help )
987 pTextWin->EnableInput( FALSE, TRUE );
988 if ( pTextWin->IsReallyVisible() )
990 sal_Bool b = sal_True;
991 Sequence < PropertyValue > aArgs( 4 );
992 aArgs[0].Name = ASCII_STR("Preview");
993 aArgs[0].Value.setValue( &b, ::getBooleanCppuType() );
994 aArgs[1].Name = ASCII_STR("ReadOnly");
995 aArgs[1].Value.setValue( &b, ::getBooleanCppuType() );
996 aArgs[2].Name = ASCII_STR("AsTemplate"); // prevents getting an empty URL with getURL()!
998 uno::Reference < task::XInteractionHandler > xInteractionHandler( ::comphelper::getProcessServiceFactory()->createInstance(
999 ::rtl::OUString::createFromAscii("com.sun.star.task.InteractionHandler") ), uno::UNO_QUERY );
1000 aArgs[3].Name = ::rtl::OUString::createFromAscii("InteractionHandler");
1001 aArgs[3].Value <<= xInteractionHandler;
1003 b = sal_False;
1004 aArgs[2].Value.setValue( &b, ::getBooleanCppuType() );
1005 xDisp->dispatch( aURL, aArgs );
1007 ::rtl::OUString aDispURL;
1008 Reference< ::com::sun::star::frame::XController > xCtrl = xFrame->getController();
1009 if( xCtrl.is() )
1011 Reference< ::com::sun::star::frame::XModel > xMdl = xCtrl->getModel();
1012 if( xMdl.is() )
1013 aDispURL = xMdl->getURL();
1016 if( aDispURL != aURL.Complete )
1018 xFrame->setComponent( Reference < com::sun::star::awt::XWindow >(), Reference < XController >() );
1019 ViewEmptyWin();
1020 m_aOpenURL = rtl::OUString();
1022 else
1023 m_aOpenURL = aDispURL;
1027 else if ( bIsTemplate )
1029 Sequence < PropertyValue > aArgs( 1 );
1030 aArgs[0].Name = ASCII_STR("AsTemplate");
1031 aArgs[0].Value <<= bAsTemplate;
1032 xDisp->dispatch( aURL, aArgs );
1033 m_aOpenURL = rtl::OUString();
1035 else
1038 SvtExecuteInfo* pExecuteInfo = new SvtExecuteInfo;
1039 pExecuteInfo->xDispatch = xDisp;
1040 pExecuteInfo->aTargetURL = aURL;
1041 Application::PostUserEvent(
1042 STATIC_LINK(0, SvtFrameWindow_Impl, ExecuteHdl_Impl), pExecuteInfo );
1044 Sequence < PropertyValue > aArgs;
1045 xDisp->dispatch( aURL, aArgs );
1046 m_aOpenURL = rtl::OUString();
1052 void SvtFrameWindow_Impl::ToggleView( sal_Bool bDI )
1054 bDocInfo = bDI;
1056 // view is set properly in OpenFile()
1058 OpenFile( aCurrentURL, sal_True, sal_False, sal_False );
1061 // class SvtTemplateWindow -----------------------------------------------
1063 SvtTemplateWindow::SvtTemplateWindow( Window* pParent ) :
1065 Window( pParent, WB_DIALOGCONTROL ),
1067 aFileViewTB ( this, SvtResId( TB_SVT_FILEVIEW ) ),
1068 aFrameWinTB ( this, SvtResId( TB_SVT_FRAMEWIN ) ),
1069 aSplitWin ( this, WB_DIALOGCONTROL | WB_NOSPLITDRAW ),
1070 pHistoryList ( NULL )
1073 // create windows
1074 pIconWin = new SvtIconWindow_Impl( this );
1075 pFileWin = new SvtFileViewWindow_Impl( this );
1076 pFileWin->SetMyDocumentsURL( pIconWin->GetMyDocumentsRootURL() );
1077 pFileWin->SetSamplesFolderURL( pIconWin->GetSamplesFolderURL() );
1078 pFrameWin = new SvtFrameWindow_Impl( this );
1080 // set handlers
1081 pIconWin->SetClickHdl( LINK( this, SvtTemplateWindow, IconClickHdl_Impl ) );
1082 pFileWin->SetSelectHdl( LINK( this, SvtTemplateWindow, FileSelectHdl_Impl ) );
1083 pFileWin->SetDoubleClickHdl( LINK( this, SvtTemplateWindow, FileDblClickHdl_Impl ) );
1084 pFileWin->SetNewFolderHdl( LINK( this, SvtTemplateWindow, NewFolderHdl_Impl ) );
1086 // create the split items
1087 aSplitWin.SetAlign( WINDOWALIGN_LEFT );
1088 long nWidth = pIconWin->GetMaxTextLength() * 8 / 7 + 1; // extra space for border
1089 aSplitWin.InsertItem( ICONWIN_ID, pIconWin, nWidth, SPLITWINDOW_APPEND, 0, SWIB_FIXED );
1090 aSplitWin.InsertItem( FILEWIN_ID, pFileWin, 50, SPLITWINDOW_APPEND, 0, SWIB_PERCENTSIZE );
1091 aSplitWin.InsertItem( FRAMEWIN_ID, pFrameWin, 50, SPLITWINDOW_APPEND, 0, SWIB_PERCENTSIZE );
1092 aSplitWin.SetSplitHdl( LINK( this, SvtTemplateWindow, ResizeHdl_Impl ) );
1094 // show the windows
1095 pIconWin->Show();
1096 pFileWin->Show();
1097 pFrameWin->Show();
1098 aSplitWin.Show();
1100 // initialize the timers
1101 aSelectTimer.SetTimeout( 200 );
1102 aSelectTimer.SetTimeoutHdl( LINK( this, SvtTemplateWindow, TimeoutHdl_Impl ) );
1104 // initialize the toolboxes and then show them
1105 InitToolBoxes();
1106 aFileViewTB.Show();
1107 aFrameWinTB.Show();
1109 ReadViewSettings( );
1111 Application::PostUserEvent( LINK( this, SvtTemplateWindow, ResizeHdl_Impl ) );
1114 // ------------------------------------------------------------------------
1116 SvtTemplateWindow::~SvtTemplateWindow()
1118 WriteViewSettings( );
1120 delete pIconWin;
1121 delete pFileWin;
1122 delete pFrameWin;
1123 if ( pHistoryList )
1125 for ( UINT32 i = 0; i < pHistoryList->Count(); ++i )
1126 delete pHistoryList->GetObject(i);
1127 delete pHistoryList;
1131 // ------------------------------------------------------------------------
1133 IMPL_LINK ( SvtTemplateWindow , IconClickHdl_Impl, SvtIconChoiceCtrl *, EMPTYARG )
1135 String aURL = pIconWin->GetSelectedIconURL();
1136 if ( !aURL.Len() )
1137 aURL = pIconWin->GetCursorPosIconURL();
1138 if ( pFileWin->GetRootURL() != aURL )
1140 pFileWin->OpenRoot( aURL );
1141 pIconWin->InvalidateIconControl();
1142 aFileViewTB.EnableItem( TI_DOCTEMPLATE_PRINT, FALSE );
1144 return 0;
1147 // ------------------------------------------------------------------------
1149 IMPL_LINK ( SvtTemplateWindow , FileSelectHdl_Impl, SvtFileView *, EMPTYARG )
1151 aSelectTimer.Start();
1152 return 0;
1155 // ------------------------------------------------------------------------
1157 IMPL_LINK ( SvtTemplateWindow , FileDblClickHdl_Impl, SvtFileView *, EMPTYARG )
1159 if ( aSelectTimer.IsActive() )
1160 aSelectTimer.Stop();
1162 String aURL = pFileWin->GetSelectedFile();
1163 if ( aURL.Len() > 0 )
1165 if ( ::utl::UCBContentHelper::IsFolder( aURL ) )
1166 pFileWin->OpenFolder( aURL );
1167 else
1168 aDoubleClickHdl.Call( this );
1171 return 0;
1174 // ------------------------------------------------------------------------
1176 IMPL_LINK ( SvtTemplateWindow , NewFolderHdl_Impl, SvtFileView *, EMPTYARG )
1178 pFrameWin->OpenFile( String(), sal_True, sal_False, sal_False );
1179 aFileViewTB.EnableItem( TI_DOCTEMPLATE_PRINT, FALSE );
1181 String sURL = pFileWin->GetFolderURL();
1182 ULONG nPos = pIconWin->GetRootPos( sURL );
1183 AppendHistoryURL( sURL, nPos );
1185 aNewFolderHdl.Call( this );
1186 return 0;
1189 // ------------------------------------------------------------------------
1191 IMPL_LINK ( SvtTemplateWindow , TimeoutHdl_Impl, Timer *, EMPTYARG )
1193 aSelectHdl.Call( this );
1194 String sURL = pFileWin->GetSelectedFile();
1195 sal_Bool bIsNewDoc = ( pIconWin->GetSelectEntryPos() == ICON_POS_NEWDOC );
1196 sal_Bool bIsFile = ( sURL.Len() != 0 && !::utl::UCBContentHelper::IsFolder( sURL ) &&
1197 INetURLObject( sURL ).GetProtocol() != INET_PROT_PRIVATE && !bIsNewDoc );
1198 aFileViewTB.EnableItem( TI_DOCTEMPLATE_PRINT, bIsFile );
1199 aFrameWinTB.EnableItem( TI_DOCTEMPLATE_PREVIEW, !bIsNewDoc );
1201 if ( bIsFile )
1202 pFrameWin->OpenFile( sURL, sal_True, sal_False, sal_False );
1203 else if ( bIsNewDoc && aFrameWinTB.IsItemChecked( TI_DOCTEMPLATE_PREVIEW ) )
1205 aFrameWinTB.CheckItem( TI_DOCTEMPLATE_DOCINFO );
1206 DoAction( TI_DOCTEMPLATE_DOCINFO );
1208 return 0;
1211 // ------------------------------------------------------------------------
1213 IMPL_LINK ( SvtTemplateWindow , ClickHdl_Impl, ToolBox *, pToolBox )
1215 DoAction( pToolBox->GetCurItemId() );
1216 return 0;
1219 // ------------------------------------------------------------------------
1221 IMPL_LINK ( SvtTemplateWindow , ResizeHdl_Impl, SplitWindow *, EMPTYARG )
1223 Resize();
1224 return 0;
1227 // ------------------------------------------------------------------------
1229 void SvtTemplateWindow::PrintFile( const String& rURL )
1231 // open the file readonly and hidden
1232 Sequence < PropertyValue > aArgs( 2 );
1233 aArgs[0].Name = ASCII_STR("ReadOnly");
1234 aArgs[0].Value <<= sal_True;
1235 aArgs[1].Name = ASCII_STR("Hidden");
1236 aArgs[1].Value <<= sal_True;
1238 Reference < XComponentLoader > xDesktop( ::comphelper::getProcessServiceFactory()->
1239 createInstance( ASCII_STR("com.sun.star.frame.Desktop") ), UNO_QUERY );
1240 Reference < XModel > xModel( xDesktop->loadComponentFromURL(
1241 rURL, ASCII_STR("_blank"), 0, aArgs ), UNO_QUERY );
1242 if ( xModel.is() )
1244 // print
1245 Reference < XPrintable > xPrintable( xModel, UNO_QUERY );
1246 if ( xPrintable.is() )
1247 xPrintable->print( Sequence < PropertyValue >() );
1251 // ------------------------------------------------------------------------
1253 void SvtTemplateWindow::AppendHistoryURL( const String& rURL, ULONG nGroup )
1255 sal_Bool bInsert = sal_True;
1256 if ( !pHistoryList )
1257 pHistoryList = new HistoryList_Impl;
1258 else if ( pHistoryList->Count() > 0 )
1260 FolderHistory* pLastEntry = pHistoryList->GetObject( pHistoryList->Count() - 1 );
1261 bInsert = ( rURL != pLastEntry->m_sURL);
1264 if ( bInsert )
1266 FolderHistory* pEntry = new FolderHistory( rURL, nGroup );
1267 pHistoryList->Insert( pEntry, LIST_APPEND );
1268 aFileViewTB.EnableItem( TI_DOCTEMPLATE_BACK, pHistoryList->Count() > 1 );
1272 // ------------------------------------------------------------------------
1274 void SvtTemplateWindow::OpenHistory()
1276 FolderHistory* pEntry = pHistoryList->Remove( pHistoryList->Count() - 1 );
1277 pEntry = pHistoryList->Remove( pHistoryList->Count() - 1 );
1278 aFileViewTB.EnableItem( TI_DOCTEMPLATE_BACK, pHistoryList->Count() > 1 );
1279 pFileWin->OpenFolder( pEntry->m_sURL );
1280 pIconWin->SetCursorPos( pEntry->m_nGroup );
1281 delete pEntry;
1284 // ------------------------------------------------------------------------
1286 void SvtTemplateWindow::DoAction( USHORT nAction )
1288 switch( nAction )
1290 case TI_DOCTEMPLATE_BACK :
1292 if ( pHistoryList && pHistoryList->Count() > 1 )
1293 OpenHistory();
1294 break;
1297 case TI_DOCTEMPLATE_PREV :
1299 String aURL;
1300 if ( pFileWin->HasPreviousLevel( aURL ) )
1301 pFileWin->OpenFolder( aURL );
1302 break;
1305 case TI_DOCTEMPLATE_PRINT :
1307 String sPrintFile( pFileWin->GetSelectedFile() );
1308 if ( sPrintFile.Len() > 0 )
1309 PrintFile( sPrintFile );
1310 break;
1313 case TI_DOCTEMPLATE_DOCINFO :
1314 case TI_DOCTEMPLATE_PREVIEW :
1316 pFrameWin->ToggleView( TI_DOCTEMPLATE_DOCINFO == nAction );
1317 break;
1322 // ------------------------------------------------------------------------
1324 void SvtTemplateWindow::InitToolBoxes()
1326 InitToolBoxImages();
1328 Size aSize = aFileViewTB.CalcWindowSizePixel();
1329 aSize.Height() += 4;
1330 aFileViewTB.SetPosSizePixel( Point( 0, 2 ), aSize );
1331 aSize = aFrameWinTB.CalcWindowSizePixel();
1332 aSize.Height() += 4;
1333 aFrameWinTB.SetPosSizePixel( Point( pFrameWin->GetPosPixel().X() + 2, 2 ), aSize );
1335 BOOL bFlat = ( SvtMiscOptions().GetToolboxStyle() == TOOLBOX_STYLE_FLAT );
1336 if ( bFlat )
1338 aFileViewTB.SetOutStyle( TOOLBOX_STYLE_FLAT );
1339 aFrameWinTB.SetOutStyle( TOOLBOX_STYLE_FLAT );
1342 aFileViewTB.EnableItem( TI_DOCTEMPLATE_BACK, FALSE );
1343 aFileViewTB.EnableItem( TI_DOCTEMPLATE_PREV, FALSE );
1344 aFileViewTB.EnableItem( TI_DOCTEMPLATE_PRINT, FALSE );
1346 Link aLink = LINK( this, SvtTemplateWindow, ClickHdl_Impl );
1347 aFileViewTB.SetClickHdl( aLink );
1348 aFrameWinTB.SetClickHdl( aLink );
1351 // ------------------------------------------------------------------------
1353 void SvtTemplateWindow::InitToolBoxImages()
1355 SvtMiscOptions aMiscOpt;
1356 BOOL bLarge = aMiscOpt.AreCurrentSymbolsLarge();
1357 sal_Bool bHiContrast = aFileViewTB.GetBackground().GetColor().IsDark();
1359 aFileViewTB.SetItemImage( TI_DOCTEMPLATE_BACK, Image( SvtResId(
1360 bLarge ? bHiContrast ? IMG_SVT_DOCTEMPL_HC_BACK_LARGE : IMG_SVT_DOCTEMPLATE_BACK_LARGE
1361 : bHiContrast ? IMG_SVT_DOCTEMPL_HC_BACK_SMALL : IMG_SVT_DOCTEMPLATE_BACK_SMALL ) ) );
1362 aFileViewTB.SetItemImage( TI_DOCTEMPLATE_PREV, Image( SvtResId(
1363 bLarge ? bHiContrast ? IMG_SVT_DOCTEMPL_HC_PREV_LARGE : IMG_SVT_DOCTEMPLATE_PREV_LARGE
1364 : bHiContrast ? IMG_SVT_DOCTEMPL_HC_PREV_SMALL : IMG_SVT_DOCTEMPLATE_PREV_SMALL ) ) );
1365 aFileViewTB.SetItemImage( TI_DOCTEMPLATE_PRINT, Image( SvtResId(
1366 bLarge ? bHiContrast ? IMG_SVT_DOCTEMPL_HC_PRINT_LARGE : IMG_SVT_DOCTEMPLATE_PRINT_LARGE
1367 : bHiContrast ? IMG_SVT_DOCTEMPL_HC_PRINT_SMALL : IMG_SVT_DOCTEMPLATE_PRINT_SMALL ) ) );
1369 aFrameWinTB.SetItemImage( TI_DOCTEMPLATE_DOCINFO, Image( SvtResId(
1370 bLarge ? bHiContrast ? IMG_SVT_DOCTEMPL_HC_DOCINFO_LARGE : IMG_SVT_DOCTEMPLATE_DOCINFO_LARGE
1371 : bHiContrast ? IMG_SVT_DOCTEMPL_HC_DOCINFO_SMALL : IMG_SVT_DOCTEMPLATE_DOCINFO_SMALL ) ) );
1372 aFrameWinTB.SetItemImage( TI_DOCTEMPLATE_PREVIEW, Image( SvtResId(
1373 bLarge ? bHiContrast ? IMG_SVT_DOCTEMPL_HC_PREVIEW_LARGE : IMG_SVT_DOCTEMPLATE_PREVIEW_LARGE
1374 : bHiContrast ? IMG_SVT_DOCTEMPL_HC_PREVIEW_SMALL : IMG_SVT_DOCTEMPLATE_PREVIEW_SMALL ) ) );
1377 // ------------------------------------------------------------------------
1379 void SvtTemplateWindow::UpdateIcons()
1381 pIconWin->UpdateIcons( aFileViewTB.GetBackground().GetColor().IsDark() );
1384 // ------------------------------------------------------------------------
1386 long SvtTemplateWindow::PreNotify( NotifyEvent& rNEvt )
1388 USHORT nType = rNEvt.GetType();
1389 long nRet = 0;
1391 if ( EVENT_KEYINPUT == nType && rNEvt.GetKeyEvent() )
1393 const KeyCode& rKeyCode = rNEvt.GetKeyEvent()->GetKeyCode();
1394 USHORT nCode = rKeyCode.GetCode();
1396 if ( KEY_BACKSPACE == nCode && !rKeyCode.GetModifier() && pFileWin->HasChildPathFocus() )
1398 DoAction( TI_DOCTEMPLATE_BACK );
1399 nRet = 1;
1401 else if ( pIconWin->ProcessKeyEvent( *rNEvt.GetKeyEvent() ) )
1403 nRet = 1;
1407 return nRet ? nRet : Window::PreNotify( rNEvt );
1410 // -----------------------------------------------------------------------------
1412 void SvtTemplateWindow::DataChanged( const DataChangedEvent& rDCEvt )
1414 Window::DataChanged( rDCEvt );
1416 if ( ( ( rDCEvt.GetType() == DATACHANGED_SETTINGS ) ||
1417 ( rDCEvt.GetType() == DATACHANGED_DISPLAY ) ) &&
1418 ( rDCEvt.GetFlags() & SETTINGS_STYLE ) )
1420 // update of the background for the area left of the FileView toolbox
1421 SetBackground( Wallpaper( GetSettings().GetStyleSettings().GetFaceColor() ) );
1422 // update of the images of the IconChoiceControl
1423 UpdateIcons();
1424 // update of the toolbox images
1425 InitToolBoxImages();
1428 // ------------------------------------------------------------------------
1430 void SvtTemplateWindow::Resize()
1432 long nItemSize = aSplitWin.GetItemSize( ICONWIN_ID );
1433 long nSplitterWidth = Splitter( this, 0 ).GetSizePixel().Width();
1435 Point aPos = aFileViewTB.GetPosPixel();
1436 aPos.X() = nItemSize + nSplitterWidth / 2;
1437 aFileViewTB.SetPosPixel( aPos );
1439 Size aWinSize = GetOutputSizePixel();
1440 long nWidth = aWinSize.Width() - aPos.X();
1442 nItemSize = nWidth * aSplitWin.GetItemSize( FILEWIN_ID ) / 100;
1443 aPos.X() = pFrameWin->GetPosPixel().X() + 2;
1444 aFrameWinTB.SetPosPixel( aPos );
1446 Size aSize = aFileViewTB.GetSizePixel();
1447 aSize.Width() = nItemSize;
1448 aFileViewTB.SetSizePixel( aSize );
1450 aSize = aFrameWinTB.GetSizePixel();
1451 aSize.Width() = nWidth - nItemSize;
1452 aFrameWinTB.SetSizePixel( aSize );
1454 long nToolBoxHeight = aSize.Height() + aFrameWinTB.GetPosPixel().Y();
1455 aSize = aWinSize;
1456 aSize.Height() -= nToolBoxHeight;
1457 aSplitWin.SetPosSizePixel( Point( 0, nToolBoxHeight ), aSize );
1460 // ------------------------------------------------------------------------
1462 String SvtTemplateWindow::GetSelectedFile() const
1464 return pFileWin->GetSelectedFile();
1467 // ------------------------------------------------------------------------
1469 sal_Bool SvtTemplateWindow::IsFileSelected() const
1471 String aURL = pFileWin->GetSelectedFile();
1472 sal_Bool bRet = ( aURL.Len() > 0 && !::utl::UCBContentHelper::IsFolder( aURL ) );
1473 return bRet;
1476 // ------------------------------------------------------------------------
1478 void SvtTemplateWindow::OpenFile( sal_Bool bNotAsTemplate )
1480 String aURL = pFileWin->GetSelectedFile();
1481 if ( aURL.Len() > 0 && !::utl::UCBContentHelper::IsFolder( aURL ) )
1482 pFrameWin->OpenFile( aURL, sal_False, pFileWin->IsTemplateFolder(), !bNotAsTemplate );
1485 // ------------------------------------------------------------------------
1487 String SvtTemplateWindow::GetFolderTitle() const
1489 String sTitle;
1490 String sFolderURL = pFileWin->GetFolderURL();
1491 if ( pIconWin->IsRootURL( sFolderURL ) )
1492 sTitle = pIconWin->GetIconText( sFolderURL );
1493 else
1494 sTitle = pFileWin->GetFolderTitle();
1495 return sTitle;
1498 // ------------------------------------------------------------------------
1500 String SvtTemplateWindow::GetFolderURL() const
1502 return pFileWin->GetFolderURL();
1506 // ------------------------------------------------------------------------
1508 void SvtTemplateWindow::SetFocus( sal_Bool bIconWin )
1510 if ( bIconWin )
1511 pIconWin->SetFocus();
1512 else
1513 pFileWin->SetFocus();
1516 // ------------------------------------------------------------------------
1518 void SvtTemplateWindow::OpenTemplateRoot()
1520 pFileWin->OpenFolder( pIconWin->GetTemplateRootURL() );
1523 // ------------------------------------------------------------------------
1525 void SvtTemplateWindow::SetPrevLevelButtonState( const String& rURL )
1527 // disable the prev level button on root folder of the icon pane (except My Documents)
1528 // and on the root of all (file:/// -> count == 0)
1529 INetURLObject aObj( rURL );
1530 sal_Int32 nCount = aObj.getSegmentCount();
1531 sal_Bool bEnable =
1532 ( nCount > 0 &&
1533 ( !pIconWin->IsRootURL( rURL ) || rURL == pIconWin->GetMyDocumentsRootURL() ) );
1534 aFileViewTB.EnableItem( TI_DOCTEMPLATE_PREV, bEnable );
1537 // ------------------------------------------------------------------------
1539 void SvtTemplateWindow::ClearHistory()
1541 if( pHistoryList )
1542 pHistoryList->Clear();
1545 // ------------------------------------------------------------------------
1547 long SvtTemplateWindow::CalcHeight() const
1549 // toolbox height
1550 long nHeight = aFileViewTB.GetSizePixel().Height();
1551 // + iconwin height
1552 nHeight += pIconWin->CalcHeight();
1553 // + little offset
1554 nHeight += 8;
1555 return nHeight;
1558 // ------------------------------------------------------------------------
1560 void SvtTemplateWindow::ReadViewSettings()
1562 // defaults
1563 sal_Int32 nSelectedGroup = ICON_POS_NEWDOC;
1564 sal_Int32 nSelectedView = TI_DOCTEMPLATE_DOCINFO;
1565 double nSplitRatio = 0.5;
1566 ::rtl::OUString sLastFolder;
1568 SvtViewOptions aViewSettings( E_DIALOG, VIEWSETTING_NEWFROMTEMPLATE );
1569 if ( aViewSettings.Exists() )
1571 // read the settings
1572 Sequence< NamedValue > aSettings = aViewSettings.GetUserData( );
1574 aViewSettings.GetUserItem( VIEWSETTING_SELECTEDGROUP ) >>= nSelectedGroup;
1575 aViewSettings.GetUserItem( VIEWSETTING_SELECTEDVIEW ) >>= nSelectedView;
1576 aViewSettings.GetUserItem( VIEWSETTING_SPLITRATIO ) >>= nSplitRatio;
1577 aViewSettings.GetUserItem( VIEWSETTING_LASTFOLDER ) >>= sLastFolder;
1579 // normalize
1580 if ( nSelectedGroup < ICON_POS_NEWDOC ) nSelectedGroup = ICON_POS_NEWDOC;
1581 if ( nSelectedGroup > ICON_POS_SAMPLES ) nSelectedGroup = ICON_POS_SAMPLES;
1583 if ( ( TI_DOCTEMPLATE_DOCINFO != nSelectedView ) && ( TI_DOCTEMPLATE_PREVIEW != nSelectedView ) )
1584 nSelectedView = TI_DOCTEMPLATE_DOCINFO;
1586 if ( nSplitRatio < 0.2 ) nSplitRatio = 0.2;
1587 if ( nSplitRatio > 0.8 ) nSplitRatio = 0.8;
1589 // change our view according to the settings
1591 // the selected view (details or preview)
1592 pFrameWin->ToggleView( TI_DOCTEMPLATE_DOCINFO == nSelectedView );
1593 aFrameWinTB.CheckItem( (sal_uInt16)nSelectedView, TRUE );
1595 // the split ratio
1596 sal_Int32 nSplitFileAndFrameSize = aSplitWin.GetItemSize( FILEWIN_ID ) + aSplitWin.GetItemSize( FRAMEWIN_ID );
1597 sal_Int32 nSplitFileSize = (sal_Int32)(nSplitFileAndFrameSize * nSplitRatio);
1598 sal_Int32 nSplitFrameSize = nSplitFileAndFrameSize - nSplitFileSize;
1599 aSplitWin.SetItemSize( FILEWIN_ID, nSplitFileSize );
1600 aSplitWin.SetItemSize( FRAMEWIN_ID, nSplitFrameSize );
1601 Resize();
1603 // the selected folder
1604 pIconWin->SetCursorPos( nSelectedGroup );
1606 // open the last folder or the selected group
1607 if ( sLastFolder.getLength() > 0 )
1608 pFileWin->OpenFolder( sLastFolder );
1609 else
1610 IconClickHdl_Impl( NULL );
1613 // ------------------------------------------------------------------------
1615 void SvtTemplateWindow::WriteViewSettings()
1617 // collect
1618 Sequence< NamedValue > aSettings(4);
1620 // the selected group
1621 aSettings[0].Name = VIEWSETTING_SELECTEDGROUP;
1622 pIconWin->SetFocus();
1623 aSettings[0].Value <<= (sal_Int32)pIconWin->GetCursorPos( );
1625 // the selected view mode
1626 aSettings[1].Name = VIEWSETTING_SELECTEDVIEW;
1627 aSettings[1].Value <<= sal_Int32( aFrameWinTB.IsItemChecked( TI_DOCTEMPLATE_DOCINFO ) ? TI_DOCTEMPLATE_DOCINFO : TI_DOCTEMPLATE_PREVIEW );
1629 // the split ratio
1630 aSettings[2].Name = VIEWSETTING_SPLITRATIO;
1631 sal_Int32 nSplitFileSize = aSplitWin.GetItemSize( FILEWIN_ID );
1632 sal_Int32 nSplitFileAndFrameSize = nSplitFileSize + aSplitWin.GetItemSize( FRAMEWIN_ID );
1633 aSettings[2].Value <<= double( 1.0 * nSplitFileSize / nSplitFileAndFrameSize );
1635 // last folder
1636 aSettings[3].Name = VIEWSETTING_LASTFOLDER;
1637 aSettings[3].Value <<= ::rtl::OUString( pFileWin->GetFolderURL() );
1639 // write
1640 SvtViewOptions aViewSettings( E_DIALOG, VIEWSETTING_NEWFROMTEMPLATE );
1641 aViewSettings.SetUserData( aSettings );
1643 /* -----------------27.11.2002 17:20-----------------
1645 * --------------------------------------------------*/
1647 void SvtTemplateWindow::SelectFolder(sal_Int32 nFolderPosition)
1649 pIconWin->SelectFolder(nFolderPosition);
1651 // struct SvtTmplDlg_Impl ------------------------------------------------
1653 struct SvtTmplDlg_Impl
1655 SvtTemplateWindow* pWin;
1656 String aTitle;
1657 Timer aUpdateTimer;
1658 sal_Bool bSelectNoOpen;
1660 uno::Reference< util::XOfficeInstallationDirectories > m_xOfficeInstDirs;
1663 SvtTmplDlg_Impl( Window* pParent ) : pWin( new SvtTemplateWindow( pParent ) ) ,bSelectNoOpen( sal_False ) {}
1665 ~SvtTmplDlg_Impl() { delete pWin; }
1667 uno::Reference< util::XOfficeInstallationDirectories > getOfficeInstDirs();
1670 uno::Reference< util::XOfficeInstallationDirectories > SvtTmplDlg_Impl::getOfficeInstDirs()
1672 if ( !m_xOfficeInstDirs.is() )
1676 uno::Reference< lang::XMultiServiceFactory > xSMgr = comphelper::getProcessServiceFactory();
1678 uno::Reference< beans::XPropertySet > xPropSet( xSMgr, uno::UNO_QUERY );
1679 if ( xPropSet.is() )
1681 uno::Reference< uno::XComponentContext > xCtx;
1682 xPropSet->getPropertyValue(
1683 rtl::OUString(
1684 RTL_CONSTASCII_USTRINGPARAM( "DefaultContext" ) ) )
1685 >>= xCtx;
1687 if ( xCtx.is() )
1689 xCtx->getValueByName(
1690 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
1691 "/singletons/com.sun.star.util.theOfficeInstallationDirectories" ) ) )
1692 >>= m_xOfficeInstDirs;
1696 catch( uno::Exception& )
1700 return m_xOfficeInstDirs;
1703 // class SvtDocumentTemplateDialog ---------------------------------------
1705 SvtDocumentTemplateDialog::SvtDocumentTemplateDialog( Window* _pParent, SelectOnly ) :
1706 ModalDialog( _pParent, SvtResId( DLG_DOCTEMPLATE ) ),
1708 aMoreTemplatesLink ( this, SvtResId( FT_DOCTEMPLATE_LINK ) ),
1709 aLine ( this, SvtResId( FL_DOCTEMPLATE ) ),
1710 aManageBtn ( this, SvtResId( BTN_DOCTEMPLATE_MANAGE ) ),
1711 aEditBtn ( this, SvtResId( BTN_DOCTEMPLATE_EDIT ) ),
1712 aOKBtn ( this, SvtResId( BTN_DOCTEMPLATE_OPEN ) ),
1713 aCancelBtn ( this, SvtResId( BTN_DOCTEMPLATE_CANCEL ) ),
1714 aHelpBtn ( this, SvtResId( BTN_DOCTEMPLATE_HELP ) ),
1715 pImpl ( NULL )
1717 FreeResource();
1718 InitImpl( );
1720 // no editing of templates
1721 aEditBtn.Hide();
1723 pImpl->bSelectNoOpen = sal_True;
1726 // ------------------------------------------------------------------------
1728 SvtDocumentTemplateDialog::SvtDocumentTemplateDialog( Window* pParent ) :
1730 ModalDialog( pParent, SvtResId( DLG_DOCTEMPLATE ) ),
1732 aMoreTemplatesLink ( this, SvtResId( FT_DOCTEMPLATE_LINK ) ),
1733 aLine ( this, SvtResId( FL_DOCTEMPLATE ) ),
1734 aManageBtn ( this, SvtResId( BTN_DOCTEMPLATE_MANAGE ) ),
1735 aEditBtn ( this, SvtResId( BTN_DOCTEMPLATE_EDIT ) ),
1736 aOKBtn ( this, SvtResId( BTN_DOCTEMPLATE_OPEN ) ),
1737 aCancelBtn ( this, SvtResId( BTN_DOCTEMPLATE_CANCEL ) ),
1738 aHelpBtn ( this, SvtResId( BTN_DOCTEMPLATE_HELP ) ),
1739 pImpl ( NULL )
1741 FreeResource();
1742 InitImpl( );
1745 // ------------------------------------------------------------------------
1747 void SvtDocumentTemplateDialog::InitImpl( )
1749 pImpl = new SvtTmplDlg_Impl( this );
1750 pImpl->aTitle = GetText();
1752 bool bHideLink = ( SvtExtendedSecurityOptions().GetOpenHyperlinkMode()
1753 == SvtExtendedSecurityOptions::OPEN_NEVER );
1754 if ( !bHideLink )
1756 aMoreTemplatesLink.SetURL( String(
1757 RTL_CONSTASCII_STRINGPARAM( "http://templates.go-oo.org/?cid=923508" ) ) );
1758 aMoreTemplatesLink.SetClickHdl( LINK( this, SvtDocumentTemplateDialog, OpenLinkHdl_Impl ) );
1760 else
1761 aMoreTemplatesLink.Hide();
1763 aManageBtn.SetClickHdl( LINK( this, SvtDocumentTemplateDialog, OrganizerHdl_Impl ) );
1764 Link aLink = LINK( this, SvtDocumentTemplateDialog, OKHdl_Impl );
1765 aEditBtn.SetClickHdl( aLink );
1766 aOKBtn.SetClickHdl( aLink );
1768 pImpl->pWin->SetSelectHdl( LINK( this, SvtDocumentTemplateDialog, SelectHdl_Impl ) );
1769 pImpl->pWin->SetDoubleClickHdl( LINK( this, SvtDocumentTemplateDialog, DoubleClickHdl_Impl ) );
1770 pImpl->pWin->SetNewFolderHdl( LINK( this, SvtDocumentTemplateDialog, NewFolderHdl_Impl ) );
1771 pImpl->pWin->SetSendFocusHdl( LINK( this, SvtDocumentTemplateDialog, SendFocusHdl_Impl ) );
1773 // dynamic height adjustment
1774 long nHeight = pImpl->pWin->CalcHeight();
1776 Size aSize = GetOutputSizePixel();
1777 Point aPos = aMoreTemplatesLink.GetPosPixel();
1778 Size a6Size = LogicToPixel( Size( 6, 6 ), MAP_APPFONT );
1779 if ( bHideLink )
1780 aPos.Y() += aMoreTemplatesLink.GetSizePixel().Height();
1781 else
1782 aPos.Y() -= a6Size.Height();
1783 long nDelta = aPos.Y() - nHeight;
1784 aSize.Height() -= nDelta;
1785 SetOutputSizePixel( aSize );
1787 aSize.Height() = nHeight;
1788 aSize.Width() -= ( a6Size.Width() * 2 );
1789 pImpl->pWin->SetPosSizePixel( Point( a6Size.Width(), 0 ), aSize );
1791 aPos = aMoreTemplatesLink.GetPosPixel();
1792 aPos.Y() -= nDelta;
1793 aMoreTemplatesLink.SetPosPixel( aPos );
1794 aPos = aLine.GetPosPixel();
1795 aPos.Y() -= nDelta;
1796 aLine.SetPosPixel( aPos );
1797 aPos = aManageBtn.GetPosPixel();
1798 aPos.Y() -= nDelta;
1799 aManageBtn.SetPosPixel( aPos );
1800 aPos = aEditBtn.GetPosPixel();
1801 aPos.Y() -= nDelta;
1802 aEditBtn.SetPosPixel( aPos );
1803 aPos = aOKBtn.GetPosPixel();
1804 aPos.Y() -= nDelta;
1805 aOKBtn.SetPosPixel( aPos );
1806 aPos = aCancelBtn.GetPosPixel();
1807 aPos.Y() -= nDelta;
1808 aCancelBtn.SetPosPixel( aPos );
1809 aPos = aHelpBtn.GetPosPixel();
1810 aPos.Y() -= nDelta;
1811 aHelpBtn.SetPosPixel( aPos );
1813 pImpl->pWin->Show();
1815 SelectHdl_Impl( NULL );
1816 NewFolderHdl_Impl( NULL );
1818 UpdateHdl_Impl( NULL );
1821 // ------------------------------------------------------------------------
1823 SvtDocumentTemplateDialog::~SvtDocumentTemplateDialog()
1825 delete pImpl;
1828 // ------------------------------------------------------------------------
1830 sal_Bool SvtDocumentTemplateDialog::IsFileSelected( ) const
1832 return pImpl->pWin->IsFileSelected();
1835 // ------------------------------------------------------------------------
1837 String SvtDocumentTemplateDialog::GetSelectedFileURL( ) const
1839 return pImpl->pWin->GetSelectedFile();
1842 // ------------------------------------------------------------------------
1844 sal_Bool SvtDocumentTemplateDialog::CanEnableEditBtn() const
1846 sal_Bool bEnable = sal_False;
1848 ::rtl::OUString aFolderURL = pImpl->pWin->GetFolderURL();
1849 if ( pImpl->pWin->IsFileSelected() && aFolderURL.getLength() )
1851 ::rtl::OUString aFileTargetURL = pImpl->pWin->GetSelectedFile();
1852 ::rtl::OUString aFolderTargetURL;
1854 ::ucbhelper::Content aFolderContent;
1855 Reference< XCommandEnvironment > xEnv;
1856 if ( ::ucbhelper::Content::create( aFolderURL, xEnv, aFolderContent ) )
1859 ::rtl::OUString aTmpURL;
1860 uno::Any aValue = aFolderContent.getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("TargetDirURL") ) );
1861 aValue >>= aTmpURL;
1863 uno::Reference< util::XOfficeInstallationDirectories > xOffInstDirs = pImpl->getOfficeInstDirs();
1864 if ( xOffInstDirs.is() )
1865 aFolderTargetURL = xOffInstDirs->makeAbsoluteURL( aTmpURL );
1867 catch( uno::Exception& )
1870 if ( aFolderTargetURL.getLength() && ::utl::UCBContentHelper::IsSubPath( aFolderTargetURL, aFileTargetURL ) )
1871 bEnable = sal_True;
1874 return bEnable;
1877 // ------------------------------------------------------------------------
1879 IMPL_LINK ( SvtDocumentTemplateDialog , SelectHdl_Impl, SvtTemplateWindow *, EMPTYARG )
1881 aEditBtn.Enable( pImpl->pWin->IsTemplateFolderOpen() && CanEnableEditBtn() );
1882 aOKBtn.Enable( pImpl->pWin->IsFileSelected() );
1883 return 0;
1886 // ------------------------------------------------------------------------
1888 IMPL_LINK ( SvtDocumentTemplateDialog , DoubleClickHdl_Impl, SvtTemplateWindow *, EMPTYARG )
1890 EndDialog( RET_OK );
1892 if ( !pImpl->bSelectNoOpen )
1893 pImpl->pWin->OpenFile( !pImpl->pWin->IsTemplateFolderOpen() );
1894 return 0;
1897 // ------------------------------------------------------------------------
1899 IMPL_LINK ( SvtDocumentTemplateDialog , NewFolderHdl_Impl, SvtTemplateWindow *, EMPTYARG )
1901 String aNewTitle( pImpl->aTitle );
1902 aNewTitle += String( ASCII_STR(" - ") );
1903 aNewTitle += pImpl->pWin->GetFolderTitle();
1904 SetText( aNewTitle );
1906 SelectHdl_Impl( NULL );
1907 return 0;
1910 // ------------------------------------------------------------------------
1912 IMPL_LINK ( SvtDocumentTemplateDialog , SendFocusHdl_Impl, SvtTemplateWindow *, EMPTYARG )
1914 if ( pImpl->pWin->HasIconWinFocus() )
1915 aHelpBtn.GrabFocus();
1916 else
1918 if ( aEditBtn.IsEnabled() )
1919 aEditBtn.GrabFocus();
1920 else if ( aOKBtn.IsEnabled() )
1921 aOKBtn.GrabFocus();
1922 else
1923 aCancelBtn.GrabFocus();
1926 return 0;
1929 // ------------------------------------------------------------------------
1931 IMPL_LINK ( SvtDocumentTemplateDialog , OKHdl_Impl, PushButton *, pBtn )
1933 if ( pImpl->pWin->IsFileSelected() )
1935 EndDialog( RET_OK );
1937 if ( !pImpl->bSelectNoOpen )
1938 pImpl->pWin->OpenFile( &aEditBtn == pBtn );
1940 return 0;
1943 // ------------------------------------------------------------------------
1945 IMPL_LINK ( SvtDocumentTemplateDialog , OrganizerHdl_Impl, PushButton *, EMPTYARG )
1947 Window* pOldDefWin = Application::GetDefDialogParent();
1948 Application::SetDefDialogParent( this );
1949 Reference < XFramesSupplier > xDesktop = Reference < XFramesSupplier >(
1950 ::comphelper::getProcessServiceFactory()->
1951 createInstance( ASCII_STR("com.sun.star.frame.Desktop") ), UNO_QUERY );
1952 Reference < XFrame > xFrame( xDesktop->getActiveFrame() );
1953 if ( !xFrame.is() )
1954 xFrame = Reference < XFrame >( xDesktop, UNO_QUERY );
1956 com::sun::star::util::URL aTargetURL;
1957 aTargetURL.Complete = ASCII_STR("slot:5540");
1958 Reference < com::sun::star::util::XURLTransformer > xTrans( ::comphelper::getProcessServiceFactory()->
1959 createInstance( ASCII_STR("com.sun.star.util.URLTransformer") ), UNO_QUERY );
1960 xTrans->parseStrict( aTargetURL );
1962 Reference < XDispatchProvider > xProv( xFrame, UNO_QUERY );
1963 Reference < XDispatch > xDisp;
1964 xDisp = xProv->queryDispatch( aTargetURL, ::rtl::OUString(), 0 );
1966 if ( xDisp.is() )
1968 Sequence<PropertyValue> aArgs(1);
1969 PropertyValue* pArg = aArgs.getArray();
1970 pArg[0].Name = ASCII_STR("Referer");
1971 pArg[0].Value <<= ASCII_STR("private:user");
1972 xDisp->dispatch( aTargetURL, aArgs );
1975 Application::SetDefDialogParent( pOldDefWin );
1976 return 0;
1979 // ------------------------------------------------------------------------
1981 IMPL_LINK ( SvtDocumentTemplateDialog, UpdateHdl_Impl, Timer*, _pEventSource )
1983 pImpl->pWin->SetFocus( sal_False );
1984 Reference< XDocumentTemplates > xTemplates( ::comphelper::getProcessServiceFactory()->
1985 createInstance( ASCII_STR("com.sun.star.frame.DocumentTemplates") ), UNO_QUERY );
1986 if ( xTemplates.is() )
1988 if ( _pEventSource )
1989 { // it was no direct call, which means it was triggered by the timer, which means we alread checked the necessity
1990 WaitObject aWaitCursor( this );
1991 xTemplates->update();
1992 if ( pImpl->pWin->IsTemplateFolderOpen() )
1994 pImpl->pWin->ClearHistory();
1995 pImpl->pWin->OpenTemplateRoot();
1998 else
2000 // check if we really need to do the update
2001 ::svt::TemplateFolderCache aCache;
2002 if ( aCache.needsUpdate() )
2003 { // yes -> do it asynchronous (it will take a noticeable time)
2005 // (but first store the current state)
2006 aCache.storeState();
2008 // start the timer for the async update
2009 pImpl->aUpdateTimer.SetTimeout( 300 );
2010 pImpl->aUpdateTimer.SetTimeoutHdl( LINK( this, SvtDocumentTemplateDialog, UpdateHdl_Impl ) );
2011 pImpl->aUpdateTimer.Start();
2015 return 0;
2018 // ------------------------------------------------------------------------
2020 IMPL_LINK ( SvtDocumentTemplateDialog, OpenLinkHdl_Impl, svt::FixedHyperlink*, EMPTYARG )
2022 ::rtl::OUString sURL( aMoreTemplatesLink.GetURL() );
2023 if ( sURL.getLength() > 0 )
2027 uno::Reference< lang::XMultiServiceFactory > xSMGR =
2028 ::comphelper::getProcessServiceFactory();
2029 uno::Reference< com::sun::star::system::XSystemShellExecute > xSystemShell(
2030 xSMGR->createInstance( ::rtl::OUString(
2031 RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.system.SystemShellExecute" ) ) ),
2032 uno::UNO_QUERY_THROW );
2033 if ( xSystemShell.is() )
2034 xSystemShell->execute( sURL, ::rtl::OUString(), com::sun::star::system::SystemShellExecuteFlags::DEFAULTS );
2035 EndDialog( RET_CANCEL );
2037 catch( const uno::Exception& e )
2039 OSL_TRACE( "Caught exception: %s\n thread terminated.\n",
2040 rtl::OUStringToOString(e.Message, RTL_TEXTENCODING_UTF8).getStr());
2043 return 0;
2046 /* -----------------27.11.2002 16:54-----------------
2048 * --------------------------------------------------*/
2049 void SvtDocumentTemplateDialog::SelectTemplateFolder()
2051 pImpl->pWin->SelectFolder(ICON_POS_TEMPLATES);