1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
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;
53 boost::scoped_ptr
<TargetList
> pList(new TargetList
);
54 pFrame
->GetTargetList(*pList
);
57 size_t nCount
= pList
->size();
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
);
92 sal_Int8 nRet
= DND_ACTION_NONE
;
94 if( aDataHelper
.GetString( FORMAT_STRING
, aString
) )
97 nRet
= DND_ACTION_COPY
;
103 void SvxHyperURLBox::Select()
107 void SvxHyperURLBox::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
,
124 const SfxItemSet
& rItemSet
)
125 : IconChoicePage ( pParent
, rResId
, rItemSet
),
131 mpFtIndication ( NULL
),
132 mpEdIndication ( NULL
),
136 mbIsCloseDisabled ( sal_False
),
137 mpDialog ( pParent
),
138 mbStdControlsInit ( sal_False
),
141 // create bookmark-window
142 mpMarkWnd
= new SvxHlinkDlgMarkWnd ( this );
145 SvxHyperlinkTabPageBase::~SvxHyperlinkTabPageBase ()
149 if ( mbStdControlsInit
)
156 delete mpFtIndication
;
157 delete mpEdIndication
;
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
;
207 sal_Bool
SvxHyperlinkTabPageBase::MoveToExtraWnd( Point aNewPos
, sal_Bool bDisConnectDlg
)
209 sal_Bool bReturn
= mpMarkWnd
->MoveTo ( aNewPos
);
212 mpMarkWnd
->ConnectToDialog( sal_False
);
214 return ( !bReturn
&& IsMarkWndVisible() );
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
);
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 ) );
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() ) );
259 void SvxHyperlinkTabPageBase::FillStandardDlgFields ( SvxHyperlinkItem
* pHyperlinkItem
)
262 sal_uInt16 nPos
= mpCbbFrame
->GetEntryPos ( pHyperlinkItem
->GetTargetFrame() );
263 if ( nPos
!= LISTBOX_ENTRY_NOTFOUND
)
264 mpCbbFrame
->SetText ( pHyperlinkItem
->GetTargetFrame() );
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
)
273 mpLbForm
->InsertEntry( aStrFormText
);
274 mpLbForm
->SelectEntryPos ( 0 );
279 mpLbForm
->InsertEntry( aStrFormText
);
280 mpLbForm
->InsertEntry( aStrFormButton
);
281 mpLbForm
->SelectEntryPos ( pHyperlinkItem
->GetInsertMode() == HLINK_BUTTON
? 1 : 0 );
285 mpEdIndication
->SetText ( pHyperlinkItem
->GetName() );
288 mpEdText
->SetText ( pHyperlinkItem
->GetIntName() );
291 if ( !pHyperlinkItem
->GetMacroEvents() )
292 mpBtScript
->Disable();
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
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
324 void SvxHyperlinkTabPageBase::SetInitFocus()
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
) );
353 aItem
.SetMacroTable( *pMacroTbl
);
355 // create empty itemset for macro-dlg
356 SfxItemSet
* pItemSet
= new SfxItemSet(SFX_APP()->GetPool(),
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
);
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
);
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() );
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
)
426 INetURLObject
aURL( aStrURL
);
427 INetProtocol aProtocol
= aURL
.GetProtocol();
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
);
456 aStrScheme
= INetURLObject::GetScheme( aProtocol
);
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);
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
)
486 FillStandardDlgFields (pHyperlinkItem
);
488 // set all other fields
489 FillDlgFields ( (String
&)pHyperlinkItem
->GetURL() );
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
);
516 String
SvxHyperlinkTabPageBase::CreateUiNameFromURL( const String
& aStrURL
)
519 INetURLObject
aURLObj( aStrURL
);
521 switch(aURLObj
.GetProtocol())
524 utl::LocalFileHelper::ConvertURLToSystemPath( aURLObj
.GetMainURL(INetURLObject::NO_DECODE
), aStrUiURL
);
528 //remove password from name
529 INetURLObject
aTmpURL(aURLObj
);
530 aTmpURL
.SetPass(aEmptyStr
);
531 aStrUiURL
= aTmpURL
.GetMainURL( INetURLObject::DECODE_UNAMBIGUOUS
);
536 aStrUiURL
= aURLObj
.GetMainURL(INetURLObject::DECODE_UNAMBIGUOUS
);
539 if(aStrUiURL
.isEmpty())
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
)
555 FillStandardDlgFields (pHyperlinkItem
);
558 // show mark-window if it was open before
559 if ( ShouldOpenMarkWnd () )
563 int SvxHyperlinkTabPageBase::DeactivatePage( SfxItemSet
* _pSet
)
566 SetMarkWndShouldOpen( IsMarkWndVisible () );
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();
580 SvxHyperlinkItem
aItem( SID_HYPERLINK_GETLINK
, aStrName
, aStrURL
, aStrFrame
,
581 aStrIntName
, eMode
, nEvents
, pTable
);
585 return( LEAVE_PAGE
);
588 sal_Bool
SvxHyperlinkTabPageBase::ShouldOpenMarkWnd()
593 void SvxHyperlinkTabPageBase::SetMarkWndShouldOpen(sal_Bool
)
597 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */