Changeset 273 for trunk/src/3rdparty/os2/xsystray/xsystray.c
- Timestamp:
- Nov 2, 2009, 3:10:29 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/3rdparty/os2/xsystray/xsystray.c
r270 r273 111 111 */ 112 112 113 typedef struct _ICONDATA113 typedef struct 114 114 { 115 115 HWND hwnd; 116 116 // associated window 117 U LONG ulId;117 UId; 118 118 // icon ID 119 119 HPOINTER hIcon; … … 123 123 PSZ pszToolTip; 124 124 // icon tooltip (NULL if none) 125 126 127 125 128 126 129 } ICONDATA, *PICONDATA; … … 147 150 size_t cIconsMax; 148 151 // maximum number of icons pIcons can fit 152 153 149 154 150 155 } SYSTRAYDATA, *PSYSTRAYDATA; … … 154 159 // space for the newly added icon 155 160 156 static ULONG QWL_USER_SERVER_DATA = 0; 157 // offset to the PXCENTERWIDGET pointer in the widget data array 161 #define SERVER_MEMORYPOOL_SIZE 65536 162 // taking NOTIFYDATA size into account (<=32 B), this is enough for at 163 // least 2048 simultaneous notification messages, which (even taking 164 // slowly responsing clients into account) sounds sane since in most 165 // cases the structure is freed once it reaches the target event queue 166 // and before a message created as a copy of it is sent to the target 167 // window procedure 158 168 159 169 #define TID_CHECKALIVE 1 … … 161 171 #define TID_CHECKALIVE_TIMEOUT 2000 // ms 162 172 // how often to perform alive checks 173 174 175 176 177 178 179 180 163 181 164 182 static … … 299 317 { 300 318 pData->hwnd = NULLHANDLE; 301 pData->u lId = 0;319 pData->uId = 0; 302 320 if (pData->hIcon != NULLHANDLE) 303 321 { … … 323 341 PICONDATA FindIconData(PSYSTRAYDATA pSysTrayData, 324 342 HWND hwnd, // in: associated window handle 325 U LONG ulId,// in: icon ID343 U // in: icon ID 326 344 size_t *pIdx) // out: index of the icon in the icon array 327 345 // (optional, may be NULL) … … 331 349 { 332 350 if (pSysTrayData->pIcons[i].hwnd == hwnd && 333 pSysTrayData->pIcons[i].u lId == ulId)351 pSysTrayData->pIcons[i].uId) 334 352 { 335 353 if (pIdx) … … 342 360 *pIdx = i; 343 361 return NULL; 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 344 481 } 345 482 … … 404 541 { 405 542 PSIZEL pszl = (PSIZEL)mp2; 406 LONG pad2 = pSysTrayData->lIconPad * 2; 407 pszl->cx = (pSysTrayData->lIconWidth + pad2) * pSysTrayData->cIcons; // desired width 408 pszl->cy = pSysTrayData->lIconHeight + pad2; // desired minimum height 543 LONG pad = pSysTrayData->lIconPad; 544 size_t cnt = pSysTrayData->cIcons; 545 // desired width 546 if (cnt) 547 pszl->cx = pad + (pSysTrayData->lIconWidth + pad) * cnt; 548 else 549 pszl->cx = 0; 550 // desired minimum height 551 pszl->cy = pSysTrayData->lIconHeight + pad * 2; 409 552 brc = TRUE; 410 553 } … … 421 564 * implementation for WM_PAINT in fnwpXSysTray. 422 565 * 423 * This really does nothing, except painting a 424 * 3D rectangle and printing a question mark. 566 * Draws all the icons. If the widget's center is located to the left from 567 * the XCenter's center, icons go left to right. Otherwise, they go right 568 * to left. 569 */ 570 /* 571 +---------------------------+ p = lIconPad 572 | p | w = lIconWidth 573 | +-------+ +-------+ | h = lIconHeight 574 | p | w | p | w | p | 575 | | h| | h| | 576 | | | | | | If "Frame around statics" is on in XCenter 577 | +-------+ +-------+ | properties, then a 1 px 3D frame is drawn 578 | p | within the pad area. So, lIconPad must 579 +---------------------------+ be at least 2 px. 425 580 */ 426 581 … … 438 593 RECTL rcl; 439 594 BOOL bLeftToRight; 440 LONG x, y, l TotalWidth;595 LONG x, y, l; 441 596 size_t i; 442 597 … … 481 636 // always center the icon vertically (we may be given more height than 482 637 // we requested) 483 y = (swp.cy - pSysTrayData->lIcon Width) / 2;638 y = (swp.cy - pSysTrayData->lIcon) / 2; 484 639 485 640 if (bLeftToRight) … … 488 643 x = swp.cx - pSysTrayData->lIconPad - pSysTrayData->lIconWidth; 489 644 490 l TotalWidth = pSysTrayData->lIconWidth + pSysTrayData->lIconPad * 2;645 l; 491 646 492 647 // where to start from? 493 648 if (bLeftToRight) 494 649 { 495 i = rclPaint.xLeft / l TotalWidth;496 x = pSysTrayData->lIconPad + i * l TotalWidth;650 i = rclPaint.xLeft / l; 651 x = pSysTrayData->lIconPad + i * l; 497 652 } 498 653 else 499 654 { 500 i = (swp.cx - rclPaint.xRight) / lTotalWidth; 501 x = swp.cx - (i + 1) * lTotalWidth + pSysTrayData->lIconPad; 655 i = (swp.cx - rclPaint.xRight) / lIconStep; 656 x = swp.cx - (i + 1) * lIconStep; 657 // negate the step, for convenience 658 lIconStep = -lIconStep; 502 659 } 503 660 504 661 // draw as many icons as we can / need 505 for ( i = 0; i < pSysTrayData->cIcons; ++i)662 for (; i < pSysTrayData->cIcons; ++i) 506 663 { 507 664 if (x >= rclPaint.xRight) … … 509 666 510 667 DrawPointer(hps, x, y, pSysTrayData->pIcons[i].hIcon, DP_MINI); 511 if (bLeftToRight) 512 x += lTotalWidth; 513 else 514 x -= lTotalWidth; 668 x += lIconStep; 515 669 } 516 670 517 671 WinEndPaint(hps); 518 672 } 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 519 811 } 520 812 … … 562 854 563 855 PSYSTRAYDATA pSysTrayData = NULL; 856 564 857 565 858 WinSetWindowPtr(hwnd, QWL_USER, mp1); … … 575 868 576 869 // initialize the SYSTRAYDATA structure 870 577 871 pSysTrayData->lIconWidth = WinQuerySysValue(HWND_DESKTOP, SV_CXICON) / 2; 578 872 pSysTrayData->lIconHeight = WinQuerySysValue(HWND_DESKTOP, SV_CYICON) / 2; … … 583 877 if (pSysTrayData->pIcons == NULL) 584 878 { 585 free(pSysTrayData);879 (pSysTrayData); 586 880 return (MRESULT)TRUE; 587 881 } 588 882 pSysTrayData->cIcons = 0; 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 589 909 590 910 // create the "server" window (note that we pass the XCENTERWIDGET … … 598 918 if (pSysTrayData->hwndServer == NULLHANDLE) 599 919 { 600 free(pSysTrayData->pIcons); 601 free(pSysTrayData); 920 FreeSysTrayData(pSysTrayData); 602 921 return (MRESULT)TRUE; 603 922 } … … 606 925 607 926 // inform all interested parties that we are fired up 608 // (NOTE: keep in sync with xstGetSysTrayCreatedMsgId()) 609 WinBroadcastMsg(HWND_DESKTOP, 610 WinAddAtom(WinQuerySystemAtomTable(), 611 "ExtendedSysTray.WM_XST_CREATED"), 612 NULL, NULL, 613 BMSG_POST); 927 WinBroadcastMsg(HWND_DESKTOP, WM_XST_CREATED, 928 NULL, NULL, BMSG_POST); 614 929 615 930 return FALSE; // confirm success … … 628 943 629 944 PSYSTRAYDATA pSysTrayData = (PSYSTRAYDATA)pWidget->pUser; 630 size_t i; 631 632 // destroy the server 633 WinDestroyWindow(pSysTrayData->hwndServer); 634 pSysTrayData->hwndServer = NULLHANDLE; 635 636 // free all system tray data 637 for (i = 0; i < pSysTrayData->cIcons; ++i) 638 FreeIconData(&pSysTrayData->pIcons[i]); 639 pSysTrayData->cIcons = 0; 640 free(pSysTrayData->pIcons); 641 pSysTrayData->pIcons = NULL; 642 643 // make sure we remove the check alive timer 644 WgtXSysTrayUpdateAfterIconAddRemove(pWidget); 645 646 free(pSysTrayData); 945 946 // stop the check alive timer 947 WinStopTimer(pWidget->habWidget, pSysTrayData->hwndServer, 948 TID_CHECKALIVE); 949 950 FreeSysTrayData(pSysTrayData); 647 951 pWidget->pUser = NULL; 648 952 … … 680 984 break; */ 681 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 682 1015 default: 683 1016 break; … … 713 1046 } 714 1047 715 if (pSysTrayData->pIcons != NULL) 716 { 717 // ask XCenter to take our new size into account (this will also 718 // invalidate us). If pIcons is NULL it means that we are in WM_DESTROY, 719 // in which case XCenter will do everything for us 720 WinPostMsg(pWidget->pGlobals->hwndClient, 721 XCM_REFORMAT, 722 (MPARAM)XFMF_GETWIDGETSIZES, 723 0); 724 } 1048 // ask XCenter to take our new size into account (this will also 1049 // invalidate us) 1050 WinPostMsg(pWidget->pGlobals->hwndClient, 1051 XCM_REFORMAT, 1052 (MPARAM)XFMF_GETWIDGETSIZES, 1053 0); 725 1054 } 726 1055 … … 767 1096 LOGF(("SYSTRAYCMD_ADDICON\n")); 768 1097 LOGF((" hwnd %x\n", pCtlData->hwndSender)); 769 LOGF((" u lId %ld\n", pCtlData->u.icon.ulId));1098 LOGF((" uId)); 770 1099 LOGF((" hIcon %x\n", pCtlData->u.icon.hIcon)); 771 1100 … … 785 1114 786 1115 pData = FindIconData(pSysTrayData, pCtlData->hwndSender, 787 pCtlData->u.icon.u lId, &i);1116 pCtlData->u.icon.uId, &i); 788 1117 if (pData) 789 1118 { … … 825 1154 826 1155 pData = &pSysTrayData->pIcons[i]; 1156 1157 827 1158 pData->hwnd = pCtlData->hwndSender; 828 pData->u lId = pCtlData->u.icon.ulId;1159 pData->uId; 829 1160 pData->hIcon = hIcon; 830 1161 pData->ulMsgId = pCtlData->u.icon.ulMsgId; … … 844 1175 LOGF(("SYSTRAYCMD_REMOVEICON\n")); 845 1176 LOGF((" hwnd %x\n", pCtlData->hwndSender)); 846 LOGF((" u lId %ld\n", pCtlData->u.icon.ulId));1177 LOGF((" uId)); 847 1178 848 1179 pCtlData->bAcknowledged = TRUE; 849 1180 850 1181 pData = FindIconData(pSysTrayData, pCtlData->hwndSender, 851 pCtlData->u.icon.u lId, &i);1182 pCtlData->u.icon.uId, &i); 852 1183 if (pData) 853 1184 { … … 893 1224 { 894 1225 PSYSTRAYDATA pSysTrayData = (PSYSTRAYDATA)pWidget->pUser; 1226 1227 1228 895 1229 896 1230 if (usTimerId == TID_CHECKALIVE) … … 904 1238 if (!WinIsWindow(pWidget->habWidget, pSysTrayData->pIcons[i].hwnd)) 905 1239 { 1240 1241 906 1242 LOGF(("Removing icon of dead window!\n")); 907 LOGF((" hwnd %x\n", pSysTrayData->pIcons[i].hwnd)); 908 LOGF((" ulId %ld\n", pSysTrayData->pIcons[i].ulId)); 909 LOGF((" hIcon %x\n", pSysTrayData->pIcons[i].hIcon)); 1243 LOGF((" hwnd %x\n", pData->hwnd)); 1244 LOGF((" usId %ld\n", pData->usId)); 1245 LOGF((" hIcon %x\n", pData->hIcon)); 1246 1247 // free memory blocks from the pool allocated for this client 1248 ulMemPoolMax = pMemPoolHdr->ulBeyond; 1249 if (ulMemPoolMax > pMemPoolHdr->ulNeedsCommit) 1250 ulMemPoolMax = pMemPoolHdr->ulNeedsCommit; 1251 ulMemPoolMax -= sizeof(MEMPOOLBLK); 1252 1253 pMemPoolBlk = pMemPoolHdr->aBlocks; 1254 while ((ULONG)pMemPoolBlk <= ulMemPoolMax) 1255 { 1256 if (pMemPoolBlk->hwnd == pData->hwnd) 1257 { 1258 LOGF((" freeing memory block %p\n", pMemPoolBlk)); 1259 __atomic_cmpxchg32((uint32_t *)&pMemPoolBlk->hwnd, 1260 NULLHANDLE, hwnd); 1261 } 1262 ++pMemPoolBlk; 1263 } 910 1264 911 1265 bAnyDead = TRUE; 912 FreeIconData( &pSysTrayData->pIcons[i]);913 // hwnd is NULLHANDLE here1266 FreeIconData(); 1267 // hwnd is NULLHANDLE here 914 1268 } 915 1269 } … … 1128 1482 } 1129 1483 1484 1485 1486 1487 1488 1489 1490 1130 1491 // no error: 1131 1492 // return widget classes array
Note:
See TracChangeset
for help on using the changeset viewer.