changeset 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
files compat.c config.h.in gtk/dw.c os2/dw.c win/dw.c
diffstat 5 files changed, 77 insertions(+), 46 deletions(-) [+]
line wrap: on
line diff
--- a/compat.c	Tue Oct 30 10:49:09 2001 +0000
+++ b/compat.c	Fri Nov 02 10:31:29 2001 +0000
@@ -20,6 +20,7 @@
 #include <sys/vfs.h>
 #endif
 #endif
+#include <time.h>
 
 #ifdef __UNIX__
 void msleep(long period)
--- a/config.h.in	Tue Oct 30 10:49:09 2001 +0000
+++ b/config.h.in	Fri Nov 02 10:31:29 2001 +0000
@@ -32,3 +32,6 @@
 
 /* Define if IMLIB is available. */
 #undef USE_IMLIB
+
+/* Define if PIXBUF is available. */
+#undef USE_PIXBUF
--- a/gtk/dw.c	Tue Oct 30 10:49:09 2001 +0000
+++ b/gtk/dw.c	Fri Nov 02 10:31:29 2001 +0000
@@ -19,6 +19,10 @@
 #include <gdk/gdkkeysyms.h>
 #ifdef USE_IMLIB
 #include <gdk_imlib.h>
+#elif defined(USE_PIXBUF)
+#include <gdk-pixbuf/gdk-pixbuf.h>
+#include <gdk-pixbuf/gdk-pixbuf-xlibrgb.h>
+#include <gdk-pixbuf/gdk-pixbuf-xlib.h>
 #endif
 
 /* These are used for resource management */
@@ -51,6 +55,8 @@
 GdkColor _foreground = { 0, 0x0000, 0x0000, 0x0000 };
 GdkColor _background = { 0, 0xaaaa, 0xaaaa, 0xaaaa };
 
+GtkWidget *last_window = NULL;
+
 int _dw_file_active = 0, _dw_ignore_click = 0;
 pthread_t _dw_thread = (pthread_t)-1;
 int _dw_mutex_locked = FALSE;
@@ -60,11 +66,6 @@
 #define  DW_MUTEX_LOCK { if(pthread_self() != _dw_thread && _dw_mutex_locked == FALSE) { gdk_threads_enter(); _dw_mutex_locked = TRUE; _locked_by_me = TRUE;  } }
 #define  DW_MUTEX_UNLOCK { if(pthread_self() != _dw_thread && _locked_by_me == TRUE) { gdk_threads_leave(); _dw_mutex_locked = FALSE; _locked_by_me = FALSE; } }
 
-/* Currently the non Imlib method does not work */
-#ifndef USE_IMLIB
-#define USE_IMLIB
-#endif
-
 #define DEFAULT_SIZE_WIDTH 12
 #define DEFAULT_SIZE_HEIGHT 6
 #define DEFAULT_TITLEBAR_HEIGHT 22
@@ -455,15 +456,12 @@
 	if(data)
 	{
 		GdkPixmap *icon_pixmap = NULL;
-#ifndef USE_IMLIB
-		GtkStyle *iconstyle;
-
-		/* hmmm why do we need the handle here? */
-		iconstyle = gtk_widget_get_style(handle);
-		if (!icon_pixmap)
-			icon_pixmap = gdk_pixmap_create_from_xpm_d(handle->window, bitmap, &iconstyle->bg[GTK_STATE_NORMAL], &data);
+#ifdef USE_IMLIB
+		gdk_imlib_data_to_pixmap((char **)data, &icon_pixmap, bitmap);
+#elif defined(USE_PIXBUF)
+		icon_pixmap = (GdkPixmap *)gdk_pixbuf_new_from_xpm_data((const char **)data);
 #else
-		gdk_imlib_data_to_pixmap((char **)data, &icon_pixmap, bitmap);
+		icon_pixmap = gdk_pixmap_create_from_xpm_d(handle->window, bitmap, &_colors[DW_CLR_PALEGRAY], &data);
 #endif
 		return icon_pixmap;
 	}
