1 /*
2 * @(#)sun.c 1.1 10/21/84
3 *
4 * SUN specific routines for the SUN Gremlin picture editor.
5 *
6 * Mark Opperman (opcode@monet.BERKELEY)
7 *
8 */
9
10 #include <suntool/tool_hs.h>
11 #include <suntool/menu.h>
12 #include <sys/file.h>
13 #include "gremlin.h"
14
15
16 /* imports from main.c */
17
18 extern tool_fd, pix_fd, menu_fd, text_fd;
19 extern struct pixfont *text_pf;
20
21 /* locals */
22
23 struct prompt prt = { {PROMPT_FLEXIBLE, PROMPT_FLEXIBLE,
24 PROMPT_FLEXIBLE, PROMPT_FLEXIBLE},
25 0, (struct pixfont *) NULL, (char *) NULL };
26
27 /*
28 * Flush all input events for a window.
29 */
flush_window_input(windowfd)30 flush_window_input(windowfd)
31 int windowfd;
32 {
33 int nfds, readfds, writefds, exceptfds;
34 struct timeval timeout;
35 struct inputevent ie;
36
37 do {
38 readfds = 1 << windowfd;
39 writefds = 0;
40 exceptfds = 0;
41 timeout.tv_sec = 0L;
42 timeout.tv_usec = 0L;
43
44 nfds = select(20, &readfds, &writefds, &exceptfds, &timeout);
45 if (nfds > 0)
46 input_readevent(windowfd, &ie);
47 } while (nfds > 0);
48 }
49
50
51 /*
52 * Display user prompt and wait for affirmative (MS_LEFT)
53 * or negative (MS_MIDDLE or MS_RIGHT) input event.
54 * Return TRUE if OK to do it, FALSE if not OK.
55 * This routine flushes the input event queue for the windowfd
56 * handling the prompt.
57 */
prompt_ok(windowfd,msg)58 prompt_ok(windowfd, msg)
59 int windowfd;
60 char *msg;
61 {
62 struct inputmask im, button_im;
63 struct inputevent ie;
64 int designee;
65
66 win_getinputmask(windowfd, &im, &designee);
67
68 input_imnull(&button_im);
69 win_setinputcodebit(&button_im, MS_LEFT);
70 win_setinputcodebit(&button_im, MS_MIDDLE);
71 win_setinputcodebit(&button_im, MS_RIGHT);
72 win_setinputmask(windowfd, &button_im, NULL, WIN_NULLLINK);
73
74 prt.prt_font = text_pf;
75 prt.prt_windowfd = windowfd;
76 prt.prt_text = msg;
77
78 flush_window_input(windowfd);
79
80 menu_prompt(&prt, &ie, windowfd);
81
82 win_setinputmask(windowfd, &im, NULL, designee);
83
84 return(ie.ie_code == MS_LEFT);
85 }
86
87 /*
88 * draw box with upper left corner at (x0, y0)
89 * lower right corner at (x1, y1);
90 */
91 pw_box(pw, x0, y0, x1, y1, op, value)
92 struct pixwin *pw;
93 register x0, y0, x1, y1;
94 int op, value;
95 {
96 pw_vector(pw, x0, y0, x1, y0, op, value);
97 pw_vector(pw, x1, y0, x1, y1, op, value);
98 pw_vector(pw, x1, y1, x0, y1, op, value);
99 pw_vector(pw, x0, y1, x0, y0, op, value);
100 }
101
102
103 /*
104 * wait for input from any button.
105 */
get_any_button()106 get_any_button()
107 {
108 int nfds, readfds, writefds, exceptfds;
109 struct inputevent ie;
110
111 for (;;) {
112 readfds = (1<<tool_fd) | (1<<pix_fd) | (1<<menu_fd) | (1<<text_fd);
113 writefds = 0;
114 exceptfds = 0;
115
116 nfds = select(20, &readfds, &writefds,
117 &exceptfds, (struct timeval *) NULL);
118 if (nfds > 0) {
119 if (readfds & (1 << menu_fd))
120 input_readevent(menu_fd, &ie);
121 else if (readfds & (1 << pix_fd))
122 input_readevent(pix_fd, &ie);
123 else if (readfds & (1 << text_fd))
124 input_readevent(text_fd, &ie);
125 else /* tool window input event */
126 input_readevent(tool_fd, &ie);
127
128 if ((ie.ie_code == MS_LEFT) || (ie.ie_code == MS_MIDDLE) ||
129 (ie.ie_code == MS_RIGHT))
130 break;
131 }
132 }
133 }
134