2
0

talk2boopsi.pas 3.6 KB

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