It is currently Thu Dec 12, 2019 9:51 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 17 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: GTK3 SetGadgetColor Workaround (Teamwork / Release)
PostPosted: Wed Dec 26, 2018 4:27 pm 
Offline
Addict
Addict
User avatar

Joined: Fri May 12, 2006 6:51 pm
Posts: 2061
Location: Germany
The fact that GTK3 is constantly changing something doesn't make things easy for app developers or Fred either.
Link to Bug-Report: viewtopic.php?f=23&t=71967

Let's see how it works with the GtkCssProviders.
Since I'm not so fit with GTK and CSS, we can switch everything to CSS together.

Thanks to ccode and Oma for help.

Here my current status of the code

Update v1.01

Update v1.02
- Fixed some colors
- Added SetWindowColor. Thanks to Shardik

Update v1.03
- Bugfix memory leak -> gtk_container_get_children_(...) returns a newly-allocated list

Code:
;-TOP

; Workaround Linux GTK3 GadgetColor
; by      : mk-soft, ccode, Oma, Shardik
; Version : v1.03
; Create  : 25.12.2018
; Update  : 06.01.2019

; -----------------------------------------------------------------------------

;- Begin Module GtkGadgetColor

DeclareModule GtkGadgetColor
 
  Declare.s GtkGetVersionString()
 
  Declare GtkSetWindowColor(Window, Color)
  Declare GtkSetGadgetColor(Gadget, ColorType, Color)
 
  Declare SetSelectedColor(Color)
  Declare SetSelectionColor(Color)
 
  Macro SetWindowColor(Window, Color)
    GTKSetWindowColor(Window, Color)
  EndMacro
 
  Macro SetGadgetColor(Gadget, ColorType, Color)
    GtkSetGadgetColor(Gadget, ColorType, Color)
  EndMacro
 
EndDeclareModule

