xref: /aoo41x/main/cui/source/customize/macropg.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 #include <basic/basmgr.hxx>
31 
32 #include "macropg.hxx"
33 #include <vcl/msgbox.hxx>
34 #define _SVSTDARR_STRINGSDTOR
35 #include <svl/svstdarr.hxx>
36 #include <svtools/svmedit.hxx>
37 #include <svl/eitem.hxx>
38 #include <tools/diagnose_ex.h>
39 #include <sfx2/app.hxx>
40 #include <sfx2/objsh.hxx>
41 #include <sfx2/sfxdefs.hxx>
42 #include <com/sun/star/container/NoSuchElementException.hpp>
43 #include <com/sun/star/lang/IllegalArgumentException.hpp>
44 #include <dialmgr.hxx>
45 #include "selector.hxx"
46 #include "cfg.hxx"
47 #include "macropg.hrc"
48 #include "helpid.hrc"
49 #include <cuires.hrc>
50 #include "headertablistbox.hxx"
51 #include "macropg_impl.hxx"
52 #include <svx/dialogs.hrc> // RID_SVXPAGE_MACROASSIGN
53 #include <comphelper/namedvaluecollection.hxx>
54 
55 #include <algorithm>
56 #include <set>
57 
58 using namespace ::com::sun::star;
59 using namespace ::com::sun::star::uno;
60 
61 static ::rtl::OUString aVndSunStarUNO =
62 	::rtl::OUString::createFromAscii( "vnd.sun.star.UNO:" );
63 static ::rtl::OUString aVndSunStarScript =
64 	::rtl::OUString::createFromAscii( "vnd.sun.star.script:" );
65 
66 _SvxMacroTabPage_Impl::_SvxMacroTabPage_Impl( const SfxItemSet& rAttrSet ) :
67 	pAssignFT( NULL ),
68     pAssignPB( NULL ),
69 	pAssignComponentPB( NULL ),
70     pDeletePB( NULL ),
71 	pMacroImg( NULL ),
72 	pComponentImg( NULL ),
73 	pMacroImg_h( NULL ),
74 	pComponentImg_h( NULL ),
75     pStrEvent( NULL ),
76     pAssignedMacro( NULL ),
77     pEventLB( NULL ),
78     bReadOnly( sal_False ),
79 	bIDEDialogMode( sal_False )
80 {
81 	const SfxPoolItem* pItem;
82 	if ( SFX_ITEM_SET == rAttrSet.GetItemState( SID_ATTR_MACROITEM, sal_False, &pItem ) )
83         bIDEDialogMode = ((const SfxBoolItem*)pItem)->GetValue();
84 }
85 
86 _SvxMacroTabPage_Impl::~_SvxMacroTabPage_Impl()
87 {
88 	delete pAssignFT;
89     delete pAssignPB;
90 	delete pAssignComponentPB;
91     delete pDeletePB;
92 	delete pMacroImg;
93 	delete pComponentImg;
94 	delete pMacroImg_h;
95 	delete pComponentImg_h;
96     delete pStrEvent;
97     delete pAssignedMacro;
98     delete pEventLB;
99 }
100 
101 // Achtung im Code wird dieses Array direkt (0, 1, ...) indiziert
102 static long nTabs[] =
103     {
104         2, // Number of Tabs
105         0, 90
106     };
107 
108 #define TAB_WIDTH_MIN        10
109 
110 // IDs for items in HeaderBar of EventLB
111 #define    ITEMID_EVENT        1
112 #define    ITMEID_ASSMACRO        2
113 
114 
115 #define LB_EVENTS_ITEMPOS    1
116 #define LB_MACROS_ITEMPOS    2
117 
118 
119 IMPL_LINK( _HeaderTabListBox, HeaderEndDrag_Impl, HeaderBar*, pBar )
120 {
121     DBG_ASSERT( pBar == &maHeaderBar, "*_HeaderTabListBox::HeaderEndDrag_Impl: something is wrong here..." );
122 	(void)pBar;
123 
124     if( !maHeaderBar.GetCurItemId() )
125         return 0;
126 
127     if( !maHeaderBar.IsItemMode() )
128     {
129         Size    aSz;
130         sal_uInt16    _nTabs = maHeaderBar.GetItemCount();
131         long    nTmpSz = 0;
132         long    nWidth = maHeaderBar.GetItemSize( ITEMID_EVENT );
133         long    nBarWidth = maHeaderBar.GetSizePixel().Width();
134 
135         if( nWidth < TAB_WIDTH_MIN )
136             maHeaderBar.SetItemSize( ITEMID_EVENT, TAB_WIDTH_MIN );
137         else if( ( nBarWidth - nWidth ) < TAB_WIDTH_MIN )
138             maHeaderBar.SetItemSize( ITEMID_EVENT, nBarWidth - TAB_WIDTH_MIN );
139 
140         {
141             long    _nWidth;
142             for( sal_uInt16 i = 1 ; i < _nTabs ; ++i )
143             {
144                 _nWidth = maHeaderBar.GetItemSize( i );
145                 aSz.Width() =  _nWidth + nTmpSz;
146                 nTmpSz += _nWidth;
147                 maListBox.SetTab( i, PixelToLogic( aSz, MapMode( MAP_APPFONT ) ).Width(), MAP_APPFONT );
148             }
149         }
150     }
151     return 1;
152 }
153 
154 long _HeaderTabListBox::Notify( NotifyEvent& rNEvt )
155 {
156     long    nRet = Control::Notify( rNEvt );
157 
158     if( rNEvt.GetType() == EVENT_GETFOCUS )
159 	{
160 		if ( rNEvt.GetWindow() != &maListBox )
161 			maListBox.GrabFocus();
162 	}
163 
164     return nRet;
165 }
166 
167 _HeaderTabListBox::_HeaderTabListBox( Window* pParent, const ResId& rId ) :
168     Control( pParent, rId ),
169     maListBox( this, WB_HSCROLL | WB_CLIPCHILDREN | WB_TABSTOP ),
170     maHeaderBar( this, WB_BUTTONSTYLE | WB_BOTTOMBORDER )
171 {
172     maListBox.SetHelpId( HID_MACRO_HEADERTABLISTBOX );
173 }
174 
175 _HeaderTabListBox::~_HeaderTabListBox()
176 {
177 }
178 
179 void _HeaderTabListBox::ConnectElements( void )
180 {
181     // calc pos and size of header bar
182     Point    aPnt( 0, 0 );
183     Size    aSize( maHeaderBar.CalcWindowSizePixel() );
184     Size    aCtrlSize( GetOutputSizePixel() );
185     aSize.Width() = aCtrlSize.Width();
186     maHeaderBar.SetPosSizePixel( aPnt, aSize );
187 
188     // calc pos and size of ListBox
189     aPnt.Y() += aSize.Height();
190     aSize.Height() = aCtrlSize.Height() - aSize.Height();
191     maListBox.SetPosSizePixel( aPnt, aSize );
192 
193     // set handler
194     maHeaderBar.SetEndDragHdl( LINK( this, _HeaderTabListBox, HeaderEndDrag_Impl ) );
195 
196     maListBox.InitHeaderBar( &maHeaderBar );
197 }
198 
199 void _HeaderTabListBox::Show( sal_Bool bVisible, sal_uInt16 nFlags )
200 {
201     maListBox.Show( bVisible, nFlags );
202     maHeaderBar.Show( bVisible, nFlags );
203 }
204 
205 void _HeaderTabListBox::Enable( bool bEnable, bool bChild )
206 {
207     maListBox.Enable( bEnable, bChild );
208     maHeaderBar.Enable( bEnable, bChild );
209 }
210 
211 // assign button ("Add Command") is enabled only if it is not read only
212 // delete button ("Remove Command") is enabled if a current binding exists
213 //     and it is not read only
214 void _SvxMacroTabPage::EnableButtons()
215 {
216     const SvLBoxEntry* pE = mpImpl->pEventLB->GetListBox().FirstSelected();
217     if ( pE )
218     {
219         SvLBoxString* pEventMacro = (SvLBoxString*)pE->GetItem( LB_MACROS_ITEMPOS );
220         mpImpl->pDeletePB->Enable( 0 != pEventMacro && !mpImpl->bReadOnly );
221 
222         mpImpl->pAssignPB->Enable( !mpImpl->bReadOnly );
223 		if( mpImpl->pAssignComponentPB )
224 			mpImpl->pAssignComponentPB->Enable( !mpImpl->bReadOnly );
225     }
226 }
227 
228 _SvxMacroTabPage::_SvxMacroTabPage( Window* pParent, const ResId& rResId, const SfxItemSet& rAttrSet )
229     : SfxTabPage( pParent, rResId, rAttrSet ),
230     m_xAppEvents(0),
231     m_xDocEvents(0),
232     bReadOnly(false),
233     bDocModified(false),
234     bAppEvents(false),
235     bInitialized(false)
236 {
237     mpImpl = new _SvxMacroTabPage_Impl( rAttrSet );
238 }
239 
240 _SvxMacroTabPage::~_SvxMacroTabPage()
241 {
242     // need to delete the user data
243     SvHeaderTabListBox& rListBox = mpImpl->pEventLB->GetListBox();
244     SvLBoxEntry* pE = rListBox.GetEntry( 0 );
245     while( pE )
246     {
247         ::rtl::OUString* pEventName = (::rtl::OUString*)pE->GetUserData();
248         delete pEventName;
249         pE->SetUserData((void*)0);
250         pE = rListBox.NextSibling( pE );
251     }
252     DELETEZ( mpImpl );
253 }
254 // -----------------------------------------------------------------------------
255 void _SvxMacroTabPage::InitResources()
256 {
257     // Note: the order here controls the order in which the events are displayed in the UI!
258 
259     // the event name to UI string mappings for App Events
260     aDisplayNames.push_back( EventDisplayName( "OnStartApp",            RID_SVXSTR_EVENT_STARTAPP ) );
261     aDisplayNames.push_back( EventDisplayName( "OnCloseApp",            RID_SVXSTR_EVENT_CLOSEAPP ) );
262     aDisplayNames.push_back( EventDisplayName( "OnCreate",              RID_SVXSTR_EVENT_CREATEDOC ) );
263     aDisplayNames.push_back( EventDisplayName( "OnNew",                 RID_SVXSTR_EVENT_NEWDOC ) );
264     aDisplayNames.push_back( EventDisplayName( "OnLoadFinished",        RID_SVXSTR_EVENT_LOADDOCFINISHED ) );
265     aDisplayNames.push_back( EventDisplayName( "OnLoad",                RID_SVXSTR_EVENT_OPENDOC ) );
266     aDisplayNames.push_back( EventDisplayName( "OnPrepareUnload",       RID_SVXSTR_EVENT_PREPARECLOSEDOC ) );
267     aDisplayNames.push_back( EventDisplayName( "OnUnload",              RID_SVXSTR_EVENT_CLOSEDOC ) ) ;
268     aDisplayNames.push_back( EventDisplayName( "OnViewCreated",         RID_SVXSTR_EVENT_VIEWCREATED ) );
269 	aDisplayNames.push_back( EventDisplayName( "OnPrepareViewClosing",  RID_SVXSTR_EVENT_PREPARECLOSEVIEW ) );
270     aDisplayNames.push_back( EventDisplayName( "OnViewClosed",          RID_SVXSTR_EVENT_CLOSEVIEW ) ) ;
271     aDisplayNames.push_back( EventDisplayName( "OnFocus",               RID_SVXSTR_EVENT_ACTIVATEDOC ) );
272     aDisplayNames.push_back( EventDisplayName( "OnUnfocus",             RID_SVXSTR_EVENT_DEACTIVATEDOC ) );
273     aDisplayNames.push_back( EventDisplayName( "OnSave",                RID_SVXSTR_EVENT_SAVEDOC ) );
274     aDisplayNames.push_back( EventDisplayName( "OnSaveDone",            RID_SVXSTR_EVENT_SAVEDOCDONE ) );
275     aDisplayNames.push_back( EventDisplayName( "OnSaveFailed",          RID_SVXSTR_EVENT_SAVEDOCFAILED ) );
276     aDisplayNames.push_back( EventDisplayName( "OnSaveAs",              RID_SVXSTR_EVENT_SAVEASDOC ) );
277     aDisplayNames.push_back( EventDisplayName( "OnSaveAsDone",          RID_SVXSTR_EVENT_SAVEASDOCDONE ) );
278     aDisplayNames.push_back( EventDisplayName( "OnSaveAsFailed",        RID_SVXSTR_EVENT_SAVEASDOCFAILED ) );
279     aDisplayNames.push_back( EventDisplayName( "OnCopyTo",              RID_SVXSTR_EVENT_COPYTODOC ) );
280     aDisplayNames.push_back( EventDisplayName( "OnCopyToDone",          RID_SVXSTR_EVENT_COPYTODOCDONE ) );
281     aDisplayNames.push_back( EventDisplayName( "OnCopyToFailed",        RID_SVXSTR_EVENT_COPYTODOCFAILED ) );
282     aDisplayNames.push_back( EventDisplayName( "OnPrint",               RID_SVXSTR_EVENT_PRINTDOC ) );
283     aDisplayNames.push_back( EventDisplayName( "OnModifyChanged",       RID_SVXSTR_EVENT_MODIFYCHANGED ) );
284     aDisplayNames.push_back( EventDisplayName( "OnTitleChanged",        RID_SVXSTR_EVENT_TITLECHANGED ) );
285 //    aDisplayNames.push_back( EventDisplayName( "OnModeChanged",         RID_SVXSTR_EVENT_MODECHANGED ) );
286 //    aDisplayNames.push_back( EventDisplayName( "OnVisAreaChanged",      RID_SVXSTR_EVENT_VISAREACHANGED ) );
287 //    aDisplayNames.push_back( EventDisplayName( "OnStorageChanged",      RID_SVXSTR_EVENT_STORAGECHANGED ) );
288 
289 	// application specific events
290     aDisplayNames.push_back( EventDisplayName( "OnMailMerge",           RID_SVXSTR_EVENT_MAILMERGE ) );
291     aDisplayNames.push_back( EventDisplayName( "OnMailMergeFinished",           RID_SVXSTR_EVENT_MAILMERGE_END ) );
292     aDisplayNames.push_back( EventDisplayName( "OnFieldMerge",           RID_SVXSTR_EVENT_FIELDMERGE ) );
293     aDisplayNames.push_back( EventDisplayName( "OnFieldMergeFinished",           RID_SVXSTR_EVENT_FIELDMERGE_FINISHED ) );
294     aDisplayNames.push_back( EventDisplayName( "OnPageCountChange",     RID_SVXSTR_EVENT_PAGECOUNTCHANGE ) );
295     aDisplayNames.push_back( EventDisplayName( "OnSubComponentOpened",  RID_SVXSTR_EVENT_SUBCOMPONENT_OPENED ) );
296     aDisplayNames.push_back( EventDisplayName( "OnSubComponentClosed",  RID_SVXSTR_EVENT_SUBCOMPONENT_CLOSED ) );
297 //    aDisplayNames.push_back( EventDisplayName( "OnLayoutFinished",		RID_SVXSTR_EVENT_LAYOUT_FINISHED ) );
298     aDisplayNames.push_back( EventDisplayName( "OnSelect",              RID_SVXSTR_EVENT_SELECTIONCHANGED ) );
299     aDisplayNames.push_back( EventDisplayName( "OnDoubleClick",         RID_SVXSTR_EVENT_DOUBLECLICK ) );
300     aDisplayNames.push_back( EventDisplayName( "OnRightClick",          RID_SVXSTR_EVENT_RIGHTCLICK ) );
301     aDisplayNames.push_back( EventDisplayName( "OnCalculate",           RID_SVXSTR_EVENT_CALCULATE ) );
302     aDisplayNames.push_back( EventDisplayName( "OnChange",              RID_SVXSTR_EVENT_CONTENTCHANGED ) );
303 
304     // the event name to UI string mappings for forms & dialogs
305     //
306     aDisplayNames.push_back( EventDisplayName( "approveAction",         RID_SVXSTR_EVENT_APPROVEACTIONPERFORMED ) );
307     aDisplayNames.push_back( EventDisplayName( "actionPerformed",       RID_SVXSTR_EVENT_ACTIONPERFORMED ) );
308     aDisplayNames.push_back( EventDisplayName( "changed",               RID_SVXSTR_EVENT_CHANGED ) );
309     aDisplayNames.push_back( EventDisplayName( "textChanged",           RID_SVXSTR_EVENT_TEXTCHANGED ) );
310     aDisplayNames.push_back( EventDisplayName( "itemStateChanged",      RID_SVXSTR_EVENT_ITEMSTATECHANGED ) );
311     aDisplayNames.push_back( EventDisplayName( "focusGained",           RID_SVXSTR_EVENT_FOCUSGAINED ) );
312     aDisplayNames.push_back( EventDisplayName( "focusLost",             RID_SVXSTR_EVENT_FOCUSLOST ) );
313     aDisplayNames.push_back( EventDisplayName( "keyPressed",            RID_SVXSTR_EVENT_KEYTYPED ) );
314     aDisplayNames.push_back( EventDisplayName( "keyReleased",           RID_SVXSTR_EVENT_KEYUP ) );
315     aDisplayNames.push_back( EventDisplayName( "mouseEntered",          RID_SVXSTR_EVENT_MOUSEENTERED ) );
316     aDisplayNames.push_back( EventDisplayName( "mouseDragged",          RID_SVXSTR_EVENT_MOUSEDRAGGED ) );
317     aDisplayNames.push_back( EventDisplayName( "mouseMoved",            RID_SVXSTR_EVENT_MOUSEMOVED ) );
318     aDisplayNames.push_back( EventDisplayName( "mousePressed",          RID_SVXSTR_EVENT_MOUSEPRESSED ) );
319     aDisplayNames.push_back( EventDisplayName( "mouseReleased",         RID_SVXSTR_EVENT_MOUSERELEASED ) );
320     aDisplayNames.push_back( EventDisplayName( "mouseExited",           RID_SVXSTR_EVENT_MOUSEEXITED ) );
321     aDisplayNames.push_back( EventDisplayName( "approveReset",          RID_SVXSTR_EVENT_APPROVERESETTED ) );
322     aDisplayNames.push_back( EventDisplayName( "resetted",              RID_SVXSTR_EVENT_RESETTED ) );
323     aDisplayNames.push_back( EventDisplayName( "approveSubmit",         RID_SVXSTR_EVENT_SUBMITTED ) );
324     aDisplayNames.push_back( EventDisplayName( "approveUpdate",         RID_SVXSTR_EVENT_BEFOREUPDATE ) );
325     aDisplayNames.push_back( EventDisplayName( "updated",               RID_SVXSTR_EVENT_AFTERUPDATE ) );
326     aDisplayNames.push_back( EventDisplayName( "loaded",                RID_SVXSTR_EVENT_LOADED ) );
327     aDisplayNames.push_back( EventDisplayName( "reloading",             RID_SVXSTR_EVENT_RELOADING ) );
328     aDisplayNames.push_back( EventDisplayName( "reloaded",              RID_SVXSTR_EVENT_RELOADED ) );
329     aDisplayNames.push_back( EventDisplayName( "unloading",             RID_SVXSTR_EVENT_UNLOADING ) );
330     aDisplayNames.push_back( EventDisplayName( "unloaded",              RID_SVXSTR_EVENT_UNLOADED ) );
331     aDisplayNames.push_back( EventDisplayName( "confirmDelete",         RID_SVXSTR_EVENT_CONFIRMDELETE ) );
332     aDisplayNames.push_back( EventDisplayName( "approveRowChange",      RID_SVXSTR_EVENT_APPROVEROWCHANGE ) );
333     aDisplayNames.push_back( EventDisplayName( "rowChanged",            RID_SVXSTR_EVENT_ROWCHANGE ) );
334     aDisplayNames.push_back( EventDisplayName( "approveCursorMove",     RID_SVXSTR_EVENT_POSITIONING ) );
335     aDisplayNames.push_back( EventDisplayName( "cursorMoved",           RID_SVXSTR_EVENT_POSITIONED ) );
336     aDisplayNames.push_back( EventDisplayName( "approveParameter",      RID_SVXSTR_EVENT_APPROVEPARAMETER ) );
337     aDisplayNames.push_back( EventDisplayName( "errorOccured",          RID_SVXSTR_EVENT_ERROROCCURED ) );
338     aDisplayNames.push_back( EventDisplayName( "adjustmentValueChanged",   RID_SVXSTR_EVENT_ADJUSTMENTVALUECHANGED ) );
339 }
340 
341 // the following method is called when the user clicks OK
342 // We use the contents of the hashes to replace the settings
343 sal_Bool _SvxMacroTabPage::FillItemSet( SfxItemSet& /*rSet*/ )
344 {
345     try
346     {
347         ::rtl::OUString eventName;
348         if( m_xAppEvents.is() )
349         {
350             EventsHash::iterator h_itEnd =  m_appEventsHash.end();
351             EventsHash::iterator h_it = m_appEventsHash.begin();
352             for ( ; h_it !=  h_itEnd; ++h_it )
353             {
354                 eventName = h_it->first;
355                 try
356                 {
357                     m_xAppEvents->replaceByName( eventName, GetPropsByName( eventName, m_appEventsHash ) );
358                 }
359                 catch( const Exception& )
360                 {
361                 	DBG_UNHANDLED_EXCEPTION();
362                 }
363             }
364         }
365         if( m_xDocEvents.is() && bDocModified )
366         {
367             EventsHash::iterator h_itEnd =  m_docEventsHash.end();
368             EventsHash::iterator h_it = m_docEventsHash.begin();
369             for ( ; h_it !=  h_itEnd; ++h_it )
370             {
371                 eventName = h_it->first;
372                 try
373                 {
374                     m_xDocEvents->replaceByName( eventName, GetPropsByName( eventName, m_docEventsHash ) );
375                 }
376                 catch( const Exception& )
377                 {
378                 	DBG_UNHANDLED_EXCEPTION();
379                 }
380             }
381             // if we have a valid XModifiable (in the case of doc events)
382             // call setModified(true)
383             // in principle this should not be necessary (see issue ??)
384             if(m_xModifiable.is())
385             {
386                 m_xModifiable->setModified( sal_True );
387             }
388         }
389     }
390     catch(Exception&)
391     {
392     }
393     // what is the return value about??
394     return sal_False;
395 }
396 
397 // the following method clears the bindings in the hashes for both doc & app
398 void _SvxMacroTabPage::Reset()
399 {
400     // called once in creation - don't reset the data this time
401     if(!bInitialized)
402     {
403         bInitialized = true;
404         return;
405     }
406 
407     try
408     {
409 			::rtl::OUString sEmpty;
410             if( m_xAppEvents.is() )
411             {
412                 EventsHash::iterator h_itEnd =  m_appEventsHash.end();
413                 EventsHash::iterator h_it = m_appEventsHash.begin();
414                 for ( ; h_it !=  h_itEnd; ++h_it )
415                 {
416                     h_it->second.second = sEmpty;
417                 }
418             }
419             if( m_xDocEvents.is() && bDocModified )
420             {
421                 EventsHash::iterator h_itEnd =  m_docEventsHash.end();
422                 EventsHash::iterator h_it = m_docEventsHash.begin();
423                 for ( ; h_it !=  h_itEnd; ++h_it )
424                 {
425                     h_it->second.second = sEmpty;
426                 }
427                 // if we have a valid XModifiable (in the case of doc events)
428                 // call setModified(true)
429                 if(m_xModifiable.is())
430                 {
431                     m_xModifiable->setModified( sal_True );
432                 }
433             }
434     }
435     catch(Exception&)
436     {
437     }
438     DisplayAppEvents(bAppEvents);
439 }
440 
441 void _SvxMacroTabPage::SetReadOnly( sal_Bool bSet )
442 {
443     mpImpl->bReadOnly = bSet;
444 }
445 
446 sal_Bool _SvxMacroTabPage::IsReadOnly() const
447 {
448     return mpImpl->bReadOnly;
449 }
450 
451 
452 class IconLBoxString : public SvLBoxString
453 {
454 	Image* m_pMacroImg;
455 	Image* m_pComponentImg;
456 	Image* m_pMacroImg_h;
457 	Image* m_pComponentImg_h;
458 	int m_nxImageOffset;
459 
460     public:
461         IconLBoxString( SvLBoxEntry* pEntry, sal_uInt16 nFlags, const String& sText,
462 			Image* pMacroImg, Image* pComponentImg,
463 			Image* pMacroImg_h, Image* pComponentImg_h );
464         virtual void Paint(const Point& aPos, SvLBox& aDevice, sal_uInt16 nFlags, SvLBoxEntry* pEntry );
465 };
466 
467 
468 IconLBoxString::IconLBoxString( SvLBoxEntry* pEntry, sal_uInt16 nFlags, const String& sText,
469 	Image* pMacroImg, Image* pComponentImg, Image* pMacroImg_h, Image* pComponentImg_h )
470 		: SvLBoxString( pEntry, nFlags, sText )
471 		, m_pMacroImg( pMacroImg )
472 		, m_pComponentImg( pComponentImg )
473 		, m_pMacroImg_h( pMacroImg_h )
474 		, m_pComponentImg_h( pComponentImg_h )
475 {
476 	m_nxImageOffset = 20;
477 }
478 
479 //===============================================
480 void IconLBoxString::Paint( const Point& aPos, SvLBox& aDevice,
481 							   sal_uInt16 /*nFlags*/, SvLBoxEntry* /*pEntry*/ )
482 {
483 	String aTxt( GetText() );
484 	if( aTxt.Len() )
485 	{
486 		::rtl::OUString aURL( aTxt );
487 		sal_Int32 nIndex = aURL.indexOf( aVndSunStarUNO );
488 		bool bUNO = nIndex == 0;
489 
490 		sal_Bool bHC = aDevice.GetSettings().GetStyleSettings().GetHighContrastMode();
491 		const Image* pImg;
492 		if( bHC )
493 			pImg = bUNO ? m_pComponentImg_h : m_pMacroImg_h;
494 		else
495 			pImg = bUNO ? m_pComponentImg : m_pMacroImg;
496 		aDevice.DrawImage( aPos, *pImg );
497 
498 		::rtl::OUString aPureMethod;
499 		if( bUNO )
500 		{
501 			sal_Int32 nBegin = aVndSunStarUNO.getLength();
502 			aPureMethod = aURL.copy( nBegin );
503 		}
504 		else
505 		{
506 			sal_Int32 nBegin = aVndSunStarScript.getLength();
507 			aPureMethod = aURL.copy( nBegin );
508 			aPureMethod = aPureMethod.copy( 0, aPureMethod.indexOf( '?' ) );
509 		}
510 
511 		Point aPnt(aPos);
512 		aPnt.X() += m_nxImageOffset;
513 		aDevice.DrawText( aPnt, aPureMethod );
514 	}
515 }
516 
517 
518 // displays the app events if appEvents=true, otherwise displays the doc events
519 void _SvxMacroTabPage::DisplayAppEvents( bool appEvents)
520 {
521     bAppEvents = appEvents;
522 
523     SvHeaderTabListBox&        rListBox = mpImpl->pEventLB->GetListBox();
524     mpImpl->pEventLB->SetUpdateMode( sal_False );
525     rListBox.Clear();
526     SvLBoxEntry*    pE = rListBox.GetEntry( 0 );
527     EventsHash* eventsHash;
528     Reference< container::XNameReplace> nameReplace;
529     if(bAppEvents)
530     {
531         eventsHash = &m_appEventsHash;
532         nameReplace = m_xAppEvents;
533     }
534     else
535     {
536         eventsHash = &m_docEventsHash;
537         nameReplace = m_xDocEvents;
538     }
539     // have to use the original XNameReplace since the hash iterators do
540     // not guarantee the order in which the elements are returned
541     if(!nameReplace.is())
542     {
543         return;
544     }
545 
546     Sequence< ::rtl::OUString > eventNames = nameReplace->getElementNames();
547     ::std::set< ::rtl::OUString > aEventNamesCache;
548     ::std::copy(
549         eventNames.getConstArray(),
550         eventNames.getConstArray() + eventNames.getLength(),
551         ::std::insert_iterator< ::std::set< ::rtl::OUString > >( aEventNamesCache, aEventNamesCache.end() )
552     );
553 
554     for (   EventDisplayNames::const_iterator displayableEvent = aDisplayNames.begin();
555             displayableEvent != aDisplayNames.end();
556             ++displayableEvent
557         )
558     {
559         ::rtl::OUString sEventName( ::rtl::OUString::createFromAscii( displayableEvent->pAsciiEventName ) );
560         if ( !nameReplace->hasByName( sEventName ) )
561             continue;
562 
563         EventsHash::iterator h_it = eventsHash->find( sEventName );
564         if( h_it == eventsHash->end() )
565         {
566             OSL_ENSURE( false, "_SvxMacroTabPage::DisplayAppEvents: something's suspicious here!" );
567             continue;
568         }
569 
570         ::rtl::OUString eventURL = h_it->second.second;
571         String displayName( CUI_RES( displayableEvent->nEventResourceID ) );
572 
573         displayName += '\t';
574         SvLBoxEntry*    _pE = rListBox.InsertEntry( displayName );
575         ::rtl::OUString* pEventName = new ::rtl::OUString( sEventName );
576         _pE->SetUserData( (void*)pEventName );
577         String sNew( eventURL );
578         _pE->ReplaceItem( new IconLBoxString( _pE, 0, sNew,
579 			mpImpl->pMacroImg, mpImpl->pComponentImg,
580 			mpImpl->pMacroImg_h, mpImpl->pComponentImg_h ), LB_MACROS_ITEMPOS );
581         rListBox.GetModel()->InvalidateEntry( _pE );
582         rListBox.Select( _pE );
583         rListBox.MakeVisible( _pE );
584     }
585 
586 	pE = rListBox.GetEntry(0);
587     if( pE )
588 	{
589         rListBox.Select( pE );
590         rListBox.MakeVisible( pE );
591 	}
592 
593     rListBox.SetUpdateMode( sal_True );
594     EnableButtons();
595 }
596 
597 // select event handler on the listbox
598 IMPL_STATIC_LINK( _SvxMacroTabPage, SelectEvent_Impl, SvTabListBox*, EMPTYARG )
599 {
600     _SvxMacroTabPage_Impl*    pImpl = pThis->mpImpl;
601     SvHeaderTabListBox&        rListBox = pImpl->pEventLB->GetListBox();
602     SvLBoxEntry*            pE = rListBox.FirstSelected();
603     sal_uLong                    nPos;
604 
605     if( !pE || LISTBOX_ENTRY_NOTFOUND ==
606         ( nPos = rListBox.GetModel()->GetAbsPos( pE ) ) )
607     {
608         DBG_ASSERT( pE, "wo kommt der leere Eintrag her?" );
609         return 0;
610     }
611 
612     pThis->EnableButtons();
613     return 0;
614 }
615 
616 IMPL_STATIC_LINK( _SvxMacroTabPage, AssignDeleteHdl_Impl, PushButton*, pBtn )
617 {
618 	return GenericHandler_Impl( pThis, pBtn );
619 }
620 
621 IMPL_STATIC_LINK( _SvxMacroTabPage, DoubleClickHdl_Impl, SvTabListBox *, EMPTYARG )
622 {
623 	return GenericHandler_Impl( pThis, NULL );
624 }
625 
626 // handler for double click on the listbox, and for the assign/delete buttons
627 long _SvxMacroTabPage::GenericHandler_Impl( _SvxMacroTabPage* pThis, PushButton* pBtn )
628 {
629     _SvxMacroTabPage_Impl*    pImpl = pThis->mpImpl;
630     SvHeaderTabListBox& rListBox = pImpl->pEventLB->GetListBox();
631     SvLBoxEntry* pE = rListBox.FirstSelected();
632     sal_uLong nPos;
633     if( !pE || LISTBOX_ENTRY_NOTFOUND ==
634         ( nPos = rListBox.GetModel()->GetAbsPos( pE ) ) )
635     {
636         DBG_ASSERT( pE, "wo kommt der leere Eintrag her?" );
637         return 0;
638     }
639 
640     const sal_Bool bAssEnabled = pBtn != pImpl->pDeletePB && pImpl->pAssignPB->IsEnabled();
641 
642     ::rtl::OUString* pEventName = (::rtl::OUString*)pE->GetUserData();
643 
644     ::rtl::OUString sEventURL;
645     ::rtl::OUString sEventType;
646     if(pThis->bAppEvents)
647     {
648         EventsHash::iterator h_it = pThis->m_appEventsHash.find( *pEventName );
649         if(h_it != pThis->m_appEventsHash.end() )
650         {
651             sEventType = h_it->second.first;
652             sEventURL = h_it->second.second;
653         }
654     }
655     else
656     {
657         EventsHash::iterator h_it = pThis->m_docEventsHash.find( *pEventName );
658         if(h_it != pThis->m_docEventsHash.end() )
659         {
660             sEventType = h_it->second.first;
661             sEventURL = h_it->second.second;
662         }
663     }
664 
665 	bool bDoubleClick = (pBtn == NULL);
666 	bool bUNOAssigned = (sEventURL.indexOf( aVndSunStarUNO ) == 0);
667     if( pBtn == pImpl->pDeletePB )
668     {
669         // delete pressed
670         sEventType = ::rtl::OUString::createFromAscii("Script");
671         sEventURL = ::rtl::OUString();
672         if(!pThis->bAppEvents)
673 			pThis->bDocModified = true;
674     }
675     else if (   (   ( pBtn != NULL )
676                 &&  ( pBtn == pImpl->pAssignComponentPB )
677                 )
678             ||  (   bDoubleClick
679                 &&  bUNOAssigned
680                 )
681             )
682     {
683 		AssignComponentDialog* pAssignDlg = new AssignComponentDialog( pThis, sEventURL );
684 
685         short ret = pAssignDlg->Execute();
686         if( ret )
687 		{
688 	        sEventType = ::rtl::OUString::createFromAscii("UNO");
689 	        sEventURL = pAssignDlg->getURL();
690             if(!pThis->bAppEvents)
691 				pThis->bDocModified = true;
692 		}
693 		delete pAssignDlg;
694 	}
695     else if( bAssEnabled )
696     {
697         // assign pressed
698         SvxScriptSelectorDialog* pDlg = new SvxScriptSelectorDialog( pThis, sal_False, pThis->GetFrame() );
699         if( pDlg )
700         {
701             short ret = pDlg->Execute();
702             if ( ret )
703             {
704                 sEventType = ::rtl::OUString::createFromAscii("Script");
705                 sEventURL = pDlg->GetScriptURL();
706                 if(!pThis->bAppEvents)
707 					pThis->bDocModified = true;
708             }
709         }
710     }
711 
712     // update the hashes
713     if(pThis->bAppEvents)
714     {
715         EventsHash::iterator h_it = pThis->m_appEventsHash.find( *pEventName );
716         h_it->second.first = sEventType;
717         h_it->second.second = sEventURL;
718     }
719     else
720     {
721         EventsHash::iterator h_it = pThis->m_docEventsHash.find( *pEventName );
722         h_it->second.first = sEventType;
723         h_it->second.second = sEventURL;
724     }
725 
726     // update the listbox entry
727     pImpl->pEventLB->SetUpdateMode( sal_False );
728     // pE->ReplaceItem( new SvLBoxString( pE, 0, sEventURL ), LB_MACROS_ITEMPOS );
729     pE->ReplaceItem( new IconLBoxString( pE, 0, sEventURL,
730 			pImpl->pMacroImg, pImpl->pComponentImg,
731 			pImpl->pMacroImg_h, pImpl->pComponentImg_h ), LB_MACROS_ITEMPOS );
732 
733     rListBox.GetModel()->InvalidateEntry( pE );
734     rListBox.Select( pE );
735     rListBox.MakeVisible( pE );
736     rListBox.SetUpdateMode( sal_True );
737 
738     pThis->EnableButtons();
739     return 0;
740 }
741 
742 // pass in the XNameReplace.
743 // can remove the 3rd arg once issue ?? is fixed
744 void _SvxMacroTabPage::InitAndSetHandler( Reference< container::XNameReplace> xAppEvents, Reference< container::XNameReplace> xDocEvents, Reference< util::XModifiable > xModifiable )
745 {
746     m_xAppEvents = xAppEvents;
747     m_xDocEvents = xDocEvents;
748     m_xModifiable = xModifiable;
749     SvHeaderTabListBox&    rListBox = mpImpl->pEventLB->GetListBox();
750     HeaderBar&            rHeaderBar = mpImpl->pEventLB->GetHeaderBar();
751     Link                aLnk(STATIC_LINK(this, _SvxMacroTabPage, AssignDeleteHdl_Impl ));
752     mpImpl->pDeletePB->SetClickHdl(    aLnk );
753     mpImpl->pAssignPB->SetClickHdl(    aLnk );
754 	if( mpImpl->pAssignComponentPB )
755 	    mpImpl->pAssignComponentPB->SetClickHdl( aLnk );
756     rListBox.SetDoubleClickHdl( STATIC_LINK(this, _SvxMacroTabPage, DoubleClickHdl_Impl ) );
757 
758     rListBox.SetSelectHdl( STATIC_LINK( this, _SvxMacroTabPage, SelectEvent_Impl ));
759 
760     rListBox.SetSelectionMode( SINGLE_SELECTION );
761     rListBox.SetTabs( &nTabs[0], MAP_APPFONT );
762     Size aSize( nTabs[ 2 ], 0 );
763     rHeaderBar.InsertItem( ITEMID_EVENT, *mpImpl->pStrEvent, LogicToPixel( aSize, MapMode( MAP_APPFONT ) ).Width() );
764     aSize.Width() = 1764;        // don't know what, so 42^2 is best to use...
765     rHeaderBar.InsertItem( ITMEID_ASSMACRO, *mpImpl->pAssignedMacro, LogicToPixel( aSize, MapMode( MAP_APPFONT ) ).Width() );
766     rListBox.SetSpaceBetweenEntries( 0 );
767 
768     mpImpl->pEventLB->Show();
769     mpImpl->pEventLB->ConnectElements();
770 
771 	long nMinLineHeight = mpImpl->pMacroImg->GetSizePixel().Height() + 2;
772 	if( nMinLineHeight > mpImpl->pEventLB->GetListBox().GetEntryHeight() )
773 	    mpImpl->pEventLB->GetListBox().SetEntryHeight(
774             sal::static_int_cast< short >(nMinLineHeight) );
775 
776     mpImpl->pEventLB->Enable( sal_True );
777 
778     if(!m_xAppEvents.is())
779     {
780         return;
781     }
782     Sequence< ::rtl::OUString > eventNames = m_xAppEvents->getElementNames();
783     sal_Int32 nEventCount = eventNames.getLength();
784     for(sal_Int32 nEvent = 0; nEvent < nEventCount; ++nEvent )
785     {
786         //need exception handling here
787         try
788         {
789             m_appEventsHash[ eventNames[nEvent] ] = GetPairFromAny( m_xAppEvents->getByName( eventNames[nEvent] ) );
790         }
791         catch (Exception e)
792         {}
793     }
794     if(m_xDocEvents.is())
795     {
796         eventNames = m_xDocEvents->getElementNames();
797         nEventCount = eventNames.getLength();
798         for(sal_Int32 nEvent = 0; nEvent < nEventCount; ++nEvent )
799         {
800             try
801             {
802                 m_docEventsHash[ eventNames[nEvent] ] = GetPairFromAny( m_xDocEvents->getByName( eventNames[nEvent] ) );
803             }
804             catch (Exception e)
805             {}
806         }
807     }
808 }
809 
810 // returns the two props EventType & Script for a given event name
811 Any _SvxMacroTabPage::GetPropsByName( const ::rtl::OUString& eventName, EventsHash& eventsHash )
812 {
813     const ::std::pair< ::rtl::OUString, ::rtl::OUString >& rAssignedEvent( eventsHash[ eventName ] );
814 
815     Any aReturn;
816     ::comphelper::NamedValueCollection aProps;
817     if ( rAssignedEvent.first.getLength() && rAssignedEvent.second.getLength() )
818     {
819         aProps.put( "EventType", rAssignedEvent.first );
820         aProps.put( "Script", rAssignedEvent.second );
821     }
822     aReturn <<= aProps.getPropertyValues();
823 
824     return aReturn;
825 }
826 
827 // converts the Any returned by GetByName into a pair which can be stored in
828 // the EventHash
829 ::std::pair< ::rtl::OUString, ::rtl::OUString  > _SvxMacroTabPage::GetPairFromAny( Any aAny )
830 {
831     Sequence< beans::PropertyValue > props;
832     ::rtl::OUString type, url;
833     if( sal_True == ( aAny >>= props ) )
834     {
835         ::comphelper::NamedValueCollection aProps( props );
836         type = aProps.getOrDefault( "EventType", type );
837         url = aProps.getOrDefault( "Script", url );
838     }
839     return ::std::make_pair( type, url );
840 }
841 
842 SvxMacroTabPage::SvxMacroTabPage( Window* pParent, const Reference< frame::XFrame >& _rxDocumentFrame, const SfxItemSet& rSet, Reference< container::XNameReplace > xNameReplace, sal_uInt16 nSelectedIndex )
843     : _SvxMacroTabPage( pParent, CUI_RES( RID_SVXPAGE_MACROASSIGN ), rSet )
844 {
845     mpImpl->pStrEvent           = new String(						CUI_RES( STR_EVENT ) );
846     mpImpl->pAssignedMacro      = new String(						CUI_RES( STR_ASSMACRO ) );
847     mpImpl->pEventLB            = new _HeaderTabListBox( this,		CUI_RES( LB_EVENT ) );
848     mpImpl->pAssignFT			= new FixedText( this,				CUI_RES( FT_ASSIGN ) );
849     mpImpl->pAssignPB           = new PushButton( this,				CUI_RES( PB_ASSIGN ) );
850     mpImpl->pDeletePB           = new PushButton( this,				CUI_RES( PB_DELETE ) );
851 	mpImpl->pAssignComponentPB  = new PushButton( this,			CUI_RES( PB_ASSIGN_COMPONENT ) );
852 	mpImpl->pMacroImg			= new Image(						CUI_RES(IMG_MACRO) );
853 	mpImpl->pComponentImg		= new Image(						CUI_RES(IMG_COMPONENT) );
854 	mpImpl->pMacroImg_h			= new Image(						CUI_RES(IMG_MACRO_H) );
855 	mpImpl->pComponentImg_h		= new Image(						CUI_RES(IMG_COMPONENT_H) );
856 
857     FreeResource();
858 
859     SetFrame( _rxDocumentFrame );
860 
861 	if( !mpImpl->bIDEDialogMode )
862 	{
863 		// Size aSizeAssign;
864 		// Point aPosAssign;
865 		// mpImpl->pAssignPB->GetPosSizePixel( aPosAssign, aSizeAssign );
866 		Point aPosAssign = mpImpl->pAssignPB->GetPosPixel();
867 		Point aPosComp = mpImpl->pAssignComponentPB->GetPosPixel();
868 
869 		Point aPosDelete = mpImpl->pDeletePB->GetPosPixel();
870 		long nYDiff = aPosComp.Y() - aPosAssign.Y();
871 		aPosDelete.Y() -= nYDiff;
872 		mpImpl->pDeletePB->SetPosPixel( aPosDelete );
873 
874 		mpImpl->pAssignComponentPB->Hide();
875 		mpImpl->pAssignComponentPB->Disable();
876 	}
877 
878     // must be done after FreeResource is called
879 	InitResources();
880 
881     mpImpl->pEventLB->GetListBox().SetHelpId( HID_SVX_MACRO_LB_EVENT );
882 
883     InitAndSetHandler( xNameReplace, Reference< container::XNameReplace>(0), Reference< util::XModifiable >(0));
884     DisplayAppEvents(true);
885     SvHeaderTabListBox& rListBox = mpImpl->pEventLB->GetListBox();
886     SvLBoxEntry* pE = rListBox.GetEntry( (sal_uLong)nSelectedIndex );
887     if( pE )
888         rListBox.Select(pE);
889 }
890 
891 SvxMacroTabPage::~SvxMacroTabPage()
892 {
893 }
894 
895 SvxMacroAssignDlg::SvxMacroAssignDlg( Window* pParent, const Reference< frame::XFrame >& _rxDocumentFrame, const SfxItemSet& rSet,
896 	const Reference< container::XNameReplace >& xNameReplace, sal_uInt16 nSelectedIndex )
897 		: SvxMacroAssignSingleTabDialog( pParent, rSet, 0 )
898 {
899     SetTabPage( new SvxMacroTabPage( this, _rxDocumentFrame, rSet, xNameReplace, nSelectedIndex ) );
900 }
901 
902 SvxMacroAssignDlg::~SvxMacroAssignDlg()
903 {
904 }
905 
906 
907 //===============================================
908 
909 IMPL_LINK(AssignComponentDialog, ButtonHandler, Button *, EMPTYARG)
910 {
911 	::rtl::OUString aMethodName = maMethodEdit.GetText();
912 	maURL = ::rtl::OUString();
913 	if( aMethodName.getLength() )
914 	{
915 		maURL = aVndSunStarUNO;
916 		maURL += aMethodName;
917 	}
918 	EndDialog(1);
919     return 0;
920 }
921 
922 AssignComponentDialog::AssignComponentDialog( Window * pParent, const ::rtl::OUString& rURL )
923 	: ModalDialog( pParent, CUI_RES( RID_SVXDLG_ASSIGNCOMPONENT ) )
924 	, maMethodLabel( this, CUI_RES( FT_METHOD ) )
925 	, maMethodEdit( this, CUI_RES( EDIT_METHOD ) )
926 	, maOKButton( this, CUI_RES( RID_PB_OK ) )
927 	, maCancelButton( this, CUI_RES( RID_PB_CANCEL ) )
928 	, maHelpButton( this, CUI_RES( RID_PB_HELP ) )
929 	, maURL( rURL )
930 {
931 	FreeResource();
932 	maOKButton.SetClickHdl(LINK(this, AssignComponentDialog, ButtonHandler));
933 
934 	::rtl::OUString aMethodName;
935 	if( maURL.getLength() )
936 	{
937 		sal_Int32 nIndex = maURL.indexOf( aVndSunStarUNO );
938 		if( nIndex == 0 )
939 		{
940 			sal_Int32 nBegin = aVndSunStarUNO.getLength();
941 			aMethodName = maURL.copy( nBegin );
942 		}
943 	}
944 	maMethodEdit.SetText( aMethodName, Selection( 0, SELECTION_MAX ) );
945 }
946 
947 AssignComponentDialog::~AssignComponentDialog()
948 {
949 }
950 
951 // -----------------------------------------------------------------------
952 
953 IMPL_LINK( SvxMacroAssignSingleTabDialog, OKHdl_Impl, Button *, pButton )
954 {
955     (void)pButton; //unused
956 	pPage->FillItemSet( *pOutSet );
957 	EndDialog( RET_OK );
958 	return 0;
959 }
960 
961 // -----------------------------------------------------------------------
962 
963 SvxMacroAssignSingleTabDialog::SvxMacroAssignSingleTabDialog
964 	( Window *pParent, const SfxItemSet& rSet, sal_uInt16 nUniqueId ) :
965 		SfxModalDialog( pParent, nUniqueId, WinBits( WB_STDMODAL | WB_3DLOOK ) ),
966 		pFixedLine      ( 0 ),
967 		pOKBtn          ( 0 ),
968 		pCancelBtn      ( 0 ),
969 		pHelpBtn        ( 0 ),
970 		pPage           ( 0 ),
971 		pOptions        ( &rSet ),
972 		pOutSet         ( 0 )
973 {}
974 
975 
976 // -----------------------------------------------------------------------
977 
978 SvxMacroAssignSingleTabDialog::~SvxMacroAssignSingleTabDialog()
979 {
980 	delete pFixedLine;
981 	delete pOKBtn;
982 	delete pCancelBtn;
983 	delete pHelpBtn;
984 	delete pPage;
985 }
986 
987 // -----------------------------------------------------------------------
988 
989 // According to SfxSingleTabDialog
990 void SvxMacroAssignSingleTabDialog::SetTabPage( SfxTabPage* pTabPage )
991 {
992 	pFixedLine = new FixedLine( this );
993 
994 	pOKBtn = new OKButton( this, WB_DEFBUTTON );
995 	pOKBtn->SetClickHdl( LINK( this, SvxMacroAssignSingleTabDialog, OKHdl_Impl ) );
996 
997 	pCancelBtn = new CancelButton( this );
998 	pHelpBtn = new HelpButton( this );
999 
1000 	pPage = pTabPage;
1001 
1002 	if ( pPage )
1003 	{
1004 		String sUserData;
1005 		pPage->SetUserData( sUserData );
1006 		pPage->Reset( *pOptions );
1007 		pPage->Show();
1008 
1009 		// Set dialog's and buttons' size and position according to tabpage size
1010 		long nSpaceX = LogicToPixel( Size( 6, 0 ), MAP_APPFONT ).Width();
1011 		long nSpaceY = LogicToPixel( Size( 0, 6 ), MAP_APPFONT ).Height();
1012 		long nHalfSpaceX = LogicToPixel( Size( 3, 0 ), MAP_APPFONT ).Width();
1013 		long nHalfSpaceY = LogicToPixel( Size( 0, 3 ), MAP_APPFONT ).Height();
1014 
1015 		pPage->SetPosPixel( Point() );
1016 		Size aTabpageSize( pPage->GetSizePixel() );
1017 		Size aDialogSize( aTabpageSize );
1018 		Size aButtonSize = LogicToPixel( Size( 50, 14 ), MAP_APPFONT );
1019 		long nButtonWidth  = aButtonSize.Width();
1020 		long nButtonHeight = aButtonSize.Height();
1021 
1022 		Size aFixedLineSize( aTabpageSize );
1023 		long nFixedLineHeight = LogicToPixel( Size( 0, 8 ), MAP_APPFONT ).Height();
1024 		aFixedLineSize.Height() = nFixedLineHeight;
1025 
1026 		aDialogSize.Height() += nFixedLineHeight + nButtonHeight + nSpaceY + nHalfSpaceY;
1027 		SetOutputSizePixel( aDialogSize );
1028 
1029 		long nButtonPosY = aTabpageSize.Height() + nFixedLineHeight + nHalfSpaceY;
1030 		long nHelpButtonPosX = nSpaceX;
1031 		pHelpBtn->SetPosSizePixel( Point( nHelpButtonPosX, nButtonPosY), aButtonSize );
1032 		pHelpBtn->Show();
1033 
1034 		long nCancelButtonPosX = aDialogSize.Width() - nButtonWidth - nSpaceX + 1;
1035 		pCancelBtn->SetPosSizePixel( Point( nCancelButtonPosX, nButtonPosY), aButtonSize );
1036 		pCancelBtn->Show();
1037 
1038 		long nOkButtonPosX = nCancelButtonPosX - nButtonWidth - nHalfSpaceX;
1039 		pOKBtn->SetPosSizePixel( Point( nOkButtonPosX, nButtonPosY), aButtonSize );
1040 		pOKBtn->Show();
1041 
1042 		long nFixedLinePosY = aTabpageSize.Height();
1043 		pFixedLine->SetPosSizePixel( Point( 0, nFixedLinePosY), aFixedLineSize );
1044 		pFixedLine->Show();
1045 
1046 		// Get text from TabPage
1047 		SetText( pPage->GetText() );
1048 
1049 		// Get IDs from TabPage
1050 		SetHelpId( pPage->GetHelpId() );
1051 		SetUniqueId( pPage->GetUniqueId() );
1052 	}
1053 }
1054