Changeset 10604 for trunk/src


Ignore:
Timestamp:
May 24, 2004, 10:47:03 AM (21 years ago)
Author:
sandervl
Message:

ER: OS2 Systray implementation

Location:
trunk/src/shell32
Files:
1 added
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/shell32/systray.c

    r10507 r10604  
    11/*
    2  *      Systray
     2 *  Systray
    33 *
    4  *      Copyright 1999 Kai Morich       <kai.morich@bigfoot.de>
     4 *  Copyright 1999 Kai Morich   <kai.morich@bigfoot.de>
    55 *
    66 *  Manage the systray window. That it actually appears in the docking
    77 *  area of KDE or GNOME is delegated to windows/x11drv/wnd.c,
    88 *  X11DRV_WND_DockWindow.
     9 *
     10 *  Modified by ErOs2 for usage with systray_os2.c
    911 *
    1012 */
     
    2426#include "heap.h"
    2527#include "config.h"
     28#include "winuser32.h"
    2629
    2730DEFAULT_DEBUG_CHANNEL(shell);
     31
     32
    2833
    2934typedef struct SystrayItem {
     
    3742static int firstSystray=TRUE; /* defer creation of window class until first systray item is created */
    3843
    39 static BOOL SYSTRAY_Delete(PNOTIFYICONDATAA pnid);
    40 
    41 
    42 #define ICON_SIZE GetSystemMetrics(SM_CXSMICON)
    43 /* space around icon (forces icon to center of KDE systray area) */
    44 #define ICON_BORDER  4
    45 
     44BOOL SYSTRAY_ItemInit(SystrayItem *ptrayItem);
     45void SYSTRAY_ItemTerm(SystrayItem *ptrayItem);
     46void SYSTRAY_ItemSetMessage(SystrayItem *ptrayItem, ULONG uCallbackMessage);
     47void SYSTRAY_ItemSetIcon(SystrayItem *ptrayItem, HICON hIcon);
     48void SYSTRAY_ItemSetTip(SystrayItem *ptrayItem, CHAR* szTip, int modify);
    4649
    4750
     
    5154  if (pnid1->uID  != pnid2->uID)  return FALSE;
    5255  return TRUE;
    53 }
    54 
    55 static LRESULT CALLBACK SYSTRAY_WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
    56 {
    57   HDC hdc;
    58   PAINTSTRUCT ps;
    59 
    60   switch (message) {
    61   case WM_PAINT:
    62   {
    63     RECT rc;
    64     SystrayItem  *ptrayItem = systray;
    65 
    66     while (ptrayItem) {
    67       if (ptrayItem->hWnd==hWnd) {
    68         if (ptrayItem->notifyIcon.hIcon) {
    69           hdc = BeginPaint(hWnd, &ps);
    70           GetClientRect(hWnd, &rc);
    71           if (!DrawIconEx(hdc, rc.left+ICON_BORDER, rc.top+ICON_BORDER, ptrayItem->notifyIcon.hIcon,
    72                           ICON_SIZE, ICON_SIZE, 0, 0, DI_DEFAULTSIZE|DI_NORMAL)) {
    73             ERR("Paint(SystrayWindow 0x%08x) failed -> removing SystrayItem %p\n", hWnd, ptrayItem);
    74             SYSTRAY_Delete(&ptrayItem->notifyIcon);
    75           }
    76         }
    77         break;
    78       }
    79       ptrayItem = ptrayItem->nextTrayItem;
    80     }
    81     EndPaint(hWnd, &ps);
    82   }
    83   break;
    84 
    85   case WM_MOUSEMOVE:
    86   case WM_LBUTTONDOWN:
    87   case WM_LBUTTONUP:
    88   case WM_RBUTTONDOWN:
    89   case WM_RBUTTONUP:
    90   case WM_MBUTTONDOWN:
    91   case WM_MBUTTONUP:
    92   {
    93     MSG msg;
    94     SystrayItem *ptrayItem = systray;
    95 
    96     while ( ptrayItem ) {
    97       if (ptrayItem->hWnd == hWnd) {
    98         msg.hwnd=hWnd;
    99         msg.message=message;
    100         msg.wParam=wParam;
    101         msg.lParam=lParam;
    102         msg.time = GetMessageTime ();
    103         msg.pt.x = LOWORD(GetMessagePos ());
    104         msg.pt.y = HIWORD(GetMessagePos ());
    105 
    106         SendMessageA(ptrayItem->hWndToolTip, TTM_RELAYEVENT, 0, (LPARAM)&msg);
    107       }
    108       ptrayItem = ptrayItem->nextTrayItem;
    109     }
    110   }
    111   /* fall through */
    112 
    113   case WM_LBUTTONDBLCLK:
    114   case WM_RBUTTONDBLCLK:
    115   case WM_MBUTTONDBLCLK:
    116   {
    117     SystrayItem *ptrayItem = systray;
    118 
    119     while (ptrayItem) {
    120       if (ptrayItem->hWnd == hWnd) {
    121         if (ptrayItem->notifyIcon.hWnd && ptrayItem->notifyIcon.uCallbackMessage) {
    122           if (!PostMessageA(ptrayItem->notifyIcon.hWnd, ptrayItem->notifyIcon.uCallbackMessage,
    123                             (WPARAM)ptrayItem->notifyIcon.uID, (LPARAM)message)) {
    124               ERR("PostMessage(SystrayWindow 0x%08x) failed -> removing SystrayItem %p\n", hWnd, ptrayItem);
    125               SYSTRAY_Delete(&ptrayItem->notifyIcon);
    126             }
    127         }
    128         break;
    129       }
    130       ptrayItem = ptrayItem->nextTrayItem;
    131     }
    132   }
    133   break;
    134 
    135   default:
    136     return (DefWindowProcA(hWnd, message, wParam, lParam));
    137   }
    138   return (0);
    139 
    140 }
    141 
    142 
    143 BOOL SYSTRAY_RegisterClass(void)
    144 {
    145   WNDCLASSA  wc;
    146 
    147   wc.style         = CS_SAVEBITS;
    148   wc.lpfnWndProc   = (WNDPROC)SYSTRAY_WndProc;
    149   wc.cbClsExtra    = 0;
    150   wc.cbWndExtra    = 0;
    151   wc.hInstance     = 0;
    152   wc.hIcon         = 0;
    153   wc.hCursor       = LoadCursorA(0, IDC_ARROWA);
    154   wc.hbrBackground = (HBRUSH)(COLOR_WINDOW);
    155   wc.lpszMenuName  = NULL;
    156   wc.lpszClassName = "WineSystray";
    157 
    158   if (!RegisterClassA(&wc)) {
    159     ERR("RegisterClass(WineSystray) failed\n");
    160     return FALSE;
    161   }
    162   return TRUE;
    163 }
    164 
    165 
    166 BOOL SYSTRAY_ItemInit(SystrayItem *ptrayItem)
    167 {
    168   RECT rect;
    169 
    170   /* Register the class if this is our first tray item. */
    171   if ( firstSystray ) {
    172     firstSystray = FALSE;
    173     if ( !SYSTRAY_RegisterClass() ) {
    174       ERR( "RegisterClass(WineSystray) failed\n" );
    175       return FALSE;
    176     }
    177   }
    178 #ifdef __WIN32OS2__
    179   //SvL: Disabled system tray for now
    180   //     Integrate with OS/2 WPS (WarpCenter tray?)
    181   dprintf(("WARNING: SHELL32: SYSTRAY_ItemInit: ignored"));
    182   return FALSE;
    183 #else
    184 
    185   /* Initialize the window size. */
    186   rect.left   = 0;
    187   rect.top    = 0;
    188   rect.right  = ICON_SIZE+2*ICON_BORDER;
    189   rect.bottom = ICON_SIZE+2*ICON_BORDER;
    190 
    191   ZeroMemory( ptrayItem, sizeof(SystrayItem) );
    192   /* Create tray window for icon. */
    193   ptrayItem->hWnd = CreateWindowExA( WS_EX_TRAYWINDOW,
    194                                 "WineSystray", "Wine-Systray",
    195                                 WS_VISIBLE,
    196                                 CW_USEDEFAULT, CW_USEDEFAULT,
    197                                 rect.right-rect.left, rect.bottom-rect.top,
    198                                 0, 0, 0, 0 );
    199   if ( !ptrayItem->hWnd ) {
    200     ERR( "CreateWindow(WineSystray) failed\n" );
    201     return FALSE;
    202   }
    203 
    204   /* Create tooltip for icon. */
    205   ptrayItem->hWndToolTip = CreateWindowA( TOOLTIPS_CLASSA,NULL,TTS_ALWAYSTIP,
    206                                      CW_USEDEFAULT, CW_USEDEFAULT,
    207                                      CW_USEDEFAULT, CW_USEDEFAULT,
    208                                      ptrayItem->hWnd, 0, 0, 0 );
    209   if ( !ptrayItem->hWndToolTip ) {
    210     ERR( "CreateWindow(TOOLTIP) failed\n" );
    211     return FALSE;
    212   }
    213   return TRUE;
    214 #endif
    215 }
    216 
    217 
    218 static void SYSTRAY_ItemTerm(SystrayItem *ptrayItem)
    219 {
    220   if(ptrayItem->notifyIcon.hIcon)
    221      DestroyIcon(ptrayItem->notifyIcon.hIcon);   
    222   if(ptrayItem->hWndToolTip)
    223       DestroyWindow(ptrayItem->hWndToolTip);
    224   if(ptrayItem->hWnd)
    225     DestroyWindow(ptrayItem->hWnd);
    226   return;
    227 }
    228 
    229 
    230 void SYSTRAY_ItemSetMessage(SystrayItem *ptrayItem, UINT uCallbackMessage)
    231 {
    232   ptrayItem->notifyIcon.uCallbackMessage = uCallbackMessage;
    233 }
    234 
    235 
    236 void SYSTRAY_ItemSetIcon(SystrayItem *ptrayItem, HICON hIcon)
    237 {
    238   ptrayItem->notifyIcon.hIcon = CopyIcon(hIcon);
    239   InvalidateRect(ptrayItem->hWnd, NULL, TRUE);
    240 }
    241 
    242 
    243 void SYSTRAY_ItemSetTip(SystrayItem *ptrayItem, CHAR* szTip, int modify)
    244 {
    245   TTTOOLINFOA ti;
    246 
    247   strncpy(ptrayItem->notifyIcon.szTip, szTip, sizeof(ptrayItem->notifyIcon.szTip));
    248   ptrayItem->notifyIcon.szTip[sizeof(ptrayItem->notifyIcon.szTip)-1]=0;
    249 
    250   ti.cbSize = sizeof(TTTOOLINFOA);
    251   ti.uFlags = 0;
    252   ti.hwnd = ptrayItem->hWnd;
    253   ti.hinst = 0;
    254   ti.uId = 0;
    255   ti.lpszText = ptrayItem->notifyIcon.szTip;
    256   ti.rect.left   = 0;
    257   ti.rect.top    = 0;
    258   ti.rect.right  = ICON_SIZE+2*ICON_BORDER;
    259   ti.rect.bottom = ICON_SIZE+2*ICON_BORDER;
    260 
    261   if(modify)
    262     SendMessageA(ptrayItem->hWndToolTip, TTM_UPDATETIPTEXTA, 0, (LPARAM)&ti);
    263   else
    264     SendMessageA(ptrayItem->hWndToolTip, TTM_ADDTOOLA, 0, (LPARAM)&ti);
    26556}
    26657
     
    28374  (*ptrayItem)->notifyIcon.uID = pnid->uID; /* only needed for callback message */
    28475  (*ptrayItem)->notifyIcon.hWnd = pnid->hWnd; /* only needed for callback message */
    285   SYSTRAY_ItemSetIcon   (*ptrayItem, (pnid->uFlags&NIF_ICON)   ?pnid->hIcon           :0);
     76  SYSTRAY_ItemSetIcon   (*ptrayItem, (pnid->uFlags&NIF_ICON)   ?GetOS2Icon(pnid->hIcon)  :0);
    28677  SYSTRAY_ItemSetMessage(*ptrayItem, (pnid->uFlags&NIF_MESSAGE)?pnid->uCallbackMessage:0);
    28778  SYSTRAY_ItemSetTip    (*ptrayItem, (pnid->uFlags&NIF_TIP)    ?pnid->szTip           :"", FALSE);
    28879
    289   TRACE("%p: 0x%08x %s\n",  (*ptrayItem), (*ptrayItem)->notifyIcon.hWnd,
    290                                           (*ptrayItem)->notifyIcon.szTip);
     80  TRACE("SYSTRAY_Add %p: 0x%08x 0x%08x 0x%08x %s\n",  (*ptrayItem), (*ptrayItem)->notifyIcon.hWnd,
     81        pnid->uCallbackMessage, (*ptrayItem)->notifyIcon.uCallbackMessage,
     82        pnid->szTip );
    29183  return TRUE;
    29284}
     
    30092    if ( SYSTRAY_ItemIsEqual(pnid, &ptrayItem->notifyIcon) ) {
    30193      if (pnid->uFlags & NIF_ICON)
    302         SYSTRAY_ItemSetIcon(ptrayItem, pnid->hIcon);
     94        SYSTRAY_ItemSetIcon(ptrayItem, GetOS2Icon(pnid->hIcon) );
    30395      if (pnid->uFlags & NIF_MESSAGE)
    30496        SYSTRAY_ItemSetMessage(ptrayItem, pnid->uCallbackMessage);
     
    30698        SYSTRAY_ItemSetTip(ptrayItem, pnid->szTip, TRUE);
    30799
    308       TRACE("%p: 0x%08x %s\n", ptrayItem, ptrayItem->notifyIcon.hWnd, ptrayItem->notifyIcon.szTip);
     100      TRACE("SYSTRAY_Modify %p: 0x%08x %s\n", ptrayItem, ptrayItem->notifyIcon.hWnd, pnid->szTip);
    309101      return TRUE;
    310102    }
     
    345137
    346138/*************************************************************************
    347  * Shell_NotifyIconA                    [SHELL32.297][SHELL32.296]
     139 * Shell_NotifyIconA            [SHELL32.297][SHELL32.296]
    348140 */
    349141BOOL WINAPI Shell_NotifyIconA(DWORD dwMessage, PNOTIFYICONDATAA pnid )
    350142{
    351 #ifdef __WIN32OS2__
    352   //SvL: Disabled system tray for now
    353   //     Integrate with OS/2 WPS (WarpCenter tray?)
    354   dprintf(("Shell_NotifyIconA %x: ignored", dwMessage));
    355   return TRUE;
    356 #else
    357143  BOOL flag=FALSE;
    358144  TRACE("enter %d %d %ld\n", pnid->hWnd, pnid->uID, dwMessage);
     
    370156  TRACE("leave %d %d %ld=%d\n", pnid->hWnd, pnid->uID, dwMessage, flag);
    371157  return flag;
    372 #endif
    373158}
    374159
    375160/*************************************************************************
    376  * Shell_NotifyIconW                    [SHELL32.298]
     161 * Shell_NotifyIconW            [SHELL32.298]
    377162 */
    378163BOOL WINAPI Shell_NotifyIconW (DWORD dwMessage, PNOTIFYICONDATAW pnid )
    379164{
    380         BOOL ret;
     165    BOOL ret;
    381166
    382         PNOTIFYICONDATAA p = HeapAlloc(GetProcessHeap(),0,sizeof(NOTIFYICONDATAA));
    383         memcpy(p, pnid, sizeof(NOTIFYICONDATAA));
     167    PNOTIFYICONDATAA p = HeapAlloc(GetProcessHeap(),0,sizeof(NOTIFYICONDATAA));
     168    memcpy(p, pnid, sizeof(NOTIFYICONDATAA));
    384169        WideCharToMultiByte( CP_ACP, 0, pnid->szTip, -1, p->szTip, sizeof(p->szTip), NULL, NULL );
    385170        p->szTip[sizeof(p->szTip)-1] = 0;
    386171
    387         ret = Shell_NotifyIconA(dwMessage, p );
     172    ret = Shell_NotifyIconA(dwMessage, p );
    388173
    389         HeapFree(GetProcessHeap(),0,p);
    390         return ret;
     174    HeapFree(GetProcessHeap(),0,p);
     175    return ret;
    391176}
     177
     178
     179#ifdef __WIN32OS2__
     180
     181BOOL DoWin32PostMessage(HWND w, ULONG m, WPARAM mp1, LPARAM mp2 )
     182{
     183    TRACE("DoWin32WinPostMsg: HWND 0x%08x  MSG 0x%08x  ID 0x%08x  MMSG 0x%08x\n", w, m, mp1, mp2);
     184    if ( w && m )
     185    {
     186        return PostMessageA( w, m, mp1, mp2 );
     187    }
     188    return FALSE;
     189}
     190
     191BOOL DoWin32CharToOem(const char *s, char *t)
     192{
     193        return CharToOemA( s , t );
     194}
     195
     196#endif
Note: See TracChangeset for help on using the changeset viewer.