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