diff os2/dw.c @ 22:6a246b3bb14f

Added tree widgets, fixed some delete event processing, fixed a layout bug on OS/2 and Win32. Added another function to compat to deal with MSVC runtime library conflicts.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Thu, 02 Aug 2001 09:57:21 +0000
parents c6e76b796b28
children 2932f9d2c7d5
line wrap: on
line diff
--- a/os2/dw.c	Fri Jul 27 07:12:35 2001 +0000
+++ b/os2/dw.c	Thu Aug 02 09:57:21 2001 +0000
@@ -55,7 +55,7 @@
 void reopen(void)
 {
 	fclose(f);
-	f = fopen("dw.log", "at");
+	f = fopen("dw.log", "a+");
 }
 #endif
 
@@ -618,6 +618,7 @@
 						reopen();
 					}
 #endif
+
 					if(thisbox->type == BOXVERT)
 					{
 						if((thisbox->items[z].width-((thisbox->items[z].pad*2)+(tmp->pad*2)))!=0)
@@ -686,6 +687,18 @@
 				thisbox->items[z].yratio = ((float)((thisbox->height * thisbox->parentyratio)-((thisbox->items[z].pad*2)+(thisbox->parentpad*2))))/((float)(thisbox->minheight-((thisbox->items[z].pad*2)+(thisbox->parentpad*2))));
 			else
 				thisbox->items[z].yratio = ((float)((thisbox->height * thisbox->parentyratio)-thisbox->upy))/((float)(thisbox->minheight-thisbox->upy));
+
+			if(thisbox->items[z].type == TYPEBOX)
+			{
+				Box *tmp = WinQueryWindowPtr(thisbox->items[z].hwnd, QWP_USER);
+
+				if(tmp)
+				{
+					tmp->parentxratio = thisbox->items[z].xratio;
+					tmp->parentyratio = thisbox->items[z].yratio;
+				}
+			}
+
 #ifdef DWDEBUG
 			fprintf(f, "RATIO- xratio = %f, yratio = %f, width = %d, height = %d, pad = %d, box xratio = %f, box yratio = %f, parent xratio = %f, parent yratio = %f, minwidth = %d, minheight = %d, width = %d, height = %d, upx = %d, upy = %d\r\n\r\n",
 					thisbox->items[z].xratio, thisbox->items[z].yratio, thisbox->items[z].width, thisbox->items[z].height, thisbox->items[z].pad, thisbox->xratio, thisbox->yratio, thisbox->parentxratio, thisbox->parentyratio, thisbox->minwidth, thisbox->minheight, thisbox->width, thisbox->height, thisbox->upx, thisbox->upy);
@@ -1283,6 +1296,8 @@
 					if(hWnd == tmp->window || hWnd == WinWindowFromID(tmp->window, FID_CLIENT))
 					{
 						result = closefunc(tmp->window, tmp->data);
+						if(result)
+							result = FALSE;
 						tmp = NULL;
 					}
 				}
@@ -1597,8 +1612,12 @@
 		}
 		break;
 	case WM_CLOSE:
-		dw_window_destroy(WinQueryWindow(hWnd, QW_PARENT));
-		return (MRESULT)TRUE;
+		if(result == -1)
+		{
+			dw_window_destroy(WinQueryWindow(hWnd, QW_PARENT));
+			return (MRESULT)TRUE;
+		}
+		break;
 	case WM_USER:
 		windowfunc = (void (*)(void *))mp1;
 
@@ -1617,7 +1636,7 @@
 		_free_window_memory(hWnd);
 		break;
 	}
-	if(filterfunc && result != -1)
+	if(result != -1)
 		return (MRESULT)result;
 	else
 		return WinDefWindowProc(hWnd, msg, mp1, mp2);
@@ -1850,7 +1869,9 @@
 					if(thisbox->items[z].type == TYPEBOX)
 					{
 						Box *tmp = WinQueryWindowPtr(thisbox->items[z].hwnd, QWP_USER);
-						_changebox(tmp, percent, thisbox->type);
+
+						if(tmp)
+							_changebox(tmp, percent, thisbox->type);
 					}
 					else
 					{
@@ -2164,7 +2185,7 @@
 	DosQuerySysInfo(QSV_VERSION_MAJOR, QSV_MS_COUNT,(void *)aulBuffer, 4*sizeof(ULONG));
 
 #ifdef DWDEBUG
-	f = fopen("dw.log", "wt");
+	f = fopen("dw.log", "w");
 #endif
 	return rc;
 }
@@ -2491,6 +2512,20 @@
 }
 
 /*
+ * Changes the appearance of the mouse pointer.
+ * Parameters:
+ *       handle: Handle to widget for which to change.
+ *       cursortype: ID of the pointer you want.
+ */
+void dw_window_pointer(HWND handle, int pointertype)
+{
+	WinSetPointer(handle,
+				  WinQuerySysPointer(HWND_DESKTOP,
+									 pointertype,
+									 FALSE));
+}
+
+/*
  * Create a new Window Frame.
  * Parameters:
  *       owner: The Owner's window handle or HWND_DESKTOP.
@@ -2880,6 +2915,36 @@
 }
 
 /*
+ * Create a tree object to be packed.
+ * Parameters:
+ *       id: An ID to be used for getting the resource from the
+ *           resource file.
+ */
+HWND dw_tree_new(ULONG id)
+{
+	CNRINFO cnrinfo;
+	HWND tmp = WinCreateWindow(HWND_OBJECT,
+							   WC_CONTAINER,
+							   NULL,
+							   WS_VISIBLE | CCS_READONLY |
+							   CCS_SINGLESEL | CCS_AUTOPOSITION,
+							   0,0,2000,1000,
+							   NULLHANDLE,
+							   HWND_TOP,
+							   id,
+							   NULL,
+							   NULL);
+
+	cnrinfo.flWindowAttr = CV_TREE | CA_TREELINE;
+	cnrinfo.slBitmapOrIcon.cx = 16;
+	cnrinfo.slBitmapOrIcon.cy = 16;
+
+	WinSendMsg(tmp, CM_SETCNRINFO, &cnrinfo, MPFROMLONG(CMA_FLWINDOWATTR | CMA_SLBITMAPORICON));
+	dw_window_set_font(tmp, DefaultFont);
+	return tmp;
+}
+
+/*
  * Create a new static text window (widget) to be packed.
  * Parameters:
  *       text: The text to be display by the static text widget.
@@ -4125,6 +4190,72 @@
 	WinSendMsg(handle,BM_SETCHECK,MPFROMSHORT(value),0);
 }
 
+typedef struct _CNRITEM
+{
+	MINIRECORDCORE rc;
+	HPOINTER       hptrIcon;
+
+} CNRITEM, *PCNRITEM;
+
+/*
+ * Inserts an item into a tree window (widget).
+ * Parameters:
+ *          handle: Handle to the tree to be inserted.
+ *          title: The text title of the entry.
+ *          icon: Handle to coresponding icon.
+ *          parent: Parent handle or 0 if root.
+ */
+HWND dw_tree_insert(HWND handle, char *title, unsigned long icon, HWND parent)
+{
+	ULONG        cbExtra;
+	PCNRITEM     pci;
+	RECORDINSERT ri;
+
+	/* Calculate extra bytes needed for each record besides that needed for the
+	 * MINIRECORDCORE structure
+	 */
+
+	cbExtra = sizeof(CNRITEM) - sizeof(MINIRECORDCORE);
+
+	/* Allocate memory for the parent record */
+
+	pci = WinSendMsg(handle, CM_ALLOCRECORD, MPFROMLONG(cbExtra), MPFROMSHORT(1));
+
+	/* Fill in the parent record data */
+
+	pci->rc.cb          = sizeof(MINIRECORDCORE);
+	pci->rc.pszIcon     = title;
+	pci->rc.hptrIcon    = icon;
+
+	pci->hptrIcon       = icon;
+
+	memset(&ri, 0, sizeof(RECORDINSERT));
+
+	ri.cb                 = sizeof(RECORDINSERT);
+	ri.pRecordOrder       = (PRECORDCORE)CMA_END;
+	ri.pRecordParent      = (PRECORDCORE)NULL;
+	ri.zOrder             = (USHORT)CMA_TOP;
+	ri.cRecordsInsert     = 1;
+	ri.fInvalidateRecord  = TRUE;
+
+	/* We are about to insert the child records. Set the parent record to be
+	 * the one we just inserted.
+	 */
+	ri.pRecordParent = (PRECORDCORE)parent;
+
+	/* Insert the record */
+	WinSendMsg(handle, CM_INSERTRECORD, MPFROMP(pci), MPFROMP(&ri));
+
+	return (HWND)pci;
+}
+
+/* Some OS/2 specific container structs */
+typedef struct _containerinfo {
+	int count;
+	void *data;
+	HWND handle;
+} ContainerInfo;
+
 /*
  * Sets up the container columns.
  * Parameters:
@@ -4281,6 +4412,7 @@
 	ULONG *flags = (ULONG *)WinQueryWindowPtr(handle, 0);
 	int z, size = 0, totalsize, count = 0;
 	PRECORDCORE temp;
+	ContainerInfo *ci;
 	void *blah;
 
 	if(!flags)
@@ -4319,7 +4451,13 @@
 		temp = temp->preccNextRecord;
 	}
 
-	return blah;
+	ci = malloc(sizeof(struct _containerinfo));
+
+	ci->count = rowcount;
+	ci->data = blah;
+	ci->handle = handle;
+
+	return (void *)ci;
 }
 
 /*
@@ -4334,13 +4472,23 @@
 void dw_container_set_item(HWND handle, void *pointer, int column, int row, void *data)
 {
 	ULONG totalsize, size = 0, *flags = (ULONG *)WinQueryWindowPtr(handle, 0);
-	int z;
-	PRECORDCORE temp = (PRECORDCORE)pointer;
+	int z, currentcount;
+	ContainerInfo *ci = (ContainerInfo *)pointer;
+	PRECORDCORE temp;
+	CNRINFO cnr;
     void *dest;
 
+	if(!ci)
+		return;
+
 	if(!flags)
 		return;
 
+	temp = (PRECORDCORE)ci->data;
+
+	WinSendMsg(handle, CM_QUERYCNRINFO, (MPARAM)&cnr, MPFROMSHORT(sizeof(CNRINFO)));
+	currentcount = cnr.cRecords;
+
 	/* Figure out the offsets to the items in the struct */
 	for(z=0;z<column;z++)
 	{
@@ -4358,7 +4506,7 @@
 
 	totalsize = size + sizeof(RECORDCORE);
 
-	for(z=0;z<row;z++)
+	for(z=0;z<(row-currentcount);z++)
 		temp = temp->preccNextRecord;
 
 	dest = (void *)(((ULONG)temp)+((ULONG)totalsize));
@@ -4405,6 +4553,17 @@
 }
 
 /*
+ * Sets the width of a column in the container.
+ * Parameters:
+ *          handle: Handle to window (widget) of container.
+ *          column: Zero based column of width being set.
+ *          width: Width of column in pixels.
+ */
+void dw_container_set_column_width(HWND handle, int column, int width)
+{
+}
+
+/*
  * Sets the title of a row in the container.
  * Parameters:
  *          pointer: Pointer to the allocated memory in dw_container_alloc().
@@ -4413,10 +4572,15 @@
  */
 void dw_container_set_row_title(void *pointer, int row, char *title)
 {
-	PRECORDCORE temp = (PRECORDCORE)pointer;
-	int z;
-
-	for(z=0;z<row;z++)
+	ContainerInfo *ci = (ContainerInfo *)pointer;
+	PRECORDCORE temp = (PRECORDCORE)ci->data;
+	int z, currentcount;
+	CNRINFO cnr;
+
+	WinSendMsg(ci->handle, CM_QUERYCNRINFO, (MPARAM)&cnr, MPFROMSHORT(sizeof(CNRINFO)));
+	currentcount = cnr.cRecords;
+
+	for(z=0;z<(row-currentcount);z++)
 		temp = temp->preccNextRecord;
 
 	temp->pszIcon = title;
@@ -4434,6 +4598,7 @@
 void dw_container_insert(HWND handle, void *pointer, int rowcount)
 {
 	RECORDINSERT recin;
+	ContainerInfo *ci = (ContainerInfo *)pointer;
 
 	recin.cb = sizeof(RECORDINSERT);
 	recin.pRecordOrder = (PRECORDCORE)CMA_END;
@@ -4442,7 +4607,7 @@
 	recin.fInvalidateRecord = TRUE;
 	recin.cRecordsInsert = rowcount;
 
-	WinSendMsg(handle, CM_INSERTRECORD, MPFROMP(pointer), MPFROMP(&recin));
+	WinSendMsg(handle, CM_INSERTRECORD, MPFROMP(ci->data), MPFROMP(&recin));
 }
 
 /*
@@ -4456,6 +4621,49 @@
 }
 
 /*
+ * Removes the first x rows from a container.
+ * Parameters:
+ *       handle: Handle to the window (widget) to be deleted from.
+ *       rowcount: The number of rows to be deleted.
+ */
+void dw_container_delete(HWND handle, int rowcount)
+{
+	RECORDCORE *last, **prc = malloc(sizeof(RECORDCORE *) * rowcount);
+	int current = 1;
+
+	prc[0] = last = (RECORDCORE *)WinSendMsg(handle, CM_QUERYRECORD, (MPARAM)0L, MPFROM2SHORT(CMA_FIRST, CMA_ITEMORDER));
+
+	while(last && current < rowcount)
+	{
+		prc[current] = last = (RECORDCORE *)WinSendMsg(handle, CM_QUERYRECORD, (MPARAM)last, MPFROM2SHORT(CMA_NEXT, CMA_ITEMORDER));
+		current++;
+	}
+	WinSendMsg(handle, CM_REMOVERECORD, (MPARAM)prc, MPFROM2SHORT(current, CMA_INVALIDATE | CMA_FREE));
+	free(prc);
+}
+
+/*
+ * Scrolls container up or down.
+ * Parameters:
+ *       handle: Handle to the window (widget) to be scrolled.
+ *       direction: DW_SCROLL_UP, DW_SCROLL_DOWN, DW_SCROLL_TOP or
+ *                  DW_SCROLL_BOTTOM. (rows is ignored for last two)
+ *       rows: The number of rows to be scrolled.
+ */
+void dw_container_scroll(HWND handle, int direction, long rows)
+{
+	switch(direction)
+	{
+	case DW_SCROLL_TOP:
+		WinSendMsg(handle, CM_SCROLLWINDOW, MPFROMSHORT(CMA_VERTICAL), MPFROMLONG(-10000000));
+        break;
+	case DW_SCROLL_BOTTOM:
+		WinSendMsg(handle, CM_SCROLLWINDOW, MPFROMSHORT(CMA_VERTICAL), MPFROMLONG(10000000));
+		break;
+	}
+}
+
+/*
  * Removes all rows from a container.
  * Parameters:
  *       handle: Handle to the window (widget) to be cleared.