x11drvdlg.c 7.84 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
/*
 * X11DRV configuration code
 *
 * Copyright 2003 Mark Westcott
 * Copyright 2003 Mike Hearn
 *
 * 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
 *
 */

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

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

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

WINE_DEFAULT_DEBUG_CHANNEL(winecfg);

37
#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? */
38
#define section (appSettings == EDITING_GLOBAL ? "x11drv" : (getSectionForApp("x11drv")))
39 40 41

int updatingUI;

42
void updateGUIForDesktopMode(HWND dialog) {
43 44 45 46 47 48
    WINE_TRACE("\n");

    updatingUI = TRUE;
    
    /* do we have desktop mode enabled? */
    if (doesConfigValueExist("x11drv", "Desktop") == S_OK) {
49
	CheckDlgButton(dialog, IDC_ENABLE_DESKTOP, BST_CHECKED);
50
	/* enable the controls */
51 52 53 54 55 56 57
	enable(IDC_DESKTOP_WIDTH);
	enable(IDC_DESKTOP_HEIGHT);
	enable(IDC_DESKTOP_SIZE);
	enable(IDC_DESKTOP_BY);
	
	SetWindowText(GetDlgItem(dialog, IDC_DESKTOP_WIDTH), "640");
	SetWindowText(GetDlgItem(dialog, IDC_DESKTOP_HEIGHT), "480");	
58 59
    }
    else {
60
	CheckDlgButton(dialog, IDC_ENABLE_DESKTOP, BST_UNCHECKED);
61
	/* disable the controls */
62 63 64 65
	disable(IDC_DESKTOP_WIDTH);
	disable(IDC_DESKTOP_HEIGHT);
	disable(IDC_DESKTOP_SIZE);
	disable(IDC_DESKTOP_BY);
66

67 68
	SetWindowText(GetDlgItem(dialog, IDC_DESKTOP_WIDTH), "");
	SetWindowText(GetDlgItem(dialog, IDC_DESKTOP_HEIGHT), "");
69 70 71 72 73
    }

    updatingUI = FALSE;
}

74 75 76
/* pokes the win32 api to setup the dialog from the config struct */
void initX11DrvDlg (HWND hDlg)
{
77
    char *buf;
78
    char *bufindex;
79 80 81 82 83 84 85

    updatingUI = TRUE;
    
    updateGUIForDesktopMode(hDlg);
    
    /* desktop size */
    buf = getConfigValue("x11drv", "Desktop", "640x480");
86 87 88
    bufindex = strchr(buf, 'x');
    *bufindex = '\0';
    bufindex++;
89
    SetWindowText(GetDlgItem(hDlg, IDC_DESKTOP_WIDTH), buf);
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
    SetWindowText(GetDlgItem(hDlg, IDC_DESKTOP_HEIGHT), bufindex);
    free(buf);
    
    SendDlgItemMessage(hDlg, IDC_SCREEN_DEPTH, CB_ADDSTRING, 0, (LPARAM) "8 bit");
    SendDlgItemMessage(hDlg, IDC_SCREEN_DEPTH, CB_ADDSTRING, 0, (LPARAM) "16 bit");
    SendDlgItemMessage(hDlg, IDC_SCREEN_DEPTH, CB_ADDSTRING, 0, (LPARAM) "24 bit");
    SendDlgItemMessage(hDlg, IDC_SCREEN_DEPTH, CB_ADDSTRING, 0, (LPARAM) "32 bit"); /* is this valid? */

    buf = getConfigValue("x11drv", "ScreenDepth", "24");
    if (strcmp(buf, "8") == 0)
	SendDlgItemMessage(hDlg, IDC_SCREEN_DEPTH, CB_SETCURSEL, 0, 0);
    else if (strcmp(buf, "16") == 0)
	SendDlgItemMessage(hDlg, IDC_SCREEN_DEPTH, CB_SETCURSEL, 1, 0);
    else if (strcmp(buf, "24") == 0)
	SendDlgItemMessage(hDlg, IDC_SCREEN_DEPTH, CB_SETCURSEL, 2, 0);
    else if (strcmp(buf, "32") == 0)
	SendDlgItemMessage(hDlg, IDC_SCREEN_DEPTH, CB_SETCURSEL, 3, 0);
    else
	WINE_ERR("Invalid screen depth read from registry (%s)\n", buf);
109 110 111
    free(buf);

    SendDlgItemMessage(hDlg, IDC_DESKTOP_WIDTH, EM_LIMITTEXT, RES_MAXLEN, 0);
112 113
    SendDlgItemMessage(hDlg, IDC_DESKTOP_HEIGHT, EM_LIMITTEXT, RES_MAXLEN, 0);

114
    buf = getConfigValue("x11drv", "DXGrab", "Y");
115
    if (IS_OPTION_TRUE(*buf))
116
	CheckDlgButton(hDlg, IDC_DX_MOUSE_GRAB, BST_CHECKED);
117
    else
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
	CheckDlgButton(hDlg, IDC_DX_MOUSE_GRAB, BST_UNCHECKED);
    free(buf);

    buf = getConfigValue("x11drv", "DesktopDoubleBuffered", "Y");
    if (IS_OPTION_TRUE(*buf))
	CheckDlgButton(hDlg, IDC_DOUBLE_BUFFER, BST_CHECKED);
    else
	CheckDlgButton(hDlg, IDC_DOUBLE_BUFFER, BST_UNCHECKED);
    free(buf);
    
    buf = getConfigValue("x11drv", "UseTakeFocus", "N");
    if (IS_OPTION_TRUE(*buf))
	CheckDlgButton(hDlg, IDC_USE_TAKE_FOCUS, BST_CHECKED);
    else
	CheckDlgButton(hDlg, IDC_USE_TAKE_FOCUS, BST_UNCHECKED);
    free(buf);
134 135 136
    
    updatingUI = FALSE;
}
137 138 139



140 141 142 143
void setFromDesktopSizeEdits(HWND hDlg) {
    char *width = malloc(RES_MAXLEN+1);
    char *height = malloc(RES_MAXLEN+1);
    char *newStr = malloc((RES_MAXLEN*2) + 2);
144

145 146 147 148 149 150
    if (updatingUI) return;
    
    WINE_TRACE("\n");
    
    GetWindowText(GetDlgItem(hDlg, IDC_DESKTOP_WIDTH), width, RES_MAXLEN+1);
    GetWindowText(GetDlgItem(hDlg, IDC_DESKTOP_HEIGHT), height, RES_MAXLEN+1);
151

152 153 154 155 156
    if (strcmp(width, "") == 0) strcpy(width, "640");
    if (strcmp(height, "") == 0) strcpy(height, "480");
    
    sprintf(newStr, "%sx%s", width, height);
    addTransaction("x11drv", "Desktop", ACTION_SET, newStr);
157

158 159 160
    free(width);
    free(height);
    free(newStr);
161 162
}

163 164 165 166 167 168 169 170 171 172 173
void onEnableDesktopClicked(HWND hDlg) {
    WINE_TRACE("\n");
    if (IsDlgButtonChecked(hDlg, IDC_ENABLE_DESKTOP) == BST_CHECKED) {
	/* it was just unchecked, so read the values of the edit boxes, set the config value */
	setFromDesktopSizeEdits(hDlg);
    } else {
	/* it was just checked, so remove the config values */
	addTransaction("x11drv", "Desktop", ACTION_REMOVE, NULL);
    }
    updateGUIForDesktopMode(hDlg);
}
174

175 176 177
void onScreenDepthChanged(HWND hDlg) {
    char *newvalue = getDialogItemText(hDlg, IDC_SCREEN_DEPTH);
    char *spaceIndex = strchr(newvalue, ' ');
178
    
179
    WINE_TRACE("newvalue=%s\n", newvalue);
180 181
    if (updatingUI) return;

182 183
    *spaceIndex = '\0';
    addTransaction("x11drv", "ScreenDepth", ACTION_SET, newvalue);
184 185 186
    free(newvalue);
}

187 188 189
void onDXMouseGrabClicked(HWND hDlg) {
    if (IsDlgButtonChecked(hDlg, IDC_DX_MOUSE_GRAB) == BST_CHECKED)
	addTransaction("x11drv", "DXGrab", ACTION_SET, "Y");
190
    else
191
	addTransaction("x11drv", "DXGrab", ACTION_SET, "N");
192 193
}

194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209

void onDoubleBufferClicked(HWND hDlg) {
    if (IsDlgButtonChecked(hDlg, IDC_DOUBLE_BUFFER) == BST_CHECKED)
	addTransaction("x11drv", "DesktopDoubleBuffered", ACTION_SET, "Y");
    else
	addTransaction("x11drv", "DesktopDoubleBuffered", ACTION_SET, "N");
}

void onUseTakeFocusClicked(HWND hDlg) {
    if (IsDlgButtonChecked(hDlg, IDC_USE_TAKE_FOCUS) == BST_CHECKED)
	addTransaction("x11drv", "UseTakeFocus", ACTION_SET, "Y");
    else
	addTransaction("x11drv", "UseTakeFocus", ACTION_SET, "N");
}


210 211 212 213 214 215
INT_PTR CALLBACK
X11DrvDlgProc (HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    switch (uMsg) {
	case WM_INITDIALOG:
	    break;
216
	    
217 218 219 220
	case WM_COMMAND:
	    switch(HIWORD(wParam)) {
		case EN_CHANGE: {
		    SendMessage(GetParent(hDlg), PSM_CHANGED, 0, 0);
221
		    if ( (LOWORD(wParam) == IDC_DESKTOP_WIDTH) || (LOWORD(wParam) == IDC_DESKTOP_HEIGHT) ) setFromDesktopSizeEdits(hDlg);
222 223
		    break;
		}
224
		case BN_CLICKED: {
225
		    WINE_TRACE("%d\n", LOWORD(wParam));
226 227
		    switch(LOWORD(wParam)) {
			case IDC_ENABLE_DESKTOP: onEnableDesktopClicked(hDlg); break;
228 229 230
			case IDC_DX_MOUSE_GRAB:  onDXMouseGrabClicked(hDlg); break;
			case IDC_USE_TAKE_FOCUS: onUseTakeFocusClicked(hDlg); break;
			case IDC_DOUBLE_BUFFER:  onDoubleBufferClicked(hDlg); break;
231 232 233
		    };
		    break;
		}
234 235 236 237
		case CBN_SELCHANGE: {
		    if (LOWORD(wParam) == IDC_SCREEN_DEPTH) onScreenDepthChanged(hDlg);
		    break;
		}
238
		    
239 240 241 242
		default:
		    break;
	    }
	    break;
243 244
	
	
245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266
	case WM_NOTIFY:
	    switch (((LPNMHDR)lParam)->code) {
		case PSN_KILLACTIVE: {
		    SetWindowLong(hDlg, DWL_MSGRESULT, FALSE);
		    break;
		}
		case PSN_APPLY: {
		    SetWindowLong(hDlg, DWL_MSGRESULT, PSNRET_NOERROR);
		    break;
		}
		case PSN_SETACTIVE: {
		    initX11DrvDlg (hDlg);
		    break;
		}
	    }
	    break;

	default:
	    break;
    }
    return FALSE;
}