update dev300-m58
[ooovba.git] / svx / source / dialog / hyprlink.cxx
blobee7c272fccca5ecb811b448f3a5959f487e66270
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: hyprlink.cxx,v $
10 * $Revision: 1.15 $
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;
64 public:
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 ),
113 bNoDoc ( TRUE ),
114 bSend ( FALSE ),
115 bHasOldName ( FALSE ),
116 bHtmlMode ( FALSE )
119 FreeResource();
121 mpManager = SfxImageManager::GetImageManager( 0 );
122 mpManager->RegisterToolBox( this );
124 SetImages();
126 // save initial size
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 );
140 sItemText.Erase();
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!
156 Show();
157 Resize();
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
185 // drop down lists.
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,
192 rtl::OUString(
193 RTL_CONSTASCII_USTRINGPARAM(
194 "InternetSearch" ) ) ) )
195 HideItem( BTN_INET_SEARCH );
198 /*--------------------------------------------------------------------
199 Beschreibung:
200 --------------------------------------------------------------------*/
202 SvxHyperlinkDlg::~SvxHyperlinkDlg()
204 SfxImageManager::GetImageManager( 0 )->ReleaseToolBox(this);
206 if (pTargetMenu != NULL)
207 delete pTargetMenu;
210 /*--------------------------------------------------------------------
211 Beschreibung: Leiste so resizen, dass die Comboboxen automatisch mit
212 verkleinert werden
213 --------------------------------------------------------------------*/
215 void SvxHyperlinkDlg::Resize()
217 long nWidth = GetSizePixel().Width();
219 ToolBox::Resize();
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
237 SetUpdateMode(TRUE);
242 /*--------------------------------------------------------------------
243 Beschreibung:
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 );
270 BOOL bItem = FALSE;
271 if ( pState && eState == SFX_ITEM_AVAILABLE )
272 bItem = ((SfxBoolItem*)pState)->GetValue();
273 SetItemState ( BTN_OPENDIALOG, bItem ? STATE_CHECK : STATE_NOCHECK );
275 else
277 SetItemState ( BTN_OPENDIALOG, STATE_NOCHECK );
278 EnableItem( BTN_OPENDIALOG, FALSE );
282 if (nSID == SID_HYPERLINK_SETLINK)
284 if (eState == SFX_ITEM_DISABLED)
285 bNoDoc = TRUE;
286 else
287 bNoDoc = FALSE;
288 EnableItem(BTN_TARGET, !bNoDoc);
289 EnableLink();
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;
302 if (!bHasOldName &&
303 (nNamePos == nNotFound || nUrlPos == nNotFound))
305 sOldName = aNameCB.GetText();
306 bHasOldName = TRUE;
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;
327 else
328 return;
330 ComboModifyHdl(&aUrlCB);
334 /*--------------------------------------------------------------------
335 Beschreibung:
336 --------------------------------------------------------------------*/
338 IMPL_LINK( SvxHyperlinkDlg, TBClickHdl, ToolBox *, pBox )
340 switch (pBox->GetCurItemId())
342 case BTN_LINK:
344 if (!bSend) // Link ins Dokument einfuegen
345 SendToApp(HLINK_DEFAULT);
347 break;
349 case BTN_OPENDIALOG:
351 GetBindings().GetDispatcher()->Execute( SID_HYPERLINK_DIALOG );
353 break;
356 return TRUE;
359 /*--------------------------------------------------------------------
360 Beschreibung:
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();
372 if ( !sName.Len() )
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 );
384 break;
387 return TRUE;
390 IMPL_LINK( SvxHyperlinkDlg, DropdownClick, ToolBox *, pBox )
392 switch (pBox->GetCurItemId())
394 case BTN_LINK:
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 );
401 break;
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();
414 String sFound;
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);
428 else
430 if (i)
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);
438 EndSelection();
439 delete pMenu;
441 break;
443 case BTN_TARGET:
445 // Target Frame einstellen
446 TargetMenu(GetSelTarget(), TRUE);
447 EndSelection();
449 break;
452 return TRUE;
455 /*--------------------------------------------------------------------
456 Beschreibung:
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);
468 return;
473 SfxViewFrame* pVwFrm = SfxViewFrame::Current();
475 if (pVwFrm) // Alle moeglichen Target Frames zusammensammeln und anzeigen
477 TargetList aList;
478 pVwFrm->GetTopFrame()->GetTargetList(aList);
480 USHORT nCount = (USHORT)aList.Count();
481 if( nCount )
483 BOOL bChecked = FALSE;
485 if (pTargetMenu != NULL)
486 delete pTargetMenu;
488 pTargetMenu = new PopupMenu;
489 pTargetMenu->SetMenuFlags( pTargetMenu->GetMenuFlags() |
490 MENU_FLAG_NOAUTOMNEMONICS );
491 USHORT i;
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);
500 bChecked = TRUE;
503 for ( i = nCount; i; i-- )
504 delete aList.GetObject( i - 1 );
506 if (!bChecked)
507 pTargetMenu->CheckItem(1);
509 if (bExecute)
511 USHORT nEntry = pTargetMenu->Execute(
512 this, GetItemRect( BTN_TARGET ), FLOATWIN_POPUPMODE_DOWN );
513 if ( nEntry )
514 pTargetMenu->CheckItem( nEntry );
520 /*--------------------------------------------------------------------
521 Beschreibung:
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);
530 break;
531 case MN_BUTTON: // URL als Button ins Dok einfuegen
532 SendToApp(HLINK_BUTTON);
533 break;
536 return TRUE;
539 /*--------------------------------------------------------------------
540 Beschreibung:
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;
561 cToken = ' ';
563 else if (sText.Search('+') != STRING_NOTFOUND)
565 sPrefix = rData.sAndPrefix;
566 sSuffix = rData.sAndSuffix;
567 sSeparator = rData.sAndSeparator;
568 nCaseMatch = rData.nAndCaseMatch;
569 cToken = '+';
571 else if (sText.Search(',') != STRING_NOTFOUND)
573 sPrefix = rData.sOrPrefix;
574 sSuffix = rData.sOrSuffix;
575 sSeparator = rData.sOrSeparator;
576 nCaseMatch = rData.nOrCaseMatch;
577 cToken = ',';
579 else
581 sPrefix = rData.sExactPrefix;
582 sSuffix = rData.sExactSuffix;
583 nCaseMatch = rData.nExactCaseMatch;
584 cToken = 0;
587 String sURL = sPrefix;
588 xub_StrLen nTok;
590 if(1 == nCaseMatch)
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);
600 if(i < nTok -1)
601 sURL += (String)sSeparator;
603 sURL += (String)sSuffix;
605 else
607 sURL += sText;
608 sURL += (String)sSuffix;
610 sURL.EraseAllChars(); // remove all spaces
611 SfxViewFrame* pViewFrame = SfxViewFrame::Current();
612 if ( pViewFrame )
613 pViewFrame = pViewFrame->GetTopViewFrame();
614 OpenDoc( sURL, pViewFrame );
616 return TRUE;
619 /*--------------------------------------------------------------------
620 Beschreibung:
621 --------------------------------------------------------------------*/
623 IMPL_LINK( SvxHyperlinkDlg, BookmarkFoundHdl, String *, pUrl )
625 if (pUrl && pUrl->Len())
627 aUrlCB.SetText(*pUrl);
628 ComboModifyHdl(&aUrlCB);
631 return TRUE;
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;
651 bSend = TRUE;
652 String sURL( aUrlCB.GetText() );
654 if ( !sURL.Len() )
655 return;
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 )
663 bIsFile = TRUE;
665 if ( bIsFile )
667 EnterWait();
668 SfxMedium aMedium( sURL, STREAM_STD_READ, TRUE );
669 if ( aMedium.Exists( FALSE ) == FALSE )
671 LeaveWait();
672 QueryBox aBox( this, SVX_RES( RID_SVXQB_DONTEXIST ) );
673 if ( aBox.Execute() == RET_NO )
674 return;
676 else
677 LeaveWait();
680 SvxHyperlinkItem aItem( SID_HYPERLINK_SETLINK );
682 if (aNameCB.GetText().Len())
683 aItem.SetName( aNameCB.GetText() );
684 else
685 aItem.SetName( sURL );
687 sOldName = aNameCB.GetText();
689 aItem.SetURL(sURL);
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()
708 String sTarget;
710 if (pTargetMenu != NULL)
712 for (USHORT i = 1; i <= pTargetMenu->GetItemCount(); i++)
714 if (pTargetMenu->IsItemChecked(i))
716 sTarget = pTargetMenu->GetItemText(i);
717 break;
722 return sTarget;
725 /*--------------------------------------------------------------------
726 Beschreibung: URL in History der Leiste aufnehmen
727 --------------------------------------------------------------------*/
729 void SvxHyperlinkDlg::AddToHistory(const String& rName, const String& rURL)
731 String sName(rName);
733 if (bHasOldName && sOldName.Len())
735 sName = sOldName;
736 bHasOldName = FALSE;
739 if (!sName.Len())
740 sName = rURL;
742 if (rURL.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)
749 nPos = nNamePos;
750 else
751 nPos = nUrlPos;
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));
780 EnableLink();
781 EnableItem(BTN_INSERT_BOOKMARK, TRUE);
782 EnableItem(BTN_INET_SEARCH, TRUE);
784 return TRUE;
787 /*--------------------------------------------------------------------
788 Beschreibung:
789 --------------------------------------------------------------------*/
791 IMPL_LINK( SvxHyperlinkDlg, ComboModifyHdl, ComboBox *, pCombo )
793 BOOL bEnable = TRUE;
795 if (!pCombo->GetText().Len())
796 bEnable = FALSE;
798 if (pCombo == &aNameCB)
800 if (IsItemEnabled(BTN_INET_SEARCH) != bEnable)
801 EnableItem(BTN_INET_SEARCH, bEnable);
804 EnableLink();
806 if (aUrlCB.GetText().Len())
807 bEnable = TRUE;
808 else
809 bEnable = FALSE;
811 if (IsItemEnabled(BTN_INSERT_BOOKMARK) != bEnable)
812 EnableItem(BTN_INSERT_BOOKMARK, bEnable);
814 return TRUE;
817 // --------------------------------------------------------------------
819 void SvxHyperlinkDlg::DataChanged( const DataChangedEvent& rDCEvt )
821 ToolBox::DataChanged( rDCEvt );
823 if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) && (rDCEvt.GetFlags() & SETTINGS_STYLE))
824 SetImages();
827 // --------------------------------------------------------------------
829 void SvxHyperlinkDlg::SetImages()
831 bool bHighContrast = GetSettings().GetStyleSettings().GetHighContrastMode() != 0;
833 if( bHighContrast )
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 )
850 pDlg = pDialog;
852 nMaxWidth = GetSizePixel().Width();
853 if (this == &pDlg->aUrlCB)
854 nMinWidth = GetTextWidth(String::CreateFromAscii("http://www.stardiv.dewww"));
855 else
856 nMinWidth = GetTextWidth(String::CreateFromAscii("StarDivision GmbHwww"));
859 /*--------------------------------------------------------------------
860 Beschreibung: Comboboxen KeyInput
861 --------------------------------------------------------------------*/
863 long HyperCombo::Notify( NotifyEvent& rNEvt )
865 long nHandled = 0;
866 static BOOL bLocked = FALSE;
868 if (bLocked) // Keine weiteren RETURNs annehmen (nicht Reentrant!)
869 return nHandled;
871 bLocked = TRUE;
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);
881 nHandled = 1;
884 if (this == &pDlg->aNameCB)
885 pDlg->sOldName = GetText();
887 if (!nHandled)
888 nHandled = ComboBox::Notify( rNEvt );
890 bLocked = FALSE;
892 return nHandled;
895 /*--------------------------------------------------------------------
896 Beschreibung: Drag&Drop vor dem Combo-Edit abfangen und weiterleiten
897 --------------------------------------------------------------------*/
899 long HyperCombo::PreNotify( NotifyEvent& rNEvt )
901 long nHandled = 0;
903 nHandled = ComboBox::PreNotify( rNEvt );
905 return nHandled;
908 /*--------------------------------------------------------------------
909 Beschreibung:
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())
920 return nNewWidth;
921 else
922 return 0; // Kein Resize notwendig
925 /*--------------------------------------------------------------------
926 Beschreibung:
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 )
941 pDlg = pDialog;
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;
957 if ( pViewFrame )
959 SfxFrameItem aView( SID_DOCFRAME, pViewFrame ? pViewFrame->GetFrame() : NULL );
960 if ( pDisp )
961 pDisp->Execute( SID_OPENDOC, SFX_CALLMODE_ASYNCHRON | SFX_CALLMODE_RECORD,
962 &aName, &aView, &aNewView, &aSilent, &aReadOnly, &aReferer, &aExternal, 0L );
964 else if ( pDisp )
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 /*--------------------------------------------------------------------
987 Beschreibung:
988 --------------------------------------------------------------------*/
990 SfxChildWinInfo SvxHyperlinkDlgWrapper::GetInfo() const
992 SfxChildWinInfo aInfo = SfxChildWindow::GetInfo();
993 return aInfo;