2 * DISTRHO Plugin Framework (DPF)
3 * Copyright (C) 2012-2021 Filipe Coelho <falktx@falktx.com>
5 * Permission to use, copy, modify, and/or distribute this software for any purpose with
6 * or without fee is hereby granted, provided that the above copyright notice and this
7 * permission notice appear in all copies.
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD
10 * TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN
11 * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
12 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
13 * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
14 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 #include "WidgetPrivateData.hpp"
18 #include "../TopLevelWidget.hpp"
19 #include "../Window.hpp"
23 // --------------------------------------------------------------------------------------------------------------------
26 Widget::Widget(TopLevelWidget
* const topLevelWidget
)
27 : pData(new PrivateData(this, topLevelWidget
)) {}
29 Widget::Widget(Widget
* const parentWidget
)
30 : pData(new PrivateData(this, parentWidget
)) {}
37 bool Widget::isVisible() const noexcept
39 return pData
->visible
;
42 void Widget::setVisible(bool visible
)
44 if (pData
->visible
== visible
)
47 pData
->visible
= visible
;
50 // FIXME check case of hiding a previously visible widget, does it trigger a repaint?
63 uint
Widget::getWidth() const noexcept
65 return pData
->size
.getWidth();
68 uint
Widget::getHeight() const noexcept
70 return pData
->size
.getHeight();
73 const Size
<uint
> Widget::getSize() const noexcept
78 void Widget::setWidth(uint width
) noexcept
80 if (pData
->size
.getWidth() == width
)
84 ev
.oldSize
= pData
->size
;
85 ev
.size
= Size
<uint
>(width
, pData
->size
.getHeight());
87 pData
->size
.setWidth(width
);
93 void Widget::setHeight(uint height
) noexcept
95 if (pData
->size
.getHeight() == height
)
99 ev
.oldSize
= pData
->size
;
100 ev
.size
= Size
<uint
>(pData
->size
.getWidth(), height
);
102 pData
->size
.setHeight(height
);
108 void Widget::setSize(uint width
, uint height
) noexcept
110 setSize(Size
<uint
>(width
, height
));
113 void Widget::setSize(const Size
<uint
>& size
) noexcept
115 if (pData
->size
== size
)
119 ev
.oldSize
= pData
->size
;
128 Application
& Widget::getApp() const noexcept
130 DISTRHO_SAFE_ASSERT(pData
->topLevelWidget
!= nullptr);
131 return pData
->topLevelWidget
->getApp();
134 Window
& Widget::getWindow() const noexcept
136 DISTRHO_SAFE_ASSERT(pData
->topLevelWidget
!= nullptr);
137 return pData
->topLevelWidget
->getWindow();
140 const GraphicsContext
& Widget::getGraphicsContext() const noexcept
142 DISTRHO_SAFE_ASSERT(pData
->topLevelWidget
!= nullptr);
143 return pData
->topLevelWidget
->getWindow().getGraphicsContext();
146 TopLevelWidget
* Widget::getTopLevelWidget() const noexcept
148 return pData
->topLevelWidget
;
151 void Widget::repaint() noexcept
155 uint
Widget::getId() const noexcept
160 void Widget::setId(uint id
) noexcept
165 bool Widget::onKeyboard(const KeyboardEvent
& ev
)
167 return pData
->giveKeyboardEventForSubWidgets(ev
);
170 bool Widget::onCharacterInput(const CharacterInputEvent
& ev
)
172 return pData
->giveCharacterInputEventForSubWidgets(ev
);
175 bool Widget::onMouse(const MouseEvent
& ev
)
178 return pData
->giveMouseEventForSubWidgets(rev
);
181 bool Widget::onMotion(const MotionEvent
& ev
)
183 MotionEvent rev
= ev
;
184 return pData
->giveMotionEventForSubWidgets(rev
);
187 bool Widget::onScroll(const ScrollEvent
& ev
)
189 ScrollEvent rev
= ev
;
190 return pData
->giveScrollEventForSubWidgets(rev
);
193 void Widget::onResize(const ResizeEvent
&)
197 // --------------------------------------------------------------------------------------------------------------------