LibreOffice Module cui (master) 1
hldoctp.cxx
Go to the documentation of this file.
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 <osl/file.hxx>
23#include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
24
25#include <hldoctp.hxx>
26#include <hlmarkwn_def.hxx>
27
28char const sHash[] = "#";
29
30/*************************************************************************
31|*
32|* Constructor / Destructor
33|*
34|************************************************************************/
35
37 : SvxHyperlinkTabPageBase(pParent, pDlg, "cui/ui/hyperlinkdocpage.ui", "HyperlinkDocPage", pItemSet)
38 , m_xCbbPath(new SvxHyperURLBox(xBuilder->weld_combo_box("path")))
39 , m_xBtFileopen(xBuilder->weld_button("fileopen"))
40 , m_xEdTarget(xBuilder->weld_entry("target"))
41 , m_xFtFullURL(xBuilder->weld_label("url"))
42 , m_xBtBrowse(xBuilder->weld_button("browse"))
43 , m_bMarkWndOpen(false)
44{
45 m_xCbbPath->SetSmartProtocol(INetProtocol::File);
46
48
49 m_xCbbPath->show();
50 m_xCbbPath->SetBaseURL(INET_FILE_SCHEME);
51
53
54 // set handlers
55 m_xBtFileopen->connect_clicked( LINK ( this, SvxHyperlinkDocTp, ClickFileopenHdl_Impl ) );
56 m_xBtBrowse->connect_clicked( LINK ( this, SvxHyperlinkDocTp, ClickTargetHdl_Impl ) );
57 m_xCbbPath->connect_changed( LINK ( this, SvxHyperlinkDocTp, ModifiedPathHdl_Impl ) );
58 m_xEdTarget->connect_changed( LINK ( this, SvxHyperlinkDocTp, ModifiedTargetHdl_Impl ) );
59
60 m_xCbbPath->connect_focus_out( LINK ( this, SvxHyperlinkDocTp, LostFocusPathHdl_Impl ) );
61
62 maTimer.SetInvokeHandler ( LINK ( this, SvxHyperlinkDocTp, TimeoutHdl_Impl ) );
63}
64
66{
67}
68
69/*************************************************************************
70|*
71|* Fill all dialog-controls except controls in groupbox "more..."
72|*
73|************************************************************************/
74void SvxHyperlinkDocTp::FillDlgFields(const OUString& rStrURL)
75{
76 sal_Int32 nPos = rStrURL.indexOf(sHash);
77 // path
78 m_xCbbPath->set_entry_text( rStrURL.copy( 0, ( nPos == -1 ? rStrURL.getLength() : nPos ) ) );
79
80 // set target in document at editfield
81 OUString aStrMark;
82 if ( nPos != -1 && nPos < rStrURL.getLength()-1 )
83 aStrMark = rStrURL.copy( nPos+1 );
84 m_xEdTarget->set_text( aStrMark );
85
86 ModifiedPathHdl_Impl(*m_xCbbPath->getWidget());
87}
88
89/*************************************************************************
90|*
91|* retrieve current url-string
92|*
93|************************************************************************/
95{
96 // get data from dialog-controls
97 OUString aStrURL;
98 OUString aStrPath( m_xCbbPath->get_active_text() );
99 OUString aStrMark( m_xEdTarget->get_text() );
100
101 if ( !aStrPath.isEmpty() )
102 {
103 INetURLObject aURL( aStrPath );
104 if ( aURL.GetProtocol() != INetProtocol::NotValid ) // maybe the path is already a valid
105 aStrURL = aStrPath; // hyperlink, then we can use this path directly
106 else
107 {
108 osl::FileBase::getFileURLFromSystemPath( aStrPath, aStrURL );
109 aStrURL = INetURLObject::decode(aStrURL, INetURLObject::DecodeMechanism::ToIUri, RTL_TEXTENCODING_UTF8);
110 }
111
112 //#105788# always create a URL even if it is not valid
113 if( aStrURL.isEmpty() )
114 aStrURL = aStrPath;
115 }
116
117 if( !aStrMark.isEmpty() )
118 {
119 aStrURL += sHash + aStrMark;
120 }
121
122 return aStrURL;
123}
124
125/*************************************************************************
126|*
127|* retrieve and prepare data from dialog-fields
128|*
129|************************************************************************/
130void SvxHyperlinkDocTp::GetCurrentItemData ( OUString& rStrURL, OUString& aStrName,
131 OUString& aStrIntName, OUString& aStrFrame,
132 SvxLinkInsertMode& eMode )
133{
134 // get data from standard-fields
135 rStrURL = GetCurrentURL();
136
137 if( rStrURL.equalsIgnoreAsciiCase( INET_FILE_SCHEME ) )
138 rStrURL.clear();
139
140 GetDataFromCommonFields( aStrName, aStrIntName, aStrFrame, eMode );
141}
142
143/*************************************************************************
144|*
145|* static method to create Tabpage
146|*
147|************************************************************************/
148std::unique_ptr<IconChoicePage> SvxHyperlinkDocTp::Create(weld::Container* pWindow, SvxHpLinkDlg* pDlg, const SfxItemSet* pItemSet)
149{
150 return std::make_unique<SvxHyperlinkDocTp>(pWindow, pDlg, pItemSet);
151}
152
153/*************************************************************************
154|*
155|* Set initial focus
156|*
157|************************************************************************/
159{
160 m_xCbbPath->grab_focus();
161}
162
163/*************************************************************************
164|*
165|* Click on imagebutton : fileopen
166|*
167|************************************************************************/
168IMPL_LINK_NOARG(SvxHyperlinkDocTp, ClickFileopenHdl_Impl, weld::Button&, void)
169{
170 DisableClose( true );
171 // Open Fileopen-Dialog
173 css::ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE, FileDialogFlags::NONE,
174 mpDialog->getDialog() );
175 OUString aOldURL( GetCurrentURL() );
176 if( aOldURL.startsWithIgnoreAsciiCase( INET_FILE_SCHEME ) )
177 {
178 OUString aPath;
179 osl::FileBase::getSystemPathFromFileURL(aOldURL, aPath);
180 aDlg.SetDisplayFolder( aPath );
181 }
182
183 ErrCode nError = aDlg.Execute();
184 DisableClose( false );
185
186 if ( ERRCODE_NONE != nError )
187 return;
188
189 OUString aURL( aDlg.GetPath() );
190 OUString aPath;
191
192 osl::FileBase::getSystemPathFromFileURL(aURL, aPath);
193
194 m_xCbbPath->SetBaseURL( aURL );
195 m_xCbbPath->set_entry_text(aPath);
196
197 if ( aOldURL != GetCurrentURL() )
198 ModifiedPathHdl_Impl(*m_xCbbPath->getWidget());
199}
200
201/*************************************************************************
202|*
203|* Click on imagebutton : target
204|*
205|************************************************************************/
206IMPL_LINK_NOARG(SvxHyperlinkDocTp, ClickTargetHdl_Impl, weld::Button&, void)
207{
208 ShowMarkWnd();
209
210 if ( GetPathType ( maStrURL ) == EPathType::ExistsFile ||
211 maStrURL.isEmpty() ||
212 maStrURL.equalsIgnoreAsciiCase( INET_FILE_SCHEME ) ||
213 maStrURL.startsWith( sHash ) )
214 {
215 mxMarkWnd->SetError( LERR_NOERROR );
216
217 weld::WaitObject aWait(mpDialog->getDialog());
218
219 if ( maStrURL.equalsIgnoreAsciiCase( INET_FILE_SCHEME ) )
220 mxMarkWnd->RefreshTree ( "" );
221 else
222 mxMarkWnd->RefreshTree ( maStrURL );
223 }
224 else
225 mxMarkWnd->SetError( LERR_DOCNOTOPEN );
226}
227
228/*************************************************************************
229|*
230|* Contents of combobox "Path" modified
231|*
232|************************************************************************/
234{
235 maStrURL = GetCurrentURL();
236
237 maTimer.SetTimeout( 2500 );
238 maTimer.Start();
239
240 m_xFtFullURL->set_label( maStrURL );
241}
242
243/*************************************************************************
244|*
245|* If path-field was modify, to browse the new doc after timeout
246|*
247|************************************************************************/
248IMPL_LINK_NOARG(SvxHyperlinkDocTp, TimeoutHdl_Impl, Timer *, void)
249{
250 if ( IsMarkWndVisible() && ( GetPathType( maStrURL )== EPathType::ExistsFile ||
251 maStrURL.isEmpty() ||
252 maStrURL.equalsIgnoreAsciiCase( INET_FILE_SCHEME ) ) )
253 {
254 weld::WaitObject aWait(mpDialog->getDialog());
255
256 if ( maStrURL.equalsIgnoreAsciiCase( INET_FILE_SCHEME ) )
257 mxMarkWnd->RefreshTree ( "" );
258 else
259 mxMarkWnd->RefreshTree ( maStrURL );
260 }
261}
262
263/*************************************************************************
264|*
265|* Contents of editfield "Target" modified
266|*
267|************************************************************************/
268IMPL_LINK_NOARG(SvxHyperlinkDocTp, ModifiedTargetHdl_Impl, weld::Entry&, void)
269{
270 maStrURL = GetCurrentURL();
271
272 if (IsMarkWndVisible())
273 mxMarkWnd->SelectEntry(m_xEdTarget->get_text());
274
275 m_xFtFullURL->set_label( maStrURL );
276}
277
278/*************************************************************************
279|*
280|* editfield "Target" lost focus
281|*
282|************************************************************************/
283IMPL_LINK_NOARG(SvxHyperlinkDocTp, LostFocusPathHdl_Impl, weld::Widget&, void)
284{
285 maStrURL = GetCurrentURL();
286
287 m_xFtFullURL->set_label( maStrURL );
288}
289
290/*************************************************************************
291|*
292|* Get String from Bookmark-Wnd
293|*
294|************************************************************************/
295void SvxHyperlinkDocTp::SetMarkStr ( const OUString& aStrMark )
296{
297 m_xEdTarget->set_text(aStrMark);
298
299 ModifiedTargetHdl_Impl ( *m_xEdTarget );
300}
301
302/*************************************************************************
303|*
304|* retrieve kind of pathstr
305|*
306|************************************************************************/
308{
309 INetURLObject aURL( rStrPath, INetProtocol::File );
310
311 if( aURL.HasError() )
312 return EPathType::Invalid;
313 else
315}
316
317/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static OUString decode(std::u16string_view rText, DecodeMechanism eMechanism, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8)
void SetExchangeSupport()
Definition: iconcdlg.hxx:60
ComboBox-Control for URL's with History and Autocompletion.
Definition: hltpbase.hxx:36
std::unique_ptr< weld::Button > m_xBtBrowse
Definition: hldoctp.hxx:35
static EPathType GetPathType(std::u16string_view rStrPath)
Definition: hldoctp.cxx:307
virtual void SetInitFocus() override
Definition: hldoctp.cxx:158
virtual void SetMarkStr(const OUString &aStrMark) override
Definition: hldoctp.cxx:295
OUString GetCurrentURL() const
Definition: hldoctp.cxx:94
static std::unique_ptr< IconChoicePage > Create(weld::Container *pWindow, SvxHpLinkDlg *pDlg, const SfxItemSet *pItemSet)
Definition: hldoctp.cxx:148
void FillDlgFields(const OUString &rStrURL) override
Definition: hldoctp.cxx:74
std::unique_ptr< SvxHyperURLBox > m_xCbbPath
Definition: hldoctp.hxx:31
std::unique_ptr< weld::Button > m_xBtFileopen
Definition: hldoctp.hxx:32
std::unique_ptr< weld::Entry > m_xEdTarget
Definition: hldoctp.hxx:33
void GetCurrentItemData(OUString &rStrURL, OUString &aStrName, OUString &aStrIntName, OUString &aStrFrame, SvxLinkInsertMode &eMode) override
Definition: hldoctp.cxx:130
SvxHyperlinkDocTp(weld::Container *pParent, SvxHpLinkDlg *pDlg, const SfxItemSet *pItemSet)
Definition: hldoctp.cxx:36
virtual ~SvxHyperlinkDocTp() override
Definition: hldoctp.cxx:65
Tabpage : Basisclass.
Definition: hltpbase.hxx:47
void GetDataFromCommonFields(OUString &aStrName, OUString &aStrIntName, OUString &aStrFrame, SvxLinkInsertMode &eMode)
Definition: hltpbase.cxx:422
void SetInvokeHandler(const Link< Timer *, void > &rLink)
OUString GetPath() const
void SetDisplayFolder(const OUString &_rURL)
URL aURL
#define ERRCODE_NONE
IMPL_LINK_NOARG(SvxHyperlinkDocTp, ClickFileopenHdl_Impl, weld::Button &, void)
Definition: hldoctp.cxx:168
char const sHash[]
Definition: hldoctp.cxx:28
#define LERR_DOCNOTOPEN
#define LERR_NOERROR
SvxLinkInsertMode
Mode eMode
sal_uInt16 nPos
constexpr OUStringLiteral INET_FILE_SCHEME