How is it working?

10 posts / 0 new
Last post
walkero
walkero's picture
Offline
Last seen: 5 days 12 hours ago
Joined: 2009-05-03 16:54
How is it working?

Can someone please explain to me how the changing of a layout content works when you have a list browser with selections?

This is something that is done on both GUI and Internet prefs. At the left side there is a listbrowser with options and at the right side the content changes depending the selected option from the left side.

What is the idea behind this? Does it detach a whole layout and attach an other at the right side? Do I understand it right?

dbstastny
dbstastny's picture
Offline
Last seen: 2 months 4 weeks ago
Joined: 2017-02-04 00:01
Re: How is it working?

I am not sure I totally understand your question. So I will try to go by assumption of a layout set with a horizontal divide. So the selection list is on left and based upon what you select it shows a component or child layouts on the right.

To do that you basically create your layout put the listbox on the first child and add all the others you want to the child on right and toggle visibility of the component/layout based upon the selection in the listbox. You might need to call Rethink and it will update the displayed layout. Now if you do something really heavy you may destroy the child and create new component/layout and add it back into the layout but for most part you can just pull it off with visibility.

Is this what your asking?

DStastny
dbstastny
dbstastny's picture
Offline
Last seen: 2 months 4 weeks ago
Joined: 2017-02-04 00:01
Re: How is it working?

I need to read better. And look at examples you sited. I looked at some old code and remembered there is no easy way to just make a element visible or not by toggling attribute. There is GA_Hidden but I have never been able to figure out what it does. I will post example for you though. That works by adding and removing children from layout on the fly. It works but I am embarrassed to post it cause cause its a cobbled mess of cut-paste. Ill put it up hopefully later tonight.

Regards

DStastny
thomas
thomas's picture
Offline
Last seen: 12 hours 2 min ago
Joined: 2011-05-16 14:23
Re: How is it working?

Does it detach a whole layout and attach an other at the right side?

This is one method. Use this if you really have highly dynamic contents.

The better, but more static, way probably is to use a page gadget on the right and define all layouts as pages. Similar to the clicktab/page combination you can use a listbrowser/page combination. The difference is that the listbrowser does not have its own support for pages. You'll have to use ICA_TARGET and ICA_MAP attributes to let the listbrowser switch pages automatically.

dbstastny
dbstastny's picture
Offline
Last seen: 2 months 4 weeks ago
Joined: 2017-02-04 00:01
Re: How is it working?

As promised a example of switching using a simple button but that could be layouts to swap. This example flags the buttons to not dispose on remove so they only get created once but if its real dynamic you could just destroy and reattach.

