Welcome, Guest. Please login or register.

Author Topic: Reaction: Adding/removing layout gadgets to Windows  (Read 2420 times)

Description:

0 Members and 1 Guest are viewing this topic.

Offline jahcTopic starter

  • Hero Member
  • *****
  • Join Date: Mar 2002
  • Posts: 521
    • Show all replies
    • http://wookiechat.amigarevolution.com
Reaction: Adding/removing layout gadgets to Windows
« on: July 04, 2003, 01:22:14 AM »
I want to be able to toggle between different layout gadgets. So if user clicks on one button, it will display layout, and if he clicks on another button, it will display layout3, for example. How do I add/remove layout gadgets to my window? I've experimented with AddGList() AddGadgets() RemoveGList() RemoveGadget() RefreshGList() etc etc to no avail. When I try to change the layout gadget for the window to something else, it will display only the listbrowser part of the layout gadget, the string gadget is nowhere to be found, and its not displayed correctly.. it appears in the corner of the window overlapping the close window gadget, and isnt updated when I resize the window.. When I use SetAttrs(), it works once if theres no layout gadget for the window yet.. otherwise it will just crash my program.

Help..

layout2=(Gadget*)LayoutObject,
            LAYOUT_DeferLayout, TRUE,    
            LAYOUT_SpaceOuter, TRUE,
            LAYOUT_BottomSpacing, 4,
            LAYOUT_HorizAlignment, LALIGN_LEFT,
            LAYOUT_Orientation, LAYOUT_ORIENT_HORIZ,
            GA_RelVerify, TRUE,
       CHILD_MaxHeight, screen->Font->ta_YSize,
   LAYOUT_AddChild,
       ButtonObject,
            GA_Text, "Status",
       ButtonEnd,
   LayoutEnd;

   layout=(Gadget*)LayoutObject,
            LAYOUT_DeferLayout, TRUE,
            LAYOUT_SpaceOuter, TRUE,
            LAYOUT_BottomSpacing, 4,
            LAYOUT_HorizAlignment, LALIGN_RIGHT,
            LAYOUT_Orientation, LAYOUT_ORIENT_VERT,
            LAYOUT_AddChild, ListBrowserObject,
   GA_RelVerify, TRUE,
        LISTBROWSER_Labels, (ULONG)&lb_list1,
                                    //LISTBROWSER_ColumnInfo, &ci1,
                                    LISTBROWSER_AutoFit, TRUE,
                                    LISTBROWSER_MultiSelect, TRUE,
                                    LISTBROWSER_ShowSelected, TRUE,
                                    LISTBROWSER_Separators, TRUE,
                                    LISTBROWSER_Editable, TRUE,
                                    LISTBROWSER_Spacing, 1,
                                ListBrowserEnd,
   LAYOUT_AddChild,StringObject,
   StringEnd,
        LAYOUT_AddChild, layout2,
        LayoutEnd;

   layout3=(Gadget*)layout;

           if (window_obj = (Object*)WindowObject,

                WA_Left, 0,
      WA_Width, 640,   
      WA_Height, 480,
                WA_Top, screen->Font->ta_YSize + 3,
                WA_CustomScreen, screen,
                WA_IDCMP, IDCMP_CLOSEWINDOW,
                WA_Flags, WFLG_DRAGBAR | WFLG_DEPTHGADGET | WFLG_CLOSEGADGET | WFLG_SIZEGADGET | WFLG_ACTIVATE | WFLG_SMART_REFRESH,
                WA_Title, "test",
                WINDOW_Layout, layout3,
                WINDOW_IconifyGadget, TRUE,
                WINDOW_Icon, GetDiskObject("PROGDIR:ReAction"),
                WINDOW_IconTitle, "ReAction Demo",
                WINDOW_AppPort, app_port,
            EndWindow)

   win = RA_OpenWindow(window_obj);
         
   //SetAttrs(window_obj, WINDOW_Layout, layout);

RemoveGList(win, layout3, -1);

AddGList(win, layout, -1, -1, NULL);
RefreshGList(layout,win, NULL, -1);
 

Offline jahcTopic starter

  • Hero Member
  • *****
  • Join Date: Mar 2002
  • Posts: 521
    • Show all replies
    • http://wookiechat.amigarevolution.com
Re: Reaction: Adding/removing layout gadgets to Windows
« Reply #1 on: July 05, 2003, 01:43:26 AM »
@TurboLaban

I used a parent layout, and then added my layout gadgets to it with LAYOUT_AddChild. Its very nearly working. It crashes the second time I try to add a child though..

SetAttrs(parent_layout, LAYOUT_AddChild, layout);
DoMethod(window_obj, WM_RETHINK);

(then later in the program)

SetAttrs(parent_layout, LAYOUT_RemoveChild, layout);
SetAttrs(parent_layout, LAYOUT_AddChild, layout3);

..

But the layout is perfect now. Just need to eliminate that crash.

If I remove "layout" then add "layout3" (as seen up there) before I open the window, it crashes straight away.. if I do those functions after the window has opened, it doesnt crash until I resize the window... so.. any ideas on what the problem could be?

-Edit- I figured out the problem. My layout gadgets share a child layout called layout2. When you use LAYOUT_RemoveChild it makes the pointers to those gadgets invalid. So when I removed "layout" then tried to add "layout3", it wouldnt go because it couldnt find "layout2" anymore.

Thanks for your help guys.