summaryrefslogtreecommitdiff
path: root/plugingui/combobox.cc
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2013-03-13 18:46:17 +0100
committerBent Bisballe Nyeng <deva@aasimon.org>2013-03-13 18:46:17 +0100
commitd55de707c3352a468a227d69920a56ef2550a7cc (patch)
tree3f7ac91962d7e09328fb24d4eb52707a3f6e7f22 /plugingui/combobox.cc
parentc17046353762a0893914e671f1f19eadce6f94f5 (diff)
Added path lineedit and drive selection (win32) to filebrowser. Made a lot of small layout tweaks.
Diffstat (limited to 'plugingui/combobox.cc')
-rw-r--r--plugingui/combobox.cc153
1 files changed, 153 insertions, 0 deletions
diff --git a/plugingui/combobox.cc b/plugingui/combobox.cc
index 483f62c..20779e8 100644
--- a/plugingui/combobox.cc
+++ b/plugingui/combobox.cc
@@ -26,6 +26,159 @@
*/
#include "combobox.h"
+#include "painter.h"
+#include "font.h"
+
+#include <stdio.h>
+
+#define BORDER 10
+
+void listboxSelectHandler(void *ptr)
+{
+ GUI::ComboBox *c = (GUI::ComboBox*)ptr;
+ GUI::ButtonEvent e;
+ e.direction = 1;
+ c->buttonEvent(&e);
+}
+
+GUI::ComboBox::ComboBox(GUI::Widget *parent)
+ : GUI::Widget(parent)
+{
+ handler = NULL;
+ ptr = NULL;
+
+ listbox = new GUI::ListBox(parent);
+ listbox->registerSelectHandler(listboxSelectHandler, this);
+ listbox->registerClickHandler(listboxSelectHandler, this);
+ listbox->hide();
+}
+
+GUI::ComboBox::~ComboBox()
+{
+}
+
+void GUI::ComboBox::addItem(std::string name, std::string value)
+{
+ listbox->addItem(name, value);
+}
+
+void GUI::ComboBox::clear()
+{
+ listbox->clear();
+ repaintEvent(NULL);
+}
+
+bool GUI::ComboBox::selectItem(int index)
+{
+ listbox->selectItem(index);
+ repaintEvent(NULL);
+ return true;
+}
+
+std::string GUI::ComboBox::selectedName()
+{
+ return listbox->selectedName();
+}
+
+std::string GUI::ComboBox::selectedValue()
+{
+ return listbox->selectedValue();
+}
+
+void GUI::ComboBox::registerValueChangedHandler(void (*handler)(void *),
+ void *ptr)
+{
+ this->handler = handler;
+ this->ptr = ptr;
+}
+
+void GUI::ComboBox::repaintEvent(GUI::RepaintEvent *e)
+{
+ Painter p(this);
+
+ int h = 16;
+
+ std::string _text = selectedName();
+
+ p.setColour(Colour(0, 0.4));
+ p.drawFilledRectangle(3,3,width()-3,h-3);
+
+ p.setColour(Colour(1,1,1));
+ p.drawRectangle(0,0,width()-1,h-1);
+ p.drawRectangle(2,2,width()-3,h-3);
+ p.drawText(BORDER - 4, h/2+5 + 1, font, _text);
+}
+
+void GUI::ComboBox::scrollEvent(ScrollEvent *e)
+{
+ /*
+ scroll_offset += e->delta;
+ if(scroll_offset < 0) scroll_offset = 0;
+ if(scroll_offset > (items.size() - 1))
+ scroll_offset = (items.size() - 1);
+ repaintEvent(NULL);
+ */
+}
+
+void GUI::ComboBox::keyEvent(GUI::KeyEvent *e)
+{
+ if(e->direction != -1) return;
+
+ /*
+ switch(e->keycode) {
+ case GUI::KeyEvent::KEY_UP:
+ {
+ selected--;
+ if(selected < 0) selected = 0;
+ if(selected < scroll_offset) {
+ scroll_offset = selected;
+ if(scroll_offset < 0) scroll_offset = 0;
+ }
+ }
+ break;
+ case GUI::KeyEvent::KEY_DOWN:
+ {
+ // Number of items that can be displayed at a time.
+ int numitems = height() / (font.textHeight() + padding);
+
+ selected++;
+ if(selected > (items.size() - 1))
+ selected = (items.size() - 1);
+ if(selected > (scroll_offset + numitems - 1)) {
+ scroll_offset = selected - numitems + 1;
+ if(scroll_offset > (items.size() - 1))
+ scroll_offset = (items.size() - 1);
+ }
+ }
+ break;
+ case GUI::KeyEvent::KEY_HOME:
+ selected = 0;
+ break;
+ case GUI::KeyEvent::KEY_END:
+ selected = items.size() - 1;
+ break;
+ default:
+ break;
+ }
+
+ repaintEvent(NULL);
+ */
+}
+
+void GUI::ComboBox::buttonEvent(ButtonEvent *e)
+{
+ if(e->direction != 1) return;
+
+ if(!listbox->visible()) {
+ listbox->resize(width() - 1, 100);
+ listbox->move(x(), y() + 16);
+ } else {
+ if(handler) handler(ptr);
+ }
+
+ listbox->setVisible(!listbox->visible());
+}
+
#ifdef TEST_COMBOBOX
//Additional dependency files
//deps: