comparison os2/dw.c @ 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 17a08cfd45d2
children b03b24bb95f8
comparison
equal deleted inserted replaced
32:f3bf96c2786d 33:72675de7d229
977 return myfunc(hWnd, msg, mp1, mp2); 977 return myfunc(hWnd, msg, mp1, mp2);
978 } 978 }
979 979
980 return WinDefWindowProc(hWnd, msg, mp1, mp2); 980 return WinDefWindowProc(hWnd, msg, mp1, mp2);
981 } 981 }
982
983 void _Top(HPS hpsPaint, RECTL rclPaint)
984 {
985 POINTL ptl1, ptl2;
986
987 ptl1.x = rclPaint.xLeft;
988 ptl2.y = ptl1.y = rclPaint.yTop - 1;
989 ptl2.x = rclPaint.xRight - 1;
990 GpiMove(hpsPaint, &ptl1);
991 GpiLine(hpsPaint, &ptl2);
992 }
993
994 /* Left hits the bottom */
995 void _Left(HPS hpsPaint, RECTL rclPaint)
996 {
997 POINTL ptl1, ptl2;
998
999 ptl2.x = ptl1.x = rclPaint.xLeft;
1000 ptl1.y = rclPaint.yTop - 1;
1001 ptl2.y = rclPaint.yBottom;
1002 GpiMove(hpsPaint, &ptl1);
1003 GpiLine(hpsPaint, &ptl2);
1004 }
1005
1006 void _Bottom(HPS hpsPaint, RECTL rclPaint)
1007 {
1008 POINTL ptl1, ptl2;
1009
1010 ptl1.x = rclPaint.xRight - 1;
1011 ptl1.y = ptl2.y = rclPaint.yBottom;
1012 ptl2.x = rclPaint.xLeft;
1013 GpiMove(hpsPaint, &ptl1);
1014 GpiLine(hpsPaint, &ptl2);
1015 }
1016
1017 /* Right hits the top */
1018 void _Right(HPS hpsPaint, RECTL rclPaint)
1019 {
1020 POINTL ptl1, ptl2;
1021
1022 ptl2.x = ptl1.x = rclPaint.xRight - 1;
1023 ptl1.y = rclPaint.yBottom + 1;
1024 ptl2.y = rclPaint.yTop - 1;
1025 GpiMove(hpsPaint, &ptl1);
1026 GpiLine(hpsPaint, &ptl2);
1027 }
1028
982 /* This procedure handles drawing of a status border */ 1029 /* This procedure handles drawing of a status border */
983 MRESULT EXPENTRY _statusproc(HWND hWnd, ULONG msg, MPARAM mp1, MPARAM mp2) 1030 MRESULT EXPENTRY _statusproc(HWND hWnd, ULONG msg, MPARAM mp1, MPARAM mp2)
984 { 1031 {
985 PFNWP *blah = WinQueryWindowPtr(hWnd, QWP_USER); 1032 PFNWP *blah = WinQueryWindowPtr(hWnd, QWP_USER);
986 1033
992 { 1039 {
993 case WM_PAINT: 1040 case WM_PAINT:
994 { 1041 {
995 HPS hpsPaint; 1042 HPS hpsPaint;
996 RECTL rclPaint; 1043 RECTL rclPaint;
997 POINTL ptl1, ptl2;
998 char buf[1024]; 1044 char buf[1024];
999 1045
1000 hpsPaint = WinBeginPaint(hWnd, 0, 0); 1046 hpsPaint = WinBeginPaint(hWnd, 0, 0);
1001 WinQueryWindowRect(hWnd, &rclPaint); 1047 WinQueryWindowRect(hWnd, &rclPaint);
1002 WinFillRect(hpsPaint, &rclPaint, CLR_PALEGRAY); 1048 WinFillRect(hpsPaint, &rclPaint, CLR_PALEGRAY);
1003 1049
1004 GpiSetColor(hpsPaint, CLR_DARKGRAY); 1050 GpiSetColor(hpsPaint, CLR_DARKGRAY);
1005 ptl1.x = 0; 1051 _Top(hpsPaint, rclPaint);
1006 ptl2.y = ptl1.y = rclPaint.yTop - rclPaint.yBottom; 1052 _Left(hpsPaint, rclPaint);
1007 ptl2.x = rclPaint.xRight - rclPaint.xLeft;
1008 GpiMove(hpsPaint, &ptl1);
1009 GpiLine(hpsPaint, &ptl2);
1010 ptl2.y = ptl2.x = 0;
1011 GpiMove(hpsPaint, &ptl1);
1012 GpiLine(hpsPaint, &ptl2);
1013 1053
1014 GpiSetColor(hpsPaint, CLR_WHITE); 1054 GpiSetColor(hpsPaint, CLR_WHITE);
1015 ptl2.x = ptl1.x = rclPaint.xRight - rclPaint.xLeft; 1055 _Right(hpsPaint, rclPaint);
1016 ptl1.y = 0; 1056 _Bottom(hpsPaint, rclPaint);
1017 ptl2.y = rclPaint.yTop - rclPaint.yBottom;
1018 GpiMove(hpsPaint, &ptl1);
1019 GpiLine(hpsPaint, &ptl2);
1020 ptl2.y = ptl2.x = 0;
1021 GpiMove(hpsPaint, &ptl1);
1022 GpiLine(hpsPaint, &ptl2);
1023 1057
1024 WinQueryWindowText(hWnd, 1024, buf); 1058 WinQueryWindowText(hWnd, 1024, buf);
1025 rclPaint.xLeft += 3; 1059 rclPaint.xLeft += 3;
1026 rclPaint.xRight--; 1060 rclPaint.xRight--;
1027 rclPaint.yTop--; 1061 rclPaint.yTop--;
1028 rclPaint.yBottom++; 1062 rclPaint.yBottom++;
1029 1063
1030 GpiSetColor(hpsPaint, CLR_BLACK); 1064 GpiSetColor(hpsPaint, CLR_BLACK);
1031 WinDrawText(hpsPaint, -1, buf, &rclPaint, DT_TEXTATTRS, DT_TEXTATTRS, DT_VCENTER | DT_LEFT | DT_TEXTATTRS); 1065 WinDrawText(hpsPaint, -1, buf, &rclPaint, DT_TEXTATTRS, DT_TEXTATTRS, DT_VCENTER | DT_LEFT | DT_TEXTATTRS);
1066 WinEndPaint(hpsPaint);
1067
1068 return (MRESULT)TRUE;
1069 }
1070 }
1071 return myfunc(hWnd, msg, mp1, mp2);
1072 }
1073
1074 return WinDefWindowProc(hWnd, msg, mp1, mp2);
1075 }
1076
1077 /* This procedure handles drawing of a percent bar */
1078 MRESULT EXPENTRY _percentproc(HWND hWnd, ULONG msg, MPARAM mp1, MPARAM mp2)
1079 {
1080 PercentBar *blah = (PercentBar *)WinQueryWindowPtr(hWnd, QWP_USER);
1081
1082 if(blah)
1083 {
1084 PFNWP myfunc = blah->oldproc;
1085
1086 switch(msg)
1087 {
1088 case WM_PAINT:
1089 {
1090 HPS hpsPaint;
1091 RECTL rclPaint, rclBar;
1092
1093 hpsPaint = WinBeginPaint(hWnd, 0, 0);
1094 WinQueryWindowRect(hWnd, &rclPaint);
1095
1096 /* Draw outer border */
1097 rclBar = rclPaint;
1098 GpiSetColor(hpsPaint, CLR_PALEGRAY);
1099 _Top(hpsPaint, rclBar);
1100 _Bottom(hpsPaint, rclBar);
1101 rclBar.yTop--;
1102 GpiSetColor(hpsPaint, CLR_WHITE);
1103 _Right(hpsPaint, rclBar);
1104 rclBar.yBottom++;
1105 GpiSetColor(hpsPaint, CLR_DARKGRAY);
1106 _Left(hpsPaint, rclBar);
1107
1108 /* Draw inner border */
1109 rclBar.xLeft++;
1110 rclBar.xRight--;
1111 GpiSetColor(hpsPaint, CLR_DARKGRAY);
1112 _Left(hpsPaint, rclBar);
1113 _Top(hpsPaint, rclBar);
1114 GpiSetColor(hpsPaint, CLR_WHITE);
1115 _Bottom(hpsPaint, rclBar);
1116 _Right(hpsPaint, rclBar);
1117
1118 /* Draw bar border */
1119 rclBar.xLeft++;
1120 rclBar.xRight--;
1121 rclBar.yBottom++;
1122 rclBar.yTop--;
1123 GpiSetColor(hpsPaint, CLR_DARKGRAY);
1124 _Left(hpsPaint, rclBar);
1125 _Top(hpsPaint, rclBar);
1126 _Bottom(hpsPaint, rclBar);
1127 _Right(hpsPaint, rclBar);
1128
1129 if(blah->pos)
1130 {
1131 rclBar.xRight = 3 + blah->pos;
1132 _Right(hpsPaint, rclBar);
1133
1134 /* Draw Bar itself */
1135 rclBar.xLeft = rclPaint.xLeft + 3;
1136 rclBar.xRight = rclPaint.xLeft + 2 + blah->pos;
1137 rclBar.yTop = rclPaint.yTop - 3;
1138 rclBar.yBottom = rclPaint.yBottom + 3;
1139
1140 WinFillRect(hpsPaint, &rclBar, CLR_DARKBLUE);
1141 }
1142
1143 /* Draw the background */
1144 rclBar.xLeft = rclPaint.xLeft + 3 + blah->pos;
1145 rclBar.xRight = rclPaint.xRight - 3;
1146 rclBar.yTop = rclPaint.yTop - 3;
1147 rclBar.yBottom = rclPaint.yBottom + 3;
1148
1149 WinFillRect(hpsPaint, &rclBar, CLR_PALEGRAY);
1150
1032 WinEndPaint(hpsPaint); 1151 WinEndPaint(hpsPaint);
1033 1152
1034 return (MRESULT)TRUE; 1153 return (MRESULT)TRUE;
1035 } 1154 }
1036 } 1155 }
3296 WinSetWindowPtr(tmp, QWP_USER, blah); 3415 WinSetWindowPtr(tmp, QWP_USER, blah);
3297 return tmp; 3416 return tmp;
3298 } 3417 }
3299 3418
3300 /* 3419 /*
3301 * Create a new slider window (widget) to be packed. 3420 * Create a new percent bar window (widget) to be packed.
3302 * Parameters: 3421 * Parameters:
3303 * id: An ID to be used with WinWindowFromID() or 0L. 3422 * id: An ID to be used with WinWindowFromID() or 0L.
3304 */ 3423 */
3305 HWND dw_slider_new(ULONG id) 3424 HWND dw_percent_new(ULONG id)
3306 { 3425 {
3307 return WinCreateWindow(HWND_OBJECT, 3426 PercentBar *blah = malloc(sizeof(PercentBar));
3308 WC_SLIDER, 3427 HWND tmp = WinCreateWindow(HWND_OBJECT,
3309 NULL, 3428 WC_STATIC,
3310 WS_VISIBLE, 3429 "",
3311 0,0,2000,1000, 3430 WS_VISIBLE | SS_TEXT,
3312 NULLHANDLE, 3431 0,0,2000,1000,
3313 HWND_TOP, 3432 NULLHANDLE,
3314 id, 3433 HWND_TOP,
3315 NULL, 3434 id,
3316 NULL); 3435 NULL,
3436 NULL);
3437 dw_window_set_font(tmp, DefaultFont);
3438 dw_window_set_color(tmp, DW_CLR_BLUE, DW_CLR_PALEGRAY);
3439
3440 blah->oldproc = WinSubclassWindow(tmp, _percentproc);
3441 blah->pos = 0;
3442 WinSetWindowPtr(tmp, QWP_USER, blah);
3443 return tmp;
3317 } 3444 }
3318 3445
3319 /* 3446 /*
3320 * Create a new checkbox window (widget) to be packed. 3447 * Create a new checkbox window (widget) to be packed.
3321 * Parameters: 3448 * Parameters:
4149 { 4276 {
4150 WinSendMsg(handle, MLM_ENABLEREFRESH, 0, 0); 4277 WinSendMsg(handle, MLM_ENABLEREFRESH, 0, 0);
4151 } 4278 }
4152 4279
4153 /* 4280 /*
4154 * Returns the range of the slider. 4281 * Returns the range of the percent bar.
4155 * Parameters: 4282 * Parameters:
4156 * handle: Handle to the slider to be queried. 4283 * handle: Handle to the slider to be queried.
4157 */ 4284 */
4158 unsigned int dw_slider_query_range(HWND handle) 4285 unsigned int dw_percent_query_range(HWND handle)
4159 { 4286 {
4160 return SHORT2FROMMP(WinSendMsg(handle, SLM_QUERYSLIDERINFO, MPFROM2SHORT(SMA_SLIDERARMPOSITION,SMA_RANGEVALUE), 0)); 4287 unsigned long width;
4161 } 4288
4162 4289 dw_window_get_pos_size(handle, 0, 0, &width, 0);
4163 /* 4290
4164 * Sets the slider position. 4291 if(width - 6 < 1)
4292 return 1;
4293 return width - 6;
4294 }
4295
4296 /*
4297 * Sets the percent bar position.
4165 * Parameters: 4298 * Parameters:
4166 * handle: Handle to the slider to be set. 4299 * handle: Handle to the slider to be set.
4167 * position: Position of the slider withing the range. 4300 * position: Position of the slider withing the range.
4168 */ 4301 */
4169 void dw_slider_set_pos(HWND handle, unsigned int position) 4302 void dw_percent_set_pos(HWND handle, unsigned int position)
4170 { 4303 {
4171 WinSendMsg(handle, SLM_SETSLIDERINFO, MPFROM2SHORT(SMA_SLIDERARMPOSITION,SMA_RANGEVALUE), (MPARAM)position); 4304 PercentBar *pb = (PercentBar *)WinQueryWindowPtr(handle, 0);
4305
4306 if(pb)
4307 {
4308 RECTL rcl;
4309
4310 pb->pos = position;
4311 WinQueryWindowRect(handle, &rcl);
4312 WinInvalidateRect(handle, &rcl, FALSE);
4313 }
4172 } 4314 }
4173 4315
4174 /* 4316 /*
4175 * Sets the spinbutton value. 4317 * Sets the spinbutton value.
4176 * Parameters: 4318 * Parameters: