summaryrefslogtreecommitdiffstats
path: root/win/tkWinMenu.c
diff options
context:
space:
mode:
Diffstat (limited to 'win/tkWinMenu.c')
-rw-r--r--win/tkWinMenu.c141
1 files changed, 65 insertions, 76 deletions
diff --git a/win/tkWinMenu.c b/win/tkWinMenu.c
index c25b793..b1bf7f8 100644
--- a/win/tkWinMenu.c
+++ b/win/tkWinMenu.c
@@ -11,20 +11,16 @@
* this file, and for a DISCLAIMER OF ALL WARRANTIES.
*/
-#define WINVER 0x0500 /* Requires Windows 2K definitions */
-#define _WIN32_WINNT 0x0500
#define OEMRESOURCE
#include "tkWinInt.h"
#include "tkMenu.h"
-#include <string.h>
-
/*
* The class of the window for popup menus.
*/
-#define MENU_CLASS_NAME "MenuWindowClass"
-#define EMBEDDED_MENU_CLASS_NAME "EmbeddedMenuWindowClass"
+#define MENU_CLASS_NAME TEXT("MenuWindowClass")
+#define EMBEDDED_MENU_CLASS_NAME TEXT("EmbeddedMenuWindowClass")
/*
* Used to align a windows bitmap inside a rectangle
@@ -159,7 +155,7 @@ static void DrawWindowsSystemBitmap(Display *display,
Drawable drawable, GC gc, const RECT *rectPtr,
int bitmapID, int alignFlags);
static void FreeID(WORD commandID);
-static TCHAR * GetEntryText(TkMenuEntry *mePtr);
+static char * GetEntryText(TkMenuEntry *mePtr);
static void GetMenuAccelGeometry(TkMenu *menuPtr,
TkMenuEntry *mePtr, Tk_Font tkfont,
const Tk_FontMetrics *fmPtr, int *widthPtr,
@@ -241,7 +237,7 @@ GetNewID(
commandEntryPtr = Tcl_CreateHashEntry(&tsdPtr->commandTable,
(char *) curID, &new);
if (new) {
- Tcl_SetHashValue(commandEntryPtr, (char *) mePtr);
+ Tcl_SetHashValue(commandEntryPtr, mePtr);
*menuIDPtr = curID;
tsdPtr->lastCommandID = curID;
return TCL_OK;
@@ -329,7 +325,7 @@ TkpNewMenu(
hashEntryPtr = Tcl_CreateHashEntry(&tsdPtr->winMenuTable,
(char *) winMenuHdl, &newEntry);
- Tcl_SetHashValue(hashEntryPtr, (char *) menuPtr);
+ Tcl_SetHashValue(hashEntryPtr, menuPtr);
menuPtr->platformData = (TkMenuPlatformData) winMenuHdl;
return TCL_OK;
@@ -356,7 +352,7 @@ TkpDestroyMenu(
TkMenu *menuPtr) /* The common menu structure */
{
HMENU winMenuHdl = (HMENU) menuPtr->platformData;
- char *searchName;
+ const char *searchName;
ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));
@@ -489,9 +485,9 @@ GetEntryText(
strcpy(itemText, "( )");
} else {
int i;
- char *label = (mePtr->labelPtr == NULL) ? ""
+ const char *label = (mePtr->labelPtr == NULL) ? ""
: Tcl_GetString(mePtr->labelPtr);
- char *accel = (mePtr->accelPtr == NULL) ? ""
+ const char *accel = (mePtr->accelPtr == NULL) ? ""
: Tcl_GetString(mePtr->accelPtr);
const char *p, *next;
Tcl_DString itemString;
@@ -525,7 +521,7 @@ GetEntryText(
}
}
- itemText = ckalloc((unsigned)Tcl_DStringLength(&itemString) + 1);
+ itemText = ckalloc(Tcl_DStringLength(&itemString) + 1);
strcpy(itemText, Tcl_DStringValue(&itemString));
Tcl_DStringFree(&itemString);
}
@@ -556,7 +552,7 @@ ReconfigureWindowsMenu(
TkMenu *menuPtr = (TkMenu *) clientData;
TkMenuEntry *mePtr;
HMENU winMenuHdl = (HMENU) menuPtr->platformData;
- TCHAR *itemText = NULL;
+ char *itemText = NULL;
const TCHAR *lpNewItem;
UINT flags;
UINT itemID;
@@ -594,7 +590,7 @@ ReconfigureWindowsMenu(
if ((menuPtr->menuType == MENUBAR)
|| (menuPtr->menuFlags & MENU_SYSTEM_MENU)) {
Tcl_WinUtfToTChar(itemText, -1, &translatedText);
- lpNewItem = Tcl_DStringValue(&translatedText);
+ lpNewItem = (const TCHAR *) Tcl_DStringValue(&translatedText);
flags |= MF_STRING;
} else {
lpNewItem = (LPCTSTR) mePtr;
@@ -706,8 +702,7 @@ ReconfigureWindowsMenu(
}
}
if (!systemMenu) {
- (*tkWinProcs->insertMenu)(winMenuHdl, 0xFFFFFFFF, flags,
- itemID, lpNewItem);
+ InsertMenu(winMenuHdl, 0xFFFFFFFF, flags, itemID, lpNewItem);
}
Tcl_DStringFree(&translatedText);
if (itemText != NULL) {
@@ -719,8 +714,8 @@ ReconfigureWindowsMenu(
if ((menuPtr->menuType == MENUBAR)
&& (menuPtr->parentTopLevelPtr != NULL)) {
- HANDLE bar;
- bar = TkWinGetWrapperWindow(menuPtr->parentTopLevelPtr);
+ HANDLE bar = TkWinGetWrapperWindow(menuPtr->parentTopLevelPtr);
+
if (bar) {
DrawMenuBar(bar);
}
@@ -899,7 +894,7 @@ TkWinMenuProc(
LRESULT lResult;
if (!TkWinHandleMenuEvent(&hwnd, &message, &wParam, &lParam, &lResult)) {
- lResult = DefWindowProc(hwnd, message, wParam, lParam);
+ lResult = DefWindowProcA(hwnd, message, wParam, lParam);
}
return lResult;
}
@@ -997,7 +992,7 @@ TkWinEmbeddedMenuProc(
}
default:
- lResult = DefWindowProc(hwnd, message, wParam, lParam);
+ lResult = DefWindowProcA(hwnd, message, wParam, lParam);
break;
}
return lResult;
@@ -1076,7 +1071,7 @@ TkWinHandleMenuEvent(
if ((code != TCL_OK) && (code != TCL_CONTINUE)
&& (code != TCL_BREAK)) {
Tcl_AddErrorInfo(interp, "\n (menu preprocess)");
- Tcl_BackgroundError(interp);
+ Tcl_BackgroundException(interp, code);
}
Tcl_Release((ClientData)interp);
}
@@ -1117,7 +1112,7 @@ TkWinHandleMenuEvent(
if ((menuRefPtr != NULL) && (menuRefPtr->parentEntryPtr != NULL)) {
for (parentEntryPtr = menuRefPtr->parentEntryPtr ; ;
parentEntryPtr = parentEntryPtr->nextCascadePtr) {
- char *name = Tcl_GetString(parentEntryPtr->namePtr);
+ const char *name = Tcl_GetString(parentEntryPtr->namePtr);
if (strcmp(name, Tk_PathName(menuPtr->tkwin)) == 0) {
break;
@@ -1135,7 +1130,7 @@ TkWinHandleMenuEvent(
code = TkInvokeMenu(interp, menuPtr, mePtr->index);
if (code != TCL_OK && code != TCL_CONTINUE && code != TCL_BREAK) {
Tcl_AddErrorInfo(interp, "\n (menu invoke)");
- Tcl_BackgroundError(interp);
+ Tcl_BackgroundException(interp, code);
}
Tcl_Release((ClientData)interp);
*plResult = 0;
@@ -1218,7 +1213,7 @@ TkWinHandleMenuEvent(
}
mePtr = (TkMenuEntry *) itemPtr->itemData;
menuPtr = mePtr->menuPtr;
- twdPtr = (TkWinDrawable *) ckalloc(sizeof(TkWinDrawable));
+ twdPtr = ckalloc(sizeof(TkWinDrawable));
twdPtr->type = TWD_WINDC;
twdPtr->winDC.hdc = itemPtr->hDC;
@@ -1261,7 +1256,7 @@ TkWinHandleMenuEvent(
itemPtr->rcItem.bottom - itemPtr->rcItem.top,
0, drawingParameters);
- ckfree((char *) twdPtr);
+ ckfree(twdPtr);
}
*plResult = 1;
returnResult = 1;
@@ -1309,7 +1304,7 @@ TkWinHandleMenuEvent(
TkActivateMenuEntry(menuPtr, -1);
} else {
if (mePtr->index >= menuPtr->numEntries) {
- Tcl_Panic("Trying to activate an entry which doesn't exist.");
+ Tcl_Panic("Trying to activate an entry which doesn't exist");
}
TkActivateMenuEntry(menuPtr, mePtr->index);
}
@@ -1404,7 +1399,7 @@ TkpSetWindowMenuBar(
winMenuHdl = CreateMenu();
hashEntryPtr = Tcl_CreateHashEntry(&tsdPtr->winMenuTable,
(char *) winMenuHdl, &newEntry);
- Tcl_SetHashValue(hashEntryPtr, (char *) menuPtr);
+ Tcl_SetHashValue(hashEntryPtr, menuPtr);
menuPtr->platformData = (TkMenuPlatformData) winMenuHdl;
TkWinSetMenu(tkwin, winMenuHdl);
if (!(menuPtr->menuFlags & MENU_RECONFIGURE_PENDING)) {
@@ -1437,7 +1432,7 @@ void
TkpSetMainMenubar(
Tcl_Interp *interp, /* The interpreter of the application */
Tk_Window tkwin, /* The frame we are setting up */
- char *menuName) /* The name of the menu to put in front. If
+ const char *menuName) /* The name of the menu to put in front. If
* NULL, use the default menu bar. */
{
/*
@@ -1513,7 +1508,7 @@ GetMenuAccelGeometry(
} else if (mePtr->accelPtr == NULL) {
*widthPtr = 0;
} else {
- char *accel = Tcl_GetString(mePtr->accelPtr);
+ const char *accel = Tcl_GetString(mePtr->accelPtr);
*widthPtr = Tk_TextWidth(tkfont, accel, mePtr->accelLength);
}
@@ -1628,7 +1623,7 @@ DrawWindowsSystemBitmap(
SelectObject(scratchDC, bitmap);
SetMapMode(scratchDC, GetMapMode(hdc));
- GetObject(bitmap, sizeof(BITMAP), &bm);
+ GetObjectA(bitmap, sizeof(BITMAP), &bm);
ptSize.x = bm.bmWidth;
ptSize.y = bm.bmHeight;
DPtoLP(scratchDC, &ptSize, 1);
@@ -1769,7 +1764,7 @@ DrawMenuEntryAccelerator(
{
int baseline;
int leftEdge = x + mePtr->indicatorSpace + mePtr->labelWidth;
- char *accel;
+ const char *accel;
if (mePtr->accelPtr != NULL) {
accel = Tcl_GetString(mePtr->accelPtr);
@@ -2028,33 +2023,33 @@ TkWinMenuKeyObjCmd(
if (eventPtr->type == KeyPress) {
switch (keySym) {
case XK_Alt_L:
- scanCode = MapVirtualKey(VK_LMENU, 0);
- CallWindowProc(DefWindowProc, Tk_GetHWND(Tk_WindowId(tkwin)),
+ scanCode = MapVirtualKeyA(VK_LMENU, 0);
+ CallWindowProcA(DefWindowProcA, Tk_GetHWND(Tk_WindowId(tkwin)),
WM_SYSKEYDOWN, VK_MENU,
(int) (scanCode << 16) | (1 << 29));
break;
case XK_Alt_R:
- scanCode = MapVirtualKey(VK_RMENU, 0);
- CallWindowProc(DefWindowProc, Tk_GetHWND(Tk_WindowId(tkwin)),
+ scanCode = MapVirtualKeyA(VK_RMENU, 0);
+ CallWindowProcA(DefWindowProcA, Tk_GetHWND(Tk_WindowId(tkwin)),
WM_SYSKEYDOWN, VK_MENU,
(int) (scanCode << 16) | (1 << 29) | (1 << 24));
break;
case XK_F10:
- scanCode = MapVirtualKey(VK_F10, 0);
- CallWindowProc(DefWindowProc, Tk_GetHWND(Tk_WindowId(tkwin)),
+ scanCode = MapVirtualKeyA(VK_F10, 0);
+ CallWindowProcA(DefWindowProcA, Tk_GetHWND(Tk_WindowId(tkwin)),
WM_SYSKEYDOWN, VK_F10, (int) (scanCode << 16));
break;
default:
virtualKey = XKeysymToKeycode(winPtr->display, keySym);
- scanCode = MapVirtualKey(virtualKey, 0);
+ scanCode = MapVirtualKeyA(virtualKey, 0);
if (0 != scanCode) {
XKeyEvent xkey = eventPtr->xkey;
- CallWindowProc(DefWindowProc, Tk_GetHWND(Tk_WindowId(tkwin)),
+ CallWindowProcA(DefWindowProcA, Tk_GetHWND(Tk_WindowId(tkwin)),
WM_SYSKEYDOWN, virtualKey,
(int) ((scanCode << 16) | (1 << 29)));
if (xkey.nbytes > 0) {
for (i = 0; i < xkey.nbytes; i++) {
- CallWindowProc(DefWindowProc,
+ CallWindowProcA(DefWindowProcA,
Tk_GetHWND(Tk_WindowId(tkwin)), WM_SYSCHAR,
xkey.trans_chars[i],
(int) ((scanCode << 16) | (1 << 29)));
@@ -2065,28 +2060,28 @@ TkWinMenuKeyObjCmd(
} else if (eventPtr->type == KeyRelease) {
switch (keySym) {
case XK_Alt_L:
- scanCode = MapVirtualKey(VK_LMENU, 0);
- CallWindowProc(DefWindowProc, Tk_GetHWND(Tk_WindowId(tkwin)),
+ scanCode = MapVirtualKeyA(VK_LMENU, 0);
+ CallWindowProcA(DefWindowProcA, Tk_GetHWND(Tk_WindowId(tkwin)),
WM_SYSKEYUP, VK_MENU, (int) (scanCode << 16)
| (1 << 29) | (1 << 30) | (1 << 31));
break;
case XK_Alt_R:
- scanCode = MapVirtualKey(VK_RMENU, 0);
- CallWindowProc(DefWindowProc, Tk_GetHWND(Tk_WindowId(tkwin)),
+ scanCode = MapVirtualKeyA(VK_RMENU, 0);
+ CallWindowProcA(DefWindowProcA, Tk_GetHWND(Tk_WindowId(tkwin)),
WM_SYSKEYUP, VK_MENU, (int) (scanCode << 16) | (1 << 24)
| (0x111 << 29) | (1 << 30) | (1 << 31));
break;
case XK_F10:
- scanCode = MapVirtualKey(VK_F10, 0);
- CallWindowProc(DefWindowProc, Tk_GetHWND(Tk_WindowId(tkwin)),
+ scanCode = MapVirtualKeyA(VK_F10, 0);
+ CallWindowProcA(DefWindowProcA, Tk_GetHWND(Tk_WindowId(tkwin)),
WM_SYSKEYUP, VK_F10,
(int) (scanCode << 16) | (1 << 30) | (1 << 31));
break;
default:
virtualKey = XKeysymToKeycode(winPtr->display, keySym);
- scanCode = MapVirtualKey(virtualKey, 0);
+ scanCode = MapVirtualKeyA(virtualKey, 0);
if (0 != scanCode) {
- CallWindowProc(DefWindowProc, Tk_GetHWND(Tk_WindowId(tkwin)),
+ CallWindowProcA(DefWindowProcA, Tk_GetHWND(Tk_WindowId(tkwin)),
WM_SYSKEYUP, virtualKey, (int) ((scanCode << 16)
| (1 << 29) | (1 << 30) | (1 << 31)));
}
@@ -2217,7 +2212,7 @@ DrawMenuEntryLabel(
}
if (!haveImage || (mePtr->compound != COMPOUND_NONE)) {
if (mePtr->labelLength > 0) {
- char *label = Tcl_GetString(mePtr->labelPtr);
+ const char *label = Tcl_GetString(mePtr->labelPtr);
textWidth = Tk_TextWidth(tkfont, label, mePtr->labelLength);
textHeight = fmPtr->linespace;
@@ -2312,7 +2307,7 @@ DrawMenuEntryLabel(
if ((mePtr->compound != COMPOUND_NONE) || !haveImage) {
if (mePtr->labelLength > 0) {
int baseline = y + (height + fmPtr->ascent - fmPtr->descent) / 2;
- char *label = Tcl_GetString(mePtr->labelPtr);
+ const char *label = Tcl_GetString(mePtr->labelPtr);
if (TkWinGetPlatformTheme() == TK_THEME_WIN_CLASSIC) {
/*
@@ -2548,7 +2543,7 @@ TkpDrawMenuEntry(
} else {
TkMenuEntry *cascadeEntryPtr;
int parentDisabled = 0;
- char *name;
+ const char *name;
for (cascadeEntryPtr = menuPtr->menuRefPtr->parentEntryPtr;
cascadeEntryPtr != NULL;
@@ -2694,7 +2689,7 @@ GetMenuLabelGeometry(
if (mePtr->labelPtr != NULL) {
int textWidth;
- char *label = Tcl_GetString(mePtr->labelPtr);
+ const char *label = Tcl_GetString(mePtr->labelPtr);
textWidth = Tk_TextWidth(tkfont, label, mePtr->labelLength);
@@ -3024,7 +3019,7 @@ MenuSelectEvent(
void
TkpMenuNotifyToplevelCreate(
Tcl_Interp *interp, /* The interp the menu lives in. */
- char *menuName) /* The name of the menu to reconfigure. */
+ const char *menuName) /* The name of the menu to reconfigure. */
{
TkMenuReferences *menuRefPtr;
TkMenu *menuPtr;
@@ -3195,7 +3190,7 @@ SetDefaults(
HDC scratchDC;
int bold = 0;
int italic = 0;
- TEXTMETRIC tm;
+ TEXTMETRICA tm;
int pointSize;
HFONT menuFont;
/* See: [Bug #3239768] tk8.4.19 (and later) WIN32 menu font support */
@@ -3217,7 +3212,7 @@ SetDefaults(
defaultBorderWidth = GetSystemMetrics(SM_CYBORDER);
}
- scratchDC = CreateDC("DISPLAY", NULL, NULL, NULL);
+ scratchDC = CreateDCA("DISPLAY", NULL, NULL, NULL);
if (!firstTime) {
Tcl_DStringFree(&menuFontDString);
}
@@ -3235,8 +3230,8 @@ SetDefaults(
&nc.metrics, 0);
menuFont = CreateFontIndirect(&nc.metrics.lfMenuFont);
SelectObject(scratchDC, menuFont);
- GetTextMetrics(scratchDC, &tm);
- GetTextFace(scratchDC, LF_FACESIZE, faceName);
+ GetTextMetricsA(scratchDC, &tm);
+ GetTextFaceA(scratchDC, LF_FACESIZE, faceName);
pointSize = MulDiv(tm.tmHeight - tm.tmInternalLeading,
72, GetDeviceCaps(scratchDC, LOGPIXELSY));
if (tm.tmWeight >= 700) {
@@ -3279,17 +3274,11 @@ SetDefaults(
* only way to ensure menu items line up, and is not documented.
*/
- if (TkWinGetPlatformId() >= VER_PLATFORM_WIN32_WINDOWS) {
- indicatorDimensions[0] = GetSystemMetrics(SM_CYMENUCHECK);
- indicatorDimensions[1] = ((GetSystemMetrics(SM_CXFIXEDFRAME) +
- GetSystemMetrics(SM_CXBORDER)
- + GetSystemMetrics(SM_CXMENUCHECK) + 7) & 0xFFF8)
- - GetSystemMetrics(SM_CXFIXEDFRAME);
- } else {
- DWORD dimensions = GetMenuCheckMarkDimensions();
- indicatorDimensions[0] = HIWORD(dimensions);
- indicatorDimensions[1] = LOWORD(dimensions);
- }
+ indicatorDimensions[0] = GetSystemMetrics(SM_CYMENUCHECK);
+ indicatorDimensions[1] = ((GetSystemMetrics(SM_CXFIXEDFRAME) +
+ GetSystemMetrics(SM_CXBORDER)
+ + GetSystemMetrics(SM_CXMENUCHECK) + 7) & 0xFFF8)
+ - GetSystemMetrics(SM_CXFIXEDFRAME);
/*
* Accelerators used to be always underlines until Win2K when a system
@@ -3298,7 +3287,7 @@ SetDefaults(
showMenuAccelerators = TRUE;
if (TkWinGetPlatformId() == VER_PLATFORM_WIN32_NT) {
- SystemParametersInfo(SPI_GETKEYBOARDCUES, 0, &showMenuAccelerators, 0);
+ SystemParametersInfoA(SPI_GETKEYBOARDCUES, 0, &showMenuAccelerators, 0);
}
}
@@ -3334,13 +3323,13 @@ TkpMenuInit(void)
wndClass.lpszMenuName = NULL;
wndClass.lpszClassName = MENU_CLASS_NAME;
if (!RegisterClass(&wndClass)) {
- Tcl_Panic("Failed to register menu window class.");
+ Tcl_Panic("Failed to register menu window class");
}
wndClass.lpfnWndProc = TkWinEmbeddedMenuProc;
wndClass.lpszClassName = EMBEDDED_MENU_CLASS_NAME;
if (!RegisterClass(&wndClass)) {
- Tcl_Panic("Failed to register embedded menu window class.");
+ Tcl_Panic("Failed to register embedded menu window class");
}
TkCreateExitHandler(MenuExitHandler, (ClientData) NULL);
@@ -3370,19 +3359,19 @@ TkpMenuThreadInit(void)
ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));
- tsdPtr->menuHWND = CreateWindow(MENU_CLASS_NAME, "MenuWindow", WS_POPUP,
+ tsdPtr->menuHWND = CreateWindow(MENU_CLASS_NAME, TEXT("MenuWindow"), WS_POPUP,
0, 0, 10, 10, NULL, NULL, Tk_GetHINSTANCE(), NULL);
if (!tsdPtr->menuHWND) {
- Tcl_Panic("Failed to create the menu window.");
+ Tcl_Panic("Failed to create the menu window");
}
tsdPtr->embeddedMenuHWND =
- CreateWindow(EMBEDDED_MENU_CLASS_NAME, "EmbeddedMenuWindow",
+ CreateWindow(EMBEDDED_MENU_CLASS_NAME, TEXT("EmbeddedMenuWindow"),
WS_POPUP, 0, 0, 10, 10, NULL, NULL, Tk_GetHINSTANCE(), NULL);
if (!tsdPtr->embeddedMenuHWND) {
- Tcl_Panic("Failed to create the embedded menu window.");
+ Tcl_Panic("Failed to create the embedded menu window");
}
Tcl_InitHashTable(&tsdPtr->winMenuTable, TCL_ONE_WORD_KEYS);