From 21bb5bd2bd4243dc83a08d6e0329b5de2f96b1fe Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Sat, 3 Oct 2015 14:34:20 +0200 Subject: Refactor ComboBox and ListBox(Thin and Basic). --- plugingui/listboxbasic.h | 84 +++++++++++++++++++++--------------------------- 1 file changed, 36 insertions(+), 48 deletions(-) (limited to 'plugingui/listboxbasic.h') diff --git a/plugingui/listboxbasic.h b/plugingui/listboxbasic.h index deb4a67..ef6aceb 100644 --- a/plugingui/listboxbasic.h +++ b/plugingui/listboxbasic.h @@ -24,8 +24,7 @@ * along with DrumGizmo; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -#ifndef __DRUMGIZMO_LISTBOXBASIC_H__ -#define __DRUMGIZMO_LISTBOXBASIC_H__ +#pragma once #include #include @@ -33,69 +32,58 @@ #include "widget.h" #include "font.h" #include "painter.h" - #include "scrollbar.h" +#include "notifier.h" namespace GUI { class ListBoxBasic : public Widget { public: - class Item { - public: - std::string name; - std::string value; - }; - - ListBoxBasic(Widget *parent); - ~ListBoxBasic(); + class Item { + public: + std::string name; + std::string value; + }; - bool isFocusable() { return true; } + ListBoxBasic(Widget *parent); + ~ListBoxBasic(); - void addItem(std::string name, std::string value); - void addItems(std::vector &items); + void addItem(std::string name, std::string value); + void addItems(std::vector &items); - void clear(); - bool selectItem(int index); - std::string selectedName(); - std::string selectedValue(); + void clear(); + bool selectItem(int index); + std::string selectedName(); + std::string selectedValue(); - void clearSelectedValue(); + void clearSelectedValue(); - void registerSelectHandler(void (*handler)(void *), void *ptr); - void registerClickHandler(void (*handler)(void *), void *ptr); - void registerValueChangeHandler(void (*handler)(void *), void *ptr); + // From Widget: + bool isFocusable() override { return true; } + virtual void repaintEvent(RepaintEvent *e) override; + virtual void buttonEvent(ButtonEvent *e) override; + virtual void scrollEvent(ScrollEvent *e) override; + virtual void keyEvent(KeyEvent *e) override; + virtual void resize(int w, int h) override; - virtual void repaintEvent(RepaintEvent *e); - virtual void buttonEvent(ButtonEvent *e); - virtual void scrollEvent(ScrollEvent *e); - virtual void keyEvent(KeyEvent *e); - virtual void resize(int w, int h); + Notifier<> selectionNotifier; + Notifier<> clickNotifier; + Notifier<> valueChangedNotifier; private: - ScrollBar scroll; - - Image bg_img; - - void setSelection(int index); + ScrollBar scroll; - std::vector items; + Image bg_img; - int selected; - int marked; - GUI::Font font; - int padding; - int btn_size; + void setSelection(int index); - void (*sel_handler)(void *); - void *sel_ptr; - - void (*clk_handler)(void *); - void *clk_ptr; - - void (*valch_handler)(void *); - void *valch_ptr; -}; + std::vector items; + int selected; + int marked; + Font font; + int padding; + int btn_size; }; -#endif/*__DRUMGIZMO_LISTBOXBASIC_H__*/ +} // GUI:: -- cgit v1.2.3