changeset 33:72675de7d229

Renamed slider class to percent class. Implemented my own percent widget on OS/2 to avoid horrible memory leak.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Thu, 30 Aug 2001 06:07:19 +0000
parents f3bf96c2786d
children b03b24bb95f8
files dw.def dw.h dww.def gtk/dw.c os2/dw.c win/dw.c
diffstat 6 files changed, 206 insertions(+), 59 deletions(-) [+]
line wrap: on
line diff
--- a/dw.def	Mon Aug 27 17:16:12 2001 +0000
+++ b/dw.def	Thu Aug 30 06:07:19 2001 +0000
@@ -83,9 +83,9 @@
   dw_listbox_selected                    @149
   dw_listbox_selected_multi              @150
 
-  dw_slider_new                          @160
-  dw_slider_query_range                  @161
-  dw_slider_set_pos                      @162
+  dw_percent_new                         @160
+  dw_percent_query_range                 @161
+  dw_percent_set_pos                     @162
 
   dw_mle_new                             @170
   dw_mle_import                          @171
--- a/dw.h	Mon Aug 27 17:16:12 2001 +0000
+++ b/dw.h	Thu Aug 30 06:07:19 2001 +0000
@@ -124,6 +124,11 @@
 	HWND menu;
 } *HMENUI;
 
+typedef struct _percentbar {
+	unsigned long pos;
+	PFNWP oldproc;
+} PercentBar;
+
 extern HAB dwhab;
 extern HMQ dwhmq;
 #endif
@@ -593,7 +598,7 @@
 HWND dw_button_new(char *text, unsigned long id);
 HWND dw_spinbutton_new(char *text, unsigned long id);
 HWND dw_radiobutton_new(char *text, ULONG id);
-HWND dw_slider_new(unsigned long id);
+HWND dw_percent_new(unsigned long id);
 HWND dw_checkbox_new(char *text, unsigned long id);
 HWND dw_listbox_new(unsigned long id, int multi);
 void dw_listbox_append(HWND handle, char *text);
@@ -606,8 +611,8 @@
 void dw_listbox_set_text(HWND handle, unsigned int index, char *buffer);
 unsigned int dw_listbox_selected(HWND handle);
 int dw_listbox_selected_multi(HWND handle, int where);
-unsigned int dw_slider_query_range(HWND handle);
-void dw_slider_set_pos(HWND handle, unsigned int position);
+unsigned int dw_percent_query_range(HWND handle);
+void dw_percent_set_pos(HWND handle, unsigned int position);
 void dw_window_set_pos(HWND handle, unsigned long x, unsigned long y);
 void dw_window_set_usize(HWND handle, unsigned long width, unsigned long height);
 void dw_window_set_pos_size(HWND handle, unsigned long x, unsigned long y, unsigned long width, unsigned long height);
--- a/dww.def	Mon Aug 27 17:16:12 2001 +0000
+++ b/dww.def	Thu Aug 30 06:07:19 2001 +0000
@@ -80,9 +80,9 @@
   dw_listbox_selected                    @149
   dw_listbox_selected_multi              @150
 
-  dw_slider_new                          @160
-  dw_slider_query_range                  @161
-  dw_slider_set_pos                      @162
+  dw_percent_new                         @160
+  dw_percent_query_range                 @161
+  dw_percent_set_pos                     @162
 
   dw_mle_new                             @170
   dw_mle_import                          @171
--- a/gtk/dw.c	Mon Aug 27 17:16:12 2001 +0000
+++ b/gtk/dw.c	Thu Aug 30 06:07:19 2001 +0000
@@ -1749,11 +1749,11 @@
 }
 
 /*
- * Create a new slider window (widget) to be packed.
+ * Create a new percent bar window (widget) to be packed.
  * Parameters:
  *       id: An ID to be used with WinWindowFromID() or 0L.
  */
-HWND dw_slider_new(unsigned long id)
+HWND dw_percent_new(unsigned long id)
 {
 	GtkWidget *tmp;
 	int _locked_by_me = FALSE;
@@ -2298,22 +2298,22 @@
 }
 
 /*
- * Returns the range of the slider.
+ * Returns the range of the percent bar.
  * Parameters:
  *          handle: Handle to the slider to be queried.
  */
