ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/proj/trunk/RenegadeMapSelector/RenegadeMapSelector.cpp
(Generate patch)

Comparing trunk/RenegadeMapSelector/RenegadeMapSelector.cpp (file contents):
Revision 69 by douglas, 2003-03-11T18:39:01-08:00 vs.
Revision 86 by douglas, 2003-03-15T16:43:53-08:00

# Line 4 | Line 4
4   //
5   // RenegadeMapSelector.cpp
6  
7 + #include "RenegadeMapSelector.h"
8 + #include "RenegadeConfig.h"
9 +
10   #ifdef _WIN32
11 +
12   #include <io.h>
13   #include <fcntl.h>
14   #include "resource.h"
11 #endif
15  
16 < #include "RenegadeMapSelector.h"
17 < #include "RenegadeConfig.h"
16 > #else
17 >
18 > #include "MapSelector.h"
19 >
20 > #endif
21  
22   bool debug = false;
23   string program;
24   RenegadeConfig* config;
25  
26   #ifndef _WIN32
27 +
28   inline string fix(const string& ansi) { return ansi; }
29 < inline void munge(void) { return; }
29 > inline void munge(void) { debug = true; }
30 >
31   #else
32 +
33   inline string fix(const wstring& wide)
34   {
35          char* buffer = new char[wide.length() + 1];
# Line 63 | Line 72 | inline void munge(void)
72  
73          debug = true;
74   }
75 +
76   #endif
77  
78 + #ifdef _WIN32
79   int CALLBACK selector(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
80  
81   int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR
# Line 72 | Line 83 | int WINAPI WinMain(HINSTANCE hInstance,
83   {
84          int argc;
85          unsigned short** argv = CommandLineToArgvW(GetCommandLineW(), &argc);
86 + #else
87 + void selector(void);
88 +
89 + int main(int argc, char* argv[])
90 + {
91 +        if (!gtk_init_check(&argc, &argv))
92 +        {
93 +                cerr << argv[0] << ": Cannot open display, need a clue-by-four?\n";
94 +
95 +                return 1;
96 +        }
97 + #endif
98  
99          string error;
100          string file = "svrcfg_cnc.ini";
# Line 96 | Line 119 | int WINAPI WinMain(HINSTANCE hInstance,
119                          {
120                                  error = "The argument -file must be followed by a filename.";
121  
122 + #ifdef _WIN32
123                                  MessageBox(NULL, error.c_str(), "Bad Arguments", MB_ICONERROR);
124 + #else
125 +                                message(NULL, error, "Bad Arguments", GTK_MESSAGE_ERROR);
126 + #endif
127                                  return 1;
128                          }
129                  }
130          }
131  
132 + #ifdef _WIN32
133          GlobalFree(argv);
134 + #endif
135  
136          if (debug) cerr << "file = " << file << "\n";
137  
# Line 111 | Line 140 | int WINAPI WinMain(HINSTANCE hInstance,
140          {
141                  error = "Could not open " + file + ".";
142  
143 + #ifdef _WIN32
144                  MessageBox(NULL, error.c_str(), "Bad File", MB_ICONERROR);
145 + #else
146 +                message(NULL, error, "Bad File", GTK_MESSAGE_ERROR);
147 + #endif
148                  return 1;
149          }
150  
151 + #ifdef _WIN32
152          DialogBox(hInstance, MAKEINTRESOURCE(IDD_MAP_SELECTOR), NULL, selector);
153 + #else
154 +        MapSelector selector;
155 + #endif
156  
157          delete config;
158  
159 <        if (debug) cin.get();
159 > #ifdef _WIN32
160 >        if (debug)
161 >        {
162 >                cout << "Press enter key to exit . . .";
163 >                cin.get();
164 >        }
165 > #endif
166  
167          return 0;
168   }
169  
170 + #ifdef _WIN32
171 +
172   int CALLBACK selector(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
173   {
174          switch (uMsg)
# Line 203 | Line 248 | int CALLBACK selector(HWND hwndDlg, UINT
248                          EndDialog(hwndDlg, wParam);
249                          return true;
250                  case IDC_ADD_MAP:
251 +                        {
252 +                                unsigned count = SendMessage(GetDlgItem(hwndDlg,
253 +                                        IDC_AVAILABLE), LB_GETSELCOUNT, 0, 0);
254 +                                unsigned* additions = new unsigned[count];
255 +
256 +                                SendMessage(GetDlgItem(hwndDlg, IDC_AVAILABLE), LB_GETSELITEMS,
257 +                                        count, long(additions));
258 +
259 +                                if (debug) cerr << "additions = {\n";
260 +                                for (unsigned index = 0; index < count; index++)
261 +                                {
262 +                                        if (debug) cerr << "   [" << index << "] = " <<
263 +                                                additions[index] << "\n";
264 +
265 +                                        char* name = new char[SendMessage(GetDlgItem(hwndDlg,
266 +                                                IDC_AVAILABLE), LB_GETTEXTLEN, additions[index], 0) + 1
267 +                                                ];
268 +
269 +                                        SendMessage(GetDlgItem(hwndDlg, IDC_AVAILABLE), LB_GETTEXT,
270 +                                                additions[index], long(name));
271 +                                        SendMessage(GetDlgItem(hwndDlg, IDC_SELECTED),
272 +                                                LB_ADDSTRING, 0, long(name));
273 +
274 +                                        delete [] name;
275 +                                }
276 +                                if (debug) cerr << "}\n";
277 +
278 +                                delete [] additions;
279 +
280 +                                SendMessage(GetDlgItem(hwndDlg, IDC_AVAILABLE), LB_SETSEL,
281 +                                        false, -1);
282 +                                EnableWindow(GetDlgItem(hwndDlg, IDC_ADD_MAP), false);
283 +                        }
284                          break;
285                  case IDC_REMOVE_MAP:
286 +                        {
287 +                                unsigned count = SendMessage(GetDlgItem(hwndDlg, IDC_SELECTED),
288 +                                        LB_GETSELCOUNT, 0, 0);
289 +                                unsigned* removals = new unsigned[count];
290 +
291 +                                SendMessage(GetDlgItem(hwndDlg, IDC_SELECTED), LB_GETSELITEMS,
292 +                                        count, long(removals));
293 +
294 +                                if (debug) cerr << "removals = {\n";
295 +                                for (unsigned index = count; index > 0; index--)
296 +                                {
297 +                                        if (debug) cerr << "   [" << index - 1 << "] = " <<
298 +                                                removals[index - 1] << "\n";
299 +
300 +                                        SendMessage(GetDlgItem(hwndDlg, IDC_SELECTED),
301 +                                                LB_DELETESTRING, removals[index - 1], 0);
302 +                                }
303 +                                if (debug) cerr << "}\n";
304 +
305 +                                delete [] removals;
306 +
307 +                                EnableWindow(GetDlgItem(hwndDlg, IDC_REMOVE_MAP), false);
308 +                                EnableWindow(GetDlgItem(hwndDlg, IDC_UP_MAP), false);
309 +                                EnableWindow(GetDlgItem(hwndDlg, IDC_DOWN_MAP), false);
310 +                        }
311                          break;
312                  case IDC_UP_MAP:
313 +                        {
314 +                                unsigned count = SendMessage(GetDlgItem(hwndDlg, IDC_SELECTED),
315 +                                        LB_GETSELCOUNT, 0, 0);
316 +                                unsigned* ups = new unsigned[count];
317 +
318 +                                SendMessage(GetDlgItem(hwndDlg, IDC_SELECTED), LB_GETSELITEMS,
319 +                                        count, long(ups));
320 +
321 +                                unsigned insert = ups[0] - 1;
322 +
323 +                                if (debug) cerr << "ups = {\n";
324 +                                for (unsigned index = 0; index < count; index++)
325 +                                {
326 +                                        if (debug) cerr << "   [" << index << "] = " << ups[index]
327 +                                                << "\n";
328 +
329 +                                        char* up = new char[SendMessage(GetDlgItem(hwndDlg,
330 +                                                IDC_SELECTED), LB_GETTEXTLEN, ups[index], 0) + 1];
331 +
332 +                                        SendMessage(GetDlgItem(hwndDlg, IDC_SELECTED), LB_GETTEXT,
333 +                                                ups[index], long(up));
334 +                                        SendMessage(GetDlgItem(hwndDlg, IDC_SELECTED),
335 +                                                LB_DELETESTRING, ups[index], 0);
336 +                                        SendMessage(GetDlgItem(hwndDlg, IDC_SELECTED),
337 +                                                LB_INSERTSTRING, insert, long(up));
338 +                                        SendMessage(GetDlgItem(hwndDlg, IDC_SELECTED), LB_SETSEL,
339 +                                                true, insert++);
340 +                                }
341 +                                if (debug) cerr << "}\n";
342 +
343 +                                delete [] ups;
344 +
345 +                                if (SendMessage(GetDlgItem(hwndDlg, IDC_SELECTED),
346 +                                        LB_GETSEL, 0, 0) == 0)
347 +                                {
348 +                                        EnableWindow(GetDlgItem(hwndDlg, IDC_UP_MAP), true);
349 +                                }
350 +                                else
351 +                                {
352 +                                        EnableWindow(GetDlgItem(hwndDlg, IDC_UP_MAP), false);
353 +                                }
354 +
355 +                                if (SendMessage(GetDlgItem(hwndDlg, IDC_SELECTED),
356 +                                        LB_GETSEL, SendMessage(GetDlgItem(hwndDlg, IDC_SELECTED
357 +                                        ), LB_GETCOUNT, 0, 0) - 1, 0) == 0)
358 +                                {
359 +                                        EnableWindow(GetDlgItem(hwndDlg, IDC_DOWN_MAP), true);
360 +                                }
361 +                        }
362                          break;
363                  case IDC_DOWN_MAP:
364 +                        {
365 +                                unsigned count = SendMessage(GetDlgItem(hwndDlg, IDC_SELECTED),
366 +                                        LB_GETSELCOUNT, 0, 0);
367 +                                unsigned* downs = new unsigned[count];
368 +
369 +                                SendMessage(GetDlgItem(hwndDlg, IDC_SELECTED), LB_GETSELITEMS,
370 +                                        count, long(downs));
371 +
372 +                                unsigned insert = downs[count - 1] + 1;
373 +
374 +                                if (debug) cerr << "downs = {\n";
375 +                                for (unsigned index = count; index > 0; index--)
376 +                                {
377 +                                        if (debug) cerr << "   [" << index << "] = " << downs[index
378 +                                                - 1] << "\n";
379 +
380 +                                        char* down = new char[SendMessage(GetDlgItem(hwndDlg,
381 +                                                IDC_SELECTED), LB_GETTEXTLEN, downs[index - 1], 0) +
382 +                                                1];
383 +
384 +                                        SendMessage(GetDlgItem(hwndDlg, IDC_SELECTED), LB_GETTEXT,
385 +                                                downs[index - 1], long(down));
386 +                                        SendMessage(GetDlgItem(hwndDlg, IDC_SELECTED),
387 +                                                LB_DELETESTRING, downs[index - 1], 0);
388 +                                        SendMessage(GetDlgItem(hwndDlg, IDC_SELECTED),
389 +                                                LB_INSERTSTRING, insert, long(down));
390 +                                        SendMessage(GetDlgItem(hwndDlg, IDC_SELECTED), LB_SETSEL,
391 +                                                true, insert--);
392 +                                }
393 +                                if (debug) cerr << "}\n";
394 +
395 +                                delete [] downs;
396 +
397 +                                if (SendMessage(GetDlgItem(hwndDlg, IDC_SELECTED),
398 +                                        LB_GETSEL, 0, 0) == 0)
399 +                                {
400 +                                        EnableWindow(GetDlgItem(hwndDlg, IDC_UP_MAP), true);
401 +                                }
402 +
403 +                                if (SendMessage(GetDlgItem(hwndDlg, IDC_SELECTED),
404 +                                        LB_GETSEL, SendMessage(GetDlgItem(hwndDlg, IDC_SELECTED
405 +                                        ), LB_GETCOUNT, 0, 0) - 1, 0) == 0)
406 +                                {
407 +                                        EnableWindow(GetDlgItem(hwndDlg, IDC_DOWN_MAP), true);
408 +                                }
409 +                                else
410 +                                {
411 +                                        EnableWindow(GetDlgItem(hwndDlg, IDC_DOWN_MAP), false);
412 +                                }
413 +                        }
414                          break;
415                  case IDC_AVAILABLE:
416                          switch (HIWORD(wParam))
# Line 271 | Line 473 | int CALLBACK selector(HWND hwndDlg, UINT
473  
474          return false;
475   }
476 +
477 + #endif

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines