/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #pragma once #include #include #include #include #include #include #include #include #include #include #include #include #include class ToolBox; class ComboBox; class VclMultiLineEdit; class SvTabListBox; class IconView; typedef std::map WidgetMap; class JSDialogNotifyIdle : public Idle { // used to send message VclPtr m_aNotifierWindow; // used to generate JSON VclPtr m_aContentWindow; std::string m_sTypeOfJSON; std::string m_LastNotificationMessage; bool m_bForce; public: JSDialogNotifyIdle(VclPtr aNotifierWindow, VclPtr aContentWindow, std::string sTypeOfJSON); void Invoke() override; void ForceUpdate(); void sendClose(); VclPtr getNotifierWindow() { return m_aNotifierWindow; } void updateStatus(VclPtr pWindow); private: void send(tools::JsonWriter& aJsonWriter); std::unique_ptr dumpStatus() const; std::unique_ptr generateCloseMessage() const; }; class JSDialogSender { std::unique_ptr mpIdleNotify; public: JSDialogSender() = default; JSDialogSender(VclPtr aNotifierWindow, VclPtr aContentWindow, std::string sTypeOfJSON) { initializeSender(aNotifierWindow, aContentWindow, sTypeOfJSON); } virtual ~JSDialogSender() = default; virtual void notifyDialogState(bool bForce = false); void sendClose(); virtual void sendUpdate(VclPtr pWindow); protected: void initializeSender(VclPtr aNotifierWindow, VclPtr aContentWindow, std::string sTypeOfJSON) { mpIdleNotify.reset(new JSDialogNotifyIdle(aNotifierWindow, aContentWindow, sTypeOfJSON)); } }; class JSDropTarget final : public cppu::WeakComponentImplHelper { osl::Mutex m_aMutex; std::vector> m_aListeners; public: JSDropTarget(); // XInitialization virtual void SAL_CALL initialize(const css::uno::Sequence& rArgs) override; // XDropTarget virtual void SAL_CALL addDropTargetListener( const css::uno::Reference&) override; virtual void SAL_CALL removeDropTargetListener( const css::uno::Reference&) override; virtual sal_Bool SAL_CALL isActive() override; virtual void SAL_CALL setActive(sal_Bool active) override; virtual sal_Int8 SAL_CALL getDefaultActions() override; virtual void SAL_CALL setDefaultActions(sal_Int8 actions) override; OUString SAL_CALL getImplementationName() override; sal_Bool SAL_CALL supportsService(OUString const& ServiceName) override; css::uno::Sequence SAL_CALL getSupportedServiceNames() override; void fire_drop(const css::datatransfer::dnd::DropTargetDropEvent& dtde); void fire_dragEnter(const css::datatransfer::dnd::DropTargetDragEnterEvent& dtde); }; class JSInstanceBuilder : public SalInstanceBuilder, public JSDialogSender { sal_uInt64 m_nWindowId; /// used in case of tab pages where dialog is not a direct top level VclPtr m_aParentDialog; VclPtr m_aContentWindow; std::list m_aRememberedWidgets; std::string m_sTypeOfJSON; bool m_bHasTopLevelDialog; bool m_bIsNotebookbar; friend VCL_DLLPUBLIC bool jsdialog::ExecuteAction(sal_uInt64 nWindowId, const OString& rWidget, StringMap& rData); static std::map& GetLOKWeldWidgetsMap(); static void InsertWindowToMap(sal_uInt64 nWindowId); void RememberWidget(const OString& id, weld::Widget* pWidget); static weld::Widget* FindWeldWidgetsMap(sal_uInt64 nWindowId, const OString& rWidget); /// used for dialogs JSInstanceBuilder(weld::Widget* pParent, const OUString& rUIRoot, const OUString& rUIFile); /// used for notebookbar, optional nWindowId is used if getting parent id failed JSInstanceBuilder(vcl::Window* pParent, const OUString& rUIRoot, const OUString& rUIFile, const css::uno::Reference& rFrame, sal_uInt64 nWindowId = 0); /// for autofilter dropdown JSInstanceBuilder(vcl::Window* pParent, const OUString& rUIRoot, const OUString& rUIFile); public: static JSInstanceBuilder* CreateDialogBuilder(weld::Widget* pParent, const OUString& rUIRoot, const OUString& rUIFile); static JSInstanceBuilder* CreateNotebookbarBuilder(vcl::Window* pParent, const OUString& rUIRoot, const OUString& rUIFile, const css::uno::Reference& rFrame, sal_uInt64 nWindowId = 0); static JSInstanceBuilder* CreateAutofilterWindowBuilder(vcl::Window* pParent, const OUString& rUIRoot, const OUString& rUIFile); virtual ~JSInstanceBuilder() override; virtual std::unique_ptr weld_message_dialog(const OString& id) override; virtual std::unique_ptr weld_dialog(const OString& id) override; virtual std::unique_ptr weld_label(const OString& id) override; virtual std::unique_ptr weld_button(const OString& id) override; virtual std::unique_ptr weld_entry(const OString& id) override; virtual std::unique_ptr weld_combo_box(const OString& id) override; virtual std::unique_ptr weld_notebook(const OString& id) override; virtual std::unique_ptr weld_spin_button(const OString& id) override; virtual std::unique_ptr weld_check_button(const OString& id) override; virtual std::unique_ptr weld_drawing_area(const OString& id, const a11yref& rA11yImpl = nullptr, FactoryFunction pUITestFactoryFunction = nullptr, void* pUserData = nullptr) override; virtual std::unique_ptr weld_toolbar(const OString& id) override; virtual std::unique_ptr weld_text_view(const OString& id) override; virtual std::unique_ptr weld_tree_view(const OString& id) override; virtual std::unique_ptr weld_expander(const OString& id) override; virtual std::unique_ptr weld_icon_view(const OString& id) override; static weld::MessageDialog* CreateMessageDialog(weld::Widget* pParent, VclMessageType eMessageType, VclButtonsType eButtonType, const OUString& rPrimaryMessage); private: const std::string& GetTypeOfJSON(); VclPtr& GetContentWindow(); VclPtr& GetNotifierWindow(); }; template class JSWidget : public BaseInstanceClass { protected: rtl::Reference m_xDropTarget; bool m_bIsFreezed; JSDialogSender* m_pSender; public: JSWidget(JSDialogSender* pSender, VclClass* pObject, SalInstanceBuilder* pBuilder, bool bTakeOwnership) : BaseInstanceClass(pObject, pBuilder, bTakeOwnership) , m_bIsFreezed(false) , m_pSender(pSender) { } JSWidget(JSDialogSender* pSender, VclClass* pObject, SalInstanceBuilder* pBuilder, const a11yref& rAlly, FactoryFunction pUITestFactoryFunction, void* pUserData, bool bTakeOwnership) : BaseInstanceClass(pObject, pBuilder, rAlly, pUITestFactoryFunction, pUserData, bTakeOwnership) , m_bIsFreezed(false) , m_pSender(pSender) { } virtual void show() override { BaseInstanceClass::show(); notifyDialogState(); } virtual void hide() override { BaseInstanceClass::hide(); notifyDialogState(); } using BaseInstanceClass::set_sensitive; virtual void set_sensitive(bool sensitive) override { BaseInstanceClass::set_sensitive(sensitive); notifyDialogState(); } virtual css::uno::Reference get_drop_target() override { if (!m_xDropTarget) m_xDropTarget.set(new JSDropTarget); return m_xDropTarget.get(); } virtual void freeze() override { BaseInstanceClass::freeze(); m_bIsFreezed = true; } virtual void thaw() override { BaseInstanceClass::thaw(); m_bIsFreezed = false; } void sendClose() { if (m_pSender) m_pSender->sendClose(); } void sendUpdate(VclPtr pWindow) { if (!m_bIsFreezed && m_pSender) m_pSender->sendUpdate(pWindow); } void notifyDialogState(bool bForce = false) { if ((!m_bIsFreezed || bForce) && m_pSender) m_pSender->notifyDialogState(bForce); } }; class JSDialog : public JSWidget { public: JSDialog(JSDialogSender* pSender, ::Dialog* pDialog, SalInstanceBuilder* pBuilder, bool bTakeOwnership); virtual void collapse(weld::Widget* pEdit, weld::Widget* pButton) override; virtual void undo_collapse() override; virtual void response(int response) override; }; class JSLabel : public JSWidget { public: JSLabel(JSDialogSender* pSender, FixedText* pLabel, SalInstanceBuilder* pBuilder, bool bTakeOwnership); virtual void set_label(const OUString& rText) override; }; class JSButton : public JSWidget { public: JSButton(JSDialogSender* pSender, ::Button* pButton, SalInstanceBuilder* pBuilder, bool bTakeOwnership); }; class JSEntry : public JSWidget { public: JSEntry(JSDialogSender* pSender, ::Edit* pEntry, SalInstanceBuilder* pBuilder, bool bTakeOwnership); virtual void set_text(const OUString& rText) override; }; class JSListBox : public JSWidget { public: JSListBox(JSDialogSender* pSender, ::ListBox* pListBox, SalInstanceBuilder* pBuilder, bool bTakeOwnership); virtual void insert(int pos, const OUString& rStr, const OUString* pId, const OUString* pIconName, VirtualDevice* pImageSurface) override; virtual void remove(int pos) override; virtual void set_active(int pos) override; }; class JSComboBox : public JSWidget { public: JSComboBox(JSDialogSender* pSender, ::ComboBox* pComboBox, SalInstanceBuilder* pBuilder, bool bTakeOwnership); virtual void insert(int pos, const OUString& rStr, const OUString* pId, const OUString* pIconName, VirtualDevice* pImageSurface) override; virtual void remove(int pos) override; virtual void set_entry_text(const OUString& rText) override; virtual void set_active(int pos) override; }; class JSNotebook : public JSWidget { public: JSNotebook(JSDialogSender* pSender, ::TabControl* pControl, SalInstanceBuilder* pBuilder, bool bTakeOwnership); virtual void set_current_page(int nPage) override; virtual void set_current_page(const OString& rIdent) override; virtual void remove_page(const OString& rIdent) override; virtual void insert_page(const OString& rIdent, const OUString& rLabel, int nPos) override; }; class JSSpinButton : public JSWidget { public: JSSpinButton(JSDialogSender* pSender, ::FormattedField* pSpin, SalInstanceBuilder* pBuilder, bool bTakeOwnership); virtual void set_value(int value) override; }; class JSMessageDialog : public JSWidget { std::unique_ptr m_pOwnedSender; public: JSMessageDialog(JSDialogSender* pSender, ::MessageDialog* pDialog, SalInstanceBuilder* pBuilder, bool bTakeOwnership); JSMessageDialog(::MessageDialog* pDialog, SalInstanceBuilder* pBuilder, bool bTakeOwnership); virtual void set_primary_text(const OUString& rText) override; virtual void set_secondary_text(const OUString& rText) override; }; class JSCheckButton : public JSWidget { public: JSCheckButton(JSDialogSender* pSender, ::CheckBox* pCheckBox, SalInstanceBuilder* pBuilder, bool bTakeOwnership); virtual void set_active(bool active) override; }; class JSDrawingArea : public JSWidget { public: JSDrawingArea(JSDialogSender* pSender, VclDrawingArea* pDrawingArea, SalInstanceBuilder* pBuilder, const a11yref& rAlly, FactoryFunction pUITestFactoryFunction, void* pUserData); virtual void queue_draw() override; virtual void queue_draw_area(int x, int y, int width, int height) override; }; class JSToolbar : public JSWidget { public: JSToolbar(JSDialogSender* pSender, ::ToolBox* pToolbox, SalInstanceBuilder* pBuilder, bool bTakeOwnership); virtual void signal_clicked(const OString& rIdent) override; }; class JSTextView : public JSWidget { public: JSTextView(JSDialogSender* pSender, ::VclMultiLineEdit* pTextView, SalInstanceBuilder* pBuilder, bool bTakeOwnership); virtual void set_text(const OUString& rText) override; }; class JSTreeView : public JSWidget { public: JSTreeView(JSDialogSender* pSender, ::SvTabListBox* pTextView, SalInstanceBuilder* pBuilder, bool bTakeOwnership); using SalInstanceTreeView::set_toggle; /// pos is used differently here, it defines how many steps of iterator we need to perform to take entry virtual void set_toggle(int pos, TriState eState, int col = -1) override; using SalInstanceTreeView::select; /// pos is used differently here, it defines how many steps of iterator we need to perform to take entry virtual void select(int pos) override; virtual weld::TreeView* get_drag_source() const override; using SalInstanceTreeView::insert; virtual void insert(const weld::TreeIter* pParent, int pos, const OUString* pStr, const OUString* pId, const OUString* pIconName, VirtualDevice* pImageSurface, bool bChildrenOnDemand, weld::TreeIter* pRet) override; virtual void set_text(int row, const OUString& rText, int col = -1) override; virtual void set_text(const weld::TreeIter& rIter, const OUString& rStr, int col = -1) override; virtual void expand_row(const weld::TreeIter& rIter) override; virtual void collapse_row(const weld::TreeIter& rIter) override; void drag_start(); void drag_end(); }; class JSExpander : public JSWidget { public: JSExpander(JSDialogSender* pSender, ::VclExpander* pExpander, SalInstanceBuilder* pBuilder, bool bTakeOwnership); virtual void set_expanded(bool bExpand) override; }; class JSIconView : public JSWidget { public: JSIconView(JSDialogSender* pSender, ::IconView* pIconView, SalInstanceBuilder* pBuilder, bool bTakeOwnership); virtual void insert(int pos, const OUString* pStr, const OUString* pId, const OUString* pIconName, weld::TreeIter* pRet) override; virtual void insert(int pos, const OUString* pStr, const OUString* pId, const VirtualDevice* pIcon, weld::TreeIter* pRet) override; virtual void clear() override; virtual void select(int pos) override; virtual void unselect(int pos) override; }; /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */