OpenXmlDialog() mit eigenen Attributen erweitern

Hier könnt ihr alle Fragen zu SpiderBasic austauschen.
Benutzeravatar
Kiffi
Beiträge: 10621
Registriert: 08.09.2004 08:21
Wohnort: Amphibios 9

OpenXmlDialog() mit eigenen Attributen erweitern

Beitrag von Kiffi »

Hello,

hier ist ein kleiner Vorschlag, wie man OpenXmlDialog() mit eigenen Attributen erweitern kann:

Code: Alles auswählen

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

; ###############
; # Beispiel:
; ###############

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
Wie Ihr sehen könnt, kann man beispielsweise Style- und Class-Attribute verwenden, um das Aussehen eines Dialogs nach seiner Erstellung zu verändern.

Bild

(danke an edel für die Hilfe!)

Grüße ... Peter
Hygge