Recent

Author Topic: Wheelmouse capture  (Read 17202 times)

cov

  • Sr. Member
  • ****
  • Posts: 250
Wheelmouse capture
« on: June 12, 2007, 12:43:24 pm »
Hi,

I've put a TScrollBox and a Tmemo onto a form. The TScrollbox has a Mousewheel event that I can use to capture Mousewheel scrolls.

However, if I place a TImage into the TScrollBox, the Mousewheel is no longer accessible.

If I click into the TScrollbox, it works. If I move the curser over the TMemo, it still works. But if I move the cursor over the TImage the mousewheel events are no longer being read.

Does anyone have a solution?

theo

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1933
RE: Wheelmouse capture
« Reply #1 on: June 12, 2007, 01:04:07 pm »
I usually don't use TImage for this.
You could make your own TCustomControl descendant then paint a bitmap in the OnPaint event and override
function  DoMouseWheel(Shift: TShiftState; WheelDelta: Integer; MousePos: TPoint): Boolean; override;

There are probably easier solutions.

antonio

  • Hero Member
  • *****
  • Posts: 605
Re: Wheelmouse capture
« Reply #2 on: June 12, 2007, 09:07:10 pm »
Quote from: "cov"
But if I move the cursor over the TImage the mousewheel events are no longer being read.


I tried this and the wheel events do are read.

cov

  • Sr. Member
  • ****
  • Posts: 250
Re: Wheelmouse capture
« Reply #3 on: June 12, 2007, 10:21:34 pm »
Quote from: "antonio"
Quote from: "cov"
But if I move the cursor over the TImage the mousewheel events are no longer being read.


I tried this and the wheel events do are read.


Well, I'm afraid that My Mileage Differs. It works fine until I place the TImage on the TScrollBox. Also the TMemo does not appear to interfere.

I also tried the following code:
Code: [Select]
unit wheelimage;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, Controls, Graphics, LCLType;
 
type

  { TWheelImage }

  TWheelImage = class(TCustomControl)
  public
    procedure EraseBackground(DC: HDC); override;
    procedure Paint; override;
    function DoMouseWheel(Shift: TShiftState; WheelDelta: Integer; MousePos: TPoint): Boolean; override;
  end;

implementation
uses unit1;
procedure TWheelImage.EraseBackground(DC: HDC);
begin
  inherited EraseBackground(DC);
end;

procedure TWheelImage.Paint;
var
  x, y: Integer;
  Bitmap: TBitmap;
begin
  Bitmap := TBitmap.Create;
  try
    // Initializes the Bitmap Size
    Bitmap.Height := Height;
    Bitmap.Width := Width;

    // Draws the background
    Bitmap.Canvas.Pen.Color := clBlack;
    Bitmap.Canvas.Rectangle(0, 0, Width, Height);
  finally
    Bitmap.Free;
  end;

  inherited Paint;
end;

function TWheelImage.DoMouseWheel(Shift: TShiftState; WheelDelta: Integer;
  MousePos: TPoint): Boolean;
begin
  Result:=inherited DoMouseWheel(Shift, WheelDelta, MousePos);
end;

end.
                                                                                 


How do I find out if the DoMouseWheel event has been triggered?

antonio

  • Hero Member
  • *****
  • Posts: 605
RE: Re: Wheelmouse capture
« Reply #4 on: June 12, 2007, 10:30:11 pm »
I put a Scrollbox on a form and a TMemo and a TImage on it. Then I set property Autscroll to True and a Beep on the wheel event. It executed.

If the event executes, DoMouseWheel method has been triggered.

theo

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1933
RE: Re: Wheelmouse capture
« Reply #5 on: June 12, 2007, 11:06:15 pm »
Which widgetset are you talking about btw?
I've just tested this on GTK1/2 and it works fine with a TImage on a TScrollbox.

cov

  • Sr. Member
  • ****
  • Posts: 250
RE: Re: Wheelmouse capture
« Reply #6 on: June 13, 2007, 06:47:04 am »
Sorry: I'm Using 0.9.22 on XP.

Antonio; try this:

Form1.Height:=600;
Form1.Widtht:=600;
Memo1.Top:=496;
Memo1.Left:=0;
Memo1.Height:=100;
Memo1.Widtht:=600;
Image1.Top:=0;
Image1.Left:=0;
Image1.Height:=560;
Image1.Widtht:=460;

On my system the mousewheel works if the mouse cursor is over the TImage if x>100 (approximately).

If you take it over the left side of the TImage it stops working.

*I've just realised that I've posted under "Suggestions and Ideas" in error. Sorry!*

Vincent Snijders

  • Administrator
  • Hero Member
  • *
  • Posts: 2661
    • My Lazarus wiki user page
RE: Re: Wheelmouse capture
« Reply #7 on: June 13, 2007, 08:29:47 am »
I am not sure if I understand exactly what you are trying to tell (too lazy to try the examples), but the win32 interface to the LCL sends mousewheel message to the control that is under the mouse pointer. So if you move your mouuse from athe timage, it won't get any mousewheel events.

cov

  • Sr. Member
  • ****
  • Posts: 250
RE: Re: Wheelmouse capture
« Reply #8 on: June 13, 2007, 09:28:07 am »
Vincent; yes.

I had a Form on which I placed a TScrollbox. I placed a TImage and a Tmemo into the scrollbox.

The TImage took up most of the ScrollBox with the TMemo occupying a strip of 100 pixels at the bottom.

In this case DoMousewheel Events were not passed onto the TScrollBox.

Antonio did the same thing to try it out, but found that the DoMouseWhell event behaved as expected.

Indeed when I tried it again and just dropped the TImage onto the TSCrollBox (without resizing it), the DoWheelMouse events were handled correctly.

However, when I resized the TImage, a dead area manifested itself in the Top Left Corner of the TScrollbox which seems to be dependent on the size of the TImage. ie. the bigger the TImage, the larger the dead area.

antonio

  • Hero Member
  • *****
  • Posts: 605
RE: Re: Wheelmouse capture
« Reply #9 on: June 13, 2007, 04:47:34 pm »
If the Scrollbox is the active control, the wheel events perform even if mouse pointer is out of it. And it becomes active even if you click on the image. If you click on the memo, this becomes active and the wheel events are not triggered.

However, it seems to be there something if you put the image at the top and the memo on bottom. When the mouse is over the image, the wheel events aren't triggered. Not the same happens if you put two images on the box. Or if you put the memo on the top and the image on bottom. Or if you put two memos.

The memo seems to interfere on the behavior of scrollbox, but only the first control on the scrollbox seems to loose wheel events, no matter it's a memo or a image. Or, yes, it seems to be restricted to a part of the first control, perhaps restricted to the first size of the first control. It seems to be there  some difference if you align scrollbox client or not.

cov

  • Sr. Member
  • ****
  • Posts: 250
Wheelmouse capture
« Reply #10 on: June 13, 2007, 07:47:32 pm »
Hi Antonio.

Form laid out with the 300x300 TImage in the middle of the TScrollbox, TScrollBox is 690x600, Tmemo is 690x100 high.

The app starts up with no response from moving the mousewheel.

Click on the TMemo: still the mousewheel doesn't trigger events.

Click in the middle of the TImage: the mousewheel is now producing events.

Mousewheel now produces events except in an area about 260x300 in the top left corner.

ie there is a dead spot about 260 wide by 300 high in the top left hand corner of the Form.

Can you reproduce these results?

antonio

  • Hero Member
  • *****
  • Posts: 605
Wheelmouse capture
« Reply #11 on: June 13, 2007, 07:55:55 pm »
Now I have two memos on the scrollbox. Not exactly, but yes.

There is a dead area associated to the presence of the memo on the scrollbox.

SynEdit doesn't solve the problem.

Apparently you should not use any multiline edit control on the scrollbox. Probably it's valid for Windows only.

cov

  • Sr. Member
  • ****
  • Posts: 250
Wheelmouse capture
« Reply #12 on: June 13, 2007, 11:36:03 pm »
Quote from: "antonio"
Now I have two memos on the scrollbox. Not exactly, but yes.

There is a dead area associated to the presence of the memo on the scrollbox.

SynEdit doesn't solve the problem.

Apparently you should not use any multiline edit control on the scrollbox. Probably it's valid for Windows only.


Antonio,

I've taken the TMemo out of the TScrollBox and placed it directly onto the Form.

There is no change in the wheelmouse behavior.

antonio

  • Hero Member
  • *****
  • Posts: 605
Wheelmouse capture
« Reply #13 on: June 13, 2007, 11:42:25 pm »
The form doesn't have wheel events. It doesn't respond to the wheel at all.

cov

  • Sr. Member
  • ****
  • Posts: 250
Wheelmouse capture
« Reply #14 on: June 14, 2007, 07:11:37 am »
Yes, but my point is that the multiline edit control is no longer in the TScrollBox, so it should not be having any impact.

 

TinyPortal © 2005-2018