global xfConf
global tkVersion
if {![info exists xfConf(macBindings)]} {
  set xfConf(macBindings) 0
}

bind Scale <Any-Enter> {# xf ignore me 8
    if $tk_strictMotif {
	set tk_priv(activeFg) [lindex [%W config -activeforeground] 4]
	%W config -activeforeground [lindex [%W config -sliderforeground] 4]
    } {
      global tk_xfScale
      set tk_xfScale(focus) [focus]
      focus %W
    }
}
bind Scale <Any-Leave> {# xf ignore me 8
    if {$tk_strictMotif && ($tk_priv(buttons) == 0)} {
	%W config -activeforeground $tk_priv(activeFg)
    } {
      global tk_xfScale
      catch "focus $tk_xfScale(focus)"
      set tk_xfScale(focus) ""
    }
}
bind Scale <Any-ButtonPress> {# xf ignore me 8
  incr tk_priv(buttons)}
bind Scale <Any-ButtonRelease> {# xf ignore me 8
  incr tk_priv(buttons) -1}
bind Scale <Left> {# xf ignore me 8
  %W set [expr [%W get]-1]}
bind Scale <Down> {# xf ignore me 8
  %W set [expr [%W get]-1]}
bind Scale <Right> {# xf ignore me 8
  %W set [expr [%W get]+1]}
bind Scale <Up> {# xf ignore me 8
  %W set [expr [%W get]+1]}
bind Scale <Prior> {# xf ignore me 8
  %W set [expr [%W get]-10]}
bind Scale <Next> {# xf ignore me 8
  %W set [expr [%W get]+10]}
bind Scale <Home> {# xf ignore me 8
  %W set [lindex [%W config -from] 4]}
bind Scale <End> {# xf ignore me 8
  %W set [lindex [%W config -to] 4]}

bind Text <Left> {# xf ignore me 8
  %W mark set insert insert-1c; %W yview -pickplace insert}
bind Text <Right> {# xf ignore me 8
  %W mark set insert insert+1c; %W yview -pickplace insert}
bind Text <Up> {# xf ignore me 8
  %W mark set insert insert-1l; %W yview -pickplace insert}
bind Text <Down> {# xf ignore me 8
  %W mark set insert insert+1l; %W yview -pickplace insert}
bind Text <Delete> {# xf ignore me 8
  tk_textBackspace %W; %W yview -pickplace insert}
bind Text <Control-a> {# xf ignore me 8
  %W mark set insert "insert linestart"; %W yview -pickplace insert}
bind Text <Control-b> {# xf ignore me 8
  %W mark set insert insert-1c; %W yview -pickplace insert}
bind Text <Control-d> {# xf ignore me 8
  %W delete insert insert+1c; %W yview -pickplace insert}
bind Text <Control-e> {# xf ignore me 8
  %W mark set insert "insert lineend"; %W yview -pickplace insert}
bind Text <Control-f> {# xf ignore me 8
  %W mark set insert insert+1c; %W yview -pickplace insert}
bind Text <Meta-h> {# xf ignore me 8
  %W delete "insert linestart" insert; %W yview -pickplace insert}
bind Text <Control-i> {# xf ignore me 8
  %W inser insert \t; %W yview -pickplace insert}
bind Text <Control-j> {# xf ignore me 8
  %W inser insert \n; %W yview -pickplace insert}
bind Text <Control-k> {# xf ignore me 8
  if {[%W compare insert == "insert lineend"]} {
    %W delete insert "insert lineend +1c"
    %W yview -pickplace insert
  } {
    %W delete insert "insert lineend"
    %W yview -pickplace insert}}
bind Text <Control-l> {# xf ignore me 8
  %W yview -pickplace insert}
bind Text <Control-m> {# xf ignore me 8
  %W inser insert \n; %W yview -pickplace insert}
bind Text <Control-n> {# xf ignore me 8
  %W mark set insert insert+1l; %W yview -pickplace insert}
bind Text <Control-o> {# xf ignore me 8
  %W inser insert \n; %W yview -pickplace insert}
bind Text <Control-p> {# xf ignore me 8
  %W mark set insert insert-1l; %W yview -pickplace insert}
bind Text <Control-w> {# xf ignore me 8
  catch "%W delete sel.first sel.last"}
bind Text <Control-y> {# xf ignore me 8
  %W insert insert "[GetSelection]"; %W yview -pickplace insert}
bind Text <Home> {# xf ignore me 8 
  %W mark set insert 1.0; %W yview -pickplace insert}
