Rev 124 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1 | pmbaty | 1 | // dialog_load.cpp |
2 | |||
3 | #include "../common.h" |
||
4 | |||
5 | |||
6 | // local prototypes |
||
7 | static void StartThread_ThisDialog (void *thread_parms); |
||
8 | |||
9 | |||
10 | void DialogBox_Load (void) |
||
11 | { |
||
12 | // helper function to fire up the modeless dialog box |
||
13 | |||
14 | _beginthread (StartThread_ThisDialog, 0, NULL); // fire up a new one |
||
15 | |||
16 | return; // return as soon as the thread is fired up |
||
17 | } |
||
18 | |||
19 | |||
20 | void DialogBox_Load_Validated (void) |
||
21 | { |
||
22 | // callback function called by the main game thread when the dialog box is validated |
||
23 | |||
24 | wchar_t fen_string[128]; |
||
25 | int length; |
||
26 | |||
27 | // remember this callback is no longer to be called |
||
28 | is_dialogbox_load_validated = false; |
||
29 | |||
30 | length = wcslen (load_pathname); // get pathname length |
||
31 | |||
32 | // is it a FEN or a PGN filename ? |
||
33 | if ((length > 4) && (_wcsicmp (&load_pathname[length - 4], L".fen") == 0)) |
||
34 | { |
||
35 | ////////////////////////////// |
||
36 | // load the requested FEN game |
||
37 | if (FENFile_Load (load_pathname, fen_string, WCHAR_SIZEOF (fen_string)) |
||
38 | && Board_Reset (&the_board, fen_string)) |
||
39 | { |
||
40 | animation_endtime = current_time + ANIMATION_DURATION; // start with an animation |
||
41 | the_board.reevaluate = true; // evaluate the new board |
||
42 | the_scene.update = true; // update scene |
||
43 | } |
||
44 | else |
||
45 | { |
||
46 | messagebox.hWndParent = hMainWnd; |
||
47 | wcscpy_s (messagebox.title, WCHAR_SIZEOF (messagebox.title), LOCALIZE (L"ImportantMessage")); |
||
48 | wcscpy_s (messagebox.text, WCHAR_SIZEOF (messagebox.text), LOCALIZE (L"Error_LoadFailed")); |
||
49 | messagebox.flags = MB_ICONWARNING | MB_OK; |
||
50 | DialogBox_Message (&messagebox); // on error, display a modeless error message box |
||
51 | } |
||
52 | } |
||
53 | else |
||
54 | { |
||
55 | ////////////////////////////// |
||
56 | // load the requested PGN file |
||
57 | if (PGNFile_Load (load_pathname)) |
||
58 | { |
||
59 | // is there only one game in this PGN file ? |
||
60 | if (game_count == 1) |
||
61 | { |
||
62 | if (PGNFile_LoadGame (&the_board, load_pathname, &games[0])) // then automatically choose the first one |
||
63 | { |
||
64 | animation_endtime = current_time + ANIMATION_DURATION; // start with an animation |
||
65 | the_board.reevaluate = true; // evaluate the new board |
||
66 | the_scene.update = true; // update scene |
||
67 | } |
||
68 | else |
||
69 | { |
||
70 | messagebox.hWndParent = hMainWnd; |
||
71 | wcscpy_s (messagebox.title, WCHAR_SIZEOF (messagebox.title), LOCALIZE (L"ImportantMessage")); |
||
72 | wcscpy_s (messagebox.text, WCHAR_SIZEOF (messagebox.text), LOCALIZE (L"Error_LoadFailed")); |
||
73 | messagebox.flags = MB_ICONWARNING | MB_OK; |
||
74 | DialogBox_Message (&messagebox); // on error, display a modeless error message box |
||
75 | } |
||
76 | } |
||
77 | |||
78 | // else is there more than one game in this PGN file ? |
||
79 | else if (game_count > 1) |
||
80 | Window_Games (); // if so, show the PGN games window |
||
81 | } |
||
82 | else |
||
83 | { |
||
84 | messagebox.hWndParent = hMainWnd; |
||
85 | wcscpy_s (messagebox.title, WCHAR_SIZEOF (messagebox.title), LOCALIZE (L"ImportantMessage")); |
||
86 | wcscpy_s (messagebox.text, WCHAR_SIZEOF (messagebox.text), LOCALIZE (L"Error_LoadFailed")); |
||
87 | messagebox.flags = MB_ICONWARNING | MB_OK; |
||
88 | DialogBox_Message (&messagebox); // on error, display a modeless error message box |
||
89 | } |
||
90 | } |
||
91 | |||
92 | return; // finished, game is loaded |
||
93 | } |
||
94 | |||
95 | |||
96 | static void StartThread_ThisDialog (void *thread_parms) |
||
97 | { |
||
98 | // this function runs in a separate thread, for that's the only way (seemingly) |
||
99 | // to implement a non-modal Open dialog box using the Common Controls library. |
||
100 | |||
101 | OPENFILENAME ofn; |
||
102 | |||
103 | // reset and prepare the open file name structure |
||
104 | memset (&ofn, 0, sizeof (ofn)); |
||
105 | ofn.lStructSize = sizeof (ofn); |
||
106 | ofn.hwndOwner = hMainWnd; |
||
107 | ofn.lpstrFilter = LOCALIZE (L"GameFileFilter"); |
||
108 | ofn.nFilterIndex = 1; // first filter (list is 1-based) |
||
109 | ofn.lpstrFile = load_pathname; |
||
110 | ofn.nMaxFile = WCHAR_SIZEOF (load_pathname); |
||
111 | ofn.Flags = OFN_ENABLESIZING | OFN_EXPLORER | OFN_ENABLEHOOK | OFN_HIDEREADONLY | OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST; |
||
112 | |||
113 | // display the dialog box and get the file name |
||
114 | if (GetOpenFileName (&ofn) != 0) |
||
115 | is_dialogbox_load_validated = true; |
||
116 | |||
124 | pmbaty | 117 | the_board.reevaluate = true; // refresh the GUI buttons if needed |
1 | pmbaty | 118 | return; // _endthread() implied |
119 | } |