Rename ListBox to Panel, matching dit.

This commit is contained in:
Hisham Muhammad 2006-05-30 13:47:28 +00:00
parent a853faaa2d
commit c2cdcd0c1d
27 changed files with 579 additions and 579 deletions

View File

@ -1,57 +1,57 @@
#include "AvailableColumnsListBox.h" #include "AvailableColumnsPanel.h"
#include "Settings.h" #include "Settings.h"
#include "Header.h" #include "Header.h"
#include "ScreenManager.h" #include "ScreenManager.h"
#include "ColumnsListBox.h" #include "ColumnsPanel.h"
#include "ListBox.h" #include "Panel.h"
#include "debug.h" #include "debug.h"
#include <assert.h> #include <assert.h>
/*{ /*{
typedef struct AvailableColumnsListBox_ { typedef struct AvailableColumnsPanel_ {
ListBox super; Panel super;
ListBox* columns; Panel* columns;
Settings* settings; Settings* settings;
ScreenManager* scr; ScreenManager* scr;
} AvailableColumnsListBox; } AvailableColumnsPanel;
}*/ }*/
AvailableColumnsListBox* AvailableColumnsListBox_new(Settings* settings, ListBox* columns, ScreenManager* scr) { AvailableColumnsPanel* AvailableColumnsPanel_new(Settings* settings, Panel* columns, ScreenManager* scr) {
AvailableColumnsListBox* this = (AvailableColumnsListBox*) malloc(sizeof(AvailableColumnsListBox)); AvailableColumnsPanel* this = (AvailableColumnsPanel*) malloc(sizeof(AvailableColumnsPanel));
ListBox* super = (ListBox*) this; Panel* super = (Panel*) this;
ListBox_init(super, 1, 1, 1, 1, LISTITEM_CLASS, true); Panel_init(super, 1, 1, 1, 1, LISTITEM_CLASS, true);
((Object*)this)->delete = AvailableColumnsListBox_delete; ((Object*)this)->delete = AvailableColumnsPanel_delete;
this->settings = settings; this->settings = settings;
this->scr = scr; this->scr = scr;
super->eventHandler = AvailableColumnsListBox_eventHandler; super->eventHandler = AvailableColumnsPanel_eventHandler;
ListBox_setHeader(super, "Available Columns"); Panel_setHeader(super, "Available Columns");
for (int i = 1; i < LAST_PROCESSFIELD; i++) { for (int i = 1; i < LAST_PROCESSFIELD; i++) {
if (i != COMM) if (i != COMM)
ListBox_add(super, (Object*) ListItem_new(Process_fieldNames[i], 0)); Panel_add(super, (Object*) ListItem_new(Process_fieldNames[i], 0));
} }
this->columns = columns; this->columns = columns;
return this; return this;
} }
void AvailableColumnsListBox_delete(Object* object) { void AvailableColumnsPanel_delete(Object* object) {
ListBox* super = (ListBox*) object; Panel* super = (Panel*) object;
AvailableColumnsListBox* this = (AvailableColumnsListBox*) object; AvailableColumnsPanel* this = (AvailableColumnsPanel*) object;
ListBox_done(super); Panel_done(super);
free(this); free(this);
} }
HandlerResult AvailableColumnsListBox_eventHandler(ListBox* super, int ch) { HandlerResult AvailableColumnsPanel_eventHandler(Panel* super, int ch) {
AvailableColumnsListBox* this = (AvailableColumnsListBox*) super; AvailableColumnsPanel* this = (AvailableColumnsPanel*) super;
char* text = ((ListItem*) ListBox_getSelected(super))->value; char* text = ((ListItem*) Panel_getSelected(super))->value;
HandlerResult result = IGNORED; HandlerResult result = IGNORED;
switch(ch) { switch(ch) {
@ -59,11 +59,11 @@ HandlerResult AvailableColumnsListBox_eventHandler(ListBox* super, int ch) {
case KEY_ENTER: case KEY_ENTER:
case KEY_F(5): case KEY_F(5):
{ {
int at = ListBox_getSelectedIndex(this->columns) + 1; int at = Panel_getSelectedIndex(this->columns) + 1;
if (at == ListBox_getSize(this->columns)) if (at == Panel_getSize(this->columns))
at--; at--;
ListBox_insert(this->columns, at, (Object*) ListItem_new(text, 0)); Panel_insert(this->columns, at, (Object*) ListItem_new(text, 0));
ColumnsListBox_update(this->columns); ColumnsPanel_update(this->columns);
result = HANDLED; result = HANDLED;
break; break;
} }

View File

@ -1,31 +1,31 @@
/* Do not edit this file. It was automatically genarated. */ /* Do not edit this file. It was automatically genarated. */
#ifndef HEADER_AvailableColumnsListBox #ifndef HEADER_AvailableColumnsPanel
#define HEADER_AvailableColumnsListBox #define HEADER_AvailableColumnsPanel
#include "Settings.h" #include "Settings.h"
#include "Header.h" #include "Header.h"
#include "ScreenManager.h" #include "ScreenManager.h"
#include "ListBox.h" #include "Panel.h"
#include "debug.h" #include "debug.h"
#include <assert.h> #include <assert.h>
typedef struct AvailableColumnsListBox_ { typedef struct AvailableColumnsPanel_ {
ListBox super; Panel super;
Settings* settings; Settings* settings;
ScreenManager* scr; ScreenManager* scr;
ListBox* columns; Panel* columns;
} AvailableColumnsListBox; } AvailableColumnsPanel;
AvailableColumnsListBox* AvailableColumnsListBox_new(Settings* settings, ListBox* columns, ScreenManager* scr); AvailableColumnsPanel* AvailableColumnsPanel_new(Settings* settings, Panel* columns, ScreenManager* scr);
void AvailableColumnsListBox_delete(Object* object); void AvailableColumnsPanel_delete(Object* object);
HandlerResult AvailableColumnsListBox_eventHandler(ListBox* super, int ch); HandlerResult AvailableColumnsPanel_eventHandler(Panel* super, int ch);
#endif #endif

View File

@ -1,79 +1,79 @@
#include "AvailableMetersListBox.h" #include "AvailableMetersPanel.h"
#include "Settings.h" #include "Settings.h"
#include "Header.h" #include "Header.h"
#include "ScreenManager.h" #include "ScreenManager.h"
#include "ListBox.h" #include "Panel.h"
#include "debug.h" #include "debug.h"
#include <assert.h> #include <assert.h>
/*{ /*{
typedef struct AvailableMetersListBox_ { typedef struct AvailableMetersPanel_ {
ListBox super; Panel super;
Settings* settings; Settings* settings;
ListBox* leftBox; Panel* leftBox;
ListBox* rightBox; Panel* rightBox;
ScreenManager* scr; ScreenManager* scr;
} AvailableMetersListBox; } AvailableMetersPanel;
}*/ }*/
AvailableMetersListBox* AvailableMetersListBox_new(Settings* settings, ListBox* leftMeters, ListBox* rightMeters, ScreenManager* scr) { AvailableMetersPanel* AvailableMetersPanel_new(Settings* settings, Panel* leftMeters, Panel* rightMeters, ScreenManager* scr) {
AvailableMetersListBox* this = (AvailableMetersListBox*) malloc(sizeof(AvailableMetersListBox)); AvailableMetersPanel* this = (AvailableMetersPanel*) malloc(sizeof(AvailableMetersPanel));
ListBox* super = (ListBox*) this; Panel* super = (Panel*) this;
ListBox_init(super, 1, 1, 1, 1, LISTITEM_CLASS, true); Panel_init(super, 1, 1, 1, 1, LISTITEM_CLASS, true);
((Object*)this)->delete = AvailableMetersListBox_delete; ((Object*)this)->delete = AvailableMetersPanel_delete;
this->settings = settings; this->settings = settings;
this->leftBox = leftMeters; this->leftBox = leftMeters;
this->rightBox = rightMeters; this->rightBox = rightMeters;
this->scr = scr; this->scr = scr;
super->eventHandler = AvailableMetersListBox_EventHandler; super->eventHandler = AvailableMetersPanel_EventHandler;
ListBox_setHeader(super, "Available meters"); Panel_setHeader(super, "Available meters");
for (int i = 1; Meter_types[i]; i++) { for (int i = 1; Meter_types[i]; i++) {
MeterType* type = Meter_types[i]; MeterType* type = Meter_types[i];
if (type != &CPUMeter) { if (type != &CPUMeter) {
ListBox_add(super, (Object*) ListItem_new(type->uiName, i << 16)); Panel_add(super, (Object*) ListItem_new(type->uiName, i << 16));
} }
} }
MeterType* type = &CPUMeter; MeterType* type = &CPUMeter;
int processors = settings->pl->processorCount; int processors = settings->pl->processorCount;
if (processors > 1) { if (processors > 1) {
ListBox_add(super, (Object*) ListItem_new("CPU average", 0)); Panel_add(super, (Object*) ListItem_new("CPU average", 0));
for (int i = 1; i <= processors; i++) { for (int i = 1; i <= processors; i++) {
char buffer[50]; char buffer[50];
sprintf(buffer, "%s %d", type->uiName, i); sprintf(buffer, "%s %d", type->uiName, i);
ListBox_add(super, (Object*) ListItem_new(buffer, i)); Panel_add(super, (Object*) ListItem_new(buffer, i));
} }
} else { } else {
ListBox_add(super, (Object*) ListItem_new("CPU", 1)); Panel_add(super, (Object*) ListItem_new("CPU", 1));
} }
return this; return this;
} }
void AvailableMetersListBox_delete(Object* object) { void AvailableMetersPanel_delete(Object* object) {
ListBox* super = (ListBox*) object; Panel* super = (Panel*) object;
AvailableMetersListBox* this = (AvailableMetersListBox*) object; AvailableMetersPanel* this = (AvailableMetersPanel*) object;
ListBox_done(super); Panel_done(super);
free(this); free(this);
} }
/* private */ /* private */
inline void AvailableMetersListBox_addHeader(Header* header, ListBox* lb, MeterType* type, int param, HeaderSide side) { inline void AvailableMetersPanel_addHeader(Header* header, Panel* lb, MeterType* type, int param, HeaderSide side) {
Meter* meter = (Meter*) Header_addMeter(header, type, param, side); Meter* meter = (Meter*) Header_addMeter(header, type, param, side);
ListBox_add(lb, (Object*) Meter_toListItem(meter)); Panel_add(lb, (Object*) Meter_toListItem(meter));
} }
HandlerResult AvailableMetersListBox_EventHandler(ListBox* super, int ch) { HandlerResult AvailableMetersPanel_EventHandler(Panel* super, int ch) {
AvailableMetersListBox* this = (AvailableMetersListBox*) super; AvailableMetersPanel* this = (AvailableMetersPanel*) super;
Header* header = this->settings->header; Header* header = this->settings->header;
ListItem* selected = (ListItem*) ListBox_getSelected(super); ListItem* selected = (ListItem*) Panel_getSelected(super);
int param = selected->key & 0xff; int param = selected->key & 0xff;
int type = selected->key >> 16; int type = selected->key >> 16;
HandlerResult result = IGNORED; HandlerResult result = IGNORED;
@ -83,7 +83,7 @@ HandlerResult AvailableMetersListBox_EventHandler(ListBox* super, int ch) {
case 'l': case 'l':
case 'L': case 'L':
{ {
AvailableMetersListBox_addHeader(header, this->leftBox, Meter_types[type], param, LEFT_HEADER); AvailableMetersPanel_addHeader(header, this->leftBox, Meter_types[type], param, LEFT_HEADER);
result = HANDLED; result = HANDLED;
break; break;
} }
@ -91,7 +91,7 @@ HandlerResult AvailableMetersListBox_EventHandler(ListBox* super, int ch) {
case 'r': case 'r':
case 'R': case 'R':
{ {
AvailableMetersListBox_addHeader(header, this->rightBox, Meter_types[type], param, RIGHT_HEADER); AvailableMetersPanel_addHeader(header, this->rightBox, Meter_types[type], param, RIGHT_HEADER);
result = HANDLED; result = HANDLED;
break; break;
} }

View File

@ -1,33 +1,33 @@
/* Do not edit this file. It was automatically genarated. */ /* Do not edit this file. It was automatically genarated. */
#ifndef HEADER_AvailableMetersListBox #ifndef HEADER_AvailableMetersPanel
#define HEADER_AvailableMetersListBox #define HEADER_AvailableMetersPanel
#include "Settings.h" #include "Settings.h"
#include "Header.h" #include "Header.h"
#include "ScreenManager.h" #include "ScreenManager.h"
#include "ListBox.h" #include "Panel.h"
#include "debug.h" #include "debug.h"
#include <assert.h> #include <assert.h>
typedef struct AvailableMetersListBox_ { typedef struct AvailableMetersPanel_ {
ListBox super; Panel super;
Settings* settings; Settings* settings;
ListBox* leftBox; Panel* leftBox;
ListBox* rightBox; Panel* rightBox;
ScreenManager* scr; ScreenManager* scr;
} AvailableMetersListBox; } AvailableMetersPanel;
AvailableMetersListBox* AvailableMetersListBox_new(Settings* settings, ListBox* leftMeters, ListBox* rightMeters, ScreenManager* scr); AvailableMetersPanel* AvailableMetersPanel_new(Settings* settings, Panel* leftMeters, Panel* rightMeters, ScreenManager* scr);
void AvailableMetersListBox_delete(Object* object); void AvailableMetersPanel_delete(Object* object);
HandlerResult AvailableMetersListBox_EventHandler(ListBox* super, int ch); HandlerResult AvailableMetersPanel_EventHandler(Panel* super, int ch);
#endif #endif

View File

@ -1,25 +1,25 @@
#include "CategoriesListBox.h" #include "CategoriesPanel.h"
#include "AvailableMetersListBox.h" #include "AvailableMetersPanel.h"
#include "MetersListBox.h" #include "MetersPanel.h"
#include "DisplayOptionsListBox.h" #include "DisplayOptionsPanel.h"
#include "ColumnsListBox.h" #include "ColumnsPanel.h"
#include "ColorsListBox.h" #include "ColorsPanel.h"
#include "AvailableColumnsListBox.h" #include "AvailableColumnsPanel.h"
#include "ListBox.h" #include "Panel.h"
#include "debug.h" #include "debug.h"
#include <assert.h> #include <assert.h>
/*{ /*{
typedef struct CategoriesListBox_ { typedef struct CategoriesPanel_ {
ListBox super; Panel super;
Settings* settings; Settings* settings;
ScreenManager* scr; ScreenManager* scr;
} CategoriesListBox; } CategoriesPanel;
}*/ }*/
@ -41,36 +41,36 @@ char* ColorsFunctions[10] = {" ", " ", " ", " ", " ", "
/* private property */ /* private property */
char* AvailableColumnsFunctions[10] = {" ", " ", " ", " ", "Add ", " ", " ", " ", " ", "Done "}; char* AvailableColumnsFunctions[10] = {" ", " ", " ", " ", "Add ", " ", " ", " ", " ", "Done "};
CategoriesListBox* CategoriesListBox_new(Settings* settings, ScreenManager* scr) { CategoriesPanel* CategoriesPanel_new(Settings* settings, ScreenManager* scr) {
CategoriesListBox* this = (CategoriesListBox*) malloc(sizeof(CategoriesListBox)); CategoriesPanel* this = (CategoriesPanel*) malloc(sizeof(CategoriesPanel));
ListBox* super = (ListBox*) this; Panel* super = (Panel*) this;
ListBox_init(super, 1, 1, 1, 1, LISTITEM_CLASS, true); Panel_init(super, 1, 1, 1, 1, LISTITEM_CLASS, true);
((Object*)this)->delete = CategoriesListBox_delete; ((Object*)this)->delete = CategoriesPanel_delete;
this->settings = settings; this->settings = settings;
this->scr = scr; this->scr = scr;
super->eventHandler = CategoriesListBox_eventHandler; super->eventHandler = CategoriesPanel_eventHandler;
ListBox_setHeader(super, "Setup"); Panel_setHeader(super, "Setup");
ListBox_add(super, (Object*) ListItem_new("Meters", 0)); Panel_add(super, (Object*) ListItem_new("Meters", 0));
ListBox_add(super, (Object*) ListItem_new("Display options", 0)); Panel_add(super, (Object*) ListItem_new("Display options", 0));
ListBox_add(super, (Object*) ListItem_new("Colors", 0)); Panel_add(super, (Object*) ListItem_new("Colors", 0));
ListBox_add(super, (Object*) ListItem_new("Columns", 0)); Panel_add(super, (Object*) ListItem_new("Columns", 0));
return this; return this;
} }
void CategoriesListBox_delete(Object* object) { void CategoriesPanel_delete(Object* object) {
ListBox* super = (ListBox*) object; Panel* super = (Panel*) object;
CategoriesListBox* this = (CategoriesListBox*) object; CategoriesPanel* this = (CategoriesPanel*) object;
ListBox_done(super); Panel_done(super);
free(this); free(this);
} }
HandlerResult CategoriesListBox_eventHandler(ListBox* super, int ch) { HandlerResult CategoriesPanel_eventHandler(Panel* super, int ch) {
CategoriesListBox* this = (CategoriesListBox*) super; CategoriesPanel* this = (CategoriesPanel*) super;
HandlerResult result = IGNORED; HandlerResult result = IGNORED;
int previous = ListBox_getSelectedIndex(super); int previous = Panel_getSelectedIndex(super);
switch (ch) { switch (ch) {
case KEY_UP: case KEY_UP:
@ -79,24 +79,24 @@ HandlerResult CategoriesListBox_eventHandler(ListBox* super, int ch) {
case KEY_PPAGE: case KEY_PPAGE:
case KEY_HOME: case KEY_HOME:
case KEY_END: { case KEY_END: {
ListBox_onKey(super, ch); Panel_onKey(super, ch);
int selected = ListBox_getSelectedIndex(super); int selected = Panel_getSelectedIndex(super);
if (previous != selected) { if (previous != selected) {
int size = ScreenManager_size(this->scr); int size = ScreenManager_size(this->scr);
for (int i = 1; i < size; i++) for (int i = 1; i < size; i++)
ScreenManager_remove(this->scr, 1); ScreenManager_remove(this->scr, 1);
switch (selected) { switch (selected) {
case 0: case 0:
CategoriesListBox_makeMetersPage(this); CategoriesPanel_makeMetersPage(this);
break; break;
case 1: case 1:
CategoriesListBox_makeDisplayOptionsPage(this); CategoriesPanel_makeDisplayOptionsPage(this);
break; break;
case 2: case 2:
CategoriesListBox_makeColorsPage(this); CategoriesPanel_makeColorsPage(this);
break; break;
case 3: case 3:
CategoriesListBox_makeColumnsPage(this); CategoriesPanel_makeColumnsPage(this);
break; break;
} }
} }
@ -107,28 +107,28 @@ HandlerResult CategoriesListBox_eventHandler(ListBox* super, int ch) {
return result; return result;
} }
void CategoriesListBox_makeMetersPage(CategoriesListBox* this) { void CategoriesPanel_makeMetersPage(CategoriesPanel* this) {
ListBox* lbLeftMeters = (ListBox*) MetersListBox_new(this->settings, "Left column", this->settings->header->leftMeters, this->scr); Panel* lbLeftMeters = (Panel*) MetersPanel_new(this->settings, "Left column", this->settings->header->leftMeters, this->scr);
ListBox* lbRightMeters = (ListBox*) MetersListBox_new(this->settings, "Right column", this->settings->header->rightMeters, this->scr); Panel* lbRightMeters = (Panel*) MetersPanel_new(this->settings, "Right column", this->settings->header->rightMeters, this->scr);
ListBox* lbAvailableMeters = (ListBox*) AvailableMetersListBox_new(this->settings, lbLeftMeters, lbRightMeters, this->scr); Panel* lbAvailableMeters = (Panel*) AvailableMetersPanel_new(this->settings, lbLeftMeters, lbRightMeters, this->scr);
ScreenManager_add(this->scr, lbLeftMeters, FunctionBar_new(10, MetersFunctions, NULL, NULL), 20); ScreenManager_add(this->scr, lbLeftMeters, FunctionBar_new(10, MetersFunctions, NULL, NULL), 20);
ScreenManager_add(this->scr, lbRightMeters, FunctionBar_new(10, MetersFunctions, NULL, NULL), 20); ScreenManager_add(this->scr, lbRightMeters, FunctionBar_new(10, MetersFunctions, NULL, NULL), 20);
ScreenManager_add(this->scr, lbAvailableMeters, FunctionBar_new(10, AvailableMetersFunctions, NULL, NULL), -1); ScreenManager_add(this->scr, lbAvailableMeters, FunctionBar_new(10, AvailableMetersFunctions, NULL, NULL), -1);
} }
void CategoriesListBox_makeDisplayOptionsPage(CategoriesListBox* this) { void CategoriesPanel_makeDisplayOptionsPage(CategoriesPanel* this) {
ListBox* lbDisplayOptions = (ListBox*) DisplayOptionsListBox_new(this->settings, this->scr); Panel* lbDisplayOptions = (Panel*) DisplayOptionsPanel_new(this->settings, this->scr);
ScreenManager_add(this->scr, lbDisplayOptions, FunctionBar_new(10, DisplayOptionsFunctions, NULL, NULL), -1); ScreenManager_add(this->scr, lbDisplayOptions, FunctionBar_new(10, DisplayOptionsFunctions, NULL, NULL), -1);
} }
void CategoriesListBox_makeColorsPage(CategoriesListBox* this) { void CategoriesPanel_makeColorsPage(CategoriesPanel* this) {
ListBox* lbColors = (ListBox*) ColorsListBox_new(this->settings, this->scr); Panel* lbColors = (Panel*) ColorsPanel_new(this->settings, this->scr);
ScreenManager_add(this->scr, lbColors, FunctionBar_new(10, ColorsFunctions, NULL, NULL), -1); ScreenManager_add(this->scr, lbColors, FunctionBar_new(10, ColorsFunctions, NULL, NULL), -1);
} }
void CategoriesListBox_makeColumnsPage(CategoriesListBox* this) { void CategoriesPanel_makeColumnsPage(CategoriesPanel* this) {
ListBox* lbColumns = (ListBox*) ColumnsListBox_new(this->settings, this->scr); Panel* lbColumns = (Panel*) ColumnsPanel_new(this->settings, this->scr);
ListBox* lbAvailableColumns = (ListBox*) AvailableColumnsListBox_new(this->settings, lbColumns, this->scr); Panel* lbAvailableColumns = (Panel*) AvailableColumnsPanel_new(this->settings, lbColumns, this->scr);
ScreenManager_add(this->scr, lbColumns, FunctionBar_new(10, ColumnsFunctions, NULL, NULL), 20); ScreenManager_add(this->scr, lbColumns, FunctionBar_new(10, ColumnsFunctions, NULL, NULL), 20);
ScreenManager_add(this->scr, lbAvailableColumns, FunctionBar_new(10, AvailableColumnsFunctions, NULL, NULL), -1); ScreenManager_add(this->scr, lbAvailableColumns, FunctionBar_new(10, AvailableColumnsFunctions, NULL, NULL), -1);
} }

View File

@ -1,40 +1,40 @@
/* Do not edit this file. It was automatically genarated. */ /* Do not edit this file. It was automatically genarated. */
#ifndef HEADER_CategoriesListBox #ifndef HEADER_CategoriesPanel
#define HEADER_CategoriesListBox #define HEADER_CategoriesPanel
#include "AvailableMetersListBox.h" #include "AvailableMetersPanel.h"
#include "MetersListBox.h" #include "MetersPanel.h"
#include "DisplayOptionsListBox.h" #include "DisplayOptionsPanel.h"
#include "ListBox.h" #include "Panel.h"
#include "debug.h" #include "debug.h"
#include <assert.h> #include <assert.h>
typedef struct CategoriesListBox_ { typedef struct CategoriesPanel_ {
ListBox super; Panel super;
Settings* settings; Settings* settings;
ScreenManager* scr; ScreenManager* scr;
} CategoriesListBox; } CategoriesPanel;
CategoriesListBox* CategoriesListBox_new(Settings* settings, ScreenManager* scr); CategoriesPanel* CategoriesPanel_new(Settings* settings, ScreenManager* scr);
void CategoriesListBox_delete(Object* object); void CategoriesPanel_delete(Object* object);
HandlerResult CategoriesListBox_eventHandler(ListBox* super, int ch); HandlerResult CategoriesPanel_eventHandler(Panel* super, int ch);
void CategoriesListBox_makeMetersPage(CategoriesListBox* this); void CategoriesPanel_makeMetersPage(CategoriesPanel* this);
void CategoriesListBox_makeDisplayOptionsPage(CategoriesListBox* this); void CategoriesPanel_makeDisplayOptionsPage(CategoriesPanel* this);
void CategoriesListBox_makeColorsPage(CategoriesListBox* this); void CategoriesPanel_makeColorsPage(CategoriesPanel* this);
void CategoriesListBox_makeColumnsPage(CategoriesListBox* this); void CategoriesPanel_makeColumnsPage(CategoriesPanel* this);
#endif #endif

View File

@ -137,7 +137,7 @@ What's new in version 0.4
* Clock and load average meters * Clock and load average meters
(thanks to Marc Calahan) (thanks to Marc Calahan)
* BUGFIX: numeric swap indicator was printing bogus value * BUGFIX: numeric swap indicator was printing bogus value
* BUGFIX: internal fixes on ListBox widget * BUGFIX: internal fixes on Panel widget
* Clear the bottom line when exiting * Clear the bottom line when exiting
* Press "F3" during search to walk through the results * Press "F3" during search to walk through the results
* Improved navigation on column configuration screen * Improved navigation on column configuration screen

View File

@ -1,8 +1,8 @@
#include "CRT.h" #include "CRT.h"
#include "ColorsListBox.h" #include "ColorsPanel.h"
#include "ListBox.h" #include "Panel.h"
#include "CheckItem.h" #include "CheckItem.h"
#include "Settings.h" #include "Settings.h"
#include "ScreenManager.h" #include "ScreenManager.h"
@ -11,20 +11,20 @@
#include <assert.h> #include <assert.h>
// TO ADD A NEW SCHEME: // TO ADD A NEW SCHEME:
// * Increment the size of bool check in ColorsListBox.h // * Increment the size of bool check in ColorsPanel.h
// * Add the entry in the ColorSchemes array below in the file // * Add the entry in the ColorSchemes array below in the file
// * Add a define in CRT.h that matches the order of the array // * Add a define in CRT.h that matches the order of the array
// * Add the colors in CRT_setColors // * Add the colors in CRT_setColors
/*{ /*{
typedef struct ColorsListBox_ { typedef struct ColorsPanel_ {
ListBox super; Panel super;
Settings* settings; Settings* settings;
ScreenManager* scr; ScreenManager* scr;
bool check[5]; bool check[5];
} ColorsListBox; } ColorsPanel;
}*/ }*/
@ -39,37 +39,37 @@ static char* ColorSchemes[] = {
NULL NULL
}; };
ColorsListBox* ColorsListBox_new(Settings* settings, ScreenManager* scr) { ColorsPanel* ColorsPanel_new(Settings* settings, ScreenManager* scr) {
ColorsListBox* this = (ColorsListBox*) malloc(sizeof(ColorsListBox)); ColorsPanel* this = (ColorsPanel*) malloc(sizeof(ColorsPanel));
ListBox* super = (ListBox*) this; Panel* super = (Panel*) this;
ListBox_init(super, 1, 1, 1, 1, CHECKITEM_CLASS, true); Panel_init(super, 1, 1, 1, 1, CHECKITEM_CLASS, true);
((Object*)this)->delete = ColorsListBox_delete; ((Object*)this)->delete = ColorsPanel_delete;
this->settings = settings; this->settings = settings;
this->scr = scr; this->scr = scr;
super->eventHandler = ColorsListBox_EventHandler; super->eventHandler = ColorsPanel_EventHandler;
ListBox_setHeader(super, "Colors"); Panel_setHeader(super, "Colors");
for (int i = 0; ColorSchemes[i] != NULL; i++) { for (int i = 0; ColorSchemes[i] != NULL; i++) {
ListBox_add(super, (Object*) CheckItem_new(String_copy(ColorSchemes[i]), &(this->check[i]))); Panel_add(super, (Object*) CheckItem_new(String_copy(ColorSchemes[i]), &(this->check[i])));
this->check[i] = false; this->check[i] = false;
} }
this->check[settings->colorScheme] = true; this->check[settings->colorScheme] = true;
return this; return this;
} }
void ColorsListBox_delete(Object* object) { void ColorsPanel_delete(Object* object) {
ListBox* super = (ListBox*) object; Panel* super = (Panel*) object;
ColorsListBox* this = (ColorsListBox*) object; ColorsPanel* this = (ColorsPanel*) object;
ListBox_done(super); Panel_done(super);
free(this); free(this);
} }
HandlerResult ColorsListBox_EventHandler(ListBox* super, int ch) { HandlerResult ColorsPanel_EventHandler(Panel* super, int ch) {
ColorsListBox* this = (ColorsListBox*) super; ColorsPanel* this = (ColorsPanel*) super;
HandlerResult result = IGNORED; HandlerResult result = IGNORED;
int mark = ListBox_getSelectedIndex(super); int mark = Panel_getSelectedIndex(super);
switch(ch) { switch(ch) {
case 0x0a: case 0x0a:
@ -88,7 +88,7 @@ HandlerResult ColorsListBox_EventHandler(ListBox* super, int ch) {
this->settings->changed = true; this->settings->changed = true;
Header* header = this->settings->header; Header* header = this->settings->header;
CRT_setColors(mark); CRT_setColors(mark);
ListBox* lbMenu = (ListBox*) Vector_get(this->scr->items, 0); Panel* lbMenu = (Panel*) Vector_get(this->scr->items, 0);
Header_draw(header); Header_draw(header);
RichString_setAttr(&(super->header), CRT_colors[PANEL_HEADER_FOCUS]); RichString_setAttr(&(super->header), CRT_colors[PANEL_HEADER_FOCUS]);
RichString_setAttr(&(lbMenu->header), CRT_colors[PANEL_HEADER_UNFOCUS]); RichString_setAttr(&(lbMenu->header), CRT_colors[PANEL_HEADER_UNFOCUS]);

View File

@ -1,10 +1,10 @@
/* Do not edit this file. It was automatically genarated. */ /* Do not edit this file. It was automatically genarated. */
#ifndef HEADER_ColorsListBox #ifndef HEADER_ColorsPanel
#define HEADER_ColorsListBox #define HEADER_ColorsPanel
#include "ListBox.h" #include "Panel.h"
#include "CheckItem.h" #include "CheckItem.h"
#include "Settings.h" #include "Settings.h"
#include "ScreenManager.h" #include "ScreenManager.h"
@ -13,20 +13,20 @@
#include <assert.h> #include <assert.h>
typedef struct ColorsListBox_ { typedef struct ColorsPanel_ {
ListBox super; Panel super;
Settings* settings; Settings* settings;
ScreenManager* scr; ScreenManager* scr;
bool check[5]; bool check[5];
} ColorsListBox; } ColorsPanel;
ColorsListBox* ColorsListBox_new(Settings* settings, ScreenManager* scr); ColorsPanel* ColorsPanel_new(Settings* settings, ScreenManager* scr);
void ColorsListBox_delete(Object* object); void ColorsPanel_delete(Object* object);
HandlerResult ColorsListBox_EventHandler(ListBox* super, int ch); HandlerResult ColorsPanel_EventHandler(Panel* super, int ch);
#endif #endif

View File

@ -1,7 +1,7 @@
#include "ColumnsListBox.h" #include "ColumnsPanel.h"
#include "ListBox.h" #include "Panel.h"
#include "Settings.h" #include "Settings.h"
#include "ScreenManager.h" #include "ScreenManager.h"
@ -10,49 +10,49 @@
/*{ /*{
typedef struct ColumnsListBox_ { typedef struct ColumnsPanel_ {
ListBox super; Panel super;
Settings* settings; Settings* settings;
ScreenManager* scr; ScreenManager* scr;
} ColumnsListBox; } ColumnsPanel;
}*/ }*/
ColumnsListBox* ColumnsListBox_new(Settings* settings, ScreenManager* scr) { ColumnsPanel* ColumnsPanel_new(Settings* settings, ScreenManager* scr) {
ColumnsListBox* this = (ColumnsListBox*) malloc(sizeof(ColumnsListBox)); ColumnsPanel* this = (ColumnsPanel*) malloc(sizeof(ColumnsPanel));
ListBox* super = (ListBox*) this; Panel* super = (Panel*) this;
ListBox_init(super, 1, 1, 1, 1, LISTITEM_CLASS, true); Panel_init(super, 1, 1, 1, 1, LISTITEM_CLASS, true);
((Object*)this)->delete = ColumnsListBox_delete; ((Object*)this)->delete = ColumnsPanel_delete;
this->settings = settings; this->settings = settings;
this->scr = scr; this->scr = scr;
super->eventHandler = ColumnsListBox_eventHandler; super->eventHandler = ColumnsPanel_eventHandler;
ListBox_setHeader(super, "Active Columns"); Panel_setHeader(super, "Active Columns");
ProcessField* fields = this->settings->pl->fields; ProcessField* fields = this->settings->pl->fields;
for (; *fields; fields++) { for (; *fields; fields++) {
ListBox_add(super, (Object*) ListItem_new(Process_fieldNames[*fields], 0)); Panel_add(super, (Object*) ListItem_new(Process_fieldNames[*fields], 0));
} }
return this; return this;
} }
void ColumnsListBox_delete(Object* object) { void ColumnsPanel_delete(Object* object) {
ListBox* super = (ListBox*) object; Panel* super = (Panel*) object;
ColumnsListBox* this = (ColumnsListBox*) object; ColumnsPanel* this = (ColumnsPanel*) object;
ListBox_done(super); Panel_done(super);
free(this); free(this);
} }
void ColumnsListBox_update(ListBox* super) { void ColumnsPanel_update(Panel* super) {
ColumnsListBox* this = (ColumnsListBox*) super; ColumnsPanel* this = (ColumnsPanel*) super;
int size = ListBox_getSize(super); int size = Panel_getSize(super);
this->settings->changed = true; this->settings->changed = true;
// FIXME: this is crappily inefficient // FIXME: this is crappily inefficient
free(this->settings->pl->fields); free(this->settings->pl->fields);
this->settings->pl->fields = (ProcessField*) malloc(sizeof(ProcessField) * (size+1)); this->settings->pl->fields = (ProcessField*) malloc(sizeof(ProcessField) * (size+1));
for (int i = 0; i < size; i++) { for (int i = 0; i < size; i++) {
char* text = ((ListItem*) ListBox_get(super, i))->value; char* text = ((ListItem*) Panel_get(super, i))->value;
for (int j = 1; j <= LAST_PROCESSFIELD; j++) { for (int j = 1; j <= LAST_PROCESSFIELD; j++) {
if (String_eq(text, Process_fieldNames[j])) { if (String_eq(text, Process_fieldNames[j])) {
this->settings->pl->fields[i] = j; this->settings->pl->fields[i] = j;
@ -63,11 +63,11 @@ void ColumnsListBox_update(ListBox* super) {
this->settings->pl->fields[size] = 0; this->settings->pl->fields[size] = 0;
} }
HandlerResult ColumnsListBox_eventHandler(ListBox* super, int ch) { HandlerResult ColumnsPanel_eventHandler(Panel* super, int ch) {
int selected = ListBox_getSelectedIndex(super); int selected = Panel_getSelectedIndex(super);
HandlerResult result = IGNORED; HandlerResult result = IGNORED;
int size = ListBox_getSize(super); int size = Panel_getSize(super);
switch(ch) { switch(ch) {
case KEY_F(7): case KEY_F(7):
@ -75,7 +75,7 @@ HandlerResult ColumnsListBox_eventHandler(ListBox* super, int ch) {
case '-': case '-':
{ {
if (selected < size - 1) if (selected < size - 1)
ListBox_moveSelectedUp(super); Panel_moveSelectedUp(super);
result = HANDLED; result = HANDLED;
break; break;
} }
@ -84,7 +84,7 @@ HandlerResult ColumnsListBox_eventHandler(ListBox* super, int ch) {
case '+': case '+':
{ {
if (selected < size - 2) if (selected < size - 2)
ListBox_moveSelectedDown(super); Panel_moveSelectedDown(super);
result = HANDLED; result = HANDLED;
break; break;
} }
@ -92,13 +92,13 @@ HandlerResult ColumnsListBox_eventHandler(ListBox* super, int ch) {
case KEY_DC: case KEY_DC:
{ {
if (selected < size - 1) { if (selected < size - 1) {
ListBox_remove(super, selected); Panel_remove(super, selected);
} }
result = HANDLED; result = HANDLED;
break; break;
} }
} }
if (result == HANDLED) if (result == HANDLED)
ColumnsListBox_update(super); ColumnsPanel_update(super);
return result; return result;
} }

View File

@ -1,10 +1,10 @@
/* Do not edit this file. It was automatically genarated. */ /* Do not edit this file. It was automatically genarated. */
#ifndef HEADER_ColumnsListBox #ifndef HEADER_ColumnsPanel
#define HEADER_ColumnsListBox #define HEADER_ColumnsPanel
#include "ListBox.h" #include "Panel.h"
#include "Settings.h" #include "Settings.h"
#include "ScreenManager.h" #include "ScreenManager.h"
@ -12,21 +12,21 @@
#include <assert.h> #include <assert.h>
typedef struct ColumnsListBox_ { typedef struct ColumnsPanel_ {
ListBox super; Panel super;
Settings* settings; Settings* settings;
Vector* columns; Vector* columns;
ScreenManager* scr; ScreenManager* scr;
} ColumnsListBox; } ColumnsPanel;
ColumnsListBox* ColumnsListBox_new(Settings* settings, ScreenManager* scr); ColumnsPanel* ColumnsPanel_new(Settings* settings, ScreenManager* scr);
void ColumnsListBox_delete(Object* object); void ColumnsPanel_delete(Object* object);
void ColumnsListBox_update(ListBox* super); void ColumnsPanel_update(Panel* super);
HandlerResult ColumnsListBox_eventHandler(ListBox* super, int ch); HandlerResult ColumnsPanel_eventHandler(Panel* super, int ch);
#endif #endif

View File

@ -1,7 +1,7 @@
#include "DisplayOptionsListBox.h" #include "DisplayOptionsPanel.h"
#include "ListBox.h" #include "Panel.h"
#include "CheckItem.h" #include "CheckItem.h"
#include "Settings.h" #include "Settings.h"
#include "ScreenManager.h" #include "ScreenManager.h"
@ -11,48 +11,48 @@
/*{ /*{
typedef struct DisplayOptionsListBox_ { typedef struct DisplayOptionsPanel_ {
ListBox super; Panel super;
Settings* settings; Settings* settings;
ScreenManager* scr; ScreenManager* scr;
} DisplayOptionsListBox; } DisplayOptionsPanel;
}*/ }*/
DisplayOptionsListBox* DisplayOptionsListBox_new(Settings* settings, ScreenManager* scr) { DisplayOptionsPanel* DisplayOptionsPanel_new(Settings* settings, ScreenManager* scr) {
DisplayOptionsListBox* this = (DisplayOptionsListBox*) malloc(sizeof(DisplayOptionsListBox)); DisplayOptionsPanel* this = (DisplayOptionsPanel*) malloc(sizeof(DisplayOptionsPanel));
ListBox* super = (ListBox*) this; Panel* super = (Panel*) this;
ListBox_init(super, 1, 1, 1, 1, CHECKITEM_CLASS, true); Panel_init(super, 1, 1, 1, 1, CHECKITEM_CLASS, true);
((Object*)this)->delete = DisplayOptionsListBox_delete; ((Object*)this)->delete = DisplayOptionsPanel_delete;
this->settings = settings; this->settings = settings;
this->scr = scr; this->scr = scr;
super->eventHandler = DisplayOptionsListBox_EventHandler; super->eventHandler = DisplayOptionsPanel_EventHandler;
ListBox_setHeader(super, "Display options"); Panel_setHeader(super, "Display options");
ListBox_add(super, (Object*) CheckItem_new(String_copy("Tree view"), &(settings->pl->treeView))); Panel_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))); Panel_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))); Panel_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))); Panel_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))); Panel_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))); Panel_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))); Panel_add(super, (Object*) CheckItem_new(String_copy("Leave a margin around header"), &(settings->header->margin)));
return this; return this;
} }
void DisplayOptionsListBox_delete(Object* object) { void DisplayOptionsPanel_delete(Object* object) {
ListBox* super = (ListBox*) object; Panel* super = (Panel*) object;
DisplayOptionsListBox* this = (DisplayOptionsListBox*) object; DisplayOptionsPanel* this = (DisplayOptionsPanel*) object;
ListBox_done(super); Panel_done(super);
free(this); free(this);
} }
HandlerResult DisplayOptionsListBox_EventHandler(ListBox* super, int ch) { HandlerResult DisplayOptionsPanel_EventHandler(Panel* super, int ch) {
DisplayOptionsListBox* this = (DisplayOptionsListBox*) super; DisplayOptionsPanel* this = (DisplayOptionsPanel*) super;
HandlerResult result = IGNORED; HandlerResult result = IGNORED;
CheckItem* selected = (CheckItem*) ListBox_getSelected(super); CheckItem* selected = (CheckItem*) Panel_getSelected(super);
switch(ch) { switch(ch) {
case 0x0a: case 0x0a:

View File

@ -1,10 +1,10 @@
/* Do not edit this file. It was automatically genarated. */ /* Do not edit this file. It was automatically genarated. */
#ifndef HEADER_DisplayOptionsListBox #ifndef HEADER_DisplayOptionsPanel
#define HEADER_DisplayOptionsListBox #define HEADER_DisplayOptionsPanel
#include "ListBox.h" #include "Panel.h"
#include "CheckItem.h" #include "CheckItem.h"
#include "Settings.h" #include "Settings.h"
#include "ScreenManager.h" #include "ScreenManager.h"
@ -13,19 +13,19 @@
#include <assert.h> #include <assert.h>
typedef struct DisplayOptionsListBox_ { typedef struct DisplayOptionsPanel_ {
ListBox super; Panel super;
Settings* settings; Settings* settings;
ScreenManager* scr; ScreenManager* scr;
} DisplayOptionsListBox; } DisplayOptionsPanel;
DisplayOptionsListBox* DisplayOptionsListBox_new(Settings* settings, ScreenManager* scr); DisplayOptionsPanel* DisplayOptionsPanel_new(Settings* settings, ScreenManager* scr);
void DisplayOptionsListBox_delete(Object* object); void DisplayOptionsPanel_delete(Object* object);
HandlerResult DisplayOptionsListBox_EventHandler(ListBox* super, int ch); HandlerResult DisplayOptionsPanel_EventHandler(Panel* super, int ch);
#endif #endif

101
ListBox.h
View File

@ -1,101 +0,0 @@
/* Do not edit this file. It was automatically genarated. */
#ifndef HEADER_ListBox
#define HEADER_ListBox
/*
htop
(C) 2004-2006 Hisham H. Muhammad
Released under the GNU GPL, see the COPYING file
in the source distribution for its full text.
*/
#include "Object.h"
#include "Vector.h"
#include "CRT.h"
#include "RichString.h"
#include <math.h>
#include <sys/param.h>
#include <stdbool.h>
#include "debug.h"
#include <assert.h>
#include <curses.h>
//#link curses
typedef struct ListBox_ ListBox;
typedef enum HandlerResult_ {
HANDLED,
IGNORED,
BREAK_LOOP
} HandlerResult;
typedef HandlerResult(*ListBox_EventHandler)(ListBox*, int);
struct ListBox_ {
Object super;
int x, y, w, h;
WINDOW* window;
Vector* items;
int selected;
int scrollV, scrollH;
int oldSelected;
bool needsRedraw;
RichString header;
ListBox_EventHandler eventHandler;
};
extern char* LISTBOX_CLASS;
ListBox* ListBox_new(int x, int y, int w, int h, char* type, bool owner);
void ListBox_delete(Object* cast);
void ListBox_init(ListBox* this, int x, int y, int w, int h, char* type, bool owner);
void ListBox_done(ListBox* this);
void ListBox_setEventHandler(ListBox* this, ListBox_EventHandler eh);
void ListBox_setRichHeader(ListBox* this, RichString header);
void ListBox_setHeader(ListBox* this, char* header);
void ListBox_move(ListBox* this, int x, int y);
void ListBox_resize(ListBox* this, int w, int h);
void ListBox_prune(ListBox* this);
void ListBox_add(ListBox* this, Object* o);
void ListBox_insert(ListBox* this, int i, Object* o);
void ListBox_set(ListBox* this, int i, Object* o);
Object* ListBox_get(ListBox* this, int i);
Object* ListBox_remove(ListBox* this, int i);
Object* ListBox_getSelected(ListBox* this);
void ListBox_moveSelectedUp(ListBox* this);
void ListBox_moveSelectedDown(ListBox* this);
int ListBox_getSelectedIndex(ListBox* this);
int ListBox_getSize(ListBox* this);
void ListBox_setSelected(ListBox* this, int selected);
void ListBox_draw(ListBox* this, bool focus);
void ListBox_onKey(ListBox* this, int key);
#endif

View File

@ -10,22 +10,22 @@ pixmap_DATA = htop.png
AM_CFLAGS = -pedantic -Wall -std=c99 AM_CFLAGS = -pedantic -Wall -std=c99
AM_CPPFLAGS = -DSYSCONFDIR=\"$(sysconfdir)\" AM_CPPFLAGS = -DSYSCONFDIR=\"$(sysconfdir)\"
htop_SOURCES = AvailableMetersListBox.c CategoriesListBox.c ClockMeter.c \ htop_SOURCES = AvailableMetersPanel.c CategoriesPanel.c ClockMeter.c \
CPUMeter.c CRT.c DebugMemory.c DisplayOptionsListBox.c FunctionBar.c \ CPUMeter.c CRT.c DebugMemory.c DisplayOptionsPanel.c FunctionBar.c \
Hashtable.c Header.c htop.c ListBox.c ListItem.c LoadAverageMeter.c \ Hashtable.c Header.c htop.c Panel.c ListItem.c LoadAverageMeter.c \
MemoryMeter.c Meter.c MetersListBox.c Object.c Process.c \ MemoryMeter.c Meter.c MetersPanel.c Object.c Process.c \
ProcessList.c RichString.c ScreenManager.c Settings.c SignalItem.c \ ProcessList.c RichString.c ScreenManager.c Settings.c SignalItem.c \
SignalsListBox.c String.c SwapMeter.c TasksMeter.c Vector.c \ SignalsPanel.c String.c SwapMeter.c TasksMeter.c Vector.c \
UptimeMeter.c UsersTable.c AvailableMetersListBox.h CategoriesListBox.h \ UptimeMeter.c UsersTable.c AvailableMetersPanel.h CategoriesPanel.h \
ClockMeter.h config.h CPUMeter.h CRT.h debug.h DebugMemory.h \ ClockMeter.h config.h CPUMeter.h CRT.h debug.h DebugMemory.h \
DisplayOptionsListBox.h FunctionBar.h Hashtable.h Header.h htop.h ListBox.h \ DisplayOptionsPanel.h FunctionBar.h Hashtable.h Header.h htop.h Panel.h \
ListItem.h LoadAverageMeter.h MemoryMeter.h Meter.h \ ListItem.h LoadAverageMeter.h MemoryMeter.h Meter.h \
MetersListBox.h Object.h Process.h ProcessList.h RichString.h ScreenManager.h \ MetersPanel.h Object.h Process.h ProcessList.h RichString.h ScreenManager.h \
Settings.h SignalItem.h SignalsListBox.h String.h SwapMeter.h TasksMeter.h \ Settings.h SignalItem.h SignalsPanel.h String.h SwapMeter.h TasksMeter.h \
Vector.h UptimeMeter.h UsersTable.h CheckItem.c CheckItem.h \ Vector.h UptimeMeter.h UsersTable.h CheckItem.c CheckItem.h \
ColorsListBox.c ColorsListBox.h TraceScreen.c TraceScreen.h \ ColorsPanel.c ColorsPanel.h TraceScreen.c TraceScreen.h \
AvailableColumnsListBox.c AvailableColumnsListBox.h ColumnsListBox.c \ AvailableColumnsPanel.c AvailableColumnsPanel.h ColumnsPanel.c \
ColumnsListBox.h ColumnsPanel.h
debug: debug:
$(MAKE) all CFLAGS="-g -DDEBUG" $(MAKE) all CFLAGS="-g -DDEBUG"

View File

@ -1,7 +1,7 @@
#include "MetersListBox.h" #include "MetersPanel.h"
#include "ListBox.h" #include "Panel.h"
#include "Settings.h" #include "Settings.h"
#include "ScreenManager.h" #include "ScreenManager.h"
@ -10,45 +10,45 @@
/*{ /*{
typedef struct MetersListBox_ { typedef struct MetersPanel_ {
ListBox super; Panel super;
Settings* settings; Settings* settings;
Vector* meters; Vector* meters;
ScreenManager* scr; ScreenManager* scr;
} MetersListBox; } MetersPanel;
}*/ }*/
MetersListBox* MetersListBox_new(Settings* settings, char* header, Vector* meters, ScreenManager* scr) { MetersPanel* MetersPanel_new(Settings* settings, char* header, Vector* meters, ScreenManager* scr) {
MetersListBox* this = (MetersListBox*) malloc(sizeof(MetersListBox)); MetersPanel* this = (MetersPanel*) malloc(sizeof(MetersPanel));
ListBox* super = (ListBox*) this; Panel* super = (Panel*) this;
ListBox_init(super, 1, 1, 1, 1, LISTITEM_CLASS, true); Panel_init(super, 1, 1, 1, 1, LISTITEM_CLASS, true);
((Object*)this)->delete = MetersListBox_delete; ((Object*)this)->delete = MetersPanel_delete;
this->settings = settings; this->settings = settings;
this->meters = meters; this->meters = meters;
this->scr = scr; this->scr = scr;
super->eventHandler = MetersListBox_EventHandler; super->eventHandler = MetersPanel_EventHandler;
ListBox_setHeader(super, header); Panel_setHeader(super, header);
for (int i = 0; i < Vector_size(meters); i++) { for (int i = 0; i < Vector_size(meters); i++) {
Meter* meter = (Meter*) Vector_get(meters, i); Meter* meter = (Meter*) Vector_get(meters, i);
ListBox_add(super, (Object*) Meter_toListItem(meter)); Panel_add(super, (Object*) Meter_toListItem(meter));
} }
return this; return this;
} }
void MetersListBox_delete(Object* object) { void MetersPanel_delete(Object* object) {
ListBox* super = (ListBox*) object; Panel* super = (Panel*) object;
MetersListBox* this = (MetersListBox*) object; MetersPanel* this = (MetersPanel*) object;
ListBox_done(super); Panel_done(super);
free(this); free(this);
} }
HandlerResult MetersListBox_EventHandler(ListBox* super, int ch) { HandlerResult MetersPanel_EventHandler(Panel* super, int ch) {
MetersListBox* this = (MetersListBox*) super; MetersPanel* this = (MetersPanel*) super;
int selected = ListBox_getSelectedIndex(super); int selected = Panel_getSelectedIndex(super);
HandlerResult result = IGNORED; HandlerResult result = IGNORED;
switch(ch) { switch(ch) {
@ -62,7 +62,7 @@ HandlerResult MetersListBox_EventHandler(ListBox* super, int ch) {
int mode = meter->mode + 1; int mode = meter->mode + 1;
if (mode == LAST_METERMODE) mode = 1; if (mode == LAST_METERMODE) mode = 1;
Meter_setMode(meter, mode); Meter_setMode(meter, mode);
ListBox_set(super, selected, (Object*) Meter_toListItem(meter)); Panel_set(super, selected, (Object*) Meter_toListItem(meter));
result = HANDLED; result = HANDLED;
break; break;
} }
@ -71,7 +71,7 @@ HandlerResult MetersListBox_EventHandler(ListBox* super, int ch) {
case '-': case '-':
{ {
Vector_moveUp(this->meters, selected); Vector_moveUp(this->meters, selected);
ListBox_moveSelectedUp(super); Panel_moveSelectedUp(super);
result = HANDLED; result = HANDLED;
break; break;
} }
@ -80,7 +80,7 @@ HandlerResult MetersListBox_EventHandler(ListBox* super, int ch) {
case '+': case '+':
{ {
Vector_moveDown(this->meters, selected); Vector_moveDown(this->meters, selected);
ListBox_moveSelectedDown(super); Panel_moveSelectedDown(super);
result = HANDLED; result = HANDLED;
break; break;
} }
@ -89,7 +89,7 @@ HandlerResult MetersListBox_EventHandler(ListBox* super, int ch) {
{ {
if (selected < Vector_size(this->meters)) { if (selected < Vector_size(this->meters)) {
Vector_remove(this->meters, selected); Vector_remove(this->meters, selected);
ListBox_remove(super, selected); Panel_remove(super, selected);
} }
result = HANDLED; result = HANDLED;
break; break;

View File

@ -1,10 +1,10 @@
/* Do not edit this file. It was automatically genarated. */ /* Do not edit this file. It was automatically genarated. */
#ifndef HEADER_MetersListBox #ifndef HEADER_MetersPanel
#define HEADER_MetersListBox #define HEADER_MetersPanel
#include "ListBox.h" #include "Panel.h"
#include "Settings.h" #include "Settings.h"
#include "ScreenManager.h" #include "ScreenManager.h"
@ -12,19 +12,19 @@
#include <assert.h> #include <assert.h>
typedef struct MetersListBox_ { typedef struct MetersPanel_ {
ListBox super; Panel super;
Settings* settings; Settings* settings;
Vector* meters; Vector* meters;
ScreenManager* scr; ScreenManager* scr;
} MetersListBox; } MetersPanel;
MetersListBox* MetersListBox_new(Settings* settings, char* header, Vector* meters, ScreenManager* scr); MetersPanel* MetersPanel_new(Settings* settings, char* header, Vector* meters, ScreenManager* scr);
void MetersListBox_delete(Object* object); void MetersPanel_delete(Object* object);
HandlerResult MetersListBox_EventHandler(ListBox* super, int ch); HandlerResult MetersPanel_EventHandler(Panel* super, int ch);
#endif #endif

View File

@ -1,12 +1,12 @@
/* /*
htop - ListBox.c htop - Panel.c
(C) 2004-2006 Hisham H. Muhammad (C) 2004-2006 Hisham H. Muhammad
Released under the GNU GPL, see the COPYING file Released under the GNU GPL, see the COPYING file
in the source distribution for its full text. in the source distribution for its full text.
*/ */
#include "Object.h" #include "Object.h"
#include "ListBox.h" #include "Panel.h"
#include "Vector.h" #include "Vector.h"
#include "CRT.h" #include "CRT.h"
#include "RichString.h" #include "RichString.h"
@ -22,7 +22,7 @@ in the source distribution for its full text.
/*{ /*{
typedef struct ListBox_ ListBox; typedef struct Panel_ Panel;
typedef enum HandlerResult_ { typedef enum HandlerResult_ {
HANDLED, HANDLED,
@ -30,9 +30,9 @@ typedef enum HandlerResult_ {
BREAK_LOOP BREAK_LOOP
} HandlerResult; } HandlerResult;
typedef HandlerResult(*ListBox_EventHandler)(ListBox*, int); typedef HandlerResult(*Panel_EventHandler)(Panel*, int);
struct ListBox_ { struct Panel_ {
Object super; Object super;
int x, y, w, h; int x, y, w, h;
WINDOW* window; WINDOW* window;
@ -42,10 +42,10 @@ struct ListBox_ {
int oldSelected; int oldSelected;
bool needsRedraw; bool needsRedraw;
RichString header; RichString header;
ListBox_EventHandler eventHandler; Panel_EventHandler eventHandler;
}; };
extern char* LISTBOX_CLASS; extern char* PANEL_CLASS;
}*/ }*/
@ -57,25 +57,25 @@ extern char* LISTBOX_CLASS;
#endif #endif
/* private property */ /* private property */
char* LISTBOX_CLASS = "ListBox"; char* PANEL_CLASS = "Panel";
ListBox* ListBox_new(int x, int y, int w, int h, char* type, bool owner) { Panel* Panel_new(int x, int y, int w, int h, char* type, bool owner) {
ListBox* this; Panel* this;
this = malloc(sizeof(ListBox)); this = malloc(sizeof(Panel));
ListBox_init(this, x, y, w, h, type, owner); Panel_init(this, x, y, w, h, type, owner);
return this; return this;
} }
void ListBox_delete(Object* cast) { void Panel_delete(Object* cast) {
ListBox* this = (ListBox*)cast; Panel* this = (Panel*)cast;
ListBox_done(this); Panel_done(this);
free(this); free(this);
} }
void ListBox_init(ListBox* this, int x, int y, int w, int h, char* type, bool owner) { void Panel_init(Panel* this, int x, int y, int w, int h, char* type, bool owner) {
Object* super = (Object*) this; Object* super = (Object*) this;
super->class = LISTBOX_CLASS; super->class = PANEL_CLASS;
super->delete = ListBox_delete; super->delete = Panel_delete;
this->x = x; this->x = x;
this->y = y; this->y = y;
this->w = w; this->w = w;
@ -90,13 +90,13 @@ void ListBox_init(ListBox* this, int x, int y, int w, int h, char* type, bool ow
this->header.len = 0; this->header.len = 0;
} }
void ListBox_done(ListBox* this) { void Panel_done(Panel* this) {
assert (this != NULL); assert (this != NULL);
RichString_delete(this->header); RichString_delete(this->header);
Vector_delete(this->items); Vector_delete(this->items);
} }
inline void ListBox_setRichHeader(ListBox* this, RichString header) { inline void Panel_setRichHeader(Panel* this, RichString header) {
assert (this != NULL); assert (this != NULL);
if (this->header.len > 0) { if (this->header.len > 0) {
@ -106,15 +106,15 @@ inline void ListBox_setRichHeader(ListBox* this, RichString header) {
this->needsRedraw = true; this->needsRedraw = true;
} }
inline void ListBox_setHeader(ListBox* this, char* header) { inline void Panel_setHeader(Panel* this, char* header) {
ListBox_setRichHeader(this, RichString_quickString(CRT_colors[PANEL_HEADER_FOCUS], header)); Panel_setRichHeader(this, RichString_quickString(CRT_colors[PANEL_HEADER_FOCUS], header));
} }
void ListBox_setEventHandler(ListBox* this, ListBox_EventHandler eh) { void Panel_setEventHandler(Panel* this, Panel_EventHandler eh) {
this->eventHandler = eh; this->eventHandler = eh;
} }
void ListBox_move(ListBox* this, int x, int y) { void Panel_move(Panel* this, int x, int y) {
assert (this != NULL); assert (this != NULL);
this->x = x; this->x = x;
@ -122,7 +122,7 @@ void ListBox_move(ListBox* this, int x, int y) {
this->needsRedraw = true; this->needsRedraw = true;
} }
void ListBox_resize(ListBox* this, int w, int h) { void Panel_resize(Panel* this, int w, int h) {
assert (this != NULL); assert (this != NULL);
if (this->header.len > 0) if (this->header.len > 0)
@ -132,7 +132,7 @@ void ListBox_resize(ListBox* this, int w, int h) {
this->needsRedraw = true; this->needsRedraw = true;
} }
void ListBox_prune(ListBox* this) { void Panel_prune(Panel* this) {
assert (this != NULL); assert (this != NULL);
Vector_prune(this->items); Vector_prune(this->items);
@ -142,33 +142,33 @@ void ListBox_prune(ListBox* this) {
this->needsRedraw = true; this->needsRedraw = true;
} }
void ListBox_add(ListBox* this, Object* o) { void Panel_add(Panel* this, Object* o) {
assert (this != NULL); assert (this != NULL);
Vector_add(this->items, o); Vector_add(this->items, o);
this->needsRedraw = true; this->needsRedraw = true;
} }
void ListBox_insert(ListBox* this, int i, Object* o) { void Panel_insert(Panel* this, int i, Object* o) {
assert (this != NULL); assert (this != NULL);
Vector_insert(this->items, i, o); Vector_insert(this->items, i, o);
this->needsRedraw = true; this->needsRedraw = true;
} }
void ListBox_set(ListBox* this, int i, Object* o) { void Panel_set(Panel* this, int i, Object* o) {
assert (this != NULL); assert (this != NULL);
Vector_set(this->items, i, o); Vector_set(this->items, i, o);
} }
Object* ListBox_get(ListBox* this, int i) { Object* Panel_get(Panel* this, int i) {
assert (this != NULL); assert (this != NULL);
return Vector_get(this->items, i); return Vector_get(this->items, i);
} }
Object* ListBox_remove(ListBox* this, int i) { Object* Panel_remove(Panel* this, int i) {
assert (this != NULL); assert (this != NULL);
this->needsRedraw = true; this->needsRedraw = true;
@ -178,13 +178,13 @@ Object* ListBox_remove(ListBox* this, int i) {
return removed; return removed;
} }
Object* ListBox_getSelected(ListBox* this) { Object* Panel_getSelected(Panel* this) {
assert (this != NULL); assert (this != NULL);
return Vector_get(this->items, this->selected); return Vector_get(this->items, this->selected);
} }
void ListBox_moveSelectedUp(ListBox* this) { void Panel_moveSelectedUp(Panel* this) {
assert (this != NULL); assert (this != NULL);
Vector_moveUp(this->items, this->selected); Vector_moveUp(this->items, this->selected);
@ -192,7 +192,7 @@ void ListBox_moveSelectedUp(ListBox* this) {
this->selected--; this->selected--;
} }
void ListBox_moveSelectedDown(ListBox* this) { void Panel_moveSelectedDown(Panel* this) {
assert (this != NULL); assert (this != NULL);
Vector_moveDown(this->items, this->selected); Vector_moveDown(this->items, this->selected);
@ -200,26 +200,26 @@ void ListBox_moveSelectedDown(ListBox* this) {
this->selected++; this->selected++;
} }
int ListBox_getSelectedIndex(ListBox* this) { int Panel_getSelectedIndex(Panel* this) {
assert (this != NULL); assert (this != NULL);
return this->selected; return this->selected;
} }
int ListBox_getSize(ListBox* this) { int Panel_getSize(Panel* this) {
assert (this != NULL); assert (this != NULL);
return Vector_size(this->items); return Vector_size(this->items);
} }
void ListBox_setSelected(ListBox* this, int selected) { void Panel_setSelected(Panel* this, int selected) {
assert (this != NULL); assert (this != NULL);
selected = MAX(0, MIN(Vector_size(this->items) - 1, selected)); selected = MAX(0, MIN(Vector_size(this->items) - 1, selected));
this->selected = selected; this->selected = selected;
} }
void ListBox_draw(ListBox* this, bool focus) { void Panel_draw(Panel* this, bool focus) {
assert (this != NULL); assert (this != NULL);
int first, last; int first, last;
@ -311,7 +311,7 @@ void ListBox_draw(ListBox* this, bool focus) {
move(0, 0); move(0, 0);
} }
void ListBox_onKey(ListBox* this, int key) { void Panel_onKey(Panel* this, int key) {
assert (this != NULL); assert (this != NULL);
switch (key) { switch (key) {
case KEY_DOWN: case KEY_DOWN:

101
Panel.h Normal file
View File

@ -0,0 +1,101 @@
/* Do not edit this file. It was automatically genarated. */
#ifndef HEADER_Panel
#define HEADER_Panel
/*
htop
(C) 2004-2006 Hisham H. Muhammad
Released under the GNU GPL, see the COPYING file
in the source distribution for its full text.
*/
#include "Object.h"
#include "Vector.h"
#include "CRT.h"
#include "RichString.h"
#include <math.h>
#include <sys/param.h>
#include <stdbool.h>
#include "debug.h"
#include <assert.h>
#include <curses.h>
//#link curses
typedef struct Panel_ Panel;
typedef enum HandlerResult_ {
HANDLED,
IGNORED,
BREAK_LOOP
} HandlerResult;
typedef HandlerResult(*Panel_EventHandler)(Panel*, int);
struct Panel_ {
Object super;
int x, y, w, h;
WINDOW* window;
Vector* items;
int selected;
int scrollV, scrollH;
int oldSelected;
bool needsRedraw;
RichString header;
Panel_EventHandler eventHandler;
};
extern char* PANEL_CLASS;
Panel* Panel_new(int x, int y, int w, int h, char* type, bool owner);
void Panel_delete(Object* cast);
void Panel_init(Panel* this, int x, int y, int w, int h, char* type, bool owner);
void Panel_done(Panel* this);
void Panel_setEventHandler(Panel* this, Panel_EventHandler eh);
void Panel_setRichHeader(Panel* this, RichString header);
void Panel_setHeader(Panel* this, char* header);
void Panel_move(Panel* this, int x, int y);
void Panel_resize(Panel* this, int w, int h);
void Panel_prune(Panel* this);
void Panel_add(Panel* this, Object* o);
void Panel_insert(Panel* this, int i, Object* o);
void Panel_set(Panel* this, int i, Object* o);
Object* Panel_get(Panel* this, int i);
Object* Panel_remove(Panel* this, int i);
Object* Panel_getSelected(Panel* this);
void Panel_moveSelectedUp(Panel* this);
void Panel_moveSelectedDown(Panel* this);
int Panel_getSelectedIndex(Panel* this);
int Panel_getSize(Panel* this);
void Panel_setSelected(Panel* this, int selected);
void Panel_draw(Panel* this, bool focus);
void Panel_onKey(Panel* this, int key);
#endif

View File

@ -6,7 +6,7 @@ in the source distribution for its full text.
*/ */
#include "ScreenManager.h" #include "ScreenManager.h"
#include "ListBox.h" #include "Panel.h"
#include "Object.h" #include "Object.h"
#include "Vector.h" #include "Vector.h"
#include "FunctionBar.h" #include "FunctionBar.h"
@ -47,7 +47,7 @@ ScreenManager* ScreenManager_new(int x1, int y1, int x2, int y2, Orientation ori
this->y2 = y2; this->y2 = y2;
this->fuBar = NULL; this->fuBar = NULL;
this->orientation = orientation; this->orientation = orientation;
this->items = Vector_new(LISTBOX_CLASS, owner, DEFAULT_SIZE); this->items = Vector_new(PANEL_CLASS, owner, DEFAULT_SIZE);
this->fuBars = Vector_new(FUNCTIONBAR_CLASS, true, DEFAULT_SIZE); this->fuBars = Vector_new(FUNCTIONBAR_CLASS, true, DEFAULT_SIZE);
this->itemCount = 0; this->itemCount = 0;
this->owner = owner; this->owner = owner;
@ -64,19 +64,19 @@ inline int ScreenManager_size(ScreenManager* this) {
return this->itemCount; return this->itemCount;
} }
void ScreenManager_add(ScreenManager* this, ListBox* item, FunctionBar* fuBar, int size) { void ScreenManager_add(ScreenManager* this, Panel* item, FunctionBar* fuBar, int size) {
if (this->orientation == HORIZONTAL) { if (this->orientation == HORIZONTAL) {
int lastX = 0; int lastX = 0;
if (this->itemCount > 0) { if (this->itemCount > 0) {
ListBox* last = (ListBox*) Vector_get(this->items, this->itemCount - 1); Panel* last = (Panel*) Vector_get(this->items, this->itemCount - 1);
lastX = last->x + last->w + 1; lastX = last->x + last->w + 1;
} }
if (size > 0) { if (size > 0) {
ListBox_resize(item, size, LINES-this->y1+this->y2); Panel_resize(item, size, LINES-this->y1+this->y2);
} else { } else {
ListBox_resize(item, COLS-this->x1+this->x2-lastX, LINES-this->y1+this->y2); Panel_resize(item, COLS-this->x1+this->x2-lastX, LINES-this->y1+this->y2);
} }
ListBox_move(item, lastX, this->y1); Panel_move(item, lastX, this->y1);
} }
// TODO: VERTICAL // TODO: VERTICAL
Vector_add(this->items, item); Vector_add(this->items, item);
@ -89,9 +89,9 @@ void ScreenManager_add(ScreenManager* this, ListBox* item, FunctionBar* fuBar, i
this->itemCount++; this->itemCount++;
} }
ListBox* ScreenManager_remove(ScreenManager* this, int index) { Panel* ScreenManager_remove(ScreenManager* this, int index) {
assert(this->itemCount > index); assert(this->itemCount > index);
ListBox* lb = (ListBox*) Vector_remove(this->items, index); Panel* lb = (Panel*) Vector_remove(this->items, index);
Vector_remove(this->fuBars, index); Vector_remove(this->fuBars, index);
this->fuBar = NULL; this->fuBar = NULL;
this->itemCount--; this->itemCount--;
@ -112,21 +112,21 @@ void ScreenManager_resize(ScreenManager* this, int x1, int y1, int x2, int y2) {
int items = this->itemCount; int items = this->itemCount;
int lastX = 0; int lastX = 0;
for (int i = 0; i < items - 1; i++) { for (int i = 0; i < items - 1; i++) {
ListBox* lb = (ListBox*) Vector_get(this->items, i); Panel* lb = (Panel*) Vector_get(this->items, i);
ListBox_resize(lb, lb->w, LINES-y1+y2); Panel_resize(lb, lb->w, LINES-y1+y2);
ListBox_move(lb, lastX, y1); Panel_move(lb, lastX, y1);
lastX = lb->x + lb->w + 1; lastX = lb->x + lb->w + 1;
} }
ListBox* lb = (ListBox*) Vector_get(this->items, items-1); Panel* lb = (Panel*) Vector_get(this->items, items-1);
ListBox_resize(lb, COLS-x1+x2-lastX, LINES-y1+y2); Panel_resize(lb, COLS-x1+x2-lastX, LINES-y1+y2);
ListBox_move(lb, lastX, y1); Panel_move(lb, lastX, y1);
} }
void ScreenManager_run(ScreenManager* this, ListBox** lastFocus, int* lastKey) { void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) {
bool quit = false; bool quit = false;
int focus = 0; int focus = 0;
ListBox* lbFocus = (ListBox*) Vector_get(this->items, focus); Panel* lbFocus = (Panel*) Vector_get(this->items, focus);
if (this->fuBar) if (this->fuBar)
FunctionBar_draw(this->fuBar, NULL); FunctionBar_draw(this->fuBar, NULL);
@ -134,8 +134,8 @@ void ScreenManager_run(ScreenManager* this, ListBox** lastFocus, int* lastKey) {
while (!quit) { while (!quit) {
int items = this->itemCount; int items = this->itemCount;
for (int i = 0; i < items; i++) { for (int i = 0; i < items; i++) {
ListBox* lb = (ListBox*) Vector_get(this->items, i); Panel* lb = (Panel*) Vector_get(this->items, i);
ListBox_draw(lb, i == focus); Panel_draw(lb, i == focus);
if (i < items) { if (i < items) {
if (this->orientation == HORIZONTAL) { if (this->orientation == HORIZONTAL) {
mvvline(lb->y, lb->x+lb->w, ' ', lb->h+1); mvvline(lb->y, lb->x+lb->w, ' ', lb->h+1);
@ -159,12 +159,12 @@ void ScreenManager_run(ScreenManager* this, ListBox** lastFocus, int* lastKey) {
ch = FunctionBar_synthesizeEvent(this->fuBar, mevent.x); ch = FunctionBar_synthesizeEvent(this->fuBar, mevent.x);
} else { } else {
for (int i = 0; i < this->itemCount; i++) { for (int i = 0; i < this->itemCount; i++) {
ListBox* lb = (ListBox*) Vector_get(this->items, i); Panel* lb = (Panel*) Vector_get(this->items, i);
if (mevent.x > lb->x && mevent.x <= lb->x+lb->w && if (mevent.x > lb->x && mevent.x <= lb->x+lb->w &&
mevent.y > lb->y && mevent.y <= lb->y+lb->h) { mevent.y > lb->y && mevent.y <= lb->y+lb->h) {
focus = i; focus = i;
lbFocus = lb; lbFocus = lb;
ListBox_setSelected(lb, mevent.y - lb->y + lb->scrollV - 1); Panel_setSelected(lb, mevent.y - lb->y + lb->scrollV - 1);
loop = true; loop = true;
break; break;
} }
@ -196,8 +196,8 @@ void ScreenManager_run(ScreenManager* this, ListBox** lastFocus, int* lastKey) {
tryLeft: tryLeft:
if (focus > 0) if (focus > 0)
focus--; focus--;
lbFocus = (ListBox*) Vector_get(this->items, focus); lbFocus = (Panel*) Vector_get(this->items, focus);
if (ListBox_getSize(lbFocus) == 0 && focus > 0) if (Panel_getSize(lbFocus) == 0 && focus > 0)
goto tryLeft; goto tryLeft;
break; break;
case KEY_RIGHT: case KEY_RIGHT:
@ -205,8 +205,8 @@ void ScreenManager_run(ScreenManager* this, ListBox** lastFocus, int* lastKey) {
tryRight: tryRight:
if (focus < this->itemCount - 1) if (focus < this->itemCount - 1)
focus++; focus++;
lbFocus = (ListBox*) Vector_get(this->items, focus); lbFocus = (Panel*) Vector_get(this->items, focus);
if (ListBox_getSize(lbFocus) == 0 && focus < this->itemCount - 1) if (Panel_getSize(lbFocus) == 0 && focus < this->itemCount - 1)
goto tryRight; goto tryRight;
break; break;
case KEY_F(10): case KEY_F(10):
@ -215,7 +215,7 @@ void ScreenManager_run(ScreenManager* this, ListBox** lastFocus, int* lastKey) {
quit = true; quit = true;
continue; continue;
default: default:
ListBox_onKey(lbFocus, ch); Panel_onKey(lbFocus, ch);
break; break;
} }
} }

View File

@ -9,7 +9,7 @@ Released under the GNU GPL, see the COPYING file
in the source distribution for its full text. in the source distribution for its full text.
*/ */
#include "ListBox.h" #include "Panel.h"
#include "Object.h" #include "Object.h"
#include "Vector.h" #include "Vector.h"
#include "FunctionBar.h" #include "FunctionBar.h"
@ -45,14 +45,14 @@ void ScreenManager_delete(ScreenManager* this);
inline int ScreenManager_size(ScreenManager* this); inline int ScreenManager_size(ScreenManager* this);
void ScreenManager_add(ScreenManager* this, ListBox* item, FunctionBar* fuBar, int size); void ScreenManager_add(ScreenManager* this, Panel* item, FunctionBar* fuBar, int size);
ListBox* ScreenManager_remove(ScreenManager* this, int index); Panel* ScreenManager_remove(ScreenManager* this, int index);
void ScreenManager_setFunctionBar(ScreenManager* this, FunctionBar* fuBar); void ScreenManager_setFunctionBar(ScreenManager* this, FunctionBar* fuBar);
void ScreenManager_resize(ScreenManager* this, int x1, int y1, int x2, int y2); void ScreenManager_resize(ScreenManager* this, int x1, int y1, int x2, int y2);
void ScreenManager_run(ScreenManager* this, ListBox** lastFocus, int* lastKey); void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey);
#endif #endif

View File

@ -1,6 +1,6 @@
#include "SignalsListBox.h" #include "SignalsPanel.h"
#include "ListBox.h" #include "Panel.h"
#include "SignalItem.h" #include "SignalItem.h"
#include "RichString.h" #include "RichString.h"
@ -11,56 +11,56 @@
/*{ /*{
typedef struct SignalsListBox_ { typedef struct SignalsPanel_ {
ListBox super; Panel super;
int state; int state;
Signal** signals; Signal** signals;
} SignalsListBox; } SignalsPanel;
}*/ }*/
SignalsListBox* SignalsListBox_new(int x, int y, int w, int h) { SignalsPanel* SignalsPanel_new(int x, int y, int w, int h) {
SignalsListBox* this = (SignalsListBox*) malloc(sizeof(SignalsListBox)); SignalsPanel* this = (SignalsPanel*) malloc(sizeof(SignalsPanel));
ListBox* super = (ListBox*) this; Panel* super = (Panel*) this;
ListBox_init(super, x, y, w, h, SIGNAL_CLASS, true); Panel_init(super, x, y, w, h, SIGNAL_CLASS, true);
((Object*)this)->delete = SignalsListBox_delete; ((Object*)this)->delete = SignalsPanel_delete;
this->signals = Signal_getSignalTable(); this->signals = Signal_getSignalTable();
super->eventHandler = SignalsListBox_EventHandler; super->eventHandler = SignalsPanel_EventHandler;
int sigCount = Signal_getSignalCount(); int sigCount = Signal_getSignalCount();
for(int i = 0; i < sigCount; i++) for(int i = 0; i < sigCount; i++)
ListBox_set(super, i, (Object*) this->signals[i]); Panel_set(super, i, (Object*) this->signals[i]);
SignalsListBox_reset(this); SignalsPanel_reset(this);
return this; return this;
} }
void SignalsListBox_delete(Object* object) { void SignalsPanel_delete(Object* object) {
ListBox* super = (ListBox*) object; Panel* super = (Panel*) object;
SignalsListBox* this = (SignalsListBox*) object; SignalsPanel* this = (SignalsPanel*) object;
ListBox_done(super); Panel_done(super);
free(this->signals); free(this->signals);
free(this); free(this);
} }
void SignalsListBox_reset(SignalsListBox* this) { void SignalsPanel_reset(SignalsPanel* this) {
ListBox* super = (ListBox*) this; Panel* super = (Panel*) this;
ListBox_setHeader(super, "Send signal:"); Panel_setHeader(super, "Send signal:");
ListBox_setSelected(super, 16); // 16th item is SIGTERM Panel_setSelected(super, 16); // 16th item is SIGTERM
this->state = 0; this->state = 0;
} }
HandlerResult SignalsListBox_EventHandler(ListBox* super, int ch) { HandlerResult SignalsPanel_EventHandler(Panel* super, int ch) {
SignalsListBox* this = (SignalsListBox*) super; SignalsPanel* this = (SignalsPanel*) super;
int size = ListBox_getSize(super); int size = Panel_getSize(super);
if (ch <= 255 && isdigit(ch)) { if (ch <= 255 && isdigit(ch)) {
int signal = ch-48 + this->state; int signal = ch-48 + this->state;
for (int i = 0; i < size; i++) for (int i = 0; i < size; i++)
if (((Signal*) ListBox_get(super, i))->number == signal) { if (((Signal*) Panel_get(super, i))->number == signal) {
ListBox_setSelected(super, i); Panel_setSelected(super, i);
break; break;
} }
this->state = signal * 10; this->state = signal * 10;

View File

@ -1,9 +1,9 @@
/* Do not edit this file. It was automatically genarated. */ /* Do not edit this file. It was automatically genarated. */
#ifndef HEADER_SignalsListBox #ifndef HEADER_SignalsPanel
#define HEADER_SignalsListBox #define HEADER_SignalsPanel
#include "ListBox.h" #include "Panel.h"
#include "SignalItem.h" #include "SignalItem.h"
#include "RichString.h" #include "RichString.h"
@ -13,20 +13,20 @@
#include <ctype.h> #include <ctype.h>
typedef struct SignalsListBox_ { typedef struct SignalsPanel_ {
ListBox super; Panel super;
int state; int state;
Signal** signals; Signal** signals;
} SignalsListBox; } SignalsPanel;
SignalsListBox* SignalsListBox_new(int x, int y, int w, int h); SignalsPanel* SignalsPanel_new(int x, int y, int w, int h);
void SignalsListBox_delete(Object* object); void SignalsPanel_delete(Object* object);
void SignalsListBox_reset(SignalsListBox* this); void SignalsPanel_reset(SignalsPanel* this);
HandlerResult SignalsListBox_EventHandler(ListBox* super, int ch); HandlerResult SignalsPanel_EventHandler(Panel* super, int ch);
#endif #endif

View File

@ -18,14 +18,14 @@ in the source distribution for its full text.
#include "ProcessList.h" #include "ProcessList.h"
#include "Process.h" #include "Process.h"
#include "ListItem.h" #include "ListItem.h"
#include "ListBox.h" #include "Panel.h"
#include "FunctionBar.h" #include "FunctionBar.h"
/*{ /*{
typedef struct TraceScreen_ { typedef struct TraceScreen_ {
Process* process; Process* process;
ListBox* display; Panel* display;
FunctionBar* bar; FunctionBar* bar;
bool tracing; bool tracing;
} TraceScreen; } TraceScreen;
@ -44,14 +44,14 @@ static int tbEvents[3] = {KEY_F(4), KEY_F(5), 27};
TraceScreen* TraceScreen_new(Process* process) { TraceScreen* TraceScreen_new(Process* process) {
TraceScreen* this = (TraceScreen*) malloc(sizeof(TraceScreen)); TraceScreen* this = (TraceScreen*) malloc(sizeof(TraceScreen));
this->process = process; this->process = process;
this->display = ListBox_new(0, 1, COLS, LINES-2, LISTITEM_CLASS, true); this->display = Panel_new(0, 1, COLS, LINES-2, LISTITEM_CLASS, true);
this->bar = FunctionBar_new(3, tbFunctions, tbKeys, tbEvents); this->bar = FunctionBar_new(3, tbFunctions, tbKeys, tbEvents);
this->tracing = true; this->tracing = true;
return this; return this;
} }
void TraceScreen_delete(TraceScreen* this) { void TraceScreen_delete(TraceScreen* this) {
ListBox_delete((Object*)this->display); Panel_delete((Object*)this->display);
FunctionBar_delete((Object*)this->bar); FunctionBar_delete((Object*)this->bar);
free(this); free(this);
} }
@ -81,7 +81,7 @@ void TraceScreen_run(TraceScreen* this) {
} }
fcntl(fdpair[0], F_SETFL, O_NONBLOCK); fcntl(fdpair[0], F_SETFL, O_NONBLOCK);
FILE* strace = fdopen(fdpair[0], "r"); FILE* strace = fdopen(fdpair[0], "r");
ListBox* lb = this->display; Panel* lb = this->display;
int fd_strace = fileno(strace); int fd_strace = fileno(strace);
TraceScreen_draw(this); TraceScreen_draw(this);
CRT_disableDelay(); CRT_disableDelay();
@ -105,23 +105,23 @@ void TraceScreen_run(TraceScreen* this) {
if (buffer[i] == '\n') { if (buffer[i] == '\n') {
buffer[i] = '\0'; buffer[i] = '\0';
if (contLine) { if (contLine) {
ListItem_append((ListItem*)ListBox_get(lb, ListItem_append((ListItem*)Panel_get(lb,
ListBox_getSize(lb)-1), line); Panel_getSize(lb)-1), line);
contLine = false; contLine = false;
} else { } else {
ListBox_add(lb, (Object*) ListItem_new(line, 0)); Panel_add(lb, (Object*) ListItem_new(line, 0));
} }
line = buffer+i+1; line = buffer+i+1;
} }
} }
if (line < buffer+nread) { if (line < buffer+nread) {
ListBox_add(lb, (Object*) ListItem_new(line, 0)); Panel_add(lb, (Object*) ListItem_new(line, 0));
buffer[nread] = '\0'; buffer[nread] = '\0';
contLine = true; contLine = true;
} }
if (follow) if (follow)
ListBox_setSelected(lb, ListBox_getSize(lb)-1); Panel_setSelected(lb, Panel_getSize(lb)-1);
ListBox_draw(lb, true); Panel_draw(lb, true);
} }
int ch = getch(); int ch = getch();
if (ch == KEY_MOUSE) { if (ch == KEY_MOUSE) {
@ -129,7 +129,7 @@ void TraceScreen_run(TraceScreen* this) {
int ok = getmouse(&mevent); int ok = getmouse(&mevent);
if (ok == OK) if (ok == OK)
if (mevent.y >= lb->y && mevent.y < LINES - 1) { if (mevent.y >= lb->y && mevent.y < LINES - 1) {
ListBox_setSelected(lb, mevent.y - lb->y + lb->scrollV); Panel_setSelected(lb, mevent.y - lb->y + lb->scrollV);
follow = false; follow = false;
ch = 0; ch = 0;
} if (mevent.y == LINES - 1) } if (mevent.y == LINES - 1)
@ -147,21 +147,21 @@ void TraceScreen_run(TraceScreen* this) {
case KEY_F(4): case KEY_F(4):
follow = !follow; follow = !follow;
if (follow) if (follow)
ListBox_setSelected(lb, ListBox_getSize(lb)-1); Panel_setSelected(lb, Panel_getSize(lb)-1);
break; break;
case 'q': case 'q':
case 27: case 27:
looping = false; looping = false;
break; break;
case KEY_RESIZE: case KEY_RESIZE:
ListBox_resize(lb, COLS, LINES-2); Panel_resize(lb, COLS, LINES-2);
TraceScreen_draw(this); TraceScreen_draw(this);
break; break;
default: default:
follow = false; follow = false;
ListBox_onKey(lb, ch); Panel_onKey(lb, ch);
} }
ListBox_draw(lb, true); Panel_draw(lb, true);
} }
kill(child, SIGTERM); kill(child, SIGTERM);
waitpid(child, NULL, 0); waitpid(child, NULL, 0);

View File

@ -15,12 +15,12 @@ in the source distribution for its full text.
#include <fcntl.h> #include <fcntl.h>
#include "ProcessList.h" #include "ProcessList.h"
#include "ListBox.h" #include "Panel.h"
#include "FunctionBar.h" #include "FunctionBar.h"
typedef struct TraceScreen_ { typedef struct TraceScreen_ {
Process* process; Process* process;
ListBox* display; Panel* display;
FunctionBar* bar; FunctionBar* bar;
bool tracing; bool tracing;
} TraceScreen; } TraceScreen;

128
htop.c
View File

@ -14,7 +14,7 @@ in the source distribution for its full text.
#include "ProcessList.h" #include "ProcessList.h"
#include "CRT.h" #include "CRT.h"
#include "ListBox.h" #include "Panel.h"
#include "UsersTable.h" #include "UsersTable.h"
#include "SignalItem.h" #include "SignalItem.h"
#include "RichString.h" #include "RichString.h"
@ -22,8 +22,8 @@ in the source distribution for its full text.
#include "ScreenManager.h" #include "ScreenManager.h"
#include "FunctionBar.h" #include "FunctionBar.h"
#include "ListItem.h" #include "ListItem.h"
#include "CategoriesListBox.h" #include "CategoriesPanel.h"
#include "SignalsListBox.h" #include "SignalsPanel.h"
#include "TraceScreen.h" #include "TraceScreen.h"
#include "config.h" #include "config.h"
@ -126,62 +126,62 @@ void showHelp() {
static void Setup_run(Settings* settings, int headerHeight) { static void Setup_run(Settings* settings, int headerHeight) {
ScreenManager* scr = ScreenManager_new(0, headerHeight, 0, -1, HORIZONTAL, true); ScreenManager* scr = ScreenManager_new(0, headerHeight, 0, -1, HORIZONTAL, true);
CategoriesListBox* lbCategories = CategoriesListBox_new(settings, scr); CategoriesPanel* lbCategories = CategoriesPanel_new(settings, scr);
ScreenManager_add(scr, (ListBox*) lbCategories, NULL, 16); ScreenManager_add(scr, (Panel*) lbCategories, NULL, 16);
CategoriesListBox_makeMetersPage(lbCategories); CategoriesPanel_makeMetersPage(lbCategories);
ListBox* lbFocus; Panel* lbFocus;
int ch; int ch;
ScreenManager_run(scr, &lbFocus, &ch); ScreenManager_run(scr, &lbFocus, &ch);
ScreenManager_delete(scr); ScreenManager_delete(scr);
} }
static bool changePriority(ListBox* lb, int delta) { static bool changePriority(Panel* lb, int delta) {
bool anyTagged = false; bool anyTagged = false;
for (int i = 0; i < ListBox_getSize(lb); i++) { for (int i = 0; i < Panel_getSize(lb); i++) {
Process* p = (Process*) ListBox_get(lb, i); Process* p = (Process*) Panel_get(lb, i);
if (p->tag) { if (p->tag) {
Process_setPriority(p, p->nice + delta); Process_setPriority(p, p->nice + delta);
anyTagged = true; anyTagged = true;
} }
} }
if (!anyTagged) { if (!anyTagged) {
Process* p = (Process*) ListBox_getSelected(lb); Process* p = (Process*) Panel_getSelected(lb);
Process_setPriority(p, p->nice + delta); Process_setPriority(p, p->nice + delta);
} }
return anyTagged; return anyTagged;
} }
static HandlerResult pickWithEnter(ListBox* lb, int ch) { static HandlerResult pickWithEnter(Panel* lb, int ch) {
if (ch == 13) if (ch == 13)
return BREAK_LOOP; return BREAK_LOOP;
return IGNORED; return IGNORED;
} }
static Object* pickFromList(ListBox* lb, ListBox* list, int x, int y, char** keyLabels, FunctionBar* prevBar) { static Object* pickFromList(Panel* lb, Panel* list, int x, int y, char** keyLabels, FunctionBar* prevBar) {
char* fuKeys[2] = {"Enter", "Esc"}; char* fuKeys[2] = {"Enter", "Esc"};
int fuEvents[2] = {13, 27}; int fuEvents[2] = {13, 27};
if (!lb->eventHandler) if (!lb->eventHandler)
ListBox_setEventHandler(list, pickWithEnter); Panel_setEventHandler(list, pickWithEnter);
ScreenManager* scr = ScreenManager_new(0, y, 0, -1, HORIZONTAL, false); ScreenManager* scr = ScreenManager_new(0, y, 0, -1, HORIZONTAL, false);
ScreenManager_add(scr, list, FunctionBar_new(2, keyLabels, fuKeys, fuEvents), x - 1); ScreenManager_add(scr, list, FunctionBar_new(2, keyLabels, fuKeys, fuEvents), x - 1);
ScreenManager_add(scr, lb, NULL, -1); ScreenManager_add(scr, lb, NULL, -1);
ListBox* lbFocus; Panel* lbFocus;
int ch; int ch;
ScreenManager_run(scr, &lbFocus, &ch); ScreenManager_run(scr, &lbFocus, &ch);
ScreenManager_delete(scr); ScreenManager_delete(scr);
ListBox_move(lb, 0, y); Panel_move(lb, 0, y);
ListBox_resize(lb, COLS, LINES-y-1); Panel_resize(lb, COLS, LINES-y-1);
FunctionBar_draw(prevBar, NULL); FunctionBar_draw(prevBar, NULL);
if (lbFocus == list && ch == 13) { if (lbFocus == list && ch == 13) {
return ListBox_getSelected(list); return Panel_getSelected(list);
} }
return NULL; return NULL;
} }
void addUserToList(int key, void* userCast, void* lbCast) { void addUserToList(int key, void* userCast, void* lbCast) {
char* user = (char*) userCast; char* user = (char*) userCast;
ListBox* lb = (ListBox*) lbCast; Panel* lb = (Panel*) lbCast;
ListBox_add(lb, (Object*) ListItem_new(user, key)); Panel_add(lb, (Object*) ListItem_new(user, key));
} }
void setUserOnly(const char* userName, bool* userOnly, uid_t* userId) { void setUserOnly(const char* userName, bool* userOnly, uid_t* userId) {
@ -219,14 +219,14 @@ int main(int argc, char** argv) {
exit(1); exit(1);
} }
ListBox* lb; Panel* lb;
int quit = 0; int quit = 0;
int refreshTimeout = 0; int refreshTimeout = 0;
int resetRefreshTimeout = 5; int resetRefreshTimeout = 5;
bool doRefresh = true; bool doRefresh = true;
Settings* settings; Settings* settings;
ListBox* lbk = NULL; Panel* lbk = NULL;
char incSearchBuffer[INCSEARCH_MAX]; char incSearchBuffer[INCSEARCH_MAX];
int incSearchIndex = 0; int incSearchIndex = 0;
@ -248,8 +248,8 @@ int main(int argc, char** argv) {
CRT_init(settings->delay, settings->colorScheme); CRT_init(settings->delay, settings->colorScheme);
lb = ListBox_new(0, headerHeight, COLS, LINES - headerHeight - 2, PROCESS_CLASS, false); lb = Panel_new(0, headerHeight, COLS, LINES - headerHeight - 2, PROCESS_CLASS, false);
ListBox_setRichHeader(lb, ProcessList_printHeader(pl)); Panel_setRichHeader(lb, ProcessList_printHeader(pl));
char* searchFunctions[3] = {"Next ", "Exit ", " Search: "}; char* searchFunctions[3] = {"Next ", "Exit ", " Search: "};
char* searchKeys[3] = {"F3", "Esc", " "}; char* searchKeys[3] = {"F3", "Esc", " "};
@ -285,7 +285,7 @@ int main(int argc, char** argv) {
if (doRefresh) { if (doRefresh) {
incSearchIndex = 0; incSearchIndex = 0;
incSearchBuffer[0] = 0; incSearchBuffer[0] = 0;
int currPos = ListBox_getSelectedIndex(lb); int currPos = Panel_getSelectedIndex(lb);
int currPid = 0; int currPid = 0;
int currScrollV = lb->scrollV; int currScrollV = lb->scrollV;
if (follow) if (follow)
@ -296,15 +296,15 @@ int main(int argc, char** argv) {
ProcessList_sort(pl); ProcessList_sort(pl);
refreshTimeout = 1; refreshTimeout = 1;
} }
ListBox_prune(lb); Panel_prune(lb);
int size = ProcessList_size(pl); int size = ProcessList_size(pl);
int lbi = 0; int lbi = 0;
for (int i = 0; i < size; i++) { for (int i = 0; i < size; i++) {
Process* p = ProcessList_get(pl, i); Process* p = ProcessList_get(pl, i);
if (!userOnly || (p->st_uid == userId)) { if (!userOnly || (p->st_uid == userId)) {
ListBox_set(lb, lbi, (Object*)p); Panel_set(lb, lbi, (Object*)p);
if ((!follow && lbi == currPos) || (follow && p->pid == currPid)) { if ((!follow && lbi == currPos) || (follow && p->pid == currPid)) {
ListBox_setSelected(lb, lbi); Panel_setSelected(lb, lbi);
lb->scrollV = currScrollV; lb->scrollV = currScrollV;
} }
lbi++; lbi++;
@ -315,7 +315,7 @@ int main(int argc, char** argv) {
Header_draw(header); Header_draw(header);
ListBox_draw(lb, true); Panel_draw(lb, true);
int prev = ch; int prev = ch;
ch = getch(); ch = getch();
@ -334,7 +334,7 @@ int main(int argc, char** argv) {
if (incSearchMode) { if (incSearchMode) {
doRefresh = false; doRefresh = false;
if (ch == KEY_F(3)) { if (ch == KEY_F(3)) {
int here = ListBox_getSelectedIndex(lb); int here = Panel_getSelectedIndex(lb);
int size = ProcessList_size(pl); int size = ProcessList_size(pl);
int i = here+1; int i = here+1;
while (i != here) { while (i != here) {
@ -342,7 +342,7 @@ int main(int argc, char** argv) {
i = 0; i = 0;
Process* p = ProcessList_get(pl, i); Process* p = ProcessList_get(pl, i);
if (String_contains_i(p->comm, incSearchBuffer)) { if (String_contains_i(p->comm, incSearchBuffer)) {
ListBox_setSelected(lb, i); Panel_setSelected(lb, i);
break; break;
} }
i++; i++;
@ -367,7 +367,7 @@ int main(int argc, char** argv) {
for (int i = 0; i < ProcessList_size(pl); i++) { for (int i = 0; i < ProcessList_size(pl); i++) {
Process* p = ProcessList_get(pl, i); Process* p = ProcessList_get(pl, i);
if (String_contains_i(p->comm, incSearchBuffer)) { if (String_contains_i(p->comm, incSearchBuffer)) {
ListBox_setSelected(lb, i); Panel_setSelected(lb, i);
found = true; found = true;
break; break;
} }
@ -381,8 +381,8 @@ int main(int argc, char** argv) {
} }
if (isdigit((char)ch)) { if (isdigit((char)ch)) {
int pid = ch-48 + acc; int pid = ch-48 + acc;
for (int i = 0; i < ProcessList_size(pl) && ((Process*) ListBox_getSelected(lb))->pid != pid; i++) for (int i = 0; i < ProcessList_size(pl) && ((Process*) Panel_getSelected(lb))->pid != pid; i++)
ListBox_setSelected(lb, i); Panel_setSelected(lb, i);
acc = pid * 10; acc = pid * 10;
if (acc > 100000) if (acc > 100000)
acc = 0; acc = 0;
@ -396,7 +396,7 @@ int main(int argc, char** argv) {
int ok = getmouse(&mevent); int ok = getmouse(&mevent);
if (ok == OK) { if (ok == OK) {
if (mevent.y >= lb->y + 1 && mevent.y < LINES - 1) { if (mevent.y >= lb->y + 1 && mevent.y < LINES - 1) {
ListBox_setSelected(lb, mevent.y - lb->y + lb->scrollV - 1); Panel_setSelected(lb, mevent.y - lb->y + lb->scrollV - 1);
doRefresh = false; doRefresh = false;
refreshTimeout = resetRefreshTimeout; refreshTimeout = resetRefreshTimeout;
follow = true; follow = true;
@ -413,7 +413,7 @@ int main(int argc, char** argv) {
switch (ch) { switch (ch) {
case KEY_RESIZE: case KEY_RESIZE:
ListBox_resize(lb, COLS, LINES-headerHeight-1); Panel_resize(lb, COLS, LINES-headerHeight-1);
if (incSearchMode) if (incSearchMode)
FunctionBar_draw(searchBar, incSearchBuffer); FunctionBar_draw(searchBar, incSearchBuffer);
else else
@ -425,7 +425,7 @@ int main(int argc, char** argv) {
pl->sortKey = PERCENT_MEM; pl->sortKey = PERCENT_MEM;
pl->treeView = false; pl->treeView = false;
settings->changed = true; settings->changed = true;
ListBox_setRichHeader(lb, ProcessList_printHeader(pl)); Panel_setRichHeader(lb, ProcessList_printHeader(pl));
break; break;
} }
case 'T': case 'T':
@ -434,13 +434,13 @@ int main(int argc, char** argv) {
pl->sortKey = TIME; pl->sortKey = TIME;
pl->treeView = false; pl->treeView = false;
settings->changed = true; settings->changed = true;
ListBox_setRichHeader(lb, ProcessList_printHeader(pl)); Panel_setRichHeader(lb, ProcessList_printHeader(pl));
break; break;
} }
case 'U': case 'U':
{ {
for (int i = 0; i < ListBox_getSize(lb); i++) { for (int i = 0; i < Panel_getSize(lb); i++) {
Process* p = (Process*) ListBox_get(lb, i); Process* p = (Process*) Panel_get(lb, i);
p->tag = false; p->tag = false;
} }
doRefresh = true; doRefresh = true;
@ -452,7 +452,7 @@ int main(int argc, char** argv) {
pl->sortKey = PERCENT_CPU; pl->sortKey = PERCENT_CPU;
pl->treeView = false; pl->treeView = false;
settings->changed = true; settings->changed = true;
ListBox_setRichHeader(lb, ProcessList_printHeader(pl)); Panel_setRichHeader(lb, ProcessList_printHeader(pl));
break; break;
} }
case KEY_F(1): case KEY_F(1):
@ -472,14 +472,14 @@ int main(int argc, char** argv) {
} }
case ' ': case ' ':
{ {
Process* p = (Process*) ListBox_getSelected(lb); Process* p = (Process*) Panel_getSelected(lb);
Process_toggleTag(p); Process_toggleTag(p);
ListBox_onKey(lb, KEY_DOWN); Panel_onKey(lb, KEY_DOWN);
break; break;
} }
case 's': case 's':
{ {
TraceScreen* ts = TraceScreen_new((Process*) ListBox_getSelected(lb)); TraceScreen* ts = TraceScreen_new((Process*) Panel_getSelected(lb));
TraceScreen_run(ts); TraceScreen_run(ts);
TraceScreen_delete(ts); TraceScreen_delete(ts);
clear(); clear();
@ -494,10 +494,10 @@ int main(int argc, char** argv) {
{ {
Setup_run(settings, headerHeight); Setup_run(settings, headerHeight);
// TODO: shouldn't need this, colors should be dynamic // TODO: shouldn't need this, colors should be dynamic
ListBox_setRichHeader(lb, ProcessList_printHeader(pl)); Panel_setRichHeader(lb, ProcessList_printHeader(pl));
headerHeight = Header_calculateHeight(header); headerHeight = Header_calculateHeight(header);
ListBox_move(lb, 0, headerHeight); Panel_move(lb, 0, headerHeight);
ListBox_resize(lb, COLS, LINES-headerHeight-1); Panel_resize(lb, COLS, LINES-headerHeight-1);
FunctionBar_draw(defaultBar, NULL); FunctionBar_draw(defaultBar, NULL);
refreshTimeout = 0; refreshTimeout = 0;
break; break;
@ -509,12 +509,12 @@ int main(int argc, char** argv) {
} }
case 'u': case 'u':
{ {
ListBox* lbu = ListBox_new(0, 0, 0, 0, LISTITEM_CLASS, true); Panel* lbu = Panel_new(0, 0, 0, 0, LISTITEM_CLASS, true);
ListBox_setHeader(lbu, "Show processes of:"); Panel_setHeader(lbu, "Show processes of:");
UsersTable_foreach(ut, addUserToList, lbu); UsersTable_foreach(ut, addUserToList, lbu);
Vector_sort(lbu->items); Vector_sort(lbu->items);
ListItem* allUsers = ListItem_new("All users", -1); ListItem* allUsers = ListItem_new("All users", -1);
ListBox_insert(lbu, 0, (Object*) allUsers); Panel_insert(lbu, 0, (Object*) allUsers);
char* fuFunctions[2] = {"Show ", "Cancel "}; char* fuFunctions[2] = {"Show ", "Cancel "};
ListItem* picked = (ListItem*) pickFromList(lb, lbu, 20, headerHeight, fuFunctions, defaultBar); ListItem* picked = (ListItem*) pickFromList(lb, lbu, 20, headerHeight, fuFunctions, defaultBar);
if (picked) { if (picked) {
@ -531,19 +531,19 @@ int main(int argc, char** argv) {
case 'k': case 'k':
{ {
if (!lbk) { if (!lbk) {
lbk = (ListBox*) SignalsListBox_new(0, 0, 0, 0); lbk = (Panel*) SignalsPanel_new(0, 0, 0, 0);
} }
SignalsListBox_reset((SignalsListBox*) lbk); SignalsPanel_reset((SignalsPanel*) lbk);
char* fuFunctions[2] = {"Send ", "Cancel "}; char* fuFunctions[2] = {"Send ", "Cancel "};
Signal* signal = (Signal*) pickFromList(lb, lbk, 15, headerHeight, fuFunctions, defaultBar); Signal* signal = (Signal*) pickFromList(lb, lbk, 15, headerHeight, fuFunctions, defaultBar);
if (signal) { if (signal) {
if (signal->number != 0) { if (signal->number != 0) {
ListBox_setHeader(lb, "Sending..."); Panel_setHeader(lb, "Sending...");
ListBox_draw(lb, true); Panel_draw(lb, true);
refresh(); refresh();
bool anyTagged = false; bool anyTagged = false;
for (int i = 0; i < ListBox_getSize(lb); i++) { for (int i = 0; i < Panel_getSize(lb); i++) {
Process* p = (Process*) ListBox_get(lb, i); Process* p = (Process*) Panel_get(lb, i);
if (p->tag) { if (p->tag) {
Process_sendSignal(p, signal->number); Process_sendSignal(p, signal->number);
Process_toggleTag(p); Process_toggleTag(p);
@ -551,13 +551,13 @@ int main(int argc, char** argv) {
} }
} }
if (!anyTagged) { if (!anyTagged) {
Process* p = (Process*) ListBox_getSelected(lb); Process* p = (Process*) Panel_getSelected(lb);
Process_sendSignal(p, signal->number); Process_sendSignal(p, signal->number);
} }
napms(500); napms(500);
} }
} }
ListBox_setRichHeader(lb, ProcessList_printHeader(pl)); Panel_setRichHeader(lb, ProcessList_printHeader(pl));
refreshTimeout = 0; refreshTimeout = 0;
break; break;
} }
@ -572,15 +572,15 @@ int main(int argc, char** argv) {
case '.': case '.':
case KEY_F(6): case KEY_F(6):
{ {
ListBox* lbf = ListBox_new(0,0,0,0,LISTITEM_CLASS,true); Panel* lbf = Panel_new(0,0,0,0,LISTITEM_CLASS,true);
ListBox_setHeader(lbf, "Sort by"); Panel_setHeader(lbf, "Sort by");
char* fuFunctions[2] = {"Sort ", "Cancel "}; char* fuFunctions[2] = {"Sort ", "Cancel "};
ProcessField* fields = pl->fields; ProcessField* fields = pl->fields;
for (int i = 0; fields[i]; i++) { for (int i = 0; fields[i]; i++) {
char* name = String_trim(Process_printField(fields[i])); char* name = String_trim(Process_printField(fields[i]));
ListBox_add(lbf, (Object*) ListItem_new(name, fields[i])); Panel_add(lbf, (Object*) ListItem_new(name, fields[i]));
if (fields[i] == pl->sortKey) if (fields[i] == pl->sortKey)
ListBox_setSelected(lbf, i); Panel_setSelected(lbf, i);
free(name); free(name);
} }
ListItem* field = (ListItem*) pickFromList(lb, lbf, 15, headerHeight, fuFunctions, defaultBar); ListItem* field = (ListItem*) pickFromList(lb, lbf, 15, headerHeight, fuFunctions, defaultBar);
@ -590,7 +590,7 @@ int main(int argc, char** argv) {
pl->sortKey = field->key; pl->sortKey = field->key;
} }
((Object*)lbf)->delete((Object*)lbf); ((Object*)lbf)->delete((Object*)lbf);
ListBox_setRichHeader(lb, ProcessList_printHeader(pl)); Panel_setRichHeader(lb, ProcessList_printHeader(pl));
refreshTimeout = 0; refreshTimeout = 0;
break; break;
} }
@ -641,7 +641,7 @@ int main(int argc, char** argv) {
default: default:
doRefresh = false; doRefresh = false;
refreshTimeout = resetRefreshTimeout; refreshTimeout = resetRefreshTimeout;
ListBox_onKey(lb, ch); Panel_onKey(lb, ch);
break; break;
} }
follow = false; follow = false;

6
htop.h
View File

@ -11,7 +11,7 @@ in the source distribution for its full text.
#include "ProcessList.h" #include "ProcessList.h"
#include "CRT.h" #include "CRT.h"
#include "ListBox.h" #include "Panel.h"
#include "UsersTable.h" #include "UsersTable.h"
#include "SignalItem.h" #include "SignalItem.h"
#include "RichString.h" #include "RichString.h"
@ -19,8 +19,8 @@ in the source distribution for its full text.
#include "ScreenManager.h" #include "ScreenManager.h"
#include "FunctionBar.h" #include "FunctionBar.h"
#include "ListItem.h" #include "ListItem.h"
#include "CategoriesListBox.h" #include "CategoriesPanel.h"
#include "SignalsListBox.h" #include "SignalsPanel.h"
#include "config.h" #include "config.h"
#include "debug.h" #include "debug.h"