home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / x / volume17 / xwbstrmt / part02 < prev    next >
Encoding:
Text File  |  1992-04-13  |  50.3 KB  |  1,525 lines

  1. Newsgroups: comp.sources.x
  2. Path: uunet!cis.ohio-state.edu!zaphod.mps.ohio-state.edu!mips!msi!dcmartin
  3. From: cattelan@everest.ee.umn.edu (Russell Cattelan)
  4. Subject: v17i056: xwebster (MOTIF) (REPOST), Part02/03
  5. Message-ID: <1992Apr14.141542.7774@msi.com>
  6. Originator: dcmartin@fascet
  7. Sender: dcmartin@msi.com (David C. Martin - Moderator)
  8. Nntp-Posting-Host: fascet
  9. Organization: Molecular Simulations, Inc.
  10. References: <csx-17i055-xwebster-motif@uunet.UU.NET>
  11. Date: Tue, 14 Apr 1992 14:15:42 GMT
  12. Approved: dcmartin@msi.com
  13. Lines: 1510
  14.  
  15. Submitted-by: cattelan@everest.ee.umn.edu (Russell Cattelan)
  16. Posting-number: Volume 17, Issue 56
  17. Archive-name: xwebster-motif/part02
  18.  
  19. #!/bin/sh
  20. # this is part.02 (part 2 of a multipart archive)
  21. # do not concatenate these parts, unpack them in order with /bin/sh
  22. # file Xwebster.ad.hp_widgets continued
  23. #
  24. if test ! -r _shar_seq_.tmp; then
  25.     echo 'Please unpack part 1 first!'
  26.     exit 1
  27. fi
  28. (read Scheck
  29.  if test "$Scheck" != 2; then
  30.     echo Please unpack part "$Scheck" next!
  31.     exit 1
  32.  else
  33.     exit 0
  34.  fi
  35. ) < _shar_seq_.tmp || exit 1
  36. if test ! -f _shar_wnt_.tmp; then
  37.     echo 'x - still skipping Xwebster.ad.hp_widgets'
  38. else
  39. echo 'x - continuing file Xwebster.ad.hp_widgets'
  40. sed 's/^X//' << 'SHAR_EOF' >> 'Xwebster.ad.hp_widgets' &&
  41. X     Ctrl<Key>H:        delete-previous-character() \n\
  42. X     Meta<Key>D:        delete-next-word() \n\
  43. X     Meta<Key>H:        delete-previous-word() \n\
  44. X     Shift Meta<Key>H:        backward-kill-word() \n\
  45. X     Ctrl<Key>W:        kill-selection() \n\
  46. X     Ctrl<Key>K:        kill-to-end-of-line() \n\
  47. X     Meta<Key>K:        kill-to-end-of-paragraph() \n\
  48. X     Ctrl<Key>Y:        unkill() \n\
  49. X     Meta<Key>Y:        stuff() \n\
  50. X     Ctrl<Key>L:        redraw-display() \n\
  51. X     <FocusIn>:            focus-in() \n\
  52. X     <FocusOut>:        focus-out() \n\
  53. X     <Btn1Down>:        select-start() \n\
  54. X     Button1<PtrMoved>:        extend-adjust() \n\
  55. X     <Btn1Up>:            extend-end() \n\
  56. X     <Btn2Down>:        stuff() \n\
  57. X     <Btn3Down>:        extend-start() \n\
  58. X     Button3<PtrMoved>:        extend-adjust() \n\
  59. X     <Btn3Up>:            extend-end() \n\
  60. X     <Key>Execute:        execute() \n\
  61. X     <Key>:            insert-char() \n\
  62. X     Shift<Key>:        insert-char() \n\
  63. X     <EnterWindow>:        enter() \n\
  64. X     <LeaveWindow>:        leave()
  65. SHAR_EOF
  66. echo 'File Xwebster.ad.hp_widgets is complete' &&
  67. chmod 0644 Xwebster.ad.hp_widgets ||
  68. echo 'restore of Xwebster.ad.hp_widgets failed'
  69. Wc_c="`wc -c < 'Xwebster.ad.hp_widgets'`"
  70. test 19389 -eq "$Wc_c" ||
  71.     echo 'Xwebster.ad.hp_widgets: original size 19389, current size' "$Wc_c"
  72. rm -f _shar_wnt_.tmp
  73. fi
  74. # ============= controlpanel.c ==============
  75. if test -f 'controlpanel.c' -a X"$1" != X"-c"; then
  76.     echo 'x - skipping controlpanel.c (File already exists)'
  77.     rm -f _shar_wnt_.tmp
  78. else
  79. > _shar_wnt_.tmp
  80. echo 'x - extracting controlpanel.c (Text)'
  81. sed 's/^X//' << 'SHAR_EOF' > 'controlpanel.c' &&
  82. X /* -*-C-*-
  83. ********************************************************************************
  84. *
  85. * File:         controlpanel.c
  86. * RCS:          $Header: /home/everest1/cattelan/work/xwebster.motif/RCS/controlpanel.c,v 1.1 1992/03/21 22:39:43 cattelan Exp $
  87. * Description:  Control Panel for Webster
  88. * Author:       Niels Mayer, HPLabs
  89. * Created:      Wed Aug 31 21:40:58 1988
  90. * Modified:     Mon Mar  6 16:08:53 1989 (Niels Mayer) mayer@hplnpm
  91. * Language:     C
  92. * Package:      N/A
  93. * Status:       G-Job
  94. *
  95. * xwebster - dictionary browser
  96. *
  97. * Copyright 1988 Hewlett-Packard Company
  98. *
  99. * Permission to use, copy, modify, and distribute this software and its
  100. * documentation for any purpose and without fee is hereby granted, provided
  101. * that the above copyright notice appear in all copies and that both that
  102. * copyright notice and this permission notice appear in supporting
  103. * documentation, and that the name of HP not be used in advertising or
  104. * publicity pertaining to distribution of the software without specific,
  105. * written prior permission.  HP makes no representations about the
  106. * suitability of this software for any purpose.  It is provided "as is"
  107. * without express or implied warranty.
  108. *
  109. * Please send any improvements, bug fixes, useful modifications, and comments
  110. * to mayer@hplabs.hp.com.
  111. ********************************************************************************
  112. */
  113. static char rcs_identity[] = "@(#)$Header: /home/everest1/cattelan/work/xwebster.motif/RCS/controlpanel.c,v 1.1 1992/03/21 22:39:43 cattelan Exp $";
  114. X
  115. #include "xwebster.h"
  116. #include "user_prefs.h"
  117. #include <stdio.h>
  118. #include <sys/types.h>
  119. #include <sys/socket.h>
  120. #include <Xm/PushB.h>
  121. #include <Xm/Text.h>
  122. #include <Xm/TextF.h>
  123. #include <Xm/Form.h>
  124. #include <Xm/LabelG.h>
  125. /*
  126. #include <Xw/PButton.h>
  127. #include <Xw/SText.h>
  128. #include <Xw/TextEdit.h>
  129. #include <Xw/TitleBar.h>
  130. */
  131. X
  132. static Widget control_panel_Wgt = NULL;
  133. static Widget word_input_Wgt = NULL;
  134. static Widget define_button_Wgt = NULL;
  135. #ifdef DEFINE_FULL 
  136. static Widget define_full_button_Wgt = NULL;
  137. #endif /* define full */
  138. static Widget complete_button_Wgt = NULL;
  139. static Widget endings_button_Wgt = NULL;
  140. static Widget thesaurus_button_Wgt = NULL;
  141. static Widget labelbar_Wgt = NULL;
  142. static Widget formbar_Wgt = NULL;
  143. static Widget quit_button_Wgt = NULL;
  144. static Widget help_button_Wgt = NULL;
  145. static int    controlpanel_active = TRUE;
  146. static int    cur_word_is_from_textedit = TRUE;
  147. X
  148. extern int   Webster_Send(/* char* buf */);  /* from xwebster.c */
  149. extern XtAppContext webster_app;
  150. int moo; /* temp variable */
  151. /******************************************************************************
  152. X * note that this callback is used for 3 different callbacks:
  153. X * 1) called from the controlpanel define_button_Wgt with client_data==NULL,
  154. X *    this proc. assumes that word to be defined is in the word_input_Wgt.
  155. X * 2) called from Controlpanel_Define_Action (which is a actionproc that is
  156. X *    called from the word_input_Wgt) with client_data==NULL, this proc.
  157. X *    again assumes that word to be defined is in the word_input_Wgt.
  158. X * 3) called from a callback on a wordbutton_Wgt in module Wordlist, 
  159. X *    client_data is set to the word to be defined. In this case, 
  160. X *    subsequent calls to Controlpanel_Cur_Word_Is_From_TextEdit()
  161. X *    will return false.
  162. X ******************************************************************************/
  163. XXtCallbackProc 
  164. X  Controlpanel_Define_Callback(widget, client_data, call_data)
  165. Widget widget;
  166. caddr_t client_data;
  167. caddr_t call_data;
  168. {
  169. X  char buf[BUFSIZ];
  170. X  extern Display* display;
  171. X  
  172. X  if (!controlpanel_active) {
  173. X    XBell(display, 100);
  174. X    return(NULL);
  175. X  }
  176. X  
  177. X  Display_Def_Text_Reset();    /* clear the def buffer to show text is coming */
  178. X  XtVaSetValues(define_button_Wgt, 
  179. X                XmNset, TRUE,
  180. X                NULL); /*-action resulted in the callback*/
  181. X  Controlpanel_Deactivate();    /* disallow further input till ready. */
  182. X
  183. X  if (client_data == NULL) {    /* IF not called from Wordlist word button */
  184. X    char* word;                 /* THEN get the word from word_input_Wgt */
  185. X    word = (char *)XmTextFieldGetString(word_input_Wgt);
  186. X    sscanf(word, "%[^\n]", temptext); /* get only one word, no newlines */
  187. X    XtFree(word);
  188. X      sprintf(buf, "DEFINE %s\r\n", temptext);
  189. X      cur_word_is_from_textedit = TRUE;
  190. X  }
  191. X  else {            /* ELSE get the word from the callback data */
  192. X    sprintf(buf, "DEFINE %s\r\n", (char*)client_data);
  193. X    Controlpanel_Set_Input_Word((char*)client_data);
  194. X    cur_word_is_from_textedit = FALSE;
  195. X  }
  196. X  if (!Webster_Send(buf))
  197. X   Controlpanel_Reactivate();
  198. }
  199. X
  200. X
  201. X
  202. static void 
  203. X  Controlpanel_Define_Action(w, event, params, num_params)
  204. Widget w;
  205. XXEvent *event;
  206. String *params;
  207. Cardinal *num_params;
  208. {
  209. X  Controlpanel_Define_Callback(w, NULL, NULL);
  210. }
  211. X
  212. XXtCallbackProc
  213. X  Controlpanel_Define_button_Callback(widget, client_data, call_data)
  214. Widget widget;
  215. caddr_t client_data;
  216. caddr_t call_data;
  217. {
  218. X  char buf[BUFSIZ]; 
  219. X  if (!strcmp(user_prefs.dictionary_source,"next")){
  220. X  sprintf(buf,"INDEX dictionary\r\n");
  221. X  if (!Webster_Send(buf))
  222. X    Controlpanel_Reactivate();
  223. };
  224. X  Controlpanel_Define_Callback(widget, client_data, call_data);
  225. }
  226. X
  227. /******************************************************************************
  228. X *
  229. X ******************************************************************************/
  230. XXtCallbackProc
  231. X  Controlpanel_Thesaurus_button_Callback(widget, client_data, call_data)
  232. Widget widget;
  233. caddr_t client_data;
  234. caddr_t call_data;
  235. {
  236. X  char buf[BUFSIZ];
  237. X  sprintf(buf,"INDEX thesaurus\r\n");
  238. X  if (!Webster_Send(buf))
  239. X    Controlpanel_Reactivate();
  240. X  Controlpanel_Define_Callback(widget, client_data, call_data);
  241. }
  242. X
  243. static void 
  244. X  Controlpanel_Thesaurus_Action(w, event, params, num_params)
  245. X     Widget w;
  246. X     XEvent *event;
  247. X     String *params;
  248. X     Cardinal *num_params;
  249. {
  250. X  Controlpanel_Thesaurus_button_Callback(w, NULL, NULL);
  251. }
  252. /******************************************************************************
  253. X *
  254. X ******************************************************************************/
  255. #ifdef DEFINE_FULL
  256. XXtCallbackuser_prefsProc
  257. X  Controlpanel_Define_full_button_Callback(widget, client_data, call_data)
  258. Widget widget;
  259. caddr_t client_data;
  260. caddr_t call_data;
  261. {
  262. X  char buf[BUFSIZ];
  263. X    sprintf(buf,"INDEX dictionary-full\r\n");
  264. X    if (!Webster_Send(buf))
  265. X      Controlpanel_Reactivate();
  266. X  Controlpanel_Define_Callback(widget, client_data, call_data);
  267. }
  268. /******************************************************************************
  269. X *
  270. X ******************************************************************************/
  271. static void 
  272. X  Controlpanel_Define_full_Action(w, event, params, num_params)
  273. X     Widget w;
  274. X     XEvent *event;
  275. X     String *params;
  276. X     Cardinal *num_params;
  277. {
  278. X  Controlpanel_Define_full_button_Callback(w, NULL, NULL);
  279. }
  280. /******************************************************************************
  281. X *
  282. X ******************************************************************************/
  283. #endif /* Define Full */
  284. static XtCallbackProc 
  285. Controlpanel_Complete_Callback(widget, client_data, call_data)
  286. X     Widget widget;
  287. X     caddr_t client_data;
  288. X     caddr_t call_data;
  289. {
  290. X  char buf[BUFSIZ];
  291. X  char* word;
  292. X  extern Display* display;
  293. X
  294. X  if (!controlpanel_active) {
  295. X    XBell(display, 100);
  296. X    return(NULL);
  297. X  }
  298. X
  299. X  /* show em which button they hit even if a key-*/
  300. X  XtVaSetValues(complete_button_Wgt,
  301. X        XmNset, TRUE,
  302. X        NULL); /*-action resulted in the callback*/
  303. X  Controlpanel_Deactivate();    /* disallow further input till ready. */
  304. X  word = (char *)XmTextFieldGetString(word_input_Wgt);
  305. X  sscanf(word, "%[^\n]", temptext); /* don't get newlines */
  306. X  XtFree(word); 
  307. X  sprintf(buf, "COMPLETE %s\r\n", temptext);
  308. X  cur_word_is_from_textedit = TRUE;
  309. X  if (!Webster_Send(buf))
  310. X    Controlpanel_Reactivate();
  311. }
  312. X
  313. /******************************************************************************
  314. X *
  315. X ******************************************************************************/
  316. static void 
  317. X  Controlpanel_Complete_Action(w, event, params, num_params)
  318. X     Widget w;
  319. X     XEvent *event;
  320. X     String *params;
  321. X     Cardinal *num_params;
  322. {
  323. X  Controlpanel_Complete_Callback(w, NULL, NULL);
  324. }
  325. X
  326. /******************************************************************************
  327. X *
  328. X ******************************************************************************/
  329. static XtCallbackProc 
  330. Controlpanel_Endings_Callback(widget, client_data, call_data)
  331. X     Widget widget;
  332. X     caddr_t client_data;
  333. X     caddr_t call_data;
  334. {
  335. X  char buf[BUFSIZ];
  336. X  char* word;
  337. X  extern Display* display;
  338. X
  339. X  if (!controlpanel_active) {
  340. X    XBell(display, 100);
  341. X    return(NULL);
  342. X  }
  343. X   
  344. X  XtVaSetValues(endings_button_Wgt,
  345. X        XmNset, TRUE,
  346. X        NULL); /*-action resulted in the callback*/
  347. X  Controlpanel_Deactivate();    /* disallow further input till ready. */
  348. X  word = (char *)XmTextFieldGetString(word_input_Wgt);
  349. X  sscanf(word, "%[^\n]", temptext); /* get only one word, no newlines */
  350. X  XtFree(word); 
  351. X  sprintf(buf, "ENDINGS %s\r\n", temptext);
  352. X  cur_word_is_from_textedit = TRUE;
  353. X  if (!Webster_Send(buf))
  354. X    Controlpanel_Reactivate();
  355. }
  356. X
  357. /******************************************************************************
  358. X *
  359. X ******************************************************************************/
  360. static void 
  361. X  Controlpanel_Endings_Action(w, event, params, num_params)
  362. X     Widget w;
  363. X     XEvent *event;
  364. X     String *params;
  365. X     Cardinal *num_params;
  366. {
  367. X  Controlpanel_Endings_Callback(w, NULL, NULL);
  368. }
  369. X
  370. X
  371. /******************************************************************************
  372. X *
  373. X ******************************************************************************/
  374. static XtCallbackProc 
  375. X  Controlpanel_Quit_Callback(widget, client_data, call_data)
  376. X     Widget widget;
  377. X     caddr_t client_data;
  378. X     caddr_t call_data;
  379. {
  380. X  /* 
  381. X   * note that the quit button is the only one that remains active all the time.
  382. X   * That's becauese it's ok to quit xwebster anytime even when it hasn't
  383. X   * completed it's transaction with the webster server.
  384. X   */
  385. X  extern int webster_Socket;    /* in main.c */
  386. X  close(webster_Socket);
  387. X  exit(0);
  388. }
  389. X
  390. X
  391. /******************************************************************************
  392. X *
  393. X ******************************************************************************/
  394. static XtCallbackProc 
  395. Controlpanel_Help_Callback(widget, client_data, call_data)
  396. X     Widget widget;
  397. X     caddr_t client_data;
  398. X     caddr_t call_data;
  399. {
  400. X  extern Display* display;
  401. X
  402. X  if (!controlpanel_active) {
  403. X    XBell(display, 100);
  404. X    return(NULL);
  405. X  }
  406. X
  407. X  Display_Def_Show_Help();
  408. }
  409. X
  410. X
  411. /******************************************************************************
  412. X *
  413. X ******************************************************************************/
  414. static void 
  415. Controlpanel_Noop_Action(w, event, params, num_params)
  416. X     Widget w;
  417. X     XEvent *event;
  418. X     String *params;
  419. X     Cardinal *num_params;
  420. {
  421. X  extern Display* display;
  422. X
  423. X  XBell(display, 100);
  424. }
  425. X
  426. X
  427. XXtActionsRec word_input_Wgt_actions_table [] = {
  428. X  {"webster-define-word",   Controlpanel_Define_Action},
  429. X  {"webster-complete-word", Controlpanel_Complete_Action},
  430. X  {"webster-list-endings",  Controlpanel_Endings_Action},
  431. X  {"webster-thesaurus-word", Controlpanel_Thesaurus_Action},
  432. X  {"webster-no-op",         Controlpanel_Noop_Action},
  433. };
  434. X
  435. /******************************************************************************
  436. X *
  437. X ******************************************************************************/
  438. void
  439. X  Controlpanel_Init(w)
  440. Widget w;
  441. {
  442. X  control_panel_Wgt = XtVaCreateManagedWidget("control_panel", 
  443. X                          xmFormWidgetClass,
  444. X                          w,
  445. X                          NULL);
  446. X  word_input_Wgt = XtVaCreateManagedWidget("word_input",
  447. X                       xmTextFieldWidgetClass,
  448. X                       control_panel_Wgt, 
  449. X                       XmNbottomAttachment, XmATTACH_FORM,
  450. X                       XmNtopAttachment, XmATTACH_FORM,
  451. X                       NULL); 
  452. /*
  453. X  XtAddCallback(word_input_Wgt,
  454. X        XmNactivateCallback, 
  455. X        (XtCallbackProc)Controlpanel_Define_Callback, 
  456. X        NULL);
  457. */
  458. X  XtAppAddActions(webster_app,
  459. X          word_input_Wgt_actions_table, 
  460. X          XtNumber(word_input_Wgt_actions_table));
  461. X  
  462. X
  463. X  define_button_Wgt = XtVaCreateManagedWidget("define", 
  464. X                          xmPushButtonWidgetClass, 
  465. X                          control_panel_Wgt, 
  466. X                          XmNleftAttachment,XmATTACH_WIDGET, 
  467. X                          XmNleftWidget, word_input_Wgt, 
  468. X                          XmNbottomAttachment, XmATTACH_FORM, 
  469. X                          XmNtopAttachment, XmATTACH_FORM,
  470. X                          NULL);
  471. X  
  472. X  XtAddCallback(define_button_Wgt, 
  473. X        XmNactivateCallback, 
  474. X        (XtCallbackProc)Controlpanel_Define_button_Callback, 
  475. X        NULL);
  476. X
  477. #ifdef DEFINE_FULL
  478. define_full_button_Wgt = XtVaCreateManagedWidget("define_full", 
  479. X                         xmPushButtonWidgetClass, 
  480. X                         control_panel_Wgt, 
  481. X                         XmNleftAttachment,XmATTACH_WIDGET, 
  482. X                         XmNleftWidget, define_button_Wgt, 
  483. X                         XmNbottomAttachment, XmATTACH_FORM, 
  484. X                         XmNtopAttachment, XmATTACH_FORM,
  485. X                         NULL);
  486. X
  487. X  XtAddCallback(define_full_button_Wgt, 
  488. X        XmNactivateCallback, 
  489. X        (XtCallbackProc)Controlpanel_Define_full_button_Callback, 
  490. X        NULL);
  491. #endif /* Define full */
  492. X  complete_button_Wgt = XtVaCreateManagedWidget("complete", 
  493. X                        xmPushButtonWidgetClass, 
  494. X                        control_panel_Wgt, 
  495. X                        XmNleftAttachment,XmATTACH_WIDGET, 
  496. #ifdef DEFINE_FULL
  497. X                        XmNleftWidget,define_full_button_Wgt, 
  498. #else
  499. X                        XmNleftWidget,define_button_Wgt,
  500. #endif /* Define full */
  501. X                        XmNbottomAttachment, XmATTACH_FORM, 
  502. X                        XmNtopAttachment, XmATTACH_FORM,
  503. X                        NULL);
  504. X  
  505. X  XtAddCallback(complete_button_Wgt, 
  506. X        XmNactivateCallback, 
  507. X        (XtCallbackProc)Controlpanel_Complete_Callback, 
  508. X        NULL);
  509. X
  510. X  endings_button_Wgt = XtVaCreateManagedWidget("endings", 
  511. X                           xmPushButtonWidgetClass, 
  512. X                           control_panel_Wgt,
  513. X                           XmNleftAttachment,XmATTACH_WIDGET, 
  514. X                           XmNleftWidget,complete_button_Wgt, 
  515. X                           XmNbottomAttachment, XmATTACH_FORM, 
  516. X                           XmNtopAttachment, XmATTACH_FORM,
  517. X                           NULL);
  518. X  XtAddCallback(endings_button_Wgt, 
  519. X        XmNactivateCallback, 
  520. X        (XtCallbackProc)Controlpanel_Endings_Callback, 
  521. X        NULL);
  522. X  
  523. X  thesaurus_button_Wgt = XtVaCreateWidget("thesaurus", 
  524. X                      xmPushButtonWidgetClass, 
  525. X                      control_panel_Wgt,
  526. X                      XmNleftAttachment,XmATTACH_WIDGET, 
  527. X                      XmNleftWidget, endings_button_Wgt ,  
  528. X                      XmNbottomAttachment, XmATTACH_FORM, 
  529. X                      XmNtopAttachment, XmATTACH_FORM,
  530. X                      NULL);
  531. X  if (!strcmp(user_prefs.dictionary_source,"next"))
  532. X    XtManageChild(thesaurus_button_Wgt);
  533. X  
  534. X  XtAddCallback(thesaurus_button_Wgt, 
  535. X        XmNactivateCallback, 
  536. X        (XtCallbackProc)Controlpanel_Thesaurus_button_Callback, 
  537. X        NULL);
  538. X  
  539. X  {/*
  540. X    * force the controlpanel to have no sash's -- do this by setting XtNmin
  541. X    * and XtNmax constraint resources to the same values -- the height of the
  542. X    * widget. See XWVPANED(3x) for details.
  543. X    */
  544. X    Dimension height;
  545. X    XtVaGetValues(control_panel_Wgt, 
  546. X          XmNheight, &height,
  547. X          NULL);
  548. X
  549. X    XtVaSetValues(control_panel_Wgt, 
  550. X          XmNminHeight, height,
  551. X          XmNmaxHeight, height,
  552. X          NULL);
  553. X
  554. X  }
  555. }
  556. X
  557. /******************************************************************************
  558. X *
  559. X ******************************************************************************/
  560. void
  561. Controlpanel_Titlebar_Init(parent_Wgt)
  562. X     Widget parent_Wgt;
  563. {
  564. X  extern char xwebster_version[]; 
  565. X  XmString label = XmStringCreateSimple(xwebster_version);
  566. X
  567. X  formbar_Wgt = XtVaCreateManagedWidget("titlebar",
  568. X                     xmFormWidgetClass,
  569. X                     parent_Wgt, 
  570. X                     NULL);
  571. X
  572. X    quit_button_Wgt = XtVaCreateManagedWidget("quit", 
  573. X                          xmPushButtonWidgetClass,
  574. X                          formbar_Wgt,
  575. X                          XmNleftAttachment, XmATTACH_FORM,
  576. X                          NULL);
  577. X
  578. X  XtAddCallback(quit_button_Wgt,
  579. X        XmNactivateCallback, 
  580. X        (XtCallbackProc)Controlpanel_Quit_Callback,
  581. X        NULL);
  582. X  
  583. X  help_button_Wgt = XtVaCreateManagedWidget("help",
  584. X                        xmPushButtonWidgetClass,
  585. X                        formbar_Wgt,
  586. X                        XmNrightAttachment,XmATTACH_FORM,
  587. X                        NULL);
  588. X  XtAddCallback(help_button_Wgt, 
  589. X        XmNactivateCallback, 
  590. X        (XtCallbackProc)Controlpanel_Help_Callback, 
  591. X        NULL);
  592. X
  593. X  labelbar_Wgt = XtVaCreateManagedWidget("labelbar",
  594. X                     xmLabelWidgetClass,
  595. X                     formbar_Wgt, 
  596. X                     XmNlabelString, label,
  597. X                     XmNleftAttachment, XmATTACH_WIDGET,
  598. X                     XmNleftWidget, quit_button_Wgt,
  599. X                     XmNalignment, XmALIGNMENT_CENTER,
  600. X                     XmNrightAttachment, XmATTACH_WIDGET,
  601. X                     XmNrightWidget, help_button_Wgt,
  602. X                     NULL);
  603. X  XmStringFree(label);
  604. X
  605. X  
  606. X
  607. X  {/*
  608. X    * force the titlebar to have no sash's -- do this by setting XtNmin
  609. X    * and XtNmax constraint resources to the same values -- the height of the
  610. X    * widget. See XWVPANED(3x) for details.
  611. X    */
  612. X    Dimension height;
  613. X    XtVaGetValues(formbar_Wgt,
  614. X          XmNheight, &height,
  615. X          NULL);
  616. X    XtVaSetValues(formbar_Wgt, 
  617. X          XmNminHeight, height,
  618. X          XmNmaxHeight, height,
  619. X          NULL);
  620. X  }
  621. }
  622. X
  623. X
  624. /******************************************************************************
  625. X *
  626. X ******************************************************************************/
  627. Controlpanel_Titlebar_Set_Label(str)
  628. X     char* str;
  629. {
  630. X XmString label = XmStringCreateSimple(str);
  631. X  XtVaSetValues(labelbar_Wgt, 
  632. X          XmNlabelString, label,
  633. X          NULL);
  634. X XmStringFree(label);
  635. }
  636. X
  637. X
  638. /******************************************************************************
  639. X *
  640. X ******************************************************************************/
  641. Controlpanel_Deactivate()
  642. {
  643. X  controlpanel_active = FALSE;
  644. X  
  645. #ifndef SLOW_X_SERVER
  646. X  XtSetSensitive(define_button_Wgt, FALSE);
  647. #ifdef DEFINE_FULL
  648. X  XtSetSensitive(define_full_button_Wgt, FALSE);
  649. #endif /* Define full */
  650. X  XtSetSensitive(complete_button_Wgt, FALSE);
  651. X  XtSetSensitive(endings_button_Wgt, FALSE);
  652. X  XtSetSensitive(thesaurus_button_Wgt, FALSE);
  653. X  /* XtSetSensitive(quit_button_Wgt, FALSE); --> allow quit while server busy*/
  654. X  XtSetSensitive(help_button_Wgt, FALSE);
  655. X  Wordlist_Deactivate();
  656. #endif
  657. }
  658. X
  659. /******************************************************************************
  660. X *
  661. X ******************************************************************************/
  662. Controlpanel_Reactivate()
  663. {
  664. X  controlpanel_active = TRUE;
  665. X
  666. #ifndef SLOW_X_SERVER
  667. X  XtSetSensitive(define_button_Wgt, TRUE);
  668. #ifdef DEFINE_FULL
  669. X  XtSetSensitive(define_full_button_Wgt, TRUE);
  670. #endif /* Define Full */
  671. X  XtSetSensitive(complete_button_Wgt, TRUE);
  672. X  XtSetSensitive(endings_button_Wgt, TRUE); 
  673. X  XtSetSensitive(thesaurus_button_Wgt, TRUE);
  674. X  /* XtSetSensitive(quit_button_Wgt, TRUE); */
  675. X  XtSetSensitive(help_button_Wgt, TRUE);
  676. X  Wordlist_Reactivate();
  677. #endif
  678. X
  679. X  /* 
  680. X   * the following is a lamo hack to fix a "feature" of PushButtons -- when they're
  681. X   *  pressed, they invert colors. if the push callback then insensitizes them,
  682. X   *  upon resensitizing they'll not invert back to the "off" color. So force them
  683. X   *  off here. 
  684. X   */
  685. X
  686. X  XtVaSetValues(define_button_Wgt, 
  687. X        XmNset, FALSE,
  688. X        NULL); 
  689. #ifdef DEFINE_FULL
  690. X  XtVaSetValues(define_full_button_Wgt, 
  691. X        XmNset, FALSE,
  692. X        NULL);
  693. #endif /* Define full */
  694. X  XtVaSetValues(complete_button_Wgt, 
  695. X        XmNset, FALSE,
  696. X        NULL);
  697. X  XtVaSetValues(endings_button_Wgt, 
  698. X        XmNset, FALSE,
  699. X        NULL);
  700. X  XtVaSetValues(thesaurus_button_Wgt, 
  701. X        XmNset, FALSE,
  702. X        NULL); 
  703. X  XtVaSetValues(quit_button_Wgt, 
  704. X        XmNset, FALSE,
  705. X        NULL);
  706. X  XtVaSetValues(help_button_Wgt, 
  707. X        XmNset, FALSE,
  708. X        NULL);
  709. X
  710. }
  711. X
  712. /******************************************************************************
  713. X *
  714. X ******************************************************************************/
  715. Controlpanel_Set_Input_Word(word)
  716. X     char* word;
  717. {
  718. X  XmTextFieldSetString(word_input_Wgt,word); 
  719. X  XmTextFieldSetInsertionPosition(word_input_Wgt, XmTextGetLastPosition(word_input_Wgt));
  720. }
  721. X
  722. /******************************************************************************
  723. X *
  724. X ******************************************************************************/
  725. int Controlpanel_Cur_Word_Is_From_TextEdit()
  726. {
  727. X  return(cur_word_is_from_textedit);
  728. }
  729. SHAR_EOF
  730. chmod 0644 controlpanel.c ||
  731. echo 'restore of controlpanel.c failed'
  732. Wc_c="`wc -c < 'controlpanel.c'`"
  733. test 19720 -eq "$Wc_c" ||
  734.     echo 'controlpanel.c: original size 19720, current size' "$Wc_c"
  735. rm -f _shar_wnt_.tmp
  736. fi
  737. # ============= display_def.c ==============
  738. if test -f 'display_def.c' -a X"$1" != X"-c"; then
  739.     echo 'x - skipping display_def.c (File already exists)'
  740.     rm -f _shar_wnt_.tmp
  741. else
  742. > _shar_wnt_.tmp
  743. echo 'x - extracting display_def.c (Text)'
  744. sed 's/^X//' << 'SHAR_EOF' > 'display_def.c' &&
  745. /* -*-C-*-
  746. ********************************************************************************
  747. *
  748. * File:         display_def.c
  749. * RCS:          $Header: /home/everest1/cattelan/work/xwebster.motif/RCS/display_def.c,v 1.1 1992/03/21 22:39:43 cattelan Exp $
  750. * Description:  Module for clearing, appending to and displaying a definition.
  751. * Author:       Niels Mayer, HPLabs
  752. * Created:      Wed Aug 31 19:17:42 1988
  753. * Modified:     Mon Mar  6 17:16:58 1989 (Niels Mayer) mayer@hplnpm
  754. * Language:     C
  755. * Package:      N/A
  756. * Status:       G-Job
  757. *
  758. * xwebster - dictionary browser
  759. *
  760. * Copyright 1988 Hewlett-Packard Company
  761. *
  762. * Permission to use, copy, modify, and distribute this software and its
  763. * documentation for any purpose and without fee is hereby granted, provided
  764. * that the above copyright notice appear in all copies and that both that
  765. * copyright notice and this permission notice appear in supporting
  766. * documentation, and that the name of HP not be used in advertising or
  767. * publicity pertaining to distribution of the software without specific,
  768. * written prior permission.  HP makes no representations about the
  769. * suitability of this software for any purpose.  It is provided "as is"
  770. * without express or implied warranty.
  771. *
  772. * Please send any improvements, bug fixes, useful modifications, and comments
  773. * to mayer@hplabs.hp.com.
  774. ********************************************************************************
  775. */
  776. static char rcs_identity[] = "@(#)$Header: /home/everest1/cattelan/work/xwebster.motif/RCS/display_def.c,v 1.1 1992/03/21 22:39:43 cattelan Exp $";
  777. X
  778. #include "xwebster.h"
  779. #include "user_prefs.h"
  780. #include <Xm/ScrolledW.h>
  781. #include <Xm/Text.h>
  782. X
  783. X
  784. static Widget display_Wgt = NULL;
  785. static char   text[16384]; /* hopefully no def will be longer than this! */
  786. static int    end_idx = 0;
  787. X
  788. X
  789. /******************************************************************************
  790. X * KLUDGE_O_RAMA: on select, invert the text in the StaticText widget to show 
  791. X * that something's being done and store the definition in the cut buffer.
  792. X ******************************************************************************/
  793. static XtCallbackProc 
  794. X  Display_Select_Callback(widget, client_data, call_data)
  795. X     Widget widget;
  796. X     caddr_t client_data;
  797. X     caddr_t call_data;
  798. {
  799. X  Pixel foreground;
  800. X  Pixel background;
  801. X  char* displ_text;
  802. X
  803. X  XtVaGetValues(widget, 
  804. X          XmNforeground, &foreground,
  805. X          XmNbackground, &background,
  806. X          NULL);
  807. X
  808. X  XtVaSetValues(widget, 
  809. X          XmNforeground, background,
  810. X          XmNbackground, foreground,
  811. X          NULL);
  812. X  
  813. X  XtVaGetValues(display_Wgt, 
  814. X          XmNstring, &displ_text,
  815. X          NULL);
  816. X  XStoreBuffer(XtDisplay(widget), displ_text, strlen(displ_text), 0);
  817. }
  818. X
  819. X
  820. /******************************************************************************
  821. X * KLUDGE_O_RAMA: on release, uninvert the text in the StaticText widget.
  822. X ******************************************************************************/
  823. static XtCallbackProc 
  824. X  Display_Release_Callback(widget, client_data, call_data)
  825. X     Widget widget;
  826. X     caddr_t client_data;
  827. X     caddr_t call_data;
  828. {
  829. X  Pixel foreground;
  830. X  Pixel background;
  831. X
  832. X  /* 
  833. X   * Uninvert the display that was inverted in Display_Select_Callback
  834. X   */
  835. X
  836. X  XtVaGetValues(widget,
  837. X          XmNforeground, &foreground,
  838. X          XmNbackground, &background,
  839. X          NULL);
  840. X
  841. X  XtVaSetValues(widget, 
  842. X          XmNforeground, background,
  843. X          XmNbackground, foreground,
  844. X          NULL);
  845. }
  846. X
  847. X
  848. /******************************************************************************
  849. X *
  850. X ******************************************************************************/
  851. void
  852. X  Display_Def_Init(w)
  853. X     Widget w;
  854. {
  855. X
  856. X    Widget display_scroller_Wgt = XtVaCreateManagedWidget("display_scroller", 
  857. X                              xmScrolledWindowWidgetClass,
  858. X                              w, 
  859. X                              XmNscrollingPolicy, XmAPPLICATION_DEFINED,
  860. X                              XmNscrollHorizontal, False,
  861. X                              XmNwordWrap, True,
  862. X                              NULL);
  863. X
  864. X    display_Wgt = XtVaCreateManagedWidget("display", 
  865. X                      xmTextWidgetClass, 
  866. X                      display_scroller_Wgt, 
  867. X                      XmNeditMode, XmMULTI_LINE_EDIT, 
  868. X                      XmNeditable, FALSE,
  869. X                      NULL);
  870. X
  871. X
  872. X    XtAddCallback(display_Wgt, 
  873. X          XmNactivateCallback,  
  874. X          (XtCallbackProc) Display_Select_Callback, 
  875. X          NULL);
  876. /*     XtAddCallback(display_Wgt, XmNrelease, Display_Release_Callback, NULL); */
  877. /*    XtAddCallback(display_Wgt, XmNactivateCallback, Display_Release_Callback, NULL);*/
  878. X
  879. }
  880. X
  881. X
  882. /******************************************************************************
  883. X *
  884. X ******************************************************************************/
  885. Display_Def_Text_Reset()
  886. {
  887. X  /* Set it to null to clear the current text */
  888. X  XmTextSetString(display_Wgt,NULL);
  889. }
  890. X
  891. X
  892. /******************************************************************************
  893. X *
  894. X ******************************************************************************/
  895. Display_Def_Text_Append(intext)
  896. X     char* intext;
  897. {
  898. X  /* Insert seems to work better for mutiple lines, there may be a better way although */
  899. X  XmTextInsert(display_Wgt, XmTextGetLastPosition(display_Wgt),intext);
  900. }
  901. X
  902. X
  903. /******************************************************************************
  904. X *
  905. X ******************************************************************************/
  906. Display_Def_Refresh()
  907. {
  908. X  /* 
  909. X    *This function could probably be removed  but I don't want to 
  910. X    *Bother with it right now, not that important
  911. X     */
  912. X  XmTextSetInsertionPosition(display_Wgt, 0);
  913. }
  914. X
  915. X
  916. /******************************************************************************
  917. X *
  918. X ******************************************************************************/
  919. Display_Def_Show_Help()
  920. {
  921. Display_Def_Text_Reset();
  922. Display_Def_Text_Append(user_prefs.help_text);
  923. Display_Def_Refresh();
  924. }
  925. SHAR_EOF
  926. chmod 0644 display_def.c ||
  927. echo 'restore of display_def.c failed'
  928. Wc_c="`wc -c < 'display_def.c'`"
  929. test 5712 -eq "$Wc_c" ||
  930.     echo 'display_def.c: original size 5712, current size' "$Wc_c"
  931. rm -f _shar_wnt_.tmp
  932. fi
  933. # ============= patchlevel.h ==============
  934. if test -f 'patchlevel.h' -a X"$1" != X"-c"; then
  935.     echo 'x - skipping patchlevel.h (File already exists)'
  936.     rm -f _shar_wnt_.tmp
  937. else
  938. > _shar_wnt_.tmp
  939. echo 'x - extracting patchlevel.h (Text)'
  940. sed 's/^X//' << 'SHAR_EOF' > 'patchlevel.h' &&
  941. #define PATCHLEVEL 0
  942. SHAR_EOF
  943. chmod 0644 patchlevel.h ||
  944. echo 'restore of patchlevel.h failed'
  945. Wc_c="`wc -c < 'patchlevel.h'`"
  946. test 21 -eq "$Wc_c" ||
  947.     echo 'patchlevel.h: original size 21, current size' "$Wc_c"
  948. rm -f _shar_wnt_.tmp
  949. fi
  950. # ============= user_prefs.h ==============
  951. if test -f 'user_prefs.h' -a X"$1" != X"-c"; then
  952.     echo 'x - skipping user_prefs.h (File already exists)'
  953.     rm -f _shar_wnt_.tmp
  954. else
  955. > _shar_wnt_.tmp
  956. echo 'x - extracting user_prefs.h (Text)'
  957. sed 's/^X//' << 'SHAR_EOF' > 'user_prefs.h' &&
  958. /* -*-C-*-
  959. ********************************************************************************
  960. *
  961. * File:         user_prefs.h
  962. * RCS:          $Header: /home/everest1/cattelan/work/xwebster.motif/RCS/user_prefs.h,v 1.1 1992/03/21 22:39:43 cattelan Exp $
  963. * Description:  type definition and global datastructure for user preferences
  964. * Author:       Niels Mayer, HPLabs
  965. * Created:      Thu Aug 11 00:06:04 1988
  966. * Modified:     Tue Sep 13 15:34:34 1988 (Niels Mayer) mayer@hplnpm
  967. * Language:     C
  968. * Package:      N/A
  969. * Status:       G-Job
  970. *
  971. * xwebster - dictionary browser
  972. *
  973. * Copyright 1988 Hewlett-Packard Company
  974. *
  975. * Permission to use, copy, modify, and distribute this software and its
  976. * documentation for any purpose and without fee is hereby granted, provided
  977. * that the above copyright notice appear in all copies and that both that
  978. * copyright notice and this permission notice appear in supporting
  979. * documentation, and that the name of HP not be used in advertising or
  980. * publicity pertaining to distribution of the software without specific,
  981. * written prior permission.  HP makes no representations about the
  982. * suitability of this software for any purpose.  It is provided "as is"
  983. * without express or implied warranty.
  984. *
  985. * Please send any improvements, bug fixes, useful modifications, and comments
  986. * to mayer@hplabs.hp.com.
  987. ********************************************************************************
  988. */
  989. static char rcs_identity_user_prefs[] = "@(#)$Header: /home/everest1/cattelan/work/xwebster.motif/RCS/user_prefs.h,v 1.1 1992/03/21 22:39:43 cattelan Exp $";
  990. X
  991. typedef struct {
  992. X  String help_text;
  993. X  String host_addr_list;    /* a list of whitespace separated host addrs */
  994. X  int    host_port;
  995. X  String host_service_name;
  996. X  int    num_words_before_refresh;
  997. X  String dictionary_source;
  998. } USER_PREFS_DATA, *USER_PREFS_DATA_PTR;
  999. X
  1000. extern USER_PREFS_DATA user_prefs;
  1001. SHAR_EOF
  1002. chmod 0644 user_prefs.h ||
  1003. echo 'restore of user_prefs.h failed'
  1004. Wc_c="`wc -c < 'user_prefs.h'`"
  1005. test 1870 -eq "$Wc_c" ||
  1006.     echo 'user_prefs.h: original size 1870, current size' "$Wc_c"
  1007. rm -f _shar_wnt_.tmp
  1008. fi
  1009. # ============= wordlist.c ==============
  1010. if test -f 'wordlist.c' -a X"$1" != X"-c"; then
  1011.     echo 'x - skipping wordlist.c (File already exists)'
  1012.     rm -f _shar_wnt_.tmp
  1013. else
  1014. > _shar_wnt_.tmp
  1015. echo 'x - extracting wordlist.c (Text)'
  1016. sed 's/^X//' << 'SHAR_EOF' > 'wordlist.c' &&
  1017. /* -*-C-*-
  1018. ********************************************************************************
  1019. *
  1020. * File:         wordlist.c
  1021. * RCS:          $Header: /home/everest1/cattelan/work/xwebster.motif/RCS/wordlist.c,v 1.1 1992/03/21 22:39:43 cattelan Exp $
  1022. * Description:  Module to display a list of words
  1023. * Author:       Niels Mayer, HPLabs
  1024. * Created:      Wed Aug 31 21:17:29 1988
  1025. * Modified:     Mon Mar  6 17:17:00 1989 (Niels Mayer) mayer@hplnpm
  1026. * Language:     C
  1027. * Package:      N/A
  1028. * Status:       G-Job
  1029. *
  1030. * xwebster - dictionary browser
  1031. *
  1032. * Copyright 1988 Hewlett-Packard Company
  1033. *
  1034. * Permission to use, copy, modify, and distribute this software and its
  1035. * documentation for any purpose and without fee is hereby granted, provided
  1036. * that the above copyright notice appear in all copies and that both that
  1037. * copyright notice and this permission notice appear in supporting
  1038. * documentation, and that the name of HP not be used in advertising or
  1039. * publicity pertaining to distribution of the software without specific,
  1040. * written prior permission.  HP makes no representations about the
  1041. * suitability of this software for any purpose.  It is provided "as is"
  1042. * without express or implied warranty.
  1043. *
  1044. * Please send any improvements, bug fixes, useful modifications, and comments
  1045. * to mayer@hplabs.hp.com.
  1046. ********************************************************************************
  1047. */
  1048. static char rcs_identity[] = "@(#)$Header: /home/everest1/cattelan/work/xwebster.motif/RCS/wordlist.c,v 1.1 1992/03/21 22:39:43 cattelan Exp $";
  1049. X
  1050. #include "xwebster.h"
  1051. #include "user_prefs.h"
  1052. #include <Xm/ScrolledW.h>
  1053. #include <Xm/RowColumn.h>
  1054. #include <Xm/PushB.h>
  1055. X
  1056. static Widget wordlist_Wgt = NULL;
  1057. static Widget wordlist_scroller_Wgt = NULL;
  1058. static Widget wordlist[16384];    /* hopefully, people won't be listing this many words */
  1059. static int    wordlist_base = 0; /* points to the first elt to be managed */
  1060. static int    wordlist_idx = 0;    /* points to the elt after last in wordlist */
  1061. X
  1062. extern XtCallbackProc Controlpanel_Define_Callback();
  1063. X
  1064. /******************************************************************************
  1065. X *
  1066. X ******************************************************************************/
  1067. Wordlist_Init(parent_Wgt)
  1068. X     Widget parent_Wgt;
  1069. {
  1070. X  wordlist_scroller_Wgt = XtVaCreateManagedWidget("wordlist_scroller", 
  1071. X                          xmScrolledWindowWidgetClass,
  1072. X                          parent_Wgt,
  1073. X                          XmNscrollingPolicy, XmAUTOMATIC,
  1074. X                          NULL);
  1075. X  wordlist_Wgt = XtVaCreateManagedWidget("wordlist", 
  1076. X                     xmRowColumnWidgetClass,
  1077. X                     wordlist_scroller_Wgt,
  1078. X                     XmNadjustLast, False,
  1079. X                     XmNpacking, XmPACK_COLUMN,
  1080. X                     NULL);
  1081. }
  1082. X
  1083. X
  1084. /******************************************************************************
  1085. X * Clears all the buttons.
  1086. X ******************************************************************************/
  1087. Wordlist_Reset()
  1088. {
  1089. X  register int i;
  1090. X
  1091. X  /*
  1092. X   * the following seems to prevent a ridiculous amount of display updating 
  1093. X   * thatwas occuring as each widget got deleted and others moved to fill the
  1094. X   * gap
  1095. X   */
  1096. X  XtUnmanageChildren(wordlist, wordlist_idx);
  1097. X
  1098. X  /*
  1099. X   * Now we can delete all the word widgets with a minimum of display noize
  1100. X   */
  1101. X  for (i=0; (i < wordlist_idx); i++) {
  1102. X    XtDestroyWidget(wordlist[i]);
  1103. X  }
  1104. X  wordlist_idx = 0;
  1105. X  wordlist_base = 0;
  1106. }
  1107. X
  1108. /******************************************************************************
  1109. X *
  1110. X ******************************************************************************/
  1111. static XtCallbackProc Wordlist_Button_Destroy_Callback(widget, client_data, call_data)
  1112. X     Widget widget;
  1113. X     caddr_t client_data;
  1114. X     caddr_t call_data;
  1115. {
  1116. X  XtFree(client_data);        /* frees the string containing the word */
  1117. }
  1118. X
  1119. /******************************************************************************
  1120. X *
  1121. X ******************************************************************************/
  1122. Wordlist_Add(str)
  1123. X     char* str;
  1124. {
  1125. X  Widget wordbutton_Wgt;
  1126. X  XmString label;
  1127. X  char* word;
  1128. X
  1129. X  label = XmStringCreateSimple(str);
  1130. X  wordbutton_Wgt = XtVaCreateWidget("word", 
  1131. X                    xmPushButtonWidgetClass,
  1132. X                    wordlist_Wgt,
  1133. X                    XmNlabelString, label,
  1134. X                    NULL);
  1135. X  XmStringFree(label);
  1136. X  word = COPY_STRING(str);
  1137. X  XtAddCallback(wordbutton_Wgt, 
  1138. X        XmNactivateCallback, 
  1139. X        (XtCallbackProc)Controlpanel_Define_Callback, 
  1140. X        word);
  1141. X  
  1142. X  XtAddCallback(wordbutton_Wgt, 
  1143. X        XmNdestroyCallback, /* on destroy, of Wgt, dealloc the word */
  1144. X        (XtCallbackProc)Wordlist_Button_Destroy_Callback, 
  1145. X        word);
  1146. X  XtSetSensitive(wordbutton_Wgt, FALSE);
  1147. X  wordlist[wordlist_idx++] = wordbutton_Wgt;
  1148. X  
  1149. X  /*
  1150. X   * Refresh the display of words every <num_words_before_refresh> words
  1151. X   */
  1152. X  if ((wordlist_idx % user_prefs.num_words_before_refresh) == 0) {
  1153. X    XtManageChildren(&wordlist[wordlist_base], (wordlist_idx - wordlist_base));
  1154. X    wordlist_base += user_prefs.num_words_before_refresh;
  1155. X  }
  1156. }
  1157. X
  1158. /******************************************************************************
  1159. X * 
  1160. X ******************************************************************************/
  1161. Wordlist_Show()
  1162. {
  1163. X  register int i;
  1164. X  
  1165. X  for (i=0; (i < wordlist_idx); i++) {
  1166. X    XtSetSensitive(wordlist[i], TRUE);
  1167. X  }
  1168. X  XtManageChildren(wordlist, wordlist_idx);
  1169. }
  1170. X
  1171. /******************************************************************************
  1172. X * Desensitizes wordlist buttons
  1173. X ******************************************************************************/
  1174. Wordlist_Deactivate()
  1175. {
  1176. X  register int i;
  1177. X
  1178. X  for (i=0; (i < wordlist_idx); i++) {
  1179. X    XtSetSensitive(wordlist[i], FALSE);
  1180. X  }
  1181. }
  1182. X
  1183. /******************************************************************************
  1184. X * Resensitizes wordlist buttons
  1185. X ******************************************************************************/
  1186. Wordlist_Reactivate()
  1187. {
  1188. X  register int i;
  1189. X
  1190. X  ARGLIST_RESET();
  1191. X  ARGLIST_ADD(XmNset, FALSE);
  1192. X  for (i=0; (i < wordlist_idx); i++) {
  1193. X    XtSetSensitive(wordlist[i], TRUE);
  1194. X    XtSetValues(wordlist[i], ARGLIST());
  1195. X  }
  1196. }
  1197. SHAR_EOF
  1198. chmod 0644 wordlist.c ||
  1199. echo 'restore of wordlist.c failed'
  1200. Wc_c="`wc -c < 'wordlist.c'`"
  1201. test 5889 -eq "$Wc_c" ||
  1202.     echo 'wordlist.c: original size 5889, current size' "$Wc_c"
  1203. rm -f _shar_wnt_.tmp
  1204. fi
  1205. # ============= xwebster.c ==============
  1206. if test -f 'xwebster.c' -a X"$1" != X"-c"; then
  1207.     echo 'x - skipping xwebster.c (File already exists)'
  1208.     rm -f _shar_wnt_.tmp
  1209. else
  1210. > _shar_wnt_.tmp
  1211. echo 'x - extracting xwebster.c (Text)'
  1212. sed 's/^X//' << 'SHAR_EOF' > 'xwebster.c' &&
  1213. /* -*-C-*-
  1214. ********************************************************************************
  1215. *
  1216. * File:         xwebster.c
  1217. * RCS:          $Header: /home/everest1/cattelan/work/xwebster.motif/RCS/xwebster.c,v 1.1 1992/03/21 22:39:43 cattelan Exp $
  1218. * Description:  X11 + HP-Xwidgets interface to a webster dictionary server
  1219. * Author:       Niels Mayer, HPLabs
  1220. * Created:      Wed Aug 31 14:09:08 1988
  1221. * Modified:     Mon Mar  6 03:43:14 1989 (Niels Mayer) mayer@hplnpm
  1222. * Language:     C
  1223. * Package:      N/A
  1224. * Status:       G-Job
  1225. *
  1226. * xwebster - dictionary browser
  1227. *
  1228. * Copyright 1988 Hewlett-Packard Company
  1229. *
  1230. * Permission to use, copy, modify, and distribute this software and its
  1231. * documentation for any purpose and without fee is hereby granted, provided
  1232. * that the above copyright notice appear in all copies and that both that
  1233. * copyright notice and this permission notice appear in supporting
  1234. * documentation, and that the name of HP not be used in advertising or
  1235. * publicity pertaining to distribution of the software without specific,
  1236. * written prior permission.  HP makes no representations about the
  1237. * suitability of this software for any purpose.  It is provided "as is"
  1238. * without express or implied warranty.
  1239. *
  1240. * Please send any improvements, bug fixes, useful modifications, and comments
  1241. * to mayer@hplabs.hp.com.
  1242. ********************************************************************************
  1243. */
  1244. static char rcs_identity[] = "@(#)$Header: /home/everest1/cattelan/work/xwebster.motif/RCS/xwebster.c,v 1.1 1992/03/21 22:39:43 cattelan Exp $";
  1245. char xwebster_version[] = "Xwebster, version 2.0";
  1246. X
  1247. /* 
  1248. X * Some aspects of this program were inspired by the first
  1249. X * C-language translation of the webster client program, webster.c, done by:
  1250. X *                   "David A. Curry
  1251. X *                    Purdue University
  1252. X *                    Engineering Computer Network
  1253. X *                    April, 1986"
  1254. X * The only copyright notice appearing in the webster.c source is:
  1255. X *   "Webster's 7th Collegiate Dictionary, Copyright (C) 1963 by Merriam-Webster,
  1256. X *    Inc.  No part of this information may be copied or reprinted without the
  1257. X *    express written consent of the publisher."
  1258. X */
  1259. X
  1260. #include "xwebster.h"
  1261. #include "user_prefs.h"
  1262. #include <stdio.h>
  1263. #include <ctype.h>
  1264. #include <sys/types.h>
  1265. #include <sys/socket.h>
  1266. #include <netinet/in.h>
  1267. #include <netdb.h>
  1268. /* #include <memory.h> */
  1269. #include <Xm/PanedW.h>
  1270. #include <X11/cursorfont.h>
  1271. X
  1272. static XtInputCallbackProc Webster_Get_Server_Output();
  1273. static void Process_Webster_Line();
  1274. static int Webster_Connect_To_Server();
  1275. static void Webster_Reconnect();
  1276. static XtInputCallbackProc Webster_Handle_Server_Exception();
  1277. static void Webster_Disconnect();
  1278. X
  1279. int              webster_Socket = NULL;
  1280. static XtInputId webster_xinput;
  1281. static XtInputId webster_xexcept;
  1282. static Widget    toplevel_Wgt = NULL;
  1283. /* must be global */
  1284. /* change this later when add the EXTERN macro */
  1285. XXtAppContext webster_app;
  1286. Display*         display;
  1287. X
  1288. String fallbacks[] = {
  1289. X  "*.panel.background: white",
  1290. X  "*.control_panel.word_input.columns: 30",
  1291. X  "*.panel.wordlist_scroller.height: 100",
  1292. X  "*.display_scroller.display.rows: 24",
  1293. X  "*.display_scroller.display.columns: 80",
  1294. X  "*.wordlist_scroller.wordlist.numColumns: 4",
  1295. X   NULL
  1296. X  };
  1297. X
  1298. USER_PREFS_DATA  user_prefs; /* extern declared in user_prefs.h, really here */
  1299. X
  1300. /* 
  1301. X * Data on how user-customization resources are interpreted:
  1302. X * this must be kept up to date with data structure USER_PREFS_DATA_PTR 
  1303. X * in user_prefs.h
  1304. X *
  1305. X * My philosophy is to place all my intended defaults in 
  1306. X * APPDEFAULTSDIR/Xwebster, so that the program doesn't have to
  1307. X * be recompiled just to change a simple default. Thus I don't always have
  1308. X * the best defaults in this structure.
  1309. X */
  1310. X
  1311. static XtResource resources[] = {
  1312. X  {"helpText", "HelpText",
  1313. X     XtRString, sizeof(String),
  1314. X     XtOffset(USER_PREFS_DATA_PTR, help_text),
  1315. X     XtRString, "Warning -- Someone forgot to install APPDEFAULTSDIR/Xwebster"},
  1316. X  {"hostAddrList", "HostAddrList",
  1317. X     XtRString, sizeof(String),
  1318. X     XtOffset(USER_PREFS_DATA_PTR, host_addr_list),
  1319. X     XtRString, ""},
  1320. X  {"hostPort", "HostPort",
  1321. X     XtRInt, sizeof(int),
  1322. X     XtOffset(USER_PREFS_DATA_PTR, host_port),
  1323. X     XtRString, ""},
  1324. X  {"hostServiceName", "HostServiceName",
  1325. X     XtRString, sizeof(String),
  1326. X     XtOffset(USER_PREFS_DATA_PTR, host_service_name),
  1327. X     XtRString, "webster"},
  1328. X  {"numWordsBeforeRefresh", "NumWordsBeforeRefresh",
  1329. X     XtRInt, sizeof(int),
  1330. X     XtOffset(USER_PREFS_DATA_PTR, num_words_before_refresh),
  1331. X     XtRString, "20"},
  1332. X  {"dictionarySource","DictonarySource",
  1333. X    XtRString, sizeof(String),
  1334. X    XtOffset(USER_PREFS_DATA_PTR, dictionary_source),
  1335. X    XtRString, "next"}
  1336. };
  1337. X
  1338. X
  1339. X
  1340. X
  1341. /******************************************************************************
  1342. X *
  1343. X ******************************************************************************/
  1344. main(argc, argv)
  1345. X     int             argc;
  1346. X     char          **argv;
  1347. {
  1348. X  /* 
  1349. X   * Initialize the toolkit, place xwebster-defined resources in user_prefs.
  1350. X   */
  1351. X  toplevel_Wgt = XtVaAppInitialize(&webster_app,"Xwebster",NULL,0,&argc,argv,fallbacks,NULL);
  1352. X
  1353. X  XtVaGetApplicationResources(toplevel_Wgt, 
  1354. X                &user_prefs, 
  1355. X                resources, 
  1356. X                XtNumber(resources), 
  1357. X                NULL);
  1358. X  {
  1359. X    Widget panel_Wgt = XtVaCreateManagedWidget("panel", 
  1360. X                           xmPanedWindowWidgetClass,
  1361. X                           toplevel_Wgt, 
  1362. X                           NULL);
  1363. X    Controlpanel_Titlebar_Init(panel_Wgt); 
  1364. X    Wordlist_Init(panel_Wgt);
  1365. X    Controlpanel_Init(panel_Wgt);
  1366. X    Display_Def_Init(panel_Wgt);
  1367. X  }
  1368. X  XtRealizeWidget(toplevel_Wgt);
  1369. X  display = XtDisplay(toplevel_Wgt);
  1370. X  XDefineCursor(display, XtWindow(toplevel_Wgt), 
  1371. X        XCreateFontCursor(display, XC_plus));
  1372. X  XtAppMainLoop(webster_app);
  1373. }
  1374. X
  1375. /******************************************************************************
  1376. X * This procedure is called indirectly, via XtAddInput() callback from 
  1377. X * XtMainLoop() whenever new input appears on webster_Socket. This callback
  1378. X * is setup in procedure Webster_Reconnect().
  1379. X * This procedure will read all the data from webster_Socket, and then call 
  1380. X * Process_Webster_Line() for each line of input received. If an incomplete 
  1381. X * line of text is received, then this procedure will buffer that line until
  1382. X * the next time it gets called from the callback.
  1383. X ******************************************************************************/
  1384. static XtInputCallbackProc 
  1385. X  Webster_Get_Server_Output(client_data, source_fildes, id)
  1386. caddr_t   client_data;
  1387. int       source_fildes;
  1388. XXtInputId id;
  1389. {
  1390. X  unsigned nbytes;
  1391. X  char readbuf[BUFSIZ];
  1392. X  static char buf[2*BUFSIZ];    /* overkill -- buf shouldn't get longer than BUFSIZ+
  1393. X                   the size of any remaining line (max 80). */
  1394. X  static char linebuf[BUFSIZ];
  1395. X  static int buf_end_idx = 0;    /* init value only on first call */
  1396. X  int prev_buf_end_idx;
  1397. X  int prev_buf_idx;
  1398. X  register int buf_idx;
  1399. X  register int linebuf_idx;
  1400. X  
  1401. X  if (webster_Socket == NULL)
  1402. X    Webster_Reconnect();
  1403. X  if (webster_Socket == NULL)
  1404. X    return;
  1405. X  if ((nbytes = read(webster_Socket, readbuf, BUFSIZ)) <= 0) {
  1406. X    Webster_Disconnect();
  1407. X    return;
  1408. X  }
  1409. X  memcpy(&(buf[buf_end_idx]), readbuf, nbytes);    /* append new input to buf */
  1410. X  buf_end_idx += nbytes;
  1411. X  buf[buf_end_idx] = '\000';    /* NULL marks end of buf */
  1412. X  prev_buf_end_idx = buf_end_idx;
  1413. X
  1414. X  buf_idx = 0; 
  1415. X  while (1) {            /* process lines till none left: exits w/ break*/
  1416. X    linebuf_idx = 0;
  1417. X    prev_buf_idx = buf_idx;
  1418. X    /** try to copy a line of characters to linebuf, quitting on EOF or \000 **/
  1419. X    while (((buf[buf_idx] & 0177) != '\n')
  1420. X       && (buf[buf_idx] != '\000')
  1421. X       && (buf[buf_idx] != '\200'))    /* webster server's <EOF> char */
  1422. X      linebuf[linebuf_idx++] = buf[buf_idx++] & 0177;
  1423. X
  1424. X    if ((buf[buf_idx] & 0177) == '\n') { /* copy to linebuf stopped at LF */
  1425. X      linebuf[linebuf_idx-1] = '\n'; /* overwrite CR with LF */
  1426. X      linebuf[linebuf_idx] = '\000'; /* NULL terminate linebuf */
  1427. X      Process_Webster_Line(linebuf); /* process a line of input */
  1428. X      buf_idx++;        /* skip over \n in buf */
  1429. X      buf_end_idx -= linebuf_idx + 1; /* shorten by len(linebuf)+len(\n) */
  1430. X    }
  1431. X    else if (buf[buf_idx] == '\200') { /* copy to linebuf stopped at EOF */
  1432. X      Process_Webster_Line(NULL); /* signal special case of EOF */
  1433. X      buf_idx++;        /* skip over \200 in buf */
  1434. X      buf_end_idx -= linebuf_idx + 1; /* shorten by len(linebuf)+len(\200) */
  1435. X    }
  1436. X    else {            /* copy to linebuf stopped at \000 (end of buf) */
  1437. X      /** IF characters were transferred from buf to linebuf... **/
  1438. X      if (prev_buf_end_idx != buf_end_idx)
  1439. X    /** ...THEN shiftLeft characters that weren't transferred. **/
  1440. X    memccpy(&(buf[0]), &(buf[prev_buf_idx]), '\000', 2*BUFSIZ); 
  1441. X      break;            /*@@@---EXIT THE WHILE LOOP---@@@*/
  1442. X      /* Buf_end_idx is now really end of buf: on the next call to this proc,
  1443. X     new input will append after remaining unprocessed input in buf.*/
  1444. X    }
  1445. X  }
  1446. }
  1447. X
  1448. /******************************************************************************
  1449. X * This is a "state machine" procedure that is called for every line of text
  1450. X * received from the webster server. The state of the webster program is
  1451. X * contained in the static variable webster_state which lets this procedure
  1452. X * handle the current line of text in a way that depends on what the previous
  1453. X * line of text was. For more info on the webster protocol that is embodied in
  1454. X * this procedure, do "/usr/bin/telnet 10.0.0.51 103" and then type "HELP<cr>".
  1455. X ******************************************************************************/
  1456. #define WEBSTER_READY 0
  1457. #define GET_WORDLIST 1
  1458. #define GET_XREFS 2
  1459. #define GET_DEFINITION 3
  1460. /*-----------------------------------------------------------------------------*/
  1461. static void 
  1462. X  Process_Webster_Line(line)
  1463. char* line;
  1464. {
  1465. X  static int num_xrefs;
  1466. X  static int webster_state = WEBSTER_READY;
  1467. X  static int current_wordlist_is_xrefs = FALSE;
  1468. X
  1469. X  switch(webster_state) {
  1470. X  case WEBSTER_READY:
  1471. X    if (line == NULL) {
  1472. X      Wordlist_Reset();
  1473. X      Controlpanel_Reactivate(); /* ready for user input */
  1474. X    } 
  1475. X    else if (strncmp(line, "AMBIGUOUS ", 10) == 0) { /* returned by COMPLETE */
  1476. X      int num_ambiguities = 0;
  1477. X      sscanf(line, "AMBIGUOUS %d\n", &num_ambiguities);
  1478. X      sprintf(temptext, "Ambiguous! Matches %d other words.", num_ambiguities);
  1479. X      Controlpanel_Titlebar_Set_Label(temptext);
  1480. X      XBell(display, 100);
  1481. X      Wordlist_Reset();
  1482. X      Controlpanel_Reactivate(); /* ready for user input */
  1483. X      /* webster_state = WEBSTER_READY; */
  1484. X    }
  1485. X    else if (strncmp(line, "COMPLETION ", 11) == 0) { /* returned by COMPLETE */
  1486. X      sscanf(line, "COMPLETION %s\n", temptext);
  1487. X      Controlpanel_Set_Input_Word(temptext);
  1488. X      Controlpanel_Titlebar_Set_Label("\000");
  1489. X      Wordlist_Reset();
  1490. X      Controlpanel_Reactivate(); /* ready for user input */
  1491. X      /* webster_state = WEBSTER_READY; */
  1492. X    }
  1493. X    else if (strncmp(line, "MATCHS 0\n", 9) == 0) { /* returned by ENDINGS */
  1494. X      XBell(display, 100);
  1495. X      Controlpanel_Titlebar_Set_Label("No matching words!");
  1496. X      Wordlist_Reset();
  1497. X      Controlpanel_Reactivate(); /* ready for user input */
  1498. X      /* webster_state = WEBSTER_READY; */
  1499. X    }      
  1500. X    else if (strncmp(line, "MATCHS\n", 7) == 0) { /* returned by ENDINGS */
  1501. X      Controlpanel_Titlebar_Set_Label("Choose a word:");
  1502. X      Wordlist_Reset();
  1503. X      webster_state = GET_WORDLIST; current_wordlist_is_xrefs = FALSE;
  1504. X    }
  1505. X    else if (strncmp(line, "SPELLING 0\n", 11) == 0) { /* returned by DEFINE and SPELL */
  1506. X      Controlpanel_Titlebar_Set_Label("No such word!");
  1507. X      XBell(display, 100);
  1508. X      Wordlist_Reset();
  1509. X      Controlpanel_Reactivate(); /* ready for user input */
  1510. X      /* webster_state = WEBSTER_READY; */
  1511. X    }
  1512. X    else if (strncmp(line, "SPELLING\n", 9) == 0) { /* returned by DEFINE */
  1513. SHAR_EOF
  1514. true || echo 'restore of xwebster.c failed'
  1515. fi
  1516. echo 'End of  part 2'
  1517. echo 'File xwebster.c is continued in part 3'
  1518. echo 3 > _shar_seq_.tmp
  1519. exit 0
  1520. -- 
  1521. --
  1522. Molecular Simulations, Inc.            mail: dcmartin@msi.com
  1523. 796 N. Pastoria Avenue                uucp: uunet!dcmartin
  1524. Sunnyvale, California 94086            at&t: 408/522-9236
  1525.