x11drvdlg.c 11.4 KB
Newer Older
1
/*
2
 * Graphics configuration code
3 4
 *
 * Copyright 2003 Mark Westcott
5
 * Copyright 2003-2004 Mike Hearn
6
 * Copyright 2005 Raphael Junqueira
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 */

24
#include <stdarg.h>
25 26 27
#include <stdlib.h>
#include <stdio.h>

28 29 30 31 32
#include <windef.h>
#include <winbase.h>
#include <winreg.h>
#include <wine/debug.h>

33 34 35 36 37
#include "resource.h"
#include "winecfg.h"

WINE_DEFAULT_DEBUG_CHANNEL(winecfg);

38 39
#define RES_MAXLEN 5 /* the maximum number of characters in a screen dimension. 5 digits should be plenty, what kind of crazy person runs their screen >10,000 pixels across? */

40 41 42 43 44 45 46 47 48

static const char* D3D_VS_Modes[] = {
  "hardware",
  "none",
  "emulation",
  NULL
};


49
int updating_ui;
50

51
static void update_gui_for_desktop_mode(HWND dialog) {
52
    int desktopenabled = FALSE;
53

54
    WINE_TRACE("\n");
55
    updating_ui = TRUE;
56 57
    
    /* do we have desktop mode enabled? */
58
    if (reg_key_exists(config_key, keypath("X11 Driver"), "Desktop"))
59
    {
60
        char* buf, *bufindex;
61
	CheckDlgButton(dialog, IDC_ENABLE_DESKTOP, BST_CHECKED);
62

63
        buf = get_reg_key(config_key, keypath("X11 Driver"), "Desktop", "640x480");
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
        /* note: this test must match the one in x11drv */
        if( buf[0] != 'n' &&  buf[0] != 'N' &&  buf[0] != 'F' &&  buf[0] != 'f'
                &&  buf[0] != '0') {
            desktopenabled = TRUE;
            enable(IDC_DESKTOP_WIDTH);
            enable(IDC_DESKTOP_HEIGHT);
            enable(IDC_DESKTOP_SIZE);
            enable(IDC_DESKTOP_BY);

            bufindex = strchr(buf, 'x');
            if (bufindex) {
                *bufindex = 0;
                ++bufindex;
                SetWindowText(GetDlgItem(dialog, IDC_DESKTOP_WIDTH), buf);
                SetWindowText(GetDlgItem(dialog, IDC_DESKTOP_HEIGHT), bufindex);
            } else {
                WINE_TRACE("Desktop registry entry is malformed");
                SetWindowText(GetDlgItem(dialog, IDC_DESKTOP_WIDTH), "640");
                SetWindowText(GetDlgItem(dialog, IDC_DESKTOP_HEIGHT), "480");
            }
84 85
        }
        HeapFree(GetProcessHeap(), 0, buf);
86
    }
87
    if (!desktopenabled)
88
    {
89
	CheckDlgButton(dialog, IDC_ENABLE_DESKTOP, BST_UNCHECKED);
90
	
91 92 93 94
	disable(IDC_DESKTOP_WIDTH);
	disable(IDC_DESKTOP_HEIGHT);
	disable(IDC_DESKTOP_SIZE);
	disable(IDC_DESKTOP_BY);
95

96 97
	SetWindowText(GetDlgItem(dialog, IDC_DESKTOP_WIDTH), "");
	SetWindowText(GetDlgItem(dialog, IDC_DESKTOP_HEIGHT), "");
98 99
    }

100
    updating_ui = FALSE;
101 102
}

103
static void init_screen_depth(HWND dialog)
104
{
105
    char* buf;
106
    buf = get_reg_key(config_key, keypath("X11 Driver"), "ScreenDepth", "24");
107
    if (strcmp(buf, "8") == 0)
108
	SendDlgItemMessage(dialog, IDC_SCREEN_DEPTH, CB_SETCURSEL, 0, 0);
109
    else if (strcmp(buf, "16") == 0)
110
	SendDlgItemMessage(dialog, IDC_SCREEN_DEPTH, CB_SETCURSEL, 1, 0);
111
    else if (strcmp(buf, "24") == 0)
112
	SendDlgItemMessage(dialog, IDC_SCREEN_DEPTH, CB_SETCURSEL, 2, 0);
113
    else if (strcmp(buf, "32") == 0)
114
	SendDlgItemMessage(dialog, IDC_SCREEN_DEPTH, CB_SETCURSEL, 3, 0);
115 116
    else
	WINE_ERR("Invalid screen depth read from registry (%s)\n", buf);
117
    HeapFree(GetProcessHeap(), 0, buf);
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
}

