SignalsListBox.c 1.78 KB
Newer Older
Hisham Muhammad's avatar
Hisham Muhammad committed
1

2
3
#include "SignalsPanel.h"
#include "Panel.h"
Hisham Muhammad's avatar
Hisham Muhammad committed
4
5
6
7
8
9
10
11
12
13
#include "SignalItem.h"
#include "RichString.h"

#include "debug.h"
#include <assert.h>

#include <ctype.h>

/*{

14
15
typedef struct SignalsPanel_ {
   Panel super;
Hisham Muhammad's avatar
Hisham Muhammad committed
16
17
18

   int state;
   Signal** signals;
19
} SignalsPanel;
Hisham Muhammad's avatar
Hisham Muhammad committed
20
21
22

}*/

23
24
25
26
27
SignalsPanel* SignalsPanel_new(int x, int y, int w, int h) {
   SignalsPanel* this = (SignalsPanel*) malloc(sizeof(SignalsPanel));
   Panel* super = (Panel*) this;
   Panel_init(super, x, y, w, h, SIGNAL_CLASS, true);
   ((Object*)this)->delete = SignalsPanel_delete;
Hisham Muhammad's avatar
Hisham Muhammad committed
28
29

   this->signals = Signal_getSignalTable();
30
   super->eventHandler = SignalsPanel_EventHandler;
Hisham Muhammad's avatar
Hisham Muhammad committed
31
32
   int sigCount = Signal_getSignalCount();
   for(int i = 0; i < sigCount; i++)
33
34
      Panel_set(super, i, (Object*) this->signals[i]);
   SignalsPanel_reset(this);
Hisham Muhammad's avatar
Hisham Muhammad committed
35
36
37
   return this;
}

38
39
40
41
void SignalsPanel_delete(Object* object) {
   Panel* super = (Panel*) object;
   SignalsPanel* this = (SignalsPanel*) object;
   Panel_done(super);
Hisham Muhammad's avatar
Hisham Muhammad committed
42
43
44
45
   free(this->signals);
   free(this);
}

46
47
void SignalsPanel_reset(SignalsPanel* this) {
   Panel* super = (Panel*) this;
Hisham Muhammad's avatar
Hisham Muhammad committed
48

49
50
   Panel_setHeader(super, "Send signal:");
   Panel_setSelected(super, 16); // 16th item is SIGTERM
Hisham Muhammad's avatar
Hisham Muhammad committed
51
52
53
   this->state = 0;
}

54
55
HandlerResult SignalsPanel_EventHandler(Panel* super, int ch) {
   SignalsPanel* this = (SignalsPanel*) super;
Hisham Muhammad's avatar
Hisham Muhammad committed
56

57
   int size = Panel_getSize(super);
Hisham Muhammad's avatar
Hisham Muhammad committed
58
59
60
61
   
   if (ch <= 255 && isdigit(ch)) {
      int signal = ch-48 + this->state;
      for (int i = 0; i < size; i++)
62
63
         if (((Signal*) Panel_get(super, i))->number == signal) {
            Panel_setSelected(super, i);
Hisham Muhammad's avatar
Hisham Muhammad committed
64
65
66
67
68
69
70
71
72
73
74
75
76
77
            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;
}