diff options
Diffstat (limited to 'library')
-rw-r--r-- | library/console.tcl | 6 | ||||
-rw-r--r-- | library/entry.tcl | 8 | ||||
-rw-r--r-- | library/spinbox.tcl | 8 | ||||
-rw-r--r-- | library/text.tcl | 8 | ||||
-rw-r--r-- | library/tk.tcl | 34 |
5 files changed, 48 insertions, 16 deletions
diff --git a/library/console.tcl b/library/console.tcl index 472dcf5..e996ea5 100644 --- a/library/console.tcl +++ b/library/console.tcl @@ -4,7 +4,7 @@ # can be used by non-unix systems that do not have built-in support # for shells. # -# RCS: @(#) $Id: console.tcl,v 1.10 2000/11/02 22:55:16 hobbs Exp $ +# RCS: @(#) $Id: console.tcl,v 1.11 2001/07/03 01:03:16 hobbs Exp $ # # Copyright (c) 1995-1997 Sun Microsystems, Inc. # Copyright (c) 1998-2000 Ajuba Solutions. @@ -350,7 +350,7 @@ proc tkConsoleBind {win} { } } bind $win <Insert> { - catch {tkConsoleInsert %W [selection get -displayof %W]} + catch {tkConsoleInsert %W [::tk::GetSelection %W PRIMARY]} break } bind $win <KeyPress> { @@ -397,7 +397,7 @@ proc tkConsoleBind {win} { } bind $win <<Paste>> { catch { - set clip [selection get -displayof %W -selection CLIPBOARD] + set clip [::tk::GetSelection %W CLIPBOARD] set list [split $clip \n\r] tkConsoleInsert %W [lindex $list 0] foreach x [lrange $list 1 end] { diff --git a/library/entry.tcl b/library/entry.tcl index a826481..5392bcd 100644 --- a/library/entry.tcl +++ b/library/entry.tcl @@ -3,7 +3,7 @@ # This file defines the default bindings for Tk entry widgets and provides # procedures that help in implementing those bindings. # -# RCS: @(#) $Id: entry.tcl,v 1.14 2001/03/29 11:05:49 mdejong Exp $ +# RCS: @(#) $Id: entry.tcl,v 1.15 2001/07/03 01:03:16 hobbs Exp $ # # Copyright (c) 1992-1994 The Regents of the University of California. # Copyright (c) 1994-1997 Sun Microsystems, Inc. @@ -55,7 +55,7 @@ bind Entry <<Paste>> { %W delete sel.first sel.last } } - %W insert insert [selection get -displayof %W -selection CLIPBOARD] + %W insert insert [::tk::GetSelection %W CLIPBOARD] tkEntrySeeInsert %W } } @@ -210,7 +210,7 @@ if {[string equal $tcl_platform(platform) "macintosh"]} { # generates the <<Paste>> event, so we don't need to do anything here. if {[string compare $tcl_platform(platform) "windows"]} { bind Entry <Insert> { - catch {tkEntryInsert %W [selection get -displayof %W]} + catch {tkEntryInsert %W [::tk::GetSelection %W PRIMARY]} } } @@ -408,7 +408,7 @@ proc tkEntryPaste {w x} { global tkPriv $w icursor [tkEntryClosestGap $w $x] - catch {$w insert insert [selection get -displayof $w]} + catch {$w insert insert [::tk::GetSelection $w PRIMARY]} if {[string compare "disabled" [$w cget -state]]} {focus $w} } diff --git a/library/spinbox.tcl b/library/spinbox.tcl index b93479b..a1ba4f4 100644 --- a/library/spinbox.tcl +++ b/library/spinbox.tcl @@ -3,7 +3,7 @@ # This file defines the default bindings for Tk spinbox widgets and provides # procedures that help in implementing those bindings. # -# RCS: @(#) $Id: spinbox.tcl,v 1.1 2000/05/29 01:43:15 hobbs Exp $ +# RCS: @(#) $Id: spinbox.tcl,v 1.2 2001/07/03 01:03:16 hobbs Exp $ # # Copyright (c) 1992-1994 The Regents of the University of California. # Copyright (c) 1994-1997 Sun Microsystems, Inc. @@ -60,7 +60,7 @@ bind Spinbox <<Paste>> { %W delete sel.first sel.last } } - %W insert insert [selection get -displayof %W -selection CLIPBOARD] + %W insert insert [::tk::GetSelection %W CLIPBOARD] ::tk::spinbox::SeeInsert %W } } @@ -218,7 +218,7 @@ if {[string equal $tcl_platform(platform) "macintosh"]} { # generates the <<Paste>> event, so we don't need to do anything here. if {[string compare $tcl_platform(platform) "windows"]} { bind Spinbox <Insert> { - catch {::tk::spinbox::Insert %W [selection get -displayof %W]} + catch {::tk::spinbox::Insert %W [::tk::GetSelection %W PRIMARY]} } } @@ -504,7 +504,7 @@ proc ::tk::spinbox::Paste {w x} { global tkPriv $w icursor [::tk::spinbox::ClosestGap $w $x] - catch {$w insert insert [selection get -displayof $w]} + catch {$w insert insert [::tk::GetSelection $w PRIMARY]} if {[string equal "disabled" [$w cget -state]]} {focus $w} } diff --git a/library/text.tcl b/library/text.tcl index 79a49e1..38f2efc 100644 --- a/library/text.tcl +++ b/library/text.tcl @@ -3,7 +3,7 @@ # This file defines the default bindings for Tk text widgets and provides # procedures that help in implementing the bindings. # -# RCS: @(#) $Id: text.tcl,v 1.14 2001/03/29 11:05:49 mdejong Exp $ +# RCS: @(#) $Id: text.tcl,v 1.15 2001/07/03 01:03:16 hobbs Exp $ # # Copyright (c) 1992-1994 The Regents of the University of California. # Copyright (c) 1994-1997 Sun Microsystems, Inc. @@ -260,7 +260,7 @@ bind Text <<PasteSelection>> { } } bind Text <Insert> { - catch {tkTextInsert %W [selection get -displayof %W]} + catch {tkTextInsert %W [::tk::GetSelection %W PRIMARY]} } bind Text <KeyPress> { tkTextInsert %W %A @@ -627,7 +627,7 @@ proc tkTextKeyExtend {w index} { proc tkTextPaste {w x y} { $w mark set insert [tkTextClosestGap $w $x $y] - catch {$w insert insert [selection get -displayof $w]} + catch {$w insert insert [::tk::GetSelection $w PRIMARY]} if {[string equal [$w cget -state] "normal"]} {focus $w} } @@ -974,7 +974,7 @@ proc tk_textPaste w { $w delete sel.first sel.last } } - $w insert insert [selection get -displayof $w -selection CLIPBOARD] + $w insert insert [::tk::GetSelection $w CLIPBOARD] } } diff --git a/library/tk.tcl b/library/tk.tcl index daba5d6..64afbe7 100644 --- a/library/tk.tcl +++ b/library/tk.tcl @@ -3,7 +3,7 @@ # Initialization script normally executed in the interpreter for each # Tk-based application. Arranges class bindings for widgets. # -# RCS: @(#) $Id: tk.tcl,v 1.29 2001/03/31 05:46:10 hobbs Exp $ +# RCS: @(#) $Id: tk.tcl,v 1.30 2001/07/03 01:03:16 hobbs Exp $ # # Copyright (c) 1992-1994 The Regents of the University of California. # Copyright (c) 1994-1996 Sun Microsystems, Inc. @@ -151,6 +151,38 @@ proc ::tk::RestoreFocusGrab {grab focus {destroy destroy}} { } } +# ::tk::GetSelection -- +# This tries to obtain the default selection. On Unix, we first try +# and get a UTF8_STRING, a type supported by modern Unix apps for +# passing Unicode data safely. We fall back on the default STRING +# type otherwise. On Windows, only the STRING type is necessary. +# Arguments: +# w The widget for which the selection will be retrieved. +# Important for the -displayof property. +# sel The source of the selection (PRIMARY or CLIPBOARD) +# Results: +# Returns the selection, or an error if none could be found +# +if {[string equal $tcl_platform(platform) "unix"]} { + proc ::tk::GetSelection {w {sel PRIMARY}} { + if {[catch {selection get -displayof $w -selection $sel \ + -type UTF8_STRING} txt] \ + && [catch {selection get -displayof $w -selection $sel} txt]} { + return -code error "could not find default selection" + } else { + return $txt + } + } +} else { + proc ::tk::GetSelection {w {sel PRIMARY}} { + if {[catch {selection get -displayof $w -selection $sel} txt]} { + return -code error "could not find default selection" + } else { + return $txt + } + } +} + # tkScreenChanged -- # This procedure is invoked by the binding mechanism whenever the # "current" screen is changing. The procedure does two things. |