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

Generated by: LCOV version 1.10