1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: hyprlink.cxx,v $
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"
33 #include <tools/urlobj.hxx>
34 #include <vcl/msgbox.hxx>
35 #include <unotools/configitem.hxx>
36 #include <svtools/cmdoptions.hxx>
37 #include <svtools/inetimg.hxx>
38 #include <svtools/urlbmk.hxx>
39 #include <svtools/eitem.hxx>
40 #include <svtools/stritem.hxx>
41 #include <sfx2/viewfrm.hxx>
42 #include <sfx2/docfile.hxx>
43 #include <sfx2/imgmgr.hxx>
44 #include <sfx2/dispatch.hxx>
45 #include <svtools/urihelper.hxx>
46 #include <sfx2/objsh.hxx>
47 #include <comphelper/processfactory.hxx>
49 #include "hlnkitem.hxx"
50 #include <svx/dialogs.hrc>
51 #include "hyprlink.hrc"
52 #include <svx/dialmgr.hxx>
53 #include "hyprlink.hxx"
54 #include "hyprdlg.hxx"
56 using namespace ::rtl
;
57 using namespace ::com::sun::star
;
59 // -----------------------------------------------------------------------
61 class SearchDefaultConfigItem_Impl
: public ::utl::ConfigItem
63 OUString sDefaultEngine
;
65 SearchDefaultConfigItem_Impl();
66 ~SearchDefaultConfigItem_Impl();
68 const OUString
& GetDefaultSearchEngine(){ return sDefaultEngine
;}
71 /*-- 11.11.2003 14:20:59---------------------------------------------------
73 -----------------------------------------------------------------------*/
74 SearchDefaultConfigItem_Impl::SearchDefaultConfigItem_Impl() :
75 ConfigItem(OUString::createFromAscii("Inet/DefaultSearchEngine"))
77 uno::Sequence
<OUString
> aNames(1);
78 aNames
.getArray()[0] = OUString::createFromAscii("Name");
79 uno::Sequence
< uno::Any
> aValues
= GetProperties(aNames
);
80 aValues
.getConstArray()[0] >>= sDefaultEngine
;
82 /*-- 11.11.2003 14:21:00---------------------------------------------------
84 -----------------------------------------------------------------------*/
85 SearchDefaultConfigItem_Impl::~SearchDefaultConfigItem_Impl()
89 /*************************************************************************
91 |* Dialog zum Einf"ugen/"Andern eines Hyperlink
93 \************************************************************************/
95 SvxHyperlinkDlg::SvxHyperlinkDlg( SfxBindings
*_pBindings
, Window
* pParent
) :
97 ToolBox ( pParent
, SVX_RES( RID_SVXDLG_HYPERLINK
) ),
98 SfxControllerItem ( SID_HYPERLINK_SETLINK
, *_pBindings
),
100 aForwarder ( SID_HYPERLINK_GETLINK
, *this ),
101 aHyperlinkDlgForward( SID_HYPERLINK_DIALOG
, *this),
103 aNameCB ( this, SVX_RES( CB_NAME
) ),
104 aUrlFT ( this, SVX_RES( FT_URL
) ),
105 aUrlCB ( this, SVX_RES( CB_URL
) ),
106 aSearchConfig (sal_True
),
107 sAddress ( SVX_RES( STR_ADDRESS
) ),
108 sExplorer ( SVX_RES( STR_EXPLORER
) ),
109 sSearchTitle ( SVX_RES( STR_BOOKMARK_SEARCH
) ),
110 aLinkPopup ( SVX_RES( RID_SVXMN_HYPERLINK
) ),
111 pTargetMenu ( NULL
),
115 bHasOldName ( FALSE
),
121 mpManager
= SfxImageManager::GetImageManager( 0 );
122 mpManager
->RegisterToolBox( this );
127 nMaxWidth
= GetSizePixel().Width();
128 nMaxHeight
= GetSizePixel().Height();
131 InsertSeparator( 0 );
132 InsertWindow( CB_URL
, &aUrlCB
, 0, 0 );
133 // we need an item text for accessibility
134 String sItemText
= aUrlCB
.GetText();
135 if ( sItemText
.Len() == 0 )
136 sItemText
= aUrlCB
.GetQuickHelpText();
137 if ( sItemText
.Len() > 0 )
139 SetItemText( CB_URL
, sItemText
);
142 InsertWindow( FT_URL
, &aUrlFT
, 0, 0 );
143 InsertSeparator( 0 );
144 InsertWindow( CB_NAME
, &aNameCB
, 0, 0 );
145 sItemText
= aNameCB
.GetText();
146 if ( sItemText
.Len() == 0 )
147 sItemText
= aNameCB
.GetQuickHelpText();
148 if ( sItemText
.Len() > 0 )
149 SetItemText( CB_NAME
, sItemText
);
151 SetSizePixel(CalcWindowSizePixel()); // Groesse initialisieren
153 nMaxHeight
= GetSizePixel().Height(); // Hoehe nochmal merken, da sie veraendert wurde
154 // SetSizePixel ruft Resize-Handler!
159 long nUrlWidth
= aUrlCB
.GetResizeWidth();
160 long nNameWidth
= aNameCB
.GetResizeWidth();
161 long nSum
= nUrlWidth
+ nNameWidth
;
163 aUrlCB
.SetRatio((nUrlWidth
* 100L) / nSum
);
164 aNameCB
.SetRatio((nNameWidth
* 100L) / nSum
);
166 SetClickHdl( LINK( this, SvxHyperlinkDlg
, TBClickHdl
) );
167 SetSelectHdl( LINK( this, SvxHyperlinkDlg
, TBSelectHdl
) );
168 SetDropdownClickHdl( LINK( this, SvxHyperlinkDlg
, DropdownClick
) );
170 SetItemBits( BTN_TARGET
, GetItemBits( BTN_TARGET
) | TIB_DROPDOWNONLY
);
171 SetItemBits( BTN_INET_SEARCH
, GetItemBits( BTN_INET_SEARCH
) | TIB_DROPDOWN
);
172 SetItemBits( BTN_INET_SEARCH
, GetItemBits( BTN_TARGET
) | TIB_DROPDOWNONLY
);
174 aLinkPopup
.SetSelectHdl(LINK(this, SvxHyperlinkDlg
, LinkPopupSelectHdl
));
176 Link aLk
= LINK(this, SvxHyperlinkDlg
, ComboSelectHdl
);
177 aNameCB
.SetSelectHdl(aLk
);
178 aUrlCB
.SetSelectHdl(aLk
);
180 aLk
= LINK(this, SvxHyperlinkDlg
, ComboModifyHdl
);
181 aNameCB
.SetModifyHdl(aLk
);
182 aUrlCB
.SetModifyHdl(aLk
);
184 // Accessibility: Set the quick help text as accessible name for the
186 aNameCB
.SetAccessibleName (aNameCB
.GetQuickHelpText());
187 aUrlCB
.SetAccessibleName (aUrlCB
.GetQuickHelpText());
189 // Hide button according to config item.
190 SvtCommandOptions aCmdOpts
;
191 if ( aCmdOpts
.Lookup( SvtCommandOptions::CMDOPTION_DISABLED
,
193 RTL_CONSTASCII_USTRINGPARAM(
194 "InternetSearch" ) ) ) )
195 HideItem( BTN_INET_SEARCH
);
198 /*--------------------------------------------------------------------
200 --------------------------------------------------------------------*/
202 SvxHyperlinkDlg::~SvxHyperlinkDlg()
204 SfxImageManager::GetImageManager( 0 )->ReleaseToolBox(this);
206 if (pTargetMenu
!= NULL
)
210 /*--------------------------------------------------------------------
211 Beschreibung: Leiste so resizen, dass die Comboboxen automatisch mit
213 --------------------------------------------------------------------*/
215 void SvxHyperlinkDlg::Resize()
217 long nWidth
= GetSizePixel().Width();
221 if (nWidth
) // nWidth ist manchmal 0
223 long nDeltaW
= nMaxWidth
- nWidth
+ aUrlCB
.LogicToPixel(Size(3, 1)).Width() + 1;
225 long nNewUrlWidth
= aUrlCB
.CalcResizeWidth(nDeltaW
);
226 long nNewNameWidth
= aNameCB
.CalcResizeWidth(nDeltaW
);
228 if (nNewUrlWidth
&& nNewNameWidth
) // Flackern reduzieren
230 SetUpdateMode(FALSE
);
232 // Comboboxen resizen
233 aUrlCB
.DoResize(nNewUrlWidth
);
234 aNameCB
.DoResize(nNewNameWidth
);
235 RecalcItems(); // Alle Elemente neu anordnen
242 /*--------------------------------------------------------------------
244 --------------------------------------------------------------------*/
246 void SvxHyperlinkDlg::Resizing(Size
& rSize
)
248 if (rSize
.Height() > nMaxHeight
)
249 rSize
.Height() = nMaxHeight
;
251 if (rSize
.Width() > nMaxWidth
)
252 rSize
.Width() = nMaxWidth
;
254 ToolBox::Resizing(rSize
);
257 /*--------------------------------------------------------------------
258 Beschreibung: Im Dokument selektierten Hyperlink in Leiste anzeigen
259 --------------------------------------------------------------------*/
261 void SvxHyperlinkDlg::StateChanged( USHORT nSID
, SfxItemState eState
,
262 const SfxPoolItem
* pState
)
264 if ( nSID
== SID_HYPERLINK_DIALOG
)
266 if( eState
!= SFX_ITEM_DISABLED
)
268 EnableItem( BTN_OPENDIALOG
, TRUE
);
271 if ( pState
&& eState
== SFX_ITEM_AVAILABLE
)
272 bItem
= ((SfxBoolItem
*)pState
)->GetValue();
273 SetItemState ( BTN_OPENDIALOG
, bItem
? STATE_CHECK
: STATE_NOCHECK
);
277 SetItemState ( BTN_OPENDIALOG
, STATE_NOCHECK
);
278 EnableItem( BTN_OPENDIALOG
, FALSE
);
282 if (nSID
== SID_HYPERLINK_SETLINK
)
284 if (eState
== SFX_ITEM_DISABLED
)
288 EnableItem(BTN_TARGET
, !bNoDoc
);
292 if (nSID
== SID_HYPERLINK_GETLINK
)
294 if (eState
== SFX_ITEM_AVAILABLE
)
296 const SvxHyperlinkItem
& rHLnkItem
= *((const SvxHyperlinkItem
*)pState
);
298 USHORT nNamePos
= aNameCB
.GetEntryPos(aNameCB
.GetText());
299 USHORT nUrlPos
= aUrlCB
.GetEntryPos(aUrlCB
.GetText());
300 USHORT nNotFound
= COMBOBOX_ENTRY_NOTFOUND
;
303 (nNamePos
== nNotFound
|| nUrlPos
== nNotFound
))
305 sOldName
= aNameCB
.GetText();
308 if (rHLnkItem
.GetName().Len())
310 aNameCB
.SetText(rHLnkItem
.GetName());
311 ComboModifyHdl(&aNameCB
);
313 if (rHLnkItem
.GetURL().Len() || rHLnkItem
.GetName().Len())
315 String sUrl
= INetURLObject(rHLnkItem
.GetURL()).GetURLNoPass();
316 aUrlCB
.SetText(sUrl
);
318 else if (aUrlCB
.GetEntryCount())
319 { // Letzten Eintrag wieder selektieren
320 aNameCB
.SetText(aNameCB
.GetEntry(0));
321 aUrlCB
.SetText(aUrlCB
.GetEntry(0));
324 TargetMenu(rHLnkItem
.GetTargetFrame(), FALSE
);
325 bHtmlMode
= (rHLnkItem
.GetInsertMode() & HLINK_HTMLMODE
) != 0;
330 ComboModifyHdl(&aUrlCB
);
334 /*--------------------------------------------------------------------
336 --------------------------------------------------------------------*/
338 IMPL_LINK( SvxHyperlinkDlg
, TBClickHdl
, ToolBox
*, pBox
)
340 switch (pBox
->GetCurItemId())
344 if (!bSend
) // Link ins Dokument einfuegen
345 SendToApp(HLINK_DEFAULT
);
351 GetBindings().GetDispatcher()->Execute( SID_HYPERLINK_DIALOG
);
359 /*--------------------------------------------------------------------
361 --------------------------------------------------------------------*/
363 IMPL_LINK( SvxHyperlinkDlg
, TBSelectHdl
, ToolBox
*, pBox
)
365 switch (pBox
->GetCurItemId())
367 // Link als Bookmark im Explorer eintragen
368 // Soll erst im Loslassen der Maus gerufen werden, daher im Select-Hdl
369 case BTN_INSERT_BOOKMARK
:
371 String sName
= aNameCB
.GetText();
373 sName
= aUrlCB
.GetText();
375 String aBase
= GetBindings().GetDispatcher()->GetFrame()->GetObjectShell()->GetMedium()->GetBaseURL();
376 SfxStringItem
aName( SID_BOOKMARK_TITLE
, sName
);
377 SfxStringItem
aURL( SID_BOOKMARK_URL
,
378 URIHelper::SmartRel2Abs( INetURLObject(aBase
), aUrlCB
.GetText(), URIHelper::GetMaybeFileHdl(), true, false,
379 INetURLObject::WAS_ENCODED
,
380 INetURLObject::DECODE_UNAMBIGUOUS
) );
381 GetBindings().GetDispatcher()->Execute(
382 SID_CREATELINK
, SFX_CALLMODE_ASYNCHRON
, &aName
, &aURL
, 0L );
390 IMPL_LINK( SvxHyperlinkDlg
, DropdownClick
, ToolBox
*, pBox
)
392 switch (pBox
->GetCurItemId())
396 // Link-Popup anstossen
397 EndSelection(); // Vor dem Execute, damit Popup den Focus bekommt
398 aLinkPopup
.EnableItem(MN_BUTTON
, !bHtmlMode
);
399 aLinkPopup
.Execute( this, GetItemRect( BTN_LINK
), FLOATWIN_POPUPMODE_DOWN
);
403 case BTN_INET_SEARCH
:
405 // Search-Engines per Popup auswaehlen
406 PopupMenu
*pMenu
= new PopupMenu
;
407 pMenu
->SetSelectHdl(LINK(this, SvxHyperlinkDlg
, SearchPopupSelectHdl
));
408 SearchDefaultConfigItem_Impl aDefaultEngine
;
409 String
sDefault(aDefaultEngine
.GetDefaultSearchEngine());
410 sDefault
.ToLowerAscii();
411 const bool bHasDefault
= sDefault
.Len() > 0;
413 sal_uInt16 nCount
= aSearchConfig
.Count();
415 for (USHORT i
= 0; i
< nCount
; i
++)
417 const SvxSearchEngineData
& rData
= aSearchConfig
.GetData(i
);
418 //check if it's the configured default search engine
419 String
sTest(rData
.sEngineName
);
420 sTest
.ToLowerAscii();
421 bool bIsDefaultEngine
= bHasDefault
&& STRING_NOTFOUND
!= sTest
.Search( sDefault
);
422 //then put it at the top
423 if(i
&& bIsDefaultEngine
)
425 pMenu
->InsertItem( i
+ 1, rData
.sEngineName
, 0, 0);
426 pMenu
->InsertSeparator(1);
431 pMenu
->InsertSeparator();
432 pMenu
->InsertItem( i
+ 1, rData
.sEngineName
);
435 pBox
->SetItemDown(BTN_INET_SEARCH
, TRUE
, TRUE
);
436 pMenu
->Execute( this, GetItemRect( BTN_INET_SEARCH
), FLOATWIN_POPUPMODE_DOWN
);
437 pBox
->SetItemDown(BTN_INET_SEARCH
, FALSE
, TRUE
);
445 // Target Frame einstellen
446 TargetMenu(GetSelTarget(), TRUE
);
455 /*--------------------------------------------------------------------
457 --------------------------------------------------------------------*/
459 void SvxHyperlinkDlg::TargetMenu(const String
& rSelEntry
, BOOL bExecute
)
461 if (pTargetMenu
&& !bExecute
)
463 for (USHORT i
= 1; i
<= pTargetMenu
->GetItemCount(); i
++)
465 if (pTargetMenu
->GetItemText(i
) == rSelEntry
)
467 pTargetMenu
->CheckItem(i
);
473 SfxViewFrame
* pVwFrm
= SfxViewFrame::Current();
475 if (pVwFrm
) // Alle moeglichen Target Frames zusammensammeln und anzeigen
478 pVwFrm
->GetTopFrame()->GetTargetList(aList
);
480 USHORT nCount
= (USHORT
)aList
.Count();
483 BOOL bChecked
= FALSE
;
485 if (pTargetMenu
!= NULL
)
488 pTargetMenu
= new PopupMenu
;
489 pTargetMenu
->SetMenuFlags( pTargetMenu
->GetMenuFlags() |
490 MENU_FLAG_NOAUTOMNEMONICS
);
492 for ( i
= 0; i
< nCount
; i
++ )
494 String
sEntry(*aList
.GetObject(i
));
495 pTargetMenu
->InsertItem(i
+ 1, sEntry
, MIB_RADIOCHECK
|MIB_AUTOCHECK
);
497 if (sEntry
== rSelEntry
)
499 pTargetMenu
->CheckItem(i
+ 1);
503 for ( i
= nCount
; i
; i
-- )
504 delete aList
.GetObject( i
- 1 );
507 pTargetMenu
->CheckItem(1);
511 USHORT nEntry
= pTargetMenu
->Execute(
512 this, GetItemRect( BTN_TARGET
), FLOATWIN_POPUPMODE_DOWN
);
514 pTargetMenu
->CheckItem( nEntry
);
520 /*--------------------------------------------------------------------
522 --------------------------------------------------------------------*/
524 IMPL_LINK( SvxHyperlinkDlg
, LinkPopupSelectHdl
, Menu
*, pMenu
)
526 switch (pMenu
->GetCurItemId())
528 case MN_FIELD
: // URL als Hyperlink ins Dok einfuegen
529 SendToApp(HLINK_FIELD
);
531 case MN_BUTTON
: // URL als Button ins Dok einfuegen
532 SendToApp(HLINK_BUTTON
);
539 /*--------------------------------------------------------------------
541 --------------------------------------------------------------------*/
543 IMPL_LINK( SvxHyperlinkDlg
, SearchPopupSelectHdl
, Menu
*, pMenu
)
545 const SvxSearchEngineData
& rData
= aSearchConfig
.GetData(pMenu
->GetCurItemId() - 1);
546 String
sText(aNameCB
.GetText());
547 sText
.EraseLeadingChars().EraseTrailingChars();
549 rtl::OUString sPrefix
;
550 rtl::OUString sSuffix
;
551 rtl::OUString sSeparator
;
552 sal_Int32 nCaseMatch
;
553 sal_Unicode cToken
= 0;
555 if (sText
.Search(' ') != STRING_NOTFOUND
)
557 sPrefix
= rData
.sExactPrefix
;
558 sSuffix
= rData
.sExactSuffix
;
559 sSeparator
= rData
.sExactSeparator
;
560 nCaseMatch
= rData
.nExactCaseMatch
;
563 else if (sText
.Search('+') != STRING_NOTFOUND
)
565 sPrefix
= rData
.sAndPrefix
;
566 sSuffix
= rData
.sAndSuffix
;
567 sSeparator
= rData
.sAndSeparator
;
568 nCaseMatch
= rData
.nAndCaseMatch
;
571 else if (sText
.Search(',') != STRING_NOTFOUND
)
573 sPrefix
= rData
.sOrPrefix
;
574 sSuffix
= rData
.sOrSuffix
;
575 sSeparator
= rData
.sOrSeparator
;
576 nCaseMatch
= rData
.nOrCaseMatch
;
581 sPrefix
= rData
.sExactPrefix
;
582 sSuffix
= rData
.sExactSuffix
;
583 nCaseMatch
= rData
.nExactCaseMatch
;
587 String sURL
= sPrefix
;
591 sText
.ToUpperAscii();
592 else if(2 == nCaseMatch
)
593 sText
.ToLowerAscii();
595 if ((nTok
= sText
.GetTokenCount(cToken
)) > 1)
597 for (USHORT i
= 0; i
< nTok
; i
++)
599 sURL
+= sText
.GetToken(i
, cToken
);
601 sURL
+= (String
)sSeparator
;
603 sURL
+= (String
)sSuffix
;
608 sURL
+= (String
)sSuffix
;
610 sURL
.EraseAllChars(); // remove all spaces
611 SfxViewFrame
* pViewFrame
= SfxViewFrame::Current();
613 pViewFrame
= pViewFrame
->GetTopViewFrame();
614 OpenDoc( sURL
, pViewFrame
);
619 /*--------------------------------------------------------------------
621 --------------------------------------------------------------------*/
623 IMPL_LINK( SvxHyperlinkDlg
, BookmarkFoundHdl
, String
*, pUrl
)
625 if (pUrl
&& pUrl
->Len())
627 aUrlCB
.SetText(*pUrl
);
628 ComboModifyHdl(&aUrlCB
);
633 /*--------------------------------------------------------------------
634 Beschreibung: Link-Button enablen/disablen
635 --------------------------------------------------------------------*/
637 void SvxHyperlinkDlg::EnableLink()
639 BOOL bEnable
= aUrlCB
.GetText().Len() != 0;
641 EnableItem(BTN_LINK
, (!bNoDoc
) & bEnable
);
644 /*--------------------------------------------------------------------
645 Beschreibung: URL im Dokument einfuegen
646 --------------------------------------------------------------------*/
648 void SvxHyperlinkDlg::SendToApp(USHORT nType
)
650 BOOL bIsFile
= FALSE
;
652 String
sURL( aUrlCB
.GetText() );
657 String aBase
= GetBindings().GetDispatcher()->GetFrame()->GetObjectShell()->GetMedium()->GetBaseURL();
658 INetURLObject
aObj( URIHelper::SmartRel2Abs( INetURLObject(aBase
), sURL
, URIHelper::GetMaybeFileHdl(), true, false,
659 INetURLObject::WAS_ENCODED
,
660 INetURLObject::DECODE_UNAMBIGUOUS
) );
661 sURL
= aObj
.GetMainURL( INetURLObject::NO_DECODE
);
662 if ( aObj
.GetProtocol() == INET_PROT_FILE
)
668 SfxMedium
aMedium( sURL
, STREAM_STD_READ
, TRUE
);
669 if ( aMedium
.Exists( FALSE
) == FALSE
)
672 QueryBox
aBox( this, SVX_RES( RID_SVXQB_DONTEXIST
) );
673 if ( aBox
.Execute() == RET_NO
)
680 SvxHyperlinkItem
aItem( SID_HYPERLINK_SETLINK
);
682 if (aNameCB
.GetText().Len())
683 aItem
.SetName( aNameCB
.GetText() );
685 aItem
.SetName( sURL
);
687 sOldName
= aNameCB
.GetText();
690 aItem
.SetInsertMode( (SvxLinkInsertMode
)nType
);
691 aItem
.SetTargetFrame( GetSelTarget() );
693 GetBindings().GetDispatcher()->Execute(
694 SID_HYPERLINK_SETLINK
, SFX_CALLMODE_ASYNCHRON
| SFX_CALLMODE_RECORD
, &aItem
, 0L );
696 AddToHistory( aNameCB
.GetText(), sURL
);
698 if ( sURL
!= aUrlCB
.GetText() )
699 aUrlCB
.SetText( sURL
);
702 /*--------------------------------------------------------------------
703 Beschreibung: Selektierten Target Frame Eintrag im Popup ermitteln
704 --------------------------------------------------------------------*/
706 String
SvxHyperlinkDlg::GetSelTarget()
710 if (pTargetMenu
!= NULL
)
712 for (USHORT i
= 1; i
<= pTargetMenu
->GetItemCount(); i
++)
714 if (pTargetMenu
->IsItemChecked(i
))
716 sTarget
= pTargetMenu
->GetItemText(i
);
725 /*--------------------------------------------------------------------
726 Beschreibung: URL in History der Leiste aufnehmen
727 --------------------------------------------------------------------*/
729 void SvxHyperlinkDlg::AddToHistory(const String
& rName
, const String
& rURL
)
733 if (bHasOldName
&& sOldName
.Len())
744 USHORT nNamePos
= aNameCB
.GetEntryPos(sName
);
745 USHORT nUrlPos
= aUrlCB
.GetEntryPos(rURL
);
746 USHORT nPos
= COMBOBOX_ENTRY_NOTFOUND
;
748 if (nNamePos
!= COMBOBOX_ENTRY_NOTFOUND
)
753 // Alten Eintrag durch neuen Eintrag ersetzen
754 if (nPos
!= COMBOBOX_ENTRY_NOTFOUND
)
756 aNameCB
.RemoveEntry(nPos
);
757 aUrlCB
.RemoveEntry(nPos
);
758 aNameCB
.SetText(rName
);
759 aUrlCB
.SetText(rURL
);
762 aNameCB
.InsertEntry(sName
, 0);
763 aUrlCB
.InsertEntry(rURL
, 0);
767 /*--------------------------------------------------------------------
768 Beschreibung: Bookmark und Search-Button enablen/disablen
769 --------------------------------------------------------------------*/
771 IMPL_LINK( SvxHyperlinkDlg
, ComboSelectHdl
, ComboBox
*, pCombo
)
773 USHORT nPos
= pCombo
->GetEntryPos(pCombo
->GetText());
775 if (nPos
!= COMBOBOX_ENTRY_NOTFOUND
)
777 aNameCB
.SetText(aNameCB
.GetEntry(nPos
));
778 aUrlCB
.SetText(aUrlCB
.GetEntry(nPos
));
781 EnableItem(BTN_INSERT_BOOKMARK
, TRUE
);
782 EnableItem(BTN_INET_SEARCH
, TRUE
);
787 /*--------------------------------------------------------------------
789 --------------------------------------------------------------------*/
791 IMPL_LINK( SvxHyperlinkDlg
, ComboModifyHdl
, ComboBox
*, pCombo
)
795 if (!pCombo
->GetText().Len())
798 if (pCombo
== &aNameCB
)
800 if (IsItemEnabled(BTN_INET_SEARCH
) != bEnable
)
801 EnableItem(BTN_INET_SEARCH
, bEnable
);
806 if (aUrlCB
.GetText().Len())
811 if (IsItemEnabled(BTN_INSERT_BOOKMARK
) != bEnable
)
812 EnableItem(BTN_INSERT_BOOKMARK
, bEnable
);
817 // --------------------------------------------------------------------
819 void SvxHyperlinkDlg::DataChanged( const DataChangedEvent
& rDCEvt
)
821 ToolBox::DataChanged( rDCEvt
);
823 if ( (rDCEvt
.GetType() == DATACHANGED_SETTINGS
) && (rDCEvt
.GetFlags() & SETTINGS_STYLE
))
827 // --------------------------------------------------------------------
829 void SvxHyperlinkDlg::SetImages()
831 bool bHighContrast
= GetSettings().GetStyleSettings().GetHighContrastMode() != 0;
834 bHighContrast
= GetDisplayBackground().GetColor().IsDark() != 0;
836 SetItemImage( BTN_LINK
, mpManager
->GetImage( BTN_LINK
, bHighContrast
) );
837 SetItemImage( BTN_INSERT_BOOKMARK
, mpManager
->GetImage( BTN_INSERT_BOOKMARK
, bHighContrast
) );
838 SetItemImage( BTN_INET_SEARCH
, mpManager
->GetImage( BTN_INET_SEARCH
, bHighContrast
) );
839 SetItemImage( BTN_TARGET
, mpManager
->GetImage( BTN_TARGET
, bHighContrast
) );
840 SetItemImage( BTN_OPENDIALOG
, mpManager
->GetImage( BTN_OPENDIALOG
, bHighContrast
) );
843 /*--------------------------------------------------------------------
844 Beschreibung: Comboboxen
845 --------------------------------------------------------------------*/
847 HyperCombo::HyperCombo( SvxHyperlinkDlg
* pDialog
, const ResId
& rResId
) :
848 ComboBox( (Window
*)pDialog
, rResId
)
852 nMaxWidth
= GetSizePixel().Width();
853 if (this == &pDlg
->aUrlCB
)
854 nMinWidth
= GetTextWidth(String::CreateFromAscii("http://www.stardiv.dewww"));
856 nMinWidth
= GetTextWidth(String::CreateFromAscii("StarDivision GmbHwww"));
859 /*--------------------------------------------------------------------
860 Beschreibung: Comboboxen KeyInput
861 --------------------------------------------------------------------*/
863 long HyperCombo::Notify( NotifyEvent
& rNEvt
)
866 static BOOL bLocked
= FALSE
;
868 if (bLocked
) // Keine weiteren RETURNs annehmen (nicht Reentrant!)
873 if ( rNEvt
.GetType() == EVENT_KEYINPUT
)
875 const KeyEvent
* pKEvt
= rNEvt
.GetKeyEvent();
876 const KeyCode aKeyCode
= pKEvt
->GetKeyCode();
878 if (aKeyCode
.GetCode() == KEY_RETURN
)
880 pDlg
->SendToApp(HLINK_DEFAULT
);
884 if (this == &pDlg
->aNameCB
)
885 pDlg
->sOldName
= GetText();
888 nHandled
= ComboBox::Notify( rNEvt
);
895 /*--------------------------------------------------------------------
896 Beschreibung: Drag&Drop vor dem Combo-Edit abfangen und weiterleiten
897 --------------------------------------------------------------------*/
899 long HyperCombo::PreNotify( NotifyEvent
& rNEvt
)
903 nHandled
= ComboBox::PreNotify( rNEvt
);
908 /*--------------------------------------------------------------------
910 --------------------------------------------------------------------*/
912 long HyperCombo::CalcResizeWidth( long nW
)
914 long nNewWidth
= Max(nMaxWidth
- nW
* GetRatio() / 100L, nMinWidth
);
916 if (nNewWidth
> nMaxWidth
)
917 nNewWidth
= nMaxWidth
;
919 if (nNewWidth
!= GetSizePixel().Width())
922 return 0; // Kein Resize notwendig
925 /*--------------------------------------------------------------------
927 --------------------------------------------------------------------*/
929 void HyperCombo::DoResize( long nNewWidth
)
931 SetSizePixel(Size(nNewWidth
, GetSizePixel().Height()));
934 /*--------------------------------------------------------------------
935 Beschreibung: FixedText
936 --------------------------------------------------------------------*/
938 HyperFixedText::HyperFixedText( SvxHyperlinkDlg
* pDialog
, const ResId
& rResId
) :
939 FixedInfo( (Window
*)pDialog
, rResId
)
944 /*--------------------------------------------------------------------
945 Beschreibung: Webseite der Search-Engine mit Suchergebnissen anzeigen
946 --------------------------------------------------------------------*/
947 void SvxHyperlinkDlg::OpenDoc( const String
& rURL
, SfxViewFrame
* pViewFrame
)
949 SfxStringItem
aName( SID_FILE_NAME
, rURL
);
950 SfxStringItem
aReferer( SID_REFERER
, String::CreateFromAscii("private:user") );
951 SfxBoolItem
aNewView( SID_OPEN_NEW_VIEW
, TRUE
);
952 SfxBoolItem
aSilent( SID_SILENT
, TRUE
);
953 SfxBoolItem
aReadOnly( SID_DOC_READONLY
, TRUE
);
954 SfxBoolItem
aExternal( SID_BROWSE
, TRUE
);
955 SfxDispatcher
* pDisp
= SfxViewFrame::Current() ? SfxViewFrame::Current()->GetDispatcher() : NULL
;
959 SfxFrameItem
aView( SID_DOCFRAME
, pViewFrame
? pViewFrame
->GetFrame() : NULL
);
961 pDisp
->Execute( SID_OPENDOC
, SFX_CALLMODE_ASYNCHRON
| SFX_CALLMODE_RECORD
,
962 &aName
, &aView
, &aNewView
, &aSilent
, &aReadOnly
, &aReferer
, &aExternal
, 0L );
965 pDisp
->Execute( SID_OPENDOC
, SFX_CALLMODE_ASYNCHRON
| SFX_CALLMODE_RECORD
,
966 &aName
, &aNewView
, &aSilent
, &aReadOnly
, &aReferer
, 0L );
968 // class SvxHyperlinkDialogWrapper ------------------------------------------
970 SFX_IMPL_CHILDWINDOW(SvxHyperlinkDlgWrapper
, SID_HYPERLINK_INSERT
)
972 /*--------------------------------------------------------------------
973 Beschreibung: Wrapper fuer Hyperlinkleiste
974 --------------------------------------------------------------------*/
976 SvxHyperlinkDlgWrapper::SvxHyperlinkDlgWrapper( Window
* _pParent
, USHORT nId
,
977 SfxBindings
* _pBindings
, SfxChildWinInfo
* /*pInfo*/ ) :
979 SfxChildWindow( _pParent
, nId
)
982 pWindow
= new SvxHyperlinkDlg( _pBindings
, _pParent
);
983 eChildAlignment
= SFX_ALIGN_TOP
;
986 /*--------------------------------------------------------------------
988 --------------------------------------------------------------------*/
990 SfxChildWinInfo
SvxHyperlinkDlgWrapper::GetInfo() const
992 SfxChildWinInfo aInfo
= SfxChildWindow::GetInfo();