static void motTabsUpdatePageNumber(Ihandle* ih) { int pos, old_pos; Ihandle* child; for (pos = 0, child = ih->firstchild; child; child = child->brother, pos++) { Widget child_manager = (Widget)iupAttribGet(child, "_IUPTAB_CONTAINER"); if (child_manager) { old_pos = iupAttribGetInt(child, "_IUPMOT_TABNUMBER"); /* did not work when using XtVaGetValues(child_manager, XmNpageNumber) */ if (pos != old_pos) { Widget tab_button = (Widget)iupAttribGet(child, "_IUPMOT_TABBUTTON"); XtVaSetValues(child_manager, XmNpageNumber, pos, NULL); XtVaSetValues(tab_button, XmNpageNumber, pos, NULL); iupAttribSetInt(child, "_IUPMOT_TABNUMBER", pos); } } } }
static int winTabsWmNotify(Ihandle* ih, NMHDR* msg_info, int *result) { (void)result; if (msg_info->code == TCN_SELCHANGING) { IFnnn cb = (IFnnn)IupGetCallback(ih, "TABCHANGE_CB"); int prev_pos = SendMessage(ih->handle, TCM_GETCURSEL, 0, 0); iupAttribSetInt(ih, "_IUPTABS_PREV_CHILD_POS", prev_pos); if (cb) { Ihandle* prev_child = IupGetChild(ih, prev_pos); iupAttribSetStr(ih, "_IUPTABS_PREV_CHILD", (char*)prev_child); } } if (msg_info->code == TCN_SELCHANGE) { IFnnn cb = (IFnnn)IupGetCallback(ih, "TABCHANGE_CB"); int pos = SendMessage(ih->handle, TCM_GETCURSEL, 0, 0); int prev_pos = iupAttribGetInt(ih, "_IUPTABS_PREV_CHILD_POS"); HWND tab_page = winTabsGetPageWindow(ih, pos); ShowWindow(tab_page, SW_SHOW); tab_page = winTabsGetPageWindow(ih, prev_pos); ShowWindow(tab_page, SW_HIDE); if (cb) { Ihandle* child = IupGetChild(ih, pos); Ihandle* prev_child = (Ihandle*)iupAttribGet(ih, "_IUPTABS_PREV_CHILD"); iupAttribSetStr(ih, "_IUPTABS_PREV_CHILD", NULL); cb(ih, child, prev_child); } } return 0; /* result not used */ }
static int motSetDragTypesAttrib(Ihandle* ih, const char* value) { int count = 0; Atom *targetlist = (Atom*)iupAttribGet(ih, "_IUPMOT_DRAG_TARGETLIST"); if (targetlist) { XtFree((char*)targetlist); iupAttribSet(ih, "_IUPMOT_DRAG_TARGETLIST", NULL); iupAttribSet(ih, "_IUPMOT_DRAG_TARGETLIST_COUNT", NULL); } if(!value) return 0; targetlist = motCreateTargetList(value, &count); if (targetlist) { iupAttribSet(ih, "_IUPMOT_DRAG_TARGETLIST", (char*)targetlist); iupAttribSetInt(ih, "_IUPMOT_DRAG_TARGETLIST_COUNT", count); } return 1; }
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 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 UINT_PTR CALLBACK winFileDlgPreviewHook(HWND hWnd, UINT uiMsg, WPARAM wParam, LPARAM lParam) { /* hWnd here is a handle to the child window that contains the template, NOT the file dialog. Only the preview canvas is a child of this window. */ switch(uiMsg) { case WM_INITDIALOG: { OPENFILENAME* openfilename = (OPENFILENAME*)lParam; Ihandle* ih = (Ihandle*)openfilename->lCustData; HWND hWndPreview = GetDlgItem(hWnd, IUP_PREVIEWCANVAS); ih->handle = GetParent(hWnd); iupDialogUpdatePosition(ih); ih->handle = NULL; /* reset handle */ if (hWndPreview) { RECT rect; winFileDlgSetPreviewCanvasPos(hWnd, hWndPreview); GetClientRect(hWndPreview, &rect); iupAttribSetInt(ih, "PREVIEWWIDTH", rect.right - rect.left); iupAttribSetInt(ih, "PREVIEWHEIGHT", rect.bottom - rect.top); } SetWindowLongPtr(hWnd, DWLP_USER, (LONG_PTR)ih); iupAttribSetStr(ih, "WID", (char*)hWndPreview); iupAttribSetStr(ih, "HWND", (char*)hWndPreview); winFileDlgUpdatePreviewGLCanvas(ih); break; } case WM_DRAWITEM: { if (wParam == IUP_PREVIEWCANVAS) { LPDRAWITEMSTRUCT lpDrawItem = (LPDRAWITEMSTRUCT)lParam; Ihandle* ih = (Ihandle*)GetWindowLongPtr(hWnd, DWLP_USER); /* callback here always exists */ IFnss cb = (IFnss)IupGetCallback(ih, "FILE_CB"); char filename[IUP_MAX_FILENAME_SIZE]; iupAttribSetStr(ih, "PREVIEWDC", (char*)lpDrawItem->hDC); if (winFileDlgGetSelectedFile(ih, hWnd, filename)) { if (iupdrvIsFile(filename)) cb(ih, filename, "PAINT"); else cb(ih, NULL, "PAINT"); } else cb(ih, NULL, "PAINT"); iupAttribSetStr(ih, "PREVIEWDC", NULL); } break; } case WM_SIZE: { HWND hWndPreview = GetDlgItem(hWnd, IUP_PREVIEWCANVAS); if (hWndPreview) { Ihandle* ih = (Ihandle*)GetWindowLongPtr(hWnd, DWLP_USER); RECT rect; winFileDlgSetPreviewCanvasPos(hWnd, hWndPreview); GetClientRect(hWndPreview, &rect); iupAttribSetInt(ih, "PREVIEWWIDTH", rect.right-rect.left); RedrawWindow(hWndPreview, NULL, NULL, RDW_INVALIDATE|RDW_UPDATENOW); } break; } case WM_DESTROY: { Ihandle* ih = (Ihandle*)GetWindowLongPtr(hWnd, DWLP_USER); /* callback here always exists */ IFnss cb = (IFnss)IupGetCallback(ih, "FILE_CB"); cb(ih, NULL, "FINISH"); break; } case WM_NOTIFY: return winFileDlgWmNotify(hWnd, (LPOFNOTIFY)lParam); } return 0; }
static int gtkCanvasMapMethod(Ihandle* ih) { GtkWidget* sb_win; #if !GTK_CHECK_VERSION(3, 0, 0) void* visual; #endif if (!ih->parent) return IUP_ERROR; ih->data->sb = iupBaseGetScrollbar(ih); #if !GTK_CHECK_VERSION(3, 0, 0) visual = (void*)IupGetAttribute(ih, "VISUAL"); /* defined by the OpenGL Canvas in X11 or NULL */ if (visual) iupgtkPushVisualAndColormap(visual, (void*)iupAttribGet(ih, "COLORMAP")); #endif ih->handle = iupgtkNativeContainerNew(); /* canvas is also a container */ #if !GTK_CHECK_VERSION(3, 0, 0) if (visual) gtk_widget_pop_colormap(); #endif if (!ih->handle) return IUP_ERROR; /* CD will NOT work properly without this, must use always the CD-GDK driver */ iupgtkNativeContainerSetHasWindow(ih->handle, TRUE); sb_win = iupgtkNativeContainerNew(); if (!sb_win) return IUP_ERROR; iupgtkNativeContainerAdd(sb_win, ih->handle); gtk_widget_show(sb_win); iupAttribSetStr(ih, "_IUP_EXTRAPARENT", (char*)sb_win); /* add to the parent, all GTK controls must call this. */ iupgtkAddToParent(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), "key-press-event", G_CALLBACK(iupgtkKeyPressEvent), ih); g_signal_connect(G_OBJECT(ih->handle), "key-release-event", G_CALLBACK(iupgtkKeyReleaseEvent), 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); #if GTK_CHECK_VERSION(3, 0, 0) g_signal_connect(G_OBJECT(ih->handle), "draw", G_CALLBACK(gtkCanvasDraw), ih); #else g_signal_connect(G_OBJECT(ih->handle), "expose-event", G_CALLBACK(gtkCanvasExposeEvent), ih); #endif g_signal_connect(G_OBJECT(ih->handle), "button-press-event", G_CALLBACK(gtkCanvasButtonEvent), ih); g_signal_connect(G_OBJECT(ih->handle), "button-release-event",G_CALLBACK(gtkCanvasButtonEvent), ih); g_signal_connect(G_OBJECT(ih->handle), "motion-notify-event",G_CALLBACK(iupgtkMotionNotifyEvent), ih); g_signal_connect(G_OBJECT(ih->handle), "scroll-event",G_CALLBACK(gtkCanvasScrollEvent), ih); g_signal_connect(G_OBJECT(ih->handle), "size-allocate", G_CALLBACK(gtkCanvasSizeAllocate), ih); /* To receive mouse events on a drawing area, you will need to enable them. */ gtk_widget_add_events(ih->handle, GDK_EXPOSURE_MASK| GDK_POINTER_MOTION_MASK|GDK_POINTER_MOTION_HINT_MASK| GDK_BUTTON_PRESS_MASK|GDK_BUTTON_RELEASE_MASK|GDK_BUTTON_MOTION_MASK| GDK_KEY_PRESS_MASK|GDK_KEY_RELEASE_MASK| GDK_ENTER_NOTIFY_MASK|GDK_LEAVE_NOTIFY_MASK| GDK_FOCUS_CHANGE_MASK|GDK_STRUCTURE_MASK); /* To receive keyboard events, you will need to set the GTK_CAN_FOCUS flag on the drawing area. */ if (ih->iclass->is_interactive) { if (iupAttribGetBoolean(ih, "CANFOCUS")) iupgtkSetCanFocus(ih->handle, 1); } if (iupAttribGetBoolean(ih, "BORDER")) { iupAttribSetInt(ih, "BORDERWIDTH", 1); #if GTK_CHECK_VERSION(3, 0, 0) g_signal_connect(G_OBJECT(sb_win), "draw", G_CALLBACK(gtkCanvasBorderDraw), NULL); #else g_signal_connect(G_OBJECT(sb_win), "expose-event", G_CALLBACK(gtkCanvasBorderExposeEvent), NULL); #endif } gtk_widget_realize(sb_win); if (ih->data->sb & IUP_SB_HORIZ) { #if GTK_CHECK_VERSION(3, 0, 0) GtkWidget* sb_horiz = gtk_scrollbar_new(GTK_ORIENTATION_HORIZONTAL, NULL); #else GtkWidget* sb_horiz = gtk_hscrollbar_new(NULL); #endif iupgtkNativeContainerAdd(sb_win, sb_horiz); gtk_widget_show(sb_horiz); gtk_widget_realize(sb_horiz); g_signal_connect(G_OBJECT(sb_horiz), "change-value",G_CALLBACK(gtkCanvasScrollHorizChangeValue), ih); g_signal_connect(G_OBJECT(gtk_range_get_adjustment(GTK_RANGE(sb_horiz))), "value-changed",G_CALLBACK(gtkCanvasAdjustHorizValueChanged), ih); iupAttribSetStr(ih, "_IUPGTK_SBHORIZ", (char*)sb_horiz); } if (ih->data->sb & IUP_SB_VERT) { #if GTK_CHECK_VERSION(3, 0, 0) GtkWidget* sb_vert = gtk_scrollbar_new(GTK_ORIENTATION_VERTICAL, NULL); #else GtkWidget* sb_vert = gtk_vscrollbar_new(NULL); #endif iupgtkNativeContainerAdd(sb_win, sb_vert); gtk_widget_show(sb_vert); gtk_widget_realize(sb_vert); g_signal_connect(G_OBJECT(sb_vert), "change-value",G_CALLBACK(gtkCanvasScrollVertChangeValue), ih); g_signal_connect(G_OBJECT(gtk_range_get_adjustment(GTK_RANGE(sb_vert))), "value-changed",G_CALLBACK(gtkCanvasAdjustVertValueChanged), ih); iupAttribSetStr(ih, "_IUPGTK_SBVERT", (char*)sb_vert); } gtk_widget_realize(ih->handle); /* configure for DRAG&DROP */ if (IupGetCallback(ih, "DROPFILES_CB")) iupAttribSetStr(ih, "DROPFILESTARGET", "YES"); /* update a mnemonic in a label if necessary */ iupgtkUpdateMnemonic(ih); /* force the update of BGCOLOR here, to let derived classes ignore it if ACTION is defined */ gtkCanvasSetBgColorAttrib(ih, iupAttribGetStr(ih, "BGCOLOR")); return IUP_NOERROR; }
static int iListDragBegin_CB(Ihandle* ih, int x, int y) { int pos = IupConvertXYToPos(ih, x, y); iupAttribSetInt(ih, "_IUP_LIST_SOURCEPOS", pos); return IUP_DEFAULT; }
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 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 gboolean gtkListEditKeyPressEvent(GtkWidget* entry, GdkEventKey *evt, Ihandle *ih) { if ((evt->keyval == GDK_Up || evt->keyval == GDK_KP_Up) || (evt->keyval == GDK_Prior || evt->keyval == GDK_KP_Page_Up) || (evt->keyval == GDK_Down || evt->keyval == GDK_KP_Down) || (evt->keyval == GDK_Next || evt->keyval == GDK_KP_Page_Down)) { int pos = -1; GtkTreeIter iter; GtkTreeModel* model = NULL; GtkTreeSelection* selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(ih->handle)); if (gtk_tree_selection_get_selected(selection, &model, &iter)) { GtkTreePath *path = gtk_tree_model_get_path(model, &iter); int* indices = gtk_tree_path_get_indices(path); pos = indices[0]; gtk_tree_path_free(path); } if (pos == -1) pos = 0; else if (evt->keyval == GDK_Up || evt->keyval == GDK_KP_Up) { pos--; if (pos < 0) pos = 0; } else if (evt->keyval == GDK_Prior || evt->keyval == GDK_KP_Page_Up) { pos -= 5; if (pos < 0) pos = 0; } else if (evt->keyval == GDK_Down || evt->keyval == GDK_KP_Down) { int count = gtk_tree_model_iter_n_children(model, NULL); pos++; if (pos > count-1) pos = count-1; } else if (evt->keyval == GDK_Next || evt->keyval == GDK_KP_Page_Down) { int count = gtk_tree_model_iter_n_children(model, NULL); pos += 5; if (pos > count-1) pos = count-1; } if (pos != -1) { GtkTreePath* path = gtk_tree_path_new_from_indices(pos, -1); g_signal_handlers_block_by_func(G_OBJECT(selection), G_CALLBACK(gtkListSelectionChanged), ih); gtk_tree_selection_select_path(selection, path); g_signal_handlers_unblock_by_func(G_OBJECT(selection), G_CALLBACK(gtkListSelectionChanged), ih); gtk_tree_path_free(path); iupAttribSetInt(ih, "_IUPLIST_OLDVALUE", pos); if (!model) model = gtkListGetModel(ih); if (gtk_tree_model_iter_nth_child(model, &iter, NULL, pos)) { gchar *text = NULL; gtk_tree_model_get(model, &iter, 0, &text, -1); if (text) gtk_entry_set_text((GtkEntry*)entry, text); } } } return iupgtkKeyPressEvent(entry, evt, ih); }
static int gtkListSetValueAttrib(Ihandle* ih, const char* value) { if (ih->data->has_editbox) { GtkEntry* entry = (GtkEntry*)iupAttribGet(ih, "_IUPGTK_ENTRY"); if (!value) value = ""; iupAttribSetStr(ih, "_IUPGTK_DISABLE_TEXT_CB", "1"); gtk_entry_set_text(entry, iupgtkStrConvertToUTF8(value)); iupAttribSetStr(ih, "_IUPGTK_DISABLE_TEXT_CB", NULL); } else { if (ih->data->is_dropdown) { int pos; g_signal_handlers_block_by_func(G_OBJECT(ih->handle), G_CALLBACK(gtkListComboBoxChanged), ih); if (iupStrToInt(value, &pos)==1) { gtk_combo_box_set_active((GtkComboBox*)ih->handle, pos-1); /* IUP starts at 1 */ iupAttribSetInt(ih, "_IUPLIST_OLDVALUE", pos); } else { gtk_combo_box_set_active((GtkComboBox*)ih->handle, -1); /* none */ iupAttribSetStr(ih, "_IUPLIST_OLDVALUE", NULL); } g_signal_handlers_unblock_by_func(G_OBJECT(ih->handle), G_CALLBACK(gtkListComboBoxChanged), ih); } else { GtkTreeSelection* selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(ih->handle)); if (!ih->data->is_multiple) { int pos; g_signal_handlers_block_by_func(G_OBJECT(selection), G_CALLBACK(gtkListSelectionChanged), ih); if (iupStrToInt(value, &pos)==1) { GtkTreePath* path = gtk_tree_path_new_from_indices(pos-1, -1); /* IUP starts at 1 */ gtk_tree_selection_select_path(selection, path); gtk_tree_path_free(path); iupAttribSetInt(ih, "_IUPLIST_OLDVALUE", pos); } else { gtk_tree_selection_unselect_all(selection); iupAttribSetStr(ih, "_IUPLIST_OLDVALUE", NULL); } g_signal_handlers_unblock_by_func(G_OBJECT(selection), G_CALLBACK(gtkListSelectionChanged), ih); } else { /* User has changed a multiple selection on a simple list. */ int i, len, count; g_signal_handlers_block_by_func(G_OBJECT(selection), G_CALLBACK(gtkListSelectionChanged), ih); /* Clear all selections */ gtk_tree_selection_unselect_all(selection); if (!value) { iupAttribSetStr(ih, "_IUPLIST_OLDVALUE", NULL); return 0; } len = strlen(value); count = iupdrvListGetCount(ih); if (len < count) count = len; /* update selection list */ for (i = 0; i<count; i++) { if (value[i]=='+') { GtkTreePath* path = gtk_tree_path_new_from_indices(i, -1); gtk_tree_selection_select_path(selection, path); gtk_tree_path_free(path); } } iupAttribStoreStr(ih, "_IUPLIST_OLDVALUE", value); g_signal_handlers_unblock_by_func(G_OBJECT(selection), G_CALLBACK(gtkListSelectionChanged), ih); } } } return 0; }
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; }
static void motTabsChildAddedMethod(Ihandle* ih, Ihandle* child) { if (IupGetName(child) == NULL) iupAttribSetHandleName(child); if (ih->handle) { Widget child_manager; Widget tab_button; int num_args = 0, pos; Arg args[30]; char *tabtitle, *tabimage, *background; Pixel color; /* open space for new tab number */ motTabsUpdatePageNumber(ih); pos = IupGetChildPos(ih, child); /* Create pages */ child_manager = XtVaCreateManagedWidget( "child_manager", xmBulletinBoardWidgetClass, ih->handle, /* Core */ XmNborderWidth, 0, /* Manager */ XmNshadowThickness, 0, XmNnavigationType, XmTAB_GROUP, XmNuserData, child, /* used only in motTabsConfigureNotify */ /* BulletinBoard */ XmNmarginWidth, 0, XmNmarginHeight, 0, XmNresizePolicy, XmRESIZE_NONE, /* no automatic resize of children */ /* Notebook Constraint */ XmNnotebookChildType, XmPAGE, XmNpageNumber, pos, XmNresizable, True, NULL); XtOverrideTranslations(child_manager, XtParseTranslationTable("<Configure>: iupTabsConfigure()")); tabtitle = iupAttribGet(child, "TABTITLE"); if (!tabtitle) tabtitle = iupTabsAttribGetStrId(ih, "TABTITLE", pos); tabimage = iupAttribGet(child, "TABIMAGE"); if (!tabimage) tabimage = iupTabsAttribGetStrId(ih, "TABIMAGE", pos); if (!tabtitle && !tabimage) tabtitle = " "; /* Create tabs */ /* Label */ iupmotSetArg(args[num_args++], XmNlabelType, tabtitle? XmSTRING: XmPIXMAP); iupmotSetArg(args[num_args++], XmNmarginHeight, 0); iupmotSetArg(args[num_args++], XmNmarginWidth, 0); /* Notebook Constraint */ iupmotSetArg(args[num_args++], XmNnotebookChildType, XmMAJOR_TAB); iupmotSetArg(args[num_args++], XmNpageNumber, pos); tab_button = XtCreateManagedWidget("tab_button", xmPushButtonWidgetClass, ih->handle, args, num_args); /* Disable Drag Source */ iupmotDisableDragSource(tab_button); XtAddEventHandler(tab_button, EnterWindowMask, False, (XtEventHandler)iupmotEnterLeaveWindowEvent, (XtPointer)ih); XtAddEventHandler(tab_button, LeaveWindowMask, False, (XtEventHandler)iupmotEnterLeaveWindowEvent, (XtPointer)ih); XtAddEventHandler(tab_button, FocusChangeMask, False, (XtEventHandler)iupmotFocusChangeEvent, (XtPointer)ih); XtAddEventHandler(tab_button, KeyPressMask, False, (XtEventHandler)iupmotKeyPressEvent, (XtPointer)ih); if (tabtitle) iupmotSetString(tab_button, XmNlabelString, tabtitle); else { Pixmap pixmap = (Pixmap)iupImageGetImage(tabimage, ih, 0, "TABIMAGE"); if (pixmap) XtVaSetValues(tab_button, XmNlabelPixmap, pixmap, NULL); } background = iupBaseNativeParentGetBgColorAttrib(ih); color = iupmotColorGetPixelStr(background); if (color != -1) iupmotSetBgColor(child_manager, color); else { Pixmap pixmap = (Pixmap)iupImageGetImage(background, ih, 0, "BACKGROUND"); if (pixmap) { XtVaSetValues(child_manager, XmNbackgroundPixmap, pixmap, NULL); } } background = iupAttribGetStr(ih, "BGCOLOR"); color = iupmotColorGetPixelStr(background); if (color != -1) iupmotSetBgColor(tab_button, color); color = iupmotColorGetPixelStr(IupGetAttribute(ih, "FGCOLOR")); XtVaSetValues(tab_button, XmNforeground, color, NULL); XtRealizeWidget(child_manager); XtRealizeWidget(tab_button); iupAttribSetStr(child, "_IUPTAB_CONTAINER", (char*)child_manager); iupAttribSetStr(child, "_IUPMOT_TABBUTTON", (char*)tab_button); iupAttribSetInt(child, "_IUPMOT_TABNUMBER", pos); } }
static int iMatrixListEdition_CB(Ihandle *ih, int lin, int col, int mode, int update) { ImatrixListData* mtxList = (ImatrixListData*)iupAttribGet(ih, "_IUPMTXLIST_DATA"); int lines_num = ih->data->lines.num; IFniiii listedition_cb = (IFniiii)IupGetCallback(ih, "LISTEDITION_CB"); /* allow editing only at the label column */ if (col != mtxList->label_col) return IUP_IGNORE; /* allow editing only if active */ if (!IupGetIntId2(ih, "ITEMACTIVE", lin, col)) return IUP_IGNORE; /* call application callback before anything */ if (listedition_cb && listedition_cb(ih, lin, col, mode, update)==IUP_IGNORE) return IUP_IGNORE; if (mode==1 && mtxList->image_col) { if (!IupGetInt(ih, "SHOWDELETE")) IupSetAttributeId(ih, "LINEDELETE", lin, "Yes"); IupSetfAttribute(ih, "REDRAW", "C%d", mtxList->image_col); } /* adding a new line */ if (mtxList->editable && lin == lines_num-1 && mode == 0) { /* clear any edition if not updating */ if (update==0) { IupSetAttribute(ih, "VALUE", ""); IupSetfAttribute(ih, "REDRAW", "L%d", lin); } else { /* check if entered a non empty value */ char* value = IupGetAttribute(ih, "VALUE"); if (value && value[0]!=0) { IFni listinsert_cb = (IFni)IupGetCallback(ih, "LISTINSERT_CB"); /* notify the application that a line will be inserted */ if (listinsert_cb && listinsert_cb(ih, lin) == IUP_IGNORE) { IupSetAttribute(ih, "VALUE", ""); IupSetfAttribute(ih, "REDRAW", "L%d", lin); } else { /* Add a new empty line */ IupSetInt(ih, "ADDLIN", lin); } } } } if (mode==0) { if (!IupGetInt(ih, "SHOWDELETE")) { /* turn off drawing, but prepare for delete */ if (update && ih->data->edit_hidden_byfocus) iupAttribSetInt(ih, "_IUPMTXLIST_DELETE", (int)clock()); IupSetAttributeId(ih, "LINEDELETE", lin, NULL); } IupSetfAttribute(ih, "REDRAW", "C%d", mtxList->image_col); } return IUP_DEFAULT; }
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 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 void motDropProc(Widget dropTarget, XtPointer clientData, XmDropProcCallbackStruct* dropData) { XmDropTransferEntryRec transferList[2]; Arg args[20]; int i, j, num_args; Widget dragContext, dropTransfer; Cardinal numDragTypes, numDropTypes; Atom *dragTypesList, *dropTypesList; Atom atomItem; Boolean found = False; Ihandle *ih = NULL; /* this is called before drag data is processed */ dragContext = dropData->dragContext; /* Getting drop types */ num_args = 0; iupMOT_SETARG(args, num_args, XmNimportTargets, &dropTypesList); iupMOT_SETARG(args, num_args, XmNnumImportTargets, &numDropTypes); XmDropSiteRetrieve (dropTarget, args, num_args); if(!numDropTypes) /* no type registered */ return; /* Getting drag types */ XtVaGetValues(dragContext, XmNexportTargets, &dragTypesList, XmNnumExportTargets, &numDragTypes, NULL); if(!numDragTypes) /* no type registered */ return; /* Checking the type compatibility */ for (i = 0; i < (int)numDragTypes; i++) { for (j = 0; j < (int)numDropTypes; j++) { if(iupStrEqualNoCase(XGetAtomName(iupmot_display, dragTypesList[i]), XGetAtomName(iupmot_display, dropTypesList[j]))) { atomItem = dropTypesList[j]; found = True; break; } } if(found == True) break; } num_args = 0; if ((!found) || (dropData->dropAction != XmDROP) || (dropData->operation != XmDROP_COPY && dropData->operation != XmDROP_MOVE)) { iupMOT_SETARG(args, num_args, XmNtransferStatus, XmTRANSFER_FAILURE); iupMOT_SETARG(args, num_args, XmNnumDropTransfers, 0); } else { XtVaGetValues(dropTarget, XmNuserData, &ih, NULL); iupAttribSetInt(ih, "_IUPMOT_DROP_X", (int)dropData->x); iupAttribSetInt(ih, "_IUPMOT_DROP_Y", (int)dropData->y); /* set up transfer requests for drop site */ transferList[0].target = atomItem; transferList[0].client_data = (XtPointer)ih; iupMOT_SETARG(args, num_args, XmNdropTransfers, transferList); iupMOT_SETARG(args, num_args, XmNnumDropTransfers, 1); iupMOT_SETARG(args, num_args, XmNtransferProc, motDropTransferProc); } /* creates a XmDropTransfer (not used here) */ dropTransfer = XmDropTransferStart(dragContext, args, num_args); (void)dropTransfer; (void)clientData; }
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 int iListDragEnd_CB(Ihandle *ih, int del) { iupAttribSetInt(ih, "_IUP_LIST_SOURCEPOS", 0); (void)del; return IUP_DEFAULT; }
static int motListSetValueAttrib(Ihandle* ih, const char* value) { if (ih->data->has_editbox) { Widget cbedit; XtVaGetValues(ih->handle, XmNtextField, &cbedit, NULL); if (!value) value = ""; iupAttribSet(ih, "_IUPMOT_DISABLE_TEXT_CB", "1"); /* disable callbacks */ iupmotTextSetString(cbedit, value); iupAttribSet(ih, "_IUPMOT_DISABLE_TEXT_CB", NULL); } else { if (ih->data->is_dropdown) { int pos; if (iupStrToInt(value, &pos)==1) { XtRemoveCallback(ih->handle, XmNselectionCallback, (XtCallbackProc)motListComboBoxSelectionCallback, (XtPointer)ih); XtVaSetValues(ih->handle, XmNselectedPosition, pos-1, NULL); /* IUP starts at 1 */ iupAttribSetInt(ih, "_IUPLIST_OLDVALUE", pos); XtAddCallback(ih->handle, XmNselectionCallback, (XtCallbackProc)motListComboBoxSelectionCallback, (XtPointer)ih); } } else { if (!ih->data->is_multiple) { int pos; if (iupStrToInt(value, &pos)==1) { XmListSelectPos(ih->handle, pos, FALSE); /* XmListSelectPos starts at 1 */ iupAttribSetInt(ih, "_IUPLIST_OLDVALUE", pos); } else { XmListDeselectAllItems(ih->handle); iupAttribSet(ih, "_IUPLIST_OLDVALUE", NULL); } } else { /* User has changed a multiple selection on a simple list. */ int i, count, len; /* Clear all selections */ XmListDeselectAllItems(ih->handle); if (!value) { iupAttribSet(ih, "_IUPLIST_OLDVALUE", NULL); return 0; } XtVaGetValues(ih->handle, XmNitemCount, &count, NULL); len = strlen(value); if (len < count) count = len; XtVaSetValues(ih->handle, XmNselectionPolicy, XmMULTIPLE_SELECT, NULL); /* update selection list */ for (i = 0; i<count; i++) { if (value[i]=='+') XmListSelectPos(ih->handle, i+1, False); /* XmListSelectPos starts at 1 */ } XtVaSetValues(ih->handle, XmNselectionPolicy, XmEXTENDED_SELECT, XmNselectionMode, XmNORMAL_MODE, NULL); /* must also restore this */ iupAttribSetStr(ih, "_IUPLIST_OLDVALUE", value); } } } return 0; }
static gboolean gtkDialogConfigureEvent(GtkWidget *widget, GdkEventConfigure *evt, Ihandle *ih) { int old_width, old_height, old_x, old_y; gint x, y; (void)widget; #ifndef HILDON /* In hildon the menu is not a menubar */ if (ih->data->menu && ih->data->menu->handle) gtk_widget_set_size_request(ih->data->menu->handle, evt->width, -1); #endif if (ih->data->ignore_resize) return FALSE; old_width = iupAttribGetInt(ih, "_IUPGTK_OLD_WIDTH"); old_height = iupAttribGetInt(ih, "_IUPGTK_OLD_HEIGHT"); /* Check the size change, because configure is called also for position changes */ if (evt->width != old_width || evt->height != old_height) { IFnii cb; int border, caption, menu; iupAttribSetInt(ih, "_IUPGTK_OLD_WIDTH", evt->width); iupAttribSetInt(ih, "_IUPGTK_OLD_HEIGHT", evt->height); iupdrvDialogGetDecoration(ih, &border, &caption, &menu); /* update dialog size */ #ifdef HILDON /* In Hildon, the configure event contains the window size, not the client area size */ ih->currentwidth = evt->width; ih->currentheight = evt->height; #else ih->currentwidth = evt->width + 2*border; ih->currentheight = evt->height + 2*border + caption; /* menu is inside the window client area */ #endif cb = (IFnii)IupGetCallback(ih, "RESIZE_CB"); if (!cb || cb(ih, evt->width, evt->height - menu)!=IUP_IGNORE) /* width and height here are for the client area */ { ih->data->ignore_resize = 1; IupRefresh(ih); ih->data->ignore_resize = 0; } } old_x = iupAttribGetInt(ih, "_IUPGTK_OLD_X"); old_y = iupAttribGetInt(ih, "_IUPGTK_OLD_Y"); iupdrvDialogGetPosition(ih, NULL, &x, &y); /* ignore evt->x and evt->y because they are the clientpos and not X/Y */ /* Check the position change, because configure is called also for size changes */ if (x != old_x || y != old_y) { IFnii cb; iupAttribSetInt(ih, "_IUPGTK_OLD_X", x); iupAttribSetInt(ih, "_IUPGTK_OLD_Y", y); cb = (IFnii)IupGetCallback(ih, "MOVE_CB"); if (cb) cb(ih, x, y); } return FALSE; }
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 winFileDlgWmNotify(HWND hWnd, LPOFNOTIFY pofn) { Ihandle* ih = (Ihandle*)pofn->lpOFN->lCustData; switch (pofn->hdr.code) { case CDN_INITDONE: { HWND hWndPreview; IFnss cb = (IFnss)IupGetCallback(ih, "FILE_CB"); if (cb) cb(ih, NULL, "INIT"); hWndPreview = GetDlgItem(hWnd, IUP_PREVIEWCANVAS); if (hWndPreview) RedrawWindow(hWndPreview, NULL, NULL, RDW_INVALIDATE|RDW_UPDATENOW); break; } case CDN_FILEOK: case CDN_SELCHANGE: { HWND hWndPreview; IFnss cb = (IFnss)IupGetCallback(ih, "FILE_CB"); if (cb) { char filename[IUP_MAX_FILENAME_SIZE]; if (winFileDlgGetSelectedFile(ih, hWnd, filename)) { int ret; char* file_msg; if (!iupdrvIsFile(filename)) file_msg = "OTHER"; else if (pofn->hdr.code == CDN_FILEOK) file_msg = "OK"; else file_msg = "SELECT"; ret = cb(ih, filename, file_msg); if (pofn->hdr.code == CDN_FILEOK && ret == IUP_IGNORE) { SetWindowLongPtr(hWnd, DWLP_MSGRESULT, 1L); return 1; /* will refuse the file */ } } } hWndPreview = GetDlgItem(hWnd, IUP_PREVIEWCANVAS); if (pofn->hdr.code == CDN_SELCHANGE && hWndPreview) RedrawWindow(hWndPreview, NULL, NULL, RDW_INVALIDATE|RDW_UPDATENOW); break; } case CDN_TYPECHANGE: { IFnss cb = (IFnss)IupGetCallback(ih, "FILE_CB"); if (cb) { char filename[IUP_MAX_FILENAME_SIZE]; if (winFileDlgGetSelectedFile(ih, hWnd, filename)) { iupAttribSetInt(ih, "FILTERUSED", (int)pofn->lpOFN->nFilterIndex); if (cb(ih, filename, "FILTER") == IUP_CONTINUE) { char* value = iupAttribGet(ih, "FILE"); if (value) { strncpy(filename, value, IUP_MAX_FILENAME_SIZE); winFileDlgStrReplacePathSlash(filename); SendMessage(GetParent(hWnd), CDM_SETCONTROLTEXT, (WPARAM)IUP_EDIT, (LPARAM)filename); } } } } break; } case CDN_HELP: { Icallback cb = (Icallback) IupGetCallback(ih, "HELP_CB"); if (cb && cb(ih) == IUP_CLOSE) EndDialog(GetParent(hWnd), IDCANCEL); break; } } return 0; }
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 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 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 (iupAttribGetInt(ih, "DIALOGFRAME")) { iupAttribSetStr(ih, "RESIZE", "NO"); iupAttribSetStr(ih, "MINBOX", "NO"); } if (iupAttribGetInt(ih, "RESIZE")) dwStyle |= WS_THICKFRAME; else iupAttribSetStr(ih, "MAXBOX", "NO"); /* Must also remove this to RESIZE=NO work */ if (iupAttribGetInt(ih, "MAXBOX")) { dwStyle |= WS_MAXIMIZEBOX; has_titlebar = 1; } if (iupAttribGetInt(ih, "MINBOX")) { dwStyle |= WS_MINIMIZEBOX; has_titlebar = 1; } if (iupAttribGetInt(ih, "MENUBOX")) { dwStyle |= WS_SYSMENU; has_titlebar = 1; } if (iupAttribGetInt(ih, "BORDER") || has_titlebar) has_border = 1; if (iupAttribGetInt(ih, "MDICHILD")) { static int mdi_child_id = 0; Ihandle *client; char name[50]; /* 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); sprintf(name, "_IUPWIN_MDI_ID_[%d]", mdi_child_id); iupAttribSetStr(parent, name, (char*)ih); mdi_child_id++; iupAttribSetInt(parent, "_IUPWIN_MAX_MDI_ID", mdi_child_id); 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 (iupAttribGet(ih, "MDIFRAME")) classname = "IupDialogMDIFrame"; } if (iupAttribGetInt(ih, "TOOLBOX") && native_parent) dwExStyle |= WS_EX_TOOLWINDOW | WS_EX_WINDOWEDGE; if (iupAttribGetInt(ih, "DIALOGFRAME") && native_parent) dwExStyle |= WS_EX_DLGMODALFRAME; /* this will hide the MENUBOX but not the close button */ if (iupAttribGetInt(ih, "COMPOSITED")) dwExStyle |= WS_EX_COMPOSITED; else dwStyle |= WS_CLIPCHILDREN; if (iupAttribGetInt(ih, "HELPBUTTON")) dwExStyle |= WS_EX_CONTEXTHELP; if (iupAttribGetInt(ih, "CONTROL") && native_parent) { /* TODO: this were used by LuaCom to create embeded controls, don't know if it is still working */ dwExStyle |= WS_EX_CONTROLPARENT; 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 (iupAttribGetInt(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. */ iupwinHandleSet(ih); if (iupStrEqual(classname, "IupDialogMDIChild")) /* hides the mdi child */ ShowWindow(ih->handle, SW_HIDE); /* configure for DRAG&DROP */ if (IupGetCallback(ih, "DROPFILES_CB")) iupAttribSetStr(ih, "DRAGDROP", "YES"); /* Reset attributes handled during creation that */ /* also can be changed later, and can be consulted from the native system. */ iupAttribSetStr(ih, "TITLE", NULL); iupAttribSetStr(ih, "BORDER", NULL); /* Ignore VISIBLE before mapping */ iupAttribSetStr(ih, "VISIBLE", NULL); /* Set the default CmdShow for ShowWindow */ ih->data->cmd_show = SW_SHOWNORMAL; return IUP_NOERROR; }