static Ihandle* iMatrixExUndoCreateDialog(ImatExData* matex_data) { Ihandle* dlg, *parent, *list; list = IupList(NULL); IupSetAttribute(list, "EXPAND","YES"); IupSetAttribute(list, "DROPDOWN","NO"); IupSetAttribute(list, "VISIBLECOLUMNS" ,"25"); IupSetAttribute(list, "VISIBLELINES" ,"10"); IupSetCallback (list, "ACTION" ,(Icallback)iMatrixExUndoListAction_CB); iMatrixUndoListUpdate(matex_data, list); parent = IupGetDialog(matex_data->ih); dlg = IupDialog(list); IupSetAttribute(dlg, "MAXBOX" ,"NO"); IupSetAttribute(dlg, "MINBOX" ,"NO"); IupSetAttribute(dlg, "TOOLBOX","YES"); IupSetStrAttribute(dlg, "TITLE" ,"_@IUP_UNDOLIST"); IupSetAttributeHandle(dlg,"PARENTDIALOG", parent); IupSetAttribute(dlg, "MATRIX_EX_DATA", (char*)matex_data); /* do not use "_IUP_MATEX_DATA" to enable inheritance */ if (IupGetAttribute(parent, "ICON")) IupSetStrAttribute(dlg,"ICON", IupGetAttribute(parent, "ICON")); else IupSetStrAttribute(dlg,"ICON", IupGetGlobal("ICON")); return dlg; }
int select_file(Ihandle* parent_dlg, int is_open) { Ihandle* config = (Ihandle*)IupGetAttribute(parent_dlg, "CONFIG"); Ihandle* canvas = IupGetDialogChild(parent_dlg, "CANVAS"); const char* dir = IupConfigGetVariableStr(config, "MainWindow", "LastDirectory"); Ihandle* filedlg = IupFileDlg(); if (is_open) IupSetAttribute(filedlg, "DIALOGTYPE", "OPEN"); else { IupSetAttribute(filedlg, "DIALOGTYPE", "SAVE"); IupSetStrAttribute(filedlg, "FILE", IupGetAttribute(canvas, "FILENAME")); } IupSetAttribute(filedlg, "EXTFILTER", "Image Files|*.bmp;*.jpg;*.png;*.tif;*.tga|All Files|*.*|"); IupSetStrAttribute(filedlg, "DIRECTORY", dir); IupSetAttributeHandle(filedlg, "PARENTDIALOG", parent_dlg); IupPopup(filedlg, IUP_CENTERPARENT, IUP_CENTERPARENT); if (IupGetInt(filedlg, "STATUS") != -1) { char* filename = IupGetAttribute(filedlg, "VALUE"); if (is_open) open_file(parent_dlg, filename); else saveas_file(canvas, filename); dir = IupGetAttribute(filedlg, "DIRECTORY"); IupConfigSetVariableStr(config, "MainWindow", "LastDirectory", dir); } IupDestroy(filedlg); return IUP_DEFAULT; }
void show_error(const char* message, int is_error) { Ihandle* dlg = IupMessageDlg(); IupSetStrAttribute(dlg, "PARENTDIALOG", IupGetGlobal("PARENTDIALOG")); IupSetAttribute(dlg, "DIALOGTYPE", is_error ? "ERROR" : "WARNING"); IupSetAttribute(dlg, "BUTTONS", "OK"); IupSetStrAttribute(dlg, "TITLE", is_error ? "Error" : "Warning"); IupSetStrAttribute(dlg, "VALUE", message); IupPopup(dlg, IUP_CENTERPARENT, IUP_CENTERPARENT); IupDestroy(dlg); }
static void iMatrixListInitSize(Ihandle* ih, ImatrixListData* mtxList) { char str[30]; int num_col = 0; if (mtxList->label_col != 0) num_col++; if (mtxList->color_col != 0) num_col++; if (mtxList->image_col != 0) num_col++; sprintf(str, "%d", num_col); iupMatrixSetNumColAttrib(ih, str); /* "NUMCOL" */ IupSetStrAttribute(ih, "NUMCOL_VISIBLE", str); if (mtxList->color_col != 0) { if (!iupAttribGetId(ih, "WIDTH", mtxList->color_col)) IupSetIntId(ih, "WIDTH", mtxList->color_col, IMTXL_COLOR_WIDTH); } if (mtxList->image_col != 0) { if (!iupAttribGetId(ih, "WIDTH", mtxList->image_col)) IupSetIntId(ih, "WIDTH", mtxList->image_col, IMTXL_IMAGE_WIDTH); } }
static int val_action_cb(Ihandle *ih) { Ihandle* pbar = (Ihandle*)IupGetAttribute(ih, "PROGRESSBAR"); IupSetStrAttribute(pbar, "VALUE", IupGetAttribute(ih, "VALUE")); printf("ACTION_CB(%s, value=%0.1f) NAME=%s\n", IupGetClassName(ih), IupGetFloat(ih, "VALUE"), IupGetAttribute(ih, "NAME")); return IUP_DEFAULT; }
int item_open_action_cb(Ihandle* item_open) { Ihandle* multitext = IupGetDialogChild(item_open, "MULTITEXT"); Ihandle *filedlg = IupFileDlg(); IupSetAttribute(filedlg, "DIALOGTYPE", "OPEN"); IupSetAttribute(filedlg, "FILTER", "*.txt"); IupSetAttribute(filedlg, "FILTERINFO", "Text Files"); IupSetAttributeHandle(filedlg, "PARENTDIALOG", IupGetDialog(item_open)); IupPopup(filedlg, IUP_CENTERPARENT, IUP_CENTERPARENT); if (IupGetInt(filedlg, "STATUS") != -1) { char* filename = IupGetAttribute(filedlg, "VALUE"); char* str = read_file(filename); if (str) { IupSetStrAttribute(multitext, "VALUE", str); free(str); } } IupDestroy(filedlg); return IUP_DEFAULT; }
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); }
void open_file(Ihandle* ih, const char* filename) { char* str = read_file(filename); if (str) { Ihandle* dlg = IupGetDialog(ih); Ihandle* multitext = IupGetDialogChild(dlg, "MULTITEXT"); Ihandle* config = (Ihandle*)IupGetAttribute(multitext, "CONFIG"); IupSetfAttribute(dlg, "TITLE", "%s - Simple Notepad", str_filetitle(filename)); IupSetStrAttribute(multitext, "FILENAME", filename); IupSetAttribute(multitext, "DIRTY", "NO"); IupSetStrAttribute(multitext, "VALUE", str); IupConfigRecentUpdate(config, filename); free(str); } }
int item_font_action_cb(Ihandle* item_font) { Ihandle* multitext = IupGetDialogChild(item_font, "MULTITEXT"); Ihandle* fontdlg = IupFontDlg(); char* font = IupGetAttribute(multitext, "FONT"); IupSetStrAttribute(fontdlg, "VALUE", font); IupSetAttributeHandle(fontdlg, "PARENTDIALOG", IupGetDialog(item_font)); IupPopup(fontdlg, IUP_CENTERPARENT, IUP_CENTERPARENT); if (IupGetInt(fontdlg, "STATUS") == 1) { font = IupGetAttribute(fontdlg, "VALUE"); IupSetStrAttribute(multitext, "FONT", font); } IupDestroy(fontdlg); return IUP_DEFAULT; }
void iuplua_show_error_message(const char *pname, const char* msg) { Ihandle *multi_text, *lbl, *copy, *button, *box, *dlg, *abort, *buttonbox; char* value = IupGetGlobal("LUA_ERROR_LABEL"); if (!pname) pname = "_@IUP_ERROR"; lbl = IupLabel("_@IUP_LUAERROR"); IupSetAttribute(lbl, "EXPAND", "HORIZONTAL"); if (value) IupSetStrAttribute(lbl, "TITLE", value); copy = IupButton("_@IUP_COPY", NULL); IupSetStrAttribute(copy, "TIP", "_@IUP_COPYTOCLIPBOARD"); IupSetStrAttribute(copy, "PADDING", IupGetGlobal("DEFAULTBUTTONPADDING")); IupSetCallback(copy, "ACTION", show_error_copy_action); button = IupButton("_@IUP_CONTINUE", NULL); IupSetStrAttribute(button, "PADDING", IupGetGlobal("DEFAULTBUTTONPADDING")); IupSetCallback(button, "ACTION", show_error_continue_action); abort = IupButton("_@IUP_EXIT", NULL); IupSetStrAttribute(abort, "PADDING", IupGetGlobal("DEFAULTBUTTONPADDING")); IupSetCallback(abort, "ACTION", show_error_exit_action); multi_text = IupMultiLine(NULL); IupSetAttribute(multi_text, "EXPAND", "YES"); IupSetAttribute(multi_text, "READONLY", "YES"); IupSetAttribute(multi_text, "FONT", "Courier, 12"); IupSetAttribute(multi_text, "VISIBLELINES", "10"); IupSetAttribute(multi_text, "VISIBLECOLUMNS", "50"); IupSetAttribute(multi_text, "NAME", "TEXT"); IupSetStrAttribute(multi_text, "VALUE", msg); buttonbox = IupHbox(copy, button, abort, NULL); IupSetAttribute(buttonbox, "GAP", "50"); IupSetAttribute(IupNormalizer(button, abort, NULL), "NORMALIZE", "HORIZONTAL"); box = IupVbox(lbl, multi_text, buttonbox, NULL); IupSetAttribute(box, "ALIGNMENT", "ACENTER"); IupSetAttribute(box, "NMARGIN", "10x10"); IupSetAttribute(box, "GAP", "10"); dlg = IupDialog(box); IupSetStrAttribute(dlg, "TITLE", pname); IupSetAttribute(dlg, "MINBOX", "NO"); IupSetAttribute(dlg, "MAXBOX", "NO"); IupSetAttribute(dlg, "PARENTDIALOG", IupGetGlobal("PARENTDIALOG")); IupSetAttribute(dlg, "ICON", IupGetGlobal("ICON")); IupSetAttributeHandle(dlg, "DEFAULTESC", button); IupSetAttributeHandle(dlg, "DEFAULTENTER", button); IupSetAttributeHandle(dlg, "STARTFOCUS", button); IupPopup(dlg, IUP_CENTERPARENT, IUP_CENTERPARENT); IupDestroy(dlg); }
static int iDetachBoxSetDetachAttrib(Ihandle* ih, const char* value) { int cur_x, cur_y; IFnnii detachedCB = (IFnnii)IupGetCallback(ih, "DETACHED_CB"); /* Create new dialog */ Ihandle *new_parent = IupDialog(NULL); Ihandle *old_dialog = IupGetDialog(ih); /* Set new dialog as child of the current application */ IupSetAttributeHandle(new_parent, "PARENTDIALOG", old_dialog); iupStrToIntInt(IupGetGlobal("CURSORPOS"), &cur_x, &cur_y, 'x'); if (detachedCB) { int ret = detachedCB(ih, new_parent, cur_x, cur_y); if (ret == IUP_IGNORE) { IupDestroy(new_parent); return IUP_DEFAULT; } } /* set user size of the detachbox as the current size of the child */ IupSetStrAttribute(ih, "RASTERSIZE", IupGetAttribute(ih->firstchild->brother, "RASTERSIZE")); /* Save current parent and reference child */ ih->data->old_parent = ih->parent; ih->data->old_brother = ih->brother; IupMap(new_parent); /* Sets the new parent */ IupReparent(ih, new_parent, NULL); /* Hide handler */ IupSetAttribute(ih->firstchild, "VISIBLE", "No"); /* force a dialog resize since IupMap already computed the dialog size */ IupSetAttribute(new_parent, "RASTERSIZE", NULL); /* Maps and shows the new dialog */ IupShowXY(new_parent, cur_x, cur_y); /* reset user size of the detachbox */ IupSetAttribute(ih, "USERSIZE", NULL); /* Updates/redraws the layout of the old dialog */ IupRefresh(old_dialog); (void)value; return 0; }
void saveas_file(Ihandle* multitext, const char* filename) { char* str = IupGetAttribute(multitext, "VALUE"); int count = IupGetInt(multitext, "COUNT"); if (write_file(filename, str, count)) { Ihandle* config = (Ihandle*)IupGetAttribute(multitext, "CONFIG"); IupSetfAttribute(IupGetDialog(multitext), "TITLE", "%s - Simple Notepad", str_filetitle(filename)); IupSetStrAttribute(multitext, "FILENAME", filename); IupSetAttribute(multitext, "DIRTY", "NO"); IupConfigRecentUpdate(config, filename); } }
void saveas_file(Ihandle* canvas, const char* filename) { imImage* image = (imImage*)IupGetAttribute(canvas, "IMAGE"); set_file_format(image, filename); if (write_file(filename, image)) { Ihandle* config = (Ihandle*)IupGetAttribute(canvas, "CONFIG"); IupSetfAttribute(IupGetDialog(canvas), "TITLE", "%s - Simple Paint", str_filetitle(filename)); IupSetStrAttribute(canvas, "FILENAME", filename); IupSetAttribute(canvas, "DIRTY", "NO"); IupConfigRecentUpdate(config, filename); } }
static int winDatePickSetOrderAttrib(Ihandle* ih, const char* value) { int i; char format[50] = ""; char* separator = iupAttribGetStr(ih, "SEPARATOR"); int zeropreced = iupAttribGetBoolean(ih, "ZEROPRECED"); int monthshortnames = iupAttribGetBoolean(ih, "MONTHSHORTNAMES"); if (!value || strlen(value) != 3) return 0; for (i = 0; i < 3; i++) { if (value[i] == 'D' || value[i] == 'd') { if (zeropreced) strcat(format, "dd"); else strcat(format, "d"); } else if (value[i] == 'M' || value[i] == 'm') { if (monthshortnames) strcat(format, "MMM"); else if (zeropreced) strcat(format, "MM"); else strcat(format, "M"); } else if (value[i] == 'Y' || value[i] == 'y') strcat(format, "yyyy"); else return 0; if (i < 2) { strcat(format, "'"); strcat(format, separator); strcat(format, "'"); } } IupSetStrAttribute(ih, "FORMAT", format); return 1; }
void set_new_image(Ihandle* canvas, imImage* image, const char* filename, int dirty) { imImage* old_image = (imImage*)IupGetAttribute(canvas, "IMAGE"); Ihandle* size_lbl = IupGetDialogChild(canvas, "SIZELABEL"); Ihandle* zoom_val = IupGetDialogChild(canvas, "ZOOMVAL"); if (filename) { IupSetStrAttribute(canvas, "FILENAME", filename); IupSetfAttribute(IupGetDialog(canvas), "TITLE", "%s - Simple Paint", str_filetitle(filename)); } else { IupSetAttribute(canvas, "FILENAME", NULL); IupSetAttribute(IupGetDialog(canvas), "TITLE", "Untitled - Simple Paint"); } /* we are going to support only RGB images with no alpha */ imImageRemoveAlpha(image); if (image->color_space != IM_RGB) { imImage* new_image = imImageCreateBased(image, -1, -1, IM_RGB, -1); imConvertColorSpace(image, new_image); imImageDestroy(image); image = new_image; } /* default file format */ const char* format = imImageGetAttribString(image, "FileFormat"); if (!format) imImageSetAttribString(image, "FileFormat", "JPEG"); IupSetAttribute(canvas, "DIRTY", dirty? "Yes": "No"); IupSetAttribute(canvas, "IMAGE", (char*)image); IupSetfAttribute(size_lbl, "TITLE", "%d x %d px", image->width, image->height); if (old_image) imImageDestroy(old_image); IupSetDouble(zoom_val, "VALUE", 0); zoom_update(canvas, 0); }
int item_saveas_action_cb(Ihandle* item_saveas) { Ihandle* multitext = IupGetDialogChild(item_saveas, "MULTITEXT"); Ihandle *filedlg = IupFileDlg(); IupSetAttribute(filedlg, "DIALOGTYPE", "SAVE"); IupSetAttribute(filedlg, "EXTFILTER", "Text Files|*.txt|All Files|*.*|"); IupSetAttributeHandle(filedlg, "PARENTDIALOG", IupGetDialog(item_saveas)); IupSetStrAttribute(filedlg, "FILE", IupGetAttribute(multitext, "FILENAME")); IupPopup(filedlg, IUP_CENTERPARENT, IUP_CENTERPARENT); if (IupGetInt(filedlg, "STATUS") != -1) { char* filename = IupGetAttribute(filedlg, "VALUE"); saveas_file(multitext, filename); } IupDestroy(filedlg); return IUP_DEFAULT; }
int IupGetColor(int x, int y, unsigned char *r, unsigned char *g, unsigned char *b) { int ret; Ihandle* dlg = IupColorDlg(); IupSetStrAttribute(dlg, "TITLE", "_@IUP_GETCOLOR"); IupSetfAttribute(dlg, "VALUE", "%d %d %d", *r, *g, *b); IupSetAttribute(dlg, "PARENTDIALOG", IupGetGlobal("PARENTDIALOG")); IupSetAttribute(dlg, "ICON", IupGetGlobal("ICON")); IupPopup(dlg, x, y); ret = IupGetInt(dlg, "STATUS"); if (ret) iupStrToRGB(IupGetAttribute(dlg, "VALUE"), r, g, b); IupDestroy(dlg); return ret; }
int item_background_action_cb(Ihandle* item_background) { Ihandle* canvas = IupGetDialogChild(item_background, "CANVAS"); Ihandle* config = (Ihandle*)IupGetAttribute(canvas, "CONFIG"); Ihandle* colordlg = IupColorDlg(); const char* background = IupConfigGetVariableStrDef(config, "MainWindow", "Background", "255 255 255"); IupSetStrAttribute(colordlg, "VALUE", background); IupSetAttributeHandle(colordlg, "PARENTDIALOG", IupGetDialog(item_background)); IupPopup(colordlg, IUP_CENTERPARENT, IUP_CENTERPARENT); if (IupGetInt(colordlg, "STATUS") == 1) { background = IupGetAttribute(colordlg, "VALUE"); IupConfigSetVariableStr(config, "MainWindow", "Background", background); IupUpdate(canvas); } IupDestroy(colordlg); return IUP_DEFAULT; }
void open_file(Ihandle* ih, const char* filename) { imImage* image = read_file(filename); if (image) { Ihandle* dlg = IupGetDialog(ih); Ihandle* canvas = IupGetDialogChild(dlg, "CANVAS"); Ihandle* config = (Ihandle*)IupGetAttribute(canvas, "CONFIG"); imImage* old_image = (imImage*)IupGetAttribute(canvas, "IMAGE"); IupSetfAttribute(dlg, "TITLE", "%s - Simple Paint", str_filetitle(filename)); IupSetStrAttribute(canvas, "FILENAME", filename); IupSetAttribute(canvas, "DIRTY", "NO"); IupSetAttribute(canvas, "IMAGE", (char*)image); IupUpdate(canvas); if (old_image) imImageDestroy(old_image); IupConfigRecentUpdate(config, filename); } }
void guiVal_OnInit( void ) { guiVal->tbValue = IupText( NULL ); guiVal->hlType = IupHList( NULL ); IupSetStrAttribute( guiVal->hlType, "1", "schar" ); IupSetStrAttribute( guiVal->hlType, "2", "uchar" ); IupSetStrAttribute( guiVal->hlType, "3", "short" ); IupSetStrAttribute( guiVal->hlType, "4", "ushort" ); IupSetStrAttribute( guiVal->hlType, "5", "int" ); IupSetStrAttribute( guiVal->hlType, "6", "uint" ); IupSetStrAttribute( guiVal->hlType, "7", "long" ); IupSetStrAttribute( guiVal->hlType, "8", "ulong" ); IupSetStrAttribute( guiVal->hlType, "9", "lint" ); IupSetStrAttribute( guiVal->hlType, "10", "ulint" ); IupSetStrAttribute( guiVal->hlType, "11", "fpn" ); IupSetStrAttribute( guiVal->hlType, "12", "dpn" ); IupSetStrAttribute( guiVal->hlType, "13", "lpn" ); guiVal->value.vb = IupVbox( guiVal->tbValue, guiVal->hlType, NULL ); guiVal->value.fset = IupFrame( guiVal->value.vb ); IupSetAttribute( guiVal->value.fset, IUP_SIZE, "100x30" ); IupSetAttribute( guiVal->value.fset, IUP_EXPAND, IUP_HORIZONTAL ); IupAppend( guiVal->main.vb, guiVal->value.fset ); IupMap( guiVal->value.fset ); guiVal_OnLang(); }
void ButtonTest(void) { Ihandle *dlg, *button, *label, *image1, *image1i, *image1p, *image2, *image3, *box1, *box2; box1 = IupVbox(NULL); IupSetAttribute(box1, "MARGIN", "5x5"); IupSetAttribute(box1, "GAP", "5"); // IupSetAttribute(box1, "BGCOLOR", "75 150 170"); // IupSetAttribute(box1, "PADDING", "15x15"); button = IupButton(NULL, NULL); IupSetStrAttribute(button, "TITLE", "_@IUP_OK"); IupSetCallback(button, "ACTION", active_cb); IupAppend(box1, button); button = IupButton(NULL, NULL); if (IupGetInt(NULL, "UTF8MODE")) IupSetAttribute(button, "TITLE", "&Text && Test(çãõáóé)"); else IupSetAttribute(button, "TITLE", "&Text && Test(ηγυασι)"); IupSetAttribute(button, "TIP", "Button & Tip"); //IupSetAttribute(button, "PADDING", "15x15"); //IupSetAttribute(button, "BGCOLOR", "128 128 255"); // IupSetAttribute(button, "SIZE", "40"); // IupSetAttribute(button, "EXPAND", "Yes"); // IupSetAttribute(button, "FGCOLOR", "0 0 255"); // IupSetAttribute(button, "RASTERSIZE", "200x100"); IupSetAttribute(button, "ALIGNMENT", "ACENTER:ACENTER"); // IupSetAttribute(button, "ALIGNMENT", "ALEFT:ATOP"); IupSetAttribute(button, "NAME", "button1"); //IupSetAttribute(button, "CANFOCUS", "NO"); set_callbacks(button); IupAppend(box1, button); button = IupButton(NULL, NULL); IupSetAttribute(button, "TITLE", "Text1\nSecond Line"); // IupSetAttribute(button, "RASTERSIZE", "200x100"); IupSetAttribute(button, "ALIGNMENT", "ACENTER:ACENTER"); IupSetAttribute(button, "FONT", "Helvetica, Underline 14"); IupSetAttribute(button, "FLAT", "YES"); IupSetAttribute(button, "NAME", "button2"); set_callbacks(button); IupAppend(box1, button); button = IupButton(NULL, NULL); IupSetAttribute(button, "TITLE", "Text2\n<b>Second Line</b>"); IupSetAttribute(button, "RASTERSIZE", "200x100"); IupSetAttribute(button, "ALIGNMENT", "ARIGHT:ABOTTOM"); IupSetAttribute(button, "MARKUP", "YES"); IupSetAttribute(button, "NAME", "button3"); IupSetAttribute(button, "CANFOCUS", "NO"); set_callbacks(button); IupAppend(box1, button); button = IupButton(NULL, NULL); IupSetAttribute(button, "RASTERSIZE", "30x30"); IupSetAttribute(button, "BGCOLOR", "255 128 92"); IupSetAttribute(button, "NAME", "color"); // IupSetAttribute(button, "EXPAND", "HORIZONTAL"); // IupSetAttribute(button, "FLAT", "Yes"); set_callbacks(button); IupAppend(box1, button); box2 = IupVbox(NULL); IupSetAttribute(box2, "MARGIN", "5x5"); IupSetAttribute(box2, "GAP", "5"); // IupSetAttribute(box2, "BGCOLOR", "75 150 170"); // IupSetAttribute(box2, "PADDING", "15x15"); image1 = IupImage(TEST_IMAGE_SIZE, TEST_IMAGE_SIZE, image_data_8); IupSetAttribute(image1, "0", "BGCOLOR"); IupSetAttribute(image1, "1", "255 0 0"); IupSetAttribute(image1, "2", "0 255 0"); IupSetAttribute(image1, "3", "0 0 255"); IupSetAttribute(image1, "4", "255 255 255"); IupSetAttribute(image1, "5", "0 0 0"); image1i = IupImage(TEST_IMAGE_SIZE, TEST_IMAGE_SIZE, image_data_8_inactive); IupSetAttribute(image1i, "0", "BGCOLOR"); IupSetAttribute(image1i, "1", "255 0 0"); IupSetAttribute(image1i, "2", "0 255 0"); IupSetAttribute(image1i, "3", "0 0 255"); IupSetAttribute(image1i, "4", "255 255 255"); IupSetAttribute(image1i, "5", "0 0 0"); IupSetHandle("image1i", image1i); /* so it will be destroyed even when not used */ #if 0 image1p = IupImage(TEST_IMAGE_SIZE, TEST_IMAGE_SIZE, image_data_8_pressed); IupSetAttribute(image1p, "0", "BGCOLOR"); IupSetAttribute(image1p, "1", "255 0 0"); IupSetAttribute(image1p, "2", "0 255 0"); IupSetAttribute(image1p, "3", "0 0 255"); IupSetAttribute(image1p, "4", "255 255 255"); IupSetAttribute(image1p, "5", "0 0 0"); #endif image2 = IupImageRGB(TEST_IMAGE_SIZE, TEST_IMAGE_SIZE, image_data_24); image3 = IupImageRGBA(TEST_IMAGE_SIZE, TEST_IMAGE_SIZE, image_data_32); button = IupButton(NULL, NULL); IupSetAttribute(button, "TITLE", "Images"); IupSetAttributeHandle(button, "IMAGE", load_image_FileSave()); //IupSetAttribute(button, "IMAGE", "TECGRAF_BITMAP"); IupAppend(box2, button); button = IupButton(NULL, NULL); // IupSetAttribute(button, "ALIGNMENT", "ALEFT:ATOP"); // IupSetAttribute(button, "RASTERSIZE", "200x100"); // IupSetAttribute(button, "IMAGEPOSITION", "BOTTOM"); // IupSetAttribute(button, "PADDING", "5x5"); // IupSetAttribute(button, "TITLE", "Text1"); // IupSetAttribute(button, "FONT", "Helvetica, 14"); // IupSetAttribute(button, "IMAGE", "IUP_Tecgraf"); IupSetAttributeHandle(button, "IMAGE", image1); IupSetAttributeHandle(button, "IMINACTIVE", image1i); // IupSetAttributeHandle(button, "IMPRESS", image1p); IupSetAttribute(button, "TIP", "Image Label"); IupSetAttribute(button, "NAME", "button4"); IupSetAttribute(button, "PADDING", "5x5"); // IupSetAttribute(button, "FLAT", "Yes"); set_callbacks(button); IupAppend(box2, button); button = IupButton(NULL, NULL); IupSetAttributeHandle(button, "IMAGE", image2); // IupSetAttribute(button, "TITLE", "Text2"); // IupSetAttribute(button, "IMAGEPOSITION", "TOP"); // IupSetAttribute(button, "SPACING", "30"); // IupSetAttribute(button, "ALIGNMENT", "ALEFT"); // IupSetAttribute(button, "RASTERSIZE", "200x100"); IupSetAttribute(button, "FLAT", "YES"); // IupSetAttributeHandle(button, "IMPRESS", image2); IupSetAttribute(button, "CANFOCUS", "NO"); IupSetAttribute(button, "PADDING", "10x10"); // IupSetAttribute(button, "RASTERSIZE", "15x15"); IupSetAttribute(button, "NAME", "button5"); set_callbacks(button); IupAppend(box2, button); button = IupButton(NULL, NULL); IupSetAttributeHandle(button, "IMAGE", image3); IupSetAttribute(button, "TITLE", "Text3"); // IupSetAttribute(button, "RASTERSIZE", "200x100"); // IupSetAttribute(button, "ALIGNMENT", "ARIGHT"); IupSetAttribute(button, "NAME", "button6"); set_callbacks(button); IupAppend(box2, button); label = IupLabel(NULL); IupSetAttribute(label, "SEPARATOR", "VERTICAL"); IupSetHandle("seplabel", label); dlg = IupDialog(IupHbox(box1, label, box2, NULL)); IupSetAttribute(dlg, "TITLE", "IupButton Test"); // IupSetAttribute(box1, "BGCOLOR", "128 0 0"); // IupSetAttribute(dlg, "BGCOLOR", "0 128 0"); // IupSetAttribute(dlg, "BACKGROUND", "255 128 128"); // IupSetAttributeHandle(dlg, "BACKGROUND", image2); // IupSetAttribute(dlg, "BGCOLOR", "173 177 194"); // Motif BGCOLOR for documentation // IupSetAttribute(dlg, "SAVEUNDER", "NO"); IupSetAttributeHandle(dlg, "STARTFOCUS", button); // IupSetGlobal("CLIENTAREAANIMATION", "No"); // IupSetGlobal("HOTTRACKING", "No"); IupShow(dlg); // IupSetAttribute(dlg, "PARENTDIALOG", "BIGTEST"); // IupShowXY(dlg, IUP_CENTERPARENT, IUP_CENTERPARENT); // IupShowXY(dlg,IUP_LEFT,IUP_TOP); // IupShowXY(dlg, IUP_RIGHT, IUP_BOTTOM); // IupShowXY(dlg, IUP_RIGHT, IUP_CENTER); // IupShowXY(dlg,0,0); }
static int iColorDlgCreateMethod(Ihandle* ih, void** params) { Ihandle *ok_bt, *cancel_bt; Ihandle *rgb_vb, *hsi_vb, *clr_vb; Ihandle *lin1, *lin2, *col1, *col2; IcolorDlgData* colordlg_data = (IcolorDlgData*)malloc(sizeof(IcolorDlgData)); memset(colordlg_data, 0, sizeof(IcolorDlgData)); iupAttribSet(ih, "_IUP_GC_DATA", (char*)colordlg_data); /* ======================================================================= */ /* BUTTONS ============================================================= */ /* ======================================================================= */ ok_bt = IupButton("_@IUP_OK", NULL); /* Ok Button */ IupSetStrAttribute(ok_bt, "PADDING", IupGetGlobal("DEFAULTBUTTONPADDING")); IupSetCallback (ok_bt, "ACTION", (Icallback)iColorDlgButtonOK_CB); IupSetAttributeHandle(ih, "DEFAULTENTER", ok_bt); cancel_bt = IupButton("_@IUP_CANCEL", NULL); /* Cancel Button */ IupSetStrAttribute(cancel_bt, "PADDING", IupGetGlobal("DEFAULTBUTTONPADDING")); IupSetCallback (cancel_bt, "ACTION", (Icallback)iColorDlgButtonCancel_CB); IupSetAttributeHandle(ih, "DEFAULTESC", cancel_bt); colordlg_data->help_bt = IupButton("_@IUP_HELP", NULL); /* Help Button */ IupSetStrAttribute(colordlg_data->help_bt, "PADDING", IupGetGlobal("DEFAULTBUTTONPADDING")); IupSetCallback (colordlg_data->help_bt, "ACTION", (Icallback)iColorDlgButtonHelp_CB); /* ======================================================================= */ /* COLOR =============================================================== */ /* ======================================================================= */ colordlg_data->color_browser = IupColorBrowser(); IupSetAttribute(colordlg_data->color_browser, "EXPAND", "YES"); IupSetCallback(colordlg_data->color_browser, "DRAG_CB", (Icallback)iColorDlgColorSelDrag_CB); IupSetCallback(colordlg_data->color_browser, "CHANGE_CB", (Icallback)iColorDlgColorSelDrag_CB); IupSetAttribute(colordlg_data->color_browser, "MINSIZE", "200x200"); colordlg_data->color_cnv = IupCanvas(NULL); /* Canvas of the color */ IupSetAttribute(colordlg_data->color_cnv, "SIZE", "x12"); IupSetAttribute(colordlg_data->color_cnv, "CANFOCUS", "NO"); IupSetAttribute(colordlg_data->color_cnv, "EXPAND", "HORIZONTAL"); IupSetCallback (colordlg_data->color_cnv, "ACTION", (Icallback)iColorDlgColorCnvAction_CB); IupSetCallback (colordlg_data->color_cnv, "BUTTON_CB", (Icallback)iColorDlgColorCnvButton_CB); colordlg_data->colorhex_txt = IupText(NULL); /* Hex of the color */ IupSetAttribute(colordlg_data->colorhex_txt, "VISIBLECOLUMNS", "7"); IupSetCallback (colordlg_data->colorhex_txt, "ACTION", (Icallback)iColorDlgHexAction_CB); IupSetAttribute(colordlg_data->colorhex_txt, "MASK", "#[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]"); /* ======================================================================= */ /* ALPHA TRANSPARENCY ================================================== */ /* ======================================================================= */ colordlg_data->alpha_val = IupVal("HORIZONTAL"); IupSetAttribute(colordlg_data->alpha_val, "EXPAND", "HORIZONTAL"); IupSetAttribute(colordlg_data->alpha_val, "MIN", "0"); IupSetAttribute(colordlg_data->alpha_val, "MAX", "255"); IupSetAttribute(colordlg_data->alpha_val, "VALUE", "255"); IupSetAttribute(colordlg_data->alpha_val, "SIZE", "80x12"); IupSetCallback (colordlg_data->alpha_val, "MOUSEMOVE_CB", (Icallback)iColorDlgAlphaVal_CB); IupSetCallback (colordlg_data->alpha_val, "BUTTON_PRESS_CB", (Icallback)iColorDlgAlphaVal_CB); IupSetCallback (colordlg_data->alpha_val, "BUTTON_RELEASE_CB", (Icallback)iColorDlgAlphaVal_CB); colordlg_data->alpha_txt = IupText(NULL); /* Alpha value */ IupSetAttribute(colordlg_data->alpha_txt, "VISIBLECOLUMNS", "3"); IupSetAttribute(colordlg_data->alpha_txt, "SPIN", "YES"); IupSetAttribute(colordlg_data->alpha_txt, "SPINMIN", "0"); IupSetAttribute(colordlg_data->alpha_txt, "SPINMAX", "255"); IupSetAttribute(colordlg_data->alpha_txt, "SPININC", "1"); IupSetCallback (colordlg_data->alpha_txt, "ACTION", (Icallback)iColorDlgAlphaAction_CB); IupSetCallback (colordlg_data->alpha_txt, "SPIN_CB", (Icallback)iColorDlgAlphaSpin_CB); IupSetAttribute(colordlg_data->alpha_txt, "MASKINT", "0:255"); /* ======================================================================= */ /* COLOR TABLE ========================================================= */ /* ======================================================================= */ colordlg_data->colortable_cbar = IupColorbar(); IupSetAttribute(colordlg_data->colortable_cbar, "ORIENTATION", "HORIZONTAL"); IupSetAttribute(colordlg_data->colortable_cbar, "NUM_PARTS", "2"); IupSetInt(colordlg_data->colortable_cbar, "NUM_CELLS", COLORTABLE_MAX); IupSetAttribute(colordlg_data->colortable_cbar, "SHOW_PREVIEW", "NO"); IupSetAttribute(colordlg_data->colortable_cbar, "SIZE", "138x22"); IupSetAttribute(colordlg_data->colortable_cbar, "SQUARED", "NO"); IupSetCallback (colordlg_data->colortable_cbar, "SELECT_CB", (Icallback)iColorDlgColorTableSelect_CB); /* ======================================================================= */ /* RGB TEXT FIELDS ===================================================== */ /* ======================================================================= */ colordlg_data->red_txt = IupText(NULL); /* Red value */ IupSetAttribute(colordlg_data->red_txt, "VISIBLECOLUMNS", "3"); IupSetAttribute(colordlg_data->red_txt, "SPIN", "YES"); IupSetAttribute(colordlg_data->red_txt, "SPINMIN", "0"); IupSetAttribute(colordlg_data->red_txt, "SPINMAX", "255"); IupSetAttribute(colordlg_data->red_txt, "SPININC", "1"); IupSetCallback (colordlg_data->red_txt, "ACTION", (Icallback)iColorDlgRedAction_CB); IupSetCallback (colordlg_data->red_txt, "SPIN_CB", (Icallback)iColorDlgRedSpin_CB); IupSetAttribute(colordlg_data->red_txt, "MASKINT", "0:255"); colordlg_data->green_txt = IupText(NULL); /* Green value */ IupSetAttribute(colordlg_data->green_txt, "VISIBLECOLUMNS", "3"); IupSetAttribute(colordlg_data->green_txt, "SPIN", "YES"); IupSetAttribute(colordlg_data->green_txt, "SPINMIN", "0"); IupSetAttribute(colordlg_data->green_txt, "SPINMAX", "255"); IupSetAttribute(colordlg_data->green_txt, "SPININC", "1"); IupSetCallback (colordlg_data->green_txt, "ACTION", (Icallback)iColorDlgGreenAction_CB); IupSetCallback (colordlg_data->green_txt, "SPIN_CB", (Icallback)iColorDlgGreenSpin_CB); IupSetAttribute(colordlg_data->green_txt, "MASKINT", "0:255"); colordlg_data->blue_txt = IupText(NULL); /* Blue value */ IupSetAttribute(colordlg_data->blue_txt, "VISIBLECOLUMNS", "3"); IupSetAttribute(colordlg_data->blue_txt, "SPIN", "YES"); IupSetAttribute(colordlg_data->blue_txt, "SPINMIN", "0"); IupSetAttribute(colordlg_data->blue_txt, "SPINMAX", "255"); IupSetAttribute(colordlg_data->blue_txt, "SPININC", "1"); IupSetCallback (colordlg_data->blue_txt, "ACTION", (Icallback)iColorDlgBlueAction_CB); IupSetCallback (colordlg_data->blue_txt, "SPIN_CB", (Icallback)iColorDlgBlueSpin_CB); IupSetAttribute(colordlg_data->blue_txt, "MASKINT", "0:255"); /* ======================================================================= */ /* HSI TEXT FIELDS ===================================================== */ /* ======================================================================= */ colordlg_data->hue_txt = IupText(NULL); /* Hue value */ IupSetAttribute(colordlg_data->hue_txt, "VISIBLECOLUMNS", "3"); IupSetAttribute(colordlg_data->hue_txt, "SPIN", "YES"); IupSetAttribute(colordlg_data->hue_txt, "SPINMIN", "0"); IupSetAttribute(colordlg_data->hue_txt, "SPINMAX", "359"); IupSetAttribute(colordlg_data->hue_txt, "SPINWRAP", "YES"); IupSetAttribute(colordlg_data->hue_txt, "SPININC", "1"); IupSetCallback(colordlg_data->hue_txt, "ACTION", (Icallback)iColorDlgHueAction_CB); IupSetCallback(colordlg_data->hue_txt, "SPIN_CB", (Icallback)iColorDlgHueSpin_CB); IupSetAttribute(colordlg_data->hue_txt, "MASKINT", "0:359"); colordlg_data->saturation_txt = IupText(NULL); /* Saturation value */ IupSetAttribute(colordlg_data->saturation_txt, "VISIBLECOLUMNS", "3"); IupSetAttribute(colordlg_data->saturation_txt, "SPIN", "YES"); IupSetAttribute(colordlg_data->saturation_txt, "SPINMIN", "0"); IupSetAttribute(colordlg_data->saturation_txt, "SPINMAX", "100"); IupSetAttribute(colordlg_data->saturation_txt, "SPININC", "1"); IupSetCallback(colordlg_data->saturation_txt, "ACTION", (Icallback)iColorDlgSaturationAction_CB); IupSetCallback(colordlg_data->saturation_txt, "SPIN_CB", (Icallback)iColorDlgSaturationSpin_CB); IupSetAttribute(colordlg_data->saturation_txt, "MASKINT", "0:100"); colordlg_data->intensity_txt = IupText(NULL); /* Intensity value */ IupSetAttribute(colordlg_data->intensity_txt, "VISIBLECOLUMNS", "3"); IupSetAttribute(colordlg_data->intensity_txt, "SPIN", "YES"); IupSetAttribute(colordlg_data->intensity_txt, "SPINMIN", "0"); IupSetAttribute(colordlg_data->intensity_txt, "SPINMAX", "100"); IupSetAttribute(colordlg_data->intensity_txt, "SPININC", "1"); IupSetCallback(colordlg_data->intensity_txt, "ACTION", (Icallback)iColorDlgIntensityAction_CB); IupSetCallback(colordlg_data->intensity_txt, "SPIN_CB", (Icallback)iColorDlgIntensitySpin_CB); IupSetAttribute(colordlg_data->intensity_txt, "MASKINT", "0:100"); /* =================== */ /* 1st line = Controls */ /* =================== */ col1 = IupVbox(colordlg_data->color_browser, IupSetAttributes(IupHbox(colordlg_data->color_cnv, NULL), "MARGIN=30x0"),NULL); hsi_vb = IupVbox(IupSetAttributes(IupHbox(IupLabel("_@IUP_HUE"), colordlg_data->hue_txt, NULL), "ALIGNMENT=ACENTER"), IupSetAttributes(IupHbox(IupLabel("_@IUP_SATURATION"), colordlg_data->saturation_txt, NULL), "ALIGNMENT=ACENTER"), IupSetAttributes(IupHbox(IupLabel("_@IUP_INTENSITY"), colordlg_data->intensity_txt, NULL), "ALIGNMENT=ACENTER"), NULL); IupSetAttribute(hsi_vb, "GAP", "5"); rgb_vb = IupVbox(IupSetAttributes(IupHbox(IupLabel("_@IUP_RED"), colordlg_data->red_txt, NULL), "ALIGNMENT=ACENTER"), IupSetAttributes(IupHbox(IupLabel("_@IUP_GREEN"), colordlg_data->green_txt, NULL), "ALIGNMENT=ACENTER"), IupSetAttributes(IupHbox(IupLabel("_@IUP_BLUE"), colordlg_data->blue_txt, NULL), "ALIGNMENT=ACENTER"), NULL); IupSetAttribute(rgb_vb, "GAP", "5"); clr_vb = IupVbox(IupSetAttributes(IupHbox(IupLabel("_@IUP_OPACITY"), colordlg_data->alpha_txt, colordlg_data->alpha_val, NULL), "ALIGNMENT=ACENTER"), IupSetAttributes(IupHbox(IupLabel("He&xa:"), colordlg_data->colorhex_txt, NULL), "ALIGNMENT=ACENTER"), IupSetAttributes(IupVbox(IupLabel("_@IUP_PALETTE"), colordlg_data->colortable_cbar, NULL), "GAP=3"), NULL); IupSetAttribute(clr_vb, "GAP", "5"); IupSetAttribute(clr_vb, "EXPAND", "YES"); IupDestroy(IupSetAttributes(IupNormalizer(IupGetChild(IupGetChild(hsi_vb, 0), 0), /* Hue Label */ IupGetChild(IupGetChild(hsi_vb, 1), 0), /* Saturation Label */ IupGetChild(IupGetChild(hsi_vb, 2), 0), /* Intensity Label */ IupGetChild(IupGetChild(clr_vb, 0), 0), /* Opacity Label */ IupGetChild(IupGetChild(clr_vb, 1), 0), /* Hexa Label */ NULL), "NORMALIZE=HORIZONTAL")); IupDestroy(IupSetAttributes(IupNormalizer(IupGetChild(IupGetChild(rgb_vb, 0), 0), /* Red Label */ IupGetChild(IupGetChild(rgb_vb, 1), 0), /* Green Label */ IupGetChild(IupGetChild(rgb_vb, 2), 0), /* Blue Label */ NULL), "NORMALIZE=HORIZONTAL")); col2 = IupVbox(IupSetAttributes(IupHbox(hsi_vb, IupFill(), rgb_vb, NULL), "EXPAND=YES"), IupSetAttributes(IupLabel(NULL), "SEPARATOR=HORIZONTAL"), clr_vb, NULL); IupSetAttributes(col2, "EXPAND=NO, GAP=10"); lin1 = IupHbox(col1, col2, NULL); IupSetAttribute(lin1, "GAP", "10"); IupSetAttribute(lin1, "MARGIN", "0x0"); /* ================== */ /* 2nd line = Buttons */ /* ================== */ lin2 = IupHbox(IupFill(), ok_bt, cancel_bt, colordlg_data->help_bt, NULL); IupSetAttribute(lin2, "GAP", "5"); IupSetAttribute(lin2, "MARGIN", "0x0"); IupSetAttribute(lin2, "NORMALIZESIZE", "HORIZONTAL"); /* Do not use IupAppend because we set childtype=IUP_CHILDNONE */ iupChildTreeAppend(ih, IupSetAttributes(IupVbox(lin1, IupSetAttributes(IupLabel(NULL), "SEPARATOR=HORIZONTAL"), lin2, NULL), "MARGIN=10x10, GAP=10")); IupRefresh(ih); if (colordlg_data->color_browser->currentwidth < colordlg_data->color_browser->currentheight) { IupSetStrf(colordlg_data->color_browser, "RASTERSIZE", "%dx", colordlg_data->color_browser->currentheight); IupSetAttribute(ih, "RASTERSIZE", NULL); } IupSetAttribute(ih, "RESIZE", "NO"); iColorDlgInit_Defaults(colordlg_data); (void)params; return IUP_NOERROR; }
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; }
int IupAlarm(const char *title, const char *msg, const char *b1, const char *b2, const char *b3) { Ihandle *dlg, *dlg_box, *button_box, *button, *default_esc, *default_enter; int bt, len; char* padding; msg = msg? msg: ""; if (b1 == NULL) return 0; len = (int)strlen(b1); if (b2) { int len2 = (int)strlen(b2); if (len2 > len) len = len2; } if (b3) { int len3 = (int)strlen(b3); if (len3 > len) len = len3; } if (len > 7) padding = "12x2"; else padding = "20x0"; button_box = IupHbox(NULL); IupSetAttribute(button_box, "NORMALIZESIZE", "HORIZONTAL"); IupSetAttribute(button_box,"MARGIN","0x0"); IupAppend(button_box, IupFill()); /* to center the buttons */ button = IupButton(b1, NULL); iupAttribSet(button, "_IUP_BUTTON_NUMBER", "1"); IupSetAttribute(button, "PADDING", padding); IupAppend(button_box, button); IupSetCallback (button, "ACTION", (Icallback)iAlarmButtonAction_CB); default_enter = button; default_esc = button; if (b2 != NULL) { button = IupButton(b2, NULL); iupAttribSet(button, "_IUP_BUTTON_NUMBER", "2"); IupSetAttribute(button, "PADDING", padding); IupAppend(button_box, button); IupSetCallback (button, "ACTION", (Icallback)iAlarmButtonAction_CB); default_esc = button; } if (b3 != NULL) { button = IupButton(b3, NULL); iupAttribSet(button, "_IUP_BUTTON_NUMBER", "3"); IupSetAttribute(button, "PADDING", padding); IupAppend(button_box, button); IupSetCallback (button, "ACTION", (Icallback)iAlarmButtonAction_CB); default_esc = button; } IupAppend(button_box, IupFill()); /* to center the buttons */ dlg_box = IupVbox( IupLabel(msg), IupSetAttributes(IupLabel(NULL), "SEPARATOR=HORIZONTAL"), button_box, NULL); IupSetAttribute(dlg_box,"MARGIN","10x10"); IupSetAttribute(dlg_box,"GAP","10"); dlg = IupDialog(dlg_box); IupSetStrAttribute(dlg,"TITLE", title); IupSetAttribute(dlg,"DIALOGFRAME","YES"); IupSetAttribute(dlg,"DIALOGHINT","YES"); IupSetAttributeHandle(dlg,"DEFAULTENTER", default_enter); IupSetAttributeHandle(dlg,"DEFAULTESC", default_esc); IupSetAttribute(dlg,"PARENTDIALOG", IupGetGlobal("PARENTDIALOG")); IupSetAttribute(dlg,"ICON", IupGetGlobal("ICON")); IupPopup(dlg,IUP_CENTERPARENT,IUP_CENTERPARENT); bt = iupAttribGetInt(dlg, "_IUP_BUTTON_NUMBER"); IupDestroy(dlg); return bt; }
int iupDataEntry(int maxlin, int* maxcol, int* maxscr, char* title, char** text, char** data) { int i, bt; Ihandle *ok, *cancel, *dlg, *vb, *hb, **txt, **lbl, *button_box, *dlg_box; txt = (Ihandle **)calloc(maxlin, sizeof(Ihandle*)); if (txt == NULL) return -2; lbl = (Ihandle **)calloc(maxlin+1, sizeof(Ihandle*)); vb = IupVbox(NULL); for (i=0; i<maxlin; i++) { txt[i] = IupText(NULL); IupSetAttribute(txt[i],"VALUE",data[i]); IupSetInt(txt[i],"VISIBLECOLUMNS", maxscr[i]); IupSetInt(txt[i],"NC", maxcol[i]); IupSetAttribute(txt[i],"EXPAND","HORIZONTAL"); hb = IupHbox(lbl[i] = IupLabel(text[i]), txt[i], NULL); IupSetAttribute(hb,"MARGIN","0x0"); IupSetAttribute(hb,"ALIGNMENT","ACENTER"); IupAppend(vb, hb); } lbl[i] = NULL; IupInsert(vb, NULL, IupNormalizerv(lbl)); ok = IupButton("_@IUP_OK", NULL); IupSetAttribute(ok, "PADDING", "20x0"); IupSetCallback(ok, "ACTION", (Icallback)CB_button_OK); cancel = IupButton("_@IUP_CANCEL", NULL); IupSetAttribute(cancel, "PADDING", "20x0"); IupSetCallback(cancel, "ACTION", (Icallback)CB_button_CANCEL); button_box = IupHbox( IupFill(), ok, cancel, NULL); IupSetAttribute(button_box,"MARGIN","0x0"); IupSetAttribute(button_box, "NORMALIZESIZE", "HORIZONTAL"); dlg_box = IupVbox( IupFrame(vb), button_box, NULL); IupSetAttribute(dlg_box,"MARGIN","10x10"); IupSetAttribute(dlg_box,"GAP","5"); dlg = IupDialog(dlg_box); IupSetStrAttribute(dlg,"TITLE",title); IupSetAttribute(dlg,"MINBOX","NO"); IupSetAttribute(dlg,"MAXBOX","NO"); IupSetAttributeHandle(dlg,"DEFAULTENTER", ok); IupSetAttributeHandle(dlg,"DEFAULTESC", cancel); IupSetAttribute(dlg,"PARENTDIALOG",IupGetGlobal("PARENTDIALOG")); IupSetAttribute(dlg,"ICON", IupGetGlobal("ICON")); IupMap(dlg); IupSetfAttribute(dlg,"MAXSIZE", "65535x%d", IupGetInt2(dlg, "RASTERSIZE")); IupSetAttribute(dlg,"MINSIZE", IupGetAttribute(dlg, "RASTERSIZE")); IupPopup(dlg,IUP_CENTERPARENT,IUP_CENTERPARENT); for (i=0; i<maxlin; i++) { iupStrCopyN(data[i], maxcol[i]+1, IupGetAttribute(txt[i], "VALUE")); } free(lbl); free(txt); bt = IupGetInt(dlg, "STATUS"); IupDestroy(dlg); return bt; }
int IupGetText(const char* title, char* text) { Ihandle *ok, *cancel, *multi_text, *button_box, *dlg_box, *dlg; int bt; multi_text = IupMultiLine(NULL); IupSetAttribute(multi_text,"EXPAND", "YES"); IupSetAttribute(multi_text,"VALUE", text); IupSetAttribute(multi_text,"FONT", "Courier, 12"); IupSetAttribute(multi_text, "VISIBLELINES", "10"); IupSetAttribute(multi_text, "VISIBLECOLUMNS", "50"); ok = IupButton("_@IUP_OK", NULL); IupSetAttribute(ok, "PADDING", "20x0"); IupSetCallback(ok, "ACTION", (Icallback)CB_button_OK); cancel = IupButton("_@IUP_CANCEL", NULL); IupSetAttribute(cancel, "PADDING", "20x0"); IupSetCallback(cancel, "ACTION", (Icallback)CB_button_CANCEL); button_box = IupHbox( IupFill(), ok, cancel, NULL); IupSetAttribute(button_box,"MARGIN","0x0"); IupSetAttribute(button_box, "NORMALIZESIZE", "HORIZONTAL"); dlg_box = IupVbox( multi_text, button_box, NULL); IupSetAttribute(dlg_box,"MARGIN","10x10"); IupSetAttribute(dlg_box,"GAP","10"); dlg = IupDialog (dlg_box); IupSetStrAttribute(dlg,"TITLE", title); IupSetAttribute(dlg,"MINBOX","NO"); IupSetAttribute(dlg,"MAXBOX","NO"); IupSetAttributeHandle(dlg,"DEFAULTENTER", ok); IupSetAttributeHandle(dlg,"DEFAULTESC", cancel); IupSetAttribute(dlg,"PARENTDIALOG", IupGetGlobal("PARENTDIALOG")); IupSetAttribute(dlg,"ICON", IupGetGlobal("ICON")); IupMap(dlg); IupSetAttribute(multi_text, "VISIBLELINES", NULL); IupSetAttribute(multi_text, "VISIBLECOLUMNS", NULL); IupPopup(dlg, IUP_CENTERPARENT, IUP_CENTERPARENT); bt = IupGetInt(dlg, "STATUS"); if (bt==1) iupStrCopyN(text, 10240, IupGetAttribute(multi_text, "VALUE")); else bt = 0; /* return 0 instead of -1 */ IupDestroy(dlg); return bt; }
int main(int argc, char **argv) { Ihandle *dlg, *vbox, *multitext, *menu; Ihandle *sub_menu_file, *file_menu, *item_exit, *item_new, *item_open, *item_save, *item_saveas, *item_revert; Ihandle *sub_menu_edit, *edit_menu, *item_find, *item_goto, *item_copy, *item_paste, *item_cut, *item_delete, *item_select_all; Ihandle *btn_cut, *btn_copy, *btn_paste, *btn_find, *btn_new, *btn_open, *btn_save; Ihandle *sub_menu_format, *format_menu, *item_font; Ihandle *sub_menu_help, *help_menu, *item_help, *item_about; Ihandle *sub_menu_view, *view_menu, *item_toolbar, *item_statusbar; Ihandle *lbl_statusbar, *toolbar_hb, *recent_menu; Ihandle *config; const char* font; IupOpen(&argc, &argv); IupImageLibOpen(); config = IupConfig(); IupSetAttribute(config, "APP_NAME", "simple_notepad"); IupConfigLoad(config); multitext = IupText(NULL); IupSetAttribute(multitext, "MULTILINE", "YES"); IupSetAttribute(multitext, "EXPAND", "YES"); IupSetAttribute(multitext, "NAME", "MULTITEXT"); IupSetAttribute(multitext, "DIRTY", "NO"); IupSetCallback(multitext, "CARET_CB", (Icallback)multitext_caret_cb); IupSetCallback(multitext, "VALUECHANGED_CB", (Icallback)multitext_valuechanged_cb); IupSetCallback(multitext, "DROPFILES_CB", (Icallback)dropfiles_cb); font = IupConfigGetVariableStr(config, "MainWindow", "Font"); if (font) IupSetStrAttribute(multitext, "FONT", font); lbl_statusbar = IupLabel("Lin 1, Col 1"); IupSetAttribute(lbl_statusbar, "NAME", "STATUSBAR"); IupSetAttribute(lbl_statusbar, "EXPAND", "HORIZONTAL"); IupSetAttribute(lbl_statusbar, "PADDING", "10x5"); item_new = IupItem("New\tCtrl+N", NULL); IupSetAttribute(item_new, "IMAGE", "IUP_FileNew"); IupSetCallback(item_new, "ACTION", (Icallback)item_new_action_cb); btn_new = IupButton(NULL, NULL); IupSetAttribute(btn_new, "IMAGE", "IUP_FileNew"); IupSetAttribute(btn_new, "FLAT", "Yes"); IupSetCallback(btn_new, "ACTION", (Icallback)item_new_action_cb); item_open = IupItem("&Open...\tCtrl+O", NULL); IupSetAttribute(item_open, "IMAGE", "IUP_FileOpen"); IupSetCallback(item_open, "ACTION", (Icallback)item_open_action_cb); btn_open = IupButton(NULL, NULL); IupSetAttribute(btn_open, "IMAGE", "IUP_FileOpen"); IupSetAttribute(btn_open, "FLAT", "Yes"); IupSetCallback(btn_open, "ACTION", (Icallback)item_open_action_cb); item_save = IupItem("Save\tCtrl+S", NULL); IupSetAttribute(item_save, "NAME", "ITEM_SAVE"); IupSetAttribute(item_save, "IMAGE", "IUP_FileSave"); IupSetCallback(item_save, "ACTION", (Icallback)item_save_action_cb); btn_save = IupButton(NULL, NULL); IupSetAttribute(btn_save, "IMAGE", "IUP_FileSave"); IupSetAttribute(btn_save, "FLAT", "Yes"); IupSetCallback(btn_save, "ACTION", (Icallback)item_save_action_cb); item_saveas = IupItem("Save &As...", NULL); IupSetAttribute(item_saveas, "NAME", "ITEM_SAVEAS"); IupSetCallback(item_saveas, "ACTION", (Icallback)item_saveas_action_cb); item_revert = IupItem("Revert", NULL); IupSetAttribute(item_revert, "NAME", "ITEM_REVERT"); IupSetCallback(item_revert, "ACTION", (Icallback)item_revert_action_cb); item_exit = IupItem("E&xit", NULL); IupSetCallback(item_exit, "ACTION", (Icallback)item_exit_action_cb); item_find = IupItem("&Find...\tCtrl+F", NULL); IupSetAttribute(item_find, "IMAGE", "IUP_EditFind"); IupSetCallback(item_find, "ACTION", (Icallback)item_find_action_cb); btn_find = IupButton(NULL, NULL); IupSetAttribute(btn_find, "IMAGE", "IUP_EditFind"); IupSetAttribute(btn_find, "FLAT", "Yes"); IupSetCallback(btn_find, "ACTION", (Icallback)item_find_action_cb); item_cut = IupItem("Cut\tCtrl+X", NULL); IupSetAttribute(item_cut, "NAME", "ITEM_CUT"); IupSetAttribute(item_cut, "IMAGE", "IUP_EditCut"); IupSetCallback(item_cut, "ACTION", (Icallback)item_cut_action_cb); item_copy = IupItem("Copy\tCtrl+C", NULL); IupSetAttribute(item_copy, "NAME", "ITEM_COPY"); IupSetAttribute(item_copy, "IMAGE", "IUP_EditCopy"); IupSetCallback(item_copy, "ACTION", (Icallback)item_copy_action_cb); item_paste = IupItem("Paste\tCtrl+V", NULL); IupSetAttribute(item_paste, "NAME", "ITEM_PASTE"); IupSetAttribute(item_paste, "IMAGE", "IUP_EditPaste"); IupSetCallback(item_paste, "ACTION", (Icallback)item_paste_action_cb); item_delete = IupItem("Delete\tDel", NULL); IupSetAttribute(item_delete, "IMAGE", "IUP_EditErase"); IupSetAttribute(item_delete, "NAME", "ITEM_DELETE"); IupSetCallback(item_delete, "ACTION", (Icallback)item_delete_action_cb); item_select_all = IupItem("Select All\tCtrl+A", NULL); IupSetCallback(item_select_all, "ACTION", (Icallback)item_select_all_action_cb); btn_cut = IupButton(NULL, NULL); IupSetAttribute(btn_cut, "IMAGE", "IUP_EditCut"); IupSetAttribute(btn_cut, "FLAT", "Yes"); IupSetCallback(btn_cut, "ACTION", (Icallback)item_cut_action_cb); btn_copy = IupButton(NULL, NULL); IupSetAttribute(btn_copy, "IMAGE", "IUP_EditCopy"); IupSetAttribute(btn_copy, "FLAT", "Yes"); IupSetCallback(btn_copy, "ACTION", (Icallback)item_copy_action_cb); btn_paste = IupButton(NULL, NULL); IupSetAttribute(btn_paste, "IMAGE", "IUP_EditPaste"); IupSetAttribute(btn_paste, "FLAT", "Yes"); IupSetCallback(btn_paste, "ACTION", (Icallback)item_paste_action_cb); toolbar_hb = IupHbox( btn_new, btn_open, btn_save, IupSetAttributes(IupLabel(NULL), "SEPARATOR=VERTICAL"), btn_cut, btn_copy, btn_paste, IupSetAttributes(IupLabel(NULL), "SEPARATOR=VERTICAL"), btn_find, NULL); IupSetAttribute(toolbar_hb, "MARGIN", "5x5"); IupSetAttribute(toolbar_hb, "GAP", "2"); item_toolbar = IupItem("&Toobar...", NULL); IupSetCallback(item_toolbar, "ACTION", (Icallback)item_toolbar_action_cb); IupSetAttribute(item_toolbar, "VALUE", "ON"); item_statusbar = IupItem("&Statusbar...", NULL); IupSetCallback(item_statusbar, "ACTION", (Icallback)item_statusbar_action_cb); IupSetAttribute(item_statusbar, "VALUE", "ON"); if (!IupConfigGetVariableIntDef(config, "MainWindow", "Toolbar", 1)) { IupSetAttribute(item_toolbar, "VALUE", "OFF"); IupSetAttribute(toolbar_hb, "FLOATING", "YES"); IupSetAttribute(toolbar_hb, "VISIBLE", "NO"); } if (!IupConfigGetVariableIntDef(config, "MainWindow", "Statusbar", 1)) { IupSetAttribute(item_statusbar, "VALUE", "OFF"); IupSetAttribute(lbl_statusbar, "FLOATING", "YES"); IupSetAttribute(lbl_statusbar, "VISIBLE", "NO"); } item_goto = IupItem("&Go To...\tCtrl+G", NULL); IupSetCallback(item_goto, "ACTION", (Icallback)item_goto_action_cb); item_font = IupItem("&Font...", NULL); IupSetCallback(item_font, "ACTION", (Icallback)item_font_action_cb); item_help = IupItem("&Help...", NULL); IupSetCallback(item_help, "ACTION", (Icallback)item_help_action_cb); item_about = IupItem("&About...", NULL); IupSetCallback(item_about, "ACTION", (Icallback)item_about_action_cb); recent_menu = IupMenu(NULL); file_menu = IupMenu( item_new, item_open, item_save, item_saveas, item_revert, IupSeparator(), IupSubmenu("Recent &Files", recent_menu), item_exit, NULL); edit_menu = IupMenu( item_cut, item_copy, item_paste, item_delete, IupSeparator(), item_find, item_goto, IupSeparator(), item_select_all, NULL); format_menu = IupMenu( item_font, NULL); view_menu = IupMenu( item_toolbar, item_statusbar, NULL); help_menu = IupMenu( item_help, item_about, NULL); IupSetCallback(file_menu, "OPEN_CB", (Icallback)file_menu_open_cb); IupSetCallback(edit_menu, "OPEN_CB", (Icallback)edit_menu_open_cb); sub_menu_file = IupSubmenu("&File", file_menu); sub_menu_edit = IupSubmenu("&Edit", edit_menu); sub_menu_format = IupSubmenu("F&ormat", format_menu); sub_menu_view = IupSubmenu("&View", view_menu); sub_menu_help = IupSubmenu("&Help", help_menu); menu = IupMenu( sub_menu_file, sub_menu_edit, sub_menu_format, sub_menu_view, sub_menu_help, NULL); vbox = IupVbox( toolbar_hb, multitext, lbl_statusbar, NULL); dlg = IupDialog(vbox); IupSetAttributeHandle(dlg, "MENU", menu); IupSetAttribute(dlg, "SIZE", "HALFxHALF"); IupSetCallback(dlg, "CLOSE_CB", (Icallback)item_exit_action_cb); IupSetCallback(dlg, "DROPFILES_CB", (Icallback)dropfiles_cb); IupSetAttribute(dlg, "CONFIG", (char*)config); /* parent for pre-defined dialogs in closed functions (IupMessage) */ IupSetAttributeHandle(NULL, "PARENTDIALOG", dlg); IupSetCallback(dlg, "K_cN", (Icallback)item_new_action_cb); IupSetCallback(dlg, "K_cO", (Icallback)item_open_action_cb); IupSetCallback(dlg, "K_cS", (Icallback)item_save_action_cb); IupSetCallback(dlg, "K_cF", (Icallback)item_find_action_cb); IupSetCallback(dlg, "K_cG", (Icallback)item_goto_action_cb); IupConfigRecentInit(config, recent_menu, item_recent_cb, 10); IupShowXY(dlg, IUP_CENTERPARENT, IUP_CENTERPARENT); IupSetAttribute(dlg, "USERSIZE", NULL); /* remove minimum size restriction */ new_file(dlg); /* open a file from the command line (allow file association in Windows) */ if (argc > 1 && argv[1]) { const char* filename = argv[1]; open_file(dlg, filename); } IupMainLoop(); IupClose(); return EXIT_SUCCESS; }
int IupListDialog (int type, const char *title, int size, const char** list_str, int op, int max_col, int max_lin, int* marks) { Ihandle *lst, *ok, *dlg, *cancel, *dlg_box, *button_box; int i, bt; char *m=NULL; if (size > 999) size = 999; lst = IupList(NULL); for (i=0;i<size;i++) IupSetAttributeId(lst,"",i+1,list_str[i]); IupSetAttributeId(lst,"",i+1,NULL); IupSetAttribute(lst,"EXPAND","YES"); ok = IupButton("_@IUP_OK", NULL); IupSetAttribute(ok,"PADDING" ,"20x0"); IupSetCallback(ok, "ACTION", (Icallback)CB_button_OK); cancel = IupButton("_@IUP_CANCEL", NULL); IupSetAttribute(cancel,"PADDING" ,"20x0"); IupSetCallback(cancel, "ACTION", (Icallback)CB_button_CANCEL); button_box = IupHbox( IupFill(), ok, cancel, NULL); IupSetAttribute(button_box,"MARGIN","0x0"); IupSetAttribute(button_box, "NORMALIZESIZE", "HORIZONTAL"); dlg_box = IupVbox( lst, button_box, NULL); IupSetAttribute(dlg_box,"MARGIN","10x10"); IupSetAttribute(dlg_box,"GAP","10"); dlg = IupDialog(dlg_box); if (type == 1) { if (op<1 || op>size) op=1; iupAttribSetInt(dlg, "_IUP_LIST_NUMBER", op-1); IupSetInt(lst,"VALUE",op); IupSetCallback(lst, "ACTION", (Icallback)CB_list); IupSetCallback(lst, "DBLCLICK_CB", (Icallback)CB_dblclick); } else if ((type == 2) && (marks != NULL)) { m=(char *)marks; for (i=0;i<size;i++) m[i] = marks[i] ? '+' : '-'; m[i]='\0'; IupSetAttribute(lst,"MULTIPLE","YES"); IupSetAttribute(lst,"VALUE",m); } if (max_lin < 4) max_lin = 4; IupSetInt(lst, "VISIBLELINES", max_lin); IupSetInt(lst, "VISIBLECOLUMNS", max_col); IupSetStrAttribute(dlg,"TITLE", title); IupSetAttribute(dlg,"MINBOX","NO"); IupSetAttribute(dlg,"MAXBOX","NO"); IupSetAttributeHandle(dlg,"DEFAULTENTER", ok); IupSetAttributeHandle(dlg,"DEFAULTESC", cancel); IupSetAttribute(dlg,"PARENTDIALOG", IupGetGlobal("PARENTDIALOG")); IupSetAttribute(dlg,"ICON", IupGetGlobal("ICON")); IupPopup(dlg,IUP_CENTERPARENT,IUP_CENTERPARENT); if ((type == 2) && (marks != NULL)) { m=IupGetAttribute(lst,"VALUE"); for (i=0;i<size;i++) marks[i] = (m[i] == '+'); } bt = IupGetInt(dlg, "STATUS"); if (type == 1) { if (bt == 1) bt = iupAttribGetInt(dlg, "_IUP_LIST_NUMBER"); else bt = -1; } else { if (bt != 1) bt = -1; } IupDestroy(dlg); return bt; }
static void iGLCanvasBoxEnterChild(Ihandle* ih, Ihandle* child, int x, int y) { Ihandle* last_child = (Ihandle*)iupAttribGet(ih, "_IUP_GLBOX_LAST_ENTER"); if (last_child && last_child != child) { if (iupAttribGetInt(last_child, "ACTIVE")) { IFn cb; char* value; value = iupAttribGet(ih, "_IUPGLBOX_TIP_SET"); if (value) { value = iupAttribGet(ih, "_IUPGLBOX_TIP"); IupSetStrAttribute(ih, "TIP", value); /* reset attribute if it was set */ iupAttribSet(ih, "_IUPGLBOX_TIP", NULL); iupAttribSet(ih, "_IUPGLBOX_TIP_SET", NULL); } iupAttribSet(last_child, "HIGHLIGHT", NULL); iupAttribSet(last_child, "PRESSED", NULL); cb = (IFn)IupGetCallback(last_child, "GL_LEAVEWINDOW_CB"); if (cb) cb(last_child); value = iupAttribGet(ih, "_IUPGLBOX_CURSOR"); if (value) { IupSetStrAttribute(ih, "CURSOR", value); /* reset attribute if it was set */ iupAttribSet(ih, "_IUPGLBOX_CURSOR", NULL); } } iupAttribSet(ih, "_IUP_GLBOX_LAST_ENTER", NULL); } if (child && child != last_child) { if (iupAttribGetInt(child, "ACTIVE")) { IFnii cb; char* value; value = iupAttribGet(child, "TIP"); if (value) { iupAttribSet(ih, "_IUPGLBOX_TIP_SET", "1"); /* TIP can be NULL */ iupAttribSetStr(ih, "_IUPGLBOX_TIP", IupGetAttribute(ih, "TIP")); IupSetStrAttribute(ih, "TIP", value); IupSetAttribute(ih, "TIPVISIBLE", "Yes"); } iupAttribSet(child, "HIGHLIGHT", "1"); cb = (IFnii)IupGetCallback(child, "GL_ENTERWINDOW_CB"); if (cb) cb(child, x, y); value = iupAttribGet(child, "CURSOR"); if (value) { iupAttribSetStr(ih, "_IUPGLBOX_CURSOR", IupGetAttribute(ih, "CURSOR")); IupSetStrAttribute(ih, "CURSOR", value); } } iupAttribSet(ih, "_IUP_GLBOX_LAST_ENTER", (char*)child); } }
static int cb_btnDecodeToMorse(Ihandle *btn) { Ihandle *txtMorse, *txtAscii, *msgDialog; char *morseText, *asciiText; int morseLen, asciiLen; Ihandle *errorDialog; char *errorText; int opReturnCode; extern char *error_decode; extern BisTree textToMorse; /* Might be declared in the driver file */ txtMorse = IupGetHandle(TXTMORSE_4); txtAscii = IupGetHandle(TXTASCII_2); asciiText = IupGetAttribute(txtAscii, "VALUE"); asciiLen = strlen(asciiText); morseText = (char *) malloc(8 * asciiLen * sizeof(char)); if (asciiLen == 0) { msgDialog = IupMessageDlg(); IupSetAttribute(msgDialog, "DIALOGTYPE", "INFORMATION"); IupSetAttribute(msgDialog, "TITLE", "Decoding Procedure"); IupSetAttribute(msgDialog, "VALUE", generalInfo); IupSetAttribute(msgDialog, "BOTTONS", "OK"); IupSetAttribute(msgDialog, "PARENTDIALOG", MAINDIALOG); IupPopup(msgDialog, IUP_CENTER, IUP_CENTER); IupDestroy(msgDialog); // IupSetAttribute(txtMorse, "VALUE", 0); goto END; } opReturnCode = morse_convAsciiToMorse( &textToMorse, asciiText, asciiLen, morseText, &morseLen); /* Check to see if decoding operation is successful or not */ if (opReturnCode != 0) { errorText = (char *) malloc(strlen(error_decode) + 10); sprintf(errorText, error_decode, opReturnCode); errorDialog = IupMessageDlg(); IupSetAttribute(errorDialog, "DIALOGTYPE", "ERROR"); IupSetAttribute(errorDialog, "BUTTONS", "OK"); IupSetAttribute(errorDialog, "TITLE", "Error"); IupSetAttribute(errorDialog, "PARENTDIALOG", MAINDIALOG); IupSetAttribute(errorDialog, "VALUE", errorText); IupPopup(errorDialog, IUP_CENTER, IUP_CENTER); IupDestroy(errorDialog); free((void *) errorText); goto END; } /* Add a nul terminator at the end of the output buffer */ *(morseText + morseLen) = '\0'; /*printf("Decoded morse %s, len %d\n", morseText, morseLen);*/ IupSetStrAttribute(txtMorse, "VALUE", morseText); END: cb_txtMorseAction(txtMorse); free((void *) morseText); return IUP_DEFAULT; }