xref: /aoo41x/main/svx/source/dialog/hyprlink.cxx (revision cdf0e10c)
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_svx.hxx"
30 #include <tools/urlobj.hxx>
31 #include <vcl/msgbox.hxx>
32 #include <unotools/configitem.hxx>
33 #include <unotools/cmdoptions.hxx>
34 #include <svtools/inetimg.hxx>
35 #include <svl/urlbmk.hxx>
36 #include <svl/eitem.hxx>
37 #include <svl/stritem.hxx>
38 #include <sfx2/viewfrm.hxx>
39 #include <sfx2/docfile.hxx>
40 #include <sfx2/imgmgr.hxx>
41 #include <sfx2/dispatch.hxx>
42 #include <svl/urihelper.hxx>
43 #include <sfx2/objsh.hxx>
44 #include <comphelper/processfactory.hxx>
45 
46 #include "svx/hlnkitem.hxx"
47 #include <svx/dialogs.hrc>
48 #include "hyprlink.hrc"
49 #include <svx/dialmgr.hxx>
50 #include "svx/hyprlink.hxx"
51 #include "hyprdlg.hxx"
52 
53 using namespace ::rtl;
54 using namespace ::com::sun::star;
55 
56 // -----------------------------------------------------------------------
57 
58 class SearchDefaultConfigItem_Impl : public ::utl::ConfigItem
59 {
60     OUString    sDefaultEngine;
61 public:
62     SearchDefaultConfigItem_Impl();
63     ~SearchDefaultConfigItem_Impl();
64 
65     const OUString&    GetDefaultSearchEngine(){ return sDefaultEngine;}
66     virtual void            Notify( const com::sun::star::uno::Sequence< rtl::OUString >& aPropertyNames );
67     virtual void            Commit();
68 };
69 
70 /*-- 11.11.2003 14:20:59---------------------------------------------------
71 
72   -----------------------------------------------------------------------*/
73 SearchDefaultConfigItem_Impl::SearchDefaultConfigItem_Impl() :
74         ConfigItem(OUString::createFromAscii("Inet/DefaultSearchEngine"))
75 {
76     uno::Sequence<OUString> aNames(1);
77     aNames.getArray()[0] = OUString::createFromAscii("Name");
78     uno::Sequence< uno::Any > aValues = GetProperties(aNames);
79     aValues.getConstArray()[0] >>= sDefaultEngine;
80 }
81 /*-- 11.11.2003 14:21:00---------------------------------------------------
82 
83   -----------------------------------------------------------------------*/
84 SearchDefaultConfigItem_Impl::~SearchDefaultConfigItem_Impl()
85 {
86 }
87 
88 void SearchDefaultConfigItem_Impl::Notify( const com::sun::star::uno::Sequence< rtl::OUString >& )
89 {
90 }
91 
92 void SearchDefaultConfigItem_Impl::Commit()
93 {
94 }
95 
96 /*************************************************************************
97 |*
98 |* Dialog zum Einf"ugen/"Andern eines Hyperlink
99 |*
100 \************************************************************************/
101 
102 SvxHyperlinkDlg::SvxHyperlinkDlg( SfxBindings *_pBindings, Window* pParent) :
103 
104     ToolBox             ( pParent, SVX_RES( RID_SVXDLG_HYPERLINK ) ),
105     SfxControllerItem   ( SID_HYPERLINK_SETLINK, *_pBindings ),
106 
107 	aForwarder			( SID_HYPERLINK_GETLINK, *this ),
108 	aHyperlinkDlgForward( SID_HYPERLINK_DIALOG , *this),
109 
110 	aNameCB				( this, SVX_RES( CB_NAME ) ),
111 	aUrlFT				( this, SVX_RES( FT_URL ) ),
112 	aUrlCB				( this, SVX_RES( CB_URL ) ),
113     aSearchConfig       (sal_True),
114 	sAddress			( SVX_RES( STR_ADDRESS ) ),
115 	sExplorer			( SVX_RES( STR_EXPLORER ) ),
116 	sSearchTitle		( SVX_RES( STR_BOOKMARK_SEARCH ) ),
117 	aLinkPopup			( SVX_RES( RID_SVXMN_HYPERLINK ) ),
118 	pTargetMenu			( NULL ),
119 
120     bNoDoc              ( sal_True ),
121     bSend               ( sal_False ),
122     bHasOldName         ( sal_False ),
123     bHtmlMode           ( sal_False )
124 
125 {
126 	FreeResource();
127 
128     mpManager = SfxImageManager::GetImageManager( 0 );
129 	mpManager->RegisterToolBox( this );
130 
131 	SetImages();
132 
133     // save initial size
134 	nMaxWidth = GetSizePixel().Width();
135 	nMaxHeight = GetSizePixel().Height();
136 
137 
138 	InsertSeparator( 0 );
139 	InsertWindow( CB_URL, &aUrlCB, 0, 0 );
140 	// we need an item text for accessibility
141 	String sItemText = aUrlCB.GetText();
142 	if ( sItemText.Len() == 0 )
143 		sItemText = aUrlCB.GetQuickHelpText();
144 	if ( sItemText.Len() > 0 )
145 	{
146 		SetItemText( CB_URL, sItemText );
147 		sItemText.Erase();
148 	}
149 	InsertWindow( FT_URL, &aUrlFT, 0, 0 );
150 	InsertSeparator( 0 );
151 	InsertWindow( CB_NAME, &aNameCB, 0, 0 );
152 	sItemText = aNameCB.GetText();
153 	if ( sItemText.Len() == 0 )
154 		sItemText = aNameCB.GetQuickHelpText();
155 	if ( sItemText.Len() > 0 )
156 		SetItemText( CB_NAME, sItemText );
157 
158 	SetSizePixel(CalcWindowSizePixel());	// Groesse initialisieren
159 
160 	nMaxHeight = GetSizePixel().Height();	// Hoehe nochmal merken, da sie veraendert wurde
161 											// SetSizePixel ruft Resize-Handler!
162 
163     Show();
164 	Resize();
165 
166 	long nUrlWidth = aUrlCB.GetResizeWidth();
167 	long nNameWidth = aNameCB.GetResizeWidth();
168 	long nSum = nUrlWidth + nNameWidth;
169 
170 	aUrlCB.SetRatio((nUrlWidth * 100L) / nSum);
171 	aNameCB.SetRatio((nNameWidth * 100L) / nSum);
172 
173 	SetClickHdl( LINK( this, SvxHyperlinkDlg, TBClickHdl ) );
174 	SetSelectHdl( LINK( this, SvxHyperlinkDlg, TBSelectHdl ) );
175     SetDropdownClickHdl( LINK( this, SvxHyperlinkDlg, DropdownClick ) );
176 
177     SetItemBits( BTN_TARGET, GetItemBits( BTN_TARGET ) | TIB_DROPDOWNONLY );
178     SetItemBits( BTN_INET_SEARCH, GetItemBits( BTN_INET_SEARCH ) | TIB_DROPDOWN );
179     SetItemBits( BTN_INET_SEARCH, GetItemBits( BTN_TARGET ) | TIB_DROPDOWNONLY );
180 
181 	aLinkPopup.SetSelectHdl(LINK(this, SvxHyperlinkDlg, LinkPopupSelectHdl));
182 
183 	Link aLk = LINK(this, SvxHyperlinkDlg, ComboSelectHdl);
184 	aNameCB.SetSelectHdl(aLk);
185 	aUrlCB.SetSelectHdl(aLk);
186 
187 	aLk = LINK(this, SvxHyperlinkDlg, ComboModifyHdl);
188 	aNameCB.SetModifyHdl(aLk);
189 	aUrlCB.SetModifyHdl(aLk);
190 
191     // Accessibility: Set the quick help text as accessible name for the
192     // drop down lists.
193     aNameCB.SetAccessibleName (aNameCB.GetQuickHelpText());
194     aUrlCB.SetAccessibleName (aUrlCB.GetQuickHelpText());
195 
196     // Hide button according to config item.
197     SvtCommandOptions aCmdOpts;
198     if ( aCmdOpts.Lookup( SvtCommandOptions::CMDOPTION_DISABLED,
199                           rtl::OUString(
200                               RTL_CONSTASCII_USTRINGPARAM(
201                                   "InternetSearch" ) ) ) )
202         HideItem( BTN_INET_SEARCH );
203 }
204 
205 /*--------------------------------------------------------------------
206 	Beschreibung:
207  --------------------------------------------------------------------*/
208 
209 SvxHyperlinkDlg::~SvxHyperlinkDlg()
210 {
211     SfxImageManager::GetImageManager( 0 )->ReleaseToolBox(this);
212 
213     if (pTargetMenu != NULL)
214 		delete pTargetMenu;
215 }
216 
217 /*--------------------------------------------------------------------
218 	Beschreibung: Leiste so resizen, dass die Comboboxen automatisch mit
219 	verkleinert werden
220  --------------------------------------------------------------------*/
221 
222 void SvxHyperlinkDlg::Resize()
223 {
224 	long nWidth = GetSizePixel().Width();
225 
226 	ToolBox::Resize();
227 
228 	if (nWidth)	// nWidth ist manchmal 0
229 	{
230 		long nDeltaW = nMaxWidth - nWidth + aUrlCB.LogicToPixel(Size(3, 1)).Width() + 1;
231 
232 		long nNewUrlWidth = aUrlCB.CalcResizeWidth(nDeltaW);
233 		long nNewNameWidth = aNameCB.CalcResizeWidth(nDeltaW);
234 
235 		if (nNewUrlWidth && nNewNameWidth)	// Flackern reduzieren
236 		{
237 			SetUpdateMode(sal_False);
238 
239 			// Comboboxen resizen
240 			aUrlCB.DoResize(nNewUrlWidth);
241 			aNameCB.DoResize(nNewNameWidth);
242 			RecalcItems();	// Alle Elemente neu anordnen
243 
244 			SetUpdateMode(sal_True);
245 		}
246 	}
247 }
248 
249 /*--------------------------------------------------------------------
250 	Beschreibung:
251  --------------------------------------------------------------------*/
252 
253 void SvxHyperlinkDlg::Resizing(Size& rSize)
254 {
255 	if (rSize.Height() > nMaxHeight)
256 		rSize.Height() = nMaxHeight;
257 
258 	if (rSize.Width() > nMaxWidth)
259 		rSize.Width() = nMaxWidth;
260 
261 	ToolBox::Resizing(rSize);
262 }
263 
264 /*--------------------------------------------------------------------
265 	Beschreibung: Im Dokument selektierten Hyperlink in Leiste anzeigen
266  --------------------------------------------------------------------*/
267 
268 void SvxHyperlinkDlg::StateChanged( sal_uInt16 nSID, SfxItemState eState,
269 													const SfxPoolItem* pState )
270 {
271 	if ( nSID == SID_HYPERLINK_DIALOG )
272 	{
273 		if( eState != SFX_ITEM_DISABLED)
274 		{
275 			EnableItem( BTN_OPENDIALOG, sal_True );
276 
277 			sal_Bool bItem = sal_False;
278 			if ( pState && eState == SFX_ITEM_AVAILABLE )
279 					bItem = ((SfxBoolItem*)pState)->GetValue();
280 			SetItemState ( BTN_OPENDIALOG, bItem ? STATE_CHECK : STATE_NOCHECK );
281 		}
282 		else
283 		{
284 			SetItemState ( BTN_OPENDIALOG, STATE_NOCHECK );
285 			EnableItem( BTN_OPENDIALOG, sal_False );
286 		}
287 	}
288 
289 	if (nSID == SID_HYPERLINK_SETLINK)
290 	{
291 		if (eState == SFX_ITEM_DISABLED)
292 			bNoDoc = sal_True;
293 		else
294 			bNoDoc = sal_False;
295 		EnableItem(BTN_TARGET, !bNoDoc);
296 		EnableLink();
297 	}
298 
299 	if (nSID == SID_HYPERLINK_GETLINK)
300 	{
301 		if (eState == SFX_ITEM_AVAILABLE)
302 		{
303 			const SvxHyperlinkItem& rHLnkItem = *((const SvxHyperlinkItem*)pState);
304 
305 			sal_uInt16 nNamePos = aNameCB.GetEntryPos(aNameCB.GetText());
306 			sal_uInt16 nUrlPos = aUrlCB.GetEntryPos(aUrlCB.GetText());
307 			sal_uInt16 nNotFound = COMBOBOX_ENTRY_NOTFOUND;
308 
309 			if (!bHasOldName &&
310 				(nNamePos == nNotFound || nUrlPos == nNotFound))
311 			{
312 				sOldName = aNameCB.GetText();
313 				bHasOldName = sal_True;
314 			}
315 			if (rHLnkItem.GetName().Len())
316 			{
317 				aNameCB.SetText(rHLnkItem.GetName());
318 				ComboModifyHdl(&aNameCB);
319 			}
320 			if (rHLnkItem.GetURL().Len() || rHLnkItem.GetName().Len())
321 			{
322 				String sUrl = INetURLObject(rHLnkItem.GetURL()).GetURLNoPass();
323 				aUrlCB.SetText(sUrl);
324 			}
325 			else if (aUrlCB.GetEntryCount())
326 			{	// Letzten Eintrag wieder selektieren
327 				aNameCB.SetText(aNameCB.GetEntry(0));
328 				aUrlCB.SetText(aUrlCB.GetEntry(0));
329 			}
330 
331 			TargetMenu(rHLnkItem.GetTargetFrame(), sal_False);
332 			bHtmlMode = (rHLnkItem.GetInsertMode() & HLINK_HTMLMODE) != 0;
333 		}
334 		else
335 			return;
336 
337 		ComboModifyHdl(&aUrlCB);
338 	}
339 }
340 
341 /*--------------------------------------------------------------------
342 	Beschreibung:
343  --------------------------------------------------------------------*/
344 
345 IMPL_LINK( SvxHyperlinkDlg, TBClickHdl, ToolBox *, pBox )
346 {
347 	switch (pBox->GetCurItemId())
348 	{
349 		case BTN_LINK:
350 		{
351 			if (!bSend)	// Link ins Dokument einfuegen
352 				SendToApp(HLINK_DEFAULT);
353 		}
354 		break;
355 
356 		case BTN_OPENDIALOG:
357 		{
358 			GetBindings().GetDispatcher()->Execute( SID_HYPERLINK_DIALOG );
359 		}
360 		break;
361 	}
362 
363 	return sal_True;
364 }
365 
366 /*--------------------------------------------------------------------
367 	Beschreibung:
368  --------------------------------------------------------------------*/
369 
370 IMPL_LINK( SvxHyperlinkDlg, TBSelectHdl, ToolBox *, pBox )
371 {
372 	switch (pBox->GetCurItemId())
373 	{
374 		// Link als Bookmark im Explorer eintragen
375 		// Soll erst im Loslassen der Maus gerufen werden, daher im Select-Hdl
376 		case BTN_INSERT_BOOKMARK:
377 		{
378 			String sName = aNameCB.GetText();
379 			if ( !sName.Len() )
380 				sName = aUrlCB.GetText();
381 
382             String aBase = GetBindings().GetDispatcher()->GetFrame()->GetObjectShell()->GetMedium()->GetBaseURL();
383 			SfxStringItem aName( SID_BOOKMARK_TITLE, sName );
384 			SfxStringItem aURL( SID_BOOKMARK_URL,
385                                 URIHelper::SmartRel2Abs( INetURLObject(aBase), aUrlCB.GetText(), URIHelper::GetMaybeFileHdl(), true, false,
386 														  INetURLObject::WAS_ENCODED,
387 														  INetURLObject::DECODE_UNAMBIGUOUS ) );
388 			GetBindings().GetDispatcher()->Execute(
389 				SID_CREATELINK, SFX_CALLMODE_ASYNCHRON, &aName, &aURL, 0L );
390 		}
391 		break;
392 	}
393 
394 	return sal_True;
395 }
396 
397 IMPL_LINK( SvxHyperlinkDlg, DropdownClick, ToolBox *, pBox )
398 {
399 	switch (pBox->GetCurItemId())
400     {
401 		case BTN_LINK:
402 		{
403 			// Link-Popup anstossen
404 	        EndSelection();	// Vor dem Execute, damit Popup den Focus bekommt
405 	        aLinkPopup.EnableItem(MN_BUTTON, !bHtmlMode);
406 	        aLinkPopup.Execute( this, GetItemRect( BTN_LINK ), FLOATWIN_POPUPMODE_DOWN );
407 		}
408 		break;
409 
410 		case BTN_INET_SEARCH:
411 		{
412 			// Search-Engines per Popup auswaehlen
413 			PopupMenu *pMenu = new PopupMenu;
414 			pMenu->SetSelectHdl(LINK(this, SvxHyperlinkDlg, SearchPopupSelectHdl));
415             SearchDefaultConfigItem_Impl aDefaultEngine;
416             String sDefault(aDefaultEngine.GetDefaultSearchEngine());
417             sDefault.ToLowerAscii();
418             const bool bHasDefault = sDefault.Len() > 0;
419 
420             sal_uInt16         nCount = aSearchConfig.Count();
421 			String sFound;
422             for (sal_uInt16 i = 0; i < nCount; i++)
423             {
424                 const SvxSearchEngineData& rData = aSearchConfig.GetData(i);
425                 //check if it's the configured default search engine
426                 String sTest(rData.sEngineName);
427                 sTest.ToLowerAscii();
428                 bool bIsDefaultEngine = bHasDefault && STRING_NOTFOUND != sTest.Search( sDefault );
429                 //then put it at the top
430                 if(i && bIsDefaultEngine)
431                 {
432                     pMenu->InsertItem( i + 1, rData.sEngineName, 0, 0);
433                     pMenu->InsertSeparator(1);
434                 }
435                 else
436                 {
437                     if (i)
438                         pMenu->InsertSeparator();
439                     pMenu->InsertItem( i + 1, rData.sEngineName);
440                 }
441             }
442             pBox->SetItemDown(BTN_INET_SEARCH, sal_True, sal_True);
443             pMenu->Execute( this, GetItemRect( BTN_INET_SEARCH ), FLOATWIN_POPUPMODE_DOWN );
444             pBox->SetItemDown(BTN_INET_SEARCH, sal_False, sal_True);
445             EndSelection();
446 			delete pMenu;
447 		}
448 		break;
449 
450         case BTN_TARGET:
451 		{
452 			// Target Frame einstellen
453 			TargetMenu(GetSelTarget(), sal_True);
454 			EndSelection();
455 		}
456 		break;
457     }
458 
459 	return sal_True;
460 }
461 
462 /*--------------------------------------------------------------------
463 	Beschreibung:
464  --------------------------------------------------------------------*/
465 
466 void SvxHyperlinkDlg::TargetMenu(const String& rSelEntry, sal_Bool bExecute)
467 {
468 	if (pTargetMenu && !bExecute)
469 	{
470 		for (sal_uInt16 i = 1; i <= pTargetMenu->GetItemCount(); i++)
471 		{
472 			if (pTargetMenu->GetItemText(i) == rSelEntry)
473 			{
474 				pTargetMenu->CheckItem(i);
475 				return;
476 			}
477 		}
478 	}
479 
480 	SfxViewFrame* pVwFrm = SfxViewFrame::Current();
481 
482 	if (pVwFrm)	// Alle moeglichen Target Frames zusammensammeln und anzeigen
483 	{
484 		TargetList aList;
485 		pVwFrm->GetTopFrame().GetTargetList(aList);
486 
487 		sal_uInt16 nCount = (sal_uInt16)aList.Count();
488 		if( nCount )
489 		{
490 			sal_Bool bChecked = sal_False;
491 
492 			if (pTargetMenu != NULL)
493 				delete pTargetMenu;
494 
495 			pTargetMenu = new PopupMenu;
496 			pTargetMenu->SetMenuFlags( pTargetMenu->GetMenuFlags() |
497 									   MENU_FLAG_NOAUTOMNEMONICS );
498 			sal_uInt16 i;
499 			for ( i = 0; i < nCount; i++ )
500 			{
501 				String sEntry(*aList.GetObject(i));
502 				pTargetMenu->InsertItem(i + 1, sEntry, MIB_RADIOCHECK|MIB_AUTOCHECK);
503 
504 				if (sEntry == rSelEntry)
505 				{
506 					pTargetMenu->CheckItem(i + 1);
507 					bChecked = sal_True;
508 				}
509 			}
510 			for ( i = nCount; i; i-- )
511 				delete aList.GetObject( i - 1 );
512 
513 			if (!bChecked)
514 				pTargetMenu->CheckItem(1);
515 
516 			if (bExecute)
517 			{
518 				sal_uInt16 nEntry = pTargetMenu->Execute(
519 					this, GetItemRect( BTN_TARGET ), FLOATWIN_POPUPMODE_DOWN );
520 				if ( nEntry )
521 					pTargetMenu->CheckItem( nEntry );
522 			}
523 		}
524 	}
525 }
526 
527 /*--------------------------------------------------------------------
528 	Beschreibung:
529  --------------------------------------------------------------------*/
530 
531 IMPL_LINK( SvxHyperlinkDlg, LinkPopupSelectHdl, Menu *, pMenu )
532 {
533 	switch (pMenu->GetCurItemId())
534 	{
535 		case MN_FIELD:	// URL als Hyperlink ins Dok einfuegen
536 			SendToApp(HLINK_FIELD);
537 			break;
538 		case MN_BUTTON:	// URL als Button ins Dok einfuegen
539 			SendToApp(HLINK_BUTTON);
540 			break;
541 	}
542 
543 	return sal_True;
544 }
545 
546 /*--------------------------------------------------------------------
547 	Beschreibung:
548  --------------------------------------------------------------------*/
549 
550 IMPL_LINK( SvxHyperlinkDlg, SearchPopupSelectHdl, Menu *, pMenu )
551 {
552     const SvxSearchEngineData&  rData = aSearchConfig.GetData(pMenu->GetCurItemId() - 1);
553     String sText(aNameCB.GetText());
554     sText.EraseLeadingChars().EraseTrailingChars();
555 
556     rtl::OUString   sPrefix;
557     rtl::OUString   sSuffix;
558     rtl::OUString   sSeparator;
559     sal_Int32       nCaseMatch;
560     sal_Unicode cToken = 0;
561 
562     if (sText.Search(' ') != STRING_NOTFOUND)
563     {
564         sPrefix = rData.sExactPrefix;
565         sSuffix = rData.sExactSuffix;
566         sSeparator = rData.sExactSeparator;
567         nCaseMatch = rData.nExactCaseMatch;
568         cToken = ' ';
569     }
570     else if (sText.Search('+') != STRING_NOTFOUND)
571     {
572         sPrefix = rData.sAndPrefix;
573         sSuffix = rData.sAndSuffix;
574         sSeparator = rData.sAndSeparator;
575         nCaseMatch = rData.nAndCaseMatch;
576         cToken = '+';
577     }
578     else if (sText.Search(',') != STRING_NOTFOUND)
579     {
580         sPrefix = rData.sOrPrefix;
581         sSuffix = rData.sOrSuffix;
582         sSeparator = rData.sOrSeparator;
583         nCaseMatch = rData.nOrCaseMatch;
584         cToken = ',';
585     }
586     else
587     {
588         sPrefix = rData.sExactPrefix;
589         sSuffix = rData.sExactSuffix;
590         nCaseMatch = rData.nExactCaseMatch;
591         cToken = 0;
592     }
593 
594     String sURL = sPrefix;
595 	xub_StrLen nTok;
596 
597     if(1 == nCaseMatch)
598         sText.ToUpperAscii();
599     else if(2 == nCaseMatch)
600         sText.ToLowerAscii();
601 
602     if ((nTok = sText.GetTokenCount(cToken)) > 1)
603 	{
604 		for (sal_uInt16 i = 0; i < nTok; i++)
605 		{
606             sURL += sText.GetToken(i, cToken);
607             if(i < nTok -1)
608                 sURL += (String)sSeparator;
609 		}
610         sURL += (String)sSuffix;
611 	}
612 	else
613 	{
614         sURL += sText;
615         sURL += (String)sSuffix;
616 	}
617     sURL.EraseAllChars();   // remove all spaces
618     SfxViewFrame* pViewFrame = SfxViewFrame::Current();
619     if ( pViewFrame )
620         pViewFrame = pViewFrame->GetTopViewFrame();
621     OpenDoc( sURL, pViewFrame );
622 
623     return sal_True;
624 }
625 
626 /*--------------------------------------------------------------------
627 	Beschreibung:
628  --------------------------------------------------------------------*/
629 
630 IMPL_LINK( SvxHyperlinkDlg, BookmarkFoundHdl, String *, pUrl )
631 {
632 	if (pUrl && pUrl->Len())
633 	{
634 		aUrlCB.SetText(*pUrl);
635 		ComboModifyHdl(&aUrlCB);
636 	}
637 
638 	return sal_True;
639 }
640 /*--------------------------------------------------------------------
641 	Beschreibung: Link-Button enablen/disablen
642  --------------------------------------------------------------------*/
643 
644 void SvxHyperlinkDlg::EnableLink()
645 {
646 	sal_Bool bEnable = aUrlCB.GetText().Len() != 0;
647 
648 	EnableItem(BTN_LINK, (!bNoDoc) & bEnable);
649 }
650 
651 /*--------------------------------------------------------------------
652 	Beschreibung: URL im Dokument einfuegen
653  --------------------------------------------------------------------*/
654 
655 void SvxHyperlinkDlg::SendToApp(sal_uInt16 nType)
656 {
657 	sal_Bool bIsFile = sal_False;
658 	bSend = sal_True;
659 	String sURL( aUrlCB.GetText() );
660 
661 	if ( !sURL.Len() )
662 		return;
663 
664     String aBase = GetBindings().GetDispatcher()->GetFrame()->GetObjectShell()->GetMedium()->GetBaseURL();
665     INetURLObject aObj( URIHelper::SmartRel2Abs( INetURLObject(aBase), sURL, URIHelper::GetMaybeFileHdl(), true, false,
666 												  INetURLObject::WAS_ENCODED,
667 												  INetURLObject::DECODE_UNAMBIGUOUS ) );
668 	sURL = aObj.GetMainURL( INetURLObject::NO_DECODE );
669 	if ( aObj.GetProtocol() == INET_PROT_FILE )
670 		bIsFile = sal_True;
671 
672 	if ( bIsFile )
673 	{
674 		EnterWait();
675 		SfxMedium aMedium( sURL, STREAM_STD_READ, sal_True );
676 		if ( aMedium.Exists( sal_False ) == sal_False )
677 		{
678 			LeaveWait();
679 			QueryBox aBox( this, SVX_RES( RID_SVXQB_DONTEXIST ) );
680 			if ( aBox.Execute() == RET_NO )
681 				return;
682 		}
683 		else
684 			LeaveWait();
685 	}
686 
687 	SvxHyperlinkItem aItem( SID_HYPERLINK_SETLINK );
688 
689 	if (aNameCB.GetText().Len())
690 		aItem.SetName( aNameCB.GetText() );
691 	else
692 		aItem.SetName( sURL );
693 
694 	sOldName = aNameCB.GetText();
695 
696 	aItem.SetURL(sURL);
697 	aItem.SetInsertMode( (SvxLinkInsertMode)nType );
698 	aItem.SetTargetFrame( GetSelTarget() );
699 
700 	GetBindings().GetDispatcher()->Execute(
701 		SID_HYPERLINK_SETLINK, SFX_CALLMODE_ASYNCHRON | SFX_CALLMODE_RECORD, &aItem, 0L );
702 
703 	AddToHistory( aNameCB.GetText(), sURL );
704 
705 	if ( sURL != aUrlCB.GetText() )
706 		aUrlCB.SetText( sURL );
707 }
708 
709 /*--------------------------------------------------------------------
710 	Beschreibung: Selektierten Target Frame Eintrag im Popup ermitteln
711  --------------------------------------------------------------------*/
712 
713 String SvxHyperlinkDlg::GetSelTarget()
714 {
715 	String sTarget;
716 
717 	if (pTargetMenu != NULL)
718 	{
719 		for (sal_uInt16 i = 1; i <= pTargetMenu->GetItemCount(); i++)
720 		{
721 			if (pTargetMenu->IsItemChecked(i))
722 			{
723 				sTarget = pTargetMenu->GetItemText(i);
724 				break;
725 			}
726 		}
727 	}
728 
729 	return sTarget;
730 }
731 
732 /*--------------------------------------------------------------------
733 	Beschreibung: URL in History der Leiste aufnehmen
734  --------------------------------------------------------------------*/
735 
736 void SvxHyperlinkDlg::AddToHistory(const String& rName, const String& rURL)
737 {
738 	String sName(rName);
739 
740 	if (bHasOldName && sOldName.Len())
741 	{
742 		sName = sOldName;
743 		bHasOldName = sal_False;
744 	}
745 
746 	if (!sName.Len())
747 		sName = rURL;
748 
749 	if (rURL.Len())
750 	{
751 		sal_uInt16 nNamePos = aNameCB.GetEntryPos(sName);
752 		sal_uInt16 nUrlPos = aUrlCB.GetEntryPos(rURL);
753 		sal_uInt16 nPos = COMBOBOX_ENTRY_NOTFOUND;
754 
755 		if (nNamePos != COMBOBOX_ENTRY_NOTFOUND)
756 			nPos = nNamePos;
757 		else
758 			nPos = nUrlPos;
759 
760 		// Alten Eintrag durch neuen Eintrag ersetzen
761 		if (nPos != COMBOBOX_ENTRY_NOTFOUND)
762 		{
763 			aNameCB.RemoveEntry(nPos);
764 			aUrlCB.RemoveEntry(nPos);
765 			aNameCB.SetText(rName);
766 			aUrlCB.SetText(rURL);
767 		}
768 
769 		aNameCB.InsertEntry(sName, 0);
770 		aUrlCB.InsertEntry(rURL, 0);
771 	}
772 }
773 
774 /*--------------------------------------------------------------------
775 	Beschreibung: Bookmark und Search-Button enablen/disablen
776  --------------------------------------------------------------------*/
777 
778 IMPL_LINK( SvxHyperlinkDlg, ComboSelectHdl, ComboBox *, pCombo )
779 {
780 	sal_uInt16 nPos = pCombo->GetEntryPos(pCombo->GetText());
781 
782 	if (nPos != COMBOBOX_ENTRY_NOTFOUND)
783 	{
784 		aNameCB.SetText(aNameCB.GetEntry(nPos));
785 		aUrlCB.SetText(aUrlCB.GetEntry(nPos));
786 
787 		EnableLink();
788 		EnableItem(BTN_INSERT_BOOKMARK, sal_True);
789 		EnableItem(BTN_INET_SEARCH, sal_True);
790 	}
791 	return sal_True;
792 }
793 
794 /*--------------------------------------------------------------------
795 	Beschreibung:
796  --------------------------------------------------------------------*/
797 
798 IMPL_LINK( SvxHyperlinkDlg, ComboModifyHdl, ComboBox *, pCombo )
799 {
800 	sal_Bool bEnable = sal_True;
801 
802 	if (!pCombo->GetText().Len())
803 		bEnable = sal_False;
804 
805 	if (pCombo == &aNameCB)
806 	{
807 		if (IsItemEnabled(BTN_INET_SEARCH) != bEnable)
808 			EnableItem(BTN_INET_SEARCH, bEnable);
809 	}
810 
811 	EnableLink();
812 
813 	if (aUrlCB.GetText().Len())
814 		bEnable = sal_True;
815 	else
816 		bEnable = sal_False;
817 
818 	if (IsItemEnabled(BTN_INSERT_BOOKMARK) != bEnable)
819 		EnableItem(BTN_INSERT_BOOKMARK, bEnable);
820 
821 	return sal_True;
822 }
823 
824 // --------------------------------------------------------------------
825 
826 void SvxHyperlinkDlg::DataChanged( const DataChangedEvent& rDCEvt )
827 {
828 	ToolBox::DataChanged( rDCEvt );
829 
830 	if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) && (rDCEvt.GetFlags() & SETTINGS_STYLE))
831 		SetImages();
832 }
833 
834 // --------------------------------------------------------------------
835 
836 void SvxHyperlinkDlg::SetImages()
837 {
838 	bool bHighContrast = GetSettings().GetStyleSettings().GetHighContrastMode();
839 
840 	SetItemImage( BTN_LINK, mpManager->GetImage( BTN_LINK, bHighContrast ) );
841 	SetItemImage( BTN_INSERT_BOOKMARK, mpManager->GetImage( BTN_INSERT_BOOKMARK, bHighContrast ) );
842 	SetItemImage( BTN_INET_SEARCH, mpManager->GetImage( BTN_INET_SEARCH, bHighContrast ) );
843 	SetItemImage( BTN_TARGET, mpManager->GetImage( BTN_TARGET, bHighContrast ) );
844 	SetItemImage( BTN_OPENDIALOG, mpManager->GetImage( BTN_OPENDIALOG, bHighContrast ) );
845 }
846 
847 /*--------------------------------------------------------------------
848 	Beschreibung: Comboboxen
849  --------------------------------------------------------------------*/
850 
851 HyperCombo::HyperCombo( SvxHyperlinkDlg* pDialog, const ResId& rResId ) :
852 		ComboBox( (Window *)pDialog, rResId )
853 {
854 	pDlg = pDialog;
855 
856 	nMaxWidth = GetSizePixel().Width();
857 	if (this == &pDlg->aUrlCB)
858 		nMinWidth = GetTextWidth(String::CreateFromAscii("http://www.stardiv.dewww"));
859 	else
860 		nMinWidth = GetTextWidth(String::CreateFromAscii("StarDivision GmbHwww"));
861 }
862 
863 /*--------------------------------------------------------------------
864 	Beschreibung: Comboboxen KeyInput
865  --------------------------------------------------------------------*/
866 
867 long HyperCombo::Notify( NotifyEvent& rNEvt )
868 {
869 	long nHandled = 0;
870 	static sal_Bool bLocked = sal_False;
871 
872 	if (bLocked)	// Keine weiteren RETURNs annehmen (nicht Reentrant!)
873 		return nHandled;
874 
875 	bLocked = sal_True;
876 
877 	if ( rNEvt.GetType() == EVENT_KEYINPUT )
878 	{
879 		const KeyEvent* pKEvt = rNEvt.GetKeyEvent();
880 		const KeyCode aKeyCode = pKEvt->GetKeyCode();
881 
882 		if (aKeyCode.GetCode() == KEY_RETURN)
883 		{
884 			pDlg->SendToApp(HLINK_DEFAULT);
885 			nHandled = 1;
886 		}
887 	}
888 	if (this == &pDlg->aNameCB)
889 		pDlg->sOldName = GetText();
890 
891 	if (!nHandled)
892 		nHandled = ComboBox::Notify( rNEvt );
893 
894 	bLocked = sal_False;
895 
896 	return nHandled;
897 }
898 
899 /*--------------------------------------------------------------------
900 	Beschreibung: Drag&Drop vor dem Combo-Edit abfangen und weiterleiten
901  --------------------------------------------------------------------*/
902 
903 long HyperCombo::PreNotify( NotifyEvent& rNEvt )
904 {
905 	long nHandled = 0;
906 
907 	nHandled = ComboBox::PreNotify( rNEvt );
908 
909 	return nHandled;
910 }
911 
912 /*--------------------------------------------------------------------
913 	Beschreibung:
914  --------------------------------------------------------------------*/
915 
916 long HyperCombo::CalcResizeWidth( long nW )
917 {
918 	long nNewWidth = Max(nMaxWidth - nW * GetRatio() / 100L, nMinWidth);
919 
920 	if (nNewWidth > nMaxWidth)
921 		nNewWidth = nMaxWidth;
922 
923 	if (nNewWidth != GetSizePixel().Width())
924 		return nNewWidth;
925 	else
926 		return 0;	// Kein Resize notwendig
927 }
928 
929 /*--------------------------------------------------------------------
930 	Beschreibung:
931  --------------------------------------------------------------------*/
932 
933 void HyperCombo::DoResize( long nNewWidth )
934 {
935 	SetSizePixel(Size(nNewWidth, GetSizePixel().Height()));
936 }
937 
938 /*--------------------------------------------------------------------
939 	Beschreibung: FixedText
940  --------------------------------------------------------------------*/
941 
942 HyperFixedText::HyperFixedText( SvxHyperlinkDlg* pDialog, const ResId& rResId ) :
943 		FixedInfo( (Window *)pDialog, rResId )
944 {
945 	pDlg = pDialog;
946 }
947 
948 /*--------------------------------------------------------------------
949 	Beschreibung: Webseite der Search-Engine mit Suchergebnissen anzeigen
950  --------------------------------------------------------------------*/
951 void SvxHyperlinkDlg::OpenDoc( const String& rURL, SfxViewFrame* pViewFrame )
952 {
953 	SfxStringItem aName( SID_FILE_NAME, rURL );
954 	SfxStringItem aReferer( SID_REFERER, String::CreateFromAscii("private:user") );
955     SfxBoolItem aNewView( SID_OPEN_NEW_VIEW, sal_True );
956 	SfxBoolItem aSilent( SID_SILENT, sal_True );
957 	SfxBoolItem aReadOnly( SID_DOC_READONLY, sal_True );
958     SfxBoolItem aExternal( SID_BROWSE, sal_True );
959     SfxDispatcher* pDisp = SfxViewFrame::Current() ? SfxViewFrame::Current()->GetDispatcher() : NULL;
960 
961 	if ( pViewFrame )
962 	{
963 		SfxFrameItem aView( SID_DOCFRAME, pViewFrame ? &pViewFrame->GetFrame() : NULL );
964 		if ( pDisp )
965 			pDisp->Execute( SID_OPENDOC, SFX_CALLMODE_ASYNCHRON | SFX_CALLMODE_RECORD,
966                             &aName, &aView, &aNewView, &aSilent, &aReadOnly, &aReferer, &aExternal, 0L );
967 	}
968 	else if ( pDisp )
969 		pDisp->Execute( SID_OPENDOC, SFX_CALLMODE_ASYNCHRON | SFX_CALLMODE_RECORD,
970 						&aName, &aNewView, &aSilent, &aReadOnly, &aReferer, 0L );
971 }
972 // class SvxHyperlinkDialogWrapper ------------------------------------------
973 
974 SFX_IMPL_CHILDWINDOW(SvxHyperlinkDlgWrapper, SID_HYPERLINK_INSERT)
975 
976 /*--------------------------------------------------------------------
977 	Beschreibung: Wrapper fuer Hyperlinkleiste
978  --------------------------------------------------------------------*/
979 
980 SvxHyperlinkDlgWrapper::SvxHyperlinkDlgWrapper( Window* _pParent, sal_uInt16 nId,
981                                                 SfxBindings* _pBindings, SfxChildWinInfo* /*pInfo*/ ) :
982 
983     SfxChildWindow( _pParent, nId )
984 
985 {
986     pWindow = new SvxHyperlinkDlg( _pBindings, _pParent );
987 	eChildAlignment = SFX_ALIGN_TOP;
988 }
989 
990 /*--------------------------------------------------------------------
991 	Beschreibung:
992  --------------------------------------------------------------------*/
993 
994 SfxChildWinInfo SvxHyperlinkDlgWrapper::GetInfo() const
995 {
996 	SfxChildWinInfo aInfo = SfxChildWindow::GetInfo();
997 	return aInfo;
998 }
999 
1000