masterfix DEV300: #i10000# build fix
[LibreOffice.git] / cui / source / customize / macropg.cxx
blob5030e44832eba11ba9da4a9c8637abf222e6f7ac
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_cui.hxx"
30 #include <basic/basmgr.hxx>
32 #include "macropg.hxx"
33 #include <vcl/msgbox.hxx>
34 #define _SVSTDARR_STRINGSDTOR
35 #include <svl/svstdarr.hxx>
36 #include <svtools/svmedit.hxx>
37 #include <svl/eitem.hxx>
38 #include <tools/diagnose_ex.h>
39 #include <sfx2/app.hxx>
40 #include <sfx2/objsh.hxx>
41 #include <sfx2/sfxdefs.hxx>
42 #include <com/sun/star/container/NoSuchElementException.hpp>
43 #include <com/sun/star/lang/IllegalArgumentException.hpp>
44 #include <dialmgr.hxx>
45 #include "selector.hxx"
46 #include "cfg.hxx"
47 #include "macropg.hrc"
48 #include "helpid.hrc"
49 #include <cuires.hrc>
50 #include "headertablistbox.hxx"
51 #include "macropg_impl.hxx"
52 #include <svx/dialogs.hrc> // RID_SVXPAGE_MACROASSIGN
53 #include <comphelper/namedvaluecollection.hxx>
55 #include <algorithm>
56 #include <set>
58 using namespace ::com::sun::star;
59 using namespace ::com::sun::star::uno;
61 static ::rtl::OUString aVndSunStarUNO =
62 ::rtl::OUString::createFromAscii( "vnd.sun.star.UNO:" );
63 static ::rtl::OUString aVndSunStarScript =
64 ::rtl::OUString::createFromAscii( "vnd.sun.star.script:" );
66 _SvxMacroTabPage_Impl::_SvxMacroTabPage_Impl( const SfxItemSet& rAttrSet ) :
67 pAssignFT( NULL ),
68 pAssignPB( NULL ),
69 pAssignComponentPB( NULL ),
70 pDeletePB( NULL ),
71 pMacroImg( NULL ),
72 pComponentImg( NULL ),
73 pMacroImg_h( NULL ),
74 pComponentImg_h( NULL ),
75 pStrEvent( NULL ),
76 pAssignedMacro( NULL ),
77 pEventLB( NULL ),
78 bReadOnly( sal_False ),
79 bIDEDialogMode( sal_False )
81 const SfxPoolItem* pItem;
82 if ( SFX_ITEM_SET == rAttrSet.GetItemState( SID_ATTR_MACROITEM, sal_False, &pItem ) )
83 bIDEDialogMode = ((const SfxBoolItem*)pItem)->GetValue();
86 _SvxMacroTabPage_Impl::~_SvxMacroTabPage_Impl()
88 delete pAssignFT;
89 delete pAssignPB;
90 delete pAssignComponentPB;
91 delete pDeletePB;
92 delete pMacroImg;
93 delete pComponentImg;
94 delete pMacroImg_h;
95 delete pComponentImg_h;
96 delete pStrEvent;
97 delete pAssignedMacro;
98 delete pEventLB;
101 // Achtung im Code wird dieses Array direkt (0, 1, ...) indiziert
102 static long nTabs[] =
104 2, // Number of Tabs
105 0, 90
108 #define TAB_WIDTH_MIN 10
110 // IDs for items in HeaderBar of EventLB
111 #define ITEMID_EVENT 1
112 #define ITMEID_ASSMACRO 2
115 #define LB_EVENTS_ITEMPOS 1
116 #define LB_MACROS_ITEMPOS 2
119 IMPL_LINK( _HeaderTabListBox, HeaderEndDrag_Impl, HeaderBar*, pBar )
121 DBG_ASSERT( pBar == &maHeaderBar, "*_HeaderTabListBox::HeaderEndDrag_Impl: something is wrong here..." );
122 (void)pBar;
124 if( !maHeaderBar.GetCurItemId() )
125 return 0;
127 if( !maHeaderBar.IsItemMode() )
129 Size aSz;
130 sal_uInt16 _nTabs = maHeaderBar.GetItemCount();
131 long nTmpSz = 0;
132 long nWidth = maHeaderBar.GetItemSize( ITEMID_EVENT );
133 long nBarWidth = maHeaderBar.GetSizePixel().Width();
135 if( nWidth < TAB_WIDTH_MIN )
136 maHeaderBar.SetItemSize( ITEMID_EVENT, TAB_WIDTH_MIN );
137 else if( ( nBarWidth - nWidth ) < TAB_WIDTH_MIN )
138 maHeaderBar.SetItemSize( ITEMID_EVENT, nBarWidth - TAB_WIDTH_MIN );
141 long _nWidth;
142 for( sal_uInt16 i = 1 ; i < _nTabs ; ++i )
144 _nWidth = maHeaderBar.GetItemSize( i );
145 aSz.Width() = _nWidth + nTmpSz;
146 nTmpSz += _nWidth;
147 maListBox.SetTab( i, PixelToLogic( aSz, MapMode( MAP_APPFONT ) ).Width(), MAP_APPFONT );
151 return 1;
154 long _HeaderTabListBox::Notify( NotifyEvent& rNEvt )
156 long nRet = Control::Notify( rNEvt );
158 if( rNEvt.GetType() == EVENT_GETFOCUS )
160 if ( rNEvt.GetWindow() != &maListBox )
161 maListBox.GrabFocus();
164 return nRet;
167 _HeaderTabListBox::_HeaderTabListBox( Window* pParent, const ResId& rId ) :
168 Control( pParent, rId ),
169 maListBox( this, WB_HSCROLL | WB_CLIPCHILDREN | WB_TABSTOP ),
170 maHeaderBar( this, WB_BUTTONSTYLE | WB_BOTTOMBORDER )
172 maListBox.SetHelpId( HID_MACRO_HEADERTABLISTBOX );
175 _HeaderTabListBox::~_HeaderTabListBox()
179 void _HeaderTabListBox::ConnectElements( void )
181 // calc pos and size of header bar
182 Point aPnt( 0, 0 );
183 Size aSize( maHeaderBar.CalcWindowSizePixel() );
184 Size aCtrlSize( GetOutputSizePixel() );
185 aSize.Width() = aCtrlSize.Width();
186 maHeaderBar.SetPosSizePixel( aPnt, aSize );
188 // calc pos and size of ListBox
189 aPnt.Y() += aSize.Height();
190 aSize.Height() = aCtrlSize.Height() - aSize.Height();
191 maListBox.SetPosSizePixel( aPnt, aSize );
193 // set handler
194 maHeaderBar.SetEndDragHdl( LINK( this, _HeaderTabListBox, HeaderEndDrag_Impl ) );
196 maListBox.InitHeaderBar( &maHeaderBar );
199 void _HeaderTabListBox::Show( sal_Bool bVisible, sal_uInt16 nFlags )
201 maListBox.Show( bVisible, nFlags );
202 maHeaderBar.Show( bVisible, nFlags );
205 void _HeaderTabListBox::Enable( bool bEnable, bool bChild )
207 maListBox.Enable( bEnable, bChild );
208 maHeaderBar.Enable( bEnable, bChild );
211 // assign button ("Add Command") is enabled only if it is not read only
212 // delete button ("Remove Command") is enabled if a current binding exists
213 // and it is not read only
214 void _SvxMacroTabPage::EnableButtons()
216 const SvLBoxEntry* pE = mpImpl->pEventLB->GetListBox().FirstSelected();
217 if ( pE )
219 SvLBoxString* pEventMacro = (SvLBoxString*)pE->GetItem( LB_MACROS_ITEMPOS );
220 mpImpl->pDeletePB->Enable( 0 != pEventMacro && !mpImpl->bReadOnly );
222 mpImpl->pAssignPB->Enable( !mpImpl->bReadOnly );
223 if( mpImpl->pAssignComponentPB )
224 mpImpl->pAssignComponentPB->Enable( !mpImpl->bReadOnly );
228 _SvxMacroTabPage::_SvxMacroTabPage( Window* pParent, const ResId& rResId, const SfxItemSet& rAttrSet )
229 : SfxTabPage( pParent, rResId, rAttrSet ),
230 m_xAppEvents(0),
231 m_xDocEvents(0),
232 bReadOnly(false),
233 bDocModified(false),
234 bAppEvents(false),
235 bInitialized(false)
237 mpImpl = new _SvxMacroTabPage_Impl( rAttrSet );
240 _SvxMacroTabPage::~_SvxMacroTabPage()
242 // need to delete the user data
243 SvHeaderTabListBox& rListBox = mpImpl->pEventLB->GetListBox();
244 SvLBoxEntry* pE = rListBox.GetEntry( 0 );
245 while( pE )
247 ::rtl::OUString* pEventName = (::rtl::OUString*)pE->GetUserData();
248 delete pEventName;
249 pE->SetUserData((void*)0);
250 pE = rListBox.NextSibling( pE );
252 DELETEZ( mpImpl );
254 // -----------------------------------------------------------------------------
255 void _SvxMacroTabPage::InitResources()
257 // Note: the order here controls the order in which the events are displayed in the UI!
259 // the event name to UI string mappings for App Events
260 aDisplayNames.push_back( EventDisplayName( "OnStartApp", RID_SVXSTR_EVENT_STARTAPP ) );
261 aDisplayNames.push_back( EventDisplayName( "OnCloseApp", RID_SVXSTR_EVENT_CLOSEAPP ) );
262 aDisplayNames.push_back( EventDisplayName( "OnCreate", RID_SVXSTR_EVENT_CREATEDOC ) );
263 aDisplayNames.push_back( EventDisplayName( "OnNew", RID_SVXSTR_EVENT_NEWDOC ) );
264 aDisplayNames.push_back( EventDisplayName( "OnLoadFinished", RID_SVXSTR_EVENT_LOADDOCFINISHED ) );
265 aDisplayNames.push_back( EventDisplayName( "OnLoad", RID_SVXSTR_EVENT_OPENDOC ) );
266 aDisplayNames.push_back( EventDisplayName( "OnPrepareUnload", RID_SVXSTR_EVENT_PREPARECLOSEDOC ) );
267 aDisplayNames.push_back( EventDisplayName( "OnUnload", RID_SVXSTR_EVENT_CLOSEDOC ) ) ;
268 aDisplayNames.push_back( EventDisplayName( "OnViewCreated", RID_SVXSTR_EVENT_VIEWCREATED ) );
269 aDisplayNames.push_back( EventDisplayName( "OnPrepareViewClosing", RID_SVXSTR_EVENT_PREPARECLOSEVIEW ) );
270 aDisplayNames.push_back( EventDisplayName( "OnViewClosed", RID_SVXSTR_EVENT_CLOSEVIEW ) ) ;
271 aDisplayNames.push_back( EventDisplayName( "OnFocus", RID_SVXSTR_EVENT_ACTIVATEDOC ) );
272 aDisplayNames.push_back( EventDisplayName( "OnUnfocus", RID_SVXSTR_EVENT_DEACTIVATEDOC ) );
273 aDisplayNames.push_back( EventDisplayName( "OnSave", RID_SVXSTR_EVENT_SAVEDOC ) );
274 aDisplayNames.push_back( EventDisplayName( "OnSaveDone", RID_SVXSTR_EVENT_SAVEDOCDONE ) );
275 aDisplayNames.push_back( EventDisplayName( "OnSaveFailed", RID_SVXSTR_EVENT_SAVEDOCFAILED ) );
276 aDisplayNames.push_back( EventDisplayName( "OnSaveAs", RID_SVXSTR_EVENT_SAVEASDOC ) );
277 aDisplayNames.push_back( EventDisplayName( "OnSaveAsDone", RID_SVXSTR_EVENT_SAVEASDOCDONE ) );
278 aDisplayNames.push_back( EventDisplayName( "OnSaveAsFailed", RID_SVXSTR_EVENT_SAVEASDOCFAILED ) );
279 aDisplayNames.push_back( EventDisplayName( "OnCopyTo", RID_SVXSTR_EVENT_COPYTODOC ) );
280 aDisplayNames.push_back( EventDisplayName( "OnCopyToDone", RID_SVXSTR_EVENT_COPYTODOCDONE ) );
281 aDisplayNames.push_back( EventDisplayName( "OnCopyToFailed", RID_SVXSTR_EVENT_COPYTODOCFAILED ) );
282 aDisplayNames.push_back( EventDisplayName( "OnPrint", RID_SVXSTR_EVENT_PRINTDOC ) );
283 aDisplayNames.push_back( EventDisplayName( "OnModifyChanged", RID_SVXSTR_EVENT_MODIFYCHANGED ) );
284 aDisplayNames.push_back( EventDisplayName( "OnTitleChanged", RID_SVXSTR_EVENT_TITLECHANGED ) );
285 // aDisplayNames.push_back( EventDisplayName( "OnModeChanged", RID_SVXSTR_EVENT_MODECHANGED ) );
286 // aDisplayNames.push_back( EventDisplayName( "OnVisAreaChanged", RID_SVXSTR_EVENT_VISAREACHANGED ) );
287 // aDisplayNames.push_back( EventDisplayName( "OnStorageChanged", RID_SVXSTR_EVENT_STORAGECHANGED ) );
289 // application specific events
290 aDisplayNames.push_back( EventDisplayName( "OnMailMerge", RID_SVXSTR_EVENT_MAILMERGE ) );
291 aDisplayNames.push_back( EventDisplayName( "OnMailMergeFinished", RID_SVXSTR_EVENT_MAILMERGE_END ) );
292 aDisplayNames.push_back( EventDisplayName( "OnFieldMerge", RID_SVXSTR_EVENT_FIELDMERGE ) );
293 aDisplayNames.push_back( EventDisplayName( "OnFieldMergeFinished", RID_SVXSTR_EVENT_FIELDMERGE_FINISHED ) );
294 aDisplayNames.push_back( EventDisplayName( "OnPageCountChange", RID_SVXSTR_EVENT_PAGECOUNTCHANGE ) );
295 aDisplayNames.push_back( EventDisplayName( "OnSubComponentOpened", RID_SVXSTR_EVENT_SUBCOMPONENT_OPENED ) );
296 aDisplayNames.push_back( EventDisplayName( "OnSubComponentClosed", RID_SVXSTR_EVENT_SUBCOMPONENT_CLOSED ) );
297 // aDisplayNames.push_back( EventDisplayName( "OnLayoutFinished", RID_SVXSTR_EVENT_LAYOUT_FINISHED ) );
298 aDisplayNames.push_back( EventDisplayName( "OnSelect", RID_SVXSTR_EVENT_SELECTIONCHANGED ) );
299 aDisplayNames.push_back( EventDisplayName( "OnDoubleClick", RID_SVXSTR_EVENT_DOUBLECLICK ) );
300 aDisplayNames.push_back( EventDisplayName( "OnRightClick", RID_SVXSTR_EVENT_RIGHTCLICK ) );
301 aDisplayNames.push_back( EventDisplayName( "OnCalculate", RID_SVXSTR_EVENT_CALCULATE ) );
302 aDisplayNames.push_back( EventDisplayName( "OnChange", RID_SVXSTR_EVENT_CONTENTCHANGED ) );
304 // the event name to UI string mappings for forms & dialogs
306 aDisplayNames.push_back( EventDisplayName( "approveAction", RID_SVXSTR_EVENT_APPROVEACTIONPERFORMED ) );
307 aDisplayNames.push_back( EventDisplayName( "actionPerformed", RID_SVXSTR_EVENT_ACTIONPERFORMED ) );
308 aDisplayNames.push_back( EventDisplayName( "changed", RID_SVXSTR_EVENT_CHANGED ) );
309 aDisplayNames.push_back( EventDisplayName( "textChanged", RID_SVXSTR_EVENT_TEXTCHANGED ) );
310 aDisplayNames.push_back( EventDisplayName( "itemStateChanged", RID_SVXSTR_EVENT_ITEMSTATECHANGED ) );
311 aDisplayNames.push_back( EventDisplayName( "focusGained", RID_SVXSTR_EVENT_FOCUSGAINED ) );
312 aDisplayNames.push_back( EventDisplayName( "focusLost", RID_SVXSTR_EVENT_FOCUSLOST ) );
313 aDisplayNames.push_back( EventDisplayName( "keyPressed", RID_SVXSTR_EVENT_KEYTYPED ) );
314 aDisplayNames.push_back( EventDisplayName( "keyReleased", RID_SVXSTR_EVENT_KEYUP ) );
315 aDisplayNames.push_back( EventDisplayName( "mouseEntered", RID_SVXSTR_EVENT_MOUSEENTERED ) );
316 aDisplayNames.push_back( EventDisplayName( "mouseDragged", RID_SVXSTR_EVENT_MOUSEDRAGGED ) );
317 aDisplayNames.push_back( EventDisplayName( "mouseMoved", RID_SVXSTR_EVENT_MOUSEMOVED ) );
318 aDisplayNames.push_back( EventDisplayName( "mousePressed", RID_SVXSTR_EVENT_MOUSEPRESSED ) );
319 aDisplayNames.push_back( EventDisplayName( "mouseReleased", RID_SVXSTR_EVENT_MOUSERELEASED ) );
320 aDisplayNames.push_back( EventDisplayName( "mouseExited", RID_SVXSTR_EVENT_MOUSEEXITED ) );
321 aDisplayNames.push_back( EventDisplayName( "approveReset", RID_SVXSTR_EVENT_APPROVERESETTED ) );
322 aDisplayNames.push_back( EventDisplayName( "resetted", RID_SVXSTR_EVENT_RESETTED ) );
323 aDisplayNames.push_back( EventDisplayName( "approveSubmit", RID_SVXSTR_EVENT_SUBMITTED ) );
324 aDisplayNames.push_back( EventDisplayName( "approveUpdate", RID_SVXSTR_EVENT_BEFOREUPDATE ) );
325 aDisplayNames.push_back( EventDisplayName( "updated", RID_SVXSTR_EVENT_AFTERUPDATE ) );
326 aDisplayNames.push_back( EventDisplayName( "loaded", RID_SVXSTR_EVENT_LOADED ) );
327 aDisplayNames.push_back( EventDisplayName( "reloading", RID_SVXSTR_EVENT_RELOADING ) );
328 aDisplayNames.push_back( EventDisplayName( "reloaded", RID_SVXSTR_EVENT_RELOADED ) );
329 aDisplayNames.push_back( EventDisplayName( "unloading", RID_SVXSTR_EVENT_UNLOADING ) );
330 aDisplayNames.push_back( EventDisplayName( "unloaded", RID_SVXSTR_EVENT_UNLOADED ) );
331 aDisplayNames.push_back( EventDisplayName( "confirmDelete", RID_SVXSTR_EVENT_CONFIRMDELETE ) );
332 aDisplayNames.push_back( EventDisplayName( "approveRowChange", RID_SVXSTR_EVENT_APPROVEROWCHANGE ) );
333 aDisplayNames.push_back( EventDisplayName( "rowChanged", RID_SVXSTR_EVENT_ROWCHANGE ) );
334 aDisplayNames.push_back( EventDisplayName( "approveCursorMove", RID_SVXSTR_EVENT_POSITIONING ) );
335 aDisplayNames.push_back( EventDisplayName( "cursorMoved", RID_SVXSTR_EVENT_POSITIONED ) );
336 aDisplayNames.push_back( EventDisplayName( "approveParameter", RID_SVXSTR_EVENT_APPROVEPARAMETER ) );
337 aDisplayNames.push_back( EventDisplayName( "errorOccured", RID_SVXSTR_EVENT_ERROROCCURED ) );
338 aDisplayNames.push_back( EventDisplayName( "adjustmentValueChanged", RID_SVXSTR_EVENT_ADJUSTMENTVALUECHANGED ) );
341 // the following method is called when the user clicks OK
342 // We use the contents of the hashes to replace the settings
343 sal_Bool _SvxMacroTabPage::FillItemSet( SfxItemSet& /*rSet*/ )
347 ::rtl::OUString eventName;
348 if( m_xAppEvents.is() )
350 EventsHash::iterator h_itEnd = m_appEventsHash.end();
351 EventsHash::iterator h_it = m_appEventsHash.begin();
352 for ( ; h_it != h_itEnd; ++h_it )
354 eventName = h_it->first;
357 m_xAppEvents->replaceByName( eventName, GetPropsByName( eventName, m_appEventsHash ) );
359 catch( const Exception& )
361 DBG_UNHANDLED_EXCEPTION();
365 if( m_xDocEvents.is() && bDocModified )
367 EventsHash::iterator h_itEnd = m_docEventsHash.end();
368 EventsHash::iterator h_it = m_docEventsHash.begin();
369 for ( ; h_it != h_itEnd; ++h_it )
371 eventName = h_it->first;
374 m_xDocEvents->replaceByName( eventName, GetPropsByName( eventName, m_docEventsHash ) );
376 catch( const Exception& )
378 DBG_UNHANDLED_EXCEPTION();
381 // if we have a valid XModifiable (in the case of doc events)
382 // call setModified(true)
383 // in principle this should not be necessary (see issue ??)
384 if(m_xModifiable.is())
386 m_xModifiable->setModified( sal_True );
390 catch(Exception&)
393 // what is the return value about??
394 return sal_False;
397 // the following method clears the bindings in the hashes for both doc & app
398 void _SvxMacroTabPage::Reset()
400 // called once in creation - don't reset the data this time
401 if(!bInitialized)
403 bInitialized = true;
404 return;
409 ::rtl::OUString sEmpty;
410 if( m_xAppEvents.is() )
412 EventsHash::iterator h_itEnd = m_appEventsHash.end();
413 EventsHash::iterator h_it = m_appEventsHash.begin();
414 for ( ; h_it != h_itEnd; ++h_it )
416 h_it->second.second = sEmpty;
419 if( m_xDocEvents.is() && bDocModified )
421 EventsHash::iterator h_itEnd = m_docEventsHash.end();
422 EventsHash::iterator h_it = m_docEventsHash.begin();
423 for ( ; h_it != h_itEnd; ++h_it )
425 h_it->second.second = sEmpty;
427 // if we have a valid XModifiable (in the case of doc events)
428 // call setModified(true)
429 if(m_xModifiable.is())
431 m_xModifiable->setModified( sal_True );
435 catch(Exception&)
438 DisplayAppEvents(bAppEvents);
441 void _SvxMacroTabPage::SetReadOnly( sal_Bool bSet )
443 mpImpl->bReadOnly = bSet;
446 sal_Bool _SvxMacroTabPage::IsReadOnly() const
448 return mpImpl->bReadOnly;
452 class IconLBoxString : public SvLBoxString
454 Image* m_pMacroImg;
455 Image* m_pComponentImg;
456 Image* m_pMacroImg_h;
457 Image* m_pComponentImg_h;
458 int m_nxImageOffset;
460 public:
461 IconLBoxString( SvLBoxEntry* pEntry, sal_uInt16 nFlags, const String& sText,
462 Image* pMacroImg, Image* pComponentImg,
463 Image* pMacroImg_h, Image* pComponentImg_h );
464 virtual void Paint(const Point& aPos, SvLBox& aDevice, sal_uInt16 nFlags, SvLBoxEntry* pEntry );
468 IconLBoxString::IconLBoxString( SvLBoxEntry* pEntry, sal_uInt16 nFlags, const String& sText,
469 Image* pMacroImg, Image* pComponentImg, Image* pMacroImg_h, Image* pComponentImg_h )
470 : SvLBoxString( pEntry, nFlags, sText )
471 , m_pMacroImg( pMacroImg )
472 , m_pComponentImg( pComponentImg )
473 , m_pMacroImg_h( pMacroImg_h )
474 , m_pComponentImg_h( pComponentImg_h )
476 m_nxImageOffset = 20;
479 //===============================================
480 void IconLBoxString::Paint( const Point& aPos, SvLBox& aDevice,
481 sal_uInt16 /*nFlags*/, SvLBoxEntry* /*pEntry*/ )
483 String aTxt( GetText() );
484 if( aTxt.Len() )
486 ::rtl::OUString aURL( aTxt );
487 sal_Int32 nIndex = aURL.indexOf( aVndSunStarUNO );
488 bool bUNO = nIndex == 0;
490 sal_Bool bHC = aDevice.GetSettings().GetStyleSettings().GetHighContrastMode();
491 const Image* pImg;
492 if( bHC )
493 pImg = bUNO ? m_pComponentImg_h : m_pMacroImg_h;
494 else
495 pImg = bUNO ? m_pComponentImg : m_pMacroImg;
496 aDevice.DrawImage( aPos, *pImg );
498 ::rtl::OUString aPureMethod;
499 if( bUNO )
501 sal_Int32 nBegin = aVndSunStarUNO.getLength();
502 aPureMethod = aURL.copy( nBegin );
504 else
506 sal_Int32 nBegin = aVndSunStarScript.getLength();
507 aPureMethod = aURL.copy( nBegin );
508 aPureMethod = aPureMethod.copy( 0, aPureMethod.indexOf( '?' ) );
511 Point aPnt(aPos);
512 aPnt.X() += m_nxImageOffset;
513 aDevice.DrawText( aPnt, aPureMethod );
518 // displays the app events if appEvents=true, otherwise displays the doc events
519 void _SvxMacroTabPage::DisplayAppEvents( bool appEvents)
521 bAppEvents = appEvents;
523 SvHeaderTabListBox& rListBox = mpImpl->pEventLB->GetListBox();
524 mpImpl->pEventLB->SetUpdateMode( sal_False );
525 rListBox.Clear();
526 SvLBoxEntry* pE = rListBox.GetEntry( 0 );
527 EventsHash* eventsHash;
528 Reference< container::XNameReplace> nameReplace;
529 if(bAppEvents)
531 eventsHash = &m_appEventsHash;
532 nameReplace = m_xAppEvents;
534 else
536 eventsHash = &m_docEventsHash;
537 nameReplace = m_xDocEvents;
539 // have to use the original XNameReplace since the hash iterators do
540 // not guarantee the order in which the elements are returned
541 if(!nameReplace.is())
543 return;
546 Sequence< ::rtl::OUString > eventNames = nameReplace->getElementNames();
547 ::std::set< ::rtl::OUString > aEventNamesCache;
548 ::std::copy(
549 eventNames.getConstArray(),
550 eventNames.getConstArray() + eventNames.getLength(),
551 ::std::insert_iterator< ::std::set< ::rtl::OUString > >( aEventNamesCache, aEventNamesCache.end() )
554 for ( EventDisplayNames::const_iterator displayableEvent = aDisplayNames.begin();
555 displayableEvent != aDisplayNames.end();
556 ++displayableEvent
559 ::rtl::OUString sEventName( ::rtl::OUString::createFromAscii( displayableEvent->pAsciiEventName ) );
560 if ( !nameReplace->hasByName( sEventName ) )
561 continue;
563 EventsHash::iterator h_it = eventsHash->find( sEventName );
564 if( h_it == eventsHash->end() )
566 OSL_ENSURE( false, "_SvxMacroTabPage::DisplayAppEvents: something's suspicious here!" );
567 continue;
570 ::rtl::OUString eventURL = h_it->second.second;
571 String displayName( CUI_RES( displayableEvent->nEventResourceID ) );
573 displayName += '\t';
574 SvLBoxEntry* _pE = rListBox.InsertEntry( displayName );
575 ::rtl::OUString* pEventName = new ::rtl::OUString( sEventName );
576 _pE->SetUserData( (void*)pEventName );
577 String sNew( eventURL );
578 _pE->ReplaceItem( new IconLBoxString( _pE, 0, sNew,
579 mpImpl->pMacroImg, mpImpl->pComponentImg,
580 mpImpl->pMacroImg_h, mpImpl->pComponentImg_h ), LB_MACROS_ITEMPOS );
581 rListBox.GetModel()->InvalidateEntry( _pE );
582 rListBox.Select( _pE );
583 rListBox.MakeVisible( _pE );
586 pE = rListBox.GetEntry(0);
587 if( pE )
589 rListBox.Select( pE );
590 rListBox.MakeVisible( pE );
593 rListBox.SetUpdateMode( sal_True );
594 EnableButtons();
597 // select event handler on the listbox
598 IMPL_STATIC_LINK( _SvxMacroTabPage, SelectEvent_Impl, SvTabListBox*, EMPTYARG )
600 _SvxMacroTabPage_Impl* pImpl = pThis->mpImpl;
601 SvHeaderTabListBox& rListBox = pImpl->pEventLB->GetListBox();
602 SvLBoxEntry* pE = rListBox.FirstSelected();
603 sal_uLong nPos;
605 if( !pE || LISTBOX_ENTRY_NOTFOUND ==
606 ( nPos = rListBox.GetModel()->GetAbsPos( pE ) ) )
608 DBG_ASSERT( pE, "wo kommt der leere Eintrag her?" );
609 return 0;
612 pThis->EnableButtons();
613 return 0;
616 IMPL_STATIC_LINK( _SvxMacroTabPage, AssignDeleteHdl_Impl, PushButton*, pBtn )
618 return GenericHandler_Impl( pThis, pBtn );
621 IMPL_STATIC_LINK( _SvxMacroTabPage, DoubleClickHdl_Impl, SvTabListBox *, EMPTYARG )
623 return GenericHandler_Impl( pThis, NULL );
626 // handler for double click on the listbox, and for the assign/delete buttons
627 long _SvxMacroTabPage::GenericHandler_Impl( _SvxMacroTabPage* pThis, PushButton* pBtn )
629 _SvxMacroTabPage_Impl* pImpl = pThis->mpImpl;
630 SvHeaderTabListBox& rListBox = pImpl->pEventLB->GetListBox();
631 SvLBoxEntry* pE = rListBox.FirstSelected();
632 sal_uLong nPos;
633 if( !pE || LISTBOX_ENTRY_NOTFOUND ==
634 ( nPos = rListBox.GetModel()->GetAbsPos( pE ) ) )
636 DBG_ASSERT( pE, "wo kommt der leere Eintrag her?" );
637 return 0;
640 const sal_Bool bAssEnabled = pBtn != pImpl->pDeletePB && pImpl->pAssignPB->IsEnabled();
642 ::rtl::OUString* pEventName = (::rtl::OUString*)pE->GetUserData();
644 ::rtl::OUString sEventURL;
645 ::rtl::OUString sEventType;
646 if(pThis->bAppEvents)
648 EventsHash::iterator h_it = pThis->m_appEventsHash.find( *pEventName );
649 if(h_it != pThis->m_appEventsHash.end() )
651 sEventType = h_it->second.first;
652 sEventURL = h_it->second.second;
655 else
657 EventsHash::iterator h_it = pThis->m_docEventsHash.find( *pEventName );
658 if(h_it != pThis->m_docEventsHash.end() )
660 sEventType = h_it->second.first;
661 sEventURL = h_it->second.second;
665 bool bDoubleClick = (pBtn == NULL);
666 bool bUNOAssigned = (sEventURL.indexOf( aVndSunStarUNO ) == 0);
667 if( pBtn == pImpl->pDeletePB )
669 // delete pressed
670 sEventType = ::rtl::OUString::createFromAscii("Script");
671 sEventURL = ::rtl::OUString();
672 if(!pThis->bAppEvents)
673 pThis->bDocModified = true;
675 else if ( ( ( pBtn != NULL )
676 && ( pBtn == pImpl->pAssignComponentPB )
678 || ( bDoubleClick
679 && bUNOAssigned
683 AssignComponentDialog* pAssignDlg = new AssignComponentDialog( pThis, sEventURL );
685 short ret = pAssignDlg->Execute();
686 if( ret )
688 sEventType = ::rtl::OUString::createFromAscii("UNO");
689 sEventURL = pAssignDlg->getURL();
690 if(!pThis->bAppEvents)
691 pThis->bDocModified = true;
693 delete pAssignDlg;
695 else if( bAssEnabled )
697 // assign pressed
698 SvxScriptSelectorDialog* pDlg = new SvxScriptSelectorDialog( pThis, sal_False, pThis->GetFrame() );
699 if( pDlg )
701 short ret = pDlg->Execute();
702 if ( ret )
704 sEventType = ::rtl::OUString::createFromAscii("Script");
705 sEventURL = pDlg->GetScriptURL();
706 if(!pThis->bAppEvents)
707 pThis->bDocModified = true;
712 // update the hashes
713 if(pThis->bAppEvents)
715 EventsHash::iterator h_it = pThis->m_appEventsHash.find( *pEventName );
716 h_it->second.first = sEventType;
717 h_it->second.second = sEventURL;
719 else
721 EventsHash::iterator h_it = pThis->m_docEventsHash.find( *pEventName );
722 h_it->second.first = sEventType;
723 h_it->second.second = sEventURL;
726 // update the listbox entry
727 pImpl->pEventLB->SetUpdateMode( sal_False );
728 // pE->ReplaceItem( new SvLBoxString( pE, 0, sEventURL ), LB_MACROS_ITEMPOS );
729 pE->ReplaceItem( new IconLBoxString( pE, 0, sEventURL,
730 pImpl->pMacroImg, pImpl->pComponentImg,
731 pImpl->pMacroImg_h, pImpl->pComponentImg_h ), LB_MACROS_ITEMPOS );
733 rListBox.GetModel()->InvalidateEntry( pE );
734 rListBox.Select( pE );
735 rListBox.MakeVisible( pE );
736 rListBox.SetUpdateMode( sal_True );
738 pThis->EnableButtons();
739 return 0;
742 // pass in the XNameReplace.
743 // can remove the 3rd arg once issue ?? is fixed
744 void _SvxMacroTabPage::InitAndSetHandler( Reference< container::XNameReplace> xAppEvents, Reference< container::XNameReplace> xDocEvents, Reference< util::XModifiable > xModifiable )
746 m_xAppEvents = xAppEvents;
747 m_xDocEvents = xDocEvents;
748 m_xModifiable = xModifiable;
749 SvHeaderTabListBox& rListBox = mpImpl->pEventLB->GetListBox();
750 HeaderBar& rHeaderBar = mpImpl->pEventLB->GetHeaderBar();
751 Link aLnk(STATIC_LINK(this, _SvxMacroTabPage, AssignDeleteHdl_Impl ));
752 mpImpl->pDeletePB->SetClickHdl( aLnk );
753 mpImpl->pAssignPB->SetClickHdl( aLnk );
754 if( mpImpl->pAssignComponentPB )
755 mpImpl->pAssignComponentPB->SetClickHdl( aLnk );
756 rListBox.SetDoubleClickHdl( STATIC_LINK(this, _SvxMacroTabPage, DoubleClickHdl_Impl ) );
758 rListBox.SetSelectHdl( STATIC_LINK( this, _SvxMacroTabPage, SelectEvent_Impl ));
760 rListBox.SetSelectionMode( SINGLE_SELECTION );
761 rListBox.SetTabs( &nTabs[0], MAP_APPFONT );
762 Size aSize( nTabs[ 2 ], 0 );
763 rHeaderBar.InsertItem( ITEMID_EVENT, *mpImpl->pStrEvent, LogicToPixel( aSize, MapMode( MAP_APPFONT ) ).Width() );
764 aSize.Width() = 1764; // don't know what, so 42^2 is best to use...
765 rHeaderBar.InsertItem( ITMEID_ASSMACRO, *mpImpl->pAssignedMacro, LogicToPixel( aSize, MapMode( MAP_APPFONT ) ).Width() );
766 rListBox.SetSpaceBetweenEntries( 0 );
768 mpImpl->pEventLB->Show();
769 mpImpl->pEventLB->ConnectElements();
771 long nMinLineHeight = mpImpl->pMacroImg->GetSizePixel().Height() + 2;
772 if( nMinLineHeight > mpImpl->pEventLB->GetListBox().GetEntryHeight() )
773 mpImpl->pEventLB->GetListBox().SetEntryHeight(
774 sal::static_int_cast< short >(nMinLineHeight) );
776 mpImpl->pEventLB->Enable( sal_True );
778 if(!m_xAppEvents.is())
780 return;
782 Sequence< ::rtl::OUString > eventNames = m_xAppEvents->getElementNames();
783 sal_Int32 nEventCount = eventNames.getLength();
784 for(sal_Int32 nEvent = 0; nEvent < nEventCount; ++nEvent )
786 //need exception handling here
789 m_appEventsHash[ eventNames[nEvent] ] = GetPairFromAny( m_xAppEvents->getByName( eventNames[nEvent] ) );
791 catch (Exception e)
794 if(m_xDocEvents.is())
796 eventNames = m_xDocEvents->getElementNames();
797 nEventCount = eventNames.getLength();
798 for(sal_Int32 nEvent = 0; nEvent < nEventCount; ++nEvent )
802 m_docEventsHash[ eventNames[nEvent] ] = GetPairFromAny( m_xDocEvents->getByName( eventNames[nEvent] ) );
804 catch (Exception e)
810 // returns the two props EventType & Script for a given event name
811 Any _SvxMacroTabPage::GetPropsByName( const ::rtl::OUString& eventName, EventsHash& eventsHash )
813 const ::std::pair< ::rtl::OUString, ::rtl::OUString >& rAssignedEvent( eventsHash[ eventName ] );
815 Any aReturn;
816 ::comphelper::NamedValueCollection aProps;
817 if ( rAssignedEvent.first.getLength() && rAssignedEvent.second.getLength() )
819 aProps.put( "EventType", rAssignedEvent.first );
820 aProps.put( "Script", rAssignedEvent.second );
822 aReturn <<= aProps.getPropertyValues();
824 return aReturn;
827 // converts the Any returned by GetByName into a pair which can be stored in
828 // the EventHash
829 ::std::pair< ::rtl::OUString, ::rtl::OUString > _SvxMacroTabPage::GetPairFromAny( Any aAny )
831 Sequence< beans::PropertyValue > props;
832 ::rtl::OUString type, url;
833 if( sal_True == ( aAny >>= props ) )
835 ::comphelper::NamedValueCollection aProps( props );
836 type = aProps.getOrDefault( "EventType", type );
837 url = aProps.getOrDefault( "Script", url );
839 return ::std::make_pair( type, url );
842 SvxMacroTabPage::SvxMacroTabPage( Window* pParent, const Reference< frame::XFrame >& _rxDocumentFrame, const SfxItemSet& rSet, Reference< container::XNameReplace > xNameReplace, sal_uInt16 nSelectedIndex )
843 : _SvxMacroTabPage( pParent, CUI_RES( RID_SVXPAGE_MACROASSIGN ), rSet )
845 mpImpl->pStrEvent = new String( CUI_RES( STR_EVENT ) );
846 mpImpl->pAssignedMacro = new String( CUI_RES( STR_ASSMACRO ) );
847 mpImpl->pEventLB = new _HeaderTabListBox( this, CUI_RES( LB_EVENT ) );
848 mpImpl->pAssignFT = new FixedText( this, CUI_RES( FT_ASSIGN ) );
849 mpImpl->pAssignPB = new PushButton( this, CUI_RES( PB_ASSIGN ) );
850 mpImpl->pDeletePB = new PushButton( this, CUI_RES( PB_DELETE ) );
851 mpImpl->pAssignComponentPB = new PushButton( this, CUI_RES( PB_ASSIGN_COMPONENT ) );
852 mpImpl->pMacroImg = new Image( CUI_RES(IMG_MACRO) );
853 mpImpl->pComponentImg = new Image( CUI_RES(IMG_COMPONENT) );
854 mpImpl->pMacroImg_h = new Image( CUI_RES(IMG_MACRO_H) );
855 mpImpl->pComponentImg_h = new Image( CUI_RES(IMG_COMPONENT_H) );
857 FreeResource();
859 SetFrame( _rxDocumentFrame );
861 if( !mpImpl->bIDEDialogMode )
863 // Size aSizeAssign;
864 // Point aPosAssign;
865 // mpImpl->pAssignPB->GetPosSizePixel( aPosAssign, aSizeAssign );
866 Point aPosAssign = mpImpl->pAssignPB->GetPosPixel();
867 Point aPosComp = mpImpl->pAssignComponentPB->GetPosPixel();
869 Point aPosDelete = mpImpl->pDeletePB->GetPosPixel();
870 long nYDiff = aPosComp.Y() - aPosAssign.Y();
871 aPosDelete.Y() -= nYDiff;
872 mpImpl->pDeletePB->SetPosPixel( aPosDelete );
874 mpImpl->pAssignComponentPB->Hide();
875 mpImpl->pAssignComponentPB->Disable();
878 // must be done after FreeResource is called
879 InitResources();
881 mpImpl->pEventLB->GetListBox().SetHelpId( HID_SVX_MACRO_LB_EVENT );
883 InitAndSetHandler( xNameReplace, Reference< container::XNameReplace>(0), Reference< util::XModifiable >(0));
884 DisplayAppEvents(true);
885 SvHeaderTabListBox& rListBox = mpImpl->pEventLB->GetListBox();
886 SvLBoxEntry* pE = rListBox.GetEntry( (sal_uLong)nSelectedIndex );
887 if( pE )
888 rListBox.Select(pE);
891 SvxMacroTabPage::~SvxMacroTabPage()
895 SvxMacroAssignDlg::SvxMacroAssignDlg( Window* pParent, const Reference< frame::XFrame >& _rxDocumentFrame, const SfxItemSet& rSet,
896 const Reference< container::XNameReplace >& xNameReplace, sal_uInt16 nSelectedIndex )
897 : SvxMacroAssignSingleTabDialog( pParent, rSet, 0 )
899 SetTabPage( new SvxMacroTabPage( this, _rxDocumentFrame, rSet, xNameReplace, nSelectedIndex ) );
902 SvxMacroAssignDlg::~SvxMacroAssignDlg()
907 //===============================================
909 IMPL_LINK(AssignComponentDialog, ButtonHandler, Button *, EMPTYARG)
911 ::rtl::OUString aMethodName = maMethodEdit.GetText();
912 maURL = ::rtl::OUString();
913 if( aMethodName.getLength() )
915 maURL = aVndSunStarUNO;
916 maURL += aMethodName;
918 EndDialog(1);
919 return 0;
922 AssignComponentDialog::AssignComponentDialog( Window * pParent, const ::rtl::OUString& rURL )
923 : ModalDialog( pParent, CUI_RES( RID_SVXDLG_ASSIGNCOMPONENT ) )
924 , maMethodLabel( this, CUI_RES( FT_METHOD ) )
925 , maMethodEdit( this, CUI_RES( EDIT_METHOD ) )
926 , maOKButton( this, CUI_RES( RID_PB_OK ) )
927 , maCancelButton( this, CUI_RES( RID_PB_CANCEL ) )
928 , maHelpButton( this, CUI_RES( RID_PB_HELP ) )
929 , maURL( rURL )
931 FreeResource();
932 maOKButton.SetClickHdl(LINK(this, AssignComponentDialog, ButtonHandler));
934 ::rtl::OUString aMethodName;
935 if( maURL.getLength() )
937 sal_Int32 nIndex = maURL.indexOf( aVndSunStarUNO );
938 if( nIndex == 0 )
940 sal_Int32 nBegin = aVndSunStarUNO.getLength();
941 aMethodName = maURL.copy( nBegin );
944 maMethodEdit.SetText( aMethodName, Selection( 0, SELECTION_MAX ) );
947 AssignComponentDialog::~AssignComponentDialog()
951 // -----------------------------------------------------------------------
953 IMPL_LINK( SvxMacroAssignSingleTabDialog, OKHdl_Impl, Button *, pButton )
955 (void)pButton; //unused
956 pPage->FillItemSet( *pOutSet );
957 EndDialog( RET_OK );
958 return 0;
961 // -----------------------------------------------------------------------
963 SvxMacroAssignSingleTabDialog::SvxMacroAssignSingleTabDialog
964 ( Window *pParent, const SfxItemSet& rSet, sal_uInt16 nUniqueId ) :
965 SfxModalDialog( pParent, nUniqueId, WinBits( WB_STDMODAL | WB_3DLOOK ) ),
966 pFixedLine ( 0 ),
967 pOKBtn ( 0 ),
968 pCancelBtn ( 0 ),
969 pHelpBtn ( 0 ),
970 pPage ( 0 ),
971 pOptions ( &rSet ),
972 pOutSet ( 0 )
976 // -----------------------------------------------------------------------
978 SvxMacroAssignSingleTabDialog::~SvxMacroAssignSingleTabDialog()
980 delete pFixedLine;
981 delete pOKBtn;
982 delete pCancelBtn;
983 delete pHelpBtn;
984 delete pPage;
987 // -----------------------------------------------------------------------
989 // According to SfxSingleTabDialog
990 void SvxMacroAssignSingleTabDialog::SetTabPage( SfxTabPage* pTabPage )
992 pFixedLine = new FixedLine( this );
994 pOKBtn = new OKButton( this, WB_DEFBUTTON );
995 pOKBtn->SetClickHdl( LINK( this, SvxMacroAssignSingleTabDialog, OKHdl_Impl ) );
997 pCancelBtn = new CancelButton( this );
998 pHelpBtn = new HelpButton( this );
1000 pPage = pTabPage;
1002 if ( pPage )
1004 String sUserData;
1005 pPage->SetUserData( sUserData );
1006 pPage->Reset( *pOptions );
1007 pPage->Show();
1009 // Set dialog's and buttons' size and position according to tabpage size
1010 long nSpaceX = LogicToPixel( Size( 6, 0 ), MAP_APPFONT ).Width();
1011 long nSpaceY = LogicToPixel( Size( 0, 6 ), MAP_APPFONT ).Height();
1012 long nHalfSpaceX = LogicToPixel( Size( 3, 0 ), MAP_APPFONT ).Width();
1013 long nHalfSpaceY = LogicToPixel( Size( 0, 3 ), MAP_APPFONT ).Height();
1015 pPage->SetPosPixel( Point() );
1016 Size aTabpageSize( pPage->GetSizePixel() );
1017 Size aDialogSize( aTabpageSize );
1018 Size aButtonSize = LogicToPixel( Size( 50, 14 ), MAP_APPFONT );
1019 long nButtonWidth = aButtonSize.Width();
1020 long nButtonHeight = aButtonSize.Height();
1022 Size aFixedLineSize( aTabpageSize );
1023 long nFixedLineHeight = LogicToPixel( Size( 0, 8 ), MAP_APPFONT ).Height();
1024 aFixedLineSize.Height() = nFixedLineHeight;
1026 aDialogSize.Height() += nFixedLineHeight + nButtonHeight + nSpaceY + nHalfSpaceY;
1027 SetOutputSizePixel( aDialogSize );
1029 long nButtonPosY = aTabpageSize.Height() + nFixedLineHeight + nHalfSpaceY;
1030 long nHelpButtonPosX = nSpaceX;
1031 pHelpBtn->SetPosSizePixel( Point( nHelpButtonPosX, nButtonPosY), aButtonSize );
1032 pHelpBtn->Show();
1034 long nCancelButtonPosX = aDialogSize.Width() - nButtonWidth - nSpaceX + 1;
1035 pCancelBtn->SetPosSizePixel( Point( nCancelButtonPosX, nButtonPosY), aButtonSize );
1036 pCancelBtn->Show();
1038 long nOkButtonPosX = nCancelButtonPosX - nButtonWidth - nHalfSpaceX;
1039 pOKBtn->SetPosSizePixel( Point( nOkButtonPosX, nButtonPosY), aButtonSize );
1040 pOKBtn->Show();
1042 long nFixedLinePosY = aTabpageSize.Height();
1043 pFixedLine->SetPosSizePixel( Point( 0, nFixedLinePosY), aFixedLineSize );
1044 pFixedLine->Show();
1046 // Get text from TabPage
1047 SetText( pPage->GetText() );
1049 // Get IDs from TabPage
1050 SetHelpId( pPage->GetHelpId() );
1051 SetUniqueId( pPage->GetUniqueId() );