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
10*2ee96f1cSAndrew Rist *
11*2ee96f1cSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*2ee96f1cSAndrew Rist *
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.
19*2ee96f1cSAndrew Rist *
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
27cdf0e10cSrcweir #define ITEMID_MACRO 0
28cdf0e10cSrcweir #include <svl/macitem.hxx>
29cdf0e10cSrcweir #undef ITEMID_MACRO
30cdf0e10cSrcweir
31cdf0e10cSrcweir #include "macroass.hxx"
32cdf0e10cSrcweir
33cdf0e10cSrcweir #include <basic/basmgr.hxx>
34cdf0e10cSrcweir #include <dialmgr.hxx>
35cdf0e10cSrcweir #include <svx/dialogs.hrc>
36cdf0e10cSrcweir #define _SVSTDARR_STRINGSDTOR
37cdf0e10cSrcweir #include <svl/svstdarr.hxx>
38cdf0e10cSrcweir
39cdf0e10cSrcweir #include <svtools/svmedit.hxx>
40cdf0e10cSrcweir #include "cfgutil.hxx"
41cdf0e10cSrcweir #include <sfx2/app.hxx>
42cdf0e10cSrcweir #include <sfx2/evntconf.hxx>
43cdf0e10cSrcweir #include <sfx2/objsh.hxx>
44cdf0e10cSrcweir #include "macroass.hrc"
45cdf0e10cSrcweir #include "cuires.hrc"
46cdf0e10cSrcweir #include <vcl/fixed.hxx>
47cdf0e10cSrcweir #include "headertablistbox.hxx"
48cdf0e10cSrcweir
49cdf0e10cSrcweir using ::com::sun::star::uno::Reference;
50cdf0e10cSrcweir using ::com::sun::star::frame::XFrame;
51cdf0e10cSrcweir
52cdf0e10cSrcweir class _SfxMacroTabPage_Impl
53cdf0e10cSrcweir {
54cdf0e10cSrcweir public:
55cdf0e10cSrcweir _SfxMacroTabPage_Impl( void );
56cdf0e10cSrcweir ~_SfxMacroTabPage_Impl();
57cdf0e10cSrcweir
58cdf0e10cSrcweir String maStaticMacroLBLabel;
59cdf0e10cSrcweir PushButton* pAssignPB;
60cdf0e10cSrcweir PushButton* pDeletePB;
61cdf0e10cSrcweir String* pStrEvent;
62cdf0e10cSrcweir String* pAssignedMacro;
63cdf0e10cSrcweir _HeaderTabListBox* pEventLB;
64cdf0e10cSrcweir SfxConfigGroupListBox_Impl* pGroupLB;
65cdf0e10cSrcweir FixedText* pFT_MacroLBLabel;
66cdf0e10cSrcweir SfxConfigFunctionListBox_Impl* pMacroLB;
67cdf0e10cSrcweir
68cdf0e10cSrcweir FixedText* pMacroFT;
69cdf0e10cSrcweir String* pMacroStr;
70cdf0e10cSrcweir
71cdf0e10cSrcweir sal_Bool bReadOnly;
72cdf0e10cSrcweir Timer maFillGroupTimer;
73cdf0e10cSrcweir sal_Bool bGotEvents;
74cdf0e10cSrcweir };
75cdf0e10cSrcweir
_SfxMacroTabPage_Impl(void)76cdf0e10cSrcweir _SfxMacroTabPage_Impl::_SfxMacroTabPage_Impl( void ) :
77cdf0e10cSrcweir pAssignPB( NULL ),
78cdf0e10cSrcweir pDeletePB( NULL ),
79cdf0e10cSrcweir pStrEvent( NULL ),
80cdf0e10cSrcweir pAssignedMacro( NULL ),
81cdf0e10cSrcweir pEventLB( NULL ),
82cdf0e10cSrcweir pGroupLB( NULL ),
83cdf0e10cSrcweir pFT_MacroLBLabel( NULL ),
84cdf0e10cSrcweir pMacroLB( NULL ),
85cdf0e10cSrcweir pMacroFT( NULL ),
86cdf0e10cSrcweir pMacroStr( NULL ),
87cdf0e10cSrcweir bReadOnly( sal_False ),
88cdf0e10cSrcweir bGotEvents( sal_False )
89cdf0e10cSrcweir {
90cdf0e10cSrcweir }
91cdf0e10cSrcweir
~_SfxMacroTabPage_Impl()92cdf0e10cSrcweir _SfxMacroTabPage_Impl::~_SfxMacroTabPage_Impl()
93cdf0e10cSrcweir {
94cdf0e10cSrcweir delete pAssignPB;
95cdf0e10cSrcweir delete pDeletePB;
96cdf0e10cSrcweir delete pStrEvent;
97cdf0e10cSrcweir delete pAssignedMacro;
98cdf0e10cSrcweir delete pEventLB;
99cdf0e10cSrcweir delete pGroupLB;
100cdf0e10cSrcweir delete pMacroLB;
101cdf0e10cSrcweir delete pFT_MacroLBLabel;
102cdf0e10cSrcweir delete pMacroFT;
103cdf0e10cSrcweir delete pMacroStr;
104cdf0e10cSrcweir }
105cdf0e10cSrcweir
106cdf0e10cSrcweir
107cdf0e10cSrcweir static sal_uInt16 __FAR_DATA aPageRg[] = {
108cdf0e10cSrcweir SID_ATTR_MACROITEM, SID_ATTR_MACROITEM,
109cdf0e10cSrcweir 0
110cdf0e10cSrcweir };
111cdf0e10cSrcweir
112cdf0e10cSrcweir // Achtung im Code wird dieses Array direkt (0, 1, ...) indiziert
113cdf0e10cSrcweir static long nTabs[] =
114cdf0e10cSrcweir {
115cdf0e10cSrcweir 2, // Number of Tabs
116cdf0e10cSrcweir 0, 90
117cdf0e10cSrcweir };
118cdf0e10cSrcweir
119cdf0e10cSrcweir #define TAB_WIDTH_MIN 10
120cdf0e10cSrcweir
121cdf0e10cSrcweir // IDs for items in HeaderBar of EventLB
122cdf0e10cSrcweir #define ITEMID_EVENT 1
123cdf0e10cSrcweir #define ITMEID_ASSMACRO 2
124cdf0e10cSrcweir
125cdf0e10cSrcweir
126cdf0e10cSrcweir #define LB_EVENTS_ITEMPOS 1
127cdf0e10cSrcweir #define LB_MACROS_ITEMPOS 2
128cdf0e10cSrcweir
ConvertToUIName_Impl(SvxMacro * pMacro)129cdf0e10cSrcweir String ConvertToUIName_Impl( SvxMacro *pMacro )
130cdf0e10cSrcweir {
131cdf0e10cSrcweir String aName( pMacro->GetMacName() );
132cdf0e10cSrcweir String aEntry;
133cdf0e10cSrcweir if ( ! pMacro->GetLanguage().EqualsAscii("JavaScript") )
134cdf0e10cSrcweir {
135cdf0e10cSrcweir sal_uInt16 nCount = aName.GetTokenCount('.');
136cdf0e10cSrcweir aEntry = aName.GetToken( nCount-1, '.' );
137cdf0e10cSrcweir if ( nCount > 2 )
138cdf0e10cSrcweir {
139cdf0e10cSrcweir aEntry += '(';
140cdf0e10cSrcweir aEntry += aName.GetToken( 0, '.' );
141cdf0e10cSrcweir aEntry += '.';
142cdf0e10cSrcweir aEntry += aName.GetToken( nCount-2, '.' );
143cdf0e10cSrcweir aEntry += ')';
144cdf0e10cSrcweir }
145cdf0e10cSrcweir return aEntry;
146cdf0e10cSrcweir }
147cdf0e10cSrcweir else
148cdf0e10cSrcweir return aName;
149cdf0e10cSrcweir }
150cdf0e10cSrcweir
EnableButtons()151cdf0e10cSrcweir void _SfxMacroTabPage::EnableButtons()
152cdf0e10cSrcweir {
153cdf0e10cSrcweir // Solange die Eventbox leer ist, nichts tun
154cdf0e10cSrcweir const SvLBoxEntry* pE = mpImpl->pEventLB->GetListBox().FirstSelected();
155cdf0e10cSrcweir if ( pE )
156cdf0e10cSrcweir {
157cdf0e10cSrcweir // Gebundenes Macro holen
158cdf0e10cSrcweir const SvxMacro* pM = aTbl.Get( (sal_uInt16)(sal_uLong) pE->GetUserData() );
159cdf0e10cSrcweir mpImpl->pDeletePB->Enable( 0 != pM && !mpImpl->bReadOnly );
160cdf0e10cSrcweir
161cdf0e10cSrcweir String sEventMacro;
162cdf0e10cSrcweir sEventMacro = ((SvLBoxString*)pE->GetItem( LB_MACROS_ITEMPOS ))->GetText();
163cdf0e10cSrcweir
164cdf0e10cSrcweir String sScriptURI = mpImpl->pMacroLB->GetSelectedScriptURI();
165cdf0e10cSrcweir mpImpl->pAssignPB->Enable( !mpImpl->bReadOnly && !sScriptURI.EqualsIgnoreCaseAscii( sEventMacro ) );
166cdf0e10cSrcweir }
167cdf0e10cSrcweir else
168cdf0e10cSrcweir mpImpl->pAssignPB->Enable( sal_False );
169cdf0e10cSrcweir }
170cdf0e10cSrcweir
_SfxMacroTabPage(Window * pParent,const ResId & rResId,const SfxItemSet & rAttrSet)171cdf0e10cSrcweir _SfxMacroTabPage::_SfxMacroTabPage( Window* pParent, const ResId& rResId, const SfxItemSet& rAttrSet )
172cdf0e10cSrcweir : SfxTabPage( pParent, rResId, rAttrSet )
173cdf0e10cSrcweir
174cdf0e10cSrcweir {
175cdf0e10cSrcweir mpImpl = new _SfxMacroTabPage_Impl;
176cdf0e10cSrcweir }
177cdf0e10cSrcweir
~_SfxMacroTabPage()178cdf0e10cSrcweir _SfxMacroTabPage::~_SfxMacroTabPage()
179cdf0e10cSrcweir {
180cdf0e10cSrcweir DELETEZ( mpImpl );
181cdf0e10cSrcweir }
182cdf0e10cSrcweir
AddEvent(const String & rEventName,sal_uInt16 nEventId)183cdf0e10cSrcweir void _SfxMacroTabPage::AddEvent( const String & rEventName, sal_uInt16 nEventId )
184cdf0e10cSrcweir {
185cdf0e10cSrcweir String sTmp( rEventName );
186cdf0e10cSrcweir sTmp += '\t';
187cdf0e10cSrcweir
188cdf0e10cSrcweir // falls die Tabelle schon gueltig ist
189cdf0e10cSrcweir SvxMacro* pM = aTbl.Get( nEventId );
190cdf0e10cSrcweir if( pM )
191cdf0e10cSrcweir {
192cdf0e10cSrcweir String sNew( ConvertToUIName_Impl( pM ) );
193cdf0e10cSrcweir sTmp += sNew;
194cdf0e10cSrcweir }
195cdf0e10cSrcweir
196cdf0e10cSrcweir SvLBoxEntry* pE = mpImpl->pEventLB->GetListBox().InsertEntry( sTmp );
197cdf0e10cSrcweir pE->SetUserData( reinterpret_cast< void* >( sal::static_int_cast< sal_IntPtr >( nEventId )) );
198cdf0e10cSrcweir }
199cdf0e10cSrcweir
ScriptChanged()200cdf0e10cSrcweir void _SfxMacroTabPage::ScriptChanged()
201cdf0e10cSrcweir {
202cdf0e10cSrcweir // neue Bereiche und deren Funktionen besorgen
203cdf0e10cSrcweir {
204cdf0e10cSrcweir mpImpl->pGroupLB->Show();
205cdf0e10cSrcweir mpImpl->pMacroLB->Show();
206cdf0e10cSrcweir mpImpl->pMacroFT->SetText( *mpImpl->pMacroStr );
207cdf0e10cSrcweir }
208cdf0e10cSrcweir
209cdf0e10cSrcweir EnableButtons();
210cdf0e10cSrcweir }
211cdf0e10cSrcweir
FillItemSet(SfxItemSet & rSet)212cdf0e10cSrcweir sal_Bool _SfxMacroTabPage::FillItemSet( SfxItemSet& rSet )
213cdf0e10cSrcweir {
214cdf0e10cSrcweir SvxMacroItem aItem( GetWhich( aPageRg[0] ) );
215cdf0e10cSrcweir ((SvxMacroTableDtor&)aItem.GetMacroTable()) = aTbl;
216cdf0e10cSrcweir
217cdf0e10cSrcweir const SfxPoolItem* pItem;
218cdf0e10cSrcweir if( SFX_ITEM_SET != GetItemSet().GetItemState( aItem.Which(), sal_True, &pItem )
219cdf0e10cSrcweir || aItem != *(SvxMacroItem*)pItem )
220cdf0e10cSrcweir {
221cdf0e10cSrcweir rSet.Put( aItem );
222cdf0e10cSrcweir return sal_True;
223cdf0e10cSrcweir }
224cdf0e10cSrcweir return sal_False;
225cdf0e10cSrcweir }
226cdf0e10cSrcweir
PageCreated(SfxAllItemSet aSet)227cdf0e10cSrcweir void _SfxMacroTabPage::PageCreated (SfxAllItemSet aSet)
228cdf0e10cSrcweir {
229cdf0e10cSrcweir const SfxPoolItem* pEventsItem;
230cdf0e10cSrcweir if( !mpImpl->bGotEvents && SFX_ITEM_SET == aSet.GetItemState( SID_EVENTCONFIG, sal_True, &pEventsItem ) )
231cdf0e10cSrcweir {
232cdf0e10cSrcweir mpImpl->bGotEvents = sal_True;
233cdf0e10cSrcweir const SfxEventNamesList& rList = ((SfxEventNamesItem*)pEventsItem)->GetEvents();
234cdf0e10cSrcweir for ( sal_uInt16 nNo = 0; nNo < rList.Count(); ++nNo )
235cdf0e10cSrcweir {
236cdf0e10cSrcweir const SfxEventName *pOwn = rList.GetObject(nNo);
237cdf0e10cSrcweir AddEvent( pOwn->maUIName, pOwn->mnId );
238cdf0e10cSrcweir }
239cdf0e10cSrcweir }
240cdf0e10cSrcweir }
241cdf0e10cSrcweir
Reset(const SfxItemSet & rSet)242cdf0e10cSrcweir void _SfxMacroTabPage::Reset( const SfxItemSet& rSet )
243cdf0e10cSrcweir {
244cdf0e10cSrcweir const SfxPoolItem* pItem;
245cdf0e10cSrcweir if( SFX_ITEM_SET == rSet.GetItemState( GetWhich( aPageRg[0] ), sal_True, &pItem ))
246cdf0e10cSrcweir aTbl = ((SvxMacroItem*)pItem)->GetMacroTable();
247cdf0e10cSrcweir
248cdf0e10cSrcweir const SfxPoolItem* pEventsItem;
249cdf0e10cSrcweir if( !mpImpl->bGotEvents && SFX_ITEM_SET == rSet.GetItemState( SID_EVENTCONFIG, sal_True, &pEventsItem ) )
250cdf0e10cSrcweir {
251cdf0e10cSrcweir mpImpl->bGotEvents = sal_True;
252cdf0e10cSrcweir const SfxEventNamesList& rList = ((SfxEventNamesItem*)pEventsItem)->GetEvents();
253cdf0e10cSrcweir for ( sal_uInt16 nNo = 0; nNo < rList.Count(); ++nNo )
254cdf0e10cSrcweir {
255cdf0e10cSrcweir const SfxEventName *pOwn = rList.GetObject(nNo);
256cdf0e10cSrcweir AddEvent( pOwn->maUIName, pOwn->mnId );
257cdf0e10cSrcweir }
258cdf0e10cSrcweir }
259cdf0e10cSrcweir
260cdf0e10cSrcweir FillEvents();
261cdf0e10cSrcweir
262cdf0e10cSrcweir SvHeaderTabListBox& rListBox = mpImpl->pEventLB->GetListBox();
263cdf0e10cSrcweir SvLBoxEntry* pE = rListBox.GetEntry( 0 );
264cdf0e10cSrcweir if( pE )
265cdf0e10cSrcweir rListBox.SetCurEntry( pE );
266cdf0e10cSrcweir }
267cdf0e10cSrcweir
IsReadOnly() const268cdf0e10cSrcweir sal_Bool _SfxMacroTabPage::IsReadOnly() const
269cdf0e10cSrcweir {
270cdf0e10cSrcweir return mpImpl->bReadOnly;
271cdf0e10cSrcweir }
272cdf0e10cSrcweir
IMPL_STATIC_LINK(_SfxMacroTabPage,SelectEvent_Impl,SvTabListBox *,EMPTYARG)273cdf0e10cSrcweir IMPL_STATIC_LINK( _SfxMacroTabPage, SelectEvent_Impl, SvTabListBox*, EMPTYARG )
274cdf0e10cSrcweir {
275cdf0e10cSrcweir _SfxMacroTabPage_Impl* pImpl = pThis->mpImpl;
276cdf0e10cSrcweir SvHeaderTabListBox& rListBox = pImpl->pEventLB->GetListBox();
277cdf0e10cSrcweir SvLBoxEntry* pE = rListBox.FirstSelected();
278cdf0e10cSrcweir sal_uLong nPos;
279cdf0e10cSrcweir if( !pE || LISTBOX_ENTRY_NOTFOUND ==
280cdf0e10cSrcweir ( nPos = rListBox.GetModel()->GetAbsPos( pE ) ) )
281cdf0e10cSrcweir {
282cdf0e10cSrcweir DBG_ASSERT( pE, "wo kommt der leere Eintrag her?" );
283cdf0e10cSrcweir return 0;
284cdf0e10cSrcweir }
285cdf0e10cSrcweir
286cdf0e10cSrcweir pThis->ScriptChanged();
287cdf0e10cSrcweir pThis->EnableButtons();
288cdf0e10cSrcweir return 0;
289cdf0e10cSrcweir }
290cdf0e10cSrcweir
IMPL_STATIC_LINK(_SfxMacroTabPage,SelectGroup_Impl,ListBox *,EMPTYARG)291cdf0e10cSrcweir IMPL_STATIC_LINK( _SfxMacroTabPage, SelectGroup_Impl, ListBox*, EMPTYARG )
292cdf0e10cSrcweir {
293cdf0e10cSrcweir _SfxMacroTabPage_Impl* pImpl = pThis->mpImpl;
294cdf0e10cSrcweir String sSel( pImpl->pGroupLB->GetGroup() );
295cdf0e10cSrcweir pImpl->pGroupLB->GroupSelected();
296cdf0e10cSrcweir const String sScriptURI = pImpl->pMacroLB->GetSelectedScriptURI();
297cdf0e10cSrcweir String aLabelText;
298cdf0e10cSrcweir if( sScriptURI.Len() > 0 )
299cdf0e10cSrcweir aLabelText = pImpl->maStaticMacroLBLabel;
300cdf0e10cSrcweir pImpl->pFT_MacroLBLabel->SetText( aLabelText );
301cdf0e10cSrcweir
302cdf0e10cSrcweir pThis->EnableButtons();
303cdf0e10cSrcweir return 0;
304cdf0e10cSrcweir }
305cdf0e10cSrcweir
IMPL_STATIC_LINK(_SfxMacroTabPage,SelectMacro_Impl,ListBox *,EMPTYARG)306cdf0e10cSrcweir IMPL_STATIC_LINK( _SfxMacroTabPage, SelectMacro_Impl, ListBox*, EMPTYARG )
307cdf0e10cSrcweir {
308cdf0e10cSrcweir _SfxMacroTabPage_Impl* pImpl = pThis->mpImpl;
309cdf0e10cSrcweir pImpl->pMacroLB->FunctionSelected();
310cdf0e10cSrcweir pThis->EnableButtons();
311cdf0e10cSrcweir return 0;
312cdf0e10cSrcweir }
313cdf0e10cSrcweir
IMPL_STATIC_LINK(_SfxMacroTabPage,AssignDeleteHdl_Impl,PushButton *,pBtn)314cdf0e10cSrcweir IMPL_STATIC_LINK( _SfxMacroTabPage, AssignDeleteHdl_Impl, PushButton*, pBtn )
315cdf0e10cSrcweir {
316cdf0e10cSrcweir _SfxMacroTabPage_Impl* pImpl = pThis->mpImpl;
317cdf0e10cSrcweir SvHeaderTabListBox& rListBox = pImpl->pEventLB->GetListBox();
318cdf0e10cSrcweir SvLBoxEntry* pE = rListBox.FirstSelected();
319cdf0e10cSrcweir sal_uLong nPos;
320cdf0e10cSrcweir if( !pE || LISTBOX_ENTRY_NOTFOUND ==
321cdf0e10cSrcweir ( nPos = rListBox.GetModel()->GetAbsPos( pE ) ) )
322cdf0e10cSrcweir {
323cdf0e10cSrcweir DBG_ASSERT( pE, "wo kommt der leere Eintrag her?" );
324cdf0e10cSrcweir return 0;
325cdf0e10cSrcweir }
326cdf0e10cSrcweir
327cdf0e10cSrcweir const sal_Bool bAssEnabled = pBtn != pImpl->pDeletePB && pImpl->pAssignPB->IsEnabled();
328cdf0e10cSrcweir
329cdf0e10cSrcweir // aus der Tabelle entfernen
330cdf0e10cSrcweir sal_uInt16 nEvent = (sal_uInt16)(sal_uLong)pE->GetUserData();
331cdf0e10cSrcweir SvxMacro *pRemoveMacro = pThis->aTbl.Remove( nEvent );
332cdf0e10cSrcweir delete pRemoveMacro;
333cdf0e10cSrcweir
334cdf0e10cSrcweir String sScriptURI;
335cdf0e10cSrcweir if( bAssEnabled )
336cdf0e10cSrcweir {
337cdf0e10cSrcweir sScriptURI = pImpl->pMacroLB->GetSelectedScriptURI();
338cdf0e10cSrcweir if( sScriptURI.CompareToAscii( "vnd.sun.star.script:", 20 ) == COMPARE_EQUAL )
339cdf0e10cSrcweir {
340cdf0e10cSrcweir pThis->aTbl.Insert(
341cdf0e10cSrcweir nEvent, new SvxMacro( sScriptURI, String::CreateFromAscii( SVX_MACRO_LANGUAGE_SF ) ) );
342cdf0e10cSrcweir }
343cdf0e10cSrcweir else
344cdf0e10cSrcweir {
345cdf0e10cSrcweir OSL_ENSURE( false, "_SfxMacroTabPage::AssignDeleteHdl_Impl: this branch is *not* dead? (out of interest: tell fs, please!)" );
346cdf0e10cSrcweir pThis->aTbl.Insert(
347cdf0e10cSrcweir nEvent, new SvxMacro( sScriptURI, String::CreateFromAscii( SVX_MACRO_LANGUAGE_STARBASIC ) ) );
348cdf0e10cSrcweir }
349cdf0e10cSrcweir }
350cdf0e10cSrcweir
351cdf0e10cSrcweir pImpl->pEventLB->SetUpdateMode( sal_False );
352cdf0e10cSrcweir pE->ReplaceItem( new SvLBoxString( pE, 0, sScriptURI ), LB_MACROS_ITEMPOS );
353cdf0e10cSrcweir rListBox.GetModel()->InvalidateEntry( pE );
354cdf0e10cSrcweir rListBox.Select( pE );
355cdf0e10cSrcweir rListBox.MakeVisible( pE );
356cdf0e10cSrcweir rListBox.SetUpdateMode( sal_True );
357cdf0e10cSrcweir
358cdf0e10cSrcweir pThis->EnableButtons();
359cdf0e10cSrcweir return 0;
360cdf0e10cSrcweir }
361cdf0e10cSrcweir
IMPL_STATIC_LINK(_SfxMacroTabPage,TimeOut_Impl,Timer *,EMPTYARG)362cdf0e10cSrcweir IMPL_STATIC_LINK( _SfxMacroTabPage, TimeOut_Impl, Timer*, EMPTYARG )
363cdf0e10cSrcweir {
364cdf0e10cSrcweir // FillMacroList() can take a long time -> show wait cursor and disable input
365cdf0e10cSrcweir SfxTabDialog* pTabDlg = pThis->GetTabDialog();
366cdf0e10cSrcweir // perhaps the tabpage is part of a SingleTabDialog then pTabDlg == NULL
367cdf0e10cSrcweir if ( pTabDlg )
368cdf0e10cSrcweir {
369cdf0e10cSrcweir pTabDlg->EnterWait();
370cdf0e10cSrcweir pTabDlg->EnableInput( sal_False );
371cdf0e10cSrcweir }
372cdf0e10cSrcweir pThis->FillMacroList();
373cdf0e10cSrcweir if ( pTabDlg )
374cdf0e10cSrcweir {
375cdf0e10cSrcweir pTabDlg->EnableInput( sal_True );
376cdf0e10cSrcweir pTabDlg->LeaveWait();
377cdf0e10cSrcweir }
378cdf0e10cSrcweir return 0;
379cdf0e10cSrcweir }
380cdf0e10cSrcweir
InitAndSetHandler()381cdf0e10cSrcweir void _SfxMacroTabPage::InitAndSetHandler()
382cdf0e10cSrcweir {
383cdf0e10cSrcweir // Handler installieren
384cdf0e10cSrcweir SvHeaderTabListBox& rListBox = mpImpl->pEventLB->GetListBox();
385cdf0e10cSrcweir HeaderBar& rHeaderBar = mpImpl->pEventLB->GetHeaderBar();
386cdf0e10cSrcweir Link aLnk(STATIC_LINK(this, _SfxMacroTabPage, AssignDeleteHdl_Impl ));
387cdf0e10cSrcweir mpImpl->pMacroLB->SetDoubleClickHdl( aLnk );
388cdf0e10cSrcweir mpImpl->pDeletePB->SetClickHdl( aLnk );
389cdf0e10cSrcweir mpImpl->pAssignPB->SetClickHdl( aLnk );
390cdf0e10cSrcweir rListBox.SetDoubleClickHdl( aLnk );
391cdf0e10cSrcweir
392cdf0e10cSrcweir rListBox.SetSelectHdl( STATIC_LINK( this, _SfxMacroTabPage, SelectEvent_Impl ));
393cdf0e10cSrcweir mpImpl->pGroupLB->SetSelectHdl( STATIC_LINK( this, _SfxMacroTabPage, SelectGroup_Impl ));
394cdf0e10cSrcweir mpImpl->pMacroLB->SetSelectHdl( STATIC_LINK( this, _SfxMacroTabPage, SelectMacro_Impl ));
395cdf0e10cSrcweir
396cdf0e10cSrcweir rListBox.SetSelectionMode( SINGLE_SELECTION );
397cdf0e10cSrcweir rListBox.SetTabs( &nTabs[0], MAP_APPFONT );
398cdf0e10cSrcweir Size aSize( nTabs[ 2 ], 0 );
399cdf0e10cSrcweir rHeaderBar.InsertItem( ITEMID_EVENT, *mpImpl->pStrEvent, LogicToPixel( aSize, MapMode( MAP_APPFONT ) ).Width() );
400cdf0e10cSrcweir aSize.Width() = 1764; // don't know what, so 42^2 is best to use...
401cdf0e10cSrcweir rHeaderBar.InsertItem( ITMEID_ASSMACRO, *mpImpl->pAssignedMacro, LogicToPixel( aSize, MapMode( MAP_APPFONT ) ).Width() );
402cdf0e10cSrcweir rListBox.SetSpaceBetweenEntries( 0 );
403cdf0e10cSrcweir
404cdf0e10cSrcweir mpImpl->pEventLB->Show();
405cdf0e10cSrcweir mpImpl->pEventLB->ConnectElements();
406cdf0e10cSrcweir
407cdf0e10cSrcweir mpImpl->pEventLB->Enable( sal_True );
408cdf0e10cSrcweir mpImpl->pGroupLB->Enable( sal_True );
409cdf0e10cSrcweir mpImpl->pMacroLB->Enable( sal_True );
410cdf0e10cSrcweir
411cdf0e10cSrcweir mpImpl->pGroupLB->SetFunctionListBox( mpImpl->pMacroLB );
412cdf0e10cSrcweir
413cdf0e10cSrcweir mpImpl->maFillGroupTimer.SetTimeoutHdl( STATIC_LINK( this, _SfxMacroTabPage, TimeOut_Impl ) );
414cdf0e10cSrcweir mpImpl->maFillGroupTimer.SetTimeout( 0 );
415cdf0e10cSrcweir mpImpl->maFillGroupTimer.Start();
416cdf0e10cSrcweir }
417cdf0e10cSrcweir
FillMacroList()418cdf0e10cSrcweir void _SfxMacroTabPage::FillMacroList()
419cdf0e10cSrcweir {
420cdf0e10cSrcweir mpImpl->pGroupLB->Init(
421cdf0e10cSrcweir ::com::sun::star::uno::Reference<
422cdf0e10cSrcweir ::com::sun::star::lang::XMultiServiceFactory >(),
423cdf0e10cSrcweir GetFrame(),
424cdf0e10cSrcweir ::rtl::OUString() );
425cdf0e10cSrcweir }
426cdf0e10cSrcweir
FillEvents()427cdf0e10cSrcweir void _SfxMacroTabPage::FillEvents()
428cdf0e10cSrcweir {
429cdf0e10cSrcweir SvHeaderTabListBox& rListBox = mpImpl->pEventLB->GetListBox();
430cdf0e10cSrcweir
431cdf0e10cSrcweir sal_uLong nEntryCnt = rListBox.GetEntryCount();
432cdf0e10cSrcweir
433cdf0e10cSrcweir // Events aus der Tabelle holen und die EventListBox entsprechen fuellen
434cdf0e10cSrcweir for( sal_uLong n = 0 ; n < nEntryCnt ; ++n )
435cdf0e10cSrcweir {
436cdf0e10cSrcweir SvLBoxEntry* pE = rListBox.GetEntry( n );
437cdf0e10cSrcweir if( pE )
438cdf0e10cSrcweir {
439cdf0e10cSrcweir SvLBoxString* pLItem = ( SvLBoxString* ) pE->GetItem( LB_MACROS_ITEMPOS );
440cdf0e10cSrcweir DBG_ASSERT( pLItem && SV_ITEM_ID_LBOXSTRING == pLItem->IsA(), "_SfxMacroTabPage::FillEvents(): no LBoxString" );
441cdf0e10cSrcweir
442cdf0e10cSrcweir String sOld( pLItem->GetText() );
443cdf0e10cSrcweir String sNew;
444cdf0e10cSrcweir sal_uInt16 nEventId = ( sal_uInt16 ) ( sal_uLong ) pE->GetUserData();
445cdf0e10cSrcweir if( aTbl.IsKeyValid( nEventId ) )
446cdf0e10cSrcweir sNew = ConvertToUIName_Impl( aTbl.Get( nEventId ) );
447cdf0e10cSrcweir
448cdf0e10cSrcweir if( sOld != sNew )
449cdf0e10cSrcweir {
450cdf0e10cSrcweir pE->ReplaceItem( new SvLBoxString( pE, 0, sNew ), LB_MACROS_ITEMPOS );
451cdf0e10cSrcweir rListBox.GetModel()->InvalidateEntry( pE );
452cdf0e10cSrcweir }
453cdf0e10cSrcweir }
454cdf0e10cSrcweir }
455cdf0e10cSrcweir }
456cdf0e10cSrcweir
SfxMacroTabPage(Window * pParent,const ResId & rResId,const Reference<XFrame> & rxDocumentFrame,const SfxItemSet & rSet)457cdf0e10cSrcweir SfxMacroTabPage::SfxMacroTabPage( Window* pParent, const ResId& rResId, const Reference< XFrame >& rxDocumentFrame, const SfxItemSet& rSet )
458cdf0e10cSrcweir : _SfxMacroTabPage( pParent, rResId, rSet )
459cdf0e10cSrcweir {
460cdf0e10cSrcweir mpImpl->pStrEvent = new String( CUI_RES( STR_EVENT ) );
461cdf0e10cSrcweir mpImpl->pAssignedMacro = new String( CUI_RES( STR_ASSMACRO ) );
462cdf0e10cSrcweir mpImpl->pEventLB = new _HeaderTabListBox( this, CUI_RES( LB_EVENT ) );
463cdf0e10cSrcweir mpImpl->pAssignPB = new PushButton( this, CUI_RES( PB_ASSIGN ) );
464cdf0e10cSrcweir mpImpl->pDeletePB = new PushButton( this, CUI_RES( PB_DELETE ) );
465cdf0e10cSrcweir mpImpl->pMacroFT = new FixedText( this, CUI_RES( FT_MACRO ) );
466cdf0e10cSrcweir mpImpl->pGroupLB = new SfxConfigGroupListBox_Impl( this, CUI_RES( LB_GROUP ) );
467cdf0e10cSrcweir mpImpl->pFT_MacroLBLabel = new FixedText( this, CUI_RES( FT_LABEL4LB_MACROS ) );
468cdf0e10cSrcweir mpImpl->maStaticMacroLBLabel= mpImpl->pFT_MacroLBLabel->GetText();
469cdf0e10cSrcweir mpImpl->pMacroLB = new SfxConfigFunctionListBox_Impl( this, CUI_RES( LB_MACROS ) );
470cdf0e10cSrcweir mpImpl->pMacroStr = new String( CUI_RES( STR_MACROS ) );
471cdf0e10cSrcweir
472cdf0e10cSrcweir FreeResource();
473cdf0e10cSrcweir
474cdf0e10cSrcweir SetFrame( rxDocumentFrame );
475cdf0e10cSrcweir
476cdf0e10cSrcweir InitAndSetHandler();
477cdf0e10cSrcweir
478cdf0e10cSrcweir ScriptChanged();
479cdf0e10cSrcweir }
480cdf0e10cSrcweir
Create(Window * pParent,const SfxItemSet & rAttrSet)481cdf0e10cSrcweir SfxTabPage* SfxMacroTabPage::Create( Window* pParent, const SfxItemSet& rAttrSet )
482cdf0e10cSrcweir {
483cdf0e10cSrcweir return new SfxMacroTabPage( pParent, CUI_RES( RID_SVXPAGE_EVENTASSIGN ), NULL, rAttrSet );
484cdf0e10cSrcweir }
485cdf0e10cSrcweir
SfxMacroAssignDlg(Window * pParent,const Reference<XFrame> & rxDocumentFrame,const SfxItemSet & rSet)486cdf0e10cSrcweir SfxMacroAssignDlg::SfxMacroAssignDlg( Window* pParent, const Reference< XFrame >& rxDocumentFrame, const SfxItemSet& rSet )
487cdf0e10cSrcweir : SfxSingleTabDialog( pParent, rSet, 0 )
488cdf0e10cSrcweir {
489cdf0e10cSrcweir SfxTabPage* pPage = SfxMacroTabPage::Create( this, rSet );
490cdf0e10cSrcweir pPage->SetFrame( rxDocumentFrame );
491cdf0e10cSrcweir SetTabPage( pPage );
492cdf0e10cSrcweir }
493cdf0e10cSrcweir
~SfxMacroAssignDlg()494cdf0e10cSrcweir SfxMacroAssignDlg::~SfxMacroAssignDlg()
495cdf0e10cSrcweir {
496cdf0e10cSrcweir }
497cdf0e10cSrcweir
498cdf0e10cSrcweir
499