static void winFileDlgGetFolder(Ihandle *ih) { InativeHandle* parent = iupDialogGetNativeParent(ih); BROWSEINFO browseinfo; char buffer[MAX_PATH]; ITEMIDLIST *selecteditem; if (!parent) parent = GetActiveWindow(); ZeroMemory(&browseinfo, sizeof(BROWSEINFO)); browseinfo.lpszTitle = iupAttribGet(ih, "TITLE"); browseinfo.pszDisplayName = buffer; browseinfo.lpfn = winFileDlgBrowseCallback; browseinfo.lParam = (LPARAM)ih; browseinfo.ulFlags = IupGetGlobal("_IUPWIN_COINIT_MULTITHREADED")? 0: BIF_NEWDIALOGSTYLE; browseinfo.hwndOwner = parent; selecteditem = SHBrowseForFolder(&browseinfo); if (!selecteditem) { iupAttribSetStr(ih, "VALUE", NULL); iupAttribSetStr(ih, "STATUS", "-1"); } else { SHGetPathFromIDList(selecteditem, buffer); iupAttribStoreStr(ih, "VALUE", buffer); iupAttribSetStr(ih, "STATUS", "0"); } iupAttribSetStr(ih, "FILEEXIST", NULL); iupAttribSetStr(ih, "FILTERUSED", NULL); }
static int winColorDlgPopup(Ihandle* ih, int x, int y) { InativeHandle* parent = iupDialogGetNativeParent(ih); CHOOSECOLOR choosecolor; unsigned char r, g, b; COLORREF lpCustColors[16]; char* value; iupAttribSetInt(ih, "_IUPDLG_X", x); /* used in iupDialogUpdatePosition */ iupAttribSetInt(ih, "_IUPDLG_Y", y); /* if NOT set will NOT be Modal */ /* anyway it will be modal only relative to its parent */ if (!parent) parent = GetActiveWindow(); iupStrToRGB(iupAttribGet(ih, "VALUE"), &r, &g, &b); ZeroMemory(lpCustColors, 16*sizeof(COLORREF)); value = iupAttribGetStr(ih, "COLORTABLE"); if (value) winColorDlgStringToColors(value, lpCustColors); ZeroMemory(&choosecolor, sizeof(CHOOSECOLOR)); choosecolor.lStructSize = sizeof(CHOOSECOLOR); choosecolor.hwndOwner = parent; choosecolor.rgbResult = RGB(r, g, b); choosecolor.lpCustColors = lpCustColors; choosecolor.lCustData = (LPARAM)ih; choosecolor.Flags = CC_RGBINIT|CC_FULLOPEN; if (IupGetCallback(ih, "HELP_CB")) choosecolor.Flags |= CC_SHOWHELP; choosecolor.Flags |= CC_ENABLEHOOK; choosecolor.lpfnHook = (LPCCHOOKPROC)winColorDlgHookProc; if (!ChooseColor(&choosecolor)) { iupAttribSet(ih, "VALUE", NULL); iupAttribSet(ih, "COLORTABLE", NULL); iupAttribSet(ih, "STATUS", NULL); return IUP_NOERROR; } iupAttribSetStrf(ih, "VALUE", "%d %d %d", GetRValue(choosecolor.rgbResult), GetGValue(choosecolor.rgbResult), GetBValue(choosecolor.rgbResult)); iupAttribSet(ih, "COLORTABLE", winColorDlgColorsToString(lpCustColors)); iupAttribSet(ih, "STATUS", "1"); return IUP_NOERROR; }
static void winFileDlgGetFolder(Ihandle *ih) { InativeHandle* parent = iupDialogGetNativeParent(ih); BROWSEINFO browseinfo; TCHAR filename[MAX_PATH]; LPITEMIDLIST selecteditem; /* if NOT set will NOT be Modal */ /* anyway it will be modal only relative to its parent */ if (!parent) parent = GetActiveWindow(); ZeroMemory(&browseinfo, sizeof(BROWSEINFO)); browseinfo.lpszTitle = iupwinStrToSystem(iupAttribGet(ih, "TITLE")); browseinfo.pszDisplayName = filename; browseinfo.lpfn = winFileDlgBrowseCallback; browseinfo.lParam = (LPARAM)ih; browseinfo.ulFlags = IupGetGlobal("_IUPWIN_COINIT_MULTITHREADED")? 0: BIF_NEWDIALOGSTYLE; browseinfo.hwndOwner = parent; selecteditem = SHBrowseForFolder(&browseinfo); if (!selecteditem) { iupAttribSet(ih, "VALUE", NULL); iupAttribSet(ih, "STATUS", "-1"); } else { SHGetPathFromIDList(selecteditem, filename); iupAttribSetStr(ih, "VALUE", iupwinStrFromSystemFilename(filename)); iupAttribSet(ih, "STATUS", "0"); } iupAttribSet(ih, "FILEEXIST", NULL); iupAttribSet(ih, "FILTERUSED", NULL); }
static int gtkDialogMapMethod(Ihandle* ih) { int decorations = 0; int functions = 0; InativeHandle* parent; GtkWidget* fixed; int has_titlebar = 0; #ifdef HILDON if (iupAttribGetBoolean(ih, "HILDONWINDOW")) { HildonProgram *program = HILDON_PROGRAM(hildon_program_get_instance()); ih->handle = hildon_window_new(); if (ih->handle) hildon_program_add_window(program, HILDON_WINDOW(ih->handle)); } else { iupAttribSetStr(ih, "DIALOGHINT", "YES"); /* otherwise not displayed correctly */ ih->handle = gtk_window_new(GTK_WINDOW_TOPLEVEL); } #else ih->handle = gtk_window_new(GTK_WINDOW_TOPLEVEL); #endif if (!ih->handle) return IUP_ERROR; parent = iupDialogGetNativeParent(ih); if (parent) { gtk_window_set_transient_for((GtkWindow*)ih->handle, (GtkWindow*)parent); /* manually remove child windows when parent is destroyed */ g_signal_connect(G_OBJECT(parent), "destroy", G_CALLBACK(gtkDialogChildDestroyEvent), ih); } g_signal_connect(G_OBJECT(ih->handle), "focus-in-event", G_CALLBACK(iupgtkFocusInOutEvent), ih); g_signal_connect(G_OBJECT(ih->handle), "focus-out-event", G_CALLBACK(iupgtkFocusInOutEvent), ih); g_signal_connect(G_OBJECT(ih->handle), "enter-notify-event", G_CALLBACK(iupgtkEnterLeaveEvent), ih); g_signal_connect(G_OBJECT(ih->handle), "leave-notify-event", G_CALLBACK(iupgtkEnterLeaveEvent), ih); g_signal_connect(G_OBJECT(ih->handle), "show-help", G_CALLBACK(iupgtkShowHelp), ih); /* The iupgtkKeyPressEvent of the control with the focus will propagate the key up to the dialog. */ /* Inside iupgtkKeyPressEvent we test this to avoid duplicate calls. */ g_signal_connect(G_OBJECT(ih->handle), "key-press-event", G_CALLBACK(iupgtkKeyPressEvent), ih); g_signal_connect(G_OBJECT(ih->handle), "configure-event", G_CALLBACK(gtkDialogConfigureEvent), ih); g_signal_connect(G_OBJECT(ih->handle), "window-state-event", G_CALLBACK(gtkDialogWindowStateEvent), ih); g_signal_connect(G_OBJECT(ih->handle), "delete-event", G_CALLBACK(iupgtkDialogDeleteEvent), ih); gtk_window_set_default_size((GtkWindow*)ih->handle, 100, 100); /* set this to avoid size calculation problems */ if (iupAttribGetBoolean(ih, "DIALOGHINT")) gtk_window_set_type_hint(GTK_WINDOW(ih->handle), GDK_WINDOW_TYPE_HINT_DIALOG); /* the container that will receive the child element. */ fixed = gtk_fixed_new(); gtk_container_add((GtkContainer*)ih->handle, fixed); gtk_widget_show(fixed); /* initialize the widget */ gtk_widget_realize(ih->handle); if (iupAttribGet(ih, "TITLE")) has_titlebar = 1; if (iupAttribGetBoolean(ih, "RESIZE")) { functions |= GDK_FUNC_RESIZE; decorations |= GDK_DECOR_RESIZEH; decorations |= GDK_DECOR_BORDER; /* has_border */ } else iupAttribSetStr(ih, "MAXBOX", "NO"); if (iupAttribGetBoolean(ih, "MENUBOX")) { functions |= GDK_FUNC_CLOSE; decorations |= GDK_DECOR_MENU; has_titlebar = 1; } if (iupAttribGetBoolean(ih, "MAXBOX")) { functions |= GDK_FUNC_MAXIMIZE; decorations |= GDK_DECOR_MAXIMIZE; has_titlebar = 1; } if (iupAttribGetBoolean(ih, "MINBOX")) { functions |= GDK_FUNC_MINIMIZE; decorations |= GDK_DECOR_MINIMIZE; has_titlebar = 1; } if (has_titlebar) { functions |= GDK_FUNC_MOVE; decorations |= GDK_DECOR_TITLE; gtk_window_set_title((GtkWindow*)ih->handle, ""); } if (iupAttribGetBoolean(ih, "BORDER") || has_titlebar) decorations |= GDK_DECOR_BORDER; /* has_border */ if (decorations == 0) gtk_window_set_decorated((GtkWindow*)ih->handle, FALSE); else { GdkWindow* window = iupgtkGetWindow(ih->handle); if (window) { gdk_window_set_decorations(window, (GdkWMDecoration)decorations); gdk_window_set_functions(window, (GdkWMFunction)functions); } } /* configure for DRAG&DROP */ if (IupGetCallback(ih, "DROPFILES_CB")) iupAttribSetStr(ih, "DROPFILESTARGET", "YES"); { /* Reset the DLGBGCOLOR global attribute if it is the first time a dialog is created. The value returned by gtk_style_new is not accurate. */ GtkStyle* style = gtk_widget_get_style(ih->handle); if (style && IupGetGlobal("_IUP_RESET_GLOBALCOLORS")) { iupgtkUpdateGlobalColors(style); IupSetGlobal("_IUP_RESET_GLOBALCOLORS", NULL); } } /* configure the size range */ gtkDialogSetMinMax(ih, 1, 1, 65535, 65535); /* MINSIZE and MAXSIZE default values */ /* Ignore VISIBLE before mapping */ iupAttribSetStr(ih, "VISIBLE", NULL); if (iupStrBoolean(IupGetGlobal("INPUTCALLBACKS"))) gtk_widget_add_events(ih->handle, GDK_POINTER_MOTION_MASK|GDK_BUTTON_PRESS_MASK|GDK_BUTTON_RELEASE_MASK|GDK_BUTTON_MOTION_MASK); return IUP_NOERROR; }
static int winDialogMapMethod(Ihandle* ih) { InativeHandle* native_parent; DWORD dwStyle = WS_CLIPSIBLINGS, dwExStyle = 0; int has_titlebar = 0, has_border = 0; char* classname = "IupDialog"; char* title = iupAttribGet(ih, "TITLE"); if (title) has_titlebar = 1; if (iupAttribGetBoolean(ih, "RESIZE")) { dwStyle |= WS_THICKFRAME; has_border = 1; } else iupAttribSetStr(ih, "MAXBOX", "NO"); if (iupAttribGetBoolean(ih, "MENUBOX")) { dwStyle |= WS_SYSMENU; has_titlebar = 1; } if (iupAttribGetBoolean(ih, "MAXBOX")) { dwStyle |= WS_MAXIMIZEBOX; has_titlebar = 1; } if (iupAttribGetBoolean(ih, "MINBOX")) { dwStyle |= WS_MINIMIZEBOX; has_titlebar = 1; } if (iupAttribGetBoolean(ih, "BORDER") || has_titlebar) has_border = 1; if (iupAttribGetBoolean(ih, "MDICHILD")) { Ihandle *client; /* must have a parent dialog (the mdi frame) */ Ihandle* parent = IupGetAttributeHandle(ih, "PARENTDIALOG"); if (!parent || !parent->handle) return IUP_ERROR; /* set when the mdi client is mapped */ client = (Ihandle*)iupAttribGet(parent, "MDICLIENT_HANDLE"); if (!client) return IUP_ERROR; /* store the mdi client handle in each mdi child also */ iupAttribSetStr(ih, "MDICLIENT_HANDLE", (char*)client); classname = "IupDialogMDIChild"; /* The actual parent is the mdi client */ native_parent = client->handle; dwStyle |= WS_CHILD; if (has_titlebar) dwStyle |= WS_CAPTION; else if (has_border) dwStyle |= WS_BORDER; if (!IupGetName(ih)) iupAttribSetHandleName(ih); } else { native_parent = iupDialogGetNativeParent(ih); if (native_parent) { dwStyle |= WS_POPUP; if (has_titlebar) dwStyle |= WS_CAPTION; else if (has_border) dwStyle |= WS_BORDER; } else { if (has_titlebar) { dwStyle |= WS_OVERLAPPED; } else { if (has_border) dwStyle |= WS_POPUP | WS_BORDER; else dwStyle |= WS_POPUP; dwExStyle |= WS_EX_NOACTIVATE; /* this will hide it from the taskbar */ } } if (iupAttribGetBoolean(ih, "MDIFRAME")) { COLORREF color = GetSysColor(COLOR_BTNFACE); iupAttribSetStrf(ih, "_IUPWIN_BACKGROUND_COLOR", "%d %d %d", (int)GetRValue(color), (int)GetGValue(color), (int)GetBValue(color)); classname = "IupDialogMDIFrame"; } } if (iupAttribGetBoolean(ih, "TOOLBOX") && native_parent) dwExStyle |= WS_EX_TOOLWINDOW | WS_EX_WINDOWEDGE; if (iupAttribGetBoolean(ih, "DIALOGFRAME") && native_parent) dwExStyle |= WS_EX_DLGMODALFRAME; /* this will hide the MENUBOX but not the close button */ iupwinGetNativeParentStyle(ih, &dwExStyle, &dwStyle); if (iupAttribGetBoolean(ih, "HELPBUTTON")) dwExStyle |= WS_EX_CONTEXTHELP; if (iupAttribGetBoolean(ih, "CONTROL") && native_parent) { /* TODO: this were used by LuaCom to create embeded controls, don't know if it is still working */ dwStyle = WS_CHILD | WS_TABSTOP | WS_CLIPCHILDREN; classname = "IupDialogControl"; } /* CreateWindowEx will send WM_GETMINMAXINFO before Ihandle is associated with HWND */ if (iupAttribGet(ih, "MINSIZE") || iupAttribGet(ih, "MAXSIZE")) winMinMaxHandle = ih; /* size will be updated in IupRefresh -> winDialogLayoutUpdate */ /* position will be updated in iupDialogShowXY */ if (iupAttribGetBoolean(ih, "MDICHILD")) ih->handle = CreateMDIWindow(classname, title, /* title */ dwStyle, /* style */ 0, /* x-position */ 0, /* y-position */ 100, /* horizontal size - set this to avoid size calculation problems */ 100, /* vertical size */ native_parent, /* owner window */ iupwin_hinstance, /* instance of app. */ 0); /* no creation parameters */ else ih->handle = CreateWindowEx(dwExStyle, /* extended styles */ classname, /* class */ title, /* title */ dwStyle, /* style */ 0, /* x-position */ 0, /* y-position */ 100, /* horizontal size - set this to avoid size calculation problems */ 100, /* vertical size */ native_parent, /* owner window */ (HMENU)0, /* Menu or child-window identifier */ iupwin_hinstance, /* instance of app. */ NULL); /* no creation parameters */ if (!ih->handle) return IUP_ERROR; /* associate HWND with Ihandle*, all Win32 controls must call this. */ iupwinHandleAdd(ih, ih->handle); if (iupStrEqual(classname, "IupDialogMDIChild")) /* hides the mdi child */ ShowWindow(ih->handle, SW_HIDE); /* configure for DROP of files */ if (IupGetCallback(ih, "DROPFILES_CB")) iupAttribSetStr(ih, "DROPFILESTARGET", "YES"); /* Reset attributes handled during creation that */ /* also can be changed later, and can be consulted from the native system. */ iupAttribSetStr(ih, "TITLE", NULL); /* Ignore VISIBLE before mapping */ iupAttribSetStr(ih, "VISIBLE", NULL); /* Set the default CmdShow for ShowWindow */ ih->data->cmd_show = SW_SHOWNORMAL; if (iupAttribGetBoolean(ih, "MDICHILD")) winDialogMDIRefreshMenu(ih); return IUP_NOERROR; }
void iupDialogAdjustPos(Ihandle *ih, int *x, int *y) { int cursor_x = 0, cursor_y = 0; int screen_width = 0, screen_height = 0; int current_x = 0, current_y = 0; int parent_x = 0, parent_y = 0; if (*x == IUP_CURRENT || *y == IUP_CURRENT) iupdrvDialogGetPosition(ih->handle, ¤t_x, ¤t_y); if (*x == IUP_CENTER || *y == IUP_CENTER || *x == IUP_RIGHT || *y == IUP_RIGHT || *x == IUP_CENTERPARENT || *y == IUP_CENTERPARENT) iupdrvGetScreenSize(&screen_width, &screen_height); if (*x == IUP_CENTERPARENT || *y == IUP_CENTERPARENT) { InativeHandle* parent = iupDialogGetNativeParent(ih); if (parent) { iupdrvDialogGetPosition(parent, &parent_x, &parent_y); if (*x == IUP_CENTERPARENT && *y == IUP_CENTERPARENT) iupdrvDialogGetSize(parent, &screen_width, &screen_height); else if (*x == IUP_CENTERPARENT) iupdrvDialogGetSize(parent, &screen_width, NULL); else if (*y == IUP_CENTERPARENT) iupdrvDialogGetSize(parent, NULL, &screen_height); } } if (*x == IUP_MOUSEPOS || *y == IUP_MOUSEPOS) iupdrvGetCursorPos(&cursor_x, &cursor_y); if (IupGetInt(ih, "MDICHILD")) { Ihandle* client = (Ihandle*)iupAttribGetStr(ih, "MDICLIENT_HANDLE"); if (client) { /* position is relative to mdi client */ parent_x = 0; parent_y = 0; /* screen size is now the size of the mdi client */ screen_width = client->currentwidth; screen_height = client->currentheight; iupdrvScreenToClient(client, ¤t_x, ¤t_y); iupdrvScreenToClient(client, &cursor_x, &cursor_y); } } switch (*x) { case IUP_CENTERPARENT: *x = (screen_width - ih->currentwidth)/2 + parent_x; break; case IUP_CENTER: *x = (screen_width - ih->currentwidth)/2; break; case IUP_LEFT: *x = 0; break; case IUP_RIGHT: *x = screen_width - ih->currentwidth; break; case IUP_MOUSEPOS: *x = cursor_x; break; case IUP_CURRENT: *x = current_x; break; } switch (*y) { case IUP_CENTERPARENT: *y = (screen_height - ih->currentheight)/2 + parent_y; break; case IUP_CENTER: *y = (screen_height - ih->currentheight)/2; break; case IUP_LEFT: *y = 0; break; case IUP_RIGHT: *y = screen_height - ih->currentheight; break; case IUP_MOUSEPOS: *y = cursor_y; break; case IUP_CURRENT: *y = current_y; break; } }
static int gtkFontDlgPopup(Ihandle* ih, int x, int y) { InativeHandle* parent = iupDialogGetNativeParent(ih); GtkFontSelectionDialog* dialog; int response; char* preview_text, *standardfont; iupAttribSetInt(ih, "_IUPDLG_X", x); /* used in iupDialogUpdatePosition */ iupAttribSetInt(ih, "_IUPDLG_Y", y); dialog = (GtkFontSelectionDialog*)gtk_font_selection_dialog_new(iupgtkStrConvertToUTF8(iupAttribGet(ih, "TITLE"))); if (!dialog) return IUP_ERROR; if (parent) gtk_window_set_transient_for((GtkWindow*)dialog, (GtkWindow*)parent); standardfont = iupAttribGet(ih, "VALUE"); if (!standardfont) standardfont = IupGetGlobal("DEFAULTFONT"); gtk_font_selection_dialog_set_font_name(dialog, standardfont); preview_text = iupAttribGet(ih, "PREVIEWTEXT"); if (preview_text) gtk_font_selection_dialog_set_preview_text(dialog, preview_text); if (IupGetCallback(ih, "HELP_CB")) gtk_dialog_add_button(GTK_DIALOG(dialog), GTK_STOCK_HELP, GTK_RESPONSE_HELP); /* initialize the widget */ gtk_widget_realize(GTK_WIDGET(dialog)); ih->handle = GTK_WIDGET(dialog); iupDialogUpdatePosition(ih); ih->handle = NULL; do { response = gtk_dialog_run(GTK_DIALOG(dialog)); if (response == GTK_RESPONSE_HELP) { Icallback cb = IupGetCallback(ih, "HELP_CB"); if (cb && cb(ih) == IUP_CLOSE) response = GTK_RESPONSE_CANCEL; } } while (response == GTK_RESPONSE_HELP); if (response == GTK_RESPONSE_OK) { char* fontname = gtk_font_selection_dialog_get_font_name(dialog); iupAttribStoreStr(ih, "VALUE", fontname); g_free(fontname); iupAttribSetStr(ih, "STATUS", "1"); } else { iupAttribSetStr(ih, "VALUE", NULL); iupAttribSetStr(ih, "STATUS", NULL); } gtk_widget_destroy(GTK_WIDGET(dialog)); return IUP_NOERROR; }
static int gtkMessageDlgPopup(Ihandle* ih, int x, int y) { InativeHandle* parent = iupDialogGetNativeParent(ih); GtkMessageType type = GTK_MESSAGE_INFO; GtkWidget* dialog; char *icon, *buttons, *title; int response, num_but = 2; iupAttribSetInt(ih, "_IUPDLG_X", x); 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, iupgtkStrConvertToUTF8(iupAttribGetStr(ih, "VALUE"))); if (!dialog) return IUP_ERROR; title = iupAttribGetStr(ih, "TITLE"); if (title) gtk_window_set_title(GTK_WINDOW(dialog), iupgtkStrConvertToUTF8(title)); buttons = iupAttribGetStr(ih, "BUTTONS"); if (iupStrEqualNoCase(buttons, "OKCANCEL")) { gtk_dialog_add_button(GTK_DIALOG(dialog), GTK_STOCK_OK, IUP_RESPONSE_1); gtk_dialog_add_button(GTK_DIALOG(dialog), GTK_STOCK_CANCEL, IUP_RESPONSE_2); } else if (iupStrEqualNoCase(buttons, "YESNO")) { gtk_dialog_add_button(GTK_DIALOG(dialog), GTK_STOCK_YES, IUP_RESPONSE_1); gtk_dialog_add_button(GTK_DIALOG(dialog), GTK_STOCK_NO, IUP_RESPONSE_2); } else /* OK */ { gtk_dialog_add_button(GTK_DIALOG(dialog), GTK_STOCK_OK, IUP_RESPONSE_1); num_but = 1; } if (IupGetCallback(ih, "HELP_CB")) gtk_dialog_add_button(GTK_DIALOG(dialog), GTK_STOCK_HELP, IUP_RESPONSE_HELP); if (num_but == 2 && iupAttribGetInt(ih, "BUTTONDEFAULT") == 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) response = (num_but == 2)? IUP_RESPONSE_2: IUP_RESPONSE_1; } } while (response == IUP_RESPONSE_HELP); if (response == IUP_RESPONSE_1) IupSetAttribute(ih, "BUTTONRESPONSE", "1"); else IupSetAttribute(ih, "BUTTONRESPONSE", "2"); gtk_widget_destroy(dialog); return IUP_NOERROR; }
static int winMessageDlgPopup(Ihandle* ih, int x, int y) { InativeHandle* parent = iupDialogGetNativeParent(ih); MSGBOXPARAMS MsgBoxParams; int result, num_but = 2; DWORD dwStyle = MB_TASKMODAL; char *icon, *buttons; (void)x; (void)y; if (!parent) parent = GetActiveWindow(); icon = iupAttribGetStr(ih, "DIALOGTYPE"); if (iupStrEqualNoCase(icon, "ERROR")) dwStyle |= MB_ICONERROR; else if (iupStrEqualNoCase(icon, "WARNING")) dwStyle |= MB_ICONWARNING; else if (iupStrEqualNoCase(icon, "INFORMATION")) dwStyle |= MB_ICONINFORMATION; else if (iupStrEqualNoCase(icon, "QUESTION")) dwStyle |= MB_ICONQUESTION; buttons = iupAttribGetStr(ih, "BUTTONS"); if (iupStrEqualNoCase(buttons, "OKCANCEL")) dwStyle |= MB_OKCANCEL; else if (iupStrEqualNoCase(buttons, "YESNO")) dwStyle |= MB_YESNO; else { dwStyle |= MB_OK; num_but = 1; } if (IupGetCallback(ih, "HELP_CB")) dwStyle |= MB_HELP; if (num_but == 2 && iupAttribGetInt(ih, "BUTTONDEFAULT") == 2) dwStyle |= MB_DEFBUTTON2; else dwStyle |= MB_DEFBUTTON1; MsgBoxParams.cbSize = sizeof(MSGBOXPARAMS); MsgBoxParams.hwndOwner = parent; MsgBoxParams.hInstance = NULL; MsgBoxParams.lpszText = iupAttribGet(ih, "VALUE"); MsgBoxParams.lpszCaption = iupAttribGet(ih, "TITLE"); MsgBoxParams.dwStyle = dwStyle; MsgBoxParams.lpszIcon = NULL; MsgBoxParams.dwContextHelpId = (DWORD_PTR)ih; MsgBoxParams.lpfnMsgBoxCallback = (MSGBOXCALLBACK)winMessageDlgHelpCallback; MsgBoxParams.dwLanguageId = MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT); result = MessageBoxIndirect(&MsgBoxParams); if (result == 0) { iupAttribSetStr(ih, "BUTTONRESPONSE", NULL); return IUP_ERROR; } if (result == IDNO || result == IDCANCEL) iupAttribSetStr(ih, "BUTTONRESPONSE", "2"); else iupAttribSetStr(ih, "BUTTONRESPONSE", "1"); return IUP_NOERROR; }
static int motDialogMapMethod(Ihandle* ih) { Widget dialog_manager; InativeHandle* parent; int mwm_decor = 0; int num_args = 0; Arg args[20]; if (iupAttribGetInt(ih, "DIALOGFRAME")) { iupAttribSetStr(ih, "RESIZE", "NO"); iupAttribSetStr(ih, "MAXBOX", "NO"); iupAttribSetStr(ih, "MINBOX", "NO"); } /****************************/ /* Create the dialog shell */ /****************************/ if (iupAttribGet(ih, "TITLE")) mwm_decor |= MWM_DECOR_TITLE; if (iupAttribGetInt(ih, "MENUBOX")) mwm_decor |= MWM_DECOR_MENU; if (iupAttribGetInt(ih, "MINBOX")) mwm_decor |= MWM_DECOR_MINIMIZE; if (iupAttribGetInt(ih, "MAXBOX")) mwm_decor |= MWM_DECOR_MAXIMIZE; if (iupAttribGetInt(ih, "RESIZE")) mwm_decor |= MWM_DECOR_RESIZEH; if (iupAttribGetInt(ih, "BORDER")) mwm_decor |= MWM_DECOR_BORDER; iupmotSetArg(args, num_args, XmNmappedWhenManaged, False); /* so XtRealizeWidget will not show the dialog */ iupmotSetArg(args, num_args, XmNdeleteResponse, XmDO_NOTHING); iupmotSetArg(args, num_args, XmNallowShellResize, True); /* Used so the BulletinBoard can control the shell size */ iupmotSetArg(args, num_args, XmNtitle, ""); iupmotSetArg(args, num_args, XmNvisual, iupmot_visual); if (iupmotColorMap()) iupmotSetArg(args, num_args, XmNcolormap, iupmotColorMap()); if (mwm_decor != 0x7E) iupmotSetArg(args, num_args, XmNmwmDecorations, mwm_decor); if (iupAttribGetInt(ih, "SAVEUNDER")) iupmotSetArg(args, num_args, XmNsaveUnder, True); parent = iupDialogGetNativeParent(ih); if (parent) ih->handle = XtCreatePopupShell(NULL, topLevelShellWidgetClass, (Widget)parent, args, num_args); else ih->handle = XtAppCreateShell(NULL, "dialog", topLevelShellWidgetClass, iupmot_display, args, num_args); if (!ih->handle) return IUP_ERROR; XmAddWMProtocolCallback(ih->handle, iupmot_wm_deletewindow, motDialogCBclose, (XtPointer)ih); XtAddEventHandler(ih->handle, FocusChangeMask, False, (XtEventHandler)iupmotFocusChangeEvent, (XtPointer)ih); XtAddEventHandler(ih->handle, EnterWindowMask, False, (XtEventHandler)iupmotEnterLeaveWindowEvent, (XtPointer)ih); XtAddEventHandler(ih->handle, LeaveWindowMask, False, (XtEventHandler)iupmotEnterLeaveWindowEvent, (XtPointer)ih); XtAddEventHandler(ih->handle, StructureNotifyMask, False, (XtEventHandler)motDialogCBStructureNotifyEvent, (XtPointer)ih); XtAddCallback(ih->handle, XmNdestroyCallback, (XtCallbackProc)motDialogDestroyCallback, (XtPointer)ih); /*****************************/ /* Create the dialog manager */ /*****************************/ dialog_manager = XtVaCreateManagedWidget( "dialog_manager", xmBulletinBoardWidgetClass, ih->handle, XmNmarginWidth, 0, XmNmarginHeight, 0, XmNwidth, 100, /* set this to avoid size calculation problems */ XmNheight, 100, XmNborderWidth, 0, XmNshadowThickness, 0, XmNnoResize, iupAttribGetInt(ih, "RESIZE")? False: True, XmNresizePolicy, XmRESIZE_NONE, /* no automatic resize of children */ XmNuserData, ih, /* used only in motDialogConfigureNotify */ XmNnavigationType, XmTAB_GROUP, NULL); XtOverrideTranslations(dialog_manager, XtParseTranslationTable("<Configure>: iupDialogConfigure()")); XtAddCallback(dialog_manager, XmNhelpCallback, (XtCallbackProc)iupmotHelpCallback, (XtPointer)ih); XtAddEventHandler(dialog_manager, KeyPressMask, False,(XtEventHandler)iupmotKeyPressEvent, (XtPointer)ih); /* force the BGCOLOR to match the DLGBGCOLOR */ motDialogSetBgColorAttrib(ih, IupGetGlobal("DLGBGCOLOR")); /* initialize the widget */ XtRealizeWidget(ih->handle); /* child dialogs must be always on top of the parent */ if (parent) XSetTransientForHint(iupmot_display, XtWindow(ih->handle), XtWindow(parent)); if (mwm_decor != 0x7E) /* some decoration was changed */ motDialogSetWindowManagerStyle(ih); /* Ignore VISIBLE before mapping */ iupAttribSetStr(ih, "VISIBLE", NULL); if (IupGetGlobal("_IUP_SET_DLGFGCOLOR")) { iupmotSetGlobalColorAttrib(dialog_manager, XmNforeground, "DLGFGCOLOR"); IupSetGlobal("_IUP_SET_DLGFGCOLOR", NULL); } return IUP_NOERROR; }
static int motMessageDlgPopup(Ihandle* ih, int x, int y) { InativeHandle* parent = iupDialogGetNativeParent(ih); Widget msgbox, dialog; int style = XmDIALOG_FULL_APPLICATION_MODAL; int type = XmDIALOG_MESSAGE; int num_but = 2; char *value; iupAttribSetInt(ih, "_IUPDLG_X", x); /* used in iupDialogUpdatePosition */ iupAttribSetInt(ih, "_IUPDLG_Y", y); if (parent) { msgbox = XmCreateMessageDialog(parent, "messagedialog", NULL, 0); dialog = XtParent(msgbox); } else { dialog = XtAppCreateShell(NULL, "messagedialog", topLevelShellWidgetClass, iupmot_display, NULL, 0); msgbox = XmCreateMessageBox(dialog, "messagebox", NULL, 0); style = XmDIALOG_MODELESS; XtVaSetValues(dialog, XmNmwmInputMode, MWM_INPUT_FULL_APPLICATION_MODAL, XmNmappedWhenManaged, False, XmNsaveUnder, True, NULL); } if (!msgbox) return IUP_NOERROR; value = iupAttribGetStr(ih, "DIALOGTYPE"); if (iupStrEqualNoCase(value, "ERROR")) type = XmDIALOG_ERROR; else if (iupStrEqualNoCase(value, "WARNING")) type = XmDIALOG_WARNING; else if (iupStrEqualNoCase(value, "INFORMATION")) type = XmDIALOG_INFORMATION; else if (iupStrEqualNoCase(value, "QUESTION")) type = XmDIALOG_QUESTION; value = iupAttribGet(ih, "TITLE"); if (value) iupmotSetString(msgbox, XmNdialogTitle, value); else { if (parent) { XmString title; XtVaGetValues(parent, XmNdialogTitle, &title, NULL); XtVaSetValues(msgbox, XmNdialogTitle, title, NULL); } } value = iupAttribGet(ih, "VALUE"); if (value) iupmotSetString(msgbox, XmNmessageString, value); XtVaSetValues(msgbox, XmNdialogType, type, XmNdialogStyle, style, XmNautoUnmanage, False, XmNnoResize, True, NULL); value = iupAttribGetStr(ih, "BUTTONS"); if (iupStrEqualNoCase(value, "OK")) { XtUnmanageChild(XmMessageBoxGetChild(msgbox, XmDIALOG_CANCEL_BUTTON)); num_but = 1; } else if (iupStrEqualNoCase(value, "YESNO")) { iupmotSetString(msgbox, XmNokLabelString, iupStrMessageGet("IUP_YES")); iupmotSetString(msgbox, XmNcancelLabelString, iupStrMessageGet("IUP_NO")); } if (!IupGetCallback(ih, "HELP_CB")) XtUnmanageChild(XmMessageBoxGetChild(msgbox, XmDIALOG_HELP_BUTTON)); if (num_but == 2 && iupAttribGetInt(ih, "BUTTONDEFAULT") == 2) XtVaSetValues(msgbox, XmNdefaultButtonType, XmDIALOG_CANCEL_BUTTON, NULL); else XtVaSetValues(msgbox, XmNdefaultButtonType, XmDIALOG_OK_BUTTON, NULL); XtAddCallback(msgbox, XmNokCallback, (XtCallbackProc)motMessageDlgCallback, (XtPointer)ih); XtAddCallback(msgbox, XmNcancelCallback, (XtCallbackProc)motMessageDlgCallback, (XtPointer)ih); XtAddCallback(msgbox, XmNhelpCallback, (XtCallbackProc)motMessageDlgHelpCallback, (XtPointer)ih); XmAddWMProtocolCallback(dialog, iupmot_wm_deletewindow, motMessageDlgDeleteWindowCallback, (XtPointer)ih); XtManageChild(msgbox); XtRealizeWidget(dialog); ih->handle = dialog; iupDialogUpdatePosition(ih); ih->handle = NULL; /* reset handle */ if (style == XmDIALOG_MODELESS) XtPopup(dialog, XtGrabExclusive); /* while the user hasn't provided an answer, simulate main loop. ** The answer changes as soon as the user selects one of the ** buttons and the callback routine changes its value. */ iupAttribSetStr(ih, "BUTTONRESPONSE", NULL); while (iupAttribGet(ih, "BUTTONRESPONSE") == NULL) XtAppProcessEvent(iupmot_appcontext, XtIMAll); if (!iupAttribGet(ih, "_IUP_WM_DELETE")) { XtUnmanageChild(msgbox); if (style == XmDIALOG_MODELESS) { XtPopdown(dialog); XtDestroyWidget(dialog); } } return IUP_NOERROR; }
static int gtkColorDlgPopup(Ihandle* ih, int x, int y) { InativeHandle* parent = iupDialogGetNativeParent(ih); GtkColorSelectionDialog* dialog; GtkColorSelection* colorsel; GdkColor color; char *value; unsigned char r = 0, g = 0, b = 0, a = 255; int response, ret; iupAttribSetInt(ih, "_IUPDLG_X", x); /* used in iupDialogUpdatePosition */ iupAttribSetInt(ih, "_IUPDLG_Y", y); dialog = (GtkColorSelectionDialog*)gtk_color_selection_dialog_new(iupgtkStrConvertToUTF8(iupAttribGet(ih, "TITLE"))); if (!dialog) return IUP_ERROR; if (parent) gtk_window_set_transient_for((GtkWindow*)dialog, (GtkWindow*)parent); ret = iupStrToRGBA(iupAttribGet(ih, "VALUE"), &r, &g, &b, &a); colorsel = (GtkColorSelection*)dialog->colorsel; iupgdkColorSet(&color, r, g, b); gtk_color_selection_set_current_color(colorsel, &color); value = iupAttribGetStr(ih, "ALPHA"); if (value) { int alpha; if (iupStrToInt(value, &alpha)) { if (alpha<0) alpha=0; if (alpha>255) alpha=255; gtk_color_selection_set_has_opacity_control(colorsel, TRUE); gtk_color_selection_set_current_alpha(colorsel, iupCOLOR8TO16(alpha)); } } else if (iupAttribGetBoolean(ih, "SHOWALPHA") || ret == 4) { gtk_color_selection_set_has_opacity_control(colorsel, TRUE); gtk_color_selection_set_current_alpha(colorsel, iupCOLOR8TO16(a)); } else gtk_color_selection_set_has_opacity_control(colorsel, FALSE); value = iupAttribGetStr(ih, "COLORTABLE"); if (value) { gtk_color_selection_set_has_palette (colorsel, TRUE); gtkColorDlgSetPalette(colorsel, value); } else if (iupAttribGetBoolean(ih, "SHOWCOLORTABLE")) gtk_color_selection_set_has_palette (colorsel, TRUE); else gtk_color_selection_set_has_palette (colorsel, FALSE); if (IupGetCallback(ih, "HELP_CB")) gtk_widget_show(dialog->help_button); /* initialize the widget */ gtk_widget_realize(GTK_WIDGET(dialog)); ih->handle = GTK_WIDGET(dialog); iupDialogUpdatePosition(ih); ih->handle = NULL; do { response = gtk_dialog_run(GTK_DIALOG(dialog)); if (response == GTK_RESPONSE_HELP) { Icallback cb = IupGetCallback(ih, "HELP_CB"); if (cb && cb(ih) == IUP_CLOSE) response = GTK_RESPONSE_CANCEL; } } while (response == GTK_RESPONSE_HELP); if (response == GTK_RESPONSE_OK) { GdkColor color; gtk_color_selection_get_current_color(colorsel, &color); IupSetAttribute(ih, "STATUS", "1"); if (gtk_color_selection_get_has_opacity_control(colorsel)) { int alpha = gtk_color_selection_get_current_alpha(colorsel); iupAttribSetInt(ih, "ALPHA", (int)iupCOLOR16TO8(alpha)); iupAttribSetStrf(ih, "VALUE", "%d %d %d %d", (int)iupCOLOR16TO8(color.red), (int)iupCOLOR16TO8(color.green), (int)iupCOLOR16TO8(color.blue), (int)iupCOLOR16TO8(alpha)); } else iupAttribSetStrf(ih, "VALUE", "%d %d %d", (int)iupCOLOR16TO8(color.red), (int)iupCOLOR16TO8(color.green), (int)iupCOLOR16TO8(color.blue)); if (gtk_color_selection_get_has_palette(colorsel)) gtkColorDlgGetPalette(ih, colorsel); } else { iupAttribSetStr(ih, "ALPHA", NULL); iupAttribSetStr(ih, "VALUE", NULL); iupAttribSetStr(ih, "COLORTABLE", NULL); iupAttribSetStr(ih, "STATUS", NULL); } gtk_widget_destroy(GTK_WIDGET(dialog)); return IUP_NOERROR; }
static int motFileDlgPopup(Ihandle* ih, int x, int y) { InativeHandle* parent = iupDialogGetNativeParent(ih); Widget filebox, dialog; int dialogtype, style = XmDIALOG_FULL_APPLICATION_MODAL; IFnss file_cb = NULL; Widget preview_canvas = NULL; char* value; 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; iupAttribSetInt(ih, "_IUPDLG_DIALOGTYPE", dialogtype); if (parent) { filebox = XmCreateFileSelectionDialog(parent, "filedialog", NULL, 0); dialog = XtParent(filebox); } else { dialog = XtAppCreateShell(NULL, "filedialog", topLevelShellWidgetClass, iupmot_display, NULL, 0); filebox = XmCreateFileSelectionBox(dialog, "filebox", NULL, 0); style = XmDIALOG_MODELESS; XtVaSetValues(dialog, XmNmwmInputMode, MWM_INPUT_FULL_APPLICATION_MODAL, XmNmappedWhenManaged, False, XmNsaveUnder, True, NULL); } if (!filebox) return IUP_NOERROR; if (!iupAttribGetBoolean(ih, "SHOWHIDDEN")) XtVaSetValues(filebox, XmNfileFilterStyle, XmFILTER_HIDDEN_FILES, NULL); value = iupAttribGet(ih, "TITLE"); if (!value) { if (dialogtype == IUP_DIALOGSAVE) value = "IUP_SAVEAS"; else if (dialogtype == IUP_DIALOGOPEN) value = "IUP_OPEN"; else value = "IUP_SELECTDIR"; iupAttribSetStr(ih, "TITLE", iupStrMessageGet(value)); } iupmotSetString(filebox, XmNdialogTitle, value); XtVaSetValues(filebox, XmNdialogStyle, style, XmNautoUnmanage, False, XmNresizePolicy, XmRESIZE_GROW, NULL); if (dialogtype == IUP_DIALOGDIR) XtVaSetValues(filebox, XmNfileTypeMask, XmFILE_DIRECTORY, NULL); /* just check for the path inside FILE */ value = iupAttribGet(ih, "FILE"); if (value && value[0] == '/') { char* dir = iupStrFileGetPath(value); iupAttribStoreStr(ih, "DIRECTORY", dir); free(dir); } /* set XmNdirectory before XmNpattern and before XmNdirSpec */ value = iupAttribGet(ih, "DIRECTORY"); if (value) iupmotSetString(filebox, XmNdirectory, value); value = iupAttribGet(ih, "FILTER"); if (value) { char *filter = value; char *p = strchr(value, ';'); if (p) { /* Use only the first filter */ int size = p-value; filter = (char*)malloc(size+1); memcpy(filter, value, size); filter[size] = 0; } iupmotSetString(filebox, XmNpattern, filter); if (filter != value) free(filter); } value = iupAttribGet(ih, "FILE"); if (value) { char* file = value; if (value[0] != '/') /* if does not contains a full path, then add the directory */ { char* cur_dir = NULL; char* dir = iupAttribGet(ih, "DIRECTORY"); if (!dir) { cur_dir = iupdrvGetCurrentDirectory(); dir = cur_dir; } file = iupStrFileMakeFileName(dir, value); if (cur_dir) free(cur_dir); } /* clear value before setting. Do not know why we have to do this, but if not cleared it will fail to set the XmNdirSpec value. */ iupmotSetString(filebox, XmNdirSpec, ""); iupmotSetString(filebox, XmNdirSpec, file); if (file != value) free(file); } if (!IupGetCallback(ih, "HELP_CB")) XtUnmanageChild(XmFileSelectionBoxGetChild(filebox, XmDIALOG_HELP_BUTTON)); XtAddCallback(filebox, XmNokCallback, (XtCallbackProc)motFileDlgCallback, (XtPointer)ih); XtAddCallback(filebox, XmNcancelCallback, (XtCallbackProc)motFileDlgCallback, (XtPointer)ih); XtAddCallback(filebox, XmNhelpCallback, (XtCallbackProc)motFileDlgHelpCallback, (XtPointer)ih); if (dialogtype == IUP_DIALOGDIR) { Widget new_folder = XtVaCreateManagedWidget("new_folder", xmPushButtonWidgetClass, filebox, XmNlabelType, XmSTRING, NULL); iupmotSetString(new_folder, XmNlabelString, iupStrMessageGet("IUP_CREATEFOLDER")); XtAddCallback(new_folder, XmNactivateCallback, (XtCallbackProc)motFileDlgNewFolderCallback, (XtPointer)filebox); } else { file_cb = (IFnss)IupGetCallback(ih, "FILE_CB"); if (file_cb) { Widget list = XmFileSelectionBoxGetChild(filebox, XmDIALOG_LIST); XtAddCallback(list, XmNbrowseSelectionCallback, (XtCallbackProc)motFileDlgBrowseSelectionCallback, (XtPointer)ih); list = XmFileSelectionBoxGetChild(filebox, XmDIALOG_DIR_LIST); XtAddCallback(list, XmNbrowseSelectionCallback, (XtCallbackProc)motFileDlgBrowseSelectionCallback, (XtPointer)ih); if (iupAttribGetBoolean(ih, "SHOWPREVIEW")) { Widget frame = XtVaCreateManagedWidget("preview_canvas", xmFrameWidgetClass, filebox, XmNshadowType, XmSHADOW_ETCHED_IN, NULL); preview_canvas = XtVaCreateManagedWidget("preview_canvas", xmDrawingAreaWidgetClass, frame, XmNwidth, 180, XmNheight, 150, XmNresizePolicy, XmRESIZE_GROW, NULL); XtAddCallback(preview_canvas, XmNexposeCallback, (XtCallbackProc)motFileDlgPreviewCanvasExposeCallback, (XtPointer)ih); XtAddCallback(preview_canvas, XmNresizeCallback, (XtCallbackProc)motFileDlgPreviewCanvasResizeCallback, (XtPointer)ih); iupAttribSetStr(ih, "_IUPDLG_FILEBOX", (char*)filebox); } } if (iupAttribGetBoolean(ih, "MULTIPLEFILES")) { Widget wList = XmFileSelectionBoxGetChild(filebox, XmDIALOG_LIST); XtVaSetValues(wList, XmNselectionPolicy, XmEXTENDED_SELECT, NULL); if (file_cb) XtAddCallback(wList, XmNextendedSelectionCallback, (XtCallbackProc)motFileDlgBrowseSelectionCallback, (XtPointer)ih); } } XmAddWMProtocolCallback(dialog, iupmot_wm_deletewindow, motFileDlgCBclose, (XtPointer)ih); XtManageChild(filebox); XtRealizeWidget(dialog); ih->handle = dialog; iupDialogUpdatePosition(ih); ih->handle = NULL; /* reset handle */ if (file_cb) { if (preview_canvas) motFileDlgPreviewCanvasInit(ih, preview_canvas); file_cb(ih, NULL, "INIT"); } if (ih->userwidth && ih->userheight) { XtVaSetValues(dialog, XmNwidth, (XtArgVal)(ih->userwidth), XmNheight, (XtArgVal)(ih->userheight), NULL); } if (style == XmDIALOG_MODELESS) XtPopup(dialog, XtGrabExclusive); /* while the user hasn't provided an answer, simulate main loop. ** The answer changes as soon as the user selects one of the ** buttons and the callback routine changes its value. */ iupAttribSetStr(ih, "STATUS", NULL); while (iupAttribGet(ih, "STATUS") == NULL) XtAppProcessEvent(iupmot_appcontext, XtIMAll); if (file_cb) { if (preview_canvas) XFreeGC(iupmot_display, (GC)iupAttribGet(ih, "PREVIEWDC")); file_cb(ih, NULL, "FINISH"); } if (!iupAttribGet(ih, "_IUP_WM_DELETE")) { XtUnmanageChild(filebox); if (style == XmDIALOG_MODELESS) { XtPopdown(dialog); XtDestroyWidget(dialog); } } return IUP_NOERROR; }
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 int gtkFontDlgPopup(Ihandle* ih, int x, int y) { InativeHandle* parent = iupDialogGetNativeParent(ih); GtkWidget* dialog; int response; char* preview_text, *standardfont; iupAttribSetInt(ih, "_IUPDLG_X", x); /* used in iupDialogUpdatePosition */ iupAttribSetInt(ih, "_IUPDLG_Y", y); #if GTK_CHECK_VERSION(3, 2, 0) dialog = gtk_font_chooser_dialog_new(iupgtkStrConvertToSystem(iupAttribGet(ih, "TITLE")), GTK_WINDOW(parent)); #else dialog = gtk_font_selection_dialog_new(iupgtkStrConvertToSystem(iupAttribGet(ih, "TITLE"))); #endif if (!dialog) return IUP_ERROR; #if !GTK_CHECK_VERSION(3, 2, 0) if (parent) gtk_window_set_transient_for(GTK_WINDOW(dialog), GTK_WINDOW(parent)); #endif standardfont = iupAttribGet(ih, "VALUE"); if (!standardfont) standardfont = IupGetGlobal("DEFAULTFONT"); #if GTK_CHECK_VERSION(3, 2, 0) gtk_font_chooser_set_font(GTK_FONT_CHOOSER(dialog), standardfont); #else gtk_font_selection_dialog_set_font_name(GTK_FONT_SELECTION_DIALOG(dialog), standardfont); #endif preview_text = iupAttribGet(ih, "PREVIEWTEXT"); if (preview_text) { preview_text = iupgtkStrConvertToSystem(preview_text); #if GTK_CHECK_VERSION(3, 2, 0) if (iupStrEqualNoCase(preview_text, "NONE")) gtk_font_chooser_set_show_preview_entry(GTK_FONT_CHOOSER(dialog), FALSE); else gtk_font_chooser_set_preview_text(GTK_FONT_CHOOSER(dialog), preview_text); #else gtk_font_selection_dialog_set_preview_text(GTK_FONT_SELECTION_DIALOG(dialog), preview_text); #endif } if (IupGetCallback(ih, "HELP_CB")) { #if GTK_CHECK_VERSION(3, 10, 0) const char* help = "_Help"; #else const char* help = GTK_STOCK_HELP; #endif gtk_dialog_add_button(GTK_DIALOG(dialog), help, GTK_RESPONSE_HELP); } /* initialize the widget */ gtk_widget_realize(GTK_WIDGET(dialog)); ih->handle = GTK_WIDGET(dialog); iupDialogUpdatePosition(ih); ih->handle = NULL; do { response = gtk_dialog_run(GTK_DIALOG(dialog)); if (response == GTK_RESPONSE_HELP) { Icallback cb = IupGetCallback(ih, "HELP_CB"); if (cb && cb(ih) == IUP_CLOSE) response = GTK_RESPONSE_CANCEL; } } while (response == GTK_RESPONSE_HELP); if (response == GTK_RESPONSE_OK) { #if GTK_CHECK_VERSION(3, 2, 0) char* fontname = gtk_font_chooser_get_font(GTK_FONT_CHOOSER(dialog)); #else char* fontname = gtk_font_selection_dialog_get_font_name(GTK_FONT_SELECTION_DIALOG(dialog)); #endif iupAttribSetStr(ih, "VALUE", fontname); g_free(fontname); iupAttribSet(ih, "STATUS", "1"); } else { iupAttribSet(ih, "VALUE", NULL); iupAttribSet(ih, "STATUS", NULL); } gtk_widget_destroy(GTK_WIDGET(dialog)); return IUP_NOERROR; }
static int gtkFileDlgPopup(Ihandle* ih, int x, int y) { InativeHandle* parent = iupDialogGetNativeParent(ih); GtkWidget* dialog; GtkWidget* preview_canvas = NULL; GtkFileChooserAction action; IFnss file_cb; char* value; int response, filter_count = 0; iupAttribSetInt(ih, "_IUPDLG_X", x); /* used in iupDialogUpdatePosition */ iupAttribSetInt(ih, "_IUPDLG_Y", y); value = iupAttribGetStr(ih, "DIALOGTYPE"); if (iupStrEqualNoCase(value, "SAVE")) action = GTK_FILE_CHOOSER_ACTION_SAVE; else if (iupStrEqualNoCase(value, "DIR")) action = GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER; else action = GTK_FILE_CHOOSER_ACTION_OPEN; value = iupAttribGet(ih, "TITLE"); if (!value) { GtkStockItem item; if (action == GTK_FILE_CHOOSER_ACTION_SAVE) value = GTK_STOCK_SAVE_AS; else value = GTK_STOCK_OPEN; gtk_stock_lookup(value, &item); value = item.label; iupAttribStoreStr(ih, "TITLE", iupgtkStrConvertFromUTF8(value)); value = iupAttribGet(ih, "TITLE"); iupStrRemoveChar(value, '_'); } dialog = gtk_file_chooser_dialog_new(iupgtkStrConvertToUTF8(value), (GtkWindow*)parent, action, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, NULL); if (!dialog) return IUP_ERROR; if (action == GTK_FILE_CHOOSER_ACTION_SAVE) gtk_dialog_add_button(GTK_DIALOG(dialog), GTK_STOCK_SAVE, GTK_RESPONSE_OK); else if (action == GTK_FILE_CHOOSER_ACTION_OPEN) gtk_dialog_add_button(GTK_DIALOG(dialog), GTK_STOCK_OPEN, GTK_RESPONSE_OK); else gtk_dialog_add_button(GTK_DIALOG(dialog), GTK_STOCK_OK, GTK_RESPONSE_OK); if (IupGetCallback(ih, "HELP_CB")) gtk_dialog_add_button(GTK_DIALOG(dialog), GTK_STOCK_HELP, GTK_RESPONSE_HELP); #if GTK_CHECK_VERSION(2, 6, 0) if (iupAttribGetBoolean(ih, "SHOWHIDDEN")) gtk_file_chooser_set_show_hidden(GTK_FILE_CHOOSER(dialog), TRUE); #endif if (iupAttribGetBoolean(ih, "MULTIPLEFILES") && action == GTK_FILE_CHOOSER_ACTION_OPEN) gtk_file_chooser_set_select_multiple(GTK_FILE_CHOOSER(dialog), TRUE); #if GTK_CHECK_VERSION(2, 8, 0) if (!iupAttribGetBoolean(ih, "NOOVERWRITEPROMPT") && action == GTK_FILE_CHOOSER_ACTION_SAVE) gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER(dialog), TRUE); #endif /* just check for the path inside FILE */ value = iupAttribGet(ih, "FILE"); if (value && (value[0] == '/' || value[1] == ':')) { char* dir = iupStrFileGetPath(value); int len = strlen(dir); iupAttribStoreStr(ih, "DIRECTORY", dir); free(dir); iupAttribStoreStr(ih, "FILE", value+len); } value = iupAttribGet(ih, "DIRECTORY"); if (value) gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), iupgtkStrConvertToFilename(value)); value = iupAttribGet(ih, "FILE"); if (value) { if (action == GTK_FILE_CHOOSER_ACTION_SAVE) gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(dialog), iupgtkStrConvertToFilename(value)); else { if (iupdrvIsFile(value)) /* check if file exists */ gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(dialog), iupgtkStrConvertToFilename(value)); } } value = iupAttribGet(ih, "EXTFILTER"); if (value) { char *name, *pattern, *filters = iupStrDup(value), *p; char atrib[30]; int i; int filter_index = iupAttribGetInt(ih, "FILTERUSED"); if (!filter_index) filter_index = 1; filter_count = iupStrReplace(filters, '|', 0) / 2; p = filters; for (i=0; i<filter_count; i++) { GtkFileFilter *filter = gtk_file_filter_new(); gtkFileDlgGetNextFilter(&p, &name, &pattern); gtk_file_filter_set_name(filter, iupgtkStrConvertToUTF8(name)); gtk_file_filter_add_pattern(filter, pattern); gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog), filter); sprintf(atrib, "_IUPDLG_FILTER%d", i+1); iupAttribSetStr(ih, atrib, (char*)filter); if (i+1 == filter_index) gtk_file_chooser_set_filter(GTK_FILE_CHOOSER(dialog), filter); } free(filters); } else { value = iupAttribGet(ih, "FILTER"); if (value) { GtkFileFilter *filter = gtk_file_filter_new(); char* info = iupAttribGet(ih, "FILTERINFO"); if (!info) info = value; gtk_file_filter_set_name(filter, iupgtkStrConvertToUTF8(info)); gtk_file_filter_add_pattern(filter, value); gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog), filter); } } file_cb = (IFnss)IupGetCallback(ih, "FILE_CB"); if (file_cb && action != GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER) { g_signal_connect(GTK_FILE_CHOOSER(dialog), "update-preview", G_CALLBACK(gtkFileDlgUpdatePreview), ih); g_signal_connect(dialog, "realize", G_CALLBACK(gtkFileDlgRealize), ih); if (iupAttribGetBoolean(ih, "SHOWPREVIEW")) { GtkWidget* frame = gtk_frame_new(NULL); gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_ETCHED_IN); gtk_widget_set_size_request(frame, 180, 150); preview_canvas = gtk_drawing_area_new(); gtk_widget_set_double_buffered(preview_canvas, FALSE); gtk_container_add(GTK_CONTAINER(frame), preview_canvas); gtk_widget_show(preview_canvas); g_signal_connect(preview_canvas, "configure-event", G_CALLBACK(gtkFileDlgPreviewConfigureEvent), ih); g_signal_connect(preview_canvas, "expose-event", G_CALLBACK(gtkFileDlgPreviewExposeEvent), ih); g_signal_connect(preview_canvas, "realize", G_CALLBACK(gtkFileDlgPreviewRealize), ih); iupAttribSetStr(ih, "_IUPDLG_FILE_CHOOSER", (char*)dialog); gtk_file_chooser_set_preview_widget(GTK_FILE_CHOOSER(dialog), frame); } } /* initialize the widget */ gtk_widget_realize(GTK_WIDGET(dialog)); ih->handle = GTK_WIDGET(dialog); iupDialogUpdatePosition(ih); ih->handle = NULL; /* reset handle */ do { response = gtk_dialog_run(GTK_DIALOG(dialog)); if (response == GTK_RESPONSE_HELP) { Icallback cb = IupGetCallback(ih, "HELP_CB"); if (cb && cb(ih) == IUP_CLOSE) response = GTK_RESPONSE_CANCEL; } else if (response == GTK_RESPONSE_OK) { char *filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog)); int file_exist = iupdrvIsFile(filename); int dir_exist = iupdrvIsDirectory(filename); g_free(filename); if (action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER) { if (!dir_exist) { iupStrMessageShowError(ih, "IUP_INVALIDDIR"); response = GTK_RESPONSE_HELP; /* to leave the dialog open */ continue; } } else if (!iupAttribGetBoolean(ih, "MULTIPLEFILES")) { if (dir_exist) { iupStrMessageShowError(ih, "IUP_FILEISDIR"); response = GTK_RESPONSE_HELP; /* to leave the dialog open */ continue; } if (!file_exist) /* if do not exist check ALLOWNEW */ { value = iupAttribGet(ih, "ALLOWNEW"); if (!value) { if (action == GTK_FILE_CHOOSER_ACTION_SAVE) value = "YES"; else value = "NO"; } if (!iupStrBoolean(value)) { iupStrMessageShowError(ih, "IUP_FILENOTEXIST"); response = GTK_RESPONSE_HELP; /* to leave the dialog open */ continue; } } if (file_cb) { char *filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog)); int ret = file_cb(ih, iupgtkStrConvertFromFilename(filename), "OK"); g_free(filename); if (ret == IUP_IGNORE) { response = GTK_RESPONSE_HELP; /* to leave the dialog open */ continue; } } } } } while (response == GTK_RESPONSE_HELP); if (file_cb) { if (iupAttribGetBoolean(ih, "SHOWPREVIEW")) iupgtkReleaseNativeGraphicsContext(preview_canvas, (void*)iupAttribGet(ih, "PREVIEWDC")); file_cb(ih, NULL, "FINISH"); } if (response == GTK_RESPONSE_OK) { int file_exist, dir_exist; if (filter_count) { int i; char atrib[30]; GtkFileFilter* filter = gtk_file_chooser_get_filter(GTK_FILE_CHOOSER(dialog)); for (i=0; i<filter_count; i++) { sprintf(atrib, "_IUPDLG_FILTER%d", i+1); if (filter == (GtkFileFilter*)iupAttribGet(ih, atrib)) iupAttribSetInt(ih, "FILTERUSED", i+1); } } if (iupAttribGetBoolean(ih, "MULTIPLEFILES")) { GSList* file_list = gtk_file_chooser_get_filenames(GTK_FILE_CHOOSER(dialog)); if (file_list->next) /* if more than one file */ gtkFileDlgGetMultipleFiles(ih, file_list); else { char* filename = (char*)file_list->data; iupAttribStoreStr(ih, "VALUE", iupgtkStrConvertFromFilename(filename)); g_free(filename); } g_slist_free(file_list); file_exist = 1; dir_exist = 0; } else { char *filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog)); iupAttribStoreStr(ih, "VALUE", iupgtkStrConvertFromFilename(filename)); file_exist = iupdrvIsFile(filename); dir_exist = iupdrvIsDirectory(filename); g_free(filename); } if (dir_exist) { iupAttribSetStr(ih, "FILEEXIST", NULL); iupAttribSetStr(ih, "STATUS", "0"); } else { if (file_exist) /* check if file exists */ { iupAttribSetStr(ih, "FILEEXIST", "YES"); iupAttribSetStr(ih, "STATUS", "0"); } else { iupAttribSetStr(ih, "FILEEXIST", "NO"); iupAttribSetStr(ih, "STATUS", "1"); } } if (action != GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER && !iupAttribGetBoolean(ih, "NOCHANGEDIR")) /* do change the current directory */ { /* GtkFileChooser does not change the current directory */ char* dir = gtk_file_chooser_get_current_folder(GTK_FILE_CHOOSER(dialog)); if (dir) iupdrvSetCurrentDirectory(dir); g_free(dir); } } else { iupAttribSetStr(ih, "FILTERUSED", NULL); iupAttribSetStr(ih, "VALUE", NULL); iupAttribSetStr(ih, "FILEEXIST", NULL); iupAttribSetStr(ih, "STATUS", "-1"); } gtk_widget_destroy(GTK_WIDGET(dialog)); return IUP_NOERROR; }
static void iDialogAdjustPos(Ihandle *ih, int *x, int *y) { int cursor_x = 0, cursor_y = 0; int screen_width = 0, screen_height = 0; int current_x = 0, current_y = 0; int parent_x = 0, parent_y = 0; /* the dialog is already mapped here */ if (*x == IUP_CURRENT || *y == IUP_CURRENT) { /* if first time, there is no current position */ if (!ih->data->first_show) { int center = IUP_CENTER; InativeHandle* parent = iupDialogGetNativeParent(ih); if (parent) center = IUP_CENTERPARENT; if (*x == IUP_CURRENT) *x = center; if (*y == IUP_CURRENT) *y = center; } else iupdrvDialogGetPosition(ih, NULL, ¤t_x, ¤t_y); } if (*x == IUP_CENTER || *y == IUP_CENTER || *x == IUP_RIGHT || *y == IUP_RIGHT || *x == IUP_CENTERPARENT || *y == IUP_CENTERPARENT) iupdrvGetScreenSize(&screen_width, &screen_height); if (*x == IUP_CENTERPARENT || *y == IUP_CENTERPARENT) { InativeHandle* parent = iupDialogGetNativeParent(ih); if (parent) { Ihandle* ih_parent = IupGetAttributeHandle(ih, "PARENTDIALOG"); iupdrvDialogGetPosition(ih_parent, parent, &parent_x, &parent_y); if (*x == IUP_CENTERPARENT && *y == IUP_CENTERPARENT) iupdrvDialogGetSize(ih_parent, parent, &screen_width, &screen_height); else if (*x == IUP_CENTERPARENT) iupdrvDialogGetSize(ih_parent, parent, &screen_width, NULL); else if (*y == IUP_CENTERPARENT) iupdrvDialogGetSize(ih_parent, parent, NULL, &screen_height); } } if (*x == IUP_MOUSEPOS || *y == IUP_MOUSEPOS) iupdrvGetCursorPos(&cursor_x, &cursor_y); if (iupAttribGetBoolean(ih, "MDICHILD")) { Ihandle* client = (Ihandle*)iupAttribGet(ih, "MDICLIENT_HANDLE"); if (client) { /* position is relative to mdi client */ parent_x = 0; parent_y = 0; /* screen size is now the size of the mdi client */ screen_width = client->currentwidth; screen_height = client->currentheight; iupdrvScreenToClient(client, ¤t_x, ¤t_y); iupdrvScreenToClient(client, &cursor_x, &cursor_y); } } switch (*x) { case IUP_CENTERPARENT: *x = (screen_width - ih->currentwidth)/2 + parent_x; break; case IUP_CENTER: *x = (screen_width - ih->currentwidth)/2; break; case IUP_LEFT: *x = 0; break; case IUP_RIGHT: *x = screen_width - ih->currentwidth; break; case IUP_MOUSEPOS: *x = cursor_x; break; case IUP_CURRENT: *x = current_x; break; } switch (*y) { case IUP_CENTERPARENT: *y = (screen_height - ih->currentheight)/2 + parent_y; break; case IUP_CENTER: *y = (screen_height - ih->currentheight)/2; break; case IUP_LEFT: *y = 0; break; case IUP_RIGHT: *y = screen_height - ih->currentheight; break; case IUP_MOUSEPOS: *y = cursor_y; break; case IUP_CURRENT: *y = current_y; break; } iupdrvAddScreenOffset(x, y, 1); }
static int winFileDlgPopup(Ihandle *ih, int x, int y) { InativeHandle* parent = iupDialogGetNativeParent(ih); OPENFILENAME openfilename; int result, dialogtype; char *value; 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 (!parent) parent = GetActiveWindow(); /* if NOT set will NOT be Modal */ /* anyway it will be modal only relative to its parent */ ZeroMemory(&openfilename, sizeof(OPENFILENAME)); openfilename.lStructSize = sizeof(OPENFILENAME); openfilename.hwndOwner = parent; value = iupAttribGet(ih, "EXTFILTER"); if (value) { int index; openfilename.lpstrFilter = winFileDlgStrReplaceSeparator(value); value = iupAttribGet(ih, "FILTERUSED"); if (iupStrToInt(value, &index)) openfilename.nFilterIndex = index; else openfilename.nFilterIndex = 1; } else { value = iupAttribGet(ih, "FILTER"); if (value) { int sz1, sz2; char* info = iupAttribGet(ih, "FILTERINFO"); if (!info) info = value; /* concat FILTERINFO+FILTER */ sz1 = strlen(info)+1; sz2 = strlen(value)+1; openfilename.lpstrFilter = (char*)malloc(sz1+sz2+1); memcpy((char*)openfilename.lpstrFilter, info, sz1); memcpy((char*)openfilename.lpstrFilter+sz1, value, sz2); ((char*)openfilename.lpstrFilter)[sz1+sz2] = 0; /* additional 0 at the end */ openfilename.nFilterIndex = 1; } } openfilename.lpstrFile = (char*)malloc(IUP_MAX_FILENAME_SIZE+1); value = iupAttribGet(ih, "FILE"); if (value) { strncpy(openfilename.lpstrFile, value, IUP_MAX_FILENAME_SIZE); winFileDlgStrReplacePathSlash(openfilename.lpstrFile); } else openfilename.lpstrFile[0] = 0; openfilename.nMaxFile = IUP_MAX_FILENAME_SIZE; openfilename.lpstrInitialDir = iupStrDup(iupAttribGet(ih, "DIRECTORY")); if (openfilename.lpstrInitialDir) winFileDlgStrReplacePathSlash((char*)openfilename.lpstrInitialDir); openfilename.lpstrTitle = 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 = "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")) { int i = 0; char* dir = iupStrFileGetPath(openfilename.lpstrFile); /* the first part is the directory already */ iupAttribStoreStr(ih, "DIRECTORY", dir); free(dir); /* If there is more than one file, replace terminator by the separator */ if (openfilename.lpstrFile[openfilename.nFileOffset-1] == 0 && openfilename.nFileOffset>0) { while (openfilename.lpstrFile[i] != 0 || openfilename.lpstrFile[i+1] != 0) { if (openfilename.lpstrFile[i]==0) openfilename.lpstrFile[i] = '|'; i++; } openfilename.lpstrFile[i] = '|'; } iupAttribSetStr(ih, "STATUS", "0"); iupAttribSetStr(ih, "FILEEXIST", "YES"); } else { if (iupdrvIsFile(openfilename.lpstrFile)) /* check if file exists */ { char* dir = iupStrFileGetPath(openfilename.lpstrFile); iupAttribStoreStr(ih, "DIRECTORY", dir); free(dir); iupAttribSetStr(ih, "FILEEXIST", "YES"); iupAttribSetStr(ih, "STATUS", "0"); } else { iupAttribSetStr(ih, "FILEEXIST", "NO"); iupAttribSetStr(ih, "STATUS", "1"); } } iupAttribStoreStr(ih, "VALUE", openfilename.lpstrFile); iupAttribSetInt(ih, "FILTERUSED", (int)openfilename.nFilterIndex); } else { iupAttribSetStr(ih, "FILTERUSED", NULL); iupAttribSetStr(ih, "VALUE", NULL); iupAttribSetStr(ih, "FILEEXIST", NULL); iupAttribSetStr(ih, "STATUS", "-1"); } if (openfilename.lpstrFilter) free((char*)openfilename.lpstrFilter); if (openfilename.lpstrInitialDir) free((char*)openfilename.lpstrInitialDir); if (openfilename.lpstrFile) free(openfilename.lpstrFile); return IUP_NOERROR; }
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; }
static int winMessageDlgPopup(Ihandle* ih, int x, int y) { InativeHandle* parent = iupDialogGetNativeParent(ih); MSGBOXPARAMS MsgBoxParams; int result, button_def; DWORD dwStyle = MB_TASKMODAL; char *icon, *buttons; (void)x; (void)y; /* MessageBox is the only Windows pre-defined dialog that has a modal control, no need to force a parent dialog here. */ icon = iupAttribGetStr(ih, "DIALOGTYPE"); if (iupStrEqualNoCase(icon, "ERROR")) dwStyle |= MB_ICONERROR; else if (iupStrEqualNoCase(icon, "WARNING")) dwStyle |= MB_ICONWARNING; else if (iupStrEqualNoCase(icon, "INFORMATION")) dwStyle |= MB_ICONINFORMATION; else if (iupStrEqualNoCase(icon, "QUESTION")) dwStyle |= MB_ICONQUESTION; buttons = iupAttribGetStr(ih, "BUTTONS"); if (iupStrEqualNoCase(buttons, "OKCANCEL")) dwStyle |= MB_OKCANCEL; else if (iupStrEqualNoCase(buttons, "RETRYCANCEL")) dwStyle |= MB_RETRYCANCEL; else if (iupStrEqualNoCase(buttons, "YESNO")) dwStyle |= MB_YESNO; else if (iupStrEqualNoCase(buttons, "YESNOCANCEL")) dwStyle |= MB_YESNOCANCEL; else dwStyle |= MB_OK; if (IupGetCallback(ih, "HELP_CB")) dwStyle |= MB_HELP; button_def = iupAttribGetInt(ih, "BUTTONDEFAULT"); if (button_def == 3) dwStyle |= MB_DEFBUTTON3; else if (button_def == 2) dwStyle |= MB_DEFBUTTON2; else dwStyle |= MB_DEFBUTTON1; MsgBoxParams.cbSize = sizeof(MSGBOXPARAMS); MsgBoxParams.hwndOwner = parent; MsgBoxParams.hInstance = NULL; MsgBoxParams.lpszText = iupwinStrToSystem(iupAttribGet(ih, "VALUE")); MsgBoxParams.lpszCaption = iupwinStrToSystem(iupAttribGet(ih, "TITLE")); MsgBoxParams.dwStyle = dwStyle; MsgBoxParams.lpszIcon = NULL; MsgBoxParams.dwContextHelpId = (DWORD_PTR)ih; MsgBoxParams.lpfnMsgBoxCallback = (MSGBOXCALLBACK)winMessageDlgHelpCallback; MsgBoxParams.dwLanguageId = MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT); result = MessageBoxIndirect(&MsgBoxParams); if (result == 0) /* memory error */ { iupAttribSet(ih, "BUTTONRESPONSE", NULL); return IUP_ERROR; } if (result == IDOK || result == IDYES || result == IDRETRY) iupAttribSet(ih, "BUTTONRESPONSE", "1"); else if (result == IDCANCEL && iupStrEqualNoCase(buttons, "YESNOCANCEL")) iupAttribSet(ih, "BUTTONRESPONSE", "3"); else iupAttribSet(ih, "BUTTONRESPONSE", "2"); return IUP_NOERROR; }
static int winFontDlgPopup(Ihandle* ih, int x, int y) { InativeHandle* parent = iupDialogGetNativeParent(ih); unsigned char r, g, b; CHOOSEFONT choosefont; LOGFONT logfont; char* standardfont; int height_pixels; char typeface[50] = ""; int height = 8; int is_bold = 0, is_italic = 0, is_underline = 0, is_strikeout = 0; int res = iupwinGetScreenRes(); iupAttribSetInt(ih, "_IUPDLG_X", x); iupAttribSetInt(ih, "_IUPDLG_Y", y); if (!parent) parent = GetActiveWindow(); standardfont = iupAttribGet(ih, "VALUE"); if (!standardfont) return IUP_ERROR; /* parse the old format first */ if (!iupFontParseWin(standardfont, typeface, &height, &is_bold, &is_italic, &is_underline, &is_strikeout)) { if (!iupFontParsePango(standardfont, typeface, &height, &is_bold, &is_italic, &is_underline, &is_strikeout)) return IUP_ERROR; } /* get size in pixels */ if (height < 0) height_pixels = height; /* already in pixels */ else height_pixels = -IUPWIN_PT2PIXEL(height, res); if (height_pixels == 0) return IUP_ERROR; ZeroMemory(&choosefont, sizeof(CHOOSEFONT)); choosefont.lStructSize = sizeof(CHOOSEFONT); if (iupStrToRGB(iupAttribGet(ih, "COLOR"), &r, &g, &b)) choosefont.rgbColors = RGB(r, g, b); choosefont.hwndOwner = parent; choosefont.lpLogFont = &logfont; choosefont.Flags = CF_SCREENFONTS | CF_EFFECTS | CF_INITTOLOGFONTSTRUCT | CF_ENABLEHOOK; choosefont.lCustData = (LPARAM)ih; choosefont.lpfnHook = (LPCFHOOKPROC)winFontDlgHookProc; if (IupGetCallback(ih, "HELP_CB")) choosefont.Flags |= CF_SHOWHELP; strcpy(logfont.lfFaceName, typeface); logfont.lfHeight = height_pixels; logfont.lfWeight = (is_bold)? FW_BOLD: FW_NORMAL; logfont.lfItalic = (BYTE)is_italic; logfont.lfUnderline = (BYTE)is_underline; logfont.lfStrikeOut = (BYTE)is_strikeout; logfont.lfCharSet = DEFAULT_CHARSET; logfont.lfEscapement = 0; logfont.lfOrientation = 0; logfont.lfWidth = 0; logfont.lfOutPrecision = OUT_TT_PRECIS; logfont.lfClipPrecision = CLIP_DEFAULT_PRECIS; logfont.lfQuality = DEFAULT_QUALITY; logfont.lfPitchAndFamily = FF_DONTCARE|DEFAULT_PITCH; if (!ChooseFont(&choosefont)) { iupAttribSetStr(ih, "VALUE", NULL); iupAttribSetStr(ih, "COLOR", NULL); iupAttribSetStr(ih, "STATUS", NULL); return IUP_NOERROR; } is_bold = (logfont.lfWeight == FW_NORMAL)? 0: 1; is_italic = logfont.lfItalic; is_underline = logfont.lfUnderline; is_strikeout = logfont.lfStrikeOut; height_pixels = logfont.lfHeight; if (height < 0) /* not an error, use old value as reference of units */ height = height_pixels; /* return in pixels */ else height = IUPWIN_PIXEL2PT(-height_pixels, res); /* return in points */ iupAttribSetStrf(ih, "VALUE", "%s, %s%s%s%s %d", logfont.lfFaceName, is_bold?"Bold ":"", is_italic?"Italic ":"", is_underline?"Underline ":"", is_strikeout?"Strikeout ":"", height); iupAttribSetStrf(ih, "COLOR", "%d %d %d", GetRValue(choosefont.rgbColors), GetGValue(choosefont.rgbColors), GetBValue(choosefont.rgbColors)); iupAttribSetStr(ih, "STATUS", "1"); return IUP_NOERROR; }