static void winToggleDrawItem(Ihandle* ih, DRAWITEMSTRUCT *drawitem) { int width, height, border = 4, check; HDC hDC; iupwinBitmapDC bmpDC; width = drawitem->rcItem.right - drawitem->rcItem.left; height = drawitem->rcItem.bottom - drawitem->rcItem.top; hDC = iupwinDrawCreateBitmapDC(&bmpDC, drawitem->hDC, width, height); iupwinDrawParentBackground(ih, hDC, &drawitem->rcItem); check = SendMessage(ih->handle, BM_GETCHECK, 0, 0L); if (check) drawitem->itemState |= ODS_SELECTED; else drawitem->itemState |= ODS_DEFAULT; /* use default mark for NOT checked */ iupwinDrawButtonBorder(ih->handle, hDC, &drawitem->rcItem, drawitem->itemState); winToggleDrawImage(ih, hDC, width, height, border, drawitem->itemState); if (drawitem->itemState & ODS_FOCUS) { border--; iupdrvDrawFocusRect(ih, hDC, border, border, width-2*border, height-2*border); } iupwinDrawDestroyBitmapDC(&bmpDC); }
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 = 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") && !iupAttribGetBoolean(ih, "IMPRESSBORDER")) draw_border = 0; else { if (iupAttribGetBoolean(ih, "FLAT")) { if (drawitem->itemState & ODS_HOTLIGHT || iupAttribGet(ih, "_IUPWINBUT_ENTERWIN")) draw_border = 1; else draw_border = 0; } else draw_border = 1; } if (draw_border) iupwinDrawButtonBorder(ih->handle, hDC, &drawitem->rcItem, drawitem->itemState); if (ih->data->type == IUP_BUTTON_IMAGE) winButtonDrawImage(ih, hDC, width, height, border, drawitem->itemState); else if (ih->data->type == IUP_BUTTON_TEXT) winButtonDrawText(ih, hDC, width, height, border, drawitem->itemState); else /* both */ winButtonDrawImageText(ih, hDC, width, height, border, drawitem->itemState); if (drawitem->itemState & ODS_FOCUS && !(drawitem->itemState & ODS_NOFOCUSRECT) && iupAttribGetBoolean(ih, "CANFOCUS")) { border--; iupdrvDrawFocusRect(ih, hDC, border, border, width-2*border, height-2*border); } iupwinDrawDestroyBitmapDC(&bmpDC); }
static void winToggleDrawItem(Ihandle* ih, DRAWITEMSTRUCT *drawitem) { /* called only when (ih->data->type==IUP_TOGGLE_IMAGE && (iupwin_comctl32ver6 || ih->data->flat)) */ int width, height, border = 4, check, draw_border; HDC hDC; iupwinBitmapDC bmpDC; width = drawitem->rcItem.right - drawitem->rcItem.left; height = drawitem->rcItem.bottom - drawitem->rcItem.top; hDC = iupwinDrawCreateBitmapDC(&bmpDC, drawitem->hDC, 0, 0, width, height); iupwinDrawParentBackground(ih, hDC, &drawitem->rcItem); if (!iupwin_comctl32ver6) { if (drawitem->itemState&ODS_SELECTED) iupAttribSet(ih, "_IUPWIN_PRESSED", "1"); } check = winToggleGetCheck(ih); if (check) drawitem->itemState |= ODS_SELECTED; else drawitem->itemState |= ODS_DEFAULT; /* use default mark for NOT checked */ if (!check && ih->data->flat) { if (drawitem->itemState & ODS_HOTLIGHT || iupAttribGet(ih, "_IUPWINTOG_ENTERWIN")) draw_border = 1; else draw_border = 0; } else draw_border = 1; /* when checked, even if flat thr border is drawn */ if (draw_border) iupwinDrawButtonBorder(ih->handle, hDC, &drawitem->rcItem, drawitem->itemState); winToggleDrawImage(ih, hDC, width, height, border, drawitem->itemState); if (drawitem->itemState & ODS_FOCUS && !(drawitem->itemState & ODS_NOFOCUSRECT) && iupAttribGetBoolean(ih, "CANFOCUS")) { border--; iupdrvDrawFocusRect(ih, hDC, border, border, width-2*border, height-2*border); } iupwinDrawDestroyBitmapDC(&bmpDC); }
void IupCdDrawFocusRect(Ihandle* ih, cdCanvas *canvas, int x1, int y1, int x2, int y2) { int y, x, w, h; #ifdef WIN32 void* gc = cdCanvasGetAttribute(canvas, "HDC"); #else void* gc = cdCanvasGetAttribute(canvas, "GC"); /* works for X11, GDK and Cairo */ #endif cdCanvasUpdateYAxis(canvas, &y1); cdCanvasUpdateYAxis(canvas, &y2); y = y1; if (y2<y1) y = y2; x = x1; if (x2<x1) x = x2; w = abs(x2-x1)+1; h = abs(y2-y1)+1; iupdrvDrawFocusRect(ih, gc, x, y, w, h); }
static void winListDrawItem(Ihandle* ih, DRAWITEMSTRUCT *drawitem) { char* text; int txt_w, txt_h; winListItemData* itemdata; HFONT hFont = (HFONT)iupwinGetHFontAttrib(ih); iupwinBitmapDC bmpDC; HDC hDC; RECT rect; COLORREF fgcolor, bgcolor; int x = drawitem->rcItem.left; int y = drawitem->rcItem.top; int width = drawitem->rcItem.right - drawitem->rcItem.left; int height = drawitem->rcItem.bottom - drawitem->rcItem.top; /* If there are no list box items, skip this message */ if (drawitem->itemID == -1) return; hDC = iupwinDrawCreateBitmapDC(&bmpDC, drawitem->hDC, x, y, width, height); if (drawitem->itemState & ODS_SELECTED) bgcolor = GetSysColor(COLOR_HIGHLIGHT); else if (!iupwinGetColorRef(ih, "BGCOLOR", &bgcolor)) bgcolor = GetSysColor(COLOR_WINDOW); SetDCBrushColor(hDC, bgcolor); SetRect(&rect, 0, 0, width, height); FillRect(hDC, &rect, (HBRUSH)GetStockObject(DC_BRUSH)); if (iupdrvIsActive(ih)) { if (drawitem->itemState & ODS_SELECTED) fgcolor = GetSysColor(COLOR_HIGHLIGHTTEXT); else if (!iupwinGetColorRef(ih, "FGCOLOR", &fgcolor)) fgcolor = GetSysColor(COLOR_WINDOWTEXT); } else fgcolor = GetSysColor(COLOR_GRAYTEXT); /* Get the bitmap associated with the item */ itemdata = winListGetItemData(ih, drawitem->itemID); /* Get and draw the string associated with the item */ text = winListGetText(ih, drawitem->itemID); iupdrvFontGetMultiLineStringSize(ih, text, &txt_w, &txt_h); x = ih->data->maximg_w + 3; /* spacing between text and image */ y = (height - txt_h)/2; /* vertically centered */ iupwinDrawText(hDC, text, x, y, txt_w, txt_h, hFont, fgcolor, 0); /* Draw the bitmap associated with the item */ if (itemdata->hBitmap) { int bpp, img_w, img_h; HBITMAP hMask = NULL; iupdrvImageGetInfo(itemdata->hBitmap, &img_w, &img_h, &bpp); if (bpp == 8) { char name[50]; sprintf(name, "IMAGE%d", (int)drawitem->itemID+1); hMask = iupdrvImageCreateMask(IupGetAttributeHandle(ih, name)); } x = 0; y = (height - img_h)/2; /* vertically centered */ iupwinDrawBitmap(hDC, itemdata->hBitmap, hMask, x, y, img_w, img_h, bpp); if (hMask) DeleteObject(hMask); } /* If the item has the focus, draw the focus rectangle */ if (drawitem->itemState & ODS_FOCUS) iupdrvDrawFocusRect(ih, hDC, 0, 0, width, height); free(text); iupwinDrawDestroyBitmapDC(&bmpDC); }