Hallo, appended patch clean up the meaning of istring in the TBUTTON_INFO structure. It is either an index into the string pool or a string pointer. SetButtonInfo sets the string unconditional, InsertButton checks whether the passed istring is an index or a string and reacts acordingly. Also I use the STR_[Get|Set]Ptr where I think they are appropriate. This makes the gradient sidebar demo http://www.codeproject.com/wtl/sidebarmenu.asp display strings in the toolbar Changelog: dll/commctrl/toolbar.c Consistant usage of istring, use STR_[Get|Set]Ptr where appropriate Bye -- Uwe Bonnes bon@elektron.ikp.physik.tu-darmstadt.de Free Software: If you contribute nothing, expect nothing -- Index: wine/dlls/comctl32/toolbar.c =================================================================== RCS file: /home/wine/wine/dlls/comctl32/toolbar.c,v retrieving revision 1.100 diff -u -r1.100 toolbar.c --- wine/dlls/comctl32/toolbar.c 14 Jan 2002 18:33:17 -0000 1.100 +++ wine/dlls/comctl32/toolbar.c 18 Jan 2002 17:11:02 -0000 @@ -148,13 +148,28 @@ #define TOOLBAR_HasDropDownArrows(exStyle) ((exStyle & TBSTYLE_EX_DRAWDDARROWS) ? TRUE : FALSE) +static LPWSTR +TOOLBAR_GetText(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr) +{ + LPWSTR lpText = NULL; + + /* FIXME: iString == -1 is undocumented */ + if ((HIWORD(btnPtr->iString) != 0) && (btnPtr->iString != -1)) + lpText = (LPWSTR)btnPtr->iString; + else if ((btnPtr->iString >= 0) && (btnPtr->iString < infoPtr->nNumStrings)) + lpText = infoPtr->strings[btnPtr->iString]; + + return lpText; +} + static void TOOLBAR_DumpButton(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *bP, INT btn_num, BOOL internal) { if (TRACE_ON(toolbar)){ - TRACE("button %d id %d, bitmap=%d, state=%02x, style=%02x, data=%08lx, string=%d\n", + TRACE("button %d id %d, bitmap=%d, state=%02x, style=%02x, data=%08lx, stringid=%x\n", btn_num, bP->idCommand, bP->iBitmap, bP->fsState, bP->fsStyle, bP->dwData, bP->iString); + TRACE("string %s\n", debugstr_w(TOOLBAR_GetText(infoPtr,bP))); if (internal) TRACE("button %d id %d, hot=%s, row=%d, rect=(%d,%d)-(%d,%d)\n", btn_num, bP->idCommand, @@ -226,20 +241,6 @@ (WPARAM) nmhdr->idFrom, (LPARAM)nmhdr); } -static LPWSTR -TOOLBAR_GetText(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr) -{ - LPWSTR lpText = NULL; - - /* FIXME: iString == -1 is undocumented */ - if ((HIWORD(btnPtr->iString) != 0) && (btnPtr->iString != -1)) - lpText = (LPWSTR)btnPtr->iString; - else if ((btnPtr->iString >= 0) && (btnPtr->iString < infoPtr->nNumStrings)) - lpText = infoPtr->strings[btnPtr->iString]; - - return lpText; -} - /*********************************************************************** * TOOLBAR_GetBitmapIndex * @@ -443,7 +444,7 @@ /* get a pointer to the text */ lpText = TOOLBAR_GetText(infoPtr, btnPtr); - TRACE ("lpText: %s\n", debugstr_w(lpText)); + TRACE ("Stringtext: %s\n", debugstr_w(lpText)); /* draw text */ if (lpText) { @@ -814,11 +815,9 @@ lpSize->cx = 0; lpSize->cy = 0; - if (!(btnPtr->fsState & TBSTATE_HIDDEN) && - (btnPtr->iString > -1) && - (btnPtr->iString < infoPtr->nNumStrings)) + if (!(btnPtr->fsState & TBSTATE_HIDDEN) ) { - LPWSTR lpText = infoPtr->strings[btnPtr->iString]; + LPWSTR lpText = TOOLBAR_GetText(infoPtr, btnPtr); /* first get size of all the text */ GetTextExtentPoint32W (hdc, lpText, strlenW (lpText), lpSize); @@ -2154,7 +2153,7 @@ if ((wParam) && (HIWORD(lParam) == 0)) { char szString[256]; - INT len, lenW; + INT len; TRACE("adding string from resource!\n"); len = LoadStringA ((HINSTANCE)wParam, (UINT)lParam, @@ -2175,15 +2174,13 @@ COMCTL32_Free (oldStrings); } - lenW = MultiByteToWideChar( CP_ACP, 0, szString, -1, NULL, 0 ); - infoPtr->strings[infoPtr->nNumStrings] = COMCTL32_Alloc (sizeof(WCHAR)*lenW); - MultiByteToWideChar( CP_ACP, 0, szString, -1, - infoPtr->strings[infoPtr->nNumStrings], lenW ); + /*COMCTL32_Alloc zeros out the allocated memory*/ + Str_SetPtrAtoW (&infoPtr->strings[infoPtr->nNumStrings], szString ); infoPtr->nNumStrings++; } else { LPSTR p = (LPSTR)lParam; - INT len, lenW; + INT len; if (p == NULL) return -1; @@ -2207,10 +2204,7 @@ COMCTL32_Free (oldStrings); } - lenW = MultiByteToWideChar( CP_ACP, 0, p, -1, NULL, 0 ); - infoPtr->strings[infoPtr->nNumStrings] = COMCTL32_Alloc (sizeof(WCHAR)*lenW); - MultiByteToWideChar( CP_ACP, 0, p, -1, - infoPtr->strings[infoPtr->nNumStrings], lenW ); + Str_SetPtrAtoW (&infoPtr->strings[infoPtr->nNumStrings], p ); infoPtr->nNumStrings++; p += (len+1); @@ -2284,9 +2278,7 @@ COMCTL32_Free (oldStrings); } - infoPtr->strings[infoPtr->nNumStrings] = - COMCTL32_Alloc (sizeof(WCHAR)*(len+1)); - strcpyW (infoPtr->strings[infoPtr->nNumStrings], szString); + Str_SetPtrW (&infoPtr->strings[infoPtr->nNumStrings], szString); infoPtr->nNumStrings++; } } @@ -2315,9 +2307,7 @@ COMCTL32_Free (oldStrings); } - infoPtr->strings[infoPtr->nNumStrings] = - COMCTL32_Alloc (sizeof(WCHAR)*(len+1)); - strcpyW (infoPtr->strings[infoPtr->nNumStrings], p); + Str_SetPtrW (&infoPtr->strings[infoPtr->nNumStrings], p); infoPtr->nNumStrings++; p += (len+1); @@ -2723,14 +2713,9 @@ if (lpTbInfo->dwMask & TBIF_STYLE) lpTbInfo->fsStyle = btnPtr->fsStyle; if (lpTbInfo->dwMask & TBIF_TEXT) { - if ((btnPtr->iString >= 0) && (btnPtr->iString < infoPtr->nNumStrings)) - { - if (!WideCharToMultiByte( CP_ACP, 0, (LPWSTR)infoPtr->strings[btnPtr->iString], -1, - lpTbInfo->pszText, lpTbInfo->cchText, NULL, NULL )) - lpTbInfo->pszText[lpTbInfo->cchText-1] = 0; + LPWSTR lpText = TOOLBAR_GetText(infoPtr,btnPtr); + Str_GetPtrWtoA (lpText, lpTbInfo->pszText,lpTbInfo->cchText); } - else lpTbInfo->pszText[0]=0; - } return nIndex; } @@ -2770,10 +2755,8 @@ if (lpTbInfo->dwMask & TBIF_STYLE) lpTbInfo->fsStyle = btnPtr->fsStyle; if (lpTbInfo->dwMask & TBIF_TEXT) { - if ((btnPtr->iString >= 0) || (btnPtr->iString < infoPtr->nNumStrings)) - lstrcpynW (lpTbInfo->pszText, - (LPWSTR)infoPtr->strings[btnPtr->iString], - lpTbInfo->cchText); + LPWSTR lpText = TOOLBAR_GetText(infoPtr,btnPtr); + Str_GetPtrW (lpText,lpTbInfo->pszText,lpTbInfo->cchText); } return nIndex; @@ -2797,23 +2780,19 @@ TOOLBAR_GetButtonTextA (HWND hwnd, WPARAM wParam, LPARAM lParam) { TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd); - INT nIndex, nStringIndex; + INT nIndex; + LPWSTR lpText; - nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE); - if (nIndex == -1) + if (lParam == 0) return -1; - nStringIndex = infoPtr->buttons[nIndex].iString; - - TRACE("index=%d stringIndex=%d\n", nIndex, nStringIndex); - - if ((nStringIndex < 0) || (nStringIndex >= infoPtr->nNumStrings)) + nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE); + if (nIndex == -1) return -1; - if (lParam == 0) - return -1; + lpText = TOOLBAR_GetText(infoPtr,&infoPtr->buttons[nIndex]); - return WideCharToMultiByte( CP_ACP, 0, (LPWSTR)infoPtr->strings[nStringIndex], -1, + return WideCharToMultiByte( CP_ACP, 0, lpText, -1, (LPSTR)lParam, 0x7fffffff, NULL, NULL ) - 1; } @@ -2822,25 +2801,21 @@ TOOLBAR_GetButtonTextW (HWND hwnd, WPARAM wParam, LPARAM lParam) { TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd); - INT nIndex, nStringIndex; + INT nIndex; + LPWSTR lpText; - nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE); - if (nIndex == -1) + if (lParam == 0) return -1; - nStringIndex = infoPtr->buttons[nIndex].iString; - - TRACE("index=%d stringIndex=%d\n", nIndex, nStringIndex); - - if ((nStringIndex < 0) || (nStringIndex >= infoPtr->nNumStrings)) + nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE); + if (nIndex == -1) return -1; - if (lParam == 0) - return -1; + lpText = TOOLBAR_GetText(infoPtr,&infoPtr->buttons[nIndex]); - strcpyW ((LPWSTR)lParam, (LPWSTR)infoPtr->strings[nStringIndex]); + strcpyW ((LPWSTR)lParam, lpText); - return strlenW ((LPWSTR)infoPtr->strings[nStringIndex]); + return strlenW (lpText); } @@ -3163,26 +3138,18 @@ nIndex * sizeof(TBUTTON_INFO)); } - /* if passed string and not index, then add string */ - if(HIWORD(lpTbb->iString) && lpTbb->iString!=-1) { - int len; - LPSTR ptr; - - len = strlen((char*)lpTbb->iString) + 2; - ptr = COMCTL32_Alloc(len*sizeof(char)); - strcpy(ptr, (char*)lpTbb->iString); - ptr[len - 1] = 0; /* ended by two '\0' */ - lpTbb->iString = TOOLBAR_AddStringA(hwnd, 0, (LPARAM)ptr); - COMCTL32_Free(ptr); - } - /* insert new button */ infoPtr->buttons[nIndex].iBitmap = lpTbb->iBitmap; infoPtr->buttons[nIndex].idCommand = lpTbb->idCommand; infoPtr->buttons[nIndex].fsState = lpTbb->fsState; infoPtr->buttons[nIndex].fsStyle = lpTbb->fsStyle; infoPtr->buttons[nIndex].dwData = lpTbb->dwData; - infoPtr->buttons[nIndex].iString = lpTbb->iString; + /* if passed string and not index, then add string */ + if(HIWORD(lpTbb->iString) && lpTbb->iString!=-1) { + Str_SetPtrAtoW ((LPWSTR *)&infoPtr->buttons[nIndex].iString, (LPCSTR )lpTbb->iString); + } + else + infoPtr->buttons[nIndex].iString = lpTbb->iString; if ((infoPtr->hwndToolTip) && !(lpTbb->fsStyle & TBSTYLE_SEP)) { TTTOOLINFOA ti; @@ -3242,18 +3209,6 @@ nIndex * sizeof(TBUTTON_INFO)); } - /* if passed string and not index, then add string */ - if(HIWORD(lpTbb->iString) && lpTbb->iString!=-1) { - int len; - LPWSTR ptr; - - len = strlenW((WCHAR*)lpTbb->iString) + 2; - ptr = COMCTL32_Alloc(len*sizeof(WCHAR)); - strcpyW(ptr, (WCHAR*)lpTbb->iString); - ptr[len - 1] = 0; /* ended by two '\0' */ - lpTbb->iString = TOOLBAR_AddStringW(hwnd, 0, (LPARAM)ptr); - COMCTL32_Free(ptr); - } /* insert new button */ infoPtr->buttons[nIndex].iBitmap = lpTbb->iBitmap; @@ -3261,7 +3216,12 @@ infoPtr->buttons[nIndex].fsState = lpTbb->fsState; infoPtr->buttons[nIndex].fsStyle = lpTbb->fsStyle; infoPtr->buttons[nIndex].dwData = lpTbb->dwData; - infoPtr->buttons[nIndex].iString = lpTbb->iString; + /* if passed string and not index, then add string */ + if(HIWORD(lpTbb->iString) && lpTbb->iString!=-1) { + Str_SetPtrW ((LPWSTR *)&infoPtr->buttons[nIndex].iString, (LPWSTR)lpTbb->iString); + } + else + infoPtr->buttons[nIndex].iString = lpTbb->iString; if ((infoPtr->hwndToolTip) && !(lpTbb->fsStyle & TBSTYLE_SEP)) { TTTOOLINFOW ti; @@ -3542,21 +3502,13 @@ if (lptbbi->dwMask & TBIF_STYLE) btnPtr->fsStyle = lptbbi->fsStyle; - if (lptbbi->dwMask & TBIF_TEXT) { - if ((btnPtr->iString >= 0) || - (btnPtr->iString < infoPtr->nNumStrings)) { - TRACE("Ooooooch\n"); -#if 0 - WCHAR **lpString = &infoPtr->strings[btnPtr->iString]; - INT len = lstrlenA (lptbbi->pszText); - *lpString = COMCTL32_ReAlloc (lpString, sizeof(WCHAR)*(len+1)); -#endif - - /* this is the ultimate sollution */ -/* Str_SetPtrA (&infoPtr->strings[btnPtr->iString], lptbbi->pszText); */ - } + if ((lptbbi->dwMask & TBIF_TEXT) && ((INT)lptbbi->pszText != -1)) { + if ((HIWORD(btnPtr->iString) == 0) || (btnPtr->iString == -1)) + /* iString is index, zero it to make Str_SetPtr succeed */ + btnPtr->iString=0; + + Str_SetPtrAtoW ((LPWSTR *)&btnPtr->iString, lptbbi->pszText); } - return TRUE; } @@ -3593,20 +3545,12 @@ if (lptbbi->dwMask & TBIF_STYLE) btnPtr->fsStyle = lptbbi->fsStyle; - if (lptbbi->dwMask & TBIF_TEXT) { - if ((btnPtr->iString >= 0) || - (btnPtr->iString < infoPtr->nNumStrings)) { -#if 0 - WCHAR **lpString = &infoPtr->strings[btnPtr->iString]; - INT len = lstrlenW (lptbbi->pszText); - *lpString = COMCTL32_ReAlloc (lpString, sizeof(WCHAR)*(len+1)); -#endif - - /* this is the ultimate solution */ -/* Str_SetPtrA (&infoPtr->strings[btnPtr->iString], lptbbi->pszText); */ - } + if ((lptbbi->dwMask & TBIF_TEXT) && ((INT)lptbbi->pszText != -1)) { + if ((HIWORD(btnPtr->iString) == 0) || (btnPtr->iString == -1)) + /* iString is index, zero it to make Str_SetPtr succeed */ + btnPtr->iString=0; + Str_SetPtrW ((LPWSTR *)&btnPtr->iString, lptbbi->pszText); } - return TRUE; }