LCOV - code coverage report
Current view: top level - libreoffice/cui/source/dialogs - hldoctp.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 1 140 0.7 %
Date: 2012-12-17 Functions: 2 24 8.3 %
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 "cuihyperdlg.hxx"
      21             : #include <unotools/localfilehelper.hxx>
      22             : #include <sfx2/filedlghelper.hxx>
      23             : #include "com/sun/star/ui/dialogs/TemplateDescription.hpp"
      24             : 
      25             : #include "hldoctp.hxx"
      26             : #include "hyperdlg.hrc"
      27             : #include "hlmarkwn_def.hxx"
      28             : 
      29             : sal_Char const sHash[]              = "#";
      30             : sal_Char const sFileScheme[]            = INET_FILE_SCHEME;
      31             : sal_Char const sNewsSRVScheme[] = "news://";
      32             :     // TODO news:// is nonsense
      33             : sal_Char const sHTTPScheme[]    = INET_HTTP_SCHEME;
      34             : 
      35             : /*************************************************************************
      36             : |*
      37             : |* Contructor / Destructor
      38             : |*
      39             : |************************************************************************/
      40             : 
      41           0 : SvxHyperlinkDocTp::SvxHyperlinkDocTp ( Window *pParent, const SfxItemSet& rItemSet)
      42           0 :     : SvxHyperlinkTabPageBase ( pParent, CUI_RES( RID_SVXPAGE_HYPERLINK_DOCUMENT ), rItemSet ),
      43           0 :     maGrpDocument   ( this, CUI_RES (GRP_DOCUMENT) ),
      44           0 :     maFtPath        ( this, CUI_RES (FT_PATH_DOC) ),
      45             :     maCbbPath       ( this, INET_PROT_FILE ),
      46           0 :     maBtFileopen    ( this, CUI_RES (BTN_FILEOPEN) ),
      47           0 :     maGrpTarget     ( this, CUI_RES (GRP_TARGET) ),
      48           0 :     maFtTarget      ( this, CUI_RES (FT_TARGET_DOC) ),
      49           0 :     maEdTarget      ( this, CUI_RES (ED_TARGET_DOC) ),
      50           0 :     maFtURL         ( this, CUI_RES (FT_URL) ),
      51           0 :     maFtFullURL     ( this, CUI_RES (FT_FULL_URL) ),
      52           0 :     maBtBrowse      ( this, CUI_RES (BTN_BROWSE) ),
      53           0 :     mbMarkWndOpen   ( sal_False )
      54             : {
      55             :     // Disable display of bitmap names.
      56           0 :     maBtBrowse.EnableTextDisplay (sal_False);
      57           0 :     maBtFileopen.EnableTextDisplay (sal_False);
      58             : 
      59           0 :     InitStdControls();
      60           0 :     FreeResource();
      61             : 
      62             :     // Init URL-Box (pos&size, Open-Handler)
      63           0 :     maCbbPath.SetPosSizePixel ( LogicToPixel( Point( COL_2, 15 ), MAP_APPFONT ),
      64           0 :                                 LogicToPixel( Size ( 176 - COL_DIFF, 60), MAP_APPFONT ) );
      65           0 :     maCbbPath.Show();
      66           0 :     String aFileScheme( INET_FILE_SCHEME, RTL_TEXTENCODING_ASCII_US );
      67           0 :     maCbbPath.SetBaseURL(aFileScheme);
      68           0 :     maCbbPath.SetHelpId( HID_HYPERDLG_DOC_PATH );
      69             : 
      70           0 :     SetExchangeSupport ();
      71             : 
      72             :     // overload handlers
      73           0 :     maBtFileopen.SetClickHdl ( LINK ( this, SvxHyperlinkDocTp, ClickFileopenHdl_Impl ) );
      74           0 :     maBtBrowse.SetClickHdl   ( LINK ( this, SvxHyperlinkDocTp, ClickTargetHdl_Impl ) );
      75           0 :     maCbbPath.SetModifyHdl   ( LINK ( this, SvxHyperlinkDocTp, ModifiedPathHdl_Impl ) );
      76           0 :     maEdTarget.SetModifyHdl  ( LINK ( this, SvxHyperlinkDocTp, ModifiedTargetHdl_Impl ) );
      77             : 
      78           0 :     maCbbPath.SetLoseFocusHdl( LINK ( this, SvxHyperlinkDocTp, LostFocusPathHdl_Impl ) );
      79             : 
      80           0 :     maBtBrowse.SetAccessibleRelationMemberOf( &maGrpTarget );
      81           0 :     maBtBrowse.SetAccessibleRelationLabeledBy( &maFtTarget );
      82           0 :     maBtFileopen.SetAccessibleRelationMemberOf( &maGrpDocument );
      83           0 :     maBtFileopen.SetAccessibleRelationLabeledBy( &maFtPath );
      84           0 :     maTimer.SetTimeoutHdl ( LINK ( this, SvxHyperlinkDocTp, TimeoutHdl_Impl ) );
      85           0 : }
      86             : 
      87           0 : SvxHyperlinkDocTp::~SvxHyperlinkDocTp ()
      88             : {
      89           0 : }
      90             : 
      91             : /*************************************************************************
      92             : |*
      93             : |* Fill all dialog-controls except controls in groupbox "more..."
      94             : |*
      95             : |************************************************************************/
      96             : 
      97           0 : void SvxHyperlinkDocTp::FillDlgFields ( String& aStrURL )
      98             : {
      99           0 :     INetURLObject aURL ( aStrURL );
     100             : 
     101           0 :     String aStrMark;
     102           0 :     xub_StrLen nPos = aStrURL.SearchAscii( sHash );
     103             :     // path
     104           0 :     maCbbPath.SetText ( aStrURL.Copy( 0, ( nPos == STRING_NOTFOUND ? aStrURL.Len() : nPos ) ) );
     105             : 
     106             :     // set target in document at editfield
     107           0 :     if ( nPos != STRING_NOTFOUND && nPos<aStrURL.Len()-1 )
     108           0 :         aStrMark = aStrURL.Copy( nPos+1, aStrURL.Len() );
     109           0 :      maEdTarget.SetText ( aStrMark );
     110             : 
     111           0 :     ModifiedPathHdl_Impl ( NULL );
     112           0 : }
     113             : 
     114             : /*************************************************************************
     115             : |*
     116             : |* retrieve current url-string
     117             : |*
     118             : |************************************************************************/
     119             : 
     120           0 : String SvxHyperlinkDocTp::GetCurrentURL ()
     121             : {
     122             :     // get data from dialog-controls
     123           0 :     String aStrURL;
     124           0 :     String aStrPath ( maCbbPath.GetText() );
     125           0 :     const String aBaseURL ( maCbbPath.GetBaseURL() );
     126           0 :     String aStrMark( maEdTarget.GetText() );
     127             : 
     128           0 :     if ( aStrPath != aEmptyStr )
     129             :     {
     130           0 :         INetURLObject aURL( aStrPath );
     131           0 :         if ( aURL.GetProtocol() != INET_PROT_NOT_VALID )    // maybe the path is already a valid
     132           0 :             aStrURL = aStrPath;                             // hyperlink, then we can use this path directly
     133             :         else
     134           0 :             utl::LocalFileHelper::ConvertSystemPathToURL( aStrPath, aBaseURL, aStrURL );
     135             : 
     136             :         //#105788# always create a URL even if it is not valid
     137           0 :         if( aStrURL == aEmptyStr )
     138           0 :             aStrURL = aStrPath;
     139             :     }
     140             : 
     141           0 :     if( aStrMark != aEmptyStr )
     142             :     {
     143           0 :         aStrURL.AppendAscii( sHash );
     144           0 :         aStrURL += aStrMark;
     145             :     }
     146             : 
     147           0 :     return aStrURL;
     148             : }
     149             : 
     150             : /*************************************************************************
     151             : |*
     152             : |* retrieve and prepare data from dialog-fields
     153             : |*
     154             : |************************************************************************/
     155             : 
     156           0 : void SvxHyperlinkDocTp::GetCurentItemData ( String& aStrURL, String& aStrName,
     157             :                                             String& aStrIntName, String& aStrFrame,
     158             :                                             SvxLinkInsertMode& eMode )
     159             : {
     160             :     // get data from standard-fields
     161           0 :     aStrURL = GetCurrentURL();
     162             : 
     163           0 :     if( aStrURL.EqualsIgnoreCaseAscii( sFileScheme ) )
     164           0 :          aStrURL=aEmptyStr;
     165             : 
     166           0 :     GetDataFromCommonFields( aStrName, aStrIntName, aStrFrame, eMode );
     167           0 : }
     168             : 
     169             : /*************************************************************************
     170             : |*
     171             : |* static method to create Tabpage
     172             : |*
     173             : |************************************************************************/
     174             : 
     175           0 : IconChoicePage* SvxHyperlinkDocTp::Create( Window* pWindow, const SfxItemSet& rItemSet )
     176             : {
     177           0 :     return( new SvxHyperlinkDocTp( pWindow, rItemSet ) );
     178             : }
     179             : 
     180             : /*************************************************************************
     181             : |*
     182             : |* Set initial focus
     183             : |*
     184             : |************************************************************************/
     185             : 
     186           0 : void SvxHyperlinkDocTp::SetInitFocus()
     187             : {
     188           0 :     maCbbPath.GrabFocus();
     189           0 : }
     190             : 
     191             : /*************************************************************************
     192             : |*
     193             : |* Click on imagebutton : fileopen
     194             : |*
     195             : |************************************************************************/
     196             : 
     197           0 : IMPL_LINK_NOARG(SvxHyperlinkDocTp, ClickFileopenHdl_Impl)
     198             : {
     199             :     // Open Fileopen-Dialog
     200             :        ::sfx2::FileDialogHelper aDlg(
     201             :         com::sun::star::ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE, 0,
     202           0 :         GetParent() );
     203           0 :     String aOldURL( GetCurrentURL() );
     204           0 :     if( aOldURL.EqualsIgnoreCaseAscii( sFileScheme, 0, sizeof( sFileScheme ) - 1 ) )
     205             :     {
     206           0 :         aDlg.SetDisplayDirectory( aOldURL );
     207             :     }
     208             : 
     209           0 :     DisableClose( sal_True );
     210           0 :     ErrCode nError = aDlg.Execute();
     211           0 :     DisableClose( sal_False );
     212             : 
     213           0 :     if ( ERRCODE_NONE == nError )
     214             :     {
     215           0 :         String aURL( aDlg.GetPath() );
     216           0 :         String aPath;
     217             : 
     218           0 :         utl::LocalFileHelper::ConvertURLToSystemPath( aURL, aPath );
     219             : 
     220           0 :         maCbbPath.SetBaseURL( aURL );
     221           0 :         maCbbPath.SetText( aPath );
     222             : 
     223           0 :         if ( aOldURL != GetCurrentURL() )
     224           0 :             ModifiedPathHdl_Impl (NULL);
     225             :     }
     226             : 
     227           0 :     return( 0L );
     228             : }
     229             : 
     230             : /*************************************************************************
     231             : |*
     232             : |* Click on imagebutton : target
     233             : |*
     234             : |************************************************************************/
     235             : 
     236           0 : IMPL_LINK_NOARG(SvxHyperlinkDocTp, ClickTargetHdl_Impl)
     237             : {
     238           0 :     if ( GetPathType ( maStrURL ) == Type_ExistsFile  ||
     239           0 :          maStrURL == aEmptyStr                        ||
     240           0 :          maStrURL.EqualsIgnoreCaseAscii( sFileScheme ) ||
     241           0 :          maStrURL.SearchAscii( sHash ) == 0 )
     242             :     {
     243           0 :         mpMarkWnd->SetError( LERR_NOERROR );
     244             : 
     245           0 :         EnterWait();
     246             : 
     247           0 :         if ( maStrURL.EqualsIgnoreCaseAscii( sFileScheme ) )
     248           0 :             mpMarkWnd->RefreshTree ( aEmptyStr );
     249             :         else
     250           0 :             mpMarkWnd->RefreshTree ( maStrURL );
     251             : 
     252           0 :         LeaveWait();
     253             :     }
     254             :     else
     255           0 :         mpMarkWnd->SetError( LERR_DOCNOTOPEN );
     256             : 
     257           0 :     ShowMarkWnd ();
     258             : 
     259           0 :     return( 0L );
     260             : }
     261             : 
     262             : /*************************************************************************
     263             : |*
     264             : |* Contens of combobox "Path" modified
     265             : |*
     266             : |************************************************************************/
     267             : 
     268           0 : IMPL_LINK_NOARG(SvxHyperlinkDocTp, ModifiedPathHdl_Impl)
     269             : {
     270           0 :     maStrURL = GetCurrentURL();
     271             : 
     272           0 :     maTimer.SetTimeout( 2500 );
     273           0 :     maTimer.Start();
     274             : 
     275           0 :     maFtFullURL.SetText( maStrURL );
     276             : 
     277           0 :     return( 0L );
     278             : }
     279             : 
     280             : /*************************************************************************
     281             : |*
     282             : |* If path-field was modify, to browse the new doc after timeout
     283             : |*
     284             : |************************************************************************/
     285             : 
     286           0 : IMPL_LINK_NOARG(SvxHyperlinkDocTp, TimeoutHdl_Impl)
     287             : {
     288           0 :     if ( IsMarkWndVisible() && ( GetPathType( maStrURL )==Type_ExistsFile ||
     289           0 :                                   maStrURL == aEmptyStr                   ||
     290           0 :                                   maStrURL.EqualsIgnoreCaseAscii( sFileScheme ) ) )
     291             :     {
     292           0 :         EnterWait();
     293             : 
     294           0 :         if ( maStrURL.EqualsIgnoreCaseAscii( sFileScheme ) )
     295           0 :             mpMarkWnd->RefreshTree ( aEmptyStr );
     296             :         else
     297           0 :             mpMarkWnd->RefreshTree ( maStrURL );
     298             : 
     299           0 :         LeaveWait();
     300             :     }
     301             : 
     302           0 :     return( 0L );
     303             : }
     304             : 
     305             : /*************************************************************************
     306             : |*
     307             : |* Contens of editfield "Target" modified
     308             : |*
     309             : |************************************************************************/
     310             : 
     311           0 : IMPL_LINK_NOARG(SvxHyperlinkDocTp, ModifiedTargetHdl_Impl)
     312             : {
     313           0 :     maStrURL = GetCurrentURL();
     314             : 
     315           0 :     if ( IsMarkWndVisible() )
     316           0 :         mpMarkWnd->SelectEntry ( maEdTarget.GetText() );
     317             : 
     318           0 :     maFtFullURL.SetText( maStrURL );
     319             : 
     320           0 :     return( 0L );
     321             : }
     322             : 
     323             : /*************************************************************************
     324             : |*
     325             : |* editfield "Target" lost focus
     326             : |*
     327             : |************************************************************************/
     328             : 
     329           0 : IMPL_LINK_NOARG(SvxHyperlinkDocTp, LostFocusPathHdl_Impl)
     330             : {
     331           0 :     maStrURL = GetCurrentURL();
     332             : 
     333           0 :     maFtFullURL.SetText( maStrURL );
     334             : 
     335           0 :     return (0L);
     336             : }
     337             : 
     338             : /*************************************************************************
     339             : |*
     340             : |* Get String from Bookmark-Wnd
     341             : |*
     342             : |************************************************************************/
     343             : 
     344           0 : void SvxHyperlinkDocTp::SetMarkStr ( String& aStrMark )
     345             : {
     346           0 :     maEdTarget.SetText ( aStrMark );
     347             : 
     348           0 :     ModifiedTargetHdl_Impl ( NULL );
     349           0 : }
     350             : 
     351             : /*************************************************************************
     352             : |*
     353             : |* retrieve kind of pathstr
     354             : |*
     355             : |************************************************************************/
     356             : 
     357           0 : SvxHyperlinkDocTp::EPathType SvxHyperlinkDocTp::GetPathType ( String& aStrPath )
     358             : {
     359           0 :     INetURLObject aURL( aStrPath, INET_PROT_FILE );
     360             : 
     361           0 :     if( aURL.HasError() )
     362           0 :         return Type_Invalid;
     363             :     else
     364           0 :         return Type_ExistsFile;
     365           6 : }
     366             : 
     367             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10