2011-12-26 21:35:57 +00:00
|
|
|
/*
|
|
|
|
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.
|
|
|
|
*/
|
2006-03-04 18:16:49 +00:00
|
|
|
|
2006-05-30 13:47:28 +00:00
|
|
|
#include "CategoriesPanel.h"
|
2011-12-26 21:35:57 +00:00
|
|
|
|
2006-05-30 13:47:28 +00:00
|
|
|
#include "AvailableMetersPanel.h"
|
|
|
|
#include "MetersPanel.h"
|
|
|
|
#include "DisplayOptionsPanel.h"
|
|
|
|
#include "ColumnsPanel.h"
|
|
|
|
#include "ColorsPanel.h"
|
|
|
|
#include "AvailableColumnsPanel.h"
|
2011-12-26 21:35:57 +00:00
|
|
|
|
2006-03-04 18:16:49 +00:00
|
|
|
#include <assert.h>
|
2011-12-26 21:35:57 +00:00
|
|
|
#include <stdlib.h>
|
2006-03-04 18:16:49 +00:00
|
|
|
|
|
|
|
/*{
|
2011-12-26 21:35:57 +00:00
|
|
|
#include "Panel.h"
|
|
|
|
#include "Settings.h"
|
|
|
|
#include "ScreenManager.h"
|
2015-01-22 01:27:31 +00:00
|
|
|
#include "ProcessList.h"
|
2006-03-04 18:16:49 +00:00
|
|
|
|
2006-05-30 13:47:28 +00:00
|
|
|
typedef struct CategoriesPanel_ {
|
|
|
|
Panel super;
|
2015-01-22 01:27:31 +00:00
|
|
|
ScreenManager* scr;
|
2006-03-04 18:16:49 +00:00
|
|
|
|
|
|
|
Settings* settings;
|
2015-01-22 01:27:31 +00:00
|
|
|
Header* header;
|
|
|
|
ProcessList* pl;
|
2006-05-30 13:47:28 +00:00
|
|
|
} CategoriesPanel;
|
2006-03-04 18:16:49 +00:00
|
|
|
|
|
|
|
}*/
|
|
|
|
|
2015-03-23 18:26:56 +00:00
|
|
|
static const char* CategoriesFunctions[] = {" ", " ", " ", " ", " ", " ", " ", " ", " ", "Done ", NULL};
|
2006-03-04 18:16:49 +00:00
|
|
|
|
2008-03-09 08:58:38 +00:00
|
|
|
static void CategoriesPanel_delete(Object* object) {
|
2006-05-30 13:47:28 +00:00
|
|
|
Panel* super = (Panel*) object;
|
|
|
|
CategoriesPanel* this = (CategoriesPanel*) object;
|
|
|
|
Panel_done(super);
|
2006-03-04 18:16:49 +00:00
|
|
|
free(this);
|
|
|
|
}
|
|
|
|
|
2008-03-09 08:58:38 +00:00
|
|
|
void CategoriesPanel_makeMetersPage(CategoriesPanel* this) {
|
2015-02-03 21:32:07 +00:00
|
|
|
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);
|
2015-03-23 18:26:56 +00:00
|
|
|
ScreenManager_add(this->scr, (Panel*) leftMeters, 20);
|
|
|
|
ScreenManager_add(this->scr, (Panel*) rightMeters, 20);
|
|
|
|
ScreenManager_add(this->scr, availableMeters, -1);
|
2008-03-09 08:58:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void CategoriesPanel_makeDisplayOptionsPage(CategoriesPanel* this) {
|
|
|
|
Panel* displayOptions = (Panel*) DisplayOptionsPanel_new(this->settings, this->scr);
|
2015-03-23 18:26:56 +00:00
|
|
|
ScreenManager_add(this->scr, displayOptions, -1);
|
2008-03-09 08:58:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void CategoriesPanel_makeColorsPage(CategoriesPanel* this) {
|
|
|
|
Panel* colors = (Panel*) ColorsPanel_new(this->settings, this->scr);
|
2015-03-23 18:26:56 +00:00
|
|
|
ScreenManager_add(this->scr, colors, -1);
|
2008-03-09 08:58:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void CategoriesPanel_makeColumnsPage(CategoriesPanel* this) {
|
2015-01-22 01:27:31 +00:00
|
|
|
Panel* columns = (Panel*) ColumnsPanel_new(this->settings);
|
|
|
|
Panel* availableColumns = (Panel*) AvailableColumnsPanel_new(columns);
|
2015-03-23 18:26:56 +00:00
|
|
|
ScreenManager_add(this->scr, columns, 20);
|
|
|
|
ScreenManager_add(this->scr, availableColumns, -1);
|
2008-03-09 08:58:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static HandlerResult CategoriesPanel_eventHandler(Panel* super, int ch) {
|
2006-05-30 13:47:28 +00:00
|
|
|
CategoriesPanel* this = (CategoriesPanel*) super;
|
2006-03-04 18:16:49 +00:00
|
|
|
|
|
|
|
HandlerResult result = IGNORED;
|
|
|
|
|
2008-03-05 06:54:30 +00:00
|
|
|
int selected = Panel_getSelectedIndex(super);
|
2006-03-04 18:16:49 +00:00
|
|
|
switch (ch) {
|
2015-03-25 02:12:43 +00:00
|
|
|
case EVENT_SET_SELECTED:
|
2008-03-05 06:54:30 +00:00
|
|
|
result = HANDLED;
|
|
|
|
break;
|
2006-03-04 18:16:49 +00:00
|
|
|
case KEY_UP:
|
2016-06-15 15:45:23 +00:00
|
|
|
case KEY_CTRL('P'):
|
2006-03-04 18:16:49 +00:00
|
|
|
case KEY_DOWN:
|
2016-06-15 15:45:23 +00:00
|
|
|
case KEY_CTRL('N'):
|
2006-03-04 18:16:49 +00:00
|
|
|
case KEY_NPAGE:
|
|
|
|
case KEY_PPAGE:
|
|
|
|
case KEY_HOME:
|
|
|
|
case KEY_END: {
|
2008-03-05 06:54:30 +00:00
|
|
|
int previous = selected;
|
2006-05-30 13:47:28 +00:00
|
|
|
Panel_onKey(super, ch);
|
2008-03-05 06:54:30 +00:00
|
|
|
selected = Panel_getSelectedIndex(super);
|
|
|
|
if (previous != selected)
|
|
|
|
result = HANDLED;
|
|
|
|
break;
|
|
|
|
}
|
2012-11-10 00:31:37 +00:00
|
|
|
default:
|
2015-03-23 01:56:28 +00:00
|
|
|
if (ch < 255 && isalpha(ch))
|
2012-11-10 00:31:37 +00:00
|
|
|
result = Panel_selectByTyping(super, ch);
|
|
|
|
if (result == BREAK_LOOP)
|
|
|
|
result = IGNORED;
|
|
|
|
break;
|
2008-03-05 06:54:30 +00:00
|
|
|
}
|
|
|
|
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;
|
2006-03-04 18:16:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2012-12-05 15:12:20 +00:00
|
|
|
PanelClass CategoriesPanel_class = {
|
|
|
|
.super = {
|
|
|
|
.extends = Class(Panel),
|
|
|
|
.delete = CategoriesPanel_delete
|
|
|
|
},
|
|
|
|
.eventHandler = CategoriesPanel_eventHandler
|
|
|
|
};
|
|
|
|
|
2015-01-22 01:27:31 +00:00
|
|
|
CategoriesPanel* CategoriesPanel_new(ScreenManager* scr, Settings* settings, Header* header, ProcessList* pl) {
|
2012-12-05 15:12:20 +00:00
|
|
|
CategoriesPanel* this = AllocThis(CategoriesPanel);
|
2008-03-09 08:58:38 +00:00
|
|
|
Panel* super = (Panel*) this;
|
2015-03-23 18:26:56 +00:00
|
|
|
FunctionBar* fuBar = FunctionBar_new(CategoriesFunctions, NULL, NULL);
|
|
|
|
Panel_init(super, 1, 1, 1, 1, Class(ListItem), true, fuBar);
|
2006-03-04 18:16:49 +00:00
|
|
|
|
2008-03-09 08:58:38 +00:00
|
|
|
this->scr = scr;
|
2015-01-22 01:27:31 +00:00
|
|
|
this->settings = settings;
|
|
|
|
this->header = header;
|
|
|
|
this->pl = pl;
|
2008-03-09 08:58:38 +00:00
|
|
|
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;
|
2006-03-04 18:16:49 +00:00
|
|
|
}
|