2010-10-12 15:57:08 +02:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-10-04 11:25:41 +01:00
|
|
|
/*
|
|
|
|
* This file is part of the LibreOffice project.
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*
|
|
|
|
* This file incorporates work covered by the following license notice:
|
|
|
|
*
|
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed
|
|
|
|
* with this work for additional information regarding copyright
|
|
|
|
* ownership. The ASF licenses this file to you under the Apache
|
|
|
|
* License, Version 2.0 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
|
|
|
|
*/
|
2009-10-31 00:36:06 +01:00
|
|
|
|
|
|
|
#include "cuihyperdlg.hxx"
|
|
|
|
#include <unotools/localfilehelper.hxx>
|
|
|
|
#include <sfx2/filedlghelper.hxx>
|
|
|
|
#include "com/sun/star/ui/dialogs/TemplateDescription.hpp"
|
|
|
|
|
|
|
|
#include "hldoctp.hxx"
|
|
|
|
#include "hyperdlg.hrc"
|
2010-10-01 22:50:43 +02:00
|
|
|
#include "hlmarkwn_def.hxx"
|
2009-10-31 00:36:06 +01:00
|
|
|
|
2010-12-12 09:17:59 +01:00
|
|
|
sal_Char const sHash[] = "#";
|
|
|
|
sal_Char const sFileScheme[] = INET_FILE_SCHEME;
|
|
|
|
sal_Char const sNewsSRVScheme[] = "news://";
|
2009-10-31 00:36:06 +01:00
|
|
|
// TODO news:// is nonsense
|
2010-12-12 09:17:59 +01:00
|
|
|
sal_Char const sHTTPScheme[] = INET_HTTP_SCHEME;
|
2009-10-31 00:36:06 +01:00
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
|*
|
|
|
|
|* Contructor / Destructor
|
|
|
|
|*
|
|
|
|
|************************************************************************/
|
|
|
|
|
|
|
|
SvxHyperlinkDocTp::SvxHyperlinkDocTp ( Window *pParent, const SfxItemSet& rItemSet)
|
2009-11-02 20:49:14 +01:00
|
|
|
: SvxHyperlinkTabPageBase ( pParent, CUI_RES( RID_SVXPAGE_HYPERLINK_DOCUMENT ), rItemSet ),
|
|
|
|
maGrpDocument ( this, CUI_RES (GRP_DOCUMENT) ),
|
|
|
|
maFtPath ( this, CUI_RES (FT_PATH_DOC) ),
|
2009-10-31 00:36:06 +01:00
|
|
|
maCbbPath ( this, INET_PROT_FILE ),
|
2009-11-02 20:49:14 +01:00
|
|
|
maBtFileopen ( this, CUI_RES (BTN_FILEOPEN) ),
|
|
|
|
maGrpTarget ( this, CUI_RES (GRP_TARGET) ),
|
|
|
|
maFtTarget ( this, CUI_RES (FT_TARGET_DOC) ),
|
|
|
|
maEdTarget ( this, CUI_RES (ED_TARGET_DOC) ),
|
|
|
|
maFtURL ( this, CUI_RES (FT_URL) ),
|
|
|
|
maFtFullURL ( this, CUI_RES (FT_FULL_URL) ),
|
|
|
|
maBtBrowse ( this, CUI_RES (BTN_BROWSE) ),
|
2011-01-14 12:41:27 +01:00
|
|
|
mbMarkWndOpen ( sal_False )
|
2009-10-31 00:36:06 +01:00
|
|
|
{
|
2010-11-13 00:33:43 -08:00
|
|
|
// Disable display of bitmap names.
|
2011-01-14 12:41:27 +01:00
|
|
|
maBtBrowse.EnableTextDisplay (sal_False);
|
|
|
|
maBtFileopen.EnableTextDisplay (sal_False);
|
2009-10-31 00:36:06 +01:00
|
|
|
|
|
|
|
InitStdControls();
|
|
|
|
FreeResource();
|
|
|
|
|
|
|
|
// Init URL-Box (pos&size, Open-Handler)
|
|
|
|
maCbbPath.SetPosSizePixel ( LogicToPixel( Point( COL_2, 15 ), MAP_APPFONT ),
|
|
|
|
LogicToPixel( Size ( 176 - COL_DIFF, 60), MAP_APPFONT ) );
|
|
|
|
maCbbPath.Show();
|
|
|
|
String aFileScheme( INET_FILE_SCHEME, RTL_TEXTENCODING_ASCII_US );
|
|
|
|
maCbbPath.SetBaseURL(aFileScheme);
|
|
|
|
maCbbPath.SetHelpId( HID_HYPERDLG_DOC_PATH );
|
|
|
|
|
|
|
|
SetExchangeSupport ();
|
|
|
|
|
|
|
|
// overload handlers
|
|
|
|
maBtFileopen.SetClickHdl ( LINK ( this, SvxHyperlinkDocTp, ClickFileopenHdl_Impl ) );
|
|
|
|
maBtBrowse.SetClickHdl ( LINK ( this, SvxHyperlinkDocTp, ClickTargetHdl_Impl ) );
|
|
|
|
maCbbPath.SetModifyHdl ( LINK ( this, SvxHyperlinkDocTp, ModifiedPathHdl_Impl ) );
|
|
|
|
maEdTarget.SetModifyHdl ( LINK ( this, SvxHyperlinkDocTp, ModifiedTargetHdl_Impl ) );
|
|
|
|
|
|
|
|
maCbbPath.SetLoseFocusHdl( LINK ( this, SvxHyperlinkDocTp, LostFocusPathHdl_Impl ) );
|
|
|
|
|
2011-01-20 12:21:31 +01:00
|
|
|
maBtBrowse.SetAccessibleRelationMemberOf( &maGrpTarget );
|
|
|
|
maBtBrowse.SetAccessibleRelationLabeledBy( &maFtTarget );
|
|
|
|
maBtFileopen.SetAccessibleRelationMemberOf( &maGrpDocument );
|
|
|
|
maBtFileopen.SetAccessibleRelationLabeledBy( &maFtPath );
|
2009-10-31 00:36:06 +01:00
|
|
|
maTimer.SetTimeoutHdl ( LINK ( this, SvxHyperlinkDocTp, TimeoutHdl_Impl ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
SvxHyperlinkDocTp::~SvxHyperlinkDocTp ()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
|*
|
|
|
|
|* Fill all dialog-controls except controls in groupbox "more..."
|
|
|
|
|*
|
|
|
|
|************************************************************************/
|
|
|
|
|
|
|
|
void SvxHyperlinkDocTp::FillDlgFields ( String& aStrURL )
|
|
|
|
{
|
|
|
|
INetURLObject aURL ( aStrURL );
|
|
|
|
|
|
|
|
String aStrMark;
|
|
|
|
xub_StrLen nPos = aStrURL.SearchAscii( sHash );
|
|
|
|
// path
|
|
|
|
maCbbPath.SetText ( aStrURL.Copy( 0, ( nPos == STRING_NOTFOUND ? aStrURL.Len() : nPos ) ) );
|
|
|
|
|
|
|
|
// set target in document at editfield
|
|
|
|
if ( nPos != STRING_NOTFOUND && nPos<aStrURL.Len()-1 )
|
|
|
|
aStrMark = aStrURL.Copy( nPos+1, aStrURL.Len() );
|
|
|
|
maEdTarget.SetText ( aStrMark );
|
|
|
|
|
|
|
|
ModifiedPathHdl_Impl ( NULL );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
|*
|
|
|
|
|* retrieve current url-string
|
|
|
|
|*
|
|
|
|
|************************************************************************/
|
|
|
|
|
|
|
|
String SvxHyperlinkDocTp::GetCurrentURL ()
|
|
|
|
{
|
|
|
|
// get data from dialog-controls
|
2013-03-19 23:07:53 +01:00
|
|
|
OUString aStrURL;
|
2009-10-31 00:36:06 +01:00
|
|
|
String aStrPath ( maCbbPath.GetText() );
|
|
|
|
const String aBaseURL ( maCbbPath.GetBaseURL() );
|
|
|
|
String aStrMark( maEdTarget.GetText() );
|
|
|
|
|
|
|
|
if ( aStrPath != aEmptyStr )
|
|
|
|
{
|
|
|
|
INetURLObject aURL( aStrPath );
|
|
|
|
if ( aURL.GetProtocol() != INET_PROT_NOT_VALID ) // maybe the path is already a valid
|
|
|
|
aStrURL = aStrPath; // hyperlink, then we can use this path directly
|
|
|
|
else
|
|
|
|
utl::LocalFileHelper::ConvertSystemPathToURL( aStrPath, aBaseURL, aStrURL );
|
|
|
|
|
|
|
|
//#105788# always create a URL even if it is not valid
|
|
|
|
if( aStrURL == aEmptyStr )
|
|
|
|
aStrURL = aStrPath;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( aStrMark != aEmptyStr )
|
|
|
|
{
|
2013-03-19 23:07:53 +01:00
|
|
|
aStrURL += OUString( sHash );
|
2009-10-31 00:36:06 +01:00
|
|
|
aStrURL += aStrMark;
|
|
|
|
}
|
|
|
|
|
|
|
|
return aStrURL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
|*
|
|
|
|
|* retrieve and prepare data from dialog-fields
|
|
|
|
|*
|
|
|
|
|************************************************************************/
|
|
|
|
|
|
|
|
void SvxHyperlinkDocTp::GetCurentItemData ( String& aStrURL, String& aStrName,
|
|
|
|
String& aStrIntName, String& aStrFrame,
|
|
|
|
SvxLinkInsertMode& eMode )
|
|
|
|
{
|
|
|
|
// get data from standard-fields
|
|
|
|
aStrURL = GetCurrentURL();
|
|
|
|
|
2010-01-19 12:49:10 +01:00
|
|
|
if( aStrURL.EqualsIgnoreCaseAscii( sFileScheme ) )
|
2009-10-31 00:36:06 +01:00
|
|
|
aStrURL=aEmptyStr;
|
|
|
|
|
|
|
|
GetDataFromCommonFields( aStrName, aStrIntName, aStrFrame, eMode );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
|*
|
|
|
|
|* static method to create Tabpage
|
|
|
|
|*
|
|
|
|
|************************************************************************/
|
|
|
|
|
|
|
|
IconChoicePage* SvxHyperlinkDocTp::Create( Window* pWindow, const SfxItemSet& rItemSet )
|
|
|
|
{
|
|
|
|
return( new SvxHyperlinkDocTp( pWindow, rItemSet ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
|*
|
|
|
|
|* Set initial focus
|
|
|
|
|*
|
|
|
|
|************************************************************************/
|
|
|
|
|
|
|
|
void SvxHyperlinkDocTp::SetInitFocus()
|
|
|
|
{
|
|
|
|
maCbbPath.GrabFocus();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
|*
|
|
|
|
|* Click on imagebutton : fileopen
|
|
|
|
|*
|
|
|
|
|************************************************************************/
|
|
|
|
|
2012-03-01 18:00:32 +01:00
|
|
|
IMPL_LINK_NOARG(SvxHyperlinkDocTp, ClickFileopenHdl_Impl)
|
2009-10-31 00:36:06 +01:00
|
|
|
{
|
|
|
|
// Open Fileopen-Dialog
|
|
|
|
::sfx2::FileDialogHelper aDlg(
|
|
|
|
com::sun::star::ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE, 0,
|
|
|
|
GetParent() );
|
|
|
|
String aOldURL( GetCurrentURL() );
|
2010-01-19 12:49:10 +01:00
|
|
|
if( aOldURL.EqualsIgnoreCaseAscii( sFileScheme, 0, sizeof( sFileScheme ) - 1 ) )
|
2009-10-31 00:36:06 +01:00
|
|
|
{
|
|
|
|
aDlg.SetDisplayDirectory( aOldURL );
|
|
|
|
}
|
|
|
|
|
|
|
|
DisableClose( sal_True );
|
|
|
|
ErrCode nError = aDlg.Execute();
|
|
|
|
DisableClose( sal_False );
|
|
|
|
|
|
|
|
if ( ERRCODE_NONE == nError )
|
|
|
|
{
|
|
|
|
String aURL( aDlg.GetPath() );
|
2013-03-19 23:07:53 +01:00
|
|
|
OUString aPath;
|
2009-10-31 00:36:06 +01:00
|
|
|
|
|
|
|
utl::LocalFileHelper::ConvertURLToSystemPath( aURL, aPath );
|
|
|
|
|
|
|
|
maCbbPath.SetBaseURL( aURL );
|
|
|
|
maCbbPath.SetText( aPath );
|
|
|
|
|
|
|
|
if ( aOldURL != GetCurrentURL() )
|
|
|
|
ModifiedPathHdl_Impl (NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
return( 0L );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
|*
|
|
|
|
|* Click on imagebutton : target
|
|
|
|
|*
|
|
|
|
|************************************************************************/
|
|
|
|
|
2012-03-01 18:00:32 +01:00
|
|
|
IMPL_LINK_NOARG(SvxHyperlinkDocTp, ClickTargetHdl_Impl)
|
2009-10-31 00:36:06 +01:00
|
|
|
{
|
|
|
|
if ( GetPathType ( maStrURL ) == Type_ExistsFile ||
|
|
|
|
maStrURL == aEmptyStr ||
|
|
|
|
maStrURL.EqualsIgnoreCaseAscii( sFileScheme ) ||
|
|
|
|
maStrURL.SearchAscii( sHash ) == 0 )
|
|
|
|
{
|
|
|
|
mpMarkWnd->SetError( LERR_NOERROR );
|
|
|
|
|
|
|
|
EnterWait();
|
|
|
|
|
2010-01-19 12:49:10 +01:00
|
|
|
if ( maStrURL.EqualsIgnoreCaseAscii( sFileScheme ) )
|
2009-10-31 00:36:06 +01:00
|
|
|
mpMarkWnd->RefreshTree ( aEmptyStr );
|
|
|
|
else
|
|
|
|
mpMarkWnd->RefreshTree ( maStrURL );
|
|
|
|
|
|
|
|
LeaveWait();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
mpMarkWnd->SetError( LERR_DOCNOTOPEN );
|
|
|
|
|
|
|
|
ShowMarkWnd ();
|
|
|
|
|
|
|
|
return( 0L );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
|*
|
|
|
|
|* Contens of combobox "Path" modified
|
|
|
|
|*
|
|
|
|
|************************************************************************/
|
|
|
|
|
2012-03-01 18:00:32 +01:00
|
|
|
IMPL_LINK_NOARG(SvxHyperlinkDocTp, ModifiedPathHdl_Impl)
|
2009-10-31 00:36:06 +01:00
|
|
|
{
|
|
|
|
maStrURL = GetCurrentURL();
|
|
|
|
|
|
|
|
maTimer.SetTimeout( 2500 );
|
|
|
|
maTimer.Start();
|
|
|
|
|
|
|
|
maFtFullURL.SetText( maStrURL );
|
|
|
|
|
|
|
|
return( 0L );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
|*
|
|
|
|
|* If path-field was modify, to browse the new doc after timeout
|
|
|
|
|*
|
|
|
|
|************************************************************************/
|
|
|
|
|
2012-03-01 18:00:32 +01:00
|
|
|
IMPL_LINK_NOARG(SvxHyperlinkDocTp, TimeoutHdl_Impl)
|
2009-10-31 00:36:06 +01:00
|
|
|
{
|
|
|
|
if ( IsMarkWndVisible() && ( GetPathType( maStrURL )==Type_ExistsFile ||
|
|
|
|
maStrURL == aEmptyStr ||
|
|
|
|
maStrURL.EqualsIgnoreCaseAscii( sFileScheme ) ) )
|
|
|
|
{
|
|
|
|
EnterWait();
|
|
|
|
|
2010-01-19 12:49:10 +01:00
|
|
|
if ( maStrURL.EqualsIgnoreCaseAscii( sFileScheme ) )
|
2009-10-31 00:36:06 +01:00
|
|
|
mpMarkWnd->RefreshTree ( aEmptyStr );
|
|
|
|
else
|
|
|
|
mpMarkWnd->RefreshTree ( maStrURL );
|
|
|
|
|
|
|
|
LeaveWait();
|
|
|
|
}
|
|
|
|
|
|
|
|
return( 0L );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
|*
|
|
|
|
|* Contens of editfield "Target" modified
|
|
|
|
|*
|
|
|
|
|************************************************************************/
|
|
|
|
|
2012-03-01 18:00:32 +01:00
|
|
|
IMPL_LINK_NOARG(SvxHyperlinkDocTp, ModifiedTargetHdl_Impl)
|
2009-10-31 00:36:06 +01:00
|
|
|
{
|
|
|
|
maStrURL = GetCurrentURL();
|
|
|
|
|
|
|
|
if ( IsMarkWndVisible() )
|
|
|
|
mpMarkWnd->SelectEntry ( maEdTarget.GetText() );
|
|
|
|
|
|
|
|
maFtFullURL.SetText( maStrURL );
|
|
|
|
|
|
|
|
return( 0L );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
|*
|
|
|
|
|* editfield "Target" lost focus
|
|
|
|
|*
|
|
|
|
|************************************************************************/
|
|
|
|
|
2012-03-01 18:00:32 +01:00
|
|
|
IMPL_LINK_NOARG(SvxHyperlinkDocTp, LostFocusPathHdl_Impl)
|
2009-10-31 00:36:06 +01:00
|
|
|
{
|
|
|
|
maStrURL = GetCurrentURL();
|
|
|
|
|
|
|
|
maFtFullURL.SetText( maStrURL );
|
|
|
|
|
|
|
|
return (0L);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
|*
|
|
|
|
|* Get String from Bookmark-Wnd
|
|
|
|
|*
|
|
|
|
|************************************************************************/
|
|
|
|
|
2013-07-31 16:11:55 +01:00
|
|
|
void SvxHyperlinkDocTp::SetMarkStr ( const String& aStrMark )
|
2009-10-31 00:36:06 +01:00
|
|
|
{
|
|
|
|
maEdTarget.SetText ( aStrMark );
|
|
|
|
|
|
|
|
ModifiedTargetHdl_Impl ( NULL );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
|*
|
|
|
|
|* retrieve kind of pathstr
|
|
|
|
|*
|
|
|
|
|************************************************************************/
|
|
|
|
|
|
|
|
SvxHyperlinkDocTp::EPathType SvxHyperlinkDocTp::GetPathType ( String& aStrPath )
|
|
|
|
{
|
|
|
|
INetURLObject aURL( aStrPath, INET_PROT_FILE );
|
|
|
|
|
|
|
|
if( aURL.HasError() )
|
|
|
|
return Type_Invalid;
|
|
|
|
else
|
|
|
|
return Type_ExistsFile;
|
|
|
|
}
|
2010-10-12 15:57:08 +02:00
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|