Skip to content

Commit

Permalink
Made the handling of non-default ttk::notebook tab positions more use…
Browse files Browse the repository at this point in the history
…r-friendly.
  • Loading branch information
csaba committed Aug 24, 2024
2 parents 38dee3b + 4035773 commit 9918057
Show file tree
Hide file tree
Showing 8 changed files with 181 additions and 6 deletions.
15 changes: 10 additions & 5 deletions doc/ttk_notebook.n
Original file line number Diff line number Diff line change
Expand Up @@ -292,25 +292,30 @@ you will have to adapt the above settings as follows:
ttk::style configure $nbStyle -tabmargins {2 0 2 2}
ttk::style map $nbStyle.Tab -expand {selected {2 2 2 2}}
.CE
The easiest way to do this is to invoke the library procedure
\fBttk::configureNotebookStyle\fP with \fB$nbStyle\fP as argument, after
setting the style's \fB\-tabposition\fP option.
.RE
\fB\-font\fP \fIfont\fP
.br
\fB\-foreground\fP \fIcolor\fP
.br
\fB\-padding\fP \fIpadding\fP
.RS
Some themes (e.g., \fBclam\fP) use a different \fIpadding\fP for the
selected tab. For example, the Ttk library file \fBclamTheme.tcl\fP
contains the lines
Some themes use a different \fIpadding\fP for the selected tab. For example,
the Ttk library file \fBclamTheme.tcl\fP contains the lines
.CS
ttk::style configure TNotebook.Tab \\
-padding {4.5p 1.5p 4.5p 1.5p}
ttk::style map TNotebook.Tab \\
-padding {selected {4.5p 3p 4.5p 1.5p}}
.CE
which are valid for the default value \fBnw\fP of the \fB\-tabposition\fP
style option. Again, for a different tab position you will have to adapt
the above settings accordingly.
style option. For a \fBttk::notebook\fP style having a different tab position
you will have to adapt the above settings accordingly. Again, the easiest way
to do this is to invoke the library procedure \fBttk::configureNotebookStyle\fP
with the style name as argument, after setting the style's \fB\-tabposition\fP
option.
.RE
.PP
Some options are only available for specific themes.
Expand Down
31 changes: 31 additions & 0 deletions library/ttk/altTheme.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,34 @@ namespace eval ttk::theme::alt {
-barsize 22.5p -thickness 11.25p
}
}

# ttk::theme::alt::configureNotebookStyle --
#
# Sets theme-specific option values for the ttk::notebook style $style and the
# style $style.Tab. Invoked by ::ttk::configureNotebookStyle.

proc ttk::theme::alt::configureNotebookStyle {style} {
set tabPos [ttk::style lookup $style -tabposition {} nw]
switch -- [string index $tabPos 0] {
n {
ttk::style configure $style -tabmargins {1.5p 1.5p 0.75p 0}
ttk::style map $style.Tab -expand {selected {1.5p 1.5p 0.75p 0}}
}
s {
ttk::style configure $style -tabmargins {1.5p 0 0.75p 1.5p}
ttk::style map $style.Tab -expand {selected {1.5p 0 0.75p 1.5p}}
}
w {
ttk::style configure $style -tabmargins {1.5p 1.5p 0 0.75p}
ttk::style map $style.Tab -expand {selected {1.5p 1.5p 0 0.75p}}
}
e {
ttk::style configure $style -tabmargins {0 1.5p 1.5p 0.75p}
ttk::style map $style.Tab -expand {selected {0 1.5p 1.5p 0.75p}}
}
default {
ttk::style configure $style -tabmargins {1.5p 1.5p 0.75p 0}
ttk::style map $style.Tab -expand {selected {1.5p 1.5p 0.75p 0}}
}
}
}
31 changes: 31 additions & 0 deletions library/ttk/clamTheme.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -157,3 +157,34 @@ namespace eval ttk::theme::clam {
ttk::style configure Sash -sashthickness 4.5p -gripsize 15p
}
}

# ttk::theme::clam::configureNotebookStyle --
#
# Sets theme-specific option values for the ttk::notebook tab style $style.Tab.
# Invoked by ::ttk::configureNotebookStyle.

proc ttk::theme::clam::configureNotebookStyle {style} {
set tabPos [ttk::style lookup $style -tabposition {} nw]
switch -- [string index $tabPos 0] {
n {
ttk::style configure $style.Tab -padding {4.5p 1.5p 4.5p 1.5p}
ttk::style map $style.Tab -padding {selected {4.5p 3p 4.5p 1.5p}}
}
s {
ttk::style configure $style.Tab -padding {4.5p 1.5p 4.5p 1.5p}
ttk::style map $style.Tab -padding {selected {4.5p 1.5p 4.5p 3p }}
}
w {
ttk::style configure $style.Tab -padding {1.5p 4.5p 1.5p 4.5p}
ttk::style map $style.Tab -padding {selected {3p 4.5p 1.5p 4.5p}}
}
e {
ttk::style configure $style.Tab -padding {1.5p 4.5p 1.5p 4.5p}
ttk::style map $style.Tab -padding {selected {1.5p 4.5p 3p 4.5p}}
}
default {
ttk::style configure $style.Tab -padding {4.5p 1.5p 4.5p 1.5p}
ttk::style map $style.Tab -padding {selected {4.5p 3p 4.5p 1.5p}}
}
}
}
15 changes: 15 additions & 0 deletions library/ttk/ttk.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,21 @@ proc ::ttk::setTheme {theme} {
set currentTheme $theme
}

