2003-08-30 02:40:46 +02:00
/*
* 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
*
*/
2003-09-06 01:08:26 +02:00
# include <stdarg.h>
2003-08-30 02:40:46 +02:00
# include <stdlib.h>
# include <stdio.h>
2003-09-06 01:08:26 +02:00
# include <windef.h>
# include <winbase.h>
# include <winreg.h>
# include <wine/debug.h>
2003-08-30 02:40:46 +02:00
# include "resource.h"
# include "winecfg.h"
WINE_DEFAULT_DEBUG_CHANNEL ( winecfg ) ;
2003-09-08 20:58:07 +02:00
# 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? */
2003-09-30 02:27:55 +02:00
# define section (appSettings == EDITING_GLOBAL ? "x11drv" : (getSectionForApp("x11drv")))
2003-09-08 20:58:07 +02:00
int updatingUI ;
2004-02-07 02:01:34 +01:00
int appSettings = EDITING_GLOBAL ; /* start by editing global */
char * currentApp ; /* the app we are currently editing, or NULL if editing global */
char * getSectionForApp ( char * pSection )
{
static char * lastResult = NULL ;
if ( lastResult ) HeapFree ( GetProcessHeap ( ) , 0 , lastResult ) ;
lastResult = HeapAlloc ( GetProcessHeap ( ) , 0 , strlen ( " AppDefaults \\ " ) + strlen ( currentApp ) + 2 /* \\ */ + strlen ( pSection ) + 1 /* terminator */ ) ;
sprintf ( lastResult , " AppDefaults \\ %s \\ %s " , currentApp , pSection ) ;
return lastResult ;
}
2003-09-30 02:27:55 +02:00
void updateGUIForDesktopMode ( HWND dialog ) {
2003-09-08 20:58:07 +02:00
WINE_TRACE ( " \n " ) ;
updatingUI = TRUE ;
/* do we have desktop mode enabled? */
2003-10-22 02:01:46 +02:00
if ( doesConfigValueExist ( section , " Desktop " ) = = S_OK ) {
2003-09-30 02:27:55 +02:00
CheckDlgButton ( dialog , IDC_ENABLE_DESKTOP , BST_CHECKED ) ;
2003-09-08 20:58:07 +02:00
/* enable the controls */
2003-09-30 02:27:55 +02:00
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 " ) ;
2003-09-08 20:58:07 +02:00
}
else {
2003-09-30 02:27:55 +02:00
CheckDlgButton ( dialog , IDC_ENABLE_DESKTOP , BST_UNCHECKED ) ;
2003-09-08 20:58:07 +02:00
/* disable the controls */
2003-09-30 02:27:55 +02:00
disable ( IDC_DESKTOP_WIDTH ) ;
disable ( IDC_DESKTOP_HEIGHT ) ;
disable ( IDC_DESKTOP_SIZE ) ;
disable ( IDC_DESKTOP_BY ) ;
2003-09-08 20:58:07 +02:00
2003-09-30 02:27:55 +02:00
SetWindowText ( GetDlgItem ( dialog , IDC_DESKTOP_WIDTH ) , " " ) ;
SetWindowText ( GetDlgItem ( dialog , IDC_DESKTOP_HEIGHT ) , " " ) ;
2003-09-08 20:58:07 +02:00
}
updatingUI = FALSE ;
}
2003-08-30 02:40:46 +02:00
/* pokes the win32 api to setup the dialog from the config struct */
void initX11DrvDlg ( HWND hDlg )
{
2003-09-08 20:58:07 +02:00
char * buf ;
2003-09-22 21:26:10 +02:00
char * bufindex ;
2003-09-08 20:58:07 +02:00
updateGUIForDesktopMode ( hDlg ) ;
2003-10-22 02:01:46 +02:00
updatingUI = TRUE ;
2003-09-08 20:58:07 +02:00
/* desktop size */
2003-10-22 02:01:46 +02:00
buf = getConfigValue ( section , " Desktop " , " 640x480 " ) ;
2003-09-22 21:26:10 +02:00
bufindex = strchr ( buf , ' x ' ) ;
* bufindex = ' \0 ' ;
bufindex + + ;
2003-09-08 20:58:07 +02:00
SetWindowText ( GetDlgItem ( hDlg , IDC_DESKTOP_WIDTH ) , buf ) ;
2003-09-22 21:26:10 +02:00
SetWindowText ( GetDlgItem ( hDlg , IDC_DESKTOP_HEIGHT ) , bufindex ) ;
free ( buf ) ;
2003-10-22 02:01:46 +02:00
SendDlgItemMessage ( hDlg , IDC_SCREEN_DEPTH , CB_RESETCONTENT , 0 , 0 ) ;
2003-09-22 21:26:10 +02:00
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? */
2003-10-22 02:01:46 +02:00
buf = getConfigValue ( section , " ScreenDepth " , " 24 " ) ;
2003-09-22 21:26:10 +02:00
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 ) ;
2003-09-08 20:58:07 +02:00
free ( buf ) ;
SendDlgItemMessage ( hDlg , IDC_DESKTOP_WIDTH , EM_LIMITTEXT , RES_MAXLEN , 0 ) ;
2003-09-18 06:32:01 +02:00
SendDlgItemMessage ( hDlg , IDC_DESKTOP_HEIGHT , EM_LIMITTEXT , RES_MAXLEN , 0 ) ;
2003-10-22 02:01:46 +02:00
buf = getConfigValue ( section , " DXGrab " , " Y " ) ;
2003-09-18 06:32:01 +02:00
if ( IS_OPTION_TRUE ( * buf ) )
2003-09-22 23:13:51 +02:00
CheckDlgButton ( hDlg , IDC_DX_MOUSE_GRAB , BST_CHECKED ) ;
2003-09-18 06:32:01 +02:00
else
2003-09-22 23:13:51 +02:00
CheckDlgButton ( hDlg , IDC_DX_MOUSE_GRAB , BST_UNCHECKED ) ;
free ( buf ) ;
2003-10-22 02:01:46 +02:00
buf = getConfigValue ( section , " DesktopDoubleBuffered " , " Y " ) ;
2003-09-22 23:13:51 +02:00
if ( IS_OPTION_TRUE ( * buf ) )
CheckDlgButton ( hDlg , IDC_DOUBLE_BUFFER , BST_CHECKED ) ;
else
CheckDlgButton ( hDlg , IDC_DOUBLE_BUFFER , BST_UNCHECKED ) ;
free ( buf ) ;
2003-10-22 02:01:46 +02:00
buf = getConfigValue ( section , " UseTakeFocus " , " N " ) ;
2003-09-22 23:13:51 +02:00
if ( IS_OPTION_TRUE ( * buf ) )
CheckDlgButton ( hDlg , IDC_USE_TAKE_FOCUS , BST_CHECKED ) ;
else
CheckDlgButton ( hDlg , IDC_USE_TAKE_FOCUS , BST_UNCHECKED ) ;
free ( buf ) ;
2003-09-08 20:58:07 +02:00
updatingUI = FALSE ;
}
2003-08-30 02:40:46 +02:00
2003-09-08 20:58:07 +02:00
void setFromDesktopSizeEdits ( HWND hDlg ) {
char * width = malloc ( RES_MAXLEN + 1 ) ;
char * height = malloc ( RES_MAXLEN + 1 ) ;
char * newStr = malloc ( ( RES_MAXLEN * 2 ) + 2 ) ;
2003-08-30 02:40:46 +02:00
2003-09-08 20:58:07 +02:00
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 ) ;
2003-08-30 02:40:46 +02:00
2003-09-08 20:58:07 +02:00
if ( strcmp ( width , " " ) = = 0 ) strcpy ( width , " 640 " ) ;
if ( strcmp ( height , " " ) = = 0 ) strcpy ( height , " 480 " ) ;
sprintf ( newStr , " %sx%s " , width , height ) ;
2003-10-22 02:01:46 +02:00
addTransaction ( section , " Desktop " , ACTION_SET , newStr ) ;
2003-08-30 02:40:46 +02:00
2003-09-08 20:58:07 +02:00
free ( width ) ;
free ( height ) ;
free ( newStr ) ;
2003-08-30 02:40:46 +02:00
}
2003-09-08 20:58:07 +02:00
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 */
2003-10-22 02:01:46 +02:00
addTransaction ( section , " Desktop " , ACTION_REMOVE , NULL ) ;
2003-09-08 20:58:07 +02:00
}
updateGUIForDesktopMode ( hDlg ) ;
}
2003-09-18 06:32:01 +02:00
2003-09-22 21:26:10 +02:00
void onScreenDepthChanged ( HWND hDlg ) {
char * newvalue = getDialogItemText ( hDlg , IDC_SCREEN_DEPTH ) ;
char * spaceIndex = strchr ( newvalue , ' ' ) ;
2003-09-08 20:58:07 +02:00
2003-09-22 21:26:10 +02:00
WINE_TRACE ( " newvalue=%s \n " , newvalue ) ;
2003-09-18 06:32:01 +02:00
if ( updatingUI ) return ;
2003-09-22 21:26:10 +02:00
* spaceIndex = ' \0 ' ;
2003-10-22 02:01:46 +02:00
addTransaction ( section , " ScreenDepth " , ACTION_SET , newvalue ) ;
2003-09-18 06:32:01 +02:00
free ( newvalue ) ;
}
2003-09-22 23:13:51 +02:00
void onDXMouseGrabClicked ( HWND hDlg ) {
if ( IsDlgButtonChecked ( hDlg , IDC_DX_MOUSE_GRAB ) = = BST_CHECKED )
2003-10-22 02:01:46 +02:00
addTransaction ( section , " DXGrab " , ACTION_SET , " Y " ) ;
2003-09-18 06:32:01 +02:00
else
2003-10-22 02:01:46 +02:00
addTransaction ( section , " DXGrab " , ACTION_SET , " N " ) ;
2003-09-18 06:32:01 +02:00
}
2003-09-22 23:13:51 +02:00
void onDoubleBufferClicked ( HWND hDlg ) {
if ( IsDlgButtonChecked ( hDlg , IDC_DOUBLE_BUFFER ) = = BST_CHECKED )
2003-10-22 02:01:46 +02:00
addTransaction ( section , " DesktopDoubleBuffered " , ACTION_SET , " Y " ) ;
2003-09-22 23:13:51 +02:00
else
2003-10-22 02:01:46 +02:00
addTransaction ( section , " DesktopDoubleBuffered " , ACTION_SET , " N " ) ;
2003-09-22 23:13:51 +02:00
}
void onUseTakeFocusClicked ( HWND hDlg ) {
if ( IsDlgButtonChecked ( hDlg , IDC_USE_TAKE_FOCUS ) = = BST_CHECKED )
2003-10-22 02:01:46 +02:00
addTransaction ( section , " UseTakeFocus " , ACTION_SET , " Y " ) ;
2003-09-22 23:13:51 +02:00
else
2003-10-22 02:01:46 +02:00
addTransaction ( section , " UseTakeFocus " , ACTION_SET , " N " ) ;
2003-09-22 23:13:51 +02:00
}
2003-08-30 02:40:46 +02:00
INT_PTR CALLBACK
X11DrvDlgProc ( HWND hDlg , UINT uMsg , WPARAM wParam , LPARAM lParam )
{
switch ( uMsg ) {
case WM_INITDIALOG :
break ;
2003-09-08 20:58:07 +02:00
2003-08-30 02:40:46 +02:00
case WM_COMMAND :
switch ( HIWORD ( wParam ) ) {
case EN_CHANGE : {
SendMessage ( GetParent ( hDlg ) , PSM_CHANGED , 0 , 0 ) ;
2003-10-22 02:01:46 +02:00
if ( ( ( LOWORD ( wParam ) = = IDC_DESKTOP_WIDTH ) | | ( LOWORD ( wParam ) = = IDC_DESKTOP_HEIGHT ) ) & & ! updatingUI )
setFromDesktopSizeEdits ( hDlg ) ;
2003-08-30 02:40:46 +02:00
break ;
}
2003-09-08 20:58:07 +02:00
case BN_CLICKED : {
2003-10-22 02:01:46 +02:00
if ( updatingUI ) break ;
2003-09-08 20:58:07 +02:00
switch ( LOWORD ( wParam ) ) {
case IDC_ENABLE_DESKTOP : onEnableDesktopClicked ( hDlg ) ; break ;
2003-09-22 23:13:51 +02:00
case IDC_DX_MOUSE_GRAB : onDXMouseGrabClicked ( hDlg ) ; break ;
case IDC_USE_TAKE_FOCUS : onUseTakeFocusClicked ( hDlg ) ; break ;
case IDC_DOUBLE_BUFFER : onDoubleBufferClicked ( hDlg ) ; break ;
2003-09-08 20:58:07 +02:00
} ;
break ;
}
2003-09-22 21:26:10 +02:00
case CBN_SELCHANGE : {
if ( LOWORD ( wParam ) = = IDC_SCREEN_DEPTH ) onScreenDepthChanged ( hDlg ) ;
break ;
}
2003-09-08 20:58:07 +02:00
2003-08-30 02:40:46 +02:00
default :
break ;
}
break ;
2003-09-08 20:58:07 +02:00
2003-08-30 02:40:46 +02:00
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 ;
}