| 1 | /* $Id: button.cpp,v 1.36 2000-06-01 11:27:56 sandervl Exp $ */
|
|---|
| 2 | /* File: button.cpp -- Button type widgets
|
|---|
| 3 | *
|
|---|
| 4 | * Copyright (C) 1993 Johannes Ruscheinski
|
|---|
| 5 | * Copyright (C) 1993 David Metcalfe
|
|---|
| 6 | * Copyright (C) 1994 Alexandre Julliard
|
|---|
| 7 | * Copyright (c) 1999 Christoph Bratschi
|
|---|
| 8 | *
|
|---|
| 9 | * Corel version: 20000513
|
|---|
| 10 | * (WINE version: 20000130)
|
|---|
| 11 | *
|
|---|
| 12 | * Status: complete
|
|---|
| 13 | * Version: 5.00
|
|---|
| 14 | */
|
|---|
| 15 |
|
|---|
| 16 | #include <string.h>
|
|---|
| 17 | #include <stdlib.h>
|
|---|
| 18 | #include <os2win.h>
|
|---|
| 19 | #include "controls.h"
|
|---|
| 20 | #include "button.h"
|
|---|
| 21 | #include <misc.h>
|
|---|
| 22 | #include "initterm.h"
|
|---|
| 23 |
|
|---|
| 24 | #define DBG_LOCALLOG DBG_button
|
|---|
| 25 | #include "dbglocal.h"
|
|---|
| 26 |
|
|---|
| 27 | #ifdef DEBUG
|
|---|
| 28 | char *GetMsgText(int Msg);
|
|---|
| 29 | #endif
|
|---|
| 30 |
|
|---|
| 31 | //Prototypes
|
|---|
| 32 |
|
|---|
| 33 | static void DrawDisabledText(HDC hdc,char* text,RECT* rtext,UINT format);
|
|---|
| 34 |
|
|---|
| 35 | static void PB_Paint(HWND hwnd,HDC hDC,WORD action);
|
|---|
| 36 | static void CB_Paint(HWND hwnd,HDC hDC,WORD action);
|
|---|
| 37 | static void GB_Paint(HWND hwnd,HDC hDC,WORD action);
|
|---|
| 38 | static void UB_Paint(HWND hwnd,HDC hDC,WORD action);
|
|---|
| 39 | static void OB_Paint(HWND hwnd,HDC hDC,WORD action);
|
|---|
| 40 | static void BUTTON_CheckAutoRadioButton(HWND hwnd);
|
|---|
| 41 | static void BUTTON_DrawPushButton(HWND hwnd,HDC hDC,WORD action,BOOL pushedState);
|
|---|
| 42 | static LRESULT BUTTON_LButtonDown(HWND hwnd,WPARAM wParam,LPARAM lParam);
|
|---|
| 43 |
|
|---|
| 44 | #define MAX_BTN_TYPE 12
|
|---|
| 45 |
|
|---|
| 46 | static const WORD maxCheckState[MAX_BTN_TYPE] =
|
|---|
| 47 | {
|
|---|
| 48 | BUTTON_UNCHECKED, /* BS_PUSHBUTTON */
|
|---|
| 49 | BUTTON_UNCHECKED, /* BS_DEFPUSHBUTTON */
|
|---|
| 50 | BUTTON_CHECKED, /* BS_CHECKBOX */
|
|---|
| 51 | BUTTON_CHECKED, /* BS_AUTOCHECKBOX */
|
|---|
| 52 | BUTTON_CHECKED, /* BS_RADIOBUTTON */
|
|---|
| 53 | BUTTON_3STATE, /* BS_3STATE */
|
|---|
| 54 | BUTTON_3STATE, /* BS_AUTO3STATE */
|
|---|
| 55 | BUTTON_UNCHECKED, /* BS_GROUPBOX */
|
|---|
| 56 | BUTTON_UNCHECKED, /* BS_USERBUTTON */
|
|---|
| 57 | BUTTON_CHECKED, /* BS_AUTORADIOBUTTON */
|
|---|
| 58 | BUTTON_UNCHECKED, /* Not defined */
|
|---|
| 59 | BUTTON_UNCHECKED /* BS_OWNERDRAW */
|
|---|
| 60 | };
|
|---|
| 61 |
|
|---|
| 62 | typedef void (*pfPaint)(HWND hwnd,HDC hdc,WORD action);
|
|---|
| 63 |
|
|---|
| 64 | static const pfPaint btnPaintFunc[MAX_BTN_TYPE] =
|
|---|
| 65 | {
|
|---|
| 66 | PB_Paint, /* BS_PUSHBUTTON */
|
|---|
| 67 | PB_Paint, /* BS_DEFPUSHBUTTON */
|
|---|
| 68 | CB_Paint, /* BS_CHECKBOX */
|
|---|
| 69 | CB_Paint, /* BS_AUTOCHECKBOX */
|
|---|
| 70 | CB_Paint, /* BS_RADIOBUTTON */
|
|---|
| 71 | CB_Paint, /* BS_3STATE */
|
|---|
| 72 | CB_Paint, /* BS_AUTO3STATE */
|
|---|
| 73 | GB_Paint, /* BS_GROUPBOX */
|
|---|
| 74 | UB_Paint, /* BS_USERBUTTON */
|
|---|
| 75 | CB_Paint, /* BS_AUTORADIOBUTTON */
|
|---|
| 76 | NULL, /* Not defined */
|
|---|
| 77 | OB_Paint /* BS_OWNERDRAW */
|
|---|
| 78 | };
|
|---|
| 79 |
|
|---|
| 80 | #define PAINT_BUTTON(hwnd,style,action) \
|
|---|
| 81 | if (btnPaintFunc[style]) { \
|
|---|
| 82 | HDC hdc = GetDC(hwnd); \
|
|---|
| 83 | (btnPaintFunc[style])(hwnd,hdc,action); \
|
|---|
| 84 | ReleaseDC(hwnd,hdc); }
|
|---|
| 85 |
|
|---|
| 86 | #define BUTTON_SEND_CTLCOLOR(hwnd,hdc) \
|
|---|
| 87 | SendMessageA( GetParent(hwnd), WM_CTLCOLORBTN, \
|
|---|
| 88 | (hdc),hwnd)
|
|---|
| 89 |
|
|---|
| 90 | static HBITMAP hbitmapCheckBoxes = 0;
|
|---|
| 91 | static WORD checkBoxWidth = 0, checkBoxHeight = 0;
|
|---|
| 92 |
|
|---|
| 93 | static LRESULT BUTTON_SendNotify(HWND hwnd,DWORD code)
|
|---|
| 94 | {
|
|---|
| 95 | return SendMessageA(GetParent(hwnd),WM_COMMAND,MAKEWPARAM(GetWindowLongA(hwnd,GWL_ID),code),hwnd);
|
|---|
| 96 | }
|
|---|
| 97 |
|
|---|
| 98 | static LRESULT BUTTON_GetDlgCode(HWND hwnd,WPARAM wParam,LPARAM lParam)
|
|---|
| 99 | {
|
|---|
| 100 | DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
|
|---|
| 101 |
|
|---|
| 102 | switch (dwStyle & 0x0f)
|
|---|
| 103 | {
|
|---|
| 104 | case BS_AUTOCHECKBOX:
|
|---|
| 105 | case BS_CHECKBOX:
|
|---|
| 106 | return DLGC_WANTCHARS | DLGC_BUTTON;
|
|---|
| 107 |
|
|---|
| 108 | case BS_PUSHBUTTON:
|
|---|
| 109 | return DLGC_UNDEFPUSHBUTTON;
|
|---|
| 110 |
|
|---|
| 111 | case BS_DEFPUSHBUTTON:
|
|---|
| 112 | return DLGC_DEFPUSHBUTTON;
|
|---|
| 113 |
|
|---|
| 114 | case BS_AUTORADIOBUTTON:
|
|---|
| 115 | case BS_RADIOBUTTON:
|
|---|
| 116 | return DLGC_RADIOBUTTON;
|
|---|
| 117 |
|
|---|
| 118 | case BS_GROUPBOX:;
|
|---|
| 119 | return DLGC_STATIC;
|
|---|
| 120 |
|
|---|
| 121 | default:
|
|---|
| 122 | return DLGC_BUTTON;
|
|---|
| 123 | }
|
|---|
| 124 | }
|
|---|
| 125 |
|
|---|
| 126 | static LRESULT BUTTON_Enable(HWND hwnd,WPARAM wParam,LPARAM lParam)
|
|---|
| 127 | {
|
|---|
| 128 | DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
|
|---|
| 129 |
|
|---|
| 130 | if ((dwStyle & BS_NOTIFY) && !wParam) BUTTON_SendNotify(hwnd,BN_DISABLE);
|
|---|
| 131 |
|
|---|
| 132 | //PAINT_BUTTON(hwnd,dwStyle & 0x0f,ODA_DRAWENTIRE);
|
|---|
| 133 | //SvL: 09/10/99 Force it to redraw properly
|
|---|
| 134 | InvalidateRect( hwnd, NULL, FALSE );
|
|---|
| 135 |
|
|---|
| 136 | return 0;
|
|---|
| 137 | }
|
|---|
| 138 |
|
|---|
| 139 | static LRESULT BUTTON_Create(HWND hwnd,WPARAM wParam,LPARAM lParam)
|
|---|
| 140 | {
|
|---|
| 141 | BUTTONINFO* infoPtr;
|
|---|
| 142 | DWORD style = GetWindowLongA(hwnd,GWL_STYLE) & 0x0f;
|
|---|
| 143 |
|
|---|
| 144 | if (!hbitmapCheckBoxes)
|
|---|
| 145 | {
|
|---|
| 146 | BITMAP bmp;
|
|---|
| 147 |
|
|---|
| 148 | hbitmapCheckBoxes = LoadBitmapA(hInstanceUser32, MAKEINTRESOURCEA(OBM_CHECKBOXES));
|
|---|
| 149 | GetObjectA( hbitmapCheckBoxes, sizeof(bmp), &bmp );
|
|---|
| 150 | if (GetObjectA(hbitmapCheckBoxes,sizeof(bmp),&bmp))
|
|---|
| 151 | {
|
|---|
| 152 | checkBoxWidth = bmp.bmWidth / 4;
|
|---|
| 153 | checkBoxHeight = bmp.bmHeight / 3;
|
|---|
| 154 | } else checkBoxWidth = checkBoxHeight = 0;
|
|---|
| 155 | }
|
|---|
| 156 | if ((style < 0L) || (style >= MAX_BTN_TYPE)) return -1; /* abort */
|
|---|
| 157 |
|
|---|
| 158 | infoPtr = (BUTTONINFO*)malloc(sizeof(BUTTONINFO));
|
|---|
| 159 | infoPtr->state = BUTTON_UNCHECKED;
|
|---|
| 160 | infoPtr->hFont = 0;
|
|---|
| 161 | infoPtr->hImage = 0;
|
|---|
| 162 | SetInfoPtr(hwnd,(DWORD)infoPtr);
|
|---|
| 163 |
|
|---|
| 164 | return 0;
|
|---|
| 165 | }
|
|---|
| 166 |
|
|---|
| 167 | static LRESULT BUTTON_Destroy(HWND hwnd,WPARAM wParam,LPARAM lParam)
|
|---|
| 168 | {
|
|---|
| 169 | BUTTONINFO* infoPtr = (BUTTONINFO*)GetInfoPtr(hwnd);
|
|---|
| 170 |
|
|---|
| 171 | free(infoPtr);
|
|---|
| 172 |
|
|---|
| 173 | return 0;
|
|---|
| 174 | }
|
|---|
| 175 |
|
|---|
| 176 | static LRESULT BUTTON_EraseBkgnd(HWND hwnd,WPARAM wParam,LPARAM lParam)
|
|---|
| 177 | {
|
|---|
| 178 | //SvL: This is wrong: should be
|
|---|
| 179 | //SvL: TODO: NT does something extra for ownerdrawn buttons; check this
|
|---|
| 180 | // if(style == BS_OWNERDRAW) {
|
|---|
| 181 | // return DefWindowProcA(hwnd, WM_ERASEBKGND, wParam, lParam);
|
|---|
| 182 | // }
|
|---|
| 183 | // return 1;
|
|---|
| 184 |
|
|---|
| 185 | //SvL: Erase background for groupboxes as the paint function only draws
|
|---|
| 186 | // a box
|
|---|
| 187 | DWORD style = GetWindowLongA(hwnd,GWL_STYLE) & 0x0f;
|
|---|
| 188 | // if(style == BS_GROUPBOX) {
|
|---|
| 189 | return DefWindowProcA(hwnd, WM_ERASEBKGND, wParam, lParam);
|
|---|
| 190 | // }
|
|---|
| 191 | // return 1;
|
|---|
| 192 | }
|
|---|
| 193 |
|
|---|
| 194 | static LRESULT BUTTON_Paint(HWND hwnd,WPARAM wParam,LPARAM lParam)
|
|---|
| 195 | {
|
|---|
| 196 | DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
|
|---|
| 197 | DWORD style = dwStyle & 0x0f;
|
|---|
| 198 |
|
|---|
| 199 | if (dwStyle & BS_NOTIFY) BUTTON_SendNotify(hwnd,BN_PAINT);
|
|---|
| 200 |
|
|---|
| 201 | if (btnPaintFunc[style])
|
|---|
| 202 | {
|
|---|
| 203 | PAINTSTRUCT ps;
|
|---|
| 204 |
|
|---|
| 205 | HDC hdc = wParam ? (HDC)wParam : BeginPaint(hwnd,&ps);
|
|---|
| 206 | SetBkMode(hdc,OPAQUE);
|
|---|
| 207 | (btnPaintFunc[style])(hwnd,hdc,ODA_DRAWENTIRE);
|
|---|
| 208 | if(!wParam) EndPaint(hwnd,&ps);
|
|---|
| 209 | } else return DefWindowProcA(hwnd,WM_PAINT,wParam,lParam);
|
|---|
| 210 |
|
|---|
| 211 | return 0;
|
|---|
| 212 | }
|
|---|
| 213 |
|
|---|
| 214 | static LRESULT BUTTON_LButtonDblClk(HWND hwnd,WPARAM wParam,LPARAM lParam)
|
|---|
| 215 | {
|
|---|
| 216 | DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
|
|---|
| 217 | DWORD style = dwStyle & 0x0f;
|
|---|
| 218 |
|
|---|
| 219 | if(dwStyle & BS_NOTIFY || style == BS_RADIOBUTTON ||
|
|---|
| 220 | style == BS_USERBUTTON || style == BS_OWNERDRAW)
|
|---|
| 221 | BUTTON_SendNotify(hwnd,BN_DOUBLECLICKED);
|
|---|
| 222 | else BUTTON_LButtonDown(hwnd,wParam,lParam);
|
|---|
| 223 |
|
|---|
| 224 | return 0;
|
|---|
| 225 | }
|
|---|
| 226 |
|
|---|
| 227 | static LRESULT BUTTON_LButtonDown(HWND hwnd,WPARAM wParam,LPARAM lParam)
|
|---|
| 228 | {
|
|---|
| 229 | BUTTONINFO* infoPtr = (BUTTONINFO*)GetInfoPtr(hwnd);
|
|---|
| 230 | DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
|
|---|
| 231 | DWORD style = dwStyle & 0x0F;
|
|---|
| 232 |
|
|---|
| 233 | if (style == BS_GROUPBOX) return 0;
|
|---|
| 234 | SetCapture(hwnd);
|
|---|
| 235 | SetFocus(hwnd);
|
|---|
| 236 | SendMessageA(hwnd,BM_SETSTATE,TRUE,0);
|
|---|
| 237 | infoPtr->state |= BUTTON_BTNPRESSED;
|
|---|
| 238 |
|
|---|
| 239 | if (dwStyle & BS_NOTIFY) BUTTON_SendNotify(hwnd,BN_HILITE);
|
|---|
| 240 |
|
|---|
| 241 | return 0;
|
|---|
| 242 | }
|
|---|
| 243 |
|
|---|
| 244 | static LRESULT BUTTON_LButtonUp(HWND hwnd,WPARAM wParam,LPARAM lParam)
|
|---|
| 245 | {
|
|---|
| 246 | BUTTONINFO* infoPtr = (BUTTONINFO*)GetInfoPtr(hwnd);
|
|---|
| 247 | DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
|
|---|
| 248 | DWORD style = dwStyle & 0x0F;
|
|---|
| 249 | RECT rect;
|
|---|
| 250 | POINT pt;
|
|---|
| 251 |
|
|---|
| 252 | pt.x = LOWORD(lParam);
|
|---|
| 253 | pt.y = HIWORD(lParam);
|
|---|
| 254 |
|
|---|
| 255 | if (!(infoPtr->state & BUTTON_BTNPRESSED)) return 0;
|
|---|
| 256 | infoPtr->state &= BUTTON_NSTATES;
|
|---|
| 257 | if (!(infoPtr->state & BUTTON_HIGHLIGHTED))
|
|---|
| 258 | {
|
|---|
| 259 | ReleaseCapture();
|
|---|
| 260 | return 0;
|
|---|
| 261 | }
|
|---|
| 262 | SendMessageA(hwnd,BM_SETSTATE,FALSE,0);
|
|---|
| 263 | ReleaseCapture();
|
|---|
| 264 | GetClientRect(hwnd,&rect);
|
|---|
| 265 | if (PtInRect(&rect,pt))
|
|---|
| 266 | {
|
|---|
| 267 | switch(dwStyle & 0x0f)
|
|---|
| 268 | {
|
|---|
| 269 | case BS_AUTOCHECKBOX:
|
|---|
| 270 | SendMessageA(hwnd,BM_SETCHECK,!(infoPtr->state & BUTTON_CHECKED),0);
|
|---|
| 271 | break;
|
|---|
| 272 | case BS_AUTORADIOBUTTON:
|
|---|
| 273 | SendMessageA(hwnd,BM_SETCHECK,TRUE,0);
|
|---|
| 274 | break;
|
|---|
| 275 | case BS_AUTO3STATE:
|
|---|
| 276 | SendMessageA(hwnd,BM_SETCHECK,
|
|---|
| 277 | (infoPtr->state & BUTTON_3STATE) ? 0 :
|
|---|
| 278 | ((infoPtr->state & 3)+1),0);
|
|---|
| 279 | break;
|
|---|
| 280 | }
|
|---|
| 281 | BUTTON_SendNotify(hwnd,BN_CLICKED);
|
|---|
| 282 | }
|
|---|
| 283 |
|
|---|
| 284 | if (dwStyle & BS_NOTIFY) BUTTON_SendNotify(hwnd,BN_UNHILITE);
|
|---|
| 285 |
|
|---|
| 286 | return 0;
|
|---|
| 287 | }
|
|---|
| 288 |
|
|---|
| 289 | static LRESULT BUTTON_CaptureChanged(HWND hwnd,WPARAM wParam,LPARAM lParam)
|
|---|
| 290 | {
|
|---|
| 291 | BUTTONINFO* infoPtr = (BUTTONINFO*)GetInfoPtr(hwnd);
|
|---|
| 292 | DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
|
|---|
| 293 |
|
|---|
| 294 | if (infoPtr->state & BUTTON_BTNPRESSED)
|
|---|
| 295 | {
|
|---|
| 296 | infoPtr->state &= BUTTON_NSTATES;
|
|---|
| 297 | if (infoPtr->state & BUTTON_HIGHLIGHTED)
|
|---|
| 298 | SendMessageA( hwnd, BM_SETSTATE, FALSE, 0 );
|
|---|
| 299 | }
|
|---|
| 300 |
|
|---|
| 301 | if (dwStyle & BS_NOTIFY) BUTTON_SendNotify(hwnd,BN_UNHILITE);
|
|---|
| 302 |
|
|---|
| 303 | return 0;
|
|---|
| 304 | }
|
|---|
| 305 |
|
|---|
| 306 | static LRESULT BUTTON_MouseMove(HWND hwnd,WPARAM wParam,LPARAM lParam)
|
|---|
| 307 | {
|
|---|
| 308 | if (GetCapture() == hwnd)
|
|---|
| 309 | {
|
|---|
| 310 | RECT rect;
|
|---|
| 311 | POINT pt;
|
|---|
| 312 |
|
|---|
| 313 | pt.x = LOWORD(lParam);
|
|---|
| 314 | pt.y = HIWORD(lParam);
|
|---|
| 315 |
|
|---|
| 316 | GetClientRect(hwnd,&rect);
|
|---|
| 317 | SendMessageA(hwnd,BM_SETSTATE,PtInRect(&rect,pt),0);
|
|---|
| 318 | }
|
|---|
| 319 |
|
|---|
| 320 | return 0;
|
|---|
| 321 | }
|
|---|
| 322 |
|
|---|
| 323 | static LRESULT BUTTON_NCHitTest(HWND hwnd,WPARAM wParam,LPARAM lParam)
|
|---|
| 324 | {
|
|---|
| 325 | DWORD style = GetWindowLongA(hwnd,GWL_STYLE) & 0x0f;
|
|---|
| 326 |
|
|---|
| 327 | //if (style == BS_GROUPBOX) return HTTRANSPARENT;
|
|---|
| 328 |
|
|---|
| 329 | return DefWindowProcA(hwnd,WM_NCHITTEST,wParam,lParam);
|
|---|
| 330 | }
|
|---|
| 331 |
|
|---|
| 332 | static LRESULT BUTTON_SetText(HWND hwnd,WPARAM wParam,LPARAM lParam)
|
|---|
| 333 | {
|
|---|
| 334 | DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
|
|---|
| 335 |
|
|---|
| 336 | DefWindowProcA(hwnd,WM_SETTEXT,wParam,lParam);
|
|---|
| 337 | if (dwStyle & WS_VISIBLE) PAINT_BUTTON(hwnd,dwStyle & 0x0f,ODA_DRAWENTIRE);
|
|---|
| 338 |
|
|---|
| 339 | return 0;
|
|---|
| 340 | }
|
|---|
| 341 |
|
|---|
| 342 | static LRESULT BUTTON_SetFont(HWND hwnd,WPARAM wParam,LPARAM lParam)
|
|---|
| 343 | {
|
|---|
| 344 | BUTTONINFO* infoPtr = (BUTTONINFO*)GetInfoPtr(hwnd);
|
|---|
| 345 | DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
|
|---|
| 346 |
|
|---|
| 347 | infoPtr->hFont = (HFONT)wParam;
|
|---|
| 348 | if (lParam && (dwStyle & WS_VISIBLE)) PAINT_BUTTON(hwnd,dwStyle & 0x0f,ODA_DRAWENTIRE);
|
|---|
| 349 |
|
|---|
| 350 | return 0;
|
|---|
| 351 | }
|
|---|
| 352 |
|
|---|
| 353 | static LRESULT BUTTON_GetFont(HWND hwnd,WPARAM wParam,LPARAM lParam)
|
|---|
| 354 | {
|
|---|
| 355 | BUTTONINFO* infoPtr = (BUTTONINFO*)GetInfoPtr(hwnd);
|
|---|
| 356 |
|
|---|
| 357 | return infoPtr->hFont;
|
|---|
| 358 | }
|
|---|
| 359 |
|
|---|
| 360 | static LRESULT BUTTON_KeyDown(HWND hwnd,WPARAM wParam,LPARAM lParam)
|
|---|
| 361 | {
|
|---|
| 362 | if (wParam == VK_SPACE)
|
|---|
| 363 | {
|
|---|
| 364 | BUTTONINFO* infoPtr = (BUTTONINFO*)GetInfoPtr(hwnd);
|
|---|
| 365 |
|
|---|
| 366 | SendMessageA(hwnd,BM_SETSTATE,TRUE,0);
|
|---|
| 367 | infoPtr->state |= BUTTON_BTNPRESSED;
|
|---|
| 368 | }
|
|---|
| 369 |
|
|---|
| 370 | return 0;
|
|---|
| 371 | }
|
|---|
| 372 |
|
|---|
| 373 | static LRESULT BUTTON_KeyUp(HWND hwnd,WPARAM wParam,LPARAM lParam)
|
|---|
| 374 | {
|
|---|
| 375 | if (wParam == VK_SPACE)
|
|---|
| 376 | {
|
|---|
| 377 | BUTTONINFO* infoPtr = (BUTTONINFO*)GetInfoPtr(hwnd);
|
|---|
| 378 | DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
|
|---|
| 379 |
|
|---|
| 380 | if (!(infoPtr->state & BUTTON_BTNPRESSED)) return 0;
|
|---|
| 381 | infoPtr->state &= BUTTON_NSTATES;
|
|---|
| 382 | if (!(infoPtr->state & BUTTON_HIGHLIGHTED)) return 0;
|
|---|
| 383 | SendMessageA(hwnd,BM_SETSTATE,FALSE,0);
|
|---|
| 384 |
|
|---|
| 385 | switch(dwStyle & 0x0f)
|
|---|
| 386 | {
|
|---|
| 387 | case BS_AUTOCHECKBOX:
|
|---|
| 388 | SendMessageA(hwnd,BM_SETCHECK,!(infoPtr->state & BUTTON_CHECKED),0);
|
|---|
| 389 | break;
|
|---|
| 390 | case BS_AUTORADIOBUTTON:
|
|---|
| 391 | SendMessageA(hwnd,BM_SETCHECK,TRUE,0);
|
|---|
| 392 | break;
|
|---|
| 393 | case BS_AUTO3STATE:
|
|---|
| 394 | SendMessageA(hwnd,BM_SETCHECK,
|
|---|
| 395 | (infoPtr->state & BUTTON_3STATE) ? 0 :
|
|---|
| 396 | ((infoPtr->state & 3)+1),0);
|
|---|
| 397 | break;
|
|---|
| 398 | }
|
|---|
| 399 | BUTTON_SendNotify(hwnd,BN_CLICKED);
|
|---|
| 400 | }
|
|---|
| 401 |
|
|---|
| 402 | return 0;
|
|---|
| 403 | }
|
|---|
| 404 |
|
|---|
| 405 | static LRESULT BUTTON_SysKeyUp(HWND hwnd,WPARAM wParam,LPARAM lParam)
|
|---|
| 406 | {
|
|---|
| 407 | if (wParam != VK_TAB) ReleaseCapture();
|
|---|
| 408 |
|
|---|
| 409 | return 0;
|
|---|
| 410 | }
|
|---|
| 411 |
|
|---|
| 412 | static LRESULT BUTTON_SetFocus(HWND hwnd,WPARAM wParam,LPARAM lParam)
|
|---|
| 413 | {
|
|---|
| 414 | BUTTONINFO* infoPtr = (BUTTONINFO*)GetInfoPtr(hwnd);
|
|---|
| 415 | DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
|
|---|
| 416 | DWORD style = dwStyle & 0x0f;
|
|---|
| 417 |
|
|---|
| 418 | if (dwStyle & BS_NOTIFY) BUTTON_SendNotify(hwnd,BN_SETFOCUS);
|
|---|
| 419 |
|
|---|
| 420 | if (((style == BS_AUTORADIOBUTTON) || (style == BS_RADIOBUTTON)) &&
|
|---|
| 421 | (GetCapture() != hwnd) && !(SendMessageA(hwnd,BM_GETCHECK,0,0) & BST_CHECKED))
|
|---|
| 422 | {
|
|---|
| 423 | /* The notification is sent when the button (BS_AUTORADIOBUTTON)
|
|---|
| 424 | is unckecked and the focus was not given by a mouse click. */
|
|---|
| 425 | if (style == BS_AUTORADIOBUTTON) SendMessageA(hwnd,BM_SETCHECK,TRUE,0);
|
|---|
| 426 | BUTTON_SendNotify(hwnd,BN_CLICKED);
|
|---|
| 427 | }
|
|---|
| 428 |
|
|---|
| 429 | infoPtr->state |= BUTTON_HASFOCUS;
|
|---|
| 430 | PAINT_BUTTON(hwnd,style,ODA_FOCUS);
|
|---|
| 431 |
|
|---|
| 432 | return 0;
|
|---|
| 433 | }
|
|---|
| 434 |
|
|---|
| 435 | static LRESULT BUTTON_KillFocus(HWND hwnd,WPARAM wParam,LPARAM lParam)
|
|---|
| 436 | {
|
|---|
| 437 | BUTTONINFO* infoPtr = (BUTTONINFO*)GetInfoPtr(hwnd);
|
|---|
| 438 | DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
|
|---|
| 439 | DWORD style = dwStyle & 0x0f;
|
|---|
| 440 |
|
|---|
| 441 | if (dwStyle & BS_NOTIFY) BUTTON_SendNotify(hwnd,BN_KILLFOCUS);
|
|---|
| 442 |
|
|---|
| 443 | if (infoPtr->state & BUTTON_HASFOCUS)
|
|---|
| 444 | {
|
|---|
| 445 | infoPtr->state &= ~BUTTON_HASFOCUS;
|
|---|
| 446 | PAINT_BUTTON(hwnd,style,ODA_FOCUS);
|
|---|
| 447 | }
|
|---|
| 448 |
|
|---|
| 449 | return 0;
|
|---|
| 450 | }
|
|---|
| 451 |
|
|---|
| 452 | static LRESULT BUTTON_SysColorChange(HWND hwnd,WPARAM wParam,LPARAM lParam)
|
|---|
| 453 | {
|
|---|
| 454 | InvalidateRect(hwnd,NULL,FALSE);
|
|---|
| 455 |
|
|---|
| 456 | return 0;
|
|---|
| 457 | }
|
|---|
| 458 |
|
|---|
| 459 | static LRESULT BUTTON_Click(HWND hwnd,WPARAM wParam,LPARAM lParam)
|
|---|
| 460 | {
|
|---|
| 461 | RECT rect;
|
|---|
| 462 | LPARAM point;
|
|---|
| 463 |
|
|---|
| 464 | GetClientRect(hwnd,&rect);
|
|---|
| 465 | point = MAKELPARAM(rect.right/2,rect.bottom/2);
|
|---|
| 466 | SendMessageA(hwnd,WM_LBUTTONDOWN,MK_LBUTTON,point);
|
|---|
| 467 | Sleep(100);
|
|---|
| 468 | SendMessageA(hwnd,WM_LBUTTONUP,0,point);
|
|---|
| 469 |
|
|---|
| 470 | return 0;
|
|---|
| 471 | }
|
|---|
| 472 |
|
|---|
| 473 | static LRESULT BUTTON_SetStyle(HWND hwnd,WPARAM wParam,LPARAM lParam)
|
|---|
| 474 | {
|
|---|
| 475 | DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE),newStyle;
|
|---|
| 476 |
|
|---|
| 477 | if ((wParam & 0x0F) >= MAX_BTN_TYPE) return 0;
|
|---|
| 478 | newStyle = (dwStyle & 0xFFFFFFF0) | (wParam & 0x0000000F);
|
|---|
| 479 |
|
|---|
| 480 | if (newStyle != dwStyle)
|
|---|
| 481 | {
|
|---|
| 482 | SetWindowLongA(hwnd,GWL_STYLE,newStyle);
|
|---|
| 483 | PAINT_BUTTON(hwnd,newStyle & 0x0F,ODA_DRAWENTIRE);
|
|---|
| 484 | }
|
|---|
| 485 |
|
|---|
| 486 | return 0;
|
|---|
| 487 | }
|
|---|
| 488 |
|
|---|
| 489 | static LRESULT BUTTON_SetImage(HWND hwnd,WPARAM wParam,LPARAM lParam)
|
|---|
| 490 | {
|
|---|
| 491 | BUTTONINFO* infoPtr = (BUTTONINFO*)GetInfoPtr(hwnd);
|
|---|
| 492 | DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
|
|---|
| 493 | HANDLE oldHbitmap = infoPtr->hImage;
|
|---|
| 494 |
|
|---|
| 495 | if ((dwStyle & BS_BITMAP) || (dwStyle & BS_ICON))
|
|---|
| 496 | {
|
|---|
| 497 | infoPtr->hImage = (HANDLE)lParam;
|
|---|
| 498 | InvalidateRect(hwnd,NULL,FALSE);
|
|---|
| 499 | }
|
|---|
| 500 |
|
|---|
| 501 | return oldHbitmap;
|
|---|
| 502 | }
|
|---|
| 503 |
|
|---|
| 504 | static LRESULT BUTTON_GetImage(HWND hwnd,WPARAM wParam,LPARAM lParam)
|
|---|
| 505 | {
|
|---|
| 506 | BUTTONINFO* infoPtr = (BUTTONINFO*)GetInfoPtr(hwnd);
|
|---|
| 507 |
|
|---|
| 508 | switch(wParam)
|
|---|
| 509 | {
|
|---|
| 510 | case IMAGE_BITMAP:
|
|---|
| 511 | return (HBITMAP)infoPtr->hImage;
|
|---|
| 512 | case IMAGE_ICON:
|
|---|
| 513 | return (HICON)infoPtr->hImage;
|
|---|
| 514 | default:
|
|---|
| 515 | return (HICON)0;
|
|---|
| 516 | }
|
|---|
| 517 | }
|
|---|
| 518 |
|
|---|
| 519 | static LRESULT BUTTON_GetCheck(HWND hwnd,WPARAM wParam,LPARAM lParam)
|
|---|
| 520 | {
|
|---|
| 521 | BUTTONINFO* infoPtr = (BUTTONINFO*)GetInfoPtr(hwnd);
|
|---|
| 522 |
|
|---|
| 523 | return infoPtr->state & 3;
|
|---|
| 524 | }
|
|---|
| 525 |
|
|---|
| 526 | static LRESULT BUTTON_SetCheck(HWND hwnd,WPARAM wParam,LPARAM lParam)
|
|---|
| 527 | {
|
|---|
| 528 | BUTTONINFO* infoPtr = (BUTTONINFO*)GetInfoPtr(hwnd);
|
|---|
| 529 | DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
|
|---|
| 530 | DWORD style = dwStyle & 0x0f;
|
|---|
| 531 |
|
|---|
| 532 | if (wParam > maxCheckState[style]) wParam = maxCheckState[style];
|
|---|
| 533 | if ((infoPtr->state & 3) != wParam)
|
|---|
| 534 | {
|
|---|
| 535 | if ((style == BS_RADIOBUTTON) || (style == BS_AUTORADIOBUTTON))
|
|---|
| 536 | {
|
|---|
| 537 | DWORD oldStyle = dwStyle;
|
|---|
| 538 |
|
|---|
| 539 | if (wParam)
|
|---|
| 540 | dwStyle |= WS_TABSTOP;
|
|---|
| 541 | else
|
|---|
| 542 | dwStyle &= ~WS_TABSTOP;
|
|---|
| 543 |
|
|---|
| 544 | if (oldStyle != dwStyle) SetWindowLongA(hwnd,GWL_STYLE,dwStyle);
|
|---|
| 545 | }
|
|---|
| 546 | infoPtr->state = (infoPtr->state & ~3) | wParam;
|
|---|
| 547 | PAINT_BUTTON(hwnd,style,ODA_SELECT);
|
|---|
| 548 | }
|
|---|
| 549 | if ((style == BS_AUTORADIOBUTTON) && (wParam == BUTTON_CHECKED))
|
|---|
| 550 | BUTTON_CheckAutoRadioButton(hwnd);
|
|---|
| 551 |
|
|---|
| 552 | return 0;
|
|---|
| 553 | }
|
|---|
| 554 |
|
|---|
| 555 | static LRESULT BUTTON_GetState(HWND hwnd,WPARAM wParam,LPARAM lParam)
|
|---|
| 556 | {
|
|---|
| 557 | BUTTONINFO* infoPtr = (BUTTONINFO*)GetInfoPtr(hwnd);
|
|---|
| 558 |
|
|---|
| 559 | return infoPtr->state;
|
|---|
| 560 | }
|
|---|
| 561 |
|
|---|
| 562 | static LRESULT BUTTON_SetState(HWND hwnd,WPARAM wParam,LPARAM lParam)
|
|---|
| 563 | {
|
|---|
| 564 | BUTTONINFO* infoPtr = (BUTTONINFO*)GetInfoPtr(hwnd);
|
|---|
| 565 | DWORD style = GetWindowLongA(hwnd,GWL_STYLE) & 0x0F;
|
|---|
| 566 |
|
|---|
| 567 | if (wParam)
|
|---|
| 568 | {
|
|---|
| 569 | if (infoPtr->state & BUTTON_HIGHLIGHTED) return 0;
|
|---|
| 570 | infoPtr->state |= BUTTON_HIGHLIGHTED;
|
|---|
| 571 | } else
|
|---|
| 572 | {
|
|---|
| 573 | if (!(infoPtr->state & BUTTON_HIGHLIGHTED)) return 0;
|
|---|
| 574 | infoPtr->state &= ~BUTTON_HIGHLIGHTED;
|
|---|
| 575 | }
|
|---|
| 576 | PAINT_BUTTON(hwnd,style,ODA_SELECT);
|
|---|
| 577 |
|
|---|
| 578 | return 0;
|
|---|
| 579 | }
|
|---|
| 580 |
|
|---|
| 581 | /***********************************************************************
|
|---|
| 582 | * ButtonWndProc
|
|---|
| 583 | */
|
|---|
| 584 | static
|
|---|
| 585 | LRESULT WINAPI ButtonWndProc(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam)
|
|---|
| 586 | {
|
|---|
| 587 | // dprintf(("ButtonWndProc hwnd: %04x, msg %s, wp %08x lp %08lx\n",
|
|---|
| 588 | // hwnd, GetMsgText(uMsg), wParam, lParam));
|
|---|
| 589 |
|
|---|
| 590 | switch (uMsg)
|
|---|
| 591 | {
|
|---|
| 592 | case WM_GETDLGCODE:
|
|---|
| 593 | return BUTTON_GetDlgCode(hwnd,wParam,lParam);
|
|---|
| 594 |
|
|---|
| 595 | case WM_ENABLE:
|
|---|
| 596 | return BUTTON_Enable(hwnd,wParam,lParam);
|
|---|
| 597 |
|
|---|
| 598 | case WM_CREATE:
|
|---|
| 599 | return BUTTON_Create(hwnd,wParam,lParam);
|
|---|
| 600 |
|
|---|
| 601 | case WM_DESTROY:
|
|---|
| 602 | return BUTTON_Destroy(hwnd,wParam,lParam);
|
|---|
| 603 |
|
|---|
| 604 | case WM_ERASEBKGND:
|
|---|
| 605 | return BUTTON_EraseBkgnd(hwnd,wParam,lParam);
|
|---|
| 606 |
|
|---|
| 607 | case WM_PAINT:
|
|---|
| 608 | return BUTTON_Paint(hwnd,wParam,lParam);
|
|---|
| 609 |
|
|---|
| 610 | case WM_LBUTTONDBLCLK:
|
|---|
| 611 | return BUTTON_LButtonDblClk(hwnd,wParam,lParam);
|
|---|
| 612 |
|
|---|
| 613 | case WM_LBUTTONDOWN:
|
|---|
| 614 | return BUTTON_LButtonDown(hwnd,wParam,lParam);
|
|---|
| 615 |
|
|---|
| 616 | case WM_LBUTTONUP:
|
|---|
| 617 | return BUTTON_LButtonUp(hwnd,wParam,lParam);
|
|---|
| 618 |
|
|---|
| 619 | case WM_CAPTURECHANGED:
|
|---|
| 620 | return BUTTON_CaptureChanged(hwnd,wParam,lParam);
|
|---|
| 621 |
|
|---|
| 622 | case WM_MOUSEMOVE:
|
|---|
| 623 | return BUTTON_MouseMove(hwnd,wParam,lParam);
|
|---|
| 624 |
|
|---|
| 625 | case WM_NCHITTEST:
|
|---|
| 626 | return BUTTON_NCHitTest(hwnd,wParam,lParam);
|
|---|
| 627 |
|
|---|
| 628 | case WM_SETTEXT:
|
|---|
| 629 | return BUTTON_SetText(hwnd,wParam,lParam);
|
|---|
| 630 |
|
|---|
| 631 | case WM_SETFONT:
|
|---|
| 632 | return BUTTON_SetFont(hwnd,wParam,lParam);
|
|---|
| 633 |
|
|---|
| 634 | case WM_GETFONT:
|
|---|
| 635 | return BUTTON_GetFont(hwnd,wParam,lParam);
|
|---|
| 636 |
|
|---|
| 637 | case WM_KEYDOWN:
|
|---|
| 638 | return BUTTON_KeyDown(hwnd,wParam,lParam);
|
|---|
| 639 |
|
|---|
| 640 | case WM_KEYUP:
|
|---|
| 641 | return BUTTON_KeyUp(hwnd,wParam,lParam);
|
|---|
| 642 |
|
|---|
| 643 | case WM_SYSKEYUP:
|
|---|
| 644 | return BUTTON_SysKeyUp(hwnd,wParam,lParam);
|
|---|
| 645 |
|
|---|
| 646 | case WM_SETFOCUS:
|
|---|
| 647 | return BUTTON_SetFocus(hwnd,wParam,lParam);
|
|---|
| 648 |
|
|---|
| 649 | case WM_KILLFOCUS:
|
|---|
| 650 | return BUTTON_KillFocus(hwnd,wParam,lParam);
|
|---|
| 651 |
|
|---|
| 652 | case WM_SYSCOLORCHANGE:
|
|---|
| 653 | return BUTTON_SysColorChange(hwnd,wParam,lParam);
|
|---|
| 654 |
|
|---|
| 655 | case BM_CLICK:
|
|---|
| 656 | return BUTTON_Click(hwnd,wParam,lParam);
|
|---|
| 657 |
|
|---|
| 658 | case BM_SETSTYLE:
|
|---|
| 659 | return BUTTON_SetStyle(hwnd,wParam,lParam);
|
|---|
| 660 |
|
|---|
| 661 | case BM_SETIMAGE:
|
|---|
| 662 | return BUTTON_SetImage(hwnd,wParam,lParam);
|
|---|
| 663 |
|
|---|
| 664 | case BM_GETIMAGE:
|
|---|
| 665 | return BUTTON_GetImage(hwnd,wParam,lParam);
|
|---|
| 666 |
|
|---|
| 667 | case BM_GETCHECK:
|
|---|
| 668 | return BUTTON_GetCheck(hwnd,wParam,lParam);
|
|---|
| 669 |
|
|---|
| 670 | case BM_SETCHECK:
|
|---|
| 671 | return BUTTON_SetCheck(hwnd,wParam,lParam);
|
|---|
| 672 |
|
|---|
| 673 | case BM_GETSTATE:
|
|---|
| 674 | return BUTTON_GetState(hwnd,wParam,lParam);
|
|---|
| 675 |
|
|---|
| 676 | case BM_SETSTATE:
|
|---|
| 677 | return BUTTON_SetState(hwnd,wParam,lParam);
|
|---|
| 678 |
|
|---|
| 679 | default:
|
|---|
| 680 | return DefWindowProcA(hwnd,uMsg,wParam,lParam);
|
|---|
| 681 | }
|
|---|
| 682 |
|
|---|
| 683 | return 0;
|
|---|
| 684 | }
|
|---|
| 685 |
|
|---|
| 686 |
|
|---|
| 687 | /**********************************************************************
|
|---|
| 688 | * Push Button Functions
|
|---|
| 689 | */
|
|---|
| 690 | static void PB_Paint( HWND hwnd, HDC hDC, WORD action )
|
|---|
| 691 | {
|
|---|
| 692 | BUTTONINFO *infoPtr = (BUTTONINFO *)GetInfoPtr(hwnd);
|
|---|
| 693 | BOOL bHighLighted = (infoPtr->state & BUTTON_HIGHLIGHTED);
|
|---|
| 694 |
|
|---|
| 695 | /*
|
|---|
| 696 | * Delegate this to the more generic pushbutton painting
|
|---|
| 697 | * method.
|
|---|
| 698 | */
|
|---|
| 699 | BUTTON_DrawPushButton(hwnd,
|
|---|
| 700 | hDC,
|
|---|
| 701 | action,
|
|---|
| 702 | bHighLighted);
|
|---|
| 703 | }
|
|---|
| 704 |
|
|---|
| 705 | static INT BUTTON_GetTextFormat(DWORD dwStyle,DWORD dwExStyle,INT defHorz,INT defVert)
|
|---|
| 706 | {
|
|---|
| 707 | INT format = 0;
|
|---|
| 708 |
|
|---|
| 709 | if (dwStyle & BS_LEFT) format = DT_LEFT;
|
|---|
| 710 | else if (dwStyle & BS_CENTER) format = DT_CENTER;
|
|---|
| 711 | else if ((dwStyle & BS_RIGHT) || (dwExStyle & WS_EX_RIGHT)) format = DT_RIGHT;
|
|---|
| 712 | else format = defHorz;
|
|---|
| 713 |
|
|---|
| 714 | if (dwStyle & BS_TOP) format |= DT_TOP;
|
|---|
| 715 | else if (dwStyle & BS_VCENTER) format |= DT_VCENTER;
|
|---|
| 716 | else if (dwStyle & BS_BOTTOM) format |= DT_BOTTOM;
|
|---|
| 717 | else format |= defVert;
|
|---|
| 718 |
|
|---|
| 719 | if (!(dwStyle & BS_MULTILINE)) format |= DT_SINGLELINE;
|
|---|
| 720 |
|
|---|
| 721 | return format;
|
|---|
| 722 | }
|
|---|
| 723 |
|
|---|
| 724 | /**********************************************************************
|
|---|
| 725 | * This method will actually do the drawing of the pushbutton
|
|---|
| 726 | * depending on it's state and the pushedState parameter.
|
|---|
| 727 | */
|
|---|
| 728 | static void BUTTON_DrawPushButton(
|
|---|
| 729 | HWND hwnd,
|
|---|
| 730 | HDC hDC,
|
|---|
| 731 | WORD action,
|
|---|
| 732 | BOOL pushedState )
|
|---|
| 733 | {
|
|---|
| 734 | RECT rc, focus_rect;
|
|---|
| 735 | HPEN hOldPen;
|
|---|
| 736 | HBRUSH hOldBrush;
|
|---|
| 737 | BUTTONINFO *infoPtr = (BUTTONINFO *)GetInfoPtr(hwnd);
|
|---|
| 738 | DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
|
|---|
| 739 | int xBorderOffset, yBorderOffset;
|
|---|
| 740 | xBorderOffset = yBorderOffset = 0;
|
|---|
| 741 | INT textLen;
|
|---|
| 742 | char* text;
|
|---|
| 743 |
|
|---|
| 744 | GetClientRect( hwnd, &rc );
|
|---|
| 745 |
|
|---|
| 746 | /* Send WM_CTLCOLOR to allow changing the font (the colors are fixed) */
|
|---|
| 747 | if (infoPtr->hFont) SelectObject( hDC, infoPtr->hFont );
|
|---|
| 748 | BUTTON_SEND_CTLCOLOR( hwnd, hDC );
|
|---|
| 749 | hOldPen = (HPEN)SelectObject(hDC, GetSysColorPen(COLOR_WINDOWFRAME));
|
|---|
| 750 | hOldBrush =(HBRUSH)SelectObject(hDC,GetSysColorBrush(COLOR_BTNFACE));
|
|---|
| 751 | SetBkMode(hDC, TRANSPARENT);
|
|---|
| 752 |
|
|---|
| 753 | if ((dwStyle & 0x000f) == BS_DEFPUSHBUTTON)
|
|---|
| 754 | {
|
|---|
| 755 | Rectangle(hDC, rc.left, rc.top, rc.right, rc.bottom);
|
|---|
| 756 | InflateRect( &rc, -1, -1 );
|
|---|
| 757 | }
|
|---|
| 758 |
|
|---|
| 759 | UINT uState = DFCS_BUTTONPUSH;
|
|---|
| 760 |
|
|---|
| 761 | if (pushedState)
|
|---|
| 762 | {
|
|---|
| 763 | if ( (dwStyle & 0x000f) == BS_DEFPUSHBUTTON )
|
|---|
| 764 | uState |= DFCS_FLAT;
|
|---|
| 765 | else
|
|---|
| 766 | uState |= DFCS_PUSHED;
|
|---|
| 767 | }
|
|---|
| 768 |
|
|---|
| 769 | if (dwStyle & BS_FLAT) uState |= DFCS_FLAT;
|
|---|
| 770 |
|
|---|
| 771 | DrawFrameControl( hDC, &rc, DFC_BUTTON, uState );
|
|---|
| 772 | InflateRect( &rc, -2, -2 );
|
|---|
| 773 |
|
|---|
| 774 | focus_rect = rc;
|
|---|
| 775 |
|
|---|
| 776 | if (pushedState)
|
|---|
| 777 | {
|
|---|
| 778 | rc.left += 2; /* To position the text down and right */
|
|---|
| 779 | rc.top += 2;
|
|---|
| 780 | }
|
|---|
| 781 |
|
|---|
| 782 |
|
|---|
| 783 | /* draw button label, if any:
|
|---|
| 784 | *
|
|---|
| 785 | * In win9x we don't show text if there is a bitmap or icon.
|
|---|
| 786 | * I don't know about win31 so I leave it as it was for win31.
|
|---|
| 787 | * Dennis Björklund 12 Jul, 99
|
|---|
| 788 | */
|
|---|
| 789 | textLen = GetWindowTextLengthA(hwnd);
|
|---|
| 790 | if ((textLen > 0) && (!(dwStyle & (BS_ICON|BS_BITMAP))))
|
|---|
| 791 | {
|
|---|
| 792 | INT format = BUTTON_GetTextFormat(dwStyle,GetWindowLongA(hwnd,GWL_EXSTYLE),DT_CENTER,DT_VCENTER);
|
|---|
| 793 |
|
|---|
| 794 | textLen++;
|
|---|
| 795 | text = (char*)malloc(textLen);
|
|---|
| 796 | GetWindowTextA(hwnd,text,textLen);
|
|---|
| 797 |
|
|---|
| 798 | if (dwStyle & WS_DISABLED) DrawDisabledText(hDC,text,&rc,format); else
|
|---|
| 799 | {
|
|---|
| 800 | SetTextColor(hDC,GetSysColor(COLOR_BTNTEXT));
|
|---|
| 801 | DrawTextA(hDC,text,-1,&rc,format);
|
|---|
| 802 | /* do we have the focus?
|
|---|
| 803 | * Win9x draws focus last with a size prop. to the button
|
|---|
| 804 | */
|
|---|
| 805 | }
|
|---|
| 806 | free(text);
|
|---|
| 807 | }
|
|---|
| 808 | if ( ((dwStyle & BS_ICON) || (dwStyle & BS_BITMAP) ) &&
|
|---|
| 809 | (infoPtr->hImage != 0) )
|
|---|
| 810 | {
|
|---|
| 811 | int yOffset, xOffset;
|
|---|
| 812 | int imageWidth, imageHeight;
|
|---|
| 813 |
|
|---|
| 814 | /*
|
|---|
| 815 | * We extract the size of the image from the handle.
|
|---|
| 816 | */
|
|---|
| 817 | if (dwStyle & BS_ICON)
|
|---|
| 818 | {
|
|---|
| 819 | ICONINFO iconInfo;
|
|---|
| 820 | BITMAP bm;
|
|---|
| 821 |
|
|---|
| 822 | GetIconInfo((HICON)infoPtr->hImage,&iconInfo);
|
|---|
| 823 | if (iconInfo.hbmColor)
|
|---|
| 824 | {
|
|---|
| 825 | GetObjectA(iconInfo.hbmColor,sizeof(BITMAP),&bm);
|
|---|
| 826 | imageWidth = bm.bmWidth;
|
|---|
| 827 | imageHeight = bm.bmHeight;
|
|---|
| 828 | } else
|
|---|
| 829 | {
|
|---|
| 830 | GetObjectA(iconInfo.hbmMask,sizeof(BITMAP),&bm);
|
|---|
| 831 | imageWidth = bm.bmWidth;
|
|---|
| 832 | imageHeight = bm.bmHeight/2;
|
|---|
| 833 | }
|
|---|
| 834 |
|
|---|
| 835 | if (iconInfo.hbmColor) DeleteObject(iconInfo.hbmColor);
|
|---|
| 836 | if (iconInfo.hbmMask) DeleteObject(iconInfo.hbmMask);
|
|---|
| 837 |
|
|---|
| 838 | }
|
|---|
| 839 | else
|
|---|
| 840 | {
|
|---|
| 841 | BITMAP bm;
|
|---|
| 842 |
|
|---|
| 843 | GetObjectA (infoPtr->hImage, sizeof(BITMAP), &bm);
|
|---|
| 844 |
|
|---|
| 845 | imageWidth = bm.bmWidth;
|
|---|
| 846 | imageHeight = bm.bmHeight;
|
|---|
| 847 | }
|
|---|
| 848 |
|
|---|
| 849 | /* Center the bitmap */
|
|---|
| 850 | xOffset = (((rc.right - rc.left) - 2*xBorderOffset) - imageWidth ) / 2;
|
|---|
| 851 | yOffset = (((rc.bottom - rc.top) - 2*yBorderOffset) - imageHeight) / 2;
|
|---|
| 852 |
|
|---|
| 853 | /* If the image is too big for the button then create a region*/
|
|---|
| 854 | if(xOffset < 0 || yOffset < 0)
|
|---|
| 855 | {
|
|---|
| 856 | HRGN hBitmapRgn = 0;
|
|---|
| 857 | hBitmapRgn = CreateRectRgn(
|
|---|
| 858 | rc.left + xBorderOffset, rc.top +yBorderOffset,
|
|---|
| 859 | rc.right - xBorderOffset, rc.bottom - yBorderOffset);
|
|---|
| 860 | SelectClipRgn(hDC, hBitmapRgn);
|
|---|
| 861 | DeleteObject(hBitmapRgn);
|
|---|
| 862 | }
|
|---|
| 863 |
|
|---|
| 864 | /* Let minimum 1 space from border */
|
|---|
| 865 | xOffset++, yOffset++;
|
|---|
| 866 |
|
|---|
| 867 | /*
|
|---|
| 868 | * Draw the image now.
|
|---|
| 869 | */
|
|---|
| 870 | if (dwStyle & BS_ICON)
|
|---|
| 871 | {
|
|---|
| 872 | DrawIcon(hDC,
|
|---|
| 873 | rc.left + xOffset, rc.top + yOffset,
|
|---|
| 874 | (HICON)infoPtr->hImage);
|
|---|
| 875 | }
|
|---|
| 876 | else
|
|---|
| 877 | {
|
|---|
| 878 | HDC hdcMem;
|
|---|
| 879 |
|
|---|
| 880 | hdcMem = CreateCompatibleDC (hDC);
|
|---|
| 881 | SelectObject (hdcMem, (HBITMAP)infoPtr->hImage);
|
|---|
| 882 | BitBlt(hDC,
|
|---|
| 883 | rc.left + xOffset,
|
|---|
| 884 | rc.top + yOffset,
|
|---|
| 885 | imageWidth, imageHeight,
|
|---|
| 886 | hdcMem, 0, 0, SRCCOPY);
|
|---|
| 887 |
|
|---|
| 888 | DeleteDC (hdcMem);
|
|---|
| 889 | }
|
|---|
| 890 |
|
|---|
| 891 | if(xOffset < 0 || yOffset < 0)
|
|---|
| 892 | {
|
|---|
| 893 | SelectClipRgn(hDC, 0);
|
|---|
| 894 | }
|
|---|
| 895 | }
|
|---|
| 896 |
|
|---|
| 897 | SelectObject( hDC, hOldPen );
|
|---|
| 898 | SelectObject( hDC, hOldBrush );
|
|---|
| 899 |
|
|---|
| 900 | if ((infoPtr->state & BUTTON_HASFOCUS) && IsWindowEnabled(hwnd))
|
|---|
| 901 | {
|
|---|
| 902 | InflateRect( &focus_rect, -1, -1 );
|
|---|
| 903 | DrawFocusRect( hDC, &focus_rect );
|
|---|
| 904 | }
|
|---|
| 905 | }
|
|---|
| 906 |
|
|---|
| 907 |
|
|---|
| 908 | static void DrawDisabledText(HDC hdc,char* text,RECT* rtext,UINT format)
|
|---|
| 909 | {
|
|---|
| 910 | COLORREF textColor = (GetSysColor(COLOR_GRAYTEXT) == GetBkColor(hdc)) ? COLOR_BTNTEXT:COLOR_GRAYTEXT;
|
|---|
| 911 | RECT rect = *rtext;
|
|---|
| 912 | COLORREF oldMode;
|
|---|
| 913 |
|
|---|
| 914 | //CB: bug in Open32 DrawText: underscore is always black! -> two black lines!
|
|---|
| 915 | SetTextColor(hdc,GetSysColor(COLOR_3DHILIGHT));
|
|---|
| 916 | DrawTextA(hdc,text,-1,&rect,format);
|
|---|
| 917 | SetTextColor(hdc,GetSysColor(COLOR_GRAYTEXT));
|
|---|
| 918 | oldMode = SetBkMode(hdc,TRANSPARENT);
|
|---|
| 919 | OffsetRect(&rect,-1,-1);
|
|---|
| 920 | DrawTextA(hdc,text,-1,&rect,format);
|
|---|
| 921 | SetBkMode(hdc,oldMode);
|
|---|
| 922 | }
|
|---|
| 923 |
|
|---|
| 924 | /**********************************************************************
|
|---|
| 925 | * Check Box & Radio Button Functions
|
|---|
| 926 | */
|
|---|
| 927 |
|
|---|
| 928 | static void CB_Paint(HWND hwnd,HDC hDC,WORD action)
|
|---|
| 929 | {
|
|---|
| 930 | BUTTONINFO* infoPtr = (BUTTONINFO*)GetInfoPtr(hwnd);
|
|---|
| 931 | DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
|
|---|
| 932 | RECT rbox, rtext, client;
|
|---|
| 933 | HBRUSH hBrush, hOldBrush;
|
|---|
| 934 | HPEN hPen, hOldPen;
|
|---|
| 935 | COLORREF colour;
|
|---|
| 936 | int textLen, delta;
|
|---|
| 937 | char* text = NULL;
|
|---|
| 938 |
|
|---|
| 939 | /*
|
|---|
| 940 | * if the button has a bitmap/icon, draw a normal pushbutton
|
|---|
| 941 | * instead of a radion button.
|
|---|
| 942 | */
|
|---|
| 943 | if (infoPtr->hImage != 0)
|
|---|
| 944 | {
|
|---|
| 945 | BOOL bHighLighted = ((infoPtr->state & BUTTON_HIGHLIGHTED) ||
|
|---|
| 946 | (infoPtr->state & BUTTON_CHECKED));
|
|---|
| 947 |
|
|---|
| 948 | BUTTON_DrawPushButton(hwnd,
|
|---|
| 949 | hDC,
|
|---|
| 950 | action,
|
|---|
| 951 | bHighLighted);
|
|---|
| 952 | return;
|
|---|
| 953 | }
|
|---|
| 954 |
|
|---|
| 955 | textLen = 0;
|
|---|
| 956 | GetClientRect(hwnd, &client);
|
|---|
| 957 | rbox = rtext = client;
|
|---|
| 958 |
|
|---|
| 959 | if (infoPtr->hFont) SelectObject( hDC, infoPtr->hFont );
|
|---|
| 960 |
|
|---|
| 961 | /* Something is still not right, checkboxes (and edit controls)
|
|---|
| 962 | * in wsping32 have white backgrounds instead of dark grey.
|
|---|
| 963 | * BUTTON_SEND_CTLCOLOR() is even worse since it returns 0 in this
|
|---|
| 964 | * particular case and the background is not painted at all.
|
|---|
| 965 | */
|
|---|
| 966 | //SvL: 20/09/99: This works well for us. Now the background of
|
|---|
| 967 | // the dialog button strings in Solitaire is gray
|
|---|
| 968 | SendMessageA(GetParent(hwnd),WM_CTLCOLORBTN,hDC,hwnd);
|
|---|
| 969 |
|
|---|
| 970 | hBrush = GetSysColorBrush(COLOR_BTNFACE);
|
|---|
| 971 |
|
|---|
| 972 | /* In order to make things right, draw the rectangle background! */
|
|---|
| 973 | if ( !(infoPtr->state & BUTTON_HASFOCUS) && (action == ODA_DRAWENTIRE) )
|
|---|
| 974 | {
|
|---|
| 975 | colour = GetBkColor(hDC);
|
|---|
| 976 | hPen = CreatePen( PS_SOLID, 1, colour );
|
|---|
| 977 | if ( hPen )
|
|---|
| 978 | {
|
|---|
| 979 | hOldBrush = SelectObject( hDC, hBrush );
|
|---|
| 980 | hOldPen = SelectObject( hDC, hPen );
|
|---|
| 981 | Rectangle( hDC, client.left, client.top, client.right, client.bottom );
|
|---|
| 982 | SelectObject( hDC, hOldPen );
|
|---|
| 983 | SelectObject( hDC, hOldBrush );
|
|---|
| 984 | DeleteObject( hPen );
|
|---|
| 985 | }
|
|---|
| 986 | }
|
|---|
| 987 |
|
|---|
| 988 | if (dwStyle & BS_LEFTTEXT)
|
|---|
| 989 | {
|
|---|
| 990 | /* magic +4 is what CTL3D expects */
|
|---|
| 991 |
|
|---|
| 992 | rtext.right -= checkBoxWidth + 4;
|
|---|
| 993 | //CB: space for focus rect
|
|---|
| 994 | rtext.left++;
|
|---|
| 995 | rtext.right++;
|
|---|
| 996 | rbox.left = rbox.right - checkBoxWidth;
|
|---|
| 997 | }
|
|---|
| 998 | else
|
|---|
| 999 | {
|
|---|
| 1000 | rtext.left += checkBoxWidth + 4;
|
|---|
| 1001 | rbox.right = checkBoxWidth;
|
|---|
| 1002 | }
|
|---|
| 1003 |
|
|---|
| 1004 | /* Draw the check-box bitmap */
|
|---|
| 1005 |
|
|---|
| 1006 | textLen = GetWindowTextLengthA(hwnd);
|
|---|
| 1007 | if (textLen > 0)
|
|---|
| 1008 | {
|
|---|
| 1009 | textLen++;
|
|---|
| 1010 | text = (char*)malloc(textLen);
|
|---|
| 1011 | GetWindowTextA(hwnd,text,textLen);
|
|---|
| 1012 | }
|
|---|
| 1013 | if ((action == ODA_DRAWENTIRE) || (action == ODA_SELECT))
|
|---|
| 1014 | {
|
|---|
| 1015 | UINT state;
|
|---|
| 1016 |
|
|---|
| 1017 | if (((dwStyle & 0x0f) == BS_RADIOBUTTON) ||
|
|---|
| 1018 | ((dwStyle & 0x0f) == BS_AUTORADIOBUTTON)) state = DFCS_BUTTONRADIO;
|
|---|
| 1019 | else if (infoPtr->state & BUTTON_3STATE) state = DFCS_BUTTON3STATE;
|
|---|
| 1020 | else state = DFCS_BUTTONCHECK;
|
|---|
| 1021 |
|
|---|
| 1022 | if (infoPtr->state & (BUTTON_CHECKED | BUTTON_3STATE)) state |= DFCS_CHECKED;
|
|---|
| 1023 |
|
|---|
| 1024 | if (infoPtr->state & BUTTON_HIGHLIGHTED) state |= DFCS_PUSHED;
|
|---|
| 1025 |
|
|---|
| 1026 | if (dwStyle & WS_DISABLED) state |= DFCS_INACTIVE;
|
|---|
| 1027 |
|
|---|
| 1028 | if (dwStyle & BS_FLAT) state |= DFCS_FLAT;
|
|---|
| 1029 |
|
|---|
| 1030 | DrawFrameControl( hDC, &rbox, DFC_BUTTON, state );
|
|---|
| 1031 |
|
|---|
| 1032 | if( text && action != ODA_SELECT )
|
|---|
| 1033 | {
|
|---|
| 1034 | INT format = BUTTON_GetTextFormat(dwStyle,GetWindowLongA(hwnd,GWL_EXSTYLE),DT_TOP,DT_VCENTER);
|
|---|
| 1035 |
|
|---|
| 1036 | if (dwStyle & WS_DISABLED) DrawDisabledText(hDC,text,&rtext,format);
|
|---|
| 1037 | else DrawTextA(hDC,text,-1,&rtext,format);
|
|---|
| 1038 | }
|
|---|
| 1039 | }
|
|---|
| 1040 |
|
|---|
| 1041 | if ((action == ODA_FOCUS) ||
|
|---|
| 1042 | ((action == ODA_DRAWENTIRE) && (infoPtr->state & BUTTON_HASFOCUS) && IsWindowEnabled(hwnd)))
|
|---|
| 1043 | {
|
|---|
| 1044 | /* again, this is what CTL3D expects */
|
|---|
| 1045 |
|
|---|
| 1046 | SetRectEmpty(&rbox);
|
|---|
| 1047 | if(textLen > 0)
|
|---|
| 1048 | DrawTextA(hDC,text,-1,&rbox,DT_SINGLELINE | DT_CALCRECT);
|
|---|
| 1049 | textLen = rbox.bottom - rbox.top;
|
|---|
| 1050 | delta = ((rtext.bottom - rtext.top) - textLen)/2;
|
|---|
| 1051 | rbox.bottom = (rbox.top = rtext.top + delta - 1) + textLen + 2;
|
|---|
| 1052 | textLen = rbox.right - rbox.left;
|
|---|
| 1053 | rbox.right = (rbox.left += --rtext.left) + textLen + 2;
|
|---|
| 1054 | IntersectRect(&rbox, &rbox, &rtext);
|
|---|
| 1055 | DrawFocusRect( hDC, &rbox );
|
|---|
| 1056 | }
|
|---|
| 1057 | if (text) free(text);
|
|---|
| 1058 | }
|
|---|
| 1059 |
|
|---|
| 1060 |
|
|---|
| 1061 | /**********************************************************************
|
|---|
| 1062 | * BUTTON_CheckAutoRadioButton
|
|---|
| 1063 | *
|
|---|
| 1064 | * wndPtr is checked, uncheck every other auto radio button in group
|
|---|
| 1065 | */
|
|---|
| 1066 | static void BUTTON_CheckAutoRadioButton(HWND hwnd)
|
|---|
| 1067 | {
|
|---|
| 1068 | DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
|
|---|
| 1069 | HWND parent, sibling, start;
|
|---|
| 1070 |
|
|---|
| 1071 | if (!(dwStyle & WS_CHILD)) return;
|
|---|
| 1072 | parent = GetParent(hwnd);
|
|---|
| 1073 | /* assure that starting control is not disabled or invisible */
|
|---|
| 1074 | //start = sibling = GetNextDlgGroupItem( parent, hwnd, TRUE );
|
|---|
| 1075 | //@YD: bugfix
|
|---|
| 1076 | //CB: doesn't work!
|
|---|
| 1077 | start = sibling = GetNextDlgGroupItem( parent, hwnd, FALSE );
|
|---|
| 1078 | do
|
|---|
| 1079 | {
|
|---|
| 1080 | if (!sibling) break;
|
|---|
| 1081 | if ((hwnd != sibling) &&
|
|---|
| 1082 | ((GetWindowLongA(sibling,GWL_STYLE) & 0x0f) == BS_AUTORADIOBUTTON))
|
|---|
| 1083 | SendMessageA( sibling, BM_SETCHECK, BUTTON_UNCHECKED, 0 );
|
|---|
| 1084 | sibling = GetNextDlgGroupItem( parent, sibling, FALSE );
|
|---|
| 1085 | } while (sibling != start);
|
|---|
| 1086 | }
|
|---|
| 1087 |
|
|---|
| 1088 |
|
|---|
| 1089 | /**********************************************************************
|
|---|
| 1090 | * Group Box Functions
|
|---|
| 1091 | */
|
|---|
| 1092 |
|
|---|
| 1093 | static void GB_Paint(HWND hwnd,HDC hDC,WORD action)
|
|---|
| 1094 | {
|
|---|
| 1095 | BUTTONINFO* infoPtr = (BUTTONINFO*)GetInfoPtr(hwnd);
|
|---|
| 1096 | DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
|
|---|
| 1097 | RECT rc, rcFrame;
|
|---|
| 1098 | TEXTMETRICA tm;
|
|---|
| 1099 | INT textLen;
|
|---|
| 1100 | char* text;
|
|---|
| 1101 |
|
|---|
| 1102 | if (action != ODA_DRAWENTIRE) return;
|
|---|
| 1103 |
|
|---|
| 1104 | SendMessageA(GetParent(hwnd),WM_CTLCOLORBTN,hDC,hwnd);
|
|---|
| 1105 |
|
|---|
| 1106 | GetClientRect(hwnd,&rc);
|
|---|
| 1107 |
|
|---|
| 1108 | rcFrame = rc;
|
|---|
| 1109 |
|
|---|
| 1110 | if (infoPtr->hFont)
|
|---|
| 1111 | SelectObject (hDC, infoPtr->hFont);
|
|---|
| 1112 | GetTextMetricsA (hDC, &tm);
|
|---|
| 1113 | rcFrame.top += (tm.tmHeight / 2) - 1;
|
|---|
| 1114 | DrawEdge (hDC, &rcFrame, EDGE_ETCHED, BF_RECT);
|
|---|
| 1115 |
|
|---|
| 1116 | textLen = GetWindowTextLengthA(hwnd);
|
|---|
| 1117 | if (textLen > 0)
|
|---|
| 1118 | {
|
|---|
| 1119 | INT format = BUTTON_GetTextFormat(dwStyle,GetWindowLongA(hwnd,GWL_EXSTYLE),DT_LEFT,DT_TOP) | DT_NOCLIP | DT_SINGLELINE;
|
|---|
| 1120 |
|
|---|
| 1121 | textLen++;
|
|---|
| 1122 | text = (char*)malloc(textLen);
|
|---|
| 1123 | GetWindowTextA(hwnd,text,textLen);
|
|---|
| 1124 | if (infoPtr->hFont) SelectObject( hDC, infoPtr->hFont );
|
|---|
| 1125 | rc.left += 10;
|
|---|
| 1126 |
|
|---|
| 1127 | if (dwStyle & WS_DISABLED) DrawDisabledText(hDC,text,&rc,format); else
|
|---|
| 1128 | {
|
|---|
| 1129 | SetTextColor(hDC,GetSysColor(COLOR_BTNTEXT));
|
|---|
| 1130 | DrawTextA(hDC,text,-1,&rc,format);
|
|---|
| 1131 | }
|
|---|
| 1132 |
|
|---|
| 1133 | free(text);
|
|---|
| 1134 | }
|
|---|
| 1135 | }
|
|---|
| 1136 |
|
|---|
| 1137 |
|
|---|
| 1138 | /**********************************************************************
|
|---|
| 1139 | * User Button Functions
|
|---|
| 1140 | */
|
|---|
| 1141 |
|
|---|
| 1142 | static void UB_Paint(HWND hwnd,HDC hDC,WORD action)
|
|---|
| 1143 | {
|
|---|
| 1144 | BUTTONINFO* infoPtr = (BUTTONINFO*)GetInfoPtr(hwnd);
|
|---|
| 1145 | DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
|
|---|
| 1146 | RECT rc;
|
|---|
| 1147 | HBRUSH hBrush;
|
|---|
| 1148 | if (action == ODA_SELECT) return;
|
|---|
| 1149 |
|
|---|
| 1150 | GetClientRect(hwnd,&rc);
|
|---|
| 1151 |
|
|---|
| 1152 | if (infoPtr->hFont) SelectObject( hDC, infoPtr->hFont );
|
|---|
| 1153 | hBrush = GetSysColorBrush(COLOR_BTNFACE);
|
|---|
| 1154 |
|
|---|
| 1155 | if ((action == ODA_FOCUS) ||
|
|---|
| 1156 | ((action == ODA_DRAWENTIRE) && (infoPtr->state & BUTTON_HASFOCUS) && IsWindowEnabled(hwnd)))
|
|---|
| 1157 | {
|
|---|
| 1158 | DrawFocusRect( hDC, &rc );
|
|---|
| 1159 | InflateRect(&rc,-1,-1);
|
|---|
| 1160 | }
|
|---|
| 1161 | FillRect( hDC, &rc, hBrush );
|
|---|
| 1162 | }
|
|---|
| 1163 |
|
|---|
| 1164 |
|
|---|
| 1165 | /**********************************************************************
|
|---|
| 1166 | * Ownerdrawn Button Functions
|
|---|
| 1167 | */
|
|---|
| 1168 |
|
|---|
| 1169 | static void OB_Paint(HWND hwnd,HDC hDC,WORD action)
|
|---|
| 1170 | {
|
|---|
| 1171 | BUTTONINFO* infoPtr = (BUTTONINFO*)GetInfoPtr(hwnd);
|
|---|
| 1172 | DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
|
|---|
| 1173 | DRAWITEMSTRUCT dis;
|
|---|
| 1174 |
|
|---|
| 1175 | dis.CtlType = ODT_BUTTON;
|
|---|
| 1176 | dis.CtlID = GetWindowLongA(hwnd,GWL_ID);
|
|---|
| 1177 | dis.itemID = 0;
|
|---|
| 1178 | dis.itemAction = action;
|
|---|
| 1179 | dis.itemState = ((infoPtr->state & BUTTON_HASFOCUS) ? ODS_FOCUS : 0) |
|
|---|
| 1180 | ((infoPtr->state & BUTTON_HIGHLIGHTED) ? ODS_SELECTED : 0) |
|
|---|
| 1181 | ((dwStyle & WS_DISABLED) ? ODS_DISABLED : 0);
|
|---|
| 1182 | dis.hwndItem = hwnd;
|
|---|
| 1183 | dis.hDC = hDC;
|
|---|
| 1184 | dis.itemData = 0;
|
|---|
| 1185 | GetClientRect( hwnd, &dis.rcItem );
|
|---|
| 1186 |
|
|---|
| 1187 | SetBkColor( hDC, GetSysColor( COLOR_BTNFACE ) );
|
|---|
| 1188 |
|
|---|
| 1189 | dprintf(("OWNERDRAW button %x, enabled %d", hwnd, !(dwStyle & WS_DISABLED)));
|
|---|
| 1190 | SendMessageA( GetParent(hwnd), WM_DRAWITEM,
|
|---|
| 1191 | GetWindowLongA(hwnd,GWL_ID), (LPARAM)&dis );
|
|---|
| 1192 | }
|
|---|
| 1193 |
|
|---|
| 1194 | BOOL BUTTON_Register()
|
|---|
| 1195 | {
|
|---|
| 1196 | WNDCLASSA wndClass;
|
|---|
| 1197 |
|
|---|
| 1198 | //SvL: Don't check this now
|
|---|
| 1199 | // if (GlobalFindAtomA(BUTTONCLASSNAME)) return FALSE;
|
|---|
| 1200 |
|
|---|
| 1201 | ZeroMemory(&wndClass,sizeof(WNDCLASSA));
|
|---|
| 1202 | wndClass.style = CS_GLOBALCLASS | CS_HREDRAW | CS_VREDRAW | CS_PARENTDC | CS_DBLCLKS;
|
|---|
| 1203 | wndClass.lpfnWndProc = (WNDPROC)ButtonWndProc;
|
|---|
| 1204 | wndClass.cbClsExtra = 0;
|
|---|
| 1205 | wndClass.cbWndExtra = sizeof(BUTTONINFO);
|
|---|
| 1206 | wndClass.hCursor = LoadCursorA(0,IDC_ARROWA);
|
|---|
| 1207 | // wndClass.hbrBackground = (HBRUSH)0;
|
|---|
| 1208 | wndClass.hbrBackground = GetSysColorBrush(COLOR_BTNFACE);
|
|---|
| 1209 | wndClass.lpszClassName = BUTTONCLASSNAME;
|
|---|
| 1210 |
|
|---|
| 1211 | return RegisterClassA(&wndClass);
|
|---|
| 1212 | }
|
|---|
| 1213 |
|
|---|
| 1214 | BOOL BUTTON_Unregister()
|
|---|
| 1215 | {
|
|---|
| 1216 | if (GlobalFindAtomA(BUTTONCLASSNAME))
|
|---|
| 1217 | return UnregisterClassA(BUTTONCLASSNAME,(HINSTANCE)NULL);
|
|---|
| 1218 | else return FALSE;
|
|---|
| 1219 | }
|
|---|