Browse Source

Allow one Window to have many top level widgets

Signed-off-by: falkTX <falktx@falktx.com>
pull/281/head
falkTX 4 years ago
parent
commit
919f18973a
Signed by: falkTX <falktx@falktx.com> GPG Key ID: CDBAA37ABC74FBA0
3 changed files with 71 additions and 25 deletions
  1. +2
    -3
      dgl/src/TopLevelWidgetPrivateData.cpp
  2. +65
    -20
      dgl/src/WindowPrivateData.cpp
  3. +4
    -2
      dgl/src/WindowPrivateData.hpp

+ 2
- 3
dgl/src/TopLevelWidgetPrivateData.cpp View File

@@ -28,13 +28,12 @@ TopLevelWidget::PrivateData::PrivateData(TopLevelWidget* const s, Window& w)
selfw(s),
window(w)
{
window.pData->topLevelWidget = self;
window.pData->topLevelWidgets.push_back(self);
}

TopLevelWidget::PrivateData::~PrivateData()
{
// FIXME?
window.pData->topLevelWidget = nullptr;
window.pData->topLevelWidgets.remove(self);
}

bool TopLevelWidget::PrivateData::keyboardEvent(const KeyboardEvent& ev)


+ 65
- 20
dgl/src/WindowPrivateData.cpp View File

@@ -51,6 +51,12 @@ START_NAMESPACE_DGL
#define DEFAULT_WIDTH 640
#define DEFAULT_HEIGHT 480

#define FOR_EACH_TOP_LEVEL_WIDGET(it) \
for (std::list<TopLevelWidget*>::iterator it = topLevelWidgets.begin(); it != topLevelWidgets.end(); ++it)

#define FOR_EACH_TOP_LEVEL_WIDGET_INV(rit) \
for (std::list<TopLevelWidget*>::reverse_iterator rit = topLevelWidgets.rbegin(); rit != topLevelWidgets.rend(); ++rit)

// -----------------------------------------------------------------------

#ifdef DISTRHO_OS_WINDOWS
@@ -73,7 +79,7 @@ Window::PrivateData::PrivateData(Application& a, Window* const s)
appData(a.pData),
self(s),
view(puglNewView(appData->world)),
topLevelWidget(nullptr),
topLevelWidgets(),
isClosed(true),
isVisible(false),
isEmbed(false),
@@ -95,7 +101,7 @@ Window::PrivateData::PrivateData(Application& a, Window* const s, PrivateData* c
appData(a.pData),
self(s),
view(puglNewView(appData->world)),
topLevelWidget(nullptr),
topLevelWidgets(),
isClosed(true),
isVisible(false),
isEmbed(false),
@@ -121,7 +127,7 @@ Window::PrivateData::PrivateData(Application& a, Window* const s,
appData(a.pData),
self(s),
view(puglNewView(appData->world)),
topLevelWidget(nullptr),
topLevelWidgets(),
isClosed(parentWindowHandle == 0),
isVisible(parentWindowHandle != 0),
isEmbed(parentWindowHandle != 0),
@@ -152,7 +158,7 @@ Window::PrivateData::PrivateData(Application& a, Window* const s,
appData(a.pData),
self(s),
view(puglNewView(appData->world)),
topLevelWidget(nullptr),
topLevelWidgets(),
isClosed(parentWindowHandle == 0),
isVisible(parentWindowHandle != 0),
isEmbed(parentWindowHandle != 0),
@@ -642,8 +648,12 @@ void Window::PrivateData::onPuglConfigure(const double width, const double heigh
self->onReshape(uwidth, uheight);

#ifndef DPF_TEST_WINDOW_CPP
if (topLevelWidget != nullptr)
topLevelWidget->setSize(uwidth, uheight);
FOR_EACH_TOP_LEVEL_WIDGET(it)
{
TopLevelWidget* const widget(*it);

widget->setSize(uwidth, uheight);
}
#endif

// always repaint after a resize
@@ -657,8 +667,13 @@ void Window::PrivateData::onPuglExpose()
puglOnDisplayPrepare(view);

#ifndef DPF_TEST_WINDOW_CPP
if (topLevelWidget != nullptr)
topLevelWidget->pData->display();
FOR_EACH_TOP_LEVEL_WIDGET(it)
{
TopLevelWidget* const widget(*it);

if (widget->isVisible())
widget->pData->display();
}
#endif
}

@@ -711,8 +726,13 @@ void Window::PrivateData::onPuglKey(const Widget::KeyboardEvent& ev)
return modal.child->focus();

#ifndef DPF_TEST_WINDOW_CPP
if (topLevelWidget != nullptr)
topLevelWidget->pData->keyboardEvent(ev);
FOR_EACH_TOP_LEVEL_WIDGET_INV(rit)
{
TopLevelWidget* const widget(*rit);

if (widget->isVisible() && widget->pData->keyboardEvent(ev))
break;
}
#endif
}

@@ -724,8 +744,13 @@ void Window::PrivateData::onPuglSpecial(const Widget::SpecialEvent& ev)
return modal.child->focus();

#ifndef DPF_TEST_WINDOW_CPP
if (topLevelWidget != nullptr)
topLevelWidget->pData->specialEvent(ev);
FOR_EACH_TOP_LEVEL_WIDGET_INV(rit)
{
TopLevelWidget* const widget(*rit);

if (widget->isVisible() && widget->pData->specialEvent(ev))
break;
}
#endif
}

@@ -737,8 +762,13 @@ void Window::PrivateData::onPuglText(const Widget::CharacterInputEvent& ev)
return modal.child->focus();

#ifndef DPF_TEST_WINDOW_CPP
if (topLevelWidget != nullptr)
topLevelWidget->pData->characterInputEvent(ev);
FOR_EACH_TOP_LEVEL_WIDGET_INV(rit)
{
TopLevelWidget* const widget(*rit);

if (widget->isVisible() && widget->pData->characterInputEvent(ev))
break;
}
#endif
}

