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;
|
2007-11-08 23:23:01 +00:00
|
|
|
bool* ref;
|
2014-02-27 19:35:22 +00:00
|
|
|
bool value;
|
2006-03-04 18:16:49 +00:00
|
|
|
} CheckItem;
|
|
|
|
|
|
|
|
}*/
|
|
|
|
|
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);
|
2020-08-31 20:08:35 +00:00
|
|
|
RichString_write(out, CRT_colors[CHECK_BOX], "[");
|
2008-03-09 08:58:38 +00:00
|
|
|
if (CheckItem_get(this))
|
2020-08-31 20:08:35 +00:00
|
|
|
RichString_append(out, CRT_colors[CHECK_MARK], "x");
|
2008-03-09 08:58:38 +00:00
|
|
|
else
|
2020-08-31 20:08:35 +00:00
|
|
|
RichString_append(out, CRT_colors[CHECK_MARK], " ");
|
|
|
|
RichString_append(out, CRT_colors[CHECK_BOX], "] ");
|
2008-03-09 08:58:38 +00:00
|
|
|
RichString_append(out, CRT_colors[CHECK_TEXT], this->text);
|
|
|
|
}
|
|
|
|
|
2012-12-05 15:12:20 +00:00
|
|
|
ObjectClass CheckItem_class = {
|
|
|
|
.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) {
|
2019-10-31 16:39:12 +00:00
|
|
|
if (this->ref)
|
2007-11-08 23:23:01 +00:00
|
|
|
*(this->ref) = value;
|
|
|
|
else
|
|
|
|
this->value = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CheckItem_get(CheckItem* this) {
|
2019-10-31 16:39:12 +00:00
|
|
|
if (this->ref)
|
2007-11-08 23:23:01 +00:00
|
|
|
return *(this->ref);
|
|
|
|
else
|
|
|
|
return this->value;
|
|
|
|
}
|