mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-30 08:34:16 +01:00
as-yet unsuccessful attempt to replace M$ ChooseColor dialog
This commit is contained in:
parent
f065f6432a
commit
20b14dfa11
1 changed files with 194 additions and 4 deletions
198
wince/ceclrsel.c
198
wince/ceclrsel.c
|
@ -24,6 +24,181 @@
|
|||
#include <commdlg.h>
|
||||
|
||||
#include "ceclrsel.h"
|
||||
#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 )
|
||||
{
|
||||
eState->clrRect.left = 10;
|
||||
eState->clrRect.top = 10;
|
||||
eState->clrRect.right = 40;
|
||||
eState->clrRect.bottom = 40;
|
||||
|
||||
InvalidateRect( hDlg, &eState->clrRect, FALSE );
|
||||
|
||||
initEditAndSlider( hDlg, CLREDT_SLIDER1, eState->r );
|
||||
initEditAndSlider( hDlg, CLREDT_SLIDER2, eState->g );
|
||||
initEditAndSlider( hDlg, CLREDT_SLIDER3, eState->b );
|
||||
} /* initChooseColor */
|
||||
|
||||
static void
|
||||
dragEnded( HWND hDlg, ClrEditDlgState* eState, XP_UCHAR sliderId, XP_U8* val )
|
||||
{
|
||||
XP_U16 newVal = SendDlgItemMessage( hDlg, sliderId, TBM_GETPOS, 0, 0L );
|
||||
XP_LOGF( "newVal=%d", newVal );
|
||||
XP_ASSERT( newVal >= 0 && newVal <= 255 );
|
||||
*val = newVal;
|
||||
|
||||
ceSetDlgItemNum( hDlg, sliderId+1, newVal );
|
||||
|
||||
InvalidateRect( hDlg, &eState->clrRect, FALSE );
|
||||
} /* dragEnded */
|
||||
|
||||
static LRESULT CALLBACK
|
||||
EditColorsDlg( HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam )
|
||||
{
|
||||
ClrEditDlgState* eState;
|
||||
XP_U16 wid;
|
||||
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;
|
||||
|
||||
case WM_NOTIFY:
|
||||
XP_LOGF( "WM_NOTIFY" );
|
||||
nmToolP = (NMTOOLBAR*)lParam;
|
||||
if ( nmToolP->hdr.code == TBN_ENDDRAG ) {
|
||||
XP_LOGF( "TBN_ENDDRAG" );
|
||||
switch( nmToolP->hdr.idFrom ) {
|
||||
case CLREDT_SLIDER1:
|
||||
dragEnded( hDlg, eState, CLREDT_SLIDER1, &eState->r );
|
||||
break;
|
||||
case CLREDT_SLIDER2:
|
||||
dragEnded( hDlg, eState, CLREDT_SLIDER2, &eState->g );
|
||||
break;
|
||||
case CLREDT_SLIDER3:
|
||||
dragEnded( hDlg, eState, CLREDT_SLIDER3, &eState->b );
|
||||
break;
|
||||
default:
|
||||
XP_LOGF( "some other value: %d", nmToolP->hdr.idFrom );
|
||||
return FALSE;
|
||||
}
|
||||
} else if ( nmToolP->hdr.code == TBN_BEGINDRAG ) {
|
||||
XP_LOGF( "TBN_BEGINDRAG" );
|
||||
} else if ( nmToolP->hdr.code == TBN_DROPDOWN ) {
|
||||
XP_LOGF( "TBN_DROPDOWN" );
|
||||
} else {
|
||||
XP_LOGF( "something else: 0x%x", nmToolP->hdr.code );
|
||||
XP_LOGF( "ctl id is %d", nmToolP->hdr.idFrom );
|
||||
}
|
||||
break;
|
||||
|
||||
case WM_COMMAND:
|
||||
wid = LOWORD(wParam);
|
||||
switch( wid ) {
|
||||
|
||||
case IDOK:
|
||||
eState->cancelled = XP_FALSE;
|
||||
/* fallthrough */
|
||||
|
||||
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
|
||||
|
||||
typedef struct ColorsDlgState {
|
||||
|
||||
|
@ -81,14 +256,29 @@ deleteButtonBrushes( ColorsDlgState* cState )
|
|||
static void
|
||||
wrapChooseColor( ColorsDlgState* cState, HWND owner, XP_U16 button )
|
||||
{
|
||||
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
|
||||
CHOOSECOLOR ccs;
|
||||
BOOL hitOk;
|
||||
COLORREF arr[16];
|
||||
XP_U16 index = button-FIRST_BUTTON;
|
||||
XP_U16 i;
|
||||
|
||||
XP_MEMSET( &ccs, 0, sizeof(ccs) );
|
||||
XP_MEMSET( &arr, 0, sizeof(arr) );
|
||||
|
||||
for ( i = 0; i < NUM_EDITABLE_COLORS; ++i ) {
|
||||
arr[i] = cState->colors[i];
|
||||
}
|
||||
|
||||
ccs.lStructSize = sizeof(ccs);
|
||||
ccs.hwndOwner = owner;
|
||||
ccs.rgbResult = cState->colors[index];
|
||||
|
@ -103,6 +293,7 @@ wrapChooseColor( ColorsDlgState* cState, HWND owner, XP_U16 button )
|
|||
DeleteObject( cState->brushes[index] );
|
||||
cState->brushes[index] = CreateSolidBrush( ccs.rgbResult );
|
||||
}
|
||||
#endif
|
||||
} /* wrapChooseColor */
|
||||
|
||||
LRESULT CALLBACK
|
||||
|
@ -169,13 +360,12 @@ XP_Bool
|
|||
ceDoColorsEdit( HWND hwnd, CEAppGlobals* globals )
|
||||
{
|
||||
ColorsDlgState state;
|
||||
int result;
|
||||
|
||||
XP_MEMSET( &state, 0, sizeof(state) );
|
||||
state.globals = globals;
|
||||
|
||||
result = DialogBoxParam( globals->hInst, (LPCTSTR)IDD_COLORSDLG, hwnd,
|
||||
(DLGPROC)ColorsDlg, (long)&state );
|
||||
(void)DialogBoxParam( globals->hInst, (LPCTSTR)IDD_COLORSDLG, hwnd,
|
||||
(DLGPROC)ColorsDlg, (long)&state );
|
||||
|
||||
if ( !state.cancelled ) {
|
||||
XP_U16 i;
|
||||
|
|
Loading…
Add table
Reference in a new issue