xref: /aoo41x/main/cui/source/dialogs/hltpbase.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_cui.hxx"
30 
31 #include <sfx2/frame.hxx>
32 #include <sfx2/viewfrm.hxx>
33 #include <sot/formats.hxx>
34 #include <sfx2/sfxsids.hrc>
35 #include <svl/macitem.hxx>
36 #include <ucbhelper/content.hxx>
37 #include <unotools/localfilehelper.hxx>
38 #include "hyperdlg.hrc"
39 #include "cuihyperdlg.hxx"  //CHINA001
40 #include "hltpbase.hxx"
41 #include "macroass.hxx"
42 #include <svx/svxdlg.hxx> //CHINA001
43 #include <cuires.hrc> //CHINA001
44 
45 using namespace ::ucbhelper;
46 
47 //########################################################################
48 //#                                                                      #
49 //# ComboBox-Control, wich is filled with all current framenames         #
50 //#                                                                      #
51 //########################################################################
52 
53 /*************************************************************************
54 |*
55 |* Contructor / Destructor
56 |*
57 |************************************************************************/
58 
59 SvxFramesComboBox::SvxFramesComboBox ( Window* pParent, const ResId& rResId,
60                                         SfxDispatcher* pDispatch )
61 :	ComboBox (pParent, rResId)
62 {
63     TargetList* pList = new TargetList;
64     SfxViewFrame* pViewFrame = pDispatch ? pDispatch->GetFrame() : 0;
65     SfxFrame* pFrame = pViewFrame ? &pViewFrame->GetTopFrame() : 0;
66     if ( pFrame )
67     {
68         pFrame->GetTargetList(*pList);
69         sal_uInt16 nCount = (sal_uInt16)pList->Count();
70         if( nCount )
71         {
72             sal_uInt16 i;
73             for ( i = 0; i < nCount; i++ )
74             {
75                 InsertEntry(*pList->GetObject(i));
76             }
77             for ( i = nCount; i; i-- )
78             {
79                 delete pList->GetObject( i - 1 );
80             }
81         }
82         delete pList;
83     }
84 }
85 
86 SvxFramesComboBox::~SvxFramesComboBox ()
87 {
88 }
89 //########################################################################
90 //#																		 #
91 //# ComboBox-Control for URL's with History and Autocompletion			 #
92 //#																		 #
93 //########################################################################
94 
95 /*************************************************************************
96 |*
97 |* Contructor / Destructor
98 |*
99 |************************************************************************/
100 
101 SvxHyperURLBox::SvxHyperURLBox( Window* pParent, INetProtocol eSmart, sal_Bool bAddresses )
102 : SvtURLBox			( pParent, eSmart ),
103   DropTargetHelper  ( this ),
104   mbAccessAddress	(bAddresses)
105 {
106 }
107 
108 sal_Int8 SvxHyperURLBox::AcceptDrop( const AcceptDropEvent& /* rEvt */ )
109 {
110     return( IsDropFormatSupported( FORMAT_STRING ) ? DND_ACTION_COPY : DND_ACTION_NONE );
111 }
112 
113 sal_Int8 SvxHyperURLBox::ExecuteDrop( const ExecuteDropEvent& rEvt )
114 {
115     TransferableDataHelper	aDataHelper( rEvt.maDropEvent.Transferable );
116     String                  aString;
117     sal_Int8                nRet = DND_ACTION_NONE;
118 
119     if( aDataHelper.GetString( FORMAT_STRING, aString ) )
120     {
121         SetText( aString );
122 		nRet = DND_ACTION_COPY;
123     }
124 
125     return nRet;
126 }
127 
128 /*
129 Diese Methode parsed eine EMailadresse aus einem D&D-DataObjekt aus der Adre�datenbank heraus
130 
131 #ifndef _OFF_OFADBMGR_HXX
132 #include <offmgr/ofadbmgr.hxx>
133 #endif
134 #ifndef _SFX_APP_HXX
135 #include <offmgr/app.hxx>
136 #endif
137 #ifndef _SDB_SDBCURS_HXX
138 #include <sdb/sdbcurs.hxx>
139 #endif
140 
141 #define DB_DD_DELIM			((char)11)
142 
143 String SvxHyperURLBox::GetAllEmailNamesFromDragItem( sal_uInt16 nItem )
144 {
145 #if !defined( ICC ) && !defined( SOLARIS )
146 	String aAddress;
147 
148 	if (  DragServer::HasFormat( nItem, SOT_FORMATSTR_ID_SBA_DATAEXCHANGE ) )
149 	{
150 		sal_uLong nLen = DragServer::GetDataLen( nItem, SOT_FORMATSTR_ID_SBA_DATAEXCHANGE ) - 1;
151 		sal_uInt16 i = 0;
152 		String aTxt;
153 		char *pTxt = aTxt.AllocStrBuf( (sal_uInt16)nLen );
154 		DragServer::PasteData( nItem, pTxt, nLen, SOT_FORMATSTR_ID_SBA_DATAEXCHANGE );
155 		String aDBName = aTxt.GetToken( i++, DB_DD_DELIM );
156 		String aTableName = aTxt.GetToken( i++, DB_DD_DELIM );
157 		i++;	// Format"anderung
158 		String aStatement = aTxt.GetToken( i++, DB_DD_DELIM );
159 		if ( !aStatement )
160 		{
161 			aDBName += DB_DELIM;
162 			aDBName += aTableName;
163 		}
164 		else
165 		{
166 			// use here another delimiter, because the OfaDBMgr uses two
167 			// delimiters ( (char)11 and ; )
168 			aDBName += ';';
169 			aDBName += aStatement;
170 		}
171 		SbaSelectionListRef pSelectionList;
172 		pSelectionList.Clear();
173 		pSelectionList = new SbaSelectionList;
174 		sal_uInt16 nTokCnt = aTxt.GetTokenCount( DB_DD_DELIM );
175 
176 		for ( ; i < nTokCnt; ++i )
177 			pSelectionList->Insert(
178 				(void*)(sal_uInt16)aTxt.GetToken( i, DB_DD_DELIM ), LIST_APPEND );
179 
180         OfaDBMgr* pDBMgr = SFX_APP()->GetOfaDBMgr();
181 		sal_Bool bBasic = DBMGR_STD;
182 
183 		if ( !pDBMgr->OpenDB( bBasic, aDBName ) )
184 			return aAddress;
185 
186 		OfaDBParam& rParam = pDBMgr->GetDBData( bBasic );
187 		pDBMgr->ChangeStatement( bBasic, aStatement );
188 		rParam.pSelectionList->Clear();
189 
190 		if ( pSelectionList.Is() &&
191 				(long)pSelectionList->GetObject(0) != -1L )
192 			*rParam.pSelectionList = *pSelectionList;
193 
194 		if ( !pDBMgr->ToFirstSelectedRecord( bBasic ) )
195 		{
196 			pDBMgr->CloseAll();
197 			return aAddress;
198 		}
199 
200 		if ( pDBMgr->IsSuccessful( bBasic ) )
201 		{
202 			//	Spaltenk"opfe
203 			SbaDBDataDefRef aDBDef = pDBMgr->OpenColumnNames( bBasic );
204 
205 			if ( aDBDef.Is() )
206 			{
207 				SbaColumn* pCol = aDBDef->GetColumn("EMAIL");
208 				sal_uLong nPos = 0;
209 
210 				if ( pCol )
211 					nPos = aDBDef->GetOriginalColumns().GetPos( pCol ) + 1;
212 				for ( i = 0 ; nPos && i < pSelectionList->Count(); ++i )
213 				{
214 					sal_uLong nIndex = (sal_uLong)pSelectionList->GetObject(i);
215 
216 					// N"achsten zu lesenden Datensatz ansteuern
217 
218 					sal_Bool bEnd = rParam.GetCursor()->IsOffRange();
219 
220 					if ( !bEnd )
221 					{
222 						const ODbRowRef aRow =
223 							pDBMgr->GetSelectedRecord( bBasic, i );
224 
225 						if ( aRow.Is() )
226 						{
227 							aAddress += pDBMgr->
228 								ImportDBField( (sal_uInt16)nPos, &aDBDef, aRow.getBodyPtr() );
229 							aAddress += ',';
230 						}
231 						else
232 						{
233 							aAddress.Erase();
234 							break;
235 						}
236 					}
237 					else
238 						break;
239 				}
240 			}
241 		}
242 		pDBMgr->CloseAll();
243 	}
244 	aAddress.EraseTrailingChars( ',' );
245 	return aAddress;
246 #else
247 	return String();
248 #endif
249 }
250 */
251 
252 void SvxHyperURLBox::Select()
253 {
254 	SvtURLBox::Select();
255 }
256 void SvxHyperURLBox::Modify()
257 {
258 	SvtURLBox::Modify();
259 }
260 long SvxHyperURLBox::Notify( NotifyEvent& rNEvt )
261 {
262 	return SvtURLBox::Notify( rNEvt );
263 }
264 long SvxHyperURLBox::PreNotify( NotifyEvent& rNEvt )
265 {
266 	return SvtURLBox::PreNotify( rNEvt );
267 }
268 
269 //########################################################################
270 //#                                                                      #
271 //# Hyperlink-Dialog: Tabpages-Baseclass                                 #
272 //#                                                                      #
273 //########################################################################
274 
275 /*************************************************************************
276 |*
277 |* Con/Destructor, Initialize
278 |*
279 \************************************************************************/
280 
281 SvxHyperlinkTabPageBase::SvxHyperlinkTabPageBase ( Window *pParent,
282 												   const ResId &rResId,
283 												   const SfxItemSet& rItemSet )
284 :	IconChoicePage			( pParent, rResId, rItemSet ),
285 	mpGrpMore				( NULL ),
286 	mpFtFrame				( NULL ),
287 	mpCbbFrame				( NULL ),
288 	mpFtForm				( NULL ),
289 	mpLbForm				( NULL ),
290 	mpFtIndication			( NULL ),
291 	mpEdIndication			( NULL ),
292 	mpFtText				( NULL ),
293 	mpEdText				( NULL ),
294 	mpBtScript				( NULL ),
295     mbIsCloseDisabled       ( sal_False ),
296 	mpDialog				( pParent ),
297     mbStdControlsInit       ( sal_False ),
298     aEmptyStr()
299 {
300 	// create bookmark-window
301 	mpMarkWnd = new SvxHlinkDlgMarkWnd ( this );
302 }
303 
304 SvxHyperlinkTabPageBase::~SvxHyperlinkTabPageBase ()
305 {
306 	maTimer.Stop();
307 
308 	if ( mbStdControlsInit )
309 	{
310 		delete mpGrpMore;
311 		delete mpFtFrame;
312 		delete mpCbbFrame;
313 		delete mpFtForm;
314 		delete mpLbForm;
315 		delete mpFtIndication;
316 		delete mpEdIndication;
317 		delete mpFtText;
318 		delete mpEdText	;
319 		delete mpBtScript;
320 	}
321 
322 	delete mpMarkWnd;
323 }
324 
325 void SvxHyperlinkTabPageBase::ActivatePage()
326 {
327 	TabPage::ActivatePage();
328 }
329 
330 void SvxHyperlinkTabPageBase::DeactivatePage()
331 {
332     TabPage::DeactivatePage();
333 }
334 
335 sal_Bool SvxHyperlinkTabPageBase::QueryClose()
336 {
337     return !mbIsCloseDisabled;
338 }
339 
340 void SvxHyperlinkTabPageBase::InitStdControls ()
341 {
342 	if ( !mbStdControlsInit )
343 	{
344 		mpGrpMore	  = new FixedLine			( this, ResId (GRP_MORE, *m_pResMgr) );
345 		mpFtFrame	  = new FixedText			( this, ResId (FT_FRAME, *m_pResMgr) );
346         mpCbbFrame    = new SvxFramesComboBox   ( this, ResId (CB_FRAME, *m_pResMgr), GetDispatcher() );
347 		mpFtForm	  = new FixedText			( this, ResId (FT_FORM, *m_pResMgr) );
348 		mpLbForm	  = new ListBox				( this, ResId (LB_FORM, *m_pResMgr) );
349 		mpFtIndication= new FixedText			( this, ResId (FT_INDICATION, *m_pResMgr) );
350 		mpEdIndication= new Edit				( this, ResId (ED_INDICATION, *m_pResMgr) );
351 		mpFtText	  = new FixedText			( this, ResId (FT_TEXT, *m_pResMgr) );
352 		mpEdText	  = new Edit				( this, ResId (ED_TEXT, *m_pResMgr) );
353 		mpBtScript	  = new ImageButton			( this, ResId (BTN_SCRIPT, *m_pResMgr) );
354 
355 		mpBtScript->SetClickHdl ( LINK ( this, SvxHyperlinkTabPageBase, ClickScriptHdl_Impl ) );
356 
357 		mpBtScript->SetModeImage( Image( ResId( IMG_SCRIPT_HC, *m_pResMgr ) ), BMP_COLOR_HIGHCONTRAST );
358         mpBtScript->EnableTextDisplay (sal_False);
359 
360 		mpBtScript->SetAccessibleRelationMemberOf( mpGrpMore );
361 		mpBtScript->SetAccessibleRelationLabeledBy( mpFtForm );
362 	}
363 
364 	mbStdControlsInit = sal_True;
365 }
366 
367 /*************************************************************************
368 |*
369 |* Move Extra-Window
370 |*
371 \************************************************************************/
372 
373 sal_Bool SvxHyperlinkTabPageBase::MoveToExtraWnd( Point aNewPos, sal_Bool bDisConnectDlg )
374 {
375 	sal_Bool bReturn = 	mpMarkWnd->MoveTo ( aNewPos );
376 
377 	if( bDisConnectDlg )
378 		mpMarkWnd->ConnectToDialog( sal_False );
379 
380 	return ( !bReturn && IsMarkWndVisible() );
381 }
382 
383 /*************************************************************************
384 |*
385 |* Show Extra-Window
386 |*
387 \************************************************************************/
388 
389 void SvxHyperlinkTabPageBase::ShowMarkWnd ()
390 {
391 	( ( Window* ) mpMarkWnd )->Show();
392 
393 	// Size of dialog-window in screen pixels
394     Rectangle aDlgRect( mpDialog->GetWindowExtentsRelative( NULL ) );
395 	Point aDlgPos ( aDlgRect.TopLeft() );
396 	Size aDlgSize (	mpDialog->GetSizePixel () );
397 
398 	// Absolute size of the screen
399     Rectangle aScreen( mpDialog->GetDesktopRectPixel() );
400 
401 	// Size of Extrawindow
402 	Size aExtraWndSize( mpMarkWnd->GetSizePixel () );
403 
404     // mpMarkWnd is a child of mpDialog, so coordinates for positioning must be relative to mpDialog
405 	if( aDlgPos.X()+(1.05*aDlgSize.Width())+aExtraWndSize.Width() > aScreen.Right() )
406 	{
407 		if( aDlgPos.X() - ( 0.05*aDlgSize.Width() ) - aExtraWndSize.Width() < 0 )
408 		{
409 			// Pos Extrawindow anywhere
410 			MoveToExtraWnd( Point(10,10) );  // very unlikely
411 			mpMarkWnd->ConnectToDialog( sal_False );
412 		}
413 		else
414 		{
415 			// Pos Extrawindow on the left side of Dialog
416 			MoveToExtraWnd( Point(0,0) - Point( long(0.05*aDlgSize.Width()), 0 ) - Point( aExtraWndSize.Width(), 0 ) );
417 		}
418 	}
419 	else
420 	{
421 		// Pos Extrawindow on the right side of Dialog
422 		MoveToExtraWnd ( Point( long(1.05*aDlgSize.getWidth()), 0 ) );
423 	}
424 
425 	// Set size of Extra-Window
426 	mpMarkWnd->SetSizePixel( Size( aExtraWndSize.Width(), aDlgSize.Height() ) );
427 }
428 
429 /*************************************************************************
430 |*
431 |* Fill Dialogfields
432 |*
433 \************************************************************************/
434 
435 void SvxHyperlinkTabPageBase::FillStandardDlgFields ( SvxHyperlinkItem* pHyperlinkItem )
436 {
437 	// Frame
438 	sal_uInt16 nPos = mpCbbFrame->GetEntryPos ( pHyperlinkItem->GetTargetFrame() );
439 	if ( nPos != LISTBOX_ENTRY_NOTFOUND)
440 		mpCbbFrame->SetText ( pHyperlinkItem->GetTargetFrame() );
441 
442 	// Form
443 	String aStrFormText = CUI_RESSTR( RID_SVXSTR_HYPERDLG_FROM_TEXT );
444 	String aStrFormButton = CUI_RESSTR( RID_SVXSTR_HYPERDLG_FORM_BUTTON );
445 
446 	if( pHyperlinkItem->GetInsertMode() & HLINK_HTMLMODE )
447 	{
448 		mpLbForm->Clear();
449 		mpLbForm->InsertEntry( aStrFormText );
450 		mpLbForm->SelectEntryPos ( 0 );
451 	}
452 	else
453 	{
454 		mpLbForm->Clear();
455 		mpLbForm->InsertEntry( aStrFormText );
456 		mpLbForm->InsertEntry( aStrFormButton );
457 		mpLbForm->SelectEntryPos ( pHyperlinkItem->GetInsertMode() == HLINK_BUTTON ? 1 : 0 );
458 	}
459 
460 	// URL
461 	mpEdIndication->SetText ( pHyperlinkItem->GetName() );
462 
463 	// Name
464 	mpEdText->SetText ( pHyperlinkItem->GetIntName() );
465 
466 	// Script-button
467 	if ( !pHyperlinkItem->GetMacroEvents() )
468 		mpBtScript->Disable();
469 	else
470 		mpBtScript->Enable();
471 }
472 
473 /*************************************************************************
474 |*
475 |* Any action to do after apply-button is pressed
476 |*
477 \************************************************************************/
478 
479 void SvxHyperlinkTabPageBase::DoApply ()
480 {
481 	// default-implemtation : do nothing
482 }
483 
484 /*************************************************************************
485 |*
486 |* Ask page whether an insert is possible
487 |*
488 \************************************************************************/
489 
490 sal_Bool SvxHyperlinkTabPageBase::AskApply ()
491 {
492 	// default-implementation
493 	return sal_True;
494 }
495 
496 /*************************************************************************
497 |*
498 |* This method would be called from bookmark-window to set new mark-string
499 |*
500 \************************************************************************/
501 
502 void SvxHyperlinkTabPageBase::SetMarkStr ( String& /*aStrMark*/ )
503 {
504 	// default-implemtation : do nothing
505 }
506 
507 /*************************************************************************
508 |*
509 |* This method will be called from the dialog-class if the state off
510 |* the online-mode has changed.
511 |*
512 \************************************************************************/
513 
514 void SvxHyperlinkTabPageBase::SetOnlineMode( sal_Bool /*bEnable*/ )
515 {
516 	// default-implemtation : do nothing
517 }
518 
519 /*************************************************************************
520 |*
521 |* Set initial focus
522 |*
523 |************************************************************************/
524 
525 void SvxHyperlinkTabPageBase::SetInitFocus()
526 {
527 	GrabFocus();
528 }
529 
530 /*************************************************************************
531 |*
532 |* Ask dialog whether the curretn doc is a HTML-doc
533 |*
534 |************************************************************************/
535 
536 sal_Bool SvxHyperlinkTabPageBase::IsHTMLDoc() const
537 {
538 	return ((SvxHpLinkDlg*)mpDialog)->IsHTMLDoc();
539 }
540 
541 /*************************************************************************
542 |*
543 |* retrieve dispatcher
544 |*
545 |************************************************************************/
546 
547 SfxDispatcher* SvxHyperlinkTabPageBase::GetDispatcher() const
548 {
549 	return ((SvxHpLinkDlg*)mpDialog)->GetDispatcher();
550 }
551 
552 /*************************************************************************
553 |*
554 |* Click on imagebutton : Script
555 |*
556 |************************************************************************/
557 
558 IMPL_LINK ( SvxHyperlinkTabPageBase, ClickScriptHdl_Impl, void *, EMPTYARG )
559 {
560 	SvxHyperlinkItem *pHyperlinkItem = (SvxHyperlinkItem *)
561 		                               GetItemSet().GetItem (SID_HYPERLINK_GETLINK);
562 
563 	if ( pHyperlinkItem->GetMacroEvents() )
564 	{
565 		// get macros from itemset
566 		const SvxMacroTableDtor* pMacroTbl = pHyperlinkItem->GetMacroTbl();
567 		SvxMacroItem aItem ( GetWhich(SID_ATTR_MACROITEM) );
568 		if( pMacroTbl )
569 			aItem.SetMacroTable( *pMacroTbl );
570 
571 		// create empty itemset for macro-dlg
572 		SfxItemSet* pItemSet = new SfxItemSet(SFX_APP()->GetPool(),
573 			                                  SID_ATTR_MACROITEM,
574 											  SID_ATTR_MACROITEM );
575 		pItemSet->Put ( aItem, SID_ATTR_MACROITEM );
576 
577         // --> PB 2006-01-13 #123474#
578         /*  disable HyperLinkDlg for input while the MacroAssignDlg is working
579             because if no JAVA is installed an error box occurs and then it is possible
580             to close the HyperLinkDlg before its child (MacroAssignDlg) -> GPF
581          */
582         sal_Bool bIsInputEnabled = GetParent()->IsInputEnabled();
583         if ( bIsInputEnabled )
584             GetParent()->EnableInput( sal_False );
585         // <--
586         SfxMacroAssignDlg aDlg( this, mxDocumentFrame, *pItemSet );
587 
588 		// add events
589 		SfxMacroTabPage *pMacroPage = (SfxMacroTabPage*) aDlg.GetTabPage();
590 
591 		if ( pHyperlinkItem->GetMacroEvents() & HYPERDLG_EVENT_MOUSEOVER_OBJECT )
592 			pMacroPage->AddEvent( String( CUI_RESSTR(RID_SVXSTR_HYPDLG_MACROACT1) ),
593 			                      SFX_EVENT_MOUSEOVER_OBJECT );
594 		if ( pHyperlinkItem->GetMacroEvents() & HYPERDLG_EVENT_MOUSECLICK_OBJECT )
595 			pMacroPage->AddEvent( String( CUI_RESSTR(RID_SVXSTR_HYPDLG_MACROACT2) ),
596 			                      SFX_EVENT_MOUSECLICK_OBJECT);
597 		if ( pHyperlinkItem->GetMacroEvents() & HYPERDLG_EVENT_MOUSEOUT_OBJECT )
598 			pMacroPage->AddEvent( String( CUI_RESSTR(RID_SVXSTR_HYPDLG_MACROACT3) ),
599 			                      SFX_EVENT_MOUSEOUT_OBJECT);
600 
601         // --> PB 2006-01-13 #123474#
602         if ( bIsInputEnabled )
603             GetParent()->EnableInput( sal_True );
604         // <--
605         // execute dlg
606         DisableClose( sal_True );
607         short nRet = aDlg.Execute();
608         DisableClose( sal_False );
609         if ( RET_OK == nRet )
610 		{
611 			const SfxItemSet* pOutSet = aDlg.GetOutputItemSet();
612 			const SfxPoolItem* pItem;
613 			if( SFX_ITEM_SET == pOutSet->GetItemState( SID_ATTR_MACROITEM, sal_False, &pItem ))
614 			{
615 				pHyperlinkItem->SetMacroTable( ((SvxMacroItem*)pItem)->GetMacroTable() );
616 			}
617 		}
618 		delete pItemSet;
619 	}
620 
621 	return( 0L );
622 }
623 
624 /*************************************************************************
625 |*
626 |* Get Macro-Infos
627 |*
628 |************************************************************************/
629 
630 sal_uInt16 SvxHyperlinkTabPageBase::GetMacroEvents()
631 {
632 	SvxHyperlinkItem *pHyperlinkItem = (SvxHyperlinkItem *)
633 		                               GetItemSet().GetItem (SID_HYPERLINK_GETLINK);
634 
635 	return pHyperlinkItem->GetMacroEvents();
636 }
637 
638 SvxMacroTableDtor* SvxHyperlinkTabPageBase::GetMacroTable()
639 {
640 	SvxHyperlinkItem *pHyperlinkItem = (SvxHyperlinkItem *)
641 		                               GetItemSet().GetItem (SID_HYPERLINK_GETLINK);
642 
643 	return ( (SvxMacroTableDtor*)pHyperlinkItem->GetMacroTbl() );
644 }
645 
646 /*************************************************************************
647 |*
648 |* Does the given file exists ?
649 |*
650 |************************************************************************/
651 
652 sal_Bool SvxHyperlinkTabPageBase::FileExists( const INetURLObject& rURL )
653 {
654 	sal_Bool bRet = sal_False;
655 
656 	if( rURL.GetFull().getLength() > 0 )
657 	{
658 		try
659 		{
660 			Content		aCnt( rURL.GetMainURL( INetURLObject::NO_DECODE ), ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XCommandEnvironment >() );
661 			::rtl::OUString	aTitle;
662 
663 			aCnt.getPropertyValue( ::rtl::OUString::createFromAscii( "Title" ) ) >>= aTitle;
664 			bRet = ( aTitle.getLength() > 0 );
665 		}
666 		catch( ... )
667 		{
668 			DBG_ERROR( "FileExists: ucb error" );
669 		}
670 	}
671 
672 	return bRet;
673 }
674 
675 /*************************************************************************
676 |*
677 |* try to detect the current protocol that is used in aStrURL
678 |*
679 |************************************************************************/
680 
681 String SvxHyperlinkTabPageBase::GetSchemeFromURL( String aStrURL )
682 {
683     String aStrScheme;
684 
685 	INetURLObject aURL( aStrURL );
686 	INetProtocol aProtocol = aURL.GetProtocol();
687 
688     // #77696#
689     // our new INetUrlObject now has the ability
690     // to detect if an Url is valid or not :-(
691     if ( aProtocol == INET_PROT_NOT_VALID )
692     {
693 	    if ( aStrURL.EqualsIgnoreCaseAscii( INET_HTTP_SCHEME, 0, 7 ) )
694         {
695             aStrScheme = String::CreateFromAscii( INET_HTTP_SCHEME );
696         }
697         else if ( aStrURL.EqualsIgnoreCaseAscii( INET_HTTPS_SCHEME, 0, 8 ) )
698         {
699             aStrScheme = String::CreateFromAscii( INET_HTTPS_SCHEME );
700         }
701         else if ( aStrURL.EqualsIgnoreCaseAscii( INET_FTP_SCHEME, 0, 6 ) )
702         {
703             aStrScheme = String::CreateFromAscii( INET_FTP_SCHEME );
704         }
705         else if ( aStrURL.EqualsIgnoreCaseAscii( INET_MAILTO_SCHEME, 0, 7 ) )
706         {
707             aStrScheme = String::CreateFromAscii( INET_MAILTO_SCHEME );
708         }
709         else if ( aStrURL.EqualsIgnoreCaseAscii( INET_NEWS_SCHEME, 0, 5 ) )
710         {
711             aStrScheme = String::CreateFromAscii( INET_NEWS_SCHEME );
712         }
713         else if ( aStrURL.EqualsIgnoreCaseAscii( INET_TELNET_SCHEME, 0, 9 ) )
714         {
715             aStrScheme = String::CreateFromAscii( INET_TELNET_SCHEME );
716         }
717     }
718     else
719         aStrScheme = INetURLObject::GetScheme( aProtocol );
720     return aStrScheme;
721 }
722 
723 
724 void SvxHyperlinkTabPageBase::GetDataFromCommonFields( String& aStrName,
725 											 String& aStrIntName, String& aStrFrame,
726 											 SvxLinkInsertMode& eMode )
727 {
728 	aStrIntName	= mpEdText->GetText();
729 	aStrName	= mpEdIndication->GetText();
730 	aStrFrame	= mpCbbFrame->GetText();
731 	eMode		= (SvxLinkInsertMode) (mpLbForm->GetSelectEntryPos()+1);
732 	if( IsHTMLDoc() )
733 		eMode = (SvxLinkInsertMode) ( sal_uInt16(eMode) | HLINK_HTMLMODE );
734 }
735 
736 /*************************************************************************
737 |*
738 |* reset dialog-fields
739 |*
740 |************************************************************************/
741 
742 void SvxHyperlinkTabPageBase::Reset( const SfxItemSet& rItemSet)
743 {
744 	///////////////////////////////////////
745 	// Set dialog-fields from create-itemset
746 	maStrInitURL = aEmptyStr;
747 
748 	SvxHyperlinkItem *pHyperlinkItem = (SvxHyperlinkItem *)
749 		                               rItemSet.GetItem (SID_HYPERLINK_GETLINK);
750 
751 	if ( pHyperlinkItem )
752 	{
753 		// set dialog-fields
754 		FillStandardDlgFields (pHyperlinkItem);
755 
756 		// set all other fields
757 		FillDlgFields ( (String&)pHyperlinkItem->GetURL() );
758 
759 		// Store initial URL
760 		maStrInitURL = pHyperlinkItem->GetURL();
761 	}
762 }
763 
764 /*************************************************************************
765 |*
766 |* Fill output-ItemSet
767 |*
768 |************************************************************************/
769 
770 sal_Bool SvxHyperlinkTabPageBase::FillItemSet( SfxItemSet& rOut)
771 {
772 	String aStrURL, aStrName, aStrIntName, aStrFrame;
773 	SvxLinkInsertMode eMode;
774 
775 	GetCurentItemData ( aStrURL, aStrName, aStrIntName, aStrFrame, eMode);
776 	if ( !aStrName.Len() ) //automatically create a visible name if the link is created without name
777 		aStrName = CreateUiNameFromURL(aStrURL);
778 
779 	sal_uInt16 nEvents = GetMacroEvents();
780 	SvxMacroTableDtor* pTable = GetMacroTable();
781 
782 	SvxHyperlinkItem aItem( SID_HYPERLINK_SETLINK, aStrName, aStrURL, aStrFrame,
783 		                    aStrIntName, eMode, nEvents, pTable );
784 	rOut.Put (aItem);
785 
786 	return sal_True;
787 }
788 
789 String SvxHyperlinkTabPageBase::CreateUiNameFromURL( const String& aStrURL )
790 {
791     String			aStrUiURL;
792     INetURLObject	aURLObj( aStrURL );
793 
794     switch(aURLObj.GetProtocol())
795     {
796         case INET_PROT_FILE:
797             utl::LocalFileHelper::ConvertURLToSystemPath( aURLObj.GetMainURL(INetURLObject::NO_DECODE), aStrUiURL );
798             break;
799     	case INET_PROT_FTP :
800             {
801                 //remove password from name
802                 INetURLObject	aTmpURL(aURLObj);
803                 aTmpURL.SetPass(aEmptyStr);
804                 aStrUiURL = aTmpURL.GetMainURL( INetURLObject::DECODE_UNAMBIGUOUS );
805             }
806             break;
807 		default :
808             {
809                 aStrUiURL = aURLObj.GetMainURL(INetURLObject::DECODE_UNAMBIGUOUS);
810             }
811     }
812     if(!aStrUiURL.Len())
813         return aStrURL;
814     return aStrUiURL;
815 }
816 
817 /*************************************************************************
818 |*
819 |* Activate / Deactivate Tabpage
820 |*
821 |************************************************************************/
822 
823 void SvxHyperlinkTabPageBase::ActivatePage( const SfxItemSet& rItemSet )
824 {
825 	///////////////////////////////////////
826 	// Set dialog-fields from input-itemset
827 	SvxHyperlinkItem *pHyperlinkItem = (SvxHyperlinkItem *)
828 		                               rItemSet.GetItem (SID_HYPERLINK_GETLINK);
829 
830 	if ( pHyperlinkItem )
831 	{
832 		// standard-fields
833 		FillStandardDlgFields (pHyperlinkItem);
834 	}
835 
836 	// show mark-window if it was open before
837 	if ( ShouldOpenMarkWnd () )
838 		ShowMarkWnd ();
839 }
840 
841 int SvxHyperlinkTabPageBase::DeactivatePage( SfxItemSet* _pSet)
842 {
843 	// hide mark-wnd
844 	SetMarkWndShouldOpen( IsMarkWndVisible () );
845 	HideMarkWnd ();
846 
847 	// retrieve data of dialog
848 	String aStrURL, aStrName, aStrIntName, aStrFrame;
849 	SvxLinkInsertMode eMode;
850 
851 	GetCurentItemData ( aStrURL, aStrName, aStrIntName, aStrFrame, eMode);
852 
853 	sal_uInt16 nEvents = GetMacroEvents();
854 	SvxMacroTableDtor* pTable = GetMacroTable();
855 
856 	if( _pSet )
857 	{
858 		SvxHyperlinkItem aItem( SID_HYPERLINK_GETLINK, aStrName, aStrURL, aStrFrame,
859 								aStrIntName, eMode, nEvents, pTable );
860 		_pSet->Put( aItem );
861 	}
862 
863 	return( LEAVE_PAGE );
864 }
865 
866 sal_Bool SvxHyperlinkTabPageBase::ShouldOpenMarkWnd()
867 {
868 	return sal_False;
869 }
870 
871 void SvxHyperlinkTabPageBase::SetMarkWndShouldOpen(sal_Bool)
872 {
873 }
874