2004-03-28 03:15:24 +02:00
|
|
|
/* -*-mode: C; fill-column: 77; c-basic-offset: 4; -*- */
|
|
|
|
/*
|
|
|
|
* Copyright 2004 by Eric House (fixin@peak.org). All rights reserved.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program 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 General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* 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>
|
|
|
|
|
|
|
|
#include "ceclrsel.h"
|
2004-04-03 17:29:34 +02:00
|
|
|
#include "ceutil.h"
|
|
|
|
|
|
|
|
#ifdef MY_COLOR_SEL
|
|
|
|
|
|
|
|
typedef struct ClrEditDlgState {
|
|
|
|
CEAppGlobals* globals;
|
|
|
|
|
|
|
|
RECT clrRect;
|
|
|
|
|
|
|
|
XP_U8 r;
|
|
|
|
XP_U8 b;
|
|
|
|
XP_U8 g;
|
|
|
|
|
|
|
|
XP_Bool inited;
|
|
|
|
XP_Bool cancelled;
|
|
|
|
} ClrEditDlgState;
|
|
|
|
|
|
|
|
static void
|
|
|
|
drawColorRect( ClrEditDlgState* eState, HDC hdc )
|
|
|
|
{
|
|
|
|
COLORREF ref = RGB( eState->r, eState->g, eState->b );
|
|
|
|
HBRUSH brush = CreateSolidBrush( ref );
|
|
|
|
FillRect( hdc, &eState->clrRect, brush );
|
|
|
|
DeleteObject( brush );
|
|
|
|
} /* drawColorRect */
|
|
|
|
|
|
|
|
static void
|
|
|
|
initEditAndSlider( HWND hDlg, XP_U16 sliderID, XP_U8 val )
|
|
|
|
{
|
|
|
|
SendDlgItemMessage( hDlg, sliderID, TBM_SETRANGE, TRUE,
|
|
|
|
MAKELONG(0,255) );
|
|
|
|
SendDlgItemMessage( hDlg, sliderID, TBM_SETPOS, TRUE,
|
|
|
|
(long)val );
|
|
|
|
ceSetDlgItemNum( hDlg, sliderID+1, val );
|
|
|
|
} /* initEditAndSlider */
|
|
|
|
|
|
|
|
static void
|
|
|
|
initChooseColor( ClrEditDlgState* eState, HWND hDlg )
|
|
|
|
{
|
2004-04-09 04:36:48 +02:00
|
|
|
eState->clrRect.left = 165;
|
|
|
|
eState->clrRect.top = 5;
|
|
|
|
eState->clrRect.right = 195;
|
|
|
|
eState->clrRect.bottom = 90;
|
2004-04-03 17:29:34 +02:00
|
|
|
|
|
|
|
InvalidateRect( hDlg, &eState->clrRect, FALSE );
|
|
|
|
|
|
|
|
initEditAndSlider( hDlg, CLREDT_SLIDER1, eState->r );
|
|
|
|
initEditAndSlider( hDlg, CLREDT_SLIDER2, eState->g );
|
|
|
|
initEditAndSlider( hDlg, CLREDT_SLIDER3, eState->b );
|
|
|
|
} /* initChooseColor */
|
|
|
|
|
2004-04-09 04:36:48 +02:00
|
|
|
static XP_U8*
|
|
|
|
colorForSlider( ClrEditDlgState* eState, XP_U16 sliderID )
|
2004-04-03 17:29:34 +02:00
|
|
|
{
|
2004-04-09 04:36:48 +02:00
|
|
|
switch( sliderID ) {
|
|
|
|
case CLREDT_SLIDER1:
|
|
|
|
return &eState->r;
|
|
|
|
case CLREDT_SLIDER2:
|
|
|
|
return &eState->g;
|
|
|
|
case CLREDT_SLIDER3:
|
|
|
|
return &eState->b;
|
|
|
|
default:
|
|
|
|
XP_LOGF( "huh???" );
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
} /* colorForSlider */
|
2004-04-03 17:29:34 +02:00
|
|
|
|
2004-04-09 04:36:48 +02:00
|
|
|
static void
|
|
|
|
updateForSlider( HWND hDlg, ClrEditDlgState* eState, XP_U16 sliderID )
|
|
|
|
{
|
|
|
|
XP_U8 newColor = SendDlgItemMessage( hDlg, sliderID, TBM_GETPOS, 0, 0L );
|
|
|
|
XP_U8* colorPtr = colorForSlider( eState, sliderID );
|
|
|
|
if ( newColor != *colorPtr ) {
|
|
|
|
*colorPtr = newColor;
|
2004-04-03 17:29:34 +02:00
|
|
|
|
2004-04-09 04:36:48 +02:00
|
|
|
ceSetDlgItemNum( hDlg, sliderID+1, (XP_S32)newColor );
|
|
|
|
|
|
|
|
InvalidateRect( hDlg, &eState->clrRect, FALSE );
|
|
|
|
}
|
|
|
|
} /* updateForSlider */
|
|
|
|
|
|
|
|
static void
|
|
|
|
updateForField( HWND hDlg, ClrEditDlgState* eState, XP_U16 fieldID )
|
|
|
|
{
|
|
|
|
XP_S32 newColor = ceGetDlgItemNum( hDlg, fieldID );
|
|
|
|
XP_U8* colorPtr = colorForSlider( eState, fieldID - 1 );
|
|
|
|
XP_Bool modified = XP_FALSE;;
|
|
|
|
|
|
|
|
if ( newColor > 255 ) {
|
|
|
|
newColor = 255;
|
|
|
|
modified = XP_TRUE;
|
|
|
|
} else if ( newColor < 0 ) {
|
|
|
|
newColor = 0;
|
|
|
|
modified = XP_TRUE;
|
|
|
|
}
|
|
|
|
if ( modified ) {
|
|
|
|
ceSetDlgItemNum( hDlg, fieldID, newColor );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( newColor != *colorPtr ) {
|
|
|
|
*colorPtr = newColor;
|
|
|
|
|
|
|
|
SendDlgItemMessage( hDlg, fieldID-1, TBM_SETPOS, TRUE,
|
|
|
|
(long)newColor );
|
|
|
|
InvalidateRect( hDlg, &eState->clrRect, FALSE );
|
|
|
|
}
|
|
|
|
} /* updateForField */
|
2004-04-03 17:29:34 +02:00
|
|
|
|
|
|
|
static LRESULT CALLBACK
|
|
|
|
EditColorsDlg( HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam )
|
|
|
|
{
|
|
|
|
ClrEditDlgState* eState;
|
|
|
|
XP_U16 wid;
|
2004-04-09 04:36:48 +02:00
|
|
|
XP_U16 notifyCode;
|
2004-04-03 17:29:34 +02:00
|
|
|
NMTOOLBAR* nmToolP;
|
|
|
|
XP_U16 idCtrl;
|
|
|
|
|
|
|
|
if ( message == WM_INITDIALOG ) {
|
|
|
|
SetWindowLong( hDlg, GWL_USERDATA, lParam );
|
|
|
|
|
|
|
|
eState = (ClrEditDlgState*)lParam;
|
|
|
|
eState->cancelled = XP_TRUE;
|
|
|
|
eState->inited = XP_FALSE;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
} else {
|
|
|
|
eState = (ClrEditDlgState*)GetWindowLong( hDlg, GWL_USERDATA );
|
|
|
|
|
|
|
|
if ( !eState->inited ) {
|
|
|
|
/* set to true first! Messages will be generated by
|
|
|
|
initChooseColor call below */
|
|
|
|
eState->inited = XP_TRUE;
|
|
|
|
initChooseColor( eState, hDlg );
|
|
|
|
XP_LOGF( "initChooseColor done" );
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (message) {
|
|
|
|
|
|
|
|
case WM_PAINT: {
|
|
|
|
PAINTSTRUCT ps;
|
|
|
|
HDC hdc = BeginPaint( hDlg, &ps );
|
|
|
|
drawColorRect( eState, hdc );
|
|
|
|
EndPaint( hDlg, &ps );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2004-04-09 04:36:48 +02:00
|
|
|
case WM_NOTIFY:
|
|
|
|
nmToolP = (NMTOOLBAR*)lParam;
|
|
|
|
wid = nmToolP->hdr.idFrom;
|
|
|
|
switch ( wid ) {
|
|
|
|
case CLREDT_SLIDER1:
|
|
|
|
case CLREDT_SLIDER2:
|
|
|
|
case CLREDT_SLIDER3:
|
|
|
|
updateForSlider( hDlg, eState, wid );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
2004-04-03 17:29:34 +02:00
|
|
|
|
|
|
|
case WM_COMMAND:
|
|
|
|
wid = LOWORD(wParam);
|
|
|
|
switch( wid ) {
|
2004-04-09 04:36:48 +02:00
|
|
|
case RED_EDIT:
|
|
|
|
case GREEN_EDIT:
|
|
|
|
case BLUE_EDIT:
|
|
|
|
notifyCode = HIWORD(wParam);
|
|
|
|
if ( notifyCode == EN_CHANGE ) {
|
|
|
|
updateForField( hDlg, eState, wid );
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
break;
|
2004-04-03 17:29:34 +02:00
|
|
|
|
|
|
|
case IDOK:
|
|
|
|
eState->cancelled = XP_FALSE;
|
|
|
|
/* fallthrough */
|
2004-04-09 04:36:48 +02:00
|
|
|
|
2004-04-03 17:29:34 +02:00
|
|
|
case IDCANCEL:
|
|
|
|
EndDialog(hDlg, wid);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
} /* EditColorsDlg */
|
|
|
|
|
|
|
|
static XP_Bool
|
|
|
|
myChooseColor( CEAppGlobals* globals, HWND hwnd, COLORREF* cref )
|
|
|
|
{
|
|
|
|
ClrEditDlgState state;
|
|
|
|
int result;
|
|
|
|
|
|
|
|
XP_MEMSET( &state, 0, sizeof(state) );
|
|
|
|
state.globals = globals;
|
|
|
|
state.r = GetRValue(*cref);
|
|
|
|
state.g = GetGValue(*cref);
|
|
|
|
state.b = GetBValue(*cref);
|
|
|
|
|
|
|
|
XP_LOGF( "setting up IDD_COLOREDITDLG" );
|
|
|
|
|
|
|
|
result = DialogBoxParam( globals->hInst, (LPCTSTR)IDD_COLOREDITDLG, hwnd,
|
|
|
|
(DLGPROC)EditColorsDlg, (long)&state );
|
|
|
|
|
|
|
|
XP_LOGF( "DialogBoxParam=>%d", result );
|
|
|
|
|
|
|
|
if ( !state.cancelled ) {
|
|
|
|
*cref = RGB( state.r, state.g, state.b );
|
|
|
|
}
|
|
|
|
|
|
|
|
return !state.cancelled;
|
|
|
|
} /* myChooseColor */
|
|
|
|
|
|
|
|
#endif
|
2004-03-28 03:15:24 +02:00
|
|
|
|
|
|
|
typedef struct ColorsDlgState {
|
|
|
|
|
|
|
|
CEAppGlobals* globals;
|
|
|
|
|
|
|
|
COLORREF colors[NUM_EDITABLE_COLORS];
|
|
|
|
HBRUSH brushes[NUM_EDITABLE_COLORS];
|
|
|
|
HWND buttons[NUM_EDITABLE_COLORS];
|
|
|
|
|
|
|
|
XP_Bool cancelled;
|
|
|
|
XP_Bool inited;
|
|
|
|
} ColorsDlgState;
|
|
|
|
|
|
|
|
#define FIRST_BUTTON DLBLTR_BUTTON
|
|
|
|
#define LAST_BUTTON PLAYER4_BUTTON
|
|
|
|
|
|
|
|
static void
|
|
|
|
initColorData( ColorsDlgState* cState, HWND hDlg )
|
|
|
|
{
|
|
|
|
CEAppGlobals* globals = cState->globals;
|
|
|
|
XP_U16 i;
|
|
|
|
|
|
|
|
XP_ASSERT( (LAST_BUTTON - FIRST_BUTTON + 1) == NUM_EDITABLE_COLORS );
|
|
|
|
|
|
|
|
for ( i = 0; i < NUM_EDITABLE_COLORS; ++i ) {
|
|
|
|
COLORREF ref = globals->appPrefs.colors[i];
|
|
|
|
cState->colors[i] = ref;
|
|
|
|
XP_LOGF( "ref[%d] = 0x%lx", i, (unsigned long)ref );
|
|
|
|
cState->brushes[i] = CreateSolidBrush( ref );
|
|
|
|
cState->buttons[i] = GetDlgItem( hDlg, FIRST_BUTTON + i );
|
|
|
|
}
|
|
|
|
} /* initColorData */
|
|
|
|
|
|
|
|
static HBRUSH
|
|
|
|
brushForButton( ColorsDlgState* cState, HWND hwndButton )
|
|
|
|
{
|
|
|
|
XP_U16 i;
|
|
|
|
for ( i = 0; i < NUM_EDITABLE_COLORS; ++i ) {
|
|
|
|
if ( cState->buttons[i] == hwndButton ) {
|
|
|
|
return cState->brushes[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
} /* brushForButton */
|
|
|
|
|
|
|
|
static void
|
|
|
|
deleteButtonBrushes( ColorsDlgState* cState )
|
|
|
|
{
|
|
|
|
XP_U16 i;
|
|
|
|
for ( i = 0; i < NUM_EDITABLE_COLORS; ++i ) {
|
|
|
|
DeleteObject( cState->brushes[i] );
|
|
|
|
}
|
|
|
|
} /* deleteButtonBrushes */
|
|
|
|
|
|
|
|
static void
|
|
|
|
wrapChooseColor( ColorsDlgState* cState, HWND owner, XP_U16 button )
|
|
|
|
{
|
2004-04-03 17:29:34 +02:00
|
|
|
XP_U16 index = button-FIRST_BUTTON;
|
|
|
|
|
|
|
|
#ifdef MY_COLOR_SEL
|
|
|
|
COLORREF clrref = cState->colors[index];
|
|
|
|
|
|
|
|
if ( myChooseColor( cState->globals, owner, &clrref ) ) {
|
|
|
|
cState->colors[index] = clrref;
|
|
|
|
DeleteObject( cState->brushes[index] );
|
|
|
|
cState->brushes[index] = CreateSolidBrush( clrref );
|
|
|
|
}
|
|
|
|
#else
|
2004-03-28 03:15:24 +02:00
|
|
|
CHOOSECOLOR ccs;
|
|
|
|
BOOL hitOk;
|
|
|
|
COLORREF arr[16];
|
2004-04-03 17:29:34 +02:00
|
|
|
XP_U16 i;
|
2004-03-28 03:15:24 +02:00
|
|
|
|
|
|
|
XP_MEMSET( &ccs, 0, sizeof(ccs) );
|
|
|
|
XP_MEMSET( &arr, 0, sizeof(arr) );
|
|
|
|
|
2004-04-03 17:29:34 +02:00
|
|
|
for ( i = 0; i < NUM_EDITABLE_COLORS; ++i ) {
|
|
|
|
arr[i] = cState->colors[i];
|
|
|
|
}
|
|
|
|
|
2004-03-28 03:15:24 +02:00
|
|
|
ccs.lStructSize = sizeof(ccs);
|
|
|
|
ccs.hwndOwner = owner;
|
|
|
|
ccs.rgbResult = cState->colors[index];
|
|
|
|
ccs.lpCustColors = arr;
|
|
|
|
|
|
|
|
ccs.Flags = CC_ANYCOLOR | CC_RGBINIT | CC_FULLOPEN;
|
|
|
|
|
|
|
|
hitOk = ChooseColor( &ccs );
|
|
|
|
|
|
|
|
if ( hitOk ) {
|
|
|
|
cState->colors[index] = ccs.rgbResult;
|
|
|
|
DeleteObject( cState->brushes[index] );
|
|
|
|
cState->brushes[index] = CreateSolidBrush( ccs.rgbResult );
|
|
|
|
}
|
2004-04-03 17:29:34 +02:00
|
|
|
#endif
|
2004-03-28 03:15:24 +02:00
|
|
|
} /* wrapChooseColor */
|
|
|
|
|
|
|
|
LRESULT CALLBACK
|
|
|
|
ColorsDlg( HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam )
|
|
|
|
{
|
|
|
|
ColorsDlgState* cState;
|
|
|
|
XP_U16 wid;
|
|
|
|
|
|
|
|
if ( message == WM_INITDIALOG ) {
|
|
|
|
SetWindowLong( hDlg, GWL_USERDATA, lParam );
|
|
|
|
|
|
|
|
cState = (ColorsDlgState*)lParam;
|
|
|
|
cState->cancelled = XP_TRUE;
|
|
|
|
cState->inited = XP_FALSE;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
} else {
|
|
|
|
cState = (ColorsDlgState*)GetWindowLong( hDlg, GWL_USERDATA );
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
} /* ColorsDlg */
|
|
|
|
|
|
|
|
XP_Bool
|
|
|
|
ceDoColorsEdit( HWND hwnd, CEAppGlobals* globals )
|
|
|
|
{
|
|
|
|
ColorsDlgState state;
|
|
|
|
|
|
|
|
XP_MEMSET( &state, 0, sizeof(state) );
|
|
|
|
state.globals = globals;
|
|
|
|
|
2004-04-03 17:29:34 +02:00
|
|
|
(void)DialogBoxParam( globals->hInst, (LPCTSTR)IDD_COLORSDLG, hwnd,
|
|
|
|
(DLGPROC)ColorsDlg, (long)&state );
|
2004-03-28 03:15:24 +02:00
|
|
|
|
|
|
|
if ( !state.cancelled ) {
|
|
|
|
XP_U16 i;
|
|
|
|
for ( i = 0; i < NUM_EDITABLE_COLORS; ++i ) {
|
|
|
|
globals->appPrefs.colors[i] = state.colors[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return !state.cancelled;
|
|
|
|
} /* ceDoColorsEdit */
|
|
|
|
|
|
|
|
#endif
|