clean up dialog init

This commit is contained in:
ehouse 2004-05-26 04:46:57 +00:00
parent fa5bdc2457
commit 0a6a9de4cf
3 changed files with 87 additions and 89 deletions

View file

@ -17,8 +17,6 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifdef XWFEATURE_CE_EDITCOLORS
#include <Windowsx.h>
#include "stdafx.h"
#include <commdlg.h>
@ -133,7 +131,7 @@ updateForField( HWND hDlg, ClrEditDlgState* eState, XP_U16 fieldID )
}
} /* updateForField */
static LRESULT CALLBACK
LRESULT CALLBACK
EditColorsDlg( HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam )
{
ClrEditDlgState* eState;
@ -151,6 +149,9 @@ EditColorsDlg( HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam )
return TRUE;
} else {
eState = (ClrEditDlgState*)GetWindowLong( hDlg, GWL_USERDATA );
if ( !eState ) {
return FALSE;
}
if ( !eState->inited ) {
/* set to true first! Messages will be generated by
@ -350,44 +351,45 @@ ColorsDlg( HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam )
return TRUE;
} else {
cState = (ColorsDlgState*)GetWindowLong( hDlg, GWL_USERDATA );
if ( !!cState ) {
if ( !cState->inited ) {
initColorData( cState, hDlg );
cState->inited = XP_TRUE;
}
switch (message) {
case WM_CTLCOLORBTN: {
HDC hdcButton = (HDC)wParam;
HWND hwndButton = (HWND)lParam;
HBRUSH brush = brushForButton( cState, hwndButton );
/* if ( !!brush ) { */
/* SetSysColors( hdcButton ) */
/* } */
return (BOOL)brush;
}
case WM_COMMAND:
wid = LOWORD(wParam);
switch( wid ) {
case IDOK:
cState->cancelled = XP_FALSE;
/* fallthrough */
case IDCANCEL:
deleteButtonBrushes( cState );
EndDialog(hDlg, wid);
return TRUE;
default:
/* it's one of the color buttons. Set up with the
appropriate color and launch ChooseColor */
wrapChooseColor( cState, hDlg, wid );
return TRUE;
if ( !cState->inited ) {
initColorData( cState, hDlg );
cState->inited = XP_TRUE;
}
switch (message) {
case WM_CTLCOLORBTN: {
HDC hdcButton = (HDC)wParam;
HWND hwndButton = (HWND)lParam;
HBRUSH brush = brushForButton( cState, hwndButton );
/* if ( !!brush ) { */
/* SetSysColors( hdcButton ) */
/* } */
return (BOOL)brush;
}
case WM_COMMAND:
wid = LOWORD(wParam);
switch( wid ) {
case IDOK:
cState->cancelled = XP_FALSE;
/* fallthrough */
case IDCANCEL:
deleteButtonBrushes( cState );
EndDialog(hDlg, wid);
return TRUE;
default:
/* it's one of the color buttons. Set up with the
appropriate color and launch ChooseColor */
wrapChooseColor( cState, hDlg, wid );
return TRUE;
}
}
}
}
@ -415,5 +417,3 @@ ceDoColorsEdit( HWND hwnd, CEAppGlobals* globals, COLORREF* colors )
return !state.cancelled;
} /* ceDoColorsEdit */
#endif

View file

@ -109,10 +109,8 @@ loadStateFromCurPrefs( const CEAppPrefs* appPrefs, const CurGameInfo* gi,
prefsPrefs->showColors = appPrefs->showColors;
XP_MEMCPY( &prefsPrefs->cp, &appPrefs->cp, sizeof(prefsPrefs->cp) );
#ifdef XWFEATURE_CE_EDITCOLORS
XP_MEMCPY( &prefsPrefs->colors, &appPrefs->colors,
sizeof(prefsPrefs->colors) );
#endif
} /* loadStateFromCurPrefs */
void
@ -130,10 +128,8 @@ loadCurPrefsFromState( CEAppPrefs* appPrefs, CurGameInfo* gi,
appPrefs->showColors = prefsPrefs->showColors;
XP_MEMCPY( &appPrefs->cp, &prefsPrefs->cp, sizeof(appPrefs->cp) );
#ifdef XWFEATURE_CE_EDITCOLORS
XP_MEMCPY( &appPrefs->colors, &prefsPrefs->colors,
sizeof(prefsPrefs->colors) );
#endif
} /* loadCurPrefsFromState */
/* Reflect local state into the controls user will see.
@ -231,39 +227,39 @@ PrefsDlg(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
} else {
XP_Bool timerOn;
pState = (CePrefsDlgState*)GetWindowLong( hDlg, GWL_USERDATA );
globals = pState->globals;
if ( !!pState ) {
globals = pState->globals;
switch (message) {
case WM_COMMAND:
id = LOWORD(wParam);
switch( id ) {
switch (message) {
case WM_COMMAND:
id = LOWORD(wParam);
switch( id ) {
case IDC_RADIOGLOBAL:
case IDC_RADIOLOCAL:
pState->globals->doGlobalPrefs = id == IDC_RADIOGLOBAL;
adjustForChoice( hDlg, pState );
break;
case IDC_RADIOGLOBAL:
case IDC_RADIOLOCAL:
pState->globals->doGlobalPrefs = id == IDC_RADIOGLOBAL;
adjustForChoice( hDlg, pState );
break;
case TIMER_CHECK:
timerOn = SendDlgItemMessage( hDlg, TIMER_CHECK, BM_GETCHECK,
0, 0 );
setTimerCtls( hDlg, timerOn );
break;
#ifdef XWFEATURE_CE_EDITCOLORS
case IDC_PREFCOLORS:
pState->colorsChanged =
ceDoColorsEdit( hDlg, pState->globals,
pState->prefsPrefs.colors );
break;
#endif
case IDOK:
ceControlsToPrefs( hDlg, &pState->prefsPrefs );
case IDCANCEL:
EndDialog(hDlg, id);
pState->userCancelled = id == IDCANCEL;
return TRUE;
}
}
case TIMER_CHECK:
timerOn = SendDlgItemMessage( hDlg, TIMER_CHECK, BM_GETCHECK,
0, 0 );
setTimerCtls( hDlg, timerOn );
break;
case IDC_PREFCOLORS:
pState->colorsChanged =
ceDoColorsEdit( hDlg, pState->globals,
pState->prefsPrefs.colors );
break;
case IDOK:
ceControlsToPrefs( hDlg, &pState->prefsPrefs );
case IDCANCEL:
EndDialog(hDlg, id);
pState->userCancelled = id == IDCANCEL;
return TRUE;
}
}
}
}
return FALSE;

View file

@ -77,24 +77,26 @@ StrBox(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
} else {
init = (StrBoxInit*)GetWindowLong( hDlg, GWL_USERDATA );
switch (message) {
if ( !!init ) {
switch (message) {
case WM_COMMAND:
if ( !init->textIsSet ) {
stuffTextInField( hDlg, init );
init->textIsSet = XP_TRUE;
case WM_COMMAND:
if ( !init->textIsSet ) {
stuffTextInField( hDlg, init );
init->textIsSet = XP_TRUE;
}
id = LOWORD(wParam);
switch( id ) {
case IDOK:
case IDCANCEL:
init->result = id;
EndDialog(hDlg, id);
return TRUE;
}
break;
}
id = LOWORD(wParam);
switch( id ) {
case IDOK:
case IDCANCEL:
init->result = id;
EndDialog(hDlg, id);
return TRUE;
}
break;
}
}
return FALSE;