]> asedeno.scripts.mit.edu Git - 1ts-debian.git/blob - zephyr/clients/xzwrite/interface.c
716e0e318420f1a8af55354890d46d7d48195c22
[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) + 12);
141           if (path2 != NULL) {
142 #ifdef HAVE_PUTENV
143                sprintf(path2, "XFILESEARCHPATH=%s:%s/zephyr/%%N", path1,
144                        DATADIR);
145                putenv(path2);
146 #else
147                sprintf(path2, "%s:%s/zephyr/%%N", path1, DATADIR);
148                setenv("XFILESEARCHPATH", path2, 1);
149                free(path2);
150 #endif
151           }
152      }
153      
154      toplevel = XtVaAppInitialize(&app_con, "XZwrite", app_options,
155 #if XtSpecificationRelease > 4
156                                   num_options, argc, argv,
157 #else
158                                   num_options, (Cardinal *) argc, argv,
159 #endif
160                                   fallback_resources, NULL);
161
162      XtVaGetApplicationResources(toplevel, (XtPointer) &defs, app_resources,
163                                  num_resources, NULL);
164
165      XtAppAddActions(app_con, actionTable, XtNumber(actionTable));
166
167      /* Create the icon */
168      icon = XVCMW("icon", commandWidgetClass, toplevel, NULL);
169
170      /* Create the menu */
171      menuWindow = XtVaCreatePopupShell("menuWindow", transientShellWidgetClass,
172                                        toplevel, NULL);
173      menuForm = XVCMW("menuForm", formWidgetClass, menuWindow, NULL);
174      menuClose = XVCMW("menuClose", commandWidgetClass, menuForm, NULL);
175      signature = XVCMW("signature", commandWidgetClass, menuForm, NULL);
176      clearOnSend = XVCMW("clearOnSend", toggleWidgetClass, menuForm, NULL);
177      closeOnSend = XVCMW("closeOnSend", toggleWidgetClass, menuForm, NULL);
178      pings = XVCMW("pings", toggleWidgetClass, menuForm, NULL);
179      verbose = XVCMW("verbose", toggleWidgetClass, menuForm, NULL);
180      authentic = XVCMW("authentic", toggleWidgetClass, menuForm, NULL);
181      yankDest = XVCMW("yankDest", toggleWidgetClass, menuForm, NULL);
182      addGlobals = XVCMW("addGlobals", toggleWidgetClass, menuForm, NULL);
183      classInst = XVCMW("classInst", toggleWidgetClass, menuForm, NULL);
184      exitProgram = XVCMW("exitProgram", commandWidgetClass, menuForm, NULL);
185
186      /* Create the editor/destination list */
187      sendWindow = XtVaCreatePopupShell("sendWindow", transientShellWidgetClass,
188                                        toplevel, NULL);
189      sendForm = XVCMW("sendForm", formWidgetClass, sendWindow, NULL);
190      sendClose = XVCMW("sendClose", commandWidgetClass, sendForm, NULL);
191      
192      editPane = XVCMW("editPane", panedWidgetClass, sendForm, NULL);
193      editTitle = XVCMW("editTitle", labelWidgetClass, editPane, NULL);
194      editForm = XVCMW("editForm", formWidgetClass, editPane, NULL);
195      editSend = XVCMW("editSend", commandWidgetClass, editForm, NULL);
196      editClear = XVCMW("editClear", commandWidgetClass, editForm, NULL);
197      editPrev = XVCMW("editPrev", commandWidgetClass, editForm, NULL);
198      editNext = XVCMW("editNext", commandWidgetClass, editForm, NULL);
199      editor = XVCMW("editor", asciiTextWidgetClass, editPane, NULL);
200
201      destForm = XVCMW("destForm", formWidgetClass, sendForm, NULL);
202      destScroll = XVCMW("destScroll", viewportWidgetClass, destForm, NULL);
203      destList = XVCMW("destList", listWidgetClass, destScroll, NULL);
204
205      XtSetKeyboardFocus(sendForm, editor);
206      getString = InitGetString(toplevel, "getStringWindow");
207
208      XtAppAddInput(app_con, ZGetFD(), (XtPointer)XtInputReadMask, zeph_dispatch, NULL);
209
210      if (defs.track_logins) {
211           XtAppAddWorkProc(app_con, (XtWorkProc)login_scan_work, NULL);
212      }
213
214      set_editor_width();
215      set_sendclose_width();
216      XtRealizeWidget(toplevel);
217 }
218
219 /* Action Procedures */     
220      
221 /* ARGSUSED */
222 static void Quit(w, e, p, n)
223    Widget w;
224    XEvent *e;
225    String *p;
226    Cardinal *n;
227 {
228      XtDestroyApplicationContext(app_con);
229      ZCancelSubscriptions(0);
230      exit(0);
231 }
232
233 /* ARGSUSED */
234 static void OpenSend(w, e, p, n)
235    Widget w;
236    XEvent *e;
237    String *p;
238    Cardinal *n;
239 {
240      XtPopup(sendWindow, XtGrabNone);
241 }
242
243 /* ARGSUSED */
244 static void CloseSend(w, e, p, n)
245    Widget w;
246    XEvent *e;
247    String *p;
248    Cardinal *n;
249 {
250      XtPopdown(sendWindow);
251 }
252
253 /* ARGSUSED */
254 static void SendMessage(w, e, p, n)
255    Widget w;
256    XEvent *e;
257    String *p;
258    Cardinal *n;
259 {
260      send_message();
261 }
262
263 /* ARGSUSED */
264 static void ClearEditor(w, e, p, n)
265    Widget w;
266    XEvent *e;
267    String *p;
268    Cardinal *n;
269 {
270      edit_clear();
271 }
272
273 /* ARGSUSED */
274 static void YankStore(w, e, p, n)
275    Widget w;
276    XEvent *e;
277    String *p;
278    Cardinal *n;
279 {
280      edit_yank_store();
281 }
282
283 /* ARGSUSED */
284 static void YankPrev(w, e, p, n)
285    Widget w;
286    XEvent *e;
287    String *p;
288    Cardinal *n;
289 {
290      edit_yank_prev();
291 }
292
293 /* ARGSUSED */
294 static void YankNext(w, e, p, n)
295    Widget w;
296    XEvent *e;
297    String *p;
298    Cardinal *n;
299 {
300      edit_yank_next();
301 }
302
303 /* ARGSUSED */
304 static void AlignParagraph(w, e, p, n)
305    Widget w;
306    XEvent *e;
307    String *p;
308    Cardinal *n;
309 {
310 }
311
312 /* ARGSUSED */
313 static void SelectDest(w, e, p, n)
314    Widget w;
315    XEvent *e;
316    String *p;
317    Cardinal *n;
318 {
319      select_dest();
320 }
321
322 /* ARGSUSED */
323 static void DeleteDest(w, e, p, n)
324    Widget w;
325    XEvent *e;
326    String *p;
327    Cardinal *n;
328 {
329      delete_dest();
330 }
331
332 /* ARGSUSED */
333 static void HighlightDest(w, e, p, n)
334    Widget w;
335    XEvent *e;
336    String *p;
337    Cardinal *n;
338 {
339 }
340
341 /* ARGSUSED */
342 static void CreateDest(w, e, p, n)
343    Widget w;
344    XEvent *e;
345    String *p;
346    Cardinal *n;
347 {
348      create_dest();
349 }
350
351 /* ARGSUSED */
352 static void OpenMenu(w, e, p, n)
353    Widget w;
354    XEvent *e;
355    String *p;
356    Cardinal *n;
357 {
358      XtPopup(menuWindow, XtGrabNone);
359 }
360
361 /* ARGSUSED */
362 static void ToggleOption(w, e, p, n)
363    Widget w;
364    XEvent *e;
365    String *p;
366    Cardinal *n;
367 {
368      menu_toggle(w);
369 }
370
371 /* ARGSUSED */
372 static void Signature(w, e, p, n)
373    Widget w;
374    XEvent *e;
375    String *p;
376    Cardinal *n;
377 {
378      menu_signature();
379 }
380
381 /* ARGSUSED */
382 static void CloseMenu(w, e, p, n)
383    Widget w;
384    XEvent *e;
385    String *p;
386    Cardinal *n;
387 {
388      XtPopdown(menuWindow);
389 }
390
391 static void set_editor_width ()
392 {
393   int w, c; char m = 'm';
394   XFontStruct *fs = (XFontStruct *) NULL;
395
396   c = defs.columns;
397   /* get the font structure. */
398   XtVaGetValues(editor, XtNfont, &fs, NULL);
399   if (c < 1 || fs == (XFontStruct *) NULL) return;
400
401   /* set the editor width */
402   w = c * XTextWidth(fs, &m, 1);
403   XtVaSetValues(editor, XtNwidth, (Dimension)w, NULL);
404   
405   /* set the destList to have 3/8ths the width of the editor */
406   /* an other idea would be to make it have 3/8ths as many characters,
407      which makes a difference when the editor and destList are in
408      different fonts.
409      however, I prefer this way. */
410   XtVaSetValues(destForm, XtNwidth, (Dimension)(w*3/8), NULL);
411 }
412
413 static void set_sendclose_width ()
414 {
415   /* make the Close Window button the width of the form */
416   Dimension wi = 0;
417   XtRealizeWidget (sendWindow);
418   XtVaGetValues(sendForm, XtNwidth, &wi, NULL);
419   XtUnrealizeWidget (sendWindow);
420   XtVaSetValues(sendClose, XtNwidth, wi, NULL);
421 }