update credits
[LibreOffice.git] / cui / source / dialogs / hltpbase.cxx
blob273d89e027bf2928888b1239d9ae31f244c8b284
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 <sfx2/frame.hxx>
21 #include <sfx2/viewfrm.hxx>
22 #include <sot/formats.hxx>
23 #include <sfx2/sfxsids.hrc>
24 #include <svl/macitem.hxx>
25 #include <ucbhelper/content.hxx>
26 #include <unotools/localfilehelper.hxx>
27 #include "hyperdlg.hrc"
28 #include "cuihyperdlg.hxx"
29 #include "hltpbase.hxx"
30 #include "macroass.hxx"
31 #include <svx/svxdlg.hxx>
32 #include <cuires.hrc>
33 #include <boost/scoped_ptr.hpp>
35 using namespace ::ucbhelper;
37 //# ComboBox-Control, which is filled with all current framenames #
39 /*************************************************************************
41 |* Contructor / Destructor
43 |************************************************************************/
45 SvxFramesComboBox::SvxFramesComboBox ( Window* pParent, const ResId& rResId,
46 SfxDispatcher* pDispatch )
47 : ComboBox (pParent, rResId)
49 SfxViewFrame* pViewFrame = pDispatch ? pDispatch->GetFrame() : 0;
50 SfxFrame* pFrame = pViewFrame ? &pViewFrame->GetTopFrame() : 0;
51 if ( pFrame )
53 boost::scoped_ptr<TargetList> pList(new TargetList);
54 pFrame->GetTargetList(*pList);
55 if( !pList->empty() )
57 size_t nCount = pList->size();
58 size_t i;
59 for ( i = 0; i < nCount; i++ )
61 InsertEntry( *pList->at( i ) );
63 for ( i = nCount; i; )
65 delete pList->at( --i );
71 SvxFramesComboBox::~SvxFramesComboBox ()
75 //# ComboBox-Control for URL's with History and Autocompletion #
77 SvxHyperURLBox::SvxHyperURLBox( Window* pParent, INetProtocol eSmart )
78 : SvtURLBox ( pParent, eSmart ),
79 DropTargetHelper ( this )
83 sal_Int8 SvxHyperURLBox::AcceptDrop( const AcceptDropEvent& /* rEvt */ )
85 return( IsDropFormatSupported( FORMAT_STRING ) ? DND_ACTION_COPY : DND_ACTION_NONE );
88 sal_Int8 SvxHyperURLBox::ExecuteDrop( const ExecuteDropEvent& rEvt )
90 TransferableDataHelper aDataHelper( rEvt.maDropEvent.Transferable );
91 String aString;
92 sal_Int8 nRet = DND_ACTION_NONE;
94 if( aDataHelper.GetString( FORMAT_STRING, aString ) )
96 SetText( aString );
97 nRet = DND_ACTION_COPY;
100 return nRet;
103 void SvxHyperURLBox::Select()
105 SvtURLBox::Select();
107 void SvxHyperURLBox::Modify()
109 SvtURLBox::Modify();
111 long SvxHyperURLBox::Notify( NotifyEvent& rNEvt )
113 return SvtURLBox::Notify( rNEvt );
115 long SvxHyperURLBox::PreNotify( NotifyEvent& rNEvt )
117 return SvtURLBox::PreNotify( rNEvt );
120 //# Hyperlink-Dialog: Tabpages-Baseclass #
122 SvxHyperlinkTabPageBase::SvxHyperlinkTabPageBase ( Window *pParent,
123 const ResId &rResId,
124 const SfxItemSet& rItemSet )
125 : IconChoicePage ( pParent, rResId, rItemSet ),
126 mpGrpMore ( NULL ),
127 mpFtFrame ( NULL ),
128 mpCbbFrame ( NULL ),
129 mpFtForm ( NULL ),
130 mpLbForm ( NULL ),
131 mpFtIndication ( NULL ),
132 mpEdIndication ( NULL ),
133 mpFtText ( NULL ),
134 mpEdText ( NULL ),
135 mpBtScript ( NULL ),
136 mbIsCloseDisabled ( sal_False ),
137 mpDialog ( pParent ),
138 mbStdControlsInit ( sal_False ),
139 aEmptyStr()
141 // create bookmark-window
142 mpMarkWnd = new SvxHlinkDlgMarkWnd ( this );
145 SvxHyperlinkTabPageBase::~SvxHyperlinkTabPageBase ()
147 maTimer.Stop();
149 if ( mbStdControlsInit )
151 delete mpGrpMore;
152 delete mpFtFrame;
153 delete mpCbbFrame;
154 delete mpFtForm;
155 delete mpLbForm;
156 delete mpFtIndication;
157 delete mpEdIndication;
158 delete mpFtText;
159 delete mpEdText ;
160 delete mpBtScript;
163 delete mpMarkWnd;
166 void SvxHyperlinkTabPageBase::ActivatePage()
168 TabPage::ActivatePage();
171 void SvxHyperlinkTabPageBase::DeactivatePage()
173 TabPage::DeactivatePage();
176 sal_Bool SvxHyperlinkTabPageBase::QueryClose()
178 return !mbIsCloseDisabled;
181 void SvxHyperlinkTabPageBase::InitStdControls ()
183 if ( !mbStdControlsInit )
185 mpGrpMore = new FixedLine ( this, ResId (GRP_MORE, *m_pResMgr) );
186 mpFtFrame = new FixedText ( this, ResId (FT_FRAME, *m_pResMgr) );
187 mpCbbFrame = new SvxFramesComboBox ( this, ResId (CB_FRAME, *m_pResMgr), GetDispatcher() );
188 mpFtForm = new FixedText ( this, ResId (FT_FORM, *m_pResMgr) );
189 mpLbForm = new ListBox ( this, ResId (LB_FORM, *m_pResMgr) );
190 mpFtIndication= new FixedText ( this, ResId (FT_INDICATION, *m_pResMgr) );
191 mpEdIndication= new Edit ( this, ResId (ED_INDICATION, *m_pResMgr) );
192 mpFtText = new FixedText ( this, ResId (FT_TEXT, *m_pResMgr) );
193 mpEdText = new Edit ( this, ResId (ED_TEXT, *m_pResMgr) );
194 mpBtScript = new ImageButton ( this, ResId (BTN_SCRIPT, *m_pResMgr) );
196 mpBtScript->SetClickHdl ( LINK ( this, SvxHyperlinkTabPageBase, ClickScriptHdl_Impl ) );
197 mpBtScript->EnableTextDisplay (sal_False);
199 mpBtScript->SetAccessibleRelationMemberOf( mpGrpMore );
200 mpBtScript->SetAccessibleRelationLabeledBy( mpFtForm );
203 mbStdControlsInit = sal_True;
206 // Move Extra-Window
207 sal_Bool SvxHyperlinkTabPageBase::MoveToExtraWnd( Point aNewPos, sal_Bool bDisConnectDlg )
209 sal_Bool bReturn = mpMarkWnd->MoveTo ( aNewPos );
211 if( bDisConnectDlg )
212 mpMarkWnd->ConnectToDialog( sal_False );
214 return ( !bReturn && IsMarkWndVisible() );
217 // Show Extra-Window
218 void SvxHyperlinkTabPageBase::ShowMarkWnd ()
220 ( ( Window* ) mpMarkWnd )->Show();
222 // Size of dialog-window in screen pixels
223 Rectangle aDlgRect( mpDialog->GetWindowExtentsRelative( NULL ) );
224 Point aDlgPos ( aDlgRect.TopLeft() );
225 Size aDlgSize ( mpDialog->GetSizePixel () );
227 // Absolute size of the screen
228 Rectangle aScreen( mpDialog->GetDesktopRectPixel() );
230 // Size of Extrawindow
231 Size aExtraWndSize( mpMarkWnd->GetSizePixel () );
233 // mpMarkWnd is a child of mpDialog, so coordinates for positioning must be relative to mpDialog
234 if( aDlgPos.X()+(1.05*aDlgSize.Width())+aExtraWndSize.Width() > aScreen.Right() )
236 if( aDlgPos.X() - ( 0.05*aDlgSize.Width() ) - aExtraWndSize.Width() < 0 )
238 // Pos Extrawindow anywhere
239 MoveToExtraWnd( Point(10,10) ); // very unlikely
240 mpMarkWnd->ConnectToDialog( sal_False );
242 else
244 // Pos Extrawindow on the left side of Dialog
245 MoveToExtraWnd( Point(0,0) - Point( long(0.05*aDlgSize.Width()), 0 ) - Point( aExtraWndSize.Width(), 0 ) );
248 else
250 // Pos Extrawindow on the right side of Dialog
251 MoveToExtraWnd ( Point( long(1.05*aDlgSize.getWidth()), 0 ) );
254 // Set size of Extra-Window
255 mpMarkWnd->SetSizePixel( Size( aExtraWndSize.Width(), aDlgSize.Height() ) );
258 // Fill Dialogfields
259 void SvxHyperlinkTabPageBase::FillStandardDlgFields ( SvxHyperlinkItem* pHyperlinkItem )
261 // Frame
262 sal_uInt16 nPos = mpCbbFrame->GetEntryPos ( pHyperlinkItem->GetTargetFrame() );
263 if ( nPos != LISTBOX_ENTRY_NOTFOUND)
264 mpCbbFrame->SetText ( pHyperlinkItem->GetTargetFrame() );
266 // Form
267 String aStrFormText = CUI_RESSTR( RID_SVXSTR_HYPERDLG_FROM_TEXT );
268 String aStrFormButton = CUI_RESSTR( RID_SVXSTR_HYPERDLG_FORM_BUTTON );
270 if( pHyperlinkItem->GetInsertMode() & HLINK_HTMLMODE )
272 mpLbForm->Clear();
273 mpLbForm->InsertEntry( aStrFormText );
274 mpLbForm->SelectEntryPos ( 0 );
276 else
278 mpLbForm->Clear();
279 mpLbForm->InsertEntry( aStrFormText );
280 mpLbForm->InsertEntry( aStrFormButton );
281 mpLbForm->SelectEntryPos ( pHyperlinkItem->GetInsertMode() == HLINK_BUTTON ? 1 : 0 );
284 // URL
285 mpEdIndication->SetText ( pHyperlinkItem->GetName() );
287 // Name
288 mpEdText->SetText ( pHyperlinkItem->GetIntName() );
290 // Script-button
291 if ( !pHyperlinkItem->GetMacroEvents() )
292 mpBtScript->Disable();
293 else
294 mpBtScript->Enable();
297 // Any action to do after apply-button is pressed
298 void SvxHyperlinkTabPageBase::DoApply ()
300 // default-implemtation : do nothing
303 // Ask page whether an insert is possible
304 sal_Bool SvxHyperlinkTabPageBase::AskApply ()
306 // default-implementation
307 return sal_True;
310 // This method would be called from bookmark-window to set new mark-string
311 void SvxHyperlinkTabPageBase::SetMarkStr ( String& /*aStrMark*/ )
313 // default-implemtation : do nothing
316 // This method will be called from the dialog-class if the state off
317 // the online-mode has changed.
318 void SvxHyperlinkTabPageBase::SetOnlineMode( sal_Bool /*bEnable*/ )
320 // default-implemtation : do nothing
323 // Set initial focus
324 void SvxHyperlinkTabPageBase::SetInitFocus()
326 GrabFocus();
329 // Ask dialog whether the curretn doc is a HTML-doc
330 sal_Bool SvxHyperlinkTabPageBase::IsHTMLDoc() const
332 return ((SvxHpLinkDlg*)mpDialog)->IsHTMLDoc();
335 // retrieve dispatcher
336 SfxDispatcher* SvxHyperlinkTabPageBase::GetDispatcher() const
338 return ((SvxHpLinkDlg*)mpDialog)->GetDispatcher();
341 // Click on imagebutton : Script
342 IMPL_LINK_NOARG(SvxHyperlinkTabPageBase, ClickScriptHdl_Impl)
344 SvxHyperlinkItem *pHyperlinkItem = (SvxHyperlinkItem *)
345 GetItemSet().GetItem (SID_HYPERLINK_GETLINK);
347 if ( pHyperlinkItem->GetMacroEvents() )
349 // get macros from itemset
350 const SvxMacroTableDtor* pMacroTbl = pHyperlinkItem->GetMacroTbl();
351 SvxMacroItem aItem ( GetWhich(SID_ATTR_MACROITEM) );
352 if( pMacroTbl )
353 aItem.SetMacroTable( *pMacroTbl );
355 // create empty itemset for macro-dlg
356 SfxItemSet* pItemSet = new SfxItemSet(SFX_APP()->GetPool(),
357 SID_ATTR_MACROITEM,
358 SID_ATTR_MACROITEM );
359 pItemSet->Put ( aItem, SID_ATTR_MACROITEM );
361 /* disable HyperLinkDlg for input while the MacroAssignDlg is working
362 because if no JAVA is installed an error box occurs and then it is possible
363 to close the HyperLinkDlg before its child (MacroAssignDlg) -> GPF
365 sal_Bool bIsInputEnabled = GetParent()->IsInputEnabled();
366 if ( bIsInputEnabled )
367 GetParent()->EnableInput( sal_False );
368 SfxMacroAssignDlg aDlg( this, mxDocumentFrame, *pItemSet );
370 // add events
371 SfxMacroTabPage *pMacroPage = (SfxMacroTabPage*) aDlg.GetTabPage();
373 if ( pHyperlinkItem->GetMacroEvents() & HYPERDLG_EVENT_MOUSEOVER_OBJECT )
374 pMacroPage->AddEvent( String( CUI_RESSTR(RID_SVXSTR_HYPDLG_MACROACT1) ),
375 SFX_EVENT_MOUSEOVER_OBJECT );
376 if ( pHyperlinkItem->GetMacroEvents() & HYPERDLG_EVENT_MOUSECLICK_OBJECT )
377 pMacroPage->AddEvent( String( CUI_RESSTR(RID_SVXSTR_HYPDLG_MACROACT2) ),
378 SFX_EVENT_MOUSECLICK_OBJECT);
379 if ( pHyperlinkItem->GetMacroEvents() & HYPERDLG_EVENT_MOUSEOUT_OBJECT )
380 pMacroPage->AddEvent( String( CUI_RESSTR(RID_SVXSTR_HYPDLG_MACROACT3) ),
381 SFX_EVENT_MOUSEOUT_OBJECT);
383 if ( bIsInputEnabled )
384 GetParent()->EnableInput( sal_True );
385 // execute dlg
386 DisableClose( sal_True );
387 short nRet = aDlg.Execute();
388 DisableClose( sal_False );
389 if ( RET_OK == nRet )
391 const SfxItemSet* pOutSet = aDlg.GetOutputItemSet();
392 const SfxPoolItem* pItem;
393 if( SFX_ITEM_SET == pOutSet->GetItemState( SID_ATTR_MACROITEM, sal_False, &pItem ))
395 pHyperlinkItem->SetMacroTable( ((SvxMacroItem*)pItem)->GetMacroTable() );
398 delete pItemSet;
401 return( 0L );
404 // Get Macro-Infos
405 sal_uInt16 SvxHyperlinkTabPageBase::GetMacroEvents()
407 SvxHyperlinkItem *pHyperlinkItem = (SvxHyperlinkItem *)
408 GetItemSet().GetItem (SID_HYPERLINK_GETLINK);
410 return pHyperlinkItem->GetMacroEvents();
413 SvxMacroTableDtor* SvxHyperlinkTabPageBase::GetMacroTable()
415 SvxHyperlinkItem *pHyperlinkItem = (SvxHyperlinkItem *)
416 GetItemSet().GetItem (SID_HYPERLINK_GETLINK);
418 return ( (SvxMacroTableDtor*)pHyperlinkItem->GetMacroTbl() );
421 // try to detect the current protocol that is used in aStrURL
422 String SvxHyperlinkTabPageBase::GetSchemeFromURL( String aStrURL )
424 String aStrScheme;
426 INetURLObject aURL( aStrURL );
427 INetProtocol aProtocol = aURL.GetProtocol();
429 // #77696#
430 // our new INetUrlObject now has the ability
431 // to detect if an Url is valid or not :-(
432 if ( aProtocol == INET_PROT_NOT_VALID )
434 if ( aStrURL.EqualsIgnoreCaseAscii( INET_HTTP_SCHEME, 0, 7 ) )
436 aStrScheme = OUString( INET_HTTP_SCHEME );
438 else if ( aStrURL.EqualsIgnoreCaseAscii( INET_HTTPS_SCHEME, 0, 8 ) )
440 aStrScheme = OUString( INET_HTTPS_SCHEME );
442 else if ( aStrURL.EqualsIgnoreCaseAscii( INET_FTP_SCHEME, 0, 6 ) )
444 aStrScheme = OUString( INET_FTP_SCHEME );
446 else if ( aStrURL.EqualsIgnoreCaseAscii( INET_MAILTO_SCHEME, 0, 7 ) )
448 aStrScheme = OUString( INET_MAILTO_SCHEME );
450 else if ( aStrURL.EqualsIgnoreCaseAscii( INET_NEWS_SCHEME, 0, 5 ) )
452 aStrScheme = OUString( INET_NEWS_SCHEME );
455 else
456 aStrScheme = INetURLObject::GetScheme( aProtocol );
457 return aStrScheme;
461 void SvxHyperlinkTabPageBase::GetDataFromCommonFields( String& aStrName,
462 String& aStrIntName, String& aStrFrame,
463 SvxLinkInsertMode& eMode )
465 aStrIntName = mpEdText->GetText();
466 aStrName = mpEdIndication->GetText();
467 aStrFrame = mpCbbFrame->GetText();
468 eMode = (SvxLinkInsertMode) (mpLbForm->GetSelectEntryPos()+1);
469 if( IsHTMLDoc() )
470 eMode = (SvxLinkInsertMode) ( sal_uInt16(eMode) | HLINK_HTMLMODE );
473 // reset dialog-fields
474 void SvxHyperlinkTabPageBase::Reset( const SfxItemSet& rItemSet)
476 ///////////////////////////////////////
477 // Set dialog-fields from create-itemset
478 maStrInitURL = aEmptyStr;
480 SvxHyperlinkItem *pHyperlinkItem = (SvxHyperlinkItem *)
481 rItemSet.GetItem (SID_HYPERLINK_GETLINK);
483 if ( pHyperlinkItem )
485 // set dialog-fields
486 FillStandardDlgFields (pHyperlinkItem);
488 // set all other fields
489 FillDlgFields ( (String&)pHyperlinkItem->GetURL() );
491 // Store initial URL
492 maStrInitURL = pHyperlinkItem->GetURL();
496 // Fill output-ItemSet
497 sal_Bool SvxHyperlinkTabPageBase::FillItemSet( SfxItemSet& rOut)
499 String aStrURL, aStrName, aStrIntName, aStrFrame;
500 SvxLinkInsertMode eMode;
502 GetCurentItemData ( aStrURL, aStrName, aStrIntName, aStrFrame, eMode);
503 if ( !aStrName.Len() ) //automatically create a visible name if the link is created without name
504 aStrName = CreateUiNameFromURL(aStrURL);
506 sal_uInt16 nEvents = GetMacroEvents();
507 SvxMacroTableDtor* pTable = GetMacroTable();
509 SvxHyperlinkItem aItem( SID_HYPERLINK_SETLINK, aStrName, aStrURL, aStrFrame,
510 aStrIntName, eMode, nEvents, pTable );
511 rOut.Put (aItem);
513 return sal_True;
516 String SvxHyperlinkTabPageBase::CreateUiNameFromURL( const String& aStrURL )
518 OUString aStrUiURL;
519 INetURLObject aURLObj( aStrURL );
521 switch(aURLObj.GetProtocol())
523 case INET_PROT_FILE:
524 utl::LocalFileHelper::ConvertURLToSystemPath( aURLObj.GetMainURL(INetURLObject::NO_DECODE), aStrUiURL );
525 break;
526 case INET_PROT_FTP :
528 //remove password from name
529 INetURLObject aTmpURL(aURLObj);
530 aTmpURL.SetPass(aEmptyStr);
531 aStrUiURL = aTmpURL.GetMainURL( INetURLObject::DECODE_UNAMBIGUOUS );
533 break;
534 default :
536 aStrUiURL = aURLObj.GetMainURL(INetURLObject::DECODE_UNAMBIGUOUS);
539 if(aStrUiURL.isEmpty())
540 return aStrURL;
541 return aStrUiURL;
544 // Activate / Deactivate Tabpage
545 void SvxHyperlinkTabPageBase::ActivatePage( const SfxItemSet& rItemSet )
547 ///////////////////////////////////////
548 // Set dialog-fields from input-itemset
549 SvxHyperlinkItem *pHyperlinkItem = (SvxHyperlinkItem *)
550 rItemSet.GetItem (SID_HYPERLINK_GETLINK);
552 if ( pHyperlinkItem )
554 // standard-fields
555 FillStandardDlgFields (pHyperlinkItem);
558 // show mark-window if it was open before
559 if ( ShouldOpenMarkWnd () )
560 ShowMarkWnd ();
563 int SvxHyperlinkTabPageBase::DeactivatePage( SfxItemSet* _pSet)
565 // hide mark-wnd
566 SetMarkWndShouldOpen( IsMarkWndVisible () );
567 HideMarkWnd ();
569 // retrieve data of dialog
570 String aStrURL, aStrName, aStrIntName, aStrFrame;
571 SvxLinkInsertMode eMode;
573 GetCurentItemData ( aStrURL, aStrName, aStrIntName, aStrFrame, eMode);
575 sal_uInt16 nEvents = GetMacroEvents();
576 SvxMacroTableDtor* pTable = GetMacroTable();
578 if( _pSet )
580 SvxHyperlinkItem aItem( SID_HYPERLINK_GETLINK, aStrName, aStrURL, aStrFrame,
581 aStrIntName, eMode, nEvents, pTable );
582 _pSet->Put( aItem );
585 return( LEAVE_PAGE );
588 sal_Bool SvxHyperlinkTabPageBase::ShouldOpenMarkWnd()
590 return sal_False;
593 void SvxHyperlinkTabPageBase::SetMarkWndShouldOpen(sal_Bool)
597 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */