Fix color edit dialog itself. Shrink to fit smartphone screen. And

use another owner-drawn button for the sample so it can be located in
the resource file.
This commit is contained in:
ehouse 2008-05-10 21:09:12 +00:00
parent 3d6f26cc3d
commit 180de81e58
3 changed files with 76 additions and 84 deletions

View file

@ -31,26 +31,27 @@
typedef struct ClrEditDlgState {
CEAppGlobals* globals;
RECT clrRect;
HWND parent;
HWND sampleButton;
XP_U16 labelID;
XP_U8 r;
XP_U8 b;
XP_U8 g;
XP_U8 red;
XP_U8 green;
XP_U8 blue;
XP_Bool inited;
XP_Bool cancelled;
} ClrEditDlgState;
static void
drawColorRect( ClrEditDlgState* eState, HDC hdc )
colorButton( DRAWITEMSTRUCT* dis, HBRUSH brush )
{
COLORREF ref = RGB( eState->r, eState->g, eState->b );
HBRUSH brush = CreateSolidBrush( ref );
FillRect( hdc, &eState->clrRect, brush );
DeleteObject( brush );
} /* drawColorRect */
RECT rect = dis->rcItem;
Rectangle( dis->hDC, rect.left, rect.top, rect.right, rect.bottom );
InsetRect( &rect, 1, 1 );
FillRect( dis->hDC, &rect, brush );
}
static void
initEditAndSlider( HWND hDlg, XP_U16 sliderID, XP_U8 val )
@ -65,16 +66,9 @@ initEditAndSlider( HWND hDlg, XP_U16 sliderID, XP_U8 val )
static void
initChooseColor( ClrEditDlgState* eState, HWND hDlg )
{
eState->clrRect.left = 162;
eState->clrRect.top = 5;
eState->clrRect.right = 193;
eState->clrRect.bottom = 90;
InvalidateRect( hDlg, &eState->clrRect, FALSE );
initEditAndSlider( hDlg, CLREDT_SLIDER1, eState->r );
initEditAndSlider( hDlg, CLREDT_SLIDER2, eState->g );
initEditAndSlider( hDlg, CLREDT_SLIDER3, eState->b );
initEditAndSlider( hDlg, CLREDT_SLIDER1, eState->red );
initEditAndSlider( hDlg, CLREDT_SLIDER2, eState->green );
initEditAndSlider( hDlg, CLREDT_SLIDER3, eState->blue );
} /* initChooseColor */
static XP_U8*
@ -82,11 +76,11 @@ colorForSlider( ClrEditDlgState* eState, XP_U16 sliderID )
{
switch( sliderID ) {
case CLREDT_SLIDER1:
return &eState->r;
return &eState->red;
case CLREDT_SLIDER2:
return &eState->g;
return &eState->green;
case CLREDT_SLIDER3:
return &eState->b;
return &eState->blue;
default:
XP_LOGF( "huh???" );
return NULL;
@ -104,7 +98,7 @@ updateForSlider( HWND hDlg, ClrEditDlgState* eState, XP_U16 sliderID )
ceSetDlgItemNum( hDlg, sliderID+1, (XP_S32)newColor );
InvalidateRect( hDlg, &eState->clrRect, FALSE );
InvalidateRect( eState->sampleButton, NULL, TRUE /* erase */ );
}
} /* updateForSlider */
@ -131,10 +125,19 @@ updateForField( HWND hDlg, ClrEditDlgState* eState, XP_U16 fieldID )
SendDlgItemMessage( hDlg, fieldID-1, TBM_SETPOS, TRUE,
(long)newColor );
InvalidateRect( hDlg, &eState->clrRect, FALSE );
InvalidateRect( eState->sampleButton, NULL, FALSE );
}
} /* updateForField */
static void
colorButtonFromState( ClrEditDlgState* eState, DRAWITEMSTRUCT* dis )
{
COLORREF ref = RGB( eState->red, eState->green, eState->blue );
HBRUSH brush = CreateSolidBrush( ref );
colorButton( dis, brush );
DeleteObject( brush );
}
LRESULT CALLBACK
EditColorsDlg( HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam )
{
@ -163,6 +166,9 @@ EditColorsDlg( HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam )
swprintf( buf, L"Edit color for %s", label );
SendMessage( hDlg, WM_SETTEXT, 0, (LPARAM)buf );
eState->sampleButton = GetDlgItem( hDlg, CLSAMPLE_BUTTON_ID );
EnableWindow( eState->sampleButton, FALSE );
return TRUE;
} else {
eState = (ClrEditDlgState*)GetWindowLong( hDlg, GWL_USERDATA );
@ -175,7 +181,6 @@ EditColorsDlg( HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam )
initChooseColor call below */
eState->inited = XP_TRUE;
initChooseColor( eState, hDlg );
XP_LOGF( "initChooseColor done" );
}
switch (message) {
@ -184,12 +189,9 @@ EditColorsDlg( HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam )
ceDoDlgScroll( eState->globals, hDlg, wParam );
break;
case WM_PAINT: {
PAINTSTRUCT ps;
HDC hdc = BeginPaint( hDlg, &ps );
drawColorRect( eState, hdc );
EndPaint( hDlg, &ps );
}
case WM_DRAWITEM:
colorButtonFromState( eState, (DRAWITEMSTRUCT*)lParam );
return TRUE;
break;
case WM_NOTIFY:
@ -240,9 +242,9 @@ myChooseColor( CEAppGlobals* globals, HWND parent, XP_U16 labelID,
XP_MEMSET( &state, 0, sizeof(state) );
state.globals = globals;
state.r = GetRValue(*cref);
state.g = GetGValue(*cref);
state.b = GetBValue(*cref);
state.red = GetRValue(*cref);
state.green = GetGValue(*cref);
state.blue = GetBValue(*cref);
state.labelID = labelID;
state.parent = parent;
@ -254,7 +256,7 @@ myChooseColor( CEAppGlobals* globals, HWND parent, XP_U16 labelID,
XP_LOGF( "DialogBoxParam=>%d", result );
if ( !state.cancelled ) {
*cref = RGB( state.r, state.g, state.b );
*cref = RGB( state.red, state.green, state.blue );
}
return !state.cancelled;
@ -364,23 +366,13 @@ wrapChooseColor( ColorsDlgState* cState, XP_U16 button )
}
} /* wrapChooseColor */
/* I'd prefer to use normal buttons, letting the OS draw them except for
* their background color, but MS docs don't seem to allow any way to do
* that. I'm either totally on my own drawing the button or they're all in
* the same color and so useless. So they're just rects with a black outer
* rect to show focus.
*/
static void
ceDrawColorButton( ColorsDlgState* cState, DRAWITEMSTRUCT* dis )
{
HBRUSH brush = brushForButton( cState, dis->hwndItem );
XP_ASSERT( !!brush );
RECT rect = dis->rcItem;
Rectangle( dis->hDC, rect.left, rect.top, rect.right, rect.bottom );
InsetRect( &rect, 1, 1 );
FillRect( dis->hDC, &rect, brush );
colorButton( dis, brush );
} /* ceDrawColorButton */
LRESULT CALLBACK

View file

@ -141,6 +141,7 @@
# define RED_LABEL 1097
# define GREEN_LABEL 1098
# define BLUE_LABEL 1099
# define CLSAMPLE_BUTTON_ID 1123
#endif // MY_COLOR_SEL
#define HC_MIN_COMBO 1100
@ -240,7 +241,7 @@
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 125
#define _APS_NEXT_COMMAND_VALUE 40029
#define _APS_NEXT_CONTROL_VALUE 1123
#define _APS_NEXT_CONTROL_VALUE 1124
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif

View file

@ -711,58 +711,57 @@ END
//
#ifdef MY_COLOR_SEL
# define CLRELABEL_COL 3
# define CLREEDIT_COL 28
# define CLRESLIDER_COL 45
# define CLRE_LAB_WIDTH 22
# define CLEDIT_WIDTH 18
# define CLSLIDER_WIDTH 30
# define CLSAMPLE_WIDTH 15
# define CLRELABEL_COL 3
# define CLREEDIT_COL (CLRELABEL_COL+CLRE_LAB_WIDTH+2)
# define CLRESLIDER_COL (CLREEDIT_COL+CLEDIT_WIDTH+3)
# define CLSAMPLE_COL (CLRESLIDER_COL+CLSLIDER_WIDTH+5)
# define CLRE_LAB_HT 12
# define CLREDIT_ROW_1 5
# define CLREDIT_ROW_2 21
# define CLREDIT_ROW_3 37
# define SLIDER_WIDTH 46
#define CLRE_WIDTH 112
#define CLRE_OK_LEFT ((CLRE_WIDTH/2)-10-REPOS_BUTTON_WIDTH)
#define CLRE_CANCEL_LEFT ((CLRE_WIDTH/2)+10)
#ifdef _WIN32_WCE
# define COLOREDITDLG_HT 56
#else
# define COLOREDITDLG_HT 72
#endif
# define CLRE_WIDTH (CLSAMPLE_COL+CLSAMPLE_WIDTH+5)
# define CLRE_OK_LEFT ((CLRE_WIDTH/2)-10-REPOS_BUTTON_WIDTH)
# define CLRE_CANCEL_LEFT ((CLRE_WIDTH/2)+10)
# ifdef _WIN32_WCE
# define COLOREDITDLG_HT 56
# else
# define COLOREDITDLG_HT 72
# endif
IDD_COLOREDITDLG DIALOG DISCARDABLE 0, 0, CLRE_WIDTH, 72
# define COLOR_EDIT_LINE(txt,row,labelId,editId,sliderId) \
LTEXT txt,labelId,CLRELABEL_COL,row, \
CLRE_LAB_WIDTH,CLRE_LAB_HT \
EDITTEXT editId,CLREEDIT_COL,row,CLEDIT_WIDTH,12, \
ES_AUTOHSCROLL | ES_NUMBER \
CONTROL "",sliderId,"msctls_trackbar32", \
TBS_BOTH|TBS_NOTICKS|WS_TABSTOP, \
CLRESLIDER_COL,row,CLSLIDER_WIDTH,12
IDD_COLOREDITDLG DIALOG DISCARDABLE 0, 0, CLRE_WIDTH, COLOREDITDLG_HT
STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | DS_CENTER
CAPTION "" /* set by code */
FONT 8, "System"
BEGIN
LTEXT "Red:",RED_LABEL,CLRELABEL_COL,CLREDIT_ROW_1,
CLRE_LAB_WIDTH,CLRE_LAB_HT
EDITTEXT RED_EDIT,CLREEDIT_COL,CLREDIT_ROW_1,18,12,
ES_AUTOHSCROLL | ES_NUMBER
CONTROL "",CLREDT_SLIDER1,"msctls_trackbar32",
TBS_BOTH|TBS_NOTICKS|WS_TABSTOP,
CLRESLIDER_COL,CLREDIT_ROW_1,SLIDER_WIDTH,15
COLOR_EDIT_LINE("Red:", CLREDIT_ROW_1, RED_LABEL, RED_EDIT, CLREDT_SLIDER1 )
COLOR_EDIT_LINE("Green:", CLREDIT_ROW_2, GREEN_LABEL, GREEN_EDIT, CLREDT_SLIDER2 )
COLOR_EDIT_LINE("Blue:", CLREDIT_ROW_3, BLUE_LABEL, BLUE_EDIT, CLREDT_SLIDER3 )
LTEXT "Green:",GREEN_LABEL,CLRELABEL_COL,CLREDIT_ROW_2,
CLRE_LAB_WIDTH,CLRE_LAB_HT
EDITTEXT GREEN_EDIT,CLREEDIT_COL,CLREDIT_ROW_2,18,12,
ES_AUTOHSCROLL | ES_NUMBER
CONTROL "",CLREDT_SLIDER2,"msctls_trackbar32",
TBS_BOTH|TBS_NOTICKS|WS_TABSTOP,
CLRESLIDER_COL,CLREDIT_ROW_2,SLIDER_WIDTH,15
/* See hack alert above. Bogus owner-draw button seems the only way to get a sample
color rect into the dialog. */
PUSHBUTTON "",CLSAMPLE_BUTTON_ID,CLSAMPLE_COL,CLREDIT_ROW_1,
CLSAMPLE_WIDTH,CLREDIT_ROW_3-CLREDIT_ROW_1+CLRE_LAB_HT,BS_OWNERDRAW
LTEXT "Blue:",BLUE_LABEL,CLRELABEL_COL,CLREDIT_ROW_3,
CLRE_LAB_WIDTH,CLRE_LAB_HT
EDITTEXT BLUE_EDIT,CLREEDIT_COL,CLREDIT_ROW_3,18,12,
ES_AUTOHSCROLL | ES_NUMBER
CONTROL "",CLREDT_SLIDER3,"msctls_trackbar32",
TBS_BOTH|TBS_NOTICKS|WS_TABSTOP,
CLRESLIDER_COL,CLREDIT_ROW_3,SLIDER_WIDTH,15
#ifndef _WIN32_WCE
# ifndef _WIN32_WCE
DEFPUSHBUTTON "OK",IDOK,CLRE_OK_LEFT,56,REPOS_BUTTON_WIDTH,
REPOS_BUTTON_HT
PUSHBUTTON "Cancel",IDCANCEL,CLRE_CANCEL_LEFT,56,REPOS_BUTTON_WIDTH,
REPOS_BUTTON_HT
#endif
# endif
END
#endif