2003-08-30 00:40:46 +00:00
/*
2004-07-30 01:35:13 +00:00
* Graphics configuration code
2003-08-30 00:40:46 +00:00
*
* Copyright 2003 Mark Westcott
2004-09-28 03:16:43 +00:00
* Copyright 2003 - 2004 Mike Hearn
2005-07-12 18:11:11 +00:00
* Copyright 2005 Raphael Junqueira
2003-08-30 00:40:46 +00:00
*
* 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
2006-05-18 12:49:52 +00:00
* Foundation , Inc . , 51 Franklin St , Fifth Floor , Boston , MA 02110 - 1301 , USA
2003-08-30 00:40:46 +00:00
*
*/
2006-01-19 10:55:01 +00:00
# define WIN32_LEAN_AND_MEAN
2003-09-05 23:08:26 +00:00
# include <stdarg.h>
2003-08-30 00:40:46 +00:00
# include <stdlib.h>
# include <stdio.h>
2006-01-19 10:55:01 +00:00
# include <windows.h>
2003-09-05 23:08:26 +00:00
# include <wine/debug.h>
2003-08-30 00:40:46 +00:00
# include "resource.h"
# include "winecfg.h"
WINE_DEFAULT_DEBUG_CHANNEL ( winecfg ) ;
2003-09-08 18:58:07 +00: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? */
2005-07-12 18:11:11 +00:00
2006-08-18 15:59:39 +00:00
static struct SHADERMODE
{
UINT displayStrID ;
const char * settingStr ;
} const D3D_VS_Modes [ ] = {
{ IDS_SHADER_MODE_HARDWARE , " hardware " } ,
{ IDS_SHADER_MODE_EMULATION , " emulation " } ,
{ IDS_SHADER_MODE_NONE , " none " } ,
{ 0 , 0 }
2005-07-12 18:11:11 +00:00
} ;
2004-09-28 03:55:16 +00:00
int updating_ui ;
2003-09-08 18:58:07 +00:00
2005-06-02 15:11:32 +00:00
static void update_gui_for_desktop_mode ( HWND dialog ) {
2005-10-18 10:35:41 +00:00
int desktopenabled = FALSE ;
2003-09-08 18:58:07 +00:00
2005-10-18 10:35:41 +00:00
WINE_TRACE ( " \n " ) ;
2004-09-28 03:55:16 +00:00
updating_ui = TRUE ;
2006-03-29 11:49:36 +00:00
if ( current_app )
{
disable ( IDC_ENABLE_DESKTOP ) ;
disable ( IDC_DESKTOP_WIDTH ) ;
disable ( IDC_DESKTOP_HEIGHT ) ;
disable ( IDC_DESKTOP_SIZE ) ;
disable ( IDC_DESKTOP_BY ) ;
return ;
}
enable ( IDC_ENABLE_DESKTOP ) ;
2003-09-08 18:58:07 +00:00
/* do we have desktop mode enabled? */
2005-06-23 11:42:54 +00:00
if ( reg_key_exists ( config_key , keypath ( " X11 Driver " ) , " Desktop " ) )
2004-09-28 03:55:16 +00:00
{
2005-01-14 19:48:41 +00:00
char * buf , * bufindex ;
2003-09-30 00:27:55 +00:00
CheckDlgButton ( dialog , IDC_ENABLE_DESKTOP , BST_CHECKED ) ;
2005-01-14 19:48:41 +00:00
2005-06-23 11:42:54 +00:00
buf = get_reg_key ( config_key , keypath ( " X11 Driver " ) , " Desktop " , " 640x480 " ) ;
2005-10-18 10:35:41 +00:00
/* 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 {
2006-10-05 09:11:03 +00:00
WINE_TRACE ( " Desktop registry entry is malformed \n " ) ;
2005-10-18 10:35:41 +00:00
SetWindowText ( GetDlgItem ( dialog , IDC_DESKTOP_WIDTH ) , " 640 " ) ;
SetWindowText ( GetDlgItem ( dialog , IDC_DESKTOP_HEIGHT ) , " 480 " ) ;
}
2005-01-14 19:48:41 +00:00
}
HeapFree ( GetProcessHeap ( ) , 0 , buf ) ;
2003-09-08 18:58:07 +00:00
}
2005-10-18 10:35:41 +00:00
if ( ! desktopenabled )
2004-09-28 03:55:16 +00:00
{
2003-09-30 00:27:55 +00:00
CheckDlgButton ( dialog , IDC_ENABLE_DESKTOP , BST_UNCHECKED ) ;
2004-09-28 03:55:16 +00:00
2003-09-30 00:27:55 +00:00
disable ( IDC_DESKTOP_WIDTH ) ;
disable ( IDC_DESKTOP_HEIGHT ) ;
disable ( IDC_DESKTOP_SIZE ) ;
disable ( IDC_DESKTOP_BY ) ;
2003-09-08 18:58:07 +00:00
2003-09-30 00:27:55 +00:00
SetWindowText ( GetDlgItem ( dialog , IDC_DESKTOP_WIDTH ) , " " ) ;
SetWindowText ( GetDlgItem ( dialog , IDC_DESKTOP_HEIGHT ) , " " ) ;
2003-09-08 18:58:07 +00:00
}
2004-09-28 03:55:16 +00:00
updating_ui = FALSE ;
2003-09-08 18:58:07 +00:00
}
2005-09-26 09:51:48 +00:00
static void init_dialog ( HWND dialog )
{
unsigned int it ;
char * buf ;
update_gui_for_desktop_mode ( dialog ) ;
updating_ui = TRUE ;
2004-09-28 04:05:55 +00:00
SendDlgItemMessage ( dialog , IDC_DESKTOP_WIDTH , EM_LIMITTEXT , RES_MAXLEN , 0 ) ;
SendDlgItemMessage ( dialog , IDC_DESKTOP_HEIGHT , EM_LIMITTEXT , RES_MAXLEN , 0 ) ;
2003-09-18 04:32:01 +00:00
2005-12-31 12:32:59 +00:00
buf = get_reg_key ( config_key , keypath ( " X11 Driver " ) , " DXGrab " , " N " ) ;
2003-09-18 04:32:01 +00:00
if ( IS_OPTION_TRUE ( * buf ) )
2004-09-28 04:05:55 +00:00
CheckDlgButton ( dialog , IDC_DX_MOUSE_GRAB , BST_CHECKED ) ;
2003-09-18 04:32:01 +00:00
else
2004-09-28 04:05:55 +00:00
CheckDlgButton ( dialog , IDC_DX_MOUSE_GRAB , BST_UNCHECKED ) ;
2004-09-28 03:55:16 +00:00
HeapFree ( GetProcessHeap ( ) , 0 , buf ) ;
2003-09-22 21:13:51 +00:00
2005-12-22 10:15:32 +00:00
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 ) ;
2005-07-12 18:11:11 +00:00
SendDlgItemMessage ( dialog , IDC_D3D_VSHADER_MODE , CB_RESETCONTENT , 0 , 0 ) ;
2006-08-18 15:59:39 +00:00
for ( it = 0 ; 0 ! = D3D_VS_Modes [ it ] . displayStrID ; + + it ) {
SendDlgItemMessageW ( dialog , IDC_D3D_VSHADER_MODE , CB_ADDSTRING , 0 ,
( LPARAM ) load_string ( D3D_VS_Modes [ it ] . displayStrID ) ) ;
2005-07-12 18:11:11 +00:00
}
buf = get_reg_key ( config_key , keypath ( " Direct3D " ) , " VertexShaderMode " , " hardware " ) ;
2006-08-18 15:59:39 +00:00
for ( it = 0 ; NULL ! = D3D_VS_Modes [ it ] . settingStr ; + + it ) {
if ( strcmp ( buf , D3D_VS_Modes [ it ] . settingStr ) = = 0 ) {
2005-07-12 18:11:11 +00:00
SendDlgItemMessage ( dialog , IDC_D3D_VSHADER_MODE , CB_SETCURSEL , it , 0 ) ;
break ;
}
}
2006-08-18 15:59:39 +00:00
if ( NULL = = D3D_VS_Modes [ it ] . settingStr ) {
2005-07-12 18:11:11 +00:00
WINE_ERR ( " Invalid Direct3D VertexShader Mode read from registry (%s) \n " , buf ) ;
}
HeapFree ( GetProcessHeap ( ) , 0 , buf ) ;
2006-09-26 18:31:44 +00:00
buf = get_reg_key ( config_key , keypath ( " Direct3D " ) , " PixelShaderMode " , " enabled " ) ;
2005-07-12 18:11:11 +00:00
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 ) ;
2004-09-28 03:55:16 +00:00
updating_ui = FALSE ;
2003-09-08 18:58:07 +00:00
}
2003-08-30 00:40:46 +00:00
2004-09-28 04:05:55 +00:00
static void set_from_desktop_edits ( HWND dialog ) {
char * width , * height , * new ;
2003-08-30 00:40:46 +00:00
2004-09-28 04:05:55 +00:00
if ( updating_ui ) return ;
2003-09-08 18:58:07 +00:00
WINE_TRACE ( " \n " ) ;
2003-08-30 00:40:46 +00:00
2004-11-23 13:50:23 +00:00
width = get_text ( dialog , IDC_DESKTOP_WIDTH ) ;
height = get_text ( dialog , IDC_DESKTOP_HEIGHT ) ;
2004-09-28 04:05:55 +00:00
2005-01-14 19:48:41 +00:00
if ( width = = NULL | | strcmp ( width , " " ) = = 0 ) {
2004-09-28 04:05:55 +00:00
HeapFree ( GetProcessHeap ( ) , 0 , width ) ;
width = strdupA ( " 640 " ) ;
}
2003-09-08 18:58:07 +00:00
2005-01-14 19:48:41 +00:00
if ( height = = NULL | | strcmp ( height , " " ) = = 0 ) {
2004-09-28 04:05:55 +00:00
HeapFree ( GetProcessHeap ( ) , 0 , height ) ;
height = strdupA ( " 480 " ) ;
}
new = HeapAlloc ( GetProcessHeap ( ) , 0 , strlen ( width ) + strlen ( height ) + 2 /* x + terminator */ ) ;
2004-09-28 03:55:16 +00:00
sprintf ( new , " %sx%s " , width , height ) ;
2005-06-23 11:42:54 +00:00
set_reg_key ( config_key , keypath ( " X11 Driver " ) , " Desktop " , new ) ;
2004-09-28 03:55:16 +00:00
HeapFree ( GetProcessHeap ( ) , 0 , width ) ;
HeapFree ( GetProcessHeap ( ) , 0 , height ) ;
HeapFree ( GetProcessHeap ( ) , 0 , new ) ;
2003-08-30 00:40:46 +00:00
}
2005-06-02 15:11:32 +00:00
static void on_enable_desktop_clicked ( HWND dialog ) {
2003-09-08 18:58:07 +00:00
WINE_TRACE ( " \n " ) ;
2004-09-28 04:05:55 +00:00
if ( IsDlgButtonChecked ( dialog , IDC_ENABLE_DESKTOP ) = = BST_CHECKED ) {
2005-01-14 19:48:41 +00:00
set_from_desktop_edits ( dialog ) ;
2003-09-08 18:58:07 +00:00
} else {
2005-06-23 11:42:54 +00:00
set_reg_key ( config_key , keypath ( " X11 Driver " ) , " Desktop " , NULL ) ;
2003-09-08 18:58:07 +00:00
}
2004-09-28 04:05:55 +00:00
update_gui_for_desktop_mode ( dialog ) ;
2003-09-08 18:58:07 +00:00
}
2003-09-18 04:32:01 +00:00
2005-12-22 10:15:32 +00:00
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 " ) ;
}
}
2004-09-28 04:05:55 +00:00
static void on_dx_mouse_grab_clicked ( HWND dialog ) {
2005-01-14 19:48:41 +00:00
if ( IsDlgButtonChecked ( dialog , IDC_DX_MOUSE_GRAB ) = = BST_CHECKED )
2005-06-23 11:42:54 +00:00
set_reg_key ( config_key , keypath ( " X11 Driver " ) , " DXGrab " , " Y " ) ;
2003-09-18 04:32:01 +00:00
else
2005-06-23 11:42:54 +00:00
set_reg_key ( config_key , keypath ( " X11 Driver " ) , " DXGrab " , " N " ) ;
2003-09-18 04:32:01 +00:00
}
2005-07-12 18:11:11 +00:00
static void on_d3d_vshader_mode_changed ( HWND dialog ) {
int selected_mode = SendDlgItemMessage ( dialog , IDC_D3D_VSHADER_MODE , CB_GETCURSEL , 0 , 0 ) ;
2006-08-18 15:59:39 +00:00
set_reg_key ( config_key , keypath ( " Direct3D " ) , " VertexShaderMode " ,
D3D_VS_Modes [ selected_mode ] . settingStr ) ;
2005-07-12 18:11:11 +00:00
}
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 " ) ;
}
2003-08-30 00:40:46 +00:00
INT_PTR CALLBACK
2005-09-26 09:51:48 +00:00
GraphDlgProc ( HWND hDlg , UINT uMsg , WPARAM wParam , LPARAM lParam )
2003-08-30 00:40:46 +00:00
{
switch ( uMsg ) {
case WM_INITDIALOG :
break ;
2004-09-28 03:55:16 +00:00
case WM_SHOWWINDOW :
set_window_title ( hDlg ) ;
break ;
2003-08-30 00:40:46 +00:00
case WM_COMMAND :
switch ( HIWORD ( wParam ) ) {
case EN_CHANGE : {
2005-01-14 19:48:41 +00:00
if ( updating_ui ) break ;
2003-08-30 00:40:46 +00:00
SendMessage ( GetParent ( hDlg ) , PSM_CHANGED , 0 , 0 ) ;
2004-09-28 03:55:16 +00:00
if ( ( ( LOWORD ( wParam ) = = IDC_DESKTOP_WIDTH ) | | ( LOWORD ( wParam ) = = IDC_DESKTOP_HEIGHT ) ) & & ! updating_ui )
2004-09-28 04:05:55 +00:00
set_from_desktop_edits ( hDlg ) ;
2003-08-30 00:40:46 +00:00
break ;
}
2003-09-08 18:58:07 +00:00
case BN_CLICKED : {
2004-09-28 03:55:16 +00:00
if ( updating_ui ) break ;
2005-01-14 19:48:41 +00:00
SendMessage ( GetParent ( hDlg ) , PSM_CHANGED , 0 , 0 ) ;
2003-09-08 18:58:07 +00:00
switch ( LOWORD ( wParam ) ) {
2004-09-28 04:05:55 +00:00
case IDC_ENABLE_DESKTOP : on_enable_desktop_clicked ( hDlg ) ; break ;
2005-12-22 10:15:32 +00:00
case IDC_ENABLE_MANAGED : on_enable_managed_clicked ( hDlg ) ; break ;
2004-09-28 04:05:55 +00:00
case IDC_DX_MOUSE_GRAB : on_dx_mouse_grab_clicked ( hDlg ) ; break ;
2005-07-12 18:11:11 +00:00
case IDC_D3D_PSHADER_MODE : on_d3d_pshader_mode_clicked ( hDlg ) ; break ;
2004-09-28 04:05:55 +00:00
}
2003-09-08 18:58:07 +00:00
break ;
}
2003-09-22 19:26:10 +00:00
case CBN_SELCHANGE : {
2005-01-14 19:48:41 +00:00
SendMessage ( GetParent ( hDlg ) , PSM_CHANGED , 0 , 0 ) ;
2005-07-12 18:11:11 +00:00
switch ( LOWORD ( wParam ) ) {
case IDC_D3D_VSHADER_MODE : on_d3d_vshader_mode_changed ( hDlg ) ; break ;
}
2003-09-22 19:26:10 +00:00
break ;
}
2003-09-08 18:58:07 +00:00
2003-08-30 00:40:46 +00:00
default :
break ;
}
break ;
2003-09-08 18:58:07 +00:00
2003-08-30 00:40:46 +00:00
case WM_NOTIFY :
switch ( ( ( LPNMHDR ) lParam ) - > code ) {
case PSN_KILLACTIVE : {
2005-02-15 21:51:06 +00:00
SetWindowLongPtr ( hDlg , DWLP_MSGRESULT , FALSE ) ;
2003-08-30 00:40:46 +00:00
break ;
}
case PSN_APPLY : {
2004-09-28 03:55:16 +00:00
apply ( ) ;
2005-02-15 21:51:06 +00:00
SetWindowLongPtr ( hDlg , DWLP_MSGRESULT , PSNRET_NOERROR ) ;
2003-08-30 00:40:46 +00:00
break ;
}
case PSN_SETACTIVE : {
2004-09-28 04:05:55 +00:00
init_dialog ( hDlg ) ;
2003-08-30 00:40:46 +00:00
break ;
}
}
break ;
default :
break ;
}
return FALSE ;
}