LCOV - code coverage report
Current view: top level - cui/source/dialogs - hldoctp.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 139 0.0 %
Date: 2012-08-25 Functions: 0 22 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 298 0.0 %

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

Generated by: LCOV version 1.10