merge the formfield patch from ooo-build
[ooovba.git] / svx / source / cui / macroass.cxx
blobed8f8a46f374ebe2aba969795393beea41ac80d5
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: macropg.cxx,v $
10 * $Revision: 1.21 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svx.hxx"
34 #define ITEMID_MACRO 0
35 #include <svtools/macitem.hxx>
36 #undef ITEMID_MACRO
38 #include "macroass.hxx"
40 #include <basic/basmgr.hxx>
41 #include <svx/dialmgr.hxx>
43 #define _SVSTDARR_STRINGSDTOR
44 #include <svtools/svstdarr.hxx>
46 #include <svtools/svmedit.hxx>
47 #include "cfgutil.hxx"
48 #include <sfx2/app.hxx>
49 #include <sfx2/objsh.hxx>
50 #include "macroass.hrc"
51 #include "svx/dialogs.hrc"
52 #include <sfx2/macrconf.hxx>
53 #include "headertablistbox.hxx"
55 using ::com::sun::star::uno::Reference;
56 using ::com::sun::star::frame::XFrame;
58 class _SfxMacroTabPage_Impl
60 public:
61 _SfxMacroTabPage_Impl( void );
62 ~_SfxMacroTabPage_Impl();
64 String maStaticMacroLBLabel;
65 PushButton* pAssignPB;
66 PushButton* pDeletePB;
67 String* pStrEvent;
68 String* pAssignedMacro;
69 ListBox* pScriptTypeLB;
70 _HeaderTabListBox* pEventLB;
71 SfxConfigGroupListBox_Impl* pGroupLB;
72 FixedText* pFT_MacroLBLabel;
73 SfxConfigFunctionListBox_Impl* pMacroLB;
75 FixedText* pMacroFT;
76 String* pMacroStr;
77 FNGetRangeHdl fnGetRange;
78 FNGetMacrosOfRangeHdl fnGetMacroOfRange;
80 BOOL bReadOnly;
81 Timer maFillGroupTimer;
82 BOOL bGotEvents;
85 _SfxMacroTabPage_Impl::_SfxMacroTabPage_Impl( void ) :
86 pAssignPB( NULL ),
87 pDeletePB( NULL ),
88 pStrEvent( NULL ),
89 pAssignedMacro( NULL ),
90 pScriptTypeLB( NULL ),
91 pEventLB( NULL ),
92 pGroupLB( NULL ),
93 pFT_MacroLBLabel( NULL ),
94 pMacroLB( NULL ),
95 pMacroFT( NULL ),
96 pMacroStr( NULL ),
97 fnGetRange( NULL ),
98 fnGetMacroOfRange( NULL ),
99 bReadOnly( FALSE ),
100 bGotEvents( FALSE )
104 _SfxMacroTabPage_Impl::~_SfxMacroTabPage_Impl()
106 delete pAssignPB;
107 delete pDeletePB;
108 delete pStrEvent;
109 delete pAssignedMacro;
110 delete pScriptTypeLB;
111 delete pEventLB;
112 delete pGroupLB;
113 delete pMacroLB;
114 delete pFT_MacroLBLabel;
115 delete pMacroFT;
116 delete pMacroStr;
120 SvStringsDtor* _ImpGetRangeHdl( _SfxMacroTabPage*, const String& rLanguage );
121 SvStringsDtor* _ImpGetMacrosOfRangeHdl( _SfxMacroTabPage*, const String& rLanguage, const String& rRange );
123 static USHORT __FAR_DATA aPageRg[] = {
124 SID_ATTR_MACROITEM, SID_ATTR_MACROITEM,
128 // Achtung im Code wird dieses Array direkt (0, 1, ...) indiziert
129 static long nTabs[] =
131 2, // Number of Tabs
132 0, 90
135 #define TAB_WIDTH_MIN 10
137 // IDs for items in HeaderBar of EventLB
138 #define ITEMID_EVENT 1
139 #define ITMEID_ASSMACRO 2
142 #define LB_EVENTS_ITEMPOS 1
143 #define LB_MACROS_ITEMPOS 2
145 String ConvertToUIName_Impl( SvxMacro *pMacro, const String& /*rLanguage*/ )
147 String aName( pMacro->GetMacName() );
148 String aEntry;
149 if ( ! pMacro->GetLanguage().EqualsAscii("JavaScript") )
151 USHORT nCount = aName.GetTokenCount('.');
152 aEntry = aName.GetToken( nCount-1, '.' );
153 if ( nCount > 2 )
155 aEntry += '(';
156 aEntry += aName.GetToken( 0, '.' );
157 aEntry += '.';
158 aEntry += aName.GetToken( nCount-2, '.' );
159 aEntry += ')';
161 return aEntry;
163 else
164 return aName;
167 void _SfxMacroTabPage::EnableButtons( const String& rLangName )
169 // Solange die Eventbox leer ist, nichts tun
170 const SvLBoxEntry* pE = mpImpl->pEventLB->GetListBox().FirstSelected();
171 if ( pE )
173 // Gebundenes Macro holen
174 const SvxMacro* pM = aTbl.Get( (USHORT)(ULONG) pE->GetUserData() );
175 mpImpl->pDeletePB->Enable( 0 != pM && !mpImpl->bReadOnly );
177 // Bei gleichem ScriptType Zuweisung nur, wenn Macro sich
178 // ge"andert hat; bei verschiedenem ScriptType, wenn Script nicht leer
179 String sEventMacro;
180 sEventMacro = ((SvLBoxString*)pE->GetItem( LB_MACROS_ITEMPOS ))->GetText();
181 if ( rLangName.EqualsAscii("JavaScript") )
183 DBG_ERROR( "_SfxMacroTabPage::EnableButtons(): this is not an up to date usage!" );
185 else
187 SfxMacroInfo* pInfo = mpImpl->pMacroLB->GetMacroInfo();
188 String sSelMacro;
189 if ( pInfo )
190 sSelMacro = pInfo->GetMacroName();
191 if( pM && rLangName != pM->GetLanguage() )
192 mpImpl->pAssignPB->Enable( pInfo != 0 && !mpImpl->bReadOnly );
193 else
194 mpImpl->pAssignPB->Enable( pInfo && !mpImpl->bReadOnly && !sSelMacro.EqualsIgnoreCaseAscii( sEventMacro ) );
199 _SfxMacroTabPage::_SfxMacroTabPage( Window* pParent, const ResId& rResId, const SfxItemSet& rAttrSet )
200 : SfxTabPage( pParent, rResId, rAttrSet )
203 mpImpl = new _SfxMacroTabPage_Impl;
204 mpImpl->fnGetRange = &_ImpGetRangeHdl;
205 mpImpl->fnGetMacroOfRange = &_ImpGetMacrosOfRangeHdl;
208 _SfxMacroTabPage::~_SfxMacroTabPage()
210 DELETEZ( mpImpl );
213 void _SfxMacroTabPage::AddEvent( const String & rEventName, USHORT nEventId )
215 String sTmp( rEventName );
216 sTmp += '\t';
218 // falls die Tabelle schon gueltig ist
219 SvxMacro* pM = aTbl.Get( nEventId );
220 if( pM )
222 String sNew( ConvertToUIName_Impl( pM, mpImpl->pScriptTypeLB->GetSelectEntry() ) );
223 sTmp += sNew;
226 SvLBoxEntry* pE = mpImpl->pEventLB->GetListBox().InsertEntry( sTmp );
227 pE->SetUserData( reinterpret_cast< void* >( sal::static_int_cast< sal_IntPtr >( nEventId )) );
230 void _SfxMacroTabPage::ScriptChanged( const String& aLangName )
232 // neue Bereiche und deren Funktionen besorgen
234 mpImpl->pGroupLB->SetScriptType( aLangName );
235 mpImpl->pGroupLB->Show();
236 mpImpl->pMacroLB->Show();
237 mpImpl->pMacroFT->SetText( *mpImpl->pMacroStr );
240 EnableButtons( aLangName );
243 void _SfxMacroTabPage::SetGetRangeLink( FNGetRangeHdl pFn )
245 mpImpl->fnGetRange = pFn;
248 FNGetRangeHdl _SfxMacroTabPage::GetGetRangeLink() const
250 return mpImpl->fnGetRange;
253 void _SfxMacroTabPage::SetGetMacrosOfRangeLink( FNGetMacrosOfRangeHdl pFn )
255 mpImpl->fnGetMacroOfRange = pFn;
258 FNGetMacrosOfRangeHdl _SfxMacroTabPage::GetGetMacrosOfRangeLink() const
260 return mpImpl->fnGetMacroOfRange;
263 BOOL _SfxMacroTabPage::FillItemSet( SfxItemSet& rSet )
265 SvxMacroItem aItem( GetWhich( aPageRg[0] ) );
266 ((SvxMacroTableDtor&)aItem.GetMacroTable()) = aTbl;
268 const SfxPoolItem* pItem;
269 if( SFX_ITEM_SET != GetItemSet().GetItemState( aItem.Which(), TRUE, &pItem )
270 || aItem != *(SvxMacroItem*)pItem )
272 rSet.Put( aItem );
273 return TRUE;
275 return FALSE;
278 void _SfxMacroTabPage::PageCreated (SfxAllItemSet aSet)
280 const SfxPoolItem* pEventsItem;
281 if( !mpImpl->bGotEvents && SFX_ITEM_SET == aSet.GetItemState( SID_EVENTCONFIG, TRUE, &pEventsItem ) )
283 mpImpl->bGotEvents = TRUE;
284 const SfxEventNamesList& rList = ((SfxEventNamesItem*)pEventsItem)->GetEvents();
285 for ( USHORT nNo = 0; nNo < rList.Count(); ++nNo )
287 const SfxEventName *pOwn = rList.GetObject(nNo);
288 AddEvent( pOwn->maUIName, pOwn->mnId );
293 void _SfxMacroTabPage::Reset( const SfxItemSet& rSet )
295 const SfxPoolItem* pItem;
296 if( SFX_ITEM_SET == rSet.GetItemState( GetWhich( aPageRg[0] ), TRUE, &pItem ))
297 aTbl = ((SvxMacroItem*)pItem)->GetMacroTable();
299 const SfxPoolItem* pEventsItem;
300 if( !mpImpl->bGotEvents && SFX_ITEM_SET == rSet.GetItemState( SID_EVENTCONFIG, TRUE, &pEventsItem ) )
302 mpImpl->bGotEvents = TRUE;
303 const SfxEventNamesList& rList = ((SfxEventNamesItem*)pEventsItem)->GetEvents();
304 for ( USHORT nNo = 0; nNo < rList.Count(); ++nNo )
306 const SfxEventName *pOwn = rList.GetObject(nNo);
307 AddEvent( pOwn->maUIName, pOwn->mnId );
311 FillEvents();
313 SvHeaderTabListBox& rListBox = mpImpl->pEventLB->GetListBox();
314 SvLBoxEntry* pE = rListBox.GetEntry( 0 );
315 if( pE )
316 rListBox.SetCurEntry( pE );
319 void _SfxMacroTabPage::SetReadOnly( BOOL bSet )
321 mpImpl->bReadOnly = bSet;
324 BOOL _SfxMacroTabPage::IsReadOnly() const
326 return mpImpl->bReadOnly;
329 IMPL_STATIC_LINK( _SfxMacroTabPage, SelectEvent_Impl, SvTabListBox*, EMPTYARG )
331 _SfxMacroTabPage_Impl* pImpl = pThis->mpImpl;
332 SvHeaderTabListBox& rListBox = pImpl->pEventLB->GetListBox();
333 SvLBoxEntry* pE = rListBox.FirstSelected();
334 ULONG nPos;
335 if( !pE || LISTBOX_ENTRY_NOTFOUND ==
336 ( nPos = rListBox.GetModel()->GetAbsPos( pE ) ) )
338 DBG_ASSERT( pE, "wo kommt der leere Eintrag her?" );
339 return 0;
342 USHORT nEventId = (USHORT)(ULONG)pE->GetUserData();
343 String aLanguage = pImpl->pScriptTypeLB->GetSelectEntry();
345 const SvxMacro* pM = pThis->aTbl.Get( nEventId );
346 if( pM )
348 if( aLanguage != pM->GetLanguage() )
350 pImpl->pScriptTypeLB->SelectEntry( pM->GetLanguage() );
351 pThis->ScriptChanged( pM->GetLanguage() );
353 else
355 DBG_ASSERT( !aLanguage.EqualsAscii("JavaScript"), "_SfxMacroTabPage, SelectEvent_Impl(): outdated use!" );
359 pThis->EnableButtons( aLanguage );
360 return 0;
363 IMPL_STATIC_LINK( _SfxMacroTabPage, SelectGroup_Impl, ListBox*, EMPTYARG )
365 _SfxMacroTabPage_Impl* pImpl = pThis->mpImpl;
366 String sSel( pImpl->pGroupLB->GetGroup() );
367 String aLanguage = pImpl->pScriptTypeLB->GetSelectEntry();
368 if( !aLanguage.EqualsAscii( "JavaScript" ) )
370 pImpl->pGroupLB->GroupSelected();
371 SfxMacroInfo* pMacro = pImpl->pMacroLB->GetMacroInfo();
372 String aLabelText;
373 if( pMacro )
375 aLabelText = pImpl->maStaticMacroLBLabel;
376 aLabelText += pMacro->GetModuleName();
378 else
380 // Wenn dort ein Macro drin ist, wurde es selektiert und der
381 // AssignButton schon in SelectMacro richtig enabled
382 pImpl->pAssignPB->Enable( FALSE );
385 pImpl->pFT_MacroLBLabel->SetText( aLabelText );
387 return 0;
390 IMPL_STATIC_LINK( _SfxMacroTabPage, SelectMacro_Impl, ListBox*, EMPTYARG )
392 _SfxMacroTabPage_Impl* pImpl = pThis->mpImpl;
393 pImpl->pMacroLB->FunctionSelected();
394 pThis->EnableButtons( pImpl->pScriptTypeLB->GetSelectEntry() );
395 return 0;
398 IMPL_STATIC_LINK( _SfxMacroTabPage, GetFocus_Impl, Edit*, EMPTYARG )
400 pThis->EnableButtons( DEFINE_CONST_UNICODE("JavaScript") );
401 return 0;
404 IMPL_STATIC_LINK( _SfxMacroTabPage, AssignDeleteHdl_Impl, PushButton*, pBtn )
406 _SfxMacroTabPage_Impl* pImpl = pThis->mpImpl;
407 SvHeaderTabListBox& rListBox = pImpl->pEventLB->GetListBox();
408 SvLBoxEntry* pE = rListBox.FirstSelected();
409 ULONG nPos;
410 if( !pE || LISTBOX_ENTRY_NOTFOUND ==
411 ( nPos = rListBox.GetModel()->GetAbsPos( pE ) ) )
413 DBG_ASSERT( pE, "wo kommt der leere Eintrag her?" );
414 return 0;
417 const BOOL bAssEnabled = pBtn != pImpl->pDeletePB && pImpl->pAssignPB->IsEnabled();
419 // aus der Tabelle entfernen
420 USHORT nEvent = (USHORT)(ULONG)pE->GetUserData();
421 SvxMacro *pRemoveMacro = pThis->aTbl.Remove( nEvent );
422 delete pRemoveMacro;
424 String aLanguage = pImpl->pScriptTypeLB->GetSelectEntry();
425 String sNew;
426 if( bAssEnabled )
428 String sGroup;
429 String sMacro;
430 String aEntryText( sNew );
431 DBG_ASSERT( !aLanguage.EqualsAscii("JavaScript"), "_SfxMacroTabPage, AssignDeleteHdl_Impl(): outdated use!" );
433 SfxMacroInfo* pMacro = pImpl->pMacroLB->GetMacroInfo();
434 sMacro = pMacro->GetQualifiedName();
435 sGroup = pImpl->pGroupLB->GetGroup();
436 sNew = pMacro->GetMacroName();
438 if( sMacro.CompareToAscii( "vnd.sun.star.script:", 20 ) == COMPARE_EQUAL )
440 OSL_TRACE("ASSIGN_DELETE: Its a script");
441 pThis->aTbl.Insert(
442 nEvent, new SvxMacro( sMacro, String::CreateFromAscii("Script") ) );
444 else
446 OSL_TRACE("ASSIGN_DELETE: Its a basic macro");
447 String sBasicName/*(SfxResId(STR_BASICNAME))*/;
448 if ( aLanguage == sBasicName )
449 pThis->aTbl.Insert( nEvent, new SvxMacro( sMacro, sGroup, STARBASIC ) );
450 else
451 pThis->aTbl.Insert( nEvent, new SvxMacro( sMacro, aLanguage ) );
455 pImpl->pEventLB->SetUpdateMode( FALSE );
456 pE->ReplaceItem( new SvLBoxString( pE, 0, sNew ), LB_MACROS_ITEMPOS );
457 rListBox.GetModel()->InvalidateEntry( pE );
458 rListBox.Select( pE );
459 rListBox.MakeVisible( pE );
460 rListBox.SetUpdateMode( TRUE );
462 pThis->EnableButtons( aLanguage );
463 return 0;
466 IMPL_STATIC_LINK( _SfxMacroTabPage, ChangeScriptHdl_Impl, RadioButton*, EMPTYARG )
468 pThis->ScriptChanged( pThis->mpImpl->pScriptTypeLB->GetSelectEntry() );
469 return 0;
472 IMPL_STATIC_LINK( _SfxMacroTabPage, TimeOut_Impl, Timer*, EMPTYARG )
474 // FillMacroList() can take a long time -> show wait cursor and disable input
475 SfxTabDialog* pTabDlg = pThis->GetTabDialog();
476 // perhaps the tabpage is part of a SingleTabDialog then pTabDlg == NULL
477 if ( pTabDlg )
479 pTabDlg->EnterWait();
480 pTabDlg->EnableInput( FALSE );
482 pThis->FillMacroList();
483 if ( pTabDlg )
485 pTabDlg->EnableInput( TRUE );
486 pTabDlg->LeaveWait();
488 return 0;
491 void _SfxMacroTabPage::InitAndSetHandler()
493 // Handler installieren
494 SvHeaderTabListBox& rListBox = mpImpl->pEventLB->GetListBox();
495 HeaderBar& rHeaderBar = mpImpl->pEventLB->GetHeaderBar();
496 Link aLnk(STATIC_LINK(this, _SfxMacroTabPage, AssignDeleteHdl_Impl ));
497 mpImpl->pMacroLB->SetDoubleClickHdl( aLnk );
498 mpImpl->pDeletePB->SetClickHdl( aLnk );
499 mpImpl->pAssignPB->SetClickHdl( aLnk );
500 rListBox.SetDoubleClickHdl( aLnk );
502 rListBox.SetSelectHdl( STATIC_LINK( this, _SfxMacroTabPage, SelectEvent_Impl ));
503 mpImpl->pGroupLB->SetSelectHdl( STATIC_LINK( this, _SfxMacroTabPage, SelectGroup_Impl ));
504 mpImpl->pMacroLB->SetSelectHdl( STATIC_LINK( this, _SfxMacroTabPage, SelectMacro_Impl ));
506 mpImpl->pScriptTypeLB->SetSelectHdl( STATIC_LINK( this, _SfxMacroTabPage, ChangeScriptHdl_Impl ));
508 rListBox.SetSelectionMode( SINGLE_SELECTION );
509 rListBox.SetTabs( &nTabs[0], MAP_APPFONT );
510 Size aSize( nTabs[ 2 ], 0 );
511 rHeaderBar.InsertItem( ITEMID_EVENT, *mpImpl->pStrEvent, LogicToPixel( aSize, MapMode( MAP_APPFONT ) ).Width() );
512 aSize.Width() = 1764; // don't know what, so 42^2 is best to use...
513 rHeaderBar.InsertItem( ITMEID_ASSMACRO, *mpImpl->pAssignedMacro, LogicToPixel( aSize, MapMode( MAP_APPFONT ) ).Width() );
514 rListBox.SetSpaceBetweenEntries( 0 );
516 mpImpl->pEventLB->Show();
517 mpImpl->pEventLB->ConnectElements();
519 mpImpl->pEventLB->Enable( TRUE );
520 mpImpl->pGroupLB->Enable( TRUE );
521 mpImpl->pMacroLB->Enable( TRUE );
523 mpImpl->pScriptTypeLB->SetDropDownLineCount( 3 );
524 String sBasicName/*(SfxResId(STR_BASICNAME))*/;
525 mpImpl->pScriptTypeLB->InsertEntry( sBasicName );
526 mpImpl->pScriptTypeLB->SelectEntry( sBasicName );
528 mpImpl->pGroupLB->SetFunctionListBox( mpImpl->pMacroLB );
530 mpImpl->maFillGroupTimer.SetTimeoutHdl( STATIC_LINK( this, _SfxMacroTabPage, TimeOut_Impl ) );
531 mpImpl->maFillGroupTimer.SetTimeout( 0 );
532 mpImpl->maFillGroupTimer.Start();
535 void _SfxMacroTabPage::FillMacroList()
537 String aLanguage = mpImpl->pScriptTypeLB->GetSelectEntry();
538 if( ! aLanguage.EqualsAscii("JavaScript") )
540 // 2 Listboxen
541 SvStringsDtor* pArr = (*mpImpl->fnGetRange)( this, String(/*SfxResId(STR_BASICNAME)*/) );
542 if( pArr )
544 mpImpl->pGroupLB->Init(
545 ::com::sun::star::uno::Reference<
546 ::com::sun::star::lang::XMultiServiceFactory >(),
547 GetFrame(),
548 ::rtl::OUString() );
550 delete pArr;
555 void _SfxMacroTabPage::FillEvents()
557 SvHeaderTabListBox& rListBox = mpImpl->pEventLB->GetListBox();
559 String aLanguage = mpImpl->pScriptTypeLB->GetSelectEntry();
560 ULONG nEntryCnt = rListBox.GetEntryCount();
562 // Events aus der Tabelle holen und die EventListBox entsprechen fuellen
563 for( ULONG n = 0 ; n < nEntryCnt ; ++n )
565 SvLBoxEntry* pE = rListBox.GetEntry( n );
566 if( pE )
568 SvLBoxString* pLItem = ( SvLBoxString* ) pE->GetItem( LB_MACROS_ITEMPOS );
569 DBG_ASSERT( pLItem && SV_ITEM_ID_LBOXSTRING == pLItem->IsA(), "_SfxMacroTabPage::FillEvents(): no LBoxString" );
571 String sOld( pLItem->GetText() );
572 String sNew;
573 USHORT nEventId = ( USHORT ) ( ULONG ) pE->GetUserData();
574 if( aTbl.IsKeyValid( nEventId ) )
575 sNew = ConvertToUIName_Impl( aTbl.Get( nEventId ), aLanguage );
577 if( sOld != sNew )
579 pE->ReplaceItem( new SvLBoxString( pE, 0, sNew ), LB_MACROS_ITEMPOS );
580 rListBox.GetModel()->InvalidateEntry( pE );
586 void _SfxMacroTabPage::SelectEvent( const String & /*rEventName*/, USHORT nEventId )
588 SvHeaderTabListBox& rListBox = mpImpl->pEventLB->GetListBox();
589 ULONG nEntryCnt = rListBox.GetEntryCount();
591 for( ULONG n = 0 ; n < nEntryCnt ; ++n )
593 SvLBoxEntry* pE = rListBox.GetEntry( n );
594 if( pE && ( USHORT ) ( ULONG ) pE->GetUserData() == nEventId )
596 rListBox.SetCurEntry( pE );
597 rListBox.MakeVisible( pE );
598 break;
604 SvStringsDtor* __EXPORT _ImpGetRangeHdl( _SfxMacroTabPage* /*pTbPg*/, const String& rLanguage )
606 SvStringsDtor* pNew = new SvStringsDtor;
607 SfxApplication* pSfxApp = SFX_APP();
609 if ( !rLanguage.EqualsAscii("JavaScript") )
611 pSfxApp->EnterBasicCall();
613 // AppBasic einf"ugen
614 String* pNewEntry = new String( pSfxApp->GetName() );
615 pNew->Insert( pNewEntry, pNew->Count() );
617 // Aktuelles Dokument
618 SfxObjectShell* pDoc = SfxObjectShell::Current();
619 if ( pDoc )
621 String aTitle = pDoc->GetTitle();
623 // Hack f"ur Aufruf aus der Basic-IDE : das Basic ermitteln, das
624 // gerade bearbeitet wird
626 String aAppName(DEFINE_CONST_UNICODE("BASIC - "));
627 USHORT nLen = aAppName.Len();
628 if ( aTitle.CompareIgnoreCaseToAscii( aAppName, nLen ) == COMPARE_EQUAL )
630 // Basic-Namensprefix entfernen
631 aTitle.Erase( 0, nLen );
632 USHORT nIndex=0, nCount=aTitle.GetTokenCount('.');
633 if ( nCount > 1 )
635 // Namen der Library entfernen
636 aTitle.GetToken( nCount-2, '.', nIndex );
637 aTitle.Erase( nIndex-1 );
640 // Wenn das App-Basic gerade in der Basic-IDE bearbeitet wird, kein
641 // Dokument verwenden
642 pDoc = SfxObjectShell::GetFirst();
643 while( pDoc )
645 if ( aTitle == pDoc->GetTitle() )
646 break;
647 pDoc = SfxObjectShell::GetNext( *pDoc );
651 if ( pDoc && pDoc->GetBasicManager() != SFX_APP()->GetBasicManager() &&
652 pDoc->GetBasicManager()->GetLibCount() )
654 pNewEntry = new String( aTitle );
655 pNew->Insert( pNewEntry, pNew->Count() );
659 pSfxApp->LeaveBasicCall();
662 return pNew;
665 // besorgen der Funktionen eines Bereiches
666 SvStringsDtor* __EXPORT _ImpGetMacrosOfRangeHdl(
667 _SfxMacroTabPage* /*pTbPg*/,
668 const String& /*rLanguage*/,
669 const String& /*rRange*/ )
671 SvStringsDtor* pNew = new SvStringsDtor;
672 return pNew;
676 SfxMacroTabPage::SfxMacroTabPage( Window* pParent, const ResId& rResId, const Reference< XFrame >& rxDocumentFrame, const SfxItemSet& rSet )
677 : _SfxMacroTabPage( pParent, rResId, rSet )
679 mpImpl->pStrEvent = new String( SVX_RES( STR_EVENT ) );
680 mpImpl->pAssignedMacro = new String( SVX_RES( STR_ASSMACRO ) );
681 mpImpl->pEventLB = new _HeaderTabListBox( this, SVX_RES( LB_EVENT ) );
682 mpImpl->pAssignPB = new PushButton( this, SVX_RES( PB_ASSIGN ) );
683 mpImpl->pDeletePB = new PushButton( this, SVX_RES( PB_DELETE ) );
684 mpImpl->pScriptTypeLB = new ListBox(this, SVX_RES( LB_SCRIPTTYPE ) );
685 mpImpl->pScriptTypeLB->Hide();
686 mpImpl->pMacroFT = new FixedText( this, SVX_RES( FT_MACRO ) );
687 mpImpl->pGroupLB = new SfxConfigGroupListBox_Impl( this, SVX_RES( LB_GROUP ) );
688 mpImpl->pFT_MacroLBLabel = new FixedText( this, SVX_RES( FT_LABEL4LB_MACROS ) );
689 mpImpl->maStaticMacroLBLabel= mpImpl->pFT_MacroLBLabel->GetText();
690 mpImpl->pMacroLB = new SfxConfigFunctionListBox_Impl( this, SVX_RES( LB_MACROS ) );
691 mpImpl->pMacroStr = new String( SVX_RES( STR_MACROS ) );
693 FreeResource();
695 SetFrame( rxDocumentFrame );
697 InitAndSetHandler();
699 ScriptChanged( String( /*SfxResId(STR_BASICNAME)*/ ) );
702 SfxTabPage* SfxMacroTabPage::Create( Window* pParent, const SfxItemSet& rAttrSet )
704 return new SfxMacroTabPage( pParent, SVX_RES( RID_SVXPAGE_EVENTASSIGN ), NULL, rAttrSet );
707 SfxMacroAssignDlg::SfxMacroAssignDlg( Window* pParent, const Reference< XFrame >& rxDocumentFrame, const SfxItemSet& rSet )
708 : SfxSingleTabDialog( pParent, rSet, 0 )
710 SfxTabPage* pPage = SfxMacroTabPage::Create( this, rSet );
711 pPage->SetFrame( rxDocumentFrame );
712 SetTabPage( pPage );
715 SfxMacroAssignDlg::~SfxMacroAssignDlg()