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