1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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>
41 #include <svtools/svmedit.hxx>
44 #include <svtools/eitem.hxx>
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"
59 #include "macropg.hrc"
61 #include <svx/dialogs.hrc>
62 #include "headertablistbox.hxx"
63 #include "macropg_impl.hxx"
65 #include <comphelper/namedvaluecollection.hxx>
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
) :
81 pAssignComponentPB( NULL
),
84 pComponentImg( NULL
),
86 pComponentImg_h( NULL
),
88 pAssignedMacro( NULL
),
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()
102 delete pAssignComponentPB
;
105 delete pComponentImg
;
107 delete pComponentImg_h
;
109 delete pAssignedMacro
;
113 // Achtung im Code wird dieses Array direkt (0, 1, ...) indiziert
114 static long nTabs
[] =
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..." );
136 if( !maHeaderBar
.GetCurItemId() )
139 if( !maHeaderBar
.IsItemMode() )
142 USHORT _nTabs
= maHeaderBar
.GetItemCount();
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
);
154 for( USHORT i
= 1 ; i
< _nTabs
; ++i
)
156 _nWidth
= maHeaderBar
.GetItemSize( i
);
157 aSz
.Width() = _nWidth
+ nTmpSz
;
159 maListBox
.SetTab( i
, PixelToLogic( aSz
, MapMode( MAP_APPFONT
) ).Width(), MAP_APPFONT
);
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();
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
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
);
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();
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
),
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 );
259 ::rtl::OUString
* pEventName
= (::rtl::OUString
*)pE
->GetUserData();
261 pE
->SetUserData((void*)0);
262 pE
= rListBox
.NextSibling( pE
);
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( "OnNew", RID_SVXSTR_EVENT_CREATEDOC
) );
275 aDisplayNames
.push_back( EventDisplayName( "OnLoad", RID_SVXSTR_EVENT_OPENDOC
) );
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( "OnSave", RID_SVXSTR_EVENT_SAVEDOC
) );
279 aDisplayNames
.push_back( EventDisplayName( "OnSaveDone", RID_SVXSTR_EVENT_SAVEDOCDONE
) );
280 aDisplayNames
.push_back( EventDisplayName( "OnPrepareUnload", RID_SVXSTR_EVENT_PREPARECLOSEDOC
) );
281 aDisplayNames
.push_back( EventDisplayName( "OnUnload", RID_SVXSTR_EVENT_CLOSEDOC
) ) ;
282 aDisplayNames
.push_back( EventDisplayName( "OnFocus", RID_SVXSTR_EVENT_ACTIVATEDOC
) );
283 aDisplayNames
.push_back( EventDisplayName( "OnUnfocus", RID_SVXSTR_EVENT_DEACTIVATEDOC
) );
284 aDisplayNames
.push_back( EventDisplayName( "OnPrint", RID_SVXSTR_EVENT_PRINTDOC
) );
285 aDisplayNames
.push_back( EventDisplayName( "OnModifyChanged", RID_SVXSTR_EVENT_MODIFYCHANGED
) );
286 aDisplayNames
.push_back( EventDisplayName( "OnMailMerge", RID_SVXSTR_EVENT_MAILMERGE
) );
287 aDisplayNames
.push_back( EventDisplayName( "OnPageCountChange", RID_SVXSTR_EVENT_PAGECOUNTCHANGE
) );
288 aDisplayNames
.push_back( EventDisplayName( "OnSubComponentOpened", RID_SVXSTR_EVENT_SUBCOMPONENT_OPENED
) );
289 aDisplayNames
.push_back( EventDisplayName( "OnSubComponentClosed", RID_SVXSTR_EVENT_SUBCOMPONENT_CLOSED
) );
291 // the event name to UI string mappings for forms & dialogs
293 aDisplayNames
.push_back( EventDisplayName( "approveAction", RID_SVXSTR_EVENT_APPROVEACTIONPERFORMED
) );
294 aDisplayNames
.push_back( EventDisplayName( "actionPerformed", RID_SVXSTR_EVENT_ACTIONPERFORMED
) );
295 aDisplayNames
.push_back( EventDisplayName( "changed", RID_SVXSTR_EVENT_CHANGED
) );
296 aDisplayNames
.push_back( EventDisplayName( "textChanged", RID_SVXSTR_EVENT_TEXTCHANGED
) );
297 aDisplayNames
.push_back( EventDisplayName( "itemStateChanged", RID_SVXSTR_EVENT_ITEMSTATECHANGED
) );
298 aDisplayNames
.push_back( EventDisplayName( "focusGained", RID_SVXSTR_EVENT_FOCUSGAINED
) );
299 aDisplayNames
.push_back( EventDisplayName( "focusLost", RID_SVXSTR_EVENT_FOCUSLOST
) );
300 aDisplayNames
.push_back( EventDisplayName( "keyPressed", RID_SVXSTR_EVENT_KEYTYPED
) );
301 aDisplayNames
.push_back( EventDisplayName( "keyReleased", RID_SVXSTR_EVENT_KEYUP
) );
302 aDisplayNames
.push_back( EventDisplayName( "mouseEntered", RID_SVXSTR_EVENT_MOUSEENTERED
) );
303 aDisplayNames
.push_back( EventDisplayName( "mouseDragged", RID_SVXSTR_EVENT_MOUSEDRAGGED
) );
304 aDisplayNames
.push_back( EventDisplayName( "mouseMoved", RID_SVXSTR_EVENT_MOUSEMOVED
) );
305 aDisplayNames
.push_back( EventDisplayName( "mousePressed", RID_SVXSTR_EVENT_MOUSEPRESSED
) );
306 aDisplayNames
.push_back( EventDisplayName( "mouseReleased", RID_SVXSTR_EVENT_MOUSERELEASED
) );
307 aDisplayNames
.push_back( EventDisplayName( "mouseExited", RID_SVXSTR_EVENT_MOUSEEXITED
) );
308 aDisplayNames
.push_back( EventDisplayName( "approveReset", RID_SVXSTR_EVENT_APPROVERESETTED
) );
309 aDisplayNames
.push_back( EventDisplayName( "resetted", RID_SVXSTR_EVENT_RESETTED
) );
310 aDisplayNames
.push_back( EventDisplayName( "approveSubmit", RID_SVXSTR_EVENT_SUBMITTED
) );
311 aDisplayNames
.push_back( EventDisplayName( "approveUpdate", RID_SVXSTR_EVENT_BEFOREUPDATE
) );
312 aDisplayNames
.push_back( EventDisplayName( "updated", RID_SVXSTR_EVENT_AFTERUPDATE
) );
313 aDisplayNames
.push_back( EventDisplayName( "loaded", RID_SVXSTR_EVENT_LOADED
) );
314 aDisplayNames
.push_back( EventDisplayName( "reloading", RID_SVXSTR_EVENT_RELOADING
) );
315 aDisplayNames
.push_back( EventDisplayName( "reloaded", RID_SVXSTR_EVENT_RELOADED
) );
316 aDisplayNames
.push_back( EventDisplayName( "unloading", RID_SVXSTR_EVENT_UNLOADING
) );
317 aDisplayNames
.push_back( EventDisplayName( "unloaded", RID_SVXSTR_EVENT_UNLOADED
) );
318 aDisplayNames
.push_back( EventDisplayName( "confirmDelete", RID_SVXSTR_EVENT_CONFIRMDELETE
) );
319 aDisplayNames
.push_back( EventDisplayName( "approveRowChange", RID_SVXSTR_EVENT_APPROVEROWCHANGE
) );
320 aDisplayNames
.push_back( EventDisplayName( "rowChanged", RID_SVXSTR_EVENT_ROWCHANGE
) );
321 aDisplayNames
.push_back( EventDisplayName( "approveCursorMove", RID_SVXSTR_EVENT_POSITIONING
) );
322 aDisplayNames
.push_back( EventDisplayName( "cursorMoved", RID_SVXSTR_EVENT_POSITIONED
) );
323 aDisplayNames
.push_back( EventDisplayName( "approveParameter", RID_SVXSTR_EVENT_APPROVEPARAMETER
) );
324 aDisplayNames
.push_back( EventDisplayName( "errorOccured", RID_SVXSTR_EVENT_ERROROCCURED
) );
325 aDisplayNames
.push_back( EventDisplayName( "adjustmentValueChanged", RID_SVXSTR_EVENT_ADJUSTMENTVALUECHANGED
) );
328 // the following method is called when the user clicks OK
329 // We use the contents of the hashes to replace the settings
330 BOOL
_SvxMacroTabPage::FillItemSet( SfxItemSet
& /*rSet*/ )
334 ::rtl::OUString eventName
;
335 if( m_xAppEvents
.is() )
337 EventsHash::iterator h_itEnd
= m_appEventsHash
.end();
338 EventsHash::iterator h_it
= m_appEventsHash
.begin();
339 for ( ; h_it
!= h_itEnd
; ++h_it
)
341 eventName
= h_it
->first
;
344 m_xAppEvents
->replaceByName( eventName
, GetPropsByName( eventName
, m_appEventsHash
) );
346 catch( const Exception
& )
348 DBG_UNHANDLED_EXCEPTION();
352 if( m_xDocEvents
.is() && bDocModified
)
354 EventsHash::iterator h_itEnd
= m_docEventsHash
.end();
355 EventsHash::iterator h_it
= m_docEventsHash
.begin();
356 for ( ; h_it
!= h_itEnd
; ++h_it
)
358 eventName
= h_it
->first
;
361 m_xDocEvents
->replaceByName( eventName
, GetPropsByName( eventName
, m_docEventsHash
) );
363 catch( const Exception
& )
365 DBG_UNHANDLED_EXCEPTION();
368 // if we have a valid XModifiable (in the case of doc events)
369 // call setModified(true)
370 // in principle this should not be necessary (see issue ??)
371 if(m_xModifiable
.is())
373 m_xModifiable
->setModified( sal_True
);
380 // what is the return value about??
384 // the following method clears the bindings in the hashes for both doc & app
385 void _SvxMacroTabPage::Reset()
387 // called once in creation - don't reset the data this time
396 ::rtl::OUString sEmpty
;
397 if( m_xAppEvents
.is() )
399 EventsHash::iterator h_itEnd
= m_appEventsHash
.end();
400 EventsHash::iterator h_it
= m_appEventsHash
.begin();
401 for ( ; h_it
!= h_itEnd
; ++h_it
)
403 h_it
->second
.second
= sEmpty
;
406 if( m_xDocEvents
.is() && bDocModified
)
408 EventsHash::iterator h_itEnd
= m_docEventsHash
.end();
409 EventsHash::iterator h_it
= m_docEventsHash
.begin();
410 for ( ; h_it
!= h_itEnd
; ++h_it
)
412 h_it
->second
.second
= sEmpty
;
414 // if we have a valid XModifiable (in the case of doc events)
415 // call setModified(true)
416 if(m_xModifiable
.is())
418 m_xModifiable
->setModified( sal_True
);
425 DisplayAppEvents(bAppEvents
);
428 void _SvxMacroTabPage::SetReadOnly( BOOL bSet
)
430 mpImpl
->bReadOnly
= bSet
;
433 BOOL
_SvxMacroTabPage::IsReadOnly() const
435 return mpImpl
->bReadOnly
;
439 class IconLBoxString
: public SvLBoxString
442 Image
* m_pComponentImg
;
443 Image
* m_pMacroImg_h
;
444 Image
* m_pComponentImg_h
;
448 IconLBoxString( SvLBoxEntry
* pEntry
, USHORT nFlags
, const String
& sText
,
449 Image
* pMacroImg
, Image
* pComponentImg
,
450 Image
* pMacroImg_h
, Image
* pComponentImg_h
);
451 virtual void Paint(const Point
& aPos
, SvLBox
& aDevice
, USHORT nFlags
, SvLBoxEntry
* pEntry
);
455 IconLBoxString::IconLBoxString( SvLBoxEntry
* pEntry
, USHORT nFlags
, const String
& sText
,
456 Image
* pMacroImg
, Image
* pComponentImg
, Image
* pMacroImg_h
, Image
* pComponentImg_h
)
457 : SvLBoxString( pEntry
, nFlags
, sText
)
458 , m_pMacroImg( pMacroImg
)
459 , m_pComponentImg( pComponentImg
)
460 , m_pMacroImg_h( pMacroImg_h
)
461 , m_pComponentImg_h( pComponentImg_h
)
463 m_nxImageOffset
= 20;
466 //===============================================
467 void IconLBoxString::Paint( const Point
& aPos
, SvLBox
& aDevice
,
468 USHORT
/*nFlags*/, SvLBoxEntry
* /*pEntry*/ )
470 String
aTxt( GetText() );
473 ::rtl::OUString
aURL( aTxt
);
474 sal_Int32 nIndex
= aURL
.indexOf( aVndSunStarUNO
);
475 bool bUNO
= nIndex
== 0;
477 Wallpaper aBackground
= aDevice
.GetBackground();
478 Color aColor
= aBackground
.GetColor();
479 BOOL bHC
= aColor
.IsDark();
482 pImg
= bUNO
? m_pComponentImg_h
: m_pMacroImg_h
;
484 pImg
= bUNO
? m_pComponentImg
: m_pMacroImg
;
485 aDevice
.DrawImage( aPos
, *pImg
);
487 ::rtl::OUString aPureMethod
;
490 sal_Int32 nBegin
= aVndSunStarUNO
.getLength();
491 aPureMethod
= aURL
.copy( nBegin
);
495 sal_Int32 nBegin
= aVndSunStarScript
.getLength();
496 aPureMethod
= aURL
.copy( nBegin
);
497 aPureMethod
= aPureMethod
.copy( 0, aPureMethod
.indexOf( '?' ) );
501 aPnt
.X() += m_nxImageOffset
;
502 aDevice
.DrawText( aPnt
, aPureMethod
);
507 // displays the app events if appEvents=true, otherwise displays the doc events
508 void _SvxMacroTabPage::DisplayAppEvents( bool appEvents
)
510 bAppEvents
= appEvents
;
512 SvHeaderTabListBox
& rListBox
= mpImpl
->pEventLB
->GetListBox();
513 mpImpl
->pEventLB
->SetUpdateMode( FALSE
);
515 SvLBoxEntry
* pE
= rListBox
.GetEntry( 0 );
516 EventsHash
* eventsHash
;
517 Reference
< container::XNameReplace
> nameReplace
;
520 eventsHash
= &m_appEventsHash
;
521 nameReplace
= m_xAppEvents
;
525 eventsHash
= &m_docEventsHash
;
526 nameReplace
= m_xDocEvents
;
528 // have to use the original XNameReplace since the hash iterators do
529 // not guarantee the order in which the elements are returned
530 if(!nameReplace
.is())
535 Sequence
< ::rtl::OUString
> eventNames
= nameReplace
->getElementNames();
536 ::std::set
< ::rtl::OUString
> aEventNamesCache
;
538 eventNames
.getConstArray(),
539 eventNames
.getConstArray() + eventNames
.getLength(),
540 ::std::insert_iterator
< ::std::set
< ::rtl::OUString
> >( aEventNamesCache
, aEventNamesCache
.end() )
543 for ( EventDisplayNames::const_iterator displayableEvent
= aDisplayNames
.begin();
544 displayableEvent
!= aDisplayNames
.end();
548 ::rtl::OUString
sEventName( ::rtl::OUString::createFromAscii( displayableEvent
->pAsciiEventName
) );
549 if ( !nameReplace
->hasByName( sEventName
) )
552 EventsHash::iterator h_it
= eventsHash
->find( sEventName
);
553 if( h_it
== eventsHash
->end() )
555 OSL_ENSURE( false, "_SvxMacroTabPage::DisplayAppEvents: something's suspicious here!" );
559 ::rtl::OUString eventURL
= h_it
->second
.second
;
560 String
displayName( SVX_RES( displayableEvent
->nEventResourceID
) );
563 SvLBoxEntry
* _pE
= rListBox
.InsertEntry( displayName
);
564 ::rtl::OUString
* pEventName
= new ::rtl::OUString( sEventName
);
565 _pE
->SetUserData( (void*)pEventName
);
566 String
sNew( eventURL
);
567 _pE
->ReplaceItem( new IconLBoxString( _pE
, 0, sNew
,
568 mpImpl
->pMacroImg
, mpImpl
->pComponentImg
,
569 mpImpl
->pMacroImg_h
, mpImpl
->pComponentImg_h
), LB_MACROS_ITEMPOS
);
570 rListBox
.GetModel()->InvalidateEntry( _pE
);
571 rListBox
.Select( _pE
);
572 rListBox
.MakeVisible( _pE
);
574 pE
= rListBox
.GetEntry(0);
576 rListBox
.Select( pE
);
577 rListBox
.SetUpdateMode( TRUE
);
578 EnableButtons( String() );
581 // select event handler on the listbox
582 IMPL_STATIC_LINK( _SvxMacroTabPage
, SelectEvent_Impl
, SvTabListBox
*, EMPTYARG
)
584 _SvxMacroTabPage_Impl
* pImpl
= pThis
->mpImpl
;
585 SvHeaderTabListBox
& rListBox
= pImpl
->pEventLB
->GetListBox();
586 SvLBoxEntry
* pE
= rListBox
.FirstSelected();
589 if( !pE
|| LISTBOX_ENTRY_NOTFOUND
==
590 ( nPos
= rListBox
.GetModel()->GetAbsPos( pE
) ) )
592 DBG_ASSERT( pE
, "wo kommt der leere Eintrag her?" );
596 pThis
->EnableButtons( String() );
600 IMPL_STATIC_LINK( _SvxMacroTabPage
, AssignDeleteHdl_Impl
, PushButton
*, pBtn
)
602 return GenericHandler_Impl( pThis
, pBtn
);
605 IMPL_STATIC_LINK( _SvxMacroTabPage
, DoubleClickHdl_Impl
, SvTabListBox
*, EMPTYARG
)
607 return GenericHandler_Impl( pThis
, NULL
);
610 // handler for double click on the listbox, and for the assign/delete buttons
611 long _SvxMacroTabPage::GenericHandler_Impl( _SvxMacroTabPage
* pThis
, PushButton
* pBtn
)
613 _SvxMacroTabPage_Impl
* pImpl
= pThis
->mpImpl
;
614 SvHeaderTabListBox
& rListBox
= pImpl
->pEventLB
->GetListBox();
615 SvLBoxEntry
* pE
= rListBox
.FirstSelected();
617 if( !pE
|| LISTBOX_ENTRY_NOTFOUND
==
618 ( nPos
= rListBox
.GetModel()->GetAbsPos( pE
) ) )
620 DBG_ASSERT( pE
, "wo kommt der leere Eintrag her?" );
624 const BOOL bAssEnabled
= pBtn
!= pImpl
->pDeletePB
&& pImpl
->pAssignPB
->IsEnabled();
626 ::rtl::OUString
* pEventName
= (::rtl::OUString
*)pE
->GetUserData();
628 ::rtl::OUString sEventURL
;
629 ::rtl::OUString sEventType
;
630 if(pThis
->bAppEvents
)
632 EventsHash::iterator h_it
= pThis
->m_appEventsHash
.find( *pEventName
);
633 if(h_it
!= pThis
->m_appEventsHash
.end() )
635 sEventType
= h_it
->second
.first
;
636 sEventURL
= h_it
->second
.second
;
641 EventsHash::iterator h_it
= pThis
->m_docEventsHash
.find( *pEventName
);
642 if(h_it
!= pThis
->m_docEventsHash
.end() )
644 sEventType
= h_it
->second
.first
;
645 sEventURL
= h_it
->second
.second
;
649 bool bDoubleClick
= (pBtn
== NULL
);
650 bool bUNOAssigned
= (sEventURL
.indexOf( aVndSunStarUNO
) == 0);
651 if( pBtn
== pImpl
->pDeletePB
)
654 sEventType
= ::rtl::OUString::createFromAscii("Script");
655 sEventURL
= ::rtl::OUString();
656 if(!pThis
->bAppEvents
)
657 pThis
->bDocModified
= true;
659 else if ( ( ( pBtn
!= NULL
)
660 && ( pBtn
== pImpl
->pAssignComponentPB
)
667 AssignComponentDialog
* pAssignDlg
= new AssignComponentDialog( pThis
, sEventURL
);
669 short ret
= pAssignDlg
->Execute();
672 sEventType
= ::rtl::OUString::createFromAscii("UNO");
673 sEventURL
= pAssignDlg
->getURL();
674 if(!pThis
->bAppEvents
)
675 pThis
->bDocModified
= true;
679 else if( bAssEnabled
)
682 SvxScriptSelectorDialog
* pDlg
= new SvxScriptSelectorDialog( pThis
, FALSE
, pThis
->GetFrame() );
685 short ret
= pDlg
->Execute();
688 sEventType
= ::rtl::OUString::createFromAscii("Script");
689 sEventURL
= pDlg
->GetScriptURL();
690 if(!pThis
->bAppEvents
)
691 pThis
->bDocModified
= true;
697 if(pThis
->bAppEvents
)
699 EventsHash::iterator h_it
= pThis
->m_appEventsHash
.find( *pEventName
);
700 h_it
->second
.first
= sEventType
;
701 h_it
->second
.second
= sEventURL
;
705 EventsHash::iterator h_it
= pThis
->m_docEventsHash
.find( *pEventName
);
706 h_it
->second
.first
= sEventType
;
707 h_it
->second
.second
= sEventURL
;
710 // update the listbox entry
711 pImpl
->pEventLB
->SetUpdateMode( FALSE
);
712 // pE->ReplaceItem( new SvLBoxString( pE, 0, sEventURL ), LB_MACROS_ITEMPOS );
713 pE
->ReplaceItem( new IconLBoxString( pE
, 0, sEventURL
,
714 pImpl
->pMacroImg
, pImpl
->pComponentImg
,
715 pImpl
->pMacroImg_h
, pImpl
->pComponentImg_h
), LB_MACROS_ITEMPOS
);
717 rListBox
.GetModel()->InvalidateEntry( pE
);
718 rListBox
.Select( pE
);
719 rListBox
.MakeVisible( pE
);
720 rListBox
.SetUpdateMode( TRUE
);
722 pThis
->EnableButtons( String() );
726 // pass in the XNameReplace.
727 // can remove the 3rd arg once issue ?? is fixed
728 void _SvxMacroTabPage::InitAndSetHandler( Reference
< container::XNameReplace
> xAppEvents
, Reference
< container::XNameReplace
> xDocEvents
, Reference
< util::XModifiable
> xModifiable
)
730 m_xAppEvents
= xAppEvents
;
731 m_xDocEvents
= xDocEvents
;
732 m_xModifiable
= xModifiable
;
733 SvHeaderTabListBox
& rListBox
= mpImpl
->pEventLB
->GetListBox();
734 HeaderBar
& rHeaderBar
= mpImpl
->pEventLB
->GetHeaderBar();
735 Link
aLnk(STATIC_LINK(this, _SvxMacroTabPage
, AssignDeleteHdl_Impl
));
736 mpImpl
->pDeletePB
->SetClickHdl( aLnk
);
737 mpImpl
->pAssignPB
->SetClickHdl( aLnk
);
738 if( mpImpl
->pAssignComponentPB
)
739 mpImpl
->pAssignComponentPB
->SetClickHdl( aLnk
);
740 rListBox
.SetDoubleClickHdl( STATIC_LINK(this, _SvxMacroTabPage
, DoubleClickHdl_Impl
) );
742 rListBox
.SetSelectHdl( STATIC_LINK( this, _SvxMacroTabPage
, SelectEvent_Impl
));
744 rListBox
.SetSelectionMode( SINGLE_SELECTION
);
745 rListBox
.SetTabs( &nTabs
[0], MAP_APPFONT
);
746 Size
aSize( nTabs
[ 2 ], 0 );
747 rHeaderBar
.InsertItem( ITEMID_EVENT
, *mpImpl
->pStrEvent
, LogicToPixel( aSize
, MapMode( MAP_APPFONT
) ).Width() );
748 aSize
.Width() = 1764; // don't know what, so 42^2 is best to use...
749 rHeaderBar
.InsertItem( ITMEID_ASSMACRO
, *mpImpl
->pAssignedMacro
, LogicToPixel( aSize
, MapMode( MAP_APPFONT
) ).Width() );
750 rListBox
.SetSpaceBetweenEntries( 0 );
752 mpImpl
->pEventLB
->Show();
753 mpImpl
->pEventLB
->ConnectElements();
755 long nMinLineHeight
= mpImpl
->pMacroImg
->GetSizePixel().Height() + 2;
756 if( nMinLineHeight
> mpImpl
->pEventLB
->GetListBox().GetEntryHeight() )
757 mpImpl
->pEventLB
->GetListBox().SetEntryHeight(
758 sal::static_int_cast
< short >(nMinLineHeight
) );
760 mpImpl
->pEventLB
->Enable( TRUE
);
762 if(!m_xAppEvents
.is())
766 Sequence
< ::rtl::OUString
> eventNames
= m_xAppEvents
->getElementNames();
767 sal_Int32 nEventCount
= eventNames
.getLength();
768 for(sal_Int32 nEvent
= 0; nEvent
< nEventCount
; ++nEvent
)
770 //need exception handling here
773 m_appEventsHash
[ eventNames
[nEvent
] ] = GetPairFromAny( m_xAppEvents
->getByName( eventNames
[nEvent
] ) );
778 if(m_xDocEvents
.is())
780 eventNames
= m_xDocEvents
->getElementNames();
781 nEventCount
= eventNames
.getLength();
782 for(sal_Int32 nEvent
= 0; nEvent
< nEventCount
; ++nEvent
)
786 m_docEventsHash
[ eventNames
[nEvent
] ] = GetPairFromAny( m_xDocEvents
->getByName( eventNames
[nEvent
] ) );
794 // returns the two props EventType & Script for a given event name
795 Any
_SvxMacroTabPage::GetPropsByName( const ::rtl::OUString
& eventName
, EventsHash
& eventsHash
)
797 const ::std::pair
< ::rtl::OUString
, ::rtl::OUString
>& rAssignedEvent( eventsHash
[ eventName
] );
800 ::comphelper::NamedValueCollection aProps
;
801 if ( rAssignedEvent
.first
.getLength() && rAssignedEvent
.second
.getLength() )
803 aProps
.put( "EventType", rAssignedEvent
.first
);
804 aProps
.put( "Script", rAssignedEvent
.second
);
806 aReturn
<<= aProps
.getPropertyValues();
811 // converts the Any returned by GetByName into a pair which can be stored in
813 ::std::pair
< ::rtl::OUString
, ::rtl::OUString
> _SvxMacroTabPage::GetPairFromAny( Any aAny
)
815 Sequence
< beans::PropertyValue
> props
;
816 ::rtl::OUString type
, url
;
817 if( sal_True
== ( aAny
>>= props
) )
819 ::comphelper::NamedValueCollection
aProps( props
);
820 type
= aProps
.getOrDefault( "EventType", type
);
821 url
= aProps
.getOrDefault( "Script", url
);
823 return ::std::make_pair( type
, url
);
826 SvxMacroTabPage::SvxMacroTabPage( Window
* pParent
, const Reference
< frame::XFrame
>& _rxDocumentFrame
, const SfxItemSet
& rSet
, Reference
< container::XNameReplace
> xNameReplace
, sal_uInt16 nSelectedIndex
)
827 : _SvxMacroTabPage( pParent
, SVX_RES( RID_SVXPAGE_MACROASSIGN
), rSet
)
829 mpImpl
->pStrEvent
= new String( SVX_RES( STR_EVENT
) );
830 mpImpl
->pAssignedMacro
= new String( SVX_RES( STR_ASSMACRO
) );
831 mpImpl
->pEventLB
= new _HeaderTabListBox( this, SVX_RES( LB_EVENT
) );
832 mpImpl
->pAssignFT
= new FixedText( this, SVX_RES( FT_ASSIGN
) );
833 mpImpl
->pAssignPB
= new PushButton( this, SVX_RES( PB_ASSIGN
) );
834 mpImpl
->pDeletePB
= new PushButton( this, SVX_RES( PB_DELETE
) );
835 mpImpl
->pAssignComponentPB
= new PushButton( this, SVX_RES( PB_ASSIGN_COMPONENT
) );
836 mpImpl
->pMacroImg
= new Image( SVX_RES(IMG_MACRO
) );
837 mpImpl
->pComponentImg
= new Image( SVX_RES(IMG_COMPONENT
) );
838 mpImpl
->pMacroImg_h
= new Image( SVX_RES(IMG_MACRO_H
) );
839 mpImpl
->pComponentImg_h
= new Image( SVX_RES(IMG_COMPONENT_H
) );
843 SetFrame( _rxDocumentFrame
);
845 if( !mpImpl
->bIDEDialogMode
)
849 // mpImpl->pAssignPB->GetPosSizePixel( aPosAssign, aSizeAssign );
850 Point aPosAssign
= mpImpl
->pAssignPB
->GetPosPixel();
851 Point aPosComp
= mpImpl
->pAssignComponentPB
->GetPosPixel();
853 Point aPosDelete
= mpImpl
->pDeletePB
->GetPosPixel();
854 long nYDiff
= aPosComp
.Y() - aPosAssign
.Y();
855 aPosDelete
.Y() -= nYDiff
;
856 mpImpl
->pDeletePB
->SetPosPixel( aPosDelete
);
858 mpImpl
->pAssignComponentPB
->Hide();
859 mpImpl
->pAssignComponentPB
->Disable();
862 // must be done after FreeResource is called
865 mpImpl
->pEventLB
->GetListBox().SetHelpId( HID_SVX_MACRO_LB_EVENT
);
867 InitAndSetHandler( xNameReplace
, Reference
< container::XNameReplace
>(0), Reference
< util::XModifiable
>(0));
868 DisplayAppEvents(true);
869 SvHeaderTabListBox
& rListBox
= mpImpl
->pEventLB
->GetListBox();
870 SvLBoxEntry
* pE
= rListBox
.GetEntry( (ULONG
)nSelectedIndex
);
875 SvxMacroTabPage::~SvxMacroTabPage()
879 SvxMacroAssignDlg::SvxMacroAssignDlg( Window
* pParent
, const Reference
< frame::XFrame
>& _rxDocumentFrame
, const SfxItemSet
& rSet
,
880 const Reference
< container::XNameReplace
>& xNameReplace
, sal_uInt16 nSelectedIndex
)
881 : SvxMacroAssignSingleTabDialog( pParent
, rSet
, 0 )
883 SetTabPage( new SvxMacroTabPage( this, _rxDocumentFrame
, rSet
, xNameReplace
, nSelectedIndex
) );
886 SvxMacroAssignDlg::~SvxMacroAssignDlg()
891 //===============================================
893 IMPL_LINK(AssignComponentDialog
, ButtonHandler
, Button
*, EMPTYARG
)
895 ::rtl::OUString aMethodName
= maMethodEdit
.GetText();
896 maURL
= ::rtl::OUString();
897 if( aMethodName
.getLength() )
899 maURL
= aVndSunStarUNO
;
900 maURL
+= aMethodName
;
906 AssignComponentDialog::AssignComponentDialog( Window
* pParent
, const ::rtl::OUString
& rURL
)
907 : ModalDialog( pParent
, SVX_RES( RID_SVXDLG_ASSIGNCOMPONENT
) )
908 , maMethodLabel( this, SVX_RES( FT_METHOD
) )
909 , maMethodEdit( this, SVX_RES( EDIT_METHOD
) )
910 , maOKButton( this, SVX_RES( RID_PB_OK
) )
911 , maCancelButton( this, SVX_RES( RID_PB_CANCEL
) )
912 , maHelpButton( this, SVX_RES( RID_PB_HELP
) )
916 maOKButton
.SetClickHdl(LINK(this, AssignComponentDialog
, ButtonHandler
));
918 ::rtl::OUString aMethodName
;
919 if( maURL
.getLength() )
921 sal_Int32 nIndex
= maURL
.indexOf( aVndSunStarUNO
);
924 sal_Int32 nBegin
= aVndSunStarUNO
.getLength();
925 aMethodName
= maURL
.copy( nBegin
);
928 maMethodEdit
.SetText( aMethodName
, Selection( 0, SELECTION_MAX
) );
931 AssignComponentDialog::~AssignComponentDialog()
935 // -----------------------------------------------------------------------
937 IMPL_LINK( SvxMacroAssignSingleTabDialog
, OKHdl_Impl
, Button
*, pButton
)
939 (void)pButton
; //unused
940 pPage
->FillItemSet( *pOutSet
);
941 EndDialog( RET_CANCEL
);
945 // -----------------------------------------------------------------------
947 SvxMacroAssignSingleTabDialog::SvxMacroAssignSingleTabDialog
948 ( Window
*pParent
, const SfxItemSet
& rSet
, sal_uInt16 nUniqueId
) :
949 SfxModalDialog( pParent
, nUniqueId
, WinBits( WB_STDMODAL
| WB_3DLOOK
) ),
960 // -----------------------------------------------------------------------
962 SvxMacroAssignSingleTabDialog::~SvxMacroAssignSingleTabDialog()
971 // -----------------------------------------------------------------------
973 // According to SfxSingleTabDialog
974 void SvxMacroAssignSingleTabDialog::SetTabPage( SfxTabPage
* pTabPage
)
976 pFixedLine
= new FixedLine( this );
978 pOKBtn
= new OKButton( this, WB_DEFBUTTON
);
979 pOKBtn
->SetClickHdl( LINK( this, SvxMacroAssignSingleTabDialog
, OKHdl_Impl
) );
981 pCancelBtn
= new CancelButton( this );
982 pHelpBtn
= new HelpButton( this );
989 pPage
->SetUserData( sUserData
);
990 pPage
->Reset( *pOptions
);
993 // Set dialog's and buttons' size and position according to tabpage size
994 long nSpaceX
= LogicToPixel( Size( 6, 0 ), MAP_APPFONT
).Width();
995 long nSpaceY
= LogicToPixel( Size( 0, 6 ), MAP_APPFONT
).Height();
996 long nHalfSpaceX
= LogicToPixel( Size( 3, 0 ), MAP_APPFONT
).Width();
997 long nHalfSpaceY
= LogicToPixel( Size( 0, 3 ), MAP_APPFONT
).Height();
999 pPage
->SetPosPixel( Point() );
1000 Size
aTabpageSize( pPage
->GetSizePixel() );
1001 Size
aDialogSize( aTabpageSize
);
1002 Size aButtonSize
= LogicToPixel( Size( 50, 14 ), MAP_APPFONT
);
1003 long nButtonWidth
= aButtonSize
.Width();
1004 long nButtonHeight
= aButtonSize
.Height();
1006 Size
aFixedLineSize( aTabpageSize
);
1007 long nFixedLineHeight
= LogicToPixel( Size( 0, 8 ), MAP_APPFONT
).Height();
1008 aFixedLineSize
.Height() = nFixedLineHeight
;
1010 aDialogSize
.Height() += nFixedLineHeight
+ nButtonHeight
+ nSpaceY
+ nHalfSpaceY
;
1011 SetOutputSizePixel( aDialogSize
);
1013 long nButtonPosY
= aTabpageSize
.Height() + nFixedLineHeight
+ nHalfSpaceY
;
1014 long nHelpButtonPosX
= nSpaceX
;
1015 pHelpBtn
->SetPosSizePixel( Point( nHelpButtonPosX
, nButtonPosY
), aButtonSize
);
1018 long nCancelButtonPosX
= aDialogSize
.Width() - nButtonWidth
- nSpaceX
+ 1;
1019 pCancelBtn
->SetPosSizePixel( Point( nCancelButtonPosX
, nButtonPosY
), aButtonSize
);
1022 long nOkButtonPosX
= nCancelButtonPosX
- nButtonWidth
- nHalfSpaceX
;
1023 pOKBtn
->SetPosSizePixel( Point( nOkButtonPosX
, nButtonPosY
), aButtonSize
);
1026 long nFixedLinePosY
= aTabpageSize
.Height();
1027 pFixedLine
->SetPosSizePixel( Point( 0, nFixedLinePosY
), aFixedLineSize
);
1030 // Get text from TabPage
1031 SetText( pPage
->GetText() );
1033 // Get IDs from TabPage
1034 SetHelpId( pPage
->GetHelpId() );
1035 SetUniqueId( pPage
->GetUniqueId() );