summaryrefslogtreecommitdiffstats
path: root/win/tkWinSysTray.c
diff options
context:
space:
mode:
Diffstat (limited to 'win/tkWinSysTray.c')
-rw-r--r--win/tkWinSysTray.c806
1 files changed, 403 insertions, 403 deletions
diff --git a/win/tkWinSysTray.c b/win/tkWinSysTray.c
index 6c8893e..a710ee6 100644
--- a/win/tkWinSysTray.c
+++ b/win/tkWinSysTray.c
@@ -36,11 +36,11 @@
typedef struct IcoInfo {
HICON hIcon; /* icon handle returned by LoadIcon. */
unsigned id; /* Identifier for command; used to
- * cancel it. */
+ * cancel it. */
Tcl_Obj *taskbar_txt; /* text to display in the taskbar */
Tcl_Interp *interp; /* interp which created the icon */
Tcl_Obj *taskbar_command; /* command to eval if events in the taskbar
- * arrive */
+ * arrive */
int taskbar_flags; /* taskbar related flags*/
HWND hwndFocus;
struct IcoInfo *nextPtr;
@@ -102,9 +102,9 @@ DrawXORMask(
/* Sanity checks */
if (lpIcon == NULL)
- return FALSE;
+ return FALSE;
if (lpIcon->lpBits == NULL)
- return FALSE;
+ return FALSE;
/* Account for height*2 thing */
lpIcon->lpbi->bmiHeader.biHeight /= 2;
@@ -115,10 +115,10 @@ DrawXORMask(
/* Blast it to the screen */
SetDIBitsToDevice(hDC, x, y,
- lpIcon->lpbi->bmiHeader.biWidth,
- lpIcon->lpbi->bmiHeader.biHeight,
- 0, 0, 0, lpIcon->lpbi->bmiHeader.biHeight,
- lpIcon->lpXOR, lpIcon->lpbi, DIB_RGB_COLORS);
+ lpIcon->lpbi->bmiHeader.biWidth,
+ lpIcon->lpbi->bmiHeader.biHeight,
+ 0, 0, 0, lpIcon->lpbi->bmiHeader.biHeight,
+ lpIcon->lpXOR, lpIcon->lpbi, DIB_RGB_COLORS);
/* UnAccount for height*2 thing */
lpIcon->lpbi->bmiHeader.biHeight *= 2;
@@ -153,9 +153,9 @@ DrawANDMask(
/* Sanity checks */
if (lpIcon == NULL)
- return FALSE;
+ return FALSE;
if (lpIcon->lpBits == NULL)
- return FALSE;
+ return FALSE;
/* Need a bitmap header for the mono mask */
lpbi = ckalloc(sizeof(BITMAPINFO) + (2 * sizeof(RGBQUAD)));
@@ -185,10 +185,10 @@ DrawANDMask(
/* Blast it to the screen */
SetDIBitsToDevice(hDC, x, y,
- lpbi->bmiHeader.biWidth,
- lpbi->bmiHeader.biHeight,
- 0, 0, 0, lpbi->bmiHeader.biHeight,
- lpIcon->lpAND, lpbi, DIB_RGB_COLORS);
+ lpbi->bmiHeader.biWidth,
+ lpbi->bmiHeader.biHeight,
+ 0, 0, 0, lpbi->bmiHeader.biHeight,
+ lpIcon->lpAND, lpbi, DIB_RGB_COLORS);
/* clean up */
ckfree(lpbi);
@@ -230,22 +230,22 @@ TaskbarOperation(
ni.hIcon = icoPtr->hIcon;
if (icoPtr->taskbar_txt != NULL) {
- Tcl_DString dst;
- Tcl_DStringInit(&dst);
- str = (WCHAR *)Tcl_UtfToWCharDString(Tcl_GetString(icoPtr->taskbar_txt), TCL_INDEX_NONE, &dst);
- wcsncpy(ni.szTip, str, (Tcl_DStringLength(&dst) + 2) / 2);
- Tcl_DStringFree(&dst);
+ Tcl_DString dst;
+ Tcl_DStringInit(&dst);
+ str = (WCHAR *)Tcl_UtfToWCharDString(Tcl_GetString(icoPtr->taskbar_txt), TCL_INDEX_NONE, &dst);
+ wcsncpy(ni.szTip, str, (Tcl_DStringLength(&dst) + 2) / 2);
+ Tcl_DStringFree(&dst);
} else {
- ni.szTip[0] = 0;
+ ni.szTip[0] = 0;
}
if (Shell_NotifyIconW(oper, &ni) == 1) {
- if (oper == NIM_ADD || oper == NIM_MODIFY) {
- icoPtr->taskbar_flags |= TASKBAR_ICON;
- }
- if (oper == NIM_DELETE) {
- icoPtr->taskbar_flags &= ~TASKBAR_ICON;
- }
+ if (oper == NIM_ADD || oper == NIM_MODIFY) {
+ icoPtr->taskbar_flags |= TASKBAR_ICON;
+ }
+ if (oper == NIM_DELETE) {
+ icoPtr->taskbar_flags &= ~TASKBAR_ICON;
+ }
}
/* Silently ignore error? */
return TCL_OK;
@@ -312,22 +312,22 @@ FreeIcoPtr(
{
IcoInfo *prevPtr;
if (icoInterpPtr->firstIcoPtr == icoPtr) {
- icoInterpPtr->firstIcoPtr = icoPtr->nextPtr;
+ icoInterpPtr->firstIcoPtr = icoPtr->nextPtr;
} else {
- for (prevPtr = icoInterpPtr->firstIcoPtr; prevPtr->nextPtr != icoPtr;
- prevPtr = prevPtr->nextPtr) {
- /* Empty loop body. */
- }
- prevPtr->nextPtr = icoPtr->nextPtr;
+ for (prevPtr = icoInterpPtr->firstIcoPtr; prevPtr->nextPtr != icoPtr;
+ prevPtr = prevPtr->nextPtr) {
+ /* Empty loop body. */
+ }
+ prevPtr->nextPtr = icoPtr->nextPtr;
}
if (icoPtr->taskbar_flags & TASKBAR_ICON) {
- TaskbarOperation(icoInterpPtr, icoPtr, NIM_DELETE);
+ TaskbarOperation(icoInterpPtr, icoPtr, NIM_DELETE);
}
if (icoPtr->taskbar_txt != NULL) {
- Tcl_DecrRefCount(icoPtr->taskbar_txt);
+ Tcl_DecrRefCount(icoPtr->taskbar_txt);
}
if (icoPtr->taskbar_command != NULL) {
- Tcl_DecrRefCount(icoPtr->taskbar_command);
+ Tcl_DecrRefCount(icoPtr->taskbar_command);
}
ckfree(icoPtr);
}
@@ -360,22 +360,22 @@ GetIcoPtr(
char *end;
if (strncmp(string, "ico#", 4) != 0) {
- goto notfound;
+ goto notfound;
}
start = string + 4;
id = strtoul(start, &end, 10);
if ((end == start) || (*end != 0)) {
- goto notfound;
+ goto notfound;
}
for (icoPtr = icoInterpPtr->firstIcoPtr; icoPtr != NULL; icoPtr = icoPtr->nextPtr) {
- if (icoPtr->id == id) {
- return icoPtr;
- }
+ if (icoPtr->id == id) {
+ return icoPtr;
+ }
}
notfound:
Tcl_AppendResult(interp, "icon \"", string,
- "\" doesn't exist", NULL);
+ "\" doesn't exist", NULL);
return NULL;
}
@@ -466,117 +466,117 @@ TaskbarExpandPercents(
char* dst;
dst = after;
while (*before) {
- const char *ptr = before;
- int len = 1;
- if(*before == '%') {
- switch(before[1]){
- case 'M':
- case 'm': {
- before++;
- len = strlen(msgstring);
- ptr = msgstring;
- break;
- }
- /* case 'W': {
- before++;
- len = (int)strlen(winstring);
- ptr = winstring;
- break;
- }
- */
- case 'i': {
- before++;
- snprintf(buffer, sizeof(buffer) - 1, "ico#%d", icoPtr->id);
- len = strlen(buffer);
- ptr = buffer;
- break;
- }
- case 'w': {
- before++;
- len = GetInt((long)wParam,buffer, sizeof(buffer));
- ptr = buffer;
- break;
- }
- case 'l': {
- before++;
- len = GetInt((long)lParam,buffer, sizeof(buffer));
- ptr = buffer;
- break;
- }
- case 't': {
- before++;
- len = GetInt((long)GetTickCount(), buffer, sizeof(buffer));
- ptr = buffer;
- break;
- }
- case 'x': {
- POINT pt;
- GetCursorPos(&pt);
- before++;
- len = GetIntDec((long)pt.x, buffer, sizeof(buffer));
- ptr = buffer;
- break;
- }
- case 'y': {
- POINT pt;
- GetCursorPos(&pt);
- before++;
- len = GetIntDec((long)pt.y,buffer, sizeof(buffer));
- ptr = buffer;
- break;
- }
- case 'X': {
- DWORD dw;
- dw = GetMessagePos();
- before++;
- len = GetIntDec((long)LOWORD(dw),buffer, sizeof(buffer));
- ptr = buffer;
- break;
- }
- case 'Y': {
- DWORD dw;
- dw = GetMessagePos();
- before++;
- len = GetIntDec((long)HIWORD(dw),buffer, sizeof(buffer));
- ptr = buffer;
- break;
- }
- case 'H': {
- before++;
- len = GetInt(PTR2INT(icoPtr->hwndFocus), buffer, sizeof(buffer));
- ptr = buffer;
- break;
- }
- case '%': {
- before++;
- len = 1;
- ptr = "%";
- break;
- }
- }
- }
- if (SPACELEFT < len) {
- char *newspace;
- ptrdiff_t dist = dst - after;
- int alloclen = ALLOCLEN;
- newspace = (char *)ckalloc(alloclen);
- if (dist>0)
- memcpy(newspace, after, dist);
- if (after && *aftersize) {
- ckfree(after);
- }
- *aftersize =alloclen;
- after = newspace;
- dst = after + dist;
- }
- if (len > 0) {
- memcpy(dst, ptr, len);
- }
- dst += len;
- if ((dst-after)>(*aftersize-1)) {
- printf("oops\n");
- }
- before++;
+ const char *ptr = before;
+ int len = 1;
+ if(*before == '%') {
+ switch(before[1]){
+ case 'M':
+ case 'm': {
+ before++;
+ len = strlen(msgstring);
+ ptr = msgstring;
+ break;
+ }
+ /* case 'W': {
+ before++;
+ len = (int)strlen(winstring);
+ ptr = winstring;
+ break;
+ }
+ */
+ case 'i': {
+ before++;
+ snprintf(buffer, sizeof(buffer) - 1, "ico#%d", icoPtr->id);
+ len = strlen(buffer);
+ ptr = buffer;
+ break;
+ }
+ case 'w': {
+ before++;
+ len = GetInt((long)wParam,buffer, sizeof(buffer));
+ ptr = buffer;
+ break;
+ }
+ case 'l': {
+ before++;
+ len = GetInt((long)lParam,buffer, sizeof(buffer));
+ ptr = buffer;
+ break;
+ }
+ case 't': {
+ before++;
+ len = GetInt((long)GetTickCount(), buffer, sizeof(buffer));
+ ptr = buffer;
+ break;
+ }
+ case 'x': {
+ POINT pt;
+ GetCursorPos(&pt);
+ before++;
+ len = GetIntDec((long)pt.x, buffer, sizeof(buffer));
+ ptr = buffer;
+ break;
+ }
+ case 'y': {
+ POINT pt;
+ GetCursorPos(&pt);
+ before++;
+ len = GetIntDec((long)pt.y,buffer, sizeof(buffer));
+ ptr = buffer;
+ break;
+ }
+ case 'X': {
+ DWORD dw;
+ dw = GetMessagePos();
+ before++;
+ len = GetIntDec((long)LOWORD(dw),buffer, sizeof(buffer));
+ ptr = buffer;
+ break;
+ }
+ case 'Y': {
+ DWORD dw;
+ dw = GetMessagePos();
+ before++;
+ len = GetIntDec((long)HIWORD(dw),buffer, sizeof(buffer));
+ ptr = buffer;
+ break;
+ }
+ case 'H': {
+ before++;
+ len = GetInt(PTR2INT(icoPtr->hwndFocus), buffer, sizeof(buffer));
+ ptr = buffer;
+ break;
+ }
+ case '%': {
+ before++;
+ len = 1;
+ ptr = "%";
+ break;
+ }
+ }
+ }
+ if (SPACELEFT < len) {
+ char *newspace;
+ ptrdiff_t dist = dst - after;
+ int alloclen = ALLOCLEN;
+ newspace = (char *)ckalloc(alloclen);
+ if (dist>0)
+ memcpy(newspace, after, dist);
+ if (after && *aftersize) {
+ ckfree(after);
+ }
+ *aftersize =alloclen;
+ after = newspace;
+ dst = after + dist;
+ }
+ if (len > 0) {
+ memcpy(dst, ptr, len);
+ }
+ dst += len;
+ if ((dst-after)>(*aftersize-1)) {
+ printf("oops\n");
+ }
+ before++;
}
*dst = 0;
return after;
@@ -612,87 +612,87 @@ TaskbarEval(
switch (lParam) {
case WM_MOUSEMOVE:
- msgstring = "WM_MOUSEMOVE";
- icoPtr->hwndFocus = GetFocus();
- break;
+ msgstring = "WM_MOUSEMOVE";
+ icoPtr->hwndFocus = GetFocus();
+ break;
case WM_LBUTTONDOWN:
- msgstring = "WM_LBUTTONDOWN";
- fixup = 1;
- break;
+ msgstring = "WM_LBUTTONDOWN";
+ fixup = 1;
+ break;
case WM_LBUTTONUP:
- msgstring = "WM_LBUTTONUP";
- fixup = 1;
- break;
+ msgstring = "WM_LBUTTONUP";
+ fixup = 1;
+ break;
case WM_LBUTTONDBLCLK:
- msgstring = "WM_LBUTTONDBLCLK";
- fixup = 1;
- break;
+ msgstring = "WM_LBUTTONDBLCLK";
+ fixup = 1;
+ break;
case WM_RBUTTONDOWN:
- msgstring = "WM_RBUTTONDOWN";
- fixup = 1;
- break;
+ msgstring = "WM_RBUTTONDOWN";
+ fixup = 1;
+ break;
case WM_RBUTTONUP:
- msgstring = "WM_RBUTTONUP";
- fixup = 1;
- break;
+ msgstring = "WM_RBUTTONUP";
+ fixup = 1;
+ break;
case WM_RBUTTONDBLCLK:
- msgstring = "WM_RBUTTONDBLCLK";
- fixup = 1;
- break;
+ msgstring = "WM_RBUTTONDBLCLK";
+ fixup = 1;
+ break;
case WM_MBUTTONDOWN:
- msgstring = "WM_MBUTTONDOWN";
- fixup = 1;
- break;
+ msgstring = "WM_MBUTTONDOWN";
+ fixup = 1;
+ break;
case WM_MBUTTONUP:
- msgstring = "WM_MBUTTONUP";
- fixup = 1;
- break;
+ msgstring = "WM_MBUTTONUP";
+ fixup = 1;
+ break;
case WM_MBUTTONDBLCLK:
- msgstring = "WM_MBUTTONDBLCLK";
- fixup = 1;
- break;
+ msgstring = "WM_MBUTTONDBLCLK";
+ fixup = 1;
+ break;
default:
- msgstring = "WM_NULL";
- fixup = 0;
+ msgstring = "WM_NULL";
+ fixup = 0;
}
expanded = TaskbarExpandPercents(icoPtr, msgstring, wParam, lParam,
- Tcl_GetString(icoPtr->taskbar_command), evalspace, &evalsize);
+ Tcl_GetString(icoPtr->taskbar_command), evalspace, &evalsize);
if (icoPtr->interp != NULL) {
- int result;
- HWND hwnd = NULL;
-
- /* See http://support.microsoft.com/kb/q135788/
- * Seems to have moved to https://www.betaarchive.com/wiki/index.php/Microsoft_KB_Archive/135788 */
- if (fixup) {
- if (icoPtr->hwndFocus != NULL && IsWindow(icoPtr->hwndFocus)) {
- hwnd = icoPtr->hwndFocus;
- } else {
- Tk_Window tkwin = Tk_MainWindow(icoPtr->interp);
- if (tkwin != NULL) {
- hwnd = Tk_GetHWND(Tk_WindowId(tkwin));
- }
- }
- if (hwnd != NULL) {
- SetForegroundWindow(hwnd);
- }
- }
-
- result = Tcl_GlobalEval(icoPtr->interp, expanded);
-
- if (hwnd != NULL) {
- /* See http://support.microsoft.com/kb/q135788/
- * Seems to have moved to https://www.betaarchive.com/wiki/index.php/Microsoft_KB_Archive/135788 */
- PostMessageW(hwnd, WM_NULL, 0, 0);
- }
- if (result != TCL_OK) {
- char buffer[100];
- snprintf(buffer, 100, "\n (command bound to taskbar-icon ico#%d)", icoPtr->id);
- Tcl_AddErrorInfo(icoPtr->interp, buffer);
- Tcl_BackgroundError(icoPtr->interp);
- }
+ int result;
+ HWND hwnd = NULL;
+
+ /* See http://support.microsoft.com/kb/q135788/
+ * Seems to have moved to https://www.betaarchive.com/wiki/index.php/Microsoft_KB_Archive/135788 */
+ if (fixup) {
+ if (icoPtr->hwndFocus != NULL && IsWindow(icoPtr->hwndFocus)) {
+ hwnd = icoPtr->hwndFocus;
+ } else {
+ Tk_Window tkwin = Tk_MainWindow(icoPtr->interp);
+ if (tkwin != NULL) {
+ hwnd = Tk_GetHWND(Tk_WindowId(tkwin));
+ }
+ }
+ if (hwnd != NULL) {
+ SetForegroundWindow(hwnd);
+ }
+ }
+
+ result = Tcl_GlobalEval(icoPtr->interp, expanded);
+
+ if (hwnd != NULL) {
+ /* See http://support.microsoft.com/kb/q135788/
+ * Seems to have moved to https://www.betaarchive.com/wiki/index.php/Microsoft_KB_Archive/135788 */
+ PostMessageW(hwnd, WM_NULL, 0, 0);
+ }
+ if (result != TCL_OK) {
+ char buffer[100];
+ snprintf(buffer, 100, "\n (command bound to taskbar-icon ico#%d)", icoPtr->id);
+ Tcl_AddErrorInfo(icoPtr->interp, buffer);
+ Tcl_BackgroundError(icoPtr->interp);
+ }
}
if (expanded != evalspace) {
- ckfree(expanded);
+ ckfree(expanded);
}
}
@@ -726,43 +726,43 @@ TaskbarHandlerProc(
switch (message) {
case WM_CREATE:
- msgTaskbarCreated = RegisterWindowMessage(TEXT("TaskbarCreated"));
- break;
+ msgTaskbarCreated = RegisterWindowMessage(TEXT("TaskbarCreated"));
+ break;
case ICON_MESSAGE:
- for (icoInterpPtr = firstIcoInterpPtr; icoInterpPtr != NULL; icoInterpPtr = icoInterpPtr->nextPtr) {
- if (icoInterpPtr->hwnd == hwnd) {
- for (icoPtr = icoInterpPtr->firstIcoPtr; icoPtr != NULL; icoPtr = icoPtr->nextPtr) {
- if (icoPtr->id == wParam) {
- if (icoPtr->taskbar_command != NULL) {
- TaskbarEval(icoPtr, wParam, lParam);
- }
- break;
- }
- }
- break;
- }
- }
- break;
+ for (icoInterpPtr = firstIcoInterpPtr; icoInterpPtr != NULL; icoInterpPtr = icoInterpPtr->nextPtr) {
+ if (icoInterpPtr->hwnd == hwnd) {
+ for (icoPtr = icoInterpPtr->firstIcoPtr; icoPtr != NULL; icoPtr = icoPtr->nextPtr) {
+ if (icoPtr->id == wParam) {
+ if (icoPtr->taskbar_command != NULL) {
+ TaskbarEval(icoPtr, wParam, lParam);
+ }
+ break;
+ }
+ }
+ break;
+ }
+ }
+ break;
default:
- /*
- * Check to see if explorer has been restarted and we need to
- * re-add our icons.
- */
- if (message == msgTaskbarCreated) {
- for (icoInterpPtr = firstIcoInterpPtr; icoInterpPtr != NULL; icoInterpPtr = icoInterpPtr->nextPtr) {
- if (icoInterpPtr->hwnd == hwnd) {
- for (icoPtr = icoInterpPtr->firstIcoPtr; icoPtr != NULL; icoPtr = icoPtr->nextPtr) {
- if (icoPtr->taskbar_flags & TASKBAR_ICON) {
- TaskbarOperation(icoInterpPtr, icoPtr, NIM_ADD);
- }
- }
- break;
- }
- }
- }
- return DefWindowProc(hwnd, message, wParam, lParam);
+ /*
+ * Check to see if explorer has been restarted and we need to
+ * re-add our icons.
+ */
+ if (message == msgTaskbarCreated) {
+ for (icoInterpPtr = firstIcoInterpPtr; icoInterpPtr != NULL; icoInterpPtr = icoInterpPtr->nextPtr) {
+ if (icoInterpPtr->hwnd == hwnd) {
+ for (icoPtr = icoInterpPtr->firstIcoPtr; icoPtr != NULL; icoPtr = icoPtr->nextPtr) {
+ if (icoPtr->taskbar_flags & TASKBAR_ICON) {
+ TaskbarOperation(icoInterpPtr, icoPtr, NIM_ADD);
+ }
+ }
+ break;
+ }
+ }
+ }
+ return DefWindowProc(hwnd, message, wParam, lParam);
}
return 0;
}
@@ -823,12 +823,12 @@ CreateTaskbarHandlerWindow(void) {
static int registered = 0;
HINSTANCE hInstance = GETHINSTANCE;
if (!registered) {
- if (!RegisterHandlerClass(hInstance))
- return 0;
- registered = 1;
+ if (!RegisterHandlerClass(hInstance))
+ return 0;
+ registered = 1;
}
return CreateWindow(HANDLER_CLASS, "", WS_OVERLAPPED, 0, 0,
- CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL);
+ CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL);
}
/*
@@ -860,23 +860,23 @@ WinIcoDestroy(
IcoInfo *nextPtr;
if (eventPtr->type != DestroyNotify) {
- return;
+ return;
}
if (firstIcoInterpPtr == icoInterpPtr) {
- firstIcoInterpPtr = icoInterpPtr->nextPtr;
+ firstIcoInterpPtr = icoInterpPtr->nextPtr;
} else {
- for (prevIcoInterpPtr = firstIcoInterpPtr; prevIcoInterpPtr->nextPtr != icoInterpPtr;
- prevIcoInterpPtr = prevIcoInterpPtr->nextPtr) {
- /* Empty loop body. */
- }
- prevIcoInterpPtr->nextPtr = icoInterpPtr->nextPtr;
+ for (prevIcoInterpPtr = firstIcoInterpPtr; prevIcoInterpPtr->nextPtr != icoInterpPtr;
+ prevIcoInterpPtr = prevIcoInterpPtr->nextPtr) {
+ /* Empty loop body. */
+ }
+ prevIcoInterpPtr->nextPtr = icoInterpPtr->nextPtr;
}
DestroyWindow(icoInterpPtr->hwnd);
for (icoPtr = icoInterpPtr->firstIcoPtr; icoPtr != NULL; icoPtr = nextPtr) {
- nextPtr = icoPtr->nextPtr;
- FreeIcoPtr(icoInterpPtr, icoPtr);
+ nextPtr = icoPtr->nextPtr;
+ FreeIcoPtr(icoInterpPtr, icoPtr);
}
ckfree(icoInterpPtr);
}
@@ -905,11 +905,11 @@ WinSystrayCmd(
Tcl_Obj *const objv[])
{
static const char *const cmdStrings[] = {
- "add", "delete", "modify", NULL
+ "add", "delete", "modify", NULL
};
enum { CMD_ADD, CMD_DELETE, CMD_MODIFY };
static const char *const optStrings[] = {
- "-callback", "-image", "-text", NULL
+ "-callback", "-image", "-text", NULL
};
enum { OPT_CALLBACK, OPT_IMAGE, OPT_TEXT };
int cmd, opt;
@@ -920,124 +920,124 @@ WinSystrayCmd(
IcoInfo *icoPtr = NULL;
if (objc < 2) {
- Tcl_WrongNumArgs(interp, 1, objv, "command ...");
- return TCL_ERROR;
+ Tcl_WrongNumArgs(interp, 1, objv, "command ...");
+ return TCL_ERROR;
}
if (Tcl_GetIndexFromObj(interp, objv[1], cmdStrings, "command",
- 0, &cmd) == TCL_ERROR) {
- return TCL_ERROR;
+ 0, &cmd) == TCL_ERROR) {
+ return TCL_ERROR;
}
switch (cmd) {
- case CMD_ADD:
- case CMD_MODIFY: {
- Tcl_Obj *imageObj = NULL, *textObj = NULL, *callbackObj = NULL;
- int optStart;
- int oper;
- if (cmd == CMD_ADD) {
- optStart = 2;
- oper = NIM_ADD;
- } else {
- optStart = 3;
- oper = NIM_MODIFY;
- if (objc != 5) {
- Tcl_WrongNumArgs(interp, 2, objv, "id option value");
- return TCL_ERROR;
- }
- icoPtr = GetIcoPtr(interp, icoInterpPtr, Tcl_GetString(objv[2]));
- if (icoPtr == NULL) {
- return TCL_ERROR;
- }
- }
- for (i = optStart; i < objc; i += 2) {
- if (Tcl_GetIndexFromObj(interp, objv[i], optStrings, "option",
- 0, &opt) == TCL_ERROR) {
- return TCL_ERROR;
- }
- if (i+1 >= objc) {
- Tcl_AppendResult(interp,
- "missing value for option \"", Tcl_GetString(objv[i]),
- "\"", NULL);
- return TCL_ERROR;
- }
- switch (opt) {
- case OPT_IMAGE:
- imageObj = objv[i+1];
- break;
- case OPT_TEXT:
- textObj = objv[i+1];
- break;
- case OPT_CALLBACK:
- callbackObj = objv[i+1];
- break;
- }
- }
- if (cmd == CMD_ADD && imageObj == NULL) {
- Tcl_SetObjResult(interp, Tcl_NewStringObj("missing required option \"-image\"", TCL_INDEX_NONE));
- return TCL_ERROR;
- }
- if (imageObj != NULL) {
- Tk_PhotoHandle photo;
- int width, height;
- Tk_PhotoImageBlock block;
-
- photo = Tk_FindPhoto(interp, Tcl_GetString(imageObj));
- if (photo == NULL) {
- Tcl_SetObjResult(interp, Tcl_ObjPrintf(
- "image \"%s\" doesn't exist", Tcl_GetString(imageObj)));
- return TCL_ERROR;
- }
- Tk_PhotoGetSize(photo, &width, &height);
- Tk_PhotoGetImage(photo, &block);
- hIcon = CreateIcoFromPhoto(width, height, block);
- if (hIcon == NULL) {
- Tcl_SetObjResult(interp, Tcl_ObjPrintf(
- "failed to create an iconphoto with image \"%s\"", Tcl_GetString(imageObj)));
- return TCL_ERROR;
- }
- }
- if (cmd == CMD_ADD) {
- icoPtr = NewIcon(interp, icoInterpPtr, hIcon);
- } else {
- if (imageObj != NULL) {
- DestroyIcon(icoPtr->hIcon);
- icoPtr->hIcon = hIcon;
- }
- }
- if (callbackObj != NULL) {
- if (icoPtr->taskbar_command != NULL) {
- Tcl_DecrRefCount(icoPtr->taskbar_command);
- }
- icoPtr->taskbar_command = callbackObj;
- Tcl_IncrRefCount(icoPtr->taskbar_command);
- }
- if (textObj != NULL) {
- if (icoPtr->taskbar_txt != NULL) {
- Tcl_DecrRefCount(icoPtr->taskbar_txt);
- }
- icoPtr->taskbar_txt = textObj;
- Tcl_IncrRefCount(icoPtr->taskbar_txt);
- }
- TaskbarOperation(icoInterpPtr, icoPtr, oper);
- if (cmd == CMD_ADD) {
- char buffer[5 + TCL_INTEGER_SPACE];
- int n;
- n = snprintf(buffer, sizeof(buffer) - 1, "ico#%d", icoPtr->id);
- buffer[n] = 0;
- Tcl_SetObjResult(interp, Tcl_NewStringObj(buffer, n));
- }
- return TCL_OK;
- }
- case CMD_DELETE:
- if (objc != 3) {
- Tcl_WrongNumArgs(interp, 2, objv, "id");
- return TCL_ERROR;
- }
- icoPtr = GetIcoPtr(interp, icoInterpPtr, Tcl_GetString(objv[2]));
- if (icoPtr == NULL) {
- return TCL_ERROR;
- }
- FreeIcoPtr(icoInterpPtr, icoPtr);
- return TCL_OK;
+ case CMD_ADD:
+ case CMD_MODIFY: {
+ Tcl_Obj *imageObj = NULL, *textObj = NULL, *callbackObj = NULL;
+ int optStart;
+ int oper;
+ if (cmd == CMD_ADD) {
+ optStart = 2;
+ oper = NIM_ADD;
+ } else {
+ optStart = 3;
+ oper = NIM_MODIFY;
+ if (objc != 5) {
+ Tcl_WrongNumArgs(interp, 2, objv, "id option value");
+ return TCL_ERROR;
+ }
+ icoPtr = GetIcoPtr(interp, icoInterpPtr, Tcl_GetString(objv[2]));
+ if (icoPtr == NULL) {
+ return TCL_ERROR;
+ }
+ }
+ for (i = optStart; i < objc; i += 2) {
+ if (Tcl_GetIndexFromObj(interp, objv[i], optStrings, "option",
+ 0, &opt) == TCL_ERROR) {
+ return TCL_ERROR;
+ }
+ if (i+1 >= objc) {
+ Tcl_AppendResult(interp,
+ "missing value for option \"", Tcl_GetString(objv[i]),
+ "\"", NULL);
+ return TCL_ERROR;
+ }
+ switch (opt) {
+ case OPT_IMAGE:
+ imageObj = objv[i+1];
+ break;
+ case OPT_TEXT:
+ textObj = objv[i+1];
+ break;
+ case OPT_CALLBACK:
+ callbackObj = objv[i+1];
+ break;
+ }
+ }
+ if (cmd == CMD_ADD && imageObj == NULL) {
+ Tcl_SetObjResult(interp, Tcl_NewStringObj("missing required option \"-image\"", TCL_INDEX_NONE));
+ return TCL_ERROR;
+ }
+ if (imageObj != NULL) {
+ Tk_PhotoHandle photo;
+ int width, height;
+ Tk_PhotoImageBlock block;
+
+ photo = Tk_FindPhoto(interp, Tcl_GetString(imageObj));
+ if (photo == NULL) {
+ Tcl_SetObjResult(interp, Tcl_ObjPrintf(
+ "image \"%s\" doesn't exist", Tcl_GetString(imageObj)));
+ return TCL_ERROR;
+ }
+ Tk_PhotoGetSize(photo, &width, &height);
+ Tk_PhotoGetImage(photo, &block);
+ hIcon = CreateIcoFromPhoto(width, height, block);
+ if (hIcon == NULL) {
+ Tcl_SetObjResult(interp, Tcl_ObjPrintf(
+ "failed to create an iconphoto with image \"%s\"", Tcl_GetString(imageObj)));
+ return TCL_ERROR;
+ }
+ }
+ if (cmd == CMD_ADD) {
+ icoPtr = NewIcon(interp, icoInterpPtr, hIcon);
+ } else {
+ if (imageObj != NULL) {
+ DestroyIcon(icoPtr->hIcon);
+ icoPtr->hIcon = hIcon;
+ }
+ }
+ if (callbackObj != NULL) {
+ if (icoPtr->taskbar_command != NULL) {
+ Tcl_DecrRefCount(icoPtr->taskbar_command);
+ }
+ icoPtr->taskbar_command = callbackObj;
+ Tcl_IncrRefCount(icoPtr->taskbar_command);
+ }
+ if (textObj != NULL) {
+ if (icoPtr->taskbar_txt != NULL) {
+ Tcl_DecrRefCount(icoPtr->taskbar_txt);
+ }
+ icoPtr->taskbar_txt = textObj;
+ Tcl_IncrRefCount(icoPtr->taskbar_txt);
+ }
+ TaskbarOperation(icoInterpPtr, icoPtr, oper);
+ if (cmd == CMD_ADD) {
+ char buffer[5 + TCL_INTEGER_SPACE];
+ int n;
+ n = snprintf(buffer, sizeof(buffer) - 1, "ico#%d", icoPtr->id);
+ buffer[n] = 0;
+ Tcl_SetObjResult(interp, Tcl_NewStringObj(buffer, n));
+ }
+ return TCL_OK;
+ }
+ case CMD_DELETE:
+ if (objc != 3) {
+ Tcl_WrongNumArgs(interp, 2, objv, "id");
+ return TCL_ERROR;
+ }
+ icoPtr = GetIcoPtr(interp, icoInterpPtr, Tcl_GetString(objv[2]));
+ if (icoPtr == NULL) {
+ return TCL_ERROR;
+ }
+ FreeIcoPtr(icoInterpPtr, icoPtr);
+ return TCL_OK;
}
return TCL_OK;
}
@@ -1074,22 +1074,22 @@ WinSysNotifyCmd(
char *msginfo;
if (objc < 2) {
- Tcl_WrongNumArgs(interp, 1, objv, "command ...");
- return TCL_ERROR;
+ Tcl_WrongNumArgs(interp, 1, objv, "command ...");
+ return TCL_ERROR;
}
if (strcmp(Tcl_GetString(objv[1]), "notify") != 0) {
- Tcl_AppendResult(interp, "unknown subcommand \"", Tcl_GetString(objv[1]),
- "\": must be notify", NULL);
- return TCL_ERROR;
+ Tcl_AppendResult(interp, "unknown subcommand \"", Tcl_GetString(objv[1]),
+ "\": must be notify", NULL);
+ return TCL_ERROR;
}
if (objc != 5) {
- Tcl_WrongNumArgs(interp, 2, objv, "id title detail");
- return TCL_ERROR;
+ Tcl_WrongNumArgs(interp, 2, objv, "id title detail");
+ return TCL_ERROR;
}
icoPtr = GetIcoPtr(interp, icoInterpPtr, Tcl_GetString(objv[2]));
if (icoPtr == NULL) {
- return TCL_ERROR;
+ return TCL_ERROR;
}
ni.cbSize = sizeof(NOTIFYICONDATAW);
@@ -1105,18 +1105,18 @@ WinSysNotifyCmd(
/* Balloon notification for system tray icon. */
if (msgtitle != NULL) {
- WCHAR *title;
- Tcl_DStringInit(&titledst);
- title = Tcl_UtfToWCharDString(msgtitle, TCL_INDEX_NONE, &titledst);
- wcsncpy(ni.szInfoTitle, title, (Tcl_DStringLength(&titledst) + 2) / 2);
- Tcl_DStringFree(&titledst);
+ WCHAR *title;
+ Tcl_DStringInit(&titledst);
+ title = Tcl_UtfToWCharDString(msgtitle, TCL_INDEX_NONE, &titledst);
+ wcsncpy(ni.szInfoTitle, title, (Tcl_DStringLength(&titledst) + 2) / 2);
+ Tcl_DStringFree(&titledst);
}
if (msginfo != NULL) {
- WCHAR *info;
- Tcl_DStringInit(&infodst);
- info = Tcl_UtfToWCharDString(msginfo, TCL_INDEX_NONE, &infodst);
- wcsncpy(ni.szInfo, info, (Tcl_DStringLength(&infodst) + 2) / 2);
- Tcl_DStringFree(&infodst);
+ WCHAR *info;
+ Tcl_DStringInit(&infodst);
+ info = Tcl_UtfToWCharDString(msginfo, TCL_INDEX_NONE, &infodst);
+ wcsncpy(ni.szInfo, info, (Tcl_DStringLength(&infodst) + 2) / 2);
+ Tcl_DStringFree(&infodst);
}
Shell_NotifyIconW(NIM_MODIFY, &ni);
@@ -1148,8 +1148,8 @@ WinIcoInit(
mainWindow = Tk_MainWindow(interp);
if (mainWindow == NULL) {
- Tcl_SetObjResult(interp, Tcl_NewStringObj("main window has been destroyed", TCL_INDEX_NONE));
- return TCL_ERROR;
+ Tcl_SetObjResult(interp, Tcl_NewStringObj("main window has been destroyed", TCL_INDEX_NONE));
+ return TCL_ERROR;
}
icoInterpPtr = (IcoInterpInfo*) ckalloc(sizeof(IcoInterpInfo));
@@ -1159,12 +1159,12 @@ WinIcoInit(
icoInterpPtr->nextPtr = firstIcoInterpPtr;
firstIcoInterpPtr = icoInterpPtr;
Tcl_CreateObjCommand(interp, "::tk::systray::_systray", WinSystrayCmd,
- icoInterpPtr, NULL);
+ icoInterpPtr, NULL);
Tcl_CreateObjCommand(interp, "::tk::sysnotify::_sysnotify", WinSysNotifyCmd,
- icoInterpPtr, NULL);
+ icoInterpPtr, NULL);
Tk_CreateEventHandler(mainWindow, StructureNotifyMask,
- WinIcoDestroy, icoInterpPtr);
+ WinIcoDestroy, icoInterpPtr);
return TCL_OK;
}