From ff9409b1737627857eb47f64f536a3f66b6a09a4 Mon Sep 17 00:00:00 2001 From: Daniel Lange Date: Mon, 11 Apr 2016 13:01:07 +0200 Subject: Imported Upstream version 2.0.0 --- ColumnsPanel.c | 77 ++++++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 54 insertions(+), 23 deletions(-) (limited to 'ColumnsPanel.c') diff --git a/ColumnsPanel.c b/ColumnsPanel.c index f4eed99..3ec9ee8 100644 --- a/ColumnsPanel.c +++ b/ColumnsPanel.c @@ -6,8 +6,11 @@ in the source distribution for its full text. */ #include "ColumnsPanel.h" +#include "Platform.h" -#include "String.h" +#include "StringUtils.h" +#include "ListItem.h" +#include "CRT.h" #include #include @@ -16,17 +19,18 @@ in the source distribution for its full text. /*{ #include "Panel.h" #include "Settings.h" -#include "ScreenManager.h" typedef struct ColumnsPanel_ { Panel super; Settings* settings; - ScreenManager* scr; + bool moving; } ColumnsPanel; }*/ +static const char* ColumnsFunctions[] = {" ", " ", " ", " ", " ", " ", "MoveUp", "MoveDn", "Remove", "Done ", NULL}; + static void ColumnsPanel_delete(Object* object) { Panel* super = (Panel*) object; ColumnsPanel* this = (ColumnsPanel*) object; @@ -35,12 +39,34 @@ static void ColumnsPanel_delete(Object* object) { } static HandlerResult ColumnsPanel_eventHandler(Panel* super, int ch) { + ColumnsPanel* const this = (ColumnsPanel*) super; int selected = Panel_getSelectedIndex(super); HandlerResult result = IGNORED; int size = Panel_size(super); switch(ch) { + case 0x0a: + case 0x0d: + case KEY_ENTER: + case KEY_MOUSE: + case KEY_RECLICK: + { + if (selected < size - 1) { + this->moving = !(this->moving); + Panel_setSelectionColor(super, this->moving ? CRT_colors[PANEL_SELECTION_FOLLOW] : CRT_colors[PANEL_SELECTION_FOCUS]); + ((ListItem*)Panel_getSelected(super))->moving = this->moving; + result = HANDLED; + } + break; + } + case KEY_UP: + { + if (!this->moving) { + break; + } + /* else fallthrough */ + } case KEY_F(7): case '[': case '-': @@ -50,6 +76,13 @@ static HandlerResult ColumnsPanel_eventHandler(Panel* super, int ch) { result = HANDLED; break; } + case KEY_DOWN: + { + if (!this->moving) { + break; + } + /* else fallthrough */ + } case KEY_F(8): case ']': case '+': @@ -70,7 +103,7 @@ static HandlerResult ColumnsPanel_eventHandler(Panel* super, int ch) { } default: { - if (isalpha(ch)) + if (ch < 255 && isalpha(ch)) result = Panel_selectByTyping(super, ch); if (result == BREAK_LOOP) result = IGNORED; @@ -90,47 +123,45 @@ PanelClass ColumnsPanel_class = { .eventHandler = ColumnsPanel_eventHandler }; -ColumnsPanel* ColumnsPanel_new(Settings* settings, ScreenManager* scr) { +ColumnsPanel* ColumnsPanel_new(Settings* settings) { ColumnsPanel* this = AllocThis(ColumnsPanel); Panel* super = (Panel*) this; - Panel_init(super, 1, 1, 1, 1, Class(ListItem), true); + FunctionBar* fuBar = FunctionBar_new(ColumnsFunctions, NULL, NULL); + Panel_init(super, 1, 1, 1, 1, Class(ListItem), true, fuBar); this->settings = settings; - this->scr = scr; + this->moving = false; Panel_setHeader(super, "Active Columns"); - ProcessField* fields = this->settings->pl->fields; + ProcessField* fields = this->settings->fields; for (; *fields; fields++) { - Panel_add(super, (Object*) ListItem_new(Process_fieldNames[*fields], 0)); + if (Process_fields[*fields].name) { + Panel_add(super, (Object*) ListItem_new(Process_fields[*fields].name, *fields)); + } } return this; } int ColumnsPanel_fieldNameToIndex(const char* name) { - for (int j = 1; j <= LAST_PROCESSFIELD; j++) { - if (String_eq(name, Process_fieldNames[j])) { + for (int j = 1; j <= Platform_numberOfFields; j++) { + if (String_eq(name, Process_fields[j].name)) { return j; } } - return 0; + return -1; } void ColumnsPanel_update(Panel* super) { ColumnsPanel* this = (ColumnsPanel*) super; int size = Panel_size(super); this->settings->changed = true; - // FIXME: this is crappily inefficient - free(this->settings->pl->fields); - this->settings->pl->fields = (ProcessField*) malloc(sizeof(ProcessField) * (size+1)); - this->settings->pl->flags = 0; + this->settings->fields = xRealloc(this->settings->fields, sizeof(ProcessField) * (size+1)); + this->settings->flags = 0; for (int i = 0; i < size; i++) { - char* text = ((ListItem*) Panel_get(super, i))->value; - int j = ColumnsPanel_fieldNameToIndex(text); - if (j > 0) { - this->settings->pl->fields[i] = j; - this->settings->pl->flags |= Process_fieldFlags[j]; - } + int key = ((ListItem*) Panel_get(super, i))->key; + this->settings->fields[i] = key; + this->settings->flags |= Process_fields[key].flags; } - this->settings->pl->fields[size] = 0; + this->settings->fields[size] = 0; } -- cgit v1.2.3