bump product version to 7.6.3.2-android
[LibreOffice.git] / vcl / source / control / InterimItemWindow.cxx
blob41d1466f70c46e68d0bcc63cd80038d69f5d6bd5
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>
12 #include <salobj.hxx>
13 #include <window.h>
15 InterimItemWindow::InterimItemWindow(vcl::Window* pParent, const OUString& rUIXMLDescription,
16 const OUString& rID, bool bAllowCycleFocusOut,
17 sal_uInt64 nLOKWindowId)
18 : Control(pParent, WB_TABSTOP)
19 , m_pWidget(nullptr) // inheritors are expected to call InitControlBase
20 , m_aLayoutIdle("InterimItemWindow m_aLayoutIdle")
22 m_aLayoutIdle.SetPriority(TaskPriority::RESIZE);
23 m_aLayoutIdle.SetInvokeHandler(LINK(this, InterimItemWindow, DoLayout));
25 m_xVclContentArea = VclPtr<VclVBox>::Create(this);
26 m_xVclContentArea->Show();
27 m_xBuilder = Application::CreateInterimBuilder(m_xVclContentArea, rUIXMLDescription,
28 bAllowCycleFocusOut, nLOKWindowId);
29 m_xContainer = m_xBuilder->weld_container(rID);
31 SetBackground();
32 SetPaintTransparent(true);
35 void InterimItemWindow::StateChanged(StateChangedType nStateChange)
37 if (nStateChange == StateChangedType::Enable)
38 m_xContainer->set_sensitive(IsEnabled());
39 Control::StateChanged(nStateChange);
42 InterimItemWindow::~InterimItemWindow() { disposeOnce(); }
44 void InterimItemWindow::dispose()
46 m_pWidget = nullptr;
48 m_xContainer.reset();
49 m_xBuilder.reset();
50 m_xVclContentArea.disposeAndClear();
52 m_aLayoutIdle.Stop();
54 Control::dispose();
57 void InterimItemWindow::StartIdleLayout()
59 if (!m_xVclContentArea)
60 return;
61 if (m_aLayoutIdle.IsActive())
62 return;
63 m_aLayoutIdle.Start();
66 void InterimItemWindow::queue_resize(StateChangedType eReason)
68 Control::queue_resize(eReason);
69 StartIdleLayout();
72 void InterimItemWindow::Resize() { Layout(); }
74 void InterimItemWindow::UnclipVisibleSysObj()
76 if (!IsVisible())
77 return;
78 vcl::Window* pChild = m_xVclContentArea->GetWindow(GetWindowType::FirstChild);
79 if (!pChild)
80 return;
81 WindowImpl* pWindowImpl = pChild->ImplGetWindowImpl();
82 if (!pWindowImpl)
83 return;
84 if (!pWindowImpl->mpSysObj)
85 return;
86 pWindowImpl->mpSysObj->Show(true);
87 pWindowImpl->mpSysObj->ResetClipRegion();
88 // flag that sysobj clip is dirty and needs to be recalculated on next use
89 pWindowImpl->mbInitWinClipRegion = true;
92 IMPL_LINK_NOARG(InterimItemWindow, DoLayout, Timer*, void) { Layout(); }
94 void InterimItemWindow::Layout()
96 m_aLayoutIdle.Stop();
97 vcl::Window* pChild = GetWindow(GetWindowType::FirstChild);
98 assert(pChild);
99 VclContainer::setLayoutAllocation(*pChild, Point(0, 0), GetSizePixel());
100 Control::Resize();
103 Size InterimItemWindow::GetOptimalSize() const
105 return VclContainer::getLayoutRequisition(*GetWindow(GetWindowType::FirstChild));
108 void InterimItemWindow::InvalidateChildSizeCache()
110 // find the bottom vcl::Window of the hierarchy and queue_resize on that
111 // one will invalidate all the size caches upwards
112 vcl::Window* pChild = GetWindow(GetWindowType::FirstChild);
113 while (true)
115 vcl::Window* pSubChild = pChild->GetWindow(GetWindowType::FirstChild);
116 if (!pSubChild)
117 break;
118 pChild = pSubChild;
120 pChild->queue_resize();
123 bool InterimItemWindow::ControlHasFocus() const
125 if (!m_pWidget)
126 return false;
127 return m_pWidget->has_focus();
130 void InterimItemWindow::InitControlBase(weld::Widget* pWidget) { m_pWidget = pWidget; }
132 void InterimItemWindow::GetFocus()
134 if (m_pWidget)
135 m_pWidget->grab_focus();
137 /* let toolbox know this item window has focus so it updates its mnHighItemId to point
138 to this toolitem in case tab means to move to another toolitem within
139 the toolbox
141 vcl::Window* pToolBox = GetParent();
142 NotifyEvent aNEvt(NotifyEventType::GETFOCUS, this);
143 pToolBox->EventNotify(aNEvt);
146 bool InterimItemWindow::ChildKeyInput(const KeyEvent& rKEvt)
148 sal_uInt16 nCode = rKEvt.GetKeyCode().GetCode();
149 if (nCode != KEY_TAB)
150 return false;
152 /* if the native widget has focus, then no vcl window has focus.
154 We want to grab focus to this vcl widget so that pressing tab will traverse
155 to the next vcl widget.
157 But just using GrabFocus will, because no vcl widget has focus, trigger
158 bringing the toplevel to front with the expectation that a suitable widget
159 will be picked for focus when that happen, which is no use to us here.
161 SetFakeFocus avoids the problem, allowing GrabFocus to do the expected thing
162 then sending the Tab to our parent will do the right traversal
164 SetFakeFocus(true);
165 GrabFocus();
167 /* now give focus to our toolbox parent */
168 vcl::Window* pToolBox = GetParent();
169 pToolBox->GrabFocus();
171 /* let toolbox know this item window has focus so it updates its mnHighItemId to point
172 to this toolitem in case tab means to move to another toolitem within
173 the toolbox
175 NotifyEvent aNEvt(NotifyEventType::GETFOCUS, this);
176 pToolBox->EventNotify(aNEvt);
178 /* send parent the tab */
179 pToolBox->KeyInput(rKEvt);
181 return true;
184 void InterimItemWindow::Draw(OutputDevice* pDevice, const Point& rPos,
185 SystemTextColorFlags /*nFlags*/)
187 m_xContainer->draw(*pDevice, rPos, GetSizePixel());
190 void InterimItemWindow::ImplPaintToDevice(::OutputDevice* pTargetOutDev, const Point& rPos)
192 Draw(pTargetOutDev, rPos, SystemTextColorFlags::NONE);
195 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */