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 ---------------------------------------------------------------
28 #include <vcl/settings.hxx>
29 #include <unotools/viewoptions.hxx>
30 #include "cuihyperdlg.hxx"
31 #include "hlinettp.hxx"
32 #include "hlmailtp.hxx"
33 #include "hldoctp.hxx"
34 #include "hldocntp.hxx"
35 #include "hyperdlg.hrc"
36 #include <svx/svxids.hrc> // SID_READONLY_MODE
37
38 using ::com::sun::star::uno::Reference;
39 using ::com::sun::star::frame::XFrame;
40
41 //########################################################################
42 //# #
43 //# Childwindow-Wrapper-Class #
44 //# #
45 //########################################################################
46
SvxHlinkCtrl(sal_uInt16 _nId,SfxBindings & rBindings,SvxHpLinkDlg * pDlg)47 SvxHlinkCtrl::SvxHlinkCtrl( sal_uInt16 _nId, SfxBindings & rBindings, SvxHpLinkDlg* pDlg )
48 : SfxControllerItem ( _nId, rBindings )
49 ,aOnlineForwarder ( SID_INTERNET_ONLINE , *this )
50 ,aRdOnlyForwarder ( SID_READONLY_MODE, *this )
51 {
52 pParent = pDlg;
53 }
54
StateChanged(sal_uInt16 nSID,SfxItemState eState,const SfxPoolItem * pState)55 void SvxHlinkCtrl::StateChanged( sal_uInt16 nSID, SfxItemState eState,
56 const SfxPoolItem* pState )
57 {
58 if ( eState == SFX_ITEM_AVAILABLE )
59 {
60 switch ( nSID )
61 {
62 case SID_INTERNET_ONLINE :
63 {
64 pParent->EnableInetBrowse( !( (SfxBoolItem*)pState)->GetValue() );
65 }
66 break;
67 case SID_HYPERLINK_GETLINK :
68 {
69 pParent->SetPage ( (SvxHyperlinkItem*)pState);
70 }
71 break;
72 case SID_READONLY_MODE :
73 {
74 pParent->SetReadOnlyMode( ( (SfxBoolItem*)pState)->GetValue() == sal_True );
75 }
76 break;
77 }
78 }
79 }
80
81
82
83 // -----------------------------------------------------------------------
84
85
86
87 //########################################################################
88 //# #
89 //# Hyperlink - Dialog #
90 //# #
91 //########################################################################
92
93 /*************************************************************************
94 |*
95 |* Constructor / Destructor
96 |*
97 |************************************************************************/
98
SvxHpLinkDlg(Window * pParent,SfxBindings * pBindings)99 SvxHpLinkDlg::SvxHpLinkDlg (Window* pParent, SfxBindings* pBindings)
100 : IconChoiceDialog( pParent, CUI_RES ( RID_SVXDLG_NEWHYPERLINK ) ),
101 maCtrl ( SID_HYPERLINK_GETLINK, *pBindings, this ),
102 mpBindings ( pBindings ),
103 mbReadOnly ( sal_False ),
104 mbIsHTMLDoc ( sal_False )
105 {
106 SetUniqueId( HID_HYPERLINK_DIALOG );
107 mbGrabFocus = sal_True;
108 // insert pages
109 Image aImage;
110 Image aImageHC;
111 String aStrTitle;
112 SvxIconChoiceCtrlEntry* pEntry = NULL;
113
114 aStrTitle = CUI_RESSTR( RID_SVXSTR_HYPERDLG_HLINETTP );
115 aImage = Image( CUI_RES ( RID_SVXBMP_HLINETTP ) );
116 aImageHC = Image( CUI_RES ( RID_SVXBMP_HLINETTP_H ) );
117 pEntry = AddTabPage ( RID_SVXPAGE_HYPERLINK_INTERNET, aStrTitle, aImage, aImageHC, SvxHyperlinkInternetTp::Create );
118 pEntry->SetQuickHelpText( CUI_RESSTR( RID_SVXSTR_HYPERDLG_HLINETTP_HELP ) );
119 aStrTitle = CUI_RESSTR( RID_SVXSTR_HYPERDLG_HLMAILTP );
120 aImage = Image( CUI_RES ( RID_SVXBMP_HLMAILTP ) );
121 aImageHC = Image( CUI_RES ( RID_SVXBMP_HLMAILTP_H ) );
122 pEntry = AddTabPage ( RID_SVXPAGE_HYPERLINK_MAIL, aStrTitle, aImage, aImageHC, SvxHyperlinkMailTp::Create );
123 pEntry->SetQuickHelpText( CUI_RESSTR( RID_SVXSTR_HYPERDLG_HLMAILTP_HELP ) );
124 aStrTitle = CUI_RESSTR( RID_SVXSTR_HYPERDLG_HLDOCTP );
125 aImage = Image( CUI_RES ( RID_SVXBMP_HLDOCTP ) );
126 aImageHC = Image( CUI_RES ( RID_SVXBMP_HLDOCTP_H ) );
127 pEntry = AddTabPage ( RID_SVXPAGE_HYPERLINK_DOCUMENT, aStrTitle, aImage, aImageHC, SvxHyperlinkDocTp::Create );
128 pEntry->SetQuickHelpText( CUI_RESSTR( RID_SVXSTR_HYPERDLG_HLDOCTP_HELP ) );
129 aStrTitle = CUI_RESSTR( RID_SVXSTR_HYPERDLG_HLDOCNTP );
130 aImage = Image( CUI_RES ( RID_SVXBMP_HLDOCNTP ) );
131 aImageHC = Image( CUI_RES ( RID_SVXBMP_HLDOCNTP_H ) );
132 pEntry = AddTabPage ( RID_SVXPAGE_HYPERLINK_NEWDOCUMENT, aStrTitle, aImage, aImageHC, SvxHyperlinkNewDocTp::Create );
133 pEntry->SetQuickHelpText( CUI_RESSTR( RID_SVXSTR_HYPERDLG_HLDOCNTP_HELP ) );
134
135 // create itemset for tabpages
136 mpItemSet = new SfxItemSet( SFX_APP()->GetPool(), SID_HYPERLINK_GETLINK,
137 SID_HYPERLINK_SETLINK );
138
139 SvxHyperlinkItem aItem;
140 mpItemSet->Put (aItem, SID_HYPERLINK_GETLINK);
141
142 SetInputSet (mpItemSet);
143
144 // Init Dialog
145 Start (sal_False);
146
147 pBindings->Update( SID_READONLY_MODE );
148
149 // set OK/Cancel - button
150 GetOKButton().SetText ( CUI_RESSTR(RID_SVXSTR_HYPDLG_APPLYBUT) );
151 GetCancelButton().SetText ( CUI_RESSTR(RID_SVXSTR_HYPDLG_CLOSEBUT) );
152
153 GetOKButton().SetClickHdl ( LINK ( this, SvxHpLinkDlg, ClickApplyHdl_Impl ) );
154 GetCancelButton().SetClickHdl( LINK ( this, SvxHpLinkDlg, ClickCloseHdl_Impl ) );
155 }
156
~SvxHpLinkDlg()157 SvxHpLinkDlg::~SvxHpLinkDlg ()
158 {
159 // delete config item, so the base class (IconChoiceDialog) can not load it on the next start
160 SvtViewOptions aViewOpt( E_TABDIALOG, String::CreateFromInt32( SID_HYPERLINK_DIALOG ) );
161 aViewOpt.Delete();
162
163 delete mpItemSet;
164 }
165
166 /*************************************************************************
167 |*
168 |* Close Dialog-Window
169 |*
170 |************************************************************************/
171
Close()172 sal_Bool SvxHpLinkDlg::Close()
173 {
174 GetDispatcher()->Execute( SID_HYPERLINK_DIALOG,
175 SFX_CALLMODE_ASYNCHRON |
176 SFX_CALLMODE_RECORD);
177 return sal_True;
178 }
179
180 /*************************************************************************
181 |*
182 |* When extrawindow is visible and its never moved by user, then move that
183 |* window, too.
184 |*
185 |************************************************************************/
186
Move()187 void SvxHpLinkDlg::Move()
188 {
189 SvxHyperlinkTabPageBase* pCurrentPage = ( SvxHyperlinkTabPageBase* )
190 GetTabPage ( GetCurPageId() );
191
192 if( pCurrentPage->IsMarkWndVisible () )
193 {
194 // Pos&Size of this dialog-window
195 Point aDlgPos ( GetPosPixel () );
196 Size aDlgSize ( GetSizePixel () );
197
198 // Size of Office-Main-Window
199 Size aWindowSize( SFX_APP()->GetTopWindow()->GetSizePixel() );
200
201 // Size of Extrawindow
202 Size aExtraWndSize( pCurrentPage->GetSizeExtraWnd() );
203
204 sal_Bool bDoInvalid ;
205 if( aDlgPos.X()+(1.02*aDlgSize.Width())+aExtraWndSize.Width() > aWindowSize.Width() )
206 {
207 if( aDlgPos.X() - ( 0.02*aDlgSize.Width() ) - aExtraWndSize.Width() < 0 )
208 {
209 // Pos Extrawindow anywhere
210 bDoInvalid = pCurrentPage->MoveToExtraWnd( Point( 1, long(1.1*aDlgPos.Y()) ), sal_True );
211 }
212 else
213 {
214 // Pos Extrawindow on the left side of Dialog
215 bDoInvalid = pCurrentPage->MoveToExtraWnd( aDlgPos -
216 Point( long(0.02*aDlgSize.Width()), 0 ) -
217 Point( aExtraWndSize.Width(), 0 ) );
218 }
219 }
220 else
221 {
222 // Pos Extrawindow on the right side of Dialog
223 bDoInvalid = pCurrentPage->MoveToExtraWnd ( aDlgPos + Point( long(1.02*aDlgSize.Width()), 0 ) );
224 }
225
226 if ( bDoInvalid )
227 Invalidate(INVALIDATE_BACKGROUND);
228 }
229
230 Window::Move();
231 }
232
233 /*long SvxHpLinkDlg::PreNotify( NotifyEvent& rNEvt )
234 {
235 long nRet = 0;
236
237 if( rNEvt.GetType() == EVENT_KEYINPUT )
238 {
239 DBG_ASSERT( rNEvt.GetKeyEvent(), "-SvxHpLinkDlg::PreNotify(): no KeyEvent for key event?!" );
240
241 const KeyEvent* pKEvt = rNEvt.GetKeyEvent();
242
243 if( KEY_MOD2 == pKEvt->GetKeyCode().GetModifier() && pKEvt->GetCharCode() && HandleShortCutKey( *pKEvt ) )
244 nRet = 1;
245 }
246
247 if( !nRet )
248 nRet = IconChoiceDialog::PreNotify( rNEvt );
249
250 return nRet;
251 }*/
252
253 /*************************************************************************
254 |*
255 |* Click on Apply-button
256 |*
257 |************************************************************************/
258
IMPL_LINK(SvxHpLinkDlg,ClickApplyHdl_Impl,void *,EMPTYARG)259 IMPL_LINK ( SvxHpLinkDlg, ClickApplyHdl_Impl, void *, EMPTYARG )
260 {
261 SfxItemSet aItemSet( SFX_APP()->GetPool(), SID_HYPERLINK_GETLINK,
262 SID_HYPERLINK_SETLINK );
263
264 SvxHyperlinkTabPageBase* pCurrentPage = (SvxHyperlinkTabPageBase*)
265 GetTabPage ( GetCurPageId() );
266
267 if ( pCurrentPage->AskApply() )
268 {
269 pCurrentPage->FillItemSet( aItemSet );
270
271 SvxHyperlinkItem *aItem = (SvxHyperlinkItem *)
272 aItemSet.GetItem (SID_HYPERLINK_SETLINK);
273
274 String aStrEmpty;
275 if ( aItem->GetURL() != aStrEmpty )
276 GetDispatcher()->Execute( SID_HYPERLINK_SETLINK, SFX_CALLMODE_ASYNCHRON |
277 SFX_CALLMODE_RECORD, aItem, 0L);
278
279 ( (SvxHyperlinkTabPageBase*)GetTabPage ( GetCurPageId() ) )->DoApply();
280 }
281
282 return( 0L );
283 }
284
285 /*************************************************************************
286 |*
287 |* Click on Close-button
288 |*
289 |************************************************************************/
290
IMPL_LINK(SvxHpLinkDlg,ClickCloseHdl_Impl,void *,EMPTYARG)291 IMPL_LINK ( SvxHpLinkDlg, ClickCloseHdl_Impl, void *, EMPTYARG )
292 {
293 Close();
294
295 return( 0L );
296 }
297
298 /*************************************************************************
299 |*
300 |* Set Page
301 |*
302 |************************************************************************/
303
SetPage(SvxHyperlinkItem * pItem)304 sal_uInt16 SvxHpLinkDlg::SetPage ( SvxHyperlinkItem* pItem )
305 {
306 sal_uInt16 nPageId = RID_SVXPAGE_HYPERLINK_INTERNET;
307
308 String aStrURL ( pItem->GetURL() );
309 INetURLObject aURL ( aStrURL );
310 INetProtocol eProtocolTyp = aURL.GetProtocol();
311
312 switch ( eProtocolTyp )
313 {
314 case INET_PROT_HTTP :
315 case INET_PROT_FTP :
316 case INET_PROT_TELNET :
317 nPageId = RID_SVXPAGE_HYPERLINK_INTERNET;
318 break;
319 case INET_PROT_FILE :
320 case INET_PROT_POP3 :
321 case INET_PROT_IMAP :
322 nPageId = RID_SVXPAGE_HYPERLINK_DOCUMENT;
323 break;
324 case INET_PROT_MAILTO :
325 case INET_PROT_NEWS :
326 nPageId = RID_SVXPAGE_HYPERLINK_MAIL;
327 break;
328 default :
329 sal_Char const sNewsSrvScheme[] = "news://";
330 // TODO news:// is nonsense
331
332 if ( aStrURL.SearchAscii( sNewsSrvScheme ) == 0 )
333 nPageId = RID_SVXPAGE_HYPERLINK_DOCUMENT;
334 else
335 {
336 sal_Char const sHash[] = "#";
337 if( aStrURL.SearchAscii( sHash ) == 0 )
338 nPageId = RID_SVXPAGE_HYPERLINK_DOCUMENT;
339 else
340 {
341 eProtocolTyp = INET_PROT_NOT_VALID;
342 nPageId = GetCurPageId();
343 }
344 }
345 break;
346 }
347
348 ShowPage (nPageId);
349
350 SvxHyperlinkTabPageBase* pCurrentPage = (SvxHyperlinkTabPageBase*)GetTabPage( nPageId );
351
352 mbIsHTMLDoc = (pItem->GetInsertMode() & HLINK_HTMLMODE) ? true : false;
353
354 SfxItemSet& aPageSet = (SfxItemSet&)GetTabPage (nPageId)->GetItemSet ();
355 aPageSet.Put ( *pItem );
356
357 pCurrentPage->Reset( aPageSet );
358 if ( mbGrabFocus )
359 {
360 pCurrentPage->SetInitFocus(); // #92535# grab the focus only once at initialization
361 mbGrabFocus = sal_False;
362 }
363 return nPageId;
364 }
365
366 /*************************************************************************
367 |*
368 |* Enable/Disable to browse targets in a html-doc
369 |*
370 |************************************************************************/
371
EnableInetBrowse(sal_Bool bEnable)372 void SvxHpLinkDlg::EnableInetBrowse( sal_Bool bEnable )
373 {
374 SvxHyperlinkTabPageBase* pCurrentPage = ( SvxHyperlinkTabPageBase* )
375 GetTabPage ( GetCurPageId() );
376 pCurrentPage->SetOnlineMode( bEnable );
377 }
378
379 /*************************************************************************
380 |*
381 |* Enable/Disable ReadOnly mode
382 |*
383 |************************************************************************/
384
SetReadOnlyMode(sal_Bool bRdOnly)385 void SvxHpLinkDlg::SetReadOnlyMode( sal_Bool bRdOnly )
386 {
387 mbReadOnly = bRdOnly;
388 if ( bRdOnly )
389 GetOKButton().Disable();
390 else
391 GetOKButton().Enable();
392 }
393
394 /*************************************************************************
395 |*
396 |* late-initialization of newly created pages
397 |*
398 |************************************************************************/
399
PageCreated(sal_uInt16,IconChoicePage & rPage)400 void SvxHpLinkDlg::PageCreated( sal_uInt16 /*nId*/, IconChoicePage& rPage )
401 {
402 SvxHyperlinkTabPageBase& rHyperlinkPage = dynamic_cast< SvxHyperlinkTabPageBase& >( rPage );
403 Reference< XFrame > xDocumentFrame;
404 if ( mpBindings )
405 xDocumentFrame = mpBindings->GetActiveFrame();
406 OSL_ENSURE( xDocumentFrame.is(), "SvxHpLinkDlg::PageCreated: macro assignment functionality won't work with a proper frame!" );
407 rHyperlinkPage.SetDocumentFrame( xDocumentFrame );
408 }
409