Updated 2018-08-31 22:31:36 by bll

Styling the readonly combobox for the vista theme edit

bll 2018-8-29: In the process of trying to figure out how to make a ttk::combobox better indicate that it was disabled on windows, François Vogel discovered how to make a readonly ttk::combobox display look like a windows native readonly combobox.

The focus still does not display in a native fashion (ttk draws its own focus ring, and always draws the focus background), so in the code below it is removed. I have not been able to determine how the windows VS API draws focus rings.

To use this, simply add -style TReadonlyCombobox to your readonly ttk::combobox's.
    # only available for Windows Vista and later
    if { $::tcl_platform(platform) eq "windows" &&
        $::tcl_platform(osVersion) >= 6.0 &&
        [ttk::style theme use] eq "vista" } {
      # Set up a readonly combobox style that matches win vista better
      # by François Vogel.
      # Focus removed as ttk always does a -focusfill.
      # I have not been able to determine how windows draws their
      # focus ring.  It does not seem to be a VS "part".
      ttk::style configure TReadonlyCombobox -padding 2
      ttk::style element create RCombobox.field vsapi \
          COMBOBOX 5 {disabled 4 pressed 3 active 2 hover 2 {} 1}
      ttk::style element create RCombobox.border vsapi \
          COMBOBOX 4 {disabled 4 focus 3 active 2 hover 2 {} 1}
      ttk::style element create RCombobox.rightdownarrow vsapi \
          COMBOBOX 6 {disabled 4 pressed 3 active 2 {} 1} \
          -syssize {SM_CXVSCROLL SM_CYVSCROLL}
      ttk::style layout TReadonlyCombobox {
          RCombobox.border -sticky nswe -border 0 -children {
              RCombobox.field -sticky nswe -children {
                  RCombobox.rightdownarrow -side right -sticky ns
                  Combobox.padding -expand 1 -sticky nswe -children {
                    Combobox.textarea -sticky nswe
    } else {
      # for other systems or themes, just copy the combobox style that
      # currently exists
      ttk::style layout TReadonlyCombobox [ttk::style layout TCombobox]
      ttk::style configure TReadonlyCombobox \
          {*}[ttk::style configure TCombobox]
      ttk::style map TReadonlyCombobox {*}[ttk::style map TCombobox]