1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
|
#include <jsdialog/jsdialogbuilder.hxx>
#include <sal/log.hxx>
#include <boost/property_tree/json_parser.hpp>
#include <comphelper/lok.hxx>
#include <vcl/tabpage.hxx>
#include <vcl/toolkit/dialog.hxx>
#include <LibreOfficeKit/LibreOfficeKitEnums.h>
void JSDialogSender::notifyDialogState()
{
if (!m_aOwnedToplevel)
return;
const vcl::ILibreOfficeKitNotifier* pNotifier = m_aOwnedToplevel->GetLOKNotifier();
if (pNotifier)
{
std::stringstream aStream;
boost::property_tree::ptree aTree = m_aOwnedToplevel->DumpAsPropertyTree();
aTree.put("id", m_aOwnedToplevel->GetLOKWindowId());
boost::property_tree::write_json(aStream, aTree);
const std::string message = aStream.str();
pNotifier->libreOfficeKitViewCallback(LOK_CALLBACK_JSDIALOG, message.c_str());
}
}
JSInstanceBuilder::JSInstanceBuilder(weld::Widget* pParent, const OUString& rUIRoot,
const OUString& rUIFile)
: SalInstanceBuilder(dynamic_cast<SalInstanceWidget*>(pParent)
? dynamic_cast<SalInstanceWidget*>(pParent)->getWidget()
: nullptr,
rUIRoot, rUIFile)
{
}
std::unique_ptr<weld::Dialog> JSInstanceBuilder::weld_dialog(const OString& id, bool bTakeOwnership)
{
::Dialog* pDialog = m_xBuilder->get<::Dialog>(id);
std::unique_ptr<weld::Dialog> pRet(pDialog ? new SalInstanceDialog(pDialog, this, false)
: nullptr);
if (bTakeOwnership && pDialog)
{
assert(!m_aOwnedToplevel && "only one toplevel per .ui allowed");
m_aOwnedToplevel.set(pDialog);
m_xBuilder->drop_ownership(pDialog);
}
const vcl::ILibreOfficeKitNotifier* pNotifier = pDialog->GetLOKNotifier();
if (pNotifier)
{
std::stringstream aStream;
boost::property_tree::ptree aTree = m_aOwnedToplevel->DumpAsPropertyTree();
aTree.put("id", m_aOwnedToplevel->GetLOKWindowId());
boost::property_tree::write_json(aStream, aTree);
const std::string message = aStream.str();
pNotifier->libreOfficeKitViewCallback(LOK_CALLBACK_JSDIALOG, message.c_str());
}
return pRet;
}
std::unique_ptr<weld::Label> JSInstanceBuilder::weld_label(const OString& id, bool bTakeOwnership)
{
::FixedText* pLabel = m_xBuilder->get<FixedText>(id);
return std::make_unique<JSLabel>(m_aOwnedToplevel, pLabel, this, bTakeOwnership);
}
std::unique_ptr<weld::Button> JSInstanceBuilder::weld_button(const OString& id, bool bTakeOwnership)
{
::Button* pButton = m_xBuilder->get<::Button>(id);
return pButton ? std::make_unique<JSButton>(m_aOwnedToplevel, pButton, this, bTakeOwnership)
: nullptr;
}
std::unique_ptr<weld::Entry> JSInstanceBuilder::weld_entry(const OString& id, bool bTakeOwnership)
{
Edit* pEntry = m_xBuilder->get<Edit>(id);
return pEntry ? std::make_unique<JSEntry>(m_aOwnedToplevel, pEntry, this, bTakeOwnership)
: nullptr;
}
std::unique_ptr<weld::ComboBox> JSInstanceBuilder::weld_combo_box(const OString& id,
bool bTakeOwnership)
{
vcl::Window* pWidget = m_xBuilder->get<vcl::Window>(id);
::ComboBox* pComboBox = dynamic_cast<::ComboBox*>(pWidget);
if (pComboBox)
return std::make_unique<JSComboBox>(m_aOwnedToplevel, pComboBox, this, bTakeOwnership);
ListBox* pListBox = dynamic_cast<ListBox*>(pWidget);
return pListBox ? std::make_unique<JSListBox>(m_aOwnedToplevel, pListBox, this, bTakeOwnership)
: nullptr;
}
std::unique_ptr<weld::Notebook> JSInstanceBuilder::weld_notebook(const OString& id,
bool bTakeOwnership)
{
TabControl* pNotebook = m_xBuilder->get<TabControl>(id);
return pNotebook
? std::make_unique<JSNotebook>(m_aOwnedToplevel, pNotebook, this, bTakeOwnership)
: nullptr;
}
JSLabel::JSLabel(VclPtr<vcl::Window> aOwnedToplevel, FixedText* pLabel,
SalInstanceBuilder* pBuilder, bool bTakeOwnership)
: JSWidget<SalInstanceLabel, FixedText>(aOwnedToplevel, pLabel, pBuilder, bTakeOwnership)
{
}
void JSLabel::set_label(const OUString& rText)
{
SalInstanceLabel::set_label(rText);
notifyDialogState();
};
JSButton::JSButton(VclPtr<vcl::Window> aOwnedToplevel, ::Button* pButton,
SalInstanceBuilder* pBuilder, bool bTakeOwnership)
: JSWidget<SalInstanceButton, ::Button>(aOwnedToplevel, pButton, pBuilder, bTakeOwnership)
{
}
JSEntry::JSEntry(VclPtr<vcl::Window> aOwnedToplevel, ::Edit* pEntry, SalInstanceBuilder* pBuilder,
bool bTakeOwnership)
: JSWidget<SalInstanceEntry, ::Edit>(aOwnedToplevel, pEntry, pBuilder, bTakeOwnership)
{
}
void JSEntry::set_text(const OUString& rText)
{
SalInstanceEntry::set_text(rText);
notifyDialogState();
}
JSListBox::JSListBox(VclPtr<vcl::Window> aOwnedToplevel, ::ListBox* pListBox,
SalInstanceBuilder* pBuilder, bool bTakeOwnership)
: JSWidget<SalInstanceComboBoxWithoutEdit, ::ListBox>(aOwnedToplevel, pListBox, pBuilder,
bTakeOwnership)
{
}
void JSListBox::insert(int pos, const OUString& rStr, const OUString* pId,
const OUString* pIconName, VirtualDevice* pImageSurface)
{
SalInstanceComboBoxWithoutEdit::insert(pos, rStr, pId, pIconName, pImageSurface);
notifyDialogState();
}
void JSListBox::remove(int pos)
{
SalInstanceComboBoxWithoutEdit::remove(pos);
notifyDialogState();
}
JSComboBox::JSComboBox(VclPtr<vcl::Window> aOwnedToplevel, ::ComboBox* pComboBox,
SalInstanceBuilder* pBuilder, bool bTakeOwnership)
: JSWidget<SalInstanceComboBoxWithEdit, ::ComboBox>(aOwnedToplevel, pComboBox, pBuilder,
bTakeOwnership)
{
}
void JSComboBox::insert(int pos, const OUString& rStr, const OUString* pId,
const OUString* pIconName, VirtualDevice* pImageSurface)
{
SalInstanceComboBoxWithEdit::insert(pos, rStr, pId, pIconName, pImageSurface);
notifyDialogState();
}
void JSComboBox::remove(int pos)
{
SalInstanceComboBoxWithEdit::remove(pos);
notifyDialogState();
}
void JSComboBox::set_entry_text(const OUString& rText)
{
SalInstanceComboBoxWithEdit::set_entry_text(rText);
notifyDialogState();
}
JSNotebook::JSNotebook(VclPtr<vcl::Window> aOwnedToplevel, ::TabControl* pControl,
SalInstanceBuilder* pBuilder, bool bTakeOwnership)
: JSWidget<SalInstanceNotebook, ::TabControl>(aOwnedToplevel, pControl, pBuilder,
bTakeOwnership)
{
}
void JSNotebook::set_current_page(int nPage)
{
SalInstanceNotebook::set_current_page(nPage);
notifyDialogState();
}
void JSNotebook::set_current_page(const OString& rIdent)
{
SalInstanceNotebook::set_current_page(rIdent);
notifyDialogState();
}
void JSNotebook::remove_page(const OString& rIdent)
{
SalInstanceNotebook::remove_page(rIdent);
notifyDialogState();
}
void JSNotebook::insert_page(const OString& rIdent, const OUString& rLabel, int nPos)
{
SalInstanceNotebook::insert_page(rIdent, rLabel, nPos);
notifyDialogState();
}
|