home *** CD-ROM | disk | FTP | other *** search
/ Computer Club Elmshorn Atari PD / CCE_PD.iso / pc / 0600 / CCE_0636.ZIP / CCE_0636 / CURSES / CRSSRC12.ZOO / widget / widget.ms < prev    next >
Text File  |  1991-05-03  |  11KB  |  340 lines

  1. .ND
  2. .LP
  3. .nr PS 12
  4. .nr VS 13
  5. .LP
  6. .nh
  7. .RP
  8. .TL
  9. A Window based Interactive Programming Utility On Unix:
  10. A Library Package for C programmers
  11. .AU
  12. Richard A. Culshaw
  13. .AI
  14. GEC Hirst Research Centre
  15. Data Systems Division
  16. East Lane
  17. Wembley
  18. Middlesex HA9 7PP
  19. .ND
  20. .KS
  21. .SH
  22. INTRODUCTION
  23.  
  24. .PP
  25. A Widget is a user definable 
  26. .B "window gadget."
  27.  They allow the user to interact with the program in specifying operations to be carried out. Widgetlib is a set of library functions which allows the user to create and interact with 
  28. .B widgets.
  29. A widget can be one of four types :
  30. .LP
  31.       1) 
  32. .B Command 
  33. Widget 
  34.       2) 
  35. .B Label 
  36. Widget
  37.       3) 
  38. .B Toggle 
  39. Widget
  40.       4) 
  41. .B Input 
  42. Widget
  43.  
  44. .SH
  45. Command Widgets
  46. .PP
  47. A command widget allows the user to select a function to be carried out, e.g in a paging program one such command could be 'Next Page'. In creating a command widget the programmer must pass it the function to be carried out when the widget is selected (activated). The widget is activated using a unique 'activation' character which is displayed in the widget for easy reference.
  48.  
  49. .SH
  50. Label Widgets
  51. .PP
  52. A label widget is simply a widget which holds a character string such as a heading, which can be changed at will later. The programmer can supply parameters which can either left justify (default), right justify, or centre the message within the widget (which has a user definable width) as well as highlight (default) or dehighlight it.
  53.  
  54. .SH
  55. Toggle Widgets
  56. .PP
  57. A toggle widget contains a message which indicates the current value of an entity which can be more than one value e.g, Yes/No/Don't-Know. The value is toggled when a given character is pressed. The activation character is also displayed in the widget. At any point the programmer can enquire as to the the current toggle value.
  58.  
  59. .SH
  60. Input Widgets
  61. .PP
  62. An input widget allows the user to enter information into the program in the form of a string, e.g in a paging program one might want to supply a file name. There are two types of input widgets :
  63.  
  64. a) The widget is activated immediately on creation therefore an activation character is not required. E.g in a paging program one might have a command widget which activates this type of input widget in order to get a file name.
  65. .LP
  66. b) The widget has an associated activation character so therefore it may be activated at any point after creation. The character is displayed in the widget.
  67.  
  68. For ease of use the input widgets contain character strings which can explain
  69. there use within the program.
  70. .KE
  71. .bp
  72. .SH
  73. Text Window
  74. .PP
  75. The library also allows the user to define a text window into which the program may report information. On creation the program has to pass a parameter which specifies how much room to leave before the top of the text window. E.g 0 means place the window immediately below the lowest widget, 1 means allow room for one more row of widgets before placing the window. The text window always stretches to the bottom of the screen. The window can be bordered on any 2 opposite sides or on all 4 (effectively b
  76. it).
  77.  
  78. .SH
  79. Widget Placement
  80. .PP
  81. The library maintains the current X,Y coordinate of the last widget created. When a new widget is created the program must pass a parameter 0 or 1. A 0 means put the new widget on the current row if possible, else go onto the next row. A 1 forces the new widget onto the next row. This means that widgets can only go after preceding ones and not before. But however widgets can be placed over widgets which have previously been destroyed.
  82.  
  83. .SH
  84. Compiling Things
  85. .PP
  86. In order to use the library, it is necessary to have certain types and variables defined. Therefore, the program must have the line:
  87. .PP
  88. .B "#include <widgets.h>"
  89. .LP
  90. at the top of the source. The header file includes <curses.h>, <sgetty.h>, <stdio.h> so you don't have to include them also. Also compilations should have the following form:
  91. .PP
  92. .B "cc [flags] file ... -lwidgets -lcurses"
  93.  
  94. .SH
  95. Type Definitions
  96. .LP
  97. The functions which create widgets return a type 
  98. .B WIDGET
  99. which is used for later identification of the widget.
  100. .LP
  101. If a function is required to return a widget identifier, then it will return 
  102. .B NULLWIDGET
  103. upon error.
  104.  
  105. .SH
  106. Screen Refresh
  107. .LP
  108. The library supports a standard screen refresh invoked by ^L.
  109. .KE
  110. .bp
  111. .KS
  112. .SH
  113.                                               USAGE
  114. .SH
  115. Getting Started
  116. .LP
  117. The first thing to do when using the library is set up the windowing system by calling 
  118. .LP
  119. .in 0.5i
  120. initialisewidgets()
  121. .in 0
  122.  
  123. .SH
  124. Creating Widgets
  125. .LP
  126. .br
  127.  
  128. .in 0.5i
  129. WIDGET mkcmdwidget (message, ch, function, row)
  130. .br 
  131. char message[];
  132. .br 
  133. char ch;
  134. .br 
  135. int 
  136. (*func)();
  137. .br 
  138. int line;
  139. .in 0
  140. .LP
  141. Creates a new command widget. message holds the message to be displayed in the command widget. ch is the activation character on which function is executed. row specifies where to place the widget (as described above). The returned value is the widget identifier for later use.
  142.  
  143. .LP
  144. .in 0.5i
  145. WIDGET mklblwidget (message, position, space, row)
  146. .br
  147. char message[];
  148. .br
  149. int  position, space, row;
  150. .in 0
  151. .LP
  152. Creates a new label widget. Message holds the contents of the label, position specifies how the message is to appear. Using the constants CENTRE, LEFTJUST, RIGHTJUST, NOHIGH, pass a combination to position e.g CENTRE or LEFTJUST|NOHIGH etc.space indicates how large the label widget is to be. A positive value is the absolute length of the widget, whereas value <= 0 specifies how far the widget is to be from the righthand edge of the screen. row specifies where to place the widget (as described above).
  153. eturned value is the widget identifier for later use.
  154.  
  155. .LP
  156. .in 0.5i
  157. WIDGET mktglwidget (message, number, tgl, tglch, row)
  158. .br
  159. char message[];
  160. .br
  161. int  number;
  162. .br
  163. char tgl[10][20];
  164. .br
  165. char tglch;
  166. .br
  167. int  row;
  168. .in 0
  169. .LP
  170. Creates a new toggle widget. message contains a label for the widget, and number holds the number of toggle values. tgl is used for holding actual toggle values which are toggled between using the activation character tglch. At present there is a limit of 10 toggle values, each being a maximum length of 20 characters. row specifies where to place the widget (as described above). The returned value is the widget identifier for later use.
  171. .LP
  172. .KE
  173. .bp
  174. .KS
  175. .in 0.5i
  176. WIDGET mkinpwidget (message, character, input, lengthstr, lengthwid, row, exec)
  177. .br
  178. char message[], character, input[];
  179. .br
  180. int  lengthstr, lengthwid, row, exec; 
  181. .in 0
  182. .LP
  183. Creates a new input widget. message contains the label for the widget, and character is the activation character for the widget. input is the variable in which the user wishes the data obtained from the input widget to be placed, lengthstr is the length of input. lengthwid specifies how big to make the widget. A positive value indicates the absolute length of the widget, where as a value <= 0 indicates how far from the righthand edge the widget is to be. exec is used to indicate whether the widget sh
  184. e activated on creation by (passing EXEC), or should remain dormant until the activation character is used (passing NOEXEC). (n.b when passing EXEC an activation character is not needed therefore one could pass NULL for character.)
  185.  
  186. .SH
  187. Text Window Management
  188. .LP
  189. .br
  190.  
  191. .in 0.5i
  192. int opentextwindow (position, border)
  193. .br
  194. int position, border;
  195. .in 0
  196. .LP
  197. Opens and displays the text window. position specifies where the window is to go. i.e position = 0 will place the window immediately below the lowest widget, position = 1 will allow room for 1 more row of widgets below the current lowest before placing the window etc. border is used to indicate whether the window should be bordered. i.e using the parameters VERTICAL & HORIZONTAL, one can specify whether the window should be bordered vertically (passing VERTICAL), horizontally (passing HORIZONTAL), bo
  198. ssing VERTICAL|HORIZONTAL), or neither (passing 0). The function returns the number of lines within the window.
  199.  
  200. .in 0.5i
  201. report (message)
  202. .br
  203. char *message;
  204. .in 0
  205. .LP
  206. Displays the given message in the text window. Scrolling is done automatically when the bottom of the window is reached and is therefore of no concern for the user.
  207.  
  208. .in 0.5i
  209. cleartextwindow ()
  210. .in 0
  211. .LP
  212. Clears the text window and returns its cursor to the top lefthand corner. 
  213.  
  214. .in 0.5i
  215. killtextwindow ()
  216. .in 0
  217. .LP
  218. Destroys the text window. The text window can be redefined at a later date.
  219.  
  220. .SH
  221. Killing Widgets
  222.  
  223. .LP
  224. .br
  225. .in 0.5i
  226. int killwidget (ptr)
  227. .br
  228. WIDGET ptr;
  229. .in 0
  230. .LP
  231. Kills the given widget. the function returns TRUE if successfull or FALSE if the widget doesn't exist.
  232. .KE
  233. .bp
  234. .KS
  235. .SH
  236. Interaction
  237.  
  238. .LP
  239. .br
  240. .in 0.5i
  241. WIDGET widgetinput ()
  242. .in 0
  243. .LP
  244. Wait for input from widgets. Program control is passed back when :-
  245. .br
  246. a) A Command widget is activated and control is passed to its associated function.
  247. .br
  248. b) An input widget is activated and after subsequent input, control is passed to the calling function with the widget pointer of the activated input widget.
  249. .br
  250. Activating a toggle widget just toggles the widget, control is only passed back upon one of the above conditions.
  251.  
  252. .LP
  253. .br
  254. .in 0.5i
  255. int tsttglwidget (ptr)
  256. .br
  257. WIDGET ptr;
  258. .in 0
  259. .LP
  260. Returns the index value of the current state of the given toggle widget (0 < index < number toggle values - 1). Returns FALSE if the given widget does not exist.
  261.  
  262. .LP
  263. .br
  264. .in 0.5i
  265. int activate (ptr)
  266. .br
  267. WIDGET ptr;
  268. .in 0
  269. .LP
  270. Reactivates a widget which was previously deactivated. Returns TRUE if successful otherwise FALSE.
  271.  
  272. .LP
  273. .br
  274. .in 0.5i
  275. int deactivate (ptr, blank)
  276. .br
  277. WIDGET ptr;
  278. .br
  279. int    blank;
  280. .in 0
  281. .LP
  282. Deactivates the given active widget. The widget remains on screen but it cannot be activated. blank can be BLANK or NOBLANK which indicates whether the contents of the widget should be blanked out or not while it is inactive. The function returns TRUE if successful or FALSE if the given widget does not exist.
  283.  
  284. .LP
  285. .br
  286. .in 0.5i
  287. int highlight (ptr)
  288. .br
  289. WIDGET ptr;
  290. .in 0
  291. .LP
  292. Highlights the given widget. Returns TRUE if successful else FALSE if the widget does not exist.
  293.  
  294. .LP
  295. .br
  296. .in 0.5i
  297. int dehighlight (ptr)
  298. .br
  299. WIDGET ptr;
  300. .in 0
  301. .LP
  302. Turns off the highlighting of the given widget. Returns TRUE if successful else FALSE if the widget does not exist.
  303.  
  304. .LP
  305. .br
  306. .in 0.5i
  307. int changelblwidget (ptr, message, position)
  308. .br
  309. WIDGET ptr;
  310. .br
  311. char   message[];
  312. .br
  313. int    position;
  314. .in 0
  315. .LP
  316. Changes the contents of the given label widget to that given in message. position specifies how the message is to appear (see mklblwidget). The function returns TRUE if successful else FALSE.
  317. .KE
  318. .KS
  319. .LP
  320. .br
  321. .in 0.5i
  322. WIDGETTYPE widgettype (ptr)
  323. .br
  324. WIDGET ptr;
  325. .in 0
  326. .LP
  327. Returns the type of widget pointed too by ptr. The returned type value is one of CMD, LBL, TGL, INP or FALSE if the widget does not exist.
  328.  
  329. .SH
  330. Finishing Up
  331.  
  332. .LP
  333. .br
  334. .in 0.5i
  335. endwidgets ()
  336. .in 0
  337. .LP
  338. Closes down the windowing system and should be used at the end. This function is also automatically called on an interrupt (e.g ^C).
  339. .KE
  340.