## ttk::configureNotebookStyle $style --
# Sets theme-specific option values for the ttk::notebook style $style
# and/or the style $style.Tab. To be invoked if the -tabposition option
# of $style has a non-default value (like "sw", "wn", or "en").
#
proc ::ttk::configureNotebookStyle {style} {
set theme [ttk::style theme use]
if {[llength [info procs theme::${theme}::configureNotebookStyle]] > 0} {
theme::${theme}::configureNotebookStyle $style
return 1
} else {
return 0
}
}

## ttk::setTreeviewRowHeight --
# Sets the default height of the ttk::treeview rows for the current theme.
# To be invoked from within the library files for the built-in themes.
Expand Down
31 changes: 31 additions & 0 deletions library/ttk/vistaTheme.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -226,3 +226,34 @@ namespace eval ttk::theme::vista {
package provide ttk::theme::vista 1.0
}
}

# ttk::theme::vista::configureNotebookStyle --
#
# Sets theme-specific option values for the ttk::notebook style $style and the
# style $style.Tab. Invoked by ::ttk::configureNotebookStyle.

proc ttk::theme::vista::configureNotebookStyle {style} {
set tabPos [ttk::style lookup $style -tabposition {} nw]
switch -- [string index $tabPos 0] {
n {
ttk::style configure $style -tabmargins {2 2 2 0}
ttk::style map $style.Tab -expand {selected {2 2 2 2}}
}
s {
ttk::style configure $style -tabmargins {2 0 2 2}
ttk::style map $style.Tab -expand {selected {2 2 2 2}}
}
w {
ttk::style configure $style -tabmargins {2 2 0 2}
ttk::style map $style.Tab -expand {selected {2 2 2 2}}
}
e {
ttk::style configure $style -tabmargins {0 2 2 2}
ttk::style map $style.Tab -expand {selected {2 2 2 2}}
}
default {
ttk::style configure $style -tabmargins {2 2 2 0}
ttk::style map $style.Tab -expand {selected {2 2 2 2}}
}
}
}
31 changes: 31 additions & 0 deletions library/ttk/winTheme.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,34 @@ namespace eval ttk::theme::winnative {
-barsize 22.5p -thickness 11.25p
}
}

# ttk::theme::winnative::configureNotebookStyle --
#
# Sets theme-specific option values for the ttk::notebook style $style and the
# style $style.Tab. Invoked by ::ttk::configureNotebookStyle.

proc ttk::theme::winnative::configureNotebookStyle {style} {
set tabPos [ttk::style lookup $style -tabposition {} nw]
switch -- [string index $tabPos 0] {
n {
ttk::style configure $style -tabmargins {2 2 2 0}
ttk::style map $style.Tab -expand {selected {2 2 2 0}}
}
s {
ttk::style configure $style -tabmargins {2 0 2 2}
ttk::style map $style.Tab -expand {selected {2 0 2 2}}
}
w {
ttk::style configure $style -tabmargins {2 2 0 2}
ttk::style map $style.Tab -expand {selected {2 2 0 2}}
}
e {
ttk::style configure $style -tabmargins {0 2 2 2}
ttk::style map $style.Tab -expand {selected {0 2 2 2}}
}
default {
ttk::style configure $style -tabmargins {2 2 2 0}
ttk::style map $style.Tab -expand {selected {2 2 2 0}}
}
}
}
31 changes: 31 additions & 0 deletions library/ttk/xpTheme.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,34 @@ namespace eval ttk::theme::xpnative {
selected SystemHighlightText]
}
}

# ttk::theme::xpnative::configureNotebookStyle --
#
# Sets theme-specific option values for the ttk::notebook style $style and the
# style $style.Tab. Invoked by ::ttk::configureNotebookStyle.

proc ttk::theme::xpnative::configureNotebookStyle {style} {
set tabPos [ttk::style lookup $style -tabposition {} nw]
switch -- [string index $tabPos 0] {
n {
ttk::style configure $style -tabmargins {2 2 2 0}
ttk::style map $style.Tab -expand {selected {2 2 2 2}}
}
s {
ttk::style configure $style -tabmargins {2 0 2 2}
ttk::style map $style.Tab -expand {selected {2 2 2 2}}
}
w {
ttk::style configure $style -tabmargins {2 2 0 2}
ttk::style map $style.Tab -expand {selected {2 2 2 2}}
}
e {
ttk::style configure $style -tabmargins {0 2 2 2}
ttk::style map $style.Tab -expand {selected {2 2 2 2}}
}
default {
ttk::style configure $style -tabmargins {2 2 2 0}
ttk::style map $style.Tab -expand {selected {2 2 2 2}}
}
}
}
2 changes: 1 addition & 1 deletion macosx/tkMacOSXKeysyms.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ static const KeyInfo keyArray[] = {
{57, XK_Caps_Lock, MOD_KEYCHAR},
{58, XK_Alt_L, MOD_KEYCHAR},
{59, XK_Control_L, MOD_KEYCHAR},
{60, XK_Shift_R, MOD_KEYCHAR},
{60, XK_Shift_R, MOD_KEYCHAR},
{61, XK_Alt_R, MOD_KEYCHAR},
{62, XK_Control_R, MOD_KEYCHAR},
{63, XK_Super_L, MOD_KEYCHAR},
Expand Down

0 comments on commit 9918057

Please sign in to comment.