1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <basic/basmgr.hxx>
22 #include "macropg.hxx"
23 #include <vcl/msgbox.hxx>
24 #include <svtools/svmedit.hxx>
25 #include <svtools/svlbitm.hxx>
26 #include "svtools/treelistentry.hxx"
27 #include <svl/eitem.hxx>
28 #include <tools/diagnose_ex.h>
29 #include <sfx2/app.hxx>
30 #include <sfx2/objsh.hxx>
31 #include <sfx2/sfxdefs.hxx>
32 #include <com/sun/star/container/NoSuchElementException.hpp>
33 #include <com/sun/star/lang/IllegalArgumentException.hpp>
34 #include <dialmgr.hxx>
35 #include "selector.hxx"
37 #include "macropg.hrc"
40 #include "headertablistbox.hxx"
41 #include "macropg_impl.hxx"
42 #include <svx/dialogs.hrc> // RID_SVXPAGE_MACROASSIGN
43 #include <comphelper/namedvaluecollection.hxx>
48 using namespace ::com::sun::star
;
49 using namespace ::com::sun::star::uno
;
51 static OUString
aVndSunStarUNO( "vnd.sun.star.UNO:" );
52 static OUString
aVndSunStarScript( "vnd.sun.star.script:" );
54 _SvxMacroTabPage_Impl::_SvxMacroTabPage_Impl( const SfxItemSet
& rAttrSet
) :
57 pAssignComponentPB( NULL
),
60 pComponentImg( NULL
),
62 pAssignedMacro( NULL
),
64 bReadOnly( sal_False
),
65 bIDEDialogMode( sal_False
)
67 const SfxPoolItem
* pItem
;
68 if ( SFX_ITEM_SET
== rAttrSet
.GetItemState( SID_ATTR_MACROITEM
, sal_False
, &pItem
) )
69 bIDEDialogMode
= ((const SfxBoolItem
*)pItem
)->GetValue();
72 _SvxMacroTabPage_Impl::~_SvxMacroTabPage_Impl()
76 delete pAssignComponentPB
;
81 delete pAssignedMacro
;
85 // attention, this array is indexed directly (0, 1, ...) in the code
92 #define TAB_WIDTH_MIN 10
94 // IDs for items in HeaderBar of EventLB
95 #define ITEMID_EVENT 1
96 #define ITMEID_ASSMACRO 2
99 #define LB_MACROS_ITEMPOS 2
102 IMPL_LINK( _HeaderTabListBox
, HeaderEndDrag_Impl
, HeaderBar
*, pBar
)
104 DBG_ASSERT( pBar
== &maHeaderBar
, "*_HeaderTabListBox::HeaderEndDrag_Impl: something is wrong here..." );
107 if( !maHeaderBar
.GetCurItemId() )
110 if( !maHeaderBar
.IsItemMode() )
113 sal_uInt16 _nTabs
= maHeaderBar
.GetItemCount();
114 long nWidth
= maHeaderBar
.GetItemSize( ITEMID_EVENT
);
115 long nBarWidth
= maHeaderBar
.GetSizePixel().Width();
117 if( nWidth
< TAB_WIDTH_MIN
)
118 maHeaderBar
.SetItemSize( ITEMID_EVENT
, TAB_WIDTH_MIN
);
119 else if( ( nBarWidth
- nWidth
) < TAB_WIDTH_MIN
)
120 maHeaderBar
.SetItemSize( ITEMID_EVENT
, nBarWidth
- TAB_WIDTH_MIN
);
123 long _nWidth
, nTmpSz
= 0;
124 for( sal_uInt16 i
= 1 ; i
< _nTabs
; ++i
)
126 _nWidth
= maHeaderBar
.GetItemSize( i
);
127 aSz
.Width() = _nWidth
+ nTmpSz
;
129 maListBox
.SetTab( i
, PixelToLogic( aSz
, MapMode( MAP_APPFONT
) ).Width(), MAP_APPFONT
);
136 long _HeaderTabListBox::Notify( NotifyEvent
& rNEvt
)
138 long nRet
= Control::Notify( rNEvt
);
140 if( rNEvt
.GetType() == EVENT_GETFOCUS
)
142 if ( rNEvt
.GetWindow() != &maListBox
)
143 maListBox
.GrabFocus();
149 _HeaderTabListBox::_HeaderTabListBox( Window
* pParent
, const ResId
& rId
) :
150 Control( pParent
, rId
),
151 maListBox( this, WB_HSCROLL
| WB_CLIPCHILDREN
| WB_TABSTOP
),
152 maHeaderBar( this, WB_BUTTONSTYLE
| WB_BOTTOMBORDER
)
154 maListBox
.SetHelpId( HID_MACRO_HEADERTABLISTBOX
);
157 _HeaderTabListBox::~_HeaderTabListBox()
161 void _HeaderTabListBox::ConnectElements( void )
163 // calc pos and size of header bar
165 Size
aSize( maHeaderBar
.CalcWindowSizePixel() );
166 Size
aCtrlSize( GetOutputSizePixel() );
167 aSize
.Width() = aCtrlSize
.Width();
168 maHeaderBar
.SetPosSizePixel( aPnt
, aSize
);
170 // calc pos and size of ListBox
171 aPnt
.Y() += aSize
.Height();
172 aSize
.Height() = aCtrlSize
.Height() - aSize
.Height();
173 maListBox
.SetPosSizePixel( aPnt
, aSize
);
176 maHeaderBar
.SetEndDragHdl( LINK( this, _HeaderTabListBox
, HeaderEndDrag_Impl
) );
178 maListBox
.InitHeaderBar( &maHeaderBar
);
181 void _HeaderTabListBox::Show( sal_Bool bVisible
, sal_uInt16 nFlags
)
183 maListBox
.Show( bVisible
, nFlags
);
184 maHeaderBar
.Show( bVisible
, nFlags
);
187 void _HeaderTabListBox::Enable( bool bEnable
, bool bChild
)
189 maListBox
.Enable( bEnable
, bChild
);
190 maHeaderBar
.Enable( bEnable
, bChild
);
193 // assign button ("Add Command") is enabled only if it is not read only
194 // delete button ("Remove Command") is enabled if a current binding exists
195 // and it is not read only
196 void _SvxMacroTabPage::EnableButtons()
198 const SvTreeListEntry
* pE
= mpImpl
->pEventLB
->GetListBox().FirstSelected();
201 SvLBoxString
* pEventMacro
= (SvLBoxString
*)pE
->GetItem( LB_MACROS_ITEMPOS
);
202 mpImpl
->pDeletePB
->Enable( 0 != pEventMacro
&& !mpImpl
->bReadOnly
);
204 mpImpl
->pAssignPB
->Enable( !mpImpl
->bReadOnly
);
205 if( mpImpl
->pAssignComponentPB
)
206 mpImpl
->pAssignComponentPB
->Enable( !mpImpl
->bReadOnly
);
210 _SvxMacroTabPage::_SvxMacroTabPage( Window
* pParent
, const ResId
& rResId
, const SfxItemSet
& rAttrSet
)
211 : SfxTabPage( pParent
, rResId
, rAttrSet
),
219 mpImpl
= new _SvxMacroTabPage_Impl( rAttrSet
);
222 _SvxMacroTabPage::~_SvxMacroTabPage()
224 // need to delete the user data
225 SvHeaderTabListBox
& rListBox
= mpImpl
->pEventLB
->GetListBox();
226 SvTreeListEntry
* pE
= rListBox
.GetEntry( 0 );
229 OUString
* pEventName
= (OUString
*)pE
->GetUserData();
231 pE
->SetUserData((void*)0);
232 pE
= rListBox
.NextSibling( pE
);
236 // -----------------------------------------------------------------------------
237 void _SvxMacroTabPage::InitResources()
239 // Note: the order here controls the order in which the events are displayed in the UI!
241 // the event name to UI string mappings for App Events
242 aDisplayNames
.push_back( EventDisplayName( "OnStartApp", RID_SVXSTR_EVENT_STARTAPP
) );
243 aDisplayNames
.push_back( EventDisplayName( "OnCloseApp", RID_SVXSTR_EVENT_CLOSEAPP
) );
244 aDisplayNames
.push_back( EventDisplayName( "OnCreate", RID_SVXSTR_EVENT_CREATEDOC
) );
245 aDisplayNames
.push_back( EventDisplayName( "OnNew", RID_SVXSTR_EVENT_NEWDOC
) );
246 aDisplayNames
.push_back( EventDisplayName( "OnLoadFinished", RID_SVXSTR_EVENT_LOADDOCFINISHED
) );
247 aDisplayNames
.push_back( EventDisplayName( "OnLoad", RID_SVXSTR_EVENT_OPENDOC
) );
248 aDisplayNames
.push_back( EventDisplayName( "OnPrepareUnload", RID_SVXSTR_EVENT_PREPARECLOSEDOC
) );
249 aDisplayNames
.push_back( EventDisplayName( "OnUnload", RID_SVXSTR_EVENT_CLOSEDOC
) ) ;
250 aDisplayNames
.push_back( EventDisplayName( "OnViewCreated", RID_SVXSTR_EVENT_VIEWCREATED
) );
251 aDisplayNames
.push_back( EventDisplayName( "OnPrepareViewClosing", RID_SVXSTR_EVENT_PREPARECLOSEVIEW
) );
252 aDisplayNames
.push_back( EventDisplayName( "OnViewClosed", RID_SVXSTR_EVENT_CLOSEVIEW
) ) ;
253 aDisplayNames
.push_back( EventDisplayName( "OnFocus", RID_SVXSTR_EVENT_ACTIVATEDOC
) );
254 aDisplayNames
.push_back( EventDisplayName( "OnUnfocus", RID_SVXSTR_EVENT_DEACTIVATEDOC
) );
255 aDisplayNames
.push_back( EventDisplayName( "OnSave", RID_SVXSTR_EVENT_SAVEDOC
) );
256 aDisplayNames
.push_back( EventDisplayName( "OnSaveDone", RID_SVXSTR_EVENT_SAVEDOCDONE
) );
257 aDisplayNames
.push_back( EventDisplayName( "OnSaveFailed", RID_SVXSTR_EVENT_SAVEDOCFAILED
) );
258 aDisplayNames
.push_back( EventDisplayName( "OnSaveAs", RID_SVXSTR_EVENT_SAVEASDOC
) );
259 aDisplayNames
.push_back( EventDisplayName( "OnSaveAsDone", RID_SVXSTR_EVENT_SAVEASDOCDONE
) );
260 aDisplayNames
.push_back( EventDisplayName( "OnSaveAsFailed", RID_SVXSTR_EVENT_SAVEASDOCFAILED
) );
261 aDisplayNames
.push_back( EventDisplayName( "OnCopyTo", RID_SVXSTR_EVENT_COPYTODOC
) );
262 aDisplayNames
.push_back( EventDisplayName( "OnCopyToDone", RID_SVXSTR_EVENT_COPYTODOCDONE
) );
263 aDisplayNames
.push_back( EventDisplayName( "OnCopyToFailed", RID_SVXSTR_EVENT_COPYTODOCFAILED
) );
264 aDisplayNames
.push_back( EventDisplayName( "OnPrint", RID_SVXSTR_EVENT_PRINTDOC
) );
265 aDisplayNames
.push_back( EventDisplayName( "OnModifyChanged", RID_SVXSTR_EVENT_MODIFYCHANGED
) );
266 aDisplayNames
.push_back( EventDisplayName( "OnTitleChanged", RID_SVXSTR_EVENT_TITLECHANGED
) );
268 // application specific events
269 aDisplayNames
.push_back( EventDisplayName( "OnMailMerge", RID_SVXSTR_EVENT_MAILMERGE
) );
270 aDisplayNames
.push_back( EventDisplayName( "OnMailMergeFinished", RID_SVXSTR_EVENT_MAILMERGE_END
) );
271 aDisplayNames
.push_back( EventDisplayName( "OnFieldMerge", RID_SVXSTR_EVENT_FIELDMERGE
) );
272 aDisplayNames
.push_back( EventDisplayName( "OnFieldMergeFinished", RID_SVXSTR_EVENT_FIELDMERGE_FINISHED
) );
273 aDisplayNames
.push_back( EventDisplayName( "OnPageCountChange", RID_SVXSTR_EVENT_PAGECOUNTCHANGE
) );
274 aDisplayNames
.push_back( EventDisplayName( "OnSubComponentOpened", RID_SVXSTR_EVENT_SUBCOMPONENT_OPENED
) );
275 aDisplayNames
.push_back( EventDisplayName( "OnSubComponentClosed", RID_SVXSTR_EVENT_SUBCOMPONENT_CLOSED
) );
276 aDisplayNames
.push_back( EventDisplayName( "OnSelect", RID_SVXSTR_EVENT_SELECTIONCHANGED
) );
277 aDisplayNames
.push_back( EventDisplayName( "OnDoubleClick", RID_SVXSTR_EVENT_DOUBLECLICK
) );
278 aDisplayNames
.push_back( EventDisplayName( "OnRightClick", RID_SVXSTR_EVENT_RIGHTCLICK
) );
279 aDisplayNames
.push_back( EventDisplayName( "OnCalculate", RID_SVXSTR_EVENT_CALCULATE
) );
280 aDisplayNames
.push_back( EventDisplayName( "OnChange", RID_SVXSTR_EVENT_CONTENTCHANGED
) );
282 // the event name to UI string mappings for forms & dialogs
284 aDisplayNames
.push_back( EventDisplayName( "approveAction", RID_SVXSTR_EVENT_APPROVEACTIONPERFORMED
) );
285 aDisplayNames
.push_back( EventDisplayName( "actionPerformed", RID_SVXSTR_EVENT_ACTIONPERFORMED
) );
286 aDisplayNames
.push_back( EventDisplayName( "changed", RID_SVXSTR_EVENT_CHANGED
) );
287 aDisplayNames
.push_back( EventDisplayName( "textChanged", RID_SVXSTR_EVENT_TEXTCHANGED
) );
288 aDisplayNames
.push_back( EventDisplayName( "itemStateChanged", RID_SVXSTR_EVENT_ITEMSTATECHANGED
) );
289 aDisplayNames
.push_back( EventDisplayName( "focusGained", RID_SVXSTR_EVENT_FOCUSGAINED
) );
290 aDisplayNames
.push_back( EventDisplayName( "focusLost", RID_SVXSTR_EVENT_FOCUSLOST
) );
291 aDisplayNames
.push_back( EventDisplayName( "keyPressed", RID_SVXSTR_EVENT_KEYTYPED
) );
292 aDisplayNames
.push_back( EventDisplayName( "keyReleased", RID_SVXSTR_EVENT_KEYUP
) );
293 aDisplayNames
.push_back( EventDisplayName( "mouseEntered", RID_SVXSTR_EVENT_MOUSEENTERED
) );
294 aDisplayNames
.push_back( EventDisplayName( "mouseDragged", RID_SVXSTR_EVENT_MOUSEDRAGGED
) );
295 aDisplayNames
.push_back( EventDisplayName( "mouseMoved", RID_SVXSTR_EVENT_MOUSEMOVED
) );
296 aDisplayNames
.push_back( EventDisplayName( "mousePressed", RID_SVXSTR_EVENT_MOUSEPRESSED
) );
297 aDisplayNames
.push_back( EventDisplayName( "mouseReleased", RID_SVXSTR_EVENT_MOUSERELEASED
) );
298 aDisplayNames
.push_back( EventDisplayName( "mouseExited", RID_SVXSTR_EVENT_MOUSEEXITED
) );
299 aDisplayNames
.push_back( EventDisplayName( "approveReset", RID_SVXSTR_EVENT_APPROVERESETTED
) );
300 aDisplayNames
.push_back( EventDisplayName( "resetted", RID_SVXSTR_EVENT_RESETTED
) );
301 aDisplayNames
.push_back( EventDisplayName( "approveSubmit", RID_SVXSTR_EVENT_SUBMITTED
) );
302 aDisplayNames
.push_back( EventDisplayName( "approveUpdate", RID_SVXSTR_EVENT_BEFOREUPDATE
) );
303 aDisplayNames
.push_back( EventDisplayName( "updated", RID_SVXSTR_EVENT_AFTERUPDATE
) );
304 aDisplayNames
.push_back( EventDisplayName( "loaded", RID_SVXSTR_EVENT_LOADED
) );
305 aDisplayNames
.push_back( EventDisplayName( "reloading", RID_SVXSTR_EVENT_RELOADING
) );
306 aDisplayNames
.push_back( EventDisplayName( "reloaded", RID_SVXSTR_EVENT_RELOADED
) );
307 aDisplayNames
.push_back( EventDisplayName( "unloading", RID_SVXSTR_EVENT_UNLOADING
) );
308 aDisplayNames
.push_back( EventDisplayName( "unloaded", RID_SVXSTR_EVENT_UNLOADED
) );
309 aDisplayNames
.push_back( EventDisplayName( "confirmDelete", RID_SVXSTR_EVENT_CONFIRMDELETE
) );
310 aDisplayNames
.push_back( EventDisplayName( "approveRowChange", RID_SVXSTR_EVENT_APPROVEROWCHANGE
) );
311 aDisplayNames
.push_back( EventDisplayName( "rowChanged", RID_SVXSTR_EVENT_ROWCHANGE
) );
312 aDisplayNames
.push_back( EventDisplayName( "approveCursorMove", RID_SVXSTR_EVENT_POSITIONING
) );
313 aDisplayNames
.push_back( EventDisplayName( "cursorMoved", RID_SVXSTR_EVENT_POSITIONED
) );
314 aDisplayNames
.push_back( EventDisplayName( "approveParameter", RID_SVXSTR_EVENT_APPROVEPARAMETER
) );
315 aDisplayNames
.push_back( EventDisplayName( "errorOccurred", RID_SVXSTR_EVENT_ERROROCCURRED
) );
316 aDisplayNames
.push_back( EventDisplayName( "adjustmentValueChanged", RID_SVXSTR_EVENT_ADJUSTMENTVALUECHANGED
) );
319 // the following method is called when the user clicks OK
320 // We use the contents of the hashes to replace the settings
321 sal_Bool
_SvxMacroTabPage::FillItemSet( SfxItemSet
& /*rSet*/ )
326 if( m_xAppEvents
.is() )
328 EventsHash::iterator h_itEnd
= m_appEventsHash
.end();
329 EventsHash::iterator h_it
= m_appEventsHash
.begin();
330 for ( ; h_it
!= h_itEnd
; ++h_it
)
332 eventName
= h_it
->first
;
335 m_xAppEvents
->replaceByName( eventName
, GetPropsByName( eventName
, m_appEventsHash
) );
337 catch (const Exception
&)
339 DBG_UNHANDLED_EXCEPTION();
343 if( m_xDocEvents
.is() && bDocModified
)
345 EventsHash::iterator h_itEnd
= m_docEventsHash
.end();
346 EventsHash::iterator h_it
= m_docEventsHash
.begin();
347 for ( ; h_it
!= h_itEnd
; ++h_it
)
349 eventName
= h_it
->first
;
352 m_xDocEvents
->replaceByName( eventName
, GetPropsByName( eventName
, m_docEventsHash
) );
354 catch (const Exception
&)
356 DBG_UNHANDLED_EXCEPTION();
359 // if we have a valid XModifiable (in the case of doc events)
360 // call setModified(true)
361 // in principle this should not be necessary (see issue ??)
362 if(m_xModifiable
.is())
364 m_xModifiable
->setModified( sal_True
);
368 catch (const Exception
&)
371 // what is the return value about??
375 // the following method clears the bindings in the hashes for both doc & app
376 void _SvxMacroTabPage::Reset()
378 // called once in creation - don't reset the data this time
388 if( m_xAppEvents
.is() )
390 EventsHash::iterator h_itEnd
= m_appEventsHash
.end();
391 EventsHash::iterator h_it
= m_appEventsHash
.begin();
392 for ( ; h_it
!= h_itEnd
; ++h_it
)
394 h_it
->second
.second
= sEmpty
;
397 if( m_xDocEvents
.is() && bDocModified
)
399 EventsHash::iterator h_itEnd
= m_docEventsHash
.end();
400 EventsHash::iterator h_it
= m_docEventsHash
.begin();
401 for ( ; h_it
!= h_itEnd
; ++h_it
)
403 h_it
->second
.second
= sEmpty
;
405 // if we have a valid XModifiable (in the case of doc events)
406 // call setModified(true)
407 if(m_xModifiable
.is())
409 m_xModifiable
->setModified( sal_True
);
413 catch (const Exception
&)
416 DisplayAppEvents(bAppEvents
);
419 void _SvxMacroTabPage::SetReadOnly( sal_Bool bSet
)
421 mpImpl
->bReadOnly
= bSet
;
424 sal_Bool
_SvxMacroTabPage::IsReadOnly() const
426 return mpImpl
->bReadOnly
;
430 class IconLBoxString
: public SvLBoxString
433 Image
* m_pComponentImg
;
437 IconLBoxString( SvTreeListEntry
* pEntry
, sal_uInt16 nFlags
, const String
& sText
,
438 Image
* pMacroImg
, Image
* pComponentImg
);
440 const Point
& rPos
, SvTreeListBox
& rOutDev
, const SvViewDataEntry
* pView
, const SvTreeListEntry
* pEntry
);
444 IconLBoxString::IconLBoxString( SvTreeListEntry
* pEntry
, sal_uInt16 nFlags
, const String
& sText
,
445 Image
* pMacroImg
, Image
* pComponentImg
)
446 : SvLBoxString( pEntry
, nFlags
, sText
)
447 , m_pMacroImg( pMacroImg
)
448 , m_pComponentImg( pComponentImg
)
450 m_nxImageOffset
= 20;
453 //===============================================
454 void IconLBoxString::Paint(
455 const Point
& aPos
, SvTreeListBox
& aDevice
, const SvViewDataEntry
* /*pView*/,
456 const SvTreeListEntry
* /*pEntry*/)
458 String
aTxt( GetText() );
461 OUString
aURL( aTxt
);
462 sal_Int32 nIndex
= aURL
.indexOf( aVndSunStarUNO
);
463 bool bUNO
= nIndex
== 0;
465 const Image
* pImg
= bUNO
? m_pComponentImg
: m_pMacroImg
;
466 aDevice
.DrawImage( aPos
, *pImg
);
468 OUString aPureMethod
;
471 sal_Int32 nBegin
= aVndSunStarUNO
.getLength();
472 aPureMethod
= aURL
.copy( nBegin
);
476 sal_Int32 nBegin
= aVndSunStarScript
.getLength();
477 aPureMethod
= aURL
.copy( nBegin
);
478 aPureMethod
= aPureMethod
.copy( 0, aPureMethod
.indexOf( '?' ) );
482 aPnt
.X() += m_nxImageOffset
;
483 aDevice
.DrawText( aPnt
, aPureMethod
);
488 // displays the app events if appEvents=true, otherwise displays the doc events
489 void _SvxMacroTabPage::DisplayAppEvents( bool appEvents
)
491 bAppEvents
= appEvents
;
493 SvHeaderTabListBox
& rListBox
= mpImpl
->pEventLB
->GetListBox();
494 mpImpl
->pEventLB
->SetUpdateMode( sal_False
);
496 SvTreeListEntry
* pE
= rListBox
.GetEntry( 0 );
497 EventsHash
* eventsHash
;
498 Reference
< container::XNameReplace
> nameReplace
;
501 eventsHash
= &m_appEventsHash
;
502 nameReplace
= m_xAppEvents
;
506 eventsHash
= &m_docEventsHash
;
507 nameReplace
= m_xDocEvents
;
509 // have to use the original XNameReplace since the hash iterators do
510 // not guarantee the order in which the elements are returned
511 if(!nameReplace
.is())
516 Sequence
< OUString
> eventNames
= nameReplace
->getElementNames();
517 ::std::set
< OUString
> aEventNamesCache
;
519 eventNames
.getConstArray(),
520 eventNames
.getConstArray() + eventNames
.getLength(),
521 ::std::insert_iterator
< ::std::set
< OUString
> >( aEventNamesCache
, aEventNamesCache
.end() )
524 for ( EventDisplayNames::const_iterator displayableEvent
= aDisplayNames
.begin();
525 displayableEvent
!= aDisplayNames
.end();
529 OUString
sEventName( OUString::createFromAscii( displayableEvent
->pAsciiEventName
) );
530 if ( !nameReplace
->hasByName( sEventName
) )
533 EventsHash::iterator h_it
= eventsHash
->find( sEventName
);
534 if( h_it
== eventsHash
->end() )
536 OSL_FAIL( "_SvxMacroTabPage::DisplayAppEvents: something's suspicious here!" );
540 OUString eventURL
= h_it
->second
.second
;
541 String
displayName( CUI_RES( displayableEvent
->nEventResourceID
) );
544 SvTreeListEntry
* _pE
= rListBox
.InsertEntry( displayName
);
545 OUString
* pEventName
= new OUString( sEventName
);
546 _pE
->SetUserData( (void*)pEventName
);
547 String
sNew( eventURL
);
548 _pE
->ReplaceItem( new IconLBoxString( _pE
, 0, sNew
,
549 mpImpl
->pMacroImg
, mpImpl
->pComponentImg
), LB_MACROS_ITEMPOS
);
550 rListBox
.GetModel()->InvalidateEntry( _pE
);
551 rListBox
.Select( _pE
);
552 rListBox
.MakeVisible( _pE
);
555 pE
= rListBox
.GetEntry(0);
558 rListBox
.Select( pE
);
559 rListBox
.MakeVisible( pE
);
562 rListBox
.SetUpdateMode( sal_True
);
566 // select event handler on the listbox
567 IMPL_STATIC_LINK( _SvxMacroTabPage
, SelectEvent_Impl
, SvTabListBox
*, EMPTYARG
)
569 _SvxMacroTabPage_Impl
* pImpl
= pThis
->mpImpl
;
570 SvHeaderTabListBox
& rListBox
= pImpl
->pEventLB
->GetListBox();
571 SvTreeListEntry
* pE
= rListBox
.FirstSelected();
574 if( !pE
|| LISTBOX_ENTRY_NOTFOUND
==
575 ( nPos
= rListBox
.GetModel()->GetAbsPos( pE
) ) )
577 DBG_ASSERT( pE
, "wo kommt der leere Eintrag her?" );
581 pThis
->EnableButtons();
585 IMPL_STATIC_LINK( _SvxMacroTabPage
, AssignDeleteHdl_Impl
, PushButton
*, pBtn
)
587 return GenericHandler_Impl( pThis
, pBtn
);
590 IMPL_STATIC_LINK( _SvxMacroTabPage
, DoubleClickHdl_Impl
, SvTabListBox
*, EMPTYARG
)
592 return GenericHandler_Impl( pThis
, NULL
);
595 // handler for double click on the listbox, and for the assign/delete buttons
596 long _SvxMacroTabPage::GenericHandler_Impl( _SvxMacroTabPage
* pThis
, PushButton
* pBtn
)
598 _SvxMacroTabPage_Impl
* pImpl
= pThis
->mpImpl
;
599 SvHeaderTabListBox
& rListBox
= pImpl
->pEventLB
->GetListBox();
600 SvTreeListEntry
* pE
= rListBox
.FirstSelected();
602 if( !pE
|| LISTBOX_ENTRY_NOTFOUND
==
603 ( nPos
= rListBox
.GetModel()->GetAbsPos( pE
) ) )
605 DBG_ASSERT( pE
, "wo kommt der leere Eintrag her?" );
609 const sal_Bool bAssEnabled
= pBtn
!= pImpl
->pDeletePB
&& pImpl
->pAssignPB
->IsEnabled();
611 OUString
* pEventName
= (OUString
*)pE
->GetUserData();
615 if(pThis
->bAppEvents
)
617 EventsHash::iterator h_it
= pThis
->m_appEventsHash
.find( *pEventName
);
618 if(h_it
!= pThis
->m_appEventsHash
.end() )
620 sEventType
= h_it
->second
.first
;
621 sEventURL
= h_it
->second
.second
;
626 EventsHash::iterator h_it
= pThis
->m_docEventsHash
.find( *pEventName
);
627 if(h_it
!= pThis
->m_docEventsHash
.end() )
629 sEventType
= h_it
->second
.first
;
630 sEventURL
= h_it
->second
.second
;
634 bool bDoubleClick
= (pBtn
== NULL
);
635 bool bUNOAssigned
= (sEventURL
.indexOf( aVndSunStarUNO
) == 0);
636 if( pBtn
== pImpl
->pDeletePB
)
639 sEventType
= OUString( "Script" );
640 sEventURL
= OUString();
641 if(!pThis
->bAppEvents
)
642 pThis
->bDocModified
= true;
644 else if ( ( ( pBtn
!= NULL
)
645 && ( pBtn
== pImpl
->pAssignComponentPB
)
652 AssignComponentDialog
* pAssignDlg
= new AssignComponentDialog( pThis
, sEventURL
);
654 short ret
= pAssignDlg
->Execute();
657 sEventType
= OUString("UNO");
658 sEventURL
= pAssignDlg
->getURL();
659 if(!pThis
->bAppEvents
)
660 pThis
->bDocModified
= true;
664 else if( bAssEnabled
)
667 SvxScriptSelectorDialog
* pDlg
= new SvxScriptSelectorDialog( pThis
, sal_False
, pThis
->GetFrame() );
670 short ret
= pDlg
->Execute();
673 sEventType
= OUString("Script");
674 sEventURL
= pDlg
->GetScriptURL();
675 if(!pThis
->bAppEvents
)
676 pThis
->bDocModified
= true;
682 if(pThis
->bAppEvents
)
684 EventsHash::iterator h_it
= pThis
->m_appEventsHash
.find( *pEventName
);
685 h_it
->second
.first
= sEventType
;
686 h_it
->second
.second
= sEventURL
;
690 EventsHash::iterator h_it
= pThis
->m_docEventsHash
.find( *pEventName
);
691 h_it
->second
.first
= sEventType
;
692 h_it
->second
.second
= sEventURL
;
695 // update the listbox entry
696 pImpl
->pEventLB
->SetUpdateMode( sal_False
);
697 pE
->ReplaceItem( new IconLBoxString( pE
, 0, sEventURL
,
698 pImpl
->pMacroImg
, pImpl
->pComponentImg
), LB_MACROS_ITEMPOS
);
700 rListBox
.GetModel()->InvalidateEntry( pE
);
701 rListBox
.Select( pE
);
702 rListBox
.MakeVisible( pE
);
703 rListBox
.SetUpdateMode( sal_True
);
705 pThis
->EnableButtons();
709 // pass in the XNameReplace.
710 // can remove the 3rd arg once issue ?? is fixed
711 void _SvxMacroTabPage::InitAndSetHandler( Reference
< container::XNameReplace
> xAppEvents
, Reference
< container::XNameReplace
> xDocEvents
, Reference
< util::XModifiable
> xModifiable
)
713 m_xAppEvents
= xAppEvents
;
714 m_xDocEvents
= xDocEvents
;
715 m_xModifiable
= xModifiable
;
716 SvHeaderTabListBox
& rListBox
= mpImpl
->pEventLB
->GetListBox();
717 HeaderBar
& rHeaderBar
= mpImpl
->pEventLB
->GetHeaderBar();
718 Link
aLnk(STATIC_LINK(this, _SvxMacroTabPage
, AssignDeleteHdl_Impl
));
719 mpImpl
->pDeletePB
->SetClickHdl( aLnk
);
720 mpImpl
->pAssignPB
->SetClickHdl( aLnk
);
721 if( mpImpl
->pAssignComponentPB
)
722 mpImpl
->pAssignComponentPB
->SetClickHdl( aLnk
);
723 rListBox
.SetDoubleClickHdl( STATIC_LINK(this, _SvxMacroTabPage
, DoubleClickHdl_Impl
) );
725 rListBox
.SetSelectHdl( STATIC_LINK( this, _SvxMacroTabPage
, SelectEvent_Impl
));
727 rListBox
.SetSelectionMode( SINGLE_SELECTION
);
728 rListBox
.SetTabs( &nTabs
[0], MAP_APPFONT
);
729 Size
aSize( nTabs
[ 2 ], 0 );
730 rHeaderBar
.InsertItem( ITEMID_EVENT
, *mpImpl
->pStrEvent
, LogicToPixel( aSize
, MapMode( MAP_APPFONT
) ).Width() );
731 aSize
.Width() = 1764; // don't know what, so 42^2 is best to use...
732 rHeaderBar
.InsertItem( ITMEID_ASSMACRO
, *mpImpl
->pAssignedMacro
, LogicToPixel( aSize
, MapMode( MAP_APPFONT
) ).Width() );
733 rListBox
.SetSpaceBetweenEntries( 0 );
735 mpImpl
->pEventLB
->Show();
736 mpImpl
->pEventLB
->ConnectElements();
738 long nMinLineHeight
= mpImpl
->pMacroImg
->GetSizePixel().Height() + 2;
739 if( nMinLineHeight
> mpImpl
->pEventLB
->GetListBox().GetEntryHeight() )
740 mpImpl
->pEventLB
->GetListBox().SetEntryHeight(
741 sal::static_int_cast
< short >(nMinLineHeight
) );
743 mpImpl
->pEventLB
->Enable( sal_True
);
745 if(!m_xAppEvents
.is())
749 Sequence
< OUString
> eventNames
= m_xAppEvents
->getElementNames();
750 sal_Int32 nEventCount
= eventNames
.getLength();
751 for(sal_Int32 nEvent
= 0; nEvent
< nEventCount
; ++nEvent
)
753 //need exception handling here
756 m_appEventsHash
[ eventNames
[nEvent
] ] = GetPairFromAny( m_xAppEvents
->getByName( eventNames
[nEvent
] ) );
758 catch (const Exception
&)
762 if(m_xDocEvents
.is())
764 eventNames
= m_xDocEvents
->getElementNames();
765 nEventCount
= eventNames
.getLength();
766 for(sal_Int32 nEvent
= 0; nEvent
< nEventCount
; ++nEvent
)
770 m_docEventsHash
[ eventNames
[nEvent
] ] = GetPairFromAny( m_xDocEvents
->getByName( eventNames
[nEvent
] ) );
772 catch (const Exception
&)
779 // returns the two props EventType & Script for a given event name
780 Any
_SvxMacroTabPage::GetPropsByName( const OUString
& eventName
, EventsHash
& eventsHash
)
782 const ::std::pair
< OUString
, OUString
>& rAssignedEvent( eventsHash
[ eventName
] );
785 ::comphelper::NamedValueCollection aProps
;
786 if ( !(rAssignedEvent
.first
.isEmpty() || rAssignedEvent
.second
.isEmpty()) )
788 aProps
.put( "EventType", rAssignedEvent
.first
);
789 aProps
.put( "Script", rAssignedEvent
.second
);
791 aReturn
<<= aProps
.getPropertyValues();
796 // converts the Any returned by GetByName into a pair which can be stored in
798 ::std::pair
< OUString
, OUString
> _SvxMacroTabPage::GetPairFromAny( Any aAny
)
800 Sequence
< beans::PropertyValue
> props
;
802 if( sal_True
== ( aAny
>>= props
) )
804 ::comphelper::NamedValueCollection
aProps( props
);
805 type
= aProps
.getOrDefault( "EventType", type
);
806 url
= aProps
.getOrDefault( "Script", url
);
808 return ::std::make_pair( type
, url
);
811 SvxMacroTabPage::SvxMacroTabPage( Window
* pParent
, const Reference
< frame::XFrame
>& _rxDocumentFrame
, const SfxItemSet
& rSet
, Reference
< container::XNameReplace
> xNameReplace
, sal_uInt16 nSelectedIndex
)
812 : _SvxMacroTabPage( pParent
, CUI_RES( RID_SVXPAGE_MACROASSIGN
), rSet
)
814 mpImpl
->pStrEvent
= new String( CUI_RES( STR_EVENT
) );
815 mpImpl
->pAssignedMacro
= new String( CUI_RES( STR_ASSMACRO
) );
816 mpImpl
->pEventLB
= new _HeaderTabListBox( this, CUI_RES( LB_EVENT
) );
817 mpImpl
->pAssignFT
= new FixedText( this, CUI_RES( FT_ASSIGN
) );
818 mpImpl
->pAssignPB
= new PushButton( this, CUI_RES( PB_ASSIGN
) );
819 mpImpl
->pDeletePB
= new PushButton( this, CUI_RES( PB_DELETE
) );
820 mpImpl
->pAssignComponentPB
= new PushButton( this, CUI_RES( PB_ASSIGN_COMPONENT
) );
821 mpImpl
->pMacroImg
= new Image( CUI_RES(IMG_MACRO
) );
822 mpImpl
->pComponentImg
= new Image( CUI_RES(IMG_COMPONENT
) );
826 SetFrame( _rxDocumentFrame
);
828 if( !mpImpl
->bIDEDialogMode
)
830 Point aPosAssign
= mpImpl
->pAssignPB
->GetPosPixel();
831 Point aPosComp
= mpImpl
->pAssignComponentPB
->GetPosPixel();
833 Point aPosDelete
= mpImpl
->pDeletePB
->GetPosPixel();
834 long nYDiff
= aPosComp
.Y() - aPosAssign
.Y();
835 aPosDelete
.Y() -= nYDiff
;
836 mpImpl
->pDeletePB
->SetPosPixel( aPosDelete
);
838 mpImpl
->pAssignComponentPB
->Hide();
839 mpImpl
->pAssignComponentPB
->Disable();
842 // must be done after FreeResource is called
845 mpImpl
->pEventLB
->GetListBox().SetHelpId( HID_SVX_MACRO_LB_EVENT
);
847 InitAndSetHandler( xNameReplace
, Reference
< container::XNameReplace
>(0), Reference
< util::XModifiable
>(0));
848 DisplayAppEvents(true);
849 SvHeaderTabListBox
& rListBox
= mpImpl
->pEventLB
->GetListBox();
850 SvTreeListEntry
* pE
= rListBox
.GetEntry( (sal_uLong
)nSelectedIndex
);
855 SvxMacroTabPage::~SvxMacroTabPage()
859 SvxMacroAssignDlg::SvxMacroAssignDlg( Window
* pParent
, const Reference
< frame::XFrame
>& _rxDocumentFrame
, const SfxItemSet
& rSet
,
860 const Reference
< container::XNameReplace
>& xNameReplace
, sal_uInt16 nSelectedIndex
)
861 : SvxMacroAssignSingleTabDialog( pParent
, rSet
, 0 )
863 SetTabPage( new SvxMacroTabPage( this, _rxDocumentFrame
, rSet
, xNameReplace
, nSelectedIndex
) );
866 SvxMacroAssignDlg::~SvxMacroAssignDlg()
871 //===============================================
873 IMPL_LINK_NOARG(AssignComponentDialog
, ButtonHandler
)
875 OUString aMethodName
= maMethodEdit
.GetText();
877 if( !aMethodName
.isEmpty() )
879 maURL
= aVndSunStarUNO
;
880 maURL
+= aMethodName
;
886 AssignComponentDialog::AssignComponentDialog( Window
* pParent
, const OUString
& rURL
)
887 : ModalDialog( pParent
, CUI_RES( RID_SVXDLG_ASSIGNCOMPONENT
) )
888 , maMethodLabel( this, CUI_RES( FT_METHOD
) )
889 , maMethodEdit( this, CUI_RES( EDIT_METHOD
) )
890 , maOKButton( this, CUI_RES( RID_PB_OK
) )
891 , maCancelButton( this, CUI_RES( RID_PB_CANCEL
) )
892 , maHelpButton( this, CUI_RES( RID_PB_HELP
) )
896 maOKButton
.SetClickHdl(LINK(this, AssignComponentDialog
, ButtonHandler
));
898 OUString aMethodName
;
899 if( !maURL
.isEmpty() )
901 sal_Int32 nIndex
= maURL
.indexOf( aVndSunStarUNO
);
904 sal_Int32 nBegin
= aVndSunStarUNO
.getLength();
905 aMethodName
= maURL
.copy( nBegin
);
908 maMethodEdit
.SetText( aMethodName
, Selection( 0, SELECTION_MAX
) );
911 AssignComponentDialog::~AssignComponentDialog()
915 // -----------------------------------------------------------------------
917 IMPL_LINK( SvxMacroAssignSingleTabDialog
, OKHdl_Impl
, Button
*, pButton
)
919 (void)pButton
; //unused
920 pPage
->FillItemSet( *pOutSet
);
925 // -----------------------------------------------------------------------
927 SvxMacroAssignSingleTabDialog::SvxMacroAssignSingleTabDialog
928 ( Window
*pParent
, const SfxItemSet
& rSet
, sal_uInt16 nUniqueId
) :
929 SfxModalDialog( pParent
, nUniqueId
, WinBits( WB_STDMODAL
| WB_3DLOOK
) ),
940 // -----------------------------------------------------------------------
942 SvxMacroAssignSingleTabDialog::~SvxMacroAssignSingleTabDialog()
951 // -----------------------------------------------------------------------
953 // According to SfxNoLayoutSingleTabDialog
954 void SvxMacroAssignSingleTabDialog::SetTabPage( SfxTabPage
* pTabPage
)
956 pFixedLine
= new FixedLine( this );
958 pOKBtn
= new OKButton( this, WB_DEFBUTTON
);
959 pOKBtn
->SetClickHdl( LINK( this, SvxMacroAssignSingleTabDialog
, OKHdl_Impl
) );
961 pCancelBtn
= new CancelButton( this );
962 pHelpBtn
= new HelpButton( this );
969 pPage
->SetUserData( sUserData
);
970 pPage
->Reset( *pOptions
);
973 // Set dialog's and buttons' size and position according to tabpage size
974 long nSpaceX
= LogicToPixel( Size( 6, 0 ), MAP_APPFONT
).Width();
975 long nSpaceY
= LogicToPixel( Size( 0, 6 ), MAP_APPFONT
).Height();
976 long nHalfSpaceX
= LogicToPixel( Size( 3, 0 ), MAP_APPFONT
).Width();
977 long nHalfSpaceY
= LogicToPixel( Size( 0, 3 ), MAP_APPFONT
).Height();
979 pPage
->SetPosPixel( Point() );
980 Size
aTabpageSize( pPage
->GetSizePixel() );
981 Size
aDialogSize( aTabpageSize
);
982 Size aButtonSize
= LogicToPixel( Size( 50, 14 ), MAP_APPFONT
);
983 long nButtonWidth
= aButtonSize
.Width();
984 long nButtonHeight
= aButtonSize
.Height();
986 Size
aFixedLineSize( aTabpageSize
);
987 long nFixedLineHeight
= LogicToPixel( Size( 0, 8 ), MAP_APPFONT
).Height();
988 aFixedLineSize
.Height() = nFixedLineHeight
;
990 aDialogSize
.Height() += nFixedLineHeight
+ nButtonHeight
+ nSpaceY
+ nHalfSpaceY
;
991 SetOutputSizePixel( aDialogSize
);
993 long nButtonPosY
= aTabpageSize
.Height() + nFixedLineHeight
+ nHalfSpaceY
;
994 long nHelpButtonPosX
= nSpaceX
;
995 pHelpBtn
->SetPosSizePixel( Point( nHelpButtonPosX
, nButtonPosY
), aButtonSize
);
998 long nCancelButtonPosX
= aDialogSize
.Width() - nButtonWidth
- nSpaceX
+ 1;
999 pCancelBtn
->SetPosSizePixel( Point( nCancelButtonPosX
, nButtonPosY
), aButtonSize
);
1002 long nOkButtonPosX
= nCancelButtonPosX
- nButtonWidth
- nHalfSpaceX
;
1003 pOKBtn
->SetPosSizePixel( Point( nOkButtonPosX
, nButtonPosY
), aButtonSize
);
1006 long nFixedLinePosY
= aTabpageSize
.Height();
1007 pFixedLine
->SetPosSizePixel( Point( 0, nFixedLinePosY
), aFixedLineSize
);
1010 // Get text from TabPage
1011 SetText( pPage
->GetText() );
1013 // Get IDs from TabPage
1014 SetHelpId( pPage
->GetHelpId() );
1015 SetUniqueId( pPage
->GetUniqueId() );
1019 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */