changeset 30:b1d7e8a28dfa

Added tree view functions and signal.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Sat, 25 Aug 2001 05:39:33 +0000
parents a33dfdc5b40a
children 17a08cfd45d2
files gtk/dw.c os2/dw.c win/dw.c
diffstat 3 files changed, 209 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/gtk/dw.c	Fri Aug 17 12:25:52 2001 +0000
+++ b/gtk/dw.c	Sat Aug 25 05:39:33 2001 +0000
@@ -82,6 +82,7 @@
 void _item_select_event(GtkWidget *widget, GtkWidget *child, gpointer data);
 void _expose_event(GtkWidget *widget, GdkEventExpose *event, gpointer data);
 void _set_focus_event(GtkWindow *window, GtkWidget *widget, gpointer data);
+void _tree_select_event(GtkTree *tree, GtkWidget *child, gpointer data);
 
 typedef struct
 {
@@ -98,7 +99,7 @@
 
 } SignalHandler;
 
-#define SIGNALMAX 13
+#define SIGNALMAX 14
 
 /* A list of signal forwarders, to account for paramater differences. */
 SignalList SignalTranslate[SIGNALMAX] = {
@@ -114,6 +115,7 @@
 	{ _container_select_event, "container-select" },
 	{ _container_context_event, "container-context" },
 	{ _item_select_event, "item-select" },
+	{ _tree_select_event, "tree-select" },
 	{ _set_focus_event, "set-focus" }
 };
 
@@ -344,6 +346,19 @@
 	}
 }
 
+void _tree_select_event(GtkTree *tree, GtkWidget *child, gpointer data)
+{
+	SignalHandler *work = (SignalHandler *)data;
+
+	if(work)
+	{
+		void (*treeselectfunc)(HWND, HWND, char *, void *) = work->func;
+		char *text = (char *)gtk_object_get_data(GTK_OBJECT(child), "text");
+
+		treeselectfunc(work->window, child, text, work->data);
+	}
+}
+
 void _container_select_event(GtkWidget *widget, GdkEventButton *event, gpointer data)
 {
 	SignalHandler *work = (SignalHandler *)data;
@@ -977,7 +992,8 @@
 void dw_window_pointer(HWND handle, int pointertype)
 {
 	GdkCursor *cursor = gdk_cursor_new(pointertype);
-	gdk_window_set_cursor(handle->window, cursor);
+	if(handle && handle->window)
+		gdk_window_set_cursor(handle->window, cursor);
 	gdk_cursor_destroy(cursor);
 }
 
@@ -2424,6 +2440,7 @@
 	}
 	item = gtk_tree_item_new();
 	label = gtk_label_new(title);
+	gtk_object_set_data(GTK_OBJECT(item), "text", (gpointer)strdup(title));
 	hbox = gtk_hbox_new(FALSE, 2);
 	gdkpix = _find_pixmap(&gdkbmp, icon, hbox);
 	pixmap = gtk_pixmap_new(gdkpix, gdkbmp);
@@ -2439,7 +2456,14 @@
 		subtree = (GtkWidget *)gtk_object_get_user_data(GTK_OBJECT(parent));
 		if(!subtree)
 		{
+			void *thisfunc = (void *)gtk_object_get_data(GTK_OBJECT(tree), "select-child-func");
+			void *work = (void *)gtk_object_get_data(GTK_OBJECT(tree), "select-child-data");
+
 			subtree = gtk_tree_new();
+
+			if(thisfunc && work)
+				gtk_signal_connect(GTK_OBJECT(subtree), "select-child", GTK_SIGNAL_FUNC(thisfunc), work);
+
 			gtk_object_set_user_data(GTK_OBJECT(parent), subtree);
 			gtk_tree_set_selection_mode(GTK_TREE(subtree), GTK_SELECTION_SINGLE);
 			gtk_tree_set_view_mode(GTK_TREE(subtree), GTK_TREE_VIEW_ITEM);
@@ -2455,6 +2479,49 @@
 	return item;
 }
 
