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 <osl/file.hxx>
22 #include <sfx2/filedlghelper.hxx>
23 #include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
25 #include <hldoctp.hxx>
26 #include <hlmarkwn_def.hxx>
27 #include <bitmaps.hlst>
29 sal_Char
const sHash
[] = "#";
30 sal_Char
const sFileScheme
[] = INET_FILE_SCHEME
;
32 /*************************************************************************
34 |* Constructor / Destructor
36 |************************************************************************/
38 SvxHyperlinkDocTp::SvxHyperlinkDocTp ( vcl::Window
*pParent
, IconChoiceDialog
* pDlg
, const SfxItemSet
* pItemSet
)
39 : SvxHyperlinkTabPageBase ( pParent
, pDlg
, "HyperlinkDocPage", "cui/ui/hyperlinkdocpage.ui", pItemSet
),
40 mbMarkWndOpen ( false )
42 get(m_pCbbPath
, "path");
43 m_pCbbPath
->SetSmartProtocol(INetProtocol::File
);
44 get(m_pBtFileopen
, "fileopen");
45 m_pBtFileopen
->SetModeImage(Image(StockImage::Yes
, RID_SVXBMP_FILEOPEN
));
46 get(m_pEdTarget
, "target");
47 get(m_pFtFullURL
, "url");
48 get(m_pBtBrowse
, "browse");
49 m_pBtBrowse
->SetModeImage(Image(StockImage::Yes
, RID_SVXBMP_TARGET
));
51 // Disable display of bitmap names.
52 m_pBtBrowse
->EnableTextDisplay (false);
53 m_pBtFileopen
->EnableTextDisplay (false);
58 m_pCbbPath
->SetBaseURL(INET_FILE_SCHEME
);
60 SetExchangeSupport ();
63 m_pBtFileopen
->SetClickHdl ( LINK ( this, SvxHyperlinkDocTp
, ClickFileopenHdl_Impl
) );
64 m_pBtBrowse
->SetClickHdl ( LINK ( this, SvxHyperlinkDocTp
, ClickTargetHdl_Impl
) );
65 m_pCbbPath
->SetModifyHdl ( LINK ( this, SvxHyperlinkDocTp
, ModifiedPathHdl_Impl
) );
66 m_pEdTarget
->SetModifyHdl ( LINK ( this, SvxHyperlinkDocTp
, ModifiedTargetHdl_Impl
) );
68 m_pCbbPath
->SetLoseFocusHdl( LINK ( this, SvxHyperlinkDocTp
, LostFocusPathHdl_Impl
) );
70 maTimer
.SetInvokeHandler ( LINK ( this, SvxHyperlinkDocTp
, TimeoutHdl_Impl
) );
73 SvxHyperlinkDocTp::~SvxHyperlinkDocTp()
78 void SvxHyperlinkDocTp::dispose()
81 m_pBtFileopen
.clear();
85 SvxHyperlinkTabPageBase::dispose();
88 /*************************************************************************
90 |* Fill all dialog-controls except controls in groupbox "more..."
92 |************************************************************************/
94 void SvxHyperlinkDocTp::FillDlgFields(const OUString
& rStrURL
)
96 sal_Int32 nPos
= rStrURL
.indexOf(sHash
);
98 m_pCbbPath
->SetText ( rStrURL
.copy( 0, ( nPos
== -1 ? rStrURL
.getLength() : nPos
) ) );
100 // set target in document at editfield
102 if ( nPos
!= -1 && nPos
< rStrURL
.getLength()-1 )
103 aStrMark
= rStrURL
.copy( nPos
+1 );
104 m_pEdTarget
->SetText ( aStrMark
);
106 ModifiedPathHdl_Impl ( *m_pCbbPath
);
109 /*************************************************************************
111 |* retrieve current url-string
113 |************************************************************************/
115 OUString
SvxHyperlinkDocTp::GetCurrentURL ()
117 // get data from dialog-controls
119 OUString
aStrPath ( m_pCbbPath
->GetText() );
120 OUString
aStrMark( m_pEdTarget
->GetText() );
122 if ( !aStrPath
.isEmpty() )
124 INetURLObject
aURL( aStrPath
);
125 if ( aURL
.GetProtocol() != INetProtocol::NotValid
) // maybe the path is already a valid
126 aStrURL
= aStrPath
; // hyperlink, then we can use this path directly
128 osl::FileBase::getFileURLFromSystemPath( aStrPath
, aStrURL
);
130 //#105788# always create a URL even if it is not valid
131 if( aStrURL
.isEmpty() )
135 if( !aStrMark
.isEmpty() )
144 /*************************************************************************
146 |* retrieve and prepare data from dialog-fields
148 |************************************************************************/
150 void SvxHyperlinkDocTp::GetCurentItemData ( OUString
& rStrURL
, OUString
& aStrName
,
151 OUString
& aStrIntName
, OUString
& aStrFrame
,
152 SvxLinkInsertMode
& eMode
)
154 // get data from standard-fields
155 rStrURL
= GetCurrentURL();
157 if( rStrURL
.equalsIgnoreAsciiCase( sFileScheme
) )
160 GetDataFromCommonFields( aStrName
, aStrIntName
, aStrFrame
, eMode
);
163 /*************************************************************************
165 |* static method to create Tabpage
167 |************************************************************************/
169 VclPtr
<IconChoicePage
> SvxHyperlinkDocTp::Create( vcl::Window
* pWindow
, IconChoiceDialog
* pDlg
, const SfxItemSet
* pItemSet
)
171 return VclPtr
<SvxHyperlinkDocTp
>::Create( pWindow
, pDlg
, pItemSet
);
174 /*************************************************************************
178 |************************************************************************/
180 void SvxHyperlinkDocTp::SetInitFocus()
182 m_pCbbPath
->GrabFocus();
185 /*************************************************************************
187 |* Click on imagebutton : fileopen
189 |************************************************************************/
191 IMPL_LINK_NOARG(SvxHyperlinkDocTp
, ClickFileopenHdl_Impl
, Button
*, void)
193 // Open Fileopen-Dialog
194 sfx2::FileDialogHelper
aDlg(
195 css::ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE
, FileDialogFlags::NONE
,
197 OUString
aOldURL( GetCurrentURL() );
198 if( aOldURL
.startsWithIgnoreAsciiCase( sFileScheme
) )
201 osl::FileBase::getSystemPathFromFileURL(aOldURL
, aPath
);
202 aDlg
.SetDisplayFolder( aPath
);
205 DisableClose( true );
206 ErrCode nError
= aDlg
.Execute();
207 DisableClose( false );
209 if ( ERRCODE_NONE
== nError
)
211 OUString
aURL( aDlg
.GetPath() );
214 osl::FileBase::getSystemPathFromFileURL(aURL
, aPath
);
216 m_pCbbPath
->SetBaseURL( aURL
);
217 m_pCbbPath
->SetText( aPath
);
219 if ( aOldURL
!= GetCurrentURL() )
220 ModifiedPathHdl_Impl(*m_pCbbPath
);
224 /*************************************************************************
226 |* Click on imagebutton : target
228 |************************************************************************/
230 IMPL_LINK_NOARG(SvxHyperlinkDocTp
, ClickTargetHdl_Impl
, Button
*, void)
232 if ( GetPathType ( maStrURL
) == EPathType::ExistsFile
||
233 maStrURL
.isEmpty() ||
234 maStrURL
.equalsIgnoreAsciiCase( sFileScheme
) ||
235 maStrURL
.startsWith( sHash
) )
237 mpMarkWnd
->SetError( LERR_NOERROR
);
241 if ( maStrURL
.equalsIgnoreAsciiCase( sFileScheme
) )
242 mpMarkWnd
->RefreshTree ( "" );
244 mpMarkWnd
->RefreshTree ( maStrURL
);
249 mpMarkWnd
->SetError( LERR_DOCNOTOPEN
);
254 /*************************************************************************
256 |* Contents of combobox "Path" modified
258 |************************************************************************/
260 IMPL_LINK_NOARG(SvxHyperlinkDocTp
, ModifiedPathHdl_Impl
, Edit
&, void)
262 maStrURL
= GetCurrentURL();
264 maTimer
.SetTimeout( 2500 );
267 m_pFtFullURL
->SetText( maStrURL
);
270 /*************************************************************************
272 |* If path-field was modify, to browse the new doc after timeout
274 |************************************************************************/
276 IMPL_LINK_NOARG(SvxHyperlinkDocTp
, TimeoutHdl_Impl
, Timer
*, void)
278 if ( IsMarkWndVisible() && ( GetPathType( maStrURL
)== EPathType::ExistsFile
||
279 maStrURL
.isEmpty() ||
280 maStrURL
.equalsIgnoreAsciiCase( sFileScheme
) ) )
284 if ( maStrURL
.equalsIgnoreAsciiCase( sFileScheme
) )
285 mpMarkWnd
->RefreshTree ( "" );
287 mpMarkWnd
->RefreshTree ( maStrURL
);
293 /*************************************************************************
295 |* Contents of editfield "Target" modified
297 |************************************************************************/
299 IMPL_LINK_NOARG(SvxHyperlinkDocTp
, ModifiedTargetHdl_Impl
, Edit
&, void)
301 maStrURL
= GetCurrentURL();
303 if ( IsMarkWndVisible() )
304 mpMarkWnd
->SelectEntry ( m_pEdTarget
->GetText() );
306 m_pFtFullURL
->SetText( maStrURL
);
309 /*************************************************************************
311 |* editfield "Target" lost focus
313 |************************************************************************/
315 IMPL_LINK_NOARG(SvxHyperlinkDocTp
, LostFocusPathHdl_Impl
, Control
&, void)
317 maStrURL
= GetCurrentURL();
319 m_pFtFullURL
->SetText( maStrURL
);
322 /*************************************************************************
324 |* Get String from Bookmark-Wnd
326 |************************************************************************/
328 void SvxHyperlinkDocTp::SetMarkStr ( const OUString
& aStrMark
)
330 m_pEdTarget
->SetText ( aStrMark
);
332 ModifiedTargetHdl_Impl ( *m_pEdTarget
);
335 /*************************************************************************
337 |* retrieve kind of pathstr
339 |************************************************************************/
341 SvxHyperlinkDocTp::EPathType
SvxHyperlinkDocTp::GetPathType ( const OUString
& rStrPath
)
343 INetURLObject
aURL( rStrPath
, INetProtocol::File
);
345 if( aURL
.HasError() )
346 return EPathType::Invalid
;
348 return EPathType::ExistsFile
;
351 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */