iconbox.c 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. iconbox(Prefab_Environ *e, Draw_Point p, String *titletext, Draw_Image *icon, Draw_Image *mask)
  10. {
  11. Draw_Rect er, r, ir;
  12. PCompound *pc;
  13. Prefab_Compound *c;
  14. PElement *elem, *title;
  15. Image *disp;
  16. Draw_Image *ddisp;
  17. Screen *screen;
  18. Heap *h;
  19. Rectangle t;
  20. Point pt;
  21. screen = lookupscreen(e->screen);
  22. if(screen == nil)
  23. return H;
  24. h = heapz(TCompound);
  25. if(h == H)
  26. return H;
  27. pc = H2D(PCompound*, h);
  28. c = &pc->c;
  29. gchalt++;
  30. title = H;
  31. if(titletext != H){
  32. er.min.x = 0;
  33. er.min.y = 0;
  34. er.max.x = Dx(icon->r)-5;
  35. er.max.y = 0;
  36. title = textelement(e, titletext, er, ETitle);
  37. if(title == H){
  38. Err:
  39. destroy(c);
  40. gchalt--;
  41. return H;
  42. }
  43. c->title = (Prefab_Element*)title;
  44. }
  45. r = icon->r;
  46. if(title != H)
  47. r.max.y += 2+1+title->nkids*e->style->titlefont->height+1;
  48. er = edgerect(e, p, &r);
  49. R2R(t, er);
  50. disp = allocwindow(screen, t, Refbackup /*refreshcompound*/, DWhite);
  51. if(disp == nil)
  52. goto Err;
  53. if((ddisp=mkdrawimage(disp, e->screen, e->screen->display, nil)) == H){
  54. freeimage(disp);
  55. goto Err;
  56. }
  57. ir = r;
  58. if(title != H){
  59. ir = r;
  60. pt.x = r.min.x+3;
  61. pt.y = r.min.y+3;
  62. translateelement(&title->e, pt);
  63. ir.min.y = title->e.r.max.y+1;
  64. }
  65. elem = iconelement(e, ir, icon, mask);
  66. c->r = r;
  67. c->image = ddisp;
  68. c->environ = e;
  69. D2H(e)->ref++;
  70. c->contents = (Prefab_Element*)elem;
  71. pc->display = screen->display;
  72. gchalt--;
  73. return pc;
  74. }