Cross-Platform: Short Functions Collection

Share your advanced PureBasic knowledge/code with the community.
User avatar
mk-soft
Always Here
Always Here
Posts: 5335
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Cross-Platform: Short Functions Collection

Post by mk-soft »

IsGadgetEditable by Shardik and mk-soft

Code: Select all

;-TOP

; IsGadgetEditable by shardik, mk-soft; v1.01.0; create 12.06.2021; All OS

Procedure IsGadgetEditable(Gadget)
  
  CompilerSelect #PB_Compiler_OS
    CompilerCase #PB_OS_Linux
      CompilerIf Subsystem("QT")
        ProcedureReturn Bool(qtscript("gadget(" + Gadget + ").readOnly") <> "true")
        
      CompilerElse
        ProcedureReturn gtk_editable_get_editable_(GadgetID(Gadget))
        
      CompilerEndIf
      
    CompilerCase #PB_OS_MacOS
      ProcedureReturn CocoaMessage(0, GadgetID(Gadget), "isEditable")
      
    CompilerCase #PB_OS_Windows
      ProcedureReturn Bool(GetWindowLongPtr_(GadgetID(gadg), #GWL_STYLE) & #ES_READONLY = 0)
      
  CompilerEndSelect
  
EndProcedure

; ****

Enumeration
  #first
  #second
  #third
  #fourth
  #last
  
  #button
EndEnumeration

OpenWindow(0,200,200,300,175,"IsGadgetEditable",#PB_Window_SystemMenu)

StringGadget(#first,10,10,280,20,"one")
StringGadget(#second,10,35,280,20,"two")
StringGadget(#third,10,60,280,20,"three",#PB_String_ReadOnly)
StringGadget(#fourth,10,85,280,20,"four")
StringGadget(#last,10,115,280,20,"five")

ButtonGadget(#button,10,140,280,25,"Clear all except 'three'")

Repeat
  ev=WaitWindowEvent()
  If ev=#PB_Event_Gadget And EventGadget()=#button
    For gad=#first To #last
      If IsGadgetEditable(gad)
        SetGadgetText(gad, "")
      EndIf  
    Next
  EndIf
Until ev=#PB_Event_CloseWindow
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
mk-soft
Always Here
Always Here
Posts: 5335
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Cross-Platform: Short Functions Collection

Post by mk-soft »

IsGadgetVisible by mk-soft

Code: Select all

;-TOP

; IsGadgetVisible by mk-soft; v1.02.0; create 05.06.2021; update 12.06.2021; All OS

CompilerIf #PB_Compiler_OS = #PB_OS_Linux
  ImportC ""
    gtk_widget_is_visible(widget)
  EndImport
CompilerEndIf

Procedure IsGadgetVisible(Gadget)
  
  CompilerSelect #PB_Compiler_OS
    CompilerCase #PB_OS_Windows
      ProcedureReturn IsWindowVisible_(GadgetID(Gadget))
      
    CompilerCase #PB_OS_MacOS
      ProcedureReturn Bool(Not CocoaMessage(0, GadgetID(Gadget), "isHidden"))
      
    CompilerCase #PB_OS_Linux
      CompilerIf Subsystem("qt")
        ProcedureReturn Bool(qtscript("gadget(" + Gadget + ").visible") = "true")
        
      CompilerElse
        ProcedureReturn gtk_widget_is_visible(GadgetID(Gadget))
        
      CompilerEndIf
      
  CompilerEndSelect
  
EndProcedure

; ****

Enumeration Windows
  #Main
EndEnumeration

Enumeration Gadgets
  #Text
EndEnumeration

Enumeration Status
  #MainStatusBar
EndEnumeration

Procedure Main()
  
  #MainStyle = #PB_Window_SystemMenu | #PB_Window_MaximizeGadget | #PB_Window_MinimizeGadget
  
  If OpenWindow(#Main, #PB_Ignore, #PB_Ignore, 400, 300, "IsGadgetVisible" , #MainStyle)
    
    TextGadget(#Text, 10, 10, 380, 25, "Hello World!")
    
    HideGadget(#Text, #True)
    r1 = IsGadgetVisible(#Text)
    Debug "Visible = " + r1
    
    HideGadget(#Text, #False)
    r1 = IsGadgetVisible(#Text)
    Debug "Visible = " + r1
     
    Repeat
      Select WaitWindowEvent()
        Case #PB_Event_CloseWindow
          Break
      EndSelect
    ForEver
    
  EndIf
  
EndProcedure : Main()
Last edited by mk-soft on Sat Jun 12, 2021 8:53 pm, edited 1 time in total.
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
Shardik
Addict
Addict
Posts: 1989
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Re: Cross-Platform: Short Functions Collection

Post by Shardik »

I have added these examples to my list of now 64 links to cross-platform API examples.
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5342
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Cross-Platform: Short Functions Collection

Post by Kwai chang caine »

Don't know "IsGadgetEditable " :shock:
Thanks for sharing 8)
ImageThe happiness is a road...
Not a destination
Post Reply