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