Comment 4 for bug 297970

Revision history for this message
mirkobau (j-launchpad-mirkobau-it) wrote : Re: chat-write-area looses focus when the scrollbar appears (Windows XP)

SOLVED!
Here's the correction; it only involves the function UI::ScrollSet from libs/UI.tcl:

# UI::ScrollSet --
#
# Command for auto hide/show scrollbars.

# 12th June 2009
# corrected a bug (badly but..hey, it works!) by Mirko Graziani (<email address hidden>)
# The problem is: scrollbars take the focus when they appear.
# My solution is:
# i'll remember which object had focus before the scrollbar became visible,
# and re-set the focus on the correct object everytime this funcion is called.
# Maybe setting focus *every* time is redundant, and could be not very elegant,
# but i know too little Coccinella source code to filter the cases.
#
# for some other info, see Coccinella bug: https://bugs.launchpad.net/bugs/297970

proc ::UI::ScrollSet {wscrollbar geocmd offset size} {
   # get the geometry manager
   set manager [lindex $geocmd 0]
   # Create the name for the focus
   set wfocus $wscrollbar.focus
   # that name must survive
   global $wfocus
   if {($offset != 0.0) || ($size != 1.0)} {
      # If the scrollbar hasn't a geomanager,
      # it means that this time it will appear (and get a geomanager)
      # then i record the name of the current focused object
      if {[string equal [$manager info $wscrollbar] ""]} {
         set $wfocus [focus]
      }
      eval $geocmd
      $wscrollbar set $offset $size
   } else {
      $manager forget $wscrollbar
   }

   # Whatever would happen, i always will set the focus
   # on the "current focused object" recorded in the lines above.
   if {[info exists $wfocus]} {
      focus [set $wfocus]
   }
}