changeset 468:0a2f13ba2d5c

More menu fixes, free signal handlers and memory on OS/2, and the begining for Windows.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Wed, 08 Oct 2003 21:40:06 +0000
parents ecf1df2edcee
children 7952b9c1dc07
files os2/dw.c win/dw.c
diffstat 2 files changed, 45 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/os2/dw.c	Wed Oct 08 10:01:09 2003 +0000
+++ b/os2/dw.c	Wed Oct 08 21:40:06 2003 +0000
@@ -36,6 +36,7 @@
 int _load_bitmap_file(char *file, HWND handle, HBITMAP *hbm, HDC *hdc, HPS *hps, unsigned long *width, unsigned long *height);
 void _dw_box_pack_start(HWND box, HWND item, int width, int height, int hsize, int vsize, int pad, char *functionname);
 void _dw_box_pack_end(HWND box, HWND item, int width, int height, int hsize, int vsize, int pad, char *functionname);
+void _free_menu_data(HWND menu);
 
 char ClassName[] = "dynamicwindows";
 char SplitbarClassName[] = "dwsplitbar";
@@ -288,6 +289,9 @@
 
 	dw_signal_disconnect_by_window(handle);
 
+	if((child = WinWindowFromID(handle, FID_MENU)) != NULLHANDLE)
+		_free_menu_data(child);
+
 	if((child = WinWindowFromID(handle, FID_CLIENT)) != NULLHANDLE)
 	{
 		Box *box = (Box *)WinQueryWindowPtr(child, QWP_USER);
@@ -354,6 +358,24 @@
 	return;
 }
 
+void _free_menu_data(HWND menu)
+{
+	int i, count = (int)WinSendMsg(menu, MM_QUERYITEMCOUNT, 0, 0);;
+
+	dw_signal_disconnect_by_name(menu, DW_SIGNAL_CLICKED);
+	_free_window_memory(menu);
+
+	for(i=0;i<count;i++)
+	{
+		SHORT menuid = (SHORT)WinSendMsg(menu, MM_ITEMIDFROMPOSITION, MPFROMSHORT(i), 0);
+		MENUITEM  mi;
+
+		if(WinSendMsg(menu, MM_QUERYITEM, MPFROMSHORT(menuid), MPFROMP(&mi))
+		   && mi.hwndSubMenu)
+			_free_menu_data(mi.hwndSubMenu);
+	}
+}
+
 /* This function returns 1 if the window (widget) handle
  * passed to it is a valid window that can gain input focus.
  */
@@ -2618,11 +2640,20 @@
 		}
 		break;
 	case WM_DESTROY:
-		/* Free memory before destroying */
-		_free_window_memory(hWnd);
+		{
+			HWND parent = WinQueryWindow(hWnd, QW_PARENT);
+
+			/* Free memory before destroying */
+			if(parent && WinWindowFromID(parent, FID_CLIENT) == hWnd)
+				_free_window_memory(parent);
+			else
+				_free_window_memory(hWnd);
+		}
 		break;
 	case WM_MENUEND:
 		_clear_emphasis();
+		if(dw_window_get_data((HWND)mp2, "_dw_popup"))
+			_free_menu_data((HWND)mp2);
 		break;
 	}
 
@@ -3534,7 +3565,7 @@
  */
 int API dw_window_destroy(HWND handle)
 {
-	HWND frame, parent = WinQueryWindow(handle, QW_PARENT);
+	HWND frame, menu, parent = WinQueryWindow(handle, QW_PARENT);
 	Box *thisbox = WinQueryWindowPtr(parent, QWP_USER);
 
 	if(!handle)
@@ -3542,6 +3573,9 @@
 
 	frame = (HWND)dw_window_get_data(handle, "_dw_combo_box");
 
+	if((menu = WinWindowFromID(handle, FID_MENU)) != NULLHANDLE)
+		_free_menu_data(menu);
+
 	if(parent != desktop && thisbox && thisbox->count)
 	{
 		int z, index = -1;
--- a/win/dw.c	Wed Oct 08 10:01:09 2003 +0000
+++ b/win/dw.c	Wed Oct 08 21:40:06 2003 +0000
@@ -417,6 +417,12 @@
 	return TRUE;
 }
 
+void _free_menu_data(HMENU menu)
+{
+	/* TODO: This needs to call this on all submenus */
+	dw_signal_disconnect_by_name((HWND)menu, DW_SIGNAL_CLICKED);
+}
+
 /* Convert to our internal color scheme */
 ULONG _internal_color(ULONG color)
 {
@@ -1816,7 +1822,8 @@
 			windowfunc((void *)mp2);
 		break;
 	case WM_USER+5:
-		dw_signal_disconnect_by_name((HWND)mp1, DW_SIGNAL_CLICKED);
+		_free_menu_data((HMENU)mp1);
+		DestroyMenu((HMENU)mp1);
 		break;
 	case WM_NOTIFY:
 		{
@@ -4035,9 +4042,7 @@
 
 		popup = parent;
 		TrackPopupMenu(mymenu, 0, x, y, 0, parent, NULL);
-		/* TODO: This needs to call this on all submenus */
 		PostMessage(DW_HWND_OBJECT, WM_USER+5, (LPARAM)mymenu, 0);
-		DestroyMenu(mymenu);
 	}
 }