-unsigned int dw_slider_query_range(HWND handle)
+unsigned int dw_percent_query_range(HWND handle)
 {
 	return 100;
 }
 
 /*
- * Sets the slider position.
+ * Sets the percent bar position.
  * Parameters:
  *          handle: Handle to the slider to be set.
  *          position: Position of the slider withing the range.
  */
-void dw_slider_set_pos(HWND handle, unsigned int position)
+void dw_percent_set_pos(HWND handle, unsigned int position)
 {
 	int _locked_by_me = FALSE;
 
--- a/os2/dw.c	Mon Aug 27 17:16:12 2001 +0000
+++ b/os2/dw.c	Thu Aug 30 06:07:19 2001 +0000
@@ -979,6 +979,53 @@
 
 	return WinDefWindowProc(hWnd, msg, mp1, mp2);
 }
+
+void _Top(HPS hpsPaint, RECTL rclPaint)
+{
+	POINTL ptl1, ptl2;
+
+	ptl1.x = rclPaint.xLeft;
+	ptl2.y = ptl1.y = rclPaint.yTop - 1;
+	ptl2.x = rclPaint.xRight - 1;
+	GpiMove(hpsPaint, &ptl1);
+	GpiLine(hpsPaint, &ptl2);
+}
+
+/* Left hits the bottom */
+void _Left(HPS hpsPaint, RECTL rclPaint)
+{
+	POINTL ptl1, ptl2;
+
+	ptl2.x = ptl1.x = rclPaint.xLeft;
+	ptl1.y = rclPaint.yTop - 1;
+	ptl2.y = rclPaint.yBottom;
+	GpiMove(hpsPaint, &ptl1);
+	GpiLine(hpsPaint, &ptl2);
+}
+
+void _Bottom(HPS hpsPaint, RECTL rclPaint)
+{
+	POINTL ptl1, ptl2;
+
+	ptl1.x = rclPaint.xRight - 1;
+	ptl1.y = ptl2.y = rclPaint.yBottom;
+	ptl2.x = rclPaint.xLeft;
+	GpiMove(hpsPaint, &ptl1);
+	GpiLine(hpsPaint, &ptl2);
+}
+
+/* Right hits the top */
+void _Right(HPS hpsPaint, RECTL rclPaint)
+{
+	POINTL ptl1, ptl2;
+
+	ptl2.x = ptl1.x = rclPaint.xRight - 1;
+	ptl1.y = rclPaint.yBottom + 1;
+	ptl2.y = rclPaint.yTop - 1;
+	GpiMove(hpsPaint, &ptl1);
+	GpiLine(hpsPaint, &ptl2);
+}
+
 /* This procedure handles drawing of a status border */
 MRESULT EXPENTRY _statusproc(HWND hWnd, ULONG msg, MPARAM mp1, MPARAM mp2)
 {
@@ -994,7 +1041,6 @@
 			{
 				HPS hpsPaint;
 				RECTL rclPaint;
-				POINTL ptl1, ptl2;
 				char buf[1024];
 
 				hpsPaint = WinBeginPaint(hWnd, 0, 0);
@@ -1002,24 +1048,12 @@
 				WinFillRect(hpsPaint, &rclPaint, CLR_PALEGRAY);
 
 				GpiSetColor(hpsPaint, CLR_DARKGRAY);
-				ptl1.x = 0;
-				ptl2.y = ptl1.y = rclPaint.yTop - rclPaint.yBottom;
-				ptl2.x = rclPaint.xRight - rclPaint.xLeft;
-				GpiMove(hpsPaint, &ptl1);
-				GpiLine(hpsPaint, &ptl2);
-				ptl2.y = ptl2.x = 0;
-				GpiMove(hpsPaint, &ptl1);
-				GpiLine(hpsPaint, &ptl2);
+				_Top(hpsPaint, rclPaint);
+				_Left(hpsPaint, rclPaint);
 
 				GpiSetColor(hpsPaint, CLR_WHITE);
-				ptl2.x = ptl1.x = rclPaint.xRight - rclPaint.xLeft;
-				ptl1.y = 0;
-				ptl2.y = rclPaint.yTop - rclPaint.yBottom;
-				GpiMove(hpsPaint, &ptl1);
-				GpiLine(hpsPaint, &ptl2);
-				ptl2.y = ptl2.x = 0;
-				GpiMove(hpsPaint, &ptl1);
-				GpiLine(hpsPaint, &ptl2);
+				_Right(hpsPaint, rclPaint);
+				_Bottom(hpsPaint, rclPaint);
 
 				WinQueryWindowText(hWnd, 1024, buf);
 				rclPaint.xLeft += 3;
@@ -1040,6 +1074,91 @@
 	return WinDefWindowProc(hWnd, msg, mp1, mp2);
 }
 
+/* This procedure handles drawing of a percent bar */
+MRESULT EXPENTRY _percentproc(HWND hWnd, ULONG msg, MPARAM mp1, MPARAM mp2)
+{
+	PercentBar *blah = (PercentBar *)WinQueryWindowPtr(hWnd, QWP_USER);
+
+	if(blah)
+	{
+		PFNWP myfunc = blah->oldproc;
+
+		switch(msg)
+		{
+		case WM_PAINT:
+			{
+				HPS hpsPaint;
+				RECTL rclPaint, rclBar;
+
+				hpsPaint = WinBeginPaint(hWnd, 0, 0);
+				WinQueryWindowRect(hWnd, &rclPaint);
+
+				/* Draw outer border */
+				rclBar = rclPaint;
+				GpiSetColor(hpsPaint, CLR_PALEGRAY);
+				_Top(hpsPaint, rclBar);
+				_Bottom(hpsPaint, rclBar);
+				rclBar.yTop--;
+				GpiSetColor(hpsPaint, CLR_WHITE);
+				_Right(hpsPaint, rclBar);
+				rclBar.yBottom++;
+				GpiSetColor(hpsPaint, CLR_DARKGRAY);
+				_Left(hpsPaint, rclBar);
+
+				/* Draw inner border */
+				rclBar.xLeft++;
+				rclBar.xRight--;
+				GpiSetColor(hpsPaint, CLR_DARKGRAY);
+				_Left(hpsPaint, rclBar);
+				_Top(hpsPaint, rclBar);
+				GpiSetColor(hpsPaint, CLR_WHITE);
+				_Bottom(hpsPaint, rclBar);
+				_Right(hpsPaint, rclBar);
+
+				/* Draw bar border */
+				rclBar.xLeft++;
+				rclBar.xRight--;
+				rclBar.yBottom++;
+				rclBar.yTop--;
+				GpiSetColor(hpsPaint, CLR_DARKGRAY);
+				_Left(hpsPaint, rclBar);
+				_Top(hpsPaint, rclBar);
+				_Bottom(hpsPaint, rclBar);
+				_Right(hpsPaint, rclBar);
+
+				if(blah->pos)
+				{
+					rclBar.xRight = 3 + blah->pos;
+					_Right(hpsPaint, rclBar);
+
+					/* Draw Bar itself */
+					rclBar.xLeft = rclPaint.xLeft + 3;
+					rclBar.xRight = rclPaint.xLeft +  2 + blah->pos;
+					rclBar.yTop = rclPaint.yTop - 3;
+					rclBar.yBottom = rclPaint.yBottom + 3;
+
+					WinFillRect(hpsPaint, &rclBar, CLR_DARKBLUE);
+				}
+
+				/* Draw the background */
+				rclBar.xLeft = rclPaint.xLeft + 3 + blah->pos;
+				rclBar.xRight = rclPaint.xRight - 3;
+				rclBar.yTop = rclPaint.yTop - 3;
+				rclBar.yBottom = rclPaint.yBottom + 3;
+
+				WinFillRect(hpsPaint, &rclBar, CLR_PALEGRAY);
+
+				WinEndPaint(hpsPaint);
+
+				return (MRESULT)TRUE;
+			}
+		}
+		return myfunc(hWnd, msg, mp1, mp2);
+	}
+
+	return WinDefWindowProc(hWnd, msg, mp1, mp2);
+}
+
 /* Originally just intended for entryfields, it now serves as a generic
  * procedure for handling TAB presses to change input focus on controls.
  */
@@ -3298,22 +3417,30 @@
 }
 
 /*
- * Create a new slider window (widget) to be packed.
+ * Create a new percent bar window (widget) to be packed.
  * Parameters:
  *       id: An ID to be used with WinWindowFromID() or 0L.
  */
