control.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. /*
  2. * This file is part of the UCB release of Plan 9. It is subject to the license
  3. * terms in the LICENSE file found in the top-level directory of this
  4. * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
  5. * part of the UCB release of Plan 9, including this file, may be copied,
  6. * modified, propagated, or distributed except according to the terms contained
  7. * in the LICENSE file.
  8. */
  9. #pragma src "/sys/src/libcontrol"
  10. #pragma lib "libcontrol.a"
  11. #pragma varargck argpos ctlprint 2
  12. #pragma varargck argpos _ctlprint 2
  13. typedef struct Control Control;
  14. typedef struct Controlset Controlset;
  15. typedef struct CParse CParse;
  16. typedef struct CCache CCache;
  17. typedef struct CCache CImage;
  18. typedef struct CCache CFont;
  19. enum /* types */
  20. {
  21. Ctlunknown,
  22. Ctlbox,
  23. Ctlbutton,
  24. Ctlentry,
  25. Ctlkeyboard,
  26. Ctllabel,
  27. Ctlmenu,
  28. Ctlradio,
  29. Ctlscribble,
  30. Ctlslider,
  31. Ctltabs,
  32. Ctltext,
  33. Ctltextbutton,
  34. Ctltextbutton3,
  35. Ctlgroup, /* divider between controls and metacontrols */
  36. Ctlboxbox,
  37. Ctlcolumn,
  38. Ctlrow,
  39. Ctlstack,
  40. Ctltab,
  41. Ntypes,
  42. };
  43. struct Controlset
  44. {
  45. Control *controls;
  46. Image *screen;
  47. Control *actives;
  48. Control *focus;
  49. Channel *ctl;
  50. Channel *data; /* currently only for sync */
  51. Channel *kbdc;
  52. Channel *mousec;
  53. Channel *resizec;
  54. Channel *resizeexitc;
  55. Channel *csexitc;
  56. Keyboardctl *keyboardctl; /* will be nil if user supplied keyboard */
  57. Mousectl *mousectl; /* will be nil if user supplied mouse */
  58. int clicktotype; /* flag */
  59. };
  60. struct Control
  61. {
  62. /* known to client */
  63. char *name;
  64. Rectangle rect;
  65. Rectangle size; /* minimum/maximum Dx, Dy (not a rect) */
  66. Channel *event; /* chan(char*) to client */
  67. Channel *data; /* chan(char*) to client */
  68. /* internal to control set */
  69. int type;
  70. int hidden; /* hide hides, show unhides (and redraws) */
  71. Controlset *controlset;
  72. Image *screen; /* where Control appears */
  73. char *format; /* used to generate events */
  74. char wevent; /* event channel rewired */
  75. char wdata; /* data channel rewired */
  76. /* method table */
  77. void (*ctl)(Control*, CParse*);
  78. void (*mouse)(Control*, Mouse*);
  79. void (*key)(Control*, Rune*);
  80. void (*exit)(Control*);
  81. void (*setsize)(Control*);
  82. void (*activate)(Control*, int);
  83. Control *nextactive;
  84. Control *next;
  85. };
  86. struct CCache
  87. {
  88. union{
  89. Image *image;
  90. Font *font;
  91. };
  92. char *name;
  93. int index; /* entry number in cache */
  94. int ref; /* one for client, plus one for each use */
  95. };
  96. struct CParse
  97. {
  98. char str[256];
  99. char *sender;
  100. char *receiver;
  101. int cmd;
  102. char *pargs[32];
  103. int iargs[32];
  104. char **args;
  105. int nargs;
  106. };
  107. enum /* alignments */
  108. {
  109. Aupperleft = 0,
  110. Auppercenter,
  111. Aupperright,
  112. Acenterleft,
  113. Acenter,
  114. Acenterright,
  115. Alowerleft,
  116. Alowercenter,
  117. Alowerright,
  118. Nalignments
  119. };
  120. enum
  121. {
  122. _Ctlmaxsize = 10000,
  123. };
  124. extern char *ctltypenames[];
  125. /* Functions used internally */
  126. void _ctladdgroup(Control*, Control*);
  127. void _ctlargcount(Control*, CParse*, int);
  128. Control* _createctl(Controlset*, char*, uint, char*);
  129. Rune* _ctlrunestr(char*);
  130. char* _ctlstrrune(Rune*);
  131. void _ctlputsnarf(Rune*);
  132. Rune* _ctlgetsnarf(void);
  133. int _ctlalignment(char*);
  134. Point _ctlalignpoint(Rectangle, int, int, int);
  135. void _ctlfocus(Control*, int);
  136. void _activategroup(Control*);
  137. void _deactivategroup(Control*);
  138. int _ctllookup(char *s, char *tab[], int ntab);
  139. void _ctlprint(Control *c, char *fmt, ...);
  140. /* images */
  141. CImage* _getctlimage(char*);
  142. void _setctlimage(Control*, CImage**, char*);
  143. void _putctlimage(CImage*);
  144. CFont* _getctlfont(char*);
  145. void _putctlfont(CFont*);
  146. /* fonts */
  147. CImage* _getctlfont(char*);
  148. void _setctlfont(Control*, CImage**, char*);
  149. void _putctlfont(CImage*);
  150. CFont* _getctlfont(char*);
  151. void _putctlfont(CFont*);
  152. /* Public functions */
  153. /* images */
  154. int namectlimage(Image*, char*);
  155. int freectlimage(char*);
  156. /* fonts */
  157. int namectlfont(Font*, char*);
  158. int freectlfont(char*);
  159. /* commands */
  160. int ctlprint(Control*, char*, ...);
  161. /* general */
  162. void initcontrols(void);
  163. Controlset* newcontrolset(Image*, Channel*, Channel*, Channel*);
  164. void closecontrolset(Controlset*);
  165. void closecontrol(Control*);
  166. void ctlerror(char*, ...);
  167. Control* controlcalled(char*);
  168. /* publicly visible error-checking allocation routines */
  169. void* ctlmalloc(uint);
  170. void* ctlrealloc(void*, uint);
  171. char* ctlstrdup(char*);
  172. /* creation */
  173. void controlwire(Control*, char*, Channel*);
  174. void activate(Control*);
  175. void deactivate(Control*);
  176. Control* createbox(Controlset*, char*);
  177. Control* createbutton(Controlset*, char*);
  178. Control* createcolumn(Controlset*, char*);
  179. Control* createboxbox(Controlset*, char*);
  180. Control* createentry(Controlset*, char*);
  181. Control* createkeyboard(Controlset*, char*);
  182. Control* createlabel(Controlset*, char*);
  183. Control* createmenu(Controlset*, char*);
  184. Control* createradiobutton(Controlset*, char*);
  185. Control* createrow(Controlset*, char*);
  186. Control* createscribble(Controlset*, char*);
  187. Control* createslider(Controlset*, char*);
  188. Control* createstack(Controlset*, char*);
  189. Control* createtab(Controlset*, char*);
  190. Control* createtext(Controlset*, char*);
  191. Control* createtextbutton(Controlset*, char*);
  192. Control* createtextbutton3(Controlset*, char*);
  193. /* user-supplied */
  194. void resizecontrolset(Controlset*);
  195. int _ctlsnarffd;
  196. char *alignnames[];
  197. int ctldeletequits;