1
0

control.h 4.7 KB

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