CategoriesPanel.c 5.55 KB
Newer Older
Hisham Muhammad's avatar
Hisham Muhammad committed
1
2
3
4
5
6
/*
htop - CategoriesPanel.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 "CategoriesPanel.h"
Hisham Muhammad's avatar
Hisham Muhammad committed
9

10
11
12
13
14
15
#include "AvailableMetersPanel.h"
#include "MetersPanel.h"
#include "DisplayOptionsPanel.h"
#include "ColumnsPanel.h"
#include "ColorsPanel.h"
#include "AvailableColumnsPanel.h"
Hisham Muhammad's avatar
Hisham Muhammad committed
16

Hisham Muhammad's avatar
Hisham Muhammad committed
17
#include <assert.h>
Hisham Muhammad's avatar
Hisham Muhammad committed
18
#include <stdlib.h>
Hisham Muhammad's avatar
Hisham Muhammad committed
19
20

/*{
Hisham Muhammad's avatar
Hisham Muhammad committed
21
22
23
#include "Panel.h"
#include "Settings.h"
#include "ScreenManager.h"
Hisham Muhammad's avatar
Hisham Muhammad committed
24
#include "ProcessList.h"
Hisham Muhammad's avatar
Hisham Muhammad committed
25

26
27
typedef struct CategoriesPanel_ {
   Panel super;
Hisham Muhammad's avatar
Hisham Muhammad committed
28
   ScreenManager* scr;
Hisham Muhammad's avatar
Hisham Muhammad committed
29
30

   Settings* settings;
Hisham Muhammad's avatar
Hisham Muhammad committed
31
32
   Header* header;
   ProcessList* pl;
33
} CategoriesPanel;
Hisham Muhammad's avatar
Hisham Muhammad committed
34
35
36

}*/

Hisham Muhammad's avatar
Hisham Muhammad committed
37
static const char* MetersFunctions[] = {"      ", "      ", "      ", "Type  ", "      ", "      ", "MoveUp", "MoveDn", "Remove", "Done  ", NULL};
Hisham Muhammad's avatar
Hisham Muhammad committed
38

Hisham Muhammad's avatar
Hisham Muhammad committed
39
static const char* AvailableMetersFunctions[] = {"      ", "      ", "      ", "      ", "Add L ", "Add R ", "      ", "      ", "      ", "Done  ", NULL};
Hisham Muhammad's avatar
Hisham Muhammad committed
40

Hisham Muhammad's avatar
Hisham Muhammad committed
41
static const char* DisplayOptionsFunctions[] = {"      ", "      ", "      ", "      ", "      ", "      ", "      ", "      ", "      ", "Done  ", NULL};
Hisham Muhammad's avatar
Hisham Muhammad committed
42

Hisham Muhammad's avatar
Hisham Muhammad committed
43
static const char* ColumnsFunctions[] = {"      ", "      ", "      ", "      ", "      ", "      ", "MoveUp", "MoveDn", "Remove", "Done  ", NULL};
Hisham Muhammad's avatar
Hisham Muhammad committed
44

Hisham Muhammad's avatar
Hisham Muhammad committed
45
static const char* ColorsFunctions[] = {"      ", "      ", "      ", "      ", "      ", "      ", "      ", "      ", "      ", "Done  ", NULL};
Hisham Muhammad's avatar
Hisham Muhammad committed
46

Hisham Muhammad's avatar
Hisham Muhammad committed
47
static const char* AvailableColumnsFunctions[] = {"      ", "      ", "      ", "      ", "Add   ", "      ", "      ", "      ", "      ", "Done  ", NULL};
Hisham Muhammad's avatar
Hisham Muhammad committed
48

49
static void CategoriesPanel_delete(Object* object) {
50
51
52
   Panel* super = (Panel*) object;
   CategoriesPanel* this = (CategoriesPanel*) object;
   Panel_done(super);
Hisham Muhammad's avatar
Hisham Muhammad committed
53
54
55
   free(this);
}

56
void CategoriesPanel_makeMetersPage(CategoriesPanel* this) {
Hisham Muhammad's avatar
Hisham Muhammad committed
57
58
59
   Panel* leftMeters = (Panel*) MetersPanel_new(this->settings, "Left column", this->header->columns[0], this->scr);
   Panel* rightMeters = (Panel*) MetersPanel_new(this->settings, "Right column", this->header->columns[1], this->scr);
   Panel* availableMeters = (Panel*) AvailableMetersPanel_new(this->settings, this->header, leftMeters, rightMeters, this->scr, this->pl);
Hisham Muhammad's avatar
Hisham Muhammad committed
60
61
62
   ScreenManager_add(this->scr, leftMeters, FunctionBar_new(MetersFunctions, NULL, NULL), 20);
   ScreenManager_add(this->scr, rightMeters, FunctionBar_new(MetersFunctions, NULL, NULL), 20);
   ScreenManager_add(this->scr, availableMeters, FunctionBar_new(AvailableMetersFunctions, NULL, NULL), -1);
63
64
65
66
}

