Reaction ListBrowsers - Some basic questions

42 posts / 0 new
Last post
AmigaOneFan
AmigaOneFan's picture
Offline
Last seen: 10 years 11 months ago
Joined: 2011-11-14 16:18
Reaction ListBrowsers - Some basic questions

Hi!

I am trying to put together a program for Amiga OS4 using Reaction that I once had on my Palm PDA. It was called BeSafe and it used the RIJNDAEL encoding method to store "safe" passwords on the Palm so that only the proper password would allow access to the data.
I have set up a reaction interface with a few tabs, each holding it own custom listbrowser. Right now I am just populating the data with arrays of hard coded strings.
Here are my questions:

1) I want to add sort capability to one or more of the columns in my listbrowser. I set the attributes for the listbowser to enable sorting, but when the program comes up I do not get the listrowser "arrow" at the title box of the listbrowser. I noticed this was true of the reaction demo included with OS4 as well - the listbrowser sort demo. The arrow doesn't appear until you click on the title. Is there a way to show the sort arrow when the listbrowser appears instead of after you click on the title box for that column?

2) What do I need to do to make automatic sorting work in a listbrowser column? The example under the listbrowser directory in reaction examples uses a custom sort and I think I am missing the simple steps required to do the built in column sort. I can get the custom sort to work fine...but it seems like extra code I shouldn't need perhaps?

3) Is there a way to obtain a numeric identifier for the current tab you are in when you have multiple tabs such that the tab Id is 0 to n?

4) Unrelated to reaction - I want to compile and build this RIJNDAEL source code and make it link to my code: http://www.efgh.com/software/rijndael.htm
I broke the source file into its component pieces - encrypt.c, decrypt.c, rijndael.c and rijndael.h - but when I use GCC to compile any of the .c code files, I get errors because each file references the other .c file for different unctions. How do I make .o files to link together to my program using GCC?

Thanks ... I can provide some source code later if you wish.

Also, thanks for the reaction beginners guide! It is good but as with anything can use more detail for certain aspects.

salass00
salass00's picture
Offline
Last seen: 6 months 2 weeks ago
Joined: 2011-02-03 11:27
1) I want to add sort


1) I want to add sort capability to one or more of the columns in my listbrowser. I set the attributes for the listbowser to enable sorting, but when the program comes up I do not get the listrowser "arrow" at the title box of the listbrowser. I noticed this was true of the reaction demo included with OS4 as well - the listbrowser sort demo. The arrow doesn't appear until you click on the title. Is there a way to show the sort arrow when the listbrowser appears instead of after you click on the title box for that column?

You need to tell listbrowser which column you want it to sort by. You can do this with the LISTBROWSER_SortColumn tag.


2) What do I need to do to make automatic sorting work in a listbrowser column? The example under the listbrowser directory in reaction examples uses a custom sort and I think I am missing the simple steps required to do the built in column sort. I can get the custom sort to work fine...but it seems like extra code I shouldn't need perhaps?

Set LBCIA_Sortable, LBCIA_AutoSort and LBCIA_SortArrow to TRUE for the columns that you want to be autosortable.

