3630
|
1 /*
|
|
2 * win32dep.c
|
|
3 *
|
|
4 * Author: Herman Bloggs <hermanator12002@yahoo.com>
|
|
5 * Date: June, 2002
|
|
6 * Description: Windows dependant code for Gaim
|
|
7 */
|
|
8 #include <windows.h>
|
|
9 #include <stdlib.h>
|
|
10 #include <stdio.h>
|
|
11 #include <glib.h>
|
|
12 #include "gaim.h"
|
|
13
|
|
14 #include "stdafx.h"
|
|
15 #include "resource.h"
|
|
16
|
|
17 /*
|
|
18 * DEFINES & MACROS
|
|
19 */
|
|
20 #define WM_TRAYMESSAGE WM_USER
|
|
21 #define GAIM_SYSTRAY_HINT "Gaim Instant Messenger"
|
|
22
|
|
23 /*
|
|
24 * LOCALS
|
|
25 */
|
|
26 static char install_dir[MAXPATHLEN];
|
|
27 static char lib_dir[MAXPATHLEN];
|
|
28 static char locale_dir[MAXPATHLEN];
|
|
29 static int bhide_icon;
|
|
30
|
|
31 /*
|
|
32 * GLOBALS
|
|
33 */
|
|
34 HINSTANCE g_hInstance = 0;
|
|
35
|
|
36 /*
|
|
37 * STATIC CODE
|
|
38 */
|
|
39
|
|
40 static void ShowNotifyIcon(HWND hWnd,BOOL bAdd)
|
|
41 {
|
|
42 NOTIFYICONDATA nid;
|
|
43 ZeroMemory(&nid,sizeof(nid));
|
|
44 nid.cbSize=sizeof(NOTIFYICONDATA);
|
|
45 nid.hWnd=hWnd;
|
|
46 nid.uID=0;
|
|
47 nid.uFlags=NIF_ICON | NIF_MESSAGE | NIF_TIP;
|
|
48 nid.uCallbackMessage=WM_TRAYMESSAGE;
|
|
49 nid.hIcon=LoadIcon(g_hInstance,MAKEINTRESOURCE(IDI_ICON2));
|
|
50 lstrcpy(nid.szTip,TEXT(GAIM_SYSTRAY_HINT));
|
|
51
|
|
52 if(bAdd)
|
|
53 Shell_NotifyIcon(NIM_ADD,&nid);
|
|
54 else
|
|
55 Shell_NotifyIcon(NIM_DELETE,&nid);
|
|
56 }
|
|
57
|
|
58 static GdkFilterReturn traymsg_filter_func( GdkXEvent *xevent, GdkEvent *event, gpointer data)
|
|
59 {
|
|
60 MSG *msg = (MSG*)xevent;
|
|
61
|
|
62 if( msg->lParam == WM_LBUTTONDBLCLK ) {
|
|
63 RestoreWndFromTray(msg->hwnd);
|
|
64 bhide_icon = TRUE;
|
|
65 return GDK_FILTER_REMOVE;
|
|
66 }
|
|
67
|
|
68 if( msg->lParam == WM_LBUTTONUP ) {
|
|
69 if(bhide_icon) {
|
|
70 ShowNotifyIcon(msg->hwnd,FALSE);
|
|
71 bhide_icon = FALSE;
|
|
72 }
|
|
73 }
|
|
74 return GDK_FILTER_REMOVE;
|
|
75 }
|
|
76
|
|
77 /*
|
|
78 * PUBLIC CODE
|
|
79 */
|
|
80
|
|
81 char* wgaim_install_dir(void) {
|
|
82 HMODULE hmod;
|
|
83 char* buf;
|
|
84
|
|
85 hmod = GetModuleHandle(NULL);
|
|
86 if( hmod == 0 ) {
|
|
87 buf = g_win32_error_message( GetLastError() );
|
|
88 debug_printf("GetModuleHandle error: %s\n", buf);
|
|
89 free(buf);
|
|
90 return NULL;
|
|
91 }
|
|
92 if(GetModuleFileName( hmod, (char*)&install_dir, MAXPATHLEN ) == 0) {
|
|
93 buf = g_win32_error_message( GetLastError() );
|
|
94 debug_printf("GetModuleFileName error: %s\n", buf);
|
|
95 free(buf);
|
|
96 return NULL;
|
|
97 }
|
|
98 buf = g_path_get_dirname( install_dir );
|
|
99 strcpy( (char*)&install_dir, buf );
|
|
100 free( buf );
|
|
101
|
|
102 return (char*)&install_dir;
|
|
103 }
|
|
104
|
|
105 char* wgaim_lib_dir(void) {
|
|
106 strcpy(lib_dir, wgaim_install_dir());
|
|
107 strcat(lib_dir, G_DIR_SEPARATOR_S "plugins");
|
|
108 return (char*)&lib_dir;
|
|
109 }
|
|
110
|
|
111 char* wgaim_locale_dir(void) {
|
|
112 strcpy(locale_dir, wgaim_install_dir());
|
|
113 strcat(locale_dir, G_DIR_SEPARATOR_S "locale");
|
|
114 return (char*)&locale_dir;
|
|
115 }
|
|
116
|
|
117 GdkFilterReturn wgaim_window_filter( GdkXEvent *xevent, GdkEvent *event, gpointer data)
|
|
118 {
|
|
119 MSG *msg = (MSG*)xevent;
|
|
120
|
|
121 switch( msg->message ) {
|
|
122 case WM_SYSCOMMAND:
|
|
123 if( msg->wParam == SC_MINIMIZE ) {
|
|
124 MinimizeWndToTray(msg->hwnd);
|
|
125 ShowNotifyIcon(msg->hwnd,TRUE);
|
|
126
|
|
127 SetWindowLong(msg->hwnd,DWL_MSGRESULT,0);
|
|
128 return GDK_FILTER_REMOVE;
|
|
129 }
|
|
130 break;
|
|
131 case WM_CLOSE:
|
|
132 MinimizeWndToTray(msg->hwnd);
|
|
133 ShowNotifyIcon(msg->hwnd,TRUE);
|
|
134 return GDK_FILTER_REMOVE;
|
|
135 }
|
|
136
|
|
137 return GDK_FILTER_CONTINUE;
|
|
138 }
|
|
139
|
|
140 void wgaim_init(void) {
|
|
141 /* Filter to catch systray events */
|
|
142 gdk_add_client_message_filter (GDK_POINTER_TO_ATOM (WM_TRAYMESSAGE),
|
|
143 traymsg_filter_func,
|
|
144 NULL);
|
|
145 }
|