home *** CD-ROM | disk | FTP | other *** search
/ Super Net 1 / SUPERNET_1.iso / PC / OTROS / UNIX / ARCHIE / CLIENTS / XARCHIE3.TAR / xarchie-2.0.1 / display-x.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-04-22  |  8.6 KB  |  428 lines

  1. /*
  2.  * xdisplay.c : Display routines for xarchie
  3.  *
  4.  * George Ferguson, ferguson@cs.rochester.edu, 23 Apr 1993.
  5.  */
  6.  
  7. #include <X11/Intrinsic.h>
  8. #include <X11/StringDefs.h>
  9. #include <X11/Xaw/AsciiText.h>
  10. #ifdef MULTILIST
  11. #include <MultiList.h>
  12. #else
  13. #include <X11/Xaw/List.h>
  14. #endif
  15. #include "xarchie.h"
  16. #include "appres.h"
  17. #include "browser.h"
  18. #include "alert.h"
  19. #include "xutil.h"
  20. #include "stringdefs.h"            /* bezro, bcopy */
  21. #include "debug.h"
  22.  
  23. /*
  24.  * Functions defined here:
  25.  */
  26. /* Text output routines */
  27. void setTitleText(), setStatusText();
  28. void setSearchText(), setHostText(), setLocationText(), setFileText();
  29. void setSizeText(), setModesText(), setDateText();
  30.  
  31. /* Button sensitivity routines */
  32. void setQuerySensitive(), setAbortSensitive();
  33. void setUpSensitive(), setDownSensitive();
  34.  
  35. /* Browser routines */
  36. void initBrowser(),clearBrowser(),redrawBrowser();
  37. void clearBrowserPane(), redrawBrowserPane(), unhighlightBrowserPane();
  38. void clearBrowserItem(), redrawBrowserItem(), unhighlightBrowserItem();
  39. void highlightBrowserItem(), setBrowserItem();
  40. /* Browser action routines */
  41. void nextBrowserPane(),prevBrowserPane();
  42. void nextBrowserItem(),prevBrowserItem();
  43. void toggleCurrentBrowserItem(),selectCurrentBrowserItem();
  44.  
  45. /* Misc. display routines */
  46. void beep();
  47.  
  48. /* Internal routines */
  49. static void updatePasteBuffer(), setListString();
  50.  
  51. /*
  52.  * Data defined here:
  53.  */
  54. /*
  55.  * These string arrays are needed since the only way to set a List
  56.  * widget in X is to pass it an array of strings. That is, there's
  57.  * no way to add items incrementally. Blech. Still, the arrays are
  58.  * grown as needed, so these values can be way off, as they are.
  59.  */
  60. #define INIT_NUM_BROWSER_STRINGS 1
  61. #define REALLOC_INCR(num) (2*(num))
  62.  
  63. static char **browserStrings[NUM_BROWSER_PANES];
  64. static int numBrowserStrings[NUM_BROWSER_PANES];
  65.  
  66. /*    -    -    -    -    -    -    -    -    */
  67. /* Text output */
  68.  
  69. /*ARGSUSED*/
  70. void
  71. setTitleText(str)
  72. char *str;
  73. {
  74.     /*EMPTY*/
  75. }
  76.  
  77. void
  78. setStatusText(str)
  79. char *str;
  80. {
  81.     setWidgetString(statusText,str);
  82.     XFlush(display);
  83. }
  84.  
  85. void
  86. setSearchText(str)
  87. char *str;
  88. {
  89.     setWidgetString(searchText,str);
  90. }
  91.  
  92. void
  93. setHostText(str)
  94. char *str;
  95. {
  96.     setWidgetString(hostText,str);
  97.     if (appResources.pasteBuffer)
  98.     updatePasteBuffer();
  99. }
  100.  
  101. void
  102. setLocationText(str)
  103. char *str;
  104. {
  105.     setWidgetString(locationText,str);
  106.     if (appResources.pasteBuffer)
  107.     updatePasteBuffer();
  108. }
  109.  
  110. void
  111. setFileText(str)
  112. char *str;
  113. {
  114.     setWidgetString(fileText,str);
  115.     if (appResources.pasteBuffer)
  116.     updatePasteBuffer();
  117. }
  118.  
  119. void
  120. setSizeText(str)
  121. char *str;
  122. {
  123.     setWidgetString(sizeText,str);
  124. }
  125.  
  126. void
  127. setModesText(str)
  128. char *str;
  129. {
  130.     setWidgetString(modesText,str);
  131. }
  132.  
  133. void
  134. setDateText(str)
  135. char *str;
  136. {
  137.     setWidgetString(dateText,str);
  138. }
  139.  
  140. static void
  141. updatePasteBuffer()
  142. {
  143.     char *host,*loc,*file,*buf;
  144.  
  145.     host = getWidgetString(hostText);
  146.     loc = getWidgetString(locationText);
  147.     file = getWidgetString(fileText);
  148.     buf = XtMalloc(strlen(host)+strlen(loc)+strlen(file)+3);
  149.     sprintf(buf,"%s:%s/%s",host,loc,file);
  150.     XStoreBytes(display,buf,strlen(buf));
  151.     XtFree(buf);
  152. }
  153.  
  154. /*    -    -    -    -    -    -    -    -    */
  155. /* Buttons */
  156.  
  157. void
  158. setQuerySensitive(state)
  159. int state;
  160. {
  161.     int i;
  162.  
  163.     XtSetSensitive(queryButton,(state > 0 ? True : False));
  164.     /* Disable the Lists so they get redrawn in "gray" */
  165.     for (i=0; i < NUM_BROWSER_PANES; i++)
  166.     XtSetSensitive(browserLists[i],(state > 0 ? True : False));
  167.     /* This is a simple way to disable the up/down buttons */
  168.     XtSetSensitive(browserForm,(state > 0 ? True : False));
  169.     /* Update the icon also (True=busy, when query off ie. state = 0) */
  170.     setIconStatus((state > 0) ? False : True);
  171. }
  172.  
  173. void
  174. setAbortSensitive(state)
  175. int state;
  176. {
  177.     XtSetSensitive(abortButton,(state > 0 ? True : False));
  178. }
  179.  
  180. void
  181. setUpSensitive(state)
  182. int state;
  183. {
  184.     XtSetSensitive(browserUpButton,(state > 0 ? True : False));
  185. }
  186.  
  187. void
  188. setDownSensitive(state)
  189. int state;
  190. {
  191.     XtSetSensitive(browserDownButton,(state > 0 ? True : False));
  192. }
  193.  
  194. /*    -    -    -    -    -    -    -    -    */
  195. /* Browser */
  196.  
  197. void
  198. initBrowser()
  199. {
  200.     /*EMPTY*//* Done by widget creation */
  201. }
  202.  
  203. void
  204. clearBrowser()
  205. {
  206.     int pane;
  207.  
  208.     for (pane=0; pane < NUM_BROWSER_PANES; pane++) {
  209.     clearBrowserPane(pane);
  210.     }
  211. }
  212.  
  213. void
  214. redrawBrowser()
  215. {
  216.     /*EMPTY*/
  217. }
  218.  
  219. /* Browser panes */
  220.  
  221. void
  222. clearBrowserPane(pane)
  223. int pane;
  224. {
  225.     static char *emptyNames[] = { NULL };
  226.  
  227. #ifdef MULTILIST
  228.     XfwfMultiListSetNewData((XfwfMultiListWidget)browserLists[pane],
  229.                 emptyNames,0,0,False,(Boolean *)NULL);
  230. #else
  231.     XawListChange(browserLists[pane],emptyNames,0,0,False);
  232. #endif
  233. }
  234.  
  235. void
  236. redrawBrowserPane(pane)
  237. int pane;
  238. {
  239. #ifdef MULTILIST
  240.     XfwfMultiListSetNewData((XfwfMultiListWidget)browserLists[pane],
  241.                 browserStrings[pane],0,0,True,(Boolean *)NULL);
  242. #else
  243.     XawListChange(browserLists[pane],browserStrings[pane],0,0,False);
  244. #endif
  245. }
  246.  
  247. void
  248. unhighlightBrowserPane(pane)
  249. int pane;
  250. {
  251. #ifdef MULTILIST
  252.     XfwfMultiListUnhighlightAll((XfwfMultiListWidget)browserLists[pane]);
  253. #else
  254.     XawListUnhighlight(browserLists[pane]);
  255. #endif
  256. }
  257.  
  258. /* Browser items */
  259.  
  260. /*ARGSUSED*/
  261. void
  262. clearBrowserItem(pane,item)
  263. int pane,item;
  264. {
  265.     /*EMPTY*/
  266. }
  267.  
  268. /*ARGSUSED*/
  269. void
  270. redrawBrowserItem(pane,item)
  271. int pane,item;
  272. {
  273.     /*EMPTY*/
  274. }
  275.  
  276. void
  277. unhighlightBrowserItem(pane,item)
  278. int pane,item;
  279. {
  280. #ifdef MULTILIST
  281.     XfwfMultiListUnhighlightItem((XfwfMultiListWidget)browserLists[pane],item);
  282. #else
  283.     XawListUnhighlight(browserLists[pane]);
  284. #endif
  285. }
  286.  
  287. void
  288. highlightBrowserItem(pane,item)
  289. int pane,item;
  290. {
  291.     Arg args[1];
  292.     int number;
  293.     float percent;
  294.  
  295. #ifdef MULTILIST
  296.     XfwfMultiListHighlightItem((XfwfMultiListWidget)browserLists[pane],item);
  297. #else
  298.     XawListHighlight(browserLists[pane],item);
  299. #endif
  300.     /* Move the scrollbar so we see the item */
  301.     if (appResources.autoScroll) {
  302.     XtSetArg(args[0],XtNnumberStrings,&number);
  303.     XtGetValues(browserLists[pane],args,1);
  304.     percent = (float)(item-1) / (float)number;
  305.     if (percent < 0.0)
  306.         percent = 0.0;
  307.     else if (percent > 100.)
  308.         percent = 100.0;
  309.     XtCallCallbacks(browserScrollbars[pane],
  310.             "jumpProc",(XtPointer)&percent);
  311.     }
  312. }
  313.  
  314. void
  315. setBrowserItem(pane,item,str)
  316. int pane,item;
  317. char *str;
  318. {
  319.     /* Set the actual value */
  320.     setListString(pane,item,str);
  321.     /* Need a terminating NULL later, so add it now */
  322.     setListString(pane,item+1,NULL);
  323. }
  324.  
  325. /* Browser actions */
  326.  
  327. void
  328. nextBrowserPane()
  329. {
  330.     /*EMPTY*//* Done with mouse */
  331. }
  332.  
  333. void
  334. prevBrowserPane()
  335. {
  336.     /*EMPTY*//* Done with mouse */
  337. }
  338.  
  339. void
  340. nextBrowserItem()
  341. {
  342.     /*EMPTY*//* Done with mouse */
  343. }
  344.  
  345. void
  346. prevBrowserItem()
  347. {
  348.     /*EMPTY*//* Done with mouse */
  349. }
  350.  
  351. void
  352. toggleCurrentBrowserItem()
  353. {
  354.     /*EMPTY*//* Done by X */
  355. }
  356.  
  357. void
  358. selectCurrentBrowserItem()
  359. {
  360.     /*EMPTY*//* Done by X */
  361. }
  362.  
  363. /*    -    -    -    -    -    -    -    -    */
  364. /* Misc. display routines */
  365.  
  366. void
  367. beep()
  368. {
  369.     XBell(display,0);
  370. }
  371.  
  372. /*    -    -    -    -    -    -    -    -    */
  373. /*
  374.  * setListString() : This routine provides access to the dynamically-grown
  375.  *    lists of strings. I bzero() the allocated space even though I shouldn't
  376.  *    need to.
  377.  */
  378. static void
  379. setListString(pane,index,string)
  380. int pane,index;
  381. char *string;
  382. {
  383.     char **oldStr;
  384.     int oldNum;
  385.  
  386.     DEBUG3("setting index %d of pane %d to \"%s\"\n",index,pane,string);
  387.     if (pane >= NUM_BROWSER_PANES) {
  388.     alert2("Attempt to set string in pane %d: \"%s\"",(char *)pane,string);
  389.     return;
  390.     }
  391.     /* Free old string if there was one */
  392.     if (index < numBrowserStrings[pane]) {
  393.     XtFree((XtPointer)(*(browserStrings[pane]+index)));
  394.     DEBUG0("  freed old string\n");
  395.     }
  396.     /* If this is the first call, get the initial string array */
  397.     if (numBrowserStrings[pane] == 0) {
  398.     DEBUG0("  getting initial string array\n");
  399.     numBrowserStrings[pane] = INIT_NUM_BROWSER_STRINGS;
  400.     browserStrings[pane] = (char **)XtCalloc(numBrowserStrings[pane],
  401.                          sizeof(char *));
  402.     bzero((char *)(browserStrings[pane]),
  403.           numBrowserStrings[pane]*sizeof(char *));
  404.     }
  405.     DEBUG1("  string array is size %d\n",numBrowserStrings[pane]);
  406.     /* Grow the array until it's big enough for this string */
  407.     while (index >= numBrowserStrings[pane]) {
  408.     DEBUG0("  growing string array\n");
  409.     oldStr = browserStrings[pane];
  410.     oldNum = numBrowserStrings[pane];
  411.     numBrowserStrings[pane] = REALLOC_INCR(numBrowserStrings[pane]);
  412.     browserStrings[pane] = (char **)XtCalloc(numBrowserStrings[pane],
  413.                          sizeof(char *));
  414.     bzero((char *)(browserStrings[pane]),
  415.           numBrowserStrings[pane]*sizeof(char *));
  416.     bcopy((char *)oldStr,(char *)(browserStrings[pane]),
  417.           oldNum*sizeof(char *));
  418.     XtFree((XtPointer)oldStr);
  419.     }
  420.     DEBUG1("  string array is now size %d\n",numBrowserStrings[pane]);
  421.     /* Finally, set this value */
  422.     if (string == (char *)NULL)
  423.     *(browserStrings[pane]+index) = (char *)NULL;
  424.     else
  425.     *(browserStrings[pane]+index) = XtNewString(string);
  426.     DEBUG1("  done setting string \"%s\"\n",string);
  427. }
  428.