android: Update app-specific/MIME type icons
[LibreOffice.git] / cui / source / customize / macropg.cxx
blob6a22ee2c3d996e4f8696bf913414bfa2d1134724
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 <macropg.hxx>
21 #include <svl/eitem.hxx>
22 #include <tools/debug.hxx>
23 #include <comphelper/diagnose_ex.hxx>
24 #include <bitmaps.hlst>
25 #include <cfgutil.hxx>
26 #include <dialmgr.hxx>
27 #include <helpids.h>
28 #include <headertablistbox.hxx>
29 #include "macropg_impl.hxx"
30 #include <o3tl/safeint.hxx>
31 #include <svl/macitem.hxx>
32 #include <svx/svxids.hrc>
33 #include <strings.hrc>
34 #include <comphelper/namedvaluecollection.hxx>
35 #include <o3tl/string_view.hxx>
36 #include <utility>
38 using namespace ::com::sun::star;
39 using namespace ::com::sun::star::uno;
41 constexpr OUStringLiteral aVndSunStarUNO = u"vnd.sun.star.UNO:";
43 SvxMacroTabPage_Impl::SvxMacroTabPage_Impl( const SfxItemSet& rAttrSet )
44 : bReadOnly(false)
45 , bIDEDialogMode(false)
47 const SfxPoolItem* pItem;
48 if ( SfxItemState::SET == rAttrSet.GetItemState( SID_ATTR_MACROITEM, false, &pItem ) )
49 bIDEDialogMode = static_cast<const SfxBoolItem*>(pItem)->GetValue();
52 MacroEventListBox::MacroEventListBox(std::unique_ptr<weld::TreeView> xTreeView)
53 : m_xTreeView(std::move(xTreeView))
55 m_xTreeView->set_help_id(HID_MACRO_HEADERTABLISTBOX);
56 m_xTreeView->set_size_request(m_xTreeView->get_approximate_digit_width() * 70, m_xTreeView->get_height_rows(9));
59 // assign button ("Add Command") is enabled only if it is not read only
60 // delete button ("Remove Command") is enabled if a current binding exists
61 // and it is not read only
62 void SvxMacroTabPage_::EnableButtons()
64 mpImpl->xDeleteAllPB->set_sensitive(m_nAssignedEvents != 0);
65 int nEvent = mpImpl->xEventLB->get_selected_index();
66 const EventPair* pEventPair = nEvent == -1 ? nullptr : LookupEvent(mpImpl->xEventLB->get_id(nEvent));
67 const bool bAssigned = pEventPair && !pEventPair->second.isEmpty();
68 mpImpl->xDeletePB->set_sensitive(!mpImpl->bReadOnly && bAssigned);
69 mpImpl->xAssignPB->set_sensitive(!mpImpl->bReadOnly);
70 if (mpImpl->xAssignComponentPB)
71 mpImpl->xAssignComponentPB->set_sensitive( !mpImpl->bReadOnly );
74 SvxMacroTabPage_::SvxMacroTabPage_(weld::Container* pPage, weld::DialogController* pController, const OUString& rUIXMLDescription,
75 const OUString& rID, const SfxItemSet& rAttrSet)
76 : SfxTabPage(pPage, pController, rUIXMLDescription, rID, &rAttrSet)
77 , m_nAssignedEvents(0)
78 , bDocModified(false)
79 , bAppEvents(false)
80 , bInitialized(false)
82 mpImpl.reset( new SvxMacroTabPage_Impl( rAttrSet ) );
85 SvxMacroTabPage_::~SvxMacroTabPage_()
87 mpImpl.reset();
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_CUISTR_EVENT_STARTAPP );
96 aDisplayNames.emplace_back( "OnCloseApp", RID_CUISTR_EVENT_CLOSEAPP );
97 aDisplayNames.emplace_back( "OnCreate", RID_CUISTR_EVENT_CREATEDOC );
98 aDisplayNames.emplace_back( "OnNew", RID_CUISTR_EVENT_NEWDOC );
99 aDisplayNames.emplace_back( "OnLoadFinished", RID_CUISTR_EVENT_LOADDOCFINISHED );
100 aDisplayNames.emplace_back( "OnLoad", RID_CUISTR_EVENT_OPENDOC );
101 aDisplayNames.emplace_back( "OnPrepareUnload", RID_CUISTR_EVENT_PREPARECLOSEDOC );
102 aDisplayNames.emplace_back( "OnUnload", RID_CUISTR_EVENT_CLOSEDOC ) ;
103 aDisplayNames.emplace_back( "OnViewCreated", RID_CUISTR_EVENT_VIEWCREATED );
104 aDisplayNames.emplace_back( "OnPrepareViewClosing", RID_CUISTR_EVENT_PREPARECLOSEVIEW );
105 aDisplayNames.emplace_back( "OnViewClosed", RID_CUISTR_EVENT_CLOSEVIEW ) ;
106 aDisplayNames.emplace_back( "OnFocus", RID_CUISTR_EVENT_ACTIVATEDOC );
107 aDisplayNames.emplace_back( "OnUnfocus", RID_CUISTR_EVENT_DEACTIVATEDOC );
108 aDisplayNames.emplace_back( "OnSave", RID_CUISTR_EVENT_SAVEDOC );
109 aDisplayNames.emplace_back( "OnSaveDone", RID_CUISTR_EVENT_SAVEDOCDONE );
110 aDisplayNames.emplace_back( "OnSaveFailed", RID_CUISTR_EVENT_SAVEDOCFAILED );
111 aDisplayNames.emplace_back( "OnSaveAs", RID_CUISTR_EVENT_SAVEASDOC );
112 aDisplayNames.emplace_back( "OnSaveAsDone", RID_CUISTR_EVENT_SAVEASDOCDONE );
113 aDisplayNames.emplace_back( "OnSaveAsFailed", RID_CUISTR_EVENT_SAVEASDOCFAILED );
114 aDisplayNames.emplace_back( "OnCopyTo", RID_CUISTR_EVENT_COPYTODOC );
115 aDisplayNames.emplace_back( "OnCopyToDone", RID_CUISTR_EVENT_COPYTODOCDONE );
116 aDisplayNames.emplace_back( "OnCopyToFailed", RID_CUISTR_EVENT_COPYTODOCFAILED );
117 aDisplayNames.emplace_back( "OnPrint", RID_CUISTR_EVENT_PRINTDOC );
118 aDisplayNames.emplace_back( "OnModifyChanged", RID_CUISTR_EVENT_MODIFYCHANGED );
119 aDisplayNames.emplace_back( "OnTitleChanged", RID_CUISTR_EVENT_TITLECHANGED );
121 // application specific events
122 aDisplayNames.emplace_back( "OnMailMerge", RID_CUISTR_EVENT_MAILMERGE );
123 aDisplayNames.emplace_back( "OnMailMergeFinished", RID_CUISTR_EVENT_MAILMERGE_END );
124 aDisplayNames.emplace_back( "OnFieldMerge", RID_CUISTR_EVENT_FIELDMERGE );
125 aDisplayNames.emplace_back( "OnFieldMergeFinished", RID_CUISTR_EVENT_FIELDMERGE_FINISHED );
126 aDisplayNames.emplace_back( "OnPageCountChange", RID_CUISTR_EVENT_PAGECOUNTCHANGE );
127 aDisplayNames.emplace_back( "OnSubComponentOpened", RID_CUISTR_EVENT_SUBCOMPONENT_OPENED );
128 aDisplayNames.emplace_back( "OnSubComponentClosed", RID_CUISTR_EVENT_SUBCOMPONENT_CLOSED );
129 aDisplayNames.emplace_back( "OnSelect", RID_CUISTR_EVENT_SELECTIONCHANGED );
130 aDisplayNames.emplace_back( "OnDoubleClick", RID_CUISTR_EVENT_DOUBLECLICK );
131 aDisplayNames.emplace_back( "OnRightClick", RID_CUISTR_EVENT_RIGHTCLICK );
132 aDisplayNames.emplace_back( "OnCalculate", RID_CUISTR_EVENT_CALCULATE );
133 aDisplayNames.emplace_back( "OnChange", RID_CUISTR_EVENT_CONTENTCHANGED );
135 // the event name to UI string mappings for forms & dialogs
137 aDisplayNames.emplace_back( "approveAction", RID_CUISTR_EVENT_APPROVEACTIONPERFORMED );
138 aDisplayNames.emplace_back( "actionPerformed", RID_CUISTR_EVENT_ACTIONPERFORMED );
139 aDisplayNames.emplace_back( "changed", RID_CUISTR_EVENT_CHANGED );
140 aDisplayNames.emplace_back( "textChanged", RID_CUISTR_EVENT_TEXTCHANGED );
141 aDisplayNames.emplace_back( "itemStateChanged", RID_CUISTR_EVENT_ITEMSTATECHANGED );
142 aDisplayNames.emplace_back( "focusGained", RID_CUISTR_EVENT_FOCUSGAINED );
143 aDisplayNames.emplace_back( "focusLost", RID_CUISTR_EVENT_FOCUSLOST );
144 aDisplayNames.emplace_back( "keyPressed", RID_CUISTR_EVENT_KEYTYPED );
145 aDisplayNames.emplace_back( "keyReleased", RID_CUISTR_EVENT_KEYUP );
146 aDisplayNames.emplace_back( "mouseEntered", RID_CUISTR_EVENT_MOUSEENTERED );
147 aDisplayNames.emplace_back( "mouseDragged", RID_CUISTR_EVENT_MOUSEDRAGGED );
148 aDisplayNames.emplace_back( "mouseMoved", RID_CUISTR_EVENT_MOUSEMOVED );
149 aDisplayNames.emplace_back( "mousePressed", RID_CUISTR_EVENT_MOUSEPRESSED );
150 aDisplayNames.emplace_back( "mouseReleased", RID_CUISTR_EVENT_MOUSERELEASED );
151 aDisplayNames.emplace_back( "mouseExited", RID_CUISTR_EVENT_MOUSEEXITED );
152 aDisplayNames.emplace_back( "approveReset", RID_CUISTR_EVENT_APPROVERESETTED );
153 aDisplayNames.emplace_back( "resetted", RID_CUISTR_EVENT_RESETTED );
154 aDisplayNames.emplace_back( "approveSubmit", RID_CUISTR_EVENT_SUBMITTED );
155 aDisplayNames.emplace_back( "approveUpdate", RID_CUISTR_EVENT_BEFOREUPDATE );
156 aDisplayNames.emplace_back( "updated", RID_CUISTR_EVENT_AFTERUPDATE );
157 aDisplayNames.emplace_back( "loaded", RID_CUISTR_EVENT_LOADED );
158 aDisplayNames.emplace_back( "reloading", RID_CUISTR_EVENT_RELOADING );
159 aDisplayNames.emplace_back( "reloaded", RID_CUISTR_EVENT_RELOADED );
160 aDisplayNames.emplace_back( "unloading", RID_CUISTR_EVENT_UNLOADING );
161 aDisplayNames.emplace_back( "unloaded", RID_CUISTR_EVENT_UNLOADED );
162 aDisplayNames.emplace_back( "confirmDelete", RID_CUISTR_EVENT_CONFIRMDELETE );
163 aDisplayNames.emplace_back( "approveRowChange", RID_CUISTR_EVENT_APPROVEROWCHANGE );
164 aDisplayNames.emplace_back( "rowChanged", RID_CUISTR_EVENT_ROWCHANGE );
165 aDisplayNames.emplace_back( "approveCursorMove", RID_CUISTR_EVENT_POSITIONING );
166 aDisplayNames.emplace_back( "cursorMoved", RID_CUISTR_EVENT_POSITIONED );
167 aDisplayNames.emplace_back( "approveParameter", RID_CUISTR_EVENT_APPROVEPARAMETER );
168 aDisplayNames.emplace_back( "errorOccured", RID_CUISTR_EVENT_ERROROCCURRED );
169 aDisplayNames.emplace_back( "adjustmentValueChanged", RID_CUISTR_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*/ )
178 OUString eventName;
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??
221 return false;
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
228 if(!bInitialized)
230 bInitialized = true;
231 return;
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;
273 namespace
275 std::u16string_view GetEventDisplayText(std::u16string_view rURL)
277 if (rURL.empty())
278 return std::u16string_view();
279 bool bUNO = o3tl::starts_with(rURL, aVndSunStarUNO);
280 std::u16string_view aPureMethod;
281 if (bUNO)
283 aPureMethod = rURL.substr(aVndSunStarUNO.getLength());
285 else
287 aPureMethod = rURL.substr(strlen("vnd.sun.star.script:"));
288 aPureMethod = aPureMethod.substr( 0, aPureMethod.find( '?' ) );
290 return aPureMethod;
293 OUString GetEventDisplayImage(std::u16string_view rURL)
295 if (rURL.empty())
296 return OUString();
297 size_t nIndex = rURL.find(aVndSunStarUNO);
298 bool bUNO = nIndex == 0;
299 return bUNO ? OUString(RID_SVXBMP_COMPONENT) : OUString(RID_SVXBMP_MACRO);
303 // displays the app events if appEvents=true, otherwise displays the doc events
304 void SvxMacroTabPage_::DisplayAppEvents( bool appEvents)
306 bAppEvents = appEvents;
308 mpImpl->xEventLB->freeze();
309 mpImpl->xEventLB->clear();
310 m_nAssignedEvents = 0;
311 EventsHash* eventsHash;
312 Reference< container::XNameReplace> nameReplace;
313 if(bAppEvents)
315 eventsHash = &m_appEventsHash;
316 nameReplace = m_xAppEvents;
318 else
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())
327 mpImpl->xEventLB->thaw();
328 return;
331 for (auto const& displayableEvent : aDisplayNames)
333 OUString sEventName( OUString::createFromAscii( displayableEvent.pAsciiEventName ) );
334 if ( !nameReplace->hasByName( sEventName ) )
335 continue;
337 EventsHash::iterator h_it = eventsHash->find( sEventName );
338 if( h_it == eventsHash->end() )
340 OSL_FAIL( "SvxMacroTabPage_::DisplayAppEvents: something's suspicious here!" );
341 continue;
344 OUString eventURL = h_it->second.second;
345 OUString displayName(CuiResId(displayableEvent.pEventResourceID));
347 int nRow = mpImpl->xEventLB->n_children();
348 mpImpl->xEventLB->append(sEventName, displayName);
349 mpImpl->xEventLB->set_image(nRow, GetEventDisplayImage(eventURL), 1);
350 mpImpl->xEventLB->set_text(nRow, OUString(GetEventDisplayText(eventURL)), 2);
352 if (!eventURL.isEmpty())
353 ++m_nAssignedEvents;
356 mpImpl->xEventLB->thaw();
358 if (mpImpl->xEventLB->n_children())
360 mpImpl->xEventLB->select(0);
361 mpImpl->xEventLB->scroll_to_row(0);
364 EnableButtons();
367 // select event handler on the listbox
368 IMPL_LINK_NOARG( SvxMacroTabPage_, SelectEvent_Impl, weld::TreeView&, void)
370 int nEntry = mpImpl->xEventLB->get_selected_index();
372 if (nEntry == -1)
374 DBG_ASSERT(false, "Where does the empty entry come from?" );
375 return;
378 EnableButtons();
381 IMPL_LINK( SvxMacroTabPage_, AssignDeleteHdl_Impl, weld::Button&, rBtn, void )
383 GenericHandler_Impl(&rBtn);
386 IMPL_LINK_NOARG( SvxMacroTabPage_, DoubleClickHdl_Impl, weld::TreeView&, bool)
388 GenericHandler_Impl(nullptr);
389 return true;
392 const EventPair* SvxMacroTabPage_::LookupEvent(const OUString& rEventName)
394 const EventPair* pRet = nullptr;
395 if (bAppEvents)
397 EventsHash::iterator h_it = m_appEventsHash.find(rEventName);
398 if (h_it != m_appEventsHash.end() )
399 pRet = &h_it->second;
401 else
403 EventsHash::iterator h_it = m_docEventsHash.find(rEventName);
404 if (h_it != m_docEventsHash.end() )
405 pRet = &h_it->second;
407 return pRet;
410 // handler for double click on the listbox, and for the assign/delete buttons
411 void SvxMacroTabPage_::GenericHandler_Impl(const weld::Button* pBtn)
413 weld::TreeView& rListBox = *mpImpl->xEventLB;
414 int nEntry = rListBox.get_selected_index();
415 if (nEntry == -1)
417 DBG_ASSERT(false, "Where does the empty entry come from?");
418 return;
421 const bool bAssEnabled = pBtn != mpImpl->xDeletePB.get() && mpImpl->xAssignPB->get_sensitive();
423 OUString sEventName = rListBox.get_id(nEntry);
425 OUString sEventURL;
426 OUString sEventType;
427 if (const EventPair* pEventPair = LookupEvent(sEventName))
429 sEventType = pEventPair->first;
430 sEventURL = pEventPair->second;
433 if (!sEventURL.isEmpty())
434 --m_nAssignedEvents;
436 bool bDoubleClick = (pBtn == nullptr);
437 bool bUNOAssigned = sEventURL.startsWith( aVndSunStarUNO );
438 if (pBtn == mpImpl->xDeletePB.get())
440 // delete pressed
441 sEventType = "Script" ;
442 sEventURL.clear();
443 if (!bAppEvents)
444 bDocModified = true;
446 else if ( ( ( pBtn != nullptr )
447 && ( pBtn == mpImpl->xAssignComponentPB.get() )
449 || ( bDoubleClick
450 && bUNOAssigned
454 AssignComponentDialog aAssignDlg(GetFrameWeld(), sEventURL);
456 short ret = aAssignDlg.run();
457 if( ret )
459 sEventType = "UNO";
460 sEventURL = aAssignDlg.getURL();
461 if (!bAppEvents)
462 bDocModified = true;
465 else if( bAssEnabled )
467 // assign pressed
468 SvxScriptSelectorDialog aDlg(GetFrameWeld(), GetFrame());
469 short ret = aDlg.run();
470 if ( ret )
472 sEventType = "Script";
473 sEventURL = aDlg.GetScriptURL();
474 if (!bAppEvents)
475 bDocModified = true;
479 // update the hashes
480 if (bAppEvents)
482 EventsHash::iterator h_it = m_appEventsHash.find(sEventName);
483 h_it->second.first = sEventType;
484 h_it->second.second = sEventURL;
486 else
488 EventsHash::iterator h_it = m_docEventsHash.find(sEventName);
489 h_it->second.first = sEventType;
490 h_it->second.second = sEventURL;
493 if (!sEventURL.isEmpty())
494 ++m_nAssignedEvents;
496 rListBox.set_image(nEntry, GetEventDisplayImage(sEventURL), 1);
497 rListBox.set_text(nEntry, OUString(GetEventDisplayText(sEventURL)), 2);
499 rListBox.select(nEntry );
500 rListBox.scroll_to_row(nEntry);
502 EnableButtons();
505 IMPL_LINK_NOARG(SvxMacroTabPage_, DeleteAllHdl_Impl, weld::Button&, void)
507 OUString sEventType = "Script" ;
508 OUString sEmptyString;
510 mpImpl->xEventLB->all_foreach([this, &sEventType, &sEmptyString](weld::TreeIter& rEntry) {
511 weld::TreeView& rListBox = *mpImpl->xEventLB;
512 OUString sEventName = rListBox.get_id(rEntry);
513 // update the hashes
514 if (bAppEvents)
516 EventsHash::iterator h_it = m_appEventsHash.find(sEventName);
517 h_it->second.first = sEventType;
518 h_it->second.second = sEmptyString;
520 else
522 EventsHash::iterator h_it = m_docEventsHash.find(sEventName);
523 h_it->second.first = sEventType;
524 h_it->second.second = sEmptyString;
527 rListBox.set_image(rEntry, sEmptyString, 1);
528 rListBox.set_text(rEntry, sEmptyString, 2);
529 return false;
532 if (!bAppEvents)
533 bDocModified = true;
535 m_nAssignedEvents = 0;
537 EnableButtons();
540 // pass in the XNameReplace.
541 // can remove the 3rd arg once issue ?? is fixed
542 void SvxMacroTabPage_::InitAndSetHandler( const Reference< container::XNameReplace>& xAppEvents, const Reference< container::XNameReplace>& xDocEvents, const Reference< util::XModifiable >& xModifiable )
544 m_xAppEvents = xAppEvents;
545 m_xDocEvents = xDocEvents;
546 m_xModifiable = xModifiable;
547 Link<weld::Button&,void> aLnk(LINK(this, SvxMacroTabPage_, AssignDeleteHdl_Impl ));
548 mpImpl->xDeletePB->connect_clicked(aLnk);
549 mpImpl->xAssignPB->connect_clicked(aLnk);
550 mpImpl->xDeleteAllPB->connect_clicked(LINK(this, SvxMacroTabPage_, DeleteAllHdl_Impl));
551 if( mpImpl->xAssignComponentPB )
552 mpImpl->xAssignComponentPB->connect_clicked( aLnk );
553 mpImpl->xEventLB->connect_row_activated( LINK(this, SvxMacroTabPage_, DoubleClickHdl_Impl ) );
554 mpImpl->xEventLB->connect_changed( LINK( this, SvxMacroTabPage_, SelectEvent_Impl ));
556 std::vector<int> aWidths
558 o3tl::narrowing<int>(mpImpl->xEventLB->get_approximate_digit_width() * 32),
559 mpImpl->xEventLB->get_checkbox_column_width()
561 mpImpl->xEventLB->set_column_fixed_widths(aWidths);
563 mpImpl->xEventLB->show();
564 mpImpl->xEventLB->set_sensitive(true);
566 if(!m_xAppEvents.is())
568 return;
570 Sequence< OUString > eventNames = m_xAppEvents->getElementNames();
571 sal_Int32 nEventCount = eventNames.getLength();
572 for(sal_Int32 nEvent = 0; nEvent < nEventCount; ++nEvent )
574 //need exception handling here
577 m_appEventsHash[ eventNames[nEvent] ] = GetPairFromAny( m_xAppEvents->getByName( eventNames[nEvent] ) );
579 catch (const Exception&)
583 if(!m_xDocEvents.is())
584 return;
586 eventNames = m_xDocEvents->getElementNames();
587 nEventCount = eventNames.getLength();
588 for(sal_Int32 nEvent = 0; nEvent < nEventCount; ++nEvent )
592 m_docEventsHash[ eventNames[nEvent] ] = GetPairFromAny( m_xDocEvents->getByName( eventNames[nEvent] ) );
594 catch (const Exception&)
600 // returns the two props EventType & Script for a given event name
601 Any SvxMacroTabPage_::GetPropsByName( const OUString& eventName, EventsHash& eventsHash )
603 const EventPair& rAssignedEvent(eventsHash[eventName]);
605 Any aReturn;
606 ::comphelper::NamedValueCollection aProps;
607 if ( !(rAssignedEvent.first.isEmpty() || rAssignedEvent.second.isEmpty()) )
609 aProps.put( "EventType", rAssignedEvent.first );
610 aProps.put( "Script", rAssignedEvent.second );
612 aReturn <<= aProps.getPropertyValues();
614 return aReturn;
617 // converts the Any returned by GetByName into a pair which can be stored in
618 // the EventHash
619 EventPair SvxMacroTabPage_::GetPairFromAny( const Any& aAny )
621 Sequence< beans::PropertyValue > props;
622 OUString type, url;
623 if( aAny >>= props )
625 ::comphelper::NamedValueCollection aProps( props );
626 type = aProps.getOrDefault( "EventType", type );
627 url = aProps.getOrDefault( "Script", url );
629 return std::make_pair( type, url );
632 SvxMacroTabPage::SvxMacroTabPage(weld::Container* pPage, weld::DialogController* pController,
633 const Reference< frame::XFrame >& _rxDocumentFrame,
634 const SfxItemSet& rSet,
635 Reference< container::XNameReplace > const & xNameReplace,
636 sal_uInt16 nSelectedIndex)
637 : SvxMacroTabPage_(pPage, pController, "cui/ui/macroassignpage.ui", "MacroAssignPage", rSet)
639 mpImpl->xEventLB = m_xBuilder->weld_tree_view("assignments");
640 mpImpl->xEventLB->set_size_request(mpImpl->xEventLB->get_approximate_digit_width() * 70,
641 mpImpl->xEventLB->get_height_rows(9));
642 mpImpl->xAssignPB = m_xBuilder->weld_button("assign");
643 mpImpl->xDeletePB = m_xBuilder->weld_button("delete");
644 mpImpl->xDeleteAllPB = m_xBuilder->weld_button("deleteall");
645 mpImpl->xAssignComponentPB = m_xBuilder->weld_button("component");
647 SetFrame( _rxDocumentFrame );
649 if( !mpImpl->bIDEDialogMode )
651 mpImpl->xAssignComponentPB->hide();
652 mpImpl->xAssignComponentPB->set_sensitive(false);
655 InitResources();
657 InitAndSetHandler( xNameReplace, Reference< container::XNameReplace>(nullptr), Reference< util::XModifiable >(nullptr));
658 DisplayAppEvents(true);
659 mpImpl->xEventLB->select(nSelectedIndex);
662 SvxMacroAssignDlg::SvxMacroAssignDlg(weld::Window* pParent, const Reference< frame::XFrame >& _rxDocumentFrame, const SfxItemSet& rSet,
663 const Reference< container::XNameReplace >& xNameReplace, sal_uInt16 nSelectedIndex)
664 : SvxMacroAssignSingleTabDialog(pParent, rSet)
666 SetTabPage(std::make_unique<SvxMacroTabPage>(get_content_area(), this, _rxDocumentFrame, rSet, xNameReplace, nSelectedIndex));
669 IMPL_LINK_NOARG(AssignComponentDialog, ButtonHandler, weld::Button&, void)
671 OUString aMethodName = mxMethodEdit->get_text();
672 maURL.clear();
673 if( !aMethodName.isEmpty() )
675 maURL = aVndSunStarUNO;
676 maURL += aMethodName;
678 m_xDialog->response(RET_OK);
681 AssignComponentDialog::AssignComponentDialog(weld::Window* pParent, OUString aURL)
682 : GenericDialogController(pParent, "cui/ui/assigncomponentdialog.ui", "AssignComponent")
683 , maURL(std::move( aURL ))
684 , mxMethodEdit(m_xBuilder->weld_entry("methodEntry"))
685 , mxOKButton(m_xBuilder->weld_button("ok"))
687 mxOKButton->connect_clicked(LINK(this, AssignComponentDialog, ButtonHandler));
689 OUString aMethodName;
690 if( maURL.startsWith( aVndSunStarUNO ) )
692 aMethodName = maURL.copy( aVndSunStarUNO.getLength() );
694 mxMethodEdit->set_text(aMethodName);
695 mxMethodEdit->select_region(0, -1);
698 AssignComponentDialog::~AssignComponentDialog()
702 IMPL_LINK_NOARG(SvxMacroAssignSingleTabDialog, OKHdl_Impl, weld::Button&, void)
704 m_xSfxPage->FillItemSet(nullptr);
705 m_xDialog->response(RET_OK);
708 SvxMacroAssignSingleTabDialog::SvxMacroAssignSingleTabDialog(weld::Window *pParent,
709 const SfxItemSet& rSet)
710 : SfxSingleTabDialogController(pParent, &rSet, "cui/ui/macroassigndialog.ui", "MacroAssignDialog")
712 GetOKButton().connect_clicked(LINK(this, SvxMacroAssignSingleTabDialog, OKHdl_Impl));
715 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */