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 "SubWidgetPrivateData.hpp"
19 #include "../TopLevelWidget.hpp"
23 #define FOR_EACH_SUBWIDGET(it) \
24 for (std::list<SubWidget*>::iterator it = subWidgets.begin(); it != subWidgets.end(); ++it)
26 #define FOR_EACH_SUBWIDGET_INV(rit) \
27 for (std::list<SubWidget*>::reverse_iterator rit = subWidgets.rbegin(); rit != subWidgets.rend(); ++rit)
29 // -----------------------------------------------------------------------
31 Widget::PrivateData::PrivateData(Widget
* const s
, TopLevelWidget
* const tlw
)
34 parentWidget(nullptr),
41 Widget::PrivateData::PrivateData(Widget
* const s
, Widget
* const pw
)
43 topLevelWidget(findTopLevelWidget(pw
)),
51 Widget::PrivateData::~PrivateData()
56 void Widget::PrivateData::displaySubWidgets(const uint width
, const uint height
, const double autoScaleFactor
)
58 if (subWidgets
.size() == 0)
61 for (std::list
<SubWidget
*>::iterator it
= subWidgets
.begin(); it
!= subWidgets
.end(); ++it
)
63 SubWidget
* const subwidget(*it
);
65 if (subwidget
->isVisible())
66 subwidget
->pData
->display(width
, height
, autoScaleFactor
);
70 // -----------------------------------------------------------------------
72 bool Widget::PrivateData::giveKeyboardEventForSubWidgets(const KeyboardEvent
& ev
)
76 if (subWidgets
.size() == 0)
79 FOR_EACH_SUBWIDGET_INV(rit
)
81 SubWidget
* const widget(*rit
);
83 if (widget
->isVisible() && widget
->onKeyboard(ev
))
90 bool Widget::PrivateData::giveCharacterInputEventForSubWidgets(const CharacterInputEvent
& ev
)
94 if (subWidgets
.size() == 0)
97 FOR_EACH_SUBWIDGET_INV(rit
)
99 SubWidget
* const widget(*rit
);
101 if (widget
->isVisible() && widget
->onCharacterInput(ev
))
108 bool Widget::PrivateData::giveMouseEventForSubWidgets(MouseEvent
& ev
)
112 if (subWidgets
.size() == 0)
115 const double x
= ev
.absolutePos
.getX();
116 const double y
= ev
.absolutePos
.getY();
118 if (SubWidget
* const selfw
= dynamic_cast<SubWidget
*>(self
))
120 if (selfw
->pData
->needsViewportScaling
)
122 ev
.absolutePos
.setX(x
- selfw
->getAbsoluteX() + selfw
->getMargin().getX());
123 ev
.absolutePos
.setY(y
- selfw
->getAbsoluteY() + selfw
->getMargin().getY());
127 FOR_EACH_SUBWIDGET_INV(rit
)
129 SubWidget
* const widget(*rit
);
131 if (! widget
->isVisible())
134 ev
.pos
= Point
<double>(x
- widget
->getAbsoluteX() + widget
->getMargin().getX(),
135 y
- widget
->getAbsoluteY() + widget
->getMargin().getY());
137 if (widget
->onMouse(ev
))
144 bool Widget::PrivateData::giveMotionEventForSubWidgets(MotionEvent
& ev
)
148 if (subWidgets
.size() == 0)
151 const double x
= ev
.absolutePos
.getX();
152 const double y
= ev
.absolutePos
.getY();
154 if (SubWidget
* const selfw
= dynamic_cast<SubWidget
*>(self
))
156 if (selfw
->pData
->needsViewportScaling
)
158 ev
.absolutePos
.setX(x
- selfw
->getAbsoluteX() + selfw
->getMargin().getX());
159 ev
.absolutePos
.setY(y
- selfw
->getAbsoluteY() + selfw
->getMargin().getY());
163 FOR_EACH_SUBWIDGET_INV(rit
)
165 SubWidget
* const widget(*rit
);
167 if (! widget
->isVisible())
170 ev
.pos
= Point
<double>(x
- widget
->getAbsoluteX() + widget
->getMargin().getX(),
171 y
- widget
->getAbsoluteY() + widget
->getMargin().getY());
173 if (widget
->onMotion(ev
))
180 bool Widget::PrivateData::giveScrollEventForSubWidgets(ScrollEvent
& ev
)
184 if (subWidgets
.size() == 0)
187 const double x
= ev
.absolutePos
.getX();
188 const double y
= ev
.absolutePos
.getY();
190 if (SubWidget
* const selfw
= dynamic_cast<SubWidget
*>(self
))
192 if (selfw
->pData
->needsViewportScaling
)
194 ev
.absolutePos
.setX(x
- selfw
->getAbsoluteX() + selfw
->getMargin().getX());
195 ev
.absolutePos
.setY(y
- selfw
->getAbsoluteY() + selfw
->getMargin().getY());
199 FOR_EACH_SUBWIDGET_INV(rit
)
201 SubWidget
* const widget(*rit
);
203 if (! widget
->isVisible())
206 ev
.pos
= Point
<double>(x
- widget
->getAbsoluteX() + widget
->getMargin().getX(),
207 y
- widget
->getAbsoluteY() + widget
->getMargin().getY());
209 if (widget
->onScroll(ev
))
216 // -----------------------------------------------------------------------
218 TopLevelWidget
* Widget::PrivateData::findTopLevelWidget(Widget
* const pw
)
220 if (pw
->pData
->topLevelWidget
!= nullptr)
221 return pw
->pData
->topLevelWidget
;
222 if (pw
->pData
->parentWidget
!= nullptr)
223 return findTopLevelWidget(pw
->pData
->parentWidget
);
227 // -----------------------------------------------------------------------