117297Sopcode /*
2*17652Sopcode * @(#)text.c 1.2 01/03/85
317297Sopcode *
417297Sopcode * Text subwindow routines for the SUN Gremlin picture editor.
517297Sopcode *
617297Sopcode * Mark Opperman (opcode@monet.BERKELEY)
717297Sopcode *
817297Sopcode */
917297Sopcode
1017297Sopcode #include <suntool/tool_hs.h>
1117297Sopcode #include <sgtty.h>
1217297Sopcode #include "gremlin.h"
1317297Sopcode #include "icondata.h"
1417297Sopcode
1517297Sopcode /* imports from main.c */
1617297Sopcode
1717297Sopcode extern struct pixwin *text_pw;
1817297Sopcode extern struct rect text_size;
1917297Sopcode extern TOOLINSTALLED;
20*17652Sopcode extern (*lastcommand)();
21*17652Sopcode extern lasttext;
2217297Sopcode
2317297Sopcode /* imports from long.c */
2417297Sopcode
2517297Sopcode extern LGTextSW();
2617297Sopcode
2717297Sopcode /* imports from graphics.c */
2817297Sopcode
2917297Sopcode extern GRCurrentSetOn();
3017297Sopcode
3117297Sopcode /* imports from help.c */
3217297Sopcode
3317297Sopcode extern textsw_help();
3417297Sopcode extern get_any_button();
3517297Sopcode
3617297Sopcode /* locals */
3717297Sopcode
3817297Sopcode struct pixfont *text_pf;
3917297Sopcode
4017297Sopcode #define TEXT_LEFT 96 /* start of text input */
4117297Sopcode #define TEXT_FIRST ' '
4217297Sopcode #define TEXT_LAST '~'
4317297Sopcode #define CTRL_W '\027'
4417297Sopcode #define RETURN '\r'
4517297Sopcode #define MSGLINE 17
4617297Sopcode
4717297Sopcode #define text_width (text_pf->pf_defaultsize.x)
4817297Sopcode #define text_height (text_pf->pf_defaultsize.y)
4917297Sopcode
50*17652Sopcode static char text_buf[TEXT_BUFMAX] = "";
51*17652Sopcode static char mesg_buf[TEXT_BUFMAX] = "";
52*17652Sopcode static char save_buf[TEXT_BUFMAX] = "";
5317297Sopcode static char text_erase;
5417297Sopcode static char text_kill;
5517297Sopcode static char text_erase_word;
5617297Sopcode static text_length;
5717297Sopcode static mesg_length; /* length of last message displayed */
5817297Sopcode static putmsg = FALSE; /* TRUE if TxPutMsg called since last button input. */
5917297Sopcode
6017297Sopcode
6117297Sopcode void
text_cursor(op)6217297Sopcode text_cursor(op)
6317297Sopcode int op;
6417297Sopcode {
6517297Sopcode pw_write(text_pw, TEXT_LEFT + text_length * text_width, 0,
6617297Sopcode text_width, text_height, op, &bigblack_pr, 0, 0);
6717297Sopcode }
6817297Sopcode
6917297Sopcode
7017297Sopcode void
text_output(c)7117297Sopcode text_output(c)
7217297Sopcode register c;
7317297Sopcode {
7417297Sopcode register count;
7517297Sopcode
7617297Sopcode TxMsgOK();
7717297Sopcode
7817297Sopcode if ((c>=TEXT_FIRST) && (c<=TEXT_LAST) && (text_length<TEXT_BUFMAX-1)) {
7917297Sopcode text_buf[text_length] = c;
8017297Sopcode text_buf[text_length+1] = '\0';
8117297Sopcode pw_char(text_pw, TEXT_LEFT + text_length * text_width, TEXT_BASELINE,
8217297Sopcode PIX_SRC, text_pf, c);
8317297Sopcode text_length++;
8417297Sopcode text_cursor(PIX_SRC);
8517297Sopcode }
8617297Sopcode
8717297Sopcode else if ((c == text_erase) && (text_length > 0)) {
8817297Sopcode text_cursor(PIX_NOT(PIX_SRC));
8917297Sopcode text_length--;
9017297Sopcode pw_char(text_pw, TEXT_LEFT + text_length * text_width,
9117297Sopcode TEXT_BASELINE, PIX_SRC^PIX_DST, text_pf, text_buf[text_length]);
9217297Sopcode text_buf[text_length] = '\0';
9317297Sopcode text_cursor(PIX_SRC);
9417297Sopcode }
9517297Sopcode
9617297Sopcode else if (c == text_kill) {
9717297Sopcode TxKillLine();
9817297Sopcode }
9917297Sopcode
10017297Sopcode else if ((c == text_erase_word) && (text_length > 0)) {
10117297Sopcode text_cursor(PIX_NOT(PIX_SRC));
10217297Sopcode count = 0;
10317297Sopcode while ((text_length > 0) && (text_buf[text_length-1] == ' ')) {
10417297Sopcode text_length--;
10517297Sopcode count++;
10617297Sopcode }
10717297Sopcode while ((text_length > 0) && (text_buf[text_length-1] != ' ')) {
10817297Sopcode text_length--;
10917297Sopcode count++;
11017297Sopcode }
11117297Sopcode text_buf[text_length] = '\0';
11217297Sopcode pw_replrop(text_pw, TEXT_LEFT + text_length * text_width, 0,
11317297Sopcode count * text_width, text_height, PIX_NOT(PIX_SRC),
11417297Sopcode &bigblack_pr, 0, 0);
11517297Sopcode text_cursor(PIX_SRC);
11617297Sopcode }
11717297Sopcode
118*17652Sopcode else if (c == RETURN) { /* new text entry method */
119*17652Sopcode lastcommand = LGTextSW;
120*17652Sopcode lasttext = TRUE;
12117297Sopcode LGTextSW();
122*17652Sopcode }
12317297Sopcode }
12417297Sopcode
12517297Sopcode
text_getvalue(s)12617297Sopcode text_getvalue(s)
12717297Sopcode register char *s;
12817297Sopcode {
12917297Sopcode register i = 0;
13017297Sopcode
13117297Sopcode while (text_buf[i] == ' ')
13217297Sopcode i++;
13317297Sopcode
134*17652Sopcode (void) strcpy(save_buf, &text_buf[i]);
13517297Sopcode (void) strcpy(s, &text_buf[i]);
13617297Sopcode }
13717297Sopcode
13817297Sopcode
text_putvalue()13917297Sopcode text_putvalue()
14017297Sopcode {
14117297Sopcode pw_text(text_pw, 2, TEXT_BASELINE, PIX_SRC,
14217297Sopcode text_pf, "text input:");
14317297Sopcode pw_text(text_pw, TEXT_LEFT, TEXT_BASELINE, PIX_SRC,
14417297Sopcode text_pf, text_buf);
14517297Sopcode text_cursor(PIX_SRC);
14617297Sopcode pw_text(text_pw, 0, MSGLINE + TEXT_BASELINE, PIX_NOT(PIX_SRC),
14717297Sopcode text_pf, mesg_buf);
14817297Sopcode }
14917297Sopcode
15017297Sopcode
text_restorebuf()151*17652Sopcode text_restorebuf()
152*17652Sopcode {
153*17652Sopcode register char *s;
154*17652Sopcode
155*17652Sopcode TxKillLine();
156*17652Sopcode s = save_buf;
157*17652Sopcode while (*s)
158*17652Sopcode text_output(*s++);
159*17652Sopcode }
160*17652Sopcode
161*17652Sopcode
text_left(ie)16217297Sopcode text_left(ie)
16317297Sopcode register struct inputevent *ie;
16417297Sopcode {
16517297Sopcode TxMsgOK();
16617297Sopcode }
16717297Sopcode
16817297Sopcode
text_middle(ie)16917297Sopcode text_middle(ie)
17017297Sopcode register struct inputevent *ie;
17117297Sopcode {
17217297Sopcode TxMsgOK();
173*17652Sopcode text_restorebuf();
17417297Sopcode }
17517297Sopcode
17617297Sopcode
text_right(ie)17717297Sopcode text_right(ie)
17817297Sopcode register struct inputevent *ie;
17917297Sopcode {
18017297Sopcode TxMsgOK();
18117297Sopcode textsw_help();
18217297Sopcode }
18317297Sopcode
18417297Sopcode
text_winexit(ie)18517297Sopcode text_winexit(ie)
18617297Sopcode register struct inputevent *ie;
18717297Sopcode {
18817297Sopcode /* check for leaving tool */
18917297Sopcode if ((ie->ie_locy < 0) || (ie->ie_locx < 0) ||
19017297Sopcode (ie->ie_locx >= text_size.r_width))
19117297Sopcode GRCurrentSetOn();
19217297Sopcode }
19317297Sopcode
19417297Sopcode
TxInit()19517297Sopcode TxInit()
19617297Sopcode {
19717297Sopcode struct sgttyb sgtty_buf;
19817297Sopcode
19917297Sopcode ioctl(fileno(stdin), TIOCGETP, &sgtty_buf);
20017297Sopcode text_erase = sgtty_buf.sg_erase;
20117297Sopcode text_kill = sgtty_buf.sg_kill;
20217297Sopcode text_erase_word = CTRL_W;
20317297Sopcode
20417297Sopcode text_length = mesg_length = 0;
20517297Sopcode text_buf[0] = mesg_buf[0] = '\0';
20617297Sopcode
20717297Sopcode text_pf = pf_open("/usr/suntool/fixedwidthfonts/gacha.r.7");
20817297Sopcode
20917297Sopcode if (text_pf == (struct pixfont*) NULL) {
21017297Sopcode printf("TxInit: error opening text_pf font file\n");
21117297Sopcode exit(1);
21217297Sopcode }
21317297Sopcode } /* end TxInit */
21417297Sopcode
21517297Sopcode
21617297Sopcode /*
21717297Sopcode * This routine marks it OK to output messages again
21817297Sopcode * just as if a button had been pressed.
21917297Sopcode */
TxMsgOK()22017297Sopcode TxMsgOK()
22117297Sopcode {
22217297Sopcode if (putmsg) { /* message on the screen to be blanked */
22317297Sopcode TxClearMsg();
22417297Sopcode }
22517297Sopcode
22617297Sopcode putmsg = FALSE;
22717297Sopcode } /* end TxMsgOK */
22817297Sopcode
22917297Sopcode
23017297Sopcode /*
231*17652Sopcode * Output a one line message into the text subwindow.
23217297Sopcode * If the message follows another without intervening user input,
23317297Sopcode * the prompt "More" is output and we wait for a button input event
23417297Sopcode * before displaying the new message.
23517297Sopcode */
TxPutMsg(msg)23617297Sopcode TxPutMsg(msg)
23717297Sopcode register char *msg;
23817297Sopcode {
23917297Sopcode if (!TOOLINSTALLED) { /* tool not displayed yet */
24017297Sopcode fprintf(stderr, "%s\n", msg);
24117297Sopcode return;
24217297Sopcode }
24317297Sopcode
24417297Sopcode if (putmsg) {
24517297Sopcode pw_text(text_pw, mesg_length * text_width, MSGLINE+TEXT_BASELINE,
24617297Sopcode PIX_SRC, text_pf, " --More--");
24717297Sopcode get_any_button();
24817297Sopcode TxClearMsg();
24917297Sopcode }
25017297Sopcode
25117297Sopcode pw_text(text_pw, 0, MSGLINE+TEXT_BASELINE, PIX_NOT(PIX_SRC), text_pf, msg);
25217297Sopcode
25317297Sopcode putmsg = TRUE;
25417297Sopcode mesg_length = strlen(msg);
25517297Sopcode (void) strcpy(mesg_buf, msg);
25617297Sopcode } /* end TxPutMsg */
25717297Sopcode
25817297Sopcode
25917297Sopcode /*
26017297Sopcode * Clear current message.
26117297Sopcode */
TxClearMsg()26217297Sopcode TxClearMsg()
26317297Sopcode {
26417297Sopcode pw_replrop(text_pw, 0, MSGLINE, 2000, text_height,
26517297Sopcode PIX_NOT(PIX_SRC), &bigblack_pr, 0, 0);
26617297Sopcode mesg_length = 0;
26717297Sopcode mesg_buf[0] = '\0';
26817297Sopcode }
26917297Sopcode
27017297Sopcode
27117297Sopcode /*
27217297Sopcode * Consume user text parameter - don't touch message area.
27317297Sopcode */
TxKillLine()27417297Sopcode TxKillLine()
27517297Sopcode {
27617297Sopcode if (text_length > 0) {
27717297Sopcode pw_replrop(text_pw, TEXT_LEFT, 0, 2000, text_height,
27817297Sopcode PIX_NOT(PIX_SRC), &bigblack_pr, 0, 0);
27917297Sopcode text_length = 0;
28017297Sopcode text_buf[0] = '\0';
28117297Sopcode text_cursor(PIX_SRC);
28217297Sopcode }
28317297Sopcode }
284