]> asedeno.scripts.mit.edu Git - 1ts-debian.git/blob - zephyr/clients/xzwrite/interface.c
This commit was generated by cvs2svn to compensate for changes in r127,
[1ts-debian.git] / zephyr / clients / xzwrite / interface.c
1 /*
2  * The xzwrite interface structure.  All top level widgets except toplevel
3  * are popup shells.
4  *
5  * toplevel - the top level shell
6  *      icon - the top level "Z" icon
7  * 
8  * sendWindow - the popup shell for the editor/destlist
9  *      sendForm - the form holding the edit tree and dest tree
10  *      sendClose - button to close sendWindow
11  * 
12  *      editPane - the pane holding editor widgets
13  *              editTitle - the label holding the zephyr triple
14  *              editForm - the box holding editor command buttons
15  *                      editSend - button to send message
16  *                      editClear - button to clear editor
17  *                      editPrev - button to yank previous
18  *                      editNext - button to yank next
19  *              editor - the text editor
20  * 
21  *      destForm - the form holding the destinations list/button
22  *              destScroll - the scrollbar holding the list
23  *                      destList - the destination list
24  * 
25  * menuWindow - the popup shell for the menu
26  *      menuForm - the form holding the menu list/button
27  *              menuClose - the Close Window button for the dest list
28  *              signature - button to change signature
29  *              clearOnSend
30  *              closeOnSend
31  *              pings
32  *              verbose
33  *              authentic
34  *              yankDest
35  *              addGlobals
36  *              classInst
37  *              exitProgram
38  *
39  * getStringWindow - the popup shell for dialog boxes (GetString.c)
40  *      getStringForm - the form containing the dialog widgets
41  *              getStringTitle - the title label width
42  *              getStringEdit - the text editor
43  *              getStringAccept - the accept button
44  *              getStringCancel - the cancel button
45  */
46
47 #include "xzwrite.h"
48 #include "GetString.h"
49
50 #include <X11/Intrinsic.h>
51 #include <X11/StringDefs.h>
52 #include <X11/Shell.h>
53 #include <X11/Xaw/Label.h>
54 #include <X11/Xaw/Command.h>
55 #include <X11/Xaw/Paned.h>
56 #include <X11/Xaw/List.h>
57 #include <X11/Xaw/Box.h>
58 #include <X11/Xaw/Form.h>
59 #include <X11/Xaw/AsciiText.h>
60 #include <X11/Xaw/Toggle.h>
61 #include <X11/Xaw/Viewport.h>
62
63 #include <zephyr/zephyr.h>      /* for ZGetFD() */
64
65 #define XVCMW XtVaCreateManagedWidget
66
67 /* Action Procedure declarations */
68 static void Quit(), SendMessage(), OpenSend(), CloseSend(),
69      ClearEditor(), YankPrev(), YankNext(), YankStore(), AlignParagraph(),
70      DeleteDest(), HighlightDest(), SelectDest(), OpenMenu(),
71      ToggleOption(), Signature(), CloseMenu(), CreateDest();
72
73 static void set_editor_width(), set_sendclose_width();
74
75 static XtActionsRec actionTable[] = {
76      /* sendWindow actions */
77      {"OpenSend", (XtActionProc) OpenSend},
78      {"CloseSend", (XtActionProc) CloseSend},
79      
80      /* Editor actions */
81      {"Quit", (XtActionProc) Quit},
82      {"SendMessage", (XtActionProc) SendMessage},
83      {"ClearEditor", (XtActionProc) ClearEditor},
84      {"YankStore", (XtActionProc) YankStore},
85      {"YankPrev", (XtActionProc) YankPrev},
86      {"YankNext", (XtActionProc) YankNext},
87      {"AlignParagraph", (XtActionProc) AlignParagraph},
88
89      /* Destination list actions */
90      {"SelectDest", (XtActionProc) SelectDest},
91      {"DeleteDest", (XtActionProc) DeleteDest},
92      {"CreateDest", (XtActionProc) CreateDest},
93      {"HighlightDest", (XtActionProc) HighlightDest},
94
95      /* Menu actions */
96      {"OpenMenu", (XtActionProc) OpenMenu},
97      {"ToggleOption", (XtActionProc) ToggleOption},
98      {"Signature", (XtActionProc) Signature},
99      {"CloseMenu", (XtActionProc) CloseMenu},
100 };
101
102 extern unsigned int num_options, num_resources;
103 extern String fallback_resources[];
104 extern XrmOptionDescRec app_options[];
105 extern XtResource app_resources[];
106
107 XtAppContext app_con;
108 Defaults defs;
109
110 /* Widgets */
111 Widget toplevel, icon, getString;
112 Widget sendWindow, sendForm, sendClose;
113 Widget destForm, destScroll, destList;
114 Widget editPane, editTitle, editForm, editSend, editClear,
115      editPrev, editNext, editor;
116 Widget menuWindow, menuForm, menuClose, signature, 
117      clearOnSend, closeOnSend, pings, verbose, authentic,
118      yankDest, addGlobals, classInst, commandMask, exitProgram;
119
120 void go()
121 {
122      XtAppMainLoop(app_con);
123 }
124
125 void build_interface(argc, argv)
126    int *argc;
127    char **argv;
128 {
129      /* Set XFILESEARCHPATH to find xzwrite's resource file */
130      /* XXX This is gross XXX */
131      {
132           char *path1, *path2;
133           
134           path1 = (char *) getenv("XFILESEARCHPATH");
135           if (! path1) path1 = "";
136           path2 = (char *) malloc(strlen(path1) +
137 #ifdef HAVE_PUTENV
138                                   strlen("XFILESEARCHPATH=") +
139 #endif
140                                   strlen(DATADIR) + 5);
141           if (path2 != NULL) {
142 #ifdef HAVE_PUTENV
143                sprintf(path2, "XFILESEARCHPATH=%s:%s/%%N", path1, DATADIR);
144                putenv(path2);
145 #else
146                sprintf(path2, "%s:%s/%N", path1, DATADIR);
147                setenv("XFILESEARCHPATH", path2, 1);
148                free(path2);
149 #endif
150           }
151      }
152      
153      toplevel = XtVaAppInitialize(&app_con, "XZwrite", app_options,
154 #if XtSpecificationRelease > 4
155                                   num_options, argc, argv,
156 #else
157                                   num_options, (Cardinal *) argc, argv,
158 #endif
159                                   fallback_resources, NULL);
160
161      XtVaGetApplicationResources(toplevel, (XtPointer) &defs, app_resources,
162                                  num_resources, NULL);
163
164      XtAppAddActions(app_con, actionTable, XtNumber(actionTable));
165
166      /* Create the icon */
167      icon = XVCMW("icon", commandWidgetClass, toplevel, NULL);
168
169      /* Create the menu */
170      menuWindow = XtVaCreatePopupShell("menuWindow", transientShellWidgetClass,
171                                        toplevel, NULL);
172      menuForm = XVCMW("menuForm", formWidgetClass, menuWindow, NULL);
173      menuClose = XVCMW("menuClose", commandWidgetClass, menuForm, NULL);
174      signature = XVCMW("signature", commandWidgetClass, menuForm, NULL);
175      clearOnSend = XVCMW("clearOnSend", toggleWidgetClass, menuForm, NULL);
176      closeOnSend = XVCMW("closeOnSend", toggleWidgetClass, menuForm, NULL);
177      pings = XVCMW("pings", toggleWidgetClass, menuForm, NULL);
178      verbose = XVCMW("verbose", toggleWidgetClass, menuForm, NULL);
179      authentic = XVCMW("authentic", toggleWidgetClass, menuForm, NULL);
180      yankDest = XVCMW("yankDest", toggleWidgetClass, menuForm, NULL);
181      addGlobals = XVCMW("addGlobals", toggleWidgetClass, menuForm, NULL);
182      classInst = XVCMW("classInst", toggleWidgetClass, menuForm, NULL);
183      exitProgram = XVCMW("exitProgram", commandWidgetClass, menuForm, NULL);
184
185      /* Create the editor/destination list */
186      sendWindow = XtVaCreatePopupShell("sendWindow", transientShellWidgetClass,
187                                        toplevel, NULL);
188      sendForm = XVCMW("sendForm", formWidgetClass, sendWindow, NULL);
189      sendClose = XVCMW("sendClose", commandWidgetClass, sendForm, NULL);
190      
191      editPane = XVCMW("editPane", panedWidgetClass, sendForm, NULL);
192      editTitle = XVCMW("editTitle", labelWidgetClass, editPane, NULL);
193      editForm = XVCMW("editForm", formWidgetClass, editPane, NULL);
194      editSend = XVCMW("editSend", commandWidgetClass, editForm, NULL);
195      editClear = XVCMW("editClear", commandWidgetClass, editForm, NULL);
196      editPrev = XVCMW("editPrev", commandWidgetClass, editForm, NULL);
197      editNext = XVCMW("editNext", commandWidgetClass, editForm, NULL);
198      editor = XVCMW("editor", asciiTextWidgetClass, editPane, NULL);
199
200      destForm = XVCMW("destForm", formWidgetClass, sendForm, NULL);
201      destScroll = XVCMW("destScroll", viewportWidgetClass, destForm, NULL);
202      destList = XVCMW("destList", listWidgetClass, destScroll, NULL);
203
204      XtSetKeyboardFocus(sendForm, editor);
205      getString = InitGetString(toplevel, "getStringWindow");
206
207      XtAppAddInput(app_con, ZGetFD(), (XtPointer)XtInputReadMask, zeph_dispatch, NULL);
208
209      if (defs.track_logins) {
210           XtAppAddWorkProc(app_con, (XtWorkProc)login_scan_work, NULL);
211      }
212
213      set_editor_width();
214      set_sendclose_width();
215      XtRealizeWidget(toplevel);
216 }
217
218 /* Action Procedures */     
219      
220 /* ARGSUSED */
221 static void Quit(w, e, p, n)
222    Widget w;
223    XEvent *e;
224    String *p;
225    Cardinal *n;
226 {
227      XtDestroyApplicationContext(app_con);
228      ZCancelSubscriptions(NULL, 0);
229      exit(0);
230 }
231
232 /* ARGSUSED */
233 static void OpenSend(w, e, p, n)
234    Widget w;
235    XEvent *e;
236    String *p;
237    Cardinal *n;
238 {
239      XtPopup(sendWindow, XtGrabNone);
240 }
241
242 /* ARGSUSED */
243 static void CloseSend(w, e, p, n)
244    Widget w;
245    XEvent *e;
246    String *p;
247    Cardinal *n;
248 {
249      XtPopdown(sendWindow);
250 }
251
252 /* ARGSUSED */
253 static void SendMessage(w, e, p, n)
254    Widget w;
255    XEvent *e;
256    String *p;
257    Cardinal *n;
258 {
259      send_message();
260 }
261
262 /* ARGSUSED */
263 static void ClearEditor(w, e, p, n)
264    Widget w;
265    XEvent *e;
266    String *p;
267    Cardinal *n;
268 {
269      edit_clear();
270 }
271
272 /* ARGSUSED */
273 static void YankStore(w, e, p, n)
274    Widget w;
275    XEvent *e;
276    String *p;
277    Cardinal *n;
278 {
279      edit_yank_store();
280 }
281
282 /* ARGSUSED */
283 static void YankPrev(w, e, p, n)
284    Widget w;
285    XEvent *e;
286    String *p;
287    Cardinal *n;
288 {
289      edit_yank_prev();
290 }
291
292 /* ARGSUSED */
293 static void YankNext(w, e, p, n)
294    Widget w;
295    XEvent *e;
296    String *p;
297    Cardinal *n;
298 {
299      edit_yank_next();
300 }
301
302 /* ARGSUSED */
303 static void AlignParagraph(w, e, p, n)
304    Widget w;
305    XEvent *e;
306    String *p;
307    Cardinal *n;
308 {
309 }
310
311 /* ARGSUSED */
312 static void SelectDest(w, e, p, n)
313    Widget w;
314    XEvent *e;
315    String *p;
316    Cardinal *n;
317 {
318      select_dest();
319 }
320
321 /* ARGSUSED */
322 static void DeleteDest(w, e, p, n)
323    Widget w;
324    XEvent *e;
325    String *p;
326    Cardinal *n;
327 {
328      delete_dest();
329 }
330
331 /* ARGSUSED */
332 static void HighlightDest(w, e, p, n)
333    Widget w;
334    XEvent *e;
335    String *p;
336    Cardinal *n;
337 {
338 }
339
340 /* ARGSUSED */
341 static void CreateDest(w, e, p, n)
342    Widget w;
343    XEvent *e;
344    String *p;
345    Cardinal *n;
346 {
347      create_dest();
348 }
349
350 /* ARGSUSED */
351 static void OpenMenu(w, e, p, n)
352    Widget w;
353    XEvent *e;
354    String *p;
355    Cardinal *n;
356 {
357      XtPopup(menuWindow, XtGrabNone);
358 }
359
360 /* ARGSUSED */
361 static void ToggleOption(w, e, p, n)
362    Widget w;
363    XEvent *e;
364    String *p;
365    Cardinal *n;
366 {
367      menu_toggle(w);
368 }
369
370 /* ARGSUSED */
371 static void Signature(w, e, p, n)
372    Widget w;
373    XEvent *e;
374    String *p;
375    Cardinal *n;
376 {
377      menu_signature();
378 }
379
380 /* ARGSUSED */
381 static void CloseMenu(w, e, p, n)
382    Widget w;
383    XEvent *e;
384    String *p;
385    Cardinal *n;
386 {
387      XtPopdown(menuWindow);
388 }
389
390 static void set_editor_width ()
391 {
392   int w, c; char m = 'm';
393   XFontStruct *fs = (XFontStruct *) NULL;
394
395   c = defs.columns;
396   /* get the font structure. */
397   XtVaGetValues(editor, XtNfont, &fs, NULL);
398   if (c < 1 || fs == (XFontStruct *) NULL) return;
399
400   /* set the editor width */
401   w = c * XTextWidth(fs, &m, 1);
402   XtVaSetValues(editor, XtNwidth, (Dimension)w, NULL);
403   
404   /* set the destList to have 3/8ths the width of the editor */
405   /* an other idea would be to make it have 3/8ths as many characters,
406      which makes a difference when the editor and destList are in
407      different fonts.
408      however, I prefer this way. */
409   XtVaSetValues(destForm, XtNwidth, (Dimension)(w*3/8), NULL);
410 }
411
412 static void set_sendclose_width ()
413 {
414   /* make the Close Window button the width of the form */
415   Dimension wi = 0;
416   XtRealizeWidget (sendWindow);
417   XtVaGetValues(sendForm, XtNwidth, &wi, NULL);
418   XtUnrealizeWidget (sendWindow);
419   XtVaSetValues(sendClose, XtNwidth, wi, NULL);
420 }