33 : variable_name(nulldup(variable_name_)),
37 select_list_widget(select_list_widget_),
39 last_of_list_table(
NULp),
50 return XmStringCreateSimple((
char*)text);
58 size_t count =
size();
61 XmString *strtab =
new XmString[count];
65 const char *s2 = lt->get_displayed();
73 if (!strlen(s2)) s2 =
" ";
86 for (
size_t i=0; i<count; i++) XmStringFree(strtab[i]);
89 if (update_cb) update_cb(
this, cl_update);
100 if (!variable_name)
return;
109 switch (variable_type) {
166 XmNvisibleItemCount, &vis,
167 XmNtopItemPosition, &top,
175 if (pos >= top + vis) {
180 GBK_terminatef(
"Selection list '%s' has no default selection", variable_name);
205 if (!sel)
return true;
207 return def && sel == def;
223 if (is_selected && !found) found = lt;
236 while (index && entry) {
253 prev = get_entry_at(index-1);
290 if (!number_of_lines)
break;
308 int element_index = 0;
310 if (*entry.
get_value() == searched_value)
return element_index;
336 char *defaultDispCopy = strdup(default_displayed);
337 char *defaultValueCopy = strdup(default_value);
339 bool defInserted =
false;
342 for (
int i = 0; entries[i]; ++i) {
343 if (!defInserted && strcmp(entries[i], defaultValueCopy) == 0) {
348 insert(entries[i], entries[i]);
351 if (!defInserted)
insert_default(defaultDispCopy, defaultValueCopy);
357 free(defaultValueCopy);
358 free(defaultDispCopy);
453 sprintf(filter,
"tmp/save_box_sel_%li/filter", (
long)
this);
455 sprintf(filter,
"tmp/load_box_sel_%li/filter", (
long)
this);
474 return selcmp(static_cast<const AW_selection_list_entry*>(t1)->get_displayed(),
475 static_cast<const AW_selection_list_entry*>(t2)->get_displayed());
480 size_t count =
size();
485 tables[count++] = lt;
491 for (i=0; i<count-1; i++) {
492 tables[i]->
next = tables[i+1];
510 if (case_sensitive) cmp = strcmp;
524 array.reserve(
size());
527 array.put(strdup(values ? lt->get_value().get_string() : lt->get_displayed()));
545 char *AW_selection_list_entry::copy_string_for_display(
const char *
str) {
546 size_t len = strlen(str);
553 size_t tlen = strlen(truncated);
555 memcpy(out+MAX_DISPLAY_LENGTH-tlen, truncated, tlen);
563 for (
size_t i = 0; i<len; ++i) {
565 case ',': out[i] =
';';
break;
566 case '\n': out[i] =
'#';
break;
603 #define TEST_LIST_CONTENT(list,values,expected) do { \
605 (list).to_array(a, values); \
606 TEST_EXPECT_STRARRAY_CONTAINS(a, ';', expected); \
609 #define TEST_GET_LIST_CONTENT(list,expected) do { \
610 char *str = (list).get_content_as_string(10); \
611 TEST_EXPECT_EQUAL(str, expected); \
615 void TEST_selection_list_access() {
625 list0.insert_default(
"First", s1st);
626 list0.insert (
"Second", s2nd);
627 list0.insert (
"Third", s3rd);
629 list1.insert (
"First",
"1st");
630 list1.insert_default(
"Second",
"2nd");
631 list1.insert (
"Third",
"3rd");
633 list2.insert (
"First", s1st);
634 list2.insert (
"Second", s2nd);
635 list2.insert (
"Third", s3rd);
636 list2.insert_default(
"Default", sempty);
670 TEST_LIST_CONTENT(list1,
true,
"1st;3rd");
671 TEST_LIST_CONTENT(list1,
false,
"First;Third");
672 TEST_GET_LIST_CONTENT(list1,
"First\nThird\n");
674 TEST_LIST_CONTENT(list2,
true,
"1st;2nd;3rd");
675 TEST_LIST_CONTENT(list2,
false,
"First;Second;Third");
676 TEST_GET_LIST_CONTENT(list2,
"First\nSecond\nThird\n");
714 list1.move_content_to(©1);
715 list2.move_content_to(©2);
720 TEST_LIST_CONTENT(copy1,
true,
"1st;3rd");
721 TEST_LIST_CONTENT(copy2,
true,
"1st;2nd;3rd");
int(* sellist_cmp_fun)(const char *disp1, const char *disp2)
bool matches_variable_type(AW_VARIABLE_TYPE atype) const
void sort(bool backward, bool case_sensitive)
GBDATA * get_pointer() const
void GB_warning(const char *message)
GBDATA * read_pointer() const
long GBS_write_hash(GB_HASH *hs, const char *key, long val)
void select_element_at(int wanted_index)
void set_file_suffix(const char *suffix)
void insert_default(const char *displayed, const AW_scalar &value)
GB_ERROR GB_add_callback(GBDATA *gbd, GB_CB_TYPE type, const DatabaseCallback &dbcb)
static void AW_DB_selection_refresh_cb(GBDATA *, AW_DB_selection *selection)
void GB_sort(void **array, size_t first, size_t behind_last, gb_compare_function compare, void *client_data)
int ARB_stricmp(const char *s1, const char *s2)
static int sel_sort_backward(const char *d1, const char *d2)
AW_selection_list(const char *variable_name_, int variable_type_, Widget select_list_widget_)
GB_ERROR write_to(class AW_awar *awar) const
void set_awar_value(const AW_scalar &new_value)
void delete_element_at(int index)
void GBK_terminatef(const char *templat,...)
void cat(const char *from)
bool default_is_selected() const
int get_index_of_selected()
static const size_t MAX_DISPLAY_LENGTH
void insert(const char *displayed, const AW_scalar &value)
const char * get_string() const
#define TEST_PUBLISH(testfunction)
AW_selection_list_entry * last_of_list_table
void to_array(StrArray &array, bool values)
static AW_root * SINGLETON
#define TEST_EXPECT(cond)
char * ARB_strduplen(const char *p, unsigned len)
const AW_scalar * get_value_at(int index)
GB_HASH * to_hash(bool case_sens)
void set_update_callback(sellist_update_cb ucb, AW_CL cl_user)
AW_DB_selection(AW_selection_list *sellist_, GBDATA *gbd_)
const char * get_displayed() const
static int sel_isort_backward(const char *d1, const char *d2)
#define TEST_REJECT(cond)
int get_index_of(const AW_scalar &searched_value)
GBDATA * GB_get_root(GBDATA *gbd)
const AW_scalar & get_value() const
AW_selection_list_entry * default_select
AW_selection_list_entry * next
GB_write_int const char GB_write_autoconv_string WRITE_SKELETON(write_pointer, GBDATA *,"%p", GB_write_pointer) char *AW_awa if)(!gb_var) return strdup("")
static unsigned update_cb(AW_root *aw_root)
char * read_string() const
AW_awar * awar(const char *awar)
void(* sellist_update_cb)(AW_selection_list *, AW_CL)
#define TEST_EXPECT_NULL(n)
char * ARB_strndup(const char *start, int len)
char * get_content_as_string(long number_of_lines)
void move_selection(int offset)
__ATTR__NORETURN void type_mismatch(const char *triedType, const char *intoWhat)
void GB_remove_callback(GBDATA *gbd, GB_CB_TYPE type, const DatabaseCallback &dbcb)
Widget select_list_widget
const char * get_type_name() const
~AW_DB_selection() OVERRIDE
const char * get_default_display() const
__ATTR__NORETURN void TERMINATE_selection_type_mismatch(const char *triedType)
AW_selection_list_entry * list_table
const AW_scalar * get_default_value() const
void move_content_to(AW_selection_list *target_list)
GB_transaction ta(gb_var)
void init_from_array(const CharPtrArray &entries, const char *default_displayed, const char *default_value)
static int gb_compare_function__2__sellist_cmp_fun(const void *t1, const void *t2, void *v_selcmp)
AW_awar * awar_string(const char *var_name, const char *default_value="", AW_default default_file=AW_ROOT_DEFAULT)
const AW_scalar * get_selected_value() const
#define TEST_EXPECT_EQUAL(expr, want)
struct _WidgetRec * Widget
AW_scalar get_awar_value() const
AW_selection_list * get_sellist()
void delete_value(const AW_scalar &value)
char * GBS_global_string_copy(const char *templat,...)
XmString XmStringCreateSimple_wrapper(const char *text)
GB_HASH * GBS_create_hash(long estimated_elements, GB_CASE case_sens)
void sortCustom(sellist_cmp_fun cmp)