Share your advanced knowledge/code with the community.
Peter
 
Posts: 409
Joined: Mon Feb 24, 2014 10:17 pm

Extending OpenXmlDialog() with own Attributes

by Peter Thu Oct 05, 2017 11:50 am

Hello,

here is a little suggestion how to extend the OpenXmlDialog-Functionality with own Xml-Attributes:

Code: Select all
EnableExplicit

Procedure ProcessGadgets(Dialog, Window, XmlNode)
 
  Protected ID.s
  Protected Name.s
  Protected Style.s
  Protected Class.s
 
  Protected oGadget
 
  Protected Counter
  Protected CssName.s
  Protected CssValue.s
 
  Protected ChildNode = ChildXMLNode(XmlNode)
 
  While ChildNode <> 0
   
    ; Debug GetXMLNodeName(ChildNode)
   
    If ExamineXMLAttributes(ChildNode)
     
      ID    = ""
      Name  = ""
      Style = ""
      oGadget = 0
     
      While NextXMLAttribute(ChildNode)
       
        ; Debug XMLAttributeName(ChildNode) + "=" + Chr(34) + XMLAttributeValue(ChildNode) + Chr(34) + " "
       
        Select LCase(XMLAttributeName(ChildNode))
          Case "id"    :  ID    = XMLAttributeValue(ChildNode)
          Case "name"  :  Name  = XMLAttributeValue(ChildNode)
          Case "style" :  Style = XMLAttributeValue(ChildNode)
          Case "class" :  Class = XMLAttributeValue(ChildNode)
        EndSelect
       
        If Name <> ""
          oGadget = GadgetID(DialogGadget(Dialog, Name))
        EndIf
       
        If ID <> ""
          If Left(ID, 1) = "#"
            oGadget = GadgetID(GetRuntimeInteger(ID))
          Else
            oGadget = GadgetID(Val(ID))
          EndIf
        EndIf
       
        If oGadget
          If Style <> ""
            For Counter = 1 To CountString(Style, ";") + 1
              CssName  = StringField(StringField(Style, Counter, ";"), 1, ":")
              CssValue = StringField(StringField(Style, Counter, ";"), 2, ":")
              ! $(v_ogadget.div).css(v_cssname, v_cssvalue);
            Next
          EndIf
          If Class <> ""
            ! $(v_ogadget.div).addClass(v_class);
          EndIf
        EndIf

      Wend
    EndIf
   
    If XMLChildCount(ChildNode)
      ProcessGadgets(Dialog, Window, ChildNode)
    EndIf
   
    ChildNode = NextXMLNode(ChildNode)
   
  Wend
 
EndProcedure

Procedure OpenXMLDialog2(Dialog, Xml, Name.s, x, y, Width, Height, ParentID)
  Protected Result = OpenXMLDialog(Dialog, Xml, Name.s, x, y, Width, Height, ParentID)
  If Result
    ProcessGadgets(Dialog, DialogWindow(Dialog), MainXMLNode(Xml))
  EndIf 
  ProcedureReturn Result
EndProcedure

Macro OpenXMLDialog(Dialog, Xml, Name, x=0, y=0, Width=0, Height=0, ParentID=0)
  OpenXMLDialog2(Dialog, Xml, Name, x, y, Width, Height, ParentID)
EndMacro

; ###############
; # Example:
; ###############

Runtime Enumeration
  #bigb = 3
EndEnumeration


! $('<style type="text/css">.myTestClass {font-size:36px;color:red}</style>').appendTo($('head'));



Define XML.s = "<window id='#PB_Any' name='test' text='Dialog example' minwidth='auto' minheight='auto' flags='#PB_Window_ScreenCentered'>" +
               " <vbox>" +
               "  <button id='0' name='smallbutton1' text='Small black button' style='font-family:Arial;font-size:10;color:black' />" +
               "  <button id='1' name='smallbutton2' text='Small blue button' style='font-family:Times New Roman;font-size:10;color:blue' />" +
               "  <button name='bigbutton1' text='Big green button' style='font-family:Arial;font-size:36px;color:green' />" +
               "  <button id='#bigb' name='bigbutton2' text='Big red button' class='myTestClass' />" +
               " </vbox>" +
               "</window>"

#Dialog = 0
#Xml    = 0

If ParseXML(#Xml, XML) And XMLStatus(#Xml) = #PB_XML_Success
  If CreateDialog(#Dialog) And OpenXMLDialog(#Dialog, #Xml, "test")
    RefreshDialog(#Dialog) ; important!
  Else
    Debug "Dialog error: " + DialogError(#Dialog)
  EndIf
EndIf


As you can see you can use style- and class-Attributes to customize the appearance of a dialog after its creation.

Image

Greetings ... Peter
Return to Tricks 'n' Tips

Who is online

Users browsing this forum: No registered users and 1 guest