+/*
+ * Removes all nodes from a tree.
+ * Parameters:
+ *       handle: Handle to the window (widget) to be cleared.
+ */
+void dw_tree_clear(HWND handle)
+{
+	GtkWidget *tree;
+	int _locked_by_me = FALSE;
+
+	DW_MUTEX_LOCK;
+	tree = (GtkWidget *)gtk_object_get_user_data(GTK_OBJECT(handle));
+	if(!tree || !GTK_IS_TREE(tree))
+	{
+		DW_MUTEX_UNLOCK;
+		return;
+	}
+	gtk_tree_clear_items(GTK_TREE(tree), 0, 1000000);
+	DW_MUTEX_UNLOCK;
+}
+
+/*
+ * Removes a node from a tree.
+ * Parameters:
+ *       handle: Handle to the window (widget) to be cleared.
+ *       item: Handle to node to be deleted.
+ */
+void dw_tree_delete(HWND handle, HWND item)
+{
+	GtkWidget *tree;
+	int _locked_by_me = FALSE;
+
+	DW_MUTEX_LOCK;
+	tree = (GtkWidget *)gtk_object_get_user_data(GTK_OBJECT(handle));
+	if(!tree || !GTK_IS_TREE(tree))
+	{
+		DW_MUTEX_UNLOCK;
+		return;
+	}
+	gtk_tree_remove_item(GTK_TREE(tree), item);
+	DW_MUTEX_UNLOCK;
+}
+
 int _dw_container_setup(HWND handle, unsigned long *flags, char **titles, int count, int separator, int extra)
 {
 	GtkWidget *clist;
@@ -4620,6 +4687,15 @@
 	{
 		thisname = "focus-in-event";
 	}
+	else if(GTK_IS_TREE(thiswindow) && strcmp(signame, "tree-select") == 0)
+	{
+		if(thisfunc)
+		{
+			gtk_object_set_data(GTK_OBJECT(thiswindow), "select-child-func", (gpointer)thisfunc);
+			gtk_object_set_data(GTK_OBJECT(thiswindow), "select-child-data", (gpointer)work);
+		}
+		thisname = "select-child";
+	}
 
 	if(!thisfunc || !thiswindow)
 	{
--- a/os2/dw.c	Fri Aug 17 12:25:52 2001 +0000
+++ b/os2/dw.c	Sat Aug 25 05:39:33 2001 +0000
@@ -89,7 +89,7 @@
 } SignalList;
 
 /* List of signals and their equivilent OS/2 message */
-#define SIGNALMAX 12
+#define SIGNALMAX 13
 
 SignalList SignalTranslate[SIGNALMAX] = {
 	{ WM_SIZE, "configure_event" },
@@ -103,6 +103,7 @@
 	{ CN_ENTER, "container-select" },
 	{ CN_CONTEXTMENU, "container-context" },
 	{ LN_SELECT, "item-select" },
+	{ WM_USER+1, "tree-select" },
 	{ WM_SETFOCUS, "set-focus" }
 };
 
@@ -1431,6 +1432,38 @@
 				break;
 			}
 		}
+
+		if(origmsg == WM_BUTTON1DOWN)
+		{
+			if(tmp->message == WM_USER+1)
+			{
+				if(tmp->window == hWnd)
+				{
+					QUERYRECFROMRECT rc;
+					POINTS pts = (*((POINTS*)&mp1));
+					RECORDCORE *prc;
+
+					rc.cb = sizeof(QUERYRECFROMRECT);
+					rc.rect.xLeft = pts.x;
+					rc.rect.xRight = pts.x + 1;
+					rc.rect.yTop = pts.y;
+					rc.rect.yBottom = pts.y - 1;
+					rc.fsSearch = CMA_PARTIAL | CMA_ITEMORDER;
+
+					prc = (RECORDCORE *)WinSendMsg(hWnd, CM_QUERYRECORDFROMRECT, (MPARAM)CMA_FIRST, MPFROMP(&rc));
+
+					if(prc)
+					{
+						int (*treeselectfunc)(HWND, HWND, char *, void *) = (int (*)(HWND, HWND, char *, void *))tmp->signalfunction;
+
+						result = treeselectfunc(tmp->window, (HWND)prc, prc->pszIcon, tmp->data);
+
+						tmp = NULL;
+					}
+				}
+			}
+		}
+
 		if(tmp)
 			tmp = tmp->next;
 
