integer.gadget in page layout

4 posts / 0 new
Last post
AND
AND's picture
Offline
Last seen: 6 years 10 months ago
Joined: 2011-01-20 12:22
integer.gadget in page layout

Hi,

I am trying to use an integer.gadget in an dynamical GUI-Layout. If I add the gadget to an emtpy window, everything works fine. But if I try to do the very same in a page-layout, the string-box of the IntegerObject is missing.
In both cases I add the gadget to a vertical LayoutObject. What is different, when adding a gadget to a page-layout?
Below is the code I use.

AND

  1. child = IntegerObject,
  2. GA_ID, id,
  3. GA_RelVerify, TRUE,
  4. GA_TabCycle, TRUE,
  5. INTEGER_MaxChars, 9,
  6. INTEGER_Number, *(ULONG*)ap[i].Variable,
  7. End;
  8. child = add_child(obj, child, 0, 0, lab);
  9.  
  10. ...
  11.  
  12. Object *add_child(Object *lay, Object *child, int w, int h, STRPTR label) {
  13. BOOL added = 0;
  14. struct TagItem attrs[] = {
  15. {CHILD_Label, 0},
  16. {CHILD_WeightedWidth, 0},
  17. {CHILD_WeightedHeight, 0},
  18. {TAG_DONE, 0}
  19. };
  20.  
  21. if(!child || !lay)
  22. return NULL;
  23.  
  24. if(label) attrs[0].ti_Data = (ULONG)pLabel(label); else attrs[0].ti_Tag = TAG_SKIP;
  25.  
  26. attrs[1].ti_Data = w;
  27. attrs[2].ti_Data = h;
  28. if(w == -1) attrs[1].ti_Tag = TAG_SKIP;
  29. if(h == -1) attrs[2].ti_Tag = TAG_SKIP;
  30.  
  31. struct lmAddChild msg;
  32. msg.MethodID = LM_ADDCHILD;
  33. msg.lm_Window = NULL;
  34. msg.lm_Object = child;
  35. msg.lm_ObjectAttrs = attrs;
  36.  
  37. added = IIntuition->IDoMethodA(lay, (void*)&msg);
  38.  
  39. return added ? child : NULL;
  40. }
Rigo
Rigo's picture
Offline
Last seen: 1 year 10 months ago
Joined: 2011-01-24 21:55
If you could supply a fully

If you could supply a fully working example (or the code for it), that may help in tracking down what is happening here.

Simon

AND
AND's picture
Offline
Last seen: 6 years 10 months ago
Joined: 2011-01-20 12:22
Well, I guess there is

Well, I guess there is something wrong with the setup of the page-gadget/clicktab-gadget.
OBJ_INTEGER_1 is crippled, whereas OBJ_INTEGER_2 works just fine.

