annotate gtk/win32/gtkdocklet-win32.c @ 14683:a8c2af13b96d

[gaim-migrate @ 17435] Fix the docklet on wingaim. What is the plan for the docklet prefs? committer: Tailor Script <tailor@pidgin.im>
author Daniel Atallah <daniel.atallah@gmail.com>
date Fri, 06 Oct 2006 05:03:28 +0000
parents
children 510da3975938
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
14683
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
1 /*
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
2 * System tray icon (aka docklet) plugin for Gaim
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
3 *
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
4 * Copyright (C) 2002-3 Robert McQueen <robot101@debian.org>
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
5 * Copyright (C) 2003 Herman Bloggs <hermanator12002@yahoo.com>
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
6 * Inspired by a similar plugin by:
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
7 * John (J5) Palmieri <johnp@martianrock.com>
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
8 *
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
9 * This program is free software; you can redistribute it and/or
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
10 * modify it under the terms of the GNU General Public License as
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
11 * published by the Free Software Foundation; either version 2 of the
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
12 * License, or (at your option) any later version.
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
13 *
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
14 * This program is distributed in the hope that it will be useful, but
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
17 * General Public License for more details.
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
18 *
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
19 * You should have received a copy of the GNU General Public License
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
20 * along with this program; if not, write to the Free Software
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
22 * 02111-1307, USA.
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
23 */
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
24
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
25 #include <windows.h>
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
26 #include <gdk/gdkwin32.h>
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
27 #include <gdk/gdk.h>
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
28
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
29 #include "internal.h"
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
30 #include "gtkblist.h"
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
31 #include "debug.h"
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
32
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
33 #include "resource.h"
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
34 #include "MinimizeToTray.h"
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
35 #include "gtkwin32dep.h"
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
36 #include "gtkdocklet.h"
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
37
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
38 /*
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
39 * DEFINES, MACROS & DATA TYPES
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
40 */
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
41 #define WM_TRAYMESSAGE WM_USER /* User defined WM Message */
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
42
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
43 /*
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
44 * LOCALS
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
45 */
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
46 static HWND systray_hwnd = 0;
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
47 static HICON sysicon_disconn = 0;
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
48 static HICON sysicon_conn = 0;
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
49 static HICON sysicon_away = 0;
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
50 static HICON sysicon_pend = 0;
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
51 static HICON sysicon_awypend = 0;
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
52 static HICON sysicon_blank = 0;
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
53 static NOTIFYICONDATA wgaim_nid;
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
54
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
55
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
56 static LRESULT CALLBACK systray_mainmsg_handler(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) {
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
57 static UINT taskbarRestartMsg; /* static here means value is kept across multiple calls to this func */
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
58
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
59 switch(msg) {
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
60 case WM_CREATE:
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
61 gaim_debug(GAIM_DEBUG_INFO, "tray icon", "WM_CREATE\n");
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
62 taskbarRestartMsg = RegisterWindowMessage("TaskbarCreated");
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
63 break;
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
64
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
65 case WM_TIMER:
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
66 gaim_debug(GAIM_DEBUG_INFO, "tray icon", "WM_TIMER\n");
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
67 break;
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
68
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
69 case WM_DESTROY:
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
70 gaim_debug(GAIM_DEBUG_INFO, "tray icon", "WM_DESTROY\n");
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
71 break;
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
72
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
73 case WM_TRAYMESSAGE:
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
74 {
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
75 int type = 0;
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
76
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
77 /* We'll use Double Click - Single click over on linux */
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
78 if(lparam == WM_LBUTTONDBLCLK)
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
79 type = 1;
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
80 else if(lparam == WM_MBUTTONUP)
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
81 type = 2;
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
82 else if(lparam == WM_RBUTTONUP)
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
83 type = 3;
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
84 else
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
85 break;
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
86
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
87 gaim_gtk_docklet_clicked(type);
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
88 break;
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
89 }
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
90 default:
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
91 if (msg == taskbarRestartMsg) {
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
92 /* explorer crashed and left us hanging...
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
93 This will put the systray icon back in it's place, when it restarts */
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
94 Shell_NotifyIcon(NIM_ADD, &wgaim_nid);
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
95 }
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
96 break;
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
97 }/* end switch */
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
98
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
99 return DefWindowProc(hwnd, msg, wparam, lparam);
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
100 }
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
101
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
102 /* Create hidden window to process systray messages */
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
103 static HWND systray_create_hiddenwin() {
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
104 WNDCLASSEX wcex;
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
105 LPCTSTR wname;
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
106
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
107 wname = TEXT("WingaimSystrayWinCls");
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
108
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
109
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
110 wcex.cbSize = sizeof(wcex);
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
111 wcex.style = 0;
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
112 wcex.lpfnWndProc = systray_mainmsg_handler;
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
113 wcex.cbClsExtra = 0;
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
114 wcex.cbWndExtra = 0;
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
115 wcex.hInstance = gtkwgaim_hinstance();
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
116 wcex.hIcon = NULL;
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
117 wcex.hCursor = NULL,
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
118 wcex.hbrBackground = NULL;
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
119 wcex.lpszMenuName = NULL;
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
120 wcex.lpszClassName = wname;
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
121 wcex.hIconSm = NULL;
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
122
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
123 RegisterClassEx(&wcex);
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
124
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
125 /* Create the window */
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
126 return (CreateWindow(wname, "", 0, 0, 0, 0, 0, GetDesktopWindow(), NULL, gtkwgaim_hinstance(), 0));
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
127 }
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
128
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
129 static void systray_init_icon(HWND hWnd, HICON icon) {
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
130 ZeroMemory(&wgaim_nid, sizeof(wgaim_nid));
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
131 wgaim_nid.cbSize = sizeof(NOTIFYICONDATA);
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
132 wgaim_nid.hWnd = hWnd;
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
133 wgaim_nid.uID = 0;
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
134 wgaim_nid.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP;
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
135 wgaim_nid.uCallbackMessage = WM_TRAYMESSAGE;
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
136 wgaim_nid.hIcon = icon;
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
137 lstrcpy(wgaim_nid.szTip, "Gaim");
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
138 Shell_NotifyIcon(NIM_ADD, &wgaim_nid);
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
139 gaim_gtk_docklet_embedded();
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
140 }
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
141
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
142 static void systray_change_icon(HICON icon) {
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
143 wgaim_nid.hIcon = icon;
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
144 Shell_NotifyIcon(NIM_MODIFY, &wgaim_nid);
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
145 }
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
146
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
147 static void systray_remove_nid(void) {
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
148 Shell_NotifyIcon(NIM_DELETE, &wgaim_nid);
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
149 }
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
150
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
151 static void wgaim_tray_update_icon(DockletStatus icon) {
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
152 switch (icon) {
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
153 case DOCKLET_STATUS_OFFLINE:
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
154 systray_change_icon(sysicon_disconn);
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
155 break;
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
156 case DOCKLET_STATUS_CONNECTING:
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
157 break;
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
158 case DOCKLET_STATUS_ONLINE:
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
159 systray_change_icon(sysicon_conn);
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
160 break;
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
161 case DOCKLET_STATUS_ONLINE_PENDING:
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
162 systray_change_icon(sysicon_pend);
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
163 break;
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
164 case DOCKLET_STATUS_AWAY:
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
165 systray_change_icon(sysicon_away);
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
166 break;
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
167 case DOCKLET_STATUS_AWAY_PENDING:
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
168 systray_change_icon(sysicon_awypend);
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
169 break;
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
170 }
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
171 }
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
172
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
173 static void wgaim_tray_blank_icon() {
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
174 systray_change_icon(sysicon_blank);
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
175 }
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
176
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
177 static void wgaim_tray_set_tooltip(gchar *tooltip) {
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
178 if (tooltip) {
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
179 char *locenc = NULL;
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
180 locenc = g_locale_from_utf8(tooltip, -1, NULL, NULL, NULL);
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
181 lstrcpyn(wgaim_nid.szTip, locenc, sizeof(wgaim_nid.szTip) / sizeof(TCHAR));
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
182 g_free(locenc);
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
183 } else {
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
184 lstrcpy(wgaim_nid.szTip, "Gaim");
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
185 }
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
186 Shell_NotifyIcon(NIM_MODIFY, &wgaim_nid);
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
187 }
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
188
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
189 static void wgaim_tray_minimize(GaimGtkBuddyList *gtkblist) {
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
190 MinimizeWndToTray(GDK_WINDOW_HWND(gtkblist->window->window));
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
191 }
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
192
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
193 static void wgaim_tray_maximize(GaimGtkBuddyList *gtkblist) {
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
194 RestoreWndFromTray(GDK_WINDOW_HWND(gtkblist->window->window));
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
195 }
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
196
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
197
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
198 static void wgaim_tray_create() {
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
199 OSVERSIONINFO osinfo;
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
200 /* dummy window to process systray messages */
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
201 systray_hwnd = systray_create_hiddenwin();
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
202
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
203 osinfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
204 GetVersionEx(&osinfo);
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
205
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
206 /* Load icons, and init systray notify icon
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
207 * NOTE: Windows < XP only supports displaying 4-bit images in the Systray,
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
208 * 2K and ME will use the highest color depth that the desktop will support,
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
209 * but will scale it back to 4-bits for display.
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
210 * That is why we use custom 4-bit icons for pre XP Windowses */
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
211 if ((osinfo.dwMajorVersion == 5 && osinfo.dwMinorVersion > 0) ||
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
212 (osinfo.dwMajorVersion >= 6))
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
213 {
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
214 sysicon_disconn = (HICON)LoadImage(gtkwgaim_hinstance(), MAKEINTRESOURCE(GAIM_OFFLINE_TRAY_ICON), IMAGE_ICON, 16, 16, 0);
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
215 sysicon_conn = (HICON)LoadImage(gtkwgaim_hinstance(), MAKEINTRESOURCE(GAIM_TRAY_ICON), IMAGE_ICON, 16, 16, 0);
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
216 sysicon_away = (HICON)LoadImage(gtkwgaim_hinstance(), MAKEINTRESOURCE(GAIM_AWAY_TRAY_ICON), IMAGE_ICON, 16, 16, 0);
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
217 sysicon_pend = (HICON)LoadImage(gtkwgaim_hinstance(), MAKEINTRESOURCE(GAIM_PEND_TRAY_ICON), IMAGE_ICON, 16, 16, 0);
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
218 sysicon_awypend = (HICON)LoadImage(gtkwgaim_hinstance(), MAKEINTRESOURCE(GAIM_AWAYPEND_TRAY_ICON), IMAGE_ICON, 16, 16, 0);
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
219 } else {
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
220 sysicon_disconn = (HICON)LoadImage(gtkwgaim_hinstance(), MAKEINTRESOURCE(GAIM_OFFLINE_TRAY_ICON_4BIT), IMAGE_ICON, 16, 16, 0);
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
221 sysicon_conn = (HICON)LoadImage(gtkwgaim_hinstance(), MAKEINTRESOURCE(GAIM_TRAY_ICON_4BIT), IMAGE_ICON, 16, 16, 0);
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
222 sysicon_away = (HICON)LoadImage(gtkwgaim_hinstance(), MAKEINTRESOURCE(GAIM_AWAY_TRAY_ICON_4BIT), IMAGE_ICON, 16, 16, 0);
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
223 sysicon_pend = (HICON)LoadImage(gtkwgaim_hinstance(), MAKEINTRESOURCE(GAIM_PEND_TRAY_ICON_4BIT), IMAGE_ICON, 16, 16, 0);
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
224 sysicon_awypend = (HICON)LoadImage(gtkwgaim_hinstance(), MAKEINTRESOURCE(GAIM_AWAYPEND_TRAY_ICON_4BIT), IMAGE_ICON, 16, 16, 0);
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
225 }
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
226 sysicon_blank = (HICON)LoadImage(gtkwgaim_hinstance(), MAKEINTRESOURCE(GAIM_BLANK_TRAY_ICON), IMAGE_ICON, 16, 16, 0);
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
227
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
228 /* Create icon in systray */
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
229 systray_init_icon(systray_hwnd, sysicon_disconn);
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
230
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
231 gaim_signal_connect(gaim_gtk_blist_get_handle(), "gtkblist-hiding",
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
232 gaim_gtk_docklet_get_handle(), GAIM_CALLBACK(wgaim_tray_minimize), NULL);
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
233 gaim_signal_connect(gaim_gtk_blist_get_handle(), "gtkblist-unhiding",
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
234 gaim_gtk_docklet_get_handle(), GAIM_CALLBACK(wgaim_tray_maximize), NULL);
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
235
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
236 gaim_debug(GAIM_DEBUG_INFO, "tray icon", "created\n");
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
237 }
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
238
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
239 static void wgaim_tray_destroy() {
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
240 systray_remove_nid();
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
241 DestroyWindow(systray_hwnd);
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
242 gaim_gtk_docklet_remove();
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
243 }
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
244
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
245 static struct docklet_ui_ops wgaim_tray_ops =
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
246 {
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
247 wgaim_tray_create,
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
248 wgaim_tray_destroy,
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
249 wgaim_tray_update_icon,
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
250 wgaim_tray_blank_icon,
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
251 wgaim_tray_set_tooltip,
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
252 NULL
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
253 };
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
254
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
255 /* Used by docklet's plugin load func */
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
256 void docklet_ui_init() {
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
257 gaim_gtk_docklet_set_ui_ops(&wgaim_tray_ops);
a8c2af13b96d [gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
258 }