Mercurial > mplayer.hg
annotate Gui/win32/gui.c @ 19311:0a4df538c136
moved pnm.h to stream/ (where it belongs)
author | ben |
---|---|
date | Fri, 04 Aug 2006 16:55:48 +0000 |
parents | 64d82a45a05d |
children | df307a050359 |
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; | |
19245 | 559 DWORD style, flags; |
18914 | 560 RECT rd; |
561 POINT pt; | |
562 while(ShowCursor(TRUE) <= 0){} | |
563 pt.x = 0; | |
564 pt.y = 0; | |
565 GetClientRect(hWnd, &rd); | |
566 ClientToScreen(hWnd, &pt); | |
567 | |
568 rect_width = rd.right - rd.left; | |
569 rect_height = rd.bottom - rd.top; | |
570 | |
571 /* maintain our aspect ratio */ | |
572 tmpheight = ((float)rect_width/sub_aspect); | |
573 tmpheight += tmpheight % 2; | |
574 if(tmpheight > rect_height) | |
575 { | |
576 rect_width = ((float)rect_height*sub_aspect); | |
577 rect_width += rect_width % 2; | |
578 } | |
579 else rect_height = tmpheight; | |
580 | |
581 rd.right = rd.left + rect_width; | |
582 rd.bottom = rd.top + rect_height; | |
583 | |
19245 | 584 if(fullscreen) |
585 { | |
586 style = WS_VISIBLE | WS_POPUP; | |
587 flags = SWP_NOZORDER | SWP_FRAMECHANGED; | |
588 } else { | |
589 style = WS_OVERLAPPEDWINDOW | WS_SIZEBOX; | |
590 flags = SWP_NOOWNERZORDER; | |
591 } | |
592 | |
593 AdjustWindowRect(&rd, style, 0); | |
594 SetWindowPos(hWnd, 0, fullscreen?0:pt.x+rd.left, fullscreen?0:pt.y+rd.top, | |
595 fullscreen?vo_screenwidth:rd.right-rd.left, fullscreen?vo_screenheight:rd.bottom-rd.top, flags); | |
18914 | 596 return 0; |
597 } | |
598 case WM_PAINT: | |
599 { | |
600 PAINTSTRUCT ps; | |
601 RECT rect; | |
602 HDC hdc = BeginPaint(hWnd, &ps); | |
603 HDC hMemDC = CreateCompatibleDC(hdc); | |
604 int width, height; | |
605 GetClientRect(hWnd, &rect); | |
606 width = rect.right - rect.left; | |
607 height = rect.bottom - rect.top; | |
608 if(guiIntfStruct.Playing == 0) | |
609 { | |
610 int i; | |
611 window *desc = NULL; | |
612 | |
613 for (i=0; i<gui->skin->windowcount; i++) | |
614 if(gui->skin->windows[i]->type == wiSub) | |
615 desc = gui->skin->windows[i]; | |
616 | |
617 SelectObject(hMemDC, get_bitmap(hWnd)); | |
618 StretchBlt(hdc, 0, 0, width, height, hMemDC, 0, 0, desc->base->bitmap[0]->width, | |
619 desc->base->bitmap[0]->height, SRCCOPY); | |
620 } | |
621 DeleteDC(hMemDC); | |
622 EndPaint(hWnd, &ps); | |
623 return 0; | |
624 } | |
625 } | |
626 return DefWindowProc(hWnd, message, wParam, lParam); | |
627 } | |
628 | |
629 /* Window Proc for the gui Window */ | |
630 static LRESULT CALLBACK EventProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) | |
631 { | |
632 gui_t *gui = (gui_t *) GetWindowLongPtr(hWnd, GWLP_USERDATA); | |
633 | |
634 /* Avoid processing when then window doesn't match gui mainwindow */ | |
635 if (gui && (gui->mainwindow != hWnd)) return FALSE; | |
636 | |
637 switch (message) | |
638 { | |
639 case WM_CLOSE: | |
640 handlemsg(hWnd, evExit); | |
641 return 0; | |
642 case WM_DESTROY: | |
643 PostQuitMessage(0); | |
644 return 0; | |
645 case WM_SYSTRAY: | |
646 { | |
647 switch(lParam) | |
648 { | |
649 POINT cursor; | |
650 case WM_RBUTTONDOWN: | |
651 { | |
652 GetCursorPos(&cursor); | |
653 SetForegroundWindow(hWnd); | |
654 TrackPopupMenu(gui->traymenu, 0, cursor.x, cursor.y, 0, hWnd, NULL); | |
655 break; | |
656 } | |
657 case WM_MBUTTONDBLCLK: | |
658 case WM_LBUTTONDBLCLK: | |
659 { | |
660 if(IsWindowVisible(hWnd)) ShowWindow(hWnd, SW_HIDE); | |
661 else { ShowWindow(hWnd, SW_SHOW); SetForegroundWindow(hWnd); } | |
662 break; | |
663 } | |
664 } | |
665 break; | |
666 } | |
667 case WM_KEYDOWN: | |
668 { | |
669 switch(wParam) | |
670 { | |
671 case VK_LEFT: | |
672 mplayer_put_key(KEY_LEFT); | |
673 break; | |
674 case VK_UP: | |
675 mplayer_put_key(KEY_UP); | |
676 break; | |
677 case VK_RIGHT: | |
678 mplayer_put_key(KEY_RIGHT); | |
679 break; | |
680 case VK_DOWN: | |
681 mplayer_put_key(KEY_DOWN); | |
682 break; | |
683 case VK_TAB: | |
684 mplayer_put_key(KEY_TAB); | |
685 break; | |
686 case VK_BACK: | |
687 mplayer_put_key(KEY_BS); | |
688 break; | |
689 case VK_DELETE: | |
690 mplayer_put_key(KEY_DELETE); | |
691 break; | |
692 case VK_INSERT: | |
693 mplayer_put_key(KEY_INSERT); | |
694 break; | |
695 case VK_HOME: | |
696 mplayer_put_key(KEY_HOME); | |
697 break; | |
698 case VK_END: | |
699 mplayer_put_key(KEY_END); | |
700 break; | |
701 case VK_PRIOR: | |
702 mplayer_put_key(KEY_PAGE_UP); | |
703 break; | |
704 case VK_NEXT: | |
705 mplayer_put_key(KEY_PAGE_DOWN); | |
706 break; | |
707 case VK_ESCAPE: | |
708 mplayer_put_key(KEY_ESC); | |
709 break; | |
710 } | |
711 break; | |
712 } | |
713 case WM_CHAR: | |
714 mplayer_put_key(wParam); | |
715 break; | |
716 case WM_SYSCOMMAND: | |
717 { | |
718 switch(wParam) | |
719 { | |
720 case SC_SCREENSAVE: | |
721 case SC_MONITORPOWER: | |
722 mp_msg(MSGT_VO, MSGL_V ,"<vo_directx><INFO>killing screensaver\n" ); | |
723 return 0; | |
724 } | |
725 break; | |
726 } | |
727 case WM_COPYDATA: | |
728 { | |
729 if(lParam) | |
730 { | |
731 PCOPYDATASTRUCT cdData; | |
732 cdData = (PCOPYDATASTRUCT) lParam; | |
733 if(!parse_filename(cdData->lpData, playtree, mconfig, 1)) | |
734 gui->playlist->add_track(gui->playlist, cdData->lpData, NULL, NULL, 0); | |
735 gui->startplay(gui); | |
736 } | |
737 break; | |
738 } | |
739 case WM_DROPFILES: | |
740 { | |
741 if(!lParam) | |
742 { | |
743 char file[MAX_PATH]; | |
744 int filecount = DragQueryFile((HDROP) wParam, -1, file, MAX_PATH); | |
745 int i; | |
746 for(i=0; i<filecount; i++) | |
747 { | |
748 DragQueryFile((HDROP) wParam, i, file, MAX_PATH); | |
749 if(!parse_filename(file, playtree, mconfig, 1)) | |
750 gui->playlist->add_track(gui->playlist, file, NULL, NULL, 0); | |
751 } | |
752 DragFinish((HDROP) wParam); | |
753 handlemsg(hWnd, evDropFile); | |
754 } | |
755 else | |
756 { | |
757 gui->playlist->clear_playlist(gui->playlist); | |
758 gui->playlist->add_track(gui->playlist, (const char *) wParam, NULL, NULL, 0); | |
759 handlemsg(hWnd, evDropFile); | |
760 } | |
761 SetForegroundWindow(gui->mainwindow); | |
762 return 0; | |
763 } | |
764 case WM_LBUTTONDOWN: | |
765 { | |
766 SetCapture(hWnd); | |
767 gui->mousex = GET_X_LPARAM(lParam); | |
768 gui->mousey = GET_Y_LPARAM(lParam); | |
769 /* inside a widget */ | |
770 gui->activewidget = clickedinsidewidget(gui, get_windowtype(hWnd), gui->mousex, gui->mousey); | |
771 if(gui->activewidget) | |
772 { | |
773 gui->activewidget->pressed = 1; | |
774 gui->mousewx = gui->mousex - gui->activewidget->x; | |
775 gui->mousewy = gui->mousey - gui->activewidget->y; | |
776 renderwidget(gui->skin, get_drawground(hWnd), gui->activewidget, 0); | |
777 RedrawWindow(hWnd, NULL, NULL, RDW_INVALIDATE); | |
778 handlemsg(hWnd, gui->activewidget->msg); | |
779 } | |
780 break; | |
781 } | |
782 case WM_CAPTURECHANGED: | |
783 { | |
784 if(gui->activewidget) | |
785 { | |
786 gui->activewidget->pressed = 0; | |
787 renderwidget(gui->skin, get_drawground(hWnd), gui->activewidget, 1); | |
788 RedrawWindow(hWnd, NULL, NULL, RDW_INVALIDATE); | |
789 gui->activewidget = NULL; | |
790 } | |
791 break; | |
792 } | |
793 case WM_LBUTTONUP: | |
794 { | |
795 ReleaseCapture(); | |
796 if(gui->activewidget) | |
797 { | |
798 gui->activewidget->pressed = 0; | |
799 renderwidget(gui->skin, get_drawground(hWnd), gui->activewidget, 1); | |
800 RedrawWindow(hWnd, NULL, NULL, RDW_INVALIDATE); | |
801 gui->activewidget = NULL; | |
802 } | |
803 break; | |
804 } | |
805 case WM_RBUTTONDOWN: | |
806 { | |
807 POINT point; | |
808 char device[MAX_PATH]; | |
809 char searchpath[MAX_PATH]; | |
810 char searchpath2[MAX_PATH]; | |
811 #ifdef HAVE_LIBCDIO | |
812 char searchpath3[MAX_PATH]; | |
813 #endif | |
814 int len, pos = 0, cdromdrive = 0; | |
815 point.x = GET_X_LPARAM(lParam); | |
816 point.y = GET_Y_LPARAM(lParam); | |
817 ClientToScreen(hWnd, &point); | |
818 len = GetLogicalDriveStrings(MAX_PATH, device); | |
819 while(pos < len) | |
820 { | |
821 if(GetDriveType(device + pos) == DRIVE_CDROM) | |
822 { | |
823 mp_msg(MSGT_GPLAYER, MSGL_V, "[GUI] checking %s for CD/VCD/SVCD/DVDs\n", device + pos); | |
824 sprintf(searchpath, "%sVIDEO_TS", device + pos); | |
825 sprintf(searchpath2, "%sMpegav", device + pos); | |
826 #ifdef HAVE_LIBCDIO | |
827 sprintf(searchpath3, "%sTrack01.cda", device + pos); | |
828 #endif | |
829 if(GetFileAttributes(searchpath) != INVALID_FILE_ATTRIBUTES) | |
830 EnableMenuItem(gui->diskmenu, IDPLAYDISK + cdromdrive, MF_BYCOMMAND | MF_ENABLED); | |
831 else if(GetFileAttributes(searchpath2) != INVALID_FILE_ATTRIBUTES) | |
832 EnableMenuItem(gui->diskmenu, IDPLAYDISK + cdromdrive, MF_BYCOMMAND | MF_ENABLED); | |
833 #ifdef HAVE_LIBCDIO | |
834 else if(GetFileAttributes(searchpath3) != INVALID_FILE_ATTRIBUTES) | |
835 EnableMenuItem(gui->diskmenu, IDPLAYDISK + cdromdrive, MF_BYCOMMAND | MF_ENABLED); | |
836 #endif | |
837 else EnableMenuItem(gui->diskmenu, IDPLAYDISK + cdromdrive, MF_BYCOMMAND | MF_GRAYED); | |
838 cdromdrive++; | |
839 } | |
840 pos += strlen(device + pos) + 1; | |
841 } | |
842 TrackPopupMenu(gui->menu, 0, point.x, point.y, 0, hWnd, NULL); | |
843 return 0; | |
844 } | |
845 case WM_MOUSEMOVE: | |
846 { | |
847 if(wParam & MK_LBUTTON) | |
848 { | |
849 POINT point; | |
850 RECT rect; | |
851 if(gui->activewidget) | |
852 { | |
853 widget *item = gui->activewidget; | |
854 | |
855 if(item->type == tyHpotmeter) | |
856 { | |
857 item->x = GET_X_LPARAM(lParam) - gui->mousewx; | |
858 item->value = (float)((float)((item->x - item->wx) * 100.0f) / (float)(item->wwidth - item->width)); | |
859 } | |
860 if(item->type == tyPotmeter) | |
861 { | |
862 gui->mousewx = GET_X_LPARAM(lParam) - gui->activewidget->x; | |
863 item->value = (float) (gui->mousewx * 100.0f) / (float) item->wwidth; | |
864 } | |
865 | |
866 if((item->type == tyPotmeter) || (item->type == tyHpotmeter) || (item->type == tyVpotmeter)) | |
867 { | |
868 /* Bound checks */ | |
869 if(item->value > 100.0f) | |
870 item->value = 100.0f; | |
871 else if(item->value < 0.0f) | |
872 item->value = 0.0f; | |
873 | |
874 if(item->msg == evSetVolume) | |
875 guiIntfStruct.Volume = (float) item->value; | |
876 else if(item->msg == evSetMoviePosition) | |
877 guiIntfStruct.Position = (float) item->value; | |
878 else if(item->msg == evSetBalance) | |
879 { | |
880 /* make the range for 50% a bit bigger, because the sliders for balance usually suck */ | |
881 if((item->value - 50.0f < 1.5f) && (item->value - 50.0f > -1.5f)) | |
882 item->value = 50.0f; | |
883 guiIntfStruct.Balance = (float) item->value; | |
884 } | |
885 updatedisplay(gui, hWnd); | |
886 handlemsg(hWnd, item->msg); | |
887 } | |
888 break; | |
889 } | |
890 point.x = GET_X_LPARAM(lParam); | |
891 point.y = GET_Y_LPARAM(lParam); | |
892 ClientToScreen(hWnd, &point); | |
893 GetWindowRect(hWnd, &rect); | |
894 MoveWindow(hWnd, point.x - gui->mousex, point.y - gui->mousey, | |
895 rect.right-rect.left,rect.bottom-rect.top,TRUE); | |
896 break; | |
897 } | |
898 break; | |
899 } | |
900 case WM_COMMAND: | |
901 { | |
902 switch(LOWORD(wParam)) | |
903 { | |
904 case IDEXIT: | |
905 PostQuitMessage(0); | |
906 handlemsg(hWnd, evExit); | |
907 break; | |
908 case IDFILE_OPEN: | |
909 handlemsg(hWnd, evLoadPlay); | |
910 break; | |
911 case IDDIR_OPEN: | |
912 { | |
913 static char path[MAX_PATH]; | |
914 BROWSEINFO bi; | |
915 memset(&bi, 0, sizeof(BROWSEINFO)); | |
916 bi.lpszTitle = "Choose a Directory..."; | |
917 LPITEMIDLIST pidl = SHBrowseForFolder(&bi); | |
918 if (SHGetPathFromIDList(pidl, path)) | |
919 { | |
920 gui->playlist->clear_playlist(gui->playlist); | |
921 adddirtoplaylist(gui->playlist, path, TRUE); | |
922 gui->startplay(gui); | |
923 } | |
924 break; | |
925 } | |
926 case ID_SKINBROWSER: | |
927 handlemsg(hWnd, evSkinBrowser); | |
928 break; | |
929 case IDURL_OPEN: | |
930 display_openurlwindow(gui, 0); | |
931 break; | |
932 #ifdef USE_SUB | |
933 case IDSUBTITLE_OPEN: | |
934 display_opensubtitlewindow(gui); | |
935 break; | |
936 #endif | |
937 case ID_PTRACK: | |
938 handlemsg(hWnd, evPrev); | |
939 break; | |
940 case ID_SEEKB: | |
941 handlemsg(hWnd, evBackward10sec); | |
942 break; | |
943 case ID_PLAY: | |
944 handlemsg(hWnd, evPlaySwitchToPause); | |
945 break; | |
946 case ID_STOP: | |
947 handlemsg(hWnd, evStop); | |
948 break; | |
949 case ID_SEEKF: | |
950 handlemsg(hWnd, evForward10sec); | |
951 break; | |
952 case ID_NTRACK: | |
953 handlemsg(hWnd, evNext); | |
954 break; | |
955 case ID_SHOWHIDE: | |
956 { | |
957 if(IsWindowVisible(hWnd)) ShowWindow(hWnd, SW_HIDE); | |
958 else ShowWindow(hWnd, SW_SHOW); | |
959 break; | |
960 } | |
961 case ID_PLAYLIST: | |
962 handlemsg(hWnd, evPlayList); | |
963 break; | |
964 case ID_PREFS: | |
965 handlemsg(hWnd, evPreferences); | |
966 break; | |
967 case ID_CONSOLE: | |
968 console_toggle(); | |
969 break; | |
970 case ID_ONLINEHELP: | |
971 ShellExecute(NULL, "open", ONLINE_HELP_URL, NULL, NULL, SW_SHOWNORMAL); | |
972 break; | |
973 } | |
974 if((IDPLAYDISK <= LOWORD(wParam)) && (LOWORD(wParam) < (IDPLAYDISK + 100))) | |
975 { | |
976 char device[MAX_PATH]; | |
977 char searchpath[MAX_PATH]; | |
978 char filename[MAX_PATH]; | |
979 int len, pos = 0, cdromdrive = 0; | |
980 len = GetLogicalDriveStrings(MAX_PATH, device); | |
981 while(pos < len) | |
982 { | |
983 if(GetDriveType(device + pos)==DRIVE_CDROM) | |
984 { | |
985 if(LOWORD(wParam) - IDPLAYDISK == cdromdrive) | |
986 { | |
987 #ifdef USE_DVDREAD | |
988 sprintf(searchpath, "%sVIDEO_TS", device + pos); | |
989 if(GetFileAttributes(searchpath) != INVALID_FILE_ATTRIBUTES) | |
990 { | |
991 if (dvd_device) free(dvd_device); | |
992 dvd_device = strdup(device + pos); | |
993 dvd_title = dvd_chapter = dvd_angle = 1; | |
994 handlemsg(hWnd, evPlayDVD); | |
995 } | |
996 #endif | |
997 #ifdef HAVE_LIBCDIO | |
998 sprintf(searchpath, "%sTrack01.cda", device + pos); | |
999 if(GetFileAttributes(searchpath) != INVALID_FILE_ATTRIBUTES) | |
1000 { | |
1001 if (cdrom_device) free(cdrom_device); | |
1002 cdrom_device = strdup(device + pos); | |
1003 /* mplayer doesn't seem to like the trailing \ after the device name */ | |
1004 cdrom_device[2]=0; | |
1005 handlemsg(hWnd, evPlayCD); | |
1006 } | |
1007 #endif | |
1008 else | |
1009 { | |
1010 HANDLE searchhndl; | |
1011 WIN32_FIND_DATA finddata; | |
1012 sprintf(searchpath, "%smpegav\\*.dat", device + pos); | |
1013 if((searchhndl=FindFirstFile(searchpath, &finddata)) != INVALID_HANDLE_VALUE) | |
1014 { | |
1015 mp_msg(MSGT_GPLAYER,MSGL_V, "Opening VCD/SVCD\n"); | |
1016 gui->playlist->clear_playlist(gui->playlist); | |
1017 do | |
1018 { | |
1019 sprintf(filename, "%smpegav\\%s", device + pos, finddata.cFileName); | |
1020 gui->playlist->add_track(gui->playlist, filename, NULL, NULL, 0); | |
1021 } | |
1022 while(FindNextFile(searchhndl, &finddata)); | |
1023 FindClose(searchhndl); | |
1024 } | |
1025 gui->startplay(gui); | |
1026 } | |
1027 } | |
1028 cdromdrive++; | |
1029 } | |
1030 pos += strlen(device + pos) + 1; | |
1031 } | |
1032 } | |
1033 break; | |
1034 } | |
1035 case WM_PAINT: | |
1036 { | |
1037 PAINTSTRUCT ps; | |
1038 RECT rd; | |
1039 HDC hdc = BeginPaint(hWnd, &ps); | |
1040 HDC hMemDC = CreateCompatibleDC(hdc); | |
1041 int width, height; | |
1042 GetClientRect(hWnd, &rd); | |
1043 width = rd.right - rd.left; | |
1044 height = rd.bottom - rd.top; | |
1045 SelectObject(hMemDC, get_bitmap(hWnd)); | |
1046 BitBlt(hdc, 0, 0, width, height, hMemDC, 0, 0, SRCCOPY); | |
1047 DeleteDC(hMemDC); | |
1048 EndPaint(hWnd, &ps); | |
1049 return 0; | |
1050 } | |
1051 return 0; | |
1052 } | |
1053 return DefWindowProc(hWnd, message, wParam, lParam); | |
1054 } | |
1055 | |
1056 inline void startplay(gui_t *gui) | |
1057 { | |
1058 handlemsg(gui->mainwindow, evDropFile); | |
1059 } | |
1060 | |
1061 /* returns the bits per pixel of the desktop */ | |
1062 /* the format is always in BGR byte order */ | |
1063 static int GetDesktopBitsPerPixel(void) | |
1064 { | |
1065 HWND desktop=GetDesktopWindow(); | |
1066 HDC dc=GetDC(desktop); | |
1067 int bpp=GetDeviceCaps(dc, BITSPIXEL); | |
1068 ReleaseDC(desktop, dc); | |
1069 return bpp; | |
1070 } | |
1071 | |
1072 /* unloads a skin and destroys its windows */ | |
1073 extern int destroy_window(gui_t *gui) | |
1074 { | |
1075 RECT rd; | |
1076 unsigned int i; | |
1077 | |
1078 /* Save position: MSDN says don't pass workspace coordinates | |
1079 * to CreateWindow() or SetWindowPos(), as both of which expect | |
1080 * screen coordinates; resulting in the window appearing in the | |
1081 * wrong location. | |
1082 * -Erik | |
1083 */ | |
1084 | |
1085 /* main window position */ | |
1086 if(IsIconic(gui->mainwindow)) | |
1087 ShowWindow(gui->mainwindow, SW_SHOWNORMAL); | |
1088 GetWindowRect(gui->mainwindow, &rd); | |
1089 gui_main_pos_x = rd.left; | |
1090 gui_main_pos_y = rd.top; | |
1091 | |
1092 /* sub window position */ | |
1093 if(IsIconic(gui->subwindow)) | |
1094 ShowWindow(gui->subwindow, SW_SHOWNORMAL); | |
1095 GetWindowRect(gui->subwindow, &rd); | |
1096 gui_sub_pos_x = rd.left; | |
1097 gui_sub_pos_y = rd.top; | |
1098 | |
1099 for(i=0; i<gui->window_priv_count; i++) | |
1100 { | |
1101 if(gui->window_priv[i]->bitmap) | |
1102 DeleteObject(gui->window_priv[i]->bitmap); | |
1103 free(gui->window_priv[i]); | |
1104 } | |
1105 free(gui->window_priv); | |
1106 gui->window_priv = NULL; | |
1107 gui->window_priv_count = 0; | |
1108 | |
1109 /* destroy the main window */ | |
1110 if(gui->mainwindow) | |
1111 DestroyWindow(gui->mainwindow); | |
1112 gui->mainwindow = NULL; | |
1113 | |
1114 /* destroy the sub window */ | |
1115 if(gui->subwindow) | |
1116 DestroyWindow(gui->subwindow); | |
1117 gui->subwindow = NULL; | |
1118 | |
1119 UnregisterClass(gui->classname, 0); | |
1120 DestroyIcon(gui->icon); | |
1121 | |
1122 gui->skin->freeskin(gui->skin); | |
1123 gui->skin = NULL; | |
1124 return 0; | |
1125 } | |
1126 | |
1127 static void create_menu(gui_t *gui) | |
1128 { | |
1129 char device[MAX_PATH]; | |
1130 char volname[MAX_PATH]; | |
1131 char menuitem[MAX_PATH]; | |
1132 int len, pos = 0, cdromdrive = 0; | |
1133 gui->diskmenu = CreatePopupMenu(); | |
1134 len = GetLogicalDriveStrings(MAX_PATH, device); | |
1135 while(pos < len) | |
1136 { | |
1137 if(GetDriveType(device + pos) == DRIVE_CDROM) | |
1138 { | |
1139 volname[0] = 0; | |
1140 menuitem[0] = 0; | |
1141 strcat(menuitem, device + pos); | |
1142 menuitem[strlen(menuitem) - 1]=0; | |
1143 GetVolumeInformation(device + pos, volname, MAX_PATH, NULL, NULL, NULL, NULL, 0); | |
1144 if (strlen(volname)) | |
1145 { | |
1146 capitalize(volname); | |
1147 strcat(menuitem, " - "); | |
1148 strcat(menuitem, volname); | |
1149 } | |
1150 AppendMenu(gui->diskmenu, MF_STRING, IDPLAYDISK + cdromdrive, menuitem); | |
1151 cdromdrive++; | |
1152 } | |
1153 pos += strlen(device + pos) + 1; | |
1154 } | |
1155 gui->menu=CreatePopupMenu(); | |
1156 gui->trayplaymenu = CreatePopupMenu(); | |
1157 AppendMenu(gui->menu, MF_STRING | MF_POPUP, (UINT) gui->trayplaymenu, "Open..."); | |
1158 AppendMenu(gui->trayplaymenu, MF_STRING, IDFILE_OPEN, "File..."); | |
1159 AppendMenu(gui->trayplaymenu, MF_STRING, IDURL_OPEN, "Url..."); | |
1160 AppendMenu(gui->trayplaymenu, MF_STRING, IDDIR_OPEN, "Directory..."); | |
1161 AppendMenu(gui->menu, MF_SEPARATOR, 0, 0); | |
1162 AppendMenu(gui->menu, MF_STRING | MF_POPUP, (UINT) gui->diskmenu, "Play &CD/DVD/VCD/SVCD"); | |
1163 AppendMenu(gui->menu, MF_SEPARATOR, 0, 0); | |
1164 #ifdef USE_SUB | |
1165 AppendMenu(gui->menu, MF_STRING, IDSUBTITLE_OPEN, "Open Subtitle"); | |
1166 #endif | |
1167 AppendMenu(gui->menu, MF_STRING, ID_SKINBROWSER, "Skin Browser"); | |
1168 AppendMenu(gui->menu, MF_SEPARATOR, 0, 0); | |
1169 AppendMenu(gui->menu, MF_STRING, ID_PREFS, "Preferences"); | |
1170 AppendMenu(gui->menu, MF_STRING, ID_CONSOLE, "Debug Console"); | |
1171 AppendMenu(gui->menu, MF_STRING, ID_ONLINEHELP, "Online Help"); | |
1172 AppendMenu(gui->menu, MF_SEPARATOR, 0, 0); | |
1173 AppendMenu(gui->menu, MF_STRING, IDEXIT, "&Exit"); | |
1174 } | |
1175 | |
1176 static void create_traymenu(gui_t *gui) | |
1177 { | |
1178 gui->traymenu = CreatePopupMenu(); | |
1179 gui->trayplaybackmenu = CreatePopupMenu(); | |
1180 AppendMenu(gui->traymenu, MF_STRING | MF_POPUP, (UINT) gui->trayplaymenu, "Open..."); | |
1181 AppendMenu(gui->traymenu, MF_SEPARATOR, 0, 0); | |
1182 AppendMenu(gui->traymenu, MF_STRING | MF_POPUP, (UINT) gui->trayplaybackmenu, "Playback"); | |
1183 AppendMenu(gui->trayplaybackmenu, MF_STRING, ID_SEEKB, "Seek Backwards"); | |
1184 AppendMenu(gui->trayplaybackmenu, MF_STRING, ID_PTRACK, "Previous Track"); | |
1185 AppendMenu(gui->trayplaybackmenu, MF_STRING, ID_PLAY, "Play/Pause"); | |
1186 AppendMenu(gui->trayplaybackmenu, MF_STRING, ID_STOP, "Stop"); | |
1187 AppendMenu(gui->trayplaybackmenu, MF_STRING, ID_NTRACK, "Next Track"); | |
1188 AppendMenu(gui->trayplaybackmenu, MF_STRING, ID_SEEKF, "Seek Forwards"); | |
1189 AppendMenu(gui->traymenu, MF_SEPARATOR, 0, 0); | |
1190 #ifdef USE_SUB | |
1191 AppendMenu(gui->traymenu, MF_STRING, IDSUBTITLE_OPEN, "Open Subtitle"); | |
1192 #endif | |
1193 AppendMenu(gui->traymenu, MF_STRING, ID_PLAYLIST, "Playlist"); | |
1194 AppendMenu(gui->traymenu, MF_SEPARATOR, 0, 0); | |
1195 AppendMenu(gui->traymenu, MF_STRING, ID_SHOWHIDE, "Show/Hide"); | |
1196 AppendMenu(gui->traymenu, MF_SEPARATOR, 0, 0); | |
1197 AppendMenu(gui->traymenu, MF_STRING, ID_PREFS, "Preferences"); | |
1198 AppendMenu(gui->traymenu, MF_STRING, ID_CONSOLE, "Debug Console"); | |
1199 AppendMenu(gui->traymenu, MF_STRING, ID_ONLINEHELP, "Online Help"); | |
1200 AppendMenu(gui->traymenu, MF_SEPARATOR, 0, 0); | |
1201 AppendMenu(gui->traymenu, MF_STRING, IDEXIT, "&Exit"); | |
1202 } | |
1203 | |
1204 static void create_submenu(gui_t *gui) | |
1205 { | |
1206 gui->submenu = CreatePopupMenu(); | |
1207 gui->dvdmenu = CreatePopupMenu(); | |
1208 gui->aspectmenu = CreatePopupMenu(); | |
1209 gui->subtitlemenu = CreatePopupMenu(); | |
1210 AppendMenu(gui->submenu, MF_STRING | MF_POPUP, (UINT) gui->trayplaymenu, "Open..."); | |
1211 AppendMenu(gui->submenu, MF_SEPARATOR, 0, 0); | |
1212 AppendMenu(gui->submenu, MF_STRING, ID_SEEKB, "Seek Backwards"); | |
1213 AppendMenu(gui->submenu, MF_STRING, ID_PTRACK, "Previous Track"); | |
1214 AppendMenu(gui->submenu, MF_STRING, ID_PLAY, "Play/Pause"); | |
1215 AppendMenu(gui->submenu, MF_STRING, ID_STOP, "Stop"); | |
1216 AppendMenu(gui->submenu, MF_STRING, ID_NTRACK, "Next Track"); | |
1217 AppendMenu(gui->submenu, MF_STRING, ID_SEEKF, "Seek Forwards"); | |
1218 AppendMenu(gui->submenu, MF_SEPARATOR, 0, 0); | |
1219 AppendMenu(gui->submenu, MF_STRING | MF_POPUP, (UINT) gui->aspectmenu, "Aspect Ratio"); | |
1220 AppendMenu(gui->submenu, MF_STRING | MF_POPUP, (UINT) gui->subtitlemenu, "Subtitle Options"); | |
1221 AppendMenu(gui->submenu, MF_STRING | MF_POPUP, (UINT) gui->dvdmenu, "DVD Options"); | |
1222 #ifdef USE_DVDREAD | |
1223 AppendMenu(gui->dvdmenu, MF_STRING | MF_GRAYED, ID_CHAPTERSEL, "Select Title/Chapter..."); | |
1224 #endif | |
1225 AppendMenu(gui->subtitlemenu, MF_STRING, IDSUB_TOGGLE, "Subtitle Visibility On/Off"); | |
1226 AppendMenu(gui->subtitlemenu, MF_STRING, IDSUB_CYCLE, "Cycle Subtitle Languages"); | |
1227 AppendMenu(gui->aspectmenu, MF_STRING, ID_ASPECT1, "Set 16:9"); | |
1228 AppendMenu(gui->aspectmenu, MF_STRING, ID_ASPECT2, "Set 4:3"); | |
1229 AppendMenu(gui->aspectmenu, MF_STRING, ID_ASPECT3, "Set 2.35"); | |
1230 AppendMenu(gui->aspectmenu, MF_SEPARATOR, 0, 0); | |
1231 AppendMenu(gui->aspectmenu, MF_STRING, ID_ASPECT4, "Original Aspect"); | |
1232 AppendMenu(gui->submenu, MF_SEPARATOR, 0, 0); | |
1233 AppendMenu(gui->submenu, MF_STRING, IDEXIT, "&Exit"); | |
1234 } | |
1235 | |
1236 static void maketransparent(HWND hwnd, COLORREF crTransparent) | |
1237 { | |
1238 HDC mdc = GetDC(hwnd); | |
1239 RECT rd; | |
1240 HRGN crRgnres, crRgn, crRgnTmp; | |
1241 int iX = 0, iY = 0, iLeftX = 0; | |
1242 int width, height; | |
1243 GetWindowRect(hwnd, &rd); | |
1244 width = rd.right - rd.left; | |
1245 height = rd.bottom - rd.top; | |
1246 | |
1247 /* create an empty region */ | |
1248 crRgn = CreateRectRgn(0, 0, 0, 0); | |
1249 | |
1250 /* Create a region from a bitmap with transparency colour of Purple */ | |
1251 for (iY = -1; iY < height; iY++) | |
1252 { | |
1253 do | |
1254 { | |
1255 /* skip over transparent pixels at start of lines */ | |
1256 while (iX <= width && GetPixel(mdc,iX, iY) == crTransparent) iX++; | |
1257 | |
1258 /* remember this pixel */ | |
1259 iLeftX = iX; | |
1260 | |
1261 /* now find first non transparent pixel */ | |
1262 while (iX <= width && GetPixel(mdc,iX, iY) != crTransparent) ++iX; | |
1263 | |
1264 /* create a temp region on this info */ | |
1265 crRgnTmp = CreateRectRgn(iLeftX, iY, iX, iY+1); | |
1266 | |
1267 /* combine into main region */ | |
1268 crRgnres = crRgn; | |
1269 CombineRgn(crRgnres, crRgn, crRgnTmp, RGN_OR); | |
1270 crRgn = crRgnres; | |
1271 | |
1272 /* delete the temp region for next pass (otherwise you'll get an ASSERT) */ | |
1273 DeleteObject(crRgnTmp); | |
1274 } while (iX < width); | |
1275 iX = 0; | |
1276 } | |
1277 SetWindowRgn(hwnd, crRgn, TRUE); | |
1278 DeleteObject(crRgn); | |
1279 ReleaseDC(hwnd,mdc); | |
1280 } | |
1281 | |
1282 static int window_render(gui_t *gui, HWND hWnd, HDC hdc, window_priv_t *priv, window *desc, BITMAPINFO binfo) | |
1283 { | |
1284 int i; | |
1285 SetWindowLongPtr(hWnd, GWLP_USERDATA, (DWORD) gui); | |
1286 (gui->window_priv_count)++; | |
1287 gui->window_priv = realloc(gui->window_priv, sizeof(window_priv_t *) * gui->window_priv_count); | |
1288 priv = gui->window_priv[gui->window_priv_count - 1] = calloc(1, sizeof(window_priv_t)); | |
1289 priv->hwnd = hWnd; | |
1290 priv->type = desc->type; | |
1291 priv->background = desc->base->bitmap[0]; | |
1292 memcpy(&priv->img, desc->base->bitmap[0], sizeof(image)); | |
1293 hdc = GetDC(hWnd); | |
1294 binfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); | |
1295 binfo.bmiHeader.biWidth = priv->img.width; | |
1296 binfo.bmiHeader.biHeight = -priv->img.height; | |
1297 binfo.bmiHeader.biPlanes = 1; | |
1298 binfo.bmiHeader.biSizeImage = priv->img.width * priv->img.height * (gui->screenbpp / 8); | |
1299 binfo.bmiHeader.biXPelsPerMeter = 0; | |
1300 binfo.bmiHeader.biYPelsPerMeter = 0; | |
1301 binfo.bmiHeader.biClrUsed = 0; | |
1302 binfo.bmiHeader.biClrImportant = 0; | |
1303 binfo.bmiHeader.biBitCount = gui->screenbpp; | |
1304 binfo.bmiHeader.biCompression = BI_RGB; | |
1305 priv->bitmap = CreateDIBSection(hdc, &binfo, DIB_RGB_COLORS, (void **) &priv->img.data, NULL, 0); | |
1306 if(!priv->bitmap) | |
1307 { | |
1308 mp_msg(MSGT_GPLAYER, MSGL_FATAL, "[GUI] unable to create bitmap for skinned window\n"); | |
1309 return 0; | |
1310 } | |
1311 memcpy(priv->img.data, desc->base->bitmap[0]->data, binfo.bmiHeader.biSizeImage); | |
1312 ReleaseDC(hWnd,hdc); | |
1313 | |
1314 for (i=0; i<gui->skin->widgetcount; i++) | |
1315 if(gui->skin->widgets[i]->window == desc->type) | |
1316 renderwidget(gui->skin, &priv->img, gui->skin->widgets[i], 1); | |
1317 | |
1318 return 0; | |
1319 } | |
1320 | |
1321 /* creates the sub (AKA video) window,*/ | |
1322 extern int create_subwindow(gui_t *gui, char *skindir) | |
1323 { | |
1324 HINSTANCE instance = GetModuleHandle(NULL); | |
1325 WNDCLASS wc; | |
1326 RECT rect; | |
1327 HWND hWnd; | |
1328 DWORD style = 0; | |
1329 HDC hdc = NULL; | |
1330 BITMAPINFO binfo; | |
1331 window_priv_t *priv = NULL; | |
1332 window *desc = NULL; | |
1333 int i, x = -1, y = -1; | |
19245 | 1334 vo_colorkey = 0xff000000; |
18914 | 1335 |
1336 for (i=0; i<gui->skin->windowcount; i++) | |
1337 if(gui->skin->windows[i]->type == wiSub) | |
1338 desc = gui->skin->windows[i]; | |
1339 | |
1340 if(!desc) | |
1341 { | |
1342 mp_msg(MSGT_GPLAYER, MSGL_FATAL, "[GUI] Invalid skin description\n"); | |
1343 return 1; | |
1344 } | |
1345 | |
1346 wc.style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS; | |
1347 wc.lpfnWndProc = SubProc; | |
1348 wc.cbClsExtra = 0; | |
1349 wc.cbWndExtra = 0; | |
1350 wc.hInstance = instance; | |
1351 wc.hCursor = LoadCursor(NULL, IDC_ARROW); | |
1352 wc.hIcon = gui->icon; | |
19245 | 1353 wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH); |
18914 | 1354 wc.lpszClassName = "MPlayer Sub for Windows"; |
1355 wc.lpszMenuName = NULL; | |
1356 RegisterClass(&wc); | |
1357 | |
1358 /* create the sub window menu */ | |
1359 create_submenu(gui); | |
1360 | |
1361 rect.top = rect.left = 100; | |
1362 rect.bottom = rect.top+desc->base->bitmap[0]->height; | |
1363 rect.right = rect.left+desc->base->bitmap[0]->width; | |
1364 | |
1365 /* our window aspect */ | |
1366 sub_aspect = (float)(rect.right-rect.left)/(rect.bottom-rect.top); | |
1367 | |
1368 style = WS_OVERLAPPEDWINDOW | WS_SYSMENU | WS_MINIMIZEBOX; | |
1369 AdjustWindowRect(&rect, style, 0); | |
1370 | |
1371 if (gui_sub_pos_x >= 0) | |
1372 x = gui_sub_pos_x; | |
1373 if (gui_sub_pos_y >= 0) | |
1374 y = gui_sub_pos_y; | |
1375 | |
1376 /* out of bounds check */ | |
1377 if (x <= -1 || (x+(rect.right-rect.left) > GetSystemMetrics(SM_CXSCREEN))) | |
1378 x = CW_USEDEFAULT; | |
1379 if (y <= -1 || (y+(rect.bottom-rect.top) > GetSystemMetrics(SM_CYSCREEN))) | |
1380 y = x; | |
1381 | |
1382 hWnd = CreateWindowEx(0, "MPlayer Sub for Windows", "MPlayer for Windows", style, | |
1383 x, y, rect.right-rect.left, rect.bottom-rect.top, | |
1384 gui->subwindow, NULL, instance, NULL); | |
1385 | |
1386 /* load all the window images */ | |
1387 window_render(gui, hWnd, hdc, priv, desc, binfo); | |
1388 | |
1389 /* enable drag and drop support */ | |
1390 DragAcceptFiles(hWnd, TRUE); | |
1391 | |
1392 gui->subwindow = hWnd; | |
1393 if(sub_window) | |
1394 WinID = gui->subwindow; | |
1395 ShowWindow(gui->subwindow, SW_SHOW); | |
1396 UpdateWindow(gui->subwindow); | |
1397 return 0; | |
1398 } | |
1399 | |
1400 /* loads/updates a skin and creates windows for it */ | |
1401 extern int create_window(gui_t *gui, char *skindir) | |
1402 { | |
1403 HINSTANCE instance = GetModuleHandle(NULL); | |
1404 WNDCLASS wc; | |
1405 RECT rect; | |
1406 DWORD style = 0; | |
1407 HWND hwnd; | |
1408 HDC hdc = NULL; | |
1409 BITMAPINFO binfo; | |
1410 window_priv_t *priv = NULL; | |
1411 window *desc = NULL; | |
1412 char dir[MAX_PATH]; | |
1413 unsigned int i; | |
1414 | |
1415 /* destroy the current main window */ | |
1416 if(gui->skin) destroy_window(gui); | |
1417 | |
1418 /* get screenproperties */ | |
1419 gui->screenbpp = GetDesktopBitsPerPixel(); | |
1420 gui->screenw = GetSystemMetrics(SM_CXSCREEN); | |
1421 gui->screenh = GetSystemMetrics(SM_CYSCREEN); | |
1422 | |
1423 /* load the new skin */ | |
1424 gui->skin = loadskin(skindir, gui->screenbpp); | |
1425 if(!gui->skin) | |
1426 { | |
1427 mp_msg(MSGT_GPLAYER, MSGL_FATAL, "[GUI] fatal error during skinload\n"); | |
1428 /* Set default Skin */ | |
1429 if (skinName) free(skinName); | |
1430 skinName = strdup("Blue"); | |
1431 /* then force write conf */ | |
1432 cfg_write(); | |
1433 return 1; | |
1434 } | |
1435 | |
1436 /* find the description of the mainwindow */ | |
1437 for (i=0; i<gui->skin->windowcount; i++) | |
1438 if(gui->skin->windows[i]->type == wiMain) | |
1439 desc = gui->skin->windows[i]; | |
1440 | |
1441 if(!desc) | |
1442 { | |
1443 mp_msg(MSGT_GPLAYER, MSGL_FATAL, "[GUI] Invalid skin description\n"); | |
1444 return 1; | |
1445 } | |
1446 | |
1447 /* load the icon from the executable */ | |
1448 GetModuleFileName(NULL, dir, MAX_PATH); | |
1449 gui->icon = ExtractIcon(instance, dir, 0); | |
1450 int x = -1, y = -1; | |
1451 | |
1452 /* create the window class */ | |
1453 wc.style = CS_HREDRAW | CS_VREDRAW; | |
1454 wc.lpfnWndProc = EventProc; | |
1455 wc.cbClsExtra = 0; | |
1456 wc.cbWndExtra = 0; | |
1457 wc.hInstance = instance; | |
1458 wc.hCursor = LoadCursor(NULL, IDC_ARROW); | |
1459 wc.hIcon = gui->icon; | |
1460 wc.hbrBackground = CreateSolidBrush(RGB(0, 0, 0)); | |
1461 wc.lpszClassName = gui->classname = "MPlayer GUI for Windows"; | |
1462 wc.lpszMenuName = NULL; | |
1463 RegisterClass(&wc); | |
1464 | |
1465 /* create a context menu */ | |
1466 create_menu(gui); | |
1467 /* create the systray menu */ | |
1468 create_traymenu(gui); | |
1469 | |
1470 /* create the mainwindow */ | |
1471 /* TODO implement aligning as described in skin.html */ | |
1472 rect.top = rect.left = 100; | |
1473 rect.bottom = rect.top+desc->base->bitmap[0]->height; | |
1474 rect.right = rect.left+desc->base->bitmap[0]->width; | |
1475 if(desc->decoration) style = WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX; | |
1476 else style = WS_POPUP | WS_SYSMENU; | |
1477 | |
1478 AdjustWindowRect(&rect, style, 0); | |
1479 | |
1480 /* Check if out of screen */ | |
1481 if (gui_main_pos_x >= 0) | |
1482 x = gui_main_pos_x; | |
1483 if (gui_main_pos_y >= 0) | |
1484 y = gui_main_pos_y; | |
1485 | |
1486 if (x <= -1 || (x+(rect.right-rect.left) > GetSystemMetrics(SM_CXFULLSCREEN))) | |
1487 { | |
1488 x = (GetSystemMetrics(SM_CXSCREEN) / 2) - ((rect.right-rect.left) / 2); | |
1489 gui_main_pos_x = x; | |
1490 } | |
1491 if (y <= -1 || (y+(rect.bottom-rect.top) > GetSystemMetrics(SM_CYFULLSCREEN))) | |
1492 { | |
1493 y = ((GetSystemMetrics(SM_CYSCREEN)-40) - (rect.bottom-rect.top)); | |
1494 gui_main_pos_y = y; | |
1495 } | |
1496 | |
1497 hwnd = CreateWindowEx(0, gui->classname, "MPlayer for Windows", style, | |
1498 x, y, rect.right-rect.left, rect.bottom-rect.top, | |
1499 gui->mainwindow, NULL, instance, NULL); | |
1500 | |
1501 /* set the systray icon properties */ | |
1502 nid.cbSize = sizeof(NOTIFYICONDATA); | |
1503 nid.hWnd = hwnd; | |
1504 nid.uID = 1; | |
1505 nid.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP; | |
1506 nid.uCallbackMessage = WM_SYSTRAY; | |
1507 nid.hIcon = gui->icon; | |
1508 strcpy(nid.szTip, "MPlayer for Windows"); | |
1509 | |
1510 /* register the systray icon */ | |
1511 Shell_NotifyIcon(NIM_ADD, &nid); | |
1512 | |
1513 /* load all the window images */ | |
1514 window_render(gui, hwnd, hdc, priv, desc, binfo); | |
1515 | |
1516 /* enable drag and drop support */ | |
1517 DragAcceptFiles(hwnd, TRUE); | |
1518 | |
1519 updatedisplay(gui, hwnd); | |
1520 gui->mainwindow = hwnd; | |
1521 | |
1522 /* display */ | |
1523 ShowWindow(gui->mainwindow, SW_SHOW); | |
1524 UpdateWindow(gui->mainwindow); | |
1525 maketransparent(gui->mainwindow, RGB(255, 0, 255)); | |
1526 return 0; | |
1527 } | |
1528 | |
1529 gui_t *create_gui(char *skindir, char *skinName, void (*playercontrol)(int event)) | |
1530 { | |
1531 gui_t *gui = calloc(1, sizeof(gui_t)); | |
1532 | |
1533 HWND runningmplayer = FindWindow("MPlayer GUI for Windows", "MPlayer for Windows"); | |
1534 if(runningmplayer) | |
1535 { | |
1536 free(gui); | |
1537 return NULL; | |
1538 } | |
1539 | |
1540 gui->startplay = startplay; | |
1541 gui->playercontrol = playercontrol; | |
1542 gui->uninit = uninit; | |
1543 gui->updatedisplay = updatedisplay; | |
1544 | |
1545 /* create playlist */ | |
1546 gui->playlist = create_playlist(); | |
1547 | |
1548 if(!skinName) skinName = strdup("Blue"); | |
1549 char temp[MAX_PATH]; | |
1550 sprintf(temp, "%s\\%s", skindir, skinName); | |
1551 if(create_window(gui, temp)) return NULL; | |
1552 if(create_subwindow(gui, temp)) return NULL; | |
1553 if(console) console_toggle(); | |
1554 return gui; | |
1555 } |