Added IWindowGroup, which is extended by ILayout and implemented by

LayoutBase. Recursive create/destroy working.
This commit is contained in:
casey 2016-05-14 01:11:03 -07:00
parent 17b56ddbab
commit dd29f1e500
12 changed files with 143 additions and 13 deletions

View File

@ -1,8 +1,8 @@
#pragma once
#include "IWindow.h"
#include "IWindowGroup.h"
class ILayout {
class ILayout : public IWindowGroup {
public:
virtual IWindow* FocusNext() = 0;
virtual IWindow* FocusPrev() = 0;

View File

@ -6,6 +6,11 @@ class IWindow {
public:
virtual void Repaint() = 0;
virtual void SetParent(IWindow* parent) = 0;
virtual void Create() = 0;
virtual void Destroy() = 0;
virtual void SetContentColor(int color) = 0;
virtual void SetFrameColor(int color) = 0;
@ -23,4 +28,6 @@ class IWindow {
virtual WINDOW* GetFrame() const = 0;
virtual WINDOW* GetContent() const = 0;
};
};
typedef std::shared_ptr<IWindow> IWindowPtr;

11
src/musikbox/IWindowGroup.h Executable file
View File

@ -0,0 +1,11 @@
#pragma once
#include "IWindow.h"
class IWindowGroup {
public:
virtual bool AddWindow(IWindowPtr window) = 0;
virtual bool RemoveWindow(IWindowPtr window) = 0;
virtual size_t GetWindowCount() = 0;
virtual IWindowPtr GetWindowAt(size_t position) = 0;
};

View File

@ -1,2 +1,62 @@
#include "stdafx.h"
#include "LayoutBase.h"
LayoutBase::LayoutBase(IWindow* parent)
: Window(parent) {
this->SetFrameVisible(false);
}
LayoutBase::~LayoutBase() {
}
void LayoutBase::Create() {
Window::Create();
for (size_t i = 0; i < this->children.size(); i++) {
this->children.at(i)->Create();
}
}
void LayoutBase::Destroy() {
for (size_t i = 0; i < this->children.size(); i++) {
this->children.at(i)->Destroy();
}
Window::Destroy();
}
bool LayoutBase::AddWindow(IWindowPtr window) {
std::vector<IWindowPtr>::iterator it = this->children.begin();
for (; it != this->children.end(); it++) {
if (*it == window) {
return true;
}
}
window->SetParent(this);
this->children.push_back(window);
return true;
}
bool LayoutBase::RemoveWindow(IWindowPtr window) {
std::vector<IWindowPtr>::iterator it = this->children.begin();
for ( ; it != this->children.end(); it++) {
if (*it == window) {
this->children.erase(it);
return true;
}
}
return false;
}
size_t LayoutBase::GetWindowCount() {
return this->children.size();
}
IWindowPtr LayoutBase::GetWindowAt(size_t position) {
return this->children.at(position);
}

View File

@ -7,9 +7,26 @@
class LayoutBase : public Window, public ILayout {
public:
LayoutBase(IWindow* parent = NULL);
virtual ~LayoutBase();
/* IWindow */
virtual void Create();
virtual void Destroy();
/* ILayout */
virtual IWindow* FocusNext() = 0;
virtual IWindow* FocusPrev() = 0;
virtual IWindow* GetFocus() = 0;
virtual void Layout() = 0;
virtual void OnIdle() = 0;
/* IWindowGroup */
virtual bool AddWindow(IWindowPtr window);
virtual bool RemoveWindow(IWindowPtr window);
virtual size_t GetWindowCount();
virtual IWindowPtr GetWindowAt(size_t position);
private:
std::vector<IWindowPtr> children;
};

View File

@ -3,13 +3,18 @@
#include "Screen.h"
#include "LibraryLayout.h"
LibraryLayout::LibraryLayout(LibraryPtr library) {
LibraryLayout::LibraryLayout(LibraryPtr library)
: LayoutBase() {
this->SetSize(Screen::GetWidth(), Screen::GetHeight());
this->SetPosition(0, 0);
this->Create();
this->albumList.reset(new CategoryListView(this, library));
this->trackList.reset(new TrackListView(this));
this->albumList.reset(new CategoryListView(NULL, library));
this->trackList.reset(new TrackListView(NULL));
this->AddWindow(this->albumList);
this->AddWindow(this->trackList);
this->Layout();
}

View File

@ -20,6 +20,6 @@ class LibraryLayout : public LayoutBase {
virtual void OnIdle();
private:
boost::shared_ptr<CategoryListView> albumList;
boost::shared_ptr<TrackListView> trackList;
std::shared_ptr<CategoryListView> albumList;
std::shared_ptr<TrackListView> trackList;
};

View File

@ -18,7 +18,9 @@ static inline IWindow* adjustFocus(IWindow* oldFocus, IWindow* newFocus) {
return newFocus;
}
MainLayout::MainLayout(Transport& transport, LibraryPtr library) {
MainLayout::MainLayout(Transport& transport, LibraryPtr library)
: LayoutBase()
{
this->SetSize(Screen::GetWidth(), Screen::GetHeight());
this->SetPosition(0, 0);
this->SetFrameVisible(false);

View File

@ -2,6 +2,7 @@
#include "stdafx.h"
#include "Window.h"
#include "IWindowGroup.h"
Window::Window(IWindow *parent) {
this->frame = this->content = 0;
@ -19,6 +20,23 @@ Window::~Window() {
this->Destroy();
}
void Window::SetParent(IWindow* parent) {
if (this->parent != parent) {
IWindowGroup* group = dynamic_cast<IWindowGroup*>(parent);
if (group) {
group->RemoveWindow(shared_from_this());
}
this->parent = parent;
if (this->frame) {
this->Destroy();
this->Create();
}
}
}
void Window::SetSize(int width, int height) {
this->width = width;
this->height = height;
@ -113,7 +131,7 @@ void Window::Create() {
wbkgd(this->frame, COLOR_PAIR(this->contentColor));
}
wrefresh(this->content);
wnoutrefresh(this->content);
}
/* otherwise we'll draw a box around the frame, and create a content
@ -137,8 +155,8 @@ void Window::Create() {
wbkgd(this->content, COLOR_PAIR(this->contentColor));
}
touchwin(this->content);
wnoutrefresh(this->frame);
touchwin(this->content);
wnoutrefresh(this->content);
doupdate();
}
@ -177,6 +195,10 @@ void Window::Repaint() {
void Window::Destroy() {
if (this->frame) {
wclear(this->frame);
wclear(this->content);
this->Repaint();
delwin(this->content);
if (this->content != this->frame) {

View File

@ -3,13 +3,15 @@
#include "curses_config.h"
#include "IWindow.h"
class Window : public IWindow {
class Window : public IWindow, public std::enable_shared_from_this<IWindow> {
public:
Window(IWindow* parent = NULL);
virtual ~Window();
virtual void SetParent(IWindow* parent);
virtual void Create();
void Destroy();
virtual void Destroy();
virtual void Repaint();

View File

@ -147,6 +147,7 @@
<ItemGroup>
<ClInclude Include="CategoryListQuery.h" />
<ClInclude Include="CategoryListView.h" />
<ClInclude Include="IWindowGroup.h" />
<ClInclude Include="LayoutBase.h" />
<ClInclude Include="ScrollAdapterBase.h" />
<ClInclude Include="IScrollable.h" />

View File

@ -150,6 +150,9 @@
<ClInclude Include="LayoutBase.h">
<Filter>curses</Filter>
</ClInclude>
<ClInclude Include="IWindowGroup.h">
<Filter>curses</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<Filter Include="curses">