static void iMatrixUndoListUpdate(ImatExData* matex_data, Ihandle* ih_list) { int pos, item; char* undostr = IupGetLanguageString("IUP_UNDONAME"); char* redostr = IupGetLanguageString("IUP_REDONAME"); int undo_stack_count = iupArrayCount(matex_data->undo_stack); IundoData* undo_stack_data = (IundoData*)iupArrayGetData(matex_data->undo_stack); item = 1; for (pos=0; pos<matex_data->undo_stack_pos; pos++) { IupSetfAttributeId(ih_list, "", item, "%s: %s", undostr, undo_stack_data[pos].name); item++; } IupSetStrAttributeId(ih_list, "", item, "_@IUP_CURRENTSTATE"); item++; for (pos=matex_data->undo_stack_pos; pos<undo_stack_count; pos++) { IupSetfAttributeId(ih_list, "", item, "%s: %s", redostr, undo_stack_data[pos].name); item++; } IupSetAttributeId(ih_list, "", item, NULL); /* stack+current+null */ }
void iupShowError(Ihandle* parent, const char* message) { Ihandle* dlg = IupMessageDlg(); char* title = NULL, *str_message; if (parent) { IupSetAttributeHandle(dlg, "PARENTDIALOG", parent); title = IupGetAttribute(parent, "TITLE"); } if (!title) title = "_@IUP_ERROR"; IupSetStrAttribute(dlg, "TITLE", title); IupSetAttribute(dlg, "DIALOGTYPE", "ERROR"); IupSetAttribute(dlg, "BUTTONS", "OK"); str_message = IupGetLanguageString(message); if (!str_message) str_message = (char*)message; IupStoreAttribute(dlg, "VALUE", str_message); IupPopup(dlg, IUP_CURRENT, IUP_CURRENT); IupDestroy(dlg); }
static void ShowFormulaError(Ihandle* ih, lua_State *L) { const char* str_message = IupGetLanguageString("IUP_ERRORINVALIDFORMULA"); const char* error = lua_tostring(L, -1); char msg[1024]; sprintf(msg, "%s\n Lua error: %s", str_message, error); IupMessageError(IupGetDialog(ih), msg); }
static void iMatrixExUndoDataInit(IundoData* undo_data, const char* name) { undo_data->cell_count = 0; undo_data->name = name; undo_data->data_table = iupTableCreate(IUPTABLE_STRINGINDEXED); if (name) { char str[50] = "IUP_"; strcat(str, name); name = IupGetLanguageString(str); if (name != str) undo_data->name = name; } }
static int gtkMessageDlgPopup(Ihandle* ih, int x, int y) { InativeHandle* parent = iupDialogGetNativeParent(ih); GtkMessageType type = GTK_MESSAGE_OTHER; GtkWidget* dialog; char *icon, *buttons, *title; const char *ok, *cancel, *yes, *no, *help, *retry = IupGetLanguageString("IUP_RETRY"); int response, button_def; iupAttribSetInt(ih, "_IUPDLG_X", x); /* used in iupDialogUpdatePosition */ iupAttribSetInt(ih, "_IUPDLG_Y", y); icon = iupAttribGetStr(ih, "DIALOGTYPE"); if (iupStrEqualNoCase(icon, "ERROR")) type = GTK_MESSAGE_ERROR; else if (iupStrEqualNoCase(icon, "WARNING")) type = GTK_MESSAGE_WARNING; else if (iupStrEqualNoCase(icon, "INFORMATION")) type = GTK_MESSAGE_INFO; else if (iupStrEqualNoCase(icon, "QUESTION")) type = GTK_MESSAGE_QUESTION; dialog = gtk_message_dialog_new((GtkWindow*)parent, 0, type, GTK_BUTTONS_NONE, "%s", iupgtkStrConvertToSystem(iupAttribGet(ih, "VALUE"))); if (!dialog) return IUP_ERROR; title = iupAttribGet(ih, "TITLE"); if (title) gtk_window_set_title(GTK_WINDOW(dialog), iupgtkStrConvertToSystem(title)); #if GTK_CHECK_VERSION(3, 10, 0) ok = "_OK"; cancel = "_Cancel"; yes = "_Yes"; no = "_No"; help = "_Help"; #else ok = GTK_STOCK_OK; cancel = GTK_STOCK_CANCEL; yes = GTK_STOCK_YES; no = GTK_STOCK_NO; help = GTK_STOCK_HELP; #endif buttons = iupAttribGetStr(ih, "BUTTONS"); if (iupStrEqualNoCase(buttons, "OKCANCEL")) { gtk_dialog_add_button(GTK_DIALOG(dialog), ok, IUP_RESPONSE_1); gtk_dialog_add_button(GTK_DIALOG(dialog), cancel, IUP_RESPONSE_2); } if (iupStrEqualNoCase(buttons, "RETRYCANCEL")) { gtk_dialog_add_button(GTK_DIALOG(dialog), retry, IUP_RESPONSE_1); gtk_dialog_add_button(GTK_DIALOG(dialog), cancel, IUP_RESPONSE_2); } else if (iupStrEqualNoCase(buttons, "YESNO")) { gtk_dialog_add_button(GTK_DIALOG(dialog), yes, IUP_RESPONSE_1); gtk_dialog_add_button(GTK_DIALOG(dialog), no, IUP_RESPONSE_2); } else if (iupStrEqualNoCase(buttons, "YESNOCANCEL")) { gtk_dialog_add_button(GTK_DIALOG(dialog), yes, IUP_RESPONSE_1); gtk_dialog_add_button(GTK_DIALOG(dialog), no, IUP_RESPONSE_2); gtk_dialog_add_button(GTK_DIALOG(dialog), cancel, IUP_RESPONSE_3); } else /* OK */ { gtk_dialog_add_button(GTK_DIALOG(dialog), ok, IUP_RESPONSE_1); } if (IupGetCallback(ih, "HELP_CB")) gtk_dialog_add_button(GTK_DIALOG(dialog), help, IUP_RESPONSE_HELP); button_def = iupAttribGetInt(ih, "BUTTONDEFAULT"); if (button_def == 3) gtk_dialog_set_default_response(GTK_DIALOG(dialog), IUP_RESPONSE_3); else if (button_def == 2) gtk_dialog_set_default_response(GTK_DIALOG(dialog), IUP_RESPONSE_2); else gtk_dialog_set_default_response(GTK_DIALOG(dialog), IUP_RESPONSE_1); /* initialize the widget */ gtk_widget_realize(dialog); ih->handle = dialog; iupDialogUpdatePosition(ih); ih->handle = NULL; do { response = gtk_dialog_run(GTK_DIALOG(dialog)); if (response == IUP_RESPONSE_HELP) { Icallback cb = IupGetCallback(ih, "HELP_CB"); if (cb && cb(ih) == IUP_CLOSE) { if (iupStrEqualNoCase(buttons, "YESNOCANCEL")) response = IUP_RESPONSE_3; else if(iupStrEqualNoCase(buttons, "OK")) response = IUP_RESPONSE_1; else response = IUP_RESPONSE_2; } } } while (response == IUP_RESPONSE_HELP); if (response == IUP_RESPONSE_3) IupSetAttribute(ih, "BUTTONRESPONSE", "3"); else if (response == IUP_RESPONSE_2) IupSetAttribute(ih, "BUTTONRESPONSE", "2"); else IupSetAttribute(ih, "BUTTONRESPONSE", "1"); gtk_widget_destroy(dialog); return IUP_NOERROR; }
int IupPlotSetFormula(Ihandle* ih, int sample_count, const char* formula, const char* init) { lua_State *L; int i, ds_index, ret_count = 1; double min, max, step, p, x, y; char formula_func[1024]; IFnL init_cb; iupASSERT(iupObjectCheck(ih)); if (!iupObjectCheck(ih)) return -1; /* must be an IupMatrix */ if (ih->iclass->nativetype != IUP_TYPECANVAS || !IupClassMatch(ih, "plot")) return -1; L = luaL_newstate(); luaL_openlibs(L); { const char* register_global = "function openpackage(ns)\n" " for n, v in pairs(ns) do _G[n] = v end\n" "end\n" "openpackage(math)\n"; luaL_dostring(L, register_global); } if (init) luaL_dostring(L, init); init_cb = (IFnL)IupGetCallback(ih, "FORMULAINIT_CB"); if (init_cb) init_cb(ih, L); lua_pushlightuserdata(L, ih); lua_setglobal(L, "plot"); if (IupGetInt(ih, "FORMULA_PARAMETRIC")) ret_count = 2; sprintf(formula_func, "function plot_formula(sample_index, %s)\n" " return %s\n" "end\n", ret_count == 2 ? "t" : "x", formula); if (luaL_dostring(L, formula_func) != 0) { ShowFormulaError(ih, L); lua_close(L); return -1; } min = IupGetDouble(ih, "FORMULA_MIN"); max = IupGetDouble(ih, "FORMULA_MAX"); step = (max - min) / (double)(sample_count - 1); IupPlotBegin(ih, 0); for (i = 0, p = min; i < sample_count; i++, p += step) { lua_getglobal(L, "plot_formula"); lua_pushinteger(L, i); lua_pushnumber(L, p); if (lua_pcall(L, 2, ret_count, 0) != 0) { ShowFormulaError(ih, L); lua_close(L); return -1; } if (!lua_isnumber(L, -1)) { const char* str_message = IupGetLanguageString("IUP_ERRORINVALIDFORMULA"); IupMessageError(IupGetDialog(ih), str_message); lua_close(L); return -1; } if (ret_count == 2) { if (!lua_isnumber(L, -2)) { const char* str_message = IupGetLanguageString("IUP_ERRORINVALIDFORMULA"); IupMessageError(IupGetDialog(ih), str_message); lua_close(L); return -1; } x = lua_tonumber(L, -2); y = lua_tonumber(L, -1); lua_pop(L, 2); /* remove the result from the stack */ } else { x = p; y = lua_tonumber(L, -1); lua_pop(L, 1); /* remove the result from the stack */ } IupPlotAdd(ih, x, y); } ds_index = IupPlotEnd(ih); lua_close(L); return ds_index; }
static int GetLanguageString(lua_State *L) { lua_pushstring(L, IupGetLanguageString(luaL_checkstring(L,1))); return 1; }