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