-HWND dw_slider_new(ULONG id)
-{
-	return WinCreateWindow(HWND_OBJECT,
-						   WC_SLIDER,
-						   NULL,
-						   WS_VISIBLE,
-						   0,0,2000,1000,
-						   NULLHANDLE,
-						   HWND_TOP,
-						   id,
-						   NULL,
-						   NULL);
+HWND dw_percent_new(ULONG id)
+{
+	PercentBar *blah = malloc(sizeof(PercentBar));
+	HWND tmp = WinCreateWindow(HWND_OBJECT,
+							   WC_STATIC,
+							   "",
+							   WS_VISIBLE | SS_TEXT,
+							   0,0,2000,1000,
+							   NULLHANDLE,
+							   HWND_TOP,
+							   id,
+							   NULL,
+							   NULL);
+	dw_window_set_font(tmp, DefaultFont);
+	dw_window_set_color(tmp, DW_CLR_BLUE, DW_CLR_PALEGRAY);
+
+	blah->oldproc = WinSubclassWindow(tmp, _percentproc);
+	blah->pos = 0;
+	WinSetWindowPtr(tmp, QWP_USER, blah);
+	return tmp;
 }
 
 /*
@@ -4151,24 +4278,39 @@
 }
 
 /*
- * Returns the range of the slider.
+ * Returns the range of the percent bar.
  * Parameters:
  *          handle: Handle to the slider to be queried.
  */
-unsigned int dw_slider_query_range(HWND handle)
-{
-	return SHORT2FROMMP(WinSendMsg(handle, SLM_QUERYSLIDERINFO, MPFROM2SHORT(SMA_SLIDERARMPOSITION,SMA_RANGEVALUE), 0));
+unsigned int dw_percent_query_range(HWND handle)
+{
+	unsigned long width;
+
+	dw_window_get_pos_size(handle, 0, 0, &width, 0);
+
+	if(width - 6 < 1)
+		return 1;
+	return width - 6;
 }
 
 /*
- * Sets the slider position.
+ * Sets the percent bar position.
  * Parameters:
  *          handle: Handle to the slider to be set.
  *          position: Position of the slider withing the range.
  */
-void dw_slider_set_pos(HWND handle, unsigned int position)
-{
-	WinSendMsg(handle, SLM_SETSLIDERINFO, MPFROM2SHORT(SMA_SLIDERARMPOSITION,SMA_RANGEVALUE), (MPARAM)position);
+void dw_percent_set_pos(HWND handle, unsigned int position)
+{
+	PercentBar *pb = (PercentBar *)WinQueryWindowPtr(handle, 0);
+
+	if(pb)
+	{
+		RECTL rcl;
+
+		pb->pos = position;
+		WinQueryWindowRect(handle, &rcl);
+		WinInvalidateRect(handle, &rcl, FALSE);
+	}
 }
 
 /*
--- a/win/dw.c	Mon Aug 27 17:16:12 2001 +0000
+++ b/win/dw.c	Thu Aug 30 06:07:19 2001 +0000
@@ -3363,11 +3363,11 @@
 
 
 /*
- * Create a new slider window (widget) to be packed.
+ * Create a new percent bar window (widget) to be packed.
  * Parameters:
  *       id: An ID to be used with WinWindowFromID() or 0L.
  */
-HWND dw_slider_new(ULONG id)
+HWND dw_percent_new(ULONG id)
 {
 	return CreateWindow(PROGRESS_CLASS,
 						"",
@@ -4375,22 +4375,22 @@
 }
 
 /*
- * Returns the range of the slider.
+ * Returns the range of the percent bar.
  * Parameters:
  *          handle: Handle to the slider to be queried.
  */
-unsigned int dw_slider_query_range(HWND handle)
+unsigned int dw_percent_query_range(HWND handle)
 {
 	return (unsigned int)SendMessage(handle, PBM_GETRANGE, (WPARAM)FALSE, 0);
 }
 
 /*
- * Sets the slider position.
+ * Sets the percent bar position.
  * Parameters:
  *          handle: Handle to the slider to be set.
  *          position: Position of the slider withing the range.
  */
-void dw_slider_set_pos(HWND handle, unsigned int position)
+void dw_percent_set_pos(HWND handle, unsigned int position)
 {
 	SendMessage(handle, PBM_SETPOS, (WPARAM)position, 0);
 }