@@ -1445,12 +1478,14 @@
 {
 	Box *blah = WinQueryWindowPtr(hWnd, QWP_USER);
 
+#ifndef NO_SIGNALS
 	switch(msg)
 	{
 	case WM_CONTROL:
 		_run_event(hWnd, msg, mp1, mp2);
 		break;
 	}
+#endif
 	if(blah && blah->oldproc)
 	{
 		return blah->oldproc(hWnd, msg, mp1, mp2);
@@ -2162,6 +2197,18 @@
 	return WinDefWindowProc(hwnd, msg, mp1, mp2);
 }
 
+MRESULT EXPENTRY _TreeProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
+{
+	Box *blah = WinQueryWindowPtr(hwnd, QWP_USER);
+
+#ifndef NO_SIGNALS
+	_run_event(hwnd, msg, mp1, mp2);
+#endif
+	if(blah && blah->oldproc)
+		return blah->oldproc(hwnd, msg, mp1, mp2);
+	return WinDefWindowProc(hwnd, msg, mp1, mp2);
+}
+
 /*
  * Initializes the Dynamic Windows engine.
  * Parameters:
@@ -2923,6 +2970,7 @@
 HWND dw_tree_new(ULONG id)
 {
 	CNRINFO cnrinfo;
+	Box *newbox = calloc(1, sizeof(Box));
 	HWND tmp = WinCreateWindow(HWND_OBJECT,
 							   WC_CONTAINER,
 							   NULL,
@@ -2940,6 +2988,8 @@
 	cnrinfo.slBitmapOrIcon.cy = 16;
 
 	WinSendMsg(tmp, CM_SETCNRINFO, &cnrinfo, MPFROMLONG(CMA_FLWINDOWATTR | CMA_SLBITMAPORICON));
+	newbox->oldproc = WinSubclassWindow(tmp, _TreeProc);
+	WinSetWindowPtr(tmp, QWP_USER, newbox);
 	dw_window_set_font(tmp, DefaultFont);
 	return tmp;
 }
@@ -4249,6 +4299,28 @@
 	return (HWND)pci;
 }
 
+/*
+ * Removes all nodes from a tree.
+ * Parameters:
+ *       handle: Handle to the window (widget) to be cleared.
+ */
+void dw_tree_clear(HWND handle)
+{
+	WinSendMsg(handle, CM_REMOVERECORD, (MPARAM)0L, MPFROM2SHORT(0, CMA_INVALIDATE | CMA_FREE));
+}
+
+/*
+ * Removes a node from a tree.
+ * Parameters:
+ *       handle: Handle to the window (widget) to be cleared.
+ *       item: Handle to node to be deleted.
+ */
+void dw_tree_delete(HWND handle, HWND item)
+{
+	PCNRITEM     pci = (PCNRITEM)item;
+	WinSendMsg(handle, CM_REMOVERECORD, (MPARAM)&pci, MPFROM2SHORT(1, CMA_INVALIDATE | CMA_FREE));
+}
+
 /* Some OS/2 specific container structs */
 typedef struct _containerinfo {
 	int count;
--- a/win/dw.c	Fri Aug 17 12:25:52 2001 +0000
+++ b/win/dw.c	Sat Aug 25 05:39:33 2001 +0000
@@ -98,7 +98,7 @@
 } SignalList;
 
 /* List of signals and their equivilent Win32 message */
-#define SIGNALMAX 12
+#define SIGNALMAX 13
 
 SignalList SignalTranslate[SIGNALMAX] = {
 	{ WM_SIZE, "configure_event" },
@@ -112,6 +112,7 @@
 	{ NM_DBLCLK, "container-select" },
 	{ NM_RCLICK, "container-context" },
 	{ LBN_SELCHANGE, "item-select" },
+	{ TVN_SELCHANGED, "tree-select" },
 	{ WM_SETFOCUS, "set-focus" }
 };
 
@@ -983,7 +984,7 @@
 		/* Find any callbacks for this function */
 		while(tmp)
 		{
-			if(tmp->message == msg || msg == WM_COMMAND)
+			if(tmp->message == msg || msg == WM_COMMAND || msg == WM_NOTIFY)
 			{
 				switch(msg)
 				{
@@ -1122,6 +1123,38 @@
 						}
 					}
 					break;
+				case WM_NOTIFY:
+					{
+						if(tmp->message == TVN_SELCHANGED)
+						{
+							NMTREEVIEW FAR *tem=(NMTREEVIEW FAR *)mp2;
+							char tmpbuf[100];
+
+							GetClassName(tem->hdr.hwndFrom, tmpbuf, 99);
+
+							if(strnicmp(tmpbuf, WC_TREEVIEW, strlen(WC_TREEVIEW))==0)
+							{
+								if(tem->hdr.code == TVN_SELCHANGED)
+								{
+									if(tmp->window == tem->hdr.hwndFrom)
+									{
+										int (*treeselectfunc)(HWND, HWND, char *, void *) = tmp->signalfunction;
+                                        TVITEM tvi;
+
+										tvi.mask = TVIF_HANDLE;
+										tvi.hItem = tem->itemNew.hItem;
+
+										TreeView_GetItem(tmp->window, &tvi);
+
+										result = treeselectfunc(tmp->window, (HWND)tem->itemNew.hItem, (char *)tvi.lParam, tmp->data);
+
+										tmp = NULL;
+									}
+								}
+							}
+						}
+					}
+					break;
 				case WM_COMMAND:
 					{
 						int (*clickfunc)(HWND, void *) = tmp->signalfunction;
@@ -4465,8 +4498,9 @@
 	TVINSERTSTRUCT tvins;
 	HTREEITEM hti;
 
-	tvi.mask = TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE ;
+	tvi.mask = TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_PARAM;
 	tvi.pszText = title;
+	tvi.lParam = (LONG)title;
 	tvi.cchTextMax = strlen(title);
 	tvi.iSelectedImage = tvi.iImage = _lookup_icon(handle, (HICON)icon, 1);
 
@@ -4480,6 +4514,27 @@
 }
 
 /*
+ * Removes all nodes from a tree.
+ * Parameters:
+ *       handle: Handle to the window (widget) to be cleared.
+ */
+void dw_tree_clear(HWND handle)
+{
+	TreeView_DeleteAllItems(handle);
+}
+
+/*
+ * Removes a node from a tree.
+ * Parameters:
+ *       handle: Handle to the window (widget) to be cleared.
+ *       item: Handle to node to be deleted.
+ */
+void dw_tree_delete(HWND handle, HWND item)
+{
+	TreeView_DeleteItem(handle, (HTREEITEM)item);
+}
+
+/*
  * Sets up the container columns.
  * Parameters:
  *          handle: Handle to the container to be configured.