"fixed" the combobox issue
authorJohn Tsiombikas <nuclear@member.fsf.org>
Fri, 10 Jan 2020 10:41:59 +0000 (12:41 +0200)
committerJohn Tsiombikas <nuclear@member.fsf.org>
Fri, 10 Jan 2020 10:41:59 +0000 (12:41 +0200)
src/rawdisk.c
src/widgets.c

index b2576ba..559f61f 100644 (file)
@@ -7,6 +7,8 @@
 #include <winioctl.h>
 #include "rawdisk.h"
 
 #include <winioctl.h>
 #include "rawdisk.h"
 
+/*#define DBG_FAKE_DISKS*/
+
 static GUID guid_iface_disk = {0x53f56307, 0xb6bf, 0x11d0, {0x94, 0xf2, 0x00, 0xa0, 0xc9, 0x1e, 0xfb, 0x8b}};
 
 int rawdisk_detect(struct rawdisk_device *disks, int max_disks)
 static GUID guid_iface_disk = {0x53f56307, 0xb6bf, 0x11d0, {0x94, 0xf2, 0x00, 0xa0, 0xc9, 0x1e, 0xfb, 0x8b}};
 
 int rawdisk_detect(struct rawdisk_device *disks, int max_disks)
@@ -77,5 +79,19 @@ int rawdisk_detect(struct rawdisk_device *disks, int max_disks)
                devidx++;
        }
 
                devidx++;
        }
 
+#ifdef DBG_FAKE_DISKS
+       {
+               int i;
+               for(i=0; i<3; i++) {
+                       char buf[32];
+                       sprintf(buf, "\\\\?\\fake\\disk\\%d", i);
+                       disks[count].path = strdup(buf);
+                       sprintf(buf, "FAKE_DISK_%d", i);
+                       disks[count].name = strdup(buf);
+                       count++;
+               }
+       }
+#endif
+
        return count;
 }
        return count;
 }
index 82e4933..2d37973 100644 (file)
@@ -294,15 +294,26 @@ static void combosize(struct wgt_window *win, HWND cbwnd, const char **items, in
        wgt_string_size(win, "00", &textsz);
        max_width = width < 0 && width != WGT_AUTO ? -width : textsz.width;
 
        wgt_string_size(win, "00", &textsz);
        max_width = width < 0 && width != WGT_AUTO ? -width : textsz.width;
 
+       /* first get the height of the editbox */
        sum_height = SendMessage(cbwnd, CB_GETITEMHEIGHT, -1, 0);
        sz->y = sum_height;
        sum_height = SendMessage(cbwnd, CB_GETITEMHEIGHT, -1, 0);
        sz->y = sum_height;
-
-       for(i=0; i<num_items; i++) {
-               wgt_string_size(win, items[i], &textsz);
-               if(textsz.width > max_width) max_width = textsz.width;
-               sum_height += SendMessage(cbwnd, CB_GETITEMHEIGHT, i, 0);
+       /* then add the height of the dropdown list items */
+       /* XXX I can't figure out why, but it's not sufficient to show all items
+        * without some more height, so let's double it...
+        */
+       sum_height *= 2;
+       sum_height += SendMessage(cbwnd, CB_GETITEMHEIGHT, 0, 0) * num_items;
+       sum_height += GetSystemMetrics(SM_CYEDGE) * 2;
+
+       if(width < 0) {
+               int sbar_width;
+               for(i=0; i<num_items; i++) {
+                       wgt_string_size(win, items[i], &textsz);
+                       if(textsz.width > max_width) max_width = textsz.width;
+               }
+               sbar_width = GetSystemMetrics(SM_CXVSCROLL);
+               width = max_width + sbar_width + GetSystemMetrics(SM_CXEDGE) * 2;
        }
        }
-       if(width < 0) width = max_width * 3 / 2;
        if(height < 0) height = sum_height;
 
        sz->width = width;
        if(height < 0) height = sum_height;
 
        sz->width = width;
@@ -344,7 +355,6 @@ struct wgt_widget *wgt_combo(struct wgt_window *win, const char **items, int num
                SendMessage(w->handle, CB_SETCURSEL, sel, 0);
        }
 
                SendMessage(w->handle, CB_SETCURSEL, sel, 0);
        }
 
-
        w->cb_modify = modfunc;
        w->next = win->wlist;
        win->wlist = w;
        w->cb_modify = modfunc;
        w->next = win->wlist;
        win->wlist = w;
@@ -402,6 +412,8 @@ int wgt_combo_setitems(struct wgt_widget *w, const char **items, int num_items)
 
        combosize(w->win, w->handle, items, num_items, w->rect.width, WGT_AUTO, &size);
        MoveWindow(w->handle, w->rect.x, w->rect.y, w->rect.width, size.height, TRUE);
 
        combosize(w->win, w->handle, items, num_items, w->rect.width, WGT_AUTO, &size);
        MoveWindow(w->handle, w->rect.x, w->rect.y, w->rect.width, size.height, TRUE);
+
+       SendMessage(w->handle, CB_SETCURSEL, 0, 0);
        return 0;
 }
 
        return 0;
 }