1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 "----------------------------------"
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"
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)" ) ),
165 aDummyHeaderBar
.Show();
167 aIconCtrl
.SetAccessibleName( OUString( "Groups" ) );
168 aIconCtrl
.SetHelpId( HID_TEMPLATEDLG_ICONCTRL
);
169 aIconCtrl
.SetChoiceWithCursor( sal_True
);
170 aIconCtrl
.SetSelectionMode( SINGLE_SELECTION
);
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
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
;
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
;
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
;
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
)
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
276 SvxIconChoiceCtrlEntry
* pEntry
= aIconCtrl
.GetCursor( );
278 aURL
= *static_cast<OUString
*>(pEntry
->GetUserData());
283 OUString
SvtIconWindow_Impl::GetSelectedIconURL() const
286 SvxIconChoiceCtrlEntry
* pEntry
= aIconCtrl
.GetSelectedEntry( nPos
);
289 aURL
= *static_cast<OUString
*>(pEntry
->GetUserData());
293 OUString
SvtIconWindow_Impl::GetIconText( const OUString
& rURL
) const
296 SvxIconChoiceCtrlEntry
* pEntry
= GetEntry( rURL
);
298 aText
= MnemonicGenerator::EraseAllMnemonicChars( pEntry
->GetText() );
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( );
313 nPos
= aIconCtrl
.GetEntryListPos( pCursorEntry
);
318 sal_uLong
SvtIconWindow_Impl::GetSelectEntryPos() const
321 if ( !aIconCtrl
.GetSelectedEntry( nPos
) )
322 nPos
= ~sal_uLong(0);
326 void SvtIconWindow_Impl::SetCursorPos( sal_uLong nPos
)
328 SvxIconChoiceCtrlEntry
* pEntry
= aIconCtrl
.GetEntry( nPos
);
329 aIconCtrl
.SetCursor( pEntry
);
330 aIconCtrl
.Invalidate();
334 void SvtIconWindow_Impl::SetFocus()
336 aIconCtrl
.GrabFocus();
339 long SvtIconWindow_Impl::CalcHeight() const
341 // calculate the required height of the IconControl
343 sal_uLong nCount
= aIconCtrl
.GetEntryCount();
345 // bottom of the last icon
346 nHeight
= aIconCtrl
.GetEntry(nCount
-1)->GetBoundRect().Bottom();
348 // + headerbar height
349 nHeight
+= aDummyHeaderBar
.GetSizePixel().Height();
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
) )
367 else if ( rURL
.startsWith(aTemplateRootURL
) )
369 else if ( rURL
.startsWith(aMyDocumentsRootURL
) )
371 else if ( rURL
.startsWith(aSamplesFolderRootURL
) )
373 else if ( aMyDocumentsRootURL
.startsWith(rURL
) )
377 DBG_WARNING( "SvtIconWindow_Impl::GetRootPos(): invalid position" );
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
);
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
);
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
,
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
);
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
)
471 if( aURL
== sSeparator
)
473 OUString
aSeparator( aSeparatorStr
);
474 aNewDocs
.push_back( aSeparator
);
479 OUString aRow
= MnemonicGenerator::EraseAllMnemonicChars( aTitle
);
493 if ( !aImageURL
.isEmpty() )
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
];
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
)
528 rParent
.SetPrevLevelButtonState( rURL
);
530 if ( INetURLObject( rURL
).GetProtocol() == INET_PROT_PRIVATE
)
532 aFileView
.EnableNameReplacing( sal_False
);
533 aFileView
.Initialize( GetNewDocContents() );
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
557 ::utl::UCBContentHelper::GetTitle( aFolderURL
, &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
);
586 // class SvtFrameWindow_Impl ---------------------------------------------
588 SvtFrameWindow_Impl::SvtFrameWindow_Impl( 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()
611 void SvtFrameWindow_Impl::ViewEditWin()
614 xWindow
->setVisible( sal_False
);
619 void SvtFrameWindow_Impl::ViewTextWin()
623 xWindow
->setVisible( sal_True
);
627 void SvtFrameWindow_Impl::ViewEmptyWin()
629 xWindow
->setVisible( sal_False
);
635 void SvtFrameWindow_Impl::ViewNonEmptyWin()
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
)
675 if ( !rURL
.isEmpty() && bPreview
&& m_xDocProps
.is() )
678 if ( rURL
.isEmpty() )
680 m_xFrame
->setComponent( Reference
< com::sun::star::awt::XWindow
>(), Reference
< XController
>() );
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
);
692 Reference
< XDispatchProvider
> xProv( m_xFrame
, UNO_QUERY_THROW
);
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() ),
705 Reference
< XDispatch
> xDisp
= xProv
.is() ?
706 xProv
->queryDispatch( aURL
, aTarget
, 0 ) : Reference
< XDispatch
>();
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
;
735 aArgs
[2].Value
.setValue( &b
, ::getBooleanCppuType() );
736 xDisp
->dispatch( aURL
, aArgs
);
739 Reference
< ::com::sun::star::frame::XController
> xCtrl
= m_xFrame
->getController();
742 Reference
< ::com::sun::star::frame::XModel
> xMdl
= xCtrl
->getModel();
744 aDispURL
= xMdl
->getURL();
747 if( aDispURL
!= aURL
.Complete
)
749 m_xFrame
->setComponent( Reference
< com::sun::star::awt::XWindow
>(), Reference
< XController
>() );
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
);
768 Sequence
< PropertyValue
> aArgs
;
769 xDisp
->dispatch( aURL
, aArgs
);
776 void SvtFrameWindow_Impl::ToggleView( sal_Bool 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
)
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 );
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
) );
824 // initialize the timers
825 aSelectTimer
.SetTimeout( 200 );
826 aSelectTimer
.SetTimeoutHdl( LINK( this, SvtTemplateWindow
, TimeoutHdl_Impl
) );
828 // initialize the toolboxes and then show them
835 Application::PostUserEvent( LINK( this, SvtTemplateWindow
, ResizeHdl_Impl
) );
838 // ------------------------------------------------------------------------
840 SvtTemplateWindow::~SvtTemplateWindow()
842 WriteViewSettings( );
849 for ( size_t i
= 0, n
= pHistoryList
->size(); i
< n
; ++i
)
850 delete (*pHistoryList
)[ i
];
851 pHistoryList
->clear();
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
);
872 // ------------------------------------------------------------------------
874 IMPL_LINK_NOARG(SvtTemplateWindow
, FileSelectHdl_Impl
)
876 aSelectTimer
.Start();
880 // ------------------------------------------------------------------------
882 IMPL_LINK_NOARG(SvtTemplateWindow
, FileDblClickHdl_Impl
)
884 if ( aSelectTimer
.IsActive() )
887 OUString aURL
= pFileWin
->GetSelectedFile();
888 if ( !aURL
.isEmpty() )
890 if ( ::utl::UCBContentHelper::IsFolder( aURL
) )
891 pFileWin
->OpenFolder( aURL
);
893 aDoubleClickHdl
.Call( this );
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 );
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
);
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
);
936 // ------------------------------------------------------------------------
938 IMPL_LINK ( SvtTemplateWindow
, ClickHdl_Impl
, ToolBox
*, pToolBox
)
940 DoAction( pToolBox
->GetCurItemId() );
944 // ------------------------------------------------------------------------
946 IMPL_LINK_NOARG(SvtTemplateWindow
, ResizeHdl_Impl
)
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
);
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
;
981 pHistoryList
= new HistoryList_Impl
;
982 else if ( pHistoryList
->size() > 0 )
984 FolderHistory
* pLastEntry
= pHistoryList
->back();
985 bInsert
= ( rURL
!= pLastEntry
->m_sURL
);
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
);
1010 // ------------------------------------------------------------------------
1012 void SvtTemplateWindow::DoAction( sal_uInt16 nAction
)
1016 case TI_DOCTEMPLATE_BACK
:
1018 if ( pHistoryList
&& pHistoryList
->size() > 1 )
1023 case TI_DOCTEMPLATE_PREV
:
1026 if ( pFileWin
->HasPreviousLevel( aURL
) )
1027 pFileWin
->OpenFolder( aURL
);
1031 case TI_DOCTEMPLATE_PRINT
:
1033 OUString
sPrintFile( pFileWin
->GetSelectedFile() );
1034 if ( !sPrintFile
.isEmpty() )
1035 PrintFile( sPrintFile
);
1039 case TI_DOCTEMPLATE_DOCINFO
:
1040 case TI_DOCTEMPLATE_PREVIEW
:
1042 pFrameWin
->ToggleView( TI_DOCTEMPLATE_DOCINFO
== nAction
);
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
);
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();
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
);
1126 else if ( pIconWin
->ProcessKeyEvent( *rNEvt
.GetKeyEvent() ) )
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
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();
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
) );
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
1215 OUString sFolderURL
= pFileWin
->GetFolderURL();
1216 if ( pIconWin
->IsRootURL( sFolderURL
) )
1217 sTitle
= pIconWin
->GetIconText( sFolderURL
);
1219 sTitle
= pFileWin
->GetFolderTitle();
1223 // ------------------------------------------------------------------------
1225 OUString
SvtTemplateWindow::GetFolderURL() const
1227 return pFileWin
->GetFolderURL();
1231 // ------------------------------------------------------------------------
1233 void SvtTemplateWindow::SetFocus( sal_Bool bIconWin
)
1236 pIconWin
->SetFocus();
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();
1258 ( !pIconWin
->IsRootURL( rURL
) || rURL
== pIconWin
->GetMyDocumentsRootURL() ) );
1259 aFileViewTB
.EnableItem( TI_DOCTEMPLATE_PREV
, bEnable
);
1262 // ------------------------------------------------------------------------
1264 void SvtTemplateWindow::ClearHistory()
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
1279 long nHeight
= aFileViewTB
.GetSizePixel().Height();
1281 nHeight
+= pIconWin
->CalcHeight();
1287 // ------------------------------------------------------------------------
1289 void SvtTemplateWindow::ReadViewSettings()
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
;
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
);
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
);
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
);
1337 IconClickHdl_Impl( NULL
);
1340 // ------------------------------------------------------------------------
1342 void SvtTemplateWindow::WriteViewSettings()
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
);
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
);
1363 aSettings
[3].Name
= VIEWSETTING_LASTFOLDER
;
1364 aSettings
[3].Value
<<= OUString( pFileWin
->GetFolderURL() );
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
;
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
) ),
1409 // ------------------------------------------------------------------------
1411 void SvtDocumentTemplateDialog::InitImpl( )
1413 pImpl
= new SvtTmplDlg_Impl( this );
1414 pImpl
->aTitle
= GetText();
1416 bool bHideLink
= ( SvtExtendedSecurityOptions().GetOpenHyperlinkMode()
1417 == SvtExtendedSecurityOptions::OPEN_NEVER
);
1420 aMoreTemplatesLink
.SetURL( "http://templates.libreoffice.org/" );
1421 aMoreTemplatesLink
.SetClickHdl( LINK( this, SvtDocumentTemplateDialog
, OpenLinkHdl_Impl
) );
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
)
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
);
1458 aPos
.Y() += aMoreTemplatesLink
.GetSizePixel().Height();
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();
1471 aMoreTemplatesLink
.SetPosPixel( aPos
);
1472 aPos
= aLine
.GetPosPixel();
1474 aLine
.SetPosPixel( aPos
);
1475 aPos
= aManageBtn
.GetPosPixel();
1477 aManageBtn
.SetPosPixel( aPos
);
1478 aPos
= aEditBtn
.GetPosPixel();
1480 aEditBtn
.SetPosPixel( aPos
);
1481 aPos
= aOKBtn
.GetPosPixel();
1483 aOKBtn
.SetPosPixel( aPos
);
1484 aPos
= aCancelBtn
.GetPosPixel();
1486 aCancelBtn
.SetPosPixel( aPos
);
1487 aPos
= aHelpBtn
.GetPosPixel();
1489 aHelpBtn
.SetPosPixel( aPos
);
1490 aPos
= aPackageBtn
.GetPosPixel();
1492 aPackageBtn
.SetPosPixel( aPos
);
1494 pImpl
->pWin
->Show();
1496 SelectHdl_Impl( NULL
);
1497 NewFolderHdl_Impl( NULL
);
1499 UpdateHdl_Impl( NULL
);
1502 // ------------------------------------------------------------------------
1504 SvtDocumentTemplateDialog::~SvtDocumentTemplateDialog()
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();
1525 // ------------------------------------------------------------------------
1527 IMPL_LINK_NOARG(SvtDocumentTemplateDialog
, SelectHdl_Impl
)
1529 aEditBtn
.Enable( pImpl
->pWin
->IsTemplateFolderOpen() && CanEnableEditBtn() );
1530 aOKBtn
.Enable( pImpl
->pWin
->IsFileSelected() );
1534 // ------------------------------------------------------------------------
1536 IMPL_LINK_NOARG(SvtDocumentTemplateDialog
, DoubleClickHdl_Impl
)
1538 EndDialog( RET_OK
);
1540 if ( !pImpl
->bSelectNoOpen
)
1541 pImpl
->pWin
->OpenFile( !pImpl
->pWin
->IsTemplateFolderOpen() );
1545 // ------------------------------------------------------------------------
1547 IMPL_LINK_NOARG(SvtDocumentTemplateDialog
, NewFolderHdl_Impl
)
1549 OUString
aNewTitle( pImpl
->aTitle
);
1551 aNewTitle
+= pImpl
->pWin
->GetFolderTitle();
1552 SetText( aNewTitle
);
1554 SelectHdl_Impl( NULL
);
1558 // ------------------------------------------------------------------------
1560 IMPL_LINK_NOARG(SvtDocumentTemplateDialog
, SendFocusHdl_Impl
)
1562 if ( pImpl
->pWin
->HasIconWinFocus() )
1563 aHelpBtn
.GrabFocus();
1566 if ( aEditBtn
.IsEnabled() )
1567 aEditBtn
.GrabFocus();
1568 else if ( aOKBtn
.IsEnabled() )
1571 aCancelBtn
.GrabFocus();
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
);
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() );
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 );
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
);
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
)
1641 "trying Install Template Pack, caught " << e
.Message
);
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();
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();
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());
1708 void SvtDocumentTemplateDialog::SelectTemplateFolder()
1710 pImpl
->pWin
->SelectFolder(ICON_POS_TEMPLATES
);
1713 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */