1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
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/.
10 #include <vcl/InterimItemWindow.hxx>
11 #include <vcl/layout.hxx>
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
);
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()
50 m_xVclContentArea
.disposeAndClear();
57 void InterimItemWindow::StartIdleLayout()
59 if (!m_xVclContentArea
)
61 if (m_aLayoutIdle
.IsActive())
63 m_aLayoutIdle
.Start();
66 void InterimItemWindow::queue_resize(StateChangedType eReason
)
68 Control::queue_resize(eReason
);
72 void InterimItemWindow::Resize() { Layout(); }
74 void InterimItemWindow::UnclipVisibleSysObj()
78 vcl::Window
* pChild
= m_xVclContentArea
->GetWindow(GetWindowType::FirstChild
);
81 WindowImpl
* pWindowImpl
= pChild
->ImplGetWindowImpl();
84 if (!pWindowImpl
->mpSysObj
)
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()
97 vcl::Window
* pChild
= GetWindow(GetWindowType::FirstChild
);
99 VclContainer::setLayoutAllocation(*pChild
, Point(0, 0), GetSizePixel());
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
);
115 vcl::Window
* pSubChild
= pChild
->GetWindow(GetWindowType::FirstChild
);
120 pChild
->queue_resize();
123 bool InterimItemWindow::ControlHasFocus() const
127 return m_pWidget
->has_focus();
130 void InterimItemWindow::InitControlBase(weld::Widget
* pWidget
) { m_pWidget
= pWidget
; }
132 void InterimItemWindow::GetFocus()
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
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
)
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
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
175 NotifyEvent
aNEvt(NotifyEventType::GETFOCUS
, this);
176 pToolBox
->EventNotify(aNEvt
);
178 /* send parent the tab */
179 pToolBox
->KeyInput(rKEvt
);
184 void InterimItemWindow::Draw(OutputDevice
* pDevice
, const Point
& rPos
,
185 SystemTextColorFlags
/*nFlags*/)
187 m_xContainer
->draw(*pDevice
, rPos
, GetSizePixel());
190 void InterimItemWindow::SetPriority(TaskPriority nPriority
)
192 // Eliminate warning when changing timer's priority
193 // Task::SetPriority() expects the timer to be stopped while
194 // changing the timer's priority.
195 bool bActive
= m_aLayoutIdle
.IsActive();
197 m_aLayoutIdle
.Stop();
198 m_aLayoutIdle
.SetPriority(nPriority
);
200 m_aLayoutIdle
.Start();
203 void InterimItemWindow::ImplPaintToDevice(::OutputDevice
* pTargetOutDev
, const Point
& rPos
)
205 Draw(pTargetOutDev
, rPos
, SystemTextColorFlags::NONE
);
208 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */