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