Rev 1 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1 | pmbaty | 1 | // window_opponents.cpp |
2 | |||
3 | #include "../common.h" |
||
4 | |||
5 | |||
6 | // window parameters |
||
7 | #define WINDOW_CLASSNAME PROGRAM_NAME L" Opponents WndClass" |
||
8 | #define WINDOW_DEFAULT_WIDTH 822 |
||
9 | #define WINDOW_DEFAULT_HEIGHT 600 |
||
10 | #define WINDOW_MIN_WIDTH 822 |
||
11 | #define WINDOW_MIN_HEIGHT 200 |
||
12 | |||
13 | |||
14 | // local definitions |
||
15 | #define WINDOW_TEXT_DOUBLECLICKORNARROWDOWN 1 |
||
16 | #define WINDOW_TEXT_NAMECONTAINS 2 |
||
17 | #define WINDOW_EDITBOX_NAMECONTAINS 3 |
||
18 | #define WINDOW_TEXT_STATUSIS 4 |
||
19 | #define WINDOW_COMBOBOX_STATUSIS 5 |
||
20 | #define WINDOW_TEXT_LEVELFROM 6 |
||
21 | #define WINDOW_EDITBOX_LEVELFROM 7 |
||
22 | #define WINDOW_TEXT_LEVELTO 8 |
||
23 | #define WINDOW_EDITBOX_LEVELTO 9 |
||
24 | #define WINDOW_LIST_OPPONENTS 10 |
||
25 | #define WINDOW_TEXT_STATUSBAR 11 |
||
26 | #define WINDOW_TIMER_REFRESH 1 |
||
27 | #define TICKED_COLUMN_WIDTH 41 |
||
28 | #define STRING_FIDEGM ((wchar_t *) "G\x00M\x00 \x00\x42\x26\x00") // "GM " + male sign |
||
29 | #define STRING_FIDEIM ((wchar_t *) "I\x00M\x00 \x00\x42\x26\x00") // "IM " + male sign |
||
30 | #define STRING_FIDEWGM ((wchar_t *) "G\x00M\x00 \x00\x40\x26\x00") // "GM " + female sign |
||
31 | #define STRING_FIDEWIM ((wchar_t *) "I\x00M\x00 \x00\x40\x26\x00") // "IM " + female sign |
||
32 | |||
33 | |||
34 | // list view column definition |
||
35 | typedef struct listviewcolumn_s |
||
36 | { |
||
37 | int width; |
||
38 | int alignment; |
||
39 | bool sort_descending; |
||
40 | wchar_t *text; |
||
41 | HWND hToolTipWnd; |
||
42 | } listviewcolumn_t; |
||
43 | |||
44 | |||
45 | // global variables used in this module only |
||
46 | static bool is_classregistered = false; |
||
47 | static int listviewicons[sizeof (handlestatus) / sizeof (handlestatus_t)]; // as big as the handlestatus global array |
||
48 | static listviewcolumn_t listviewcolumns[] = |
||
49 | { |
||
50 | { 140, LVCFMT_LEFT, true, NULL /*LOCALIZE (L"Opponents_ColumnNickname")*/, NULL }, // text address needs to be set at runtime, because it's mallocated |
||
51 | { 60, LVCFMT_LEFT, false, NULL /*LOCALIZE (L"Opponents_ColumnFIDERank")*/, NULL }, |
||
52 | { 120, LVCFMT_LEFT, false, NULL /*LOCALIZE (L"Opponents_ColumnStatus")*/, NULL }, |
||
53 | { 60, LVCFMT_LEFT, false, NULL /*LOCALIZE (L"Opponents_ColumnRating")*/, NULL }, |
||
54 | { TICKED_COLUMN_WIDTH, LVCFMT_CENTER, false, NULL /*LOCALIZE (L"Opponents_ColumnComputer")*/, NULL }, |
||
55 | { TICKED_COLUMN_WIDTH, LVCFMT_CENTER, false, NULL /*LOCALIZE (L"Opponents_ColumnAdministrator")*/, NULL }, |
||
56 | { TICKED_COLUMN_WIDTH, LVCFMT_CENTER, false, NULL /*LOCALIZE (L"Opponents_ColumnBlindfold")*/, NULL }, |
||
57 | { TICKED_COLUMN_WIDTH, LVCFMT_CENTER, false, NULL /*LOCALIZE (L"Opponents_ColumnTeam")*/, NULL }, |
||
58 | { TICKED_COLUMN_WIDTH, LVCFMT_CENTER, false, NULL /*LOCALIZE (L"Opponents_ColumnChessAdvisor")*/, NULL }, |
||
59 | { TICKED_COLUMN_WIDTH, LVCFMT_CENTER, false, NULL /*LOCALIZE (L"Opponents_ColumnServiceRepresentative")*/, NULL }, |
||
60 | { TICKED_COLUMN_WIDTH, LVCFMT_CENTER, false, NULL /*LOCALIZE (L"Opponents_ColumnTournamentDirector")*/, NULL }, |
||
61 | { TICKED_COLUMN_WIDTH, LVCFMT_CENTER, false, NULL /*LOCALIZE (L"Opponents_ColumnMamerManager")*/, NULL }, |
||
62 | { TICKED_COLUMN_WIDTH, LVCFMT_CENTER, false, NULL /*LOCALIZE (L"Opponents_ColumnUnregistered")*/, NULL }, |
||
63 | }; |
||
64 | static int current_sortcolumn = 0; |
||
65 | static wchar_t window_title[256]; |
||
66 | static wchar_t opponent_namecontains[64]; |
||
67 | static wchar_t rating_string[64]; |
||
68 | //static HWND hThisWnd = NULL; |
||
69 | #define hThisWnd hOpponentsWnd // shared variable |
||
70 | |||
71 | |||
72 | // prototypes of local functions |
||
73 | static LRESULT CALLBACK WindowProc_ThisWindow (HWND hWnd, unsigned int message, WPARAM wParam, LPARAM lParam); |
||
74 | static int CALLBACK CompareProc_ListOpponents (LPARAM lParam1, LPARAM lParam2, LPARAM column); |
||
75 | static int WINAPI ListView_WndProc (HWND hWnd, unsigned int message, WPARAM wParam, LPARAM lParam); |
||
76 | |||
77 | |||
78 | void Window_Opponents (void) |
||
79 | { |
||
80 | // helper function to fire up the child window |
||
81 | |||
82 | WNDCLASSEX wc; |
||
83 | player_t *network_player; |
||
84 | |||
85 | // is the window we want to display already displayed ? |
||
86 | if (IsWindow (hThisWnd)) |
||
87 | SetForegroundWindow (hThisWnd); // if so, just bring it to front |
||
88 | |||
89 | // else the way is clear |
||
90 | else |
||
91 | { |
||
92 | // find the network player and make him ask an update from the server |
||
93 | if ((network_player = Player_FindByType (PLAYER_INTERNET)) != NULL) |
||
94 | { |
||
95 | SAFE_free ((void **) &onlineplayers); // free the online players list we know |
||
96 | onlineplayer_count = -1; // and reset its count (-1 means "reply not arrived") |
||
97 | Player_SendBuffer_Add (network_player, 1000, L"who\n"); // send the players update request |
||
98 | } |
||
99 | |||
100 | // is the window class NOT registered yet ? |
||
101 | if (!is_classregistered) |
||
102 | { |
||
103 | // if so, register the window class once and for all |
||
104 | memset (&wc, 0, sizeof (wc)); |
||
105 | wc.cbSize = sizeof (wc); |
||
106 | wc.style = CS_HREDRAW | CS_VREDRAW; |
||
107 | wc.lpfnWndProc = WindowProc_ThisWindow; |
||
108 | wc.hInstance = hAppInstance; |
||
109 | wc.hIcon = LoadIcon (hAppInstance, (wchar_t *) ICON_MAIN); |
||
110 | wc.hCursor = LoadCursor (NULL, IDC_ARROW); |
||
111 | wc.hbrBackground = GetSysColorBrush (COLOR_3DFACE); |
||
112 | wc.lpszClassName = WINDOW_CLASSNAME; |
||
113 | RegisterClassEx (&wc); |
||
114 | |||
115 | is_classregistered = true; // remember this window class is registered |
||
116 | } |
||
117 | |||
118 | // create the child window |
||
119 | hThisWnd = CreateWindowEx (WS_EX_CLIENTEDGE, WINDOW_CLASSNAME, LOCALIZE (L"Opponents_TitleBuildingList"), WS_OVERLAPPEDWINDOW, |
||
120 | CW_USEDEFAULT, CW_USEDEFAULT, WINDOW_DEFAULT_WIDTH, WINDOW_DEFAULT_HEIGHT, |
||
121 | hMainWnd, NULL, hAppInstance, NULL); |
||
122 | } |
||
123 | |||
124 | return; // return as soon as the thread is fired up |
||
125 | } |
||
126 | |||
127 | |||
128 | void Window_Opponents_Validated (void) |
||
129 | { |
||
130 | // callback function called by the main game thread when the window is validated |
||
131 | |||
132 | // remember this callback is no longer to be called |
||
133 | is_window_opponents_validated = false; |
||
134 | |||
135 | return; // finished |
||
136 | } |
||
137 | |||
138 | |||
139 | static LRESULT CALLBACK WindowProc_ThisWindow (HWND hWnd, unsigned int message, WPARAM wParam, LPARAM lParam) |
||
140 | { |
||
141 | // message handler for the child window |
||
142 | |||
143 | unsigned short wParam_hiword; |
||
144 | unsigned short wParam_loword; |
||
145 | int opponent_statusis; |
||
146 | int opponent_ratingfrom; |
||
147 | int opponent_ratingto; |
||
148 | int result; |
||
149 | HWND hListWnd; |
||
150 | LVCOLUMN lvc; |
||
151 | LVITEM lvi; |
||
152 | HDITEM hdi; |
||
153 | NMLISTVIEW *lv; |
||
154 | NMITEMACTIVATE *clickeditem; |
||
155 | HIMAGELIST imagelist; |
||
156 | MINMAXINFO *minmax; |
||
157 | RECT client_rect; |
||
158 | onlineplayer_t *onlineplayer; |
||
159 | player_t *local_player; |
||
160 | int onlineplayer_index; |
||
161 | int column_index; |
||
162 | int insert_index; |
||
163 | int displayed_count; |
||
164 | |||
165 | // filter out the commonly used message values |
||
166 | wParam_hiword = HIWORD (wParam); |
||
167 | wParam_loword = LOWORD (wParam); |
||
168 | |||
169 | // have we just fired up this window ? |
||
170 | if (message == WM_CREATE) |
||
171 | { |
||
172 | // center the window |
||
173 | CenterWindow (hWnd, hMainWnd); |
||
174 | |||
175 | // populate the window |
||
176 | CreateWindowEx (0, L"static", L"", |
||
177 | WS_CHILD | WS_VISIBLE, |
||
178 | 0, 0, 0, 0, hWnd, (HMENU) WINDOW_TEXT_DOUBLECLICKORNARROWDOWN, hAppInstance, NULL); |
||
179 | CreateWindowEx (WS_EX_RIGHT, L"static", L"", |
||
180 | WS_CHILD | WS_VISIBLE, |
||
181 | 0, 0, 0, 0, hWnd, (HMENU) WINDOW_TEXT_NAMECONTAINS, hAppInstance, NULL); |
||
182 | CreateWindowEx (WS_EX_CLIENTEDGE, L"edit", L"", |
||
183 | WS_CHILD | WS_VISIBLE | ES_AUTOHSCROLL, |
||
184 | 0, 0, 0, 0, hWnd, (HMENU) WINDOW_EDITBOX_NAMECONTAINS, hAppInstance, NULL); |
||
185 | CreateWindowEx (WS_EX_RIGHT, L"static", L"", |
||
186 | WS_CHILD | WS_VISIBLE, |
||
187 | 0, 0, 0, 0, hWnd, (HMENU) WINDOW_TEXT_STATUSIS, hAppInstance, NULL); |
||
188 | CreateWindowEx (WS_EX_CLIENTEDGE, L"combobox", L"", |
||
189 | WS_CHILD | WS_VISIBLE | CBS_DROPDOWNLIST, |
||
190 | 0, 0, 0, 0, hWnd, (HMENU) WINDOW_COMBOBOX_STATUSIS, hAppInstance, NULL); |
||
191 | CreateWindowEx (WS_EX_RIGHT, L"static", L"", |
||
192 | WS_CHILD | WS_VISIBLE, |
||
193 | 0, 0, 0, 0, hWnd, (HMENU) WINDOW_TEXT_LEVELFROM, hAppInstance, NULL); |
||
194 | CreateWindowEx (WS_EX_CLIENTEDGE, L"edit", L"", |
||
195 | WS_CHILD | WS_VISIBLE | ES_AUTOHSCROLL | SS_CENTERIMAGE, |
||
196 | 0, 0, 0, 0, hWnd, (HMENU) WINDOW_EDITBOX_LEVELFROM, hAppInstance, NULL); |
||
197 | CreateWindowEx (WS_EX_RIGHT, L"static", L"", |
||
198 | WS_CHILD | WS_VISIBLE, |
||
199 | 0, 0, 0, 0, hWnd, (HMENU) WINDOW_TEXT_LEVELTO, hAppInstance, NULL); |
||
200 | CreateWindowEx (WS_EX_CLIENTEDGE, L"edit", L"", |
||
201 | WS_CHILD | WS_VISIBLE | ES_AUTOHSCROLL | SS_CENTERIMAGE, |
||
202 | 0, 0, 0, 0, hWnd, (HMENU) WINDOW_EDITBOX_LEVELTO, hAppInstance, NULL); |
||
203 | CreateWindowEx (WS_EX_STATICEDGE, L"syslistview32", L"", |
||
204 | WS_CHILD | WS_VISIBLE | WS_TABSTOP | LVS_REPORT | LVS_SINGLESEL | LVS_SHOWSELALWAYS | LVS_ALIGNLEFT, |
||
205 | 0, 0, 0, 0, hWnd, (HMENU) WINDOW_LIST_OPPONENTS, hAppInstance, NULL); |
||
206 | CreateWindowEx (WS_EX_RIGHT, L"static", L"", |
||
207 | WS_CHILD | WS_VISIBLE, |
||
208 | 0, 0, 0, 0, hWnd, (HMENU) WINDOW_TEXT_STATUSBAR, hAppInstance, NULL); |
||
209 | |||
210 | // prepare the list view : do it before anything that could trigger a fill |
||
211 | |||
212 | // get a quick access to the list control |
||
213 | hListWnd = GetDlgItem (hWnd, WINDOW_LIST_OPPONENTS); |
||
214 | |||
215 | // add full row select and header columns rearranging to it |
||
216 | ListView_SetExtendedListViewStyle (hListWnd, ListView_GetExtendedListViewStyle (hListWnd) |
||
217 | | LVS_EX_GRIDLINES | LVS_EX_LABELTIP |
||
218 | | LVS_EX_FULLROWSELECT | LVS_EX_HEADERDRAGDROP); |
||
219 | |||
220 | // subclass the list view procedure to handle header tooltips and save the old procedure as one of the window's property |
||
221 | SetProp (hListWnd, L"BaseWndProc", (HANDLE) SetWindowLongPtr (hListWnd, GWL_WNDPROC, (long) ListView_WndProc)); |
||
222 | |||
223 | // tell Windows which members of the LVCOLUMN structure we're filling |
||
224 | memset (&lvc, 0, sizeof (lvc)); |
||
225 | lvc.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM; |
||
226 | for (column_index = 0; column_index < sizeof (listviewcolumns) / sizeof (listviewcolumn_t); column_index++) |
||
227 | { |
||
228 | lvc.iSubItem = column_index; |
||
229 | if (column_index == 0) lvc.pszText = LOCALIZE (L"Opponents_ColumnNickname"); |
||
230 | else if (column_index == 1) lvc.pszText = LOCALIZE (L"Opponents_ColumnFIDERank"); |
||
231 | else if (column_index == 2) lvc.pszText = LOCALIZE (L"Opponents_ColumnStatus"); |
||
232 | else if (column_index == 3) lvc.pszText = LOCALIZE (L"Opponents_ColumnRating"); |
||
233 | else if (column_index == 4) lvc.pszText = LOCALIZE (L"Opponents_ColumnComputer"); |
||
234 | else if (column_index == 5) lvc.pszText = LOCALIZE (L"Opponents_ColumnAdministrator"); |
||
235 | else if (column_index == 6) lvc.pszText = LOCALIZE (L"Opponents_ColumnBlindfold"); |
||
236 | else if (column_index == 7) lvc.pszText = LOCALIZE (L"Opponents_ColumnTeam"); |
||
237 | else if (column_index == 8) lvc.pszText = LOCALIZE (L"Opponents_ColumnChessAdvisor"); |
||
238 | else if (column_index == 9) lvc.pszText = LOCALIZE (L"Opponents_ColumnServiceRepresentative"); |
||
239 | else if (column_index == 10) lvc.pszText = LOCALIZE (L"Opponents_ColumnTournamentDirector"); |
||
240 | else if (column_index == 11) lvc.pszText = LOCALIZE (L"Opponents_ColumnMamerManager"); |
||
241 | else if (column_index == 12) lvc.pszText = LOCALIZE (L"Opponents_ColumnUnregistered"); |
||
242 | lvc.cx = listviewcolumns[column_index].width; |
||
243 | lvc.fmt = listviewcolumns[column_index].alignment; |
||
244 | ListView_InsertColumn (hListWnd, column_index, &lvc); // add each column to list view |
||
245 | } |
||
246 | |||
247 | // create the listview image list |
||
248 | imagelist = ImageList_Create (16, 16, ILC_COLOR32, sizeof (handlestatus) / sizeof (handlestatus_t), 1); // create an imagelist holding N 32-bit images |
||
249 | for (insert_index = 1; insert_index < sizeof (handlestatus) / sizeof (handlestatus_t); insert_index++) |
||
250 | listviewicons[insert_index] = ImageList_AddIcon (imagelist, handlestatus[insert_index].icon); // add our icons in the image list |
||
251 | ListView_SetImageList (hListWnd, imagelist, LVSIL_SMALL); // associate it with the listview |
||
252 | |||
253 | // associate the default GUI font with the "double-click or narrow down" message and set its text |
||
254 | SendMessage (GetDlgItem (hWnd, WINDOW_TEXT_DOUBLECLICKORNARROWDOWN), WM_SETFONT, (WPARAM) GetStockObject (DEFAULT_GUI_FONT), false); |
||
255 | SetWindowText (GetDlgItem (hWnd, WINDOW_TEXT_DOUBLECLICKORNARROWDOWN), LOCALIZE (L"Opponents_DoubleClickOrNarrowDown")); |
||
256 | |||
257 | // associate the default GUI font with the "name contains" message and set its text |
||
258 | SendMessage (GetDlgItem (hWnd, WINDOW_TEXT_NAMECONTAINS), WM_SETFONT, (WPARAM) GetStockObject (DEFAULT_GUI_FONT), false); |
||
259 | SetWindowText (GetDlgItem (hWnd, WINDOW_TEXT_NAMECONTAINS), LOCALIZE (L"Opponents_NameContains")); |
||
260 | |||
261 | // associate the default GUI font with the "name contains" edit box and reset it |
||
262 | SendMessage (GetDlgItem (hWnd, WINDOW_EDITBOX_NAMECONTAINS), WM_SETFONT, (WPARAM) GetStockObject (DEFAULT_GUI_FONT), false); |
||
263 | SetDlgItemText (hWnd, WINDOW_EDITBOX_NAMECONTAINS, L""); |
||
264 | |||
265 | // associate the default GUI font with the "status is" message and set its text |
||
266 | SendMessage (GetDlgItem (hWnd, WINDOW_TEXT_STATUSIS), WM_SETFONT, (WPARAM) GetStockObject (DEFAULT_GUI_FONT), false); |
||
267 | SetWindowText (GetDlgItem (hWnd, WINDOW_TEXT_STATUSIS), LOCALIZE (L"Opponents_StatusIs")); |
||
268 | |||
269 | // associate the default GUI font with the "status is" combo box and populate the combo box |
||
270 | SendMessage (GetDlgItem (hWnd, WINDOW_COMBOBOX_STATUSIS), WM_SETFONT, (WPARAM) GetStockObject (DEFAULT_GUI_FONT), false); |
||
271 | ComboBox_AddString (GetDlgItem (hWnd, WINDOW_COMBOBOX_STATUSIS), L""); |
||
272 | ComboBox_AddString (GetDlgItem (hWnd, WINDOW_COMBOBOX_STATUSIS), LOCALIZE (L"Opponents_StatusInGame")); |
||
273 | ComboBox_AddString (GetDlgItem (hWnd, WINDOW_COMBOBOX_STATUSIS), LOCALIZE (L"Opponents_StatusInSimulation")); |
||
274 | ComboBox_AddString (GetDlgItem (hWnd, WINDOW_COMBOBOX_STATUSIS), LOCALIZE (L"Opponents_StatusInTournament")); |
||
275 | ComboBox_AddString (GetDlgItem (hWnd, WINDOW_COMBOBOX_STATUSIS), LOCALIZE (L"Opponents_StatusExaminingAGame")); |
||
276 | ComboBox_AddString (GetDlgItem (hWnd, WINDOW_COMBOBOX_STATUSIS), LOCALIZE (L"Opponents_StatusNotOpenForAMatch")); |
||
277 | ComboBox_AddString (GetDlgItem (hWnd, WINDOW_COMBOBOX_STATUSIS), LOCALIZE (L"Opponents_StatusInactiveOrBusy")); |
||
278 | ComboBox_AddString (GetDlgItem (hWnd, WINDOW_COMBOBOX_STATUSIS), LOCALIZE (L"Opponents_StatusAvailable")); |
||
279 | |||
280 | // associate the default GUI font with the "level from" message and set its text |
||
281 | SendMessage (GetDlgItem (hWnd, WINDOW_TEXT_LEVELFROM), WM_SETFONT, (WPARAM) GetStockObject (DEFAULT_GUI_FONT), false); |
||
282 | SetWindowText (GetDlgItem (hWnd, WINDOW_TEXT_LEVELFROM), LOCALIZE (L"Opponents_LevelFrom")); |
||
283 | |||
284 | // associate the default GUI font with the "level from" edit box and reset it |
||
285 | SendMessage (GetDlgItem (hWnd, WINDOW_EDITBOX_LEVELFROM), WM_SETFONT, (WPARAM) GetStockObject (DEFAULT_GUI_FONT), false); |
||
286 | SetDlgItemText (hWnd, WINDOW_EDITBOX_LEVELFROM, L""); |
||
287 | |||
288 | // associate the default GUI font with the "level to" message and set its text |
||
289 | SendMessage (GetDlgItem (hWnd, WINDOW_TEXT_LEVELTO), WM_SETFONT, (WPARAM) GetStockObject (DEFAULT_GUI_FONT), false); |
||
290 | SetWindowText (GetDlgItem (hWnd, WINDOW_TEXT_LEVELTO), LOCALIZE (L"Opponents_LevelTo")); |
||
291 | |||
292 | // associate the default GUI font with the "level to" edit box and reset it |
||
293 | SendMessage (GetDlgItem (hWnd, WINDOW_EDITBOX_LEVELTO), WM_SETFONT, (WPARAM) GetStockObject (DEFAULT_GUI_FONT), false); |
||
294 | SetDlgItemText (hWnd, WINDOW_EDITBOX_LEVELTO, L""); |
||
295 | |||
296 | // associate the default GUI font with the status bar and set its text |
||
297 | SendMessage (GetDlgItem (hWnd, WINDOW_TEXT_STATUSBAR), WM_SETFONT, (WPARAM) GetStockObject (DEFAULT_GUI_FONT), false); |
||
298 | SetWindowText (GetDlgItem (hWnd, WINDOW_TEXT_STATUSBAR), LOCALIZE (L"Opponents_StatusBar")); |
||
299 | |||
300 | // refresh the window every second |
||
301 | SetTimer (hWnd, WINDOW_TIMER_REFRESH, 1000, NULL); |
||
302 | |||
303 | // convert the status bar message to a hyperlink |
||
304 | ConvertStaticToHyperlink (GetDlgItem (hWnd, WINDOW_TEXT_STATUSBAR)); |
||
305 | |||
306 | // now show the window |
||
307 | ShowWindow (hWnd, SW_SHOW); |
||
308 | |||
309 | // and send focus to the player name filter field (note: GetDlgItem works ALSO with windows! MSDN certified :)) |
||
310 | if (GetForegroundWindow () == hWnd) |
||
311 | SetFocus (GetDlgItem (hWnd, WINDOW_EDITBOX_NAMECONTAINS)); |
||
312 | } |
||
313 | |||
314 | // else did we click the close button on the title bar ? |
||
315 | else if (message == WM_CLOSE) |
||
21 | pmbaty | 316 | DestroyWindow (hWnd); // close the window |
1 | pmbaty | 317 | |
318 | // else are we destroying this window ? |
||
319 | else if (message == WM_DESTROY) |
||
320 | { |
||
321 | KillTimer (hWnd, WINDOW_TIMER_REFRESH); // destroy the timer we used to refresh the window |
||
322 | hThisWnd = NULL; // window is closed |
||
323 | SetForegroundWindow (hMainWnd); // restore focus on the main window |
||
324 | is_window_opponents_validated = true; // remember we closed this window |
||
325 | } |
||
326 | |||
327 | // else are we resizing the window ? |
||
328 | else if (message == WM_SIZE) |
||
329 | { |
||
330 | // get the new window size |
||
331 | GetClientRect (hWnd, &client_rect); |
||
332 | |||
333 | SetWindowPos (GetDlgItem (hWnd, WINDOW_TEXT_DOUBLECLICKORNARROWDOWN), NULL, 16, 16, client_rect.right - 32, 16, SWP_NOZORDER); |
||
334 | SetWindowPos (GetDlgItem (hWnd, WINDOW_TEXT_NAMECONTAINS), NULL, 16, 40, 136, 16, SWP_NOZORDER); |
||
335 | SetWindowPos (GetDlgItem (hWnd, WINDOW_EDITBOX_NAMECONTAINS), NULL, 160, 38, 128, 20, SWP_NOZORDER); |
||
336 | SetWindowPos (GetDlgItem (hWnd, WINDOW_TEXT_STATUSIS), NULL, 288, 40, 88, 16, SWP_NOZORDER); |
||
337 | SetWindowPos (GetDlgItem (hWnd, WINDOW_COMBOBOX_STATUSIS), NULL, 384, 38, 128, 20, SWP_NOZORDER); |
||
338 | SetWindowPos (GetDlgItem (hWnd, WINDOW_TEXT_LEVELFROM), NULL, 512, 40, 120, 16, SWP_NOZORDER); |
||
339 | SetWindowPos (GetDlgItem (hWnd, WINDOW_EDITBOX_LEVELFROM), NULL, 640, 38, 48, 20, SWP_NOZORDER); |
||
340 | SetWindowPos (GetDlgItem (hWnd, WINDOW_TEXT_LEVELTO), NULL, 688, 40, 40, 16, SWP_NOZORDER); |
||
341 | SetWindowPos (GetDlgItem (hWnd, WINDOW_EDITBOX_LEVELTO), NULL, 736, 38, 48, 20, SWP_NOZORDER); |
||
342 | SetWindowPos (GetDlgItem (hWnd, WINDOW_LIST_OPPONENTS), NULL, 16, 64, client_rect.right - 32, client_rect.bottom - 80, SWP_NOZORDER); |
||
343 | SetWindowPos (GetDlgItem (hWnd, WINDOW_TEXT_STATUSBAR), NULL, 0, client_rect.bottom - 16, client_rect.right, 16, SWP_NOZORDER); |
||
344 | } |
||
345 | |||
346 | // else are we asking how big/small we can resize ? |
||
347 | else if (message == WM_GETMINMAXINFO) |
||
348 | { |
||
349 | minmax = (MINMAXINFO *) lParam; // get a pointer to the min/max info structure |
||
350 | |||
351 | minmax->ptMinTrackSize.x = WINDOW_MIN_WIDTH; |
||
352 | minmax->ptMinTrackSize.y = WINDOW_MIN_HEIGHT; |
||
353 | } |
||
354 | |||
355 | // else is it a timer event AND is it our refresh timer ? |
||
356 | else if ((message == WM_TIMER) && (wParam == WINDOW_TIMER_REFRESH)) |
||
357 | { |
||
358 | // do we need to update the opponents list ? |
||
359 | if (onlineplayers_updated) |
||
360 | { |
||
361 | hListWnd = GetDlgItem (hWnd, WINDOW_LIST_OPPONENTS); // get a quick access to the list control |
||
362 | |||
363 | // grab the different filters |
||
364 | GetDlgItemText (hWnd, WINDOW_EDITBOX_NAMECONTAINS, opponent_namecontains, WCHAR_SIZEOF (opponent_namecontains)); |
||
365 | opponent_statusis = ComboBox_GetCurSel (GetDlgItem (hWnd, WINDOW_COMBOBOX_STATUSIS)); |
||
366 | opponent_ratingfrom = GetDlgItemInt (hWnd, WINDOW_EDITBOX_LEVELFROM, &result, false); |
||
367 | opponent_ratingto = GetDlgItemInt (hWnd, WINDOW_EDITBOX_LEVELTO, &result, false); |
||
368 | if (result == 0) |
||
369 | opponent_ratingto = 9999; // if we couldn't read a number, set the default value |
||
370 | |||
371 | // populate the list control |
||
372 | ListView_DeleteAllItems (hListWnd); // start by emptying it first |
||
373 | displayed_count = 0; |
||
374 | |||
375 | // tell Windows which members of the LVCOLUMN structure we're filling |
||
376 | memset (&lvi, 0, sizeof (lvi)); |
||
377 | lvi.mask = LVIF_IMAGE | LVIF_PARAM; // we want to set the image and the item's pointer |
||
378 | for (onlineplayer_index = 0; onlineplayer_index < onlineplayer_count; onlineplayer_index++) |
||
379 | { |
||
380 | onlineplayer = &onlineplayers[onlineplayer_index]; // quick access to online player |
||
381 | |||
382 | // should item be skipped because of its name ? |
||
383 | if ((opponent_namecontains[0] != 0) && (wcsistr (onlineplayer->nickname, opponent_namecontains) == NULL)) |
||
384 | continue; // if so, skip it |
||
385 | |||
386 | // should item be skipped because of its status ? |
||
387 | if ((opponent_statusis == 1) && (onlineplayer->handlestatus != HANDLESTATUS_INGAME)) |
||
388 | continue; // if so, skip it |
||
389 | else if ((opponent_statusis == 2) && (onlineplayer->handlestatus != HANDLESTATUS_INSIMULATION)) |
||
390 | continue; // if so, skip it |
||
391 | else if ((opponent_statusis == 3) && (onlineplayer->handlestatus != HANDLESTATUS_INTOURNAMENT)) |
||
392 | continue; // if so, skip it |
||
393 | else if ((opponent_statusis == 4) && (onlineplayer->handlestatus != HANDLESTATUS_EXAMININGAGAME)) |
||
394 | continue; // if so, skip it |
||
395 | else if ((opponent_statusis == 5) && (onlineplayer->handlestatus != HANDLESTATUS_NOTOPENFORAMATCH)) |
||
396 | continue; // if so, skip it |
||
397 | else if ((opponent_statusis == 6) && (onlineplayer->handlestatus != HANDLESTATUS_INACTIVEORBUSY)) |
||
398 | continue; // if so, skip it |
||
399 | else if ((opponent_statusis == 7) && (onlineplayer->handlestatus != HANDLESTATUS_AVAILABLE)) |
||
400 | continue; // if so, skip it |
||
401 | |||
402 | // should it be skipped because of its rating (low value) ? |
||
403 | if (onlineplayer->rating < opponent_ratingfrom) |
||
404 | continue; // if so, skip it |
||
405 | else if (onlineplayer->rating > opponent_ratingto) |
||
406 | continue; // if so, skip it |
||
407 | |||
408 | // first, attach the right structure to this item |
||
409 | lvi.lParam = (LPARAM) onlineplayer; |
||
410 | |||
411 | // set item's image and name |
||
412 | lvi.iItem = onlineplayer_index; |
||
413 | lvi.iImage = listviewicons[onlineplayer->handlestatus]; |
||
414 | insert_index = ListView_InsertItem (hListWnd, &lvi); // add each item to list view |
||
415 | |||
416 | // set item's substrings |
||
417 | |||
418 | // nickname |
||
419 | ListView_SetItemText (hListWnd, insert_index, 0, onlineplayer->nickname); |
||
420 | |||
421 | // FIDE rank |
||
422 | if (onlineplayer->handlecodes & HANDLECODE_FIDEGREATMASTER) |
||
423 | ListView_SetItemText (hListWnd, insert_index, 1, STRING_FIDEGM) |
||
424 | else if (onlineplayer->handlecodes & HANDLECODE_FIDEINTERNATIONALMASTER) |
||
425 | ListView_SetItemText (hListWnd, insert_index, 1, STRING_FIDEIM) |
||
426 | else if (onlineplayer->handlecodes & HANDLECODE_FIDEMASTER) |
||
427 | ListView_SetItemText (hListWnd, insert_index, 1, L"M") |
||
428 | else if (onlineplayer->handlecodes & HANDLECODE_FIDEWOMENSGREATMASTER) |
||
429 | ListView_SetItemText (hListWnd, insert_index, 1, STRING_FIDEWGM) |
||
430 | else if (onlineplayer->handlecodes & HANDLECODE_FIDEWOMENSINTERNATIONALMASTER) |
||
431 | ListView_SetItemText (hListWnd, insert_index, 1, STRING_FIDEWIM) |
||
432 | |||
433 | // status |
||
434 | ListView_SetItemText (hListWnd, insert_index, 2, handlestatus[onlineplayer->handlestatus].text) |
||
435 | |||
436 | // rating |
||
437 | if (onlineplayer->ratingtype == OPPONENTRATINGTYPE_ESTIMATED) |
||
438 | swprintf_s (rating_string, WCHAR_SIZEOF (rating_string), L"%d (est.)", onlineplayer->rating); |
||
439 | else if (onlineplayer->ratingtype == OPPONENTRATINGTYPE_PROVISIONAL) |
||
440 | swprintf_s (rating_string, WCHAR_SIZEOF (rating_string), L"%d (prov.)", onlineplayer->rating); |
||
441 | else |
||
442 | swprintf_s (rating_string, WCHAR_SIZEOF (rating_string), L"%d", onlineplayer->rating); |
||
443 | ListView_SetItemText (hListWnd, insert_index, 3, rating_string); |
||
444 | |||
445 | // characteristics coulumns |
||
446 | if (onlineplayer->handlecodes & HANDLECODE_COMPUTER) |
||
447 | ListView_SetItemText (hListWnd, insert_index, 4, L"×"); |
||
448 | if (onlineplayer->handlecodes & HANDLECODE_ADMINISTRATOR) |
||
449 | ListView_SetItemText (hListWnd, insert_index, 5, L"×"); |
||
450 | if (onlineplayer->handlecodes & HANDLECODE_BLINDFOLD) |
||
451 | ListView_SetItemText (hListWnd, insert_index, 6, L"×"); |
||
452 | if (onlineplayer->handlecodes & HANDLECODE_TEAM) |
||
453 | ListView_SetItemText (hListWnd, insert_index, 7, L"×"); |
||
454 | if (onlineplayer->handlecodes & HANDLECODE_CHESSADVISOR) |
||
455 | ListView_SetItemText (hListWnd, insert_index, 8, L"×"); |
||
456 | if (onlineplayer->handlecodes & HANDLECODE_SERVICEREPRESENTATIVE) |
||
457 | ListView_SetItemText (hListWnd, insert_index, 9, L"×"); |
||
458 | if (onlineplayer->handlecodes & HANDLECODE_TOURNAMENTDIRECTOR) |
||
459 | ListView_SetItemText (hListWnd, insert_index, 10, L"×"); |
||
460 | if (onlineplayer->handlecodes & HANDLECODE_MAMERMANAGER) |
||
461 | ListView_SetItemText (hListWnd, insert_index, 11, L"×"); |
||
462 | if (onlineplayer->handlecodes & HANDLECODE_UNREGISTERED) |
||
463 | ListView_SetItemText (hListWnd, insert_index, 12, L"×"); |
||
464 | |||
465 | displayed_count++; // we displayed now one player more |
||
466 | } |
||
467 | |||
468 | // now sort the list view according to the column we selected and its current sort order |
||
469 | ListView_SortItems (hListWnd, CompareProc_ListOpponents, current_sortcolumn); |
||
470 | |||
471 | // cycle through all columns and reset their sort order |
||
472 | for (column_index = 0; column_index < sizeof (listviewcolumns) / sizeof (listviewcolumn_t); column_index++) |
||
473 | { |
||
474 | memset (&hdi, 0, sizeof (hdi)); |
||
475 | hdi.mask = HDI_FORMAT; |
||
476 | Header_GetItem (ListView_GetHeader (hListWnd), column_index, &hdi); // get the column's sort arrow state |
||
477 | hdi.fmt &= ~(HDF_SORTDOWN | HDF_SORTUP); |
||
478 | if (column_index == current_sortcolumn) |
||
479 | hdi.fmt |= (listviewcolumns[column_index].sort_descending ? HDF_SORTDOWN : HDF_SORTUP); |
||
480 | Header_SetItem (ListView_GetHeader (hListWnd), column_index, &hdi); // update the column's sort arrow state |
||
481 | } |
||
482 | |||
483 | // now that the display is finished, IF the reply is arrived, set the totals in the window title |
||
484 | if (onlineplayer_count >= 0) |
||
485 | { |
||
486 | swprintf_s (window_title, WCHAR_SIZEOF (window_title), LOCALIZE (L"Opponents_Title"), onlineplayer_count, displayed_count); |
||
487 | SetWindowText (hWnd, window_title); |
||
488 | } |
||
489 | |||
490 | onlineplayers_updated = false; // remember we updated the list (don't do it twice) |
||
491 | } |
||
492 | } |
||
493 | |||
494 | // is it a list view message ? |
||
495 | else if ((message == WM_NOTIFY) && (wParam == WINDOW_LIST_OPPONENTS)) |
||
496 | { |
||
497 | lv = (NMLISTVIEW *) lParam; // quick access to list view |
||
498 | |||
499 | // is it a click on one of the headers' columns ? |
||
500 | if (lv->hdr.code == LVN_COLUMNCLICK) |
||
501 | { |
||
502 | // cycle through all columns and reset their sort order |
||
503 | for (column_index = 0; column_index < sizeof (listviewcolumns) / sizeof (listviewcolumn_t); column_index++) |
||
504 | { |
||
505 | memset (&hdi, 0, sizeof (hdi)); |
||
506 | hdi.mask = HDI_FORMAT; |
||
507 | Header_GetItem (ListView_GetHeader (lv->hdr.hwndFrom), column_index, &hdi); // get the column's sort arrow state |
||
508 | hdi.fmt &= ~(HDF_SORTDOWN | HDF_SORTUP); |
||
509 | if (column_index == lv->iSubItem) |
||
510 | { |
||
511 | listviewcolumns[column_index].sort_descending ^= true; // revert the sort order for the clicked column |
||
512 | hdi.fmt |= (listviewcolumns[column_index].sort_descending ? HDF_SORTDOWN : HDF_SORTUP); |
||
513 | current_sortcolumn = column_index; // save the current sort column |
||
514 | } |
||
515 | else |
||
516 | listviewcolumns[column_index].sort_descending = false; // reset the sort order for all the other ones |
||
517 | Header_SetItem (ListView_GetHeader (lv->hdr.hwndFrom), column_index, &hdi); // update the column's sort arrow state |
||
518 | } |
||
519 | |||
520 | // now sort the list view according to the column we selected and its current sort order |
||
521 | ListView_SortItems (lv->hdr.hwndFrom, CompareProc_ListOpponents, lv->iSubItem); |
||
522 | } |
||
523 | |||
524 | // else is it a double-click on one of the elements ? |
||
525 | else if (lv->hdr.code == NM_DBLCLK) |
||
526 | { |
||
527 | clickeditem = (NMITEMACTIVATE *) lParam; // get the item it is |
||
528 | |||
529 | // is it valid ? |
||
530 | if (clickeditem->iItem != -1) |
||
531 | { |
||
532 | // get which item it is in the listview data |
||
533 | memset (&lvi, 0, sizeof (lvi)); |
||
534 | lvi.iItem = clickeditem->iItem; |
||
535 | lvi.mask = LVIF_PARAM; |
||
536 | ListView_GetItem (lv->hdr.hwndFrom, &lvi); |
||
537 | |||
538 | onlineplayer = (onlineplayer_t *) lvi.lParam; // get the online player it is |
||
539 | |||
540 | local_player = Player_FindByType (PLAYER_HUMAN); // find the local player |
||
541 | |||
542 | // is it NOT ourselves ? if so, find or create an interlocutor structure for this cc member |
||
543 | if ((local_player != NULL) && (wcscmp (onlineplayer->nickname, local_player->name) != 0)) |
||
544 | Interlocutor_FindOrCreate (onlineplayer->nickname); |
||
545 | else |
||
546 | PlayerCard_FindOrCreate (onlineplayer->nickname); // else just display his player card |
||
547 | } |
||
548 | } |
||
549 | } |
||
550 | |||
551 | // else did we take action on one of the controls ? |
||
552 | else if (message == WM_COMMAND) |
||
553 | { |
||
554 | // was the name edit box changed ? |
||
555 | if ((wParam_loword == WINDOW_EDITBOX_NAMECONTAINS) && (wParam_hiword == EN_CHANGE)) |
||
556 | { |
||
557 | onlineplayers_updated = true; // remember online player list is to be updated |
||
558 | SendMessage (hWnd, WM_TIMER, WINDOW_TIMER_REFRESH, NULL); // refresh window now |
||
559 | } |
||
560 | |||
561 | // else was the filter combo box changed ? |
||
562 | else if ((wParam_loword == WINDOW_COMBOBOX_STATUSIS) && (wParam_hiword == CBN_SELCHANGE)) |
||
563 | { |
||
564 | onlineplayers_updated = true; // remember online player list is to be updated |
||
565 | SendMessage (hWnd, WM_TIMER, WINDOW_TIMER_REFRESH, NULL); // refresh window now |
||
566 | } |
||
567 | |||
568 | // else was either of the rating edit box changed ? |
||
569 | else if ((wParam_loword == WINDOW_EDITBOX_LEVELFROM) && (wParam_hiword == EN_CHANGE)) |
||
570 | { |
||
571 | onlineplayers_updated = true; // remember online player list is to be updated |
||
572 | SendMessage (hWnd, WM_TIMER, WINDOW_TIMER_REFRESH, NULL); // refresh window now |
||
573 | } |
||
574 | else if ((wParam_loword == WINDOW_EDITBOX_LEVELTO) && (wParam_hiword == EN_CHANGE)) |
||
575 | { |
||
576 | onlineplayers_updated = true; // remember online player list is to be updated |
||
577 | SendMessage (hWnd, WM_TIMER, WINDOW_TIMER_REFRESH, NULL); // refresh window now |
||
578 | } |
||
579 | |||
580 | // else was it the status bar hyperlink ? |
||
581 | else if (wParam_loword == WINDOW_TEXT_STATUSBAR) |
||
582 | ShellExecute (NULL, L"open", PROGRAM_URL, NULL, NULL, SW_MAXIMIZE); // open the donation page in the default browser, maximized |
||
583 | } |
||
584 | |||
585 | // call the default window message processing function to keep things going |
||
586 | return (DefWindowProc (hWnd, message, wParam, lParam)); |
||
587 | } |
||
588 | |||
589 | |||
590 | static int CALLBACK CompareProc_ListOpponents (LPARAM lParam1, LPARAM lParam2, LPARAM column) |
||
591 | { |
||
592 | // callback function that tells whether the lParam1 listview element comes before lParam2 in the |
||
593 | // sort order of the specified column |
||
594 | |||
595 | wchar_t *string_to_compare1; |
||
596 | wchar_t *string_to_compare2; |
||
597 | |||
598 | // nickname |
||
599 | if (column == 0) |
||
600 | { |
||
601 | string_to_compare1 = ((onlineplayer_t *) lParam1)->nickname; |
||
602 | string_to_compare2 = ((onlineplayer_t *) lParam2)->nickname; |
||
603 | } |
||
604 | |||
605 | // FIDE rank |
||
606 | else if (column == 1) |
||
607 | { |
||
608 | if (((onlineplayer_t *) lParam1)->handlecodes & HANDLECODE_FIDEGREATMASTER) |
||
609 | string_to_compare1 = STRING_FIDEGM; |
||
610 | else if (((onlineplayer_t *) lParam1)->handlecodes & HANDLECODE_FIDEINTERNATIONALMASTER) |
||
611 | string_to_compare1 = STRING_FIDEIM; |
||
612 | else if (((onlineplayer_t *) lParam1)->handlecodes & HANDLECODE_FIDEMASTER) |
||
613 | string_to_compare1 = L"M"; |
||
614 | else if (((onlineplayer_t *) lParam1)->handlecodes & HANDLECODE_FIDEWOMENSGREATMASTER) |
||
615 | string_to_compare1 = STRING_FIDEWGM; |
||
616 | else if (((onlineplayer_t *) lParam1)->handlecodes & HANDLECODE_FIDEWOMENSINTERNATIONALMASTER) |
||
617 | string_to_compare1 = STRING_FIDEWIM; |
||
618 | else |
||
619 | string_to_compare1 = L""; |
||
620 | |||
621 | if (((onlineplayer_t *) lParam2)->handlecodes & HANDLECODE_FIDEGREATMASTER) |
||
622 | string_to_compare2 = STRING_FIDEGM; |
||
623 | else if (((onlineplayer_t *) lParam2)->handlecodes & HANDLECODE_FIDEINTERNATIONALMASTER) |
||
624 | string_to_compare2 = STRING_FIDEIM; |
||
625 | else if (((onlineplayer_t *) lParam2)->handlecodes & HANDLECODE_FIDEMASTER) |
||
626 | string_to_compare2 = L"M"; |
||
627 | else if (((onlineplayer_t *) lParam2)->handlecodes & HANDLECODE_FIDEWOMENSGREATMASTER) |
||
628 | string_to_compare2 = STRING_FIDEWGM; |
||
629 | else if (((onlineplayer_t *) lParam2)->handlecodes & HANDLECODE_FIDEWOMENSINTERNATIONALMASTER) |
||
630 | string_to_compare2 = STRING_FIDEWIM; |
||
631 | else |
||
632 | string_to_compare2 = L""; |
||
633 | } |
||
634 | |||
635 | // status |
||
636 | else if (column == 2) |
||
637 | { |
||
638 | string_to_compare1 = handlestatus[((onlineplayer_t *) lParam1)->handlestatus].text; |
||
639 | string_to_compare2 = handlestatus[((onlineplayer_t *) lParam2)->handlestatus].text; |
||
640 | } |
||
641 | |||
642 | // FIDE rating |
||
643 | else if (column == 3) |
||
644 | { |
||
645 | if (listviewcolumns[column].sort_descending) |
||
646 | return (((onlineplayer_t *) lParam1)->rating <= ((onlineplayer_t *) lParam2)->rating); |
||
647 | else |
||
648 | return (((onlineplayer_t *) lParam1)->rating >= ((onlineplayer_t *) lParam2)->rating); |
||
649 | } |
||
650 | |||
651 | #define ELSE_IF_COLUMN_SORT_BY_FLAG(col,flag) \ |
||
652 | else if (column == (col)) \ |
||
653 | { \ |
||
654 | string_to_compare1 = (((onlineplayer_t *) lParam1)->handlecodes & (flag) ? L"×" : L" "); \ |
||
655 | string_to_compare2 = (((onlineplayer_t *) lParam2)->handlecodes & (flag) ? L"×" : L" "); \ |
||
656 | } |
||
657 | |||
658 | ELSE_IF_COLUMN_SORT_BY_FLAG (4, HANDLECODE_COMPUTER) |
||
659 | ELSE_IF_COLUMN_SORT_BY_FLAG (5, HANDLECODE_ADMINISTRATOR) |
||
660 | ELSE_IF_COLUMN_SORT_BY_FLAG (6, HANDLECODE_BLINDFOLD) |
||
661 | ELSE_IF_COLUMN_SORT_BY_FLAG (7, HANDLECODE_TEAM) |
||
662 | ELSE_IF_COLUMN_SORT_BY_FLAG (8, HANDLECODE_CHESSADVISOR) |
||
663 | ELSE_IF_COLUMN_SORT_BY_FLAG (9, HANDLECODE_SERVICEREPRESENTATIVE) |
||
664 | ELSE_IF_COLUMN_SORT_BY_FLAG (10, HANDLECODE_TOURNAMENTDIRECTOR) |
||
665 | ELSE_IF_COLUMN_SORT_BY_FLAG (11, HANDLECODE_MAMERMANAGER) |
||
666 | ELSE_IF_COLUMN_SORT_BY_FLAG (12, HANDLECODE_UNREGISTERED) |
||
667 | |||
668 | #undef ELSE_IF_COLUMN_SORT_BY_FLAG |
||
669 | |||
670 | // which order do we want this column to be sorted ? |
||
671 | if (listviewcolumns[column].sort_descending) |
||
672 | return (_wcsicmp (string_to_compare1, string_to_compare2)); // normal order |
||
673 | else |
||
674 | return (-_wcsicmp (string_to_compare1, string_to_compare2)); // reverse order |
||
675 | } |
||
676 | |||
677 | |||
678 | static int WINAPI ListView_WndProc (HWND hWnd, unsigned int message, WPARAM wParam, LPARAM lParam) |
||
679 | { |
||
680 | // callback that subclasses the original ListView window procedure, so that we can hook |
||
681 | // some of its messages |
||
682 | |||
683 | static bool tooltips_initialized = false; |
||
684 | static bool update_tooltips = false; |
||
685 | WNDPROC BaseWndProc; |
||
686 | TOOLINFO toolinfo; |
||
687 | HWND hHeaderWnd; |
||
688 | int column_index; |
||
689 | |||
690 | // get a pointer to the base window procedure (it was stored as a window property) |
||
691 | BaseWndProc = (WNDPROC) GetProp (hWnd, L"BaseWndProc"); |
||
692 | if (BaseWndProc == NULL) |
||
693 | return (DefWindowProc (hWnd, message, wParam, lParam)); // consistency check |
||
694 | |||
695 | // is the mouse moving around ? |
||
696 | if (message == WM_MOUSEMOVE) |
||
697 | { |
||
698 | // do the tooltips need to be created ? |
||
699 | if (!tooltips_initialized) |
||
700 | { |
||
701 | hHeaderWnd = (HWND) SendMessage (hWnd, LVM_GETHEADER, 0, 0); // get listview header |
||
702 | |||
703 | // add a tooltip for each column |
||
704 | for (column_index = 0; column_index < sizeof (listviewcolumns) / sizeof (listviewcolumn_t); column_index++) |
||
705 | { |
||
706 | // create the tooltip and set its window topmost |
||
707 | listviewcolumns[column_index].hToolTipWnd = CreateWindowEx (WS_EX_TOPMOST, TOOLTIPS_CLASS, NULL, WS_POPUP | TTS_NOPREFIX | TTS_ALWAYSTIP, |
||
708 | CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, |
||
709 | hHeaderWnd, NULL, hAppInstance, NULL); |
||
710 | |||
711 | // associate the tooltip with the tool |
||
712 | memset (&toolinfo, 0, sizeof (toolinfo)); |
||
713 | toolinfo.cbSize = sizeof (toolinfo); |
||
714 | toolinfo.uFlags = TTF_SUBCLASS; |
||
715 | toolinfo.hwnd = hHeaderWnd; // this tooltip works on the list header window handle |
||
716 | toolinfo.uId = column_index; // tooltip ID will be column ID |
||
717 | toolinfo.hinst = hAppInstance; |
||
718 | toolinfo.lpszText = listviewcolumns[column_index].text; // tooltip text |
||
719 | Header_GetItemRect (hHeaderWnd, column_index, &toolinfo.rect); // get header's item rectangle |
||
720 | SendMessage (listviewcolumns[column_index].hToolTipWnd, TTM_ADDTOOL, 0, (LPARAM) &toolinfo); |
||
721 | } |
||
722 | |||
723 | tooltips_initialized = true; // do this only once |
||
724 | } |
||
725 | |||
726 | // else do the tooltips need to be updated ? |
||
727 | else if (update_tooltips) |
||
728 | { |
||
729 | hHeaderWnd = (HWND) SendMessage (hWnd, LVM_GETHEADER, 0, 0); // get listview header |
||
730 | |||
731 | // cycle through all columns |
||
732 | for (column_index = 0; column_index < sizeof (listviewcolumns) / sizeof (listviewcolumn_t); column_index++) |
||
733 | { |
||
734 | // update the tooltip rectangle |
||
735 | memset (&toolinfo, 0, sizeof (toolinfo)); |
||
736 | toolinfo.cbSize = sizeof (toolinfo); |
||
737 | toolinfo.hwnd = hHeaderWnd; // this tooltip works on the list header window handle |
||
738 | toolinfo.uId = column_index; // tooltip ID is column ID |
||
739 | Header_GetItemRect (hHeaderWnd, column_index, &toolinfo.rect); // get header's item rectangle |
||
740 | SendMessage (listviewcolumns[column_index].hToolTipWnd, TTM_NEWTOOLRECT, 0, (LPARAM) &toolinfo); |
||
741 | } |
||
742 | |||
743 | update_tooltips = false; // do this only once |
||
744 | } |
||
745 | } |
||
746 | |||
747 | // else has the user finished dragging/resizing a column header ? |
||
748 | else if ((message == WM_NOTIFY) && ((((NMHDR *) lParam)->code == HDN_ENDTRACK) || (((NMHDR *) lParam)->code == HDN_ENDDRAG))) |
||
749 | update_tooltips = true; // if so, remember to update tooltips on the next mouse move |
||
750 | |||
751 | // in any case, forward all messages to the original ListView hook procedure |
||
752 | return (CallWindowProc (BaseWndProc, hWnd, message, wParam, lParam)); |
||
753 | } |