bump product version to 7.6.3.2-android
[LibreOffice.git] / vcl / jsdialog / jsdialogbuilder.cxx
blobb894395e4660997d78e614a2164492eba07f13b0
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 <sal/log.hxx>
12 #include <comphelper/lok.hxx>
13 #include <utility>
14 #include <vcl/tabpage.hxx>
15 #include <vcl/toolkit/button.hxx>
16 #include <vcl/toolkit/dialog.hxx>
17 #include <LibreOfficeKit/LibreOfficeKitEnums.h>
18 #include <vcl/toolkit/combobox.hxx>
19 #include <messagedialog.hxx>
20 #include <tools/json_writer.hxx>
21 #include <o3tl/deleter.hxx>
22 #include <memory>
23 #include <vcl/toolbox.hxx>
24 #include <vcl/toolkit/vclmedit.hxx>
25 #include <boost/property_tree/json_parser.hpp>
26 #include <vcl/toolkit/treelistentry.hxx>
27 #include <vcl/jsdialog/executor.hxx>
28 #include <cppuhelper/supportsservice.hxx>
29 #include <wizdlg.hxx>
31 static std::map<OUString, vcl::Window*>& GetLOKPopupsMap()
33 // Map to remember the LOKWindowId <-> vcl popup binding.
34 static std::map<OUString, vcl::Window*> s_aLOKPopupsMap;
36 return s_aLOKPopupsMap;
39 namespace
41 void response_help(vcl::Window* pWindow)
43 ::Dialog* pDialog = dynamic_cast<::Dialog*>(pWindow);
44 if (!pDialog)
45 return;
47 vcl::Window* pButtonWindow = pDialog->get_widget_for_response(RET_HELP);
48 ::Button* pButton = dynamic_cast<::Button*>(pButtonWindow);
49 if (!pButton)
50 return;
52 pButton->Click();
56 JSDialogNotifyIdle::JSDialogNotifyIdle(VclPtr<vcl::Window> aNotifierWindow,
57 VclPtr<vcl::Window> aContentWindow,
58 const OUString& sTypeOfJSON)
59 : Idle("JSDialog notify")
60 , m_aNotifierWindow(std::move(aNotifierWindow))
61 , m_aContentWindow(std::move(aContentWindow))
62 , m_sTypeOfJSON(sTypeOfJSON)
63 , m_bForce(false)
65 SetPriority(TaskPriority::POST_PAINT);
68 void JSDialogNotifyIdle::forceUpdate() { m_bForce = true; }
70 void JSDialogNotifyIdle::send(tools::JsonWriter& aJsonWriter)
72 if (!m_aNotifierWindow)
74 aJsonWriter.finishAndGetAsOString();
75 return;
78 const vcl::ILibreOfficeKitNotifier* pNotifier = m_aNotifierWindow->GetLOKNotifier();
79 if (pNotifier)
81 if (m_bForce || !aJsonWriter.isDataEquals(m_LastNotificationMessage))
83 m_bForce = false;
84 m_LastNotificationMessage = aJsonWriter.finishAndGetAsOString();
85 pNotifier->libreOfficeKitViewCallback(LOK_CALLBACK_JSDIALOG, m_LastNotificationMessage);
87 else
89 aJsonWriter.finishAndGetAsOString();
92 else
94 aJsonWriter.finishAndGetAsOString();
98 namespace
100 OUString extractActionType(const jsdialog::ActionDataMap& rData)
102 auto it = rData.find(ACTION_TYPE);
103 if (it != rData.end())
104 return it->second;
105 return "";
109 void JSDialogNotifyIdle::sendMessage(jsdialog::MessageType eType, VclPtr<vcl::Window> pWindow,
110 std::unique_ptr<jsdialog::ActionDataMap> pData)
112 std::scoped_lock aGuard(m_aQueueMutex);
114 // we want only the latest update of same type
115 // TODO: also if we met full update - previous updates are not valid
116 auto it = m_aMessageQueue.begin();
118 while (it != m_aMessageQueue.end())
120 if (it->m_eType == eType && it->m_pWindow == pWindow)
122 if (it->m_pData && pData
123 && extractActionType(*it->m_pData) != extractActionType(*pData))
125 it++;
126 continue;
128 it = m_aMessageQueue.erase(it);
130 else
131 it++;
134 JSDialogMessageInfo aMessage(eType, pWindow, std::move(pData));
135 m_aMessageQueue.push_back(aMessage);
138 std::unique_ptr<tools::JsonWriter> JSDialogNotifyIdle::generateFullUpdate() const
140 std::unique_ptr<tools::JsonWriter> aJsonWriter(new tools::JsonWriter());
142 if (!m_aContentWindow || !m_aNotifierWindow)
143 return aJsonWriter;
145 m_aContentWindow->DumpAsPropertyTree(*aJsonWriter);
146 if (m_aNotifierWindow)
147 aJsonWriter->put("id", m_aNotifierWindow->GetLOKWindowId());
148 aJsonWriter->put("jsontype", m_sTypeOfJSON);
150 return aJsonWriter;
153 std::unique_ptr<tools::JsonWriter>
154 JSDialogNotifyIdle::generateWidgetUpdate(VclPtr<vcl::Window> pWindow) const
156 std::unique_ptr<tools::JsonWriter> aJsonWriter(new tools::JsonWriter());
158 if (!pWindow || !m_aNotifierWindow)
159 return aJsonWriter;
161 aJsonWriter->put("jsontype", m_sTypeOfJSON);
162 aJsonWriter->put("action", "update");
163 if (m_aNotifierWindow)
164 aJsonWriter->put("id", m_aNotifierWindow->GetLOKWindowId());
166 auto aEntries = aJsonWriter->startNode("control");
167 pWindow->DumpAsPropertyTree(*aJsonWriter);
170 return aJsonWriter;
173 std::unique_ptr<tools::JsonWriter> JSDialogNotifyIdle::generateCloseMessage() const
175 std::unique_ptr<tools::JsonWriter> aJsonWriter(new tools::JsonWriter());
176 if (m_aNotifierWindow)
177 aJsonWriter->put("id", m_aNotifierWindow->GetLOKWindowId());
178 aJsonWriter->put("jsontype", m_sTypeOfJSON);
179 aJsonWriter->put("action", "close");
181 return aJsonWriter;
184 std::unique_ptr<tools::JsonWriter>
185 JSDialogNotifyIdle::generateActionMessage(VclPtr<vcl::Window> pWindow,
186 std::unique_ptr<jsdialog::ActionDataMap> pData) const
188 std::unique_ptr<tools::JsonWriter> aJsonWriter(new tools::JsonWriter());
190 aJsonWriter->put("jsontype", m_sTypeOfJSON);
191 aJsonWriter->put("action", "action");
192 if (m_aNotifierWindow)
193 aJsonWriter->put("id", m_aNotifierWindow->GetLOKWindowId());
196 auto aDataNode = aJsonWriter->startNode("data");
197 aJsonWriter->put("control_id", pWindow->get_id());
199 for (auto it = pData->begin(); it != pData->end(); it++)
200 aJsonWriter->put(it->first, it->second);
203 return aJsonWriter;
206 std::unique_ptr<tools::JsonWriter>
207 JSDialogNotifyIdle::generatePopupMessage(VclPtr<vcl::Window> pWindow, OUString sParentId,
208 OUString sCloseId) const
210 std::unique_ptr<tools::JsonWriter> aJsonWriter(new tools::JsonWriter());
212 if (!pWindow || !m_aNotifierWindow)
213 return aJsonWriter;
215 if (!pWindow->GetParentWithLOKNotifier())
216 return aJsonWriter;
219 auto aChildren = aJsonWriter->startArray("children");
221 auto aStruct = aJsonWriter->startStruct();
222 pWindow->DumpAsPropertyTree(*aJsonWriter);
226 // try to get the position eg. for the autofilter
228 vcl::Window* pVclWindow = pWindow.get();
229 DockingWindow* pDockingWindow = dynamic_cast<DockingWindow*>(pVclWindow);
230 while (pVclWindow && !pDockingWindow)
232 pVclWindow = pVclWindow->GetParent();
233 pDockingWindow = dynamic_cast<DockingWindow*>(pVclWindow);
236 if (pDockingWindow)
238 Point aPos = pDockingWindow->GetFloatingPos();
239 aJsonWriter->put("posx", aPos.getX());
240 aJsonWriter->put("posy", aPos.getY());
241 if (!pDockingWindow->IsVisible())
242 aJsonWriter->put("visible", "false");
246 aJsonWriter->put("jsontype", "dialog");
247 aJsonWriter->put("type", "modalpopup");
248 aJsonWriter->put("cancellable", true);
249 aJsonWriter->put("popupParent", sParentId);
250 aJsonWriter->put("clickToClose", sCloseId);
251 aJsonWriter->put("id", pWindow->GetParentWithLOKNotifier()->GetLOKWindowId());
253 return aJsonWriter;
256 std::unique_ptr<tools::JsonWriter>
257 JSDialogNotifyIdle::generateClosePopupMessage(OUString sWindowId) const
259 std::unique_ptr<tools::JsonWriter> aJsonWriter(new tools::JsonWriter());
261 if (!m_aNotifierWindow)
262 return aJsonWriter;
264 aJsonWriter->put("jsontype", "dialog");
265 aJsonWriter->put("type", "modalpopup");
266 aJsonWriter->put("action", "close");
267 aJsonWriter->put("id", sWindowId);
269 return aJsonWriter;
272 void JSDialogNotifyIdle::Invoke()
274 std::deque<JSDialogMessageInfo> aMessageQueue;
276 std::scoped_lock aGuard(m_aQueueMutex);
278 std::swap(aMessageQueue, m_aMessageQueue);
281 for (auto& rMessage : aMessageQueue)
283 jsdialog::MessageType eType = rMessage.m_eType;
285 if (m_sTypeOfJSON == "formulabar" && eType != jsdialog::MessageType::Action)
286 continue;
288 switch (eType)
290 case jsdialog::MessageType::FullUpdate:
291 send(*generateFullUpdate());
292 break;
294 case jsdialog::MessageType::WidgetUpdate:
295 send(*generateWidgetUpdate(rMessage.m_pWindow));
296 break;
298 case jsdialog::MessageType::Close:
299 send(*generateCloseMessage());
300 break;
302 case jsdialog::MessageType::Action:
303 send(*generateActionMessage(rMessage.m_pWindow, std::move(rMessage.m_pData)));
304 break;
306 case jsdialog::MessageType::Popup:
307 send(*generatePopupMessage(rMessage.m_pWindow, (*rMessage.m_pData)[PARENT_ID],
308 (*rMessage.m_pData)[CLOSE_ID]));
309 break;
311 case jsdialog::MessageType::PopupClose:
312 send(*generateClosePopupMessage((*rMessage.m_pData)[WINDOW_ID]));
313 break;
318 void JSDialogNotifyIdle::clearQueue() { m_aMessageQueue.clear(); }
320 JSDialogSender::~JSDialogSender() COVERITY_NOEXCEPT_FALSE
322 sendClose();
324 if (mpIdleNotify)
325 mpIdleNotify->Stop();
328 void JSDialogSender::sendFullUpdate(bool bForce)
330 if (!mpIdleNotify)
331 return;
333 if (bForce)
334 mpIdleNotify->forceUpdate();
336 mpIdleNotify->sendMessage(jsdialog::MessageType::FullUpdate, nullptr);
337 mpIdleNotify->Start();
340 void JSDialogSender::sendClose()
342 if (!mpIdleNotify || !m_bCanClose)
343 return;
345 mpIdleNotify->clearQueue();
346 mpIdleNotify->sendMessage(jsdialog::MessageType::Close, nullptr);
347 flush();
350 void JSDialogSender::sendUpdate(VclPtr<vcl::Window> pWindow, bool bForce)
352 if (!mpIdleNotify)
353 return;
355 if (bForce)
356 mpIdleNotify->forceUpdate();
358 mpIdleNotify->sendMessage(jsdialog::MessageType::WidgetUpdate, pWindow);
359 mpIdleNotify->Start();
362 void JSDialogSender::sendAction(VclPtr<vcl::Window> pWindow,
363 std::unique_ptr<jsdialog::ActionDataMap> pData)
365 if (!mpIdleNotify)
366 return;
368 mpIdleNotify->sendMessage(jsdialog::MessageType::Action, pWindow, std::move(pData));
369 mpIdleNotify->Start();
372 void JSDialogSender::sendPopup(VclPtr<vcl::Window> pWindow, OUString sParentId, OUString sCloseId)
374 if (!mpIdleNotify)
375 return;
377 std::unique_ptr<jsdialog::ActionDataMap> pData = std::make_unique<jsdialog::ActionDataMap>();
378 (*pData)[PARENT_ID] = sParentId;
379 (*pData)[CLOSE_ID] = sCloseId;
380 mpIdleNotify->sendMessage(jsdialog::MessageType::Popup, pWindow, std::move(pData));
381 mpIdleNotify->Start();
384 void JSDialogSender::sendClosePopup(vcl::LOKWindowId nWindowId)
386 if (!mpIdleNotify)
387 return;
389 std::unique_ptr<jsdialog::ActionDataMap> pData = std::make_unique<jsdialog::ActionDataMap>();
390 (*pData)[WINDOW_ID] = OUString::number(nWindowId);
391 mpIdleNotify->sendMessage(jsdialog::MessageType::PopupClose, nullptr, std::move(pData));
392 flush();
395 namespace
397 vcl::Window* extract_sal_widget(weld::Widget* pParent)
399 SalInstanceWidget* pInstanceWidget = dynamic_cast<SalInstanceWidget*>(pParent);
400 return pInstanceWidget ? pInstanceWidget->getWidget() : nullptr;
404 // Drag and drop
406 namespace
408 class JSDropTargetDropContext
409 : public cppu::WeakImplHelper<css::datatransfer::dnd::XDropTargetDropContext>
411 public:
412 JSDropTargetDropContext() {}
414 // XDropTargetDropContext
415 virtual void SAL_CALL acceptDrop(sal_Int8 /*dragOperation*/) override {}
417 virtual void SAL_CALL rejectDrop() override {}
419 virtual void SAL_CALL dropComplete(sal_Bool /*bSuccess*/) override {}
423 static JSTreeView* g_DragSource;
425 JSDropTarget::JSDropTarget() {}
427 void JSDropTarget::initialize(const css::uno::Sequence<css::uno::Any>& /*rArgs*/) {}
429 void JSDropTarget::addDropTargetListener(
430 const css::uno::Reference<css::datatransfer::dnd::XDropTargetListener>& xListener)
432 std::unique_lock aGuard(m_aMutex);
434 m_aListeners.push_back(xListener);
437 void JSDropTarget::removeDropTargetListener(
438 const css::uno::Reference<css::datatransfer::dnd::XDropTargetListener>& xListener)
440 std::unique_lock aGuard(m_aMutex);
442 m_aListeners.erase(std::remove(m_aListeners.begin(), m_aListeners.end(), xListener),
443 m_aListeners.end());
446 sal_Bool JSDropTarget::isActive() { return false; }
448 void JSDropTarget::setActive(sal_Bool /*active*/) {}
450 sal_Int8 JSDropTarget::getDefaultActions() { return 0; }
452 void JSDropTarget::setDefaultActions(sal_Int8 /*actions*/) {}
454 OUString JSDropTarget::getImplementationName()
456 return "com.sun.star.datatransfer.dnd.JSDropTarget";
459 sal_Bool JSDropTarget::supportsService(OUString const& ServiceName)
461 return cppu::supportsService(this, ServiceName);
464 css::uno::Sequence<OUString> JSDropTarget::getSupportedServiceNames()
466 css::uno::Sequence<OUString> aRet{ "com.sun.star.datatransfer.dnd.JSDropTarget" };
467 return aRet;
470 void JSDropTarget::fire_drop(const css::datatransfer::dnd::DropTargetDropEvent& dtde)
472 std::unique_lock aGuard(m_aMutex);
473 std::vector<css::uno::Reference<css::datatransfer::dnd::XDropTargetListener>> aListeners(
474 m_aListeners);
475 aGuard.unlock();
477 for (auto const& listener : aListeners)
479 listener->drop(dtde);
483 void JSDropTarget::fire_dragEnter(const css::datatransfer::dnd::DropTargetDragEnterEvent& dtde)
485 std::unique_lock aGuard(m_aMutex);
486 std::vector<css::uno::Reference<css::datatransfer::dnd::XDropTargetListener>> aListeners(
487 m_aListeners);
488 aGuard.unlock();
490 for (auto const& listener : aListeners)
492 listener->dragEnter(dtde);
496 OUString JSInstanceBuilder::getMapIdFromWindowId() const
498 if (m_sTypeOfJSON == "sidebar" || m_sTypeOfJSON == "notebookbar"
499 || m_sTypeOfJSON == "formulabar")
500 return OUString::number(m_nWindowId) + m_sTypeOfJSON;
501 else
502 return OUString::number(m_nWindowId);
505 // used for dialogs
506 JSInstanceBuilder::JSInstanceBuilder(weld::Widget* pParent, const OUString& rUIRoot,
507 const OUString& rUIFile, bool bPopup)
508 : SalInstanceBuilder(extract_sal_widget(pParent), rUIRoot, rUIFile)
509 , m_nWindowId(0)
510 , m_aParentDialog(nullptr)
511 , m_aContentWindow(nullptr)
512 , m_sTypeOfJSON("dialog")
513 , m_bHasTopLevelDialog(false)
514 , m_bIsNotebookbar(false)
515 , m_bSentInitialUpdate(false)
516 , m_bIsNestedBuilder(false)
517 , m_aWindowToRelease(nullptr)
519 // when it is a popup we initialize sender in weld_popover
520 if (bPopup)
522 m_sTypeOfJSON = "popup";
523 return;
526 vcl::Window* pRoot = m_xBuilder->get_widget_root();
528 if (pRoot && pRoot->GetParent())
530 m_aParentDialog = pRoot->GetParent()->GetParentWithLOKNotifier();
531 if (m_aParentDialog)
532 m_nWindowId = m_aParentDialog->GetLOKWindowId();
533 InsertWindowToMap(getMapIdFromWindowId());
536 initializeSender(GetNotifierWindow(), GetContentWindow(), GetTypeOfJSON());
539 // used for sidebar panels
540 JSInstanceBuilder::JSInstanceBuilder(weld::Widget* pParent, const OUString& rUIRoot,
541 const OUString& rUIFile, sal_uInt64 nLOKWindowId)
542 : SalInstanceBuilder(extract_sal_widget(pParent), rUIRoot, rUIFile)
543 , m_nWindowId(nLOKWindowId)
544 , m_aParentDialog(nullptr)
545 , m_aContentWindow(nullptr)
546 , m_sTypeOfJSON("sidebar")
547 , m_bHasTopLevelDialog(false)
548 , m_bIsNotebookbar(false)
549 , m_bSentInitialUpdate(false)
550 , m_bIsNestedBuilder(false)
551 , m_aWindowToRelease(nullptr)
553 vcl::Window* pRoot = m_xBuilder->get_widget_root();
555 m_aParentDialog = pRoot->GetParentWithLOKNotifier();
557 if (rUIFile == "sfx/ui/panel.ui")
559 // builder for Panel, get SidebarDockingWindow as m_aContentWindow
560 m_aContentWindow = pRoot;
561 for (int i = 0; i < 7 && m_aContentWindow; i++)
562 m_aContentWindow = m_aContentWindow->GetParent();
564 else
566 // embedded fragments cannot send close message for whole sidebar
567 if (rUIFile == "modules/simpress/ui/customanimationfragment.ui")
568 m_bCanClose = false;
570 // builder for PanelLayout, get SidebarDockingWindow as m_aContentWindow
571 m_aContentWindow = pRoot;
572 for (int i = 0; i < 9 && m_aContentWindow; i++)
573 m_aContentWindow = m_aContentWindow->GetParent();
576 InsertWindowToMap(getMapIdFromWindowId());
578 initializeSender(GetNotifierWindow(), GetContentWindow(), GetTypeOfJSON());
581 // used for notebookbar
582 JSInstanceBuilder::JSInstanceBuilder(vcl::Window* pParent, const OUString& rUIRoot,
583 const OUString& rUIFile,
584 const css::uno::Reference<css::frame::XFrame>& rFrame,
585 sal_uInt64 nWindowId)
586 : SalInstanceBuilder(pParent, rUIRoot, rUIFile, rFrame)
587 , m_nWindowId(0)
588 , m_aParentDialog(nullptr)
589 , m_aContentWindow(nullptr)
590 , m_sTypeOfJSON("notebookbar")
591 , m_bHasTopLevelDialog(false)
592 , m_bIsNotebookbar(false)
593 , m_bSentInitialUpdate(false)
594 , m_bIsNestedBuilder(false)
595 , m_aWindowToRelease(nullptr)
597 vcl::Window* pRoot = m_xBuilder->get_widget_root();
598 if (pRoot && pRoot->GetParent())
600 m_aParentDialog = pRoot->GetParent()->GetParentWithLOKNotifier();
601 if (m_aParentDialog)
602 m_nWindowId = m_aParentDialog->GetLOKWindowId();
603 if (!m_nWindowId && nWindowId)
605 m_nWindowId = nWindowId;
606 m_bIsNotebookbar = true;
608 InsertWindowToMap(getMapIdFromWindowId());
611 initializeSender(GetNotifierWindow(), GetContentWindow(), GetTypeOfJSON());
614 // used for formulabar
615 JSInstanceBuilder::JSInstanceBuilder(vcl::Window* pParent, const OUString& rUIRoot,
616 const OUString& rUIFile, sal_uInt64 nLOKWindowId)
617 : SalInstanceBuilder(pParent, rUIRoot, rUIFile)
618 , m_nWindowId(nLOKWindowId)
619 , m_aParentDialog(nullptr)
620 , m_aContentWindow(nullptr)
621 , m_sTypeOfJSON("formulabar")
622 , m_bHasTopLevelDialog(false)
623 , m_bIsNotebookbar(false)
624 , m_bSentInitialUpdate(false)
625 , m_bIsNestedBuilder(false)
626 , m_aWindowToRelease(nullptr)
628 vcl::Window* pRoot = m_xBuilder->get_widget_root();
629 m_aContentWindow = pParent;
630 if (pRoot && pRoot->GetParent())
632 m_aParentDialog = pRoot->GetParent()->GetParentWithLOKNotifier();
633 InsertWindowToMap(getMapIdFromWindowId());
636 initializeSender(GetNotifierWindow(), GetContentWindow(), GetTypeOfJSON());
639 std::unique_ptr<JSInstanceBuilder> JSInstanceBuilder::CreateDialogBuilder(weld::Widget* pParent,
640 const OUString& rUIRoot,
641 const OUString& rUIFile)
643 return std::make_unique<JSInstanceBuilder>(pParent, rUIRoot, rUIFile);
646 std::unique_ptr<JSInstanceBuilder> JSInstanceBuilder::CreateNotebookbarBuilder(
647 vcl::Window* pParent, const OUString& rUIRoot, const OUString& rUIFile,
648 const css::uno::Reference<css::frame::XFrame>& rFrame, sal_uInt64 nWindowId)
650 return std::make_unique<JSInstanceBuilder>(pParent, rUIRoot, rUIFile, rFrame, nWindowId);
653 std::unique_ptr<JSInstanceBuilder> JSInstanceBuilder::CreateSidebarBuilder(weld::Widget* pParent,
654 const OUString& rUIRoot,
655 const OUString& rUIFile,
656 sal_uInt64 nLOKWindowId)
658 return std::make_unique<JSInstanceBuilder>(pParent, rUIRoot, rUIFile, nLOKWindowId);
661 std::unique_ptr<JSInstanceBuilder> JSInstanceBuilder::CreatePopupBuilder(weld::Widget* pParent,
662 const OUString& rUIRoot,
663 const OUString& rUIFile)
665 return std::make_unique<JSInstanceBuilder>(pParent, rUIRoot, rUIFile, true);
668 std::unique_ptr<JSInstanceBuilder>
669 JSInstanceBuilder::CreateFormulabarBuilder(vcl::Window* pParent, const OUString& rUIRoot,
670 const OUString& rUIFile, sal_uInt64 nLOKWindowId)
672 return std::make_unique<JSInstanceBuilder>(pParent, rUIRoot, rUIFile, nLOKWindowId);
675 JSInstanceBuilder::~JSInstanceBuilder()
677 // tab page closed -> refresh parent window
678 if (m_bIsNestedBuilder && m_sTypeOfJSON == "dialog")
680 sendFullUpdate(true);
681 flush();
684 if (m_sTypeOfJSON == "popup")
685 sendClosePopup(m_nWindowId);
687 if (m_aWindowToRelease)
689 m_aWindowToRelease->ReleaseLOKNotifier();
690 m_aWindowToRelease.clear();
693 if (m_nWindowId && (m_bHasTopLevelDialog || m_bIsNotebookbar))
695 GetLOKWeldWidgetsMap().erase(getMapIdFromWindowId());
697 else
699 auto it = GetLOKWeldWidgetsMap().find(getMapIdFromWindowId());
700 if (it != GetLOKWeldWidgetsMap().end())
702 std::for_each(m_aRememberedWidgets.begin(), m_aRememberedWidgets.end(),
703 [it](const OUString& sId) { it->second.erase(sId); });
707 GetLOKPopupsMap().erase(OUString::number(m_nWindowId));
710 std::map<OUString, WidgetMap>& JSInstanceBuilder::GetLOKWeldWidgetsMap()
712 // Map to remember the LOKWindowId <-> weld widgets binding.
713 static std::map<OUString, WidgetMap> s_aLOKWeldBuildersMap;
715 return s_aLOKWeldBuildersMap;
718 weld::Widget* JSInstanceBuilder::FindWeldWidgetsMap(const OUString& nWindowId,
719 const OUString& rWidget)
721 const auto it = GetLOKWeldWidgetsMap().find(nWindowId);
723 if (it != GetLOKWeldWidgetsMap().end())
725 auto widgetIt = it->second.find(rWidget);
726 if (widgetIt != it->second.end())
727 return widgetIt->second;
730 return nullptr;
733 void JSInstanceBuilder::InsertWindowToMap(const OUString& nWindowId)
735 WidgetMap map;
736 auto it = GetLOKWeldWidgetsMap().find(nWindowId);
737 if (it == GetLOKWeldWidgetsMap().end())
738 GetLOKWeldWidgetsMap().insert({ nWindowId, map });
741 void JSInstanceBuilder::RememberWidget(OUString sId, weld::Widget* pWidget)
743 // do not use the same id for two widgets inside one builder
744 // exception is sidebar where we base our full invalidation on that "Panel" id sharing
745 if (m_sTypeOfJSON != "sidebar")
747 static std::atomic<unsigned long long int> nNotRepeatIndex = 0;
748 auto aWindowIt = GetLOKWeldWidgetsMap().find(getMapIdFromWindowId());
749 if (aWindowIt != GetLOKWeldWidgetsMap().end())
751 auto aWidgetIt = aWindowIt->second.find(sId);
752 if (aWidgetIt != aWindowIt->second.end())
754 unsigned long long int nIndex = nNotRepeatIndex++;
755 // found duplicated it -> add some number to the id and apply to the widget
756 sId = sId + OUString::number(nIndex);
757 SalInstanceWidget* pSalWidget = dynamic_cast<SalInstanceWidget*>(pWidget);
758 assert(pSalWidget && "can only be a SalInstanceWidget");
759 vcl::Window* pVclWidget = pSalWidget->getWidget();
760 pVclWidget->set_id(pVclWidget->get_id() + OUString::number(nIndex));
765 RememberWidget(getMapIdFromWindowId(), sId, pWidget);
766 m_aRememberedWidgets.push_back(sId);
769 void JSInstanceBuilder::RememberWidget(const OUString& nWindowId, const OUString& id,
770 weld::Widget* pWidget)
772 auto it = GetLOKWeldWidgetsMap().find(nWindowId);
773 if (it != GetLOKWeldWidgetsMap().end())
775 it->second.erase(id);
776 it->second.insert(WidgetMap::value_type(id, pWidget));
780 void JSInstanceBuilder::AddChildWidget(const OUString& nWindowId, const OUString& id,
781 weld::Widget* pWidget)
783 auto it = GetLOKWeldWidgetsMap().find(nWindowId);
784 if (it != GetLOKWeldWidgetsMap().end())
786 it->second.erase(id);
787 it->second.insert(WidgetMap::value_type(id, pWidget));
791 void JSInstanceBuilder::RemoveWindowWidget(const OUString& nWindowId)
793 auto it = JSInstanceBuilder::GetLOKWeldWidgetsMap().find(nWindowId);
794 if (it != JSInstanceBuilder::GetLOKWeldWidgetsMap().end())
796 JSInstanceBuilder::GetLOKWeldWidgetsMap().erase(it);
800 void JSInstanceBuilder::RememberPopup(const OUString& nWindowId, VclPtr<vcl::Window> pWidget)
802 GetLOKPopupsMap()[nWindowId] = pWidget;
805 void JSInstanceBuilder::ForgetPopup(const OUString& nWindowId)
807 auto it = GetLOKPopupsMap().find(nWindowId);
808 if (it != GetLOKPopupsMap().end())
809 GetLOKPopupsMap().erase(it);
812 vcl::Window* JSInstanceBuilder::FindPopup(const OUString& nWindowId)
814 const auto it = GetLOKPopupsMap().find(nWindowId);
816 if (it != GetLOKPopupsMap().end())
817 return it->second;
819 return nullptr;
822 const OUString& JSInstanceBuilder::GetTypeOfJSON() const { return m_sTypeOfJSON; }
824 VclPtr<vcl::Window>& JSInstanceBuilder::GetContentWindow()
826 if (m_aContentWindow)
827 return m_aContentWindow;
828 else
829 return m_bHasTopLevelDialog ? m_aOwnedToplevel : m_aParentDialog;
832 VclPtr<vcl::Window>& JSInstanceBuilder::GetNotifierWindow()
834 return m_bHasTopLevelDialog ? m_aOwnedToplevel : m_aParentDialog;
837 std::unique_ptr<weld::Dialog> JSInstanceBuilder::weld_dialog(const OUString& id)
839 std::unique_ptr<weld::Dialog> pRet;
840 ::Dialog* pDialog = m_xBuilder->get<::Dialog>(id);
842 if (pDialog)
844 m_nWindowId = pDialog->GetLOKWindowId();
845 pDialog->SetLOKTunnelingState(false);
847 InsertWindowToMap(getMapIdFromWindowId());
849 assert(!m_aOwnedToplevel && "only one toplevel per .ui allowed");
850 m_aOwnedToplevel.set(pDialog);
851 m_xBuilder->drop_ownership(pDialog);
852 m_bHasTopLevelDialog = true;
854 pRet.reset(new JSDialog(this, pDialog, this, false));
856 RememberWidget("__DIALOG__", pRet.get());
858 initializeSender(GetNotifierWindow(), GetContentWindow(), GetTypeOfJSON());
859 m_bSentInitialUpdate = true;
862 return pRet;
865 std::unique_ptr<weld::Assistant> JSInstanceBuilder::weld_assistant(const OUString& id)
867 vcl::RoadmapWizard* pDialog = m_xBuilder->get<vcl::RoadmapWizard>(id);
868 std::unique_ptr<JSAssistant> pRet(pDialog ? new JSAssistant(this, pDialog, this, false)
869 : nullptr);
870 if (pDialog)
872 m_nWindowId = pDialog->GetLOKWindowId();
873 pDialog->SetLOKTunnelingState(false);
875 InsertWindowToMap(getMapIdFromWindowId());
877 assert(!m_aOwnedToplevel && "only one toplevel per .ui allowed");
878 m_aOwnedToplevel.set(pDialog);
879 m_xBuilder->drop_ownership(pDialog);
880 m_bHasTopLevelDialog = true;
882 pRet.reset(new JSAssistant(this, pDialog, this, false));
884 RememberWidget("__DIALOG__", pRet.get());
886 initializeSender(GetNotifierWindow(), GetContentWindow(), GetTypeOfJSON());
887 m_bSentInitialUpdate = true;
890 return pRet;
893 std::unique_ptr<weld::MessageDialog> JSInstanceBuilder::weld_message_dialog(const OUString& id)
895 std::unique_ptr<weld::MessageDialog> pRet;
896 ::MessageDialog* pMessageDialog = m_xBuilder->get<::MessageDialog>(id);
898 if (pMessageDialog)
900 m_nWindowId = pMessageDialog->GetLOKWindowId();
901 pMessageDialog->SetLOKTunnelingState(false);
903 InsertWindowToMap(getMapIdFromWindowId());
905 assert(!m_aOwnedToplevel && "only one toplevel per .ui allowed");
906 m_aOwnedToplevel.set(pMessageDialog);
907 m_xBuilder->drop_ownership(pMessageDialog);
908 m_bHasTopLevelDialog = true;
910 initializeSender(GetNotifierWindow(), GetContentWindow(), GetTypeOfJSON());
911 m_bSentInitialUpdate = true;
914 pRet.reset(pMessageDialog ? new JSMessageDialog(this, pMessageDialog, this, false) : nullptr);
916 if (pRet)
917 RememberWidget("__DIALOG__", pRet.get());
919 return pRet;
922 std::unique_ptr<weld::Container> JSInstanceBuilder::weld_container(const OUString& id)
924 vcl::Window* pContainer = m_xBuilder->get<vcl::Window>(id);
925 auto pWeldWidget
926 = pContainer ? std::make_unique<JSContainer>(this, pContainer, this, false) : nullptr;
928 if (pWeldWidget)
929 RememberWidget(id, pWeldWidget.get());
931 if (!m_bSentInitialUpdate && pContainer)
933 m_bSentInitialUpdate = true;
935 // use parent builder to send update - avoid multiple calls from many builders
936 vcl::Window* pParent = pContainer->GetParent();
937 OUString sId = OUString::number(m_nWindowId);
938 while (pParent && !FindWeldWidgetsMap(sId, pParent->get_id()))
939 pParent = pParent->GetParent();
941 if (pParent)
942 jsdialog::SendFullUpdate(sId, pParent->get_id());
944 // this is nested builder, don't close parent dialog on destroy (eg. single tab page is closed)
945 m_bCanClose = false;
946 m_bIsNestedBuilder = true;
949 return pWeldWidget;
952 std::unique_ptr<weld::ScrolledWindow>
953 JSInstanceBuilder::weld_scrolled_window(const OUString& id, bool bUserManagedScrolling)
955 VclScrolledWindow* pScrolledWindow = m_xBuilder->get<VclScrolledWindow>(id);
956 auto pWeldWidget = pScrolledWindow
957 ? std::make_unique<JSScrolledWindow>(this, pScrolledWindow, this, false,
958 bUserManagedScrolling)
959 : nullptr;
961 if (pWeldWidget)
962 RememberWidget(id, pWeldWidget.get());
964 return pWeldWidget;
967 std::unique_ptr<weld::Label> JSInstanceBuilder::weld_label(const OUString& id)
969 Control* pLabel = m_xBuilder->get<Control>(id);
970 auto pWeldWidget = std::make_unique<JSLabel>(this, pLabel, this, false);
972 if (pWeldWidget)
973 RememberWidget(id, pWeldWidget.get());
975 return pWeldWidget;
978 std::unique_ptr<weld::Button> JSInstanceBuilder::weld_button(const OUString& id)
980 ::Button* pButton = m_xBuilder->get<::Button>(id);
981 auto pWeldWidget = pButton ? std::make_unique<JSButton>(this, pButton, this, false) : nullptr;
983 if (pWeldWidget)
984 RememberWidget(id, pWeldWidget.get());
986 return pWeldWidget;
989 std::unique_ptr<weld::LinkButton> JSInstanceBuilder::weld_link_button(const OUString& id)
991 ::FixedHyperlink* pButton = m_xBuilder->get<::FixedHyperlink>(id);
992 auto pWeldWidget
993 = pButton ? std::make_unique<JSLinkButton>(this, pButton, this, false) : nullptr;
995 if (pWeldWidget)
996 RememberWidget(id, pWeldWidget.get());
998 return pWeldWidget;
1001 std::unique_ptr<weld::ToggleButton> JSInstanceBuilder::weld_toggle_button(const OUString& id)
1003 ::PushButton* pButton = m_xBuilder->get<::PushButton>(id);
1004 auto pWeldWidget
1005 = pButton ? std::make_unique<JSToggleButton>(this, pButton, this, false) : nullptr;
1007 if (pWeldWidget)
1008 RememberWidget(id, pWeldWidget.get());
1010 return pWeldWidget;
1013 std::unique_ptr<weld::Entry> JSInstanceBuilder::weld_entry(const OUString& id)
1015 Edit* pEntry = m_xBuilder->get<Edit>(id);
1016 auto pWeldWidget = pEntry ? std::make_unique<JSEntry>(this, pEntry, this, false) : nullptr;
1018 if (pWeldWidget)
1019 RememberWidget(id, pWeldWidget.get());
1021 return pWeldWidget;
1024 std::unique_ptr<weld::ComboBox> JSInstanceBuilder::weld_combo_box(const OUString& id)
1026 vcl::Window* pWidget = m_xBuilder->get<vcl::Window>(id);
1027 ::ComboBox* pComboBox = dynamic_cast<::ComboBox*>(pWidget);
1028 std::unique_ptr<weld::ComboBox> pWeldWidget;
1030 if (pComboBox)
1032 pWeldWidget = std::make_unique<JSComboBox>(this, pComboBox, this, false);
1034 else
1036 ListBox* pListBox = dynamic_cast<ListBox*>(pWidget);
1037 pWeldWidget = pListBox ? std::make_unique<JSListBox>(this, pListBox, this, false) : nullptr;
1040 if (pWeldWidget)
1041 RememberWidget(id, pWeldWidget.get());
1043 return pWeldWidget;
1046 std::unique_ptr<weld::Notebook> JSInstanceBuilder::weld_notebook(const OUString& id)
1048 TabControl* pNotebook = m_xBuilder->get<TabControl>(id);
1049 auto pWeldWidget
1050 = pNotebook ? std::make_unique<JSNotebook>(this, pNotebook, this, false) : nullptr;
1052 if (pWeldWidget)
1053 RememberWidget(id, pWeldWidget.get());
1055 return pWeldWidget;
1058 std::unique_ptr<weld::SpinButton> JSInstanceBuilder::weld_spin_button(const OUString& id)
1060 FormattedField* pSpinButton = m_xBuilder->get<FormattedField>(id);
1061 auto pWeldWidget
1062 = pSpinButton ? std::make_unique<JSSpinButton>(this, pSpinButton, this, false) : nullptr;
1064 if (pWeldWidget)
1065 RememberWidget(id, pWeldWidget.get());
1067 return pWeldWidget;
1070 std::unique_ptr<weld::CheckButton> JSInstanceBuilder::weld_check_button(const OUString& id)
1072 CheckBox* pCheckButton = m_xBuilder->get<CheckBox>(id);
1073 auto pWeldWidget
1074 = pCheckButton ? std::make_unique<JSCheckButton>(this, pCheckButton, this, false) : nullptr;
1076 if (pWeldWidget)
1077 RememberWidget(id, pWeldWidget.get());
1079 return pWeldWidget;
1082 std::unique_ptr<weld::DrawingArea>
1083 JSInstanceBuilder::weld_drawing_area(const OUString& id, const a11yref& rA11yImpl,
1084 FactoryFunction pUITestFactoryFunction, void* pUserData)
1086 VclDrawingArea* pArea = m_xBuilder->get<VclDrawingArea>(id);
1087 auto pWeldWidget = pArea ? std::make_unique<JSDrawingArea>(this, pArea, this, rA11yImpl,
1088 pUITestFactoryFunction, pUserData)
1089 : nullptr;
1091 if (pWeldWidget)
1092 RememberWidget(id, pWeldWidget.get());
1094 return pWeldWidget;
1097 std::unique_ptr<weld::Toolbar> JSInstanceBuilder::weld_toolbar(const OUString& id)
1099 ToolBox* pToolBox = m_xBuilder->get<ToolBox>(id);
1100 auto pWeldWidget
1101 = pToolBox ? std::make_unique<JSToolbar>(this, pToolBox, this, false) : nullptr;
1103 if (pWeldWidget)
1104 RememberWidget(id, pWeldWidget.get());
1106 return pWeldWidget;
1109 std::unique_ptr<weld::TextView> JSInstanceBuilder::weld_text_view(const OUString& id)
1111 VclMultiLineEdit* pTextView = m_xBuilder->get<VclMultiLineEdit>(id);
1112 auto pWeldWidget
1113 = pTextView ? std::make_unique<JSTextView>(this, pTextView, this, false) : nullptr;
1115 if (pWeldWidget)
1116 RememberWidget(id, pWeldWidget.get());
1118 return pWeldWidget;
1121 std::unique_ptr<weld::TreeView> JSInstanceBuilder::weld_tree_view(const OUString& id)
1123 SvTabListBox* pTreeView = m_xBuilder->get<SvTabListBox>(id);
1124 auto pWeldWidget
1125 = pTreeView ? std::make_unique<JSTreeView>(this, pTreeView, this, false) : nullptr;
1127 if (pWeldWidget)
1128 RememberWidget(id, pWeldWidget.get());
1130 return pWeldWidget;
1133 std::unique_ptr<weld::Expander> JSInstanceBuilder::weld_expander(const OUString& id)
1135 VclExpander* pExpander = m_xBuilder->get<VclExpander>(id);
1136 auto pWeldWidget
1137 = pExpander ? std::make_unique<JSExpander>(this, pExpander, this, false) : nullptr;
1139 if (pWeldWidget)
1140 RememberWidget(id, pWeldWidget.get());
1142 return pWeldWidget;
1145 std::unique_ptr<weld::IconView> JSInstanceBuilder::weld_icon_view(const OUString& id)
1147 ::IconView* pIconView = m_xBuilder->get<::IconView>(id);
1148 auto pWeldWidget
1149 = pIconView ? std::make_unique<JSIconView>(this, pIconView, this, false) : nullptr;
1151 if (pWeldWidget)
1152 RememberWidget(id, pWeldWidget.get());
1154 return pWeldWidget;
1157 std::unique_ptr<weld::RadioButton> JSInstanceBuilder::weld_radio_button(const OUString& id)
1159 ::RadioButton* pRadioButton = m_xBuilder->get<::RadioButton>(id);
1160 auto pWeldWidget
1161 = pRadioButton ? std::make_unique<JSRadioButton>(this, pRadioButton, this, false) : nullptr;
1163 if (pWeldWidget)
1164 RememberWidget(id, pWeldWidget.get());
1166 return pWeldWidget;
1169 std::unique_ptr<weld::Frame> JSInstanceBuilder::weld_frame(const OUString& id)
1171 ::VclFrame* pFrame = m_xBuilder->get<::VclFrame>(id);
1172 auto pWeldWidget = pFrame ? std::make_unique<JSFrame>(this, pFrame, this, false) : nullptr;
1174 if (pWeldWidget)
1175 RememberWidget(id, pWeldWidget.get());
1177 return pWeldWidget;
1180 std::unique_ptr<weld::MenuButton> JSInstanceBuilder::weld_menu_button(const OUString& id)
1182 ::MenuButton* pMenuButton = m_xBuilder->get<::MenuButton>(id);
1183 auto pWeldWidget
1184 = pMenuButton ? std::make_unique<JSMenuButton>(this, pMenuButton, this, false) : nullptr;
1186 if (pWeldWidget)
1187 RememberWidget(id, pWeldWidget.get());
1189 return pWeldWidget;
1192 std::unique_ptr<weld::Popover> JSInstanceBuilder::weld_popover(const OUString& id)
1194 DockingWindow* pDockingWindow = m_xBuilder->get<DockingWindow>(id);
1195 JSPopover* pPopover
1196 = pDockingWindow ? new JSPopover(this, pDockingWindow, this, false) : nullptr;
1197 std::unique_ptr<weld::Popover> pWeldWidget(pPopover);
1198 if (pDockingWindow)
1200 assert(!m_aOwnedToplevel && "only one toplevel per .ui allowed");
1201 m_aOwnedToplevel.set(pDockingWindow);
1202 m_xBuilder->drop_ownership(pDockingWindow);
1204 if (VclPtr<vcl::Window> pWin = pDockingWindow->GetParentWithLOKNotifier())
1206 vcl::Window* pPopupRoot = pDockingWindow->GetChild(0);
1207 pPopupRoot->SetLOKNotifier(pWin->GetLOKNotifier());
1208 m_aParentDialog = pPopupRoot;
1209 m_aWindowToRelease = pPopupRoot;
1210 m_nWindowId = m_aParentDialog->GetLOKWindowId();
1212 pPopover->set_window_id(m_nWindowId);
1213 JSInstanceBuilder::RememberPopup(OUString::number(m_nWindowId), pDockingWindow);
1215 InsertWindowToMap(getMapIdFromWindowId());
1216 initializeSender(GetNotifierWindow(), GetContentWindow(), GetTypeOfJSON());
1220 if (pWeldWidget)
1221 RememberWidget("__POPOVER__", pWeldWidget.get());
1223 return pWeldWidget;
1226 std::unique_ptr<weld::Box> JSInstanceBuilder::weld_box(const OUString& id)
1228 VclBox* pContainer = m_xBuilder->get<VclBox>(id);
1229 auto pWeldWidget
1230 = pContainer ? std::make_unique<JSBox>(this, pContainer, this, false) : nullptr;
1232 if (pWeldWidget)
1233 RememberWidget(id, pWeldWidget.get());
1235 return pWeldWidget;
1238 std::unique_ptr<weld::Widget> JSInstanceBuilder::weld_widget(const OUString& id)
1240 vcl::Window* pWidget = m_xBuilder->get(id);
1241 auto pWeldWidget
1242 = pWidget ? std::make_unique<JSWidgetInstance>(this, pWidget, this, false) : nullptr;
1244 if (pWeldWidget)
1245 RememberWidget(id, pWeldWidget.get());
1247 return pWeldWidget;
1250 std::unique_ptr<weld::Image> JSInstanceBuilder::weld_image(const OUString& id)
1252 FixedImage* pImage = m_xBuilder->get<FixedImage>(id);
1254 auto pWeldWidget = pImage ? std::make_unique<JSImage>(this, pImage, this, false) : nullptr;
1256 if (pWeldWidget)
1257 RememberWidget(id, pWeldWidget.get());
1259 return pWeldWidget;
1262 weld::MessageDialog*
1263 JSInstanceBuilder::CreateMessageDialog(weld::Widget* pParent, VclMessageType eMessageType,
1264 VclButtonsType eButtonType, const OUString& rPrimaryMessage,
1265 const vcl::ILibreOfficeKitNotifier* pNotifier)
1267 SalInstanceWidget* pParentInstance = dynamic_cast<SalInstanceWidget*>(pParent);
1268 SystemWindow* pParentWidget = pParentInstance ? pParentInstance->getSystemWindow() : nullptr;
1269 VclPtrInstance<::MessageDialog> xMessageDialog(pParentWidget, rPrimaryMessage, eMessageType,
1270 eButtonType);
1272 if (pNotifier)
1273 xMessageDialog->SetLOKNotifier(pNotifier);
1275 pNotifier = xMessageDialog->GetLOKNotifier();
1276 if (pNotifier)
1278 tools::JsonWriter aJsonWriter;
1279 xMessageDialog->DumpAsPropertyTree(aJsonWriter);
1280 aJsonWriter.put("id", xMessageDialog->GetLOKWindowId());
1281 aJsonWriter.put("jsontype", "dialog");
1282 OString message(aJsonWriter.finishAndGetAsOString());
1283 pNotifier->libreOfficeKitViewCallback(LOK_CALLBACK_JSDIALOG, message);
1285 OUString sWindowId = OUString::number(xMessageDialog->GetLOKWindowId());
1286 InsertWindowToMap(sWindowId);
1287 xMessageDialog->SetLOKTunnelingState(false);
1289 return new JSMessageDialog(xMessageDialog, nullptr, true);
1291 else
1292 SAL_WARN("vcl", "No notifier in JSInstanceBuilder::CreateMessageDialog");
1294 return new JSMessageDialog(xMessageDialog, nullptr, true);
1297 JSDialog::JSDialog(JSDialogSender* pSender, ::Dialog* pDialog, SalInstanceBuilder* pBuilder,
1298 bool bTakeOwnership)
1299 : JSWidget<SalInstanceDialog, ::Dialog>(pSender, pDialog, pBuilder, bTakeOwnership)
1303 void JSDialog::collapse(weld::Widget* pEdit, weld::Widget* pButton)
1305 SalInstanceDialog::collapse(pEdit, pButton);
1306 sendFullUpdate();
1309 void JSDialog::undo_collapse()
1311 SalInstanceDialog::undo_collapse();
1312 sendFullUpdate();
1315 void JSDialog::response(int response)
1317 if (response == RET_HELP)
1319 response_help(m_xWidget.get());
1320 return;
1323 sendClose();
1324 SalInstanceDialog::response(response);
1327 void JSAssistant::response(int response)
1329 if (response == RET_HELP)
1331 response_help(m_xWidget.get());
1332 return;
1335 sendClose();
1336 SalInstanceAssistant::response(response);
1339 int JSDialog::run()
1341 sendFullUpdate(true);
1342 int ret = SalInstanceDialog::run();
1343 return ret;
1346 bool JSDialog::runAsync(std::shared_ptr<weld::DialogController> aOwner,
1347 const std::function<void(sal_Int32)>& rEndDialogFn)
1349 bool ret = SalInstanceDialog::runAsync(aOwner, rEndDialogFn);
1350 sendFullUpdate();
1351 return ret;
1354 bool JSDialog::runAsync(std::shared_ptr<Dialog> const& rxSelf,
1355 const std::function<void(sal_Int32)>& func)
1357 bool ret = SalInstanceDialog::runAsync(rxSelf, func);
1358 sendFullUpdate();
1359 return ret;
1362 int JSAssistant::run()
1364 sendFullUpdate(true);
1365 int ret = SalInstanceDialog::run();
1366 return ret;
1369 bool JSAssistant::runAsync(std::shared_ptr<weld::DialogController> aOwner,
1370 const std::function<void(sal_Int32)>& rEndDialogFn)
1372 bool ret = SalInstanceDialog::runAsync(aOwner, rEndDialogFn);
1373 sendFullUpdate();
1374 return ret;
1377 bool JSAssistant::runAsync(std::shared_ptr<Dialog> const& rxSelf,
1378 const std::function<void(sal_Int32)>& func)
1380 bool ret = SalInstanceDialog::runAsync(rxSelf, func);
1381 sendFullUpdate();
1382 return ret;
1385 weld::Button* JSDialog::weld_widget_for_response(int nResponse)
1387 PushButton* pButton
1388 = dynamic_cast<::PushButton*>(m_xDialog->get_widget_for_response(nResponse));
1389 auto pWeldWidget = pButton ? new JSButton(m_pSender, pButton, nullptr, false) : nullptr;
1391 if (pWeldWidget)
1393 auto pParentDialog = m_xDialog->GetParentWithLOKNotifier();
1394 if (pParentDialog)
1395 JSInstanceBuilder::RememberWidget(OUString::number(pParentDialog->GetLOKWindowId()),
1396 pButton->get_id(), pWeldWidget);
1399 return pWeldWidget;
1402 weld::Button* JSAssistant::weld_widget_for_response(int nResponse)
1404 ::PushButton* pButton = nullptr;
1405 JSButton* pWeldWidget = nullptr;
1406 if (nResponse == RET_YES)
1407 pButton = m_xWizard->m_pNextPage;
1408 else if (nResponse == RET_NO)
1409 pButton = m_xWizard->m_pPrevPage;
1410 else if (nResponse == RET_OK)
1411 pButton = m_xWizard->m_pFinish;
1412 else if (nResponse == RET_CANCEL)
1413 pButton = m_xWizard->m_pCancel;
1414 else if (nResponse == RET_HELP)
1415 pButton = m_xWizard->m_pHelp;
1416 if (pButton)
1417 pWeldWidget = new JSButton(m_pSender, pButton, nullptr, false);
1419 if (pWeldWidget)
1421 auto pParentDialog = m_xWizard->GetParentWithLOKNotifier();
1422 if (pParentDialog)
1423 JSInstanceBuilder::RememberWidget(OUString::number(pParentDialog->GetLOKWindowId()),
1424 pButton->get_id(), pWeldWidget);
1427 return pWeldWidget;
1430 JSAssistant::JSAssistant(JSDialogSender* pSender, vcl::RoadmapWizard* pDialog,
1431 SalInstanceBuilder* pBuilder, bool bTakeOwnership)
1432 : JSWidget<SalInstanceAssistant, vcl::RoadmapWizard>(pSender, pDialog, pBuilder, bTakeOwnership)
1436 void JSAssistant::set_current_page(int nPage)
1438 SalInstanceAssistant::set_current_page(nPage);
1439 sendFullUpdate();
1442 void JSAssistant::set_current_page(const OUString& rIdent)
1444 SalInstanceAssistant::set_current_page(rIdent);
1445 sendFullUpdate();
1448 JSContainer::JSContainer(JSDialogSender* pSender, vcl::Window* pContainer,
1449 SalInstanceBuilder* pBuilder, bool bTakeOwnership)
1450 : JSWidget<SalInstanceContainer, vcl::Window>(pSender, pContainer, pBuilder, bTakeOwnership)
1454 JSScrolledWindow::JSScrolledWindow(JSDialogSender* pSender, ::VclScrolledWindow* pContainer,
1455 SalInstanceBuilder* pBuilder, bool bTakeOwnership,
1456 bool bUserManagedScrolling)
1457 : JSWidget<SalInstanceScrolledWindow, ::VclScrolledWindow>(
1458 pSender, pContainer, pBuilder, bTakeOwnership, bUserManagedScrolling)
1462 void JSScrolledWindow::vadjustment_configure(int value, int lower, int upper, int step_increment,
1463 int page_increment, int page_size)
1465 SalInstanceScrolledWindow::vadjustment_configure(value, lower, upper, step_increment,
1466 page_increment, page_size);
1467 sendUpdate();
1470 void JSScrolledWindow::vadjustment_set_value(int value)
1472 SalInstanceScrolledWindow::vadjustment_set_value(value);
1473 sendUpdate();
1476 void JSScrolledWindow::vadjustment_set_value_no_notification(int value)
1478 SalInstanceScrolledWindow::vadjustment_set_value(value);
1481 void JSScrolledWindow::vadjustment_set_page_size(int size)
1483 SalInstanceScrolledWindow::vadjustment_set_page_size(size);
1484 sendUpdate();
1487 void JSScrolledWindow::set_vpolicy(VclPolicyType eVPolicy)
1489 SalInstanceScrolledWindow::set_vpolicy(eVPolicy);
1490 sendUpdate();
1493 void JSScrolledWindow::hadjustment_configure(int value, int lower, int upper, int step_increment,
1494 int page_increment, int page_size)
1496 SalInstanceScrolledWindow::hadjustment_configure(value, lower, upper, step_increment,
1497 page_increment, page_size);
1498 sendUpdate();
1501 void JSScrolledWindow::hadjustment_set_value(int value)
1503 SalInstanceScrolledWindow::hadjustment_set_value(value);
1504 sendUpdate();
1507 void JSScrolledWindow::hadjustment_set_value_no_notification(int value)
1509 SalInstanceScrolledWindow::hadjustment_set_value(value);
1512 void JSScrolledWindow::hadjustment_set_page_size(int size)
1514 SalInstanceScrolledWindow::hadjustment_set_page_size(size);
1515 sendUpdate();
1518 void JSScrolledWindow::set_hpolicy(VclPolicyType eVPolicy)
1520 SalInstanceScrolledWindow::set_hpolicy(eVPolicy);
1521 sendUpdate();
1524 JSLabel::JSLabel(JSDialogSender* pSender, Control* pLabel, SalInstanceBuilder* pBuilder,
1525 bool bTakeOwnership)
1526 : JSWidget<SalInstanceLabel, Control>(pSender, pLabel, pBuilder, bTakeOwnership)
1530 void JSLabel::set_label(const OUString& rText)
1532 SalInstanceLabel::set_label(rText);
1533 sendUpdate();
1536 JSButton::JSButton(JSDialogSender* pSender, ::Button* pButton, SalInstanceBuilder* pBuilder,
1537 bool bTakeOwnership)
1538 : JSWidget<SalInstanceButton, ::Button>(pSender, pButton, pBuilder, bTakeOwnership)
1542 JSLinkButton::JSLinkButton(JSDialogSender* pSender, ::FixedHyperlink* pButton,
1543 SalInstanceBuilder* pBuilder, bool bTakeOwnership)
1544 : JSWidget<SalInstanceLinkButton, ::FixedHyperlink>(pSender, pButton, pBuilder, bTakeOwnership)
1548 JSToggleButton::JSToggleButton(JSDialogSender* pSender, ::PushButton* pButton,
1549 SalInstanceBuilder* pBuilder, bool bTakeOwnership)
1550 : JSWidget<SalInstanceToggleButton, ::PushButton>(pSender, pButton, pBuilder, bTakeOwnership)
1554 JSEntry::JSEntry(JSDialogSender* pSender, ::Edit* pEntry, SalInstanceBuilder* pBuilder,
1555 bool bTakeOwnership)
1556 : JSWidget<SalInstanceEntry, ::Edit>(pSender, pEntry, pBuilder, bTakeOwnership)
1560 void JSEntry::set_text(const OUString& rText)
1562 SalInstanceEntry::set_text(rText);
1563 sendUpdate();
1566 void JSEntry::set_text_without_notify(const OUString& rText) { SalInstanceEntry::set_text(rText); }
1568 void JSEntry::replace_selection(const OUString& rText)
1570 SalInstanceEntry::replace_selection(rText);
1571 sendUpdate();
1574 JSListBox::JSListBox(JSDialogSender* pSender, ::ListBox* pListBox, SalInstanceBuilder* pBuilder,
1575 bool bTakeOwnership)
1576 : JSWidget<SalInstanceComboBoxWithoutEdit, ::ListBox>(pSender, pListBox, pBuilder,
1577 bTakeOwnership)
1581 void JSListBox::insert(int pos, const OUString& rStr, const OUString* pId,
1582 const OUString* pIconName, VirtualDevice* pImageSurface)
1584 SalInstanceComboBoxWithoutEdit::insert(pos, rStr, pId, pIconName, pImageSurface);
1585 sendUpdate();
1588 void JSListBox::remove(int pos)
1590 SalInstanceComboBoxWithoutEdit::remove(pos);
1591 sendUpdate();
1594 void JSListBox::set_active(int pos)
1596 SalInstanceComboBoxWithoutEdit::set_active(pos);
1597 sendUpdate();
1600 JSComboBox::JSComboBox(JSDialogSender* pSender, ::ComboBox* pComboBox, SalInstanceBuilder* pBuilder,
1601 bool bTakeOwnership)
1602 : JSWidget<SalInstanceComboBoxWithEdit, ::ComboBox>(pSender, pComboBox, pBuilder,
1603 bTakeOwnership)
1607 void JSComboBox::insert(int pos, const OUString& rStr, const OUString* pId,
1608 const OUString* pIconName, VirtualDevice* pImageSurface)
1610 SalInstanceComboBoxWithEdit::insert(pos, rStr, pId, pIconName, pImageSurface);
1611 sendUpdate();
1614 void JSComboBox::remove(int pos)
1616 SalInstanceComboBoxWithEdit::remove(pos);
1617 sendUpdate();
1620 void JSComboBox::set_entry_text_without_notify(const OUString& rText)
1622 SalInstanceComboBoxWithEdit::set_entry_text(rText);
1625 void JSComboBox::set_entry_text(const OUString& rText)
1627 SalInstanceComboBoxWithEdit::set_entry_text(rText);
1628 sendUpdate();
1631 void JSComboBox::set_active(int pos)
1633 SalInstanceComboBoxWithEdit::set_active(pos);
1634 sendUpdate();
1637 bool JSComboBox::changed_by_direct_pick() const { return true; }
1639 JSNotebook::JSNotebook(JSDialogSender* pSender, ::TabControl* pControl,
1640 SalInstanceBuilder* pBuilder, bool bTakeOwnership)
1641 : JSWidget<SalInstanceNotebook, ::TabControl>(pSender, pControl, pBuilder, bTakeOwnership)
1645 void JSNotebook::remove_page(const OUString& rIdent)
1647 SalInstanceNotebook::remove_page(rIdent);
1648 sendFullUpdate();
1651 void JSNotebook::insert_page(const OUString& rIdent, const OUString& rLabel, int nPos)
1653 SalInstanceNotebook::insert_page(rIdent, rLabel, nPos);
1654 sendFullUpdate();
1657 JSSpinButton::JSSpinButton(JSDialogSender* pSender, ::FormattedField* pSpin,
1658 SalInstanceBuilder* pBuilder, bool bTakeOwnership)
1659 : JSWidget<SalInstanceSpinButton, ::FormattedField>(pSender, pSpin, pBuilder, bTakeOwnership)
1663 void JSSpinButton::set_value(sal_Int64 value)
1665 SalInstanceSpinButton::set_value(value);
1667 std::unique_ptr<jsdialog::ActionDataMap> pMap = std::make_unique<jsdialog::ActionDataMap>();
1668 (*pMap)[ACTION_TYPE] = "setText";
1669 (*pMap)["text"] = OUString::number(m_rFormatter.GetValue());
1670 sendAction(std::move(pMap));
1673 JSMessageDialog::JSMessageDialog(JSDialogSender* pSender, ::MessageDialog* pDialog,
1674 SalInstanceBuilder* pBuilder, bool bTakeOwnership)
1675 : JSWidget<SalInstanceMessageDialog, ::MessageDialog>(pSender, pDialog, pBuilder,
1676 bTakeOwnership)
1680 JSMessageDialog::JSMessageDialog(::MessageDialog* pDialog, SalInstanceBuilder* pBuilder,
1681 bool bTakeOwnership)
1682 : JSWidget<SalInstanceMessageDialog, ::MessageDialog>(nullptr, pDialog, pBuilder,
1683 bTakeOwnership)
1684 , m_pOwnedSender(new JSDialogSender(pDialog, pDialog, "dialog"))
1686 m_pSender = m_pOwnedSender.get();
1688 if (pBuilder)
1689 return;
1691 m_sWindowId = OUString::number(m_xMessageDialog->GetLOKWindowId());
1693 if (::OKButton* pOKBtn
1694 = dynamic_cast<::OKButton*>(m_xMessageDialog->get_widget_for_response(RET_OK)))
1696 m_pOK.reset(new JSButton(m_pSender, pOKBtn, nullptr, false));
1697 JSInstanceBuilder::AddChildWidget(m_sWindowId, pOKBtn->get_id(), m_pOK.get());
1698 m_pOK->connect_clicked(LINK(this, JSMessageDialog, OKHdl));
1701 if (::CancelButton* pCancelBtn
1702 = dynamic_cast<::CancelButton*>(m_xMessageDialog->get_widget_for_response(RET_CANCEL)))
1704 m_pCancel.reset(new JSButton(m_pSender, pCancelBtn, nullptr, false));
1705 JSInstanceBuilder::AddChildWidget(m_sWindowId, pCancelBtn->get_id(), m_pCancel.get());
1706 m_pCancel->connect_clicked(LINK(this, JSMessageDialog, CancelHdl));
1710 JSMessageDialog::~JSMessageDialog()
1712 if (m_pOK || m_pCancel)
1713 JSInstanceBuilder::RemoveWindowWidget(m_sWindowId);
1716 void JSMessageDialog::RememberMessageDialog()
1718 static OUStringLiteral sWidgetName = u"__DIALOG__";
1719 OUString sWindowId = OUString::number(m_xMessageDialog->GetLOKWindowId());
1720 if (JSInstanceBuilder::FindWeldWidgetsMap(sWindowId, sWidgetName) != nullptr)
1721 return;
1723 JSInstanceBuilder::InsertWindowToMap(sWindowId);
1724 JSInstanceBuilder::RememberWidget(sWindowId, sWidgetName, this);
1727 int JSMessageDialog::run()
1729 if (GetLOKNotifier())
1731 RememberMessageDialog();
1732 sendFullUpdate();
1735 int bRet = SalInstanceMessageDialog::run();
1736 return bRet;
1739 bool JSMessageDialog::runAsync(std::shared_ptr<weld::DialogController> aOwner,
1740 const std::function<void(sal_Int32)>& rEndDialogFn)
1742 bool bRet = SalInstanceMessageDialog::runAsync(aOwner, rEndDialogFn);
1744 RememberMessageDialog();
1745 sendFullUpdate();
1747 return bRet;
1750 bool JSMessageDialog::runAsync(std::shared_ptr<Dialog> const& rxSelf,
1751 const std::function<void(sal_Int32)>& rEndDialogFn)
1753 bool bRet = SalInstanceMessageDialog::runAsync(rxSelf, rEndDialogFn);
1755 RememberMessageDialog();
1756 sendFullUpdate();
1758 return bRet;
1761 IMPL_LINK_NOARG(JSMessageDialog, OKHdl, weld::Button&, void) { response(RET_OK); }
1763 IMPL_LINK_NOARG(JSMessageDialog, CancelHdl, weld::Button&, void) { response(RET_CANCEL); }
1765 void JSMessageDialog::set_primary_text(const OUString& rText)
1767 SalInstanceMessageDialog::set_primary_text(rText);
1768 sendFullUpdate();
1771 void JSMessageDialog::set_secondary_text(const OUString& rText)
1773 SalInstanceMessageDialog::set_secondary_text(rText);
1774 sendFullUpdate();
1777 void JSMessageDialog::response(int response)
1779 if (response == RET_HELP)
1781 response_help(m_xWidget.get());
1782 return;
1785 sendClose();
1786 SalInstanceMessageDialog::response(response);
1789 JSCheckButton::JSCheckButton(JSDialogSender* pSender, ::CheckBox* pCheckBox,
1790 SalInstanceBuilder* pBuilder, bool bTakeOwnership)
1791 : JSWidget<SalInstanceCheckButton, ::CheckBox>(pSender, pCheckBox, pBuilder, bTakeOwnership)
1795 void JSCheckButton::set_active(bool active)
1797 bool bWasActive = get_active();
1798 SalInstanceCheckButton::set_active(active);
1799 if (bWasActive != active)
1800 sendUpdate();
1803 JSDrawingArea::JSDrawingArea(JSDialogSender* pSender, VclDrawingArea* pDrawingArea,
1804 SalInstanceBuilder* pBuilder, const a11yref& rAlly,
1805 FactoryFunction pUITestFactoryFunction, void* pUserData)
1806 : JSWidget<SalInstanceDrawingArea, VclDrawingArea>(pSender, pDrawingArea, pBuilder, rAlly,
1807 std::move(pUITestFactoryFunction), pUserData,
1808 false)
1812 void JSDrawingArea::queue_draw()
1814 SalInstanceDrawingArea::queue_draw();
1815 sendUpdate();
1818 void JSDrawingArea::queue_draw_area(int x, int y, int width, int height)
1820 SalInstanceDrawingArea::queue_draw_area(x, y, width, height);
1821 sendUpdate();
1824 JSToolbar::JSToolbar(JSDialogSender* pSender, ::ToolBox* pToolbox, SalInstanceBuilder* pBuilder,
1825 bool bTakeOwnership)
1826 : JSWidget<SalInstanceToolbar, ::ToolBox>(pSender, pToolbox, pBuilder, bTakeOwnership)
1830 void JSToolbar::set_menu_item_active(const OUString& rIdent, bool bActive)
1832 bool bWasActive = get_menu_item_active(rIdent);
1833 SalInstanceToolbar::set_menu_item_active(rIdent, bActive);
1835 ToolBoxItemId nItemId = m_xToolBox->GetItemId(rIdent);
1836 VclPtr<vcl::Window> pFloat = m_aFloats[nItemId];
1838 if (!pFloat)
1839 return;
1841 // See WeldToolbarPopup : include/svtools/toolbarmenu.hxx
1842 // TopLevel (Popover) -> Container -> main container of the popup
1843 vcl::Window* pPopupRoot = pFloat->GetChild(0);
1844 if (pPopupRoot)
1845 pPopupRoot = pPopupRoot->GetChild(0);
1847 if (pPopupRoot)
1849 if (bActive)
1851 JSInstanceBuilder::RememberPopup(OUString::number(pPopupRoot->GetLOKWindowId()),
1852 pFloat);
1853 sendPopup(pPopupRoot, m_xToolBox->get_id(), rIdent);
1855 else if (bWasActive)
1857 JSInstanceBuilder::ForgetPopup(OUString::number(pPopupRoot->GetLOKWindowId()));
1858 sendClosePopup(pPopupRoot->GetLOKWindowId());
1863 void JSToolbar::set_item_sensitive(const OUString& rIdent, bool bSensitive)
1865 SalInstanceToolbar::set_item_sensitive(rIdent, bSensitive);
1866 sendUpdate();
1869 void JSToolbar::set_item_icon_name(const OUString& rIdent, const OUString& rIconName)
1871 SalInstanceToolbar::set_item_icon_name(rIdent, rIconName);
1872 sendUpdate();
1875 JSTextView::JSTextView(JSDialogSender* pSender, ::VclMultiLineEdit* pTextView,
1876 SalInstanceBuilder* pBuilder, bool bTakeOwnership)
1877 : JSWidget<SalInstanceTextView, ::VclMultiLineEdit>(pSender, pTextView, pBuilder,
1878 bTakeOwnership)
1882 void JSTextView::set_text(const OUString& rText)
1884 SalInstanceTextView::set_text(rText);
1885 sendUpdate();
1888 void JSTextView::set_text_without_notify(const OUString& rText)
1890 SalInstanceTextView::set_text(rText);
1893 void JSTextView::replace_selection(const OUString& rText)
1895 SalInstanceTextView::replace_selection(rText);
1896 sendUpdate();
1899 JSTreeView::JSTreeView(JSDialogSender* pSender, ::SvTabListBox* pTreeView,
1900 SalInstanceBuilder* pBuilder, bool bTakeOwnership)
1901 : JSWidget<SalInstanceTreeView, ::SvTabListBox>(pSender, pTreeView, pBuilder, bTakeOwnership)
1905 void JSTreeView::set_toggle(int pos, TriState eState, int col)
1907 SvTreeListEntry* pEntry = m_xTreeView->GetEntry(nullptr, 0);
1909 while (pEntry && pos--)
1910 pEntry = m_xTreeView->Next(pEntry);
1912 if (pEntry)
1914 SalInstanceTreeView::set_toggle(pEntry, eState, col);
1915 signal_toggled(iter_col(SalInstanceTreeIter(pEntry), col));
1917 sendUpdate();
1921 void JSTreeView::set_toggle(const weld::TreeIter& rIter, TriState bOn, int col)
1923 SalInstanceTreeView::set_toggle(rIter, bOn, col);
1924 sendUpdate();
1927 void JSTreeView::select(int pos)
1929 assert(m_xTreeView->IsUpdateMode() && "don't select when frozen");
1930 disable_notify_events();
1931 if (pos == -1 || (pos == 0 && n_children() == 0))
1932 m_xTreeView->SelectAll(false);
1933 else
1935 SvTreeListEntry* pEntry = m_xTreeView->GetEntry(nullptr, 0);
1937 while (pEntry && pos--)
1938 pEntry = m_xTreeView->Next(pEntry);
1940 if (pEntry)
1942 m_xTreeView->Select(pEntry, true);
1943 m_xTreeView->MakeVisible(pEntry);
1946 enable_notify_events();
1948 std::unique_ptr<jsdialog::ActionDataMap> pMap = std::make_unique<jsdialog::ActionDataMap>();
1949 (*pMap)[ACTION_TYPE] = "select";
1950 (*pMap)["position"] = OUString::number(pos);
1951 sendAction(std::move(pMap));
1954 weld::TreeView* JSTreeView::get_drag_source() const { return g_DragSource; }
1956 void JSTreeView::drag_start() { g_DragSource = this; }
1958 void JSTreeView::drag_end()
1960 css::datatransfer::dnd::XDropTarget* xDropTarget = m_xDropTarget.get();
1961 if (xDropTarget)
1963 css::datatransfer::dnd::DropTargetDropEvent aEvent;
1964 aEvent.Source = xDropTarget;
1965 aEvent.Context = new JSDropTargetDropContext();
1966 // dummy values
1967 aEvent.LocationX = 50;
1968 aEvent.LocationY = 50;
1969 aEvent.DropAction = css::datatransfer::dnd::DNDConstants::ACTION_DEFAULT;
1970 aEvent.SourceActions = css::datatransfer::dnd::DNDConstants::ACTION_DEFAULT;
1972 m_xDropTarget->fire_drop(aEvent);
1974 sendUpdate();
1975 if (g_DragSource)
1976 g_DragSource->sendUpdate();
1979 g_DragSource = nullptr;
1982 void JSTreeView::insert(const weld::TreeIter* pParent, int pos, const OUString* pStr,
1983 const OUString* pId, const OUString* pIconName,
1984 VirtualDevice* pImageSurface, bool bChildrenOnDemand, weld::TreeIter* pRet)
1986 SalInstanceTreeView::insert(pParent, pos, pStr, pId, pIconName, pImageSurface,
1987 bChildrenOnDemand, pRet);
1989 sendUpdate();
1992 void JSTreeView::set_text(int row, const OUString& rText, int col)
1994 SalInstanceTreeView::set_text(row, rText, col);
1995 sendUpdate();
1998 void JSTreeView::set_text(const weld::TreeIter& rIter, const OUString& rStr, int col)
2000 SalInstanceTreeView::set_text(rIter, rStr, col);
2001 sendUpdate();
2004 void JSTreeView::remove(int pos)
2006 SalInstanceTreeView::remove(pos);
2007 sendUpdate();
2010 void JSTreeView::remove(const weld::TreeIter& rIter)
2012 SalInstanceTreeView::remove(rIter);
2013 sendUpdate();
2016 void JSTreeView::clear()
2018 SalInstanceTreeView::clear();
2019 sendUpdate();
2022 void JSTreeView::set_cursor_without_notify(const weld::TreeIter& rIter)
2024 SalInstanceTreeView::set_cursor(rIter);
2027 void JSTreeView::set_cursor(const weld::TreeIter& rIter)
2029 SalInstanceTreeView::set_cursor(rIter);
2030 sendUpdate();
2033 void JSTreeView::set_cursor(int pos)
2035 SalInstanceTreeView::set_cursor(pos);
2036 sendUpdate();
2039 void JSTreeView::expand_row(const weld::TreeIter& rIter)
2041 bool bNotify = false;
2042 const SalInstanceTreeIter& rVclIter = static_cast<const SalInstanceTreeIter&>(rIter);
2043 if (!m_xTreeView->IsExpanded(rVclIter.iter))
2044 bNotify = true;
2046 SalInstanceTreeView::expand_row(rIter);
2048 if (bNotify)
2049 sendUpdate();
2052 void JSTreeView::collapse_row(const weld::TreeIter& rIter)
2054 bool bNotify = false;
2055 const SalInstanceTreeIter& rVclIter = static_cast<const SalInstanceTreeIter&>(rIter);
2056 if (m_xTreeView->IsExpanded(rVclIter.iter))
2057 bNotify = true;
2059 SalInstanceTreeView::collapse_row(rIter);
2061 if (bNotify)
2062 sendUpdate();
2065 JSExpander::JSExpander(JSDialogSender* pSender, ::VclExpander* pExpander,
2066 SalInstanceBuilder* pBuilder, bool bTakeOwnership)
2067 : JSWidget<SalInstanceExpander, ::VclExpander>(pSender, pExpander, pBuilder, bTakeOwnership)
2071 void JSExpander::set_expanded(bool bExpand)
2073 SalInstanceExpander::set_expanded(bExpand);
2074 sendUpdate();
2077 JSIconView::JSIconView(JSDialogSender* pSender, ::IconView* pIconView, SalInstanceBuilder* pBuilder,
2078 bool bTakeOwnership)
2079 : JSWidget<SalInstanceIconView, ::IconView>(pSender, pIconView, pBuilder, bTakeOwnership)
2083 void JSIconView::insert(int pos, const OUString* pStr, const OUString* pId,
2084 const OUString* pIconName, weld::TreeIter* pRet)
2086 SalInstanceIconView::insert(pos, pStr, pId, pIconName, pRet);
2087 sendUpdate();
2090 void JSIconView::insert(int pos, const OUString* pStr, const OUString* pId,
2091 const VirtualDevice* pIcon, weld::TreeIter* pRet)
2093 SalInstanceIconView::insert(pos, pStr, pId, pIcon, pRet);
2094 sendUpdate();
2097 void JSIconView::insert_separator(int pos, const OUString* pId)
2099 SalInstanceIconView::insert_separator(pos, pId);
2100 sendUpdate();
2103 void JSIconView::clear()
2105 SalInstanceIconView::clear();
2106 sendUpdate();
2109 void JSIconView::select(int pos)
2111 SalInstanceIconView::select(pos);
2113 std::unique_ptr<jsdialog::ActionDataMap> pMap = std::make_unique<jsdialog::ActionDataMap>();
2114 (*pMap)[ACTION_TYPE] = "select";
2115 (*pMap)["position"] = OUString::number(pos);
2116 sendAction(std::move(pMap));
2119 void JSIconView::unselect(int pos)
2121 SalInstanceIconView::unselect(pos);
2122 sendUpdate();
2125 JSRadioButton::JSRadioButton(JSDialogSender* pSender, ::RadioButton* pRadioButton,
2126 SalInstanceBuilder* pBuilder, bool bTakeOwnership)
2127 : JSWidget<SalInstanceRadioButton, ::RadioButton>(pSender, pRadioButton, pBuilder,
2128 bTakeOwnership)
2132 void JSRadioButton::set_active(bool active)
2134 SalInstanceRadioButton::set_active(active);
2135 sendUpdate();
2138 JSFrame::JSFrame(JSDialogSender* pSender, ::VclFrame* pFrame, SalInstanceBuilder* pBuilder,
2139 bool bTakeOwnership)
2140 : JSWidget<SalInstanceFrame, ::VclFrame>(pSender, pFrame, pBuilder, bTakeOwnership)
2144 JSMenuButton::JSMenuButton(JSDialogSender* pSender, ::MenuButton* pMenuButton,
2145 SalInstanceBuilder* pBuilder, bool bTakeOwnership)
2146 : JSWidget<SalInstanceMenuButton, ::MenuButton>(pSender, pMenuButton, pBuilder, bTakeOwnership)
2150 void JSMenuButton::set_label(const OUString& rText)
2152 OUString aPreviousLabel = get_label();
2153 SalInstanceMenuButton::set_label(rText);
2154 if (aPreviousLabel != rText)
2155 sendUpdate();
2158 void JSMenuButton::set_image(VirtualDevice* pDevice)
2160 SalInstanceMenuButton::set_image(pDevice);
2161 sendUpdate();
2164 void JSMenuButton::set_image(const css::uno::Reference<css::graphic::XGraphic>& rImage)
2166 SalInstanceMenuButton::set_image(rImage);
2167 sendUpdate();
2170 void JSMenuButton::set_active(bool bActive)
2172 SalInstanceMenuButton::set_active(bActive);
2174 VclPtr<vcl::Window> pPopup = m_xMenuButton->GetPopover();
2175 if (pPopup)
2177 if (bActive)
2178 sendPopup(pPopup->GetChild(0), m_xMenuButton->get_id(), m_xMenuButton->get_id());
2179 else
2180 sendClosePopup(pPopup->GetChild(0)->GetLOKWindowId());
2184 JSPopover::JSPopover(JSDialogSender* pSender, DockingWindow* pDockingWindow,
2185 SalInstanceBuilder* pBuilder, bool bTakeOwnership)
2186 : JSWidget<SalInstancePopover, DockingWindow>(pSender, pDockingWindow, pBuilder, bTakeOwnership)
2187 , mnWindowId(0)
2191 void JSPopover::popup_at_rect(weld::Widget* pParent, const tools::Rectangle& rRect,
2192 weld::Placement ePlace)
2194 SalInstancePopover::popup_at_rect(pParent, rRect, ePlace);
2195 sendPopup(getWidget()->GetChild(0), "_POPOVER_", "_POPOVER_");
2198 void JSPopover::popdown()
2200 vcl::Window* pPopup = JSInstanceBuilder::FindPopup(OUString::number(mnWindowId));
2202 if (pPopup)
2204 sendClosePopup(mnWindowId);
2205 vcl::Window::GetDockingManager()->EndPopupMode(pPopup);
2208 if (getWidget() && getWidget()->GetChild(0))
2209 sendClosePopup(getWidget()->GetChild(0)->GetLOKWindowId());
2211 SalInstancePopover::popdown();
2214 JSBox::JSBox(JSDialogSender* pSender, VclBox* pBox, SalInstanceBuilder* pBuilder,
2215 bool bTakeOwnership)
2216 : JSWidget<SalInstanceBox, VclBox>(pSender, pBox, pBuilder, bTakeOwnership)
2220 void JSBox::reorder_child(weld::Widget* pWidget, int nNewPosition)
2222 SalInstanceBox::reorder_child(pWidget, nNewPosition);
2223 sendUpdate();
2226 JSImage::JSImage(JSDialogSender* pSender, FixedImage* pImage, SalInstanceBuilder* pBuilder,
2227 bool bTakeOwnership)
2228 : JSWidget<SalInstanceImage, FixedImage>(pSender, pImage, pBuilder, bTakeOwnership)
2232 void JSImage::set_image(VirtualDevice* pDevice)
2234 SalInstanceImage::set_image(pDevice);
2235 sendUpdate();
2238 void JSImage::set_image(const css::uno::Reference<css::graphic::XGraphic>& rImage)
2240 SalInstanceImage::set_image(rImage);
2241 sendUpdate();
2244 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */