void FileDropHandler(Widget widget, XtPointer data, XEvent * event, Boolean * p) { unsigned long Size; unsigned char *Data; /* We only know how to handle simple file names */ if (MwDndDataType(event) != MW_DndFile && MwDndDataType(event) != MW_DndExe) { error("Don't know how to handle this drop!"); return; } /* If the drop is from this editor, do nothing! */ /* Updated for version 1 protocol */ if (MwDndSourceWindow(event) == XtWindow(widget)) return; /* Test for source changes */ if (IsSourceChanged()) if (warning("Unsaved Changes!") == XED_ABORT) return; /* Load the file */ MwDndGetData(&Data, &Size); if (Size && Data != NULL) { load_file(Data); ResetSourceChanged(textwindow); /* de-iconify us */ XMapWindow(XtDisplay(top), XtWindow(top)); } }
static void makeButtonsAndBoxes(Widget parent) { Widget outer, b_row, viewport; Arg arglist[10]; Cardinal num_args; xedit_flist_item *item; static char *labelWindow = "labelWindow", *editWindow = "editWindow"; static char *formWindow = "formWindow", *positionWindow = "positionWindow"; outer = XtCreateManagedWidget("paned", panedWidgetClass, parent, NULL, ZERO); b_row = XtCreateManagedWidget("buttons", panedWidgetClass, outer, NULL, ZERO); { MakeCommandButton(b_row, "quit", DoQuit); MakeCommandButton(b_row, "save", DoSave); MakeCommandButton(b_row, "load", DoLoad); filenamewindow = MakeStringBox(b_row, "filename", NULL); } hintswindow = XtCreateManagedWidget("bc_label", labelWidgetClass, outer, NULL, ZERO); num_args = 0; XtSetArg(arglist[num_args], XtNeditType, XawtextEdit); ++num_args; messwidget = XtCreateManagedWidget("messageWindow", asciiTextWidgetClass, outer, arglist, num_args); num_args = 0; XtSetArg(arglist[num_args], XtNorientation, XtorientHorizontal); ++num_args; hpane = XtCreateManagedWidget("hpane", panedWidgetClass, outer, arglist, num_args); num_args = 0; XtSetArg(arglist[num_args], XtNorientation, XtorientVertical); ++num_args; vpanes[0] = XtCreateManagedWidget("vpane", panedWidgetClass, hpane, arglist, num_args); XtSetArg(arglist[num_args], XtNheight, 1); ++num_args; XtSetArg(arglist[num_args], XtNwidth, 1); ++num_args; vpanes[1] = XtCreateWidget("vpane", panedWidgetClass, hpane, arglist, num_args); forms[0] = XtCreateManagedWidget(formWindow, formWidgetClass, vpanes[0], NULL, 0); labelwindow = XtCreateManagedWidget(labelWindow,labelWidgetClass, forms[0], NULL, 0); labels[0] = labelwindow; positions[0] = XtCreateManagedWidget(positionWindow,labelWidgetClass, forms[0], NULL, 0); forms[2] = XtCreateWidget(formWindow, formWidgetClass, vpanes[1], NULL, 0); labels[2] = XtCreateManagedWidget(labelWindow,labelWidgetClass, forms[2], NULL, 0); positions[2] = XtCreateManagedWidget(positionWindow,labelWidgetClass, forms[2], NULL, 0); num_args = 0; XtSetArg(arglist[num_args], XtNtype, XawAsciiFile); ++num_args; XtSetArg(arglist[num_args], XtNeditType, XawtextEdit); ++num_args; textwindow = XtCreateManagedWidget(editWindow, asciiTextWidgetClass, vpanes[0], arglist, num_args); /* Get international resource value form the textwindow */ num_args = 0; XtSetArg(arglist[num_args], XtNinternational, &international); ++num_args; XtGetValues(textwindow, arglist, num_args); num_args = 0; XtSetArg(arglist[num_args], XtNtype, XawAsciiFile); ++num_args; XtSetArg(arglist[num_args], XtNeditType, XawtextEdit); ++num_args; scratch = XtVaCreateWidget("textSource", international ? multiSrcObjectClass : asciiSrcObjectClass, topwindow, XtNtype, XawAsciiFile, XtNeditType, XawtextEdit, NULL, NULL); XtSetValues(scratch, arglist, num_args); num_args = 0; XtSetArg(arglist[num_args], XtNtextSource, scratch); ++num_args; XtSetValues(textwindow, arglist, num_args); texts[0] = textwindow; num_args = 0; XtSetArg(arglist[num_args], XtNtextSource, scratch); ++num_args; XtSetArg(arglist[num_args], XtNdisplayCaret, False); ++num_args; texts[2] = XtCreateWidget(editWindow, asciiTextWidgetClass, vpanes[1], arglist, num_args); forms[1] = XtCreateWidget(formWindow, formWidgetClass, vpanes[0], NULL, 0); labels[1] = XtCreateManagedWidget(labelWindow,labelWidgetClass, forms[1], NULL, 0); positions[1] = XtCreateManagedWidget(positionWindow,labelWidgetClass, forms[1], NULL, 0); texts[1] = XtCreateWidget(editWindow, asciiTextWidgetClass, vpanes[0], arglist, num_args); dirlabel = XtCreateWidget("dirlabel", labelWidgetClass, vpanes[1], NULL, 0); num_args = 0; XtSetArg(arglist[num_args], XtNheight, 1); ++num_args; XtSetArg(arglist[num_args], XtNwidth, 1); ++num_args; viewport = XtCreateWidget("viewport", viewportWidgetClass, vpanes[1], arglist, num_args); dirwindow = XtCreateManagedWidget("dirwindow", listWidgetClass, viewport, NULL, 0); item = AddTextSource(scratch, "*scratch*", "*scratch*", 0, WRITE_OK); item->wrap = XawtextWrapLine; item->flags |= WRAP_BIT; XtAddCallback(item->source, XtNcallback, SourceChanged, (XtPointer)item); ResetSourceChanged(item); flist.current = item; for (num_args = 0; num_args < 3; num_args++) XtAddCallback(texts[num_args], XtNpositionCallback, PositionChanged, NULL); for (num_args = 0; num_args < 3; num_args++) { XtSetArg(arglist[0], XtNwrap, &wrapmodes[num_args]); XtGetValues(texts[num_args], arglist, 1); } XtAddCallback(dirwindow, XtNcallback, DirWindowCB, NULL); }
int main(int argc, char *argv[]) { Boolean exists; char *filename; FileAccess file_access; Widget source; XtAppContext appcon; Boolean show_dir; xedit_flist_item *first_item; unsigned int i, lineno; lineno = 0; show_dir = FALSE; first_item = NULL; topwindow = XtAppInitialize(&appcon, "Xedit", NULL, 0, &argc, argv, NULL, NULL, 0); XtAppAddActions(appcon, actions, XtNumber(actions)); XtOverrideTranslations(topwindow, XtParseTranslationTable("<Message>WM_PROTOCOLS: quit()")); XtGetApplicationResources(topwindow, (XtPointer) &app_resources, resources, XtNumber(resources), NULL, 0); CurDpy = XtDisplay(topwindow); XawSimpleMenuAddGlobalActions(appcon); XtRegisterGrabAction(PopupMenu, True, ButtonPressMask | ButtonReleaseMask, GrabModeAsync, GrabModeAsync); makeButtonsAndBoxes(topwindow); StartHints(); StartFormatPosition(); (void)StartHooks(appcon); if (position_format_mask == 0) { for (i = 0; i < 3; i++) XtRemoveCallback(texts[i], XtNpositionCallback, PositionChanged, NULL); } XtRealizeWidget(topwindow); #ifndef __UNIXOS2__ XeditLispInitialize(); #endif options_popup = XtCreatePopupShell("optionsMenu", simpleMenuWidgetClass, topwindow, NULL, 0); XtRealizeWidget(options_popup); XtAddCallback(XtCreateManagedWidget("ispell", smeBSBObjectClass, options_popup, NULL, 0), XtNcallback, IspellCallback, NULL); CreateEditPopup(); wm_delete_window = XInternAtom(XtDisplay(topwindow), "WM_DELETE_WINDOW", False); (void)XSetWMProtocols(XtDisplay(topwindow), XtWindow(topwindow), &wm_delete_window, 1); /* This first call is just to save the default font and colors */ UpdateTextProperties(0); if (argc > 1) { xedit_flist_item *item; Arg args[2]; unsigned int num_args; for (i = 1; i < argc; i++) { struct stat st; if (argv[i][0] == '+') { char *endptr; lineno = strtol(argv[i], &endptr, 10); /* Don't warn about incorrect input? */ if (*endptr) lineno = 0; continue; } filename = ResolveName(argv[i]); if (filename == NULL || FindTextSource(NULL, filename) != NULL) continue; num_args = 0; if (stat(filename, &st) == 0 && !S_ISREG(st.st_mode)) { if (S_ISDIR(st.st_mode)) { if (!first_item) { char path[BUFSIZ + 1]; strncpy(path, filename, sizeof(path) - 2); path[sizeof(path) - 2] = '\0'; if (*path) { if (path[strlen(path) - 1] != '/') strcat(path, "/"); } else strcpy(path, "./"); XtSetArg(args[0], XtNlabel, ""); XtSetValues(dirlabel, args, 1); SwitchDirWindow(True); DirWindowCB(dirwindow, path, NULL); show_dir = True; } continue; } } switch (file_access = CheckFilePermissions(filename, &exists)) { case NO_READ: if (exists) XeditPrintf("File %s exists, and could not be opened for " "reading.\n", argv[i]); else XeditPrintf("File %s does not exist, and the directory " "could not be opened for writing.\n", argv[i]); break; case READ_OK: XtSetArg(args[num_args], XtNeditType, XawtextRead); num_args++; XeditPrintf("File %s opened READ ONLY.\n", argv[i]); break; case WRITE_OK: XtSetArg(args[num_args], XtNeditType, XawtextEdit); num_args++; XeditPrintf("File %s opened read - write.\n", argv[i]); break; } if (file_access != NO_READ) { int flags; if (exists) { flags = EXISTS_BIT; XtSetArg(args[num_args], XtNstring, filename);num_args++; } else { flags = 0; XtSetArg(args[num_args], XtNstring, NULL); num_args++; } source = XtVaCreateWidget("textSource", international ? multiSrcObjectClass : asciiSrcObjectClass, topwindow, XtNtype, XawAsciiFile, XtNeditType, XawtextEdit, NULL, NULL); XtSetValues(source, args, num_args); item = AddTextSource(source, argv[i], filename, flags, file_access); XtAddCallback(item->source, XtNcallback, SourceChanged, (XtPointer)item); if (exists && file_access == WRITE_OK) { item->mode = st.st_mode & (S_IRWXU | S_IRWXG | S_IRWXO); item->mtime = st.st_mtime; } if (!first_item && !show_dir) first_item = item; ResetSourceChanged(item); } } } if (!flist.pixmap && strlen(app_resources.changed_pixmap_name)) { XrmValue from, to; from.size = strlen(app_resources.changed_pixmap_name); from.addr = app_resources.changed_pixmap_name; to.size = sizeof(Pixmap); to.addr = (XtPointer)&(flist.pixmap); XtConvertAndStore(flist.popup, XtRString, &from, XtRBitmap, &to); } if (first_item == NULL) { XtSetKeyboardFocus(topwindow, filenamewindow); XtVaSetValues(textwindow, XtNwrap, XawtextWrapLine, NULL); } else { SwitchTextSource(first_item); XtSetKeyboardFocus(topwindow, textwindow); if (lineno) { XawTextPosition position; source = XawTextGetSource(textwindow); position = RSCAN(XawTextGetInsertionPoint(textwindow), lineno, False); position = LSCAN(position, 1, False); XawTextSetInsertionPoint(textwindow, position); } } XtAppMainLoop(appcon); return EXIT_SUCCESS; }