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 <macropg.hxx>
21 #include <svl/eitem.hxx>
22 #include <tools/debug.hxx>
23 #include <tools/diagnose_ex.h>
24 #include <bitmaps.hlst>
25 #include <cfgutil.hxx>
26 #include <dialmgr.hxx>
28 #include <headertablistbox.hxx>
29 #include "macropg_impl.hxx"
30 #include <svl/macitem.hxx>
31 #include <svx/svxids.hrc>
32 #include <strings.hrc>
33 #include <comphelper/namedvaluecollection.hxx>
39 using namespace ::com::sun::star
;
40 using namespace ::com::sun::star::uno
;
42 static const char aVndSunStarUNO
[] = "vnd.sun.star.UNO:";
44 SvxMacroTabPage_Impl::SvxMacroTabPage_Impl( const SfxItemSet
& rAttrSet
)
46 , bIDEDialogMode(false)
48 const SfxPoolItem
* pItem
;
49 if ( SfxItemState::SET
== rAttrSet
.GetItemState( SID_ATTR_MACROITEM
, false, &pItem
) )
50 bIDEDialogMode
= static_cast<const SfxBoolItem
*>(pItem
)->GetValue();
53 MacroEventListBox::MacroEventListBox(std::unique_ptr
<weld::TreeView
> xTreeView
)
54 : m_xTreeView(std::move(xTreeView
))
56 m_xTreeView
->set_help_id(HID_MACRO_HEADERTABLISTBOX
);
57 m_xTreeView
->set_size_request(m_xTreeView
->get_approximate_digit_width() * 70, m_xTreeView
->get_height_rows(9));
60 // assign button ("Add Command") is enabled only if it is not read only
61 // delete button ("Remove Command") is enabled if a current binding exists
62 // and it is not read only
63 void SvxMacroTabPage_::EnableButtons()
65 int nEvent
= mpImpl
->xEventLB
->get_selected_index();
68 mpImpl
->xDeletePB
->set_sensitive( !mpImpl
->bReadOnly
);
69 mpImpl
->xAssignPB
->set_sensitive( !mpImpl
->bReadOnly
);
70 if( mpImpl
->xAssignComponentPB
)
71 mpImpl
->xAssignComponentPB
->set_sensitive( !mpImpl
->bReadOnly
);
75 SvxMacroTabPage_::SvxMacroTabPage_(weld::Container
* pPage
, weld::DialogController
* pController
, const OUString
& rUIXMLDescription
,
76 const OString
& rID
, const SfxItemSet
& rAttrSet
)
77 : SfxTabPage(pPage
, pController
, rUIXMLDescription
, rID
, &rAttrSet
)
82 mpImpl
.reset( new SvxMacroTabPage_Impl( rAttrSet
) );
85 SvxMacroTabPage_::~SvxMacroTabPage_()
90 void SvxMacroTabPage_::InitResources()
92 // Note: the order here controls the order in which the events are displayed in the UI!
94 // the event name to UI string mappings for App Events
95 aDisplayNames
.emplace_back( "OnStartApp", RID_SVXSTR_EVENT_STARTAPP
);
96 aDisplayNames
.emplace_back( "OnCloseApp", RID_SVXSTR_EVENT_CLOSEAPP
);
97 aDisplayNames
.emplace_back( "OnCreate", RID_SVXSTR_EVENT_CREATEDOC
);
98 aDisplayNames
.emplace_back( "OnNew", RID_SVXSTR_EVENT_NEWDOC
);
99 aDisplayNames
.emplace_back( "OnLoadFinished", RID_SVXSTR_EVENT_LOADDOCFINISHED
);
100 aDisplayNames
.emplace_back( "OnLoad", RID_SVXSTR_EVENT_OPENDOC
);
101 aDisplayNames
.emplace_back( "OnPrepareUnload", RID_SVXSTR_EVENT_PREPARECLOSEDOC
);
102 aDisplayNames
.emplace_back( "OnUnload", RID_SVXSTR_EVENT_CLOSEDOC
) ;
103 aDisplayNames
.emplace_back( "OnViewCreated", RID_SVXSTR_EVENT_VIEWCREATED
);
104 aDisplayNames
.emplace_back( "OnPrepareViewClosing", RID_SVXSTR_EVENT_PREPARECLOSEVIEW
);
105 aDisplayNames
.emplace_back( "OnViewClosed", RID_SVXSTR_EVENT_CLOSEVIEW
) ;
106 aDisplayNames
.emplace_back( "OnFocus", RID_SVXSTR_EVENT_ACTIVATEDOC
);
107 aDisplayNames
.emplace_back( "OnUnfocus", RID_SVXSTR_EVENT_DEACTIVATEDOC
);
108 aDisplayNames
.emplace_back( "OnSave", RID_SVXSTR_EVENT_SAVEDOC
);
109 aDisplayNames
.emplace_back( "OnSaveDone", RID_SVXSTR_EVENT_SAVEDOCDONE
);
110 aDisplayNames
.emplace_back( "OnSaveFailed", RID_SVXSTR_EVENT_SAVEDOCFAILED
);
111 aDisplayNames
.emplace_back( "OnSaveAs", RID_SVXSTR_EVENT_SAVEASDOC
);
112 aDisplayNames
.emplace_back( "OnSaveAsDone", RID_SVXSTR_EVENT_SAVEASDOCDONE
);
113 aDisplayNames
.emplace_back( "OnSaveAsFailed", RID_SVXSTR_EVENT_SAVEASDOCFAILED
);
114 aDisplayNames
.emplace_back( "OnCopyTo", RID_SVXSTR_EVENT_COPYTODOC
);
115 aDisplayNames
.emplace_back( "OnCopyToDone", RID_SVXSTR_EVENT_COPYTODOCDONE
);
116 aDisplayNames
.emplace_back( "OnCopyToFailed", RID_SVXSTR_EVENT_COPYTODOCFAILED
);
117 aDisplayNames
.emplace_back( "OnPrint", RID_SVXSTR_EVENT_PRINTDOC
);
118 aDisplayNames
.emplace_back( "OnModifyChanged", RID_SVXSTR_EVENT_MODIFYCHANGED
);
119 aDisplayNames
.emplace_back( "OnTitleChanged", RID_SVXSTR_EVENT_TITLECHANGED
);
121 // application specific events
122 aDisplayNames
.emplace_back( "OnMailMerge", RID_SVXSTR_EVENT_MAILMERGE
);
123 aDisplayNames
.emplace_back( "OnMailMergeFinished", RID_SVXSTR_EVENT_MAILMERGE_END
);
124 aDisplayNames
.emplace_back( "OnFieldMerge", RID_SVXSTR_EVENT_FIELDMERGE
);
125 aDisplayNames
.emplace_back( "OnFieldMergeFinished", RID_SVXSTR_EVENT_FIELDMERGE_FINISHED
);
126 aDisplayNames
.emplace_back( "OnPageCountChange", RID_SVXSTR_EVENT_PAGECOUNTCHANGE
);
127 aDisplayNames
.emplace_back( "OnSubComponentOpened", RID_SVXSTR_EVENT_SUBCOMPONENT_OPENED
);
128 aDisplayNames
.emplace_back( "OnSubComponentClosed", RID_SVXSTR_EVENT_SUBCOMPONENT_CLOSED
);
129 aDisplayNames
.emplace_back( "OnSelect", RID_SVXSTR_EVENT_SELECTIONCHANGED
);
130 aDisplayNames
.emplace_back( "OnDoubleClick", RID_SVXSTR_EVENT_DOUBLECLICK
);
131 aDisplayNames
.emplace_back( "OnRightClick", RID_SVXSTR_EVENT_RIGHTCLICK
);
132 aDisplayNames
.emplace_back( "OnCalculate", RID_SVXSTR_EVENT_CALCULATE
);
133 aDisplayNames
.emplace_back( "OnChange", RID_SVXSTR_EVENT_CONTENTCHANGED
);
135 // the event name to UI string mappings for forms & dialogs
137 aDisplayNames
.emplace_back( "approveAction", RID_SVXSTR_EVENT_APPROVEACTIONPERFORMED
);
138 aDisplayNames
.emplace_back( "actionPerformed", RID_SVXSTR_EVENT_ACTIONPERFORMED
);
139 aDisplayNames
.emplace_back( "changed", RID_SVXSTR_EVENT_CHANGED
);
140 aDisplayNames
.emplace_back( "textChanged", RID_SVXSTR_EVENT_TEXTCHANGED
);
141 aDisplayNames
.emplace_back( "itemStateChanged", RID_SVXSTR_EVENT_ITEMSTATECHANGED
);
142 aDisplayNames
.emplace_back( "focusGained", RID_SVXSTR_EVENT_FOCUSGAINED
);
143 aDisplayNames
.emplace_back( "focusLost", RID_SVXSTR_EVENT_FOCUSLOST
);
144 aDisplayNames
.emplace_back( "keyPressed", RID_SVXSTR_EVENT_KEYTYPED
);
145 aDisplayNames
.emplace_back( "keyReleased", RID_SVXSTR_EVENT_KEYUP
);
146 aDisplayNames
.emplace_back( "mouseEntered", RID_SVXSTR_EVENT_MOUSEENTERED
);
147 aDisplayNames
.emplace_back( "mouseDragged", RID_SVXSTR_EVENT_MOUSEDRAGGED
);
148 aDisplayNames
.emplace_back( "mouseMoved", RID_SVXSTR_EVENT_MOUSEMOVED
);
149 aDisplayNames
.emplace_back( "mousePressed", RID_SVXSTR_EVENT_MOUSEPRESSED
);
150 aDisplayNames
.emplace_back( "mouseReleased", RID_SVXSTR_EVENT_MOUSERELEASED
);
151 aDisplayNames
.emplace_back( "mouseExited", RID_SVXSTR_EVENT_MOUSEEXITED
);
152 aDisplayNames
.emplace_back( "approveReset", RID_SVXSTR_EVENT_APPROVERESETTED
);
153 aDisplayNames
.emplace_back( "resetted", RID_SVXSTR_EVENT_RESETTED
);
154 aDisplayNames
.emplace_back( "approveSubmit", RID_SVXSTR_EVENT_SUBMITTED
);
155 aDisplayNames
.emplace_back( "approveUpdate", RID_SVXSTR_EVENT_BEFOREUPDATE
);
156 aDisplayNames
.emplace_back( "updated", RID_SVXSTR_EVENT_AFTERUPDATE
);
157 aDisplayNames
.emplace_back( "loaded", RID_SVXSTR_EVENT_LOADED
);
158 aDisplayNames
.emplace_back( "reloading", RID_SVXSTR_EVENT_RELOADING
);
159 aDisplayNames
.emplace_back( "reloaded", RID_SVXSTR_EVENT_RELOADED
);
160 aDisplayNames
.emplace_back( "unloading", RID_SVXSTR_EVENT_UNLOADING
);
161 aDisplayNames
.emplace_back( "unloaded", RID_SVXSTR_EVENT_UNLOADED
);
162 aDisplayNames
.emplace_back( "confirmDelete", RID_SVXSTR_EVENT_CONFIRMDELETE
);
163 aDisplayNames
.emplace_back( "approveRowChange", RID_SVXSTR_EVENT_APPROVEROWCHANGE
);
164 aDisplayNames
.emplace_back( "rowChanged", RID_SVXSTR_EVENT_ROWCHANGE
);
165 aDisplayNames
.emplace_back( "approveCursorMove", RID_SVXSTR_EVENT_POSITIONING
);
166 aDisplayNames
.emplace_back( "cursorMoved", RID_SVXSTR_EVENT_POSITIONED
);
167 aDisplayNames
.emplace_back( "approveParameter", RID_SVXSTR_EVENT_APPROVEPARAMETER
);
168 aDisplayNames
.emplace_back( "errorOccured", RID_SVXSTR_EVENT_ERROROCCURRED
);
169 aDisplayNames
.emplace_back( "adjustmentValueChanged", RID_SVXSTR_EVENT_ADJUSTMENTVALUECHANGED
);
172 // the following method is called when the user clicks OK
173 // We use the contents of the hashes to replace the settings
174 bool SvxMacroTabPage_::FillItemSet( SfxItemSet
* /*rSet*/ )
179 if( m_xAppEvents
.is() )
181 for (auto const& appEvent
: m_appEventsHash
)
183 eventName
= appEvent
.first
;
186 m_xAppEvents
->replaceByName( eventName
, GetPropsByName( eventName
, m_appEventsHash
) );
188 catch (const Exception
&)
190 DBG_UNHANDLED_EXCEPTION("cui.customize");
194 if( m_xDocEvents
.is() && bDocModified
)
196 for (auto const& docEvent
: m_docEventsHash
)
198 eventName
= docEvent
.first
;
201 m_xDocEvents
->replaceByName( eventName
, GetPropsByName( eventName
, m_docEventsHash
) );
203 catch (const Exception
&)
205 DBG_UNHANDLED_EXCEPTION("cui.customize");
208 // if we have a valid XModifiable (in the case of doc events)
209 // call setModified(true)
210 // in principle this should not be necessary (see issue ??)
211 if(m_xModifiable
.is())
213 m_xModifiable
->setModified( true );
217 catch (const Exception
&)
220 // what is the return value about??
224 // the following method clears the bindings in the hashes for both doc & app
225 void SvxMacroTabPage_::Reset( const SfxItemSet
* )
227 // called once in creation - don't reset the data this time
236 if( m_xAppEvents
.is() )
238 for (auto & appEvent
: m_appEventsHash
)
240 appEvent
.second
.second
.clear();
243 if( m_xDocEvents
.is() && bDocModified
)
245 for (auto & docEvent
: m_docEventsHash
)
247 docEvent
.second
.second
.clear();
249 // if we have a valid XModifiable (in the case of doc events)
250 // call setModified(true)
251 if(m_xModifiable
.is())
253 m_xModifiable
->setModified( true );
257 catch (const Exception
&)
260 DisplayAppEvents(bAppEvents
);
263 void SvxMacroTabPage_::SetReadOnly( bool bSet
)
265 mpImpl
->bReadOnly
= bSet
;
268 bool SvxMacroTabPage_::IsReadOnly() const
270 return mpImpl
->bReadOnly
;
275 OUString
GetEventDisplayText(const OUString
&rURL
)
279 sal_Int32 nIndex
= rURL
.indexOf(aVndSunStarUNO
);
280 bool bUNO
= nIndex
== 0;
281 OUString aPureMethod
;
284 aPureMethod
= rURL
.copy(strlen(aVndSunStarUNO
));
288 aPureMethod
= rURL
.copy(strlen("vnd.sun.star.script:"));
289 aPureMethod
= aPureMethod
.copy( 0, aPureMethod
.indexOf( '?' ) );
294 OUString
GetEventDisplayImage(const OUString
&rURL
)
298 sal_Int32 nIndex
= rURL
.indexOf(aVndSunStarUNO
);
299 bool bUNO
= nIndex
== 0;
300 return bUNO
? OUString(RID_SVXBMP_COMPONENT
) : OUString(RID_SVXBMP_MACRO
);
304 // displays the app events if appEvents=true, otherwise displays the doc events
305 void SvxMacroTabPage_::DisplayAppEvents( bool appEvents
)
307 bAppEvents
= appEvents
;
309 mpImpl
->xEventLB
->freeze();
310 mpImpl
->xEventLB
->clear();
311 EventsHash
* eventsHash
;
312 Reference
< container::XNameReplace
> nameReplace
;
315 eventsHash
= &m_appEventsHash
;
316 nameReplace
= m_xAppEvents
;
320 eventsHash
= &m_docEventsHash
;
321 nameReplace
= m_xDocEvents
;
323 // have to use the original XNameReplace since the hash iterators do
324 // not guarantee the order in which the elements are returned
325 if(!nameReplace
.is())
328 Sequence
< OUString
> eventNames
= nameReplace
->getElementNames();
329 std::set
< OUString
> aEventNamesCache
;
333 std::insert_iterator
< std::set
< OUString
> >( aEventNamesCache
, aEventNamesCache
.end() )
336 for (auto const& displayableEvent
: aDisplayNames
)
338 OUString
sEventName( OUString::createFromAscii( displayableEvent
.pAsciiEventName
) );
339 if ( !nameReplace
->hasByName( sEventName
) )
342 EventsHash::iterator h_it
= eventsHash
->find( sEventName
);
343 if( h_it
== eventsHash
->end() )
345 OSL_FAIL( "SvxMacroTabPage_::DisplayAppEvents: something's suspicious here!" );
349 OUString eventURL
= h_it
->second
.second
;
350 OUString
displayName(CuiResId(displayableEvent
.pEventResourceID
));
352 int nRow
= mpImpl
->xEventLB
->n_children();
353 mpImpl
->xEventLB
->append(sEventName
, displayName
);
354 mpImpl
->xEventLB
->set_image(nRow
, GetEventDisplayImage(eventURL
), 1);
355 mpImpl
->xEventLB
->set_text(nRow
, GetEventDisplayText(eventURL
), 2);
358 mpImpl
->xEventLB
->thaw();
360 if (mpImpl
->xEventLB
->n_children())
362 mpImpl
->xEventLB
->select(0);
363 mpImpl
->xEventLB
->scroll_to_row(0);
369 // select event handler on the listbox
370 IMPL_LINK_NOARG( SvxMacroTabPage_
, SelectEvent_Impl
, weld::TreeView
&, void)
372 int nEntry
= mpImpl
->xEventLB
->get_selected_index();
376 DBG_ASSERT(false, "Where does the empty entry come from?" );
383 IMPL_LINK( SvxMacroTabPage_
, AssignDeleteHdl_Impl
, weld::Button
&, rBtn
, void )
385 GenericHandler_Impl(this, &rBtn
);
388 IMPL_LINK_NOARG( SvxMacroTabPage_
, DoubleClickHdl_Impl
, weld::TreeView
&, bool)
390 GenericHandler_Impl(this, nullptr);
394 // handler for double click on the listbox, and for the assign/delete buttons
395 void SvxMacroTabPage_::GenericHandler_Impl(SvxMacroTabPage_
* pThis
, const weld::Button
* pBtn
)
397 SvxMacroTabPage_Impl
* pImpl
= pThis
->mpImpl
.get();
398 weld::TreeView
& rListBox
= *pImpl
->xEventLB
;
399 int nEntry
= rListBox
.get_selected_index();
402 DBG_ASSERT(false, "Where does the empty entry come from?");
406 const bool bAssEnabled
= pBtn
!= pImpl
->xDeletePB
.get() && pImpl
->xAssignPB
->get_sensitive();
408 OUString sEventName
= rListBox
.get_id(nEntry
);
412 if(pThis
->bAppEvents
)
414 EventsHash::iterator h_it
= pThis
->m_appEventsHash
.find(sEventName
);
415 if(h_it
!= pThis
->m_appEventsHash
.end() )
417 sEventType
= h_it
->second
.first
;
418 sEventURL
= h_it
->second
.second
;
423 EventsHash::iterator h_it
= pThis
->m_docEventsHash
.find(sEventName
);
424 if(h_it
!= pThis
->m_docEventsHash
.end() )
426 sEventType
= h_it
->second
.first
;
427 sEventURL
= h_it
->second
.second
;
431 bool bDoubleClick
= (pBtn
== nullptr);
432 bool bUNOAssigned
= sEventURL
.startsWith( aVndSunStarUNO
);
433 if( pBtn
== pImpl
->xDeletePB
.get() )
436 sEventType
= "Script" ;
438 if(!pThis
->bAppEvents
)
439 pThis
->bDocModified
= true;
441 else if ( ( ( pBtn
!= nullptr )
442 && ( pBtn
== pImpl
->xAssignComponentPB
.get() )
449 AssignComponentDialog
aAssignDlg(pThis
->GetFrameWeld(), sEventURL
);
451 short ret
= aAssignDlg
.run();
455 sEventURL
= aAssignDlg
.getURL();
456 if(!pThis
->bAppEvents
)
457 pThis
->bDocModified
= true;
460 else if( bAssEnabled
)
463 SvxScriptSelectorDialog
aDlg(pThis
->GetFrameWeld(), false, pThis
->GetFrame());
464 short ret
= aDlg
.run();
467 sEventType
= "Script";
468 sEventURL
= aDlg
.GetScriptURL();
469 if(!pThis
->bAppEvents
)
470 pThis
->bDocModified
= true;
475 if(pThis
->bAppEvents
)
477 EventsHash::iterator h_it
= pThis
->m_appEventsHash
.find(sEventName
);
478 h_it
->second
.first
= sEventType
;
479 h_it
->second
.second
= sEventURL
;
483 EventsHash::iterator h_it
= pThis
->m_docEventsHash
.find(sEventName
);
484 h_it
->second
.first
= sEventType
;
485 h_it
->second
.second
= sEventURL
;
488 rListBox
.set_image(nEntry
, GetEventDisplayImage(sEventURL
), 1);
489 rListBox
.set_text(nEntry
, GetEventDisplayText(sEventURL
), 2);
491 rListBox
.select(nEntry
);
492 rListBox
.scroll_to_row(nEntry
);
494 pThis
->EnableButtons();
497 // pass in the XNameReplace.
498 // can remove the 3rd arg once issue ?? is fixed
499 void SvxMacroTabPage_::InitAndSetHandler( const Reference
< container::XNameReplace
>& xAppEvents
, const Reference
< container::XNameReplace
>& xDocEvents
, const Reference
< util::XModifiable
>& xModifiable
)
501 m_xAppEvents
= xAppEvents
;
502 m_xDocEvents
= xDocEvents
;
503 m_xModifiable
= xModifiable
;
504 Link
<weld::Button
&,void> aLnk(LINK(this, SvxMacroTabPage_
, AssignDeleteHdl_Impl
));
505 mpImpl
->xDeletePB
->connect_clicked(aLnk
);
506 mpImpl
->xAssignPB
->connect_clicked(aLnk
);
507 if( mpImpl
->xAssignComponentPB
)
508 mpImpl
->xAssignComponentPB
->connect_clicked( aLnk
);
509 mpImpl
->xEventLB
->connect_row_activated( LINK(this, SvxMacroTabPage_
, DoubleClickHdl_Impl
) );
510 mpImpl
->xEventLB
->connect_changed( LINK( this, SvxMacroTabPage_
, SelectEvent_Impl
));
512 std::vector
<int> aWidths
;
513 aWidths
.push_back(mpImpl
->xEventLB
->get_approximate_digit_width() * 32);
514 aWidths
.push_back(mpImpl
->xEventLB
->get_checkbox_column_width());
515 mpImpl
->xEventLB
->set_column_fixed_widths(aWidths
);
517 mpImpl
->xEventLB
->show();
518 mpImpl
->xEventLB
->set_sensitive(true);
520 if(!m_xAppEvents
.is())
524 Sequence
< OUString
> eventNames
= m_xAppEvents
->getElementNames();
525 sal_Int32 nEventCount
= eventNames
.getLength();
526 for(sal_Int32 nEvent
= 0; nEvent
< nEventCount
; ++nEvent
)
528 //need exception handling here
531 m_appEventsHash
[ eventNames
[nEvent
] ] = GetPairFromAny( m_xAppEvents
->getByName( eventNames
[nEvent
] ) );
533 catch (const Exception
&)
537 if(m_xDocEvents
.is())
539 eventNames
= m_xDocEvents
->getElementNames();
540 nEventCount
= eventNames
.getLength();
541 for(sal_Int32 nEvent
= 0; nEvent
< nEventCount
; ++nEvent
)
545 m_docEventsHash
[ eventNames
[nEvent
] ] = GetPairFromAny( m_xDocEvents
->getByName( eventNames
[nEvent
] ) );
547 catch (const Exception
&)
554 // returns the two props EventType & Script for a given event name
555 Any
SvxMacroTabPage_::GetPropsByName( const OUString
& eventName
, EventsHash
& eventsHash
)
557 const std::pair
< OUString
, OUString
>& rAssignedEvent( eventsHash
[ eventName
] );
560 ::comphelper::NamedValueCollection aProps
;
561 if ( !(rAssignedEvent
.first
.isEmpty() || rAssignedEvent
.second
.isEmpty()) )
563 aProps
.put( "EventType", rAssignedEvent
.first
);
564 aProps
.put( "Script", rAssignedEvent
.second
);
566 aReturn
<<= aProps
.getPropertyValues();
571 // converts the Any returned by GetByName into a pair which can be stored in
573 std::pair
< OUString
, OUString
> SvxMacroTabPage_::GetPairFromAny( const Any
& aAny
)
575 Sequence
< beans::PropertyValue
> props
;
579 ::comphelper::NamedValueCollection
aProps( props
);
580 type
= aProps
.getOrDefault( "EventType", type
);
581 url
= aProps
.getOrDefault( "Script", url
);
583 return std::make_pair( type
, url
);
586 SvxMacroTabPage::SvxMacroTabPage(weld::Container
* pPage
, weld::DialogController
* pController
,
587 const Reference
< frame::XFrame
>& _rxDocumentFrame
,
588 const SfxItemSet
& rSet
,
589 Reference
< container::XNameReplace
> const & xNameReplace
,
590 sal_uInt16 nSelectedIndex
)
591 : SvxMacroTabPage_(pPage
, pController
, "cui/ui/macroassignpage.ui", "MacroAssignPage", rSet
)
593 mpImpl
->xEventLB
= m_xBuilder
->weld_tree_view("assignments");
594 mpImpl
->xEventLB
->set_size_request(mpImpl
->xEventLB
->get_approximate_digit_width() * 70,
595 mpImpl
->xEventLB
->get_height_rows(9));
596 mpImpl
->xAssignPB
= m_xBuilder
->weld_button("assign");
597 mpImpl
->xDeletePB
= m_xBuilder
->weld_button("delete");
598 mpImpl
->xAssignComponentPB
= m_xBuilder
->weld_button("component");
600 SetFrame( _rxDocumentFrame
);
602 if( !mpImpl
->bIDEDialogMode
)
604 mpImpl
->xAssignComponentPB
->hide();
605 mpImpl
->xAssignComponentPB
->set_sensitive(false);
610 InitAndSetHandler( xNameReplace
, Reference
< container::XNameReplace
>(nullptr), Reference
< util::XModifiable
>(nullptr));
611 DisplayAppEvents(true);
612 mpImpl
->xEventLB
->select(nSelectedIndex
);
615 SvxMacroAssignDlg::SvxMacroAssignDlg(weld::Window
* pParent
, const Reference
< frame::XFrame
>& _rxDocumentFrame
, const SfxItemSet
& rSet
,
616 const Reference
< container::XNameReplace
>& xNameReplace
, sal_uInt16 nSelectedIndex
)
617 : SvxMacroAssignSingleTabDialog(pParent
, rSet
)
619 SetTabPage(std::make_unique
<SvxMacroTabPage
>(get_content_area(), this, _rxDocumentFrame
, rSet
, xNameReplace
, nSelectedIndex
));
622 IMPL_LINK_NOARG(AssignComponentDialog
, ButtonHandler
, weld::Button
&, void)
624 OUString aMethodName
= mxMethodEdit
->get_text();
626 if( !aMethodName
.isEmpty() )
628 maURL
= aVndSunStarUNO
;
629 maURL
+= aMethodName
;
631 m_xDialog
->response(RET_OK
);
634 AssignComponentDialog::AssignComponentDialog(weld::Window
* pParent
, const OUString
& rURL
)
635 : GenericDialogController(pParent
, "cui/ui/assigncomponentdialog.ui", "AssignComponent")
637 , mxMethodEdit(m_xBuilder
->weld_entry("methodEntry"))
638 , mxOKButton(m_xBuilder
->weld_button("ok"))
640 mxOKButton
->connect_clicked(LINK(this, AssignComponentDialog
, ButtonHandler
));
642 OUString aMethodName
;
643 if( maURL
.startsWith( aVndSunStarUNO
) )
645 aMethodName
= maURL
.copy( strlen(aVndSunStarUNO
) );
647 mxMethodEdit
->set_text(aMethodName
);
648 mxMethodEdit
->select_region(0, -1);
651 AssignComponentDialog::~AssignComponentDialog()
655 IMPL_LINK_NOARG(SvxMacroAssignSingleTabDialog
, OKHdl_Impl
, weld::Button
&, void)
657 m_xSfxPage
->FillItemSet(nullptr);
658 m_xDialog
->response(RET_OK
);
661 SvxMacroAssignSingleTabDialog::SvxMacroAssignSingleTabDialog(weld::Window
*pParent
,
662 const SfxItemSet
& rSet
)
663 : SfxSingleTabDialogController(pParent
, &rSet
, "cui/ui/macroassigndialog.ui", "MacroAssignDialog")
665 GetOKButton().connect_clicked(LINK(this, SvxMacroAssignSingleTabDialog
, OKHdl_Impl
));
668 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */