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