Avoid potential negative array index access to cached text.
[LibreOffice.git] / vcl / inc / jsdialog / jsdialogbuilder.hxx
blob71061c27cb3ba9b550205bb3d2fee23bc4d4c908
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 */
10 #pragma once
12 #include <utility>
13 #include <vcl/weld.hxx>
14 #include <vcl/jsdialog/executor.hxx>
15 #include <vcl/virdev.hxx>
16 #include <salvtables.hxx>
17 #include <vcl/toolkit/button.hxx>
18 #include <vcl/toolkit/fmtfield.hxx>
19 #include <vcl/toolkit/prgsbar.hxx>
21 #include <com/sun/star/lang/XInitialization.hpp>
22 #include <com/sun/star/lang/XServiceInfo.hpp>
23 #include <com/sun/star/datatransfer/dnd/XDropTarget.hpp>
24 #include <comphelper/compbase.hxx>
26 #include <deque>
27 #include <list>
28 #include <mutex>
30 #define ACTION_TYPE "action_type"
31 #define PARENT_ID "parent_id"
32 #define WINDOW_ID "id"
33 #define CLOSE_ID "close_id"
35 class ToolBox;
36 class ComboBox;
37 class VclMultiLineEdit;
38 class SvTabListBox;
39 class IconView;
40 class VclScrolledWindow;
42 namespace vcl
44 class ILibreOfficeKitNotifier;
47 typedef std::map<OUString, weld::Widget*> WidgetMap;
49 namespace jsdialog
51 enum MessageType
53 FullUpdate,
54 WidgetUpdate,
55 Close,
56 Action,
57 Popup,
58 PopupClose
62 /// Class with the message description for storing in the queue
63 class JSDialogMessageInfo
65 public:
66 jsdialog::MessageType m_eType;
67 VclPtr<vcl::Window> m_pWindow;
68 std::unique_ptr<jsdialog::ActionDataMap> m_pData;
70 private:
71 void copy(const JSDialogMessageInfo& rInfo)
73 this->m_eType = rInfo.m_eType;
74 this->m_pWindow = rInfo.m_pWindow;
75 if (rInfo.m_pData)
77 std::unique_ptr<jsdialog::ActionDataMap> pData(
78 new jsdialog::ActionDataMap(*rInfo.m_pData));
79 this->m_pData = std::move(pData);
83 public:
84 JSDialogMessageInfo(jsdialog::MessageType eType, VclPtr<vcl::Window> pWindow,
85 std::unique_ptr<jsdialog::ActionDataMap> pData)
86 : m_eType(eType)
87 , m_pWindow(std::move(pWindow))
88 , m_pData(std::move(pData))
92 JSDialogMessageInfo(const JSDialogMessageInfo& rInfo) { copy(rInfo); }
94 JSDialogMessageInfo& operator=(JSDialogMessageInfo aInfo)
96 if (this == &aInfo)
97 return *this;
99 copy(aInfo);
100 return *this;
104 class JSDialogNotifyIdle final : public Idle
106 // used to send message
107 VclPtr<vcl::Window> m_aNotifierWindow;
108 // used to generate JSON
109 VclPtr<vcl::Window> m_aContentWindow;
110 OUString m_sTypeOfJSON;
111 OString m_LastNotificationMessage;
112 bool m_bForce;
114 std::deque<JSDialogMessageInfo> m_aMessageQueue;
115 std::mutex m_aQueueMutex;
117 public:
118 JSDialogNotifyIdle(VclPtr<vcl::Window> aNotifierWindow, VclPtr<vcl::Window> aContentWindow,
119 const OUString& sTypeOfJSON);
121 void Invoke() override;
123 void clearQueue();
124 void forceUpdate();
125 void sendMessage(jsdialog::MessageType eType, VclPtr<vcl::Window> pWindow,
126 std::unique_ptr<jsdialog::ActionDataMap> pData = nullptr);
128 private:
129 void send(const OString& sMsg);
130 OString generateFullUpdate() const;
131 OString generateWidgetUpdate(VclPtr<vcl::Window> pWindow) const;
132 OString generateCloseMessage() const;
133 OString generateActionMessage(VclPtr<vcl::Window> pWindow,
134 std::unique_ptr<jsdialog::ActionDataMap> pData) const;
135 OString generatePopupMessage(VclPtr<vcl::Window> pWindow, OUString sParentId,
136 OUString sCloseId) const;
137 OString generateClosePopupMessage(OUString sWindowId) const;
140 class JSDialogSender
142 std::unique_ptr<JSDialogNotifyIdle> mpIdleNotify;
144 protected:
145 bool m_bCanClose; // specifies if can send a close message
147 public:
148 JSDialogSender()
149 : m_bCanClose(true)
152 JSDialogSender(VclPtr<vcl::Window> aNotifierWindow, VclPtr<vcl::Window> aContentWindow,
153 const OUString& sTypeOfJSON)
154 : m_bCanClose(true)
156 initializeSender(aNotifierWindow, aContentWindow, sTypeOfJSON);
159 virtual ~JSDialogSender() COVERITY_NOEXCEPT_FALSE;
161 virtual void sendFullUpdate(bool bForce = false);
162 void sendClose();
163 void sendUpdate(VclPtr<vcl::Window> pWindow, bool bForce = false);
164 virtual void sendAction(VclPtr<vcl::Window> pWindow,
165 std::unique_ptr<jsdialog::ActionDataMap> pData);
166 virtual void sendPopup(VclPtr<vcl::Window> pWindow, OUString sParentId, OUString sCloseId);
167 virtual void sendClosePopup(vcl::LOKWindowId nWindowId);
168 void flush() { mpIdleNotify->Invoke(); }
170 protected:
171 void initializeSender(const VclPtr<vcl::Window>& rNotifierWindow,
172 const VclPtr<vcl::Window>& rContentWindow, const OUString& rTypeOfJSON)
174 mpIdleNotify.reset(new JSDialogNotifyIdle(rNotifierWindow, rContentWindow, rTypeOfJSON));
178 class JSDropTarget final
179 : public comphelper::WeakComponentImplHelper<
180 css::datatransfer::dnd::XDropTarget, css::lang::XInitialization, css::lang::XServiceInfo>
182 std::vector<css::uno::Reference<css::datatransfer::dnd::XDropTargetListener>> m_aListeners;
184 public:
185 JSDropTarget();
187 // XInitialization
188 virtual void SAL_CALL initialize(const css::uno::Sequence<css::uno::Any>& rArgs) override;
190 // XDropTarget
191 virtual void SAL_CALL addDropTargetListener(
192 const css::uno::Reference<css::datatransfer::dnd::XDropTargetListener>&) override;
193 virtual void SAL_CALL removeDropTargetListener(
194 const css::uno::Reference<css::datatransfer::dnd::XDropTargetListener>&) override;
195 virtual sal_Bool SAL_CALL isActive() override;
196 virtual void SAL_CALL setActive(sal_Bool active) override;
197 virtual sal_Int8 SAL_CALL getDefaultActions() override;
198 virtual void SAL_CALL setDefaultActions(sal_Int8 actions) override;
200 OUString SAL_CALL getImplementationName() override;
202 sal_Bool SAL_CALL supportsService(OUString const& ServiceName) override;
204 css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames() override;
206 void fire_drop(const css::datatransfer::dnd::DropTargetDropEvent& dtde);
208 void fire_dragEnter(const css::datatransfer::dnd::DropTargetDragEnterEvent& dtde);
211 class JSInstanceBuilder final : public SalInstanceBuilder, public JSDialogSender
213 sal_uInt64 m_nWindowId;
214 /// used in case of tab pages where dialog is not a direct top level
215 VclPtr<vcl::Window> m_aParentDialog;
216 VclPtr<vcl::Window> m_aContentWindow;
217 std::list<OUString> m_aRememberedWidgets;
218 OUString m_sTypeOfJSON;
219 bool m_bHasTopLevelDialog;
220 bool m_bIsNotebookbar;
221 /// used to detect when we have to send Full Update in container handler
222 bool m_bSentInitialUpdate;
223 /// is true for tabpages, prevents from closing parent window on destroy
224 bool m_bIsNestedBuilder;
225 /// When LOKNotifier is set by jsdialogs code we need to release it
226 VclPtr<vcl::Window> m_aWindowToRelease;
228 friend class JSMessageDialog; // static message boxes have to be registered outside
229 friend class JSDialog;
230 friend class JSAssistant;
232 friend VCL_DLLPUBLIC bool jsdialog::ExecuteAction(const OUString& nWindowId,
233 const OUString& rWidget, StringMap& rData);
234 friend VCL_DLLPUBLIC void jsdialog::SendFullUpdate(const OUString& nWindowId,
235 const OUString& rWidget);
236 friend VCL_DLLPUBLIC void jsdialog::SendAction(const OUString& nWindowId,
237 const OUString& rWidget,
238 std::unique_ptr<jsdialog::ActionDataMap> pData);
240 static std::map<OUString, WidgetMap>& GetLOKWeldWidgetsMap();
241 static void InsertWindowToMap(const OUString& nWindowId);
242 void RememberWidget(OUString id, weld::Widget* pWidget);
243 static void RememberWidget(const OUString& nWindowId, const OUString& id,
244 weld::Widget* pWidget);
245 static weld::Widget* FindWeldWidgetsMap(const OUString& nWindowId, const OUString& rWidget);
247 OUString getMapIdFromWindowId() const;
249 public:
250 /// used for dialogs or popups
251 JSInstanceBuilder(weld::Widget* pParent, const OUString& rUIRoot, const OUString& rUIFile,
252 bool bPopup = false);
253 /// used for sidebar panels
254 JSInstanceBuilder(weld::Widget* pParent, const OUString& rUIRoot, const OUString& rUIFile,
255 sal_uInt64 nLOKWindowId);
256 /// used for notebookbar, optional nWindowId is used if getting parent id failed
257 JSInstanceBuilder(vcl::Window* pParent, const OUString& rUIRoot, const OUString& rUIFile,
258 const css::uno::Reference<css::frame::XFrame>& rFrame,
259 sal_uInt64 nWindowId = 0);
260 /// used for formulabar
261 JSInstanceBuilder(vcl::Window* pParent, const OUString& rUIRoot, const OUString& rUIFile,
262 sal_uInt64 nLOKWindowId);
264 static std::unique_ptr<JSInstanceBuilder>
265 CreateDialogBuilder(weld::Widget* pParent, const OUString& rUIRoot, const OUString& rUIFile);
266 static std::unique_ptr<JSInstanceBuilder>
267 CreateNotebookbarBuilder(vcl::Window* pParent, const OUString& rUIRoot, const OUString& rUIFile,
268 const css::uno::Reference<css::frame::XFrame>& rFrame,
269 sal_uInt64 nWindowId = 0);
270 static std::unique_ptr<JSInstanceBuilder> CreateSidebarBuilder(weld::Widget* pParent,
271 const OUString& rUIRoot,
272 const OUString& rUIFile,
273 sal_uInt64 nLOKWindowId = 0);
274 static std::unique_ptr<JSInstanceBuilder>
275 CreatePopupBuilder(weld::Widget* pParent, const OUString& rUIRoot, const OUString& rUIFile);
276 static std::unique_ptr<JSInstanceBuilder> CreateFormulabarBuilder(vcl::Window* pParent,
277 const OUString& rUIRoot,
278 const OUString& rUIFile,
279 sal_uInt64 nLOKWindowId);
281 virtual ~JSInstanceBuilder() override;
282 virtual std::unique_ptr<weld::MessageDialog> weld_message_dialog(const OUString& id) override;
283 virtual std::unique_ptr<weld::Dialog> weld_dialog(const OUString& id) override;
284 virtual std::unique_ptr<weld::Assistant> weld_assistant(const OUString& id) override;
285 virtual std::unique_ptr<weld::Container> weld_container(const OUString& id) override;
286 virtual std::unique_ptr<weld::Label> weld_label(const OUString& id) override;
287 virtual std::unique_ptr<weld::Button> weld_button(const OUString& id) override;
288 virtual std::unique_ptr<weld::LinkButton> weld_link_button(const OUString& id) override;
289 virtual std::unique_ptr<weld::ToggleButton> weld_toggle_button(const OUString& id) override;
290 virtual std::unique_ptr<weld::Entry> weld_entry(const OUString& id) override;
291 virtual std::unique_ptr<weld::ComboBox> weld_combo_box(const OUString& id) override;
292 virtual std::unique_ptr<weld::Notebook> weld_notebook(const OUString& id) override;
293 virtual std::unique_ptr<weld::SpinButton> weld_spin_button(const OUString& id) override;
294 virtual std::unique_ptr<weld::FormattedSpinButton>
295 weld_formatted_spin_button(const OUString& id) override;
296 virtual std::unique_ptr<weld::CheckButton> weld_check_button(const OUString& id) override;
297 virtual std::unique_ptr<weld::DrawingArea>
298 weld_drawing_area(const OUString& id, const a11yref& rA11yImpl = nullptr,
299 FactoryFunction pUITestFactoryFunction = nullptr,
300 void* pUserData = nullptr) override;
301 virtual std::unique_ptr<weld::Toolbar> weld_toolbar(const OUString& id) override;
302 virtual std::unique_ptr<weld::TextView> weld_text_view(const OUString& id) override;
303 virtual std::unique_ptr<weld::TreeView> weld_tree_view(const OUString& id) override;
304 virtual std::unique_ptr<weld::Expander> weld_expander(const OUString& id) override;
305 virtual std::unique_ptr<weld::IconView> weld_icon_view(const OUString& id) override;
306 virtual std::unique_ptr<weld::ScrolledWindow>
307 weld_scrolled_window(const OUString& id, bool bUserManagedScrolling = false) override;
308 virtual std::unique_ptr<weld::RadioButton> weld_radio_button(const OUString& id) override;
309 virtual std::unique_ptr<weld::Frame> weld_frame(const OUString& id) override;
310 virtual std::unique_ptr<weld::MenuButton> weld_menu_button(const OUString& id) override;
311 virtual std::unique_ptr<weld::Popover> weld_popover(const OUString& id) override;
312 virtual std::unique_ptr<weld::Box> weld_box(const OUString& id) override;
313 virtual std::unique_ptr<weld::Widget> weld_widget(const OUString& id) override;
314 virtual std::unique_ptr<weld::Image> weld_image(const OUString& id) override;
315 virtual std::unique_ptr<weld::LevelBar> weld_level_bar(const OUString& id) override;
316 virtual std::unique_ptr<weld::Calendar> weld_calendar(const OUString& id) override;
318 static weld::MessageDialog*
319 CreateMessageDialog(weld::Widget* pParent, VclMessageType eMessageType,
320 VclButtonsType eButtonType, const OUString& rPrimaryMessage,
321 const vcl::ILibreOfficeKitNotifier* pNotifier = nullptr);
323 static void AddChildWidget(const OUString& nWindowId, const OUString& id,
324 weld::Widget* pWidget);
325 static void RemoveWindowWidget(const OUString& nWindowId);
327 // we need to remember original popup window to close it properly (its handled by vcl)
328 static void RememberPopup(const OUString& nWindowId, VclPtr<vcl::Window> pWidget);
329 static void ForgetPopup(const OUString& nWindowId);
330 static vcl::Window* FindPopup(const OUString& nWindowId);
332 private:
333 const OUString& GetTypeOfJSON() const;
334 VclPtr<vcl::Window>& GetContentWindow();
335 VclPtr<vcl::Window>& GetNotifierWindow();
338 class SAL_LOPLUGIN_ANNOTATE("crosscast") BaseJSWidget
340 public:
341 virtual ~BaseJSWidget() = default;
343 virtual void sendClose() = 0;
345 virtual void sendUpdate(bool bForce = false) = 0;
347 virtual void sendFullUpdate(bool bForce = false) = 0;
349 virtual void sendAction(std::unique_ptr<jsdialog::ActionDataMap> pData) = 0;
351 virtual void sendPopup(vcl::Window* pPopup, OUString sParentId, OUString sCloseId) = 0;
353 virtual void sendClosePopup(vcl::LOKWindowId nWindowId) = 0;
356 template <class BaseInstanceClass, class VclClass>
357 class JSWidget : public BaseInstanceClass, public BaseJSWidget
359 protected:
360 rtl::Reference<JSDropTarget> m_xDropTarget;
361 bool m_bIsFreezed;
363 JSDialogSender* m_pSender;
365 public:
366 JSWidget(JSDialogSender* pSender, VclClass* pObject, SalInstanceBuilder* pBuilder,
367 bool bTakeOwnership)
368 : BaseInstanceClass(pObject, pBuilder, bTakeOwnership)
369 , m_bIsFreezed(false)
370 , m_pSender(pSender)
374 JSWidget(JSDialogSender* pSender, VclClass* pObject, SalInstanceBuilder* pBuilder,
375 bool bTakeOwnership, bool bUserManagedScrolling)
376 : BaseInstanceClass(pObject, pBuilder, bTakeOwnership, bUserManagedScrolling)
377 , m_bIsFreezed(false)
378 , m_pSender(pSender)
382 JSWidget(JSDialogSender* pSender, VclClass* pObject, SalInstanceBuilder* pBuilder,
383 const a11yref& rAlly, FactoryFunction pUITestFactoryFunction, void* pUserData,
384 bool bTakeOwnership)
385 : BaseInstanceClass(pObject, pBuilder, rAlly, pUITestFactoryFunction, pUserData,
386 bTakeOwnership)
387 , m_bIsFreezed(false)
388 , m_pSender(pSender)
392 virtual void show() override
394 bool bWasVisible = BaseInstanceClass::get_visible();
395 BaseInstanceClass::show();
396 if (!bWasVisible)
398 std::unique_ptr<jsdialog::ActionDataMap> pMap
399 = std::make_unique<jsdialog::ActionDataMap>();
400 (*pMap)[ACTION_TYPE ""_ostr] = "show";
401 sendAction(std::move(pMap));
405 virtual void hide() override
407 bool bWasVisible = BaseInstanceClass::get_visible();
408 BaseInstanceClass::hide();
409 if (bWasVisible)
411 std::unique_ptr<jsdialog::ActionDataMap> pMap
412 = std::make_unique<jsdialog::ActionDataMap>();
413 (*pMap)[ACTION_TYPE ""_ostr] = "hide";
414 sendAction(std::move(pMap));
418 using BaseInstanceClass::set_sensitive;
419 virtual void set_sensitive(bool sensitive) override
421 bool bIsSensitive = BaseInstanceClass::get_sensitive();
422 BaseInstanceClass::set_sensitive(sensitive);
423 if (bIsSensitive != sensitive)
425 std::unique_ptr<jsdialog::ActionDataMap> pMap
426 = std::make_unique<jsdialog::ActionDataMap>();
427 (*pMap)[ACTION_TYPE ""_ostr] = (sensitive ? u"enable" : u"disable");
428 sendAction(std::move(pMap));
432 virtual css::uno::Reference<css::datatransfer::dnd::XDropTarget> get_drop_target() override
434 if (!m_xDropTarget)
435 m_xDropTarget.set(new JSDropTarget);
437 return m_xDropTarget;
440 virtual void freeze() override
442 BaseInstanceClass::freeze();
443 m_bIsFreezed = true;
446 virtual void thaw() override
448 BaseInstanceClass::thaw();
449 m_bIsFreezed = false;
450 sendUpdate();
453 virtual void grab_focus() override
455 BaseInstanceClass::grab_focus();
456 std::unique_ptr<jsdialog::ActionDataMap> pMap = std::make_unique<jsdialog::ActionDataMap>();
457 (*pMap)[ACTION_TYPE ""_ostr] = "grab_focus";
458 sendAction(std::move(pMap));
461 virtual void sendClose() override
463 if (m_pSender)
464 m_pSender->sendClose();
467 virtual void sendUpdate(bool bForce = false) override
469 if (!m_bIsFreezed && m_pSender)
470 m_pSender->sendUpdate(BaseInstanceClass::m_xWidget, bForce);
473 virtual void sendFullUpdate(bool bForce = false) override
475 if ((!m_bIsFreezed || bForce) && m_pSender)
476 m_pSender->sendFullUpdate(bForce);
479 virtual void sendAction(std::unique_ptr<jsdialog::ActionDataMap> pData) override
481 if (!m_bIsFreezed && m_pSender && pData)
482 m_pSender->sendAction(BaseInstanceClass::m_xWidget, std::move(pData));
485 virtual void sendPopup(vcl::Window* pPopup, OUString sParentId, OUString sCloseId) override
487 if (!m_bIsFreezed && m_pSender)
488 m_pSender->sendPopup(pPopup, sParentId, sCloseId);
491 virtual void sendClosePopup(vcl::LOKWindowId nWindowId) override
493 if (!m_bIsFreezed && m_pSender)
494 m_pSender->sendClosePopup(nWindowId);
497 virtual void set_buildable_name(const OUString& rName) override
499 SalInstanceWidget::set_buildable_name(rName);
500 assert(false); // we remember old name in GetLOKWeldWidgetsMap()
501 // TODO: implement renaming or avoid it for LOK
505 class JSDialog final : public JSWidget<SalInstanceDialog, ::Dialog>
507 public:
508 JSDialog(JSDialogSender* pSender, ::Dialog* pDialog, SalInstanceBuilder* pBuilder,
509 bool bTakeOwnership);
511 virtual void collapse(weld::Widget* pEdit, weld::Widget* pButton) override;
512 virtual void undo_collapse() override;
513 virtual void response(int response) override;
514 virtual weld::Button* weld_widget_for_response(int response) override;
515 virtual int run() override;
516 virtual bool runAsync(std::shared_ptr<weld::DialogController> aOwner,
517 const std::function<void(sal_Int32)>& rEndDialogFn) override;
518 virtual bool runAsync(std::shared_ptr<Dialog> const& rxSelf,
519 const std::function<void(sal_Int32)>& func) override;
522 class JSAssistant final : public JSWidget<SalInstanceAssistant, vcl::RoadmapWizard>
524 public:
525 JSAssistant(JSDialogSender* pSender, vcl::RoadmapWizard* pDialog, SalInstanceBuilder* pBuilder,
526 bool bTakeOwnership);
528 virtual void set_current_page(int nPage) override;
529 virtual void set_current_page(const OUString& rIdent) override;
530 virtual void response(int response) override;
531 virtual weld::Button* weld_widget_for_response(int response) override;
532 virtual int run() override;
533 virtual bool runAsync(std::shared_ptr<weld::DialogController> aOwner,
534 const std::function<void(sal_Int32)>& rEndDialogFn) override;
535 virtual bool runAsync(std::shared_ptr<Dialog> const& rxSelf,
536 const std::function<void(sal_Int32)>& func) override;
539 class JSContainer final : public JSWidget<SalInstanceContainer, vcl::Window>
541 public:
542 JSContainer(JSDialogSender* pSender, vcl::Window* pContainer, SalInstanceBuilder* pBuilder,
543 bool bTakeOwnership);
545 void move(weld::Widget* pWidget, weld::Container* pNewParent) override;
548 class JSScrolledWindow final : public JSWidget<SalInstanceScrolledWindow, ::VclScrolledWindow>
550 public:
551 JSScrolledWindow(JSDialogSender* pSender, ::VclScrolledWindow* pWindow,
552 SalInstanceBuilder* pBuilder, bool bTakeOwnership, bool bUserManagedScrolling);
554 virtual void vadjustment_configure(int value, int lower, int upper, int step_increment,
555 int page_increment, int page_size) override;
556 virtual void vadjustment_set_value(int value) override;
557 void vadjustment_set_value_no_notification(int value);
558 virtual void vadjustment_set_page_size(int size) override;
559 virtual void set_vpolicy(VclPolicyType eVPolicy) override;
561 virtual void hadjustment_configure(int value, int lower, int upper, int step_increment,
562 int page_increment, int page_size) override;
563 virtual void hadjustment_set_value(int value) override;
564 void hadjustment_set_value_no_notification(int value);
565 virtual void hadjustment_set_page_size(int size) override;
566 virtual void set_hpolicy(VclPolicyType eVPolicy) override;
569 class JSLabel final : public JSWidget<SalInstanceLabel, Control>
571 public:
572 JSLabel(JSDialogSender* pSender, Control* pLabel, SalInstanceBuilder* pBuilder,
573 bool bTakeOwnership);
574 virtual void set_label(const OUString& rText) override;
577 class JSButton final : public JSWidget<SalInstanceButton, ::Button>
579 public:
580 JSButton(JSDialogSender* pSender, ::Button* pButton, SalInstanceBuilder* pBuilder,
581 bool bTakeOwnership);
584 class JSLinkButton final : public JSWidget<SalInstanceLinkButton, ::FixedHyperlink>
586 public:
587 JSLinkButton(JSDialogSender* pSender, ::FixedHyperlink* pButton, SalInstanceBuilder* pBuilder,
588 bool bTakeOwnership);
591 class JSToggleButton final : public JSWidget<SalInstanceToggleButton, ::PushButton>
593 public:
594 JSToggleButton(JSDialogSender* pSender, ::PushButton* pButton, SalInstanceBuilder* pBuilder,
595 bool bTakeOwnership);
598 class JSEntry final : public JSWidget<SalInstanceEntry, ::Edit>
600 public:
601 JSEntry(JSDialogSender* pSender, ::Edit* pEntry, SalInstanceBuilder* pBuilder,
602 bool bTakeOwnership);
603 virtual void set_text(const OUString& rText) override;
604 void set_text_without_notify(const OUString& rText);
605 virtual void replace_selection(const OUString& rText) override;
608 class JSListBox final : public JSWidget<SalInstanceComboBoxWithoutEdit, ::ListBox>
610 public:
611 JSListBox(JSDialogSender* pSender, ::ListBox* pListBox, SalInstanceBuilder* pBuilder,
612 bool bTakeOwnership);
613 virtual void insert(int pos, const OUString& rStr, const OUString* pId,
614 const OUString* pIconName, VirtualDevice* pImageSurface) override;
615 virtual void remove(int pos) override;
616 virtual void set_active(int pos) override;
619 class JSComboBox final : public JSWidget<SalInstanceComboBoxWithEdit, ::ComboBox>
621 public:
622 JSComboBox(JSDialogSender* pSender, ::ComboBox* pComboBox, SalInstanceBuilder* pBuilder,
623 bool bTakeOwnership);
624 virtual void insert(int pos, const OUString& rStr, const OUString* pId,
625 const OUString* pIconName, VirtualDevice* pImageSurface) override;
626 virtual void remove(int pos) override;
627 virtual void set_entry_text_without_notify(const OUString& rText);
628 virtual void set_entry_text(const OUString& rText) override;
629 virtual void set_active(int pos) override;
630 virtual void set_active_id(const OUString& rText) override;
631 virtual bool changed_by_direct_pick() const override;
633 void render_entry(int pos, int dpix, int dpiy);
636 class JSNotebook final : public JSWidget<SalInstanceNotebook, ::TabControl>
638 public:
639 JSNotebook(JSDialogSender* pSender, ::TabControl* pControl, SalInstanceBuilder* pBuilder,
640 bool bTakeOwnership);
642 virtual void remove_page(const OUString& rIdent) override;
643 virtual void insert_page(const OUString& rIdent, const OUString& rLabel, int nPos) override;
646 class JSVerticalNotebook final : public JSWidget<SalInstanceVerticalNotebook, ::VerticalTabControl>
648 public:
649 JSVerticalNotebook(JSDialogSender* pSender, ::VerticalTabControl* pControl,
650 SalInstanceBuilder* pBuilder, bool bTakeOwnership);
652 virtual void remove_page(const OUString& rIdent) override;
653 virtual void insert_page(const OUString& rIdent, const OUString& rLabel, int nPos) override;
656 class JSSpinButton final : public JSWidget<SalInstanceSpinButton, ::FormattedField>
658 public:
659 JSSpinButton(JSDialogSender* pSender, ::FormattedField* pSpin, SalInstanceBuilder* pBuilder,
660 bool bTakeOwnership);
662 virtual void set_value(sal_Int64 value) override;
663 virtual void set_range(sal_Int64 min, sal_Int64 max) override;
666 class JSFormattedSpinButton final
667 : public JSWidget<SalInstanceFormattedSpinButton, ::FormattedField>
669 public:
670 JSFormattedSpinButton(JSDialogSender* pSender, ::FormattedField* pSpin,
671 SalInstanceBuilder* pBuilder, bool bTakeOwnership);
673 virtual void set_text(const OUString& rText) override;
674 void set_text_without_notify(const OUString& rText);
677 class JSMessageDialog final : public JSWidget<SalInstanceMessageDialog, ::MessageDialog>
679 std::unique_ptr<JSDialogSender> m_pOwnedSender;
680 std::unique_ptr<JSButton> m_pOK;
681 std::unique_ptr<JSButton> m_pCancel;
683 // used for message dialogs created using static functions
684 OUString m_sWindowId;
686 DECL_LINK(OKHdl, weld::Button&, void);
687 DECL_LINK(CancelHdl, weld::Button&, void);
689 void RememberMessageDialog();
691 public:
692 JSMessageDialog(JSDialogSender* pSender, ::MessageDialog* pDialog, SalInstanceBuilder* pBuilder,
693 bool bTakeOwnership);
694 JSMessageDialog(::MessageDialog* pDialog, SalInstanceBuilder* pBuilder, bool bTakeOwnership);
695 virtual ~JSMessageDialog();
697 virtual void set_primary_text(const OUString& rText) override;
699 virtual void set_secondary_text(const OUString& rText) override;
701 virtual void response(int response) override;
703 virtual int run() override;
704 // TODO: move to dialog class so we will not send json when built but on run
705 bool runAsync(std::shared_ptr<weld::DialogController> aOwner,
706 const std::function<void(sal_Int32)>& rEndDialogFn) override;
708 bool runAsync(std::shared_ptr<Dialog> const& rxSelf,
709 const std::function<void(sal_Int32)>& rEndDialogFn) override;
712 class JSCheckButton final : public JSWidget<SalInstanceCheckButton, ::CheckBox>
714 public:
715 JSCheckButton(JSDialogSender* pSender, ::CheckBox* pCheckBox, SalInstanceBuilder* pBuilder,
716 bool bTakeOwnership);
718 virtual void set_active(bool active) override;
721 class JSDrawingArea final : public JSWidget<SalInstanceDrawingArea, VclDrawingArea>
723 public:
724 JSDrawingArea(JSDialogSender* pSender, VclDrawingArea* pDrawingArea,
725 SalInstanceBuilder* pBuilder, const a11yref& rAlly,
726 FactoryFunction pUITestFactoryFunction, void* pUserData);
728 virtual void queue_draw() override;
729 virtual void queue_draw_area(int x, int y, int width, int height) override;
732 class JSToolbar final : public JSWidget<SalInstanceToolbar, ::ToolBox>
734 std::map<sal_uInt16, weld::Widget*> m_pPopovers;
736 public:
737 JSToolbar(JSDialogSender* pSender, ::ToolBox* pToolbox, SalInstanceBuilder* pBuilder,
738 bool bTakeOwnership);
740 virtual void set_menu_item_active(const OUString& rIdent, bool bActive) override;
741 virtual void set_item_sensitive(const OUString& rIdent, bool bSensitive) override;
742 virtual void set_item_icon_name(const OUString& rIdent, const OUString& rIconName) override;
745 class JSTextView final : public JSWidget<SalInstanceTextView, ::VclMultiLineEdit>
747 public:
748 JSTextView(JSDialogSender* pSender, ::VclMultiLineEdit* pTextView, SalInstanceBuilder* pBuilder,
749 bool bTakeOwnership);
750 virtual void set_text(const OUString& rText) override;
751 void set_text_without_notify(const OUString& rText);
752 virtual void replace_selection(const OUString& rText) override;
755 class JSTreeView final : public JSWidget<SalInstanceTreeView, ::SvTabListBox>
757 public:
758 JSTreeView(JSDialogSender* pSender, ::SvTabListBox* pTextView, SalInstanceBuilder* pBuilder,
759 bool bTakeOwnership);
761 using SalInstanceTreeView::set_toggle;
762 /// pos is used differently here, it defines how many steps of iterator we need to perform to take entry
763 virtual void set_toggle(int pos, TriState eState, int col = -1) override;
764 virtual void set_toggle(const weld::TreeIter& rIter, TriState bOn, int col = -1) override;
766 using SalInstanceTreeView::select;
767 /// pos is used differently here, it defines how many steps of iterator we need to perform to take entry
768 virtual void select(int pos) override;
770 virtual weld::TreeView* get_drag_source() const override;
772 using SalInstanceTreeView::insert;
773 virtual void insert(const weld::TreeIter* pParent, int pos, const OUString* pStr,
774 const OUString* pId, const OUString* pIconName,
775 VirtualDevice* pImageSurface, bool bChildrenOnDemand,
776 weld::TreeIter* pRet) override;
778 virtual void set_text(int row, const OUString& rText, int col = -1) override;
779 virtual void set_text(const weld::TreeIter& rIter, const OUString& rStr, int col = -1) override;
781 virtual void expand_row(const weld::TreeIter& rIter) override;
782 virtual void collapse_row(const weld::TreeIter& rIter) override;
784 virtual void set_cursor(const weld::TreeIter& rIter) override;
785 void set_cursor_without_notify(const weld::TreeIter& rIter);
786 virtual void set_cursor(int pos) override;
788 using SalInstanceTreeView::remove;
789 virtual void remove(int pos) override;
790 virtual void remove(const weld::TreeIter& rIter) override;
792 virtual void clear() override;
794 void drag_start();
795 void drag_end();
798 class JSExpander final : public JSWidget<SalInstanceExpander, ::VclExpander>
800 public:
801 JSExpander(JSDialogSender* pSender, ::VclExpander* pExpander, SalInstanceBuilder* pBuilder,
802 bool bTakeOwnership);
804 virtual void set_expanded(bool bExpand) override;
807 class JSIconView final : public JSWidget<SalInstanceIconView, ::IconView>
809 public:
810 JSIconView(JSDialogSender* pSender, ::IconView* pIconView, SalInstanceBuilder* pBuilder,
811 bool bTakeOwnership);
813 virtual void insert(int pos, const OUString* pStr, const OUString* pId,
814 const OUString* pIconName, weld::TreeIter* pRet) override;
816 virtual void insert(int pos, const OUString* pStr, const OUString* pId,
817 const VirtualDevice* pIcon, weld::TreeIter* pRet) override;
819 virtual void insert_separator(int pos, const OUString* pId) override;
821 virtual void clear() override;
822 virtual void select(int pos) override;
823 virtual void unselect(int pos) override;
826 class JSRadioButton final : public JSWidget<SalInstanceRadioButton, ::RadioButton>
828 public:
829 JSRadioButton(JSDialogSender* pSender, ::RadioButton* pRadioButton,
830 SalInstanceBuilder* pBuilder, bool bTakeOwnership);
832 virtual void set_active(bool active) override;
835 class JSFrame : public JSWidget<SalInstanceFrame, ::VclFrame>
837 public:
838 JSFrame(JSDialogSender* pSender, ::VclFrame* pFrame, SalInstanceBuilder* pBuilder,
839 bool bTakeOwnership);
842 class JSMenuButton : public JSWidget<SalInstanceMenuButton, ::MenuButton>
844 public:
845 JSMenuButton(JSDialogSender* pSender, ::MenuButton* pMenuButton, SalInstanceBuilder* pBuilder,
846 bool bTakeOwnership);
848 virtual void set_label(const OUString& rText) override;
849 virtual void set_image(VirtualDevice* pDevice) override;
850 virtual void set_image(const css::uno::Reference<css::graphic::XGraphic>& rImage) override;
851 virtual void set_active(bool active) override;
854 class JSPopover : public JSWidget<SalInstancePopover, DockingWindow>
856 vcl::LOKWindowId mnWindowId;
858 public:
859 JSPopover(JSDialogSender* pSender, DockingWindow* pPopover, SalInstanceBuilder* pBuilder,
860 bool bTakeOwnership);
862 virtual void popup_at_rect(weld::Widget* pParent, const tools::Rectangle& rRect,
863 weld::Placement ePlace = weld::Placement::Under) override;
864 virtual void popdown() override;
866 void set_window_id(vcl::LOKWindowId nWindowId) { mnWindowId = nWindowId; }
869 class JSBox : public JSWidget<SalInstanceBox, VclBox>
871 public:
872 JSBox(JSDialogSender* pSender, VclBox* pBox, SalInstanceBuilder* pBuilder, bool bTakeOwnership);
874 void reorder_child(weld::Widget* pWidget, int nNewPosition) override;
877 class JSWidgetInstance : public JSWidget<SalInstanceWidget, vcl::Window>
879 public:
880 JSWidgetInstance(JSDialogSender* pSender, vcl::Window* pObject, SalInstanceBuilder* pBuilder,
881 bool bTakeOwnership)
882 : JSWidget<SalInstanceWidget, vcl::Window>(pSender, pObject, pBuilder, bTakeOwnership)
887 class JSImage : public JSWidget<SalInstanceImage, FixedImage>
889 public:
890 JSImage(JSDialogSender* pSender, FixedImage* pImage, SalInstanceBuilder* pBuilder,
891 bool bTakeOwnership);
892 virtual void set_image(VirtualDevice* pDevice) override;
893 virtual void set_image(const css::uno::Reference<css::graphic::XGraphic>& rImage) override;
896 class JSLevelBar : public JSWidget<SalInstanceLevelBar, ::ProgressBar>
898 public:
899 JSLevelBar(JSDialogSender* pSender, ::ProgressBar* pProgressBar, SalInstanceBuilder* pBuilder,
900 bool bTakeOwnership);
901 virtual void set_percentage(double fPercentage) override;
904 class JSCalendar : public JSWidget<SalInstanceCalendar, ::Calendar>
906 public:
907 JSCalendar(JSDialogSender* pSender, ::Calendar* pCalendar, SalInstanceBuilder* pBuilder,
908 bool bTakeOwnership);
911 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */