// Create a file dialog NAME with DO_SEARCH_FILES and DO_SEARCH_DIRS // as search procedures for files and directories, respectively, and // OK_CALLBACK as the procedure called when a file is selected. static Widget file_dialog(Widget w, const string& name, FileSearchProc do_search_files = 0, FileSearchProc do_search_dirs = 0, XtCallbackProc ok_callback = 0) { Delay delay(w); Arg args[10]; int arg = 0; string pwd; arg = 0; if (do_search_files) { XtSetArg(args[arg], XmNfileSearchProc, do_search_files); arg++; } if (do_search_dirs) { XtSetArg(args[arg], XmNdirSearchProc, do_search_dirs); arg++; } if (remote_gdb()) { static MString xmpwd; xmpwd = source_view->pwd(); XtSetArg(args[arg], XmNdirectory, xmpwd.xmstring()); arg++; } Widget dialog = verify(XmCreateFileSelectionDialog(w, XMST(name.chars()), args, arg)); Delay::register_shell(dialog); if (ok_callback != 0) XtAddCallback(dialog, XmNokCallback, ok_callback, 0); XtAddCallback(dialog, XmNcancelCallback, UnmanageThisCB, XtPointer(dialog)); XtAddCallback(dialog, XmNhelpCallback, ImmediateHelpCB, 0); Widget filter = XmFileSelectionBoxGetChild(dialog, XmDIALOG_FILTER_TEXT); file_filters += filter; if (!current_file_filter.empty()) XmTextSetString(filter, XMST(current_file_filter.chars())); XtAddCallback(filter, XmNvalueChangedCallback, SyncFiltersCB, 0); Widget filter_button = XmFileSelectionBoxGetChild(dialog, XmDIALOG_APPLY_BUTTON); XtAddCallback(filter_button, XmNactivateCallback, FilterAllCB, 0); XtAddCallback(dialog, XmNunmapCallback, ClearStatusCB, 0); file_dialogs += dialog; return dialog; }
// Make sure that every change in one filter is reflected in all others static void SyncFiltersCB(Widget dialog, XtPointer, XtPointer) { static bool entered = false; if (entered) return; entered = true; // std::clog << "widget = " << longName(text) << "\n"; while (dialog != 0 && !XmIsFileSelectionBox(dialog)) dialog = XtParent(dialog); // std::clog << "dialog = " << longName(dialog) << "\n"; Widget text = XmFileSelectionBoxGetChild(dialog, XmDIALOG_FILTER_TEXT); String _current_file_filter = XmTextGetString(text); current_file_filter = _current_file_filter; XtFree(_current_file_filter); for (int i = 0; i < file_filters.size(); i++) { if (file_dialogs[i] != dialog) { // std::clog << "other dialog = " << longName(file_dialogs[i]) << "\n"; XmTextSetString(file_filters[i], XMST(current_file_filter.chars())); } } entered = false; }
Widget UIFileSelectionCreate(char *titleText, char *directory, char *pattern, int type) { static char fullPath[DBDataFileNameLen]; XmString string; Widget dShell, selection; dShell = XtVaCreatePopupShell(titleText, xmDialogShellWidgetClass, UITopLevel(), XmNallowShellResize, true, XmNtransient, true, XmNkeyboardFocusPolicy, XmEXPLICIT, NULL); selection = XtVaCreateWidget("UIFileSelectionDialog", xmFileSelectionBoxWidgetClass, dShell, XmNfileTypeMask, type, XmNdialogStyle, XmDIALOG_FULL_APPLICATION_MODAL, NULL); if (directory != NULL) { string = XmStringCreate(directory, UICharSetNormal); XtVaSetValues(selection, XmNdirectory, string, NULL); XmStringFree(string); } if (pattern != NULL) { string = XmStringCreate(pattern, UICharSetNormal); XtVaSetValues(selection, XmNpattern, string, NULL); XmStringFree(string); } XtUnmanageChild(XmFileSelectionBoxGetChild(selection, XmDIALOG_HELP_BUTTON)); XtAddCallback(selection, XmNokCallback, (XtCallbackProc) _UIFileSelectionOkCBK, fullPath); XtAddCallback(selection, XmNokCallback, (XtCallbackProc) UILoopStopCBK, NULL); XtAddCallback(selection, XmNcancelCallback, (XtCallbackProc) UILoopStopCBK, NULL); XtAddCallback(selection, XmNnoMatchCallback, (XtCallbackProc) _UIFileSelectionNoMatchCBK, NULL); return (selection); }
Widget XsraSelFile(Widget parent, struct filesel_callback *callback) { Widget dialog = XmCreateFileSelectionDialog(parent, "file", NULL, 0); XtVaSetValues(XtParent(dialog), XmNtitle, callback->title, NULL); XtAddCallback(dialog, XmNokCallback, accept_callback, (XtPointer)callback); XtAddCallback(dialog, XmNcancelCallback, cancel_callback, (XtPointer)callback); /* When opening a DVI file, offer to open in new window */ if (callback->must_exist) { Widget form, button; XmString test; form = XtVaCreateManagedWidget("new_window_form", xmFormWidgetClass, dialog, NULL); test = XmStringCreateLocalized("Open file in new window"); button = XtVaCreateManagedWidget(Xdvi_NEW_WINDOW_RADIO_NAME, xmToggleButtonGadgetClass, form, XmNlabelString, test, XmNindicatorType, XmN_OF_MANY, XmNset, resource.filesel_open_new_window, NULL); XmStringFree(test); XtAddCallback(button, XmNvalueChangedCallback, cb_open_new_window, (XtPointer)NULL); } /* We have no help in this window, so hide help button */ XtUnmanageChild(XmFileSelectionBoxGetChild(dialog, (unsigned char)XmDIALOG_HELP_BUTTON)); return dialog; }
void CoWowMotif::CreateFileSelDia( const char *title, void *parent_ctx, void (*file_selected_cb)(void *, char *, wow_eFileSelType), wow_eFileSelType file_type) { Arg args[10]; XmString ctitle, cdirectory, cpattern; char directory[200]; int i; wow_tFileSelCtx ctx; Widget help; ctx = (wow_tFileSelCtx) calloc( 1, sizeof(*ctx)); ctx->file_selected_cb = file_selected_cb; ctx->parent_ctx = parent_ctx; ctx->file_type = file_type; ctitle = XmStringCreateLtoR( (char*) title, XmSTRING_DEFAULT_CHARSET); i = 0; XtSetArg( args[i], XmNdialogTitle, ctitle); i++; XtSetArg( args[i], XmNfileTypeMask, XmFILE_REGULAR); i++; XtSetArg( args[i], XmNfileSearchProc, file_search_cb); i++; switch( file_type) { case wow_eFileSelType_All: break; case wow_eFileSelType_Dbs: dcli_translate_filename( directory, "$pwrp_load/"); cdirectory = XmStringCreateLtoR( directory, XmSTRING_DEFAULT_CHARSET); cpattern = XmStringCreateLtoR( (char*) "*.dbs", XmSTRING_DEFAULT_CHARSET); XtSetArg( args[i], XmNdirectory, cdirectory); i++; XtSetArg( args[i], XmNpattern, cpattern); i++; break; case wow_eFileSelType_Wbl: case wow_eFileSelType_WblClass: dcli_translate_filename( directory, "$pwrp_db/"); cdirectory = XmStringCreateLtoR( directory, XmSTRING_DEFAULT_CHARSET); cpattern = XmStringCreateLtoR( (char*) "*.wb_load", XmSTRING_DEFAULT_CHARSET); XtSetArg( args[i], XmNdirectory, cdirectory); i++; XtSetArg( args[i], XmNpattern, cpattern); i++; break; default: ; } ctx->dialog = XmCreateFileSelectionDialog( m_parent, (char*) "fileseldia", args, i); XtAddCallback( ctx->dialog, XmNokCallback, file_ok_cb, ctx); XtAddCallback( ctx->dialog, XmNcancelCallback, file_cancel_cb, ctx); help = XmFileSelectionBoxGetChild( ctx->dialog, XmDIALOG_HELP_BUTTON); XtUnmanageChild( help); XtManageChild( ctx->dialog); XmStringFree( ctitle); XmStringFree( cdirectory); XmStringFree( cpattern); }
void CtrlBox(int argc, char **argv) { XtAppContext app; Widget toplevel, box, temp; Widget buttons[10]; int nbuttons; char* exitPoint = names[EXIT_PROGRAM]; if (argc > 1) { argv[0] = "Remote"; if (argc > 2) exitPoint = "Back to PC desktop "; } else argv[0] = "Local"; argc = 1; toplevel = XtVaAppInitialize(&app,"CtrlBox",NULL, 0, &argc, argv, NULL, NULL); box = XtVaCreateManagedWidget("box",xmRowColumnWidgetClass, toplevel, NULL); nbuttons = 0; while(names[nbuttons] != 0) { if (nbuttons == EXIT_PROGRAM ) buttons[nbuttons] = XtVaCreateManagedWidget(exitPoint, xmPushButtonWidgetClass, box, NULL, 0); else buttons[nbuttons] = XtVaCreateManagedWidget(names[nbuttons], xmPushButtonWidgetClass, box, NULL, 0); XtAddCallback(buttons[nbuttons],XmNactivateCallback, callback, &values[nbuttons]); nbuttons++; } // Create a popup error message dialog; no cancel, no help button errorDialog = XmCreateErrorDialog(box, "errorDialog", NULL, 0); temp = XmMessageBoxGetChild(errorDialog, XmDIALOG_CANCEL_BUTTON); XtUnmanageChild(temp); temp = XmMessageBoxGetChild(errorDialog, XmDIALOG_HELP_BUTTON); XtUnmanageChild(temp); // Create a popup dialog to get the filename; no help button fileDialog = XmCreateFileSelectionDialog(box, "fileDialog", NULL, 0); XtVaSetValues(fileDialog, XmNwidth, 400, NULL); temp = XmFileSelectionBoxGetChild(fileDialog, XmDIALOG_HELP_BUTTON); XtUnmanageChild(temp); XtAddCallback(fileDialog, XmNokCallback, OpenFile, NULL); XtAddCallback(fileDialog, XmNcancelCallback, Cancel, NULL); XtManageChildren(buttons,nbuttons); XtRealizeWidget(toplevel); XMoveWindow (XtDisplay(toplevel), XtWindow(toplevel), 0, 0); XWarpPointer(XtDisplay(box), None, XtWindow(box), 0, 0, 0, 0, 400, 300); XtAppMainLoop(app); }
/*ARGSUSED*/ static void openCB(Widget w,int client_data,XmFileSelectionBoxCallbackStruct *call_data) { if (client_data==DIALOG_CANCEL) { /* do nothing if cancel is selected. */ XtUnmanageChild(open_dialog); return; } else if (client_data==DIALOG_ALL) { /* Add all the listed files */ Arg al[10]; int ac; Widget the_list; int nbfile; XmStringTable files; char *text; int i; the_list=XmFileSelectionBoxGetChild(open_dialog,XmDIALOG_LIST); if (!XmIsList(the_list)) { fprintf(stderr, "PANIC: List are not what they used to be" NLS); exit(1); } ac=0; XtSetArg(al[ac], XmNitemCount, &nbfile); ac++; XtSetArg(al[ac], XmNitems, &files); ac++; XtGetValues(the_list, al, ac); m_pipe_int_write(MOTIF_EXPAND); m_pipe_int_write(nbfile); for (i=0;i<nbfile;i++) { XmStringGetLtoR(files[i],char_set,&text); m_pipe_string_write(text); XtFree(text); } XtUnmanageChild(open_dialog); } else { /* get filename from file selection box and add it to the list*/ char *text; m_pipe_int_write(MOTIF_EXPAND); m_pipe_int_write(1); XmStringGetLtoR(call_data->value,char_set,&text); m_pipe_string_write(text); XtFree(text); XtUnmanageChild(open_dialog); } }
static void replacementFileSearchProc(Widget w, XtPointer searchData) { Boolean updated; /* Call the original search procedure to do the actual search */ (*OrigFileSearchProc)(w, searchData); /* Refreshing a list clears the keystroke history, even if no update. */ nKeystrokes = 0; XtVaGetValues(w, XmNlistUpdated, &updated, NULL); if (!updated) return; /* Sort the items in the list */ sortWidgetList(XmFileSelectionBoxGetChild(w, XmDIALOG_LIST)); }
static void BrowseOkCallback(Widget w, Widget fp, XmFileSelectionBoxCallbackStruct *cbs) { Widget FSB_TextField; String Value; #ifdef DEBUG printf("%s:BrowseOkCallback(%d) - %s %s\n", __FILE__, __LINE__, XtName(w), XtName(fp)); #endif FSB_TextField = XmFileSelectionBoxGetChild(w, XmDIALOG_TEXT); Value = XmTextFieldGetString(FSB_TextField); XmTextFieldSetString(FilePicker_TextField(fp), Value); XmTextFieldSetInsertionPosition(FilePicker_TextField(fp), XmTextFieldGetLastPosition(FilePicker_TextField(fp))); XtFree(Value); XtUnmanageChild(w); }
int main(int argc, char *argv[]) { XtAppContext app_context; Widget toplevel = XtAppInitialize(&app_context, "Test-file", XtPointer(0), 0, &argc, argv, 0, XtPointer(0), 0); Widget box = XmCreateFileSelectionBox(toplevel, "open_file", 0, 0); XtManageChild(box); Widget help = XmFileSelectionBoxGetChild(box, XmDIALOG_HELP_BUTTON); XtSetSensitive(help, False); XtAddCallback(box, XmNokCallback, echoCB, 0); XtAddCallback(box, XmNcancelCallback, doneCB, 0); XtRealizeWidget(toplevel); XtAppMainLoop(app_context); return EXIT_SUCCESS; }
void create_workingdir_popup(Widget w, XtPointer, XtPointer) { XmString str; set_wait_cursor(); if (workingd_dialog == NULL) { workingd_dialog = XmCreateFileSelectionDialog(app_shell, (char *)"workingd_dialog", NULL, 0); XtVaSetValues(XtParent(workingd_dialog), XmNtitle, "Set working directory", NULL); XtAddCallback(workingd_dialog, XmNcancelCallback, (XtCallbackProc)destroy_dialog, (XtPointer)workingd_dialog); XtAddCallback(workingd_dialog, XmNokCallback, (XtCallbackProc)workingdir_apply_notify_proc, (XtPointer)0); /* unmanage unneeded items */ w = XmFileSelectionBoxGetChild(workingd_dialog, XmDIALOG_LIST); XtUnmanageChild(XtParent(w)); w = XmFileSelectionBoxGetChild(workingd_dialog, XmDIALOG_LIST_LABEL); XtUnmanageChild(w); w = XmFileSelectionBoxGetChild(workingd_dialog, XmDIALOG_FILTER_LABEL); XtUnmanageChild(w); w = XmFileSelectionBoxGetChild(workingd_dialog, XmDIALOG_FILTER_TEXT); XtUnmanageChild(w); w = XmFileSelectionBoxGetChild(workingd_dialog, XmDIALOG_APPLY_BUTTON); XtUnmanageChild(w); /* save the name of the text item used for definition */ dir_item = XmFileSelectionBoxGetChild(workingd_dialog, XmDIALOG_TEXT); /* Add a callback to the dir list */ w = XmFileSelectionBoxGetChild(workingd_dialog, XmDIALOG_DIR_LIST); XtAddCallback(w, XmNsingleSelectionCallback, (XtCallbackProc)select_dir, (XtPointer)0); XtVaSetValues(w, XmNselectionPolicy, XmSINGLE_SELECT, NULL); } xv_setstr(dir_item, workingdir); XtVaSetValues(workingd_dialog, XmNdirectory, str = XmStringCreateLtoR(workingdir, charset), NULL); XmFileSelectionDoSearch(workingd_dialog, NULL); XmStringFree(str); XtRaise(workingd_dialog); unset_wait_cursor(); }
void getbdffn(Exc_data * ed) { Widget filesb; Arg args[20]; Cardinal n; char *selectlabel; XmString xms; selectlabel = GETMESSAGE(2, 2, "BDF file selection"); n = 0; XtSetArg(args[n], XmNtitle, maintitle); n++; xms = XmStringCreateLocalized(selectlabel); XtSetArg(args[n], XmNselectionLabelString, xms); n++; filesb = XmCreateFileSelectionDialog(ed->toplevel, "filesb", args, n); XtAddCallback(filesb, XmNokCallback, (XtCallbackProc) filesbokCB, (XtPointer) ed); XtAddCallback(filesb, XmNcancelCallback, (XtCallbackProc) filesbcancelCB, (XtPointer) ed); XtUnmanageChild(XmFileSelectionBoxGetChild(filesb, XmDIALOG_HELP_BUTTON)); XtManageChild(filesb); }
void text_save(Widget w, XtPointer client_data, XtPointer call_data) { Widget child; char *ptr, bufr[256], nam1[256]; XmString namx; if (!savetextdialog) { savetextdialog = XmCreateFileSelectionDialog(GetTopShell(w), "textfile", NULL, 0); /* Get rid of Help button */ XtUnmanageChild(XmSelectionBoxGetChild(savetextdialog, XmDIALOG_HELP_BUTTON)); XtAddCallback(savetextdialog, XmNokCallback, get_textfile, NULL); XtAddCallback(savetextdialog, XmNcancelCallback, (XtCallbackProc)XtUnmanageChild, NULL); child = XmFileSelectionBoxGetChild(savetextdialog, XmDIALOG_TEXT); XtVaGetValues(child, XmNvalue, &ptr, NULL); } namx = XmStringCreateLocalized(raobsavefilename); printf( "Setting Default Output File Name = %s\n", raobsavefilename); XtVaSetValues( savetextdialog, XmNdirSpec, namx); XtManageChild(savetextdialog); XtPopup(XtParent(savetextdialog), XtGrabNone); }
/* * File selection box callback */ void openCB(Widget w,int client_data,XmFileSelectionBoxCallbackStruct *call_data) { if (client_data==DIALOG_CANCEL) { /* do nothing if cancel is selected. */ XtUnmanageChild(open_dialog); return; } else if (client_data==DIALOG_ALL) { /* Add all the listed files */ Arg al[10]; int ac; Widget the_list; int nbfile; XmStringTable files; int i; the_list=XmFileSelectionBoxGetChild(open_dialog,XmDIALOG_LIST); if (!XmIsList(the_list)) { printf("PANIC: List are not what they used to be\n"); exit; } ac=0; XtSetArg(al[ac], XmNitemCount, &nbfile); ac++; XtSetArg(al[ac], XmNitems, &files); ac++; XtGetValues(the_list, al, ac); for (i=0;i<nbfile;i++) XmListAddItemUnselected(file_list,files[i],0); } else { /* get filename from file selection box and add it to the list*/ XmListAddItemUnselected(file_list,call_data->value,0); XtUnmanageChild(open_dialog); } }
/* ARGSUSED */ void LocalProduct_Callback ( Widget w, long which, XmFileSelectionBoxCallbackStruct *call ) { Widget list; int itemc; /*---------------------------------------------------------------------*/ switch( which ) { case 0: /* ok callback (select) */ OpenModel = 1; Select_File_Callback( local_toplevel, NULL, call); XtManageChild( group_select_toplevel ); break; case 1: /* cancel callback (close) */ XtUnmanageChild( local_toplevel ); break; case 2: /* apply callback ( update model ) */ list = XmFileSelectionBoxGetChild( local_toplevel, XmDIALOG_LIST); XtVaGetValues(list, XmNitemCount, &itemc, NULL); XmListDeselectAllItems(list); XmFileSelectionDoSearch( local_toplevel, call->mask); XmListSetHorizPos(list, call->dir_length); XtVaSetValues(list, XmNitemCount, itemc, NULL); break; } }
void pglpfw_create ( Widget parent ) /************************************************************************ * pglpfw_create * * * * This function creates a file selection dialog box. * * * * void pglpfw_create ( parent ) * * * * Input parameters: * * parent Widget Parent widget * * * * Output parameters: * * Return parameters: * * NONE * * * ** * * * * T. Lee/SAIC 04/02 Created * * T. Piper/SAIC 10/05 declared ii & nn long * ***********************************************************************/ { int toff = 5, ier; long ii, nn; char *open_btnstr[] = {"Open", "Cancel"}; char *sort_str[] = {"Name", "Date"}; Widget pane, label, frame, sort_label; Arg args[10]; Cardinal argcnt; XmString xmpattern; XmStringTable xmfils; /*---------------------------------------------------------------------*/ _fileSelW = XmCreateFormDialog( parent, "Open product", NULL, 0 ); XtVaSetValues(_fileSelW, XmNdialogStyle, XmDIALOG_APPLICATION_MODAL, NULL); /* * create a parent pane widget */ pane = XtVaCreateWidget("pglpfw_pane", xmPanedWindowWidgetClass, _fileSelW, XmNsashWidth, 1, XmNsashHeight, 1, NULL); /* * ******** SORT PANE ******** * create a form widget to hold the sort by toggles */ _sortPaneW = XtVaCreateWidget("pglpfw_form", xmFormWidgetClass, pane, XmNnoResize, TRUE, XmNautoUnmanage, FALSE, XmNfractionBase, 110, NULL ); sort_label = XmCreateLabel( _sortPaneW, "Display Files In Order By:", NULL, 0 ); XtVaSetValues( sort_label, XmNtopAttachment, XmATTACH_POSITION, XmNtopPosition, 2, XmNleftAttachment, XmATTACH_POSITION, XmNleftPosition, 1, XmNrightAttachment, XmATTACH_POSITION, XmNrightPosition, 60, NULL ); XtManageChild( sort_label ); _sortRadioW = XtVaCreateManagedWidget ("sort_radio", xmRowColumnWidgetClass, _sortPaneW, XmNorientation, XmVERTICAL, XmNradioBehavior, True, XmNtopAttachment, XmATTACH_WIDGET, XmNtopWidget, sort_label, XmNrightAttachment, XmATTACH_FORM, XmNleftAttachment, XmATTACH_FORM, NULL); nn = XtNumber (sort_str); _sortBy = SORT_BY_NAME; _sortBtn = (WidgetList)XtMalloc(nn*sizeof(Widget)); for (ii = 0; ii < nn; ii++) { _sortBtn[ii] = XtVaCreateManagedWidget (sort_str[ii], xmToggleButtonWidgetClass, _sortRadioW, XmNtraversalOn, FALSE, NULL); XtAddCallback(_sortBtn[ii], XmNdisarmCallback, pglpfw_sortByCb, (XtPointer) ii); XmToggleButtonSetState (_sortBtn[ii], (_sortBy == ii), FALSE); } XtManageChild(_sortPaneW); /* * ******** SELECT PANE ******** * create a form widget to hold the directory and file lists */ _selectPaneW = XtVaCreateWidget("pglpfw_selectform", xmFormWidgetClass, pane, NULL); XtVaSetValues( _selectPaneW, XmNnoResize, TRUE, XmNautoUnmanage, FALSE, NULL ); /* * create the directory list */ label = XmCreateLabel( _selectPaneW, "Select directory:", NULL, 0 ); XtManageChild( label ); XtVaSetValues( label, XmNtopAttachment, XmATTACH_POSITION, XmNtopPosition, 2, XmNleftAttachment, XmATTACH_POSITION, XmNleftPosition, 1, XmNrightAttachment, XmATTACH_POSITION, XmNrightPosition, 60, NULL ); frame = XmCreateFrame( _selectPaneW, "_DirSel_frameW", NULL, 0 ); XtVaSetValues( frame, XmNtopAttachment, XmATTACH_WIDGET, XmNtopWidget, label, XmNrightAttachment, XmATTACH_FORM, XmNleftAttachment, XmATTACH_FORM, NULL ); _dirSel_listW = XmCreateScrolledList( frame, "_DirSel_lstW", NULL, 0 ); XtVaSetValues( _dirSel_listW, XmNvisibleItemCount, VISIBLE_ITEM, NULL ); XtAddCallback( _dirSel_listW, XmNbrowseSelectionCallback, pglpfw_selectDirCb, NULL ); pglpfw_readUsrTbl("lpf.nmap", &_lpfUsrTbl, &ier); if (_lpfUsrTbl.nitems > 0) { xmfils = (XmStringTable) XtMalloc (_lpfUsrTbl.nitems * sizeof (XmString *)); for (ii = 0; ii < _lpfUsrTbl.nitems; ii++) { xmfils[ii] = XmStringCreateLocalized (_lpfUsrTbl.items[ii].title); } XtVaSetValues (_dirSel_listW, XmNitems, xmfils, XmNitemCount, _lpfUsrTbl.nitems, NULL); for (ii = 0; ii < _lpfUsrTbl.nitems; ii++) { XmStringFree (xmfils[ii]); } XtFree ((XtPointer) xmfils); /* * hi-light the local directory */ _dirPos = _lpfUsrTbl.nitems; } XtManageChild( _dirSel_listW ); XtManageChild( frame ); /* * create the file list */ label = XmCreateLabel( _selectPaneW, "Select layer product file:", NULL, 0 ); XtManageChild (label ); XtVaSetValues (label, XmNtopAttachment, XmATTACH_WIDGET, XmNtopWidget, frame, XmNtopOffset, toff, XmNleftAttachment, XmATTACH_POSITION, XmNleftPosition, 1, XmNrightAttachment, XmATTACH_POSITION, XmNrightPosition, 60, NULL ); frame = XmCreateFrame( _selectPaneW, "_FileSel_frameW", NULL, 0 ); XtVaSetValues (frame, XmNtopAttachment, XmATTACH_WIDGET, XmNtopWidget, label, XmNrightAttachment, XmATTACH_FORM, XmNleftAttachment, XmATTACH_FORM, NULL); _fileSel_listW = XmCreateScrolledList (frame, "_FileSel_lstW", NULL, 0); XtVaSetValues (_fileSel_listW, XmNvisibleItemCount, VISIBLE_ITEM, NULL); XtAddCallback (_fileSel_listW, XmNbrowseSelectionCallback, pglpfw_selectCb, NULL); XtManageChild (_fileSel_listW); XtManageChild (frame); XtManageChild(_selectPaneW); /* * ******** BROWSE PANE ******** */ _browseBtnPane = XtVaCreateManagedWidget ("Browse", xmPushButtonWidgetClass, pane, NULL); XtAddCallback(_browseBtnPane, XmNarmCallback, pglpfw_browseBtnCb, (XtPointer) NULL); /* * ******** OPEN CONTROL PANE ******** */ _openPaneW = (Widget) NxmCtlBtn_create (pane, 1, "pglpfw_open", XtNumber(open_btnstr), open_btnstr, (XtCallbackProc)pglpfw_openCtlBtnCb, NULL); XtManageChild(pane); /* * browse popup */ argcnt = 0; xmpattern = XmStringCreateLocalized(FILE_PATTERN); XtSetArg (args[argcnt], XmNpattern, xmpattern); argcnt++; XtSetArg (args[argcnt], XmNtitle, "Browse"); argcnt++; _browsePopup = XmCreateFileSelectionDialog(parent, "browseBox", args, argcnt); XmStringFree(xmpattern); XtAddCallback(_browsePopup, XmNcancelCallback, pglpfw_browseDoneCb, (XtPointer) 0); XtAddCallback(_browsePopup, XmNokCallback, pglpfw_browseDoneCb, (XtPointer) 1); XtUnmanageChild(XmFileSelectionBoxGetChild(_browsePopup, XmDIALOG_HELP_BUTTON)); }
XSilChessWindow::XSilChessWindow(XtAppContext app, Widget toplevel, Visual * vsl, int vsldepth, Colormap cmap) { char tmp[512]; Arg al[10]; int i; XmString xms; // Initialize member variables App=app; TopLevel=toplevel; Disp=XtDisplay(TopLevel); Vsl=vsl; VslDepth=vsldepth; CMap=cmap; DlgVsl=DefaultVisual(Disp,XScreenNumberOfScreen(XtScreen(TopLevel))); DlgVslDepth=DefaultDepth(Disp,XScreenNumberOfScreen(XtScreen(TopLevel))); DlgCMap=DefaultColormap(Disp,XScreenNumberOfScreen(XtScreen(TopLevel))); PixelSize=(VslDepth<=8 ? 1 : (VslDepth<=16 ? 2 : 4)); RedMask=Vsl->red_mask; GreenMask=Vsl->green_mask; BlueMask=Vsl->blue_mask; SelX=SelY-1; IsSearching=false; AbortSearching=false; NeedPainting=false; IsPainting=false; HintWanted=false; HintValid=false; // Create main window MainWin=XtVaCreateManagedWidget( "mainWin",xmMainWindowWidgetClass,TopLevel, (char*)NULL ); // Create main menu bar MainMenu=XmCreateMenuBar(MainWin,(char*)"mainMenu",NULL,0); XtManageChild(MainMenu); // Create menu item: file XtSetArg(al[0],XmNvisual,Vsl); XtSetArg(al[1],XmNdepth,VslDepth); XtSetArg(al[2],XmNcolormap,CMap); FileMenu=XmCreatePulldownMenu(MainMenu,(char*)"fileMenu",al,3); BFile=XtVaCreateManagedWidget( "file",xmCascadeButtonWidgetClass,MainMenu, XmNsubMenuId,FileMenu, (char*)NULL ); // Create menu item: file/load BFileLoad=XtVaCreateManagedWidget( "load",xmPushButtonWidgetClass,FileMenu, (char*)NULL ); XtAddCallback(BFileLoad,XmNactivateCallback,HandleCallback,this); // Create menu item: file/save BFileSave=XtVaCreateManagedWidget( "save",xmPushButtonWidgetClass,FileMenu, (char*)NULL ); XtAddCallback(BFileSave,XmNactivateCallback,HandleCallback,this); // Create menu item: file/exit XtVaCreateManagedWidget( "separator",xmSeparatorWidgetClass,FileMenu, (char*)NULL ); BFileExit=XtVaCreateManagedWidget( "exit",xmPushButtonWidgetClass,FileMenu, (char*)NULL ); XtAddCallback(BFileExit,XmNactivateCallback,HandleCallback,this); // Create menu item: game XtSetArg(al[0],XmNvisual,Vsl); XtSetArg(al[1],XmNdepth,VslDepth); XtSetArg(al[2],XmNcolormap,CMap); GameMenu=XmCreatePulldownMenu(MainMenu,(char*)"gameMenu",al,3); BGame=XtVaCreateManagedWidget( "game",xmCascadeButtonWidgetClass,MainMenu, XmNsubMenuId,GameMenu, (char*)NULL ); // Create menu item: game/new BGameNew=XtVaCreateManagedWidget( "new",xmPushButtonWidgetClass,GameMenu, (char*)NULL ); XtAddCallback(BGameNew,XmNactivateCallback,HandleCallback,this); // Create menu item: game/flip BGameFlip=XtVaCreateManagedWidget( "flip",xmPushButtonWidgetClass,GameMenu, (char*)NULL ); XtAddCallback(BGameFlip,XmNactivateCallback,HandleCallback,this); // Create menu item: game/undo BGameUndo=XtVaCreateManagedWidget( "undo",xmPushButtonWidgetClass,GameMenu, (char*)NULL ); XtAddCallback(BGameUndo,XmNactivateCallback,HandleCallback,this); // Create menu item: game/list BGameList=XtVaCreateManagedWidget( "list",xmPushButtonWidgetClass,GameMenu, (char*)NULL ); XtAddCallback(BGameList,XmNactivateCallback,HandleCallback,this); // Create menu item: computer XtSetArg(al[0],XmNvisual,Vsl); XtSetArg(al[1],XmNdepth,VslDepth); XtSetArg(al[2],XmNcolormap,CMap); CompMenu=XmCreatePulldownMenu(MainMenu,(char*)"compMenu",al,3); BComp=XtVaCreateManagedWidget( "comp",xmCascadeButtonWidgetClass,MainMenu, XmNsubMenuId,CompMenu, (char*)NULL ); // Create menu item: computer/hint BCompHint=XtVaCreateManagedWidget( "hint",xmPushButtonWidgetClass,CompMenu, (char*)NULL ); XtAddCallback(BCompHint,XmNactivateCallback,HandleCallback,this); // Create menu item: computer/depth XtSetArg(al[0],XmNvisual,Vsl); XtSetArg(al[1],XmNdepth,VslDepth); XtSetArg(al[2],XmNcolormap,CMap); XtSetArg(al[3],XmNradioBehavior,True); DepthMenu=XmCreatePulldownMenu(CompMenu,(char*)"depthMenu",al,4); BCompDepth=XtVaCreateManagedWidget( "depth",xmCascadeButtonWidgetClass,CompMenu, XmNsubMenuId,DepthMenu, (char*)NULL ); // Create menu items: computer/depth/1... for (i=0; i<=SilChessMachine::MAX_SEARCH_DEPTH; i++) { sprintf(tmp,"%d",i); BDepth[i]=XtVaCreateManagedWidget( tmp,xmToggleButtonWidgetClass,DepthMenu, (char*)NULL ); XtAddCallback(BDepth[i],XmNvalueChangedCallback,HandleCallback,this); } // Create menu item: help XtSetArg(al[0],XmNvisual,Vsl); XtSetArg(al[1],XmNdepth,VslDepth); XtSetArg(al[2],XmNcolormap,CMap); HelpMenu=XmCreatePulldownMenu(MainMenu,(char*)"helpMenu",al,3); BHelp=XtVaCreateManagedWidget( "help",xmCascadeButtonWidgetClass,MainMenu, XmNsubMenuId,HelpMenu, (char*)NULL ); XtVaSetValues(MainMenu,XmNmenuHelpWidget,BHelp,(char*)NULL); // Create menu item: help/about BHelpAbout=XtVaCreateManagedWidget( "about",xmPushButtonWidgetClass,HelpMenu, (char*)NULL ); XtAddCallback(BHelpAbout,XmNactivateCallback,HandleCallback,this); // Create a parent for status bar and view MainForm=XtVaCreateManagedWidget( "mainForm",xmFormWidgetClass,MainWin, (char*)NULL ); // Create status line StatusFrame=XtVaCreateManagedWidget( "statusFrame",xmFrameWidgetClass,MainForm, XmNleftAttachment,XmATTACH_FORM, XmNrightAttachment,XmATTACH_FORM, XmNtopAttachment,XmATTACH_FORM, (char*)NULL ); StatusLabel=XtVaCreateManagedWidget( "statusLabel",xmLabelWidgetClass,StatusFrame, XmNalignment, XmALIGNMENT_BEGINNING, (char*)NULL ); // Create the chess board view ViewFrame=XtVaCreateManagedWidget( "viewFrame",xmFrameWidgetClass,MainForm, XmNtopAttachment,XmATTACH_WIDGET, XmNtopWidget,StatusFrame, XmNleftAttachment,XmATTACH_FORM, XmNrightAttachment,XmATTACH_FORM, XmNbottomAttachment,XmATTACH_FORM, (char*)NULL ); ViewArea=XtVaCreateManagedWidget( "viewArea",xmDrawingAreaWidgetClass,ViewFrame, XmNtopAttachment,XmATTACH_FORM, XmNleftAttachment,XmATTACH_FORM, XmNrightAttachment,XmATTACH_FORM, XmNbottomAttachment,XmATTACH_FORM, (char*)NULL ); XtAddCallback(ViewArea,XmNexposeCallback,HandleCallback,this); XtAddCallback(ViewArea,XmNresizeCallback,HandleCallback,this); XtAddEventHandler( ViewArea,ButtonPressMask|ButtonMotionMask|ButtonReleaseMask| StructureNotifyMask,False,HandleEvent,this ); XtVaGetValues(ViewArea,XmNwidth,&ViewWidth,(char*)NULL); XtVaGetValues(ViewArea,XmNheight,&ViewHeight,(char*)NULL); ViewWin=0; ViewGC=NULL; // Create dialog: load game XtSetArg(al[0],XmNvisual,DlgVsl); XtSetArg(al[1],XmNdepth,DlgVslDepth); XtSetArg(al[2],XmNcolormap,DlgCMap); XtSetArg(al[3],XmNautoUnmanage,True); LoadDialog=XmCreateFileSelectionDialog(TopLevel,(char*)"loadDialog",al,4); XtAddCallback(LoadDialog,XmNokCallback,HandleCallback,this); XtUnmanageChild(XmFileSelectionBoxGetChild(LoadDialog,XmDIALOG_HELP_BUTTON)); // Create dialog: save game XtSetArg(al[0],XmNvisual,DlgVsl); XtSetArg(al[1],XmNdepth,DlgVslDepth); XtSetArg(al[2],XmNcolormap,DlgCMap); XtSetArg(al[3],XmNautoUnmanage, True); SaveDialog=XmCreateFileSelectionDialog(TopLevel,(char*)"saveDialog",al,4); XtAddCallback(SaveDialog,XmNokCallback,HandleCallback,this); XtUnmanageChild(XmFileSelectionBoxGetChild(SaveDialog,XmDIALOG_HELP_BUTTON)); // Create dialog: file exists, overwrite? XtSetArg(al[0],XmNvisual,DlgVsl); XtSetArg(al[1],XmNdepth,DlgVslDepth); XtSetArg(al[2],XmNcolormap,DlgCMap); XtSetArg(al[3],XmNautoUnmanage, True); OverwriteDialog=XmCreateWarningDialog(TopLevel,(char*)"overwriteDialog",al,4); XtUnmanageChild(XmMessageBoxGetChild(OverwriteDialog,XmDIALOG_HELP_BUTTON)); XtAddCallback(OverwriteDialog,XmNokCallback,HandleCallback,this); // Create dialog: error message XtSetArg(al[0],XmNvisual,DlgVsl); XtSetArg(al[1],XmNdepth,DlgVslDepth); XtSetArg(al[2],XmNcolormap,DlgCMap); XtSetArg(al[3],XmNautoUnmanage, True); ErrorBox=XmCreateWarningDialog(TopLevel,(char*)"errorBox",al,4); XtUnmanageChild(XmMessageBoxGetChild(ErrorBox,XmDIALOG_CANCEL_BUTTON)); XtUnmanageChild(XmMessageBoxGetChild(ErrorBox,XmDIALOG_HELP_BUTTON)); // Create dialog: list of moves ListDialogPopup=XtVaCreateWidget( "listDialog_popup",xmDialogShellWidgetClass,TopLevel, XmNvisual,DlgVsl, XmNdepth,DlgVslDepth, XmNcolormap,DlgCMap, (char*)NULL ); ListDialog=XtVaCreateWidget( "listDialog",xmFormWidgetClass,ListDialogPopup, (char*)NULL ); LDClose=XtVaCreateManagedWidget( "close",xmPushButtonWidgetClass,ListDialog, XmNleftAttachment,XmATTACH_FORM, XmNrightAttachment,XmATTACH_FORM, XmNbottomAttachment,XmATTACH_FORM, (char*)NULL ); XtAddCallback(LDClose,XmNactivateCallback,HandleCallback,this); LDScroll=XtVaCreateManagedWidget( "scroll",xmScrolledWindowWidgetClass,ListDialog, XmNscrollingPolicy,XmAUTOMATIC, XmNscrollBarDisplayPolicy,XmAS_NEEDED, XmNleftAttachment,XmATTACH_FORM, XmNrightAttachment,XmATTACH_FORM, XmNtopAttachment,XmATTACH_FORM, XmNbottomAttachment,XmATTACH_WIDGET, XmNbottomWidget,LDClose, (char*)NULL ); LDList=XtVaCreateManagedWidget( "list",xmLabelGadgetClass,LDScroll, XmNalignment,XmALIGNMENT_BEGINNING, (char*)NULL ); // Create dialog: about xms=XmStringCreateLtoR((char*)AboutText,XmFONTLIST_DEFAULT_TAG); XtSetArg(al[0],XmNvisual,DlgVsl); XtSetArg(al[1],XmNdepth,DlgVslDepth); XtSetArg(al[2],XmNcolormap,DlgCMap); XtSetArg(al[3],XmNautoUnmanage,True); XtSetArg(al[4],XmNmessageString,xms); XtSetArg(al[5],XmNmessageAlignment,XmALIGNMENT_CENTER); AboutDialog=XmCreateMessageDialog(TopLevel,(char*)"aboutDialog",al,6); XmStringFree(xms); XtUnmanageChild(XmMessageBoxGetChild(AboutDialog,XmDIALOG_CANCEL_BUTTON)); XtUnmanageChild(XmMessageBoxGetChild(AboutDialog,XmDIALOG_HELP_BUTTON)); // Set main window areas XmMainWindowSetAreas(MainWin,MainMenu,NULL,NULL,NULL,MainForm); // Create chess machine Machine = new SilChessMachine(); // Setup ray tracer RT.SetViewSize(ViewWidth,ViewHeight); RT.SetWorld(Machine); // Update all UpdateStatusBar(); UpdateMovesList(); UpdateView(); UpdateDepthMenu(); }
void XSilChessWindow::HandleCallbackOrEvent(Widget widget, XmAnyCallbackStruct * cbs, XEvent * event) { XGCValues gcval; const char * file_name; XmString xms; char tmp[512]; int i; if (widget==BFileLoad) { XtUnmanageChild(LoadDialog); XmFileSelectionDoSearch(LoadDialog,NULL); XtManageChild(LoadDialog); } else if (widget==BFileSave) { XtUnmanageChild(SaveDialog); XmFileSelectionDoSearch(SaveDialog,NULL); XtManageChild(SaveDialog); } else if (widget==BFileExit) { exit(0); } else if (widget==BGameNew) { AbortSearching=true; HintWanted=false; HintValid=false; Machine->StartNewGame(); RT.SetWorld(Machine); UpdateStatusBar(); UpdateMovesList(); UpdateView(); } else if (widget==BGameFlip) { AbortSearching=true; HintWanted=false; HintValid=false; Machine->SetHumanWhite(!Machine->IsHumanWhite()); RT.SetWorld(Machine); UpdateStatusBar(); UpdateView(); } else if (widget==BGameUndo) { AbortSearching=true; HintWanted=false; HintValid=false; Machine->UndoMove(); if (!Machine->IsHumanOn()) Machine->UndoMove(); RT.SetWorld(Machine); UpdateStatusBar(); UpdateMovesList(); UpdateView(); } else if (widget==BGameList) { XtUnmanageChild(ListDialog); XtManageChild(ListDialog); } else if (widget==LoadDialog) { AbortSearching=true; HintWanted=false; HintValid=false; file_name=XmTextGetString( XmFileSelectionBoxGetChild(widget,XmDIALOG_TEXT) ); if (!Machine->Load(file_name)) { XtUnmanageChild(ErrorBox); sprintf(tmp,"Failed to load '%s'",file_name); xms=XmStringCreateSimple(tmp); XtVaSetValues(ErrorBox,XmNmessageString,xms,(char*)NULL); XmStringFree(xms); XtManageChild(ErrorBox); } RT.SetWorld(Machine); UpdateStatusBar(); UpdateMovesList(); UpdateView(); UpdateDepthMenu(); } else if (widget==SaveDialog) { file_name=XmTextGetString( XmFileSelectionBoxGetChild(widget,XmDIALOG_TEXT) ); if (access(file_name,F_OK)!=-1) { XtUnmanageChild(OverwriteDialog); sprintf(tmp,"OK to overwrite '%s'?",file_name); xms=XmStringCreateSimple(tmp); XtVaSetValues(OverwriteDialog,XmNmessageString,xms,(char*)NULL); XmStringFree(xms); XtManageChild(OverwriteDialog); strcpy(OverwriteFile,file_name); } else if (!Machine->Save(file_name)) { XtUnmanageChild(ErrorBox); sprintf(tmp,"Failed to save '%s'",file_name); xms=XmStringCreateSimple(tmp); XtVaSetValues(ErrorBox,XmNmessageString,xms,(char*)NULL); XmStringFree(xms); XtManageChild(ErrorBox); } } else if (widget==OverwriteDialog) { file_name=OverwriteFile; if (!Machine->Save(file_name)) { XtUnmanageChild(ErrorBox); sprintf(tmp,"Failed to save '%s'",file_name); xms=XmStringCreateSimple(tmp); XtVaSetValues(ErrorBox,XmNmessageString,xms,(char*)NULL); XmStringFree(xms); XtManageChild(ErrorBox); } } else if (widget==ViewArea) { if (cbs!=NULL && cbs->reason==XmCR_EXPOSE && cbs->event && cbs->event->xexpose.count==0) { UpdateView(); } else if (cbs!=NULL && cbs->reason==XmCR_RESIZE) { XtVaGetValues(ViewArea,XmNwidth,&ViewWidth,(char*)NULL); XtVaGetValues(ViewArea,XmNheight,&ViewHeight,(char*)NULL); RT.SetViewSize(ViewWidth,ViewHeight); UpdateView(); } else if (event!=NULL && event->type==ButtonPress) { MousePress(event->xbutton.x,event->xbutton.y); } else if (event!=NULL && event->type==MapNotify && !ViewWin) { ViewWin=XtWindow(ViewArea); ViewGC=XtGetGC(ViewArea,0,&gcval); } } else if (widget==BCompHint) { AbortSearching=true; HintWanted=true; HintValid=false; UpdateStatusBar(); } else if (widget==BHelpAbout) { XtUnmanageChild(AboutDialog); XtManageChild(AboutDialog); } else if (widget==LDClose) { XtUnmanageChild(ListDialog); } else { for (i=0; i<=SilChessMachine::MAX_SEARCH_DEPTH; i++) { if (widget==BDepth[i] && cbs!=NULL) { if (((XmToggleButtonCallbackStruct*)cbs)->set) { AbortSearching=true; Machine->SetSearchDepth(i); UpdateStatusBar(); } } } } do { DoPainting(); DoSearching(); } while(NeedPainting && !IsPainting && ViewWin); }
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 motFileDlgCallback(Widget w, Ihandle* ih, XmFileSelectionBoxCallbackStruct* call_data) { (void)w; if (call_data->reason == XmCR_OK) { int dialogtype = iupAttribGetInt(ih, "_IUPDLG_DIALOGTYPE"); char* filename; XmStringGetLtoR(call_data->value, XmSTRING_DEFAULT_CHARSET, &filename); iupAttribStoreStr(ih, "VALUE", filename); XtFree(filename); if (!motFileDlgCheckValue(ih, w)) return; if (dialogtype == IUP_DIALOGDIR) { iupAttribSetStr(ih, "STATUS", "0"); iupAttribSetStr(ih, "FILEEXIST", NULL); } else if (iupAttribGetBoolean(ih, "MULTIPLEFILES")) { Widget wList = XmFileSelectionBoxGetChild(w, XmDIALOG_LIST); /* VALUE obtained above contains exactly the DIRECTORY */ char* dir = iupAttribGet(ih, "VALUE"); int len = strlen(dir); if (dir[len-1]=='/') dir[len-1] = 0; /* remove last '/' */ iupAttribStoreStr(ih, "DIRECTORY", dir); if (!motFileDlgGetMultipleFiles(ih, iupAttribGet(ih, "DIRECTORY"), wList)) { iupStrMessageShowError(ih, "IUP_FILENOTEXIST"); return; } iupAttribSetStr(ih, "STATUS", "0"); iupAttribSetStr(ih, "FILEEXIST", "YES"); } else { IFnss file_cb = (IFnss)IupGetCallback(ih, "FILE_CB"); filename = iupAttribGet(ih, "VALUE"); if (file_cb && file_cb(ih, filename, "OK") == IUP_IGNORE) return; if (iupdrvIsFile(filename)) /* check if file exists */ { char* dir = iupStrFileGetPath(filename); iupAttribStoreStr(ih, "DIRECTORY", dir); free(dir); iupAttribSetStr(ih, "FILEEXIST", "YES"); iupAttribSetStr(ih, "STATUS", "0"); } else { iupAttribSetStr(ih, "FILEEXIST", "NO"); iupAttribSetStr(ih, "STATUS", "1"); } } if (!iupAttribGetBoolean(ih, "NOCHANGEDIR")) /* do change the current directory */ { /* XmFileSelection does not change the current directory */ XmString xm_dir; char* dir; XtVaGetValues(w, XmNdirectory, &xm_dir, NULL); XmStringGetLtoR(xm_dir, XmSTRING_DEFAULT_CHARSET, &dir); iupdrvSetCurrentDirectory(dir); XtFree(dir); } } else if (call_data->reason == XmCR_CANCEL) { iupAttribSetStr(ih, "VALUE", NULL); iupAttribSetStr(ih, "FILEEXIST", NULL); iupAttribSetStr(ih, "STATUS", "-1"); } }
/* ** HandleCustomExistFileSB ** ** Manage a customized file selection box for opening existing files. ** Use this if you want to change the standard file selection dialog ** from the defaults provided in GetExistingFilename, but still ** want take advantage of the button processing, help messages, and ** file checking of GetExistingFilename. ** ** Arguments: ** ** Widget existFileSB - your custom file selection box widget id ** char * filename - a string to receive the selected filename ** (this string will not be altered if the ** user pressed the cancel button) ** ** Returns: GFN_OK - file was selected and OK button pressed ** GFN_CANCEL - Cancel button pressed and no returned file ** */ int HandleCustomExistFileSB(Widget existFileSB, char *filename) { Boolean done_with_dialog=False; /* ok to destroy dialog flag */ char *fileString; /* C string for file selected */ char *dirString; /* C string for dir of file selected */ XmString cFileString; /* compound string for file selected */ XmString cDir; /* compound directory selected */ XmString cPattern; /* compound filter pattern */ Widget help; /* help window form dialog */ #if XmVersion < 1002 int i; #endif XtAddCallback(existFileSB, XmNokCallback, (XtCallbackProc)existOkCB, &done_with_dialog); XtAddCallback(existFileSB, XmNcancelCallback, (XtCallbackProc)existCancelCB, &done_with_dialog); AddMotifCloseCallback(XtParent(existFileSB), (XtCallbackProc)existCancelCB, &done_with_dialog); help = createPanelHelp(existFileSB, HelpExist, "Selecting Files to Open"); createErrorDialog(existFileSB); XtAddCallback(existFileSB, XmNhelpCallback, (XtCallbackProc)existHelpCB, (char *)help); if (DefaultDirectory != NULL || DefaultPattern != NULL) XtVaSetValues(existFileSB, XmNdirectory, DefaultDirectory, XmNpattern, DefaultPattern, NULL); #ifndef SGI_CUSTOM makeListTypeable(XmFileSelectionBoxGetChild(existFileSB,XmDIALOG_LIST)); makeListTypeable(XmFileSelectionBoxGetChild(existFileSB,XmDIALOG_DIR_LIST)); #if XmVersion >= 1002 XtVaSetValues(existFileSB, XmNinitialFocus, XtParent( XmFileSelectionBoxGetChild(existFileSB, XmDIALOG_LIST)), NULL); #endif #endif ManageDialogCenteredOnPointer(existFileSB); #ifndef SGI_CUSTOM /* Typing in the directory list is dependent on the list being in the same form of alphabetical order expected by the character processing routines. As of about 1.2.3, some Motif libraries seem to have a different idea of ordering than is usual for Unix directories. To sort them properly, we have to patch the directory and file searching routines to re-sort the lists when they change */ XtVaGetValues(existFileSB, XmNdirSearchProc, &OrigDirSearchProc, XmNfileSearchProc, &OrigFileSearchProc, NULL); XtVaSetValues(existFileSB, XmNdirSearchProc, replacementDirSearchProc, XmNfileSearchProc, replacementFileSearchProc, NULL); sortWidgetList(XmFileSelectionBoxGetChild(existFileSB, XmDIALOG_DIR_LIST)); sortWidgetList(XmFileSelectionBoxGetChild(existFileSB, XmDIALOG_LIST)); #if XmVersion < 1002 /* To give file list initial focus, revoke default button status for the "OK" button. Dynamic defaulting will restore it as the default button after the keyboard focus is established. Note the voodoo below: calling XmProcess traversal extra times (a recommendation from OSF technical support) somehow succeedes in giving the file list focus */ XtVaSetValues(existFileSB, XmNdefaultButton, NULL, NULL); for (i=1; i<30; i++) XmProcessTraversal(XmFileSelectionBoxGetChild(existFileSB, XmDIALOG_LIST), XmTRAVERSE_CURRENT); #endif #endif /* SGI_CUSTOM */ while (!done_with_dialog) XtAppProcessEvent(XtWidgetToApplicationContext(existFileSB), XtIMAll); if (SelectResult == GFN_OK) { XtVaGetValues(existFileSB, XmNdirSpec, &cFileString, XmNdirectory, &cDir, XmNpattern, &cPattern, NULL); /* Undocumented: file selection box widget allocates copies of these strings on getValues calls. I have risked freeing them to avoid memory leaks, since I assume other developers have made this same realization, therefore OSF can't easily go back and change it */ if (DefaultDirectory != NULL) XmStringFree(DefaultDirectory); if (DefaultPattern != NULL) XmStringFree(DefaultPattern); DefaultDirectory = cDir; DefaultPattern = cPattern; XmStringGetLtoR(cFileString, XmSTRING_DEFAULT_CHARSET, &fileString); /* Motif 2.x seem to contain a bug that causes it to return only the relative name of the file in XmNdirSpec when XmNpathMode is set to XmPATH_MODE_RELATIVE (through X resources), although the man page states that it always returns the full path name. We can easily work around this by checking that the first character of the file name is a `/'. */ #ifdef VMS /* VMS won't return `/' as the 1st character of the full file spec. `:' terminates the device name and is not allowed elsewhere */ if (strchr(fileString, ':') != NULL) { #else if (fileString[0] == '/') { #endif /* VMS */ /* The directory name is already present in the file name or the user entered a full path name. */ strcpy(filename, fileString); } else { /* Concatenate the directory name and the file name */ XmStringGetLtoR(cDir, XmSTRING_DEFAULT_CHARSET, &dirString); strcpy(filename, dirString); strcat(filename, fileString); XtFree(dirString); } XmStringFree(cFileString); XtFree(fileString); } /* Destroy the dialog _shell_ iso. the dialog. Normally, this shouldn't be necessary as the shell is destroyed automatically when the dialog is. However, due to a bug in various Lesstif versions, the latter messes up the grab cascades and leaves new windows without grabs, such that they appear to be frozen. */ XtDestroyWidget(XtParent(existFileSB)); return SelectResult; } /* ** HandleCustomNewFileSB ** ** Manage a customized file selection box for opening new files. ** ** Arguments: ** ** Widget newFileSB - your custom file selection box widget id ** char * filename - a string to receive the selected filename ** (this string will not be altered if the ** user pressed the cancel button) ** char* defaultName - default name to be pre-entered in filename ** text field. ** ** Returns: GFN_OK - file was selected and OK button pressed ** GFN_CANCEL - Cancel button pressed and no returned file ** */ int HandleCustomNewFileSB(Widget newFileSB, char *filename, char *defaultName) { Boolean done_with_dialog=False; /* ok to destroy dialog flag */ Widget help; /* help window form dialog */ XmString cFileString; /* compound string for file selected */ XmString cDir; /* compound directory selected */ XmString cPattern; /* compound filter pattern */ char *fileString; /* C string for file selected */ char *dirString; /* C string for dir of file selected */ #if XmVersion < 1002 int i; #endif XtAddCallback(newFileSB, XmNokCallback, (XtCallbackProc)newFileOKCB, &done_with_dialog); XtAddCallback(newFileSB, XmNcancelCallback, (XtCallbackProc)newFileCancelCB, &done_with_dialog); #ifndef SGI_CUSTOM makeListTypeable(XmFileSelectionBoxGetChild(newFileSB,XmDIALOG_LIST)); makeListTypeable(XmFileSelectionBoxGetChild(newFileSB,XmDIALOG_DIR_LIST)); #endif if (DefaultDirectory != NULL || DefaultPattern != NULL) XtVaSetValues(newFileSB, XmNdirectory, DefaultDirectory, XmNpattern, DefaultPattern, NULL); help = createPanelHelp(newFileSB, HelpNew, "Saving a File"); createYesNoDialog(newFileSB); createErrorDialog(newFileSB); XtAddCallback(newFileSB, XmNhelpCallback, (XtCallbackProc)newHelpCB, (char *)help); if (defaultName != NULL) { Widget nameField = XmFileSelectionBoxGetChild(newFileSB, XmDIALOG_TEXT); XmTextInsert(nameField, XmTextGetLastPosition(nameField), defaultName); } #if XmVersion >= 1002 #ifndef SGI_CUSTOM XtVaSetValues(newFileSB, XmNinitialFocus, XmFileSelectionBoxGetChild(newFileSB, XmDIALOG_TEXT), NULL); #else /* SGI_CUSTOM */ { Widget finder = XmFileSelectionBoxGetChild(newFileSB, SgDIALOG_FINDER); if ( finder != NULL ) XtVaSetValues(newFileSB, XmNinitialFocus, finder, NULL); } #endif #endif ManageDialogCenteredOnPointer(newFileSB); #ifndef SGI_CUSTOM #if XmVersion < 1002 /* To give filename text initial focus, revoke default button status for the "OK" button. Dynamic defaulting will restore it as the default button after the keyboard focus is established. Note the voodoo below: calling XmProcess traversal FOUR times (a recommendation from OSF technical support) somehow succeedes in changing the focus */ XtVaSetValues(newFileSB, XmNdefaultButton, NULL, NULL); for (i=1; i<30; i++) XmProcessTraversal(XmFileSelectionBoxGetChild(newFileSB, XmDIALOG_TEXT), XmTRAVERSE_CURRENT); #endif /* Typing in the directory list is dependent on the list being in the same form of alphabetical order expected by the character processing routines. As of about 1.2.3, some Motif libraries seem to have a different idea of ordering than is usual for Unix directories. To sort them properly, we have to patch the directory and file searching routines to re-sort the lists when they change */ XtVaGetValues(newFileSB, XmNdirSearchProc, &OrigDirSearchProc, XmNfileSearchProc, &OrigFileSearchProc, NULL); XtVaSetValues(newFileSB, XmNdirSearchProc, replacementDirSearchProc, XmNfileSearchProc, replacementFileSearchProc, NULL); sortWidgetList(XmFileSelectionBoxGetChild(newFileSB, XmDIALOG_DIR_LIST)); sortWidgetList(XmFileSelectionBoxGetChild(newFileSB, XmDIALOG_LIST)); #endif /* SGI_CUSTOM */ while (!done_with_dialog) XtAppProcessEvent (XtWidgetToApplicationContext(newFileSB), XtIMAll); if (SelectResult == GFN_OK) { /* See note in existing file routines about freeing the values obtained in the following call */ XtVaGetValues(newFileSB, XmNdirSpec, &cFileString, XmNdirectory, &cDir, XmNpattern, &cPattern, NULL); if (DefaultDirectory != NULL) XmStringFree(DefaultDirectory); if (DefaultPattern != NULL) XmStringFree(DefaultPattern); DefaultDirectory = cDir; DefaultPattern = cPattern; XmStringGetLtoR(cFileString, XmSTRING_DEFAULT_CHARSET, &fileString); /* See note in existing file routines about Motif 2.x bug. */ #ifdef VMS /* VMS won't return `/' as the 1st character of the full file spec. `:' terminates the device name and is not allowed elsewhere */ if (strchr(fileString, ':') != NULL) { #else if (fileString[0] == '/') { #endif /* VMS */ /* The directory name is already present in the file name or the user entered a full path name. */ strcpy(filename, fileString); } else { /* Concatenate the directory name and the file name */ XmStringGetLtoR(cDir, XmSTRING_DEFAULT_CHARSET, &dirString); strcpy(filename, dirString); strcat(filename, fileString); XtFree(dirString); } XmStringFree(cFileString); XtFree(fileString); } XtDestroyWidget(newFileSB); return SelectResult; } /* ** Return current default directory used by GetExistingFilename. ** Can return NULL if no default directory has been set (meaning ** use the application's current working directory) String must ** be freed by the caller using XtFree. */ char *GetFileDialogDefaultDirectory(void) { char *string; if (DefaultDirectory == NULL) return NULL; XmStringGetLtoR(DefaultDirectory, XmSTRING_DEFAULT_CHARSET, &string); return string; }
void create_local_products ( Widget parent ) { Arg args[10]; Cardinal argcnt, ii; struct stat buf; char *default_dir, name[150]; Widget ignorew; XmStringTable xmstr; /*---------------------------------------------------------------------*/ /* Create a popup shell & list widget for the file list. */ default_dir = (char *)getenv("HOME"); strcpy(name, default_dir); strcat(name , "/meta"); if ( lstat(name , &buf ) != 0 ) return; xmstr = (XmStringTable)XtMalloc(5*sizeof(XmString *)); argcnt = 0; xmstr[argcnt] = XmStringCreateLocalized("Local Products"); XtSetArg(args[argcnt], XmNtitle, xmstr[argcnt]); argcnt++; xmstr[argcnt] = XmStringCreateLocalized("Update"); XtSetArg(args[argcnt], XmNapplyLabelString, xmstr[argcnt]); argcnt++; xmstr[argcnt] = XmStringCreateLocalized("Close"); XtSetArg(args[argcnt], XmNcancelLabelString, xmstr[argcnt]); argcnt++; xmstr[argcnt] = XmStringCreateLocalized(name); XtSetArg(args[argcnt], XmNdirectory, xmstr[argcnt]); argcnt++; xmstr[argcnt] = XmStringCreateLocalized("Select"); XtSetArg(args[argcnt], XmNokLabelString, xmstr[argcnt]); argcnt++; local_toplevel = XmCreateFileSelectionDialog(parent, "LocalProduct",args,argcnt); for ( ii = 0; ii < argcnt; ii++ ) { XmStringFree( xmstr[ ii ] ); } XtFree((XtPointer)xmstr); ignorew = XmFileSelectionBoxGetChild(local_toplevel, XmDIALOG_HELP_BUTTON); XtUnmanageChild(ignorew); ignorew = XmFileSelectionBoxGetChild(local_toplevel, XmDIALOG_DIR_LIST); XtUnmanageChild(ignorew); ignorew = XmFileSelectionBoxGetChild(local_toplevel, XmDIALOG_TEXT); XtUnmanageChild(ignorew); ignorew = XmFileSelectionBoxGetChild(local_toplevel, XmDIALOG_SELECTION_LABEL); XtUnmanageChild(ignorew); ignorew = XmFileSelectionBoxGetChild(local_toplevel, XmDIALOG_FILTER_TEXT); XtUnmanageChild(ignorew); ignorew = XmFileSelectionBoxGetChild(local_toplevel, XmDIALOG_FILTER_LABEL); XtUnmanageChild(ignorew); ignorew = XmFileSelectionBoxGetChild(local_toplevel, XmDIALOG_DIR_LIST_LABEL); XtUnmanageChild(ignorew); XtAddCallback(local_toplevel, XmNokCallback, (XtCallbackProc)LocalProduct_Callback, (XtPointer)0); XtAddCallback(local_toplevel, XmNcancelCallback, (XtCallbackProc)LocalProduct_Callback, (XtPointer)1); XtAddCallback(local_toplevel, XmNapplyCallback, (XtCallbackProc)LocalProduct_Callback, (XtPointer)2); }