htop/CheckItem.c

73 lines
1.5 KiB
C
Raw Normal View History

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
2006-03-04 18:16:49 +00:00
Released under the GNU GPL, see the COPYING file
in the source distribution for its full text.
*/
#include "CheckItem.h"
2011-12-26 21:35:57 +00:00
#include "CRT.h"
2006-03-04 18:16:49 +00:00
2011-12-26 21:35:57 +00:00
#include <assert.h>
#include <stdlib.h>
2006-03-04 18:16:49 +00:00
/*{
2011-12-26 21:35:57 +00:00
#include "Object.h"
2006-03-04 18:16:49 +00:00
typedef struct CheckItem_ {
Object super;
char* text;
bool* ref;
2014-02-27 19:35:22 +00:00
bool value;
2006-03-04 18:16:49 +00:00
} CheckItem;
}*/
static void CheckItem_delete(Object* cast) {
CheckItem* this = (CheckItem*)cast;
assert (this != NULL);
free(this->text);
free(this);
}
static void CheckItem_display(Object* cast, RichString* out) {
CheckItem* this = (CheckItem*)cast;
assert (this != NULL);
RichString_write(out, CRT_colors[CHECK_BOX], "[");
if (CheckItem_get(this))
RichString_append(out, CRT_colors[CHECK_MARK], "x");
else
RichString_append(out, CRT_colors[CHECK_MARK], " ");
RichString_append(out, CRT_colors[CHECK_BOX], "] ");
RichString_append(out, CRT_colors[CHECK_TEXT], this->text);
}
ObjectClass CheckItem_class = {
.display = CheckItem_display,
.delete = CheckItem_delete
};
CheckItem* CheckItem_new(char* text, bool* ref, bool value) {
CheckItem* this = AllocThis(CheckItem);
2006-03-04 18:16:49 +00:00
this->text = text;
this->value = value;
this->ref = ref;
2006-03-04 18:16:49 +00:00
return this;
}
void CheckItem_set(CheckItem* this, bool value) {
if (this->ref)
*(this->ref) = value;
else
this->value = value;
}
bool CheckItem_get(CheckItem* this) {
if (this->ref)
return *(this->ref);
else
return this->value;
}