Changeset 269 for trunk/src/3rdparty/os2/xsystray/xsystray.c
- Timestamp:
- Oct 30, 2009, 2:27:42 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/3rdparty/os2/xsystray/xsystray.c
r268 r269 133 133 typedef struct 134 134 { 135 HWND hwndServer; 136 // systtem tray server window handle 135 137 LONG lIconWidth; 136 138 // system icon width in px … … 148 150 } SYSTRAYDATA, *PSYSTRAYDATA; 149 151 152 #define ICONARRAY_GROW 4 153 // number of element the icon array is increased by when there is no 154 // space for the newly added icon 155 150 156 static ULONG QWL_USER_SERVER_DATA = 0; 151 157 // offset to the PXCENTERWIDGET pointer in the widget data array … … 303 309 pData->pszToolTip = NULL; 304 310 } 311 } 312 313 /* 314 *@@ FindIconData: 315 * Searches for the icon with the given identity. Returns NULL if not 316 * found. 317 */ 318 319 static 320 PICONDATA FindIconData(PSYSTRAYDATA pSysTrayData, 321 HWND hwnd, // in: associated window handle 322 ULONG ulId, // in: icon ID 323 size_t *pIdx) // out: index of the icon in the icon array 324 // (optional, may be NULL) 325 { 326 size_t i; 327 for (i = 0; i < pSysTrayData->cIcons; ++i) 328 { 329 if (pSysTrayData->pIcons[i].hwnd == hwnd && 330 pSysTrayData->pIcons[i].ulId == ulId) 331 { 332 if (pIdx) 333 *pIdx = i; 334 return &pSysTrayData->pIcons[i]; 335 } 336 } 337 338 if (pIdx) 339 *pIdx = i; 340 return NULL; 305 341 } 306 342 … … 492 528 */ 493 529 530 static 494 531 MRESULT EXPENTRY fnwpXSysTray(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2) 495 532 { … … 539 576 pSysTrayData->lIconHeight = WinQuerySysValue(HWND_DESKTOP, SV_CYICON) / 2; 540 577 pSysTrayData->lIconPad = pSysTrayData->lIconHeight / 8; 541 pSysTrayData->cIconsMax = 4;578 pSysTrayData->cIconsMax = ICONARRAY_GROW; 542 579 pSysTrayData->pIcons = malloc(sizeof(*pSysTrayData->pIcons) * 543 580 pSysTrayData->cIconsMax); … … 548 585 } 549 586 pSysTrayData->cIcons = 0; 550 pWidget->pUser = pSysTrayData;551 587 552 588 // create the "server" window (note that we pass the XCENTERWIDGET 553 589 // pointer on to it) 554 HWNDhwndServer =590 pSysTrayData->hwndServer = 555 591 WinCreateWindow(HWND_DESKTOP, WNDCLASS_WIDGET_XSYSTRAY_SERVER, 556 592 NULL, WS_MINIMIZED, … … 558 594 HWND_DESKTOP, HWND_BOTTOM, 559 595 0, mp1, NULL); 560 if (hwndServer == NULLHANDLE) 596 if (pSysTrayData->hwndServer == NULLHANDLE) 597 { 598 free(pSysTrayData->pIcons); 599 free(pSysTrayData); 561 600 break; 601 } 602 603 pWidget->pUser = pSysTrayData; 562 604 563 605 mrc = FALSE; // confirm success … … 623 665 624 666 /* 667 *@@ WgtXSysTrayUpdateAfterIconAddRemove: 668 * Name says it all. 669 */ 670 671 static 672 VOID WgtXSysTrayUpdateAfterIconAddRemove(PXCENTERWIDGET pWidget) 673 { 674 PSYSTRAYDATA pSysTrayData = (PSYSTRAYDATA)pWidget->pUser; 675 676 if (pSysTrayData->cIcons == 1) 677 { 678 // start a timer to perform "is window alive" checks 679 WinStartTimer(pWidget->habWidget, pSysTrayData->hwndServer, 680 TID_CHECKALIVE, 681 TID_CHECKALIVE_TIMEOUT); 682 } 683 else 684 if (pSysTrayData->cIcons == 0) 685 { 686 // stop the check alive timer 687 WinStopTimer(pWidget->habWidget, pSysTrayData->hwndServer, 688 TID_CHECKALIVE); 689 } 690 691 // ask XCenter to take our new size into account 692 // (this will also invalidate us) 693 WinPostMsg(pWidget->pGlobals->hwndClient, 694 XCM_REFORMAT, 695 (MPARAM)XFMF_GETWIDGETSIZES, 696 0); 697 } 698 699 /* 625 700 *@@ WgtXSysTrayControl: 626 701 * implementation for WM_XST_CONTROL in fnwpXSysTrayServer. … … 659 734 POINTERINFO Info; 660 735 HPOINTER hIcon = NULLHANDLE; 736 size_t i; 737 PICONDATA pData; 661 738 662 739 LOGF(("SYSTRAYCMD_ADDICON\n")); 663 LOGF(("hIcon %x\n", pCtlData->u.icon.hIcon)); 740 LOGF((" hwnd %x\n", pCtlData->hwndSender)); 741 LOGF((" ulId %ld\n", pCtlData->u.icon.ulId)); 742 LOGF((" hIcon %x\n", pCtlData->u.icon.hIcon)); 664 743 665 744 pCtlData->bAcknowledged = TRUE; … … 677 756 } 678 757 679 // @todo just testing.... 680 if (pSysTrayData->pIcons[0].hIcon != NULLHANDLE) 681 WinDestroyPointer(pSysTrayData->pIcons[0].hIcon); 682 pSysTrayData->cIcons = 1; 683 pSysTrayData->pIcons[0].hwnd = pCtlData->hwndSender; 684 pSysTrayData->pIcons[0].ulId = pCtlData->u.icon.ulId; 685 pSysTrayData->pIcons[0].hIcon = hIcon; 686 pSysTrayData->pIcons[0].ulMsgId = pCtlData->u.icon.ulMsgId; 687 688 // ask XCenter to take our new size into account 689 // (this will also invalidate us) 690 WinPostMsg(pWidget->pGlobals->hwndClient, 691 XCM_REFORMAT, 692 (MPARAM)XFMF_GETWIDGETSIZES, 693 0); 694 695 if (pSysTrayData->cIcons == 1) 758 pData = FindIconData(pSysTrayData, pCtlData->hwndSender, 759 pCtlData->u.icon.ulId, &i); 760 if (pData) 696 761 { 697 // start a timer to perform "is window alive" checks 698 WinStartTimer(pWidget->habWidget, hwnd, 699 TID_CHECKALIVE, 700 TID_CHECKALIVE_TIMEOUT); 762 LOGF((" Updating hIcon %x\n", hIcon)); 763 764 WinDestroyPointer(pData->hIcon); 765 pData->hIcon = hIcon; 766 pData->ulMsgId = pCtlData->u.icon.ulMsgId; 767 768 // we didn't change the number of icons so simply invalidate 769 WinInvalidateRect(pWidget->hwndWidget, NULL, FALSE); 701 770 } 771 else 772 { 773 LOGF((" Adding new hIcon %x\n", hIcon)); 774 775 if (pSysTrayData->cIcons == pSysTrayData->cIconsMax) 776 { 777 PICONDATA pNewIcons; 778 779 LOGF((" Allocating more memory (new icon count is %u)!\n", 780 pSysTrayData->cIcons + 1)); 781 782 pNewIcons = realloc(pSysTrayData->pIcons, 783 sizeof(*pSysTrayData->pIcons) * 784 pSysTrayData->cIconsMax + ICONARRAY_GROW); 785 if (pNewIcons == NULL) 786 { 787 WinDestroyPointer(hIcon); 788 break; 789 } 790 791 pSysTrayData->pIcons = pNewIcons; 792 pSysTrayData->cIconsMax += ICONARRAY_GROW; 793 } 794 795 i = pSysTrayData->cIcons; 796 ++pSysTrayData->cIcons; 797 798 pData = &pSysTrayData->pIcons[i]; 799 pData->hwnd = pCtlData->hwndSender; 800 pData->ulId = pCtlData->u.icon.ulId; 801 pData->hIcon = hIcon; 802 pData->ulMsgId = pCtlData->u.icon.ulMsgId; 803 804 WgtXSysTrayUpdateAfterIconAddRemove(pWidget); 805 } 702 806 703 807 brc = TRUE; 704 808 } 809 break; 810 811 case SYSTRAYCMD_REMOVEICON: 812 { 813 size_t i; 814 PICONDATA pData; 815 816 LOGF(("SYSTRAYCMD_REMOVEICON\n")); 817 LOGF((" hwnd %x\n", pCtlData->hwndSender)); 818 LOGF((" ulId %ld\n", pCtlData->u.icon.ulId)); 819 820 pCtlData->bAcknowledged = TRUE; 821 822 pData = FindIconData(pSysTrayData, pCtlData->hwndSender, 823 pCtlData->u.icon.ulId, &i); 824 if (pData) 825 { 826 LOGF((" Removing hIcon %x\n", pData->hIcon)); 827 828 FreeIconData(pData); 829 830 --pSysTrayData->cIcons; 831 if (pSysTrayData->cIcons > 0) 832 { 833 memcpy(&pSysTrayData->pIcons[i], 834 &pSysTrayData->pIcons[i + 1], 835 sizeof(*pSysTrayData->pIcons) * (pSysTrayData->cIcons - i)); 836 } 837 838 WgtXSysTrayUpdateAfterIconAddRemove(pWidget); 839 840 brc = TRUE; 841 } 842 else 843 LOGF((" Icon not found!\n")); 844 } 845 break; 705 846 706 847 default: … … 735 876 if (!WinIsWindow(pWidget->habWidget, pSysTrayData->pIcons[i].hwnd)) 736 877 { 878 LOGF(("Removing icon of dead window!\n")); 879 LOGF((" hwnd %x\n", pSysTrayData->pIcons[i].hwnd)); 880 LOGF((" ulId %ld\n", pSysTrayData->pIcons[i].ulId)); 881 LOGF((" hIcon %x\n", pSysTrayData->pIcons[i].hIcon)); 882 737 883 bAnyDead = TRUE; 738 884 FreeIconData(&pSysTrayData->pIcons[i]); … … 761 907 } 762 908 763 if (pSysTrayData->cIcons == 0) 764 { 765 // stop the check alive timer 766 WinStopTimer(pWidget->habWidget, hwnd, 767 TID_CHECKALIVE); 768 } 769 770 // ask XCenter to take our new size into account 771 // (this will also invalidate us) 772 WinPostMsg(pWidget->pGlobals->hwndClient, 773 XCM_REFORMAT, 774 (MPARAM)XFMF_GETWIDGETSIZES, 775 0); 909 WgtXSysTrayUpdateAfterIconAddRemove(pWidget); 776 910 } 777 911 }
Note:
See TracChangeset
for help on using the changeset viewer.