Align() & Dock()

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
mestnyi
Addict
Addict
Posts: 1098
Joined: Mon Nov 25, 2013 6:41 am

Align() & Dock()

Post by mestnyi »

While there is no sense to you to write, :evil: we will persevere :D

Code: Select all

CompilerIf #PB_Compiler_OS = #PB_OS_Windows
      Import ""
      CompilerElse
        ImportC ""
        CompilerEndIf
        PB_Object_EnumerateStart( PB_Objects )
        PB_Object_EnumerateNext( PB_Objects, *ID.Integer )
        PB_Object_EnumerateAbort( PB_Objects )
        
        PB_Object_Count( PB_Objects )
        
        PB_Window_Objects.i
        PB_Gadget_Objects.i
        PB_Image_Objects.i
      EndImport
      
  
  ProcedureDLL ID_Init()
    Structure PropType
      Value.i
    EndStructure
    
    Structure PropMap
      Map PropName.PropType()
    EndStructure
    
    Global NewMap Props.PropMap()
  EndProcedure
  
  CompilerIf Not Defined( ID_Init, #PB_Function ) 
    ID_Init( )
  CompilerEndIf
  
  
  Procedure GetWindow( WindowID )  
    If MapSize( Props( ))
      ProcedureReturn (Props(Str(WindowID))\PropName("PB_WindowID")\Value) -1
    EndIf
    ProcedureReturn -1
  EndProcedure   
  
  Procedure GetGadget( GadgetID )  
    If MapSize( Props( ))
      ProcedureReturn (Props(Str(GadgetID))\PropName("PB_GadgetID")\Value) -1
    EndIf
    ProcedureReturn -1
  EndProcedure 
  
  
  Procedure SetWindow( Window )  
    If IsWindow( Window ) And GetWindow( WindowID( Window )) =-1
      Props(Str(WindowID(Window)))\PropName("PB_WindowID")\Value = Window +1
      ProcedureReturn WindowID( Window )
    EndIf  
  EndProcedure   
  
  Procedure SetGadget( Gadget )  
    If IsGadget( Gadget ) And GetGadget( GadgetID( Gadget )) =-1
      Props(Str(GadgetID(Gadget)))\PropName("PB_GadgetID")\Value = Gadget +1
      ProcedureReturn GadgetID( Gadget )
    EndIf  
  EndProcedure 
  
  
  Procedure SetAllWindow( )
    Protected Set, Window =-1
    PB_Object_EnumerateStart( PB_Window_Objects )
    If PB_Window_Objects
      While PB_Object_EnumerateNext(PB_Window_Objects, @Window )
        Set = SetWindow( Window )
        
      Wend
      PB_Object_EnumerateAbort( PB_Window_Objects ) 
    EndIf
    
    If Set
      PB_Object_EnumerateStart( PB_Window_Objects )
      PB_Object_EnumerateNext(PB_Window_Objects, @Window )
    EndIf
    ProcedureReturn Set
  EndProcedure
  
  Procedure SetAllGadget( )
    Protected Set, Gadget =-1
    PB_Object_EnumerateStart( PB_Gadget_Objects )
    If PB_Gadget_Objects
      While PB_Object_EnumerateNext(PB_Gadget_Objects, @Gadget )
        Set = SetGadget( Gadget )
      Wend
      
      PB_Object_EnumerateAbort( PB_Gadget_Objects ) 
    EndIf
    
    If Set
      PB_Object_EnumerateStart( PB_Gadget_Objects )
      PB_Object_EnumerateNext(PB_Gadget_Objects, @Gadget )
    EndIf
    ProcedureReturn Set
  EndProcedure
  
  
  ProcedureDLL IDWindow( WindowID ) ;Returns purebasic Window ID from WindowID
    Protected Window = GetWindow( WindowID )
    
    If Window =-1 
      If SetAllWindow( ) 
        SetAllGadget( )
        ProcedureReturn IDWindow( WindowID )
      EndIf
    EndIf 
    
   ProcedureReturn Window 
  EndProcedure  
  
  ProcedureDLL IDGadget( GadgetID ) ;Returns purebasic Gadget ID from GadgetID
    Protected Gadget = GetGadget( GadgetID ) 
     
     If Gadget =-1 
       If SetAllWindow( ) 
         SetAllGadget( )
         ProcedureReturn IDGadget( GadgetID ) 
       EndIf
     EndIf 
     
    ProcedureReturn Gadget 
  EndProcedure  
  
  
  ProcedureDLL IsWindowID(WindowID) ;Returns TRUE if is WindowID
    If IsWindow(IDWindow(WindowID));GetIsWindow(WindowID)
      ProcedureReturn #True
    EndIf
  EndProcedure  
  
  ProcedureDLL IsGadgetID(GadgetID);Returns TRUE if is GadgetID
    If IsGadget(IDGadget(GadgetID));GetIsGadget(GadgetID)
      ProcedureReturn #True
    EndIf  
  EndProcedure  
  
  ProcedureDLL GetParent(ChildID) ;Returns ParentID from ChildID (Default)
    If ChildID <>-1
      CompilerIf #PB_Compiler_OS = #PB_OS_Windows
        ProcedureReturn GetParent_(ChildID)
      CompilerElseIf #PB_Compiler_OS = #PB_OS_Linux
        ProcedureReturn gtk_widget_get_parent_(ChildID)
      CompilerEndIf
    EndIf  
    ProcedureReturn -1
  EndProcedure 
  
  ProcedureDLL GadgetParentID(Gadget) ;Returns ParentID from gadget ID
    Protected ChildID =-1 
    If IsGadget(Gadget)
      ChildID = GadgetID(Gadget)
      
      While ChildID
        ChildID = GetParent(ChildID)
        If IsWindowID(ChildID)
          Break
        EndIf
      Wend  
      
      ProcedureReturn ChildID
    EndIf
  EndProcedure
  
  ProcedureDLL GadgetWindow(Gadget) ;Returns Top Parent WindowID from child Gadget
    Protected ParentID
    ParentID = GadgetParentID(Gadget)
    If IsWindowID(ParentID)
      ProcedureReturn IDWindow(ParentID)
    Else  
      While ParentID
        ParentID = GadgetParentID(ParentID)
        If IsWindowID(ParentID)
          ProcedureReturn IDWindow(ParentID)
        EndIf
      Wend
    EndIf
    ProcedureReturn -1
  EndProcedure
  
  ProcedureDLL ClipGadget( ) 
    CompilerIf #PB_Compiler_OS = #PB_OS_Windows
      Protected Height, Gadget
      PB_Object_EnumerateStart( PB_Gadget_Objects )
      If PB_Gadget_Objects
        While PB_Object_EnumerateNext(PB_Gadget_Objects, @Gadget )
          If GetWindowLongPtr_( GadgetID( Gadget ), #GWL_STYLE ) & #WS_CLIPSIBLINGS = #False 
            Height = GadgetHeight( Gadget ) 
            SetWindowLongPtr_( GadgetID( Gadget ), #GWL_STYLE, GetWindowLongPtr_( GadgetID( Gadget ), #GWL_STYLE )|#WS_CLIPSIBLINGS )
            ResizeGadget( Gadget, #PB_Ignore, #PB_Ignore, #PB_Ignore, Height )
          EndIf
          SetWindowPos_( GadgetID( Gadget ), 0, 0,0,0,0, #SWP_NOMOVE|#SWP_NOSIZE )
        Wend
        
        PB_Object_EnumerateAbort( PB_Gadget_Objects ) 
      EndIf
    CompilerEndIf
  EndProcedure
  
  ProcedureDLL ID_End()
    If MapSize( Props( ))
      DeleteMapElement( Props( ))
    EndIf 
  EndProcedure
  
  
;  
#PB_Align_None   =1<<0
#PB_Align_Left   =1<<1
#PB_Align_Top    =1<<2
#PB_Align_Right  =1<<3
#PB_Align_Bottom =1<<4
#PB_Align_Full   =1<<5
#PB_Align_Center =1<<6
 
 
CompilerIf Not Defined(AlignGadget, #PB_Function)
  EnableExplicit
  
  ProcedureDLL AlignGadget_Init()
    Structure AGRS
      Window.i     
      Parent.i
      ParentID.i
      Gadget.i     
      BindGadget.i
      Zazor.i
      
      X.i
      Y.i
      Left.i   
      Top.i         
      Right.i       
      Bottom.i   
      
      Lock_Left.b
      Lock_Top.b
      Lock_Right.b
      Lock_Bottom.b 
      
      Lock_Bind_Left.b
      Lock_Bind_Top.b
      Lock_Bind_Right.b
      Lock_Bind_Bottom.b 
    EndStructure     
    
    Global NewList AGRS.AGRS()
  EndProcedure
  
  CompilerIf Not Defined(AlignGadget, #PB_Function)
    AlignGadget_Init()       
  CompilerEndIf
  
  Procedure AlignGadgetResize(List Align.AGRS(),Window)
    Protected.i ParentID,Parent,Gadget,BindGadget
    Protected.i Width, Height, GadgetX,GadgetY,GadgetWidth,GadgetHeight
    If ListSize(Align())
      
      ForEach   Align()
        If Window = Align()\Window 
          Gadget = Align()\Gadget
          Parent = Align()\Parent
          ParentID = Align()\ParentID
          BindGadget = Align()\BindGadget
          
          If IsWindow(Parent) And WindowID(Parent) = ParentID
            Width = WindowWidth(Parent)
            Height = WindowHeight(Parent)
          Else
            Width = GadgetWidth(Parent)
            Height = GadgetHeight(Parent)
          EndIf  
          
          GadgetX = GadgetX(Gadget)
          GadgetY = GadgetY(Gadget)
          GadgetWidth = GadgetWidth(Gadget)
          GadgetHeight = GadgetHeight(Gadget)
          
          If Align()\Lock_left = #False   
            If Align()\Lock_Right ;К правому краю 
              GadgetX = (Width - Align()\Left)
            Else ;В серединe по вертикали
              GadgetX = Align()\X + ((Width - Align()\Left - Align()\X) /2)
            EndIf
          EndIf
          
          If Align()\Lock_Top  = #False 
            If Align()\Lock_Bottom ;К нижнему краю 
              GadgetY = (Height - Align()\Top)
            Else ;В серединe по горизонтали 
              GadgetY = Align()\Y + ((Height - Align()\Top - Align()\Y) /2)
            EndIf
          EndIf       
          
          If BindGadget =-1 ;Сосед не указан (BindGadget is none)
            If Align()\Lock_Left And Align()\Lock_Right  :GadgetWidth  = (Width  - GadgetX(Gadget)) - Align()\Right  :EndIf
            
            If Align()\Lock_Top  And Align()\Lock_Bottom :GadgetHeight = (Height - GadgetY(Gadget)) - Align()\Bottom :EndIf       
          Else
            If Align()\Lock_Bind_Left ;Сосед находится слева (BindGadget is left)
              GadgetX = (GadgetX(BindGadget) + GadgetWidth(BindGadget)) + Align()\Zazor
              GadgetWidth = Width - GadgetX - Align()\Right
            EndIf
            
            If Align()\Lock_Bind_Top ;Сосед находится сверху (BindGadget is top)
              GadgetY = (GadgetY(BindGadget) + GadgetHeight(BindGadget)) + Align()\Zazor
              GadgetHeight = Height - GadgetY - Align()\Bottom
            EndIf
            
            If Align()\Lock_Bind_Bottom ;Сосед находится снизу (BindGadget is bottom)
              GadgetHeight = GadgetY(BindGadget) - GadgetY(Gadget) -Align()\Zazor
            EndIf
            
            If Align()\Lock_Bind_Right ;Сосед находится справа (BindGadget is right)
              GadgetWidth = GadgetX(BindGadget) - GadgetX(Gadget) -Align()\Zazor
            EndIf
          EndIf
          
          ResizeGadget(Gadget, GadgetX, GadgetY, GadgetWidth, GadgetHeight)
        EndIf
      Next
      
      CompilerIf #PB_Compiler_OS = #PB_OS_Windows
        RedrawWindow_(WindowID(Window), 0, 0, #RDW_ALLCHILDREN|#RDW_UPDATENOW)
      CompilerEndIf
    EndIf
  EndProcedure
  
  Procedure AlignGadgetCallBack()
    ProcedureReturn AlignGadgetResize(AGRS(), EventWindow())
  EndProcedure
  
  Procedure AddGadget(List Align.AGRS(),ParentID,Window,Parent,Gadget,BindGadget,Flags,Zazor)
    Protected.i Left, Top, Right, Bottom, Width, Height 
    AddElement(Align())
    Align()\Window = Window
    Align()\Parent = Parent
    Align()\Gadget = Gadget
    Align()\ParentID = ParentID
    Align()\BindGadget = BindGadget 
    
    If IsWindowID(ParentID)
      Width = WindowWidth(Parent)
      Height = WindowHeight(Parent)
    ElseIf IsGadgetID(ParentID)
      Width = GadgetWidth(Parent)
      Height = GadgetHeight(Parent)
    EndIf
    
    If Flags & #PB_Align_Center
      Flags = #False
    EndIf
    If Flags & #PB_Align_Full
      Flags = #PB_Align_Left|#PB_Align_Top|#PB_Align_Right|#PB_Align_Bottom
    EndIf
    
    If Flags & #PB_Align_Left   :Align()\Lock_left   = #True
    Else
      Align()\X = GadgetX(Gadget)
      Align()\Left = Width - GadgetX(Gadget)
    EndIf  
    If Flags & #PB_Align_Top    :Align()\Lock_top    = #True
    Else
      Align()\Y = GadgetY(Gadget)
      Align()\Top = Height - GadgetY(Gadget)
    EndIf
    If Flags & #PB_Align_Right  :Align()\Lock_right  = #True
      If BindGadget <>-1
        If GadgetX(Gadget) < GadgetX(BindGadget)
          Align()\Lock_Bind_Right = #True
          Align()\Zazor=(GadgetY(BindGadget)-(GadgetY(Gadget) +GadgetHeight(Gadget)))-Zazor
        ElseIf GadgetX(Gadget) > GadgetX(BindGadget)
          Align()\Lock_Bind_Left = #True
          Align()\Zazor=(GadgetY(Gadget)-(GadgetY(BindGadget) +GadgetHeight(BindGadget)))-Zazor
        EndIf  
      EndIf
      Align()\Right = Width - (GadgetX(Gadget) + GadgetWidth(Gadget))
    EndIf
    If Flags & #PB_Align_Bottom :Align()\Lock_bottom = #True
      If BindGadget <>-1
        If GadgetY(Gadget) < GadgetY(BindGadget)
          Align()\Lock_Bind_Bottom = #True
          Align()\Zazor=GadgetY(BindGadget)-(GadgetY(Gadget) +GadgetHeight(Gadget))
        ElseIf GadgetY(Gadget) > GadgetY(BindGadget)
          Align()\Lock_Bind_Top = #True
          Align()\Zazor=GadgetY(Gadget)-(GadgetY(BindGadget) +GadgetHeight(BindGadget))
        EndIf 
      EndIf
      Align()\Bottom = Height - (GadgetY(Gadget) + GadgetHeight(Gadget))
    EndIf
  EndProcedure  
  
  ProcedureDLL AlignGadget3(Gadget, Flags, BindGadget =-1, Zazor = #False) ;
    If IsGadget(Gadget)
      Protected Window = GadgetWindow(Gadget)
      Protected ParentID = GadgetParentID(Gadget)
      Protected Parent
      
      If IsWindowID(ParentID)
        Parent = IDWindow(ParentID)
      ElseIf IsGadgetID(ParentID)
        Parent = IDGadget(ParentID)
      EndIf
      
      ;
      If IsWindow(Window)
        Static OldWindow =-1
        If OldWindow ! Window
          SmartWindowRefresh( Window, #True )
          BindEvent(#PB_Event_SizeWindow,@AlignGadgetCallBack(),Window) 
          OldWindow = Window
        EndIf
        
        AddGadget(AGRS(),ParentID,Window,Parent,Gadget,BindGadget,Flags, Zazor)
        AlignGadgetResize(AGRS(), Window)
      EndIf
    EndIf
  EndProcedure
  ProcedureDLL AlignGadget2(Gadget, Flags, BindGadget)
    ProcedureReturn AlignGadget3(Gadget, Flags, BindGadget, #False)
  EndProcedure
  ProcedureDLL AlignGadget(Gadget, Flags)
    ProcedureReturn AlignGadget2(Gadget, Flags, #PB_Any)
  EndProcedure
  Macro AlignGadget(Gadget, Flags, BindGadget =-1, Zazor = #False)
    AlignGadget3(Gadget, Flags, BindGadget, Zazor)
  EndMacro
  
  ProcedureDLL AlignGadget_End() 
    If ListSize(AGRS())
      FreeList(AGRS())
    EndIf
  EndProcedure

 DisableExplicit
CompilerEndIf


CompilerIf #PB_Compiler_IsMainFile
  Procedure Win()
    OpenWindow(1, 358, 178, 300, 275, " Test ResizeWindow (Module)",  #PB_Window_SizeGadget | #PB_Window_SystemMenu | #PB_Window_TitleBar | #PB_Window_ScreenCentered | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget)
    
    WindowBounds(1, 250, 200, #PB_Ignore, #PB_Ignore)
    
    ButtonGadget(30, 5, 5, 50, 25, "Resize -")
    ButtonGadget(31, 245, 5, 50, 25, "Resize +")
    ButtonGadget(32, 5, 240, 50, 25, "Reset")
    ListIconGadget(35, 55, 30, 190, 210, "Column 0", 56, #PB_ListIcon_GridLines) :AddGadgetColumn(35, 1, "Column 1", 130)
    ButtonGadget(34, 110, 245, 80, 25, "Center")
    
    ;EditorGadget(37, 5, 35, 45, 85)
    ;EditorGadget(38, 5, 150, 45, 90)
    EditorGadget(37, 250, 35, 45, 50)
    ButtonGadget(33, 250, 90, 45, 20, "Button")
    EditorGadget(48, 250, 115, 45, 45)
    
    ButtonGadget(43, 250, 165, 45, 20, "Button")
    EditorGadget(38, 250, 190, 45, 50)
    
    AlignGadget(31,#PB_Align_Top|#PB_Align_Right)
    AlignGadget(32,#PB_Align_Left|#PB_Align_Bottom)
    AlignGadget(35, #PB_Align_Full)
    AlignGadget(34, #PB_Align_Bottom)
    
    AlignGadget(33, #PB_Align_Right|#PB_Align_Top)
    AlignGadget(43, #PB_Align_Right|#PB_Align_Bottom)
    ;пропорционально
    
    ;AlignGadgetAnchor(37, 1 ,1,0,1,33)
    ;AlignGadgetAnchor(38, 1,1,0,1,33)
    AlignGadget(37, #PB_Align_Top|#PB_Align_Right|#PB_Align_Bottom,33)
    AlignGadget(48, #PB_Align_Top|#PB_Align_Right|#PB_Align_Bottom,33)
    AlignGadget(48, #PB_Align_Top|#PB_Align_Right|#PB_Align_Bottom,43)
    AlignGadget(38, #PB_Align_Top|#PB_Align_Right|#PB_Align_Bottom,43)
    
  EndProcedure      
  Procedure Win0()
    OpenWindow(1, 358, 178, 300, 275, " Test ResizeWindow (Module)",  #PB_Window_SizeGadget | #PB_Window_SystemMenu | #PB_Window_TitleBar | #PB_Window_ScreenCentered | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget)
    
    WindowBounds(1, 250, 200, #PB_Ignore, #PB_Ignore)
    
    ButtonGadget(30, 5, 5, 50, 25, "Resize -")
    ButtonGadget(31, 245, 5, 50, 25, "Resize +")
    ButtonGadget(32, 5, 240, 50, 25, "Reset")
    ListIconGadget(35, 55, 30, 190, 210, "Column 0", 56, #PB_ListIcon_GridLines) :AddGadgetColumn(35, 1, "Column 1", 130)
    ButtonGadget(34, 110, 245, 80, 25, "Center")
    
    ;EditorGadget(37, 5, 35, 45, 85)
    ;EditorGadget(38, 5, 150, 45, 90)
    EditorGadget(37, 250, 35, 45, 85)
    EditorGadget(38, 250, 150, 45, 90)
    ButtonGadget(33, 250, 125, 45, 20, "Button")
    
    AlignGadget(31,#PB_Align_Top|#PB_Align_Right)
    AlignGadget(32,#PB_Align_Left|#PB_Align_Bottom)
    AlignGadget(35, #PB_Align_Full)
    AlignGadget(34, #PB_Align_Bottom)
    
    AlignGadget(33, #PB_Align_Right)
    ;пропорционально
    
    ;AlignGadget(37, 1 ,1,0,1,33)
    ;AlignGadget(38, 1,1,0,1,33)
    AlignGadget(37, #PB_Align_Top|#PB_Align_Right|#PB_Align_Bottom,33)
    AlignGadget(38, #PB_Align_Top|#PB_Align_Right|#PB_Align_Bottom,33)
    
  EndProcedure      
  Procedure Win1(In = 0)
    OpenWindow(5,5,5,400,300,"",#PB_Window_SystemMenu|#PB_Window_SizeGadget)
    ;
    WindowBounds(5, 400, 300, #PB_Ignore, #PB_Ignore)
    
    If in =1
      ContainerGadget(0, 0, 0,400,300,#PB_Container_Flat )
    ElseIf in =2
      PanelGadget(0, 0, 0,400,300 ) :AddGadgetItem(0,-1,"Panel")
    ElseIf in =3
      ScrollAreaGadget(0, 0, 0,400,300,400,300,0,#PB_ScrollArea_Flat )
    EndIf
    
    If in
      AlignGadget(0,#PB_Align_Full)
    EndIf
    
    FrameGadget(9,135,140,130,25,"Dock = client") :AlignGadget(9,#PB_Align_Full)
    
    FrameGadget(20,5,140,130,25,"Dock = left") :AlignGadget(20,#PB_Align_Left)
    FrameGadget(1,135,5,130,25,"Dock = top") :AlignGadget(1,#PB_Align_Top)
    FrameGadget(2,265,140,130,25,"Dock = right") :AlignGadget(2,#PB_Align_Right)
    FrameGadget(3,135,270,130,25,"Dock = bottom") :AlignGadget(3,#PB_Align_Bottom)
    
    
    FrameGadget(10,5,140,130,25,"Dock = l_r") :AlignGadget(10,#PB_Align_Left|#PB_Align_Right)
    FrameGadget(11,135,5,130,25,"Dock = t_b") :AlignGadget(11,#PB_Align_Top|#PB_Align_Bottom)
    
    
    FrameGadget(8,5,5,130,25,"Dock = lefttop") :AlignGadget(8,#PB_Align_Left|#PB_Align_Top)
    FrameGadget(5,265,5,130,25,"Dock = righttop") :AlignGadget(5,#PB_Align_Right|#PB_Align_Top)
    FrameGadget(6,5,270,130,25,"Dock = leftbottom") :AlignGadget(6,#PB_Align_Left|#PB_Align_Bottom)
    FrameGadget(7,265,270,130,25,"Dock = rightbottom") :AlignGadget(7,#PB_Align_Right|#PB_Align_Bottom)
    
    FrameGadget(12,265,140,130,25,"Dock = t_r_b") :AlignGadget(12,#PB_Align_Top|#PB_Align_Right|#PB_Align_Bottom)
    FrameGadget(13,135,270,130,25,"Dock = l_b_r") :AlignGadget(13,#PB_Align_Left|#PB_Align_Bottom|#PB_Align_Right)
    
    FrameGadget(18,5,140,130,25,"Dock = t_l_b") :AlignGadget(18,#PB_Align_Top|#PB_Align_Left|#PB_Align_Bottom)
    FrameGadget(15,135,5,130,25,"Dock = l_t_r") :AlignGadget(15,#PB_Align_Left|#PB_Align_Top|#PB_Align_Right)
    
    FrameGadget(4,135,140,130,25,"Dock = center") :AlignGadget(4,#PB_Align_Center)
    
    If in
      CloseGadgetList()
    EndIf
  EndProcedure   
  Procedure Win2(In = 0)
    OpenWindow(5,5,5,400,300,"",#PB_Window_SystemMenu|#PB_Window_SizeGadget)
    ;
    WindowBounds(5, 400, 300, #PB_Ignore, #PB_Ignore)
    
    ButtonGadget(1,265,110,130,25,"Dock = top") :AlignGadget(1,#PB_Align_Right)
    ButtonGadget(2,265,140,130,25,"Dock = right") :AlignGadget(2,#PB_Align_Right)
    ButtonGadget(3,265,170,130,25,"Dock = left") :AlignGadget(3,#PB_Align_Right)
    
  EndProcedure   
  
  Win()
  Win1(1)
  
  ExitWindow = #False
  
  ClipGadget()
  
  Repeat
    Select WaitWindowEvent()
      Case #PB_Event_CloseWindow
        ExitWindow = #True
      Case #PB_Event_Gadget
        
        Select EventGadget()
          Case 30
            ResizeWindow(1, #PB_Ignore, #PB_Ignore, 250, 300)
          Case 31
            ResizeWindow(1, #PB_Ignore, #PB_Ignore, 350, 400)
          Case 32
            ResizeWindow(1, #PB_Ignore, #PB_Ignore, 300, 300)
        EndSelect
    EndSelect
  Until ExitWindow
  
  CloseWindow(1)
  
CompilerEndIf
Last edited by mestnyi on Wed Mar 16, 2016 8:29 pm, edited 1 time in total.
mestnyi
Addict
Addict
Posts: 1098
Joined: Mon Nov 25, 2013 6:41 am

Re: Align() & Dock()

Post by mestnyi »

Code: Select all

EnableExplicit
;*********************************
; Module:   RS_gadget
; Author:   mestnyi
; Compiler: PB 542 lts
;*********************************
;info: RS_gadget (Automatically Resize PureBasic gadgets)
;
; To use:
; - Include this source file.
; - Call RS_Register ONCE for EACH Gadget to be resized, specifying side locks.
; - Call RS_Resize in the event loop, specifying Parent ID.
;

;DECLARATIONS
DeclareModule RS_gadget
  EnableExplicit
  ;  
  #PB_Align_Avto   =1<<0
  #PB_Align_Left   =1<<1
  #PB_Align_Top    =1<<2
  #PB_Align_Right  =1<<3
  #PB_Align_Bottom =1<<4
  #PB_Align_Center =1<<5
  #PB_Align_Full   =1<<6
  
  #PB_Align_Left_Top = #PB_Align_Left|#PB_Align_Top
  #PB_Align_Left_Botton = #PB_Align_Left|#PB_Align_Bottom
  
  #PB_Align_Right_Top = #PB_Align_Right|#PB_Align_Top ; Привязка в право и верх
  #PB_Align_Right_Botton = #PB_Align_Right|#PB_Align_Bottom ; Привязка вправо и вниз
  
  #PB_Align_Top_Right = #PB_Align_Left|#PB_Align_Top|#PB_Align_Right
  #PB_Align_Botton_Right = #PB_Align_Left|#PB_Align_Bottom|#PB_Align_Right
  
  Declare RS_Resize()
  Declare RS_Init(RS_Window)
  Declare RS_Free(RS_Window)
  Declare RS_Event(*CallBack)
  Declare RS_UnRegister(RS_Gadget)
  Declare RS_ClipGadgets( ParentID )
  Declare RS_UseParentID(RS_ParentID)
  Declare RS_Register(RS_Gadget, RS_Flags, RS_gap_x = #False, RS_gap_y = #False)
EndDeclareModule

Module RS_Gadget
  Structure RS_Struct
    ParentID.i     
    Gadget.i     
    Parent.i
    Window.i
    
    X.i
    Y.i
    Width.i
    Height.i
    
    Top.i         
    Left.i   
    Right.i       
    Bottom.i   
    
    Dock.i
    Flags.i
  EndStructure 
  
  Global NewList CallBack()
  Global NewList RS_Parents.RS_Struct()
  Global NewList RS_Gadgets.RS_Struct()
  
  Macro EnableEnumerate
    CompilerIf #PB_Compiler_OS = #PB_OS_Windows
      Import ""
      CompilerElse
        ImportC ""
        CompilerEndIf
        PB_Object_EnumerateStart( PB_Objects )
        PB_Object_EnumerateNext( PB_Objects, *ID.Integer )
        PB_Object_EnumerateAbort( PB_Objects )
        
        PB_Object_Count( PB_Objects )
        
        PB_Window_Objects.i
        PB_Gadget_Objects.i
      EndImport
    EndMacro : EnableEnumerate
    
    Procedure RS_ClipGadgets( ParentID ) 
      CompilerIf #PB_Compiler_OS = #PB_OS_Windows
        Static II
        Protected WindowID = UseGadgetList(0)
        If ParentID
          Protected GadgetID
          Protected Dim EnumerateList.I(0)
          Protected Gadget = GetProp_( ParentID, "PB_ID" )
          
          ;         ; Фокус на гаджеты
          ;         #UIS_CLEAR = 2
          ;         #UISF_HIDEFOCUS = 1
          ;         #UISF_HIDEACCEL = 2
          
          ;Protected String$=Space(1024) :GetClassName_(ParentID, @String$,Len(String$)) : Debug String$
          ;RealGetWindowClass_(GadgetID(1), @pszType$, Len(pszType$))
          ;Define Null : SetWindowTheme_(GadgetID(Gadget), @Null, @Null)
          
          ;SendMessage_(ParentID, #WM_UPDATEUISTATE, ((#UISF_HIDEFOCUS|#UISF_HIDEACCEL)<<16) | #UIS_CLEAR, 0)
          
          If (GetWindowLongPtr_(ParentID, #GWL_STYLE) & #WS_CLIPCHILDREN) = #False
            SetWindowLongPtr_(ParentID, #GWL_STYLE, GetWindowLongPtr_(ParentID, #GWL_STYLE) | #WS_CLIPCHILDREN)
            SetWindowLongPtr_(ParentID, #GWL_EXSTYLE, GetWindowLongPtr_(ParentID, #GWL_EXSTYLE) | #WS_EX_COMPOSITED)
          EndIf
          
          If SendMessage_( ParentID, #TCM_GETITEMCOUNT, 0, 0)
            Protected I : For I = 0 To II : GadgetID = FindWindowEx_( ParentID, GadgetID, 0,0) 
              If (GetWindowLongPtr_(GadgetID, #GWL_STYLE) & #WS_CLIPCHILDREN) = #False
                SetWindowLongPtr_(GadgetID, #GWL_STYLE, GetWindowLongPtr_(GadgetID, #GWL_STYLE) | #WS_CLIPCHILDREN)
              EndIf
              If (GetWindowLongPtr_(ParentID, #GWL_STYLE) & #WS_CLIPCHILDREN) And 
                 (GetWindowLongPtr_(GadgetID, #GWL_EXSTYLE) & #WS_EX_TRANSPARENT) = #False
                SetWindowLongPtr_(GadgetID, #GWL_EXSTYLE, GetWindowLongPtr_(GadgetID, #GWL_EXSTYLE) | #WS_EX_TRANSPARENT)
              EndIf
              SetWindowLongPtr_( GadgetID, #GWL_STYLE, GetWindowLongPtr_( GadgetID, #GWL_STYLE ) | #WS_CLIPSIBLINGS )
            Next
            
            GadgetID = FindWindowEx_( GadgetID, 0,0,0 )
          Else
            If ( IsGadget( Gadget ) And GadgetID( Gadget ) = ParentID )
              Debug "ParentID Gadget "+Str(GetProp_( ParentID, "PB_ID" ))
              
              If FindWindowEx_( FindWindowEx_( ParentID, 0,0,0 ), 0,0,0 ) ; ScrollArea
                ParentID = FindWindowEx_( ParentID, 0,0,0 )
              EndIf
              ;ParentID = SendMessage_(ParentID, #LVM_GETHEADER, 0, 0)
              
              If (GetWindowLongPtr_(ParentID, #GWL_STYLE) & #WS_CLIPCHILDREN) = #False
                SetWindowLongPtr_(ParentID, #GWL_STYLE, GetWindowLongPtr_(ParentID, #GWL_STYLE) | #WS_CLIPCHILDREN)
              EndIf
              
              GadgetID = FindWindowEx_( ParentID, 0,0,0 )
            Else
              Debug "ParentID Window "+Str(GetProp_( ParentID, "PB_WindowID" ) - 1)
              
              SetWindowLongPtr_(ParentID, #GWL_STYLE, GetWindowLongPtr_(ParentID, #GWL_STYLE) &~ #WS_CLIPCHILDREN)
              SetWindowLongPtr_(ParentID, #GWL_EXSTYLE, GetWindowLongPtr_(ParentID, #GWL_EXSTYLE) &~ #WS_EX_COMPOSITED)
              
              GadgetID = FindWindowEx_( ParentID, 0,0,0 );ParentID 
            EndIf
          EndIf
          
          
          While GadgetID
            If GadgetID
              Gadget = GetProp_( GadgetID, "PB_ID" )
              If ( IsGadget( Gadget ) And GadgetID( Gadget ) = GadgetID )
                If GetWindowLongPtr_( GadgetID, #GWL_STYLE ) & #WS_CLIPSIBLINGS = #False 
                  Protected Height = GadgetHeight( Gadget ) 
                  SetWindowLongPtr_( GadgetID, #GWL_STYLE, GetWindowLongPtr_( GadgetID, #GWL_STYLE ) | #WS_CLIPSIBLINGS | #WS_CLIPCHILDREN )
                  ResizeGadget( Gadget, #PB_Ignore, #PB_Ignore, #PB_Ignore, Height )
                EndIf
                
                If (GetWindowLongPtr_(GetParent_(GadgetID), #GWL_STYLE) & #WS_CLIPCHILDREN)
                  Select GadgetType(Gadget)
                    Case #PB_GadgetType_Frame, #PB_GadgetType_Image
                      If (GetWindowLongPtr_(GadgetID, #GWL_STYLE) & #WS_EX_TRANSPARENT) = #False
                        SetWindowLongPtr_(GadgetID, #GWL_EXSTYLE, GetWindowLongPtr_(GadgetID, #GWL_EXSTYLE) | #WS_EX_TRANSPARENT)
                      EndIf
                  EndSelect
                EndIf
              EndIf
              
              ReDim EnumerateList( ArraySize( EnumerateList() ) + (1) ) : EnumerateList( ArraySize( EnumerateList() ) ) = GadgetID
            EndIf
            GadgetID = GetWindow_( GadgetID, #GW_HWNDNEXT )  
          Wend
          
          While ArraySize( EnumerateList() ) 
            If ArraySize( EnumerateList() )
              GadgetID = EnumerateList( ArraySize( EnumerateList() ) ) : ReDim EnumerateList( ArraySize( EnumerateList() ) - (1) )
              SetWindowPos_( GadgetID, #GW_HWNDLAST, 0,0,0,0, #SWP_NOMOVE|#SWP_NOSIZE )
            EndIf 
          Wend
          
          If SendMessage_( ParentID, #TCM_GETITEMCOUNT, 0, 0) : II + (1)
            If (SendMessage_( ParentID, #TCM_GETITEMCOUNT, 0, 0) = II) 
              II = #False
            Else
              RS_ClipGadgets( ParentID ) 
            EndIf
          EndIf
          
          FreeArray( EnumerateList() )
        Else
          If (GetWindowLongPtr_( WindowID, #GWL_EXSTYLE) & #WS_EX_COMPOSITED ) = #False
            SmartWindowRefresh(( GetProp_( WindowID, "PB_WindowID" ) - 1), #False)
            SetWindowLongPtr_( WindowID, #GWL_STYLE, GetWindowLongPtr_( WindowID, #GWL_STYLE) | #WS_CLIPCHILDREN)
            SetWindowLongPtr_( WindowID, #GWL_EXSTYLE, GetWindowLongPtr_( WindowID, #GWL_EXSTYLE ) | #WS_EX_COMPOSITED )
          EndIf
          
        EndIf
      CompilerEndIf
    EndProcedure
    
    ; RS_Resize - Resize all registered gadgets for the resizing window.
    ; Parameters: Parent ID (long).
    Procedure RS_Resize()
      Protected xOffset, yOffset
      Protected RS_x, RS_y, RS_w, RS_h, RS_Parent, RS_ParentID
      
      If ListSize(RS_Parents())
        PushListPosition(RS_Parents())
        ForEach RS_Parents()
          RS_Parent = RS_Parents()\Parent
          RS_ParentID = RS_Parents()\ParentID
          
          If (IsWindow(RS_Parent) And WindowID(RS_Parent) = RS_ParentID)
            RS_w = WindowWidth(RS_Parent)
            RS_h = WindowHeight(RS_Parent)
            xOffset = WindowX(RS_Parent, #PB_Window_InnerCoordinate)
            yOffset = WindowY(RS_Parent, #PB_Window_InnerCoordinate)
            
          ElseIf (IsGadget(RS_Parent) And GadgetID(RS_Parent) = RS_ParentID)
            If GadgetType(RS_Parent) = #PB_GadgetType_Panel
              Rs_w = GetGadgetAttribute(RS_Parent, #PB_Panel_ItemWidth)
              Rs_h = GetGadgetAttribute(RS_Parent, #PB_Panel_ItemHeight)
            Else
              CompilerIf #PB_Compiler_OS = #PB_OS_Windows
                Protected RECT.RECT : GetClientRect_(RS_ParentID,RECT.RECT)
                
                Rs_w = GadgetWidth(RS_Parent) - ((GadgetWidth(RS_Parent)-(RECT\right - RECT\left)) )
                Rs_h = GadgetHeight(RS_Parent) - ((GadgetHeight(RS_Parent)-(RECT\bottom - RECT\top)) ) 
              CompilerElse
                ; TODO
                RS_w = GadgetWidth(RS_Parent)
                RS_h = GadgetHeight(RS_Parent)
              CompilerEndIf 
            EndIf
            xOffset = GadgetX(RS_Parent, #PB_Gadget_WindowCoordinate)
            yOffset = GadgetY(RS_Parent, #PB_Gadget_WindowCoordinate)
          EndIf
          
          If ListSize(RS_gadgets()) And ((RS_Parents()\Width <> Rs_w) Or (RS_Parents()\Height <> Rs_h)) 
            CompilerIf #PB_Compiler_OS = #PB_OS_Windows
              SendMessage_(RS_ParentID, #WM_SETREDRAW, #False, 0)
            CompilerEndIf
            
            PushListPosition(RS_gadgets())
            ForEach RS_gadgets()
              If RS_gadgets()\ParentID = RS_ParentID
                
                If ((RS_gadgets()\Flags & #PB_Align_Left) = #PB_Align_Left)
                  If (((RS_gadgets()\Flags & #PB_Align_Right) = #PB_Align_Right) And (RS_Parents()\Width <> Rs_w)) ; По ширине (Flags = #PB_Align_Left | #PB_Align_Right)
                    ResizeGadget(RS_gadgets()\Gadget, #PB_Ignore, #PB_Ignore, ((RS_w - GadgetX(RS_gadgets()\Gadget)) - RS_gadgets()\Right), #PB_Ignore)
                  EndIf
                  
                Else
                  RS_x = (RS_w - RS_gadgets()\Left)
                  If Not ((RS_gadgets()\Flags & #PB_Align_Right) = #PB_Align_Right) 
                    RS_x = (RS_gadgets()\X + ((RS_x - RS_gadgets()\X) / 2)) ; Середина по вертикали
                  EndIf
                  ResizeGadget(RS_gadgets()\Gadget, RS_x, #PB_Ignore, #PB_Ignore, #PB_Ignore)
                  
                EndIf
                
                If ((RS_gadgets()\Flags & #PB_Align_Top) = #PB_Align_Top)
                  If (((RS_gadgets()\Flags & #PB_Align_Bottom) = #PB_Align_Bottom) And (RS_Parents()\Height <> Rs_h)) ; По высоте (Flags = #PB_Align_Top | #PB_Align_Bottom)
                    ResizeGadget(RS_gadgets()\Gadget, #PB_Ignore, #PB_Ignore, #PB_Ignore, ((RS_h - GadgetY(RS_gadgets()\Gadget)) - RS_gadgets()\Bottom))
                  EndIf       
                  
                Else
                  RS_y = (RS_h - RS_gadgets()\Top)
                  If Not ((RS_gadgets()\Flags & #PB_Align_Bottom) = #PB_Align_Bottom)
                    RS_y = (RS_gadgets()\Y + ((RS_y - RS_gadgets()\Y) / 2)) ; Середина по горизонтали
                  EndIf
                  ResizeGadget(RS_gadgets()\Gadget, #PB_Ignore, RS_y, #PB_Ignore, #PB_Ignore)
                  
                EndIf  
                
              EndIf
            Next
            PopListPosition(RS_gadgets())
            
            CompilerIf #PB_Compiler_OS = #PB_OS_Windows
              SendMessage_(RS_ParentID, #WM_SETREDRAW, #True, 0)                                 ;
              
              GetClientRect_(RS_ParentID, @Rect) 
              InvalidateRect_(RS_ParentID, Rect, #True)
              PushListPosition(RS_gadgets())
              ForEach RS_gadgets()
                If RS_gadgets()\ParentID = RS_ParentID
                  Select GadgetType(RS_gadgets()\Gadget)
                    Case #PB_GadgetType_Frame,
                         #PB_GadgetType_Image   
                    Default ; validate area of all 'good' Gadgets
                      GetWindowRect_(GadgetID(RS_gadgets()\Gadget), @Rect) ; get Gadget-Area
                      Rect\top - yOffset
                      Rect\left - xOffset
                      Rect\bottom - yOffset
                      Rect\right - xOffset
                      ValidateRect_(RS_ParentID, Rect) ; validate Gadget-Area
                  EndSelect
                EndIf
              Next
              PopListPosition(RS_gadgets())
              Protected ps.PAINTSTRUCT
              BeginPaint_(RS_ParentID, ps.PAINTSTRUCT)
              RedrawWindow_(RS_ParentID, #Null,#Null,#RDW_INVALIDATE|#RDW_ALLCHILDREN|#RDW_UPDATENOW)
              EndPaint_(RS_ParentID, ps.PAINTSTRUCT)
              
            CompilerEndIf
            
            RS_Parents()\Width = Rs_w 
            RS_Parents()\Height = Rs_h
          EndIf
        Next
        PopListPosition(RS_Parents())
        
        PushListPosition(CallBack())
        ForEach CallBack()
          CallFunctionFast(CallBack())
        Next
        PopListPosition(CallBack())
        
      EndIf
    EndProcedure
    
    Procedure RS_AvtoAlign(RS_ParentID, RS_w, RS_h)
      Protected RS_Flags, RS_Parent, RS_Gadget, RS_x, RS_y
      If ListSize(RS_gadgets())
        RS_Flags = RS_gadgets()\Flags
        RS_gadget = RS_gadgets()\Gadget
        RS_Parent = RS_gadgets()\Parent
        
        Protected RS_gap_x = GadgetX(RS_Gadget)
        Protected RS_gap_y = GadgetY(RS_Gadget)
        
        If (((RS_Flags & #PB_Align_Left) = #PB_Align_Left) And ((RS_Flags & #PB_Align_Top) = #PB_Align_Top)  ) And (((RS_Flags & #PB_Align_Right) = #PB_Align_Right) And ((RS_Flags & #PB_Align_Bottom) = #PB_Align_Bottom)  ) ; (RS_gadgets()\Lock_left And RS_gadgets()\Lock_top) And (RS_gadgets()\Lock_right And RS_gadgets()\Lock_bottom)
          ResizeGadget(RS_gadget, RS_gap_x, RS_gap_y, Rs_w-RS_gap_x*2, Rs_h-RS_gap_y*2)
        Else
          If ((RS_Flags & #PB_Align_Left) = #PB_Align_Left)
            If ((RS_Flags & #PB_Align_Right) = #PB_Align_Right)
              If ((RS_Flags & #PB_Align_Top) = #PB_Align_Top) Or (((RS_Flags & #PB_Align_Right) = #PB_Align_Right) And ((RS_Flags & #PB_Align_Bottom) = #PB_Align_Bottom)  ); RS_gadgets()\Lock_top Or (RS_gadgets()\Lock_right And RS_gadgets()\Lock_bottom)
                ResizeGadget(RS_gadget, (Rs_w - GadgetWidth(RS_gadget)) /2, #PB_Ignore, #PB_Ignore, #PB_Ignore)
              EndIf
              ResizeGadget(RS_gadget, #PB_Ignore, #PB_Ignore, (Rs_w - GadgetX(RS_gadget)) - (Rs_w - (GadgetX(RS_gadget) + GadgetWidth(RS_gadget))), #PB_Ignore)
            Else
              If ((RS_Flags & #PB_Align_Top) = #PB_Align_Top)
                ResizeGadget(RS_gadget, RS_gap_x, RS_gap_y, #PB_Ignore, #PB_Ignore)
              EndIf
            EndIf
          Else
            RS_x = (Rs_w - GadgetWidth(RS_gadget))-RS_gap_x
            If Not ((RS_Flags & #PB_Align_Right) = #PB_Align_Right)
              RS_x = GadgetX(RS_gadget) + ((RS_x - (GadgetX(RS_gadget) - RS_gap_x)) /2) ; Середина по вертикали
            EndIf
            ResizeGadget(RS_gadget, RS_x, #PB_Ignore, #PB_Ignore, #PB_Ignore)
            If ((RS_Flags & #PB_Align_Top) = #PB_Align_Top)
              ResizeGadget(RS_gadget, #PB_Ignore, RS_gap_y, #PB_Ignore, #PB_Ignore)
            EndIf
          EndIf
          
          If ((RS_Flags & #PB_Align_Top) = #PB_Align_Top)
            If ((RS_Flags & #PB_Align_Bottom) = #PB_Align_Bottom) 
              If ((RS_Flags & #PB_Align_Left) = #PB_Align_Left) Or (((RS_Flags & #PB_Align_Right) = #PB_Align_Right) And ((RS_Flags & #PB_Align_Bottom) = #PB_Align_Bottom)  ) ; RS_gadgets()\Lock_left Or (RS_gadgets()\Lock_bottom And RS_gadgets()\Lock_right)
                ResizeGadget(RS_gadget, #PB_Ignore, (Rs_h - GadgetHeight(RS_gadget)) /2, #PB_Ignore, #PB_Ignore)
              EndIf
              ResizeGadget(RS_gadget, #PB_Ignore, #PB_Ignore, #PB_Ignore, (Rs_h - GadgetY(RS_gadget)) - (Rs_h - (GadgetY(RS_gadget) + GadgetHeight(RS_gadget))))
            Else
              If ((RS_Flags & #PB_Align_Left) = #PB_Align_Left) 
                ResizeGadget(RS_gadget, RS_gap_x, RS_gap_y, #PB_Ignore, #PB_Ignore)
              EndIf
            EndIf       
          Else
            RS_y = (Rs_h - GadgetHeight(RS_gadget))-RS_gap_y
            If Not ((RS_Flags & #PB_Align_Bottom) = #PB_Align_Bottom)
              RS_y = (GadgetY(RS_gadget) + ((RS_y - (GadgetY(RS_gadget) - RS_gap_y)) /2)) ; Середина по горизонтали
            EndIf
            ResizeGadget(RS_gadget, #PB_Ignore, RS_y, #PB_Ignore, #PB_Ignore)
            If ((RS_Flags & #PB_Align_Left) = #PB_Align_Left) 
              ResizeGadget(RS_gadget, RS_gap_x, #PB_Ignore, #PB_Ignore, #PB_Ignore)
            EndIf
          EndIf       
        EndIf
      EndIf
      
    EndProcedure
    
    Procedure RS_AvtoDock(RS_ParentID, RS_w, RS_h)
      Protected Left,Top,Right,Bottom,Client
      Protected RS_Flags, RS_Parent, RS_Gadget, RS_x, RS_y
      Static RS_B_Gadget, RS_T_Gadget,RS_R_Gadget, RS_L_Gadget, Rs_gw, Rs_gh
      
      If ListSize(RS_gadgets())
        RS_Flags = RS_gadgets()\Flags
        RS_gadget = RS_gadgets()\Gadget
        RS_Parent = RS_gadgets()\Parent
        
        Protected RS_gap_x = GadgetX(RS_Gadget)
        Protected RS_gap_y = GadgetY(RS_Gadget)
        
        RS_gadgets()\Dock = RS_Flags
        
        PushListPosition(RS_Gadgets())
        ForEach RS_gadgets() 
          If RS_gadgets()\ParentID = RS_ParentID
            If RS_gadgets()\Dock & #PB_Align_Full = #PB_Align_Full 
              If RS_gadgets()\Dock & #PB_Align_Top = #PB_Align_Top  
                ResizeGadget(RS_gadgets()\Gadget, Left, Top, RS_w, #PB_Ignore) 
                Top + GadgetHeight(RS_gadgets()\Gadget) 
                RS_gadgets()\Flags = RS_gadgets()\Flags|#PB_Align_Left|#PB_Align_Right
              EndIf
              If RS_gadgets()\Dock & #PB_Align_Bottom = #PB_Align_Bottom  
                Bottom + GadgetHeight(RS_gadgets()\Gadget)  
                ResizeGadget(RS_gadgets()\Gadget, Left, RS_h-Bottom, RS_w-(Right+Left), #PB_Ignore) 
                RS_gadgets()\Flags = RS_gadgets()\Flags|#PB_Align_Left|#PB_Align_Right
              EndIf
            EndIf
          EndIf
        Next 
        PopListPosition(RS_Gadgets())
        
        PushListPosition(RS_Gadgets())
        ForEach RS_gadgets() 
          If RS_gadgets()\ParentID = RS_ParentID
            If RS_gadgets()\Dock & #PB_Align_Full = #PB_Align_Full 
              If RS_gadgets()\Dock & #PB_Align_Left = #PB_Align_Left
                ResizeGadget(RS_gadgets()\Gadget,Left,Top,#PB_Ignore,RS_h-(Top+Bottom)) 
                Left + GadgetWidth(RS_gadgets()\Gadget)  
                RS_gadgets()\Flags = RS_gadgets()\Flags|#PB_Align_Top|#PB_Align_Bottom
              EndIf
              If RS_gadgets()\Dock & #PB_Align_Right = #PB_Align_Right 
                Right + GadgetWidth(RS_gadgets()\Gadget)
                ResizeGadget(RS_gadgets()\Gadget,(RS_w-Right),Top,#PB_Ignore,RS_h-(Top+Bottom)) 
                RS_gadgets()\Flags = RS_gadgets()\Flags|#PB_Align_Top|#PB_Align_Bottom
              EndIf
            EndIf
          EndIf
        Next 
        PopListPosition(RS_Gadgets())
        
        PushListPosition(RS_Gadgets())
        ForEach RS_gadgets() 
          If RS_gadgets()\ParentID = RS_ParentID
            If RS_gadgets()\Dock &~ #PB_Align_Full &~ #PB_Align_Avto = #False
              Client + GadgetHeight(RS_gadgets()\Gadget)  
              ResizeGadget(RS_gadgets()\Gadget,(RS_gap_x+Left),(RS_gap_y+Top),((RS_w-(Right+Left))-RS_gap_x*2),((RS_h-(Top+Bottom))-RS_gap_y*2)) 
              RS_gadgets()\Flags = RS_gadgets()\Flags|#PB_Align_Left|#PB_Align_Right|#PB_Align_Top|#PB_Align_Bottom
            EndIf
          EndIf
        Next 
        PopListPosition(RS_Gadgets())
        
      EndIf
    EndProcedure
    
    ;PROCEDURES
    
    ; RS_Register - Register Gadget to be resized and how to resize.
    ; Specify #TRUE for each side of the Gadget you want to LOCK, else #FALSE.
    ; Parameters:  Window (long), Gadget (long), Left (boolean), Top (boolean), Right (boolean), Bottom (boolean).
    Procedure RS_Register(RS_Gadget, RS_Flags, RS_gap_x = #False, RS_gap_y = #False) ;
      Protected RS_x.i, RS_y.i, RS_w.i, RS_h.i, RS_ParentID
      
      If IsGadget(RS_Gadget)
        If ListSize(RS_Parents()) 
          If Not (GadgetX(RS_Gadget)+GadgetY(RS_Gadget))
            RS_Flags = RS_Flags | #PB_Align_Avto
          EndIf
          
          AddElement(RS_gadgets())
          RS_gadgets()\Flags = RS_Flags
          RS_gadgets()\Gadget = RS_Gadget
          RS_gadgets()\Parent = RS_Parents()\Parent
          RS_gadgets()\Window = RS_Parents()\Window
          RS_gadgets()\ParentID = RS_Parents()\ParentID
          RS_ParentID = RS_gadgets()\ParentID
          
          If IsWindow(RS_gadgets()\Parent) And WindowID(RS_gadgets()\Parent) = RS_gadgets()\ParentID
            Rs_w = WindowWidth(RS_gadgets()\Parent)
            Rs_h = WindowHeight(RS_gadgets()\Parent)
          ElseIf IsGadget(RS_gadgets()\Parent) And GadgetID(RS_gadgets()\Parent) = RS_gadgets()\ParentID
            
            If GadgetType(RS_gadgets()\Parent) = #PB_GadgetType_Panel
              Rs_w = GetGadgetAttribute(RS_gadgets()\Parent, #PB_Panel_ItemWidth)
              Rs_h = GetGadgetAttribute(RS_gadgets()\Parent, #PB_Panel_ItemHeight)
            ElseIf GadgetType(RS_gadgets()\Parent) = #PB_GadgetType_ScrollArea
              Rs_w = GetGadgetAttribute(RS_gadgets()\Parent, #PB_ScrollArea_InnerWidth)
              Rs_h = GetGadgetAttribute(RS_gadgets()\Parent, #PB_ScrollArea_InnerHeight)
            Else
              CompilerIf #PB_Compiler_OS = #PB_OS_Windows
                Protected RECT.RECT : GetClientRect_(RS_gadgets()\ParentID,RECT.RECT)
                
                Rs_w = GadgetWidth(RS_gadgets()\Parent) - ((GadgetWidth(RS_gadgets()\Parent)-(RECT\right - RECT\left)) )
                Rs_h = GadgetHeight(RS_gadgets()\Parent) - ((GadgetHeight(RS_gadgets()\Parent)-(RECT\bottom - RECT\top)) ) 
              CompilerElse
                ; TODO
                RS_w = GadgetWidth(RS_gadgets()\Parent)
                RS_h = GadgetHeight(RS_gadgets()\Parent)
              CompilerEndIf 
            EndIf
          EndIf
          
          If (RS_Flags & #PB_Align_Avto) = #PB_Align_Avto
            If (RS_Flags & #PB_Align_Full) = #PB_Align_Full
              RS_AvtoDock(RS_gadgets()\ParentID, Rs_w, Rs_h)
            Else
              RS_AvtoAlign(RS_gadgets()\ParentID, Rs_w, Rs_h)
            EndIf
          Else
            If (RS_Flags & #PB_Align_Full) = #PB_Align_Full
              RS_gadgets()\Flags = RS_gadgets()\Flags |#PB_Align_Left|#PB_Align_Right|#PB_Align_Top|#PB_Align_Bottom 
            EndIf
          EndIf
          
          RS_x = GadgetX(RS_Gadget)
          RS_y = GadgetY(RS_Gadget)
          
          ; нужен 
          RS_Flags = RS_gadgets()\Flags
          
          
          If ((RS_Flags & #PB_Align_Left) = #PB_Align_Left)
            If ((RS_Flags & #PB_Align_Right) = #PB_Align_Right) 
              RS_gadgets()\Right = (Rs_w - (RS_x + GadgetWidth(RS_Gadget))) 
            EndIf
          Else
            RS_gadgets()\X = RS_x
            RS_gadgets()\Left = (Rs_w - RS_x)
          EndIf
          If ((RS_Flags & #PB_Align_Top) = #PB_Align_Top)
            If ((RS_Flags & #PB_Align_Bottom) = #PB_Align_Bottom) 
              RS_gadgets()\Bottom = (Rs_h - (RS_y + GadgetHeight(RS_Gadget)))
            EndIf
          Else
            RS_gadgets()\Y = RS_y
            RS_gadgets()\Top = (Rs_h - RS_y)
          EndIf
          
          ;
          If (RS_Flags & #PB_Align_Avto) = #PB_Align_Avto
            If (RS_Flags & #PB_Align_Full) = #PB_Align_Full
              PushListPosition(RS_Gadgets())
              ForEach RS_gadgets() 
                If RS_gadgets()\ParentID = RS_ParentID
                  If (RS_gadgets()\Flags & #PB_Align_Full) = #PB_Align_Full
                    If ((RS_gadgets()\Flags & #PB_Align_Bottom) = #PB_Align_Bottom) 
                      RS_gadgets()\Bottom = (Rs_h - (GadgetY(RS_gadgets()\Gadget) + GadgetHeight(RS_gadgets()\Gadget)))
                    EndIf
                  EndIf
                EndIf
              Next 
              PopListPosition(RS_Gadgets())
            EndIf
          EndIf
          
        EndIf
      EndIf
      
    EndProcedure
    
    ; RS_Use - Use resizing Parent
    Procedure RS_UseParentID(RS_ParentID)
      Protected ParentWindow =- 1, Window =- 1, Gadget =- 1
      
      If ListSize(RS_Parents())
        PushListPosition(RS_Parents())
        ForEach RS_Parents()
          If RS_Parents()\Window = RS_Parents()\Parent
            ParentWindow = RS_Parents()\Window
          EndIf
        Next
        PopListPosition(RS_Parents())
      EndIf
      
      AddElement(RS_Parents())
      RS_Parents()\Window =- 1
      RS_Parents()\Parent =- 1
      RS_Parents()\Gadget =- 1
      
      
      PB_Object_EnumerateStart( PB_Window_Objects )
      If PB_Window_Objects
        While PB_Object_EnumerateNext(PB_Window_Objects, @Window )
          If WindowID( Window ) = RS_ParentID
            RS_Parents()\Window = Window
            RS_Parents()\Parent = Window
            RS_Parents()\ParentID = RS_ParentID
            RS_Parents()\Width = WindowWidth( Window ) 
            RS_Parents()\Height = WindowHeight( Window )
            ProcedureReturn Window
          EndIf  
        Wend
        
        PB_Object_EnumerateAbort( PB_Window_Objects ) 
      EndIf
      
      PB_Object_EnumerateStart( PB_Gadget_Objects )
      If PB_Gadget_Objects
        While PB_Object_EnumerateNext(PB_Gadget_Objects, @Gadget )
          If GadgetID( Gadget ) = RS_ParentID
            RS_Parents()\Window = ParentWindow
            RS_Parents()\Gadget = Gadget
            RS_Parents()\Parent = Gadget
            RS_Parents()\ParentID = RS_ParentID
            RS_Parents()\Width = GadgetWidth( Gadget ) 
            RS_Parents()\Height = GadgetHeight( Gadget )
            
            CompilerIf #PB_Compiler_OS = #PB_OS_Windows
;               Protected I, GadgetID
;               If GadgetType( Gadget ) = #PB_GadgetType_Panel 
;                 For I = 0 To SendMessage_(RS_ParentID, #TCM_GETCURSEL, 0, 0) 
;                   GadgetID = FindWindowEx_( RS_ParentID, GadgetID, 0,0) 
;                 Next
;               EndIf
;               RS_Parents()\ParentID = GadgetID
              
              If (GetWindowLongPtr_(RS_ParentID, #GWL_STYLE) & #WS_CLIPCHILDREN) = #False
                SetWindowLongPtr_(RS_ParentID, #GWL_STYLE, GetWindowLongPtr_(RS_ParentID, #GWL_STYLE) | #WS_CLIPCHILDREN)
                SetWindowLongPtr_(RS_ParentID, #GWL_EXSTYLE, GetWindowLongPtr_(RS_ParentID, #GWL_EXSTYLE) | #WS_EX_COMPOSITED)
              EndIf
            CompilerEndIf
            
            ProcedureReturn Gadget
          EndIf  
        Wend
        
        PB_Object_EnumerateAbort( PB_Gadget_Objects ) 
      EndIf
      
      ProcedureReturn #PB_Any
    EndProcedure
    
    Procedure RS_Resize_Thread(Time)
      Repeat
        RS_Resize()
        Delay(Time)
      ForEver
    EndProcedure
    
    ; RS_Init - Init resizing
    Procedure RS_Init(RS_window)
      If IsWindow(RS_window)
        BindEvent(#PB_Event_SizeWindow, @RS_Resize(), RS_window) 
        ;AddWindowTimer(RS_window,#PB_Ignore,2) : BindEvent(#PB_Event_Timer,@RS_Resize(),RS_window)
        ;Static CreateThread : If IsThread(CreateThread) : KillThread(CreateThread) : EndIf : CreateThread = CreateThread(@RS_Resize_Thread(), 1)
        
        RS_UseParentID(WindowID(RS_window))
      EndIf
    EndProcedure
    
    ;
    Procedure RS_Event(*CallBack)
      AddElement(CallBack()) : CallBack() = *CallBack
    EndProcedure
    
    ; RS_Unregister - Unregister Gadget from resizing
    Procedure RS_UnRegister( RS_gadget )
      
      ForEach RS_gadgets()
        If (RS_gadgets()\Gadget = RS_gadget)
          DeleteElement(RS_gadgets())
        EndIf
      Next 
      
    EndProcedure
    
    ; RS_Free - Free init resizing
    Procedure RS_Free( RS_window )
      
      ForEach RS_gadgets()
        If (RS_gadgets()\Window = RS_window)
          DeleteElement(RS_gadgets())
        EndIf
      Next 
      
    EndProcedure
  EndModule
  
  
  
  UseModule RS_gadget
  
  ;- >->- Demonstration example
  ;{  Init()
  Enumeration 900;
    #StrName     ;         0;
    #StrExt      ;            1;
    #StrOutput   ;         2;
    #IcoName     ;         3;
    #IcoExt      ;         4;
    #IcoOut      ;         5;
    #IcoSearch   ;
    #IcoReplace  ;
    
    #WinID;
    #Frm01;
    #Frm02;
    #Frm03;
    #TxtInfo;
    #TxtName;
    #TxtExt ;
    #TxtOutput;
    #StrInfo  ;
    #TxtSearch;
    #TxtReplace;
    #FlgOutCase;
    #FlgNameOnly;
    #FlgCase    ;
    #FlgAll     ;
    #FlgDate    ;
    #List       ;
    #ButRename  ;
    #ButClose   ;
    #ButProfile ;
    #ButFilter  ;
    #ButExtras  ;
    #TxtWriteName;
    #TxtWriteExt ;
    #StrSearch   ;
    #StrReplace  ;
    #StrWriteName;      \;
    #StrWriteExt ;      /;
    #KeySearch   ;
    #KeyReplace  ;
    #IconOk      ;
  EndEnumeration ;
  
  Enumeration
    #WriteUnchanged;
    #WriteAllLower ;
    #WriteWordUpper;
    #WriteAllUpper ;
  EndEnumeration   ;
  
  Enumeration;
    #ListOldName;
    #ListNewName;
    #ListSize   ;
    #ListDate   ;
    #ListState  ;
  EndEnumeration;
  
  #WinW=720
  #WinH=552
  #WinZ=400
  
  Procedure Events()                                        ;
                                                            ;
    Protected x,y,n,m                                       ;
    If EventWindow()=#WinID                                 ;
      x=WindowWidth(#WinID)                                 ;
      
      n=(x-#WinW)/5                                                              ;
      y=n<<1  
      
      SetGadgetItemAttribute(#List,#PB_Ignore,#PB_ListIcon_ColumnWidth,210+y,#ListOldName);
      SetGadgetItemAttribute(#List,#PB_Ignore,#PB_ListIcon_ColumnWidth,210+y,#ListNewName);
      SetGadgetItemAttribute(#List,#PB_Ignore,#PB_ListIcon_ColumnWidth,78+n,#ListState)   ;
      
    EndIf                                                                                       ;
                                                                                                ;
  EndProcedure                                                                                  ;
  Procedure Init()                                                                              ;
    Protected i                                                                                 ;
    Protected makro                                                                             ;
    Protected flag                                                                              ;
    Protected s.s                                                                               ;
    
    CatchImage(#IconOk,?IconOk);
                               ;
    OpenWindow(#WinID,0,0,#WinW,#WinH,"",#PB_Window_ScreenCentered|#PB_Window_Invisible|#PB_Window_SizeGadget|#PB_Window_MaximizeGadget|#PB_Window_MinimizeGadget);
    WindowBounds(#WinID,#WinW,#WinZ,#PB_Default,#PB_Default)                                                                                                      ;
    Define SS_CENTERIMAGE
    CompilerIf #PB_Compiler_OS = #PB_OS_Windows
      SS_CENTERIMAGE = #SS_CENTERIMAGE
    CompilerEndIf
    
    ;
    FrameGadget(#Frm01,10,10,560,72,"Reguläre Ausdrücke")                                                                                                                                                       ;
    TextGadget(#TxtName,20,30,60,20,"Datei&name:",SS_CENTERIMAGE)                                                                                                                                               ;
    ComboBoxGadget(#StrName,95,29,207,22,#PB_ComboBox_Editable)                                                                                                                                                 ;
    ImageGadget(#IcoName,307,32,16,16,ImageID(#IconOk))                                                                                                                                                         ;
    TextGadget(#TxtExt,345,30,75,20,"&Erweiterung:",SS_CENTERIMAGE)                                                                                                                                             ;
    ComboBoxGadget(#StrExt,410,29,125,22,#PB_ComboBox_Editable)                                                                                                                                                 ;
    ImageGadget(#IcoExt,540,32,16,16,ImageID(#IconOk))                                                                                                                                                          ;
    TextGadget(#TxtOutput,20,55,60,20,"Ändern &in:",SS_CENTERIMAGE)                                                                                                                                             ;
    ComboBoxGadget(#StrOutput,95,54,207,22,#PB_ComboBox_Editable)                                                                                                                                               ;
    ImageGadget(#IcoOut,307,57,16,16,ImageID(#IconOk))                                                                                                                                                          ;
    CheckBoxGadget(#FlgOutCase,346,55,175,22," &Groß-/Kleinschreibung beachten")                                                                                                                                ;
                                                                                                                                                                                                                ;
    FrameGadget(#Frm02,10,90,560,72,"Suchen und Ersetzen")                                                                                                                                                      ;
    TextGadget(#TxtSearch,20,110,100,20,"&Anfangs:",SS_CENTERIMAGE)                                                                                                                                             ;
    ComboBoxGadget(#StrSearch,95,109,207,22,#PB_ComboBox_Editable)                                                                                                                                              ;
    ImageGadget(#IcoSearch,307,112,16,16,ImageID(#IconOk))                                                                                                                                                      ;
                                                                                                                                                                                                                ;
    TextGadget(#TxtReplace,20,135,100,20,"A&bschließend:",SS_CENTERIMAGE)                                                                                                                                       ;
    ComboBoxGadget(#StrReplace,95,134,207,22,#PB_ComboBox_Editable)                                                                                                                                             ;
    ImageGadget(#IcoReplace,307,137,16,16,ImageID(#IconOk))                                                                                                                                                     ;
                                                                                                                                                                                                                ;
    CheckBoxGadget(#FlgNameOnly,346,104,180,18," Nur den Dateina&men verändern")                                                                                                                                ;
    CheckBoxGadget(#FlgCase,346,122,175,18," Groß-/&Kleinschreibung beachten")                                                                                                                                  ;
    CheckBoxGadget(#FlgAll,346,140,175,18," Alle &Vorkommen ersetzen")                                                                                                                                          ;
                                                                                                                                                                                                                ;
    FrameGadget(#Frm03,10,168,560,48,"Erweitert")                                                                                                                                                               ;
    TextGadget(#TxtWriteName,20,188,75,20,"Schreib&weise:",SS_CENTERIMAGE)                                                                                                                                      ;
    ComboBoxGadget(#StrWriteName,95,188,100,20)                                                                                                                                                                 ;
    TextGadget(#TxtWriteExt,240,188,70,20,"Erwei&terung:",SS_CENTERIMAGE)                                                                                                                                       ;
    ComboBoxGadget(#StrWriteExt,310,188,100,20)                                                                                                                                                                 ;
    CheckBoxGadget(#FlgDate,455,188,76,18," Datei&datum aktualisieren")                                                                                                                                         ; 140;
                                                                                                                                                                                                                ;
    For i=0 To 1                                                                                                                                                                                                ;
      AddGadgetItem(#StrWriteName+i,#WriteUnchanged,"Unverändert")                                                                                                                                              ;
      AddGadgetItem(#StrWriteName+i,#WriteAllLower,"Alles klein")                                                                                                                                               ;
      AddGadgetItem(#StrWriteName+i,#WriteWordUpper,"Wortanfänge groß")                                                                                                                                         ;
      AddGadgetItem(#StrWriteName+i,#WriteAllUpper,"Alles groß")                                                                                                                                                ;
    Next i                                                                                                                                                                                                      ;
                                                                                                                                                                                                                ;
    ListIconGadget(#List,10,230,694,285," ·",20,#PB_ListIcon_FullRowSelect|#PB_ListIcon_GridLines)                                                                                                              ;
                                                                                                                                                                                                                ;SetGadgetColor(#List,#PB_ListIcon_GridLines,#Black);
    AddGadgetColumn(#List,#ListOldName,"Alter Dateiname",210)                                                                                                                                                   ;
    AddGadgetColumn(#List,#ListNewName,"Neuer Dateiname",210)                                                                                                                                                   ;
    AddGadgetColumn(#List,#ListSize,"Größe",52)                                                                                                                                                                 ;
    AddGadgetColumn(#List,#ListDate,"Datum",102)                                                                                                                                                                ;
    AddGadgetColumn(#List,#ListState,"Status",78)                                                                                                                                                               ;
    EnableGadgetDrop(#List,#PB_Drop_Files,#PB_Drag_Move|#PB_Drag_Copy)                                                                                                                                          ;
                                                                                                                                                                                                                ;
    CompilerIf #PB_Compiler_OS = #PB_OS_Windows
      Global lvm.LV_COLUMN                                                                                                                                                                                        ;
      lvm\mask=#LVCF_FMT                                                                                                                                                                                          ;
      lvm\fmt=#LVCFMT_CENTER                                                                                                                                                                                      ;
      SendMessage_(GadgetID(#List),#LVM_SETCOLUMN,#ListDate,@lvm)                                                                                                                                                 ;
      lvm\mask=#LVCF_FMT                                                                                                                                                                                          ;
      lvm\fmt=#LVCFMT_RIGHT                                                                                                                                                                                       ;
      SendMessage_(GadgetID(#List),#LVM_SETCOLUMN,#ListSize,@lvm)                                                                                                                                                 ;
    CompilerEndIf
    ;
    FrameGadget(#TxtInfo,0,530,#WinW,2,"",#PB_Frame_Single)                                                                                                                                                     ;
    TextGadget(#StrInfo,0,534,999,16,"StrInfo",SS_CENTERIMAGE)                                                                                                                                                  ;
                                                                                                                                                                                                                ;
    ButtonGadget(#ButRename,585,15,115,30,"&Umbenennen",#PB_Button_Default)                                                                                                                                     ;
    ButtonGadget(#ButClose,585,53,115,30,"S&chließen")                                                                                                                                                          ;
    ButtonGadget(#ButProfile,585,95,115,30,"&Profile")                                                                                                                                                          ;
    ImageGadget(#ButExtras,585,132,115,30,ImageID(#IconOk))                                                                                                                                                     ; "S&onderfunktionen")                                                                                                                                                       ;
    ButtonGadget(#ButFilter,585,180,115,30,"Ergebnisliste &filtern",#PB_Button_Toggle)                                                                                                                          ;
    
    RS_Init(#WinID)
    
    ;RS_UseParentID(WindowID(#WinID))
    
    RS_Register(#Frm01,#PB_Align_Left_Top|#PB_Align_Right_Top)
    RS_Register(#StrName,#PB_Align_Left_Top|#PB_Align_Right_Top)
    RS_Register(#IcoName,#PB_Align_Right_Top)
    RS_Register(#TxtExt,#PB_Align_Right_Top)
    
    RS_Register(#StrExt,#PB_Align_Right_Top)
    RS_Register(#IcoExt,#PB_Align_Right_Top)
    
    RS_Register(#StrOutput,#PB_Align_Left_Top|#PB_Align_Right_Top)
    RS_Register(#IcoOut,#PB_Align_Right_Top)
    RS_Register(#FlgOutCase,#PB_Align_Right_Top)
    
    
    RS_Register(#Frm02,#PB_Align_Left_Top|#PB_Align_Right_Top)
    RS_Register(#StrSearch,#PB_Align_Left_Top|#PB_Align_Right_Top)
    RS_Register(#IcoSearch,#PB_Align_Right_Top)
    
    RS_Register(#StrReplace,#PB_Align_Left_Top|#PB_Align_Right_Top)
    RS_Register(#IcoReplace,#PB_Align_Right_Top)
    
    RS_Register(#FlgNameOnly,#PB_Align_Right_Top)
    RS_Register(#FlgCase,#PB_Align_Right_Top)
    RS_Register(#FlgAll,#PB_Align_Right_Top)
    
    RS_Register(#Frm03,#PB_Align_Left_Top|#PB_Align_Right_Top)
    
    RS_Register(#StrWriteName,#PB_Align_Left_Top|#PB_Align_Right_Top)                                                                                                                                   ;
    RS_Register(#TxtWriteExt,#PB_Align_Right_Top)                                                                                                                                                       ;
    RS_Register(#StrWriteExt,#PB_Align_Right_Top)                                                                                                                                                       ;
    RS_Register(#FlgDate,#PB_Align_Right_Top)
    
    
    
    
    RS_Register(#List,#PB_Align_Full)
    
    RS_Register(#ButRename,#PB_Align_Right_Top)
    RS_Register(#ButClose,#PB_Align_Right_Top)
    RS_Register(#ButProfile,#PB_Align_Right_Top)
    RS_Register(#ButExtras,#PB_Align_Right_Top)
    RS_Register(#ButFilter,#PB_Align_Right_Top)
    
    RS_Register(#TxtInfo,#PB_Align_Left_Botton|#PB_Align_Right_Botton)
    RS_Register(#StrInfo,#PB_Align_Left_Botton|#PB_Align_Right_Botton)
    ;
    RS_Event(@Events())                                                                                                                               ;
    
    
    RS_ClipGadgets( WindowID(#WinID) )
    ;
    SetActiveWindow(#WinID)                                                                                                                                                         ;
    SetActiveGadget(#StrName)                                                                                                                                                       ;
    HideWindow(#WinID,#Null)                                                                                                                                                        ;
    
    DataSection;
      IconOk:  ; 1406 Bytes;
      Data.q $1010000100010000,$568000800010000,$28000000160000,$20000000100000,$800010000;
      Data.q $1000000,$100000000000000,$3737000001000000,$CB4A0089B5320037,$FFFF00B5E15D009F;
      Data.q $FF,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
      Data.q 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
      Data.q 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,$505000000000000,$505050505050505,$505050505050505;
      Data.q $505050505050505,$505050505050505,$505050500050505,$505050505050505,$505050001000505          ;
      Data.q $505050505050505,$505000102020005,$505050505050505,$500010202020200,$5050505050505            ;
      Data.q $1020300020202,$300050505050505,$102030005000202,$5050505050500,$203000505050003              ;
      Data.q $505050505050001,$300050505050500,$505050505000102,$5050505050505,$505050500010203            ;
      Data.q $505050505050505,$505050001020300,$505050505050505,$505050500030005,$505050505050505          ;
      Data.q $505050505000505,$505050505050505,$505050505050505,$505050505050505,$FFFF050505050505         ;
      Data.q $FFFB0000FFFF0000,$FFE00000FFF10000,$3F8000007FC00000,$F8E00001F040000,$83FF000007DF0000      ;
      Data.q $E3FF0000C1FF0000,$FFFF0000F7FF0000,$FFFF0000                                                 ;
    EndDataSection                                                                                         ;
                                                                                                           ;
  EndProcedure                                                                                             ;
                                                                                                           ;}                                                                                                        ;
                                                                                                           ;{  Demo()
  Procedure ScrollAreaEvents()
    If IsGadget(100) And GetGadgetAttribute(100, #PB_ScrollArea_InnerWidth)<>GadgetWidth(100) Or 
       GetGadgetAttribute(100, #PB_ScrollArea_InnerHeight)<>GadgetHeight(100) 
      
      
      SetGadgetAttribute(100, #PB_ScrollArea_InnerWidth, GadgetWidth(100))
      SetGadgetAttribute(100, #PB_ScrollArea_InnerHeight, GadgetHeight(100) )
    EndIf
  EndProcedure
  
  Procedure Demos(RS_window, In = 0, Mode = 0 )
    OpenWindow(RS_window,#PB_Ignore,#PB_Ignore,400,300,"",#PB_Window_SystemMenu|#PB_Window_SizeGadget)
    WindowBounds(RS_window, WindowWidth(RS_window), WindowHeight(RS_window), #PB_Ignore, #PB_Ignore)
    
    RS_Init(RS_window)
    
    ;Macro ButtonGadget : FrameGadget : EndMacro
    
    If in =1
      ContainerGadget(RS_window, 5, 5,WindowWidth(RS_window)-10,WindowHeight(RS_window)-10,#PB_Container_Flat )
    ElseIf in =2
      PanelGadget(RS_window, 5, 5,WindowWidth(RS_window)-10,WindowHeight(RS_window)-10 ) :AddGadgetItem(RS_window,-1,"Panel1")
    ElseIf in =3
      ScrollAreaGadget(RS_window, 5, 5,WindowWidth(RS_window)-10,WindowHeight(RS_window)-10,400,300,0,#PB_ScrollArea_Flat )
      BindEvent(#PB_Event_SizeWindow, @ScrollAreaEvents(), RS_window)                                                                                                                               ;
    ElseIf in =4
      FrameGadget(RS_window, 5, 5,WindowWidth(RS_window)-10,WindowHeight(RS_window)-10,"Frame",#PB_Frame_Flat )
    EndIf
    
    If in
      RS_Register(RS_window,#PB_Align_Full)
      RS_UseParentID(GadgetID(RS_window))
      ;RS_UnRegister(RS_window)
    EndIf
    
    If Mode = 0
      ; Align Ok
      If in = 1
        SetWindowTitle(RS_window, "Demo align gadgets in container")
      ElseIf in = 2
        SetWindowTitle(RS_window, "Demo align gadgets in Panel")
      ElseIf in = 3
        SetWindowTitle(RS_window, "Demo align gadgets in ScrollArea")
      Else
        SetWindowTitle(RS_window, "Demo align gadgets in window")
      EndIf
      
      ButtonGadget(RS_window+1, 0, 0,130,25,"left_center "+Str(RS_window+1))   :RS_Register(RS_window+1, #PB_Align_Left  |#PB_Align_Center)
      ButtonGadget(RS_window+2, 0, 0,130,25,"top_center "+Str(RS_window+2))    :RS_Register(RS_window+2, #PB_Align_Top   |#PB_Align_Center)
      ButtonGadget(RS_window+3, 0, 0,130,25,"right_center "+Str(RS_window+3))  :RS_Register(RS_window+3, #PB_Align_Right |#PB_Align_Center)
      ButtonGadget(RS_window+4, 0, 0,130,25,"bottom_center "+Str(RS_window+4)) :RS_Register(RS_window+4, #PB_Align_Bottom|#PB_Align_Center)
      ButtonGadget(RS_window+5, 0, 0,130,25,"center "+Str(RS_window+5))        :RS_Register(RS_window+5, #PB_Align_Center)
      
      ButtonGadget(RS_window+6, 0, 0,130,25,"left_top "+Str(RS_window+6))      :RS_Register(RS_window+6, #PB_Align_Left  |#PB_Align_Top)
      ButtonGadget(RS_window+7, 0, 0,130,25,"right_top "+Str(RS_window+7))     :RS_Register(RS_window+7, #PB_Align_Right |#PB_Align_Top)
      ButtonGadget(RS_window+8, 0, 0,130,25,"right_bottom "+Str(RS_window+8))  :RS_Register(RS_window+8, #PB_Align_Right |#PB_Align_Bottom)
      ButtonGadget(RS_window+9, 0, 0,130,25,"left_bottom "+Str(RS_window+9))   :RS_Register(RS_window+9, #PB_Align_Left  |#PB_Align_Bottom)
      
    Else
      ; Dock
      If in = 1
        SetWindowTitle(RS_window, "Demo dock gadgets in container")
      ElseIf in = 2
        SetWindowTitle(RS_window, "Demo dock gadgets in Panel")
      ElseIf in = 3
        SetWindowTitle(RS_window, "Demo dock gadgets in ScrollArea")
      Else
        SetWindowTitle(RS_window, "Demo dock gadgets in window")
      EndIf
      
      ButtonGadget(RS_window+1, 0, 0,130,25,"left_full "+Str(RS_window+1))   :RS_Register(RS_window+1, #PB_Align_Left  |#PB_Align_Full)
      ButtonGadget(RS_window+3, 0, 0,130,25,"right_full "+Str(RS_window+3))  :RS_Register(RS_window+3, #PB_Align_Right |#PB_Align_Full)
      ButtonGadget(RS_window+2, 0, 0,130,15,"top_full "+Str(RS_window+2))    :RS_Register(RS_window+2, #PB_Align_Top   |#PB_Align_Full)
      ButtonGadget(RS_window+4, 0, 0,130,25,"bottom_full "+Str(RS_window+4)) :RS_Register(RS_window+4, #PB_Align_Bottom|#PB_Align_Full)
      ButtonGadget(RS_window+14, 0, 0,130,35,"14bottom_full "+Str(RS_window+14)) :RS_Register(RS_window+14, #PB_Align_Bottom|#PB_Align_Full)
      ButtonGadget(RS_window+5, 0, 0,130,25,"full")        :RS_Register(RS_window+5, #PB_Align_Full)
      
    EndIf
    
    
    
    If in
      If in < 4 
        If in = 2
          AddGadgetItem(RS_window,-1,"Panel2")
          ;ListIconGadget(RS_window+15,0,0,0,0," ·",20,#PB_ListIcon_FullRowSelect|#PB_ListIcon_GridLines) :RS_Register(RS_window+15, #PB_Align_Right|#PB_Align_Bottom|#PB_Align_Center)
        EndIf
        CloseGadgetList() ; ContainerGadget
        RS_ClipGadgets(GadgetID(RS_window))
      EndIf
    Else
      RS_ClipGadgets(UseGadgetList(0));
    EndIf
    
   ; BindEvent(#PB_Event_SizeWindow, @ScrollAreaEvents(), RS_window)                                                                                                                               ;
    
  EndProcedure   
  
    Demos(0,0)
    Demos(30,0,1)
    Demos(60,1)
    Demos(90,1,1)
    Demos(120,2)
    Demos(150,2,1)
    Demos(180,3)
    Demos(210,3,1)
;   
;   Init()
  
  Repeat
    
    Select WaitWindowEvent() 
      Case #PB_Event_CloseWindow
        If WindowID(EventWindow()) = UseGadgetList(0)
          End
        Else
          CloseWindow(EventWindow())
          RS_Free(EventWindow())
        EndIf
    EndSelect
    
  ForEver
  UnuseModule RS_gadget
  
  
Post Reply