CategoriesPanel.c 4.82 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
#include "AvailableMetersPanel.h"
#include "MetersPanel.h"
#include "DisplayOptionsPanel.h"
#include "ColumnsPanel.h"
14
#include "ScreensPanel.h"
15
16
#include "ColorsPanel.h"
#include "AvailableColumnsPanel.h"
Hisham Muhammad's avatar
Hisham Muhammad committed
17

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

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

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

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

}*/

Richard's avatar
Richard committed
38
static const char* const CategoriesFunctions[] = {"      ", "      ", "      ", "      ", "      ", "      ", "      ", "      ", "      ", "Done  ", NULL};
Hisham Muhammad's avatar
Hisham Muhammad committed
39

40
static void CategoriesPanel_delete(Object* object) {
41
42
43
   Panel* super = (Panel*) object;
   CategoriesPanel* this = (CategoriesPanel*) object;
   Panel_done(super);
Hisham Muhammad's avatar
Hisham Muhammad committed
44
45
46
   free(this);
}

47
void CategoriesPanel_makeMetersPage(CategoriesPanel* this) {
48
49
50
51
52
   MetersPanel* leftMeters = MetersPanel_new(this->settings, "Left column", this->header->columns[0], this->scr);
   MetersPanel* rightMeters = MetersPanel_new(this->settings, "Right column", this->header->columns[1], this->scr);
   leftMeters->rightNeighbor = rightMeters;
   rightMeters->leftNeighbor = leftMeters;
   Panel* availableMeters = (Panel*) AvailableMetersPanel_new(this->settings, this->header, (Panel*) leftMeters, (Panel*) rightMeters, this->scr, this->pl);
53
54
55
   ScreenManager_add(this->scr, (Panel*) leftMeters, 20);
   ScreenManager_add(this->scr, (Panel*) rightMeters, 20);
   ScreenManager_add(this->scr, availableMeters, -1);
56
57
58
59
}

static void CategoriesPanel_makeDisplayOptionsPage(CategoriesPanel* this) {
   Panel* displayOptions = (Panel*) DisplayOptionsPanel_new(this->settings, this->scr);
60
   ScreenManager_add(this->scr, displayOptions, -1);
61
62
63
64
}

static void CategoriesPanel_makeColorsPage(CategoriesPanel* this) {
   Panel* colors = (Panel*) ColorsPanel_new(this->settings, this->scr);
65
   ScreenManager_add(this->scr, colors, -1);
66
67
}

68
69
static void CategoriesPanel_makeScreensPage(CategoriesPanel* this) {
   Panel* screens = (Panel*) ScreensPanel_new(this->settings);
Hisham Muhammad's avatar
Hisham Muhammad committed
70
71
   Panel* columns = (Panel*) ColumnsPanel_new(this->settings);
   Panel* availableColumns = (Panel*) AvailableColumnsPanel_new(columns);
72
   ScreenManager_add(this->scr, screens, 20);
73
74
   ScreenManager_add(this->scr, columns, 20);
   ScreenManager_add(this->scr, availableColumns, -1);
75
76
77
}

static HandlerResult CategoriesPanel_eventHandler(Panel* super, int ch) {
78
   CategoriesPanel* this = (CategoriesPanel*) super;
Hisham Muhammad's avatar
Hisham Muhammad committed
79
80
81

   HandlerResult result = IGNORED;

82
   int selected = Panel_getSelectedIndex(super);
Hisham Muhammad's avatar
Hisham Muhammad committed
83
   switch (ch) {
84
      case EVENT_SET_SELECTED:
85
86
         result = HANDLED;
         break;
Hisham Muhammad's avatar
Hisham Muhammad committed
87
      case KEY_UP:
88
      case KEY_CTRL('P'):
Hisham Muhammad's avatar
Hisham Muhammad committed
89
      case KEY_DOWN:
90
      case KEY_CTRL('N'):
Hisham Muhammad's avatar
Hisham Muhammad committed
91
92
93
94
      case KEY_NPAGE:
      case KEY_PPAGE:
      case KEY_HOME:
      case KEY_END: {
95
         int previous = selected;
96
         Panel_onKey(super, ch);
97
98
99
100
101
         selected = Panel_getSelectedIndex(super);
         if (previous != selected)
            result = HANDLED;
         break;
      }
102
      default:
103
         if (ch < 255 && isalpha(ch))
104
105
106
107
            result = Panel_selectByTyping(super, ch);
         if (result == BREAK_LOOP)
            result = IGNORED;
         break;
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
   }
   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:
124
            CategoriesPanel_makeScreensPage(this);
125
            break;
Hisham Muhammad's avatar
Hisham Muhammad committed
126
127
128
129
130
      }
   }
   return result;
}

131
132
133
134
135
136
137
138
PanelClass CategoriesPanel_class = {
   .super = {
      .extends = Class(Panel),
      .delete = CategoriesPanel_delete
   },
   .eventHandler = CategoriesPanel_eventHandler
};

Hisham Muhammad's avatar
Hisham Muhammad committed
139
CategoriesPanel* CategoriesPanel_new(ScreenManager* scr, Settings* settings, Header* header, ProcessList* pl) {
140
   CategoriesPanel* this = AllocThis(CategoriesPanel);
141
   Panel* super = (Panel*) this;
142
143
   FunctionBar* fuBar = FunctionBar_new(CategoriesFunctions, NULL, NULL);
   Panel_init(super, 1, 1, 1, 1, Class(ListItem), true, fuBar);
Hisham Muhammad's avatar
Hisham Muhammad committed
144

145
   this->scr = scr;
Hisham Muhammad's avatar
Hisham Muhammad committed
146
147
148
   this->settings = settings;
   this->header = header;
   this->pl = pl;
149
150
151
152
   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));
153
   Panel_add(super, (Object*) ListItem_new("Screens", 0));
154
   return this;
Hisham Muhammad's avatar
Hisham Muhammad committed
155
}