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

Contents of /navit/navit/gui/win32/win32_gui_destination.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: 13763 byte(s)
import files
1 #include <windows.h>
2 #include <windowsx.h>
3 #include <commctrl.h>
4 #include <glib.h>
5 #include "item.h"
6 #include "attr.h"
7 #include "navit.h"
8 #include "search.h"
9 #include "debug.h"
10 #include "util.h"
11 #include "win32_gui_notify.h"
12 #include "resources/resource.h"
13
14 static const TCHAR g_szDestinationClassName[] = TEXT("navit_gui_destinationwindow_class");
15
16 struct datawindow_priv
17 {
18 HWND hwnd;
19 HWND hwndLabel;
20 HWND hwndEdit;
21 HWND hwndList;
22 HWND hwndButtonPrev;
23 HWND hwndButtonNext;
24 enum attr_type currentSearchState;
25 struct search_list *sl;
26 struct navit *nav;
27 struct notify_priv *notifications;
28 };
29
30 static void setlayout(struct datawindow_priv *datawindow)
31 {
32 LVCOLUMN lvc;
33 lvc.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;
34
35 RECT winrect;
36 GetWindowRect (datawindow->hwndList, &winrect);
37
38 lvc.iSubItem = 1;
39 lvc.cx = (winrect.right - winrect.left) - 52 ;
40 lvc.fmt = LVCFMT_LEFT; // left-aligned column
41
42 switch (datawindow->currentSearchState)
43 {
44 case attr_country_name:
45 {
46 Edit_SetText(datawindow->hwndLabel, TEXT("Country"));
47 lvc.pszText = TEXT("Country");
48 }
49 break;
50 case attr_town_name:
51 {
52 Edit_SetText(datawindow->hwndLabel, TEXT("Postal or Town"));
53 lvc.pszText = TEXT("Town");
54 }
55 break;
56 case attr_street_name:
57 {
58 Edit_SetText(datawindow->hwndLabel, TEXT("Street"));
59 lvc.pszText = TEXT("Street");
60 }
61 break;
62 default:
63 break;
64
65 }
66
67 (void)ListView_SetColumn(datawindow->hwndList, 1, &lvc);
68
69 Edit_SetText(datawindow->hwndEdit, TEXT(""));
70 SetFocus(datawindow->hwndEdit);
71 }
72
73 static void notify_apply(struct datawindow_priv *datawindow, int index, int param2)
74 {
75 TCHAR txtBuffer[1024];
76 char search_string[1024];
77 struct attr search_attr;
78 struct search_list_result *res;
79
80
81 if ( index >= 0 )
82 {
83 ListView_GetItemText(datawindow->hwndList, index, 1, txtBuffer, 1024);
84
85 TCHAR_TO_UTF8(txtBuffer, search_string);
86
87 search_attr.type = datawindow->currentSearchState;
88 search_attr.u.str = search_string;
89
90 search_list_search(datawindow->sl, &search_attr, 0);
91 res=search_list_get_result(datawindow->sl);
92 }
93
94 switch (datawindow->currentSearchState)
95 {
96 case attr_country_name:
97 {
98 datawindow->currentSearchState = attr_town_name;
99 }
100 break;
101 case attr_town_name:
102 {
103 datawindow->currentSearchState = attr_street_name;
104 }
105 break;
106 case attr_street_name:
107 {
108 navit_set_destination(datawindow->nav, res->c, "Mein Test", 1);
109 DestroyWindow(datawindow->hwnd);
110 }
111 break;
112 default:
113 break;
114
115 }
116
117 setlayout(datawindow);
118
119 }
120
121 static void notify_back(struct datawindow_priv *datawindow, int param1, int param2)
122 {
123 switch (datawindow->currentSearchState)
124 {
125 case attr_country_name:
126 break;
127 case attr_town_name:
128 {
129 datawindow->currentSearchState = attr_country_name;
130 }
131 break;
132 case attr_street_name:
133 {
134 datawindow->currentSearchState = attr_town_name;
135 }
136 break;
137 default:
138 break;
139
140 }
141
142 setlayout(datawindow);
143 }
144
145 static void notify_textchange(struct datawindow_priv *datawindow, int param1, int param2)
146 {
147
148 struct attr search_attr;
149 struct search_list_result *res;
150 char search_string[1024];
151 TCHAR converted_iso2[32];
152
153
154 int lineLength = Edit_LineLength(datawindow->hwndEdit, 0);
155 TCHAR line[lineLength + 1];
156 (void)Edit_GetLine(datawindow->hwndEdit, 0, line, lineLength + 1);
157 line[lineLength] = 0;
158
159
160 (void)ListView_DeleteAllItems( datawindow->hwndList);
161
162 TCHAR_TO_UTF8(line, search_string);
163
164 search_attr.type = datawindow->currentSearchState;
165 search_attr.u.str = search_string;
166
167 if (lineLength<1)
168 return;
169
170 search_list_search(datawindow->sl, &search_attr, 1);
171
172
173 TCHAR *tcharBuffer = NULL;
174 int listIndex = 0;
175 LVITEM lvI;
176
177 lvI.mask = LVIF_TEXT | LVIF_PARAM | LVIF_STATE;
178 lvI.state = 0;
179 lvI.stateMask = 0;
180
181 while ((res=search_list_get_result(datawindow->sl)) && listIndex < 50)
182 {
183
184 switch (search_attr.type)
185 {
186 case attr_country_name:
187 tcharBuffer = newSysString(res->country->name);
188 break;
189 case attr_town_name:
190 tcharBuffer = newSysString(res->town->common.town_name);
191 break;
192 case attr_street_name:
193 if (res->street->name)
194 {
195 tcharBuffer = newSysString(res->street->name);
196 }
197 else
198 {
199 continue;
200 }
201 break;
202 default:
203 dbg(0, "Unhandled search type");
204 }
205
206 lvI.iItem = listIndex;
207 lvI.iImage = listIndex;
208 lvI.iSubItem = 0;
209 lvI.lParam = (LPARAM) res->country->iso2;
210 UTF8_TO_TCHAR(res->country->iso2, converted_iso2);
211 lvI.pszText = converted_iso2;//LPSTR_TEXTCALLBACK; // sends an LVN_GETDISP message.
212 (void)ListView_InsertItem(datawindow->hwndList, &lvI);
213 ListView_SetItemText(datawindow->hwndList, listIndex, 1, tcharBuffer);
214 g_free(tcharBuffer);
215 dbg(0,"%s\n", res->country->name);
216 listIndex++;
217 }
218 }
219
220 static void notify_destroy(struct datawindow_priv *datawindow, int param1, int param2)
221 {
222 if ( datawindow )
223 {
224 search_list_destroy(datawindow->sl);
225 g_free(datawindow);
226 }
227 }
228
229 static void notify_size(struct datawindow_priv *datawindow, int width, int height)
230 {
231 if (datawindow)
232 {
233 MoveWindow(datawindow->hwndLabel,
234 0, 0, // starting x- and y-coordinates
235 width, // width of client area
236 20, // height of client area
237 TRUE); // repaint window
238 MoveWindow(datawindow->hwndEdit,
239 0, 20, // starting x- and y-coordinates
240 width, // width of client area
241 20, // height of client area
242 TRUE); // repaint window
243 MoveWindow(datawindow->hwndList,
244 0, 40, // starting x- and y-coordinates
245 width, // width of client area
246 height - 60, // height of client area
247 TRUE); // repaint window
248 MoveWindow(datawindow->hwndButtonPrev,
249 0, height - 20, // starting x- and y-coordinates
250 width/2, // width of client area
251 20, // height of client area
252 TRUE); // repaint window
253 MoveWindow(datawindow->hwndButtonNext,
254 width/2, height - 20, // starting x- and y-coordinates
255 width/2, // width of client area
256 20, // height of client area
257 TRUE); // repaint window
258
259 setlayout(datawindow);
260
261 }
262 }
263
264 static BOOL init_lv_columns(HWND hWndListView)
265 {
266
267 // struct LVCOLUMN lvc = {LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM,
268 // LVCFMT_LEFT, 100, szText[iCol], 0, iCol, 0, 0 };
269
270 TCHAR szText[][8] = {TEXT("Iso"),TEXT("Country")}; // temporary buffer
271 LVCOLUMN lvc;
272 int iCol;
273
274 lvc.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;
275
276 for (iCol = 0; iCol < 2; iCol++)
277 {
278 lvc.iSubItem = iCol;
279 lvc.pszText = szText[iCol];
280 lvc.cx = 50; // width of column in pixels
281
282 if ( iCol < 2 )
283 lvc.fmt = LVCFMT_LEFT; // left-aligned column
284 else
285 lvc.fmt = LVCFMT_RIGHT; // right-aligned column
286
287 if (ListView_InsertColumn(hWndListView, iCol, &lvc) == -1)
288 return FALSE;
289 }
290 return TRUE;
291 }
292
293 BOOL register_destination_window()
294 {
295 WNDCLASS wc;
296
297 wc.style = 0;
298 wc.lpfnWndProc = message_handler;
299 wc.cbClsExtra = 0;
300 wc.cbWndExtra = 32;
301 wc.hInstance = NULL;
302 wc.hCursor = LoadCursor(NULL, IDC_ARROW);
303 wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
304 wc.lpszMenuName = NULL;
305 wc.lpszClassName = g_szDestinationClassName;
306 wc.hIcon = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_NAVIT));
307
308 if (!RegisterClass(&wc))
309 {
310 dbg(0, "Window Registration Failed!\n");
311 return FALSE;
312 }
313 return TRUE;
314 }
315
316 HANDLE create_destination_window( struct navit *nav )
317 {
318
319
320 struct datawindow_priv *this_;
321
322 this_=g_new0(struct datawindow_priv, 1);
323 this_->nav = nav;
324 this_->currentSearchState = attr_country_name;
325 this_->sl=search_list_new(navit_get_mapset(this_->nav));
326
327 this_->hwnd = CreateWindowEx(
328 WS_EX_CLIENTEDGE,
329 g_szDestinationClassName,
330 TEXT("Destination Input"),
331 #if defined(__CEGCC__)
332 WS_SYSMENU | WS_CLIPCHILDREN,
333 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
334 #else
335 WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN,
336 CW_USEDEFAULT, CW_USEDEFAULT, 640, 480,
337 #endif
338 NULL, NULL, NULL, NULL);
339
340 if (this_->hwnd == NULL)
341 {
342 dbg(0, "Window Creation Failed!\n");
343 return 0;
344 }
345
346 this_->notifications = win32_gui_notify_new(this_);
347 SetWindowLongPtr( this_->hwnd , DWLP_USER, (LONG_PTR) this_->notifications );
348
349 this_->hwndLabel = CreateWindow(WC_STATIC, // predefined class
350 TEXT("Country"), // no window title
351 WS_CHILD | WS_VISIBLE | ES_LEFT , //| WS_VSCROLL | ES_MULTILINE | ES_AUTOVSCROLL
352 0, 0, 0, 0, // set size in WM_SIZE message
353 this_->hwnd, // parent window
354 NULL,//(HMENU) ID_EDITCHILD, // edit control ID
355 (HINSTANCE) GetWindowLong(this_->hwnd, GWL_HINSTANCE),
356 NULL); // pointer not needed
357
358 this_->hwndEdit = CreateWindow(WC_EDIT, // predefined class
359 NULL, // no window title
360 WS_CHILD | WS_VISIBLE | ES_LEFT | WS_BORDER , //| WS_VSCROLL | ES_MULTILINE | ES_AUTOVSCROLL
361 0, 0, 0, 0, // set size in WM_SIZE message
362 this_->hwnd, // parent window
363 NULL,//(HMENU) ID_EDITCHILD, // edit control ID
364 (HINSTANCE) GetWindowLong(this_->hwnd, GWL_HINSTANCE),
365 NULL); // pointer not needed
366
367 this_->hwndList = CreateWindow(WC_LISTVIEW, // predefined class
368 NULL, // no window title
369 WS_CHILD | WS_VISIBLE | ES_LEFT | WS_BORDER | LVS_REPORT , //| WS_VSCROLL | ES_MULTILINE | ES_AUTOVSCROLL
370 0, 0, 0, 0, // set size in WM_SIZE message
371 this_->hwnd, // parent window
372 NULL,//(HMENU) ID_EDITCHILD, // edit control ID
373 (HINSTANCE) GetWindowLong(this_->hwnd, GWL_HINSTANCE),
374 NULL); // pointer not needed
375
376 this_->hwndButtonPrev = CreateWindow(WC_BUTTON, // predefined class
377 TEXT("<<"), // no window title
378 WS_CHILD | WS_VISIBLE | ES_LEFT | WS_BORDER | LVS_REPORT , //| WS_VSCROLL | ES_MULTILINE | ES_AUTOVSCROLL
379 0, 0, 0, 0, // set size in WM_SIZE message
380 this_->hwnd, // parent window
381 NULL,//(HMENU) ID_EDITCHILD, // edit control ID
382 (HINSTANCE) GetWindowLong(this_->hwnd, GWL_HINSTANCE),
383 NULL); // pointer not needed
384 this_->hwndButtonNext = CreateWindow(WC_BUTTON, // predefined class
385 TEXT(">>"), // no window title
386 WS_CHILD | WS_VISIBLE | ES_LEFT | WS_BORDER | LVS_REPORT , //| WS_VSCROLL | ES_MULTILINE | ES_AUTOVSCROLL
387 0, 0, 0, 0, // set size in WM_SIZE message
388 this_->hwnd, // parent window
389 NULL,//(HMENU) ID_EDITCHILD, // edit control ID
390 (HINSTANCE) GetWindowLong(this_->hwnd, GWL_HINSTANCE),
391 NULL); // pointer not needed
392 #ifdef LVS_EX_FULLROWSELECT
393 (void)ListView_SetExtendedListViewStyle(this_->hwndList,LVS_EX_FULLROWSELECT);
394 #endif
395
396
397 win32_gui_notify( this_->notifications, this_->hwndEdit, CHANGE, notify_textchange);
398 win32_gui_notify( this_->notifications, NULL, WINDOW_SIZE, notify_size);
399 win32_gui_notify( this_->notifications, this_->hwndList, DBLCLICK, notify_apply);
400 win32_gui_notify( this_->notifications, this_->hwnd, WINDOW_DESTROY, notify_destroy);
401
402 win32_gui_notify( this_->notifications, this_->hwndButtonNext, BUTTON_CLICK, notify_apply);
403 win32_gui_notify( this_->notifications, this_->hwndButtonPrev, BUTTON_CLICK, notify_back);
404
405 init_lv_columns(this_->hwndList);
406 SetFocus(this_->hwndEdit);
407 ShowWindow(this_->hwnd, TRUE);
408 UpdateWindow(this_->hwnd);
409
410 return this_->hwnd;
411 }
412

   
Visit the ZANavi Wiki