~ubuntu-branches/ubuntu/hoary/htop/hoary

« back to all changes in this revision

Viewing changes to SignalsListBox.c

  • Committer: Bazaar Package Importer
  • Author(s): Bartosz Fenski
  • Date: 2004-11-27 10:10:17 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20041127101017-vwknw2ipfvxchno4
Tags: 0.5-1
* New upstream version.
  - fixes problem with wrongly displayed CPU bar (Closes: #283212)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
#include "SignalsListBox.h"
 
3
#include "ListBox.h"
 
4
#include "Signal.h"
 
5
#include "RichString.h"
 
6
 
 
7
#include "debug.h"
 
8
#include <assert.h>
 
9
 
 
10
#include <ctype.h>
 
11
 
 
12
/*{
 
13
 
 
14
typedef struct SignalsListBox_ {
 
15
   ListBox super;
 
16
 
 
17
   int state;
 
18
   Signal** signals;
 
19
} SignalsListBox;
 
20
 
 
21
}*/
 
22
 
 
23
SignalsListBox* SignalsListBox_new(int x, int y, int w, int h) {
 
24
   SignalsListBox* this = (SignalsListBox*) malloc(sizeof(SignalsListBox));
 
25
   ListBox* super = (ListBox*) this;
 
26
   ListBox_init(super, x, y, w, h, SIGNAL_CLASS, true);
 
27
   ((Object*)this)->delete = SignalsListBox_delete;
 
28
 
 
29
   this->signals = Signal_getSignalTable();
 
30
   super->eventHandler = SignalsListBox_eventHandler;
 
31
   int sigCount = Signal_getSignalCount();
 
32
   for(int i = 0; i < sigCount; i++)
 
33
      ListBox_set(super, i, (Object*) this->signals[i]);
 
34
   SignalsListBox_reset(this);
 
35
   return this;
 
36
}
 
37
 
 
38
void SignalsListBox_delete(Object* object) {
 
39
   ListBox* super = (ListBox*) object;
 
40
   SignalsListBox* this = (SignalsListBox*) object;
 
41
   ListBox_done(super);
 
42
   free(this->signals);
 
43
   free(this);
 
44
}
 
45
 
 
46
void SignalsListBox_reset(SignalsListBox* this) {
 
47
   ListBox* super = (ListBox*) this;
 
48
 
 
49
   ListBox_setHeader(super, RichString_quickString(CRT_colors[PANEL_HEADER_FOCUS], "Send signal:"));
 
50
   ListBox_setSelected(super, 16); // 16th item is SIGTERM
 
51
   this->state = 0;
 
52
}
 
53
 
 
54
HandlerResult SignalsListBox_eventHandler(ListBox* super, int ch) {
 
55
   SignalsListBox* this = (SignalsListBox*) super;
 
56
 
 
57
   int size = ListBox_getSize(super);
 
58
   if (isdigit(ch)) {
 
59
      int signal = ch-48 + this->state;
 
60
      for (int i = 0; i < size; i++)
 
61
         if (((Signal*) ListBox_get(super, i))->number == signal) {
 
62
            ListBox_setSelected(super, i);
 
63
            break;
 
64
         }
 
65
      this->state = signal * 10;
 
66
      if (this->state > 100)
 
67
         this->state = 0;
 
68
      return HANDLED;
 
69
   } else {
 
70
      this->state = 0;
 
71
   }
 
72
   if (ch == 13) {
 
73
      return BREAK_LOOP;
 
74
   }
 
75
   return IGNORED;
 
76
}