Mercurial > mplayer.hg
annotate gui/win32/gui.c @ 35501:7bb176fac55c
Use boolean symbolic constants in Win32 GUI.
Use them wherever suitable and useful to make code easier to read.
author | ib |
---|---|
date | Tue, 04 Dec 2012 20:06:43 +0000 |
parents | f42cc2361ee4 |
children | baf53d200292 |
rev | line source |
---|---|
23077 | 1 /* |
23079 | 2 * MPlayer GUI for Win32 |
3 * Copyright (C) 2003 Sascha Sommer <saschasommer@freenet.de> | |
4 * Copyright (C) 2006 Erik Augustson <erik_27can@yahoo.com> | |
5 * Copyright (C) 2006 Gianluigi Tiesi <sherpya@netfarm.it> | |
6 * | |
7 * This file is part of MPlayer. | |
8 * | |
9 * MPlayer is free software; you can redistribute it and/or modify | |
10 * it under the terms of the GNU General Public License as published by | |
11 * the Free Software Foundation; either version 2 of the License, or | |
12 * (at your option) any later version. | |
13 * | |
14 * MPlayer is distributed in the hope that it will be useful, | |
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 * GNU General Public License for more details. | |
18 * | |
26457 | 19 * You should have received a copy of the GNU General Public License along |
20 * with MPlayer; if not, write to the Free Software Foundation, Inc., | |
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
23079 | 22 */ |
23077 | 23 |
24 #include <stdio.h> | |
25 #include <stdlib.h> | |
26 #include <ctype.h> | |
27 #include <fcntl.h> | |
28 #include <windows.h> | |
29 #include <windowsx.h> | |
30 #include <shlobj.h> | |
23091
52488bb09d90
Consistently use quotes instead of angled brackets in #include
diego
parents:
23079
diff
changeset
|
31 |
35450 | 32 #include "config.h" |
31511
13ca93203358
Factorize MPlayer/MEncoder version string handling.
diego
parents:
30684
diff
changeset
|
33 #include "mpcommon.h" |
23091
52488bb09d90
Consistently use quotes instead of angled brackets in #include
diego
parents:
23079
diff
changeset
|
34 #include "mplayer.h" |
52488bb09d90
Consistently use quotes instead of angled brackets in #include
diego
parents:
23079
diff
changeset
|
35 #include "mp_fifo.h" |
52488bb09d90
Consistently use quotes instead of angled brackets in #include
diego
parents:
23079
diff
changeset
|
36 #include "mp_msg.h" |
52488bb09d90
Consistently use quotes instead of angled brackets in #include
diego
parents:
23079
diff
changeset
|
37 #include "help_mp.h" |
52488bb09d90
Consistently use quotes instead of angled brackets in #include
diego
parents:
23079
diff
changeset
|
38 #include "input/input.h" |
52488bb09d90
Consistently use quotes instead of angled brackets in #include
diego
parents:
23079
diff
changeset
|
39 #include "input/mouse.h" |
52488bb09d90
Consistently use quotes instead of angled brackets in #include
diego
parents:
23079
diff
changeset
|
40 #include "osdep/keycodes.h" |
52488bb09d90
Consistently use quotes instead of angled brackets in #include
diego
parents:
23079
diff
changeset
|
41 #include "stream/stream.h" |
52488bb09d90
Consistently use quotes instead of angled brackets in #include
diego
parents:
23079
diff
changeset
|
42 #include "libvo/video_out.h" |
30684
dc7ed18ea0df
Include libmpcodecs/vd.h for declaration of "fullscreen".
zuxy
parents:
30558
diff
changeset
|
43 #include "libmpcodecs/vd.h" |
26372
76413880bfad
Update include paths to account for build system changes.
diego
parents:
26193
diff
changeset
|
44 #include "gui/interface.h" |
33761 | 45 #include "gui/ui/actions.h" |
33557 | 46 #include "gui/ui/gmplayer.h" |
33770 | 47 #include "gui/util/mem.h" |
23077 | 48 #include "gui.h" |
49 #include "dialogs.h" | |
33965 | 50 #include "version.h" |
23077 | 51 |
34684 | 52 /* HACK around bug in old mingw */ |
23077 | 53 #undef INVALID_FILE_ATTRIBUTES |
54 #define INVALID_FILE_ATTRIBUTES ((DWORD)-1) | |
55 | |
56 #ifndef WM_XBUTTONDOWN | |
57 # define WM_XBUTTONDOWN 0x020B | |
58 # define WM_XBUTTONUP 0x020C | |
59 # define WM_XBUTTONDBLCLK 0x020D | |
60 #endif | |
61 | |
62 /* Globals / Externs */ | |
34697 | 63 float video_aspect; |
23077 | 64 |
65 DWORD oldtime; | |
66 NOTIFYICONDATA nid; | |
35501 | 67 int console_state = FALSE; |
23077 | 68 play_tree_t *playtree = NULL; |
69 | |
70 static HBRUSH colorbrush = NULL; //Handle to colorkey brush | |
71 static COLORREF windowcolor = RGB(255,0,255); //Windowcolor == colorkey | |
72 | |
34163 | 73 /** |
74 * @brief Convert an UTF-8 encoded string into ANSI codepage encoding. | |
75 * | |
76 * @param utf8 UTF-8 encoded string | |
77 * | |
78 * @return string containing ANSI codepage encoding of @a utf8 (or, in case | |
79 * of error, a string containing the question mark character) | |
80 */ | |
81 LPSTR acp (LPCSTR utf8) | |
82 { | |
83 static LPSTR acp_str = NULL; | |
84 int chars; | |
85 LPWSTR uc_str; | |
86 | |
87 chars = MultiByteToWideChar(CP_UTF8, 0, utf8, -1, NULL, 0); | |
88 | |
89 if (chars) | |
90 { | |
91 uc_str = malloc(sizeof(*uc_str) * (chars + 1)); | |
92 | |
93 if (uc_str) | |
94 { | |
95 MultiByteToWideChar(CP_UTF8, 0, utf8, -1, uc_str, chars); | |
96 | |
97 chars = WideCharToMultiByte(CP_ACP, 0, uc_str, -1, NULL, 0, NULL, 0); | |
98 | |
99 if (chars) | |
100 { | |
101 free(acp_str); | |
102 acp_str = malloc(sizeof(*acp_str) * (chars + 1)); | |
103 | |
104 if (acp_str) | |
105 { | |
106 WideCharToMultiByte(CP_ACP, 0, uc_str, -1, acp_str, chars, NULL, 0); | |
107 free(uc_str); | |
108 | |
109 return acp_str; | |
110 } | |
111 } | |
112 | |
113 free(uc_str); | |
114 } | |
115 } | |
116 | |
117 return "?"; | |
118 } | |
119 | |
35001 | 120 static void console_toggle(gui_t *gui) |
23077 | 121 { |
122 if (console_state) | |
123 { | |
124 FreeConsole(); | |
35501 | 125 console = FALSE; |
126 console_state = FALSE; | |
23077 | 127 } |
128 else | |
129 { | |
130 /* This code comes from: http://dslweb.nwnexus.com/~ast/dload/guicon.htm */ | |
131 CONSOLE_SCREEN_BUFFER_INFO coninfo; | |
132 FILE *fp; | |
133 HWND hwnd = NULL; | |
35501 | 134 console = TRUE; |
23077 | 135 AllocConsole(); |
31511
13ca93203358
Factorize MPlayer/MEncoder version string handling.
diego
parents:
30684
diff
changeset
|
136 SetConsoleTitle(mplayer_version); |
23077 | 137 |
138 /* disable the close button for now */ | |
139 while (!hwnd) | |
140 { | |
31511
13ca93203358
Factorize MPlayer/MEncoder version string handling.
diego
parents:
30684
diff
changeset
|
141 hwnd = FindWindow(NULL, mplayer_version); |
23077 | 142 Sleep(100); |
143 } | |
144 DeleteMenu(GetSystemMenu(hwnd, 0), SC_CLOSE, MF_BYCOMMAND); | |
145 | |
146 GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &coninfo); | |
147 coninfo.dwSize.Y = 1000; | |
148 SetConsoleScreenBufferSize(GetStdHandle(STD_OUTPUT_HANDLE), coninfo.dwSize); | |
149 fp = freopen("con", "w", stdout); | |
150 *stdout = *fp; | |
151 setvbuf(stdout, NULL, _IONBF, 0); | |
152 fp = freopen("con", "r", stdin); | |
153 *stdin = *fp; | |
154 setvbuf(stdin, NULL, _IONBF, 0); | |
155 fp = freopen("con", "w", stdout); | |
156 *stderr = *fp; | |
157 setvbuf(stderr, NULL, _IONBF, 0); | |
31532 | 158 print_version("MPlayer"); |
35501 | 159 console_state = TRUE; |
23077 | 160 } |
35002
64d72a128ea8
Rewrite condition and use console_state instead of console.
ib
parents:
35001
diff
changeset
|
161 |
64d72a128ea8
Rewrite condition and use console_state instead of console.
ib
parents:
35001
diff
changeset
|
162 if (gui) |
64d72a128ea8
Rewrite condition and use console_state instead of console.
ib
parents:
35001
diff
changeset
|
163 { |
64d72a128ea8
Rewrite condition and use console_state instead of console.
ib
parents:
35001
diff
changeset
|
164 CheckMenuItem(gui->traymenu, ID_CONSOLE, MF_BYCOMMAND | (console_state ? MF_CHECKED : MF_UNCHECKED)); |
64d72a128ea8
Rewrite condition and use console_state instead of console.
ib
parents:
35001
diff
changeset
|
165 CheckMenuItem(gui->menu, ID_CONSOLE, MF_BYCOMMAND | (console_state ? MF_CHECKED : MF_UNCHECKED)); |
64d72a128ea8
Rewrite condition and use console_state instead of console.
ib
parents:
35001
diff
changeset
|
166 } |
23077 | 167 } |
168 | |
169 void capitalize(char *filename) | |
170 { | |
171 unsigned int i; | |
172 BOOL cap = TRUE; | |
173 for (i=0; i < strlen(filename); i++) | |
174 { | |
175 if (cap) | |
176 { | |
177 cap = FALSE; | |
178 filename[i] = toupper(filename[i]); | |
179 } | |
180 else if (filename[i] == ' ') | |
181 cap = TRUE; | |
182 else | |
183 filename[i] = tolower(filename[i]); | |
184 } | |
185 } | |
33965 | 186 static void display_about_box(HWND hWnd) |
187 { | |
188 char about_msg[512]; | |
189 snprintf(about_msg, sizeof(about_msg), MP_TITLE "\n" COPYRIGHT, "MPlayer"); | |
34163 | 190 MessageBox(hWnd, about_msg, acp(MSGTR_About), MB_OK); |
33965 | 191 } |
23077 | 192 |
193 static image *get_drawground(HWND hwnd) | |
194 { | |
195 gui_t * gui = (gui_t *) GetWindowLongPtr(hwnd, GWLP_USERDATA); | |
196 unsigned int i; | |
197 if(!gui) return NULL; | |
198 for(i=0; i<gui->window_priv_count; i++) | |
199 if(gui->window_priv[i]->hwnd==hwnd) | |
200 return &gui->window_priv[i]->img; | |
201 return NULL; | |
202 } | |
203 | |
204 static HBITMAP get_bitmap(HWND hwnd) | |
205 { | |
206 gui_t *gui = (gui_t *) GetWindowLongPtr(hwnd, GWLP_USERDATA); | |
207 unsigned int i; | |
208 if(!gui) return NULL; | |
209 for(i=0; i<gui->window_priv_count; i++) | |
210 if(gui->window_priv[i]->hwnd == hwnd) | |
211 return gui->window_priv[i]->bitmap; | |
212 return NULL; | |
213 } | |
214 | |
215 static int get_windowtype(HWND hwnd) | |
216 { | |
217 gui_t *gui = (gui_t *) GetWindowLongPtr(hwnd, GWLP_USERDATA); | |
218 unsigned int i; | |
219 if(!gui) return -1; | |
220 for(i=0; i<gui->window_priv_count; i++) | |
221 if(gui->window_priv[i]->hwnd == hwnd) | |
222 return gui->window_priv[i]->type; | |
223 return -1; | |
224 } | |
225 | |
226 static void uninit(gui_t *gui) | |
227 { | |
228 if(gui->skin) destroy_window(gui); | |
229 if(gui->playlist) gui->playlist->free_playlist(gui->playlist); | |
230 gui->playlist = NULL; | |
231 } | |
232 | |
233 /* | |
234 the gui message handler | |
235 tries to handle the incoming messages | |
236 and passes them to the player's message handler if it can't handle them | |
237 */ | |
238 static void handlemsg(HWND hWnd, int msg) | |
239 { | |
240 gui_t *gui = (gui_t *) GetWindowLongPtr(hWnd, GWLP_USERDATA); | |
241 if(msg == evNone) return; | |
242 | |
243 switch(msg) | |
244 { | |
245 case evLoadPlay: | |
246 case evLoad: | |
247 if(display_openfilewindow(gui, 0) && (msg == evLoadPlay)) | |
34325 | 248 gui->playercontrol(evLoadPlay); |
23077 | 249 return; |
250 case evLoadSubtitle: | |
251 display_opensubtitlewindow(gui); | |
252 break; | |
253 case evPreferences: | |
254 display_prefswindow(gui); | |
255 return; | |
34321
daebf766dea6
Cosmetic: Synchronize evPlaylist event and message names.
ib
parents:
34315
diff
changeset
|
256 case evPlaylist: |
23077 | 257 display_playlistwindow(gui); |
258 return; | |
259 case evSkinBrowser: | |
260 display_skinbrowser(gui); | |
261 break; | |
262 case evEqualizer: | |
263 display_eqwindow(gui); | |
264 break; | |
265 case evAbout: | |
33965 | 266 display_about_box(hWnd); |
23077 | 267 break; |
268 case evIconify: | |
269 ShowWindow(hWnd, SW_MINIMIZE); | |
270 break; | |
271 case evIncVolume: | |
272 mplayer_put_key(KEY_VOLUME_UP); | |
273 break; | |
274 case evDecVolume: | |
275 mplayer_put_key(KEY_VOLUME_DOWN); | |
276 break; | |
277 default: | |
278 mp_msg(MSGT_GPLAYER, MSGL_V, "[GUI] received msg %s (%i)\n", gui->skin->geteventname(msg), msg); | |
279 break; | |
280 } | |
281 gui->playercontrol(msg); | |
282 } | |
283 | |
284 static widget *clickedinsidewidget(gui_t *gui, int window, int x, int y) | |
285 { | |
286 unsigned int i; | |
287 widget *item; | |
288 for(i=0; i<gui->skin->widgetcount; i++) | |
289 { | |
290 item = gui->skin->widgets[i]; | |
291 if((item->window == window) && (item->x <= x) && (item->x + item->width >= x) && | |
292 (item->y <= y) && (item->y + item->height >= y)) | |
293 return item; | |
294 } | |
295 return NULL; | |
296 } | |
297 | |
298 /* updates sliders and the display */ | |
299 static void updatedisplay(gui_t *gui, HWND hwnd) | |
300 { | |
301 unsigned int i; | |
302 window_priv_t *priv = NULL; | |
303 DWORD time = timeGetTime(); | |
304 | |
305 if(!hwnd) return; | |
306 | |
307 /* load all potmeters hpotmeters */ | |
308 for(i=0; i<gui->skin->widgetcount; i++) | |
309 { | |
310 if(gui->skin->widgets[i]->type == tyHpotmeter || gui->skin->widgets[i]->type == tyPotmeter) | |
311 { | |
312 if(gui->skin->widgets[i]->msg == evSetVolume) | |
33555 | 313 gui->skin->widgets[i]->value = guiInfo.Volume; |
23077 | 314 else if(gui->skin->widgets[i]->msg == evSetMoviePosition) |
33555 | 315 gui->skin->widgets[i]->value = guiInfo.Position; |
23077 | 316 else if(gui->skin->widgets[i]->msg == evSetBalance) |
33555 | 317 gui->skin->widgets[i]->value = guiInfo.Balance; |
23077 | 318 if(gui->skin->widgets[i]->window == get_windowtype(hwnd)) |
319 renderwidget(gui->skin, get_drawground(hwnd), gui->skin->widgets[i], | |
320 gui->skin->widgets[i]->pressed ? 0 : 1); | |
321 } | |
322 /* update some buttons */ | |
323 if(gui->skin->widgets[i]->type == tyButton && gui->skin->widgets[i]->window == get_windowtype(hwnd)) | |
324 { | |
325 if(gui->skin->widgets[i]->msg == evPlaySwitchToPause) | |
326 { | |
33555 | 327 gui->skin->widgets[i]->value = guiInfo.Playing; |
23077 | 328 renderwidget(gui->skin, get_drawground(hwnd), gui->skin->widgets[i], |
33615
1f9a31d4f114
Replace all playback integer constants by their symbolic constants.
ib
parents:
33580
diff
changeset
|
329 guiInfo.Playing == GUI_PLAY ? 0 : 1); |
23077 | 330 } |
331 if(gui->skin->widgets[i]->msg == evMute) | |
332 { | |
33555 | 333 gui->skin->widgets[i]->value = guiInfo.Volume; |
23077 | 334 renderwidget(gui->skin, get_drawground(hwnd), gui->skin->widgets[i], |
33555 | 335 guiInfo.Volume == 0.0f ? 0 : 1); |
23077 | 336 } |
337 } | |
338 } | |
339 | |
340 /* updating the display once a 100.second is enough imo */ | |
341 if((time - oldtime) < 100) return; | |
342 oldtime=time; | |
343 | |
344 for (i=0; i<gui->window_priv_count; i++) | |
345 { | |
346 if(gui->window_priv[i]->hwnd == hwnd) | |
347 priv=gui->window_priv[i]; | |
348 }// Sherpya | |
349 /* display the status msgs */ | |
350 renderinfobox(gui->skin, priv); | |
351 RedrawWindow(hwnd, NULL, NULL, RDW_INVALIDATE); | |
352 } | |
353 | |
34697 | 354 static LRESULT CALLBACK VideoProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) |
23077 | 355 { |
356 gui_t *gui = (gui_t *) GetWindowLongPtr(hWnd, GWLP_USERDATA); | |
34697 | 357 if (gui && (gui->videowindow != hWnd)) return FALSE; |
23077 | 358 |
359 switch (message) | |
360 { | |
361 case WM_CLOSE: | |
362 handlemsg(hWnd, evExit); | |
363 return 0; | |
364 case WM_DESTROY: | |
365 PostQuitMessage(0); | |
366 return 0; | |
367 case WM_KEYDOWN: | |
368 { | |
369 switch(wParam) | |
370 { | |
371 case VK_LEFT: | |
372 mplayer_put_key(KEY_LEFT); | |
373 break; | |
374 case VK_UP: | |
375 mplayer_put_key(KEY_UP); | |
376 break; | |
377 case VK_RIGHT: | |
378 mplayer_put_key(KEY_RIGHT); | |
379 break; | |
380 case VK_DOWN: | |
381 mplayer_put_key(KEY_DOWN); | |
382 break; | |
383 case VK_TAB: | |
384 mplayer_put_key(KEY_TAB); | |
385 break; | |
386 case VK_BACK: | |
387 mplayer_put_key(KEY_BS); | |
388 break; | |
389 case VK_DELETE: | |
390 mplayer_put_key(KEY_DELETE); | |
391 break; | |
392 case VK_INSERT: | |
393 mplayer_put_key(KEY_INSERT); | |
394 break; | |
395 case VK_HOME: | |
396 mplayer_put_key(KEY_HOME); | |
397 break; | |
398 case VK_END: | |
399 mplayer_put_key(KEY_END); | |
400 break; | |
401 case VK_PRIOR: | |
402 mplayer_put_key(KEY_PAGE_UP); | |
403 break; | |
404 case VK_NEXT: | |
405 mplayer_put_key(KEY_PAGE_DOWN); | |
406 break; | |
407 case VK_ESCAPE: | |
408 mplayer_put_key(KEY_ESC); | |
409 break; | |
410 } | |
411 break; | |
412 } | |
413 case WM_COMMAND: | |
414 { | |
415 switch(LOWORD(wParam)) | |
416 { | |
417 case IDEXIT: | |
418 PostQuitMessage(0); | |
419 handlemsg(hWnd, evExit); | |
420 break; | |
421 case IDFILE_OPEN: | |
422 handlemsg(hWnd, evLoadPlay); | |
423 break; | |
424 case IDURL_OPEN: | |
425 display_openurlwindow(gui, 0); | |
426 break; | |
427 case IDDIR_OPEN: | |
428 { | |
429 static char path[MAX_PATH]; | |
430 BROWSEINFO bi; | |
431 LPITEMIDLIST pidl; | |
432 memset(&bi, 0, sizeof(BROWSEINFO)); | |
34163 | 433 bi.lpszTitle = acp(MSGTR_DirectorySelect); |
23077 | 434 pidl = SHBrowseForFolder(&bi); |
435 if (SHGetPathFromIDList(pidl, path)) | |
436 { | |
437 gui->playlist->clear_playlist(gui->playlist); | |
438 adddirtoplaylist(gui->playlist, path, TRUE); | |
439 gui->startplay(gui); | |
440 } | |
441 break; | |
442 } | |
443 case ID_PTRACK: | |
444 handlemsg(hWnd, evPrev); | |
445 break; | |
446 case ID_SEEKB: | |
447 handlemsg(hWnd, evBackward10sec); | |
448 break; | |
449 case ID_PLAY: | |
450 handlemsg(hWnd, evPlaySwitchToPause); | |
451 break; | |
452 case ID_STOP: | |
453 handlemsg(hWnd, evStop); | |
454 break; | |
455 case ID_SEEKF: | |
456 handlemsg(hWnd, evForward10sec); | |
457 break; | |
458 case ID_NTRACK: | |
459 handlemsg(hWnd, evNext); | |
460 break; | |
461 case ID_CHAPTERSEL: | |
462 display_chapterselwindow(gui); | |
463 break; | |
464 case ID_FULLSCREEN: | |
465 mp_input_queue_cmd(mp_input_parse_cmd("vo_fullscreen")); | |
466 break; | |
467 case ID_MUTE: | |
468 mp_input_queue_cmd(mp_input_parse_cmd("mute")); | |
469 break; | |
470 case ID_ASPECT1: | |
471 mp_input_queue_cmd(mp_input_parse_cmd("switch_ratio 1.777777")); | |
472 break; | |
473 case ID_ASPECT2: | |
474 mp_input_queue_cmd(mp_input_parse_cmd("switch_ratio 1.333333")); | |
475 break; | |
476 case ID_ASPECT3: | |
477 mp_input_queue_cmd(mp_input_parse_cmd("switch_ratio 2.35")); | |
478 break; | |
479 case ID_ASPECT4: | |
480 mp_input_queue_cmd(mp_input_parse_cmd("switch_ratio 0")); | |
481 break; | |
482 case IDSUB_TOGGLE: | |
483 mp_input_queue_cmd(mp_input_parse_cmd("sub_visibility")); | |
484 break; | |
485 case IDSUB_CYCLE: | |
486 mp_input_queue_cmd(mp_input_parse_cmd("sub_select")); | |
487 break; | |
488 } | |
489 return 0; | |
490 } | |
491 case WM_CHAR: | |
492 mplayer_put_key(wParam); | |
493 break; | |
494 case WM_DROPFILES: | |
495 { | |
496 if(!lParam) | |
497 { | |
498 char file[MAX_PATH]; | |
499 int filecount = DragQueryFile((HDROP) wParam, -1, file, MAX_PATH); | |
500 int i; | |
501 for(i=0; i<filecount; i++) | |
502 { | |
503 DragQueryFile((HDROP) wParam, i, file, MAX_PATH); | |
35452 | 504 uiSetFile(NULL, file, STREAMTYPE_FILE); |
23077 | 505 if(!parse_filename(file, playtree, mconfig, 1)) |
506 gui->playlist->add_track(gui->playlist, file, NULL, NULL, 0); | |
507 } | |
508 DragFinish((HDROP) wParam); | |
34325 | 509 gui->playercontrol(evLoadPlay); |
23077 | 510 } |
511 else | |
512 { | |
513 gui->playlist->clear_playlist(gui->playlist); | |
514 gui->playlist->add_track(gui->playlist, (const char *) wParam, NULL, NULL, 0); | |
34325 | 515 gui->playercontrol(evLoadPlay); |
23077 | 516 } |
34697 | 517 SetForegroundWindow(gui->videowindow); |
23077 | 518 return 0; |
519 } | |
520 case WM_LBUTTONDOWN: | |
521 { | |
522 if(!vo_nomouse_input) | |
523 mplayer_put_key(MOUSE_BTN0); | |
524 break; | |
525 } | |
526 case WM_MBUTTONDOWN: | |
527 { | |
528 if(!vo_nomouse_input) | |
529 mplayer_put_key(MOUSE_BTN1); | |
530 break; | |
531 } | |
532 case WM_RBUTTONDOWN: | |
533 { | |
534 POINT point; | |
535 point.x = GET_X_LPARAM(lParam); | |
536 point.y = GET_Y_LPARAM(lParam); | |
537 ClientToScreen(hWnd, &point); | |
33555 | 538 if(guiInfo.StreamType == STREAMTYPE_DVD) |
23077 | 539 EnableMenuItem(gui->dvdmenu, ID_CHAPTERSEL, MF_BYCOMMAND | MF_ENABLED); |
34697 | 540 TrackPopupMenu(gui->videomenu, 0, point.x, point.y, 0, hWnd, NULL); |
23077 | 541 return 0; |
542 } | |
543 case WM_LBUTTONDBLCLK: | |
544 { | |
545 if(!vo_nomouse_input) | |
546 mplayer_put_key(MOUSE_BTN0_DBL); | |
547 break; | |
548 } | |
549 case WM_MBUTTONDBLCLK: | |
550 { | |
551 if(!vo_nomouse_input) | |
552 mplayer_put_key(MOUSE_BTN1_DBL); | |
553 break; | |
554 } | |
555 case WM_RBUTTONDBLCLK: | |
556 { | |
557 if(!vo_nomouse_input) | |
558 mplayer_put_key(MOUSE_BTN2_DBL); | |
559 break; | |
560 } | |
561 case WM_MOUSEWHEEL: | |
562 { | |
563 int x = GET_WHEEL_DELTA_WPARAM(wParam); | |
564 if(vo_nomouse_input) | |
565 break; | |
566 if (x > 0) | |
567 mplayer_put_key(MOUSE_BTN3); | |
568 else | |
569 mplayer_put_key(MOUSE_BTN4); | |
570 break; | |
571 } | |
572 case WM_XBUTTONDOWN: | |
573 { | |
574 if(vo_nomouse_input) | |
575 break; | |
576 if(HIWORD(wParam) == 1) | |
577 mplayer_put_key(MOUSE_BTN5); | |
578 else | |
579 mplayer_put_key(MOUSE_BTN6); | |
580 break; | |
581 } | |
582 case WM_XBUTTONDBLCLK: | |
583 { | |
584 if(vo_nomouse_input) | |
585 break; | |
586 if(HIWORD(wParam) == 1) | |
587 mplayer_put_key(MOUSE_BTN5_DBL); | |
588 else | |
589 mplayer_put_key(MOUSE_BTN6_DBL); | |
590 break; | |
591 } | |
592 case WM_TIMER: | |
593 { | |
594 if(fullscreen) while(ShowCursor(FALSE) >= 0){} | |
595 KillTimer(hWnd, ID_TIMER); | |
596 return 0; | |
597 } | |
598 case WM_MOUSEMOVE: | |
599 { | |
600 ShowCursor(TRUE); | |
601 SetTimer(hWnd, ID_TIMER, 3000, (TIMERPROC) NULL); | |
602 break; | |
603 } | |
604 case WM_WINDOWPOSCHANGED: | |
605 { | |
34996
ebcc17a3c165
Fix compiler warnings (comparison between signed and unsigned).
ib
parents:
34995
diff
changeset
|
606 uint32_t tmpheight=0; |
23077 | 607 static uint32_t rect_width; |
608 static uint32_t rect_height; | |
609 RECT rd; | |
610 POINT pt; | |
611 pt.x = 0; | |
612 pt.y = 0; | |
613 GetClientRect(hWnd, &rd); | |
614 ClientToScreen(hWnd, &pt); | |
615 | |
616 rect_width = rd.right - rd.left; | |
617 rect_height = rd.bottom - rd.top; | |
618 | |
619 /* maintain our aspect ratio */ | |
34697 | 620 tmpheight = ((float)rect_width/video_aspect); |
23077 | 621 tmpheight += tmpheight % 2; |
622 if(tmpheight > rect_height) | |
623 { | |
34697 | 624 rect_width = ((float)rect_height*video_aspect); |
23077 | 625 rect_width += rect_width % 2; |
626 } | |
627 else rect_height = tmpheight; | |
628 | |
629 rd.right = rd.left + rect_width; | |
630 rd.bottom = rd.top + rect_height; | |
631 | |
632 AdjustWindowRect(&rd, WS_OVERLAPPEDWINDOW | WS_SIZEBOX, 0); | |
633 SetWindowPos(hWnd, 0, fullscreen?0:pt.x+rd.left, fullscreen?0:pt.y+rd.top, | |
634 fullscreen?vo_screenwidth:rd.right-rd.left, fullscreen?vo_screenheight:rd.bottom-rd.top, SWP_NOOWNERZORDER); | |
635 SetForegroundWindow(hWnd); | |
636 return 0; | |
637 } | |
638 case WM_SYSCOMMAND: | |
639 { | |
640 switch(wParam) | |
641 { | |
642 case SC_SCREENSAVE: | |
643 case SC_MONITORPOWER: | |
644 mp_msg(MSGT_VO, MSGL_V ,"<vo_directx><INFO>killing screensaver\n" ); | |
645 return 0; | |
646 } | |
647 break; | |
648 } | |
649 case WM_PAINT: | |
650 { | |
651 PAINTSTRUCT ps; | |
652 RECT rect; | |
653 HDC hdc = BeginPaint(hWnd, &ps); | |
654 HDC hMemDC = CreateCompatibleDC(hdc); | |
655 HBRUSH blackbrush = (HBRUSH)GetStockObject(BLACK_BRUSH); | |
656 int width, height; | |
657 GetClientRect(hWnd, &rect); | |
658 width = rect.right - rect.left; | |
659 height = rect.bottom - rect.top; | |
33615
1f9a31d4f114
Replace all playback integer constants by their symbolic constants.
ib
parents:
33580
diff
changeset
|
660 if(guiInfo.Playing == GUI_STOP) |
23077 | 661 { |
34996
ebcc17a3c165
Fix compiler warnings (comparison between signed and unsigned).
ib
parents:
34995
diff
changeset
|
662 unsigned int i; |
23077 | 663 window *desc = NULL; |
664 | |
665 for (i=0; i<gui->skin->windowcount; i++) | |
34697 | 666 if(gui->skin->windows[i]->type == wiVideo) |
23077 | 667 desc = gui->skin->windows[i]; |
668 | |
669 SelectObject(hMemDC, get_bitmap(hWnd)); | |
670 StretchBlt(hdc, 0, 0, width, height, hMemDC, 0, 0, desc->base->bitmap[0]->width, | |
671 desc->base->bitmap[0]->height, SRCCOPY); | |
672 } else { | |
673 FillRect(GetDC(hWnd), &rect, fullscreen?blackbrush:colorbrush); | |
674 } | |
675 DeleteDC(hMemDC); | |
676 EndPaint(hWnd, &ps); | |
677 return 0; | |
678 } | |
679 } | |
680 return DefWindowProc(hWnd, message, wParam, lParam); | |
681 } | |
682 | |
683 /* Window Proc for the gui Window */ | |
684 static LRESULT CALLBACK EventProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) | |
685 { | |
686 gui_t *gui = (gui_t *) GetWindowLongPtr(hWnd, GWLP_USERDATA); | |
687 | |
688 /* Avoid processing when then window doesn't match gui mainwindow */ | |
689 if (gui && (gui->mainwindow != hWnd)) return FALSE; | |
690 | |
691 switch (message) | |
692 { | |
693 case WM_CLOSE: | |
694 handlemsg(hWnd, evExit); | |
695 return 0; | |
696 case WM_DESTROY: | |
697 PostQuitMessage(0); | |
698 return 0; | |
699 case WM_SYSTRAY: | |
700 { | |
701 switch(lParam) | |
702 { | |
703 POINT cursor; | |
704 case WM_RBUTTONDOWN: | |
705 { | |
706 GetCursorPos(&cursor); | |
707 SetForegroundWindow(hWnd); | |
708 TrackPopupMenu(gui->traymenu, 0, cursor.x, cursor.y, 0, hWnd, NULL); | |
709 break; | |
710 } | |
711 case WM_MBUTTONDBLCLK: | |
712 case WM_LBUTTONDBLCLK: | |
713 { | |
714 if(IsWindowVisible(hWnd)) ShowWindow(hWnd, SW_HIDE); | |
715 else { ShowWindow(hWnd, SW_SHOW); SetForegroundWindow(hWnd); } | |
716 break; | |
717 } | |
718 } | |
719 break; | |
720 } | |
721 case WM_KEYDOWN: | |
722 { | |
723 switch(wParam) | |
724 { | |
725 case VK_LEFT: | |
726 mplayer_put_key(KEY_LEFT); | |
727 break; | |
728 case VK_UP: | |
729 mplayer_put_key(KEY_UP); | |
730 break; | |
731 case VK_RIGHT: | |
732 mplayer_put_key(KEY_RIGHT); | |
733 break; | |
734 case VK_DOWN: | |
735 mplayer_put_key(KEY_DOWN); | |
736 break; | |
737 case VK_TAB: | |
738 mplayer_put_key(KEY_TAB); | |
739 break; | |
740 case VK_BACK: | |
741 mplayer_put_key(KEY_BS); | |
742 break; | |
743 case VK_DELETE: | |
744 mplayer_put_key(KEY_DELETE); | |
745 break; | |
746 case VK_INSERT: | |
747 mplayer_put_key(KEY_INSERT); | |
748 break; | |
749 case VK_HOME: | |
750 mplayer_put_key(KEY_HOME); | |
751 break; | |
752 case VK_END: | |
753 mplayer_put_key(KEY_END); | |
754 break; | |
755 case VK_PRIOR: | |
756 mplayer_put_key(KEY_PAGE_UP); | |
757 break; | |
758 case VK_NEXT: | |
759 mplayer_put_key(KEY_PAGE_DOWN); | |
760 break; | |
761 case VK_ESCAPE: | |
762 mplayer_put_key(KEY_ESC); | |
763 break; | |
764 } | |
765 break; | |
766 } | |
767 case WM_CHAR: | |
768 mplayer_put_key(wParam); | |
769 break; | |
770 case WM_COPYDATA: | |
771 { | |
772 if(lParam) | |
773 { | |
774 PCOPYDATASTRUCT cdData; | |
775 cdData = (PCOPYDATASTRUCT) lParam; | |
35452 | 776 uiSetFile(NULL, cdData->lpData, STREAMTYPE_FILE); |
23077 | 777 if(!parse_filename(cdData->lpData, playtree, mconfig, 1)) |
778 gui->playlist->add_track(gui->playlist, cdData->lpData, NULL, NULL, 0); | |
779 gui->startplay(gui); | |
780 } | |
781 break; | |
782 } | |
783 case WM_DROPFILES: | |
784 { | |
785 if(!lParam) | |
786 { | |
787 char file[MAX_PATH]; | |
788 int filecount = DragQueryFile((HDROP) wParam, -1, file, MAX_PATH); | |
789 int i; | |
790 for(i=0; i<filecount; i++) | |
791 { | |
792 DragQueryFile((HDROP) wParam, i, file, MAX_PATH); | |
35452 | 793 uiSetFile(NULL, file, STREAMTYPE_FILE); |
23077 | 794 if(!parse_filename(file, playtree, mconfig, 1)) |
795 gui->playlist->add_track(gui->playlist, file, NULL, NULL, 0); | |
796 } | |
797 DragFinish((HDROP) wParam); | |
34325 | 798 gui->playercontrol(evLoadPlay); |
23077 | 799 } |
800 else | |
801 { | |
802 gui->playlist->clear_playlist(gui->playlist); | |
803 gui->playlist->add_track(gui->playlist, (const char *) wParam, NULL, NULL, 0); | |
34325 | 804 gui->playercontrol(evLoadPlay); |
23077 | 805 } |
806 SetForegroundWindow(gui->mainwindow); | |
807 return 0; | |
808 } | |
809 case WM_LBUTTONDOWN: | |
810 { | |
811 SetCapture(hWnd); | |
812 gui->mousex = GET_X_LPARAM(lParam); | |
813 gui->mousey = GET_Y_LPARAM(lParam); | |
814 /* inside a widget */ | |
815 gui->activewidget = clickedinsidewidget(gui, get_windowtype(hWnd), gui->mousex, gui->mousey); | |
816 if(gui->activewidget) | |
817 { | |
818 gui->activewidget->pressed = 1; | |
819 gui->mousewx = gui->mousex - gui->activewidget->x; | |
820 gui->mousewy = gui->mousey - gui->activewidget->y; | |
821 renderwidget(gui->skin, get_drawground(hWnd), gui->activewidget, 0); | |
822 RedrawWindow(hWnd, NULL, NULL, RDW_INVALIDATE); | |
823 handlemsg(hWnd, gui->activewidget->msg); | |
824 } | |
825 break; | |
826 } | |
827 case WM_CAPTURECHANGED: | |
828 { | |
829 if(gui->activewidget) | |
830 { | |
831 gui->activewidget->pressed = 0; | |
832 renderwidget(gui->skin, get_drawground(hWnd), gui->activewidget, 1); | |
833 RedrawWindow(hWnd, NULL, NULL, RDW_INVALIDATE); | |
834 gui->activewidget = NULL; | |
835 } | |
836 break; | |
837 } | |
838 case WM_LBUTTONUP: | |
839 { | |
840 ReleaseCapture(); | |
841 if(gui->activewidget) | |
842 { | |
843 gui->activewidget->pressed = 0; | |
844 renderwidget(gui->skin, get_drawground(hWnd), gui->activewidget, 1); | |
845 RedrawWindow(hWnd, NULL, NULL, RDW_INVALIDATE); | |
846 gui->activewidget = NULL; | |
847 } | |
848 break; | |
849 } | |
850 case WM_RBUTTONDOWN: | |
851 { | |
852 POINT point; | |
853 char device[MAX_PATH]; | |
854 char searchpath[MAX_PATH]; | |
855 int len, pos = 0, cdromdrive = 0; | |
856 UINT errmode; | |
857 point.x = GET_X_LPARAM(lParam); | |
858 point.y = GET_Y_LPARAM(lParam); | |
859 ClientToScreen(hWnd, &point); | |
860 errmode = SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOOPENFILEERRORBOX); | |
861 while (GetMenuItemCount(gui->diskmenu) > 0) | |
862 DeleteMenu(gui->diskmenu, 0, MF_BYPOSITION); | |
863 len = GetLogicalDriveStrings(MAX_PATH, device); | |
864 while(pos < len) | |
865 { | |
866 if(GetDriveType(device + pos) == DRIVE_CDROM) | |
867 { | |
868 char volname[MAX_PATH]; | |
869 char menuitem[MAX_PATH]; | |
35501 | 870 int flags = MF_STRING, enable = FALSE; |
23077 | 871 mp_msg(MSGT_GPLAYER, MSGL_V, "[GUI] checking %s for CD/VCD/SVCD/DVDs\n", device + pos); |
34454 | 872 #ifdef CONFIG_DVDREAD |
23077 | 873 sprintf(searchpath, "%sVIDEO_TS", device + pos); |
34452
c3e63d8b6cf3
Reduce number and avoid conditional definition of searchpath variables.
ib
parents:
34405
diff
changeset
|
874 if(GetFileAttributes(searchpath) != INVALID_FILE_ATTRIBUTES) |
35501 | 875 enable = TRUE; |
34454 | 876 #endif |
34452
c3e63d8b6cf3
Reduce number and avoid conditional definition of searchpath variables.
ib
parents:
34405
diff
changeset
|
877 sprintf(searchpath, "%sMpegav", device + pos); |
23077 | 878 if(GetFileAttributes(searchpath) != INVALID_FILE_ATTRIBUTES) |
35501 | 879 enable = TRUE; |
34405
35fd66684548
Use cdparanoia compatibility names for CD function calls.
ib
parents:
34391
diff
changeset
|
880 #ifdef CONFIG_CDDA |
34452
c3e63d8b6cf3
Reduce number and avoid conditional definition of searchpath variables.
ib
parents:
34405
diff
changeset
|
881 sprintf(searchpath, "%sTrack01.cda", device + pos); |
c3e63d8b6cf3
Reduce number and avoid conditional definition of searchpath variables.
ib
parents:
34405
diff
changeset
|
882 if(GetFileAttributes(searchpath) != INVALID_FILE_ATTRIBUTES) |
35501 | 883 enable = TRUE; |
23077 | 884 #endif |
34452
c3e63d8b6cf3
Reduce number and avoid conditional definition of searchpath variables.
ib
parents:
34405
diff
changeset
|
885 flags |= (enable ? MF_ENABLED : MF_GRAYED); |
23077 | 886 volname[0] = 0; |
887 strcpy(menuitem, device + pos); | |
888 menuitem[strlen(menuitem) - 1]=0; | |
889 GetVolumeInformation(device + pos, volname, MAX_PATH, NULL, NULL, NULL, NULL, 0); | |
890 if (strlen(volname)) | |
891 { | |
892 capitalize(volname); | |
893 strcat(menuitem, " - "); | |
894 strcat(menuitem, volname); | |
895 } | |
896 AppendMenu(gui->diskmenu, flags, IDPLAYDISK + cdromdrive, menuitem); | |
34979 | 897 if (++cdromdrive == IDPLAYDISK_LIMIT - IDPLAYDISK) break; |
23077 | 898 } |
899 pos += strlen(device + pos) + 1; | |
900 } | |
901 SetErrorMode(errmode); | |
902 TrackPopupMenu(gui->menu, 0, point.x, point.y, 0, hWnd, NULL); | |
903 return 0; | |
904 } | |
905 case WM_MOUSEMOVE: | |
906 { | |
907 if(wParam & MK_LBUTTON) | |
908 { | |
909 POINT point; | |
910 RECT rect; | |
911 if(gui->activewidget) | |
912 { | |
913 widget *item = gui->activewidget; | |
914 | |
915 if(item->type == tyHpotmeter) | |
916 { | |
917 item->x = GET_X_LPARAM(lParam) - gui->mousewx; | |
918 item->value = (float)((float)((item->x - item->wx) * 100.0f) / (float)(item->wwidth - item->width)); | |
919 } | |
920 if(item->type == tyPotmeter) | |
921 { | |
922 gui->mousewx = GET_X_LPARAM(lParam) - gui->activewidget->x; | |
923 item->value = (float) (gui->mousewx * 100.0f) / (float) item->wwidth; | |
924 } | |
925 | |
926 if((item->type == tyPotmeter) || (item->type == tyHpotmeter) || (item->type == tyVpotmeter)) | |
927 { | |
928 /* Bound checks */ | |
929 if(item->value > 100.0f) | |
930 item->value = 100.0f; | |
931 else if(item->value < 0.0f) | |
932 item->value = 0.0f; | |
933 | |
934 if(item->msg == evSetVolume) | |
33555 | 935 guiInfo.Volume = (float) item->value; |
23077 | 936 else if(item->msg == evSetMoviePosition) |
33555 | 937 guiInfo.Position = (float) item->value; |
23077 | 938 else if(item->msg == evSetBalance) |
939 { | |
940 /* make the range for 50% a bit bigger, because the sliders for balance usually suck */ | |
941 if((item->value - 50.0f < 1.5f) && (item->value - 50.0f > -1.5f)) | |
942 item->value = 50.0f; | |
33555 | 943 guiInfo.Balance = (float) item->value; |
23077 | 944 } |
945 updatedisplay(gui, hWnd); | |
946 handlemsg(hWnd, item->msg); | |
947 } | |
948 break; | |
949 } | |
950 point.x = GET_X_LPARAM(lParam); | |
951 point.y = GET_Y_LPARAM(lParam); | |
952 ClientToScreen(hWnd, &point); | |
953 GetWindowRect(hWnd, &rect); | |
954 MoveWindow(hWnd, point.x - gui->mousex, point.y - gui->mousey, | |
955 rect.right-rect.left,rect.bottom-rect.top,TRUE); | |
956 break; | |
957 } | |
958 break; | |
959 } | |
960 case WM_COMMAND: | |
961 { | |
962 switch(LOWORD(wParam)) | |
963 { | |
964 case IDEXIT: | |
965 PostQuitMessage(0); | |
966 handlemsg(hWnd, evExit); | |
967 break; | |
968 case IDFILE_OPEN: | |
969 handlemsg(hWnd, evLoadPlay); | |
970 break; | |
971 case IDDIR_OPEN: | |
972 { | |
973 static char path[MAX_PATH]; | |
974 BROWSEINFO bi; | |
975 LPITEMIDLIST pidl; | |
976 memset(&bi, 0, sizeof(BROWSEINFO)); | |
34163 | 977 bi.lpszTitle = acp(MSGTR_DirectorySelect); |
23077 | 978 pidl = SHBrowseForFolder(&bi); |
979 if (SHGetPathFromIDList(pidl, path)) | |
980 { | |
981 gui->playlist->clear_playlist(gui->playlist); | |
982 adddirtoplaylist(gui->playlist, path, TRUE); | |
983 gui->startplay(gui); | |
984 } | |
985 break; | |
986 } | |
987 case ID_SKINBROWSER: | |
988 handlemsg(hWnd, evSkinBrowser); | |
989 break; | |
990 case IDURL_OPEN: | |
991 display_openurlwindow(gui, 0); | |
992 break; | |
993 case ID_MUTE: | |
994 mp_input_queue_cmd(mp_input_parse_cmd("mute")); | |
995 break; | |
996 case IDSUBTITLE_OPEN: | |
997 display_opensubtitlewindow(gui); | |
998 break; | |
999 case ID_PTRACK: | |
1000 handlemsg(hWnd, evPrev); | |
1001 break; | |
1002 case ID_SEEKB: | |
1003 handlemsg(hWnd, evBackward10sec); | |
1004 break; | |
1005 case ID_PLAY: | |
1006 handlemsg(hWnd, evPlaySwitchToPause); | |
1007 break; | |
1008 case ID_STOP: | |
1009 handlemsg(hWnd, evStop); | |
1010 break; | |
1011 case ID_SEEKF: | |
1012 handlemsg(hWnd, evForward10sec); | |
1013 break; | |
1014 case ID_NTRACK: | |
1015 handlemsg(hWnd, evNext); | |
1016 break; | |
1017 case ID_SHOWHIDE: | |
1018 { | |
1019 if(IsWindowVisible(hWnd)) ShowWindow(hWnd, SW_HIDE); | |
1020 else ShowWindow(hWnd, SW_SHOW); | |
1021 break; | |
1022 } | |
1023 case ID_PLAYLIST: | |
34321
daebf766dea6
Cosmetic: Synchronize evPlaylist event and message names.
ib
parents:
34315
diff
changeset
|
1024 handlemsg(hWnd, evPlaylist); |
23077 | 1025 break; |
1026 case ID_PREFS: | |
1027 handlemsg(hWnd, evPreferences); | |
1028 break; | |
1029 case ID_CONSOLE: | |
35001 | 1030 console_toggle(gui); |
23077 | 1031 break; |
1032 case ID_ONLINEHELP: | |
1033 ShellExecute(NULL, "open", ONLINE_HELP_URL, NULL, NULL, SW_SHOWNORMAL); | |
1034 break; | |
33965 | 1035 case IDHELP_ABOUT: |
1036 handlemsg(hWnd, evAbout); | |
1037 break; | |
23077 | 1038 } |
34979 | 1039 if(LOWORD(wParam) >= IDPLAYDISK && LOWORD(wParam) < IDPLAYDISK_LIMIT) |
23077 | 1040 { |
1041 char device[MAX_PATH]; | |
1042 char searchpath[MAX_PATH]; | |
1043 char filename[MAX_PATH]; | |
1044 int len, pos = 0, cdromdrive = 0; | |
1045 len = GetLogicalDriveStrings(MAX_PATH, device); | |
1046 while(pos < len) | |
1047 { | |
1048 if(GetDriveType(device + pos)==DRIVE_CDROM) | |
1049 { | |
1050 if(LOWORD(wParam) - IDPLAYDISK == cdromdrive) | |
1051 { | |
1052 sprintf(searchpath, "%sVIDEO_TS", device + pos); | |
1053 if(GetFileAttributes(searchpath) != INVALID_FILE_ATTRIBUTES) | |
1054 { | |
32537
8fa2f43cb760
Remove most of the NULL pointer check before free all over the code
cboesch
parents:
31532
diff
changeset
|
1055 free(dvd_device); |
23077 | 1056 dvd_device = strdup(device + pos); |
1057 handlemsg(hWnd, evPlayDVD); | |
1058 } | |
1059 sprintf(searchpath, "%sTrack01.cda", device + pos); | |
1060 if(GetFileAttributes(searchpath) != INVALID_FILE_ATTRIBUTES) | |
1061 { | |
32537
8fa2f43cb760
Remove most of the NULL pointer check before free all over the code
cboesch
parents:
31532
diff
changeset
|
1062 free(cdrom_device); |
23077 | 1063 cdrom_device = strdup(device + pos); |
1064 /* mplayer doesn't seem to like the trailing \ after the device name */ | |
1065 cdrom_device[2]=0; | |
1066 handlemsg(hWnd, evPlayCD); | |
23147
21c35763b178
compilation fix for disabling dvd functionality, patch by <bangbangbear at gmail dot com>, slightly modified by me.
vayne
parents:
23091
diff
changeset
|
1067 } else { |
23077 | 1068 HANDLE searchhndl; |
1069 WIN32_FIND_DATA finddata; | |
34092
dbf5042ab255
Don't use the Windows style path separator character in Win32 GUI.
ib
parents:
33965
diff
changeset
|
1070 sprintf(searchpath, "%smpegav/*.dat", device + pos); |
23077 | 1071 if((searchhndl=FindFirstFile(searchpath, &finddata)) != INVALID_HANDLE_VALUE) |
1072 { | |
1073 mp_msg(MSGT_GPLAYER,MSGL_V, "Opening VCD/SVCD\n"); | |
1074 gui->playlist->clear_playlist(gui->playlist); | |
1075 do | |
1076 { | |
34092
dbf5042ab255
Don't use the Windows style path separator character in Win32 GUI.
ib
parents:
33965
diff
changeset
|
1077 sprintf(filename, "%smpegav/%s", device + pos, finddata.cFileName); |
23077 | 1078 gui->playlist->add_track(gui->playlist, filename, NULL, NULL, 0); |
1079 } | |
1080 while(FindNextFile(searchhndl, &finddata)); | |
1081 FindClose(searchhndl); | |
1082 } | |
1083 gui->startplay(gui); | |
1084 } | |
1085 } | |
1086 cdromdrive++; | |
1087 } | |
1088 pos += strlen(device + pos) + 1; | |
1089 } | |
1090 } | |
1091 break; | |
1092 } | |
1093 case WM_PAINT: | |
1094 { | |
1095 PAINTSTRUCT ps; | |
1096 RECT rd; | |
1097 HDC hdc = BeginPaint(hWnd, &ps); | |
1098 HDC hMemDC = CreateCompatibleDC(hdc); | |
1099 int width, height; | |
1100 GetClientRect(hWnd, &rd); | |
1101 width = rd.right - rd.left; | |
1102 height = rd.bottom - rd.top; | |
1103 SelectObject(hMemDC, get_bitmap(hWnd)); | |
1104 BitBlt(hdc, 0, 0, width, height, hMemDC, 0, 0, SRCCOPY); | |
1105 DeleteDC(hMemDC); | |
1106 EndPaint(hWnd, &ps); | |
1107 return 0; | |
1108 } | |
1109 return 0; | |
1110 } | |
1111 return DefWindowProc(hWnd, message, wParam, lParam); | |
1112 } | |
1113 | |
27292 | 1114 static void startplay(gui_t *gui) |
23077 | 1115 { |
34325 | 1116 gui->playercontrol(evLoadPlay); |
23077 | 1117 } |
1118 | |
1119 /* returns the bits per pixel of the desktop */ | |
1120 /* the format is always in BGR byte order */ | |
1121 static int GetDesktopBitsPerPixel(void) | |
1122 { | |
1123 HWND desktop=GetDesktopWindow(); | |
1124 HDC dc=GetDC(desktop); | |
1125 int bpp=GetDeviceCaps(dc, BITSPIXEL); | |
1126 ReleaseDC(desktop, dc); | |
1127 return bpp; | |
1128 } | |
1129 | |
1130 /* unloads a skin and destroys its windows */ | |
28051 | 1131 int destroy_window(gui_t *gui) |
23077 | 1132 { |
1133 RECT rd; | |
1134 unsigned int i; | |
1135 | |
1136 /* Save position: MSDN says don't pass workspace coordinates | |
1137 * to CreateWindow() or SetWindowPos(), as both of which expect | |
1138 * screen coordinates; resulting in the window appearing in the | |
1139 * wrong location. | |
1140 * -Erik | |
1141 */ | |
1142 | |
1143 /* main window position */ | |
1144 if(IsIconic(gui->mainwindow)) | |
1145 ShowWindow(gui->mainwindow, SW_SHOWNORMAL); | |
1146 GetWindowRect(gui->mainwindow, &rd); | |
1147 gui_main_pos_x = rd.left; | |
1148 gui_main_pos_y = rd.top; | |
1149 | |
34697 | 1150 /* video window position */ |
1151 if(IsIconic(gui->videowindow)) | |
1152 ShowWindow(gui->videowindow, SW_SHOWNORMAL); | |
1153 GetWindowRect(gui->videowindow, &rd); | |
1154 gui_video_pos_x = rd.left; | |
1155 gui_video_pos_y = rd.top; | |
23077 | 1156 |
1157 for(i=0; i<gui->window_priv_count; i++) | |
1158 { | |
1159 if(gui->window_priv[i]->bitmap) | |
1160 DeleteObject(gui->window_priv[i]->bitmap); | |
1161 free(gui->window_priv[i]); | |
1162 } | |
33770 | 1163 nfree(gui->window_priv); |
23077 | 1164 gui->window_priv_count = 0; |
1165 | |
1166 /* destroy the main window */ | |
1167 if(gui->mainwindow) | |
1168 DestroyWindow(gui->mainwindow); | |
1169 gui->mainwindow = NULL; | |
1170 | |
34697 | 1171 /* destroy the video window */ |
1172 if(gui->videowindow) | |
1173 DestroyWindow(gui->videowindow); | |
1174 gui->videowindow = NULL; | |
23077 | 1175 |
1176 UnregisterClass(gui->classname, 0); | |
1177 DestroyIcon(gui->icon); | |
1178 | |
1179 gui->skin->freeskin(gui->skin); | |
1180 gui->skin = NULL; | |
1181 return 0; | |
1182 } | |
1183 | |
1184 static void create_menu(gui_t *gui) | |
1185 { | |
1186 gui->diskmenu = CreatePopupMenu(); | |
1187 gui->menu=CreatePopupMenu(); | |
1188 gui->trayplaymenu = CreatePopupMenu(); | |
34163 | 1189 AppendMenu(gui->menu, MF_STRING | MF_POPUP, (UINT_PTR) gui->trayplaymenu, acp(MSGTR_MENU_Open)); |
1190 AppendMenu(gui->trayplaymenu, MF_STRING, IDFILE_OPEN, acp(MSGTR_MENU_PlayFile)); | |
1191 AppendMenu(gui->trayplaymenu, MF_STRING, IDURL_OPEN, acp(MSGTR_MENU_PlayURL)); | |
1192 AppendMenu(gui->trayplaymenu, MF_STRING, IDDIR_OPEN, acp(MSGTR_MENU_PlayDirectory)); | |
23077 | 1193 AppendMenu(gui->menu, MF_SEPARATOR, 0, 0); |
34163 | 1194 AppendMenu(gui->menu, MF_STRING | MF_POPUP, (UINT_PTR) gui->diskmenu, acp(MSGTR_MENU_PlayDisc)); |
23077 | 1195 AppendMenu(gui->menu, MF_SEPARATOR, 0, 0); |
34163 | 1196 AppendMenu(gui->menu, MF_STRING, IDSUBTITLE_OPEN, acp(MSGTR_MENU_LoadSubtitle)); |
1197 AppendMenu(gui->menu, MF_STRING, ID_SKINBROWSER, acp(MSGTR_MENU_SkinBrowser)); | |
23077 | 1198 AppendMenu(gui->menu, MF_SEPARATOR, 0, 0); |
34163 | 1199 AppendMenu(gui->menu, MF_STRING, ID_PREFS, acp(MSGTR_MENU_Preferences)); |
1200 AppendMenu(gui->menu, MF_STRING, ID_CONSOLE, acp(MSGTR_MENU_DebugConsole)); | |
1201 AppendMenu(gui->menu, MF_STRING, ID_ONLINEHELP, acp(MSGTR_MENU_OnlineHelp)); | |
1202 AppendMenu(gui->menu, MF_STRING, IDHELP_ABOUT, acp(MSGTR_MENU_AboutMPlayer)); | |
23077 | 1203 AppendMenu(gui->menu, MF_SEPARATOR, 0, 0); |
34163 | 1204 AppendMenu(gui->menu, MF_STRING, IDEXIT, acp(MSGTR_MENU_Exit)); |
23077 | 1205 } |
1206 | |
1207 static void create_traymenu(gui_t *gui) | |
1208 { | |
1209 gui->traymenu = CreatePopupMenu(); | |
1210 gui->trayplaybackmenu = CreatePopupMenu(); | |
34163 | 1211 AppendMenu(gui->traymenu, MF_STRING | MF_POPUP, (UINT_PTR) gui->trayplaymenu, acp(MSGTR_MENU_Open)); |
23077 | 1212 AppendMenu(gui->traymenu, MF_SEPARATOR, 0, 0); |
34163 | 1213 AppendMenu(gui->traymenu, MF_STRING | MF_POPUP, (UINT_PTR) gui->trayplaybackmenu, acp(MSGTR_MENU_Playing)); |
1214 AppendMenu(gui->trayplaybackmenu, MF_STRING, ID_SEEKB, acp(MSGTR_MENU_SeekBack)); | |
1215 AppendMenu(gui->trayplaybackmenu, MF_STRING, ID_PTRACK, acp(MSGTR_MENU_PrevStream)); | |
1216 AppendMenu(gui->trayplaybackmenu, MF_STRING, ID_PLAY, acp(MSGTR_MENU_Play "/" MSGTR_MENU_Pause)); | |
1217 AppendMenu(gui->trayplaybackmenu, MF_STRING, ID_STOP, acp(MSGTR_MENU_Stop)); | |
1218 AppendMenu(gui->trayplaybackmenu, MF_STRING, ID_NTRACK, acp(MSGTR_MENU_NextStream)); | |
1219 AppendMenu(gui->trayplaybackmenu, MF_STRING, ID_SEEKF, acp(MSGTR_MENU_SeekForw)); | |
23077 | 1220 AppendMenu(gui->traymenu, MF_SEPARATOR, 0, 0); |
34163 | 1221 AppendMenu(gui->traymenu, MF_STRING, ID_MUTE, acp(MSGTR_MENU_Mute)); |
23077 | 1222 AppendMenu(gui->traymenu, MF_SEPARATOR, 0, 0); |
34163 | 1223 AppendMenu(gui->traymenu, MF_STRING, IDSUBTITLE_OPEN, acp(MSGTR_MENU_LoadSubtitle)); |
1224 AppendMenu(gui->traymenu, MF_STRING, ID_PLAYLIST, acp(MSGTR_MENU_PlayList)); | |
23077 | 1225 AppendMenu(gui->traymenu, MF_SEPARATOR, 0, 0); |
34163 | 1226 AppendMenu(gui->traymenu, MF_STRING, ID_SHOWHIDE, acp(MSGTR_MENU_ShowHide)); |
23077 | 1227 AppendMenu(gui->traymenu, MF_SEPARATOR, 0, 0); |
34163 | 1228 AppendMenu(gui->traymenu, MF_STRING, ID_PREFS, acp(MSGTR_MENU_Preferences)); |
1229 AppendMenu(gui->traymenu, MF_STRING, ID_CONSOLE, acp(MSGTR_MENU_DebugConsole)); | |
1230 AppendMenu(gui->traymenu, MF_STRING, ID_ONLINEHELP, acp(MSGTR_MENU_OnlineHelp)); | |
1231 AppendMenu(gui->traymenu, MF_STRING, IDHELP_ABOUT, acp(MSGTR_MENU_AboutMPlayer)); | |
23077 | 1232 AppendMenu(gui->traymenu, MF_SEPARATOR, 0, 0); |
34163 | 1233 AppendMenu(gui->traymenu, MF_STRING, IDEXIT, acp(MSGTR_MENU_Exit)); |
23077 | 1234 } |
1235 | |
34697 | 1236 static void create_videomenu(gui_t *gui) |
23077 | 1237 { |
34697 | 1238 gui->videomenu = CreatePopupMenu(); |
23077 | 1239 gui->dvdmenu = CreatePopupMenu(); |
1240 gui->aspectmenu = CreatePopupMenu(); | |
1241 gui->subtitlemenu = CreatePopupMenu(); | |
34697 | 1242 AppendMenu(gui->videomenu, MF_STRING | MF_POPUP, (UINT_PTR) gui->trayplaymenu, acp(MSGTR_MENU_Open)); |
1243 AppendMenu(gui->videomenu, MF_SEPARATOR, 0, 0); | |
1244 AppendMenu(gui->videomenu, MF_STRING, ID_SEEKB, acp(MSGTR_MENU_SeekBack)); | |
1245 AppendMenu(gui->videomenu, MF_STRING, ID_PTRACK, acp(MSGTR_MENU_PrevStream)); | |
1246 AppendMenu(gui->videomenu, MF_STRING, ID_PLAY, acp(MSGTR_MENU_Play "/" MSGTR_MENU_Pause)); | |
1247 AppendMenu(gui->videomenu, MF_STRING, ID_STOP, acp(MSGTR_MENU_Stop)); | |
1248 AppendMenu(gui->videomenu, MF_STRING, ID_NTRACK, acp(MSGTR_MENU_NextStream)); | |
1249 AppendMenu(gui->videomenu, MF_STRING, ID_SEEKF, acp(MSGTR_MENU_SeekForw)); | |
1250 AppendMenu(gui->videomenu, MF_SEPARATOR, 0, 0); | |
1251 AppendMenu(gui->videomenu, MF_STRING, ID_FULLSCREEN, acp(MSGTR_MENU_FullScreen)); | |
1252 AppendMenu(gui->videomenu, MF_STRING, ID_MUTE, acp(MSGTR_MENU_Mute)); | |
1253 AppendMenu(gui->videomenu, MF_SEPARATOR, 0, 0); | |
1254 AppendMenu(gui->videomenu, MF_STRING | MF_POPUP, (UINT_PTR) gui->aspectmenu, acp(MSGTR_MENU_AspectRatio)); | |
1255 AppendMenu(gui->videomenu, MF_STRING | MF_POPUP, (UINT_PTR) gui->subtitlemenu, acp(MSGTR_MENU_Subtitles)); | |
34454 | 1256 #ifdef CONFIG_DVDREAD |
34697 | 1257 AppendMenu(gui->videomenu, MF_STRING | MF_POPUP, (UINT_PTR) gui->dvdmenu, acp(MSGTR_MENU_DVD)); |
34382 | 1258 AppendMenu(gui->dvdmenu, MF_STRING | MF_GRAYED, ID_CHAPTERSEL, acp(MSGTR_SelectTitleChapter)); |
23077 | 1259 #endif |
34163 | 1260 AppendMenu(gui->subtitlemenu, MF_STRING, IDSUB_TOGGLE, acp(MSGTR_MENU_SubtitlesOnOff)); |
1261 AppendMenu(gui->subtitlemenu, MF_STRING, IDSUB_CYCLE, acp(MSGTR_MENU_SubtitleLanguages)); | |
1262 AppendMenu(gui->aspectmenu, MF_STRING, ID_ASPECT1, "16:9"); | |
1263 AppendMenu(gui->aspectmenu, MF_STRING, ID_ASPECT2, "4:3"); | |
1264 AppendMenu(gui->aspectmenu, MF_STRING, ID_ASPECT3, "2.35"); | |
23077 | 1265 AppendMenu(gui->aspectmenu, MF_SEPARATOR, 0, 0); |
34163 | 1266 AppendMenu(gui->aspectmenu, MF_STRING, ID_ASPECT4, acp(MSGTR_MENU_Original)); |
34697 | 1267 AppendMenu(gui->videomenu, MF_SEPARATOR, 0, 0); |
1268 AppendMenu(gui->videomenu, MF_STRING, IDEXIT, acp(MSGTR_MENU_Exit)); | |
23077 | 1269 } |
1270 | |
1271 static void maketransparent(HWND hwnd, COLORREF crTransparent) | |
1272 { | |
1273 HDC mdc = GetDC(hwnd); | |
34133
568f3a8e1b89
Support transparency in decorated windows in the Win32 GUI.
ib
parents:
34092
diff
changeset
|
1274 RECT wrd, crd; |
23077 | 1275 HRGN crRgnres, crRgn, crRgnTmp; |
1276 int iX = 0, iY = 0, iLeftX = 0; | |
34133
568f3a8e1b89
Support transparency in decorated windows in the Win32 GUI.
ib
parents:
34092
diff
changeset
|
1277 int border, title; |
23077 | 1278 int width, height; |
34133
568f3a8e1b89
Support transparency in decorated windows in the Win32 GUI.
ib
parents:
34092
diff
changeset
|
1279 |
568f3a8e1b89
Support transparency in decorated windows in the Win32 GUI.
ib
parents:
34092
diff
changeset
|
1280 GetWindowRect(hwnd, &wrd); |
568f3a8e1b89
Support transparency in decorated windows in the Win32 GUI.
ib
parents:
34092
diff
changeset
|
1281 GetClientRect(hwnd, &crd); |
23077 | 1282 |
34133
568f3a8e1b89
Support transparency in decorated windows in the Win32 GUI.
ib
parents:
34092
diff
changeset
|
1283 border = (wrd.right - wrd.left - crd.right) / 2; |
568f3a8e1b89
Support transparency in decorated windows in the Win32 GUI.
ib
parents:
34092
diff
changeset
|
1284 title = (wrd.bottom - wrd.top - crd.bottom) - border; |
568f3a8e1b89
Support transparency in decorated windows in the Win32 GUI.
ib
parents:
34092
diff
changeset
|
1285 |
568f3a8e1b89
Support transparency in decorated windows in the Win32 GUI.
ib
parents:
34092
diff
changeset
|
1286 width = crd.right - crd.left; |
568f3a8e1b89
Support transparency in decorated windows in the Win32 GUI.
ib
parents:
34092
diff
changeset
|
1287 height = crd.bottom - crd.top; |
568f3a8e1b89
Support transparency in decorated windows in the Win32 GUI.
ib
parents:
34092
diff
changeset
|
1288 |
568f3a8e1b89
Support transparency in decorated windows in the Win32 GUI.
ib
parents:
34092
diff
changeset
|
1289 /* create the title bar region */ |
568f3a8e1b89
Support transparency in decorated windows in the Win32 GUI.
ib
parents:
34092
diff
changeset
|
1290 crRgn = CreateRectRgn(0, 0, width + border + border, title); |
23077 | 1291 |
1292 /* Create a region from a bitmap with transparency colour of Purple */ | |
1293 for (iY = -1; iY < height; iY++) | |
1294 { | |
1295 do | |
1296 { | |
1297 /* skip over transparent pixels at start of lines */ | |
1298 while (iX <= width && GetPixel(mdc,iX, iY) == crTransparent) iX++; | |
1299 | |
1300 /* remember this pixel */ | |
1301 iLeftX = iX; | |
1302 | |
34133
568f3a8e1b89
Support transparency in decorated windows in the Win32 GUI.
ib
parents:
34092
diff
changeset
|
1303 /* now find last non transparent pixel */ |
23077 | 1304 while (iX <= width && GetPixel(mdc,iX, iY) != crTransparent) ++iX; |
1305 | |
1306 /* create a temp region on this info */ | |
34133
568f3a8e1b89
Support transparency in decorated windows in the Win32 GUI.
ib
parents:
34092
diff
changeset
|
1307 crRgnTmp = CreateRectRgn(iLeftX + border, iY + title, iX + border, iY + title + 1); |
23077 | 1308 |
1309 /* combine into main region */ | |
1310 crRgnres = crRgn; | |
1311 CombineRgn(crRgnres, crRgn, crRgnTmp, RGN_OR); | |
1312 crRgn = crRgnres; | |
1313 | |
1314 /* delete the temp region for next pass (otherwise you'll get an ASSERT) */ | |
1315 DeleteObject(crRgnTmp); | |
1316 } while (iX < width); | |
1317 iX = 0; | |
1318 } | |
34133
568f3a8e1b89
Support transparency in decorated windows in the Win32 GUI.
ib
parents:
34092
diff
changeset
|
1319 |
568f3a8e1b89
Support transparency in decorated windows in the Win32 GUI.
ib
parents:
34092
diff
changeset
|
1320 /* left border region */ |
568f3a8e1b89
Support transparency in decorated windows in the Win32 GUI.
ib
parents:
34092
diff
changeset
|
1321 crRgnTmp = CreateRectRgn(0, title, border, title + height); |
568f3a8e1b89
Support transparency in decorated windows in the Win32 GUI.
ib
parents:
34092
diff
changeset
|
1322 CombineRgn(crRgn, crRgn, crRgnTmp, RGN_OR); |
568f3a8e1b89
Support transparency in decorated windows in the Win32 GUI.
ib
parents:
34092
diff
changeset
|
1323 DeleteObject(crRgnTmp); |
568f3a8e1b89
Support transparency in decorated windows in the Win32 GUI.
ib
parents:
34092
diff
changeset
|
1324 |
568f3a8e1b89
Support transparency in decorated windows in the Win32 GUI.
ib
parents:
34092
diff
changeset
|
1325 /* right border region */ |
568f3a8e1b89
Support transparency in decorated windows in the Win32 GUI.
ib
parents:
34092
diff
changeset
|
1326 crRgnTmp = CreateRectRgn(width + border, title, width + border + border, title + height); |
568f3a8e1b89
Support transparency in decorated windows in the Win32 GUI.
ib
parents:
34092
diff
changeset
|
1327 CombineRgn(crRgn, crRgn, crRgnTmp, RGN_OR); |
568f3a8e1b89
Support transparency in decorated windows in the Win32 GUI.
ib
parents:
34092
diff
changeset
|
1328 DeleteObject(crRgnTmp); |
568f3a8e1b89
Support transparency in decorated windows in the Win32 GUI.
ib
parents:
34092
diff
changeset
|
1329 |
568f3a8e1b89
Support transparency in decorated windows in the Win32 GUI.
ib
parents:
34092
diff
changeset
|
1330 /* bottom region */ |
568f3a8e1b89
Support transparency in decorated windows in the Win32 GUI.
ib
parents:
34092
diff
changeset
|
1331 crRgnTmp = CreateRectRgn(0, title + height, width + border + border, title + height + border); |
568f3a8e1b89
Support transparency in decorated windows in the Win32 GUI.
ib
parents:
34092
diff
changeset
|
1332 CombineRgn(crRgn, crRgn, crRgnTmp, RGN_OR); |
568f3a8e1b89
Support transparency in decorated windows in the Win32 GUI.
ib
parents:
34092
diff
changeset
|
1333 DeleteObject(crRgnTmp); |
568f3a8e1b89
Support transparency in decorated windows in the Win32 GUI.
ib
parents:
34092
diff
changeset
|
1334 |
23077 | 1335 SetWindowRgn(hwnd, crRgn, TRUE); |
1336 DeleteObject(crRgn); | |
1337 ReleaseDC(hwnd,mdc); | |
1338 } | |
1339 | |
1340 static int window_render(gui_t *gui, HWND hWnd, HDC hdc, window_priv_t *priv, window *desc, BITMAPINFO binfo) | |
1341 { | |
34996
ebcc17a3c165
Fix compiler warnings (comparison between signed and unsigned).
ib
parents:
34995
diff
changeset
|
1342 unsigned int i; |
33638
dbca6aa18b50
Cast new user data value in SetWindowLongPtr() to LONG_PTR.
ib
parents:
33615
diff
changeset
|
1343 SetWindowLongPtr(hWnd, GWLP_USERDATA, (LONG_PTR) gui); |
23077 | 1344 (gui->window_priv_count)++; |
1345 gui->window_priv = realloc(gui->window_priv, sizeof(window_priv_t *) * gui->window_priv_count); | |
1346 priv = gui->window_priv[gui->window_priv_count - 1] = calloc(1, sizeof(window_priv_t)); | |
1347 priv->hwnd = hWnd; | |
1348 priv->type = desc->type; | |
1349 priv->background = desc->base->bitmap[0]; | |
1350 memcpy(&priv->img, desc->base->bitmap[0], sizeof(image)); | |
1351 hdc = GetDC(hWnd); | |
1352 binfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); | |
1353 binfo.bmiHeader.biWidth = priv->img.width; | |
1354 binfo.bmiHeader.biHeight = -priv->img.height; | |
1355 binfo.bmiHeader.biPlanes = 1; | |
1356 binfo.bmiHeader.biSizeImage = priv->img.width * priv->img.height * (gui->screenbpp / 8); | |
1357 binfo.bmiHeader.biXPelsPerMeter = 0; | |
1358 binfo.bmiHeader.biYPelsPerMeter = 0; | |
1359 binfo.bmiHeader.biClrUsed = 0; | |
1360 binfo.bmiHeader.biClrImportant = 0; | |
1361 binfo.bmiHeader.biBitCount = gui->screenbpp; | |
1362 binfo.bmiHeader.biCompression = BI_RGB; | |
1363 priv->bitmap = CreateDIBSection(hdc, &binfo, DIB_RGB_COLORS, (void **) &priv->img.data, NULL, 0); | |
1364 if(!priv->bitmap) | |
1365 { | |
1366 mp_msg(MSGT_GPLAYER, MSGL_FATAL, "[GUI] unable to create bitmap for skinned window\n"); | |
1367 return 0; | |
1368 } | |
1369 memcpy(priv->img.data, desc->base->bitmap[0]->data, binfo.bmiHeader.biSizeImage); | |
1370 ReleaseDC(hWnd,hdc); | |
1371 | |
1372 for (i=0; i<gui->skin->widgetcount; i++) | |
1373 if(gui->skin->widgets[i]->window == desc->type) | |
1374 renderwidget(gui->skin, &priv->img, gui->skin->widgets[i], 1); | |
1375 | |
1376 return 0; | |
1377 } | |
1378 | |
34697 | 1379 /* creates the video window */ |
1380 int create_videowindow(gui_t *gui) | |
23077 | 1381 { |
1382 HINSTANCE instance = GetModuleHandle(NULL); | |
1383 WNDCLASS wc; | |
1384 RECT rect; | |
1385 DWORD style = 0; | |
1386 HDC hdc = NULL; | |
1387 BITMAPINFO binfo; | |
1388 window_priv_t *priv = NULL; | |
1389 window *desc = NULL; | |
34996
ebcc17a3c165
Fix compiler warnings (comparison between signed and unsigned).
ib
parents:
34995
diff
changeset
|
1390 unsigned int i; |
ebcc17a3c165
Fix compiler warnings (comparison between signed and unsigned).
ib
parents:
34995
diff
changeset
|
1391 int x = -1, y = -1; |
23077 | 1392 vo_colorkey = 0xff00ff; |
1393 | |
1394 for (i=0; i<gui->skin->windowcount; i++) | |
34697 | 1395 if(gui->skin->windows[i]->type == wiVideo) |
23077 | 1396 desc = gui->skin->windows[i]; |
1397 | |
1398 if(!desc) | |
1399 { | |
1400 mp_msg(MSGT_GPLAYER, MSGL_FATAL, "[GUI] Invalid skin description\n"); | |
1401 return 1; | |
1402 } | |
1403 | |
1404 windowcolor = vo_colorkey; | |
1405 colorbrush = CreateSolidBrush(windowcolor); | |
1406 wc.style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS; | |
34697 | 1407 wc.lpfnWndProc = VideoProc; |
23077 | 1408 wc.cbClsExtra = 0; |
1409 wc.cbWndExtra = 0; | |
1410 wc.hInstance = instance; | |
1411 wc.hCursor = LoadCursor(NULL, IDC_ARROW); | |
1412 wc.hIcon = gui->icon; | |
1413 wc.hbrBackground = NULL; //WM_PAINT will handle background color switching; | |
34162 | 1414 wc.lpszClassName = "MPlayer - Video"; |
23077 | 1415 wc.lpszMenuName = NULL; |
1416 RegisterClass(&wc); | |
1417 | |
34697 | 1418 /* create the video window menu */ |
1419 create_videomenu(gui); | |
23077 | 1420 |
1421 rect.top = rect.left = 100; | |
1422 rect.bottom = rect.top+desc->base->bitmap[0]->height; | |
1423 rect.right = rect.left+desc->base->bitmap[0]->width; | |
1424 | |
1425 /* our window aspect */ | |
34697 | 1426 video_aspect = (float)(rect.right-rect.left)/(rect.bottom-rect.top); |
23077 | 1427 |
1428 style = fullscreen?WS_VISIBLE | WS_POPUP:WS_OVERLAPPEDWINDOW | WS_SYSMENU | WS_MINIMIZEBOX; | |
1429 AdjustWindowRect(&rect, style, 0); | |
1430 | |
34697 | 1431 if (gui_video_pos_x >= 0) |
1432 x = gui_video_pos_x; | |
1433 if (gui_video_pos_y >= 0) | |
1434 y = gui_video_pos_y; | |
23077 | 1435 |
1436 /* out of bounds check */ | |
1437 if (x <= -1 || (x+(rect.right-rect.left) > GetSystemMetrics(SM_CXSCREEN))) | |
1438 x = CW_USEDEFAULT; | |
1439 if (y <= -1 || (y+(rect.bottom-rect.top) > GetSystemMetrics(SM_CYSCREEN))) | |
1440 y = x; | |
1441 | |
34994 | 1442 gui->videowindow = CreateWindowEx(0, "MPlayer - Video", "MPlayer - Video", style, |
34995 | 1443 x, y, rect.right-rect.left, rect.bottom-rect.top, |
1444 NULL, NULL, instance, NULL); | |
23077 | 1445 |
1446 /* load all the window images */ | |
34994 | 1447 window_render(gui, gui->videowindow, hdc, priv, desc, binfo); |
23077 | 1448 |
1449 /* enable drag and drop support */ | |
34994 | 1450 DragAcceptFiles(gui->videowindow, TRUE); |
23077 | 1451 |
34697 | 1452 if(video_window) |
1453 WinID = gui->videowindow; | |
1454 ShowWindow(gui->videowindow, SW_SHOW); | |
1455 UpdateWindow(gui->videowindow); | |
23077 | 1456 return 0; |
1457 } | |
1458 | |
1459 /* loads/updates a skin and creates windows for it */ | |
28051 | 1460 int create_window(gui_t *gui, char *skindir) |
23077 | 1461 { |
1462 HINSTANCE instance = GetModuleHandle(NULL); | |
1463 WNDCLASS wc; | |
1464 RECT rect; | |
1465 DWORD style = 0; | |
1466 HDC hdc = NULL; | |
1467 BITMAPINFO binfo; | |
1468 window_priv_t *priv = NULL; | |
1469 window *desc = NULL; | |
1470 char dir[MAX_PATH]; | |
1471 unsigned int i; | |
1472 int x = -1, y = -1; | |
1473 | |
1474 /* destroy the current main window */ | |
1475 if(gui->skin) destroy_window(gui); | |
1476 | |
1477 /* get screenproperties */ | |
1478 gui->screenbpp = GetDesktopBitsPerPixel(); | |
1479 gui->screenw = GetSystemMetrics(SM_CXSCREEN); | |
1480 gui->screenh = GetSystemMetrics(SM_CYSCREEN); | |
1481 | |
1482 /* load the new skin */ | |
1483 gui->skin = loadskin(skindir, gui->screenbpp); | |
1484 if(!gui->skin) | |
1485 { | |
1486 mp_msg(MSGT_GPLAYER, MSGL_FATAL, "[GUI] fatal error during skinload\n"); | |
1487 /* Set default Skin */ | |
32537
8fa2f43cb760
Remove most of the NULL pointer check before free all over the code
cboesch
parents:
31532
diff
changeset
|
1488 free(skinName); |
23077 | 1489 skinName = strdup("Blue"); |
1490 /* then force write conf */ | |
1491 cfg_write(); | |
1492 return 1; | |
1493 } | |
1494 | |
1495 /* find the description of the mainwindow */ | |
1496 for (i=0; i<gui->skin->windowcount; i++) | |
1497 if(gui->skin->windows[i]->type == wiMain) | |
1498 desc = gui->skin->windows[i]; | |
1499 | |
1500 if(!desc) | |
1501 { | |
1502 mp_msg(MSGT_GPLAYER, MSGL_FATAL, "[GUI] Invalid skin description\n"); | |
1503 return 1; | |
1504 } | |
1505 | |
1506 /* load the icon from the executable */ | |
1507 GetModuleFileName(NULL, dir, MAX_PATH); | |
1508 gui->icon = ExtractIcon(instance, dir, 0); | |
1509 | |
1510 /* create the window class */ | |
1511 wc.style = CS_HREDRAW | CS_VREDRAW; | |
1512 wc.lpfnWndProc = EventProc; | |
1513 wc.cbClsExtra = 0; | |
1514 wc.cbWndExtra = 0; | |
1515 wc.hInstance = instance; | |
1516 wc.hCursor = LoadCursor(NULL, IDC_ARROW); | |
1517 wc.hIcon = gui->icon; | |
1518 wc.hbrBackground = CreateSolidBrush(RGB(0, 0, 0)); | |
34162 | 1519 wc.lpszClassName = gui->classname = "MPlayer"; |
23077 | 1520 wc.lpszMenuName = NULL; |
1521 RegisterClass(&wc); | |
1522 | |
1523 /* create a context menu */ | |
1524 create_menu(gui); | |
1525 /* create the systray menu */ | |
1526 create_traymenu(gui); | |
1527 | |
1528 /* create the mainwindow */ | |
1529 /* TODO implement aligning as described in skin.html */ | |
1530 rect.top = rect.left = 100; | |
1531 rect.bottom = rect.top+desc->base->bitmap[0]->height; | |
1532 rect.right = rect.left+desc->base->bitmap[0]->width; | |
1533 if(desc->decoration) style = WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX; | |
1534 else style = WS_POPUP | WS_SYSMENU; | |
1535 | |
1536 AdjustWindowRect(&rect, style, 0); | |
1537 | |
1538 /* Check if out of screen */ | |
1539 if (gui_main_pos_x >= 0) | |
1540 x = gui_main_pos_x; | |
1541 if (gui_main_pos_y >= 0) | |
1542 y = gui_main_pos_y; | |
1543 | |
1544 if (x <= -1 || (x+(rect.right-rect.left) > GetSystemMetrics(SM_CXFULLSCREEN))) | |
1545 { | |
1546 x = (GetSystemMetrics(SM_CXSCREEN) / 2) - ((rect.right-rect.left) / 2); | |
1547 gui_main_pos_x = x; | |
1548 } | |
1549 if (y <= -1 || (y+(rect.bottom-rect.top) > GetSystemMetrics(SM_CYFULLSCREEN))) | |
1550 { | |
1551 y = ((GetSystemMetrics(SM_CYSCREEN)-40) - (rect.bottom-rect.top)); | |
1552 gui_main_pos_y = y; | |
1553 } | |
1554 | |
34994 | 1555 gui->mainwindow = CreateWindowEx(0, gui->classname, "MPlayer", style, |
34995 | 1556 x, y, rect.right-rect.left, rect.bottom-rect.top, |
1557 NULL, NULL, instance, NULL); | |
23077 | 1558 |
1559 /* set the systray icon properties */ | |
1560 nid.cbSize = sizeof(NOTIFYICONDATA); | |
34994 | 1561 nid.hWnd = gui->mainwindow; |
23077 | 1562 nid.uID = 1; |
1563 nid.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP; | |
1564 nid.uCallbackMessage = WM_SYSTRAY; | |
1565 nid.hIcon = gui->icon; | |
34162 | 1566 strcpy(nid.szTip, "MPlayer"); |
23077 | 1567 |
1568 /* register the systray icon */ | |
1569 Shell_NotifyIcon(NIM_ADD, &nid); | |
1570 | |
1571 /* load all the window images */ | |
34994 | 1572 window_render(gui, gui->mainwindow, hdc, priv, desc, binfo); |
23077 | 1573 |
1574 /* enable drag and drop support */ | |
34994 | 1575 DragAcceptFiles(gui->mainwindow, TRUE); |
23077 | 1576 |
34994 | 1577 updatedisplay(gui, gui->mainwindow); |
23077 | 1578 |
1579 /* display */ | |
1580 ShowWindow(gui->mainwindow, SW_SHOW); | |
1581 UpdateWindow(gui->mainwindow); | |
1582 maketransparent(gui->mainwindow, RGB(255, 0, 255)); | |
1583 return 0; | |
1584 } | |
1585 | |
33781 | 1586 gui_t *create_gui(char *skindir, void (*playercontrol)(int event)) |
23077 | 1587 { |
1588 gui_t *gui = calloc(1, sizeof(gui_t)); | |
1589 char temp[MAX_PATH]; | |
34162 | 1590 HWND runningmplayer = FindWindow("MPlayer", "MPlayer"); |
23077 | 1591 |
1592 if(runningmplayer) | |
1593 { | |
1594 free(gui); | |
1595 return NULL; | |
1596 } | |
1597 | |
1598 gui->startplay = startplay; | |
1599 gui->playercontrol = playercontrol; | |
1600 gui->uninit = uninit; | |
1601 gui->updatedisplay = updatedisplay; | |
1602 | |
1603 /* create playlist */ | |
1604 gui->playlist = create_playlist(); | |
1605 | |
34092
dbf5042ab255
Don't use the Windows style path separator character in Win32 GUI.
ib
parents:
33965
diff
changeset
|
1606 sprintf(temp, "%s/%s", skindir, skinName); |
23077 | 1607 if(create_window(gui, temp)) return NULL; |
34697 | 1608 if(create_videowindow(gui)) return NULL; |
35001 | 1609 if(console) console_toggle(gui); |
23077 | 1610 return gui; |
1611 } |