# HG changeset patch # User bsmith@81767d24-ef19-dc11-ae90-00e081727c95 # Date 1620709207 0 # Node ID 457c916348811291e556b950fccc82408cc6889c # Parent f45ebd96ebe5952a2a27081b702beca6cf3b9da8 Added dw_window_compare() to check if two window handles refer to the same object. Most platforms just compare the pointer or handle, but Android uses IsSameObject(). diff -r f45ebd96ebe5 -r 457c91634881 android/dw.cpp --- a/android/dw.cpp Tue May 11 00:51:20 2021 +0000 +++ b/android/dw.cpp Tue May 11 05:00:07 2021 +0000 @@ -3574,7 +3574,7 @@ jmethodID pixmapBitBlt = env->GetMethodID(clazz, "pixmapBitBlt", "(Lorg/dbsoft/dwindows/DWRender;Landroid/graphics/Bitmap;IIIILorg/dbsoft/dwindows/DWRender;Landroid/graphics/Bitmap;IIII)I"); // Call the method on the object - retval = env->CallIntMethod(_dw_obj, pixmapBitBlt, dest, destp->bitmap, xdest, ydest, width, height, src, srcp->bitmap, xsrc, ysrc, srcwidth, srcheight); + retval = env->CallIntMethod(_dw_obj, pixmapBitBlt, dest, destp ? destp->bitmap : NULL, xdest, ydest, width, height, src, srcp ? srcp->bitmap : NULL, xsrc, ysrc, srcwidth, srcheight); } return retval; } @@ -4794,6 +4794,27 @@ } /* + * Compare two window handles. + * Parameters: + * window1: First window handle to compare. + * window2: Second window handle to compare. + * Returns: + * TRUE if the windows are the same object, FALSE if not. + */ +int API dw_window_compare(HWND window1, HWND window2) +{ + JNIEnv *env; + void *retval = nullptr; + + if(window1 && window2 && (env = (JNIEnv *)pthread_getspecific(_dw_env_key))) + { + if(env->IsSameObject(window1, window2)) + return TRUE; + } + return FALSE; +} + +/* * Add a callback to a timer event. * Parameters: * interval: Milliseconds to delay between calls. diff -r f45ebd96ebe5 -r 457c91634881 dw.h --- a/dw.h Tue May 11 00:51:20 2021 +0000 +++ b/dw.h Tue May 11 05:00:07 2021 +0000 @@ -2122,6 +2122,7 @@ void * API dw_dialog_wait(DWDialog *dialog); void API dw_window_set_data(HWND window, const char *dataname, void *data); void * API dw_window_get_data(HWND window, const char *dataname); +int API dw_window_compare(HWND window1, HWND window2); int API dw_module_load(const char *name, HMOD *handle); int API dw_module_symbol(HMOD handle, const char *name, void**func); int API dw_module_close(HMOD handle); diff -r f45ebd96ebe5 -r 457c91634881 dwtest.c --- a/dwtest.c Tue May 11 00:51:20 2021 +0000 +++ b/dwtest.c Tue May 11 05:00:07 2021 +0000 @@ -274,9 +274,9 @@ HPIXMAP hpm; unsigned long width,height; - if (hwnd == textbox1) + if(dw_window_compare(hwnd, textbox1)) hpm = text1pm; - else if(hwnd == textbox2) + else if(dw_window_compare(hwnd, textbox2)) hpm = text2pm; else return TRUE; diff -r f45ebd96ebe5 -r 457c91634881 gtk/dw.c --- a/gtk/dw.c Tue May 11 00:51:20 2021 +0000 +++ b/gtk/dw.c Tue May 11 05:00:07 2021 +0000 @@ -13519,6 +13519,24 @@ } /* + * Compare two window handles. + * Parameters: + * window1: First window handle to compare. + * window2: Second window handle to compare. + * Returns: + * TRUE if the windows are the same object, FALSE if not. + */ +int API dw_window_compare(HWND window1, HWND window2) +{ + /* If anything special is require to compare... do it + * here otherwise just compare the handles. + */ + if(window1 && window2 && window1 == window2) + return TRUE; + return FALSE; +} + +/* * Add a callback to a timer event. * Parameters: * interval: Milliseconds to delay between calls. diff -r f45ebd96ebe5 -r 457c91634881 gtk3/dw.c --- a/gtk3/dw.c Tue May 11 00:51:20 2021 +0000 +++ b/gtk3/dw.c Tue May 11 05:00:07 2021 +0000 @@ -12156,6 +12156,24 @@ return ret; } +/* + * Compare two window handles. + * Parameters: + * window1: First window handle to compare. + * window2: Second window handle to compare. + * Returns: + * TRUE if the windows are the same object, FALSE if not. + */ +int API dw_window_compare(HWND window1, HWND window2) +{ + /* If anything special is require to compare... do it + * here otherwise just compare the handles. + */ + if(window1 && window2 && window1 == window2) + return TRUE; + return FALSE; +} + /* Internal function to get the state of the timer before firing */ gboolean _dw_timer_func(gpointer data) { diff -r f45ebd96ebe5 -r 457c91634881 gtk4/dw.c --- a/gtk4/dw.c Tue May 11 00:51:20 2021 +0000 +++ b/gtk4/dw.c Tue May 11 05:00:07 2021 +0000 @@ -10612,6 +10612,24 @@ return ret; } +/* + * Compare two window handles. + * Parameters: + * window1: First window handle to compare. + * window2: Second window handle to compare. + * Returns: + * TRUE if the windows are the same object, FALSE if not. + */ +int API dw_window_compare(HWND window1, HWND window2) +{ + /* If anything special is require to compare... do it + * here otherwise just compare the handles. + */ + if(window1 && window2 && window1 == window2) + return TRUE; + return FALSE; +} + /* Internal function to get the state of the timer before firing */ gboolean _dw_timer_func(gpointer data) { diff -r f45ebd96ebe5 -r 457c91634881 ios/dw.m --- a/ios/dw.m Tue May 11 00:51:20 2021 +0000 +++ b/ios/dw.m Tue May 11 05:00:07 2021 +0000 @@ -9277,6 +9277,24 @@ DW_FUNCTION_RETURN_THIS(retval); } +/* + * Compare two window handles. + * Parameters: + * window1: First window handle to compare. + * window2: Second window handle to compare. + * Returns: + * TRUE if the windows are the same object, FALSE if not. + */ +int API dw_window_compare(HWND window1, HWND window2) +{ + /* If anything special is require to compare... do it + * here otherwise just compare the handles. + */ + if(window1 && window2 && window1 == window2) + return TRUE; + return FALSE; +} + #define DW_TIMER_MAX 64 static NSTimer *DWTimers[DW_TIMER_MAX]; diff -r f45ebd96ebe5 -r 457c91634881 mac/dw.m --- a/mac/dw.m Tue May 11 00:51:20 2021 +0000 +++ b/mac/dw.m Tue May 11 05:00:07 2021 +0000 @@ -11488,6 +11488,24 @@ return NULL; } +/* + * Compare two window handles. + * Parameters: + * window1: First window handle to compare. + * window2: Second window handle to compare. + * Returns: + * TRUE if the windows are the same object, FALSE if not. + */ +int API dw_window_compare(HWND window1, HWND window2) +{ + /* If anything special is require to compare... do it + * here otherwise just compare the handles. + */ + if(window1 && window2 && window1 == window2) + return TRUE; + return FALSE; +} + #define DW_TIMER_MAX 64 static NSTimer *DWTimers[DW_TIMER_MAX]; diff -r f45ebd96ebe5 -r 457c91634881 os2/dw.c --- a/os2/dw.c Tue May 11 00:51:20 2021 +0000 +++ b/os2/dw.c Tue May 11 05:00:07 2021 +0000 @@ -13499,6 +13499,24 @@ } /* + * Compare two window handles. + * Parameters: + * window1: First window handle to compare. + * window2: Second window handle to compare. + * Returns: + * TRUE if the windows are the same object, FALSE if not. + */ +int API dw_window_compare(HWND window1, HWND window2) +{ + /* If anything special is require to compare... do it + * here otherwise just compare the handles. + */ + if(window1 && window2 && window1 == window2) + return TRUE; + return FALSE; +} + +/* * Add a callback to a timer event. * Parameters: * interval: Milliseconds to delay between calls. diff -r f45ebd96ebe5 -r 457c91634881 os2/dw.def --- a/os2/dw.def Tue May 11 00:51:20 2021 +0000 +++ b/os2/dw.def Tue May 11 05:00:07 2021 +0000 @@ -77,6 +77,7 @@ dw_window_get_preferred_size @84 dw_window_set_gravity @85 dw_window_set_focus @86 + dw_window_compare @87 dw_button_new @90 dw_bitmapbutton_new @91 diff -r f45ebd96ebe5 -r 457c91634881 readme.txt --- a/readme.txt Tue May 11 00:51:20 2021 +0000 +++ b/readme.txt Tue May 11 05:00:07 2021 +0000 @@ -83,6 +83,10 @@ callback. GTK4 and GTK3 with Wayland require drawing to be done in the callback, necessitating a dw_render_redraw() or dw_flush() call. dw_flush() may cause multiple draw passes. +Added new function dw_window_compare() to check if two window handles + reference the same object. Necessary in the Android port since + handles passed to callbacks are local references, so they don't + match the handles saved during window creation. Added support for dw_window_set_font() with a NULL font parameter. This resets the font used on the widget to the default font. Fixed GTK warnings on GTK3 caused by using Pango style font syntax. diff -r f45ebd96ebe5 -r 457c91634881 template/dw.c --- a/template/dw.c Tue May 11 00:51:20 2021 +0000 +++ b/template/dw.c Tue May 11 05:00:07 2021 +0000 @@ -3104,6 +3104,24 @@ } /* + * Compare two window handles. + * Parameters: + * window1: First window handle to compare. + * window2: Second window handle to compare. + * Returns: + * TRUE if the windows are the same object, FALSE if not. + */ +int API dw_window_compare(HWND window1, HWND window2) +{ + /* If anything special is require to compare... do it + * here otherwise just compare the handles. + */ + if(window1 && window2 && window1 == window2) + return TRUE; + return FALSE; +} + +/* * Add a callback to a timer event. * Parameters: * interval: Milliseconds to delay between calls. diff -r f45ebd96ebe5 -r 457c91634881 win/dw.c --- a/win/dw.c Tue May 11 00:51:20 2021 +0000 +++ b/win/dw.c Tue May 11 05:00:07 2021 +0000 @@ -13546,6 +13546,24 @@ } /* + * Compare two window handles. + * Parameters: + * window1: First window handle to compare. + * window2: Second window handle to compare. + * Returns: + * TRUE if the windows are the same object, FALSE if not. + */ +int API dw_window_compare(HWND window1, HWND window2) +{ + /* If anything special is require to compare... do it + * here otherwise just compare the handles. + */ + if(window1 && window2 && window1 == window2) + return TRUE; + return FALSE; +} + +/* * Add a callback to a timer event. * Parameters: * interval: Milliseconds to delay between calls. diff -r f45ebd96ebe5 -r 457c91634881 win/dw.def --- a/win/dw.def Tue May 11 00:51:20 2021 +0000 +++ b/win/dw.def Tue May 11 05:00:07 2021 +0000 @@ -75,6 +75,7 @@ dw_window_get_preferred_size @84 dw_window_set_gravity @85 dw_window_set_focus @86 + dw_window_compare @87 dw_button_new @90 dw_bitmapbutton_new @91