LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/svtools/source/contnr - templwin.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 1 877 0.1 %
Date: 2013-07-09 Functions: 2 117 1.7 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       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/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      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 .
      18             :  */
      19             : 
      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>
      79             : 
      80             : #include <ucbhelper/content.hxx>
      81             : #include <comphelper/string.hxx>
      82             : 
      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;
      93             : 
      94             : #define aSeparatorStr   "----------------------------------"
      95             : 
      96             : #define ICONWIN_ID          2
      97             : #define FILEWIN_ID          3
      98             : #define FRAMEWIN_ID         4
      99             : 
     100             : #define ICON_POS_NEWDOC     0
     101             : #define ICON_POS_TEMPLATES  1
     102             : #define ICON_POS_MYDOCS     2
     103             : #define ICON_POS_SAMPLES    3
     104             : 
     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"
     110             : 
     111           0 : struct FolderHistory
     112             : {
     113             :     String      m_sURL;
     114             :     sal_uLong       m_nGroup;
     115             : 
     116           0 :     FolderHistory( const String& _rURL, sal_Int32 _nGroup ) :
     117           0 :         m_sURL( _rURL ), m_nGroup( _nGroup ) {}
     118             : };
     119             : 
     120             : typedef ::std::vector< OUString* > NewDocList_Impl;
     121             : 
     122             : // class SvtDummyHeaderBar_Impl ------------------------------------------
     123             : 
     124           0 : void SvtDummyHeaderBar_Impl::UpdateBackgroundColor()
     125             : {
     126           0 :     SetBackground( Wallpaper( GetSettings().GetStyleSettings().GetWindowColor() ) );
     127           0 : }
     128             : 
     129           0 : SvtDummyHeaderBar_Impl::SvtDummyHeaderBar_Impl( Window* pPar ) : Window( pPar )
     130             : {
     131           0 :     SetSizePixel( HeaderBar( this, 0 ).CalcWindowSizePixel() ); // HeaderBar used only to calculate size
     132             : 
     133           0 :     UpdateBackgroundColor();
     134           0 : }
     135             : 
     136           0 : SvtDummyHeaderBar_Impl::~SvtDummyHeaderBar_Impl()
     137             : {
     138           0 : }
     139             : 
     140           0 : void SvtDummyHeaderBar_Impl::DataChanged( const DataChangedEvent& r )
     141             : {
     142           0 :     Window::DataChanged( r );
     143           0 :     if( r.GetType() == DATACHANGED_SETTINGS )
     144           0 :         UpdateBackgroundColor();
     145           0 : }
     146             : 
     147             : // class SvtIconWindow_Impl ----------------------------------------------
     148             : 
     149           0 : SvtIconWindow_Impl::SvtIconWindow_Impl( Window* pParent ) :
     150             : 
     151             :     Window( pParent, WB_DIALOGCONTROL | WB_BORDER | WB_3DLOOK ),
     152             : 
     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           0 :     aMyDocumentsRootURL( SvtPathOptions().GetWorkPath() ),
     158             :     aSamplesFolderRootURL( SvtPathOptions().
     159             :         SubstituteVariable( String( "$(insturl)/share/samples/$(vlang)" ) ) ),
     160           0 :     nMaxTextLength( 0 )
     161             : 
     162             : {
     163           0 :     aDummyHeaderBar.Show();
     164             : 
     165           0 :     aIconCtrl.SetAccessibleName( String( RTL_CONSTASCII_USTRINGPARAM("Groups") ) );
     166           0 :       aIconCtrl.SetHelpId( HID_TEMPLATEDLG_ICONCTRL );
     167           0 :     aIconCtrl.SetChoiceWithCursor( sal_True );
     168           0 :     aIconCtrl.SetSelectionMode( SINGLE_SELECTION );
     169           0 :     aIconCtrl.Show();
     170             : 
     171             :     // detect the root URL of templates
     172           0 :     Reference< XDocumentTemplates > xTemplates( frame::DocumentTemplates::create(::comphelper::getProcessComponentContext()) );
     173             : 
     174           0 :     Reference < XContent > aRootContent = xTemplates->getContent();
     175           0 :     Reference < XCommandEnvironment > aCmdEnv;
     176             : 
     177           0 :     if ( aRootContent.is() )
     178           0 :         aTemplateRootURL = aRootContent->getIdentifier()->getContentIdentifier();
     179             : 
     180             :     // insert the categories
     181             :     // "New Document"
     182           0 :     Image aImage( SvtResId( IMG_SVT_NEWDOC ) );
     183           0 :     nMaxTextLength = aImage.GetSizePixel().Width();
     184           0 :     String aEntryStr = SVT_RESSTR(STR_SVT_NEWDOC);
     185             :     SvxIconChoiceCtrlEntry* pEntry =
     186           0 :         aIconCtrl.InsertEntry( aEntryStr, aImage, ICON_POS_NEWDOC );
     187           0 :     pEntry->SetUserData( new String( aNewDocumentRootURL ) );
     188           0 :     pEntry->SetQuickHelpText( SVT_RESSTR(STR_SVT_NEWDOC_HELP) );
     189             :     DBG_ASSERT( !pEntry->GetBoundRect().IsEmpty(), "empty rectangle" );
     190           0 :     long nTemp = pEntry->GetBoundRect().GetSize().Width();
     191           0 :     if (nTemp > nMaxTextLength)
     192           0 :         nMaxTextLength = nTemp;
     193             : 
     194             :     // "Templates"
     195           0 :     if( aTemplateRootURL.Len() > 0 )
     196             :     {
     197           0 :         aEntryStr = SVT_RESSTR(STR_SVT_TEMPLATES);
     198             :         pEntry = aIconCtrl.InsertEntry(
     199           0 :             aEntryStr, Image( SvtResId( IMG_SVT_TEMPLATES ) ), ICON_POS_TEMPLATES );
     200           0 :         pEntry->SetUserData( new String( aTemplateRootURL ) );
     201           0 :         pEntry->SetQuickHelpText(SVT_RESSTR(STR_SVT_TEMPLATES_HELP));
     202             :         DBG_ASSERT( !pEntry->GetBoundRect().IsEmpty(), "empty rectangle" );
     203           0 :         nTemp = pEntry->GetBoundRect().GetSize().Width();
     204           0 :         if (nTemp > nMaxTextLength)
     205           0 :             nMaxTextLength = nTemp;
     206             :     }
     207             : 
     208             :     // "My Documents"
     209           0 :     aEntryStr = SVT_RESSTR(STR_SVT_MYDOCS);
     210             :     pEntry = aIconCtrl.InsertEntry(
     211           0 :         aEntryStr, Image( SvtResId( IMG_SVT_MYDOCS ) ), ICON_POS_MYDOCS );
     212           0 :     pEntry->SetUserData( new String( aMyDocumentsRootURL ) );
     213           0 :     pEntry->SetQuickHelpText( SVT_RESSTR(STR_SVT_MYDOCS_HELP) );
     214             :     DBG_ASSERT( !pEntry->GetBoundRect().IsEmpty(), "empty rectangle" );
     215           0 :     nTemp = pEntry->GetBoundRect().GetSize().Width();
     216           0 :     if( nTemp > nMaxTextLength )
     217           0 :         nMaxTextLength = nTemp;
     218             : 
     219             :     // "Samples"
     220           0 :     aEntryStr = SVT_RESSTR(STR_SVT_SAMPLES);
     221             :     pEntry = aIconCtrl.InsertEntry(
     222           0 :         aEntryStr, Image( SvtResId( IMG_SVT_SAMPLES ) ), ICON_POS_SAMPLES );
     223           0 :     pEntry->SetUserData( new String( aSamplesFolderRootURL ) );
     224           0 :     pEntry->SetQuickHelpText( SVT_RESSTR(STR_SVT_SAMPLES_HELP));
     225             :     DBG_ASSERT( !pEntry->GetBoundRect().IsEmpty(), "empty rectangle" );
     226           0 :     nTemp = pEntry->GetBoundRect().GetSize().Width();
     227           0 :     if (nTemp > nMaxTextLength)
     228           0 :         nMaxTextLength = nTemp;
     229             : 
     230           0 :     aIconCtrl.CreateAutoMnemonics();
     231           0 : }
     232             : 
     233           0 : SvtIconWindow_Impl::~SvtIconWindow_Impl()
     234             : {
     235           0 :     for ( sal_uLong i = 0; i < aIconCtrl.GetEntryCount(); ++i )
     236             :     {
     237           0 :         SvxIconChoiceCtrlEntry* pEntry = aIconCtrl.GetEntry( i );
     238           0 :         delete (String*)pEntry->GetUserData();
     239             :     }
     240           0 : }
     241             : 
     242           0 : SvxIconChoiceCtrlEntry* SvtIconWindow_Impl::GetEntry( const String& rURL ) const
     243             : {
     244           0 :     SvxIconChoiceCtrlEntry* pEntry = NULL;
     245           0 :     for ( sal_uLong i = 0; i < aIconCtrl.GetEntryCount(); ++i )
     246             :     {
     247           0 :         SvxIconChoiceCtrlEntry* pTemp = aIconCtrl.GetEntry( i );
     248           0 :         String aURL( *( (String*)pTemp->GetUserData() ) );
     249           0 :         if ( aURL == rURL )
     250             :         {
     251           0 :             pEntry = pTemp;
     252           0 :             break;
     253             :         }
     254           0 :     }
     255             : 
     256           0 :     return pEntry;
     257             : }
     258             : 
     259           0 : void SvtIconWindow_Impl::Resize()
     260             : {
     261           0 :     Size aWinSize = GetOutputSizePixel();
     262           0 :     Size aHeaderSize = aDummyHeaderBar.GetSizePixel();
     263           0 :     aHeaderSize.Width() = aWinSize.Width();
     264           0 :     aDummyHeaderBar.SetSizePixel( aHeaderSize );
     265           0 :     long nHeaderHeight = aHeaderSize.Height();
     266           0 :     aWinSize.Height() -= nHeaderHeight;
     267           0 :     aIconCtrl.SetPosSizePixel( Point( 0, nHeaderHeight ), aWinSize );
     268           0 :     aIconCtrl.ArrangeIcons();
     269           0 : }
     270             : 
     271           0 : String SvtIconWindow_Impl::GetCursorPosIconURL() const
     272             : {
     273           0 :     String aURL;
     274           0 :     SvxIconChoiceCtrlEntry* pEntry = aIconCtrl.GetCursor( );
     275           0 :     if ( pEntry )
     276           0 :         aURL = *static_cast<String*>(pEntry->GetUserData());
     277           0 :     return aURL;
     278             : 
     279             : }
     280             : 
     281           0 : String SvtIconWindow_Impl::GetSelectedIconURL() const
     282             : {
     283             :     sal_uLong nPos;
     284           0 :     SvxIconChoiceCtrlEntry* pEntry = aIconCtrl.GetSelectedEntry( nPos );
     285           0 :     String aURL;
     286           0 :     if ( pEntry )
     287           0 :         aURL = *static_cast<String*>(pEntry->GetUserData());
     288           0 :     return aURL;
     289             : }
     290             : 
     291           0 : String SvtIconWindow_Impl::GetIconText( const String& rURL ) const
     292             : {
     293           0 :     String aText;
     294           0 :     SvxIconChoiceCtrlEntry* pEntry = GetEntry( rURL );
     295           0 :     if ( pEntry )
     296           0 :         aText = MnemonicGenerator::EraseAllMnemonicChars( pEntry->GetText() );
     297           0 :     return aText;
     298             : }
     299             : 
     300           0 : void SvtIconWindow_Impl::InvalidateIconControl()
     301             : {
     302           0 :     aIconCtrl.Invalidate();
     303           0 : }
     304             : 
     305           0 : sal_uLong SvtIconWindow_Impl::GetCursorPos() const
     306             : {
     307           0 :     sal_uLong nPos = ~sal_uLong(0);
     308             : 
     309           0 :     SvxIconChoiceCtrlEntry* pCursorEntry = aIconCtrl.GetCursor( );
     310           0 :     if ( pCursorEntry )
     311           0 :         nPos = aIconCtrl.GetEntryListPos( pCursorEntry );
     312             : 
     313           0 :     return nPos;
     314             : }
     315             : 
     316           0 : sal_uLong SvtIconWindow_Impl::GetSelectEntryPos() const
     317             : {
     318             :     sal_uLong nPos;
     319           0 :     if ( !aIconCtrl.GetSelectedEntry( nPos ) )
     320           0 :         nPos = ~sal_uLong(0);
     321           0 :     return nPos;
     322             : }
     323             : 
     324           0 : void SvtIconWindow_Impl::SetCursorPos( sal_uLong nPos )
     325             : {
     326           0 :     SvxIconChoiceCtrlEntry* pEntry = aIconCtrl.GetEntry( nPos );
     327           0 :     aIconCtrl.SetCursor( pEntry );
     328           0 :     aIconCtrl.Invalidate();
     329           0 :     aIconCtrl.Update();
     330           0 : }
     331             : 
     332           0 : void SvtIconWindow_Impl::SetFocus()
     333             : {
     334           0 :     aIconCtrl.GrabFocus();
     335           0 : }
     336             : 
     337           0 : long SvtIconWindow_Impl::CalcHeight() const
     338             : {
     339             :     // calculate the required height of the IconControl
     340           0 :     long nHeight = 0;
     341           0 :     sal_uLong nCount = aIconCtrl.GetEntryCount();
     342           0 :     if ( nCount > 0 )
     343             :         // bottom of the last icon
     344           0 :         nHeight = aIconCtrl.GetEntry(nCount-1)->GetBoundRect().Bottom();
     345             : 
     346             :     // + headerbar height
     347           0 :     nHeight += aDummyHeaderBar.GetSizePixel().Height();
     348             : 
     349           0 :     return nHeight;
     350             : }
     351             : 
     352           0 : sal_Bool SvtIconWindow_Impl::IsRootURL( const String& rURL ) const
     353             : {
     354           0 :     return  rURL == aNewDocumentRootURL ||
     355           0 :             rURL == aTemplateRootURL ||
     356           0 :             rURL == aMyDocumentsRootURL ||
     357           0 :             rURL == aSamplesFolderRootURL;
     358             : }
     359             : 
     360           0 : sal_uLong SvtIconWindow_Impl::GetRootPos( const String& rURL ) const
     361             : {
     362           0 :     sal_uLong nPos = ~sal_uLong(0);
     363           0 :     if ( aNewDocumentRootURL.Match( rURL ) == STRING_MATCH )
     364           0 :         nPos = 0;
     365           0 :     else if ( aTemplateRootURL.Match( rURL ) == STRING_MATCH )
     366           0 :         nPos = 1;
     367           0 :     else if ( aMyDocumentsRootURL.Match( rURL ) == STRING_MATCH )
     368           0 :         nPos = 2;
     369           0 :     else if ( aSamplesFolderRootURL.Match( rURL ) == STRING_MATCH )
     370           0 :         nPos = 3;
     371           0 :     else if ( rURL.Match( aMyDocumentsRootURL ) == STRING_MATCH )
     372           0 :         nPos = 2;
     373             :     else
     374             :     {
     375             :         DBG_WARNING( "SvtIconWindow_Impl::GetRootPos(): invalid position" );
     376           0 :         nPos = 2;
     377             :     }
     378             : 
     379           0 :     return nPos;
     380             : }
     381             : 
     382           0 : void SvtIconWindow_Impl::UpdateIcons()
     383             : {
     384             :     aIconCtrl.GetEntry( ICON_POS_NEWDOC )->SetImage(
     385           0 :         Image( SvtResId( IMG_SVT_NEWDOC ) ) );
     386             :     aIconCtrl.GetEntry( ICON_POS_TEMPLATES )->SetImage(
     387           0 :         Image( SvtResId( IMG_SVT_TEMPLATES ) ) );
     388             :     aIconCtrl.GetEntry( ICON_POS_MYDOCS )->SetImage(
     389           0 :         Image( SvtResId( IMG_SVT_MYDOCS ) ) );
     390             :     aIconCtrl.GetEntry( ICON_POS_SAMPLES )->SetImage(
     391           0 :         Image( SvtResId( IMG_SVT_SAMPLES ) ) );
     392           0 : }
     393             : 
     394           0 : void SvtIconWindow_Impl::SelectFolder(sal_Int32 nFolderPosition)
     395             : {
     396           0 :     SvxIconChoiceCtrlEntry* pEntry = aIconCtrl.GetEntry( nFolderPosition );
     397           0 :     if(pEntry)
     398             :     {
     399           0 :         aIconCtrl.SetCursor( pEntry );
     400           0 :         aIconCtrl.GetClickHdl().Call(&aIconCtrl);
     401             :     }
     402           0 : }
     403             : 
     404             : // class SvtFileViewWindow_Impl -----------------------------------------_
     405             : 
     406           0 : SvtFileViewWindow_Impl::SvtFileViewWindow_Impl( SvtTemplateWindow* pParent ) :
     407             : 
     408             :     Window( pParent, WB_DIALOGCONTROL | WB_TABSTOP | WB_BORDER | WB_3DLOOK ),
     409             : 
     410             :     rParent             ( *pParent ),
     411             :     aFileView           ( this, SvtResId( CTRL_FILEVIEW ), FILEVIEW_SHOW_NONE | FILEVIEW_SHOW_ONLYTITLE ),
     412           0 :     bIsTemplateFolder   ( sal_False )
     413             : 
     414             : {
     415           0 :     aFileView.SetStyle( aFileView.GetStyle() | WB_DIALOGCONTROL | WB_TABSTOP );
     416           0 :     aFileView.SetHelpId( HID_TEMPLATEDLG_FILEVIEW );
     417           0 :     aFileView.Show();
     418           0 :     aFileView.EnableAutoResize();
     419           0 :     aFileView.EnableContextMenu( sal_False );
     420           0 :     aFileView.EnableDelete( sal_False );
     421           0 : }
     422             : 
     423           0 : SvtFileViewWindow_Impl::~SvtFileViewWindow_Impl()
     424             : {
     425           0 : }
     426             : 
     427           0 : void GetMenuEntry_Impl
     428             : (
     429             :     Sequence< PropertyValue >& aDynamicMenuEntry,
     430             :     OUString& rTitle,
     431             :     OUString& rURL,
     432             :     OUString& rFrame,
     433             :     OUString& rImageId
     434             : )
     435             : {
     436           0 :     for ( int i = 0; i < aDynamicMenuEntry.getLength(); i++ )
     437             :     {
     438           0 :         if ( aDynamicMenuEntry[i].Name == DYNAMICMENU_PROPERTYNAME_URL )
     439           0 :             aDynamicMenuEntry[i].Value >>= rURL;
     440           0 :         else if ( aDynamicMenuEntry[i].Name == DYNAMICMENU_PROPERTYNAME_TITLE )
     441           0 :             aDynamicMenuEntry[i].Value >>= rTitle;
     442           0 :         else if ( aDynamicMenuEntry[i].Name == DYNAMICMENU_PROPERTYNAME_IMAGEIDENTIFIER )
     443           0 :             aDynamicMenuEntry[i].Value >>= rImageId;
     444           0 :         else if ( aDynamicMenuEntry[i].Name == DYNAMICMENU_PROPERTYNAME_TARGETNAME )
     445           0 :             aDynamicMenuEntry[i].Value >>= rFrame;
     446             :     }
     447           0 : }
     448             : 
     449           0 : Sequence< OUString > SvtFileViewWindow_Impl::GetNewDocContents() const
     450             : {
     451           0 :     NewDocList_Impl aNewDocs;
     452           0 :     Sequence< Sequence< PropertyValue > > aDynamicMenuEntries;
     453           0 :     aDynamicMenuEntries = SvtDynamicMenuOptions().GetMenu( E_NEWMENU );
     454             : 
     455           0 :     OUString aTitle;
     456           0 :     OUString aURL;
     457           0 :     OUString aImageURL;
     458           0 :     OUString aTargetFrame;
     459             : 
     460           0 :     sal_uInt32 i, nCount = aDynamicMenuEntries.getLength();
     461           0 :     OUString sSeparator( "private:separator" );
     462           0 :     OUString sSlotURL( "slot:5500" );
     463             : 
     464           0 :     for ( i = 0; i < nCount; ++i )
     465             :     {
     466           0 :         GetMenuEntry_Impl( aDynamicMenuEntries[i], aTitle, aURL, aTargetFrame, aImageURL );
     467           0 :         if( aURL == sSlotURL )
     468           0 :             continue;
     469           0 :         if( aURL == sSeparator )
     470             :         {
     471           0 :             String aSeparator( aSeparatorStr );
     472           0 :             OUString* pSeparator = new OUString( aSeparator );
     473           0 :             aNewDocs.push_back( pSeparator );
     474             :         }
     475             :         else
     476             :         {
     477             :             // title
     478           0 :             String aRow = MnemonicGenerator::EraseAllMnemonicChars( String( aTitle ) );
     479           0 :             aRow += '\t';
     480             :             // no type
     481           0 :             aRow += '\t';
     482             :             // no size
     483           0 :             aRow += '\t';
     484             :             // no date
     485           0 :             aRow += '\t';
     486             :             // url
     487           0 :             aRow += String( aURL );
     488           0 :             aRow += '\t';
     489             :             // folder == false
     490           0 :             aRow += '0';
     491             :             // image url?
     492           0 :             if ( !aImageURL.isEmpty() )
     493             :             {
     494           0 :                 aRow += '\t';
     495           0 :                 aRow += String( aImageURL );
     496             :             }
     497             : 
     498           0 :             OUString* pRow = new OUString( aRow );
     499           0 :             aNewDocs.push_back( pRow );
     500             :         }
     501             :     }
     502             : 
     503           0 :     nCount = aNewDocs.size();
     504           0 :     Sequence < OUString > aRet( nCount );
     505           0 :     OUString* pRet = aRet.getArray();
     506           0 :     for ( i = 0; i < nCount; ++i )
     507             :     {
     508           0 :         OUString* pNewDoc = aNewDocs[i];
     509           0 :         pRet[i] = *( pNewDoc );
     510           0 :         delete pNewDoc;
     511             :     }
     512             : 
     513           0 :     return aRet;
     514             : }
     515             : 
     516           0 : void SvtFileViewWindow_Impl::Resize()
     517             : {
     518           0 :     aFileView.SetSizePixel(GetOutputSizePixel());
     519           0 : }
     520             : 
     521           0 : String SvtFileViewWindow_Impl::GetSelectedFile() const
     522             : {
     523           0 :     return aFileView.GetCurrentURL();
     524             : }
     525             : 
     526           0 : void SvtFileViewWindow_Impl::OpenFolder( const String& rURL )
     527             : {
     528           0 :     aFolderURL = rURL;
     529             : 
     530           0 :     rParent.SetPrevLevelButtonState( rURL );
     531             : 
     532           0 :     if ( INetURLObject( rURL ).GetProtocol() == INET_PROT_PRIVATE )
     533             :     {
     534           0 :         aFileView.EnableNameReplacing( sal_False );
     535           0 :         aFileView.Initialize( GetNewDocContents() );
     536             :     }
     537             :     else
     538             :     {
     539           0 :         xub_StrLen nSampFoldLen = aSamplesFolderURL.Len();
     540             :         aFileView.EnableNameReplacing(
     541           0 :                     nSampFoldLen && rURL.CompareTo( aSamplesFolderURL, nSampFoldLen ) == COMPARE_EQUAL );
     542           0 :         aFileView.Initialize( rURL, String(), NULL );
     543             :     }
     544           0 :     aNewFolderLink.Call( this );
     545           0 : }
     546             : 
     547           0 : sal_Bool SvtFileViewWindow_Impl::HasPreviousLevel( String& rURL ) const
     548             : {
     549           0 :     INetURLObject aViewObj( aFileView.GetViewURL() );
     550           0 :     INetURLObject aRootObj( aCurrentRootURL );
     551           0 :     INetURLObject aMyDocObj( aMyDocumentsURL );
     552             : 
     553           0 :     return ( ( aViewObj != aRootObj || aRootObj == aMyDocObj ) && aFileView.GetParentURL( rURL ) );
     554             : }
     555             : 
     556           0 : String SvtFileViewWindow_Impl::GetFolderTitle() const
     557             : {
     558           0 :     OUString aTitle;
     559           0 :     ::utl::UCBContentHelper::GetTitle( aFolderURL, &aTitle );
     560           0 :     return aTitle;
     561             : }
     562             : 
     563           0 : void SvtFileViewWindow_Impl::SetFocus()
     564             : {
     565           0 :     aFileView.SetFocus();
     566           0 : }
     567             : 
     568             : // class SvtDocInfoTable_Impl --------------------------------------------
     569             : 
     570           0 : SvtDocInfoTable_Impl::SvtDocInfoTable_Impl() :
     571             : 
     572           0 :     ResStringArray( SvtResId( STRARY_SVT_DOCINFO ) )
     573             : 
     574             : {
     575           0 : }
     576             : // -----------------------------------------------------------------------
     577             : 
     578           0 : OUString SvtDocInfoTable_Impl::GetString( long nId ) const
     579             : {
     580           0 :     sal_uInt32 nPos( FindIndex( nId ) );
     581             : 
     582           0 :     if ( RESARRAY_INDEX_NOTFOUND != nPos )
     583           0 :         return ResStringArray::GetString( nPos );
     584             : 
     585           0 :     return OUString();
     586             : }
     587             : 
     588             : // class SvtFrameWindow_Impl ---------------------------------------------
     589             : 
     590           0 : SvtFrameWindow_Impl::SvtFrameWindow_Impl( Window* pParent )
     591           0 :   : Window( pParent )
     592             : {
     593             :     // create windows and frame
     594           0 :     pEditWin = new ODocumentInfoPreview( this ,WB_LEFT | WB_VSCROLL | WB_READONLY | WB_BORDER | WB_3DLOOK);
     595           0 :     pTextWin = new Window( this );
     596           0 :     m_xFrame = Frame::create( ::comphelper::getProcessComponentContext() );
     597           0 :     xWindow = VCLUnoHelper::GetInterface( pTextWin );
     598           0 :     m_xFrame->initialize( xWindow );
     599             : 
     600             :     // create docinfo instance
     601           0 :     m_xDocProps.set( document::DocumentProperties::create(::comphelper::getProcessComponentContext()) );
     602             : 
     603           0 :     pEmptyWin = new Window( this, WB_BORDER | WB_3DLOOK );
     604           0 : }
     605             : 
     606           0 : SvtFrameWindow_Impl::~SvtFrameWindow_Impl()
     607             : {
     608           0 :     delete pEditWin;
     609           0 :     delete pEmptyWin;
     610           0 :     m_xFrame->dispose();
     611           0 : }
     612             : 
     613           0 : void SvtFrameWindow_Impl::ViewEditWin()
     614             : {
     615           0 :     pEmptyWin->Hide();
     616           0 :     xWindow->setVisible( sal_False );
     617           0 :     pTextWin->Hide();
     618           0 :     pEditWin->Show();
     619           0 : }
     620             : 
     621           0 : void SvtFrameWindow_Impl::ViewTextWin()
     622             : {
     623           0 :     pEmptyWin->Hide();
     624           0 :     pEditWin->Hide();
     625           0 :     xWindow->setVisible( sal_True );
     626           0 :     pTextWin->Show();
     627           0 : }
     628             : 
     629           0 : void SvtFrameWindow_Impl::ViewEmptyWin()
     630             : {
     631           0 :     xWindow->setVisible( sal_False );
     632           0 :     pTextWin->Hide();
     633           0 :     pEditWin->Hide();
     634           0 :     pEmptyWin->Show();
     635           0 : }
     636             : 
     637           0 : void SvtFrameWindow_Impl::ViewNonEmptyWin()
     638             : {
     639           0 :     if( bDocInfo )
     640           0 :         ViewEditWin();
     641             :     else
     642           0 :         ViewTextWin();
     643           0 : }
     644             : 
     645           0 : void SvtFrameWindow_Impl::ShowDocInfo( const String& rURL )
     646             : {
     647             :     try
     648             :     {
     649             :         uno::Reference < task::XInteractionHandler2 > xInteractionHandler(
     650           0 :             task::InteractionHandler::createWithParent(::comphelper::getProcessComponentContext(), 0) );
     651           0 :         uno::Sequence < beans::PropertyValue> aProps(1);
     652           0 :         aProps[0].Name = OUString( "InteractionHandler" );
     653           0 :         aProps[0].Value <<= xInteractionHandler;
     654           0 :         m_xDocProps->loadFromMedium( rURL, aProps );
     655           0 :         pEditWin->fill( m_xDocProps, rURL );
     656             :     }
     657           0 :     catch ( UnknownPropertyException& ) {}
     658           0 :     catch ( Exception& ) {}
     659           0 : }
     660             : 
     661           0 : void SvtFrameWindow_Impl::Resize()
     662             : {
     663           0 :     Size aWinSize = GetOutputSizePixel();
     664           0 :     pEditWin->SetSizePixel( aWinSize );
     665           0 :     pTextWin->SetSizePixel( aWinSize );
     666           0 :     pEmptyWin->SetSizePixel( aWinSize );
     667           0 : }
     668             : 
     669           0 : void SvtFrameWindow_Impl::OpenFile( const String& rURL, sal_Bool bPreview, sal_Bool bIsTemplate, sal_Bool bAsTemplate )
     670             : {
     671           0 :     if ( bPreview )
     672           0 :         aCurrentURL = rURL;
     673             : 
     674           0 :     ViewNonEmptyWin();
     675           0 :     pEditWin->clear();
     676             : 
     677           0 :     if ( rURL.Len() > 0 && bPreview && m_xDocProps.is() )
     678           0 :         ShowDocInfo( rURL );
     679             : 
     680           0 :     if ( rURL.Len() == 0 )
     681             :     {
     682           0 :         m_xFrame->setComponent( Reference < com::sun::star::awt::XWindow >(), Reference < XController >() );
     683           0 :         ViewEmptyWin();
     684             :     }
     685           0 :     else if ( !::utl::UCBContentHelper::IsFolder( rURL ) )
     686             :     {
     687           0 :         com::sun::star::util::URL aURL;
     688           0 :         aURL.Complete = rURL;
     689             :         Reference< com::sun::star::util::XURLTransformer > xTrans(
     690           0 :                     com::sun::star::util::URLTransformer::create( ::comphelper::getProcessComponentContext() ) );
     691           0 :         xTrans->parseStrict( aURL );
     692             : 
     693           0 :         String aTarget;
     694           0 :         Reference < XDispatchProvider > xProv( m_xFrame, UNO_QUERY_THROW );
     695           0 :         if ( bPreview )
     696           0 :             aTarget = "_self";
     697             :         else
     698             :         {
     699             :             // can be removed if the database application change its URL
     700           0 :             String sServiceScheme( RTL_CONSTASCII_USTRINGPARAM( "service:" ) );
     701           0 :             if ( rURL.Match( sServiceScheme ) != sServiceScheme.Len() )
     702             :                 // service URL has no default target
     703           0 :                 aTarget = "_default";
     704           0 :             xProv = Reference < XDispatchProvider >( Desktop::create(::comphelper::getProcessComponentContext() ),
     705           0 :                 UNO_QUERY_THROW );
     706             :         }
     707             : 
     708           0 :         Reference < XDispatch > xDisp = xProv.is() ?
     709           0 :             xProv->queryDispatch( aURL, aTarget, 0 ) : Reference < XDispatch >();
     710             : 
     711           0 :         if ( xDisp.is() )
     712             :         {
     713           0 :             if ( bPreview )
     714             :             {
     715           0 :                 if ( m_aOpenURL != aURL.Complete )
     716             :                 {
     717           0 :                     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           0 :                     pTextWin->EnableInput( sal_False, sal_True );
     722           0 :                     if ( pTextWin->IsReallyVisible() )
     723             :                     {
     724           0 :                         sal_Bool    b = sal_True;
     725           0 :                         Sequence < PropertyValue > aArgs( 4 );
     726           0 :                         aArgs[0].Name = "Preview";
     727           0 :                         aArgs[0].Value.setValue( &b, ::getBooleanCppuType() );
     728           0 :                         aArgs[1].Name = "ReadOnly";
     729           0 :                         aArgs[1].Value.setValue( &b, ::getBooleanCppuType() );
     730           0 :                         aArgs[2].Name = "AsTemplate";    // prevents getting an empty URL with getURL()!
     731             : 
     732             :                         uno::Reference < task::XInteractionHandler2 > xInteractionHandler(
     733           0 :                             task::InteractionHandler::createWithParent(::comphelper::getProcessComponentContext(), 0) );
     734           0 :                         aArgs[3].Name = OUString( "InteractionHandler" );
     735           0 :                         aArgs[3].Value <<= xInteractionHandler;
     736             : 
     737           0 :                         b = sal_False;
     738           0 :                         aArgs[2].Value.setValue( &b, ::getBooleanCppuType() );
     739           0 :                         xDisp->dispatch( aURL, aArgs );
     740             : 
     741           0 :                         OUString                                                aDispURL;
     742           0 :                         Reference< ::com::sun::star::frame::XController >       xCtrl = m_xFrame->getController();
     743           0 :                         if( xCtrl.is() )
     744             :                         {
     745           0 :                             Reference< ::com::sun::star::frame::XModel >        xMdl = xCtrl->getModel();
     746           0 :                             if( xMdl.is() )
     747           0 :                                 aDispURL = xMdl->getURL();
     748             :                         }
     749             : 
     750           0 :                         if( aDispURL != aURL.Complete )
     751             :                         {
     752           0 :                             m_xFrame->setComponent( Reference < com::sun::star::awt::XWindow >(), Reference < XController >() );
     753           0 :                             ViewEmptyWin();
     754           0 :                             m_aOpenURL = OUString();
     755             :                         }
     756             :                         else
     757           0 :                             m_aOpenURL = aDispURL;
     758           0 :                     }
     759             :                 }
     760             :             }
     761           0 :             else if ( bIsTemplate )
     762             :             {
     763           0 :                 Sequence < PropertyValue > aArgs( 1 );
     764           0 :                 aArgs[0].Name = "AsTemplate";
     765           0 :                 aArgs[0].Value <<= bAsTemplate;
     766           0 :                 xDisp->dispatch( aURL, aArgs );
     767           0 :                 m_aOpenURL = OUString();
     768             :             }
     769             :             else
     770             :             {
     771           0 :                 Sequence < PropertyValue > aArgs;
     772           0 :                 xDisp->dispatch( aURL, aArgs );
     773           0 :                 m_aOpenURL = OUString();
     774             :             }
     775           0 :         }
     776             :     }
     777           0 : }
     778             : 
     779           0 : void SvtFrameWindow_Impl::ToggleView( sal_Bool bDI )
     780             : {
     781           0 :     bDocInfo = bDI;
     782             : 
     783             :     // view is set properly in OpenFile()
     784             : 
     785           0 :     OpenFile( aCurrentURL, sal_True, sal_False, sal_False );
     786           0 : }
     787             : 
     788             : // class SvtTemplateWindow -----------------------------------------------
     789             : 
     790           0 : SvtTemplateWindow::SvtTemplateWindow( Window* pParent ) :
     791             : 
     792             :     Window( pParent, WB_DIALOGCONTROL ),
     793             : 
     794             :     aFileViewTB             ( this, SvtResId( TB_SVT_FILEVIEW ) ),
     795             :     aFrameWinTB             ( this, SvtResId( TB_SVT_FRAMEWIN ) ),
     796             :     aSplitWin               ( this, WB_DIALOGCONTROL | WB_NOSPLITDRAW ),
     797           0 :     pHistoryList            ( NULL )
     798             : 
     799             : {
     800             :     // create windows
     801           0 :     pIconWin = new SvtIconWindow_Impl( this );
     802           0 :     pFileWin = new SvtFileViewWindow_Impl( this );
     803           0 :     pFileWin->SetMyDocumentsURL( pIconWin->GetMyDocumentsRootURL() );
     804           0 :     pFileWin->SetSamplesFolderURL( pIconWin->GetSamplesFolderURL() );
     805           0 :     pFrameWin = new SvtFrameWindow_Impl( this );
     806             : 
     807             :     // set handlers
     808           0 :     pIconWin->SetClickHdl( LINK( this, SvtTemplateWindow, IconClickHdl_Impl ) );
     809           0 :     pFileWin->SetSelectHdl( LINK( this, SvtTemplateWindow, FileSelectHdl_Impl ) );
     810           0 :     pFileWin->SetDoubleClickHdl( LINK( this, SvtTemplateWindow, FileDblClickHdl_Impl ) );
     811           0 :     pFileWin->SetNewFolderHdl( LINK( this, SvtTemplateWindow, NewFolderHdl_Impl ) );
     812             : 
     813             :     // create the split items
     814           0 :     aSplitWin.SetAlign( WINDOWALIGN_LEFT );
     815           0 :     long nWidth = pIconWin->GetMaxTextLength() * 8 / 7 + 1; // extra space for border
     816           0 :     aSplitWin.InsertItem( ICONWIN_ID, pIconWin, nWidth, SPLITWINDOW_APPEND, 0, SWIB_FIXED );
     817           0 :     aSplitWin.InsertItem( FILEWIN_ID, pFileWin, 50, SPLITWINDOW_APPEND, 0, SWIB_PERCENTSIZE );
     818           0 :     aSplitWin.InsertItem( FRAMEWIN_ID, pFrameWin, 50, SPLITWINDOW_APPEND, 0, SWIB_PERCENTSIZE );
     819           0 :     aSplitWin.SetSplitHdl( LINK( this, SvtTemplateWindow, ResizeHdl_Impl ) );
     820             : 
     821             :     // show the windows
     822           0 :     pIconWin->Show();
     823           0 :     pFileWin->Show();
     824           0 :     pFrameWin->Show();
     825           0 :     aSplitWin.Show();
     826             : 
     827             :     // initialize the timers
     828           0 :     aSelectTimer.SetTimeout( 200 );
     829           0 :     aSelectTimer.SetTimeoutHdl( LINK( this, SvtTemplateWindow, TimeoutHdl_Impl ) );
     830             : 
     831             :     // initialize the toolboxes and then show them
     832           0 :     InitToolBoxes();
     833           0 :     aFileViewTB.Show();
     834           0 :     aFrameWinTB.Show();
     835             : 
     836           0 :     ReadViewSettings( );
     837             : 
     838           0 :     Application::PostUserEvent( LINK( this, SvtTemplateWindow, ResizeHdl_Impl ) );
     839           0 : }
     840             : 
     841             : // ------------------------------------------------------------------------
     842             : 
     843           0 : SvtTemplateWindow::~SvtTemplateWindow()
     844             : {
     845           0 :     WriteViewSettings( );
     846             : 
     847           0 :     delete pIconWin;
     848           0 :     delete pFileWin;
     849           0 :     delete pFrameWin;
     850           0 :     if ( pHistoryList )
     851             :     {
     852           0 :         for ( size_t i = 0, n = pHistoryList->size(); i < n; ++i )
     853           0 :             delete (*pHistoryList)[ i ];
     854           0 :         pHistoryList->clear();
     855           0 :         delete pHistoryList;
     856             :     }
     857           0 : }
     858             : 
     859             : // ------------------------------------------------------------------------
     860             : 
     861           0 : IMPL_LINK_NOARG(SvtTemplateWindow , IconClickHdl_Impl)
     862             : {
     863           0 :     String aURL = pIconWin->GetSelectedIconURL();
     864           0 :     if ( !aURL.Len() )
     865           0 :         aURL = pIconWin->GetCursorPosIconURL();
     866           0 :     if ( pFileWin->GetRootURL() != aURL )
     867             :     {
     868           0 :         pFileWin->OpenRoot( aURL );
     869           0 :         pIconWin->InvalidateIconControl();
     870           0 :         aFileViewTB.EnableItem( TI_DOCTEMPLATE_PRINT, sal_False );
     871             :     }
     872           0 :     return 0;
     873             : }
     874             : 
     875             : // ------------------------------------------------------------------------
     876             : 
     877           0 : IMPL_LINK_NOARG(SvtTemplateWindow , FileSelectHdl_Impl)
     878             : {
     879           0 :     aSelectTimer.Start();
     880           0 :     return 0;
     881             : }
     882             : 
     883             : // ------------------------------------------------------------------------
     884             : 
     885           0 : IMPL_LINK_NOARG(SvtTemplateWindow , FileDblClickHdl_Impl)
     886             : {
     887           0 :     if ( aSelectTimer.IsActive() )
     888           0 :         aSelectTimer.Stop();
     889             : 
     890           0 :     String aURL = pFileWin->GetSelectedFile();
     891           0 :     if ( aURL.Len() > 0 )
     892             :     {
     893           0 :         if ( ::utl::UCBContentHelper::IsFolder( aURL ) )
     894           0 :             pFileWin->OpenFolder( aURL );
     895             :         else
     896           0 :             aDoubleClickHdl.Call( this );
     897             :     }
     898             : 
     899           0 :     return 0;
     900             : }
     901             : 
     902             : // ------------------------------------------------------------------------
     903             : 
     904           0 : IMPL_LINK_NOARG(SvtTemplateWindow , NewFolderHdl_Impl)
     905             : {
     906           0 :     pFrameWin->OpenFile( String(), sal_True, sal_False, sal_False );
     907           0 :     aFileViewTB.EnableItem( TI_DOCTEMPLATE_PRINT, sal_False );
     908             : 
     909           0 :     String sURL = pFileWin->GetFolderURL();
     910           0 :     sal_uLong nPos = pIconWin->GetRootPos( sURL );
     911           0 :     AppendHistoryURL( sURL, nPos );
     912             : 
     913           0 :     aNewFolderHdl.Call( this );
     914           0 :     return 0;
     915             : }
     916             : 
     917             : // ------------------------------------------------------------------------
     918             : 
     919           0 : IMPL_LINK_NOARG(SvtTemplateWindow , TimeoutHdl_Impl)
     920             : {
     921           0 :     aSelectHdl.Call( this );
     922           0 :     String sURL = pFileWin->GetSelectedFile();
     923           0 :     sal_Bool bIsNewDoc = ( pIconWin->GetSelectEntryPos() == ICON_POS_NEWDOC );
     924           0 :     sal_Bool bIsFile = ( sURL.Len() != 0 && !::utl::UCBContentHelper::IsFolder( sURL ) &&
     925           0 :                          INetURLObject( sURL ).GetProtocol() != INET_PROT_PRIVATE && !bIsNewDoc );
     926           0 :     aFileViewTB.EnableItem( TI_DOCTEMPLATE_PRINT, bIsFile );
     927           0 :     aFrameWinTB.EnableItem( TI_DOCTEMPLATE_PREVIEW, !bIsNewDoc );
     928             : 
     929           0 :     if ( bIsFile )
     930           0 :         pFrameWin->OpenFile( sURL, sal_True, sal_False, sal_False );
     931           0 :     else if ( bIsNewDoc && aFrameWinTB.IsItemChecked( TI_DOCTEMPLATE_PREVIEW ) )
     932             :     {
     933           0 :         aFrameWinTB.CheckItem( TI_DOCTEMPLATE_DOCINFO );
     934           0 :         DoAction( TI_DOCTEMPLATE_DOCINFO );
     935             :     }
     936           0 :     return 0;
     937             : }
     938             : 
     939             : // ------------------------------------------------------------------------
     940             : 
     941           0 : IMPL_LINK ( SvtTemplateWindow , ClickHdl_Impl, ToolBox *, pToolBox )
     942             : {
     943           0 :     DoAction( pToolBox->GetCurItemId() );
     944           0 :     return 0;
     945             : }
     946             : 
     947             : // ------------------------------------------------------------------------
     948             : 
     949           0 : IMPL_LINK_NOARG(SvtTemplateWindow , ResizeHdl_Impl)
     950             : {
     951           0 :     Resize();
     952           0 :     return 0;
     953             : }
     954             : 
     955             : // ------------------------------------------------------------------------
     956             : 
     957           0 : void SvtTemplateWindow::PrintFile( const String& rURL )
     958             : {
     959             :     // open the file readonly and hidden
     960           0 :     Sequence < PropertyValue > aArgs( 2 );
     961           0 :     aArgs[0].Name = "ReadOnly";
     962           0 :     aArgs[0].Value <<= sal_True;
     963           0 :     aArgs[1].Name = "Hidden";
     964           0 :     aArgs[1].Value <<= sal_True;
     965             : 
     966           0 :     Reference < XDesktop2 > xDesktop = Desktop::create( ::comphelper::getProcessComponentContext() );
     967           0 :     Reference < XModel > xModel( xDesktop->loadComponentFromURL(
     968           0 :         rURL, "_blank", 0, aArgs ), UNO_QUERY );
     969           0 :     if ( xModel.is() )
     970             :     {
     971             :         // print
     972           0 :         Reference < XPrintable > xPrintable( xModel, UNO_QUERY );
     973           0 :         if ( xPrintable.is() )
     974           0 :             xPrintable->print( Sequence < PropertyValue >() );
     975           0 :     }
     976           0 : }
     977             : 
     978             : // ------------------------------------------------------------------------
     979             : 
     980           0 : void SvtTemplateWindow::AppendHistoryURL( const String& rURL, sal_uLong nGroup )
     981             : {
     982           0 :     sal_Bool bInsert = sal_True;
     983           0 :     if ( !pHistoryList )
     984           0 :         pHistoryList = new HistoryList_Impl;
     985           0 :     else if ( pHistoryList->size() > 0 )
     986             :     {
     987           0 :         FolderHistory* pLastEntry = pHistoryList->back();
     988           0 :         bInsert = ( rURL != pLastEntry->m_sURL);
     989             :     }
     990             : 
     991           0 :     if ( bInsert )
     992             :     {
     993           0 :         FolderHistory* pEntry = new FolderHistory( rURL, nGroup );
     994           0 :         pHistoryList->push_back( pEntry );
     995           0 :         aFileViewTB.EnableItem( TI_DOCTEMPLATE_BACK, pHistoryList->size() > 1 );
     996             :     }
     997           0 : }
     998             : 
     999             : // ------------------------------------------------------------------------
    1000             : 
    1001           0 : void SvtTemplateWindow::OpenHistory()
    1002             : {
    1003           0 :     delete pHistoryList->back();
    1004           0 :     pHistoryList->pop_back();
    1005           0 :     FolderHistory* pEntry = pHistoryList->back();
    1006           0 :     pHistoryList->pop_back();
    1007           0 :     aFileViewTB.EnableItem( TI_DOCTEMPLATE_BACK, pHistoryList->size() > 1 );
    1008           0 :     pFileWin->OpenFolder( pEntry->m_sURL );
    1009           0 :     pIconWin->SetCursorPos( pEntry->m_nGroup );
    1010           0 :     delete pEntry;
    1011           0 : }
    1012             : 
    1013             : // ------------------------------------------------------------------------
    1014             : 
    1015           0 : void SvtTemplateWindow::DoAction( sal_uInt16 nAction )
    1016             : {
    1017           0 :     switch( nAction )
    1018             :     {
    1019             :         case TI_DOCTEMPLATE_BACK :
    1020             :         {
    1021           0 :             if ( pHistoryList && pHistoryList->size() > 1 )
    1022           0 :                 OpenHistory();
    1023           0 :             break;
    1024             :         }
    1025             : 
    1026             :         case TI_DOCTEMPLATE_PREV :
    1027             :         {
    1028           0 :             String aURL;
    1029           0 :             if ( pFileWin->HasPreviousLevel( aURL ) )
    1030           0 :                 pFileWin->OpenFolder( aURL );
    1031           0 :             break;
    1032             :         }
    1033             : 
    1034             :         case TI_DOCTEMPLATE_PRINT :
    1035             :         {
    1036           0 :             String sPrintFile( pFileWin->GetSelectedFile() );
    1037           0 :             if ( sPrintFile.Len() > 0 )
    1038           0 :                 PrintFile( sPrintFile );
    1039           0 :             break;
    1040             :         }
    1041             : 
    1042             :         case TI_DOCTEMPLATE_DOCINFO :
    1043             :         case TI_DOCTEMPLATE_PREVIEW :
    1044             :         {
    1045           0 :             pFrameWin->ToggleView( TI_DOCTEMPLATE_DOCINFO == nAction );
    1046           0 :             break;
    1047             :         }
    1048             :     }
    1049           0 : }
    1050             : 
    1051             : // ------------------------------------------------------------------------
    1052             : 
    1053           0 : void SvtTemplateWindow::InitToolBoxes()
    1054             : {
    1055           0 :     InitToolBoxImages();
    1056             : 
    1057           0 :     Size aSize = aFileViewTB.CalcWindowSizePixel();
    1058           0 :     aSize.Height() += 4;
    1059           0 :     aFileViewTB.SetPosSizePixel( Point( 0, 2 ), aSize );
    1060           0 :     aSize = aFrameWinTB.CalcWindowSizePixel();
    1061           0 :     aSize.Height() += 4;
    1062           0 :     aFrameWinTB.SetPosSizePixel( Point( pFrameWin->GetPosPixel().X() + 2, 2 ), aSize );
    1063             : 
    1064           0 :     sal_Bool bFlat = ( SvtMiscOptions().GetToolboxStyle() == TOOLBOX_STYLE_FLAT );
    1065           0 :     if ( bFlat )
    1066             :     {
    1067           0 :         aFileViewTB.SetOutStyle( TOOLBOX_STYLE_FLAT );
    1068           0 :         aFrameWinTB.SetOutStyle( TOOLBOX_STYLE_FLAT );
    1069             :     }
    1070             : 
    1071           0 :     aFileViewTB.EnableItem( TI_DOCTEMPLATE_BACK, sal_False );
    1072           0 :     aFileViewTB.EnableItem( TI_DOCTEMPLATE_PREV, sal_False );
    1073           0 :     aFileViewTB.EnableItem( TI_DOCTEMPLATE_PRINT, sal_False );
    1074             : 
    1075           0 :     Link aLink = LINK( this, SvtTemplateWindow, ClickHdl_Impl );
    1076           0 :     aFileViewTB.SetClickHdl( aLink );
    1077           0 :     aFrameWinTB.SetClickHdl( aLink );
    1078           0 : }
    1079             : 
    1080             : // ------------------------------------------------------------------------
    1081             : 
    1082           0 : void SvtTemplateWindow::InitToolBoxImages()
    1083             : {
    1084           0 :     SvtMiscOptions aMiscOpt;
    1085           0 :     sal_Bool bLarge = aMiscOpt.AreCurrentSymbolsLarge();
    1086             : 
    1087             :     aFileViewTB.SetItemImage( TI_DOCTEMPLATE_BACK, Image( SvtResId(
    1088             :         bLarge ? IMG_SVT_DOCTEMPLATE_BACK_LARGE
    1089           0 :                : IMG_SVT_DOCTEMPLATE_BACK_SMALL ) ) );
    1090             :     aFileViewTB.SetItemImage( TI_DOCTEMPLATE_PREV, Image( SvtResId(
    1091             :         bLarge ? IMG_SVT_DOCTEMPLATE_PREV_LARGE
    1092           0 :                : IMG_SVT_DOCTEMPLATE_PREV_SMALL ) ) );
    1093             :     aFileViewTB.SetItemImage( TI_DOCTEMPLATE_PRINT, Image( SvtResId(
    1094             :         bLarge ? IMG_SVT_DOCTEMPLATE_PRINT_LARGE
    1095           0 :                : IMG_SVT_DOCTEMPLATE_PRINT_SMALL ) ) );
    1096             : 
    1097             :     aFrameWinTB.SetItemImage( TI_DOCTEMPLATE_DOCINFO, Image( SvtResId(
    1098             :         bLarge ? IMG_SVT_DOCTEMPLATE_DOCINFO_LARGE
    1099           0 :                : IMG_SVT_DOCTEMPLATE_DOCINFO_SMALL ) ) );
    1100             :     aFrameWinTB.SetItemImage( TI_DOCTEMPLATE_PREVIEW, Image( SvtResId(
    1101             :         bLarge ? IMG_SVT_DOCTEMPLATE_PREVIEW_LARGE
    1102           0 :                : IMG_SVT_DOCTEMPLATE_PREVIEW_SMALL ) ) );
    1103           0 : }
    1104             : 
    1105             : // ------------------------------------------------------------------------
    1106             : 
    1107           0 : void SvtTemplateWindow::UpdateIcons()
    1108             : {
    1109           0 :     pIconWin->UpdateIcons();
    1110           0 : }
    1111             : 
    1112             : // ------------------------------------------------------------------------
    1113             : 
    1114           0 : long SvtTemplateWindow::PreNotify( NotifyEvent& rNEvt )
    1115             : {
    1116           0 :     sal_uInt16 nType = rNEvt.GetType();
    1117           0 :     long nRet = 0;
    1118             : 
    1119           0 :     if ( EVENT_KEYINPUT == nType && rNEvt.GetKeyEvent() )
    1120             :     {
    1121           0 :         const KeyCode& rKeyCode = rNEvt.GetKeyEvent()->GetKeyCode();
    1122           0 :         sal_uInt16 nCode = rKeyCode.GetCode();
    1123             : 
    1124           0 :         if ( KEY_BACKSPACE == nCode && !rKeyCode.GetModifier() && pFileWin->HasChildPathFocus() )
    1125             :         {
    1126           0 :             DoAction( TI_DOCTEMPLATE_BACK );
    1127           0 :             nRet = 1;
    1128             :         }
    1129           0 :         else if ( pIconWin->ProcessKeyEvent( *rNEvt.GetKeyEvent() ) )
    1130             :         {
    1131           0 :             nRet = 1;
    1132             :         }
    1133             :     }
    1134             : 
    1135           0 :     return nRet ? nRet : Window::PreNotify( rNEvt );
    1136             : }
    1137             : 
    1138             : // -----------------------------------------------------------------------------
    1139             : 
    1140           0 : void SvtTemplateWindow::DataChanged( const DataChangedEvent& rDCEvt )
    1141             : {
    1142           0 :     Window::DataChanged( rDCEvt );
    1143             : 
    1144           0 :     if ( ( ( rDCEvt.GetType() == DATACHANGED_SETTINGS ) ||
    1145           0 :            ( rDCEvt.GetType() == DATACHANGED_DISPLAY ) ) &&
    1146           0 :          ( rDCEvt.GetFlags() & SETTINGS_STYLE ) )
    1147             :     {
    1148             :         // update of the background for the area left of the FileView toolbox
    1149           0 :         SetBackground( Wallpaper( GetSettings().GetStyleSettings().GetFaceColor() ) );
    1150             :         // update of the images of the IconChoiceControl
    1151           0 :         UpdateIcons();
    1152             :         // update of the toolbox images
    1153           0 :         InitToolBoxImages();
    1154             :     }
    1155           0 : }
    1156             : // ------------------------------------------------------------------------
    1157             : 
    1158           0 : void SvtTemplateWindow::Resize()
    1159             : {
    1160           0 :     long nItemSize = aSplitWin.GetItemSize( ICONWIN_ID );
    1161           0 :     long nSplitterWidth = Splitter( this, 0 ).GetSizePixel().Width();
    1162             : 
    1163           0 :     Point aPos = aFileViewTB.GetPosPixel();
    1164           0 :     aPos.X() = nItemSize + nSplitterWidth / 2;
    1165           0 :     aFileViewTB.SetPosPixel( aPos );
    1166             : 
    1167           0 :     Size aWinSize = GetOutputSizePixel();
    1168           0 :     long nWidth = aWinSize.Width() - aPos.X();
    1169             : 
    1170           0 :     nItemSize = nWidth * aSplitWin.GetItemSize( FILEWIN_ID ) / 100;
    1171           0 :     aPos.X() = pFrameWin->GetPosPixel().X() + 2;
    1172           0 :     aFrameWinTB.SetPosPixel( aPos );
    1173             : 
    1174           0 :     Size aSize = aFileViewTB.GetSizePixel();
    1175           0 :     aSize.Width() = nItemSize;
    1176           0 :     aFileViewTB.SetSizePixel( aSize );
    1177             : 
    1178           0 :     aSize = aFrameWinTB.GetSizePixel();
    1179           0 :     aSize.Width() = nWidth - nItemSize;
    1180           0 :     aFrameWinTB.SetSizePixel( aSize );
    1181             : 
    1182           0 :     long nToolBoxHeight = aSize.Height() + aFrameWinTB.GetPosPixel().Y();
    1183           0 :     aSize = aWinSize;
    1184           0 :     aSize.Height() -= nToolBoxHeight;
    1185           0 :     aSplitWin.SetPosSizePixel( Point( 0, nToolBoxHeight  ), aSize );
    1186           0 : }
    1187             : 
    1188             : // ------------------------------------------------------------------------
    1189             : 
    1190           0 : String SvtTemplateWindow::GetSelectedFile() const
    1191             : {
    1192           0 :     return pFileWin->GetSelectedFile();
    1193             : }
    1194             : 
    1195             : // ------------------------------------------------------------------------
    1196             : 
    1197           0 : sal_Bool SvtTemplateWindow::IsFileSelected() const
    1198             : {
    1199           0 :     String aURL = pFileWin->GetSelectedFile();
    1200           0 :     sal_Bool bRet = ( aURL.Len() > 0 && !::utl::UCBContentHelper::IsFolder( aURL ) );
    1201           0 :     return bRet;
    1202             : }
    1203             : 
    1204             : // ------------------------------------------------------------------------
    1205             : 
    1206           0 : void SvtTemplateWindow::OpenFile( sal_Bool bNotAsTemplate )
    1207             : {
    1208           0 :     String aURL = pFileWin->GetSelectedFile();
    1209           0 :     if ( aURL.Len() > 0 && !::utl::UCBContentHelper::IsFolder( aURL ) )
    1210           0 :         pFrameWin->OpenFile( aURL, sal_False, pFileWin->IsTemplateFolder(), !bNotAsTemplate );
    1211           0 : }
    1212             : 
    1213             : // ------------------------------------------------------------------------
    1214             : 
    1215           0 : String SvtTemplateWindow::GetFolderTitle() const
    1216             : {
    1217           0 :     String sTitle;
    1218           0 :     String sFolderURL = pFileWin->GetFolderURL();
    1219           0 :     if ( pIconWin->IsRootURL( sFolderURL ) )
    1220           0 :         sTitle = pIconWin->GetIconText( sFolderURL );
    1221             :     else
    1222           0 :         sTitle = pFileWin->GetFolderTitle();
    1223           0 :     return sTitle;
    1224             : }
    1225             : 
    1226             : // ------------------------------------------------------------------------
    1227             : 
    1228           0 : String SvtTemplateWindow::GetFolderURL() const
    1229             : {
    1230           0 :     return pFileWin->GetFolderURL();
    1231             : }
    1232             : 
    1233             : 
    1234             : // ------------------------------------------------------------------------
    1235             : 
    1236           0 : void SvtTemplateWindow::SetFocus( sal_Bool bIconWin )
    1237             : {
    1238           0 :     if ( bIconWin )
    1239           0 :         pIconWin->SetFocus();
    1240             :     else
    1241           0 :         pFileWin->SetFocus();
    1242           0 : }
    1243             : 
    1244             : // ------------------------------------------------------------------------
    1245             : 
    1246           0 : void SvtTemplateWindow::OpenTemplateRoot()
    1247             : {
    1248           0 :     pFileWin->OpenFolder( pIconWin->GetTemplateRootURL() );
    1249           0 : }
    1250             : 
    1251             : // ------------------------------------------------------------------------
    1252             : 
    1253           0 : void SvtTemplateWindow::SetPrevLevelButtonState( const String& rURL )
    1254             : {
    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           0 :     INetURLObject aObj( rURL );
    1258           0 :     sal_Int32 nCount = aObj.getSegmentCount();
    1259             :     sal_Bool bEnable =
    1260           0 :         ( nCount > 0 &&
    1261           0 :             ( !pIconWin->IsRootURL( rURL ) || rURL == pIconWin->GetMyDocumentsRootURL() ) );
    1262           0 :     aFileViewTB.EnableItem( TI_DOCTEMPLATE_PREV, bEnable );
    1263           0 : }
    1264             : 
    1265             : // ------------------------------------------------------------------------
    1266             : 
    1267           0 : void SvtTemplateWindow::ClearHistory()
    1268             : {
    1269           0 :     if( pHistoryList )
    1270             :     {
    1271           0 :         for ( size_t i = 0, n = pHistoryList->size(); i < n; ++i )
    1272           0 :             delete (*pHistoryList)[ i ];
    1273           0 :         pHistoryList->clear();
    1274             :     }
    1275           0 : }
    1276             : 
    1277             : // ------------------------------------------------------------------------
    1278             : 
    1279           0 : long SvtTemplateWindow::CalcHeight() const
    1280             : {
    1281             :     // toolbox height
    1282           0 :     long nHeight = aFileViewTB.GetSizePixel().Height();
    1283             :     // + iconwin height
    1284           0 :     nHeight += pIconWin->CalcHeight();
    1285             :     // + little offset
    1286           0 :     nHeight += 8;
    1287           0 :     return nHeight;
    1288             : }
    1289             : 
    1290             : // ------------------------------------------------------------------------
    1291             : 
    1292           0 : void SvtTemplateWindow::ReadViewSettings()
    1293             : {
    1294             :     // defaults
    1295           0 :     sal_Int32 nSelectedGroup    =   ICON_POS_TEMPLATES;
    1296           0 :     sal_Int32 nSelectedView     =   TI_DOCTEMPLATE_DOCINFO;
    1297           0 :     double nSplitRatio          =   0.5;
    1298           0 :     OUString sLastFolder;
    1299             : 
    1300           0 :     SvtViewOptions aViewSettings( E_DIALOG, VIEWSETTING_NEWFROMTEMPLATE );
    1301           0 :     if ( aViewSettings.Exists() )
    1302             :     {
    1303             :         // read the settings
    1304           0 :         Sequence< NamedValue > aSettings = aViewSettings.GetUserData( );
    1305             : 
    1306           0 :         aViewSettings.GetUserItem( VIEWSETTING_SELECTEDGROUP ) >>= nSelectedGroup;
    1307           0 :         aViewSettings.GetUserItem( VIEWSETTING_SELECTEDVIEW ) >>= nSelectedView;
    1308           0 :         aViewSettings.GetUserItem( VIEWSETTING_SPLITRATIO ) >>= nSplitRatio;
    1309           0 :         aViewSettings.GetUserItem( VIEWSETTING_LASTFOLDER ) >>= sLastFolder;
    1310             :     }
    1311             :     // normalize
    1312           0 :     if ( nSelectedGroup < ICON_POS_NEWDOC )     nSelectedGroup = ICON_POS_NEWDOC;
    1313           0 :     if ( nSelectedGroup > ICON_POS_SAMPLES )    nSelectedGroup = ICON_POS_SAMPLES;
    1314             : 
    1315           0 :     if ( ( TI_DOCTEMPLATE_DOCINFO != nSelectedView ) && ( TI_DOCTEMPLATE_PREVIEW != nSelectedView ) )
    1316           0 :         nSelectedView = TI_DOCTEMPLATE_DOCINFO;
    1317             : 
    1318           0 :     if ( nSplitRatio < 0.2 ) nSplitRatio = 0.2;
    1319           0 :     if ( nSplitRatio > 0.8 ) nSplitRatio = 0.8;
    1320             : 
    1321             :     // change our view according to the settings
    1322             : 
    1323             :     // the selected view (details or preview)
    1324           0 :     pFrameWin->ToggleView( TI_DOCTEMPLATE_DOCINFO == nSelectedView );
    1325           0 :     aFrameWinTB.CheckItem( (sal_uInt16)nSelectedView, sal_True );
    1326             : 
    1327             :     // the split ratio
    1328           0 :     sal_Int32 nSplitFileAndFrameSize = aSplitWin.GetItemSize( FILEWIN_ID ) + aSplitWin.GetItemSize( FRAMEWIN_ID );
    1329           0 :     sal_Int32 nSplitFileSize = (sal_Int32)(nSplitFileAndFrameSize * nSplitRatio);
    1330           0 :     sal_Int32 nSplitFrameSize = nSplitFileAndFrameSize - nSplitFileSize;
    1331           0 :     aSplitWin.SetItemSize( FILEWIN_ID, nSplitFileSize );
    1332           0 :     aSplitWin.SetItemSize( FRAMEWIN_ID, nSplitFrameSize );
    1333           0 :     Resize();
    1334             : 
    1335             :     // the selected folder
    1336           0 :     pIconWin->SetCursorPos( nSelectedGroup );
    1337             : 
    1338             :     // open the last folder or the selected group
    1339           0 :     if ( !sLastFolder.isEmpty() )
    1340           0 :         pFileWin->OpenFolder( sLastFolder );
    1341             :     else
    1342           0 :         IconClickHdl_Impl( NULL );
    1343           0 : }
    1344             : 
    1345             : // ------------------------------------------------------------------------
    1346             : 
    1347           0 : void SvtTemplateWindow::WriteViewSettings()
    1348             : {
    1349             :     // collect
    1350           0 :     Sequence< NamedValue > aSettings(4);
    1351             : 
    1352             :     // the selected group
    1353           0 :     aSettings[0].Name   =   VIEWSETTING_SELECTEDGROUP;
    1354           0 :     pIconWin->SetFocus();
    1355           0 :     aSettings[0].Value  <<= (sal_Int32)pIconWin->GetCursorPos( );
    1356             : 
    1357             :     // the selected view mode
    1358           0 :     aSettings[1].Name   =   VIEWSETTING_SELECTEDVIEW;
    1359           0 :     aSettings[1].Value  <<= sal_Int32( aFrameWinTB.IsItemChecked( TI_DOCTEMPLATE_DOCINFO ) ? TI_DOCTEMPLATE_DOCINFO : TI_DOCTEMPLATE_PREVIEW );
    1360             : 
    1361             :     // the split ratio
    1362           0 :     aSettings[2].Name   =   VIEWSETTING_SPLITRATIO;
    1363           0 :     sal_Int32 nSplitFileSize = aSplitWin.GetItemSize( FILEWIN_ID );
    1364           0 :     sal_Int32 nSplitFileAndFrameSize = nSplitFileSize + aSplitWin.GetItemSize( FRAMEWIN_ID );
    1365           0 :     aSettings[2].Value  <<= double( 1.0 * nSplitFileSize / nSplitFileAndFrameSize );
    1366             : 
    1367             :     // last folder
    1368           0 :     aSettings[3].Name   =   VIEWSETTING_LASTFOLDER;
    1369           0 :     aSettings[3].Value  <<= OUString( pFileWin->GetFolderURL() );
    1370             : 
    1371             :     // write
    1372           0 :     SvtViewOptions aViewSettings( E_DIALOG, VIEWSETTING_NEWFROMTEMPLATE );
    1373           0 :     aViewSettings.SetUserData( aSettings );
    1374           0 : }
    1375             : 
    1376           0 : void SvtTemplateWindow::SelectFolder(sal_Int32 nFolderPosition)
    1377             : {
    1378           0 :     pIconWin->SelectFolder(nFolderPosition);
    1379           0 : }
    1380             : 
    1381             : struct SvtTmplDlg_Impl
    1382             : {
    1383             :     SvtTemplateWindow*  pWin;
    1384             :     String              aTitle;
    1385             :     Timer               aUpdateTimer;
    1386             :     sal_Bool            bSelectNoOpen;
    1387             : 
    1388             :     uno::Reference< util::XOfficeInstallationDirectories > m_xOfficeInstDirs;
    1389             : 
    1390             : 
    1391           0 :     SvtTmplDlg_Impl( Window* pParent ) : pWin( new SvtTemplateWindow( pParent ) ) ,bSelectNoOpen( sal_False ) {}
    1392             : 
    1393           0 :     ~SvtTmplDlg_Impl() { delete pWin; }
    1394             : };
    1395             : 
    1396           0 : SvtDocumentTemplateDialog::SvtDocumentTemplateDialog( Window* pParent ) :
    1397             : 
    1398             :     ModalDialog( pParent, SvtResId( DLG_DOCTEMPLATE ) ),
    1399             : 
    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 ) ),
    1408           0 :     pImpl               ( NULL )
    1409             : {
    1410           0 :     FreeResource();
    1411           0 :     InitImpl( );
    1412           0 : }
    1413             : 
    1414             : // ------------------------------------------------------------------------
    1415             : 
    1416           0 : void SvtDocumentTemplateDialog::InitImpl( )
    1417             : {
    1418           0 :     pImpl = new SvtTmplDlg_Impl( this );
    1419           0 :     pImpl->aTitle = GetText();
    1420             : 
    1421           0 :     bool bHideLink = ( SvtExtendedSecurityOptions().GetOpenHyperlinkMode()
    1422           0 :                     == SvtExtendedSecurityOptions::OPEN_NEVER );
    1423           0 :     if ( !bHideLink )
    1424             :          {
    1425             :     aMoreTemplatesLink.SetURL( String(
    1426           0 :         RTL_CONSTASCII_USTRINGPARAM( "http://templates.libreoffice.org/" ) ) );
    1427           0 :     aMoreTemplatesLink.SetClickHdl( LINK( this, SvtDocumentTemplateDialog, OpenLinkHdl_Impl ) );
    1428             :     }
    1429             :     else
    1430           0 :        aMoreTemplatesLink.Hide();
    1431             : 
    1432           0 :     aManageBtn.SetClickHdl( LINK( this, SvtDocumentTemplateDialog, OrganizerHdl_Impl ) );
    1433             :     // Only enable the Package Button, if the service is available
    1434             :     try
    1435             :     {
    1436             :         using namespace org::freedesktop::PackageKit;
    1437           0 :         Reference< XSyncDbusSessionHelper > xSyncDbusSessionHelper(SyncDbusSessionHelper::create(comphelper::getProcessComponentContext()), UNO_QUERY);
    1438           0 :         aPackageBtn.SetClickHdl( LINK( this, SvtDocumentTemplateDialog, PackageHdl_Impl ) );
    1439           0 :         aPackageBtn.Enable(xSyncDbusSessionHelper.is());
    1440             :     }
    1441           0 :     catch (Exception & e)
    1442             :     {
    1443             :         SAL_INFO(
    1444             :             "svtools.contnr",
    1445             :             "disable Install Template Pack, caught " << e.Message);
    1446           0 :         aPackageBtn.Enable(false);
    1447             :     }
    1448           0 :     Link aLink = LINK( this, SvtDocumentTemplateDialog, OKHdl_Impl );
    1449           0 :     aEditBtn.SetClickHdl( aLink );
    1450           0 :     aOKBtn.SetClickHdl( aLink );
    1451             : 
    1452           0 :     pImpl->pWin->SetSelectHdl( LINK( this, SvtDocumentTemplateDialog, SelectHdl_Impl ) );
    1453           0 :     pImpl->pWin->SetDoubleClickHdl( LINK( this, SvtDocumentTemplateDialog, DoubleClickHdl_Impl ) );
    1454           0 :     pImpl->pWin->SetNewFolderHdl( LINK( this, SvtDocumentTemplateDialog, NewFolderHdl_Impl ) );
    1455           0 :     pImpl->pWin->SetSendFocusHdl( LINK( this, SvtDocumentTemplateDialog, SendFocusHdl_Impl ) );
    1456             : 
    1457             :     // dynamic height adjustment
    1458           0 :     long nHeight = pImpl->pWin->CalcHeight();
    1459             : 
    1460           0 :     Size aSize = GetOutputSizePixel();
    1461           0 :     Point aPos = aMoreTemplatesLink.GetPosPixel();
    1462           0 :     Size a6Size = LogicToPixel( Size( 6, 6 ), MAP_APPFONT );
    1463           0 :     if ( bHideLink )
    1464           0 :         aPos.Y() += aMoreTemplatesLink.GetSizePixel().Height();
    1465             :     else
    1466           0 :         aPos.Y() -= a6Size.Height();
    1467           0 :     long nDelta = aPos.Y() - nHeight;
    1468           0 :     aSize.Height() -= nDelta;
    1469           0 :     SetOutputSizePixel( aSize );
    1470             : 
    1471           0 :     aSize.Height() = nHeight;
    1472           0 :     aSize.Width() -= ( a6Size.Width() * 2 );
    1473           0 :     pImpl->pWin->SetPosSizePixel( Point( a6Size.Width(), 0 ), aSize );
    1474             : 
    1475           0 :     aPos = aMoreTemplatesLink.GetPosPixel();
    1476           0 :     aPos.Y() -= nDelta;
    1477           0 :     aMoreTemplatesLink.SetPosPixel( aPos );
    1478           0 :     aPos = aLine.GetPosPixel();
    1479           0 :     aPos.Y() -= nDelta;
    1480           0 :     aLine.SetPosPixel( aPos );
    1481           0 :     aPos = aManageBtn.GetPosPixel();
    1482           0 :     aPos.Y() -= nDelta;
    1483           0 :     aManageBtn.SetPosPixel( aPos );
    1484           0 :     aPos = aEditBtn.GetPosPixel();
    1485           0 :     aPos.Y() -= nDelta;
    1486           0 :     aEditBtn.SetPosPixel( aPos );
    1487           0 :     aPos = aOKBtn.GetPosPixel();
    1488           0 :     aPos.Y() -= nDelta;
    1489           0 :     aOKBtn.SetPosPixel( aPos );
    1490           0 :     aPos = aCancelBtn.GetPosPixel();
    1491           0 :     aPos.Y() -= nDelta;
    1492           0 :     aCancelBtn.SetPosPixel( aPos );
    1493           0 :     aPos = aHelpBtn.GetPosPixel();
    1494           0 :     aPos.Y() -= nDelta;
    1495           0 :     aHelpBtn.SetPosPixel( aPos );
    1496           0 :     aPos = aPackageBtn.GetPosPixel();
    1497           0 :     aPos.Y() -= nDelta;
    1498           0 :     aPackageBtn.SetPosPixel( aPos );
    1499             : 
    1500           0 :     pImpl->pWin->Show();
    1501             : 
    1502           0 :     SelectHdl_Impl( NULL );
    1503           0 :     NewFolderHdl_Impl( NULL );
    1504             : 
    1505           0 :     UpdateHdl_Impl( NULL );
    1506           0 : }
    1507             : 
    1508             : // ------------------------------------------------------------------------
    1509             : 
    1510           0 : SvtDocumentTemplateDialog::~SvtDocumentTemplateDialog()
    1511             : {
    1512           0 :     delete pImpl;
    1513           0 : }
    1514             : 
    1515             : // ------------------------------------------------------------------------
    1516             : 
    1517           0 : sal_Bool SvtDocumentTemplateDialog::CanEnableEditBtn() const
    1518             : {
    1519           0 :     sal_Bool bEnable = sal_False;
    1520             : 
    1521           0 :     OUString aFolderURL = pImpl->pWin->GetFolderURL();
    1522           0 :     if ( pImpl->pWin->IsFileSelected() && !aFolderURL.isEmpty() )
    1523             :     {
    1524           0 :         OUString aFileTargetURL = pImpl->pWin->GetSelectedFile();
    1525           0 :         bEnable = !aFileTargetURL.isEmpty();
    1526             :     }
    1527             : 
    1528           0 :     return bEnable;
    1529             : }
    1530             : 
    1531             : // ------------------------------------------------------------------------
    1532             : 
    1533           0 : IMPL_LINK_NOARG(SvtDocumentTemplateDialog , SelectHdl_Impl)
    1534             : {
    1535           0 :     aEditBtn.Enable( pImpl->pWin->IsTemplateFolderOpen() && CanEnableEditBtn() );
    1536           0 :     aOKBtn.Enable( pImpl->pWin->IsFileSelected() );
    1537           0 :     return 0;
    1538             : }
    1539             : 
    1540             : // ------------------------------------------------------------------------
    1541             : 
    1542           0 : IMPL_LINK_NOARG(SvtDocumentTemplateDialog , DoubleClickHdl_Impl)
    1543             : {
    1544           0 :     EndDialog( RET_OK );
    1545             : 
    1546           0 :     if ( !pImpl->bSelectNoOpen )
    1547           0 :         pImpl->pWin->OpenFile( !pImpl->pWin->IsTemplateFolderOpen() );
    1548           0 :     return 0;
    1549             : }
    1550             : 
    1551             : // ------------------------------------------------------------------------
    1552             : 
    1553           0 : IMPL_LINK_NOARG(SvtDocumentTemplateDialog , NewFolderHdl_Impl)
    1554             : {
    1555           0 :     String aNewTitle( pImpl->aTitle );
    1556           0 :     aNewTitle += String( " - " );
    1557           0 :     aNewTitle += pImpl->pWin->GetFolderTitle();
    1558           0 :     SetText( aNewTitle );
    1559             : 
    1560           0 :     SelectHdl_Impl( NULL );
    1561           0 :     return 0;
    1562             : }
    1563             : 
    1564             : // ------------------------------------------------------------------------
    1565             : 
    1566           0 : IMPL_LINK_NOARG(SvtDocumentTemplateDialog , SendFocusHdl_Impl)
    1567             : {
    1568           0 :     if ( pImpl->pWin->HasIconWinFocus() )
    1569           0 :         aHelpBtn.GrabFocus();
    1570             :     else
    1571             :     {
    1572           0 :         if ( aEditBtn.IsEnabled() )
    1573           0 :             aEditBtn.GrabFocus();
    1574           0 :         else if ( aOKBtn.IsEnabled() )
    1575           0 :             aOKBtn.GrabFocus();
    1576             :         else
    1577           0 :             aCancelBtn.GrabFocus();
    1578             :     }
    1579             : 
    1580           0 :     return 0;
    1581             : }
    1582             : 
    1583             : // ------------------------------------------------------------------------
    1584             : 
    1585           0 : IMPL_LINK ( SvtDocumentTemplateDialog , OKHdl_Impl, PushButton *, pBtn )
    1586             : {
    1587           0 :     if ( pImpl->pWin->IsFileSelected() )
    1588             :     {
    1589           0 :         EndDialog( RET_OK );
    1590             : 
    1591           0 :         if ( !pImpl->bSelectNoOpen )
    1592           0 :             pImpl->pWin->OpenFile( &aEditBtn == pBtn );
    1593             :     }
    1594           0 :     return 0;
    1595             : }
    1596             : 
    1597             : // ------------------------------------------------------------------------
    1598             : 
    1599           0 : IMPL_LINK_NOARG(SvtDocumentTemplateDialog , OrganizerHdl_Impl)
    1600             : {
    1601           0 :     Window* pOldDefWin = Application::GetDefDialogParent();
    1602           0 :     Application::SetDefDialogParent( this );
    1603           0 :     Reference < XDesktop2 > xDesktop = Desktop::create( ::comphelper::getProcessComponentContext() );
    1604           0 :     Reference < XFrame > xFrame( xDesktop->getActiveFrame() );
    1605           0 :     if ( !xFrame.is() )
    1606           0 :         xFrame = xDesktop;
    1607             : 
    1608           0 :     com::sun::star::util::URL aTargetURL;
    1609           0 :     aTargetURL.Complete = "slot:5540";
    1610             :     Reference< com::sun::star::util::XURLTransformer > xTrans(
    1611           0 :                 com::sun::star::util::URLTransformer::create( ::comphelper::getProcessComponentContext() ) );
    1612           0 :     xTrans->parseStrict( aTargetURL );
    1613             : 
    1614           0 :     Reference < XDispatchProvider > xProv( xFrame, UNO_QUERY );
    1615           0 :     Reference < XDispatch > xDisp;
    1616           0 :     xDisp = xProv->queryDispatch( aTargetURL, OUString(), 0 );
    1617             : 
    1618           0 :     if ( xDisp.is() )
    1619             :     {
    1620           0 :         Sequence<PropertyValue> aArgs(1);
    1621           0 :         PropertyValue* pArg = aArgs.getArray();
    1622           0 :         pArg[0].Name = "Referer";
    1623           0 :         pArg[0].Value <<= OUString("private:user");
    1624           0 :         xDisp->dispatch( aTargetURL, aArgs );
    1625             :     }
    1626             : 
    1627           0 :     Application::SetDefDialogParent( pOldDefWin );
    1628           0 :     return 0;
    1629             : }
    1630             : 
    1631             : 
    1632           0 : IMPL_LINK_NOARG(SvtDocumentTemplateDialog, PackageHdl_Impl)
    1633             : {
    1634             :     try
    1635             :     {
    1636             :         using namespace org::freedesktop::PackageKit;
    1637           0 :         Reference< XSyncDbusSessionHelper > xSyncDbusSessionHelper(SyncDbusSessionHelper::create(comphelper::getProcessComponentContext()), UNO_QUERY);
    1638           0 :         Sequence< OUString > vPackages(1);
    1639           0 :         vPackages[0] = "libreoffice-templates";
    1640           0 :         OUString sInteraction("");
    1641           0 :         xSyncDbusSessionHelper->InstallPackageNames(0, vPackages, sInteraction);
    1642             :     }
    1643           0 :     catch (Exception & e)
    1644             :     {
    1645             :         SAL_INFO(
    1646             :             "svtools.contnr",
    1647             :             "trying Install Template Pack, caught " << e.Message);
    1648             :     }
    1649           0 :     return 0;
    1650             : }
    1651             : 
    1652             : // ------------------------------------------------------------------------
    1653             : 
    1654           0 : IMPL_LINK ( SvtDocumentTemplateDialog, UpdateHdl_Impl, Timer*, _pEventSource )
    1655             : {
    1656           0 :     pImpl->pWin->SetFocus( sal_False );
    1657           0 :     Reference< XDocumentTemplates > xTemplates( frame::DocumentTemplates::create(::comphelper::getProcessComponentContext()) );
    1658           0 :     if ( _pEventSource )
    1659             :     {   // it was no direct call, which means it was triggered by the timer, which means we alread checked the necessity
    1660           0 :         WaitObject aWaitCursor( this );
    1661           0 :         xTemplates->update();
    1662           0 :         if ( pImpl->pWin->IsTemplateFolderOpen() )
    1663             :         {
    1664           0 :             pImpl->pWin->ClearHistory();
    1665           0 :             pImpl->pWin->OpenTemplateRoot();
    1666           0 :         }
    1667             :     }
    1668             :     else
    1669             :     {
    1670             :         // check if we really need to do the update
    1671           0 :         ::svt::TemplateFolderCache aCache;
    1672           0 :         if ( aCache.needsUpdate() )
    1673             :         {   // yes -> do it asynchronous (it will take a noticeable time)
    1674             : 
    1675             :             // (but first store the current state)
    1676           0 :             aCache.storeState();
    1677             : 
    1678             :             // start the timer for the async update
    1679           0 :             pImpl->aUpdateTimer.SetTimeout( 300 );
    1680           0 :             pImpl->aUpdateTimer.SetTimeoutHdl( LINK( this, SvtDocumentTemplateDialog, UpdateHdl_Impl ) );
    1681           0 :             pImpl->aUpdateTimer.Start();
    1682           0 :         }
    1683             :     }
    1684           0 :     return 0;
    1685             : }
    1686             : 
    1687             : // ------------------------------------------------------------------------
    1688             : 
    1689           0 : IMPL_LINK_NOARG(SvtDocumentTemplateDialog, OpenLinkHdl_Impl)
    1690             : {
    1691           0 :     OUString sURL( aMoreTemplatesLink.GetURL() );
    1692           0 :     if ( !sURL.isEmpty() )
    1693             :     {
    1694           0 :         localizeWebserviceURI(sURL);
    1695             :         try
    1696             :         {
    1697             :             uno::Reference< uno::XComponentContext > xContext =
    1698           0 :                 ::comphelper::getProcessComponentContext();
    1699             :             uno::Reference< com::sun::star::system::XSystemShellExecute > xSystemShell(
    1700           0 :                 com::sun::star::system::SystemShellExecute::create(xContext) );
    1701           0 :             if ( xSystemShell.is() )
    1702           0 :                 xSystemShell->execute( sURL, OUString(), com::sun::star::system::SystemShellExecuteFlags::URIS_ONLY );
    1703           0 :             EndDialog( RET_CANCEL );
    1704             :         }
    1705           0 :         catch( const uno::Exception& e )
    1706             :         {
    1707             :              OSL_TRACE( "Caught exception: %s\n thread terminated.\n",
    1708             :                 OUStringToOString(e.Message, RTL_TEXTENCODING_UTF8).getStr());
    1709             :         }
    1710             :     }
    1711           0 :     return 0;
    1712             : }
    1713             : 
    1714           0 : void SvtDocumentTemplateDialog::SelectTemplateFolder()
    1715             : {
    1716           0 :     pImpl->pWin->SelectFolder(ICON_POS_TEMPLATES);
    1717         465 : }
    1718             : 
    1719             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10