nss: upgrade to release 3.73
[LibreOffice.git] / vcl / jsdialog / executor.cxx
blob53fded14e1c11c0a30875e53456c1e529fd37783
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 #include <jsdialog/jsdialogbuilder.hxx>
11 #include <vcl/weld.hxx>
12 #include <vcl/jsdialog/executor.hxx>
13 #include <sal/log.hxx>
15 namespace jsdialog
17 bool ExecuteAction(sal_uInt64 nWindowId, const OString& rWidget, StringMap& rData)
19 weld::Widget* pWidget = JSInstanceBuilder::FindWeldWidgetsMap(nWindowId, rWidget);
21 if (pWidget != nullptr)
23 OUString sControlType = rData["type"];
24 OUString sAction = rData["cmd"];
26 if (sControlType == "tabcontrol")
28 auto pNotebook = dynamic_cast<weld::Notebook*>(pWidget);
29 if (pNotebook)
31 if (sAction == "selecttab")
33 OString pageId = OUStringToOString(rData["data"], RTL_TEXTENCODING_ASCII_US);
34 int page = std::atoi(pageId.getStr());
36 pNotebook->set_current_page(page);
38 return true;
42 else if (sControlType == "combobox")
44 auto pCombobox = dynamic_cast<weld::ComboBox*>(pWidget);
45 if (pCombobox)
47 if (sAction == "selected")
49 int separatorPos = rData["data"].indexOf(';');
50 if (separatorPos)
52 OUString entryPos = rData["data"].copy(0, separatorPos);
53 OString posString = OUStringToOString(entryPos, RTL_TEXTENCODING_ASCII_US);
54 int pos = std::atoi(posString.getStr());
55 pCombobox->set_active(pos);
56 LOKTrigger::trigger_changed(*pCombobox);
57 return true;
60 else if (sAction == "change")
62 pCombobox->set_entry_text(rData["data"]);
63 LOKTrigger::trigger_changed(*pCombobox);
64 return true;
68 else if (sControlType == "pushbutton")
70 auto pButton = dynamic_cast<weld::Button*>(pWidget);
71 if (pButton)
73 if (sAction == "click")
75 pButton->clicked();
76 return true;
80 else if (sControlType == "drawingarea")
82 auto pArea = dynamic_cast<weld::DrawingArea*>(pWidget);
83 if (pArea)
85 if (sAction == "click")
87 LOKTrigger::trigger_click(*pArea, Point(10, 10));
88 return true;
92 else if (sControlType == "spinfield")
94 auto pSpinField = dynamic_cast<weld::SpinButton*>(pWidget);
95 if (pSpinField)
97 if (sAction == "plus")
99 pSpinField->set_value(pSpinField->get_value() + 1);
100 return true;
102 else if (sAction == "minus")
104 pSpinField->set_value(pSpinField->get_value() - 1);
105 return true;
109 else if (sControlType == "toolbox")
111 auto pToolbar = dynamic_cast<weld::Toolbar*>(pWidget);
112 if (pToolbar)
114 if (sAction == "click")
116 LOKTrigger::trigger_clicked(
117 *pToolbar, OUStringToOString(rData["data"], RTL_TEXTENCODING_ASCII_US));
118 return true;
122 else if (sControlType == "edit")
124 auto pEdit = dynamic_cast<weld::Entry*>(pWidget);
125 if (pEdit)
127 if (sAction == "change")
129 pEdit->set_text(rData["data"]);
130 LOKTrigger::trigger_changed(*pEdit);
131 return true;
135 auto pTextView = dynamic_cast<weld::TextView*>(pWidget);
136 if (pTextView)
138 if (sAction == "change")
140 pTextView->set_text(rData["data"]);
141 LOKTrigger::trigger_changed(*pTextView);
142 return true;
148 return false;
152 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */