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>
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
);
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()
48 m_xVclContentArea
.disposeAndClear();
55 void InterimItemWindow::StartIdleLayout()
57 if (!m_xVclContentArea
)
59 if (m_aLayoutIdle
.IsActive())
61 m_aLayoutIdle
.Start();
64 void InterimItemWindow::queue_resize(StateChangedType eReason
)
66 Control::queue_resize(eReason
);
70 void InterimItemWindow::Resize() { Layout(); }
72 IMPL_LINK_NOARG(InterimItemWindow
, DoLayout
, Timer
*, void) { Layout(); }
74 void InterimItemWindow::Layout()
77 vcl::Window
* pChild
= GetWindow(GetWindowType::FirstChild
);
79 VclContainer::setLayoutAllocation(*pChild
, Point(0, 0), GetSizePixel());
83 Size
InterimItemWindow::GetOptimalSize() const
85 return VclContainer::getLayoutRequisition(*GetWindow(GetWindowType::FirstChild
));
88 bool InterimItemWindow::ControlHasFocus() const
92 return m_pWidget
->has_focus();
95 void InterimItemWindow::InitControlBase(weld::Widget
* pWidget
) { m_pWidget
= pWidget
; }
97 void InterimItemWindow::GetFocus()
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
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
)
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
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
140 NotifyEvent
aNEvt(MouseNotifyEvent::GETFOCUS
, this);
141 pToolBox
->EventNotify(aNEvt
);
143 /* send parent the tab */
144 pToolBox
->KeyInput(rKEvt
);
149 void InterimItemWindow::Draw(OutputDevice
* pDevice
, const Point
& rPos
, DrawFlags
/*nFlags*/)
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: */