static void iFlatButtonDrawIcon(Ihandle* ih, IdrawCanvas* dc, int icon_x, int icon_y, int icon_width, int icon_height, const char *baseattrib, const char* imagename, const char* title, const char* fgcolor, const char* bgcolor, int active) { int x, y, width, height; if (imagename) { if (title) { int img_x, img_y, txt_x, txt_y; int txt_width, txt_height; int img_width, img_height; iupdrvFontGetMultiLineStringSize(ih, title, &txt_width, &txt_height); iupImageGetInfo(imagename, &img_width, &img_height, NULL); if (ih->data->img_position == IUP_IMGPOS_RIGHT || ih->data->img_position == IUP_IMGPOS_LEFT) { width = img_width + txt_width + ih->data->spacing; height = iupMAX(img_height, txt_height); } else { width = iupMAX(img_width, txt_width); height = img_height + txt_height + ih->data->spacing; } iFlatButtonGetIconPosition(ih, icon_width, icon_height, &x, &y, width, height); iFlatButtonGetImageTextPosition(x, y, ih->data->img_position, ih->data->spacing, img_width, img_height, txt_width, txt_height, &img_x, &img_y, &txt_x, &txt_y); iFlatButtonDrawImage(ih, dc, img_x + icon_x, img_y + icon_y, baseattrib, imagename, active); iFlatButtonDrawText(ih, dc, txt_x + icon_x, txt_y + icon_y, title, fgcolor, bgcolor, active); } else { iupImageGetInfo(imagename, &width, &height, NULL); iFlatButtonGetIconPosition(ih, icon_width, icon_height, &x, &y, width, height); iFlatButtonDrawImage(ih, dc, x + icon_x, y + icon_y, baseattrib, imagename, active); } } else if (title) { iupdrvFontGetMultiLineStringSize(ih, title, &width, &height); iFlatButtonGetIconPosition(ih, icon_width, icon_height, &x, &y, width, height); iFlatButtonDrawText(ih, dc, x + icon_x, y + icon_y, title, fgcolor, bgcolor, active); } }
static void iFlatButtonComputeNaturalSizeMethod(Ihandle* ih, int *w, int *h, int *children_expand) { int fit2backimage = iupAttribGetBoolean(ih, "FITTOBACKIMAGE"); char* bgimage = iupAttribGet(ih, "BACKIMAGE"); if (fit2backimage && bgimage) iupImageGetInfo(bgimage, w, h, NULL); else { char* image = iupAttribGet(ih, "IMAGE"); char* title = iupAttribGet(ih, "TITLE"); *w = 0, *h = 0; if (image) { iupImageGetInfo(image, w, h, NULL); if (title) { int text_w, text_h; iupdrvFontGetMultiLineStringSize(ih, title, &text_w, &text_h); if (ih->data->img_position == IUP_IMGPOS_RIGHT || ih->data->img_position == IUP_IMGPOS_LEFT) { *w += text_w + ih->data->spacing; *h = iupMAX(*h, text_h); } else { *w = iupMAX(*w, text_w); *h += text_h + ih->data->spacing; } } } else if (title) iupdrvFontGetMultiLineStringSize(ih, title, w, h); *w += 2 * ih->data->horiz_padding; *h += 2 * ih->data->vert_padding; *w += 2 * ih->data->border_width; *h += 2 * ih->data->border_width; } (void)children_expand; /* unset if not a container */ }
static void iLabelComputeNaturalSizeMethod(Ihandle* ih, int *w, int *h, int *children_expand) { int natural_w = 0, natural_h = 0, type = iupLabelGetTypeBeforeMap(ih); (void)children_expand; /* unset if not a container */ if (type == IUP_LABEL_SEP_HORIZ) natural_h = 2; else if (type == IUP_LABEL_SEP_VERT) natural_w = 2; else if (type == IUP_LABEL_IMAGE) { iupImageGetInfo(iupAttribGet(ih, "IMAGE"), &natural_w, &natural_h, NULL); natural_w += 2*ih->data->horiz_padding; natural_h += 2*ih->data->vert_padding; } else /* IUP_LABEL_TEXT */ { /* must use IupGetAttribute to check from the native implementation */ char* title = IupGetAttribute(ih, "TITLE"); char* str = iupStrProcessMnemonic(title, NULL, 0); /* remove & */ iupdrvFontGetMultiLineStringSize(ih, str, &natural_w, &natural_h); if (str && str!=title) free(str); natural_w += 2*ih->data->horiz_padding; natural_h += 2*ih->data->vert_padding; } *w = natural_w; *h = natural_h; }
static void iLabelComputeNaturalSizeMethod(Ihandle* ih, int *w, int *h, int *expand) { int natural_w = 0, natural_h = 0, type = ih->data->type; (void)expand; /* unset if not a container */ if (!ih->handle) { /* if not mapped must initialize the internal values */ char* value = iupAttribGet(ih, "SEPARATOR"); if (value) { if (iupStrEqualNoCase(value, "HORIZONTAL")) type = IUP_LABEL_SEP_HORIZ; else /* "VERTICAL" */ type = IUP_LABEL_SEP_VERT; } else { value = iupAttribGet(ih, "IMAGE"); if (value) type = IUP_LABEL_IMAGE; else type = IUP_LABEL_TEXT; } } if (type == IUP_LABEL_SEP_HORIZ) natural_h = 2; else if (type == IUP_LABEL_SEP_VERT) natural_w = 2; else if (type == IUP_LABEL_IMAGE) { iupImageGetInfo(iupAttribGet(ih, "IMAGE"), &natural_w, &natural_h, NULL); natural_w += 2*ih->data->horiz_padding; natural_h += 2*ih->data->vert_padding; } else /* IUP_LABEL_TEXT */ { /* must use IupGetAttribute to check from the native implementation */ char* title = IupGetAttribute(ih, "TITLE"); char* str = iupStrProcessMnemonic(title, NULL, 0); /* remove & */ iupdrvFontGetMultiLineStringSize(ih, str, &natural_w, &natural_h); if (str && str!=title) free(str); natural_w += 2*ih->data->horiz_padding; natural_h += 2*ih->data->vert_padding; } *w = natural_w; *h = natural_h; }
static void iListGetItemImageInfo(Ihandle *ih, int id, int *img_w, int *img_h) { char str[20]; char *value; *img_w = 0; *img_h = 0; sprintf(str, "IMAGE%d", id); value = iupAttribGet(ih, str); if (value) iupImageGetInfo(value, img_w, img_h, NULL); }
static void iToggleComputeNaturalSizeMethod(Ihandle* ih, int *w, int *h, int *children_expand) { int natural_w = 0, natural_h = 0, type = ih->data->type; (void)children_expand; /* unset if not a container */ if (!ih->handle) { /* if not mapped must initialize the internal values */ char* value = iupAttribGet(ih, "IMAGE"); if (value) type = IUP_TOGGLE_IMAGE; else type = IUP_TOGGLE_TEXT; } if (type == IUP_TOGGLE_IMAGE) { iupImageGetInfo(iupAttribGet(ih, "IMAGE"), &natural_w, &natural_h, NULL); /* even when IMPRESS is set, must compute the borders space */ iupdrvButtonAddBorders(&natural_w, &natural_h); natural_w += 2*ih->data->horiz_padding; natural_h += 2*ih->data->vert_padding; } else /* IUP_TOGGLE_TEXT */ { /* must use IupGetAttribute to check from the native implementation */ char* title = IupGetAttribute(ih, "TITLE"); char* str = iupStrProcessMnemonic(title, NULL, 0); /* remove & */ iupdrvFontGetMultiLineStringSize(ih, str, &natural_w, &natural_h); iupdrvToggleAddCheckBox(&natural_w, &natural_h, str); if (str && str != title) free(str); } *w = natural_w; *h = natural_h; }
static void iListGetItemImageInfo(Ihandle *ih, int id, int *img_w, int *img_h) { *img_w = 0; *img_h = 0; if (!ih->handle) { char *value = iupAttribGetId(ih, "IMAGE", id); if (value) iupImageGetInfo(value, img_w, img_h, NULL); } else { void* handle = iupdrvListGetImageHandle(ih, id); if (handle) { int bpp; iupdrvImageGetInfo(handle, img_w, img_h, &bpp); } } }
static void iButtonComputeNaturalSizeMethod(Ihandle* ih, int *w, int *h, int *children_expand) { int natural_w = 0, natural_h = 0, type = ih->data->type; (void)children_expand; /* unset if not a container */ if (!ih->handle) { /* if not mapped must initialize the internal values */ char* value = iupAttribGet(ih, "IMAGE"); if (value) { char* title = iupAttribGet(ih, "TITLE"); type = IUP_BUTTON_IMAGE; if (title && *title!=0) type |= IUP_BUTTON_TEXT; } else type = IUP_BUTTON_TEXT; } if (type & IUP_BUTTON_IMAGE) { iupImageGetInfo(iupAttribGet(ih, "IMAGE"), &natural_w, &natural_h, NULL); if (type & IUP_BUTTON_TEXT) { int text_w, text_h; /* must use IupGetAttribute to check from the native implementation */ char* title = IupGetAttribute(ih, "TITLE"); iupdrvFontGetMultiLineStringSize(ih, title, &text_w, &text_h); if (ih->data->img_position == IUP_IMGPOS_RIGHT || ih->data->img_position == IUP_IMGPOS_LEFT) { natural_w += text_w + ih->data->spacing; natural_h = iupMAX(natural_h, text_h); } else { natural_w = iupMAX(natural_w, text_w); natural_h += text_h + ih->data->spacing; } } } else /* IUP_BUTTON_TEXT only */ { /* must use IupGetAttribute to check from the native implementation */ char* title = IupGetAttribute(ih, "TITLE"); char* str = iupStrProcessMnemonic(title, NULL, 0); /* remove & */ iupdrvFontGetMultiLineStringSize(ih, str, &natural_w, &natural_h); if (str && str!=title) free(str); } /* if IMPRESS is set, do NOT compute the borders space */ if (!((type == IUP_BUTTON_IMAGE) && iupAttribGet(ih, "IMPRESS") && !iupAttribGetBoolean(ih, "IMPRESSBORDER"))) iupdrvButtonAddBorders(&natural_w, &natural_h); natural_w += 2*ih->data->horiz_padding; natural_h += 2*ih->data->vert_padding; *w = natural_w; *h = natural_h; }