diff options
author | Daniel Lange <DLange@git.local> | 2016-04-11 13:00:15 +0200 |
---|---|---|
committer | Daniel Lange <DLange@git.local> | 2016-04-11 13:00:15 +0200 |
commit | d3c9975943df58e293359b87905d19ff1fd52061 (patch) | |
tree | e416378879f60e8d538b1b25963904f767d30ff4 /SignalsListBox.c | |
download | debian_htop-d3c9975943df58e293359b87905d19ff1fd52061.tar.gz debian_htop-d3c9975943df58e293359b87905d19ff1fd52061.tar.bz2 debian_htop-d3c9975943df58e293359b87905d19ff1fd52061.zip |
Imported Upstream version 0.5upstream/0.5
Diffstat (limited to 'SignalsListBox.c')
-rw-r--r-- | SignalsListBox.c | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/SignalsListBox.c b/SignalsListBox.c new file mode 100644 index 0000000..591483b --- /dev/null +++ b/SignalsListBox.c @@ -0,0 +1,76 @@ + +#include "SignalsListBox.h" +#include "ListBox.h" +#include "Signal.h" +#include "RichString.h" + +#include "debug.h" +#include <assert.h> + +#include <ctype.h> + +/*{ + +typedef struct SignalsListBox_ { + ListBox super; + + int state; + Signal** signals; +} SignalsListBox; + +}*/ + +SignalsListBox* SignalsListBox_new(int x, int y, int w, int h) { + SignalsListBox* this = (SignalsListBox*) malloc(sizeof(SignalsListBox)); + ListBox* super = (ListBox*) this; + ListBox_init(super, x, y, w, h, SIGNAL_CLASS, true); + ((Object*)this)->delete = SignalsListBox_delete; + + this->signals = Signal_getSignalTable(); + super->eventHandler = SignalsListBox_eventHandler; + int sigCount = Signal_getSignalCount(); + for(int i = 0; i < sigCount; i++) + ListBox_set(super, i, (Object*) this->signals[i]); + SignalsListBox_reset(this); + return this; +} + +void SignalsListBox_delete(Object* object) { + ListBox* super = (ListBox*) object; + SignalsListBox* this = (SignalsListBox*) object; + ListBox_done(super); + free(this->signals); + free(this); +} + +void SignalsListBox_reset(SignalsListBox* this) { + ListBox* super = (ListBox*) this; + + ListBox_setHeader(super, RichString_quickString(CRT_colors[PANEL_HEADER_FOCUS], "Send signal:")); + ListBox_setSelected(super, 16); // 16th item is SIGTERM + this->state = 0; +} + +HandlerResult SignalsListBox_eventHandler(ListBox* super, int ch) { + SignalsListBox* this = (SignalsListBox*) super; + + int size = ListBox_getSize(super); + if (isdigit(ch)) { + int signal = ch-48 + this->state; + for (int i = 0; i < size; i++) + if (((Signal*) ListBox_get(super, i))->number == signal) { + ListBox_setSelected(super, i); + break; + } + this->state = signal * 10; + if (this->state > 100) + this->state = 0; + return HANDLED; + } else { + this->state = 0; + } + if (ch == 13) { + return BREAK_LOOP; + } + return IGNORED; +} |