[cvs] / xvidcore / vfw / src / config.c Repository:
ViewVC logotype

Diff of /xvidcore/vfw/src/config.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1, Sat Feb 22 08:24:01 2003 UTC revision 1.1.2.31, Sun Jan 25 06:06:22 2004 UTC
# Line 0  Line 1 
1    /**************************************************************************
2     *
3     *      XVID VFW FRONTEND
4     *      config
5     *
6     *      This program is free software; you can redistribute it and/or modify
7     *      it under the terms of the GNU General Public License as published by
8     *      the Free Software Foundation; either version 2 of the License, or
9     *      (at your option) any later version.
10     *
11     *      This program is distributed in the hope that it will be useful,
12     *      but WITHOUT ANY WARRANTY; without even the implied warranty of
13     *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     *      GNU General Public License for more details.
15     *
16     *      You should have received a copy of the GNU General Public License
17     *      along with this program; if not, write to the Free Software
18     *      Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19     *
20     *************************************************************************/
21    
22    /**************************************************************************
23     *
24     *      History:
25     *
26     *      15.06.2002      added bframes options
27     *      21.04.2002      fixed custom matrix support, tried to get dll size down
28     *      17.04.2002      re-enabled lumi masking in 1st pass
29     *      15.04.2002      updated cbr support
30     *      07.04.2002      min keyframe interval checkbox
31     *                              2-pass max bitrate and overflow customization
32     *      04.04.2002      interlacing support
33     *                              hinted ME support
34     *      24.03.2002      daniel smith <danielsmith@astroboymail.com>
35     *                              added Foxer's new CBR engine
36     *                              - cbr_buffer is being used as reaction delay (quick hack)
37     *      23.03.2002      daniel smith <danielsmith@astroboymail.com>
38     *                              added load defaults button
39     *                              merged foxer's alternative 2-pass code (2-pass alt tab)
40     *                              added proper tooltips
41     *                              moved registry data into reg_ints/reg_strs arrays
42     *                              added DEBUGERR output on errors instead of returning
43     *      16.03.2002      daniel smith <danielsmith@astroboymail.com>
44     *                              rewrote/restructured most of file
45     *                              added tooltips (kind of - dirty message hook method)
46     *                              split tabs into a main dialog / advanced prop sheet
47     *                              advanced controls are now enabled/disabled by mode
48     *                              added modulated quantization, DX50 fourcc
49     *      11.03.2002  Min Chen <chenm001@163.com>
50     *                        now get Core Version use xvid_init()
51     *      05.03.2002  Min Chen <chenm001@163.com>
52     *                              Add Core version display to about box
53     *      01.12.2001      inital version; (c)2001 peter ross <pross@xvid.org>
54     *
55     *************************************************************************/
56    
57    
58    #include <windows.h>
59    #include <commctrl.h>
60    #include <shlobj.h>
61    #include <prsht.h>
62    
63    #include <stdio.h>  /* sprintf */
64    #include <xvid.h>       /* XviD API */
65    
66    #include "debug.h"
67    #include "config.h"
68    #include "resource.h"
69    
70    
71    #define CONSTRAINVAL(X,Y,Z) if((X)<(Y)) X=Y; if((X)>(Z)) X=Z;
72    #define IsDlgChecked(hwnd,idc)  (IsDlgButtonChecked(hwnd,idc) == BST_CHECKED)
73    #define CheckDlg(hwnd,idc,value) CheckDlgButton(hwnd,idc, value?BST_CHECKED:BST_UNCHECKED)
74    #define EnableDlgWindow(hwnd,idc,state) EnableWindow(GetDlgItem(hwnd,idc),state)
75    
76    static void zones_update(HWND hDlg, CONFIG * config);
77    
78    HINSTANCE g_hInst;
79    HWND g_hTooltip;
80    
81    static int g_use_bitrate = 1;
82    int pp_dy, pp_duv, pp_dr, pp_fe; /* decoder options */
83    
84    /* enumerates child windows, assigns tooltips */
85    BOOL CALLBACK enum_tooltips(HWND hWnd, LPARAM lParam)
86    {
87            char help[500];
88    
89            if (LoadString(g_hInst, GetDlgCtrlID(hWnd), help, 500))
90            {
91                    TOOLINFO ti;
92                    ti.cbSize = sizeof(TOOLINFO);
93                    ti.uFlags = TTF_SUBCLASS | TTF_IDISHWND;
94                    ti.hwnd = GetParent(hWnd);
95                    ti.uId  = (LPARAM)hWnd;
96                    ti.lpszText = help;
97                    SendMessage(g_hTooltip, TTM_ADDTOOL, 0, (LPARAM)&ti);
98            }
99    
100            return TRUE;
101    }
102    
103    
104    /* ===================================================================================== */
105    /* MPEG-4 PROFILES/LEVELS ============================================================== */
106    /* ===================================================================================== */
107    
108    
109    
110    /* default vbv_occupancy is (64/170)*vbv_buffer_size */
111    
112    const profile_t profiles[] =
113    {
114    /*      name                             p@l,   w       h  fps  obj  Tvmv  vmv  vcv   ac%        vbv      pkt   kbps  flags */
115            { "Simple @ L0",           0x08,  176, 144, 15,  1,  198,   99,   1485, 100,  10*16368,  2048,   64, 0 },
116            /* simple@l0: max f_code=1, intra_dc_vlc_threshold=0 */
117            /* if ac preidition is used, adaptive quantization must not be used */
118            /* <=qcif must be used */
119            { "Simple @ L1",           0x01,  176, 144, 15,  4,  198,   99,   1485, 100,  10*16368,  2048,   64, PROFILE_ADAPTQUANT },
120            { "Simple @ L2",           0x02,  352, 288, 15,  4,  792,  396,   5940, 100,  40*16368,  4096,  128, PROFILE_ADAPTQUANT },
121            { "Simple @ L3",           0x03,  352, 288, 15,  4,  792,  396,  11880, 100,  40*16368,  8192,  384, PROFILE_ADAPTQUANT },
122    
123            { "ARTS @ L1",           0x91,  176, 144, 15,  4,  198,   99,   1485, 100,  10*16368,  8192,   64, PROFILE_ARTS },
124            { "ARTS @ L2",           0x92,  352, 288, 15,  4,  792,  396,   5940, 100,  40*16368, 16384,  128, PROFILE_ARTS },
125            { "ARTS @ L3",           0x93,  352, 288, 30,  4,  792,  396,  11880, 100,  40*16368, 16384,  384, PROFILE_ARTS },
126            { "ARTS @ L4",           0x94,  352, 288, 30, 16,  792,  396,  11880, 100,  80*16368, 16384, 2000, PROFILE_ARTS },
127    
128            { "AS @ L0",               0xf0,  176, 144, 30,  1,  297,   99,   2970, 100,  10*16368,  2048,  128, PROFILE_AS },
129            { "AS @ L1",               0xf1,  176, 144, 30,  4,  297,   99,   2970, 100,  10*16368,  2048,  128, PROFILE_AS },
130            { "AS @ L2",               0xf2,  352, 288, 15,  4, 1188,  396,   5940, 100,  40*16368,  4096,  384, PROFILE_AS },
131            { "AS @ L3",               0xf3,  352, 288, 30,  4, 1188,  396,  11880, 100,  40*16368,  4096,  768, PROFILE_AS },
132     /*  ISMA Profile 1, (ASP) @ L3b (CIF, 1.5 Mb/s) CIF(352x288), 30fps, 1.5Mbps max ??? */
133            { "AS @ L4",               0xf4,  352, 576, 30,  4, 2376,  792,  23760,  50,  80*16368,  8192, 3000, PROFILE_AS },
134            { "AS @ L5",               0xf5,  720, 576, 30,  4, 4860, 1620,  48600,  25, 112*16368, 16384, 8000, PROFILE_AS },
135    
136    #ifdef DXN_PROFILES
137            { "DXN Handheld",          0x00,  176, 144, 15, -1,  198,   99,   1485, 100,  16*16368, -1,  128, PROFILE_ADAPTQUANT },
138            { "DXN Portable NTSC", 0x00,  352, 240, 30, -1,  990,  330,   9900, 100,  64*16368,     -1,  768, PROFILE_ADAPTQUANT|PROFILE_BVOP },
139            { "DXN Portable PAL",  0x00,  352, 288, 25, -1, 1188,  396,   9900, 100,  64*16368,     -1,  768, PROFILE_ADAPTQUANT|PROFILE_BVOP },
140            { "DXN HT NTSC",           0x00,  720, 480, 30, -1, 4050, 1350,  40500, 100, 192*16368, -1, 4000, PROFILE_ADAPTQUANT|PROFILE_BVOP|PROFILE_INTERLACE },
141            { "DXN HT PAL",         0x00,  720, 576, 25, -1, 4860, 1620,  40500, 100, 192*16368,    -1, 4000, PROFILE_ADAPTQUANT|PROFILE_BVOP|PROFILE_INTERLACE },
142            { "DXN HDTV",             0x00, 1280, 720, 30, -1,10800, 3600, 108000, 100, 384*16368,  -1, 8000, PROFILE_ADAPTQUANT|PROFILE_BVOP|PROFILE_INTERLACE },
143    #endif
144    
145            { "(unrestricted)",     0x00,   0,   0,  0,  0, 0,      0,        0, 100,   0*16368,     0,     0, 0xffffffff },
146    };
147    
148    
149    /* ===================================================================================== */
150    /* REGISTRY ============================================================================ */
151    /* ===================================================================================== */
152    
153    /* registry info structs */
154    CONFIG reg;
155    
156    static const REG_INT reg_ints[] = {
157            {"mode",                                        &reg.mode,                                              RC_MODE_1PASS},
158            {"bitrate",                                     &reg.bitrate,                                   700},
159            {"desired_size",                        &reg.desired_size,                              570000},
160            {"use_2pass_bitrate",           &reg.use_2pass_bitrate,                 0},
161            {"desired_quant",                       &reg.desired_quant,                             DEFAULT_QUANT}, /* 100-base float */
162    
163            /* profile */
164            {"quant_type",                          &reg.quant_type,                                0},
165            {"lum_masking",                         &reg.lum_masking,                               0},
166            {"interlacing",                         &reg.interlacing,                               0},
167            {"qpel",                                        &reg.qpel,                                              0},
168            {"gmc",                                         &reg.gmc,                                               0},
169            {"reduced_resolution",          &reg.reduced_resolution,                0},
170            {"use_bvop",                            &reg.use_bvop,                                  1},
171            {"max_bframes",                         &reg.max_bframes,                               2},
172            {"bquant_ratio",                        &reg.bquant_ratio,                              150},   /* 100-base float */
173            {"bquant_offset",                       &reg.bquant_offset,                             100},   /* 100-base float */
174            {"packed",                                      &reg.packed,                                    1},
175            {"closed_gov",                          &reg.closed_gov,                                1},
176    
177            /* aspect ratio */
178            {"ar_mode",                                     &reg.ar_mode,                                   0},
179            {"aspect_ratio",                        &reg.display_aspect_ratio,              0},
180            {"par_x",                                       &reg.par_x,                                             1},
181            {"par_y",                                       &reg.par_y,                                             1},
182            {"ar_x",                                        &reg.ar_x,                                              4},
183            {"ar_y",                                        &reg.ar_y,                                              3},
184    
185            /* zones */
186            {"num_zones",                           &reg.num_zones,                                 1},
187    
188            /* single pass */
189            {"rc_reaction_delay_factor",&reg.rc_reaction_delay_factor,      16},
190            {"rc_averaging_period",         &reg.rc_averaging_period,               100},
191            {"rc_buffer",                           &reg.rc_buffer,                                 100},
192    
193            /* 2pass1 */
194            {"discard1pass",                        &reg.discard1pass,                              1},
195    
196            /* 2pass2 */
197            {"keyframe_boost",                      &reg.keyframe_boost,                    10},
198            {"kfreduction",                         &reg.kfreduction,                               20},
199            {"kfthreshold",                         &reg.kfthreshold,                               1},
200            {"curve_compression_high",      &reg.curve_compression_high,    0},
201            {"curve_compression_low",       &reg.curve_compression_low,             0},
202            {"overflow_control_strength", &reg.overflow_control_strength, 5},
203            {"twopass_max_overflow_improvement", &reg.twopass_max_overflow_improvement, 5},
204            {"twopass_max_overflow_degradation", &reg.twopass_max_overflow_degradation, 5},
205    
206            /* motion */
207            {"motion_search",                       &reg.motion_search,                             6},
208            {"vhq_mode",                            &reg.vhq_mode,                                  1},
209            {"chromame",                            &reg.chromame,                                  1},
210            {"cartoon_mode",                        &reg.cartoon_mode,                              0},
211            {"turbo",                                       &reg.turbo,                                             0},
212            {"max_key_interval",            &reg.max_key_interval,                  300},
213            {"frame_drop_ratio",            &reg.frame_drop_ratio,                  0},
214    
215            /* quant */
216            {"min_iquant",                          &reg.min_iquant,                                1},
217            {"max_iquant",                          &reg.max_iquant,                                31},
218            {"min_pquant",                          &reg.min_pquant,                                1},
219            {"max_pquant",                          &reg.max_pquant,                                31},
220            {"min_bquant",                          &reg.min_bquant,                                1},
221            {"max_bquant",                          &reg.max_bquant,                                31},
222            {"trellis_quant",                       &reg.trellis_quant,                             0},
223    
224            /* debug */
225            {"fourcc_used",                         &reg.fourcc_used,                               0},
226            {"debug",                                       &reg.debug,                                             0x0},
227            {"vop_debug",                           &reg.vop_debug,                                 0},
228            {"display_status",                      &reg.display_status,                    1},
229    
230            /* decoder, shared with dshow */
231            {"Deblock_Y",                           &pp_dy,                                                 0},
232            {"Deblock_UV",                          &pp_duv,                                                0},
233            {"Dering",                                      &pp_dr,                                                 0},
234            {"FilmEffect",                          &pp_fe,                                                 0},
235    
236    };
237    
238    static const REG_STR reg_strs[] = {
239            {"profile",                                     reg.profile_name,                               "AS @ L5"},
240            {"stats",                                       reg.stats,                                              CONFIG_2PASS_FILE},
241    };
242    
243    
244    zone_t stmp;
245    static const REG_INT reg_zone[] = {
246            {"zone%i_frame",                        &stmp.frame,                                    0},
247            {"zone%i_mode",                         &stmp.mode,                                             RC_ZONE_WEIGHT},
248            {"zone%i_weight",                       &stmp.weight,                                   100},     /* 100-base float */
249            {"zone%i_quant",                        &stmp.quant,                                    500},     /* 100-base float */
250            {"zone%i_type",                         &stmp.type,                                             XVID_TYPE_AUTO},
251            {"zone%i_greyscale",            &stmp.greyscale,                                0},
252            {"zone%i_chroma_opt",           &stmp.chroma_opt,                               0},
253            {"zone%i_bvop_threshold",   &stmp.bvop_threshold,                       0},
254    };
255    
256    static const BYTE default_qmatrix_intra[] = {
257            8, 17,18,19,21,23,25,27,
258            17,18,19,21,23,25,27,28,
259            20,21,22,23,24,26,28,30,
260            21,22,23,24,26,28,30,32,
261            22,23,24,26,28,30,32,35,
262            23,24,26,28,30,32,35,38,
263            25,26,28,30,32,35,38,41,
264            27,28,30,32,35,38,41,45
265    };
266    
267    static const BYTE default_qmatrix_inter[] = {
268            16,17,18,19,20,21,22,23,
269            17,18,19,20,21,22,23,24,
270            18,19,20,21,22,23,24,25,
271            19,20,21,22,23,24,26,27,
272            20,21,22,23,25,26,27,28,
273            21,22,23,24,26,27,28,30,
274            22,23,24,26,27,28,30,31,
275            23,24,25,27,28,30,31,33
276    };
277    
278    
279    
280    #define REG_GET_B(X, Y, Z) size=sizeof((Z));if(RegQueryValueEx(hKey, X, 0, 0, Y, &size) != ERROR_SUCCESS) {memcpy(Y, Z, sizeof((Z)));}
281    
282    #define XVID_DLL_NAME "xvidcore.dll"
283    
284    void config_reg_get(CONFIG * config)
285    {
286            char tmp[32];
287            HKEY hKey;
288            DWORD size;
289            int i,j;
290            xvid_gbl_info_t info;
291            HINSTANCE m_hdll;
292    
293            memset(&info, 0, sizeof(info));
294            info.version = XVID_VERSION;
295    
296            m_hdll = LoadLibrary(XVID_DLL_NAME);
297            if (m_hdll != NULL) {
298    
299                    ((int (__cdecl *)(void *, int, void *, void *))GetProcAddress(m_hdll, "xvid_global"))
300                            (0, XVID_GBL_INFO, &info, NULL);
301    
302                    FreeLibrary(m_hdll);
303            }
304    
305            reg.cpu = info.cpu_flags;
306            reg.num_threads = info.num_threads;
307    
308            RegOpenKeyEx(XVID_REG_KEY, XVID_REG_PARENT "\\" XVID_REG_CHILD, 0, KEY_READ, &hKey);
309    
310            /* read integer values */
311            for (i=0 ; i<sizeof(reg_ints)/sizeof(REG_INT); i++) {
312                    size = sizeof(int);
313                    if (RegQueryValueEx(hKey, reg_ints[i].reg_value, 0, 0, (LPBYTE)reg_ints[i].config_int, &size) != ERROR_SUCCESS) {
314                            *reg_ints[i].config_int = reg_ints[i].def;
315                    }
316            }
317    
318            /* read string values */
319            for (i=0 ; i<sizeof(reg_strs)/sizeof(REG_STR); i++) {
320                    size = MAX_PATH;
321                    if (RegQueryValueEx(hKey, reg_strs[i].reg_value, 0, 0, (LPBYTE)reg_strs[i].config_str, &size) != ERROR_SUCCESS) {
322                            memcpy(reg_strs[i].config_str, reg_strs[i].def, MAX_PATH);
323                    }
324            }
325    
326            reg.profile = 0;
327            for (i=0; i<sizeof(profiles)/sizeof(profile_t); i++) {
328                    if (strcmpi(profiles[i].name, reg.profile_name) == 0) {
329                            reg.profile = i;
330                    }
331            }
332    
333            memcpy(config, &reg, sizeof(CONFIG));
334    
335    
336            /* read quant matrices */
337            REG_GET_B("qmatrix_intra", config->qmatrix_intra, default_qmatrix_intra);
338            REG_GET_B("qmatrix_inter", config->qmatrix_inter, default_qmatrix_inter);
339    
340    
341            /* read zones */
342            if (config->num_zones>MAX_ZONES) {
343                    config->num_zones=MAX_ZONES;
344            }else if (config->num_zones<=0) {
345                    config->num_zones = 1;
346            }
347    
348            for (i=0; i<config->num_zones; i++) {
349                    for (j=0; j<sizeof(reg_zone)/sizeof(REG_INT); j++)  {
350                            size = sizeof(int);
351    
352                            wsprintf(tmp, reg_zone[j].reg_value, i);
353                            if (RegQueryValueEx(hKey, tmp, 0, 0, (LPBYTE)reg_zone[j].config_int, &size) != ERROR_SUCCESS)
354                                    *reg_zone[j].config_int = reg_zone[j].def;
355                    }
356    
357                    memcpy(&config->zones[i], &stmp, sizeof(zone_t));
358            }
359    
360            RegCloseKey(hKey);
361    }
362    
363    
364    /* put config settings in registry */
365    
366    #define REG_SET_B(X, Y) RegSetValueEx(hKey, X, 0, REG_BINARY, Y, sizeof((Y)))
367    
368    void config_reg_set(CONFIG * config)
369    {
370            char tmp[64];
371            HKEY hKey;
372            DWORD dispo;
373            int i,j;
374    
375            if (RegCreateKeyEx(
376                            XVID_REG_KEY,
377                            XVID_REG_PARENT "\\" XVID_REG_CHILD,
378                            0,
379                            XVID_REG_CLASS,
380                            REG_OPTION_NON_VOLATILE,
381                            KEY_WRITE,
382                            0,
383                            &hKey,
384                            &dispo) != ERROR_SUCCESS)
385            {
386                    DPRINTF("Couldn't create XVID_REG_SUBKEY - GetLastError=%i", GetLastError());
387                    return;
388            }
389    
390            memcpy(&reg, config, sizeof(CONFIG));
391    
392            /* set integer values */
393            for (i=0 ; i<sizeof(reg_ints)/sizeof(REG_INT); i++) {
394                    RegSetValueEx(hKey, reg_ints[i].reg_value, 0, REG_DWORD, (LPBYTE)reg_ints[i].config_int, sizeof(int));
395            }
396    
397            /* set string values */
398            strcpy(reg.profile_name, profiles[reg.profile].name);
399            for (i=0 ; i<sizeof(reg_strs)/sizeof(REG_STR); i++) {
400                    RegSetValueEx(hKey, reg_strs[i].reg_value, 0, REG_SZ, reg_strs[i].config_str, lstrlen(reg_strs[i].config_str)+1);
401            }
402    
403            /* set quant matrices */
404            REG_SET_B("qmatrix_intra", config->qmatrix_intra);
405            REG_SET_B("qmatrix_inter", config->qmatrix_inter);
406    
407            /* set seections */
408            for (i=0; i<config->num_zones; i++) {
409                    memcpy(&stmp, &config->zones[i], sizeof(zone_t));
410                    for (j=0; j<sizeof(reg_zone)/sizeof(REG_INT); j++)  {
411                            wsprintf(tmp, reg_zone[j].reg_value, i);
412                            RegSetValueEx(hKey, tmp, 0, REG_DWORD, (LPBYTE)reg_zone[j].config_int, sizeof(int));
413                    }
414            }
415    
416            RegCloseKey(hKey);
417    }
418    
419    
420    /* clear XviD registry key, load defaults */
421    
422    void config_reg_default(CONFIG * config)
423    {
424            HKEY hKey;
425    
426            if (RegOpenKeyEx(XVID_REG_KEY, XVID_REG_PARENT, 0, KEY_ALL_ACCESS, &hKey)) {
427                    DPRINTF("Couldn't open registry key for deletion - GetLastError=%i", GetLastError());
428                    return;
429            }
430    
431            if (RegDeleteKey(hKey, XVID_REG_CHILD)) {
432                    DPRINTF("Couldn't delete registry key - GetLastError=%i", GetLastError());
433                    return;
434            }
435    
436            RegCloseKey(hKey);
437            config_reg_get(config);
438            config_reg_set(config);
439    }
440    
441    
442    /* leaves current config value if dialog item is empty */
443    int config_get_int(HWND hDlg, INT item, int config)
444    {
445            BOOL success = FALSE;
446            int tmp = GetDlgItemInt(hDlg, item, &success, TRUE);
447            return (success) ? tmp : config;
448    }
449    
450    
451    int config_get_uint(HWND hDlg, UINT item, int config)
452    {
453            BOOL success = FALSE;
454            int tmp = GetDlgItemInt(hDlg, item, &success, FALSE);
455            return (success) ? tmp : config;
456    }
457    
458    
459    /* we use "100 base" floats */
460    
461    #define FLOAT_BUF_SZ    20
462    int get_dlgitem_float(HWND hDlg, UINT item, int def)
463    {
464            char buf[FLOAT_BUF_SZ];
465    
466            if (GetDlgItemText(hDlg, item, buf, FLOAT_BUF_SZ) == 0)
467                    return def;
468    
469            return (int)(atof(buf)*100);
470    }
471    
472    void set_dlgitem_float(HWND hDlg, UINT item, int value)
473    {
474            char buf[FLOAT_BUF_SZ];
475            sprintf(buf, "%.2f", (float)value/100);
476            SetDlgItemText(hDlg, item, buf);
477    }
478    
479    
480    #define HEX_BUF_SZ  16
481    unsigned int get_dlgitem_hex(HWND hDlg, UINT item, unsigned int def)
482    {
483            char buf[HEX_BUF_SZ];
484            unsigned int value;
485    
486            if (GetDlgItemText(hDlg, item, buf, HEX_BUF_SZ) == 0)
487                    return def;
488    
489            if (sscanf(buf,"0x%x", &value)==1 || sscanf(buf,"%x", &value)==1) {
490                    return value;
491            }
492    
493            return def;
494    }
495    
496    void set_dlgitem_hex(HWND hDlg, UINT item, int value)
497    {
498            char buf[HEX_BUF_SZ];
499            wsprintf(buf, "0x%x", value);
500            SetDlgItemText(hDlg, item, buf);
501    }
502    
503    /* ===================================================================================== */
504    /* QUANT MATRIX DIALOG ================================================================= */
505    /* ===================================================================================== */
506    
507    void quant_upload(HWND hDlg, CONFIG* config)
508    {
509            int i;
510    
511            for (i=0 ; i<64; i++) {
512                    SetDlgItemInt(hDlg, IDC_QINTRA00 + i, config->qmatrix_intra[i], FALSE);
513                    SetDlgItemInt(hDlg, IDC_QINTER00 + i, config->qmatrix_inter[i], FALSE);
514            }
515    }
516    
517    
518    void quant_download(HWND hDlg, CONFIG* config)
519    {
520            int i;
521    
522            for (i=0; i<64; i++) {
523                    int temp;
524    
525                    temp = config_get_uint(hDlg, i + IDC_QINTRA00, config->qmatrix_intra[i]);
526                    CONSTRAINVAL(temp, 1, 255);
527                    config->qmatrix_intra[i] = temp;
528    
529                    temp = config_get_uint(hDlg, i + IDC_QINTER00, config->qmatrix_inter[i]);
530                    CONSTRAINVAL(temp, 1, 255);
531                    config->qmatrix_inter[i] = temp;
532            }
533    }
534    
535    
536    void quant_loadsave(HWND hDlg, CONFIG * config, int save)
537    {
538            char file[MAX_PATH];
539            OPENFILENAME ofn;
540            HANDLE hFile;
541            DWORD read=128, wrote=0;
542            BYTE quant_data[128];
543    
544            strcpy(file, "\\matrix");
545            memset(&ofn, 0, sizeof(OPENFILENAME));
546            ofn.lStructSize = sizeof(OPENFILENAME);
547    
548            ofn.hwndOwner = hDlg;
549            ofn.lpstrFilter = "All files (*.*)\0*.*\0\0";
550            ofn.lpstrFile = file;
551            ofn.nMaxFile = MAX_PATH;
552            ofn.Flags = OFN_PATHMUSTEXIST;
553    
554            if (save) {
555                    ofn.Flags |= OFN_OVERWRITEPROMPT;
556                    if (GetSaveFileName(&ofn)) {
557                            hFile = CreateFile(file, GENERIC_WRITE, 0, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
558    
559                            quant_download(hDlg, config);
560                            memcpy(quant_data, config->qmatrix_intra, 64);
561                            memcpy(quant_data+64, config->qmatrix_inter, 64);
562    
563                            if (hFile == INVALID_HANDLE_VALUE) {
564                                    DPRINTF("Couldn't save quant matrix");
565                            }else{
566                                    if (!WriteFile(hFile, quant_data, 128, &wrote, 0)) {
567                                            DPRINTF("Couldnt write quant matrix");
568                                    }
569                            }
570                            CloseHandle(hFile);
571                    }
572            }else{
573                    ofn.Flags |= OFN_FILEMUSTEXIST;
574                    if (GetOpenFileName(&ofn)) {
575                            hFile = CreateFile(file, GENERIC_READ, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
576    
577                            if (hFile == INVALID_HANDLE_VALUE) {
578                                    DPRINTF("Couldn't load quant matrix");
579                            } else {
580                                    if (!ReadFile(hFile, quant_data, 128, &read, 0)) {
581                                            DPRINTF("Couldnt read quant matrix");
582                                    }else{
583                                            memcpy(config->qmatrix_intra, quant_data, 64);
584                                            memcpy(config->qmatrix_inter, quant_data+64, 64);
585                                            quant_upload(hDlg, config);
586                                    }
587                            }
588                            CloseHandle(hFile);
589                    }
590            }
591    }
592    
593    /* quantization matrix dialog proc */
594    
595    BOOL CALLBACK quantmatrix_proc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
596    {
597            CONFIG* config = (CONFIG*)GetWindowLong(hDlg, GWL_USERDATA);
598    
599            switch (uMsg)
600            {
601            case WM_INITDIALOG :
602                    SetWindowLong(hDlg, GWL_USERDATA, lParam);
603                    config = (CONFIG*)lParam;
604                    quant_upload(hDlg, config);
605    
606                    if (g_hTooltip)
607                    {
608                            EnumChildWindows(hDlg, enum_tooltips, 0);
609                    }
610                    break;
611    
612            case WM_COMMAND :
613    
614                    if (HIWORD(wParam) == BN_CLICKED) {
615                            switch(LOWORD(wParam)) {
616                            case IDOK :
617                                    quant_download(hDlg, config);
618                                    EndDialog(hDlg, IDOK);
619                                    break;
620    
621                            case IDCANCEL :
622                                    EndDialog(hDlg, IDCANCEL);
623                                    break;
624    
625                            case IDC_SAVE :
626                                    quant_loadsave(hDlg, config, 1);
627                                    break;
628    
629                            case IDC_LOAD :
630                                    quant_loadsave(hDlg, config, 0);
631                                    break;
632    
633                            default :
634                                    return FALSE;
635                            }
636                            break;
637                    }
638                    return FALSE;
639    
640            default :
641                    return FALSE;
642            }
643    
644            return TRUE;
645    }
646    
647    
648    /* ===================================================================================== */
649    /* ADVANCED DIALOG PAGES ================================================================ */
650    /* ===================================================================================== */
651    
652    /* initialise pages */
653    void adv_init(HWND hDlg, int idd, CONFIG * config)
654    {
655            unsigned int i;
656    
657            switch(idd) {
658            case IDD_PROFILE :
659                    for (i=0; i<sizeof(profiles)/sizeof(profile_t); i++)
660                            SendDlgItemMessage(hDlg, IDC_PROFILE_PROFILE, CB_ADDSTRING, 0, (LPARAM)profiles[i].name);
661                    SendDlgItemMessage(hDlg, IDC_QUANTTYPE, CB_ADDSTRING, 0, (LPARAM)"H.263");
662                    SendDlgItemMessage(hDlg, IDC_QUANTTYPE, CB_ADDSTRING, 0, (LPARAM)"MPEG");
663                    SendDlgItemMessage(hDlg, IDC_QUANTTYPE, CB_ADDSTRING, 0, (LPARAM)"MPEG-Custom");
664    
665                    break;
666            case IDD_AR:
667                    SendDlgItemMessage(hDlg, IDC_ASPECT_RATIO, CB_ADDSTRING, 0, (LPARAM)"Square (default)");
668                    SendDlgItemMessage(hDlg, IDC_ASPECT_RATIO, CB_ADDSTRING, 0, (LPARAM)"4:3 PAL");
669                    SendDlgItemMessage(hDlg, IDC_ASPECT_RATIO, CB_ADDSTRING, 0, (LPARAM)"4:3 NTSC");
670                    SendDlgItemMessage(hDlg, IDC_ASPECT_RATIO, CB_ADDSTRING, 0, (LPARAM)"16:9 PAL");
671                    SendDlgItemMessage(hDlg, IDC_ASPECT_RATIO, CB_ADDSTRING, 0, (LPARAM)"16:9 NTSC");
672                    SendDlgItemMessage(hDlg, IDC_ASPECT_RATIO, CB_ADDSTRING, 0, (LPARAM)"Custom...");
673                    break;
674    
675            case IDD_LEVEL :
676                    for (i=0; i<sizeof(profiles)/sizeof(profile_t); i++)
677                            SendDlgItemMessage(hDlg, IDC_LEVEL_PROFILE, CB_ADDSTRING, 0, (LPARAM)profiles[i].name);
678                    break;
679    
680            case IDD_ZONE :
681                    EnableDlgWindow(hDlg, IDC_ZONE_FETCH, config->ci_valid);
682                    break;
683    
684            case IDD_MOTION :
685                    SendDlgItemMessage(hDlg, IDC_MOTION, CB_ADDSTRING, 0, (LPARAM)"0 - None");
686                    SendDlgItemMessage(hDlg, IDC_MOTION, CB_ADDSTRING, 0, (LPARAM)"1 - Very Low");
687                    SendDlgItemMessage(hDlg, IDC_MOTION, CB_ADDSTRING, 0, (LPARAM)"2 - Low");
688                    SendDlgItemMessage(hDlg, IDC_MOTION, CB_ADDSTRING, 0, (LPARAM)"3 - Medium");
689                    SendDlgItemMessage(hDlg, IDC_MOTION, CB_ADDSTRING, 0, (LPARAM)"4 - High");
690                    SendDlgItemMessage(hDlg, IDC_MOTION, CB_ADDSTRING, 0, (LPARAM)"5 - Very High");
691                    SendDlgItemMessage(hDlg, IDC_MOTION, CB_ADDSTRING, 0, (LPARAM)"6 - Ultra High");
692    
693                    SendDlgItemMessage(hDlg, IDC_VHQ, CB_ADDSTRING, 0, (LPARAM)"0 - Off");
694                    SendDlgItemMessage(hDlg, IDC_VHQ, CB_ADDSTRING, 0, (LPARAM)"1 - Mode Decision");
695                    SendDlgItemMessage(hDlg, IDC_VHQ, CB_ADDSTRING, 0, (LPARAM)"2 - Limited Search");
696                    SendDlgItemMessage(hDlg, IDC_VHQ, CB_ADDSTRING, 0, (LPARAM)"3 - Medium Search");
697                    SendDlgItemMessage(hDlg, IDC_VHQ, CB_ADDSTRING, 0, (LPARAM)"4 - Wide Search");
698                    break;
699    
700            case IDD_DEBUG :
701                    /* force threads disabled */
702                    EnableWindow(GetDlgItem(hDlg, IDC_NUMTHREADS_STATIC), FALSE);
703                    EnableWindow(GetDlgItem(hDlg, IDC_NUMTHREADS), FALSE);
704    
705                    SendDlgItemMessage(hDlg, IDC_FOURCC, CB_ADDSTRING, 0, (LPARAM)"XVID");
706                    SendDlgItemMessage(hDlg, IDC_FOURCC, CB_ADDSTRING, 0, (LPARAM)"DIVX");
707                    SendDlgItemMessage(hDlg, IDC_FOURCC, CB_ADDSTRING, 0, (LPARAM)"DX50");
708                    break;
709            }
710    }
711    
712    
713    /* enable/disable controls based on encoder-mode or user selection */
714    
715    void adv_mode(HWND hDlg, int idd, CONFIG * config)
716    {
717            int profile;
718            int weight_en, quant_en;
719            int cpu_force;
720            int custom_quant, bvops;
721            int ar_mode, ar_par;
722    
723            switch(idd) {
724            case IDD_PROFILE :
725                    profile = SendDlgItemMessage(hDlg, IDC_PROFILE_PROFILE, CB_GETCURSEL, 0, 0);
726                    EnableDlgWindow(hDlg, IDC_BVOP, profiles[profile].flags&PROFILE_BVOP);
727    
728                    EnableDlgWindow(hDlg, IDC_QUANTTYPE_S, profiles[profile].flags&PROFILE_MPEGQUANT);
729                    EnableDlgWindow(hDlg, IDC_QUANTTYPE_S, profiles[profile].flags&PROFILE_MPEGQUANT);
730                    EnableDlgWindow(hDlg, IDC_QUANTTYPE, profiles[profile].flags&PROFILE_MPEGQUANT);
731                    custom_quant = (profiles[profile].flags&PROFILE_MPEGQUANT) && SendDlgItemMessage(hDlg, IDC_QUANTTYPE, CB_GETCURSEL, 0, 0)==QUANT_MODE_CUSTOM;
732                    EnableDlgWindow(hDlg, IDC_QUANTMATRIX, custom_quant);
733                    EnableDlgWindow(hDlg, IDC_LUMMASK, profiles[profile].flags&PROFILE_ADAPTQUANT);
734                    EnableDlgWindow(hDlg, IDC_INTERLACING, profiles[profile].flags&PROFILE_INTERLACE);
735                    EnableDlgWindow(hDlg, IDC_QPEL, profiles[profile].flags&PROFILE_QPEL);
736                    EnableDlgWindow(hDlg, IDC_GMC, profiles[profile].flags&PROFILE_GMC);
737                    EnableDlgWindow(hDlg, IDC_REDUCED, profiles[profile].flags&PROFILE_REDUCED);
738    
739                    bvops = (profiles[profile].flags&PROFILE_BVOP) && IsDlgChecked(hDlg, IDC_BVOP);
740                    EnableDlgWindow(hDlg, IDC_MAXBFRAMES,      bvops);
741                    EnableDlgWindow(hDlg, IDC_BQUANTRATIO,    bvops);
742                    EnableDlgWindow(hDlg, IDC_BQUANTOFFSET,  bvops);
743                    EnableDlgWindow(hDlg, IDC_MAXBFRAMES_S,  bvops);
744                    EnableDlgWindow(hDlg, IDC_BQUANTRATIO_S,        bvops);
745                    EnableDlgWindow(hDlg, IDC_BQUANTOFFSET_S,   bvops);
746                    EnableDlgWindow(hDlg, IDC_PACKED,                  bvops);
747                    EnableDlgWindow(hDlg, IDC_CLOSEDGOV,            bvops);
748                    break;
749    
750            case IDD_AR:
751                    ar_mode = IsDlgChecked(hDlg, IDC_PAR);
752                    EnableDlgWindow(hDlg, IDC_ASPECT_RATIO, ar_mode);
753    
754                    ar_par = SendDlgItemMessage(hDlg, IDC_ASPECT_RATIO, CB_GETCURSEL, 0, 0);
755                    if (ar_par == 5) { /* custom par */
756                            SetDlgItemInt(hDlg, IDC_PARY, config->par_y, FALSE);
757                            SetDlgItemInt(hDlg, IDC_PARX, config->par_x, FALSE);
758    
759                            EnableDlgWindow(hDlg, IDC_PARX, ar_mode);
760                            EnableDlgWindow(hDlg, IDC_PARY, ar_mode);
761                    } else {
762                            SetDlgItemInt(hDlg, IDC_PARX, PARS[ar_par][0], FALSE);
763                            SetDlgItemInt(hDlg, IDC_PARY, PARS[ar_par][1], FALSE);
764                            EnableDlgWindow(hDlg, IDC_PARX, FALSE);
765                            EnableDlgWindow(hDlg, IDC_PARY, FALSE);
766                    }
767    
768                    ar_mode = IsDlgChecked(hDlg, IDC_AR);
769    
770                    config->ar_x = config_get_uint(hDlg, IDC_ARX, config->ar_x);
771                    config->ar_y = config_get_uint(hDlg, IDC_ARY, config->ar_y);
772    
773                    EnableDlgWindow(hDlg, IDC_ARX, ar_mode);
774                    EnableDlgWindow(hDlg, IDC_ARY, ar_mode);
775                    break;
776    
777            case IDD_LEVEL :
778                    profile = SendDlgItemMessage(hDlg, IDC_LEVEL_PROFILE, CB_GETCURSEL, 0, 0);
779                    SetDlgItemInt(hDlg, IDC_LEVEL_WIDTH, profiles[profile].width, FALSE);
780                    SetDlgItemInt(hDlg, IDC_LEVEL_HEIGHT, profiles[profile].height, FALSE);
781                    SetDlgItemInt(hDlg, IDC_LEVEL_FPS, profiles[profile].fps, FALSE);
782                    SetDlgItemInt(hDlg, IDC_LEVEL_VMV, profiles[profile].max_vmv_buffer_sz, FALSE);
783                    SetDlgItemInt(hDlg, IDC_LEVEL_VCV, profiles[profile].vcv_decoder_rate, FALSE);
784                    SetDlgItemInt(hDlg, IDC_LEVEL_VBV, profiles[profile].max_vbv_size, FALSE);
785                    SetDlgItemInt(hDlg, IDC_LEVEL_BITRATE, profiles[profile].max_bitrate, FALSE);
786                    break;
787    
788            case IDD_ZONE :
789                    weight_en = IsDlgChecked(hDlg, IDC_ZONE_MODE_WEIGHT);
790                    quant_en =   IsDlgChecked(hDlg, IDC_ZONE_MODE_QUANT);
791                    EnableDlgWindow(hDlg, IDC_ZONE_WEIGHT, weight_en);
792                    EnableDlgWindow(hDlg, IDC_ZONE_QUANT, quant_en);
793                    EnableDlgWindow(hDlg, IDC_ZONE_SLIDER, weight_en|quant_en);
794    
795                    if (weight_en) {
796                            SendDlgItemMessage(hDlg, IDC_ZONE_SLIDER, TBM_SETRANGE, TRUE, MAKELONG(001,200));
797                            SendDlgItemMessage(hDlg, IDC_ZONE_SLIDER, TBM_SETPOS, TRUE, get_dlgitem_float(hDlg, IDC_ZONE_WEIGHT, 100));
798                            SetDlgItemText(hDlg, IDC_ZONE_MIN, "0.01");
799                            SetDlgItemText(hDlg, IDC_ZONE_MAX, "2.00");
800                    }else if (quant_en) {
801                            SendDlgItemMessage(hDlg, IDC_ZONE_SLIDER, TBM_SETRANGE, TRUE, MAKELONG(100,3100));
802                            SendDlgItemMessage(hDlg, IDC_ZONE_SLIDER, TBM_SETPOS, TRUE, get_dlgitem_float(hDlg, IDC_ZONE_QUANT, 100));
803                            SetDlgItemText(hDlg, IDC_ZONE_MIN, "1");
804                            SetDlgItemText(hDlg, IDC_ZONE_MAX, "31");
805                    }
806    
807                    bvops = (profiles[config->profile].flags&PROFILE_BVOP) && config->use_bvop;
808                    EnableDlgWindow(hDlg, IDC_ZONE_BVOPTHRESHOLD_S, bvops);
809                    EnableDlgWindow(hDlg, IDC_ZONE_BVOPTHRESHOLD, bvops);
810                    break;
811    
812            case IDD_DEBUG :
813                    cpu_force                       = IsDlgChecked(hDlg, IDC_CPU_FORCE);
814                    EnableDlgWindow(hDlg, IDC_CPU_MMX,              cpu_force);
815                    EnableDlgWindow(hDlg, IDC_CPU_MMXEXT,   cpu_force);
816                    EnableDlgWindow(hDlg, IDC_CPU_SSE,              cpu_force);
817                    EnableDlgWindow(hDlg, IDC_CPU_SSE2,             cpu_force);
818                    EnableDlgWindow(hDlg, IDC_CPU_3DNOW,    cpu_force);
819                    EnableDlgWindow(hDlg, IDC_CPU_3DNOWEXT, cpu_force);
820                    break;
821            }
822    }
823    
824    
825    /* upload config data into dialog */
826    void adv_upload(HWND hDlg, int idd, CONFIG * config)
827    {
828            switch (idd)
829            {
830            case IDD_PROFILE :
831                    SendDlgItemMessage(hDlg, IDC_PROFILE_PROFILE, CB_SETCURSEL, config->profile, 0);
832    
833                    SendDlgItemMessage(hDlg, IDC_QUANTTYPE, CB_SETCURSEL, config->quant_type, 0);
834                    CheckDlg(hDlg, IDC_LUMMASK, config->lum_masking);
835                    CheckDlg(hDlg, IDC_INTERLACING, config->interlacing);
836                    CheckDlg(hDlg, IDC_QPEL, config->qpel);
837                    CheckDlg(hDlg, IDC_GMC, config->gmc);
838                    CheckDlg(hDlg, IDC_REDUCED, config->reduced_resolution);
839                    CheckDlg(hDlg, IDC_BVOP, config->use_bvop);
840    
841                    SetDlgItemInt(hDlg, IDC_MAXBFRAMES, config->max_bframes, FALSE);
842                    set_dlgitem_float(hDlg, IDC_BQUANTRATIO, config->bquant_ratio);
843                    set_dlgitem_float(hDlg, IDC_BQUANTOFFSET, config->bquant_offset);
844                    CheckDlg(hDlg, IDC_PACKED, config->packed);
845                    CheckDlg(hDlg, IDC_CLOSEDGOV, config->closed_gov);
846    
847                    break;
848            case IDD_AR:
849                    CheckRadioButton(hDlg, IDC_AR, IDC_PAR, config->ar_mode == 0 ? IDC_PAR : IDC_AR);
850                    SendDlgItemMessage(hDlg, IDC_ASPECT_RATIO, CB_SETCURSEL, (config->display_aspect_ratio), 0);
851                    SetDlgItemInt(hDlg, IDC_ARX, config->ar_x, FALSE);
852                    SetDlgItemInt(hDlg, IDC_ARY, config->ar_y, FALSE);
853                    break;
854    
855            case IDD_LEVEL :
856                    SendDlgItemMessage(hDlg, IDC_LEVEL_PROFILE, CB_SETCURSEL, config->profile, 0);
857                    break;
858    
859            case IDD_RC_CBR :
860                    SetDlgItemInt(hDlg, IDC_CBR_REACTIONDELAY, config->rc_reaction_delay_factor, FALSE);
861                    SetDlgItemInt(hDlg, IDC_CBR_AVERAGINGPERIOD, config->rc_averaging_period, FALSE);
862                    SetDlgItemInt(hDlg, IDC_CBR_BUFFER, config->rc_buffer, FALSE);
863                    break;
864    
865            case IDD_RC_2PASS1 :
866                    SetDlgItemText(hDlg, IDC_STATS, config->stats);
867                    CheckDlg(hDlg, IDC_DISCARD1PASS, config->discard1pass);
868                    break;
869    
870            case IDD_RC_2PASS2 :
871                    SetDlgItemText(hDlg, IDC_STATS, config->stats);
872                    SetDlgItemInt(hDlg, IDC_KFBOOST, config->keyframe_boost, FALSE);
873                    SetDlgItemInt(hDlg, IDC_KFREDUCTION, config->kfreduction, FALSE);
874    
875                    SetDlgItemInt(hDlg, IDC_OVERFLOW_CONTROL_STRENGTH, config->overflow_control_strength, FALSE);
876                    SetDlgItemInt(hDlg, IDC_OVERIMP, config->twopass_max_overflow_improvement, FALSE);
877                    SetDlgItemInt(hDlg, IDC_OVERDEG, config->twopass_max_overflow_degradation, FALSE);
878    
879                    SetDlgItemInt(hDlg, IDC_CURVECOMPH, config->curve_compression_high, FALSE);
880                    SetDlgItemInt(hDlg, IDC_CURVECOMPL, config->curve_compression_low, FALSE);
881                    SetDlgItemInt(hDlg, IDC_MINKEY, config->kfthreshold, FALSE);
882                    break;
883    
884            case IDD_ZONE :
885                    SetDlgItemInt(hDlg, IDC_ZONE_FRAME, config->zones[config->cur_zone].frame, FALSE);
886    
887                    CheckDlgButton(hDlg, IDC_ZONE_MODE_WEIGHT,   config->zones[config->cur_zone].mode == RC_ZONE_WEIGHT);
888                    CheckDlgButton(hDlg, IDC_ZONE_MODE_QUANT,                config->zones[config->cur_zone].mode == RC_ZONE_QUANT);
889    
890                    set_dlgitem_float(hDlg, IDC_ZONE_WEIGHT, config->zones[config->cur_zone].weight);
891                    set_dlgitem_float(hDlg, IDC_ZONE_QUANT, config->zones[config->cur_zone].quant);
892    
893                    CheckDlgButton(hDlg, IDC_ZONE_FORCEIVOP, config->zones[config->cur_zone].type==XVID_TYPE_IVOP);
894                    CheckDlgButton(hDlg, IDC_ZONE_GREYSCALE, config->zones[config->cur_zone].greyscale);
895                    CheckDlgButton(hDlg, IDC_ZONE_CHROMAOPT, config->zones[config->cur_zone].chroma_opt);
896    
897                    SetDlgItemInt(hDlg, IDC_ZONE_BVOPTHRESHOLD, config->zones[config->cur_zone].bvop_threshold, TRUE);
898                    break;
899    
900            case IDD_MOTION :
901                    SendDlgItemMessage(hDlg, IDC_MOTION, CB_SETCURSEL, config->motion_search, 0);
902                    SendDlgItemMessage(hDlg, IDC_VHQ, CB_SETCURSEL, config->vhq_mode, 0);
903                    CheckDlg(hDlg, IDC_CHROMAME, config->chromame);
904                    CheckDlg(hDlg, IDC_CARTOON, config->cartoon_mode);
905                    CheckDlg(hDlg, IDC_TURBO, config->turbo);
906                    SetDlgItemInt(hDlg, IDC_FRAMEDROP, config->frame_drop_ratio, FALSE);
907                    SetDlgItemInt(hDlg, IDC_MAXKEY, config->max_key_interval, FALSE);
908                    break;
909    
910            case IDD_QUANT :
911                    SetDlgItemInt(hDlg, IDC_MINIQUANT, config->min_iquant, FALSE);
912                    SetDlgItemInt(hDlg, IDC_MAXIQUANT, config->max_iquant, FALSE);
913                    SetDlgItemInt(hDlg, IDC_MINPQUANT, config->min_pquant, FALSE);
914                    SetDlgItemInt(hDlg, IDC_MAXPQUANT, config->max_pquant, FALSE);
915                    SetDlgItemInt(hDlg, IDC_MINBQUANT, config->min_bquant, FALSE);
916                    SetDlgItemInt(hDlg, IDC_MAXBQUANT, config->max_bquant, FALSE);
917                    CheckDlg(hDlg, IDC_TRELLISQUANT, config->trellis_quant);
918                    break;
919    
920            case IDD_DEBUG :
921                    CheckDlg(hDlg, IDC_CPU_MMX, (config->cpu & XVID_CPU_MMX));
922                    CheckDlg(hDlg, IDC_CPU_MMXEXT, (config->cpu & XVID_CPU_MMXEXT));
923                    CheckDlg(hDlg, IDC_CPU_SSE, (config->cpu & XVID_CPU_SSE));
924                    CheckDlg(hDlg, IDC_CPU_SSE2, (config->cpu & XVID_CPU_SSE2));
925                    CheckDlg(hDlg, IDC_CPU_3DNOW, (config->cpu & XVID_CPU_3DNOW));
926                    CheckDlg(hDlg, IDC_CPU_3DNOWEXT, (config->cpu & XVID_CPU_3DNOWEXT));
927    
928                    CheckRadioButton(hDlg, IDC_CPU_AUTO, IDC_CPU_FORCE,
929                            config->cpu & XVID_CPU_FORCE ? IDC_CPU_FORCE : IDC_CPU_AUTO );
930    
931                    SetDlgItemInt(hDlg, IDC_NUMTHREADS, config->num_threads, FALSE);
932    
933                    SendDlgItemMessage(hDlg, IDC_FOURCC, CB_SETCURSEL, config->fourcc_used, 0);
934                    set_dlgitem_hex(hDlg, IDC_DEBUG, config->debug);
935                    CheckDlg(hDlg, IDC_VOPDEBUG, config->vop_debug);
936                    CheckDlg(hDlg, IDC_DISPLAY_STATUS, config->display_status);
937                    break;
938    
939            case IDD_DEC :
940                    CheckDlg(hDlg, IDC_DEC_DY,      pp_dy);
941                    CheckDlg(hDlg, IDC_DEC_DUV,     pp_duv);
942                    CheckDlg(hDlg, IDC_DEC_DR,      pp_dr);
943                    CheckDlg(hDlg, IDC_DEC_FE,      pp_fe);
944                    break;
945            }
946    }
947    
948    
949    /* download config data from dialog */
950    
951    void adv_download(HWND hDlg, int idd, CONFIG * config)
952    {
953            switch (idd)
954            {
955            case IDD_PROFILE :
956                    config->profile = SendDlgItemMessage(hDlg, IDC_PROFILE_PROFILE, CB_GETCURSEL, 0, 0);
957    
958                    config->quant_type = SendDlgItemMessage(hDlg, IDC_QUANTTYPE, CB_GETCURSEL, 0, 0);
959                    config->lum_masking = IsDlgChecked(hDlg, IDC_LUMMASK);
960                    config->interlacing = IsDlgChecked(hDlg, IDC_INTERLACING);
961                    config->qpel = IsDlgChecked(hDlg, IDC_QPEL);
962                    config->gmc = IsDlgChecked(hDlg, IDC_GMC);
963                    config->reduced_resolution = IsDlgChecked(hDlg, IDC_REDUCED);
964    
965                    config->use_bvop = IsDlgChecked(hDlg, IDC_BVOP);
966                    config->max_bframes = config_get_uint(hDlg, IDC_MAXBFRAMES, config->max_bframes);
967                    config->bquant_ratio = get_dlgitem_float(hDlg, IDC_BQUANTRATIO, config->bquant_ratio);
968                    config->bquant_offset = get_dlgitem_float(hDlg, IDC_BQUANTOFFSET, config->bquant_offset);
969                    config->packed = IsDlgChecked(hDlg, IDC_PACKED);
970                    config->closed_gov = IsDlgChecked(hDlg, IDC_CLOSEDGOV);
971                    break;
972    
973            case IDD_AR:
974                    config->ar_mode = IsDlgChecked(hDlg, IDC_PAR) ? 0:1;
975                    config->ar_x = config_get_uint(hDlg, IDC_ARX, config->ar_x);
976                    config->ar_y = config_get_uint(hDlg, IDC_ARY, config->ar_y);
977                    config->display_aspect_ratio = SendDlgItemMessage(hDlg, IDC_ASPECT_RATIO, CB_GETCURSEL, 0, 0);
978                    if (config->display_aspect_ratio == 5) {
979                            config->par_x = config_get_uint(hDlg, IDC_PARX, config->par_x);
980                            config->par_y = config_get_uint(hDlg, IDC_PARY, config->par_y);
981                    }
982                    break;
983    
984            case IDD_LEVEL :
985                    config->profile = SendDlgItemMessage(hDlg, IDC_LEVEL_PROFILE, CB_GETCURSEL, 0, 0);
986                    break;
987    
988            case IDD_RC_CBR :
989                    config->rc_reaction_delay_factor = config_get_uint(hDlg, IDC_CBR_REACTIONDELAY, config->rc_reaction_delay_factor);
990                    config->rc_averaging_period = config_get_uint(hDlg, IDC_CBR_AVERAGINGPERIOD, config->rc_averaging_period);
991                    config->rc_buffer = config_get_uint(hDlg, IDC_CBR_BUFFER, config->rc_buffer);
992                    break;
993    
994            case IDD_RC_2PASS1 :
995                    if (GetDlgItemText(hDlg, IDC_STATS, config->stats, MAX_PATH) == 0)
996                            lstrcpy(config->stats, CONFIG_2PASS_FILE);
997                    config->discard1pass = IsDlgChecked(hDlg, IDC_DISCARD1PASS);
998                    break;
999    
1000            case IDD_RC_2PASS2 :
1001                    if (GetDlgItemText(hDlg, IDC_STATS, config->stats, MAX_PATH) == 0)
1002                            lstrcpy(config->stats, CONFIG_2PASS_FILE);
1003    
1004                    config->keyframe_boost = GetDlgItemInt(hDlg, IDC_KFBOOST, NULL, FALSE);
1005                    config->kfreduction = GetDlgItemInt(hDlg, IDC_KFREDUCTION, NULL, FALSE);
1006                    CONSTRAINVAL(config->keyframe_boost, 0, 1000);
1007    
1008                    config->overflow_control_strength = GetDlgItemInt(hDlg, IDC_OVERFLOW_CONTROL_STRENGTH, NULL, FALSE);
1009                    config->twopass_max_overflow_improvement = config_get_uint(hDlg, IDC_OVERIMP, config->twopass_max_overflow_improvement);
1010                    config->twopass_max_overflow_degradation = config_get_uint(hDlg, IDC_OVERDEG, config->twopass_max_overflow_degradation);
1011                    CONSTRAINVAL(config->twopass_max_overflow_improvement, 1, 80);
1012                    CONSTRAINVAL(config->twopass_max_overflow_degradation, 1, 80);
1013                    CONSTRAINVAL(config->overflow_control_strength, 0, 100);
1014    
1015                    config->curve_compression_high = GetDlgItemInt(hDlg, IDC_CURVECOMPH, NULL, FALSE);
1016                    config->curve_compression_low = GetDlgItemInt(hDlg, IDC_CURVECOMPL, NULL, FALSE);
1017                    CONSTRAINVAL(config->curve_compression_high, 0, 100);
1018                    CONSTRAINVAL(config->curve_compression_low, 0, 100);
1019    
1020                    config->kfthreshold = config_get_uint(hDlg, IDC_MINKEY, config->kfthreshold);
1021    
1022                    break;
1023    
1024            case IDD_ZONE :
1025                    config->zones[config->cur_zone].frame = config_get_uint(hDlg, IDC_ZONE_FRAME, config->zones[config->cur_zone].frame);
1026    
1027                    if (IsDlgChecked(hDlg, IDC_ZONE_MODE_WEIGHT)) {
1028                            config->zones[config->cur_zone].mode = RC_ZONE_WEIGHT;
1029                    }else if (IsDlgChecked(hDlg, IDC_ZONE_MODE_QUANT)) {
1030                            config->zones[config->cur_zone].mode = RC_ZONE_QUANT;
1031                    }
1032    
1033                    config->zones[config->cur_zone].weight = get_dlgitem_float(hDlg, IDC_ZONE_WEIGHT, config->zones[config->cur_zone].weight);
1034                    config->zones[config->cur_zone].quant =  get_dlgitem_float(hDlg, IDC_ZONE_QUANT, config->zones[config->cur_zone].quant);
1035    
1036                    config->zones[config->cur_zone].type = IsDlgButtonChecked(hDlg, IDC_ZONE_FORCEIVOP)?XVID_TYPE_IVOP:XVID_TYPE_AUTO;
1037                    config->zones[config->cur_zone].greyscale = IsDlgButtonChecked(hDlg, IDC_ZONE_GREYSCALE);
1038                    config->zones[config->cur_zone].chroma_opt = IsDlgButtonChecked(hDlg, IDC_ZONE_CHROMAOPT);
1039    
1040                    config->zones[config->cur_zone].bvop_threshold = config_get_int(hDlg, IDC_ZONE_BVOPTHRESHOLD, config->zones[config->cur_zone].bvop_threshold);
1041                    break;
1042    
1043            case IDD_MOTION :
1044                    config->motion_search = SendDlgItemMessage(hDlg, IDC_MOTION, CB_GETCURSEL, 0, 0);
1045                    config->vhq_mode = SendDlgItemMessage(hDlg, IDC_VHQ, CB_GETCURSEL, 0, 0);
1046                    config->chromame = IsDlgChecked(hDlg, IDC_CHROMAME);
1047                    config->cartoon_mode = IsDlgChecked(hDlg, IDC_CARTOON);
1048                    config->turbo = IsDlgChecked(hDlg, IDC_TURBO);
1049    
1050                    config->frame_drop_ratio = config_get_uint(hDlg, IDC_FRAMEDROP, config->frame_drop_ratio);
1051    
1052                    config->max_key_interval = config_get_uint(hDlg, IDC_MAXKEY, config->max_key_interval);
1053                    break;
1054    
1055            case IDD_QUANT :
1056                    config->min_iquant = config_get_uint(hDlg, IDC_MINIQUANT, config->min_iquant);
1057                    config->max_iquant = config_get_uint(hDlg, IDC_MAXIQUANT, config->max_iquant);
1058                    config->min_pquant = config_get_uint(hDlg, IDC_MINPQUANT, config->min_pquant);
1059                    config->max_pquant = config_get_uint(hDlg, IDC_MAXPQUANT, config->max_pquant);
1060                    config->min_bquant = config_get_uint(hDlg, IDC_MINBQUANT, config->min_bquant);
1061                    config->max_bquant = config_get_uint(hDlg, IDC_MAXBQUANT, config->max_bquant);
1062    
1063                    CONSTRAINVAL(config->min_iquant, 1, 31);
1064                    CONSTRAINVAL(config->max_iquant, config->min_iquant, 31);
1065                    CONSTRAINVAL(config->min_pquant, 1, 31);
1066                    CONSTRAINVAL(config->max_pquant, config->min_pquant, 31);
1067                    CONSTRAINVAL(config->min_bquant, 1, 31);
1068                    CONSTRAINVAL(config->max_bquant, config->min_bquant, 31);
1069    
1070                    config->trellis_quant = IsDlgChecked(hDlg, IDC_TRELLISQUANT);
1071                    break;
1072    
1073            case IDD_DEBUG :
1074                    config->cpu = 0;
1075                    config->cpu |= IsDlgChecked(hDlg, IDC_CPU_MMX)    ? XVID_CPU_MMX : 0;
1076                    config->cpu |= IsDlgChecked(hDlg, IDC_CPU_MMXEXT)   ? XVID_CPU_MMXEXT : 0;
1077                    config->cpu |= IsDlgChecked(hDlg, IDC_CPU_SSE)    ? XVID_CPU_SSE : 0;
1078                    config->cpu |= IsDlgChecked(hDlg, IDC_CPU_SSE2)  ? XVID_CPU_SSE2 : 0;
1079                    config->cpu |= IsDlgChecked(hDlg, IDC_CPU_3DNOW)        ? XVID_CPU_3DNOW : 0;
1080                    config->cpu |= IsDlgChecked(hDlg, IDC_CPU_3DNOWEXT) ? XVID_CPU_3DNOWEXT : 0;
1081                    config->cpu |= IsDlgChecked(hDlg, IDC_CPU_FORCE)        ? XVID_CPU_FORCE : 0;
1082    
1083                    config->num_threads = config_get_uint(hDlg, IDC_NUMTHREADS, config->num_threads);
1084    
1085                    config->fourcc_used = SendDlgItemMessage(hDlg, IDC_FOURCC, CB_GETCURSEL, 0, 0);
1086                    config->debug = get_dlgitem_hex(hDlg, IDC_DEBUG, config->debug);
1087                    config->vop_debug = IsDlgChecked(hDlg, IDC_VOPDEBUG);
1088                    config->display_status = IsDlgChecked(hDlg, IDC_DISPLAY_STATUS);
1089                    break;
1090    
1091            case IDD_DEC :
1092                    pp_dy = IsDlgChecked(hDlg, IDC_DEC_DY);
1093                    pp_duv = IsDlgChecked(hDlg, IDC_DEC_DUV);
1094                    pp_dr = IsDlgChecked(hDlg, IDC_DEC_DR);
1095                    pp_fe = IsDlgChecked(hDlg, IDC_DEC_FE);
1096                    break;
1097            }
1098    }
1099    
1100    
1101    
1102    /* advanced dialog proc */
1103    
1104    BOOL CALLBACK adv_proc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
1105    {
1106            PROPSHEETINFO *psi;
1107    
1108            psi = (PROPSHEETINFO*)GetWindowLong(hDlg, GWL_USERDATA);
1109    
1110            switch (uMsg)
1111            {
1112            case WM_INITDIALOG :
1113                    psi = (PROPSHEETINFO*) ((LPPROPSHEETPAGE)lParam)->lParam;
1114                    SetWindowLong(hDlg, GWL_USERDATA, (LPARAM)psi);
1115    
1116                    if (g_hTooltip)
1117                            EnumChildWindows(hDlg, enum_tooltips, 0);
1118    
1119                    adv_init(hDlg, psi->idd, psi->config);
1120                    break;
1121    
1122            case WM_COMMAND :
1123                    if (HIWORD(wParam) == BN_CLICKED)
1124                    {
1125                            switch (LOWORD(wParam))
1126                            {
1127                            case IDC_BVOP :
1128                            case IDC_ZONE_MODE_WEIGHT :
1129                            case IDC_ZONE_MODE_QUANT :
1130                            case IDC_ZONE_BVOPTHRESHOLD_ENABLE :
1131                            case IDC_CPU_AUTO :
1132                            case IDC_CPU_FORCE :
1133                            case IDC_AR :
1134                            case IDC_PAR :
1135                                    adv_mode(hDlg, psi->idd, psi->config);
1136                                    break;
1137    
1138                            case IDC_QUANTMATRIX :
1139                                    DialogBoxParam(g_hInst, MAKEINTRESOURCE(IDD_QUANTMATRIX), hDlg, quantmatrix_proc, (LPARAM)psi->config);
1140                                    break;
1141    
1142                            case IDC_STATS_BROWSE :
1143                            {
1144                                    OPENFILENAME ofn;
1145                                    char tmp[MAX_PATH];
1146    
1147                                    GetDlgItemText(hDlg, IDC_STATS, tmp, MAX_PATH);
1148    
1149                                    memset(&ofn, 0, sizeof(OPENFILENAME));
1150                                    ofn.lStructSize = sizeof(OPENFILENAME);
1151    
1152                                    ofn.hwndOwner = hDlg;
1153                                    ofn.lpstrFilter = "bitrate curve (*.pass)\0*.pass\0All files (*.*)\0*.*\0\0";
1154                                    ofn.lpstrFile = tmp;
1155                                    ofn.nMaxFile = MAX_PATH;
1156                                    ofn.Flags = OFN_PATHMUSTEXIST;
1157    
1158                                    if (psi->idd == IDD_RC_2PASS1) {
1159                                            ofn.Flags |= OFN_OVERWRITEPROMPT;
1160                                    }else{
1161                                            ofn.Flags |= OFN_FILEMUSTEXIST;
1162                                    }
1163    
1164                                    if (GetSaveFileName(&ofn))
1165                                    {
1166                                            SetDlgItemText(hDlg, IDC_STATS, tmp);
1167                                    }
1168                            }
1169    
1170                            case IDC_ZONE_FETCH :
1171                                    SetDlgItemInt(hDlg, IDC_ZONE_FRAME, psi->config->ci.ciActiveFrame, FALSE);
1172                                    break;
1173    
1174                            case IDC_AR_DEFAULT:
1175                                    CheckRadioButton(hDlg, IDC_AR, IDC_PAR, IDC_PAR);
1176                                    SendDlgItemMessage(hDlg, IDC_ASPECT_RATIO, CB_SETCURSEL, 0, 0);
1177                                    adv_mode(hDlg, psi->idd, psi->config);
1178                                    break;
1179                            case IDC_AR_4_3:
1180                                    SetDlgItemInt(hDlg, IDC_ARX, 4, FALSE);
1181                                    SetDlgItemInt(hDlg, IDC_ARY, 3, FALSE);
1182                                    CheckRadioButton(hDlg, IDC_AR, IDC_PAR, IDC_AR);
1183                                    adv_mode(hDlg, psi->idd, psi->config);
1184                                    break;
1185                            case IDC_AR_16_9:
1186                                    SetDlgItemInt(hDlg, IDC_ARX, 16, FALSE);
1187                                    SetDlgItemInt(hDlg, IDC_ARY, 9, FALSE);
1188                                    CheckRadioButton(hDlg, IDC_AR, IDC_PAR, IDC_AR);
1189                                    adv_mode(hDlg, psi->idd, psi->config);
1190                                    break;
1191                            case IDC_AR_235_100:
1192                                    SetDlgItemInt(hDlg, IDC_ARX, 235, FALSE);
1193                                    SetDlgItemInt(hDlg, IDC_ARY, 100, FALSE);
1194                                    CheckRadioButton(hDlg, IDC_AR, IDC_PAR, IDC_AR);
1195                                    adv_mode(hDlg, psi->idd, psi->config);
1196                                    break;
1197    
1198                            default :
1199                                    return TRUE;
1200                            }
1201                    }else if (HIWORD(wParam) == LBN_SELCHANGE &&
1202                            (LOWORD(wParam) == IDC_PROFILE_PROFILE ||
1203                             LOWORD(wParam) == IDC_LEVEL_PROFILE ||
1204                             LOWORD(wParam) == IDC_QUANTTYPE ||
1205                             LOWORD(wParam) == IDC_ASPECT_RATIO))
1206                    {
1207                            adv_mode(hDlg, psi->idd, psi->config);
1208                    }else if (HIWORD(wParam) == EN_UPDATE && (LOWORD(wParam)==IDC_ZONE_WEIGHT || LOWORD(wParam)==IDC_ZONE_QUANT)) {
1209    
1210                            SendDlgItemMessage(hDlg, IDC_ZONE_SLIDER, TBM_SETPOS, TRUE,
1211                                            get_dlgitem_float(hDlg, LOWORD(wParam), 100));
1212                    } else if (HIWORD(wParam) == EN_UPDATE && (LOWORD(wParam)==IDC_PARX || LOWORD(wParam)==IDC_PARY)) {
1213                            if (5 == SendDlgItemMessage(hDlg, IDC_ASPECT_RATIO, CB_GETCURSEL, 0, 0)) {
1214                                    if(LOWORD(wParam)==IDC_PARX)
1215                                            psi->config->par_x = config_get_uint(hDlg, LOWORD(wParam), psi->config->par_x);
1216                                    else
1217                                            psi->config->par_y = config_get_uint(hDlg, LOWORD(wParam), psi->config->par_y);
1218                            }
1219                    } else
1220                            return 0;
1221                    break;
1222    
1223            case WM_HSCROLL :
1224                    if((HWND)lParam == GetDlgItem(hDlg, IDC_ZONE_SLIDER)) {
1225                            int idc = IsDlgChecked(hDlg, IDC_ZONE_MODE_WEIGHT) ? IDC_ZONE_WEIGHT : IDC_ZONE_QUANT;
1226                            set_dlgitem_float(hDlg, idc, SendMessage((HWND)lParam, TBM_GETPOS, 0, 0) );
1227                            break;
1228                    }
1229                    return 0;
1230    
1231    
1232            case WM_NOTIFY :
1233                    switch (((NMHDR *)lParam)->code)
1234                    {
1235                    case PSN_SETACTIVE :
1236                            OutputDebugString("PSN_SET");
1237                            adv_upload(hDlg, psi->idd, psi->config);
1238                            adv_mode(hDlg, psi->idd, psi->config);
1239                            SetWindowLong(hDlg, DWL_MSGRESULT, FALSE);
1240                            break;
1241    
1242                    case PSN_KILLACTIVE :
1243                            OutputDebugString("PSN_KILL");
1244                            adv_download(hDlg, psi->idd, psi->config);
1245                            SetWindowLong(hDlg, DWL_MSGRESULT, FALSE);
1246                            break;
1247    
1248                    case PSN_APPLY :
1249                            OutputDebugString("PSN_APPLY");
1250                            psi->config->save = TRUE;
1251                            SetWindowLong(hDlg, DWL_MSGRESULT, FALSE);
1252                            break;
1253                    }
1254                    break;
1255    
1256            default :
1257                    return 0;
1258            }
1259    
1260            return 1;
1261    }
1262    
1263    
1264    
1265    
1266    /* load advanced options property sheet
1267      returns true, if the user accepted the changes
1268      or fasle if changes were canceled.
1269    
1270      */
1271    BOOL adv_dialog(HWND hParent, CONFIG * config, const int * dlgs, int size)
1272    {
1273            PROPSHEETINFO psi[6];
1274            PROPSHEETPAGE psp[6];
1275            PROPSHEETHEADER psh;
1276            CONFIG temp;
1277            int i;
1278    
1279            config->save = FALSE;
1280            memcpy(&temp, config, sizeof(CONFIG));
1281    
1282            for (i=0; i<size; i++)
1283            {
1284                    psp[i].dwSize = sizeof(PROPSHEETPAGE);
1285                    psp[i].dwFlags = 0;
1286                    psp[i].hInstance = g_hInst;
1287                    psp[i].pfnDlgProc = adv_proc;
1288                    psp[i].lParam = (LPARAM)&psi[i];
1289                    psp[i].pfnCallback = NULL;
1290                    psp[i].pszTemplate = MAKEINTRESOURCE(dlgs[i]);
1291    
1292                    psi[i].idd = dlgs[i];
1293                    psi[i].config = &temp;
1294            }
1295    
1296            psh.dwSize = sizeof(PROPSHEETHEADER);
1297            psh.dwFlags = PSH_PROPSHEETPAGE | PSH_NOAPPLYNOW;
1298            psh.hwndParent = hParent;
1299            psh.hInstance = g_hInst;
1300            psh.pszCaption = (LPSTR) "XviD Configuration";
1301            psh.nPages = size;
1302            psh.nStartPage = 0;
1303            psh.ppsp = (LPCPROPSHEETPAGE)&psp;
1304            psh.pfnCallback = NULL;
1305            PropertySheet(&psh);
1306    
1307            if (temp.save)
1308                    memcpy(config, &temp, sizeof(CONFIG));
1309    
1310            return temp.save;
1311    }
1312    
1313    /* ===================================================================================== */
1314    /* MAIN DIALOG ========================================================================= */
1315    /* ===================================================================================== */
1316    
1317    
1318    void main_insert_zone(HWND hDlg, zone_t * s, int i, BOOL insert)
1319    {
1320            char tmp[32];
1321    
1322            wsprintf(tmp,"%i",s->frame);
1323    
1324            if (insert) {
1325                    LVITEM lvi;
1326    
1327                    lvi.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_PARAM | LVIF_STATE;
1328                    lvi.state = 0;
1329                    lvi.stateMask = 0;
1330                    lvi.iImage = 0;
1331                    lvi.pszText = tmp;
1332                    lvi.cchTextMax = strlen(tmp);
1333                    lvi.iItem = i;
1334                    lvi.iSubItem = 0;
1335                    ListView_InsertItem(hDlg, &lvi);
1336            }else{
1337                    ListView_SetItemText(hDlg, i, 0, tmp);
1338            }
1339    
1340            if (s->mode == RC_ZONE_WEIGHT) {
1341                    sprintf(tmp,"W %.2f",(float)s->weight/100);
1342            }else if (s->mode == RC_ZONE_QUANT) {
1343                    sprintf(tmp,"Q %.2f",(float)s->quant/100);
1344            }else {
1345                    strcpy(tmp,"EXT");
1346            }
1347            ListView_SetItemText(hDlg, i, 1, tmp);
1348    
1349            tmp[0] = '\0';
1350            if (s->type==XVID_TYPE_IVOP)
1351                    strcat(tmp, "K ");
1352    
1353            if (s->greyscale)
1354                    strcat(tmp, "G ");
1355    
1356            if (s->chroma_opt)
1357                    strcat(tmp, "C ");
1358    
1359            ListView_SetItemText(hDlg, i, 2, tmp);
1360    }
1361    
1362    void main_mode(HWND hDlg, CONFIG * config)
1363    {
1364            const int profile = SendDlgItemMessage(hDlg, IDC_PROFILE, CB_GETCURSEL, 0, 0);
1365            const int rc_mode = SendDlgItemMessage(hDlg, IDC_MODE, CB_GETCURSEL, 0, 0);
1366            /* enable target rate/size control only for 1pass and 2pass  modes*/
1367            const int target_en = rc_mode==RC_MODE_1PASS || rc_mode==RC_MODE_2PASS2;
1368            const int target_en_slider = rc_mode==RC_MODE_1PASS ||
1369                    (rc_mode==RC_MODE_2PASS2 && config->use_2pass_bitrate);
1370    
1371            char buf[16];
1372            int max;
1373    
1374            g_use_bitrate = config->use_2pass_bitrate;
1375    
1376            if (g_use_bitrate) {
1377                    SetDlgItemText(hDlg, IDC_BITRATE_S, "Target bitrate (kbps):");
1378    
1379                    wsprintf(buf, "%i kbps", DEFAULT_MIN_KBPS);
1380                    SetDlgItemText(hDlg, IDC_BITRATE_MIN, buf);
1381    
1382                    max = profiles[profile].max_bitrate;
1383                    if (max == 0) max = DEFAULT_MAX_KBPS;
1384                    wsprintf(buf, "%i kbps", max);
1385                    SetDlgItemText(hDlg, IDC_BITRATE_MAX, buf);
1386    
1387                    SendDlgItemMessage(hDlg, IDC_SLIDER, TBM_SETRANGE, TRUE, MAKELONG(DEFAULT_MIN_KBPS, max));
1388                    SendDlgItemMessage(hDlg, IDC_SLIDER, TBM_SETPOS, TRUE,
1389                                                    config_get_uint(hDlg, IDC_BITRATE, DEFAULT_MIN_KBPS) );
1390    
1391            } else if (rc_mode==RC_MODE_2PASS2) {
1392                    SetDlgItemText(hDlg, IDC_BITRATE_S, "Target size (kbytes):");
1393            } else if (rc_mode==RC_MODE_1PASS) {
1394                    SetDlgItemText(hDlg, IDC_BITRATE_S, "Target quantizer:");
1395                    SendDlgItemMessage(hDlg, IDC_SLIDER, TBM_SETRANGE, TRUE, MAKELONG(100, 3100));
1396                    SendDlgItemMessage(hDlg, IDC_SLIDER, TBM_SETPOS, TRUE,
1397                                                            get_dlgitem_float(hDlg, IDC_BITRATE, DEFAULT_QUANT ));
1398                    SetDlgItemText(hDlg, IDC_BITRATE_MIN, "1 (maximum quality)");
1399                    SetDlgItemText(hDlg, IDC_BITRATE_MAX, "(smallest file) 31");
1400    
1401            }
1402    
1403            EnableDlgWindow(hDlg, IDC_BITRATE_S, target_en);
1404            EnableDlgWindow(hDlg, IDC_BITRATE, target_en);
1405    
1406            EnableDlgWindow(hDlg, IDC_BITRATE_MIN, target_en_slider);
1407            EnableDlgWindow(hDlg, IDC_BITRATE_MAX, target_en_slider);
1408            EnableDlgWindow(hDlg, IDC_SLIDER, target_en_slider);
1409    }
1410    
1411    
1412    
1413    void main_upload(HWND hDlg, CONFIG * config)
1414    {
1415    
1416            SendDlgItemMessage(hDlg, IDC_PROFILE, CB_SETCURSEL, config->profile, 0);
1417            SendDlgItemMessage(hDlg, IDC_MODE, CB_SETCURSEL, config->mode, 0);
1418    
1419            g_use_bitrate = config->use_2pass_bitrate;
1420    
1421            if (g_use_bitrate) {
1422                    SetDlgItemInt(hDlg, IDC_BITRATE, config->bitrate, FALSE);
1423            } else if (config->mode == RC_MODE_2PASS2) {
1424                    SetDlgItemInt(hDlg, IDC_BITRATE, config->desired_size, FALSE);
1425            } else if (config->mode == RC_MODE_1PASS) {
1426                    set_dlgitem_float(hDlg, IDC_BITRATE, config->desired_quant);
1427            }
1428    
1429            zones_update(hDlg, config);}
1430    
1431    
1432    /* downloads data from main dialog */
1433    void main_download(HWND hDlg, CONFIG * config)
1434    {
1435            config->profile = SendDlgItemMessage(hDlg, IDC_PROFILE, CB_GETCURSEL, 0, 0);
1436            config->mode = SendDlgItemMessage(hDlg, IDC_MODE, CB_GETCURSEL, 0, 0);
1437    
1438            if (g_use_bitrate) {
1439                    config->bitrate = config_get_uint(hDlg, IDC_BITRATE, config->bitrate);
1440            } else if (config->mode == RC_MODE_2PASS2) {
1441                    config->desired_size = config_get_uint(hDlg, IDC_BITRATE, config->desired_size);
1442            } else if (config->mode == RC_MODE_1PASS) {
1443                    config->desired_quant = get_dlgitem_float(hDlg, IDC_BITRATE, config->desired_quant);
1444            }
1445    }
1446    
1447    
1448    /* main dialog proc */
1449    
1450    static const int profile_dlgs[] = { IDD_PROFILE, IDD_LEVEL, IDD_AR };
1451    static const int single_dlgs[] = { IDD_RC_CBR };
1452    static const int pass1_dlgs[] = { IDD_RC_2PASS1 };
1453    static const int pass2_dlgs[] = { IDD_RC_2PASS2 };
1454    static const int zone_dlgs[] = { IDD_ZONE };
1455    static const int decoder_dlgs[] = { IDD_DEC };
1456    static const int adv_dlgs[] = { IDD_MOTION, IDD_QUANT, IDD_DEBUG};
1457    
1458    
1459    BOOL CALLBACK main_proc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
1460    {
1461            CONFIG* config = (CONFIG*)GetWindowLong(hDlg, GWL_USERDATA);
1462            unsigned int i;
1463    
1464            switch (uMsg)
1465            {
1466            case WM_INITDIALOG :
1467                    SetWindowLong(hDlg, GWL_USERDATA, lParam);
1468                    config = (CONFIG*)lParam;
1469    
1470                    for (i=0; i<sizeof(profiles)/sizeof(profile_t); i++)
1471                            SendDlgItemMessage(hDlg, IDC_PROFILE, CB_ADDSTRING, 0, (LPARAM)profiles[i].name);
1472    
1473                    SendDlgItemMessage(hDlg, IDC_MODE, CB_ADDSTRING, 0, (LPARAM)"Single pass");
1474                    SendDlgItemMessage(hDlg, IDC_MODE, CB_ADDSTRING, 0, (LPARAM)"Twopass - 1st pass");
1475                    SendDlgItemMessage(hDlg, IDC_MODE, CB_ADDSTRING, 0, (LPARAM)"Twopass - 2nd pass");
1476    #ifdef _DEBUG
1477                    SendDlgItemMessage(hDlg, IDC_MODE, CB_ADDSTRING, 0, (LPARAM)"Null test speed");
1478    #endif
1479    
1480                    InitCommonControls();
1481    
1482                    if ((g_hTooltip = CreateWindow(TOOLTIPS_CLASS, NULL, TTS_ALWAYSTIP,
1483                                    CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
1484                                    NULL, NULL, g_hInst, NULL)))
1485                    {
1486                            SetWindowPos(g_hTooltip, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE);
1487                            SendMessage(g_hTooltip, TTM_SETDELAYTIME, TTDT_AUTOMATIC, MAKELONG(1500, 0));
1488                            SendMessage(g_hTooltip, TTM_SETMAXTIPWIDTH, 0, 400);
1489    
1490                            EnumChildWindows(hDlg, enum_tooltips, 0);
1491                    }
1492    
1493                    SetClassLong(GetDlgItem(hDlg, IDC_BITRATE_S), GCL_HCURSOR, (LONG)LoadCursor(NULL, IDC_HAND));
1494    
1495                    {
1496                            DWORD ext_style = ListView_GetExtendedListViewStyle(GetDlgItem(hDlg,IDC_ZONES));
1497                            ext_style |= LVS_EX_FULLROWSELECT | LVS_EX_FLATSB ;
1498                            ListView_SetExtendedListViewStyle(GetDlgItem(hDlg,IDC_ZONES), ext_style);
1499                    }
1500    
1501                    {
1502                            typedef struct {
1503                                    char * name;
1504                                    int value;
1505                            } char_int_t;
1506    
1507                            const static char_int_t columns[] = {
1508                                    {"Frame #",      64},
1509                                    {"Weight/Quant",  82},
1510                                    {"Modifiers",   120}};
1511    
1512                            LVCOLUMN lvc;
1513                            int i;
1514    
1515                            /* Initialize the LVCOLUMN structure.  */
1516                            lvc.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;
1517                            lvc.fmt = LVCFMT_LEFT;
1518    
1519                            /* Add the columns.  */
1520                            for (i=0; i<sizeof(columns)/sizeof(char_int_t); i++) {
1521                                    lvc.pszText = (char*)columns[i].name;
1522                                    lvc.cchTextMax = strlen(columns[i].name);
1523                                    lvc.iSubItem = i;
1524                                    lvc.cx = columns[i].value;  /* column width, pixels */
1525                                    ListView_InsertColumn(GetDlgItem(hDlg,IDC_ZONES), i, &lvc);
1526                            }
1527                    }
1528    
1529                    /* XXX: main_mode needs RC_MODE_xxx, main_upload needs g_use_bitrate set correctly... */
1530                    main_upload(hDlg, config);
1531                    main_mode(hDlg, config);
1532                    main_upload(hDlg, config);
1533                    break;
1534    
1535            case WM_NOTIFY :
1536                    {
1537                            NMHDR * n = (NMHDR*)lParam;
1538    
1539                            if (n->code == NM_DBLCLK) {
1540                                     NMLISTVIEW * nmlv = (NMLISTVIEW*) lParam;
1541                                     config->cur_zone = nmlv->iItem;
1542    
1543                                     main_download(hDlg, config);
1544                                     if (config->cur_zone >= 0 && adv_dialog(hDlg, config, zone_dlgs, sizeof(zone_dlgs)/sizeof(int))) {
1545                                             zones_update(hDlg, config);
1546                                     }
1547                                     break;
1548                            }
1549    
1550                            if (n->code == NM_RCLICK) {
1551                                    OutputDebugString("Right click");
1552                            }
1553                    break;
1554                    }
1555    
1556            case WM_COMMAND :
1557                    if (HIWORD(wParam) == BN_CLICKED) {
1558    
1559                            switch(LOWORD(wParam)) {
1560                            case IDC_PROFILE_ADV :
1561                                    main_download(hDlg, config);
1562                                    adv_dialog(hDlg, config, profile_dlgs, sizeof(profile_dlgs)/sizeof(int));
1563    
1564                                    SendDlgItemMessage(hDlg, IDC_PROFILE, CB_SETCURSEL, config->profile, 0);
1565                                    main_mode(hDlg, config);
1566                                    break;
1567    
1568                            case IDC_MODE_ADV :
1569                                    main_download(hDlg, config);
1570                                    if (config->mode == RC_MODE_1PASS) {
1571                                            adv_dialog(hDlg, config, single_dlgs, sizeof(single_dlgs)/sizeof(int));
1572                                    }else if (config->mode == RC_MODE_2PASS1) {
1573                                            adv_dialog(hDlg, config, pass1_dlgs, sizeof(pass1_dlgs)/sizeof(int));
1574                                    }else if (config->mode == RC_MODE_2PASS2) {
1575                                            adv_dialog(hDlg, config, pass2_dlgs, sizeof(pass2_dlgs)/sizeof(int));
1576                                    }
1577                                    break;
1578    
1579    
1580                            case IDC_BITRATE_S :
1581                                    /* alternate between bitrate/desired_length metrics */
1582                                    main_download(hDlg, config);
1583                                    config->use_2pass_bitrate = !config->use_2pass_bitrate;
1584                                    main_mode(hDlg, config);
1585                                    main_upload(hDlg, config);
1586                                    break;
1587    
1588                            case IDC_DECODER :
1589                                    main_download(hDlg, config);
1590                                    adv_dialog(hDlg, config, decoder_dlgs, sizeof(decoder_dlgs)/sizeof(int));
1591                                    main_mode(hDlg, config);
1592                                    break;
1593    
1594                            case IDC_ADD :
1595                            {
1596                                    int i, sel, new_frame;
1597    
1598                                    if (config->num_zones >= MAX_ZONES) {
1599                                            MessageBox(hDlg, "Exceeded maximum number of zones.\nIncrease config.h:MAX_ZONES and rebuild.", "Warning", 0);
1600                                            break;
1601                                    }
1602    
1603                                    sel = ListView_GetNextItem(GetDlgItem(hDlg, IDC_ZONES), -1, LVNI_SELECTED);
1604    
1605                                    if (sel<0) {
1606                                            if (config->ci_valid && config->ci.ciActiveFrame>0) {
1607                                                    for(sel=0; sel<config->num_zones-1 && config->zones[sel].frame<config->ci.ciActiveFrame; sel++) ;
1608                                                    sel--;
1609                                                    new_frame = config->ci.ciActiveFrame;
1610                                            }else{
1611                                                    sel = config->num_zones-1;
1612                                                    new_frame = sel<0 ? 0 : config->zones[sel].frame + 1;
1613                                            }
1614                                    }else{
1615                                            new_frame = config->zones[sel].frame + 1;
1616                                    }
1617    
1618                                    for(i=config->num_zones-1; i>sel; i--) {
1619                                            config->zones[i+1] = config->zones[i];
1620                                    }
1621                                    config->num_zones++;
1622                                    config->zones[sel+1].frame = new_frame;
1623                                    config->zones[sel+1].mode = RC_ZONE_WEIGHT;
1624                                    config->zones[sel+1].weight = 100;
1625                                    config->zones[sel+1].quant = 500;
1626                                    config->zones[sel+1].type = XVID_TYPE_AUTO;
1627                                    config->zones[sel+1].greyscale = 0;
1628                                    config->zones[sel+1].chroma_opt = 0;
1629                                    config->zones[sel+1].bvop_threshold = 0;
1630    
1631                                    ListView_SetItemState(GetDlgItem(hDlg, IDC_ZONES), sel, 0x00000000, LVIS_SELECTED);
1632                                    zones_update(hDlg, config);
1633                                    ListView_SetItemState(GetDlgItem(hDlg, IDC_ZONES), sel+1, 0xffffffff, LVIS_SELECTED);
1634                                    break;
1635                            }
1636    
1637                            case IDC_REMOVE :
1638                            {
1639                                    int i, sel;
1640                                    sel = ListView_GetNextItem(GetDlgItem(hDlg, IDC_ZONES), -1, LVNI_SELECTED);
1641    
1642                                    if (sel == -1 || config->num_zones < 1) {
1643                                            /*MessageBox(hDlg, "Nothing selected", "Warning", 0);*/
1644                                            break;
1645                                    }
1646    
1647                                    for (i=sel; i<config->num_zones-1; i++)
1648                                            config->zones[i] = config->zones[i+1];
1649    
1650                                    config->num_zones--;
1651    
1652                                    zones_update(hDlg, config);
1653                                    break;
1654                            }
1655    
1656                            case IDC_EDIT :
1657                                    main_download(hDlg, config);
1658                                    config->cur_zone = ListView_GetNextItem(GetDlgItem(hDlg, IDC_ZONES), -1, LVNI_SELECTED);
1659                                    if (config->cur_zone != -1 && adv_dialog(hDlg, config, zone_dlgs, sizeof(zone_dlgs)/sizeof(int))) {
1660                                            zones_update(hDlg, config);
1661                                    }
1662                                    break;
1663    
1664                            case IDC_ADVANCED :
1665                                    main_download(hDlg, config);
1666                                    adv_dialog(hDlg, config, adv_dlgs, sizeof(adv_dlgs)/sizeof(int));
1667                                    break;
1668    
1669                            case IDC_DEFAULTS :
1670                                    config_reg_default(config);
1671                                    main_mode(hDlg, config);
1672                                    main_upload(hDlg, config);
1673                                    break;
1674    
1675                            case IDOK :
1676                                    main_download(hDlg, config);
1677                                    config->save = TRUE;
1678                                    EndDialog(hDlg, IDOK);
1679                                    break;
1680    
1681                            case IDCANCEL :
1682                                    config->save = FALSE;
1683                                    EndDialog(hDlg, IDCANCEL);
1684                                    break;
1685                            }
1686                    } else if (HIWORD(wParam) == LBN_SELCHANGE &&
1687                            (LOWORD(wParam)==IDC_PROFILE || LOWORD(wParam)==IDC_MODE)) {
1688    
1689                            config->mode = SendDlgItemMessage(hDlg, IDC_MODE, CB_GETCURSEL, 0, 0);
1690                            config->profile = SendDlgItemMessage(hDlg, IDC_PROFILE, CB_GETCURSEL, 0, 0);
1691    
1692                            if (!g_use_bitrate) {
1693                                    if (config->mode == RC_MODE_1PASS)
1694                                            set_dlgitem_float(hDlg, IDC_BITRATE, config->desired_quant);
1695                                    else if (config->mode == RC_MODE_2PASS2)
1696                                            SetDlgItemInt(hDlg, IDC_BITRATE, config->desired_size, FALSE);
1697                            }
1698    
1699                            main_mode(hDlg, config);
1700                            main_upload(hDlg, config);
1701    
1702                    }else if (HIWORD(wParam)==EN_UPDATE && LOWORD(wParam)==IDC_BITRATE) {
1703    
1704                            if (g_use_bitrate) {
1705                                    SendDlgItemMessage(hDlg, IDC_SLIDER, TBM_SETPOS, TRUE,
1706                                                    config_get_uint(hDlg, IDC_BITRATE, DEFAULT_MIN_KBPS) );
1707                            } else if (config->mode == RC_MODE_1PASS) {
1708                                    SendDlgItemMessage(hDlg, IDC_SLIDER, TBM_SETPOS, TRUE,
1709                                                    get_dlgitem_float(hDlg, IDC_BITRATE, DEFAULT_QUANT) );
1710                            }
1711                            main_download(hDlg, config);
1712    
1713                    }else {
1714                            return 0;
1715                    }
1716                    break;
1717    
1718            case WM_HSCROLL :
1719                    if((HWND)lParam == GetDlgItem(hDlg, IDC_SLIDER)) {
1720                            if (g_use_bitrate)
1721                                    SetDlgItemInt(hDlg, IDC_BITRATE, SendMessage((HWND)lParam, TBM_GETPOS, 0, 0), FALSE);
1722                            else
1723                                    set_dlgitem_float(hDlg, IDC_BITRATE, SendMessage((HWND)lParam, TBM_GETPOS, 0, 0));
1724    
1725                            main_download(hDlg, config);
1726                            break;
1727                    }
1728                    return 0;
1729    
1730            default :
1731                    return 0;
1732            }
1733    
1734            return 1;
1735    }
1736    
1737    
1738    
1739    /* ===================================================================================== */
1740    /* ABOUT DIALOG ======================================================================== */
1741    /* ===================================================================================== */
1742    
1743    BOOL CALLBACK about_proc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
1744    {
1745            switch (uMsg)
1746            {
1747            case WM_INITDIALOG :
1748                    {
1749                            xvid_gbl_info_t info;
1750                            char core[100];
1751                            HFONT hFont;
1752                            LOGFONT lfData;
1753                            HINSTANCE m_hdll;
1754    
1755                            SetDlgItemText(hDlg, IDC_BUILD, XVID_BUILD);
1756                            SetDlgItemText(hDlg, IDC_SPECIAL_BUILD, XVID_SPECIAL_BUILD);
1757    
1758                            memset(&info, 0, sizeof(info));
1759                            info.version = XVID_VERSION;
1760    
1761                            m_hdll = LoadLibrary(XVID_DLL_NAME);
1762                            if (m_hdll != NULL) {
1763    
1764                                    ((int (__cdecl *)(void *, int, void *, void *))GetProcAddress(m_hdll, "xvid_global"))
1765                                            (0, XVID_GBL_INFO, &info, NULL);
1766    
1767                                    wsprintf(core, "xvidcore.dll version %d.%d.%d (\"%s\")",
1768                                            XVID_VERSION_MAJOR(info.actual_version),
1769                                            XVID_VERSION_MINOR(info.actual_version),
1770                                            XVID_VERSION_PATCH(info.actual_version),
1771                                            info.build);
1772    
1773                                    FreeLibrary(m_hdll);
1774                            } else {
1775                                    wsprintf(core, "xvidcore.dll not found!");
1776                            }
1777    
1778                            SetDlgItemText(hDlg, IDC_CORE, core);
1779    
1780                            hFont = (HFONT)SendDlgItemMessage(hDlg, IDC_WEBSITE, WM_GETFONT, 0, 0L);
1781    
1782                            if (GetObject(hFont, sizeof(LOGFONT), &lfData)) {
1783                                    lfData.lfUnderline = 1;
1784    
1785                                    hFont = CreateFontIndirect(&lfData);
1786                                    if (hFont) {
1787                                            SendDlgItemMessage(hDlg, IDC_WEBSITE, WM_SETFONT, (WPARAM)hFont, 1L);
1788                                    }
1789                            }
1790    
1791                            SetClassLong(GetDlgItem(hDlg, IDC_WEBSITE), GCL_HCURSOR, (LONG)LoadCursor(NULL, IDC_HAND));
1792                            SetDlgItemText(hDlg, IDC_WEBSITE, XVID_WEBSITE);
1793                    }
1794                    break;
1795            case WM_CTLCOLORSTATIC :
1796                    if ((HWND)lParam == GetDlgItem(hDlg, IDC_WEBSITE))
1797                    {
1798                            SetBkMode((HDC)wParam, TRANSPARENT) ;
1799                            SetTextColor((HDC)wParam, RGB(0x00,0x00,0xc0));
1800                            return (BOOL)GetStockObject(NULL_BRUSH);
1801                    }
1802                    return 0;
1803    
1804            case WM_COMMAND :
1805                    if (LOWORD(wParam) == IDC_WEBSITE && HIWORD(wParam) == STN_CLICKED)
1806                    {
1807                            ShellExecute(hDlg, "open", XVID_WEBSITE, NULL, NULL, SW_SHOWNORMAL);
1808                    }
1809                    else if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
1810                    {
1811                            EndDialog(hDlg, LOWORD(wParam));
1812                    }
1813                    break;
1814    
1815            default :
1816                    return 0;
1817            }
1818    
1819            return 1;
1820    }
1821    
1822    void
1823    sort_zones(zone_t * zones, int zone_num, int * sel)
1824    {
1825            int i, j;
1826            zone_t tmp;
1827            for (i = 0; i < zone_num; i++) {
1828                    int cur = i;
1829                    int min_f = zones[i].frame;
1830                    for (j = i + 1; j < zone_num; j++) {
1831                            if (zones[j].frame < min_f) {
1832                                    min_f = zones[j].frame;
1833                                    cur = j;
1834                            }
1835                    }
1836                    if (cur != i) {
1837                            tmp = zones[i];
1838                            zones[i] = zones[cur];
1839                            zones[cur] = tmp;
1840                            if (i == *sel) *sel = cur;
1841                            else if (cur == *sel) *sel = i;
1842                    }
1843            }
1844    }
1845    
1846    
1847    static void
1848    zones_update(HWND hDlg, CONFIG * config)
1849    {
1850            int i, sel;
1851    
1852            sel = ListView_GetNextItem(GetDlgItem(hDlg, IDC_ZONES), -1, LVNI_SELECTED);
1853    
1854            sort_zones(config->zones, config->num_zones, &sel);
1855    
1856            ListView_DeleteAllItems(GetDlgItem(hDlg,IDC_ZONES));
1857    
1858            for (i = 0; i < config->num_zones; i++)
1859                    main_insert_zone(GetDlgItem(hDlg,IDC_ZONES), &config->zones[i], i, TRUE);
1860    
1861            if (sel == -1 && config->num_zones > 0) sel = 0;
1862            if (sel >= config->num_zones) sel = config->num_zones-1;
1863    
1864            config->cur_zone = sel;
1865            ListView_SetItemState(GetDlgItem(hDlg, IDC_ZONES), sel, 0xffffffff, LVIS_SELECTED);
1866    }

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.1.2.31

No admin address has been configured
ViewVC Help
Powered by ViewVC 1.0.4