xref: /AOO41X/main/cui/source/dialogs/hldoctp.cxx (revision 2ee96f1cdb99d49425d866b1ec4c5567f37285e6)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_cui.hxx"
26 
27 #include "cuihyperdlg.hxx"
28 #include <unotools/localfilehelper.hxx>
29 #include <sfx2/filedlghelper.hxx>
30 #include "com/sun/star/ui/dialogs/TemplateDescription.hpp"
31 
32 #include "hldoctp.hxx"
33 #include "hyperdlg.hrc"
34 #include "hlmarkwn_def.hxx" //ADD CHINA001
35 
36 sal_Char __READONLY_DATA sHash[]                = "#";
37 sal_Char __READONLY_DATA sFileScheme[]          = INET_FILE_SCHEME;
38 sal_Char __READONLY_DATA sNewsSRVScheme[] = "news://";
39     // TODO news:// is nonsense
40 sal_Char __READONLY_DATA sHTTPScheme[]    = INET_HTTP_SCHEME;
41 
42 /*************************************************************************
43 |*
44 |* Contructor / Destructor
45 |*
46 |************************************************************************/
47 
SvxHyperlinkDocTp(Window * pParent,const SfxItemSet & rItemSet)48 SvxHyperlinkDocTp::SvxHyperlinkDocTp ( Window *pParent, const SfxItemSet& rItemSet)
49     : SvxHyperlinkTabPageBase ( pParent, CUI_RES( RID_SVXPAGE_HYPERLINK_DOCUMENT ), rItemSet ),
50     maGrpDocument   ( this, CUI_RES (GRP_DOCUMENT) ),
51     maFtPath        ( this, CUI_RES (FT_PATH_DOC) ),
52     maCbbPath       ( this, INET_PROT_FILE ),
53     maBtFileopen    ( this, CUI_RES (BTN_FILEOPEN) ),
54     maGrpTarget     ( this, CUI_RES (GRP_TARGET) ),
55     maFtTarget      ( this, CUI_RES (FT_TARGET_DOC) ),
56     maEdTarget      ( this, CUI_RES (ED_TARGET_DOC) ),
57     maFtURL         ( this, CUI_RES (FT_URL) ),
58     maFtFullURL     ( this, CUI_RES (FT_FULL_URL) ),
59     maBtBrowse      ( this, CUI_RES (BTN_BROWSE) ),
60     mbMarkWndOpen   ( sal_False )
61 {
62     // Set HC bitmaps and disable display of bitmap names.
63     maBtBrowse.SetModeImage( Image( CUI_RES( IMG_BROWSE_HC ) ), BMP_COLOR_HIGHCONTRAST );
64     maBtBrowse.EnableTextDisplay (sal_False);
65     maBtFileopen.SetModeImage( Image( CUI_RES( IMG_FILEOPEN_HC ) ), BMP_COLOR_HIGHCONTRAST );
66     maBtFileopen.EnableTextDisplay (sal_False);
67 
68     InitStdControls();
69     FreeResource();
70 
71     // Init URL-Box (pos&size, Open-Handler)
72     maCbbPath.SetPosSizePixel ( LogicToPixel( Point( COL_2, 15 ), MAP_APPFONT ),
73                                 LogicToPixel( Size ( 176 - COL_DIFF, 60), MAP_APPFONT ) );
74     maCbbPath.Show();
75     String aFileScheme( INET_FILE_SCHEME, RTL_TEXTENCODING_ASCII_US );
76     maCbbPath.SetBaseURL(aFileScheme);
77     maCbbPath.SetHelpId( HID_HYPERDLG_DOC_PATH );
78 
79     SetExchangeSupport ();
80 
81     // overload handlers
82     maBtFileopen.SetClickHdl ( LINK ( this, SvxHyperlinkDocTp, ClickFileopenHdl_Impl ) );
83     maBtBrowse.SetClickHdl   ( LINK ( this, SvxHyperlinkDocTp, ClickTargetHdl_Impl ) );
84     maCbbPath.SetModifyHdl   ( LINK ( this, SvxHyperlinkDocTp, ModifiedPathHdl_Impl ) );
85     maEdTarget.SetModifyHdl  ( LINK ( this, SvxHyperlinkDocTp, ModifiedTargetHdl_Impl ) );
86 
87     maCbbPath.SetLoseFocusHdl( LINK ( this, SvxHyperlinkDocTp, LostFocusPathHdl_Impl ) );
88 
89     maBtBrowse.SetAccessibleRelationMemberOf( &maGrpTarget );
90     maBtBrowse.SetAccessibleRelationLabeledBy( &maFtTarget );
91     maBtFileopen.SetAccessibleRelationMemberOf( &maGrpDocument );
92     maBtFileopen.SetAccessibleRelationLabeledBy( &maFtPath );
93     maTimer.SetTimeoutHdl ( LINK ( this, SvxHyperlinkDocTp, TimeoutHdl_Impl ) );
94 }
95 
~SvxHyperlinkDocTp()96 SvxHyperlinkDocTp::~SvxHyperlinkDocTp ()
97 {
98 }
99 
100 /*************************************************************************
101 |*
102 |* Fill all dialog-controls except controls in groupbox "more..."
103 |*
104 |************************************************************************/
105 
FillDlgFields(String & aStrURL)106 void SvxHyperlinkDocTp::FillDlgFields ( String& aStrURL )
107 {
108     INetURLObject aURL ( aStrURL );
109 
110     String aStrMark;
111     xub_StrLen nPos = aStrURL.SearchAscii( sHash );
112     // path
113     maCbbPath.SetText ( aStrURL.Copy( 0, ( nPos == STRING_NOTFOUND ? aStrURL.Len() : nPos ) ) );
114 
115     // set target in document at editfield
116     if ( nPos != STRING_NOTFOUND && nPos<aStrURL.Len()-1 )
117         aStrMark = aStrURL.Copy( nPos+1, aStrURL.Len() );
118      maEdTarget.SetText ( aStrMark );
119 
120     ModifiedPathHdl_Impl ( NULL );
121 }
122 
123 /*************************************************************************
124 |*
125 |* retrieve current url-string
126 |*
127 |************************************************************************/
128 
GetCurrentURL()129 String SvxHyperlinkDocTp::GetCurrentURL ()
130 {
131     // get data from dialog-controls
132     String aStrURL;
133     String aStrPath ( maCbbPath.GetText() );
134     const String aBaseURL ( maCbbPath.GetBaseURL() );
135     String aStrMark( maEdTarget.GetText() );
136 
137     if ( aStrPath != aEmptyStr )
138     {
139         INetURLObject aURL( aStrPath );
140         if ( aURL.GetProtocol() != INET_PROT_NOT_VALID )    // maybe the path is already a valid
141             aStrURL = aStrPath;                             // hyperlink, then we can use this path directly
142         else
143             utl::LocalFileHelper::ConvertSystemPathToURL( aStrPath, aBaseURL, aStrURL );
144 
145         //#105788# always create a URL even if it is not valid
146         if( aStrURL == aEmptyStr )
147             aStrURL = aStrPath;
148     }
149 
150     if( aStrMark != aEmptyStr )
151     {
152         aStrURL.AppendAscii( sHash );
153         aStrURL += aStrMark;
154     }
155 
156     return aStrURL;
157 }
158 
159 /*************************************************************************
160 |*
161 |* retrieve and prepare data from dialog-fields
162 |*
163 |************************************************************************/
164 
GetCurentItemData(String & aStrURL,String & aStrName,String & aStrIntName,String & aStrFrame,SvxLinkInsertMode & eMode)165 void SvxHyperlinkDocTp::GetCurentItemData ( String& aStrURL, String& aStrName,
166                                             String& aStrIntName, String& aStrFrame,
167                                             SvxLinkInsertMode& eMode )
168 {
169     // get data from standard-fields
170     aStrURL = GetCurrentURL();
171 
172     if( aStrURL.EqualsIgnoreCaseAscii( sFileScheme ) )
173          aStrURL=aEmptyStr;
174 
175     GetDataFromCommonFields( aStrName, aStrIntName, aStrFrame, eMode );
176 }
177 
178 /*************************************************************************
179 |*
180 |* static method to create Tabpage
181 |*
182 |************************************************************************/
183 
Create(Window * pWindow,const SfxItemSet & rItemSet)184 IconChoicePage* SvxHyperlinkDocTp::Create( Window* pWindow, const SfxItemSet& rItemSet )
185 {
186     return( new SvxHyperlinkDocTp( pWindow, rItemSet ) );
187 }
188 
189 /*************************************************************************
190 |*
191 |* Set initial focus
192 |*
193 |************************************************************************/
194 
SetInitFocus()195 void SvxHyperlinkDocTp::SetInitFocus()
196 {
197     maCbbPath.GrabFocus();
198 }
199 
200 /*************************************************************************
201 |*
202 |* Click on imagebutton : fileopen
203 |*
204 |************************************************************************/
205 
IMPL_LINK(SvxHyperlinkDocTp,ClickFileopenHdl_Impl,void *,EMPTYARG)206 IMPL_LINK ( SvxHyperlinkDocTp, ClickFileopenHdl_Impl, void *, EMPTYARG )
207 {
208     // Open Fileopen-Dialog
209     ::sfx2::FileDialogHelper aDlg(
210         com::sun::star::ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE, 0,
211         GetParent() );
212     String aOldURL( GetCurrentURL() );
213     if( aOldURL.EqualsIgnoreCaseAscii( sFileScheme, 0, sizeof( sFileScheme ) - 1 ) )
214     {
215         aDlg.SetDisplayDirectory( aOldURL );
216     }
217 
218     DisableClose( sal_True );
219     ErrCode nError = aDlg.Execute();
220     DisableClose( sal_False );
221 
222     if ( ERRCODE_NONE == nError )
223     {
224         String aURL( aDlg.GetPath() );
225         String aPath;
226 
227         utl::LocalFileHelper::ConvertURLToSystemPath( aURL, aPath );
228 
229         maCbbPath.SetBaseURL( aURL );
230         maCbbPath.SetText( aPath );
231 
232         if ( aOldURL != GetCurrentURL() )
233             ModifiedPathHdl_Impl (NULL);
234     }
235 
236     return( 0L );
237 }
238 
239 /*************************************************************************
240 |*
241 |* Click on imagebutton : target
242 |*
243 |************************************************************************/
244 
IMPL_LINK(SvxHyperlinkDocTp,ClickTargetHdl_Impl,void *,EMPTYARG)245 IMPL_LINK ( SvxHyperlinkDocTp, ClickTargetHdl_Impl, void *, EMPTYARG )
246 {
247     if ( GetPathType ( maStrURL ) == Type_ExistsFile  ||
248          maStrURL == aEmptyStr                        ||
249          maStrURL.EqualsIgnoreCaseAscii( sFileScheme ) ||
250          maStrURL.SearchAscii( sHash ) == 0 )
251     {
252         mpMarkWnd->SetError( LERR_NOERROR );
253 
254         EnterWait();
255 
256         if ( maStrURL.EqualsIgnoreCaseAscii( sFileScheme ) )
257             mpMarkWnd->RefreshTree ( aEmptyStr );
258         else
259             mpMarkWnd->RefreshTree ( maStrURL );
260 
261         LeaveWait();
262     }
263     else
264         mpMarkWnd->SetError( LERR_DOCNOTOPEN );
265 
266     ShowMarkWnd ();
267 
268     return( 0L );
269 }
270 
271 /*************************************************************************
272 |*
273 |* Contens of combobox "Path" modified
274 |*
275 |************************************************************************/
276 
IMPL_LINK(SvxHyperlinkDocTp,ModifiedPathHdl_Impl,void *,EMPTYARG)277 IMPL_LINK ( SvxHyperlinkDocTp, ModifiedPathHdl_Impl, void *, EMPTYARG )
278 {
279     maStrURL = GetCurrentURL();
280 
281     maTimer.SetTimeout( 2500 );
282     maTimer.Start();
283 
284     maFtFullURL.SetText( maStrURL );
285 
286     return( 0L );
287 }
288 
289 /*************************************************************************
290 |*
291 |* If path-field was modify, to browse the new doc after timeout
292 |*
293 |************************************************************************/
294 
IMPL_LINK(SvxHyperlinkDocTp,TimeoutHdl_Impl,Timer *,EMPTYARG)295 IMPL_LINK ( SvxHyperlinkDocTp, TimeoutHdl_Impl, Timer *, EMPTYARG )
296 {
297     if ( IsMarkWndVisible() && ( GetPathType( maStrURL )==Type_ExistsFile ||
298                                   maStrURL == aEmptyStr                   ||
299                                   maStrURL.EqualsIgnoreCaseAscii( sFileScheme ) ) )
300     {
301         EnterWait();
302 
303         if ( maStrURL.EqualsIgnoreCaseAscii( sFileScheme ) )
304             mpMarkWnd->RefreshTree ( aEmptyStr );
305         else
306             mpMarkWnd->RefreshTree ( maStrURL );
307 
308         LeaveWait();
309     }
310 
311     return( 0L );
312 }
313 
314 /*************************************************************************
315 |*
316 |* Contens of editfield "Target" modified
317 |*
318 |************************************************************************/
319 
IMPL_LINK(SvxHyperlinkDocTp,ModifiedTargetHdl_Impl,void *,EMPTYARG)320 IMPL_LINK ( SvxHyperlinkDocTp, ModifiedTargetHdl_Impl, void *, EMPTYARG )
321 {
322     maStrURL = GetCurrentURL();
323 
324     if ( IsMarkWndVisible() )
325         mpMarkWnd->SelectEntry ( maEdTarget.GetText() );
326 
327     maFtFullURL.SetText( maStrURL );
328 
329     return( 0L );
330 }
331 
332 /*************************************************************************
333 |*
334 |* editfield "Target" lost focus
335 |*
336 |************************************************************************/
337 
IMPL_LINK(SvxHyperlinkDocTp,LostFocusPathHdl_Impl,void *,EMPTYARG)338 IMPL_LINK ( SvxHyperlinkDocTp, LostFocusPathHdl_Impl, void *, EMPTYARG )
339 {
340     maStrURL = GetCurrentURL();
341 
342     maFtFullURL.SetText( maStrURL );
343 
344     return (0L);
345 }
346 
347 /*************************************************************************
348 |*
349 |* Get String from Bookmark-Wnd
350 |*
351 |************************************************************************/
352 
SetMarkStr(String & aStrMark)353 void SvxHyperlinkDocTp::SetMarkStr ( String& aStrMark )
354 {
355     maEdTarget.SetText ( aStrMark );
356 
357     ModifiedTargetHdl_Impl ( NULL );
358 }
359 
360 /*************************************************************************
361 |*
362 |* retrieve kind of pathstr
363 |*
364 |************************************************************************/
365 
GetPathType(String & aStrPath)366 SvxHyperlinkDocTp::EPathType SvxHyperlinkDocTp::GetPathType ( String& aStrPath )
367 {
368     INetURLObject aURL( aStrPath, INET_PROT_FILE );
369 
370     if( aURL.HasError() )
371         return Type_Invalid;
372     else
373         return Type_ExistsFile;
374 }
375