LibreOffice Module cui (master)  1
macropg.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
19 
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>
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>
35 
36 using namespace ::com::sun::star;
37 using namespace ::com::sun::star::uno;
38 
39 constexpr OUStringLiteral aVndSunStarUNO = u"vnd.sun.star.UNO:";
40 
42  : bReadOnly(false)
43  , bIDEDialogMode(false)
44 {
45  const SfxPoolItem* pItem;
46  if ( SfxItemState::SET == rAttrSet.GetItemState( SID_ATTR_MACROITEM, false, &pItem ) )
47  bIDEDialogMode = static_cast<const SfxBoolItem*>(pItem)->GetValue();
48 }
49 
50 MacroEventListBox::MacroEventListBox(std::unique_ptr<weld::TreeView> xTreeView)
51  : m_xTreeView(std::move(xTreeView))
52 {
54  m_xTreeView->set_size_request(m_xTreeView->get_approximate_digit_width() * 70, m_xTreeView->get_height_rows(9));
55 }
56 
57 // assign button ("Add Command") is enabled only if it is not read only
58 // delete button ("Remove Command") is enabled if a current binding exists
59 // and it is not read only
61 {
62  int nEvent = mpImpl->xEventLB->get_selected_index();
63  if (nEvent != -1)
64  {
65  mpImpl->xDeletePB->set_sensitive( !mpImpl->bReadOnly );
66  mpImpl->xAssignPB->set_sensitive( !mpImpl->bReadOnly );
67  if( mpImpl->xAssignComponentPB )
68  mpImpl->xAssignComponentPB->set_sensitive( !mpImpl->bReadOnly );
69  }
70 }
71 
72 SvxMacroTabPage_::SvxMacroTabPage_(weld::Container* pPage, weld::DialogController* pController, const OUString& rUIXMLDescription,
73  const OString& rID, const SfxItemSet& rAttrSet)
74  : SfxTabPage(pPage, pController, rUIXMLDescription, rID, &rAttrSet)
75  , bDocModified(false)
76  , bAppEvents(false)
77  , bInitialized(false)
78 {
79  mpImpl.reset( new SvxMacroTabPage_Impl( rAttrSet ) );
80 }
81 
83 {
84  mpImpl.reset();
85 }
86 
88 {
89  // Note: the order here controls the order in which the events are displayed in the UI!
90 
91  // the event name to UI string mappings for App Events
92  aDisplayNames.emplace_back( "OnStartApp", RID_CUISTR_EVENT_STARTAPP );
93  aDisplayNames.emplace_back( "OnCloseApp", RID_CUISTR_EVENT_CLOSEAPP );
94  aDisplayNames.emplace_back( "OnCreate", RID_CUISTR_EVENT_CREATEDOC );
95  aDisplayNames.emplace_back( "OnNew", RID_CUISTR_EVENT_NEWDOC );
96  aDisplayNames.emplace_back( "OnLoadFinished", RID_CUISTR_EVENT_LOADDOCFINISHED );
97  aDisplayNames.emplace_back( "OnLoad", RID_CUISTR_EVENT_OPENDOC );
98  aDisplayNames.emplace_back( "OnPrepareUnload", RID_CUISTR_EVENT_PREPARECLOSEDOC );
99  aDisplayNames.emplace_back( "OnUnload", RID_CUISTR_EVENT_CLOSEDOC ) ;
100  aDisplayNames.emplace_back( "OnViewCreated", RID_CUISTR_EVENT_VIEWCREATED );
101  aDisplayNames.emplace_back( "OnPrepareViewClosing", RID_CUISTR_EVENT_PREPARECLOSEVIEW );
102  aDisplayNames.emplace_back( "OnViewClosed", RID_CUISTR_EVENT_CLOSEVIEW ) ;
103  aDisplayNames.emplace_back( "OnFocus", RID_CUISTR_EVENT_ACTIVATEDOC );
104  aDisplayNames.emplace_back( "OnUnfocus", RID_CUISTR_EVENT_DEACTIVATEDOC );
105  aDisplayNames.emplace_back( "OnSave", RID_CUISTR_EVENT_SAVEDOC );
106  aDisplayNames.emplace_back( "OnSaveDone", RID_CUISTR_EVENT_SAVEDOCDONE );
107  aDisplayNames.emplace_back( "OnSaveFailed", RID_CUISTR_EVENT_SAVEDOCFAILED );
108  aDisplayNames.emplace_back( "OnSaveAs", RID_CUISTR_EVENT_SAVEASDOC );
109  aDisplayNames.emplace_back( "OnSaveAsDone", RID_CUISTR_EVENT_SAVEASDOCDONE );
110  aDisplayNames.emplace_back( "OnSaveAsFailed", RID_CUISTR_EVENT_SAVEASDOCFAILED );
111  aDisplayNames.emplace_back( "OnCopyTo", RID_CUISTR_EVENT_COPYTODOC );
112  aDisplayNames.emplace_back( "OnCopyToDone", RID_CUISTR_EVENT_COPYTODOCDONE );
113  aDisplayNames.emplace_back( "OnCopyToFailed", RID_CUISTR_EVENT_COPYTODOCFAILED );
114  aDisplayNames.emplace_back( "OnPrint", RID_CUISTR_EVENT_PRINTDOC );
115  aDisplayNames.emplace_back( "OnModifyChanged", RID_CUISTR_EVENT_MODIFYCHANGED );
116  aDisplayNames.emplace_back( "OnTitleChanged", RID_CUISTR_EVENT_TITLECHANGED );
117 
118  // application specific events
119  aDisplayNames.emplace_back( "OnMailMerge", RID_CUISTR_EVENT_MAILMERGE );
120  aDisplayNames.emplace_back( "OnMailMergeFinished", RID_CUISTR_EVENT_MAILMERGE_END );
121  aDisplayNames.emplace_back( "OnFieldMerge", RID_CUISTR_EVENT_FIELDMERGE );
122  aDisplayNames.emplace_back( "OnFieldMergeFinished", RID_CUISTR_EVENT_FIELDMERGE_FINISHED );
123  aDisplayNames.emplace_back( "OnPageCountChange", RID_CUISTR_EVENT_PAGECOUNTCHANGE );
124  aDisplayNames.emplace_back( "OnSubComponentOpened", RID_CUISTR_EVENT_SUBCOMPONENT_OPENED );
125  aDisplayNames.emplace_back( "OnSubComponentClosed", RID_CUISTR_EVENT_SUBCOMPONENT_CLOSED );
126  aDisplayNames.emplace_back( "OnSelect", RID_CUISTR_EVENT_SELECTIONCHANGED );
127  aDisplayNames.emplace_back( "OnDoubleClick", RID_CUISTR_EVENT_DOUBLECLICK );
128  aDisplayNames.emplace_back( "OnRightClick", RID_CUISTR_EVENT_RIGHTCLICK );
129  aDisplayNames.emplace_back( "OnCalculate", RID_CUISTR_EVENT_CALCULATE );
130  aDisplayNames.emplace_back( "OnChange", RID_CUISTR_EVENT_CONTENTCHANGED );
131 
132  // the event name to UI string mappings for forms & dialogs
133 
134  aDisplayNames.emplace_back( "approveAction", RID_CUISTR_EVENT_APPROVEACTIONPERFORMED );
135  aDisplayNames.emplace_back( "actionPerformed", RID_CUISTR_EVENT_ACTIONPERFORMED );
136  aDisplayNames.emplace_back( "changed", RID_CUISTR_EVENT_CHANGED );
137  aDisplayNames.emplace_back( "textChanged", RID_CUISTR_EVENT_TEXTCHANGED );
138  aDisplayNames.emplace_back( "itemStateChanged", RID_CUISTR_EVENT_ITEMSTATECHANGED );
139  aDisplayNames.emplace_back( "focusGained", RID_CUISTR_EVENT_FOCUSGAINED );
140  aDisplayNames.emplace_back( "focusLost", RID_CUISTR_EVENT_FOCUSLOST );
141  aDisplayNames.emplace_back( "keyPressed", RID_CUISTR_EVENT_KEYTYPED );
142  aDisplayNames.emplace_back( "keyReleased", RID_CUISTR_EVENT_KEYUP );
143  aDisplayNames.emplace_back( "mouseEntered", RID_CUISTR_EVENT_MOUSEENTERED );
144  aDisplayNames.emplace_back( "mouseDragged", RID_CUISTR_EVENT_MOUSEDRAGGED );
145  aDisplayNames.emplace_back( "mouseMoved", RID_CUISTR_EVENT_MOUSEMOVED );
146  aDisplayNames.emplace_back( "mousePressed", RID_CUISTR_EVENT_MOUSEPRESSED );
147  aDisplayNames.emplace_back( "mouseReleased", RID_CUISTR_EVENT_MOUSERELEASED );
148  aDisplayNames.emplace_back( "mouseExited", RID_CUISTR_EVENT_MOUSEEXITED );
149  aDisplayNames.emplace_back( "approveReset", RID_CUISTR_EVENT_APPROVERESETTED );
150  aDisplayNames.emplace_back( "resetted", RID_CUISTR_EVENT_RESETTED );
151  aDisplayNames.emplace_back( "approveSubmit", RID_CUISTR_EVENT_SUBMITTED );
152  aDisplayNames.emplace_back( "approveUpdate", RID_CUISTR_EVENT_BEFOREUPDATE );
153  aDisplayNames.emplace_back( "updated", RID_CUISTR_EVENT_AFTERUPDATE );
154  aDisplayNames.emplace_back( "loaded", RID_CUISTR_EVENT_LOADED );
155  aDisplayNames.emplace_back( "reloading", RID_CUISTR_EVENT_RELOADING );
156  aDisplayNames.emplace_back( "reloaded", RID_CUISTR_EVENT_RELOADED );
157  aDisplayNames.emplace_back( "unloading", RID_CUISTR_EVENT_UNLOADING );
158  aDisplayNames.emplace_back( "unloaded", RID_CUISTR_EVENT_UNLOADED );
159  aDisplayNames.emplace_back( "confirmDelete", RID_CUISTR_EVENT_CONFIRMDELETE );
160  aDisplayNames.emplace_back( "approveRowChange", RID_CUISTR_EVENT_APPROVEROWCHANGE );
161  aDisplayNames.emplace_back( "rowChanged", RID_CUISTR_EVENT_ROWCHANGE );
162  aDisplayNames.emplace_back( "approveCursorMove", RID_CUISTR_EVENT_POSITIONING );
163  aDisplayNames.emplace_back( "cursorMoved", RID_CUISTR_EVENT_POSITIONED );
164  aDisplayNames.emplace_back( "approveParameter", RID_CUISTR_EVENT_APPROVEPARAMETER );
165  aDisplayNames.emplace_back( "errorOccured", RID_CUISTR_EVENT_ERROROCCURRED );
166  aDisplayNames.emplace_back( "adjustmentValueChanged", RID_CUISTR_EVENT_ADJUSTMENTVALUECHANGED );
167 }
168 
169 // the following method is called when the user clicks OK
170 // We use the contents of the hashes to replace the settings
172 {
173  try
174  {
175  OUString eventName;
176  if( m_xAppEvents.is() )
177  {
178  for (auto const& appEvent : m_appEventsHash)
179  {
180  eventName = appEvent.first;
181  try
182  {
183  m_xAppEvents->replaceByName( eventName, GetPropsByName( eventName, m_appEventsHash ) );
184  }
185  catch (const Exception&)
186  {
187  DBG_UNHANDLED_EXCEPTION("cui.customize");
188  }
189  }
190  }
191  if( m_xDocEvents.is() && bDocModified )
192  {
193  for (auto const& docEvent : m_docEventsHash)
194  {
195  eventName = docEvent.first;
196  try
197  {
198  m_xDocEvents->replaceByName( eventName, GetPropsByName( eventName, m_docEventsHash ) );
199  }
200  catch (const Exception&)
201  {
202  DBG_UNHANDLED_EXCEPTION("cui.customize");
203  }
204  }
205  // if we have a valid XModifiable (in the case of doc events)
206  // call setModified(true)
207  // in principle this should not be necessary (see issue ??)
208  if(m_xModifiable.is())
209  {
210  m_xModifiable->setModified( true );
211  }
212  }
213  }
214  catch (const Exception&)
215  {
216  }
217  // what is the return value about??
218  return false;
219 }
220 
221 // the following method clears the bindings in the hashes for both doc & app
223 {
224  // called once in creation - don't reset the data this time
225  if(!bInitialized)
226  {
227  bInitialized = true;
228  return;
229  }
230 
231  try
232  {
233  if( m_xAppEvents.is() )
234  {
235  for (auto & appEvent : m_appEventsHash)
236  {
237  appEvent.second.second.clear();
238  }
239  }
240  if( m_xDocEvents.is() && bDocModified )
241  {
242  for (auto & docEvent : m_docEventsHash)
243  {
244  docEvent.second.second.clear();
245  }
246  // if we have a valid XModifiable (in the case of doc events)
247  // call setModified(true)
248  if(m_xModifiable.is())
249  {
250  m_xModifiable->setModified( true );
251  }
252  }
253  }
254  catch (const Exception&)
255  {
256  }
258 }
259 
261 {
262  mpImpl->bReadOnly = bSet;
263 }
264 
266 {
267  return mpImpl->bReadOnly;
268 }
269 
270 namespace
271 {
272  OUString GetEventDisplayText(const OUString &rURL)
273  {
274  if (rURL.isEmpty())
275  return OUString();
276  sal_Int32 nIndex = rURL.indexOf(aVndSunStarUNO);
277  bool bUNO = nIndex == 0;
278  OUString aPureMethod;
279  if (bUNO)
280  {
281  aPureMethod = rURL.copy(aVndSunStarUNO.getLength());
282  }
283  else
284  {
285  aPureMethod = rURL.copy(strlen("vnd.sun.star.script:"));
286  aPureMethod = aPureMethod.copy( 0, aPureMethod.indexOf( '?' ) );
287  }
288  return aPureMethod;
289  }
290 
291  OUString GetEventDisplayImage(const OUString &rURL)
292  {
293  if (rURL.isEmpty())
294  return OUString();
295  sal_Int32 nIndex = rURL.indexOf(aVndSunStarUNO);
296  bool bUNO = nIndex == 0;
297  return bUNO ? OUString(RID_SVXBMP_COMPONENT) : OUString(RID_SVXBMP_MACRO);
298  }
299 }
300 
301 // displays the app events if appEvents=true, otherwise displays the doc events
303 {
304  bAppEvents = appEvents;
305 
306  mpImpl->xEventLB->freeze();
307  mpImpl->xEventLB->clear();
308  EventsHash* eventsHash;
309  Reference< container::XNameReplace> nameReplace;
310  if(bAppEvents)
311  {
312  eventsHash = &m_appEventsHash;
313  nameReplace = m_xAppEvents;
314  }
315  else
316  {
317  eventsHash = &m_docEventsHash;
318  nameReplace = m_xDocEvents;
319  }
320  // have to use the original XNameReplace since the hash iterators do
321  // not guarantee the order in which the elements are returned
322  if(!nameReplace.is())
323  {
324  mpImpl->xEventLB->thaw();
325  return;
326  }
327 
328  for (auto const& displayableEvent : aDisplayNames)
329  {
330  OUString sEventName( OUString::createFromAscii( displayableEvent.pAsciiEventName ) );
331  if ( !nameReplace->hasByName( sEventName ) )
332  continue;
333 
334  EventsHash::iterator h_it = eventsHash->find( sEventName );
335  if( h_it == eventsHash->end() )
336  {
337  OSL_FAIL( "SvxMacroTabPage_::DisplayAppEvents: something's suspicious here!" );
338  continue;
339  }
340 
341  OUString eventURL = h_it->second.second;
342  OUString displayName(CuiResId(displayableEvent.pEventResourceID));
343 
344  int nRow = mpImpl->xEventLB->n_children();
345  mpImpl->xEventLB->append(sEventName, displayName);
346  mpImpl->xEventLB->set_image(nRow, GetEventDisplayImage(eventURL), 1);
347  mpImpl->xEventLB->set_text(nRow, GetEventDisplayText(eventURL), 2);
348  }
349 
350  mpImpl->xEventLB->thaw();
351 
352  if (mpImpl->xEventLB->n_children())
353  {
354  mpImpl->xEventLB->select(0);
355  mpImpl->xEventLB->scroll_to_row(0);
356  }
357 
358  EnableButtons();
359 }
360 
361 // select event handler on the listbox
363 {
364  int nEntry = mpImpl->xEventLB->get_selected_index();
365 
366  if (nEntry == -1)
367  {
368  DBG_ASSERT(false, "Where does the empty entry come from?" );
369  return;
370  }
371 
372  EnableButtons();
373 }
374 
375 IMPL_LINK( SvxMacroTabPage_, AssignDeleteHdl_Impl, weld::Button&, rBtn, void )
376 {
377  GenericHandler_Impl(this, &rBtn);
378 }
379 
380 IMPL_LINK_NOARG( SvxMacroTabPage_, DoubleClickHdl_Impl, weld::TreeView&, bool)
381 {
382  GenericHandler_Impl(this, nullptr);
383  return true;
384 }
385 
386 // handler for double click on the listbox, and for the assign/delete buttons
388 {
389  SvxMacroTabPage_Impl* pImpl = pThis->mpImpl.get();
390  weld::TreeView& rListBox = *pImpl->xEventLB;
391  int nEntry = rListBox.get_selected_index();
392  if (nEntry == -1)
393  {
394  DBG_ASSERT(false, "Where does the empty entry come from?");
395  return;
396  }
397 
398  const bool bAssEnabled = pBtn != pImpl->xDeletePB.get() && pImpl->xAssignPB->get_sensitive();
399 
400  OUString sEventName = rListBox.get_id(nEntry);
401 
402  OUString sEventURL;
403  OUString sEventType;
404  if(pThis->bAppEvents)
405  {
406  EventsHash::iterator h_it = pThis->m_appEventsHash.find(sEventName);
407  if(h_it != pThis->m_appEventsHash.end() )
408  {
409  sEventType = h_it->second.first;
410  sEventURL = h_it->second.second;
411  }
412  }
413  else
414  {
415  EventsHash::iterator h_it = pThis->m_docEventsHash.find(sEventName);
416  if(h_it != pThis->m_docEventsHash.end() )
417  {
418  sEventType = h_it->second.first;
419  sEventURL = h_it->second.second;
420  }
421  }
422 
423  bool bDoubleClick = (pBtn == nullptr);
424  bool bUNOAssigned = sEventURL.startsWith( aVndSunStarUNO );
425  if( pBtn == pImpl->xDeletePB.get() )
426  {
427  // delete pressed
428  sEventType = "Script" ;
429  sEventURL.clear();
430  if(!pThis->bAppEvents)
431  pThis->bDocModified = true;
432  }
433  else if ( ( ( pBtn != nullptr )
434  && ( pBtn == pImpl->xAssignComponentPB.get() )
435  )
436  || ( bDoubleClick
437  && bUNOAssigned
438  )
439  )
440  {
441  AssignComponentDialog aAssignDlg(pThis->GetFrameWeld(), sEventURL);
442 
443  short ret = aAssignDlg.run();
444  if( ret )
445  {
446  sEventType = "UNO";
447  sEventURL = aAssignDlg.getURL();
448  if(!pThis->bAppEvents)
449  pThis->bDocModified = true;
450  }
451  }
452  else if( bAssEnabled )
453  {
454  // assign pressed
455  SvxScriptSelectorDialog aDlg(pThis->GetFrameWeld(), pThis->GetFrame());
456  short ret = aDlg.run();
457  if ( ret )
458  {
459  sEventType = "Script";
460  sEventURL = aDlg.GetScriptURL();
461  if(!pThis->bAppEvents)
462  pThis->bDocModified = true;
463  }
464  }
465 
466  // update the hashes
467  if(pThis->bAppEvents)
468  {
469  EventsHash::iterator h_it = pThis->m_appEventsHash.find(sEventName);
470  h_it->second.first = sEventType;
471  h_it->second.second = sEventURL;
472  }
473  else
474  {
475  EventsHash::iterator h_it = pThis->m_docEventsHash.find(sEventName);
476  h_it->second.first = sEventType;
477  h_it->second.second = sEventURL;
478  }
479 
480  rListBox.set_image(nEntry, GetEventDisplayImage(sEventURL), 1);
481  rListBox.set_text(nEntry, GetEventDisplayText(sEventURL), 2);
482 
483  rListBox.select(nEntry );
484  rListBox.scroll_to_row(nEntry);
485 
486  pThis->EnableButtons();
487 }
488 
489 // pass in the XNameReplace.
490 // can remove the 3rd arg once issue ?? is fixed
491 void SvxMacroTabPage_::InitAndSetHandler( const Reference< container::XNameReplace>& xAppEvents, const Reference< container::XNameReplace>& xDocEvents, const Reference< util::XModifiable >& xModifiable )
492 {
493  m_xAppEvents = xAppEvents;
494  m_xDocEvents = xDocEvents;
495  m_xModifiable = xModifiable;
496  Link<weld::Button&,void> aLnk(LINK(this, SvxMacroTabPage_, AssignDeleteHdl_Impl ));
497  mpImpl->xDeletePB->connect_clicked(aLnk);
498  mpImpl->xAssignPB->connect_clicked(aLnk);
499  if( mpImpl->xAssignComponentPB )
500  mpImpl->xAssignComponentPB->connect_clicked( aLnk );
501  mpImpl->xEventLB->connect_row_activated( LINK(this, SvxMacroTabPage_, DoubleClickHdl_Impl ) );
502  mpImpl->xEventLB->connect_changed( LINK( this, SvxMacroTabPage_, SelectEvent_Impl ));
503 
504  std::vector<int> aWidths
505  {
506  o3tl::narrowing<int>(mpImpl->xEventLB->get_approximate_digit_width() * 32),
507  mpImpl->xEventLB->get_checkbox_column_width()
508  };
509  mpImpl->xEventLB->set_column_fixed_widths(aWidths);
510 
511  mpImpl->xEventLB->show();
512  mpImpl->xEventLB->set_sensitive(true);
513 
514  if(!m_xAppEvents.is())
515  {
516  return;
517  }
518  Sequence< OUString > eventNames = m_xAppEvents->getElementNames();
519  sal_Int32 nEventCount = eventNames.getLength();
520  for(sal_Int32 nEvent = 0; nEvent < nEventCount; ++nEvent )
521  {
522  //need exception handling here
523  try
524  {
525  m_appEventsHash[ eventNames[nEvent] ] = GetPairFromAny( m_xAppEvents->getByName( eventNames[nEvent] ) );
526  }
527  catch (const Exception&)
528  {
529  }
530  }
531  if(!m_xDocEvents.is())
532  return;
533 
534  eventNames = m_xDocEvents->getElementNames();
535  nEventCount = eventNames.getLength();
536  for(sal_Int32 nEvent = 0; nEvent < nEventCount; ++nEvent )
537  {
538  try
539  {
540  m_docEventsHash[ eventNames[nEvent] ] = GetPairFromAny( m_xDocEvents->getByName( eventNames[nEvent] ) );
541  }
542  catch (const Exception&)
543  {
544  }
545  }
546 }
547 
548 // returns the two props EventType & Script for a given event name
549 Any SvxMacroTabPage_::GetPropsByName( const OUString& eventName, EventsHash& eventsHash )
550 {
551  const std::pair< OUString, OUString >& rAssignedEvent( eventsHash[ eventName ] );
552 
553  Any aReturn;
555  if ( !(rAssignedEvent.first.isEmpty() || rAssignedEvent.second.isEmpty()) )
556  {
557  aProps.put( "EventType", rAssignedEvent.first );
558  aProps.put( "Script", rAssignedEvent.second );
559  }
560  aReturn <<= aProps.getPropertyValues();
561 
562  return aReturn;
563 }
564 
565 // converts the Any returned by GetByName into a pair which can be stored in
566 // the EventHash
567 std::pair< OUString, OUString > SvxMacroTabPage_::GetPairFromAny( const Any& aAny )
568 {
570  OUString type, url;
571  if( aAny >>= props )
572  {
573  ::comphelper::NamedValueCollection aProps( props );
574  type = aProps.getOrDefault( "EventType", type );
575  url = aProps.getOrDefault( "Script", url );
576  }
577  return std::make_pair( type, url );
578 }
579 
581  const Reference< frame::XFrame >& _rxDocumentFrame,
582  const SfxItemSet& rSet,
583  Reference< container::XNameReplace > const & xNameReplace,
584  sal_uInt16 nSelectedIndex)
585  : SvxMacroTabPage_(pPage, pController, "cui/ui/macroassignpage.ui", "MacroAssignPage", rSet)
586 {
587  mpImpl->xEventLB = m_xBuilder->weld_tree_view("assignments");
588  mpImpl->xEventLB->set_size_request(mpImpl->xEventLB->get_approximate_digit_width() * 70,
589  mpImpl->xEventLB->get_height_rows(9));
590  mpImpl->xAssignPB = m_xBuilder->weld_button("assign");
591  mpImpl->xDeletePB = m_xBuilder->weld_button("delete");
592  mpImpl->xAssignComponentPB = m_xBuilder->weld_button("component");
593 
594  SetFrame( _rxDocumentFrame );
595 
596  if( !mpImpl->bIDEDialogMode )
597  {
598  mpImpl->xAssignComponentPB->hide();
599  mpImpl->xAssignComponentPB->set_sensitive(false);
600  }
601 
602  InitResources();
603 
604  InitAndSetHandler( xNameReplace, Reference< container::XNameReplace>(nullptr), Reference< util::XModifiable >(nullptr));
605  DisplayAppEvents(true);
606  mpImpl->xEventLB->select(nSelectedIndex);
607 }
608 
609 SvxMacroAssignDlg::SvxMacroAssignDlg(weld::Window* pParent, const Reference< frame::XFrame >& _rxDocumentFrame, const SfxItemSet& rSet,
610  const Reference< container::XNameReplace >& xNameReplace, sal_uInt16 nSelectedIndex)
611  : SvxMacroAssignSingleTabDialog(pParent, rSet)
612 {
613  SetTabPage(std::make_unique<SvxMacroTabPage>(get_content_area(), this, _rxDocumentFrame, rSet, xNameReplace, nSelectedIndex));
614 }
615 
617 {
618  OUString aMethodName = mxMethodEdit->get_text();
619  maURL.clear();
620  if( !aMethodName.isEmpty() )
621  {
622  maURL = aVndSunStarUNO;
623  maURL += aMethodName;
624  }
625  m_xDialog->response(RET_OK);
626 }
627 
629  : GenericDialogController(pParent, "cui/ui/assigncomponentdialog.ui", "AssignComponent")
630  , maURL( rURL )
631  , mxMethodEdit(m_xBuilder->weld_entry("methodEntry"))
632  , mxOKButton(m_xBuilder->weld_button("ok"))
633 {
634  mxOKButton->connect_clicked(LINK(this, AssignComponentDialog, ButtonHandler));
635 
636  OUString aMethodName;
637  if( maURL.startsWith( aVndSunStarUNO ) )
638  {
639  aMethodName = maURL.copy( aVndSunStarUNO.getLength() );
640  }
641  mxMethodEdit->set_text(aMethodName);
642  mxMethodEdit->select_region(0, -1);
643 }
644 
646 {
647 }
648 
650 {
651  m_xSfxPage->FillItemSet(nullptr);
652  m_xDialog->response(RET_OK);
653 }
654 
656  const SfxItemSet& rSet)
657  : SfxSingleTabDialogController(pParent, &rSet, "cui/ui/macroassigndialog.ui", "MacroAssignDialog")
658 {
660 }
661 
662 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual void set_text(int row, const OUString &rText, int col=-1)=0
virtual bool FillItemSet(SfxItemSet *rSet) override
Definition: macropg.cxx:171
sal_Int32 nIndex
SvxMacroAssignDlg(weld::Window *pParent, const css::uno::Reference< css::frame::XFrame > &_rxDocumentFrame, const SfxItemSet &rSet, const css::uno::Reference< css::container::XNameReplace > &xNameReplace, sal_uInt16 nSelectedIndex)
Definition: macropg.cxx:609
constexpr OUStringLiteral aVndSunStarUNO
Definition: macropg.cxx:39
static void GenericHandler_Impl(SvxMacroTabPage_ *pThis, const weld::Button *pBtn)
Definition: macropg.cxx:387
void DisplayAppEvents(bool appEvents)
Definition: macropg.cxx:302
SvxMacroTabPage_(weld::Container *pPage, weld::DialogController *pController, const OUString &rUIXMLDescription, const OString &rID, const SfxItemSet &rItemSet)
Definition: macropg.cxx:72
SvxMacroAssignSingleTabDialog(weld::Window *pParent, const SfxItemSet &rOptionsSet)
Definition: macropg.cxx:655
virtual ~AssignComponentDialog() override
Definition: macropg.cxx:645
css::uno::Reference< css::util::XModifiable > m_xModifiable
Definition: macropg.hxx:64
std::unique_ptr< weld::Entry > mxMethodEdit
std::unique_ptr< weld::Button > mxOKButton
weld::Container * get_content_area()
bool bReadOnly
EventsHash m_docEventsHash
Definition: macropg.hxx:66
SvxMacroTabPage(weld::Container *pPage, weld::DialogController *pController, const css::uno::Reference< css::frame::XFrame > &_rxDocumentFrame, const SfxItemSet &rSet, css::uno::Reference< css::container::XNameReplace > const &xNameReplace, sal_uInt16 nSelectedIndex)
Definition: macropg.cxx:580
MacroEventListBox(std::unique_ptr< weld::TreeView > xTreeView)
Definition: macropg.cxx:50
std::vector< EventDisplayName > aDisplayNames
Definition: macropg.hxx:68
virtual OUString get_id(int pos) const =0
VALUE_TYPE getOrDefault(const OUString &_rValueName, const VALUE_TYPE &_rDefault) const
void SetFrame(const css::uno::Reference< css::frame::XFrame > &xFrame)
constexpr OUStringLiteral sEventType
std::unique_ptr< SvxMacroTabPage_Impl > mpImpl
Definition: macropg.hxx:62
IMPL_LINK(SvxMacroTabPage_, AssignDeleteHdl_Impl, weld::Button &, rBtn, void)
Definition: macropg.cxx:375
std::unordered_map< OUString, std::pair< OUString, OUString > > EventsHash
Definition: macropg.hxx:33
OUString CuiResId(TranslateId aKey)
Definition: cuiresmgr.cxx:23
#define DBG_UNHANDLED_EXCEPTION(...)
void connect_clicked(const Link< Button &, void > &rLink)
std::unique_ptr< weld::Button > xAssignPB
void InitAndSetHandler(const css::uno::Reference< css::container::XNameReplace > &xAppEvents, const css::uno::Reference< css::container::XNameReplace > &xDocEvents, const css::uno::Reference< css::util::XModifiable > &xModifiable)
Definition: macropg.cxx:491
static css::uno::Any GetPropsByName(const OUString &eventName, EventsHash &eventsHash)
Definition: macropg.cxx:549
css::uno::Reference< css::frame::XFrame > GetFrame() const
SfxItemState GetItemState(sal_uInt16 nWhich, bool bSrchInParent=true, const SfxPoolItem **ppItem=nullptr) const
#define DBG_ASSERT(sCon, aError)
css::uno::Reference< css::container::XNameReplace > m_xAppEvents
Definition: macropg.hxx:60
css::uno::Sequence< css::beans::PropertyValue > getPropertyValues() const
virtual int get_selected_index() const =0
float u
dictionary props
void SetTabPage(std::unique_ptr< SfxTabPage > xTabPage)
bool IsReadOnly() const override
Definition: macropg.cxx:265
constexpr OStringLiteral HID_MACRO_HEADERTABLISTBOX
Definition: helpids.h:48
std::unique_ptr< weld::Button > xAssignComponentPB
std::unique_ptr< weld::Button > xDeletePB
static std::pair< OUString, OUString > GetPairFromAny(const css::uno::Any &aAny)
Definition: macropg.cxx:567
void EnableButtons()
Definition: macropg.cxx:60
void SetReadOnly(bool bSet)
Definition: macropg.cxx:260
std::unique_ptr< weld::TreeView > m_xTreeView
virtual void select(int pos)=0
weld::Window * GetFrameWeld() const
SvxMacroTabPage_Impl(const SfxItemSet &rAttrSet)
Definition: macropg.cxx:41
RET_OK
bool put(const OUString &_rValueName, const VALUE_TYPE &_rValue)
Reference< XExecutableDialog > m_xDialog
virtual short run()
virtual void set_image(int row, const OUString &rImage, int col=-1)=0
virtual ~SvxMacroTabPage_() override
Definition: macropg.cxx:82
void InitResources()
Definition: macropg.cxx:87
AssignComponentDialog(weld::Window *pParent, const OUString &rURL)
Definition: macropg.cxx:628
ResultType type
css::uno::Reference< css::container::XNameReplace > m_xDocEvents
Definition: macropg.hxx:63
virtual void Reset(const SfxItemSet *) override
Definition: macropg.cxx:222
std::unique_ptr< TabPageImpl > pImpl
virtual weld::Button & GetOKButton() const override
IMPL_LINK_NOARG(SvxMacroTabPage_, SelectEvent_Impl, weld::TreeView &, void)
Definition: macropg.cxx:362
std::unique_ptr< weld::TreeView > xEventLB
EventsHash m_appEventsHash
Definition: macropg.hxx:65
virtual void scroll_to_row(int row)=0