control.h 5.0 KB

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