nss: upgrade to release 3.73
[LibreOffice.git] / vcl / source / control / InterimItemWindow.cxx
blob3ed1107bea87ef8b1b6f0eb383b4e056fa49aadb
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 <vcl/InterimItemWindow.hxx>
11 #include <vcl/layout.hxx>
13 InterimItemWindow::InterimItemWindow(vcl::Window* pParent, const OUString& rUIXMLDescription,
14 const OString& rID, bool bAllowCycleFocusOut,
15 sal_uInt64 nLOKWindowId)
16 : Control(pParent, WB_TABSTOP)
17 , m_pWidget(nullptr) // inheritors are expected to call InitControlBase
19 m_aLayoutIdle.SetPriority(TaskPriority::RESIZE);
20 m_aLayoutIdle.SetInvokeHandler(LINK(this, InterimItemWindow, DoLayout));
21 m_aLayoutIdle.SetDebugName("InterimItemWindow m_aLayoutIdle");
23 m_xVclContentArea = VclPtr<VclVBox>::Create(this);
24 m_xVclContentArea->Show();
25 m_xBuilder.reset(Application::CreateInterimBuilder(m_xVclContentArea, rUIXMLDescription,
26 bAllowCycleFocusOut, nLOKWindowId));
27 m_xContainer = m_xBuilder->weld_container(rID);
29 SetBackground();
30 SetPaintTransparent(true);
33 void InterimItemWindow::StateChanged(StateChangedType nStateChange)
35 if (nStateChange == StateChangedType::Enable)
36 m_xContainer->set_sensitive(IsEnabled());
37 Control::StateChanged(nStateChange);
40 InterimItemWindow::~InterimItemWindow() { disposeOnce(); }
42 void InterimItemWindow::dispose()
44 m_pWidget = nullptr;
46 m_xContainer.reset();
47 m_xBuilder.reset();
48 m_xVclContentArea.disposeAndClear();
50 m_aLayoutIdle.Stop();
52 Control::dispose();
55 void InterimItemWindow::StartIdleLayout()
57 if (!m_xVclContentArea)
58 return;
59 if (m_aLayoutIdle.IsActive())
60 return;
61 m_aLayoutIdle.Start();
64 void InterimItemWindow::queue_resize(StateChangedType eReason)
66 Control::queue_resize(eReason);
67 StartIdleLayout();
70 void InterimItemWindow::Resize() { Layout(); }
72 IMPL_LINK_NOARG(InterimItemWindow, DoLayout, Timer*, void) { Layout(); }
74 void InterimItemWindow::Layout()
76 m_aLayoutIdle.Stop();
77 vcl::Window* pChild = GetWindow(GetWindowType::FirstChild);
78 assert(pChild);
79 VclContainer::setLayoutAllocation(*pChild, Point(0, 0), GetSizePixel());
80 Control::Resize();
83 Size InterimItemWindow::GetOptimalSize() const
85 return VclContainer::getLayoutRequisition(*GetWindow(GetWindowType::FirstChild));
88 bool InterimItemWindow::ControlHasFocus() const
90 if (!m_pWidget)
91 return false;
92 return m_pWidget->has_focus();
95 void InterimItemWindow::InitControlBase(weld::Widget* pWidget) { m_pWidget = pWidget; }
97 void InterimItemWindow::GetFocus()
99 if (m_pWidget)
100 m_pWidget->grab_focus();
102 /* let toolbox know this item window has focus so it updates its mnHighItemId to point
103 to this toolitem in case tab means to move to another toolitem within
104 the toolbox
106 vcl::Window* pToolBox = GetParent();
107 NotifyEvent aNEvt(MouseNotifyEvent::GETFOCUS, this);
108 pToolBox->EventNotify(aNEvt);
111 bool InterimItemWindow::ChildKeyInput(const KeyEvent& rKEvt)
113 sal_uInt16 nCode = rKEvt.GetKeyCode().GetCode();
114 if (nCode != KEY_TAB)
115 return false;
117 /* if the native widget has focus, then no vcl window has focus.
119 We want to grab focus to this vcl widget so that pressing tab will traverse
120 to the next vcl widget.
122 But just using GrabFocus will, because no vcl widget has focus, trigger
123 bringing the toplevel to front with the expectation that a suitable widget
124 will be picked for focus when that happen, which is no use to us here.
126 SetFakeFocus avoids the problem, allowing GrabFocus to do the expected thing
127 then sending the Tab to our parent will do the right traversal
129 SetFakeFocus(true);
130 GrabFocus();
132 /* now give focus to our toolbox parent */
133 vcl::Window* pToolBox = GetParent();
134 pToolBox->GrabFocus();
136 /* let toolbox know this item window has focus so it updates its mnHighItemId to point
137 to this toolitem in case tab means to move to another toolitem within
138 the toolbox
140 NotifyEvent aNEvt(MouseNotifyEvent::GETFOCUS, this);
141 pToolBox->EventNotify(aNEvt);
143 /* send parent the tab */
144 pToolBox->KeyInput(rKEvt);
146 return true;
149 void InterimItemWindow::Draw(OutputDevice* pDevice, const Point& rPos, DrawFlags /*nFlags*/)
151 if (!m_pWidget)
152 return;
153 m_pWidget->draw(*pDevice, tools::Rectangle(rPos, GetSizePixel()));
156 void InterimItemWindow::ImplPaintToDevice(::OutputDevice* pTargetOutDev, const Point& rPos)
158 Draw(pTargetOutDev, rPos, DrawFlags::NONE);
161 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */