comparison gtk/dw.c @ 1571:5371dbfc2262

Added support for sizing listboxes on GTK2.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Sun, 22 Jan 2012 10:27:18 +0000
parents 035bc006afbe
children e6a2e6405d30
comparison
equal deleted inserted replaced
1570:d6988022c5cf 1571:5371dbfc2262
10022 /* Internal function to get the recommended size of scrolled items */ 10022 /* Internal function to get the recommended size of scrolled items */
10023 void _get_scrolled_size(GtkWidget *item, gint *thiswidth, gint *thisheight) 10023 void _get_scrolled_size(GtkWidget *item, gint *thiswidth, gint *thisheight)
10024 { 10024 {
10025 GtkWidget *widget = gtk_object_get_user_data(GTK_OBJECT(item)); 10025 GtkWidget *widget = gtk_object_get_user_data(GTK_OBJECT(item));
10026 10026
10027 /* Try to figure out the contents for MLE and Container */ 10027 /* Try to figure out the contents for Listbox and Container */
10028 if(widget && (GTK_IS_TEXT_VIEW(widget) || GTK_IS_CLIST(widget))) 10028 if(widget && (GTK_IS_LIST(widget) || GTK_IS_CLIST(widget)))
10029 { 10029 {
10030 if(GTK_IS_CLIST(widget)) 10030 GtkRequisition req;
10031 { 10031
10032 GtkRequisition req; 10032 gtk_widget_size_request(widget, &req);
10033
10034 *thiswidth = req.width + 20;
10035 *thisheight = req.height + 20;
10036 }
10037 /* Try to figure out the contents for MLE */
10038 else if(widget && GTK_IS_TEXT_VIEW(widget))
10039 {
10040 unsigned long bytes;
10041 int height, width;
10042 char *buf, *ptr;
10043 int basicwidth;
10044 int wrap = (gtk_text_view_get_wrap_mode(GTK_TEXT_VIEW(widget)) == GTK_WRAP_WORD);
10045 static char testtext[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
10046
10047 *thisheight = 20;
10048 basicwidth = *thiswidth = 20;
10049
10050 dw_mle_get_size(item, &bytes, NULL);
10051
10052 ptr = buf = alloca(bytes + 2);
10053 dw_mle_export(item, buf, 0, (int)bytes);
10054 buf[bytes] = 0;
10055 strcat(buf, "\r");
10056
10057 /* MLE */
10058 while((ptr = strstr(buf, "\r")))
10059 {
10060 ptr[0] = 0;
10061 width = 0;
10062 if(strlen(buf))
10063 dw_font_text_extents_get(item, NULL, buf, &width, &height);
10064 else
10065 dw_font_text_extents_get(item, NULL, testtext, NULL, &height);
10033 10066
10034 gtk_widget_size_request(widget, &req); 10067 width += basicwidth;
10035 10068
10036 *thiswidth = req.width + 20; 10069 if(wrap && width > _DW_SCROLLED_MAX_WIDTH)
10037 *thisheight = req.height + 20;
10038 }
10039 else
10040 {
10041 unsigned long bytes;
10042 int height, width;
10043 char *buf, *ptr;
10044 int basicwidth;
10045 int wrap = (gtk_text_view_get_wrap_mode(GTK_TEXT_VIEW(widget)) == GTK_WRAP_WORD);
10046 static char testtext[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
10047
10048 *thisheight = 20;
10049 basicwidth = *thiswidth = 20;
10050
10051 dw_mle_get_size(item, &bytes, NULL);
10052
10053 ptr = buf = alloca(bytes + 2);
10054 dw_mle_export(item, buf, 0, (int)bytes);
10055 buf[bytes] = 0;
10056 strcat(buf, "\r");
10057
10058 /* MLE */
10059 while((ptr = strstr(buf, "\r")))
10060 { 10070 {
10061 ptr[0] = 0; 10071 *thiswidth = _DW_SCROLLED_MAX_WIDTH;
10062 width = 0; 10072 *thisheight += height * (width / _DW_SCROLLED_MAX_WIDTH);
10063 if(strlen(buf))
10064 dw_font_text_extents_get(item, NULL, buf, &width, &height);
10065 else
10066 dw_font_text_extents_get(item, NULL, testtext, NULL, &height);
10067
10068 width += basicwidth;
10069
10070 if(wrap && width > _DW_SCROLLED_MAX_WIDTH)
10071 {
10072 *thiswidth = _DW_SCROLLED_MAX_WIDTH;
10073 *thisheight += height * (width / _DW_SCROLLED_MAX_WIDTH);
10074 }
10075 else
10076 {
10077 if(width > *thiswidth)
10078 *thiswidth = width > _DW_SCROLLED_MAX_WIDTH ? _DW_SCROLLED_MAX_WIDTH : width;
10079 }
10080 *thisheight += height;
10081 if(ptr[1] == '\n')
10082 buf = &ptr[2];
10083 else
10084 buf = &ptr[1];
10085 } 10073 }
10074 else
10075 {
10076 if(width > *thiswidth)
10077 *thiswidth = width > _DW_SCROLLED_MAX_WIDTH ? _DW_SCROLLED_MAX_WIDTH : width;
10078 }
10079 *thisheight += height;
10080 if(ptr[1] == '\n')
10081 buf = &ptr[2];
10082 else
10083 buf = &ptr[1];
10086 } 10084 }
10087 } 10085 }
10088 else 10086 else
10089 { 10087 {
10090 /* Set to half for others */ 10088 /* Set to half for others */