1999-12-12 00:54:59 +01:00
|
|
|
/*
|
|
|
|
* Systray
|
|
|
|
*
|
|
|
|
* Copyright 1999 Kai Morich <kai.morich@bigfoot.de>
|
|
|
|
*
|
|
|
|
* Manage the systray window. That it actually appears in the docking
|
|
|
|
* area of KDE or GNOME is delegated to windows/x11drv/wnd.c,
|
|
|
|
* X11DRV_WND_DockWindow.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2000-01-04 01:33:56 +01:00
|
|
|
#include "heap.h"
|
1999-12-12 00:54:59 +01:00
|
|
|
#include "shellapi.h"
|
|
|
|
#include "shell32_main.h"
|
|
|
|
#include "windows.h"
|
|
|
|
#include "commctrl.h"
|
|
|
|
#include "debugtools.h"
|
2000-02-07 17:02:41 +01:00
|
|
|
#include "config.h"
|
1999-12-12 00:54:59 +01:00
|
|
|
|
|
|
|
DEFAULT_DEBUG_CHANNEL(shell)
|
|
|
|
|
|
|
|
typedef struct SystrayData {
|
2000-02-07 17:02:41 +01:00
|
|
|
HWND hWnd;
|
|
|
|
HWND hWndToolTip;
|
|
|
|
NOTIFYICONDATAA notifyIcon;
|
|
|
|
int nitem; /* number of current element = tooltip id */
|
|
|
|
struct SystrayData *nextTrayItem;
|
|
|
|
} SystrayData;
|
|
|
|
|
|
|
|
typedef struct Systray {
|
1999-12-12 00:54:59 +01:00
|
|
|
int hasCritSection;
|
|
|
|
CRITICAL_SECTION critSection;
|
2000-02-07 17:02:41 +01:00
|
|
|
SystrayData *systrayItemList;
|
|
|
|
} Systray;
|
1999-12-12 00:54:59 +01:00
|
|
|
|
2000-02-07 17:02:41 +01:00
|
|
|
static Systray systray;
|
|
|
|
static int nNumberTrayElements;
|
1999-12-12 00:54:59 +01:00
|
|
|
|
|
|
|
|
|
|
|
static BOOL SYSTRAY_Delete(PNOTIFYICONDATAA pnid);
|
|
|
|
|
|
|
|
|
|
|
|
/**************************************************************************
|
2000-02-07 17:02:41 +01:00
|
|
|
* internal systray
|
1999-12-12 00:54:59 +01:00
|
|
|
*
|
|
|
|
*/
|
2000-02-07 17:02:41 +01:00
|
|
|
|
1999-12-12 00:54:59 +01:00
|
|
|
#define SMALL_ICON_SIZE GetSystemMetrics(SM_CXSMICON)
|
2000-02-07 17:02:41 +01:00
|
|
|
|
1999-12-12 00:54:59 +01:00
|
|
|
/* space between icons and frame */
|
|
|
|
#define IBORDER 3
|
|
|
|
#define OBORDER 2
|
2000-02-07 17:02:41 +01:00
|
|
|
#define TBORDER (OBORDER+1+IBORDER)
|
1999-12-12 00:54:59 +01:00
|
|
|
|
|
|
|
static LRESULT CALLBACK SYSTRAY_WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
|
|
|
{
|
|
|
|
HDC hdc;
|
|
|
|
PAINTSTRUCT ps;
|
|
|
|
|
|
|
|
switch (message) {
|
|
|
|
case WM_PAINT:
|
|
|
|
{
|
|
|
|
RECT rc;
|
2000-02-07 17:02:41 +01:00
|
|
|
SystrayData *ptrayItem = systray.systrayItemList;
|
|
|
|
|
|
|
|
while (ptrayItem)
|
|
|
|
{
|
|
|
|
if (ptrayItem->hWnd == hWnd)
|
|
|
|
{
|
|
|
|
hdc = BeginPaint(hWnd, &ps);
|
|
|
|
GetClientRect(hWnd, &rc);
|
|
|
|
|
|
|
|
if (!DrawIconEx(hdc, rc.left, rc.top, ptrayItem->notifyIcon.hIcon,
|
|
|
|
SMALL_ICON_SIZE, SMALL_ICON_SIZE, 0, 0, DI_DEFAULTSIZE|DI_NORMAL))
|
|
|
|
SYSTRAY_Delete(&ptrayItem->notifyIcon);
|
|
|
|
}
|
|
|
|
ptrayItem = ptrayItem->nextTrayItem;
|
1999-12-12 00:54:59 +01:00
|
|
|
}
|
|
|
|
EndPaint(hWnd, &ps);
|
2000-02-07 17:02:41 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
1999-12-12 00:54:59 +01:00
|
|
|
case WM_MOUSEMOVE:
|
|
|
|
case WM_LBUTTONDOWN:
|
|
|
|
case WM_LBUTTONUP:
|
|
|
|
case WM_RBUTTONDOWN:
|
|
|
|
case WM_RBUTTONUP:
|
|
|
|
case WM_MBUTTONDOWN:
|
|
|
|
case WM_MBUTTONUP:
|
|
|
|
{
|
|
|
|
MSG msg;
|
2000-02-07 17:02:41 +01:00
|
|
|
SystrayData *ptrayItem = systray.systrayItemList;
|
|
|
|
|
|
|
|
while ( ptrayItem )
|
|
|
|
{
|
|
|
|
if (ptrayItem->hWnd == hWnd)
|
|
|
|
{
|
|
|
|
msg.hwnd=hWnd;
|
|
|
|
msg.message=message;
|
|
|
|
msg.wParam=wParam;
|
|
|
|
msg.lParam=lParam;
|
|
|
|
msg.time = GetMessageTime ();
|
|
|
|
msg.pt.x = LOWORD(GetMessagePos ());
|
|
|
|
msg.pt.y = HIWORD(GetMessagePos ());
|
|
|
|
|
|
|
|
SendMessageA(ptrayItem->hWndToolTip, TTM_RELAYEVENT, 0, (LPARAM)&msg);
|
|
|
|
}
|
|
|
|
ptrayItem = ptrayItem->nextTrayItem;
|
|
|
|
}
|
1999-12-12 00:54:59 +01:00
|
|
|
}
|
2000-02-07 17:02:41 +01:00
|
|
|
|
1999-12-12 00:54:59 +01:00
|
|
|
case WM_LBUTTONDBLCLK:
|
|
|
|
case WM_RBUTTONDBLCLK:
|
|
|
|
case WM_MBUTTONDBLCLK:
|
|
|
|
{
|
2000-02-07 17:02:41 +01:00
|
|
|
int xPos;
|
|
|
|
SystrayData *ptrayItem = systray.systrayItemList;
|
|
|
|
|
|
|
|
while (ptrayItem)
|
|
|
|
{
|
|
|
|
if (ptrayItem->hWnd == hWnd)
|
|
|
|
{
|
|
|
|
xPos = LOWORD(lParam);
|
|
|
|
if( (xPos >= TBORDER) &&
|
|
|
|
(xPos < (TBORDER+SMALL_ICON_SIZE)) )
|
|
|
|
{
|
|
|
|
if (!PostMessageA(ptrayItem->notifyIcon.hWnd, ptrayItem->notifyIcon.uCallbackMessage,
|
|
|
|
(WPARAM)ptrayItem->notifyIcon.uID, (LPARAM)message))
|
|
|
|
SYSTRAY_Delete(&ptrayItem->notifyIcon);
|
|
|
|
break;
|
|
|
|
}
|
1999-12-12 00:54:59 +01:00
|
|
|
}
|
2000-02-07 17:02:41 +01:00
|
|
|
ptrayItem = ptrayItem->nextTrayItem;
|
1999-12-12 00:54:59 +01:00
|
|
|
}
|
2000-02-07 17:02:41 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
1999-12-12 00:54:59 +01:00
|
|
|
default:
|
|
|
|
return (DefWindowProcA(hWnd, message, wParam, lParam));
|
2000-02-07 17:02:41 +01:00
|
|
|
}
|
|
|
|
return (0);
|
|
|
|
|
1999-12-12 00:54:59 +01:00
|
|
|
}
|
|
|
|
|
2000-02-07 17:02:41 +01:00
|
|
|
BOOL SYSTRAY_RegisterClass(void)
|
1999-12-12 00:54:59 +01:00
|
|
|
{
|
|
|
|
WNDCLASSA wc;
|
2000-02-07 17:02:41 +01:00
|
|
|
|
1999-12-12 00:54:59 +01:00
|
|
|
wc.style = CS_SAVEBITS;
|
|
|
|
wc.lpfnWndProc = (WNDPROC)SYSTRAY_WndProc;
|
|
|
|
wc.cbClsExtra = 0;
|
|
|
|
wc.cbWndExtra = 0;
|
|
|
|
wc.hInstance = 0;
|
|
|
|
wc.hIcon = 0; /* LoadIcon (NULL, IDI_EXCLAMATION); */
|
|
|
|
wc.hCursor = LoadCursorA(0, IDC_ARROWA);
|
|
|
|
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW);
|
|
|
|
wc.lpszMenuName = NULL;
|
|
|
|
wc.lpszClassName = "WineSystray";
|
2000-02-07 17:02:41 +01:00
|
|
|
|
1999-12-12 00:54:59 +01:00
|
|
|
if (!RegisterClassA(&wc)) {
|
|
|
|
ERR("RegisterClass(WineSystray) failed\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
2000-02-07 17:02:41 +01:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
BOOL SYSTRAY_Create(SystrayData *ptrayItem)
|
|
|
|
{
|
|
|
|
RECT rect;
|
|
|
|
|
|
|
|
/* Register the class if this is our first tray item. */
|
|
|
|
if ( nNumberTrayElements == 1 )
|
|
|
|
{
|
|
|
|
if ( !SYSTRAY_RegisterClass() )
|
|
|
|
{
|
|
|
|
ERR( "RegisterClass(WineSystray) failed\n" );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Initialize the window size. */
|
1999-12-12 00:54:59 +01:00
|
|
|
rect.left = 0;
|
|
|
|
rect.top = 0;
|
|
|
|
rect.right = SMALL_ICON_SIZE+2*TBORDER;
|
|
|
|
rect.bottom = SMALL_ICON_SIZE+2*TBORDER;
|
2000-02-07 17:02:41 +01:00
|
|
|
|
|
|
|
/* Create tray window for icon. */
|
|
|
|
ptrayItem->hWnd = CreateWindowExA( WS_EX_TRAYWINDOW,
|
|
|
|
"WineSystray", "Wine-Systray",
|
|
|
|
WS_VISIBLE,
|
|
|
|
CW_USEDEFAULT, CW_USEDEFAULT,
|
|
|
|
rect.right-rect.left, rect.bottom-rect.top,
|
|
|
|
0, 0, 0, 0 );
|
|
|
|
if ( !ptrayItem->hWnd )
|
|
|
|
{
|
|
|
|
ERR( "CreateWindow(WineSystray) failed\n" );
|
1999-12-12 00:54:59 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
2000-02-07 17:02:41 +01:00
|
|
|
|
|
|
|
/* Create tooltip for icon. */
|
|
|
|
ptrayItem->hWndToolTip = CreateWindowA( TOOLTIPS_CLASSA,NULL,TTS_ALWAYSTIP,
|
|
|
|
CW_USEDEFAULT, CW_USEDEFAULT,
|
|
|
|
CW_USEDEFAULT, CW_USEDEFAULT,
|
|
|
|
ptrayItem->hWnd, 0, 0, 0 );
|
|
|
|
if ( ptrayItem->hWndToolTip==0 )
|
|
|
|
{
|
|
|
|
ERR( "CreateWindow(TOOLTIP) failed\n" );
|
1999-12-12 00:54:59 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2000-02-07 17:02:41 +01:00
|
|
|
static void SYSTRAY_RepaintAll(void)
|
|
|
|
{
|
|
|
|
SystrayData *ptrayItem = systray.systrayItemList;
|
|
|
|
|
|
|
|
while(ptrayItem)
|
|
|
|
{
|
|
|
|
InvalidateRect(ptrayItem->hWnd, NULL, TRUE);
|
|
|
|
ptrayItem = ptrayItem->nextTrayItem;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
1999-12-12 00:54:59 +01:00
|
|
|
|
|
|
|
static void SYSTRAY_RepaintItem(int nitem)
|
|
|
|
{
|
2000-02-07 17:02:41 +01:00
|
|
|
|
|
|
|
SystrayData *ptrayItem = systray.systrayItemList;
|
|
|
|
|
|
|
|
while(ptrayItem)
|
|
|
|
{
|
|
|
|
if (ptrayItem->nitem == nitem)
|
|
|
|
InvalidateRect(ptrayItem->hWnd, NULL, TRUE);
|
|
|
|
|
|
|
|
ptrayItem = ptrayItem->nextTrayItem;
|
1999-12-12 00:54:59 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-02-07 17:02:41 +01:00
|
|
|
void SYSTRAY_InitItem(SystrayData *ptrayItem)
|
|
|
|
{
|
|
|
|
ptrayItem->nitem = nNumberTrayElements++;
|
|
|
|
SYSTRAY_Create(ptrayItem);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SYSTRAY_SetIcon(SystrayData *ptrayItem, HICON hIcon)
|
1999-12-12 00:54:59 +01:00
|
|
|
{
|
2000-06-16 23:48:57 +02:00
|
|
|
/* keep our own copy of "hIcon" object */
|
|
|
|
ptrayItem->notifyIcon.hIcon = CopyIcon(hIcon);
|
1999-12-12 00:54:59 +01:00
|
|
|
}
|
|
|
|
|
2000-02-07 17:02:41 +01:00
|
|
|
void SYSTRAY_SetTip(SystrayData *ptrayItem, CHAR* szTip)
|
1999-12-12 00:54:59 +01:00
|
|
|
{
|
2000-02-07 17:02:41 +01:00
|
|
|
TTTOOLINFOA ti;
|
|
|
|
|
|
|
|
strncpy(ptrayItem->notifyIcon.szTip, szTip, sizeof(ptrayItem->notifyIcon.szTip));
|
|
|
|
ptrayItem->notifyIcon.szTip[sizeof(ptrayItem->notifyIcon.szTip)-1]=0;
|
|
|
|
|
|
|
|
ti.cbSize = sizeof(TTTOOLINFOA);
|
|
|
|
ti.uFlags = 0;
|
|
|
|
ti.hwnd = ptrayItem->hWnd;
|
|
|
|
ti.hinst = 0;
|
|
|
|
ti.uId = ptrayItem->nitem;
|
|
|
|
ti.lpszText = ptrayItem->notifyIcon.szTip;
|
|
|
|
ti.rect.left = 0;
|
|
|
|
ti.rect.top = 0;
|
|
|
|
ti.rect.right = SMALL_ICON_SIZE+2*TBORDER;
|
|
|
|
ti.rect.bottom = SMALL_ICON_SIZE+2*TBORDER;
|
|
|
|
|
|
|
|
SendMessageA(ptrayItem->hWndToolTip, TTM_ADDTOOLA, 0, (LPARAM)&ti);
|
1999-12-12 00:54:59 +01:00
|
|
|
}
|
|
|
|
|
2000-02-07 17:02:41 +01:00
|
|
|
static void SYSTRAY_ModifyTip(SystrayData *ptrayItem, CHAR* szTip)
|
1999-12-12 00:54:59 +01:00
|
|
|
{
|
2000-02-07 17:02:41 +01:00
|
|
|
TTTOOLINFOA ti;
|
|
|
|
|
|
|
|
strncpy(ptrayItem->notifyIcon.szTip, szTip, sizeof(ptrayItem->notifyIcon.szTip));
|
|
|
|
ptrayItem->notifyIcon.szTip[sizeof(ptrayItem->notifyIcon.szTip)-1]=0;
|
1999-12-12 00:54:59 +01:00
|
|
|
|
|
|
|
ti.cbSize = sizeof(TTTOOLINFOA);
|
2000-02-07 17:02:41 +01:00
|
|
|
ti.uFlags = 0;
|
|
|
|
ti.hwnd = ptrayItem->hWnd;
|
|
|
|
ti.hinst = 0;
|
|
|
|
ti.uId = ptrayItem->nitem;
|
|
|
|
ti.lpszText = ptrayItem->notifyIcon.szTip;
|
|
|
|
ti.rect.left = 0;
|
|
|
|
ti.rect.top = 0;
|
|
|
|
ti.rect.right = SMALL_ICON_SIZE+2*TBORDER;
|
|
|
|
ti.rect.bottom = SMALL_ICON_SIZE+2*TBORDER;
|
|
|
|
|
|
|
|
SendMessageA(ptrayItem->hWndToolTip, TTM_UPDATETIPTEXTA, 0, (LPARAM)&ti);
|
1999-12-12 00:54:59 +01:00
|
|
|
}
|
|
|
|
|
2000-02-07 17:02:41 +01:00
|
|
|
static void SYSTRAY_TermItem(SystrayData *removeItem)
|
1999-12-12 00:54:59 +01:00
|
|
|
{
|
|
|
|
int nitem;
|
2000-02-07 17:02:41 +01:00
|
|
|
SystrayData **trayItem;
|
|
|
|
TTTOOLINFOA ti;
|
1999-12-12 00:54:59 +01:00
|
|
|
ti.cbSize = sizeof(TTTOOLINFOA);
|
2000-02-07 17:02:41 +01:00
|
|
|
ti.uFlags = 0;
|
|
|
|
ti.hinst = 0;
|
1999-12-12 00:54:59 +01:00
|
|
|
|
|
|
|
/* delete all tooltips ...*/
|
2000-02-07 17:02:41 +01:00
|
|
|
trayItem = &systray.systrayItemList;
|
1999-12-12 00:54:59 +01:00
|
|
|
while (*trayItem) {
|
|
|
|
ti.uId = (*trayItem)->nitem;
|
2000-02-07 17:02:41 +01:00
|
|
|
ti.hwnd = (*trayItem)->hWnd;
|
|
|
|
SendMessageA((*trayItem)->hWndToolTip, TTM_DELTOOLA, 0, (LPARAM)&ti);
|
|
|
|
trayItem = &((*trayItem)->nextTrayItem);
|
1999-12-12 00:54:59 +01:00
|
|
|
}
|
|
|
|
/* ... and add them again, because uID may shift */
|
|
|
|
nitem=0;
|
2000-02-07 17:02:41 +01:00
|
|
|
trayItem = &systray.systrayItemList;
|
|
|
|
while (*trayItem)
|
|
|
|
{
|
|
|
|
if (*trayItem != removeItem)
|
|
|
|
{
|
1999-12-12 00:54:59 +01:00
|
|
|
(*trayItem)->nitem = nitem;
|
|
|
|
ti.uId = nitem;
|
2000-02-07 17:02:41 +01:00
|
|
|
ti.hwnd = (*trayItem)->hWnd;
|
1999-12-12 00:54:59 +01:00
|
|
|
ti.lpszText = (*trayItem)->notifyIcon.szTip;
|
2000-02-07 17:02:41 +01:00
|
|
|
ti.rect.left = 0;
|
|
|
|
ti.rect.top = 0;
|
|
|
|
ti.rect.right = SMALL_ICON_SIZE+2*TBORDER;
|
|
|
|
ti.rect.bottom = SMALL_ICON_SIZE+2*TBORDER;
|
|
|
|
SendMessageA((*trayItem)->hWndToolTip, TTM_ADDTOOLA, 0, (LPARAM)&ti);
|
1999-12-12 00:54:59 +01:00
|
|
|
nitem++;
|
|
|
|
}
|
2000-02-07 17:02:41 +01:00
|
|
|
trayItem = &((*trayItem)->nextTrayItem);
|
1999-12-12 00:54:59 +01:00
|
|
|
}
|
2000-02-07 17:02:41 +01:00
|
|
|
nNumberTrayElements--;
|
1999-12-12 00:54:59 +01:00
|
|
|
}
|
|
|
|
|
2000-02-07 17:02:41 +01:00
|
|
|
|
1999-12-12 00:54:59 +01:00
|
|
|
/**************************************************************************
|
2000-02-07 17:02:41 +01:00
|
|
|
* helperfunctions
|
1999-12-12 00:54:59 +01:00
|
|
|
*
|
|
|
|
*/
|
2000-02-07 17:02:41 +01:00
|
|
|
void SYSTRAY_SetMessage(SystrayData *ptrayItem, UINT uCallbackMessage)
|
1999-12-12 00:54:59 +01:00
|
|
|
{
|
2000-02-07 17:02:41 +01:00
|
|
|
ptrayItem->notifyIcon.uCallbackMessage = uCallbackMessage;
|
1999-12-12 00:54:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL SYSTRAY_IsEqual(PNOTIFYICONDATAA pnid1, PNOTIFYICONDATAA pnid2)
|
|
|
|
{
|
|
|
|
if (pnid1->hWnd != pnid2->hWnd) return FALSE;
|
|
|
|
if (pnid1->uID != pnid2->uID) return FALSE;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL SYSTRAY_Add(PNOTIFYICONDATAA pnid)
|
|
|
|
{
|
2000-02-07 17:02:41 +01:00
|
|
|
SystrayData **ptrayItem = &systray.systrayItemList;
|
|
|
|
|
|
|
|
/* Find empty space for new element. */
|
|
|
|
while( *ptrayItem )
|
|
|
|
{
|
|
|
|
if ( SYSTRAY_IsEqual(pnid, &(*ptrayItem)->notifyIcon) )
|
1999-12-12 00:54:59 +01:00
|
|
|
return FALSE;
|
2000-02-07 17:02:41 +01:00
|
|
|
ptrayItem = &((*ptrayItem)->nextTrayItem);
|
1999-12-12 00:54:59 +01:00
|
|
|
}
|
2000-02-07 17:02:41 +01:00
|
|
|
|
|
|
|
/* Allocate SystrayData for element and zero memory. */
|
|
|
|
(*ptrayItem) = ( SystrayData *)malloc( sizeof(SystrayData) );
|
|
|
|
ZeroMemory( (*ptrayItem), sizeof(SystrayData) );
|
|
|
|
|
|
|
|
/* Copy notification data */
|
|
|
|
memcpy( &(*ptrayItem)->notifyIcon, pnid, sizeof(NOTIFYICONDATAA) );
|
|
|
|
|
|
|
|
/* Initialize and set data for the tray element. */
|
|
|
|
SYSTRAY_InitItem( (*ptrayItem) );
|
|
|
|
|
|
|
|
SYSTRAY_SetIcon (*ptrayItem, (pnid->uFlags&NIF_ICON) ?pnid->hIcon :0);
|
|
|
|
SYSTRAY_SetMessage(*ptrayItem, (pnid->uFlags&NIF_MESSAGE)?pnid->uCallbackMessage:0);
|
|
|
|
SYSTRAY_SetTip (*ptrayItem, (pnid->uFlags&NIF_TIP) ?pnid->szTip :"");
|
|
|
|
|
|
|
|
(*ptrayItem)->nextTrayItem = NULL; /* may be overkill after the ZeroMemory call. */
|
|
|
|
|
|
|
|
/* Repaint all system tray icons as we have added one. */
|
|
|
|
SYSTRAY_RepaintAll();
|
|
|
|
|
|
|
|
TRACE("%p: 0x%08x %d %s\n", (*ptrayItem), (*ptrayItem)->notifyIcon.hWnd,
|
|
|
|
(*ptrayItem)->notifyIcon.uID,
|
|
|
|
(*ptrayItem)->notifyIcon.szTip);
|
1999-12-12 00:54:59 +01:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL SYSTRAY_Modify(PNOTIFYICONDATAA pnid)
|
|
|
|
{
|
2000-02-07 17:02:41 +01:00
|
|
|
SystrayData *ptrayItem = systray.systrayItemList;
|
|
|
|
|
|
|
|
while ( ptrayItem )
|
|
|
|
{
|
|
|
|
if ( SYSTRAY_IsEqual(pnid, &ptrayItem->notifyIcon) )
|
|
|
|
{
|
1999-12-12 00:54:59 +01:00
|
|
|
if (pnid->uFlags & NIF_ICON)
|
2000-02-07 17:02:41 +01:00
|
|
|
{
|
|
|
|
SYSTRAY_SetIcon(ptrayItem, pnid->hIcon);
|
|
|
|
SYSTRAY_RepaintItem(ptrayItem->nitem);
|
|
|
|
}
|
|
|
|
|
1999-12-12 00:54:59 +01:00
|
|
|
if (pnid->uFlags & NIF_MESSAGE)
|
2000-02-07 17:02:41 +01:00
|
|
|
SYSTRAY_SetMessage(ptrayItem, pnid->uCallbackMessage);
|
|
|
|
|
1999-12-12 00:54:59 +01:00
|
|
|
if (pnid->uFlags & NIF_TIP)
|
2000-02-07 17:02:41 +01:00
|
|
|
SYSTRAY_ModifyTip(ptrayItem, pnid->szTip);
|
|
|
|
|
|
|
|
TRACE("%p: 0x%08x %d %s\n", ptrayItem, ptrayItem->notifyIcon.hWnd,
|
|
|
|
ptrayItem->notifyIcon.uID, ptrayItem->notifyIcon.szTip);
|
1999-12-12 00:54:59 +01:00
|
|
|
return TRUE;
|
|
|
|
}
|
2000-02-07 17:02:41 +01:00
|
|
|
ptrayItem = ptrayItem->nextTrayItem;
|
1999-12-12 00:54:59 +01:00
|
|
|
}
|
|
|
|
return FALSE; /* not found */
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL SYSTRAY_Delete(PNOTIFYICONDATAA pnid)
|
|
|
|
{
|
2000-02-07 17:02:41 +01:00
|
|
|
SystrayData **ptrayItem = &systray.systrayItemList;
|
|
|
|
|
|
|
|
while (*ptrayItem)
|
|
|
|
{
|
|
|
|
if (SYSTRAY_IsEqual(pnid, &(*ptrayItem)->notifyIcon))
|
|
|
|
{
|
|
|
|
SystrayData *next = (*ptrayItem)->nextTrayItem;
|
|
|
|
TRACE("%p: 0x%08x %d %s\n", *ptrayItem, (*ptrayItem)->notifyIcon.hWnd,
|
|
|
|
(*ptrayItem)->notifyIcon.uID, (*ptrayItem)->notifyIcon.szTip);
|
|
|
|
SYSTRAY_TermItem(*ptrayItem);
|
|
|
|
|
2000-06-16 23:48:57 +02:00
|
|
|
DestroyIcon ((*ptrayItem)->notifyIcon.hIcon);
|
2000-02-07 17:02:41 +01:00
|
|
|
DestroyWindow((*ptrayItem)->hWndToolTip);
|
|
|
|
DestroyWindow((*ptrayItem)->hWnd);
|
|
|
|
|
|
|
|
free(*ptrayItem);
|
|
|
|
*ptrayItem = next;
|
|
|
|
|
|
|
|
SYSTRAY_RepaintAll();
|
1999-12-12 00:54:59 +01:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
2000-02-07 17:02:41 +01:00
|
|
|
ptrayItem = &((*ptrayItem)->nextTrayItem);
|
1999-12-12 00:54:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE; /* not found */
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
BOOL SYSTRAY_Init(void)
|
|
|
|
{
|
2000-02-07 17:02:41 +01:00
|
|
|
if (!systray.hasCritSection)
|
|
|
|
{
|
1999-12-12 00:54:59 +01:00
|
|
|
systray.hasCritSection=1;
|
|
|
|
InitializeCriticalSection(&systray.critSection);
|
|
|
|
MakeCriticalSectionGlobal(&systray.critSection);
|
2000-02-07 17:02:41 +01:00
|
|
|
TRACE(" =%p\n", &systray.critSection);
|
1999-12-12 00:54:59 +01:00
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* Shell_NotifyIconA [SHELL32.297]
|
|
|
|
*/
|
|
|
|
BOOL WINAPI Shell_NotifyIconA(DWORD dwMessage, PNOTIFYICONDATAA pnid )
|
|
|
|
{
|
|
|
|
BOOL flag=FALSE;
|
|
|
|
TRACE("wait %d %d %ld\n", pnid->hWnd, pnid->uID, dwMessage);
|
|
|
|
/* must be serialized because all apps access same systray */
|
|
|
|
EnterCriticalSection(&systray.critSection);
|
|
|
|
TRACE("enter %d %d %ld\n", pnid->hWnd, pnid->uID, dwMessage);
|
|
|
|
|
2000-02-07 17:02:41 +01:00
|
|
|
|
1999-12-12 00:54:59 +01:00
|
|
|
switch(dwMessage) {
|
|
|
|
case NIM_ADD:
|
2000-02-07 17:02:41 +01:00
|
|
|
TRACE("Calling systray add\n");
|
1999-12-12 00:54:59 +01:00
|
|
|
flag = SYSTRAY_Add(pnid);
|
|
|
|
break;
|
|
|
|
case NIM_MODIFY:
|
|
|
|
flag = SYSTRAY_Modify(pnid);
|
|
|
|
break;
|
|
|
|
case NIM_DELETE:
|
|
|
|
flag = SYSTRAY_Delete(pnid);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
LeaveCriticalSection(&systray.critSection);
|
|
|
|
TRACE("leave %d %d %ld\n", pnid->hWnd, pnid->uID, dwMessage);
|
|
|
|
return flag;
|
|
|
|
}
|
|
|
|
|
2000-01-04 01:33:56 +01:00
|
|
|
/*************************************************************************
|
2000-03-24 21:46:04 +01:00
|
|
|
* Shell_NotifyIconW [SHELL32.297]
|
2000-01-04 01:33:56 +01:00
|
|
|
*/
|
|
|
|
BOOL WINAPI Shell_NotifyIconW (DWORD dwMessage, PNOTIFYICONDATAW pnid )
|
|
|
|
{
|
|
|
|
BOOL ret;
|
|
|
|
|
|
|
|
PNOTIFYICONDATAA p = HeapAlloc(GetProcessHeap(),0,sizeof(NOTIFYICONDATAA));
|
|
|
|
memcpy(p, pnid, sizeof(NOTIFYICONDATAA));
|
|
|
|
if (*(pnid->szTip))
|
|
|
|
lstrcpynWtoA (p->szTip, pnid->szTip, 64 );
|
|
|
|
|
|
|
|
ret = Shell_NotifyIconA(dwMessage, p );
|
|
|
|
|
|
|
|
HeapFree(GetProcessHeap(),0,p);
|
|
|
|
return ret;
|
|
|
|
}
|
1999-12-12 00:54:59 +01:00
|
|
|
/*************************************************************************
|
|
|
|
* Shell_NotifyIcon [SHELL32.296]
|
|
|
|
*/
|
|
|
|
BOOL WINAPI Shell_NotifyIcon(DWORD dwMessage, PNOTIFYICONDATAA pnid)
|
|
|
|
{
|
|
|
|
return Shell_NotifyIconA(dwMessage, pnid);
|
|
|
|
}
|