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