static void init_dialog(HWND dialog)
{
    unsigned int it;
    char* buf;

    update_gui_for_desktop_mode(dialog);

    updating_ui = TRUE;
    
    SendDlgItemMessage(dialog, IDC_SCREEN_DEPTH, CB_RESETCONTENT, 0, 0);
    SendDlgItemMessage(dialog, IDC_SCREEN_DEPTH, CB_ADDSTRING, 0, (LPARAM) "8 bit");
    SendDlgItemMessage(dialog, IDC_SCREEN_DEPTH, CB_ADDSTRING, 0, (LPARAM) "16 bit");
    SendDlgItemMessage(dialog, IDC_SCREEN_DEPTH, CB_ADDSTRING, 0, (LPARAM) "24 bit");
    SendDlgItemMessage(dialog, IDC_SCREEN_DEPTH, CB_ADDSTRING, 0, (LPARAM) "32 bit"); /* is this valid? */
134

135 136
    SendDlgItemMessage(dialog, IDC_DESKTOP_WIDTH, EM_LIMITTEXT, RES_MAXLEN, 0);
    SendDlgItemMessage(dialog, IDC_DESKTOP_HEIGHT, EM_LIMITTEXT, RES_MAXLEN, 0);
137

138
    buf = get_reg_key(config_key, keypath("X11 Driver"), "DXGrab", "N");
139
    if (IS_OPTION_TRUE(*buf))
140
	CheckDlgButton(dialog, IDC_DX_MOUSE_GRAB, BST_CHECKED);
141
    else
142
	CheckDlgButton(dialog, IDC_DX_MOUSE_GRAB, BST_UNCHECKED);
143
    HeapFree(GetProcessHeap(), 0, buf);
144

145
    buf = get_reg_key(config_key, keypath("X11 Driver"), "DesktopDoubleBuffered", "Y");
146
    if (IS_OPTION_TRUE(*buf)) {
147
	CheckDlgButton(dialog, IDC_DOUBLE_BUFFER, BST_CHECKED);
148 149 150
	SendDlgItemMessage(dialog, IDC_SCREEN_DEPTH, CB_SETCURSEL, -1, 0);
	disable(IDC_SCREEN_DEPTH);
    } else {
151
	CheckDlgButton(dialog, IDC_DOUBLE_BUFFER, BST_UNCHECKED);
152 153 154
    	init_screen_depth(dialog);
	enable(IDC_SCREEN_DEPTH);
    }
155
    HeapFree(GetProcessHeap(), 0, buf);
156

157 158 159 160 161 162 163
    buf = get_reg_key(config_key, keypath("X11 Driver"), "Managed", "Y");
    if (IS_OPTION_TRUE(*buf))
	CheckDlgButton(dialog, IDC_ENABLE_MANAGED, BST_CHECKED);
    else
	CheckDlgButton(dialog, IDC_ENABLE_MANAGED, BST_UNCHECKED);
    HeapFree(GetProcessHeap(), 0, buf);

164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186
    SendDlgItemMessage(dialog, IDC_D3D_VSHADER_MODE, CB_RESETCONTENT, 0, 0);
    for (it = 0; NULL != D3D_VS_Modes[it]; ++it) {
      SendDlgItemMessage(dialog, IDC_D3D_VSHADER_MODE, CB_ADDSTRING, 0, (LPARAM) D3D_VS_Modes[it]);
    }  
    buf = get_reg_key(config_key, keypath("Direct3D"), "VertexShaderMode", "hardware"); 
    for (it = 0; NULL != D3D_VS_Modes[it]; ++it) {
      if (strcmp(buf, D3D_VS_Modes[it]) == 0) {
	SendDlgItemMessage(dialog, IDC_D3D_VSHADER_MODE, CB_SETCURSEL, it, 0);
	break ;
      }
    }
    if (NULL == D3D_VS_Modes[it]) {
      WINE_ERR("Invalid Direct3D VertexShader Mode read from registry (%s)\n", buf);
    }
    HeapFree(GetProcessHeap(), 0, buf);

    buf = get_reg_key(config_key, keypath("Direct3D"), "PixelShaderMode", "enabled");
    if (!strcmp(buf, "enabled"))
      CheckDlgButton(dialog, IDC_D3D_PSHADER_MODE, BST_CHECKED);
    else
      CheckDlgButton(dialog, IDC_D3D_PSHADER_MODE, BST_UNCHECKED);
    HeapFree(GetProcessHeap(), 0, buf);

187
    updating_ui = FALSE;
188
}
189

