📄 gtkdocklet-win32.c
字号:
/* * System tray icon (aka docklet) plugin for Winpidgin * * Copyright (C) 2002-3 Robert McQueen <robot101@debian.org> * Copyright (C) 2003 Herman Bloggs <hermanator12002@yahoo.com> * Inspired by a similar plugin by: * John (J5) Palmieri <johnp@martianrock.com> * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of the * License, or (at your option) any later version. * * This program 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 * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA * 02111-1307, USA. */#include <windows.h>#include <gdk/gdkwin32.h>#include <gdk/gdk.h>#include "internal.h"#include "gtkblist.h"#include "debug.h"#include "resource.h"#include "MinimizeToTray.h"#include "gtkwin32dep.h"#include "gtkdocklet.h"#include "pidginstock.h"/* * DEFINES, MACROS & DATA TYPES */#define WM_TRAYMESSAGE WM_USER /* User defined WM Message *//* * LOCALS */static HWND systray_hwnd = NULL;/* additional two cached_icons entries for pending and connecting icons */static HICON cached_icons[PURPLE_STATUS_NUM_PRIMITIVES + 2];static GtkWidget *image = NULL;static NOTIFYICONDATA _nicon_data;static LRESULT CALLBACK systray_mainmsg_handler(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) { static UINT taskbarRestartMsg; /* static here means value is kept across multiple calls to this func */ switch(msg) { case WM_CREATE: purple_debug_info("docklet", "WM_CREATE\n"); taskbarRestartMsg = RegisterWindowMessage("TaskbarCreated"); break; case WM_TIMER: purple_debug_info("docklet", "WM_TIMER\n"); break; case WM_DESTROY: purple_debug_info("docklet", "WM_DESTROY\n"); break; case WM_TRAYMESSAGE: { int type = 0; /* We'll use Double Click - Single click over on linux */ if(lparam == WM_LBUTTONDBLCLK) type = 1; else if(lparam == WM_MBUTTONUP) type = 2; else if(lparam == WM_RBUTTONUP) type = 3; else break; pidgin_docklet_clicked(type); break; } default: if (msg == taskbarRestartMsg) { /* explorer crashed and left us hanging... This will put the systray icon back in it's place, when it restarts */ Shell_NotifyIcon(NIM_ADD, &_nicon_data); } break; }/* end switch */ return DefWindowProc(hwnd, msg, wparam, lparam);}/* Create hidden window to process systray messages */static HWND systray_create_hiddenwin() { WNDCLASSEX wcex; LPCTSTR wname; wname = TEXT("WinpidginSystrayWinCls"); wcex.cbSize = sizeof(wcex); wcex.style = 0; wcex.lpfnWndProc = systray_mainmsg_handler; wcex.cbClsExtra = 0; wcex.cbWndExtra = 0; wcex.hInstance = winpidgin_exe_hinstance(); wcex.hIcon = NULL; wcex.hCursor = NULL, wcex.hbrBackground = NULL; wcex.lpszMenuName = NULL; wcex.lpszClassName = wname; wcex.hIconSm = NULL; RegisterClassEx(&wcex); /* Create the window */ return (CreateWindow(wname, "", 0, 0, 0, 0, 0, GetDesktopWindow(), NULL, winpidgin_exe_hinstance(), 0));}static void systray_init_icon(HWND hWnd) { ZeroMemory(&_nicon_data, sizeof(_nicon_data)); _nicon_data.cbSize = sizeof(NOTIFYICONDATA); _nicon_data.hWnd = hWnd; _nicon_data.uID = 0; _nicon_data.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP; _nicon_data.uCallbackMessage = WM_TRAYMESSAGE; _nicon_data.hIcon = NULL; lstrcpy(_nicon_data.szTip, PIDGIN_NAME); Shell_NotifyIcon(NIM_ADD, &_nicon_data); pidgin_docklet_embedded();}/* This is ganked from GTK+. * When we can use GTK+ 2.10 and the GtkStatusIcon stuff, this will no longer be necesary */#define WIN32_GDI_FAILED(api) printf("GDI FAILED %s\n", api)static gboolean_gdk_win32_pixbuf_to_hicon_supports_alpha (void){ static gboolean is_win_xp=FALSE, is_win_xp_checked=FALSE; if (!is_win_xp_checked) { is_win_xp_checked = TRUE; if (!G_WIN32_IS_NT_BASED ()) is_win_xp = FALSE; else { OSVERSIONINFO version; memset (&version, 0, sizeof (version)); version.dwOSVersionInfoSize = sizeof (version); is_win_xp = GetVersionEx (&version) && version.dwPlatformId == VER_PLATFORM_WIN32_NT && (version.dwMajorVersion > 5 || (version.dwMajorVersion == 5 && version.dwMinorVersion >= 1)); } } return is_win_xp;}static HBITMAPcreate_alpha_bitmap (gint size, guchar **outdata){ BITMAPV5HEADER bi; HDC hdc; HBITMAP hBitmap; ZeroMemory (&bi, sizeof (BITMAPV5HEADER)); bi.bV5Size = sizeof (BITMAPV5HEADER); bi.bV5Height = bi.bV5Width = size; bi.bV5Planes = 1; bi.bV5BitCount = 32; bi.bV5Compression = BI_BITFIELDS; /* The following mask specification specifies a supported 32 BPP * alpha format for Windows XP (BGRA format). */ bi.bV5RedMask = 0x00FF0000; bi.bV5GreenMask = 0x0000FF00; bi.bV5BlueMask = 0x000000FF; bi.bV5AlphaMask = 0xFF000000; /* Create the DIB section with an alpha channel. */ hdc = GetDC (NULL); if (!hdc) { WIN32_GDI_FAILED ("GetDC"); return NULL; } hBitmap = CreateDIBSection (hdc, (BITMAPINFO *)&bi, DIB_RGB_COLORS, (PVOID *) outdata, NULL, (DWORD)0); if (hBitmap == NULL) WIN32_GDI_FAILED ("CreateDIBSection"); ReleaseDC (NULL, hdc); return hBitmap;}static HBITMAPcreate_color_bitmap (gint size, guchar **outdata, gint bits){ struct { BITMAPV4HEADER bmiHeader; RGBQUAD bmiColors[2]; } bmi; HDC hdc; HBITMAP hBitmap; ZeroMemory (&bmi, sizeof (bmi)); bmi.bmiHeader.bV4Size = sizeof (BITMAPV4HEADER); bmi.bmiHeader.bV4Height = bmi.bmiHeader.bV4Width = size; bmi.bmiHeader.bV4Planes = 1; bmi.bmiHeader.bV4BitCount = bits; bmi.bmiHeader.bV4V4Compression = BI_RGB; /* when bits is 1, these will be used. * bmiColors[0] already zeroed from ZeroMemory() */ bmi.bmiColors[1].rgbBlue = 0xFF; bmi.bmiColors[1].rgbGreen = 0xFF; bmi.bmiColors[1].rgbRed = 0xFF; hdc = GetDC (NULL); if (!hdc) { WIN32_GDI_FAILED ("GetDC"); return NULL; } hBitmap = CreateDIBSection (hdc, (BITMAPINFO *)&bmi, DIB_RGB_COLORS, (PVOID *) outdata, NULL, (DWORD)0); if (hBitmap == NULL) WIN32_GDI_FAILED ("CreateDIBSection"); ReleaseDC (NULL, hdc); return hBitmap;}static gbooleanpixbuf_to_hbitmaps_alpha_winxp (GdkPixbuf *pixbuf, HBITMAP *color, HBITMAP *mask){ /* Based on code from * http://www.dotnet247.com/247reference/msgs/13/66301.aspx */ HBITMAP hColorBitmap, hMaskBitmap; guchar *indata, *inrow; guchar *colordata, *colorrow, *maskdata, *maskbyte; gint width, height, size, i, i_offset, j, j_offset, rowstride; guint maskstride, mask_bit; width = gdk_pixbuf_get_width (pixbuf); /* width of icon */ height = gdk_pixbuf_get_height (pixbuf); /* height of icon */ /* The bitmaps are created square */ size = MAX (width, height); hColorBitmap = create_alpha_bitmap (size, &colordata); if (!hColorBitmap) return FALSE; hMaskBitmap = create_color_bitmap (size, &maskdata, 1); if (!hMaskBitmap) { DeleteObject (hColorBitmap); return FALSE; } /* MSDN says mask rows are aligned to "LONG" boundaries */ maskstride = (((size + 31) & ~31) >> 3); indata = gdk_pixbuf_get_pixels (pixbuf); rowstride = gdk_pixbuf_get_rowstride (pixbuf); if (width > height) { i_offset = 0; j_offset = (width - height) / 2; } else { i_offset = (height - width) / 2; j_offset = 0; } for (j = 0; j < height; j++) { colorrow = colordata + 4*(j+j_offset)*size + 4*i_offset; maskbyte = maskdata + (j+j_offset)*maskstride + i_offset/8; mask_bit = (0x80 >> (i_offset % 8)); inrow = indata + (height-j-1)*rowstride; for (i = 0; i < width; i++) { colorrow[4*i+0] = inrow[4*i+2]; colorrow[4*i+1] = inrow[4*i+1]; colorrow[4*i+2] = inrow[4*i+0]; colorrow[4*i+3] = inrow[4*i+3]; if (inrow[4*i+3] == 0) maskbyte[0] |= mask_bit; /* turn ON bit */ else maskbyte[0] &= ~mask_bit; /* turn OFF bit */ mask_bit >>= 1; if (mask_bit == 0) { mask_bit = 0x80; maskbyte++; } } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -