File: | home/maarten/src/libreoffice/core/include/rtl/ref.hxx |
Warning: | line 113, column 13 Use of memory after it is freed |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
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. | |||
4 | * | |||
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 | */ | |||
9 | ||||
10 | #include <jsdialog/jsdialogbuilder.hxx> | |||
11 | #include <sal/log.hxx> | |||
12 | #include <comphelper/lok.hxx> | |||
13 | #include <vcl/tabpage.hxx> | |||
14 | #include <vcl/toolkit/button.hxx> | |||
15 | #include <vcl/toolkit/dialog.hxx> | |||
16 | #include <LibreOfficeKit/LibreOfficeKitEnums.h> | |||
17 | #include <vcl/toolkit/combobox.hxx> | |||
18 | #include <messagedialog.hxx> | |||
19 | #include <tools/json_writer.hxx> | |||
20 | #include <o3tl/deleter.hxx> | |||
21 | #include <memory> | |||
22 | #include <vcl/toolbox.hxx> | |||
23 | #include <vcl/toolkit/vclmedit.hxx> | |||
24 | #include <boost/property_tree/json_parser.hpp> | |||
25 | ||||
26 | JSDialogNotifyIdle::JSDialogNotifyIdle(VclPtr<vcl::Window> aWindow) | |||
27 | : Idle("JSDialog notify") | |||
28 | , m_aWindow(aWindow) | |||
29 | , m_LastNotificationMessage() | |||
30 | , m_bForce(false) | |||
31 | { | |||
32 | SetPriority(TaskPriority::POST_PAINT); | |||
33 | } | |||
34 | ||||
35 | void JSDialogNotifyIdle::ForceUpdate() { m_bForce = true; } | |||
36 | ||||
37 | void JSDialogNotifyIdle::Invoke() | |||
38 | { | |||
39 | try | |||
40 | { | |||
41 | if (!m_aWindow) | |||
42 | return; | |||
43 | ||||
44 | const vcl::ILibreOfficeKitNotifier* pNotifier = m_aWindow->GetLOKNotifier(); | |||
45 | if (pNotifier) | |||
46 | { | |||
47 | tools::JsonWriter aJsonWriter; | |||
48 | m_aWindow->DumpAsPropertyTree(aJsonWriter); | |||
49 | aJsonWriter.put("id", m_aWindow->GetLOKWindowId()); | |||
50 | if (m_bForce || !aJsonWriter.isDataEquals(m_LastNotificationMessage)) | |||
51 | { | |||
52 | m_bForce = false; | |||
53 | m_LastNotificationMessage = aJsonWriter.extractAsStdString(); | |||
54 | pNotifier->libreOfficeKitViewCallback(LOK_CALLBACK_JSDIALOG, | |||
55 | m_LastNotificationMessage.c_str()); | |||
56 | } | |||
57 | } | |||
58 | } | |||
59 | catch (boost::property_tree::json_parser::json_parser_error& rError) | |||
60 | { | |||
61 | SAL_WARN("vcl", rError.message())do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_WARN , "vcl")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break; case SAL_DETAIL_LOG_ACTION_LOG : if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart () << rError.message()) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN ), ("vcl"), ("/home/maarten/src/libreoffice/core/vcl/jsdialog/jsdialogbuilder.cxx" ":" "61" ": "), ::sal::detail::unwrapStream( ::sal::detail:: StreamStart() << rError.message()), 0); } else { ::std:: ostringstream sal_detail_stream; sal_detail_stream << rError .message(); ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN) , ("vcl"), ("/home/maarten/src/libreoffice/core/vcl/jsdialog/jsdialogbuilder.cxx" ":" "61" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL : if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart () << rError.message()) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN ), ("vcl"), ("/home/maarten/src/libreoffice/core/vcl/jsdialog/jsdialogbuilder.cxx" ":" "61" ": "), ::sal::detail::unwrapStream( ::sal::detail:: StreamStart() << rError.message()), 0); } else { ::std:: ostringstream sal_detail_stream; sal_detail_stream << rError .message(); ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN) , ("vcl"), ("/home/maarten/src/libreoffice/core/vcl/jsdialog/jsdialogbuilder.cxx" ":" "61" ": "), sal_detail_stream, 0); }; std::abort(); break ; } } } while (false); | |||
62 | } | |||
63 | } | |||
64 | ||||
65 | void JSDialogSender::notifyDialogState(bool bForce) | |||
66 | { | |||
67 | if (bForce) | |||
68 | mpIdleNotify->ForceUpdate(); | |||
69 | mpIdleNotify->Start(); | |||
70 | } | |||
71 | ||||
72 | namespace | |||
73 | { | |||
74 | vcl::Window* extract_sal_widget(weld::Widget* pParent) | |||
75 | { | |||
76 | SalInstanceWidget* pInstanceWidget = dynamic_cast<SalInstanceWidget*>(pParent); | |||
77 | return pInstanceWidget ? pInstanceWidget->getWidget() : nullptr; | |||
78 | } | |||
79 | } | |||
80 | ||||
81 | JSInstanceBuilder::JSInstanceBuilder(weld::Widget* pParent, const OUString& rUIRoot, | |||
82 | const OUString& rUIFile) | |||
83 | : SalInstanceBuilder(extract_sal_widget(pParent), rUIRoot, rUIFile) | |||
84 | , m_nWindowId(0) | |||
85 | , m_aParentDialog(nullptr) | |||
86 | , m_bHasTopLevelDialog(false) | |||
87 | , m_bIsNotebookbar(false) | |||
88 | { | |||
89 | vcl::Window* pRoot = m_xBuilder->get_widget_root(); | |||
90 | if (pRoot && pRoot->GetParent()) | |||
91 | { | |||
92 | m_aParentDialog = pRoot->GetParent()->GetParentWithLOKNotifier(); | |||
93 | if (m_aParentDialog) | |||
94 | m_nWindowId = m_aParentDialog->GetLOKWindowId(); | |||
95 | InsertWindowToMap(m_nWindowId); | |||
96 | } | |||
97 | } | |||
98 | ||||
99 | JSInstanceBuilder::JSInstanceBuilder(vcl::Window* pParent, const OUString& rUIRoot, | |||
100 | const OUString& rUIFile, | |||
101 | const css::uno::Reference<css::frame::XFrame>& rFrame, | |||
102 | sal_uInt64 nWindowId) | |||
103 | : SalInstanceBuilder(pParent, rUIRoot, rUIFile, rFrame) | |||
104 | , m_nWindowId(0) | |||
105 | , m_aParentDialog(nullptr) | |||
106 | , m_bHasTopLevelDialog(false) | |||
107 | , m_bIsNotebookbar(false) | |||
108 | { | |||
109 | vcl::Window* pRoot = m_xBuilder->get_widget_root(); | |||
110 | if (pRoot && pRoot->GetParent()) | |||
111 | { | |||
112 | m_aParentDialog = pRoot->GetParent()->GetParentWithLOKNotifier(); | |||
113 | if (m_aParentDialog) | |||
114 | m_nWindowId = m_aParentDialog->GetLOKWindowId(); | |||
115 | if (!m_nWindowId && nWindowId) | |||
116 | { | |||
117 | m_nWindowId = nWindowId; | |||
118 | m_bIsNotebookbar = true; | |||
119 | } | |||
120 | InsertWindowToMap(m_nWindowId); | |||
121 | } | |||
122 | } | |||
123 | ||||
124 | JSInstanceBuilder::~JSInstanceBuilder() | |||
125 | { | |||
126 | if (m_nWindowId && (m_bHasTopLevelDialog || m_bIsNotebookbar)) | |||
127 | GetLOKWeldWidgetsMap().erase(m_nWindowId); | |||
128 | } | |||
129 | ||||
130 | std::map<sal_uInt64, WidgetMap>& JSInstanceBuilder::GetLOKWeldWidgetsMap() | |||
131 | { | |||
132 | // Map to remember the LOKWindowId <-> weld widgets binding. | |||
133 | static std::map<sal_uInt64, WidgetMap> s_aLOKWeldBuildersMap; | |||
134 | ||||
135 | return s_aLOKWeldBuildersMap; | |||
136 | } | |||
137 | ||||
138 | weld::Widget* JSInstanceBuilder::FindWeldWidgetsMap(sal_uInt64 nWindowId, const OString& rWidget) | |||
139 | { | |||
140 | const auto it = GetLOKWeldWidgetsMap().find(nWindowId); | |||
141 | ||||
142 | if (it != GetLOKWeldWidgetsMap().end()) | |||
143 | { | |||
144 | auto widgetIt = it->second.find(rWidget); | |||
145 | if (widgetIt != it->second.end()) | |||
146 | return widgetIt->second; | |||
147 | } | |||
148 | ||||
149 | return nullptr; | |||
150 | } | |||
151 | ||||
152 | void JSInstanceBuilder::InsertWindowToMap(sal_uInt64 nWindowId) | |||
153 | { | |||
154 | WidgetMap map; | |||
155 | auto it = GetLOKWeldWidgetsMap().find(nWindowId); | |||
156 | if (it == GetLOKWeldWidgetsMap().end()) | |||
157 | GetLOKWeldWidgetsMap().insert(std::map<sal_uInt64, WidgetMap>::value_type(nWindowId, map)); | |||
158 | } | |||
159 | ||||
160 | void JSInstanceBuilder::RememberWidget(const OString& id, weld::Widget* pWidget) | |||
161 | { | |||
162 | auto it = GetLOKWeldWidgetsMap().find(m_nWindowId); | |||
163 | if (it != GetLOKWeldWidgetsMap().end()) | |||
164 | { | |||
165 | it->second.erase(id); | |||
166 | it->second.insert(WidgetMap::value_type(id, pWidget)); | |||
167 | } | |||
168 | } | |||
169 | ||||
170 | std::unique_ptr<weld::Dialog> JSInstanceBuilder::weld_dialog(const OString& id) | |||
171 | { | |||
172 | ::Dialog* pDialog = m_xBuilder->get<::Dialog>(id); | |||
173 | m_nWindowId = pDialog->GetLOKWindowId(); | |||
174 | ||||
175 | InsertWindowToMap(m_nWindowId); | |||
176 | ||||
177 | std::unique_ptr<weld::Dialog> pRet( | |||
178 | pDialog ? new JSDialog(m_aOwnedToplevel, pDialog, this, false) : nullptr); | |||
179 | if (pDialog) | |||
180 | { | |||
181 | assert(!m_aOwnedToplevel && "only one toplevel per .ui allowed")(static_cast <bool> (!m_aOwnedToplevel && "only one toplevel per .ui allowed" ) ? void (0) : __assert_fail ("!m_aOwnedToplevel && \"only one toplevel per .ui allowed\"" , "/home/maarten/src/libreoffice/core/vcl/jsdialog/jsdialogbuilder.cxx" , 181, __extension__ __PRETTY_FUNCTION__)); | |||
182 | m_aOwnedToplevel.set(pDialog); | |||
183 | m_xBuilder->drop_ownership(pDialog); | |||
184 | m_bHasTopLevelDialog = true; | |||
185 | } | |||
186 | ||||
187 | const vcl::ILibreOfficeKitNotifier* pNotifier = pDialog->GetLOKNotifier(); | |||
188 | if (pNotifier) | |||
189 | { | |||
190 | tools::JsonWriter aJsonWriter; | |||
191 | m_aOwnedToplevel->DumpAsPropertyTree(aJsonWriter); | |||
192 | aJsonWriter.put("id", m_aOwnedToplevel->GetLOKWindowId()); | |||
193 | pNotifier->libreOfficeKitViewCallback(LOK_CALLBACK_JSDIALOG, aJsonWriter.extractData()); | |||
194 | } | |||
195 | ||||
196 | return pRet; | |||
197 | } | |||
198 | ||||
199 | std::unique_ptr<weld::Label> JSInstanceBuilder::weld_label(const OString& id) | |||
200 | { | |||
201 | ::FixedText* pLabel = m_xBuilder->get<FixedText>(id); | |||
202 | auto pWeldWidget = std::make_unique<JSLabel>( | |||
203 | m_bHasTopLevelDialog ? m_aOwnedToplevel : m_aParentDialog, pLabel, this, false); | |||
204 | ||||
205 | if (pWeldWidget) | |||
206 | RememberWidget(id, pWeldWidget.get()); | |||
207 | ||||
208 | return pWeldWidget; | |||
209 | } | |||
210 | ||||
211 | std::unique_ptr<weld::Button> JSInstanceBuilder::weld_button(const OString& id) | |||
212 | { | |||
213 | ::Button* pButton = m_xBuilder->get<::Button>(id); | |||
214 | auto pWeldWidget = pButton ? std::make_unique<JSButton>(m_bHasTopLevelDialog ? m_aOwnedToplevel | |||
215 | : m_aParentDialog, | |||
216 | pButton, this, false) | |||
217 | : nullptr; | |||
218 | ||||
219 | if (pWeldWidget) | |||
220 | RememberWidget(id, pWeldWidget.get()); | |||
221 | ||||
222 | return pWeldWidget; | |||
223 | } | |||
224 | ||||
225 | std::unique_ptr<weld::Entry> JSInstanceBuilder::weld_entry(const OString& id) | |||
226 | { | |||
227 | Edit* pEntry = m_xBuilder->get<Edit>(id); | |||
228 | auto pWeldWidget = pEntry ? std::make_unique<JSEntry>(m_bHasTopLevelDialog ? m_aOwnedToplevel | |||
229 | : m_aParentDialog, | |||
230 | pEntry, this, false) | |||
231 | : nullptr; | |||
232 | ||||
233 | if (pWeldWidget) | |||
234 | RememberWidget(id, pWeldWidget.get()); | |||
235 | ||||
236 | return pWeldWidget; | |||
237 | } | |||
238 | ||||
239 | std::unique_ptr<weld::ComboBox> JSInstanceBuilder::weld_combo_box(const OString& id) | |||
240 | { | |||
241 | vcl::Window* pWidget = m_xBuilder->get<vcl::Window>(id); | |||
242 | ::ComboBox* pComboBox = dynamic_cast<::ComboBox*>(pWidget); | |||
243 | std::unique_ptr<weld::ComboBox> pWeldWidget; | |||
244 | ||||
245 | if (pComboBox) | |||
246 | { | |||
247 | pWeldWidget = std::make_unique<JSComboBox>( | |||
248 | m_bHasTopLevelDialog ? m_aOwnedToplevel : m_aParentDialog, pComboBox, this, false); | |||
249 | } | |||
250 | else | |||
251 | { | |||
252 | ListBox* pListBox = dynamic_cast<ListBox*>(pWidget); | |||
253 | pWeldWidget = pListBox ? std::make_unique<JSListBox>(m_bHasTopLevelDialog ? m_aOwnedToplevel | |||
254 | : m_aParentDialog, | |||
255 | pListBox, this, false) | |||
256 | : nullptr; | |||
257 | } | |||
258 | ||||
259 | if (pWeldWidget) | |||
260 | RememberWidget(id, pWeldWidget.get()); | |||
261 | ||||
262 | return pWeldWidget; | |||
263 | } | |||
264 | ||||
265 | std::unique_ptr<weld::Notebook> JSInstanceBuilder::weld_notebook(const OString& id) | |||
266 | { | |||
267 | TabControl* pNotebook = m_xBuilder->get<TabControl>(id); | |||
268 | auto pWeldWidget = pNotebook ? std::make_unique<JSNotebook>( | |||
269 | m_bHasTopLevelDialog ? m_aOwnedToplevel : m_aParentDialog, | |||
270 | pNotebook, this, false) | |||
271 | : nullptr; | |||
272 | ||||
273 | if (pWeldWidget) | |||
274 | RememberWidget(id, pWeldWidget.get()); | |||
275 | ||||
276 | return pWeldWidget; | |||
277 | } | |||
278 | ||||
279 | std::unique_ptr<weld::SpinButton> JSInstanceBuilder::weld_spin_button(const OString& id) | |||
280 | { | |||
281 | FormattedField* pSpinButton = m_xBuilder->get<FormattedField>(id); | |||
282 | auto pWeldWidget = pSpinButton ? std::make_unique<JSSpinButton>( | |||
283 | m_bHasTopLevelDialog ? m_aOwnedToplevel : m_aParentDialog, | |||
284 | pSpinButton, this, false) | |||
285 | : nullptr; | |||
286 | ||||
287 | if (pWeldWidget) | |||
288 | RememberWidget(id, pWeldWidget.get()); | |||
289 | ||||
290 | return pWeldWidget; | |||
291 | } | |||
292 | ||||
293 | std::unique_ptr<weld::CheckButton> JSInstanceBuilder::weld_check_button(const OString& id) | |||
294 | { | |||
295 | CheckBox* pCheckButton = m_xBuilder->get<CheckBox>(id); | |||
296 | auto pWeldWidget = pCheckButton ? std::make_unique<JSCheckButton>( | |||
297 | m_bHasTopLevelDialog ? m_aOwnedToplevel : m_aParentDialog, | |||
298 | pCheckButton, this, false) | |||
299 | : nullptr; | |||
300 | ||||
301 | if (pWeldWidget) | |||
302 | RememberWidget(id, pWeldWidget.get()); | |||
303 | ||||
304 | return pWeldWidget; | |||
305 | } | |||
306 | ||||
307 | std::unique_ptr<weld::DrawingArea> | |||
308 | JSInstanceBuilder::weld_drawing_area(const OString& id, const a11yref& rA11yImpl, | |||
309 | FactoryFunction pUITestFactoryFunction, void* pUserData) | |||
310 | { | |||
311 | VclDrawingArea* pArea = m_xBuilder->get<VclDrawingArea>(id); | |||
312 | auto pWeldWidget = pArea ? std::make_unique<JSDrawingArea>( | |||
313 | m_bHasTopLevelDialog ? m_aOwnedToplevel : m_aParentDialog, pArea, | |||
314 | this, rA11yImpl, pUITestFactoryFunction, pUserData) | |||
315 | : nullptr; | |||
316 | ||||
317 | if (pWeldWidget) | |||
318 | RememberWidget(id, pWeldWidget.get()); | |||
319 | ||||
320 | return pWeldWidget; | |||
321 | } | |||
322 | ||||
323 | std::unique_ptr<weld::Toolbar> JSInstanceBuilder::weld_toolbar(const OString& id) | |||
324 | { | |||
325 | ToolBox* pToolBox = m_xBuilder->get<ToolBox>(id); | |||
326 | auto pWeldWidget = pToolBox ? std::make_unique<JSToolbar>( | |||
327 | m_bHasTopLevelDialog ? m_aOwnedToplevel : m_aParentDialog, | |||
328 | pToolBox, this, false) | |||
329 | : nullptr; | |||
330 | ||||
331 | if (pWeldWidget) | |||
332 | RememberWidget(id, pWeldWidget.get()); | |||
333 | ||||
334 | return pWeldWidget; | |||
335 | } | |||
336 | ||||
337 | std::unique_ptr<weld::TextView> JSInstanceBuilder::weld_text_view(const OString& id) | |||
338 | { | |||
339 | VclMultiLineEdit* pTextView = m_xBuilder->get<VclMultiLineEdit>(id); | |||
340 | auto pWeldWidget = pTextView ? std::make_unique<JSTextView>( | |||
341 | m_bHasTopLevelDialog ? m_aOwnedToplevel : m_aParentDialog, | |||
342 | pTextView, this, false) | |||
343 | : nullptr; | |||
344 | ||||
345 | if (pWeldWidget) | |||
346 | RememberWidget(id, pWeldWidget.get()); | |||
347 | ||||
348 | return pWeldWidget; | |||
349 | } | |||
350 | ||||
351 | weld::MessageDialog* JSInstanceBuilder::CreateMessageDialog(weld::Widget* pParent, | |||
352 | VclMessageType eMessageType, | |||
353 | VclButtonsType eButtonType, | |||
354 | const OUString& rPrimaryMessage) | |||
355 | { | |||
356 | SalInstanceWidget* pParentInstance = dynamic_cast<SalInstanceWidget*>(pParent); | |||
357 | SystemWindow* pParentWidget = pParentInstance ? pParentInstance->getSystemWindow() : nullptr; | |||
358 | VclPtrInstance<::MessageDialog> xMessageDialog(pParentWidget, rPrimaryMessage, eMessageType, | |||
359 | eButtonType); | |||
360 | ||||
361 | const vcl::ILibreOfficeKitNotifier* pNotifier = xMessageDialog->GetLOKNotifier(); | |||
362 | if (pNotifier) | |||
363 | { | |||
364 | tools::JsonWriter aJsonWriter; | |||
365 | xMessageDialog->DumpAsPropertyTree(aJsonWriter); | |||
366 | aJsonWriter.put("id", xMessageDialog->GetLOKWindowId()); | |||
367 | std::unique_ptr<char[], o3tl::free_delete> message(aJsonWriter.extractData()); | |||
368 | pNotifier->libreOfficeKitViewCallback(LOK_CALLBACK_JSDIALOG, message.get()); | |||
369 | } | |||
370 | ||||
371 | return new JSMessageDialog(xMessageDialog, nullptr, true); | |||
372 | } | |||
373 | ||||
374 | JSDialog::JSDialog(VclPtr<vcl::Window> aOwnedToplevel, ::Dialog* pDialog, | |||
375 | SalInstanceBuilder* pBuilder, bool bTakeOwnership) | |||
376 | : JSWidget<SalInstanceDialog, ::Dialog>(aOwnedToplevel, pDialog, pBuilder, bTakeOwnership) | |||
377 | { | |||
378 | } | |||
379 | ||||
380 | void JSDialog::collapse(weld::Widget* pEdit, weld::Widget* pButton) | |||
381 | { | |||
382 | SalInstanceDialog::collapse(pEdit, pButton); | |||
383 | notifyDialogState(); | |||
384 | } | |||
385 | ||||
386 | void JSDialog::undo_collapse() | |||
387 | { | |||
388 | SalInstanceDialog::undo_collapse(); | |||
389 | notifyDialogState(); | |||
390 | } | |||
391 | ||||
392 | JSLabel::JSLabel(VclPtr<vcl::Window> aOwnedToplevel, FixedText* pLabel, | |||
393 | SalInstanceBuilder* pBuilder, bool bTakeOwnership) | |||
394 | : JSWidget<SalInstanceLabel, FixedText>(aOwnedToplevel, pLabel, pBuilder, bTakeOwnership) | |||
395 | { | |||
396 | } | |||
397 | ||||
398 | void JSLabel::set_label(const OUString& rText) | |||
399 | { | |||
400 | SalInstanceLabel::set_label(rText); | |||
401 | notifyDialogState(); | |||
402 | }; | |||
403 | ||||
404 | JSButton::JSButton(VclPtr<vcl::Window> aOwnedToplevel, ::Button* pButton, | |||
405 | SalInstanceBuilder* pBuilder, bool bTakeOwnership) | |||
406 | : JSWidget<SalInstanceButton, ::Button>(aOwnedToplevel, pButton, pBuilder, bTakeOwnership) | |||
407 | { | |||
408 | } | |||
409 | ||||
410 | JSEntry::JSEntry(VclPtr<vcl::Window> aOwnedToplevel, ::Edit* pEntry, SalInstanceBuilder* pBuilder, | |||
411 | bool bTakeOwnership) | |||
412 | : JSWidget<SalInstanceEntry, ::Edit>(aOwnedToplevel, pEntry, pBuilder, bTakeOwnership) | |||
413 | { | |||
414 | } | |||
415 | ||||
416 | void JSEntry::set_text(const OUString& rText) | |||
417 | { | |||
418 | SalInstanceEntry::set_text(rText); | |||
419 | notifyDialogState(); | |||
420 | } | |||
421 | ||||
422 | JSListBox::JSListBox(VclPtr<vcl::Window> aOwnedToplevel, ::ListBox* pListBox, | |||
423 | SalInstanceBuilder* pBuilder, bool bTakeOwnership) | |||
424 | : JSWidget<SalInstanceComboBoxWithoutEdit, ::ListBox>(aOwnedToplevel, pListBox, pBuilder, | |||
| ||||
425 | bTakeOwnership) | |||
426 | { | |||
427 | } | |||
428 | ||||
429 | void JSListBox::insert(int pos, const OUString& rStr, const OUString* pId, | |||
430 | const OUString* pIconName, VirtualDevice* pImageSurface) | |||
431 | { | |||
432 | SalInstanceComboBoxWithoutEdit::insert(pos, rStr, pId, pIconName, pImageSurface); | |||
433 | notifyDialogState(); | |||
434 | } | |||
435 | ||||
436 | void JSListBox::remove(int pos) | |||
437 | { | |||
438 | SalInstanceComboBoxWithoutEdit::remove(pos); | |||
439 | notifyDialogState(); | |||
440 | } | |||
441 | ||||
442 | void JSListBox::set_active(int pos) | |||
443 | { | |||
444 | SalInstanceComboBoxWithoutEdit::set_active(pos); | |||
445 | notifyDialogState(); | |||
446 | } | |||
447 | ||||
448 | JSComboBox::JSComboBox(VclPtr<vcl::Window> aOwnedToplevel, ::ComboBox* pComboBox, | |||
449 | SalInstanceBuilder* pBuilder, bool bTakeOwnership) | |||
450 | : JSWidget<SalInstanceComboBoxWithEdit, ::ComboBox>(aOwnedToplevel, pComboBox, pBuilder, | |||
451 | bTakeOwnership) | |||
452 | { | |||
453 | } | |||
454 | ||||
455 | void JSComboBox::insert(int pos, const OUString& rStr, const OUString* pId, | |||
456 | const OUString* pIconName, VirtualDevice* pImageSurface) | |||
457 | { | |||
458 | SalInstanceComboBoxWithEdit::insert(pos, rStr, pId, pIconName, pImageSurface); | |||
459 | notifyDialogState(); | |||
460 | } | |||
461 | ||||
462 | void JSComboBox::remove(int pos) | |||
463 | { | |||
464 | SalInstanceComboBoxWithEdit::remove(pos); | |||
465 | notifyDialogState(); | |||
466 | } | |||
467 | ||||
468 | void JSComboBox::set_entry_text(const OUString& rText) | |||
469 | { | |||
470 | SalInstanceComboBoxWithEdit::set_entry_text(rText); | |||
471 | notifyDialogState(); | |||
472 | } | |||
473 | ||||
474 | void JSComboBox::set_active(int pos) | |||
475 | { | |||
476 | SalInstanceComboBoxWithEdit::set_active(pos); | |||
477 | notifyDialogState(); | |||
478 | } | |||
479 | ||||
480 | JSNotebook::JSNotebook(VclPtr<vcl::Window> aOwnedToplevel, ::TabControl* pControl, | |||
481 | SalInstanceBuilder* pBuilder, bool bTakeOwnership) | |||
482 | : JSWidget<SalInstanceNotebook, ::TabControl>(aOwnedToplevel, pControl, pBuilder, | |||
483 | bTakeOwnership) | |||
484 | { | |||
485 | } | |||
486 | ||||
487 | void JSNotebook::set_current_page(int nPage) | |||
488 | { | |||
489 | bool bForce = false; | |||
490 | int nCurrent = get_current_page(); | |||
491 | if (nCurrent == nPage) | |||
492 | bForce = true; | |||
493 | ||||
494 | SalInstanceNotebook::set_current_page(nPage); | |||
495 | notifyDialogState(bForce); | |||
496 | } | |||
497 | ||||
498 | void JSNotebook::set_current_page(const OString& rIdent) | |||
499 | { | |||
500 | bool bForce = false; | |||
501 | OString sCurrent = get_current_page_ident(); | |||
502 | if (sCurrent == rIdent) | |||
503 | bForce = true; | |||
504 | ||||
505 | SalInstanceNotebook::set_current_page(rIdent); | |||
506 | notifyDialogState(bForce); | |||
507 | } | |||
508 | ||||
509 | void JSNotebook::remove_page(const OString& rIdent) | |||
510 | { | |||
511 | SalInstanceNotebook::remove_page(rIdent); | |||
512 | notifyDialogState(); | |||
513 | } | |||
514 | ||||
515 | void JSNotebook::insert_page(const OString& rIdent, const OUString& rLabel, int nPos) | |||
516 | { | |||
517 | SalInstanceNotebook::insert_page(rIdent, rLabel, nPos); | |||
518 | notifyDialogState(); | |||
519 | } | |||
520 | ||||
521 | JSSpinButton::JSSpinButton(VclPtr<vcl::Window> aOwnedToplevel, ::FormattedField* pSpin, | |||
522 | SalInstanceBuilder* pBuilder, bool bTakeOwnership) | |||
523 | : JSWidget<SalInstanceSpinButton, ::FormattedField>(aOwnedToplevel, pSpin, pBuilder, | |||
524 | bTakeOwnership) | |||
525 | { | |||
526 | } | |||
527 | ||||
528 | void JSSpinButton::set_value(int value) | |||
529 | { | |||
530 | SalInstanceSpinButton::set_value(value); | |||
531 | notifyDialogState(); | |||
532 | } | |||
533 | ||||
534 | JSMessageDialog::JSMessageDialog(::MessageDialog* pDialog, SalInstanceBuilder* pBuilder, | |||
535 | bool bTakeOwnership) | |||
536 | : SalInstanceMessageDialog(pDialog, pBuilder, bTakeOwnership) | |||
537 | , JSDialogSender(m_xMessageDialog) | |||
538 | { | |||
539 | } | |||
540 | ||||
541 | void JSMessageDialog::set_primary_text(const OUString& rText) | |||
542 | { | |||
543 | SalInstanceMessageDialog::set_primary_text(rText); | |||
544 | notifyDialogState(); | |||
545 | } | |||
546 | ||||
547 | void JSMessageDialog::set_secondary_text(const OUString& rText) | |||
548 | { | |||
549 | SalInstanceMessageDialog::set_secondary_text(rText); | |||
550 | notifyDialogState(); | |||
551 | } | |||
552 | ||||
553 | JSCheckButton::JSCheckButton(VclPtr<vcl::Window> aOwnedToplevel, ::CheckBox* pCheckBox, | |||
554 | SalInstanceBuilder* pBuilder, bool bTakeOwnership) | |||
555 | : JSWidget<SalInstanceCheckButton, ::CheckBox>(aOwnedToplevel, pCheckBox, pBuilder, | |||
556 | bTakeOwnership) | |||
557 | { | |||
558 | } | |||
559 | ||||
560 | void JSCheckButton::set_active(bool active) | |||
561 | { | |||
562 | SalInstanceCheckButton::set_active(active); | |||
563 | notifyDialogState(); | |||
564 | } | |||
565 | ||||
566 | JSDrawingArea::JSDrawingArea(VclPtr<vcl::Window> aOwnedToplevel, VclDrawingArea* pDrawingArea, | |||
567 | SalInstanceBuilder* pBuilder, const a11yref& rAlly, | |||
568 | FactoryFunction pUITestFactoryFunction, void* pUserData) | |||
569 | : SalInstanceDrawingArea(pDrawingArea, pBuilder, rAlly, pUITestFactoryFunction, pUserData, | |||
570 | false) | |||
571 | , JSDialogSender(aOwnedToplevel) | |||
572 | { | |||
573 | } | |||
574 | ||||
575 | void JSDrawingArea::queue_draw() | |||
576 | { | |||
577 | SalInstanceDrawingArea::queue_draw(); | |||
578 | notifyDialogState(); | |||
579 | } | |||
580 | ||||
581 | void JSDrawingArea::queue_draw_area(int x, int y, int width, int height) | |||
582 | { | |||
583 | SalInstanceDrawingArea::queue_draw_area(x, y, width, height); | |||
584 | notifyDialogState(); | |||
585 | } | |||
586 | ||||
587 | JSToolbar::JSToolbar(VclPtr<vcl::Window> aOwnedToplevel, ::ToolBox* pToolbox, | |||
588 | SalInstanceBuilder* pBuilder, bool bTakeOwnership) | |||
589 | : JSWidget<SalInstanceToolbar, ::ToolBox>(aOwnedToplevel, pToolbox, pBuilder, bTakeOwnership) | |||
590 | { | |||
591 | } | |||
592 | ||||
593 | void JSToolbar::signal_clicked(const OString& rIdent) | |||
594 | { | |||
595 | SalInstanceToolbar::signal_clicked(rIdent); | |||
596 | notifyDialogState(); | |||
597 | } | |||
598 | ||||
599 | JSTextView::JSTextView(VclPtr<vcl::Window> aOwnedToplevel, ::VclMultiLineEdit* pTextView, | |||
600 | SalInstanceBuilder* pBuilder, bool bTakeOwnership) | |||
601 | : JSWidget<SalInstanceTextView, ::VclMultiLineEdit>(aOwnedToplevel, pTextView, pBuilder, | |||
602 | bTakeOwnership) | |||
603 | { | |||
604 | } | |||
605 | ||||
606 | void JSTextView::set_text(const OUString& rText) | |||
607 | { | |||
608 | SalInstanceTextView::set_text(rText); | |||
609 | notifyDialogState(); | |||
610 | } | |||
611 | ||||
612 | /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ |
1 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ | ||||||||||||||||
2 | /* | ||||||||||||||||
3 | * This file is part of the LibreOffice project. | ||||||||||||||||
4 | * | ||||||||||||||||
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 | * | ||||||||||||||||
9 | * This file incorporates work covered by the following license notice: | ||||||||||||||||
10 | * | ||||||||||||||||
11 | * Licensed to the Apache Software Foundation (ASF) under one or more | ||||||||||||||||
12 | * contributor license agreements. See the NOTICE file distributed | ||||||||||||||||
13 | * with this work for additional information regarding copyright | ||||||||||||||||
14 | * ownership. The ASF licenses this file to you under the Apache | ||||||||||||||||
15 | * License, Version 2.0 (the "License"); you may not use this file | ||||||||||||||||
16 | * except in compliance with the License. You may obtain a copy of | ||||||||||||||||
17 | * the License at http://www.apache.org/licenses/LICENSE-2.0 . | ||||||||||||||||
18 | */ | ||||||||||||||||
19 | |||||||||||||||||
20 | #ifndef INCLUDED_RTL_REF_HXX | ||||||||||||||||
21 | #define INCLUDED_RTL_REF_HXX | ||||||||||||||||
22 | |||||||||||||||||
23 | #include "sal/config.h" | ||||||||||||||||
24 | |||||||||||||||||
25 | #include <cassert> | ||||||||||||||||
26 | #include <cstddef> | ||||||||||||||||
27 | #include <functional> | ||||||||||||||||
28 | #ifdef LIBO_INTERNAL_ONLY1 | ||||||||||||||||
29 | #include <type_traits> | ||||||||||||||||
30 | #endif | ||||||||||||||||
31 | |||||||||||||||||
32 | #include "sal/types.h" | ||||||||||||||||
33 | |||||||||||||||||
34 | namespace rtl | ||||||||||||||||
35 | { | ||||||||||||||||
36 | |||||||||||||||||
37 | /** Template reference class for reference type. | ||||||||||||||||
38 | */ | ||||||||||||||||
39 | template <class reference_type> | ||||||||||||||||
40 | class Reference | ||||||||||||||||
41 | { | ||||||||||||||||
42 | /** The <b>reference_type</b> body pointer. | ||||||||||||||||
43 | */ | ||||||||||||||||
44 | reference_type * m_pBody; | ||||||||||||||||
45 | |||||||||||||||||
46 | |||||||||||||||||
47 | public: | ||||||||||||||||
48 | /** Constructor... | ||||||||||||||||
49 | */ | ||||||||||||||||
50 | Reference() | ||||||||||||||||
51 | : m_pBody (NULL__null) | ||||||||||||||||
52 | {} | ||||||||||||||||
53 | |||||||||||||||||
54 | |||||||||||||||||
55 | /** Constructor... | ||||||||||||||||
56 | */ | ||||||||||||||||
57 | Reference (reference_type * pBody, __sal_NoAcquire) | ||||||||||||||||
58 | : m_pBody (pBody) | ||||||||||||||||
59 | { | ||||||||||||||||
60 | } | ||||||||||||||||
61 | |||||||||||||||||
62 | /** Constructor... | ||||||||||||||||
63 | */ | ||||||||||||||||
64 | Reference (reference_type * pBody) | ||||||||||||||||
65 | : m_pBody (pBody) | ||||||||||||||||
66 | { | ||||||||||||||||
67 | if (m_pBody) | ||||||||||||||||
68 | m_pBody->acquire(); | ||||||||||||||||
69 | } | ||||||||||||||||
70 | |||||||||||||||||
71 | /** Copy constructor... | ||||||||||||||||
72 | */ | ||||||||||||||||
73 | Reference (const Reference<reference_type> & handle) | ||||||||||||||||
74 | : m_pBody (handle.m_pBody) | ||||||||||||||||
75 | { | ||||||||||||||||
76 | if (m_pBody) | ||||||||||||||||
77 | m_pBody->acquire(); | ||||||||||||||||
78 | } | ||||||||||||||||
79 | |||||||||||||||||
80 | #ifdef LIBO_INTERNAL_ONLY1 | ||||||||||||||||
81 | /** Move constructor... | ||||||||||||||||
82 | */ | ||||||||||||||||
83 | Reference (Reference<reference_type> && handle) noexcept | ||||||||||||||||
84 | : m_pBody (handle.m_pBody) | ||||||||||||||||
85 | { | ||||||||||||||||
86 | handle.m_pBody = nullptr; | ||||||||||||||||
87 | } | ||||||||||||||||
88 | #endif | ||||||||||||||||
89 | |||||||||||||||||
90 | #if defined LIBO_INTERNAL_ONLY1 | ||||||||||||||||
91 | /** Up-casting conversion constructor: Copies interface reference. | ||||||||||||||||
92 | |||||||||||||||||
93 | Does not work for up-casts to ambiguous bases. | ||||||||||||||||
94 | |||||||||||||||||
95 | @param rRef another reference | ||||||||||||||||
96 | */ | ||||||||||||||||
97 | template< class derived_type > | ||||||||||||||||
98 | inline Reference( | ||||||||||||||||
99 | const Reference< derived_type > & rRef, | ||||||||||||||||
100 | std::enable_if_t<std::is_base_of_v<reference_type, derived_type>, int> = 0 ) | ||||||||||||||||
101 | : m_pBody (rRef.get()) | ||||||||||||||||
102 | { | ||||||||||||||||
103 | if (m_pBody) | ||||||||||||||||
104 | m_pBody->acquire(); | ||||||||||||||||
105 | } | ||||||||||||||||
106 | #endif | ||||||||||||||||
107 | |||||||||||||||||
108 | /** Destructor... | ||||||||||||||||
109 | */ | ||||||||||||||||
110 | ~Reference() COVERITY_NOEXCEPT_FALSE | ||||||||||||||||
111 | { | ||||||||||||||||
112 | if (m_pBody
| ||||||||||||||||
113 | m_pBody->release(); | ||||||||||||||||
| |||||||||||||||||
114 | } | ||||||||||||||||
115 | |||||||||||||||||
116 | /** Set... | ||||||||||||||||
117 | Similar to assignment. | ||||||||||||||||
118 | */ | ||||||||||||||||
119 | Reference<reference_type> & | ||||||||||||||||
120 | SAL_CALL set (reference_type * pBody) | ||||||||||||||||
121 | { | ||||||||||||||||
122 | if (pBody) | ||||||||||||||||
123 | pBody->acquire(); | ||||||||||||||||
124 | reference_type * const pOld = m_pBody; | ||||||||||||||||
125 | m_pBody = pBody; | ||||||||||||||||
126 | if (pOld) | ||||||||||||||||
127 | pOld->release(); | ||||||||||||||||
128 | return *this; | ||||||||||||||||
129 | } | ||||||||||||||||
130 | |||||||||||||||||
131 | /** Assignment. | ||||||||||||||||
132 | Unbinds this instance from its body (if bound) and | ||||||||||||||||
133 | bind it to the body represented by the handle. | ||||||||||||||||
134 | */ | ||||||||||||||||
135 | Reference<reference_type> & | ||||||||||||||||
136 | SAL_CALL operator= (const Reference<reference_type> & handle) | ||||||||||||||||
137 | { | ||||||||||||||||
138 | return set( handle.m_pBody ); | ||||||||||||||||
139 | } | ||||||||||||||||
140 | |||||||||||||||||
141 | #ifdef LIBO_INTERNAL_ONLY1 | ||||||||||||||||
142 | /** Assignment. | ||||||||||||||||
143 | * Unbinds this instance from its body (if bound), | ||||||||||||||||
144 | * bind it to the body represented by the handle, and | ||||||||||||||||
145 | * set the body represented by the handle to nullptr. | ||||||||||||||||
146 | */ | ||||||||||||||||
147 | Reference<reference_type> & | ||||||||||||||||
148 | operator= (Reference<reference_type> && handle) | ||||||||||||||||
149 | { | ||||||||||||||||
150 | // self-movement guts ourself | ||||||||||||||||
151 | if (m_pBody) | ||||||||||||||||
152 | m_pBody->release(); | ||||||||||||||||
153 | m_pBody = handle.m_pBody; | ||||||||||||||||
154 | handle.m_pBody = nullptr; | ||||||||||||||||
155 | return *this; | ||||||||||||||||
156 | } | ||||||||||||||||
157 | #endif | ||||||||||||||||
158 | |||||||||||||||||
159 | /** Assignment... | ||||||||||||||||
160 | */ | ||||||||||||||||
161 | Reference<reference_type> & | ||||||||||||||||
162 | SAL_CALL operator= (reference_type * pBody) | ||||||||||||||||
163 | { | ||||||||||||||||
164 | return set( pBody ); | ||||||||||||||||
165 | } | ||||||||||||||||
166 | |||||||||||||||||
167 | /** Unbind the body from this handle. | ||||||||||||||||
168 | Note that for a handle representing a large body, | ||||||||||||||||
169 | "handle.clear().set(new body());" _might_ | ||||||||||||||||
170 | perform a little bit better than "handle.set(new body());", | ||||||||||||||||
171 | since in the second case two large objects exist in memory | ||||||||||||||||
172 | (the old body and the new body). | ||||||||||||||||
173 | */ | ||||||||||||||||
174 | Reference<reference_type> & SAL_CALL clear() | ||||||||||||||||
175 | { | ||||||||||||||||
176 | if (m_pBody) | ||||||||||||||||
177 | { | ||||||||||||||||
178 | reference_type * const pOld = m_pBody; | ||||||||||||||||
179 | m_pBody = NULL__null; | ||||||||||||||||
180 | pOld->release(); | ||||||||||||||||
181 | } | ||||||||||||||||
182 | return *this; | ||||||||||||||||
183 | } | ||||||||||||||||
184 | |||||||||||||||||
185 | |||||||||||||||||
186 | /** Get the body. Can be used instead of operator->(). | ||||||||||||||||
187 | I.e. handle->someBodyOp() and handle.get()->someBodyOp() | ||||||||||||||||
188 | are the same. | ||||||||||||||||
189 | */ | ||||||||||||||||
190 | reference_type * SAL_CALL get() const | ||||||||||||||||
191 | { | ||||||||||||||||
192 | return m_pBody; | ||||||||||||||||
193 | } | ||||||||||||||||
194 | |||||||||||||||||
195 | |||||||||||||||||
196 | /** Probably most common used: handle->someBodyOp(). | ||||||||||||||||
197 | */ | ||||||||||||||||
198 | reference_type * SAL_CALL operator->() const | ||||||||||||||||
199 | { | ||||||||||||||||
200 | assert(m_pBody != NULL)(static_cast <bool> (m_pBody != __null) ? void (0) : __assert_fail ("m_pBody != NULL", "/home/maarten/src/libreoffice/core/include/rtl/ref.hxx" , 200, __extension__ __PRETTY_FUNCTION__)); | ||||||||||||||||
201 | return m_pBody; | ||||||||||||||||
202 | } | ||||||||||||||||
203 | |||||||||||||||||
204 | |||||||||||||||||
205 | /** Allows (*handle).someBodyOp(). | ||||||||||||||||
206 | */ | ||||||||||||||||
207 | reference_type & SAL_CALL operator*() const | ||||||||||||||||
208 | { | ||||||||||||||||
209 | assert(m_pBody != NULL)(static_cast <bool> (m_pBody != __null) ? void (0) : __assert_fail ("m_pBody != NULL", "/home/maarten/src/libreoffice/core/include/rtl/ref.hxx" , 209, __extension__ __PRETTY_FUNCTION__)); | ||||||||||||||||
210 | return *m_pBody; | ||||||||||||||||
211 | } | ||||||||||||||||
212 | |||||||||||||||||
213 | |||||||||||||||||
214 | /** Returns True if the handle does point to a valid body. | ||||||||||||||||
215 | */ | ||||||||||||||||
216 | bool SAL_CALL is() const | ||||||||||||||||
217 | { | ||||||||||||||||
218 | return (m_pBody != NULL__null); | ||||||||||||||||
219 | } | ||||||||||||||||
220 | |||||||||||||||||
221 | #if defined LIBO_INTERNAL_ONLY1 | ||||||||||||||||
222 | /** Returns True if the handle does point to a valid body. | ||||||||||||||||
223 | */ | ||||||||||||||||
224 | explicit operator bool() const | ||||||||||||||||
225 | { | ||||||||||||||||
226 | return is(); | ||||||||||||||||
227 | } | ||||||||||||||||
228 | #endif | ||||||||||||||||
229 | |||||||||||||||||
230 | /** Returns True if this points to pBody. | ||||||||||||||||
231 | */ | ||||||||||||||||
232 | bool SAL_CALL operator== (const reference_type * pBody) const | ||||||||||||||||
233 | { | ||||||||||||||||
234 | return (m_pBody == pBody); | ||||||||||||||||
235 | } | ||||||||||||||||
236 | |||||||||||||||||
237 | |||||||||||||||||
238 | /** Returns True if handle points to the same body. | ||||||||||||||||
239 | */ | ||||||||||||||||
240 | bool | ||||||||||||||||
241 | SAL_CALL operator== (const Reference<reference_type> & handle) const | ||||||||||||||||
242 | { | ||||||||||||||||
243 | return (m_pBody == handle.m_pBody); | ||||||||||||||||
244 | } | ||||||||||||||||
245 | |||||||||||||||||
246 | |||||||||||||||||
247 | /** Needed to place References into STL collection. | ||||||||||||||||
248 | */ | ||||||||||||||||
249 | bool | ||||||||||||||||
250 | SAL_CALL operator!= (const Reference<reference_type> & handle) const | ||||||||||||||||
251 | { | ||||||||||||||||
252 | return (m_pBody != handle.m_pBody); | ||||||||||||||||
253 | } | ||||||||||||||||
254 | |||||||||||||||||
255 | |||||||||||||||||
256 | /** Needed to place References into STL collection. | ||||||||||||||||
257 | */ | ||||||||||||||||
258 | bool | ||||||||||||||||
259 | SAL_CALL operator< (const Reference<reference_type> & handle) const | ||||||||||||||||
260 | { | ||||||||||||||||
261 | return (m_pBody < handle.m_pBody); | ||||||||||||||||
262 | } | ||||||||||||||||
263 | |||||||||||||||||
264 | |||||||||||||||||
265 | /** Needed to place References into STL collection. | ||||||||||||||||
266 | */ | ||||||||||||||||
267 | bool | ||||||||||||||||
268 | SAL_CALL operator> (const Reference<reference_type> & handle) const | ||||||||||||||||
269 | { | ||||||||||||||||
270 | return (m_pBody > handle.m_pBody); | ||||||||||||||||
271 | } | ||||||||||||||||
272 | }; | ||||||||||||||||
273 | |||||||||||||||||
274 | } // namespace rtl | ||||||||||||||||
275 | |||||||||||||||||
276 | #if defined LIBO_INTERNAL_ONLY1 | ||||||||||||||||
277 | namespace std | ||||||||||||||||
278 | { | ||||||||||||||||
279 | |||||||||||||||||
280 | /// @cond INTERNAL | ||||||||||||||||
281 | /** | ||||||||||||||||
282 | Make rtl::Reference hashable by default for use in STL containers. | ||||||||||||||||
283 | |||||||||||||||||
284 | @since LibreOffice 6.3 | ||||||||||||||||
285 | */ | ||||||||||||||||
286 | template<typename T> | ||||||||||||||||
287 | struct hash<::rtl::Reference<T>> | ||||||||||||||||
288 | { | ||||||||||||||||
289 | std::size_t operator()(::rtl::Reference<T> const & s) const | ||||||||||||||||
290 | { return std::size_t(s.get()); } | ||||||||||||||||
291 | }; | ||||||||||||||||
292 | /// @endcond | ||||||||||||||||
293 | |||||||||||||||||
294 | } | ||||||||||||||||
295 | |||||||||||||||||
296 | #endif | ||||||||||||||||
297 | |||||||||||||||||
298 | #endif /* ! INCLUDED_RTL_REF_HXX */ | ||||||||||||||||
299 | |||||||||||||||||
300 | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |
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. |
4 | * |
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 | */ |
9 | |
10 | #pragma once |
11 | |
12 | #include <vcl/weld.hxx> |
13 | #include <vcl/jsdialog/executor.hxx> |
14 | #include <comphelper/string.hxx> |
15 | #include <vcl/sysdata.hxx> |
16 | #include <vcl/virdev.hxx> |
17 | #include <vcl/builder.hxx> |
18 | #include <salvtables.hxx> |
19 | #include <vcl/toolkit/button.hxx> |
20 | #include <vcl/toolkit/fmtfield.hxx> |
21 | |
22 | class ToolBox; |
23 | class ComboBox; |
24 | class VclMultiLineEdit; |
25 | |
26 | typedef std::map<OString, weld::Widget*> WidgetMap; |
27 | |
28 | class JSDialogNotifyIdle : public Idle |
29 | { |
30 | VclPtr<vcl::Window> m_aWindow; |
31 | std::string m_LastNotificationMessage; |
32 | bool m_bForce; |
33 | |
34 | public: |
35 | JSDialogNotifyIdle(VclPtr<vcl::Window> aWindow); |
36 | |
37 | void Invoke() override; |
38 | void ForceUpdate(); |
39 | }; |
40 | |
41 | class JSDialogSender |
42 | { |
43 | std::unique_ptr<JSDialogNotifyIdle> mpIdleNotify; |
44 | |
45 | public: |
46 | JSDialogSender(VclPtr<vcl::Window> aOwnedToplevel) |
47 | : mpIdleNotify(new JSDialogNotifyIdle(aOwnedToplevel)) |
48 | { |
49 | } |
50 | |
51 | void notifyDialogState(bool bForce = false); |
52 | }; |
53 | |
54 | class JSInstanceBuilder : public SalInstanceBuilder |
55 | { |
56 | sal_uInt64 m_nWindowId; |
57 | /// used in case of tab pages where dialog is not a direct top level |
58 | VclPtr<vcl::Window> m_aParentDialog; |
59 | bool m_bHasTopLevelDialog; |
60 | bool m_bIsNotebookbar; |
61 | |
62 | friend VCL_DLLPUBLIC__attribute__ ((visibility("default"))) bool jsdialog::ExecuteAction(sal_uInt64 nWindowId, const OString& rWidget, |
63 | StringMap& rData); |
64 | |
65 | static std::map<sal_uInt64, WidgetMap>& GetLOKWeldWidgetsMap(); |
66 | static void InsertWindowToMap(sal_uInt64 nWindowId); |
67 | void RememberWidget(const OString& id, weld::Widget* pWidget); |
68 | static weld::Widget* FindWeldWidgetsMap(sal_uInt64 nWindowId, const OString& rWidget); |
69 | |
70 | public: |
71 | JSInstanceBuilder(weld::Widget* pParent, const OUString& rUIRoot, const OUString& rUIFile); |
72 | /// optional nWindowId is used if getting parent id failed |
73 | JSInstanceBuilder(vcl::Window* pParent, const OUString& rUIRoot, const OUString& rUIFile, |
74 | const css::uno::Reference<css::frame::XFrame>& rFrame, |
75 | sal_uInt64 nWindowId = 0); |
76 | virtual ~JSInstanceBuilder() override; |
77 | virtual std::unique_ptr<weld::Dialog> weld_dialog(const OString& id) override; |
78 | virtual std::unique_ptr<weld::Label> weld_label(const OString& id) override; |
79 | virtual std::unique_ptr<weld::Button> weld_button(const OString& id) override; |
80 | virtual std::unique_ptr<weld::Entry> weld_entry(const OString& id) override; |
81 | virtual std::unique_ptr<weld::ComboBox> weld_combo_box(const OString& id) override; |
82 | virtual std::unique_ptr<weld::Notebook> weld_notebook(const OString& id) override; |
83 | virtual std::unique_ptr<weld::SpinButton> weld_spin_button(const OString& id) override; |
84 | virtual std::unique_ptr<weld::CheckButton> weld_check_button(const OString& id) override; |
85 | virtual std::unique_ptr<weld::DrawingArea> |
86 | weld_drawing_area(const OString& id, const a11yref& rA11yImpl = nullptr, |
87 | FactoryFunction pUITestFactoryFunction = nullptr, |
88 | void* pUserData = nullptr) override; |
89 | std::unique_ptr<weld::Toolbar> weld_toolbar(const OString& id) override; |
90 | std::unique_ptr<weld::TextView> weld_text_view(const OString& id) override; |
91 | |
92 | static weld::MessageDialog* CreateMessageDialog(weld::Widget* pParent, |
93 | VclMessageType eMessageType, |
94 | VclButtonsType eButtonType, |
95 | const OUString& rPrimaryMessage); |
96 | }; |
97 | |
98 | template <class BaseInstanceClass, class VclClass> |
99 | class JSWidget : public BaseInstanceClass, public JSDialogSender |
100 | { |
101 | public: |
102 | JSWidget(VclPtr<vcl::Window> aOwnedToplevel, VclClass* pObject, SalInstanceBuilder* pBuilder, |
103 | bool bTakeOwnership) |
104 | : BaseInstanceClass(pObject, pBuilder, bTakeOwnership) |
105 | , JSDialogSender(aOwnedToplevel) |
106 | { |
107 | } |
108 | |
109 | virtual void show() override |
110 | { |
111 | BaseInstanceClass::show(); |
112 | notifyDialogState(); |
113 | } |
114 | |
115 | virtual void hide() override |
116 | { |
117 | BaseInstanceClass::hide(); |
118 | notifyDialogState(); |
119 | } |
120 | |
121 | virtual void set_sensitive(bool sensitive) override |
122 | { |
123 | BaseInstanceClass::set_sensitive(sensitive); |
124 | notifyDialogState(); |
125 | } |
126 | }; |
127 | |
128 | class JSDialog : public JSWidget<SalInstanceDialog, ::Dialog> |
129 | { |
130 | public: |
131 | JSDialog(VclPtr<vcl::Window> aOwnedToplevel, ::Dialog* pDialog, SalInstanceBuilder* pBuilder, |
132 | bool bTakeOwnership); |
133 | |
134 | virtual void collapse(weld::Widget* pEdit, weld::Widget* pButton) override; |
135 | virtual void undo_collapse() override; |
136 | }; |
137 | |
138 | class JSLabel : public JSWidget<SalInstanceLabel, FixedText> |
139 | { |
140 | public: |
141 | JSLabel(VclPtr<vcl::Window> aOwnedToplevel, FixedText* pLabel, SalInstanceBuilder* pBuilder, |
142 | bool bTakeOwnership); |
143 | virtual void set_label(const OUString& rText) override; |
144 | }; |
145 | |
146 | class JSButton : public JSWidget<SalInstanceButton, ::Button> |
147 | { |
148 | public: |
149 | JSButton(VclPtr<vcl::Window> aOwnedToplevel, ::Button* pButton, SalInstanceBuilder* pBuilder, |
150 | bool bTakeOwnership); |
151 | }; |
152 | |
153 | class JSEntry : public JSWidget<SalInstanceEntry, ::Edit> |
154 | { |
155 | public: |
156 | JSEntry(VclPtr<vcl::Window> aOwnedToplevel, ::Edit* pEntry, SalInstanceBuilder* pBuilder, |
157 | bool bTakeOwnership); |
158 | virtual void set_text(const OUString& rText) override; |
159 | }; |
160 | |
161 | class JSListBox : public JSWidget<SalInstanceComboBoxWithoutEdit, ::ListBox> |
162 | { |
163 | public: |
164 | JSListBox(VclPtr<vcl::Window> aOwnedToplevel, ::ListBox* pListBox, SalInstanceBuilder* pBuilder, |
165 | bool bTakeOwnership); |
166 | virtual void insert(int pos, const OUString& rStr, const OUString* pId, |
167 | const OUString* pIconName, VirtualDevice* pImageSurface) override; |
168 | virtual void remove(int pos) override; |
169 | virtual void set_active(int pos) override; |
170 | }; |
171 | |
172 | class JSComboBox : public JSWidget<SalInstanceComboBoxWithEdit, ::ComboBox> |
173 | { |
174 | public: |
175 | JSComboBox(VclPtr<vcl::Window> aOwnedToplevel, ::ComboBox* pComboBox, |
176 | SalInstanceBuilder* pBuilder, bool bTakeOwnership); |
177 | virtual void insert(int pos, const OUString& rStr, const OUString* pId, |
178 | const OUString* pIconName, VirtualDevice* pImageSurface) override; |
179 | virtual void remove(int pos) override; |
180 | virtual void set_entry_text(const OUString& rText) override; |
181 | virtual void set_active(int pos) override; |
182 | }; |
183 | |
184 | class JSNotebook : public JSWidget<SalInstanceNotebook, ::TabControl> |
185 | { |
186 | public: |
187 | JSNotebook(VclPtr<vcl::Window> aOwnedToplevel, ::TabControl* pControl, |
188 | SalInstanceBuilder* pBuilder, bool bTakeOwnership); |
189 | |
190 | virtual void set_current_page(int nPage) override; |
191 | |
192 | virtual void set_current_page(const OString& rIdent) override; |
193 | |
194 | virtual void remove_page(const OString& rIdent) override; |
195 | |
196 | virtual void insert_page(const OString& rIdent, const OUString& rLabel, int nPos) override; |
197 | }; |
198 | |
199 | class JSSpinButton : public JSWidget<SalInstanceSpinButton, ::FormattedField> |
200 | { |
201 | public: |
202 | JSSpinButton(VclPtr<vcl::Window> aOwnedToplevel, ::FormattedField* pSpin, |
203 | SalInstanceBuilder* pBuilder, bool bTakeOwnership); |
204 | |
205 | virtual void set_value(int value) override; |
206 | }; |
207 | |
208 | class JSMessageDialog : public SalInstanceMessageDialog, public JSDialogSender |
209 | { |
210 | public: |
211 | JSMessageDialog(::MessageDialog* pDialog, SalInstanceBuilder* pBuilder, bool bTakeOwnership); |
212 | |
213 | virtual void set_primary_text(const OUString& rText) override; |
214 | |
215 | virtual void set_secondary_text(const OUString& rText) override; |
216 | }; |
217 | |
218 | class JSCheckButton : public JSWidget<SalInstanceCheckButton, ::CheckBox> |
219 | { |
220 | public: |
221 | JSCheckButton(VclPtr<vcl::Window> aOwnedToplevel, ::CheckBox* pCheckBox, |
222 | SalInstanceBuilder* pBuilder, bool bTakeOwnership); |
223 | |
224 | virtual void set_active(bool active) override; |
225 | }; |
226 | |
227 | class JSDrawingArea : public SalInstanceDrawingArea, public JSDialogSender |
228 | { |
229 | public: |
230 | JSDrawingArea(VclPtr<vcl::Window> aOwnedToplevel, VclDrawingArea* pDrawingArea, |
231 | SalInstanceBuilder* pBuilder, const a11yref& rAlly, |
232 | FactoryFunction pUITestFactoryFunction, void* pUserData); |
233 | |
234 | virtual void queue_draw() override; |
235 | virtual void queue_draw_area(int x, int y, int width, int height) override; |
236 | }; |
237 | |
238 | class JSToolbar : public JSWidget<SalInstanceToolbar, ::ToolBox> |
239 | { |
240 | public: |
241 | JSToolbar(VclPtr<vcl::Window> aOwnedToplevel, ::ToolBox* pToolbox, SalInstanceBuilder* pBuilder, |
242 | bool bTakeOwnership); |
243 | |
244 | virtual void signal_clicked(const OString& rIdent) override; |
245 | }; |
246 | |
247 | class JSTextView : public JSWidget<SalInstanceTextView, ::VclMultiLineEdit> |
248 | { |
249 | public: |
250 | JSTextView(VclPtr<vcl::Window> aOwnedToplevel, ::VclMultiLineEdit* pTextView, |
251 | SalInstanceBuilder* pBuilder, bool bTakeOwnership); |
252 | virtual void set_text(const OUString& rText) override; |
253 | }; |
254 | |
255 | /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ |
1 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | /* |
3 | * This file is part of the LibreOffice project. |
4 | * |
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 | * |
9 | * This file incorporates work covered by the following license notice: |
10 | * |
11 | * Licensed to the Apache Software Foundation (ASF) under one or more |
12 | * contributor license agreements. See the NOTICE file distributed |
13 | * with this work for additional information regarding copyright |
14 | * ownership. The ASF licenses this file to you under the Apache |
15 | * License, Version 2.0 (the "License"); you may not use this file |
16 | * except in compliance with the License. You may obtain a copy of |
17 | * the License at http://www.apache.org/licenses/LICENSE-2.0 . |
18 | */ |
19 | #ifndef INCLUDED_VCL_Reference_HXX |
20 | #define INCLUDED_VCL_Reference_HXX |
21 | |
22 | #include <vcl/dllapi.h> |
23 | #include <osl/interlck.h> |
24 | |
25 | class VCL_DLLPUBLIC__attribute__ ((visibility("default"))) VclReferenceBase |
26 | { |
27 | mutable oslInterlockedCount mnRefCnt; |
28 | |
29 | template<typename T> friend class VclPtr; |
30 | |
31 | public: |
32 | void acquire() const |
33 | { |
34 | osl_atomic_increment(&mnRefCnt)__sync_add_and_fetch((&mnRefCnt), 1); |
35 | } |
36 | |
37 | void release() const |
38 | { |
39 | if (osl_atomic_decrement(&mnRefCnt)__sync_sub_and_fetch((&mnRefCnt), 1) == 0) |
40 | delete this; |
41 | } |
42 | #ifdef DBG_UTIL |
43 | #ifndef _WIN32 |
44 | sal_Int32 getRefCount() const { return mnRefCnt; } |
45 | #endif |
46 | #endif |
47 | |
48 | |
49 | private: |
50 | VclReferenceBase(const VclReferenceBase&) = delete; |
51 | VclReferenceBase& operator=(const VclReferenceBase&) = delete; |
52 | |
53 | bool mbDisposed : 1; |
54 | |
55 | protected: |
56 | VclReferenceBase(); |
57 | protected: |
58 | virtual ~VclReferenceBase(); |
59 | |
60 | protected: |
61 | virtual void dispose(); |
62 | |
63 | public: |
64 | void disposeOnce(); |
65 | bool isDisposed() const { return mbDisposed; } |
66 | |
67 | }; |
68 | #endif |