aboutsummaryrefslogtreecommitdiffstats
path: root/DisplayOptionsListBox.c
blob: 37541f2339743f75090d75449aa6beaf37da7155 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74

#include "DisplayOptionsListBox.h"

#include "ListBox.h"
#include "CheckItem.h"
#include "Settings.h"
#include "ScreenManager.h"

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

/*{

typedef struct DisplayOptionsListBox_ {
   ListBox super;

   Settings* settings;
   ScreenManager* scr;
} DisplayOptionsListBox;

}*/

DisplayOptionsListBox* DisplayOptionsListBox_new(Settings* settings, ScreenManager* scr) {
   DisplayOptionsListBox* this = (DisplayOptionsListBox*) malloc(sizeof(DisplayOptionsListBox));
   ListBox* super = (ListBox*) this;
   ListBox_init(super, 1, 1, 1, 1, CHECKITEM_CLASS, true);
   ((Object*)this)->delete = DisplayOptionsListBox_delete;

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

   ListBox_setHeader(super, RichString_quickString(CRT_colors[PANEL_HEADER_FOCUS], "Display options"));
   ListBox_add(super, (Object*) CheckItem_new(String_copy("Tree view"), &(settings->pl->treeView)));
   ListBox_add(super, (Object*) CheckItem_new(String_copy("Shadow other users' processes"), &(settings->pl->shadowOtherUsers)));
   ListBox_add(super, (Object*) CheckItem_new(String_copy("Hide kernel threads"), &(settings->pl->hideKernelThreads)));
   ListBox_add(super, (Object*) CheckItem_new(String_copy("Hide userland threads"), &(settings->pl->hideUserlandThreads)));
   ListBox_add(super, (Object*) CheckItem_new(String_copy("Highlight program \"basename\""), &(settings->pl->highlightBaseName)));
   ListBox_add(super, (Object*) CheckItem_new(String_copy("Highlight megabytes in memory counters"), &(settings->pl->highlightMegabytes)));
   ListBox_add(super, (Object*) CheckItem_new(String_copy("Leave a margin around header"), &(settings->header->margin)));
   return this;
}

void DisplayOptionsListBox_delete(Object* object) {
   ListBox* super = (ListBox*) object;
   DisplayOptionsListBox* this = (DisplayOptionsListBox*) object;
   ListBox_done(super);
   free(this);
}

HandlerResult DisplayOptionsListBox_eventHandler(ListBox* super, int ch) {
   DisplayOptionsListBox* this = (DisplayOptionsListBox*) super;
   
   HandlerResult result = IGNORED;
   CheckItem* selected = (CheckItem*) ListBox_getSelected(super);

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

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

© 2014-2024 Faster IT GmbH | imprint | privacy policy