From ef67d7e478dcdd96b095c80fbf1d95330ee35117 Mon Sep 17 00:00:00 2001 From: culler Date: Wed, 15 Apr 2020 17:24:51 +0000 Subject: Apply a patch from Christopher Chavez which correctly deals with the fact that Apple uses the middle mouse button for Button 3. --- doc/entry.n | 7 ++++--- doc/spinbox.n | 7 ++++--- doc/text.n | 9 +++++---- doc/ttk_entry.n | 7 ++++--- library/demos/entry1.tcl | 2 +- library/demos/entry2.tcl | 2 +- library/demos/text.tcl | 8 +++++--- library/entry.tcl | 27 ++++++++++++++++++++------- library/spinbox.tcl | 27 ++++++++++++++++++++------- library/text.tcl | 27 ++++++++++++++++++++------- library/ttk/entry.tcl | 19 +++++++++++++------ macosx/tkMacOSXMouseEvent.c | 36 ++++++++++-------------------------- 12 files changed, 107 insertions(+), 71 deletions(-) diff --git a/doc/entry.n b/doc/entry.n index ccfcd24..dc2f896 100644 --- a/doc/entry.n +++ b/doc/entry.n @@ -448,9 +448,10 @@ insertion cursor in the entry without affecting the selection. If any normal printing characters are typed in an entry, they are inserted at the point of the insertion cursor. .IP [7] -The view in the entry can be adjusted by dragging with mouse button 2. -If mouse button 2 is clicked without moving the mouse, the selection -is copied into the entry at the position of the mouse cursor. +The view in the entry can be adjusted by dragging with the middle +mouse button (button 2, or button 3 in TkAqua). If the middle mouse +button is clicked without moving the mouse, the selection is copied +into the entry at the position of the mouse cursor. .IP [8] If the mouse is dragged out of the entry on the left or right sides while button 1 is pressed, the entry will automatically scroll to diff --git a/doc/spinbox.n b/doc/spinbox.n index acf06d6..ad7123b 100644 --- a/doc/spinbox.n +++ b/doc/spinbox.n @@ -514,9 +514,10 @@ insertion cursor in the spinbox without affecting the selection. If any normal printing characters are typed in a spinbox, they are inserted at the point of the insertion cursor. .IP [7] -The view in the spinbox can be adjusted by dragging with mouse button 2. -If mouse button 2 is clicked without moving the mouse, the selection -is copied into the spinbox at the position of the mouse cursor. +The view in the spinbox can be adjusted by dragging with the middle +mouse button (button 2, or button 3 in TkAqua). If the middle mouse +button is clicked without moving the mouse, the selection is copied +into the spinbox at the position of the mouse cursor. .IP [8] If the mouse is dragged out of the spinbox on the left or right sides while button 1 is pressed, the spinbox will automatically scroll to diff --git a/doc/text.n b/doc/text.n index 2a161e6..90834df 100644 --- a/doc/text.n +++ b/doc/text.n @@ -2057,10 +2057,11 @@ insertion cursor without affecting the selection. If any normal printing characters are typed, they are inserted at the point of the insertion cursor. .IP [7] -The view in the widget can be adjusted by dragging with mouse button 2. If -mouse button 2 is clicked without moving the mouse, the selection is copied -into the text at the position of the mouse cursor. The Insert key also inserts -the selection, but at the position of the insertion cursor. +The view in the widget can be adjusted by dragging with the middle mouse +button (button 2, or button 3 in TkAqua). If the middle mouse button is +clicked without moving the mouse, the selection is copied into the text at the +position of the mouse cursor. The Insert key also inserts the selection, +but at the position of the insertion cursor. .IP [8] If the mouse is dragged out of the widget while button 1 is pressed, the entry will automatically scroll to make more text visible (if there is more text diff --git a/doc/ttk_entry.n b/doc/ttk_entry.n index adc4f16..0da60d1 100644 --- a/doc/ttk_entry.n +++ b/doc/ttk_entry.n @@ -353,9 +353,10 @@ insert cursor in the entry without affecting the selection. If any normal printing characters are typed in an entry, they are inserted at the point of the insert cursor. .IP \0\(bu 4 -The view in the entry can be adjusted by dragging with mouse button 2. -If mouse button 2 is clicked without moving the mouse, the selection -is copied into the entry at the position of the mouse cursor. +The view in the entry can be adjusted by dragging with the middle +mouse button (button 2, or button 3 in TkAqua). If the middle mouse +button is clicked without moving the mouse, the selection is copied +into the entry at the position of the mouse cursor. .IP \0\(bu 4 If the mouse is dragged out of the entry on the left or right sides while button 1 is pressed, the entry will automatically scroll to diff --git a/library/demos/entry1.tcl b/library/demos/entry1.tcl index eef8964..7365fc7 100644 --- a/library/demos/entry1.tcl +++ b/library/demos/entry1.tcl @@ -16,7 +16,7 @@ wm title $w "Entry Demonstration (no scrollbars)" wm iconname $w "entry1" positionWindow $w -label $w.msg -font $font -wraplength 5i -justify left -text "Three different entries are displayed below. You can add characters by pointing, clicking and typing. The normal Motif editing characters are supported, along with many Emacs bindings. For example, Backspace and Control-h delete the character to the left of the insertion cursor and Delete and Control-d delete the chararacter to the right of the insertion cursor. For entries that are too large to fit in the window all at once, you can scan through the entries by dragging with mouse button2 pressed." +label $w.msg -font $font -wraplength 5i -justify left -text "Three different entries are displayed below. You can add characters by pointing, clicking and typing. The normal Motif editing characters are supported, along with many Emacs bindings. For example, Backspace and Control-h delete the character to the left of the insertion cursor and Delete and Control-d delete the chararacter to the right of the insertion cursor. For entries that are too large to fit in the window all at once, you can scan through the entries by dragging with mouse the middle mouse button pressed." pack $w.msg -side top ## See Code / Dismiss buttons diff --git a/library/demos/entry2.tcl b/library/demos/entry2.tcl index 9e3f4ef..6405d85 100644 --- a/library/demos/entry2.tcl +++ b/library/demos/entry2.tcl @@ -16,7 +16,7 @@ wm title $w "Entry Demonstration (with scrollbars)" wm iconname $w "entry2" positionWindow $w -label $w.msg -font $font -wraplength 5i -justify left -text "Three different entries are displayed below, with a scrollbar for each entry. You can add characters by pointing, clicking and typing. The normal Motif editing characters are supported, along with many Emacs bindings. For example, Backspace and Control-h delete the character to the left of the insertion cursor and Delete and Control-d delete the chararacter to the right of the insertion cursor. For entries that are too large to fit in the window all at once, you can scan through the entries with the scrollbars, or by dragging with mouse button2 pressed." +label $w.msg -font $font -wraplength 5i -justify left -text "Three different entries are displayed below, with a scrollbar for each entry. You can add characters by pointing, clicking and typing. The normal Motif editing characters are supported, along with many Emacs bindings. For example, Backspace and Control-h delete the character to the left of the insertion cursor and Delete and Control-d delete the chararacter to the right of the insertion cursor. For entries that are too large to fit in the window all at once, you can scan through the entries with the scrollbars, or by dragging with the middle mouse button pressed." pack $w.msg -side top ## See Code / Dismiss buttons diff --git a/library/demos/text.tcl b/library/demos/text.tcl index d1801d1..2736b88 100644 --- a/library/demos/text.tcl +++ b/library/demos/text.tcl @@ -57,8 +57,9 @@ can do to a text widget: 1. Scrolling. Use the scrollbar to adjust the view in the text window. -2. Scanning. Press mouse button 2 in the text window and drag up or down. -This will drag the text at high speed to allow you to scan its contents. +2. Scanning. Press the middle mouse button in the text window and drag up +or down. This will drag the text at high speed to allow you to scan its +contents. 3. Insert text. Press mouse button 1 to set the insertion cursor, then type text. What you type will be added to the widget. @@ -77,7 +78,8 @@ text, in which case it will replace the selected text. 6. Copy the selection. To copy the selection into this window, select what you want to copy (either here or in another application), then -click button 2 to copy the selection to the point of the mouse cursor. +click the middle mouse button to copy the selection to the point of the +mouse cursor. 7. Edit. Text widgets support the standard Motif editing characters plus many Emacs editing characters. Backspace and Control-h erase the diff --git a/library/entry.tcl b/library/entry.tcl index 2aab934..9cc9f6f 100644 --- a/library/entry.tcl +++ b/library/entry.tcl @@ -293,14 +293,27 @@ bind Entry <> { # A few additional bindings of my own. -bind Entry <2> { - if {!$tk_strictMotif} { - ::tk::EntryScanMark %W %x +if {[tk windowingsystem] ne "aqua"} { + bind Entry <2> { + if {!$tk_strictMotif} { + ::tk::EntryScanMark %W %x + } } -} -bind Entry { - if {!$tk_strictMotif} { - ::tk::EntryScanDrag %W %x + bind Entry { + if {!$tk_strictMotif} { + ::tk::EntryScanDrag %W %x + } + } +} else { + bind Entry <3> { + if {!$tk_strictMotif} { + ::tk::EntryScanMark %W %x + } + } + bind Entry { + if {!$tk_strictMotif} { + ::tk::EntryScanDrag %W %x + } } } diff --git a/library/spinbox.tcl b/library/spinbox.tcl index 1965ed8..f5a2ad3 100644 --- a/library/spinbox.tcl +++ b/library/spinbox.tcl @@ -280,14 +280,27 @@ bind Spinbox { # A few additional bindings of my own. -bind Spinbox <2> { - if {!$tk_strictMotif} { - ::tk::EntryScanMark %W %x +if {[tk windowingsystem] ne "aqua"} { + bind Spinbox <2> { + if {!$tk_strictMotif} { + ::tk::EntryScanMark %W %x + } } -} -bind Spinbox { - if {!$tk_strictMotif} { - ::tk::EntryScanDrag %W %x + bind Spinbox { + if {!$tk_strictMotif} { + ::tk::EntryScanDrag %W %x + } + } +} else { + bind Spinbox <3> { + if {!$tk_strictMotif} { + ::tk::EntryScanMark %W %x + } + } + bind Spinbox { + if {!$tk_strictMotif} { + ::tk::EntryScanDrag %W %x + } } } diff --git a/library/text.tcl b/library/text.tcl index bdfb78e..0fa37e7 100644 --- a/library/text.tcl +++ b/library/text.tcl @@ -429,14 +429,27 @@ bind Text { %W see insert } } -bind Text <2> { - if {!$tk_strictMotif} { - tk::TextScanMark %W %x %y +if {[tk windowingsystem] ne "aqua"} { + bind Text <2> { + if {!$tk_strictMotif} { + tk::TextScanMark %W %x %y + } } -} -bind Text { - if {!$tk_strictMotif} { - tk::TextScanDrag %W %x %y + bind Text { + if {!$tk_strictMotif} { + tk::TextScanDrag %W %x %y + } + } +} else { + bind Text <3> { + if {!$tk_strictMotif} { + tk::TextScanMark %W %x %y + } + } + bind Text { + if {!$tk_strictMotif} { + tk::TextScanDrag %W %x %y + } } } set ::tk::Priv(prevPos) {} diff --git a/library/ttk/entry.tcl b/library/ttk/entry.tcl index 45e3506..1ee6005 100644 --- a/library/ttk/entry.tcl +++ b/library/ttk/entry.tcl @@ -82,13 +82,20 @@ bind TEntry <> { %W instate {!readonly !disabled} { %W icursor @%x ; focus %W } } -## Button2 bindings: +## Button2 (Button3 on Aqua) bindings: # Used for scanning and primary transfer. -# Note: ButtonRelease-2 is mapped to <> in tk.tcl. -# -bind TEntry { ttk::entry::ScanMark %W %x } -bind TEntry { ttk::entry::ScanDrag %W %x } -bind TEntry { ttk::entry::ScanRelease %W %x } +# Note: ButtonRelease-2 (ButtonRelease-3 on Aqua) +# is mapped to <> in tk.tcl. +# +if {[tk windowingsystem] ne "aqua"} { + bind TEntry { ttk::entry::ScanMark %W %x } + bind TEntry { ttk::entry::ScanDrag %W %x } + bind TEntry { ttk::entry::ScanRelease %W %x } +} else { + bind TEntry { ttk::entry::ScanMark %W %x } + bind TEntry { ttk::entry::ScanDrag %W %x } + bind TEntry { ttk::entry::ScanRelease %W %x } +} bind TEntry <> { ttk::entry::ScanRelease %W %x } ## Keyboard navigation bindings: diff --git a/macosx/tkMacOSXMouseEvent.c b/macosx/tkMacOSXMouseEvent.c index f4156fe..dd50d0a 100644 --- a/macosx/tkMacOSXMouseEvent.c +++ b/macosx/tkMacOSXMouseEvent.c @@ -55,6 +55,7 @@ enum { TkWindow *winPtr = NULL, *grabWinPtr; Tk_Window tkwin; NSPoint local, global; + NSInteger button = -1; #if 0 NSTrackingArea *trackingArea = nil; NSInteger eventNumber, clickCount, buttonNumber; @@ -65,18 +66,19 @@ enum { TKLog(@"-[%@(%p) %s] %@", [self class], self, _cmd, theEvent); #endif switch (eventType) { - case NSMouseEntered: - case NSMouseExited: - case NSCursorUpdate: case NSLeftMouseDown: - case NSLeftMouseUp: case NSRightMouseDown: - case NSRightMouseUp: case NSOtherMouseDown: - case NSOtherMouseUp: case NSLeftMouseDragged: case NSRightMouseDragged: case NSOtherMouseDragged: + button = [theEvent buttonNumber] + Button1; + case NSMouseEntered: + case NSMouseExited: + case NSCursorUpdate: + case NSLeftMouseUp: + case NSRightMouseUp: + case NSOtherMouseUp: case NSMouseMoved: case NSTabletPoint: case NSTabletProximity: @@ -226,26 +228,8 @@ enum { */ unsigned int state = 0; - int button = [theEvent buttonNumber] + Button1; - EventRef eventRef = (EventRef)[theEvent eventRef]; - UInt32 buttons; - OSStatus err = GetEventParameter(eventRef, kEventParamMouseChord, - typeUInt32, NULL, sizeof(UInt32), NULL, &buttons); - - if (err == noErr) { - state |= (buttons & 0x1F) * Button1Mask; - } else if (button <= Button5) { - switch (eventType) { - case NSLeftMouseDown: - case NSRightMouseDown: - case NSLeftMouseDragged: - case NSRightMouseDragged: - case NSOtherMouseDown: - state |= TkGetButtonMask(button); - break; - default: - break; - } + if (button > 0) { + state |= TkGetButtonMask(button); } NSUInteger modifiers = [theEvent modifierFlags]; -- cgit v0.12