diff options
author | Bent Bisballe Nyeng <deva@aasimon.org> | 2015-10-03 14:34:20 +0200 |
---|---|---|
committer | Bent Bisballe Nyeng <deva@aasimon.org> | 2015-10-03 14:34:20 +0200 |
commit | 21bb5bd2bd4243dc83a08d6e0329b5de2f96b1fe (patch) | |
tree | beef1c65f08a9677611b20fbb86deff5f1820bd9 /plugingui/listbox.cc | |
parent | 3be8598f672eb5b8e48373ed4ee59feff543ada2 (diff) |
Refactor ComboBox and ListBox(Thin and Basic).
Diffstat (limited to 'plugingui/listbox.cc')
-rw-r--r-- | plugingui/listbox.cc | 116 |
1 files changed, 59 insertions, 57 deletions
diff --git a/plugingui/listbox.cc b/plugingui/listbox.cc index ed873b2..22263b0 100644 --- a/plugingui/listbox.cc +++ b/plugingui/listbox.cc @@ -29,95 +29,97 @@ #include "painter.h" #include "font.h" -#include <stdio.h> - -GUI::ListBox::ListBox(GUI::Widget *parent) - : GUI::Widget(parent) +namespace GUI { + +ListBox::ListBox(Widget *parent) + : Widget(parent) + , selectionNotifier(basic.selectionNotifier) + , clickNotifier(basic.clickNotifier) + , valueChangedNotifier(basic.valueChangedNotifier) + , basic(this) { - box.topLeft = new Image(":widget_tl.png"); - box.top = new Image(":widget_t.png"); - box.topRight = new Image(":widget_tr.png"); - box.left = new Image(":widget_l.png"); - box.right = new Image(":widget_r.png"); - box.bottomLeft = new Image(":widget_bl.png"); - box.bottom = new Image(":widget_b.png"); - box.bottomRight = new Image(":widget_br.png"); - box.center = new Image(":widget_c.png"); - - basic = new GUI::ListBoxBasic(this); - basic->move(box.left->width(), box.top->height()); + box.topLeft = new Image(":widget_tl.png"); + box.top = new Image(":widget_t.png"); + box.topRight = new Image(":widget_tr.png"); + box.left = new Image(":widget_l.png"); + box.right = new Image(":widget_r.png"); + box.bottomLeft = new Image(":widget_bl.png"); + box.bottom = new Image(":widget_b.png"); + box.bottomRight = new Image(":widget_br.png"); + box.center = new Image(":widget_c.png"); + + basic.move(box.left->width(), box.top->height()); } -GUI::ListBox::~ListBox() +ListBox::~ListBox() { + delete box.topLeft; + delete box.top; + delete box.topRight; + delete box.left; + delete box.right; + delete box.bottomLeft; + delete box.bottom; + delete box.bottomRight; + delete box.center; } -void GUI::ListBox::addItem(std::string name, std::string value) +void ListBox::addItem(std::string name, std::string value) { - basic->addItem(name, value); + basic.addItem(name, value); } -void GUI::ListBox::addItems(std::vector<ListBoxBasic::Item> &items) +void ListBox::addItems(std::vector<ListBoxBasic::Item> &items) { - basic->addItems(items); + basic.addItems(items); } -void GUI::ListBox::clear() +void ListBox::clear() { - basic->clear(); + basic.clear(); } -bool GUI::ListBox::selectItem(int index) +bool ListBox::selectItem(int index) { - return basic->selectItem(index); + return basic.selectItem(index); } -std::string GUI::ListBox::selectedName() +std::string ListBox::selectedName() { - return basic->selectedName(); + return basic.selectedName(); } -std::string GUI::ListBox::selectedValue() +std::string ListBox::selectedValue() { - return basic->selectedValue(); + return basic.selectedValue(); } -void GUI::ListBox::clearSelectedValue() +void ListBox::clearSelectedValue() { - basic->clearSelectedValue(); + basic.clearSelectedValue(); } -void GUI::ListBox::registerClickHandler(void (*handler)(void *), void *ptr) +void ListBox::repaintEvent(RepaintEvent *e) { - basic->registerClickHandler(handler, ptr); -} + Painter p(this); -void GUI::ListBox::registerSelectHandler(void (*handler)(void *), void *ptr) -{ - basic->registerSelectHandler(handler, ptr); -} + p.clear(); -void GUI::ListBox::registerValueChangeHandler(void (*handler)(void *), - void *ptr) -{ - basic->registerValueChangeHandler(handler, ptr); -} + int w = width(); + int h = height(); + if(w == 0 || h == 0) + { + return; + } -void GUI::ListBox::repaintEvent(GUI::RepaintEvent *e) -{ - GUI::Painter p(this); - - p.clear(); - - int w = width(); - int h = height(); - if(w == 0 || h == 0) return; - p.drawBox(0, 0, &box, w, h); + p.drawBox(0, 0, &box, w, h); } -void GUI::ListBox::resize(int width, int height) +void ListBox::resize(int width, int height) { - GUI::Widget::resize(width, height); - basic->resize(width - (box.left->width() + box.right->width()), - height - (box.top->height() + box.bottom->height())); + Widget::resize(width, height); + basic.resize(width - (box.left->width() + box.right->width()), + height - (box.top->height() + box.bottom->height())); } + +} // GUI:: |