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); } }
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); } }
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); }
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); } }