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