Update ooo320-m1
[ooovba.git] / svx / source / cui / hldoctp.cxx
blob2abec10a01af07c244fd18bcbb8c14e26d513e5a
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: hldoctp.cxx,v $
10 * $Revision: 1.28 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svx.hxx"
34 #ifdef SVX_DLLIMPLEMENTATION
35 #undef SVX_DLLIMPLEMENTATION
36 #endif
38 #include "cuihyperdlg.hxx"
39 #include <unotools/localfilehelper.hxx>
40 #include <sfx2/filedlghelper.hxx>
41 #include "com/sun/star/ui/dialogs/TemplateDescription.hpp"
43 #include "hldoctp.hxx"
44 #include "hyperdlg.hrc"
45 #include "hlmarkwn_def.hxx" //ADD CHINA001
47 sal_Char __READONLY_DATA sHash[] = "#";
48 sal_Char __READONLY_DATA sFileScheme[] = INET_FILE_SCHEME;
49 sal_Char __READONLY_DATA sPortalFileScheme[] = "vnd.sun.star.wfs://";
50 sal_Char __READONLY_DATA sNewsSRVScheme[] = "news://";
51 // TODO news:// is nonsense
52 sal_Char __READONLY_DATA sHTTPScheme[] = INET_HTTP_SCHEME;
54 /*************************************************************************
56 |* Contructor / Destructor
58 |************************************************************************/
60 SvxHyperlinkDocTp::SvxHyperlinkDocTp ( Window *pParent, const SfxItemSet& rItemSet)
61 : SvxHyperlinkTabPageBase ( pParent, SVX_RES( RID_SVXPAGE_HYPERLINK_DOCUMENT ), rItemSet ),
62 maGrpDocument ( this, SVX_RES (GRP_DOCUMENT) ),
63 maFtPath ( this, SVX_RES (FT_PATH_DOC) ),
64 maCbbPath ( this, INET_PROT_FILE ),
65 maBtFileopen ( this, SVX_RES (BTN_FILEOPEN) ),
66 maGrpTarget ( this, SVX_RES (GRP_TARGET) ),
67 maFtTarget ( this, SVX_RES (FT_TARGET_DOC) ),
68 maEdTarget ( this, SVX_RES (ED_TARGET_DOC) ),
69 maFtURL ( this, SVX_RES (FT_URL) ),
70 maFtFullURL ( this, SVX_RES (FT_FULL_URL) ),
71 maBtBrowse ( this, SVX_RES (BTN_BROWSE) ),
72 mbMarkWndOpen ( FALSE )
74 // Set HC bitmaps and disable display of bitmap names.
75 maBtBrowse.SetModeImage( Image( SVX_RES( IMG_BROWSE_HC ) ), BMP_COLOR_HIGHCONTRAST );
76 maBtBrowse.EnableTextDisplay (FALSE);
77 maBtFileopen.SetModeImage( Image( SVX_RES( IMG_FILEOPEN_HC ) ), BMP_COLOR_HIGHCONTRAST );
78 maBtFileopen.EnableTextDisplay (FALSE);
80 InitStdControls();
81 FreeResource();
83 // Init URL-Box (pos&size, Open-Handler)
84 maCbbPath.SetPosSizePixel ( LogicToPixel( Point( COL_2, 15 ), MAP_APPFONT ),
85 LogicToPixel( Size ( 176 - COL_DIFF, 60), MAP_APPFONT ) );
86 maCbbPath.Show();
87 String aFileScheme( INET_FILE_SCHEME, RTL_TEXTENCODING_ASCII_US );
88 maCbbPath.SetBaseURL(aFileScheme);
89 maCbbPath.SetHelpId( HID_HYPERDLG_DOC_PATH );
91 SetExchangeSupport ();
93 // overload handlers
94 maBtFileopen.SetClickHdl ( LINK ( this, SvxHyperlinkDocTp, ClickFileopenHdl_Impl ) );
95 maBtBrowse.SetClickHdl ( LINK ( this, SvxHyperlinkDocTp, ClickTargetHdl_Impl ) );
96 maCbbPath.SetModifyHdl ( LINK ( this, SvxHyperlinkDocTp, ModifiedPathHdl_Impl ) );
97 maEdTarget.SetModifyHdl ( LINK ( this, SvxHyperlinkDocTp, ModifiedTargetHdl_Impl ) );
99 maCbbPath.SetLoseFocusHdl( LINK ( this, SvxHyperlinkDocTp, LostFocusPathHdl_Impl ) );
101 maTimer.SetTimeoutHdl ( LINK ( this, SvxHyperlinkDocTp, TimeoutHdl_Impl ) );
104 SvxHyperlinkDocTp::~SvxHyperlinkDocTp ()
108 /*************************************************************************
110 |* Fill all dialog-controls except controls in groupbox "more..."
112 |************************************************************************/
114 void SvxHyperlinkDocTp::FillDlgFields ( String& aStrURL )
116 INetURLObject aURL ( aStrURL );
118 String aStrMark;
119 xub_StrLen nPos = aStrURL.SearchAscii( sHash );
120 // path
121 maCbbPath.SetText ( aStrURL.Copy( 0, ( nPos == STRING_NOTFOUND ? aStrURL.Len() : nPos ) ) );
123 // set target in document at editfield
124 if ( nPos != STRING_NOTFOUND && nPos<aStrURL.Len()-1 )
125 aStrMark = aStrURL.Copy( nPos+1, aStrURL.Len() );
126 maEdTarget.SetText ( aStrMark );
128 ModifiedPathHdl_Impl ( NULL );
131 /*************************************************************************
133 |* retrieve current url-string
135 |************************************************************************/
137 String SvxHyperlinkDocTp::GetCurrentURL ()
139 // get data from dialog-controls
140 String aStrURL;
141 String aStrPath ( maCbbPath.GetText() );
142 const String aBaseURL ( maCbbPath.GetBaseURL() );
143 String aStrMark( maEdTarget.GetText() );
145 if ( aStrPath != aEmptyStr )
147 INetURLObject aURL( aStrPath );
148 if ( aURL.GetProtocol() != INET_PROT_NOT_VALID ) // maybe the path is already a valid
149 aStrURL = aStrPath; // hyperlink, then we can use this path directly
150 else
151 utl::LocalFileHelper::ConvertSystemPathToURL( aStrPath, aBaseURL, aStrURL );
153 //#105788# always create a URL even if it is not valid
154 if( aStrURL == aEmptyStr )
155 aStrURL = aStrPath;
158 if( aStrMark != aEmptyStr )
160 aStrURL.AppendAscii( sHash );
161 aStrURL += aStrMark;
164 return aStrURL;
167 /*************************************************************************
169 |* retrieve and prepare data from dialog-fields
171 |************************************************************************/
173 void SvxHyperlinkDocTp::GetCurentItemData ( String& aStrURL, String& aStrName,
174 String& aStrIntName, String& aStrFrame,
175 SvxLinkInsertMode& eMode )
177 // get data from standard-fields
178 aStrURL = GetCurrentURL();
180 if( aStrURL.EqualsIgnoreCaseAscii( sFileScheme ) ||
181 aStrURL.EqualsIgnoreCaseAscii( sPortalFileScheme ) )
182 aStrURL=aEmptyStr;
184 GetDataFromCommonFields( aStrName, aStrIntName, aStrFrame, eMode );
187 /*************************************************************************
189 |* static method to create Tabpage
191 |************************************************************************/
193 IconChoicePage* SvxHyperlinkDocTp::Create( Window* pWindow, const SfxItemSet& rItemSet )
195 return( new SvxHyperlinkDocTp( pWindow, rItemSet ) );
198 /*************************************************************************
200 |* Set initial focus
202 |************************************************************************/
204 void SvxHyperlinkDocTp::SetInitFocus()
206 maCbbPath.GrabFocus();
209 /*************************************************************************
211 |* Click on imagebutton : fileopen
213 |************************************************************************/
215 IMPL_LINK ( SvxHyperlinkDocTp, ClickFileopenHdl_Impl, void *, EMPTYARG )
217 // Open Fileopen-Dialog
218 ::sfx2::FileDialogHelper aDlg(
219 com::sun::star::ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE, 0,
220 GetParent() );
221 String aOldURL( GetCurrentURL() );
222 if( aOldURL.EqualsIgnoreCaseAscii( sFileScheme, 0, sizeof( sFileScheme ) - 1 ) ||
223 aOldURL.EqualsIgnoreCaseAscii( sPortalFileScheme, 0, sizeof( sFileScheme ) - 1 ) )
225 aDlg.SetDisplayDirectory( aOldURL );
228 DisableClose( sal_True );
229 ErrCode nError = aDlg.Execute();
230 DisableClose( sal_False );
232 if ( ERRCODE_NONE == nError )
234 String aURL( aDlg.GetPath() );
235 String aPath;
237 utl::LocalFileHelper::ConvertURLToSystemPath( aURL, aPath );
239 maCbbPath.SetBaseURL( aURL );
240 maCbbPath.SetText( aPath );
242 if ( aOldURL != GetCurrentURL() )
243 ModifiedPathHdl_Impl (NULL);
246 return( 0L );
249 /*************************************************************************
251 |* Click on imagebutton : target
253 |************************************************************************/
255 IMPL_LINK ( SvxHyperlinkDocTp, ClickTargetHdl_Impl, void *, EMPTYARG )
257 if ( GetPathType ( maStrURL ) == Type_ExistsFile ||
258 maStrURL == aEmptyStr ||
259 maStrURL.EqualsIgnoreCaseAscii( sFileScheme ) ||
260 maStrURL.EqualsIgnoreCaseAscii( sPortalFileScheme ) ||
261 maStrURL.SearchAscii( sHash ) == 0 )
263 mpMarkWnd->SetError( LERR_NOERROR );
265 EnterWait();
267 if ( maStrURL.EqualsIgnoreCaseAscii( sFileScheme ) ||
268 maStrURL.EqualsIgnoreCaseAscii( sPortalFileScheme ) )
269 mpMarkWnd->RefreshTree ( aEmptyStr );
270 else
271 mpMarkWnd->RefreshTree ( maStrURL );
273 LeaveWait();
275 else
276 mpMarkWnd->SetError( LERR_DOCNOTOPEN );
278 ShowMarkWnd ();
280 return( 0L );
283 /*************************************************************************
285 |* Contens of combobox "Path" modified
287 |************************************************************************/
289 IMPL_LINK ( SvxHyperlinkDocTp, ModifiedPathHdl_Impl, void *, EMPTYARG )
291 maStrURL = GetCurrentURL();
293 maTimer.SetTimeout( 2500 );
294 maTimer.Start();
296 maFtFullURL.SetText( maStrURL );
298 return( 0L );
301 /*************************************************************************
303 |* If path-field was modify, to browse the new doc after timeout
305 |************************************************************************/
307 IMPL_LINK ( SvxHyperlinkDocTp, TimeoutHdl_Impl, Timer *, EMPTYARG )
309 if ( IsMarkWndVisible() && ( GetPathType( maStrURL )==Type_ExistsFile ||
310 maStrURL == aEmptyStr ||
311 maStrURL.EqualsIgnoreCaseAscii( sFileScheme ) ) )
313 EnterWait();
315 if ( maStrURL.EqualsIgnoreCaseAscii( sFileScheme ) ||
316 maStrURL.EqualsIgnoreCaseAscii( sPortalFileScheme ) )
317 mpMarkWnd->RefreshTree ( aEmptyStr );
318 else
319 mpMarkWnd->RefreshTree ( maStrURL );
321 LeaveWait();
324 return( 0L );
327 /*************************************************************************
329 |* Contens of editfield "Target" modified
331 |************************************************************************/
333 IMPL_LINK ( SvxHyperlinkDocTp, ModifiedTargetHdl_Impl, void *, EMPTYARG )
335 maStrURL = GetCurrentURL();
337 if ( IsMarkWndVisible() )
338 mpMarkWnd->SelectEntry ( maEdTarget.GetText() );
340 maFtFullURL.SetText( maStrURL );
342 return( 0L );
345 /*************************************************************************
347 |* editfield "Target" lost focus
349 |************************************************************************/
351 IMPL_LINK ( SvxHyperlinkDocTp, LostFocusPathHdl_Impl, void *, EMPTYARG )
353 maStrURL = GetCurrentURL();
355 maFtFullURL.SetText( maStrURL );
357 return (0L);
360 /*************************************************************************
362 |* Get String from Bookmark-Wnd
364 |************************************************************************/
366 void SvxHyperlinkDocTp::SetMarkStr ( String& aStrMark )
368 maEdTarget.SetText ( aStrMark );
370 ModifiedTargetHdl_Impl ( NULL );
373 /*************************************************************************
375 |* retrieve kind of pathstr
377 |************************************************************************/
379 SvxHyperlinkDocTp::EPathType SvxHyperlinkDocTp::GetPathType ( String& aStrPath )
381 INetURLObject aURL( aStrPath, INET_PROT_FILE );
383 if( aURL.HasError() )
384 return Type_Invalid;
385 else
386 return Type_ExistsFile;