So, here is a fully working example:

  1. /*
  2. gcc -o IntegerTest IntegerTest.c -lauto
  3. quit
  4. */
  5.  
  6. #include <exec/exec.h>
  7. #include <intuition/intuition.h>
  8. #include <dos/dos.h>
  9. #include <images/label.h>
  10.  
  11. #include <classes/window.h>
  12.  
  13. #include <gadgets/layout.h>
  14. #include <gadgets/integer.h>
  15. #include <gadgets/clicktab.h>
  16.  
  17. #include <proto/exec.h>
  18. #include <proto/intuition.h>
  19.  
  20. #include <proto/window.h>
  21. #include <proto/layout.h>
  22. #include <proto/integer.h>
  23. #include <proto/label.h>
  24. #include <proto/clicktab.h>
  25.  
  26. #include <reaction/reaction_macros.h>
  27.  
  28.  
  29. static Object *win;
  30.  
  31. static struct MsgPort *AppPort;
  32. static struct List *CTLabels = NULL;
  33.  
  34. enum
  35. {
  36. OBJ_INTEGER_1,
  37. OBJ_INTEGER_2,
  38. OBJ_PAGE,
  39. OBJ_CLICKTAB,
  40. OBJ_NUM
  41. };
  42.  
  43. static Object *Objects[OBJ_NUM];
  44. #define OBJ(x) Objects[x]
  45. #define GAD(x) (struct Gadget *)Objects[x]
  46.  
  47. #define pLabel(txt) IIntuition->NewObject(ILabel->LABEL_GetClass(), NULL, \
  48.   LABEL_Text, txt, LABEL_Underscore, 13, TAG_DONE)
  49.  
  50.  
  51.  
  52. static Object *lay;
  53.  
  54. static void set_clicktab_labels(struct List *lab) {
  55. CTLabels = lab;
  56. }
  57.  
  58. static Object *add_child(Object *lay, Object *child, int w, int h, STRPTR label) {
  59. BOOL added = 0;
  60. struct TagItem attrs[] = {
  61. {CHILD_Label, 0},
  62. {CHILD_WeightedWidth, 0},
  63. {CHILD_WeightedHeight, 0},
  64. {TAG_DONE, 0}
  65. };
  66.  
  67. if(!child || !lay)
  68. return NULL;
  69.  
  70. if(label) attrs[0].ti_Data = (ULONG)pLabel(label); else attrs[0].ti_Tag = TAG_SKIP;
  71. // if(label) add_image(lay, pLabel(label));
  72.  
  73. attrs[1].ti_Data = w;
  74. attrs[2].ti_Data = h;
  75. if(w == -1) attrs[1].ti_Tag = TAG_SKIP;
  76. if(h == -1) attrs[2].ti_Tag = TAG_SKIP;
  77.  
  78. struct lmAddChild msg;
  79. msg.MethodID = LM_ADDCHILD;
  80. msg.lm_Window = NULL;
  81. msg.lm_Object = child;
  82. msg.lm_ObjectAttrs = attrs;
  83.  
  84. added = IIntuition->IDoMethodA(lay, (void*)&msg);
  85.  
  86. return added ? child : NULL;
  87. }
  88.  
  89. static Object *add_vert(Object *lay, CONST_STRPTR group) {
  90. Object *gad;
  91.  
  92. gad = IIntuition->NewObject(NULL, "layout.gadget",
  93. LAYOUT_Orientation, LAYOUT_ORIENT_VERT,
  94. LAYOUT_Parent, lay,
  95. group ? LAYOUT_BevelStyle : TAG_IGNORE, BVS_GROUP,
  96. group ? LAYOUT_Label : TAG_IGNORE, group,
  97. TAG_DONE);
  98. return add_child(lay, gad, 0, 1, NULL);
  99. }
  100.  
  101. static struct Node *append_page(Object *pgroup, CONST_STRPTR label, CONST_STRPTR group) {
  102. struct Node *tab_node;
  103. Object *page;
  104.  
  105. page = IIntuition->NewObject(NULL, "layout.gadget",
  106. LAYOUT_Orientation, LAYOUT_ORIENT_VERT,
  107. group ? LAYOUT_BevelStyle : TAG_IGNORE, BVS_GROUP,
  108. group ? LAYOUT_Label : TAG_IGNORE, group,
  109. TAG_DONE);
  110.  
  111. if(page != NULL)
  112. IIntuition->SetAttrs(pgroup, PAGE_Add, page, TAG_DONE);
  113.  
  114. tab_node = IClickTab->AllocClickTabNode(TNA_Text, label,
  115. TNA_UserData, page,
  116. TAG_DONE);
  117.  
  118. if(tab_node != NULL)
  119. IExec->AddTail(CTLabels, tab_node);
  120.  
  121. return tab_node;
  122. }
  123.  
  124. static Object *make_window(void) {
  125. struct List clicki;
  126. Object *window, *vlayout;
  127.  
  128. IExec->NewList(&clicki);
  129. set_clicktab_labels(&clicki);
  130.  
  131. window = WindowObject,
  132. WA_ScreenTitle, "ReAction Example",
  133. WA_Title, "Integer Example",
  134. WA_DragBar, TRUE,
  135. WA_CloseGadget, TRUE,
  136. WA_SizeGadget, TRUE,
  137. WA_DepthGadget, TRUE,
  138. WA_Activate, TRUE,
  139. WINDOW_IconifyGadget, TRUE,
  140. WINDOW_IconTitle, "Iconified",
  141. WINDOW_AppPort, AppPort,
  142. WINDOW_Position, WPOS_CENTERSCREEN,
  143. WINDOW_Layout, VLayoutObject,
  144. LAYOUT_SpaceOuter, TRUE,
  145. LAYOUT_AddChild, vlayout = VLayoutObject,
  146. LAYOUT_SpaceOuter, TRUE,
  147.  
  148. LAYOUT_AddChild, OBJ(OBJ_CLICKTAB) = IIntuition->NewObject(NULL, "clicktab.gadget",
  149. GA_ID, OBJ_CLICKTAB,
  150. GA_RelVerify, TRUE,
  151. // The list of tabs; we add this later.
  152. CLICKTAB_Labels, NULL,
  153. // Override the system settings and force each tab to be even size.
  154. CLICKTAB_EvenSize, FALSE,
  155. // Allow tabs to be truncated, adding tabs requires more room.
  156. CLICKTAB_LabelTruncate, TRUE,
  157. // Automatically fit dynamic tabs within our rendering bounds.
  158. CLICKTAB_AutoFit, TRUE,
  159. // Add a page.gadget for flipping between pages.
  160. CLICKTAB_PageGroup, OBJ(OBJ_PAGE) = IIntuition->NewObject(NULL, "page.gadget", TAG_DONE),
  161. // Automatically number tabs for the page group page.gadget.
  162. CLICKTAB_AutoTabNumbering, TRUE,
  163. TAG_DONE),
  164.  
  165. End, // HLayout
  166.  
  167. End, // VLayout
  168. End; // WindowObject
  169.  
  170. if(window) {
  171. struct Node *node = append_page(OBJ(OBJ_PAGE), "Tescht", NULL);
  172. Object *page;
  173.  
  174. IClickTab->GetClickTabNodeAttrs(node, TNA_UserData, &page, TAG_DONE);
  175.  
  176. // Add Layout-Object to Page-Group
  177. lay = add_vert(page, " (Connected) Integers ");
  178.  
  179. // Now create Integer-Gadget inside Page-Group
  180. OBJ(OBJ_INTEGER_1) = IntegerObject,
  181. GA_ID, OBJ_INTEGER_1,
  182. GA_RelVerify, TRUE,
  183. GA_TabCycle, TRUE,
  184. INTEGER_Arrows, TRUE,
  185. INTEGER_MaxChars, 3,
  186. INTEGER_Minimum, 0,
  187. INTEGER_Maximum, 100,
  188. INTEGER_Number, 35,
  189. INTEGER_SkipVal, 5,
  190. End;
  191.  
  192. add_child(lay, OBJ(OBJ_INTEGER_1), 0, 0, " Integer 1 ");
  193.  
  194. // Add an integer.gadget inside main window
  195. OBJ(OBJ_INTEGER_2) = IntegerObject,
  196. GA_ID, OBJ_INTEGER_2,
  197. GA_RelVerify, TRUE,
  198. GA_TabCycle, TRUE,
  199. INTEGER_Arrows, TRUE,
  200. INTEGER_MaxChars, 3,
  201. INTEGER_Minimum, 0,
  202. INTEGER_Maximum, 100,
  203. INTEGER_Number, 50,
  204. End;
  205.  
  206. add_child(vlayout, OBJ(OBJ_INTEGER_2), 0, 0, " Integer 2 ");
  207.  
  208. IIntuition->SetAttrs(OBJ(OBJ_CLICKTAB),
  209. CLICKTAB_Labels, &clicki,
  210. CLICKTAB_Current, 0,
  211. TAG_DONE);
  212. }
  213.  
  214. return window;
  215. }
  216.  
  217.  
  218. int main(void) {
  219. struct Window *window;
  220.  
  221. if(AppPort = IExec->CreateMsgPort()) {
  222. win = make_window();
  223. if(window = RA_OpenWindow(win)) {
  224. uint32
  225. sigmask = 0,
  226. siggot = 0,
  227. result = 0;
  228. uint16
  229. code = 0;
  230. BOOL
  231. done = FALSE;
  232.  
  233. IIntuition->GetAttr(WINDOW_SigMask, win, &sigmask);
  234. while(!done) {
  235. siggot = IExec->Wait(sigmask | SIGBREAKF_CTRL_C);
  236. if(siggot & SIGBREAKF_CTRL_C) done = TRUE;
  237. while((result = RA_HandleInput(win, &code))) {
  238. switch(result & WMHI_CLASSMASK) {
  239. case WMHI_CLOSEWINDOW:
  240. done = TRUE;
  241. break;
  242. case WMHI_GADGETUP:
  243. break;
  244. case WMHI_ICONIFY:
  245. if (RA_Iconify(win)) window = NULL;
  246. break;
  247. case WMHI_UNICONIFY:
  248. window = RA_OpenWindow(win);
  249. break;
  250. }
  251. }
  252. }
  253. }
  254. IIntuition->DisposeObject(win);
  255. IExec->DeleteMsgPort(AppPort);
  256. }
  257.  
  258. return 0;
  259. }
Rigo
Rigo's picture
Offline
Last seen: 1 year 10 months ago
Joined: 2011-01-24 21:55
Thanks for the example. There

Thanks for the example. There is definitely something wrong here, because Intuition has recognised a problem before the integer.gadget in the page layout is fully drawn. This is shown by trying to resize the window, and the complete machine lock that results.

I'm investigating....

Simon

Log in or register to post comments