From 33afe8f744587b9a8da67e85298bb2e1c28d083d Mon Sep 17 00:00:00 2001 From: Bjørn Lindeijer Date: Fri, 10 Apr 2009 02:20:04 +0200 Subject: Reduced the GCContainer to be even more trivial A container that deletes all its children on destruction doesn't have to be so complicated. Also renamed it to simply Container, since I think it should simply be default behavior. WindowContainer and Popup classes now inherit from this Container. --- src/CMakeLists.txt | 4 +-- src/Makefile.am | 4 +-- src/gui/guildwindow.cpp | 1 - src/gui/guildwindow.h | 8 ------ src/gui/setuptab.h | 4 +-- src/gui/skilldialog.cpp | 5 ++-- src/gui/widgets/avatar.h | 4 +-- src/gui/widgets/container.cpp | 28 ++++++++++++++++++++ src/gui/widgets/container.h | 38 +++++++++++++++++++++++++++ src/gui/widgets/gccontainer.cpp | 54 --------------------------------------- src/gui/widgets/gccontainer.h | 50 ------------------------------------ src/gui/widgets/popup.cpp | 7 ----- src/gui/widgets/popup.h | 4 +-- src/gui/widgets/window.cpp | 6 +---- src/gui/widgets/windowcontainer.h | 4 +-- src/main.cpp | 8 ------ tmw.cbp | 4 +-- 17 files changed, 83 insertions(+), 150 deletions(-) create mode 100644 src/gui/widgets/container.cpp create mode 100644 src/gui/widgets/container.h delete mode 100644 src/gui/widgets/gccontainer.cpp delete mode 100644 src/gui/widgets/gccontainer.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index efb548ea..8d1dd1ea 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -64,12 +64,12 @@ SET(SRCS gui/widgets/chattab.h gui/widgets/checkbox.cpp gui/widgets/checkbox.h + gui/widgets/container.cpp + gui/widgets/container.h gui/widgets/desktop.cpp gui/widgets/desktop.h gui/widgets/dropdown.cpp gui/widgets/dropdown.h - gui/widgets/gccontainer.cpp - gui/widgets/gccontainer.h gui/widgets/icon.cpp gui/widgets/icon.h gui/widgets/inttextfield.cpp diff --git a/src/Makefile.am b/src/Makefile.am index e13299f0..6bef1960 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -17,12 +17,12 @@ tmw_SOURCES = gui/widgets/avatar.cpp \ gui/widgets/chattab.h \ gui/widgets/checkbox.cpp \ gui/widgets/checkbox.h \ + gui/widgets/container.cpp \ + gui/widgets/container.h \ gui/widgets/desktop.cpp \ gui/widgets/desktop.h \ gui/widgets/dropdown.cpp \ gui/widgets/dropdown.h \ - gui/widgets/gccontainer.cpp \ - gui/widgets/gccontainer.h \ gui/widgets/icon.cpp \ gui/widgets/icon.h \ gui/widgets/inttextfield.cpp \ diff --git a/src/gui/guildwindow.cpp b/src/gui/guildwindow.cpp index 91759687..020edf44 100644 --- a/src/gui/guildwindow.cpp +++ b/src/gui/guildwindow.cpp @@ -80,7 +80,6 @@ GuildWindow::GuildWindow(): GuildWindow::~GuildWindow() { - delete mGuildTabs; } void GuildWindow::update() diff --git a/src/gui/guildwindow.h b/src/gui/guildwindow.h index 3d7ac3ea..15f35b00 100644 --- a/src/gui/guildwindow.h +++ b/src/gui/guildwindow.h @@ -38,20 +38,12 @@ class TextDialog; class ConfirmDialog; class GuildListBox; class ScrollArea; -class GCContainer; class TabbedArea; class GuildWindow : public Window, public gcn::ActionListener { public: - /** - * Constructor. - */ GuildWindow(); - - /** - * Destructor. - */ ~GuildWindow(); /** diff --git a/src/gui/setuptab.h b/src/gui/setuptab.h index 7b92e2fe..f0af1ea9 100644 --- a/src/gui/setuptab.h +++ b/src/gui/setuptab.h @@ -22,14 +22,14 @@ #ifndef GUI_SETUPTAB_H #define GUI_SETUPTAB_H -#include "gui/widgets/gccontainer.h" +#include "gui/widgets/container.h" #include /** * A container for the contents of a tab in the setup window. */ -class SetupTab : public GCContainer +class SetupTab : public Container { public: SetupTab(); diff --git a/src/gui/skilldialog.cpp b/src/gui/skilldialog.cpp index 5788aa99..c3ff1ded 100644 --- a/src/gui/skilldialog.cpp +++ b/src/gui/skilldialog.cpp @@ -22,7 +22,7 @@ #include "gui/skilldialog.h" #include "gui/widgets/button.h" -#include "gui/widgets/gccontainer.h" +#include "gui/widgets/container.h" #include "gui/widgets/icon.h" #include "gui/widgets/label.h" #include "gui/widgets/listbox.h" @@ -40,7 +40,7 @@ #include #include -class SkillTab : public GCContainer, public gcn::ActionListener +class SkillTab : public Container, public gcn::ActionListener { public: /** @@ -197,7 +197,6 @@ SkillTab::SkillTab(const std::string &type): type(type) } update(); - } int SkillTab::getSkillNum() diff --git a/src/gui/widgets/avatar.h b/src/gui/widgets/avatar.h index d1380bfd..550e43b4 100644 --- a/src/gui/widgets/avatar.h +++ b/src/gui/widgets/avatar.h @@ -24,14 +24,14 @@ #include "guichanfwd.h" -#include "gui/widgets/gccontainer.h" +#include "gui/widgets/container.h" #include class Image; class Icon; -class Avatar : public GCContainer +class Avatar : public Container { public: /** diff --git a/src/gui/widgets/container.cpp b/src/gui/widgets/container.cpp new file mode 100644 index 00000000..10ef78a5 --- /dev/null +++ b/src/gui/widgets/container.cpp @@ -0,0 +1,28 @@ +/* + * The Mana World + * Copyright (C) 2004 The Mana World Development Team + * + * This file is part of The Mana World. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "gui/widgets/container.h" + +Container::~Container() +{ + while (!mWidgets.empty()) + delete mWidgets.front(); +} diff --git a/src/gui/widgets/container.h b/src/gui/widgets/container.h new file mode 100644 index 00000000..a6d1610e --- /dev/null +++ b/src/gui/widgets/container.h @@ -0,0 +1,38 @@ +/* + * The Mana World + * Copyright (C) 2004 The Mana World Development Team + * + * This file is part of The Mana World. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef GUI_CONTAINER_H +#define GUI_CONTAINER_H + +#include + +/** + * A widget container. The only difference between the standard Guichan + * container and this one is that childs added to this container are + * automatically deleted when the container is deleted. + */ +class Container : public gcn::Container +{ + public: + ~Container(); +}; + +#endif diff --git a/src/gui/widgets/gccontainer.cpp b/src/gui/widgets/gccontainer.cpp deleted file mode 100644 index 8325ccd4..00000000 --- a/src/gui/widgets/gccontainer.cpp +++ /dev/null @@ -1,54 +0,0 @@ -/* - * The Mana World - * Copyright (C) 2004 The Mana World Development Team - * - * This file is part of The Mana World. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include "gccontainer.h" - -GCContainer::~GCContainer() -{ - WidgetIterator i = mDeathList.begin(); - - while (i != mDeathList.end()) { - /* Take care _not_ to modify the list in our _announceDeath method */ - gcn::Widget *w = (*i); - i = mDeathList.erase(i); - delete w; - } - - mDeathList.clear(); -} - -void GCContainer::add(gcn::Widget *w) -{ - mDeathList.push_back(w); - Container::add(w); -} - -void GCContainer::add(gcn::Widget *w, int x, int y) -{ - mDeathList.push_back(w); - Container::add(w, x, y); -} - -void GCContainer::death(const gcn::Event &event) -{ - mDeathList.remove(event.getSource()); - Container::death(event); -} diff --git a/src/gui/widgets/gccontainer.h b/src/gui/widgets/gccontainer.h deleted file mode 100644 index da584a42..00000000 --- a/src/gui/widgets/gccontainer.h +++ /dev/null @@ -1,50 +0,0 @@ -/* - * The Mana World - * Copyright (C) 2004 The Mana World Development Team - * - * This file is part of The Mana World. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifndef GUI_GCCONTAINER_H -#define GUI_GCCONTAINER_H - -#include - -#include - -/** - * A garbage collecting container. Childs added to this container are - * automatically deleted when the container is deleted. - */ -class GCContainer : public gcn::Container -{ - public: - virtual ~GCContainer(); - - virtual void add(gcn::Widget *w); - - virtual void add(gcn::Widget *w, int x, int y); - - virtual void death(const gcn::Event &event); - - protected: - typedef std::list Widgets; - typedef Widgets::iterator WidgetIterator; - Widgets mDeathList; -}; - -#endif diff --git a/src/gui/widgets/popup.cpp b/src/gui/widgets/popup.cpp index 9040d6b2..7d73e749 100644 --- a/src/gui/widgets/popup.cpp +++ b/src/gui/widgets/popup.cpp @@ -65,13 +65,6 @@ Popup::~Popup() savePopupConfiguration(); - while (!mWidgets.empty()) - { - gcn::Widget *w = mWidgets.front(); - remove(w); - delete(w); - } - mSkin->instances--; } diff --git a/src/gui/widgets/popup.h b/src/gui/widgets/popup.h index 71ce2d89..928c8d32 100644 --- a/src/gui/widgets/popup.h +++ b/src/gui/widgets/popup.h @@ -23,7 +23,7 @@ #ifndef POPUP_H #define POPUP_H -#include +#include "gui/widgets/container.h" #include "guichanfwd.h" @@ -41,7 +41,7 @@ class WindowContainer; * * \ingroup GUI */ -class Popup : public gcn::Container +class Popup : public Container { public: /** diff --git a/src/gui/widgets/window.cpp b/src/gui/widgets/window.cpp index 0aadeb3e..1d7961f3 100644 --- a/src/gui/widgets/window.cpp +++ b/src/gui/widgets/window.cpp @@ -97,11 +97,7 @@ Window::~Window() delete mLayout; while (!mWidgets.empty()) - { - gcn::Widget *w = mWidgets.front(); - remove(w); - delete(w); - } + delete mWidgets.front(); removeWidgetListener(this); diff --git a/src/gui/widgets/windowcontainer.h b/src/gui/widgets/windowcontainer.h index bc918184..a2c285cb 100644 --- a/src/gui/widgets/windowcontainer.h +++ b/src/gui/widgets/windowcontainer.h @@ -22,7 +22,7 @@ #ifndef WINDOWCONTAINER_H #define WINDOWCONTAINER_H -#include +#include "gui/widgets/container.h" /** * A window container. This container adds functionality for more convenient @@ -30,7 +30,7 @@ * * \ingroup GUI */ -class WindowContainer : public gcn::Container +class WindowContainer : public Container { public: /** diff --git a/src/main.cpp b/src/main.cpp index 1f3d4664..913b7ae9 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1594,14 +1594,6 @@ int main(int argc, char *argv[]) } delete guiPalette; -#ifdef PACKAGE_VERSION - delete versionLabel; -#endif - delete progressBar; - delete progressLabel; - delete setupButton; - delete setupWindow; - delete desktop; #ifdef EATHENA_SUPPORT delete network; diff --git a/tmw.cbp b/tmw.cbp index c2a73270..058e220d 100644 --- a/tmw.cbp +++ b/tmw.cbp @@ -443,10 +443,10 @@ + + - - -- cgit v1.2.3-70-g09d2