Mercurial > mplayer.hg
annotate gui/win32/interface.c @ 23126:99dc21f992c3
10l: Remove stray 'fi'.
author | diego |
---|---|
date | Thu, 26 Apr 2007 20:37:24 +0000 |
parents | 21e29d5932c5 |
children | 21c35763b178 |
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 <windows.h> | |
23091
52488bb09d90
Consistently use quotes instead of angled brackets in #include
diego
parents:
23079
diff
changeset
|
25 |
52488bb09d90
Consistently use quotes instead of angled brackets in #include
diego
parents:
23079
diff
changeset
|
26 #include "interface.h" |
52488bb09d90
Consistently use quotes instead of angled brackets in #include
diego
parents:
23079
diff
changeset
|
27 #include "m_option.h" |
52488bb09d90
Consistently use quotes instead of angled brackets in #include
diego
parents:
23079
diff
changeset
|
28 #include "mixer.h" |
52488bb09d90
Consistently use quotes instead of angled brackets in #include
diego
parents:
23079
diff
changeset
|
29 #include "mp_msg.h" |
52488bb09d90
Consistently use quotes instead of angled brackets in #include
diego
parents:
23079
diff
changeset
|
30 #include "help_mp.h" |
52488bb09d90
Consistently use quotes instead of angled brackets in #include
diego
parents:
23079
diff
changeset
|
31 #include "codec-cfg.h" |
52488bb09d90
Consistently use quotes instead of angled brackets in #include
diego
parents:
23079
diff
changeset
|
32 #include "stream/stream.h" |
52488bb09d90
Consistently use quotes instead of angled brackets in #include
diego
parents:
23079
diff
changeset
|
33 #include "libmpdemux/demuxer.h" |
52488bb09d90
Consistently use quotes instead of angled brackets in #include
diego
parents:
23079
diff
changeset
|
34 #include "libmpdemux/stheader.h" |
23077 | 35 #ifdef USE_DVDREAD |
23091
52488bb09d90
Consistently use quotes instead of angled brackets in #include
diego
parents:
23079
diff
changeset
|
36 #include "stream/stream_dvd.h" |
23077 | 37 #endif |
23091
52488bb09d90
Consistently use quotes instead of angled brackets in #include
diego
parents:
23079
diff
changeset
|
38 #include "input/input.h" |
52488bb09d90
Consistently use quotes instead of angled brackets in #include
diego
parents:
23079
diff
changeset
|
39 #include "libvo/video_out.h" |
52488bb09d90
Consistently use quotes instead of angled brackets in #include
diego
parents:
23079
diff
changeset
|
40 #include "libao2/audio_out.h" |
52488bb09d90
Consistently use quotes instead of angled brackets in #include
diego
parents:
23079
diff
changeset
|
41 #include "access_mpcontext.h" |
23077 | 42 #include "gui.h" |
43 #include "dialogs.h" | |
44 #include "wincfg.h" | |
45 #ifdef HAVE_LIBCDIO | |
46 #include <cdio/cdio.h> | |
47 #endif | |
48 | |
49 extern int abs_seek_pos; | |
50 extern float rel_seek_secs; | |
51 extern int vcd_track; | |
52 extern af_cfg_t af_cfg; | |
53 int guiWinID = 0; | |
54 | |
55 char *skinName = NULL; | |
56 char *codecname = NULL; | |
57 int mplGotoTheNext = 1; | |
58 static gui_t *mygui = NULL; | |
59 static int update_subwindow(void); | |
60 static RECT old_rect; | |
61 static DWORD style; | |
62 ao_functions_t *audio_out = NULL; | |
63 vo_functions_t *video_out = NULL; | |
64 mixer_t *mixer = NULL; | |
65 | |
66 /* test for playlist files, no need to specify -playlist on the commandline. | |
67 * add any conceivable playlist extensions here. | |
68 * - Erik | |
69 */ | |
70 int parse_filename(char *file, play_tree_t *playtree, m_config_t *mconfig, int clear) | |
71 { | |
72 if(clear) | |
73 mygui->playlist->clear_playlist(mygui->playlist); | |
74 | |
75 if(strstr(file, ".m3u") || strstr(file, ".pls")) | |
76 { | |
77 playtree = parse_playlist_file(file); | |
78 import_playtree_playlist_into_gui(playtree, mconfig); | |
79 return 1; | |
80 } | |
81 return 0; | |
82 } | |
83 | |
84 /** | |
85 * \brief this actually creates a new list containing only one element... | |
86 */ | |
87 void gaddlist( char ***list, const char *entry) | |
88 { | |
89 int i; | |
90 | |
91 if (*list) | |
92 { | |
93 for (i=0; (*list)[i]; i++) free((*list)[i]); | |
94 free(*list); | |
95 } | |
96 | |
97 *list = malloc(2 * sizeof(char **)); | |
98 (*list)[0] = gstrdup(entry); | |
99 (*list)[1] = NULL; | |
100 } | |
101 | |
102 char *gstrdup(const char *str) | |
103 { | |
104 if (!str) return NULL; | |
105 return strdup(str); | |
106 } | |
107 | |
108 /** | |
109 * \brief this replaces a string starting with search by replace. | |
110 * If not found, replace is appended. | |
111 */ | |
112 void greplace(char ***list, char *search, char *replace) | |
113 { | |
114 int i = 0; | |
115 int len = (search) ? strlen(search) : 0; | |
116 | |
117 if (*list) | |
118 { | |
119 for (i = 0; (*list)[i]; i++) | |
120 { | |
121 if (search && (!strncmp((*list)[i], search, len))) | |
122 { | |
123 free((*list)[i]); | |
124 (*list)[i] = gstrdup(replace); | |
125 return; | |
126 } | |
127 } | |
128 *list = realloc(*list, (i + 2) * sizeof(char *)); | |
129 } | |
130 else | |
131 *list = malloc(2 * sizeof(char *)); | |
132 | |
133 (*list)[i] = gstrdup(replace); | |
134 (*list)[i + 1] = NULL; | |
135 } | |
136 | |
137 /* this function gets called by the gui to update mplayer */ | |
138 static void guiSetEvent(int event) | |
139 { | |
140 if(guiIntfStruct.mpcontext) | |
141 mixer = mpctx_get_mixer(guiIntfStruct.mpcontext); | |
142 | |
143 switch(event) | |
144 { | |
145 case evPlay: | |
146 case evPlaySwitchToPause: | |
147 mplPlay(); | |
148 break; | |
149 case evPause: | |
150 mplPause(); | |
151 break; | |
152 #ifdef USE_DVDREAD | |
153 case evPlayDVD: | |
154 { | |
155 static char dvdname[MAX_PATH]; | |
156 guiIntfStruct.DVD.current_title = dvd_title; | |
157 guiIntfStruct.DVD.current_chapter = dvd_chapter; | |
158 guiIntfStruct.DVD.current_angle = dvd_angle; | |
159 guiIntfStruct.DiskChanged = 1; | |
160 | |
161 mplSetFileName(NULL, dvd_device, STREAMTYPE_DVD); | |
162 dvdname[0] = 0; | |
163 strcat(dvdname, "DVD Movie"); | |
164 GetVolumeInformation(dvd_device, dvdname, MAX_PATH, NULL, NULL, NULL, NULL, 0); | |
165 capitalize(dvdname); | |
166 mp_msg(MSGT_GPLAYER, MSGL_V, "Opening DVD %s -> %s\n", dvd_device, dvdname); | |
167 guiGetEvent(guiSetParameters, (char *) STREAMTYPE_DVD); | |
168 mygui->playlist->clear_playlist(mygui->playlist); | |
169 mygui->playlist->add_track(mygui->playlist, filename, NULL, dvdname, 0); | |
170 mygui->startplay(mygui); | |
171 break; | |
172 } | |
173 #endif | |
174 #ifdef HAVE_LIBCDIO | |
175 case evPlayCD: | |
176 { | |
177 int i; | |
178 char track[10]; | |
179 char trackname[10]; | |
180 CdIo_t *p_cdio = cdio_open(NULL, DRIVER_UNKNOWN); | |
181 track_t i_tracks; | |
182 | |
183 if(p_cdio == NULL) printf("Couldn't find a driver.\n"); | |
184 i_tracks = cdio_get_num_tracks(p_cdio); | |
185 | |
186 mygui->playlist->clear_playlist(mygui->playlist); | |
187 for(i=0;i<i_tracks;i++) | |
188 { | |
189 sprintf(track, "cdda://%d", i+1); | |
190 sprintf(trackname, "Track %d", i+1); | |
191 mygui->playlist->add_track(mygui->playlist, track, NULL, trackname, 0); | |
192 } | |
193 cdio_destroy(p_cdio); | |
194 mygui->startplay(mygui); | |
195 break; | |
196 } | |
197 #endif | |
198 case evFullScreen: | |
199 mp_input_queue_cmd(mp_input_parse_cmd("vo_fullscreen")); | |
200 break; | |
201 case evExit: | |
202 { | |
203 /* We are asking mplayer to exit, later it will ask us after uninit is made | |
204 this should be the only safe way to quit */ | |
205 mygui->activewidget = NULL; | |
206 mp_input_queue_cmd(mp_input_parse_cmd("quit")); | |
207 break; | |
208 } | |
209 case evStop: | |
210 if(guiIntfStruct.Playing) | |
211 guiGetEvent(guiCEvent, (void *) guiSetStop); | |
212 break; | |
213 case evSetMoviePosition: | |
214 { | |
215 rel_seek_secs = guiIntfStruct.Position / 100.0f; | |
216 abs_seek_pos = 3; | |
217 break; | |
218 } | |
219 case evForward10sec: | |
220 { | |
221 rel_seek_secs = 10.0f; | |
222 abs_seek_pos = 0; | |
223 break; | |
224 } | |
225 case evBackward10sec: | |
226 { | |
227 rel_seek_secs = -10.0f; | |
228 abs_seek_pos = 0; | |
229 break; | |
230 } | |
231 case evSetBalance: | |
232 case evSetVolume: | |
233 { | |
234 float l,r; | |
235 | |
236 if (guiIntfStruct.Playing == 0) | |
237 break; | |
238 | |
239 if (guiIntfStruct.Balance == 50.0f) | |
240 mixer_setvolume(mixer, guiIntfStruct.Volume, guiIntfStruct.Volume); | |
241 | |
242 l = guiIntfStruct.Volume * ((100.0f - guiIntfStruct.Balance) / 50.0f); | |
243 r = guiIntfStruct.Volume * ((guiIntfStruct.Balance) / 50.0f); | |
244 | |
245 if (l > guiIntfStruct.Volume) l=guiIntfStruct.Volume; | |
246 if (r > guiIntfStruct.Volume) r=guiIntfStruct.Volume; | |
247 mixer_setvolume(mixer, l, r); | |
248 /* Check for balance support on mixer - there is a better way ?? */ | |
249 if (r != l) | |
250 { | |
251 mixer_getvolume(mixer, &l, &r); | |
252 if (r == l) | |
253 { | |
254 mp_msg(MSGT_GPLAYER, MSGL_V, "[GUI] Mixer doesn't support balanced audio\n"); | |
255 mixer_setvolume(mixer, guiIntfStruct.Volume, guiIntfStruct.Volume); | |
256 guiIntfStruct.Balance = 50.0f; | |
257 } | |
258 } | |
259 break; | |
260 } | |
261 case evMute: | |
262 { | |
263 mp_cmd_t * cmd = calloc(1, sizeof(*cmd)); | |
264 cmd->id=MP_CMD_MUTE; | |
265 cmd->name=strdup("mute"); | |
266 mp_input_queue_cmd(cmd); | |
267 break; | |
268 } | |
269 case evDropFile: | |
270 case evLoadPlay: | |
271 { | |
272 switch(guiIntfStruct.StreamType) | |
273 { | |
274 case STREAMTYPE_DVD: | |
275 { | |
276 guiIntfStruct.Title = guiIntfStruct.DVD.current_title; | |
277 guiIntfStruct.Chapter = guiIntfStruct.DVD.current_chapter; | |
278 guiIntfStruct.Angle = guiIntfStruct.DVD.current_angle; | |
279 guiIntfStruct.DiskChanged = 1; | |
280 guiGetEvent(guiCEvent, (void *) guiSetPlay); | |
281 break; | |
282 } | |
283 default: | |
284 { | |
285 guiIntfStruct.FilenameChanged = guiIntfStruct.NewPlay = 1; | |
286 update_playlistwindow(); | |
287 mplGotoTheNext = guiIntfStruct.Playing? 0 : 1; | |
288 guiGetEvent(guiCEvent, (void *) guiSetStop); | |
289 guiGetEvent(guiCEvent, (void *) guiSetPlay); | |
290 break; | |
291 } | |
292 } | |
293 break; | |
294 } | |
295 case evNext: | |
296 mplNext(); | |
297 break; | |
298 case evPrev: | |
299 mplPrev(); | |
300 break; | |
301 } | |
302 } | |
303 | |
304 void mplPlay( void ) | |
305 { | |
306 if((!guiIntfStruct.Filename ) || (guiIntfStruct.Filename[0] == 0)) | |
307 return; | |
308 | |
309 if(guiIntfStruct.Playing > 0) | |
310 { | |
311 mplPause(); | |
312 return; | |
313 } | |
314 guiIntfStruct.NewPlay = 1; | |
315 guiGetEvent(guiCEvent, (void *) guiSetPlay); | |
316 } | |
317 | |
318 void mplPause( void ) | |
319 { | |
320 if(!guiIntfStruct.Playing) return; | |
321 | |
322 if(guiIntfStruct.Playing == 1) | |
323 { | |
324 mp_cmd_t * cmd = calloc(1, sizeof(*cmd)); | |
325 cmd->id=MP_CMD_PAUSE; | |
326 cmd->name=strdup("pause"); | |
327 mp_input_queue_cmd(cmd); | |
328 } else guiIntfStruct.Playing = 1; | |
329 } | |
330 | |
331 void mplNext(void) | |
332 { | |
333 if(guiIntfStruct.Playing == 2) return; | |
334 switch(guiIntfStruct.StreamType) | |
335 { | |
336 #ifdef USE_DVDREAD | |
337 case STREAMTYPE_DVD: | |
338 if(guiIntfStruct.DVD.current_chapter == (guiIntfStruct.DVD.chapters - 1)) | |
339 return; | |
340 guiIntfStruct.DVD.current_chapter++; | |
341 break; | |
342 #endif | |
343 default: | |
344 if(mygui->playlist->current == (mygui->playlist->trackcount - 1)) | |
345 return; | |
346 mplSetFileName(NULL, mygui->playlist->tracks[(mygui->playlist->current)++]->filename, | |
347 STREAMTYPE_STREAM); | |
348 break; | |
349 } | |
350 mygui->startplay(mygui); | |
351 } | |
352 | |
353 void mplPrev(void) | |
354 { | |
355 if(guiIntfStruct.Playing == 2) return; | |
356 switch(guiIntfStruct.StreamType) | |
357 { | |
358 #ifdef USE_DVDREAD | |
359 case STREAMTYPE_DVD: | |
360 if(guiIntfStruct.DVD.current_chapter == 1) | |
361 return; | |
362 guiIntfStruct.DVD.current_chapter--; | |
363 break; | |
364 #endif | |
365 default: | |
366 if(mygui->playlist->current == 0) | |
367 return; | |
368 mplSetFileName(NULL, mygui->playlist->tracks[(mygui->playlist->current)--]->filename, | |
369 STREAMTYPE_STREAM); | |
370 break; | |
371 } | |
372 mygui->startplay(mygui); | |
373 } | |
374 | |
375 void mplEnd( void ) | |
376 { | |
377 if(!mplGotoTheNext && guiIntfStruct.Playing) | |
378 { | |
379 mplGotoTheNext = 1; | |
380 return; | |
381 } | |
382 | |
383 if(mplGotoTheNext && guiIntfStruct.Playing && | |
384 (mygui->playlist->current < (mygui->playlist->trackcount - 1)) && | |
385 guiIntfStruct.StreamType != STREAMTYPE_DVD && | |
386 guiIntfStruct.StreamType != STREAMTYPE_DVDNAV) | |
387 { | |
388 /* we've finished this file, reset the aspect */ | |
389 if(movie_aspect >= 0) | |
390 movie_aspect = -1; | |
391 | |
392 mplGotoTheNext = guiIntfStruct.FilenameChanged = guiIntfStruct.NewPlay = 1; | |
393 mplSetFileName(NULL, mygui->playlist->tracks[(mygui->playlist->current)++]->filename, STREAMTYPE_STREAM); | |
394 //sprintf(guiIntfStruct.Filename, mygui->playlist->tracks[(mygui->playlist->current)++]->filename); | |
395 } | |
396 | |
397 if(guiIntfStruct.FilenameChanged && guiIntfStruct.NewPlay) | |
398 return; | |
399 | |
400 guiIntfStruct.TimeSec = 0; | |
401 guiIntfStruct.Position = 0; | |
402 guiIntfStruct.AudioType = 0; | |
403 | |
404 #ifdef USE_DVDREAD | |
405 guiIntfStruct.DVD.current_title = 1; | |
406 guiIntfStruct.DVD.current_chapter = 1; | |
407 guiIntfStruct.DVD.current_angle = 1; | |
408 #endif | |
409 | |
410 if (mygui->playlist->current == (mygui->playlist->trackcount - 1)) | |
411 mygui->playlist->current = 0; | |
412 | |
413 fullscreen = 0; | |
414 if(style == WS_VISIBLE | WS_POPUP) | |
415 { | |
416 style = WS_OVERLAPPEDWINDOW | WS_SIZEBOX; | |
417 SetWindowLong(mygui->subwindow, GWL_STYLE, style); | |
418 } | |
419 guiGetEvent(guiCEvent, (void *) guiSetStop); | |
420 } | |
421 | |
422 void mplSetFileName(char *dir, char *name, int type) | |
423 { | |
424 if(!name) return; | |
425 if(!dir) | |
426 guiSetFilename(guiIntfStruct.Filename, name) | |
427 else | |
428 guiSetDF(guiIntfStruct.Filename, dir, name); | |
429 | |
430 guiIntfStruct.StreamType = type; | |
431 free((void **) &guiIntfStruct.AudioFile); | |
432 free((void **) &guiIntfStruct.Subtitlename); | |
433 } | |
434 | |
435 void mplFullScreen( void ) | |
436 { | |
437 if(!guiIntfStruct.sh_video) return; | |
438 | |
439 if(sub_window) | |
440 { | |
441 if(!fullscreen && IsWindowVisible(mygui->subwindow) && !IsIconic(mygui->subwindow)) | |
442 GetWindowRect(mygui->subwindow, &old_rect); | |
443 | |
444 if(fullscreen) | |
445 { | |
446 fullscreen = 0; | |
447 style = WS_OVERLAPPEDWINDOW | WS_SIZEBOX; | |
448 } else { | |
449 fullscreen = 1; | |
450 style = WS_VISIBLE | WS_POPUP; | |
451 } | |
452 SetWindowLong(mygui->subwindow, GWL_STYLE, style); | |
453 update_subwindow(); | |
454 } | |
455 video_out->control(VOCTRL_FULLSCREEN, 0); | |
456 if(sub_window) ShowWindow(mygui->subwindow, SW_SHOW); | |
457 } | |
458 | |
459 static DWORD WINAPI GuiThread(void) | |
460 { | |
461 MSG msg; | |
462 | |
463 if(!skinName) skinName = strdup("Blue"); | |
464 if(!mygui) mygui = create_gui(get_path("skins"), skinName, guiSetEvent); | |
23078 | 465 if(!mygui) exit_player("Unable to load GUI."); |
23077 | 466 |
467 if(autosync && autosync != gtkAutoSync) | |
468 { | |
469 gtkAutoSyncOn = 1; | |
470 gtkAutoSync = autosync; | |
471 } | |
472 | |
473 while(mygui) | |
474 { | |
475 GetMessage(&msg, NULL, 0, 0); | |
476 TranslateMessage(&msg); | |
477 DispatchMessage(&msg); | |
478 } | |
23078 | 479 fprintf(stderr, "[GUI] GUI thread terminated.\n"); |
23077 | 480 fflush(stderr); |
481 return 0; | |
482 } | |
483 | |
484 void guiInit(void) | |
485 { | |
486 DWORD threadId; | |
487 memset(&guiIntfStruct, 0, sizeof(guiIntfStruct)); | |
488 /* Create The gui thread */ | |
489 if (!mygui) | |
490 { | |
491 CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) GuiThread, NULL, 0, &threadId); | |
492 mp_msg(MSGT_GPLAYER, MSGL_V, "[GUI] Creating GUI Thread 0x%04x\n", threadId); | |
493 } | |
494 | |
495 /* Wait until the gui is created */ | |
496 while(!mygui) Sleep(100); | |
23078 | 497 mp_msg(MSGT_GPLAYER, MSGL_V, "[GUI] GUI thread started.\n"); |
23077 | 498 } |
499 | |
500 void guiDone(void) | |
501 { | |
502 if(mygui) | |
503 { | |
504 fprintf(stderr, "[GUI] Closed by main mplayer window\n"); | |
505 fflush(stderr); | |
506 mygui->uninit(mygui); | |
507 free(mygui); | |
508 TerminateThread(GuiThread, 0); | |
509 mygui = NULL; | |
510 } | |
511 /* Remove tray icon */ | |
512 Shell_NotifyIcon(NIM_DELETE, &nid); | |
513 cfg_write(); | |
514 } | |
515 | |
516 /* this function gets called by mplayer to update the gui */ | |
517 int guiGetEvent(int type, char *arg) | |
518 { | |
519 stream_t *stream = (stream_t *) arg; | |
520 #ifdef USE_DVDREAD | |
521 dvd_priv_t *dvdp = (dvd_priv_t *) arg; | |
522 #endif | |
523 if(!mygui || !mygui->skin) return 0; | |
524 | |
525 if(guiIntfStruct.mpcontext) | |
526 { | |
527 audio_out = mpctx_get_audio_out(guiIntfStruct.mpcontext); | |
528 video_out = mpctx_get_video_out(guiIntfStruct.mpcontext); | |
529 mixer = mpctx_get_mixer(guiIntfStruct.mpcontext); | |
530 playtree = mpctx_get_playtree_iter(guiIntfStruct.mpcontext); | |
531 } | |
532 | |
533 switch (type) | |
534 { | |
535 case guiSetFileFormat: | |
536 guiIntfStruct.FileFormat = (int) arg; | |
537 break; | |
538 case guiSetParameters: | |
539 { | |
540 guiGetEvent(guiSetDefaults, NULL); | |
541 guiIntfStruct.DiskChanged = 0; | |
542 guiIntfStruct.FilenameChanged = 0; | |
543 guiIntfStruct.NewPlay = 0; | |
544 switch(guiIntfStruct.StreamType) | |
545 { | |
546 case STREAMTYPE_PLAYLIST: | |
547 break; | |
548 #ifdef USE_DVDREAD | |
549 case STREAMTYPE_DVD: | |
550 { | |
551 char tmp[512]; | |
552 dvd_title = guiIntfStruct.DVD.current_title; | |
553 dvd_chapter = guiIntfStruct.DVD.current_chapter; | |
554 dvd_angle = guiIntfStruct.DVD.current_angle; | |
555 sprintf(tmp,"dvd://%d", guiIntfStruct.Title); | |
556 guiSetFilename(guiIntfStruct.Filename, tmp); | |
557 break; | |
558 } | |
559 #endif | |
560 } | |
561 if(guiIntfStruct.Filename) | |
562 filename = strdup(guiIntfStruct.Filename); | |
563 else if(filename) | |
564 strcpy(guiIntfStruct.Filename, filename); | |
565 break; | |
566 } | |
567 case guiSetAudioOnly: | |
568 { | |
569 guiIntfStruct.AudioOnly = (int) arg; | |
570 if(IsWindowVisible(mygui->subwindow)) | |
571 ShowWindow(mygui->subwindow, SW_HIDE); | |
572 break; | |
573 } | |
574 case guiSetContext: | |
575 guiIntfStruct.mpcontext = (void *) arg; | |
576 break; | |
577 case guiSetDemuxer: | |
578 guiIntfStruct.demuxer = (void *) arg; | |
579 break; | |
580 case guiSetValues: | |
581 { | |
582 guiIntfStruct.sh_video = arg; | |
583 if (arg) | |
584 { | |
585 sh_video_t *sh = (sh_video_t *)arg; | |
586 codecname = sh->codec->name; | |
587 guiIntfStruct.FPS = sh->fps; | |
588 | |
589 /* we have video, show the subwindow */ | |
590 if(!IsWindowVisible(mygui->subwindow) || IsIconic(mygui->subwindow)) | |
591 ShowWindow(mygui->subwindow, SW_SHOWNORMAL); | |
592 if(WinID == -1) | |
593 update_subwindow(); | |
594 | |
595 } | |
596 break; | |
597 } | |
598 case guiSetShVideo: | |
599 { | |
600 guiIntfStruct.MovieWidth = vo_dwidth; | |
601 guiIntfStruct.MovieHeight = vo_dheight; | |
602 | |
603 sub_aspect = (float)guiIntfStruct.MovieWidth/guiIntfStruct.MovieHeight; | |
604 if(WinID != -1) | |
605 update_subwindow(); | |
606 break; | |
607 } | |
608 case guiSetStream: | |
609 { | |
610 guiIntfStruct.StreamType = stream->type; | |
611 switch(stream->type) | |
612 { | |
613 #ifdef USE_DVDREAD | |
614 case STREAMTYPE_DVD: | |
615 guiGetEvent(guiSetDVD, (char *) stream->priv); | |
616 break; | |
617 #endif | |
618 } | |
619 break; | |
620 } | |
621 #ifdef USE_DVDREAD | |
622 case guiSetDVD: | |
623 { | |
624 guiIntfStruct.DVD.titles = dvdp->vmg_file->tt_srpt->nr_of_srpts; | |
625 guiIntfStruct.DVD.chapters = dvdp->vmg_file->tt_srpt->title[dvd_title].nr_of_ptts; | |
626 guiIntfStruct.DVD.angles = dvdp->vmg_file->tt_srpt->title[dvd_title].nr_of_angles; | |
627 guiIntfStruct.DVD.nr_of_audio_channels = dvdp->nr_of_channels; | |
628 memcpy(guiIntfStruct.DVD.audio_streams, dvdp->audio_streams, sizeof(dvdp->audio_streams)); | |
629 guiIntfStruct.DVD.nr_of_subtitles = dvdp->nr_of_subtitles; | |
630 memcpy(guiIntfStruct.DVD.subtitles, dvdp->subtitles, sizeof(dvdp->subtitles)); | |
631 guiIntfStruct.DVD.current_title = dvd_title + 1; | |
632 guiIntfStruct.DVD.current_chapter = dvd_chapter + 1; | |
633 guiIntfStruct.DVD.current_angle = dvd_angle + 1; | |
634 guiIntfStruct.Track = dvd_title + 1; | |
635 break; | |
636 } | |
637 #endif | |
638 case guiReDraw: | |
639 mygui->updatedisplay(mygui, mygui->mainwindow); | |
640 break; | |
641 case guiSetAfilter: | |
642 guiIntfStruct.afilter = (void *) arg; | |
643 break; | |
644 case guiCEvent: | |
645 { | |
646 guiIntfStruct.Playing = (int) arg; | |
647 switch (guiIntfStruct.Playing) | |
648 { | |
649 case guiSetPlay: | |
650 { | |
651 guiIntfStruct.Playing = 1; | |
652 break; | |
653 } | |
654 case guiSetStop: | |
655 { | |
656 guiIntfStruct.Playing = 0; | |
657 if(movie_aspect >= 0) | |
658 movie_aspect = -1; | |
659 update_subwindow(); | |
660 break; | |
661 } | |
662 case guiSetPause: | |
663 guiIntfStruct.Playing = 2; | |
664 break; | |
665 } | |
666 break; | |
667 } | |
668 case guiIEvent: | |
669 { | |
670 mp_msg(MSGT_GPLAYER,MSGL_V, "cmd: %d\n", (int) arg); | |
671 /* MPlayer asks us to quit */ | |
672 switch((int) arg) | |
673 { | |
674 case MP_CMD_GUI_FULLSCREEN: | |
675 mplFullScreen(); | |
676 break; | |
677 case MP_CMD_QUIT: | |
678 { | |
679 mygui->uninit(mygui); | |
680 free(mygui); | |
681 mygui = NULL; | |
682 exit_player("Done"); | |
683 return 0; | |
684 } | |
685 case MP_CMD_GUI_STOP: | |
686 guiGetEvent(guiCEvent, (void *) guiSetStop); | |
687 break; | |
688 case MP_CMD_GUI_PLAY: | |
689 guiGetEvent(guiCEvent, (void *) guiSetPlay); | |
690 break; | |
691 case MP_CMD_GUI_SKINBROWSER: | |
692 if(fullscreen) guiSetEvent(evFullScreen); | |
693 PostMessage(mygui->mainwindow, WM_COMMAND, (WPARAM) ID_SKINBROWSER, 0); | |
694 break; | |
695 case MP_CMD_GUI_PLAYLIST: | |
696 if(fullscreen) guiSetEvent(evFullScreen); | |
697 PostMessage(mygui->mainwindow, WM_COMMAND, (WPARAM) ID_PLAYLIST, 0); | |
698 break; | |
699 case MP_CMD_GUI_PREFERENCES: | |
700 if(fullscreen) guiSetEvent(evFullScreen); | |
701 PostMessage(mygui->mainwindow, WM_COMMAND, (WPARAM) ID_PREFS, 0); | |
702 break; | |
703 case MP_CMD_GUI_LOADFILE: | |
704 if(fullscreen) guiSetEvent(evFullScreen); | |
705 PostMessage(mygui->mainwindow, WM_COMMAND, (WPARAM) IDFILE_OPEN, 0); | |
706 break; | |
707 case MP_CMD_GUI_LOADSUBTITLE: | |
708 if(fullscreen) guiSetEvent(evFullScreen); | |
709 PostMessage(mygui->mainwindow, WM_COMMAND, (WPARAM) IDSUBTITLE_OPEN, 0); | |
710 break; | |
711 default: | |
712 break; | |
713 } | |
714 break; | |
715 } | |
716 case guiSetFileName: | |
717 if (arg) guiIntfStruct.Filename = (char *) arg; | |
718 break; | |
719 case guiSetDefaults: | |
720 { | |
721 audio_id = -1; | |
722 video_id = -1; | |
723 dvdsub_id = -1; | |
724 vobsub_id = -1; | |
725 stream_cache_size = -1; | |
726 autosync = 0; | |
727 vcd_track = 0; | |
728 dvd_title = 0; | |
729 force_fps = 0; | |
730 if(!mygui->playlist->tracks) return 0; | |
731 filename = guiIntfStruct.Filename = mygui->playlist->tracks[mygui->playlist->current]->filename; | |
732 guiIntfStruct.Track = mygui->playlist->current + 1; | |
733 if(gtkAONorm) greplace(&af_cfg.list, "volnorm", "volnorm"); | |
734 if(gtkAOExtraStereo) | |
735 { | |
736 char *name = malloc(12 + 20 + 1); | |
737 snprintf(name, 12 + 20, "extrastereo=%f", gtkAOExtraStereoMul); | |
738 name[12 + 20] = 0; | |
739 greplace(&af_cfg.list, "extrastereo", name); | |
740 free(name); | |
741 } | |
742 if(gtkCacheOn) stream_cache_size = gtkCacheSize; | |
743 if(gtkAutoSyncOn) autosync = gtkAutoSync; | |
744 break; | |
745 } | |
746 case guiSetVolume: | |
747 { | |
748 if(audio_out) | |
749 { | |
750 /* Some audio_out drivers do not support balance e.g. dsound */ | |
751 /* FIXME this algo is not correct */ | |
752 float l, r; | |
753 mixer_getvolume(mixer, &l, &r); | |
754 guiIntfStruct.Volume = (r > l ? r : l); /* max(r,l) */ | |
755 if (r != l) | |
756 guiIntfStruct.Balance = ((r-l) + 100.0f) * 0.5f; | |
757 else | |
758 guiIntfStruct.Balance = 50.0f; | |
759 } | |
760 break; | |
761 } | |
762 default: | |
763 mp_msg(MSGT_GPLAYER, MSGL_ERR, "[GUI] GOT UNHANDLED EVENT %i\n", type); | |
764 } | |
765 return 0; | |
766 } | |
767 | |
768 /* This function adds/inserts one file into the gui playlist */ | |
769 int import_file_into_gui(char *pathname, int insert) | |
770 { | |
771 char filename[MAX_PATH]; | |
772 char *filepart = filename; | |
773 | |
774 if (strstr(pathname, "://")) | |
775 { | |
776 mp_msg(MSGT_GPLAYER, MSGL_V, "[GUI] Adding special %s\n", pathname); | |
777 mygui->playlist->add_track(mygui->playlist, pathname, NULL, NULL, 0); | |
778 return 1; | |
779 } | |
780 if (GetFullPathName(pathname, MAX_PATH, filename, &filepart)) | |
781 { | |
782 if (!(GetFileAttributes(filename) & FILE_ATTRIBUTE_DIRECTORY)) | |
783 { | |
784 mp_msg(MSGT_GPLAYER, MSGL_V, "[GUI] Adding filename: %s - fullpath: %s\n", filepart, filename); | |
785 mygui->playlist->add_track(mygui->playlist, filename, NULL, filepart, 0); | |
786 return 1; | |
787 } | |
788 else | |
789 mp_msg(MSGT_GPLAYER, MSGL_V, "[GUI] Cannot add %s\n", filename); | |
790 } | |
791 | |
792 return 0; | |
793 } | |
794 | |
795 /* This function imports the initial playtree (based on cmd-line files) into the gui playlist | |
796 by either: | |
797 - overwriting gui pl (enqueue=0) */ | |
798 | |
799 int import_initial_playtree_into_gui(play_tree_t *my_playtree, m_config_t *config, int enqueue) | |
800 { | |
801 play_tree_iter_t *my_pt_iter = NULL; | |
802 int result = 0; | |
803 | |
804 if(!mygui) guiInit(); | |
805 | |
806 if((my_pt_iter = pt_iter_create(&my_playtree, config))) | |
807 { | |
808 while ((filename = pt_iter_get_next_file(my_pt_iter)) != NULL) | |
809 { | |
810 if (parse_filename(filename, my_playtree, config, 0)) | |
811 result = 1; | |
812 else if (import_file_into_gui(filename, 0)) /* Add it to end of list */ | |
813 result = 1; | |
814 } | |
815 } | |
816 mplGotoTheNext = 1; | |
817 | |
818 if (result) | |
819 { | |
820 mygui->playlist->current = 0; | |
821 filename = mygui->playlist->tracks[0]->filename; | |
822 } | |
823 return result; | |
824 } | |
825 | |
826 /* This function imports and inserts an playtree, that is created "on the fly", for example by | |
827 parsing some MOV-Reference-File; or by loading an playlist with "File Open" | |
828 The file which contained the playlist is thereby replaced with it's contents. */ | |
829 | |
830 int import_playtree_playlist_into_gui(play_tree_t *my_playtree, m_config_t *config) | |
831 { | |
832 play_tree_iter_t *my_pt_iter = NULL; | |
833 int result = 0; | |
834 | |
835 if((my_pt_iter = pt_iter_create(&my_playtree, config))) | |
836 { | |
837 while ((filename = pt_iter_get_next_file(my_pt_iter)) != NULL) | |
838 if (import_file_into_gui(filename, 1)) /* insert it into the list and set plCurrent = new item */ | |
839 result = 1; | |
840 pt_iter_destroy(&my_pt_iter); | |
841 } | |
842 filename = NULL; | |
843 return result; | |
844 } | |
845 | |
846 inline void gtkMessageBox(int type, const char *str) | |
847 { | |
848 if (type & GTK_MB_FATAL) | |
849 MessageBox(NULL, str, "MPlayer GUI for Windows Error", MB_OK | MB_ICONERROR); | |
850 | |
851 fprintf(stderr, "[GUI] MessageBox: %s\n", str); | |
852 fflush(stderr); | |
853 } | |
854 | |
855 void guiMessageBox(int level, char *str) | |
856 { | |
857 switch(level) | |
858 { | |
859 case MSGL_FATAL: | |
860 gtkMessageBox(GTK_MB_FATAL | GTK_MB_SIMPLE, str); | |
861 break; | |
862 case MSGL_ERR: | |
863 gtkMessageBox(GTK_MB_ERROR | GTK_MB_SIMPLE, str); | |
864 break; | |
865 } | |
866 } | |
867 | |
868 static int update_subwindow(void) | |
869 { | |
870 int x,y; | |
871 RECT rd; | |
872 WINDOWPOS wp; | |
873 | |
874 if(!sub_window) | |
875 { | |
876 WinID = -1; // so far only directx supports WinID in windows | |
877 | |
878 if(IsWindowVisible(mygui->subwindow) && guiIntfStruct.sh_video && guiIntfStruct.Playing) | |
879 { | |
880 ShowWindow(mygui->subwindow, SW_HIDE); | |
881 return 0; | |
882 } | |
883 else if(guiIntfStruct.AudioOnly) | |
884 return 0; | |
885 else ShowWindow(mygui->subwindow, SW_SHOW); | |
886 } | |
887 | |
888 /* we've come out of fullscreen at the end of file */ | |
889 if((!IsWindowVisible(mygui->subwindow) || IsIconic(mygui->subwindow)) && !guiIntfStruct.AudioOnly) | |
890 ShowWindow(mygui->subwindow, SW_SHOWNORMAL); | |
891 | |
892 /* get our current window coordinates */ | |
893 GetWindowRect(mygui->subwindow, &rd); | |
894 | |
895 x = rd.left; | |
896 y = rd.top; | |
897 | |
898 /* restore sub window position when coming out of fullscreen */ | |
899 if(x <= 0) x = old_rect.left; | |
900 if(y <= 0) y = old_rect.top; | |
901 | |
902 if(!guiIntfStruct.Playing) | |
903 { | |
904 window *desc = NULL; | |
905 int i; | |
906 | |
907 for (i=0; i<mygui->skin->windowcount; i++) | |
908 if(mygui->skin->windows[i]->type == wiSub) | |
909 desc = mygui->skin->windows[i]; | |
910 | |
911 rd.right = rd.left+desc->base->bitmap[0]->width; | |
912 rd.bottom = rd.top+desc->base->bitmap[0]->height; | |
913 sub_aspect = (float)(rd.right-rd.left)/(rd.bottom-rd.top); | |
914 } | |
915 else | |
916 { | |
917 rd.right = rd.left+guiIntfStruct.MovieWidth; | |
918 rd.bottom = rd.top+guiIntfStruct.MovieHeight; | |
919 | |
920 if (movie_aspect > 0.0) // forced aspect from the cmdline | |
921 sub_aspect = movie_aspect; | |
922 } | |
923 | |
924 | |
925 AdjustWindowRect(&rd, WS_OVERLAPPEDWINDOW | WS_SIZEBOX, 0); | |
926 SetWindowPos(mygui->subwindow, 0, x, y, rd.right-rd.left, rd.bottom-rd.top, SWP_NOOWNERZORDER); | |
927 | |
928 wp.hwnd = mygui->subwindow; | |
929 wp.x = rd.left; | |
930 wp.y = rd.top; | |
931 wp.cx = rd.right-rd.left; | |
932 wp.cy = rd.bottom-rd.top; | |
933 wp.flags = SWP_NOOWNERZORDER | SWP_SHOWWINDOW; | |
934 | |
935 /* erase the bitmap image if there's video */ | |
936 if(guiIntfStruct.Playing != 0 && guiIntfStruct.sh_video) | |
937 SendMessage(mygui->subwindow, WM_ERASEBKGND, (WPARAM)GetDC(mygui->subwindow), 0); | |
938 | |
939 /* reset the window aspect */ | |
940 SendMessage(mygui->subwindow, WM_WINDOWPOSCHANGED, 0, (LPARAM)&wp); | |
941 return 0; | |
942 } | |
943 | |
944 void guiEventHandling(void) {} |