summaryrefslogtreecommitdiffstats
path: root/win/tkWinMenu.c
diff options
context:
space:
mode:
authorjan.nijtmans <nijtmans@users.sourceforge.net>2020-03-24 07:56:41 (GMT)
committerjan.nijtmans <nijtmans@users.sourceforge.net>2020-03-24 07:56:41 (GMT)
commitbc56730d2abae5198c3667a55729e01684f3cb29 (patch)
treea67f18bf70f2081877ab48b4aecd142c54848262 /win/tkWinMenu.c
parentabbe37191732849b4d22072a8572f29205025457 (diff)
downloadtk-bc56730d2abae5198c3667a55729e01684f3cb29.zip
tk-bc56730d2abae5198c3667a55729e01684f3cb29.tar.gz
tk-bc56730d2abae5198c3667a55729e01684f3cb29.tar.bz2
Replace all instances of Tcl_WinTCharToUtf()/Tcl_WinUtfToTChar() with Tcl_UniCharToUtfDString()/Tcl_UtfToUniCharDString(), if possible (only for -DTCL_UTF_MAX=3, which is the default and only supported option)
Backported, as far as possible, from 8.7. This helps moving away from Tcl_WinTCharToUtf()/Tcl_WinUtfToTChar(), even though it only becomes deprecated in 8.7.
Diffstat (limited to 'win/tkWinMenu.c')
-rw-r--r--win/tkWinMenu.c143
1 files changed, 95 insertions, 48 deletions
diff --git a/win/tkWinMenu.c b/win/tkWinMenu.c
index 6e856c7..d2d39cc 100644
--- a/win/tkWinMenu.c
+++ b/win/tkWinMenu.c
@@ -233,13 +233,13 @@ GetNewID(
TkMenuEntry *mePtr, /* The menu we are working with. */
WORD *menuIDPtr) /* The resulting id. */
{
- ThreadSpecificData *tsdPtr =
+ ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));
WORD curID = tsdPtr->lastCommandID;
while (1) {
Tcl_HashEntry *commandEntryPtr;
- int new;
+ int isNew;
/*
* Try the next ID number, taking care to wrap rather than stray
@@ -255,8 +255,8 @@ GetNewID(
}
commandEntryPtr = Tcl_CreateHashEntry(&tsdPtr->commandTable,
- INT2PTR(curID), &new);
- if (new) {
+ INT2PTR(curID), &isNew);
+ if (isNew) {
Tcl_SetHashValue(commandEntryPtr, mePtr);
*menuIDPtr = curID;
tsdPtr->lastCommandID = curID;
@@ -285,7 +285,7 @@ static void
FreeID(
WORD commandID)
{
- ThreadSpecificData *tsdPtr =
+ ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));
/*
@@ -328,7 +328,7 @@ TkpNewMenu(
HMENU winMenuHdl;
Tcl_HashEntry *hashEntryPtr;
int newEntry;
- ThreadSpecificData *tsdPtr =
+ ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));
winMenuHdl = CreatePopupMenu();
@@ -374,7 +374,7 @@ TkpDestroyMenu(
{
HMENU winMenuHdl = (HMENU) menuPtr->platformData;
const char *searchName;
- ThreadSpecificData *tsdPtr =
+ ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));
if (menuPtr->menuFlags & MENU_RECONFIGURE_PENDING) {
@@ -388,7 +388,7 @@ TkpDestroyMenu(
if (menuPtr->menuFlags & MENU_SYSTEM_MENU) {
TkMenuEntry *searchEntryPtr;
Tcl_HashTable *tablePtr = TkGetMenuHashTable(menuPtr->interp);
- char *menuName = Tcl_GetHashKey(tablePtr,
+ char *menuName = (char *)Tcl_GetHashKey(tablePtr,
menuPtr->menuRefPtr->hashEntryPtr);
/*
@@ -420,7 +420,7 @@ TkpDestroyMenu(
if (tsdPtr->menuHWND != NULL) {
Tcl_HashEntry *hashEntryPtr =
- Tcl_FindHashEntry(&tsdPtr->winMenuTable, (char *) winMenuHdl);
+ Tcl_FindHashEntry(&tsdPtr->winMenuTable, winMenuHdl);
if (hashEntryPtr != NULL) {
Tcl_DeleteHashEntry(hashEntryPtr);
@@ -492,16 +492,16 @@ GetEntryText(
char *itemText;
if (mePtr->type == TEAROFF_ENTRY) {
- itemText = ckalloc(sizeof("(Tear-off)"));
+ itemText = (char *)ckalloc(sizeof("(Tear-off)"));
strcpy(itemText, "(Tear-off)");
} else if (mePtr->imagePtr != NULL) {
- itemText = ckalloc(sizeof("(Image)"));
+ itemText = (char *)ckalloc(sizeof("(Image)"));
strcpy(itemText, "(Image)");
} else if (mePtr->bitmapPtr != NULL) {
- itemText = ckalloc(sizeof("(Pixmap)"));
+ itemText = (char *)ckalloc(sizeof("(Pixmap)"));
strcpy(itemText, "(Pixmap)");
} else if (mePtr->labelPtr == NULL || mePtr->labelLength == 0) {
- itemText = ckalloc(sizeof("( )"));
+ itemText = (char *)ckalloc(sizeof("( )"));
strcpy(itemText, "( )");
} else {
int i;
@@ -541,7 +541,7 @@ GetEntryText(
}
}
- itemText = ckalloc(Tcl_DStringLength(&itemString) + 1);
+ itemText = (char *)ckalloc(Tcl_DStringLength(&itemString) + 1);
strcpy(itemText, Tcl_DStringValue(&itemString));
Tcl_DStringFree(&itemString);
}
@@ -569,7 +569,7 @@ static void
ReconfigureWindowsMenu(
ClientData clientData) /* The menu we are rebuilding */
{
- TkMenu *menuPtr = clientData;
+ TkMenu *menuPtr = (TkMenu *)clientData;
TkMenuEntry *mePtr;
HMENU winMenuHdl = (HMENU) menuPtr->platformData;
char *itemText = NULL;
@@ -609,7 +609,8 @@ ReconfigureWindowsMenu(
itemText = GetEntryText(menuPtr, mePtr);
if ((menuPtr->menuType == MENUBAR)
|| (menuPtr->menuFlags & MENU_SYSTEM_MENU)) {
- Tcl_WinUtfToTChar(itemText, -1, &translatedText);
+ Tcl_DStringInit(&translatedText);
+ Tcl_UtfToWCharDString(itemText, -1, &translatedText);
lpNewItem = (LPCWSTR) Tcl_DStringValue(&translatedText);
flags |= MF_STRING;
} else {
@@ -728,7 +729,7 @@ ReconfigureWindowsMenu(
if ((menuPtr->menuType == MENUBAR)
&& (menuPtr->parentTopLevelPtr != NULL)) {
- HANDLE bar = TkWinGetWrapperWindow(menuPtr->parentTopLevelPtr);
+ HWND bar = TkWinGetWrapperWindow(menuPtr->parentTopLevelPtr);
if (bar) {
DrawMenuBar(bar);
@@ -759,7 +760,7 @@ ReconfigureWindowsMenu(
int
TkpPostMenu(
- Tcl_Interp *interp,
+ Tcl_Interp *dummy,
TkMenu *menuPtr,
int x, int y, int index)
{
@@ -769,8 +770,9 @@ TkpPostMenu(
POINT point;
Tk_Window parentWindow = Tk_Parent(menuPtr->tkwin);
int oldServiceMode = Tcl_GetServiceMode();
- ThreadSpecificData *tsdPtr =
+ ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));
+ (void)dummy;
tsdPtr->inPostMenu++;
CallPendingReconfigureImmediately(menuPtr);
@@ -869,13 +871,14 @@ TkpPostMenu(
int
TkpPostTearoffMenu(
- Tcl_Interp *interp, /* The interpreter of the menu */
+ Tcl_Interp *dummy, /* The interpreter of the menu */
TkMenu *menuPtr, /* The menu we are posting */
int x, int y, int index) /* The root X,Y coordinates where we are
* posting */
{
int vRootX, vRootY, vRootWidth, vRootHeight;
int result;
+ (void)dummy;
if (index >= menuPtr->numEntries) {
index = menuPtr->numEntries - 1;
@@ -1064,7 +1067,7 @@ TkWinEmbeddedMenuProc(
{
static int nIdles = 0;
LRESULT lResult = 1;
- ThreadSpecificData *tsdPtr =
+ ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));
switch(message) {
@@ -1140,15 +1143,16 @@ TkWinHandleMenuEvent(
int returnResult = 0;
TkMenu *menuPtr;
TkMenuEntry *mePtr;
- ThreadSpecificData *tsdPtr =
+ ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));
+ (void)phwnd;
switch (*pMessage) {
case WM_UNINITMENUPOPUP:
hashEntryPtr = Tcl_FindHashEntry(&tsdPtr->winMenuTable,
- (char *) *pwParam);
+ *pwParam);
if (hashEntryPtr != NULL) {
- menuPtr = Tcl_GetHashValue(hashEntryPtr);
+ menuPtr = (TkMenu *)Tcl_GetHashValue(hashEntryPtr);
if ((menuPtr->menuRefPtr != NULL)
&& (menuPtr->menuRefPtr->parentEntryPtr != NULL)) {
TkPostSubmenu(menuPtr->interp,
@@ -1160,10 +1164,10 @@ TkWinHandleMenuEvent(
case WM_INITMENU:
TkMenuInit();
hashEntryPtr = Tcl_FindHashEntry(&tsdPtr->winMenuTable,
- (char *) *pwParam);
+ *pwParam);
if (hashEntryPtr != NULL) {
tsdPtr->oldServiceMode = Tcl_SetServiceMode(TCL_SERVICE_ALL);
- menuPtr = Tcl_GetHashValue(hashEntryPtr);
+ menuPtr = (TkMenu *)Tcl_GetHashValue(hashEntryPtr);
tsdPtr->modalMenuPtr = menuPtr;
CallPendingReconfigureImmediately(menuPtr);
RecursivelyClearActiveMenu(menuPtr);
@@ -1199,7 +1203,7 @@ TkWinHandleMenuEvent(
if (hashEntryPtr == NULL) {
break;
}
- mePtr = Tcl_GetHashValue(hashEntryPtr);
+ mePtr = (TkMenuEntry *)Tcl_GetHashValue(hashEntryPtr);
if (mePtr != NULL) {
TkMenuReferences *menuRefPtr;
TkMenuEntry *parentEntryPtr;
@@ -1245,16 +1249,16 @@ TkWinHandleMenuEvent(
case WM_MENUCHAR: {
hashEntryPtr = Tcl_FindHashEntry(&tsdPtr->winMenuTable,
- (char *) *plParam);
+ *plParam);
if (hashEntryPtr != NULL) {
int i, len, underline;
Tcl_Obj *labelPtr;
- LPCWSTR wlabel;
+ WCHAR *wlabel;
int menuChar;
Tcl_DString ds;
*plResult = 0;
- menuPtr = Tcl_GetHashValue(hashEntryPtr);
+ menuPtr = (TkMenu *)Tcl_GetHashValue(hashEntryPtr);
/*
* Assume we have something directly convertable to Tcl_UniChar.
* True at least for wide systems.
@@ -1272,8 +1276,9 @@ TkWinHandleMenuEvent(
const char *src = Tcl_GetStringFromObj(labelPtr, &len);
Tcl_DStringFree(&ds);
- wlabel = (LPCWSTR) Tcl_WinUtfToTChar(src, len, &ds);
- if ((underline < len) && (menuChar ==
+ Tcl_DStringInit(&ds);
+ wlabel = Tcl_UtfToWCharDString(src, len, &ds);
+ if ((underline + 1 < len + 1) && (menuChar ==
Tcl_UniCharToUpper(wlabel[underline]))) {
*plResult = (2 << 16) | i;
returnResult = 1;
@@ -1325,7 +1330,7 @@ TkWinHandleMenuEvent(
}
mePtr = (TkMenuEntry *) itemPtr->itemData;
menuPtr = mePtr->menuPtr;
- twdPtr = ckalloc(sizeof(TkWinDrawable));
+ twdPtr = (TkWinDrawable *)ckalloc(sizeof(TkWinDrawable));
twdPtr->type = TWD_WINDC;
twdPtr->winDC.hdc = itemPtr->hDC;
@@ -1389,9 +1394,9 @@ TkWinHandleMenuEvent(
menuPtr = NULL;
if (*plParam != 0) {
hashEntryPtr = Tcl_FindHashEntry(&tsdPtr->winMenuTable,
- (char *) *plParam);
+ *plParam);
if (hashEntryPtr != NULL) {
- menuPtr = Tcl_GetHashValue(hashEntryPtr);
+ menuPtr = (TkMenu *)Tcl_GetHashValue(hashEntryPtr);
}
}
@@ -1416,7 +1421,7 @@ TkWinHandleMenuEvent(
hashEntryPtr = Tcl_FindHashEntry(&tsdPtr->commandTable,
INT2PTR(entryIndex));
if (hashEntryPtr != NULL) {
- mePtr = Tcl_GetHashValue(hashEntryPtr);
+ mePtr = (TkMenuEntry *)Tcl_GetHashValue(hashEntryPtr);
}
}
}
@@ -1505,7 +1510,7 @@ TkpSetWindowMenuBar(
TkMenu *menuPtr) /* The menu we are inserting */
{
HMENU winMenuHdl;
- ThreadSpecificData *tsdPtr =
+ ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));
if (menuPtr != NULL) {
@@ -1514,7 +1519,7 @@ TkpSetWindowMenuBar(
winMenuHdl = (HMENU) menuPtr->platformData;
hashEntryPtr = Tcl_FindHashEntry(&tsdPtr->winMenuTable,
- (char *) winMenuHdl);
+ winMenuHdl);
Tcl_DeleteHashEntry(hashEntryPtr);
DestroyMenu(winMenuHdl);
winMenuHdl = CreateMenu();
@@ -1553,6 +1558,10 @@ TkpSetMainMenubar(
const char *menuName) /* The name of the menu to put in front. If
* NULL, use the default menu bar. */
{
+ (void)interp;
+ (void)tkwin;
+ (void)menuName;
+
/*
* Nothing to do.
*/
@@ -1583,6 +1592,10 @@ GetMenuIndicatorGeometry(
int *widthPtr, /* The resulting width */
int *heightPtr) /* The resulting height */
{
+ (void)menuPtr;
+ (void)tkfont;
+ (void)fmPtr;
+
*heightPtr = indicatorDimensions[0];
if (mePtr->hideMargin) {
*widthPtr = 0;
@@ -1666,6 +1679,9 @@ GetTearoffEntryGeometry(
int *widthPtr, /* The resulting width */
int *heightPtr) /* The resulting height */
{
+ (void)mePtr;
+ (void)tkfont;
+
if (menuPtr->menuType != MASTER_MENU) {
*heightPtr = 0;
} else {
@@ -1699,6 +1715,10 @@ GetMenuSeparatorGeometry(
int *widthPtr, /* The resulting width */
int *heightPtr) /* The resulting height */
{
+ (void)menuPtr;
+ (void)mePtr;
+ (void)tkfont;
+
*widthPtr = 0;
*heightPtr = fmPtr->linespace - (2 * fmPtr->descent);
}
@@ -1812,6 +1832,11 @@ DrawMenuEntryIndicator(
int width,
int height)
{
+ (void)tkfont;
+ (void)fmPtr;
+ (void)width;
+ (void)height;
+
if ((mePtr->type == CHECK_BUTTON_ENTRY)
|| (mePtr->type == RADIO_BUTTON_ENTRY)) {
if (mePtr->indicatorOn && (mePtr->entryFlags & ENTRY_SELECTED)) {
@@ -1892,6 +1917,9 @@ DrawMenuEntryAccelerator(
int baseline;
int leftEdge = x + mePtr->indicatorSpace + mePtr->labelWidth;
const char *accel;
+ (void)activeBorder;
+ (void)width;
+ (void)height;
if (menuPtr->menuType == MENUBAR) {
return;
@@ -1965,6 +1993,8 @@ DrawMenuEntryArrow(
COLORREF oldFgColor;
COLORREF oldBgColor;
RECT rect;
+ (void)gc;
+ (void)activeBorder;
if (!drawArrow || (mePtr->type != CASCADE_ENTRY)) {
return;
@@ -2035,6 +2065,10 @@ DrawMenuSeparator(
{
XPoint points[2];
Tk_3DBorder border;
+ (void)mePtr;
+ (void)gc;
+ (void)tkfont;
+ (void)fmPtr;
points[0].x = x;
points[0].y = y + height / 2;
@@ -2074,6 +2108,9 @@ DrawMenuUnderline(
int width, /* Width of entry */
int height) /* Height of entry */
{
+ (void)fmPtr;
+ (void)width;
+
if ((mePtr->underline >= 0) && (mePtr->labelPtr != NULL)) {
int len;
@@ -2113,7 +2150,7 @@ DrawMenuUnderline(
static int
TkWinMenuKeyObjCmd(
- ClientData clientData, /* Unused. */
+ ClientData dummy, /* Unused. */
Tcl_Interp *interp, /* Current interpreter. */
int objc, /* Number of arguments. */
Tcl_Obj *const objv[]) /* Argument objects. */
@@ -2125,6 +2162,7 @@ TkWinMenuKeyObjCmd(
TkWindow *winPtr;
KeySym keySym;
int i;
+ (void)dummy;
if (objc != 3) {
Tcl_WrongNumArgs(interp, 1, objv, "window keySym");
@@ -2257,8 +2295,7 @@ TkpInitializeMenuBindings(
*/
(void) Tcl_CreateObjCommand(interp, "tk::WinMenuKey",
- TkWinMenuKeyObjCmd,
- (ClientData) Tk_MainWindow(interp), (Tcl_CmdDeleteProc *) NULL);
+ TkWinMenuKeyObjCmd, Tk_MainWindow(interp), NULL);
(void) Tk_CreateBinding(interp, bindingTable, (ClientData) uid,
"<Alt_L>", "tk::WinMenuKey %W %N", 0);
@@ -2537,6 +2574,10 @@ DrawTearoffEntry(
XPoint points[2];
int segmentWidth, maxX;
Tk_3DBorder border;
+ (void)mePtr;
+ (void)gc;
+ (void)tkfont;
+ (void)fmPtr;
if (menuPtr->menuType != MASTER_MENU) {
return;
@@ -2580,7 +2621,7 @@ DrawTearoffEntry(
int
TkpConfigureMenuEntry(
- register TkMenuEntry *mePtr)/* Information about menu entry; may or may
+ TkMenuEntry *mePtr)/* Information about menu entry; may or may
* not already have values for some fields. */
{
ScheduleMenuReconfigure(mePtr->menuPtr);
@@ -2644,7 +2685,7 @@ TkpDrawMenuEntry(
menuDc = TkWinGetDrawableDC(menuPtr->display, menuDrawable, &dcState);
memDc = CreateCompatibleDC(menuDc);
- oldBitmap = SelectObject(memDc,
+ oldBitmap = (HBITMAP)SelectObject(memDc,
CreateCompatibleBitmap(menuDc, width, height) );
memWinDraw.type = TWD_WINDC;
@@ -3187,8 +3228,9 @@ HWND
Tk_GetMenuHWND(
Tk_Window tkwin)
{
- ThreadSpecificData *tsdPtr =
+ ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));
+ (void)tkwin;
TkMenuInit();
return tsdPtr->embeddedMenuHWND;
@@ -3212,8 +3254,10 @@ Tk_GetMenuHWND(
static void
MenuExitHandler(
- ClientData clientData) /* Not used */
+ ClientData dummy) /* Not used */
{
+ (void)dummy;
+
UnregisterClassW(MENU_CLASS_NAME, Tk_GetHINSTANCE());
UnregisterClassW(EMBEDDED_MENU_CLASS_NAME, Tk_GetHINSTANCE());
}
@@ -3237,10 +3281,11 @@ MenuExitHandler(
static void
MenuThreadExitHandler(
- ClientData clientData) /* Not used */
+ ClientData dummy) /* Not used */
{
- ThreadSpecificData *tsdPtr =
+ ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));
+ (void)dummy;
DestroyWindow(tsdPtr->menuHWND);
DestroyWindow(tsdPtr->embeddedMenuHWND);
@@ -3277,6 +3322,8 @@ TkWinGetMenuSystemDefault(
const char *className) /* The name of the option class. */
{
Tcl_Obj *valuePtr = NULL;
+ (void)tkwin;
+ (void)className;
if ((strcmp(dbName, "activeBorderWidth") == 0) ||
(strcmp(dbName, "borderWidth") == 0)) {
@@ -3480,7 +3527,7 @@ TkpMenuInit(void)
void
TkpMenuThreadInit(void)
{
- ThreadSpecificData *tsdPtr =
+ ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));
tsdPtr->menuHWND = CreateWindowW(MENU_CLASS_NAME, L"MenuWindow", WS_POPUP,