Changeset 269 for trunk/src


Ignore:
Timestamp:
Oct 30, 2009, 2:27:42 AM (16 years ago)
Author:
Dmitry A. Kuminov
Message:

3rdparty: os2/xsystray: Implemented adding and removing icons.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/3rdparty/os2/xsystray/xsystray.c

    r268 r269  
    133133typedef struct
    134134{
     135    HWND        hwndServer;
     136                // systtem tray server window handle
    135137    LONG        lIconWidth;
    136138                // system icon width in px
     
    148150} SYSTRAYDATA, *PSYSTRAYDATA;
    149151
     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
    150156static ULONG QWL_USER_SERVER_DATA = 0;
    151157             // offset to the PXCENTERWIDGET pointer in the widget data array
     
    303309        pData->pszToolTip = NULL;
    304310    }
     311}
     312
     313/*
     314 *@@ FindIconData:
     315 *      Searches for the icon with the given identity. Returns NULL if not
     316 *      found.
     317 */
     318
     319static
     320PICONDATA 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;
    305341}
    306342
     
    492528 */
    493529
     530static
    494531MRESULT EXPENTRY fnwpXSysTray(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
    495532{
     
    539576            pSysTrayData->lIconHeight = WinQuerySysValue(HWND_DESKTOP, SV_CYICON) / 2;
    540577            pSysTrayData->lIconPad = pSysTrayData->lIconHeight / 8;
    541             pSysTrayData->cIconsMax = 4;
     578            pSysTrayData->cIconsMax = ICONARRAY_GROW;
    542579            pSysTrayData->pIcons = malloc(sizeof(*pSysTrayData->pIcons) *
    543580                                          pSysTrayData->cIconsMax);
     
    548585            }
    549586            pSysTrayData->cIcons = 0;
    550             pWidget->pUser = pSysTrayData;
    551587
    552588            // create the "server" window (note that we pass the XCENTERWIDGET
    553589            // pointer on to it)
    554             HWND hwndServer =
     590            pSysTrayData->hwndServer =
    555591                WinCreateWindow(HWND_DESKTOP, WNDCLASS_WIDGET_XSYSTRAY_SERVER,
    556592                                NULL, WS_MINIMIZED,
     
    558594                                HWND_DESKTOP, HWND_BOTTOM,
    559595                                0, mp1, NULL);
    560             if (hwndServer == NULLHANDLE)
     596            if (pSysTrayData->hwndServer == NULLHANDLE)
     597            {
     598                free(pSysTrayData->pIcons);
     599                free(pSysTrayData);
    561600                break;
     601            }
     602
     603            pWidget->pUser = pSysTrayData;
    562604
    563605            mrc = FALSE; // confirm success
     
    623665
    624666/*
     667 *@@ WgtXSysTrayUpdateAfterIconAddRemove:
     668 *      Name says it all.
     669 */
     670
     671static
     672VOID 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/*
    625700 *@@ WgtXSysTrayControl:
    626701 *      implementation for WM_XST_CONTROL in fnwpXSysTrayServer.
     
    659734            POINTERINFO Info;
    660735            HPOINTER hIcon = NULLHANDLE;
     736            size_t i;
     737            PICONDATA pData;
    661738
    662739            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));
    664743
    665744            pCtlData->bAcknowledged = TRUE;
     
    677756            }
    678757
    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)
    696761            {
    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);
    701770            }
     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            }
    702806
    703807            brc = TRUE;
    704808        }
     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;
    705846
    706847        default:
     
    735876            if (!WinIsWindow(pWidget->habWidget, pSysTrayData->pIcons[i].hwnd))
    736877            {
     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
    737883                bAnyDead = TRUE;
    738884                FreeIconData(&pSysTrayData->pIcons[i]);
     
    761907            }
    762908
    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);
    776910        }
    777911    }
Note: See TracChangeset for help on using the changeset viewer.