/[zanavi_public1]/navit/navit/gui/win32/win32_gui_notify.c
ZANavi

Contents of /navit/navit/gui/win32/win32_gui_notify.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2 - (show annotations) (download)
Fri Oct 28 21:19:04 2011 UTC (12 years, 5 months ago) by zoff99
File MIME type: text/plain
File size: 3186 byte(s)
import files
1 #include <windows.h>
2 #include <windowsx.h>
3 #include <commctrl.h>
4 #include <glib.h>
5 #include "win32_gui_notify.h"
6
7 struct window_data
8 {
9 HWND hwnd;
10 UINT message;
11 void(*func)(struct datawindow_priv *parent, int param1, int param2);
12 };
13
14 struct notify_priv
15 {
16 GList *window_list;
17 struct datawindow_priv *parent;
18
19 };
20
21
22 void win32_gui_notify(struct notify_priv* notify, HWND hwnd, int message_id, void(*func)(struct datawindow_priv *parent, int param1, int param2))
23 {
24 struct window_data *wnd_data = g_new( struct window_data,1);
25
26 wnd_data->hwnd = hwnd;
27 wnd_data->message = message_id;
28 wnd_data->func = func;
29
30 notify->window_list = g_list_append( notify->window_list, (gpointer) wnd_data );
31
32 }
33
34 struct notify_priv* win32_gui_notify_new(struct datawindow_priv *parent)
35 {
36 struct notify_priv* notify = g_new0(struct notify_priv,1);
37 notify->parent = parent;
38 return notify;
39 }
40
41 LRESULT CALLBACK message_handler(HWND hwnd, UINT win_message, WPARAM wParam, LPARAM lParam)
42 {
43 enum message_id message = INVALID;
44 int param1 = -1;
45 int param2 = -1;
46 HWND hwndDlg = hwnd;
47
48 switch (win_message)
49 {
50 case WM_CREATE:
51 {
52 message = WINDOW_CREATE;
53 }
54 break;
55 case WM_SIZE:
56 {
57 message = WINDOW_SIZE;
58 param1 = LOWORD(lParam);
59 param2 = HIWORD(lParam);
60 }
61 break;
62 case WM_DESTROY:
63 {
64 message = WINDOW_DESTROY;
65 }
66 break;
67 case WM_NOTIFY:
68 {
69 hwndDlg = (((LPNMHDR)lParam)->hwndFrom);
70 switch (((LPNMHDR)lParam)->code)
71 {
72 case NM_DBLCLK:
73 {
74 message = DBLCLICK;
75 #ifdef LPNMITEMACTIVATE
76 param1 = ((LPNMITEMACTIVATE)lParam)->iItem;
77 #endif
78 }
79 break;
80 case NM_CLICK:
81 message = CLICK;
82 break;
83 }
84 }
85 break;
86 case WM_COMMAND:
87 {
88 hwndDlg = (HWND)lParam;
89
90 switch (HIWORD(wParam))
91 {
92 case EN_CHANGE:
93 {
94 message = CHANGE;
95 }
96 break;
97 case BN_CLICKED:
98 {
99 message = BUTTON_CLICK;
100 }
101 break;
102 }
103 }
104 break;
105
106 default:
107 return DefWindowProc(hwnd, win_message, wParam, lParam);
108 }
109
110 struct notify_priv* notify_data = (struct notify_priv*)GetWindowLongPtr( hwnd , DWLP_USER );
111
112 if ( message != INVALID && notify_data && notify_data->window_list )
113 {
114
115 GList* current_element = g_list_first(notify_data->window_list);
116
117
118 struct window_data* wnd_data = NULL;
119 while (current_element != NULL)
120 {
121 wnd_data = current_element->data;
122
123 if ( (wnd_data->hwnd == hwndDlg || wnd_data->hwnd == NULL) && message == wnd_data->message)
124 {
125 wnd_data->func(notify_data->parent, param1, param2);
126 }
127
128 current_element = g_list_next(current_element);
129 }
130 }
131 return FALSE;
132 }

   
Visit the ZANavi Wiki