Scroll wheel with scrollable canvas

I’ve embedded a TGVerticalFrame into a TCanvas such that the canvas supplies automatic scrollbars (similar to here: Scrollbar on TGVerticalFrame).

The problem I’m having is that the mouse’s scroll wheel only works for scrolling when the mouse is hovering over the scrollbar itself, rather than when over my frame or canvas. Is there a way to get the scroll wheel to work more naturally? For example, scrolling the wheel while hovered over the embedded frame scrolls the frame. I’m seeing the same behavior in multiple OS, so I’m thinking that’s not the problem.

Thanks in advance for the help!

[quote=“tjstavenger”]The problem I’m having is that the mouse’s scroll wheel only works for scrolling when the mouse is hovering over the scrollbar itself, rather than when over my frame or canvas. Is there a way to get the scroll wheel to work more naturally? For example, scrolling the wheel while hovered over the embedded frame scrolls the frame. I’m seeing the same behavior in multiple OS, so I’m thinking that’s not the problem.

Thanks in advance for the help![/quote]

No, it’s not a problem, you can read about X11 (event masks) and modify event mask on a window you want to receive scroll events.

And AFAIK, standard TCanvas already receives/processes mouse wheel events - using them, for example, to zoom/unzoom 3D scenes.

I considered the X11 environment being part of the problem, so I also compiled the same code in Windows and had the same behavior.

I also figured it was a problem with getting the embedded frame to receive the scroll events and pass them up to the canvas. I’ve tried variations of calling AddInput (root.cern.ch/root/html/TGFrame.h … e:AddInput), but I had no success.

Any pointers on getting the frame to pass its events up to the canvas so that scrolling works?

Thanks!

[quote=“tjstavenger”]Any pointers on getting the frame to pass its events up to the canvas so that scrolling works?

Thanks![/quote]

Hmm, I was wrong about zooming, in a standard canvas scrolling works as you want. Do you have something different in your program ? (TRootEmbedded canvas?)

I don’t think I’m doing anything too out of the ordinary, but I could be mistaken. Here’s a short snippet that illustrates the TGVerticalFrame -> TGCanvas -> TGVerticalFrame design I currently have:

TGVerticalFrame* mWidget = NULL; // mWidget initialized with the rest of our UI

TGLayoutHints* layout = NULL;

layout = new TGLayoutHints(201, 0, 0, 0, 0);
TGCanvas* mPaletteCanvas = new TGCanvas(mWidget);
mWidget->AddFrame(mPaletteCanvas, layout);

layout = new TGLayoutHints(203, 0, 0, 0, 0);
TGVerticalFrame* mPaletteFrame = new TGVerticalFrame(mPaletteCanvas->GetViewPort(), 500, 300, 0);
mPaletteCanvas->SetContainer(mPaletteFrame);

The mPaletteFrame later gets many buttons & labels added to it that cause the TGCanvas to show a vertical scrollbar. That scrollbar only works with the scroll wheel if the cursor is hovering over the scrollbar. The scroll wheel does not work if the cursor is hovering over the mPaletteFrame. I’ve been trying, unsuccessfully, to get the mPaletteFrame to send its scroll events to the mPaletteCanvas.

If needed, I may be able to break out a working sample that illustrates the behavior.

[quote=“tjstavenger”]I don’t think I’m doing anything too out of the ordinary, but I could be mistaken. Here’s a short snippet that illustrates the TGVerticalFrame -> TGCanvas -> TGVerticalFrame design I currently have:

TGVerticalFrame* mWidget = NULL; // mWidget initialized with the rest of our UI

TGLayoutHints* layout = NULL;

layout = new TGLayoutHints(201, 0, 0, 0, 0);
TGCanvas* mPaletteCanvas = new TGCanvas(mWidget);
mWidget->AddFrame(mPaletteCanvas, layout);

layout = new TGLayoutHints(203, 0, 0, 0, 0);
TGVerticalFrame* mPaletteFrame = new TGVerticalFrame(mPaletteCanvas->GetViewPort(), 500, 300, 0);
mPaletteCanvas->SetContainer(mPaletteFrame);

The mPaletteFrame later gets many buttons & labels added to it that cause the TGCanvas to show a vertical scrollbar. That scrollbar only works with the scroll wheel if the cursor is hovering over the scrollbar. The scroll wheel does not work if the cursor is hovering over the mPaletteFrame. I’ve been trying, unsuccessfully, to get the mPaletteFrame to send its scroll events to the mPaletteCanvas.

If needed, I may be able to break out a working sample that illustrates the behavior.[/quote]

Have a look how it’s done in a TRootCanvas:

[code]Bool_t TRootContainer::HandleButton(Event_t *event)
{
// Directly handle scroll mouse buttons (4 and 5), only pass buttons
// 1, 2 and 3 on to the TCanvas.

TGViewPort vp = (TGViewPort)fParent;
UInt_t page = vp->GetHeight()/4;
Int_t newpos;

gVirtualX->SetInputFocus(GetMainFrame()->GetId());

if (event->fCode == kButton4) {
//scroll up
newpos = fCanvas->fCanvasWindow->GetVsbPosition() - page;
if (newpos < 0) newpos = 0;
fCanvas->fCanvasWindow->SetVsbPosition(newpos);
// return kTRUE;
}
if (event->fCode == kButton5) {
// scroll down
newpos = fCanvas->fCanvasWindow->GetVsbPosition() + page;
fCanvas->fCanvasWindow->SetVsbPosition(newpos);
// return kTRUE;
}

return fCanvas->HandleContainerButton(event);
}[/code]

You can do something like this.