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