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