190 191
static void set_from_desktop_edits(HWND dialog) {
    char *width, *height, *new;
192

193
    if (updating_ui) return;
194 195
    
    WINE_TRACE("\n");
196

Mike Hearn's avatar
Mike Hearn committed
197 198
    width = get_text(dialog, IDC_DESKTOP_WIDTH);
    height = get_text(dialog, IDC_DESKTOP_HEIGHT);
199

200
    if (width == NULL || strcmp(width, "") == 0) {
201 202 203
        HeapFree(GetProcessHeap(), 0, width);
        width = strdupA("640");
    }
204
    
205
    if (height == NULL || strcmp(height, "") == 0) {
206 207 208 209 210
        HeapFree(GetProcessHeap(), 0, height);
        height = strdupA("480");
    }

    new = HeapAlloc(GetProcessHeap(), 0, strlen(width) + strlen(height) + 2 /* x + terminator */);
211
    sprintf(new, "%sx%s", width, height);
212
    set_reg_key(config_key, keypath("X11 Driver"), "Desktop", new);
213 214 215 216
    
    HeapFree(GetProcessHeap(), 0, width);
    HeapFree(GetProcessHeap(), 0, height);
    HeapFree(GetProcessHeap(), 0, new);
217 218
}

219
static void on_enable_desktop_clicked(HWND dialog) {
220
    WINE_TRACE("\n");
221 222
    
    if (IsDlgButtonChecked(dialog, IDC_ENABLE_DESKTOP) == BST_CHECKED) {
223
        set_from_desktop_edits(dialog);
224
    } else {
225
        set_reg_key(config_key, keypath("X11 Driver"), "Desktop", NULL);
226
    }
227 228
    
    update_gui_for_desktop_mode(dialog);
229
}
230

231 232 233 234 235 236 237 238 239 240
static void on_enable_managed_clicked(HWND dialog) {
    WINE_TRACE("\n");
    
    if (IsDlgButtonChecked(dialog, IDC_ENABLE_MANAGED) == BST_CHECKED) {
        set_reg_key(config_key, keypath("X11 Driver"), "Managed", "Y");
    } else {
        set_reg_key(config_key, keypath("X11 Driver"), "Managed", "N");
    }
}

241
static void on_screen_depth_changed(HWND dialog) {
Mike Hearn's avatar
Mike Hearn committed
242
    char *newvalue = get_text(dialog, IDC_SCREEN_DEPTH);
243
    char *spaceIndex = strchr(newvalue, ' ');
244
    
245
    WINE_TRACE("newvalue=%s\n", newvalue);
246
    if (updating_ui) return;
247

248
    *spaceIndex = '\0';
249
    set_reg_key(config_key, keypath("X11 Driver"), "ScreenDepth", newvalue);
250
    HeapFree(GetProcessHeap(), 0, newvalue);
251 252
}

253
static void on_dx_mouse_grab_clicked(HWND dialog) {
254
    if (IsDlgButtonChecked(dialog, IDC_DX_MOUSE_GRAB) == BST_CHECKED) 
255
        set_reg_key(config_key, keypath("X11 Driver"), "DXGrab", "Y");
256
    else
257
        set_reg_key(config_key, keypath("X11 Driver"), "DXGrab", "N");
258 259
}

260

