2011-12-26 21:35:57 +00:00
|
|
|
/*
|
|
|
|
htop - ColorsPanel.c
|
|
|
|
(C) 2004-2011 Hisham H. Muhammad
|
2020-10-05 07:51:32 +00:00
|
|
|
Released under the GNU GPLv2, see the COPYING file
|
2011-12-26 21:35:57 +00:00
|
|
|
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
|
|
|
|
2020-09-19 11:55:23 +00:00
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
2006-03-04 18:16:49 +00:00
|
|
|
#include "CheckItem.h"
|
2020-09-19 11:55:23 +00:00
|
|
|
#include "CRT.h"
|
|
|
|
#include "FunctionBar.h"
|
|
|
|
#include "Header.h"
|
|
|
|
#include "Object.h"
|
|
|
|
#include "ProvideCurses.h"
|
|
|
|
#include "RichString.h"
|
|
|
|
#include "Vector.h"
|
2020-10-14 18:21:09 +00:00
|
|
|
#include "XUtils.h"
|
2011-12-26 21:35:57 +00:00
|
|
|
|
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
|
2015-02-03 21:30:05 +00:00
|
|
|
// * 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
|
|
|
|
|
|
|
|
|
2017-07-23 02:41:19 +00:00
|
|
|
static const char* const ColorsFunctions[] = {" ", " ", " ", " ", " ", " ", " ", " ", " ", "Done ", NULL};
|
2015-03-23 18:26:56 +00:00
|
|
|
|
2017-07-23 02:41:19 +00:00
|
|
|
static const char* const ColorSchemeNames[] = {
|
2006-03-04 18:16:49 +00:00
|
|
|
"Default",
|
|
|
|
"Monochromatic",
|
|
|
|
"Black on White",
|
|
|
|
"Light Terminal",
|
|
|
|
"MC",
|
|
|
|
"Black Night",
|
2015-04-09 18:17:20 +00:00
|
|
|
"Broken Gray",
|
2006-03-04 18:16:49 +00:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2008-03-09 08:58:38 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2012-12-05 15:12:20 +00:00
|
|
|
static HandlerResult ColorsPanel_eventHandler(Panel* super, int ch) {
|
2006-05-30 13:47:28 +00:00
|
|
|
ColorsPanel* this = (ColorsPanel*) super;
|
2019-10-31 16:39:12 +00:00
|
|
|
|
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:
|
2015-08-27 21:42:35 +00:00
|
|
|
case KEY_RECLICK:
|
2006-03-04 18:16:49 +00:00
|
|
|
case ' ':
|
2015-02-03 21:30:05 +00:00
|
|
|
for (int i = 0; ColorSchemeNames[i] != NULL; i++)
|
2007-11-08 23:23:01 +00:00
|
|
|
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) {
|
2006-05-19 20:27:23 +00:00
|
|
|
this->settings->changed = true;
|
2015-01-22 01:27:31 +00:00
|
|
|
const Header* header = this->scr->header;
|
2006-03-04 18:16:49 +00:00
|
|
|
CRT_setColors(mark);
|
2018-02-05 06:01:12 +00:00
|
|
|
clear();
|
2011-12-01 12:31:57 +00:00
|
|
|
Panel* menu = (Panel*) Vector_get(this->scr->panels, 0);
|
2006-03-04 18:16:49 +00:00
|
|
|
Header_draw(header);
|
2020-10-05 13:14:54 +00:00
|
|
|
FunctionBar_draw(super->currentBar);
|
2006-03-04 18:16:49 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2020-10-05 11:19:50 +00:00
|
|
|
const PanelClass ColorsPanel_class = {
|
2012-12-05 15:12:20 +00:00
|
|
|
.super = {
|
|
|
|
.extends = Class(Panel),
|
|
|
|
.delete = ColorsPanel_delete
|
|
|
|
},
|
|
|
|
.eventHandler = ColorsPanel_eventHandler
|
|
|
|
};
|
|
|
|
|
2008-03-09 08:58:38 +00:00
|
|
|
ColorsPanel* ColorsPanel_new(Settings* settings, ScreenManager* scr) {
|
2012-12-05 15:12:20 +00:00
|
|
|
ColorsPanel* this = AllocThis(ColorsPanel);
|
2008-03-09 08:58:38 +00:00
|
|
|
Panel* super = (Panel*) this;
|
2015-03-23 18:26:56 +00:00
|
|
|
FunctionBar* fuBar = FunctionBar_new(ColorsFunctions, NULL, NULL);
|
|
|
|
Panel_init(super, 1, 1, 1, 1, Class(CheckItem), true, fuBar);
|
2008-03-09 08:58:38 +00:00
|
|
|
|
|
|
|
this->settings = settings;
|
|
|
|
this->scr = scr;
|
|
|
|
|
|
|
|
Panel_setHeader(super, "Colors");
|
2015-02-03 21:30:05 +00:00
|
|
|
for (int i = 0; ColorSchemeNames[i] != NULL; i++) {
|
2016-02-02 14:53:02 +00:00
|
|
|
Panel_add(super, (Object*) CheckItem_newByVal(xStrdup(ColorSchemeNames[i]), false));
|
2008-03-09 08:58:38 +00:00
|
|
|
}
|
|
|
|
CheckItem_set((CheckItem*)Panel_get(super, settings->colorScheme), true);
|
|
|
|
return this;
|
|
|
|
}
|