[prev in list] [next in list] [prev in thread] [next in thread] 

List:       wine-patches
Subject:    Move Notification Window (aka systray) To A Separate Process (Try
From:       Robert Shearman <rob () codeweavers ! com>
Date:       2005-06-30 13:49:52
Message-ID: 42C3F880.6060607 () codeweavers ! com
[Download RAW message or body]

Hi,

Changes since last time:
- winesystray -> explorer
- a few small cleanups and one extra comment
- include diff of programs/Makefile.in

Changelog:
Move notification window (aka systray) to a separate process.

-- 
Rob Shearman


["systray_sep_process2.diff" (text/x-patch)]

Index: dlls/shell32/systray.c
===================================================================
RCS file: /home/wine/wine/dlls/shell32/systray.c,v
retrieving revision 1.30
diff -u -p -r1.30 systray.c
--- dlls/shell32/systray.c	20 Jun 2005 10:30:15 -0000	1.30
+++ dlls/shell32/systray.c	30 Jun 2005 13:43:59 -0000
@@ -1,11 +1,9 @@
 /*
- *	Systray
+ * Systray handling
  *
- *	Copyright 1999 Kai Morich	<kai.morich@bigfoot.de>
- *
- *  Manage the systray window. That it actually appears in the docking
- *  area of KDE is handled in dlls/x11drv/window.c,
- *  X11DRV_set_wm_hints using KWM_DOCKWINDOW.
+ * Copyright 1999 Kai Morich	<kai.morich@bigfoot.de>
+ * Copyright 2004 Mike Hearn, for CodeWeavers
+ * Copyright 2005 Robert Shearman
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -22,375 +20,178 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
-#include "config.h"
-
-#ifdef HAVE_UNISTD_H
-# include <unistd.h>
-#endif
 #include <stdarg.h>
-#include <string.h>
 
 #include "windef.h"
 #include "winbase.h"
-#include "winnls.h"
 #include "wingdi.h"
+#include "winnls.h"
 #include "winuser.h"
-#include "shlobj.h"
 #include "shellapi.h"
-#include "shell32_main.h"
-#include "commctrl.h"
-#include "wine/debug.h"
-
-WINE_DEFAULT_DEBUG_CHANNEL(shell);
-
-typedef struct SystrayItem {
-  HWND                  hWnd;
-  HWND                  hWndToolTip;
-  NOTIFYICONDATAA       notifyIcon;
-  struct SystrayItem    *nextTrayItem;
-} SystrayItem;
-
-static SystrayItem *systray=NULL;
-static int firstSystray=TRUE; /* defer creation of window class until first systray \
                item is created */
-
-static BOOL SYSTRAY_Delete(PNOTIFYICONDATAA pnid);
-
-
-#define ICON_SIZE GetSystemMetrics(SM_CXSMICON)
-/* space around icon (forces icon to center of KDE systray area) */
-#define ICON_BORDER  4
-
-
-
-static BOOL SYSTRAY_ItemIsEqual(PNOTIFYICONDATAA pnid1, PNOTIFYICONDATAA pnid2)
-{
-  if (pnid1->hWnd != pnid2->hWnd) return FALSE;
-  if (pnid1->uID  != pnid2->uID)  return FALSE;
-  return TRUE;
-}
-
-static LRESULT CALLBACK SYSTRAY_WndProc(HWND hWnd, UINT message, WPARAM wParam, \
                LPARAM lParam)
-{
-  HDC hdc;
-  PAINTSTRUCT ps;
-
-  switch (message) {
-  case WM_PAINT:
-  {
-    RECT rc;
-    SystrayItem  *ptrayItem = systray;
-
-    while (ptrayItem) {
-      if (ptrayItem->hWnd==hWnd) {
-	if (ptrayItem->notifyIcon.hIcon) {
-	  hdc = BeginPaint(hWnd, &ps);
-	  GetClientRect(hWnd, &rc);
-	  if (!DrawIconEx(hdc, rc.left+ICON_BORDER, rc.top+ICON_BORDER, \
                ptrayItem->notifyIcon.hIcon,
-			  ICON_SIZE, ICON_SIZE, 0, 0, DI_DEFAULTSIZE|DI_NORMAL)) {
-	    ERR("Paint(SystrayWindow %p) failed -> removing SystrayItem %p\n", hWnd, \
                ptrayItem);
-	    SYSTRAY_Delete(&ptrayItem->notifyIcon);
-	  }
-	}
-	break;
-      }
-      ptrayItem = ptrayItem->nextTrayItem;
-    }
-    EndPaint(hWnd, &ps);
-  }
-  break;
-
-  case WM_MOUSEMOVE:
-  case WM_LBUTTONDOWN:
-  case WM_LBUTTONUP:
-  case WM_RBUTTONDOWN:
-  case WM_RBUTTONUP:
-  case WM_MBUTTONDOWN:
-  case WM_MBUTTONUP:
-  {
-    MSG msg;
-    SystrayItem *ptrayItem = systray;
-
-    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;
-    }
-  }
-  /* fall through */
-
-  case WM_LBUTTONDBLCLK:
-  case WM_RBUTTONDBLCLK:
-  case WM_MBUTTONDBLCLK:
-  {
-    SystrayItem *ptrayItem = systray;
-
-    while (ptrayItem) {
-      if (ptrayItem->hWnd == hWnd) {
-	if (ptrayItem->notifyIcon.hWnd && ptrayItem->notifyIcon.uCallbackMessage) {
-          if (!PostMessageA(ptrayItem->notifyIcon.hWnd, \
                ptrayItem->notifyIcon.uCallbackMessage,
-                            (WPARAM)ptrayItem->notifyIcon.uID, (LPARAM)message)) {
-	      ERR("PostMessage(SystrayWindow %p) failed -> removing SystrayItem %p\n", \
                hWnd, ptrayItem);
-	      SYSTRAY_Delete(&ptrayItem->notifyIcon);
-	    }
-        }
-	break;
-      }
-      ptrayItem = ptrayItem->nextTrayItem;
-    }
-  }
-  break;
-
-  default:
-    return (DefWindowProcA(hWnd, message, wParam, lParam));
-  }
-  return (0);
-
-}
-
-
-static BOOL SYSTRAY_RegisterClass(void)
-{
-  WNDCLASSA  wc;
-
-  wc.style         = CS_SAVEBITS|CS_DBLCLKS;
-  wc.lpfnWndProc   = SYSTRAY_WndProc;
-  wc.cbClsExtra    = 0;
-  wc.cbWndExtra    = 0;
-  wc.hInstance     = 0;
-  wc.hIcon         = 0;
-  wc.hCursor       = LoadCursorA(0, (LPSTR)IDC_ARROW);
-  wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
-  wc.lpszMenuName  = NULL;
-  wc.lpszClassName = "WineSystray";
-
-  if (!RegisterClassA(&wc)) {
-    ERR("RegisterClass(WineSystray) failed\n");
-    return FALSE;
-  }
-  return TRUE;
-}
-
-
-static BOOL SYSTRAY_ItemInit(SystrayItem *ptrayItem)
-{
-  RECT rect;
-
-  /* Register the class if this is our first tray item. */
-  if ( firstSystray ) {
-    firstSystray = FALSE;
-    if ( !SYSTRAY_RegisterClass() ) {
-      ERR( "RegisterClass(WineSystray) failed\n" );
-      return FALSE;
-    }
-  }
-
-  /* Initialize the window size. */
-  rect.left   = 0;
-  rect.top    = 0;
-  rect.right  = ICON_SIZE+2*ICON_BORDER;
-  rect.bottom = ICON_SIZE+2*ICON_BORDER;
-
-  ZeroMemory( ptrayItem, sizeof(SystrayItem) );
-  /* 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" );
-    return FALSE;
-  }
-
-  /* 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 ) {
-    ERR( "CreateWindow(TOOLTIP) failed\n" );
-    return FALSE;
-  }
-  return TRUE;
-}
-
-
-static void SYSTRAY_ItemTerm(SystrayItem *ptrayItem)
-{
-  if(ptrayItem->notifyIcon.hIcon)
-     DestroyIcon(ptrayItem->notifyIcon.hIcon);
-  if(ptrayItem->hWndToolTip)
-      DestroyWindow(ptrayItem->hWndToolTip);
-  if(ptrayItem->hWnd)
-    DestroyWindow(ptrayItem->hWnd);
-  return;
-}
-
-
-static void SYSTRAY_ItemSetMessage(SystrayItem *ptrayItem, UINT uCallbackMessage)
-{
-  ptrayItem->notifyIcon.uCallbackMessage = uCallbackMessage;
-}
-
 
-static void SYSTRAY_ItemSetIcon(SystrayItem *ptrayItem, HICON hIcon)
-{
-  if(ptrayItem->notifyIcon.hIcon)
-    DestroyIcon(ptrayItem->notifyIcon.hIcon);
-  ptrayItem->notifyIcon.hIcon = CopyIcon(hIcon);
-  InvalidateRect(ptrayItem->hWnd, NULL, TRUE);
-}
-
-
-static void SYSTRAY_ItemSetTip(SystrayItem *ptrayItem, CHAR* szTip, int modify)
-{
-  TTTOOLINFOA ti;
+#include "wine/debug.h"
 
-  lstrcpynA(ptrayItem->notifyIcon.szTip, szTip, \
sizeof(ptrayItem->notifyIcon.szTip)); +WINE_DEFAULT_DEBUG_CHANNEL(systray);
 
-  ti.cbSize = sizeof(TTTOOLINFOA);
-  ti.uFlags = 0;
-  ti.hwnd = ptrayItem->hWnd;
-  ti.hinst = 0;
-  ti.uId = 0;
-  ti.lpszText = ptrayItem->notifyIcon.szTip;
-  ti.rect.left   = 0;
-  ti.rect.top    = 0;
-  ti.rect.right  = ICON_SIZE+2*ICON_BORDER;
-  ti.rect.bottom = ICON_SIZE+2*ICON_BORDER;
-
-  if(modify)
-    SendMessageA(ptrayItem->hWndToolTip, TTM_UPDATETIPTEXTA, 0, (LPARAM)&ti);
-  else
-    SendMessageA(ptrayItem->hWndToolTip, TTM_ADDTOOLA, 0, (LPARAM)&ti);
-}
+const static WCHAR classname[] = /* Shell_TrayWnd */ \
{'S','h','e','l','l','_','T','r','a','y','W','n','d','\0'};  
+/* start timeout of 1 second */
+#define SYSTRAY_START_TIMEOUT 1000
 
-static BOOL SYSTRAY_Add(PNOTIFYICONDATAA pnid)
+static BOOL start_systray_process(void)
 {
-  SystrayItem **ptrayItem = &systray;
-
-  /* Find last element. */
-  while( *ptrayItem ) {
-    if ( SYSTRAY_ItemIsEqual(pnid, &(*ptrayItem)->notifyIcon) )
-      return FALSE;
-    ptrayItem = &((*ptrayItem)->nextTrayItem);
-  }
-  /* Allocate SystrayItem for element and add to end of list. */
-  (*ptrayItem) = HeapAlloc(GetProcessHeap(),0,sizeof(SystrayItem));
-
-  /* Initialize and set data for the tray element. */
-  SYSTRAY_ItemInit( (*ptrayItem) );
-  (*ptrayItem)->notifyIcon.uID = pnid->uID; /* only needed for callback message */
-  (*ptrayItem)->notifyIcon.hWnd = pnid->hWnd; /* only needed for callback message */
-  SYSTRAY_ItemSetIcon   (*ptrayItem, (pnid->uFlags&NIF_ICON)   ?pnid->hIcon          \
                :0);
-  SYSTRAY_ItemSetMessage(*ptrayItem, \
                (pnid->uFlags&NIF_MESSAGE)?pnid->uCallbackMessage:0);
-  SYSTRAY_ItemSetTip    (*ptrayItem, (pnid->uFlags&NIF_TIP)    ?pnid->szTip          \
                :"", FALSE);
-
-  TRACE("%p: %p %s\n",  (*ptrayItem), (*ptrayItem)->notifyIcon.hWnd,
-                                          (*ptrayItem)->notifyIcon.szTip);
-  return TRUE;
-}
+    STARTUPINFOW          sinfo;
+    PROCESS_INFORMATION   pinfo;
+    WCHAR                 process_name[] = {'e','x','p','l','o','r','e','r',0};
+    static const WCHAR    event_name[] = \
{'W','i','n','e','S','y','s','t','r','a','y','I','n','i','t','e','d',0}; +    HANDLE  \
systray_ready_event; +    DWORD                 wait;
 
+    TRACE("No tray window found, starting %s\n", debugstr_w(process_name));
 
-static BOOL SYSTRAY_Modify(PNOTIFYICONDATAA pnid)
-{
-  SystrayItem *ptrayItem = systray;
-
-  while ( ptrayItem ) {
-    if ( SYSTRAY_ItemIsEqual(pnid, &ptrayItem->notifyIcon) ) {
-      if (pnid->uFlags & NIF_ICON)
-        SYSTRAY_ItemSetIcon(ptrayItem, pnid->hIcon);
-      if (pnid->uFlags & NIF_MESSAGE)
-        SYSTRAY_ItemSetMessage(ptrayItem, pnid->uCallbackMessage);
-      if (pnid->uFlags & NIF_TIP)
-        SYSTRAY_ItemSetTip(ptrayItem, pnid->szTip, TRUE);
+    ZeroMemory(&sinfo, sizeof(sinfo));
+    sinfo.cb = sizeof(sinfo);
 
-      TRACE("%p: %p %s\n", ptrayItem, ptrayItem->notifyIcon.hWnd, \
                ptrayItem->notifyIcon.szTip);
-      return TRUE;
+    if (CreateProcessW(NULL, process_name, NULL, NULL, FALSE, 0, NULL, NULL, &sinfo, \
&pinfo) == 0) +    {
+        ERR("Could not start %s, error 0x%lx\n", debugstr_w(process_name), \
GetLastError()); +        return FALSE;
     }
-    ptrayItem = ptrayItem->nextTrayItem;
-  }
-  return FALSE; /* not found */
-}
-
 
-static BOOL SYSTRAY_Delete(PNOTIFYICONDATAA pnid)
-{
-  SystrayItem **ptrayItem = &systray;
+    CloseHandle(pinfo.hThread);
+    CloseHandle(pinfo.hProcess);
 
-  while (*ptrayItem) {
-    if (SYSTRAY_ItemIsEqual(pnid, &(*ptrayItem)->notifyIcon)) {
-      SystrayItem *next = (*ptrayItem)->nextTrayItem;
-      TRACE("%p: %p %s\n", *ptrayItem, (*ptrayItem)->notifyIcon.hWnd, \
                (*ptrayItem)->notifyIcon.szTip);
-      SYSTRAY_ItemTerm(*ptrayItem);
+    systray_ready_event = CreateEventW(NULL, TRUE, FALSE, event_name);
+    if (!systray_ready_event) return FALSE;
 
-      HeapFree(GetProcessHeap(),0,*ptrayItem);
-      *ptrayItem = next;
+    /* don't guess how long to wait, just wait for process to signal to us
+     * that it has created the Shell_TrayWnd class before continuing */
+    wait = WaitForSingleObject(systray_ready_event, SYSTRAY_START_TIMEOUT);
+    CloseHandle(systray_ready_event);
 
-      return TRUE;
+    if (wait == WAIT_TIMEOUT)
+    {
+        ERR("timeout waiting for %s to start\n", debugstr_w(process_name));
+        return FALSE;
     }
-    ptrayItem = &((*ptrayItem)->nextTrayItem);
-  }
-
-  return FALSE; /* not found */
-}
 
-/*************************************************************************
- *
- */
-BOOL SYSTRAY_Init(void)
-{
-  return TRUE;
+    return TRUE;
 }
 
 /*************************************************************************
  * Shell_NotifyIcon			[SHELL32.296]
  * Shell_NotifyIconA			[SHELL32.297]
  */
-BOOL WINAPI Shell_NotifyIconA(DWORD dwMessage, PNOTIFYICONDATAA pnid )
+BOOL WINAPI Shell_NotifyIconA(DWORD dwMessage, PNOTIFYICONDATAA pnid)
 {
-  BOOL flag=FALSE;
-  TRACE("enter %p %d %ld\n", pnid->hWnd, pnid->uID, dwMessage);
-  switch(dwMessage) {
-  case NIM_ADD:
-    flag = SYSTRAY_Add(pnid);
-    break;
-  case NIM_MODIFY:
-    flag = SYSTRAY_Modify(pnid);
-    break;
-  case NIM_DELETE:
-    flag = SYSTRAY_Delete(pnid);
-    break;
-  }
-  TRACE("leave %p %d %ld=%d\n", pnid->hWnd, pnid->uID, dwMessage, flag);
-  return flag;
+    NOTIFYICONDATAW nidW;
+    
+    nidW.cbSize = sizeof(nidW);
+    nidW.hWnd   = pnid->hWnd;
+    nidW.uID    = pnid->uID;
+    nidW.uFlags = pnid->uFlags;
+    nidW.uCallbackMessage = pnid->uCallbackMessage;
+    nidW.hIcon  = pnid->hIcon;
+
+    /* szTip */
+    MultiByteToWideChar(CP_ACP, 0, pnid->szTip, sizeof(pnid->szTip), nidW.szTip, \
sizeof(nidW.szTip)); +
+    nidW.dwState      = pnid->dwState;
+    nidW.dwStateMask  = pnid->dwStateMask;
+
+    /* szInfo */
+    MultiByteToWideChar(CP_ACP, 0, pnid->szInfo, sizeof(pnid->szInfo),  nidW.szInfo, \
sizeof(nidW.szInfo)); +
+    nidW.uTimeout = pnid->uTimeout;
+
+    /* szInfoTitle */
+    MultiByteToWideChar(CP_ACP, 0, pnid->szInfoTitle, sizeof(pnid->szInfoTitle), \
nidW.szInfoTitle, sizeof(nidW.szInfoTitle)); +    
+    nidW.dwInfoFlags = pnid->dwInfoFlags;
+
+    return Shell_NotifyIconW(dwMessage, &nidW);
 }
 
 /*************************************************************************
  * Shell_NotifyIconW			[SHELL32.298]
  */
-BOOL WINAPI Shell_NotifyIconW (DWORD dwMessage, PNOTIFYICONDATAW pnid )
+BOOL WINAPI Shell_NotifyIconW(DWORD dwMessage, PNOTIFYICONDATAW nid)
 {
-	BOOL ret;
+    HWND tray;
+    COPYDATASTRUCT cds;
+
+    TRACE("dwMessage = %ld\n", dwMessage);
 
-	PNOTIFYICONDATAA p = HeapAlloc(GetProcessHeap(),0,sizeof(NOTIFYICONDATAA));
-	memcpy(p, pnid, sizeof(NOTIFYICONDATAA));
-        WideCharToMultiByte( CP_ACP, 0, pnid->szTip, -1, p->szTip, sizeof(p->szTip), \
                NULL, NULL );
-        p->szTip[sizeof(p->szTip)-1] = 0;
+    tray = FindWindowExW(0, NULL, classname, NULL);
+
+    /* this isn't how native does it - it assumes that Explorer is always
+     * running */
+    if (!tray)
+    {
+        if (!start_systray_process())
+            return FALSE;
+        tray = FindWindowExW(0, NULL, classname, NULL);
+    }
+
+    if (!tray) return FALSE;
+
+    cds.dwData = dwMessage;
+
+    /* FIXME: if statement only needed because we don't support interprocess
+     * icon handles */
+    if (nid->uFlags & NIF_ICON)
+    {
+        ICONINFO iconinfo;
+        char *buffer;
+        BITMAP bmMask;
+        BITMAP bmColour;
+        LONG cbMaskBits;
+        LONG cbColourBits;
+
+        if (!GetIconInfo(nid->hIcon, &iconinfo))
+            return FALSE;
+
+        if (!GetObjectW(iconinfo.hbmMask, sizeof(bmMask), &bmMask) ||
+            !GetObjectW(iconinfo.hbmColor, sizeof(bmColour), &bmColour))
+        {
+            DeleteObject(iconinfo.hbmMask);
+            DeleteObject(iconinfo.hbmColor);
+            return FALSE;
+        }
 
-	ret = Shell_NotifyIconA(dwMessage, p );
+        cbMaskBits = (bmMask.bmPlanes * bmMask.bmWidth * bmMask.bmHeight * \
bmMask.bmBitsPixel) / 8; +        cbColourBits = (bmColour.bmPlanes * \
bmColour.bmWidth * bmColour.bmHeight * bmColour.bmBitsPixel) / 8; +        cds.cbData \
= sizeof(*nid) + 2*sizeof(BITMAP) + cbMaskBits + cbColourBits; +        buffer = \
HeapAlloc(GetProcessHeap(), 0, cds.cbData); +        if (!buffer) return FALSE;
+        cds.lpData = buffer;
+
+        memcpy(buffer, nid, sizeof(*nid));
+        buffer += sizeof(*nid);
+        memcpy(buffer, &bmMask, sizeof(bmMask));
+        buffer += sizeof(bmMask);
+        memcpy(buffer, &bmColour, sizeof(bmColour));
+        buffer += sizeof(bmColour);
+        GetBitmapBits(iconinfo.hbmMask, cbMaskBits, buffer);
+        buffer += cbMaskBits;
+        GetBitmapBits(iconinfo.hbmColor, cbColourBits, buffer);
+        buffer += cbColourBits;
+
+        DeleteObject(iconinfo.hbmMask);
+        DeleteObject(iconinfo.hbmColor);
+    }
+    else
+    {
+        cds.cbData = sizeof(*nid);
+        cds.lpData = nid;
+    }
+
+    SendMessageW(tray, WM_COPYDATA, (WPARAM)nid->hWnd, (LPARAM)&cds);
+
+    /* FIXME: if statement only needed because we don't support interprocess
+     * icon handles */
+    if (nid->uFlags & NIF_ICON)
+        HeapFree(GetProcessHeap(), 0, cds.lpData);
 
-	HeapFree(GetProcessHeap(),0,p);
-	return ret;
+    return TRUE;
 }
Index: configure.ac
===================================================================
RCS file: /home/wine/wine/configure.ac,v
retrieving revision 1.368
diff -u -p -r1.368 configure.ac
--- configure.ac	27 Jun 2005 12:07:49 -0000	1.368
+++ configure.ac	30 Jun 2005 13:43:59 -0000
@@ -1767,6 +1767,7 @@ programs/clock/Makefile
 programs/cmdlgtst/Makefile
 programs/control/Makefile
 programs/expand/Makefile
+programs/explorer/Makefile
 programs/msiexec/Makefile
 programs/notepad/Makefile
 programs/progman/Makefile
Index: programs/Makefile.in
===================================================================
RCS file: /home/wine/wine/programs/Makefile.in,v
retrieving revision 1.47
diff -u -p -r1.47 Makefile.in
--- programs/Makefile.in	10 May 2005 16:02:04 -0000	1.47
+++ programs/Makefile.in	30 Jun 2005 13:43:59 -0000
@@ -11,6 +11,7 @@ SUBDIRS = \
 	cmdlgtst \
 	control \
 	expand \
+	explorer \
 	msiexec \
 	notepad \
 	progman \
@@ -43,6 +44,7 @@ INSTALLSUBDIRS = \
 	clock \
 	control \
 	expand \
+	explorer \
 	msiexec \
 	notepad \
 	progman \
@@ -95,6 +97,7 @@ SYMLINKS = \
 	cmdlgtst.exe$(DLLEXT) \
 	control.exe$(DLLEXT) \
 	expand.exe$(DLLEXT) \
+	explorer.exe$(DLLEXT) \
 	icinfo.exe$(DLLEXT) \
 	msiexec.exe$(DLLEXT) \
 	notepad.exe$(DLLEXT) \
@@ -183,6 +186,9 @@ control.exe$(DLLEXT): control/control.ex
 expand.exe$(DLLEXT): expand/expand.exe$(DLLEXT)
 	$(RM) $@ && $(LN_S) expand/expand.exe$(DLLEXT) $@
 
+explorer.exe$(DLLEXT): explorer/explorer.exe$(DLLEXT)
+	$(RM) $@ && $(LN_S) explorer/explorer.exe$(DLLEXT) $@
+
 icinfo.exe$(DLLEXT): avitools/icinfo.exe$(DLLEXT)
 	$(RM) $@ && $(LN_S) avitools/icinfo.exe$(DLLEXT) $@
 
@@ -267,6 +273,7 @@ clock/clock.exe$(DLLEXT): clock
 cmdlgtst/cmdlgtst.exe$(DLLEXT): cmdlgtst
 control/control.exe$(DLLEXT): control
 expand/expand.exe$(DLLEXT): expand
+explorer/explorer.exe$(DLLEXT): explorer
 avitools/icinfo.exe$(DLLEXT): avitools
 msiexec/msiexec.exe$(DLLEXT): msiexec
 notepad/notepad.exe$(DLLEXT): notepad
--- /dev/null	2005-06-30 02:31:55.548593392 -0500
+++ programs/explorer/main.c	2005-06-26 08:34:07.000000000 -0500
@@ -0,0 +1,75 @@
+/*
+ * Copyright (C) 2004 Mike Hearn, for CodeWeavers
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * This program is a general purpose bridge between the Windows
+ * environment and native. Currently it deals with system tray
+ * windows, in future it may take on other functions that the standard
+ * windows shell (Explorer) deals with, for instance responding to DDE
+ * requests and syncing the wallpaper with native.
+ */
+
+#include <stdio.h>
+#include <assert.h>
+
+#include <windows.h>
+#include <wine/debug.h>
+
+#include <systray.h>
+
+WINE_DEFAULT_DEBUG_CHANNEL(explorer);
+
+unsigned int shell_refs = 0;
+
+int main(int argc, char *argv[])
+{
+    initialize_systray();
+
+    while (TRUE)
+    {
+        const int timeout = 5;
+        MSG message;
+        DWORD res;
+
+        res = MsgWaitForMultipleObjectsEx(0, NULL, shell_refs ? INFINITE : timeout * \
1000, +                                          QS_ALLINPUT, MWMO_WAITALL);
+        if (res == WAIT_TIMEOUT) break;
+
+        res = PeekMessage(&message, 0, 0, 0, PM_REMOVE);
+        if (!res) continue;
+
+        if (message.message == WM_QUIT)
+        {
+            WINE_FIXME("Somebody sent the shell a WM_QUIT message, should we \
reboot?"); +
+            /* Sending the tray window a WM_QUIT message is actually a
+             * tip given by some programming websites as a way of
+             * forcing a reboot! let's delay implementing this hack
+             * until we find a program that really needs it. for now
+             * just bail out.
+             */
+            
+            break;
+        }
+
+        TranslateMessage(&message);
+        DispatchMessage(&message);
+    }
+
+    shutdown_systray();
+    
+    return 0;
+}
--- /dev/null	2005-06-30 02:31:55.548593392 -0500
+++ programs/explorer/systray.h	2005-06-26 08:34:07.000000000 -0500
@@ -0,0 +1,23 @@
+/*
+ * Copyright (C) 2004 Mike Hearn, for CodeWeavers
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+void initialize_systray();
+void shutdown_systray();
+
+/* when this drops to zero, a few seconds later the shell will shut down */
+extern unsigned int shell_refs;       
--- /dev/null	2005-06-30 02:31:55.548593392 -0500
+++ programs/explorer/systray.c	2005-06-30 08:39:20.000000000 -0500
@@ -0,0 +1,404 @@
+/*
+ * Copyright (C) 2004 Mike Hearn, for CodeWeavers
+ * Copyright (C) 2005 Robert Shearman
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+/* There are two types of window involved here. The first is the
+ * listener window. This is like the taskbar in Windows. It doesn't
+ * ever appear on-screen in our implementation, instead we create
+ * individual mini "adaptor" windows which are docked by the native
+ * systray host.
+ *
+ * In future for those who don't have a systray we could make the
+ * listener window more clever so it can draw itself like the Windows
+ * tray area does (with a clock and stuff).
+ */
+
+#include <assert.h>
+
+#define UNICODE
+#define _WIN32_IE 0x500
+#include <windows.h>
+
+#include <wine/debug.h>
+#include <wine/list.h>
+
+#include "systray.h"
+
+WINE_DEFAULT_DEBUG_CHANNEL(systray);
+
+const static WCHAR adaptor_classname[] = /* Adaptor */ \
{'A','d','a','p','t','o','r',0}; +
+/* tray state */
+struct tray
+{
+    HWND           window;
+    struct list    icons;
+};
+
+/* an individual systray icon, unpacked from the NOTIFYICONDATA and always in \
unicode */ +struct icon
+{
+    struct list    entry;
+    HICON          image;    /* the image to render */
+    HWND           owner;    /* the HWND passed in to the Shell_NotifyIcon call */
+    HWND           window;   /* the adaptor window */
+    UINT           id;       /* the unique id given by the app */
+    UINT           callback_message;
+};
+
+static struct tray tray;
+
+/* adaptor code */
+
+#define ICON_SIZE GetSystemMetrics(SM_CXSMICON)
+/* space around icon (forces icon to center of KDE systray area) */
+#define ICON_BORDER  4
+
+static LRESULT WINAPI adaptor_wndproc(HWND window, UINT msg,
+                                      WPARAM wparam, LPARAM lparam)
+{
+    struct icon *icon = NULL;
+    BOOL ret;
+
+    WINE_TRACE("hwnd=%p, msg=0x%x\n", window, msg);
+
+    /* set the icon data for the window from the data passed into CreateWindow */
+    if (msg == WM_NCCREATE)
+        SetWindowLongPtrW(window, GWLP_USERDATA, (LPARAM)((const CREATESTRUCT \
*)lparam)->lpCreateParams); +
+    icon = (struct icon *) GetWindowLongPtr(window, GWLP_USERDATA);
+
+    switch (msg)
+    {
+        case WM_PAINT:
+        {
+            RECT rc;
+            int top;
+            PAINTSTRUCT  ps;
+            HDC          hdc;
+
+            WINE_TRACE("painting\n");
+            
+            hdc = BeginPaint(window, &ps);
+            GetClientRect(window, &rc);
+            
+            /* calculate top so we can deal with arbitrary sized trays */
+            top = ((rc.bottom-rc.top)/2) - ((ICON_SIZE)/2);
+            
+            DrawIconEx(hdc, (ICON_BORDER/2), top, icon->image,
+                       ICON_SIZE, ICON_SIZE, 0, 0, DI_DEFAULTSIZE|DI_NORMAL);
+            
+            EndPaint(window, &ps);
+            break;
+	}
+
+        case WM_MOUSEMOVE:
+        case WM_LBUTTONDOWN:
+        case WM_LBUTTONUP:
+        case WM_RBUTTONDOWN:
+        case WM_RBUTTONUP:
+        case WM_MBUTTONDOWN:
+        case WM_MBUTTONUP:
+        case WM_LBUTTONDBLCLK:
+        case WM_RBUTTONDBLCLK:
+        case WM_MBUTTONDBLCLK:
+        {
+            /* notify the owner hwnd of the message */
+            WINE_TRACE("relaying 0x%x\n", msg);
+            ret = PostMessage(icon->owner, icon->callback_message, (WPARAM) \
icon->id, (LPARAM) msg); +            if (!ret && (GetLastError() == \
ERROR_INVALID_HANDLE)) +            {
+                WINE_ERR("application window was destroyed without removing "
+                    "notification icon, removing automatically\n");
+                DestroyWindow(window);
+            }
+            return 0;
+        }
+
+        case WM_NCDESTROY:
+            SetWindowLongPtr(window, GWLP_USERDATA, 0);
+
+            list_remove(&icon->entry);
+            DestroyIcon(icon->image);
+            HeapFree(GetProcessHeap(), 0, icon);
+
+            shell_refs--;
+            WINE_TRACE("shell now has %d refs\n", shell_refs);
+            break;
+    }
+
+    return DefWindowProc(window, msg, wparam, lparam);
+}
+
+
+/* listener code */
+
+static struct icon *get_icon(HWND owner, UINT id)
+{
+    struct icon *this;
+
+    /* search for the icon */
+    LIST_FOR_EACH_ENTRY( this, &tray.icons, struct icon, entry )
+        if ((this->id == id) && (this->owner = owner)) return this;
+
+    return NULL;
+}
+
+static void modify_icon(const NOTIFYICONDATAW *nid)
+{
+    struct icon    *icon;
+    
+    WINE_TRACE("id=0x%x, hwnd=%p\n", nid->uID, nid->hWnd);
+    
+    /* demarshal the request from the NID */
+    icon = get_icon(nid->hWnd, nid->uID);
+    if (!icon)
+    {
+        WINE_WARN("Invalid icon ID (0x%x) for HWND %p\n", nid->uID, nid->hWnd);
+        return;
+    }
+
+    if (nid->uFlags & NIF_ICON)
+    {
+        if (icon->image) DestroyIcon(icon->image);
+        icon->image = CopyIcon(nid->hIcon);
+
+        RedrawWindow(icon->window, NULL, NULL, RDW_ERASE | RDW_INVALIDATE | \
RDW_UPDATENOW); +    }
+
+    if (nid->uFlags & NIF_MESSAGE)
+    {
+        icon->callback_message = nid->uCallbackMessage;
+    }
+}
+
+static void add_icon(const NOTIFYICONDATAW *nid)
+{
+    RECT rect;
+    struct icon  *icon;
+    const static WCHAR adaptor_windowname[] = /* Wine System Tray Adaptor */ \
{'W','i','n','e',' ','S','y','s','t','e','m',' ','T','r','a','y',' \
','A','d','a','p','t','o','r',0}; +
+    WINE_TRACE("id=0x%x, hwnd=%p\n", nid->uID, nid->hWnd);
+
+    if ((icon = get_icon(nid->hWnd, nid->uID)))
+    {
+        WINE_WARN("duplicate tray icon add, buggy app?\n");
+        return;
+    }
+    
+    if (!(icon = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*icon))))
+    {
+        WINE_ERR("out of memory\n");
+        return;
+    }
+    
+    icon->id    = nid->uID;
+    icon->owner = nid->hWnd;
+    icon->image = NULL;
+
+    rect.left = 0;
+    rect.top = 0;
+    rect.right = GetSystemMetrics(SM_CXSMICON);
+    rect.bottom = GetSystemMetrics(SM_CYSMICON);
+    AdjustWindowRect(&rect, 0, FALSE);
+
+    /* create the adaptor window */
+    icon->window = CreateWindowEx(WS_EX_TRAYWINDOW, adaptor_classname,
+                                  adaptor_windowname, 0,
+                                  CW_USEDEFAULT, CW_USEDEFAULT,
+                                  rect.right-rect.left, rect.bottom - rect.top,
+                                  NULL, NULL, NULL, icon);
+
+    ShowWindow(icon->window, SW_SHOW);
+    
+    list_add_tail(&tray.icons, &icon->entry);
+    
+    modify_icon(nid);
+
+    shell_refs++;
+    WINE_TRACE("shell now has %d refs\n", shell_refs);
+}
+
+static void delete_icon(const NOTIFYICONDATAW *nid)
+{
+    struct icon *icon = get_icon(nid->hWnd, nid->uID);
+
+    WINE_TRACE("id=0x%x, hwnd=%p\n", nid->uID, nid->hWnd);
+   
+    if (!icon)
+    {
+        WINE_ERR("invalid tray icon ID specified: %ud\n", nid->uID);
+        return;
+    }
+
+    DestroyWindow(icon->window);
+}
+
+static void handle_incoming(HWND hwndSource, COPYDATASTRUCT *cds)
+{
+    NOTIFYICONDATAW nid;
+
+    if (cds->cbData < sizeof(nid)) return;
+    memcpy(&nid, cds->lpData, sizeof(nid));
+
+    /* FIXME: if statement only needed because we don't support interprocess
+     * icon handles */
+    if (nid.uFlags & NIF_ICON)
+    {
+        LONG cbMaskBits;
+        LONG cbColourBits;
+        BITMAP bmMask;
+        BITMAP bmColour;
+        const char *buffer = cds->lpData;
+
+        buffer += sizeof(nid);
+
+        if (cds->cbData < sizeof(nid) + 2 * sizeof(BITMAP))
+        {
+            WINE_ERR("buffer underflow\n");
+            return;
+        }
+
+        memcpy(&bmMask, buffer, sizeof(bmMask));
+        buffer += sizeof(bmMask);
+        memcpy(&bmColour, buffer, sizeof(bmColour));
+        buffer += sizeof(bmColour);
+
+        cbMaskBits = (bmMask.bmPlanes * bmMask.bmWidth * bmMask.bmHeight * \
bmMask.bmBitsPixel) / 8; +        cbColourBits = (bmColour.bmPlanes * \
bmColour.bmWidth * bmColour.bmHeight * bmColour.bmBitsPixel) / 8; +
+        if (cds->cbData < sizeof(nid) + 2 * sizeof(BITMAP) + cbMaskBits + \
cbColourBits) +        {
+            WINE_ERR("buffer underflow\n");
+            return;
+        }
+
+        /* sanity check */
+        if ((bmColour.bmWidth != bmMask.bmWidth) || (bmColour.bmHeight != \
bmMask.bmHeight)) +        {
+            WINE_ERR("colour and mask bitmaps aren't consistent\n");
+            return;
+        }
+
+        nid.hIcon = CreateIcon(NULL, bmColour.bmWidth, bmColour.bmHeight,
+                               bmColour.bmPlanes, bmColour.bmBitsPixel,
+                               buffer, buffer + cbMaskBits);
+    }
+
+    switch (cds->dwData)
+    {
+    case NIM_ADD:
+        add_icon(&nid);
+        break;
+    case NIM_DELETE:
+        delete_icon(&nid);
+        break;
+    case NIM_MODIFY:
+        modify_icon(&nid);
+        break;
+    default:
+        WINE_FIXME("unhandled tray message: %ld\n", cds->dwData);
+        break;
+    }
+
+    /* FIXME: if statement only needed because we don't support interprocess
+     * icon handles */
+    if (nid.uFlags & NIF_ICON)
+        DestroyIcon(nid.hIcon);
+}
+
+static LRESULT WINAPI listener_wndproc(HWND window, UINT msg,
+                                       WPARAM wparam, LPARAM lparam)
+{
+    if (msg == WM_COPYDATA)
+        handle_incoming((HWND)wparam, (COPYDATASTRUCT *)lparam);
+
+    return DefWindowProc(window, msg, wparam, lparam);
+}
+
+
+/* this function creates the the listener window */
+void initialize_systray()
+{
+    WNDCLASSEX class;
+    HANDLE event;
+    static const WCHAR classname[] = /* Shell_TrayWnd */ \
{'S','h','e','l','l','_','T','r','a','y','W','n','d',0}; +    static const WCHAR \
winname[]   = /* Wine Systray Listener */ +        {'W','i','n','e',' \
','S','y','s','t','r','a','y',' ','L','i','s','t','e','n','e','r',0}; +    static \
const WCHAR    event_name[] = \
{'W','i','n','e','S','y','s','t','r','a','y','I','n','i','t','e','d',0}; +
+    WINE_TRACE("initiaizing\n");
+    
+    list_init(&tray.icons);
+
+    /* register the systray listener window class */
+    ZeroMemory(&class, sizeof(class));
+    class.cbSize        = sizeof(class);
+    class.lpfnWndProc   = &listener_wndproc;
+    class.hInstance     = NULL;
+    class.hIcon         = LoadIcon(0, IDI_WINLOGO);
+    class.hCursor       = LoadCursor(0, IDC_ARROW);
+    class.hbrBackground = (HBRUSH) COLOR_WINDOW;
+    class.lpszClassName = (WCHAR *) &classname;
+
+    if (!RegisterClassEx(&class))
+    {
+        WINE_ERR("Could not register SysTray window class\n");
+        return;
+    }
+
+    /* now register the adaptor window class */
+    ZeroMemory(&class, sizeof(class));
+    class.cbSize        = sizeof(class);
+    class.lpfnWndProc   = adaptor_wndproc;
+    class.hInstance     = NULL;
+    class.hIcon         = LoadIcon(0, IDI_WINLOGO);
+    class.hCursor       = LoadCursor(0, IDC_ARROW);
+    class.hbrBackground = (HBRUSH) COLOR_WINDOW;
+    class.lpszClassName = adaptor_classname;
+    class.style         = CS_SAVEBITS | CS_DBLCLKS;
+
+    if (!RegisterClassEx(&class))
+    {
+        WINE_ERR("Could not register adaptor class\n");
+        return;
+    }
+    
+    tray.window = CreateWindow(classname, winname, WS_OVERLAPPED,
+                               CW_USEDEFAULT, CW_USEDEFAULT,
+                               0, 0, 0, 0, 0, 0);
+
+    if (!tray.window)
+    {
+        WINE_ERR("Could not create tray window\n");
+        return;
+    }
+
+    /* tell shell32 that we're ready */
+    event = OpenEventW(EVENT_MODIFY_STATE, FALSE, event_name);
+    if (event)
+    {
+        SetEvent(event);
+        CloseHandle(event);
+    }
+}
+
+void shutdown_systray()
+{
+    DestroyWindow(tray.window);
+}
--- /dev/null	2005-06-30 02:31:55.548593392 -0500
+++ programs/explorer/Makefile.in	2005-06-28 12:29:51.000000000 -0500
@@ -0,0 +1,16 @@
+TOPSRCDIR = @top_srcdir@
+TOPOBJDIR = ../..
+SRCDIR    = @srcdir@
+VPATH     = @srcdir@
+MODULE    = explorer.exe
+APPMODE   = -mwindows
+IMPORTS   = user32 gdi32 kernel32
+
+C_SRCS = \
+	main.c \
+	systray.c
+
+
+@MAKE_PROG_RULES@
+
+### Dependencies:



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic