Ignore:
Timestamp:
Jun 30, 1999, 5:52:19 PM (26 years ago)
Author:
cbratschi
Message:

unicode and other changes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/comctl32/tooltips.c

    r236 r252  
    1 /* $Id: tooltips.c,v 1.8 1999-06-28 15:46:27 cbratschi Exp $ */
     1/* $Id: tooltips.c,v 1.9 1999-06-30 15:52:18 cbratschi Exp $ */
    22/*
    33 * Tool tip control
     
    88 *
    99 * TODO:
    10  *   - Unicode support.
    1110 *   - Custom draw support.
    1211 *
     
    2019/* CB: Odin32 problems
    2120 - WM_NCCREATE not handled first -> title bar visible if WS_POPUP wasn't set before
     21 - CS_SAVEBITS: window movements are slow, bug in Open32?
    2222*/
    2323
     
    117117        } else if (ttnmdi.szText[0])
    118118        {
    119           lstrcpynAtoW(infoPtr->szTipText,ttnmdi.szText,MIN(INFOTIPSIZE-1,lstrlenA(ttnmdi.szText)));
     119          lstrcpynAtoW(infoPtr->szTipText,ttnmdi.szText,INFOTIPSIZE);
    120120          if (ttnmdi.uFlags & TTF_DI_SETITEM)
    121121          {
     
    131131        } else if (ttnmdi.lpszText != LPSTR_TEXTCALLBACKA)
    132132        {
    133           lstrcpynAtoW(infoPtr->szTipText,ttnmdi.lpszText,MIN(INFOTIPSIZE-1,lstrlenA(ttnmdi.lpszText)));
     133          lstrcpynAtoW(infoPtr->szTipText,ttnmdi.lpszText,INFOTIPSIZE);
    134134          if (ttnmdi.uFlags & TTF_DI_SETITEM)
    135135          {
     
    147147      {
    148148        /* the item is a usual (unicode) text */
    149         lstrcpynW(infoPtr->szTipText,toolPtr->lpszText,MIN(INFOTIPSIZE-1,lstrlenW(toolPtr->lpszText)));
     149        lstrcpynW(infoPtr->szTipText,toolPtr->lpszText,INFOTIPSIZE);
    150150      }
    151151    }
     
    160160
    161161static VOID
    162 TOOLTIPS_CalcTipSize (HWND hwnd,TOOLTIPS_INFO *infoPtr,LPSIZE lpSize)
     162TOOLTIPS_CalcTipRect (HWND hwnd,TOOLTIPS_INFO *infoPtr,TTTOOL_INFO *toolPtr,LPRECT lpRect)
    163163{
    164164    HDC hdc;
     
    166166    UINT uFlags = DT_EXTERNALLEADING | DT_CALCRECT;
    167167    RECT rc = {0,0,0,0};
     168    SIZE size;
    168169
    169170    if (infoPtr->nMaxTipWidth > -1)
     
    181182    ReleaseDC(hwnd,hdc);
    182183
    183     lpSize->cx = rc.right-rc.left+4+infoPtr->rcMargin.left+infoPtr->rcMargin.right;
    184     lpSize->cy = rc.bottom-rc.top+4+infoPtr->rcMargin.bottom+infoPtr->rcMargin.top;
    185 }
    186 
    187 
    188 static VOID
    189 TOOLTIPS_Show (HWND hwnd, TOOLTIPS_INFO *infoPtr)
    190 {
    191     TTTOOL_INFO *toolPtr;
    192     RECT rect;
    193     SIZE size;
    194     HDC  hdc;
    195     NMHDR  hdr;
    196 
    197     if (infoPtr->nTool == -1)
    198     {
    199 //      TRACE (tooltips, "invalid tool (-1)!\n");
    200         return;
    201     }
    202 
    203     infoPtr->nCurrentTool = infoPtr->nTool;
    204 
    205 //    TRACE (tooltips, "Show tooltip pre %d!\n", infoPtr->nTool);
    206     TOOLTIPS_GetTipText(hwnd,infoPtr,infoPtr->nCurrentTool);
    207 
    208     if (infoPtr->szTipText[0] == '\0')
    209     {
    210         infoPtr->nCurrentTool = -1;
    211         return;
    212     }
    213 
    214 //    TRACE (tooltips, "Show tooltip %d!\n", infoPtr->nCurrentTool);
    215     toolPtr = &infoPtr->tools[infoPtr->nCurrentTool];
    216 
    217     hdr.hwndFrom = hwnd;
    218     hdr.idFrom = toolPtr->uId;
    219     hdr.code = TTN_SHOW;
    220     SendMessageA(toolPtr->hwnd,WM_NOTIFY,
    221                     (WPARAM)toolPtr->uId,(LPARAM)&hdr);
    222 
    223 //    TRACE (tooltips, "\"%s\"\n", debugstr_w(infoPtr->szTipText));
    224 
    225     TOOLTIPS_CalcTipSize (hwnd, infoPtr, &size);
    226 //    TRACE (tooltips, "size %d - %d\n", size.cx, size.cy);
    227 
    228     if (toolPtr->uFlags & TTF_CENTERTIP)
    229     {
    230         RECT rc;
    231 
    232         if (toolPtr->uFlags & TTF_IDISHWND)
    233             GetWindowRect ((HWND)toolPtr->uId, &rc);
    234         else
    235         {
    236             rc = toolPtr->rect;
    237             MapWindowPoints (toolPtr->hwnd, (HWND)0, (LPPOINT)&rc, 2);
    238         }
    239         rect.left = (rc.left + rc.right - size.cx) / 2;
    240         rect.top  = rc.bottom + 2;
    241     } else
    242     {
    243         GetCursorPos((LPPOINT)&rect);
    244         rect.top += 20;
    245     }
    246 
    247     /* FIXME: check position */
    248 
    249 //    TRACE (tooltips, "pos %d - %d\n", rect.left, rect.top);
    250 
    251     rect.right = rect.left + size.cx;
    252     rect.bottom = rect.top + size.cy;
    253 
    254     AdjustWindowRectEx (&rect,GetWindowLongA(hwnd, GWL_STYLE),
    255                         FALSE,GetWindowLongA(hwnd, GWL_EXSTYLE));
    256 
    257     SetWindowPos (hwnd,HWND_TOP,rect.left,rect.top,
    258                     rect.right-rect.left,rect.bottom-rect.top,
    259                     SWP_SHOWWINDOW | SWP_NOACTIVATE);
    260 
    261     /* repaint the tooltip */
    262     hdc = GetDC(hwnd);
    263     TOOLTIPS_Refresh(hwnd,hdc);
    264     ReleaseDC(hwnd,hdc);
    265 
    266     SetTimer (hwnd,ID_TIMERPOP,infoPtr->nAutoPopTime,0);
    267 }
    268 
    269 
    270 static VOID
    271 TOOLTIPS_Hide (HWND hwnd, TOOLTIPS_INFO *infoPtr)
    272 {
    273     TTTOOL_INFO *toolPtr;
    274     NMHDR hdr;
    275 
    276     if (infoPtr->nCurrentTool == -1)
    277         return;
    278 
    279     toolPtr = &infoPtr->tools[infoPtr->nCurrentTool];
    280 //    TRACE (tooltips, "Hide tooltip %d!\n", infoPtr->nCurrentTool);
    281     KillTimer (hwnd, ID_TIMERPOP);
    282 
    283     hdr.hwndFrom = hwnd;
    284     hdr.idFrom = toolPtr->uId;
    285     hdr.code = TTN_POP;
    286     SendMessageA (toolPtr->hwnd, WM_NOTIFY,
    287                     (WPARAM)toolPtr->uId, (LPARAM)&hdr);
    288 
    289     infoPtr->nCurrentTool = -1;
    290 
    291     SetWindowPos (hwnd, HWND_TOP, 0, 0, 0, 0,
    292                     SWP_NOZORDER | SWP_HIDEWINDOW | SWP_NOACTIVATE);
    293 }
    294 
    295 
    296 static VOID
    297 TOOLTIPS_TrackShow (HWND hwnd, TOOLTIPS_INFO *infoPtr)
    298 {
    299     TTTOOL_INFO *toolPtr;
    300     RECT rect;
    301     SIZE size;
    302     HDC  hdc;
    303     NMHDR hdr;
    304 
    305     if (infoPtr->nTrackTool == -1)
    306     {
    307 //    TRACE (tooltips, "invalid tracking tool (-1)!\n");
    308       return;
    309     }
    310 
    311 //    TRACE (tooltips, "show tracking tooltip pre %d!\n", infoPtr->nTrackTool);
    312 
    313     TOOLTIPS_GetTipText(hwnd,infoPtr,infoPtr->nTrackTool);
    314 
    315     if (infoPtr->szTipText[0] == '\0')
    316     {
    317       infoPtr->nTrackTool = -1;
    318       return;
    319     }
    320 
    321 //    TRACE (tooltips, "show tracking tooltip %d!\n", infoPtr->nTrackTool);
    322     toolPtr = &infoPtr->tools[infoPtr->nTrackTool];
    323 
    324     hdr.hwndFrom = hwnd;
    325     hdr.idFrom = toolPtr->uId;
    326     hdr.code = TTN_SHOW;
    327     SendMessageA(toolPtr->hwnd,WM_NOTIFY,(WPARAM)toolPtr->uId,(LPARAM)&hdr);
    328 
    329 //    TRACE (tooltips, "\"%s\"\n", debugstr_w(infoPtr->szTipText));
    330 
    331     TOOLTIPS_CalcTipSize(hwnd,infoPtr,&size);
    332 //    TRACE (tooltips, "size %d - %d\n", size.cx, size.cy);
     184    size.cx = rc.right-rc.left+4+infoPtr->rcMargin.left+infoPtr->rcMargin.right;
     185    size.cy = rc.bottom-rc.top+4+infoPtr->rcMargin.bottom+infoPtr->rcMargin.top;
     186
     187    //CB: optimize
    333188
    334189    if (toolPtr->uFlags & TTF_ABSOLUTE)
    335190    {
    336       rect.left = infoPtr->xTrackPos;
    337       rect.top  = infoPtr->yTrackPos;
     191      rc.left = infoPtr->xTrackPos;
     192      rc.top  = infoPtr->yTrackPos;
    338193
    339194      if (toolPtr->uFlags & TTF_CENTERTIP)
    340195      {
    341         rect.left -= (size.cx/2);
    342         rect.top  -= (size.cy/2);
     196        rc.left -= (size.cx/2);
     197        rc.top  -= (size.cy/2);
    343198      }
    344199    } else
     
    355210      }
    356211
    357       GetCursorPos ((LPPOINT)&rect);
    358       rect.top += 20;
    359 
    360212      if (toolPtr->uFlags & TTF_CENTERTIP)
    361213      {
    362         rect.left -= (size.cx / 2);
    363         rect.top  -= (size.cy / 2);
     214        if (infoPtr->bTrackActive)
     215        {
     216          GetCursorPos((LPPOINT)&rc);
     217          rc.top += 20;
     218          rc.left -= (size.cx / 2);
     219          rc.top  -= (size.cy / 2);
     220        } else
     221        {
     222          rc.left = (rcTool.left + rcTool.right-size.cx)/ 2;
     223          rc.top  = rcTool.bottom+2;
     224        }
     225
     226      } else
     227      {
     228        GetCursorPos((LPPOINT)&rc);
     229        rc.top += 20;
    364230      }
    365231
    366232      /* smart placement */
    367       if ((rect.left + size.cx > rcTool.left) && (rect.left < rcTool.right) &&
    368           (rect.top + size.cy > rcTool.top) && (rect.top < rcTool.bottom))
    369           rect.left = rcTool.right;
     233      if (infoPtr->bTrackActive)
     234      {
     235        if ((rc.left + size.cx > rcTool.left) && (rc.left < rcTool.right) &&
     236            (rc.top + size.cy > rcTool.top) && (rc.top < rcTool.bottom))
     237            rc.left = rcTool.right;
     238      }
    370239    }
    371240
    372241//    TRACE (tooltips, "pos %d - %d\n", rect.left, rect.top);
    373242
    374     rect.right = rect.left+size.cx;
    375     rect.bottom = rect.top+size.cy;
    376 
    377     AdjustWindowRectEx (&rect,GetWindowLongA(hwnd,GWL_STYLE),
     243    rc.right = rc.left+size.cx;
     244    rc.bottom = rc.top+size.cy;
     245
     246    AdjustWindowRectEx (&rc,GetWindowLongA(hwnd,GWL_STYLE),
    378247                        FALSE,GetWindowLongA(hwnd,GWL_EXSTYLE));
     248
     249    *lpRect = rc;
     250
     251}
     252
     253
     254static VOID
     255TOOLTIPS_Show (HWND hwnd, TOOLTIPS_INFO *infoPtr)
     256{
     257    TTTOOL_INFO *toolPtr;
     258    RECT rect;
     259    HDC  hdc;
     260    NMHDR  hdr;
     261
     262    if (infoPtr->nTool == -1)
     263    {
     264//      TRACE (tooltips, "invalid tool (-1)!\n");
     265        return;
     266    }
     267
     268    infoPtr->nCurrentTool = infoPtr->nTool;
     269
     270//    TRACE (tooltips, "Show tooltip pre %d!\n", infoPtr->nTool);
     271    TOOLTIPS_GetTipText(hwnd,infoPtr,infoPtr->nCurrentTool);
     272
     273    if (infoPtr->szTipText[0] == '\0')
     274    {
     275        infoPtr->nCurrentTool = -1;
     276        return;
     277    }
     278
     279//    TRACE (tooltips, "Show tooltip %d!\n", infoPtr->nCurrentTool);
     280    toolPtr = &infoPtr->tools[infoPtr->nCurrentTool];
     281
     282    hdr.hwndFrom = hwnd;
     283    hdr.idFrom = toolPtr->uId;
     284    hdr.code = TTN_SHOW;
     285    SendMessageA(toolPtr->hwnd,WM_NOTIFY,
     286                    (WPARAM)toolPtr->uId,(LPARAM)&hdr);
     287
     288//    TRACE (tooltips, "\"%s\"\n", debugstr_w(infoPtr->szTipText));
     289
     290    TOOLTIPS_CalcTipRect(hwnd,infoPtr,toolPtr,&rect);
     291
     292    SetWindowPos (hwnd,HWND_TOP,rect.left,rect.top,
     293                    rect.right-rect.left,rect.bottom-rect.top,
     294                    SWP_SHOWWINDOW | SWP_NOACTIVATE);
     295
     296    /* repaint the tooltip */
     297    hdc = GetDC(hwnd);
     298    TOOLTIPS_Refresh(hwnd,hdc);
     299    ReleaseDC(hwnd,hdc);
     300
     301    SetTimer (hwnd,ID_TIMERPOP,infoPtr->nAutoPopTime,0);
     302}
     303
     304
     305static VOID
     306TOOLTIPS_Hide (HWND hwnd, TOOLTIPS_INFO *infoPtr)
     307{
     308    TTTOOL_INFO *toolPtr;
     309    NMHDR hdr;
     310
     311    if (infoPtr->nCurrentTool == -1)
     312        return;
     313
     314    toolPtr = &infoPtr->tools[infoPtr->nCurrentTool];
     315//    TRACE (tooltips, "Hide tooltip %d!\n", infoPtr->nCurrentTool);
     316    KillTimer (hwnd, ID_TIMERPOP);
     317
     318    hdr.hwndFrom = hwnd;
     319    hdr.idFrom = toolPtr->uId;
     320    hdr.code = TTN_POP;
     321    SendMessageA (toolPtr->hwnd, WM_NOTIFY,
     322                    (WPARAM)toolPtr->uId, (LPARAM)&hdr);
     323
     324    infoPtr->nCurrentTool = -1;
     325
     326    SetWindowPos (hwnd, HWND_TOP, 0, 0, 0, 0,
     327                    SWP_NOZORDER | SWP_HIDEWINDOW | SWP_NOACTIVATE);
     328}
     329
     330
     331static VOID
     332TOOLTIPS_TrackShow (HWND hwnd, TOOLTIPS_INFO *infoPtr)
     333{
     334    TTTOOL_INFO *toolPtr;
     335    RECT rect;
     336    HDC  hdc;
     337    NMHDR hdr;
     338
     339    if (infoPtr->nTrackTool == -1)
     340    {
     341//    TRACE (tooltips, "invalid tracking tool (-1)!\n");
     342      return;
     343    }
     344
     345//    TRACE (tooltips, "show tracking tooltip pre %d!\n", infoPtr->nTrackTool);
     346
     347    TOOLTIPS_GetTipText(hwnd,infoPtr,infoPtr->nTrackTool);
     348
     349    if (infoPtr->szTipText[0] == '\0')
     350    {
     351      infoPtr->nTrackTool = -1;
     352      return;
     353    }
     354
     355//    TRACE (tooltips, "show tracking tooltip %d!\n", infoPtr->nTrackTool);
     356    toolPtr = &infoPtr->tools[infoPtr->nTrackTool];
     357
     358    hdr.hwndFrom = hwnd;
     359    hdr.idFrom = toolPtr->uId;
     360    hdr.code = TTN_SHOW;
     361    SendMessageA(toolPtr->hwnd,WM_NOTIFY,(WPARAM)toolPtr->uId,(LPARAM)&hdr);
     362
     363//    TRACE (tooltips, "\"%s\"\n", debugstr_w(infoPtr->szTipText));
     364
     365    TOOLTIPS_CalcTipRect(hwnd,infoPtr,toolPtr,&rect);
    379366
    380367    SetWindowPos (hwnd,HWND_TOP,rect.left,rect.top,
     
    17011688//      TRACE (tooltips, "[%d %d]\n",
    17021689//             infoPtr->xTrackPos, infoPtr->yTrackPos);
    1703 
    17041690      TOOLTIPS_TrackShow(hwnd,infoPtr);
    17051691    }
     
    20582044    if(wParam < length)
    20592045    {
    2060         lstrcpynWtoA((LPSTR)lParam,infoPtr->szTipText,MIN((UINT)wParam,lstrlenW(infoPtr->szTipText)));
     2046        lstrcpynWtoA((LPSTR)lParam,infoPtr->szTipText,(UINT)wParam);//includes 0 terminator
    20612047        return wParam;
    20622048    }
Note: See TracChangeset for help on using the changeset viewer.