Changeset 17 for trunk/gui/scripts/mainwin.tcl
- Timestamp:
- Jun 11, 2005, 9:56:37 PM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gui/scripts/mainwin.tcl
r13 r17 13 13 # ====================================================================== 14 14 package require Itk 15 package require BLT 15 16 16 17 option add *MainWin.mode desktop widgetDefault … … 31 32 32 33 public method draw {option args} 34 public method syncCutBuffer {option args} 33 35 34 36 protected method _redraw {} 35 37 36 38 private variable _contents "" ;# frame containing app 39 private variable _sync ;# to sync current selection and cut buffer 37 40 private variable _bgscript "" ;# script of background drawing cmds 38 41 private variable _bgparser "" ;# parser for bgscript … … 96 99 set btags [bindtags $itk_component(hull)] 97 100 bindtags $itk_component(hull) [lappend btags RapptureMainWin] 101 102 set _sync(cutbuffer) "" 103 set _sync(selection) "" 104 syncCutBuffer ifneeded 105 } 106 107 # ---------------------------------------------------------------------- 108 # USAGE: syncCutBuffer ifneeded 109 # USAGE: syncCutBuffer transfer <offset> <maxchars> 110 # USAGE: syncCutBuffer lostselection 111 # 112 # Invoked automatically whenever the mouse pointer enters or leaves 113 # a main window to sync the cut buffer with the primary selection. 114 # This helps applications work properly with the "Copy/Paste with 115 # Desktop" option on the VNC applet for the nanoHUB. 116 # 117 # The "ifneeded" option syncs the cutbuffer and the primary selection 118 # if either one has new data. 119 # 120 # The "fromselection" option syncs from the primary selection to the 121 # cut buffer. If there's a primary selection, it gets copied to the 122 # cut buffer. 123 # ---------------------------------------------------------------------- 124 itcl::body Rappture::MainWin::syncCutBuffer {option args} { 125 set mainwin $itk_component(hull) 126 switch -- $option { 127 ifneeded { 128 # 129 # See if the incoming cut buffer has changed. 130 # If so, then sync the new input to the primary selection. 131 # 132 set s [blt::cutbuffer get] 133 if {"" != $s && ![string equal $s $_sync(cutbuffer)]} { 134 set _sync(cutbuffer) $s 135 136 if {![string equal $s $_sync(selection)] 137 && [selection own -selection PRIMARY] != $mainwin} { 138 set _sync(selection) $s 139 140 clipboard clear 141 clipboard append -- $s 142 selection handle -selection PRIMARY $mainwin \ 143 [itcl::code $this syncCutBuffer transfer] 144 selection own -selection PRIMARY -command \ 145 [itcl::code $this syncCutBuffer lostselection] \ 146 $mainwin 147 } 148 } 149 150 # 151 # See if the selection has changed. If so, then sync 152 # the new input to the cut buffer, so it's available 153 # outside the VNC client. 154 # 155 set s "" 156 if {[catch {selection get -selection PRIMARY} s] || "" == $s} { 157 if {[catch {clipboard get} s]} { 158 set s "" 159 } 160 } 161 if {"" != $s && ![string equal $s $_sync(selection)]} { 162 set _sync(selection) $s 163 blt::cutbuffer set $s 164 } 165 166 # do this again soon 167 after 1000 [itcl::code $this syncCutBuffer ifneeded] 168 } 169 transfer { 170 if {[llength $args] != 2} { 171 error "wrong # args: should be \"syncCutBuffer transfer offset max\"" 172 } 173 set offset [lindex $args 0] 174 set maxchars [lindex $args 1] 175 return [string range $_currseln $offset [expr {$offset+$maxchars-1}]] 176 } 177 lostselection { 178 # nothing to do 179 } 180 default { 181 error "bad option \"$option\": should be ifneeded, transfer, or lostselection" 182 } 183 } 98 184 } 99 185 … … 127 213 } 128 214 215 set bd 0 ;# optional border 129 216 set sw [winfo width $itk_component(area)] 130 217 set sh [winfo height $itk_component(area)] … … 133 220 set w [winfo reqwidth $itk_component(app)] 134 221 set h [winfo reqheight $itk_component(app)] 135 if {$w > $sw } {136 set $w $sw222 if {$w > $sw-2*$bd} { 223 set $w [expr {$sw-2*$bd}] 137 224 set clip 1 138 225 } … … 141 228 n { 142 229 set x [expr {$sw/2}] 143 set y 0230 set y $bd 144 231 } 145 232 s { 146 233 set x [expr {$sw/2}] 147 set y $sh234 set y [expr {$sh-$bd}] 148 235 } 149 236 center { … … 152 239 } 153 240 w { 154 set x 0241 set x $bd 155 242 set y [expr {$sh/2}] 156 243 } 157 244 e { 158 set x $sw245 set x [expr {$sw-$bd}] 159 246 set y [expr {$sh/2}] 160 247 } 161 248 nw { 162 set x 0163 set y 0249 set x $bd 250 set y $bd 164 251 } 165 252 ne { 166 set x $sw167 set y 0253 set x [expr {$sw-$bd}] 254 set y $bd 168 255 } 169 256 sw { 170 set x 0171 set y $sh257 set x $bd 258 set y [expr {$sh-$bd}] 172 259 } 173 260 se { 174 set x $sw175 set y $sh261 set x [expr {$sw-$bd}] 262 set y [expr {$sh-$bd}] 176 263 } 177 264 }
Note: See TracChangeset
for help on using the changeset viewer.