bump product version to 6.3.0.0.beta1
[LibreOffice.git] / cui / source / dialogs / hldoctp.cxx
blobe492703ab3a0a066394e8bad7289010408a72a68
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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);
55 InitStdControls();
57 m_pCbbPath->Show();
58 m_pCbbPath->SetBaseURL(INET_FILE_SCHEME);
60 SetExchangeSupport ();
62 // set handlers
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()
75 disposeOnce();
78 void SvxHyperlinkDocTp::dispose()
80 m_pCbbPath.clear();
81 m_pBtFileopen.clear();
82 m_pEdTarget.clear();
83 m_pFtFullURL.clear();
84 m_pBtBrowse.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);
97 // path
98 m_pCbbPath->SetText ( rStrURL.copy( 0, ( nPos == -1 ? rStrURL.getLength() : nPos ) ) );
100 // set target in document at editfield
101 OUString aStrMark;
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
118 OUString aStrURL;
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
127 else
128 osl::FileBase::getFileURLFromSystemPath( aStrPath, aStrURL );
130 //#105788# always create a URL even if it is not valid
131 if( aStrURL.isEmpty() )
132 aStrURL = aStrPath;
135 if( !aStrMark.isEmpty() )
137 aStrURL += sHash;
138 aStrURL += aStrMark;
141 return aStrURL;
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 ) )
158 rStrURL.clear();
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 /*************************************************************************
176 |* Set initial focus
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,
196 GetFrameWeld() );
197 OUString aOldURL( GetCurrentURL() );
198 if( aOldURL.startsWithIgnoreAsciiCase( sFileScheme ) )
200 OUString aPath;
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() );
212 OUString aPath;
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 );
239 EnterWait();
241 if ( maStrURL.equalsIgnoreAsciiCase( sFileScheme ) )
242 mpMarkWnd->RefreshTree ( "" );
243 else
244 mpMarkWnd->RefreshTree ( maStrURL );
246 LeaveWait();
248 else
249 mpMarkWnd->SetError( LERR_DOCNOTOPEN );
251 ShowMarkWnd ();
254 /*************************************************************************
256 |* Contents of combobox "Path" modified
258 |************************************************************************/
260 IMPL_LINK_NOARG(SvxHyperlinkDocTp, ModifiedPathHdl_Impl, Edit&, void)
262 maStrURL = GetCurrentURL();
264 maTimer.SetTimeout( 2500 );
265 maTimer.Start();
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 ) ) )
282 EnterWait();
284 if ( maStrURL.equalsIgnoreAsciiCase( sFileScheme ) )
285 mpMarkWnd->RefreshTree ( "" );
286 else
287 mpMarkWnd->RefreshTree ( maStrURL );
289 LeaveWait();
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;
347 else
348 return EPathType::ExistsFile;
351 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */