1 |
// Renegade Map Selector |
2 |
// |
3 |
// Douglas Thrift |
4 |
// |
5 |
// RenegadeMapSelector.cpp |
6 |
|
7 |
#include "RenegadeMapSelector.h" |
8 |
#include "RenegadeConfig.h" |
9 |
|
10 |
#ifdef _WIN32 |
11 |
#include <io.h> |
12 |
#include <fcntl.h> |
13 |
#include "resource.h" |
14 |
#else |
15 |
#include "gtk/gtk.h" |
16 |
#endif |
17 |
|
18 |
bool debug = false; |
19 |
string program; |
20 |
RenegadeConfig* config; |
21 |
|
22 |
#ifndef _WIN32 |
23 |
inline string fix(const string& ansi) { return ansi; } |
24 |
inline void munge(void) { debug = true; } |
25 |
|
26 |
void message(const string& text, const string& title, GtkMessageType type); |
27 |
#else |
28 |
inline string fix(const wstring& wide) |
29 |
{ |
30 |
char* buffer = new char[wide.length() + 1]; |
31 |
|
32 |
WideCharToMultiByte(CP_ACP, 0, wide.c_str(), -1, buffer, wide.length() + 1, |
33 |
NULL, NULL); |
34 |
|
35 |
string ansi = buffer; |
36 |
delete [] buffer; |
37 |
|
38 |
return ansi; |
39 |
} |
40 |
|
41 |
inline void munge(void) |
42 |
{ |
43 |
if (debug) return; |
44 |
|
45 |
AllocConsole(); |
46 |
SetConsoleTitle("Renegade Map Selector"); |
47 |
|
48 |
int hin = _open_osfhandle(long(GetStdHandle(STD_INPUT_HANDLE)), _O_TEXT); |
49 |
int hout = _open_osfhandle(long(GetStdHandle(STD_OUTPUT_HANDLE)), _O_TEXT); |
50 |
int herr = _open_osfhandle(long(GetStdHandle(STD_ERROR_HANDLE)), _O_TEXT); |
51 |
|
52 |
FILE* fin = _fdopen(hin, "r"); |
53 |
FILE* fout = _fdopen(hout, "w"); |
54 |
FILE* ferr = _fdopen(herr, "w"); |
55 |
|
56 |
*stdin = *fin; |
57 |
*stdout = *fout; |
58 |
*stderr = *ferr; |
59 |
|
60 |
setvbuf(stdin, NULL, _IONBF, 0); |
61 |
setvbuf(stdout, NULL, _IONBF, 0); |
62 |
setvbuf(stderr, NULL, _IONBF, 0); |
63 |
|
64 |
cin.sync_with_stdio(); |
65 |
cout.sync_with_stdio(); |
66 |
cerr.sync_with_stdio(); |
67 |
|
68 |
debug = true; |
69 |
} |
70 |
#endif |
71 |
|
72 |
#ifdef _WIN32 |
73 |
int CALLBACK selector(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam); |
74 |
|
75 |
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR |
76 |
lpCmdLine, int nShowCmd) |
77 |
{ |
78 |
int argc; |
79 |
unsigned short** argv = CommandLineToArgvW(GetCommandLineW(), &argc); |
80 |
#else |
81 |
void selector(void); |
82 |
|
83 |
int main(int argc, char* argv[]) |
84 |
{ |
85 |
gtk_init(&argc, &argv); |
86 |
#endif |
87 |
|
88 |
string error; |
89 |
string file = "svrcfg_cnc.ini"; |
90 |
|
91 |
program = fix(argv[0]); |
92 |
|
93 |
for (int index = 1; index < argc; index++) |
94 |
{ |
95 |
string arg = fix(argv[index]); |
96 |
|
97 |
if (arg == "-D") |
98 |
{ |
99 |
munge(); |
100 |
} |
101 |
else if (arg == "-file") |
102 |
{ |
103 |
if (++index < argc) |
104 |
{ |
105 |
file = fix(argv[index]); |
106 |
} |
107 |
else |
108 |
{ |
109 |
error = "The argument -file must be followed by a filename."; |
110 |
|
111 |
#ifdef _WIN32 |
112 |
MessageBox(NULL, error.c_str(), "Bad Arguments", MB_ICONERROR); |
113 |
#else |
114 |
message(error, "Bad Arguments", GTK_MESSAGE_ERROR); |
115 |
#endif |
116 |
return 1; |
117 |
} |
118 |
} |
119 |
} |
120 |
|
121 |
#ifdef _WIN32 |
122 |
GlobalFree(argv); |
123 |
#endif |
124 |
|
125 |
if (debug) cerr << "file = " << file << "\n"; |
126 |
|
127 |
config = new RenegadeConfig(file); |
128 |
if (!config->load()) |
129 |
{ |
130 |
error = "Could not open " + file + "."; |
131 |
|
132 |
#ifdef _WIN32 |
133 |
MessageBox(NULL, error.c_str(), "Bad File", MB_ICONERROR); |
134 |
#else |
135 |
message(error, "Bad File", GTK_MESSAGE_ERROR); |
136 |
#endif |
137 |
return 1; |
138 |
} |
139 |
|
140 |
#ifdef _WIN32 |
141 |
DialogBox(hInstance, MAKEINTRESOURCE(IDD_MAP_SELECTOR), NULL, selector); |
142 |
#else |
143 |
selector(); |
144 |
#endif |
145 |
|
146 |
delete config; |
147 |
|
148 |
#ifdef _WIN32 |
149 |
if (debug) |
150 |
{ |
151 |
cout << "Press enter key to exit . . ."; |
152 |
cin.get(); |
153 |
} |
154 |
#endif |
155 |
|
156 |
return 0; |
157 |
} |
158 |
|
159 |
#ifdef _WIN32 |
160 |
int CALLBACK selector(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) |
161 |
{ |
162 |
switch (uMsg) |
163 |
{ |
164 |
case WM_INITDIALOG: |
165 |
{ |
166 |
char* directory = new char[MAX_PATH + 1]; |
167 |
GetCurrentDirectory(MAX_PATH + 1, directory); |
168 |
if (debug) cerr << "directory = " << directory << "\n"; |
169 |
|
170 |
char* data = new char[MAX_PATH + 1]; |
171 |
sprintf(data, "%s\\data\\*.mix", directory); |
172 |
delete [] directory; |
173 |
if (debug) cerr << "data = " << data << "\n"; |
174 |
|
175 |
DlgDirList(hwndDlg, data, IDC_AVAILABLE, 0, DDL_ARCHIVE); |
176 |
SetCurrentDirectory(".."); |
177 |
|
178 |
delete [] data; |
179 |
} |
180 |
{ |
181 |
vector<string> maps = config->getMaps(); |
182 |
|
183 |
for (unsigned index = 0; index < maps.size(); index++) |
184 |
{ |
185 |
SendMessage(GetDlgItem(hwndDlg, IDC_SELECTED), LB_ADDSTRING, 0, |
186 |
long(maps[index].c_str())); |
187 |
} |
188 |
} |
189 |
break; |
190 |
case WM_COMMAND: |
191 |
switch (LOWORD(wParam)) |
192 |
{ |
193 |
case IDOK: |
194 |
if (GetListBoxInfo(GetDlgItem(hwndDlg, IDC_SELECTED)) == 0) |
195 |
{ |
196 |
MessageBox(hwndDlg, "You need at least one map.", "No Maps", |
197 |
MB_ICONEXCLAMATION); |
198 |
|
199 |
return false; |
200 |
} |
201 |
else |
202 |
{ |
203 |
vector<string> maps; |
204 |
|
205 |
for (unsigned index = 0; index < GetListBoxInfo(GetDlgItem( |
206 |
hwndDlg, IDC_SELECTED)); index++) |
207 |
{ |
208 |
char* name = new char[SendMessage(GetDlgItem(hwndDlg, |
209 |
IDC_SELECTED), LB_GETTEXTLEN, index, 0) + 1]; |
210 |
|
211 |
SendMessage(GetDlgItem(hwndDlg, IDC_SELECTED), LB_GETTEXT, |
212 |
index, long(name)); |
213 |
maps.push_back(name); |
214 |
|
215 |
delete [] name; |
216 |
} |
217 |
|
218 |
config->setMaps(maps); |
219 |
} |
220 |
config->save(); |
221 |
case IDCANCEL: |
222 |
EndDialog(hwndDlg, wParam); |
223 |
return true; |
224 |
case IDC_ADD_MAP: |
225 |
{ |
226 |
unsigned count = SendMessage(GetDlgItem(hwndDlg, |
227 |
IDC_AVAILABLE), LB_GETSELCOUNT, 0, 0); |
228 |
unsigned* additions = new unsigned[count]; |
229 |
|
230 |
SendMessage(GetDlgItem(hwndDlg, IDC_AVAILABLE), LB_GETSELITEMS, |
231 |
count, long(additions)); |
232 |
|
233 |
if (debug) cerr << "additions = {\n"; |
234 |
for (unsigned index = 0; index < count; index++) |
235 |
{ |
236 |
if (debug) cerr << " [" << index << "] = " << |
237 |
additions[index] << "\n"; |
238 |
|
239 |
char* name = new char[SendMessage(GetDlgItem(hwndDlg, |
240 |
IDC_AVAILABLE), LB_GETTEXTLEN, additions[index], 0) + 1 |
241 |
]; |
242 |
|
243 |
SendMessage(GetDlgItem(hwndDlg, IDC_AVAILABLE), LB_GETTEXT, |
244 |
additions[index], long(name)); |
245 |
SendMessage(GetDlgItem(hwndDlg, IDC_SELECTED), |
246 |
LB_ADDSTRING, 0, long(name)); |
247 |
|
248 |
delete [] name; |
249 |
} |
250 |
if (debug) cerr << "}\n"; |
251 |
|
252 |
delete [] additions; |
253 |
|
254 |
SendMessage(GetDlgItem(hwndDlg, IDC_AVAILABLE), LB_SETSEL, |
255 |
false, -1); |
256 |
EnableWindow(GetDlgItem(hwndDlg, IDC_ADD_MAP), false); |
257 |
} |
258 |
break; |
259 |
case IDC_REMOVE_MAP: |
260 |
{ |
261 |
unsigned count = SendMessage(GetDlgItem(hwndDlg, IDC_SELECTED), |
262 |
LB_GETSELCOUNT, 0, 0); |
263 |
unsigned* removals = new unsigned[count]; |
264 |
|
265 |
SendMessage(GetDlgItem(hwndDlg, IDC_SELECTED), LB_GETSELITEMS, |
266 |
count, long(removals)); |
267 |
|
268 |
if (debug) cerr << "removals = {\n"; |
269 |
for (unsigned index = count; index > 0; index--) |
270 |
{ |
271 |
if (debug) cerr << " [" << index - 1 << "] = " << |
272 |
removals[index - 1] << "\n"; |
273 |
|
274 |
SendMessage(GetDlgItem(hwndDlg, IDC_SELECTED), |
275 |
LB_DELETESTRING, removals[index - 1], 0); |
276 |
} |
277 |
if (debug) cerr << "}\n"; |
278 |
|
279 |
delete [] removals; |
280 |
|
281 |
EnableWindow(GetDlgItem(hwndDlg, IDC_REMOVE_MAP), false); |
282 |
EnableWindow(GetDlgItem(hwndDlg, IDC_UP_MAP), false); |
283 |
EnableWindow(GetDlgItem(hwndDlg, IDC_DOWN_MAP), false); |
284 |
} |
285 |
break; |
286 |
case IDC_UP_MAP: |
287 |
{ |
288 |
unsigned count = SendMessage(GetDlgItem(hwndDlg, IDC_SELECTED), |
289 |
LB_GETSELCOUNT, 0, 0); |
290 |
unsigned* ups = new unsigned[count]; |
291 |
|
292 |
SendMessage(GetDlgItem(hwndDlg, IDC_SELECTED), LB_GETSELITEMS, |
293 |
count, long(ups)); |
294 |
|
295 |
unsigned insert = ups[0] - 1; |
296 |
|
297 |
if (debug) cerr << "ups = {\n"; |
298 |
for (unsigned index = 0; index < count; index++) |
299 |
{ |
300 |
if (debug) cerr << " [" << index << "] = " << ups[index] |
301 |
<< "\n"; |
302 |
|
303 |
char* up = new char[SendMessage(GetDlgItem(hwndDlg, |
304 |
IDC_SELECTED), LB_GETTEXTLEN, ups[index], 0) + 1]; |
305 |
|
306 |
SendMessage(GetDlgItem(hwndDlg, IDC_SELECTED), LB_GETTEXT, |
307 |
ups[index], long(up)); |
308 |
SendMessage(GetDlgItem(hwndDlg, IDC_SELECTED), |
309 |
LB_DELETESTRING, ups[index], 0); |
310 |
SendMessage(GetDlgItem(hwndDlg, IDC_SELECTED), |
311 |
LB_INSERTSTRING, insert, long(up)); |
312 |
SendMessage(GetDlgItem(hwndDlg, IDC_SELECTED), LB_SETSEL, |
313 |
true, insert++); |
314 |
} |
315 |
if (debug) cerr << "}\n"; |
316 |
|
317 |
delete [] ups; |
318 |
|
319 |
if (SendMessage(GetDlgItem(hwndDlg, IDC_SELECTED), |
320 |
LB_GETSEL, 0, 0) == 0) |
321 |
{ |
322 |
EnableWindow(GetDlgItem(hwndDlg, IDC_UP_MAP), true); |
323 |
} |
324 |
else |
325 |
{ |
326 |
EnableWindow(GetDlgItem(hwndDlg, IDC_UP_MAP), false); |
327 |
} |
328 |
|
329 |
if (SendMessage(GetDlgItem(hwndDlg, IDC_SELECTED), |
330 |
LB_GETSEL, SendMessage(GetDlgItem(hwndDlg, IDC_SELECTED |
331 |
), LB_GETCOUNT, 0, 0) - 1, 0) == 0) |
332 |
{ |
333 |
EnableWindow(GetDlgItem(hwndDlg, IDC_DOWN_MAP), true); |
334 |
} |
335 |
} |
336 |
break; |
337 |
case IDC_DOWN_MAP: |
338 |
{ |
339 |
unsigned count = SendMessage(GetDlgItem(hwndDlg, IDC_SELECTED), |
340 |
LB_GETSELCOUNT, 0, 0); |
341 |
unsigned* downs = new unsigned[count]; |
342 |
|
343 |
SendMessage(GetDlgItem(hwndDlg, IDC_SELECTED), LB_GETSELITEMS, |
344 |
count, long(downs)); |
345 |
|
346 |
unsigned insert = downs[count - 1] + 1; |
347 |
|
348 |
if (debug) cerr << "downs = {\n"; |
349 |
for (unsigned index = count; index > 0; index--) |
350 |
{ |
351 |
if (debug) cerr << " [" << index << "] = " << downs[index |
352 |
- 1] << "\n"; |
353 |
|
354 |
char* down = new char[SendMessage(GetDlgItem(hwndDlg, |
355 |
IDC_SELECTED), LB_GETTEXTLEN, downs[index - 1], 0) + |
356 |
1]; |
357 |
|
358 |
SendMessage(GetDlgItem(hwndDlg, IDC_SELECTED), LB_GETTEXT, |
359 |
downs[index - 1], long(down)); |
360 |
SendMessage(GetDlgItem(hwndDlg, IDC_SELECTED), |
361 |
LB_DELETESTRING, downs[index - 1], 0); |
362 |
SendMessage(GetDlgItem(hwndDlg, IDC_SELECTED), |
363 |
LB_INSERTSTRING, insert, long(down)); |
364 |
SendMessage(GetDlgItem(hwndDlg, IDC_SELECTED), LB_SETSEL, |
365 |
true, insert--); |
366 |
} |
367 |
if (debug) cerr << "}\n"; |
368 |
|
369 |
delete [] downs; |
370 |
|
371 |
if (SendMessage(GetDlgItem(hwndDlg, IDC_SELECTED), |
372 |
LB_GETSEL, 0, 0) == 0) |
373 |
{ |
374 |
EnableWindow(GetDlgItem(hwndDlg, IDC_UP_MAP), true); |
375 |
} |
376 |
|
377 |
if (SendMessage(GetDlgItem(hwndDlg, IDC_SELECTED), |
378 |
LB_GETSEL, SendMessage(GetDlgItem(hwndDlg, IDC_SELECTED |
379 |
), LB_GETCOUNT, 0, 0) - 1, 0) == 0) |
380 |
{ |
381 |
EnableWindow(GetDlgItem(hwndDlg, IDC_DOWN_MAP), true); |
382 |
} |
383 |
else |
384 |
{ |
385 |
EnableWindow(GetDlgItem(hwndDlg, IDC_DOWN_MAP), false); |
386 |
} |
387 |
} |
388 |
break; |
389 |
case IDC_AVAILABLE: |
390 |
switch (HIWORD(wParam)) |
391 |
{ |
392 |
case LBN_SELCHANGE: |
393 |
if (SendMessage(GetDlgItem(hwndDlg, IDC_AVAILABLE), |
394 |
LB_GETSELCOUNT, 0, 0) > 0) |
395 |
{ |
396 |
EnableWindow(GetDlgItem(hwndDlg, IDC_ADD_MAP), true); |
397 |
} |
398 |
else |
399 |
{ |
400 |
EnableWindow(GetDlgItem(hwndDlg, IDC_ADD_MAP), false); |
401 |
} |
402 |
break; |
403 |
} |
404 |
break; |
405 |
case IDC_SELECTED: |
406 |
switch (HIWORD(wParam)) |
407 |
{ |
408 |
case LBN_SELCHANGE: |
409 |
if (SendMessage(GetDlgItem(hwndDlg, IDC_SELECTED), |
410 |
LB_GETSELCOUNT, 0, 0) > 0) |
411 |
{ |
412 |
EnableWindow(GetDlgItem(hwndDlg, IDC_REMOVE_MAP), true); |
413 |
|
414 |
if (SendMessage(GetDlgItem(hwndDlg, IDC_SELECTED), |
415 |
LB_GETSEL, 0, 0) == 0) |
416 |
{ |
417 |
EnableWindow(GetDlgItem(hwndDlg, IDC_UP_MAP), true); |
418 |
} |
419 |
else |
420 |
{ |
421 |
EnableWindow(GetDlgItem(hwndDlg, IDC_UP_MAP), false); |
422 |
} |
423 |
|
424 |
if (SendMessage(GetDlgItem(hwndDlg, IDC_SELECTED), |
425 |
LB_GETSEL, SendMessage(GetDlgItem(hwndDlg, IDC_SELECTED |
426 |
), LB_GETCOUNT, 0, 0) - 1, 0) == 0) |
427 |
{ |
428 |
EnableWindow(GetDlgItem(hwndDlg, IDC_DOWN_MAP), true); |
429 |
} |
430 |
else |
431 |
{ |
432 |
EnableWindow(GetDlgItem(hwndDlg, IDC_DOWN_MAP), false); |
433 |
} |
434 |
} |
435 |
else |
436 |
{ |
437 |
EnableWindow(GetDlgItem(hwndDlg, IDC_REMOVE_MAP), false); |
438 |
EnableWindow(GetDlgItem(hwndDlg, IDC_UP_MAP), false); |
439 |
EnableWindow(GetDlgItem(hwndDlg, IDC_DOWN_MAP), false); |
440 |
} |
441 |
break; |
442 |
} |
443 |
break; |
444 |
} |
445 |
break; |
446 |
} |
447 |
|
448 |
return false; |
449 |
} |
450 |
#else |
451 |
static void destruct(GtkWidget* widget, gpointer data) |
452 |
{ |
453 |
gtk_main_quit(); |
454 |
} |
455 |
|
456 |
static void done(GtkWidget* widget, gpointer data) |
457 |
{ |
458 |
if (true) |
459 |
{ |
460 |
message("You need at least one map.", "No Maps", |
461 |
GTK_MESSAGE_WARNING); |
462 |
} |
463 |
else |
464 |
{ |
465 |
// |
466 |
|
467 |
config->save(); |
468 |
|
469 |
gtk_main_quit(); |
470 |
} |
471 |
} |
472 |
|
473 |
static void mapAdd(GtkWidget* widget, gpointer data) |
474 |
{ |
475 |
cout << "STUB: add\n\a" << flush; |
476 |
} |
477 |
|
478 |
static void mapRemove(GtkWidget* widget, gpointer data) |
479 |
{ |
480 |
cout << "STUB: remove\n\a" << flush; |
481 |
} |
482 |
|
483 |
static void mapUp(GtkWidget* widget, gpointer data) |
484 |
{ |
485 |
cout << "STUB: up\n\a" << flush; |
486 |
} |
487 |
|
488 |
static void mapDown(GtkWidget* widget, gpointer data) |
489 |
{ |
490 |
cout << "STUB: down\n\a" << flush; |
491 |
} |
492 |
|
493 |
void selector(void) |
494 |
{ |
495 |
GtkWidget* window = gtk_window_new(GTK_WINDOW_TOPLEVEL); |
496 |
|
497 |
gtk_window_set_title(GTK_WINDOW(window), "Renegade Map Selector"); |
498 |
gtk_window_set_resizable(GTK_WINDOW(window), false); |
499 |
g_signal_connect(G_OBJECT(window), "delete_event", G_CALLBACK(destruct), |
500 |
NULL); |
501 |
|
502 |
GtkWidget* vertical = gtk_vbox_new(false, 0); |
503 |
GtkWidget* horizontal = gtk_hbox_new(false, 9); |
504 |
GtkWidget* left = gtk_frame_new("Available Maps"); |
505 |
|
506 |
gtk_frame_set_label_align(GTK_FRAME(left), 0.5, 0.5); |
507 |
gtk_container_set_border_width(GTK_CONTAINER(left), 6); |
508 |
|
509 |
GtkWidget* center = gtk_vbox_new(true, 0); |
510 |
GtkWidget* top = gtk_vbutton_box_new(); |
511 |
|
512 |
gtk_button_box_set_layout(GTK_BUTTON_BOX(top), GTK_BUTTONBOX_START); |
513 |
gtk_box_set_spacing(GTK_BOX(top), 9); |
514 |
gtk_container_set_border_width(GTK_CONTAINER(top), 6); |
515 |
|
516 |
GtkWidget* add = gtk_button_new_with_mnemonic("_Add"); |
517 |
|
518 |
g_signal_connect(G_OBJECT(add), "clicked", G_CALLBACK(mapAdd), NULL); |
519 |
gtk_widget_set_sensitive(add, false); |
520 |
|
521 |
GtkWidget* remove = gtk_button_new_with_mnemonic("_Remove"); |
522 |
|
523 |
g_signal_connect(G_OBJECT(remove), "clicked", G_CALLBACK(mapRemove), NULL); |
524 |
gtk_widget_set_sensitive(remove, false); |
525 |
|
526 |
GtkWidget* middle = gtk_vbutton_box_new(); |
527 |
|
528 |
gtk_button_box_set_layout(GTK_BUTTON_BOX(middle), GTK_BUTTONBOX_END); |
529 |
gtk_box_set_spacing(GTK_BOX(middle), 9); |
530 |
gtk_container_set_border_width(GTK_CONTAINER(middle), 6); |
531 |
|
532 |
GtkWidget* up = gtk_button_new_with_mnemonic("_Up"); |
533 |
|
534 |
g_signal_connect(G_OBJECT(up), "clicked", G_CALLBACK(mapUp), NULL); |
535 |
gtk_widget_set_sensitive(up, false); |
536 |
|
537 |
GtkWidget* down = gtk_button_new_with_mnemonic("_Down"); |
538 |
|
539 |
g_signal_connect(G_OBJECT(down), "clicked", G_CALLBACK(mapDown), NULL); |
540 |
gtk_widget_set_sensitive(down, false); |
541 |
|
542 |
GtkWidget* right = gtk_frame_new("Selected Maps"); |
543 |
|
544 |
gtk_frame_set_label_align(GTK_FRAME(right), 0.5, 0.5); |
545 |
gtk_container_set_border_width(GTK_CONTAINER(right), 6); |
546 |
|
547 |
GtkWidget* separator = gtk_hseparator_new(); |
548 |
GtkWidget* bottom = gtk_hbutton_box_new(); |
549 |
|
550 |
gtk_button_box_set_layout(GTK_BUTTON_BOX(bottom), GTK_BUTTONBOX_END); |
551 |
gtk_box_set_spacing(GTK_BOX(bottom), 9); |
552 |
gtk_container_set_border_width(GTK_CONTAINER(bottom), 6); |
553 |
|
554 |
GtkWidget* ok = gtk_button_new_from_stock(GTK_STOCK_OK); |
555 |
|
556 |
g_signal_connect(G_OBJECT(ok), "clicked", G_CALLBACK(done), NULL); |
557 |
|
558 |
GtkWidget* cancel = gtk_button_new_from_stock(GTK_STOCK_CANCEL); |
559 |
|
560 |
g_signal_connect(G_OBJECT(cancel), "clicked", G_CALLBACK(destruct), NULL); |
561 |
|
562 |
// pack |
563 |
gtk_container_add(GTK_CONTAINER(vertical), horizontal); |
564 |
gtk_container_add(GTK_CONTAINER(horizontal), left); |
565 |
gtk_container_add(GTK_CONTAINER(horizontal), center); |
566 |
gtk_container_add(GTK_CONTAINER(center), top); |
567 |
gtk_container_add(GTK_CONTAINER(top), add); |
568 |
gtk_container_add(GTK_CONTAINER(top), remove); |
569 |
gtk_container_add(GTK_CONTAINER(center), middle); |
570 |
gtk_container_add(GTK_CONTAINER(middle), up); |
571 |
gtk_container_add(GTK_CONTAINER(middle), down); |
572 |
gtk_container_add(GTK_CONTAINER(horizontal), right); |
573 |
gtk_container_add(GTK_CONTAINER(vertical), separator); |
574 |
gtk_container_add(GTK_CONTAINER(bottom), ok); |
575 |
gtk_container_add(GTK_CONTAINER(bottom), cancel); |
576 |
gtk_container_add(GTK_CONTAINER(vertical), bottom); |
577 |
gtk_container_add(GTK_CONTAINER(window), vertical); |
578 |
|
579 |
// show |
580 |
gtk_widget_show(left); |
581 |
gtk_widget_show(add); |
582 |
gtk_widget_show(remove); |
583 |
gtk_widget_show(top); |
584 |
gtk_widget_show(up); |
585 |
gtk_widget_show(down); |
586 |
gtk_widget_show(middle); |
587 |
gtk_widget_show(center); |
588 |
gtk_widget_show(right); |
589 |
gtk_widget_show(horizontal); |
590 |
gtk_widget_show(separator); |
591 |
gtk_widget_show(ok); |
592 |
gtk_widget_show(cancel); |
593 |
gtk_widget_show(bottom); |
594 |
gtk_widget_show(vertical); |
595 |
gtk_widget_show(window); |
596 |
|
597 |
gtk_main(); |
598 |
} |
599 |
|
600 |
void message(const string& text, const string& title, GtkMessageType type) |
601 |
{ |
602 |
GtkWidget* box = gtk_message_dialog_new(NULL, GTK_DIALOG_MODAL, type, |
603 |
GTK_BUTTONS_OK, text.c_str()); |
604 |
|
605 |
gtk_window_set_title(GTK_WINDOW(box), title.c_str()); |
606 |
|
607 |
gtk_dialog_run(GTK_DIALOG(box)); |
608 |
gtk_widget_destroy(box); |
609 |
} |
610 |
#endif |