Subversion Repositories Games.Chess Giants

Rev

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_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;
64
   int theme_index;
65
 
66
   // filter out the commonly used message values
67
   wParam_hiword = HIWORD (wParam);
68
   wParam_loword = LOWORD (wParam);
69
 
70
   // have we just fired up this window ?
71
   if (message == WM_INITDIALOG)
72
   {
73
      // center the window
74
      CenterWindow (hWnd, hMainWnd);
75
 
76
      // set dialog icons (small one for title bar & big one for task manager)
77
      SendMessage (hWnd, WM_SETICON, ICON_SMALL, (LPARAM) LoadIcon (hAppInstance, MAKEINTRESOURCE (ICON_MAIN)));
78
      SendMessage (hWnd, WM_SETICON, ICON_BIG, (LPARAM) LoadIcon (hAppInstance, MAKEINTRESOURCE (ICON_MAIN)));
79
 
80
      // set window title and control texts
81
      SetWindowText (hWnd, LOCALIZE (L"ChangeAppearance_Title"));
82
      Static_SetText (GetDlgItem (hWnd, GROUPBOX_TABLESKIN), LOCALIZE (L"ChangeAppearance_TableSkin"));
83
      Static_SetText (GetDlgItem (hWnd, STATICTEXT_CHANGEAPPEARANCE_THEMEINFO), (theme->description != NULL ? theme->description : L""));
84
      SetWindowText (GetDlgItem (hWnd, CHECKBOX_CHANGEAPPEARANCE_SHOWGRID), LOCALIZE (L"ChangeAppearance_ShowGrid"));
85
      SetWindowText (GetDlgItem (hWnd, CHECKBOX_CHANGEAPPEARANCE_SHOWICONSRATHER), LOCALIZE (L"ChangeAppearance_ShowIconsRather"));
86
      SetWindowText (GetDlgItem (hWnd, CHECKBOX_CHANGEAPPEARANCE_CUSTOMBACKGROUND), LOCALIZE (L"ChangeAppearance_CustomPicture"));
87
      SetWindowText (GetDlgItem (hWnd, BUTTON_BROWSE), LOCALIZE (L"Button_Browse"));
88
      Static_SetText (GetDlgItem (hWnd, STATICTEXT_CHANGEAPPEARANCE_STATUSBAR), LOCALIZE (L"ChangeAppearance_StatusBar"));
89
 
90
      // get a quick access to the themes combo box
91
      hComboBoxWnd = GetDlgItem (hWnd, COMBOBOX_THEMES);
92
 
93
      // populate the themes combo box
94
      ComboBox_ResetContent (hComboBoxWnd);
95
      for (theme_index = 0; theme_index < theme_count; theme_index++)
96
         ComboBox_AddString (hComboBoxWnd, themes[theme_index].name);
97
 
98
      // cycle through all the themes now...
99
      for (theme_index = 0; theme_index < theme_count; theme_index++)
100
         if (_wcsicmp (themes[theme_index].name, theme->name) == 0)
101
         {
102
            ComboBox_SetCurSel (hComboBoxWnd, theme_index); // put the selection back
103
            break; // and stop searching as soon as we've found it again
104
         }
105
 
106
      // initialize the checkboxes
107
      Button_SetCheck (GetDlgItem (hWnd, CHECKBOX_CHANGEAPPEARANCE_SHOWGRID), (want_grid ? BST_CHECKED : BST_UNCHECKED));
108
      Button_SetCheck (GetDlgItem (hWnd, CHECKBOX_CHANGEAPPEARANCE_SHOWICONSRATHER), (want_flaticons ? BST_CHECKED : BST_UNCHECKED));
109
      Button_SetCheck (GetDlgItem (hWnd, CHECKBOX_CHANGEAPPEARANCE_CUSTOMBACKGROUND), (want_custombackground ? BST_CHECKED : BST_UNCHECKED));
110
 
111
      // enable or disable the browse button based on whether we want a custom background or not
112
      EnableWindow (GetDlgItem (hWnd, BUTTON_BROWSE), want_custombackground);
113
   }
114
 
115
   // else did we click the close button on the title bar ?
116
   else if (message == WM_CLOSE)
117
      EndDialog (hWnd, 0); // close the dialog box
118
 
119
   // else did we take action on one of the controls ?
