Mercurial > dwindows
comparison gtk/dw.c @ 1833:b35e041fc114
Fixed dw_bitmapbutton_new_from_data(); was missing the save of the bitmap image reference.
Also changed dwtest.c to test dw_window_set_bitmap_from*() functions.
author | mhessling@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Thu, 01 Nov 2012 00:55:30 +0000 |
parents | ce7543633fef |
children | ca6ef85fffc5 |
comparison
equal
deleted
inserted
replaced
1832:cd4ff1eb34a3 | 1833:b35e041fc114 |
---|---|
1404 if(work.window) | 1404 if(work.window) |
1405 { | 1405 { |
1406 int (*keypressfunc)(HWND, char, int, int, void *, char *) = work.func; | 1406 int (*keypressfunc)(HWND, char, int, int, void *, char *) = work.func; |
1407 guint32 unichar = gdk_keyval_to_unicode(event->keyval); | 1407 guint32 unichar = gdk_keyval_to_unicode(event->keyval); |
1408 char utf8[7] = { 0 }; | 1408 char utf8[7] = { 0 }; |
1409 | 1409 |
1410 g_unichar_to_utf8(unichar, utf8); | 1410 g_unichar_to_utf8(unichar, utf8); |
1411 | 1411 |
1412 retval = keypressfunc(work.window, *event->string, event->keyval, | 1412 retval = keypressfunc(work.window, *event->string, event->keyval, |
1413 event->state & (GDK_CONTROL_MASK | GDK_SHIFT_MASK | GDK_MOD1_MASK), work.data, utf8); | 1413 event->state & (GDK_CONTROL_MASK | GDK_SHIFT_MASK | GDK_MOD1_MASK), work.data, utf8); |
1414 } | 1414 } |
2074 } | 2074 } |
2075 #endif | 2075 #endif |
2076 | 2076 |
2077 static GStaticRecMutex _dw_gdk_lock; | 2077 static GStaticRecMutex _dw_gdk_lock; |
2078 | 2078 |
2079 static void _dw_gdk_lock_enter(void) | 2079 static void _dw_gdk_lock_enter(void) |
2080 { | 2080 { |
2081 g_static_rec_mutex_lock(&_dw_gdk_lock); | 2081 g_static_rec_mutex_lock(&_dw_gdk_lock); |
2082 } | 2082 } |
2083 | 2083 |
2084 static void _dw_gdk_lock_leave(void) | 2084 static void _dw_gdk_lock_leave(void) |
2085 { | 2085 { |
2086 g_static_rec_mutex_unlock(&_dw_gdk_lock); | 2086 g_static_rec_mutex_unlock(&_dw_gdk_lock); |
2087 } | 2087 } |
2088 | 2088 |
2089 /* | 2089 /* |
2112 if(argc && argv && *argc > 0 && (*argv)[0]) | 2112 if(argc && argv && *argc > 0 && (*argv)[0]) |
2113 { | 2113 { |
2114 char *pathcopy = strdup((*argv)[0]); | 2114 char *pathcopy = strdup((*argv)[0]); |
2115 char *pos = strrchr(pathcopy, '/'); | 2115 char *pos = strrchr(pathcopy, '/'); |
2116 char *binname = pathcopy; | 2116 char *binname = pathcopy; |
2117 | 2117 |
2118 /* If we have a / then... | 2118 /* If we have a / then... |
2119 * the binary name should be at the end. | 2119 * the binary name should be at the end. |
2120 */ | 2120 */ |
2121 if(pos) | 2121 if(pos) |
2122 { | 2122 { |
2123 binname = pos + 1; | 2123 binname = pos + 1; |
2124 *pos = 0; | 2124 *pos = 0; |
2125 } | 2125 } |
2126 | 2126 |
2127 if(*binname) | 2127 if(*binname) |
2128 { | 2128 { |
2129 char *binpos = strstr(pathcopy, "/bin"); | 2129 char *binpos = strstr(pathcopy, "/bin"); |
2130 | 2130 |
2131 if(binpos) | 2131 if(binpos) |
2132 strncpy(_dw_share_path, pathcopy, (size_t)(binpos - pathcopy)); | 2132 strncpy(_dw_share_path, pathcopy, (size_t)(binpos - pathcopy)); |
2133 else | 2133 else |
2134 strcpy(_dw_share_path, "/usr/local"); | 2134 strcpy(_dw_share_path, "/usr/local"); |
2135 strcat(_dw_share_path, "/share/"); | 2135 strcat(_dw_share_path, "/share/"); |
2148 #endif | 2148 #endif |
2149 #if GTK_MAJOR_VERSION > 1 | 2149 #if GTK_MAJOR_VERSION > 1 |
2150 g_static_rec_mutex_init(&_dw_gdk_lock); | 2150 g_static_rec_mutex_init(&_dw_gdk_lock); |
2151 | 2151 |
2152 gdk_threads_set_lock_functions(G_CALLBACK(_dw_gdk_lock_enter), G_CALLBACK(_dw_gdk_lock_leave)); | 2152 gdk_threads_set_lock_functions(G_CALLBACK(_dw_gdk_lock_enter), G_CALLBACK(_dw_gdk_lock_leave)); |
2153 | 2153 |
2154 gdk_threads_init(); | 2154 gdk_threads_init(); |
2155 #endif | 2155 #endif |
2156 | 2156 |
2157 gtk_init(argc, argv); | 2157 gtk_init(argc, argv); |
2158 #ifdef USE_IMLIB | 2158 #ifdef USE_IMLIB |
2254 gettimeofday(&tv, NULL); | 2254 gettimeofday(&tv, NULL); |
2255 | 2255 |
2256 while(((tv.tv_sec - start.tv_sec)*1000) + ((tv.tv_usec - start.tv_usec)/1000) <= milliseconds) | 2256 while(((tv.tv_sec - start.tv_sec)*1000) + ((tv.tv_usec - start.tv_usec)/1000) <= milliseconds) |
2257 { | 2257 { |
2258 int _locked_by_me = FALSE; | 2258 int _locked_by_me = FALSE; |
2259 | 2259 |
2260 if(orig == (pthread_t)-1) | 2260 if(orig == (pthread_t)-1) |
2261 { | 2261 { |
2262 if(!pthread_getspecific(_dw_mutex_key)) | 2262 if(!pthread_getspecific(_dw_mutex_key)) |
2263 { | 2263 { |
2264 gdk_threads_enter(); | 2264 gdk_threads_enter(); |
2293 void API dw_main_iteration(void) | 2293 void API dw_main_iteration(void) |
2294 { | 2294 { |
2295 pthread_t orig = _dw_thread; | 2295 pthread_t orig = _dw_thread; |
2296 pthread_t curr = pthread_self(); | 2296 pthread_t curr = pthread_self(); |
2297 int _locked_by_me = FALSE; | 2297 int _locked_by_me = FALSE; |
2298 | 2298 |
2299 if(_dw_thread == (pthread_t)-1) | 2299 if(_dw_thread == (pthread_t)-1) |
2300 { | 2300 { |
2301 if(!pthread_getspecific(_dw_mutex_key)) | 2301 if(!pthread_getspecific(_dw_mutex_key)) |
2302 { | 2302 { |
2303 gdk_threads_enter(); | 2303 gdk_threads_enter(); |
2886 | 2886 |
2887 /* Handle the invisible event box if it exists */ | 2887 /* Handle the invisible event box if it exists */ |
2888 if(eventbox && GTK_IS_WIDGET(eventbox)) | 2888 if(eventbox && GTK_IS_WIDGET(eventbox)) |
2889 handle2 = eventbox; | 2889 handle2 = eventbox; |
2890 | 2890 |
2891 /* Check if we are removing a widget from a box */ | 2891 /* Check if we are removing a widget from a box */ |
2892 if((box = gtk_widget_get_parent(handle2)) && GTK_IS_TABLE(box)) | 2892 if((box = gtk_widget_get_parent(handle2)) && GTK_IS_TABLE(box)) |
2893 { | 2893 { |
2894 /* Get the number of items in the box... */ | 2894 /* Get the number of items in the box... */ |
2895 int boxcount = GPOINTER_TO_INT(gtk_object_get_data(GTK_OBJECT(box), "_dw_boxcount")); | 2895 int boxcount = GPOINTER_TO_INT(gtk_object_get_data(GTK_OBJECT(box), "_dw_boxcount")); |
2896 int boxtype = GPOINTER_TO_INT(gtk_object_get_data(GTK_OBJECT(box), "_dw_boxtype")); | 2896 int boxtype = GPOINTER_TO_INT(gtk_object_get_data(GTK_OBJECT(box), "_dw_boxtype")); |
2897 gint pos; | 2897 gint pos; |
2898 | 2898 |
2899 gtk_container_child_get(GTK_CONTAINER(box), handle2, boxtype == DW_VERT ? "top-attach" : "left-attach", &pos, NULL); | 2899 gtk_container_child_get(GTK_CONTAINER(box), handle2, boxtype == DW_VERT ? "top-attach" : "left-attach", &pos, NULL); |
2900 gtk_widget_destroy(handle2); | 2900 gtk_widget_destroy(handle2); |
2901 | 2901 |
2902 /* If we are destroying the last item in the box this isn't necessary */ | 2902 /* If we are destroying the last item in the box this isn't necessary */ |
2903 if((pos+1) < boxcount) | 2903 if((pos+1) < boxcount) |
2904 { | 2904 { |
2905 /* If we need to contract the table, reposition all the children */ | 2905 /* If we need to contract the table, reposition all the children */ |
2906 gtk_container_forall(GTK_CONTAINER(box),_rearrange_table_destroy, GINT_TO_POINTER(boxtype == DW_VERT ? pos : -(pos+1))); | 2906 gtk_container_forall(GTK_CONTAINER(box),_rearrange_table_destroy, GINT_TO_POINTER(boxtype == DW_VERT ? pos : -(pos+1))); |
2907 } | 2907 } |
2908 | 2908 |
2909 if(boxcount > 0) | 2909 if(boxcount > 0) |
2910 { | 2910 { |
2911 /* Decrease the count by 1 */ | 2911 /* Decrease the count by 1 */ |
2912 boxcount--; | 2912 boxcount--; |
2913 gtk_object_set_data(GTK_OBJECT(box), "_dw_boxcount", GINT_TO_POINTER(boxcount)); | 2913 gtk_object_set_data(GTK_OBJECT(box), "_dw_boxcount", GINT_TO_POINTER(boxcount)); |
2914 } | 2914 } |
2915 | 2915 |
2916 /* If we aren't trying to resize the table to 0... */ | 2916 /* If we aren't trying to resize the table to 0... */ |
2917 if(boxcount > 0) | 2917 if(boxcount > 0) |
2918 { | 2918 { |
2919 /* Contract the table to the size we need */ | 2919 /* Contract the table to the size we need */ |
2920 gtk_table_resize(GTK_TABLE(box), boxtype == DW_VERT ? boxcount : 1, boxtype == DW_VERT ? 1 : boxcount); | 2920 gtk_table_resize(GTK_TABLE(box), boxtype == DW_VERT ? boxcount : 1, boxtype == DW_VERT ? 1 : boxcount); |
2921 } | 2921 } |
2922 } | 2922 } |
2923 else | 2923 else |
2924 { | 2924 { |
2925 /* Finally destroy the widget */ | 2925 /* Finally destroy the widget */ |
2926 gtk_widget_destroy(handle2); | 2926 gtk_widget_destroy(handle2); |
2927 } | 2927 } |
2928 } | 2928 } |
2929 DW_MUTEX_UNLOCK; | 2929 DW_MUTEX_UNLOCK; |
2930 return 0; | 2930 return 0; |
3589 flags |= GDK_DECOR_BORDER; | 3589 flags |= GDK_DECOR_BORDER; |
3590 | 3590 |
3591 #if GTK_MAJOR_VERSION > 1 | 3591 #if GTK_MAJOR_VERSION > 1 |
3592 if(flStyle & DW_FCF_MAXIMIZE) | 3592 if(flStyle & DW_FCF_MAXIMIZE) |
3593 gtk_window_maximize(GTK_WINDOW(tmp)); | 3593 gtk_window_maximize(GTK_WINDOW(tmp)); |
3594 | 3594 |
3595 if(flStyle & DW_FCF_MINIMIZE) | 3595 if(flStyle & DW_FCF_MINIMIZE) |
3596 gtk_window_iconify(GTK_WINDOW(tmp)); | 3596 gtk_window_iconify(GTK_WINDOW(tmp)); |
3597 #endif | 3597 #endif |
3598 | 3598 |
3599 #if GTK_CHECK_VERSION(2,10,0) | 3599 #if GTK_CHECK_VERSION(2,10,0) |
4647 | 4647 |
4648 if ( bitmap ) | 4648 if ( bitmap ) |
4649 { | 4649 { |
4650 dw_window_set_bitmap_from_data(bitmap, 0, data, len); | 4650 dw_window_set_bitmap_from_data(bitmap, 0, data, len); |
4651 gtk_container_add (GTK_CONTAINER(tmp), bitmap); | 4651 gtk_container_add (GTK_CONTAINER(tmp), bitmap); |
4652 g_object_set_data(GTK_OBJECT(tmp), "_dw_bitmap", bitmap); | |
4652 } | 4653 } |
4653 gtk_widget_show(tmp); | 4654 gtk_widget_show(tmp); |
4654 _create_tooltip(tmp, text); | 4655 _create_tooltip(tmp, text); |
4655 gtk_object_set_data(GTK_OBJECT(tmp), "_dw_id", GINT_TO_POINTER(id)); | 4656 gtk_object_set_data(GTK_OBJECT(tmp), "_dw_id", GINT_TO_POINTER(id)); |
4656 DW_MUTEX_UNLOCK; | 4657 DW_MUTEX_UNLOCK; |
6999 { | 7000 { |
7000 if(ret) | 7001 if(ret) |
7001 { | 7002 { |
7002 int pwidth = gdk_pixbuf_get_width(ret); | 7003 int pwidth = gdk_pixbuf_get_width(ret); |
7003 int pheight = gdk_pixbuf_get_height(ret); | 7004 int pheight = gdk_pixbuf_get_height(ret); |
7004 | 7005 |
7005 if(pwidth > 24 || pheight > 24) | 7006 if(pwidth > 24 || pheight > 24) |
7006 { | 7007 { |
7007 GdkPixbuf *orig = ret; | 7008 GdkPixbuf *orig = ret; |
7008 ret = gdk_pixbuf_scale_simple(ret, pwidth > 24 ? 24 : pwidth, pheight > 24 ? 24 : pheight, GDK_INTERP_BILINEAR); | 7009 ret = gdk_pixbuf_scale_simple(ret, pwidth > 24 ? 24 : pwidth, pheight > 24 ? 24 : pheight, GDK_INTERP_BILINEAR); |
7009 g_object_unref(G_OBJECT(orig)); | 7010 g_object_unref(G_OBJECT(orig)); |
7354 | 7355 |
7355 if(flag & DW_CFA_BITMAPORICON) | 7356 if(flag & DW_CFA_BITMAPORICON) |
7356 { | 7357 { |
7357 GdkBitmap *bitmap = NULL; | 7358 GdkBitmap *bitmap = NULL; |
7358 GdkPixmap *pixmap = NULL; | 7359 GdkPixmap *pixmap = NULL; |
7359 | 7360 |
7360 if(data) | 7361 if(data) |
7361 { | 7362 { |
7362 HICN hicon = *((HICN *)data); | 7363 HICN hicon = *((HICN *)data); |
7363 pixmap = _find_pixmap(&bitmap, hicon, clist, NULL, NULL); | 7364 pixmap = _find_pixmap(&bitmap, hicon, clist, NULL, NULL); |
7364 } | 7365 } |
7366 } | 7367 } |
7367 else if(flag & DW_CFA_STRINGANDICON) | 7368 else if(flag & DW_CFA_STRINGANDICON) |
7368 { | 7369 { |
7369 GdkBitmap *bitmap = NULL; | 7370 GdkBitmap *bitmap = NULL; |
7370 GdkPixmap *pixmap = NULL; | 7371 GdkPixmap *pixmap = NULL; |
7371 | 7372 |
7372 if(data) | 7373 if(data) |
7373 { | 7374 { |
7374 HICN hicon = *((HICN *)data); | 7375 HICN hicon = *((HICN *)data); |
7375 pixmap = _find_pixmap(&bitmap, hicon, clist, NULL, NULL); | 7376 pixmap = _find_pixmap(&bitmap, hicon, clist, NULL, NULL); |
7376 } | 7377 } |
8396 { | 8397 { |
8397 GdkColor *foreground = pthread_getspecific(_dw_fg_color_key); | 8398 GdkColor *foreground = pthread_getspecific(_dw_fg_color_key); |
8398 | 8399 |
8399 if(flags & DW_DRAW_NOAA) | 8400 if(flags & DW_DRAW_NOAA) |
8400 cairo_set_antialias(cr, CAIRO_ANTIALIAS_NONE); | 8401 cairo_set_antialias(cr, CAIRO_ANTIALIAS_NONE); |
8401 | 8402 |
8402 gdk_cairo_set_source_color (cr, foreground); | 8403 gdk_cairo_set_source_color (cr, foreground); |
8403 cairo_set_line_width(cr, 1); | 8404 cairo_set_line_width(cr, 1); |
8404 cairo_move_to(cr, x[0], y[0]); | 8405 cairo_move_to(cr, x[0], y[0]); |
8405 for(i=1;i<npoints;i++) | 8406 for(i=1;i<npoints;i++) |
8406 { | 8407 { |
8460 { | 8461 { |
8461 GdkColor *foreground = pthread_getspecific(_dw_fg_color_key); | 8462 GdkColor *foreground = pthread_getspecific(_dw_fg_color_key); |
8462 | 8463 |
8463 if(flags & DW_DRAW_NOAA) | 8464 if(flags & DW_DRAW_NOAA) |
8464 cairo_set_antialias(cr, CAIRO_ANTIALIAS_NONE); | 8465 cairo_set_antialias(cr, CAIRO_ANTIALIAS_NONE); |
8465 | 8466 |
8466 gdk_cairo_set_source_color (cr, foreground); | 8467 gdk_cairo_set_source_color (cr, foreground); |
8467 cairo_set_line_width(cr, 1); | 8468 cairo_set_line_width(cr, 1); |
8468 cairo_move_to(cr, x, y); | 8469 cairo_move_to(cr, x, y); |
8469 cairo_line_to(cr, x, y + height); | 8470 cairo_line_to(cr, x, y + height); |
8470 cairo_line_to(cr, x + width, y + height); | 8471 cairo_line_to(cr, x + width, y + height); |
8523 int width = abs(x2-x1); | 8524 int width = abs(x2-x1); |
8524 float scale = fabs((float)(y2-y1))/(float)width; | 8525 float scale = fabs((float)(y2-y1))/(float)width; |
8525 | 8526 |
8526 if(flags & DW_DRAW_NOAA) | 8527 if(flags & DW_DRAW_NOAA) |
8527 cairo_set_antialias(cr, CAIRO_ANTIALIAS_NONE); | 8528 cairo_set_antialias(cr, CAIRO_ANTIALIAS_NONE); |
8528 | 8529 |
8529 gdk_cairo_set_source_color (cr, foreground); | 8530 gdk_cairo_set_source_color (cr, foreground); |
8530 cairo_set_line_width(cr, 1); | 8531 cairo_set_line_width(cr, 1); |
8531 if(scale != 1.0) | 8532 if(scale != 1.0) |
8532 cairo_scale(cr, 1.0, scale); | 8533 cairo_scale(cr, 1.0, scale); |
8533 if(flags & DW_DRAW_FULL) | 8534 if(flags & DW_DRAW_FULL) |
10167 | 10168 |
10168 /* Try to figure out the contents for Listbox and Container */ | 10169 /* Try to figure out the contents for Listbox and Container */ |
10169 if(widget && (GTK_IS_LIST(widget) || GTK_IS_CLIST(widget))) | 10170 if(widget && (GTK_IS_LIST(widget) || GTK_IS_CLIST(widget))) |
10170 { | 10171 { |
10171 GtkRequisition req; | 10172 GtkRequisition req; |
10172 | 10173 |
10173 gtk_widget_size_request(widget, &req); | 10174 gtk_widget_size_request(widget, &req); |
10174 | 10175 |
10175 *thiswidth = req.width + 20; | 10176 *thiswidth = req.width + 20; |
10176 *thisheight = req.height + 20; | 10177 *thisheight = req.height + 20; |
10177 | 10178 |
10178 if(GTK_IS_CLIST(widget)) | 10179 if(GTK_IS_CLIST(widget)) |
10179 { | 10180 { |
10180 gint rowcount = GPOINTER_TO_INT(gtk_object_get_data(GTK_OBJECT(widget), "_dw_rowcount")); | 10181 gint rowcount = GPOINTER_TO_INT(gtk_object_get_data(GTK_OBJECT(widget), "_dw_rowcount")); |
10181 | 10182 |
10182 if(rowcount) | 10183 if(rowcount) |
10183 { | 10184 { |
10184 int height = 0; | 10185 int height = 0; |
10185 | 10186 |
10186 dw_font_text_extents_get(item, NULL, testtext, NULL, &height); | 10187 dw_font_text_extents_get(item, NULL, testtext, NULL, &height); |
10187 *thisheight += rowcount * height; | 10188 *thisheight += rowcount * height; |
10188 } | 10189 } |
10189 } | 10190 } |
10190 } | 10191 } |
10194 unsigned long bytes; | 10195 unsigned long bytes; |
10195 int height, width; | 10196 int height, width; |
10196 char *buf, *ptr; | 10197 char *buf, *ptr; |
10197 int basicwidth; | 10198 int basicwidth; |
10198 int wrap = (gtk_text_view_get_wrap_mode(GTK_TEXT_VIEW(widget)) == GTK_WRAP_WORD); | 10199 int wrap = (gtk_text_view_get_wrap_mode(GTK_TEXT_VIEW(widget)) == GTK_WRAP_WORD); |
10199 | 10200 |
10200 *thisheight = 20; | 10201 *thisheight = 20; |
10201 basicwidth = *thiswidth = 20; | 10202 basicwidth = *thiswidth = 20; |
10202 | 10203 |
10203 dw_mle_get_size(item, &bytes, NULL); | 10204 dw_mle_get_size(item, &bytes, NULL); |
10204 | 10205 |
10205 ptr = buf = alloca(bytes + 2); | 10206 ptr = buf = alloca(bytes + 2); |
10206 dw_mle_export(item, buf, 0, (int)bytes); | 10207 dw_mle_export(item, buf, 0, (int)bytes); |
10207 buf[bytes] = 0; | 10208 buf[bytes] = 0; |
10208 strcat(buf, "\r"); | 10209 strcat(buf, "\r"); |
10209 | 10210 |
10210 /* MLE */ | 10211 /* MLE */ |
10211 while((ptr = strstr(buf, "\r"))) | 10212 while((ptr = strstr(buf, "\r"))) |
10212 { | 10213 { |
10213 ptr[0] = 0; | 10214 ptr[0] = 0; |
10214 width = 0; | 10215 width = 0; |
10215 if(strlen(buf)) | 10216 if(strlen(buf)) |
10216 dw_font_text_extents_get(item, NULL, buf, &width, &height); | 10217 dw_font_text_extents_get(item, NULL, buf, &width, &height); |
10217 else | 10218 else |
10218 dw_font_text_extents_get(item, NULL, testtext, NULL, &height); | 10219 dw_font_text_extents_get(item, NULL, testtext, NULL, &height); |
10219 | 10220 |
10220 width += basicwidth; | 10221 width += basicwidth; |
10221 | 10222 |
10222 if(wrap && width > _DW_SCROLLED_MAX_WIDTH) | 10223 if(wrap && width > _DW_SCROLLED_MAX_WIDTH) |
10223 { | 10224 { |
10224 *thiswidth = _DW_SCROLLED_MAX_WIDTH; | 10225 *thiswidth = _DW_SCROLLED_MAX_WIDTH; |
10225 *thisheight += height * (width / _DW_SCROLLED_MAX_WIDTH); | 10226 *thisheight += height * (width / _DW_SCROLLED_MAX_WIDTH); |
10226 } | 10227 } |
10352 { | 10353 { |
10353 int thiswidth = width, thisheight = height; | 10354 int thiswidth = width, thisheight = height; |
10354 | 10355 |
10355 /* If it is a scrolled item and not expandable... | 10356 /* If it is a scrolled item and not expandable... |
10356 * Clamp to minumum or maximum. | 10357 * Clamp to minumum or maximum. |
10357 */ | 10358 */ |
10358 if(GTK_IS_SCROLLED_WINDOW(item) && ((width < 1 && !hsize) || (height < 1 && !vsize))) | 10359 if(GTK_IS_SCROLLED_WINDOW(item) && ((width < 1 && !hsize) || (height < 1 && !vsize))) |
10359 { | 10360 { |
10360 gint scrolledwidth = 0, scrolledheight = 0; | 10361 gint scrolledwidth = 0, scrolledheight = 0; |
10361 | 10362 |
10362 _get_scrolled_size(item, &scrolledwidth, &scrolledheight); | 10363 _get_scrolled_size(item, &scrolledwidth, &scrolledheight); |
10363 | 10364 |
10364 if(width < 1 && !hsize) | 10365 if(width < 1 && !hsize) |
10365 thiswidth = scrolledwidth; | 10366 thiswidth = scrolledwidth; |
10366 if(height < 1 && !vsize) | 10367 if(height < 1 && !vsize) |
10367 thisheight = scrolledheight; | 10368 thisheight = scrolledheight; |
10368 } | 10369 } |
10407 * DW_ERROR_NONE on success and DW_ERROR_GENERAL on failure. | 10408 * DW_ERROR_NONE on success and DW_ERROR_GENERAL on failure. |
10408 */ | 10409 */ |
10409 int API dw_box_unpack(HWND handle) | 10410 int API dw_box_unpack(HWND handle) |
10410 { | 10411 { |
10411 int _locked_by_me = FALSE, retcode = DW_ERROR_GENERAL; | 10412 int _locked_by_me = FALSE, retcode = DW_ERROR_GENERAL; |
10412 | 10413 |
10413 DW_MUTEX_LOCK; | 10414 DW_MUTEX_LOCK; |
10414 if(GTK_IS_WIDGET(handle)) | 10415 if(GTK_IS_WIDGET(handle)) |
10415 { | 10416 { |
10416 GtkWidget *box, *handle2 = handle; | 10417 GtkWidget *box, *handle2 = handle; |
10417 GtkWidget *eventbox = (GtkWidget *)gtk_object_get_data(GTK_OBJECT(handle), "_dw_eventbox"); | 10418 GtkWidget *eventbox = (GtkWidget *)gtk_object_get_data(GTK_OBJECT(handle), "_dw_eventbox"); |
10418 | 10419 |
10419 /* Handle the invisible event box if it exists */ | 10420 /* Handle the invisible event box if it exists */ |
10420 if(eventbox && GTK_IS_WIDGET(eventbox)) | 10421 if(eventbox && GTK_IS_WIDGET(eventbox)) |
10421 handle2 = eventbox; | 10422 handle2 = eventbox; |
10422 | 10423 |
10423 /* Check if we are removing a widget from a box */ | 10424 /* Check if we are removing a widget from a box */ |
10424 if((box = gtk_widget_get_parent(handle2)) && GTK_IS_TABLE(box)) | 10425 if((box = gtk_widget_get_parent(handle2)) && GTK_IS_TABLE(box)) |
10425 { | 10426 { |
10426 /* Get the number of items in the box... */ | 10427 /* Get the number of items in the box... */ |
10427 int boxcount = GPOINTER_TO_INT(gtk_object_get_data(GTK_OBJECT(box), "_dw_boxcount")); | 10428 int boxcount = GPOINTER_TO_INT(gtk_object_get_data(GTK_OBJECT(box), "_dw_boxcount")); |
10428 int boxtype = GPOINTER_TO_INT(gtk_object_get_data(GTK_OBJECT(box), "_dw_boxtype")); | 10429 int boxtype = GPOINTER_TO_INT(gtk_object_get_data(GTK_OBJECT(box), "_dw_boxtype")); |
10429 gint pos; | 10430 gint pos; |
10430 | 10431 |
10431 gtk_container_child_get(GTK_CONTAINER(box), handle2, boxtype == DW_VERT ? "top-attach" : "left-attach", &pos, NULL); | 10432 gtk_container_child_get(GTK_CONTAINER(box), handle2, boxtype == DW_VERT ? "top-attach" : "left-attach", &pos, NULL); |
10432 /* If we haven't incremented the reference count... raised it before removal */ | 10433 /* If we haven't incremented the reference count... raised it before removal */ |
10433 if(!gtk_object_get_data(GTK_OBJECT(handle2), "_dw_refed")) | 10434 if(!gtk_object_get_data(GTK_OBJECT(handle2), "_dw_refed")) |
10434 { | 10435 { |
10435 g_object_ref(G_OBJECT(handle2)); | 10436 g_object_ref(G_OBJECT(handle2)); |
10436 gtk_object_set_data(GTK_OBJECT(handle2), "_dw_refed", GINT_TO_POINTER(1)); | 10437 gtk_object_set_data(GTK_OBJECT(handle2), "_dw_refed", GINT_TO_POINTER(1)); |
10437 } | 10438 } |
10438 gtk_container_remove(GTK_CONTAINER(box), handle2); | 10439 gtk_container_remove(GTK_CONTAINER(box), handle2); |
10439 retcode = DW_ERROR_NONE; | 10440 retcode = DW_ERROR_NONE; |
10440 | 10441 |
10441 /* If we are destroying the last item in the box this isn't necessary */ | 10442 /* If we are destroying the last item in the box this isn't necessary */ |
10442 if((pos+1) < boxcount) | 10443 if((pos+1) < boxcount) |
10443 { | 10444 { |
10444 /* If we need to contract the table, reposition all the children */ | 10445 /* If we need to contract the table, reposition all the children */ |
10445 gtk_container_forall(GTK_CONTAINER(box),_rearrange_table_destroy, GINT_TO_POINTER(boxtype == DW_VERT ? pos : -(pos+1))); | 10446 gtk_container_forall(GTK_CONTAINER(box),_rearrange_table_destroy, GINT_TO_POINTER(boxtype == DW_VERT ? pos : -(pos+1))); |
10446 } | 10447 } |
10447 | 10448 |
10448 if(boxcount > 0) | 10449 if(boxcount > 0) |
10449 { | 10450 { |
10450 /* Decrease the count by 1 */ | 10451 /* Decrease the count by 1 */ |
10451 boxcount--; | 10452 boxcount--; |
10452 gtk_object_set_data(GTK_OBJECT(box), "_dw_boxcount", GINT_TO_POINTER(boxcount)); | 10453 gtk_object_set_data(GTK_OBJECT(box), "_dw_boxcount", GINT_TO_POINTER(boxcount)); |
10453 } | 10454 } |
10454 | 10455 |
10455 /* If we aren't trying to resize the table to 0... */ | 10456 /* If we aren't trying to resize the table to 0... */ |
10456 if(boxcount > 0) | 10457 if(boxcount > 0) |
10457 { | 10458 { |
10458 /* Contract the table to the size we need */ | 10459 /* Contract the table to the size we need */ |
10459 gtk_table_resize(GTK_TABLE(box), boxtype == DW_VERT ? boxcount : 1, boxtype == DW_VERT ? 1 : boxcount); | 10460 gtk_table_resize(GTK_TABLE(box), boxtype == DW_VERT ? boxcount : 1, boxtype == DW_VERT ? 1 : boxcount); |
10476 { | 10477 { |
10477 HWND retval = 0; | 10478 HWND retval = 0; |
10478 int _locked_by_me = FALSE; | 10479 int _locked_by_me = FALSE; |
10479 | 10480 |
10480 DW_MUTEX_LOCK; | 10481 DW_MUTEX_LOCK; |
10481 /* Check if we are removing a widget from a box */ | 10482 /* Check if we are removing a widget from a box */ |
10482 if(GTK_IS_TABLE(box)) | 10483 if(GTK_IS_TABLE(box)) |
10483 { | 10484 { |
10484 /* Get the number of items in the box... */ | 10485 /* Get the number of items in the box... */ |
10485 int boxcount = GPOINTER_TO_INT(gtk_object_get_data(GTK_OBJECT(box), "_dw_boxcount")); | 10486 int boxcount = GPOINTER_TO_INT(gtk_object_get_data(GTK_OBJECT(box), "_dw_boxcount")); |
10486 int boxtype = GPOINTER_TO_INT(gtk_object_get_data(GTK_OBJECT(box), "_dw_boxtype")); | 10487 int boxtype = GPOINTER_TO_INT(gtk_object_get_data(GTK_OBJECT(box), "_dw_boxtype")); |
10487 GList *children, *child; | 10488 GList *children, *child; |
10488 GtkWidget *item = NULL; | 10489 GtkWidget *item = NULL; |
10489 gint pos; | 10490 gint pos; |
10490 | 10491 |
10491 children = child = gtk_container_get_children(GTK_CONTAINER(box)); | 10492 children = child = gtk_container_get_children(GTK_CONTAINER(box)); |
10492 | 10493 |
10493 /* Locate the child with the correct attachment point in the table */ | 10494 /* Locate the child with the correct attachment point in the table */ |
10494 while(child) | 10495 while(child) |
10495 { | 10496 { |
10496 gtk_container_child_get(GTK_CONTAINER(box), (GtkWidget *)child->data, boxtype == DW_VERT ? "top-attach" : "left-attach", &pos, NULL); | 10497 gtk_container_child_get(GTK_CONTAINER(box), (GtkWidget *)child->data, boxtype == DW_VERT ? "top-attach" : "left-attach", &pos, NULL); |
10497 if(pos == index) | 10498 if(pos == index) |
10499 item = (GtkWidget *)child->data; | 10500 item = (GtkWidget *)child->data; |
10500 child = NULL; | 10501 child = NULL; |
10501 } | 10502 } |
10502 else | 10503 else |
10503 child = child->next; | 10504 child = child->next; |
10504 } | 10505 } |
10505 | 10506 |
10506 /* Free the returned list */ | 10507 /* Free the returned list */ |
10507 if(children) | 10508 if(children) |
10508 g_list_free(children); | 10509 g_list_free(children); |
10509 | 10510 |
10510 if(item) | 10511 if(item) |
10511 { | 10512 { |
10512 /* If we haven't incremented the reference count... raise it before removal */ | 10513 /* If we haven't incremented the reference count... raise it before removal */ |
10513 if(gtk_object_get_data(GTK_OBJECT(item), "_dw_padding")) | 10514 if(gtk_object_get_data(GTK_OBJECT(item), "_dw_padding")) |
10514 gtk_widget_destroy(item); | 10515 gtk_widget_destroy(item); |
10515 else | 10516 else |
10516 { | 10517 { |
10517 if(!gtk_object_get_data(GTK_OBJECT(item), "_dw_refed")) | 10518 if(!gtk_object_get_data(GTK_OBJECT(item), "_dw_refed")) |
10518 { | 10519 { |
10519 g_object_ref(G_OBJECT(item)); | 10520 g_object_ref(G_OBJECT(item)); |
10520 gtk_object_set_data(GTK_OBJECT(item), "_dw_refed", GINT_TO_POINTER(1)); | 10521 gtk_object_set_data(GTK_OBJECT(item), "_dw_refed", GINT_TO_POINTER(1)); |
10521 } | 10522 } |
10522 /* Remove the widget from the box */ | 10523 /* Remove the widget from the box */ |
10523 gtk_container_remove(GTK_CONTAINER(box), item); | 10524 gtk_container_remove(GTK_CONTAINER(box), item); |
10524 retval = item; | 10525 retval = item; |
10525 } | 10526 } |
10526 | 10527 |
10527 /* If we are destroying the last item in the box this isn't necessary */ | 10528 /* If we are destroying the last item in the box this isn't necessary */ |
10528 if((pos+1) < boxcount) | 10529 if((pos+1) < boxcount) |
10529 { | 10530 { |
10530 /* If we need to contract the table, reposition all the children */ | 10531 /* If we need to contract the table, reposition all the children */ |
10531 gtk_container_forall(GTK_CONTAINER(box),_rearrange_table_destroy, GINT_TO_POINTER(boxtype == DW_VERT ? pos : -(pos+1))); | 10532 gtk_container_forall(GTK_CONTAINER(box),_rearrange_table_destroy, GINT_TO_POINTER(boxtype == DW_VERT ? pos : -(pos+1))); |
10532 } | 10533 } |
10533 | 10534 |
10534 if(boxcount > 0) | 10535 if(boxcount > 0) |
10535 { | 10536 { |
10536 /* Decrease the count by 1 */ | 10537 /* Decrease the count by 1 */ |
10537 boxcount--; | 10538 boxcount--; |
10538 gtk_object_set_data(GTK_OBJECT(box), "_dw_boxcount", GINT_TO_POINTER(boxcount)); | 10539 gtk_object_set_data(GTK_OBJECT(box), "_dw_boxcount", GINT_TO_POINTER(boxcount)); |
10539 } | 10540 } |
10540 | 10541 |
10541 /* If we aren't trying to resize the table to 0... */ | 10542 /* If we aren't trying to resize the table to 0... */ |
10542 if(boxcount > 0) | 10543 if(boxcount > 0) |
10543 { | 10544 { |
10544 /* Contract the table to the size we need */ | 10545 /* Contract the table to the size we need */ |
10545 gtk_table_resize(GTK_TABLE(box), boxtype == DW_VERT ? boxcount : 1, boxtype == DW_VERT ? 1 : boxcount); | 10546 gtk_table_resize(GTK_TABLE(box), boxtype == DW_VERT ? boxcount : 1, boxtype == DW_VERT ? 1 : boxcount); |
10655 (SubstructureRedirectMask | SubstructureNotifyMask), | 10656 (SubstructureRedirectMask | SubstructureNotifyMask), |
10656 &xevent); | 10657 &xevent); |
10657 | 10658 |
10658 /* Connect a signal to look for the property change */ | 10659 /* Connect a signal to look for the property change */ |
10659 connid = gtk_signal_connect(GTK_OBJECT(window), "property_notify_event", GTK_SIGNAL_FUNC(_dw_property_notify), window->window); | 10660 connid = gtk_signal_connect(GTK_OBJECT(window), "property_notify_event", GTK_SIGNAL_FUNC(_dw_property_notify), window->window); |
10660 | 10661 |
10661 /* Record the request time */ | 10662 /* Record the request time */ |
10662 time(&extents_time); | 10663 time(&extents_time); |
10663 | 10664 |
10664 /* Look for the property notify event */ | 10665 /* Look for the property notify event */ |
10665 do | 10666 do |
10666 { | 10667 { |
10667 dw_main_iteration(); | 10668 dw_main_iteration(); |
10668 time(&currtime); | 10669 time(&currtime); |
10669 } | 10670 } |
10670 while(currtime - extents_time < 2); | 10671 while(currtime - extents_time < 2); |
10671 | 10672 |
10672 /* Remove the signal handler now that we are done */ | 10673 /* Remove the signal handler now that we are done */ |
10673 gtk_signal_disconnect(GTK_OBJECT(window), connid); | 10674 gtk_signal_disconnect(GTK_OBJECT(window), connid); |
10674 } | 10675 } |
10675 | 10676 |
10676 /* Attempt to retrieve window's frame extents. */ | 10677 /* Attempt to retrieve window's frame extents. */ |
10774 | 10775 |
10775 DW_MUTEX_LOCK; | 10776 DW_MUTEX_LOCK; |
10776 if(GTK_IS_SCROLLED_WINDOW(handle)) | 10777 if(GTK_IS_SCROLLED_WINDOW(handle)) |
10777 { | 10778 { |
10778 gint scrolledwidth, scrolledheight; | 10779 gint scrolledwidth, scrolledheight; |
10779 | 10780 |
10780 _get_scrolled_size(handle, &scrolledwidth, &scrolledheight); | 10781 _get_scrolled_size(handle, &scrolledwidth, &scrolledheight); |
10781 | 10782 |
10782 if(width) | 10783 if(width) |
10783 *width = scrolledwidth; | 10784 *width = scrolledwidth; |
10784 if(height) | 10785 if(height) |
10785 *height = scrolledheight; | 10786 *height = scrolledheight; |
10786 } | 10787 } |
13699 * or NULL on failure. | 13700 * or NULL on failure. |
13700 */ | 13701 */ |
13701 wchar_t * API dw_utf8_to_wchar(char *utf8string) | 13702 wchar_t * API dw_utf8_to_wchar(char *utf8string) |
13702 { | 13703 { |
13703 wchar_t *retval = NULL, *freeme; | 13704 wchar_t *retval = NULL, *freeme; |
13704 | 13705 |
13705 if(sizeof(wchar_t) == sizeof(gunichar)) | 13706 if(sizeof(wchar_t) == sizeof(gunichar)) |
13706 freeme = retval = (wchar_t *)g_utf8_to_ucs4(utf8string, -1, NULL, NULL, NULL); | 13707 freeme = retval = (wchar_t *)g_utf8_to_ucs4(utf8string, -1, NULL, NULL, NULL); |
13707 else if(sizeof(wchar_t) == sizeof(gunichar2)) | 13708 else if(sizeof(wchar_t) == sizeof(gunichar2)) |
13708 freeme = retval = (wchar_t *)g_utf8_to_utf16(utf8string, -1, NULL, NULL, NULL); | 13709 freeme = retval = (wchar_t *)g_utf8_to_utf16(utf8string, -1, NULL, NULL, NULL); |
13709 if(retval) | 13710 if(retval) |
13710 { | 13711 { |
13711 retval = wcsdup(retval); | 13712 retval = wcsdup(retval); |
13712 g_free(freeme); | 13713 g_free(freeme); |
13723 * or NULL on failure. | 13724 * or NULL on failure. |
13724 */ | 13725 */ |
13725 char * API dw_wchar_to_utf8(wchar_t *wstring) | 13726 char * API dw_wchar_to_utf8(wchar_t *wstring) |
13726 { | 13727 { |
13727 char *retval = NULL, *freeme; | 13728 char *retval = NULL, *freeme; |
13728 | 13729 |
13729 if(sizeof(wchar_t) == sizeof(gunichar)) | 13730 if(sizeof(wchar_t) == sizeof(gunichar)) |
13730 freeme = retval = g_ucs4_to_utf8((gunichar *)wstring, -1, NULL, NULL, NULL); | 13731 freeme = retval = g_ucs4_to_utf8((gunichar *)wstring, -1, NULL, NULL, NULL); |
13731 else if(sizeof(wchar_t) == sizeof(gunichar2)) | 13732 else if(sizeof(wchar_t) == sizeof(gunichar2)) |
13732 freeme = retval = g_utf16_to_utf8((gunichar2 *)wstring, -1, NULL, NULL, NULL); | 13733 freeme = retval = g_utf16_to_utf8((gunichar2 *)wstring, -1, NULL, NULL, NULL); |
13733 if(retval) | 13734 if(retval) |
13734 { | 13735 { |
13735 retval = strdup(retval); | 13736 retval = strdup(retval); |
13736 g_free(freeme); | 13737 g_free(freeme); |
13737 } | 13738 } |
13738 return retval; | 13739 return retval; |
13739 } | 13740 } |
13740 | 13741 |