Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uwm.edu!bionet!agate!ucbvax!MODAL375.ME.VT.EDU!hildjj From: hildjj@MODAL375.ME.VT.EDU (Joe Hildebrand) Newsgroups: comp.windows.x.motif Subject: XmFileSelectionBoxes in 1.1 & 1.0 Message-ID: <9103232013.AA12988@BU.EDU> Date: 23 Mar 91 20:14:22 GMT Sender: daemon@ucbvax.BERKELEY.EDU Distribution: inet Organization: The Internet Lines: 92 > Message-Id: > I have a couple of problems with the FileSelectionBox that I can't seem to > get around. Perhaps someone in-the-know can help me out. > 2. Is there any way to get a CallBack invoked when a file or directory > is selected (as opposed to when the OK or Filter buttons are pressed, > or the file/directory is double-clicked)? I'd like to set some other > values in the user interface based upon the file the user is > "considering". I'm using Motif 1.0.? (since HP does not see fit to ship an upgrade until this FALL!) But this should work for your second question. void create_file_box(parent) Widget parent; { Widget text, file_box; file_box = XmCreateSelectionBox(parent, "File Box", NULL, 0); XtManageChild(file_box); XtAddCallback(file_box, XmNokCallback, validate_selection, parent); XtAddCallback(parent, XmNactivateCallback, show_file_box_CB, file_box); text = XmFileSelectionBoxGetChild(file_box, XmDIALOG_TEXT); XtAddCallback(text, XmNvalueChangedCallback, new_file_CB, NULL); } additionally, the FAQ says that file selection boxes don't work in 1.0. I have a work-around. Before popping up an XmFileSelectionDialog, change to the directory you want. When a file is selected, check if it is a directory, so that we can change to it. i.e. static void show_file_box_CB(w, client_data, call_data) Widget w; Widget client_data; XmAnyCallbackStruct *call_data; { chdir("/users/hildjj/files"); XtManageChild(client_data); } static void val_save(w, client_data, call_data) Widget w; Widget client_data; XmSelectionBoxCallbackStruct *call_data; { struct stat buf; /* struct stat is defined in stat.h */ char *filename; /* get the file name from the FileSelectionBox */ filename = SmX(call_data->value); /* get the status of the file named filename, and put it into buf */ if (!stat(filename, &buf)) { /* if it's a directory */ if(S_ISDIR(buf.st_mode)) { /* change to that directory, and update the FileSelectionBox */ chdir(filename); XmFileSelectionDoSearch(w, NULL); } else /* if it's a regualr file */ if(S_ISREG(buf.st_mode)) /* ask if it should be overwritten */ XtManageChild(valbox); else /* it's another kind of file. What type, i can't think of, but it might happen */ pop_up_error_box(client_data, "Error saving file"); } else /* we couldn't get the file status */ { /* if it's because the file doesn't exist, we're golden */ if (errno == ENOENT) save_file(); else /* there is some other problem getting the status. e.g. bad path */ pop_up_error_box(client_data, "Error saving file"); } } this still doesn't implement the file masking stuff, but since HP obviously is placing very low priority on their implementation of 1.1 (not to mention X11R4, due this summer...), I'll have to make do. Joe Hildebrand [hildjj@modal375.me.vt.edu (128.173.5.186)] Virginia Tech DepartMent of Mechanical Engineering and Babcock & Wilcox Nuclear Services, Lynchburg, VA