static int iMatrixSetVisibleColAttribId(Ihandle *ih, int col, const char* value) { char* old_width; if (!iupStrBoolean(value)) { old_width = iupAttribGetId(ih, "WIDTH", col); if (old_width) iupAttribSetStrId(ih, "_IUP_SHOWCOL_WIDTH", col, old_width); else { old_width = iupAttribGetId(ih, "RASTERWIDTH", col); if (old_width) iupAttribSetStrId(ih, "_IUP_SHOWCOL_RASTERWIDTH", col, old_width); } IupSetAttributeId(ih, "WIDTH", col, "0"); /* this is enough */ } else { iupAttribSetId(ih, "WIDTH", col, NULL); /* this may be insufficient */ iupAttribSetId(ih, "RASTERWIDTH", col, NULL); old_width = iupAttribGetId(ih, "_IUP_SHOWCOL_WIDTH", col); if (old_width) IupSetStrAttributeId(ih, "WIDTH", col, old_width); else { old_width = iupAttribGetId(ih, "_IUP_SHOWCOL_RASTERWIDTH", col); if (old_width) IupSetStrAttributeId(ih, "RASTERWIDTH", col, old_width); else IupSetAttributeId(ih, "RASTERWIDTH", col, NULL); } } return 0; }
static int iMatrixSetVisibleLinAttribId(Ihandle *ih, int lin, const char* value) { char* old_height; if (!iupStrBoolean(value)) { old_height = iupAttribGetId(ih, "HEIGHT", lin); if (old_height) iupAttribSetStrId(ih, "_IUP_SHOWCOL_HEIGHT", lin, old_height); else { old_height = iupAttribGetId(ih, "RASTERHEIGHT", lin); if (old_height) iupAttribSetStrId(ih, "_IUP_SHOWCOL_RASTERHEIGHT", lin, old_height); } IupSetAttributeId(ih, "HEIGHT", lin, "0"); /* this is enough */ } else { iupAttribSetId(ih, "HEIGHT", lin, NULL); /* this may be insufficient */ iupAttribSetId(ih, "RASTERHEIGHT", lin, NULL); old_height = iupAttribGetId(ih, "_IUP_SHOWCOL_HEIGHT", lin); if (old_height) IupSetStrAttributeId(ih, "HEIGHT", lin, old_height); else { old_height = iupAttribGetId(ih, "_IUP_SHOWCOL_RASTERHEIGHT", lin); if (old_height) IupSetStrAttributeId(ih, "RASTERHEIGHT", lin, old_height); else IupSetAttributeId(ih, "RASTERHEIGHT", lin, NULL); } } return 0; }
static int winFileDlgPopup(Ihandle *ih, int x, int y) { InativeHandle* parent = iupDialogGetNativeParent(ih); OPENFILENAME openfilename; int result, dialogtype; char *value, *initial_dir=NULL; TCHAR* extfilter = NULL; iupAttribSetInt(ih, "_IUPDLG_X", x); /* used in iupDialogUpdatePosition */ iupAttribSetInt(ih, "_IUPDLG_Y", y); value = iupAttribGetStr(ih, "DIALOGTYPE"); if (iupStrEqualNoCase(value, "SAVE")) dialogtype = IUP_DIALOGSAVE; else if (iupStrEqualNoCase(value, "DIR")) dialogtype = IUP_DIALOGDIR; else dialogtype = IUP_DIALOGOPEN; if (dialogtype == IUP_DIALOGDIR) { winFileDlgGetFolder(ih); return IUP_NOERROR; } /* if NOT set will NOT be Modal */ /* anyway it will be modal only relative to its parent */ if (!parent) parent = GetActiveWindow(); ZeroMemory(&openfilename, sizeof(OPENFILENAME)); openfilename.lStructSize = sizeof(OPENFILENAME); openfilename.hwndOwner = parent; value = iupAttribGet(ih, "EXTFILTER"); if (value) { int index; extfilter = winFileDlgStrReplaceSeparator(iupwinStrToSystem(value)); openfilename.lpstrFilter = extfilter; value = iupAttribGet(ih, "FILTERUSED"); if (iupStrToInt(value, &index)) openfilename.nFilterIndex = index; else openfilename.nFilterIndex = 1; } else { value = iupAttribGet(ih, "FILTER"); if (value) { TCHAR *winfo, *wvalue; int sz1, sz2; char* info = iupAttribGet(ih, "FILTERINFO"); if (!info) info = value; winfo = iupwinStrToSystem(info); wvalue = iupwinStrToSystem(value); /* concat FILTERINFO+FILTER */ sz1 = lstrlen(winfo)+1; /* each part has a terminator */ sz2 = lstrlen(wvalue)+1; extfilter = (TCHAR*)malloc((sz1+sz2+1)*sizeof(TCHAR)); memcpy(extfilter, winfo, sz1*sizeof(TCHAR)); /* copy also the terminator */ memcpy(extfilter+sz1, wvalue, sz2*sizeof(TCHAR)); extfilter[sz1+sz2] = 0; /* additional terminator at the end */ openfilename.lpstrFilter = extfilter; openfilename.nFilterIndex = 1; } } openfilename.lpstrFile = (TCHAR*)malloc((IUP_MAX_FILENAME_SIZE+1)*sizeof(TCHAR)); value = iupAttribGet(ih, "FILE"); if (value) { iupwinStrCopy(openfilename.lpstrFile, value, IUP_MAX_FILENAME_SIZE); winFileDlgStrReplacePathSlash(openfilename.lpstrFile); } else openfilename.lpstrFile[0] = 0; openfilename.nMaxFile = IUP_MAX_FILENAME_SIZE; /* only supports extensions with up to three characters, should NOT include the period */ openfilename.lpstrDefExt = iupwinStrToSystem(iupAttribGet(ih, "EXTDEFAULT")); initial_dir = iupStrDup(iupAttribGet(ih, "DIRECTORY")); openfilename.lpstrInitialDir = iupwinStrToSystemFilename(initial_dir); if (openfilename.lpstrInitialDir) winFileDlgStrReplacePathSlash((TCHAR*)openfilename.lpstrInitialDir); openfilename.lpstrTitle = iupwinStrToSystem(iupAttribGet(ih, "TITLE")); openfilename.Flags = OFN_PATHMUSTEXIST | OFN_HIDEREADONLY; if (!iupAttribGetBoolean(ih, "NOOVERWRITEPROMPT")) openfilename.Flags |= OFN_OVERWRITEPROMPT; if (iupAttribGetBoolean(ih, "SHOWHIDDEN")) openfilename.Flags |= OFN_FORCESHOWHIDDEN; value = iupAttribGet(ih, "ALLOWNEW"); if (!value) { if (dialogtype == IUP_DIALOGSAVE) value = "YES"; else value = "NO"; } if (iupStrBoolean(value)) openfilename.Flags |= OFN_CREATEPROMPT; else openfilename.Flags |= OFN_FILEMUSTEXIST; if (iupAttribGetBoolean(ih, "NOCHANGEDIR")) openfilename.Flags |= OFN_NOCHANGEDIR; if (iupAttribGetBoolean(ih, "MULTIPLEFILES")) openfilename.Flags |= OFN_ALLOWMULTISELECT; openfilename.lpfnHook = winFileDlgSimpleHook; openfilename.Flags |= OFN_ENABLEHOOK | OFN_EXPLORER | OFN_ENABLESIZING; openfilename.lCustData = (LPARAM)ih; if (iupAttribGetBoolean(ih, "SHOWPREVIEW") && IupGetCallback(ih, "FILE_CB")) { openfilename.Flags |= OFN_ENABLETEMPLATE; openfilename.hInstance = iupwin_dll_hinstance? iupwin_dll_hinstance: iupwin_hinstance; openfilename.lpTemplateName = TEXT("iupPreviewDlg"); openfilename.lpfnHook = winFileDlgPreviewHook; } if (IupGetCallback(ih, "HELP_CB")) openfilename.Flags |= OFN_SHOWHELP; if (dialogtype == IUP_DIALOGOPEN) result = GetOpenFileName(&openfilename); else result = GetSaveFileName(&openfilename); if (result) { if (iupAttribGetBoolean(ih, "MULTIPLEFILES")) { /* If there is more than one file, replace terminator by the separator */ if (openfilename.lpstrFile[openfilename.nFileOffset-1] == 0 && openfilename.nFileOffset>0) { int i = 0; int count = 0; char* dir = iupwinStrFromSystemFilename(openfilename.lpstrFile); /* already is the directory, but without the last separator */ iupAttribSetStrf(ih, "DIRECTORY", "%s\\", dir); /* add the last separator */ /* first the path */ iupAttribSetStrId(ih, "MULTIVALUE", count, iupAttribGet(ih, "DIRECTORY")); /* here count=0 always */ count++; while (openfilename.lpstrFile[i] != 0 || openfilename.lpstrFile[i + 1] != 0) { if (openfilename.lpstrFile[i] == 0) { iupAttribSetStrId(ih, "MULTIVALUE", count, iupwinStrFromSystemFilename(openfilename.lpstrFile + i + 1)); count++; openfilename.lpstrFile[i] = TEXT('|'); } i++; } iupAttribSetInt(ih, "MULTIVALUECOUNT", count); openfilename.lpstrFile[i] = TEXT('|'); /* one last at the end */ iupAttribSetStr(ih, "VALUE", iupwinStrFromSystemFilename(openfilename.lpstrFile)); /* here file was already modified to match the IUP format */ } else { /* if there is only one file selected the returned value is different and includes just that file */ char* filename = iupwinStrFromSystemFilename(openfilename.lpstrFile); char* dir = iupStrFileGetPath(filename); int dir_len = (int)strlen(dir); iupAttribSetStr(ih, "DIRECTORY", dir); iupAttribSetStrId(ih, "MULTIVALUE", 0, dir); iupAttribSetStrId(ih, "MULTIVALUE", 1, filename + dir_len); iupAttribSetStr(ih, "VALUE", filename); /* here value is not separated by '|' */ iupAttribSetInt(ih, "MULTIVALUECOUNT", 2); free(dir); } iupAttribSet(ih, "STATUS", "0"); iupAttribSet(ih, "FILEEXIST", "YES"); } else { char* filename = iupwinStrFromSystemFilename(openfilename.lpstrFile); char* dir = iupStrFileGetPath(filename); iupAttribSetStr(ih, "DIRECTORY", dir); free(dir); if (winIsFile(openfilename.lpstrFile)) /* check if file exists */ { iupAttribSet(ih, "FILEEXIST", "YES"); iupAttribSet(ih, "STATUS", "0"); } else { iupAttribSet(ih, "FILEEXIST", "NO"); iupAttribSet(ih, "STATUS", "1"); } iupAttribSetStr(ih, "VALUE", filename); } iupAttribSetInt(ih, "FILTERUSED", (int)openfilename.nFilterIndex); } else { iupAttribSet(ih, "FILTERUSED", NULL); iupAttribSet(ih, "VALUE", NULL); iupAttribSet(ih, "DIRECTORY", NULL); iupAttribSet(ih, "FILEEXIST", NULL); iupAttribSet(ih, "STATUS", "-1"); } if (extfilter) free(extfilter); if (initial_dir) free(initial_dir); if (openfilename.lpstrFile) free(openfilename.lpstrFile); return IUP_NOERROR; }
static void iMatrixListCopyLinAttrib(Ihandle* ih, const char* name, int lin1, int lin2) { char* value = iupAttribGetId(ih, name, lin1); /* from lin1 to lin2 */ iupAttribSetStrId(ih, name, lin2, value); }
void IupSaveClassAttributes(Ihandle* ih) { int has_attrib_id, start_id = 0; Iclass* ic; char *name; iupASSERT(iupObjectCheck(ih)); if (!iupObjectCheck(ih)) return; ic = 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(ih, name)) /* can not be saved */ { name = iupTableNext(ic->attrib_func); continue; } if (!(afunc->flags & IUPAF_HAS_ID)) /* no ID */ { int inherit; char *def_value; char *value = iupClassObjectGetAttribute(ih, name, &def_value, &inherit); if (value && value[0]) /* NOT NULL and not empty */ { if ((def_value && iupStrEqualNoCase(def_value, value)) || /* equal to the default value */ (!def_value && iupStrFalse(value))) /* default=NULL and value=NO */ { name = iupTableNext(ic->attrib_func); continue; } if (!iupStrEqualNoCase(value, iupAttribGet(ih, name))) /* NOT already stored */ iupAttribSetStr(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(ih, "NUMCOL")+1, numlin = IupGetInt(ih, "NUMLIN")+1; for (lin=0; lin<numlin; lin++) { for (col=0; col<numcol; col++) { value = iupClassObjectGetAttributeId2(ih, name, lin, col); if (value && value[0]) /* NOT NULL and not empty */ { if (!iupStrEqualNoCase(value, iupAttribGetId2(ih, name, lin, col))) /* NOT already stored */ iupAttribSetStrId2(ih, name, lin, col, value); } } } } else { int id, count = IupGetInt(ih, "COUNT"); for (id=start_id; id<count+start_id; id++) { value = iupClassObjectGetAttributeId(ih, name, id); if (value && value[0]) /* NOT NULL and not empty */ { if (!iupStrEqualNoCase(value, iupAttribGetId(ih, name, id))) /* NOT already stored */ iupAttribSetStrId(ih, name, id, value); } } } } } name = iupTableNext(ic->attrib_func); } }