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