1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
|
#include <stdlib.h> /* free/malloc */
#include <string.h>
#include "comm.h"
#include "data.h"
#include "data_entry_bool.h"
static int is_true(const char *str){
if (!str)
return 0;
if ((str[0] != 't')&&(str[0] != 'T'))
return 0; /* mlterm returns "true" or "false". first char is enough*/
return 1;
}
void entry_bool_reset(const entry_t *entry){
entry_bool_t * data = entry->data;
mlterm_set_param(entry->key, ((data->initial)? "true" : "false"));
}
void entry_bool_apply(const entry_t *entry){
entry_bool_t * data = entry->data;
mlterm_set_param(entry->key, ((data->current)? "true" : "false"));
}
entry_bool_t *entry_bool_new(const char *key){
entry_bool_t *entry;
entry = malloc(sizeof(entry_bool_t));
entry->initial = is_true(mlterm_get_param(key));
entry->current = entry->initial;;
return entry;
}
int entry_bool_add(section_t *section, const char *name, const char * key){
if (section->maxwidth < strlen(name))
section->maxwidth = strlen(name);
section->entry[section->size].name = name;
section->entry[section->size].key = key;
section->entry[section->size].type = ENT_BOOL;
section->entry[section->size].data = entry_bool_new(key);
section->size++;
return 0;
}
void entry_bool_free_data(entry_t * entry){
free(entry->data);
return;
}
void entry_bool_display(window_t *window, const entry_t *entry, int x, int y, int state){
entry_bool_t * data;
data = entry->data;
display_str(window, x, y, ((data->current)? "True" : "False"), DC_NORMAL);
}
int entry_bool_edit(window_t *window, entry_t *entry, int x, int y){
int buffer;
entry_bool_t *data;
data = entry->data;
buffer = read_one();
switch(buffer){
case KEY_ESC:
case 10:
return -1;
case KEY_RIGHT:
case KEY_LEFT:
case KEY_UP:
case KEY_DOWN:
data->current = 1 - data->current;
entry->modified = 1;
return 1; /* redraw */
break;
default:
/* ignore */
return 0;
}
}
|