xref: /trunk/main/svtools/source/contnr/templwin.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_svtools.hxx"
30 #include "templwin.hxx"
31 #include <svtools/templdlg.hxx>
32 #include <svtools/svtdata.hxx>
33 #include <unotools/pathoptions.hxx>
34 #include <unotools/dynamicmenuoptions.hxx>
35 #include <unotools/extendedsecurityoptions.hxx>
36 #include <svtools/xtextedt.hxx>
37 #include <svl/inettype.hxx>
38 #include <svtools/imagemgr.hxx>
39 #include <svtools/miscopt.hxx>
40 #include <svtools/templatefoldercache.hxx>
41 #include <svtools/imgdef.hxx>
42 #include <svtools/txtattr.hxx>
43 #include <svtools/svtools.hrc>
44 #include "templwin.hrc"
45 #include <svtools/helpid.hrc>
46 #include <unotools/pathoptions.hxx>
47 #include <unotools/viewoptions.hxx>
48 #include <unotools/ucbhelper.hxx>
49 #include "unotools/configmgr.hxx"
50 #include <com/sun/star/awt/XWindow.hpp>
51 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
52 #include <com/sun/star/frame/XFrame.hpp>
53 #include <toolkit/helper/vclunohelper.hxx>
54 #include <com/sun/star/util/URL.hpp>
55 #include <com/sun/star/util/XURLTransformer.hpp>
56 #include <com/sun/star/util/XOfficeInstallationDirectories.hpp>
57 #include <com/sun/star/frame/XDispatchProvider.hpp>
58 #include <com/sun/star/frame/XDocumentTemplates.hpp>
59 #include <com/sun/star/frame/XComponentLoader.hpp>
60 #include <com/sun/star/beans/PropertyValue.hpp>
61 #include <com/sun/star/ucb/XContent.hpp>
62 #include <com/sun/star/ucb/XCommandEnvironment.hpp>
63 #include <com/sun/star/view/XPrintable.hpp>
64 #include <com/sun/star/awt/XWindow.hpp>
65 #include <com/sun/star/document/XDocumentProperties.hpp>
66 #include <com/sun/star/beans/XPropertySet.hpp>
67 #include <com/sun/star/beans/XMultiPropertySet.hpp>
68 #include <com/sun/star/beans/XPropertySetInfo.hpp>
69 #include <com/sun/star/io/IOException.hpp>
70 #include <com/sun/star/util/DateTime.hpp>
71 #include <com/sun/star/script/XTypeConverter.hpp>
72 #include <com/sun/star/system/XSystemShellExecute.hpp>
73 #include <com/sun/star/system/SystemShellExecuteFlags.hpp>
74 #include <unotools/localedatawrapper.hxx>
75 #include <com/sun/star/container/XNameContainer.hpp>
76 #include <vcl/waitobj.hxx>
77 #include <comphelper/processfactory.hxx>
78 #include <tools/urlobj.hxx>
79 #include <tools/datetime.hxx>
80 #include <vcl/svapp.hxx>
81 #include <vcl/split.hxx>
82 #include <vcl/msgbox.hxx>
83 #include <svtools/DocumentInfoPreview.hxx>
84 #include <vcl/mnemonic.hxx>
85 
86 #include <ucbhelper/content.hxx>
87 #include <comphelper/string.hxx>
88 
89 
90 using namespace ::com::sun::star;
91 using namespace ::com::sun::star::beans;
92 using namespace ::com::sun::star::container;
93 using namespace ::com::sun::star::frame;
94 using namespace ::com::sun::star::document;
95 using namespace ::com::sun::star::lang;
96 using namespace ::com::sun::star::ucb;
97 using namespace ::com::sun::star::uno;
98 using namespace ::com::sun::star::view;
99 using namespace svtools;
100 
101 extern ::rtl::OUString CreateExactSizeText_Impl( sal_Int64 nSize ); // fileview.cxx
102 
103 #define SPLITSET_ID			0
104 #define COLSET_ID			1
105 #define ICONWIN_ID			2
106 #define FILEWIN_ID			3
107 #define FRAMEWIN_ID			4
108 
109 #define ICON_POS_NEWDOC		0
110 #define ICON_POS_TEMPLATES	1
111 #define ICON_POS_MYDOCS		2
112 #define ICON_POS_SAMPLES	3
113 
114 #define ASCII_STR(s)					::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(s) )
115 #define VIEWSETTING_NEWFROMTEMPLATE		ASCII_STR("NewFromTemplate")
116 #define VIEWSETTING_SELECTEDGROUP		ASCII_STR("SelectedGroup")
117 #define VIEWSETTING_SELECTEDVIEW		ASCII_STR("SelectedView")
118 #define VIEWSETTING_SPLITRATIO			ASCII_STR("SplitRatio")
119 #define VIEWSETTING_LASTFOLDER			ASCII_STR("LastFolder")
120 
121 struct FolderHistory
122 {
123 	String		m_sURL;
124 	sal_uLong		m_nGroup;
125 
126 	FolderHistory( const String& _rURL, sal_Int32 _nGroup ) :
127 		m_sURL( _rURL ), m_nGroup( _nGroup ) {}
128 };
129 
130 DECLARE_LIST( HistoryList_Impl, FolderHistory* )
131 DECLARE_LIST( NewDocList_Impl, ::rtl::OUString* )
132 
133 ODocumentInfoPreview::ODocumentInfoPreview( Window* pParent ,WinBits _nBits) : Window(pParent,WB_DIALOGCONTROL)
134 {
135 	m_pEditWin = new SvtExtendedMultiLineEdit_Impl(this,_nBits);
136 	m_pEditWin->Show();
137 	m_pEditWin->EnableCursor( sal_False );
138 	m_pInfoTable = new SvtDocInfoTable_Impl();
139 	// detect application language
140 	m_aLocale = SvtPathOptions().GetLocale();
141 }
142 // -----------------------------------------------------------------------------
143 ODocumentInfoPreview::~ODocumentInfoPreview()
144 {
145 	delete m_pEditWin;
146 	delete m_pInfoTable;
147 }
148 // -----------------------------------------------------------------------------
149 void ODocumentInfoPreview::Resize()
150 {
151 	Size aOutputSize( GetOutputSize() );
152 	m_pEditWin->SetPosSizePixel( Point(0,0),aOutputSize);
153 }
154 // -----------------------------------------------------------------------------
155 void ODocumentInfoPreview::Clear()
156 {
157 	m_pEditWin->Clear();
158 }
159 // -----------------------------------------------------------------------------
160 
161 void lcl_insertDateTimeEntry(SvtExtendedMultiLineEdit_Impl* i_pEditWin,
162     const ::rtl::OUString & i_rName, const util::DateTime & i_rUDT)
163 {
164     DateTime aToolsDT =
165         DateTime( Date( i_rUDT.Day, i_rUDT.Month, i_rUDT.Year ),
166                 Time( i_rUDT.Hours, i_rUDT.Minutes,
167                       i_rUDT.Seconds, i_rUDT.HundredthSeconds ) );
168     if ( aToolsDT.IsValid() )
169     {
170         LocaleDataWrapper aLocaleWrapper(
171             ::comphelper::getProcessServiceFactory(),
172             Application::GetSettings().GetLocale() );
173         String aDateStr = aLocaleWrapper.getDate( aToolsDT );
174         aDateStr += String( RTL_CONSTASCII_STRINGPARAM(", ") );
175         aDateStr += aLocaleWrapper.getTime( aToolsDT );
176         i_pEditWin->InsertEntry( i_rName, aDateStr );
177     }
178 }
179 
180 void ODocumentInfoPreview::fill(
181     const Reference< XDocumentProperties >& i_xDocProps, const String& i_rURL)
182 {
183     if (!i_xDocProps.is()) throw RuntimeException();
184 
185     ::rtl::OUString aStr;
186     m_pEditWin->SetAutoScroll( sal_False );
187 
188     aStr = i_xDocProps->getTitle();
189     if (aStr.getLength()) {
190         m_pEditWin->InsertEntry( m_pInfoTable->GetString( DI_TITLE ), aStr );
191     }
192 
193     aStr = i_xDocProps->getAuthor();
194     if (aStr.getLength()) {
195         m_pEditWin->InsertEntry( m_pInfoTable->GetString( DI_FROM ), aStr );
196     }
197 
198     lcl_insertDateTimeEntry(m_pEditWin,
199             m_pInfoTable->GetString( DI_DATE ),
200             i_xDocProps->getCreationDate());
201 
202     aStr = i_xDocProps->getModifiedBy();
203     if (aStr.getLength()) {
204         m_pEditWin->InsertEntry( m_pInfoTable->GetString(DI_MODIFIEDBY), aStr );
205     }
206 
207     lcl_insertDateTimeEntry(m_pEditWin,
208             m_pInfoTable->GetString( DI_MODIFIEDDATE ),
209             i_xDocProps->getModificationDate());
210 
211     aStr = i_xDocProps->getPrintedBy();
212     if (aStr.getLength()) {
213         m_pEditWin->InsertEntry( m_pInfoTable->GetString( DI_PRINTBY ), aStr );
214     }
215 
216     lcl_insertDateTimeEntry(m_pEditWin,
217             m_pInfoTable->GetString( DI_PRINTDATE ),
218             i_xDocProps->getPrintDate());
219 
220     aStr = i_xDocProps->getSubject();
221     if (aStr.getLength()) {
222         m_pEditWin->InsertEntry( m_pInfoTable->GetString( DI_THEME ), aStr );
223     }
224 
225     aStr =
226         ::comphelper::string::convertCommaSeparated(i_xDocProps->getKeywords());
227     if (aStr.getLength()) {
228         m_pEditWin->InsertEntry( m_pInfoTable->GetString( DI_KEYWORDS ), aStr );
229     }
230 
231     aStr = i_xDocProps->getDescription();
232     if (aStr.getLength()) {
233         m_pEditWin->InsertEntry( m_pInfoTable->GetString( DI_DESCRIPTION ),
234             aStr );
235     }
236 
237     // size
238     if ( i_rURL.Len() > 0 )
239     {
240         sal_uLong nDocSize = ::utl::UCBContentHelper::GetSize( i_rURL );
241         m_pEditWin->InsertEntry(
242             m_pInfoTable->GetString( DI_SIZE ),
243             CreateExactSizeText_Impl( nDocSize ) );
244     }
245 
246     // MIMEType
247     if ( i_rURL.Len() > 0 )
248     {
249         INetContentType eTypeID =
250             INetContentTypes::GetContentTypeFromURL( i_rURL );
251         if ( eTypeID != CONTENT_TYPE_APP_OCTSTREAM ) {
252             aStr = INetContentTypes::GetPresentation( eTypeID, m_aLocale );
253         } else {
254             aStr = SvFileInformationManager::GetDescription(
255                         INetURLObject(i_rURL) );
256         }
257         if (aStr.getLength()) {
258             m_pEditWin->InsertEntry( m_pInfoTable->GetString( DI_MIMETYPE ),
259                 aStr );
260         }
261 	}
262 
263     // user-defined (custom) properties
264     Reference< XPropertySet > xUserDefined(
265         i_xDocProps->getUserDefinedProperties(), UNO_QUERY_THROW );
266     Reference< XPropertySetInfo > xUDInfo = xUserDefined->getPropertySetInfo();
267     Sequence< Property > props = xUDInfo->getProperties();
268     for (sal_Int32 i = 0; i < props.getLength(); ++i) {
269         const ::rtl::OUString name = props[i].Name;
270         uno::Any aAny;
271         try {
272             aAny = xUserDefined->getPropertyValue(name);
273             uno::Reference < script::XTypeConverter > xConverter(
274                 comphelper::getProcessServiceFactory()->createInstance(
275                     ASCII_STR("com.sun.star.script.Converter")),
276                 UNO_QUERY );
277             uno::Any aNew;
278             aNew = xConverter->convertToSimpleType( aAny, TypeClass_STRING );
279             if ((aNew >>= aStr) && aStr.getLength()) {
280                 m_pEditWin->InsertEntry( name, aStr);
281             }
282         } catch (uno::Exception &) {
283             // ignore
284         }
285     }
286 
287     m_pEditWin->SetSelection( Selection( 0, 0 ) );
288     m_pEditWin->SetAutoScroll( sal_True );
289 }
290 
291 // -----------------------------------------------------------------------------
292 void ODocumentInfoPreview::InsertEntry( const String& rTitle, const String& rValue )
293 {
294 	m_pEditWin->InsertEntry( rTitle, rValue);
295 }
296 // -----------------------------------------------------------------------------
297 
298 // class SvtDummyHeaderBar_Impl ------------------------------------------
299 
300 void SvtDummyHeaderBar_Impl::UpdateBackgroundColor()
301 {
302 	SetBackground( Wallpaper( GetSettings().GetStyleSettings().GetWindowColor() ) );
303 }
304 
305 SvtDummyHeaderBar_Impl::SvtDummyHeaderBar_Impl( Window* pPar ) : Window( pPar )
306 {
307 	SetSizePixel( HeaderBar( this, 0 ).CalcWindowSizePixel() );	// HeaderBar used only to calculate size
308 
309 	UpdateBackgroundColor();
310 }
311 
312 SvtDummyHeaderBar_Impl::~SvtDummyHeaderBar_Impl()
313 {
314 }
315 
316 void SvtDummyHeaderBar_Impl::DataChanged( const DataChangedEvent& r )
317 {
318 	Window::DataChanged( r );
319 	if( r.GetType() == DATACHANGED_SETTINGS )
320 		UpdateBackgroundColor();
321 }
322 
323 // class SvtIconWindow_Impl ----------------------------------------------
324 
325 SvtIconWindow_Impl::SvtIconWindow_Impl( Window* pParent ) :
326 
327 	Window( pParent, WB_DIALOGCONTROL | WB_BORDER | WB_3DLOOK ),
328 
329 	aDummyHeaderBar( this ),
330 	aIconCtrl( this, WB_ICON | WB_NOCOLUMNHEADER | WB_HIGHLIGHTFRAME | /*!WB_NOSELECTION |*/
331 					 WB_NODRAGSELECTION | WB_TABSTOP | WB_CLIPCHILDREN ),
332 	aNewDocumentRootURL( ASCII_STR("private:newdoc") ),
333 	aMyDocumentsRootURL( SvtPathOptions().GetWorkPath() ),
334 	aSamplesFolderRootURL( SvtPathOptions().
335 		SubstituteVariable( String( ASCII_STR("$(insturl)/share/samples/$(vlang)") ) ) ),
336 	nMaxTextLength( 0 )
337 
338 {
339 	aDummyHeaderBar.Show();
340 
341     aIconCtrl.SetAccessibleName( String( RTL_CONSTASCII_USTRINGPARAM("Groups") ) );
342   	aIconCtrl.SetHelpId( HID_TEMPLATEDLG_ICONCTRL );
343 	aIconCtrl.SetChoiceWithCursor( sal_True );
344 	aIconCtrl.SetSelectionMode( SINGLE_SELECTION );
345 	aIconCtrl.Show();
346 
347 	// detect the root URL of templates
348 	Reference< XDocumentTemplates > xTemplates( ::comphelper::getProcessServiceFactory()->
349 		createInstance( ASCII_STR("com.sun.star.frame.DocumentTemplates") ), UNO_QUERY );
350 
351 	if ( xTemplates.is() )
352 	{
353 		Reference < XContent > aRootContent = xTemplates->getContent();
354 		Reference < XCommandEnvironment > aCmdEnv;
355 
356 		if ( aRootContent.is() )
357 			aTemplateRootURL = aRootContent->getIdentifier()->getContentIdentifier();
358 	}
359 
360 	// insert the categories
361 	// "New Document"
362 	sal_Bool bHiContrast = GetSettings().GetStyleSettings().GetHighContrastMode();
363     Image aImage( SvtResId( bHiContrast ? IMG_SVT_NEWDOC_HC : IMG_SVT_NEWDOC ) );
364     nMaxTextLength = aImage.GetSizePixel().Width();
365 	String aEntryStr = String( SvtResId( STR_SVT_NEWDOC ) );
366 	SvxIconChoiceCtrlEntry*	pEntry =
367         aIconCtrl.InsertEntry( aEntryStr, aImage, ICON_POS_NEWDOC );
368 	pEntry->SetUserData( new String( aNewDocumentRootURL ) );
369 	pEntry->SetQuickHelpText( String( SvtResId( STR_SVT_NEWDOC_HELP ) ) );
370     DBG_ASSERT( !pEntry->GetBoundRect().IsEmpty(), "empty rectangle" );
371     long nTemp = pEntry->GetBoundRect().GetSize().Width();
372     if (nTemp > nMaxTextLength)
373         nMaxTextLength = nTemp;
374 
375 	// "Templates"
376 	if( aTemplateRootURL.Len() > 0 )
377 	{
378 		aEntryStr = String( SvtResId( STR_SVT_TEMPLATES ) );
379 		pEntry = aIconCtrl.InsertEntry(
380 			aEntryStr, Image( SvtResId( bHiContrast ? IMG_SVT_TEMPLATES_HC : IMG_SVT_TEMPLATES ) ), ICON_POS_TEMPLATES );
381 		pEntry->SetUserData( new String( aTemplateRootURL ) );
382 		pEntry->SetQuickHelpText( String( SvtResId( STR_SVT_TEMPLATES_HELP ) ) );
383         DBG_ASSERT( !pEntry->GetBoundRect().IsEmpty(), "empty rectangle" );
384         nTemp = pEntry->GetBoundRect().GetSize().Width();
385         if (nTemp > nMaxTextLength)
386             nMaxTextLength = nTemp;
387 	}
388 
389 	// "My Documents"
390 	aEntryStr = String( SvtResId( STR_SVT_MYDOCS ) );
391 	pEntry = aIconCtrl.InsertEntry(
392 		aEntryStr, Image( SvtResId( bHiContrast ? IMG_SVT_MYDOCS_HC : IMG_SVT_MYDOCS ) ), ICON_POS_MYDOCS );
393 	pEntry->SetUserData( new String( aMyDocumentsRootURL ) );
394 	pEntry->SetQuickHelpText( String( SvtResId( STR_SVT_MYDOCS_HELP ) ) );
395     DBG_ASSERT( !pEntry->GetBoundRect().IsEmpty(), "empty rectangle" );
396     nTemp = pEntry->GetBoundRect().GetSize().Width();
397     if( nTemp > nMaxTextLength )
398         nMaxTextLength = nTemp;
399 
400 	// "Samples"
401 	aEntryStr = String( SvtResId( STR_SVT_SAMPLES ) );
402 	pEntry = aIconCtrl.InsertEntry(
403 		aEntryStr, Image( SvtResId( bHiContrast ? IMG_SVT_SAMPLES_HC : IMG_SVT_SAMPLES ) ), ICON_POS_SAMPLES );
404 	pEntry->SetUserData( new String( aSamplesFolderRootURL ) );
405 	pEntry->SetQuickHelpText( String( SvtResId( STR_SVT_SAMPLES_HELP ) ) );
406     DBG_ASSERT( !pEntry->GetBoundRect().IsEmpty(), "empty rectangle" );
407     nTemp = pEntry->GetBoundRect().GetSize().Width();
408     if (nTemp > nMaxTextLength)
409         nMaxTextLength = nTemp;
410 
411 	aIconCtrl.CreateAutoMnemonics();
412 }
413 
414 SvtIconWindow_Impl::~SvtIconWindow_Impl()
415 {
416 	for ( sal_uLong i = 0; i < aIconCtrl.GetEntryCount(); ++i )
417 	{
418 		SvxIconChoiceCtrlEntry* pEntry = aIconCtrl.GetEntry( i );
419 		delete (String*)pEntry->GetUserData();
420 	}
421 }
422 
423 SvxIconChoiceCtrlEntry*	SvtIconWindow_Impl::GetEntry( const String& rURL ) const
424 {
425 	SvxIconChoiceCtrlEntry* pEntry = NULL;
426 	for ( sal_uLong i = 0; i < aIconCtrl.GetEntryCount(); ++i )
427 	{
428 		SvxIconChoiceCtrlEntry* pTemp = aIconCtrl.GetEntry( i );
429 		String aURL( *( (String*)pTemp->GetUserData() ) );
430 		if ( aURL == rURL )
431 		{
432 			pEntry = pTemp;
433 			break;
434 		}
435 	}
436 
437 	return pEntry;
438 }
439 
440 void SvtIconWindow_Impl::Resize()
441 {
442 	Size aWinSize = GetOutputSizePixel();
443 	Size aHeaderSize = aDummyHeaderBar.GetSizePixel();
444 	aHeaderSize.Width() = aWinSize.Width();
445 	aDummyHeaderBar.SetSizePixel( aHeaderSize );
446 	long nHeaderHeight = aHeaderSize.Height();
447 	aWinSize.Height() -= nHeaderHeight;
448 	aIconCtrl.SetPosSizePixel( Point( 0, nHeaderHeight ), aWinSize );
449 	aIconCtrl.ArrangeIcons();
450 }
451 
452 String SvtIconWindow_Impl::GetCursorPosIconURL() const
453 {
454 	String aURL;
455 	SvxIconChoiceCtrlEntry* pEntry = aIconCtrl.GetCursor( );
456 	if ( pEntry )
457 		aURL = *static_cast<String*>(pEntry->GetUserData());
458 	return aURL;
459 
460 }
461 
462 String SvtIconWindow_Impl::GetSelectedIconURL() const
463 {
464 	sal_uLong nPos;
465 	SvxIconChoiceCtrlEntry* pEntry = aIconCtrl.GetSelectedEntry( nPos );
466 	String aURL;
467 	if ( pEntry )
468 		aURL = *static_cast<String*>(pEntry->GetUserData());
469 	return aURL;
470 }
471 
472 String SvtIconWindow_Impl::GetSelectedIconText() const
473 {
474 	sal_uLong nPos;
475 	return MnemonicGenerator::EraseAllMnemonicChars( aIconCtrl.GetSelectedEntry( nPos )->GetText() );
476 }
477 
478 String SvtIconWindow_Impl::GetIconText( const String& rURL ) const
479 {
480 	String aText;
481 	SvxIconChoiceCtrlEntry* pEntry = GetEntry( rURL );
482 	if ( pEntry )
483 		aText = MnemonicGenerator::EraseAllMnemonicChars( pEntry->GetText() );
484 	return aText;
485 }
486 
487 void SvtIconWindow_Impl::InvalidateIconControl()
488 {
489 	aIconCtrl.Invalidate();
490 }
491 
492 sal_uLong SvtIconWindow_Impl::GetCursorPos() const
493 {
494 	sal_uLong nPos = ~sal_uLong(0);
495 
496 	SvxIconChoiceCtrlEntry* pCursorEntry = aIconCtrl.GetCursor( );
497 	if ( pCursorEntry )
498 		nPos = aIconCtrl.GetEntryListPos( pCursorEntry );
499 
500 	return nPos;
501 }
502 
503 sal_uLong SvtIconWindow_Impl::GetSelectEntryPos() const
504 {
505 	sal_uLong nPos;
506 	if ( !aIconCtrl.GetSelectedEntry( nPos ) )
507 		nPos = ~sal_uLong(0);
508 	return nPos;
509 }
510 
511 void SvtIconWindow_Impl::SetCursorPos( sal_uLong nPos )
512 {
513 	SvxIconChoiceCtrlEntry*	pEntry = aIconCtrl.GetEntry( nPos );
514 	aIconCtrl.SetCursor( pEntry );
515 	aIconCtrl.Invalidate();
516 	aIconCtrl.Update();
517 }
518 
519 void SvtIconWindow_Impl::SetFocus()
520 {
521 	aIconCtrl.GrabFocus();
522 }
523 
524 long SvtIconWindow_Impl::CalcHeight() const
525 {
526 	// calculate the required height of the IconControl
527 	long nHeight = 0;
528 	sal_uLong nCount = aIconCtrl.GetEntryCount();
529 	if ( nCount > 0 )
530 		// bottom of the last icon
531 		nHeight = aIconCtrl.GetEntry(nCount-1)->GetBoundRect().Bottom();
532 
533 	// + headerbar height
534 	nHeight += aDummyHeaderBar.GetSizePixel().Height();
535 
536 	return nHeight;
537 }
538 
539 sal_Bool SvtIconWindow_Impl::IsRootURL( const String& rURL ) const
540 {
541 	return	rURL == aNewDocumentRootURL ||
542 			rURL == aTemplateRootURL ||
543 			rURL == aMyDocumentsRootURL ||
544 			rURL == aSamplesFolderRootURL;
545 }
546 
547 sal_uLong SvtIconWindow_Impl::GetRootPos( const String& rURL ) const
548 {
549 	sal_uLong nPos = ~sal_uLong(0);
550 	if ( aNewDocumentRootURL.Match( rURL ) == STRING_MATCH )
551 		nPos = 0;
552 	else if ( aTemplateRootURL.Match( rURL ) == STRING_MATCH )
553 		nPos = 1;
554 	else if ( aMyDocumentsRootURL.Match( rURL ) == STRING_MATCH )
555 		nPos = 2;
556 	else if ( aSamplesFolderRootURL.Match( rURL ) == STRING_MATCH )
557 		nPos = 3;
558     else if ( rURL.Match( aMyDocumentsRootURL ) == STRING_MATCH )
559         nPos = 2;
560 	else
561 	{
562         DBG_WARNING( "SvtIconWindow_Impl::GetRootPos(): invalid position" );
563         nPos = 2;
564 	}
565 
566 	return nPos;
567 }
568 
569 void SvtIconWindow_Impl::UpdateIcons( sal_Bool _bHiContrast )
570 {
571 	aIconCtrl.GetEntry( ICON_POS_NEWDOC )->SetImage(
572 		Image( SvtResId( _bHiContrast ? IMG_SVT_NEWDOC_HC : IMG_SVT_NEWDOC ) ) );
573 	aIconCtrl.GetEntry( ICON_POS_TEMPLATES )->SetImage(
574 		Image( SvtResId( _bHiContrast ? IMG_SVT_TEMPLATES_HC : IMG_SVT_TEMPLATES ) ) );
575 	aIconCtrl.GetEntry( ICON_POS_MYDOCS )->SetImage(
576 		Image( SvtResId( _bHiContrast ? IMG_SVT_MYDOCS_HC : IMG_SVT_MYDOCS ) ) );
577 	aIconCtrl.GetEntry( ICON_POS_SAMPLES )->SetImage(
578 		Image( SvtResId( _bHiContrast ? IMG_SVT_SAMPLES_HC : IMG_SVT_SAMPLES ) ) );
579 }
580 /* -----------------27.11.2002 16:58-----------------
581  *
582  * --------------------------------------------------*/
583 void SvtIconWindow_Impl::SelectFolder(sal_Int32 nFolderPosition)
584 {
585     SvxIconChoiceCtrlEntry* pEntry = aIconCtrl.GetEntry( nFolderPosition );
586     if(pEntry)
587     {
588         aIconCtrl.SetCursor( pEntry );
589         aIconCtrl.GetClickHdl().Call(&aIconCtrl);
590     }
591 }
592 
593 // class SvtFileViewWindow_Impl -----------------------------------------_
594 
595 SvtFileViewWindow_Impl::SvtFileViewWindow_Impl( SvtTemplateWindow* pParent ) :
596 
597 	Window( pParent, WB_DIALOGCONTROL | WB_TABSTOP | WB_BORDER | WB_3DLOOK ),
598 
599 	rParent				( *pParent ),
600 	aFileView			( this, SvtResId( CTRL_FILEVIEW ), FILEVIEW_SHOW_TITLE ),
601 	bIsTemplateFolder	( sal_False )
602 
603 {
604 	aFileView.SetStyle( aFileView.GetStyle() | WB_DIALOGCONTROL | WB_TABSTOP );
605 	aFileView.SetHelpId( HID_TEMPLATEDLG_FILEVIEW );
606 	aFileView.Show();
607 	aFileView.SetPosPixel( Point( 0, 0 ) );
608 	aFileView.EnableAutoResize();
609     aFileView.EnableContextMenu( sal_False );
610     aFileView.EnableDelete( sal_False );
611 }
612 
613 SvtFileViewWindow_Impl::~SvtFileViewWindow_Impl()
614 {
615 }
616 
617 void GetMenuEntry_Impl
618 (
619 	Sequence< PropertyValue >& aDynamicMenuEntry,
620 	::rtl::OUString& rTitle,
621 	::rtl::OUString& rURL,
622     ::rtl::OUString& rFrame,
623 	::rtl::OUString& rImageId
624 )
625 {
626 	for ( int i = 0; i < aDynamicMenuEntry.getLength(); i++ )
627 	{
628 		if ( aDynamicMenuEntry[i].Name == DYNAMICMENU_PROPERTYNAME_URL )
629 			aDynamicMenuEntry[i].Value >>= rURL;
630 		else if ( aDynamicMenuEntry[i].Name == DYNAMICMENU_PROPERTYNAME_TITLE )
631 			aDynamicMenuEntry[i].Value >>= rTitle;
632 		else if ( aDynamicMenuEntry[i].Name == DYNAMICMENU_PROPERTYNAME_IMAGEIDENTIFIER )
633 			aDynamicMenuEntry[i].Value >>= rImageId;
634 		else if ( aDynamicMenuEntry[i].Name == DYNAMICMENU_PROPERTYNAME_TARGETNAME )
635 			aDynamicMenuEntry[i].Value >>= rFrame;
636 	}
637 }
638 Sequence< ::rtl::OUString > SvtFileViewWindow_Impl::GetNewDocContents() const
639 {
640 	NewDocList_Impl aNewDocs;
641 	Sequence< Sequence< PropertyValue > > aDynamicMenuEntries;
642 	aDynamicMenuEntries = SvtDynamicMenuOptions().GetMenu( E_NEWMENU );
643 
644 	::rtl::OUString aTitle;
645 	::rtl::OUString aURL;
646 	::rtl::OUString aImageURL;
647 	::rtl::OUString aTargetFrame;
648 
649 	sal_uInt32 i, nCount = aDynamicMenuEntries.getLength();
650 	::rtl::OUString sSeparator( ASCII_STR("private:separator") );
651 	::rtl::OUString sSlotURL( ASCII_STR("slot:5500") );
652 
653 	for ( i = 0; i < nCount; ++i )
654 	{
655 		GetMenuEntry_Impl( aDynamicMenuEntries[i], aTitle, aURL, aTargetFrame, aImageURL );
656 
657         if ( aURL == sSeparator || aURL == sSlotURL )
658 			continue;
659 		else
660 		{
661 			// title
662 			String aRow = MnemonicGenerator::EraseAllMnemonicChars( String( aTitle ) );
663 			aRow += '\t';
664 			// no type
665 			aRow += '\t';
666 			// no size
667 			aRow += '\t';
668 			// no date
669 			aRow += '\t';
670 			// url
671 			aRow += String( aURL );
672 			aRow += '\t';
673 			// folder == false
674 			aRow += '0';
675 			// image url?
676 			if ( aImageURL.getLength() > 0 )
677 			{
678 				aRow += '\t';
679 				aRow += String( aImageURL );
680 			}
681 
682 			::rtl::OUString* pRow = new ::rtl::OUString( aRow );
683 			aNewDocs.Insert( pRow, LIST_APPEND );
684 		}
685 	}
686 
687     nCount = aNewDocs.Count();
688 	Sequence < ::rtl::OUString > aRet( nCount );
689 	::rtl::OUString* pRet = aRet.getArray();
690 	for ( i = 0; i < nCount; ++i )
691 	{
692 		::rtl::OUString* pNewDoc = aNewDocs.GetObject(i);
693 		pRet[i] = *( pNewDoc );
694 		delete pNewDoc;
695 	}
696 
697 	return aRet;
698 }
699 
700 void SvtFileViewWindow_Impl::Resize()
701 {
702 	Size aWinSize = GetOutputSizePixel();
703 
704 	static int	x = 0;
705 	static int	y = 0;
706 
707 	aWinSize.nA += x;
708 	aWinSize.nB += y;
709 	aFileView.SetSizePixel( aWinSize );
710 }
711 
712 String SvtFileViewWindow_Impl::GetSelectedFile() const
713 {
714 	return aFileView.GetCurrentURL();
715 }
716 
717 void SvtFileViewWindow_Impl::OpenFolder( const String& rURL )
718 {
719 	aFolderURL = rURL;
720 
721 	rParent.SetPrevLevelButtonState( rURL );
722 
723     aFileView.SetUrlFilter( &aURLFilter );
724 
725 	INetProtocol eProt = INetURLObject( rURL ).GetProtocol();
726 	bIsTemplateFolder = ( eProt == INET_PROT_VND_SUN_STAR_HIER );
727     bool isNewDocumentFolder = ( eProt == INET_PROT_PRIVATE );
728 
729     aURLFilter.enableFilter( !bIsTemplateFolder && !isNewDocumentFolder );
730 
731     if ( isNewDocumentFolder )
732 	{
733 		aFileView.EnableNameReplacing( sal_False );
734 		aFileView.Initialize( GetNewDocContents() );
735 	}
736 	else
737 	{
738 		xub_StrLen nSampFoldLen = aSamplesFolderURL.Len();
739 		aFileView.EnableNameReplacing(
740 					nSampFoldLen && rURL.CompareTo( aSamplesFolderURL, nSampFoldLen ) == COMPARE_EQUAL );
741 		aFileView.Initialize( rURL, String(), NULL );
742 	}
743 	aNewFolderLink.Call( this );
744 }
745 
746 sal_Bool SvtFileViewWindow_Impl::HasPreviousLevel( String& rURL ) const
747 {
748 	INetURLObject aViewObj( aFileView.GetViewURL() );
749 	INetURLObject aRootObj( aCurrentRootURL );
750 	INetURLObject aMyDocObj( aMyDocumentsURL );
751 
752     return ( ( aViewObj != aRootObj || aRootObj == aMyDocObj ) && aFileView.GetParentURL( rURL ) );
753 }
754 
755 String SvtFileViewWindow_Impl::GetFolderTitle() const
756 {
757 	String aTitle;
758 	::utl::UCBContentHelper::GetTitle( aFolderURL, aTitle );
759 	return aTitle;
760 }
761 
762 void SvtFileViewWindow_Impl::SetFocus()
763 {
764 	aFileView.SetFocus();
765 }
766 
767 // class SvtDocInfoTable_Impl --------------------------------------------
768 
769 SvtDocInfoTable_Impl::SvtDocInfoTable_Impl() :
770 
771 	ResStringArray( SvtResId( STRARY_SVT_DOCINFO ) )
772 
773 {
774 }
775 // -----------------------------------------------------------------------------
776 // class SvtExtendedMultiLineEdit_Impl --------------------------------------------
777 SvtExtendedMultiLineEdit_Impl::SvtExtendedMultiLineEdit_Impl( Window* pParent,WinBits _nBits ) :
778 
779 	ExtMultiLineEdit( pParent, _nBits )
780 
781 {
782 	SetLeftMargin( 10 );
783 }
784 // -----------------------------------------------------------------------------
785 void SvtExtendedMultiLineEdit_Impl::InsertEntry( const String& rTitle, const String& rValue )
786 {
787 	String aText( '\n' );
788 	aText += rTitle;
789 	aText += ':';
790 	InsertText( aText );
791 	sal_uLong nPara = GetParagraphCount() - 1;
792 	SetAttrib( TextAttribFontWeight( WEIGHT_BOLD ), nPara, 0, aText.Len() );
793 
794 	aText = '\n';
795 	aText += rValue;
796 	InsertText( aText );
797 	nPara = GetParagraphCount() - 1;
798 	SetAttrib( TextAttribFontWeight( WEIGHT_NORMAL ), nPara, 0, aText.Len() );
799 
800 	InsertText( String( '\n' ) );
801 }
802 // -----------------------------------------------------------------------------
803 
804 // -----------------------------------------------------------------------
805 
806 const String& SvtDocInfoTable_Impl::GetString( long nId ) const
807 {
808     sal_uInt32 nPos( FindIndex( nId ) );
809 
810 	if ( RESARRAY_INDEX_NOTFOUND != nPos )
811 		return ResStringArray::GetString( nPos );
812 	else
813 		return aEmptyString;
814 }
815 
816 // class SvtFrameWindow_Impl ---------------------------------------------
817 
818 SvtFrameWindow_Impl::SvtFrameWindow_Impl( Window* pParent ) :
819 
820 	Window( pParent )
821 
822 {
823 	// detect application language
824 	aLocale= SvtPathOptions().GetLocale();
825 
826 	// create windows and frame
827 	pEditWin = new ODocumentInfoPreview( this ,WB_LEFT | WB_VSCROLL | WB_READONLY | WB_BORDER | WB_3DLOOK);
828 	pTextWin = new Window( this );
829     xFrame = Reference < XFrame > ( ::comphelper::getProcessServiceFactory()->
830 		createInstance( ASCII_STR("com.sun.star.frame.Frame") ), UNO_QUERY );
831 	xWindow = VCLUnoHelper::GetInterface( pTextWin );
832 	xFrame->initialize( xWindow );
833 
834 	// create docinfo instance
835     m_xDocProps.set( ::comphelper::getProcessServiceFactory()->createInstance(
836             ASCII_STR("com.sun.star.document.DocumentProperties") ),
837         UNO_QUERY );
838 
839 	pEmptyWin = new Window( this, WB_BORDER | WB_3DLOOK );
840 }
841 
842 SvtFrameWindow_Impl::~SvtFrameWindow_Impl()
843 {
844 	delete pEditWin;
845 	delete pEmptyWin;
846 	xFrame->dispose();
847 }
848 
849 void SvtFrameWindow_Impl::ViewEditWin()
850 {
851 	pEmptyWin->Hide();
852 	xWindow->setVisible( sal_False );
853 	pTextWin->Hide();
854 	pEditWin->Show();
855 }
856 
857 void SvtFrameWindow_Impl::ViewTextWin()
858 {
859 	pEmptyWin->Hide();
860 	pEditWin->Hide();
861 	xWindow->setVisible( sal_True );
862 	pTextWin->Show();
863 }
864 
865 void SvtFrameWindow_Impl::ViewEmptyWin()
866 {
867 	xWindow->setVisible( sal_False );
868 	pTextWin->Hide();
869 	pEditWin->Hide();
870 	pEmptyWin->Show();
871 }
872 
873 void SvtFrameWindow_Impl::ViewNonEmptyWin()
874 {
875 	if( bDocInfo )
876 		ViewEditWin();
877 	else
878 		ViewTextWin();
879 }
880 
881 IMPL_STATIC_LINK_NOINSTANCE( SvtFrameWindow_Impl, ExecuteHdl_Impl, SvtExecuteInfo*, pExecuteInfo )
882 {
883     try
884     {
885         pExecuteInfo->xDispatch->dispatch( pExecuteInfo->aTargetURL, Sequence < PropertyValue >() );
886     }
887     catch ( Exception& )
888     {
889     }
890 
891     delete pExecuteInfo;
892     return 0;
893 }
894 
895 void SvtFrameWindow_Impl::ShowDocInfo( const String& rURL )
896 {
897 	try
898 	{
899 		uno::Reference < task::XInteractionHandler > xInteractionHandler( ::comphelper::getProcessServiceFactory()->createInstance(
900 			::rtl::OUString::createFromAscii("com.sun.star.task.InteractionHandler") ), uno::UNO_QUERY );
901 		uno::Sequence < beans::PropertyValue> aProps(1);
902 		aProps[0].Name = ::rtl::OUString::createFromAscii("InteractionHandler");
903 		aProps[0].Value <<= xInteractionHandler;
904 		m_xDocProps->loadFromMedium( rURL, aProps );
905         pEditWin->fill( m_xDocProps, rURL );
906 	}
907 	catch ( UnknownPropertyException& ) {}
908 	catch ( Exception& ) {}
909 }
910 
911 void SvtFrameWindow_Impl::Resize()
912 {
913 	Size aWinSize = GetOutputSizePixel();
914 	pEditWin->SetSizePixel( aWinSize );
915 	pTextWin->SetSizePixel( aWinSize );
916 	pEmptyWin->SetSizePixel( aWinSize );
917 }
918 
919 void SvtFrameWindow_Impl::OpenFile( const String& rURL, sal_Bool bPreview, sal_Bool bIsTemplate, sal_Bool bAsTemplate )
920 {
921 	if ( bPreview )
922 		aCurrentURL = rURL;
923 
924 	ViewNonEmptyWin();
925 	pEditWin->Clear();
926 
927     if ( rURL.Len() > 0 && bPreview && m_xDocProps.is() )
928         ShowDocInfo( rURL );
929 
930 	if ( rURL.Len() == 0 )
931 	{
932 		xFrame->setComponent( Reference < com::sun::star::awt::XWindow >(), Reference < XController >() );
933 		ViewEmptyWin();
934 	}
935 	else if ( !::utl::UCBContentHelper::IsFolder( rURL ) )
936 	{
937 		com::sun::star::util::URL aURL;
938 		aURL.Complete = rURL;
939     	Reference < com::sun::star::util::XURLTransformer > xTrans( ::comphelper::getProcessServiceFactory()->
940 			createInstance( ASCII_STR("com.sun.star.util.URLTransformer" ) ), UNO_QUERY );
941     	xTrans->parseStrict( aURL );
942 
943 		String aTarget;
944     	Reference < XDispatchProvider > xProv( xFrame, UNO_QUERY );
945 		if ( bPreview )
946 			aTarget = ASCII_STR("_self");
947 		else
948 		{
949             // can be removed if the database application change its URL
950             String sServiceScheme( RTL_CONSTASCII_STRINGPARAM( "service:" ) );
951             if ( rURL.Match( sServiceScheme ) != sServiceScheme.Len() )
952                 // service URL has no default target
953                 aTarget = ASCII_STR("_default");
954 			xProv = Reference < XDispatchProvider >( ::comphelper::getProcessServiceFactory()->
955 				createInstance( ASCII_STR("com.sun.star.frame.Desktop") ), UNO_QUERY );
956 		}
957 
958     	Reference < XDispatch > xDisp = xProv.is() ?
959 			xProv->queryDispatch( aURL, aTarget, 0 ) : Reference < XDispatch >();
960 
961 		if ( xDisp.is() )
962 		{
963 			if ( bPreview )
964 			{
965 				if ( m_aOpenURL != aURL.Complete )
966 				{
967 					WaitObject aWaitCursor( GetParent() );
968 	                // disabling must be done here, does not work in ctor because
969 	                // execute of the dialog will overwrite it
970 	                // ( own execute method would help )
971 	                pTextWin->EnableInput( sal_False, sal_True );
972 					if ( pTextWin->IsReallyVisible() )
973 					{
974 						sal_Bool	b = sal_True;
975 						Sequence < PropertyValue > aArgs( 4 );
976 	        			aArgs[0].Name = ASCII_STR("Preview");
977 						aArgs[0].Value.setValue( &b, ::getBooleanCppuType() );
978 	        			aArgs[1].Name = ASCII_STR("ReadOnly");
979 						aArgs[1].Value.setValue( &b, ::getBooleanCppuType() );
980 	        			aArgs[2].Name = ASCII_STR("AsTemplate");	// prevents getting an empty URL with getURL()!
981 
982 						uno::Reference < task::XInteractionHandler > xInteractionHandler( ::comphelper::getProcessServiceFactory()->createInstance(
983 							::rtl::OUString::createFromAscii("com.sun.star.task.InteractionHandler") ), uno::UNO_QUERY );
984 						aArgs[3].Name = ::rtl::OUString::createFromAscii("InteractionHandler");
985 						aArgs[3].Value <<= xInteractionHandler;
986 
987 						b = sal_False;
988 	        			aArgs[2].Value.setValue( &b, ::getBooleanCppuType() );
989 	        			xDisp->dispatch( aURL, aArgs );
990 
991 						::rtl::OUString											aDispURL;
992 						Reference< ::com::sun::star::frame::XController >		xCtrl = xFrame->getController();
993 						if( xCtrl.is() )
994 						{
995 							Reference< ::com::sun::star::frame::XModel >		xMdl = xCtrl->getModel();
996 							if( xMdl.is() )
997 								aDispURL = xMdl->getURL();
998 						}
999 
1000 						if( aDispURL != aURL.Complete )
1001 						{
1002 							xFrame->setComponent( Reference < com::sun::star::awt::XWindow >(), Reference < XController >() );
1003 							ViewEmptyWin();
1004 							m_aOpenURL = rtl::OUString();
1005 						}
1006 						else
1007 							m_aOpenURL = aDispURL;
1008 					}
1009 				}
1010 			}
1011 			else if ( bIsTemplate )
1012 			{
1013 				Sequence < PropertyValue > aArgs( 1 );
1014         		aArgs[0].Name = ASCII_STR("AsTemplate");
1015         		aArgs[0].Value <<= bAsTemplate;
1016         		xDisp->dispatch( aURL, aArgs );
1017 				m_aOpenURL = rtl::OUString();
1018 			}
1019 			else
1020 			{
1021 			/*
1022                 SvtExecuteInfo* pExecuteInfo = new SvtExecuteInfo;
1023                 pExecuteInfo->xDispatch = xDisp;
1024                 pExecuteInfo->aTargetURL = aURL;
1025                 Application::PostUserEvent(
1026                     STATIC_LINK(0, SvtFrameWindow_Impl, ExecuteHdl_Impl), pExecuteInfo );
1027             */
1028 				Sequence < PropertyValue > aArgs;
1029         		xDisp->dispatch( aURL, aArgs );
1030 				m_aOpenURL = rtl::OUString();
1031 			}
1032 		}
1033 	}
1034 }
1035 
1036 void SvtFrameWindow_Impl::ToggleView( sal_Bool bDI )
1037 {
1038 	bDocInfo = bDI;
1039 
1040 	// view is set properly in OpenFile()
1041 
1042 	OpenFile( aCurrentURL, sal_True, sal_False, sal_False );
1043 }
1044 
1045 // class SvtTemplateWindow -----------------------------------------------
1046 
1047 SvtTemplateWindow::SvtTemplateWindow( Window* pParent ) :
1048 
1049 	Window( pParent, WB_DIALOGCONTROL ),
1050 
1051 	aFileViewTB				( this, SvtResId( TB_SVT_FILEVIEW ) ),
1052 	aFrameWinTB				( this, SvtResId( TB_SVT_FRAMEWIN ) ),
1053 	aSplitWin				( this, WB_DIALOGCONTROL | WB_NOSPLITDRAW ),
1054 	pHistoryList			( NULL )
1055 
1056 {
1057 	// create windows
1058 	pIconWin = new SvtIconWindow_Impl( this );
1059 	pFileWin = new SvtFileViewWindow_Impl( this );
1060 	pFileWin->SetMyDocumentsURL( pIconWin->GetMyDocumentsRootURL() );
1061 	pFileWin->SetSamplesFolderURL( pIconWin->GetSamplesFolderURL() );
1062 	pFrameWin = new SvtFrameWindow_Impl( this );
1063 
1064 	// set handlers
1065 	pIconWin->SetClickHdl( LINK( this, SvtTemplateWindow, IconClickHdl_Impl ) );
1066 	pFileWin->SetSelectHdl( LINK( this, SvtTemplateWindow, FileSelectHdl_Impl ) );
1067 	pFileWin->SetDoubleClickHdl( LINK( this, SvtTemplateWindow, FileDblClickHdl_Impl ) );
1068 	pFileWin->SetNewFolderHdl( LINK( this, SvtTemplateWindow, NewFolderHdl_Impl ) );
1069 
1070 	// create the split items
1071 	aSplitWin.SetAlign( WINDOWALIGN_LEFT );
1072     long nWidth = pIconWin->GetMaxTextLength() * 8 / 7 + 1;	// extra space for border
1073 	aSplitWin.InsertItem( ICONWIN_ID, pIconWin, nWidth, SPLITWINDOW_APPEND, 0, SWIB_FIXED );
1074 	aSplitWin.InsertItem( FILEWIN_ID, pFileWin, 50, SPLITWINDOW_APPEND, 0, SWIB_PERCENTSIZE );
1075 	aSplitWin.InsertItem( FRAMEWIN_ID, pFrameWin, 50, SPLITWINDOW_APPEND, 0, SWIB_PERCENTSIZE );
1076 	aSplitWin.SetSplitHdl( LINK( this, SvtTemplateWindow, ResizeHdl_Impl ) );
1077 
1078 	// show the windows
1079 	pIconWin->Show();
1080 	pFileWin->Show();
1081 	pFrameWin->Show();
1082 	aSplitWin.Show();
1083 
1084 	// initialize the timers
1085 	aSelectTimer.SetTimeout( 200 );
1086 	aSelectTimer.SetTimeoutHdl( LINK( this, SvtTemplateWindow, TimeoutHdl_Impl ) );
1087 
1088 	// initialize the toolboxes and then show them
1089 	InitToolBoxes();
1090 	aFileViewTB.Show();
1091 	aFrameWinTB.Show();
1092 
1093 	ReadViewSettings( );
1094 
1095 	Application::PostUserEvent( LINK( this, SvtTemplateWindow, ResizeHdl_Impl ) );
1096 }
1097 
1098 // ------------------------------------------------------------------------
1099 
1100 SvtTemplateWindow::~SvtTemplateWindow()
1101 {
1102 	WriteViewSettings( );
1103 
1104 	delete pIconWin;
1105 	delete pFileWin;
1106 	delete pFrameWin;
1107 	if ( pHistoryList )
1108 	{
1109 		for ( sal_uInt32 i = 0; i < pHistoryList->Count(); ++i )
1110 			delete pHistoryList->GetObject(i);
1111 		delete pHistoryList;
1112 	}
1113 }
1114 
1115 // ------------------------------------------------------------------------
1116 
1117 IMPL_LINK ( SvtTemplateWindow , IconClickHdl_Impl, SvtIconChoiceCtrl *, EMPTYARG )
1118 {
1119 	String aURL = pIconWin->GetSelectedIconURL();
1120 	if ( !aURL.Len() )
1121 		aURL = pIconWin->GetCursorPosIconURL();
1122 	if ( pFileWin->GetRootURL() != aURL )
1123 	{
1124 		pFileWin->OpenRoot( aURL );
1125 		pIconWin->InvalidateIconControl();
1126 		aFileViewTB.EnableItem( TI_DOCTEMPLATE_PRINT, sal_False );
1127 	}
1128 	return 0;
1129 }
1130 
1131 // ------------------------------------------------------------------------
1132 
1133 IMPL_LINK ( SvtTemplateWindow , FileSelectHdl_Impl, SvtFileView *, EMPTYARG )
1134 {
1135 	aSelectTimer.Start();
1136 	return 0;
1137 }
1138 
1139 // ------------------------------------------------------------------------
1140 
1141 IMPL_LINK ( SvtTemplateWindow , FileDblClickHdl_Impl, SvtFileView *, EMPTYARG )
1142 {
1143 	if ( aSelectTimer.IsActive() )
1144 		aSelectTimer.Stop();
1145 
1146 	String aURL = pFileWin->GetSelectedFile();
1147     if ( aURL.Len() > 0 )
1148     {
1149         if ( ::utl::UCBContentHelper::IsFolder( aURL ) )
1150             pFileWin->OpenFolder( aURL );
1151         else
1152             aDoubleClickHdl.Call( this );
1153     }
1154 
1155     return 0;
1156 }
1157 
1158 // ------------------------------------------------------------------------
1159 
1160 IMPL_LINK ( SvtTemplateWindow , NewFolderHdl_Impl, SvtFileView *, EMPTYARG )
1161 {
1162 	pFrameWin->OpenFile( String(), sal_True, sal_False, sal_False );
1163 	aFileViewTB.EnableItem( TI_DOCTEMPLATE_PRINT, sal_False );
1164 
1165 	String sURL = pFileWin->GetFolderURL();
1166 	sal_uLong nPos = pIconWin->GetRootPos( sURL );
1167 	AppendHistoryURL( sURL, nPos );
1168 
1169 	aNewFolderHdl.Call( this );
1170 	return 0;
1171 }
1172 
1173 // ------------------------------------------------------------------------
1174 
1175 IMPL_LINK ( SvtTemplateWindow , TimeoutHdl_Impl, Timer *, EMPTYARG )
1176 {
1177     aSelectHdl.Call( this );
1178     String sURL = pFileWin->GetSelectedFile();
1179     sal_Bool bIsNewDoc = ( pIconWin->GetSelectEntryPos() == ICON_POS_NEWDOC );
1180     sal_Bool bIsFile = ( sURL.Len() != 0 && !::utl::UCBContentHelper::IsFolder( sURL ) &&
1181                          INetURLObject( sURL ).GetProtocol() != INET_PROT_PRIVATE && !bIsNewDoc );
1182     aFileViewTB.EnableItem( TI_DOCTEMPLATE_PRINT, bIsFile );
1183     aFrameWinTB.EnableItem( TI_DOCTEMPLATE_PREVIEW, !bIsNewDoc );
1184 
1185     if ( bIsFile )
1186         pFrameWin->OpenFile( sURL, sal_True, sal_False, sal_False );
1187     else if ( bIsNewDoc && aFrameWinTB.IsItemChecked( TI_DOCTEMPLATE_PREVIEW ) )
1188     {
1189         aFrameWinTB.CheckItem( TI_DOCTEMPLATE_DOCINFO );
1190         DoAction( TI_DOCTEMPLATE_DOCINFO );
1191     }
1192     return 0;
1193 }
1194 
1195 // ------------------------------------------------------------------------
1196 
1197 IMPL_LINK ( SvtTemplateWindow , ClickHdl_Impl, ToolBox *, pToolBox )
1198 {
1199 	DoAction( pToolBox->GetCurItemId() );
1200 	return 0;
1201 }
1202 
1203 // ------------------------------------------------------------------------
1204 
1205 IMPL_LINK ( SvtTemplateWindow , ResizeHdl_Impl, SplitWindow *, EMPTYARG )
1206 {
1207 	Resize();
1208 	return 0;
1209 }
1210 
1211 // ------------------------------------------------------------------------
1212 
1213 void SvtTemplateWindow::PrintFile( const String& rURL )
1214 {
1215 	// open the file readonly and hidden
1216 	Sequence < PropertyValue > aArgs( 2 );
1217     aArgs[0].Name = ASCII_STR("ReadOnly");
1218     aArgs[0].Value <<= sal_True;
1219 	aArgs[1].Name = ASCII_STR("Hidden");
1220     aArgs[1].Value <<= sal_True;
1221 
1222 	Reference < XComponentLoader > xDesktop( ::comphelper::getProcessServiceFactory()->
1223 		createInstance( ASCII_STR("com.sun.star.frame.Desktop") ), UNO_QUERY );
1224     Reference < XModel > xModel( xDesktop->loadComponentFromURL(
1225 		rURL, ASCII_STR("_blank"), 0, aArgs ), UNO_QUERY );
1226     if ( xModel.is() )
1227 	{
1228 		// print
1229     	Reference < XPrintable > xPrintable( xModel, UNO_QUERY );
1230 		if ( xPrintable.is() )
1231 			xPrintable->print( Sequence < PropertyValue >() );
1232 	}
1233 }
1234 
1235 // ------------------------------------------------------------------------
1236 
1237 void SvtTemplateWindow::AppendHistoryURL( const String& rURL, sal_uLong nGroup )
1238 {
1239 	sal_Bool bInsert = sal_True;
1240 	if ( !pHistoryList )
1241 		pHistoryList = new HistoryList_Impl;
1242 	else if ( pHistoryList->Count() > 0 )
1243 	{
1244 		FolderHistory* pLastEntry = pHistoryList->GetObject( pHistoryList->Count() - 1 );
1245 		bInsert = ( rURL != pLastEntry->m_sURL);
1246 	}
1247 
1248 	if ( bInsert )
1249 	{
1250 		FolderHistory* pEntry = new FolderHistory( rURL, nGroup );
1251 		pHistoryList->Insert( pEntry, LIST_APPEND );
1252 		aFileViewTB.EnableItem( TI_DOCTEMPLATE_BACK, pHistoryList->Count() > 1 );
1253 	}
1254 }
1255 
1256 // ------------------------------------------------------------------------
1257 
1258 void SvtTemplateWindow::OpenHistory()
1259 {
1260 	FolderHistory* pEntry = pHistoryList->Remove( pHistoryList->Count() - 1 );
1261 	pEntry = pHistoryList->Remove( pHistoryList->Count() - 1 );
1262 	aFileViewTB.EnableItem( TI_DOCTEMPLATE_BACK, pHistoryList->Count() > 1 );
1263 	pFileWin->OpenFolder( pEntry->m_sURL );
1264 	pIconWin->SetCursorPos( pEntry->m_nGroup );
1265 	delete pEntry;
1266 }
1267 
1268 // ------------------------------------------------------------------------
1269 
1270 void SvtTemplateWindow::DoAction( sal_uInt16 nAction )
1271 {
1272 	switch( nAction )
1273 	{
1274 		case TI_DOCTEMPLATE_BACK :
1275 		{
1276 			if ( pHistoryList && pHistoryList->Count() > 1 )
1277 				OpenHistory();
1278 			break;
1279 		}
1280 
1281 		case TI_DOCTEMPLATE_PREV :
1282 		{
1283 			String aURL;
1284 			if ( pFileWin->HasPreviousLevel( aURL ) )
1285 				pFileWin->OpenFolder( aURL );
1286 			break;
1287 		}
1288 
1289 		case TI_DOCTEMPLATE_PRINT :
1290 		{
1291 			String sPrintFile( pFileWin->GetSelectedFile() );
1292 			if ( sPrintFile.Len() > 0 )
1293 				PrintFile( sPrintFile );
1294 			break;
1295 		}
1296 
1297 		case TI_DOCTEMPLATE_DOCINFO :
1298 		case TI_DOCTEMPLATE_PREVIEW :
1299 		{
1300 			pFrameWin->ToggleView( TI_DOCTEMPLATE_DOCINFO == nAction );
1301 			break;
1302 		}
1303 	}
1304 }
1305 
1306 // ------------------------------------------------------------------------
1307 
1308 void SvtTemplateWindow::InitToolBoxes()
1309 {
1310 	InitToolBoxImages();
1311 
1312 	Size aSize = aFileViewTB.CalcWindowSizePixel();
1313 	aSize.Height() += 4;
1314 	aFileViewTB.SetPosSizePixel( Point( 0, 2 ), aSize );
1315 	aSize = aFrameWinTB.CalcWindowSizePixel();
1316 	aSize.Height() += 4;
1317 	aFrameWinTB.SetPosSizePixel( Point( pFrameWin->GetPosPixel().X() + 2, 2 ), aSize );
1318 
1319 	sal_Bool bFlat = ( SvtMiscOptions().GetToolboxStyle() == TOOLBOX_STYLE_FLAT );
1320 	if ( bFlat )
1321 	{
1322 		aFileViewTB.SetOutStyle( TOOLBOX_STYLE_FLAT );
1323 		aFrameWinTB.SetOutStyle( TOOLBOX_STYLE_FLAT );
1324 	}
1325 
1326 	aFileViewTB.EnableItem( TI_DOCTEMPLATE_BACK, sal_False );
1327 	aFileViewTB.EnableItem( TI_DOCTEMPLATE_PREV, sal_False );
1328 	aFileViewTB.EnableItem( TI_DOCTEMPLATE_PRINT, sal_False );
1329 
1330 	Link aLink = LINK( this, SvtTemplateWindow, ClickHdl_Impl );
1331 	aFileViewTB.SetClickHdl( aLink );
1332 	aFrameWinTB.SetClickHdl( aLink );
1333 }
1334 
1335 // ------------------------------------------------------------------------
1336 
1337 void SvtTemplateWindow::InitToolBoxImages()
1338 {
1339 	SvtMiscOptions aMiscOpt;
1340 	sal_Bool bLarge = aMiscOpt.AreCurrentSymbolsLarge();
1341 	sal_Bool bHiContrast = aFileViewTB.GetSettings().GetStyleSettings().GetHighContrastMode();
1342 
1343 	aFileViewTB.SetItemImage( TI_DOCTEMPLATE_BACK, Image( SvtResId(
1344 		bLarge ? bHiContrast ? IMG_SVT_DOCTEMPL_HC_BACK_LARGE : IMG_SVT_DOCTEMPLATE_BACK_LARGE
1345 			   : bHiContrast ? IMG_SVT_DOCTEMPL_HC_BACK_SMALL : IMG_SVT_DOCTEMPLATE_BACK_SMALL ) ) );
1346 	aFileViewTB.SetItemImage( TI_DOCTEMPLATE_PREV, Image( SvtResId(
1347 		bLarge ? bHiContrast ? IMG_SVT_DOCTEMPL_HC_PREV_LARGE : IMG_SVT_DOCTEMPLATE_PREV_LARGE
1348 			   : bHiContrast ? IMG_SVT_DOCTEMPL_HC_PREV_SMALL : IMG_SVT_DOCTEMPLATE_PREV_SMALL ) ) );
1349 	aFileViewTB.SetItemImage( TI_DOCTEMPLATE_PRINT, Image( SvtResId(
1350 		bLarge ? bHiContrast ? IMG_SVT_DOCTEMPL_HC_PRINT_LARGE : IMG_SVT_DOCTEMPLATE_PRINT_LARGE
1351 			   : bHiContrast ? IMG_SVT_DOCTEMPL_HC_PRINT_SMALL : IMG_SVT_DOCTEMPLATE_PRINT_SMALL ) ) );
1352 
1353 	aFrameWinTB.SetItemImage( TI_DOCTEMPLATE_DOCINFO, Image( SvtResId(
1354 		bLarge ? bHiContrast ? IMG_SVT_DOCTEMPL_HC_DOCINFO_LARGE : IMG_SVT_DOCTEMPLATE_DOCINFO_LARGE
1355 			   : bHiContrast ? IMG_SVT_DOCTEMPL_HC_DOCINFO_SMALL : IMG_SVT_DOCTEMPLATE_DOCINFO_SMALL ) ) );
1356 	aFrameWinTB.SetItemImage( TI_DOCTEMPLATE_PREVIEW, Image( SvtResId(
1357 		bLarge ? bHiContrast ? IMG_SVT_DOCTEMPL_HC_PREVIEW_LARGE : IMG_SVT_DOCTEMPLATE_PREVIEW_LARGE
1358 			   : bHiContrast ? IMG_SVT_DOCTEMPL_HC_PREVIEW_SMALL : IMG_SVT_DOCTEMPLATE_PREVIEW_SMALL ) ) );
1359 }
1360 
1361 // ------------------------------------------------------------------------
1362 
1363 void SvtTemplateWindow::UpdateIcons()
1364 {
1365 	pIconWin->UpdateIcons( aFileViewTB.GetSettings().GetStyleSettings().GetHighContrastMode() );
1366 }
1367 
1368 // ------------------------------------------------------------------------
1369 
1370 long SvtTemplateWindow::PreNotify( NotifyEvent& rNEvt )
1371 {
1372 	sal_uInt16 nType = rNEvt.GetType();
1373 	long nRet = 0;
1374 
1375 	if ( EVENT_KEYINPUT == nType && rNEvt.GetKeyEvent() )
1376 	{
1377 		const KeyCode& rKeyCode = rNEvt.GetKeyEvent()->GetKeyCode();
1378 		sal_uInt16 nCode = rKeyCode.GetCode();
1379 
1380 		if ( KEY_BACKSPACE == nCode && !rKeyCode.GetModifier() && pFileWin->HasChildPathFocus() )
1381 		{
1382 			DoAction( TI_DOCTEMPLATE_BACK );
1383 			nRet = 1;
1384 		}
1385 		else if ( pIconWin->ProcessKeyEvent( *rNEvt.GetKeyEvent() ) )
1386 		{
1387 			nRet = 1;
1388 		}
1389 	}
1390 
1391 	return nRet ? nRet : Window::PreNotify( rNEvt );
1392 }
1393 
1394 // -----------------------------------------------------------------------------
1395 
1396 void SvtTemplateWindow::DataChanged( const DataChangedEvent& rDCEvt )
1397 {
1398 	Window::DataChanged( rDCEvt );
1399 
1400 	if ( ( ( rDCEvt.GetType() == DATACHANGED_SETTINGS )	||
1401 		   ( rDCEvt.GetType() == DATACHANGED_DISPLAY ) ) &&
1402 		 ( rDCEvt.GetFlags() & SETTINGS_STYLE ) )
1403 	{
1404 		// update of the background for the area left of the FileView toolbox
1405 		SetBackground( Wallpaper( GetSettings().GetStyleSettings().GetFaceColor() ) );
1406 		// update of the images of the IconChoiceControl
1407 		UpdateIcons();
1408 		// update of the toolbox images
1409 		InitToolBoxImages();
1410 	}
1411 }
1412 // ------------------------------------------------------------------------
1413 
1414 void SvtTemplateWindow::Resize()
1415 {
1416 	long nItemSize = aSplitWin.GetItemSize( ICONWIN_ID );
1417 	long nSplitterWidth = Splitter( this, 0 ).GetSizePixel().Width();
1418 
1419 	Point aPos = aFileViewTB.GetPosPixel();
1420 	aPos.X() = nItemSize + nSplitterWidth / 2;
1421 	aFileViewTB.SetPosPixel( aPos );
1422 
1423 	Size aWinSize = GetOutputSizePixel();
1424 	long nWidth = aWinSize.Width() - aPos.X();
1425 
1426 	nItemSize = nWidth * aSplitWin.GetItemSize( FILEWIN_ID ) / 100;
1427 	aPos.X() = pFrameWin->GetPosPixel().X() + 2;
1428 	aFrameWinTB.SetPosPixel( aPos );
1429 
1430 	Size aSize = aFileViewTB.GetSizePixel();
1431 	aSize.Width() = nItemSize;
1432 	aFileViewTB.SetSizePixel( aSize );
1433 
1434 	aSize = aFrameWinTB.GetSizePixel();
1435 	aSize.Width() = nWidth - nItemSize;
1436 	aFrameWinTB.SetSizePixel( aSize );
1437 
1438 	long nToolBoxHeight = aSize.Height() + aFrameWinTB.GetPosPixel().Y();
1439 	aSize = aWinSize;
1440 	aSize.Height() -= nToolBoxHeight;
1441 	aSplitWin.SetPosSizePixel( Point( 0, nToolBoxHeight  ), aSize );
1442 }
1443 
1444 // ------------------------------------------------------------------------
1445 
1446 String SvtTemplateWindow::GetSelectedFile() const
1447 {
1448 	return pFileWin->GetSelectedFile();
1449 }
1450 
1451 // ------------------------------------------------------------------------
1452 
1453 sal_Bool SvtTemplateWindow::IsFileSelected() const
1454 {
1455 	String aURL = pFileWin->GetSelectedFile();
1456 	sal_Bool bRet = ( aURL.Len() > 0 && !::utl::UCBContentHelper::IsFolder( aURL ) );
1457 	return bRet;
1458 }
1459 
1460 // ------------------------------------------------------------------------
1461 
1462 void SvtTemplateWindow::OpenFile( sal_Bool bNotAsTemplate )
1463 {
1464 	String aURL = pFileWin->GetSelectedFile();
1465 	if ( aURL.Len() > 0 && !::utl::UCBContentHelper::IsFolder( aURL ) )
1466 		pFrameWin->OpenFile( aURL, sal_False, pFileWin->IsTemplateFolder(), !bNotAsTemplate );
1467 }
1468 
1469 // ------------------------------------------------------------------------
1470 
1471 String SvtTemplateWindow::GetFolderTitle() const
1472 {
1473 	String sTitle;
1474 	String sFolderURL = pFileWin->GetFolderURL();
1475 	if ( pIconWin->IsRootURL( sFolderURL ) )
1476 		sTitle = pIconWin->GetIconText( sFolderURL );
1477 	else
1478 		sTitle = pFileWin->GetFolderTitle();
1479 	return sTitle;
1480 }
1481 
1482 // ------------------------------------------------------------------------
1483 
1484 String SvtTemplateWindow::GetFolderURL() const
1485 {
1486 	return pFileWin->GetFolderURL();
1487 }
1488 
1489 
1490 // ------------------------------------------------------------------------
1491 
1492 void SvtTemplateWindow::SetFocus( sal_Bool bIconWin )
1493 {
1494 	if ( bIconWin )
1495 		pIconWin->SetFocus();
1496 	else
1497 		pFileWin->SetFocus();
1498 }
1499 
1500 // ------------------------------------------------------------------------
1501 
1502 void SvtTemplateWindow::OpenTemplateRoot()
1503 {
1504 	pFileWin->OpenFolder( pIconWin->GetTemplateRootURL() );
1505 }
1506 
1507 // ------------------------------------------------------------------------
1508 
1509 void SvtTemplateWindow::SetPrevLevelButtonState( const String& rURL )
1510 {
1511 	// disable the prev level button on root folder of the icon pane (except My Documents)
1512 	// and on the root of all (file:/// -> count == 0)
1513 	INetURLObject aObj( rURL );
1514 	sal_Int32 nCount = aObj.getSegmentCount();
1515 	sal_Bool bEnable =
1516 		( nCount > 0 &&
1517 			( !pIconWin->IsRootURL( rURL ) || rURL == pIconWin->GetMyDocumentsRootURL() ) );
1518 	aFileViewTB.EnableItem( TI_DOCTEMPLATE_PREV, bEnable );
1519 }
1520 
1521 // ------------------------------------------------------------------------
1522 
1523 void SvtTemplateWindow::ClearHistory()
1524 {
1525 	if( pHistoryList )
1526 		pHistoryList->Clear();
1527 }
1528 
1529 // ------------------------------------------------------------------------
1530 
1531 long SvtTemplateWindow::CalcHeight() const
1532 {
1533 	// toolbox height
1534 	long nHeight = aFileViewTB.GetSizePixel().Height();
1535 	// + iconwin height
1536 	nHeight += pIconWin->CalcHeight();
1537 	// + little offset
1538 	nHeight += 8;
1539 	return nHeight;
1540 }
1541 
1542 // ------------------------------------------------------------------------
1543 
1544 void SvtTemplateWindow::ReadViewSettings()
1545 {
1546 	// defaults
1547 	sal_Int32 nSelectedGroup	=	ICON_POS_TEMPLATES;
1548 	sal_Int32 nSelectedView		=	TI_DOCTEMPLATE_DOCINFO;
1549 	double nSplitRatio			=	0.5;
1550 	::rtl::OUString sLastFolder;
1551 
1552 	SvtViewOptions aViewSettings( E_DIALOG, VIEWSETTING_NEWFROMTEMPLATE );
1553 	if ( aViewSettings.Exists() )
1554 	{
1555 		// read the settings
1556 		Sequence< NamedValue > aSettings = aViewSettings.GetUserData( );
1557 
1558 		aViewSettings.GetUserItem( VIEWSETTING_SELECTEDGROUP ) >>= nSelectedGroup;
1559 		aViewSettings.GetUserItem( VIEWSETTING_SELECTEDVIEW ) >>= nSelectedView;
1560 		aViewSettings.GetUserItem( VIEWSETTING_SPLITRATIO ) >>= nSplitRatio;
1561 		aViewSettings.GetUserItem( VIEWSETTING_LASTFOLDER ) >>= sLastFolder;
1562 	}
1563 	// normalize
1564 	if ( nSelectedGroup < ICON_POS_NEWDOC )		nSelectedGroup = ICON_POS_NEWDOC;
1565 	if ( nSelectedGroup > ICON_POS_SAMPLES )	nSelectedGroup = ICON_POS_SAMPLES;
1566 
1567 	if ( ( TI_DOCTEMPLATE_DOCINFO != nSelectedView ) && ( TI_DOCTEMPLATE_PREVIEW != nSelectedView ) )
1568 		nSelectedView = TI_DOCTEMPLATE_DOCINFO;
1569 
1570 	if ( nSplitRatio < 0.2 ) nSplitRatio = 0.2;
1571 	if ( nSplitRatio > 0.8 ) nSplitRatio = 0.8;
1572 
1573 	// change our view according to the settings
1574 
1575 	// the selected view (details or preview)
1576 	pFrameWin->ToggleView( TI_DOCTEMPLATE_DOCINFO == nSelectedView );
1577 	aFrameWinTB.CheckItem( (sal_uInt16)nSelectedView, sal_True );
1578 
1579 	// the split ratio
1580 	sal_Int32 nSplitFileAndFrameSize = aSplitWin.GetItemSize( FILEWIN_ID ) + aSplitWin.GetItemSize( FRAMEWIN_ID );
1581 	sal_Int32 nSplitFileSize = (sal_Int32)(nSplitFileAndFrameSize * nSplitRatio);
1582 	sal_Int32 nSplitFrameSize = nSplitFileAndFrameSize - nSplitFileSize;
1583 	aSplitWin.SetItemSize( FILEWIN_ID, nSplitFileSize );
1584 	aSplitWin.SetItemSize( FRAMEWIN_ID, nSplitFrameSize );
1585 	Resize();
1586 
1587 	// the selected folder
1588 	pIconWin->SetCursorPos( nSelectedGroup );
1589 
1590 	// open the last folder or the selected group
1591 	if ( sLastFolder.getLength() > 0 )
1592 		pFileWin->OpenFolder( sLastFolder );
1593 	else
1594 		IconClickHdl_Impl( NULL );
1595 }
1596 
1597 // ------------------------------------------------------------------------
1598 
1599 void SvtTemplateWindow::WriteViewSettings()
1600 {
1601 	// collect
1602 	Sequence< NamedValue > aSettings(4);
1603 
1604 	// the selected group
1605 	aSettings[0].Name	=	VIEWSETTING_SELECTEDGROUP;
1606 	pIconWin->SetFocus();
1607 	aSettings[0].Value	<<=	(sal_Int32)pIconWin->GetCursorPos( );
1608 
1609 	// the selected view mode
1610 	aSettings[1].Name	=	VIEWSETTING_SELECTEDVIEW;
1611 	aSettings[1].Value	<<=	sal_Int32( aFrameWinTB.IsItemChecked( TI_DOCTEMPLATE_DOCINFO ) ? TI_DOCTEMPLATE_DOCINFO : TI_DOCTEMPLATE_PREVIEW );
1612 
1613 	// the split ratio
1614 	aSettings[2].Name	=	VIEWSETTING_SPLITRATIO;
1615 	sal_Int32 nSplitFileSize = aSplitWin.GetItemSize( FILEWIN_ID );
1616 	sal_Int32 nSplitFileAndFrameSize = nSplitFileSize + aSplitWin.GetItemSize( FRAMEWIN_ID );
1617 	aSettings[2].Value	<<=	double( 1.0 * nSplitFileSize / nSplitFileAndFrameSize );
1618 
1619 	// last folder
1620 	aSettings[3].Name	=	VIEWSETTING_LASTFOLDER;
1621 	aSettings[3].Value	<<=	::rtl::OUString( pFileWin->GetFolderURL() );
1622 
1623 	// write
1624 	SvtViewOptions aViewSettings( E_DIALOG, VIEWSETTING_NEWFROMTEMPLATE );
1625 	aViewSettings.SetUserData( aSettings );
1626 }
1627 /* -----------------27.11.2002 17:20-----------------
1628  *
1629  * --------------------------------------------------*/
1630 
1631 void SvtTemplateWindow::SelectFolder(sal_Int32 nFolderPosition)
1632 {
1633     pIconWin->SelectFolder(nFolderPosition);
1634 }
1635 // struct SvtTmplDlg_Impl ------------------------------------------------
1636 
1637 struct SvtTmplDlg_Impl
1638 {
1639 	SvtTemplateWindow*	pWin;
1640 	String				aTitle;
1641 	Timer				aUpdateTimer;
1642 	sal_Bool			bSelectNoOpen;
1643 
1644 	uno::Reference< util::XOfficeInstallationDirectories > m_xOfficeInstDirs;
1645 
1646 
1647 	SvtTmplDlg_Impl( Window* pParent ) : pWin( new SvtTemplateWindow( pParent ) ) ,bSelectNoOpen( sal_False ) {}
1648 
1649 	~SvtTmplDlg_Impl() { delete pWin; }
1650 
1651 	uno::Reference< util::XOfficeInstallationDirectories > getOfficeInstDirs();
1652 };
1653 
1654 uno::Reference< util::XOfficeInstallationDirectories > SvtTmplDlg_Impl::getOfficeInstDirs()
1655 {
1656 	if ( !m_xOfficeInstDirs.is() )
1657 	{
1658 		try
1659 		{
1660 			uno::Reference< lang::XMultiServiceFactory > xSMgr = comphelper::getProcessServiceFactory();
1661 
1662 			uno::Reference< beans::XPropertySet > xPropSet( xSMgr, uno::UNO_QUERY );
1663 			if ( xPropSet.is() )
1664 			{
1665 				uno::Reference< uno::XComponentContext > xCtx;
1666 				xPropSet->getPropertyValue(
1667 					rtl::OUString(
1668 						RTL_CONSTASCII_USTRINGPARAM( "DefaultContext" ) ) )
1669 				>>= xCtx;
1670 
1671 				if ( xCtx.is() )
1672 				{
1673 					xCtx->getValueByName(
1674 						rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
1675 							"/singletons/com.sun.star.util.theOfficeInstallationDirectories" ) ) )
1676 					>>= m_xOfficeInstDirs;
1677 				}
1678 			}
1679 		}
1680 		catch( uno::Exception& )
1681 		{}
1682 	}
1683 
1684 	return m_xOfficeInstDirs;
1685 }
1686 
1687 // class SvtDocumentTemplateDialog ---------------------------------------
1688 
1689 SvtDocumentTemplateDialog::SvtDocumentTemplateDialog( Window* _pParent, SelectOnly ) :
1690 	ModalDialog( _pParent, SvtResId( DLG_DOCTEMPLATE ) ),
1691 
1692     aMoreTemplatesLink  ( this, SvtResId( FT_DOCTEMPLATE_LINK ) ),
1693     aLine               ( this, SvtResId( FL_DOCTEMPLATE ) ),
1694     aManageBtn          ( this, SvtResId( BTN_DOCTEMPLATE_MANAGE ) ),
1695     aEditBtn            ( this, SvtResId( BTN_DOCTEMPLATE_EDIT ) ),
1696     aOKBtn              ( this, SvtResId( BTN_DOCTEMPLATE_OPEN ) ),
1697     aCancelBtn          ( this, SvtResId( BTN_DOCTEMPLATE_CANCEL ) ),
1698     aHelpBtn            ( this, SvtResId( BTN_DOCTEMPLATE_HELP ) ),
1699     pImpl               ( NULL )
1700 {
1701 	FreeResource();
1702 	InitImpl( );
1703 
1704 	// no editing of templates
1705 	aEditBtn.Hide();
1706 
1707 	pImpl->bSelectNoOpen = sal_True;
1708 }
1709 
1710 // ------------------------------------------------------------------------
1711 
1712 SvtDocumentTemplateDialog::SvtDocumentTemplateDialog( Window* pParent ) :
1713 
1714 	ModalDialog( pParent, SvtResId( DLG_DOCTEMPLATE ) ),
1715 
1716     aMoreTemplatesLink  ( this, SvtResId( FT_DOCTEMPLATE_LINK ) ),
1717     aLine               ( this, SvtResId( FL_DOCTEMPLATE ) ),
1718     aManageBtn          ( this, SvtResId( BTN_DOCTEMPLATE_MANAGE ) ),
1719     aEditBtn            ( this, SvtResId( BTN_DOCTEMPLATE_EDIT ) ),
1720     aOKBtn              ( this, SvtResId( BTN_DOCTEMPLATE_OPEN ) ),
1721     aCancelBtn          ( this, SvtResId( BTN_DOCTEMPLATE_CANCEL ) ),
1722     aHelpBtn            ( this, SvtResId( BTN_DOCTEMPLATE_HELP ) ),
1723     pImpl               ( NULL )
1724 {
1725 	FreeResource();
1726 	InitImpl( );
1727 }
1728 
1729 // ------------------------------------------------------------------------
1730 
1731 void SvtDocumentTemplateDialog::InitImpl( )
1732 {
1733 	pImpl = new SvtTmplDlg_Impl( this );
1734 	pImpl->aTitle = GetText();
1735 
1736 	bool bHideLink = ( SvtExtendedSecurityOptions().GetOpenHyperlinkMode()
1737 					== SvtExtendedSecurityOptions::OPEN_NEVER );
1738 	if ( !bHideLink )
1739      	{
1740     aMoreTemplatesLink.SetURL( String(
1741         RTL_CONSTASCII_STRINGPARAM( "http://templates.services.openoffice.org/?cid=923508" ) ) );
1742     aMoreTemplatesLink.SetClickHdl( LINK( this, SvtDocumentTemplateDialog, OpenLinkHdl_Impl ) );
1743 	}
1744 	else
1745 	   aMoreTemplatesLink.Hide();
1746 
1747     aManageBtn.SetClickHdl( LINK( this, SvtDocumentTemplateDialog, OrganizerHdl_Impl ) );
1748 	Link aLink = LINK( this, SvtDocumentTemplateDialog, OKHdl_Impl );
1749 	aEditBtn.SetClickHdl( aLink );
1750 	aOKBtn.SetClickHdl( aLink );
1751 
1752 	pImpl->pWin->SetSelectHdl( LINK( this, SvtDocumentTemplateDialog, SelectHdl_Impl ) );
1753 	pImpl->pWin->SetDoubleClickHdl( LINK( this, SvtDocumentTemplateDialog, DoubleClickHdl_Impl ) );
1754 	pImpl->pWin->SetNewFolderHdl( LINK( this, SvtDocumentTemplateDialog, NewFolderHdl_Impl ) );
1755 	pImpl->pWin->SetSendFocusHdl( LINK( this, SvtDocumentTemplateDialog, SendFocusHdl_Impl ) );
1756 
1757 	// dynamic height adjustment
1758 	long nHeight = pImpl->pWin->CalcHeight();
1759 
1760 	Size aSize = GetOutputSizePixel();
1761     Point aPos = aMoreTemplatesLink.GetPosPixel();
1762 	Size a6Size = LogicToPixel( Size( 6, 6 ), MAP_APPFONT );
1763     if ( bHideLink )
1764         aPos.Y() += aMoreTemplatesLink.GetSizePixel().Height();
1765     else
1766         aPos.Y() -= a6Size.Height();
1767 	long nDelta = aPos.Y() - nHeight;
1768 	aSize.Height() -= nDelta;
1769 	SetOutputSizePixel( aSize );
1770 
1771 	aSize.Height() = nHeight;
1772     aSize.Width() -= ( a6Size.Width() * 2 );
1773     pImpl->pWin->SetPosSizePixel( Point( a6Size.Width(), 0 ), aSize );
1774 
1775     aPos = aMoreTemplatesLink.GetPosPixel();
1776     aPos.Y() -= nDelta;
1777     aMoreTemplatesLink.SetPosPixel( aPos );
1778     aPos = aLine.GetPosPixel();
1779     aPos.Y() -= nDelta;
1780     aLine.SetPosPixel( aPos );
1781 	aPos = aManageBtn.GetPosPixel();
1782 	aPos.Y() -= nDelta;
1783 	aManageBtn.SetPosPixel( aPos );
1784 	aPos = aEditBtn.GetPosPixel();
1785 	aPos.Y() -= nDelta;
1786 	aEditBtn.SetPosPixel( aPos );
1787 	aPos = aOKBtn.GetPosPixel();
1788 	aPos.Y() -= nDelta;
1789 	aOKBtn.SetPosPixel( aPos );
1790 	aPos = aCancelBtn.GetPosPixel();
1791 	aPos.Y() -= nDelta;
1792 	aCancelBtn.SetPosPixel( aPos );
1793 	aPos = aHelpBtn.GetPosPixel();
1794 	aPos.Y() -= nDelta;
1795 	aHelpBtn.SetPosPixel( aPos );
1796 
1797 	pImpl->pWin->Show();
1798 
1799 	SelectHdl_Impl( NULL );
1800 	NewFolderHdl_Impl( NULL );
1801 
1802 	UpdateHdl_Impl( NULL );
1803 }
1804 
1805 // ------------------------------------------------------------------------
1806 
1807 SvtDocumentTemplateDialog::~SvtDocumentTemplateDialog()
1808 {
1809 	delete pImpl;
1810 }
1811 
1812 // ------------------------------------------------------------------------
1813 
1814 sal_Bool SvtDocumentTemplateDialog::IsFileSelected( ) const
1815 {
1816 	return pImpl->pWin->IsFileSelected();
1817 }
1818 
1819 // ------------------------------------------------------------------------
1820 
1821 String SvtDocumentTemplateDialog::GetSelectedFileURL( ) const
1822 {
1823 	return pImpl->pWin->GetSelectedFile();
1824 }
1825 
1826 // ------------------------------------------------------------------------
1827 
1828 sal_Bool SvtDocumentTemplateDialog::CanEnableEditBtn() const
1829 {
1830 	sal_Bool bEnable = sal_False;
1831 
1832 	::rtl::OUString aFolderURL = pImpl->pWin->GetFolderURL();
1833 	if ( pImpl->pWin->IsFileSelected() && aFolderURL.getLength() )
1834 	{
1835 		::rtl::OUString aFileTargetURL = pImpl->pWin->GetSelectedFile();
1836         bEnable = aFileTargetURL.getLength() > 0;
1837 	}
1838 
1839 	return bEnable;
1840 }
1841 
1842 // ------------------------------------------------------------------------
1843 
1844 IMPL_LINK ( SvtDocumentTemplateDialog , SelectHdl_Impl, SvtTemplateWindow *, EMPTYARG )
1845 {
1846 	aEditBtn.Enable( pImpl->pWin->IsTemplateFolderOpen() && CanEnableEditBtn() );
1847 	aOKBtn.Enable( pImpl->pWin->IsFileSelected() );
1848 	return 0;
1849 }
1850 
1851 // ------------------------------------------------------------------------
1852 
1853 IMPL_LINK ( SvtDocumentTemplateDialog , DoubleClickHdl_Impl, SvtTemplateWindow *, EMPTYARG )
1854 {
1855 	EndDialog( RET_OK );
1856 
1857 	if ( !pImpl->bSelectNoOpen )
1858 		pImpl->pWin->OpenFile( !pImpl->pWin->IsTemplateFolderOpen() );
1859 	return 0;
1860 }
1861 
1862 // ------------------------------------------------------------------------
1863 
1864 IMPL_LINK ( SvtDocumentTemplateDialog , NewFolderHdl_Impl, SvtTemplateWindow *, EMPTYARG )
1865 {
1866 	String aNewTitle( pImpl->aTitle );
1867 	aNewTitle += String( ASCII_STR(" - ") );
1868 	aNewTitle += pImpl->pWin->GetFolderTitle();
1869 	SetText( aNewTitle );
1870 
1871 	SelectHdl_Impl( NULL );
1872 	return 0;
1873 }
1874 
1875 // ------------------------------------------------------------------------
1876 
1877 IMPL_LINK ( SvtDocumentTemplateDialog , SendFocusHdl_Impl, SvtTemplateWindow *, EMPTYARG )
1878 {
1879 	if ( pImpl->pWin->HasIconWinFocus() )
1880 		aHelpBtn.GrabFocus();
1881 	else
1882 	{
1883 		if ( aEditBtn.IsEnabled() )
1884 			aEditBtn.GrabFocus();
1885 		else if ( aOKBtn.IsEnabled() )
1886 			aOKBtn.GrabFocus();
1887 		else
1888 			aCancelBtn.GrabFocus();
1889 	}
1890 
1891 	return 0;
1892 }
1893 
1894 // ------------------------------------------------------------------------
1895 
1896 IMPL_LINK ( SvtDocumentTemplateDialog , OKHdl_Impl, PushButton *, pBtn )
1897 {
1898 	if ( pImpl->pWin->IsFileSelected() )
1899 	{
1900 		EndDialog( RET_OK );
1901 
1902 		if ( !pImpl->bSelectNoOpen )
1903 			pImpl->pWin->OpenFile( &aEditBtn == pBtn );
1904 	}
1905 	return 0;
1906 }
1907 
1908 // ------------------------------------------------------------------------
1909 
1910 IMPL_LINK ( SvtDocumentTemplateDialog , OrganizerHdl_Impl, PushButton *, EMPTYARG )
1911 {
1912 	Window* pOldDefWin = Application::GetDefDialogParent();
1913 	Application::SetDefDialogParent( this );
1914     Reference < XFramesSupplier > xDesktop = Reference < XFramesSupplier >(
1915 		::comphelper::getProcessServiceFactory()->
1916 		createInstance( ASCII_STR("com.sun.star.frame.Desktop") ), UNO_QUERY );
1917     Reference < XFrame > xFrame( xDesktop->getActiveFrame() );
1918     if ( !xFrame.is() )
1919         xFrame = Reference < XFrame >( xDesktop, UNO_QUERY );
1920 
1921     com::sun::star::util::URL aTargetURL;
1922     aTargetURL.Complete = ASCII_STR("slot:5540");
1923     Reference < com::sun::star::util::XURLTransformer > xTrans( ::comphelper::getProcessServiceFactory()->
1924 		createInstance( ASCII_STR("com.sun.star.util.URLTransformer") ), UNO_QUERY );
1925     xTrans->parseStrict( aTargetURL );
1926 
1927     Reference < XDispatchProvider > xProv( xFrame, UNO_QUERY );
1928     Reference < XDispatch > xDisp;
1929     xDisp = xProv->queryDispatch( aTargetURL, ::rtl::OUString(), 0 );
1930 
1931 	if ( xDisp.is() )
1932 	{
1933 		Sequence<PropertyValue> aArgs(1);
1934 		PropertyValue* pArg = aArgs.getArray();
1935 		pArg[0].Name = ASCII_STR("Referer");
1936         pArg[0].Value <<= ASCII_STR("private:user");
1937 		xDisp->dispatch( aTargetURL, aArgs );
1938 	}
1939 
1940 	Application::SetDefDialogParent( pOldDefWin );
1941 	return 0;
1942 }
1943 
1944 // ------------------------------------------------------------------------
1945 
1946 IMPL_LINK ( SvtDocumentTemplateDialog, UpdateHdl_Impl, Timer*, _pEventSource )
1947 {
1948 	pImpl->pWin->SetFocus( sal_False );
1949 	Reference< XDocumentTemplates > xTemplates( ::comphelper::getProcessServiceFactory()->
1950 		createInstance( ASCII_STR("com.sun.star.frame.DocumentTemplates") ), UNO_QUERY );
1951 	if ( xTemplates.is() )
1952 	{
1953 		if ( _pEventSource )
1954 		{	// it was no direct call, which means it was triggered by the timer, which means we alread checked the necessity
1955 			WaitObject aWaitCursor( this );
1956 			xTemplates->update();
1957 			if ( pImpl->pWin->IsTemplateFolderOpen() )
1958 			{
1959 				pImpl->pWin->ClearHistory();
1960 				pImpl->pWin->OpenTemplateRoot();
1961 			}
1962 		}
1963 		else
1964 		{
1965 			// check if we really need to do the update
1966 			::svt::TemplateFolderCache aCache;
1967 			if ( aCache.needsUpdate() )
1968 			{	// yes -> do it asynchronous (it will take a noticeable time)
1969 
1970 				// (but first store the current state)
1971 				aCache.storeState();
1972 
1973 				// start the timer for the async update
1974 				pImpl->aUpdateTimer.SetTimeout( 300 );
1975 				pImpl->aUpdateTimer.SetTimeoutHdl( LINK( this, SvtDocumentTemplateDialog, UpdateHdl_Impl ) );
1976 				pImpl->aUpdateTimer.Start();
1977 			}
1978 		}
1979 	}
1980 	return 0;
1981 }
1982 
1983 // ------------------------------------------------------------------------
1984 
1985 IMPL_LINK ( SvtDocumentTemplateDialog, OpenLinkHdl_Impl, svt::FixedHyperlink*, EMPTYARG )
1986 {
1987     ::rtl::OUString sURL( aMoreTemplatesLink.GetURL() );
1988     if ( sURL.getLength() > 0 )
1989     {
1990         try
1991         {
1992             uno::Reference< lang::XMultiServiceFactory > xSMGR =
1993                 ::comphelper::getProcessServiceFactory();
1994             uno::Reference< com::sun::star::system::XSystemShellExecute > xSystemShell(
1995                 xSMGR->createInstance( ::rtl::OUString(
1996                     RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.system.SystemShellExecute" ) ) ),
1997                 uno::UNO_QUERY_THROW );
1998             if ( xSystemShell.is() )
1999                 xSystemShell->execute( sURL, ::rtl::OUString(), com::sun::star::system::SystemShellExecuteFlags::DEFAULTS );
2000             EndDialog( RET_CANCEL );
2001         }
2002         catch( const uno::Exception& e )
2003         {
2004              OSL_TRACE( "Caught exception: %s\n thread terminated.\n",
2005                 rtl::OUStringToOString(e.Message, RTL_TEXTENCODING_UTF8).getStr());
2006         }
2007     }
2008     return 0;
2009 }
2010 
2011 /* -----------------27.11.2002 16:54-----------------
2012  *
2013  * --------------------------------------------------*/
2014 void SvtDocumentTemplateDialog::SelectTemplateFolder()
2015 {
2016     pImpl->pWin->SelectFolder(ICON_POS_TEMPLATES);
2017 }
2018 
2019