Mercurial > dwindows
comparison gtk/dw.c @ 1561:46e34bd92336
Implemented guessing size of MLE on GTK... not as accurate as the other platforms...
but until the bugs are fixed in GTK this is the best we can do.
Also make dw_window_get_preferred_size() return our guesses.
Added a piece of safety code on Windows... just in case.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Tue, 17 Jan 2012 18:18:00 +0000 |
parents | 4a9c574d5c17 |
children | 9a8aa230a538 |
comparison
equal
deleted
inserted
replaced
1560:ee47bda26916 | 1561:46e34bd92336 |
---|---|
10017 gtk_container_child_set(cont, widget, "top-attach", (oldpos + 1), "bottom-attach", (oldpos+2), NULL); | 10017 gtk_container_child_set(cont, widget, "top-attach", (oldpos + 1), "bottom-attach", (oldpos+2), NULL); |
10018 } | 10018 } |
10019 } | 10019 } |
10020 } | 10020 } |
10021 | 10021 |
10022 /* Internal function to get the recommended size of scrolled items */ | |
10023 void _get_scrolled_size(GtkWidget *item, gint *thiswidth, gint *thisheight) | |
10024 { | |
10025 GtkWidget *widget = gtk_object_get_user_data(GTK_OBJECT(item)); | |
10026 | |
10027 /* Try to figure out the contents for MLE and Container */ | |
10028 if(widget && (GTK_IS_TEXT_VIEW(widget) || GTK_IS_CLIST(widget))) | |
10029 { | |
10030 if(GTK_IS_CLIST(widget)) | |
10031 { | |
10032 GtkRequisition req; | |
10033 | |
10034 gtk_widget_size_request(widget, &req); | |
10035 | |
10036 *thiswidth = req.width + 20; | |
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, "\n"); | |
10057 | |
10058 /* MLE */ | |
10059 while((ptr = strstr(buf, "\n"))) | |
10060 { | |
10061 ptr[0] = 0; | |
10062 width = 0; | |
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 buf = &ptr[1]; | |
10082 } | |
10083 } | |
10084 } | |
10085 else | |
10086 { | |
10087 /* Set to max for others */ | |
10088 *thiswidth = _DW_SCROLLED_MAX_WIDTH; | |
10089 *thisheight = _DW_SCROLLED_MAX_HEIGHT; | |
10090 } | |
10091 if(*thiswidth < _DW_SCROLLED_MIN_WIDTH) | |
10092 *thiswidth = _DW_SCROLLED_MIN_WIDTH; | |
10093 if(*thiswidth > _DW_SCROLLED_MAX_WIDTH) | |
10094 *thiswidth = _DW_SCROLLED_MAX_WIDTH; | |
10095 if(*thisheight < _DW_SCROLLED_MIN_HEIGHT) | |
10096 *thisheight = _DW_SCROLLED_MIN_HEIGHT; | |
10097 if(*thisheight > _DW_SCROLLED_MAX_HEIGHT) | |
10098 *thisheight = _DW_SCROLLED_MAX_HEIGHT; | |
10099 } | |
10100 | |
10022 /* Internal box packing function called by the other 3 functions */ | 10101 /* Internal box packing function called by the other 3 functions */ |
10023 void _dw_box_pack(HWND box, HWND item, int index, int width, int height, int hsize, int vsize, int pad, char *funcname) | 10102 void _dw_box_pack(HWND box, HWND item, int index, int width, int height, int hsize, int vsize, int pad, char *funcname) |
10024 { | 10103 { |
10025 int warn = FALSE, _locked_by_me = FALSE; | 10104 int warn = FALSE, _locked_by_me = FALSE; |
10026 GtkWidget *tmp, *tmpitem; | 10105 GtkWidget *tmp, *tmpitem; |
10119 int thiswidth = width, thisheight = height; | 10198 int thiswidth = width, thisheight = height; |
10120 | 10199 |
10121 /* If it is a scrolled item and not expandable... | 10200 /* If it is a scrolled item and not expandable... |
10122 * Clamp to minumum or maximum. | 10201 * Clamp to minumum or maximum. |
10123 */ | 10202 */ |
10124 if(GTK_IS_SCROLLED_WINDOW(item)) | 10203 if(GTK_IS_SCROLLED_WINDOW(item) && ((width < 1 && !hsize) || (height < 1 && !vsize))) |
10125 { | 10204 { |
10126 GtkWidget *widget = gtk_object_get_user_data(GTK_OBJECT(item)); | 10205 gint scrolledwidth = 0, scrolledheight = 0; |
10127 | 10206 |
10128 /* Try to figure out the contents for MLE and Container */ | 10207 _get_scrolled_size(item, &scrolledwidth, &scrolledheight); |
10129 if(widget && (GTK_IS_TEXT_VIEW(widget) || GTK_IS_CLIST(widget))) | 10208 |
10130 { | 10209 if(width < 1 && !hsize) |
10131 GtkRequisition req; | 10210 thiswidth = scrolledwidth; |
10132 | 10211 if(height < 1 && !vsize) |
10133 gtk_widget_size_request(widget, &req); | 10212 thisheight = scrolledheight; |
10134 | |
10135 if(thiswidth < 1 && !hsize) | |
10136 { | |
10137 thiswidth = req.width + 20; | |
10138 if(thiswidth < _DW_SCROLLED_MIN_WIDTH) | |
10139 thiswidth = _DW_SCROLLED_MIN_WIDTH; | |
10140 if(thiswidth > _DW_SCROLLED_MAX_WIDTH) | |
10141 thiswidth = _DW_SCROLLED_MAX_WIDTH; | |
10142 } | |
10143 if(thisheight < 1 && !vsize) | |
10144 { | |
10145 thisheight = req.height + 20; | |
10146 if(thisheight < _DW_SCROLLED_MIN_HEIGHT) | |
10147 thisheight = _DW_SCROLLED_MIN_HEIGHT; | |
10148 if(thisheight > _DW_SCROLLED_MAX_HEIGHT) | |
10149 thisheight = _DW_SCROLLED_MAX_HEIGHT; | |
10150 } | |
10151 } | |
10152 else | |
10153 { | |
10154 /* Set to max for others */ | |
10155 if(thiswidth < 1 && !hsize) | |
10156 thiswidth = _DW_SCROLLED_MAX_WIDTH; | |
10157 if(thisheight < 1 && !vsize) | |
10158 thisheight = _DW_SCROLLED_MAX_HEIGHT; | |
10159 } | |
10160 } | 10213 } |
10161 gtk_widget_set_usize(item, thiswidth, thisheight); | 10214 gtk_widget_set_usize(item, thiswidth, thisheight); |
10162 } | 10215 } |
10163 if(GTK_IS_RADIO_BUTTON(item)) | 10216 if(GTK_IS_RADIO_BUTTON(item)) |
10164 { | 10217 { |
10406 { | 10459 { |
10407 GtkRequisition req; | 10460 GtkRequisition req; |
10408 int _locked_by_me = FALSE; | 10461 int _locked_by_me = FALSE; |
10409 | 10462 |
10410 DW_MUTEX_LOCK; | 10463 DW_MUTEX_LOCK; |
10411 gtk_widget_size_request(handle, &req); | 10464 if(GTK_IS_SCROLLED_WINDOW(handle)) |
10412 if(width) | 10465 { |
10413 *width = req.width; | 10466 gint scrolledwidth, scrolledheight; |
10414 if(height) | 10467 |
10415 *height = req.height; | 10468 _get_scrolled_size(handle, &scrolledwidth, &scrolledheight); |
10469 | |
10470 if(width) | |
10471 *width = scrolledwidth; | |
10472 if(height) | |
10473 *height = scrolledheight; | |
10474 } | |
10475 else | |
10476 { | |
10477 gtk_widget_size_request(handle, &req); | |
10478 if(width) | |
10479 *width = req.width; | |
10480 if(height) | |
10481 *height = req.height; | |
10482 } | |
10416 DW_MUTEX_UNLOCK; | 10483 DW_MUTEX_UNLOCK; |
10417 } | 10484 } |
10418 | 10485 |
10419 /* | 10486 /* |
10420 * Returns the width of the screen. | 10487 * Returns the width of the screen. |