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 "templwin.hxx"
21 #include <svtools/templdlg.hxx>
22 #include <svtools/svtresid.hxx>
23 #include <svtools/langhelp.hxx>
24 #include <unotools/pathoptions.hxx>
25 #include <unotools/dynamicmenuoptions.hxx>
26 #include <unotools/extendedsecurityoptions.hxx>
27 #include <vcl/xtextedt.hxx>
28 #include <svl/inettype.hxx>
29 #include <svtools/imagemgr.hxx>
30 #include <svtools/miscopt.hxx>
31 #include <svtools/templatefoldercache.hxx>
32 #include <svtools/imgdef.hxx>
33 #include <vcl/txtattr.hxx>
34 #include <svtools/svtools.hrc>
35 #include "templwin.hrc"
36 #include <svtools/helpid.hrc>
37 #include <unotools/viewoptions.hxx>
38 #include <unotools/ucbhelper.hxx>
39 #include "unotools/configmgr.hxx"
40 #include <com/sun/star/awt/XWindow.hpp>
41 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
42 #include <com/sun/star/frame/Frame.hpp>
43 #include <toolkit/helper/vclunohelper.hxx>
44 #include <com/sun/star/util/URL.hpp>
45 #include <com/sun/star/util/URLTransformer.hpp>
46 #include <com/sun/star/util/XURLTransformer.hpp>
47 #include <com/sun/star/util/XOfficeInstallationDirectories.hpp>
48 #include <com/sun/star/frame/Desktop.hpp>
49 #include <com/sun/star/frame/XDispatchProvider.hpp>
50 #include <com/sun/star/frame/DocumentTemplates.hpp>
51 #include <com/sun/star/frame/XDocumentTemplates.hpp>
52 #include <com/sun/star/frame/XComponentLoader.hpp>
53 #include <com/sun/star/beans/PropertyValue.hpp>
54 #include <com/sun/star/ucb/XContent.hpp>
55 #include <com/sun/star/ucb/XCommandEnvironment.hpp>
56 #include <com/sun/star/view/XPrintable.hpp>
57 #include <com/sun/star/document/DocumentProperties.hpp>
58 #include <com/sun/star/beans/XPropertySet.hpp>
59 #include <com/sun/star/beans/XMultiPropertySet.hpp>
60 #include <com/sun/star/beans/XPropertySetInfo.hpp>
61 #include <com/sun/star/io/IOException.hpp>
62 #include <com/sun/star/util/DateTime.hpp>
63 #include <com/sun/star/script/XTypeConverter.hpp>
64 #include <com/sun/star/system/SystemShellExecute.hpp>
65 #include <com/sun/star/system/SystemShellExecuteFlags.hpp>
66 #include <com/sun/star/task/InteractionHandler.hpp>
67 #include <org/freedesktop/PackageKit/SyncDbusSessionHelper.hpp>
68 #include <unotools/localedatawrapper.hxx>
69 #include <com/sun/star/container/XNameContainer.hpp>
70 #include <vcl/waitobj.hxx>
71 #include <comphelper/processfactory.hxx>
72 #include <tools/urlobj.hxx>
73 #include <tools/datetime.hxx>
74 #include <vcl/svapp.hxx>
75 #include <vcl/split.hxx>
76 #include <vcl/msgbox.hxx>
77 #include <svtools/DocumentInfoPreview.hxx>
78 #include <vcl/mnemonic.hxx>
80 #include <ucbhelper/content.hxx>
81 #include <comphelper/string.hxx>
83 using namespace ::com::sun::star
;
84 using namespace ::com::sun::star::beans
;
85 using namespace ::com::sun::star::container
;
86 using namespace ::com::sun::star::frame
;
87 using namespace ::com::sun::star::document
;
88 using namespace ::com::sun::star::lang
;
89 using namespace ::com::sun::star::ucb
;
90 using namespace ::com::sun::star::uno
;
91 using namespace ::com::sun::star::view
;
92 using namespace svtools
;
94 #define aSeparatorStr "----------------------------------"
100 #define ICON_POS_NEWDOC 0
101 #define ICON_POS_TEMPLATES 1
102 #define ICON_POS_MYDOCS 2
103 #define ICON_POS_SAMPLES 3
105 #define VIEWSETTING_NEWFROMTEMPLATE "NewFromTemplate"
106 #define VIEWSETTING_SELECTEDGROUP "SelectedGroup"
107 #define VIEWSETTING_SELECTEDVIEW "SelectedView"
108 #define VIEWSETTING_SPLITRATIO "SplitRatio"
109 #define VIEWSETTING_LASTFOLDER "LastFolder"
116 FolderHistory( const String
& _rURL
, sal_Int32 _nGroup
) :
117 m_sURL( _rURL
), m_nGroup( _nGroup
) {}
120 typedef ::std::vector
< OUString
* > NewDocList_Impl
;
122 // class SvtDummyHeaderBar_Impl ------------------------------------------
124 void SvtDummyHeaderBar_Impl::UpdateBackgroundColor()
126 SetBackground( Wallpaper( GetSettings().GetStyleSettings().GetWindowColor() ) );
129 SvtDummyHeaderBar_Impl::SvtDummyHeaderBar_Impl( Window
* pPar
) : Window( pPar
)
131 SetSizePixel( HeaderBar( this, 0 ).CalcWindowSizePixel() ); // HeaderBar used only to calculate size
133 UpdateBackgroundColor();
136 SvtDummyHeaderBar_Impl::~SvtDummyHeaderBar_Impl()
140 void SvtDummyHeaderBar_Impl::DataChanged( const DataChangedEvent
& r
)
142 Window::DataChanged( r
);
143 if( r
.GetType() == DATACHANGED_SETTINGS
)
144 UpdateBackgroundColor();
147 // class SvtIconWindow_Impl ----------------------------------------------
149 SvtIconWindow_Impl::SvtIconWindow_Impl( Window
* pParent
) :
151 Window( pParent
, WB_DIALOGCONTROL
| WB_BORDER
| WB_3DLOOK
),
153 aDummyHeaderBar( this ),
154 aIconCtrl( this, WB_ICON
| WB_NOCOLUMNHEADER
| WB_HIGHLIGHTFRAME
| /*!WB_NOSELECTION |*/
155 WB_NODRAGSELECTION
| WB_TABSTOP
| WB_CLIPCHILDREN
),
156 aNewDocumentRootURL( "private:newdoc" ),
157 aMyDocumentsRootURL( SvtPathOptions().GetWorkPath() ),
158 aSamplesFolderRootURL( SvtPathOptions().
159 SubstituteVariable( String( "$(insturl)/share/samples/$(vlang)" ) ) ),
163 aDummyHeaderBar
.Show();
165 aIconCtrl
.SetAccessibleName( String( RTL_CONSTASCII_USTRINGPARAM("Groups") ) );
166 aIconCtrl
.SetHelpId( HID_TEMPLATEDLG_ICONCTRL
);
167 aIconCtrl
.SetChoiceWithCursor( sal_True
);
168 aIconCtrl
.SetSelectionMode( SINGLE_SELECTION
);
171 // detect the root URL of templates
172 Reference
< XDocumentTemplates
> xTemplates( frame::DocumentTemplates::create(::comphelper::getProcessComponentContext()) );
174 Reference
< XContent
> aRootContent
= xTemplates
->getContent();
175 Reference
< XCommandEnvironment
> aCmdEnv
;
177 if ( aRootContent
.is() )
178 aTemplateRootURL
= aRootContent
->getIdentifier()->getContentIdentifier();
180 // insert the categories
182 Image
aImage( SvtResId( IMG_SVT_NEWDOC
) );
183 nMaxTextLength
= aImage
.GetSizePixel().Width();
184 String aEntryStr
= SVT_RESSTR(STR_SVT_NEWDOC
);
185 SvxIconChoiceCtrlEntry
* pEntry
=
186 aIconCtrl
.InsertEntry( aEntryStr
, aImage
, ICON_POS_NEWDOC
);
187 pEntry
->SetUserData( new String( aNewDocumentRootURL
) );
188 pEntry
->SetQuickHelpText( SVT_RESSTR(STR_SVT_NEWDOC_HELP
) );
189 DBG_ASSERT( !pEntry
->GetBoundRect().IsEmpty(), "empty rectangle" );
190 long nTemp
= pEntry
->GetBoundRect().GetSize().Width();
191 if (nTemp
> nMaxTextLength
)
192 nMaxTextLength
= nTemp
;
195 if( aTemplateRootURL
.Len() > 0 )
197 aEntryStr
= SVT_RESSTR(STR_SVT_TEMPLATES
);
198 pEntry
= aIconCtrl
.InsertEntry(
199 aEntryStr
, Image( SvtResId( IMG_SVT_TEMPLATES
) ), ICON_POS_TEMPLATES
);
200 pEntry
->SetUserData( new String( aTemplateRootURL
) );
201 pEntry
->SetQuickHelpText(SVT_RESSTR(STR_SVT_TEMPLATES_HELP
));
202 DBG_ASSERT( !pEntry
->GetBoundRect().IsEmpty(), "empty rectangle" );
203 nTemp
= pEntry
->GetBoundRect().GetSize().Width();
204 if (nTemp
> nMaxTextLength
)
205 nMaxTextLength
= nTemp
;
209 aEntryStr
= SVT_RESSTR(STR_SVT_MYDOCS
);
210 pEntry
= aIconCtrl
.InsertEntry(
211 aEntryStr
, Image( SvtResId( IMG_SVT_MYDOCS
) ), ICON_POS_MYDOCS
);
212 pEntry
->SetUserData( new String( aMyDocumentsRootURL
) );
213 pEntry
->SetQuickHelpText( SVT_RESSTR(STR_SVT_MYDOCS_HELP
) );
214 DBG_ASSERT( !pEntry
->GetBoundRect().IsEmpty(), "empty rectangle" );
215 nTemp
= pEntry
->GetBoundRect().GetSize().Width();
216 if( nTemp
> nMaxTextLength
)
217 nMaxTextLength
= nTemp
;
220 aEntryStr
= SVT_RESSTR(STR_SVT_SAMPLES
);
221 pEntry
= aIconCtrl
.InsertEntry(
222 aEntryStr
, Image( SvtResId( IMG_SVT_SAMPLES
) ), ICON_POS_SAMPLES
);
223 pEntry
->SetUserData( new String( aSamplesFolderRootURL
) );
224 pEntry
->SetQuickHelpText( SVT_RESSTR(STR_SVT_SAMPLES_HELP
));
225 DBG_ASSERT( !pEntry
->GetBoundRect().IsEmpty(), "empty rectangle" );
226 nTemp
= pEntry
->GetBoundRect().GetSize().Width();
227 if (nTemp
> nMaxTextLength
)
228 nMaxTextLength
= nTemp
;
230 aIconCtrl
.CreateAutoMnemonics();
233 SvtIconWindow_Impl::~SvtIconWindow_Impl()
235 for ( sal_uLong i
= 0; i
< aIconCtrl
.GetEntryCount(); ++i
)
237 SvxIconChoiceCtrlEntry
* pEntry
= aIconCtrl
.GetEntry( i
);
238 delete (String
*)pEntry
->GetUserData();
242 SvxIconChoiceCtrlEntry
* SvtIconWindow_Impl::GetEntry( const String
& rURL
) const
244 SvxIconChoiceCtrlEntry
* pEntry
= NULL
;
245 for ( sal_uLong i
= 0; i
< aIconCtrl
.GetEntryCount(); ++i
)
247 SvxIconChoiceCtrlEntry
* pTemp
= aIconCtrl
.GetEntry( i
);
248 String
aURL( *( (String
*)pTemp
->GetUserData() ) );
259 void SvtIconWindow_Impl::Resize()
261 Size aWinSize
= GetOutputSizePixel();
262 Size aHeaderSize
= aDummyHeaderBar
.GetSizePixel();
263 aHeaderSize
.Width() = aWinSize
.Width();
264 aDummyHeaderBar
.SetSizePixel( aHeaderSize
);
265 long nHeaderHeight
= aHeaderSize
.Height();
266 aWinSize
.Height() -= nHeaderHeight
;
267 aIconCtrl
.SetPosSizePixel( Point( 0, nHeaderHeight
), aWinSize
);
268 aIconCtrl
.ArrangeIcons();
271 String
SvtIconWindow_Impl::GetCursorPosIconURL() const
274 SvxIconChoiceCtrlEntry
* pEntry
= aIconCtrl
.GetCursor( );
276 aURL
= *static_cast<String
*>(pEntry
->GetUserData());
281 String
SvtIconWindow_Impl::GetSelectedIconURL() const
284 SvxIconChoiceCtrlEntry
* pEntry
= aIconCtrl
.GetSelectedEntry( nPos
);
287 aURL
= *static_cast<String
*>(pEntry
->GetUserData());
291 String
SvtIconWindow_Impl::GetIconText( const String
& rURL
) const
294 SvxIconChoiceCtrlEntry
* pEntry
= GetEntry( rURL
);
296 aText
= MnemonicGenerator::EraseAllMnemonicChars( pEntry
->GetText() );
300 void SvtIconWindow_Impl::InvalidateIconControl()
302 aIconCtrl
.Invalidate();
305 sal_uLong
SvtIconWindow_Impl::GetCursorPos() const
307 sal_uLong nPos
= ~sal_uLong(0);
309 SvxIconChoiceCtrlEntry
* pCursorEntry
= aIconCtrl
.GetCursor( );
311 nPos
= aIconCtrl
.GetEntryListPos( pCursorEntry
);
316 sal_uLong
SvtIconWindow_Impl::GetSelectEntryPos() const
319 if ( !aIconCtrl
.GetSelectedEntry( nPos
) )
320 nPos
= ~sal_uLong(0);
324 void SvtIconWindow_Impl::SetCursorPos( sal_uLong nPos
)
326 SvxIconChoiceCtrlEntry
* pEntry
= aIconCtrl
.GetEntry( nPos
);
327 aIconCtrl
.SetCursor( pEntry
);
328 aIconCtrl
.Invalidate();
332 void SvtIconWindow_Impl::SetFocus()
334 aIconCtrl
.GrabFocus();
337 long SvtIconWindow_Impl::CalcHeight() const
339 // calculate the required height of the IconControl
341 sal_uLong nCount
= aIconCtrl
.GetEntryCount();
343 // bottom of the last icon
344 nHeight
= aIconCtrl
.GetEntry(nCount
-1)->GetBoundRect().Bottom();
346 // + headerbar height
347 nHeight
+= aDummyHeaderBar
.GetSizePixel().Height();
352 sal_Bool
SvtIconWindow_Impl::IsRootURL( const String
& rURL
) const
354 return rURL
== aNewDocumentRootURL
||
355 rURL
== aTemplateRootURL
||
356 rURL
== aMyDocumentsRootURL
||
357 rURL
== aSamplesFolderRootURL
;
360 sal_uLong
SvtIconWindow_Impl::GetRootPos( const String
& rURL
) const
362 sal_uLong nPos
= ~sal_uLong(0);
363 if ( aNewDocumentRootURL
.Match( rURL
) == STRING_MATCH
)
365 else if ( aTemplateRootURL
.Match( rURL
) == STRING_MATCH
)
367 else if ( aMyDocumentsRootURL
.Match( rURL
) == STRING_MATCH
)
369 else if ( aSamplesFolderRootURL
.Match( rURL
) == STRING_MATCH
)
371 else if ( rURL
.Match( aMyDocumentsRootURL
) == STRING_MATCH
)
375 DBG_WARNING( "SvtIconWindow_Impl::GetRootPos(): invalid position" );
382 void SvtIconWindow_Impl::UpdateIcons()
384 aIconCtrl
.GetEntry( ICON_POS_NEWDOC
)->SetImage(
385 Image( SvtResId( IMG_SVT_NEWDOC
) ) );
386 aIconCtrl
.GetEntry( ICON_POS_TEMPLATES
)->SetImage(
387 Image( SvtResId( IMG_SVT_TEMPLATES
) ) );
388 aIconCtrl
.GetEntry( ICON_POS_MYDOCS
)->SetImage(
389 Image( SvtResId( IMG_SVT_MYDOCS
) ) );
390 aIconCtrl
.GetEntry( ICON_POS_SAMPLES
)->SetImage(
391 Image( SvtResId( IMG_SVT_SAMPLES
) ) );
394 void SvtIconWindow_Impl::SelectFolder(sal_Int32 nFolderPosition
)
396 SvxIconChoiceCtrlEntry
* pEntry
= aIconCtrl
.GetEntry( nFolderPosition
);
399 aIconCtrl
.SetCursor( pEntry
);
400 aIconCtrl
.GetClickHdl().Call(&aIconCtrl
);
404 // class SvtFileViewWindow_Impl -----------------------------------------_
406 SvtFileViewWindow_Impl::SvtFileViewWindow_Impl( SvtTemplateWindow
* pParent
) :
408 Window( pParent
, WB_DIALOGCONTROL
| WB_TABSTOP
| WB_BORDER
| WB_3DLOOK
),
410 rParent ( *pParent
),
411 aFileView ( this, SvtResId( CTRL_FILEVIEW
), FILEVIEW_SHOW_NONE
| FILEVIEW_SHOW_ONLYTITLE
),
412 bIsTemplateFolder ( sal_False
)
415 aFileView
.SetStyle( aFileView
.GetStyle() | WB_DIALOGCONTROL
| WB_TABSTOP
);
416 aFileView
.SetHelpId( HID_TEMPLATEDLG_FILEVIEW
);
418 aFileView
.EnableAutoResize();
419 aFileView
.EnableContextMenu( sal_False
);
420 aFileView
.EnableDelete( sal_False
);
423 SvtFileViewWindow_Impl::~SvtFileViewWindow_Impl()
427 void GetMenuEntry_Impl
429 Sequence
< PropertyValue
>& aDynamicMenuEntry
,
436 for ( int i
= 0; i
< aDynamicMenuEntry
.getLength(); i
++ )
438 if ( aDynamicMenuEntry
[i
].Name
== DYNAMICMENU_PROPERTYNAME_URL
)
439 aDynamicMenuEntry
[i
].Value
>>= rURL
;
440 else if ( aDynamicMenuEntry
[i
].Name
== DYNAMICMENU_PROPERTYNAME_TITLE
)
441 aDynamicMenuEntry
[i
].Value
>>= rTitle
;
442 else if ( aDynamicMenuEntry
[i
].Name
== DYNAMICMENU_PROPERTYNAME_IMAGEIDENTIFIER
)
443 aDynamicMenuEntry
[i
].Value
>>= rImageId
;
444 else if ( aDynamicMenuEntry
[i
].Name
== DYNAMICMENU_PROPERTYNAME_TARGETNAME
)
445 aDynamicMenuEntry
[i
].Value
>>= rFrame
;
449 Sequence
< OUString
> SvtFileViewWindow_Impl::GetNewDocContents() const
451 NewDocList_Impl aNewDocs
;
452 Sequence
< Sequence
< PropertyValue
> > aDynamicMenuEntries
;
453 aDynamicMenuEntries
= SvtDynamicMenuOptions().GetMenu( E_NEWMENU
);
458 OUString aTargetFrame
;
460 sal_uInt32 i
, nCount
= aDynamicMenuEntries
.getLength();
461 OUString
sSeparator( "private:separator" );
462 OUString
sSlotURL( "slot:5500" );
464 for ( i
= 0; i
< nCount
; ++i
)
466 GetMenuEntry_Impl( aDynamicMenuEntries
[i
], aTitle
, aURL
, aTargetFrame
, aImageURL
);
467 if( aURL
== sSlotURL
)
469 if( aURL
== sSeparator
)
471 String
aSeparator( aSeparatorStr
);
472 OUString
* pSeparator
= new OUString( aSeparator
);
473 aNewDocs
.push_back( pSeparator
);
478 String aRow
= MnemonicGenerator::EraseAllMnemonicChars( String( aTitle
) );
487 aRow
+= String( aURL
);
492 if ( !aImageURL
.isEmpty() )
495 aRow
+= String( aImageURL
);
498 OUString
* pRow
= new OUString( aRow
);
499 aNewDocs
.push_back( pRow
);
503 nCount
= aNewDocs
.size();
504 Sequence
< OUString
> aRet( nCount
);
505 OUString
* pRet
= aRet
.getArray();
506 for ( i
= 0; i
< nCount
; ++i
)
508 OUString
* pNewDoc
= aNewDocs
[i
];
509 pRet
[i
] = *( pNewDoc
);
516 void SvtFileViewWindow_Impl::Resize()
518 aFileView
.SetSizePixel(GetOutputSizePixel());
521 String
SvtFileViewWindow_Impl::GetSelectedFile() const
523 return aFileView
.GetCurrentURL();
526 void SvtFileViewWindow_Impl::OpenFolder( const String
& rURL
)
530 rParent
.SetPrevLevelButtonState( rURL
);
532 if ( INetURLObject( rURL
).GetProtocol() == INET_PROT_PRIVATE
)
534 aFileView
.EnableNameReplacing( sal_False
);
535 aFileView
.Initialize( GetNewDocContents() );
539 xub_StrLen nSampFoldLen
= aSamplesFolderURL
.Len();
540 aFileView
.EnableNameReplacing(
541 nSampFoldLen
&& rURL
.CompareTo( aSamplesFolderURL
, nSampFoldLen
) == COMPARE_EQUAL
);
542 aFileView
.Initialize( rURL
, String(), NULL
);
544 aNewFolderLink
.Call( this );
547 sal_Bool
SvtFileViewWindow_Impl::HasPreviousLevel( String
& rURL
) const
549 INetURLObject
aViewObj( aFileView
.GetViewURL() );
550 INetURLObject
aRootObj( aCurrentRootURL
);
551 INetURLObject
aMyDocObj( aMyDocumentsURL
);
553 return ( ( aViewObj
!= aRootObj
|| aRootObj
== aMyDocObj
) && aFileView
.GetParentURL( rURL
) );
556 String
SvtFileViewWindow_Impl::GetFolderTitle() const
559 ::utl::UCBContentHelper::GetTitle( aFolderURL
, &aTitle
);
563 void SvtFileViewWindow_Impl::SetFocus()
565 aFileView
.SetFocus();
568 // class SvtDocInfoTable_Impl --------------------------------------------
570 SvtDocInfoTable_Impl::SvtDocInfoTable_Impl() :
572 ResStringArray( SvtResId( STRARY_SVT_DOCINFO
) )
576 // -----------------------------------------------------------------------
578 OUString
SvtDocInfoTable_Impl::GetString( long nId
) const
580 sal_uInt32
nPos( FindIndex( nId
) );
582 if ( RESARRAY_INDEX_NOTFOUND
!= nPos
)
583 return ResStringArray::GetString( nPos
);
588 // class SvtFrameWindow_Impl ---------------------------------------------
590 SvtFrameWindow_Impl::SvtFrameWindow_Impl( Window
* pParent
)
593 // create windows and frame
594 pEditWin
= new ODocumentInfoPreview( this ,WB_LEFT
| WB_VSCROLL
| WB_READONLY
| WB_BORDER
| WB_3DLOOK
);
595 pTextWin
= new Window( this );
596 m_xFrame
= Frame::create( ::comphelper::getProcessComponentContext() );
597 xWindow
= VCLUnoHelper::GetInterface( pTextWin
);
598 m_xFrame
->initialize( xWindow
);
600 // create docinfo instance
601 m_xDocProps
.set( document::DocumentProperties::create(::comphelper::getProcessComponentContext()) );
603 pEmptyWin
= new Window( this, WB_BORDER
| WB_3DLOOK
);
606 SvtFrameWindow_Impl::~SvtFrameWindow_Impl()
613 void SvtFrameWindow_Impl::ViewEditWin()
616 xWindow
->setVisible( sal_False
);
621 void SvtFrameWindow_Impl::ViewTextWin()
625 xWindow
->setVisible( sal_True
);
629 void SvtFrameWindow_Impl::ViewEmptyWin()
631 xWindow
->setVisible( sal_False
);
637 void SvtFrameWindow_Impl::ViewNonEmptyWin()
645 void SvtFrameWindow_Impl::ShowDocInfo( const String
& rURL
)
649 uno::Reference
< task::XInteractionHandler2
> xInteractionHandler(
650 task::InteractionHandler::createWithParent(::comphelper::getProcessComponentContext(), 0) );
651 uno::Sequence
< beans::PropertyValue
> aProps(1);
652 aProps
[0].Name
= OUString( "InteractionHandler" );
653 aProps
[0].Value
<<= xInteractionHandler
;
654 m_xDocProps
->loadFromMedium( rURL
, aProps
);
655 pEditWin
->fill( m_xDocProps
, rURL
);
657 catch ( UnknownPropertyException
& ) {}
658 catch ( Exception
& ) {}
661 void SvtFrameWindow_Impl::Resize()
663 Size aWinSize
= GetOutputSizePixel();
664 pEditWin
->SetSizePixel( aWinSize
);
665 pTextWin
->SetSizePixel( aWinSize
);
666 pEmptyWin
->SetSizePixel( aWinSize
);
669 void SvtFrameWindow_Impl::OpenFile( const String
& rURL
, sal_Bool bPreview
, sal_Bool bIsTemplate
, sal_Bool bAsTemplate
)
677 if ( rURL
.Len() > 0 && bPreview
&& m_xDocProps
.is() )
680 if ( rURL
.Len() == 0 )
682 m_xFrame
->setComponent( Reference
< com::sun::star::awt::XWindow
>(), Reference
< XController
>() );
685 else if ( !::utl::UCBContentHelper::IsFolder( rURL
) )
687 com::sun::star::util::URL aURL
;
688 aURL
.Complete
= rURL
;
689 Reference
< com::sun::star::util::XURLTransformer
> xTrans(
690 com::sun::star::util::URLTransformer::create( ::comphelper::getProcessComponentContext() ) );
691 xTrans
->parseStrict( aURL
);
694 Reference
< XDispatchProvider
> xProv( m_xFrame
, UNO_QUERY_THROW
);
699 // can be removed if the database application change its URL
700 String
sServiceScheme( RTL_CONSTASCII_USTRINGPARAM( "service:" ) );
701 if ( rURL
.Match( sServiceScheme
) != sServiceScheme
.Len() )
702 // service URL has no default target
703 aTarget
= "_default";
704 xProv
= Reference
< XDispatchProvider
>( Desktop::create(::comphelper::getProcessComponentContext() ),
708 Reference
< XDispatch
> xDisp
= xProv
.is() ?
709 xProv
->queryDispatch( aURL
, aTarget
, 0 ) : Reference
< XDispatch
>();
715 if ( m_aOpenURL
!= aURL
.Complete
)
717 WaitObject
aWaitCursor( GetParent() );
718 // disabling must be done here, does not work in ctor because
719 // execute of the dialog will overwrite it
720 // ( own execute method would help )
721 pTextWin
->EnableInput( sal_False
, sal_True
);
722 if ( pTextWin
->IsReallyVisible() )
724 sal_Bool b
= sal_True
;
725 Sequence
< PropertyValue
> aArgs( 4 );
726 aArgs
[0].Name
= "Preview";
727 aArgs
[0].Value
.setValue( &b
, ::getBooleanCppuType() );
728 aArgs
[1].Name
= "ReadOnly";
729 aArgs
[1].Value
.setValue( &b
, ::getBooleanCppuType() );
730 aArgs
[2].Name
= "AsTemplate"; // prevents getting an empty URL with getURL()!
732 uno::Reference
< task::XInteractionHandler2
> xInteractionHandler(
733 task::InteractionHandler::createWithParent(::comphelper::getProcessComponentContext(), 0) );
734 aArgs
[3].Name
= OUString( "InteractionHandler" );
735 aArgs
[3].Value
<<= xInteractionHandler
;
738 aArgs
[2].Value
.setValue( &b
, ::getBooleanCppuType() );
739 xDisp
->dispatch( aURL
, aArgs
);
742 Reference
< ::com::sun::star::frame::XController
> xCtrl
= m_xFrame
->getController();
745 Reference
< ::com::sun::star::frame::XModel
> xMdl
= xCtrl
->getModel();
747 aDispURL
= xMdl
->getURL();
750 if( aDispURL
!= aURL
.Complete
)
752 m_xFrame
->setComponent( Reference
< com::sun::star::awt::XWindow
>(), Reference
< XController
>() );
754 m_aOpenURL
= OUString();
757 m_aOpenURL
= aDispURL
;
761 else if ( bIsTemplate
)
763 Sequence
< PropertyValue
> aArgs( 1 );
764 aArgs
[0].Name
= "AsTemplate";
765 aArgs
[0].Value
<<= bAsTemplate
;
766 xDisp
->dispatch( aURL
, aArgs
);
767 m_aOpenURL
= OUString();
771 Sequence
< PropertyValue
> aArgs
;
772 xDisp
->dispatch( aURL
, aArgs
);
773 m_aOpenURL
= OUString();
779 void SvtFrameWindow_Impl::ToggleView( sal_Bool bDI
)
783 // view is set properly in OpenFile()
785 OpenFile( aCurrentURL
, sal_True
, sal_False
, sal_False
);
788 // class SvtTemplateWindow -----------------------------------------------
790 SvtTemplateWindow::SvtTemplateWindow( Window
* pParent
) :
792 Window( pParent
, WB_DIALOGCONTROL
),
794 aFileViewTB ( this, SvtResId( TB_SVT_FILEVIEW
) ),
795 aFrameWinTB ( this, SvtResId( TB_SVT_FRAMEWIN
) ),
796 aSplitWin ( this, WB_DIALOGCONTROL
| WB_NOSPLITDRAW
),
797 pHistoryList ( NULL
)
801 pIconWin
= new SvtIconWindow_Impl( this );
802 pFileWin
= new SvtFileViewWindow_Impl( this );
803 pFileWin
->SetMyDocumentsURL( pIconWin
->GetMyDocumentsRootURL() );
804 pFileWin
->SetSamplesFolderURL( pIconWin
->GetSamplesFolderURL() );
805 pFrameWin
= new SvtFrameWindow_Impl( this );
808 pIconWin
->SetClickHdl( LINK( this, SvtTemplateWindow
, IconClickHdl_Impl
) );
809 pFileWin
->SetSelectHdl( LINK( this, SvtTemplateWindow
, FileSelectHdl_Impl
) );
810 pFileWin
->SetDoubleClickHdl( LINK( this, SvtTemplateWindow
, FileDblClickHdl_Impl
) );
811 pFileWin
->SetNewFolderHdl( LINK( this, SvtTemplateWindow
, NewFolderHdl_Impl
) );
813 // create the split items
814 aSplitWin
.SetAlign( WINDOWALIGN_LEFT
);
815 long nWidth
= pIconWin
->GetMaxTextLength() * 8 / 7 + 1; // extra space for border
816 aSplitWin
.InsertItem( ICONWIN_ID
, pIconWin
, nWidth
, SPLITWINDOW_APPEND
, 0, SWIB_FIXED
);
817 aSplitWin
.InsertItem( FILEWIN_ID
, pFileWin
, 50, SPLITWINDOW_APPEND
, 0, SWIB_PERCENTSIZE
);
818 aSplitWin
.InsertItem( FRAMEWIN_ID
, pFrameWin
, 50, SPLITWINDOW_APPEND
, 0, SWIB_PERCENTSIZE
);
819 aSplitWin
.SetSplitHdl( LINK( this, SvtTemplateWindow
, ResizeHdl_Impl
) );
827 // initialize the timers
828 aSelectTimer
.SetTimeout( 200 );
829 aSelectTimer
.SetTimeoutHdl( LINK( this, SvtTemplateWindow
, TimeoutHdl_Impl
) );
831 // initialize the toolboxes and then show them
838 Application::PostUserEvent( LINK( this, SvtTemplateWindow
, ResizeHdl_Impl
) );
841 // ------------------------------------------------------------------------
843 SvtTemplateWindow::~SvtTemplateWindow()
845 WriteViewSettings( );
852 for ( size_t i
= 0, n
= pHistoryList
->size(); i
< n
; ++i
)
853 delete (*pHistoryList
)[ i
];
854 pHistoryList
->clear();
859 // ------------------------------------------------------------------------
861 IMPL_LINK_NOARG(SvtTemplateWindow
, IconClickHdl_Impl
)
863 String aURL
= pIconWin
->GetSelectedIconURL();
865 aURL
= pIconWin
->GetCursorPosIconURL();
866 if ( pFileWin
->GetRootURL() != aURL
)
868 pFileWin
->OpenRoot( aURL
);
869 pIconWin
->InvalidateIconControl();
870 aFileViewTB
.EnableItem( TI_DOCTEMPLATE_PRINT
, sal_False
);
875 // ------------------------------------------------------------------------
877 IMPL_LINK_NOARG(SvtTemplateWindow
, FileSelectHdl_Impl
)
879 aSelectTimer
.Start();
883 // ------------------------------------------------------------------------
885 IMPL_LINK_NOARG(SvtTemplateWindow
, FileDblClickHdl_Impl
)
887 if ( aSelectTimer
.IsActive() )
890 String aURL
= pFileWin
->GetSelectedFile();
891 if ( aURL
.Len() > 0 )
893 if ( ::utl::UCBContentHelper::IsFolder( aURL
) )
894 pFileWin
->OpenFolder( aURL
);
896 aDoubleClickHdl
.Call( this );
902 // ------------------------------------------------------------------------
904 IMPL_LINK_NOARG(SvtTemplateWindow
, NewFolderHdl_Impl
)
906 pFrameWin
->OpenFile( String(), sal_True
, sal_False
, sal_False
);
907 aFileViewTB
.EnableItem( TI_DOCTEMPLATE_PRINT
, sal_False
);
909 String sURL
= pFileWin
->GetFolderURL();
910 sal_uLong nPos
= pIconWin
->GetRootPos( sURL
);
911 AppendHistoryURL( sURL
, nPos
);
913 aNewFolderHdl
.Call( this );
917 // ------------------------------------------------------------------------
919 IMPL_LINK_NOARG(SvtTemplateWindow
, TimeoutHdl_Impl
)
921 aSelectHdl
.Call( this );
922 String sURL
= pFileWin
->GetSelectedFile();
923 sal_Bool bIsNewDoc
= ( pIconWin
->GetSelectEntryPos() == ICON_POS_NEWDOC
);
924 sal_Bool bIsFile
= ( sURL
.Len() != 0 && !::utl::UCBContentHelper::IsFolder( sURL
) &&
925 INetURLObject( sURL
).GetProtocol() != INET_PROT_PRIVATE
&& !bIsNewDoc
);
926 aFileViewTB
.EnableItem( TI_DOCTEMPLATE_PRINT
, bIsFile
);
927 aFrameWinTB
.EnableItem( TI_DOCTEMPLATE_PREVIEW
, !bIsNewDoc
);
930 pFrameWin
->OpenFile( sURL
, sal_True
, sal_False
, sal_False
);
931 else if ( bIsNewDoc
&& aFrameWinTB
.IsItemChecked( TI_DOCTEMPLATE_PREVIEW
) )
933 aFrameWinTB
.CheckItem( TI_DOCTEMPLATE_DOCINFO
);
934 DoAction( TI_DOCTEMPLATE_DOCINFO
);
939 // ------------------------------------------------------------------------
941 IMPL_LINK ( SvtTemplateWindow
, ClickHdl_Impl
, ToolBox
*, pToolBox
)
943 DoAction( pToolBox
->GetCurItemId() );
947 // ------------------------------------------------------------------------
949 IMPL_LINK_NOARG(SvtTemplateWindow
, ResizeHdl_Impl
)
955 // ------------------------------------------------------------------------
957 void SvtTemplateWindow::PrintFile( const String
& rURL
)
959 // open the file readonly and hidden
960 Sequence
< PropertyValue
> aArgs( 2 );
961 aArgs
[0].Name
= "ReadOnly";
962 aArgs
[0].Value
<<= sal_True
;
963 aArgs
[1].Name
= "Hidden";
964 aArgs
[1].Value
<<= sal_True
;
966 Reference
< XDesktop2
> xDesktop
= Desktop::create( ::comphelper::getProcessComponentContext() );
967 Reference
< XModel
> xModel( xDesktop
->loadComponentFromURL(
968 rURL
, "_blank", 0, aArgs
), UNO_QUERY
);
972 Reference
< XPrintable
> xPrintable( xModel
, UNO_QUERY
);
973 if ( xPrintable
.is() )
974 xPrintable
->print( Sequence
< PropertyValue
>() );
978 // ------------------------------------------------------------------------
980 void SvtTemplateWindow::AppendHistoryURL( const String
& rURL
, sal_uLong nGroup
)
982 sal_Bool bInsert
= sal_True
;
984 pHistoryList
= new HistoryList_Impl
;
985 else if ( pHistoryList
->size() > 0 )
987 FolderHistory
* pLastEntry
= pHistoryList
->back();
988 bInsert
= ( rURL
!= pLastEntry
->m_sURL
);
993 FolderHistory
* pEntry
= new FolderHistory( rURL
, nGroup
);
994 pHistoryList
->push_back( pEntry
);
995 aFileViewTB
.EnableItem( TI_DOCTEMPLATE_BACK
, pHistoryList
->size() > 1 );
999 // ------------------------------------------------------------------------
1001 void SvtTemplateWindow::OpenHistory()
1003 delete pHistoryList
->back();
1004 pHistoryList
->pop_back();
1005 FolderHistory
* pEntry
= pHistoryList
->back();
1006 pHistoryList
->pop_back();
1007 aFileViewTB
.EnableItem( TI_DOCTEMPLATE_BACK
, pHistoryList
->size() > 1 );
1008 pFileWin
->OpenFolder( pEntry
->m_sURL
);
1009 pIconWin
->SetCursorPos( pEntry
->m_nGroup
);
1013 // ------------------------------------------------------------------------
1015 void SvtTemplateWindow::DoAction( sal_uInt16 nAction
)
1019 case TI_DOCTEMPLATE_BACK
:
1021 if ( pHistoryList
&& pHistoryList
->size() > 1 )
1026 case TI_DOCTEMPLATE_PREV
:
1029 if ( pFileWin
->HasPreviousLevel( aURL
) )
1030 pFileWin
->OpenFolder( aURL
);
1034 case TI_DOCTEMPLATE_PRINT
:
1036 String
sPrintFile( pFileWin
->GetSelectedFile() );
1037 if ( sPrintFile
.Len() > 0 )
1038 PrintFile( sPrintFile
);
1042 case TI_DOCTEMPLATE_DOCINFO
:
1043 case TI_DOCTEMPLATE_PREVIEW
:
1045 pFrameWin
->ToggleView( TI_DOCTEMPLATE_DOCINFO
== nAction
);
1051 // ------------------------------------------------------------------------
1053 void SvtTemplateWindow::InitToolBoxes()
1055 InitToolBoxImages();
1057 Size aSize
= aFileViewTB
.CalcWindowSizePixel();
1058 aSize
.Height() += 4;
1059 aFileViewTB
.SetPosSizePixel( Point( 0, 2 ), aSize
);
1060 aSize
= aFrameWinTB
.CalcWindowSizePixel();
1061 aSize
.Height() += 4;
1062 aFrameWinTB
.SetPosSizePixel( Point( pFrameWin
->GetPosPixel().X() + 2, 2 ), aSize
);
1064 sal_Bool bFlat
= ( SvtMiscOptions().GetToolboxStyle() == TOOLBOX_STYLE_FLAT
);
1067 aFileViewTB
.SetOutStyle( TOOLBOX_STYLE_FLAT
);
1068 aFrameWinTB
.SetOutStyle( TOOLBOX_STYLE_FLAT
);
1071 aFileViewTB
.EnableItem( TI_DOCTEMPLATE_BACK
, sal_False
);
1072 aFileViewTB
.EnableItem( TI_DOCTEMPLATE_PREV
, sal_False
);
1073 aFileViewTB
.EnableItem( TI_DOCTEMPLATE_PRINT
, sal_False
);
1075 Link aLink
= LINK( this, SvtTemplateWindow
, ClickHdl_Impl
);
1076 aFileViewTB
.SetClickHdl( aLink
);
1077 aFrameWinTB
.SetClickHdl( aLink
);
1080 // ------------------------------------------------------------------------
1082 void SvtTemplateWindow::InitToolBoxImages()
1084 SvtMiscOptions aMiscOpt
;
1085 sal_Bool bLarge
= aMiscOpt
.AreCurrentSymbolsLarge();
1087 aFileViewTB
.SetItemImage( TI_DOCTEMPLATE_BACK
, Image( SvtResId(
1088 bLarge
? IMG_SVT_DOCTEMPLATE_BACK_LARGE
1089 : IMG_SVT_DOCTEMPLATE_BACK_SMALL
) ) );
1090 aFileViewTB
.SetItemImage( TI_DOCTEMPLATE_PREV
, Image( SvtResId(
1091 bLarge
? IMG_SVT_DOCTEMPLATE_PREV_LARGE
1092 : IMG_SVT_DOCTEMPLATE_PREV_SMALL
) ) );
1093 aFileViewTB
.SetItemImage( TI_DOCTEMPLATE_PRINT
, Image( SvtResId(
1094 bLarge
? IMG_SVT_DOCTEMPLATE_PRINT_LARGE
1095 : IMG_SVT_DOCTEMPLATE_PRINT_SMALL
) ) );
1097 aFrameWinTB
.SetItemImage( TI_DOCTEMPLATE_DOCINFO
, Image( SvtResId(
1098 bLarge
? IMG_SVT_DOCTEMPLATE_DOCINFO_LARGE
1099 : IMG_SVT_DOCTEMPLATE_DOCINFO_SMALL
) ) );
1100 aFrameWinTB
.SetItemImage( TI_DOCTEMPLATE_PREVIEW
, Image( SvtResId(
1101 bLarge
? IMG_SVT_DOCTEMPLATE_PREVIEW_LARGE
1102 : IMG_SVT_DOCTEMPLATE_PREVIEW_SMALL
) ) );
1105 // ------------------------------------------------------------------------
1107 void SvtTemplateWindow::UpdateIcons()
1109 pIconWin
->UpdateIcons();
1112 // ------------------------------------------------------------------------
1114 long SvtTemplateWindow::PreNotify( NotifyEvent
& rNEvt
)
1116 sal_uInt16 nType
= rNEvt
.GetType();
1119 if ( EVENT_KEYINPUT
== nType
&& rNEvt
.GetKeyEvent() )
1121 const KeyCode
& rKeyCode
= rNEvt
.GetKeyEvent()->GetKeyCode();
1122 sal_uInt16 nCode
= rKeyCode
.GetCode();
1124 if ( KEY_BACKSPACE
== nCode
&& !rKeyCode
.GetModifier() && pFileWin
->HasChildPathFocus() )
1126 DoAction( TI_DOCTEMPLATE_BACK
);
1129 else if ( pIconWin
->ProcessKeyEvent( *rNEvt
.GetKeyEvent() ) )
1135 return nRet
? nRet
: Window::PreNotify( rNEvt
);
1138 // -----------------------------------------------------------------------------
1140 void SvtTemplateWindow::DataChanged( const DataChangedEvent
& rDCEvt
)
1142 Window::DataChanged( rDCEvt
);
1144 if ( ( ( rDCEvt
.GetType() == DATACHANGED_SETTINGS
) ||
1145 ( rDCEvt
.GetType() == DATACHANGED_DISPLAY
) ) &&
1146 ( rDCEvt
.GetFlags() & SETTINGS_STYLE
) )
1148 // update of the background for the area left of the FileView toolbox
1149 SetBackground( Wallpaper( GetSettings().GetStyleSettings().GetFaceColor() ) );
1150 // update of the images of the IconChoiceControl
1152 // update of the toolbox images
1153 InitToolBoxImages();
1156 // ------------------------------------------------------------------------
1158 void SvtTemplateWindow::Resize()
1160 long nItemSize
= aSplitWin
.GetItemSize( ICONWIN_ID
);
1161 long nSplitterWidth
= Splitter( this, 0 ).GetSizePixel().Width();
1163 Point aPos
= aFileViewTB
.GetPosPixel();
1164 aPos
.X() = nItemSize
+ nSplitterWidth
/ 2;
1165 aFileViewTB
.SetPosPixel( aPos
);
1167 Size aWinSize
= GetOutputSizePixel();
1168 long nWidth
= aWinSize
.Width() - aPos
.X();
1170 nItemSize
= nWidth
* aSplitWin
.GetItemSize( FILEWIN_ID
) / 100;
1171 aPos
.X() = pFrameWin
->GetPosPixel().X() + 2;
1172 aFrameWinTB
.SetPosPixel( aPos
);
1174 Size aSize
= aFileViewTB
.GetSizePixel();
1175 aSize
.Width() = nItemSize
;
1176 aFileViewTB
.SetSizePixel( aSize
);
1178 aSize
= aFrameWinTB
.GetSizePixel();
1179 aSize
.Width() = nWidth
- nItemSize
;
1180 aFrameWinTB
.SetSizePixel( aSize
);
1182 long nToolBoxHeight
= aSize
.Height() + aFrameWinTB
.GetPosPixel().Y();
1184 aSize
.Height() -= nToolBoxHeight
;
1185 aSplitWin
.SetPosSizePixel( Point( 0, nToolBoxHeight
), aSize
);
1188 // ------------------------------------------------------------------------
1190 String
SvtTemplateWindow::GetSelectedFile() const
1192 return pFileWin
->GetSelectedFile();
1195 // ------------------------------------------------------------------------
1197 sal_Bool
SvtTemplateWindow::IsFileSelected() const
1199 String aURL
= pFileWin
->GetSelectedFile();
1200 sal_Bool bRet
= ( aURL
.Len() > 0 && !::utl::UCBContentHelper::IsFolder( aURL
) );
1204 // ------------------------------------------------------------------------
1206 void SvtTemplateWindow::OpenFile( sal_Bool bNotAsTemplate
)
1208 String aURL
= pFileWin
->GetSelectedFile();
1209 if ( aURL
.Len() > 0 && !::utl::UCBContentHelper::IsFolder( aURL
) )
1210 pFrameWin
->OpenFile( aURL
, sal_False
, pFileWin
->IsTemplateFolder(), !bNotAsTemplate
);
1213 // ------------------------------------------------------------------------
1215 String
SvtTemplateWindow::GetFolderTitle() const
1218 String sFolderURL
= pFileWin
->GetFolderURL();
1219 if ( pIconWin
->IsRootURL( sFolderURL
) )
1220 sTitle
= pIconWin
->GetIconText( sFolderURL
);
1222 sTitle
= pFileWin
->GetFolderTitle();
1226 // ------------------------------------------------------------------------
1228 String
SvtTemplateWindow::GetFolderURL() const
1230 return pFileWin
->GetFolderURL();
1234 // ------------------------------------------------------------------------
1236 void SvtTemplateWindow::SetFocus( sal_Bool bIconWin
)
1239 pIconWin
->SetFocus();
1241 pFileWin
->SetFocus();
1244 // ------------------------------------------------------------------------
1246 void SvtTemplateWindow::OpenTemplateRoot()
1248 pFileWin
->OpenFolder( pIconWin
->GetTemplateRootURL() );
1251 // ------------------------------------------------------------------------
1253 void SvtTemplateWindow::SetPrevLevelButtonState( const String
& rURL
)
1255 // disable the prev level button on root folder of the icon pane (except My Documents)
1256 // and on the root of all (file:/// -> count == 0)
1257 INetURLObject
aObj( rURL
);
1258 sal_Int32 nCount
= aObj
.getSegmentCount();
1261 ( !pIconWin
->IsRootURL( rURL
) || rURL
== pIconWin
->GetMyDocumentsRootURL() ) );
1262 aFileViewTB
.EnableItem( TI_DOCTEMPLATE_PREV
, bEnable
);
1265 // ------------------------------------------------------------------------
1267 void SvtTemplateWindow::ClearHistory()
1271 for ( size_t i
= 0, n
= pHistoryList
->size(); i
< n
; ++i
)
1272 delete (*pHistoryList
)[ i
];
1273 pHistoryList
->clear();
1277 // ------------------------------------------------------------------------
1279 long SvtTemplateWindow::CalcHeight() const
1282 long nHeight
= aFileViewTB
.GetSizePixel().Height();
1284 nHeight
+= pIconWin
->CalcHeight();
1290 // ------------------------------------------------------------------------
1292 void SvtTemplateWindow::ReadViewSettings()
1295 sal_Int32 nSelectedGroup
= ICON_POS_TEMPLATES
;
1296 sal_Int32 nSelectedView
= TI_DOCTEMPLATE_DOCINFO
;
1297 double nSplitRatio
= 0.5;
1298 OUString sLastFolder
;
1300 SvtViewOptions
aViewSettings( E_DIALOG
, VIEWSETTING_NEWFROMTEMPLATE
);
1301 if ( aViewSettings
.Exists() )
1303 // read the settings
1304 Sequence
< NamedValue
> aSettings
= aViewSettings
.GetUserData( );
1306 aViewSettings
.GetUserItem( VIEWSETTING_SELECTEDGROUP
) >>= nSelectedGroup
;
1307 aViewSettings
.GetUserItem( VIEWSETTING_SELECTEDVIEW
) >>= nSelectedView
;
1308 aViewSettings
.GetUserItem( VIEWSETTING_SPLITRATIO
) >>= nSplitRatio
;
1309 aViewSettings
.GetUserItem( VIEWSETTING_LASTFOLDER
) >>= sLastFolder
;
1312 if ( nSelectedGroup
< ICON_POS_NEWDOC
) nSelectedGroup
= ICON_POS_NEWDOC
;
1313 if ( nSelectedGroup
> ICON_POS_SAMPLES
) nSelectedGroup
= ICON_POS_SAMPLES
;
1315 if ( ( TI_DOCTEMPLATE_DOCINFO
!= nSelectedView
) && ( TI_DOCTEMPLATE_PREVIEW
!= nSelectedView
) )
1316 nSelectedView
= TI_DOCTEMPLATE_DOCINFO
;
1318 if ( nSplitRatio
< 0.2 ) nSplitRatio
= 0.2;
1319 if ( nSplitRatio
> 0.8 ) nSplitRatio
= 0.8;
1321 // change our view according to the settings
1323 // the selected view (details or preview)
1324 pFrameWin
->ToggleView( TI_DOCTEMPLATE_DOCINFO
== nSelectedView
);
1325 aFrameWinTB
.CheckItem( (sal_uInt16
)nSelectedView
, sal_True
);
1328 sal_Int32 nSplitFileAndFrameSize
= aSplitWin
.GetItemSize( FILEWIN_ID
) + aSplitWin
.GetItemSize( FRAMEWIN_ID
);
1329 sal_Int32 nSplitFileSize
= (sal_Int32
)(nSplitFileAndFrameSize
* nSplitRatio
);
1330 sal_Int32 nSplitFrameSize
= nSplitFileAndFrameSize
- nSplitFileSize
;
1331 aSplitWin
.SetItemSize( FILEWIN_ID
, nSplitFileSize
);
1332 aSplitWin
.SetItemSize( FRAMEWIN_ID
, nSplitFrameSize
);
1335 // the selected folder
1336 pIconWin
->SetCursorPos( nSelectedGroup
);
1338 // open the last folder or the selected group
1339 if ( !sLastFolder
.isEmpty() )
1340 pFileWin
->OpenFolder( sLastFolder
);
1342 IconClickHdl_Impl( NULL
);
1345 // ------------------------------------------------------------------------
1347 void SvtTemplateWindow::WriteViewSettings()
1350 Sequence
< NamedValue
> aSettings(4);
1352 // the selected group
1353 aSettings
[0].Name
= VIEWSETTING_SELECTEDGROUP
;
1354 pIconWin
->SetFocus();
1355 aSettings
[0].Value
<<= (sal_Int32
)pIconWin
->GetCursorPos( );
1357 // the selected view mode
1358 aSettings
[1].Name
= VIEWSETTING_SELECTEDVIEW
;
1359 aSettings
[1].Value
<<= sal_Int32( aFrameWinTB
.IsItemChecked( TI_DOCTEMPLATE_DOCINFO
) ? TI_DOCTEMPLATE_DOCINFO
: TI_DOCTEMPLATE_PREVIEW
);
1362 aSettings
[2].Name
= VIEWSETTING_SPLITRATIO
;
1363 sal_Int32 nSplitFileSize
= aSplitWin
.GetItemSize( FILEWIN_ID
);
1364 sal_Int32 nSplitFileAndFrameSize
= nSplitFileSize
+ aSplitWin
.GetItemSize( FRAMEWIN_ID
);
1365 aSettings
[2].Value
<<= double( 1.0 * nSplitFileSize
/ nSplitFileAndFrameSize
);
1368 aSettings
[3].Name
= VIEWSETTING_LASTFOLDER
;
1369 aSettings
[3].Value
<<= OUString( pFileWin
->GetFolderURL() );
1372 SvtViewOptions
aViewSettings( E_DIALOG
, VIEWSETTING_NEWFROMTEMPLATE
);
1373 aViewSettings
.SetUserData( aSettings
);
1376 void SvtTemplateWindow::SelectFolder(sal_Int32 nFolderPosition
)
1378 pIconWin
->SelectFolder(nFolderPosition
);
1381 struct SvtTmplDlg_Impl
1383 SvtTemplateWindow
* pWin
;
1386 sal_Bool bSelectNoOpen
;
1388 uno::Reference
< util::XOfficeInstallationDirectories
> m_xOfficeInstDirs
;
1391 SvtTmplDlg_Impl( Window
* pParent
) : pWin( new SvtTemplateWindow( pParent
) ) ,bSelectNoOpen( sal_False
) {}
1393 ~SvtTmplDlg_Impl() { delete pWin
; }
1396 SvtDocumentTemplateDialog::SvtDocumentTemplateDialog( Window
* pParent
) :
1398 ModalDialog( pParent
, SvtResId( DLG_DOCTEMPLATE
) ),
1400 aMoreTemplatesLink ( this, SvtResId( FT_DOCTEMPLATE_LINK
) ),
1401 aLine ( this, SvtResId( FL_DOCTEMPLATE
) ),
1402 aManageBtn ( this, SvtResId( BTN_DOCTEMPLATE_MANAGE
) ),
1403 aPackageBtn ( this, SvtResId( BTN_DOCTEMPLATE_PACKAGE
) ),
1404 aEditBtn ( this, SvtResId( BTN_DOCTEMPLATE_EDIT
) ),
1405 aOKBtn ( this, SvtResId( BTN_DOCTEMPLATE_OPEN
) ),
1406 aCancelBtn ( this, SvtResId( BTN_DOCTEMPLATE_CANCEL
) ),
1407 aHelpBtn ( this, SvtResId( BTN_DOCTEMPLATE_HELP
) ),
1414 // ------------------------------------------------------------------------
1416 void SvtDocumentTemplateDialog::InitImpl( )
1418 pImpl
= new SvtTmplDlg_Impl( this );
1419 pImpl
->aTitle
= GetText();
1421 bool bHideLink
= ( SvtExtendedSecurityOptions().GetOpenHyperlinkMode()
1422 == SvtExtendedSecurityOptions::OPEN_NEVER
);
1425 aMoreTemplatesLink
.SetURL( String(
1426 RTL_CONSTASCII_USTRINGPARAM( "http://templates.libreoffice.org/" ) ) );
1427 aMoreTemplatesLink
.SetClickHdl( LINK( this, SvtDocumentTemplateDialog
, OpenLinkHdl_Impl
) );
1430 aMoreTemplatesLink
.Hide();
1432 aManageBtn
.SetClickHdl( LINK( this, SvtDocumentTemplateDialog
, OrganizerHdl_Impl
) );
1433 // Only enable the Package Button, if the service is available
1436 using namespace org::freedesktop::PackageKit
;
1437 Reference
< XSyncDbusSessionHelper
> xSyncDbusSessionHelper(SyncDbusSessionHelper::create(comphelper::getProcessComponentContext()), UNO_QUERY
);
1438 aPackageBtn
.SetClickHdl( LINK( this, SvtDocumentTemplateDialog
, PackageHdl_Impl
) );
1439 aPackageBtn
.Enable(xSyncDbusSessionHelper
.is());
1441 catch (Exception
& e
)
1445 "disable Install Template Pack, caught " << e
.Message
);
1446 aPackageBtn
.Enable(false);
1448 Link aLink
= LINK( this, SvtDocumentTemplateDialog
, OKHdl_Impl
);
1449 aEditBtn
.SetClickHdl( aLink
);
1450 aOKBtn
.SetClickHdl( aLink
);
1452 pImpl
->pWin
->SetSelectHdl( LINK( this, SvtDocumentTemplateDialog
, SelectHdl_Impl
) );
1453 pImpl
->pWin
->SetDoubleClickHdl( LINK( this, SvtDocumentTemplateDialog
, DoubleClickHdl_Impl
) );
1454 pImpl
->pWin
->SetNewFolderHdl( LINK( this, SvtDocumentTemplateDialog
, NewFolderHdl_Impl
) );
1455 pImpl
->pWin
->SetSendFocusHdl( LINK( this, SvtDocumentTemplateDialog
, SendFocusHdl_Impl
) );
1457 // dynamic height adjustment
1458 long nHeight
= pImpl
->pWin
->CalcHeight();
1460 Size aSize
= GetOutputSizePixel();
1461 Point aPos
= aMoreTemplatesLink
.GetPosPixel();
1462 Size a6Size
= LogicToPixel( Size( 6, 6 ), MAP_APPFONT
);
1464 aPos
.Y() += aMoreTemplatesLink
.GetSizePixel().Height();
1466 aPos
.Y() -= a6Size
.Height();
1467 long nDelta
= aPos
.Y() - nHeight
;
1468 aSize
.Height() -= nDelta
;
1469 SetOutputSizePixel( aSize
);
1471 aSize
.Height() = nHeight
;
1472 aSize
.Width() -= ( a6Size
.Width() * 2 );
1473 pImpl
->pWin
->SetPosSizePixel( Point( a6Size
.Width(), 0 ), aSize
);
1475 aPos
= aMoreTemplatesLink
.GetPosPixel();
1477 aMoreTemplatesLink
.SetPosPixel( aPos
);
1478 aPos
= aLine
.GetPosPixel();
1480 aLine
.SetPosPixel( aPos
);
1481 aPos
= aManageBtn
.GetPosPixel();
1483 aManageBtn
.SetPosPixel( aPos
);
1484 aPos
= aEditBtn
.GetPosPixel();
1486 aEditBtn
.SetPosPixel( aPos
);
1487 aPos
= aOKBtn
.GetPosPixel();
1489 aOKBtn
.SetPosPixel( aPos
);
1490 aPos
= aCancelBtn
.GetPosPixel();
1492 aCancelBtn
.SetPosPixel( aPos
);
1493 aPos
= aHelpBtn
.GetPosPixel();
1495 aHelpBtn
.SetPosPixel( aPos
);
1496 aPos
= aPackageBtn
.GetPosPixel();
1498 aPackageBtn
.SetPosPixel( aPos
);
1500 pImpl
->pWin
->Show();
1502 SelectHdl_Impl( NULL
);
1503 NewFolderHdl_Impl( NULL
);
1505 UpdateHdl_Impl( NULL
);
1508 // ------------------------------------------------------------------------
1510 SvtDocumentTemplateDialog::~SvtDocumentTemplateDialog()
1515 // ------------------------------------------------------------------------
1517 sal_Bool
SvtDocumentTemplateDialog::CanEnableEditBtn() const
1519 sal_Bool bEnable
= sal_False
;
1521 OUString aFolderURL
= pImpl
->pWin
->GetFolderURL();
1522 if ( pImpl
->pWin
->IsFileSelected() && !aFolderURL
.isEmpty() )
1524 OUString aFileTargetURL
= pImpl
->pWin
->GetSelectedFile();
1525 bEnable
= !aFileTargetURL
.isEmpty();
1531 // ------------------------------------------------------------------------
1533 IMPL_LINK_NOARG(SvtDocumentTemplateDialog
, SelectHdl_Impl
)
1535 aEditBtn
.Enable( pImpl
->pWin
->IsTemplateFolderOpen() && CanEnableEditBtn() );
1536 aOKBtn
.Enable( pImpl
->pWin
->IsFileSelected() );
1540 // ------------------------------------------------------------------------
1542 IMPL_LINK_NOARG(SvtDocumentTemplateDialog
, DoubleClickHdl_Impl
)
1544 EndDialog( RET_OK
);
1546 if ( !pImpl
->bSelectNoOpen
)
1547 pImpl
->pWin
->OpenFile( !pImpl
->pWin
->IsTemplateFolderOpen() );
1551 // ------------------------------------------------------------------------
1553 IMPL_LINK_NOARG(SvtDocumentTemplateDialog
, NewFolderHdl_Impl
)
1555 String
aNewTitle( pImpl
->aTitle
);
1556 aNewTitle
+= String( " - " );
1557 aNewTitle
+= pImpl
->pWin
->GetFolderTitle();
1558 SetText( aNewTitle
);
1560 SelectHdl_Impl( NULL
);
1564 // ------------------------------------------------------------------------
1566 IMPL_LINK_NOARG(SvtDocumentTemplateDialog
, SendFocusHdl_Impl
)
1568 if ( pImpl
->pWin
->HasIconWinFocus() )
1569 aHelpBtn
.GrabFocus();
1572 if ( aEditBtn
.IsEnabled() )
1573 aEditBtn
.GrabFocus();
1574 else if ( aOKBtn
.IsEnabled() )
1577 aCancelBtn
.GrabFocus();
1583 // ------------------------------------------------------------------------
1585 IMPL_LINK ( SvtDocumentTemplateDialog
, OKHdl_Impl
, PushButton
*, pBtn
)
1587 if ( pImpl
->pWin
->IsFileSelected() )
1589 EndDialog( RET_OK
);
1591 if ( !pImpl
->bSelectNoOpen
)
1592 pImpl
->pWin
->OpenFile( &aEditBtn
== pBtn
);
1597 // ------------------------------------------------------------------------
1599 IMPL_LINK_NOARG(SvtDocumentTemplateDialog
, OrganizerHdl_Impl
)
1601 Window
* pOldDefWin
= Application::GetDefDialogParent();
1602 Application::SetDefDialogParent( this );
1603 Reference
< XDesktop2
> xDesktop
= Desktop::create( ::comphelper::getProcessComponentContext() );
1604 Reference
< XFrame
> xFrame( xDesktop
->getActiveFrame() );
1606 xFrame
= Reference
< XFrame
>( xDesktop
, UNO_QUERY
);
1608 com::sun::star::util::URL aTargetURL
;
1609 aTargetURL
.Complete
= "slot:5540";
1610 Reference
< com::sun::star::util::XURLTransformer
> xTrans(
1611 com::sun::star::util::URLTransformer::create( ::comphelper::getProcessComponentContext() ) );
1612 xTrans
->parseStrict( aTargetURL
);
1614 Reference
< XDispatchProvider
> xProv( xFrame
, UNO_QUERY
);
1615 Reference
< XDispatch
> xDisp
;
1616 xDisp
= xProv
->queryDispatch( aTargetURL
, OUString(), 0 );
1620 Sequence
<PropertyValue
> aArgs(1);
1621 PropertyValue
* pArg
= aArgs
.getArray();
1622 pArg
[0].Name
= "Referer";
1623 pArg
[0].Value
<<= OUString("private:user");
1624 xDisp
->dispatch( aTargetURL
, aArgs
);
1627 Application::SetDefDialogParent( pOldDefWin
);
1632 IMPL_LINK_NOARG(SvtDocumentTemplateDialog
, PackageHdl_Impl
)
1636 using namespace org::freedesktop::PackageKit
;
1637 Reference
< XSyncDbusSessionHelper
> xSyncDbusSessionHelper(SyncDbusSessionHelper::create(comphelper::getProcessComponentContext()), UNO_QUERY
);
1638 Sequence
< OUString
> vPackages(1);
1639 vPackages
[0] = "libreoffice-templates";
1640 OUString
sInteraction("");
1641 xSyncDbusSessionHelper
->InstallPackageNames(0, vPackages
, sInteraction
);
1643 catch (Exception
& e
)
1647 "trying Install Template Pack, caught " << e
.Message
);
1652 // ------------------------------------------------------------------------
1654 IMPL_LINK ( SvtDocumentTemplateDialog
, UpdateHdl_Impl
, Timer
*, _pEventSource
)
1656 pImpl
->pWin
->SetFocus( sal_False
);
1657 Reference
< XDocumentTemplates
> xTemplates( frame::DocumentTemplates::create(::comphelper::getProcessComponentContext()) );
1658 if ( _pEventSource
)
1659 { // it was no direct call, which means it was triggered by the timer, which means we alread checked the necessity
1660 WaitObject
aWaitCursor( this );
1661 xTemplates
->update();
1662 if ( pImpl
->pWin
->IsTemplateFolderOpen() )
1664 pImpl
->pWin
->ClearHistory();
1665 pImpl
->pWin
->OpenTemplateRoot();
1670 // check if we really need to do the update
1671 ::svt::TemplateFolderCache aCache
;
1672 if ( aCache
.needsUpdate() )
1673 { // yes -> do it asynchronous (it will take a noticeable time)
1675 // (but first store the current state)
1676 aCache
.storeState();
1678 // start the timer for the async update
1679 pImpl
->aUpdateTimer
.SetTimeout( 300 );
1680 pImpl
->aUpdateTimer
.SetTimeoutHdl( LINK( this, SvtDocumentTemplateDialog
, UpdateHdl_Impl
) );
1681 pImpl
->aUpdateTimer
.Start();
1687 // ------------------------------------------------------------------------
1689 IMPL_LINK_NOARG(SvtDocumentTemplateDialog
, OpenLinkHdl_Impl
)
1691 OUString
sURL( aMoreTemplatesLink
.GetURL() );
1692 if ( !sURL
.isEmpty() )
1694 localizeWebserviceURI(sURL
);
1697 uno::Reference
< uno::XComponentContext
> xContext
=
1698 ::comphelper::getProcessComponentContext();
1699 uno::Reference
< com::sun::star::system::XSystemShellExecute
> xSystemShell(
1700 com::sun::star::system::SystemShellExecute::create(xContext
) );
1701 if ( xSystemShell
.is() )
1702 xSystemShell
->execute( sURL
, OUString(), com::sun::star::system::SystemShellExecuteFlags::URIS_ONLY
);
1703 EndDialog( RET_CANCEL
);
1705 catch( const uno::Exception
& e
)
1707 OSL_TRACE( "Caught exception: %s\n thread terminated.\n",
1708 OUStringToOString(e
.Message
, RTL_TEXTENCODING_UTF8
).getStr());
1714 void SvtDocumentTemplateDialog::SelectTemplateFolder()
1716 pImpl
->pWin
->SelectFolder(ICON_POS_TEMPLATES
);
1719 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */