2006-03-04 18:16:49 +00:00
|
|
|
/*
|
|
|
|
htop
|
2010-02-25 02:08:18 +00:00
|
|
|
(C) 2004-2010 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"
|
|
|
|
#include "Object.h"
|
|
|
|
#include "CRT.h"
|
|
|
|
|
|
|
|
#include "debug.h"
|
|
|
|
|
|
|
|
/*{
|
|
|
|
|
|
|
|
typedef struct CheckItem_ {
|
|
|
|
Object super;
|
|
|
|
char* text;
|
2007-11-08 23:23:01 +00:00
|
|
|
bool value;
|
|
|
|
bool* ref;
|
2006-03-04 18:16:49 +00:00
|
|
|
} CheckItem;
|
|
|
|
|
|
|
|
}*/
|
|
|
|
|
2006-07-11 06:13:32 +00:00
|
|
|
#ifdef DEBUG
|
2006-03-04 18:16:49 +00:00
|
|
|
char* CHECKITEM_CLASS = "CheckItem";
|
2006-07-11 06:13:32 +00:00
|
|
|
#else
|
|
|
|
#define CHECKITEM_CLASS NULL
|
|
|
|
#endif
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2007-11-08 23:23:01 +00:00
|
|
|
CheckItem* CheckItem_new(char* text, bool* ref, bool value) {
|
2006-03-04 18:16:49 +00:00
|
|
|
CheckItem* this = malloc(sizeof(CheckItem));
|
2006-07-11 06:13:32 +00:00
|
|
|
Object_setClass(this, CHECKITEM_CLASS);
|
2006-03-04 18:16:49 +00:00
|
|
|
((Object*)this)->display = CheckItem_display;
|
|
|
|
((Object*)this)->delete = CheckItem_delete;
|
|
|
|
this->text = text;
|
|
|
|
this->value = value;
|
2007-11-08 23:23:01 +00:00
|
|
|
this->ref = ref;
|
2006-03-04 18:16:49 +00:00
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2007-11-08 23:23:01 +00:00
|
|
|
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;
|
|
|
|
}
|