source: trunk/src/shell32/systray.c@ 21591

Last change on this file since 21591 was 21591, checked in by dmik, 14 years ago

shell32: Prepared to the xsystray integration (keeping the old Systray/WPS based implementation).

File size: 5.4 KB
Line 
1/*
2 * Systray
3 *
4 * Copyright 1999 Kai Morich <kai.morich@bigfoot.de>
5 *
6 * Manage the systray window. That it actually appears in the docking
7 * area of KDE or GNOME is delegated to windows/x11drv/wnd.c,
8 * X11DRV_WND_DockWindow.
9 *
10 * Modified by ErOs2 for usage with systray_os2.c
11 *
12 */
13
14#ifndef __WIN32OS2__
15#include <unistd.h>
16#endif
17#include <stdlib.h>
18#include <string.h>
19
20#include "winnls.h"
21#include "shlobj.h"
22#include "shellapi.h"
23#include "shell32_main.h"
24#include "commctrl.h"
25#include "debugtools.h"
26#include "heap.h"
27#include "config.h"
28#include "winuser32.h"
29
30#include "systray.h"
31
32DEFAULT_DEBUG_CHANNEL(shell);
33
34
35struct _SystrayItem {
36 HWND hWnd;
37 HWND hWndToolTip;
38 NOTIFYICONDATAA notifyIcon;
39 struct _SystrayItem *nextTrayItem;
40};
41
42static SystrayItem *systray=NULL;
43
44BOOL (*SYSTRAY_ItemInit)(SystrayItem *ptrayItem) = 0;
45void (*SYSTRAY_ItemTerm)(SystrayItem *ptrayItem) = 0;
46void (*SYSTRAY_ItemSetMessage)(SystrayItem *ptrayItem, ULONG uCallbackMessage) = 0;
47void (*SYSTRAY_ItemSetIcon)(SystrayItem *ptrayItem, HICON hIcon) = 0;
48void (*SYSTRAY_ItemSetTip)(SystrayItem *ptrayItem, CHAR* szTip, int modify) = 0;
49
50
51static BOOL SYSTRAY_ItemIsEqual(PNOTIFYICONDATAA pnid1, PNOTIFYICONDATAA pnid2)
52{
53 if (pnid1->hWnd != pnid2->hWnd) return FALSE;
54 if (pnid1->uID != pnid2->uID) return FALSE;
55 return TRUE;
56}
57
58
59static BOOL SYSTRAY_Add(PNOTIFYICONDATAA pnid)
60{
61 SystrayItem **ptrayItem = &systray;
62
63 /* Find last element. */
64 while( *ptrayItem ) {
65 if ( SYSTRAY_ItemIsEqual(pnid, &(*ptrayItem)->notifyIcon) )
66 return FALSE;
67 ptrayItem = &((*ptrayItem)->nextTrayItem);
68 }
69 /* Allocate SystrayItem for element and add to end of list. */
70 (*ptrayItem) = ( SystrayItem *)malloc( sizeof(SystrayItem) );
71
72 /* Initialize and set data for the tray element. */
73 SYSTRAY_ItemInit( (*ptrayItem) );
74 (*ptrayItem)->notifyIcon.uID = pnid->uID; /* only needed for callback message */
75 (*ptrayItem)->notifyIcon.hWnd = pnid->hWnd; /* only needed for callback message */
76 SYSTRAY_ItemSetIcon (*ptrayItem, (pnid->uFlags&NIF_ICON) ?GetOS2Icon(pnid->hIcon) :0);
77 SYSTRAY_ItemSetMessage(*ptrayItem, (pnid->uFlags&NIF_MESSAGE)?pnid->uCallbackMessage:0);
78 SYSTRAY_ItemSetTip (*ptrayItem, (pnid->uFlags&NIF_TIP) ?pnid->szTip :"", FALSE);
79
80 TRACE("SYSTRAY_Add %p: 0x%08x 0x%08x 0x%08x 0x%08x %s\n", (*ptrayItem),
81 (*ptrayItem)->notifyIcon.hWnd, (*ptrayItem)->notifyIcon.hIcon,
82 pnid->uCallbackMessage, (*ptrayItem)->notifyIcon.uCallbackMessage,
83 pnid->szTip );
84 return TRUE;
85}
86
87
88static BOOL SYSTRAY_Modify(PNOTIFYICONDATAA pnid)
89{
90 SystrayItem *ptrayItem = systray;
91
92 while ( ptrayItem ) {
93 if ( SYSTRAY_ItemIsEqual(pnid, &ptrayItem->notifyIcon) ) {
94 if (pnid->uFlags & NIF_ICON)
95 SYSTRAY_ItemSetIcon(ptrayItem, GetOS2Icon(pnid->hIcon) );
96 if (pnid->uFlags & NIF_MESSAGE)
97 SYSTRAY_ItemSetMessage(ptrayItem, pnid->uCallbackMessage);
98 if (pnid->uFlags & NIF_TIP)
99 SYSTRAY_ItemSetTip(ptrayItem, pnid->szTip, TRUE);
100
101 TRACE("SYSTRAY_Modify %p: 0x%08x %s\n", ptrayItem, ptrayItem->notifyIcon.hWnd, pnid->szTip);
102 return TRUE;
103 }
104 ptrayItem = ptrayItem->nextTrayItem;
105 }
106 return FALSE; /* not found */
107}
108
109
110static BOOL SYSTRAY_Delete(PNOTIFYICONDATAA pnid)
111{
112 SystrayItem **ptrayItem = &systray;
113
114 while (*ptrayItem) {
115 if (SYSTRAY_ItemIsEqual(pnid, &(*ptrayItem)->notifyIcon)) {
116 SystrayItem *next = (*ptrayItem)->nextTrayItem;
117 TRACE("%p: 0x%08x %s\n", *ptrayItem, (*ptrayItem)->notifyIcon.hWnd, (*ptrayItem)->notifyIcon.szTip);
118 SYSTRAY_ItemTerm(*ptrayItem);
119
120 free(*ptrayItem);
121 *ptrayItem = next;
122
123 return TRUE;
124 }
125 ptrayItem = &((*ptrayItem)->nextTrayItem);
126 }
127
128 return FALSE; /* not found */
129}
130
131#ifndef __WIN32OS2__
132/*************************************************************************
133 *
134 */
135BOOL SYSTRAY_Init(void)
136{
137 return TRUE;
138}
139#endif
140
141/*************************************************************************
142 * Shell_NotifyIconA [SHELL32.297][SHELL32.296]
143 */
144BOOL WINAPI Shell_NotifyIconA(DWORD dwMessage, PNOTIFYICONDATAA pnid )
145{
146 BOOL flag=FALSE;
147 TRACE("enter %d %d %ld\n", pnid->hWnd, pnid->uID, dwMessage);
148 switch(dwMessage) {
149 case NIM_ADD:
150 flag = SYSTRAY_Add(pnid);
151 break;
152 case NIM_MODIFY:
153 flag = SYSTRAY_Modify(pnid);
154 break;
155 case NIM_DELETE:
156 flag = SYSTRAY_Delete(pnid);
157 break;
158 }
159 TRACE("leave %d %d %ld=%d\n", pnid->hWnd, pnid->uID, dwMessage, flag);
160 return flag;
161}
162
163/*************************************************************************
164 * Shell_NotifyIconW [SHELL32.298]
165 */
166BOOL WINAPI Shell_NotifyIconW (DWORD dwMessage, PNOTIFYICONDATAW pnid )
167{
168 BOOL ret;
169
170 PNOTIFYICONDATAA p = HeapAlloc(GetProcessHeap(),0,sizeof(NOTIFYICONDATAA));
171 memcpy(p, pnid, sizeof(NOTIFYICONDATAA));
172 WideCharToMultiByte( CP_ACP, 0, pnid->szTip, -1, p->szTip, sizeof(p->szTip), NULL, NULL );
173 p->szTip[sizeof(p->szTip)-1] = 0;
174
175 ret = Shell_NotifyIconA(dwMessage, p );
176
177 HeapFree(GetProcessHeap(),0,p);
178 return ret;
179}
180
181
182#ifdef __WIN32OS2__
183
184BOOL DoWin32PostMessage(HWND w, ULONG m, WPARAM mp1, LPARAM mp2 )
185{
186 TRACE("DoWin32WinPostMsg: HWND 0x%08x MSG 0x%08x ID 0x%08x MMSG 0x%08x\n", w, m, mp1, mp2);
187 if ( w && m )
188 {
189 return PostMessageA( w, m, mp1, mp2 );
190 }
191 return FALSE;
192}
193
194BOOL DoWin32CharToOem(const char *s, char *t)
195{
196 return CharToOemA( s , t );
197}
198
199#endif
Note: See TracBrowser for help on using the repository browser.