This is code that I use in DiskImageGUI for autosortable columns:

  1. enum {
  2. DRIVE_COL_ICON,
  3. DRIVE_COL_UNIT,
  4. DRIVE_COL_DEVICE,
  5. DRIVE_COL_WP,
  6. DRIVE_COL_DISKIMAGE,
  7. DRIVE_COL_MAX
  8. };
  9. /* ... */
  10. Gui.columninfos[CIID_DRIVELIST] = IListBrowser->AllocLBColumnInfo(DRIVE_COL_MAX,
  11. LBCIA_Column, DRIVE_COL_ICON,
  12. LBCIA_Title, "",
  13. LBCIA_Column, DRIVE_COL_UNIT,
  14. LBCIA_Title, GetString(&LocaleInfo, MSG_UNIT_LBL),
  15. LBCIA_Sortable, TRUE,
  16. LBCIA_AutoSort, TRUE,
  17. LBCIA_SortArrow, TRUE,
  18. LBCIA_Column, DRIVE_COL_DEVICE,
  19. LBCIA_Title, GetString(&LocaleInfo, MSG_DEVICE_LBL),
  20. LBCIA_Sortable, TRUE,
  21. LBCIA_AutoSort, TRUE,
  22. LBCIA_SortArrow, TRUE,
  23. LBCIA_Column, DRIVE_COL_WP,
  24. LBCIA_Title, GetString(&LocaleInfo, MSG_WRITEPROTECT_LBL),
  25. LBCIA_Sortable, TRUE,
  26. LBCIA_AutoSort, TRUE,
  27. LBCIA_SortArrow, TRUE,
  28. LBCIA_Column, DRIVE_COL_DISKIMAGE,
  29. LBCIA_Title, GetString(&LocaleInfo, MSG_FILENAME_LBL),
  30. LBCIA_Sortable, TRUE,
  31. LBCIA_AutoSort, TRUE,
  32. LBCIA_SortArrow, TRUE,
  33. TAG_END);
  34. /* ... */
  35. Gui.gadgets[GID_DRIVELIST] = IIntuition->NewObject(NULL, "listbrowser.gadget",
  36. GA_ID, GID_DRIVELIST,
  37. GA_RelVerify, TRUE,
  38. LISTBROWSER_ColumnTitles, TRUE,
  39. LISTBROWSER_TitleClickable, TRUE,
  40. LISTBROWSER_ColumnInfo, Gui.columninfos[CIID_DRIVELIST],
  41. LISTBROWSER_Labels, Gui.lists[LID_DRIVELIST],
  42. LISTBROWSER_ShowSelected, TRUE,
  43. LISTBROWSER_AutoFit, TRUE,
  44. LISTBROWSER_SortColumn, DRIVE_COL_UNIT,
  45. LISTBROWSER_VerticalProp, FALSE,
  46. TAG_END);
salass00
salass00's picture
Offline
Last seen: 6 months 2 weeks ago
Joined: 2011-02-03 11:27
3) Is there a way to obtain a


3) Is there a way to obtain a numeric identifier for the current tab you are in when you have multiple tabs such that the tab Id is 0 to n?

  1. uint32 current_tab;
  2. IIntuition->GetAttr(CLICKTAB_Current, clicktab_object, &current_tab);


4) Unrelated to reaction - I want to compile and build this RIJNDAEL source code and make it link to my code: http://www.efgh.com/software/rijndael.htm
I broke the source file into its component pieces - encrypt.c, decrypt.c, rijndael.c and rijndael.h - but when I use GCC to compile any of the .c code files, I get errors because each file references the other .c file for different unctions. How do I make .o files to link together to my program using GCC?

Use -c option:
gcc -c -o file1.o file1.c
gcc -c -o file2.o file2.c
gcc -c -o file3.o file3.c
gcc -o final_exe file1.o file2.o file3.o

Preferably you should use a Makefile instead of typing in commands manually into the shell so that only .c files that have actually changed are recompiled and also so that you don't need to remember all the options you need to use to compile your program.

AmigaOneFan
AmigaOneFan's picture
Offline
Last seen: 10 years 11 months ago
Joined: 2011-11-14 16:18
Great! Okay, I got the

Great! Okay, I got the sorting working using the built in sort. I had forgotten to set the LBCIA_sortable when allocating my listbrowser columns.

Thanks!

AmigaOneFan
AmigaOneFan's picture
Offline
Last seen: 10 years 11 months ago
Joined: 2011-11-14 16:18
Ah, okay. I thought I tried

Ah, okay. I thought I tried the way you show to figure out the current tab, I'll try it again.
Yes...I need to use a makefile...or put all the code inline in one .c file, which is messy.

Okay, another listbrowser question.

How can I traverse the listbrowser elements to retrieve the text in order to store it to a file?

