LibreOffice Module vcl (master)  1
InterimItemWindow.cxx
Go to the documentation of this file.
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 
11 #include <vcl/layout.hxx>
12 
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
18 {
21  m_aLayoutIdle.SetDebugName("InterimItemWindow m_aLayoutIdle");
22 
26  bAllowCycleFocusOut, nLOKWindowId));
27  m_xContainer = m_xBuilder->weld_container(rID);
28 
29  SetBackground();
30  SetPaintTransparent(true);
31 }
32 
34 {
35  if (nStateChange == StateChangedType::Enable)
36  m_xContainer->set_sensitive(IsEnabled());
37  Control::StateChanged(nStateChange);
38 }
39 
41 
43 {
44  m_pWidget = nullptr;
45 
46  m_xContainer.reset();
47  m_xBuilder.reset();
49 
51 
53 }
54 
56 {
57  if (!m_xVclContentArea)
58  return;
59  if (m_aLayoutIdle.IsActive())
60  return;
62 }
63 
65 {
66  Control::queue_resize(eReason);
68 }
69 
71 
72 IMPL_LINK_NOARG(InterimItemWindow, DoLayout, Timer*, void) { Layout(); }
73 
75 {
78  assert(pChild);
81 }
82 
84 {
86 }
87 
89 {
90  // find the bottom vcl::Window of the hierarchy and queue_resize on that
91  // one will invalidate all the size caches upwards
93  while (true)
94  {
95  vcl::Window* pSubChild = pChild->GetWindow(GetWindowType::FirstChild);
96  if (!pSubChild)
97  break;
98  pChild = pSubChild;
99  }
100  pChild->queue_resize();
101 }
102 
104 {
105  if (!m_pWidget)
106  return false;
107  return m_pWidget->has_focus();
108 }
109 
111 
113 {
114  if (m_pWidget)
116 
117  /* let toolbox know this item window has focus so it updates its mnHighItemId to point
118  to this toolitem in case tab means to move to another toolitem within
119  the toolbox
120  */
121  vcl::Window* pToolBox = GetParent();
123  pToolBox->EventNotify(aNEvt);
124 }
125 
127 {
128  sal_uInt16 nCode = rKEvt.GetKeyCode().GetCode();
129  if (nCode != KEY_TAB)
130  return false;
131 
132  /* if the native widget has focus, then no vcl window has focus.
133 
134  We want to grab focus to this vcl widget so that pressing tab will traverse
135  to the next vcl widget.
136 
137  But just using GrabFocus will, because no vcl widget has focus, trigger
138  bringing the toplevel to front with the expectation that a suitable widget
139  will be picked for focus when that happen, which is no use to us here.
140 
141  SetFakeFocus avoids the problem, allowing GrabFocus to do the expected thing
142  then sending the Tab to our parent will do the right traversal
143  */
144  SetFakeFocus(true);
145  GrabFocus();
146 
147  /* now give focus to our toolbox parent */
148  vcl::Window* pToolBox = GetParent();
149  pToolBox->GrabFocus();
150 
151  /* let toolbox know this item window has focus so it updates its mnHighItemId to point
152  to this toolitem in case tab means to move to another toolitem within
153  the toolbox
154  */
156  pToolBox->EventNotify(aNEvt);
157 
158  /* send parent the tab */
159  pToolBox->KeyInput(rKEvt);
160 
161  return true;
162 }
163 
164 void InterimItemWindow::Draw(OutputDevice* pDevice, const Point& rPos, DrawFlags /*nFlags*/)
165 {
166  if (!m_pWidget)
167  return;
168  m_pWidget->draw(*pDevice, tools::Rectangle(rPos, GetSizePixel()));
169 }
170 
171 void InterimItemWindow::ImplPaintToDevice(::OutputDevice* pTargetOutDev, const Point& rPos)
172 {
173  Draw(pTargetOutDev, rPos, DrawFlags::NONE);
174 }
175 
176 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
static void setLayoutAllocation(vcl::Window &rWindow, const Point &rPos, const Size &rSize)
Definition: layout.cxx:67
InterimItemWindow(vcl::Window *pParent, const OUString &rUIXMLDescription, const OString &rID, bool bAllowCycleFocusOut=true, sal_uInt64 nLOKWindowId=0)
virtual void Draw(OutputDevice *pDevice, const Point &rPos, DrawFlags nFlags) override
weld::Widget * m_pWidget
Resize runs before repaint, so we won't paint twice.
static Size getLayoutRequisition(const vcl::Window &rWindow)
Definition: layout.cxx:142
void disposeAndClear()
Definition: vclptr.hxx:200
virtual void StateChanged(StateChangedType nStateChange) override
Definition: ctrl.cxx:260
virtual Size GetSizePixel() const
Definition: window.cxx:2400
bool ChildKeyInput(const KeyEvent &rKEvt)
sal_uInt16 GetCode() const
Definition: keycod.hxx:51
void SetFakeFocus(bool bFocus)
Set this when you need to act as if the window has focus even if it doesn't.
Definition: window.cxx:2980
bool IsActive() const
Definition: task.hxx:90
bool ControlHasFocus() const
StateChangedType
Definition: window.hxx:317
virtual void Layout()
void SetBackground()
virtual void StateChanged(StateChangedType nStateChange) override
const BorderLinePrimitive2D *pCandidateB assert(pCandidateA)
static weld::Builder * CreateInterimBuilder(vcl::Window *pParent, const OUString &rUIFile, bool bAllowCycleFocusOut, sal_uInt64 nLOKWindowId=0)
Definition: builder.cxx:187
virtual void GetFocus() override
virtual void Start() override
Activates the timer task.
Definition: idle.cxx:34
VclPtr< vcl::Window > m_xVclContentArea
virtual void queue_resize(StateChangedType eReason=StateChangedType::Layout)
Definition: window2.cxx:1327
virtual void Resize() override
virtual void ImplPaintToDevice(::OutputDevice *pTargetOutDev, const Point &rPos) override
sal_uInt16 nCode
void SetDebugName(const char *pDebugName)
Definition: task.hxx:81
virtual void draw(OutputDevice &rOutput, const tools::Rectangle &rRect)=0
virtual bool EventNotify(NotifyEvent &rNEvt)
Definition: event.cxx:103
DrawFlags
Definition: window.hxx:360
virtual bool has_focus() const =0
Some things multiple-inherit from VclAbstractDialog and OutputDevice, so we need to use virtual inher...
Definition: outdev.hxx:302
virtual void dispose() override
This is intended to be used to clear any locally held references to other Window-subclass objects...
Definition: ctrl.cxx:59
void SetPaintTransparent(bool bTransparent)
Definition: paint.cxx:1026
void GrabFocus()
Definition: window.cxx:2957
vcl::Window * GetParent() const
Definition: window2.cxx:1097
vcl::Window * GetWindow(GetWindowType nType) const
Definition: stacking.cxx:1039
virtual void queue_resize(StateChangedType eReason=StateChangedType::Layout) override
virtual void KeyInput(const KeyEvent &rKEvt)
Definition: window.cxx:1804
const vcl::KeyCode & GetKeyCode() const
Definition: event.hxx:54
virtual void Resize() override
Definition: ctrl.cxx:74
void Stop()
Definition: scheduler.cxx:601
IMPL_LINK_NOARG(InterimItemWindow, DoLayout, Timer *, void)
std::unique_ptr< weld::Container > m_xContainer
Definition: ctrl.hxx:33
virtual void grab_focus()=0
virtual void dispose() override
This is intended to be used to clear any locally held references to other Window-subclass objects...
virtual ~InterimItemWindow() override
static VclPtr< reference_type > Create(Arg &&...arg)
A construction helper for VclPtr.
Definition: vclptr.hxx:127
void SetInvokeHandler(const Link< Timer *, void > &rLink)
Definition: timer.hxx:56
std::unique_ptr< weld::Builder > m_xBuilder
WinBits const WB_TABSTOP
virtual Size GetOptimalSize() const override
Layout
bool IsEnabled() const
Definition: window2.cxx:1122
Definition: timer.hxx:26
void SetPriority(TaskPriority ePriority)
Definition: scheduler.cxx:608
void InitControlBase(weld::Widget *pWidget)
constexpr sal_uInt16 KEY_TAB
Definition: keycodes.hxx:121
void Show(bool bVisible=true, ShowFlags nFlags=ShowFlags::NONE)
Definition: window.cxx:2186