bind Text <End> {# xf ignore me 8
  %W mark set insert end; %W yview -pickplace insert}
bind Text <Prior> {# xf ignore me 8
  set xfCounter [lindex [%W config -height] 4]
  while {$xfCounter > 0} {
    %W mark set insert insert-1l
    incr xfCounter -1
  }
  %W yview -pickplace insert}
bind Text <Next> {# xf ignore me 8
  set xfCounter [lindex [%W config -height] 4]
  while {$xfCounter > 0} {
    %W mark set insert insert+1l
    incr xfCounter -1
  }
  %W yview -pickplace insert}

if {$xfConf(macBindings)} {
bind Text <Meta-c> {# xf ignore me 8
  global tk_priv(xfTextCutBuffer)
  if {![catch "%W get sel.first sel.last" select]} {
    if {"$select" != ""} {
      set tk_priv(xfTextCutBuffer) $select
    }
  }}
bind Text <Meta-v> {# xf ignore me 8
  global tk_priv(xfTextCutBuffer)
  if {[info exists tk_priv(xfTextCutBuffer)]} {
    if {![catch "%W get sel.first sel.last" select]} {
      set index [%W index sel.first]
      %W delete sel.first sel.last
      %W insert $index "$tk_priv(xfTextCutBuffer)"
    } {
      %W insert insert "$tk_priv(xfTextCutBuffer)"
    }
  } {
    %W insert insert "[GetSelection]"
  }
  %W yview -pickplace insert}
bind Text <Meta-x> {# xf ignore me 8
  global tk_priv(xfTextCutBuffer)
  if {![catch "%W get sel.first sel.last" select]} {
    if {"$select" != ""} {
      set tk_priv(xfTextCutBuffer) $select
    }
  }
  catch "%W delete sel.first sel.last"}
} {
bind Text <Meta-v> {# xf ignore me 8
  set xfCounter [lindex [%W config -height] 4]
  while {$xfCounter > 0} {
    %W mark set insert insert-1l
    incr xfCounter -1
  }
  %W yview -pickplace insert}
bind Text <Control-v> {# xf ignore me 8
  set xfCounter [lindex [%W config -height] 4]
  while {$xfCounter > 0} {
    %W mark set insert insert+1l
    incr xfCounter -1
  }
  %W yview -pickplace insert}
}


