DisplayOptionsPanel.c 3.29 KB
Newer Older
Hisham Muhammad's avatar
Hisham Muhammad committed
1
2
3
4
5
6
/*
htop - DisplayOptionsPanel.c
(C) 2004-2011 Hisham H. Muhammad
Released under the GNU GPL, see the COPYING file
in the source distribution for its full text.
*/
Hisham Muhammad's avatar
Hisham Muhammad committed
7

8
#include "DisplayOptionsPanel.h"
Hisham Muhammad's avatar
Hisham Muhammad committed
9
10

#include "CheckItem.h"
Hisham Muhammad's avatar
Hisham Muhammad committed
11

Hisham Muhammad's avatar
Hisham Muhammad committed
12
#include <assert.h>
Hisham Muhammad's avatar
Hisham Muhammad committed
13
14
#include <stdlib.h>
#include <string.h>
Hisham Muhammad's avatar
Hisham Muhammad committed
15
16

/*{
Hisham Muhammad's avatar
Hisham Muhammad committed
17
18
19
#include "Panel.h"
#include "Settings.h"
#include "ScreenManager.h"
Hisham Muhammad's avatar
Hisham Muhammad committed
20

21
22
typedef struct DisplayOptionsPanel_ {
   Panel super;
Hisham Muhammad's avatar
Hisham Muhammad committed
23
24
25

   Settings* settings;
   ScreenManager* scr;
26
} DisplayOptionsPanel;
Hisham Muhammad's avatar
Hisham Muhammad committed
27
28
29

}*/

30
static void DisplayOptionsPanel_delete(Object* object) {
31
32
33
   Panel* super = (Panel*) object;
   DisplayOptionsPanel* this = (DisplayOptionsPanel*) object;
   Panel_done(super);
Hisham Muhammad's avatar
Hisham Muhammad committed
34
35
36
   free(this);
}

37
static HandlerResult DisplayOptionsPanel_eventHandler(Panel* super, int ch) {
38
   DisplayOptionsPanel* this = (DisplayOptionsPanel*) super;
Hisham Muhammad's avatar
Hisham Muhammad committed
39
40
   
   HandlerResult result = IGNORED;
41
   CheckItem* selected = (CheckItem*) Panel_getSelected(super);
Hisham Muhammad's avatar
Hisham Muhammad committed
42
43
44
45
46

   switch(ch) {
   case 0x0a:
   case 0x0d:
   case KEY_ENTER:
47
   case KEY_MOUSE:
Hisham Muhammad's avatar
Hisham Muhammad committed
48
   case ' ':
49
      CheckItem_set(selected, ! (CheckItem_get(selected)) );
Hisham Muhammad's avatar
Hisham Muhammad committed
50
51
52
53
54
55
56
      result = HANDLED;
   }

   if (result == HANDLED) {
      this->settings->changed = true;
      Header* header = this->settings->header;
      Header_calculateHeight(header);
57
      Header_reinit(header);
Hisham Muhammad's avatar
Hisham Muhammad committed
58
59
60
61
62
63
      Header_draw(header);
      ScreenManager_resize(this->scr, this->scr->x1, header->height, this->scr->x2, this->scr->y2);
   }
   return result;
}

64
65
66
67
68
69
70
71
72
73
74
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");
Hisham Muhammad's avatar
Hisham Muhammad committed
75
76
77
78
79
80
81
82
83
84
85
   Panel_add(super, (Object*) CheckItem_new(strdup("Tree view"), &(settings->pl->treeView), false));
   Panel_add(super, (Object*) CheckItem_new(strdup("Shadow other users' processes"), &(settings->pl->shadowOtherUsers), false));
   Panel_add(super, (Object*) CheckItem_new(strdup("Hide kernel threads"), &(settings->pl->hideKernelThreads), false));
   Panel_add(super, (Object*) CheckItem_new(strdup("Hide userland threads"), &(settings->pl->hideUserlandThreads), false));
   Panel_add(super, (Object*) CheckItem_new(strdup("Display threads in a different color"), &(settings->pl->highlightThreads), false));
   Panel_add(super, (Object*) CheckItem_new(strdup("Show custom thread names"), &(settings->pl->showThreadNames), false));
   Panel_add(super, (Object*) CheckItem_new(strdup("Highlight program \"basename\""), &(settings->pl->highlightBaseName), false));
   Panel_add(super, (Object*) CheckItem_new(strdup("Highlight large numbers in memory counters"), &(settings->pl->highlightMegabytes), false));
   Panel_add(super, (Object*) CheckItem_new(strdup("Leave a margin around header"), &(settings->header->margin), false));
   Panel_add(super, (Object*) CheckItem_new(strdup("Detailed CPU time (System/IO-Wait/Hard-IRQ/Soft-IRQ/Steal/Guest)"), &(settings->pl->detailedCPUTime), false));
   Panel_add(super, (Object*) CheckItem_new(strdup("Count CPUs from 0 instead of 1"), &(settings->pl->countCPUsFromZero), false));
86
87
   return this;
}