diff options
Diffstat (limited to 'iup/src/win/iupwin_button.c')
-rwxr-xr-x | iup/src/win/iupwin_button.c | 62 |
1 files changed, 47 insertions, 15 deletions
diff --git a/iup/src/win/iupwin_button.c b/iup/src/win/iupwin_button.c index 7f780e3..3b05ba7 100755 --- a/iup/src/win/iupwin_button.c +++ b/iup/src/win/iupwin_button.c @@ -27,6 +27,7 @@ #include "iupwin_drv.h" #include "iupwin_handle.h" #include "iupwin_draw.h" +#include "iupwin_info.h" #ifndef CDIS_SHOWKEYBOARDCUES @@ -308,18 +309,22 @@ static void winButtonDrawText(Ihandle* ih, HDC hDC, int rect_width, int rect_hei static void winButtonDrawItem(Ihandle* ih, DRAWITEMSTRUCT *drawitem) { + HDC hDC; iupwinBitmapDC bmpDC; int border, draw_border; int width = drawitem->rcItem.right - drawitem->rcItem.left; int height = drawitem->rcItem.bottom - drawitem->rcItem.top; - HDC hDC = iupwinDrawCreateBitmapDC(&bmpDC, drawitem->hDC, width, height); + hDC = iupwinDrawCreateBitmapDC(&bmpDC, drawitem->hDC, width, height); iupwinDrawParentBackground(ih, hDC, &drawitem->rcItem); if ((drawitem->itemState & ODS_FOCUS) && !(drawitem->itemState & ODS_HOTLIGHT)) drawitem->itemState |= ODS_DEFAULT; + if (iupAttribGet(ih, "_IUPWINBUT_SELECTED")) + drawitem->itemState |= ODS_SELECTED; + border = winButtonGetBorder(); if (ih->data->type & IUP_BUTTON_IMAGE && iupAttribGet(ih, "IMPRESS") && !iupAttribGetStr(ih, "IMPRESSBORDER")) @@ -365,7 +370,7 @@ static int winButtonSetImageAttrib(Ihandle* ih, const char* value) (void)value; if (ih->data->type != IUP_BUTTON_TEXT) { - iupdrvDisplayUpdate(ih); + iupdrvPostRedraw(ih); return 1; } else @@ -377,7 +382,7 @@ static int winButtonSetImInactiveAttrib(Ihandle* ih, const char* value) (void)value; if (ih->data->type != IUP_BUTTON_TEXT) { - iupdrvDisplayUpdate(ih); + iupdrvPostRedraw(ih); return 1; } else @@ -389,7 +394,7 @@ static int winButtonSetImPressAttrib(Ihandle* ih, const char* value) (void)value; if (ih->data->type != IUP_BUTTON_TEXT) { - iupdrvDisplayUpdate(ih); + iupdrvPostRedraw(ih); return 1; } else @@ -400,7 +405,7 @@ static int winButtonSetActiveAttrib(Ihandle* ih, const char* value) { /* redraw IMINACTIVE image if any */ if (ih->data->type != IUP_BUTTON_TEXT) - iupdrvDisplayUpdate(ih); + iupdrvPostRedraw(ih); return iupBaseSetActiveAttrib(ih, value); } @@ -425,7 +430,7 @@ static int winButtonSetAlignmentAttrib(Ihandle* ih, const char* value) else /* "ACENTER" */ ih->data->vert_alignment = IUP_ALIGN_ACENTER; - iupdrvDisplayRedraw(ih); + iupdrvRedrawNow(ih); return 1; } @@ -443,7 +448,7 @@ static int winButtonSetPaddingAttrib(Ihandle* ih, const char* value) { iupStrToIntInt(value, &ih->data->horiz_padding, &ih->data->vert_padding, 'x'); if (ih->handle) - iupdrvDisplayRedraw(ih); + iupdrvRedrawNow(ih); return 0; } @@ -454,7 +459,7 @@ static int winButtonSetBgColorAttrib(Ihandle* ih, const char* value) { iupAttribSetStr(ih, "BGCOLOR", value); iupImageUpdateParent(ih); - iupdrvDisplayRedraw(ih); + iupdrvRedrawNow(ih); } return 1; } @@ -486,7 +491,9 @@ static int winButtonSetFgColorAttrib(Ihandle* ih, const char* value) if (iupStrToRGB(value, &r, &g, &b)) { ih->data->fgcolor = RGB(r,g,b); - iupdrvDisplayRedraw(ih); + + if (ih->handle) + iupdrvRedrawNow(ih); } return 1; } @@ -499,7 +506,7 @@ static int winButtonProc(Ihandle* ih, UINT msg, WPARAM wp, LPARAM lp, LRESULT *r { /* redraw IMPRESS image if any */ if ((msg == WM_LBUTTONDOWN || msg == WM_LBUTTONUP) && iupAttribGet(ih, "IMPRESS")) - iupdrvDisplayRedraw(ih); + iupdrvRedrawNow(ih); } switch (msg) @@ -514,6 +521,13 @@ static int winButtonProc(Ihandle* ih, UINT msg, WPARAM wp, LPARAM lp, LRESULT *r case WM_RBUTTONDOWN: { iupwinButtonDown(ih, msg, wp, lp); + + /* Feedback will NOT be done when not receiving the focus */ + if (msg==WM_LBUTTONDOWN && !iupAttribGetBoolean(ih, "FOCUSONCLICK")) + { + iupAttribSetStr(ih, "_IUPWINBUT_SELECTED", "1"); + iupdrvRedrawNow(ih); + } break; } case WM_XBUTTONUP: @@ -526,11 +540,24 @@ static int winButtonProc(Ihandle* ih, UINT msg, WPARAM wp, LPARAM lp, LRESULT *r /* BN_CLICKED will NOT be notified when not receiving the focus */ if (msg==WM_LBUTTONUP && !iupAttribGetBoolean(ih, "FOCUSONCLICK")) { - Icallback cb = IupGetCallback(ih, "ACTION"); + Icallback cb; + + iupAttribSetStr(ih, "_IUPWINBUT_SELECTED", NULL); + iupdrvRedrawNow(ih); + + cb = IupGetCallback(ih, "ACTION"); if (cb && cb(ih) == IUP_CLOSE) IupExitLoop(); } + if (!iupwinIsVistaOrNew()) + { + /* TIPs desapear forever after a button click in XP, + so we force an update. */ + char* tip = iupAttribGet(ih, "TIP"); + if (tip) + iupdrvBaseSetTipAttrib(ih, tip); + } break; } case WM_KEYDOWN: @@ -549,7 +576,12 @@ static int winButtonProc(Ihandle* ih, UINT msg, WPARAM wp, LPARAM lp, LRESULT *r if (!iupwin_comctl32ver6) { iupAttribSetStr(ih, "_IUPWINBUT_ENTERWIN", NULL); - iupdrvDisplayRedraw(ih); + iupdrvRedrawNow(ih); + } + if (!iupAttribGetBoolean(ih, "FOCUSONCLICK")) + { + iupAttribSetStr(ih, "_IUPWINBUT_SELECTED", NULL); + iupdrvRedrawNow(ih); } break; case WM_MOUSEMOVE: @@ -558,7 +590,7 @@ static int winButtonProc(Ihandle* ih, UINT msg, WPARAM wp, LPARAM lp, LRESULT *r if (!iupAttribGet(ih, "_IUPWINBUT_ENTERWIN")) { iupAttribSetStr(ih, "_IUPWINBUT_ENTERWIN", "1"); - iupdrvDisplayRedraw(ih); + iupdrvRedrawNow(ih); } } break; @@ -635,7 +667,7 @@ static int winButtonWmCommand(Ihandle* ih, WPARAM wp, LPARAM lp) static int winButtonMapMethod(Ihandle* ih) { char* value; - DWORD dwStyle = WS_CHILD | + DWORD dwStyle = WS_CHILD | WS_CLIPSIBLINGS | BS_NOTIFY; /* necessary because of the base messages */ if (!ih->parent) @@ -661,7 +693,7 @@ static int winButtonMapMethod(Ihandle* ih) ih->data->type = IUP_BUTTON_IMAGE; value = iupAttribGet(ih, "TITLE"); - if (value) + if (value && *value!=0) ih->data->type |= IUP_BUTTON_TEXT; } else |