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