@@ -750,8 +780,13 @@ void Window::PrivateData::onPuglMouse(const Widget::MouseEvent& ev)
return modal.child->focus();

#ifndef DPF_TEST_WINDOW_CPP
if (topLevelWidget != nullptr)
topLevelWidget->pData->mouseEvent(ev);
FOR_EACH_TOP_LEVEL_WIDGET_INV(rit)
{
TopLevelWidget* const widget(*rit);

if (widget->isVisible() && widget->pData->mouseEvent(ev))
break;
}
#endif
}

@@ -763,8 +798,13 @@ void Window::PrivateData::onPuglMotion(const Widget::MotionEvent& ev)
return modal.child->focus();

#ifndef DPF_TEST_WINDOW_CPP
if (topLevelWidget != nullptr)
topLevelWidget->pData->motionEvent(ev);
FOR_EACH_TOP_LEVEL_WIDGET_INV(rit)
{
TopLevelWidget* const widget(*rit);

if (widget->isVisible() && widget->pData->motionEvent(ev))
break;
}
#endif
}

@@ -776,8 +816,13 @@ void Window::PrivateData::onPuglScroll(const Widget::ScrollEvent& ev)
return modal.child->focus();

#ifndef DPF_TEST_WINDOW_CPP
if (topLevelWidget != nullptr)
topLevelWidget->pData->scrollEvent(ev);
FOR_EACH_TOP_LEVEL_WIDGET_INV(rit)
{
TopLevelWidget* const widget(*rit);

if (widget->isVisible() && widget->pData->scrollEvent(ev))
break;
}
#endif
}



+ 4
- 2
dgl/src/WindowPrivateData.hpp View File

@@ -23,6 +23,8 @@

#include "pugl.hpp"

#include <list>

START_NAMESPACE_DGL

class TopLevelWidget;
@@ -45,8 +47,8 @@ struct Window::PrivateData : IdleCallback {
/** Reserved space for graphics context. */
mutable uint8_t graphicsContext[sizeof(void*)];

/** The top-level widget associated with this Window. */
TopLevelWidget* topLevelWidget;
/** The top-level widgets associated with this Window. */
std::list<TopLevelWidget*> topLevelWidgets;

/** Whether this Window is closed (not visible or counted in the Application it is tied to).
Defaults to true unless embed (embed windows are never closed). */


Loading…
Cancel
Save