bump product version to 6.3.0.0.beta1
[LibreOffice.git] / cui / source / customize / macropg.cxx
blob00af4cd2252d63278e8e408fe0992b83d7beec2e
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 <svl/eitem.hxx>
24 #include <tools/debug.hxx>
25 #include <tools/diagnose_ex.h>
26 #include <sfx2/app.hxx>
27 #include <sfx2/objsh.hxx>
28 #include <com/sun/star/container/NoSuchElementException.hpp>
29 #include <com/sun/star/lang/IllegalArgumentException.hpp>
30 #include <bitmaps.hlst>
31 #include <cfg.hxx>
32 #include <cfgutil.hxx>
33 #include <dialmgr.hxx>
34 #include <helpids.h>
35 #include <headertablistbox.hxx>
36 #include "macropg_impl.hxx"
37 #include <svx/dialogs.hrc>
38 #include <svx/svxids.hrc>
39 #include <strings.hrc>
40 #include <comphelper/namedvaluecollection.hxx>
42 #include <algorithm>
43 #include <iterator>
44 #include <set>
46 using namespace ::com::sun::star;
47 using namespace ::com::sun::star::uno;
49 static const char aVndSunStarUNO[] = "vnd.sun.star.UNO:";
51 SvxMacroTabPage_Impl::SvxMacroTabPage_Impl( const SfxItemSet& rAttrSet )
52 : bReadOnly(false)
53 , bIDEDialogMode(false)
55 const SfxPoolItem* pItem;
56 if ( SfxItemState::SET == rAttrSet.GetItemState( SID_ATTR_MACROITEM, false, &pItem ) )
57 bIDEDialogMode = static_cast<const SfxBoolItem*>(pItem)->GetValue();
60 MacroEventListBox::MacroEventListBox(std::unique_ptr<weld::TreeView> xTreeView)
61 : m_xTreeView(std::move(xTreeView))
63 m_xTreeView->set_help_id(HID_MACRO_HEADERTABLISTBOX);
64 m_xTreeView->set_size_request(m_xTreeView->get_approximate_digit_width() * 70, m_xTreeView->get_height_rows(9));
67 // assign button ("Add Command") is enabled only if it is not read only
68 // delete button ("Remove Command") is enabled if a current binding exists
69 // and it is not read only
70 void SvxMacroTabPage_::EnableButtons()
72 int nEvent = mpImpl->xEventLB->get_selected_index();
73 if (nEvent != -1)
75 mpImpl->xDeletePB->set_sensitive( !mpImpl->bReadOnly );
76 mpImpl->xAssignPB->set_sensitive( !mpImpl->bReadOnly );
77 if( mpImpl->xAssignComponentPB )
78 mpImpl->xAssignComponentPB->set_sensitive( !mpImpl->bReadOnly );
82 SvxMacroTabPage_::SvxMacroTabPage_(TabPageParent pParent, const OUString& rUIXMLDescription,
83 const OString& rID, const SfxItemSet& rAttrSet)
84 : SfxTabPage(pParent, rUIXMLDescription, rID, &rAttrSet)
85 , bDocModified(false)
86 , bAppEvents(false)
87 , bInitialized(false)
89 mpImpl.reset( new SvxMacroTabPage_Impl( rAttrSet ) );
92 SvxMacroTabPage_::~SvxMacroTabPage_()
94 disposeOnce();
97 void SvxMacroTabPage_::dispose()
99 mpImpl.reset();
100 SfxTabPage::dispose();
103 void SvxMacroTabPage_::InitResources()
105 // Note: the order here controls the order in which the events are displayed in the UI!
107 // the event name to UI string mappings for App Events
108 aDisplayNames.emplace_back( "OnStartApp", RID_SVXSTR_EVENT_STARTAPP );
109 aDisplayNames.emplace_back( "OnCloseApp", RID_SVXSTR_EVENT_CLOSEAPP );
110 aDisplayNames.emplace_back( "OnCreate", RID_SVXSTR_EVENT_CREATEDOC );
111 aDisplayNames.emplace_back( "OnNew", RID_SVXSTR_EVENT_NEWDOC );
112 aDisplayNames.emplace_back( "OnLoadFinished", RID_SVXSTR_EVENT_LOADDOCFINISHED );
113 aDisplayNames.emplace_back( "OnLoad", RID_SVXSTR_EVENT_OPENDOC );
114 aDisplayNames.emplace_back( "OnPrepareUnload", RID_SVXSTR_EVENT_PREPARECLOSEDOC );
115 aDisplayNames.emplace_back( "OnUnload", RID_SVXSTR_EVENT_CLOSEDOC ) ;
116 aDisplayNames.emplace_back( "OnViewCreated", RID_SVXSTR_EVENT_VIEWCREATED );
117 aDisplayNames.emplace_back( "OnPrepareViewClosing", RID_SVXSTR_EVENT_PREPARECLOSEVIEW );
118 aDisplayNames.emplace_back( "OnViewClosed", RID_SVXSTR_EVENT_CLOSEVIEW ) ;
119 aDisplayNames.emplace_back( "OnFocus", RID_SVXSTR_EVENT_ACTIVATEDOC );
120 aDisplayNames.emplace_back( "OnUnfocus", RID_SVXSTR_EVENT_DEACTIVATEDOC );
121 aDisplayNames.emplace_back( "OnSave", RID_SVXSTR_EVENT_SAVEDOC );
122 aDisplayNames.emplace_back( "OnSaveDone", RID_SVXSTR_EVENT_SAVEDOCDONE );
123 aDisplayNames.emplace_back( "OnSaveFailed", RID_SVXSTR_EVENT_SAVEDOCFAILED );
124 aDisplayNames.emplace_back( "OnSaveAs", RID_SVXSTR_EVENT_SAVEASDOC );
125 aDisplayNames.emplace_back( "OnSaveAsDone", RID_SVXSTR_EVENT_SAVEASDOCDONE );
126 aDisplayNames.emplace_back( "OnSaveAsFailed", RID_SVXSTR_EVENT_SAVEASDOCFAILED );
127 aDisplayNames.emplace_back( "OnCopyTo", RID_SVXSTR_EVENT_COPYTODOC );
128 aDisplayNames.emplace_back( "OnCopyToDone", RID_SVXSTR_EVENT_COPYTODOCDONE );
129 aDisplayNames.emplace_back( "OnCopyToFailed", RID_SVXSTR_EVENT_COPYTODOCFAILED );
130 aDisplayNames.emplace_back( "OnPrint", RID_SVXSTR_EVENT_PRINTDOC );
131 aDisplayNames.emplace_back( "OnModifyChanged", RID_SVXSTR_EVENT_MODIFYCHANGED );
132 aDisplayNames.emplace_back( "OnTitleChanged", RID_SVXSTR_EVENT_TITLECHANGED );
134 // application specific events
135 aDisplayNames.emplace_back( "OnMailMerge", RID_SVXSTR_EVENT_MAILMERGE );
136 aDisplayNames.emplace_back( "OnMailMergeFinished", RID_SVXSTR_EVENT_MAILMERGE_END );
137 aDisplayNames.emplace_back( "OnFieldMerge", RID_SVXSTR_EVENT_FIELDMERGE );
138 aDisplayNames.emplace_back( "OnFieldMergeFinished", RID_SVXSTR_EVENT_FIELDMERGE_FINISHED );
139 aDisplayNames.emplace_back( "OnPageCountChange", RID_SVXSTR_EVENT_PAGECOUNTCHANGE );
140 aDisplayNames.emplace_back( "OnSubComponentOpened", RID_SVXSTR_EVENT_SUBCOMPONENT_OPENED );
141 aDisplayNames.emplace_back( "OnSubComponentClosed", RID_SVXSTR_EVENT_SUBCOMPONENT_CLOSED );
142 aDisplayNames.emplace_back( "OnSelect", RID_SVXSTR_EVENT_SELECTIONCHANGED );
143 aDisplayNames.emplace_back( "OnDoubleClick", RID_SVXSTR_EVENT_DOUBLECLICK );
144 aDisplayNames.emplace_back( "OnRightClick", RID_SVXSTR_EVENT_RIGHTCLICK );
145 aDisplayNames.emplace_back( "OnCalculate", RID_SVXSTR_EVENT_CALCULATE );
146 aDisplayNames.emplace_back( "OnChange", RID_SVXSTR_EVENT_CONTENTCHANGED );
148 // the event name to UI string mappings for forms & dialogs
150 aDisplayNames.emplace_back( "approveAction", RID_SVXSTR_EVENT_APPROVEACTIONPERFORMED );
151 aDisplayNames.emplace_back( "actionPerformed", RID_SVXSTR_EVENT_ACTIONPERFORMED );
152 aDisplayNames.emplace_back( "changed", RID_SVXSTR_EVENT_CHANGED );
153 aDisplayNames.emplace_back( "textChanged", RID_SVXSTR_EVENT_TEXTCHANGED );
154 aDisplayNames.emplace_back( "itemStateChanged", RID_SVXSTR_EVENT_ITEMSTATECHANGED );
155 aDisplayNames.emplace_back( "focusGained", RID_SVXSTR_EVENT_FOCUSGAINED );
156 aDisplayNames.emplace_back( "focusLost", RID_SVXSTR_EVENT_FOCUSLOST );
157 aDisplayNames.emplace_back( "keyPressed", RID_SVXSTR_EVENT_KEYTYPED );
158 aDisplayNames.emplace_back( "keyReleased", RID_SVXSTR_EVENT_KEYUP );
159 aDisplayNames.emplace_back( "mouseEntered", RID_SVXSTR_EVENT_MOUSEENTERED );
160 aDisplayNames.emplace_back( "mouseDragged", RID_SVXSTR_EVENT_MOUSEDRAGGED );
161 aDisplayNames.emplace_back( "mouseMoved", RID_SVXSTR_EVENT_MOUSEMOVED );
162 aDisplayNames.emplace_back( "mousePressed", RID_SVXSTR_EVENT_MOUSEPRESSED );
163 aDisplayNames.emplace_back( "mouseReleased", RID_SVXSTR_EVENT_MOUSERELEASED );
164 aDisplayNames.emplace_back( "mouseExited", RID_SVXSTR_EVENT_MOUSEEXITED );
165 aDisplayNames.emplace_back( "approveReset", RID_SVXSTR_EVENT_APPROVERESETTED );
166 aDisplayNames.emplace_back( "resetted", RID_SVXSTR_EVENT_RESETTED );
167 aDisplayNames.emplace_back( "approveSubmit", RID_SVXSTR_EVENT_SUBMITTED );
168 aDisplayNames.emplace_back( "approveUpdate", RID_SVXSTR_EVENT_BEFOREUPDATE );
169 aDisplayNames.emplace_back( "updated", RID_SVXSTR_EVENT_AFTERUPDATE );
170 aDisplayNames.emplace_back( "loaded", RID_SVXSTR_EVENT_LOADED );
171 aDisplayNames.emplace_back( "reloading", RID_SVXSTR_EVENT_RELOADING );
172 aDisplayNames.emplace_back( "reloaded", RID_SVXSTR_EVENT_RELOADED );
173 aDisplayNames.emplace_back( "unloading", RID_SVXSTR_EVENT_UNLOADING );
174 aDisplayNames.emplace_back( "unloaded", RID_SVXSTR_EVENT_UNLOADED );
175 aDisplayNames.emplace_back( "confirmDelete", RID_SVXSTR_EVENT_CONFIRMDELETE );
176 aDisplayNames.emplace_back( "approveRowChange", RID_SVXSTR_EVENT_APPROVEROWCHANGE );
177 aDisplayNames.emplace_back( "rowChanged", RID_SVXSTR_EVENT_ROWCHANGE );
178 aDisplayNames.emplace_back( "approveCursorMove", RID_SVXSTR_EVENT_POSITIONING );
179 aDisplayNames.emplace_back( "cursorMoved", RID_SVXSTR_EVENT_POSITIONED );
180 aDisplayNames.emplace_back( "approveParameter", RID_SVXSTR_EVENT_APPROVEPARAMETER );
181 aDisplayNames.emplace_back( "errorOccured", RID_SVXSTR_EVENT_ERROROCCURRED );
182 aDisplayNames.emplace_back( "adjustmentValueChanged", RID_SVXSTR_EVENT_ADJUSTMENTVALUECHANGED );
185 // the following method is called when the user clicks OK
186 // We use the contents of the hashes to replace the settings
187 bool SvxMacroTabPage_::FillItemSet( SfxItemSet* /*rSet*/ )
191 OUString eventName;
192 if( m_xAppEvents.is() )
194 for (auto const& appEvent : m_appEventsHash)
196 eventName = appEvent.first;
199 m_xAppEvents->replaceByName( eventName, GetPropsByName( eventName, m_appEventsHash ) );
201 catch (const Exception&)
203 DBG_UNHANDLED_EXCEPTION("cui.customize");
207 if( m_xDocEvents.is() && bDocModified )
209 for (auto const& docEvent : m_docEventsHash)
211 eventName = docEvent.first;
214 m_xDocEvents->replaceByName( eventName, GetPropsByName( eventName, m_docEventsHash ) );
216 catch (const Exception&)
218 DBG_UNHANDLED_EXCEPTION("cui.customize");
221 // if we have a valid XModifiable (in the case of doc events)
222 // call setModified(true)
223 // in principle this should not be necessary (see issue ??)
224 if(m_xModifiable.is())
226 m_xModifiable->setModified( true );
230 catch (const Exception&)
233 // what is the return value about??
234 return false;
237 // the following method clears the bindings in the hashes for both doc & app
238 void SvxMacroTabPage_::Reset( const SfxItemSet* )
240 // called once in creation - don't reset the data this time
241 if(!bInitialized)
243 bInitialized = true;
244 return;
249 if( m_xAppEvents.is() )
251 for (auto & appEvent : m_appEventsHash)
253 appEvent.second.second.clear();
256 if( m_xDocEvents.is() && bDocModified )
258 for (auto & docEvent : m_docEventsHash)
260 docEvent.second.second.clear();
262 // if we have a valid XModifiable (in the case of doc events)
263 // call setModified(true)
264 if(m_xModifiable.is())
266 m_xModifiable->setModified( true );
270 catch (const Exception&)
273 DisplayAppEvents(bAppEvents);
276 void SvxMacroTabPage_::SetReadOnly( bool bSet )
278 mpImpl->bReadOnly = bSet;
281 bool SvxMacroTabPage_::IsReadOnly() const
283 return mpImpl->bReadOnly;
286 namespace
288 OUString GetEventDisplayText(const OUString &rURL)
290 if (rURL.isEmpty())
291 return OUString();
292 sal_Int32 nIndex = rURL.indexOf(aVndSunStarUNO);
293 bool bUNO = nIndex == 0;
294 OUString aPureMethod;
295 if (bUNO)
297 aPureMethod = rURL.copy(strlen(aVndSunStarUNO));
299 else
301 aPureMethod = rURL.copy(strlen("vnd.sun.star.script:"));
302 aPureMethod = aPureMethod.copy( 0, aPureMethod.indexOf( '?' ) );
304 return aPureMethod;
307 OUString GetEventDisplayImage(const OUString &rURL)
309 if (rURL.isEmpty())
310 return OUString();
311 sal_Int32 nIndex = rURL.indexOf(aVndSunStarUNO);
312 bool bUNO = nIndex == 0;
313 return bUNO ? OUString(RID_SVXBMP_COMPONENT) : OUString(RID_SVXBMP_MACRO);
317 // displays the app events if appEvents=true, otherwise displays the doc events
318 void SvxMacroTabPage_::DisplayAppEvents( bool appEvents)
320 bAppEvents = appEvents;
322 mpImpl->xEventLB->freeze();
323 mpImpl->xEventLB->clear();
324 EventsHash* eventsHash;
325 Reference< container::XNameReplace> nameReplace;
326 if(bAppEvents)
328 eventsHash = &m_appEventsHash;
329 nameReplace = m_xAppEvents;
331 else
333 eventsHash = &m_docEventsHash;
334 nameReplace = m_xDocEvents;
336 // have to use the original XNameReplace since the hash iterators do
337 // not guarantee the order in which the elements are returned
338 if(!nameReplace.is())
339 return;
341 Sequence< OUString > eventNames = nameReplace->getElementNames();
342 std::set< OUString > aEventNamesCache;
343 std::copy(
344 eventNames.begin(),
345 eventNames.end(),
346 std::insert_iterator< std::set< OUString > >( aEventNamesCache, aEventNamesCache.end() )
349 for (auto const& displayableEvent : aDisplayNames)
351 OUString sEventName( OUString::createFromAscii( displayableEvent.pAsciiEventName ) );
352 if ( !nameReplace->hasByName( sEventName ) )
353 continue;
355 EventsHash::iterator h_it = eventsHash->find( sEventName );
356 if( h_it == eventsHash->end() )
358 OSL_FAIL( "SvxMacroTabPage_::DisplayAppEvents: something's suspicious here!" );
359 continue;
362 OUString eventURL = h_it->second.second;
363 OUString displayName(CuiResId(displayableEvent.pEventResourceID));
365 int nRow = mpImpl->xEventLB->n_children();
366 mpImpl->xEventLB->append(sEventName, displayName);
367 mpImpl->xEventLB->set_image(nRow, GetEventDisplayImage(eventURL), 1);
368 mpImpl->xEventLB->set_text(nRow, GetEventDisplayText(eventURL), 2);
371 mpImpl->xEventLB->thaw();
373 if (mpImpl->xEventLB->n_children())
375 mpImpl->xEventLB->select(0);
376 mpImpl->xEventLB->scroll_to_row(0);
379 EnableButtons();
382 // select event handler on the listbox
383 IMPL_LINK_NOARG( SvxMacroTabPage_, SelectEvent_Impl, weld::TreeView&, void)
385 int nEntry = mpImpl->xEventLB->get_selected_index();
387 if (nEntry == -1)
389 DBG_ASSERT(false, "Where does the empty entry come from?" );
390 return;
393 EnableButtons();
396 IMPL_LINK( SvxMacroTabPage_, AssignDeleteHdl_Impl, weld::Button&, rBtn, void )
398 GenericHandler_Impl(this, &rBtn);
401 IMPL_LINK_NOARG( SvxMacroTabPage_, DoubleClickHdl_Impl, weld::TreeView&, void)
403 GenericHandler_Impl(this, nullptr);
406 // handler for double click on the listbox, and for the assign/delete buttons
407 void SvxMacroTabPage_::GenericHandler_Impl(SvxMacroTabPage_* pThis, weld::Button* pBtn)
409 SvxMacroTabPage_Impl* pImpl = pThis->mpImpl.get();
410 weld::TreeView& rListBox = *pImpl->xEventLB;
411 int nEntry = rListBox.get_selected_index();
412 if (nEntry == -1)
414 DBG_ASSERT(false, "Where does the empty entry come from?");
415 return;
418 const bool bAssEnabled = pBtn != pImpl->xDeletePB.get() && pImpl->xAssignPB->get_sensitive();
420 OUString sEventName = rListBox.get_id(nEntry);
422 OUString sEventURL;
423 OUString sEventType;
424 if(pThis->bAppEvents)
426 EventsHash::iterator h_it = pThis->m_appEventsHash.find(sEventName);
427 if(h_it != pThis->m_appEventsHash.end() )
429 sEventType = h_it->second.first;
430 sEventURL = h_it->second.second;
433 else
435 EventsHash::iterator h_it = pThis->m_docEventsHash.find(sEventName);
436 if(h_it != pThis->m_docEventsHash.end() )
438 sEventType = h_it->second.first;
439 sEventURL = h_it->second.second;
443 bool bDoubleClick = (pBtn == nullptr);
444 bool bUNOAssigned = sEventURL.startsWith( aVndSunStarUNO );
445 if( pBtn == pImpl->xDeletePB.get() )
447 // delete pressed
448 sEventType = "Script" ;
449 sEventURL.clear();
450 if(!pThis->bAppEvents)
451 pThis->bDocModified = true;
453 else if ( ( ( pBtn != nullptr )
454 && ( pBtn == pImpl->xAssignComponentPB.get() )
456 || ( bDoubleClick
457 && bUNOAssigned
461 AssignComponentDialog aAssignDlg(pThis->GetFrameWeld(), sEventURL);
463 short ret = aAssignDlg.run();
464 if( ret )
466 sEventType = "UNO";
467 sEventURL = aAssignDlg.getURL();
468 if(!pThis->bAppEvents)
469 pThis->bDocModified = true;
472 else if( bAssEnabled )
474 // assign pressed
475 SvxScriptSelectorDialog aDlg(pThis->GetDialogFrameWeld(), false, pThis->GetFrame());
476 short ret = aDlg.run();
477 if ( ret )
479 sEventType = "Script";
480 sEventURL = aDlg.GetScriptURL();
481 if(!pThis->bAppEvents)
482 pThis->bDocModified = true;
486 // update the hashes
487 if(pThis->bAppEvents)
489 EventsHash::iterator h_it = pThis->m_appEventsHash.find(sEventName);
490 h_it->second.first = sEventType;
491 h_it->second.second = sEventURL;
493 else
495 EventsHash::iterator h_it = pThis->m_docEventsHash.find(sEventName);
496 h_it->second.first = sEventType;
497 h_it->second.second = sEventURL;
500 rListBox.set_image(nEntry, GetEventDisplayImage(sEventURL), 1);
501 rListBox.set_text(nEntry, GetEventDisplayText(sEventURL), 2);
503 rListBox.select(nEntry );
504 rListBox.scroll_to_row(nEntry);
506 pThis->EnableButtons();
509 // pass in the XNameReplace.
510 // can remove the 3rd arg once issue ?? is fixed
511 void SvxMacroTabPage_::InitAndSetHandler( const Reference< container::XNameReplace>& xAppEvents, const Reference< container::XNameReplace>& xDocEvents, const Reference< util::XModifiable >& xModifiable )
513 m_xAppEvents = xAppEvents;
514 m_xDocEvents = xDocEvents;
515 m_xModifiable = xModifiable;
516 Link<weld::Button&,void> aLnk(LINK(this, SvxMacroTabPage_, AssignDeleteHdl_Impl ));
517 mpImpl->xDeletePB->connect_clicked(aLnk);
518 mpImpl->xAssignPB->connect_clicked(aLnk);
519 if( mpImpl->xAssignComponentPB )
520 mpImpl->xAssignComponentPB->connect_clicked( aLnk );
521 mpImpl->xEventLB->connect_row_activated( LINK(this, SvxMacroTabPage_, DoubleClickHdl_Impl ) );
522 mpImpl->xEventLB->connect_changed( LINK( this, SvxMacroTabPage_, SelectEvent_Impl ));
524 std::vector<int> aWidths;
525 aWidths.push_back(mpImpl->xEventLB->get_approximate_digit_width() * 32);
526 aWidths.push_back(mpImpl->xEventLB->get_checkbox_column_width());
527 mpImpl->xEventLB->set_column_fixed_widths(aWidths);
529 mpImpl->xEventLB->show();
530 mpImpl->xEventLB->set_sensitive(true);
532 if(!m_xAppEvents.is())
534 return;
536 Sequence< OUString > eventNames = m_xAppEvents->getElementNames();
537 sal_Int32 nEventCount = eventNames.getLength();
538 for(sal_Int32 nEvent = 0; nEvent < nEventCount; ++nEvent )
540 //need exception handling here
543 m_appEventsHash[ eventNames[nEvent] ] = GetPairFromAny( m_xAppEvents->getByName( eventNames[nEvent] ) );
545 catch (const Exception&)
549 if(m_xDocEvents.is())
551 eventNames = m_xDocEvents->getElementNames();
552 nEventCount = eventNames.getLength();
553 for(sal_Int32 nEvent = 0; nEvent < nEventCount; ++nEvent )
557 m_docEventsHash[ eventNames[nEvent] ] = GetPairFromAny( m_xDocEvents->getByName( eventNames[nEvent] ) );
559 catch (const Exception&)
566 // returns the two props EventType & Script for a given event name
567 Any SvxMacroTabPage_::GetPropsByName( const OUString& eventName, EventsHash& eventsHash )
569 const std::pair< OUString, OUString >& rAssignedEvent( eventsHash[ eventName ] );
571 Any aReturn;
572 ::comphelper::NamedValueCollection aProps;
573 if ( !(rAssignedEvent.first.isEmpty() || rAssignedEvent.second.isEmpty()) )
575 aProps.put( "EventType", rAssignedEvent.first );
576 aProps.put( "Script", rAssignedEvent.second );
578 aReturn <<= aProps.getPropertyValues();
580 return aReturn;
583 // converts the Any returned by GetByName into a pair which can be stored in
584 // the EventHash
585 std::pair< OUString, OUString > SvxMacroTabPage_::GetPairFromAny( const Any& aAny )
587 Sequence< beans::PropertyValue > props;
588 OUString type, url;
589 if( aAny >>= props )
591 ::comphelper::NamedValueCollection aProps( props );
592 type = aProps.getOrDefault( "EventType", type );
593 url = aProps.getOrDefault( "Script", url );
595 return std::make_pair( type, url );
598 SvxMacroTabPage::SvxMacroTabPage(TabPageParent pParent,
599 const Reference< frame::XFrame >& _rxDocumentFrame,
600 const SfxItemSet& rSet,
601 Reference< container::XNameReplace > const & xNameReplace,
602 sal_uInt16 nSelectedIndex)
603 : SvxMacroTabPage_(pParent, "cui/ui/macroassignpage.ui", "MacroAssignPage", rSet)
605 mpImpl->xEventLB = m_xBuilder->weld_tree_view("assignments");
606 mpImpl->xEventLB->set_size_request(mpImpl->xEventLB->get_approximate_digit_width() * 70,
607 mpImpl->xEventLB->get_height_rows(9));
608 mpImpl->xAssignPB = m_xBuilder->weld_button("assign");
609 mpImpl->xDeletePB = m_xBuilder->weld_button("delete");
610 mpImpl->xAssignComponentPB = m_xBuilder->weld_button("component");
612 SetFrame( _rxDocumentFrame );
614 if( !mpImpl->bIDEDialogMode )
616 mpImpl->xAssignComponentPB->hide();
617 mpImpl->xAssignComponentPB->set_sensitive(false);
620 InitResources();
622 InitAndSetHandler( xNameReplace, Reference< container::XNameReplace>(nullptr), Reference< util::XModifiable >(nullptr));
623 DisplayAppEvents(true);
624 mpImpl->xEventLB->select(nSelectedIndex);
627 SvxMacroAssignDlg::SvxMacroAssignDlg(weld::Window* pParent, const Reference< frame::XFrame >& _rxDocumentFrame, const SfxItemSet& rSet,
628 const Reference< container::XNameReplace >& xNameReplace, sal_uInt16 nSelectedIndex)
629 : SvxMacroAssignSingleTabDialog(pParent, rSet)
631 TabPageParent pPageParent(get_content_area(), this);
632 auto pPage = VclPtr<SvxMacroTabPage>::Create(pPageParent, _rxDocumentFrame, rSet, xNameReplace, nSelectedIndex);
633 SetTabPage(pPage);
636 IMPL_LINK_NOARG(AssignComponentDialog, ButtonHandler, weld::Button&, void)
638 OUString aMethodName = mxMethodEdit->get_text();
639 maURL.clear();
640 if( !aMethodName.isEmpty() )
642 maURL = aVndSunStarUNO;
643 maURL += aMethodName;
645 m_xDialog->response(RET_OK);
648 AssignComponentDialog::AssignComponentDialog(weld::Window* pParent, const OUString& rURL)
649 : GenericDialogController(pParent, "cui/ui/assigncomponentdialog.ui", "AssignComponent")
650 , maURL( rURL )
651 , mxMethodEdit(m_xBuilder->weld_entry("methodEntry"))
652 , mxOKButton(m_xBuilder->weld_button("ok"))
654 mxOKButton->connect_clicked(LINK(this, AssignComponentDialog, ButtonHandler));
656 OUString aMethodName;
657 if( maURL.startsWith( aVndSunStarUNO ) )
659 aMethodName = maURL.copy( strlen(aVndSunStarUNO) );
661 mxMethodEdit->set_text(aMethodName);
662 mxMethodEdit->select_region(0, -1);
665 AssignComponentDialog::~AssignComponentDialog()
669 IMPL_LINK_NOARG(SvxMacroAssignSingleTabDialog, OKHdl_Impl, weld::Button&, void)
671 m_xSfxPage->FillItemSet(nullptr);
672 m_xDialog->response(RET_OK);
675 SvxMacroAssignSingleTabDialog::SvxMacroAssignSingleTabDialog(weld::Window *pParent,
676 const SfxItemSet& rSet)
677 : SfxSingleTabDialogController(pParent, &rSet, "cui/ui/macroassigndialog.ui", "MacroAssignDialog")
679 GetOKButton().connect_clicked(LINK(this, SvxMacroAssignSingleTabDialog, OKHdl_Impl));
682 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */