update credits
[LibreOffice.git] / cui / source / dialogs / cuihyperdlg.cxx
blob2911204fbbb2fc231d61f82d3169bf805374ab28
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 <vcl/settings.hxx>
21 #include <unotools/viewoptions.hxx>
22 #include "cuihyperdlg.hxx"
23 #include "hlinettp.hxx"
24 #include "hlmailtp.hxx"
25 #include "hldoctp.hxx"
26 #include "hldocntp.hxx"
27 #include "hyperdlg.hrc"
28 #include <svx/svxids.hrc> // SID_READONLY_MODE
30 using ::com::sun::star::uno::Reference;
31 using ::com::sun::star::frame::XFrame;
33 //########################################################################
34 //# #
35 //# Childwindow-Wrapper-Class #
36 //# #
37 //########################################################################
39 SvxHlinkCtrl::SvxHlinkCtrl( sal_uInt16 _nId, SfxBindings & rBindings, SvxHpLinkDlg* pDlg )
40 : SfxControllerItem ( _nId, rBindings )
41 ,aOnlineForwarder ( SID_INTERNET_ONLINE , *this )
42 ,aRdOnlyForwarder ( SID_READONLY_MODE, *this )
44 pParent = pDlg;
47 void SvxHlinkCtrl::StateChanged( sal_uInt16 nSID, SfxItemState eState,
48 const SfxPoolItem* pState )
50 if ( eState == SFX_ITEM_AVAILABLE )
52 switch ( nSID )
54 case SID_INTERNET_ONLINE :
56 pParent->EnableInetBrowse( !( (SfxBoolItem*)pState)->GetValue() );
58 break;
59 case SID_HYPERLINK_GETLINK :
61 pParent->SetPage ( (SvxHyperlinkItem*)pState);
63 break;
64 case SID_READONLY_MODE :
66 pParent->SetReadOnlyMode( ( (SfxBoolItem*)pState)->GetValue() == sal_True );
68 break;
75 // -----------------------------------------------------------------------
79 //########################################################################
80 //# #
81 //# Hyperlink - Dialog #
82 //# #
83 //########################################################################
85 /*************************************************************************
87 |* Contructor / Destructor
89 |************************************************************************/
91 SvxHpLinkDlg::SvxHpLinkDlg (Window* pParent, SfxBindings* pBindings)
92 : IconChoiceDialog( pParent, CUI_RES ( RID_SVXDLG_NEWHYPERLINK ) ),
93 maCtrl ( SID_HYPERLINK_GETLINK, *pBindings, this ),
94 mpBindings ( pBindings ),
95 mbReadOnly ( sal_False ),
96 mbIsHTMLDoc ( sal_False )
98 SetUniqueId( HID_HYPERLINK_DIALOG );
99 mbGrabFocus = sal_True;
100 // insert pages
101 Image aImage;
102 String aStrTitle;
103 SvxIconChoiceCtrlEntry* pEntry = NULL;
105 aStrTitle = CUI_RESSTR( RID_SVXSTR_HYPERDLG_HLINETTP );
106 aImage = Image( CUI_RES ( RID_SVXBMP_HLINETTP ) );
107 pEntry = AddTabPage ( RID_SVXPAGE_HYPERLINK_INTERNET, aStrTitle, aImage, SvxHyperlinkInternetTp::Create );
108 pEntry->SetQuickHelpText( CUI_RESSTR( RID_SVXSTR_HYPERDLG_HLINETTP_HELP ) );
109 aStrTitle = CUI_RESSTR( RID_SVXSTR_HYPERDLG_HLMAILTP );
110 aImage = Image( CUI_RES ( RID_SVXBMP_HLMAILTP ) );
111 pEntry = AddTabPage ( RID_SVXPAGE_HYPERLINK_MAIL, aStrTitle, aImage, SvxHyperlinkMailTp::Create );
112 pEntry->SetQuickHelpText( CUI_RESSTR( RID_SVXSTR_HYPERDLG_HLMAILTP_HELP ) );
113 aStrTitle = CUI_RESSTR( RID_SVXSTR_HYPERDLG_HLDOCTP );
114 aImage = Image( CUI_RES ( RID_SVXBMP_HLDOCTP ) );
115 pEntry = AddTabPage ( RID_SVXPAGE_HYPERLINK_DOCUMENT, aStrTitle, aImage, SvxHyperlinkDocTp::Create );
116 pEntry->SetQuickHelpText( CUI_RESSTR( RID_SVXSTR_HYPERDLG_HLDOCTP_HELP ) );
117 aStrTitle = CUI_RESSTR( RID_SVXSTR_HYPERDLG_HLDOCNTP );
118 aImage = Image( CUI_RES ( RID_SVXBMP_HLDOCNTP ) );
119 pEntry = AddTabPage ( RID_SVXPAGE_HYPERLINK_NEWDOCUMENT, aStrTitle, aImage, SvxHyperlinkNewDocTp::Create );
120 pEntry->SetQuickHelpText( CUI_RESSTR( RID_SVXSTR_HYPERDLG_HLDOCNTP_HELP ) );
122 // create itemset for tabpages
123 mpItemSet = new SfxItemSet( SFX_APP()->GetPool(), SID_HYPERLINK_GETLINK,
124 SID_HYPERLINK_SETLINK );
126 SvxHyperlinkItem aItem;
127 mpItemSet->Put (aItem, SID_HYPERLINK_GETLINK);
129 SetInputSet (mpItemSet);
131 // Init Dialog
132 Start (sal_False);
134 pBindings->Update( SID_READONLY_MODE );
136 // set OK/Cancel - button
137 GetOKButton().SetText ( CUI_RESSTR(RID_SVXSTR_HYPDLG_APPLYBUT) );
138 GetCancelButton().SetText ( CUI_RESSTR(RID_SVXSTR_HYPDLG_CLOSEBUT) );
140 GetOKButton().SetClickHdl ( LINK ( this, SvxHpLinkDlg, ClickApplyHdl_Impl ) );
141 GetCancelButton().SetClickHdl( LINK ( this, SvxHpLinkDlg, ClickCloseHdl_Impl ) );
144 SvxHpLinkDlg::~SvxHpLinkDlg ()
146 // delete config item, so the base class (IconChoiceDialog) can not load it on the next start
147 SvtViewOptions aViewOpt( E_TABDIALOG, OUString::number(SID_HYPERLINK_DIALOG) );
148 aViewOpt.Delete();
150 delete mpItemSet;
153 /*************************************************************************
155 |* Close Dialog-Window
157 |************************************************************************/
159 sal_Bool SvxHpLinkDlg::Close()
161 GetDispatcher()->Execute( SID_HYPERLINK_DIALOG,
162 SFX_CALLMODE_ASYNCHRON |
163 SFX_CALLMODE_RECORD);
164 return sal_True;
167 /*************************************************************************
169 |* When extrawindow is visible and its never moved by user, then move that
170 |* window, too.
172 |************************************************************************/
174 void SvxHpLinkDlg::Move()
176 SvxHyperlinkTabPageBase* pCurrentPage = ( SvxHyperlinkTabPageBase* )
177 GetTabPage ( GetCurPageId() );
179 if( pCurrentPage->IsMarkWndVisible () )
181 // Pos&Size of this dialog-window
182 Point aDlgPos ( GetPosPixel () );
183 Size aDlgSize ( GetSizePixel () );
185 // Size of Office-Main-Window
186 Size aWindowSize( SFX_APP()->GetTopWindow()->GetSizePixel() );
188 // Size of Extrawindow
189 Size aExtraWndSize( pCurrentPage->GetSizeExtraWnd() );
191 sal_Bool bDoInvalid ;
192 if( aDlgPos.X()+(1.02*aDlgSize.Width())+aExtraWndSize.Width() > aWindowSize.Width() )
194 if( aDlgPos.X() - ( 0.02*aDlgSize.Width() ) - aExtraWndSize.Width() < 0 )
196 // Pos Extrawindow anywhere
197 bDoInvalid = pCurrentPage->MoveToExtraWnd( Point( 1, long(1.1*aDlgPos.Y()) ), sal_True );
199 else
201 // Pos Extrawindow on the left side of Dialog
202 bDoInvalid = pCurrentPage->MoveToExtraWnd( aDlgPos -
203 Point( long(0.02*aDlgSize.Width()), 0 ) -
204 Point( aExtraWndSize.Width(), 0 ) );
207 else
209 // Pos Extrawindow on the right side of Dialog
210 bDoInvalid = pCurrentPage->MoveToExtraWnd ( aDlgPos + Point( long(1.02*aDlgSize.Width()), 0 ) );
213 if ( bDoInvalid )
214 Invalidate(INVALIDATE_BACKGROUND);
217 Window::Move();
220 /*************************************************************************
222 |* Click on Apply-button
224 |************************************************************************/
226 IMPL_LINK_NOARG(SvxHpLinkDlg, ClickApplyHdl_Impl)
228 SfxItemSet aItemSet( SFX_APP()->GetPool(), SID_HYPERLINK_GETLINK,
229 SID_HYPERLINK_SETLINK );
231 SvxHyperlinkTabPageBase* pCurrentPage = (SvxHyperlinkTabPageBase*)
232 GetTabPage ( GetCurPageId() );
234 if ( pCurrentPage->AskApply() )
236 pCurrentPage->FillItemSet( aItemSet );
238 SvxHyperlinkItem *aItem = (SvxHyperlinkItem *)
239 aItemSet.GetItem (SID_HYPERLINK_SETLINK);
241 String aStrEmpty;
242 if ( aItem->GetURL() != aStrEmpty )
243 GetDispatcher()->Execute( SID_HYPERLINK_SETLINK, SFX_CALLMODE_ASYNCHRON |
244 SFX_CALLMODE_RECORD, aItem, 0L);
246 ( (SvxHyperlinkTabPageBase*)GetTabPage ( GetCurPageId() ) )->DoApply();
249 return( 0L );
252 /*************************************************************************
254 |* Click on Close-button
256 |************************************************************************/
258 IMPL_LINK_NOARG(SvxHpLinkDlg, ClickCloseHdl_Impl)
260 Close();
262 return( 0L );
265 /*************************************************************************
267 |* Set Page
269 |************************************************************************/
271 sal_uInt16 SvxHpLinkDlg::SetPage ( SvxHyperlinkItem* pItem )
273 sal_uInt16 nPageId = RID_SVXPAGE_HYPERLINK_INTERNET;
275 String aStrURL ( pItem->GetURL() );
276 INetURLObject aURL ( aStrURL );
277 INetProtocol eProtocolTyp = aURL.GetProtocol();
279 switch ( eProtocolTyp )
281 case INET_PROT_HTTP :
282 case INET_PROT_FTP :
283 nPageId = RID_SVXPAGE_HYPERLINK_INTERNET;
284 break;
285 case INET_PROT_FILE :
286 case INET_PROT_POP3 :
287 case INET_PROT_IMAP :
288 nPageId = RID_SVXPAGE_HYPERLINK_DOCUMENT;
289 break;
290 case INET_PROT_MAILTO :
291 case INET_PROT_NEWS :
292 nPageId = RID_SVXPAGE_HYPERLINK_MAIL;
293 break;
294 default :
295 sal_Char const sNewsSrvScheme[] = "news://";
296 // TODO news:// is nonsense
298 if ( aStrURL.SearchAscii( sNewsSrvScheme ) == 0 )
299 nPageId = RID_SVXPAGE_HYPERLINK_DOCUMENT;
300 else
302 sal_Char const sHash[] = "#";
303 if( aStrURL.SearchAscii( sHash ) == 0 )
304 nPageId = RID_SVXPAGE_HYPERLINK_DOCUMENT;
305 else
307 eProtocolTyp = INET_PROT_NOT_VALID;
308 nPageId = GetCurPageId();
311 break;
314 ShowPage (nPageId);
316 SvxHyperlinkTabPageBase* pCurrentPage = (SvxHyperlinkTabPageBase*)GetTabPage( nPageId );
318 mbIsHTMLDoc = (pItem->GetInsertMode() & HLINK_HTMLMODE) ? true : false;
320 SfxItemSet& aPageSet = (SfxItemSet&)GetTabPage (nPageId)->GetItemSet ();
321 aPageSet.Put ( *pItem );
323 pCurrentPage->Reset( aPageSet );
324 if ( mbGrabFocus )
326 pCurrentPage->SetInitFocus(); // #92535# grab the focus only once at initialization
327 mbGrabFocus = sal_False;
329 return nPageId;
332 /*************************************************************************
334 |* Enable/Disable to browse targets in a html-doc
336 |************************************************************************/
338 void SvxHpLinkDlg::EnableInetBrowse( sal_Bool bEnable )
340 SvxHyperlinkTabPageBase* pCurrentPage = ( SvxHyperlinkTabPageBase* )
341 GetTabPage ( GetCurPageId() );
342 pCurrentPage->SetOnlineMode( bEnable );
345 /*************************************************************************
347 |* Enable/Disable ReadOnly mode
349 |************************************************************************/
351 void SvxHpLinkDlg::SetReadOnlyMode( sal_Bool bRdOnly )
353 mbReadOnly = bRdOnly;
354 if ( bRdOnly )
355 GetOKButton().Disable();
356 else
357 GetOKButton().Enable();
360 /*************************************************************************
362 |* late-initialization of newly created pages
364 |************************************************************************/
366 void SvxHpLinkDlg::PageCreated( sal_uInt16 /*nId*/, IconChoicePage& rPage )
368 SvxHyperlinkTabPageBase& rHyperlinkPage = dynamic_cast< SvxHyperlinkTabPageBase& >( rPage );
369 Reference< XFrame > xDocumentFrame;
370 if ( mpBindings )
371 xDocumentFrame = mpBindings->GetActiveFrame();
372 OSL_ENSURE( xDocumentFrame.is(), "SvxHpLinkDlg::PageCreated: macro assignment functionality won't work with a proper frame!" );
373 rHyperlinkPage.SetDocumentFrame( xDocumentFrame );
376 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */