Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

MouseWheel TIP #171 interaction with canvas

199 views
Skip to first unread message

Harald Oehlmann

unread,
Mar 7, 2012, 4:26:03 AM3/7/12
to
I have pasted the code of TIP #171
http://www.tcl.tk/cgi-bin/tct/tip/171.html
into my TCL 8.5 application using BWidgets and TTK

There are funny interactions:
when having a BWidget NoteBook widget with a client with a scrollbar
and I klick on a NoteBook tab and I use the scrollwhell, The whole
Notebook is scrolled out and gray place is shown below.

I suppose that the canvas within the Notebook implementation sets the
scrolling region to a higher value and thus, the Canvas is scrolled.

Inside the NoteBook, I have a BWidget ScrolledWindow environment.
This widget is not scrolled by the mousewheel.
But if the mouse is over the Scrollbar of the ScrolledWindw, the
scrolled window is scrolled now (without click).
This did not work before.

Does anybody have looked to those issues ?

When starting BWidget under TCL8.6, this misbehaviour will show-up,
right ?

Martyn, you told me, you have work done here. Do you have any
comments ?

Thank you for any ideas,
Harald

mse...@gmail.com

unread,
Mar 7, 2012, 5:10:06 AM3/7/12
to

Hi Harald,

Yes I have solved this problem in some of my programs, my MouseWheel handler which is bound to all widgets (I still use a TCL which needs keyboard for the mousewhell) handles the specific case for my notebook and uses the "NoteBook::_xview" internal proc to simulate the action of the two dynamic arrow buttons on the BWidget::NoteBook.
So now my notebook tabs scroll left/right with the mousewheel just like firefox.

# Scroll the Notebook canvas but only by 1 unit
if {$w eq "$::Gui(NoteBook).c"} {
if {$step < 0} {
set step -1
} else {
set step 1
}
catch {NoteBook::_xview $::Gui(NoteBook) $step}
} else {
# Dont scroll the notebook arrows (any sub canvas of Notebook)
if {![string match "$::Gui(NoteBook).c*" $w]&&![string match ".colour*" $w]} {
$w $view scroll $step $units
}
}


Martyn

Harald Oehlmann

unread,
Mar 7, 2012, 8:21:50 AM3/7/12
to
Thank you, Martyn,
-Harald

Koen Danckaert

unread,
Mar 8, 2012, 11:21:41 AM3/8/12
to
On 07/03/12 10:26, Harald Oehlmann wrote:
> I have pasted the code of TIP #171
> http://www.tcl.tk/cgi-bin/tct/tip/171.html
> into my TCL 8.5 application using BWidgets and TTK

The actual implementation used for TIP 171 was completely different from the
one in the TIP text. The main problem addressed by the TIP was the fact that
on Windows, the mousewheel scrolls the focus widget (instead of the widget
under the mouse pointer). At Tcl level, this could only be partly remedied by
the complex (and not always working) bindings described in the TIP. Therefore,
the focus problem was instead solved by a much simpler patch at the C level.

The [bind all <MouseWheel>] binding in the TIP text was not included, because
it was not necessary anymore. You can easily add such bindings yourself now,
if you want.

> There are funny interactions:
> when having a BWidget NoteBook widget with a client with a scrollbar
> and I klick on a NoteBook tab and I use the scrollwhell, The whole
> Notebook is scrolled out and gray place is shown below.
>
> I suppose that the canvas within the Notebook implementation sets the
> scrolling region to a higher value and thus, the Canvas is scrolled.
>
> Inside the NoteBook, I have a BWidget ScrolledWindow environment.
> This widget is not scrolled by the mousewheel.
> But if the mouse is over the Scrollbar of the ScrolledWindw, the
> scrolled window is scrolled now (without click).
> This did not work before.
>
> Does anybody have looked to those issues ?
>
> When starting BWidget under TCL8.6, this misbehaviour will show-up,
> right ?

No. You won't notice much difference. If you want to use generic MouseWheel
bindings in 8.6, you still have to add something like the following:

proc MouseWheel {w D X Y} {
# Search upward for widget which can perform yview
# (and do not scroll canvas with undefined scrollregion)
for {} {[winfo toplevel $w] ne $w} {set w [winfo parent $w]} {
if {![catch {$w cget -scrollregion} sr] && $sr eq ""} {continue}
if {![catch {$w yview scroll [expr {-$D/30}] units}]} {break}
}
}
foreach class {Text Listbox} {
bind $class <MouseWheel> {}
if {[tk windowingsystem] eq "x11"} {
bind $class <4> {}
bind $class <5> {}
}
}
bind all <MouseWheel> {MouseWheel %W %D %X %Y}
if {[tk windowingsystem] eq "x11"} {
bind all <4> {MouseWheel %W 120 %X %Y}
bind all <5> {MouseWheel %W -120 %X %Y}
}

Regards,
Koen

Harald Oehlmann

unread,
Mar 8, 2012, 12:23:40 PM3/8/12
to
Thank you Koen, very helpful answer !
- Harald
0 new messages