GPU-Calc: remove Alloc_Host_Ptr for clmem of NAN vector
[LibreOffice.git] / svtools / source / contnr / templwin.cxx
bloba57a15a76b2130a21139cbbf2b475818b20f3f8c
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <config_folders.h>
22 #include "templwin.hxx"
23 #include <svtools/templdlg.hxx>
24 #include <svtools/svtresid.hxx>
25 #include <svtools/langhelp.hxx>
26 #include <unotools/pathoptions.hxx>
27 #include <unotools/dynamicmenuoptions.hxx>
28 #include <unotools/extendedsecurityoptions.hxx>
29 #include <vcl/xtextedt.hxx>
30 #include <svl/inettype.hxx>
31 #include <svtools/imagemgr.hxx>
32 #include <svtools/miscopt.hxx>
33 #include <svtools/templatefoldercache.hxx>
34 #include <svtools/imgdef.hxx>
35 #include <vcl/txtattr.hxx>
36 #include <svtools/svtools.hrc>
37 #include "templwin.hrc"
38 #include <svtools/helpid.hrc>
39 #include <unotools/viewoptions.hxx>
40 #include <unotools/ucbhelper.hxx>
41 #include "unotools/configmgr.hxx"
42 #include <com/sun/star/awt/XWindow.hpp>
43 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
44 #include <com/sun/star/frame/Frame.hpp>
45 #include <toolkit/helper/vclunohelper.hxx>
46 #include <com/sun/star/util/URL.hpp>
47 #include <com/sun/star/util/URLTransformer.hpp>
48 #include <com/sun/star/util/XURLTransformer.hpp>
49 #include <com/sun/star/util/XOfficeInstallationDirectories.hpp>
50 #include <com/sun/star/frame/Desktop.hpp>
51 #include <com/sun/star/frame/XDispatchProvider.hpp>
52 #include <com/sun/star/frame/DocumentTemplates.hpp>
53 #include <com/sun/star/frame/XDocumentTemplates.hpp>
54 #include <com/sun/star/frame/XComponentLoader.hpp>
55 #include <com/sun/star/beans/PropertyValue.hpp>
56 #include <com/sun/star/ucb/XContent.hpp>
57 #include <com/sun/star/ucb/XCommandEnvironment.hpp>
58 #include <com/sun/star/view/XPrintable.hpp>
59 #include <com/sun/star/document/DocumentProperties.hpp>
60 #include <com/sun/star/beans/XPropertySet.hpp>
61 #include <com/sun/star/beans/XMultiPropertySet.hpp>
62 #include <com/sun/star/beans/XPropertySetInfo.hpp>
63 #include <com/sun/star/io/IOException.hpp>
64 #include <com/sun/star/util/DateTime.hpp>
65 #include <com/sun/star/script/XTypeConverter.hpp>
66 #include <com/sun/star/system/SystemShellExecute.hpp>
67 #include <com/sun/star/system/SystemShellExecuteFlags.hpp>
68 #include <com/sun/star/task/InteractionHandler.hpp>
69 #include <org/freedesktop/PackageKit/SyncDbusSessionHelper.hpp>
70 #include <unotools/localedatawrapper.hxx>
71 #include <com/sun/star/container/XNameContainer.hpp>
72 #include <vcl/waitobj.hxx>
73 #include <comphelper/processfactory.hxx>
74 #include <tools/urlobj.hxx>
75 #include <tools/datetime.hxx>
76 #include <vcl/svapp.hxx>
77 #include <vcl/split.hxx>
78 #include <vcl/msgbox.hxx>
79 #include <svtools/DocumentInfoPreview.hxx>
80 #include <vcl/mnemonic.hxx>
82 #include <ucbhelper/content.hxx>
83 #include <comphelper/string.hxx>
85 using namespace ::com::sun::star;
86 using namespace ::com::sun::star::beans;
87 using namespace ::com::sun::star::container;
88 using namespace ::com::sun::star::frame;
89 using namespace ::com::sun::star::document;
90 using namespace ::com::sun::star::lang;
91 using namespace ::com::sun::star::ucb;
92 using namespace ::com::sun::star::uno;
93 using namespace ::com::sun::star::view;
94 using namespace svtools;
96 #define aSeparatorStr "----------------------------------"
98 #define ICONWIN_ID 2
99 #define FILEWIN_ID 3
100 #define FRAMEWIN_ID 4
102 #define ICON_POS_NEWDOC 0
103 #define ICON_POS_TEMPLATES 1
104 #define ICON_POS_MYDOCS 2
105 #define ICON_POS_SAMPLES 3
107 #define VIEWSETTING_NEWFROMTEMPLATE "NewFromTemplate"
108 #define VIEWSETTING_SELECTEDGROUP "SelectedGroup"
109 #define VIEWSETTING_SELECTEDVIEW "SelectedView"
110 #define VIEWSETTING_SPLITRATIO "SplitRatio"
111 #define VIEWSETTING_LASTFOLDER "LastFolder"
113 struct FolderHistory
115 OUString m_sURL;
116 sal_uLong m_nGroup;
118 FolderHistory( const OUString& _rURL, sal_Int32 _nGroup ) :
119 m_sURL( _rURL ), m_nGroup( _nGroup ) {}
122 typedef ::std::vector< OUString > NewDocList_Impl;
124 // class SvtDummyHeaderBar_Impl ------------------------------------------
126 void SvtDummyHeaderBar_Impl::UpdateBackgroundColor()
128 SetBackground( Wallpaper( GetSettings().GetStyleSettings().GetWindowColor() ) );
131 SvtDummyHeaderBar_Impl::SvtDummyHeaderBar_Impl( Window* pPar ) : Window( pPar )
133 SetSizePixel( HeaderBar( this, 0 ).CalcWindowSizePixel() ); // HeaderBar used only to calculate size
135 UpdateBackgroundColor();
138 SvtDummyHeaderBar_Impl::~SvtDummyHeaderBar_Impl()
142 void SvtDummyHeaderBar_Impl::DataChanged( const DataChangedEvent& r )
144 Window::DataChanged( r );
145 if( r.GetType() == DATACHANGED_SETTINGS )
146 UpdateBackgroundColor();
149 // class SvtIconWindow_Impl ----------------------------------------------
151 SvtIconWindow_Impl::SvtIconWindow_Impl( Window* pParent ) :
153 Window( pParent, WB_DIALOGCONTROL | WB_BORDER | WB_3DLOOK ),
155 aDummyHeaderBar( this ),
156 aIconCtrl( this, WB_ICON | WB_NOCOLUMNHEADER | WB_HIGHLIGHTFRAME | /*!WB_NOSELECTION |*/
157 WB_NODRAGSELECTION | WB_TABSTOP | WB_CLIPCHILDREN ),
158 aNewDocumentRootURL( "private:newdoc" ),
159 aMyDocumentsRootURL( SvtPathOptions().GetWorkPath() ),
160 aSamplesFolderRootURL( SvtPathOptions().
161 SubstituteVariable( "$(insturl)/" LIBO_SHARE_FOLDER "/samples/$(vlang)" ) ),
162 nMaxTextLength( 0 )
165 aDummyHeaderBar.Show();
167 aIconCtrl.SetAccessibleName( OUString( "Groups" ) );
168 aIconCtrl.SetHelpId( HID_TEMPLATEDLG_ICONCTRL );
169 aIconCtrl.SetChoiceWithCursor( sal_True );
170 aIconCtrl.SetSelectionMode( SINGLE_SELECTION );
171 aIconCtrl.Show();
173 // detect the root URL of templates
174 Reference< XDocumentTemplates > xTemplates( frame::DocumentTemplates::create(::comphelper::getProcessComponentContext()) );
176 Reference < XContent > aRootContent = xTemplates->getContent();
177 Reference < XCommandEnvironment > aCmdEnv;
179 if ( aRootContent.is() )
180 aTemplateRootURL = aRootContent->getIdentifier()->getContentIdentifier();
182 // insert the categories
183 // "New Document"
184 Image aImage( SvtResId( IMG_SVT_NEWDOC ) );
185 nMaxTextLength = aImage.GetSizePixel().Width();
186 OUString aEntryStr = SVT_RESSTR(STR_SVT_NEWDOC);
187 SvxIconChoiceCtrlEntry* pEntry =
188 aIconCtrl.InsertEntry( aEntryStr, aImage, ICON_POS_NEWDOC );
189 pEntry->SetUserData( new OUString(aNewDocumentRootURL) );
190 pEntry->SetQuickHelpText( SVT_RESSTR(STR_SVT_NEWDOC_HELP) );
191 DBG_ASSERT( !pEntry->GetBoundRect().IsEmpty(), "empty rectangle" );
192 long nTemp = pEntry->GetBoundRect().GetSize().Width();
193 if (nTemp > nMaxTextLength)
194 nMaxTextLength = nTemp;
196 // "Templates"
197 if( !aTemplateRootURL.isEmpty() )
199 aEntryStr = SVT_RESSTR(STR_SVT_TEMPLATES);
200 pEntry = aIconCtrl.InsertEntry(
201 aEntryStr, Image( SvtResId( IMG_SVT_TEMPLATES ) ), ICON_POS_TEMPLATES );
202 pEntry->SetUserData( new OUString(aTemplateRootURL) );
203 pEntry->SetQuickHelpText(SVT_RESSTR(STR_SVT_TEMPLATES_HELP));
204 DBG_ASSERT( !pEntry->GetBoundRect().IsEmpty(), "empty rectangle" );
205 nTemp = pEntry->GetBoundRect().GetSize().Width();
206 if (nTemp > nMaxTextLength)
207 nMaxTextLength = nTemp;
210 // "My Documents"
211 aEntryStr = SVT_RESSTR(STR_SVT_MYDOCS);
212 pEntry = aIconCtrl.InsertEntry(
213 aEntryStr, Image( SvtResId( IMG_SVT_MYDOCS ) ), ICON_POS_MYDOCS );
214 pEntry->SetUserData( new OUString(aMyDocumentsRootURL) );
215 pEntry->SetQuickHelpText( SVT_RESSTR(STR_SVT_MYDOCS_HELP) );
216 DBG_ASSERT( !pEntry->GetBoundRect().IsEmpty(), "empty rectangle" );
217 nTemp = pEntry->GetBoundRect().GetSize().Width();
218 if( nTemp > nMaxTextLength )
219 nMaxTextLength = nTemp;
221 // "Samples"
222 aEntryStr = SVT_RESSTR(STR_SVT_SAMPLES);
223 pEntry = aIconCtrl.InsertEntry(
224 aEntryStr, Image( SvtResId( IMG_SVT_SAMPLES ) ), ICON_POS_SAMPLES );
225 pEntry->SetUserData( new OUString(aSamplesFolderRootURL) );
226 pEntry->SetQuickHelpText( SVT_RESSTR(STR_SVT_SAMPLES_HELP));
227 DBG_ASSERT( !pEntry->GetBoundRect().IsEmpty(), "empty rectangle" );
228 nTemp = pEntry->GetBoundRect().GetSize().Width();
229 if (nTemp > nMaxTextLength)
230 nMaxTextLength = nTemp;
232 aIconCtrl.CreateAutoMnemonics();
235 SvtIconWindow_Impl::~SvtIconWindow_Impl()
237 for ( sal_uLong i = 0; i < aIconCtrl.GetEntryCount(); ++i )
239 SvxIconChoiceCtrlEntry* pEntry = aIconCtrl.GetEntry( i );
240 delete (OUString*)pEntry->GetUserData();
244 SvxIconChoiceCtrlEntry* SvtIconWindow_Impl::GetEntry( const OUString& rURL ) const
246 SvxIconChoiceCtrlEntry* pEntry = NULL;
247 for ( sal_uLong i = 0; i < aIconCtrl.GetEntryCount(); ++i )
249 SvxIconChoiceCtrlEntry* pTemp = aIconCtrl.GetEntry( i );
250 OUString *pURL = (OUString*)pTemp->GetUserData();
251 if ( (*pURL) == rURL )
253 pEntry = pTemp;
254 break;
258 return pEntry;
261 void SvtIconWindow_Impl::Resize()
263 Size aWinSize = GetOutputSizePixel();
264 Size aHeaderSize = aDummyHeaderBar.GetSizePixel();
265 aHeaderSize.Width() = aWinSize.Width();
266 aDummyHeaderBar.SetSizePixel( aHeaderSize );
267 long nHeaderHeight = aHeaderSize.Height();
268 aWinSize.Height() -= nHeaderHeight;
269 aIconCtrl.SetPosSizePixel( Point( 0, nHeaderHeight ), aWinSize );
270 aIconCtrl.ArrangeIcons();
273 OUString SvtIconWindow_Impl::GetCursorPosIconURL() const
275 OUString aURL;
276 SvxIconChoiceCtrlEntry* pEntry = aIconCtrl.GetCursor( );
277 if ( pEntry )
278 aURL = *static_cast<OUString*>(pEntry->GetUserData());
279 return aURL;
283 OUString SvtIconWindow_Impl::GetSelectedIconURL() const
285 sal_uLong nPos;
286 SvxIconChoiceCtrlEntry* pEntry = aIconCtrl.GetSelectedEntry( nPos );
287 OUString aURL;
288 if ( pEntry )
289 aURL = *static_cast<OUString*>(pEntry->GetUserData());
290 return aURL;
293 OUString SvtIconWindow_Impl::GetIconText( const OUString& rURL ) const
295 OUString aText;
296 SvxIconChoiceCtrlEntry* pEntry = GetEntry( rURL );
297 if ( pEntry )
298 aText = MnemonicGenerator::EraseAllMnemonicChars( pEntry->GetText() );
299 return aText;
302 void SvtIconWindow_Impl::InvalidateIconControl()
304 aIconCtrl.Invalidate();
307 sal_uLong SvtIconWindow_Impl::GetCursorPos() const
309 sal_uLong nPos = ~sal_uLong(0);
311 SvxIconChoiceCtrlEntry* pCursorEntry = aIconCtrl.GetCursor( );
312 if ( pCursorEntry )
313 nPos = aIconCtrl.GetEntryListPos( pCursorEntry );
315 return nPos;
318 sal_uLong SvtIconWindow_Impl::GetSelectEntryPos() const
320 sal_uLong nPos;
321 if ( !aIconCtrl.GetSelectedEntry( nPos ) )
322 nPos = ~sal_uLong(0);
323 return nPos;
326 void SvtIconWindow_Impl::SetCursorPos( sal_uLong nPos )
328 SvxIconChoiceCtrlEntry* pEntry = aIconCtrl.GetEntry( nPos );
329 aIconCtrl.SetCursor( pEntry );
330 aIconCtrl.Invalidate();
331 aIconCtrl.Update();
334 void SvtIconWindow_Impl::SetFocus()
336 aIconCtrl.GrabFocus();
339 long SvtIconWindow_Impl::CalcHeight() const
341 // calculate the required height of the IconControl
342 long nHeight = 0;
343 sal_uLong nCount = aIconCtrl.GetEntryCount();
344 if ( nCount > 0 )
345 // bottom of the last icon
346 nHeight = aIconCtrl.GetEntry(nCount-1)->GetBoundRect().Bottom();
348 // + headerbar height
349 nHeight += aDummyHeaderBar.GetSizePixel().Height();
351 return nHeight;
354 sal_Bool SvtIconWindow_Impl::IsRootURL( const OUString& rURL ) const
356 return rURL == aNewDocumentRootURL ||
357 rURL == aTemplateRootURL ||
358 rURL == aMyDocumentsRootURL ||
359 rURL == aSamplesFolderRootURL;
362 sal_uLong SvtIconWindow_Impl::GetRootPos( const OUString& rURL ) const
364 sal_uLong nPos = ~sal_uLong(0);
365 if ( rURL.startsWith(aNewDocumentRootURL) )
366 nPos = 0;
367 else if ( rURL.startsWith(aTemplateRootURL) )
368 nPos = 1;
369 else if ( rURL.startsWith(aMyDocumentsRootURL) )
370 nPos = 2;
371 else if ( rURL.startsWith(aSamplesFolderRootURL) )
372 nPos = 3;
373 else if ( aMyDocumentsRootURL.startsWith(rURL) )
374 nPos = 2;
375 else
377 DBG_WARNING( "SvtIconWindow_Impl::GetRootPos(): invalid position" );
378 nPos = 2;
381 return nPos;
384 void SvtIconWindow_Impl::UpdateIcons()
386 aIconCtrl.GetEntry( ICON_POS_NEWDOC )->SetImage(
387 Image( SvtResId( IMG_SVT_NEWDOC ) ) );
388 aIconCtrl.GetEntry( ICON_POS_TEMPLATES )->SetImage(
389 Image( SvtResId( IMG_SVT_TEMPLATES ) ) );
390 aIconCtrl.GetEntry( ICON_POS_MYDOCS )->SetImage(
391 Image( SvtResId( IMG_SVT_MYDOCS ) ) );
392 aIconCtrl.GetEntry( ICON_POS_SAMPLES )->SetImage(
393 Image( SvtResId( IMG_SVT_SAMPLES ) ) );
396 void SvtIconWindow_Impl::SelectFolder(sal_Int32 nFolderPosition)
398 SvxIconChoiceCtrlEntry* pEntry = aIconCtrl.GetEntry( nFolderPosition );
399 if(pEntry)
401 aIconCtrl.SetCursor( pEntry );
402 aIconCtrl.GetClickHdl().Call(&aIconCtrl);
406 // class SvtFileViewWindow_Impl -----------------------------------------_
408 SvtFileViewWindow_Impl::SvtFileViewWindow_Impl( SvtTemplateWindow* pParent ) :
410 Window( pParent, WB_DIALOGCONTROL | WB_TABSTOP | WB_BORDER | WB_3DLOOK ),
412 rParent ( *pParent ),
413 aFileView ( this, SvtResId( CTRL_FILEVIEW ), FILEVIEW_SHOW_NONE | FILEVIEW_SHOW_ONLYTITLE ),
414 bIsTemplateFolder ( sal_False )
417 aFileView.SetStyle( aFileView.GetStyle() | WB_DIALOGCONTROL | WB_TABSTOP );
418 aFileView.SetHelpId( HID_TEMPLATEDLG_FILEVIEW );
419 aFileView.Show();
420 aFileView.EnableAutoResize();
421 aFileView.EnableContextMenu( sal_False );
422 aFileView.EnableDelete( sal_False );
425 SvtFileViewWindow_Impl::~SvtFileViewWindow_Impl()
429 void GetMenuEntry_Impl
431 Sequence< PropertyValue >& aDynamicMenuEntry,
432 OUString& rTitle,
433 OUString& rURL,
434 OUString& rFrame,
435 OUString& rImageId
438 for ( int i = 0; i < aDynamicMenuEntry.getLength(); i++ )
440 if ( aDynamicMenuEntry[i].Name == DYNAMICMENU_PROPERTYNAME_URL )
441 aDynamicMenuEntry[i].Value >>= rURL;
442 else if ( aDynamicMenuEntry[i].Name == DYNAMICMENU_PROPERTYNAME_TITLE )
443 aDynamicMenuEntry[i].Value >>= rTitle;
444 else if ( aDynamicMenuEntry[i].Name == DYNAMICMENU_PROPERTYNAME_IMAGEIDENTIFIER )
445 aDynamicMenuEntry[i].Value >>= rImageId;
446 else if ( aDynamicMenuEntry[i].Name == DYNAMICMENU_PROPERTYNAME_TARGETNAME )
447 aDynamicMenuEntry[i].Value >>= rFrame;
451 Sequence< OUString > SvtFileViewWindow_Impl::GetNewDocContents() const
453 NewDocList_Impl aNewDocs;
454 Sequence< Sequence< PropertyValue > > aDynamicMenuEntries;
455 aDynamicMenuEntries = SvtDynamicMenuOptions().GetMenu( E_NEWMENU );
457 OUString aTitle;
458 OUString aURL;
459 OUString aImageURL;
460 OUString aTargetFrame;
462 sal_uInt32 i, nCount = aDynamicMenuEntries.getLength();
463 OUString sSeparator( "private:separator" );
464 OUString sSlotURL( "slot:5500" );
466 for ( i = 0; i < nCount; ++i )
468 GetMenuEntry_Impl( aDynamicMenuEntries[i], aTitle, aURL, aTargetFrame, aImageURL );
469 if( aURL == sSlotURL )
470 continue;
471 if( aURL == sSeparator )
473 OUString aSeparator( aSeparatorStr );
474 aNewDocs.push_back( aSeparator );
476 else
478 // title
479 OUString aRow = MnemonicGenerator::EraseAllMnemonicChars( aTitle );
480 aRow += "\t";
481 // no type
482 aRow += "\t";
483 // no size
484 aRow += "\t";
485 // no date
486 aRow += "\t";
487 // url
488 aRow += aURL;
489 aRow += "\t";
490 // folder == false
491 aRow += "0";
492 // image url?
493 if ( !aImageURL.isEmpty() )
495 aRow += "\t";
496 aRow += aImageURL;
499 aNewDocs.push_back( aRow );
503 nCount = aNewDocs.size();
504 Sequence < OUString > aRet( nCount );
505 OUString* pRet = aRet.getArray();
506 for ( i = 0; i < nCount; ++i )
508 pRet[i] = aNewDocs[i];
511 return aRet;
514 void SvtFileViewWindow_Impl::Resize()
516 aFileView.SetSizePixel(GetOutputSizePixel());
519 OUString SvtFileViewWindow_Impl::GetSelectedFile() const
521 return aFileView.GetCurrentURL();
524 void SvtFileViewWindow_Impl::OpenFolder( const OUString& rURL )
526 aFolderURL = rURL;
528 rParent.SetPrevLevelButtonState( rURL );
530 if ( INetURLObject( rURL ).GetProtocol() == INET_PROT_PRIVATE )
532 aFileView.EnableNameReplacing( sal_False );
533 aFileView.Initialize( GetNewDocContents() );
535 else
537 sal_Int32 nSampFoldLen = aSamplesFolderURL.getLength();
538 aFileView.EnableNameReplacing(
539 nSampFoldLen && rURL.compareTo( aSamplesFolderURL, nSampFoldLen ) == 0 );
540 aFileView.Initialize( rURL, "", NULL );
542 aNewFolderLink.Call( this );
545 sal_Bool SvtFileViewWindow_Impl::HasPreviousLevel( OUString& rURL ) const
547 INetURLObject aViewObj( aFileView.GetViewURL() );
548 INetURLObject aRootObj( aCurrentRootURL );
549 INetURLObject aMyDocObj( aMyDocumentsURL );
551 return ( ( aViewObj != aRootObj || aRootObj == aMyDocObj ) && aFileView.GetParentURL( rURL ) );
554 OUString SvtFileViewWindow_Impl::GetFolderTitle() const
556 OUString aTitle;
557 ::utl::UCBContentHelper::GetTitle( aFolderURL, &aTitle );
558 return aTitle;
561 void SvtFileViewWindow_Impl::SetFocus()
563 aFileView.SetFocus();
566 // class SvtDocInfoTable_Impl --------------------------------------------
568 SvtDocInfoTable_Impl::SvtDocInfoTable_Impl() :
570 ResStringArray( SvtResId( STRARY_SVT_DOCINFO ) )
574 // -----------------------------------------------------------------------
576 OUString SvtDocInfoTable_Impl::GetString( long nId ) const
578 sal_uInt32 nPos( FindIndex( nId ) );
580 if ( RESARRAY_INDEX_NOTFOUND != nPos )
581 return ResStringArray::GetString( nPos );
583 return OUString();
586 // class SvtFrameWindow_Impl ---------------------------------------------
588 SvtFrameWindow_Impl::SvtFrameWindow_Impl( Window* pParent )
589 : Window( pParent )
591 // create windows and frame
592 pEditWin = new ODocumentInfoPreview( this ,WB_LEFT | WB_VSCROLL | WB_READONLY | WB_BORDER | WB_3DLOOK);
593 pTextWin = new Window( this );
594 m_xFrame = Frame::create( ::comphelper::getProcessComponentContext() );
595 xWindow = VCLUnoHelper::GetInterface( pTextWin );
596 m_xFrame->initialize( xWindow );
598 // create docinfo instance
599 m_xDocProps.set( document::DocumentProperties::create(::comphelper::getProcessComponentContext()) );
601 pEmptyWin = new Window( this, WB_BORDER | WB_3DLOOK );
604 SvtFrameWindow_Impl::~SvtFrameWindow_Impl()
606 delete pEditWin;
607 delete pEmptyWin;
608 m_xFrame->dispose();
611 void SvtFrameWindow_Impl::ViewEditWin()
613 pEmptyWin->Hide();
614 xWindow->setVisible( sal_False );
615 pTextWin->Hide();
616 pEditWin->Show();
619 void SvtFrameWindow_Impl::ViewTextWin()
621 pEmptyWin->Hide();
622 pEditWin->Hide();
623 xWindow->setVisible( sal_True );
624 pTextWin->Show();
627 void SvtFrameWindow_Impl::ViewEmptyWin()
629 xWindow->setVisible( sal_False );
630 pTextWin->Hide();
631 pEditWin->Hide();
632 pEmptyWin->Show();
635 void SvtFrameWindow_Impl::ViewNonEmptyWin()
637 if( bDocInfo )
638 ViewEditWin();
639 else
640 ViewTextWin();
643 void SvtFrameWindow_Impl::ShowDocInfo( const OUString& rURL )
647 uno::Reference < task::XInteractionHandler2 > xInteractionHandler(
648 task::InteractionHandler::createWithParent(::comphelper::getProcessComponentContext(), 0) );
649 uno::Sequence < beans::PropertyValue> aProps(1);
650 aProps[0].Name = "InteractionHandler";
651 aProps[0].Value <<= xInteractionHandler;
652 m_xDocProps->loadFromMedium( rURL, aProps );
653 pEditWin->fill( m_xDocProps, rURL );
655 catch ( UnknownPropertyException& ) {}
656 catch ( Exception& ) {}
659 void SvtFrameWindow_Impl::Resize()
661 Size aWinSize = GetOutputSizePixel();
662 pEditWin->SetSizePixel( aWinSize );
663 pTextWin->SetSizePixel( aWinSize );
664 pEmptyWin->SetSizePixel( aWinSize );
667 void SvtFrameWindow_Impl::OpenFile( const OUString& rURL, sal_Bool bPreview, sal_Bool bIsTemplate, sal_Bool bAsTemplate )
669 if ( bPreview )
670 aCurrentURL = rURL;
672 ViewNonEmptyWin();
673 pEditWin->clear();
675 if ( !rURL.isEmpty() && bPreview && m_xDocProps.is() )
676 ShowDocInfo( rURL );
678 if ( rURL.isEmpty() )
680 m_xFrame->setComponent( Reference < com::sun::star::awt::XWindow >(), Reference < XController >() );
681 ViewEmptyWin();
683 else if ( !::utl::UCBContentHelper::IsFolder( rURL ) )
685 com::sun::star::util::URL aURL;
686 aURL.Complete = rURL;
687 Reference< com::sun::star::util::XURLTransformer > xTrans(
688 com::sun::star::util::URLTransformer::create( ::comphelper::getProcessComponentContext() ) );
689 xTrans->parseStrict( aURL );
691 OUString aTarget;
692 Reference < XDispatchProvider > xProv( m_xFrame, UNO_QUERY_THROW );
693 if ( bPreview )
694 aTarget = "_self";
695 else
697 // can be removed if the database application change its URL
698 if ( !rURL.startsWith( "service:" ) )
699 // service URL has no default target
700 aTarget = "_default";
701 xProv = Reference < XDispatchProvider >( Desktop::create(::comphelper::getProcessComponentContext() ),
702 UNO_QUERY_THROW );
705 Reference < XDispatch > xDisp = xProv.is() ?
706 xProv->queryDispatch( aURL, aTarget, 0 ) : Reference < XDispatch >();
708 if ( xDisp.is() )
710 if ( bPreview )
712 if ( m_aOpenURL != aURL.Complete )
714 WaitObject aWaitCursor( GetParent() );
715 // disabling must be done here, does not work in ctor because
716 // execute of the dialog will overwrite it
717 // ( own execute method would help )
718 pTextWin->EnableInput( sal_False, sal_True );
719 if ( pTextWin->IsReallyVisible() )
721 sal_Bool b = sal_True;
722 Sequence < PropertyValue > aArgs( 4 );
723 aArgs[0].Name = "Preview";
724 aArgs[0].Value.setValue( &b, ::getBooleanCppuType() );
725 aArgs[1].Name = "ReadOnly";
726 aArgs[1].Value.setValue( &b, ::getBooleanCppuType() );
727 aArgs[2].Name = "AsTemplate"; // prevents getting an empty URL with getURL()!
729 uno::Reference < task::XInteractionHandler2 > xInteractionHandler(
730 task::InteractionHandler::createWithParent(::comphelper::getProcessComponentContext(), 0) );
731 aArgs[3].Name = "InteractionHandler";
732 aArgs[3].Value <<= xInteractionHandler;
734 b = sal_False;
735 aArgs[2].Value.setValue( &b, ::getBooleanCppuType() );
736 xDisp->dispatch( aURL, aArgs );
738 OUString aDispURL;
739 Reference< ::com::sun::star::frame::XController > xCtrl = m_xFrame->getController();
740 if( xCtrl.is() )
742 Reference< ::com::sun::star::frame::XModel > xMdl = xCtrl->getModel();
743 if( xMdl.is() )
744 aDispURL = xMdl->getURL();
747 if( aDispURL != aURL.Complete )
749 m_xFrame->setComponent( Reference < com::sun::star::awt::XWindow >(), Reference < XController >() );
750 ViewEmptyWin();
751 m_aOpenURL = "";
753 else
754 m_aOpenURL = aDispURL;
758 else if ( bIsTemplate )
760 Sequence < PropertyValue > aArgs( 1 );
761 aArgs[0].Name = "AsTemplate";
762 aArgs[0].Value <<= bAsTemplate;
763 xDisp->dispatch( aURL, aArgs );
764 m_aOpenURL = "";
766 else
768 Sequence < PropertyValue > aArgs;
769 xDisp->dispatch( aURL, aArgs );
770 m_aOpenURL = "";
776 void SvtFrameWindow_Impl::ToggleView( sal_Bool bDI )
778 bDocInfo = bDI;
780 // view is set properly in OpenFile()
782 OpenFile( aCurrentURL, sal_True, sal_False, sal_False );
785 // class SvtTemplateWindow -----------------------------------------------
787 SvtTemplateWindow::SvtTemplateWindow( Window* pParent ) :
789 Window( pParent, WB_DIALOGCONTROL ),
791 aFileViewTB ( this, SvtResId( TB_SVT_FILEVIEW ) ),
792 aFrameWinTB ( this, SvtResId( TB_SVT_FRAMEWIN ) ),
793 aSplitWin ( this, WB_DIALOGCONTROL | WB_NOSPLITDRAW ),
794 pHistoryList ( NULL )
797 // create windows
798 pIconWin = new SvtIconWindow_Impl( this );
799 pFileWin = new SvtFileViewWindow_Impl( this );
800 pFileWin->SetMyDocumentsURL( pIconWin->GetMyDocumentsRootURL() );
801 pFileWin->SetSamplesFolderURL( pIconWin->GetSamplesFolderURL() );
802 pFrameWin = new SvtFrameWindow_Impl( this );
804 // set handlers
805 pIconWin->SetClickHdl( LINK( this, SvtTemplateWindow, IconClickHdl_Impl ) );
806 pFileWin->SetSelectHdl( LINK( this, SvtTemplateWindow, FileSelectHdl_Impl ) );
807 pFileWin->SetDoubleClickHdl( LINK( this, SvtTemplateWindow, FileDblClickHdl_Impl ) );
808 pFileWin->SetNewFolderHdl( LINK( this, SvtTemplateWindow, NewFolderHdl_Impl ) );
810 // create the split items
811 aSplitWin.SetAlign( WINDOWALIGN_LEFT );
812 long nWidth = pIconWin->GetMaxTextLength() * 8 / 7 + 1; // extra space for border
813 aSplitWin.InsertItem( ICONWIN_ID, pIconWin, nWidth, SPLITWINDOW_APPEND, 0, SWIB_FIXED );
814 aSplitWin.InsertItem( FILEWIN_ID, pFileWin, 50, SPLITWINDOW_APPEND, 0, SWIB_PERCENTSIZE );
815 aSplitWin.InsertItem( FRAMEWIN_ID, pFrameWin, 50, SPLITWINDOW_APPEND, 0, SWIB_PERCENTSIZE );
816 aSplitWin.SetSplitHdl( LINK( this, SvtTemplateWindow, ResizeHdl_Impl ) );
818 // show the windows
819 pIconWin->Show();
820 pFileWin->Show();
821 pFrameWin->Show();
822 aSplitWin.Show();
824 // initialize the timers
825 aSelectTimer.SetTimeout( 200 );
826 aSelectTimer.SetTimeoutHdl( LINK( this, SvtTemplateWindow, TimeoutHdl_Impl ) );
828 // initialize the toolboxes and then show them
829 InitToolBoxes();
830 aFileViewTB.Show();
831 aFrameWinTB.Show();
833 ReadViewSettings( );
835 Application::PostUserEvent( LINK( this, SvtTemplateWindow, ResizeHdl_Impl ) );
838 // ------------------------------------------------------------------------
840 SvtTemplateWindow::~SvtTemplateWindow()
842 WriteViewSettings( );
844 delete pIconWin;
845 delete pFileWin;
846 delete pFrameWin;
847 if ( pHistoryList )
849 for ( size_t i = 0, n = pHistoryList->size(); i < n; ++i )
850 delete (*pHistoryList)[ i ];
851 pHistoryList->clear();
852 delete pHistoryList;
856 // ------------------------------------------------------------------------
858 IMPL_LINK_NOARG(SvtTemplateWindow , IconClickHdl_Impl)
860 OUString aURL = pIconWin->GetSelectedIconURL();
861 if ( aURL.isEmpty() )
862 aURL = pIconWin->GetCursorPosIconURL();
863 if ( pFileWin->GetRootURL() != aURL )
865 pFileWin->OpenRoot( aURL );
866 pIconWin->InvalidateIconControl();
867 aFileViewTB.EnableItem( TI_DOCTEMPLATE_PRINT, sal_False );
869 return 0;
872 // ------------------------------------------------------------------------
874 IMPL_LINK_NOARG(SvtTemplateWindow , FileSelectHdl_Impl)
876 aSelectTimer.Start();
877 return 0;
880 // ------------------------------------------------------------------------
882 IMPL_LINK_NOARG(SvtTemplateWindow , FileDblClickHdl_Impl)
884 if ( aSelectTimer.IsActive() )
885 aSelectTimer.Stop();
887 OUString aURL = pFileWin->GetSelectedFile();
888 if ( !aURL.isEmpty() )
890 if ( ::utl::UCBContentHelper::IsFolder( aURL ) )
891 pFileWin->OpenFolder( aURL );
892 else
893 aDoubleClickHdl.Call( this );
896 return 0;
899 // ------------------------------------------------------------------------
901 IMPL_LINK_NOARG(SvtTemplateWindow , NewFolderHdl_Impl)
903 pFrameWin->OpenFile( "", sal_True, sal_False, sal_False );
904 aFileViewTB.EnableItem( TI_DOCTEMPLATE_PRINT, sal_False );
906 OUString sURL = pFileWin->GetFolderURL();
907 sal_uLong nPos = pIconWin->GetRootPos( sURL );
908 AppendHistoryURL( sURL, nPos );
910 aNewFolderHdl.Call( this );
911 return 0;
914 // ------------------------------------------------------------------------
916 IMPL_LINK_NOARG(SvtTemplateWindow , TimeoutHdl_Impl)
918 aSelectHdl.Call( this );
919 OUString sURL = pFileWin->GetSelectedFile();
920 sal_Bool bIsNewDoc = ( pIconWin->GetSelectEntryPos() == ICON_POS_NEWDOC );
921 sal_Bool bIsFile = ( !sURL.isEmpty() && !::utl::UCBContentHelper::IsFolder( sURL ) &&
922 INetURLObject( sURL ).GetProtocol() != INET_PROT_PRIVATE && !bIsNewDoc );
923 aFileViewTB.EnableItem( TI_DOCTEMPLATE_PRINT, bIsFile );
924 aFrameWinTB.EnableItem( TI_DOCTEMPLATE_PREVIEW, !bIsNewDoc );
926 if ( bIsFile )
927 pFrameWin->OpenFile( sURL, sal_True, sal_False, sal_False );
928 else if ( bIsNewDoc && aFrameWinTB.IsItemChecked( TI_DOCTEMPLATE_PREVIEW ) )
930 aFrameWinTB.CheckItem( TI_DOCTEMPLATE_DOCINFO );
931 DoAction( TI_DOCTEMPLATE_DOCINFO );
933 return 0;
936 // ------------------------------------------------------------------------
938 IMPL_LINK ( SvtTemplateWindow , ClickHdl_Impl, ToolBox *, pToolBox )
940 DoAction( pToolBox->GetCurItemId() );
941 return 0;
944 // ------------------------------------------------------------------------
946 IMPL_LINK_NOARG(SvtTemplateWindow , ResizeHdl_Impl)
948 Resize();
949 return 0;
952 // ------------------------------------------------------------------------
954 void SvtTemplateWindow::PrintFile( const OUString& rURL )
956 // open the file readonly and hidden
957 Sequence < PropertyValue > aArgs( 2 );
958 aArgs[0].Name = "ReadOnly";
959 aArgs[0].Value <<= sal_True;
960 aArgs[1].Name = "Hidden";
961 aArgs[1].Value <<= sal_True;
963 Reference < XDesktop2 > xDesktop = Desktop::create( ::comphelper::getProcessComponentContext() );
964 Reference < XModel > xModel( xDesktop->loadComponentFromURL(
965 rURL, "_blank", 0, aArgs ), UNO_QUERY );
966 if ( xModel.is() )
968 // print
969 Reference < XPrintable > xPrintable( xModel, UNO_QUERY );
970 if ( xPrintable.is() )
971 xPrintable->print( Sequence < PropertyValue >() );
975 // ------------------------------------------------------------------------
977 void SvtTemplateWindow::AppendHistoryURL( const OUString& rURL, sal_uLong nGroup )
979 sal_Bool bInsert = sal_True;
980 if ( !pHistoryList )
981 pHistoryList = new HistoryList_Impl;
982 else if ( pHistoryList->size() > 0 )
984 FolderHistory* pLastEntry = pHistoryList->back();
985 bInsert = ( rURL != pLastEntry->m_sURL);
988 if ( bInsert )
990 FolderHistory* pEntry = new FolderHistory( rURL, nGroup );
991 pHistoryList->push_back( pEntry );
992 aFileViewTB.EnableItem( TI_DOCTEMPLATE_BACK, pHistoryList->size() > 1 );
996 // ------------------------------------------------------------------------
998 void SvtTemplateWindow::OpenHistory()
1000 delete pHistoryList->back();
1001 pHistoryList->pop_back();
1002 FolderHistory* pEntry = pHistoryList->back();
1003 pHistoryList->pop_back();
1004 aFileViewTB.EnableItem( TI_DOCTEMPLATE_BACK, pHistoryList->size() > 1 );
1005 pFileWin->OpenFolder( pEntry->m_sURL );
1006 pIconWin->SetCursorPos( pEntry->m_nGroup );
1007 delete pEntry;
1010 // ------------------------------------------------------------------------
1012 void SvtTemplateWindow::DoAction( sal_uInt16 nAction )
1014 switch( nAction )
1016 case TI_DOCTEMPLATE_BACK :
1018 if ( pHistoryList && pHistoryList->size() > 1 )
1019 OpenHistory();
1020 break;
1023 case TI_DOCTEMPLATE_PREV :
1025 OUString aURL;
1026 if ( pFileWin->HasPreviousLevel( aURL ) )
1027 pFileWin->OpenFolder( aURL );
1028 break;
1031 case TI_DOCTEMPLATE_PRINT :
1033 OUString sPrintFile( pFileWin->GetSelectedFile() );
1034 if ( !sPrintFile.isEmpty() )
1035 PrintFile( sPrintFile );
1036 break;
1039 case TI_DOCTEMPLATE_DOCINFO :
1040 case TI_DOCTEMPLATE_PREVIEW :
1042 pFrameWin->ToggleView( TI_DOCTEMPLATE_DOCINFO == nAction );
1043 break;
1048 // ------------------------------------------------------------------------
1050 void SvtTemplateWindow::InitToolBoxes()
1052 InitToolBoxImages();
1054 Size aSize = aFileViewTB.CalcWindowSizePixel();
1055 aSize.Height() += 4;
1056 aFileViewTB.SetPosSizePixel( Point( 0, 2 ), aSize );
1057 aSize = aFrameWinTB.CalcWindowSizePixel();
1058 aSize.Height() += 4;
1059 aFrameWinTB.SetPosSizePixel( Point( pFrameWin->GetPosPixel().X() + 2, 2 ), aSize );
1061 sal_Bool bFlat = ( SvtMiscOptions().GetToolboxStyle() == TOOLBOX_STYLE_FLAT );
1062 if ( bFlat )
1064 aFileViewTB.SetOutStyle( TOOLBOX_STYLE_FLAT );
1065 aFrameWinTB.SetOutStyle( TOOLBOX_STYLE_FLAT );
1068 aFileViewTB.EnableItem( TI_DOCTEMPLATE_BACK, sal_False );
1069 aFileViewTB.EnableItem( TI_DOCTEMPLATE_PREV, sal_False );
1070 aFileViewTB.EnableItem( TI_DOCTEMPLATE_PRINT, sal_False );
1072 Link aLink = LINK( this, SvtTemplateWindow, ClickHdl_Impl );
1073 aFileViewTB.SetClickHdl( aLink );
1074 aFrameWinTB.SetClickHdl( aLink );
1077 // ------------------------------------------------------------------------
1079 void SvtTemplateWindow::InitToolBoxImages()
1081 SvtMiscOptions aMiscOpt;
1082 sal_Bool bLarge = aMiscOpt.AreCurrentSymbolsLarge();
1084 aFileViewTB.SetItemImage( TI_DOCTEMPLATE_BACK, Image( SvtResId(
1085 bLarge ? IMG_SVT_DOCTEMPLATE_BACK_LARGE
1086 : IMG_SVT_DOCTEMPLATE_BACK_SMALL ) ) );
1087 aFileViewTB.SetItemImage( TI_DOCTEMPLATE_PREV, Image( SvtResId(
1088 bLarge ? IMG_SVT_DOCTEMPLATE_PREV_LARGE
1089 : IMG_SVT_DOCTEMPLATE_PREV_SMALL ) ) );
1090 aFileViewTB.SetItemImage( TI_DOCTEMPLATE_PRINT, Image( SvtResId(
1091 bLarge ? IMG_SVT_DOCTEMPLATE_PRINT_LARGE
1092 : IMG_SVT_DOCTEMPLATE_PRINT_SMALL ) ) );
1094 aFrameWinTB.SetItemImage( TI_DOCTEMPLATE_DOCINFO, Image( SvtResId(
1095 bLarge ? IMG_SVT_DOCTEMPLATE_DOCINFO_LARGE
1096 : IMG_SVT_DOCTEMPLATE_DOCINFO_SMALL ) ) );
1097 aFrameWinTB.SetItemImage( TI_DOCTEMPLATE_PREVIEW, Image( SvtResId(
1098 bLarge ? IMG_SVT_DOCTEMPLATE_PREVIEW_LARGE
1099 : IMG_SVT_DOCTEMPLATE_PREVIEW_SMALL ) ) );
1102 // ------------------------------------------------------------------------
1104 void SvtTemplateWindow::UpdateIcons()
1106 pIconWin->UpdateIcons();
1109 // ------------------------------------------------------------------------
1111 long SvtTemplateWindow::PreNotify( NotifyEvent& rNEvt )
1113 sal_uInt16 nType = rNEvt.GetType();
1114 long nRet = 0;
1116 if ( EVENT_KEYINPUT == nType && rNEvt.GetKeyEvent() )
1118 const KeyCode& rKeyCode = rNEvt.GetKeyEvent()->GetKeyCode();
1119 sal_uInt16 nCode = rKeyCode.GetCode();
1121 if ( KEY_BACKSPACE == nCode && !rKeyCode.GetModifier() && pFileWin->HasChildPathFocus() )
1123 DoAction( TI_DOCTEMPLATE_BACK );
1124 nRet = 1;
1126 else if ( pIconWin->ProcessKeyEvent( *rNEvt.GetKeyEvent() ) )
1128 nRet = 1;
1132 return nRet ? nRet : Window::PreNotify( rNEvt );
1135 // -----------------------------------------------------------------------------
1137 void SvtTemplateWindow::DataChanged( const DataChangedEvent& rDCEvt )
1139 Window::DataChanged( rDCEvt );
1141 if ( ( ( rDCEvt.GetType() == DATACHANGED_SETTINGS ) ||
1142 ( rDCEvt.GetType() == DATACHANGED_DISPLAY ) ) &&
1143 ( rDCEvt.GetFlags() & SETTINGS_STYLE ) )
1145 // update of the background for the area left of the FileView toolbox
1146 SetBackground( Wallpaper( GetSettings().GetStyleSettings().GetFaceColor() ) );
1147 // update of the images of the IconChoiceControl
1148 UpdateIcons();
1149 // update of the toolbox images
1150 InitToolBoxImages();
1153 // ------------------------------------------------------------------------
1155 void SvtTemplateWindow::Resize()
1157 long nItemSize = aSplitWin.GetItemSize( ICONWIN_ID );
1158 long nSplitterWidth = Splitter( this, 0 ).GetSizePixel().Width();
1160 Point aPos = aFileViewTB.GetPosPixel();
1161 aPos.X() = nItemSize + nSplitterWidth / 2;
1162 aFileViewTB.SetPosPixel( aPos );
1164 Size aWinSize = GetOutputSizePixel();
1165 long nWidth = aWinSize.Width() - aPos.X();
1167 nItemSize = nWidth * aSplitWin.GetItemSize( FILEWIN_ID ) / 100;
1168 aPos.X() = pFrameWin->GetPosPixel().X() + 2;
1169 aFrameWinTB.SetPosPixel( aPos );
1171 Size aSize = aFileViewTB.GetSizePixel();
1172 aSize.Width() = nItemSize;
1173 aFileViewTB.SetSizePixel( aSize );
1175 aSize = aFrameWinTB.GetSizePixel();
1176 aSize.Width() = nWidth - nItemSize;
1177 aFrameWinTB.SetSizePixel( aSize );
1179 long nToolBoxHeight = aSize.Height() + aFrameWinTB.GetPosPixel().Y();
1180 aSize = aWinSize;
1181 aSize.Height() -= nToolBoxHeight;
1182 aSplitWin.SetPosSizePixel( Point( 0, nToolBoxHeight ), aSize );
1185 // ------------------------------------------------------------------------
1187 OUString SvtTemplateWindow::GetSelectedFile() const
1189 return pFileWin->GetSelectedFile();
1192 // ------------------------------------------------------------------------
1194 sal_Bool SvtTemplateWindow::IsFileSelected() const
1196 OUString aURL = pFileWin->GetSelectedFile();
1197 sal_Bool bRet = ( !aURL.isEmpty() && !::utl::UCBContentHelper::IsFolder( aURL ) );
1198 return bRet;
1201 // ------------------------------------------------------------------------
1203 void SvtTemplateWindow::OpenFile( sal_Bool bNotAsTemplate )
1205 OUString aURL = pFileWin->GetSelectedFile();
1206 if ( !aURL.isEmpty() && !::utl::UCBContentHelper::IsFolder( aURL ) )
1207 pFrameWin->OpenFile( aURL, sal_False, pFileWin->IsTemplateFolder(), !bNotAsTemplate );
1210 // ------------------------------------------------------------------------
1212 OUString SvtTemplateWindow::GetFolderTitle() const
1214 OUString sTitle;
1215 OUString sFolderURL = pFileWin->GetFolderURL();
1216 if ( pIconWin->IsRootURL( sFolderURL ) )
1217 sTitle = pIconWin->GetIconText( sFolderURL );
1218 else
1219 sTitle = pFileWin->GetFolderTitle();
1220 return sTitle;
1223 // ------------------------------------------------------------------------
1225 OUString SvtTemplateWindow::GetFolderURL() const
1227 return pFileWin->GetFolderURL();
1231 // ------------------------------------------------------------------------
1233 void SvtTemplateWindow::SetFocus( sal_Bool bIconWin )
1235 if ( bIconWin )
1236 pIconWin->SetFocus();
1237 else
1238 pFileWin->SetFocus();
1241 // ------------------------------------------------------------------------
1243 void SvtTemplateWindow::OpenTemplateRoot()
1245 pFileWin->OpenFolder( pIconWin->GetTemplateRootURL() );
1248 // ------------------------------------------------------------------------
1250 void SvtTemplateWindow::SetPrevLevelButtonState( const OUString& rURL )
1252 // disable the prev level button on root folder of the icon pane (except My Documents)
1253 // and on the root of all (file:/// -> count == 0)
1254 INetURLObject aObj( rURL );
1255 sal_Int32 nCount = aObj.getSegmentCount();
1256 sal_Bool bEnable =
1257 ( nCount > 0 &&
1258 ( !pIconWin->IsRootURL( rURL ) || rURL == pIconWin->GetMyDocumentsRootURL() ) );
1259 aFileViewTB.EnableItem( TI_DOCTEMPLATE_PREV, bEnable );
1262 // ------------------------------------------------------------------------
1264 void SvtTemplateWindow::ClearHistory()
1266 if( pHistoryList )
1268 for ( size_t i = 0, n = pHistoryList->size(); i < n; ++i )
1269 delete (*pHistoryList)[ i ];
1270 pHistoryList->clear();
1274 // ------------------------------------------------------------------------
1276 long SvtTemplateWindow::CalcHeight() const
1278 // toolbox height
1279 long nHeight = aFileViewTB.GetSizePixel().Height();
1280 // + iconwin height
1281 nHeight += pIconWin->CalcHeight();
1282 // + little offset
1283 nHeight += 8;
1284 return nHeight;
1287 // ------------------------------------------------------------------------
1289 void SvtTemplateWindow::ReadViewSettings()
1291 // defaults
1292 sal_Int32 nSelectedGroup = ICON_POS_TEMPLATES;
1293 sal_Int32 nSelectedView = TI_DOCTEMPLATE_DOCINFO;
1294 double nSplitRatio = 0.5;
1295 OUString sLastFolder;
1297 SvtViewOptions aViewSettings( E_DIALOG, VIEWSETTING_NEWFROMTEMPLATE );
1298 if ( aViewSettings.Exists() )
1300 // read the settings
1301 aViewSettings.GetUserItem( VIEWSETTING_SELECTEDGROUP ) >>= nSelectedGroup;
1302 aViewSettings.GetUserItem( VIEWSETTING_SELECTEDVIEW ) >>= nSelectedView;
1303 aViewSettings.GetUserItem( VIEWSETTING_SPLITRATIO ) >>= nSplitRatio;
1304 aViewSettings.GetUserItem( VIEWSETTING_LASTFOLDER ) >>= sLastFolder;
1306 // normalize
1307 if ( nSelectedGroup < ICON_POS_NEWDOC ) nSelectedGroup = ICON_POS_NEWDOC;
1308 if ( nSelectedGroup > ICON_POS_SAMPLES ) nSelectedGroup = ICON_POS_SAMPLES;
1310 if ( ( TI_DOCTEMPLATE_DOCINFO != nSelectedView ) && ( TI_DOCTEMPLATE_PREVIEW != nSelectedView ) )
1311 nSelectedView = TI_DOCTEMPLATE_DOCINFO;
1313 if ( nSplitRatio < 0.2 ) nSplitRatio = 0.2;
1314 if ( nSplitRatio > 0.8 ) nSplitRatio = 0.8;
1316 // change our view according to the settings
1318 // the selected view (details or preview)
1319 pFrameWin->ToggleView( TI_DOCTEMPLATE_DOCINFO == nSelectedView );
1320 aFrameWinTB.CheckItem( (sal_uInt16)nSelectedView, sal_True );
1322 // the split ratio
1323 sal_Int32 nSplitFileAndFrameSize = aSplitWin.GetItemSize( FILEWIN_ID ) + aSplitWin.GetItemSize( FRAMEWIN_ID );
1324 sal_Int32 nSplitFileSize = (sal_Int32)(nSplitFileAndFrameSize * nSplitRatio);
1325 sal_Int32 nSplitFrameSize = nSplitFileAndFrameSize - nSplitFileSize;
1326 aSplitWin.SetItemSize( FILEWIN_ID, nSplitFileSize );
1327 aSplitWin.SetItemSize( FRAMEWIN_ID, nSplitFrameSize );
1328 Resize();
1330 // the selected folder
1331 pIconWin->SetCursorPos( nSelectedGroup );
1333 // open the last folder or the selected group
1334 if ( !sLastFolder.isEmpty() )
1335 pFileWin->OpenFolder( sLastFolder );
1336 else
1337 IconClickHdl_Impl( NULL );
1340 // ------------------------------------------------------------------------
1342 void SvtTemplateWindow::WriteViewSettings()
1344 // collect
1345 Sequence< NamedValue > aSettings(4);
1347 // the selected group
1348 aSettings[0].Name = VIEWSETTING_SELECTEDGROUP;
1349 pIconWin->SetFocus();
1350 aSettings[0].Value <<= (sal_Int32)pIconWin->GetCursorPos( );
1352 // the selected view mode
1353 aSettings[1].Name = VIEWSETTING_SELECTEDVIEW;
1354 aSettings[1].Value <<= sal_Int32( aFrameWinTB.IsItemChecked( TI_DOCTEMPLATE_DOCINFO ) ? TI_DOCTEMPLATE_DOCINFO : TI_DOCTEMPLATE_PREVIEW );
1356 // the split ratio
1357 aSettings[2].Name = VIEWSETTING_SPLITRATIO;
1358 sal_Int32 nSplitFileSize = aSplitWin.GetItemSize( FILEWIN_ID );
1359 sal_Int32 nSplitFileAndFrameSize = nSplitFileSize + aSplitWin.GetItemSize( FRAMEWIN_ID );
1360 aSettings[2].Value <<= double( 1.0 * nSplitFileSize / nSplitFileAndFrameSize );
1362 // last folder
1363 aSettings[3].Name = VIEWSETTING_LASTFOLDER;
1364 aSettings[3].Value <<= OUString( pFileWin->GetFolderURL() );
1366 // write
1367 SvtViewOptions aViewSettings( E_DIALOG, VIEWSETTING_NEWFROMTEMPLATE );
1368 aViewSettings.SetUserData( aSettings );
1371 void SvtTemplateWindow::SelectFolder(sal_Int32 nFolderPosition)
1373 pIconWin->SelectFolder(nFolderPosition);
1376 struct SvtTmplDlg_Impl
1378 SvtTemplateWindow* pWin;
1379 OUString aTitle;
1380 Timer aUpdateTimer;
1381 sal_Bool bSelectNoOpen;
1383 uno::Reference< util::XOfficeInstallationDirectories > m_xOfficeInstDirs;
1386 SvtTmplDlg_Impl( Window* pParent ) : pWin( new SvtTemplateWindow( pParent ) ) ,bSelectNoOpen( sal_False ) {}
1388 ~SvtTmplDlg_Impl() { delete pWin; }
1391 SvtDocumentTemplateDialog::SvtDocumentTemplateDialog( Window* pParent ) :
1393 ModalDialog( pParent, SvtResId( DLG_DOCTEMPLATE ) ),
1395 aMoreTemplatesLink ( this, SvtResId( FT_DOCTEMPLATE_LINK ) ),
1396 aLine ( this, SvtResId( FL_DOCTEMPLATE ) ),
1397 aManageBtn ( this, SvtResId( BTN_DOCTEMPLATE_MANAGE ) ),
1398 aPackageBtn ( this, SvtResId( BTN_DOCTEMPLATE_PACKAGE ) ),
1399 aEditBtn ( this, SvtResId( BTN_DOCTEMPLATE_EDIT ) ),
1400 aOKBtn ( this, SvtResId( BTN_DOCTEMPLATE_OPEN ) ),
1401 aCancelBtn ( this, SvtResId( BTN_DOCTEMPLATE_CANCEL ) ),
1402 aHelpBtn ( this, SvtResId( BTN_DOCTEMPLATE_HELP ) ),
1403 pImpl ( NULL )
1405 FreeResource();
1406 InitImpl( );
1409 // ------------------------------------------------------------------------
1411 void SvtDocumentTemplateDialog::InitImpl( )
1413 pImpl = new SvtTmplDlg_Impl( this );
1414 pImpl->aTitle = GetText();
1416 bool bHideLink = ( SvtExtendedSecurityOptions().GetOpenHyperlinkMode()
1417 == SvtExtendedSecurityOptions::OPEN_NEVER );
1418 if ( !bHideLink )
1420 aMoreTemplatesLink.SetURL( "http://templates.libreoffice.org/" );
1421 aMoreTemplatesLink.SetClickHdl( LINK( this, SvtDocumentTemplateDialog, OpenLinkHdl_Impl ) );
1423 else
1424 aMoreTemplatesLink.Hide();
1426 aManageBtn.SetClickHdl( LINK( this, SvtDocumentTemplateDialog, OrganizerHdl_Impl ) );
1427 // Only enable the Package Button, if the service is available
1430 using namespace org::freedesktop::PackageKit;
1431 Reference< XSyncDbusSessionHelper > xSyncDbusSessionHelper(SyncDbusSessionHelper::create(comphelper::getProcessComponentContext()), UNO_QUERY);
1432 aPackageBtn.SetClickHdl( LINK( this, SvtDocumentTemplateDialog, PackageHdl_Impl ) );
1433 aPackageBtn.Enable(xSyncDbusSessionHelper.is());
1435 catch (Exception & e)
1437 SAL_INFO(
1438 "svtools.contnr",
1439 "disable Install Template Pack, caught " << e.Message);
1440 aPackageBtn.Enable(false);
1442 Link aLink = LINK( this, SvtDocumentTemplateDialog, OKHdl_Impl );
1443 aEditBtn.SetClickHdl( aLink );
1444 aOKBtn.SetClickHdl( aLink );
1446 pImpl->pWin->SetSelectHdl( LINK( this, SvtDocumentTemplateDialog, SelectHdl_Impl ) );
1447 pImpl->pWin->SetDoubleClickHdl( LINK( this, SvtDocumentTemplateDialog, DoubleClickHdl_Impl ) );
1448 pImpl->pWin->SetNewFolderHdl( LINK( this, SvtDocumentTemplateDialog, NewFolderHdl_Impl ) );
1449 pImpl->pWin->SetSendFocusHdl( LINK( this, SvtDocumentTemplateDialog, SendFocusHdl_Impl ) );
1451 // dynamic height adjustment
1452 long nHeight = pImpl->pWin->CalcHeight();
1454 Size aSize = GetOutputSizePixel();
1455 Point aPos = aMoreTemplatesLink.GetPosPixel();
1456 Size a6Size = LogicToPixel( Size( 6, 6 ), MAP_APPFONT );
1457 if ( bHideLink )
1458 aPos.Y() += aMoreTemplatesLink.GetSizePixel().Height();
1459 else
1460 aPos.Y() -= a6Size.Height();
1461 long nDelta = aPos.Y() - nHeight;
1462 aSize.Height() -= nDelta;
1463 SetOutputSizePixel( aSize );
1465 aSize.Height() = nHeight;
1466 aSize.Width() -= ( a6Size.Width() * 2 );
1467 pImpl->pWin->SetPosSizePixel( Point( a6Size.Width(), 0 ), aSize );
1469 aPos = aMoreTemplatesLink.GetPosPixel();
1470 aPos.Y() -= nDelta;
1471 aMoreTemplatesLink.SetPosPixel( aPos );
1472 aPos = aLine.GetPosPixel();
1473 aPos.Y() -= nDelta;
1474 aLine.SetPosPixel( aPos );
1475 aPos = aManageBtn.GetPosPixel();
1476 aPos.Y() -= nDelta;
1477 aManageBtn.SetPosPixel( aPos );
1478 aPos = aEditBtn.GetPosPixel();
1479 aPos.Y() -= nDelta;
1480 aEditBtn.SetPosPixel( aPos );
1481 aPos = aOKBtn.GetPosPixel();
1482 aPos.Y() -= nDelta;
1483 aOKBtn.SetPosPixel( aPos );
1484 aPos = aCancelBtn.GetPosPixel();
1485 aPos.Y() -= nDelta;
1486 aCancelBtn.SetPosPixel( aPos );
1487 aPos = aHelpBtn.GetPosPixel();
1488 aPos.Y() -= nDelta;
1489 aHelpBtn.SetPosPixel( aPos );
1490 aPos = aPackageBtn.GetPosPixel();
1491 aPos.Y() -= nDelta;
1492 aPackageBtn.SetPosPixel( aPos );
1494 pImpl->pWin->Show();
1496 SelectHdl_Impl( NULL );
1497 NewFolderHdl_Impl( NULL );
1499 UpdateHdl_Impl( NULL );
1502 // ------------------------------------------------------------------------
1504 SvtDocumentTemplateDialog::~SvtDocumentTemplateDialog()
1506 delete pImpl;
1509 // ------------------------------------------------------------------------
1511 sal_Bool SvtDocumentTemplateDialog::CanEnableEditBtn() const
1513 sal_Bool bEnable = sal_False;
1515 OUString aFolderURL = pImpl->pWin->GetFolderURL();
1516 if ( pImpl->pWin->IsFileSelected() && !aFolderURL.isEmpty() )
1518 OUString aFileTargetURL = pImpl->pWin->GetSelectedFile();
1519 bEnable = !aFileTargetURL.isEmpty();
1522 return bEnable;
1525 // ------------------------------------------------------------------------
1527 IMPL_LINK_NOARG(SvtDocumentTemplateDialog , SelectHdl_Impl)
1529 aEditBtn.Enable( pImpl->pWin->IsTemplateFolderOpen() && CanEnableEditBtn() );
1530 aOKBtn.Enable( pImpl->pWin->IsFileSelected() );
1531 return 0;
1534 // ------------------------------------------------------------------------
1536 IMPL_LINK_NOARG(SvtDocumentTemplateDialog , DoubleClickHdl_Impl)
1538 EndDialog( RET_OK );
1540 if ( !pImpl->bSelectNoOpen )
1541 pImpl->pWin->OpenFile( !pImpl->pWin->IsTemplateFolderOpen() );
1542 return 0;
1545 // ------------------------------------------------------------------------
1547 IMPL_LINK_NOARG(SvtDocumentTemplateDialog , NewFolderHdl_Impl)
1549 OUString aNewTitle( pImpl->aTitle );
1550 aNewTitle += " - ";
1551 aNewTitle += pImpl->pWin->GetFolderTitle();
1552 SetText( aNewTitle );
1554 SelectHdl_Impl( NULL );
1555 return 0;
1558 // ------------------------------------------------------------------------
1560 IMPL_LINK_NOARG(SvtDocumentTemplateDialog , SendFocusHdl_Impl)
1562 if ( pImpl->pWin->HasIconWinFocus() )
1563 aHelpBtn.GrabFocus();
1564 else
1566 if ( aEditBtn.IsEnabled() )
1567 aEditBtn.GrabFocus();
1568 else if ( aOKBtn.IsEnabled() )
1569 aOKBtn.GrabFocus();
1570 else
1571 aCancelBtn.GrabFocus();
1574 return 0;
1577 // ------------------------------------------------------------------------
1579 IMPL_LINK ( SvtDocumentTemplateDialog , OKHdl_Impl, PushButton *, pBtn )
1581 if ( pImpl->pWin->IsFileSelected() )
1583 EndDialog( RET_OK );
1585 if ( !pImpl->bSelectNoOpen )
1586 pImpl->pWin->OpenFile( &aEditBtn == pBtn );
1588 return 0;
1591 // ------------------------------------------------------------------------
1593 IMPL_LINK_NOARG(SvtDocumentTemplateDialog , OrganizerHdl_Impl)
1595 Window* pOldDefWin = Application::GetDefDialogParent();
1596 Application::SetDefDialogParent( this );
1597 Reference < XDesktop2 > xDesktop = Desktop::create( ::comphelper::getProcessComponentContext() );
1598 Reference < XFrame > xFrame( xDesktop->getActiveFrame() );
1599 if ( !xFrame.is() )
1600 xFrame = xDesktop;
1602 com::sun::star::util::URL aTargetURL;
1603 aTargetURL.Complete = "slot:5540";
1604 Reference< com::sun::star::util::XURLTransformer > xTrans(
1605 com::sun::star::util::URLTransformer::create( ::comphelper::getProcessComponentContext() ) );
1606 xTrans->parseStrict( aTargetURL );
1608 Reference < XDispatchProvider > xProv( xFrame, UNO_QUERY );
1609 Reference < XDispatch > xDisp;
1610 xDisp = xProv->queryDispatch( aTargetURL, OUString(), 0 );
1612 if ( xDisp.is() )
1614 Sequence<PropertyValue> aArgs(1);
1615 PropertyValue* pArg = aArgs.getArray();
1616 pArg[0].Name = "Referer";
1617 pArg[0].Value <<= OUString("private:user");
1618 xDisp->dispatch( aTargetURL, aArgs );
1621 Application::SetDefDialogParent( pOldDefWin );
1622 return 0;
1626 IMPL_LINK_NOARG(SvtDocumentTemplateDialog, PackageHdl_Impl)
1630 using namespace org::freedesktop::PackageKit;
1631 Reference< XSyncDbusSessionHelper > xSyncDbusSessionHelper(SyncDbusSessionHelper::create(comphelper::getProcessComponentContext()), UNO_QUERY);
1632 Sequence< OUString > vPackages(1);
1633 vPackages[0] = "libreoffice-templates";
1634 OUString sInteraction("");
1635 xSyncDbusSessionHelper->InstallPackageNames(0, vPackages, sInteraction);
1637 catch (Exception & e)
1639 SAL_INFO(
1640 "svtools.contnr",
1641 "trying Install Template Pack, caught " << e.Message);
1643 return 0;
1646 // ------------------------------------------------------------------------
1648 IMPL_LINK ( SvtDocumentTemplateDialog, UpdateHdl_Impl, Timer*, _pEventSource )
1650 pImpl->pWin->SetFocus( sal_False );
1651 Reference< XDocumentTemplates > xTemplates( frame::DocumentTemplates::create(::comphelper::getProcessComponentContext()) );
1652 if ( _pEventSource )
1653 { // it was no direct call, which means it was triggered by the timer, which means we alread checked the necessity
1654 WaitObject aWaitCursor( this );
1655 xTemplates->update();
1656 if ( pImpl->pWin->IsTemplateFolderOpen() )
1658 pImpl->pWin->ClearHistory();
1659 pImpl->pWin->OpenTemplateRoot();
1662 else
1664 // check if we really need to do the update
1665 ::svt::TemplateFolderCache aCache;
1666 if ( aCache.needsUpdate() )
1667 { // yes -> do it asynchronous (it will take a noticeable time)
1669 // (but first store the current state)
1670 aCache.storeState();
1672 // start the timer for the async update
1673 pImpl->aUpdateTimer.SetTimeout( 300 );
1674 pImpl->aUpdateTimer.SetTimeoutHdl( LINK( this, SvtDocumentTemplateDialog, UpdateHdl_Impl ) );
1675 pImpl->aUpdateTimer.Start();
1678 return 0;
1681 // ------------------------------------------------------------------------
1683 IMPL_LINK_NOARG(SvtDocumentTemplateDialog, OpenLinkHdl_Impl)
1685 OUString sURL( aMoreTemplatesLink.GetURL() );
1686 if ( !sURL.isEmpty() )
1688 localizeWebserviceURI(sURL);
1691 uno::Reference< uno::XComponentContext > xContext =
1692 ::comphelper::getProcessComponentContext();
1693 uno::Reference< com::sun::star::system::XSystemShellExecute > xSystemShell(
1694 com::sun::star::system::SystemShellExecute::create(xContext) );
1695 if ( xSystemShell.is() )
1696 xSystemShell->execute( sURL, OUString(), com::sun::star::system::SystemShellExecuteFlags::URIS_ONLY );
1697 EndDialog( RET_CANCEL );
1699 catch( const uno::Exception& e )
1701 OSL_TRACE( "Caught exception: %s\n thread terminated.\n",
1702 OUStringToOString(e.Message, RTL_TEXTENCODING_UTF8).getStr());
1705 return 0;
1708 void SvtDocumentTemplateDialog::SelectTemplateFolder()
1710 pImpl->pWin->SelectFolder(ICON_POS_TEMPLATES);
1713 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */