Mon, 11 Aug 2003 18:54:38 +0000
[gaim-migrate @ 6933]
Warnings and gaim_debugs
|
6278
d0cd8645bf90
[gaim-migrate @ 6777]
Herman Bloggs <herman@bluedigits.com>
parents:
6261
diff
changeset
|
1 | /* |
| 6209 | 2 | * System tray icon (aka docklet) plugin for Gaim |
| 3 | * | |
| 4 | * Copyright (C) 2002-3 Robert McQueen <robot101@debian.org> | |
| 5 | * Copyright (C) 2003 Herman Bloggs <hermanator12002@yahoo.com> | |
| 6 | * Inspired by a similar plugin by: | |
| 7 | * John (J5) Palmieri <johnp@martianrock.com> | |
| 8 | * | |
| 9 | * This program is free software; you can redistribute it and/or | |
| 10 | * modify it under the terms of the GNU General Public License as | |
| 11 | * published by the Free Software Foundation; either version 2 of the | |
| 12 | * License, or (at your option) any later version. | |
| 13 | * | |
| 14 | * This program is distributed in the hope that it will be useful, but | |
| 15 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 17 | * General Public License for more details. | |
| 18 | * | |
| 19 | * You should have received a copy of the GNU General Public License | |
| 20 | * along with this program; if not, write to the Free Software | |
| 21 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA | |
| 22 | * 02111-1307, USA. | |
| 23 | */ | |
| 24 | ||
| 25 | #include <windows.h> | |
| 26 | #include <gdk/gdkwin32.h> | |
| 27 | #include <gdk/gdk.h> | |
| 28 | ||
| 29 | #include "internal.h" | |
| 30 | #include "gtkblist.h" | |
| 31 | #include "gtkprefs.h" | |
| 32 | #include "debug.h" | |
| 33 | ||
| 34 | #include "gaim.h" | |
| 35 | #include "ui.h" | |
| 36 | ||
| 37 | #include "resource.h" | |
| 38 | #include "MinimizeToTray.h" | |
| 39 | #include "docklet.h" | |
| 40 | ||
| 41 | /* | |
| 42 | * DEFINES, MACROS & DATA TYPES | |
| 43 | */ | |
|
6261
cd2f10dfd8b5
[gaim-migrate @ 6757]
Herman Bloggs <herman@bluedigits.com>
parents:
6260
diff
changeset
|
44 | #define GAIM_SYSTRAY_HINT _("Gaim") |
|
cd2f10dfd8b5
[gaim-migrate @ 6757]
Herman Bloggs <herman@bluedigits.com>
parents:
6260
diff
changeset
|
45 | #define GAIM_SYSTRAY_DISCONN_HINT _("Gaim - Signed off") |
|
cd2f10dfd8b5
[gaim-migrate @ 6757]
Herman Bloggs <herman@bluedigits.com>
parents:
6260
diff
changeset
|
46 | #define GAIM_SYSTRAY_AWAY_HINT _("Gaim - Away") |
| 6209 | 47 | #define WM_TRAYMESSAGE WM_USER /* User defined WM Message */ |
| 48 | ||
| 49 | /* | |
| 50 | * LOCALS | |
| 51 | */ | |
| 52 | static HWND systray_hwnd=0; | |
| 53 | static HICON sysicon_disconn=0; | |
| 54 | static HICON sysicon_conn=0; | |
| 55 | static HICON sysicon_away=0; | |
| 56 | static HICON sysicon_pend=0; | |
| 57 | static HICON sysicon_awypend=0; | |
| 58 | static NOTIFYICONDATA wgaim_nid; | |
| 59 | ||
| 60 | ||
| 61 | static LRESULT CALLBACK systray_mainmsg_handler(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) { | |
| 62 | static UINT taskbarRestartMsg; /* static here means value is kept across multiple calls to this func */ | |
| 63 | ||
| 64 | switch(msg) { | |
| 65 | case WM_CREATE: | |
|
6425
3e86c949c98a
[gaim-migrate @ 6933]
Herman Bloggs <herman@bluedigits.com>
parents:
6278
diff
changeset
|
66 | gaim_debug(GAIM_DEBUG_INFO, "tray icon", "WM_CREATE\n"); |
| 6209 | 67 | taskbarRestartMsg = RegisterWindowMessage("TaskbarCreated"); |
| 68 | break; | |
| 69 | ||
| 70 | case WM_TIMER: | |
|
6425
3e86c949c98a
[gaim-migrate @ 6933]
Herman Bloggs <herman@bluedigits.com>
parents:
6278
diff
changeset
|
71 | gaim_debug(GAIM_DEBUG_INFO, "tray icon", "WM_TIMER\n"); |
| 6209 | 72 | break; |
| 73 | ||
| 74 | case WM_DESTROY: | |
|
6425
3e86c949c98a
[gaim-migrate @ 6933]
Herman Bloggs <herman@bluedigits.com>
parents:
6278
diff
changeset
|
75 | gaim_debug(GAIM_DEBUG_INFO, "tray icon", "WM_DESTROY\n"); |
| 6209 | 76 | break; |
| 77 | ||
| 78 | case WM_TRAYMESSAGE: | |
| 79 | { | |
| 80 | int type = 0; | |
| 81 | ||
| 82 | /* We'll use Double Click - Single click over on linux */ | |
| 83 | if( lparam == WM_LBUTTONDBLCLK ) | |
| 84 | type = 1; | |
| 85 | else if( lparam == WM_MBUTTONUP ) | |
| 86 | type = 2; | |
| 87 | else if( lparam == WM_RBUTTONUP ) | |
| 88 | type = 3; | |
| 89 | else | |
| 90 | break; | |
| 91 | ||
| 92 | docklet_clicked(type); | |
| 93 | break; | |
| 94 | } | |
| 95 | default: | |
| 96 | if (msg == taskbarRestartMsg) { | |
| 97 | /* explorer crashed and left us hanging... | |
| 98 | This will put the systray icon back in it's place, when it restarts */ | |
| 99 | Shell_NotifyIcon(NIM_ADD,&wgaim_nid); | |
| 100 | } | |
| 101 | break; | |
| 102 | }/* end switch */ | |
| 103 | ||
| 104 | return DefWindowProc(hwnd, msg, wparam, lparam); | |
| 105 | } | |
| 106 | ||
| 107 | /* Create hidden window to process systray messages */ | |
| 108 | static HWND systray_create_hiddenwin() { | |
| 109 | WNDCLASSEX wcex; | |
| 110 | TCHAR wname[32]; | |
| 111 | ||
| 112 | strcpy(wname, "GaimWin"); | |
| 113 | ||
| 114 | wcex.cbSize = sizeof(WNDCLASSEX); | |
| 115 | ||
| 116 | wcex.style = 0; | |
| 117 | wcex.lpfnWndProc = (WNDPROC)systray_mainmsg_handler; | |
| 118 | wcex.cbClsExtra = 0; | |
| 119 | wcex.cbWndExtra = 0; | |
| 120 | wcex.hInstance = wgaim_hinstance(); | |
| 121 | wcex.hIcon = NULL; | |
| 122 | wcex.hCursor = NULL, | |
| 123 | wcex.hbrBackground = NULL; | |
| 124 | wcex.lpszMenuName = NULL; | |
| 125 | wcex.lpszClassName = wname; | |
| 126 | wcex.hIconSm = NULL; | |
| 127 | ||
| 128 | RegisterClassEx(&wcex); | |
| 129 | ||
| 130 | // Create the window | |
| 131 | return (CreateWindow(wname, "", 0, 0, 0, 0, 0, GetDesktopWindow(), NULL, wgaim_hinstance(), 0)); | |
| 132 | } | |
| 133 | ||
| 134 | static void systray_init_icon(HWND hWnd, HICON icon) { | |
| 135 | char* locenc=NULL; | |
| 136 | ||
| 137 | ZeroMemory(&wgaim_nid,sizeof(wgaim_nid)); | |
| 138 | wgaim_nid.cbSize=sizeof(NOTIFYICONDATA); | |
| 139 | wgaim_nid.hWnd=hWnd; | |
| 140 | wgaim_nid.uID=0; | |
| 141 | wgaim_nid.uFlags=NIF_ICON | NIF_MESSAGE | NIF_TIP; | |
| 142 | wgaim_nid.uCallbackMessage=WM_TRAYMESSAGE; | |
| 143 | wgaim_nid.hIcon=icon; | |
| 144 | locenc=g_locale_from_utf8(GAIM_SYSTRAY_DISCONN_HINT, -1, NULL, NULL, NULL); | |
| 145 | strcpy(wgaim_nid.szTip, locenc); | |
| 146 | g_free(locenc); | |
| 147 | Shell_NotifyIcon(NIM_ADD,&wgaim_nid); | |
| 148 | docklet_embedded(); | |
| 149 | } | |
| 150 | ||
| 151 | static void systray_change_icon(HICON icon, char* text) { | |
| 152 | char *locenc=NULL; | |
| 153 | wgaim_nid.hIcon = icon; | |
| 154 | locenc = g_locale_from_utf8(text, -1, NULL, NULL, NULL); | |
| 155 | lstrcpy(wgaim_nid.szTip, locenc); | |
| 156 | g_free(locenc); | |
| 157 | Shell_NotifyIcon(NIM_MODIFY,&wgaim_nid); | |
| 158 | } | |
| 159 | ||
| 160 | static void systray_remove_nid(void) { | |
| 161 | Shell_NotifyIcon(NIM_DELETE,&wgaim_nid); | |
| 162 | } | |
| 163 | ||
| 164 | static void wgaim_tray_update_icon(enum docklet_status icon) { | |
| 165 | switch (icon) { | |
| 166 | case offline: | |
| 167 | systray_change_icon(sysicon_disconn, GAIM_SYSTRAY_DISCONN_HINT); | |
| 168 | break; | |
| 169 | case offline_connecting: | |
| 170 | case online_connecting: | |
| 171 | break; | |
| 172 | case online: | |
| 173 | systray_change_icon(sysicon_conn, GAIM_SYSTRAY_HINT); | |
| 174 | break; | |
| 175 | case online_pending: | |
| 176 | systray_change_icon(sysicon_pend, GAIM_SYSTRAY_HINT); | |
| 177 | break; | |
| 178 | case away: | |
| 179 | systray_change_icon(sysicon_away, GAIM_SYSTRAY_AWAY_HINT); | |
| 180 | break; | |
| 181 | case away_pending: | |
| 182 | systray_change_icon(sysicon_awypend, GAIM_SYSTRAY_AWAY_HINT); | |
| 183 | break; | |
| 184 | } | |
| 185 | } | |
| 186 | ||
| 187 | static void wgaim_tray_create() { | |
| 188 | /* dummy window to process systray messages */ | |
| 189 | systray_hwnd = systray_create_hiddenwin(); | |
| 190 | ||
| 191 | /* Load icons, and init systray notify icon */ | |
| 192 | sysicon_disconn = (HICON)LoadImage(wgaim_hinstance(), MAKEINTRESOURCE(GAIM_OFFLINE_TRAY_ICON), IMAGE_ICON, 16, 16, 0); | |
| 193 | sysicon_conn = (HICON)LoadImage(wgaim_hinstance(), MAKEINTRESOURCE(GAIM_TRAY_ICON), IMAGE_ICON, 16, 16, 0); | |
| 194 | sysicon_away = (HICON)LoadImage(wgaim_hinstance(), MAKEINTRESOURCE(GAIM_AWAY_TRAY_ICON), IMAGE_ICON, 16, 16, 0); | |
| 195 | sysicon_pend = (HICON)LoadImage(wgaim_hinstance(), MAKEINTRESOURCE(GAIM_PEND_TRAY_ICON), IMAGE_ICON, 16, 16, 0); | |
| 196 | sysicon_awypend = (HICON)LoadImage(wgaim_hinstance(), MAKEINTRESOURCE(GAIM_AWAYPEND_TRAY_ICON), IMAGE_ICON, 16, 16, 0); | |
| 197 | ||
| 198 | /* Create icon in systray */ | |
| 199 | systray_init_icon(systray_hwnd, sysicon_disconn); | |
| 200 | gaim_debug(GAIM_DEBUG_INFO, "tray icon", "created\n"); | |
| 201 | } | |
| 202 | ||
| 203 | static void wgaim_tray_destroy() { | |
| 204 | systray_remove_nid(); | |
| 205 | DestroyWindow(systray_hwnd); | |
| 206 | docklet_remove(TRUE); | |
| 207 | } | |
| 208 | ||
| 209 | static struct docklet_ui_ops wgaim_tray_ops = | |
| 210 | { | |
| 211 | wgaim_tray_create, | |
| 212 | wgaim_tray_destroy, | |
| 213 | wgaim_tray_update_icon | |
| 214 | }; | |
| 215 | ||
| 216 | /* Used by docklet's plugin load func */ | |
| 217 | void docklet_ui_init() { | |
| 218 | docklet_set_ui_ops(&wgaim_tray_ops); | |
| 219 | } |