Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include <vcl/settings.hxx>
30 : : #include <unotools/viewoptions.hxx>
31 : : #include "cuihyperdlg.hxx"
32 : : #include "hlinettp.hxx"
33 : : #include "hlmailtp.hxx"
34 : : #include "hldoctp.hxx"
35 : : #include "hldocntp.hxx"
36 : : #include "hyperdlg.hrc"
37 : : #include <svx/svxids.hrc> // SID_READONLY_MODE
38 : :
39 : : using ::com::sun::star::uno::Reference;
40 : : using ::com::sun::star::frame::XFrame;
41 : :
42 : : //########################################################################
43 : : //# #
44 : : //# Childwindow-Wrapper-Class #
45 : : //# #
46 : : //########################################################################
47 : :
48 : 0 : SvxHlinkCtrl::SvxHlinkCtrl( sal_uInt16 _nId, SfxBindings & rBindings, SvxHpLinkDlg* pDlg )
49 : : : SfxControllerItem ( _nId, rBindings )
50 : : ,aOnlineForwarder ( SID_INTERNET_ONLINE , *this )
51 [ # # ][ # # ]: 0 : ,aRdOnlyForwarder ( SID_READONLY_MODE, *this )
52 : : {
53 : 0 : pParent = pDlg;
54 : 0 : }
55 : :
56 : 0 : void SvxHlinkCtrl::StateChanged( sal_uInt16 nSID, SfxItemState eState,
57 : : const SfxPoolItem* pState )
58 : : {
59 [ # # ]: 0 : if ( eState == SFX_ITEM_AVAILABLE )
60 : : {
61 [ # # # # ]: 0 : switch ( nSID )
62 : : {
63 : : case SID_INTERNET_ONLINE :
64 : : {
65 : 0 : pParent->EnableInetBrowse( !( (SfxBoolItem*)pState)->GetValue() );
66 : : }
67 : 0 : break;
68 : : case SID_HYPERLINK_GETLINK :
69 : : {
70 : 0 : pParent->SetPage ( (SvxHyperlinkItem*)pState);
71 : : }
72 : 0 : break;
73 : : case SID_READONLY_MODE :
74 : : {
75 : 0 : pParent->SetReadOnlyMode( ( (SfxBoolItem*)pState)->GetValue() == sal_True );
76 : : }
77 : 0 : break;
78 : : }
79 : : }
80 : 0 : }
81 : :
82 : :
83 : :
84 : : // -----------------------------------------------------------------------
85 : :
86 : :
87 : :
88 : : //########################################################################
89 : : //# #
90 : : //# Hyperlink - Dialog #
91 : : //# #
92 : : //########################################################################
93 : :
94 : : /*************************************************************************
95 : : |*
96 : : |* Contructor / Destructor
97 : : |*
98 : : |************************************************************************/
99 : :
100 : 0 : SvxHpLinkDlg::SvxHpLinkDlg (Window* pParent, SfxBindings* pBindings)
101 : 0 : : IconChoiceDialog( pParent, CUI_RES ( RID_SVXDLG_NEWHYPERLINK ) ),
102 : : maCtrl ( SID_HYPERLINK_GETLINK, *pBindings, this ),
103 : : mpBindings ( pBindings ),
104 : : mbReadOnly ( sal_False ),
105 [ # # ][ # # ]: 0 : mbIsHTMLDoc ( sal_False )
106 : : {
107 [ # # ]: 0 : SetUniqueId( HID_HYPERLINK_DIALOG );
108 : 0 : mbGrabFocus = sal_True;
109 : : // insert pages
110 [ # # ]: 0 : Image aImage;
111 [ # # ]: 0 : String aStrTitle;
112 : 0 : SvxIconChoiceCtrlEntry* pEntry = NULL;
113 : :
114 [ # # ][ # # ]: 0 : aStrTitle = CUI_RESSTR( RID_SVXSTR_HYPERDLG_HLINETTP );
[ # # ]
115 [ # # ][ # # ]: 0 : aImage = Image( CUI_RES ( RID_SVXBMP_HLINETTP ) );
[ # # ][ # # ]
116 [ # # ]: 0 : pEntry = AddTabPage ( RID_SVXPAGE_HYPERLINK_INTERNET, aStrTitle, aImage, SvxHyperlinkInternetTp::Create );
117 [ # # ][ # # ]: 0 : pEntry->SetQuickHelpText( CUI_RESSTR( RID_SVXSTR_HYPERDLG_HLINETTP_HELP ) );
[ # # ][ # # ]
[ # # ]
118 [ # # ][ # # ]: 0 : aStrTitle = CUI_RESSTR( RID_SVXSTR_HYPERDLG_HLMAILTP );
[ # # ]
119 [ # # ][ # # ]: 0 : aImage = Image( CUI_RES ( RID_SVXBMP_HLMAILTP ) );
[ # # ][ # # ]
120 [ # # ]: 0 : pEntry = AddTabPage ( RID_SVXPAGE_HYPERLINK_MAIL, aStrTitle, aImage, SvxHyperlinkMailTp::Create );
121 [ # # ][ # # ]: 0 : pEntry->SetQuickHelpText( CUI_RESSTR( RID_SVXSTR_HYPERDLG_HLMAILTP_HELP ) );
[ # # ][ # # ]
[ # # ]
122 [ # # ][ # # ]: 0 : aStrTitle = CUI_RESSTR( RID_SVXSTR_HYPERDLG_HLDOCTP );
[ # # ]
123 [ # # ][ # # ]: 0 : aImage = Image( CUI_RES ( RID_SVXBMP_HLDOCTP ) );
[ # # ][ # # ]
124 [ # # ]: 0 : pEntry = AddTabPage ( RID_SVXPAGE_HYPERLINK_DOCUMENT, aStrTitle, aImage, SvxHyperlinkDocTp::Create );
125 [ # # ][ # # ]: 0 : pEntry->SetQuickHelpText( CUI_RESSTR( RID_SVXSTR_HYPERDLG_HLDOCTP_HELP ) );
[ # # ][ # # ]
[ # # ]
126 [ # # ][ # # ]: 0 : aStrTitle = CUI_RESSTR( RID_SVXSTR_HYPERDLG_HLDOCNTP );
[ # # ]
127 [ # # ][ # # ]: 0 : aImage = Image( CUI_RES ( RID_SVXBMP_HLDOCNTP ) );
[ # # ][ # # ]
128 [ # # ]: 0 : pEntry = AddTabPage ( RID_SVXPAGE_HYPERLINK_NEWDOCUMENT, aStrTitle, aImage, SvxHyperlinkNewDocTp::Create );
129 [ # # ][ # # ]: 0 : pEntry->SetQuickHelpText( CUI_RESSTR( RID_SVXSTR_HYPERDLG_HLDOCNTP_HELP ) );
[ # # ][ # # ]
[ # # ]
130 : :
131 : : // create itemset for tabpages
132 [ # # ]: 0 : mpItemSet = new SfxItemSet( SFX_APP()->GetPool(), SID_HYPERLINK_GETLINK,
133 [ # # ][ # # ]: 0 : SID_HYPERLINK_SETLINK );
134 : :
135 [ # # ]: 0 : SvxHyperlinkItem aItem;
136 [ # # ]: 0 : mpItemSet->Put (aItem, SID_HYPERLINK_GETLINK);
137 : :
138 [ # # ]: 0 : SetInputSet (mpItemSet);
139 : :
140 : : // Init Dialog
141 [ # # ]: 0 : Start (sal_False);
142 : :
143 [ # # ]: 0 : pBindings->Update( SID_READONLY_MODE );
144 : :
145 : : // set OK/Cancel - button
146 [ # # ][ # # ]: 0 : GetOKButton().SetText ( CUI_RESSTR(RID_SVXSTR_HYPDLG_APPLYBUT) );
[ # # ][ # # ]
[ # # ]
147 [ # # ][ # # ]: 0 : GetCancelButton().SetText ( CUI_RESSTR(RID_SVXSTR_HYPDLG_CLOSEBUT) );
[ # # ][ # # ]
[ # # ]
148 : :
149 [ # # ]: 0 : GetOKButton().SetClickHdl ( LINK ( this, SvxHpLinkDlg, ClickApplyHdl_Impl ) );
150 [ # # ][ # # ]: 0 : GetCancelButton().SetClickHdl( LINK ( this, SvxHpLinkDlg, ClickCloseHdl_Impl ) );
[ # # ][ # # ]
151 : 0 : }
152 : :
153 [ # # ]: 0 : SvxHpLinkDlg::~SvxHpLinkDlg ()
154 : : {
155 : : // delete config item, so the base class (IconChoiceDialog) can not load it on the next start
156 [ # # ][ # # ]: 0 : SvtViewOptions aViewOpt( E_TABDIALOG, String::CreateFromInt32( SID_HYPERLINK_DIALOG ) );
[ # # ][ # # ]
157 [ # # ]: 0 : aViewOpt.Delete();
158 : :
159 [ # # ][ # # ]: 0 : delete mpItemSet;
[ # # ]
160 [ # # ]: 0 : }
161 : :
162 : : /*************************************************************************
163 : : |*
164 : : |* Close Dialog-Window
165 : : |*
166 : : |************************************************************************/
167 : :
168 : 0 : sal_Bool SvxHpLinkDlg::Close()
169 : : {
170 : : GetDispatcher()->Execute( SID_HYPERLINK_DIALOG,
171 : : SFX_CALLMODE_ASYNCHRON |
172 : 0 : SFX_CALLMODE_RECORD);
173 : 0 : return sal_True;
174 : : }
175 : :
176 : : /*************************************************************************
177 : : |*
178 : : |* When extrawindow is visible and its never moved by user, then move that
179 : : |* window, too.
180 : : |*
181 : : |************************************************************************/
182 : :
183 : 0 : void SvxHpLinkDlg::Move()
184 : : {
185 : : SvxHyperlinkTabPageBase* pCurrentPage = ( SvxHyperlinkTabPageBase* )
186 : 0 : GetTabPage ( GetCurPageId() );
187 : :
188 [ # # ]: 0 : if( pCurrentPage->IsMarkWndVisible () )
189 : : {
190 : : // Pos&Size of this dialog-window
191 [ # # ]: 0 : Point aDlgPos ( GetPosPixel () );
192 [ # # ]: 0 : Size aDlgSize ( GetSizePixel () );
193 : :
194 : : // Size of Office-Main-Window
195 [ # # ][ # # ]: 0 : Size aWindowSize( SFX_APP()->GetTopWindow()->GetSizePixel() );
[ # # ]
196 : :
197 : : // Size of Extrawindow
198 [ # # ]: 0 : Size aExtraWndSize( pCurrentPage->GetSizeExtraWnd() );
199 : :
200 : : sal_Bool bDoInvalid ;
201 [ # # ]: 0 : if( aDlgPos.X()+(1.02*aDlgSize.Width())+aExtraWndSize.Width() > aWindowSize.Width() )
202 : : {
203 [ # # ]: 0 : if( aDlgPos.X() - ( 0.02*aDlgSize.Width() ) - aExtraWndSize.Width() < 0 )
204 : : {
205 : : // Pos Extrawindow anywhere
206 [ # # ]: 0 : bDoInvalid = pCurrentPage->MoveToExtraWnd( Point( 1, long(1.1*aDlgPos.Y()) ), sal_True );
207 : : }
208 : : else
209 : : {
210 : : // Pos Extrawindow on the left side of Dialog
211 : : bDoInvalid = pCurrentPage->MoveToExtraWnd( aDlgPos -
212 : 0 : Point( long(0.02*aDlgSize.Width()), 0 ) -
213 [ # # ]: 0 : Point( aExtraWndSize.Width(), 0 ) );
214 : : }
215 : : }
216 : : else
217 : : {
218 : : // Pos Extrawindow on the right side of Dialog
219 [ # # ]: 0 : bDoInvalid = pCurrentPage->MoveToExtraWnd ( aDlgPos + Point( long(1.02*aDlgSize.Width()), 0 ) );
220 : : }
221 : :
222 [ # # ]: 0 : if ( bDoInvalid )
223 [ # # ]: 0 : Invalidate(INVALIDATE_BACKGROUND);
224 : : }
225 : :
226 : 0 : Window::Move();
227 : 0 : }
228 : :
229 : : /*************************************************************************
230 : : |*
231 : : |* Click on Apply-button
232 : : |*
233 : : |************************************************************************/
234 : :
235 : 0 : IMPL_LINK_NOARG(SvxHpLinkDlg, ClickApplyHdl_Impl)
236 : : {
237 [ # # ]: 0 : SfxItemSet aItemSet( SFX_APP()->GetPool(), SID_HYPERLINK_GETLINK,
238 [ # # ]: 0 : SID_HYPERLINK_SETLINK );
239 : :
240 : : SvxHyperlinkTabPageBase* pCurrentPage = (SvxHyperlinkTabPageBase*)
241 [ # # ]: 0 : GetTabPage ( GetCurPageId() );
242 : :
243 [ # # ][ # # ]: 0 : if ( pCurrentPage->AskApply() )
244 : : {
245 [ # # ]: 0 : pCurrentPage->FillItemSet( aItemSet );
246 : :
247 : : SvxHyperlinkItem *aItem = (SvxHyperlinkItem *)
248 [ # # ]: 0 : aItemSet.GetItem (SID_HYPERLINK_SETLINK);
249 : :
250 [ # # ]: 0 : String aStrEmpty;
251 [ # # ][ # # ]: 0 : if ( aItem->GetURL() != aStrEmpty )
252 : : GetDispatcher()->Execute( SID_HYPERLINK_SETLINK, SFX_CALLMODE_ASYNCHRON |
253 [ # # ]: 0 : SFX_CALLMODE_RECORD, aItem, 0L);
254 : :
255 [ # # ][ # # ]: 0 : ( (SvxHyperlinkTabPageBase*)GetTabPage ( GetCurPageId() ) )->DoApply();
[ # # ]
256 : : }
257 : :
258 [ # # ]: 0 : return( 0L );
259 : : }
260 : :
261 : : /*************************************************************************
262 : : |*
263 : : |* Click on Close-button
264 : : |*
265 : : |************************************************************************/
266 : :
267 : 0 : IMPL_LINK_NOARG(SvxHpLinkDlg, ClickCloseHdl_Impl)
268 : : {
269 : 0 : Close();
270 : :
271 : 0 : return( 0L );
272 : : }
273 : :
274 : : /*************************************************************************
275 : : |*
276 : : |* Set Page
277 : : |*
278 : : |************************************************************************/
279 : :
280 : 0 : sal_uInt16 SvxHpLinkDlg::SetPage ( SvxHyperlinkItem* pItem )
281 : : {
282 : 0 : sal_uInt16 nPageId = RID_SVXPAGE_HYPERLINK_INTERNET;
283 : :
284 [ # # ]: 0 : String aStrURL ( pItem->GetURL() );
285 [ # # ][ # # ]: 0 : INetURLObject aURL ( aStrURL );
286 : 0 : INetProtocol eProtocolTyp = aURL.GetProtocol();
287 : :
288 [ # # # # ]: 0 : switch ( eProtocolTyp )
289 : : {
290 : : case INET_PROT_HTTP :
291 : : case INET_PROT_FTP :
292 : 0 : nPageId = RID_SVXPAGE_HYPERLINK_INTERNET;
293 : : break;
294 : : case INET_PROT_FILE :
295 : : case INET_PROT_POP3 :
296 : : case INET_PROT_IMAP :
297 : 0 : nPageId = RID_SVXPAGE_HYPERLINK_DOCUMENT;
298 : : break;
299 : : case INET_PROT_MAILTO :
300 : : case INET_PROT_NEWS :
301 : 0 : nPageId = RID_SVXPAGE_HYPERLINK_MAIL;
302 : : break;
303 : : default :
304 : 0 : sal_Char const sNewsSrvScheme[] = "news://";
305 : : // TODO news:// is nonsense
306 : :
307 [ # # ][ # # ]: 0 : if ( aStrURL.SearchAscii( sNewsSrvScheme ) == 0 )
308 : 0 : nPageId = RID_SVXPAGE_HYPERLINK_DOCUMENT;
309 : : else
310 : : {
311 : 0 : sal_Char const sHash[] = "#";
312 [ # # ][ # # ]: 0 : if( aStrURL.SearchAscii( sHash ) == 0 )
313 : 0 : nPageId = RID_SVXPAGE_HYPERLINK_DOCUMENT;
314 : : else
315 : : {
316 : 0 : eProtocolTyp = INET_PROT_NOT_VALID;
317 : 0 : nPageId = GetCurPageId();
318 : : }
319 : : }
320 : : break;
321 : : }
322 : :
323 [ # # ]: 0 : ShowPage (nPageId);
324 : :
325 [ # # ]: 0 : SvxHyperlinkTabPageBase* pCurrentPage = (SvxHyperlinkTabPageBase*)GetTabPage( nPageId );
326 : :
327 : 0 : mbIsHTMLDoc = (pItem->GetInsertMode() & HLINK_HTMLMODE) ? true : false;
328 : :
329 [ # # ]: 0 : SfxItemSet& aPageSet = (SfxItemSet&)GetTabPage (nPageId)->GetItemSet ();
330 [ # # ]: 0 : aPageSet.Put ( *pItem );
331 : :
332 [ # # ]: 0 : pCurrentPage->Reset( aPageSet );
333 [ # # ]: 0 : if ( mbGrabFocus )
334 : : {
335 [ # # ]: 0 : pCurrentPage->SetInitFocus(); // #92535# grab the focus only once at initialization
336 : 0 : mbGrabFocus = sal_False;
337 : : }
338 [ # # ][ # # ]: 0 : return nPageId;
339 : : }
340 : :
341 : : /*************************************************************************
342 : : |*
343 : : |* Enable/Disable to browse targets in a html-doc
344 : : |*
345 : : |************************************************************************/
346 : :
347 : 0 : void SvxHpLinkDlg::EnableInetBrowse( sal_Bool bEnable )
348 : : {
349 : : SvxHyperlinkTabPageBase* pCurrentPage = ( SvxHyperlinkTabPageBase* )
350 : 0 : GetTabPage ( GetCurPageId() );
351 : 0 : pCurrentPage->SetOnlineMode( bEnable );
352 : 0 : }
353 : :
354 : : /*************************************************************************
355 : : |*
356 : : |* Enable/Disable ReadOnly mode
357 : : |*
358 : : |************************************************************************/
359 : :
360 : 0 : void SvxHpLinkDlg::SetReadOnlyMode( sal_Bool bRdOnly )
361 : : {
362 : 0 : mbReadOnly = bRdOnly;
363 [ # # ]: 0 : if ( bRdOnly )
364 : 0 : GetOKButton().Disable();
365 : : else
366 : 0 : GetOKButton().Enable();
367 : 0 : }
368 : :
369 : : /*************************************************************************
370 : : |*
371 : : |* late-initialization of newly created pages
372 : : |*
373 : : |************************************************************************/
374 : :
375 : 0 : void SvxHpLinkDlg::PageCreated( sal_uInt16 /*nId*/, IconChoicePage& rPage )
376 : : {
377 [ # # ]: 0 : SvxHyperlinkTabPageBase& rHyperlinkPage = dynamic_cast< SvxHyperlinkTabPageBase& >( rPage );
378 : 0 : Reference< XFrame > xDocumentFrame;
379 [ # # ]: 0 : if ( mpBindings )
380 [ # # ][ # # ]: 0 : xDocumentFrame = mpBindings->GetActiveFrame();
381 : : OSL_ENSURE( xDocumentFrame.is(), "SvxHpLinkDlg::PageCreated: macro assignment functionality won't work with a proper frame!" );
382 [ # # ]: 0 : rHyperlinkPage.SetDocumentFrame( xDocumentFrame );
383 : 0 : }
384 : :
385 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|