1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
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/.
10 #include <jsdialog/jsdialogbuilder.hxx>
11 #include <vcl/weld.hxx>
12 #include <vcl/jsdialog/executor.hxx>
13 #include <sal/log.hxx>
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
);
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
);
42 else if (sControlType
== "combobox")
44 auto pCombobox
= dynamic_cast<weld::ComboBox
*>(pWidget
);
47 if (sAction
== "selected")
49 int separatorPos
= rData
["data"].indexOf(';');
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
);
60 else if (sAction
== "change")
62 pCombobox
->set_entry_text(rData
["data"]);
63 LOKTrigger::trigger_changed(*pCombobox
);
68 else if (sControlType
== "pushbutton")
70 auto pButton
= dynamic_cast<weld::Button
*>(pWidget
);
73 if (sAction
== "click")
80 else if (sControlType
== "drawingarea")
82 auto pArea
= dynamic_cast<weld::DrawingArea
*>(pWidget
);
85 if (sAction
== "click")
87 LOKTrigger::trigger_click(*pArea
, Point(10, 10));
92 else if (sControlType
== "spinfield")
94 auto pSpinField
= dynamic_cast<weld::SpinButton
*>(pWidget
);
97 if (sAction
== "plus")
99 pSpinField
->set_value(pSpinField
->get_value() + 1);
102 else if (sAction
== "minus")
104 pSpinField
->set_value(pSpinField
->get_value() - 1);
109 else if (sControlType
== "toolbox")
111 auto pToolbar
= dynamic_cast<weld::Toolbar
*>(pWidget
);
114 if (sAction
== "click")
116 LOKTrigger::trigger_clicked(
117 *pToolbar
, OUStringToOString(rData
["data"], RTL_TEXTENCODING_ASCII_US
));
122 else if (sControlType
== "edit")
124 auto pEdit
= dynamic_cast<weld::Entry
*>(pWidget
);
127 if (sAction
== "change")
129 pEdit
->set_text(rData
["data"]);
130 LOKTrigger::trigger_changed(*pEdit
);
135 auto pTextView
= dynamic_cast<weld::TextView
*>(pWidget
);
138 if (sAction
== "change")
140 pTextView
->set_text(rData
["data"]);
141 LOKTrigger::trigger_changed(*pTextView
);
152 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */