box.c 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #include <lib9.h>
  2. #include <draw.h>
  3. #include <interp.h>
  4. #include <isa.h>
  5. #include "../libinterp/runt.h"
  6. #include <drawif.h>
  7. #include <prefab.h>
  8. PCompound*
  9. box(Prefab_Environ *e, Draw_Point p, Prefab_Element *title, Prefab_Element *list)
  10. {
  11. Draw_Rect er, r, lr;
  12. PCompound *pc;
  13. Prefab_Compound *c;
  14. Image *disp;
  15. Draw_Image *ddisp;
  16. Screen *screen;
  17. Heap *h;
  18. Point pt;
  19. int w;
  20. if(list == H)
  21. return H;
  22. screen = lookupscreen(e->screen);
  23. if(screen == nil)
  24. return H;
  25. h = heapz(TCompound);
  26. if(h == H)
  27. return H;
  28. pc = H2D(PCompound*, h);
  29. c = &pc->c;
  30. gchalt++;
  31. r = list->r;
  32. if(title != H){
  33. w = 2+1+3+Dx(title->r)+1;
  34. if(w > Dx(r))
  35. r.max.x = r.min.x + w;
  36. r.max.y += 2+1+Dy(title->r)+1;
  37. }
  38. er = edgerect(e, p, &r);
  39. disp = allocwindow(screen, IRECT(er), Refbackup /*refreshcompound*/, DWhite);
  40. if(disp == nil){
  41. Err:
  42. destroy(c);
  43. gchalt--;
  44. return H;
  45. }
  46. if((ddisp=mkdrawimage(disp, e->screen, e->screen->display, nil)) == H){
  47. freeimage(disp);
  48. goto Err;
  49. }
  50. lr = r;
  51. if(title != H){
  52. pt.x = r.min.x+3;
  53. pt.y = r.min.y+3;
  54. translateelement(title, pt);
  55. lr.min.y = title->r.max.y+1;
  56. }
  57. translateelement(list, subpt(IPOINT(lr.min), IPOINT(list->r.min)));
  58. c->r = r;
  59. c->image = ddisp;
  60. c->environ = e;
  61. D2H(e)->ref++;
  62. if(title != H){
  63. c->title = title;
  64. D2H(title)->ref++;
  65. }
  66. if(list != H){
  67. c->contents = (Prefab_Element*)list;
  68. D2H(list)->ref++;
  69. }
  70. pc->display = screen->display;
  71. gchalt--;
  72. return pc;
  73. }