Here's what I am doing right now....
I have populated a listbrowser node list using a hard coded string array. Now I want to pull the elements out to save to a file...

  1. currentNode = IExec->GetHead(&listbrowser_list1);
  2.  
  3. while(currentNode != NULL)
  4. {
  5. IListBrowser->GetListBrowserNodeAttrs(currentNode,
  6. LBNA_UserData,&TextData,
  7. LBNA_NumColumns,&columns1,
  8. TAG_DONE);
  9.  
  10. IDOS->Printf("Data = %s columns = %lu\n",text,columns1);
  11. currentNode = IExec->GetSucc(currentNode);
  12. i++;
  13. }

When I print text and columns1 I see " " and "0". What silly mistake am I making here?

Thanks!

trixie
trixie's picture
Offline
Last seen: 6 months 3 weeks ago
Joined: 2011-02-03 13:58
Re: Reaction ListBrowsers - Some basic questions

How can I traverse the listbrowser elements to retrieve the text in order to store it to a file?

You're retrieving data from the node's userdata field, not the actual node/column text - are you sure you really want that? Retrieving text from a multi-column listbrowser is done like this:

  1. IListBrowser->GetListBrowserNodeAttrs(currentNode,
  2. LBNA_Column, 0,
  3. LBNCA_Text, &column1_text,
  4. LBNA_Column, 1,
  5. LBNCA_Text, &column2_text,
  6. LBNA_Column, 2,
  7. LBNCA_Text, &column3_text,
  8. .
  9. .
  10. .
  11. TAG_DONE);

AmigaOne X5000-020 / 2GB RAM / Sapphire Pulse Radeon RX 560 / AmigaOS 4.1 Final Edition Update 2

AmigaOneFan
AmigaOneFan's picture
Offline
Last seen: 10 years 11 months ago
Joined: 2011-11-14 16:18
Hi Trixie, Doh! You are

Hi Trixie,

Doh! You are right! I am looking at the wrong thing...no wonder I am getting the wrong answer! I'll put in the code to access the column data and give it a try.

Thanks!

My source can be found here: http://www.os4coding.net/source/162

Scott

AmigaOneFan
AmigaOneFan's picture
Offline
Last seen: 10 years 11 months ago
Joined: 2011-11-14 16:18
Salass00, I downloaded

Salass00,

I downloaded codebench and am quite impressed! It should take care of my having to include multiple source files and creating makefiles for me. Great program!
Oh, sometimes when I exit codebench I get an program ISI error.
Also, what do I need to do in codebench to get the debugger to work?

Here's another listbrowser question - how do I make listbrowser data editable? I have tried adding LISTBROWSER_ShowSelected and LISTBROWSER_Editable to my creation of the listbrowsers when I do a newOBJ on them...but it doesn;t seem to make any difference. When I click inside any of the data items, I am not able to edit them....the row highlights showing it is selected, but it does not allow me to edit it.
Is there some sort of LBCIA control I need to add?

Thanks!

salass00
salass00's picture
Offline
Last seen: 6 months 2 weeks ago
Joined: 2011-02-03 11:27
@AmigaOneFan I downloaded

@AmigaOneFan


I downloaded codebench and am quite impressed! It should take care of my having to include multiple source files and creating makefiles for me. Great program!
Oh, sometimes when I exit codebench I get an program ISI error.
Also, what do I need to do in codebench to get the debugger to work?

Someone who's used CodeBench will have to answer this question for you. If you post in the CodeBench support forum on www.amigans.net you will probably have a higher chance to get a reply from the author.


Here's another listbrowser question - how do I make listbrowser data editable? I have tried adding LISTBROWSER_ShowSelected and LISTBROWSER_Editable to my creation of the listbrowsers when I do a newOBJ on them...but it doesn;t seem to make any difference. When I click inside any of the data items, I am not able to edit them....the row highlights showing it is selected, but it does not allow me to edit it.
Is there some sort of LBCIA control I need to add?

