talk2boopsi.pas 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. PROGRAM Talk2Boopsi;
  2. { This example creates a Boopsi prop gadget and integer string gadget, connecting them so they }
  3. { update each other when the user changes their value. The example program only initializes }
  4. { the gadgets and puts them on the window; it doesn't have to interact with them to make them }
  5. { talk to each other. }
  6. uses Exec, Intuition, Utility;
  7. {$I tagutils.inc}
  8. VAR
  9. w : pWindow;
  10. mymsg : pIntuiMessage;
  11. prop,
  12. int : pGadget;
  13. done : BOOLEAN;
  14. dummy : Word;
  15. temp : Longint;
  16. thetags : array[0..11] of tTagItem;
  17. prop2intmap : array[0..1] of tTagItem;
  18. int2propmap : array[0..1] of tTagItem;
  19. CONST
  20. vers : PChar = '$VER: Talk2boopsi 37.1';
  21. PROPGADGET_ID = 1;
  22. INTGADGET_ID = 2;
  23. PROPGADGETWIDTH = 10;
  24. PROPGADGETHEIGHT = 80;
  25. INTGADGETHEIGHT = 18;
  26. VISIBLE = 10;
  27. TOTAL = 100;
  28. INITIALVAL = 25;
  29. MINWINDOWWIDTH = 80;
  30. MINWINDOWHEIGHT = (PROPGADGETHEIGHT + 70);
  31. MAXCHARS = 3;
  32. PROCEDURE CleanUp(Why : STRING; err: Word);
  33. BEGIN
  34. IF prop <> NIL THEN DisposeObject(prop);
  35. IF int <> NIL THEN DisposeObject(int);
  36. IF w <> NIL THEN CloseWindow(w);
  37. IF Why <> '' THEN WriteLN(Why);
  38. Halt(err);
  39. END;
  40. BEGIN
  41. done := FALSE;
  42. prop2intmap[0] := TagItem(PGA_Top, STRINGA_LongVal);
  43. prop2intmap[1].ti_Tag := TAG_END;
  44. int2propmap[0] := TagItem(STRINGA_LongVal, PGA_Top);
  45. int2propmap[1].ti_Tag := TAG_END;
  46. thetags[0] := TagItem(WA_Flags, WFLG_DEPTHGADGET + WFLG_DRAGBAR +
  47. WFLG_CLOSEGADGET + WFLG_SIZEGADGET + WFLG_ACTIVATE);
  48. thetags[1] := TagItem(WA_IDCMP, IDCMP_CLOSEWINDOW);
  49. thetags[2] := TagItem(WA_Width, MINWINDOWWIDTH + 10);
  50. thetags[3] := TagItem(WA_Height, MINWINDOWHEIGHT + 10);
  51. thetags[4] := TagItem(WA_MinWidth, MINWINDOWWIDTH);
  52. thetags[5] := TagItem(WA_MinHeight, MINWINDOWHEIGHT);
  53. thetags[6].ti_Tag := TAG_END;
  54. w := OpenWindowTagList(NIL,@thetags);
  55. IF w=NIL THEN CleanUp('No window',20);
  56. thetags[0] := TagItem(GA_ID, PROPGADGET_ID);
  57. thetags[1] := TagItem(GA_Top, (w^.BorderTop) + 5);
  58. thetags[2] := TagItem(GA_Left, (w^.BorderLeft) + 5);
  59. thetags[3] := TagItem(GA_Width, PROPGADGETWIDTH);
  60. thetags[4] := TagItem(GA_Height, PROPGADGETHEIGHT);
  61. thetags[5] := TagItem(ICA_MAP, Longint(@prop2intmap));
  62. thetags[6] := TagItem(PGA_Total, TOTAL);
  63. thetags[7] := TagItem(PGA_Top, INITIALVAL);
  64. thetags[8] := TagItem(PGA_Visible, VISIBLE);
  65. thetags[9] := TagItem(PGA_NewLook, 1); { true }
  66. thetags[10].ti_Tag := TAG_END;
  67. prop := NewObjectA(NIL, PChar('propgclass'#0),@thetags);
  68. IF prop = NIL THEN CleanUp('No propgadget',20);
  69. thetags[0] := TagItem(GA_ID, INTGADGET_ID);
  70. thetags[2] := TagItem(GA_Top, (w^.BorderTop) + 5);
  71. thetags[3] := TagItem(GA_Left, (w^.BorderLeft) + PROPGADGETWIDTH + 10);
  72. thetags[4] := TagItem(GA_Width, MINWINDOWWIDTH -
  73. (w^.BorderLeft + w^.BorderRight +
  74. PROPGADGETWIDTH + 15));
  75. thetags[5] := TagItem(GA_Height, INTGADGETHEIGHT);
  76. thetags[6] := TagItem(ICA_MAP, Longint(@int2propmap));
  77. thetags[7] := TagItem(ICA_TARGET, Longint(prop));
  78. thetags[8] := TagItem(GA_Previous, Longint(prop));
  79. thetags[9] := TagItem(STRINGA_LongVal, INITIALVAL);
  80. thetags[10] := TagItem(STRINGA_MaxChars, MAXCHARS);
  81. thetags[11].ti_Tag := TAG_END;
  82. int := NewObjectA(NIL, PChar('strgclass'#0),@thetags);
  83. thetags[0] := TagItem(ICA_TARGET, Longint(int));
  84. thetags[1].ti_Tag := TAG_END;
  85. temp := SetGadgetAttrsA(prop, w, NIL,@thetags);
  86. IF int = NIL THEN CleanUp('No INTEGER gadget',20);
  87. dummy := AddGList(w, prop, -1, -1, NIL);
  88. RefreshGList(prop, w, NIL, -1);
  89. WHILE (NOT done) DO BEGIN
  90. mymsg := pIntuiMessage(WaitPort(W^.UserPort));
  91. mymsg := pIntuiMessage(GetMsg(W^.UserPort));
  92. IF mymsg^.IClass = IDCMP_CLOSEWINDOW THEN done := True;
  93. ReplyMsg(pMessage(mymsg));
  94. END;
  95. dummy := RemoveGList(w, prop, -1);
  96. CleanUp('',0);
  97. END.