Adaptive gadget location

Just starting out? Need help? Post your questions and find answers here.
SergeyA
Posts: 4
Joined: Mon May 12, 2014 3:23 pm

Adaptive gadget location

Post by SergeyA »

How to make an adaptive arrangement of gadgets in a dialog?

Code: Select all

Enumeration Window
  #Form
EndEnumeration

Enumeration Xml
  #Xml
EndEnumeration

Enumeration Dialog
  #Dialog
EndEnumeration


Define Xml.s

Xml + "<window id='#PB_Any' name='dialog1' text='Dialog example' flags='#PB_Window_BorderLess'>" +
Xml + "    <vbox>" +
Xml + "        <option name='option1' text='Enter your credit card:' group='1'/>" +
Xml + "        <string name='string'/>" +
Xml + "        <option name='option2' text='Use paypal account' group='1'/>" +
Xml + "        <option name='option3' text='Use wiretransfert' group='1'/>" +
Xml + "        <hbox>" +
Xml + "            <button name='ok' text='Continue'/>" +
Xml + "            <button name='cancel' text='Cancel'/>" +
Xml + "        </hbox>" +
Xml + "    </vbox>" +
Xml + "</window>"


Procedure SizeHandler()
  Select EventWindow()
    Case #Form
      If IsDialog(#Dialog)
        ResizeWindow(DialogWindow(#Dialog), #PB_Ignore, #PB_Ignore, WindowWidth(#Form), WindowHeight(#Form))
      EndIf
  EndSelect
EndProcedure

If OpenWindow(#Form, 0, 0, 0, 0, "Demo", #PB_Window_Background)
  BindEvent(#PB_Event_SizeWindow, @SizeHandler())
  If ParseXML(#Xml, Xml)
    If (XMLStatus(#Xml) = #PB_XML_Success)
      If CreateDialog(#Dialog)
        If OpenXMLDialog(#Dialog, #Xml, "dialog1", 0, 0, 0, 0, WindowID(#Form))
          Option3 = DialogGadget(#Dialog, "option3")
          SetGadgetState(Option3, #True)
        EndIf
      EndIf
    EndIf
  EndIf 
EndIf
SergeyA
Posts: 4
Joined: Mon May 12, 2014 3:23 pm

Re: Adaptive gadget location

Post by SergeyA »

Solved through crutches

Code: Select all

DeclareModule App
  Declare Run()
EndDeclareModule

Module App
  
  Enumeration Window
    #Form
  EndEnumeration

  Enumeration Xml
    #Xml
  EndEnumeration

  Enumeration Dialog
    #Dialog
  EndEnumeration

  Procedure SizeWindowHandler()
    Select EventWindow()
      Case #Form
        If IsDialog(#Dialog)
          ResizeWindow(DialogWindow(#Dialog), #PB_Ignore, #PB_Ignore, WindowWidth(#Form), WindowHeight(#Form))
          PostEvent(#PB_Event_SizeWindow, DialogWindow(#Dialog), 0)
        EndIf
    EndSelect
  EndProcedure
  
  Procedure Run()
    
    Define Xml.s

    Xml + "<window id='#PB_Any' name='dialog1' text='Dialog example' flags='#PB_Window_BorderLess'>" +
    Xml + "    <hbox>" +
    Xml + "        <empty/>" + 
    Xml + "        <vbox>" + 
    Xml + "            <empty/>" + 
    Xml + "            <button name='ok' text='Continue'/>" +
    Xml + "            <empty/>" + 
    Xml + "        </vbox>" + 
    Xml + "        <empty/>" + 
    Xml + "    </hbox>" +
    Xml + "</window>"
    
    If OpenWindow(#Form, 0, 0, 0, 0, "Demo", #PB_Window_Background)
      BindEvent(#PB_Event_SizeWindow, @SizeWindowHandler())
      If ParseXML(#Xml, Xml)
        If (XMLStatus(#Xml) = #PB_XML_Success)
          If CreateDialog(#Dialog)
            If OpenXMLDialog(#Dialog, #Xml, "dialog1", 0, 0, 0, 0, WindowID(#Form))
              PostEvent(#PB_Event_SizeWindow, #Form, 0)
              SetGadgetState(DialogGadget(#Dialog, "option3"), #True)
            EndIf
          EndIf
        EndIf
      EndIf 
    EndIf
  EndProcedure
  
EndModule

App::Run()
Post Reply