Page 1 of 1

Is Frame a Container ?

Posted: Thu Sep 19, 2024 2:29 pm
by ChrisR
With the new flag #PB_Frame_Container, do you have a way to know if a FrameGadget is a Container or not ?
Would it be safer to add the #WS_CLIPCHILDREN Style, to differentiate them as for the Canvas container ?

Code: Select all

EnableExplicit

Enumeration Window
  #Window
EndEnumeration

Enumeration Gadgets
  #Frame_Container
  #Button_Container
  #Frame
  #Button
EndEnumeration

Procedure IsFrameContainer(Gadget)
  Protected Result
  Result = Random(1, 0)
  ;If GetWindowLongPtr_(GadgetID(Gadget), #GWL_STYLE) & #WS_CLIPCHILDREN
  ;  Result = #True
  ;EndIf
  ProcedureReturn Result
EndProcedure

Procedure Open_Window_0(X = 0, Y = 0, Width = 400, Height = 340)
  If OpenWindow(#Window, 0, Y, Width, Height, "Title", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_ScreenCentered)
    FrameGadget(#Frame_Container, 60, 20, 280, 130, "Frame Container", #PB_Frame_Container | #PB_Frame_Flat)
      ;SetWindowLongPtr_(GadgetID(#Frame_Container), #GWL_STYLE, GetWindowLongPtr_(GadgetID(#Frame_Container), #GWL_STYLE) | #WS_CLIPCHILDREN) 
      ButtonGadget(#Button_Container, 30, 30, 220, 80, "Button in Container")
    CloseGadgetList()
    FrameGadget(#Frame, 60, 180, 280, 130, "Frame ", #PB_Frame_Flat)
    ButtonGadget(#Button, 90, 210, 220, 80, "Button")
    ProcedureReturn #True
  EndIf
EndProcedure

If Open_Window_0()
  Debug "#Frame_Container is a Container : " + Str(IsFrameContainer(#Frame_Container))
  Debug "#Frame is a Container : " + Str(IsFrameContainer(#Frame))
  
  Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf

Re: Is Frame a Container ?

Posted: Thu Sep 19, 2024 4:06 pm
by RASHAD
Hi ChrisR
You are the coder ?
Use gadget DATA

Code: Select all

EnableExplicit

Enumeration Window
  #Window
EndEnumeration

Enumeration Gadgets
  #Frame_Container
  #Button_Container
  #Frame
  #Button
EndEnumeration

Procedure IsFrameContainer(Gadget)
  If GetGadgetData(gadget) = 1  
    Debug "gadget "+Str(gadget) +" Is a container"
  Else 
    Debug "gadget "+Str(gadget) +" Is not a container"
  EndIf
EndProcedure

Procedure Open_Window_0(X = 0, Y = 0, Width = 400, Height = 340)
  If OpenWindow(#Window, 0, Y, Width, Height, "Title", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_ScreenCentered)
      FrameGadget(#Frame_Container, 60, 20, 280, 130, "Frame Container", #PB_Frame_Container| #PB_Frame_Flat)
      SetGadgetData(#Frame_Container,1)
      ButtonGadget(#Button_Container, 30, 25, 220, 80, "Button in Container")
    CloseGadgetList()
    FrameGadget(#Frame, 60, 180, 280, 130, "Frame ", #PB_Frame_Flat)
    SetGadgetData(#Frame,0)
    ButtonGadget(#Button, 90, 205 ,220, 80, "Button")
    ProcedureReturn #True
  EndIf
EndProcedure

If Open_Window_0()
  IsFrameContainer(#Frame_Container)
  IsFrameContainer(#Frame)   
  Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
You like to use Windows API
Not recommended

Code: Select all

EnableExplicit

Enumeration Window
  #Window
EndEnumeration

Enumeration Gadgets
  #Frame_Container
  #Button_Container
  #Frame
  #Button
EndEnumeration

Procedure IsFrameContainer(Gadget,child)
  If GetWindow_( GadgetID(Gadget), #GW_CHILD) = GadgetID(child)    
    Debug "gadget "+Str(gadget) +" Is a container"
  Else 
    Debug "gadget "+Str(gadget) +" Is not a container"
  EndIf
EndProcedure

Procedure Open_Window_0(X = 0, Y = 0, Width = 400, Height = 340)
  If OpenWindow(#Window, 0, Y, Width, Height, "Title", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_ScreenCentered)
      FrameGadget(#Frame_Container, 60, 20, 280, 130, "Frame Container", #PB_Frame_Container| #PB_Frame_Flat)
      SetGadgetData(#Frame_Container,1)
      ButtonGadget(#Button_Container, 30, 25, 220, 80, "Button in Container")
    CloseGadgetList()
    FrameGadget(#Frame, 60, 180, 280, 130, "Frame ", #PB_Frame_Flat)
    SetGadgetData(#Frame,0)
    ButtonGadget(#Button, 90, 205 ,220, 80, "Button")
    ProcedureReturn #True
  EndIf
EndProcedure

If Open_Window_0()
  IsFrameContainer(#Frame_Container,#Button_Container)
  IsFrameContainer(#Frame,#Button)  
  Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf

Re: Is Frame a Container ?

Posted: Thu Sep 19, 2024 4:51 pm
by ChrisR
Hi RASHAD,
Yes, Gadget Data should do it for my app :)
but, but I can't use it for everything, for example, to get Gadget info on an existing source code without having to change it too much, by using PB_Object_Enumerate e.g: PBForm2IceDesign.pb

For your 2nd snippet, yes, less recommendable and better with : If GadgetID(Gadget) = GetParent_(GadgetID(child))
I was a bit on that tip trying to get the Frame borders size. But the GadgetList is not defined for the Frame Container: viewtopic.php?t=85381

Code: Select all

Procedure ContainerOffset(Gadget, *OffSet.OffSet)
  Protected rcClient.RECT, Button
  If IsGadget(Gadget)
    Select GadgetType(Gadget)
      Case #PB_GadgetType_Frame
        OpenGadgetList(Gadget)
        Button               = ButtonGadget(#PB_Any, 0, 0, 0, 0, "")
        *OffSet\LeftOffSet   = GadgetX(Button, #PB_Gadget_ScreenCoordinate) - GadgetX(Gadget, #PB_Gadget_ScreenCoordinate)
        *OffSet\TopOffSet    = GadgetY(Button, #PB_Gadget_ScreenCoordinate) - GadgetY(Gadget, #PB_Gadget_ScreenCoordinate)
        GetClientRect_(GadgetID(Gadget), @rcClient)
        *OffSet\InnerWidth   = rcClient\right
        *OffSet\InnerHeight  = rcClient\bottom
        *OffSet\RightOffSet  = GadgetWidth(Gadget)  - *OffSet\InnerWidth - *OffSet\LeftOffSet
        *OffSet\BottomOffSet = GadgetHeight(Gadget) - *OffSet\InnerHeight - *OffSet\TopOffSet
        FreeGadget(Button)
        CloseGadgetList()
...
For windows, it would probably be good if Fred could add the #WS_CLIPCHILDREN style or other propertie.
Thanks :)

Re: Is Frame a Container ?

Posted: Thu Sep 19, 2024 7:17 pm
by Fred
Clipchildren is known to have a lot of redraw issues so we can't add it on containers.

Re: Is Frame a Container ?

Posted: Thu Sep 19, 2024 9:58 pm
by ChrisR
Thanks for letting me know, I don't know any more. I suggested Clipchildren in connection with the Canvas Container and because the description seems to fit:
Excludes the area occupied by child windows when drawing occurs within the parent window. This style is used when creating the parent window.
It would be nice if we could have a flag, a property in future, to know if a previously created Frame is a container or not.