@@ -1175,7 +1173,7 @@
 	int flags = 0;
 
 	DW_MUTEX_LOCK;
-	tmp = gtk_window_new(GTK_WINDOW_TOPLEVEL);
+	last_window = tmp = gtk_window_new(GTK_WINDOW_TOPLEVEL);
 
 	gtk_window_set_title(GTK_WINDOW(tmp), title);
 	if(!(flStyle & DW_FCF_SIZEBORDER))
@@ -1190,9 +1188,9 @@
 		flags |= GDK_DECOR_MINIMIZE | GDK_DECOR_MAXIMIZE;
 
 	if(flStyle & DW_FCF_SIZEBORDER)
-		flags |= GDK_DECOR_RESIZEH;
-
-	if(flStyle & DW_FCF_BORDER)
+		flags |= GDK_DECOR_RESIZEH | GDK_DECOR_BORDER;
+
+	if(flStyle & DW_FCF_BORDER || flStyle & DW_FCF_DLGBORDER)
 		flags |= GDK_DECOR_BORDER;
 
 	gdk_window_set_decorations(tmp->window, flags);
@@ -1271,22 +1269,23 @@
 	GdkPixmap *pixmap= NULL;
 	GdkBitmap *bitmap;
 	GtkWidget *tmp;
-	char * test_xpm[] = {
-		"1 1 1 1",
-		"       c None",
-		" "};
+	static char * test_xpm[] = {
+		"1 1 2 1",
+		"	c None",
+		".	c #FFFFFF",
+		"."};
 	int _locked_by_me = FALSE;
 
 	DW_MUTEX_LOCK;
-#ifndef USE_IMLIB
-	GtkStyle *iconstyle;
-
-	/* hmmm why do we need the handle here? */
-	iconstyle = gtk_widget_get_style(handle);
-	if (!pixmap)
-		pixmap = gdk_pixmap_create_from_xpm_d(handle->window, &bitmap, &iconstyle->bg[GTK_STATE_NORMAL], &test_xpm);
+#ifdef USE_IMLIB
+	gdk_imlib_data_to_pixmap(test_xpm, &pixmap, &bitmap);
+#elif defined(USE_PIXBUF)
+	pixmap = (GdkPixmap *)gdk_pixbuf_new_from_xpm_data((const char **)test_xpm);
 #else
-	gdk_imlib_data_to_pixmap(test_xpm, &pixmap, &bitmap);
+	gtk_widget_realize(last_window);
+
+	if(last_window)
+		pixmap = gdk_pixmap_create_from_xpm_d(last_window->window, &bitmap, &_colors[DW_CLR_PALEGRAY], test_xpm);
 #endif
 	tmp = gtk_pixmap_new(pixmap, bitmap);
 	gtk_widget_show(tmp);
@@ -3459,7 +3458,11 @@
 
 	DW_MUTEX_LOCK;
 	pixmap->handle = handle;
+#ifdef USE_PIXBUF
+	pixmap->pixmap = (GdkPixmap *)gdk_pixbuf_new(GDK_COLORSPACE_RGB, FALSE, depth, width, height);
+#else
 	pixmap->pixmap = gdk_pixmap_new(handle->window, width, height, depth);
+#endif
 	DW_MUTEX_UNLOCK;
 	return pixmap;
 }
@@ -3516,7 +3519,11 @@
 	int _locked_by_me = FALSE;
 
 	DW_MUTEX_LOCK;
+#ifdef USE_PIXBUF
+	gdk_pixbuf_unref((GdkPixbuf *)pixmap->pixmap);
+#else
 	gdk_pixmap_unref(pixmap->pixmap);
+#endif
 	free(pixmap);
 	DW_MUTEX_UNLOCK;
 }
