XML Dialog, <option> not correctly working on MacOS

Just starting out? Need help? Post your questions and find answers here.
User avatar
Kukulkan
Addict
Addict
Posts: 1396
Joined: Mon Jun 06, 2005 2:35 pm
Location: germany
Contact:

XML Dialog, <option> not correctly working on MacOS

Post by Kukulkan »

Try this code on both Windows and MacOS. On Windows it works fine, on MacOS it is not usable:

Code: Select all

CompilerIf #PB_Compiler_Unicode
  #XmlEncoding = #PB_UTF8
CompilerElse
  #XmlEncoding = #PB_Ascii
CompilerEndIf

#Dialog = 0
#Xml = 0

XML$ = "<window id='#PB_Any' name='test' text='Gridbox' minwidth='auto' minheight='auto' flags='#PB_Window_ScreenCentered | #PB_Window_SystemMenu | #PB_Window_SizeGadget'>" +
       "    <gridbox columns='1'>" +
       "          <option name='opt1' text='Option 1' />" +
       "          <string name='strTest' minwidth='450' />" +
       "          <option name='opt2' text='Option 2' />" +
       "          <option name='opt3' text='Option 3' />" +
       "    </gridbox>" +
       "  </window>"

If CatchXML(#Xml, @XML$, StringByteLength(XML$), 0, #XmlEncoding) And XMLStatus(#Xml) = #PB_XML_Success
 
  If CreateDialog(#Dialog) And OpenXMLDialog(#Dialog, #Xml, "test")
    
    SetGadgetState(DialogGadget(#Dialog, "opt1"), 1); select opt1 by default
    
    Repeat
      Event = WaitWindowEvent()
      EventType = EventType()
      If Event = #PB_Event_Gadget
        Gadget = EventGadget()
        
        ;{ Handle Option Group because PB does not...
        If Gadget = DialogGadget(#Dialog, "opt1")
          SetGadgetState(DialogGadget(#Dialog, "opt2"), 0)
          SetGadgetState(DialogGadget(#Dialog, "opt3"), 0)
          SetActiveGadget(DialogGadget(#Dialog, "strTest"))
        EndIf
        If Gadget = DialogGadget(#Dialog, "opt2")
          SetGadgetState(DialogGadget(#Dialog, "opt1"), 0)
          SetGadgetState(DialogGadget(#Dialog, "opt3"), 0)
        EndIf
        If Gadget = DialogGadget(#Dialog, "opt3")
          SetGadgetState(DialogGadget(#Dialog, "opt1"), 0)
          SetGadgetState(DialogGadget(#Dialog, "opt2"), 0)
        EndIf
        ;}
      EndIf
    Until Event = #PB_Event_CloseWindow
   
  Else 
    Debug "Dialog error: " + DialogError(#Dialog)
  EndIf
Else
  Debug "XML error: " + XMLError(#Xml) + " (Line: " + XMLErrorLine(#Xml) + ")"
EndIf
What am I doing wrong?

[EDIT]I forgot to mention that I need a quick solution to this :-( [/EDIT]

Kukulkan
User avatar
Shardik
Addict
Addict
Posts: 2058
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Re: XML Dialog, <option> not correctly working on MacOS

Post by Shardik »

Kukulkan wrote:Try this code on both Windows and MacOS. On Windows it works fine, on MacOS it is not usable:
I can confirm the bug on MacOS X 10.6.8 (Snow Leopard): "Option 2" and "Option 3" are not selectable although "Option 1" is deselected (but the focus ring still remains around the circle of "Option 1" !).

But please take a look into my following workaround which works without problems on Windows 7 SP1 x64 with PB 5.22 x86 and x64 and on MacOS X 10.6.8 with PB 5.22 x86 and x64. I have added SetActiveGadget() for OptionGadgets 2 and 3 and always even a 3rd SetGadgetState(OptionGadget, 1) for the modified OptionGadget. For OptionGadget "opt2" it's further absolutely necessary to use the SetGadgetState(DialogGadget(#Dialog, "opt2"), 1) as the last of the SetGadgetState() commands because otherwise the OptionGadget on MacOS will be selected with a focus ring but the dot in the circle will be missing...

Code: Select all

CompilerIf #PB_Compiler_Unicode
  #XmlEncoding = #PB_UTF8
CompilerElse
  #XmlEncoding = #PB_Ascii
CompilerEndIf

#Dialog = 0
#Xml = 0

XML$ = "<window id='#PB_Any' name='test' text='Gridbox' minwidth='auto' minheight='auto' flags='#PB_Window_ScreenCentered | #PB_Window_SystemMenu | #PB_Window_SizeGadget'>" +
       "    <gridbox columns='1'>" +
       "          <option name='opt1' text='Option 1' />" +
       "          <string name='strTest' minwidth='450' />" +
       "          <option name='opt2' text='Option 2' />" +
       "          <option name='opt3' text='Option 3' />" +
       "    </gridbox>" +
       "  </window>"

If CatchXML(#Xml, @XML$, StringByteLength(XML$), 0, #XmlEncoding) And XMLStatus(#Xml) = #PB_XML_Success
 
  If CreateDialog(#Dialog) And OpenXMLDialog(#Dialog, #Xml, "test")
   
    SetGadgetState(DialogGadget(#Dialog, "opt1"), 1); select opt1 by default
    SetActiveGadget(DialogGadget(#Dialog, "strTest"))
   
    Repeat
      Event = WaitWindowEvent()
      EventType = EventType()
      If Event = #PB_Event_Gadget
        Gadget = EventGadget()

        ;{ Handle Option Group because PB does not...
        Select Gadget
          Case DialogGadget(#Dialog, "opt1")
            DisableGadget(DialogGadget(#Dialog, "strTest"), 0)
            SetGadgetState(DialogGadget(#Dialog, "opt1"), 1)
            SetGadgetState(DialogGadget(#Dialog, "opt2"), 0)
            SetGadgetState(DialogGadget(#Dialog, "opt3"), 0)
            SetActiveGadget(DialogGadget(#Dialog, "strTest"))
          Case DialogGadget(#Dialog, "opt2")
            SetGadgetState(DialogGadget(#Dialog, "opt1"), 0)
            SetGadgetState(DialogGadget(#Dialog, "opt3"), 0)
            SetGadgetState(DialogGadget(#Dialog, "opt2"), 1)
            SetActiveGadget(Gadget)
          Case DialogGadget(#Dialog, "opt3")
            SetGadgetState(DialogGadget(#Dialog, "opt1"), 0)
            SetGadgetState(DialogGadget(#Dialog, "opt2"), 0)
            SetGadgetState(DialogGadget(#Dialog, "opt3"), 1)
            SetActiveGadget(Gadget)
        EndSelect
        ;}
      EndIf
    Until Event = #PB_Event_CloseWindow
   
  Else
    Debug "Dialog error: " + DialogError(#Dialog)
  EndIf
Else
  Debug "XML error: " + XMLError(#Xml) + " (Line: " + XMLErrorLine(#Xml) + ")"
EndIf
User avatar
Kukulkan
Addict
Addict
Posts: 1396
Joined: Mon Jun 06, 2005 2:35 pm
Location: germany
Contact:

Re: XML Dialog, <option> not correctly working on MacOS

Post by Kukulkan »

Hello Shardik,

thank you. Indeed, setting the status of the selected option to 1 is the key (must be done at last).

I'm still waiting for a grouping option in XML dialog feature because the option elements are not easy to use. Fred already confirmed that this is needed, but he did not add it until now :-(

Thanks,

Kukulkan
Post Reply