comparison gtk/dw.c @ 47:997e9ed670ef

Fixes for box alignment problem on OS/2, crash in dw_bitmap_new() on unix with certain versions of imlib. And other various code cleanups. Also initial code for eventual conversion to gdk-pixbuf on unix from imlib.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Fri, 02 Nov 2001 10:31:29 +0000
parents 30d091bc7899
children 16eac0f8b45f
comparison
equal deleted inserted replaced
46:30d091bc7899 47:997e9ed670ef
17 #include <sys/time.h> 17 #include <sys/time.h>
18 #include "config.h" 18 #include "config.h"
19 #include <gdk/gdkkeysyms.h> 19 #include <gdk/gdkkeysyms.h>
20 #ifdef USE_IMLIB 20 #ifdef USE_IMLIB
21 #include <gdk_imlib.h> 21 #include <gdk_imlib.h>
22 #elif defined(USE_PIXBUF)
23 #include <gdk-pixbuf/gdk-pixbuf.h>
24 #include <gdk-pixbuf/gdk-pixbuf-xlibrgb.h>
25 #include <gdk-pixbuf/gdk-pixbuf-xlib.h>
22 #endif 26 #endif
23 27
24 /* These are used for resource management */ 28 /* These are used for resource management */
25 #if defined(DW_RESOURCES) && !defined(BUILD_DLL) 29 #if defined(DW_RESOURCES) && !defined(BUILD_DLL)
26 extern DWResources _resources; 30 extern DWResources _resources;
49 }; 53 };
50 54
51 GdkColor _foreground = { 0, 0x0000, 0x0000, 0x0000 }; 55 GdkColor _foreground = { 0, 0x0000, 0x0000, 0x0000 };
52 GdkColor _background = { 0, 0xaaaa, 0xaaaa, 0xaaaa }; 56 GdkColor _background = { 0, 0xaaaa, 0xaaaa, 0xaaaa };
53 57
58 GtkWidget *last_window = NULL;
59
54 int _dw_file_active = 0, _dw_ignore_click = 0; 60 int _dw_file_active = 0, _dw_ignore_click = 0;
55 pthread_t _dw_thread = (pthread_t)-1; 61 pthread_t _dw_thread = (pthread_t)-1;
56 int _dw_mutex_locked = FALSE; 62 int _dw_mutex_locked = FALSE;
57 /* Use default border size for the default enlightenment theme */ 63 /* Use default border size for the default enlightenment theme */
58 int _dw_border_width = 12, _dw_border_height = 28; 64 int _dw_border_width = 12, _dw_border_height = 28;
59 65
60 #define DW_MUTEX_LOCK { if(pthread_self() != _dw_thread && _dw_mutex_locked == FALSE) { gdk_threads_enter(); _dw_mutex_locked = TRUE; _locked_by_me = TRUE; } } 66 #define DW_MUTEX_LOCK { if(pthread_self() != _dw_thread && _dw_mutex_locked == FALSE) { gdk_threads_enter(); _dw_mutex_locked = TRUE; _locked_by_me = TRUE; } }
61 #define DW_MUTEX_UNLOCK { if(pthread_self() != _dw_thread && _locked_by_me == TRUE) { gdk_threads_leave(); _dw_mutex_locked = FALSE; _locked_by_me = FALSE; } } 67 #define DW_MUTEX_UNLOCK { if(pthread_self() != _dw_thread && _locked_by_me == TRUE) { gdk_threads_leave(); _dw_mutex_locked = FALSE; _locked_by_me = FALSE; } }
62
63 /* Currently the non Imlib method does not work */
64 #ifndef USE_IMLIB
65 #define USE_IMLIB
66 #endif
67 68
68 #define DEFAULT_SIZE_WIDTH 12 69 #define DEFAULT_SIZE_WIDTH 12
69 #define DEFAULT_SIZE_HEIGHT 6 70 #define DEFAULT_SIZE_HEIGHT 6
70 #define DEFAULT_TITLEBAR_HEIGHT 22 71 #define DEFAULT_TITLEBAR_HEIGHT 22
71 72
453 } 454 }
454 455
455 if(data) 456 if(data)
456 { 457 {
457 GdkPixmap *icon_pixmap = NULL; 458 GdkPixmap *icon_pixmap = NULL;
458 #ifndef USE_IMLIB 459 #ifdef USE_IMLIB
459 GtkStyle *iconstyle; 460 gdk_imlib_data_to_pixmap((char **)data, &icon_pixmap, bitmap);
460 461 #elif defined(USE_PIXBUF)
461 /* hmmm why do we need the handle here? */ 462 icon_pixmap = (GdkPixmap *)gdk_pixbuf_new_from_xpm_data((const char **)data);
462 iconstyle = gtk_widget_get_style(handle);
463 if (!icon_pixmap)
464 icon_pixmap = gdk_pixmap_create_from_xpm_d(handle->window, bitmap, &iconstyle->bg[GTK_STATE_NORMAL], &data);
465 #else 463 #else
466 gdk_imlib_data_to_pixmap((char **)data, &icon_pixmap, bitmap); 464 icon_pixmap = gdk_pixmap_create_from_xpm_d(handle->window, bitmap, &_colors[DW_CLR_PALEGRAY], &data);
467 #endif 465 #endif
468 return icon_pixmap; 466 return icon_pixmap;
469 } 467 }
470 return NULL; 468 return NULL;
471 } 469 }
1173 GtkWidget *tmp; 1171 GtkWidget *tmp;
1174 int _locked_by_me = FALSE; 1172 int _locked_by_me = FALSE;
1175 int flags = 0; 1173 int flags = 0;
1176 1174
1177 DW_MUTEX_LOCK; 1175 DW_MUTEX_LOCK;
1178 tmp = gtk_window_new(GTK_WINDOW_TOPLEVEL); 1176 last_window = tmp = gtk_window_new(GTK_WINDOW_TOPLEVEL);
1179 1177
1180 gtk_window_set_title(GTK_WINDOW(tmp), title); 1178 gtk_window_set_title(GTK_WINDOW(tmp), title);
1181 if(!(flStyle & DW_FCF_SIZEBORDER)) 1179 if(!(flStyle & DW_FCF_SIZEBORDER))
1182 gtk_window_set_policy(GTK_WINDOW(tmp), FALSE, FALSE, TRUE); 1180 gtk_window_set_policy(GTK_WINDOW(tmp), FALSE, FALSE, TRUE);
1183 1181
1188 1186
1189 if(flStyle & DW_FCF_MINMAX) 1187 if(flStyle & DW_FCF_MINMAX)
1190 flags |= GDK_DECOR_MINIMIZE | GDK_DECOR_MAXIMIZE; 1188 flags |= GDK_DECOR_MINIMIZE | GDK_DECOR_MAXIMIZE;
1191 1189
1192 if(flStyle & DW_FCF_SIZEBORDER) 1190 if(flStyle & DW_FCF_SIZEBORDER)
1193 flags |= GDK_DECOR_RESIZEH; 1191 flags |= GDK_DECOR_RESIZEH | GDK_DECOR_BORDER;
1194 1192
1195 if(flStyle & DW_FCF_BORDER) 1193 if(flStyle & DW_FCF_BORDER || flStyle & DW_FCF_DLGBORDER)
1196 flags |= GDK_DECOR_BORDER; 1194 flags |= GDK_DECOR_BORDER;
1197 1195
1198 gdk_window_set_decorations(tmp->window, flags); 1196 gdk_window_set_decorations(tmp->window, flags);
1199 1197
1200 if(hwndOwner) 1198 if(hwndOwner)
1269 HWND dw_bitmap_new(unsigned long id) 1267 HWND dw_bitmap_new(unsigned long id)
1270 { 1268 {
1271 GdkPixmap *pixmap= NULL; 1269 GdkPixmap *pixmap= NULL;
1272 GdkBitmap *bitmap; 1270 GdkBitmap *bitmap;
1273 GtkWidget *tmp; 1271 GtkWidget *tmp;
1274 char * test_xpm[] = { 1272 static char * test_xpm[] = {
1275 "1 1 1 1", 1273 "1 1 2 1",
1276 " c None", 1274 " c None",
1277 " "}; 1275 ". c #FFFFFF",
1278 int _locked_by_me = FALSE; 1276 "."};
1279 1277 int _locked_by_me = FALSE;
1280 DW_MUTEX_LOCK; 1278
1281 #ifndef USE_IMLIB 1279 DW_MUTEX_LOCK;
1282 GtkStyle *iconstyle; 1280 #ifdef USE_IMLIB
1283 1281 gdk_imlib_data_to_pixmap(test_xpm, &pixmap, &bitmap);
1284 /* hmmm why do we need the handle here? */ 1282 #elif defined(USE_PIXBUF)
1285 iconstyle = gtk_widget_get_style(handle); 1283 pixmap = (GdkPixmap *)gdk_pixbuf_new_from_xpm_data((const char **)test_xpm);
1286 if (!pixmap)
1287 pixmap = gdk_pixmap_create_from_xpm_d(handle->window, &bitmap, &iconstyle->bg[GTK_STATE_NORMAL], &test_xpm);
1288 #else 1284 #else
1289 gdk_imlib_data_to_pixmap(test_xpm, &pixmap, &bitmap); 1285 gtk_widget_realize(last_window);
1286
1287 if(last_window)
1288 pixmap = gdk_pixmap_create_from_xpm_d(last_window->window, &bitmap, &_colors[DW_CLR_PALEGRAY], test_xpm);
1290 #endif 1289 #endif
1291 tmp = gtk_pixmap_new(pixmap, bitmap); 1290 tmp = gtk_pixmap_new(pixmap, bitmap);
1292 gtk_widget_show(tmp); 1291 gtk_widget_show(tmp);
1293 gtk_object_set_data(GTK_OBJECT(tmp), "id", (gpointer)id); 1292 gtk_object_set_data(GTK_OBJECT(tmp), "id", (gpointer)id);
1294 DW_MUTEX_UNLOCK; 1293 DW_MUTEX_UNLOCK;
3457 pixmap->width = width; pixmap->height = height; 3456 pixmap->width = width; pixmap->height = height;
3458 3457
3459 3458
3460 DW_MUTEX_LOCK; 3459 DW_MUTEX_LOCK;
3461 pixmap->handle = handle; 3460 pixmap->handle = handle;
3461 #ifdef USE_PIXBUF
3462 pixmap->pixmap = (GdkPixmap *)gdk_pixbuf_new(GDK_COLORSPACE_RGB, FALSE, depth, width, height);
3463 #else
3462 pixmap->pixmap = gdk_pixmap_new(handle->window, width, height, depth); 3464 pixmap->pixmap = gdk_pixmap_new(handle->window, width, height, depth);
3465 #endif
3463 DW_MUTEX_UNLOCK; 3466 DW_MUTEX_UNLOCK;
3464 return pixmap; 3467 return pixmap;
3465 } 3468 }
3466 3469
3467 /* 3470 /*
3514 void dw_pixmap_destroy(HPIXMAP pixmap) 3517 void dw_pixmap_destroy(HPIXMAP pixmap)
3515 { 3518 {
3516 int _locked_by_me = FALSE; 3519 int _locked_by_me = FALSE;
3517 3520
3518 DW_MUTEX_LOCK; 3521 DW_MUTEX_LOCK;
3522 #ifdef USE_PIXBUF
3523 gdk_pixbuf_unref((GdkPixbuf *)pixmap->pixmap);
3524 #else
3519 gdk_pixmap_unref(pixmap->pixmap); 3525 gdk_pixmap_unref(pixmap->pixmap);
3526 #endif
3520 free(pixmap); 3527 free(pixmap);
3521 DW_MUTEX_UNLOCK; 3528 DW_MUTEX_UNLOCK;
3522 } 3529 }
3523 3530
3524 /* 3531 /*
3535 * xsrc: X coordinate of source. 3542 * xsrc: X coordinate of source.
3536 * ysrc: Y coordinate of source. 3543 * ysrc: Y coordinate of source.
3537 */ 3544 */
3538 void dw_pixmap_bitblt(HWND dest, HPIXMAP destp, int xdest, int ydest, int width, int height, HWND src, HPIXMAP srcp, int xsrc, int ysrc) 3545 void dw_pixmap_bitblt(HWND dest, HPIXMAP destp, int xdest, int ydest, int width, int height, HWND src, HPIXMAP srcp, int xsrc, int ysrc)
3539 { 3546 {
3547 /* Ok, these #ifdefs are going to get a bit confusing because
3548 * when using gdk-pixbuf, pixmaps are really pixbufs, so we
3549 * have to use the pixbuf functions on them, and thus convoluting
3550 * the code here a bit. -Brian
3551 */
3540 int _locked_by_me = FALSE; 3552 int _locked_by_me = FALSE;
3541 GdkGC *gc = NULL; 3553 GdkGC *gc = NULL;
3542 3554
3543 if((!dest && !destp) || (!src && !srcp)) 3555 if((!dest && (!destp || !destp->pixmap)) || (!src && (!srcp || !srcp->pixmap)))
3544 return; 3556 return;
3545 3557
3546 DW_MUTEX_LOCK; 3558 DW_MUTEX_LOCK;
3547 if(dest) 3559 if(dest)
3548 gc = _set_colors(dest->window); 3560 gc = _set_colors(dest->window);
3549 else if(src) 3561 else if(src)
3550 gc = _set_colors(src->window); 3562 gc = _set_colors(src->window);
3563 #ifndef USE_PIXBUF
3551 else if(destp) 3564 else if(destp)
3552 gc = gdk_gc_new(destp->pixmap); 3565 gc = gdk_gc_new(destp->pixmap);
3553 else if(srcp) 3566 else if(srcp)
3554 gc = gdk_gc_new(srcp->pixmap); 3567 gc = gdk_gc_new(srcp->pixmap);
3555 3568 #endif
3556 if(gc) 3569
3557 { 3570 if(gc
3571 #ifdef USE_PIXBUF
3572 || (!dest && !src)
3573 #endif
3574 )
3575 {
3576 #ifndef USE_PIXBUF
3558 gdk_draw_pixmap(dest ? dest->window : destp->pixmap, gc, src ? src->window : srcp->pixmap, xsrc, ysrc, xdest, ydest, width, height); 3577 gdk_draw_pixmap(dest ? dest->window : destp->pixmap, gc, src ? src->window : srcp->pixmap, xsrc, ysrc, xdest, ydest, width, height);
3559 gdk_gc_unref(gc); 3578 #else
3579 if(dest && srcp)
3580 gdk_pixbuf_xlib_render_to_drawable(dest->window, gc, (GdkPixbuf *)srcp->pixmap, xsrc, ysrc, xdest, ydest, width, height, XLIB_RGB_DITHER_NONE, 0, 0);
3581
3582 if(gc)
3583 #endif
3584 gdk_gc_unref(gc);
3560 } 3585 }
3561 DW_MUTEX_UNLOCK; 3586 DW_MUTEX_UNLOCK;
3562 } 3587 }
3563 3588
3564 /* 3589 /*
5215 dw_main(0L, NULL); 5240 dw_main(0L, NULL);
5216 5241
5217 return 0; 5242 return 0;
5218 } 5243 }
5219 #endif 5244 #endif
5245