home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / x / volume17 / xbae / part12 < prev    next >
Encoding:
Text File  |  1992-03-22  |  11.5 KB  |  374 lines

  1. Newsgroups: comp.sources.x
  2. Path: uunet!usc!rpi!zaphod.mps.ohio-state.edu!mips!msi!dcmartin
  3. From: Andrew Wason <aw@bae.bellcore.com>
  4. Subject: v17i039: Xbae widgets (MOTIF), Part12/12
  5. Message-ID: <1992Mar23.180458.16458@msi.com>
  6. Originator: dcmartin@fascet
  7. Sender: dcmartin@msi.com (David C. Martin - Moderator)
  8. Organization: Molecular Simulations, Inc.
  9. References: <csx-17i028-xbae@uunet.UU.NET>
  10. Date: Mon, 23 Mar 1992 18:04:58 GMT
  11. Approved: dcmartin@msi.com
  12. Lines: 360
  13.  
  14. Submitted-by: Andrew Wason <aw@bae.bellcore.com>
  15. Posting-number: Volume 17, Issue 39
  16. Archive-name: xbae/part12
  17.  
  18. Submitted-by: aw@jello
  19. Archive-name: Xbae/part12
  20.  
  21. ---- Cut Here and feed the following to sh ----
  22. #!/bin/sh
  23. # this is Xbae.shar.12 (part 12 of Xbae)
  24. # do not concatenate these parts, unpack them in order with /bin/sh
  25. # file Xbae/examples/README continued
  26. #
  27. if test ! -r _shar_seq_.tmp; then
  28.     echo 'Please unpack part 1 first!'
  29.     exit 1
  30. fi
  31. (read Scheck
  32.  if test "$Scheck" != 12; then
  33.     echo Please unpack part "$Scheck" next!
  34.     exit 1
  35.  else
  36.     exit 0
  37.  fi
  38. ) < _shar_seq_.tmp || exit 1
  39. if test ! -f _shar_wnt_.tmp; then
  40.     echo 'x - still skipping Xbae/examples/README'
  41. else
  42. echo 'x - continuing file Xbae/examples/README'
  43. sed 's/^X//' << 'SHAR_EOF' >> 'Xbae/examples/README' &&
  44. set the XENVIRONMENT variable to point to the appropriate resource
  45. file and run the program, e.g.:
  46. X
  47. X  cd matrix
  48. X  XENVIRONMENT=Matrix.ad matrix
  49. X
  50. You can also use the shell script "runtest" in this directory to
  51. run all the examples.
  52. X
  53. X
  54. matrix
  55. X  A simple example of a loaded XbaeMatrix widget.
  56. X
  57. colors
  58. X  Interactively sets row, column and cell colors to the color name
  59. X  entered in a cell.
  60. X
  61. traversal
  62. X  Example of custom traversal.  Defines new traversal type -- when Return
  63. X  is pressed, moves down a row and back to the first column (carriage return).
  64. X
  65. dynamic
  66. X  Dynamically expands the matrix when a row/column boundary is passed.
  67. X
  68. select
  69. X  Demonstrates row/column/cell selection techniques. Requires Wcl.
  70. X
  71. select-drag
  72. X  Demonstrates "dragging out a rectangle" selection technique.
  73. X
  74. add
  75. X  Demonstrates dynamically adding multiple rows and columns.
  76. X
  77. caption
  78. X  Demonstrates five configurations using XbaeCaption.
  79. X
  80. Mri
  81. X  A version of Mri which knows about the XbaeMatrix and XbaeCaption widgets.
  82. X  Requires Wcl.  Two simple Wcl resource files creating a Matrix and
  83. X  Caption widget are provided.
  84. SHAR_EOF
  85. echo 'File Xbae/examples/README is complete' &&
  86. chmod 0644 Xbae/examples/README ||
  87. echo 'restore of Xbae/examples/README failed'
  88. Wc_c="`wc -c < 'Xbae/examples/README'`"
  89. test 1157 -eq "$Wc_c" ||
  90.     echo 'Xbae/examples/README: original size 1157, current size' "$Wc_c"
  91. rm -f _shar_wnt_.tmp
  92. fi
  93. # ============= Xbae/examples/Imakefile ==============
  94. if test -f 'Xbae/examples/Imakefile' -a X"$1" != X"-c"; then
  95.     echo 'x - skipping Xbae/examples/Imakefile (File already exists)'
  96.     rm -f _shar_wnt_.tmp
  97. else
  98. > _shar_wnt_.tmp
  99. echo 'x - extracting Xbae/examples/Imakefile (Text)'
  100. sed 's/^X//' << 'SHAR_EOF' > 'Xbae/examples/Imakefile' &&
  101. #include "../Xbae.tmpl"
  102. X
  103. #define IHaveSubdirs
  104. #define PassCDebugFlags 'CDEBUGFLAGS=$(CDEBUGFLAGS)'
  105. X
  106. #if HaveWcl
  107. X    SUBDIRS = Mri add caption colors dynamic matrix select select-drag traversal
  108. #else
  109. X    SUBDIRS = add caption colors dynamic matrix select-drag traversal
  110. #endif
  111. X
  112. MakeSubdirs($(SUBDIRS))
  113. DependSubdirs($(SUBDIRS))
  114. SHAR_EOF
  115. chmod 0644 Xbae/examples/Imakefile ||
  116. echo 'restore of Xbae/examples/Imakefile failed'
  117. Wc_c="`wc -c < 'Xbae/examples/Imakefile'`"
  118. test 327 -eq "$Wc_c" ||
  119.     echo 'Xbae/examples/Imakefile: original size 327, current size' "$Wc_c"
  120. rm -f _shar_wnt_.tmp
  121. fi
  122. # ============= Xbae/examples/select-drag/Imakefile ==============
  123. if test ! -d 'Xbae/examples/select-drag'; then
  124.     echo 'x - creating directory Xbae/examples/select-drag'
  125.     mkdir 'Xbae/examples/select-drag'
  126. fi
  127. if test -f 'Xbae/examples/select-drag/Imakefile' -a X"$1" != X"-c"; then
  128.     echo 'x - skipping Xbae/examples/select-drag/Imakefile (File already exists)'
  129.     rm -f _shar_wnt_.tmp
  130. else
  131. > _shar_wnt_.tmp
  132. echo 'x - extracting Xbae/examples/select-drag/Imakefile (Text)'
  133. sed 's/^X//' << 'SHAR_EOF' > 'Xbae/examples/select-drag/Imakefile' &&
  134. #include "../../Xbae.tmpl"
  135. X
  136. X   LOCAL_LDFLAGS = -L../../src
  137. X LOCAL_LIBRARIES = -lXbae -lXm -lXt -lX11
  138. X         DEPLIBS =
  139. X        INCLUDES = -I../../src
  140. X         DEFINES = -D_NO_PROTO
  141. X
  142. UninstalledSimpleProgramTarget(select-drag)
  143. SHAR_EOF
  144. chmod 0644 Xbae/examples/select-drag/Imakefile ||
  145. echo 'restore of Xbae/examples/select-drag/Imakefile failed'
  146. Wc_c="`wc -c < 'Xbae/examples/select-drag/Imakefile'`"
  147. test 227 -eq "$Wc_c" ||
  148.     echo 'Xbae/examples/select-drag/Imakefile: original size 227, current size' "$Wc_c"
  149. rm -f _shar_wnt_.tmp
  150. fi
  151. # ============= Xbae/examples/select-drag/select-drag.c ==============
  152. if test -f 'Xbae/examples/select-drag/select-drag.c' -a X"$1" != X"-c"; then
  153.     echo 'x - skipping Xbae/examples/select-drag/select-drag.c (File already exists)'
  154.     rm -f _shar_wnt_.tmp
  155. else
  156. > _shar_wnt_.tmp
  157. echo 'x - extracting Xbae/examples/select-drag/select-drag.c (Text)'
  158. sed 's/^X//' << 'SHAR_EOF' > 'Xbae/examples/select-drag/select-drag.c' &&
  159. /*
  160. X * Copyright(c) 1992 Bell Communications Research, Inc. (Bellcore)
  161. X *                        All rights reserved
  162. X * Permission to use, copy, modify and distribute this material for
  163. X * any purpose and without fee is hereby granted, provided that the
  164. X * above copyright notice and this permission notice appear in all
  165. X * copies, and that the name of Bellcore not be used in advertising
  166. X * or publicity pertaining to this material without the specific,
  167. X * prior written permission of an authorized representative of
  168. X * Bellcore.
  169. X *
  170. X * BELLCORE MAKES NO REPRESENTATIONS AND EXTENDS NO WARRANTIES, EX-
  171. X * PRESS OR IMPLIED, WITH RESPECT TO THE SOFTWARE, INCLUDING, BUT
  172. X * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  173. X * FITNESS FOR ANY PARTICULAR PURPOSE, AND THE WARRANTY AGAINST IN-
  174. X * FRINGEMENT OF PATENTS OR OTHER INTELLECTUAL PROPERTY RIGHTS.  THE
  175. X * SOFTWARE IS PROVIDED "AS IS", AND IN NO EVENT SHALL BELLCORE OR
  176. X * ANY OF ITS AFFILIATES BE LIABLE FOR ANY DAMAGES, INCLUDING ANY
  177. X * LOST PROFITS OR OTHER INCIDENTAL OR CONSEQUENTIAL DAMAGES RELAT-
  178. X * ING TO THE SOFTWARE.
  179. X */
  180. X
  181. #include <stdio.h>
  182. #include <Xm/Xm.h>
  183. #include <Xbae/Matrix.h>
  184. X
  185. void LoadMatrix();
  186. void SelectCB();
  187. X
  188. /*
  189. X * Create an uneditable matrix. When Btn1 is dragged, a rectangular region
  190. X * of cells is selected.
  191. X */
  192. X
  193. void
  194. main(argc, argv)
  195. int argc;
  196. char *argv[];
  197. {
  198. X    Widget toplevel, matrix;
  199. X    XtAppContext app;
  200. X
  201. X    toplevel = XtAppInitialize(&app, "Select-drag",
  202. X                   NULL, 0,
  203. X                   (Cardinal *)&argc, argv,
  204. X                   NULL,
  205. X                   NULL, 0);
  206. X
  207. X    matrix = XtVaCreateManagedWidget("matrix",
  208. X                     xbaeMatrixWidgetClass, toplevel,
  209. X                     NULL);
  210. X    XtAddCallback(matrix, XmNselectCellCallback, SelectCB, NULL);
  211. X    LoadMatrix(matrix);
  212. X
  213. X    XtRealizeWidget(toplevel);
  214. X    XtAppMainLoop(app);
  215. }
  216. X
  217. /*
  218. X * Callback when the mouse is moved, we want to select a rectangle of cells
  219. X */
  220. /* ARGSUSED */
  221. void
  222. SelectCB(w, client_data, call_data)
  223. Widget w;
  224. XXtPointer client_data;
  225. XXbaeMatrixSelectCellCallbackStruct *call_data;
  226. {
  227. X    static int start_row, start_column;
  228. X    static int last_row, last_column;
  229. X    int i, j;
  230. X
  231. X    /*
  232. X     * If we have params, we must be starting a rectangle
  233. X     */
  234. X    if (call_data->num_params) {
  235. X    start_row = last_row = call_data->row;
  236. X    start_column = last_column = call_data->column;
  237. X    XbaeMatrixSelectCell(w, last_row, last_column);
  238. X    }
  239. X    /*
  240. X     * Else we are in the middle of dragging a rectangle
  241. X     */
  242. X    else {
  243. X    /*
  244. X     * This is a pretty simplistic, stupid implementation
  245. X     * of selecting a rectangle.
  246. X     */
  247. X    if (call_data->row > last_row) {
  248. X        for (i = last_row + 1; i <= call_data->row; i++)
  249. X        for (j = start_column; j <= call_data->column; j++)
  250. X            XbaeMatrixSelectCell(w, i, j);
  251. X    }
  252. X    if (call_data->column > last_column) {
  253. X        for (i = start_row; i <= last_row; i++)
  254. X        for (j = last_column + 1; j <= call_data->column; j++)
  255. X            XbaeMatrixSelectCell(w, i, j);
  256. X    }
  257. X
  258. X    last_row = call_data->row;
  259. X    last_column = call_data->column;
  260. X    }
  261. }
  262. X
  263. /* ARGSUSED */
  264. void
  265. LoadMatrix(matrix)
  266. Widget matrix;
  267. {
  268. X    int i, j;
  269. X    int rows, columns;
  270. X    char buf[BUFSIZ];
  271. X    String **cells;
  272. X
  273. X    XtVaGetValues(matrix,
  274. X          XmNrows, &rows,
  275. X          XmNcolumns, &columns,
  276. X          NULL);
  277. X
  278. X    cells = (String **) XtMalloc(sizeof(String *) * rows);
  279. X    for (i = 0; i < rows; i++) {
  280. X    cells[i] = (String *) XtMalloc(sizeof(String) * columns);
  281. X    for (j = 0; j < columns; j++) {
  282. X        sprintf(buf, "r%dc%d", i, j);
  283. X        cells[i][j] = XtNewString(buf);
  284. X    }
  285. X    }
  286. X
  287. X    XtVaSetValues(matrix,
  288. X          XmNcells, cells,
  289. X          NULL);
  290. X
  291. X    for (i = 0; i < rows; i++) {
  292. X    for (j = 0; j < columns; j++)
  293. X        XtFree((XtPointer)cells[i][j]);
  294. X    XtFree((XtPointer)cells[i]);
  295. X    }
  296. X    XtFree((XtPointer)cells);
  297. }
  298. SHAR_EOF
  299. chmod 0644 Xbae/examples/select-drag/select-drag.c ||
  300. echo 'restore of Xbae/examples/select-drag/select-drag.c failed'
  301. Wc_c="`wc -c < 'Xbae/examples/select-drag/select-drag.c'`"
  302. test 3695 -eq "$Wc_c" ||
  303.     echo 'Xbae/examples/select-drag/select-drag.c: original size 3695, current size' "$Wc_c"
  304. rm -f _shar_wnt_.tmp
  305. fi
  306. # ============= Xbae/examples/select-drag/Select-drag.ad ==============
  307. if test -f 'Xbae/examples/select-drag/Select-drag.ad' -a X"$1" != X"-c"; then
  308.     echo 'x - skipping Xbae/examples/select-drag/Select-drag.ad (File already exists)'
  309.     rm -f _shar_wnt_.tmp
  310. else
  311. > _shar_wnt_.tmp
  312. echo 'x - extracting Xbae/examples/select-drag/Select-drag.ad (Text)'
  313. sed 's/^X//' << 'SHAR_EOF' > 'Xbae/examples/select-drag/Select-drag.ad' &&
  314. *matrix.rows:        25
  315. *matrix.columns:    15
  316. *matrix.columnWidths:    10,10,10,6,6,6,10,10,10,6,6,6,6,6,6
  317. *matrix.visibleRows:    15
  318. X
  319. !
  320. ! We have an uneditable matrix. Apply translations to clip widget too
  321. ! to get autoscrolling as we drag
  322. !
  323. *matrix.translations:    #replace\n\
  324. X            <Btn1Down>:    SelectCell(start)\n\
  325. X            <Btn1Motion>:    SelectCell()
  326. *matrix.clip.translations:    #replace\n\
  327. X                <Btn1Down>:    SelectCell(start)\n\
  328. X                <Btn1Motion>:    SelectCell()
  329. *matrix.traversalOn:    off
  330. SHAR_EOF
  331. chmod 0644 Xbae/examples/select-drag/Select-drag.ad ||
  332. echo 'restore of Xbae/examples/select-drag/Select-drag.ad failed'
  333. Wc_c="`wc -c < 'Xbae/examples/select-drag/Select-drag.ad'`"
  334. test 461 -eq "$Wc_c" ||
  335.     echo 'Xbae/examples/select-drag/Select-drag.ad: original size 461, current size' "$Wc_c"
  336. rm -f _shar_wnt_.tmp
  337. fi
  338. # ============= Xbae/examples/runtest ==============
  339. if test -f 'Xbae/examples/runtest' -a X"$1" != X"-c"; then
  340.     echo 'x - skipping Xbae/examples/runtest (File already exists)'
  341.     rm -f _shar_wnt_.tmp
  342. else
  343. > _shar_wnt_.tmp
  344. echo 'x - extracting Xbae/examples/runtest (Text)'
  345. sed 's/^X//' << 'SHAR_EOF' > 'Xbae/examples/runtest' &&
  346. #!/bin/sh
  347. X
  348. env XENVIRONMENT=Mri/Matrix.ad Mri/Mri
  349. env XENVIRONMENT=Mri/Caption.ad Mri/Mri
  350. env XENVIRONMENT=add/Add.ad add/add
  351. env XENVIRONMENT=caption/Caption.ad caption/caption
  352. env XENVIRONMENT=colors/Colors.ad colors/colors
  353. env XENVIRONMENT=dynamic/Dynamic.ad dynamic/dynamic
  354. env XENVIRONMENT=matrix/Matrix.ad matrix/matrix
  355. env XENVIRONMENT=select/Select.ad select/select
  356. env XENVIRONMENT=select-drag/Select-drag.ad select-drag/select-drag
  357. env XENVIRONMENT=traversal/Traversal.ad traversal/traversal
  358. SHAR_EOF
  359. chmod 0755 Xbae/examples/runtest ||
  360. echo 'restore of Xbae/examples/runtest failed'
  361. Wc_c="`wc -c < 'Xbae/examples/runtest'`"
  362. test 502 -eq "$Wc_c" ||
  363.     echo 'Xbae/examples/runtest: original size 502, current size' "$Wc_c"
  364. rm -f _shar_wnt_.tmp
  365. fi
  366. rm -f _shar_seq_.tmp
  367. echo You have unpacked the last part
  368. exit 0
  369. -- 
  370. --
  371. Molecular Simulations, Inc.            mail: dcmartin@msi.com
  372. 796 N. Pastoria Avenue                uucp: uunet!dcmartin
  373. Sunnyvale, California 94086            at&t: 408/522-9236
  374.