I had to check AminetReadme source code to refresh my memory on this topic. In addition to setting LISTBROWSER_Editable to TRUE when creating the listbrowser you also need to set for every node that you create, for every column that you want to be editable the LBNCA_Editable tag to TRUE and LBNCA_MaxChars tag to the max amount of characters that you want the user to be able to enter. Also when you want to set or change a text in one of your editable column(s) you need to use LBNCA_CopyText (set to TRUE) so that the text you provide with LBNCA_Text is copied into the node's internal buffer.

F.e. to create a listbrowser node with three editable columns (30 characters each):

  1. struct Node *node;
  2. node = IListBrowser->AllocListBrowserNode(3,
  3. LBNA_Column, 0,
  4. LBNCA_Text, "column 1 text",
  5. LBNCA_CopyText, TRUE,
  6. LBNCA_Editable, TRUE,
  7. LBNCA_MaxChars, 30,
  8. LBNA_Column, 1,
  9. LBNCA_Text, "column 2 text",
  10. LBNCA_CopyText, TRUE,
  11. LBNCA_Editable, TRUE,
  12. LBNCA_MaxChars, 30,
  13. LBNA_Column, 2,
  14. LBNCA_Text, "column 3 text",
  15. LBNCA_CopyText, TRUE,
  16. LBNCA_Editable, TRUE,
  17. LBNCA_MaxChars, 30,
  18. TAG_END);
AmigaOneFan
AmigaOneFan's picture
Offline
Last seen: 10 years 11 months ago
Joined: 2011-11-14 16:18
Salass00, Great! That did

Salass00,

Great! That did the trick! Thank you so much, I couldn't find any examples or any details on how to do this simple thing. You say you found this off of Aminet???

salass00
salass00's picture
Offline
Last seen: 6 months 2 weeks ago
Joined: 2011-02-03 11:27
@AmigaOneFan No, I was

@AmigaOneFan

No, I was referring to AminetReadme program for creating/editing Aminet readme files.

AmigaOneFan
AmigaOneFan's picture
Offline
Last seen: 10 years 11 months ago
Joined: 2011-11-14 16:18
Ah, back to some programming

