Rev 140 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1 | pmbaty | 1 | // dialog_changeappearance.cpp |
2 | |||
3 | #include "../common.h" |
||
4 | |||
5 | |||
6 | // dialog template |
||
7 | #define THIS_DIALOG DIALOG_CHANGEAPPEARANCE |
||
8 | |||
9 | |||
10 | // global variables |
||
11 | static wchar_t ofn_customfilter[256] = L""; |
||
12 | |||
13 | |||
14 | // prototypes of local functions |
||
15 | static void StartThread_ThisDialog (void *thread_parms); |
||
16 | static int CALLBACK DialogProc_ThisDialog (HWND hWnd, unsigned int message, WPARAM wParam, LPARAM lParam); |
||
17 | static void StartThread_DialogBoxLoad (void *thread_parms); |
||
18 | |||
19 | |||
20 | void DialogBox_ChangeAppearance (void) |
||
21 | { |
||
22 | // helper function to fire up the modeless dialog box |
||
23 | |||
140 | pmbaty | 24 | is_dialogbox_displayed = true; |
1 | pmbaty | 25 | _beginthread (StartThread_ThisDialog, 0, NULL); // fire up a new one |
26 | |||
27 | return; // return as soon as the thread is fired up |
||
28 | } |
||
29 | |||
30 | |||
31 | void DialogBox_ChangeAppearance_Validated (void) |
||
32 | { |
||
33 | // callback function called by the main game thread when the dialog box is validated |
||
34 | |||
35 | // remember this callback is no longer to be called |
||
36 | is_dialogbox_changeappearance_validated = false; |
||
37 | |||
38 | return; // finished |
||
39 | } |
||
40 | |||
41 | |||
42 | static void StartThread_ThisDialog (void *thread_parms) |
||
43 | { |
||
44 | // this function runs in a separate thread, for that's the only way (seemingly) |
||
45 | // to implement a non-modal message box using the Common Controls library. |
||
46 | |||
47 | // display the dialog box |
||
48 | if (DialogBox (hAppInstance, MAKEINTRESOURCE (THIS_DIALOG), hMainWnd, DialogProc_ThisDialog) == 1) |
||
49 | is_dialogbox_changeappearance_validated = true; |
||
140 | pmbaty | 50 | is_dialogbox_displayed = false; |
1 | pmbaty | 51 | |
124 | pmbaty | 52 | the_board.reevaluate = true; // refresh the GUI buttons if needed |
1 | pmbaty | 53 | return; // _endthread() implied |
54 | } |
||
55 | |||
56 | |||
57 | static int CALLBACK DialogProc_ThisDialog (HWND hWnd, unsigned int message, WPARAM wParam, LPARAM lParam) |
||
58 | { |
||
59 | // message handler for the dialog box |
||
60 | |||
61 | unsigned short wParam_hiword; |
||
62 | unsigned short wParam_loword; |
||
63 | HWND hComboBoxWnd; |
||
193 | pmbaty | 64 | int selected_index; |
1 | pmbaty | 65 | int theme_index; |
66 | |||
67 | // filter out the commonly used message values |
||
68 | wParam_hiword = HIWORD (wParam); |
||
69 | wParam_loword = LOWORD (wParam); |
||
70 | |||
71 | // have we just fired up this window ? |
||
72 | if (message == WM_INITDIALOG) |
||
73 | { |
||
74 | // center the window |
||
75 | CenterWindow (hWnd, hMainWnd); |
||
76 | |||
77 | // set dialog icons (small one for title bar & big one for task manager) |
||
78 | SendMessage (hWnd, WM_SETICON, ICON_SMALL, (LPARAM) LoadIcon (hAppInstance, MAKEINTRESOURCE (ICON_MAIN))); |
||
79 | SendMessage (hWnd, WM_SETICON, ICON_BIG, (LPARAM) LoadIcon (hAppInstance, MAKEINTRESOURCE (ICON_MAIN))); |
||
80 | |||
81 | // set window title and control texts |
||
82 | SetWindowText (hWnd, LOCALIZE (L"ChangeAppearance_Title")); |
||
83 | Static_SetText (GetDlgItem (hWnd, GROUPBOX_TABLESKIN), LOCALIZE (L"ChangeAppearance_TableSkin")); |
||
84 | Static_SetText (GetDlgItem (hWnd, STATICTEXT_CHANGEAPPEARANCE_THEMEINFO), (theme->description != NULL ? theme->description : L"")); |
||
85 | SetWindowText (GetDlgItem (hWnd, CHECKBOX_CHANGEAPPEARANCE_SHOWGRID), LOCALIZE (L"ChangeAppearance_ShowGrid")); |
||
86 | SetWindowText (GetDlgItem (hWnd, CHECKBOX_CHANGEAPPEARANCE_SHOWICONSRATHER), LOCALIZE (L"ChangeAppearance_ShowIconsRather")); |
||
87 | SetWindowText (GetDlgItem (hWnd, CHECKBOX_CHANGEAPPEARANCE_CUSTOMBACKGROUND), LOCALIZE (L"ChangeAppearance_CustomPicture")); |
||
88 | SetWindowText (GetDlgItem (hWnd, BUTTON_BROWSE), LOCALIZE (L"Button_Browse")); |
||
89 | Static_SetText (GetDlgItem (hWnd, STATICTEXT_CHANGEAPPEARANCE_STATUSBAR), LOCALIZE (L"ChangeAppearance_StatusBar")); |
||
90 | |||
91 | // get a quick access to the themes combo box |
||
92 | hComboBoxWnd = GetDlgItem (hWnd, COMBOBOX_THEMES); |
||
93 | |||
94 | // populate the themes combo box |
||
95 | ComboBox_ResetContent (hComboBoxWnd); |
||
96 | for (theme_index = 0; theme_index < theme_count; theme_index++) |
||
193 | pmbaty | 97 | { |
98 | selected_index = ComboBox_AddString (hComboBoxWnd, themes[theme_index].name); |
||
99 | ComboBox_SetItemData (hComboBoxWnd, selected_index, theme_index); // save the theme index along with its name in the combo box |
||
1 | pmbaty | 100 | if (_wcsicmp (themes[theme_index].name, theme->name) == 0) |
193 | pmbaty | 101 | ComboBox_SetCurSel (hComboBoxWnd, selected_index); // put the user selection back on the fly |
102 | } |
||
1 | pmbaty | 103 | |
104 | // initialize the checkboxes |
||
105 | Button_SetCheck (GetDlgItem (hWnd, CHECKBOX_CHANGEAPPEARANCE_SHOWGRID), (want_grid ? BST_CHECKED : BST_UNCHECKED)); |
||
106 | Button_SetCheck (GetDlgItem (hWnd, CHECKBOX_CHANGEAPPEARANCE_SHOWICONSRATHER), (want_flaticons ? BST_CHECKED : BST_UNCHECKED)); |
||
107 | Button_SetCheck (GetDlgItem (hWnd, CHECKBOX_CHANGEAPPEARANCE_CUSTOMBACKGROUND), (want_custombackground ? BST_CHECKED : BST_UNCHECKED)); |
||
108 | |||
109 | // enable or disable the browse button based on whether we want a custom background or not |
||
110 | EnableWindow (GetDlgItem (hWnd, BUTTON_BROWSE), want_custombackground); |
||
111 | } |
||
112 | |||
113 | // else did we click the close button on the title bar ? |
||
114 | else if (message == WM_CLOSE) |
||
115 | EndDialog (hWnd, 0); // close the dialog box |
||
116 | |||
117 | // else did we take action on one of the controls ? |
||
118 | else if (message == WM_COMMAND) |
||
119 | { |
||
120 | // did we cancel the dialog box ? (IDCANCEL is a system-wide dialog box handler value, that catches the ESC key) |
||
121 | if (wParam_loword == IDCANCEL) |
||
122 | EndDialog (hWnd, 0); // close the dialog box |
||
123 | |||
124 | // else given the control that's clicked, update the relevant skin |
||
125 | else if ((wParam_loword == COMBOBOX_THEMES) && (wParam_hiword == CBN_SELCHANGE)) |
||
126 | { |
||
193 | pmbaty | 127 | // get a quick access to the themes combo box |
128 | hComboBoxWnd = GetDlgItem (hWnd, COMBOBOX_THEMES); |
||
129 | |||
130 | selected_index = ComboBox_GetCurSel (hComboBoxWnd); // as the combo box is sorted, the selected index is NOT the theme index |
||
131 | if ((selected_index >= 0) && (selected_index < theme_count)) |
||
1 | pmbaty | 132 | { |
193 | pmbaty | 133 | theme_index = ComboBox_GetItemData (hComboBoxWnd, selected_index); // retrieve the actual theme index from the combo box's user data |
1 | pmbaty | 134 | while (!themes[theme_index].is_loaded) |
135 | Sleep (100); // wait until theme is fully loaded |
||
136 | theme = &themes[theme_index]; // update the selected theme (WARNING: race condition ?) |
||
137 | |||
138 | // update the theme info text |
||
139 | Static_SetText (GetDlgItem (hWnd, STATICTEXT_CHANGEAPPEARANCE_THEMEINFO), (theme->description != NULL ? theme->description : L"")); |
||
140 | } |
||
141 | the_scene.update = true; // redraw scene |
||
142 | } |
||
143 | else if (wParam_loword == CHECKBOX_CHANGEAPPEARANCE_SHOWGRID) |
||
144 | { |
||
145 | want_grid = (Button_GetCheck (GetDlgItem (hWnd, CHECKBOX_CHANGEAPPEARANCE_SHOWGRID)) != 0); |
||
146 | the_scene.update = true; // redraw scene |
||
147 | } |
||
148 | else if (wParam_loword == CHECKBOX_CHANGEAPPEARANCE_SHOWICONSRATHER) |
||
149 | { |
||
150 | want_flaticons = (Button_GetCheck (GetDlgItem (hWnd, CHECKBOX_CHANGEAPPEARANCE_SHOWICONSRATHER)) != 0); |
||
151 | the_scene.update = true; // redraw scene |
||
152 | } |
||
153 | else if (wParam_loword == CHECKBOX_CHANGEAPPEARANCE_CUSTOMBACKGROUND) |
||
154 | { |
||
155 | want_custombackground = (Button_GetCheck (GetDlgItem (hWnd, CHECKBOX_CHANGEAPPEARANCE_CUSTOMBACKGROUND)) != 0); |
||
156 | EnableWindow (GetDlgItem (hWnd, BUTTON_BROWSE), want_custombackground); |
||
157 | the_scene.update = true; // redraw scene |
||
158 | } |
||
159 | |||
160 | // else did we click the browse button ? |
||
161 | else if (wParam_loword == BUTTON_BROWSE) |
||
162 | _beginthread (StartThread_DialogBoxLoad, 0, (void *) hWnd); // fire up the load dialog box thread |
||
163 | } |
||
164 | |||
165 | // call the default dialog message processing function to keep things going |
||
166 | return (false); |
||
167 | } |
||
168 | |||
169 | |||
170 | static void StartThread_DialogBoxLoad (void *thread_parms) |
||
171 | { |
||
172 | // this function runs in a separate thread, for that's the only way (seemingly) |
||
173 | // to implement a non-modal Open dialog box using the Common Controls library. |
||
174 | |||
175 | OPENFILENAME ofn; |
||
176 | |||
177 | // reset and prepare the open file name structure |
||
178 | memset (&ofn, 0, sizeof (ofn)); |
||
179 | ofn.lStructSize = sizeof (ofn); |
||
180 | ofn.hwndOwner = (HWND) thread_parms; |
||
181 | ofn.lpstrFilter = LOCALIZE (L"ImageFileFilter"); |
||
182 | ofn.lpstrDefExt = L"jpg"; // default extension |
||
183 | ofn.lpstrCustomFilter = ofn_customfilter; |
||
184 | ofn.nMaxCustFilter = WCHAR_SIZEOF (ofn_customfilter); |
||
185 | ofn.nFilterIndex = 1; // first filter (list is 1-based) |
||
186 | ofn.lpstrFile = custombackground_pathname; |
||
187 | ofn.nMaxFile = WCHAR_SIZEOF (custombackground_pathname); |
||
188 | ofn.Flags = OFN_ENABLESIZING | OFN_EXPLORER | OFN_HIDEREADONLY | OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST; |
||
189 | |||
190 | // display the dialog box and get the file name |
||
191 | if (GetOpenFileName (&ofn)) |
||
192 | Background_LoadImage (&custombg, custombackground_pathname); |
||
193 | |||
194 | the_scene.update = true; // redraw scene |
||
195 | return; // _endthread() implied |
||
196 | } |