Ignore:
Timestamp:
Jan 3, 2001, 10:05:57 PM (25 years ago)
Author:
umoeller
Message:

Reworked tooltip.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/helpers/cctl_tooltip.c

    r14 r19  
    182182            qmsg.mp1 = mp1;
    183183            qmsg.mp2 = mp2;
    184             /* WinQueryMsgPos(pst->hab,
    185                            &qmsg.ptl);
    186             qmsg.time = WinQueryMsgTime(pst->hab); */
    187             // _Pmpf(("ctl_fnwpSubclassedTool: sending TTM_RELAYEVENT"));
     184            _Pmpf((__FUNCTION__ ": sending TTM_RELAYEVENT"));
    188185            WinSendMsg(pst->hwndTooltip,
    189186                       TTM_RELAYEVENT,
     
    194191
    195192        case WM_DESTROY:
    196             mrc = (pst->pfnwpOrig)(hwndTool, msg, mp1, mp2);
    197193            lstRemoveItem(G_pllSubclassedTools, pst);         // this frees the item
    198194            if (lstCountItems(G_pllSubclassedTools) == 0)
     
    201197                lstFree(G_pllSubclassedTools);
    202198                G_pllSubclassedTools = NULL;
     199                _Pmpf((__FUNCTION__ ": removed hwnd 0x%lX", hwndTool));
    203200            }
     201            mrc = (pst->pfnwpOrig)(hwndTool, msg, mp1, mp2);
    204202        break;
    205203
     
    240238
    241239            lstAppendItem(G_pllSubclassedTools, pst);
     240            _Pmpf((__FUNCTION__ ": subclassed hwnd 0x%lX", hwndTool));
    242241        }
    243242    }
     
    284283    BOOL        fIsVisible;         // TRUE if tooltip is visible
    285284
    286     CHAR        szTextBuf[256];     // static buffer for copying/loading strings
     285    // CHAR        szTextBuf[256];     // static buffer for copying/loading strings
    287286} TOOLTIPDATA, *PTOOLTIPDATA;
    288287
     
    435434                    BOOL fShow)  // if TRUE: show, else: HIDE
    436435{
     436    _Pmpf((__FUNCTION__ ": fShow %d", fShow));
    437437    if (fShow)
    438438    {
     
    458458           )
    459459        {
    460             pttd->pszPaintText = NULL;
    461460            // mouse not moved since timer was started:
    462461            // find the current TOOLINFO
     462            _Pmpf((__FUNCTION__ ": mouse not moved... pttd->ptiMouseOver 0x%lX", pttd->ptiMouseOver));
    463463            if (pttd->ptiMouseOver)
    464464            {
     
    470470                           (MPARAM)0,
    471471                           (MPARAM)&tiTemp);
    472                 if (tiTemp.lpszText)
    473                     pttd->pszPaintText = strdup(tiTemp.lpszText);
     472                if (tiTemp.pszText)
     473                    pttd->pszPaintText = strdup(tiTemp.pszText);
    474474                else
    475475                    pttd->pszPaintText = NULL;
    476476            }
     477
     478            _Pmpf((__FUNCTION__ ": pttd->pszPaintText %s",
     479                    (pttd->pszPaintText) ? pttd->pszPaintText : "NULL"));
    477480
    478481            if (pttd->pszPaintText)
     
    499502
    500503                // calc x and y pos of tooltip
    501                 if (pttd->ptiMouseOver->uFlags & TTF_CENTERTIP)
     504                if (    (pttd->ptiMouseOver->ulFlags & TTF_CENTERBELOW)
     505                     || (pttd->ptiMouseOver->ulFlags & TTF_CENTERABOVE)
     506                   )
    502507                {
    503508                    // center below control:
    504                     if (pttd->ptiMouseOver->uFlags & TTF_IDISHWND)
    505                     {
    506                         SWP swpTool;
    507                         WinQueryWindowPos(pttd->ptiMouseOver->uId, &swpTool);
    508                         ptlTooltip.x = swpTool.x;
    509                         ptlTooltip.y = swpTool.y;
    510                         // convert x, y to desktop points
    511                         WinMapWindowPoints(WinQueryWindow(pttd->ptiMouseOver->uId,
    512                                                           QW_PARENT), // hwndFrom
    513                                            HWND_DESKTOP,            // hwndTo
    514                                            &ptlTooltip,
    515                                            1);
    516                         ptlTooltip.x += ((swpTool.cx - cx) / 2L);
     509                    SWP swpTool;
     510                    WinQueryWindowPos(pttd->ptiMouseOver->hwndTool, &swpTool);
     511                    ptlTooltip.x = swpTool.x;
     512                    ptlTooltip.y = swpTool.y;
     513                    // convert x, y to desktop points
     514                    WinMapWindowPoints(WinQueryWindow(pttd->ptiMouseOver->hwndTool,
     515                                                      QW_PARENT), // hwndFrom
     516                                       HWND_DESKTOP,            // hwndTo
     517                                       &ptlTooltip,
     518                                       1);
     519                    ptlTooltip.x += ((swpTool.cx - cx) / 2L);
     520                    if (pttd->ptiMouseOver->ulFlags & TTF_CENTERBELOW)
    517521                        ptlTooltip.y -= cy;
    518                     }
    519                     // else xxx rectangle def
     522                    else
     523                        ptlTooltip.y += swpTool.cy;
    520524                }
    521525                else
     
    594598                                                     TOOLTIP_ID_TIMER_AUTOPOP,
    595599                                                     pttd->ulTimeoutAutopop);
    596             }
    597         }
     600            } // end if (pttd->pszPaintText)
     601        } // end if (    (ptlPointer.x == pttd->ptlPointerLast.x)...
    598602    } // end if (mp1)
    599603    else
     
    847851                    case TOOLTIP_ID_TIMER_INITIAL:
    848852                        // _Pmpf(("WM_TIMER: Stopping initial timer: %d", usTimer));
     853                        _Pmpf((__FUNCTION__ ": TOOLTIP_ID_TIMER_INITIAL"));
    849854                        WinStopTimer(pttd->hab,
    850855                                     hwndTooltip,
     
    944949             *      the address of a TOOLINFO structure, which provides
    945950             *      information the tooltip control needs to display text
    946              *      for the tool. The cbSize member is required and must
    947              *      specify the size of the structure.
     951             *      for the tool.
    948952             *
    949953             *      A tooltip control supports tools implemented as windows
     
    952956             *
    953957             *      --  When you add a tool implemented as a rectangular area, the
    954              *          "hwnd" member of TOOLINFO must specify the handle of the
    955              *          window that contains the area, and the "rect" member must
     958             *          "hwndToolOwner" member of TOOLINFO must specify the handle
     959             *          of the window that contains the area, and the "rect" member must
    956960             *          specify the client coordinates of the area's bounding
    957              *          rectangle. In addition, the "uId" member must specify the
    958              *          application-defined identifier for the tool.
    959              *
    960              *      --  When you add a tool implemented as a window, the "uId"
     961             *          rectangle. ### not implemented yet
     962             *
     963             *      --  When you add a tool implemented as a window, the "hwndTool"
    961964             *          member of TOOLINFO must contain the window handle of the
    962              *          tool. Also, the "uFlags" member must specify the TTF_IDISHWND
    963              *          value, which tells the tooltip control to interpret the "uId"
    964              *          member as a window handle.
    965              *
    966              *      When you add a tool to a tooltip control, the "lpszText"
    967              *      member of the TOOLINFO structure must specify the address
    968              *      of the string to display for the tool. You can change the
    969              *      text any time after adding the tool by using the
    970              *      TTM_UPDATETIPTEXT message.
    971              *
    972              *      If the high-order word of lpszText is zero, the low-order
    973              *      word must be the identifier of a string resource. When
    974              *      the tooltip control needs the text, the system loads
    975              *      the specified string resource from the application instance
    976              *      identified by the "hinst" member of TOOLINFO.
    977              *
    978              *      If you specify the LPSTR_TEXTCALLBACK value in the lpszText
    979              *      member, the tooltip control notifies the window specified
    980              *      in the hwnd member of TOOLINFO whenever the tooltip control
    981              *      needs to display text for the tool. The tooltip control
    982              *      sends the TTN_NEEDTEXT notification message to the window.
     965             *          tool. hwndToolOwner should be the owner of the tool.
     966             *
     967             *      When you add a tool to a tooltip control, the "pszText"
     968             *      member of the TOOLINFO structure must specify the string
     969             *      to display for the tool. You can change the text any time
     970             *      after adding the tool by using the TTM_UPDATETIPTEXT message.
     971             *
     972             *      If you specify the PSZ_TEXTCALLBACK value in the pszText
     973             *      member, whenever the tooltip control needs the text for the
     974             *      tool, it sends a WM_CONTROL message to hwndToolOwner with
     975             *      the TTN_NEEDTEXT notification code.
     976             *
    983977             *      The message includes the address of a TOOLTIPTEXT structure,
    984              *      which contains the window handle as well as the
    985              *      application-defined identifier for the tool. The window
    986              *      examines the structure to determine the tool for which text
    987              *      is needed, and it fills the appropriate structure members
    988              *      with information that the tooltip control needs to display
    989              *      the string.
    990              *
    991              *      Many applications create toolbars containing tools that
    992              *      correspond to menu commands. For such tools, it is convenient
    993              *      for the tooltip control to display the same text as the
    994              *      corresponding menu item. Windows automatically strips the
    995              *      ampersand (&) accelerator characters from all strings passed
    996              *      to a tooltip control, unless the control has the TTS_NOPREFIX style.
    997              *
    998              *      OS/2 note: This implementation does this too, but will not
    999              *      strip the ampersand, but the tilde (~) character.
     978             *      which contains the window handle of the tool. You can then
     979             *      fill the TOOLTIPTEXT structure with the tool text.
    1000980             *
    1001981             *      To retrieve the text for a tool, use the TTM_GETTEXT message.
     
    1010990                    if (ptiNew)
    1011991                    {
    1012                         memcpy(ptiNew, ptiPassed, ptiPassed->cbSize);
     992                        memcpy(ptiNew, ptiPassed, sizeof(TOOLINFO));
    1013993                        lstAppendItem(&pttd->llTools,
    1014994                                      ptiNew);
    1015995
    1016                         if (ptiPassed->uFlags & TTF_IDISHWND)
    1017                             if (ptiPassed->uFlags & TTF_SUBCLASS)
    1018                                 SubclassToolForToolinfo(hwndTooltip,
    1019                                                         ptiPassed->uId);
     996                        if (ptiPassed->ulFlags & TTF_SUBCLASS)
     997                            SubclassToolForToolinfo(hwndTooltip,
     998                                                    ptiPassed->hwndTool);
    1020999
    10211000                        mrc = (MPARAM)TRUE;
     
    10461025                    {
    10471026                        PTOOLINFO ptiThis = (PTOOLINFO)pToolNode->pItemData;
    1048                         if (    (ptiThis->hwnd == ptiSearch->hwnd)
    1049                              && (ptiThis->uId == ptiSearch->uId)
     1027                        if (    (ptiThis->hwndToolOwner == ptiSearch->hwndToolOwner)
     1028                             && (ptiThis->hwndTool == ptiSearch->hwndTool)
    10501029                           )
    10511030                        {
     
    11781157                    {
    11791158                        PTOOLINFO pti = (PTOOLINFO)pToolNode->pItemData;
    1180                         if (    (pti->uFlags &TTF_IDISHWND)
    1181                              && (pti->uId == pqmsg->hwnd)
    1182                            )
     1159                        if (pti->hwndTool == pqmsg->hwnd)
    11831160                        {
     1161                            _Pmpf((__FUNCTION__ ": found tool"));
    11841162                            pttd->ptiMouseOver = pti;
    11851163                            break;
     
    11961174                    {
    11971175                        // mouse pos changed:
     1176                        // hide tooltip
    11981177                        WinPostMsg(hwndTooltip,
    11991178                                   TTM_SHOWTOOLTIPNOW,
     
    12021181                        memcpy(&pttd->ptlPointerLast, &ptlPointer, sizeof(POINTL));
    12031182
     1183                        _Pmpf((__FUNCTION__ ": pttd->ptiMouseOver: 0x%lX", pttd->ptiMouseOver));
     1184                        _Pmpf((__FUNCTION__ ": pttd->fIsActive: 0x%lX", pttd->fIsActive));
    12041185                        if (    (pttd->ptiMouseOver)
    12051186                             && (pttd->fIsActive)
     
    13031284                PTOOLINFO pti = (PTOOLINFO)mp2;
    13041285
    1305                 if (pti->lpszText == LPSTR_TEXTCALLBACK)
     1286                if (pti->pszText == PSZ_TEXTCALLBACK)
    13061287                {
    13071288                    // TTN_NEEDTEXT notification desired:
    13081289                    // compose values for that msg
    1309                     TOOLTIPTEXT     ttt;
    1310                     memset(&ttt, 0, sizeof(ttt));
    1311                     ttt.hdr.hwndFrom = hwndTooltip;
    1312 
    1313                     if (pti->uFlags & TTF_IDISHWND)
    1314                         // HWND mode:
    1315                         ttt.uFlags = TTF_IDISHWND;
    1316                     ttt.hdr.idFrom = pti->uId;      // HWND or app-def'd ID
    1317                     ttt.hdr.code = TTN_NEEDTEXT;
    1318                     WinSendMsg(pti->hwnd,
     1290                    TOOLTIPTEXT ttt = {0};
     1291                    _Pmpf(("TTM_GETTEXT: LPSTR_TEXTCALLBACK"));
     1292                    ttt.hwndTooltip = hwndTooltip;
     1293                    ttt.hwndTool = pti->hwndTool;
     1294                    WinSendMsg(pti->hwndTool,
    13191295                               WM_CONTROL,
    13201296                               MPFROM2SHORT(pttd->ulTooltipID,  // tooltip control wnd ID
     
    13241300                    // in case of error: set lpszText to NULL; this
    13251301                    // is not specified in the docs however.
    1326                     pti->lpszText = NULL;
    1327 
    1328                     if (ttt.szText[0] != 0)
     1302                    pti->pszText = NULL;
     1303
     1304                    switch (ttt.ulFormat)
    13291305                    {
    1330                         // owner copied string to ttt.szText:
    1331                         // copy that to our buffer in the window words
    1332                         // to make it static
    1333                         strcpy(pttd->szTextBuf, ttt.szText);    // maxlen is 80 chars
    1334                         pti->lpszText = pttd->szTextBuf;
    1335                     }
    1336                     else if (   (ttt.lpszText != 0)
    1337                              && (((ULONG)ttt.lpszText & 0xFFFF0000) != 0)
    1338                             )
    1339                         // owner specified pointer to static buffer somewhere:
    1340                         pti->lpszText = ttt.lpszText;
    1341                     else if ((ULONG)ttt.lpszText & 0xFFFF)
    1342                     {
    1343                         if (WinLoadString(pttd->hab,
    1344                                           ttt.hinst,
    1345                                           (ULONG)ttt.lpszText,
    1346                                           sizeof(pttd->szTextBuf),  // 256 chars
    1347                                           pttd->szTextBuf))
    1348                             pti->lpszText = pttd->szTextBuf;
     1306                        case TTFMT_PSZ:
     1307                            if (ttt.pszText)
     1308                                pti->pszText = ttt.pszText;
     1309                        break;
     1310
     1311                        case TTFMT_STRINGRES:
     1312                            // ### not supported yet
     1313                        break;
    13491314                    }
    13501315                }
     
    14401405                    if (ptiFound)
    14411406                    {
    1442                         memcpy(ptiTarget, ptiFound, ptiTarget->cbSize);
     1407                        memcpy(ptiTarget, ptiFound, sizeof(TOOLINFO));
    14431408                        mrc = (MRESULT)TRUE;
    14441409                    }
     
    14681433                    if (pttd->ptiMouseOver)
    14691434                    {
    1470                         memcpy(ptiTarget, pttd->ptiMouseOver, ptiTarget->cbSize);
     1435                        memcpy(ptiTarget, pttd->ptiMouseOver, sizeof(TOOLINFO));
    14711436                        mrc = (MPARAM)TRUE;
    14721437                    }
     
    15121477                    {
    15131478                        PTOOLINFO ptiThis = (PTOOLINFO)pToolNode->pItemData;
    1514                         if (    (ptiThis->hwnd == ptiSearch->hwnd)
    1515                              && (ptiThis->uId == ptiSearch->uId)
     1479                        if (    (ptiThis->hwndToolOwner == ptiSearch->hwndToolOwner)
     1480                             && (ptiThis->hwndTool == ptiSearch->hwndTool)
    15161481                           )
    15171482                        {
    15181483                            // found:
    1519                             memcpy(ptiSearch, ptiThis, ptiSearch->cbSize);
     1484                            memcpy(ptiSearch, ptiThis, sizeof(TOOLINFO));
    15201485                            mrc = (MPARAM)TRUE;
    15211486                            break;
     
    15551520
    15561521            case TTM_SHOWTOOLTIPNOW:
     1522                _Pmpf((__FUNCTION__ ": TTM_SHOWTOOLTIPNOW %d", mp1));
    15571523                TtmShowTooltip(hwndTooltip, pttd, (BOOL)mp1);
    15581524            break;
Note: See TracChangeset for help on using the changeset viewer.