/* winfncs.c */ #include "ml.h" #include #include Widget ConfirmW; int Confirmation = 0; /* globals */ Cursor clock_cursor = 0; Cursor top_left_cursor = 0; Cursor pirate_cursor = 0; Cursor create_left_cursor(); Cursor create_clock_cursor(); Cursor create_pirate_cursor(); Menu help_help_menu[] = { { NULL, "dismiss", NUL_TERM, help_dismiss, NULL, 0, NULL, NULL, BTN_ON }, { NULL, "print", NUL_TERM, help_print, NULL, 0, NULL, NULL, BTN_ON }, { NULL, "HELP", NUL_TERM, help_help, NULL, 0, NULL, NULL, BTN_ON }, }; typedef struct _CURSOR_STACK_ { int stack[64]; int pointer; } Cursor_Stack; Cursor_Stack cursor_stack; #ifdef __STDC__ void push_cursor(int cursor_type) #else void push_cursor(cursor_type) int cursor_type; #endif { cursor_stack.pointer ++; cursor_stack.stack[cursor_stack.pointer] = cursor_type; set_cursor(cursor_type); return; } #ifdef __STDC__ void pop_cursor(void) #else void pop_cursor() #endif { if(cursor_stack.pointer) { cursor_stack.pointer --; set_cursor(cursor_stack.stack[cursor_stack.pointer]); } else reset_cursors(); } #ifdef __STDC__ void set_cursor(int cursor_type) #else void set_cursor(cursor_type) int cursor_type; #endif { switch (cursor_type) { case PIRATE_CURSOR: set_pirate_cursors(); break; case WATCH_CURSOR: set_watch_cursors(); break; case DEFAULT_CURSOR: default: reset_cursors(); break; } return; } #ifdef __STDC__ void create_cursors(Display *display) #else void create_cursors(display) Display *display; #endif { clock_cursor = create_clock_cursor(display); top_left_cursor = create_left_cursor(display); pirate_cursor = create_pirate_cursor(display); cursor_stack.pointer = 0; return; } #ifdef __STDC__ Cursor create_left_cursor(Display *display) #else Cursor create_left_cursor(display) Display *display; #endif { return (XCreateFontCursor(display, XC_top_left_arrow)); } #ifdef __STDC__ Cursor create_pirate_cursor(Display *display) #else Cursor create_pirate_cursor(display) Display *display; #endif { return(XCreateFontCursor(display, XC_pirate)); } #ifdef __STDC__ Cursor create_clock_cursor(Display *display) #else Cursor create_clock_cursor(display) Display *display; #endif { return(XCreateFontCursor(display, XC_watch)); } #ifdef __STDC__ void display_fontcursor(Display *display, Window w, Cursor cursor) #else void display_fontcursor(display, w, cursor) Display *display; Window w; Cursor cursor; #endif { if(cursor) XDefineCursor(display, w, cursor); return; } #ifdef __STDC__ void reset_cursor(Display *display, Window w) #else void reset_cursor(display, w) Display *display; Window w; #endif { XUndefineCursor(display, w); XFlush(display); return; } #ifdef __STDC__ void set_watch_cursors(void) #else void set_watch_cursors() #endif { MainWindow *mwin; Read *read; Gentext *gentext; MLCompose *compose; session->busy = TRUE; if((session->lwin) && (session->lwin->destroyed == FALSE)) XDefineCursor(display, XtWindow(session->lwin->shell), clock_cursor); if(session->netconf && session->netconf->is_realized) XDefineCursor(display, XtWindow(session->netconf->shell), clock_cursor); for(mwin = session->mwin; mwin; mwin = mwin->next) { if(mwin->destroyed) continue; XDefineCursor(display, XtWindow(mwin->shell), clock_cursor); if(mwin->listwin->is_realized) XDefineCursor(display, XtWindow(mwin->listwin->shell), clock_cursor); } if(session->mailboxwin && session->mailboxwin->is_realized) XDefineCursor(display, XtWindow(session->mailboxwin->shell),clock_cursor); if(session->mailcopywin && session->mailcopywin->is_realized) XDefineCursor(display, XtWindow(session->mailcopywin->shell),clock_cursor); if(session->edfilter && session->edfilter->is_realized) XDefineCursor(display,XtWindow(session->edfilter->shell), clock_cursor); if(session->address_book && session->address_book->is_realized) XDefineCursor(display, XtWindow(session->address_book->shell), clock_cursor); if(session->compose) for(compose = session->compose; compose; compose = compose->next) { XDefineCursor(display, XtWindow(compose->window->shell), clock_cursor); if(compose->spellwindow && compose->spellwindow->is_realized) XDefineCursor(display,XtWindow(compose->spellwindow->shell), clock_cursor); if(compose->options && compose->options->window && compose->options->window->destroyed == FALSE) XDefineCursor(display,XtWindow(compose->options->window->shell), clock_cursor); } for(read = session->read; read; read = read->next) XDefineCursor(display, XtWindow(read->shell), clock_cursor); if(session->prefst && session->prefst->is_realized) XDefineCursor(display, XtWindow(session->prefst->shell), clock_cursor); if(session->pref2st && session->pref2st->is_realized) XDefineCursor(display, XtWindow(session->pref2st->shell), clock_cursor); if(session->note && session->note->is_realized) XDefineCursor(display, XtWindow(session->note->shell), clock_cursor); for(gentext = session->gentext; gentext; gentext = gentext->next) XDefineCursor(display,XtWindow(gentext->shell), clock_cursor); XFlush(display); return; } #ifdef __STDC__ void set_pirate_cursors(void) #else void set_pirate_cursors() #endif { MainWindow *mwin; Read *read; Gentext *gentext; MLCompose *compose; session->busy = TRUE; if((session->lwin) && (session->lwin->destroyed == FALSE)) XDefineCursor(display, XtWindow(session->lwin->shell), pirate_cursor); if(session->netconf && session->netconf->is_realized) XDefineCursor(display, XtWindow(session->netconf->shell), pirate_cursor); for(mwin = session->mwin; mwin; mwin = mwin->next) { if(mwin->destroyed) continue; XDefineCursor(display, XtWindow(mwin->shell), pirate_cursor); if(mwin->listwin->is_realized) XDefineCursor(display, XtWindow(mwin->listwin->shell), pirate_cursor); } if(session->mailboxwin && session->mailboxwin->is_realized) XDefineCursor(display,XtWindow(session->mailboxwin->shell), pirate_cursor); if(session->mailcopywin && session->mailcopywin->is_realized) XDefineCursor(display,XtWindow(session->mailcopywin->shell), pirate_cursor); if(session->edfilter && session->edfilter->is_realized) XDefineCursor(display, XtWindow(session->edfilter->shell), pirate_cursor); if(session->address_book && session->address_book->is_realized) XDefineCursor(display,XtWindow(session->address_book->shell), pirate_cursor); if(session->compose) for(compose = session->compose; compose; compose = compose->next) { XDefineCursor(display, XtWindow(compose->window->shell), pirate_cursor); if(compose->spellwindow && compose->spellwindow->is_realized) XDefineCursor(display,XtWindow(compose->spellwindow->shell), pirate_cursor); if(compose->options && compose->options->window && compose->options->window->destroyed == FALSE) XDefineCursor(display,XtWindow(compose->options->window->shell), pirate_cursor); } for(read = session->read; read; read = read->next) XDefineCursor(display,XtWindow(read->shell), pirate_cursor); if(session->prefst && session->prefst->is_realized) XDefineCursor(display, XtWindow(session->prefst->shell), pirate_cursor); if(session->pref2st && session->pref2st->is_realized) XDefineCursor(display, XtWindow(session->pref2st->shell), pirate_cursor); if(session->note && session->note->is_realized) XDefineCursor(display, XtWindow(session->note->shell), pirate_cursor); for(gentext = session->gentext; gentext; gentext = gentext->next) XDefineCursor(display,XtWindow(gentext->shell), pirate_cursor); XFlush(display); return; } #ifdef __STDC__ void reset_cursors(void) #else void reset_cursors() #endif { MainWindow *mwin; Read *read; Gentext *gentext; MLCompose *compose; if((session->lwin) && (session->lwin->destroyed == FALSE)) XUndefineCursor(display, XtWindow(session->lwin->shell)); if(session->netconf && session->netconf->is_realized) XUndefineCursor(display, XtWindow(session->netconf->shell)); for(mwin = session->mwin; mwin; mwin = mwin->next) { if(mwin->destroyed) continue; XUndefineCursor(display, XtWindow(mwin->shell)); if(mwin->listwin->is_realized) XUndefineCursor(display, XtWindow(mwin->listwin->shell)); } if(session->mailboxwin && session->mailboxwin->is_realized) XUndefineCursor(display, XtWindow(session->mailboxwin->shell)); if(session->mailcopywin && session->mailcopywin->is_realized) XUndefineCursor(display, XtWindow(session->mailcopywin->shell)); if(session->edfilter && session->edfilter->is_realized) XUndefineCursor(display,XtWindow(session->edfilter->shell)); if(session->address_book && session->address_book->is_realized) XUndefineCursor(display,XtWindow(session->address_book->shell)); if(session->compose) for(compose = session->compose; compose; compose = compose->next) { XUndefineCursor(display, XtWindow(compose->window->shell)); if(compose->spellwindow && compose->spellwindow->is_realized) XUndefineCursor(display,XtWindow(compose->spellwindow->shell)); if(compose->options && compose->options->window && compose->options->window->destroyed == FALSE) XUndefineCursor(display,XtWindow(compose->options->window->shell)); } for(read = session->read; read; read = read->next) XUndefineCursor(display,XtWindow(read->shell)); if(session->prefst && session->prefst->is_realized) XUndefineCursor(display,XtWindow(session->prefst->shell)); if(session->pref2st && session->pref2st->is_realized) XUndefineCursor(display,XtWindow(session->pref2st->shell)); if(session->note && session->note->is_realized) XUndefineCursor(display,XtWindow(session->note->shell)); for(gentext = session->gentext; gentext; gentext = gentext->next) XUndefineCursor(display,XtWindow(gentext->shell)); XFlush(display); session->busy = FALSE; return; } #ifdef __STDC__ void get_pointer_position(Widget w, Position *x, Position *y) #else void get_pointer_position(w,x,y) Widget w; Position *x; Position *y; #endif { Window junk1, junk2; int root_x, root_y, junkX, junkY; unsigned int junkM; if (XQueryPointer(XtDisplay(w), XtWindow(w), &junk1, &junk2, &root_x, &root_y, &junkX, &junkY, &junkM) == FALSE) return; *x = (short) root_x; *y = (short) root_y; return; } #ifdef __STDC__ void get_screen_size(int *x, int *y) #else void get_screen_size(x,y) int *x; int *y; #endif { int screen_number; screen_number = XDefaultScreen(display); *x = XDisplayWidth(display,screen_number); *y = XDisplayHeight(display,screen_number); return; } #define BORDER_SLOP 60 #ifdef __STDC__ void position_popup_widget(Widget w, Boolean force) #else void position_popup_widget(w, force) Widget w; Boolean force; #endif { int rsize_x, rsize_y; Dimension wid_h, wid_w, wid_b; Position p_x, p_y; get_screen_size(&rsize_x, &rsize_y); get_pointer_position(w, &p_x, &p_y); XtRealizeWidget(w); if((preferences.autoPlace == FALSE) && (force == FALSE)) return; XtVaGetValues(w, XmNheight, &wid_h, XmNwidth, &wid_w, XmNborderWidth, &wid_b, NULL); p_x -= (Position) (wid_w / 2) - wid_b; p_y -= (Position) (wid_h / 2) - wid_b; if(p_x < BORDER_SLOP) p_x = BORDER_SLOP; else if(((int) (p_x + wid_w + wid_b)) > rsize_x) p_x = rsize_x - wid_w - wid_b - BORDER_SLOP; if(p_y < BORDER_SLOP) p_y = BORDER_SLOP; else if(((int) (p_y + wid_h + wid_b)) > rsize_y) p_y = rsize_y - wid_h - wid_b - BORDER_SLOP; XtVaSetValues(w, XtNx, p_x, XtNy, p_y, NULL); } /* To determine if an item in a list widget was selected or deselected */ #ifdef __STDC__ Boolean is_selected(XmListCallbackStruct *ptr, unsigned long num) #else Boolean is_selected(ptr,num) XmListCallbackStruct *ptr; unsigned long num; #endif { register int i; for(i = 0; i < ptr->selected_item_count; i ++) { if(ptr->selected_item_positions[i] == num) return(TRUE); } return(FALSE); } #ifdef __STDC__ Widget create_label(Widget form, Widget below, char *string) #else Widget create_label(form,below,string) Widget form; Widget below; char *string; #endif { Arg args[ARGLISTSIZE]; int n = 0; Widget label; XtSetArg(args[n], XmNtopAttachment, XmATTACH_WIDGET ); n ++; XtSetArg(args[n], XmNtopWidget, below ); n ++; XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM ); n ++; XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM ); n ++; XtSetArg(args[n], XmNborderWidth, 0 ); n ++; label = XmCreateLabel(form, string, args, n); n = 0; XtManageChild(label); return(label); } #ifdef __STDC__ Widget create_text_field(Widget form, Widget below, char *label_string, char *string, int width, XtPointer fn, XtPointer data) #else Widget create_text_field(form,below,label_string,string,width,fn,data) Widget form; Widget below; char *label_string; char *string; int width; XtPointer fn; XtPointer data; #endif { Arg args[ARGLISTSIZE]; int n = 0; XtTranslations translations; Widget this_widget; Widget label; char buffer[FILEBUFFLEN]; XtSetArg(args[n], XmNtopAttachment, XmATTACH_WIDGET ); n ++; XtSetArg(args[n], XmNtopWidget, below ); n ++; XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM ); n ++; XtSetArg(args[n], XmNborderWidth, 0 ); n ++; strcpy(buffer,label_string); strcat(buffer,"_lbl"); label = XmCreateLabel(form, buffer, args, n); n = 0; XtManageChild(label); XtSetArg(args[n], XmNtopAttachment, XmATTACH_WIDGET ); n ++; XtSetArg(args[n], XmNtopWidget, below ); n ++; XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM ); n ++; XtSetArg(args[n], XmNleftAttachment, XmATTACH_WIDGET ); n ++; XtSetArg(args[n], XmNleftWidget, label ); n ++; if(width) { XtSetArg(args[n], XmNcolumns, width ); n ++; } strcpy(buffer,label_string); strcat(buffer,"_textfld"); this_widget = XmCreateTextField(form, buffer, args, n); n = 0; XtManageChild(this_widget); if(string) AppendText(this_widget,string); translations = XtParseTranslationTable(GLOBAL_text_field_translations); XtOverrideTranslations(this_widget,translations); if(fn) { translations = XtParseTranslationTable(GLOBAL_terminal_text_field_translations); XtOverrideTranslations(this_widget,translations); XtAddCallback(this_widget, XmNactivateCallback, (XtCallbackProc) fn, data); } else { translations = XtParseTranslationTable(GLOBAL_nonterminal_text_field_translations); XtOverrideTranslations(this_widget,translations); } XtAddCallback(this_widget, XmNmodifyVerifyCallback, (XtCallbackProc) text_field_edit, NULL); return(this_widget); } #ifdef __STDC__ void help(Widget w, char *filename) #else void help(w, filename) Widget w; char *filename; #endif { char buffer[MAXPATHLEN]; char altbuffer[MAXPATHLEN]; char *local_language = NULL; sprintf(buffer,"%s/%s",preferences.help_directory,filename); strcpy(altbuffer,buffer); local_language = getenv("LANG"); if(local_language == NULL) local_language = getenv("ML_LANG"); if(local_language != NULL) { strcat(altbuffer,"."); strcat(altbuffer,local_language); } if((access(altbuffer,R_OK)) == SYSCALL_SUCCESS) display_text(w,NULL,altbuffer,NULL,DOCTYPE_HELP); else display_text(w,NULL,buffer,NULL,DOCTYPE_HELP); return; } #ifdef __STDC__ void display_text(Widget w, char *title, char *filename, char *string, Doc_Type doctype) #else void display_text(w,title,filename,string, doctype) Widget w; char *title; char *filename; char *string; Doc_Type doctype; #endif { Arg args[ARGLISTSIZE]; int n = 0; Widget form, menubar, text; XtTranslations translations; Gentext *gentext; FILE *fp; char buffer[FILEBUFFLEN]; if(filename) { if((fp = fopen(filename,"r")) == NULL) { sprintf(buffer,MLGetLocalized(XtNmsgCannotReadFile,MsgCannotReadFile), filename); mm_log(buffer,WARN); return; } if(doctype == DOCTYPE_HELP) { if((fgets(buffer,sizeof(buffer),fp)) != NULL) { buffer[strlen(buffer) - 1] = NUL_TERM; XtSetArg(args[n], XmNtitle, buffer); n ++; } } } gentext = (Gentext *) fs_get(sizeof(Gentext)); gentext->next = NULL; gentext->prev = NULL; if(title) { XtSetArg(args[n], XmNtitle, title); n ++; } XtSetArg (args[n], XmNdeleteResponse, XmDO_NOTHING); n++; gentext->shell = XtCreateWidget((filename) ? "helpwin" : "textwin", topLevelShellWidgetClass, w, args, n ); n = 0; AddDestroyCallback (gentext->shell); setup_editres(gentext->shell); if(help_icon != (Pixmap) None) XtVaSetValues(gentext->shell, XmNiconPixmap,help_icon, NULL); form = XmCreateForm(gentext->shell, "form", args, n); n = 0; XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n ++; XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n ++; XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n ++; menubar = XmCreateMenuBar(form,"menubar", args, n); n = 0; XtManageChild(menubar); create_buttons(NULL, menubar, help_help_menu, XtNumber(help_help_menu), BTN_ON, (XtPointer) gentext, ROOTMENULEVEL); XtSetArg(args[n], XmNeditable, FALSE); n ++; XtSetArg(args[n], XmNeditMode, XmMULTI_LINE_EDIT); n ++; XtSetArg(args[n], XmNwordWrap, TRUE); n ++; XtSetArg(args[n], XmNscrollVertical, TRUE); n ++; XtSetArg(args[n], XmNscrollHorizontal, FALSE ); n ++; gentext->text = XmCreateScrolledText(form, "text", args, n); n = 0; translations = XtParseTranslationTable(GLOBAL_text_translations); XtOverrideTranslations(gentext->text, translations); translations = XtParseTranslationTable(GLOBAL_help_pop_translations); XtOverrideTranslations(gentext->text, translations); XtManageChild(gentext->text); if(filename) { while(fgets(buffer,sizeof(buffer),fp)) AppendText(gentext->text,buffer); fclose(fp); } else XmTextSetString(gentext->text,string); XtSetArg(args[n], XmNtopAttachment, XmATTACH_WIDGET); n ++; XtSetArg(args[n], XmNtopWidget, menubar); n ++; XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n ++; XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n ++; XtSetArg(args[n], XmNbottomAttachment, XmATTACH_FORM); n ++; XtSetValues(XtParent(gentext->text),args,n); n = 0; XtManageChild(form); XmTextShowPosition(gentext->text,0); XmTextSetInsertionPosition(gentext->text,0); XtAddCallback(gentext->shell, XmNdestroyCallback, (XtCallbackProc) help_destroy, gentext); if(session->gentext == NULL) session->gentext = gentext; else { gentext->next = session->gentext; session->gentext->prev = gentext; session->gentext = gentext; } XtManageChild(gentext->shell); XtRealizeWidget(gentext->shell); XFlush(display); return; } #ifdef __STDC__ void help_dismiss(Widget w, Gentext *gentext, XtPointer xp) #else void help_dismiss(w,gentext,xp) Widget w; Gentext *gentext; XtPointer xp; #endif { XtRemoveCallback(gentext->shell, XmNdestroyCallback, (XtCallbackProc) help_destroy, gentext); XtDestroyWidget(gentext->shell); if(gentext->next) gentext->next->prev = gentext->prev; if(gentext->prev) gentext->prev->next = gentext->next; else session->gentext = gentext->next; fs_give((void **) &gentext); return; } #ifdef __STDC__ void help_pop(Widget w, XtPointer xp) #else void help_pop(w,xp) Widget w; XtPointer xp; #endif { Gentext *curr; for(curr = session->gentext; curr; curr = curr->next) { if(curr->text == w) help_dismiss(w,curr,NULL); } return; } #ifdef __STDC__ void help_print(Widget w, Gentext *gentext, XtPointer xp) #else void help_print(w,gentext,xp) Widget w; Gentext *gentext; XtPointer xp; #endif { char *txt; if(*preferences.print_command == NUL_TERM) { mm_log(MLGetLocalized(XtNmsgNoPrintCommand,MsgNoPrintCommand), WARN); return; } push_cursor(WATCH_CURSOR); txt = XmTextGetString(gentext->text); if(txt != NULL) { if(write_to_pipe(preferences.print_command, NULL, txt, strlen(txt))) mm_log(MLGetLocalized(XtNmsgPrintFail,MsgPrintFail), WARN); else mm_log(MLGetLocalized(XtNmsgPrintSuccess,MsgPrintSuccess), NIL); fs_give((void **) &txt); } pop_cursor(); return; } #ifdef __STDC__ void help_help(Widget w, Gentext *gentext, XtPointer xp) #else void help_help(w,gentext,xp) Widget w; Gentext *gentext; XtPointer xp; #endif { help(gentext->shell, HELPHELPFILE); return; } #ifdef __STDC__ void help_destroy(Widget w, Gentext *gentext, XtPointer xp) #else void help_destroy(w,gentext,xp) Widget w; Gentext *gentext; XtPointer xp; #endif { if(gentext->next) gentext->next->prev = gentext->prev; if(gentext->prev) gentext->prev->next = gentext->next; else session->gentext = gentext->next; fs_give((void **) &gentext); return; }