# HG changeset patch # User bsmith@81767d24-ef19-dc11-ae90-00e081727c95 # Date 1327228038 0 # Node ID 5371dbfc2262f791bdb86080a666c5e2e63bde3c # Parent d6988022c5cf0b8afbfe0f7b74c46940b05b2668 Added support for sizing listboxes on GTK2. diff -r d6988022c5cf -r 5371dbfc2262 gtk/dw.c --- a/gtk/dw.c Sun Jan 22 10:05:16 2012 +0000 +++ b/gtk/dw.c Sun Jan 22 10:27:18 2012 +0000 @@ -10024,65 +10024,63 @@ { GtkWidget *widget = gtk_object_get_user_data(GTK_OBJECT(item)); - /* Try to figure out the contents for MLE and Container */ - if(widget && (GTK_IS_TEXT_VIEW(widget) || GTK_IS_CLIST(widget))) - { - if(GTK_IS_CLIST(widget)) - { - GtkRequisition req; - - gtk_widget_size_request(widget, &req); - - *thiswidth = req.width + 20; - *thisheight = req.height + 20; - } - else - { - unsigned long bytes; - int height, width; - char *buf, *ptr; - int basicwidth; - int wrap = (gtk_text_view_get_wrap_mode(GTK_TEXT_VIEW(widget)) == GTK_WRAP_WORD); - static char testtext[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; - - *thisheight = 20; - basicwidth = *thiswidth = 20; - - dw_mle_get_size(item, &bytes, NULL); + /* Try to figure out the contents for Listbox and Container */ + if(widget && (GTK_IS_LIST(widget) || GTK_IS_CLIST(widget))) + { + GtkRequisition req; + + gtk_widget_size_request(widget, &req); + + *thiswidth = req.width + 20; + *thisheight = req.height + 20; + } + /* Try to figure out the contents for MLE */ + else if(widget && GTK_IS_TEXT_VIEW(widget)) + { + unsigned long bytes; + int height, width; + char *buf, *ptr; + int basicwidth; + int wrap = (gtk_text_view_get_wrap_mode(GTK_TEXT_VIEW(widget)) == GTK_WRAP_WORD); + static char testtext[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; + + *thisheight = 20; + basicwidth = *thiswidth = 20; + + dw_mle_get_size(item, &bytes, NULL); + + ptr = buf = alloca(bytes + 2); + dw_mle_export(item, buf, 0, (int)bytes); + buf[bytes] = 0; + strcat(buf, "\r"); + + /* MLE */ + while((ptr = strstr(buf, "\r"))) + { + ptr[0] = 0; + width = 0; + if(strlen(buf)) + dw_font_text_extents_get(item, NULL, buf, &width, &height); + else + dw_font_text_extents_get(item, NULL, testtext, NULL, &height); - ptr = buf = alloca(bytes + 2); - dw_mle_export(item, buf, 0, (int)bytes); - buf[bytes] = 0; - strcat(buf, "\r"); + width += basicwidth; - /* MLE */ - while((ptr = strstr(buf, "\r"))) + if(wrap && width > _DW_SCROLLED_MAX_WIDTH) + { + *thiswidth = _DW_SCROLLED_MAX_WIDTH; + *thisheight += height * (width / _DW_SCROLLED_MAX_WIDTH); + } + else { - ptr[0] = 0; - width = 0; - if(strlen(buf)) - dw_font_text_extents_get(item, NULL, buf, &width, &height); - else - dw_font_text_extents_get(item, NULL, testtext, NULL, &height); - - width += basicwidth; - - if(wrap && width > _DW_SCROLLED_MAX_WIDTH) - { - *thiswidth = _DW_SCROLLED_MAX_WIDTH; - *thisheight += height * (width / _DW_SCROLLED_MAX_WIDTH); - } - else - { - if(width > *thiswidth) - *thiswidth = width > _DW_SCROLLED_MAX_WIDTH ? _DW_SCROLLED_MAX_WIDTH : width; - } - *thisheight += height; - if(ptr[1] == '\n') - buf = &ptr[2]; - else - buf = &ptr[1]; + if(width > *thiswidth) + *thiswidth = width > _DW_SCROLLED_MAX_WIDTH ? _DW_SCROLLED_MAX_WIDTH : width; } + *thisheight += height; + if(ptr[1] == '\n') + buf = &ptr[2]; + else + buf = &ptr[1]; } } else