htop/ColorsPanel.c

109 lines
2.8 KiB
C
Raw Normal View History

2011-12-26 21:35:57 +00:00
/*
htop - ColorsPanel.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 "ColorsPanel.h"
2006-03-04 18:16:49 +00:00
2011-12-26 21:35:57 +00:00
#include "CRT.h"
2006-03-04 18:16:49 +00:00
#include "CheckItem.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>
#include <string.h>
2006-03-04 18:16:49 +00:00
// TO ADD A NEW SCHEME:
2006-05-30 13:47:28 +00:00
// * Increment the size of bool check in ColorsPanel.h
// * Add the entry in the ColorSchemeNames array below in the file
2006-03-04 18:16:49 +00:00
// * Add a define in CRT.h that matches the order of the array
// * Add the colors in CRT_setColors
/*{
2011-12-26 21:35:57 +00:00
#include "Panel.h"
#include "Settings.h"
#include "ScreenManager.h"
2006-03-04 18:16:49 +00:00
2006-05-30 13:47:28 +00:00
typedef struct ColorsPanel_ {
Panel super;
2006-03-04 18:16:49 +00:00
Settings* settings;
ScreenManager* scr;
2006-05-30 13:47:28 +00:00
} ColorsPanel;
2006-03-04 18:16:49 +00:00
}*/
static const char* ColorSchemeNames[] = {
2006-03-04 18:16:49 +00:00
"Default",
"Monochromatic",
"Black on White",
"Light Terminal",
"MC",
"Black Night",
NULL
};
static void ColorsPanel_delete(Object* object) {
2006-05-30 13:47:28 +00:00
Panel* super = (Panel*) object;
ColorsPanel* this = (ColorsPanel*) object;
Panel_done(super);
2006-03-04 18:16:49 +00:00
free(this);
}
static HandlerResult ColorsPanel_eventHandler(Panel* super, int ch) {
2006-05-30 13:47:28 +00:00
ColorsPanel* this = (ColorsPanel*) super;
2006-03-04 18:16:49 +00:00
HandlerResult result = IGNORED;
2006-05-30 13:47:28 +00:00
int mark = Panel_getSelectedIndex(super);
2006-03-04 18:16:49 +00:00
switch(ch) {
case 0x0a:
case 0x0d:
case KEY_ENTER:
2008-05-07 23:01:45 +00:00
case KEY_MOUSE:
2006-03-04 18:16:49 +00:00
case ' ':
for (int i = 0; ColorSchemeNames[i] != NULL; i++)
CheckItem_set((CheckItem*)Panel_get(super, i), false);
CheckItem_set((CheckItem*)Panel_get(super, mark), true);
2006-03-04 18:16:49 +00:00
this->settings->colorScheme = mark;
result = HANDLED;
}
if (result == HANDLED) {
this->settings->changed = true;
const Header* header = this->scr->header;
2006-03-04 18:16:49 +00:00
CRT_setColors(mark);
Panel* menu = (Panel*) Vector_get(this->scr->panels, 0);
2006-03-04 18:16:49 +00:00
Header_draw(header);
RichString_setAttr(&(super->header), CRT_colors[PANEL_HEADER_FOCUS]);
2006-05-30 14:02:43 +00:00
RichString_setAttr(&(menu->header), CRT_colors[PANEL_HEADER_UNFOCUS]);
2006-03-04 18:16:49 +00:00
ScreenManager_resize(this->scr, this->scr->x1, header->height, this->scr->x2, this->scr->y2);
}
return result;
}
PanelClass ColorsPanel_class = {
.super = {
.extends = Class(Panel),
.delete = ColorsPanel_delete
},
.eventHandler = ColorsPanel_eventHandler
};
ColorsPanel* ColorsPanel_new(Settings* settings, ScreenManager* scr) {
ColorsPanel* this = AllocThis(ColorsPanel);
Panel* super = (Panel*) this;
Panel_init(super, 1, 1, 1, 1, Class(CheckItem), true);
this->settings = settings;
this->scr = scr;
Panel_setHeader(super, "Colors");
for (int i = 0; ColorSchemeNames[i] != NULL; i++) {
Panel_add(super, (Object*) CheckItem_new(strdup(ColorSchemeNames[i]), NULL, false));
}
CheckItem_set((CheckItem*)Panel_get(super, settings->colorScheme), true);
return this;
}