int wxMessageDialog::ShowModal() { WX_HOOK_MODAL_DIALOG(); const long style = GetMessageDialogStyle(); DialogCreateFunction dialogCreateFunction; if ( style & wxYES_NO ) { // if we have [Yes], it must be a question dialogCreateFunction = XmCreateQuestionDialog; } else if ( style & wxICON_STOP ) { // error dialog is the one with error icon... dialogCreateFunction = XmCreateErrorDialog; } else if ( style & wxICON_EXCLAMATION ) { // ...and the warning dialog too dialogCreateFunction = XmCreateWarningDialog; } else { // finally, use the info dialog by default dialogCreateFunction = XmCreateInformationDialog; } Widget wParent = m_parent ? GetWidget(m_parent) : (Widget) 0; if ( !wParent ) { wxWindow *window = wxTheApp->GetTopWindow(); if ( !window ) { wxFAIL_MSG("can't show message box without parent window"); return wxID_CANCEL; } wParent = GetWidget(window); } // prepare the arg list Arg args[10]; int ac = 0; wxXmString text(GetFullMessage()); wxXmString title(m_caption); XtSetArg(args[ac], XmNmessageString, text()); ac++; XtSetArg(args[ac], XmNdialogTitle, title()); ac++; Display* dpy = XtDisplay(wParent); if (m_backgroundColour.IsOk()) { wxComputeColours (dpy, & m_backgroundColour, NULL); XtSetArg(args[ac], XmNbackground, g_itemColors[wxBACK_INDEX].pixel); ac++; XtSetArg(args[ac], XmNtopShadowColor, g_itemColors[wxTOPS_INDEX].pixel); ac++; XtSetArg(args[ac], XmNbottomShadowColor, g_itemColors[wxBOTS_INDEX].pixel); ac++; XtSetArg(args[ac], XmNforeground, g_itemColors[wxFORE_INDEX].pixel); ac++; } wxFont font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT); #if __WXMOTIF20__ && !__WXLESSTIF__ XtSetArg(args[ac], XmNbuttonRenderTable, font.GetFontTypeC(dpy)); ac++; XtSetArg(args[ac], XmNlabelRenderTable, font.GetFontTypeC(dpy)); ac++; XtSetArg(args[ac], XmNtextRenderTable, font.GetFontTypeC(dpy)); ac++; #else XtSetArg(args[ac], XmNbuttonFontList, font.GetFontTypeC(dpy)); ac++; XtSetArg(args[ac], XmNlabelFontList, font.GetFontTypeC(dpy)); ac++; XtSetArg(args[ac], XmNtextFontList, font.GetFontTypeC(dpy)); ac++; #endif // do create message box Widget wMsgBox = (*dialogCreateFunction)(wParent, wxMOTIF_STR(""), args, ac); wxCHECK_MSG( wMsgBox, wxID_CANCEL, "msg box creation failed" ); // get the buttons which we might either remove or rename // depending on the requested style // Widget wBtnOk = XmMessageBoxGetChild(wMsgBox, XmDIALOG_OK_BUTTON); Widget wBtnHelp = XmMessageBoxGetChild(wMsgBox, XmDIALOG_HELP_BUTTON); Widget wBtnCancel = XmMessageBoxGetChild(wMsgBox, XmDIALOG_CANCEL_BUTTON); if ( style & wxYES_NO ) { wxXmString yes(_("Yes")), no(_("No")), cancel(_("Cancel")); if ( style & wxCANCEL ) { // use the cancel button for No and the help button for // Cancel Yuk :-) MB // XtVaSetValues(wBtnOk, XmNlabelString, yes(), NULL); XtVaSetValues(wBtnCancel, XmNlabelString, no(), NULL); XtVaSetValues(wBtnHelp, XmNlabelString, cancel(), NULL); } else { // no cancel button requested... // remove the help button and use cancel for no // XtVaSetValues(wBtnCancel, XmNlabelString, no(), NULL); XtUnmanageChild(wBtnHelp); } } else { // remove the help button and the cancel button (unless it was // requested) // XtUnmanageChild(wBtnHelp); if ( !(style & wxCANCEL ) ) XtUnmanageChild(wBtnCancel); } // set the callbacks for the message box buttons XtAddCallback(wMsgBox, XmNokCallback, (XtCallbackProc)msgboxCallBackOk, (XtPointer)this); XtAddCallback(wMsgBox, XmNcancelCallback, (XtCallbackProc)msgboxCallBackCancel, (XtPointer)this); XtAddCallback(wMsgBox, XmNhelpCallback, (XtCallbackProc)msgboxCallBackHelp, (XtPointer)this); XtAddCallback(wMsgBox, XmNunmapCallback, (XtCallbackProc)msgboxCallBackClose, (XtPointer)this); // show it as a modal dialog XtManageChild(wMsgBox); XtAddGrab(wMsgBox, True, False); // the m_result will be changed when message box goes away m_result = -1; // local message loop XtAppContext context = XtWidgetToApplicationContext(wParent); XEvent event; while ( m_result == -1 ) { XtAppNextEvent(context, &event); XtDispatchEvent(&event); } // translate the result if necessary if ( style & wxYES_NO ) { if ( m_result == wxID_OK ) m_result = wxID_YES; else if ( m_result == wxID_CANCEL ) m_result = wxID_NO; else if ( m_result == wxID_HELP ) m_result = wxID_CANCEL; } return m_result; }
int yesno(const char *msg1, const char *s1, const char *s2, const char *helptext) { char buf[256]; static XmString str, str1, str2; XEvent event; ht = (char *)helptext; keep_grab = True; if (noask) { return 1; } if (!inwin) { fprintf(stderr, "%s\n", msg1); fprintf(stderr, "%s\n", "(y)es/(n)o:"); fgets(buf, 256, stdin); if (buf[0] == 'y') { return 1; } else { return 0; } } if (yesno_popup) { XmStringFree(str); XmStringFree(str1); XmStringFree(str2); str = XmStringCreateLtoR((char *)msg1, charset); XtVaSetValues(yesno_popup, XmNmessageString, str, NULL); if (s1 != NULL) { XtVaSetValues(yesno_popup, XmNokLabelString, str1 = XmStringCreateLtoR((char *)s1, charset), NULL); } else { XtVaSetValues(yesno_popup, XmNokLabelString, str1 = XmStringCreateLtoR((char *)"OK", charset), NULL); } if (s2 != NULL) { XtVaSetValues(yesno_popup, XmNcancelLabelString, str2 = XmStringCreateLtoR((char *)s2, charset), NULL); } else { XtVaSetValues(yesno_popup, XmNcancelLabelString, str2 = XmStringCreateLtoR((char *)"Cancel", charset), NULL); } } else { str = XmStringCreateLtoR((char *)msg1, charset); yesno_popup = XmCreateErrorDialog(app_shell, (char *)"warndlg", NULL, 0); XtVaSetValues(yesno_popup, XmNmessageString, str, XmNdialogTitle, XmStringCreateLtoR((char *)"Warning", charset), NULL); if (s1 != NULL) { XtVaSetValues(yesno_popup, XmNokLabelString, str1 = XmStringCreateLtoR((char *)s1, charset), NULL); } else { } if (s2 != NULL) { XtVaSetValues(yesno_popup, XmNcancelLabelString, str2 = XmStringCreateLtoR((char *)s2, charset), NULL); } else { } XtAddCallback(yesno_popup, XmNokCallback, (XtCallbackProc)yesnoCB, (XtPointer)&keep_grab); XtAddCallback(yesno_popup, XmNcancelCallback, (XtCallbackProc)yesnoCB, (XtPointer)&keep_grab); XtAddCallback(yesno_popup, XmNhelpCallback, (XtCallbackProc)yesnoCB, (XtPointer)&keep_grab); } XtManageChild(yesno_popup); XtAddGrab(XtParent(yesno_popup), True, False); while (keep_grab || XtAppPending(app_con)) { XtAppNextEvent(app_con, &event); XtDispatchEvent(&event); } return yesno_retval; }
int wxFileDialog::ShowModal() { wxBeginBusyCursor(); // static char fileBuf[512]; Widget parentWidget = (Widget) 0; if (m_parent) parentWidget = (Widget) m_parent->GetTopWidget(); else parentWidget = (Widget) wxTheApp->GetTopLevelWidget(); // prepare the arg list Display* dpy = XtDisplay(parentWidget); Arg args[10]; int ac = 0; if (m_backgroundColour.IsOk()) { wxComputeColours (dpy, & m_backgroundColour, NULL); XtSetArg(args[ac], XmNbackground, g_itemColors[wxBACK_INDEX].pixel); ac++; XtSetArg(args[ac], XmNtopShadowColor, g_itemColors[wxTOPS_INDEX].pixel); ac++; XtSetArg(args[ac], XmNbottomShadowColor, g_itemColors[wxBOTS_INDEX].pixel); ac++; XtSetArg(args[ac], XmNforeground, g_itemColors[wxFORE_INDEX].pixel); ac++; } wxFont font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT); #if __WXMOTIF20__ && !__WXLESSTIF__ XtSetArg(args[ac], XmNbuttonRenderTable, font.GetFontTypeC(dpy)); ac++; XtSetArg(args[ac], XmNlabelRenderTable, font.GetFontTypeC(dpy)); ac++; XtSetArg(args[ac], XmNtextRenderTable, font.GetFontTypeC(dpy)); ac++; #else XtSetArg(args[ac], XmNbuttonFontList, font.GetFontTypeC(dpy)); ac++; XtSetArg(args[ac], XmNlabelFontList, font.GetFontTypeC(dpy)); ac++; XtSetArg(args[ac], XmNtextFontList, font.GetFontTypeC(dpy)); ac++; #endif Widget fileSel = XmCreateFileSelectionDialog(parentWidget, wxMOTIF_STR("file_selector"), args, ac); #define wxFSChild( name ) \ XmFileSelectionBoxGetChild(fileSel, name) XtUnmanageChild(wxFSChild(XmDIALOG_HELP_BUTTON)); Widget filterWidget = wxFSChild(XmDIALOG_FILTER_TEXT); Widget selectionWidget = wxFSChild(XmDIALOG_TEXT); Widget dirListWidget = wxFSChild(XmDIALOG_DIR_LIST); Widget fileListWidget = wxFSChild(XmDIALOG_LIST); // for changing labels Widget okWidget = wxFSChild(XmDIALOG_OK_BUTTON); Widget applyWidget = wxFSChild(XmDIALOG_APPLY_BUTTON); Widget cancelWidget = wxFSChild(XmDIALOG_CANCEL_BUTTON); Widget dirlistLabel = wxFSChild(XmDIALOG_DIR_LIST_LABEL); Widget filterLabel = wxFSChild(XmDIALOG_FILTER_LABEL); Widget listLabel = wxFSChild(XmDIALOG_LIST_LABEL); Widget selectionLabel = wxFSChild(XmDIALOG_SELECTION_LABEL); #undef wxFSChild // change labels wxXmString btnOK( wxGetStockLabel( wxID_OK, false ) ), btnCancel( wxGetStockLabel( wxID_CANCEL, false ) ), btnFilter( _("Filter") ), lblFilter( _("Filter") ), lblDirectories( _("Directories") ), lblFiles( _("Files" ) ), lblSelection( _("Selection") ); XtVaSetValues( okWidget, XmNlabelString, btnOK(), NULL ); XtVaSetValues( applyWidget, XmNlabelString, btnFilter(), NULL ); XtVaSetValues( cancelWidget, XmNlabelString, btnCancel(), NULL ); XtVaSetValues( dirlistLabel, XmNlabelString, lblDirectories(), NULL ); XtVaSetValues( filterLabel, XmNlabelString, lblFilter(), NULL ); XtVaSetValues( listLabel, XmNlabelString, lblFiles(), NULL ); XtVaSetValues( selectionLabel, XmNlabelString, lblSelection(), NULL ); Widget shell = XtParent(fileSel); if ( !m_message.empty() ) XtVaSetValues(shell, XmNtitle, (const char*)m_message.mb_str(), NULL); if (!m_wildCard.empty()) { // return something understandable by Motif wxString wildCard = ParseWildCard( m_wildCard ); wxString filter; if (!m_dir.empty()) filter = m_dir + wxString("/") + wildCard; else filter = wildCard; XmTextSetString(filterWidget, filter.char_str()); XmFileSelectionDoSearch(fileSel, NULL); } // Suggested by Terry Gitnick, 16/9/97, because of change in Motif // file selector on Solaris 1.5.1. if ( !m_dir.empty() ) { wxXmString thePath( m_dir ); XtVaSetValues (fileSel, XmNdirectory, thePath(), NULL); } wxString entirePath; if (!m_dir.empty()) { entirePath = m_dir + wxString("/") + m_fileName; } else { entirePath = m_fileName; } if (!entirePath.empty()) { XmTextSetString(selectionWidget, entirePath.char_str()); } XtAddCallback(fileSel, XmNcancelCallback, (XtCallbackProc)wxFileSelCancel, (XtPointer)NULL); XtAddCallback(fileSel, XmNokCallback, (XtCallbackProc)wxFileSelOk, (XtPointer)NULL); XtAddCallback(fileSel, XmNunmapCallback, (XtCallbackProc)wxFileSelClose, (XtPointer)this); //#if XmVersion > 1000 // I'm not sure about what you mean with XmVersion. // If this is for Motif1.1/Motif1.2, then check XmVersion>=1200 // (Motif1.1.4 ==> XmVersion 1100 ) // Nevertheless, I put here a #define, so anyone can choose in (I)makefile. // #if !DEFAULT_FILE_SELECTOR_SIZE int width = wxFSB_WIDTH; int height = wxFSB_HEIGHT; XtVaSetValues(fileSel, XmNwidth, width, XmNheight, height, XmNresizePolicy, XmRESIZE_NONE, NULL); #endif wxDoChangeBackgroundColour((WXWidget) filterWidget, *wxWHITE); wxDoChangeBackgroundColour((WXWidget) selectionWidget, *wxWHITE); wxChangeListBoxColours(this, dirListWidget); wxChangeListBoxColours(this, fileListWidget); XtManageChild(fileSel); m_fileSelectorAnswer = wxEmptyString; m_fileSelectorReturned = false; wxEndBusyCursor(); XtAddGrab(XtParent(fileSel), True, False); XtAppContext context = (XtAppContext) wxTheApp->GetAppContext(); XEvent event; while (!m_fileSelectorReturned) { XtAppNextEvent(context, &event); XtDispatchEvent(&event); } XtRemoveGrab(XtParent(fileSel)); XtUnmapWidget(XtParent(fileSel)); XtDestroyWidget(XtParent(fileSel)); // Now process all events, because otherwise // this might remain on the screen wxFlushEvents(XtDisplay(fileSel)); m_path = m_fileSelectorAnswer; m_fileName = wxFileNameFromPath(m_fileSelectorAnswer); m_dir = wxPathOnly(m_path); if (m_fileName.empty()) return wxID_CANCEL; else return wxID_OK; }
int RequestAction(int labelc, int buttonc, int justify, char *banner, char *labels[], char *buttons[], struct Logo *Llogo, struct Logo *Rlogo, void (*callBack)(int)) { int i; int b_y; int count; int leng; void IFeep(); XEvent event; Arg args[200]; WindowInfo info; XSizeHints hints; Widget last = NULL; act.active = 1; act.callBack = callBack; count = 0; XtSetArg(args[count], XtNx, start_x); count++; XtSetArg(args[count], XtNy, start_y); count++; XtSetArg(args[count], XtNiconName, "Terrain Message"); count++; XtSetArg(args[count], XtNmappedWhenManaged, False); count++; act.shell = XtCreatePopupShell("Message" , topLevelShellWidgetClass, w_top, args, (unsigned) count); /* form to hold items */ count = 0; XtSetArg(args[count], XtNdefaultDistance, DEF_DIST); count++; act.form = XtCreateManagedWidget("form", formWidgetClass, act.shell, args, (unsigned) count); XtAddEventHandler(act.form, ButtonPressMask, (int)NULL, IFeep, NULL); /* left logo if it exists */ if (Llogo) { count = 0; XtSetArg(args[count], XtNborderWidth, 0); count++; XtSetArg(args[count], XtNbitmap, Llogo->icon); count++; last = act.Llogo = XtCreateManagedWidget("Llogo", labelWidgetClass, act.form, args, (unsigned) count); } /* banner title */ b_y = Llogo ? Llogo->h : 0; b_y = (Rlogo && (Rlogo->h > b_y)) ? Rlogo->h : b_y; count = 0; if (Llogo) XtSetArg(args[count], XtNhorizDistance, 0), count++; if (b_y) XtSetArg(args[count], XtNheight, b_y); count++; XtSetArg(args[count], XtNresizable, True); count++; XtSetArg(args[count], XtNresize, True); count++; XtSetArg(args[count], XtNfromHoriz, last); count++; XtSetArg(args[count], XtNborderWidth, 0); count++; XtSetArg(args[count], XtNlabel, banner); count++; last = act.banner = XtCreateManagedWidget("bannerString", labelWidgetClass, act.form, args, (unsigned) count); /* right logo if it exists */ if (Rlogo) { count = 0; XtSetArg(args[count], XtNbitmap, Rlogo->icon); count++; XtSetArg(args[count], XtNborderWidth, 0); count++; XtSetArg(args[count], XtNfromHoriz, act.banner); count++; XtSetArg(args[count], XtNhorizDistance, 5), count++; last = act.Rlogo = XtCreateManagedWidget("Rlogo", labelWidgetClass, act.form, args, (unsigned) count); } if (labelc) { leng = 0; width = 0; for (i=0; i < labelc; i++) { leng += strlen(labels[i]); width = max(width,XTextWidth(fontStruct, labels[i], (signed) strlen(labels[i]))); } act.str = (char *) malloc((unsigned) leng + labelc); act.str[0] = '\0'; for (i=0; i < labelc; i++) { if (i) strcat(act.str, "\n"); strcat(act.str, labels[i]); } count = 0; XtSetArg(args[count], XtNborderWidth, 0); count++; XtSetArg(args[count], XtNtopMargin, 0); count++; XtSetArg(args[count], XtNbottomMargin, 0); count++; XtSetArg(args[count], XtNwidth, width+10); count++; height = fontHeight * labelc; XtSetArg(args[count], XtNheight, height+5); count++; XtSetArg(args[count], XtNjustify, justify); count++; XtSetArg(args[count], XtNfromVert, last); count++; XtSetArg(args[count], XtNresizable, True); count++; XtSetArg(args[count], XtNdisplayCaret, False); count++; XtSetArg(args[count], XtNresize, XawtextResizeWidth); count++; XtSetArg(args[count], XtNstring, act.str); count++; last = act.message = XtCreateManagedWidget("message", asciiTextWidgetClass, act.form, args, (unsigned) count); } count = 0; XtSetArg(args[count], XtNfromVert, last); count++; XtSetArg(args[count], XtNfromHoriz, NULL); count++; XtSetArg(args[count], XtNborderWidth, 0); count++; XtSetArg(args[count], XtNvSpace, 5); count++; XtSetArg(args[count], XtNhSpace, 15); count++; XtSetArg(args[count], XtNorientation, XtorientHorizontal); count++; XtSetArg(args[count], XtNtop, XtChainBottom); count++; XtSetArg(args[count], XtNbottom, XtChainBottom); count++; XtSetArg(args[count], XtNresizable, True); count++; XtSetArg(args[count], XtNresize, True); count++; XtSetArg(args[count], XtNformat, XtNcenter); count++; act.box = XtCreateManagedWidget("box", formatBoxWidgetClass, act.form, args, (unsigned) count); act.buttons = (Widget *) calloc((unsigned) buttonc, sizeof(Widget)); for (i=0; i < buttonc; i++) { last = act.buttons[i] = XtCreateManagedWidget(buttons[i], commandWidgetClass, act.box, NULL, 0); XtAddCallback(act.buttons[i], XtNcallback, (XtCallbackProc)EndActFunc, (XtPointer)i); } XtRealizeWidget(act.shell); IGetGeometry(XtWindow(act.form), &info); width = info.width - 2 * DEF_DIST; width -= Rlogo ? (Rlogo->w + DEF_DIST): 0; width -= Llogo ? (Llogo->w + DEF_DIST): 0; XtSetValue(act.banner, XtNwidth, (XtPointer)width); width = info.width - 2 * DEF_DIST; if (labelc) XtSetValue(act.message, XtNwidth, (XtPointer)width); XtSetValue(act.box, XtNwidth, (XtPointer)width); hints.flags = USPosition; hints.x = start_x; hints.y = start_y; XSetNormalHints(XtDisplay(act.shell), XtWindow(act.shell), &hints); XtAddGrab(act.shell, TRUE, FALSE); XtMapWidget(act.shell); /* We need to process events until the action is done, then we can let the function return. This prevents multiple error windows from becomming active at once. */ while (act.active) { XNextEvent(dpy, &event); XtDispatchEvent(&event); } return(0); }