@@ -3537,10 +3544,15 @@
  */
 void dw_pixmap_bitblt(HWND dest, HPIXMAP destp, int xdest, int ydest, int width, int height, HWND src, HPIXMAP srcp, int xsrc, int ysrc)
 {
+	/* Ok, these #ifdefs are going to get a bit confusing because
+	 * when using gdk-pixbuf, pixmaps are really pixbufs, so we
+	 * have to use the pixbuf functions on them, and thus convoluting
+	 * the code here a bit. -Brian
+	 */
 	int _locked_by_me = FALSE;
 	GdkGC *gc = NULL;
 
-	if((!dest && !destp) || (!src && !srcp))
+	if((!dest && (!destp || !destp->pixmap)) || (!src && (!srcp || !srcp->pixmap)))
 		return;
 
 	DW_MUTEX_LOCK;
@@ -3548,15 +3560,28 @@
 		gc = _set_colors(dest->window);
 	else if(src)
 		gc = _set_colors(src->window);
+#ifndef USE_PIXBUF
 	else if(destp)
 		gc = gdk_gc_new(destp->pixmap);
 	else if(srcp)
 		gc = gdk_gc_new(srcp->pixmap);
-
-	if(gc)
+#endif
+
+	if(gc
+#ifdef USE_PIXBUF
+       || (!dest && !src)
+#endif
+	  )
 	{
+#ifndef USE_PIXBUF
 		gdk_draw_pixmap(dest ? dest->window : destp->pixmap, gc, src ? src->window : srcp->pixmap, xsrc, ysrc, xdest, ydest, width, height);
-		gdk_gc_unref(gc);
+#else
+        if(dest && srcp)
+			gdk_pixbuf_xlib_render_to_drawable(dest->window, gc, (GdkPixbuf *)srcp->pixmap, xsrc, ysrc, xdest, ydest, width, height, XLIB_RGB_DITHER_NONE, 0, 0);
+
+        if(gc)
+#endif
+			gdk_gc_unref(gc);
 	}
 	DW_MUTEX_UNLOCK;
 }
@@ -5216,4 +5241,5 @@
 
 	return 0;
 }
-#endif
\ No newline at end of file
+#endif
+
--- a/os2/dw.c	Tue Oct 30 10:49:09 2001 +0000
+++ b/os2/dw.c	Fri Nov 02 10:31:29 2001 +0000
@@ -596,7 +596,6 @@
 				int pass, int *usedpadx, int *usedpady)
 {
 	int z, currentx = 0, currenty = 0;
-	int vectorx = 0, vectory = 0;
 	int uymax = 0, uxmax = 0;
 	int upymax = 0, upxmax = 0;
 	/* Used for the SIZEEXPAND */
@@ -861,9 +860,6 @@
 
 					(*depth)++;
 
-					/*tmp->xratio = ((float)((thisbox->items[z].width * thisbox->xratio)-tmp->upx) )/((float)(tmp->minwidth-tmp->upx));
-					tmp->yratio = ((float)((thisbox->items[z].height * thisbox->yratio)-tmp->upy))/((float)(tmp->minheight-tmp->upy));*/
-
 #ifdef DWDEBUG
 					fprintf(f, "2- Resize Box depth %d\r\nx = %d, y = %d, usedx = %d, usedy = %d, usedpadx = %d, usedpady = %d xratio = %f, yratio = %f,\r\nupx = %d, upy = %d, width = %d, height = %d, minwidth = %d, minheight = %d, box xratio = %f, box yratio = %f\r\n\r\n",
 						*depth, x, y, *usedx, *usedy, *usedpadx, *usedpady, tmp->xratio, tmp->yratio, tmp->upx, tmp->upy, thisbox->items[z].width, thisbox->items[z].height, tmp->minwidth, tmp->minheight, thisbox->xratio, thisbox->yratio);
@@ -884,6 +880,7 @@
 			int width = thisbox->items[z].width;
 			int pad = thisbox->items[z].pad;
 			HWND handle = thisbox->items[z].hwnd;
+			int vectorx, vectory;
 
 			/* When upxmax != pad*2 then ratios are incorrect. */
 			vectorx = (int)((width*thisbox->items[z].xratio)-width);
@@ -929,7 +926,7 @@
 
 						if(boxinfo && boxinfo->grouphwnd)
 							WinSetWindowPos(boxinfo->grouphwnd, HWND_TOP, 0, 0,
-											width + vectorx, height + vectory, SWP_MOVE | SWP_SIZE /*| SWP_ZORDER*/);
+											width + vectorx, height + vectory, SWP_MOVE | SWP_SIZE);
 
 					}
 
