1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
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>
38 using namespace ::com::sun::star
;
39 using namespace ::com::sun::star::uno
;
41 constexpr OUString aVndSunStarUNO
= u
"vnd.sun.star.UNO:"_ustr
;
43 SvxMacroTabPage_Impl::SvxMacroTabPage_Impl( const SfxItemSet
& rAttrSet
)
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)
82 mpImpl
.reset( new SvxMacroTabPage_Impl( rAttrSet
) );
85 SvxMacroTabPage_::~SvxMacroTabPage_()
91 struct EventDisplayName
93 OUString aAsciiEventName
;
94 TranslateId pEventResourceID
;
98 // Note: the order here controls the order in which the events are displayed in the UI!
99 // the event name to UI string mappings for App Events
100 constexpr EventDisplayName gDisplayNames
[] {
101 { u
"OnStartApp"_ustr
, RID_CUISTR_EVENT_STARTAPP
},
102 { u
"OnCloseApp"_ustr
, RID_CUISTR_EVENT_CLOSEAPP
},
103 { u
"OnCreate"_ustr
, RID_CUISTR_EVENT_CREATEDOC
},
104 { u
"OnNew"_ustr
, RID_CUISTR_EVENT_NEWDOC
},
105 { u
"OnLoadFinished"_ustr
, RID_CUISTR_EVENT_LOADDOCFINISHED
},
106 { u
"OnLoad"_ustr
, RID_CUISTR_EVENT_OPENDOC
},
107 { u
"OnPrepareUnload"_ustr
, RID_CUISTR_EVENT_PREPARECLOSEDOC
},
108 { u
"OnUnload"_ustr
, RID_CUISTR_EVENT_CLOSEDOC
},
109 { u
"OnViewCreated"_ustr
, RID_CUISTR_EVENT_VIEWCREATED
},
110 { u
"OnPrepareViewClosing"_ustr
, RID_CUISTR_EVENT_PREPARECLOSEVIEW
},
111 { u
"OnViewClosed"_ustr
, RID_CUISTR_EVENT_CLOSEVIEW
},
112 { u
"OnFocus"_ustr
, RID_CUISTR_EVENT_ACTIVATEDOC
},
113 { u
"OnUnfocus"_ustr
, RID_CUISTR_EVENT_DEACTIVATEDOC
},
114 { u
"OnSave"_ustr
, RID_CUISTR_EVENT_SAVEDOC
},
115 { u
"OnSaveDone"_ustr
, RID_CUISTR_EVENT_SAVEDOCDONE
},
116 { u
"OnSaveFailed"_ustr
, RID_CUISTR_EVENT_SAVEDOCFAILED
},
117 { u
"OnSaveAs"_ustr
, RID_CUISTR_EVENT_SAVEASDOC
},
118 { u
"OnSaveAsDone"_ustr
, RID_CUISTR_EVENT_SAVEASDOCDONE
},
119 { u
"OnSaveAsFailed"_ustr
, RID_CUISTR_EVENT_SAVEASDOCFAILED
},
120 { u
"OnCopyTo"_ustr
, RID_CUISTR_EVENT_COPYTODOC
},
121 { u
"OnCopyToDone"_ustr
, RID_CUISTR_EVENT_COPYTODOCDONE
},
122 { u
"OnCopyToFailed"_ustr
, RID_CUISTR_EVENT_COPYTODOCFAILED
},
123 { u
"OnPrint"_ustr
, RID_CUISTR_EVENT_PRINTDOC
},
124 { u
"OnModifyChanged"_ustr
, RID_CUISTR_EVENT_MODIFYCHANGED
},
125 { u
"OnTitleChanged"_ustr
, RID_CUISTR_EVENT_TITLECHANGED
},
127 // application specific events
128 { u
"OnMailMerge"_ustr
, RID_CUISTR_EVENT_MAILMERGE
},
129 { u
"OnMailMergeFinished"_ustr
, RID_CUISTR_EVENT_MAILMERGE_END
},
130 { u
"OnFieldMerge"_ustr
, RID_CUISTR_EVENT_FIELDMERGE
},
131 { u
"OnFieldMergeFinished"_ustr
, RID_CUISTR_EVENT_FIELDMERGE_FINISHED
},
132 { u
"OnPageCountChange"_ustr
, RID_CUISTR_EVENT_PAGECOUNTCHANGE
},
133 { u
"OnSubComponentOpened"_ustr
, RID_CUISTR_EVENT_SUBCOMPONENT_OPENED
},
134 { u
"OnSubComponentClosed"_ustr
, RID_CUISTR_EVENT_SUBCOMPONENT_CLOSED
},
135 { u
"OnSelect"_ustr
, RID_CUISTR_EVENT_SELECTIONCHANGED
},
136 { u
"OnDoubleClick"_ustr
, RID_CUISTR_EVENT_DOUBLECLICK
},
137 { u
"OnRightClick"_ustr
, RID_CUISTR_EVENT_RIGHTCLICK
},
138 { u
"OnCalculate"_ustr
, RID_CUISTR_EVENT_CALCULATE
},
139 { u
"OnChange"_ustr
, RID_CUISTR_EVENT_CONTENTCHANGED
},
141 // the event name to UI string mappings for forms & dialogs
143 { u
"approveAction"_ustr
, RID_CUISTR_EVENT_APPROVEACTIONPERFORMED
},
144 { u
"actionPerformed"_ustr
, RID_CUISTR_EVENT_ACTIONPERFORMED
},
145 { u
"changed"_ustr
, RID_CUISTR_EVENT_CHANGED
},
146 { u
"textChanged"_ustr
, RID_CUISTR_EVENT_TEXTCHANGED
},
147 { u
"itemStateChanged"_ustr
, RID_CUISTR_EVENT_ITEMSTATECHANGED
},
148 { u
"focusGained"_ustr
, RID_CUISTR_EVENT_FOCUSGAINED
},
149 { u
"focusLost"_ustr
, RID_CUISTR_EVENT_FOCUSLOST
},
150 { u
"keyPressed"_ustr
, RID_CUISTR_EVENT_KEYTYPED
},
151 { u
"keyReleased"_ustr
, RID_CUISTR_EVENT_KEYUP
},
152 { u
"mouseEntered"_ustr
, RID_CUISTR_EVENT_MOUSEENTERED
},
153 { u
"mouseDragged"_ustr
, RID_CUISTR_EVENT_MOUSEDRAGGED
},
154 { u
"mouseMoved"_ustr
, RID_CUISTR_EVENT_MOUSEMOVED
},
155 { u
"mousePressed"_ustr
, RID_CUISTR_EVENT_MOUSEPRESSED
},
156 { u
"mouseReleased"_ustr
, RID_CUISTR_EVENT_MOUSERELEASED
},
157 { u
"mouseExited"_ustr
, RID_CUISTR_EVENT_MOUSEEXITED
},
158 { u
"approveReset"_ustr
, RID_CUISTR_EVENT_APPROVERESETTED
},
159 { u
"resetted"_ustr
, RID_CUISTR_EVENT_RESETTED
},
160 { u
"approveSubmit"_ustr
, RID_CUISTR_EVENT_SUBMITTED
},
161 { u
"approveUpdate"_ustr
, RID_CUISTR_EVENT_BEFOREUPDATE
},
162 { u
"updated"_ustr
, RID_CUISTR_EVENT_AFTERUPDATE
},
163 { u
"loaded"_ustr
, RID_CUISTR_EVENT_LOADED
},
164 { u
"reloading"_ustr
, RID_CUISTR_EVENT_RELOADING
},
165 { u
"reloaded"_ustr
, RID_CUISTR_EVENT_RELOADED
},
166 { u
"unloading"_ustr
, RID_CUISTR_EVENT_UNLOADING
},
167 { u
"unloaded"_ustr
, RID_CUISTR_EVENT_UNLOADED
},
168 { u
"confirmDelete"_ustr
, RID_CUISTR_EVENT_CONFIRMDELETE
},
169 { u
"approveRowChange"_ustr
, RID_CUISTR_EVENT_APPROVEROWCHANGE
},
170 { u
"rowChanged"_ustr
, RID_CUISTR_EVENT_ROWCHANGE
},
171 { u
"approveCursorMove"_ustr
, RID_CUISTR_EVENT_POSITIONING
},
172 { u
"cursorMoved"_ustr
, RID_CUISTR_EVENT_POSITIONED
},
173 { u
"approveParameter"_ustr
, RID_CUISTR_EVENT_APPROVEPARAMETER
},
174 { u
"errorOccured"_ustr
, RID_CUISTR_EVENT_ERROROCCURRED
},
175 { u
"adjustmentValueChanged"_ustr
, RID_CUISTR_EVENT_ADJUSTMENTVALUECHANGED
},
178 // the following method is called when the user clicks OK
179 // We use the contents of the hashes to replace the settings
180 bool SvxMacroTabPage_::FillItemSet( SfxItemSet
* /*rSet*/ )
185 if( m_xAppEvents
.is() )
187 for (auto const& appEvent
: m_appEventsHash
)
189 eventName
= appEvent
.first
;
192 m_xAppEvents
->replaceByName( eventName
, GetPropsByName( eventName
, m_appEventsHash
) );
194 catch (const Exception
&)
196 DBG_UNHANDLED_EXCEPTION("cui.customize");
200 if( m_xDocEvents
.is() && bDocModified
)
202 for (auto const& docEvent
: m_docEventsHash
)
204 eventName
= docEvent
.first
;
207 m_xDocEvents
->replaceByName( eventName
, GetPropsByName( eventName
, m_docEventsHash
) );
209 catch (const Exception
&)
211 DBG_UNHANDLED_EXCEPTION("cui.customize");
214 // if we have a valid XModifiable (in the case of doc events)
215 // call setModified(true)
216 // in principle this should not be necessary (see issue ??)
217 if(m_xModifiable
.is())
219 m_xModifiable
->setModified( true );
223 catch (const Exception
&)
226 // what is the return value about??
230 // the following method clears the bindings in the hashes for both doc & app
231 void SvxMacroTabPage_::Reset( const SfxItemSet
* )
233 // called once in creation - don't reset the data this time
242 if( m_xAppEvents
.is() )
244 for (auto & appEvent
: m_appEventsHash
)
246 appEvent
.second
.second
.clear();
249 if( m_xDocEvents
.is() && bDocModified
)
251 for (auto & docEvent
: m_docEventsHash
)
253 docEvent
.second
.second
.clear();
255 // if we have a valid XModifiable (in the case of doc events)
256 // call setModified(true)
257 if(m_xModifiable
.is())
259 m_xModifiable
->setModified( true );
263 catch (const Exception
&)
266 DisplayAppEvents(bAppEvents
);
269 void SvxMacroTabPage_::SetReadOnly( bool bSet
)
271 mpImpl
->bReadOnly
= bSet
;
274 bool SvxMacroTabPage_::IsReadOnly() const
276 return mpImpl
->bReadOnly
;
281 std::u16string_view
GetEventDisplayText(std::u16string_view rURL
)
284 return std::u16string_view();
285 bool bUNO
= o3tl::starts_with(rURL
, aVndSunStarUNO
);
286 std::u16string_view aPureMethod
;
289 aPureMethod
= rURL
.substr(aVndSunStarUNO
.getLength());
293 aPureMethod
= rURL
.substr(strlen("vnd.sun.star.script:"));
294 aPureMethod
= aPureMethod
.substr( 0, aPureMethod
.find( '?' ) );
299 const OUString
& GetEventDisplayImage(std::u16string_view rURL
)
302 return EMPTY_OUSTRING
;
303 size_t nIndex
= rURL
.find(aVndSunStarUNO
);
304 bool bUNO
= nIndex
== 0;
305 return bUNO
? RID_SVXBMP_COMPONENT
: RID_SVXBMP_MACRO
;
309 // displays the app events if appEvents=true, otherwise displays the doc events
310 void SvxMacroTabPage_::DisplayAppEvents( bool appEvents
)
312 bAppEvents
= appEvents
;
314 mpImpl
->xEventLB
->freeze();
315 mpImpl
->xEventLB
->clear();
316 m_nAssignedEvents
= 0;
317 EventsHash
* eventsHash
;
318 Reference
< container::XNameReplace
> nameReplace
;
321 eventsHash
= &m_appEventsHash
;
322 nameReplace
= m_xAppEvents
;
326 eventsHash
= &m_docEventsHash
;
327 nameReplace
= m_xDocEvents
;
329 // have to use the original XNameReplace since the hash iterators do
330 // not guarantee the order in which the elements are returned
331 if(!nameReplace
.is())
333 mpImpl
->xEventLB
->thaw();
337 for (auto const& displayableEvent
: gDisplayNames
)
339 const OUString
& sEventName( displayableEvent
.aAsciiEventName
);
340 if ( !nameReplace
->hasByName( sEventName
) )
343 EventsHash::iterator h_it
= eventsHash
->find( sEventName
);
344 if( h_it
== eventsHash
->end() )
346 OSL_FAIL( "SvxMacroTabPage_::DisplayAppEvents: something's suspicious here!" );
350 OUString eventURL
= h_it
->second
.second
;
351 OUString
displayName(CuiResId(displayableEvent
.pEventResourceID
));
353 int nRow
= mpImpl
->xEventLB
->n_children();
354 mpImpl
->xEventLB
->append(sEventName
, displayName
);
355 mpImpl
->xEventLB
->set_image(nRow
, GetEventDisplayImage(eventURL
), 1);
356 mpImpl
->xEventLB
->set_text(nRow
, OUString(GetEventDisplayText(eventURL
)), 2);
358 if (!eventURL
.isEmpty())
362 mpImpl
->xEventLB
->thaw();
364 if (mpImpl
->xEventLB
->n_children())
366 mpImpl
->xEventLB
->select(0);
367 mpImpl
->xEventLB
->scroll_to_row(0);
373 // select event handler on the listbox
374 IMPL_LINK_NOARG( SvxMacroTabPage_
, SelectEvent_Impl
, weld::TreeView
&, void)
376 int nEntry
= mpImpl
->xEventLB
->get_selected_index();
380 DBG_ASSERT(false, "Where does the empty entry come from?" );
387 IMPL_LINK( SvxMacroTabPage_
, AssignDeleteHdl_Impl
, weld::Button
&, rBtn
, void )
389 GenericHandler_Impl(&rBtn
);
392 IMPL_LINK_NOARG( SvxMacroTabPage_
, DoubleClickHdl_Impl
, weld::TreeView
&, bool)
394 GenericHandler_Impl(nullptr);
398 const EventPair
* SvxMacroTabPage_::LookupEvent(const OUString
& rEventName
)
400 const EventPair
* pRet
= nullptr;
403 EventsHash::iterator h_it
= m_appEventsHash
.find(rEventName
);
404 if (h_it
!= m_appEventsHash
.end() )
405 pRet
= &h_it
->second
;
409 EventsHash::iterator h_it
= m_docEventsHash
.find(rEventName
);
410 if (h_it
!= m_docEventsHash
.end() )
411 pRet
= &h_it
->second
;
416 // handler for double click on the listbox, and for the assign/delete buttons
417 void SvxMacroTabPage_::GenericHandler_Impl(const weld::Button
* pBtn
)
419 weld::TreeView
& rListBox
= *mpImpl
->xEventLB
;
420 int nEntry
= rListBox
.get_selected_index();
423 DBG_ASSERT(false, "Where does the empty entry come from?");
427 const bool bAssEnabled
= pBtn
!= mpImpl
->xDeletePB
.get() && mpImpl
->xAssignPB
->get_sensitive();
429 OUString sEventName
= rListBox
.get_id(nEntry
);
433 if (const EventPair
* pEventPair
= LookupEvent(sEventName
))
435 sEventType
= pEventPair
->first
;
436 sEventURL
= pEventPair
->second
;
439 if (!sEventURL
.isEmpty())
442 bool bDoubleClick
= (pBtn
== nullptr);
443 bool bUNOAssigned
= sEventURL
.startsWith( aVndSunStarUNO
);
444 if (pBtn
== mpImpl
->xDeletePB
.get())
447 sEventType
= "Script" ;
452 else if ( ( ( pBtn
!= nullptr )
453 && ( pBtn
== mpImpl
->xAssignComponentPB
.get() )
460 AssignComponentDialog
aAssignDlg(GetFrameWeld(), sEventURL
);
462 short ret
= aAssignDlg
.run();
466 sEventURL
= aAssignDlg
.getURL();
471 else if( bAssEnabled
)
474 SvxScriptSelectorDialog
aDlg(GetFrameWeld(), GetFrame());
475 short ret
= aDlg
.run();
478 sEventType
= "Script";
479 sEventURL
= aDlg
.GetScriptURL();
488 EventsHash::iterator h_it
= m_appEventsHash
.find(sEventName
);
489 assert(h_it
!= m_appEventsHash
.end());
490 h_it
->second
.first
= sEventType
;
491 h_it
->second
.second
= sEventURL
;
495 EventsHash::iterator h_it
= m_docEventsHash
.find(sEventName
);
496 assert(h_it
!= m_docEventsHash
.end());
497 h_it
->second
.first
= sEventType
;
498 h_it
->second
.second
= sEventURL
;
501 if (!sEventURL
.isEmpty())
504 rListBox
.set_image(nEntry
, GetEventDisplayImage(sEventURL
), 1);
505 rListBox
.set_text(nEntry
, OUString(GetEventDisplayText(sEventURL
)), 2);
507 rListBox
.select(nEntry
);
508 rListBox
.scroll_to_row(nEntry
);
513 IMPL_LINK_NOARG(SvxMacroTabPage_
, DeleteAllHdl_Impl
, weld::Button
&, void)
515 OUString sEventType
= u
"Script"_ustr
;
516 OUString sEmptyString
;
518 mpImpl
->xEventLB
->all_foreach([this, &sEventType
, &sEmptyString
](weld::TreeIter
& rEntry
) {
519 weld::TreeView
& rListBox
= *mpImpl
->xEventLB
;
520 OUString sEventName
= rListBox
.get_id(rEntry
);
524 EventsHash::iterator h_it
= m_appEventsHash
.find(sEventName
);
525 assert(h_it
!= m_appEventsHash
.end());
526 h_it
->second
.first
= sEventType
;
527 h_it
->second
.second
= sEmptyString
;
531 EventsHash::iterator h_it
= m_docEventsHash
.find(sEventName
);
532 assert(h_it
!= m_docEventsHash
.end());
533 h_it
->second
.first
= sEventType
;
534 h_it
->second
.second
= sEmptyString
;
537 rListBox
.set_image(rEntry
, sEmptyString
, 1);
538 rListBox
.set_text(rEntry
, sEmptyString
, 2);
545 m_nAssignedEvents
= 0;
550 // pass in the XNameReplace.
551 // can remove the 3rd arg once issue ?? is fixed
552 void SvxMacroTabPage_::InitAndSetHandler( const Reference
< container::XNameReplace
>& xAppEvents
, const Reference
< container::XNameReplace
>& xDocEvents
, const Reference
< util::XModifiable
>& xModifiable
)
554 m_xAppEvents
= xAppEvents
;
555 m_xDocEvents
= xDocEvents
;
556 m_xModifiable
= xModifiable
;
557 Link
<weld::Button
&,void> aLnk(LINK(this, SvxMacroTabPage_
, AssignDeleteHdl_Impl
));
558 mpImpl
->xDeletePB
->connect_clicked(aLnk
);
559 mpImpl
->xAssignPB
->connect_clicked(aLnk
);
560 mpImpl
->xDeleteAllPB
->connect_clicked(LINK(this, SvxMacroTabPage_
, DeleteAllHdl_Impl
));
561 if( mpImpl
->xAssignComponentPB
)
562 mpImpl
->xAssignComponentPB
->connect_clicked( aLnk
);
563 mpImpl
->xEventLB
->connect_row_activated( LINK(this, SvxMacroTabPage_
, DoubleClickHdl_Impl
) );
564 mpImpl
->xEventLB
->connect_selection_changed(LINK(this, SvxMacroTabPage_
, SelectEvent_Impl
));
566 std::vector
<int> aWidths
568 o3tl::narrowing
<int>(mpImpl
->xEventLB
->get_approximate_digit_width() * 32),
569 mpImpl
->xEventLB
->get_checkbox_column_width()
571 mpImpl
->xEventLB
->set_column_fixed_widths(aWidths
);
573 mpImpl
->xEventLB
->show();
574 mpImpl
->xEventLB
->set_sensitive(true);
576 if(!m_xAppEvents
.is())
580 Sequence
< OUString
> eventNames
= m_xAppEvents
->getElementNames();
581 sal_Int32 nEventCount
= eventNames
.getLength();
582 for(sal_Int32 nEvent
= 0; nEvent
< nEventCount
; ++nEvent
)
584 //need exception handling here
587 m_appEventsHash
[ eventNames
[nEvent
] ] = GetPairFromAny( m_xAppEvents
->getByName( eventNames
[nEvent
] ) );
589 catch (const Exception
&)
593 if(!m_xDocEvents
.is())
596 eventNames
= m_xDocEvents
->getElementNames();
597 nEventCount
= eventNames
.getLength();
598 for(sal_Int32 nEvent
= 0; nEvent
< nEventCount
; ++nEvent
)
602 m_docEventsHash
[ eventNames
[nEvent
] ] = GetPairFromAny( m_xDocEvents
->getByName( eventNames
[nEvent
] ) );
604 catch (const Exception
&)
610 // returns the two props EventType & Script for a given event name
611 Any
SvxMacroTabPage_::GetPropsByName( const OUString
& eventName
, EventsHash
& eventsHash
)
613 const EventPair
& rAssignedEvent(eventsHash
[eventName
]);
616 ::comphelper::NamedValueCollection aProps
;
617 if ( !(rAssignedEvent
.first
.isEmpty() || rAssignedEvent
.second
.isEmpty()) )
619 aProps
.put( u
"EventType"_ustr
, rAssignedEvent
.first
);
620 aProps
.put( u
"Script"_ustr
, rAssignedEvent
.second
);
622 aReturn
<<= aProps
.getPropertyValues();
627 // converts the Any returned by GetByName into a pair which can be stored in
629 EventPair
SvxMacroTabPage_::GetPairFromAny( const Any
& aAny
)
631 Sequence
< beans::PropertyValue
> props
;
635 ::comphelper::NamedValueCollection
aProps( props
);
636 type
= aProps
.getOrDefault( u
"EventType"_ustr
, type
);
637 url
= aProps
.getOrDefault( u
"Script"_ustr
, url
);
639 return std::make_pair( type
, url
);
642 SvxMacroTabPage::SvxMacroTabPage(weld::Container
* pPage
, weld::DialogController
* pController
,
643 const Reference
< frame::XFrame
>& _rxDocumentFrame
,
644 const SfxItemSet
& rSet
,
645 Reference
< container::XNameReplace
> const & xNameReplace
,
646 sal_uInt16 nSelectedIndex
)
647 : SvxMacroTabPage_(pPage
, pController
, u
"cui/ui/macroassignpage.ui"_ustr
, u
"MacroAssignPage"_ustr
, rSet
)
649 mpImpl
->xEventLB
= m_xBuilder
->weld_tree_view(u
"assignments"_ustr
);
650 mpImpl
->xEventLB
->set_size_request(mpImpl
->xEventLB
->get_approximate_digit_width() * 70,
651 mpImpl
->xEventLB
->get_height_rows(9));
652 mpImpl
->xAssignPB
= m_xBuilder
->weld_button(u
"assign"_ustr
);
653 mpImpl
->xDeletePB
= m_xBuilder
->weld_button(u
"delete"_ustr
);
654 mpImpl
->xDeleteAllPB
= m_xBuilder
->weld_button(u
"deleteall"_ustr
);
655 mpImpl
->xAssignComponentPB
= m_xBuilder
->weld_button(u
"component"_ustr
);
657 SetFrame( _rxDocumentFrame
);
659 if( !mpImpl
->bIDEDialogMode
)
661 mpImpl
->xAssignComponentPB
->hide();
662 mpImpl
->xAssignComponentPB
->set_sensitive(false);
665 InitAndSetHandler( xNameReplace
, Reference
< container::XNameReplace
>(nullptr), Reference
< util::XModifiable
>(nullptr));
666 DisplayAppEvents(true);
667 mpImpl
->xEventLB
->select(nSelectedIndex
);
670 SvxMacroAssignDlg::SvxMacroAssignDlg(weld::Window
* pParent
, const Reference
< frame::XFrame
>& _rxDocumentFrame
, const SfxItemSet
& rSet
,
671 const Reference
< container::XNameReplace
>& xNameReplace
, sal_uInt16 nSelectedIndex
)
672 : SvxMacroAssignSingleTabDialog(pParent
, rSet
)
674 SetTabPage(std::make_unique
<SvxMacroTabPage
>(get_content_area(), this, _rxDocumentFrame
, rSet
, xNameReplace
, nSelectedIndex
));
677 IMPL_LINK_NOARG(AssignComponentDialog
, ButtonHandler
, weld::Button
&, void)
679 OUString aMethodName
= mxMethodEdit
->get_text();
681 if( !aMethodName
.isEmpty() )
683 maURL
= aVndSunStarUNO
;
684 maURL
+= aMethodName
;
686 m_xDialog
->response(RET_OK
);
689 AssignComponentDialog::AssignComponentDialog(weld::Window
* pParent
, OUString aURL
)
690 : GenericDialogController(pParent
, u
"cui/ui/assigncomponentdialog.ui"_ustr
, u
"AssignComponent"_ustr
)
691 , maURL(std::move( aURL
))
692 , mxMethodEdit(m_xBuilder
->weld_entry(u
"methodEntry"_ustr
))
693 , mxOKButton(m_xBuilder
->weld_button(u
"ok"_ustr
))
695 mxOKButton
->connect_clicked(LINK(this, AssignComponentDialog
, ButtonHandler
));
697 OUString aMethodName
;
698 if( maURL
.startsWith( aVndSunStarUNO
) )
700 aMethodName
= maURL
.copy( aVndSunStarUNO
.getLength() );
702 mxMethodEdit
->set_text(aMethodName
);
703 mxMethodEdit
->select_region(0, -1);
706 AssignComponentDialog::~AssignComponentDialog()
710 IMPL_LINK_NOARG(SvxMacroAssignSingleTabDialog
, OKHdl_Impl
, weld::Button
&, void)
712 m_xSfxPage
->FillItemSet(nullptr);
713 m_xDialog
->response(RET_OK
);
716 SvxMacroAssignSingleTabDialog::SvxMacroAssignSingleTabDialog(weld::Window
*pParent
,
717 const SfxItemSet
& rSet
)
718 : SfxSingleTabDialogController(pParent
, &rSet
, u
"cui/ui/macroassigndialog.ui"_ustr
, u
"MacroAssignDialog"_ustr
)
720 GetOKButton().connect_clicked(LINK(this, SvxMacroAssignSingleTabDialog
, OKHdl_Impl
));
723 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */