jsdialog: move executor code to vcl

Change-Id: I9247a652707fe3239dc488a605a2c506d8eec95c
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/97736
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Szymon Kłos <szymon.klos@collabora.com>
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/98819
Tested-by: Jenkins
This commit is contained in:
Szymon Kłos
2020-07-02 11:01:54 +02:00
parent 07ad277ce3
commit d41b79f105
7 changed files with 194 additions and 186 deletions

View File

@@ -151,7 +151,7 @@
#include <vcl/abstdlg.hxx>
#include <tools/diagnose_ex.h>
#include <vcl/uitest/uiobject.hxx>
#include <vcl/jsdialog/builder.hxx>
#include <vcl/jsdialog/executor.hxx>
// Needed for getUndoManager()
#include <com/sun/star/document/XUndoManager.hpp>
@@ -188,30 +188,6 @@ static void SetLastExceptionMsg(const OUString& s = OUString())
gImpl->maLastExceptionMsg = s;
}
class LOKTrigger
{
public:
static void trigger_changed(weld::Entry& rEdit)
{
rEdit.signal_changed();
}
static void trigger_changed(weld::ComboBox& rComboBox)
{
rComboBox.signal_changed();
}
static void trigger_clicked(weld::Toolbar& rToolbar, const OString& rIdent)
{
rToolbar.signal_clicked(rIdent);
}
static void trigger_click(weld::DrawingArea& rDrawingArea, const Point& rPos)
{
rDrawingArea.click(rPos);
}
};
namespace {
struct ExtensionMap
@@ -3653,137 +3629,11 @@ static void doc_sendDialogEvent(LibreOfficeKitDocument* /*pThis*/, unsigned long
try
{
OString sControlId = OUStringToOString(aMap["id"], RTL_TEXTENCODING_ASCII_US);
weld::Widget* pWidget = jsdialog::FindWeldWidgetsMap(nWindowId, sControlId);
if (!pWidget && nWindowId == 0)
{
pWidget = jsdialog::FindWeldWidgetsMap(reinterpret_cast<sal_uInt64>(SfxViewShell::Current()), sControlId);
}
bIsWeldedDialog = pWidget != nullptr;
bool bContinueWithLOKWindow = false;
if (bIsWeldedDialog)
{
OUString sControlType = aMap["type"];
OUString sAction = aMap["cmd"];
if (sControlType == "tabcontrol")
{
auto pNotebook = dynamic_cast<weld::Notebook*>(pWidget);
if (pNotebook)
{
if (sAction == "selecttab")
{
OString pageId = OUStringToOString(aMap["data"], RTL_TEXTENCODING_ASCII_US);
int page = std::atoi(pageId.getStr());
pNotebook->set_current_page(page);
}
else
bContinueWithLOKWindow = true;
}
}
else if (sControlType == "combobox")
{
auto pCombobox = dynamic_cast<weld::ComboBox*>(pWidget);
if (pCombobox)
{
if (sAction == "selected")
{
int separatorPos = aMap["data"].indexOf(';');
if (separatorPos)
{
OUString entryPos = aMap["data"].copy(0, separatorPos);
OString posString = OUStringToOString(entryPos, RTL_TEXTENCODING_ASCII_US);
int pos = std::atoi(posString.getStr());
pCombobox->set_active(pos);
LOKTrigger::trigger_changed(*pCombobox);
}
}
else if (sAction == "change")
{
pCombobox->set_entry_text(aMap["data"]);
LOKTrigger::trigger_changed(*pCombobox);
}
else
bContinueWithLOKWindow = true;
}
}
else if (sControlType == "pushbutton")
{
auto pButton = dynamic_cast<weld::Button*>(pWidget);
if (pButton)
{
if (sAction == "click")
{
pButton->clicked();
}
else
bContinueWithLOKWindow = true;
}
}
else if (sControlType == "drawingarea")
{
auto pArea = dynamic_cast<weld::DrawingArea*>(pWidget);
if (pArea)
{
if (sAction == "click")
{
LOKTrigger::trigger_click(*pArea, Point(10, 10));
}
else
bContinueWithLOKWindow = true;
}
}
else if (sControlType == "spinfield")
{
auto pSpinField = dynamic_cast<weld::SpinButton*>(pWidget);
if (pSpinField)
{
if (sAction == "plus")
{
pSpinField->set_value(pSpinField->get_value() + 1);
}
else if (sAction == "minus")
{
pSpinField->set_value(pSpinField->get_value() - 1);
}
else
bContinueWithLOKWindow = true;
}
}
else if (sControlType == "toolbox")
{
auto pToolbar = dynamic_cast<weld::Toolbar*>(pWidget);
if (pToolbar)
{
if (sAction == "click")
{
LOKTrigger::trigger_clicked(*pToolbar, OUStringToOString(aMap["data"], RTL_TEXTENCODING_ASCII_US));
}
else
bContinueWithLOKWindow = true;
}
}
else if (sControlType == "edit")
{
auto pEdit = dynamic_cast<weld::Entry*>(pWidget);
if (pEdit)
{
if (sAction == "change")
{
pEdit->set_text(aMap["data"]);
LOKTrigger::trigger_changed(*pEdit);
}
else
bContinueWithLOKWindow = true;
}
}
else
{
bContinueWithLOKWindow = true;
}
}
bIsWeldedDialog = jsdialog::ExecuteAction(nWindowId, sControlId, aMap);
if (!bIsWeldedDialog)
bIsWeldedDialog = jsdialog::ExecuteAction(reinterpret_cast<sal_uInt64>(SfxViewShell::Current()),
sControlId, aMap);
if (!pWindow)
{
@@ -3791,7 +3641,7 @@ static void doc_sendDialogEvent(LibreOfficeKitDocument* /*pThis*/, unsigned long
return;
}
if (!bIsWeldedDialog || bContinueWithLOKWindow)
if (!bIsWeldedDialog)
{
WindowUIObject aUIObject(pWindow);
std::unique_ptr<UIObject> pUIWindow(aUIObject.get_child(aMap["id"]));

View File

@@ -1,21 +0,0 @@
/* -*- 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 <vcl/dllapi.h>
#include <vcl/IDialogRenderable.hxx>
#include <vcl/weld.hxx>
namespace jsdialog
{
VCL_DLLPUBLIC weld::Widget* FindWeldWidgetsMap(sal_uInt64 nWindowId, const OString& rWidget);
};
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */

View File

@@ -0,0 +1,39 @@
/* -*- 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 <vcl/dllapi.h>
#include <vcl/uitest/uiobject.hxx>
#include <vcl/weld.hxx>
class LOKTrigger
{
public:
static void trigger_changed(weld::Entry& rEdit) { rEdit.signal_changed(); }
static void trigger_changed(weld::ComboBox& rComboBox) { rComboBox.signal_changed(); }
static void trigger_clicked(weld::Toolbar& rToolbar, const OString& rIdent)
{
rToolbar.signal_clicked(rIdent);
}
static void trigger_click(weld::DrawingArea& rDrawingArea, const Point& rPos)
{
rDrawingArea.click(rPos);
}
};
namespace jsdialog
{
VCL_DLLPUBLIC bool ExecuteAction(sal_uInt64 nWindowId, const OString& rWidget, StringMap& rData);
};
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */

View File

@@ -479,6 +479,7 @@ $(eval $(call gb_Library_add_exception_objects,vcl,\
vcl/backendtest/outputdevice/polyline_b2d \
vcl/backendtest/outputdevice/rectangle \
vcl/jsdialog/jsdialogbuilder \
vcl/jsdialog/executor \
))
$(eval $(call gb_Library_add_cobjects,vcl,\

View File

@@ -9,8 +9,8 @@
#pragma once
#include <vcl/jsdialog/builder.hxx>
#include <vcl/weld.hxx>
#include <vcl/jsdialog/executor.hxx>
#include <comphelper/string.hxx>
#include <vcl/sysdata.hxx>
#include <vcl/virdev.hxx>
@@ -55,12 +55,13 @@ class JSInstanceBuilder : public SalInstanceBuilder
bool m_bHasTopLevelDialog;
bool m_bIsNotebookbar;
friend VCL_DLLPUBLIC weld::Widget* jsdialog::FindWeldWidgetsMap(sal_uInt64 nWindowId,
const OString& rWidget);
friend VCL_DLLPUBLIC bool jsdialog::ExecuteAction(sal_uInt64 nWindowId, const OString& rWidget,
StringMap& rData);
static std::map<sal_uInt64, WidgetMap>& 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);
public:
JSInstanceBuilder(weld::Widget* pParent, const OUString& rUIRoot, const OUString& rUIFile);

141
vcl/jsdialog/executor.cxx Normal file
View File

@@ -0,0 +1,141 @@
/* -*- 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/.
*/
#include <jsdialog/jsdialogbuilder.hxx>
#include <vcl/weld.hxx>
#include <vcl/jsdialog/executor.hxx>
#include <sal/log.hxx>
namespace jsdialog
{
bool ExecuteAction(sal_uInt64 nWindowId, const OString& rWidget, StringMap& rData)
{
weld::Widget* pWidget = JSInstanceBuilder::FindWeldWidgetsMap(nWindowId, rWidget);
if (pWidget != nullptr)
{
OUString sControlType = rData["type"];
OUString sAction = rData["cmd"];
if (sControlType == "tabcontrol")
{
auto pNotebook = dynamic_cast<weld::Notebook*>(pWidget);
if (pNotebook)
{
if (sAction == "selecttab")
{
OString pageId = OUStringToOString(rData["data"], RTL_TEXTENCODING_ASCII_US);
int page = std::atoi(pageId.getStr());
pNotebook->set_current_page(page);
return true;
}
}
}
else if (sControlType == "combobox")
{
auto pCombobox = dynamic_cast<weld::ComboBox*>(pWidget);
if (pCombobox)
{
if (sAction == "selected")
{
int separatorPos = rData["data"].indexOf(';');
if (separatorPos)
{
OUString entryPos = rData["data"].copy(0, separatorPos);
OString posString = OUStringToOString(entryPos, RTL_TEXTENCODING_ASCII_US);
int pos = std::atoi(posString.getStr());
pCombobox->set_active(pos);
LOKTrigger::trigger_changed(*pCombobox);
return true;
}
}
else if (sAction == "change")
{
pCombobox->set_entry_text(rData["data"]);
LOKTrigger::trigger_changed(*pCombobox);
return true;
}
}
}
else if (sControlType == "pushbutton")
{
auto pButton = dynamic_cast<weld::Button*>(pWidget);
if (pButton)
{
if (sAction == "click")
{
pButton->clicked();
return true;
}
}
}
else if (sControlType == "drawingarea")
{
auto pArea = dynamic_cast<weld::DrawingArea*>(pWidget);
if (pArea)
{
if (sAction == "click")
{
LOKTrigger::trigger_click(*pArea, Point(10, 10));
return true;
}
}
}
else if (sControlType == "spinfield")
{
auto pSpinField = dynamic_cast<weld::SpinButton*>(pWidget);
if (pSpinField)
{
if (sAction == "plus")
{
pSpinField->set_value(pSpinField->get_value() + 1);
return true;
}
else if (sAction == "minus")
{
pSpinField->set_value(pSpinField->get_value() - 1);
return true;
}
}
}
else if (sControlType == "toolbox")
{
auto pToolbar = dynamic_cast<weld::Toolbar*>(pWidget);
if (pToolbar)
{
if (sAction == "click")
{
LOKTrigger::trigger_clicked(
*pToolbar, OUStringToOString(rData["data"], RTL_TEXTENCODING_ASCII_US));
return true;
}
}
}
else if (sControlType == "edit")
{
auto pEdit = dynamic_cast<weld::Entry*>(pWidget);
if (pEdit)
{
if (sAction == "change")
{
pEdit->set_text(rData["data"]);
LOKTrigger::trigger_changed(*pEdit);
return true;
}
}
}
}
return false;
}
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */

View File

@@ -124,13 +124,11 @@ std::map<sal_uInt64, WidgetMap>& JSInstanceBuilder::GetLOKWeldWidgetsMap()
return s_aLOKWeldBuildersMap;
}
namespace jsdialog
weld::Widget* JSInstanceBuilder::FindWeldWidgetsMap(sal_uInt64 nWindowId, const OString& rWidget)
{
weld::Widget* FindWeldWidgetsMap(sal_uInt64 nWindowId, const OString& rWidget)
{
const auto it = JSInstanceBuilder::GetLOKWeldWidgetsMap().find(nWindowId);
const auto it = GetLOKWeldWidgetsMap().find(nWindowId);
if (it != JSInstanceBuilder::GetLOKWeldWidgetsMap().end())
if (it != GetLOKWeldWidgetsMap().end())
{
auto widgetIt = it->second.find(rWidget);
if (widgetIt != it->second.end())
@@ -139,7 +137,6 @@ weld::Widget* FindWeldWidgetsMap(sal_uInt64 nWindowId, const OString& rWidget)
return nullptr;
}
}
void JSInstanceBuilder::InsertWindowToMap(sal_uInt64 nWindowId)
{