]> asedeno.scripts.mit.edu Git - 1ts-debian.git/blob - zephyr/clients/xzwrite/edit_window.c
finalize -3
[1ts-debian.git] / zephyr / clients / xzwrite / edit_window.c
1 #include <X11/Intrinsic.h>
2 #include <X11/StringDefs.h>
3 #include <X11/Xaw/Paned.h>
4 #include <X11/Xaw/Label.h>
5 #include <X11/Xaw/Form.h>
6 #include <X11/Xaw/Command.h>
7 #include <X11/Xaw/AsciiText.h>
8
9 #include "xzwrite.h"
10
11 extern Widget toplevel, editor, editTitle;
12 extern Defaults defs;
13 extern DestRec  current_dest;
14
15 void edit_win_init()
16 {
17      edit_set_title(&current_dest);
18 }
19
20 void send_message()
21 {
22      char       *buf;
23      int        ret;
24      Widget     text_source;
25
26      /* I should do more interesting things with these error conditions */
27
28      XtVaGetValues(editor, XtNstring, (XtArgVal) &buf,
29                    XtNtextSource, (XtArgVal) &text_source, NULL);
30
31      ret = zeph_send_message(&current_dest, buf);
32      XawAsciiSourceFreeString(text_source);
33
34      switch (ret) {
35      case SEND_OK:
36           break;
37      case SENDFAIL_SEND:
38      case SENDFAIL_RECV:
39      case SENDFAIL_ACK:
40           if (defs.verbose)
41                XBell(XtDisplay(toplevel), 0);
42           break;
43      }
44
45      /* Only the second argument matters */
46      if (defs.close_on_send)
47           XtCallActionProc(toplevel, "CloseSend", NULL, NULL, 0);
48
49      if (defs.clear_on_send)
50           XtCallActionProc(toplevel, "ClearEditor", NULL, NULL, 0);
51 }
52
53 void edit_set_title(dest)
54    Dest dest;
55 {
56      char       *title;
57
58      /* alloc two extra bytes  for * in case zinst or zrecip are "" */
59      title = (char *) Malloc( strlen(dest->zclass) + strlen(dest->zinst) +
60                              strlen(dest->zrecip) + 20, "while setting title",
61                              NULL);
62      sprintf(title, "Sending to <%s, %s, %s>", dest->zclass,
63              *dest->zinst ? dest->zinst : "*",
64              *dest->zrecip ? dest->zrecip : "*");
65
66      XtVaSetValues(editTitle,
67                    XtNlabel, title,
68                    NULL);
69
70      free(title);
71 }
72
73 void edit_clear()
74 {
75      XtVaSetValues(editor,
76                    XtNstring, "",
77                    NULL);
78 }
79
80 void edit_yank_prev()
81 {
82      Yank     yank;
83
84      yank = yank_prev();
85      if (! yank)
86           return;
87      
88      XtVaSetValues(editor,
89                  XtNstring, (XtArgVal) yank->msg,
90                  NULL);
91      if (defs.yank_dest) {
92         dest_set_current_dest(&yank->dest);
93         edit_set_title(&yank->dest);
94    }
95 }
96
97 void edit_yank_next()
98 {
99      Yank     yank;
100
101      yank = yank_next();
102      if (! yank)
103           return;
104      
105      XtVaSetValues(editor,
106                  XtNstring, (XtArgVal) yank->msg,
107                  NULL);
108      if (defs.yank_dest) {
109           dest_set_current_dest(&yank->dest);
110           edit_set_title(&yank->dest);
111      }
112 }
113
114 void edit_yank_store()
115 {
116      char *buf;
117      Widget text_source;
118
119      XtVaGetValues(editor, XtNstring, (XtArgVal) &buf,
120                    XtNtextSource, (XtArgVal) &text_source, NULL);
121
122      if (buf != NULL && *buf != '\0')
123           yank_store(&current_dest, buf);
124
125      XawAsciiSourceFreeString(text_source);
126 }