261
static void on_double_buffer_clicked(HWND dialog) {
262
    if (IsDlgButtonChecked(dialog, IDC_DOUBLE_BUFFER) == BST_CHECKED) {
263
        set_reg_key(config_key, keypath("X11 Driver"), "DesktopDoubleBuffered", "Y");
264 265 266
	SendDlgItemMessage(dialog, IDC_SCREEN_DEPTH, CB_SETCURSEL, -1, 0);
	disable(IDC_SCREEN_DEPTH);
    } else {
267
        set_reg_key(config_key, keypath("X11 Driver"), "DesktopDoubleBuffered", "N");
268 269 270
    	init_screen_depth(dialog);
	enable(IDC_SCREEN_DEPTH);
    }
271 272
}

273 274 275 276 277 278 279 280 281 282 283 284
static void on_d3d_vshader_mode_changed(HWND dialog) {
  int selected_mode = SendDlgItemMessage(dialog, IDC_D3D_VSHADER_MODE, CB_GETCURSEL, 0, 0);  
  set_reg_key(config_key, keypath("Direct3D"), "VertexShaderMode", D3D_VS_Modes[selected_mode]); 
}

static void on_d3d_pshader_mode_clicked(HWND dialog) {
    if (IsDlgButtonChecked(dialog, IDC_D3D_PSHADER_MODE) == BST_CHECKED)
        set_reg_key(config_key, keypath("Direct3D"), "PixelShaderMode", "enabled");
    else
        set_reg_key(config_key, keypath("Direct3D"), "PixelShaderMode", "disabled");
}

285
INT_PTR CALLBACK
286
GraphDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
287 288 289 290
{
    switch (uMsg) {
	case WM_INITDIALOG:
	    break;
291 292 293 294 295

        case WM_SHOWWINDOW:
            set_window_title(hDlg);
            break;
            
296 297 298
	case WM_COMMAND:
	    switch(HIWORD(wParam)) {
		case EN_CHANGE: {
299
		    if (updating_ui) break;
300
		    SendMessage(GetParent(hDlg), PSM_CHANGED, 0, 0);
301
		    if ( ((LOWORD(wParam) == IDC_DESKTOP_WIDTH) || (LOWORD(wParam) == IDC_DESKTOP_HEIGHT)) && !updating_ui )
302
			set_from_desktop_edits(hDlg);
303 304
		    break;
		}
305
		case BN_CLICKED: {
306
		    if (updating_ui) break;
307
		    SendMessage(GetParent(hDlg), PSM_CHANGED, 0, 0);
308
		    switch(LOWORD(wParam)) {
309
			case IDC_ENABLE_DESKTOP: on_enable_desktop_clicked(hDlg); break;
310
                        case IDC_ENABLE_MANAGED: on_enable_managed_clicked(hDlg); break;
311 312
			case IDC_DX_MOUSE_GRAB:  on_dx_mouse_grab_clicked(hDlg); break;
                        case IDC_DOUBLE_BUFFER:  on_double_buffer_clicked(hDlg); break;
313
		        case IDC_D3D_PSHADER_MODE: on_d3d_pshader_mode_clicked(hDlg); break;
314
		    }
315 316
		    break;
		}
317
		case CBN_SELCHANGE: {
318
		    SendMessage(GetParent(hDlg), PSM_CHANGED, 0, 0);
319 320 321 322
		    switch (LOWORD(wParam)) {
		    case IDC_SCREEN_DEPTH: on_screen_depth_changed(hDlg); break;
		    case IDC_D3D_VSHADER_MODE: on_d3d_vshader_mode_changed(hDlg); break;
		    }
323 324
		    break;
		}
325
		    
326 327 328 329
		default:
		    break;
	    }
	    break;
330 331
	
	
332 333 334
	case WM_NOTIFY:
	    switch (((LPNMHDR)lParam)->code) {
		case PSN_KILLACTIVE: {
335
		    SetWindowLongPtr(hDlg, DWLP_MSGRESULT, FALSE);
336 337 338
		    break;
		}
		case PSN_APPLY: {
339
                    apply();
340
		    SetWindowLongPtr(hDlg, DWLP_MSGRESULT, PSNRET_NOERROR);
341 342 343
		    break;
		}
		case PSN_SETACTIVE: {
344
		    init_dialog (hDlg);
345 346 347 348 349 350 351 352 353 354
		    break;
		}
	    }
	    break;

	default:
	    break;
    }
    return FALSE;
}