26 February 2023, 20:56 | #1 |
Registered User
Join Date: Jan 2020
Location: Poland
Posts: 181
|
[ReAction] How to change content of LIST_BROWSER gadget.
Hi,
My goal is to change the content of the LIST_BROWSER gadget in ReAction. I want to push a button and then the list that is attached to LIST_BROWSER should be cleared and filled up again with new values. Right now it "works" partially, but there are errors. Maybe You have some example how to do such an operation. I am sending the code and example picture how it crashes after clearing list and filing again. Code:
// AmigaOS includes. #include <proto/exec.h> #include <proto/dos.h> #include <proto/graphics.h> #include <proto/intuition.h> #include <proto/gadtools.h> #include <intuition/intuition.h> #include <libraries/gadtools.h> #include <proto/cybergraphics.h> #include <cybergraphx/cybergraphics.h> #include <exec/lists.h> #include <exec/nodes.h> #include <exec/memory.h> #include <clib/alib_protos.h> #include <clib/exec_protos.h> // For ReAction gadgets library. #include <reaction/reaction.h> #include <reaction/reaction_macros.h> #include <clib/reaction_lib_protos.h> #include <classes/window.h> #include <gadgets/layout.h> #include <gadgets/listbrowser.h> #include <gadgets/chooser.h> #include <images/label.h> #include <proto/listbrowser.h> #include <proto/chooser.h> #include <proto/label.h> #include <proto/layout.h> #include <proto/window.h> #include <proto/button.h> // Standard C includes. #include <string.h> #include <stdio.h> #include <stdlib.h> // ---------------------------------------- // --- AMIGA Starter - global variables --- // ---------------------------------------- #define STARTER_WINDOW_NAME "msRay (v0.36), Amiga Starter." #define STARTER_WINDOW_WIDTH 350 #define STARTER_WINDOW_HEIGHT 210 struct Window* STARTER_window; // All gadgets numerations ids. enum { GID_START_BUTTON, GID_HELP_BUTTON, GID_LIST, GID_MODE_CHOOSER, GID_ASPECT_CHOOSER, GID_PIXEL_CHOOSER, GID_BUFFER_CHOOSER, GID_LAST }; // All gadgets structure holder. struct Gadget *G_gadgets[GID_LAST]; // All gadgets strings for cycle/chooser. const char* G_mode_strings[] = { "Fullscreen (32bit)", "Window (32bit)", "Fullscreen (HAM)", NULL }; // All gadgets helper variables, to keep states. enum { G_MODE_FULLSCREEN_32BIT, G_MODE_WINDOW_32BIT, G_MODE_HAM }; ULONG G_mode_selection = G_MODE_FULLSCREEN_32BIT; struct List G_list; // Only for ReAction gadgets. struct Library* WindowBase = NULL; struct Library* LayoutBase = NULL; struct Library* LabelBase = NULL; struct Library* ButtonBase = NULL; struct Library* ListBrowserBase = NULL; struct Library* ChooserBase = NULL; Object* REACTION_window_object; struct MsgPort* REACTION_msg_app_port; // ---------------------------------------------- // --- AMIGA Starter - functions DECLARATIONS --- // ---------------------------------------------- UBYTE STARTER_Init(void); void CGX_Get_Fullscreen_32bit_Modes(void); UBYTE GUI_REACTION_Init(void); void GUI_REACTION_Update(void); void GUI_REACTION_Message_Loop(void); // -------------------------------------------- // --- AMIGA Starter - main() - entry point --- // -------------------------------------------- int main(void) { WindowBase = OpenLibrary("window.class", 0L); LayoutBase = OpenLibrary("gadgets/layout.gadget", 0L); LabelBase = OpenLibrary("images/label.image", 0L); ButtonBase = OpenLibrary("gadgets/button.gadget", 0L); ListBrowserBase = OpenLibrary("gadgets/listbrowser.gadget", 0L); ChooserBase = OpenLibrary("gadgets/chooser.gadget", 0L); if (WindowBase == NULL || LayoutBase == NULL || LabelBase == NULL || ButtonBase == NULL || ListBrowserBase == NULL || ChooserBase == NULL) return 0; GUI_REACTION_Init(); GUI_REACTION_Message_Loop(); return 0; } void CGX_Get_Fullscreen_32bit_Modes(void) { // Lets count the 32bit modes that we are interested in. //ULONG count = 0; // prepare lists structure that will hold screen modes //struct Node *node, *nextnode; /*node = G_list.lh_Head; while (nextnode = node->ln_Succ) { FreeListBrowserNode(node); //Remove(node); node = nextnode; }*/ FreeListBrowserList(&G_list); NewList(&G_list); for (int i = 0; i < 5; i++) { struct Node *tmp_node; tmp_node = AllocListBrowserNode( 2, LBNA_Column, 0, LBNCA_CopyText, TRUE, LBNCA_Text, (ULONG)"ffff", LBNCA_MaxChars, 10, LBNCA_Justification, LCJ_LEFT, LBNA_Column, 1, LBNCA_CopyText, TRUE, LBNCA_Text, (ULONG)"bbbb", LBNCA_MaxChars, 16, LBNCA_Justification, LCJ_RIGHT, TAG_DONE); AddTail(&G_list, tmp_node); } } UBYTE GUI_REACTION_Init(void) { //NewList(&G_list); GUI_REACTION_Update(); // Create message port. REACTION_msg_app_port = CreateMsgPort(); // Stucture describing the list view gadget. struct ColumnInfo list_browser_column_info[] = { { 38, "Driver", 0 }, { 62, "Resolution", 0 }, { -1, (STRPTR)~0, -1 } }; // Create ReAction gadgets. REACTION_window_object = NewObject(WINDOW_GetClass(), NULL, WA_ScreenTitle, (ULONG)STARTER_WINDOW_NAME, WA_Title, (ULONG)STARTER_WINDOW_NAME, WA_Activate, TRUE, WA_DragBar, TRUE, WA_DepthGadget, TRUE, WA_CloseGadget, TRUE, WA_SmartRefresh, TRUE, WINDOW_AppPort, (ULONG)REACTION_msg_app_port, WINDOW_IconTitle, (ULONG)STARTER_WINDOW_NAME, WINDOW_Position, WPOS_CENTERSCREEN, WINDOW_ParentGroup, (ULONG)NewObject(LAYOUT_GetClass(), NULL, LAYOUT_Orientation, LAYOUT_ORIENT_VERT, LAYOUT_DeferLayout, TRUE, // RIGHT SIDE LAYOUT_AddChild, (ULONG)NewObject(LAYOUT_GetClass(), NULL, LAYOUT_Orientation, LAYOUT_ORIENT_VERT, // screen size - list view LAYOUT_AddChild, (ULONG)NewObject(LAYOUT_GetClass(), NULL, LAYOUT_Orientation, LAYOUT_ORIENT_VERT, LAYOUT_BevelStyle, BVS_SBAR_VERT, LAYOUT_Label, (ULONG)"Screen size:", LAYOUT_AddChild, (ULONG)(G_gadgets[GID_LIST] = NewObject(LISTBROWSER_GetClass(), NULL, GA_ID, GID_LIST, GA_RelVerify, TRUE, LISTBROWSER_Labels, (ULONG)&G_list, LISTBROWSER_ColumnInfo, (ULONG)&list_browser_column_info, LISTBROWSER_ColumnTitles, TRUE, LISTBROWSER_Separators, TRUE, LISTBROWSER_Hierarchical, FALSE, LISTBROWSER_Editable, FALSE, LISTBROWSER_MultiSelect, FALSE, LISTBROWSER_Selected, (ULONG)0, LISTBROWSER_ShowSelected, TRUE, TAG_END)), CHILD_MinWidth, 150, TAG_END), TAG_END), // ADD ROW AT THE BOTTOM LAYOUT_AddChild, (ULONG)NewObject(LAYOUT_GetClass(), NULL, LAYOUT_Orientation, LAYOUT_ORIENT_HORIZ, LAYOUT_SpaceOuter, TRUE, LAYOUT_AddChild, (ULONG)NewObject(BUTTON_GetClass(), NULL, GA_ID, GID_START_BUTTON, GA_RelVerify, TRUE, GA_Text, (ULONG)"START RAYCASTER", TAG_END), CHILD_WeightedWidth, 70, CHILD_MinHeight, 28, TAG_END), CHILD_WeightedHeight, 0, TAG_END), TAG_END); if (!REACTION_window_object) return 0; // Create Reaction window. STARTER_window = (struct Window *)RA_OpenWindow(REACTION_window_object); if(!STARTER_window) return 0; return 1; } void GUI_REACTION_Update(void) { // Update the GUI elements according to selected values. CGX_Get_Fullscreen_32bit_Modes(); RefreshGadgets(G_gadgets[GID_LIST], STARTER_window, NULL); RefreshGList(G_gadgets[GID_LIST], STARTER_window, NULL, -1); } void GUI_REACTION_Message_Loop(void) { ULONG app_signals = (1L << REACTION_msg_app_port->mp_SigBit); ULONG win_signals, wait_signals, result; UWORD code; GetAttr(WINDOW_SigMask, REACTION_window_object, &win_signals); // enter main loop UBYTE is_loop = TRUE; // When done return selected screen mode or 0 if Starter just exit. //STA_requested_display_id = 0; // Update GUI changes. // GUI_REACTION_Update(); while(is_loop) { wait_signals = Wait( win_signals | SIGBREAKF_CTRL_C | app_signals); if (wait_signals & SIGBREAKF_CTRL_C) is_loop = FALSE; else { while (( result = RA_HandleInput(REACTION_window_object, &code)) != WMHI_LASTMSG) { switch (result & WMHI_CLASSMASK) { case WMHI_CLOSEWINDOW: is_loop = FALSE; break; case WMHI_GADGETUP: switch (result & WMHI_GADGETMASK) { case GID_START_BUTTON: GUI_REACTION_Update(); break; } break; } } } } } Last edited by mateusz_s; 26 February 2023 at 22:35. |
26 February 2023, 23:30 | #2 |
Registered User
Join Date: Jan 2020
Location: Poland
Posts: 181
|
Ok, I found the solution..
The structure describing the columns in LIST_BROWSER was not global. After refreshing the gadget it was missing and the layout was broken // it should be global struct ColumnInfo list_browser_column_info[] = { {38, "Driver", 0 }, { 62, "Resolution", 0 }, { -1, (STRPTR)~0, -1 } }; |
27 February 2023, 18:03 | #3 |
Registered User
Join Date: Jan 2020
Location: Poland
Posts: 181
|
Hi,
I found another issue.. Before I create the ReAction GUI window and elements, I use Code:
NewList(&G_list) When I fill the list with new content - something is a bit wrong because I can have multiple selections like this: I noticed that this is combined somehow with the initial number of elements that are in the list attached to list_browser. In the first example when the list was empty, the multiple selection blue boxes can appear on every selected line. But If I would make initial list to have lets say 5 elements, Then this 5 first lines will never go multiple selected (but lines that are below 5 line wil be multiselected) any ideas? |
27 February 2023, 18:28 | #4 |
Registered User
Join Date: Jan 2002
Location: Germany
Posts: 7,035
|
If you modify the list while the window is open, you have to set LISTBROWSER_Labels to -1 before you do any changes and set it back to &G_list afterwards.
Why do you call both RefreshGadgets and RefreshGList? The former refreshes all gadgets starting with the given gadget and the latter refreshes the given number of gadgets. You set the number to -1 which means it does the same as the former again. Neither makes sense in a hierarchical construct like the ReAction GUI. You should only use RefreshGList with number set to 1 (one, not minus one). If you want to refresh multiple gadgets at once you should refresh the surrounding layout group. |
27 February 2023, 20:14 | #5 |
Registered User
Join Date: Jan 2020
Location: Poland
Posts: 181
|
Thank You @thomas, it works!
Yes I removed RefreshGList later, I left with RefreshGadgets to refresh the gadgets that need to be updated.. |
17 November 2023, 17:14 | #6 |
Camilla, AmigaOS Dev.
Join Date: Mar 2020
Location: Frederiksberg
Posts: 330
|
If you change the list (as opposed to just making small changes to one of the nodes) then you should set LISTBROWSER_Labels to NULL and not just ~0
the gadget will behave slightly different. Also it should not be nessesary to call refresh in this - it should happen automatically - in fact you will have a double refresh the way you have done it. |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Converting to Reaction: Shared UserPort? | Warty | Coders. C/C++ | 12 | 10 July 2021 07:38 |
ClassAct/Reaction & Eclipse/GCC Cross Chain | Warty | Coders. C/C++ | 3 | 15 August 2020 18:41 |
installing Classact and Reaction on 3.1.4 | dschallock | support.Other | 8 | 06 February 2020 19:19 |
Update ReAction classes | mritter0 | Coders. General | 2 | 30 July 2014 01:55 |
Proper ReAction coding | mritter0 | Coders. C/C++ | 3 | 24 April 2014 07:34 |
|
|