Changeset 232 for trunk/src/helpers/comctl.c
- Timestamp:
- Dec 5, 2002, 9:36:28 PM (23 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/helpers/comctl.c
r229 r232 90 90 #define INCL_WINSTDCNR 91 91 #define INCL_WINENTRYFIELDS 92 #define INCL_WINSHELLDATA 92 93 93 94 #define INCL_GPIPRIMITIVES … … 112 113 #include "helpers\linklist.h" 113 114 #include "helpers\winh.h" 115 #include "helpers\standards.h" 114 116 115 117 #include "helpers\comctl.h" 116 118 117 119 #pragma hdrstop 120 121 /* ****************************************************************** 122 * 123 * Shared stuff 124 * 125 ********************************************************************/ 126 127 /* 128 *@@ ctlSendWmControl: 129 * little helper that post a WM_CONTROL message to 130 * a control's owner. 131 * 132 *@@added V1.0.1 (2002-11-30) [umoeller] 133 */ 134 135 MRESULT ctlSendWmControl(HWND hwndControl, // in: control who's posting 136 USHORT usCode, // in: code for SHORT2FROMMP(mp1) 137 MPARAM mp2) // in: mp2 from WM_CONTROL 138 { 139 HWND hwndOwner; 140 141 if (hwndOwner = WinQueryWindow(hwndControl, QW_OWNER)) 142 return WinSendMsg(hwndOwner, 143 WM_CONTROL, 144 MPFROM2SHORT(WinQueryWindowUShort(hwndControl, QWS_ID), 145 usCode), 146 mp2); 147 148 return NULL; 149 } 150 151 /* 152 *@@ ctlPostWmControl: 153 * little helper that post a WM_CONTROL message to 154 * a control's owner. 155 * 156 *@@added V1.0.1 (2002-11-30) [umoeller] 157 */ 158 159 BOOL ctlPostWmControl(HWND hwndControl, // in: control who's posting 160 USHORT usCode, // in: code for SHORT2FROMMP(mp1) 161 MPARAM mp2) // in: mp2 from WM_CONTROL 162 { 163 HWND hwndOwner; 164 165 if (hwndOwner = WinQueryWindow(hwndControl, QW_OWNER)) 166 return WinPostMsg(hwndOwner, 167 WM_CONTROL, 168 MPFROM2SHORT(WinQueryWindowUShort(hwndControl, QWS_ID), 169 usCode), 170 mp2); 171 172 return FALSE; 173 } 174 175 /* 176 *@@ ctlInitDWD: 177 * ininitializes the DEFWINDATA struct for the 178 * given window. This must be called in WM_CREATE 179 * of a window proc if it intends to use 180 * ctlDefWindowProc as its default window procedure. 181 * 182 *@@added V1.0.1 (2002-11-30) [umoeller] 183 */ 184 185 VOID ctlInitDWD(HWND hwnd, 186 MPARAM mp2, 187 PDEFWINDATA pdwd, 188 PFNWP pDefWindowProc, 189 const SYSCOLORSET *pSysColorSet) 190 { 191 pdwd->hwnd = hwnd; 192 pdwd->szlWin.cx = ((PCREATESTRUCT)mp2)->cx; 193 pdwd->szlWin.cy = ((PCREATESTRUCT)mp2)->cy; 194 pdwd->hab = WinQueryAnchorBlock(hwnd); 195 pdwd->pDefWindowProc = pDefWindowProc; 196 pdwd->pSysColorSet = pSysColorSet; 197 198 ctlRefreshColors(pdwd); 199 } 200 201 /* 202 *@@ ctlRefreshColors: 203 * 204 *@@added V1.0.1 (2002-11-30) [umoeller] 205 */ 206 207 VOID ctlRefreshColors(PDEFWINDATA pdwd) 208 { 209 pdwd->lcolBackground = winhQueryPresColor2(pdwd->hwnd, 210 PP_BACKGROUNDCOLOR, 211 PP_BACKGROUNDCOLORINDEX, 212 pdwd->pSysColorSet->fInheritPP, 213 pdwd->pSysColorSet->lBackIndex); 214 pdwd->lcolForeground = winhQueryPresColor2(pdwd->hwnd, 215 PP_FOREGROUNDCOLOR, 216 PP_FOREGROUNDCOLORINDEX, 217 pdwd->pSysColorSet->fInheritPP, 218 pdwd->pSysColorSet->lForeIndex); 219 } 220 221 /* 222 *@@ ctlDefWindowProc: 223 * replacement default window procedure for controls that 224 * have a custom window class and do not inherit from 225 * standard OS/2 controls. 226 * 227 * If a window proc wishes to use this, it must allocate 228 * its own private window data in WM_CREATE (preferrably in 229 * QWL_USER + 1) and have room for a DEFWINDATA struct in 230 * there. It must call ctlInitDWD in WM_CREATE also which 231 * initializes that structure. It can then safely pass 232 * messages to this function. 233 * 234 *@@added V1.0.1 (2002-11-30) [umoeller] 235 */ 236 237 MRESULT ctlDefWindowProc(PDEFWINDATA pdwd, ULONG msg, MPARAM mp1, MPARAM mp2) 238 { 239 MRESULT mrc = 0; 240 241 switch (msg) 242 { 243 case WM_SYSCOLORCHANGE: 244 case WM_PRESPARAMCHANGED: 245 ctlRefreshColors(pdwd); 246 break; 247 248 default: 249 mrc = pdwd->pDefWindowProc(pdwd->hwnd, msg, mp1, mp2); 250 } 251 252 return mrc; 253 } 118 254 119 255 /* ****************************************************************** … … 131 267 * 132 268 *@@added V0.9.20 (2002-08-10) [umoeller] 269 *@@changed V1.0.1 (2002-11-30) [umoeller]: added SEPS_VERTICAL 133 270 */ 134 271 … … 150 287 gpihSwitchToRGB(hps); 151 288 152 GpiSetColor(hps, WinQuerySysColor(HWND_DESKTOP, SYSCLR_BUTTONLIGHT, 0)); 153 154 ptl.x = rcl.xLeft; 155 ptl.y = (rcl.yTop - rcl.yBottom) / 2 - 1; 156 GpiMove(hps, &ptl); 157 ptl.x = rcl.xRight; 158 GpiLine(hps, &ptl); 159 160 GpiSetColor(hps, WinQuerySysColor(HWND_DESKTOP, SYSCLR_BUTTONDARK, 0)); 161 162 ptl.x = rcl.xLeft; 163 ++ptl.y; 164 GpiMove(hps, &ptl); 165 ptl.x = rcl.xRight; 166 GpiLine(hps, &ptl); 289 WinFillRect(hps, 290 &rcl, 291 winhQueryPresColor2(hwnd, 292 PP_BACKGROUNDCOLOR, 293 PP_BACKGROUNDCOLORINDEX, 294 TRUE, 295 SYSCLR_WINDOW)); 296 297 if (WinQueryWindowULong(hwnd, QWL_STYLE) & SEPS_VERTICAL) 298 { 299 GpiSetColor(hps, G_lcol3DDark); 300 301 ptl.x = (rcl.xRight - rcl.xLeft) / 2 - 1; 302 ptl.y = rcl.yBottom; 303 GpiMove(hps, &ptl); 304 ptl.y = rcl.yTop; 305 GpiLine(hps, &ptl); 306 307 GpiSetColor(hps, G_lcol3DLight); 308 309 ptl.y = rcl.yBottom; 310 ++ptl.x; 311 GpiMove(hps, &ptl); 312 ptl.y = rcl.yTop; 313 GpiLine(hps, &ptl); 314 } 315 else 316 { 317 GpiSetColor(hps, G_lcol3DLight); 318 319 ptl.x = rcl.xLeft; 320 ptl.y = (rcl.yTop - rcl.yBottom) / 2 - 1; 321 GpiMove(hps, &ptl); 322 ptl.x = rcl.xRight; 323 GpiLine(hps, &ptl); 324 325 GpiSetColor(hps, G_lcol3DDark); 326 327 ptl.x = rcl.xLeft; 328 ++ptl.y; 329 GpiMove(hps, &ptl); 330 ptl.x = rcl.xRight; 331 GpiLine(hps, &ptl); 332 } 167 333 168 334 WinEndPaint(hps); … … 179 345 180 346 /* 181 *@@ ctlMakeSeparatorLine: 182 * turns the given static control into a 3D separator line. 347 *@@ ctlRegisterSeparatorLine: 348 * registers the separator line control, which is a dull 349 * static displaying a 3D line for use as a separator 350 * in dialogs. 351 * 352 * In addition to the standard WS_* styles, the control 353 * supports the SEPS_VERTICAL style bit. If set, the 354 * separator is vertical; if not, it is horizontal. 183 355 * 184 356 *@@added V1.0.0 (2002-08-12) [umoeller] … … 195 367 196 368 return WinRegisterClass(hab, 197 WC_ SEPARATORLINE,369 WC_CCTL_SEPARATOR, 198 370 fnwpSeparatorLine, 199 371 (ciStatic.flClassStyle & ~CS_PUBLIC), … … 203 375 204 376 return FALSE; 205 }206 207 /* ******************************************************************208 *209 * "XButton" control210 *211 ********************************************************************/212 213 /*214 *@@ ctlPaintXButton:215 * paints an X-button control. Can be called externally216 * for just painting a button even if this is not really217 * a window.218 *219 * WARNING: this is work in progress and will change into220 * the future. Eventually this will turn into a full221 * button control replacement.222 *223 *@@added V0.9.13 (2001-06-21) [umoeller]224 *@@changed V0.9.16 (2001-10-24) [umoeller]: fixed wrong hatch color and paint offset225 *@@changed V0.9.16 (2001-10-28) [umoeller]: added bitmap support, fixed bad clip rectangle226 *@@changed V0.9.20 (2002-08-04) [umoeller]: fixed button offset, depressed color227 */228 229 VOID ctlPaintXButton(HPS hps, // in: presentation space (RGB mode)230 ULONG fl, // in: XBF_* flags231 PXBUTTONDATA pxbd) // in: button data232 {233 ULONG ulBorder = 0,234 cx,235 cy,236 ulOfs = 0;237 LONG lLeft,238 lRight,239 lColorMiddle = pxbd->lMiddle;240 RECTL rclWin;241 242 memcpy(&rclWin, &pxbd->rcl, sizeof(RECTL));243 244 if (0 == (fl & XBF_FLAT))245 ulBorder = 2;246 247 gpihSwitchToRGB(hps);248 249 if (fl & XBF_PRESSED)250 {251 // paint button "down":252 lLeft = pxbd->lcol3DDark;253 lRight = pxbd->lcol3DLight;254 // add offset for icon painting at the bottom255 ulOfs += 1;256 if (ulBorder == 0)257 ulBorder = 1;258 259 // make the depressed color darker260 // V0.9.20 (2002-07-31) [umoeller]261 gpihManipulateRGB(&lColorMiddle,262 .95);263 }264 else265 {266 lLeft = pxbd->lcol3DLight;267 lRight = pxbd->lcol3DDark;268 }269 270 if (ulBorder)271 {272 // button border:273 // now paint button frame274 275 // make rcl inclusive276 rclWin.xRight--;277 rclWin.yTop--;278 gpihDraw3DFrame(hps,279 &rclWin, // inclusive280 ulBorder,281 lLeft,282 lRight);283 284 // now paint button middle285 rclWin.xLeft += ulBorder;286 rclWin.yBottom += ulBorder;287 rclWin.xRight -= ulBorder - 1; // make exclusive again288 rclWin.yTop -= ulBorder - 1; // make exclusive again289 }290 291 if (fl & XBF_BACKGROUND)292 WinFillRect(hps,293 &rclWin, // exclusive294 lColorMiddle);295 296 // get icon297 if (pxbd->hptr)298 {299 // calculate x and y to be centered in rectangle300 POINTL ptl;301 302 cx = rclWin.xRight - rclWin.xLeft;303 cy = rclWin.yTop - rclWin.yBottom;304 305 ptl.x = rclWin.xLeft + ((cx - pxbd->cxIconOrBitmap) / 2);306 ptl.y = rclWin.yBottom + ((cy - pxbd->cyIconOrBitmap) / 2);307 308 if (fl & XBF_INUSE)309 {310 // caller wants in-use (hatched) emphasis:311 // draw a box then312 POINTL ptl2;313 ptl2.x = ptl.x - 2;314 ptl2.y = ptl.y - 2;315 GpiMove(hps,316 &ptl2); // &ptl317 // duh, typo V0.9.16 (2001-10-24) [umoeller]318 GpiSetPattern(hps, PATSYM_DIAG1);319 GpiSetColor(hps, RGBCOL_BLACK); // V0.9.16 (2001-10-24) [umoeller]320 ptl2.x = ptl.x + pxbd->cxIconOrBitmap + 1; // inclusive!321 ptl2.y = ptl.y + pxbd->cyIconOrBitmap + 1; // inclusive!322 GpiBox(hps,323 DRO_FILL,324 &ptl2,325 0,326 0);327 }328 329 // now paint icon330 331 // make rcl inclusive // V0.9.16 (2001-10-28) [umoeller]332 rclWin.xRight--;333 rclWin.yTop--;334 GpiIntersectClipRectangle(hps,335 &rclWin); // inclusive!336 337 // center this in remaining rectl338 ptl.x += ulOfs;339 ptl.y -= ulOfs;340 if (fl & XBF_BITMAP)341 // V0.9.16 (2001-10-28) [umoeller]342 WinDrawBitmap(hps,343 pxbd->hptr, // a bitmap really344 NULL, // entire bitmap345 &ptl,346 0,347 0,348 DBM_NORMAL);349 else350 WinDrawPointer(hps,351 // center this in remaining rectl352 ptl.x, // + ulOfs,353 ptl.y, // - ulOfs,354 pxbd->hptr,355 DP_MINI);356 }357 377 } 358 378 … … 1097 1117 WinQueryWindowRect(hwndStatic, &pa->rclIcon); 1098 1118 pa->OldStaticProc = WinSubclassWindow(hwndStatic, ctl_fnwpBitmapStatic); 1099 pa->szlIcon.cx = WinQuerySysValue(HWND_DESKTOP, SV_CXICON);1100 pa->szlIcon.cy = WinQuerySysValue(HWND_DESKTOP, SV_CYICON);1119 pa->szlIcon.cx = G_cxIcon; 1120 pa->szlIcon.cy = G_cyIcon; 1101 1121 } 1102 1122 } … … 1628 1648 // doesn't send any notifications, we 1629 1649 // use EN_CHANGED 1630 WinSendMsg(WinQueryWindow(hwndStatic, QW_OWNER), 1631 WM_CONTROL, 1632 MPFROM2SHORT(WinQueryWindowUShort(hwndStatic, QWS_ID), 1633 EN_CHANGE), 1634 (MPARAM)hwndStatic); 1650 ctlSendWmControl(hwndStatic, 1651 EN_CHANGE, 1652 (MPARAM)hwndStatic); 1635 1653 break; 1636 1654 }
Note:
See TracChangeset
for help on using the changeset viewer.