Attachment "patch-mainframe1.23-casesensitive.txt" to
ticket [1977644fff]
added by
cmard
2008-05-29 18:09:59.
Index: mainframe.tcl
===================================================================
--- mainframe.tcl (revision 5)
+++ mainframe.tcl (working copy)
@@ -38,13 +38,14 @@
}
Widget::declare MainFrame {
- {-width TkResource 0 0 frame}
- {-height TkResource 0 0 frame}
- {-background TkResource "" 0 frame}
- {-textvariable String "" 0}
- {-menu String {} 1}
- {-separator Enum both 1 {none top bottom both}}
- {-bg Synonym -background}
+ {-width TkResource 0 0 frame}
+ {-height TkResource 0 0 frame}
+ {-background TkResource "" 0 frame}
+ {-textvariable String "" 0}
+ {-casesensitive Boolean 0 0}
+ {-menu String {} 1}
+ {-separator Enum both 1 {none top bottom both}}
+ {-bg Synonym -background}
{-menubarfont String "" 0}
{-menuentryfont String "" 0}
@@ -176,7 +177,7 @@
set menu [Widget::getoption $path -menu]
if { [llength $menu] } {
- _create_menubar $path $menu
+ _create_menubar $path $menu [Widget::getoption $path -casesensitive]
}
bind $path <Destroy> [list MainFrame::_destroy %W]
@@ -503,7 +504,7 @@
# ----------------------------------------------------------------------------
# Command MainFrame::_create_menubar
# ----------------------------------------------------------------------------
-proc MainFrame::_create_menubar { path descmenu } {
+proc MainFrame::_create_menubar { path descmenu casesensitive } {
variable _widget
global tcl_platform
@@ -554,7 +555,7 @@
# menu has identifier
set _widget($path,menuid,$menuid) $menu
}
- _create_entries $path $menu $menuopts $entries
+ _create_entries $path $menu $menuopts $entries $casesensitive
incr count
}
}
@@ -563,7 +564,7 @@
# ----------------------------------------------------------------------------
# Command MainFrame::_create_entries
# ----------------------------------------------------------------------------
-proc MainFrame::_create_entries { path menu menuopts entries } {
+proc MainFrame::_create_entries { path menu menuopts entries casesensitive } {
variable _widget
set count [$menu cget -tearoff]
@@ -601,7 +602,7 @@
# menu has identifier
set _widget($path,menuid,$menuid) $submenu
}
- _create_entries $path $submenu $menuopts [lindex $entry 5]
+ _create_entries $path $submenu $menuopts [lindex $entry 5] $casesensitive
incr count
continue
}
@@ -617,7 +618,7 @@
}
# entry accelerator
- set accel [_parse_accelerator [lindex $entry 4]]
+ set accel [_parse_accelerator [lindex $entry 4] $casesensitive]
if { [llength $accel] } {
lappend opt -accelerator [lindex $accel 0]
bind $_widget($path,top) [lindex $accel 1] [list $menu invoke $count]
@@ -668,40 +669,47 @@
# Results:
# {accel event} a list containing the accelerator string and the event
-proc MainFrame::_parse_accelerator { desc } {
+proc MainFrame::_parse_accelerator { desc casesensitive } {
if { [llength $desc] == 1 } {
set seq None
- set key [string tolower [lindex $desc 0]]
+ set key [lindex $desc 0]
# If the key is an F key (ie, F1, F2, etc), it has to be capitalized
- if {[regexp {^f([1-9]|([12][0-9]|3[0-5]))$} $key]} {
+ if {[regexp {^f([1-9]|([12][0-9]|3[0-5]))$} [string tolower $key]]} {
set key [string toupper $key]
}
} elseif { [llength $desc] == 2 } {
set seq [lindex $desc 0]
- set key [string tolower [lindex $desc 1]]
+ set key [lindex $desc 1]
# If the key is an F key (ie, F1, F2, etc), it has to be capitalized
- if {[regexp {^f([1-9]|([12][0-9]|3[0-5]))$} $key]} {
+ if {[regexp {^f([1-9]|([12][0-9]|3[0-5]))$} [string tolower $key]]} {
set key [string toupper $key]
}
} else {
return {}
}
+ if {! $casesensitive} {
+ set akey [string toupper $key]
+ set ekey [string tolower $key]
+ } else {
+ set akey $key
+ set ekey $key
+ }
switch -- $seq {
None {
- set accel "[string toupper $key]"
- set event "<Key-$key>"
+ set accel $akey
+ set event "<Key-$ekey>"
}
Ctrl {
- set accel "Ctrl+[string toupper $key]"
- set event "<Control-Key-$key>"
+ set accel "Ctrl+$akey"
+ set event "<Control-Key-$ekey>"
}
Alt {
- set accel "Alt+[string toupper $key]"
- set event "<Alt-Key-$key>"
+ set accel "Alt+$akey"
+ set event "<Alt-Key-$ekey>"
}
CtrlAlt {
- set accel "Ctrl+Alt+[string toupper $key]"
- set event "<Control-Alt-Key-$key>"
+ set accel "Ctrl+Alt+$akey"
+ set event "<Control-Alt-Key-$ekey>"
}
default {
return -code error "invalid accelerator code $seq"
Index: BWman/MainFrame.html
===================================================================
--- BWman/MainFrame.html (revision 5)
+++ BWman/MainFrame.html (working copy)
@@ -3,7 +3,7 @@
<BODY BGCOLOR=white>
<DL><DT><I><A HREF="#descr">NAME</A></I></DT>
<DD><B>MainFrame</B>
- - Manage toplevel with menu, toolbar and statusbar
+ - Manage toplevel with menu, toolbar and statusbar
</DD></DL>
<DL>
<DT><I>CREATION</I></DT>
@@ -22,21 +22,26 @@
</TR>
<TR>
<TD> -progressvar (see <B>-variable</B>)</TD>
+</TR>
</TABLE></DD>
</DL>
<DL>
<DT><I><A HREF="#wso">WIDGET-SPECIFIC OPTIONS</A></I></DT>
<DD><TABLE CELLSPACING=0 CELLSPACING=0 BORDER=0>
<TR>
-<TD> <A HREF="#-height">-height</A></TR>
-<TD> <A HREF="#-menu">-menu</A></TR>
+<TD> <A HREF="#-casesensitive">-casesensitive</A></TD></TR>
+<TR>
+<TD> <A HREF="#-height">-height</A></TD></TR>
+<TR>
+<TD> <A HREF="#-menu">-menu</A></TD>
</TR>
<TR>
-<TD> <A HREF="#-separator">-separator</A></TR>
-<TD> <A HREF="#-textvariable">-textvariable</A></TR>
+<TD> <A HREF="#-separator">-separator</A></TD></TR>
+<TR>
+<TD> <A HREF="#-textvariable">-textvariable</A></TD>
</TR>
<TR>
-<TD> <A HREF="#-width">-width</A></TR>
+<TD> <A HREF="#-width">-width</A></TD></TR>
</TABLE></DD>
</DL>
<DL>
@@ -82,14 +87,36 @@
MainFrame manage toplevel to have:<BR>
<UL>
<LI>simple menu creation, with automatic accelerator bindings and
-<A HREF="DynamicHelp.html">DynamicHelp</A> association,
-<LI>one or more toolbars that user can hide,
-<LI>a status bar, displaying a user message or a menu description, and optionally a
-<A HREF="ProgressBar.html">ProgressBar</A>.
+<A HREF="DynamicHelp.html">DynamicHelp</A> association,</LI>
+<LI>one or more toolbars that user can hide,</LI>
+<LI>a status bar, displaying a user message or a menu description, and optionally a
+<A HREF="ProgressBar.html">ProgressBar</A>.</LI>
</UL>
</P>
<BR><HR WIDTH="50%"><BR>
<B><A NAME="wso">WIDGET-SPECIFIC OPTIONS</A></B><BR>
+
+<DL><DT><A NAME="-casesensitive"><B>-casesensitive</B></A></DT>
+<DD>
+Controlls the interpretation of <I>accelerator</I> definition by the <B>-menu</B>
+option. If this option is <B>false</B> or not given, the accelerator binding is done
+for lowercase letters (no Shift Key pressed) and the accelerator text of the menu entry
+is shown in uppercase letters. If it is set to <B>true</B> the accelerator binding
+and the menu entry is done as given.
+<P>
+Example:<BR>
+Both accelerators are identically if <B>-casesensitive</B> is specified as false. See
+<A HREF="#-menu">-menu</A> for the syntax of the menu discription list.
+</P>
+<PRE>
+...
+{command "&Save" {} {Save the document} {<B>Ctrl s</B>} -command Menu::save}
+{command "&Save As" {} {Save with different name} {<B>Ctrl S</B>} -command Menu::saveAs}
+...
+</PRE>
+</DD>
+</DL>
+
<DL><DT><A NAME="-height"><B>-height</B></A></DT>
<DD>
@@ -107,33 +134,35 @@
where <I>menuentries</I> is a list where each element describe one menu entry, which can be:
<UL>
<LI>for a separator:<BR>
- {<B>separator</B>}
+ {<B>separator</B>}</LI>
<LI>for a command:<BR>
- {<B>command</B> <I>menuname</I> ?<I>tags</I>? ?<I>description</I>? ?<I>accelerator</I>? ?<I>option</I> <I>value</I>? ...}
+ {<B>command</B> <I>menuname</I> ?<I>tags</I>? ?<I>description</I>? ?<I>accelerator</I>? ?<I>option</I> <I>value</I>? ...}</LI>
<LI>for a check button:<BR>
- {<B>checkbutton</B> <I>menuname</I> ?<I>tags</I>? ?<I>description</I>? ?<I>accelerator</I>? ?<I>option</I> <I>value</I>? ...}
+ {<B>checkbutton</B> <I>menuname</I> ?<I>tags</I>? ?<I>description</I>? ?<I>accelerator</I>? ?<I>option</I> <I>value</I>? ...}</LI>
<LI>for a radio button:<BR>
- {<B>radiobutton</B> <I>menuname</I> ?<I>tags</I>? ?<I>description</I>? ?<I>accelerator</I> ?<I>option</I> <I>value</I>? ...}
+ {<B>radiobutton</B> <I>menuname</I> ?<I>tags</I>? ?<I>description</I>? ?<I>accelerator</I> ?<I>option</I> <I>value</I>? ...}</LI>
<LI>for a cascade menu:<BR>
- {<B>cascade</B> <I>menuname</I> <I>tags</I> <I>menuId</I> <I>tearoff</I> <I>menuentries</I>}
+ {<B>cascade</B> <I>menuname</I> <I>tags</I> <I>menuId</I> <I>tearoff</I> <I>menuentries</I>}</LI>
</UL>
where:
<UL>
<LI><I>menuname</I> is the name of the menu. If it contains a &, the following character
is automatically converted to the corresponding <B>-underline</B> option of <B>menu add</B>
-command.
+command.</LI>
<LI><I>tags</I> is the tags list for the entry, used for enabling or disabling menu
-entries with <B>MainFrame::setmenustate</B>.
+entries with <B>MainFrame::setmenustate</B>.</LI>
<LI><I>menuId</I> is an id for the menu, from which you can get menu pathname with
- <B>MainFrame::getmenu</B>.
-<LI><I>tearoff</I> specifies if menu has tearoff entry.
-<LI><I>description</I> specifies a string for <A HREF=\"DynamicHelp.html\">DynamicHelp</A>.
+ <B>MainFrame::getmenu</B>.</LI>
+<LI><I>tearoff</I> specifies if menu has tearoff entry.</LI>
+<LI><I>description</I> specifies a string for <A HREF=\"DynamicHelp.html\">DynamicHelp</A>.</LI>
<LI><I>accelerator</I> specifies a key sequence. It is a list of two elements, where the first
-is one of <B>Ctrl</B>, <B>Alt</B> or <B>CtrlAlt</B>, and the second as letter or a digit.
+is one of <B>Ctrl</B>, <B>Alt</B> or <B>CtrlAlt</B>, and the second as letter
+(see <A HREF="#-casesensitive">-casesensitive</A> option for interpretation), a digit or
+a special key name.
An accelerator string is build and corresponding binding set on the toplevel to invoke the
-menu entry.
+menu entry.</LI>
<LI><I>option value</I> specifies additionnal options for the entry (see <B>menu add</B>
-command).
+command).</LI>
</UL>
Each value enclosed by ? are optional and defaulted to empty string, but must be
provided if one or more following options is not empty.
@@ -154,7 +183,7 @@
{command "E&xit" {} "Exit the application" {} -command Menu::exit}
}
"&Options" {} {} 0 {
- {checkbutton "Toolbar" {} "Show/hide toolbar" {}
+ {checkbutton "Toolbar" {} "Show/hide toolbar" {}
-variable Menu::_drawtoolbar
-command {$Menu::_mainframe showtoolbar toolbar $Menu::_drawtoolbar}
}