2006-03-04 18:16:49 +00:00
|
|
|
/*
|
2011-12-26 21:35:57 +00:00
|
|
|
htop - CheckItem.c
|
2011-05-26 16:35:07 +00:00
|
|
|
(C) 2004-2011 Hisham H. Muhammad
|
2020-10-05 07:51:32 +00:00
|
|
|
Released under the GNU GPLv2, see the COPYING file
|
2006-03-04 18:16:49 +00:00
|
|
|
in the source distribution for its full text.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "CheckItem.h"
|
|
|
|
|
2011-12-26 21:35:57 +00:00
|
|
|
#include <assert.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
2020-09-19 11:55:23 +00:00
|
|
|
#include "CRT.h"
|
|
|
|
#include "RichString.h"
|
|
|
|
|
2006-03-04 18:16:49 +00:00
|
|
|
|
2008-03-09 08:58:38 +00:00
|
|
|
static void CheckItem_delete(Object* cast) {
|
|
|
|
CheckItem* this = (CheckItem*)cast;
|
|
|
|
assert (this != NULL);
|
|
|
|
|
|
|
|
free(this->text);
|
|
|
|
free(this);
|
|
|
|
}
|
|
|
|
|
2020-10-06 10:28:11 +00:00
|
|
|
static void CheckItem_display(const Object* cast, RichString* out) {
|
|
|
|
const CheckItem* this = (const CheckItem*)cast;
|
2008-03-09 08:58:38 +00:00
|
|
|
assert (this != NULL);
|
2020-08-31 20:08:35 +00:00
|
|
|
RichString_write(out, CRT_colors[CHECK_BOX], "[");
|
2020-11-01 00:09:51 +00:00
|
|
|
if (CheckItem_get(this)) {
|
2020-08-31 20:08:35 +00:00
|
|
|
RichString_append(out, CRT_colors[CHECK_MARK], "x");
|
2020-11-01 00:09:51 +00:00
|
|
|
} else {
|
2020-08-31 20:08:35 +00:00
|
|
|
RichString_append(out, CRT_colors[CHECK_MARK], " ");
|
2020-11-01 00:09:51 +00:00
|
|
|
}
|
2020-08-31 20:08:35 +00:00
|
|
|
RichString_append(out, CRT_colors[CHECK_BOX], "] ");
|
2008-03-09 08:58:38 +00:00
|
|
|
RichString_append(out, CRT_colors[CHECK_TEXT], this->text);
|
|
|
|
}
|
|
|
|
|
2020-10-05 11:19:50 +00:00
|
|
|
const ObjectClass CheckItem_class = {
|
2012-12-05 15:12:20 +00:00
|
|
|
.display = CheckItem_display,
|
|
|
|
.delete = CheckItem_delete
|
|
|
|
};
|
|
|
|
|
2015-08-12 20:29:32 +00:00
|
|
|
CheckItem* CheckItem_newByRef(char* text, bool* ref) {
|
2012-12-05 15:12:20 +00:00
|
|
|
CheckItem* this = AllocThis(CheckItem);
|
2006-03-04 18:16:49 +00:00
|
|
|
this->text = text;
|
2015-08-12 20:29:32 +00:00
|
|
|
this->value = false;
|
2007-11-08 23:23:01 +00:00
|
|
|
this->ref = ref;
|
2006-03-04 18:16:49 +00:00
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2015-08-12 20:29:32 +00:00
|
|
|
CheckItem* CheckItem_newByVal(char* text, bool value) {
|
|
|
|
CheckItem* this = AllocThis(CheckItem);
|
|
|
|
this->text = text;
|
|
|
|
this->value = value;
|
|
|
|
this->ref = NULL;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2007-11-08 23:23:01 +00:00
|
|
|
void CheckItem_set(CheckItem* this, bool value) {
|
2020-11-01 00:09:51 +00:00
|
|
|
if (this->ref) {
|
2007-11-08 23:23:01 +00:00
|
|
|
*(this->ref) = value;
|
2020-11-01 00:09:51 +00:00
|
|
|
} else {
|
2007-11-08 23:23:01 +00:00
|
|
|
this->value = value;
|
2020-11-01 00:09:51 +00:00
|
|
|
}
|
2007-11-08 23:23:01 +00:00
|
|
|
}
|
|
|
|
|
2020-10-06 10:28:11 +00:00
|
|
|
bool CheckItem_get(const CheckItem* this) {
|
2020-11-01 00:09:51 +00:00
|
|
|
if (this->ref) {
|
2007-11-08 23:23:01 +00:00
|
|
|
return *(this->ref);
|
2020-11-01 00:09:51 +00:00
|
|
|
} else {
|
2007-11-08 23:23:01 +00:00
|
|
|
return this->value;
|
2020-11-01 00:09:51 +00:00
|
|
|
}
|
2007-11-08 23:23:01 +00:00
|
|
|
}
|