frame.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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/lib/frame"
  10. #pragma lib "libframe.a"
  11. typedef struct Frbox Frbox;
  12. typedef struct Frame Frame;
  13. enum{
  14. BACK,
  15. HIGH,
  16. BORD,
  17. TEXT,
  18. HTEXT,
  19. NCOL
  20. };
  21. #define FRTICKW 3
  22. struct Frbox
  23. {
  24. int32_t wid; /* in pixels */
  25. int32_t nrune; /* <0 ==> negate and treat as break char */
  26. union{
  27. uint8_t *ptr;
  28. struct{
  29. int16_t bc; /* break char */
  30. int16_t minwid;
  31. };
  32. };
  33. };
  34. struct Frame
  35. {
  36. Font *font; /* of chars in the frame */
  37. Display *display; /* on which frame appears */
  38. Image *b; /* on which frame appears */
  39. Image *cols[NCOL]; /* text and background colors */
  40. Rectangle r; /* in which text appears */
  41. Rectangle entire; /* of full frame */
  42. void (*scroll)(Frame*, int); /* scroll function provided by application */
  43. Frbox *box;
  44. uint32_t p0, p1; /* selection */
  45. uint16_t nbox, nalloc;
  46. uint16_t maxtab; /* max size of tab, in pixels */
  47. uint16_t nchars; /* # runes in frame */
  48. uint16_t nlines; /* # lines with text */
  49. uint16_t maxlines; /* total # lines in frame */
  50. uint16_t lastlinefull; /* last line fills frame */
  51. uint16_t modified; /* changed since frselect() */
  52. Image *tick; /* typing tick */
  53. Image *tickback; /* saved image under tick */
  54. int ticked; /* flag: is tick onscreen? */
  55. };
  56. uint32_t frcharofpt(Frame*, Point);
  57. Point frptofchar(Frame*, uint32_t);
  58. int frdelete(Frame*, uint32_t, uint32_t);
  59. void frinsert(Frame*, Rune*, Rune*, uint32_t);
  60. void frselect(Frame*, Mousectl*);
  61. void frselectpaint(Frame*, Point, Point, Image*);
  62. void frdrawsel(Frame*, Point, uint32_t, uint32_t, int);
  63. Point frdrawsel0(Frame*, Point, uint32_t, uint32_t, Image*, Image*);
  64. void frinit(Frame*, Rectangle, Font*, Image*, Image**);
  65. void frsetrects(Frame*, Rectangle, Image*);
  66. void frclear(Frame*, int);
  67. uint8_t *_frallocstr(Frame*, unsigned);
  68. void _frinsure(Frame*, int, unsigned);
  69. Point _frdraw(Frame*, Point);
  70. void _frgrowbox(Frame*, int);
  71. void _frfreebox(Frame*, int, int);
  72. void _frmergebox(Frame*, int);
  73. void _frdelbox(Frame*, int, int);
  74. void _frsplitbox(Frame*, int, int);
  75. int _frfindbox(Frame*, int, uint32_t, uint32_t);
  76. void _frclosebox(Frame*, int, int);
  77. int _frcanfit(Frame*, Point, Frbox*);
  78. void _frcklinewrap(Frame*, Point*, Frbox*);
  79. void _frcklinewrap0(Frame*, Point*, Frbox*);
  80. void _fradvance(Frame*, Point*, Frbox*);
  81. int _frnewwid(Frame*, Point, Frbox*);
  82. int _frnewwid0(Frame*, Point, Frbox*);
  83. void _frclean(Frame*, Point, int, int);
  84. void _frdrawtext(Frame*, Point, Image*, Image*);
  85. void _fraddbox(Frame*, int, int);
  86. Point _frptofcharptb(Frame*, uint32_t, Point, int);
  87. Point _frptofcharnb(Frame*, uint32_t, int);
  88. int _frstrlen(Frame*, int);
  89. void frtick(Frame*, Point, int);
  90. void frinittick(Frame*);
  91. void frredraw(Frame*);
  92. #define NRUNE(b) ((b)->nrune<0? 1 : (b)->nrune)
  93. #define NBYTE(b) strlen((char*)(b)->ptr)