merge the formfield patch from ooo-build
[ooovba.git] / svx / source / cui / macropg.cxx
blobf705df676b038cafcfe2bd1f87a9cac50b4cb73e
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.22.166.2 $
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"
33 #include <basic/basmgr.hxx>
36 #include "macropg.hxx"
37 #include <vcl/msgbox.hxx>
38 #define _SVSTDARR_STRINGSDTOR
39 #include <svtools/svstdarr.hxx>
40 #ifndef _SV_MEDIT_HXX
41 #include <svtools/svmedit.hxx>
42 #endif
43 #ifndef _EITEM_HXX
44 #include <svtools/eitem.hxx>
45 #endif
46 #include <tools/diagnose_ex.h>
48 #include <sfx2/app.hxx>
49 #include <sfx2/objsh.hxx>
50 #include <sfx2/macrconf.hxx>
51 #include <sfx2/sfxdefs.hxx>
53 #include <com/sun/star/container/NoSuchElementException.hpp>
54 #include <com/sun/star/lang/IllegalArgumentException.hpp>
56 #include <svx/dialmgr.hxx>
57 #include "selector.hxx"
58 #include "cfg.hxx"
59 #include "macropg.hrc"
60 #include "helpid.hrc"
61 #include <svx/dialogs.hrc>
62 #include "headertablistbox.hxx"
63 #include "macropg_impl.hxx"
65 #include <comphelper/namedvaluecollection.hxx>
67 #include <algorithm>
68 #include <set>
70 using namespace ::com::sun::star;
71 using namespace ::com::sun::star::uno;
73 static ::rtl::OUString aVndSunStarUNO =
74 ::rtl::OUString::createFromAscii( "vnd.sun.star.UNO:" );
75 static ::rtl::OUString aVndSunStarScript =
76 ::rtl::OUString::createFromAscii( "vnd.sun.star.script:" );
78 _SvxMacroTabPage_Impl::_SvxMacroTabPage_Impl( const SfxItemSet& rAttrSet ) :
79 pAssignFT( NULL ),
80 pAssignPB( NULL ),
81 pAssignComponentPB( NULL ),
82 pDeletePB( NULL ),
83 pMacroImg( NULL ),
84 pComponentImg( NULL ),
85 pMacroImg_h( NULL ),
86 pComponentImg_h( NULL ),
87 pStrEvent( NULL ),
88 pAssignedMacro( NULL ),
89 pEventLB( NULL ),
90 bReadOnly( FALSE ),
91 bIDEDialogMode( FALSE )
93 const SfxPoolItem* pItem;
94 if ( SFX_ITEM_SET == rAttrSet.GetItemState( SID_ATTR_MACROITEM, FALSE, &pItem ) )
95 bIDEDialogMode = ((const SfxBoolItem*)pItem)->GetValue();
98 _SvxMacroTabPage_Impl::~_SvxMacroTabPage_Impl()
100 delete pAssignFT;
101 delete pAssignPB;
102 delete pAssignComponentPB;
103 delete pDeletePB;
104 delete pMacroImg;
105 delete pComponentImg;
106 delete pMacroImg_h;
107 delete pComponentImg_h;
108 delete pStrEvent;
109 delete pAssignedMacro;
110 delete pEventLB;
113 // Achtung im Code wird dieses Array direkt (0, 1, ...) indiziert
114 static long nTabs[] =
116 2, // Number of Tabs
117 0, 90
120 #define TAB_WIDTH_MIN 10
122 // IDs for items in HeaderBar of EventLB
123 #define ITEMID_EVENT 1
124 #define ITMEID_ASSMACRO 2
127 #define LB_EVENTS_ITEMPOS 1
128 #define LB_MACROS_ITEMPOS 2
131 IMPL_LINK( _HeaderTabListBox, HeaderEndDrag_Impl, HeaderBar*, pBar )
133 DBG_ASSERT( pBar == &maHeaderBar, "*_HeaderTabListBox::HeaderEndDrag_Impl: something is wrong here..." );
134 (void)pBar;
136 if( !maHeaderBar.GetCurItemId() )
137 return 0;
139 if( !maHeaderBar.IsItemMode() )
141 Size aSz;
142 USHORT _nTabs = maHeaderBar.GetItemCount();
143 long nTmpSz = 0;
144 long nWidth = maHeaderBar.GetItemSize( ITEMID_EVENT );
145 long nBarWidth = maHeaderBar.GetSizePixel().Width();
147 if( nWidth < TAB_WIDTH_MIN )
148 maHeaderBar.SetItemSize( ITEMID_EVENT, TAB_WIDTH_MIN );
149 else if( ( nBarWidth - nWidth ) < TAB_WIDTH_MIN )
150 maHeaderBar.SetItemSize( ITEMID_EVENT, nBarWidth - TAB_WIDTH_MIN );
153 long _nWidth;
154 for( USHORT i = 1 ; i < _nTabs ; ++i )
156 _nWidth = maHeaderBar.GetItemSize( i );
157 aSz.Width() = _nWidth + nTmpSz;
158 nTmpSz += _nWidth;
159 maListBox.SetTab( i, PixelToLogic( aSz, MapMode( MAP_APPFONT ) ).Width(), MAP_APPFONT );
163 return 1;
166 long _HeaderTabListBox::Notify( NotifyEvent& rNEvt )
168 long nRet = Control::Notify( rNEvt );
170 if( rNEvt.GetType() == EVENT_GETFOCUS )
172 if ( rNEvt.GetWindow() != &maListBox )
173 maListBox.GrabFocus();
176 return nRet;
179 _HeaderTabListBox::_HeaderTabListBox( Window* pParent, const ResId& rId ) :
180 Control( pParent, rId ),
181 maListBox( this, WB_HSCROLL | WB_CLIPCHILDREN | WB_TABSTOP ),
182 maHeaderBar( this, WB_BUTTONSTYLE | WB_BOTTOMBORDER )
184 // maListBox.SetWindowBits( WB_HSCROLL | WB_CLIPCHILDREN | WB_TABSTOP );
187 _HeaderTabListBox::~_HeaderTabListBox()
191 void _HeaderTabListBox::ConnectElements( void )
193 // calc pos and size of header bar
194 Point aPnt( 0, 0 );
195 Size aSize( maHeaderBar.CalcWindowSizePixel() );
196 Size aCtrlSize( GetOutputSizePixel() );
197 aSize.Width() = aCtrlSize.Width();
198 maHeaderBar.SetPosSizePixel( aPnt, aSize );
200 // calc pos and size of ListBox
201 aPnt.Y() += aSize.Height();
202 aSize.Height() = aCtrlSize.Height() - aSize.Height();
203 maListBox.SetPosSizePixel( aPnt, aSize );
205 // set handler
206 maHeaderBar.SetEndDragHdl( LINK( this, _HeaderTabListBox, HeaderEndDrag_Impl ) );
208 maListBox.InitHeaderBar( &maHeaderBar );
211 void _HeaderTabListBox::Show( BOOL bVisible, USHORT nFlags )
213 maListBox.Show( bVisible, nFlags );
214 maHeaderBar.Show( bVisible, nFlags );
217 void _HeaderTabListBox::Enable( bool bEnable, bool bChild )
219 maListBox.Enable( bEnable, bChild );
220 maHeaderBar.Enable( bEnable, bChild );
223 // assign button ("Add Command") is enabled only if it is not read only
224 // delete button ("Remove Command") is enabled if a current binding exists
225 // and it is not read only
226 void _SvxMacroTabPage::EnableButtons( const String& /*rLangName*/ )
228 const SvLBoxEntry* pE = mpImpl->pEventLB->GetListBox().FirstSelected();
229 if ( pE )
231 SvLBoxString* pEventMacro = (SvLBoxString*)pE->GetItem( LB_MACROS_ITEMPOS );
232 mpImpl->pDeletePB->Enable( 0 != pEventMacro && !mpImpl->bReadOnly );
234 mpImpl->pAssignPB->Enable( !mpImpl->bReadOnly );
235 if( mpImpl->pAssignComponentPB )
236 mpImpl->pAssignComponentPB->Enable( !mpImpl->bReadOnly );
240 _SvxMacroTabPage::_SvxMacroTabPage( Window* pParent, const ResId& rResId, const SfxItemSet& rAttrSet )
241 : SfxTabPage( pParent, rResId, rAttrSet ),
242 m_xAppEvents(0),
243 m_xDocEvents(0),
244 bReadOnly(false),
245 bDocModified(false),
246 bAppEvents(false),
247 bInitialized(false)
249 mpImpl = new _SvxMacroTabPage_Impl( rAttrSet );
252 _SvxMacroTabPage::~_SvxMacroTabPage()
254 // need to delete the user data
255 SvHeaderTabListBox& rListBox = mpImpl->pEventLB->GetListBox();
256 SvLBoxEntry* pE = rListBox.GetEntry( 0 );
257 while( pE )
259 ::rtl::OUString* pEventName = (::rtl::OUString*)pE->GetUserData();
260 delete pEventName;
261 pE->SetUserData((void*)0);
262 pE = rListBox.NextSibling( pE );
264 DELETEZ( mpImpl );
266 // -----------------------------------------------------------------------------
267 void _SvxMacroTabPage::InitResources()
269 // Note: the order here controls the order in which the events are displayed in the UI!
271 // the event name to UI string mappings for App Events
272 aDisplayNames.push_back( EventDisplayName( "OnStartApp", RID_SVXSTR_EVENT_STARTAPP ) );
273 aDisplayNames.push_back( EventDisplayName( "OnCloseApp", RID_SVXSTR_EVENT_CLOSEAPP ) );
274 aDisplayNames.push_back( EventDisplayName( "OnCreate", RID_SVXSTR_EVENT_CREATEDOC ) );
275 aDisplayNames.push_back( EventDisplayName( "OnNew", RID_SVXSTR_EVENT_NEWDOC ) );
276 aDisplayNames.push_back( EventDisplayName( "OnLoadFinished", RID_SVXSTR_EVENT_LOADDOCFINISHED ) );
277 aDisplayNames.push_back( EventDisplayName( "OnLoad", RID_SVXSTR_EVENT_OPENDOC ) );
278 aDisplayNames.push_back( EventDisplayName( "OnPrepareUnload", RID_SVXSTR_EVENT_PREPARECLOSEDOC ) );
279 aDisplayNames.push_back( EventDisplayName( "OnUnload", RID_SVXSTR_EVENT_CLOSEDOC ) ) ;
280 aDisplayNames.push_back( EventDisplayName( "OnViewCreated", RID_SVXSTR_EVENT_VIEWCREATED ) );
281 aDisplayNames.push_back( EventDisplayName( "OnPrepareViewClosing", RID_SVXSTR_EVENT_PREPARECLOSEVIEW ) );
282 aDisplayNames.push_back( EventDisplayName( "OnViewClosed", RID_SVXSTR_EVENT_CLOSEVIEW ) ) ;
283 aDisplayNames.push_back( EventDisplayName( "OnFocus", RID_SVXSTR_EVENT_ACTIVATEDOC ) );
284 aDisplayNames.push_back( EventDisplayName( "OnUnfocus", RID_SVXSTR_EVENT_DEACTIVATEDOC ) );
285 aDisplayNames.push_back( EventDisplayName( "OnSave", RID_SVXSTR_EVENT_SAVEDOC ) );
286 aDisplayNames.push_back( EventDisplayName( "OnSaveDone", RID_SVXSTR_EVENT_SAVEDOCDONE ) );
287 aDisplayNames.push_back( EventDisplayName( "OnSaveFailed", RID_SVXSTR_EVENT_SAVEDOCFAILED ) );
288 aDisplayNames.push_back( EventDisplayName( "OnSaveAs", RID_SVXSTR_EVENT_SAVEASDOC ) );
289 aDisplayNames.push_back( EventDisplayName( "OnSaveAsDone", RID_SVXSTR_EVENT_SAVEASDOCDONE ) );
290 aDisplayNames.push_back( EventDisplayName( "OnSaveAsFailed", RID_SVXSTR_EVENT_SAVEASDOCFAILED ) );
291 aDisplayNames.push_back( EventDisplayName( "OnCopyTo", RID_SVXSTR_EVENT_COPYTODOC ) );
292 aDisplayNames.push_back( EventDisplayName( "OnCopyToDone", RID_SVXSTR_EVENT_COPYTODOCDONE ) );
293 aDisplayNames.push_back( EventDisplayName( "OnCopyToFailed", RID_SVXSTR_EVENT_COPYTODOCFAILED ) );
294 aDisplayNames.push_back( EventDisplayName( "OnPrint", RID_SVXSTR_EVENT_PRINTDOC ) );
295 aDisplayNames.push_back( EventDisplayName( "OnModifyChanged", RID_SVXSTR_EVENT_MODIFYCHANGED ) );
296 aDisplayNames.push_back( EventDisplayName( "OnTitleChanged", RID_SVXSTR_EVENT_TITLECHANGED ) );
297 // aDisplayNames.push_back( EventDisplayName( "OnModeChanged", RID_SVXSTR_EVENT_MODECHANGED ) );
298 // aDisplayNames.push_back( EventDisplayName( "OnVisAreaChanged", RID_SVXSTR_EVENT_VISAREACHANGED ) );
299 // aDisplayNames.push_back( EventDisplayName( "OnStorageChanged", RID_SVXSTR_EVENT_STORAGECHANGED ) );
301 // application specific events
302 aDisplayNames.push_back( EventDisplayName( "OnMailMerge", RID_SVXSTR_EVENT_MAILMERGE ) );
303 aDisplayNames.push_back( EventDisplayName( "OnMailMergeFinished", RID_SVXSTR_EVENT_MAILMERGE_END ) );
304 aDisplayNames.push_back( EventDisplayName( "OnFieldMerge", RID_SVXSTR_EVENT_FIELDMERGE ) );
305 aDisplayNames.push_back( EventDisplayName( "OnFieldMergeFinished", RID_SVXSTR_EVENT_FIELDMERGE_FINISHED ) );
306 aDisplayNames.push_back( EventDisplayName( "OnPageCountChange", RID_SVXSTR_EVENT_PAGECOUNTCHANGE ) );
307 aDisplayNames.push_back( EventDisplayName( "OnSubComponentOpened", RID_SVXSTR_EVENT_SUBCOMPONENT_OPENED ) );
308 aDisplayNames.push_back( EventDisplayName( "OnSubComponentClosed", RID_SVXSTR_EVENT_SUBCOMPONENT_CLOSED ) );
309 // aDisplayNames.push_back( EventDisplayName( "OnLayoutFinished", RID_SVXSTR_EVENT_LAYOUT_FINISHED ) );
311 // the event name to UI string mappings for forms & dialogs
313 aDisplayNames.push_back( EventDisplayName( "approveAction", RID_SVXSTR_EVENT_APPROVEACTIONPERFORMED ) );
314 aDisplayNames.push_back( EventDisplayName( "actionPerformed", RID_SVXSTR_EVENT_ACTIONPERFORMED ) );
315 aDisplayNames.push_back( EventDisplayName( "changed", RID_SVXSTR_EVENT_CHANGED ) );
316 aDisplayNames.push_back( EventDisplayName( "textChanged", RID_SVXSTR_EVENT_TEXTCHANGED ) );
317 aDisplayNames.push_back( EventDisplayName( "itemStateChanged", RID_SVXSTR_EVENT_ITEMSTATECHANGED ) );
318 aDisplayNames.push_back( EventDisplayName( "focusGained", RID_SVXSTR_EVENT_FOCUSGAINED ) );
319 aDisplayNames.push_back( EventDisplayName( "focusLost", RID_SVXSTR_EVENT_FOCUSLOST ) );
320 aDisplayNames.push_back( EventDisplayName( "keyPressed", RID_SVXSTR_EVENT_KEYTYPED ) );
321 aDisplayNames.push_back( EventDisplayName( "keyReleased", RID_SVXSTR_EVENT_KEYUP ) );
322 aDisplayNames.push_back( EventDisplayName( "mouseEntered", RID_SVXSTR_EVENT_MOUSEENTERED ) );
323 aDisplayNames.push_back( EventDisplayName( "mouseDragged", RID_SVXSTR_EVENT_MOUSEDRAGGED ) );
324 aDisplayNames.push_back( EventDisplayName( "mouseMoved", RID_SVXSTR_EVENT_MOUSEMOVED ) );
325 aDisplayNames.push_back( EventDisplayName( "mousePressed", RID_SVXSTR_EVENT_MOUSEPRESSED ) );
326 aDisplayNames.push_back( EventDisplayName( "mouseReleased", RID_SVXSTR_EVENT_MOUSERELEASED ) );
327 aDisplayNames.push_back( EventDisplayName( "mouseExited", RID_SVXSTR_EVENT_MOUSEEXITED ) );
328 aDisplayNames.push_back( EventDisplayName( "approveReset", RID_SVXSTR_EVENT_APPROVERESETTED ) );
329 aDisplayNames.push_back( EventDisplayName( "resetted", RID_SVXSTR_EVENT_RESETTED ) );
330 aDisplayNames.push_back( EventDisplayName( "approveSubmit", RID_SVXSTR_EVENT_SUBMITTED ) );
331 aDisplayNames.push_back( EventDisplayName( "approveUpdate", RID_SVXSTR_EVENT_BEFOREUPDATE ) );
332 aDisplayNames.push_back( EventDisplayName( "updated", RID_SVXSTR_EVENT_AFTERUPDATE ) );
333 aDisplayNames.push_back( EventDisplayName( "loaded", RID_SVXSTR_EVENT_LOADED ) );
334 aDisplayNames.push_back( EventDisplayName( "reloading", RID_SVXSTR_EVENT_RELOADING ) );
335 aDisplayNames.push_back( EventDisplayName( "reloaded", RID_SVXSTR_EVENT_RELOADED ) );
336 aDisplayNames.push_back( EventDisplayName( "unloading", RID_SVXSTR_EVENT_UNLOADING ) );
337 aDisplayNames.push_back( EventDisplayName( "unloaded", RID_SVXSTR_EVENT_UNLOADED ) );
338 aDisplayNames.push_back( EventDisplayName( "confirmDelete", RID_SVXSTR_EVENT_CONFIRMDELETE ) );
339 aDisplayNames.push_back( EventDisplayName( "approveRowChange", RID_SVXSTR_EVENT_APPROVEROWCHANGE ) );
340 aDisplayNames.push_back( EventDisplayName( "rowChanged", RID_SVXSTR_EVENT_ROWCHANGE ) );
341 aDisplayNames.push_back( EventDisplayName( "approveCursorMove", RID_SVXSTR_EVENT_POSITIONING ) );
342 aDisplayNames.push_back( EventDisplayName( "cursorMoved", RID_SVXSTR_EVENT_POSITIONED ) );
343 aDisplayNames.push_back( EventDisplayName( "approveParameter", RID_SVXSTR_EVENT_APPROVEPARAMETER ) );
344 aDisplayNames.push_back( EventDisplayName( "errorOccured", RID_SVXSTR_EVENT_ERROROCCURED ) );
345 aDisplayNames.push_back( EventDisplayName( "adjustmentValueChanged", RID_SVXSTR_EVENT_ADJUSTMENTVALUECHANGED ) );
348 // the following method is called when the user clicks OK
349 // We use the contents of the hashes to replace the settings
350 BOOL _SvxMacroTabPage::FillItemSet( SfxItemSet& /*rSet*/ )
354 ::rtl::OUString eventName;
355 if( m_xAppEvents.is() )
357 EventsHash::iterator h_itEnd = m_appEventsHash.end();
358 EventsHash::iterator h_it = m_appEventsHash.begin();
359 for ( ; h_it != h_itEnd; ++h_it )
361 eventName = h_it->first;
364 m_xAppEvents->replaceByName( eventName, GetPropsByName( eventName, m_appEventsHash ) );
366 catch( const Exception& )
368 DBG_UNHANDLED_EXCEPTION();
372 if( m_xDocEvents.is() && bDocModified )
374 EventsHash::iterator h_itEnd = m_docEventsHash.end();
375 EventsHash::iterator h_it = m_docEventsHash.begin();
376 for ( ; h_it != h_itEnd; ++h_it )
378 eventName = h_it->first;
381 m_xDocEvents->replaceByName( eventName, GetPropsByName( eventName, m_docEventsHash ) );
383 catch( const Exception& )
385 DBG_UNHANDLED_EXCEPTION();
388 // if we have a valid XModifiable (in the case of doc events)
389 // call setModified(true)
390 // in principle this should not be necessary (see issue ??)
391 if(m_xModifiable.is())
393 m_xModifiable->setModified( sal_True );
397 catch(Exception&)
400 // what is the return value about??
401 return FALSE;
404 // the following method clears the bindings in the hashes for both doc & app
405 void _SvxMacroTabPage::Reset()
407 // called once in creation - don't reset the data this time
408 if(!bInitialized)
410 bInitialized = true;
411 return;
416 ::rtl::OUString sEmpty;
417 if( m_xAppEvents.is() )
419 EventsHash::iterator h_itEnd = m_appEventsHash.end();
420 EventsHash::iterator h_it = m_appEventsHash.begin();
421 for ( ; h_it != h_itEnd; ++h_it )
423 h_it->second.second = sEmpty;
426 if( m_xDocEvents.is() && bDocModified )
428 EventsHash::iterator h_itEnd = m_docEventsHash.end();
429 EventsHash::iterator h_it = m_docEventsHash.begin();
430 for ( ; h_it != h_itEnd; ++h_it )
432 h_it->second.second = sEmpty;
434 // if we have a valid XModifiable (in the case of doc events)
435 // call setModified(true)
436 if(m_xModifiable.is())
438 m_xModifiable->setModified( sal_True );
442 catch(Exception&)
445 DisplayAppEvents(bAppEvents);
448 void _SvxMacroTabPage::SetReadOnly( BOOL bSet )
450 mpImpl->bReadOnly = bSet;
453 BOOL _SvxMacroTabPage::IsReadOnly() const
455 return mpImpl->bReadOnly;
459 class IconLBoxString : public SvLBoxString
461 Image* m_pMacroImg;
462 Image* m_pComponentImg;
463 Image* m_pMacroImg_h;
464 Image* m_pComponentImg_h;
465 int m_nxImageOffset;
467 public:
468 IconLBoxString( SvLBoxEntry* pEntry, USHORT nFlags, const String& sText,
469 Image* pMacroImg, Image* pComponentImg,
470 Image* pMacroImg_h, Image* pComponentImg_h );
471 virtual void Paint(const Point& aPos, SvLBox& aDevice, USHORT nFlags, SvLBoxEntry* pEntry );
475 IconLBoxString::IconLBoxString( SvLBoxEntry* pEntry, USHORT nFlags, const String& sText,
476 Image* pMacroImg, Image* pComponentImg, Image* pMacroImg_h, Image* pComponentImg_h )
477 : SvLBoxString( pEntry, nFlags, sText )
478 , m_pMacroImg( pMacroImg )
479 , m_pComponentImg( pComponentImg )
480 , m_pMacroImg_h( pMacroImg_h )
481 , m_pComponentImg_h( pComponentImg_h )
483 m_nxImageOffset = 20;
486 //===============================================
487 void IconLBoxString::Paint( const Point& aPos, SvLBox& aDevice,
488 USHORT /*nFlags*/, SvLBoxEntry* /*pEntry*/ )
490 String aTxt( GetText() );
491 if( aTxt.Len() )
493 ::rtl::OUString aURL( aTxt );
494 sal_Int32 nIndex = aURL.indexOf( aVndSunStarUNO );
495 bool bUNO = nIndex == 0;
497 Wallpaper aBackground = aDevice.GetBackground();
498 Color aColor = aBackground.GetColor();
499 BOOL bHC = aColor.IsDark();
500 const Image* pImg;
501 if( bHC )
502 pImg = bUNO ? m_pComponentImg_h : m_pMacroImg_h;
503 else
504 pImg = bUNO ? m_pComponentImg : m_pMacroImg;
505 aDevice.DrawImage( aPos, *pImg );
507 ::rtl::OUString aPureMethod;
508 if( bUNO )
510 sal_Int32 nBegin = aVndSunStarUNO.getLength();
511 aPureMethod = aURL.copy( nBegin );
513 else
515 sal_Int32 nBegin = aVndSunStarScript.getLength();
516 aPureMethod = aURL.copy( nBegin );
517 aPureMethod = aPureMethod.copy( 0, aPureMethod.indexOf( '?' ) );
520 Point aPnt(aPos);
521 aPnt.X() += m_nxImageOffset;
522 aDevice.DrawText( aPnt, aPureMethod );
527 // displays the app events if appEvents=true, otherwise displays the doc events
528 void _SvxMacroTabPage::DisplayAppEvents( bool appEvents)
530 bAppEvents = appEvents;
532 SvHeaderTabListBox& rListBox = mpImpl->pEventLB->GetListBox();
533 mpImpl->pEventLB->SetUpdateMode( FALSE );
534 rListBox.Clear();
535 SvLBoxEntry* pE = rListBox.GetEntry( 0 );
536 EventsHash* eventsHash;
537 Reference< container::XNameReplace> nameReplace;
538 if(bAppEvents)
540 eventsHash = &m_appEventsHash;
541 nameReplace = m_xAppEvents;
543 else
545 eventsHash = &m_docEventsHash;
546 nameReplace = m_xDocEvents;
548 // have to use the original XNameReplace since the hash iterators do
549 // not guarantee the order in which the elements are returned
550 if(!nameReplace.is())
552 return;
555 Sequence< ::rtl::OUString > eventNames = nameReplace->getElementNames();
556 ::std::set< ::rtl::OUString > aEventNamesCache;
557 ::std::copy(
558 eventNames.getConstArray(),
559 eventNames.getConstArray() + eventNames.getLength(),
560 ::std::insert_iterator< ::std::set< ::rtl::OUString > >( aEventNamesCache, aEventNamesCache.end() )
563 for ( EventDisplayNames::const_iterator displayableEvent = aDisplayNames.begin();
564 displayableEvent != aDisplayNames.end();
565 ++displayableEvent
568 ::rtl::OUString sEventName( ::rtl::OUString::createFromAscii( displayableEvent->pAsciiEventName ) );
569 if ( !nameReplace->hasByName( sEventName ) )
570 continue;
572 EventsHash::iterator h_it = eventsHash->find( sEventName );
573 if( h_it == eventsHash->end() )
575 OSL_ENSURE( false, "_SvxMacroTabPage::DisplayAppEvents: something's suspicious here!" );
576 continue;
579 ::rtl::OUString eventURL = h_it->second.second;
580 String displayName( SVX_RES( displayableEvent->nEventResourceID ) );
582 displayName += '\t';
583 SvLBoxEntry* _pE = rListBox.InsertEntry( displayName );
584 ::rtl::OUString* pEventName = new ::rtl::OUString( sEventName );
585 _pE->SetUserData( (void*)pEventName );
586 String sNew( eventURL );
587 _pE->ReplaceItem( new IconLBoxString( _pE, 0, sNew,
588 mpImpl->pMacroImg, mpImpl->pComponentImg,
589 mpImpl->pMacroImg_h, mpImpl->pComponentImg_h ), LB_MACROS_ITEMPOS );
590 rListBox.GetModel()->InvalidateEntry( _pE );
591 rListBox.Select( _pE );
592 rListBox.MakeVisible( _pE );
595 pE = rListBox.GetEntry(0);
596 if( pE )
598 rListBox.Select( pE );
599 rListBox.MakeVisible( pE );
602 rListBox.SetUpdateMode( TRUE );
603 EnableButtons( String() );
606 // select event handler on the listbox
607 IMPL_STATIC_LINK( _SvxMacroTabPage, SelectEvent_Impl, SvTabListBox*, EMPTYARG )
609 _SvxMacroTabPage_Impl* pImpl = pThis->mpImpl;
610 SvHeaderTabListBox& rListBox = pImpl->pEventLB->GetListBox();
611 SvLBoxEntry* pE = rListBox.FirstSelected();
612 ULONG nPos;
614 if( !pE || LISTBOX_ENTRY_NOTFOUND ==
615 ( nPos = rListBox.GetModel()->GetAbsPos( pE ) ) )
617 DBG_ASSERT( pE, "wo kommt der leere Eintrag her?" );
618 return 0;
621 pThis->EnableButtons( String() );
622 return 0;
625 IMPL_STATIC_LINK( _SvxMacroTabPage, AssignDeleteHdl_Impl, PushButton*, pBtn )
627 return GenericHandler_Impl( pThis, pBtn );
630 IMPL_STATIC_LINK( _SvxMacroTabPage, DoubleClickHdl_Impl, SvTabListBox *, EMPTYARG )
632 return GenericHandler_Impl( pThis, NULL );
635 // handler for double click on the listbox, and for the assign/delete buttons
636 long _SvxMacroTabPage::GenericHandler_Impl( _SvxMacroTabPage* pThis, PushButton* pBtn )
638 _SvxMacroTabPage_Impl* pImpl = pThis->mpImpl;
639 SvHeaderTabListBox& rListBox = pImpl->pEventLB->GetListBox();
640 SvLBoxEntry* pE = rListBox.FirstSelected();
641 ULONG nPos;
642 if( !pE || LISTBOX_ENTRY_NOTFOUND ==
643 ( nPos = rListBox.GetModel()->GetAbsPos( pE ) ) )
645 DBG_ASSERT( pE, "wo kommt der leere Eintrag her?" );
646 return 0;
649 const BOOL bAssEnabled = pBtn != pImpl->pDeletePB && pImpl->pAssignPB->IsEnabled();
651 ::rtl::OUString* pEventName = (::rtl::OUString*)pE->GetUserData();
653 ::rtl::OUString sEventURL;
654 ::rtl::OUString sEventType;
655 if(pThis->bAppEvents)
657 EventsHash::iterator h_it = pThis->m_appEventsHash.find( *pEventName );
658 if(h_it != pThis->m_appEventsHash.end() )
660 sEventType = h_it->second.first;
661 sEventURL = h_it->second.second;
664 else
666 EventsHash::iterator h_it = pThis->m_docEventsHash.find( *pEventName );
667 if(h_it != pThis->m_docEventsHash.end() )
669 sEventType = h_it->second.first;
670 sEventURL = h_it->second.second;
674 bool bDoubleClick = (pBtn == NULL);
675 bool bUNOAssigned = (sEventURL.indexOf( aVndSunStarUNO ) == 0);
676 if( pBtn == pImpl->pDeletePB )
678 // delete pressed
679 sEventType = ::rtl::OUString::createFromAscii("Script");
680 sEventURL = ::rtl::OUString();
681 if(!pThis->bAppEvents)
682 pThis->bDocModified = true;
684 else if ( ( ( pBtn != NULL )
685 && ( pBtn == pImpl->pAssignComponentPB )
687 || ( bDoubleClick
688 && bUNOAssigned
692 AssignComponentDialog* pAssignDlg = new AssignComponentDialog( pThis, sEventURL );
694 short ret = pAssignDlg->Execute();
695 if( ret )
697 sEventType = ::rtl::OUString::createFromAscii("UNO");
698 sEventURL = pAssignDlg->getURL();
699 if(!pThis->bAppEvents)
700 pThis->bDocModified = true;
702 delete pAssignDlg;
704 else if( bAssEnabled )
706 // assign pressed
707 SvxScriptSelectorDialog* pDlg = new SvxScriptSelectorDialog( pThis, FALSE, pThis->GetFrame() );
708 if( pDlg )
710 short ret = pDlg->Execute();
711 if ( ret )
713 sEventType = ::rtl::OUString::createFromAscii("Script");
714 sEventURL = pDlg->GetScriptURL();
715 if(!pThis->bAppEvents)
716 pThis->bDocModified = true;
721 // update the hashes
722 if(pThis->bAppEvents)
724 EventsHash::iterator h_it = pThis->m_appEventsHash.find( *pEventName );
725 h_it->second.first = sEventType;
726 h_it->second.second = sEventURL;
728 else
730 EventsHash::iterator h_it = pThis->m_docEventsHash.find( *pEventName );
731 h_it->second.first = sEventType;
732 h_it->second.second = sEventURL;
735 // update the listbox entry
736 pImpl->pEventLB->SetUpdateMode( FALSE );
737 // pE->ReplaceItem( new SvLBoxString( pE, 0, sEventURL ), LB_MACROS_ITEMPOS );
738 pE->ReplaceItem( new IconLBoxString( pE, 0, sEventURL,
739 pImpl->pMacroImg, pImpl->pComponentImg,
740 pImpl->pMacroImg_h, pImpl->pComponentImg_h ), LB_MACROS_ITEMPOS );
742 rListBox.GetModel()->InvalidateEntry( pE );
743 rListBox.Select( pE );
744 rListBox.MakeVisible( pE );
745 rListBox.SetUpdateMode( TRUE );
747 pThis->EnableButtons( String() );
748 return 0;
751 // pass in the XNameReplace.
752 // can remove the 3rd arg once issue ?? is fixed
753 void _SvxMacroTabPage::InitAndSetHandler( Reference< container::XNameReplace> xAppEvents, Reference< container::XNameReplace> xDocEvents, Reference< util::XModifiable > xModifiable )
755 m_xAppEvents = xAppEvents;
756 m_xDocEvents = xDocEvents;
757 m_xModifiable = xModifiable;
758 SvHeaderTabListBox& rListBox = mpImpl->pEventLB->GetListBox();
759 HeaderBar& rHeaderBar = mpImpl->pEventLB->GetHeaderBar();
760 Link aLnk(STATIC_LINK(this, _SvxMacroTabPage, AssignDeleteHdl_Impl ));
761 mpImpl->pDeletePB->SetClickHdl( aLnk );
762 mpImpl->pAssignPB->SetClickHdl( aLnk );
763 if( mpImpl->pAssignComponentPB )
764 mpImpl->pAssignComponentPB->SetClickHdl( aLnk );
765 rListBox.SetDoubleClickHdl( STATIC_LINK(this, _SvxMacroTabPage, DoubleClickHdl_Impl ) );
767 rListBox.SetSelectHdl( STATIC_LINK( this, _SvxMacroTabPage, SelectEvent_Impl ));
769 rListBox.SetSelectionMode( SINGLE_SELECTION );
770 rListBox.SetTabs( &nTabs[0], MAP_APPFONT );
771 Size aSize( nTabs[ 2 ], 0 );
772 rHeaderBar.InsertItem( ITEMID_EVENT, *mpImpl->pStrEvent, LogicToPixel( aSize, MapMode( MAP_APPFONT ) ).Width() );
773 aSize.Width() = 1764; // don't know what, so 42^2 is best to use...
774 rHeaderBar.InsertItem( ITMEID_ASSMACRO, *mpImpl->pAssignedMacro, LogicToPixel( aSize, MapMode( MAP_APPFONT ) ).Width() );
775 rListBox.SetSpaceBetweenEntries( 0 );
777 mpImpl->pEventLB->Show();
778 mpImpl->pEventLB->ConnectElements();
780 long nMinLineHeight = mpImpl->pMacroImg->GetSizePixel().Height() + 2;
781 if( nMinLineHeight > mpImpl->pEventLB->GetListBox().GetEntryHeight() )
782 mpImpl->pEventLB->GetListBox().SetEntryHeight(
783 sal::static_int_cast< short >(nMinLineHeight) );
785 mpImpl->pEventLB->Enable( TRUE );
787 if(!m_xAppEvents.is())
789 return;
791 Sequence< ::rtl::OUString > eventNames = m_xAppEvents->getElementNames();
792 sal_Int32 nEventCount = eventNames.getLength();
793 for(sal_Int32 nEvent = 0; nEvent < nEventCount; ++nEvent )
795 //need exception handling here
798 m_appEventsHash[ eventNames[nEvent] ] = GetPairFromAny( m_xAppEvents->getByName( eventNames[nEvent] ) );
800 catch (Exception e)
803 if(m_xDocEvents.is())
805 eventNames = m_xDocEvents->getElementNames();
806 nEventCount = eventNames.getLength();
807 for(sal_Int32 nEvent = 0; nEvent < nEventCount; ++nEvent )
811 m_docEventsHash[ eventNames[nEvent] ] = GetPairFromAny( m_xDocEvents->getByName( eventNames[nEvent] ) );
813 catch (Exception e)
819 // returns the two props EventType & Script for a given event name
820 Any _SvxMacroTabPage::GetPropsByName( const ::rtl::OUString& eventName, EventsHash& eventsHash )
822 const ::std::pair< ::rtl::OUString, ::rtl::OUString >& rAssignedEvent( eventsHash[ eventName ] );
824 Any aReturn;
825 ::comphelper::NamedValueCollection aProps;
826 if ( rAssignedEvent.first.getLength() && rAssignedEvent.second.getLength() )
828 aProps.put( "EventType", rAssignedEvent.first );
829 aProps.put( "Script", rAssignedEvent.second );
831 aReturn <<= aProps.getPropertyValues();
833 return aReturn;
836 // converts the Any returned by GetByName into a pair which can be stored in
837 // the EventHash
838 ::std::pair< ::rtl::OUString, ::rtl::OUString > _SvxMacroTabPage::GetPairFromAny( Any aAny )
840 Sequence< beans::PropertyValue > props;
841 ::rtl::OUString type, url;
842 if( sal_True == ( aAny >>= props ) )
844 ::comphelper::NamedValueCollection aProps( props );
845 type = aProps.getOrDefault( "EventType", type );
846 url = aProps.getOrDefault( "Script", url );
848 return ::std::make_pair( type, url );
851 SvxMacroTabPage::SvxMacroTabPage( Window* pParent, const Reference< frame::XFrame >& _rxDocumentFrame, const SfxItemSet& rSet, Reference< container::XNameReplace > xNameReplace, sal_uInt16 nSelectedIndex )
852 : _SvxMacroTabPage( pParent, SVX_RES( RID_SVXPAGE_MACROASSIGN ), rSet )
854 mpImpl->pStrEvent = new String( SVX_RES( STR_EVENT ) );
855 mpImpl->pAssignedMacro = new String( SVX_RES( STR_ASSMACRO ) );
856 mpImpl->pEventLB = new _HeaderTabListBox( this, SVX_RES( LB_EVENT ) );
857 mpImpl->pAssignFT = new FixedText( this, SVX_RES( FT_ASSIGN ) );
858 mpImpl->pAssignPB = new PushButton( this, SVX_RES( PB_ASSIGN ) );
859 mpImpl->pDeletePB = new PushButton( this, SVX_RES( PB_DELETE ) );
860 mpImpl->pAssignComponentPB = new PushButton( this, SVX_RES( PB_ASSIGN_COMPONENT ) );
861 mpImpl->pMacroImg = new Image( SVX_RES(IMG_MACRO) );
862 mpImpl->pComponentImg = new Image( SVX_RES(IMG_COMPONENT) );
863 mpImpl->pMacroImg_h = new Image( SVX_RES(IMG_MACRO_H) );
864 mpImpl->pComponentImg_h = new Image( SVX_RES(IMG_COMPONENT_H) );
866 FreeResource();
868 SetFrame( _rxDocumentFrame );
870 if( !mpImpl->bIDEDialogMode )
872 // Size aSizeAssign;
873 // Point aPosAssign;
874 // mpImpl->pAssignPB->GetPosSizePixel( aPosAssign, aSizeAssign );
875 Point aPosAssign = mpImpl->pAssignPB->GetPosPixel();
876 Point aPosComp = mpImpl->pAssignComponentPB->GetPosPixel();
878 Point aPosDelete = mpImpl->pDeletePB->GetPosPixel();
879 long nYDiff = aPosComp.Y() - aPosAssign.Y();
880 aPosDelete.Y() -= nYDiff;
881 mpImpl->pDeletePB->SetPosPixel( aPosDelete );
883 mpImpl->pAssignComponentPB->Hide();
884 mpImpl->pAssignComponentPB->Disable();
887 // must be done after FreeResource is called
888 InitResources();
890 mpImpl->pEventLB->GetListBox().SetHelpId( HID_SVX_MACRO_LB_EVENT );
892 InitAndSetHandler( xNameReplace, Reference< container::XNameReplace>(0), Reference< util::XModifiable >(0));
893 DisplayAppEvents(true);
894 SvHeaderTabListBox& rListBox = mpImpl->pEventLB->GetListBox();
895 SvLBoxEntry* pE = rListBox.GetEntry( (ULONG)nSelectedIndex );
896 if( pE )
897 rListBox.Select(pE);
900 SvxMacroTabPage::~SvxMacroTabPage()
904 SvxMacroAssignDlg::SvxMacroAssignDlg( Window* pParent, const Reference< frame::XFrame >& _rxDocumentFrame, const SfxItemSet& rSet,
905 const Reference< container::XNameReplace >& xNameReplace, sal_uInt16 nSelectedIndex )
906 : SvxMacroAssignSingleTabDialog( pParent, rSet, 0 )
908 SetTabPage( new SvxMacroTabPage( this, _rxDocumentFrame, rSet, xNameReplace, nSelectedIndex ) );
911 SvxMacroAssignDlg::~SvxMacroAssignDlg()
916 //===============================================
918 IMPL_LINK(AssignComponentDialog, ButtonHandler, Button *, EMPTYARG)
920 ::rtl::OUString aMethodName = maMethodEdit.GetText();
921 maURL = ::rtl::OUString();
922 if( aMethodName.getLength() )
924 maURL = aVndSunStarUNO;
925 maURL += aMethodName;
927 EndDialog(1);
928 return 0;
931 AssignComponentDialog::AssignComponentDialog( Window * pParent, const ::rtl::OUString& rURL )
932 : ModalDialog( pParent, SVX_RES( RID_SVXDLG_ASSIGNCOMPONENT ) )
933 , maMethodLabel( this, SVX_RES( FT_METHOD ) )
934 , maMethodEdit( this, SVX_RES( EDIT_METHOD ) )
935 , maOKButton( this, SVX_RES( RID_PB_OK ) )
936 , maCancelButton( this, SVX_RES( RID_PB_CANCEL ) )
937 , maHelpButton( this, SVX_RES( RID_PB_HELP ) )
938 , maURL( rURL )
940 FreeResource();
941 maOKButton.SetClickHdl(LINK(this, AssignComponentDialog, ButtonHandler));
943 ::rtl::OUString aMethodName;
944 if( maURL.getLength() )
946 sal_Int32 nIndex = maURL.indexOf( aVndSunStarUNO );
947 if( nIndex == 0 )
949 sal_Int32 nBegin = aVndSunStarUNO.getLength();
950 aMethodName = maURL.copy( nBegin );
953 maMethodEdit.SetText( aMethodName, Selection( 0, SELECTION_MAX ) );
956 AssignComponentDialog::~AssignComponentDialog()
960 // -----------------------------------------------------------------------
962 IMPL_LINK( SvxMacroAssignSingleTabDialog, OKHdl_Impl, Button *, pButton )
964 (void)pButton; //unused
965 pPage->FillItemSet( *pOutSet );
966 EndDialog( RET_CANCEL );
967 return 0;
970 // -----------------------------------------------------------------------
972 SvxMacroAssignSingleTabDialog::SvxMacroAssignSingleTabDialog
973 ( Window *pParent, const SfxItemSet& rSet, sal_uInt16 nUniqueId ) :
974 SfxModalDialog( pParent, nUniqueId, WinBits( WB_STDMODAL | WB_3DLOOK ) ),
975 pFixedLine ( 0 ),
976 pOKBtn ( 0 ),
977 pCancelBtn ( 0 ),
978 pHelpBtn ( 0 ),
979 pPage ( 0 ),
980 pOptions ( &rSet ),
981 pOutSet ( 0 )
985 // -----------------------------------------------------------------------
987 SvxMacroAssignSingleTabDialog::~SvxMacroAssignSingleTabDialog()
989 delete pFixedLine;
990 delete pOKBtn;
991 delete pCancelBtn;
992 delete pHelpBtn;
993 delete pPage;
996 // -----------------------------------------------------------------------
998 // According to SfxSingleTabDialog
999 void SvxMacroAssignSingleTabDialog::SetTabPage( SfxTabPage* pTabPage )
1001 pFixedLine = new FixedLine( this );
1003 pOKBtn = new OKButton( this, WB_DEFBUTTON );
1004 pOKBtn->SetClickHdl( LINK( this, SvxMacroAssignSingleTabDialog, OKHdl_Impl ) );
1006 pCancelBtn = new CancelButton( this );
1007 pHelpBtn = new HelpButton( this );
1009 pPage = pTabPage;
1011 if ( pPage )
1013 String sUserData;
1014 pPage->SetUserData( sUserData );
1015 pPage->Reset( *pOptions );
1016 pPage->Show();
1018 // Set dialog's and buttons' size and position according to tabpage size
1019 long nSpaceX = LogicToPixel( Size( 6, 0 ), MAP_APPFONT ).Width();
1020 long nSpaceY = LogicToPixel( Size( 0, 6 ), MAP_APPFONT ).Height();
1021 long nHalfSpaceX = LogicToPixel( Size( 3, 0 ), MAP_APPFONT ).Width();
1022 long nHalfSpaceY = LogicToPixel( Size( 0, 3 ), MAP_APPFONT ).Height();
1024 pPage->SetPosPixel( Point() );
1025 Size aTabpageSize( pPage->GetSizePixel() );
1026 Size aDialogSize( aTabpageSize );
1027 Size aButtonSize = LogicToPixel( Size( 50, 14 ), MAP_APPFONT );
1028 long nButtonWidth = aButtonSize.Width();
1029 long nButtonHeight = aButtonSize.Height();
1031 Size aFixedLineSize( aTabpageSize );
1032 long nFixedLineHeight = LogicToPixel( Size( 0, 8 ), MAP_APPFONT ).Height();
1033 aFixedLineSize.Height() = nFixedLineHeight;
1035 aDialogSize.Height() += nFixedLineHeight + nButtonHeight + nSpaceY + nHalfSpaceY;
1036 SetOutputSizePixel( aDialogSize );
1038 long nButtonPosY = aTabpageSize.Height() + nFixedLineHeight + nHalfSpaceY;
1039 long nHelpButtonPosX = nSpaceX;
1040 pHelpBtn->SetPosSizePixel( Point( nHelpButtonPosX, nButtonPosY), aButtonSize );
1041 pHelpBtn->Show();
1043 long nCancelButtonPosX = aDialogSize.Width() - nButtonWidth - nSpaceX + 1;
1044 pCancelBtn->SetPosSizePixel( Point( nCancelButtonPosX, nButtonPosY), aButtonSize );
1045 pCancelBtn->Show();
1047 long nOkButtonPosX = nCancelButtonPosX - nButtonWidth - nHalfSpaceX;
1048 pOKBtn->SetPosSizePixel( Point( nOkButtonPosX, nButtonPosY), aButtonSize );
1049 pOKBtn->Show();
1051 long nFixedLinePosY = aTabpageSize.Height();
1052 pFixedLine->SetPosSizePixel( Point( 0, nFixedLinePosY), aFixedLineSize );
1053 pFixedLine->Show();
1055 // Get text from TabPage
1056 SetText( pPage->GetText() );
1058 // Get IDs from TabPage
1059 SetHelpId( pPage->GetHelpId() );
1060 SetUniqueId( pPage->GetUniqueId() );