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 #include <salobj.hxx>
13 #include <window.h>
14 
15 InterimItemWindow::InterimItemWindow(vcl::Window* pParent, const OUString& rUIXMLDescription,
16  const OString& 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")
21 {
24 
28  bAllowCycleFocusOut, nLOKWindowId);
29  m_xContainer = m_xBuilder->weld_container(rID);
30 
31  SetBackground();
32  SetPaintTransparent(true);
33 }
34 
36 {
37  if (nStateChange == StateChangedType::Enable)
38  m_xContainer->set_sensitive(IsEnabled());
39  Control::StateChanged(nStateChange);
40 }
41 
43 
45 {
46  m_pWidget = nullptr;
47 
48  m_xContainer.reset();
49  m_xBuilder.reset();
51 
53 
55 }
56 
58 {
59  if (!m_xVclContentArea)
60  return;
61  if (m_aLayoutIdle.IsActive())
62  return;
64 }
65 
67 {
68  Control::queue_resize(eReason);
70 }
71 
73 
75 {
76  if (!IsVisible())
77  return;
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;
90 }
91 
92 IMPL_LINK_NOARG(InterimItemWindow, DoLayout, Timer*, void) { Layout(); }
93 
95 {
98  assert(pChild);
100  Control::Resize();
101 }
102 
104 {
106 }
107 
109 {
110  // find the bottom vcl::Window of the hierarchy and queue_resize on that
111  // one will invalidate all the size caches upwards
113  while (true)
114  {
115  vcl::Window* pSubChild = pChild->GetWindow(GetWindowType::FirstChild);
116  if (!pSubChild)
117  break;
118  pChild = pSubChild;
119  }
120  pChild->queue_resize();
121 }
122 
124 {
125  if (!m_pWidget)
126  return false;
127  return m_pWidget->has_focus();
128 }
129 
131 
133 {
134  if (m_pWidget)
136 
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
140  */
141  vcl::Window* pToolBox = GetParent();
143  pToolBox->EventNotify(aNEvt);
144 }
145 
147 {
148  sal_uInt16 nCode = rKEvt.GetKeyCode().GetCode();
149  if (nCode != KEY_TAB)
150  return false;
151 
152  /* if the native widget has focus, then no vcl window has focus.
153 
154  We want to grab focus to this vcl widget so that pressing tab will traverse
155  to the next vcl widget.
156 
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.
160 
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
163  */
164  SetFakeFocus(true);
165  GrabFocus();
166 
167  /* now give focus to our toolbox parent */
168  vcl::Window* pToolBox = GetParent();
169  pToolBox->GrabFocus();
170 
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
174  */
176  pToolBox->EventNotify(aNEvt);
177 
178  /* send parent the tab */
179  pToolBox->KeyInput(rKEvt);
180 
181  return true;
182 }
183 
184 void InterimItemWindow::Draw(OutputDevice* pDevice, const Point& rPos,
185  SystemTextColorFlags /*nFlags*/)
186 {
187  m_xContainer->draw(*pDevice, rPos, GetSizePixel());
188 }
189 
190 void InterimItemWindow::ImplPaintToDevice(::OutputDevice* pTargetOutDev, const Point& rPos)
191 {
192  Draw(pTargetOutDev, rPos, SystemTextColorFlags::NONE);
193 }
194 
195 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
void SetBackground()
Definition: window3.cxx:100
static void setLayoutAllocation(vcl::Window &rWindow, const Point &rPos, const Size &rSize)
Definition: layout.cxx:76
InterimItemWindow(vcl::Window *pParent, const OUString &rUIXMLDescription, const OString &rID, bool bAllowCycleFocusOut=true, sal_uInt64 nLOKWindowId=0)
weld::Widget * m_pWidget
Resize runs before repaint, so we won't paint twice.
static Size getLayoutRequisition(const vcl::Window &rWindow)
Definition: layout.cxx:151
void disposeAndClear()
Definition: vclptr.hxx:200
virtual void StateChanged(StateChangedType nStateChange) override
Definition: ctrl.cxx:256
virtual Size GetSizePixel() const
Definition: window.cxx:2405
bool ChildKeyInput(const KeyEvent &rKEvt)
SAL_DLLPRIVATE WindowImpl * ImplGetWindowImpl() const
Definition: window.hxx:527
sal_uInt16 GetCode() const
Definition: keycod.hxx:49
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:3005
bool IsActive() const
Definition: task.hxx:101
bool ControlHasFocus() const
StateChangedType
Definition: window.hxx:289
virtual void Layout()
virtual void StateChanged(StateChangedType nStateChange) override
virtual void GetFocus() override
VclPtr< vcl::Window > m_xVclContentArea
SystemTextColorFlags
virtual void queue_resize(StateChangedType eReason=StateChangedType::Layout)
Definition: window2.cxx:1350
bool mbInitWinClipRegion
Definition: window.h:317
virtual void Resize() override
virtual void ImplPaintToDevice(::OutputDevice *pTargetOutDev, const Point &rPos) override
sal_uInt16 nCode
virtual bool EventNotify(NotifyEvent &rNEvt)
Definition: event.cxx:104
virtual bool has_focus() const =0
Some things multiple-inherit from VclAbstractDialog and OutputDevice, so we need to use virtual inher...
Definition: outdev.hxx:175
SalObject * mpSysObj
Definition: window.h:230
virtual void dispose() override
This is intended to be used to clear any locally held references to other Window-subclass objects...
Definition: ctrl.cxx:58
void SetPaintTransparent(bool bTransparent)
Definition: paint.cxx:1025
void GrabFocus()
Definition: window.cxx:2982
vcl::Window * GetParent() const
Definition: window2.cxx:1120
vcl::Window * GetWindow(GetWindowType nType) const
Definition: stacking.cxx:1035
virtual void queue_resize(StateChangedType eReason=StateChangedType::Layout) override
virtual void KeyInput(const KeyEvent &rKEvt)
Definition: window.cxx:1808
virtual void Show(bool bVisible)=0
const vcl::KeyCode & GetKeyCode() const
Definition: event.hxx:57
virtual void Resize() override
Definition: ctrl.cxx:74
void Stop()
Definition: scheduler.cxx:590
IMPL_LINK_NOARG(InterimItemWindow, DoLayout, Timer *, void)
std::unique_ptr< weld::Container > m_xContainer
Definition: ctrl.hxx:81
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 void Draw(OutputDevice *pDevice, const Point &rPos, SystemTextColorFlags nFlags) override
bool IsVisible() const
Definition: window2.cxx:1125
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 void Start(bool bStartTimer=true) override
Schedules the task for execution.
Definition: idle.cxx:34
virtual Size GetOptimalSize() const override
Layout
bool IsEnabled() const
Definition: window2.cxx:1145
Definition: timer.hxx:26
void SetPriority(TaskPriority ePriority)
Definition: scheduler.cxx:597
virtual void ResetClipRegion()=0
static std::unique_ptr< weld::Builder > CreateInterimBuilder(vcl::Window *pParent, const OUString &rUIFile, bool bAllowCycleFocusOut, sal_uInt64 nLOKWindowId=0)
Definition: builder.cxx:199
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:2190