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

Generated by: LCOV version 1.10