2006-03-04 18:16:49 +00:00
|
|
|
|
|
|
|
#include "MetersListBox.h"
|
|
|
|
|
|
|
|
#include "ListBox.h"
|
|
|
|
#include "Settings.h"
|
|
|
|
#include "ScreenManager.h"
|
|
|
|
|
|
|
|
#include "debug.h"
|
|
|
|
#include <assert.h>
|
|
|
|
|
|
|
|
/*{
|
|
|
|
|
|
|
|
typedef struct MetersListBox_ {
|
|
|
|
ListBox super;
|
|
|
|
|
|
|
|
Settings* settings;
|
2006-05-30 13:45:40 +00:00
|
|
|
Vector* meters;
|
2006-03-04 18:16:49 +00:00
|
|
|
ScreenManager* scr;
|
|
|
|
} MetersListBox;
|
|
|
|
|
|
|
|
}*/
|
|
|
|
|
2006-05-30 13:45:40 +00:00
|
|
|
MetersListBox* MetersListBox_new(Settings* settings, char* header, Vector* meters, ScreenManager* scr) {
|
2006-03-04 18:16:49 +00:00
|
|
|
MetersListBox* this = (MetersListBox*) malloc(sizeof(MetersListBox));
|
|
|
|
ListBox* super = (ListBox*) this;
|
|
|
|
ListBox_init(super, 1, 1, 1, 1, LISTITEM_CLASS, true);
|
|
|
|
((Object*)this)->delete = MetersListBox_delete;
|
|
|
|
|
|
|
|
this->settings = settings;
|
|
|
|
this->meters = meters;
|
|
|
|
this->scr = scr;
|
|
|
|
super->eventHandler = MetersListBox_EventHandler;
|
|
|
|
ListBox_setHeader(super, header);
|
2006-05-30 13:45:40 +00:00
|
|
|
for (int i = 0; i < Vector_size(meters); i++) {
|
|
|
|
Meter* meter = (Meter*) Vector_get(meters, i);
|
2006-03-04 18:16:49 +00:00
|
|
|
ListBox_add(super, (Object*) Meter_toListItem(meter));
|
|
|
|
}
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MetersListBox_delete(Object* object) {
|
|
|
|
ListBox* super = (ListBox*) object;
|
|
|
|
MetersListBox* this = (MetersListBox*) object;
|
|
|
|
ListBox_done(super);
|
|
|
|
free(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
HandlerResult MetersListBox_EventHandler(ListBox* super, int ch) {
|
|
|
|
MetersListBox* this = (MetersListBox*) super;
|
|
|
|
|
|
|
|
int selected = ListBox_getSelectedIndex(super);
|
|
|
|
HandlerResult result = IGNORED;
|
|
|
|
|
|
|
|
switch(ch) {
|
|
|
|
case 0x0a:
|
|
|
|
case 0x0d:
|
|
|
|
case KEY_ENTER:
|
|
|
|
case KEY_F(4):
|
|
|
|
case 't':
|
|
|
|
{
|
2006-05-30 13:45:40 +00:00
|
|
|
Meter* meter = (Meter*) Vector_get(this->meters, selected);
|
2006-04-10 20:40:38 +00:00
|
|
|
int mode = meter->mode + 1;
|
|
|
|
if (mode == LAST_METERMODE) mode = 1;
|
2006-03-04 18:16:49 +00:00
|
|
|
Meter_setMode(meter, mode);
|
|
|
|
ListBox_set(super, selected, (Object*) Meter_toListItem(meter));
|
|
|
|
result = HANDLED;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case KEY_F(7):
|
|
|
|
case '[':
|
|
|
|
case '-':
|
|
|
|
{
|
2006-05-30 13:45:40 +00:00
|
|
|
Vector_moveUp(this->meters, selected);
|
2006-03-04 18:16:49 +00:00
|
|
|
ListBox_moveSelectedUp(super);
|
|
|
|
result = HANDLED;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case KEY_F(8):
|
|
|
|
case ']':
|
|
|
|
case '+':
|
|
|
|
{
|
2006-05-30 13:45:40 +00:00
|
|
|
Vector_moveDown(this->meters, selected);
|
2006-03-04 18:16:49 +00:00
|
|
|
ListBox_moveSelectedDown(super);
|
|
|
|
result = HANDLED;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case KEY_F(9):
|
|
|
|
case KEY_DC:
|
|
|
|
{
|
2006-05-30 13:45:40 +00:00
|
|
|
if (selected < Vector_size(this->meters)) {
|
|
|
|
Vector_remove(this->meters, selected);
|
2006-03-04 18:16:49 +00:00
|
|
|
ListBox_remove(super, selected);
|
|
|
|
}
|
|
|
|
result = HANDLED;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (result == HANDLED) {
|
|
|
|
Header* header = this->settings->header;
|
|
|
|
Header_calculateHeight(header);
|
|
|
|
Header_draw(header);
|
|
|
|
ScreenManager_resize(this->scr, this->scr->x1, header->height, this->scr->x2, this->scr->y2);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|