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