120
   else if (message == WM_COMMAND)
121
   {
122
      // did we cancel the dialog box ? (IDCANCEL is a system-wide dialog box handler value, that catches the ESC key)
123
      if (wParam_loword == IDCANCEL)
124
         EndDialog (hWnd, 0); // close the dialog box
125
 
126
      // else given the control that's clicked, update the relevant skin
127
      else if ((wParam_loword == COMBOBOX_THEMES) && (wParam_hiword == CBN_SELCHANGE))
128
      {
129
         theme_index = ComboBox_GetCurSel (GetDlgItem (hWnd, COMBOBOX_THEMES));
130
         if ((theme_index >= 0) && (theme_index < theme_count))
131
         {
132
            while (!themes[theme_index].is_loaded)
133
               Sleep (100); // wait until theme is fully loaded
134
            theme = &themes[theme_index]; // update the selected theme (WARNING: race condition ?)
135
 
136
            // update the theme info text
137
            Static_SetText (GetDlgItem (hWnd, STATICTEXT_CHANGEAPPEARANCE_THEMEINFO), (theme->description != NULL ? theme->description : L""));
138
         }
139
         the_scene.update = true; // redraw scene
140
      }
141
      else if (wParam_loword == CHECKBOX_CHANGEAPPEARANCE_SHOWGRID)
142
      {
143
         want_grid = (Button_GetCheck (GetDlgItem (hWnd, CHECKBOX_CHANGEAPPEARANCE_SHOWGRID)) != 0);
144
         the_scene.update = true; // redraw scene
145
      }
146
      else if (wParam_loword == CHECKBOX_CHANGEAPPEARANCE_SHOWICONSRATHER)
147
      {
148
         want_flaticons = (Button_GetCheck (GetDlgItem (hWnd, CHECKBOX_CHANGEAPPEARANCE_SHOWICONSRATHER)) != 0);
149
         the_scene.update = true; // redraw scene
150
      }
151
      else if (wParam_loword == CHECKBOX_CHANGEAPPEARANCE_CUSTOMBACKGROUND)
152
      {
153
         want_custombackground = (Button_GetCheck (GetDlgItem (hWnd, CHECKBOX_CHANGEAPPEARANCE_CUSTOMBACKGROUND)) != 0);
154
         EnableWindow (GetDlgItem (hWnd, BUTTON_BROWSE), want_custombackground);
155
         the_scene.update = true; // redraw scene
156
      }
157
 
158
      // else did we click the browse button ?
159
      else if (wParam_loword == BUTTON_BROWSE)
160
         _beginthread (StartThread_DialogBoxLoad, 0, (void *) hWnd); // fire up the load dialog box thread
161
   }
162
 
163
   // call the default dialog message processing function to keep things going
164
   return (false);
165
}
166
 
167
 
168
static void StartThread_DialogBoxLoad (void *thread_parms)
169
{
170
   // this function runs in a separate thread, for that's the only way (seemingly)
171
   // to implement a non-modal Open dialog box using the Common Controls library.
172
 
173
   OPENFILENAME ofn;
174
 
175
   // reset and prepare the open file name structure
176
   memset (&ofn, 0, sizeof (ofn));
177
   ofn.lStructSize = sizeof (ofn);
178
   ofn.hwndOwner = (HWND) thread_parms;
179
   ofn.lpstrFilter = LOCALIZE (L"ImageFileFilter");
180
   ofn.lpstrDefExt = L"jpg"; // default extension
181
   ofn.lpstrCustomFilter = ofn_customfilter;
182
   ofn.nMaxCustFilter = WCHAR_SIZEOF (ofn_customfilter);
183
   ofn.nFilterIndex = 1; // first filter (list is 1-based)
184
   ofn.lpstrFile = custombackground_pathname;
185
   ofn.nMaxFile = WCHAR_SIZEOF (custombackground_pathname);
186
   ofn.Flags = OFN_ENABLESIZING | OFN_EXPLORER | OFN_HIDEREADONLY | OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
187
 
188
   // display the dialog box and get the file name
189
   if (GetOpenFileName (&ofn))
190
      Background_LoadImage (&custombg, custombackground_pathname);
191
 
192
   the_scene.update = true; // redraw scene
193
   return; // _endthread() implied
194
}