@@ -2919,7 +2916,8 @@
 	hwndframe = WinCreateWindow(HWND_OBJECT,
 								WC_FRAME,
 								NULL,
-								WS_VISIBLE | WS_CLIPCHILDREN,
+								WS_VISIBLE | WS_CLIPCHILDREN |
+								FS_NOBYTEALIGN,
 								0,0,2000,1000,
 								NULLHANDLE,
 								HWND_TOP,
@@ -2952,7 +2950,8 @@
 	hwndframe = WinCreateWindow(HWND_OBJECT,
 								WC_FRAME,
 								NULL,
-								WS_VISIBLE,
+								WS_VISIBLE |
+								FS_NOBYTEALIGN,
 								0,0,2000,1000,
 								NULLHANDLE,
 								HWND_TOP,
@@ -2991,7 +2990,8 @@
 	hwndframe = WinCreateWindow(HWND_OBJECT,
 								WC_FRAME,
 								NULL,
-								WS_VISIBLE | WS_CLIPCHILDREN,
+								WS_VISIBLE | WS_CLIPCHILDREN |
+								FS_NOBYTEALIGN,
 								0,0,2000,1000,
 								NULLHANDLE,
 								HWND_TOP,
@@ -5195,7 +5195,8 @@
 	HWND hwndframe = WinCreateWindow(HWND_OBJECT,
 									 WC_FRAME,
 									 NULL,
-									 WS_VISIBLE,
+									 WS_VISIBLE |
+									 FS_NOBYTEALIGN,
 									 0,0,2000,1000,
 									 NULLHANDLE,
 									 HWND_TOP,
--- a/win/dw.c	Tue Oct 30 10:49:09 2001 +0000
+++ b/win/dw.c	Fri Nov 02 10:31:29 2001 +0000
@@ -838,9 +838,6 @@
 
 					(*depth)++;
 
-					/*tmp->xratio = ((float)((thisbox->items[z].width * thisbox->xratio)-tmp->upx) )/((float)(tmp->minwidth-tmp->upx));
-					tmp->yratio = ((float)((thisbox->items[z].height * thisbox->yratio)-tmp->upy))/((float)(tmp->minheight-tmp->upy));*/
-
 #ifdef DWDEBUG
 					fprintf(f, "2- Resize Box depth %d\r\nx = %d, y = %d, usedx = %d, usedy = %d, usedpadx = %d, usedpady = %d xratio = %f, yratio = %f,\r\nupx = %d, upy = %d, width = %d, height = %d, minwidth = %d, minheight = %d, box xratio = %f, box yratio = %f\r\n\r\n",
 						*depth, x, y, *usedx, *usedy, *usedpadx, *usedpady, tmp->xratio, tmp->yratio, tmp->upx, tmp->upy, thisbox->items[z].width, thisbox->items[z].height, tmp->minwidth, tmp->minheight, thisbox->xratio, thisbox->yratio);
@@ -963,6 +960,9 @@
 
 			_resize_box(thisbox, &depth, x, y, &usedx, &usedy, 1, &usedpadx, &usedpady);
 
+			if(usedx-usedpadx == 0 || usedy-usedpady == 0)
+				return;
+
 			thisbox->xratio = ((float)(x-usedpadx))/((float)(usedx-usedpadx));
 			thisbox->yratio = ((float)(y-usedpady))/((float)(usedy-usedpady));