Ignore:
Timestamp:
Oct 22, 2010, 4:06:10 PM (14 years ago)
Author:
gah
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gui/scripts/mainwin.tcl

    r1342 r1929  
    3838bind Entry <<Paste>> {
    3939    catch {
    40         # always replace existing selection
    41         catch { %W delete sel.first sel.last }
    42 
    43         %W insert insert [::tk::GetSelection %W CLIPBOARD]
    44         tk::EntrySeeInsert %W
     40        # always replace existing selection
     41        catch { %W delete sel.first sel.last }
     42
     43        %W insert insert [::tk::GetSelection %W CLIPBOARD]
     44        tk::EntrySeeInsert %W
    4545    }
    4646}
     
    4848    global tcl_platform
    4949    if {![catch {::tk::GetSelection $w CLIPBOARD} sel]} {
    50         if {[catch {$w cget -autoseparators} oldSeparator]} {
    51             # in case we're using an older version of Tk
    52             set oldSeparator 0
    53         }
    54         if { $oldSeparator } {
    55             $w configure -autoseparators 0
    56             $w edit separator
    57         }
    58 
    59         # always replace existing selection
    60         catch { $w delete sel.first sel.last }
    61         $w insert insert $sel
    62 
    63         if { $oldSeparator } {
    64             $w edit separator
    65             $w configure -autoseparators 1
    66         }
     50        if {[catch {$w cget -autoseparators} oldSeparator]} {
     51            # in case we're using an older version of Tk
     52            set oldSeparator 0
     53        }
     54        if { $oldSeparator } {
     55            $w configure -autoseparators 0
     56            $w edit separator
     57        }
     58
     59        # always replace existing selection
     60        catch { $w delete sel.first sel.last }
     61        $w insert insert $sel
     62
     63        if { $oldSeparator } {
     64            $w edit separator
     65            $w configure -autoseparators 1
     66        }
    6767    }
    6868}
     
    8888    private variable _bgparser ""  ;# parser for bgscript
    8989}
    90                                                                                
     90                                                                               
    9191itk::usual MainWin {
    9292    keep -background -cursor foreground -font
     
    9898itcl::body Rappture::MainWin::constructor {args} {
    9999    itk_component add area {
    100         canvas $itk_interior.area
     100        canvas $itk_interior.area
    101101    } {
    102         usual
    103         rename -background -bgcolor bgColor Background
     102        usual
     103        rename -background -bgcolor bgColor Background
    104104    }
    105105    pack $itk_component(area) -expand yes -fill both
     
    107107
    108108    itk_component add app {
    109         frame $itk_component(area).app
     109        frame $itk_component(area).app
    110110    } {
    111         usual
    112         keep -borderwidth -relief
     111        usual
     112        keep -borderwidth -relief
    113113    }
    114114    bind $itk_component(app) <Configure> "
    115         after cancel [itcl::code $this _redraw]
    116         after idle [itcl::code $this _redraw]
     115        after cancel [itcl::code $this _redraw]
     116        after idle [itcl::code $this _redraw]
    117117    "
    118118
    119119    itk_component add menu {
    120         menu $itk_interior.menu
     120        menu $itk_interior.menu
    121121    }
    122122    itk_component add filemenu {
    123         menu $itk_component(menu).file
     123        menu $itk_component(menu).file
    124124    }
    125125    $itk_component(menu) add cascade -label "File" -underline 0 \
    126         -menu $itk_component(filemenu)
     126        -menu $itk_component(filemenu)
    127127    $itk_component(filemenu) add command -label "Exit" -underline 1 \
    128         -command {destroy .}
     128        -command {destroy .}
    129129
    130130    #
     
    184184    set mainwin $itk_component(hull)
    185185    switch -- $option {
    186         ifneeded {
    187             #
    188             # See if the incoming cut buffer has changed.
    189             # If so, then sync the new input to the primary selection.
    190             #
    191             set s [blt::cutbuffer get]
    192             if {"" != $s && ![string equal $s $_sync(cutbuffer)]} {
    193                 #
    194                 # Convert any \r's in the cutbuffer to \n's.
    195                 #
    196                 if {[string first "\r" $s] >= 0} {
    197                     regsub -all "\r\n" $s "\n" s
    198                     regsub -all "\r" $s "\n" s
    199                     blt::cutbuffer set $s
    200                 }
    201 
    202                 set _sync(cutbuffer) $s
    203 
    204                 if {![string equal $s $_sync(selection)]
    205                       && [selection own -selection PRIMARY] != $mainwin} {
    206                     set _sync(selection) $s
    207 
    208                     clipboard clear
    209                     clipboard append -- $s
    210                     selection handle -selection PRIMARY $mainwin \
    211                         [itcl::code $this syncCutBuffer transfer]
    212                     selection own -selection PRIMARY -command \
    213                         [itcl::code $this syncCutBuffer lostselection] \
    214                         $mainwin
    215                 }
    216             }
    217 
    218             #
    219             # See if the selection has changed.  If so, then sync
    220             # the new input to the cut buffer, so it's available
    221             # outside the VNC client.
    222             #
    223             if {[catch {selection get -selection PRIMARY} s]} {
    224                 set s ""
    225             }
    226             if {"" != $s && ![string equal $s $_sync(selection)]} {
    227                 set _sync(selection) $s
    228                 blt::cutbuffer set $s
    229             }
    230 
    231             # do this again soon
    232             after 1000 [itcl::code $this syncCutBuffer ifneeded]
    233         }
    234         transfer {
    235             if {[llength $args] != 2} {
    236                 error "wrong # args: should be \"syncCutBuffer transfer offset max\""
    237             }
    238             set offset [lindex $args 0]
    239             set maxchars [lindex $args 1]
    240             return [string range $_currseln $offset [expr {$offset+$maxchars-1}]]
    241         }
    242         lostselection {
    243             # nothing to do
    244         }
    245         default {
    246             error "bad option \"$option\": should be ifneeded, transfer, or lostselection"
    247         }
     186        ifneeded {
     187            #
     188            # See if the incoming cut buffer has changed.
     189            # If so, then sync the new input to the primary selection.
     190            #
     191            set s [blt::cutbuffer get]
     192            if {"" != $s && ![string equal $s $_sync(cutbuffer)]} {
     193                #
     194                # Convert any \r's in the cutbuffer to \n's.
     195                #
     196                if {[string first "\r" $s] >= 0} {
     197                    regsub -all "\r\n" $s "\n" s
     198                    regsub -all "\r" $s "\n" s
     199                    blt::cutbuffer set $s
     200                }
     201
     202                set _sync(cutbuffer) $s
     203
     204                if {![string equal $s $_sync(selection)]
     205                      && [selection own -selection PRIMARY] != $mainwin} {
     206                    set _sync(selection) $s
     207
     208                    clipboard clear
     209                    clipboard append -- $s
     210                    selection handle -selection PRIMARY $mainwin \
     211                        [itcl::code $this syncCutBuffer transfer]
     212                    selection own -selection PRIMARY -command \
     213                        [itcl::code $this syncCutBuffer lostselection] \
     214                        $mainwin
     215                }
     216            }
     217
     218            #
     219            # See if the selection has changed.  If so, then sync
     220            # the new input to the cut buffer, so it's available
     221            # outside the VNC client.
     222            #
     223            if {[catch {selection get -selection PRIMARY} s]} {
     224                set s ""
     225            }
     226            if {"" != $s && ![string equal $s $_sync(selection)]} {
     227                set _sync(selection) $s
     228                blt::cutbuffer set $s
     229            }
     230
     231            # do this again soon
     232            after 1000 [itcl::code $this syncCutBuffer ifneeded]
     233        }
     234        transfer {
     235            if {[llength $args] != 2} {
     236                error "wrong # args: should be \"syncCutBuffer transfer offset max\""
     237            }
     238            set offset [lindex $args 0]
     239            set maxchars [lindex $args 1]
     240            return [string range $_currseln $offset [expr {$offset+$maxchars-1}]]
     241        }
     242        lostselection {
     243            # nothing to do
     244        }
     245        default {
     246            error "bad option \"$option\": should be ifneeded, transfer, or lostselection"
     247        }
    248248    }
    249249}
     
    274274    $itk_component(area) delete all
    275275    if {$itk_option(-mode) == "web"} {
    276         if {[catch {$_bgparser eval $itk_option(-bgscript)} result]} {
    277             bgerror "$result\n    (while redrawing application background)"
    278         }
    279 
    280         set bd 0  ;# optional border
    281         set sw [winfo width $itk_component(area)]
    282         set sh [winfo height $itk_component(area)]
    283 
    284         set clip 0
    285         set w [winfo reqwidth $itk_component(app)]
    286         set h [winfo reqheight $itk_component(app)]
    287         if {$w > $sw-2*$bd} {
    288             set $w [expr {$sw-2*$bd}]
    289             set clip 1
    290         }
    291 
    292         set anchor $itk_option(-anchor)
    293         switch -- $itk_option(-anchor) {
    294             n {
    295                 set x [expr {$sw/2}]
    296                 set y $bd
    297             }
    298             s {
    299                 set x [expr {$sw/2}]
    300                 set y [expr {$sh-$bd}]
    301             }
    302             center {
    303                 set x [expr {$sw/2}]
    304                 set y [expr {$sh/2}]
    305             }
    306             w {
    307                 set x $bd
    308                 set y [expr {$sh/2}]
    309             }
    310             e {
    311                 set x [expr {$sw-$bd}]
    312                 set y [expr {$sh/2}]
    313             }
    314             nw {
    315                 set x $bd
    316                 set y $bd
    317             }
    318             ne {
    319                 set x [expr {$sw-$bd}]
    320                 set y $bd
    321             }
    322             sw {
    323                 set x $bd
    324                 set y [expr {$sh-$bd}]
    325             }
    326             se {
    327                 set x [expr {$sw-$bd}]
    328                 set y [expr {$sh-$bd}]
    329             }
    330             fill {
    331                 set anchor nw
    332                 set x $bd
    333                 set y $bd
    334                 set w [expr {$sw-2*$bd}]
    335                 set h [expr {$sh-2*$bd}]
    336                 set clip 1
    337             }
    338         }
    339 
    340         # if the app is too big, use w/h. otherwise, 0,0 for default size
    341         if {!$clip} {
    342             set w 0
    343             set h 0
    344         }
    345 
    346         $itk_component(area) create window $x $y \
    347             -anchor $anchor -window $itk_component(app) \
    348             -width $w -height $h
     276        if {[catch {$_bgparser eval $itk_option(-bgscript)} result]} {
     277            bgerror "$result\n    (while redrawing application background)"
     278        }
     279
     280        set bd 0  ;# optional border
     281        set sw [winfo width $itk_component(area)]
     282        set sh [winfo height $itk_component(area)]
     283
     284        set clip 0
     285        set w [winfo reqwidth $itk_component(app)]
     286        set h [winfo reqheight $itk_component(app)]
     287        if {$w > $sw-2*$bd} {
     288            set $w [expr {$sw-2*$bd}]
     289            set clip 1
     290        }
     291
     292        set anchor $itk_option(-anchor)
     293        switch -- $itk_option(-anchor) {
     294            n {
     295                set x [expr {$sw/2}]
     296                set y $bd
     297            }
     298            s {
     299                set x [expr {$sw/2}]
     300                set y [expr {$sh-$bd}]
     301            }
     302            center {
     303                set x [expr {$sw/2}]
     304                set y [expr {$sh/2}]
     305            }
     306            w {
     307                set x $bd
     308                set y [expr {$sh/2}]
     309            }
     310            e {
     311                set x [expr {$sw-$bd}]
     312                set y [expr {$sh/2}]
     313            }
     314            nw {
     315                set x $bd
     316                set y $bd
     317            }
     318            ne {
     319                set x [expr {$sw-$bd}]
     320                set y $bd
     321            }
     322            sw {
     323                set x $bd
     324                set y [expr {$sh-$bd}]
     325            }
     326            se {
     327                set x [expr {$sw-$bd}]
     328                set y [expr {$sh-$bd}]
     329            }
     330            fill {
     331                set anchor nw
     332                set x $bd
     333                set y $bd
     334                set w [expr {$sw-2*$bd}]
     335                set h [expr {$sh-2*$bd}]
     336                set clip 1
     337            }
     338        }
     339
     340        # if the app is too big, use w/h. otherwise, 0,0 for default size
     341        if {!$clip} {
     342            set w 0
     343            set h 0
     344        }
     345
     346        $itk_component(area) create window $x $y \
     347            -anchor $anchor -window $itk_component(app) \
     348            -width $w -height $h
    349349    }
    350350}
     
    355355itcl::configbody Rappture::MainWin::mode {
    356356    switch -- $itk_option(-mode) {
    357         desktop {
    358             component hull configure -menu $itk_component(hull).menu
    359             pack $itk_component(app) -expand yes -fill both
    360             wm geometry $itk_component(hull) ""
    361         }
    362         web {
    363             component hull configure -menu ""
    364             pack forget $itk_component(app)
    365             set wx [winfo screenwidth $itk_component(hull)]
    366             set wy [winfo screenheight $itk_component(hull)]
    367             wm geometry $itk_component(hull) ${wx}x${wy}+0+0
    368             _redraw
    369         }
    370         default {
    371             error "bad value \"$itk_option(-mode)\": should be desktop or web"
    372         }
     357        desktop {
     358            component hull configure -menu $itk_component(hull).menu
     359            pack $itk_component(app) -expand yes -fill both
     360            wm geometry $itk_component(hull) ""
     361        }
     362        web {
     363            component hull configure -menu ""
     364            pack forget $itk_component(app)
     365            set wx [winfo screenwidth $itk_component(hull)]
     366            set wy [winfo screenheight $itk_component(hull)]
     367            wm geometry $itk_component(hull) ${wx}x${wy}+0+0
     368            _redraw
     369        }
     370        default {
     371            error "bad value \"$itk_option(-mode)\": should be desktop or web"
     372        }
    373373    }
    374374}
     
    386386itcl::configbody Rappture::MainWin::anchor {
    387387    if {[lsearch {n s e w ne nw se sw center fill} $itk_option(-anchor)] < 0} {
    388         error "bad anchor \"$itk_option(-anchor)\""
     388        error "bad anchor \"$itk_option(-anchor)\""
    389389    }
    390390    _redraw
Note: See TracChangeset for help on using the changeset viewer.