X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?p=instimg;a=blobdiff_plain;f=src%2Fwidgets.c;h=707d5158cea32006bf7a7ffc15d6b903243516d2;hp=2c08856c53ac3241b296138f70594404b64270a8;hb=5ac430128e1fa0e70e1cb232bd5d756b7e8c6abf;hpb=df3263076df0ad443dd9262b6250820c038fa7f2 diff --git a/src/widgets.c b/src/widgets.c index 2c08856..707d515 100644 --- a/src/widgets.c +++ b/src/widgets.c @@ -24,6 +24,8 @@ struct wgt_widget { char **itemlist; int num_items; + int disabled; + wgt_callback cb_click; wgt_callback cb_modify; }; @@ -118,6 +120,23 @@ void wgt_destroy_widget(struct wgt_widget *w) free(w->itemlist); } +void wgt_enable_widget(struct wgt_widget *w) +{ + w->disabled = 0; + EnableWindow(w->handle, 1); +} + +void wgt_disable_widget(struct wgt_widget *w) +{ + w->disabled = 1; + EnableWindow(w->handle, 0); +} + +int wgt_widget_enabled(struct wgt_widget *w) +{ + return !w->disabled; +} + struct wgt_window *wgt_widget_window(struct wgt_widget *w) { return w->win; @@ -285,7 +304,10 @@ struct wgt_widget *wgt_combo(struct wgt_window *win, const char **items, int num return 0; } - max_width = max_height = sum_height = 0; + wgt_string_size(win, "00", &textsz); + max_width = width < 0 && width != WGT_AUTO ? -width : textsz.width; + max_height = height < 0 && height != WGT_AUTO ? -height : textsz.height; + sum_height = num_items ? 0 : max_height; for(i=0; ihandle = CreateWindow("COMBOBOX", items[0], + if(!(w->handle = CreateWindow("COMBOBOX", items[0] ? items[0] : "", WS_CHILD | WS_VISIBLE | CBS_DROPDOWNLIST | CBS_HASSTRINGS, x, y, width, height, win->handle, 0, GetModuleHandle(0), 0))) { fprintf(stderr, "wgt_combo: failed to create window\n"); @@ -322,7 +344,9 @@ struct wgt_widget *wgt_combo(struct wgt_window *win, const char **items, int num if(sel < 0) sel = 0; if(sel >= num_items) sel = num_items - 1; - SendMessage(w->handle, CB_SETCURSEL, sel, 0); + if(sel >= 0) { + SendMessage(w->handle, CB_SETCURSEL, sel, 0); + } w->rect.x = x; w->rect.y = y;