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? */
int updatingUI ;
void updateGUIForDesktopMode ( HWND hDlg ) {
WINE_TRACE ( " \n " ) ;
updatingUI = TRUE ;
/* do we have desktop mode enabled? */
if ( doesConfigValueExist ( " x11drv " , " Desktop " ) = = S_OK ) {
CheckDlgButton ( hDlg , IDC_ENABLE_DESKTOP , BST_CHECKED ) ;
/* enable the controls */
EnableWindow ( GetDlgItem ( hDlg , IDC_DESKTOP_WIDTH ) , 1 ) ;
EnableWindow ( GetDlgItem ( hDlg , IDC_DESKTOP_HEIGHT ) , 1 ) ;
EnableWindow ( GetDlgItem ( hDlg , IDC_DESKTOP_SIZE ) , 1 ) ;
EnableWindow ( GetDlgItem ( hDlg , IDC_DESKTOP_BY ) , 1 ) ;
SetWindowText ( GetDlgItem ( hDlg , IDC_DESKTOP_WIDTH ) , " 640 " ) ;
SetWindowText ( GetDlgItem ( hDlg , IDC_DESKTOP_HEIGHT ) , " 480 " ) ;
}
else {
CheckDlgButton ( hDlg , IDC_ENABLE_DESKTOP , BST_UNCHECKED ) ;
/* disable the controls */
EnableWindow ( GetDlgItem ( hDlg , IDC_DESKTOP_WIDTH ) , 0 ) ;
EnableWindow ( GetDlgItem ( hDlg , IDC_DESKTOP_HEIGHT ) , 0 ) ;
EnableWindow ( GetDlgItem ( hDlg , IDC_DESKTOP_SIZE ) , 0 ) ;
EnableWindow ( GetDlgItem ( hDlg , IDC_DESKTOP_BY ) , 0 ) ;
SetWindowText ( GetDlgItem ( hDlg , IDC_DESKTOP_WIDTH ) , " " ) ;
SetWindowText ( GetDlgItem ( hDlg , IDC_DESKTOP_HEIGHT ) , " " ) ;
}
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 ;
char * i ;
updatingUI = TRUE ;
updateGUIForDesktopMode ( hDlg ) ;
/* desktop size */
buf = getConfigValue ( " x11drv " , " Desktop " , " 640x480 " ) ;
i = strchr ( buf , ' x ' ) ;
* i = ' \0 ' ;
i + + ;
SetWindowText ( GetDlgItem ( hDlg , IDC_DESKTOP_WIDTH ) , buf ) ;
SetWindowText ( GetDlgItem ( hDlg , IDC_DESKTOP_HEIGHT ) , i ) ;
free ( buf ) ;
SendDlgItemMessage ( hDlg , IDC_DESKTOP_WIDTH , EM_LIMITTEXT , RES_MAXLEN , 0 ) ;
SendDlgItemMessage ( hDlg , IDC_DESKTOP_HEIGHT , EM_LIMITTEXT , RES_MAXLEN , 0 ) ;
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 ) ;
addTransaction ( " x11drv " , " 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 */
addTransaction ( " x11drv " , " Desktop " , ACTION_REMOVE , NULL ) ;
}
updateGUIForDesktopMode ( hDlg ) ;
}
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-09-08 20:58:07 +02:00
if ( ( LOWORD ( wParam ) = = IDC_DESKTOP_WIDTH ) | | ( LOWORD ( wParam ) = = IDC_DESKTOP_HEIGHT ) ) setFromDesktopSizeEdits ( hDlg ) ;
2003-08-30 02:40:46 +02:00
break ;
}
2003-09-08 20:58:07 +02:00
case BN_CLICKED : {
2003-09-08 21:38:45 +02:00
WINE_TRACE ( " %d \n " , LOWORD ( wParam ) ) ;
2003-09-08 20:58:07 +02:00
switch ( LOWORD ( wParam ) ) {
case IDC_ENABLE_DESKTOP : onEnableDesktopClicked ( hDlg ) ; break ;
} ;
break ;
}
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 ;
}