diff options
author | Mateusz Kaduk <mateusz.kaduk@gmail.com> | 2005-05-15 09:17:40 +0000 |
---|---|---|
committer | Mateusz Kaduk <mateusz.kaduk@gmail.com> | 2005-05-15 09:17:40 +0000 |
commit | 13deabf8b93a2a6307978d9f49ad8fde5dbefdfd (patch) | |
tree | e21a23d1e6606ca86fb5629cd4048d62e560191c | |
parent | 0632377e8b2e63f965b30ac89a9e2dca819735ef (diff) | |
download | mana-client-13deabf8b93a2a6307978d9f49ad8fde5dbefdfd.tar.gz mana-client-13deabf8b93a2a6307978d9f49ad8fde5dbefdfd.tar.bz2 mana-client-13deabf8b93a2a6307978d9f49ad8fde5dbefdfd.tar.xz mana-client-13deabf8b93a2a6307978d9f49ad8fde5dbefdfd.zip |
Using guichan ListModel
-rw-r--r-- | src/gui/buddywindow.cpp | 11 | ||||
-rw-r--r-- | src/gui/buddywindow.h | 3 | ||||
-rw-r--r-- | src/resources/buddylist.cpp | 39 | ||||
-rw-r--r-- | src/resources/buddylist.h | 13 |
4 files changed, 33 insertions, 33 deletions
diff --git a/src/gui/buddywindow.cpp b/src/gui/buddywindow.cpp index e5b0d82f..54652a30 100644 --- a/src/gui/buddywindow.cpp +++ b/src/gui/buddywindow.cpp @@ -23,17 +23,17 @@ #include "buddywindow.h" BuddyWindow::BuddyWindow(): - Window("") + Window("Buddys") { setContentSize(80,200); - textlist = new TextBox(); - textlist->setEditable(false); - scrollArea = new ScrollArea(textlist); + listbox = new gcn::ListBox(); + listbox->setListModel(dynamic_cast<ListModel*>(this)); + scrollArea = new ScrollArea(listbox); } BuddyWindow::~BuddyWindow() { - delete textlist; + delete listbox; delete scrollArea; } @@ -41,6 +41,7 @@ void BuddyWindow::draw(gcn::Graphics *graphics) { // Draw the children Window::draw(graphics); + } void BuddyWindow::action(const std::string& eventId) diff --git a/src/gui/buddywindow.h b/src/gui/buddywindow.h index 8fa515d5..00fb07fb 100644 --- a/src/gui/buddywindow.h +++ b/src/gui/buddywindow.h @@ -26,7 +26,6 @@ #include <guichan.hpp> #include "window.h" #include "scrollarea.h" -#include "textbox.h" #include "../resources/buddylist.h" /** @@ -59,7 +58,7 @@ class BuddyWindow : public Window, public BuddyList, void action(const std::string &actionId); private: - TextBox *textlist; + gcn::ListBox *listbox; ScrollArea *scrollArea; }; diff --git a/src/resources/buddylist.cpp b/src/resources/buddylist.cpp index 0f64492b..87e6438f 100644 --- a/src/resources/buddylist.cpp +++ b/src/resources/buddylist.cpp @@ -24,7 +24,7 @@ #include <iostream> BuddyList::BuddyList() -{ +{ } BuddyList::~BuddyList() @@ -39,19 +39,22 @@ bool BuddyList::addBuddy(const std::string buddy) if(*buddyit == buddy) return false; } - // Buddy doesnt exist + // Buddy doesnt exist, add it buddylist.push_back(buddy); + return true; } bool BuddyList::removeBuddy(const std::string buddy) { - for(buddyit = buddylist.begin(); buddyit != buddylist.end(); buddyit++) - { - // Buddy exist, remove it - if(*buddyit == buddy) { - buddylist.remove(buddy); - return true; + if(buddylist.size() > 0) { + for(buddyit = buddylist.begin(); buddyit != buddylist.end(); buddyit++) + { + // Buddy exist, remove it + if(*buddyit == buddy) { + buddylist.remove(buddy); + return true; + } } } @@ -59,24 +62,20 @@ bool BuddyList::removeBuddy(const std::string buddy) return false; } -int BuddyList::getBuddyNumber(void) +int BuddyList::getNumberOfElements(void) { - int ret = 0; - for(buddyit = buddylist.begin(); buddyit != buddylist.end(); buddyit++) - ret++; - return ret; + return buddylist.size(); } -std::string BuddyList::getBuddy(int number) +std::string BuddyList::getElementAt(int number) { - int i = 0; - for(buddyit = buddylist.begin(); buddyit != buddylist.end(); buddyit++) + if(number <= buddylist.size()) { - if(i == number) - return *buddyit; - i++; + buddyit = buddylist.begin(); + std::advance(buddyit, number); + return *buddyit; } - + return ""; } diff --git a/src/resources/buddylist.h b/src/resources/buddylist.h index cb798f1e..704ce450 100644 --- a/src/resources/buddylist.h +++ b/src/resources/buddylist.h @@ -23,10 +23,11 @@ #ifndef _TMW_BUDDYLIST_H #define _TMW_BUDDYLIST_H +#include <guichan.hpp> #include <list> #include <string> -class BuddyList { +class BuddyList : public gcn::ListModel { public: /** * Constructor @@ -36,27 +37,27 @@ class BuddyList { /** * Destructor */ - ~BuddyList(); + virtual ~BuddyList(); /** - * Adds 'buddy' to the list + * Adds buddy to the list */ bool addBuddy(const std::string buddy); /** - * Removes 'buddy' from the list + * Removes buddy from the list */ bool removeBuddy(const std::string buddy); /** * Returns the number of buddy on the list */ - int getBuddyNumber(void); + int getNumberOfElements(void); /** * Returns the buddy of the number or null */ - std::string getBuddy(int number); + std::string getElementAt(int number); private: std::list<std::string> buddylist; /**< Buddy list */ |