As Thomas said you can use page.gadget as well.

  1. /* Execute me to compile
  2.   gcc -o demo demo.c -lauto
  3. */
  4.  
  5. #include <exec/exec.h>
  6. #include <intuition/intuition.h>
  7. #include <intuition/gui.h>
  8. #include <dos/dos.h>
  9. #include <images/label.h>
  10. #include <classes/window.h>
  11. #include <gadgets/layout.h>
  12. #include <gadgets/listbrowser.h>
  13. #include <libraries/keymap.h>
  14.  
  15. #include <proto/exec.h>
  16. #include <proto/dos.h>
  17. #include <proto/intuition.h>
  18. #include <proto/window.h>
  19. #include <proto/layout.h>
  20. #include <proto/label.h>
  21. #include <proto/listbrowser.h>
  22.  
  23. struct ViewNode
  24. {
  25. struct Node Node;
  26. APTR Data;
  27. };
  28.  
  29. struct List listbrowser_list;
  30.  
  31.  
  32. enum
  33. {
  34. OBJ_WINDOW,
  35. OBJ_LISTBROWSER,
  36. OBJ_QUIT,
  37. OBJ_VIEW,
  38. OBJ_BUTTON1,
  39. OBJ_BUTTON2,
  40. OBJ_BUTTON3,
  41. OBJ_LAST
  42. };
  43.  
  44. Object *Objects[OBJ_LAST];
  45.  
  46.  
  47. STRPTR list_strings[] =
  48. {
  49. "View Button 1",
  50. "View Button 2",
  51. "View Button 3",
  52. NULL
  53. };
  54.  
  55. STRPTR button_strings[] =
  56. {
  57. "Button 1",
  58. "Button 2",
  59. "Button 3",
  60. NULL
  61. };
  62.  
  63.  
  64. BOOL filllist(struct List *, STRPTR*);
  65. void freelist(struct List *list);
  66.  
  67. Object * make_window(struct MsgPort *appPort)
  68. {
  69.  
  70. return IIntuition->NewObject(NULL, "window.class",
  71. WA_ScreenTitle, "Demo",
  72. WA_Title, "Layout Views",
  73. WA_DragBar, TRUE,
  74. WA_CloseGadget, TRUE,
  75. WA_SizeGadget, TRUE,
  76. WA_DepthGadget, TRUE,
  77. WA_Activate, TRUE,
  78. WA_InnerWidth, 260,
  79. WA_InnerHeight, 300,
  80. WINDOW_IconifyGadget, TRUE,
  81. WINDOW_IconTitle, "Iconified",
  82. WINDOW_AppPort, appPort,
  83. WINDOW_Position, WPOS_CENTERSCREEN,
  84. WINDOW_Layout, IIntuition->NewObject(NULL, "layout.gadget",
  85. LAYOUT_Orientation, LAYOUT_ORIENT_VERT,
  86. LAYOUT_SpaceOuter, TRUE,
  87. LAYOUT_AddChild, IIntuition->NewObject(NULL, "layout.gadget",
  88. LAYOUT_Orientation, LAYOUT_ORIENT_VERT,
  89. LAYOUT_SpaceOuter, TRUE,
  90. LAYOUT_BevelStyle, BVS_GROUP,
  91. LAYOUT_Label, "Select Button View",
  92. LAYOUT_AddChild, Objects[OBJ_VIEW]= IIntuition->NewObject(NULL, "layout.gadget",
  93. LAYOUT_Orientation, LAYOUT_ORIENT_HORIZ,
  94. LAYOUT_SpaceOuter, TRUE,
  95. LAYOUT_AddChild, Objects[OBJ_LISTBROWSER] = IIntuition->NewObject(NULL, "listbrowser.gadget",
  96. GA_ID, OBJ_LISTBROWSER,
  97. GA_RelVerify, TRUE,
  98. GA_TabCycle, TRUE,
  99. LISTBROWSER_AutoFit, TRUE,
  100. LISTBROWSER_Labels, &listbrowser_list,
  101. LISTBROWSER_ShowSelected, TRUE,
  102.  
  103. TAG_DONE),
  104. TAG_DONE),
  105. LAYOUT_AddChild, Objects[OBJ_QUIT] = IIntuition->NewObject(NULL, "button.gadget",
  106. GA_Text, "_Quit",
  107. GA_ID, OBJ_QUIT,
  108. GA_RelVerify, TRUE,
  109. GA_TabCycle, TRUE,
  110. TAG_DONE),
  111. CHILD_WeightedHeight, 0,
  112.  
  113. TAG_DONE),
  114. TAG_END),
  115. TAG_DONE);
  116. }
  117.  
  118. struct ViewNode* activateview(struct Window *window, struct ViewNode* currentView, struct ViewNode* newView)
  119. {
  120. if (NULL != currentView)
  121. {
  122. IIntuition->IDoMethod(Objects[OBJ_VIEW], LM_REMOVECHILD, window, currentView->Data, TAG_DONE);
  123. }
  124. if (NULL!= newView)
  125. {
  126. struct TagItem tagitem[2];
  127. tagitem[0].ti_Tag = CHILD_NoDispose;
  128. tagitem[0].ti_Data = TRUE;
  129. tagitem[1].ti_Tag = TAG_END;
  130. IIntuition->IDoMethod(Objects[OBJ_VIEW], LM_ADDCHILD, window, newView->Data, tagitem, TAG_END);
  131. }
  132. IIntuition->IDoMethod(Objects[OBJ_WINDOW], WM_RETHINK);
  133. return newView;
  134. }
  135.  
  136. int main()
  137. {
  138.  
  139. struct MsgPort *appPort;
  140. struct Window *window;
  141.  
  142. struct ViewNode* activeView=NULL;
  143.  
  144. if (appPort = (struct MsgPort*)IExec->AllocSysObject(ASOT_PORT, TAG_DONE))
  145. {
  146. if (filllist(&listbrowser_list, list_strings))
  147. {
  148. Objects[OBJ_WINDOW] = make_window(appPort);
  149.  
  150.  
  151. if (window = (struct Window*)IIntuition->IDoMethod(Objects[OBJ_WINDOW], WM_OPEN))
  152. {
  153. IIntuition->SetAttrs(Objects[OBJ_LISTBROWSER] , LISTBROWSER_Selected,0, TAG_END);
  154. activeView=activateview(window, NULL, (struct ViewNode*)listbrowser_list.lh_Head);
  155.  
  156. BOOL done = FALSE;
  157. uint32 sigmask = 0;
  158. IIntuition->GetAttr(WINDOW_SigMask, Objects[OBJ_WINDOW], &sigmask);
  159. struct ViewNode *node;
  160. while (!done)
  161. {
  162. uint32 siggot = IExec->Wait(sigmask | SIGBREAKF_CTRL_C);
  163. if (siggot & SIGBREAKF_CTRL_C)
  164. {
  165. done = TRUE;
  166. }
  167.  
  168. uint32 result = 0;
  169. uint16 code = 0;
  170.  
  171. while ((result = IIntuition->IDoMethod(Objects[OBJ_WINDOW], WM_HANDLEINPUT, &code)))
  172. {
  173. switch(result & WMHI_CLASSMASK)
  174. {
  175. case WMHI_CLOSEWINDOW:
  176. done = TRUE;
  177. break;
  178. case WMHI_GADGETUP:
  179. switch (result & WMHI_GADGETMASK)
  180. {
  181. case OBJ_QUIT:
  182. done = TRUE;
  183. break;
  184. case OBJ_LISTBROWSER:
  185.  
  186. IIntuition->GetAttr(LISTBROWSER_SelectedNode,Objects[OBJ_LISTBROWSER] ,(uint32*)&node);
  187. activeView=activateview(window, activeView, node);
  188. break;
  189. case OBJ_BUTTON1:
  190. case OBJ_BUTTON2:
  191. case OBJ_BUTTON3:
  192. IDOS->Printf("Button: [%ld]\n", ((result & WMHI_GADGETMASK) - OBJ_BUTTON1) +1);
  193. break;
  194. }
  195. break;
  196. case WMHI_ICONIFY:
  197. if (IIntuition->IDoMethod(Objects[OBJ_WINDOW], WM_ICONIFY))
  198. {
  199. window = NULL;
  200. }
  201. break;
  202. case WMHI_UNICONIFY:
  203. window = (struct Window*)IIntuition->IDoMethod(Objects[OBJ_WINDOW], WM_OPEN);
  204. break;
  205. case WMHI_RAWKEY:
  206. if (code == (IECODE_UP_PREFIX | RAWKEY_TAB))
  207. {
  208. IIntuition->IDoMethod(Objects[OBJ_WINDOW], WM_ACTIVATEGADGET, Objects[OBJ_LISTBROWSER]));
  209. }
  210. break;
  211. }
  212. }
  213. }
  214. }
  215. IIntuition->DisposeObject(Objects[OBJ_WINDOW]);
  216. freelist(&listbrowser_list);
  217.  
  218. }
  219. IExec->FreeSysObject(ASOT_PORT, appPort);
  220. }
  221. }
  222.  
  223. void freelist(struct List *list)
  224. {
  225. struct ViewNode *node;
  226. for ( node = (struct ViewNode *)IExec->GetHead(list) ; node != NULL ; node = (struct ViewNode *)IExec->GetSucc((struct Node *)node) )
  227. {
  228. IIntuition->DisposeObject((Object*)node->Data);
  229. IDOS->Printf("Deleting: [%ld]\n",node->Node.ln_Pri);
  230. }
  231.  
  232. IListBrowser->FreeListBrowserList(list);
  233. }
  234.  
  235. BOOL filllist(struct List *list, STRPTR* items)
  236. {
  237. struct ViewNode *node;
  238. IExec->NewList(list);
  239. int32 i =0;
  240. while (*items)
  241. {
  242. if (node = (struct ViewNode *)IListBrowser->AllocListBrowserNode(1,
  243. LBNA_Column, 0, LBNCA_Text, *items,
  244. LBNA_NodeSize, sizeof(struct ViewNode),
  245. TAG_DONE))
  246. {
  247. node->Data = Objects<em> = IIntuition->NewObject(NULL, "button.gadget",
  248. GA_Text, button_strings<em>,
  249. GA_ID, i+(int32)OBJ_BUTTON1,
  250. GA_RelVerify, TRUE,
  251. GA_TabCycle, TRUE,
  252. TAG_DONE);
  253. node->Node.ln_Pri = i++;
  254. IExec->AddTail(list, (struct Node*) node);
  255. }
  256. else
  257. {
  258. IDOS->Printf(" AllocListBrowserNode() failed\n");
  259. return FALSE;
  260. }
  261. items++;
  262. }
  263. return TRUE;
  264. }

