static int param_action(Ihandle* dialog, int param_index, void* user_data) { switch(param_index) { case IUP_GETPARAM_OK: printf("IupGetParam - OK\n"); break; case IUP_GETPARAM_INIT: { Ihandle* param = (Ihandle*)IupGetAttributeId(dialog, "PARAM", param_index); IupSetfAttribute(param, "MAXSTR", "%d", 30); printf("IupGetParam - Map\n"); break; } case IUP_GETPARAM_CANCEL: printf("IupGetParam - Cancel\n"); break; case IUP_GETPARAM_HELP: printf("IupGetParam - Help\n"); break; // case 1: // return 0; default: { Ihandle* param = (Ihandle*)IupGetAttributeId(dialog, "PARAM", param_index); printf("PARAM%d = %s\n", param_index, IupGetAttribute(param, "VALUE")); break; } } return 1; }
static void iMatrixEditInitMenu(Ihandle* ih_menu) { char *value; int i = 1; int v = IupGetInt(ih_menu, "VALUE"); do { value = IupGetAttributeId(ih_menu, "", i); if (value) { Ihandle* item = IupItem(value, NULL); char* img = IupGetAttributeId(ih_menu, "IMAGE", i); if (img) IupSetAttribute(item, "IMAGE", img); IupSetCallback(item, "ACTION", (Icallback)iMatrixMenuItemAction_CB); if (v == i) /* if v==0 no mark will be shown */ IupSetAttribute(item, "VALUE", "On"); IupAppend(ih_menu, item); } i++; } while (value); }
static long iPlotGetSampleColorTable(Ihandle* ih, int index) { char* value = IupGetAttributeId(ih, "SAMPLECOLOR", index); long color; if (iupStrToColor(value, &color)) return color; switch (index % 12) { case 0: return cdEncodeColor(220, 60, 20); case 1: return cdEncodeColor(0, 128, 0); case 2: return cdEncodeColor(20, 100, 220); case 3: return cdEncodeColor(220, 128, 0); case 4: return cdEncodeColor(128, 0, 128); case 5: return cdEncodeColor(0, 128, 220); case 6: return cdEncodeColor(220, 60, 128); case 7: return cdEncodeColor(128, 220, 0); case 8: return cdEncodeColor(192, 60, 60); case 9: return cdEncodeColor(60, 60, 128); case 10: return cdEncodeColor(220, 60, 220); case 11: return cdEncodeColor(60, 128, 128); } return 0; }
static int selection_cb(Ihandle *ih, int id, int status) { (void)ih; printf("SELECTION_CB(id=%d, status=%d)\n", id, status); printf(" USERDATA=%s\n", IupGetAttributeId(ih, "USERDATA", id)); return IUP_DEFAULT; }
static int GetParamParam(lua_State *L) { Ihandle *dialog = iuplua_checkihandle(L, 1); int param_index = (int)luaL_checkinteger(L, 2); Ihandle* param = (Ihandle*)IupGetAttributeId(dialog, "PARAM", param_index); iuplua_pushihandle(L, param); return 1; }
float IupGetFloatId(Ihandle *ih, const char* name, int id) { float f = 0; char *value = IupGetAttributeId(ih, name, id); if (value) iupStrToFloat(value, &f); return f; }
static int GetAttributeId(lua_State *L) { Ihandle *ih = iuplua_checkihandle(L,1); const char *name = luaL_checkstring(L,2); int id = (int)luaL_checkinteger(L,3); const char *value = IupGetAttributeId(ih, name, id); iuplua_pushvalue(L, ih, name, value); return 1; }
static char* iListGetValueStringAttrib(Ihandle* ih) { if (!ih->data->has_editbox && (ih->data->is_dropdown || !ih->data->is_multiple)) { int i = IupGetInt(ih, "VALUE"); return IupGetAttributeId(ih, "", i); } return NULL; }
static char* iMatrixExGetNumericQuantityAttrib(Ihandle* ih, int col) { if (!IupGetAttributeId(ih, "NUMERICQUANTITYINDEX", col)) return NULL; else { int quantity = IupGetIntId(ih, "NUMERICQUANTITYINDEX", col); return (char*)imatex_quantities[quantity].q_name; } }
void iupListSingleCallDblClickCb(Ihandle* ih, IFnis cb, int pos) { char *text; if (pos<=0) return; text = IupGetAttributeId(ih, "", pos); if (cb(ih, pos, text) == IUP_CLOSE) IupExitLoop(); }
static int iColorDlgColorTableSelect_CB(Ihandle* ih, int cell, int type) { IcolorDlgData* colordlg_data = (IcolorDlgData*)iupAttribGetInherit(ih, "_IUP_GC_DATA"); iupStrToRGB(IupGetAttributeId(ih, "CELL", cell), &colordlg_data->red, &colordlg_data->green, &colordlg_data->blue); iColorDlgRGB_TXT_Update(colordlg_data); iColorDlgRGBChanged(colordlg_data); (void)type; return IUP_DEFAULT; }
static void iListCallActionCallback(Ihandle* ih, IFnsii cb, int pos, int state) { char *text; if (pos<=0) return; text = IupGetAttributeId(ih, "", pos); if (cb(ih, text, pos, state) == IUP_CLOSE) IupExitLoop(); }
int IupGetIntId(Ihandle *ih, const char* name, int id) { int i = 0; char *value = IupGetAttributeId(ih, name, id); if (value) { if (!iupStrToInt(value, &i)) { if (iupStrBoolean(value)) i = 1; } } return i; }
static char* iColorDlgGetColorTableAttrib(Ihandle* ih) { int i, inc, off = 0; IcolorDlgData* colordlg_data = (IcolorDlgData*)iupAttribGetInherit(ih, "_IUP_GC_DATA"); char* color_str; char* str = iupStrGetMemory(COLORTABLE_MAX * 3 * 20); for (i = 0; i < COLORTABLE_MAX; i++) { color_str = IupGetAttributeId(colordlg_data->colortable_cbar, "CELL", i); inc = (int)strlen(color_str); memcpy(str+off, color_str, inc); memcpy(str+off+inc, ";", 1); off += inc+1; } str[off-1] = 0; /* remove last separator */ return str; }
static void cdIupInitPalette(Ihandle* image, long* palette, long bgcolor, int make_inactive) { int i; unsigned char r, g, b, bg_r, bg_g, bg_b; cdDecodeColor(bgcolor, &bg_r, &bg_g, &bg_b); for(i = 0; i < 256; i++) { char* color = IupGetAttributeId(image, "", i); r = bg_r; g = bg_g; b = bg_b; iupStrToRGB(color, &r, &g, &b); /* no need to test for BGCOLOR, if this failed it will not set the parameters */ if (make_inactive) iupImageColorMakeInactive(&r, &g, &b, bg_r, bg_g, bg_b); palette[i] = cdEncodeColor(r, g, b); } }
static int iListSetValueStringAttrib(Ihandle* ih, const char* value) { if (!ih->data->has_editbox && (ih->data->is_dropdown || !ih->data->is_multiple)) { int i, count = iListGetCount(ih); for (i = 1; i <= count; i++) { char* item = IupGetAttributeId(ih, "", i); if (iupStrEqual(value, item)) { IupSetInt(ih, "VALUE", i); return 0; } } } return 0; }
static void motFontDlgSelectFontFace(Ihandle* ih, char* fontface, int select) { Ihandle* sample = IupGetDialogChild(ih, "SAMPLE"); char* style = IupGetAttribute(sample, "FONTSTYLE"); int size = IupGetInt(sample, "FONTSIZE"); Ihandle* list1 = IupGetDialogChild(ih, "LIST1"); Ihandle* list2 = IupGetDialogChild(ih, "LIST2"); int i, count, is_bold, is_italic; motFontDlgInitSizeList(ih, fontface, size); if (select) { /* find the fontface in the list and select it */ count = IupGetInt(list1, "COUNT"); for (i=0; i<count; i++) { if (iupStrEqualNoCase(fontface, IupGetAttributeId(list1, "", i+1))) { IupSetfAttribute(list1, "VALUE", "%d", i+1); IupSetfAttribute(list1, "TOPITEM", "%d", i+1); break; } } } is_bold = strstr(style, "Bold")!=NULL; is_italic = strstr(style, "Italic")!=NULL; if (is_bold && is_italic) IupSetAttribute(list2, "VALUE", "4"); else if (is_italic) IupSetAttribute(list2, "VALUE", "3"); else if (is_bold) IupSetAttribute(list2, "VALUE", "2"); else IupSetAttribute(list2, "VALUE", "1"); }
static int GetAttributeId(lua_State *L) { Ihandle *ih = iuplua_checkihandle(L,1); const char *name = luaL_checkstring(L,2); int id = luaL_checkint(L,3); const char *value = IupGetAttributeId(ih, name, id); if (!value || iupATTRIB_ISINTERNAL(name)) lua_pushnil(L); else { if (iupAttribIsPointer(ih, name)) { if (ih->handle == (InativeHandle*)value) /* work around for WID, sometimes WID in Windows is not a valid pointer. Why? */ iuplua_pushihandle(L, ih); else if (iupObjectCheck((Ihandle*)value)) iuplua_pushihandle(L, (Ihandle*)value); else lua_pushlightuserdata(L, (void*)value); } else lua_pushstring(L,value); } return 1; }
static void iListGetNaturalItemsSize(Ihandle *ih, int *w, int *h) { char *value; int max_w = 0, max_h = 0; int visiblecolumns, i, count = iListGetCount(ih); *w = 0; *h = 0; iupdrvFontGetCharSize(ih, w, h); /* one line height, and one character width */ visiblecolumns = iupAttribGetInt(ih, "VISIBLECOLUMNS"); if (visiblecolumns) { *w = iupdrvFontGetStringWidth(ih, "WWWWWWWWWW"); *w = (visiblecolumns*(*w))/10; } else { int item_w; for (i=1; i<=count; i++) { item_w = 0; value = IupGetAttributeId(ih, "", i); /* must use IupGetAttribute to check the native system */ if (value) item_w = iupdrvFontGetStringWidth(ih, value); if (item_w > *w) *w = item_w; } if (*w == 0) /* default is 5 characters in 1 item */ *w = iupdrvFontGetStringWidth(ih, "WWWWW"); } if (ih->data->show_image) { for (i=1; i<=count; i++) { int img_w, img_h; iListGetItemImageInfo(ih, i, &img_w, &img_h); if (img_w > max_w) max_w = img_w; if (img_h > max_h) max_h = img_h; } /* Used only in Windows */ ih->data->maximg_w = max_w; ih->data->maximg_h = max_h; *w += max_w; } /* compute height for multiple lines, dropdown is just 1 line */ if (!ih->data->is_dropdown) { int visiblelines, num_lines, edit_line_size = *h; /* don't include the highest image */ if (ih->data->show_image && max_h > *h) /* use the highest image to compute the natural size */ *h = max_h; iupdrvListAddItemSpace(ih, h); /* this is independent from spacing */ *h += 2*ih->data->spacing; /* this will be multiplied by the number of lines */ *w += 2*ih->data->spacing; /* include also horizontal spacing */ num_lines = count; if (num_lines == 0) num_lines = 1; visiblelines = iupAttribGetInt(ih, "VISIBLELINES"); if (visiblelines) num_lines = visiblelines; *h = *h * num_lines; if (ih->data->has_editbox) *h += edit_line_size; } else { if (!ih->data->has_editbox) { if (ih->data->show_image && max_h > *h) /* use the highest image to compute the natural size */ *h = max_h; } } }
int iupMatrixEditShowXY(Ihandle* ih, int x, int y) { char* mask; /* work around for Windows when using Multiline */ if (iupAttribGet(ih, "_IUPMAT_IGNORE_SHOW")) { iupAttribSet(ih, "_IUPMAT_IGNORE_SHOW", NULL); return 0; } /* there are no cells that can be edited */ if (ih->data->columns.num <= 1 || ih->data->lines.num <= 1) return 0; if (ih->data->editing || iupMatrixEditIsVisible(ih)) { if (ih->data->edit_hide_onfocus) return 0; iupMatrixEditHide(ih); } ih->data->edit_lin = ih->data->lines.focus_cell; ih->data->edit_col = ih->data->columns.focus_cell; /* notify application */ if (iMatrixEditCallEditionCbUpdateValue(ih, 1, 0) == IUP_IGNORE) /* only place where mode=1 */ return 0; if (iMatrixEditCallMenuDropCb(ih, ih->data->edit_lin, ih->data->edit_col)) return 0; ih->data->editing = 1; /* select edit control */ iMatrixEditChooseElement(ih); /* position the cell to make it visible */ /* If the focus is not visible, a scroll is done for that the focus to be visible */ if (!iupMatrixAuxIsCellStartVisible(ih, ih->data->edit_lin, ih->data->edit_col)) iupMatrixScrollToVisible(ih, ih->data->edit_lin, ih->data->edit_col); /* set attributes */ iupMatrixPrepareDrawData(ih); IupStoreAttribute(ih->data->datah, "BGCOLOR", iupMatrixGetBgColorStr(ih, ih->data->edit_lin, ih->data->edit_col)); IupStoreAttribute(ih->data->datah, "FGCOLOR", iupMatrixGetFgColorStr(ih, ih->data->edit_lin, ih->data->edit_col)); IupSetAttribute(ih->data->datah, "FONT", iupMatrixGetFont(ih, ih->data->edit_lin, ih->data->edit_col)); mask = IupGetAttributeId2(ih, "MASK", ih->data->edit_lin, ih->data->edit_col); if (mask) { IupSetAttribute(ih->data->datah, "MASKCASEI", IupGetAttributeId2(ih, "MASKCASEI", ih->data->edit_lin, ih->data->edit_col)); IupSetAttribute(ih->data->datah, "MASKNOEMPTY", IupGetAttributeId2(ih, "MASKNOEMPTY", ih->data->edit_lin, ih->data->edit_col)); IupSetAttribute(ih->data->datah, "MASK", mask); } else { mask = IupGetAttributeId2(ih, "MASKINT", ih->data->edit_lin, ih->data->edit_col); if (mask) IupSetAttribute(ih->data->datah, "MASKINT", mask); else { mask = IupGetAttributeId2(ih, "MASKFLOAT", ih->data->edit_lin, ih->data->edit_col); if (mask) IupSetAttribute(ih->data->datah, "MASKFLOAT", mask); else IupSetAttribute(ih->data->datah, "MASK", NULL); } } iupMatrixEditUpdatePos(ih); /* activate and show */ IupSetAttribute(ih->data->datah, "ACTIVE", "YES"); IupSetAttribute(ih->data->datah, "VISIBLE", "YES"); IupSetFocus(ih->data->datah); if (ih->data->datah == ih->data->texth) { if (iupAttribGetBoolean(ih, "EDITALIGN")) IupSetStrAttribute(ih->data->datah, "ALIGNMENT", IupGetAttributeId(ih, "ALIGNMENT", ih->data->edit_col)); if (x || y) { int pos; x -= ih->data->datah->x; y -= ih->data->datah->y; pos = IupConvertXYToPos(ih->data->datah, x, y); IupSetInt(ih->data->datah, "CARETPOS", pos); } } return 1; }
void IupCopyClassAttributes(Ihandle* src_ih, Ihandle* dst_ih) { int has_attrib_id, start_id = 0; Iclass* ic; char *name; iupASSERT(iupObjectCheck(src_ih)); if (!iupObjectCheck(src_ih)) return; iupASSERT(iupObjectCheck(dst_ih)); if (!iupObjectCheck(dst_ih)) return; if (!IupClassMatch(dst_ih, src_ih->iclass->name)) return; ic = src_ih->iclass; has_attrib_id = ic->has_attrib_id; if (iupClassMatch(ic, "tree") || /* tree can only set id attributes after map, so they can not be saved */ iupClassMatch(ic, "cells")) /* cells does not have any saveable id attributes */ has_attrib_id = 0; if (iupClassMatch(ic, "list")) start_id = 1; name = iupTableFirst(ic->attrib_func); while (name) { IattribFunc* afunc = (IattribFunc*)iupTableGet(ic->attrib_func, name); if (afunc && !(afunc->flags & IUPAF_NO_STRING) && /* is a string */ !(afunc->flags & IUPAF_READONLY) && /* not read-only */ !(afunc->flags & IUPAF_WRITEONLY) && /* not write-only */ !(afunc->flags & IUPAF_CALLBACK)) /* not a callback */ { if ((afunc->flags&IUPAF_NO_SAVE) && iupBaseNoSaveCheck(src_ih, name)) /* can not be saved */ { name = iupTableNext(ic->attrib_func); continue; } if (!(afunc->flags & IUPAF_HAS_ID)) /* no ID */ { char *value = IupGetAttribute(src_ih, name); if (value && value[0]) /* NOT NULL and not empty */ { if (!iupStrEqualNoCase(value, IupGetAttribute(dst_ih, name))) /* NOT already equal */ IupStoreAttribute(dst_ih, name, value); } } else if (has_attrib_id) { char *value; if (iupStrEqual(name, "IDVALUE")) name = ""; if (afunc->flags&IUPAF_HAS_ID2) { int lin, col, numcol = IupGetInt(src_ih, "NUMCOL")+1, numlin = IupGetInt(src_ih, "NUMLIN")+1; for (lin=0; lin<numlin; lin++) { for (col=0; col<numcol; col++) { value = IupGetAttributeId2(src_ih, name, lin, col); if (value && value[0]) /* NOT NULL and not empty */ { if (!iupStrEqualNoCase(value, IupGetAttributeId2(dst_ih, name, lin, col))) /* NOT already stored */ IupStoreAttributeId2(dst_ih, name, lin, col, value); } } } } else { int id, count = IupGetInt(src_ih, "COUNT"); for (id=start_id; id<count+start_id; id++) { value = IupGetAttributeId(src_ih, name, id); if (value && value[0]) /* NOT NULL and not empty */ { if (!iupStrEqualNoCase(value, IupGetAttributeId(dst_ih, name, id))) /* NOT already stored */ IupStoreAttributeId(dst_ih, name, id, value); } } } } } name = iupTableNext(ic->attrib_func); } name = iupTableFirst(ic->attrib_func); while (name) { IattribFunc* afunc = (IattribFunc*)iupTableGet(ic->attrib_func, name); if (afunc && !(afunc->flags & IUPAF_NO_STRING) && /* is a string */ !(afunc->flags & IUPAF_READONLY) && !(afunc->flags & IUPAF_WRITEONLY) && !(afunc->flags & IUPAF_HAS_ID) && !(afunc->flags & IUPAF_CALLBACK)) { char *value = IupGetAttribute(src_ih, name); if (value && /* NOT NULL */ !iupStrEqualNoCase(value, IupGetAttribute(dst_ih, name))) /* NOT already stored */ IupStoreAttribute(dst_ih, name, value); } name = iupTableNext(ic->attrib_func); } }
char* IupTreeGetAttribute(Ihandle* ih, const char* a, int id) { return IupGetAttributeId(ih, a, id); }