comparison Gui/win32/gui.c @ 18914:d450ec82ae57

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