Ah, back to some programming fun!
I am able to obtain the current tab number 0 to n using your suggestion. But now I want to delete from the current tab whatever row is selected in that tabs listbrowser. (See my code example here: http://www.os4coding.net/source/162 ).
On line 925 of this code I have code that responds to the selection of the delete entry button. How do I determine which row of the current tab's listbrowser is selected? As I mentioned above, I can figure out which tab I am on using IIntuition->GetAttr(CLICKTAB_Current, clicktab_object, &current_tab);

Also, once I determine which row of the listbrowser to delete, what do I need to do to refresh the list and update the tab listbrowser display?

Thanks!

salass00
salass00's picture
Offline
Last seen: 6 months 2 weeks ago
Joined: 2011-02-03 11:27
How do I determine which row


How do I determine which row of the current tab's listbrowser is selected?

  1. Object *listbrowser;
  2. struct Node *node = NULL;
  3. IIntuition->GetAttr(LISTBROWSER_SelectedNode, listbrowser, (Tag *)&node);
  4. if (node) {
  5. /* got selected node */
  6. } else {
  7. /* no node selected */
  8. }
salass00
salass00's picture
Offline
Last seen: 6 months 2 weeks ago
Joined: 2011-02-03 11:27
Also, once I determine which


Also, once I determine which row of the listbrowser to delete, what do I need to do to refresh the list and update the tab listbrowser display?

You mean remove the node from the listbrowser?

  1. Object *winobj;
  2. struct Window *window = NULL;
  3. IIntuition->GetAttr(WINDOW_Window, winobj, (Tag *)&window);
  4. /* remove node, free it and update display */
  5. IIntuition->DoGadgetMethod((struct Gadget *)listbrowser, window, NULL, LBM_REMNODE, NULL, node);

This also frees the node.

If you just want to remove it the code gets slightly longer:

  1. Object *winobj;
  2. struct Window *window = NULL;
  3. struct List *list = NULL;
  4. IIntuition->GetAttr(WINDOW_Window, winobj, (Tag *)&window);
  5. IIntuition->GetAttr(LISTBROWSER_Labels, listbrowser, (Tag *)&list);
  6. /* detach list from listbrowser */
  7. IIntuition->SetAtts(listbrowser, LISTBROWSER_Labels, ~0, TAG_END);
  8. /* remove node from list */
  9. IExec->Remove(node);
  10. /* reattach list and update display */
  11. IIntuition->SetGadgetAttrs((struct Gadget *)listbrowser, window, NULL, LISTBROWSER_Labels, list, TAG_END);
AmigaOneFan
AmigaOneFan's picture
Offline
Last seen: 10 years 11 months ago
Joined: 2011-11-14 16:18
Okay, (I say a year later!) I

Okay, (I say a year later!) I finally got around to trying this. When I use the code:
IIntuition->GetAttr(LISTBROWSER_SelectedNode, listbrowser, (TAG *)&node);

node always returns -1, which is I believe the default value.

Why am I not seeing the actual selected node, no matter which row I have selected in my listbrowser? Is there some other parameter that needs to be initialized?
Oh, when I try using LISTBROWSER_Selected (just for fun) instead I always get a result of 0, again the default value for that field.

Note that I am using my own listbrowser name from my code pointed to previously, not the actual text "listbrowser" as shown.

What am I missing now?

Thanks!

trixie
trixie's picture
Offline
Last seen: 6 months 3 weeks ago
Joined: 2011-02-03 13:58
Re: Reaction ListBrowsers - Some basic questions

@AmigaOneFan

IIntuition->GetAttr(LISTBROWSER_SelectedNode, listbrowser, (TAG *)&node);
always returns -1, which is I believe the default value.

As LISTBROWSER_SelectedNode contains a pointer to struct Node, I'd say the default value would be NULL, not -1. Just guessing though.

I'm not sure how your (TAG *) typecast might influence the result of the call, I've never seen it used before. I always retrieve the selected node like this:

  1. struct Node *node = NULL;
  2.  
  3. IIntuition->GetAttrs(listbrowser, LISTBROWSER_SelectedNode, (uint32 *)&node, TAG_DONE);

Why am I not seeing the actual selected node, no matter which row I have selected in my listbrowser?

What do you mean by "I am not seeing the actual selected node"? Doesn't the node (row) become highlighted when you click on it?

AmigaOne X5000-020 / 2GB RAM / Sapphire Pulse Radeon RX 560 / AmigaOS 4.1 Final Edition Update 2

salass00
salass00's picture
Offline
Last seen: 6 months 2 weeks ago
Joined: 2011-02-03 11:27
@trixie As

@trixie


As LISTBROWSER_SelectedNode contains a pointer to struct Node, I'd say the default value would be NULL, not -1. Just guessing though.

I think he has the return values mixed up because -1 is the return value of LISTBROWSER_Selected when no node is selected, for LISTBROWSER_SelectedNode the equivalent value is NULL.


I'm not sure how your (TAG *) typecast might influence the result of the call, I've never seen it used before. I always retrieve the selected node like this:

Using Tag type may in some cases be more portable than using uint32 because uint32 will fail on a 64-bit system (in this case it doesn't really matter because the cast is there just so the compiler doesn't throw a warning). Even better would of course be if AmigaOS had a type similar to IPTR on AROS (IPTR on AROS is an unsigned integer type that is guaranteed to always be large enough to contain a pointer).


What do you mean by "I am not seeing the actual selected node"? Doesn't the node (row) become highlighted when you click on it?

Maybe he has forgot to set LISTBROWSER_ShowSelected to TRUE?

AmigaOneFan
AmigaOneFan's picture
Offline
Last seen: 10 years 11 months ago
Joined: 2011-11-14 16:18
Thanks for the info. I am

Thanks for the info. I am setting LISTBROWSER_ShowSelect TRUE in my code here:

  1.  
  2. LAYOUT_AddChild, OBJ(OBJ_LISTBROWSER4) = IIntuition->NewObject(NULL, "listbrowser.gadget",
  3. GA_ID, OBJ_LISTBROWSER4,
  4. GA_RelVerify, TRUE,
  5. GA_TabCycle, TRUE,
  6. LISTBROWSER_AutoFit, TRUE,
  7. LISTBROWSER_Labels, &listbrowser_list4,
  8. LISTBROWSER_ColumnInfo, columninfo4,
  9. LISTBROWSER_ColumnTitles, TRUE,
  10. LISTBROWSER_ShowSelected, TRUE,
  11. LISTBROWSER_Editable, TRUE,
  12. LISTBROWSER_Striping, LBS_ROWS,
  13. TAG_DONE),

... for each listbrowser I create (one for each of four tabs). And yes, when I select an item in the list it is highlighted and I can edit it and save it.
But, when I try to identify which item is selected using LISTBROWSER_SelectedNode as shown in the code in one of the earlier posts, the value never changes no matter which item I select. It is always (IIRC) -1. I want to perform operations on the listbrowser data by identifying which tab and which item is selected - for example to delete an item from the list. But although I can identify the correct tab (thanks for your previous help on this) I never get anything valid as far as which node (or item) is selected.
I must be doing something dumb wrong here...but it is just not obvious to me.

Thanks for your help! Any more ideas?

gazelle
gazelle's picture
Offline
Last seen: 1 year 9 months ago
Joined: 2011-04-13 12:52
@AmigaOneFan If your code

@AmigaOneFan

If your code example is still valid you're creating eight listbrowsers in line 252, 274, 294, 314 and than again at 421, 434, 447, 460 but only using four variables to remember the objects OBJ(OBJ_LISTBROWSER[1234]).

My guess would be the first four are the one which are beeing displayed but you're testing the wrong one because you have overwritten the corresponding variables.

You are adding two parent level layouts to your window (line 375 and 412) and I think that you shouldn't do that.

AmigaOneFan
AmigaOneFan's picture
Offline
Last seen: 10 years 11 months ago
Joined: 2011-11-14 16:18
@gazelle Yes, you are

@gazelle

Yes, you are absolutely right! I wonder how that cut and paste error crept into the code!
Okay, fixed.
Now I am getting something returned when I look at my listbrowser nodes. The uint32 I get showing my active node is not a number but a pointer to the node, correct?

Thanks!

trixie
trixie's picture
Offline
Last seen: 6 months 3 weeks ago
Joined: 2011-02-03 13:58
Re: Reaction ListBrowsers - Some basic questions

The uint32 I get showing my active node is not a number but a pointer to the node, correct?

If you GetAttr() from LISTBROWSER_SelectedNode then the returned uint32 is actually a pointer to the currently selected node. A pointer is actually an address in memory = a 32 bit integer number.

AmigaOne X5000-020 / 2GB RAM / Sapphire Pulse Radeon RX 560 / AmigaOS 4.1 Final Edition Update 2

AmigaOneFan
AmigaOneFan's picture
Offline
Last seen: 10 years 11 months ago
Joined: 2011-11-14 16:18
@trixie wrote... "the

@trixie wrote...

"the returned uint32 is actually a pointer to the currently selected node"

Yes, as I guessed. Good. got my delete node working now for all possible entries in all tabs! Hurray!

Now on to the next problem. I want to add a node at the bottom of a listbrowser list. To do so, I have a function named AddNode(struct List *browserlist, int columns). So I should know which browserlist to add an entry to, and how many coulmns it will have so I can set it up.
For now, I am just attempting my columns size of 5. First, I detach the browserlist like this:

  1. struct Node *node;
  2. // Detach the listbrowser list first
  3. IIntuition->SetAttrs(OBJ(OBJ_LISTBROWSER1),
  4. LISTBROWSER_Labels, NULL, TAG_DONE);

then I create a blank node to add to the tail of the list....like this:

  1. if (node = IListBrowser->AllocListBrowserNode(columns,
  2. LBNA_Column, 0,
  3. LBNCA_Text, "1",
  4. LBNCA_Editable, TRUE,
  5. LBNCA_CopyText, TRUE,
  6. LBNCA_MaxChars, 30,
  7. LBNA_Column, 1,
  8. LBNCA_Text, "2",
  9. LBNCA_Editable, TRUE,
  10. LBNCA_CopyText, TRUE,
  11. LBNCA_MaxChars, 30,
  12. LBNA_Column, 2,
  13. LBNCA_Text, "3",
  14. LBNCA_Editable, TRUE,
  15. LBNCA_CopyText, TRUE,
  16. LBNCA_MaxChars, 30,
  17. LBNA_Column, 3,
  18. LBNCA_Text, "4",
  19. LBNCA_Editable, TRUE,
  20. LBNCA_CopyText, TRUE,
  21. LBNCA_MaxChars, 30,
  22. LBNA_Column, 4,
  23. LBNCA_Text, "5",
  24. LBNCA_Editable, TRUE,
  25. LBNCA_CopyText, TRUE,
  26. LBNCA_MaxChars, 30,
  27. (TAG_DONE)))
  28. {
  29. IDOS->Printf(" Adding broweser tail entry to tab 1\n");
  30. IExec->AddTail(browserlist, node);
  31. }
  32. else
  33. {
  34. IDOS->Printf(" AllocListBrowserNode() failed\n");
  35. return(FALSE);
  36. }

So, it goes ahead and does this, but what happens is not what I expect. Instead of adding a new node to the tail of my browserlist, what happens is that my browserlist gets erased completely. I see this when I click to another tab and then back to the one which I have added this new node to. It is now empty (have to do this because I am not updating the display...yet).
My call to the function is:

  1. if(AddNode((struct List *)&listbrowser_list1, COLSTAB1))
  2. {
  3. }
  4. else
  5. {
  6. IDOS->Printf(" Unable to add listbrowser node!\n");
  7. }

and it does not show any error that it is not adding the node.
This is likely another dumb pointer issue. You would think I would see these by now! But I am not seeing what I have missed here.

Any ideas or help would be appreciated.

Thanks!

AmigaOneFan
AmigaOneFan's picture
Offline
Last seen: 10 years 11 months ago
Joined: 2011-11-14 16:18
oops...double post!

oops...double post!

thomas
thomas's picture
Offline
Last seen: 3 months 1 week ago
Joined: 2011-05-16 14:23
First, I detach the

First, I detach the browserlist like this:

then I create a blank node to add to the tail of the list....like this:

what happens is that my browserlist gets erased completely.

You forgot to attach the list to the browser again.

salass00
salass00's picture
Offline
Last seen: 6 months 2 weeks ago
Joined: 2011-02-03 11:27
@AmigaOneFan You should set

@AmigaOneFan

You should set LISTBROWSER_Labels to -1 not NULL if you're just removing the list so that you can add some modifications to it, also you want to add the list back after doing your modifications using IIntuition->SetGadgetAttrs().

  1. void AddNodeToLB (Object *winobj, Object *lb, struct Node *node) {
  2. struct Window *window = NULL;
  3. struct List *list = NULL;
  4.  
  5. /* get intuition window and list pointers (window pointer can be NULL) */
  6. IIntuition->GetAttr(WINDOW_Window, winobj, (Tag *)&window);
  7. IIntuition->GetAttr(LISTBROWSER_Labels, lb, (Tag *)&list);
  8.  
  9. if (list) {
  10. /* remove list temporarily */
  11. IIntuition->SetAttrs(lb,
  12. LISTBROWSER_Labels, ~0,
  13. TAG_END);
  14.  
  15. /* add our node */
  16. IExec->AddTail(list, node);
  17.  
  18. /* add it back and refresh */
  19. IIntuition->SetGadgetAttrs((struct Gadget *)lb, window, NULL,
  20. LISTBROWSER_Labels, list,
  21. TAG_END);
  22. }
  23. }
trixie
trixie's picture
Offline
Last seen: 6 months 3 weeks ago
Joined: 2011-02-03 13:58
Re: Reaction ListBrowsers - Some basic questions

@AmigaOneFan

As Thomas says, make sure you attach the list back to the listbrowser. Use SetGadgetAttrs() if you want the browser display to get updated right away, otherwise you can use SetAttrs().

@salass00

You should set LISTBROWSER_Labels to -1 not NULL if you're just removing the list so that you can add some modifications to it

The listbrowser autodoc says quite explicitly that the "detach value" is ~0 or NULL, not -1.

AmigaOne X5000-020 / 2GB RAM / Sapphire Pulse Radeon RX 560 / AmigaOS 4.1 Final Edition Update 2

salass00
salass00's picture
Offline
Last seen: 6 months 2 weeks ago
Joined: 2011-02-03 11:27
The listbrowser autodoc says


The listbrowser autodoc says quite explicitly that the "detach value" is ~0 or NULL, not -1.

-1 is the same value as ~0 (in 2's complement which practically all sane systems use). I find it strange that you do not know this...

As you may or may not have noticed I've used ~0 in the example code above but using either should be ok as they produce the same value.

thomas
thomas's picture
Offline
Last seen: 3 months 1 week ago
Joined: 2011-05-16 14:23
He is using tabs (a.k.a.

He is using tabs (a.k.a. pages) so actually he should use SetPageGadgetAttrs instead of SetGadgetAttrs. Otherwise strange things will happen if the list browser he is changing is not on the page which is currently displayed.

salass00
salass00's picture
Offline
Last seen: 6 months 2 weeks ago
Joined: 2011-02-03 11:27
He is using tabs (a.k.a.


He is using tabs (a.k.a. pages) so actually he should use SetPageGadgetAttrs instead of SetGadgetAttrs. Otherwise strange things will happen if the list browser he is changing is not on the page which is currently displayed.

If his listbrowser is located in a page gadget then he should of course use SetPageGadgetAttrs(). I didn't look too closely at his code so I didn't notice it was located in a clicktab page.

Modified code:

  1. void AddNodeToLB (Object *winobj, Object *page, Object *lb, struct Node *node) {
  2. struct Window *window = NULL;
  3. struct List *list = NULL;
  4.  
  5. /* get intuition window and list pointers (window pointer can be NULL) */
  6. IIntuition->GetAttr(WINDOW_Window, winobj, (Tag *)&window);
  7. IIntuition->GetAttr(LISTBROWSER_Labels, lb, (Tag *)&list);
  8.  
  9. if (list) {
  10. /* remove list temporarily */
  11. IIntuition->SetAttrs(lb,
  12. LISTBROWSER_Labels, ~0,
  13. TAG_END);
  14.  
  15. /* add our node */
  16. IExec->AddTail(list, node);
  17.  
  18. /* add it back and refresh */
  19. if (page) {
  20. ILayout->SetPageGadgetAttrs((struct Gadget *)lb, page, window, NULL,
  21. LISTBROWSER_Labels, list,
  22. TAG_END);
  23. } else {
  24. IIntuition->SetGadgetAttrs((struct Gadget *)lb, window, NULL,
  25. LISTBROWSER_Labels, list,
  26. TAG_END);
  27. }
  28. }
  29. }
AmigaOneFan
AmigaOneFan's picture
Offline
Last seen: 10 years 11 months ago
Joined: 2011-11-14 16:18
@salass00 Okay, this did

@salass00

Okay, this did the trick....

  1. IIntuition->SetGadgetAttrs((struct Gadget *)lb, window, NULL,
  2. LISTBROWSER_Labels, list,
  3. TAG_END);

Thanks! As for being careful about updating tabs that are not currently viewed, I will be adding code to ensure my listbrowser list and object are the ones based on the current tab.

Thanks!

salass00
salass00's picture
Offline
Last seen: 6 months 2 weeks ago
Joined: 2011-02-03 11:27
As for being careful about


As for being careful about updating tabs that are not currently viewed, I will be adding code to ensure my listbrowser list and object are the ones based on the current tab.

That's not a safe solution. The only 100% safe solution is to use SetPageGadgetAttrs() providing the pointer to the page in question.

Pages

Log in or register to post comments