1
0

control.h 4.7 KB

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