DStastny
walkero
walkero's picture
Offline
Last seen: 5 days 12 hours ago
Joined: 2009-05-03 16:54
Re: How is it working?

Thank you so much guys for the explaination.
The solution with the pages seems valid, but I didn't know that you can do it without the tabs.

I will see what is more suitable for my project and I will get back to you.

Thanks again

walkero
walkero's picture
Offline
Last seen: 5 days 12 hours ago
Joined: 2009-05-03 16:54
Re: How is it working?

@thomas
To do the ICA_MAP I need to get the index of the clicked node from the listbrowser.

  1. static const ULONG listToPage[] = {
  2. ????????, PAGE_Current,
  3. TAG_END
  4. };

Any idea what the ?????? at the above should be? Which ListBrowser attribute would return the selected node?

Thank you for your help.

thomas
thomas's picture
Offline
Last seen: 12 hours 2 min ago
Joined: 2011-05-16 14:23
Re: How is it working?

Which ListBrowser attribute would return the selected node?

LISTBROWSER_Selected

The documentation is misleading because it says the attribute would set the selected node. This is only true for OM_SET, but it also supports OM_GET and OM_NOTIFY in which case it returns the selected node.

https://wiki.amigaos.net/amiga/autodocs/listbrowser_gc.doc.txt

walkero
walkero's picture
Offline
Last seen: 5 days 12 hours ago
Joined: 2009-05-03 16:54
Re: How is it working?

Oh my god. Thanks Thomas.
On the autodocs I have here this is marked as BOOLEAN. Will test it and hope it works.

walkero
walkero's picture
Offline
Last seen: 5 days 12 hours ago
Joined: 2009-05-03 16:54
Re: How is it working?

Yeap, it worked flawlessly. I ICA_TARGET and ICA_MAP and the page gadget and works very nice.
Thank you guys for your help.

Log in or register to post comments