DisplayOptionsPanel.c 2.63 KB
Newer Older
Hisham Muhammad's avatar
Hisham Muhammad committed
1

2
#include "DisplayOptionsPanel.h"
Hisham Muhammad's avatar
Hisham Muhammad committed
3

4
#include "Panel.h"
Hisham Muhammad's avatar
Hisham Muhammad committed
5
6
7
8
9
10
11
12
13
#include "CheckItem.h"
#include "Settings.h"
#include "ScreenManager.h"

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

/*{

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

   Settings* settings;
   ScreenManager* scr;
19
} DisplayOptionsPanel;
Hisham Muhammad's avatar
Hisham Muhammad committed
20
21
22

}*/

23
24
25
26
27
DisplayOptionsPanel* DisplayOptionsPanel_new(Settings* settings, ScreenManager* scr) {
   DisplayOptionsPanel* this = (DisplayOptionsPanel*) malloc(sizeof(DisplayOptionsPanel));
   Panel* super = (Panel*) this;
   Panel_init(super, 1, 1, 1, 1, CHECKITEM_CLASS, true);
   ((Object*)this)->delete = DisplayOptionsPanel_delete;
Hisham Muhammad's avatar
Hisham Muhammad committed
28
29
30

   this->settings = settings;
   this->scr = scr;
31
   super->eventHandler = DisplayOptionsPanel_EventHandler;
Hisham Muhammad's avatar
Hisham Muhammad committed
32

33
34
35
36
37
38
39
40
   Panel_setHeader(super, "Display options");
   Panel_add(super, (Object*) CheckItem_new(String_copy("Tree view"), &(settings->pl->treeView)));
   Panel_add(super, (Object*) CheckItem_new(String_copy("Shadow other users' processes"), &(settings->pl->shadowOtherUsers)));
   Panel_add(super, (Object*) CheckItem_new(String_copy("Hide kernel threads"), &(settings->pl->hideKernelThreads)));
   Panel_add(super, (Object*) CheckItem_new(String_copy("Hide userland threads"), &(settings->pl->hideUserlandThreads)));
   Panel_add(super, (Object*) CheckItem_new(String_copy("Highlight program \"basename\""), &(settings->pl->highlightBaseName)));
   Panel_add(super, (Object*) CheckItem_new(String_copy("Highlight megabytes in memory counters"), &(settings->pl->highlightMegabytes)));
   Panel_add(super, (Object*) CheckItem_new(String_copy("Leave a margin around header"), &(settings->header->margin)));
41
   Panel_add(super, (Object*) CheckItem_new(String_copy("Split System Time into System/IO-Wait/Hard-IRQ/Soft-IRQ"), &(settings->pl->expandSystemTime)));
Hisham Muhammad's avatar
Hisham Muhammad committed
42
43
44
   return this;
}

45
46
47
48
void DisplayOptionsPanel_delete(Object* object) {
   Panel* super = (Panel*) object;
   DisplayOptionsPanel* this = (DisplayOptionsPanel*) object;
   Panel_done(super);
Hisham Muhammad's avatar
Hisham Muhammad committed
49
50
51
   free(this);
}

52
53
HandlerResult DisplayOptionsPanel_EventHandler(Panel* super, int ch) {
   DisplayOptionsPanel* this = (DisplayOptionsPanel*) super;
Hisham Muhammad's avatar
Hisham Muhammad committed
54
55
   
   HandlerResult result = IGNORED;
56
   CheckItem* selected = (CheckItem*) Panel_getSelected(super);
Hisham Muhammad's avatar
Hisham Muhammad committed
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76

   switch(ch) {
   case 0x0a:
   case 0x0d:
   case KEY_ENTER:
   case ' ':
      *(selected->value) = ! *(selected->value);
      result = HANDLED;
   }

   if (result == HANDLED) {
      this->settings->changed = true;
      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;
}