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