Changeset 496 for trunk/src/comctl32/datetime.c
- Timestamp:
- Aug 14, 1999, 6:13:16 PM (26 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/comctl32/datetime.c
r94 r496 1 /* $Id: datetime.c,v 1. 3 1999-06-10 16:21:58 achimhaExp $ */1 /* $Id: datetime.c,v 1.4 1999-08-14 16:13:10 cbratschi Exp $ */ 2 2 /* 3 3 * Date and time picker control 4 4 * 5 5 * Copyright 1998, 1999 Eric Kohl 6 * Copyright 1999 Alex Priem <alexp@sci.kun.nl> 6 7 * Copyright 1999 Achim Hasenmueller 8 * Copyright 1999 Christoph Bratschi 7 9 * 8 * NOTES9 * This is just a dummy control. An author is needed! Any volunteers?10 * I will only improve this control once in a while.11 * Eric <ekohl@abo.rhein-zeitung.de>12 10 * 13 11 * TODO: … … 20 18 #include "commctrl.h" 21 19 #include "datetime.h" 22 20 #include "monthcal.h" 21 #include <string.h> 22 #include <stdio.h> 23 23 24 24 25 25 #define DATETIME_GetInfoPtr(hwnd) ((DATETIME_INFO *)GetWindowLongA (hwnd, 0)) 26 static BOOL 27 28 DATETIME_SendSimpleNotify (HWND hwnd, UINT code); 29 30 static char *days[] = {"Sunday", "Monday", "Tuesday", "Wednesday", 31 "Thursday", "Friday", "Saturday", NULL}; 32 33 static char *monthtxt[] = {"January", "February", "March", "April", "May", 34 "June", "July", "August", "September", "October", 35 "November", "December"}; 36 37 static LRESULT 38 DATETIME_GetSystemTime (HWND hwnd, WPARAM wParam, LPARAM lParam ) 39 { 40 DATETIME_INFO *infoPtr = DATETIME_GetInfoPtr (hwnd); 41 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE); 42 SYSTEMTIME *lprgSysTimeArray=(SYSTEMTIME *) lParam; 43 44 if (!lParam) return GDT_NONE; 45 46 if ((dwStyle & DTS_SHOWNONE) && 47 (SendMessageA (infoPtr->hwndCheckbut, BM_GETCHECK, 0, 0))) 48 return GDT_NONE; 49 50 MONTHCAL_CopyTime (&infoPtr->date, lprgSysTimeArray); 51 52 return GDT_VALID; 53 } 54 55 56 static LRESULT 57 DATETIME_SetSystemTime (HWND hwnd, WPARAM wParam, LPARAM lParam ) 58 { 59 DATETIME_INFO *infoPtr = DATETIME_GetInfoPtr (hwnd); 60 SYSTEMTIME *lprgSysTimeArray=(SYSTEMTIME *) lParam; 61 62 if (!lParam) return 0; 63 64 if (lParam==GDT_VALID) 65 MONTHCAL_CopyTime (lprgSysTimeArray, &infoPtr->date); 66 if (lParam==GDT_NONE) { 67 infoPtr->dateValid=FALSE; 68 SendMessageA (infoPtr->hwndCheckbut, BM_SETCHECK, 0, 0); 69 } 70 return 1; 71 } 72 73 74 static LRESULT 75 DATETIME_GetMonthCalColor (HWND hwnd, WPARAM wParam) 76 { 77 DATETIME_INFO *infoPtr = DATETIME_GetInfoPtr (hwnd); 78 79 return SendMessageA (infoPtr->hMonthCal, MCM_GETCOLOR, wParam, 0); 80 } 81 82 static LRESULT 83 DATETIME_SetMonthCalColor (HWND hwnd, WPARAM wParam, LPARAM lParam) 84 { 85 DATETIME_INFO *infoPtr = DATETIME_GetInfoPtr (hwnd); 86 87 return SendMessageA (infoPtr->hMonthCal, MCM_SETCOLOR, wParam, lParam); 88 } 89 90 91 /* FIXME: need to get way to force font into monthcal structure */ 92 93 static LRESULT 94 DATETIME_GetMonthCal (HWND hwnd) 95 { 96 DATETIME_INFO *infoPtr = DATETIME_GetInfoPtr (hwnd); 97 98 return infoPtr->hMonthCal; 99 } 100 101 102 103 /* FIXME: need to get way to force font into monthcal structure */ 104 105 static LRESULT 106 DATETIME_GetMonthCalFont (HWND hwnd) 107 { 108 109 return 0; 110 } 111 112 static LRESULT 113 DATETIME_SetMonthCalFont (HWND hwnd, WPARAM wParam, LPARAM lParam) 114 { 115 116 return 0; 117 } 118 119 120 static void DATETIME_Refresh (HWND hwnd, HDC hdc) 121 122 { 123 DATETIME_INFO *infoPtr = DATETIME_GetInfoPtr (hwnd); 124 RECT *daytxt = &infoPtr->daytxt; 125 RECT *daynumtxt= &infoPtr->daynumtxt; 126 RECT *rmonthtxt= &infoPtr->rmonthtxt; 127 RECT *yeartxt = &infoPtr->yeartxt; 128 RECT *calbutton= &infoPtr->calbutton; 129 RECT *checkbox = &infoPtr->checkbox; 130 RECT *rect = &infoPtr->rect; 131 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE); 132 SYSTEMTIME date = infoPtr->date; 133 SIZE size; 134 BOOL prssed=FALSE; 135 COLORREF oldBk; 136 137 138 139 if (infoPtr->dateValid) { 140 char txt[80]; 141 HFONT oldFont; 142 oldFont = SelectObject (hdc, infoPtr->hFont); 143 144 GetClientRect (hwnd, rect); 145 146 sprintf (txt,"%s,",days[date.wDayOfWeek]); 147 GetTextExtentPoint32A (hdc, txt, strlen (txt), &size); 148 rect->bottom=size.cy+2; 149 150 checkbox->left = 0; 151 checkbox->right = 0; 152 checkbox->top = rect->top; 153 checkbox->bottom= rect->bottom; 154 if (dwStyle & DTS_SHOWNONE) { /* FIXME: draw checkbox */ 155 checkbox->right=18; 156 } 157 158 159 if (infoPtr->select==(DTHT_DAY|DTHT_GOTFOCUS)) 160 oldBk=SetBkColor (hdc, COLOR_GRAYTEXT); 161 daytxt->left = checkbox->right; 162 daytxt->right = checkbox->right+size.cx; 163 daytxt->top = rect->top; 164 daytxt->bottom= rect->bottom; 165 DrawTextA ( hdc, txt, strlen(txt), daytxt, 166 DT_LEFT | DT_VCENTER | DT_SINGLELINE ); 167 if (infoPtr->select==(DTHT_DAY|DTHT_GOTFOCUS)) 168 SetBkColor (hdc, oldBk); 169 170 if (infoPtr->select==(DTHT_MONTH|DTHT_GOTFOCUS)) 171 oldBk=SetBkColor (hdc, COLOR_GRAYTEXT); 172 strcpy (txt, monthtxt[date.wMonth]); 173 GetTextExtentPoint32A (hdc, "September", 9, &size); 174 rmonthtxt->left = daytxt->right; 175 rmonthtxt->right = daytxt->right+size.cx; 176 rmonthtxt->top = rect->top; 177 rmonthtxt->bottom= rect->bottom; 178 DrawTextA ( hdc, txt, strlen(txt), rmonthtxt, 179 DT_CENTER | DT_VCENTER | DT_SINGLELINE ); 180 if (infoPtr->select==(DTHT_MONTH|DTHT_GOTFOCUS)) 181 SetBkColor (hdc, oldBk); 182 183 if (infoPtr->select==(DTHT_DAYNUM|DTHT_GOTFOCUS)) 184 oldBk=SetBkColor (hdc, COLOR_GRAYTEXT); 185 sprintf (txt,"%d,",date.wDay); 186 GetTextExtentPoint32A (hdc, "31,", 3, &size); 187 daynumtxt->left = rmonthtxt->right; 188 daynumtxt->right = rmonthtxt->right+size.cx; 189 daynumtxt->top = rect->top; 190 daynumtxt->bottom= rect->bottom; 191 DrawTextA ( hdc, txt, strlen(txt), daynumtxt, 192 DT_RIGHT | DT_VCENTER | DT_SINGLELINE ); 193 if (infoPtr->select==(DTHT_DAYNUM|DTHT_GOTFOCUS)) 194 SetBkColor (hdc, oldBk); 195 196 if (infoPtr->select==(DTHT_YEAR|DTHT_GOTFOCUS)) 197 oldBk=SetBkColor (hdc, COLOR_GRAYTEXT); 198 sprintf (txt,"%d",date.wYear); 199 GetTextExtentPoint32A (hdc, "2000", 5, &size); 200 yeartxt->left = daynumtxt->right; 201 yeartxt->right = daynumtxt->right+size.cx; 202 yeartxt->top = rect->top; 203 yeartxt->bottom= rect->bottom; 204 DrawTextA ( hdc, txt, strlen(txt), yeartxt, 205 DT_RIGHT | DT_VCENTER | DT_SINGLELINE ); 206 if (infoPtr->select==(DTHT_YEAR|DTHT_GOTFOCUS)) 207 SetBkColor (hdc, oldBk); 208 209 SelectObject (hdc, oldFont); 210 } 211 212 if (!(dwStyle & DTS_UPDOWN)) { 213 214 calbutton->right = rect->right; 215 calbutton->left = rect->right-15; 216 calbutton->top = rect->top; 217 calbutton->bottom= rect->bottom; 218 219 DrawFrameControl(hdc, calbutton, DFC_SCROLL, 220 DFCS_SCROLLDOWN | (prssed ? DFCS_PUSHED : 0) | 221 (dwStyle & WS_DISABLED ? DFCS_INACTIVE : 0) ); 222 } 223 224 } 225 226 static LRESULT 227 DATETIME_HitTest (HWND hwnd, DATETIME_INFO *infoPtr, POINT pt) 228 { 229 //TRACE ("%ld, %ld\n",pt.x,pt.y); 230 231 if (PtInRect (&infoPtr->calbutton, pt)) return DTHT_MCPOPUP; 232 if (PtInRect (&infoPtr->yeartxt, pt)) return DTHT_YEAR; 233 if (PtInRect (&infoPtr->daynumtxt, pt)) return DTHT_DAYNUM; 234 if (PtInRect (&infoPtr->rmonthtxt, pt)) return DTHT_MONTH; 235 if (PtInRect (&infoPtr->daytxt, pt)) return DTHT_DAY; 236 if (PtInRect (&infoPtr->checkbox, pt)) return DTHT_CHECKBOX; 237 238 return 0; 239 } 240 241 static LRESULT 242 DATETIME_LButtonDown (HWND hwnd, WPARAM wParam, LPARAM lParam) 243 { 244 DATETIME_INFO *infoPtr = DATETIME_GetInfoPtr (hwnd); 245 POINT pt; 246 int old; 247 248 //TRACE ("\n"); 249 250 old=infoPtr->select; 251 pt.x=(INT)LOWORD(lParam); 252 pt.y=(INT)HIWORD(lParam); 253 infoPtr->select=DATETIME_HitTest (hwnd, infoPtr, pt); 254 255 if (infoPtr->select!=old) { 256 HDC hdc; 257 258 SetFocus (hwnd); 259 hdc=GetDC (hwnd); 260 DATETIME_Refresh (hwnd,hdc); 261 ReleaseDC (hwnd, hdc); 262 } 263 if (infoPtr->select==DTHT_MCPOPUP) { 264 POINT pt; 265 266 pt.x=8; 267 pt.y=infoPtr->rect.bottom+5; 268 ClientToScreen (hwnd, &pt); 269 infoPtr->hMonthCal=CreateWindowExA (0,"SysMonthCal32", 0, 270 WS_POPUP | WS_BORDER, 271 pt.x,pt.y,145,150, 272 GetParent (hwnd), 273 0,0,0); 274 275 //TRACE ("dt:%x mc:%x mc parent:%x, desktop:%x, mcpp:%x\n", 276 //hwnd,infoPtr->hMonthCal, 277 //GetParent (infoPtr->hMonthCal), 278 //GetDesktopWindow (), 279 //GetParent (GetParent (infoPtr->hMonthCal))); 280 281 SetFocus (hwnd); 282 DATETIME_SendSimpleNotify (hwnd, DTN_DROPDOWN); 283 } 284 return 0; 285 } 286 287 288 static LRESULT 289 DATETIME_Paint (HWND hwnd, WPARAM wParam) 290 { 291 HDC hdc; 292 PAINTSTRUCT ps; 293 294 hdc = wParam==0 ? BeginPaint (hwnd, &ps) : (HDC)wParam; 295 DATETIME_Refresh (hwnd, hdc); 296 if(!wParam) 297 EndPaint (hwnd, &ps); 298 return 0; 299 } 300 301 static LRESULT 302 DATETIME_ParentNotify (HWND hwnd, WPARAM wParam, LPARAM lParam) 303 { 304 DATETIME_INFO *infoPtr = DATETIME_GetInfoPtr (hwnd); 305 LPNMHDR lpnmh=(LPNMHDR) lParam; 306 307 //TRACE ("%x,%lx\n",wParam, lParam); 308 //TRACE ("Got notification %x from %x\n", lpnmh->code, lpnmh->hwndFrom); 309 //TRACE ("info: %x %x %x\n",hwnd,infoPtr->hMonthCal,infoPtr->hUpdown); 310 return 0; 311 } 312 313 static LRESULT 314 DATETIME_Notify (HWND hwnd, WPARAM wParam, LPARAM lParam) 315 316 { 317 DATETIME_INFO *infoPtr = DATETIME_GetInfoPtr (hwnd); 318 LPNMHDR lpnmh=(LPNMHDR) lParam; 319 320 //TRACE ("%x,%lx\n",wParam, lParam); 321 //TRACE ("Got notification %x from %x\n", lpnmh->code, lpnmh->hwndFrom); 322 //TRACE ("info: %x %x %x\n",hwnd,infoPtr->hMonthCal,infoPtr->hUpdown); 323 return 0; 324 } 325 326 static LRESULT 327 DATETIME_KillFocus (HWND hwnd, WPARAM wParam, LPARAM lParam) 328 { 329 DATETIME_INFO *infoPtr = DATETIME_GetInfoPtr (hwnd); 330 HDC hdc; 331 332 //TRACE ("\n"); 333 334 if (infoPtr->select) { 335 DATETIME_SendSimpleNotify (hwnd, NM_KILLFOCUS); 336 infoPtr->select&= ~DTHT_GOTFOCUS; 337 } 338 hdc = GetDC (hwnd); 339 DATETIME_Refresh (hwnd, hdc); 340 ReleaseDC (hwnd, hdc); 341 InvalidateRect (hwnd, NULL, TRUE); 342 343 return 0; 344 } 345 346 347 static LRESULT 348 DATETIME_SetFocus (HWND hwnd, WPARAM wParam, LPARAM lParam) 349 { 350 HDC hdc; 351 DATETIME_INFO *infoPtr = DATETIME_GetInfoPtr (hwnd); 352 353 //TRACE ("\n"); 354 355 if (infoPtr->select) { 356 DATETIME_SendSimpleNotify (hwnd, NM_SETFOCUS); 357 infoPtr->select|=DTHT_GOTFOCUS; 358 } 359 hdc = GetDC (hwnd); 360 DATETIME_Refresh (hwnd, hdc); 361 ReleaseDC (hwnd, hdc); 362 363 return 0; 364 } 365 366 367 static BOOL 368 DATETIME_SendSimpleNotify (HWND hwnd, UINT code) 369 { 370 NMHDR nmhdr; 371 372 //TRACE("%x\n",code); 373 nmhdr.hwndFrom = hwnd; 374 nmhdr.idFrom = GetWindowLongA( hwnd, GWL_ID); 375 nmhdr.code = code; 376 377 return (BOOL) SendMessageA (GetParent (hwnd), WM_NOTIFY, 378 (WPARAM)nmhdr.idFrom, (LPARAM)&nmhdr); 379 } 26 380 27 381 … … 33 387 DATETIME_Create (HWND hwnd, WPARAM wParam, LPARAM lParam) 34 388 { 35 DATETIME_INFO *infoPtr; 389 DATETIME_INFO *infoPtr; 390 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE); 36 391 37 392 /* allocate memory for info structure */ 38 393 infoPtr = (DATETIME_INFO *)COMCTL32_Alloc (sizeof(DATETIME_INFO)); 39 394 if (infoPtr == NULL) { 40 // ERR (datetime,"could not allocate info memory!\n");41 395 //ERR("could not allocate info memory!\n"); 396 return 0; 42 397 } 43 398 44 399 SetWindowLongA (hwnd, 0, (DWORD)infoPtr); 45 400 401 if (dwStyle & DTS_SHOWNONE) { 402 infoPtr->hwndCheckbut=CreateWindowExA (0,"button", 0, 403 WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX, 404 2,2,13,13, 405 hwnd, 406 0, GetWindowLongA (hwnd, GWL_HINSTANCE), 0); 407 SendMessageA (infoPtr->hwndCheckbut, BM_SETCHECK, 1, 0); 408 } 409 410 if (dwStyle & DTS_UPDOWN) { 411 412 infoPtr->hUpdown=CreateUpDownControl ( 413 WS_CHILD | WS_BORDER | WS_VISIBLE, 414 120,1,20,20, 415 hwnd,1,0,0, 416 UD_MAXVAL, UD_MINVAL, 0); 417 } 46 418 47 419 /* initialize info structure */ 48 49 50 420 infoPtr->hMonthCal=0; 421 GetSystemTime (&infoPtr->date); 422 infoPtr->dateValid = TRUE; 423 infoPtr->hFont = GetStockObject(DEFAULT_GUI_FONT); 51 424 return 0; 52 425 } … … 58 431 DATETIME_INFO *infoPtr = DATETIME_GetInfoPtr (hwnd); 59 432 60 /* free datetime info data */61 433 COMCTL32_Free (infoPtr); 62 63 return 0; 64 } 65 66 67 68 69 LRESULT WINAPI434 return 0; 435 } 436 437 438 439 440 441 static LRESULT WINAPI 70 442 DATETIME_WindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) 71 443 { 444 72 445 switch (uMsg) 73 446 { 74 447 75 448 case DTM_GETSYSTEMTIME: 76 // FIXME (datetime, "Unimplemented msg DTM_GETSYSTEMTIME\n"); 77 return GDT_VALID; 449 DATETIME_GetSystemTime (hwnd, wParam, lParam); 78 450 79 451 case DTM_SETSYSTEMTIME: 80 // FIXME (datetime, "Unimplemented msg DTM_SETSYSTEMTIME\n"); 452 DATETIME_SetSystemTime (hwnd, wParam, lParam); 453 454 case DTM_GETRANGE: 455 //FIXME("Unimplemented msg DTM_GETRANGE\n"); 456 return 0; 457 458 case DTM_SETRANGE: 459 //FIXME("Unimplemented msg DTM_SETRANGE\n"); 81 460 return 1; 82 461 83 case DTM_GETRANGE: 84 // FIXME (datetime, "Unimplemented msg DTM_GETRANGE\n"); 85 return 0; 86 87 case DTM_SETRANGE: 88 // FIXME (datetime, "Unimplemented msg DTM_SETRANGE\n"); 462 case DTM_SETFORMATA: 463 //FIXME("Unimplemented msg DTM_SETFORMAT32A\n"); 89 464 return 1; 90 465 91 case DTM_SETFORMAT A:92 // FIXME (datetime, "Unimplemented msg DTM_SETFORMAT32A\n");466 case DTM_SETFORMATW: 467 //FIXME("Unimplemented msg DTM_SETFORMAT32W\n"); 93 468 return 1; 94 469 95 case DTM_SETFORMATW:96 // FIXME (datetime, "Unimplemented msg DTM_SETFORMAT32W\n");97 return 1;98 99 470 case DTM_SETMCCOLOR: 100 // FIXME (datetime, "Unimplemented msg DTM_SETMCCOLOR\n"); 101 return 0; 471 return DATETIME_SetMonthCalColor (hwnd, wParam, lParam); 102 472 103 473 case DTM_GETMCCOLOR: 104 // FIXME (datetime, "Unimplemented msg DTM_GETMCCOLOR\n"); 105 return 0; 474 return DATETIME_GetMonthCalColor (hwnd, wParam); 106 475 107 476 case DTM_GETMONTHCAL: 108 // FIXME (datetime, "Unimplemented msg DTM_GETMONTHCAL\n"); 109 return 0; 477 return DATETIME_GetMonthCal (hwnd); 110 478 111 479 case DTM_SETMCFONT: 112 // FIXME (datetime, "Unimplemented msg DTM_SETMCFONT\n"); 113 return 0; 480 return DATETIME_SetMonthCalFont (hwnd, wParam, lParam); 114 481 115 482 case DTM_GETMCFONT: 116 // FIXME (datetime, "Unimplemented msg DTM_GETMCFONT\n"); 117 return 0; 118 119 case WM_CREATE: 120 return DATETIME_Create (hwnd, wParam, lParam); 121 122 case WM_DESTROY: 123 return DATETIME_Destroy (hwnd, wParam, lParam); 124 125 default: 126 // if (uMsg >= WM_USER) 127 // ERR (datetime, "unknown msg %04x wp=%08x lp=%08lx\n", 128 // uMsg, wParam, lParam); 129 return DefWindowProcA (hwnd, uMsg, wParam, lParam); 483 return DATETIME_GetMonthCalFont (hwnd); 484 485 case WM_PARENTNOTIFY: 486 return DATETIME_ParentNotify (hwnd, wParam, lParam); 487 488 case WM_NOTIFY: 489 return DATETIME_Notify (hwnd, wParam, lParam); 490 491 case WM_PAINT: 492 return DATETIME_Paint (hwnd, wParam); 493 494 case WM_KILLFOCUS: 495 return DATETIME_KillFocus (hwnd, wParam, lParam); 496 497 case WM_SETFOCUS: 498 return DATETIME_SetFocus (hwnd, wParam, lParam); 499 500 case WM_LBUTTONDOWN: 501 return DATETIME_LButtonDown (hwnd, wParam, lParam); 502 503 case WM_CREATE: 504 return DATETIME_Create (hwnd, wParam, lParam); 505 506 case WM_DESTROY: 507 return DATETIME_Destroy (hwnd, wParam, lParam); 508 509 default: 510 //if (uMsg >= WM_USER) 511 //ERR("unknown msg %04x wp=%08x lp=%08lx\n", 512 // uMsg, wParam, lParam); 513 return DefWindowProcA (hwnd, uMsg, wParam, lParam); 130 514 } 131 515 return 0; … … 134 518 135 519 VOID 136 DATETIME_Register ( VOID)520 DATETIME_Register (void) 137 521 { 138 522 WNDCLASSA wndClass; … … 148 532 wndClass.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1); 149 533 wndClass.lpszClassName = DATETIMEPICK_CLASSA; 150 534 151 535 RegisterClassA (&wndClass); 152 536 } … … 154 538 155 539 VOID 156 DATETIME_Unregister ( VOID)540 DATETIME_Unregister (void) 157 541 { 158 542 if (GlobalFindAtomA (DATETIMEPICK_CLASSA)) 159 160 } 161 543 UnregisterClassA (DATETIMEPICK_CLASSA, (HINSTANCE)NULL); 544 } 545
Note:
See TracChangeset
for help on using the changeset viewer.