Initial import of MPlayer SVN rev 28382 and FFmpeg SVN rev 16846.
[vaapi:athaifas-mplayer.git] / gui / win32 / .svn / text-base / preferences.c.svn-base
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 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 along
20  * with MPlayer; if not, write to the Free Software Foundation, Inc.,
21  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22  */
23
24 #include <windows.h>
25 #include <commctrl.h>
26 #include <stdio.h>
27 #include <stdlib.h>
28 #include <string.h>
29
30 #include "libvo/video_out.h"
31 #include "libao2/audio_out.h"
32 #include "mixer.h"
33 #include "gui/interface.h"
34 #include "gui.h"
35 #include "mp_msg.h"
36 #include "help_mp.h"
37 #include "dialogs.h"
38
39 extern char  *proc_priority;
40
41 static void set_defaults(void);
42
43 static LRESULT CALLBACK PrefsWndProc(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
44 {
45     HWND btn, label, edit1, edit2, edit3, updown1, updown2, track1, track2;
46     static HWND vo_driver, ao_driver, prio;
47     int i = 0, j = 0;
48     char dvddevice[MAX_PATH];
49     char cdromdevice[MAX_PATH];
50     char procprio[11];
51     float x = 10.0, y = 100.0, stereopos, delaypos;
52     stereopos = gtkAOExtraStereoMul * x;
53     delaypos = audio_delay * y;
54
55     switch (iMsg)
56     {
57         case WM_CREATE:
58         {
59             /* video and audio drivers */
60             label = CreateWindow("static", "Video Driver:",
61                                  WS_CHILD | WS_VISIBLE,
62                                  10, 13, 70, 15, hwnd,
63                                  NULL, ((LPCREATESTRUCT) lParam) -> hInstance,
64                                  NULL);
65             SendMessage(label, WM_SETFONT, (WPARAM) GetStockObject(DEFAULT_GUI_FONT), 0);
66
67             label = CreateWindow("static", "Audio Driver:",
68                                  WS_CHILD | WS_VISIBLE,
69                                  190, 13, 70, 15, hwnd,
70                                  NULL, ((LPCREATESTRUCT) lParam) -> hInstance,
71                                  NULL);
72             SendMessage(label, WM_SETFONT, (WPARAM) GetStockObject(DEFAULT_GUI_FONT), 0);
73
74             label = CreateWindow("static", "Extra stereo coefficient:",
75                                  WS_CHILD | WS_VISIBLE,
76                                  10, 126, 115, 15, hwnd,
77                                  NULL, ((LPCREATESTRUCT) lParam) -> hInstance,
78                                  NULL);
79             SendMessage(label, WM_SETFONT, (WPARAM) GetStockObject(DEFAULT_GUI_FONT), 0);
80
81             label = CreateWindow("static", "Audio delay:",
82                                  WS_CHILD | WS_VISIBLE,
83                                  36, 165, 115, 15, hwnd,
84                                  NULL, ((LPCREATESTRUCT) lParam) -> hInstance,
85                                  NULL);
86             SendMessage(label, WM_SETFONT, (WPARAM) GetStockObject(DEFAULT_GUI_FONT), 0);
87
88             label = CreateWindow("static", "OSD level:",
89                                  WS_CHILD | WS_VISIBLE,
90                                  10, 264, 115, 15, hwnd,
91                                  NULL, ((LPCREATESTRUCT) lParam) -> hInstance,
92                                  NULL);
93             SendMessage(label, WM_SETFONT, (WPARAM) GetStockObject(DEFAULT_GUI_FONT), 0);
94
95             label = CreateWindow("static", "DVD device:",
96                                  WS_CHILD | WS_VISIBLE,
97                                  80, 363, 115, 15, hwnd,
98                                  NULL, ((LPCREATESTRUCT) lParam) -> hInstance,
99                                  NULL);
100             SendMessage(label, WM_SETFONT, (WPARAM) GetStockObject(DEFAULT_GUI_FONT), 0);
101
102             label = CreateWindow("static", "CD device:",
103                                  WS_CHILD | WS_VISIBLE,
104                                  202, 363, 115, 15, hwnd,
105                                  NULL, ((LPCREATESTRUCT) lParam) -> hInstance,
106                                  NULL);
107             SendMessage(label, WM_SETFONT, (WPARAM) GetStockObject(DEFAULT_GUI_FONT), 0);
108
109             label = CreateWindow("static", "Priority:",
110                                  WS_CHILD | WS_VISIBLE,
111                                  217, 264, 115, 15, hwnd,
112                                  NULL, ((LPCREATESTRUCT) lParam) -> hInstance,
113                                  NULL);
114             SendMessage(label, WM_SETFONT, (WPARAM) GetStockObject(DEFAULT_GUI_FONT), 0);
115
116             vo_driver = CreateWindow("combobox", NULL,
117                                      CBS_DROPDOWNLIST | CB_SHOWDROPDOWN |
118                                      CBS_NOINTEGRALHEIGHT | CBS_HASSTRINGS |
119                                      WS_CHILD | WS_VISIBLE |
120                                      WS_VSCROLL | WS_TABSTOP,
121                                      80, 10, 100, 160, hwnd,
122                                      (HMENU) ID_VO_DRIVER,
123                                      ((LPCREATESTRUCT) lParam) -> hInstance,
124                                      NULL);
125
126             ao_driver = CreateWindow("combobox", NULL,
127                                      CBS_DROPDOWNLIST | CB_SHOWDROPDOWN |
128                                      CBS_NOINTEGRALHEIGHT | CBS_HASSTRINGS |
129                                      WS_CHILD | WS_VISIBLE |
130                                      WS_VSCROLL | WS_TABSTOP,
131                                      260, 10, 100, 160, hwnd,
132                                      (HMENU) ID_AO_DRIVER,
133                                      ((LPCREATESTRUCT) lParam) -> hInstance,
134                                      NULL);
135
136             prio = CreateWindow("combobox", NULL,
137                                 CBS_DROPDOWNLIST | CB_SHOWDROPDOWN |
138                                 CBS_NOINTEGRALHEIGHT | CBS_HASSTRINGS |
139                                 WS_CHILD | WS_VISIBLE |
140                                 WS_VSCROLL | WS_TABSTOP,
141                                 260, 260, 100, 160, hwnd,
142                                 (HMENU) ID_PRIO,
143                                 ((LPCREATESTRUCT) lParam) -> hInstance,
144                                 NULL);
145
146             /* checkboxes */
147             btn = CreateWindow("button", "Enable double buffering",
148                                WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX,
149                                25, 35, 150, 25,
150                                hwnd, (HMENU) ID_DOUBLE,
151                                ((LPCREATESTRUCT) lParam) -> hInstance,
152                                NULL);
153             SendMessage(btn, WM_SETFONT, (WPARAM) GetStockObject(DEFAULT_GUI_FONT), 0);
154
155             btn = CreateWindow("button", "Enable direct rendering",
156                                WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX,
157                                25, 57, 150, 25,
158                                hwnd, (HMENU) ID_DIRECT,
159                                ((LPCREATESTRUCT) lParam) -> hInstance,
160                                NULL);
161             SendMessage(btn, WM_SETFONT, (WPARAM) GetStockObject(DEFAULT_GUI_FONT), 0);
162
163             btn = CreateWindow("button", "Enable framedropping",
164                                WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX,
165                                25, 79, 150, 25,
166                                hwnd, (HMENU) ID_FRAMEDROP,
167                                ((LPCREATESTRUCT) lParam) -> hInstance,
168                                NULL);
169             SendMessage(btn, WM_SETFONT, (WPARAM) GetStockObject(DEFAULT_GUI_FONT), 0);
170
171             btn = CreateWindow("button", "Normalize sound",
172                                WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX,
173                                205, 35, 150, 25,
174                                hwnd, (HMENU) ID_NORMALIZE,
175                                ((LPCREATESTRUCT) lParam) -> hInstance,
176                                NULL);
177             SendMessage(btn, WM_SETFONT, (WPARAM) GetStockObject(DEFAULT_GUI_FONT), 0);
178
179             btn = CreateWindow("button", "Enable software mixer",
180                                WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX,
181                                205, 57, 150, 25,
182                                hwnd, (HMENU) ID_SOFTMIX,
183                                ((LPCREATESTRUCT) lParam) -> hInstance,
184                                NULL);
185             SendMessage(btn, WM_SETFONT, (WPARAM) GetStockObject(DEFAULT_GUI_FONT), 0);
186
187             btn = CreateWindow("button", "Enable extra stereo",
188                                WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX,
189                                205, 79, 150, 25,
190                                hwnd, (HMENU) ID_EXTRASTEREO,
191                                ((LPCREATESTRUCT) lParam) -> hInstance,
192                                NULL);
193             SendMessage(btn, WM_SETFONT, (WPARAM) GetStockObject(DEFAULT_GUI_FONT), 0);
194
195             btn = CreateWindow("button", "Enable cache",
196                                WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX,
197                                10, 200, 90, 25,
198                                hwnd, (HMENU) ID_CACHE,
199                                ((LPCREATESTRUCT) lParam) -> hInstance,
200                                NULL);
201             SendMessage(btn, WM_SETFONT, (WPARAM) GetStockObject(DEFAULT_GUI_FONT), 0);
202
203             btn = CreateWindow("button", "Enable autosync",
204                                WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX,
205                                192, 200, 100, 25, hwnd,
206                                (HMENU) ID_AUTOSYNC,
207                                ((LPCREATESTRUCT) lParam) -> hInstance,
208                                NULL);
209             SendMessage(btn, WM_SETFONT, (WPARAM) GetStockObject(DEFAULT_GUI_FONT), 0);
210
211             btn = CreateWindow("button", "Display videos in the sub window",
212                                WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX,
213                                85, 227, 250, 25,
214                                hwnd, (HMENU) ID_SUBWINDOW,
215                                ((LPCREATESTRUCT) lParam) -> hInstance,
216                                NULL);
217             SendMessage(btn, WM_SETFONT, (WPARAM) GetStockObject(DEFAULT_GUI_FONT), 0);
218
219             /* osd level */
220             btn = CreateWindow("button", "None",
221                                WS_CHILD | WS_VISIBLE | BS_AUTORADIOBUTTON,
222                                95, 260, 100, 25, hwnd,
223                                (HMENU) ID_NONE,
224                                ((LPCREATESTRUCT) lParam) -> hInstance,
225                                NULL);
226             SendMessage(btn, WM_SETFONT, (WPARAM) GetStockObject(DEFAULT_GUI_FONT), 0);
227
228             btn = CreateWindow("button", "Timer and indicators",
229                                WS_CHILD | WS_VISIBLE | BS_AUTORADIOBUTTON,
230                                95, 280, 180, 25, hwnd,
231                                (HMENU) ID_OSD1,
232                                ((LPCREATESTRUCT) lParam) -> hInstance,
233                                NULL);
234             SendMessage(btn, WM_SETFONT, (WPARAM) GetStockObject(DEFAULT_GUI_FONT), 0);
235
236             btn = CreateWindow("button", "Progress bar only",
237                                WS_CHILD | WS_VISIBLE | BS_AUTORADIOBUTTON,
238                                95, 300, 180, 25, hwnd,
239                                (HMENU) ID_OSD2,
240                                ((LPCREATESTRUCT) lParam) -> hInstance,
241                                NULL);
242             SendMessage(btn, WM_SETFONT, (WPARAM) GetStockObject(DEFAULT_GUI_FONT), 0);
243
244             btn = CreateWindow("button", "Timer, percentage, and total time",
245                                WS_CHILD | WS_VISIBLE | BS_AUTORADIOBUTTON,
246                                95, 320, 180, 25, hwnd,
247                                (HMENU) ID_OSD3,
248                                ((LPCREATESTRUCT) lParam) -> hInstance,
249                                NULL);
250             SendMessage(btn, WM_SETFONT, (WPARAM) GetStockObject(DEFAULT_GUI_FONT), 0);
251
252             btn = CreateWindow("button", "Apply",
253                                WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
254                                199, 395, 80, 25, hwnd,
255                                (HMENU) ID_APPLY,
256                                ((LPCREATESTRUCT) lParam) -> hInstance,
257                                NULL);
258             SendMessage(btn, WM_SETFONT, (WPARAM) GetStockObject(DEFAULT_GUI_FONT), 0);
259
260             btn = CreateWindow("button", "Cancel",
261                                WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
262                                285, 395, 80, 25, hwnd,
263                                (HMENU) ID_CANCEL,
264                                ((LPCREATESTRUCT) lParam) -> hInstance,
265                                NULL);
266             SendMessage(btn, WM_SETFONT, (WPARAM) GetStockObject(DEFAULT_GUI_FONT), 0);
267
268             btn = CreateWindow("button", "Defaults",
269                                WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
270                                4, 395, 80, 25, hwnd,
271                                (HMENU) ID_DEFAULTS,
272                                ((LPCREATESTRUCT) lParam) -> hInstance,
273                                NULL);
274             SendMessage(btn, WM_SETFONT, (WPARAM) GetStockObject(DEFAULT_GUI_FONT), 0);
275
276             /* extra stereo coefficient trackbar */
277             track1 = CreateWindow(TRACKBAR_CLASS, "Coefficient",
278                                   WS_CHILD | WS_VISIBLE | WS_TABSTOP |
279                                   WS_DISABLED | TBS_HORZ |
280                                   TBS_BOTTOM | TBS_NOTICKS,
281                                   120, 120, 245, 35, hwnd,
282                                   (HMENU) ID_TRACKBAR1,
283                                   ((LPCREATESTRUCT) lParam) -> hInstance,
284                                   NULL);
285             SendDlgItemMessage(hwnd, ID_TRACKBAR1, TBM_SETRANGE, 1, MAKELONG(-100, 100));
286
287             /* audio delay */
288             track2 = CreateWindow(TRACKBAR_CLASS, "Audio delay",
289                                   WS_CHILD | WS_VISIBLE | WS_TABSTOP |
290                                   WS_DISABLED | TBS_HORZ |
291                                   TBS_BOTTOM | TBS_NOTICKS,
292                                   120, 160, 245, 35, hwnd,
293                                   (HMENU) ID_TRACKBAR2,
294                                   ((LPCREATESTRUCT) lParam) -> hInstance,
295                                   NULL);
296             SendDlgItemMessage(hwnd, ID_TRACKBAR2, TBM_SETRANGE, 1, MAKELONG(-1000, 1000));
297
298             /* cache */
299             edit1 = CreateWindowEx(WS_EX_CLIENTEDGE, "edit", "cache",
300                                    WS_CHILD | WS_VISIBLE | WS_DISABLED |
301                                    ES_LEFT | ES_AUTOHSCROLL,
302                                    105, 203, 40, 20, hwnd,
303                                    (HMENU) ID_EDIT1,
304                                    ((LPCREATESTRUCT) lParam) -> hInstance,
305                                    NULL);
306             SendMessage(edit1, WM_SETFONT, (WPARAM) GetStockObject(DEFAULT_GUI_FONT), 0);
307
308             updown1 = CreateUpDownControl(WS_CHILD | WS_VISIBLE |
309                                           WS_DISABLED | UDS_SETBUDDYINT |
310                                           UDS_ARROWKEYS | UDS_NOTHOUSANDS,
311                                           145, 203, 20, 20, hwnd,
312                                           ID_UPDOWN1,
313                                           ((LPCREATESTRUCT) lParam) -> hInstance,
314                                           (HWND)edit1, 0, 0, 0);
315             SendDlgItemMessage(hwnd, ID_UPDOWN1, UDM_SETRANGE32, (WPARAM)0, (LPARAM)65535);
316
317             /* autosync */
318             edit2 = CreateWindowEx(WS_EX_CLIENTEDGE, "edit", "autosync",
319                                    WS_CHILD | WS_VISIBLE | WS_DISABLED |
320                                    ES_LEFT | ES_AUTOHSCROLL,
321                                    300, 203, 40, 20, hwnd,
322                                    (HMENU) ID_EDIT2,
323                                    ((LPCREATESTRUCT) lParam) -> hInstance,
324                                    NULL);
325             SendMessage(edit2, WM_SETFONT, (WPARAM) GetStockObject(DEFAULT_GUI_FONT), 0);
326
327             updown2 = CreateUpDownControl(WS_CHILD | WS_VISIBLE |
328                                           WS_DISABLED | UDS_SETBUDDYINT |
329                                           UDS_ARROWKEYS | UDS_NOTHOUSANDS,
330                                           340, 203, 20, 20, hwnd,
331                                           ID_UPDOWN2,
332                                           ((LPCREATESTRUCT) lParam) -> hInstance,
333                                           (HWND)edit2, 0, 0, 0);
334             SendDlgItemMessage(hwnd, ID_UPDOWN2, UDM_SETRANGE32, (WPARAM)0, (LPARAM)10000);
335
336             /* dvd and cd devices */
337             edit3 = CreateWindowEx(WS_EX_CLIENTEDGE, "edit", NULL,
338                                    WS_CHILD | WS_VISIBLE |
339                                    ES_LEFT | ES_AUTOHSCROLL,
340                                    145, 360, 20, 20, hwnd,
341                                    (HMENU) ID_DVDDEVICE,
342                                    ((LPCREATESTRUCT) lParam) -> hInstance,
343                                    NULL);
344             SendMessage(edit3, WM_SETFONT, (WPARAM) GetStockObject(DEFAULT_GUI_FONT), 0);
345
346             edit3 = CreateWindowEx(WS_EX_CLIENTEDGE, "edit", NULL,
347                                    WS_CHILD | WS_VISIBLE |
348                                    ES_LEFT| ES_AUTOHSCROLL,
349                                    260, 360, 20, 20, hwnd,
350                                    (HMENU) ID_CDDEVICE,
351                                    ((LPCREATESTRUCT) lParam) -> hInstance,
352                                    NULL);
353             SendMessage(edit3, WM_SETFONT, (WPARAM) GetStockObject(DEFAULT_GUI_FONT), 0);
354
355             while(video_out_drivers[i])
356             {
357                 const vo_info_t *info = video_out_drivers[i++]->info;
358                 if(!video_driver_list) gaddlist(&video_driver_list, (char *)info->short_name);
359                     SendDlgItemMessage(hwnd, ID_VO_DRIVER, CB_ADDSTRING, 0, (LPARAM) info->short_name);
360             }
361             /* Special case for directx:noaccel */
362             SendDlgItemMessage(hwnd, ID_VO_DRIVER, CB_ADDSTRING, 0, (LPARAM) "directx:noaccel");
363             SendMessage(vo_driver, WM_SETFONT, (WPARAM) GetStockObject(DEFAULT_GUI_FONT), 0);
364
365             while(audio_out_drivers[j])
366             {
367                 const ao_info_t *info = audio_out_drivers[j++]->info;
368                 if(!audio_driver_list)
369                 {
370                     // FIXME: default priority (i.e. order in audio_out_drivers) should be fixed instead
371                     // if win32 as default is really desirable
372                     gaddlist(&audio_driver_list, "win32"/*(char *)info->short_name*/);
373                 }
374                 SendDlgItemMessage(hwnd, ID_AO_DRIVER, CB_ADDSTRING, 0, (LPARAM) info->short_name);
375             }
376             SendMessage(ao_driver, WM_SETFONT, (WPARAM) GetStockObject(DEFAULT_GUI_FONT), 0);
377
378             /* priority list, i'm leaving out realtime for safety's sake */
379             SendDlgItemMessage(hwnd, ID_PRIO, CB_INSERTSTRING, 0, (LPARAM) "low");
380             SendDlgItemMessage(hwnd, ID_PRIO, CB_INSERTSTRING, 0, (LPARAM) "belownormal");
381             SendDlgItemMessage(hwnd, ID_PRIO, CB_INSERTSTRING, 0, (LPARAM) "normal");
382             SendDlgItemMessage(hwnd, ID_PRIO, CB_INSERTSTRING, 0, (LPARAM) "abovenormal");
383             SendDlgItemMessage(hwnd, ID_PRIO, CB_INSERTSTRING, 0, (LPARAM) "high");
384             SendMessage(prio, WM_SETFONT, (WPARAM) GetStockObject(DEFAULT_GUI_FONT), 0);
385
386             /* set our preferences on what we already have */
387             if(video_driver_list)
388                 SendDlgItemMessage(hwnd, ID_VO_DRIVER, CB_SETCURSEL,
389                                    (WPARAM)SendMessage(vo_driver, CB_FINDSTRING, -1,
390                                    (LPARAM)video_driver_list[0]), 0);
391
392             if(audio_driver_list)
393                 SendDlgItemMessage(hwnd, ID_AO_DRIVER, CB_SETCURSEL,
394                                    (WPARAM)SendMessage(ao_driver, CB_FINDSTRING, -1,
395                                    (LPARAM)audio_driver_list[0]), 0);
396
397             if(vo_doublebuffering)
398                 SendDlgItemMessage(hwnd, ID_DOUBLE, BM_SETCHECK, 1, 0);
399             if(vo_directrendering)
400                 SendDlgItemMessage(hwnd, ID_DIRECT, BM_SETCHECK, 1, 0);
401             if(frame_dropping)
402                 SendDlgItemMessage(hwnd, ID_FRAMEDROP, BM_SETCHECK, 1, 0);
403             if(gtkAONorm)
404                 SendDlgItemMessage(hwnd, ID_NORMALIZE, BM_SETCHECK, 1, 0);
405             if(soft_vol)
406                 SendDlgItemMessage(hwnd, ID_SOFTMIX, BM_SETCHECK, 1, 0);
407             if(gtkAOExtraStereo)
408             {
409                 SendDlgItemMessage(hwnd, ID_EXTRASTEREO, BM_SETCHECK, 1, 0);
410                 if(!guiIntfStruct.Playing)
411                 {
412                     EnableWindow(track1, 1);
413                     EnableWindow(track2, 1);
414                 }
415             }
416             else gtkAOExtraStereoMul = 1.0;
417             SendDlgItemMessage(hwnd, ID_TRACKBAR1, TBM_SETPOS, 1, (LPARAM)stereopos);
418
419             if(audio_delay)
420                 SendDlgItemMessage(hwnd, ID_TRACKBAR2, TBM_SETPOS, 1, (LPARAM)delaypos);
421
422             if(gtkCacheOn) {
423                 SendDlgItemMessage(hwnd, ID_CACHE, BM_SETCHECK, 1, 0);
424                 EnableWindow(edit1, 1);
425                 EnableWindow(updown1, 1);
426             }
427             else gtkCacheSize = 2048;
428             SendDlgItemMessage(hwnd, ID_UPDOWN1, UDM_SETPOS32, 0, (LPARAM)gtkCacheSize);
429
430             if(gtkAutoSyncOn) {
431                 SendDlgItemMessage(hwnd, ID_AUTOSYNC, BM_SETCHECK, 1, 0);
432                 EnableWindow(edit2, 1);
433                 EnableWindow(updown2, 1);
434             }
435             else gtkAutoSync = 0;
436             SendDlgItemMessage(hwnd, ID_UPDOWN2, UDM_SETPOS32, 0, (LPARAM)gtkAutoSync);
437
438             if(sub_window)
439                 SendDlgItemMessage(hwnd, ID_SUBWINDOW, BM_SETCHECK, 1, 0);
440
441             if(!osd_level)
442                 SendDlgItemMessage(hwnd, ID_NONE, BM_SETCHECK, 1, 0);
443             else if(osd_level == 1)
444                 SendDlgItemMessage(hwnd, ID_OSD1, BM_SETCHECK, 1, 0);
445             else if(osd_level == 2)
446                 SendDlgItemMessage(hwnd, ID_OSD2, BM_SETCHECK, 1, 0);
447             else if(osd_level == 3)
448                 SendDlgItemMessage(hwnd, ID_OSD3, BM_SETCHECK, 1, 0);
449
450             if(dvd_device)
451                 SendDlgItemMessage(hwnd, ID_DVDDEVICE, WM_SETTEXT, 0, (LPARAM)dvd_device);
452             else SendDlgItemMessage(hwnd, ID_DVDDEVICE, WM_SETTEXT, 0, (LPARAM)"D:");
453
454             if(cdrom_device)
455                 SendDlgItemMessage(hwnd, ID_CDDEVICE, WM_SETTEXT, 0, (LPARAM)cdrom_device);
456             else SendDlgItemMessage(hwnd, ID_CDDEVICE, WM_SETTEXT, 0, (LPARAM)"D:");
457
458             if(proc_priority)
459                 SendDlgItemMessage(hwnd, ID_PRIO, CB_SETCURSEL,
460                                    (WPARAM)SendMessage(prio, CB_FINDSTRING, -1,
461                                    (LPARAM)proc_priority), 0);
462
463             else SendDlgItemMessage(hwnd, ID_PRIO, CB_SETCURSEL, 2, 0);
464
465             break;
466         }
467         case WM_CTLCOLORDLG:
468         case WM_CTLCOLOREDIT:
469         case WM_CTLCOLORBTN:
470         case WM_CTLCOLORSTATIC:
471         {
472             HDC hdc = (HDC)wParam;
473             SetBkMode(hdc, TRANSPARENT);
474             return (INT_PTR)SOLID_GREY;
475         }
476         break;
477         case WM_COMMAND:
478         {
479             switch (LOWORD(wParam))
480             {
481                 case ID_EXTRASTEREO:
482                 {
483                     if(SendDlgItemMessage(hwnd, ID_EXTRASTEREO, BM_GETCHECK, 0, 0) == BST_CHECKED)
484                     {
485                         EnableWindow(GetDlgItem(hwnd, ID_TRACKBAR1), 1);
486                         EnableWindow(GetDlgItem(hwnd, ID_TRACKBAR2), 1);
487                     } else {
488                         EnableWindow(GetDlgItem(hwnd, ID_TRACKBAR1), 0);
489                         EnableWindow(GetDlgItem(hwnd, ID_TRACKBAR2), 0);
490                         SendDlgItemMessage(hwnd, ID_TRACKBAR1, TBM_SETPOS, 1, (LPARAM)10.0);
491                         SendDlgItemMessage(hwnd, ID_TRACKBAR2, TBM_SETPOS, 1, (LPARAM)0);
492                     }
493                     break;
494                 }
495                 case ID_CACHE:
496                 {
497                     if(SendDlgItemMessage(hwnd, ID_CACHE, BM_GETCHECK, 0, 0) == BST_CHECKED)
498                     {
499                         EnableWindow(GetDlgItem(hwnd, ID_EDIT1), 1);
500                         EnableWindow(GetDlgItem(hwnd, ID_UPDOWN1), 1);
501                     } else {
502                         EnableWindow(GetDlgItem(hwnd, ID_EDIT1), 0);
503                         EnableWindow(GetDlgItem(hwnd, ID_UPDOWN1), 0);
504                         SendDlgItemMessage(hwnd, ID_UPDOWN1, UDM_SETPOS32, 1, (LPARAM)2048);
505                     }
506                     break;
507                 }
508                 case ID_AUTOSYNC:
509                 {
510                     if(SendDlgItemMessage(hwnd, ID_AUTOSYNC, BM_GETCHECK, 0, 0) == BST_CHECKED)
511                     {
512                         EnableWindow(GetDlgItem(hwnd, ID_EDIT2), 1);
513                         EnableWindow(GetDlgItem(hwnd, ID_UPDOWN2), 1);
514                     } else {
515                         EnableWindow(GetDlgItem(hwnd, ID_EDIT2), 0);
516                         EnableWindow(GetDlgItem(hwnd, ID_UPDOWN2), 0);
517                         SendDlgItemMessage(hwnd, ID_UPDOWN2, UDM_SETPOS32, 1, (LPARAM)0);
518                     }
519                     break;
520                 }
521                 case ID_DEFAULTS:
522                 {
523                     set_defaults();
524                     SendDlgItemMessage(hwnd, ID_VO_DRIVER, CB_SETCURSEL,
525                                        (WPARAM)SendMessage(vo_driver, CB_FINDSTRING, -1, (LPARAM)"directx"), 0);
526
527                     SendDlgItemMessage(hwnd, ID_AO_DRIVER, CB_SETCURSEL,
528                                        (WPARAM)SendMessage(ao_driver, CB_FINDSTRING, -1, (LPARAM)"dsound"), 0);
529
530                     SendDlgItemMessage(hwnd, ID_PRIO, CB_SETCURSEL,
531                                        (WPARAM)SendMessage(prio, CB_FINDSTRING, -1, (LPARAM)proc_priority), 0);
532
533                     SendDlgItemMessage(hwnd, ID_TRACKBAR1, TBM_SETPOS, 1, (LPARAM)10.0);
534                     SendDlgItemMessage(hwnd, ID_TRACKBAR2, TBM_SETPOS, 1, (LPARAM)0.0);
535                     SendDlgItemMessage(hwnd, ID_UPDOWN1, UDM_SETPOS32, 0, (LPARAM)gtkCacheSize);
536                     SendDlgItemMessage(hwnd, ID_UPDOWN2, UDM_SETPOS32, 0, (LPARAM)gtkAutoSync);
537                     SendDlgItemMessage(hwnd, ID_DOUBLE, BM_SETCHECK, 0, 0);
538                     SendDlgItemMessage(hwnd, ID_DIRECT, BM_SETCHECK, 0, 0);
539                     SendDlgItemMessage(hwnd, ID_FRAMEDROP, BM_SETCHECK, 0, 0);
540                     SendDlgItemMessage(hwnd, ID_NORMALIZE, BM_SETCHECK, 0, 0);
541                     SendDlgItemMessage(hwnd, ID_SOFTMIX, BM_SETCHECK, 0, 0);
542                     SendDlgItemMessage(hwnd, ID_EXTRASTEREO, BM_SETCHECK, 0, 0);
543                     SendDlgItemMessage(hwnd, ID_CACHE, BM_SETCHECK, 0, 0);
544                     SendDlgItemMessage(hwnd, ID_AUTOSYNC, BM_SETCHECK, 0, 0);
545                     SendDlgItemMessage(hwnd, ID_SUBWINDOW, BM_SETCHECK, 1, 0);
546                     SendDlgItemMessage(hwnd, ID_NONE, BM_SETCHECK, 0, 0);
547                     SendDlgItemMessage(hwnd, ID_OSD1, BM_SETCHECK, 1, 0);
548                     SendDlgItemMessage(hwnd, ID_OSD2, BM_SETCHECK, 0, 0);
549                     SendDlgItemMessage(hwnd, ID_OSD3, BM_SETCHECK, 0, 0);
550                     SendDlgItemMessage(hwnd, ID_DVDDEVICE, WM_SETTEXT, 0, (LPARAM)"D:");
551                     SendDlgItemMessage(hwnd, ID_CDDEVICE, WM_SETTEXT, 0, (LPARAM)"D:");
552                     SendMessage(hwnd, WM_COMMAND, (WPARAM)ID_APPLY, 0);
553                     break;
554                 }
555                 case ID_CANCEL:
556                     DestroyWindow(hwnd);
557                     return 0;
558                 case ID_APPLY:
559                 {
560                     int strl;
561                     if(guiIntfStruct.Playing) guiGetEvent(guiCEvent, (void *)guiSetStop);
562
563                     /* Set the video driver */
564                     gfree(video_driver_list[0]);
565                     strl = SendMessage(vo_driver, CB_GETCURSEL, 0, 0);
566                     video_driver_list[0] = malloc(strl);
567                     SendMessage(vo_driver, CB_GETLBTEXT, (WPARAM)strl,
568                                 (LPARAM)video_driver_list[0]);
569
570                     /* Set the audio driver */
571                     gfree(audio_driver_list[0]);
572                     strl = SendMessage(ao_driver, CB_GETCURSEL, 0, 0);
573                     audio_driver_list[0] = malloc(strl);
574                     SendMessage(ao_driver, CB_GETLBTEXT, (WPARAM)strl,
575                                 (LPARAM)audio_driver_list[0]);
576
577                     /* Set the priority level */
578                     SendMessage(prio, CB_GETLBTEXT, (WPARAM)SendMessage(prio, CB_GETCURSEL, 0, 0), (LPARAM)procprio);
579                     proc_priority = strdup(procprio);
580
581                     /* double buffering */
582                     if(SendDlgItemMessage(hwnd, ID_DOUBLE, BM_GETCHECK, 0, 0) == BST_CHECKED)
583                         vo_doublebuffering = 1;
584                     else vo_doublebuffering = 0;
585
586                     /* direct rendering */
587                     if(SendDlgItemMessage(hwnd, ID_DIRECT, BM_GETCHECK, 0, 0) == BST_CHECKED)
588                         vo_directrendering = 1;
589                     else vo_directrendering = 0;
590
591                     /* frame dropping */
592                     if(SendDlgItemMessage(hwnd, ID_FRAMEDROP, BM_GETCHECK, 0, 0) == BST_CHECKED)
593                         frame_dropping = 1;
594                     else frame_dropping = 0;
595
596                     /* normalize */
597                     if(SendDlgItemMessage(hwnd, ID_NORMALIZE, BM_GETCHECK, 0, 0) == BST_CHECKED)
598                         gtkAONorm = 1;
599                     else gtkAONorm = 0;
600
601                     /* software mixer */
602                     if(SendDlgItemMessage(hwnd, ID_SOFTMIX, BM_GETCHECK, 0, 0) == BST_CHECKED)
603                         soft_vol = 1;
604                     else soft_vol = 0;
605
606                     /* extra stereo */
607                     if(SendDlgItemMessage(hwnd, ID_EXTRASTEREO, BM_GETCHECK, 0, 0) == BST_CHECKED)
608                         gtkAOExtraStereo = 1;
609                     else {
610                         gtkAOExtraStereo = 0;
611                         gtkAOExtraStereoMul = 10.0;
612                     }
613                     gtkAOExtraStereoMul = SendDlgItemMessage(hwnd, ID_TRACKBAR1, TBM_GETPOS, 0, 0) / 10.0;
614
615                     /* audio delay */
616                     audio_delay = SendDlgItemMessage(hwnd, ID_TRACKBAR2, TBM_GETPOS, 0, 0) / 100.0;
617
618                     /* cache */
619                     if(SendDlgItemMessage(hwnd, ID_CACHE, BM_GETCHECK, 0, 0) == BST_CHECKED)
620                         gtkCacheOn = 1;
621                     else gtkCacheOn = 0;
622                     gtkCacheSize = SendDlgItemMessage(hwnd, ID_UPDOWN1, UDM_GETPOS32, 0, 0);
623
624                     /* autosync */
625                     if(SendDlgItemMessage(hwnd, ID_AUTOSYNC, BM_GETCHECK, 0, 0) == BST_CHECKED)
626                         gtkAutoSyncOn = 1;
627                     else gtkAutoSyncOn = 0;
628                     gtkAutoSync = SendDlgItemMessage(hwnd, ID_UPDOWN2, UDM_GETPOS32, 0, 0);
629
630                     /* sub window */
631                     if(SendDlgItemMessage(hwnd, ID_SUBWINDOW, BM_GETCHECK, 0, 0) == BST_CHECKED)
632                         sub_window = 1;
633                     else sub_window = 0;
634
635                     /* osd level */
636                     if(SendDlgItemMessage(hwnd, ID_NONE, BM_GETCHECK, 0, 0) == BST_CHECKED)
637                         osd_level = 0;
638                     else if(SendDlgItemMessage(hwnd, ID_OSD1, BM_GETCHECK, 0, 0) == BST_CHECKED)
639                         osd_level = 1;
640                     else if(SendDlgItemMessage(hwnd, ID_OSD2, BM_GETCHECK, 0, 0) == BST_CHECKED)
641                         osd_level = 2;
642                     else if(SendDlgItemMessage(hwnd, ID_OSD3, BM_GETCHECK, 0, 0) == BST_CHECKED)
643                         osd_level = 3;
644
645                     /* dvd and cd devices */
646                     SendDlgItemMessage(hwnd, ID_DVDDEVICE, WM_GETTEXT, MAX_PATH, (LPARAM)dvddevice);
647                     dvd_device = strdup(dvddevice);
648                     SendDlgItemMessage(hwnd, ID_CDDEVICE, WM_GETTEXT, MAX_PATH, (LPARAM)cdromdevice);
649                     cdrom_device = strdup(cdromdevice);
650
651                     MessageBox(hwnd, "You must restart MPlayer for the changes to take effect.", "MPlayer - Info:", MB_OK);
652                     DestroyWindow(hwnd);
653                     break;
654                 }
655             }
656             return 0;
657         }
658     }
659     return DefWindowProc(hwnd, iMsg, wParam, lParam);
660 }
661
662 void display_prefswindow(gui_t *gui)
663 {
664     HWND hWnd;
665     HINSTANCE hInstance = GetModuleHandle(NULL);
666     WNDCLASS wc;
667     int x, y;
668     if(FindWindow(NULL, "MPlayer - Preferences")) return;
669     wc.style         = CS_HREDRAW | CS_VREDRAW;
670     wc.lpfnWndProc   = PrefsWndProc;
671     wc.cbClsExtra    = 0;
672     wc.cbWndExtra    = 0;
673     wc.hInstance     = hInstance;
674     wc.hCursor       = LoadCursor(NULL,IDC_ARROW);
675     wc.hIcon         = gui->icon;
676     wc.hbrBackground = SOLID_GREY;
677     wc.lpszClassName = "MPlayer - Preferences";
678     wc.lpszMenuName  = NULL;
679     RegisterClass(&wc);
680     x = (GetSystemMetrics(SM_CXSCREEN) / 2) - (375 / 2);
681     y = (GetSystemMetrics(SM_CYSCREEN) / 2) - (452 / 2);
682     hWnd = CreateWindow("MPlayer - Preferences",
683                         "MPlayer - Preferences",
684                         WS_POPUPWINDOW | WS_CAPTION,
685                         x,
686                         y,
687                         375,
688                         452,
689                         NULL,
690                         NULL,
691                         hInstance,
692                         NULL);
693    SetWindowLongPtr(hWnd, GWLP_USERDATA, (DWORD) gui);
694    ShowWindow(hWnd, SW_SHOW);
695    UpdateWindow(hWnd);
696 }
697
698 static void set_defaults(void)
699 {
700     proc_priority = "normal";
701     vo_doublebuffering = 1;
702     vo_directrendering = 0;
703     frame_dropping = 0;
704     soft_vol = 0;
705     gtkAONorm = 0;
706     gtkAOExtraStereo = 0;
707     gtkAOExtraStereoMul = 1.0;
708     audio_delay = 0.0;
709     sub_window = 1;
710     gtkCacheOn = 0;
711     gtkCacheSize = 2048;
712     gtkAutoSyncOn = 0;
713     gtkAutoSync = 0;
714 }