1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "cuihyperdlg.hxx"
21 #include <unotools/localfilehelper.hxx>
22 #include <sfx2/filedlghelper.hxx>
23 #include "com/sun/star/ui/dialogs/TemplateDescription.hpp"
25 #include "hldoctp.hxx"
26 #include "hlmarkwn_def.hxx"
28 sal_Char
const sHash
[] = "#";
29 sal_Char
const sFileScheme
[] = INET_FILE_SCHEME
;
31 /*************************************************************************
33 |* Constructor / Destructor
35 |************************************************************************/
37 SvxHyperlinkDocTp::SvxHyperlinkDocTp ( vcl::Window
*pParent
, IconChoiceDialog
* pDlg
, const SfxItemSet
& rItemSet
)
38 : SvxHyperlinkTabPageBase ( pParent
, pDlg
, "HyperlinkDocPage", "cui/ui/hyperlinkdocpage.ui", rItemSet
),
39 mbMarkWndOpen ( false )
41 get(m_pCbbPath
, "path");
42 m_pCbbPath
->SetSmartProtocol(INetProtocol::File
);
43 get(m_pBtFileopen
, "fileopen");
44 m_pBtFileopen
->SetModeImage(Image(CUI_RES(RID_SVXBMP_FILEOPEN
)));
45 get(m_pEdTarget
, "target");
46 get(m_pFtFullURL
, "url");
47 get(m_pBtBrowse
, "browse");
48 m_pBtBrowse
->SetModeImage(Image(CUI_RES(RID_SVXBMP_TARGET
)));
50 // Disable display of bitmap names.
51 m_pBtBrowse
->EnableTextDisplay (false);
52 m_pBtFileopen
->EnableTextDisplay (false);
57 OUString
aFileScheme( INET_FILE_SCHEME
);
58 m_pCbbPath
->SetBaseURL(aFileScheme
);
59 m_pCbbPath
->SetHelpId( HID_HYPERDLG_DOC_PATH
);
61 SetExchangeSupport ();
64 m_pBtFileopen
->SetClickHdl ( LINK ( this, SvxHyperlinkDocTp
, ClickFileopenHdl_Impl
) );
65 m_pBtBrowse
->SetClickHdl ( LINK ( this, SvxHyperlinkDocTp
, ClickTargetHdl_Impl
) );
66 m_pCbbPath
->SetModifyHdl ( LINK ( this, SvxHyperlinkDocTp
, ModifiedPathHdl_Impl
) );
67 m_pEdTarget
->SetModifyHdl ( LINK ( this, SvxHyperlinkDocTp
, ModifiedTargetHdl_Impl
) );
69 m_pCbbPath
->SetLoseFocusHdl( LINK ( this, SvxHyperlinkDocTp
, LostFocusPathHdl_Impl
) );
71 maTimer
.SetTimeoutHdl ( LINK ( this, SvxHyperlinkDocTp
, TimeoutHdl_Impl
) );
74 SvxHyperlinkDocTp::~SvxHyperlinkDocTp()
79 void SvxHyperlinkDocTp::dispose()
82 m_pBtFileopen
.clear();
86 SvxHyperlinkTabPageBase::dispose();
89 /*************************************************************************
91 |* Fill all dialog-controls except controls in groupbox "more..."
93 |************************************************************************/
95 void SvxHyperlinkDocTp::FillDlgFields(const OUString
& rStrURL
)
97 sal_Int32 nPos
= rStrURL
.indexOf(sHash
);
99 m_pCbbPath
->SetText ( rStrURL
.copy( 0, ( nPos
== -1 ? rStrURL
.getLength() : nPos
) ) );
101 // set target in document at editfield
103 if ( nPos
!= -1 && nPos
< rStrURL
.getLength()-1 )
104 aStrMark
= rStrURL
.copy( nPos
+1 );
105 m_pEdTarget
->SetText ( aStrMark
);
107 ModifiedPathHdl_Impl ( NULL
);
110 /*************************************************************************
112 |* retrieve current url-string
114 |************************************************************************/
116 OUString
SvxHyperlinkDocTp::GetCurrentURL ()
118 // get data from dialog-controls
120 OUString
aStrPath ( m_pCbbPath
->GetText() );
121 const OUString
aBaseURL ( m_pCbbPath
->GetBaseURL() );
122 OUString
aStrMark( m_pEdTarget
->GetText() );
124 if ( aStrPath
!= aEmptyStr
)
126 INetURLObject
aURL( aStrPath
);
127 if ( aURL
.GetProtocol() != INetProtocol::NotValid
) // maybe the path is already a valid
128 aStrURL
= aStrPath
; // hyperlink, then we can use this path directly
130 utl::LocalFileHelper::ConvertSystemPathToURL( aStrPath
, aBaseURL
, aStrURL
);
132 //#105788# always create a URL even if it is not valid
133 if( aStrURL
== aEmptyStr
)
137 if( aStrMark
!= aEmptyStr
)
139 aStrURL
+= OUString( sHash
);
146 /*************************************************************************
148 |* retrieve and prepare data from dialog-fields
150 |************************************************************************/
152 void SvxHyperlinkDocTp::GetCurentItemData ( OUString
& rStrURL
, OUString
& aStrName
,
153 OUString
& aStrIntName
, OUString
& aStrFrame
,
154 SvxLinkInsertMode
& eMode
)
156 // get data from standard-fields
157 rStrURL
= GetCurrentURL();
159 if( rStrURL
.equalsIgnoreAsciiCase( sFileScheme
) )
162 GetDataFromCommonFields( aStrName
, aStrIntName
, aStrFrame
, eMode
);
165 /*************************************************************************
167 |* static method to create Tabpage
169 |************************************************************************/
171 VclPtr
<IconChoicePage
> SvxHyperlinkDocTp::Create( vcl::Window
* pWindow
, IconChoiceDialog
* pDlg
, const SfxItemSet
& rItemSet
)
173 return VclPtr
<SvxHyperlinkDocTp
>::Create( pWindow
, pDlg
, rItemSet
);
176 /*************************************************************************
180 |************************************************************************/
182 void SvxHyperlinkDocTp::SetInitFocus()
184 m_pCbbPath
->GrabFocus();
187 /*************************************************************************
189 |* Click on imagebutton : fileopen
191 |************************************************************************/
193 IMPL_LINK_NOARG(SvxHyperlinkDocTp
, ClickFileopenHdl_Impl
)
195 // Open Fileopen-Dialog
196 ::sfx2::FileDialogHelper
aDlg(
197 com::sun::star::ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE
, 0,
199 OUString
aOldURL( GetCurrentURL() );
200 if( aOldURL
.startsWithIgnoreAsciiCase( sFileScheme
) )
202 aDlg
.SetDisplayDirectory( aOldURL
);
205 DisableClose( true );
206 ErrCode nError
= aDlg
.Execute();
207 DisableClose( false );
209 if ( ERRCODE_NONE
== nError
)
211 OUString
aURL( aDlg
.GetPath() );
214 utl::LocalFileHelper::ConvertURLToSystemPath( aURL
, aPath
);
216 m_pCbbPath
->SetBaseURL( aURL
);
217 m_pCbbPath
->SetText( aPath
);
219 if ( aOldURL
!= GetCurrentURL() )
220 ModifiedPathHdl_Impl (NULL
);
226 /*************************************************************************
228 |* Click on imagebutton : target
230 |************************************************************************/
232 IMPL_LINK_NOARG(SvxHyperlinkDocTp
, ClickTargetHdl_Impl
)
234 if ( GetPathType ( maStrURL
) == Type_ExistsFile
||
235 maStrURL
.isEmpty() ||
236 maStrURL
.equalsIgnoreAsciiCase( sFileScheme
) ||
237 maStrURL
.startsWith( sHash
) )
239 mpMarkWnd
->SetError( LERR_NOERROR
);
243 if ( maStrURL
.equalsIgnoreAsciiCase( sFileScheme
) )
244 mpMarkWnd
->RefreshTree ( aEmptyStr
);
246 mpMarkWnd
->RefreshTree ( maStrURL
);
251 mpMarkWnd
->SetError( LERR_DOCNOTOPEN
);
258 /*************************************************************************
260 |* Contens of combobox "Path" modified
262 |************************************************************************/
264 IMPL_LINK_NOARG(SvxHyperlinkDocTp
, ModifiedPathHdl_Impl
)
266 maStrURL
= GetCurrentURL();
268 maTimer
.SetTimeout( 2500 );
271 m_pFtFullURL
->SetText( maStrURL
);
276 /*************************************************************************
278 |* If path-field was modify, to browse the new doc after timeout
280 |************************************************************************/
282 IMPL_LINK_NOARG_TYPED(SvxHyperlinkDocTp
, TimeoutHdl_Impl
, Timer
*, void)
284 if ( IsMarkWndVisible() && ( GetPathType( maStrURL
)==Type_ExistsFile
||
285 maStrURL
.isEmpty() ||
286 maStrURL
.equalsIgnoreAsciiCase( sFileScheme
) ) )
290 if ( maStrURL
.equalsIgnoreAsciiCase( sFileScheme
) )
291 mpMarkWnd
->RefreshTree ( aEmptyStr
);
293 mpMarkWnd
->RefreshTree ( maStrURL
);
299 /*************************************************************************
301 |* Contens of editfield "Target" modified
303 |************************************************************************/
305 IMPL_LINK_NOARG(SvxHyperlinkDocTp
, ModifiedTargetHdl_Impl
)
307 maStrURL
= GetCurrentURL();
309 if ( IsMarkWndVisible() )
310 mpMarkWnd
->SelectEntry ( m_pEdTarget
->GetText() );
312 m_pFtFullURL
->SetText( maStrURL
);
317 /*************************************************************************
319 |* editfield "Target" lost focus
321 |************************************************************************/
323 IMPL_LINK_NOARG(SvxHyperlinkDocTp
, LostFocusPathHdl_Impl
)
325 maStrURL
= GetCurrentURL();
327 m_pFtFullURL
->SetText( maStrURL
);
332 /*************************************************************************
334 |* Get String from Bookmark-Wnd
336 |************************************************************************/
338 void SvxHyperlinkDocTp::SetMarkStr ( const OUString
& aStrMark
)
340 m_pEdTarget
->SetText ( aStrMark
);
342 ModifiedTargetHdl_Impl ( NULL
);
345 /*************************************************************************
347 |* retrieve kind of pathstr
349 |************************************************************************/
351 SvxHyperlinkDocTp::EPathType
SvxHyperlinkDocTp::GetPathType ( const OUString
& rStrPath
)
353 INetURLObject
aURL( rStrPath
, INetProtocol::File
);
355 if( aURL
.HasError() )
358 return Type_ExistsFile
;
361 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */