update dev300-m58
[ooovba.git] / svx / source / cui / cuihyperdlg.cxx
blob3eb69780d8215fc74f68cd1d56961a09b9657d33
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: cuihyperdlg.cxx,v $
10 * $Revision: 1.8 $
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 ---------------------------------------------------------------
39 #include <vcl/settings.hxx>
40 #include <svtools/viewoptions.hxx>
42 #include "cuihyperdlg.hxx"
44 #include "hlinettp.hxx"
45 #include "hlmailtp.hxx"
46 #include "hldoctp.hxx"
47 #include "hldocntp.hxx"
49 #include "hyperdlg.hrc"
51 using ::com::sun::star::uno::Reference;
52 using ::com::sun::star::frame::XFrame;
54 //########################################################################
55 //# #
56 //# Childwindow-Wrapper-Class #
57 //# #
58 //########################################################################
60 SvxHlinkCtrl::SvxHlinkCtrl( USHORT _nId, SfxBindings & rBindings, SvxHpLinkDlg* pDlg )
61 : SfxControllerItem ( _nId, rBindings )
62 ,aOnlineForwarder ( SID_INTERNET_ONLINE , *this )
63 ,aRdOnlyForwarder ( SID_READONLY_MODE, *this )
65 pParent = pDlg;
68 void SvxHlinkCtrl::StateChanged( USHORT nSID, SfxItemState eState,
69 const SfxPoolItem* pState )
71 if ( eState == SFX_ITEM_AVAILABLE )
73 switch ( nSID )
75 case SID_INTERNET_ONLINE :
77 pParent->EnableInetBrowse( !( (SfxBoolItem*)pState)->GetValue() );
79 break;
80 case SID_HYPERLINK_GETLINK :
82 pParent->SetPage ( (SvxHyperlinkItem*)pState);
84 break;
85 case SID_READONLY_MODE :
87 pParent->SetReadOnlyMode( ( (SfxBoolItem*)pState)->GetValue() == TRUE );
89 break;
96 // -----------------------------------------------------------------------
100 //########################################################################
101 //# #
102 //# Hyperlink - Dialog #
103 //# #
104 //########################################################################
106 /*************************************************************************
108 |* Contructor / Destructor
110 |************************************************************************/
112 SvxHpLinkDlg::SvxHpLinkDlg (Window* pParent, SfxBindings* pBindings)
113 : IconChoiceDialog( pParent, SVX_RES ( RID_SVXDLG_NEWHYPERLINK ) ),
114 maCtrl ( SID_HYPERLINK_GETLINK, *pBindings, this ),
115 mpBindings ( pBindings ),
116 mbReadOnly ( sal_False ),
117 mbIsHTMLDoc ( sal_False )
119 mbGrabFocus = sal_True;
120 // insert pages
121 Image aImage;
122 Image aImageHC;
123 String aStrTitle;
124 SvxIconChoiceCtrlEntry* pEntry = NULL;
126 aStrTitle = SVX_RESSTR( RID_SVXSTR_HYPERDLG_HLINETTP );
127 aImage = Image( SVX_RES ( RID_SVXBMP_HLINETTP ) );
128 aImageHC = Image( SVX_RES ( RID_SVXBMP_HLINETTP_H ) );
129 pEntry = AddTabPage ( RID_SVXPAGE_HYPERLINK_INTERNET, aStrTitle, aImage, aImageHC, SvxHyperlinkInternetTp::Create );
130 pEntry->SetQuickHelpText( SVX_RESSTR( RID_SVXSTR_HYPERDLG_HLINETTP_HELP ) );
131 aStrTitle = SVX_RESSTR( RID_SVXSTR_HYPERDLG_HLMAILTP );
132 aImage = Image( SVX_RES ( RID_SVXBMP_HLMAILTP ) );
133 aImageHC = Image( SVX_RES ( RID_SVXBMP_HLMAILTP_H ) );
134 pEntry = AddTabPage ( RID_SVXPAGE_HYPERLINK_MAIL, aStrTitle, aImage, aImageHC, SvxHyperlinkMailTp::Create );
135 pEntry->SetQuickHelpText( SVX_RESSTR( RID_SVXSTR_HYPERDLG_HLMAILTP_HELP ) );
136 aStrTitle = SVX_RESSTR( RID_SVXSTR_HYPERDLG_HLDOCTP );
137 aImage = Image( SVX_RES ( RID_SVXBMP_HLDOCTP ) );
138 aImageHC = Image( SVX_RES ( RID_SVXBMP_HLDOCTP_H ) );
139 pEntry = AddTabPage ( RID_SVXPAGE_HYPERLINK_DOCUMENT, aStrTitle, aImage, aImageHC, SvxHyperlinkDocTp::Create );
140 pEntry->SetQuickHelpText( SVX_RESSTR( RID_SVXSTR_HYPERDLG_HLDOCTP_HELP ) );
141 aStrTitle = SVX_RESSTR( RID_SVXSTR_HYPERDLG_HLDOCNTP );
142 aImage = Image( SVX_RES ( RID_SVXBMP_HLDOCNTP ) );
143 aImageHC = Image( SVX_RES ( RID_SVXBMP_HLDOCNTP_H ) );
144 pEntry = AddTabPage ( RID_SVXPAGE_HYPERLINK_NEWDOCUMENT, aStrTitle, aImage, aImageHC, SvxHyperlinkNewDocTp::Create );
145 pEntry->SetQuickHelpText( SVX_RESSTR( RID_SVXSTR_HYPERDLG_HLDOCNTP_HELP ) );
147 // all tab pages set -> create mnemonics
148 // CreateIconTextAutoMnemonics(); #99671# not useful, because this is not what user expects when using mnemonics on the pages
150 // create itemset for tabpages
151 mpItemSet = new SfxItemSet( SFX_APP()->GetPool(), SID_HYPERLINK_GETLINK,
152 SID_HYPERLINK_SETLINK );
154 SvxHyperlinkItem aItem;
155 mpItemSet->Put (aItem, SID_HYPERLINK_GETLINK);
157 SetInputSet (mpItemSet);
159 // Init Dialog
160 Start (FALSE);
162 pBindings->Update( SID_READONLY_MODE );
164 // set OK/Cancel - button
165 GetOKButton().SetText ( SVX_RESSTR(RID_SVXSTR_HYPDLG_APPLYBUT) );
166 GetCancelButton().SetText ( SVX_RESSTR(RID_SVXSTR_HYPDLG_CLOSEBUT) );
168 GetOKButton().SetClickHdl ( LINK ( this, SvxHpLinkDlg, ClickApplyHdl_Impl ) );
169 GetCancelButton().SetClickHdl( LINK ( this, SvxHpLinkDlg, ClickCloseHdl_Impl ) );
172 SvxHpLinkDlg::~SvxHpLinkDlg ()
174 // delete config item, so the base class (IconChoiceDialog) can not load it on the next start
175 SvtViewOptions aViewOpt( E_TABDIALOG, String::CreateFromInt32( SID_HYPERLINK_DIALOG ) );
176 aViewOpt.Delete();
178 delete mpItemSet;
181 /*************************************************************************
183 |* Close Dialog-Window
185 |************************************************************************/
187 BOOL SvxHpLinkDlg::Close()
189 GetDispatcher()->Execute( SID_HYPERLINK_DIALOG,
190 SFX_CALLMODE_ASYNCHRON |
191 SFX_CALLMODE_RECORD);
192 return TRUE;
195 /*************************************************************************
197 |* When extrawindow is visible and its never moved by user, then move that
198 |* window, too.
200 |************************************************************************/
202 void SvxHpLinkDlg::Move()
204 SvxHyperlinkTabPageBase* pCurrentPage = ( SvxHyperlinkTabPageBase* )
205 GetTabPage ( GetCurPageId() );
207 if( pCurrentPage->IsMarkWndVisible () )
209 // Pos&Size of this dialog-window
210 Point aDlgPos ( GetPosPixel () );
211 Size aDlgSize ( GetSizePixel () );
213 // Size of Office-Main-Window
214 Size aWindowSize( SFX_APP()->GetTopWindow()->GetSizePixel() );
216 // Size of Extrawindow
217 Size aExtraWndSize( pCurrentPage->GetSizeExtraWnd() );
219 BOOL bDoInvalid ;
220 if( aDlgPos.X()+(1.02*aDlgSize.Width())+aExtraWndSize.Width() > aWindowSize.Width() )
222 if( aDlgPos.X() - ( 0.02*aDlgSize.Width() ) - aExtraWndSize.Width() < 0 )
224 // Pos Extrawindow anywhere
225 bDoInvalid = pCurrentPage->MoveToExtraWnd( Point( 1, long(1.1*aDlgPos.Y()) ), TRUE );
227 else
229 // Pos Extrawindow on the left side of Dialog
230 bDoInvalid = pCurrentPage->MoveToExtraWnd( aDlgPos -
231 Point( long(0.02*aDlgSize.Width()), 0 ) -
232 Point( aExtraWndSize.Width(), 0 ) );
235 else
237 // Pos Extrawindow on the right side of Dialog
238 bDoInvalid = pCurrentPage->MoveToExtraWnd ( aDlgPos + Point( long(1.02*aDlgSize.Width()), 0 ) );
241 if ( bDoInvalid )
242 Invalidate(INVALIDATE_BACKGROUND);
245 Window::Move();
248 /*long SvxHpLinkDlg::PreNotify( NotifyEvent& rNEvt )
250 long nRet = 0;
252 if( rNEvt.GetType() == EVENT_KEYINPUT )
254 DBG_ASSERT( rNEvt.GetKeyEvent(), "-SvxHpLinkDlg::PreNotify(): no KeyEvent for key event?!" );
256 const KeyEvent* pKEvt = rNEvt.GetKeyEvent();
258 if( KEY_MOD2 == pKEvt->GetKeyCode().GetModifier() && pKEvt->GetCharCode() && HandleShortCutKey( *pKEvt ) )
259 nRet = 1;
262 if( !nRet )
263 nRet = IconChoiceDialog::PreNotify( rNEvt );
265 return nRet;
268 /*************************************************************************
270 |* Click on Apply-button
272 |************************************************************************/
274 IMPL_LINK ( SvxHpLinkDlg, ClickApplyHdl_Impl, void *, EMPTYARG )
276 SfxItemSet aItemSet( SFX_APP()->GetPool(), SID_HYPERLINK_GETLINK,
277 SID_HYPERLINK_SETLINK );
279 SvxHyperlinkTabPageBase* pCurrentPage = (SvxHyperlinkTabPageBase*)
280 GetTabPage ( GetCurPageId() );
282 if ( pCurrentPage->AskApply() )
284 pCurrentPage->FillItemSet( aItemSet );
286 SvxHyperlinkItem *aItem = (SvxHyperlinkItem *)
287 aItemSet.GetItem (SID_HYPERLINK_SETLINK);
289 String aStrEmpty;
290 if ( aItem->GetURL() != aStrEmpty )
291 GetDispatcher()->Execute( SID_HYPERLINK_SETLINK, SFX_CALLMODE_ASYNCHRON |
292 SFX_CALLMODE_RECORD, aItem, 0L);
294 ( (SvxHyperlinkTabPageBase*)GetTabPage ( GetCurPageId() ) )->DoApply();
297 return( 0L );
300 /*************************************************************************
302 |* Click on Close-button
304 |************************************************************************/
306 IMPL_LINK ( SvxHpLinkDlg, ClickCloseHdl_Impl, void *, EMPTYARG )
308 Close();
310 return( 0L );
313 /*************************************************************************
315 |* Set Page
317 |************************************************************************/
319 USHORT SvxHpLinkDlg::SetPage ( SvxHyperlinkItem* pItem )
321 USHORT nPageId = RID_SVXPAGE_HYPERLINK_INTERNET;
323 String aStrURL ( pItem->GetURL() );
324 INetURLObject aURL ( aStrURL );
325 INetProtocol eProtocolTyp = aURL.GetProtocol();
327 switch ( eProtocolTyp )
329 case INET_PROT_HTTP :
330 case INET_PROT_FTP :
331 case INET_PROT_TELNET :
332 nPageId = RID_SVXPAGE_HYPERLINK_INTERNET;
333 break;
334 case INET_PROT_FILE :
335 case INET_PROT_POP3 :
336 case INET_PROT_IMAP :
337 nPageId = RID_SVXPAGE_HYPERLINK_DOCUMENT;
338 break;
339 case INET_PROT_MAILTO :
340 case INET_PROT_NEWS :
341 nPageId = RID_SVXPAGE_HYPERLINK_MAIL;
342 break;
343 default :
344 sal_Char const sNewsSrvScheme[] = "news://";
345 // TODO news:// is nonsense
347 if ( aStrURL.SearchAscii( sNewsSrvScheme ) == 0 )
348 nPageId = RID_SVXPAGE_HYPERLINK_DOCUMENT;
349 else
351 sal_Char const sHash[] = "#";
352 if( aStrURL.SearchAscii( sHash ) == 0 )
353 nPageId = RID_SVXPAGE_HYPERLINK_DOCUMENT;
354 else
356 eProtocolTyp = INET_PROT_NOT_VALID;
357 nPageId = GetCurPageId();
360 break;
363 ShowPage (nPageId);
365 SvxHyperlinkTabPageBase* pCurrentPage = (SvxHyperlinkTabPageBase*)GetTabPage( nPageId );
367 mbIsHTMLDoc = (pItem->GetInsertMode() & HLINK_HTMLMODE) ? true : false;
369 SfxItemSet& aPageSet = (SfxItemSet&)GetTabPage (nPageId)->GetItemSet ();
370 aPageSet.Put ( *pItem );
372 pCurrentPage->Reset( aPageSet );
373 if ( mbGrabFocus )
375 pCurrentPage->SetInitFocus(); // #92535# grab the focus only once at initialization
376 mbGrabFocus = sal_False;
378 return nPageId;
381 /*************************************************************************
383 |* Enable/Disable to browse targets in a html-doc
385 |************************************************************************/
387 void SvxHpLinkDlg::EnableInetBrowse( sal_Bool bEnable )
389 SvxHyperlinkTabPageBase* pCurrentPage = ( SvxHyperlinkTabPageBase* )
390 GetTabPage ( GetCurPageId() );
391 pCurrentPage->SetOnlineMode( bEnable );
394 /*************************************************************************
396 |* Enable/Disable ReadOnly mode
398 |************************************************************************/
400 void SvxHpLinkDlg::SetReadOnlyMode( sal_Bool bRdOnly )
402 mbReadOnly = bRdOnly;
403 if ( bRdOnly )
404 GetOKButton().Disable();
405 else
406 GetOKButton().Enable();
409 /*************************************************************************
411 |* late-initialization of newly created pages
413 |************************************************************************/
415 void SvxHpLinkDlg::PageCreated( USHORT /*nId*/, IconChoicePage& rPage )
417 SvxHyperlinkTabPageBase& rHyperlinkPage = dynamic_cast< SvxHyperlinkTabPageBase& >( rPage );
418 Reference< XFrame > xDocumentFrame;
419 if ( mpBindings )
420 xDocumentFrame = mpBindings->GetActiveFrame();
421 OSL_ENSURE( xDocumentFrame.is(), "SvxHpLinkDlg::PageCreated: macro assignment functionality won't work with a proper frame!" );
422 rHyperlinkPage.SetDocumentFrame( xDocumentFrame );