DisplayOptionsPanel.c 3.16 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
static void DisplayOptionsPanel_delete(Object* object) {
24
25
26
   Panel* super = (Panel*) object;
   DisplayOptionsPanel* this = (DisplayOptionsPanel*) object;
   Panel_done(super);
Hisham Muhammad's avatar
Hisham Muhammad committed
27
28
29
   free(this);
}

30
static HandlerResult DisplayOptionsPanel_eventHandler(Panel* super, int ch) {
31
   DisplayOptionsPanel* this = (DisplayOptionsPanel*) super;
Hisham Muhammad's avatar
Hisham Muhammad committed
32
33
   
   HandlerResult result = IGNORED;
34
   CheckItem* selected = (CheckItem*) Panel_getSelected(super);
Hisham Muhammad's avatar
Hisham Muhammad committed
35
36
37
38
39

   switch(ch) {
   case 0x0a:
   case 0x0d:
   case KEY_ENTER:
40
   case KEY_MOUSE:
Hisham Muhammad's avatar
Hisham Muhammad committed
41
   case ' ':
42
      CheckItem_set(selected, ! (CheckItem_get(selected)) );
Hisham Muhammad's avatar
Hisham Muhammad committed
43
44
45
46
47
48
49
      result = HANDLED;
   }

   if (result == HANDLED) {
      this->settings->changed = true;
      Header* header = this->settings->header;
      Header_calculateHeight(header);
50
      Header_reinit(header);
Hisham Muhammad's avatar
Hisham Muhammad committed
51
52
53
54
55
56
      Header_draw(header);
      ScreenManager_resize(this->scr, this->scr->x1, header->height, this->scr->x2, this->scr->y2);
   }
   return result;
}

57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
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;

   this->settings = settings;
   this->scr = scr;
   super->eventHandler = DisplayOptionsPanel_eventHandler;

   Panel_setHeader(super, "Display options");
   Panel_add(super, (Object*) CheckItem_new(String_copy("Tree view"), &(settings->pl->treeView), false));
   Panel_add(super, (Object*) CheckItem_new(String_copy("Shadow other users' processes"), &(settings->pl->shadowOtherUsers), false));
   Panel_add(super, (Object*) CheckItem_new(String_copy("Hide kernel threads"), &(settings->pl->hideKernelThreads), false));
   Panel_add(super, (Object*) CheckItem_new(String_copy("Hide userland threads"), &(settings->pl->hideUserlandThreads), false));
   Panel_add(super, (Object*) CheckItem_new(String_copy("Display threads in a different color"), &(settings->pl->highlightThreads), false));
Hisham Muhammad's avatar
Hisham Muhammad committed
73
   Panel_add(super, (Object*) CheckItem_new(String_copy("Show custom thread names"), &(settings->pl->showThreadNames), false));
74
   Panel_add(super, (Object*) CheckItem_new(String_copy("Highlight program \"basename\""), &(settings->pl->highlightBaseName), false));
75
   Panel_add(super, (Object*) CheckItem_new(String_copy("Highlight large numbers in memory counters"), &(settings->pl->highlightMegabytes), false));
76
   Panel_add(super, (Object*) CheckItem_new(String_copy("Leave a margin around header"), &(settings->header->margin), false));
77
   Panel_add(super, (Object*) CheckItem_new(String_copy("Detailed CPU time (System/IO-Wait/Hard-IRQ/Soft-IRQ/Steal/Guest)"), &(settings->pl->detailedCPUTime), false));
78
   Panel_add(super, (Object*) CheckItem_new(String_copy("Count CPUs from 0 instead of 1"), &(settings->pl->countCPUsFromZero), false));
79
80
   return this;
}