if {$tkVersion >= 3.0} {
bind Entry <Right> {# xf ignore me 8
  %W icursor [expr [%W index insert]+1]; tk_entrySeeCaret %W }
bind Entry <Left> {# xf ignore me 8
  %W icursor [expr [%W index insert]-1]; tk_entrySeeCaret %W }
bind Entry <Control-a> {# xf ignore me 8
  %W icursor 0; %W view 0}
bind Entry <Control-b> {# xf ignore me 8
  %W icursor [expr [%W index insert]-1]; tk_entrySeeCaret %W}
bind Entry <Control-d> {# xf ignore me 8
  %W delete [%W index insert]; tk_entrySeeCaret %W }
bind Entry <Control-e> {# xf ignore me 8
  %W icursor end; tk_entrySeeCaret %W}
bind Entry <Control-f> {# xf ignore me 8
  %W icursor [expr [%W index insert]+1]; tk_entrySeeCaret %W}
bind Entry <Control-h> {# xf ignore me 8
  tk_entryBackspace %W; tk_entrySeeCaret %W}
bind Entry <Meta-h> {# xf ignore me 8
  %W delete 0 insert; %W view insert}
bind Entry <Control-i> {# xf ignore me 8
  %W insert insert \t; tk_entrySeeCaret %W}
bind Entry <Control-k> {# xf ignore me 8
  %W delete insert end; tk_entrySeeCaret %W}
bind Entry <Control-l> {# xf ignore me 8
  tk_entrySeeCaret %W}
bind Entry <Control-v> {# xf ignore me 8
  %W insert insert "[GetSelection]"; tk_entrySeeCaret %W}
bind Entry <Control-w> {# xf ignore me 8
  catch "%W delete sel.first sel.last"; tk_entrySeeCaret %W}
bind Entry <Control-y> {# xf ignore me 8
  %W insert insert "[GetSelection]"; tk_entrySeeCaret %W}
if {$xfConf(macBindings)} {
bind Entry <Meta-c> {# xf ignore me 8
  global tk_priv(xfEntryCutBuffer)
  if {![catch "%W index sel.first"]} {
    set select [string range [%W get] [%W index sel.first] [%W index sel.last]]
    if {"$select" != ""} {
      set tk_priv(xfEntryCutBuffer) $select
    }
  }
  tk_entrySeeCaret %W}
bind Entry <Meta-v> {# xf ignore me 8
  global tk_priv(xfEntryCutBuffer)
  if {[info exists tk_priv(xfEntryCutBuffer)]} {
    if {![catch "%W index sel.first"]} {
      set index [%W index sel.first]
      %W delete sel.first sel.last
      %W insert $index "$tk_priv(xfEntryCutBuffer)"
    } {
      %W insert insert "$tk_priv(xfEntryCutBuffer)"
    }
  } {
    %W insert insert "[GetSelection]"
  }
  tk_entrySeeCaret %W}
bind Entry <Meta-x> {# xf ignore me 8
  global tk_priv(xfEntryCutBuffer)
  if {![catch "%W index sel.first"]} {
    set select [string range [%W get] [%W index sel.first] [%W index sel.last]]
    if {"$select" != ""} {
      set tk_priv(xfEntryCutBuffer) $select
    }
  }
  catch "%W delete sel.first sel.last"
  tk_entrySeeCaret %W}
}
} {
bind Entry <Right> {# xf ignore me 8
  %W cursor [expr [%W index cursor]+1]; tk_entrySeeCaret %W }
bind Entry <Left> {# xf ignore me 8
  %W cursor [expr [%W index cursor]-1]; tk_entrySeeCaret %W }
bind Entry <Control-a> {# xf ignore me 8
  %W cursor 0; %W view 0}
bind Entry <Control-b> {# xf ignore me 8
  %W cursor [expr [%W index cursor]-1]; tk_entrySeeCaret %W}
bind Entry <Control-d> {# xf ignore me 8
  %W delete [%W index cursor]; tk_entrySeeCaret %W }
bind Entry <Control-e> {# xf ignore me 8
  %W cursor end; tk_entrySeeCaret %W}
bind Entry <Control-f> {# xf ignore me 8
  %W cursor [expr [%W index cursor]+1]; tk_entrySeeCaret %W}
bind Entry <Control-h> {# xf ignore me 8
  tk_entryBackspace %W; tk_entrySeeCaret %W}
bind Entry <Meta-h> {# xf ignore me 8
  %W delete 0 cursor; %W view cursor}
bind Entry <Control-i> {# xf ignore me 8
  %W insert cursor \t; tk_entrySeeCaret %W}
bind Entry <Control-k> {# xf ignore me 8
  %W delete cursor end; tk_entrySeeCaret %W}
bind Entry <Control-l> {# xf ignore me 8
  tk_entrySeeCaret %W}
bind Entry <Control-v> {# xf ignore me 8
  %W insert cursor "[GetSelection]"; tk_entrySeeCaret %W}
bind Entry <Control-w> {# xf ignore me 8
  catch "%W delete sel.first sel.last"; tk_entrySeeCaret %W}
bind Entry <Control-y> {# xf ignore me 8
  %W insert cursor "[GetSelection]"; tk_entrySeeCaret %W}
if {$xfConf(macBindings)} {
bind Entry <Meta-c> {# xf ignore me 8
  global tk_priv(xfEntryCutBuffer)
  if {![catch "%W index sel.first"]} {
    set select [string range [%W get] [%W index sel.first] [%W index sel.last]]
    if {"$select" != ""} {
      set tk_priv(xfEntryCutBuffer) $select
    }
  }
  tk_entrySeeCaret %W}
bind Entry <Meta-v> {# xf ignore me 8
  global tk_priv(xfEntryCutBuffer)
  if {[info exists tk_priv(xfEntryCutBuffer)]} {
    if {![catch "%W index sel.first"]} {
      set index [%W index sel.first]
      %W delete sel.first sel.last
      %W insert $index "$tk_priv(xfEntryCutBuffer)"
    } {
      %W insert cursor "$tk_priv(xfEntryCutBuffer)"
    }
  } {
    %W insert cursor "[GetSelection]"
  }
  tk_entrySeeCaret %W}
bind Entry <Meta-x> {# xf ignore me 8
  global tk_priv(xfEntryCutBuffer)
  if {![catch "%W index sel.first"]} {
    set select [string range [%W get] [%W index sel.first] [%W index sel.last]]
    if {"$select" != ""} {
      set tk_priv(xfEntryCutBuffer) $select
    }
  }
  catch "%W delete sel.first sel.last"
  tk_entrySeeCaret %W}
}
}

