home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / x / volume13 / xdtm / part03 < prev    next >
Internet Message Format  |  1991-05-18  |  50KB

  1. Path: uunet!cs.utexas.edu!sun-barr!newstop!exodus!cogs.sussex.ac.uk
  2. From: eddyg@cogs.sussex.ac.uk (EdwardJ. Groenendaal)
  3. Newsgroups: comp.sources.x
  4. Subject: v13i008: xdtm - X Desktop Manager for the X Window System, Part03/11
  5. Message-ID: <13572@exodus.Eng.Sun.COM>
  6. Date: 19 May 91 00:02:54 GMT
  7. References: <csx-13i006:xdtm@uunet.UU.NET>
  8. Sender: news@exodus.Eng.Sun.COM
  9. Lines: 1460
  10. Approved: argv@sun.com
  11.  
  12. Submitted-by: Edward "J." Groenendaal <eddyg@cogs.sussex.ac.uk>
  13. Posting-number: Volume 13, Issue 8
  14. Archive-name: xdtm/part03
  15.  
  16. Submitted-by: eddyg@cste
  17. Archive-name: xdtm/part03
  18.  
  19. ---- Cut Here and feed the following to sh ----
  20. #!/bin/sh
  21. # This is part 03 of xdtm
  22. # ============= xdtm/Xedw/XedwList.c ==============
  23. if test ! -d 'xdtm'; then
  24.     echo 'x - creating directory xdtm'
  25.     mkdir 'xdtm'
  26. fi
  27. if test ! -d 'xdtm/Xedw'; then
  28.     echo 'x - creating directory xdtm/Xedw'
  29.     mkdir 'xdtm/Xedw'
  30. fi
  31. if test -f 'xdtm/Xedw/XedwList.c' -a X"$1" != X"-c"; then
  32.     echo 'x - skipping xdtm/Xedw/XedwList.c (File already exists)'
  33. else
  34. echo 'x - extracting xdtm/Xedw/XedwList.c (Text)'
  35. sed 's/^X//' << 'SHAR_EOF' > 'xdtm/Xedw/XedwList.c' &&
  36. X#include <X11/copyright.h>
  37. X
  38. X/*
  39. X * XedwList.c - XedwList widget
  40. X *
  41. X * This is the XedwList widget. It is very similar to the Athena Widget List,
  42. X * except it has the ability to display an icon with the string. Plus allows
  43. X * multiple selections.
  44. X * It allows the user to select one or more items in a list and notifies the
  45. X * application through a callback function.
  46. X *
  47. X *  List Created:   8/13/88
  48. X *  By:     Chris D. Peterson
  49. X *                      MIT X Consortium
  50. X *
  51. X *  Modified to XedwList: 1/26/91
  52. X *  By:     Edward Groenendaal
  53. X *                      University of Sussex, UK.
  54. X */
  55. X
  56. X#include <stdio.h>
  57. X#include <ctype.h>
  58. X
  59. X#include <X11/IntrinsicP.h>
  60. X#include <X11/StringDefs.h>
  61. X
  62. X#include <X11/Xmu/Drawing.h>
  63. X
  64. X#include <X11/Xaw/XawInit.h>
  65. X#include "XedwListP.h"
  66. X
  67. X/*
  68. X * Include bitmap for the default icon
  69. X */
  70. X
  71. X#include "DefIcon.icon"
  72. X
  73. X
  74. X/*
  75. X * Default Translation table.
  76. X */
  77. X
  78. Xstatic char defaultTranslations[] =
  79. X  "!Shift<Btn1Down>:             MultipleSet()\n\
  80. X   <Btn1Down>:               Set()\n\
  81. X   !Shift<Btn1Down>,<Btn1Up>:   Notify()\n\
  82. X   <Btn1Down>,<Btn1Up>:         Notify()";
  83. X
  84. X/****************************************************************
  85. X *
  86. X * Full class record constant
  87. X *
  88. X ****************************************************************/
  89. X
  90. X/* Private Data */
  91. X
  92. X#define offset(field) XtOffset(XedwListWidget, field)
  93. X
  94. Xstatic XtResource resources[] = {
  95. X  {XtNforeground, XtCForeground, XtRPixel, sizeof(Pixel),
  96. X     offset(xedwList.foreground), XtRString, "XtDefaultForeground"},
  97. X  {XtNcursor, XtCCursor, XtRCursor, sizeof(Cursor),
  98. X     offset(simple.cursor), XtRString, "left_ptr"},
  99. X  {XtNfont,  XtCFont, XtRFontStruct, sizeof(XFontStruct *),
  100. X     offset(xedwList.font),XtRString, "XtDefaultFont"},
  101. X  {XtNxedwList, XtCXedwList, XtRPointer, sizeof(XedwList **), /* XedwList */
  102. X     offset(xedwList.xedwList), XtRString, NULL},
  103. X  {XtNdefaultColumns, XtCColumns, XtRInt,  sizeof(int),
  104. X     offset(xedwList.default_cols), XtRImmediate, (caddr_t)2},
  105. X  {XtNlongest, XtCLongest, XtRInt,  sizeof(int),
  106. X     offset(xedwList.longest), XtRImmediate, (caddr_t)0},
  107. X  {XtNnumberStrings, XtCNumberStrings, XtRInt,  sizeof(int),
  108. X     offset(xedwList.nitems), XtRImmediate, (caddr_t)0},
  109. X  {XtNpasteBuffer, XtCBoolean, XtRBoolean,  sizeof(Boolean),
  110. X     offset(xedwList.paste), XtRString, (caddr_t) "False"},
  111. X  {XtNforceColumns, XtCColumns, XtRBoolean,  sizeof(Boolean),
  112. X     offset(xedwList.force_cols), XtRString, (caddr_t) "False"},
  113. X  {XtNverticalList, XtCBoolean, XtRBoolean,  sizeof(Boolean),
  114. X     offset(xedwList.vertical_cols), XtRString, (caddr_t) "False"},
  115. X  {XtNinternalWidth, XtCWidth, XtRDimension,  sizeof(Dimension),
  116. X     offset(xedwList.internal_width), XtRImmediate, (caddr_t)4},
  117. X  {XtNinternalHeight, XtCHeight, XtRDimension, sizeof(Dimension),
  118. X     offset(xedwList.internal_height), XtRImmediate, (caddr_t)2},
  119. X  {XtNcolumnSpacing, XtCSpacing, XtRDimension,  sizeof(Dimension),
  120. X     offset(xedwList.column_space), XtRImmediate, (caddr_t)10},
  121. X  {XtNrowSpacing, XtCSpacing, XtRDimension,  sizeof(Dimension),
  122. X     offset(xedwList.row_space), XtRImmediate, (caddr_t)10},
  123. X  {XtNiconWidth, XtCWidth, XtRDimension, sizeof(Dimension),    /* IconWidth */
  124. X     offset(xedwList.icon_width), XtRImmediate, (caddr_t)32},
  125. X  {XtNiconHeight, XtCHeight, XtRDimension, sizeof(Dimension),  /* IconHeight */
  126. X     offset(xedwList.icon_height), XtRImmediate, (caddr_t)32},
  127. X  {XtNshowIcons, XtCBoolean, XtRBoolean, sizeof(Boolean),      /* ShowIcons */
  128. X     offset(xedwList.show_icons), XtRString, (caddr_t) "False"},
  129. X  {XtNmSelections, XtCBoolean, XtRBoolean, sizeof(Boolean),    /* Multiple   */
  130. X     offset(xedwList.multiple), XtRString, (caddr_t) "False"}, /* Selections */
  131. X  {XtNdefaultIcon, XtCPixmap, XtRPixmap, sizeof(Pixmap),      /* DefaultIcon */
  132. X     offset(xedwList.default_icon), XtRPixmap, (caddr_t) NULL},
  133. X  {XtNcallback, XtCCallback, XtRCallback, sizeof(caddr_t),
  134. X     offset(xedwList.callback), XtRCallback, NULL},
  135. X};
  136. X
  137. Xstatic void             Initialize   (Widget, Widget);
  138. Xstatic void             ChangeSize   (Widget, Dimension, Dimension);
  139. Xstatic void             Resize       (Widget);
  140. Xstatic void             Redisplay    (Widget, XEvent*, Region);
  141. Xstatic Boolean          Layout       (Widget, Boolean, Boolean, Dimension*, Dimension*);
  142. Xstatic XtGeometryResult PreferredGeom(Widget, XtWidgetGeometry*, XtWidgetGeometry*);
  143. Xstatic Boolean          SetValues    (Widget, Widget, Widget);
  144. Xstatic void             Notify       (Widget, XEvent*, String*, Cardinal*),
  145. X                        Set          (Widget, XEvent*, String*, Cardinal*), 
  146. X                        MultipleSet  (Widget, XEvent*, String*, Cardinal*), 
  147. X                        Unset        (Widget, XEvent*, String*, Cardinal*);
  148. Xstatic Boolean         IsHighlighted(Widget, int);
  149. Xstatic void        AddNode         (Widget, int);
  150. Xstatic void        RemoveNode   (Widget, int);
  151. X
  152. Xstatic XtActionsRec actions[] = {
  153. X  {"Notify",         Notify},
  154. X  {"Set",            Set},
  155. X  {"Unset",          Unset},
  156. X  {"MultipleSet",    MultipleSet},
  157. X  {NULL,NULL}
  158. X};
  159. X
  160. XXedwListClassRec xedwListClassRec = {
  161. X  {
  162. X/* core_class fields */
  163. X#define superclass                  (&simpleClassRec)
  164. X    /* superclass               */  (WidgetClass) superclass,
  165. X    /* class_name               */  "XedwList",
  166. X    /* widget_size              */  sizeof(XedwListRec),
  167. X    /* class_initialize         */  XawInitializeWidgetSet,
  168. X    /* class_part_initialize    */  NULL,
  169. X    /* class_inited             */  FALSE,
  170. X    /* initialize               */  Initialize,
  171. X    /* initialize_hook          */  NULL,
  172. X    /* realize                  */  XtInheritRealize,
  173. X    /* actions                  */  actions,
  174. X    /* num_actions              */  XtNumber(actions),
  175. X    /* resources                */  resources,
  176. X    /* num_resources            */  XtNumber(resources),
  177. X    /* xrm_class                */  NULLQUARK,
  178. X    /* compress_motion          */  TRUE,
  179. X    /* compress_exposure        */  FALSE,
  180. X    /* compress_enterleave      */  TRUE,
  181. X    /* visible_interest         */  FALSE,
  182. X    /* destroy                  */  NULL,
  183. X    /* resize                   */  Resize,
  184. X    /* expose                   */  Redisplay,
  185. X    /* set_values               */  SetValues,
  186. X    /* set_values_hook          */  NULL,
  187. X    /* set_values_almost        */  XtInheritSetValuesAlmost,
  188. X    /* get_values_hook          */  NULL,
  189. X    /* accept_focus             */  NULL,
  190. X    /* version                  */  XtVersion,
  191. X    /* callback_private         */  NULL,
  192. X    /* tm_table                 */  defaultTranslations,
  193. X    /* query_geometry           */  PreferredGeom,
  194. X  },
  195. X/* Simple class fields initialization */
  196. X  {
  197. X    /* change_sensitive     */  XtInheritChangeSensitive
  198. X  }
  199. X};
  200. X
  201. XWidgetClass xedwListWidgetClass = (WidgetClass)&xedwListClassRec;
  202. X
  203. X/****************************************************************
  204. X *
  205. X * Private Procedures
  206. X *
  207. X ****************************************************************/
  208. X
  209. Xstatic void GetGCs(Widget w)
  210. X{
  211. X
  212. X  XGCValues   values;
  213. X  XedwListWidget ilw = (XedwListWidget) w;
  214. X
  215. X  values.foreground   = ilw->xedwList.foreground;
  216. X  values.background   = ilw->core.background_pixel; 
  217. X  values.font         = ilw->xedwList.font->fid;
  218. X  ilw->xedwList.normgc = XtGetGC(w, (unsigned) GCBackground | GCForeground | GCFont,
  219. X                 &values);
  220. X
  221. X  values.foreground   = ilw->core.background_pixel; 
  222. X  values.background   = ilw->xedwList.foreground;
  223. X  ilw->xedwList.revgc = XtGetGC(w, (unsigned) GCBackground | GCForeground | GCFont, &values);
  224. X
  225. X  values.tile       = XmuCreateStippledPixmap(XtScreen(w),
  226. X                          ilw->xedwList.foreground,
  227. X                          ilw->core.background_pixel,
  228. X                          ilw->core.depth);
  229. X  values.fill_style = FillTiled;
  230. X
  231. X  ilw->xedwList.graygc = XtGetGC(w, (unsigned) GCFont | GCTile | GCFillStyle,
  232. X                 &values);
  233. X}
  234. X
  235. X/*  Function Name:  ResetXedwList
  236. X *  Description:    Resets the new xedwList when important things change.
  237. X *  Arguments:      w - the widget.
  238. X *                  changex, changey - allow the height or width to change?
  239. X *  Returns: none.
  240. X */
  241. X
  242. Xstatic void ResetXedwList(Widget w, Boolean changex, Boolean changey)
  243. X{
  244. X  XedwListWidget ilw = (XedwListWidget) w;
  245. X  Dimension width = w->core.width;
  246. X  Dimension height = w->core.height;
  247. X  register int i, len;
  248. X
  249. X  /*
  250. X   * If xedwList is NULL then the xedwList will just be the name of the widget,
  251. X   * the icon will be set to the default icon. (defined in XedwListP.h)
  252. X   */
  253. X
  254. X  if (ilw->xedwList.xedwList == NULL) {
  255. X    /* Make room for structure */
  256. X    ilw->xedwList.xedwList = XtNew(XedwList *);
  257. X    ilw->xedwList.xedwList[0] = XtNew(XedwList);
  258. X    ilw->xedwList.xedwList[0]->string = ilw->core.name;
  259. X    ilw->xedwList.xedwList[0]->icon = NULL;
  260. X    ilw->xedwList.nitems = 1;
  261. X  }
  262. X
  263. X  if (ilw->xedwList.nitems == 0)       /* Get number of items. */
  264. X    for ( ; ilw->xedwList.xedwList[ilw->xedwList.nitems] != NULL ; ilw->xedwList.nitems++);
  265. X  
  266. X  if (ilw->xedwList.longest == 0) /* Get column width. */
  267. X    for ( i = 0 ; i < ilw->xedwList.nitems; i++) {
  268. X      len = XTextWidth(ilw->xedwList.font, ilw->xedwList.xedwList[i]->string,
  269. X               strlen(ilw->xedwList.xedwList[i]->string));
  270. X      if (len > ilw->xedwList.longest)
  271. X    ilw->xedwList.longest = len;
  272. X    }
  273. X
  274. X  /* If longest string is less than the width of a bitmap then the longest is
  275. X   * the width of a bitmap
  276. X   */
  277. X  if (ilw->xedwList.show_icons)
  278. X    if (ilw->xedwList.longest < ilw->xedwList.icon_width)
  279. X      ilw->xedwList.longest = ilw->xedwList.icon_width;
  280. X
  281. X
  282. X  ilw->xedwList.col_width = ilw->xedwList.longest + ilw->xedwList.column_space;
  283. X
  284. X  if (Layout(w, changex, changey, &width, &height))
  285. X    ChangeSize(w, width, height);
  286. X}
  287. X
  288. X/*  Function Name: ChangeSize.
  289. X *  Description: Laysout the widget.
  290. X *  Arguments: w - the widget to try change the size of.
  291. X *  Returns: none.
  292. X */
  293. X
  294. Xstatic void ChangeSize(Widget w, Dimension width, Dimension height)
  295. X{
  296. X  XtWidgetGeometry request, reply;
  297. X
  298. X  request.request_mode = CWWidth | CWHeight;
  299. X  request.width = width;
  300. X  request.height = height;
  301. X
  302. X  switch ( XtMakeGeometryRequest(w, &request, &reply) ) {
  303. X  case XtGeometryYes:
  304. X  case XtGeometryNo:
  305. X    break;
  306. X  case XtGeometryAlmost:
  307. X    Layout(w, (request.height != reply.height),
  308. X       (request.width != reply.width),
  309. X           &(reply.width), &(reply.height));
  310. X    request = reply;
  311. X    switch (XtMakeGeometryRequest(w, &request, &reply) ) {
  312. X    case XtGeometryYes:
  313. X    case XtGeometryNo:
  314. X      break;
  315. X    case XtGeometryAlmost:
  316. X      request = reply;
  317. X      if (Layout(w, FALSE, FALSE,
  318. X         &(request.width), &(request.height))) {
  319. X    char buf[BUFSIZ];
  320. X    sprintf(buf, "XedwList Widget: %s %s",
  321. X        "Size Changed when it shouldn't have",
  322. X        "when computing layout");
  323. X    XtAppWarning(XtWidgetToApplicationContext(w), buf);
  324. X      }
  325. X      request.request_mode = CWWidth | CWHeight;
  326. X      XtMakeGeometryRequest(w, &request, &reply);
  327. X      break;
  328. X    default:
  329. X      XtAppWarning(XtWidgetToApplicationContext(w),
  330. X           "XedwList Widget: Unknown geometry return.");
  331. X      break;
  332. X    }
  333. X    break;
  334. X  default:
  335. X    XtAppWarning(XtWidgetToApplicationContext(w),
  336. X         "XedwList Widget: Unknown geometry return.");
  337. X    break;
  338. X  }
  339. X}
  340. X
  341. X/*  Function Name: Initialise
  342. X *  Description: Function that initilises the widget instance.
  343. X *  Arguments: junk - NOT USED.
  344. X *             new  - the new widget.
  345. X *  Returns: none
  346. X */
  347. X
  348. Xstatic void Initialize(Widget junk, Widget new)
  349. X{
  350. X  XedwListWidget ilw = (XedwListWidget) new;
  351. X
  352. X/*
  353. X * Initialize all private resources.
  354. X */
  355. X
  356. X  GetGCs(new);
  357. X
  358. X  /* Set row height. */
  359. X  if (ilw->xedwList.show_icons)
  360. X    ilw->xedwList.row_height = ilw->xedwList.font->max_bounds.ascent
  361. X      + ilw->xedwList.font->max_bounds.descent
  362. X      + ilw->xedwList.row_space
  363. X      + ilw->xedwList.icon_height;
  364. X  else
  365. X    ilw->xedwList.row_height = ilw->xedwList.font->max_bounds.ascent
  366. X      + ilw->xedwList.font->max_bounds.descent
  367. X      + ilw->xedwList.row_space;
  368. X
  369. X  ResetXedwList(new, (new->core.width == 0), (new->core.height == 0));
  370. X
  371. X  ilw->xedwList.is_highlighted = (LinkedList*) XtMalloc (sizeof(LinkedList));
  372. X
  373. X  ilw->xedwList.highlight = ilw->xedwList.is_highlighted->index = NO_HIGHLIGHT;
  374. X  ilw->xedwList.is_highlighted->next = NULL;
  375. X
  376. X} /* Initialize */
  377. X
  378. X/*  Function Name: CvtToItem
  379. X *  Description: Converts Xcoord to item number of item containing that
  380. X *               point.
  381. X *  Arguments: w - the xedwList widget.
  382. X *             xloc, yloc - x location, and y location.
  383. X *  Returns: the item number.
  384. X */
  385. X
  386. Xstatic int CvtToItem(Widget w, int xloc, int yloc, int *item)
  387. X{
  388. X  int one, another;
  389. X  XedwListWidget ilw = (XedwListWidget) w;
  390. X  int ret_val = OKAY;
  391. X
  392. X  if (ilw->xedwList.vertical_cols) {
  393. X    one = ilw->xedwList.nrows * ((xloc - (int) ilw->xedwList.internal_width)
  394. X                 / ilw->xedwList.col_width);
  395. X    another = (yloc - (int) ilw->xedwList.internal_height)
  396. X      / ilw->xedwList.row_height;
  397. X    /* If out of range, return minimum possible value. */
  398. X    if (another >= ilw->xedwList.nrows) {
  399. X      another = ilw->xedwList.nrows - 1;
  400. X      ret_val = OUT_OF_RANGE;
  401. X    }
  402. X  }
  403. X  else {
  404. X    one = (ilw->xedwList.ncols * ((yloc - (int) ilw->xedwList.internal_height)
  405. X                  / ilw->xedwList.row_height)) ;
  406. X    /* If in right margin handle things right. */
  407. X    another = (xloc - (int) ilw->xedwList.internal_width) / ilw->xedwList.col_width;
  408. X    if (another >= ilw->xedwList.ncols) {
  409. X      another = ilw->xedwList.ncols - 1;
  410. X      ret_val = OUT_OF_RANGE;
  411. X    }
  412. X  }
  413. X  if ((xloc < 0) || (yloc < 0))
  414. X    ret_val = OUT_OF_RANGE;
  415. X  if (one < 0) one = 0;
  416. X  if (another < 0) another = 0;
  417. X  *item = one + another;
  418. X  if (*item >= ilw->xedwList.nitems) return(OUT_OF_RANGE);
  419. X  return(ret_val);
  420. X}
  421. X
  422. X/*  Function Name: FindCornerItems.
  423. X *  Description: Find the corners of the rectangle in item space.
  424. X *  Arguments: w - the xedwList widget.
  425. X *             event - the event structure that has the rectangle it it.
  426. X *             ul_ret, lr_ret - the corners ** RETURNED **.
  427. X *  Returns: none.
  428. X */
  429. X
  430. Xstatic int FindCornerItems(Widget w, XEvent *event, int *ul_ret, int *lr_ret)
  431. X{
  432. X  int xloc, yloc;
  433. X  
  434. X  xloc = event->xexpose.x;
  435. X  yloc = event->xexpose.y;
  436. X  CvtToItem(w, xloc, yloc, ul_ret);
  437. X  xloc += event->xexpose.width;
  438. X  yloc += event->xexpose.height;
  439. X  CvtToItem(w, xloc, yloc, lr_ret);
  440. X}
  441. X
  442. X/*  Function Name: ItemInRectangle
  443. X *  Description: returns TRUE if the item passed is in the given rectangle.
  444. X *  Arguments: w - the xedwList widget.
  445. X *             ul, lr - corners of the rectangle in item space.
  446. X *             item - item to check.
  447. X *  Returns: TRUE if the item passed is in the given rectangle.
  448. X */
  449. X
  450. Xstatic int ItemInRectangle(Widget w, int ul, int lr, int item)
  451. X{
  452. X  XedwListWidget ilw = (XedwListWidget) w;
  453. X  register int mod_item;
  454. X  int things;
  455. X
  456. X  if (item < ul || item > lr)
  457. X    return(FALSE);
  458. X  if (ilw->xedwList.vertical_cols)
  459. X    things = ilw->xedwList.nrows;
  460. X  else
  461. X    things = ilw->xedwList.ncols;
  462. X  
  463. X  mod_item = item % things;
  464. X  if ( (mod_item >= ul % things) && (mod_item <= lr % things ) )
  465. X    return(TRUE);
  466. X  return(FALSE);
  467. X}
  468. X
  469. X/*  Function Name: HighlightBackground
  470. X *  Description: paints the color of the background for the given item.
  471. X *  Arguments: w - the widget.
  472. X *             x, y - ul corner of the area item occupies.
  473. X *             item - the item we are dealing with.
  474. X *             gc - the gc that is used to paint this rectangle
  475. X *  Returns:
  476. X */
  477. X
  478. Xstatic int HighlightBackground(Widget w, int x, int y, int item, GC gc)
  479. X{
  480. X  XedwListWidget ilw = (XedwListWidget) w;
  481. X  int hl_x, hl_y, width, height;
  482. X
  483. X  hl_x = x - ilw->xedwList.column_space/2;
  484. X  width = XTextWidth(ilw->xedwList.font, ilw->xedwList.xedwList[item]->string,
  485. X             strlen(ilw->xedwList.xedwList[item]->string))
  486. X    + ilw->xedwList.column_space;
  487. X  hl_y = y + ((ilw->xedwList.show_icons) ? ilw->xedwList.icon_height : 0);
  488. X  height = ilw->xedwList.row_height - ilw->xedwList.row_space -
  489. X    ((ilw->xedwList.show_icons) ? ilw->xedwList.icon_height : 0);
  490. X
  491. X  XFillRectangle(XtDisplay(w), XtWindow(w), gc, hl_x, hl_y, width, height);
  492. X}
  493. X
  494. X/*  Function Name: PaintItemName
  495. X *  Description: paints the name of the item in the appropriate location.
  496. X *  Arguments: w - the xedwList widget.
  497. X
  498. X *             item - the item to draw.
  499. X *           op - XedwOn, XedwOff
  500. X *  Returns: none.
  501. X *
  502. X *      NOTE: no action taken on an unrealized widget.
  503. X */
  504. X
  505. Xstatic int PaintItemName(Widget w, int item, int operation)
  506. X{
  507. X  char * str;
  508. X  GC gc;
  509. X  unsigned normalmode, inversemode;
  510. X  int x, y, str_y, str_x;
  511. X  XedwListWidget ilw = (XedwListWidget) w;
  512. X
  513. X  if (!XtIsRealized(w)) return; /* Just in case... */
  514. X
  515. X
  516. X  if (ilw->xedwList.vertical_cols) {
  517. X    x = ilw->xedwList.col_width * (item / ilw->xedwList.nrows)
  518. X      + ilw->xedwList.internal_width;
  519. X    y = ilw->xedwList.row_height * (item % ilw->xedwList.nrows)
  520. X      + ilw->xedwList.internal_height;
  521. X  }
  522. X  else {
  523. X    x = ilw->xedwList.col_width * (item % ilw->xedwList.ncols)
  524. X      + ilw->xedwList.internal_width;
  525. X    y = ilw->xedwList.row_height * (item / ilw->xedwList.ncols)
  526. X      + ilw->xedwList.internal_height;
  527. X  }
  528. X
  529. X  
  530. X  str =  ilw->xedwList.xedwList[item]->string;
  531. X  
  532. X  str_y = y + ilw->xedwList.font->max_bounds.ascent;
  533. X
  534. X  if (ilw->xedwList.show_icons)
  535. X    str_x = x + ((ilw->xedwList.longest/2) -
  536. X         (XTextWidth(ilw->xedwList.font, str, strlen(str))/2));
  537. X  else
  538. X    str_x = x;
  539. X
  540. X  if (DefaultDepthOfScreen(XtScreen(ilw)) == 1) {
  541. X    /* Monochrome */
  542. X    if ((BlackPixelOfScreen(XtScreen(ilw))) == 1) {
  543. X      normalmode = GXcopy;
  544. X      inversemode = GXcopyInverted;
  545. X    } else {
  546. X      normalmode = GXcopyInverted;
  547. X      inversemode = GXcopy;
  548. X    }
  549. X  } else {
  550. X    /* Colour */
  551. X    normalmode = GXcopy;
  552. X    inversemode = GXcopy;
  553. X  }
  554. X
  555. X  if (ilw->xedwList.is_highlighted->index != NO_HIGHLIGHT) {
  556. X    /* There are some highlighted items */
  557. X    if (ilw->xedwList.highlight == NO_HIGHLIGHT) {
  558. X      /* This is an update */
  559. X      if (operation == XedwOn) {
  560. X    if (XtIsSensitive(w)) {
  561. X      /* Draw Inverse item */
  562. X      gc = ilw->xedwList.revgc;
  563. X      XSetFunction(XtDisplay(w), gc, inversemode);
  564. X      HighlightBackground(w, str_x, y, item, ilw->xedwList.normgc);
  565. X    } else {
  566. X      /* Draw Grey item */
  567. X    }  
  568. X      } else {
  569. X    gc = ilw->xedwList.normgc;
  570. X    XSetFunction(XtDisplay(w), gc, normalmode); /* jcc */
  571. X      }
  572. X    } else {
  573. X      /* Were toggling something */
  574. X      if (operation == XedwOn) {
  575. X        if (XtIsSensitive(w)) {
  576. X          /* Draw Inverse item */
  577. X          gc = ilw->xedwList.revgc;
  578. X          XSetFunction(XtDisplay(w), gc, inversemode); 
  579. X          HighlightBackground(w, str_x, y, item, ilw->xedwList.normgc);
  580. X    } else {
  581. X      /* Draw Grey item */
  582. X    } 
  583. X      } else {
  584. X    /* Draw Normal item */
  585. X    gc = ilw->xedwList.normgc;
  586. X    XSetFunction(XtDisplay(ilw), gc, normalmode);
  587. X    HighlightBackground(w, str_x, y, item, ilw->xedwList.revgc); 
  588. X      }
  589. X    }
  590. X  } else {
  591. X    gc = ilw->xedwList.normgc;
  592. X    XSetFunction(XtDisplay(ilw), gc, normalmode);
  593. X  }
  594. X
  595. X  if (ilw->xedwList.default_icon == NULL)
  596. X    ilw->xedwList.default_icon = 
  597. X      XCreateBitmapFromData(XtDisplay(ilw), XtWindow(ilw), default_bits, 
  598. X                default_width, default_height);
  599. X
  600. X  if (ilw->xedwList.show_icons){
  601. X    Pixmap icon;
  602. X    if (ilw->xedwList.xedwList[item]->icon == NULL &&
  603. X    ilw->xedwList.default_icon != NULL) 
  604. X      icon = ilw->xedwList.default_icon;
  605. X    else 
  606. X      icon = ilw->xedwList.xedwList[item]->icon;
  607. X    if (DefaultDepthOfScreen(XtScreen(ilw)) == 1)
  608. X      XCopyArea(XtDisplay(ilw), icon,
  609. X        XtWindow(ilw), gc, 0, 0,
  610. X        ilw->xedwList.icon_width, ilw->xedwList.icon_height, x +
  611. X        ((ilw->xedwList.longest/2) - (ilw->xedwList.icon_width/2)), y);
  612. X    else
  613. X      XCopyPlane(XtDisplay(ilw), icon,
  614. X         XtWindow(ilw), gc, 0,0,
  615. X         ilw->xedwList.icon_width,ilw->xedwList.icon_height,x +
  616. X         ((ilw->xedwList.longest/2) - (ilw->xedwList.icon_width/2)), y,1);
  617. X    /* Draw string */
  618. X    XSetFunction(XtDisplay(ilw), gc, GXcopy);
  619. X    XDrawString(XtDisplay(ilw), XtWindow(ilw), gc, str_x,
  620. X        str_y+ilw->xedwList.icon_height, str, strlen(str));
  621. X  } else { /* No Icons */
  622. X    XSetFunction(XtDisplay(ilw), gc, GXcopy);
  623. X    XDrawString(XtDisplay(ilw), XtWindow(ilw), gc, str_x, str_y, str, strlen(str));
  624. X  }
  625. X}
  626. X
  627. X/*  Function Name: Redisplay
  628. X *  Description: Repaints the widget window on expose events.
  629. X *  Arguments: w - the xedwList widget.
  630. X *                 event - the expose event for this repaint.
  631. X *                 junk - NOT USED.
  632. X *  Returns:
  633. X */
  634. X
  635. Xstatic void Redisplay(Widget w, XEvent *event, Region junk)
  636. X{
  637. X  int item;           /* an item to work with. */
  638. X  int ul_item, lr_item;       /* corners of items we need to paint. */
  639. X  XedwListWidget ilw = (XedwListWidget) w;
  640. X
  641. X  if (event == NULL) {    /* repaint all. */
  642. X    ul_item = 0;
  643. X    lr_item = ilw->xedwList.nrows * ilw->xedwList.ncols - 1;
  644. X    XClearWindow(XtDisplay(w), XtWindow(w));
  645. X  }
  646. X  else
  647. X    FindCornerItems(w, event, &ul_item, &lr_item);
  648. X
  649. X  ilw->xedwList.highlight = NO_HIGHLIGHT;
  650. X  for (item = ul_item; (item <= lr_item && item < ilw->xedwList.nitems) ; item++)
  651. X    if (ItemInRectangle(w, ul_item, lr_item, item))
  652. X      if (IsHighlighted(w, item))
  653. X    PaintItemName(w, item, XedwOn);
  654. X      else
  655. X    PaintItemName(w, item, XedwOff);
  656. X}
  657. X
  658. X/*  Function Name: PreferredGeom
  659. X *  Description: This tells the parent what size we would like to be
  660. X *                   given certain constraints.
  661. X *  Arguments: w - the widget.
  662. X *                 intended - what the parent intends to do with us.
  663. X *                 requested - what we want to happen.
  664. X *  Returns: none.
  665. X */
  666. X
  667. Xstatic XtGeometryResult PreferredGeom(Widget w, 
  668. X                      XtWidgetGeometry *intended, 
  669. X                      XtWidgetGeometry *requested)
  670. X{
  671. X  Dimension new_width, new_height;
  672. X  Boolean change, width_req, height_req;
  673. X
  674. X  width_req = intended->request_mode & CWWidth;
  675. X  height_req = intended->request_mode & CWHeight;
  676. X
  677. X  if (width_req)
  678. X    new_width = intended->width;
  679. X  else
  680. X    new_width = w->core.width;
  681. X
  682. X  if (height_req)
  683. X    new_height = intended->height;
  684. X  else
  685. X    new_height = w->core.height;
  686. X
  687. X  requested->request_mode = 0;
  688. X
  689. X  /*
  690. X   * We only care about our height and width.
  691. X   */
  692. X
  693. X  if ( !width_req && !height_req)
  694. X    return(XtGeometryYes);
  695. X
  696. X  change = Layout(w, !width_req, !height_req, &new_width, &new_height);
  697. X
  698. X  requested->request_mode |= CWWidth;
  699. X  requested->width = new_width;
  700. X  requested->request_mode |= CWHeight;
  701. X  requested->height = new_height;
  702. X
  703. X  if (change)
  704. X    return(XtGeometryAlmost);
  705. X  return(XtGeometryYes);
  706. X}
  707. X
  708. X/*  Function Name: Resize
  709. X *  Description: resizes the widget, by changing the number of rows and
  710. X *               columns.
  711. X *  Arguments: w - the widget.
  712. X *  Returns: none.
  713. X */
  714. X
  715. Xstatic void Resize(Widget w)
  716. X{
  717. X  Dimension width, height;
  718. X
  719. X  width = w->core.width;
  720. X  height = w->core.height;
  721. X
  722. X  if (Layout(w, FALSE, FALSE, &width, &height))
  723. X    XtAppWarning(XtWidgetToApplicationContext(w),
  724. X         "XedwList Widget: Size changed when it shouldn't have when resising.");
  725. X}
  726. X
  727. X/*  Function Name: Layout
  728. X *  Description: lays out the item in the xedwList.
  729. X *  Arguments: w - the widget.
  730. X *             xfree, yfree - TRUE if we are free to resize the widget in
  731. X *                            this direction.
  732. X *             width, height - the is the current width and height that
  733. X *                             we are going to layout the xedwList widget to,
  734. X *                             depending on xfree and yfree of course.
  735. X *
  736. X *  Returns: TRUE if width or height have been changed.
  737. X */
  738. X
  739. Xstatic Boolean Layout(Widget w, Boolean xfree, Boolean yfree, 
  740. X              Dimension *width, Dimension *height)
  741. X{
  742. X  XedwListWidget ilw = (XedwListWidget) w;
  743. X  Boolean change = FALSE;
  744. X
  745. X  /*
  746. X   * If force columns is set then always use number of columns specified
  747. X   * by default_cols.
  748. X   */
  749. X
  750. X  if (ilw->xedwList.force_cols) {
  751. X    ilw->xedwList.ncols = ilw->xedwList.default_cols;
  752. X    if (ilw->xedwList.ncols <= 0) ilw->xedwList.ncols = 1;
  753. X    /* 12/3 = 4 and 10/3 = 4, but 9/3 = 3 */
  754. X    ilw->xedwList.nrows = ( ( ilw->xedwList.nitems - 1) / ilw->xedwList.ncols) + 1 ;
  755. X    if (xfree) {        /* If allowed resize width. */
  756. X      *width = ilw->xedwList.ncols * ilw->xedwList.col_width
  757. X    + 2 * ilw->xedwList.internal_width;
  758. X      change = TRUE;
  759. X    }
  760. X    if (yfree) {        /* If allowed resize height. */
  761. X      *height = (ilw->xedwList.nrows * ilw->xedwList.row_height)
  762. X    + 2 * ilw->xedwList.internal_height;
  763. X      change = TRUE;
  764. X    }
  765. X    return(change);
  766. X  }
  767. X
  768. X  /*
  769. X   * If both width and height are free to change the use default_cols
  770. X   * to determine the number columns and set new width and height to
  771. X   * just fit the window.
  772. X   */
  773. X
  774. X  if (xfree && yfree) {
  775. X    ilw->xedwList.ncols = ilw->xedwList.default_cols;
  776. X    if (ilw->xedwList.ncols <= 0) ilw->xedwList.ncols = 1;
  777. X    ilw->xedwList.nrows = ( ( ilw->xedwList.nitems - 1) / ilw->xedwList.ncols) + 1 ;
  778. X    *width = ilw->xedwList.ncols * ilw->xedwList.col_width
  779. X      + 2 * ilw->xedwList.internal_width;
  780. X    *height = (ilw->xedwList.nrows * ilw->xedwList.row_height)
  781. X      + 2 * ilw->xedwList.internal_height;
  782. X    change = TRUE;
  783. X  }
  784. X  /*
  785. X   * If the width is fixed then use it to determine the number of columns.
  786. X   * If the height is free to move (width still fixed) then resize the height
  787. X   * of the widget to fit the current xedwList exactly.
  788. X   */
  789. X  else if (!xfree) {
  790. X    ilw->xedwList.ncols = ( (*width - 2 * ilw->xedwList.internal_width)
  791. X               / ilw->xedwList.col_width);
  792. X    if (ilw->xedwList.ncols <= 0) ilw->xedwList.ncols = 1;
  793. X    ilw->xedwList.nrows = ( ( ilw->xedwList.nitems - 1) / ilw->xedwList.ncols) + 1 ;
  794. X    if ( yfree ) {
  795. X      *height = (ilw->xedwList.nrows * ilw->xedwList.row_height)
  796. X    + 2 * ilw->xedwList.internal_height;
  797. X      change = TRUE;
  798. X    }
  799. X  }
  800. X  /*
  801. X   * The last case is xfree and !yfree we use the height to determine
  802. X   * the number of rows and then set the width to just fit the resulting
  803. X   * number of columns.
  804. X   */
  805. X  else if (!yfree) {      /* xfree must be TRUE. */
  806. X    ilw->xedwList.nrows = (*height - 2 * ilw->xedwList.internal_height)
  807. X      / ilw->xedwList.row_height;
  808. X    if (ilw->xedwList.nrows <= 0) ilw->xedwList.nrows = 1;
  809. X    ilw->xedwList.ncols = (( ilw->xedwList.nitems - 1 ) / ilw->xedwList.nrows) + 1;
  810. X    *width = ilw->xedwList.ncols * ilw->xedwList.col_width
  811. X      + 2 * ilw->xedwList.internal_width;
  812. X    change = TRUE;
  813. X  }
  814. X  return(change);
  815. X}
  816. X
  817. X/*  Function Name: Notify
  818. X *  Description: Notifies the user that a button has been pressed, and
  819. X *               calles the callback, if the XtNpasteBuffer resource
  820. X *               is true then the name of the item is also put in the
  821. X *               X cut buffer ( buf (0) ).
  822. X *  Arguments: w - the widget that the notify occured in.
  823. X *             event - event that caused this notification.
  824. X *             params, num_params - not used.
  825. X *  Returns: none.
  826. X */
  827. X
  828. Xstatic void Notify(Widget w, XEvent *event, String *params, 
  829. X           Cardinal *num_params)
  830. X{
  831. X  XedwListWidget ilw = ( XedwListWidget ) w;
  832. X  LinkedList *list = ilw->xedwList.is_highlighted;
  833. X  int item, item_len;
  834. X  XedwListReturnStruct ret_value;
  835. X
  836. X  if ( ((CvtToItem(w, event->xbutton.x, event->xbutton.y, &item))
  837. X    == OUT_OF_RANGE) || (ilw->xedwList.highlight != item) ) {
  838. X    XedwListUnhighlight(w, ilw->xedwList.highlight);
  839. X    RemoveNode(w, ilw->xedwList.highlight);
  840. X    XtCallCallbacks(w, XtNcallback, (caddr_t) 0);
  841. X    return;
  842. X  }
  843. X
  844. X  /* Put the name of ALL highlighted strings into the X cut buffer, 
  845. X   * seperated by spaces.
  846. X
  847. X  item_len = 0;
  848. X  while(list != NULL) {
  849. X    item_len +=  strlen(ilw->xedwList.xedwList[list.index]->string) + 1;
  850. X      list=list->next;
  851. X  }
  852. X
  853. X  */
  854. X
  855. X  item_len = strlen(ilw->xedwList.xedwList[item]->string);
  856. X  
  857. X  if ( ilw->xedwList.paste )   /* if XtNpasteBuffer set then paste it. */
  858. X    XStoreBytes(XtDisplay(w), ilw->xedwList.xedwList[item]->string, item_len);
  859. X
  860. X  /*
  861. X   * Call Callback function.
  862. X   */
  863. X
  864. X  ret_value.string = ilw->xedwList.xedwList[item]->string;
  865. X  ret_value.xedwList_index = item;
  866. X  ret_value.next = NULL;
  867. X  
  868. X  XtCallCallbacks( w, XtNcallback, (caddr_t) &ret_value);
  869. X}
  870. X
  871. X/*  Function Name: Unset
  872. X *  Description: unhighlights the current elements.
  873. X *  Arguments: w - the widget that the event occured in.
  874. X *                 event - not used.
  875. X *                 params, num_params - not used.
  876. X *  Returns: none.
  877. X */
  878. X
  879. Xstatic void Unset(Widget w, XEvent *event, String *params, 
  880. X          Cardinal *num_params)
  881. X{
  882. X  XedwListUnhighlight(w, XedwAll);
  883. X}
  884. X
  885. X/*  Function Name: Set
  886. X *  Description: Highlights the current element.
  887. X *  Arguments: w - the widget that the event occured in.
  888. X *                 event - event that caused this notification.
  889. X *                 params, num_params - not used.
  890. X *  Returns: none.
  891. X */
  892. X
  893. Xstatic void Set(Widget w, XEvent *event, String *params, 
  894. X        Cardinal *num_params)
  895. X{
  896. X  int item;
  897. X  XedwListWidget ilw = (XedwListWidget) w;
  898. X
  899. X  if ( (CvtToItem(w, event->xbutton.x, event->xbutton.y, &item))
  900. X      == OUT_OF_RANGE)
  901. X    XedwListUnhighlight(w, XedwAll);    /* Unhighlight current items. */
  902. X  else {
  903. X    if (ilw->xedwList.highlight != item || 
  904. X    ilw->xedwList.is_highlighted->next != NULL) 
  905. X      XedwListUnhighlight(w, XedwAll);    /* Unhighlight any others */
  906. X    XedwListHighlight(w, item);       /* highlight it */
  907. X  }
  908. X}
  909. X
  910. X/*  Function Name: MultipleSet
  911. X *  Description: Highlights the current element.
  912. X *  Arguments: w - the widget that the event occured in.
  913. X *                 event - event that caused this notification.
  914. X *                 params, num_params - not used.
  915. X *  Returns: none.
  916. X */
  917. X
  918. Xstatic void MultipleSet(Widget w, XEvent *event, String *params, 
  919. X        Cardinal *num_params)
  920. X{
  921. X  int item;
  922. X  XedwListWidget ilw = (XedwListWidget) w;
  923. X
  924. X  if (ilw->xedwList.multiple == True)
  925. X    if ( (CvtToItem(w, event->xbutton.x, event->xbutton.y, &item))
  926. X    == OUT_OF_RANGE)
  927. X      XedwListUnhighlight(w, XedwAll);     /* Unhighlight all current items. */
  928. X    else 
  929. X      if (IsHighlighted(w, item))    /* If already highlighted, */
  930. X    XedwListUnhighlight(w, item);    /* unhighlight it */
  931. X      else
  932. X    XedwListHighlight(w, item);       /* otherwise highlight it */
  933. X  else
  934. X    XBell(XtDisplay(w), 100);
  935. X}
  936. X
  937. X/* 
  938. X * Return state of a list item 
  939. X */
  940. Xstatic Boolean IsHighlighted(Widget w, int item)
  941. X{
  942. X  XedwListWidget ilw = (XedwListWidget) w;
  943. X  LinkedList *list = ilw->xedwList.is_highlighted;
  944. X  Boolean ret_val;
  945. X
  946. X  while (list != NULL && list->index != item && list->index != NO_HIGHLIGHT)
  947. X    list = list->next;
  948. X  
  949. X  if (list == NULL || list->index == NO_HIGHLIGHT)
  950. X    ret_val=FALSE;
  951. X  else
  952. X    ret_val=TRUE;
  953. X  
  954. X  return(ret_val);    /* true if item was in list false otherwise */
  955. X}
  956. X
  957. X/*
  958. X * Set specified arguments into widget
  959. X */
  960. X
  961. Xstatic Boolean SetValues(Widget current, 
  962. X             Widget request, 
  963. X             Widget new)
  964. X{
  965. X  XedwListWidget cl = (XedwListWidget) current;
  966. X  XedwListWidget rl = (XedwListWidget) request;
  967. X  XedwListWidget nl = (XedwListWidget) new;
  968. X  Boolean redraw = FALSE;
  969. X
  970. X  if ((cl->xedwList.foreground != rl->xedwList.foreground) ||
  971. X      (cl->core.background_pixel != rl->core.background_pixel) ||
  972. X      (cl->xedwList.font != rl->xedwList.font) ) {
  973. X    XtDestroyGC(cl->xedwList.normgc);
  974. X    XtDestroyGC(cl->xedwList.graygc);
  975. X    XtDestroyGC(cl->xedwList.revgc);
  976. X    GetGCs(new);
  977. X    redraw = TRUE;
  978. X  }
  979. X
  980. X  /* Reset row height. */
  981. X  
  982. X  if ((cl->xedwList.row_space != rl->xedwList.row_space) ||
  983. X      (cl->xedwList.font != rl->xedwList.font)           ||
  984. X      (cl->xedwList.show_icons != rl->xedwList.show_icons) ||
  985. X      (cl->xedwList.icon_width != rl->xedwList.icon_width)           ||
  986. X      (cl->xedwList.icon_height != rl->xedwList.icon_height))
  987. X    if (rl->xedwList.show_icons) 
  988. X      nl->xedwList.row_height = nl->xedwList.font->max_bounds.ascent
  989. X    + nl->xedwList.font->max_bounds.descent
  990. X    + nl->xedwList.row_space
  991. X        + nl->xedwList.icon_height;
  992. X    else
  993. X      nl->xedwList.row_height = nl->xedwList.font->max_bounds.ascent
  994. X    + nl->xedwList.font->max_bounds.descent
  995. X    + nl->xedwList.row_space;
  996. X
  997. X  if ((cl->core.width != rl->core.width)                     ||
  998. X      (cl->core.height != rl->core.height)                   ||
  999. X      (cl->xedwList.internal_width != rl->xedwList.internal_width)   ||
  1000. X      (cl->xedwList.internal_height != rl->xedwList.internal_height) ||
  1001. X      (cl->xedwList.column_space != rl->xedwList.column_space)       ||
  1002. X      (cl->xedwList.row_space != rl->xedwList.row_space)             ||
  1003. X      (cl->xedwList.default_cols != rl->xedwList.default_cols)       ||
  1004. X      ((cl->xedwList.force_cols != rl->xedwList.force_cols) &&
  1005. X       (rl->xedwList.force_cols != rl->xedwList.ncols))           ||
  1006. X      (cl->xedwList.vertical_cols != rl->xedwList.vertical_cols)     ||
  1007. X      (cl->xedwList.longest != rl->xedwList.longest)                 ||
  1008. X      (cl->xedwList.nitems != rl->xedwList.nitems)                   ||
  1009. X      (cl->xedwList.font != rl->xedwList.font)                       ||
  1010. X      (cl->xedwList.show_icons != rl->xedwList.show_icons)           ||
  1011. X      (cl->xedwList.icon_width != rl->xedwList.icon_width)           ||
  1012. X      (cl->xedwList.icon_height != rl->xedwList.icon_height)         ||
  1013. X      (cl->xedwList.default_icon != rl->xedwList.default_icon)       ||
  1014. X      (cl->xedwList.xedwList != rl->xedwList.xedwList)                        ) {
  1015. X    
  1016. X    ResetXedwList(new, TRUE, TRUE);
  1017. X    redraw = TRUE;
  1018. X  }
  1019. X
  1020. X  if (cl->xedwList.xedwList != rl->xedwList.xedwList)
  1021. X    nl->xedwList.highlight = NO_HIGHLIGHT;
  1022. X
  1023. X  if ((cl->core.sensitive != rl->core.sensitive) ||
  1024. X      (cl->core.ancestor_sensitive != rl->core.ancestor_sensitive)) {
  1025. X    nl->xedwList.highlight = NO_HIGHLIGHT;
  1026. X    redraw = TRUE;
  1027. X  }
  1028. X  
  1029. X  if (!XtIsRealized(current))
  1030. X    return(FALSE);
  1031. X
  1032. X  return(redraw);
  1033. X}
  1034. X
  1035. X/* Exported Functions */
  1036. X
  1037. X/*  Function Name: XedwListChange.
  1038. X *  Description: Changes the xedwList being used and shown.
  1039. X *  Arguments: w - the xedwList widget.
  1040. X *                 xedwList - the new xedwList.
  1041. X *                 nitems - the number of items in the xedwList.
  1042. X *                 longest - the length (in Pixels) of the longest element
  1043. X *                           in the xedwList.
  1044. X *                 resize - if TRUE the the xedwList widget will
  1045. X *                          try to resize itself.
  1046. X *  Returns: none.
  1047. X *      NOTE:      If nitems of longest are <= 0 then they will be calculated.
  1048. X *                 If nitems is <= 0 then the xedwList needs to be NULL terminated.
  1049. X */
  1050. X
  1051. Xvoid XedwListChange(Widget w, XedwList **xedwList, 
  1052. X               int nitems, int longest, Boolean resize_it)
  1053. X{
  1054. X  XedwListWidget ilw = (XedwListWidget) w;
  1055. X
  1056. X  ilw->xedwList.xedwList = xedwList;
  1057. X  
  1058. X  if (nitems <= 0) nitems = 0;
  1059. X  ilw->xedwList.nitems = nitems;
  1060. X  if (longest <= 0) longest = 0;
  1061. X  ilw->xedwList.longest = longest;
  1062. X
  1063. X  ResetXedwList(w, resize_it, resize_it);
  1064. X  /* Free the memeory in the old list TODO */
  1065. X  ilw->xedwList.is_highlighted->index = ilw->xedwList.highlight = NO_HIGHLIGHT;
  1066. X  ilw->xedwList.is_highlighted->next = NULL;
  1067. X  if ( XtIsRealized(w) )
  1068. X    Redisplay(w, NULL, NULL);
  1069. X}
  1070. X
  1071. X/*  Function Name: XedwListUnhighlight
  1072. X *  Description: unlights the current highlighted element.
  1073. X *  Arguments: w - the widget.
  1074. X *  Returns: none.
  1075. X */
  1076. X
  1077. Xvoid XedwListUnhighlight(Widget w, int item)
  1078. X{
  1079. X  XedwListWidget ilw = ( XedwListWidget ) w;
  1080. X  LinkedList *list = ilw->xedwList.is_highlighted;
  1081. X  LinkedList *temp;
  1082. X
  1083. X  if (ilw->xedwList.is_highlighted->index != NO_HIGHLIGHT)
  1084. X    if (item == XedwAll) {
  1085. X      ilw->xedwList.highlight = list->index;    
  1086. X      PaintItemName(w, list->index, XedwOff);    /* unhighlight ALL */
  1087. X      while (list->next != NULL) {        
  1088. X    temp = list;
  1089. X    list = list->next;
  1090. X    ilw->xedwList.highlight = list->index;
  1091. X    PaintItemName(w, list->index, XedwOff);
  1092. X    XtFree(temp);
  1093. X      }
  1094. X      list->index = NO_HIGHLIGHT;
  1095. X      ilw->xedwList.is_highlighted = list;
  1096. X    } else {
  1097. X      ilw->xedwList.highlight = item;
  1098. X      PaintItemName(w, item, XedwOff);
  1099. X      RemoveNode(w, item);
  1100. X    }
  1101. X}
  1102. X
  1103. X/*  Function Name: XedwListHighlight
  1104. X *  Description: Highlights the given item.
  1105. X *  Arguments: w - the xedwList widget.
  1106. X *             item - the item to hightlight.
  1107. X *  Returns: none.
  1108. X */
  1109. X
  1110. Xvoid XedwListHighlight(Widget w, int item)
  1111. X{
  1112. X  XedwListWidget ilw = ( XedwListWidget ) w;
  1113. X  int n;
  1114. X
  1115. X  if (XtIsSensitive(w)) {
  1116. X    if (item == XedwAll) {
  1117. X      for(n=0; n < ilw->xedwList.nitems; n++) {
  1118. X    ilw->xedwList.highlight = n;
  1119. X    RemoveNode(w, n);
  1120. X    AddNode(w, n);
  1121. X    PaintItemName(w, n, XedwOn);
  1122. X      }
  1123. X    } else {
  1124. X      ilw->xedwList.highlight = item;
  1125. X      RemoveNode(w, item);
  1126. X      AddNode(w, item);
  1127. X      PaintItemName(w, item, XedwOn);    
  1128. X    }
  1129. X  }
  1130. X}
  1131. X
  1132. X/*  Function Name: XedwListShowCurrent
  1133. X *  Description: returns the currently highlighted object.
  1134. X *  Arguments: w - the xedwList widget.
  1135. X *  Returns: the info about the currently highlighted object.
  1136. X */
  1137. X
  1138. XXedwListReturnStruct *XedwListShowCurrent(Widget w)
  1139. X{
  1140. X  XedwListWidget ilw = ( XedwListWidget ) w;
  1141. X  LinkedList *hl = ilw->xedwList.is_highlighted;
  1142. X  XedwListReturnStruct *ret_val, *rest;
  1143. X
  1144. X  rest = NULL;
  1145. X  while (hl != NULL) {
  1146. X    ret_val = (XedwListReturnStruct *) XtMalloc (sizeof (XedwListReturnStruct));
  1147. X    
  1148. X    ret_val->xedwList_index = hl->index;
  1149. X    if (ret_val->xedwList_index == XDTM_LIST_NONE)
  1150. X      ret_val->string = "";
  1151. X    else
  1152. X      ret_val->string = 
  1153. X    XtNewString(ilw->xedwList.xedwList[ret_val->xedwList_index]->string);
  1154. X    hl = hl->next;
  1155. X    ret_val->next = rest;
  1156. X    rest = ret_val;
  1157. X  }
  1158. X  return(ret_val);
  1159. X}
  1160. X
  1161. XBoolean XedwListSelection(Widget w)
  1162. X{
  1163. X  XedwListWidget ilw = ( XedwListWidget ) w;
  1164. X  LinkedList *hl = ilw->xedwList.is_highlighted;
  1165. X  Boolean ret_val = True;
  1166. X  
  1167. X  if (hl->index == NO_HIGHLIGHT)
  1168. X    ret_val = False;
  1169. X
  1170. X  return(ret_val);
  1171. X}
  1172. X
  1173. X/* AddNode to LinkedList of highlighted items
  1174. X */
  1175. Xstatic void AddNode(Widget w, int item)
  1176. X{
  1177. X  XedwListWidget ilw = ( XedwListWidget ) w;
  1178. X  LinkedList *list = ilw->xedwList.is_highlighted;
  1179. X  LinkedList *temp;
  1180. X
  1181. X  if (list->index != NO_HIGHLIGHT) {
  1182. X    temp = (LinkedList*) XtMalloc (sizeof(LinkedList));
  1183. X    temp->index = item;
  1184. X    temp->next = list;
  1185. X    ilw->xedwList.is_highlighted = temp;
  1186. X  } else {
  1187. X    list->index = item;    /* jcc */
  1188. X    list->next = NULL;
  1189. X  }
  1190. X}
  1191. X  
  1192. X
  1193. Xstatic void RemoveNode(Widget w, int item)
  1194. X{
  1195. X  XedwListWidget ilw = ( XedwListWidget ) w;
  1196. X  LinkedList *list = ilw->xedwList.is_highlighted;
  1197. X  LinkedList *last;                              
  1198. X
  1199. X  last = list;
  1200. X  while (list != NULL && list->index != item) {
  1201. X    last = list;
  1202. X    list=list->next;
  1203. X  }
  1204. X  if (list != NULL) {            /* item WAS found */
  1205. X    if (last == list) {        /* it was the first item */
  1206. X      if (list->next == NULL)   /* there are no more in the list */
  1207. X    list->index = NO_HIGHLIGHT;
  1208. X      else {
  1209. X    ilw->xedwList.is_highlighted = list->next;
  1210. X    XtFree(list);
  1211. X      }
  1212. X    } else {
  1213. X      last->next = list->next;
  1214. X      XtFree(list);
  1215. X    }
  1216. X  } 
  1217. X}
  1218. SHAR_EOF
  1219. chmod 0644 xdtm/Xedw/XedwList.c ||
  1220. echo 'restore of xdtm/Xedw/XedwList.c failed'
  1221. Wc_c="`wc -c < 'xdtm/Xedw/XedwList.c'`"
  1222. test 38223 -eq "$Wc_c" ||
  1223.     echo 'xdtm/Xedw/XedwList.c: original size 38223, current size' "$Wc_c"
  1224. fi
  1225. # ============= xdtm/Xedw/XedwList.h ==============
  1226. if test -f 'xdtm/Xedw/XedwList.h' -a X"$1" != X"-c"; then
  1227.     echo 'x - skipping xdtm/Xedw/XedwList.h (File already exists)'
  1228. else
  1229. echo 'x - extracting xdtm/Xedw/XedwList.h (Text)'
  1230. sed 's/^X//' << 'SHAR_EOF' > 'xdtm/Xedw/XedwList.h' &&
  1231. X/*
  1232. X * Copyright 1989 Massachusetts Institute of Technology
  1233. X *
  1234. X * Permission to use, copy, modify, distribute, and sell this software and its
  1235. X * documentation for any purpose is hereby granted without fee, provided that
  1236. X * the above copyright notice appear in all copies and that both that
  1237. X * copyright notice and this permission notice appear in supporting
  1238. X * documentation, and that the name of M.I.T. not be used in advertising or
  1239. X * publicity pertaining to distribution of the software without specific,
  1240. X * written prior permission.  M.I.T. makes no representations about the
  1241. X * suitability of this software for any purpose.  It is provided "as is"
  1242. X * without express or implied warranty.
  1243. X *
  1244. X * M.I.T. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
  1245. X * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL M.I.T.
  1246. X * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  1247. X * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
  1248. X * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  1249. X * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  1250. X */
  1251. X
  1252. X/*
  1253. X * XedwList.h - XedwList widget
  1254. X *
  1255. X * This is the XedwList widget. It is very similar to the Athena Widget List,
  1256. X * except it has the ability to display an icon with the string.
  1257. X * It allows the user to select an item in a xedwList and notifies the
  1258. X * application through a callback function.
  1259. X *
  1260. X *  List Created:   8/13/88
  1261. X *  By:     Chris D. Peterson
  1262. X *                      MIT X Consortium
  1263. X *
  1264. X * Modified to XedwList: 1/26/90
  1265. X * By:      Edward Groenendaal
  1266. X *                      University of Sussex, UK.
  1267. X */
  1268. X
  1269. X#ifndef _XawXedwList_h
  1270. X#define _XawXedwList_h
  1271. X
  1272. X/***********************************************************************
  1273. X *
  1274. X * XedwList Widget
  1275. X *
  1276. X ***********************************************************************/
  1277. X
  1278. X#include <X11/Xaw/Simple.h>
  1279. X
  1280. X/* Resources:
  1281. X
  1282. X Name               Class           RepType             Default Value
  1283. X ----               -----           -------             -------------
  1284. X background         Background      Pixel               XtDefaultBackground
  1285. X border             BorderColor     Pixel               XtDefaultForeground
  1286. X borderWidth        BorderWidth     Dimension           1
  1287. X callback           Callback        XtCallbackXedwList  NULL       **6
  1288. X columnSpacing      Spacing         Dimension           6
  1289. X cursor             Cursor          Cursor              left_ptr
  1290. X defaultColumns     Columns         int                 2          **5
  1291. X destroyCallback    Callback        Pointer             NULL
  1292. X font               Font            XFontStruct*        XtDefaultFont
  1293. X forceColumns       Columns         Boolean             False      **5
  1294. X foreground         Foreground      Pixel               XtDefaultForeground
  1295. X height             Height          Dimension           0          **1
  1296. X insensitiveBorder  Insensitive     Pixmap              Gray
  1297. X internalHeight     Height          Dimension           2
  1298. X internalWidth      Width           Dimension           4
  1299. X xedwList           XedwList        XedwList **      NULL       **2
  1300. X iconWidth          Width           Dimension           32
  1301. X iconHeight         Height          Dimension           32
  1302. X longest            Longest         int                 0          **3  **4
  1303. X mappedWhenManaged  MappedWhenManaged   Boolean         True
  1304. X mSelections        Boolean         Boolean             False
  1305. X numberStrings      NumberStrings   int                 0          **4
  1306. X pasteBuffer        Boolean         Boolean             False
  1307. X rowSpacing         Spacing         Dimension           4
  1308. X sensitive          Sensitive       Boolean             True
  1309. X showIcons          Boolean         Boolean             False                  
  1310. X verticalList       Boolean         Boolean             False
  1311. X width              Width           Dimension           0          **1
  1312. X x                  Position        Position            0
  1313. X y                  Position        Position            0
  1314. X
  1315. X **1 - If the Width or Height of the xedwList widget is zero (0) then the value
  1316. X       is set to the minimum size necessay to fit the entire list.
  1317. X
  1318. X       If both Width and Height are zero then they are adjusted to fit the
  1319. X       entire list that is created width the number of default columns
  1320. X       specified in the defaultColumns resource.
  1321. X
  1322. X **2 - This is an array of strings the specify elements of the xedwList.
  1323. X       This resource must be specified.
  1324. X
  1325. X **3 - Longest is the length of the widest string in pixels.
  1326. X
  1327. X **4 - If either of these values are zero (0) then the xedwList widget calculates
  1328. X       the correct value.
  1329. X
  1330. X       (This allows you to make startup faster if you already have
  1331. X        this information calculated)
  1332. X
  1333. X       NOTE: If the numberStrings value is zero the xedwList must
  1334. X             be NULL terminated.
  1335. X
  1336. X **5 - By setting the XedwList.Columns resource you can force the application to
  1337. X       have a given number of columns.
  1338. X
  1339. X **6 - This returns the name and index of the item selected in an
  1340. X       XedwListReturnStruct that is pointed to by the client_data
  1341. X       in the CallbackProc.
  1342. X
  1343. X*/
  1344. X
  1345. X
  1346. X/*
  1347. X * Value returned when there are no highlighted objects.
  1348. X */
  1349. X
  1350. X#define XDTM_LIST_NONE -1
  1351. X
  1352. X#define XtCXedwList "XedwList"
  1353. X#define XtCSpacing "Spacing"
  1354. X#define XtCColumns "Columns"
  1355. X#define XtCLongest "Longest"
  1356. X#define XtCNumberStrings "NumberStrings"
  1357. X
  1358. X#define XtNcursor "cursor"
  1359. X#define XtNcolumnSpacing "columnSpacing"
  1360. X#define XtNdefaultColumns "defaultColumns"
  1361. X#define XtNforceColumns "forceColumns"
  1362. X#define XtNxedwList "xedwList"
  1363. X#define XtNiconWidth "iconWidth"
  1364. X#define XtNiconHeight "iconHeight"
  1365. X#define XtNdefaultIcon "defaultIcon"
  1366. X#define XtNlongest "longest"
  1367. X#define XtNnumberStrings "numberStrings"
  1368. X#define XtNpasteBuffer "pasteBuffer"
  1369. X#define XtNrowSpacing "rowSpacing"
  1370. X#define XtNshowIcons "showIcons"
  1371. X#define XtNmSelections "mSelections"
  1372. X#define XtNverticalList "verticalList"
  1373. X
  1374. X#define XedwSingle    1
  1375. X#define XedwMultiple  2
  1376. X
  1377. X#define XedwAll            -1
  1378. X
  1379. X#define IconBitmapWidth       32
  1380. X#define IconBitmapHeight      32
  1381. X
  1382. X/* Class record constants */
  1383. X
  1384. Xextern WidgetClass xedwListWidgetClass;
  1385. X
  1386. Xtypedef struct _XedwListClassRec *XedwListWidgetClass;
  1387. Xtypedef struct _XedwListRec      *XedwListWidget;
  1388. X
  1389. X/* The structure of XedwList */
  1390. X
  1391. Xtypedef struct _XedwList {
  1392. X  String string;
  1393. X  Pixmap icon;
  1394. X} XedwList;
  1395. X
  1396. X/* The xedwList return structure. */
  1397. X
  1398. Xtypedef struct _XedwListReturnStruct {
  1399. X  String   string;            /* String */
  1400. X  int      xedwList_index;        /* Index into list */
  1401. X  struct _XedwListReturnStruct *next;    /* Next highlighted entry */
  1402. X} XedwListReturnStruct;
  1403. X
  1404. X/******************************************************************
  1405. X *
  1406. X * Exported Functions
  1407. X *
  1408. X *****************************************************************/
  1409. X
  1410. X/*  Function Name:  XedwListChange.
  1411. X *  Description:    Changes the xedwList being used and shown.
  1412. X *  Arguments:      w        -  the xedwList widget.
  1413. X *                  xedwList -  the new xedwList.
  1414. X *                  nitems   -  the number of items in the xedwList.
  1415. X *                  longest  -  the length (in Pixels) of the longest element
  1416. X *                              in the xedwList.
  1417. X *                  resize   -  if TRUE the the xedwList widget will
  1418. X *                              try to resize itself.
  1419. X *  Returns: none.
  1420. X *  NOTE:    If nitems of longest are <= 0 then they will be caluculated.
  1421. X *           If nitems is <= 0 then the xedwList needs to be NULL terminated.
  1422. X */
  1423. X
  1424. Xextern void XedwListChange(Widget, XedwList**,int,int,Boolean); 
  1425. X
  1426. X/*  Function Name:  XedwListUnhighlight
  1427. X *  Description:    unlights the current highlighted element.
  1428. X *  Arguments:      w   -   the widget.
  1429. X *  Returns: none.
  1430. X */
  1431. X
  1432. Xextern void XedwListUnhighlight(Widget, int);
  1433. X
  1434. X/*  Function Name:  XedwListHighlight
  1435. X *  Description:    Highlights the given item.
  1436. X *  Arguments:      w    -  the xedwList widget.
  1437. X *                  item -  the item to hightlight.
  1438. X *  Returns: none.
  1439. X */
  1440. X
  1441. Xextern void XedwListHighlight(Widget, int); 
  1442. X
  1443. X
  1444. X/*  Function Name: XedwListShowCurrent
  1445. X *  Description: returns the currently highlighted objects.
  1446. X *  Arguments: w - the xedwList widget.
  1447. X *  Returns: the info about the currently highlighted object.
  1448. X */
  1449. X
  1450. Xextern XedwListReturnStruct *XedwListShowCurrent(Widget);
  1451. X
  1452. Xextern Boolean XedwListSelection(Widget);
  1453. X
  1454. X#endif /* _XedwList_h */
  1455. X
  1456. SHAR_EOF
  1457. chmod 0644 xdtm/Xedw/XedwList.h ||
  1458. echo 'restore of xdtm/Xedw/XedwList.h failed'
  1459. Wc_c="`wc -c < 'xdtm/Xedw/XedwList.h'`"
  1460. test 8356 -eq "$Wc_c" ||
  1461.     echo 'xdtm/Xedw/XedwList.h: original size 8356, current size' "$Wc_c"
  1462. fi
  1463. true || echo 'restore of xdtm/Xedw/XedwListP.h failed'
  1464. echo End of part 3, continue with part 4
  1465. exit 0
  1466.  
  1467. --
  1468. Dan Heller
  1469. O'Reilly && Associates       Z-Code Software    Comp-sources-x:
  1470. Senior Writer                President          comp-sources-x@uunet.uu.net
  1471. argv@ora.com                 argv@zipcode.com
  1472.