static void CategoriesPanel_makeDisplayOptionsPage(CategoriesPanel* this) {
   Panel* displayOptions = (Panel*) DisplayOptionsPanel_new(this->settings, this->scr);
Hisham Muhammad's avatar
Hisham Muhammad committed
67
   ScreenManager_add(this->scr, displayOptions, FunctionBar_new(DisplayOptionsFunctions, NULL, NULL), -1);
68
69
70
71
}

static void CategoriesPanel_makeColorsPage(CategoriesPanel* this) {
   Panel* colors = (Panel*) ColorsPanel_new(this->settings, this->scr);
Hisham Muhammad's avatar
Hisham Muhammad committed
72
   ScreenManager_add(this->scr, colors, FunctionBar_new(ColorsFunctions, NULL, NULL), -1);
73
74
75
}

static void CategoriesPanel_makeColumnsPage(CategoriesPanel* this) {
Hisham Muhammad's avatar
Hisham Muhammad committed
76
77
   Panel* columns = (Panel*) ColumnsPanel_new(this->settings);
   Panel* availableColumns = (Panel*) AvailableColumnsPanel_new(columns);
Hisham Muhammad's avatar
Hisham Muhammad committed
78
79
   ScreenManager_add(this->scr, columns, FunctionBar_new(ColumnsFunctions, NULL, NULL), 20);
   ScreenManager_add(this->scr, availableColumns, FunctionBar_new(AvailableColumnsFunctions, NULL, NULL), -1);
80
81
82
}

static HandlerResult CategoriesPanel_eventHandler(Panel* super, int ch) {
83
   CategoriesPanel* this = (CategoriesPanel*) super;
Hisham Muhammad's avatar
Hisham Muhammad committed
84
85
86

   HandlerResult result = IGNORED;

87
   int selected = Panel_getSelectedIndex(super);
Hisham Muhammad's avatar
Hisham Muhammad committed
88
   switch (ch) {
89
90
91
      case EVENT_SETSELECTED:
         result = HANDLED;
         break;
Hisham Muhammad's avatar
Hisham Muhammad committed
92
      case KEY_UP:
93
      case KEY_CTRLP:
Hisham Muhammad's avatar
Hisham Muhammad committed
94
      case KEY_DOWN:
95
      case KEY_CTRLN:
Hisham Muhammad's avatar
Hisham Muhammad committed
96
97
98
99
      case KEY_NPAGE:
      case KEY_PPAGE:
      case KEY_HOME:
      case KEY_END: {
100
         int previous = selected;
101
         Panel_onKey(super, ch);
102
103
104
105
106
         selected = Panel_getSelectedIndex(super);
         if (previous != selected)
            result = HANDLED;
         break;
      }
107
108
109
110
111
112
      default:
         if (isalpha(ch))
            result = Panel_selectByTyping(super, ch);
         if (result == BREAK_LOOP)
            result = IGNORED;
         break;
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
   }
   if (result == HANDLED) {
      int size = ScreenManager_size(this->scr);
      for (int i = 1; i < size; i++)
         ScreenManager_remove(this->scr, 1);
      switch (selected) {
         case 0:
            CategoriesPanel_makeMetersPage(this);
            break;
         case 1:
            CategoriesPanel_makeDisplayOptionsPage(this);
            break;
         case 2:
            CategoriesPanel_makeColorsPage(this);
            break;
         case 3:
            CategoriesPanel_makeColumnsPage(this);
            break;
Hisham Muhammad's avatar
Hisham Muhammad committed
131
132
133
134
135
      }
   }
   return result;
}

136
137
138
139
140
141
142
143
PanelClass CategoriesPanel_class = {
   .super = {
      .extends = Class(Panel),
      .delete = CategoriesPanel_delete
   },
   .eventHandler = CategoriesPanel_eventHandler
};

Hisham Muhammad's avatar
Hisham Muhammad committed
144
CategoriesPanel* CategoriesPanel_new(ScreenManager* scr, Settings* settings, Header* header, ProcessList* pl) {
145
   CategoriesPanel* this = AllocThis(CategoriesPanel);
146
   Panel* super = (Panel*) this;
147
   Panel_init(super, 1, 1, 1, 1, Class(ListItem), true);
Hisham Muhammad's avatar
Hisham Muhammad committed
148

149
   this->scr = scr;
Hisham Muhammad's avatar
Hisham Muhammad committed
150
151
152
   this->settings = settings;
   this->header = header;
   this->pl = pl;
153
154
155
156
157
158
   Panel_setHeader(super, "Setup");
   Panel_add(super, (Object*) ListItem_new("Meters", 0));
   Panel_add(super, (Object*) ListItem_new("Display options", 0));
   Panel_add(super, (Object*) ListItem_new("Colors", 0));
   Panel_add(super, (Object*) ListItem_new("Columns", 0));
   return this;
Hisham Muhammad's avatar
Hisham Muhammad committed
159
}