Module GtkGadgetColor
 
  EnableExplicit
 
  ;- Imports
  ImportC ""
    ;
    gtk_get_major_version()
    gtk_get_minor_version()
    gtk_get_micro_version()
    ;
    gtk_widget_override_color(*handle, state, color)
    gtk_widget_override_background_color(*handle, state, color)
    ;
    gtk_widget_get_style_context(*Widget.GtkWidget)
    gtk_css_provider_new()
    gtk_css_provider_load_from_data(*CSSProvider, CSSData.p-utf8, Length, *Error.GError)
    gtk_style_context_add_provider(*CSSContext, *CSSProvider, Priority)
    gtk_style_context_remove_provider(*CSSContext, *CSSProvider)
    ;
    gtk_widget_get_screen(*Widget.GtkWidget)
    gtk_style_context_add_provider_for_screen(*CSSContext, *CSSProvider, Priority)
    gtk_style_context_remove_provider_for_screen(*CSSContext, *CSSProvider)
    ;
    gtk_style_context_add_class(*CSSContext, ClassName.p-utf8)
    gtk_style_context_list_classes(*CSSContext)
   
    gtk_viewport_get_view_window(*Viewport)
  EndImport
 
  ;- Constants
  #GTK_STATE_FLAG_NORMAL       = 0
  #GTK_STATE_FLAG_ACTIVE       = 1 << 0
  #GTK_STATE_FLAG_PRELIGHT     = 1 << 1
  #GTK_STATE_FLAG_SELECTED     = 1 << 2
  #GTK_STATE_FLAG_INSENSITIVE  = 1 << 3
  #GTK_STATE_FLAG_INCONSISTENT = 1 << 4
  #GTK_STATE_FLAG_FOCUSED      = 1 << 5
  #GTK_STATE_FLAG_BACKDROP     = 1 << 6
  #GTK_STATE_FLAG_DIR_LTR      = 1 << 7
  #GTK_STATE_FLAG_DIR_RTL      = 1 << 8
 
  #GTK_STYLE_PROVIDER_PRIORITY_FALLBACK = 1
  #GTK_STYLE_PROVIDER_PRIORITY_THEME = 200
  #GTK_STYLE_PROVIDER_PRIORITY_SETTINGS = 400
  #GTK_STYLE_PROVIDER_PRIORITY_APPLICATION = 600
  #GTK_STYLE_PROVIDER_PRIORITY_USER  = 800
 
  ;- Structures
  Structure GdkRGBA
    red.d
    green.d
    blue.d
    alpha.d
  EndStructure
 
  ;- Maps
  Global NewMap CSSProviderList()
 
  ;- Global Variables
  Global GTKMinorVersion = gtk_get_minor_version()
 
  Global CSSColorSelected.s = "RGB(128,128,255)"
  Global CSSColorSelection.s = "RGB(160,160,255)"
 
  ;- Macros
  Macro PB(Function)
    Function
  EndMacro
 
  Macro SetProvider()
    CSSProvider = gtk_css_provider_new()
    CSSContext = gtk_widget_get_style_context(GadgetID(Gadget))
    If FindMapElement(CSSProviderList(), Hex(gadget) + "/" + Hex(ColorType))
      gtk_style_context_remove_provider(CSSContext, CSSProviderList())
    EndIf
    CSSProviderList(Hex(gadget) + "/" + Hex(ColorType)) = CSSProvider
    gtk_css_provider_load_from_data(CSSProvider, CSSData, -1, 0)
    gtk_style_context_add_provider(CSSContext, CSSProvider, #GTK_STYLE_PROVIDER_PRIORITY_USER)
    g_object_unref_(CSSProvider)
  EndMacro
 
  Macro SetOverride()
    *GdKColor = AllocateStructure(GdkRGBA)
    *GdKColor\red = (1.0/255.) * Red(Color)
    *GdKColor\green = (1.0/255.0) * Green(Color)
    *GdKColor\blue = (1.0/255.0) * Blue(Color)
    *GdKColor\alpha = 1.0
    Select ColorType
      Case #PB_Gadget_FrontColor
        gtk_widget_override_color(GadgetID(Gadget), #GTK_STATE_FLAG_NORMAL, *GdKColor)
      Case #PB_Gadget_BackColor
        gtk_widget_override_background_color(GadgetID(Gadget), #GTK_STATE_FLAG_NORMAL, *GdKColor)
        *GdKColor\red = 0.0
        *GdKColor\green = 0.0
        *GdKColor\blue = 1.0
        *GdKColor\alpha = 0.5
        gtk_widget_override_background_color(GadgetID(Gadget), #GTK_STATE_FLAG_SELECTED, *GdKColor)
      Default
        PB(SetGadgetColor)(Gadget, ColorType, Color)
    EndSelect
    FreeStructure(*GDKColor)
  EndMacro
 
  ; ---------------------------------------------------------------------------
 
  Procedure.s CSSColorString(color)
    !mov eax, dword [p.v_color]
    !bswap eax
    !shr eax, 8
    !mov dword [p.v_color], eax
    ProcedureReturn "#" + Hex(Color)
  EndProcedure
 
  ; ---------------------------------------------------------------------------
 
  Procedure.s CSSColorStringLight(color, prozent)
    Protected r1.s, r,g,b
    r = Red(color) * prozent / 100
    g = Green(color) * prozent / 100
    b = Blue(color) * prozent / 100
    r1 = "rgb(" + r + "," + g + "," + b + ")"
    ProcedureReturn r1
  EndProcedure
 
  ; ---------------------------------------------------------------------------
 
  Procedure SetSelectedColor(Color)
    CSSColorSelected = CSSColorString(Color)
  EndProcedure
 
  ; ---------------------------------------------------------------------------
 
  Procedure SetSelectionColor(Color)
    CSSColorSelection = CSSColorString(Color)
  EndProcedure
 
  ; ---------------------------------------------------------------------------
 
  Procedure.s GtkGetVersionString()
    Protected major, minor, micro
    major = gtk_get_major_version()
    minor = gtk_get_minor_version()
    micro = gtk_get_micro_version()
    ProcedureReturn "" + major + "." + minor + "." + micro
  EndProcedure
 
  ; ---------------------------------------------------------------------------
 
  Procedure GtkSetWindowColor(Window, Color)
    Static NewMap CSSProviderMap()
    Protected CSSProvider, CSSContainer, CSSContext, CSSColor.s, CSSData.s
    Protected GList
   
    CSSColor = CSSColorString(Color)
    If GTKMinorVersion > 15
      CSSData = "window.background {background-color: " + CSSColor + ";}"
      CSSContainer = WindowID(Window)
    Else
      CSSData = "GtkLayout {background-color: " + CSSColor + ";}"
      GList = gtk_container_get_children_(WindowID(Window))
      CSSContainer = g_list_nth_data_(GList, 0)
      g_list_free_(GList)
      GList = gtk_container_get_children_(CSSContainer)
      CSSContainer = g_list_nth_data_(GList, 0)
      g_list_free_(GList)
    EndIf
    CSSProvider = gtk_css_provider_new()
    CSSContext = gtk_widget_get_style_context(CSSContainer)
    If FindMapElement(CSSProviderMap(), Hex(Window))
      gtk_style_context_remove_provider(CSSContext, CSSProviderMap())
    EndIf
    CSSProviderMap(Hex(Window)) = CSSProvider
    gtk_css_provider_load_from_data(CSSProvider, CSSData, -1, 0)
    gtk_style_context_add_provider(CSSContext, CSSProvider, #GTK_STYLE_PROVIDER_PRIORITY_USER)
    g_object_unref_(CSSProvider)
  EndProcedure
 
  ; ---------------------------------------------------------------------------
 
  Procedure GtkSetGadgetColor(Gadget, ColorType, Color)
    Protected CSSProvider, CSSContext, CSSColor.s, CSSColor2.s, CSSData.s
    Protected GList, Layer, Layer2, Layer3
    Protected *GdKColor.GdkRGBA
   
    If GTKMinorVersion <= 15
      ProcedureReturn PB(SetGadgetColor)(Gadget, ColorType, Color)
    EndIf
   
    Select GadgetType(Gadget)
      Case #PB_GadgetType_Button
        ;-* #PB_GadgetType_Button
        CSSColor = CSSColorString(Color)
        Select ColorType
          Case #PB_Gadget_FrontColor
            CSSData = "* button {color: " + CSSColor + ";}"
          Case #PB_Gadget_BackColor
            CSSData = "* button {background: " + CSSColor + ";}"
            CSSData + "* button:active {" + "background: " + CSSColorSelected + ";}"
          Default
            ProcedureReturn PB(SetGadgetColor)(Gadget, ColorType, Color)
        EndSelect
        SetProvider()
       
      Case #PB_GadgetType_ButtonImage
        ;-* #PB_GadgetType_ButtonImage
        ;TODO
        PB(SetGadgetColor)(Gadget, ColorType, Color)
       
      Case #PB_GadgetType_Calendar
        ;-* #PB_GadgetType_Calendar
        ;TODO Override
        SetOverride()
       
      Case #PB_GadgetType_CheckBox
        ;-* #PB_GadgetType_CheckBox
        CSSColor = CSSColorString(Color)
        Select ColorType
          Case #PB_Gadget_FrontColor
            CSSData = "* checkbutton {color: " + CSSColor + ";}"
          Case #PB_Gadget_BackColor
            CSSData = "* checkbutton {background: " + CSSColor + ";}"
          Default
            ProcedureReturn PB(SetGadgetColor)(Gadget, ColorType, Color)
        EndSelect
        SetProvider()
       
      Case #PB_GadgetType_ComboBox
        ;-* #PB_GadgetType_ComboBox
        CSSColor = CSSColorString(Color)
        Select ColorType
          Case #PB_Gadget_FrontColor
            CSSData = "* .combo {color: " + CSSColor + ";}"
          Case #PB_Gadget_BackColor
            CSSData = "* .combo {background: " + CSSColor + ";}"
            ;CSSData + "* .combo:focus {" + "background: " + CSSColorSelected + ";}"
            ;CSSData + "* .combo > selection {" + "background-color: " + CSSColorSelection + ";}"
          Default
            ProcedureReturn PB(SetGadgetColor)(Gadget, ColorType, Color)
        EndSelect
        Layer = gtk_bin_get_child_(GadgetID(Gadget))
        Layer2 = gtk_widget_get_parent_(Layer)
        Layer3 = gtk_widget_get_parent_(Layer2)
        CSSContext = gtk_widget_get_style_context(Layer3)
        CSSProvider = gtk_css_provider_new()
        If FindMapElement(CSSProviderList(), Hex(gadget) + "/" + Hex(ColorType))
          gtk_style_context_remove_provider(CSSContext, CSSProviderList())
        EndIf
        CSSProviderList(Hex(gadget) + "/" + Hex(ColorType)) = CSSProvider
        gtk_css_provider_load_from_data(CSSProvider, CSSData, -1, 0)
        gtk_style_context_add_provider(CSSContext, CSSProvider, #GTK_STYLE_PROVIDER_PRIORITY_USER)
        g_object_unref_(CSSProvider)
       
      Case #PB_GadgetType_Container
        ;-* #PB_GadgetType_Container
        ;TODO
        ProcedureReturn PB(SetGadgetColor)(Gadget, ColorType, Color)
       
      Case #PB_GadgetType_Date
        ;-* #PB_GadgetType_Date
        CSSColor = CSSColorString(Color)
        Select ColorType
          Case #PB_Gadget_FrontColor
            CSSData = "* entry {color: " + CSSColor + ";}"
          Case #PB_Gadget_BackColor
            CSSData = "* entry {background: " + CSSColor + ";}"
          Default
            ProcedureReturn PB(SetGadgetColor)(Gadget, ColorType, Color)
        EndSelect 
        SetProvider()
       
      Case #PB_GadgetType_Editor
        ;-* #PB_GadgetType_Editor
        CSSColor = CSSColorString(Color)
        Select ColorType
          Case #PB_Gadget_FrontColor
            CSSData = "* text {color: " + CSSColor + ";}"
          Case #PB_Gadget_BackColor
            CSSData = "* text {background: " + CSSColor + ";}"
            CSSData + "* text > selection {" + "background-color: " + CSSColorSelection + ";}"
          Default
            ProcedureReturn PB(SetGadgetColor)(Gadget, ColorType, Color)
        EndSelect 
        SetProvider()
       
      Case #PB_GadgetType_ExplorerCombo
        ;-* #PB_GadgetType_ExplorerCombo
        CSSColor = CSSColorString(Color)
        Select ColorType
          Case #PB_Gadget_FrontColor
            CSSData = "* .combo {color: " + CSSColor + ";}"
          Case #PB_Gadget_BackColor
            CSSData = "* .combo {background: " + CSSColor + ";}"
            ;CSSData + "*.combo:focus {" + "background: " + CSSColorSelected + ";}"
            ;CSSData + "*.combo > selection {" + "background-color: " + CSSColorSelection + ";}"
          Default
            ProcedureReturn PB(SetGadgetColor)(Gadget, ColorType, Color)
        EndSelect
       
        GList = gtk_container_get_children_(GadgetID(Gadget))
        Layer = g_list_nth_data_(GList, 0)
        g_list_free_(GList)
        CSSContext = gtk_widget_get_style_context(Layer)
        CSSProvider = gtk_css_provider_new()
        If FindMapElement(CSSProviderList(), Hex(gadget) + "/" + Hex(ColorType))
          gtk_style_context_remove_provider(CSSContext, CSSProviderList())
        EndIf
        CSSProviderList(Hex(gadget) + "/" + Hex(ColorType)) = CSSProvider
        gtk_css_provider_load_from_data(CSSProvider, CSSData, -1, 0)
        gtk_style_context_add_provider(CSSContext, CSSProvider, #GTK_STYLE_PROVIDER_PRIORITY_USER)
        g_object_unref_(CSSProvider)
       
      Case #PB_GadgetType_ExplorerList, #PB_GadgetType_ExplorerTree
        ;-* #PB_GadgetType_ExplorerList, #PB_GadgetType_ExplorerTree
        CSSColor = CSSColorString(Color)
        Select ColorType
          Case #PB_Gadget_FrontColor
            CSSData = "* .view {color: " + CSSColor + ";}"
          Case #PB_Gadget_BackColor
            CSSData = "* .view {background: " + CSSColor + ";}"
            CSSData + "* .view:selected {background: " + CSSColorSelected + ";}"
          Default
            ProcedureReturn PB(SetGadgetColor)(Gadget, ColorType, Color)
        EndSelect
        SetProvider()
       
      Case #PB_GadgetType_Frame
        ;-* #PB_GadgetType_Frame
        CSSColor = CSSColorString(Color)
        Select ColorType
          Case #PB_Gadget_FrontColor
            CSSData = "* frame {color: " + CSSColor + "};"
          Case #PB_Gadget_BackColor
            CSSData = "* border {background: " + CSSColor + ";} "
          Default
            ProcedureReturn PB(SetGadgetColor)(Gadget, ColorType, Color)
        EndSelect 
        SetProvider()
       
      Case #PB_GadgetType_HyperLink
        ;-* #PB_GadgetType_HyperLink
        CSSColor = CSSColorString(Color)
        Select ColorType
          Case #PB_Gadget_FrontColor
            ;Intern: <span color='#0000FF'>Text</span>
            ProcedureReturn 0
          Case #PB_Gadget_BackColor
            CSSData = "* label {background: " + CSSColor + "};"
          Default
        EndSelect 
        SetProvider()
       
      Case #PB_GadgetType_IPAddress
        ;-* #PB_GadgetType_IPAddress
        CSSColor = CSSColorString(Color)
        Select ColorType
          Case #PB_Gadget_FrontColor
            CSSData = "* entry {color: " + CSSColor + "};"
          Case #PB_Gadget_BackColor
            CSSData = "* entry {background: " + CSSColor + "};"
          Default
            ProcedureReturn PB(SetGadgetColor)(Gadget, ColorType, Color)
        EndSelect 
        SetProvider()
       
      Case #PB_GadgetType_ListIcon, #PB_GadgetType_ListView, #PB_GadgetType_Tree
        ;-* #PB_GadgetType_ListIcon, #PB_GadgetType_ListView, #PB_GadgetType_Tree
        CSSColor = CSSColorString(Color)
        Select ColorType
          Case #PB_Gadget_FrontColor
            CSSData = "* .view {color: " + CSSColor + ";}"
          Case #PB_Gadget_BackColor
            CSSData = "* .view {background: " + CSSColor + ";}"
            CSSData + "* .view:selected {background: " + CSSColorSelected + ";}"
          Default
            ProcedureReturn PB(SetGadgetColor)(Gadget, ColorType, Color)
        EndSelect
        SetProvider()
       
      Case #PB_GadgetType_Option
        ;-* #PB_GadgetType_Option
        CSSColor = CSSColorString(Color)
        Select ColorType
          Case #PB_Gadget_FrontColor
            CSSData = "* radiobutton {color: " + CSSColor + ";}"
          Case #PB_Gadget_BackColor
            CSSData = "* radiobutton {background: " + CSSColor + ";}"
          Default
            ProcedureReturn PB(SetGadgetColor)(Gadget, ColorType, Color)
        EndSelect 
        SetProvider()
       
      Case #PB_GadgetType_Panel
        ;-* #PB_GadgetType_Panel
        CSSColor = CSSColorString(Color)
        CSSColor2 = CSSColorStringLight(Color, 90)
        Select ColorType
          Case #PB_Gadget_FrontColor
            CSSData = "* {color: " + CSSColor + ";}"
          Case #PB_Gadget_BackColor
            CSSData = "* box * {background: " + CSSColor + ";}"
            CSSData + "* .top * {background: " + CSSColor2 + ";}"
            CSSData + "* .up {background: transparent}"
            CSSData + "* .down {background: transparent}"
            CSSData + "* :checked {background: " + CSSColor + ";}"
          Default
            ProcedureReturn PB(SetGadgetColor)(Gadget, ColorType, Color)
        EndSelect
        SetProvider()
       
      Case #PB_GadgetType_ProgressBar
        ;-* #PB_GadgetType_ProgressBar
        CSSColor = CSSColorString(Color)
        Select ColorType
          Case #PB_Gadget_FrontColor
            CSSData = "* .left {color: " + CSSColor + ";}"
          Case #PB_Gadget_BackColor
            ;Eigentlich: .left{background-image: linear-gardient(..,..)}
            CSSData = "* .left {background: " + CSSColor + ";}"
            CSSData + "* .left:selected {background: " + CSSColorSelected + ";}"
          Default
            ProcedureReturn PB(SetGadgetColor)(Gadget, ColorType, Color)
        EndSelect
        SetProvider()
       
      Case #PB_GadgetType_Scintilla
        ;-* #PB_GadgetType_Scintilla
        CSSColor = CSSColorString(Color)
        Select ColorType
          Case #PB_Gadget_FrontColor
            ScintillaSendMessage(Gadget, #SCI_STYLESETFORE, #STYLE_DEFAULT, color) 
            ScintillaSendMessage(Gadget, #SCI_STYLECLEARALL)
          Case #PB_Gadget_BackColor
            ScintillaSendMessage(Gadget, #SCI_STYLESETBACK, #STYLE_DEFAULT, color) 
            ScintillaSendMessage(Gadget, #SCI_STYLECLEARALL)
          Default
            ProcedureReturn PB(SetGadgetColor)(Gadget, ColorType, Color)
        EndSelect
       
      Case #PB_GadgetType_ScrollArea
        ;-* #PB_GadgetType_ScrollArea (Bug ?)
        ;ProcedureReturn PB(SetGadgetColor)(Gadget, ColorType, Color)
        CSSColor = CSSColorString(Color)
        Select ColorType
          Case #PB_Gadget_FrontColor
            ; Nothing
            ProcedureReturn 0
          Case #PB_Gadget_BackColor
            CSSData = "* > box > label {background: " + CSSColor + "};"
          Default
            ProcedureReturn PB(SetGadgetColor)(Gadget, ColorType, Color)
        EndSelect
        SetProvider()
       
      Case #PB_GadgetType_ScrollBar
        ;-* #PB_GadgetType_ScrollBar
        CSSColor = CSSColorString(Color)
        Select ColorType
          Case #PB_Gadget_FrontColor
            CSSData = "* slider {background: " + CSSColor + "};"
          Case #PB_Gadget_BackColor
            CSSData = "* scrollbar {background: " + CSSColor + "};"
          Default
            ProcedureReturn PB(SetGadgetColor)(Gadget, ColorType, Color)
        EndSelect
        SetProvider()
       
      Case #PB_GadgetType_Shortcut
        ;-* #PB_GadgetType_Shortcut
        CSSColor = CSSColorString(Color)
        Select ColorType
          Case #PB_Gadget_FrontColor
            CSSData = "* entry {color: " + CSSColor + ";}"
          Case #PB_Gadget_BackColor
            CSSData = "* entry {background: " + CSSColor + ";}"
            CSSData + "* entry > selection {" + "background-color: " + CSSColorSelected + ";}"
          Default
            ProcedureReturn PB(SetGadgetColor)(Gadget, ColorType, Color)
        EndSelect
        SetProvider()
       
      Case #PB_GadgetType_Spin
        ;-* #PB_GadgetType_Spin
        CSSColor = CSSColorString(Color)
        Select ColorType
          Case #PB_Gadget_FrontColor
            CSSData = ".input {color: " + CSSColor + ";}"
          Case #PB_Gadget_BackColor
            CSSData = "*.input {background: " + CSSColor + ";}"
            CSSData + "*.input:focus {" + "background: " + CSSColorSelected + ";}"
            CSSData + "*.input > selection {" + "background-color: " + CSSColorSelection + ";}"
          Default
            ProcedureReturn PB(SetGadgetColor)(Gadget, ColorType, Color)
        EndSelect
        GList = gtk_container_get_children_(GadgetID(Gadget))
        Layer = g_list_nth_data_(GList, 0)
        g_list_free_(GList)
        CSSContext = gtk_widget_get_style_context(Layer)
        CSSProvider = gtk_css_provider_new()
        If FindMapElement(CSSProviderList(), Hex(gadget) + "/" + Hex(ColorType))
          gtk_style_context_remove_provider(CSSContext, CSSProviderList())
        EndIf
        CSSProviderList(Hex(gadget) + "/" + Hex(ColorType)) = CSSProvider
        gtk_css_provider_load_from_data(CSSProvider, CSSData, -1, 0)
        gtk_style_context_add_class(CSSContext, "input")
        gtk_style_context_add_provider(CSSContext, CSSProvider, #GTK_STYLE_PROVIDER_PRIORITY_APPLICATION)
        g_object_unref_(CSSProvider)
       
      Case #PB_GadgetType_Splitter
        ;-* #PB_GadgetType_Splitter
        ;TODO
        PB(SetGadgetColor)(Gadget, ColorType, Color)
       
      Case #PB_GadgetType_String
        ;-* #PB_GadgetType_String
        CSSColor = CSSColorString(Color)
        Select ColorType
          Case #PB_Gadget_FrontColor
            CSSData = "* entry {color: " + CSSColor + ";}"
          Case #PB_Gadget_BackColor
            CSSData = "* entry {background: " + CSSColor + ";}"
            CSSData + "* entry:focus {" + "background-color: " + CSSColorSelected + ";}"
            CSSData + "* entry > selection {" + "background-color: " + CSSColorSelection + ";}"
          Default
            ProcedureReturn PB(SetGadgetColor)(Gadget, ColorType, Color)
        EndSelect
        SetProvider()
       
      Case #PB_GadgetType_Text
        ;-* #PB_GadgetType_Text
        CSSColor = CSSColorString(Color)
        Select ColorType
          Case #PB_Gadget_FrontColor
            CSSData = "* label {color: " + CSSColor + "};"
          Case #PB_Gadget_BackColor
            CSSData = "* label {background: " + CSSColor + "};"
          Default
            ProcedureReturn PB(SetGadgetColor)(Gadget, ColorType, Color)
        EndSelect 
        SetProvider()
       
      Case #PB_GadgetType_TrackBar
        ;-* #PB_GadgetType_TrackBar
        CSSColor = CSSColorString(Color)
        Select ColorType
          Case #PB_Gadget_FrontColor
            CSSData = "* slider {background: " + CSSColor + "};"
          Case #PB_Gadget_BackColor
            CSSData = "* highlight {background: " + CSSColor + "};"
          Default
            ProcedureReturn PB(SetGadgetColor)(Gadget, ColorType, Color)
        EndSelect
        SetProvider()
       
      Default
        PB(SetGadgetColor)(Gadget, ColorType, Color)
       
    EndSelect
   
  EndProcedure
 
EndModule

;- End Module GtkGadgetColor

; *****************************************************************************

CompilerIf #PB_Compiler_IsMainFile
 
  UseModule GtkGadgetColor
 
  If OpenWindow(0, 80, 80, 400, 240, "Gadget (GTK v" + GtkGetVersionString() + ")", #PB_Window_SystemMenu)
    ;widget = ButtonGadget(0, 10, 10, 380, 25, "Button")
   
    ;widget = CalendarGadget(0, 10, 10, 380, 25)
    ;widget = CheckBoxGadget(0, 10, 10, 380, 25, "Check 1")
    ;widget = ComboBoxGadget(0, 10, 10, 380, 25)
    ;widget = ContainerGadget(0, 10, 10, 380, 220, #PB_Container_Raised) : CloseGadgetList()
    ;widget = ContainerGadget(0, 10, 10, 380, 220) : CloseGadgetList()
   
    ;widget = DateGadget(0, 10, 10, 380, 25)
   
    ;widget = EditorGadget(0, 10, 10, 380, 220)
    ;widget = ExplorerComboGadget(0, 10, 10, 380, 25, "/")
    ;widget = ExplorerListGadget(0, 10, 10, 380, 220, "/")
    ;widget = ExplorerTreeGadget(0, 10, 10, 380, 220, "/")
   
    ;widget = FrameGadget(0, 10, 10, 380, 220, "Text")
   
    ;widget = HyperLinkGadget(0, 10, 10, 380, 220, "Text", #Blue)
   
    ;widget = IPAddressGadget(0, 10, 10, 380, 25)
   
    ;widget = ListViewGadget(0, 10, 10, 380, 220)
    ;widget = ListIconGadget(0, 10, 10, 380, 220, "Column 1", 150) : AddGadgetColumn(0, 1, "Column 2", 150)
   
    ;widget = OptionGadget(0, 10, 10, 380, 25, "Option 1")
   
    widget = PanelGadget(0, 10, 10, 380, 220)
    ;widget = ProgressBarGadget(0, 10, 10, 380, 40, 0, 100) : SetGadgetState(0, 50)
   
    ;widget = TextGadget(0, 10, 10, 380, 220, "Hello World!")
    ;widget = TreeGadget(0, 10, 10, 380, 220) : For i = 0 To 5 : AddGadgetItem (ID, -1, "Item "+Str(a), 0, i % 2) : Next
   
    ;widget = ScintillaGadget(0, 10, 10, 380, 220, 0) : SetGadgetText(0, "Hello world!")
    ;widget = ScrollAreaGadget(0, 10, 10, 380, 220, 760, 440, #PB_ScrollArea_Single) : TextGadget(1, 5, 5, 200,40, "Text") : CloseGadgetList()
    ;widget = ShortcutGadget(0, 10, 10, 380, 40, #PB_Shortcut_End)
    ;widget = SpinGadget(0, 10, 10, 380, 40, 0, 100, #PB_Spin_Numeric) : SetGadgetState(0, 50)
    ;widget = StringGadget(0, 10, 10, 380, 25, "Hello World!")
   
    ;widget = TrackBarGadget(0, 10, 10, 380, 40, 0, 100) : SetGadgetState(0, 50)
   
    For a = 1 To 16
      AddGadgetItem (0, -1, "Item " + Str(a)) ; define listview content
    Next
   
    SetWindowColor(0, #Gray)
   
    ;SetGadgetColor(0, #PB_Gadget_FrontColor, #Red)
    ;SetGadgetColor(0, #PB_Gadget_BackColor, #Yellow)
    SetGadgetColor(0, #PB_Gadget_FrontColor, #White)
    SetGadgetColor(0, #PB_Gadget_BackColor, $5D524E)
   
    Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
  EndIf
 
CompilerEndIf

_________________
My Projects ThreadToGUI / OOP-BaseClass / OOP-BaseClassDispatch / EventDesigner V3
PB v3.30 / v5.70 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace


Last edited by mk-soft on Sun Jan 06, 2019 7:30 pm, edited 20 times in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: GTK3 SetGadgetColor Workaround (Teamwork)
PostPosted: Wed Dec 26, 2018 6:50 pm 
Offline
User
User

Joined: Sat Jun 23, 2018 5:21 pm
Posts: 99
I try and try, but I can not find a solution.
How to set the line colors in a ListViewGadget via CSS?
With a ListIconGadget or TreeGadget one can set this also normally.
Everything is internal but a GTKTreeView.

After the "API" but something like that, right?

"treeview: nth-child (odd) {background-color: blue;}"

????

Incidentally, the window color can also be set via CSS.

Code:
Procedure SetWindowColorEx(Window, wcolor)
  Protected *gProvider= gtk_css_provider_new()
  Protected.s CSS = "*{background: rgb("+Red(wcolor)+","+Green(wcolor)+","+Blue(wcolor)+")}"
 
  gtk_css_provider_load_from_data(*gProvider, CSS, -1, #Null)
  gtk_style_context_add_provider(gtk_widget_get_style_context(WindowID(Window)), *gProvider, 600)
  g_object_unref_(*gProvider)
EndProcedure


Top
 Profile  
Reply with quote  
 Post subject: Re: GTK3 SetGadgetColor Workaround (Teamwork)
PostPosted: Wed Dec 26, 2018 8:23 pm 
Offline
Addict
Addict
User avatar

Joined: Fri May 12, 2006 6:51 pm
Posts: 2061
Location: Germany
Update
I've come a little further now.
But there is still a lot to work on. We can use help.

I optimized the CSSColor with some ASM.
Code:
  Procedure.s CSSColorString(color)
    !mov eax, dword [p.v_color]
    !bswap eax
    !shr eax, 8
    !mov dword [p.v_color], eax
    ProcedureReturn "#" + Hex(Color)
  EndProcedure

_________________
My Projects ThreadToGUI / OOP-BaseClass / OOP-BaseClassDispatch / EventDesigner V3
PB v3.30 / v5.70 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace


Top
 Profile  
Reply with quote  
 Post subject: Re: GTK3 SetGadgetColor Workaround (Teamwork)
PostPosted: Thu Dec 27, 2018 5:08 pm 
Offline
Enthusiast
Enthusiast

Joined: Thu Jun 26, 2014 9:17 am
Posts: 308
Location: Germany
Hi!
I've created (even if they are not PB supported ?) StringGadget and ButtonGadget with some hard coded "states". (Probably more would have to be added - but how to handle?)
I changed the CheckBoxGadget - with a 'focus'ed-state too.
I hope other people aren't working on it too - or working on better versions.

My yesterday's post for '#PB_GadgetType_ListIcon, #PB_GadgetType_ListView, #PB_GadgetType_Tree' should be extended to:
'#PB_GadgetType_ListIcon, #PB_GadgetType_ListView, #PB_GadgetType_Tree, #PB_GadgetType_ExplorerTree, #PB_GadgetType_ExplorerList', i think.

But don't trust my thing yet! I don't know what I'm doing. :(
Code:
Case #PB_GadgetType_Button
   CSSColor = "#" + RSet(Hex(Red(Color)), 2, "0") + RSet(Hex(Green(Color)), 2, "0") + RSet(Hex(Blue(Color)), 2, "0")
   Select ColorType
      Case #PB_Gadget_FrontColor
         CSSData = "* button {color: " + CSSColor + ";}"
      Case #PB_Gadget_BackColor
            CSSData = "* button {background: " + CSSColor + ";}"
         CSSData + "* button:active {" + "background: RGB(128,128,255);}"
      Default
            ProcedureReturn PB(SetGadgetColor)(Gadget, ColorType, Color)
   EndSelect
   SetProvider()
   
Case #PB_GadgetType_String
   CSSColor = "#" + RSet(Hex(Red(Color)), 2, "0") + RSet(Hex(Green(Color)), 2, "0") + RSet(Hex(Blue(Color)), 2, "0")
   Select ColorType
      Case #PB_Gadget_FrontColor
         CSSData = "* entry {color: " + CSSColor + ";}"
      Case #PB_Gadget_BackColor
            CSSData = "* entry {background: " + CSSColor + ";}"
            CSSData + "* entry:focus {" + "background: RGB(128,128,255);}"
            CSSData + "* entry > selection {" + "background-color: RGB(255,0,0);}"
      Default
            ProcedureReturn PB(SetGadgetColor)(Gadget, ColorType, Color)
   EndSelect
   SetProvider()
   

Case #PB_GadgetType_CheckBox
   ;TODO Lost focus ???
   CSSColor = "#" + RSet(Hex(Red(Color)), 2, "0") + RSet(Hex(Green(Color)), 2, "0") + RSet(Hex(Blue(Color)), 2, "0")
   Select ColorType
      Case #PB_Gadget_FrontColor
         CSSData = "* checkbutton {color: " + CSSColor + ";}"
      Case #PB_Gadget_BackColor
            CSSData = "* checkbutton:focus {background-color: " + CSSColor + ";}"
            CSSData + "* checkbutton {background-color: " + "RGB(255,255,255)" + ";}"
      Default
         ProcedureReturn PB(SetGadgetColor)(Gadget, ColorType, Color)
   EndSelect
   SetProvider()
Please adapt to your taste.
We should place one (or more) examples of each gadget in a ScrollAreaGadget() to have an overview and to recognize side effects.
The mysterious thing is the use of both terms background-color <-> background for the background color? I don't see the scheme behind it yet.

Regards, Charly

_________________
PureBasic 5.4-5.7, Linux: (X/L/K)Ubuntus+Mint - Windows XP (32Bit)
PureBasic Linux-API-Library & Viewer: http://www.chabba.de


Top
 Profile  
Reply with quote  
 Post subject: Re: GTK3 SetGadgetColor Workaround (Teamwork)
PostPosted: Thu Dec 27, 2018 5:58 pm 
Offline
Addict
Addict
User avatar

Joined: Fri May 12, 2006 6:51 pm
Posts: 2061
Location: Germany
Thanks Oma,

I don't know what I'm doing either.

Now I put the ComboBoxGadget on the TODO list, the "gtk_style_context_add_provider_for_screen" is global for all gadgets.
But I can't do it with the ComboBox. Slowly believe it's a bug in GTK...

I took over your code with small adjustments.
Code:
CSSColor = CSSColorString(Color)

_________________
My Projects ThreadToGUI / OOP-BaseClass / OOP-BaseClassDispatch / EventDesigner V3
PB v3.30 / v5.70 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace


Top
 Profile  
Reply with quote  
 Post subject: Re: GTK3 SetGadgetColor Workaround (Teamwork)
PostPosted: Thu Dec 27, 2018 7:21 pm 
Offline
Enthusiast
Enthusiast

Joined: Thu Jun 26, 2014 9:17 am
Posts: 308
Location: Germany
The ComboBoxGadget can be a complicated construction. I'll try my luck with it the next few days.
Shardik has already done some things with CSS. Maybe he'd like to join in.

_________________
PureBasic 5.4-5.7, Linux: (X/L/K)Ubuntus+Mint - Windows XP (32Bit)
PureBasic Linux-API-Library & Viewer: http://www.chabba.de


Top
 Profile  
Reply with quote  
 Post subject: Re: GTK3 SetGadgetColor Workaround (Teamwork)
PostPosted: Fri Dec 28, 2018 5:54 pm 
Offline
Addict
Addict
User avatar

Joined: Fri May 12, 2006 6:51 pm
Posts: 2061
Location: Germany
Cleaned up the code a bit...
Also added two color variables as standard
Code:
  ;- Global Variables
  Global CSSColorSelected.s = "RGB(128,128,255)"
  Global CSSColorSelection.s = "RGB(96,96,255)"


The function "gtk_widget_override_*" is moved to a macro

Updated the following gadgets
- OptionGadget
- CheckboxGadget
- ShortcutGadget
- ContainerGadget


There are still some gadgets to edit

_________________
My Projects ThreadToGUI / OOP-BaseClass / OOP-BaseClassDispatch / EventDesigner V3
PB v3.30 / v5.70 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace


Top
 Profile  
Reply with quote  
 Post subject: Re: GTK3 SetGadgetColor Workaround (Teamwork)
PostPosted: Sat Dec 29, 2018 8:33 am 
Offline
Enthusiast
Enthusiast

Joined: Thu Jun 26, 2014 9:17 am
Posts: 308
Location: Germany
Thanks so far.

Yesterday I played with the ComboBoxGadget. I haven't made a breakthrough yet.
Above all, I didn't get access to the text color in the ComboBox yet.
However, PB's SetGadgetColor() for the ComboBoxGadget is not defined at the moment!
If I get the aggressiveness again, I'll try again :twisted:

And a test on my 'still-main-system' Xubuntu 14.04 (i know the time is running out :cry: ) showed that with the CSS syntax used in the code (and possibly because of the chosen 'theme') no color setting works at all. (Wouldn't be so bad now!)

_________________
PureBasic 5.4-5.7, Linux: (X/L/K)Ubuntus+Mint - Windows XP (32Bit)
PureBasic Linux-API-Library & Viewer: http://www.chabba.de


Top
 Profile  
Reply with quote  
 Post subject: Re: GTK3 SetGadgetColor Workaround (Teamwork)
PostPosted: Sat Dec 29, 2018 12:39 pm 
Offline
Addict
Addict
User avatar

Joined: Fri May 12, 2006 6:51 pm
Posts: 2061
Location: Germany
Hi,
With the Gadget with Combo I have also given up for the time being. Somehow the style is always overwritten by Application Style. A Linux professional programmer has to look at that

The rest looks pretty good already...

P.S.
with the style for "*for_screen" it works. But then it is for all "combobox"
Code:
css_combo = "menuitem {color: blue; background: yellow;} menuitem:hover { background: rgb(128,128,255);} .combo {color: blue; background: yellow} "

_________________
My Projects ThreadToGUI / OOP-BaseClass / OOP-BaseClassDispatch / EventDesigner V3
PB v3.30 / v5.70 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace


Top
 Profile  
Reply with quote  
 Post subject: Re: GTK3 SetGadgetColor Workaround (Teamwork)
PostPosted: Sat Dec 29, 2018 8:52 pm 
Offline
Addict
Addict
User avatar

Joined: Thu Apr 21, 2005 2:38 pm
Posts: 1657
Location: Germany
In the ImportC block I had to comment out
Code:
    gtk_style_context_to_string (*Context, flags)
because this function was introduced in GTK+ 3.20 and my Linux Mint 18.3 has only installed GTK+ 3.18.9. This function is only used in these two code lines:
Code:
    Protected *string = gtk_style_context_to_string(gtk_widget_get_style_context(GadgetID(Gadget)), 1)
    Debug PeekS(*string, -1, #PB_UTF8)
and you may also comment them out because currently *string isn't used in the rest of the source code.


Top
 Profile  
Reply with quote  
 Post subject: Re: GTK3 SetGadgetColor Workaround (Teamwork)
PostPosted: Sat Dec 29, 2018 10:27 pm 
Offline
User
User

Joined: Sat Jun 23, 2018 5:21 pm
Posts: 99
Hello Shardik!

Interesting to know.

I use Linux Mint LMDE 3 and have the GTK version: 3.22.11

And it works.


Top
 Profile  
Reply with quote  
 Post subject: Re: GTK3 SetGadgetColor Workaround (Teamwork)
PostPosted: Sat Dec 29, 2018 11:24 pm 
Offline
Addict
Addict
User avatar

Joined: Fri May 12, 2006 6:51 pm
Posts: 2061
Location: Germany
Hi Shardik,

I can remove it. Is ever only for debug information ... -> removed!

Update v0.11 (OMA)
- #PB_GadgetType_ExplorerList, #PB_GadgetType_ExplorerTree

_________________
My Projects ThreadToGUI / OOP-BaseClass / OOP-BaseClassDispatch / EventDesigner V3
PB v3.30 / v5.70 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace


Last edited by mk-soft on Sun Dec 30, 2018 12:32 am, edited 1 time in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: GTK3 SetGadgetColor Workaround (Teamwork)
PostPosted: Sun Dec 30, 2018 12:27 am 
Offline
User
User

Joined: Sat Jun 23, 2018 5:21 pm
Posts: 99
The SpinGadget is very mysterious.
Actually it should behave like an "entry". But you have no access to it, only to the "box".

If the entry but give a style class. (Example: test)
Then I can in the CSS tab (inspector tool) via the following command set the color.

.test {color: red; background: yellow}

????

But under PureBasic at least it does not work, but the style class is set correctly.

Code:
;gtk_style_context_add_class(*CSSContext, *ClassName)
; gtk_style_context_list_classes(*CSSContext)
;...
Case #PB_GadgetType_Spin
        ;-* #PB_GadgetType_Spin
        Layer = g_list_nth_data_(gtk_container_get_children_(GadgetID(Gadget)), 0)
        ;Debug PeekS(gtk_widget_get_name_(Layer), -1, #PB_UTF8)
       
        CSSContext = gtk_widget_get_style_context(Layer)
        gtk_style_context_add_class(CSSContext, UTF8("test"))
       
        ;Debug PeekS(gtk_style_context_list_classes(CSSContext), -1, #PB_UTF8)
        CSSColor = CSSColorString(Color)
        Select ColorType
          Case #PB_Gadget_FrontColor
            CSSData = ".test {color: " + CSSColor + ";}"
          Case #PB_Gadget_BackColor
           
            CSSData = ".test {background: yellow}"
            ;CSSData + "* entry:focus {" + "background: " + CSSColorSelected + ";}"
;             CSSData + "* entry > selection {" + "background-color: " + CSSColorSelection + ";}"
          Default
            ProcedureReturn PB(SetGadgetColor)(Gadget, ColorType, Color)
        EndSelect
        SetProvider()
;...


This works!
The context must remain with the "entry" and must not point to the "box".
Code:
;...
;-* #PB_GadgetType_Spin
        Layer = g_list_nth_data_(gtk_container_get_children_(GadgetID(Gadget)), 0)
        Debug PeekS(gtk_widget_get_name_(Layer), -1, #PB_UTF8)
       
        CSSContext2 = gtk_widget_get_style_context(Layer)
        gtk_style_context_add_class(CSSContext2, UTF8("input"))
       
        CSSColor = CSSColorString(Color)
        Select ColorType
          Case #PB_Gadget_FrontColor
            CSSData = "box * {color: " + CSSColor + ";}"
            ;CSSData2 = ".input {color: " + CSSColor + ";}"
          Case #PB_Gadget_BackColor
            CSSData = "box * {background: " + CSSColor + ";}"
            CSSData2 = "*.input {background: " + CSSColor + ";}"
            CSSData2 + "*.input:focus {" + "background: " + CSSColorSelected + ";}"
            CSSData2 + "*.input > selection {" + "background-color: " + CSSColorSelection + ";}"
          Default
            ProcedureReturn PB(SetGadgetColor)(Gadget, ColorType, Color)
        EndSelect
        SetProvider()
        CSSProvider2 = gtk_css_provider_new()
        If FindMapElement(CSSProviderList(), Hex(gadget) + "/" + Hex(ColorType))
          gtk_style_context_remove_provider(CSSContext2, CSSProviderList())
        EndIf
        CSSProviderList(Hex(gadget) + "/" + Hex(ColorType)) = CSSProvider2
        gtk_css_provider_load_from_data(CSSProvider2, CSSData2, -1, 0)
        gtk_style_context_add_provider(CSSContext2, CSSProvider2, #GTK_STYLE_PROVIDER_PRIORITY_APPLICATION)
        g_object_unref_(CSSProvider2)
;...


I'm stupid!
If I do it right, the arrows will go, of course!
widget = SpinGadget(0, 10, 10, 380, 40, 0, 100, #PB_Spin_Numeric) : SetGadgetState(0, 50)

But it would be great if you could not just adjust the selected / selection colors globally.
Also, an adjustment of the containing containers should be solved nicely.
I think it needs more additional constants here.


Last edited by ccode on Sun Dec 30, 2018 5:04 pm, edited 1 time in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: GTK3 SetGadgetColor Workaround (Teamwork)
PostPosted: Sun Dec 30, 2018 3:17 am 
Offline
Addict
Addict
User avatar

Joined: Fri May 12, 2006 6:51 pm
Posts: 2061
Location: Germany
As I see it, the SpinGadget of the nodes entry background color is controlled by the location gtk.css and therefore always overwritten.

_________________
My Projects ThreadToGUI / OOP-BaseClass / OOP-BaseClassDispatch / EventDesigner V3
PB v3.30 / v5.70 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace


Top
 Profile  
Reply with quote  
 Post subject: Re: GTK3 SetGadgetColor Workaround (Teamwork / Release)
PostPosted: Tue Jan 01, 2019 2:43 pm 
Offline
Addict
Addict
User avatar

Joined: Fri May 12, 2006 6:51 pm
Posts: 2061
Location: Germany
Release Version v1.01

After good cooperation the first release version is online.
Many thanks to "ccode" for the last extensions and of course to "OMI".

_________________
My Projects ThreadToGUI / OOP-BaseClass / OOP-BaseClassDispatch / EventDesigner V3
PB v3.30 / v5.70 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 17 posts ]  Go to page 1, 2  Next

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye