On Thu, 17 Feb 2000, Bernhard Zipp wrote:
> I am running vtcl under NT4.0 and I want to use in my applications the
> Windoze copy and paste. How can I enable or disable this function in
> vtcl? Sometimes, when I use an EDIT-widget I can copy the text content
> into the clipboard. But sometimes it doesn t work, even in the same
> application. I can find no significant difference in the code which is
> responsible for this behaviour. I didn t use any bind-commands or
> anything else which has to do with keyboard control.
Well, this is your lucky day!
It just happens that I have a general clipboard system that is easy to add
to any application. It works on both Windows and UNIX in the same way. It
gets applied to all entry and text widgets.
Please note that on UNIX, the clipboard and the XSelection are two
different "buffers", and they can contain different data. The XSelection
is what you highlight by dragging the mouse button 1. The following
functions copy the XSelection into the clipboard. After having done that,
and highlighting different text with button 1, button 2 will paste the
highlighted selection (which could be in another app or xterm), but the
following paste functions paste the clipboard contents.
While I'm at it, note that the Tcl/Tk widget options that say "export
selection" (eg Listbox) refers to this same XSelection buffer.
Lastly, while I'm at it still: It took me over three years to figure out
why pasting with button 2 into Tk widgets on UNIX would sometimes work and
sometimes not. If you move the mouse even one pixel while pressing button
2, the widgets think that you're dragging button 2 which is bound to
scroll features so it doesn't do the paste. You must hold the mouse
absolutely still.
There are no changes required for the following to work.
proc {clipboard_create} {} {
event add <<Cut>> <Control-Key-X>
event add <<Copy>> <Control-Key-C>
event add <<Paste>> <Control-Key-V>
set m .clipboardmenu
menu $m -tearoff 0
$m add command -label "Cut" -accel "Ctrl+X"
$m add command -label "Copy" -accel "Ctrl+C"
$m add command -label "Paste" -accel "Ctrl+V"
$m add command -label "Delete" -accel "Delete"
$m add separator
$m add command -label "Select All" -accel "Ctrl+/"
}
proc {clipboard_doit} {w opt} {
event generate $w <$opt>
}
proc {clipboard_post} {w x y} {
set m .clipboardmenu
if {[winfo class $w] == "Text"} {
set sel [$w tag ranges sel]
} {
if {[$w selection present]} {
set sel "1"
} {
set sel ""
}
}
if {$sel == ""} {
set selstate disabled
} {
set selstate normal
}
set editstate [$w cget -state]
if {$editstate == "disabled"} {
set cutstate $editstate
} {
set cutstate $selstate
}
if {[catch {selection get -displayof $w -selection CLIPBOARD} sel] ||
$sel == ""} {
set pastestate disabled
} {
set pastestate $editstate
}
$m entryconfig "Cut" -command "clipboard_doit $w <Cut>"
-state $cutstate
$m entryconfig "Copy" -command "clipboard_doit $w <Copy>"
-state $selstate
$m entryconfig "Paste" -command "clipboard_doit $w <Paste>"
-state $pastestate
$m entryconfig "Delete" -command "clipboard_doit $w Delete"
-state $cutstate
$m entryconfig "Select All" -command "clipboard_doit $w
Control-slash"
tk_popup $m $x $y
}
=======================
Then, in the main proc:
=======================
# Clipboard popup memu
clipboard_create
bind Text <3> "clipboard_post %W %X %Y"
bind Entry <3> "clipboard_post %W %X %Y"
bind Text <Enter> "+focus %W"
bind Entry <Enter> "+focus %W"
...RickM...
---------------------------------------------------------------------------
To unsubscribe from the Visual Tcl mailing list, please send a message
to [EMAIL PROTECTED] with "unsubscribe vtcl [EMAIL PROTECTED]" in the
message body (where [EMAIL PROTECTED] is your e-mail address).