2
$Id: winmouse.pp,v 1.7 2005/02/14 17:13:32 peter Exp $
3
This file is part of the Free Pascal run time library.
4
Copyright (c) 1999-2000 by Florian Klaempfl
5
member of the Free Pascal development team
7
This is unit implements a subset of the msmouse unit functionality
8
for the gui win32 graph unit implementation
10
See the file COPYING.FPC, included in this distribution,
11
for details about the copyright.
13
This program is distributed in the hope that it will be useful,
14
but WITHOUT ANY WARRANTY; without even the implied warranty of
15
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
17
**********************************************************************}
21
{ initializes the mouse with the default values for the current screen mode }
22
Function InitMouse:Boolean;
24
{ shows mouse pointer,text+graphics screen support }
27
{ hides mouse pointer }
30
{ reads mouse position in pixels (divide by 8 to get text position in standard
31
text mode) and reads the buttons state:
32
bit 1 set -> left button pressed
33
bit 2 set -> right button pressed
34
bit 3 set -> middle button pressed
35
Have a look at the example program in the manual to see how you can use this }
36
Procedure GetMouseState(var x,y, buttons :Longint);
38
{ returns true if the left button is pressed }
39
Function LPressed:Boolean;
41
{ returns true if the right button is pressed }
42
Function RPressed:Boolean;
44
{ returns true if the middle button is pressed }
45
Function MPressed:Boolean;
47
(*!!!!! the following functions aren't implemented yet:
48
{ positions the mouse pointer }
49
Procedure SetMousePos(x,y:Longint);
51
{ returns at which position "button" was last pressed in x,y and returns the
52
number of times this button has been pressed since the last time this
53
function was called with "button" as parameter. For button you can use the
54
LButton, RButton and MButton constants for resp. the left, right and middle
56
Function GetLastButtonPress(button:Longint;var x,y:Longint): Longint;
58
{ returns at which position "button" was last released in x,y and returns the
59
number of times this button has been re since the last time. For button
60
you can use the LButton, RButton and MButton constants for resp. the left,
61
right and middle button
63
Function GetLastButtonRelease (button : Longint; var x,y:Longint): Longint;
65
{ sets mouse's x range, with Min and Max resp. the higest and the lowest
66
column (in pixels) in between which the mouse cursor can move }
67
Procedure SetMouseXRange (Min,Max:Longint);
69
{ sets mouse's y range, with Min and Max resp. the higest and the lowest
70
row (in pixels) in between which the mouse cursor can move}
71
Procedure SetMouseYRange (Min,Max:Longint);
73
{ set the window coordinates in which the mouse cursor can move }
74
Procedure SetMouseWindow(x1,y1,x2,y2:Longint);
76
{ sets the mouse shape in text mode: background and foreground color and the
77
Ascii value with which the character on screen is XOR'ed when the cursor
78
moves over it. Set to 0 for a "transparent" cursor}
79
Procedure SetMouseShape(ForeColor,BackColor,Ascii:Byte);
81
{ sets the mouse ascii in text mode. The difference between this one and
82
SetMouseShape, is that the foreground and background colors stay the same
83
and that the Ascii code you enter is the character that you will get on
84
screen; there's no XOR'ing }
85
Procedure SetMouseAscii(Ascii:Byte);
87
{ set mouse speed in mickey's/pixel; default: horizontal: 8; vertical: 16 }
88
Procedure SetMouseSpeed(Horizontal ,Vertical:Longint);
90
{ set a rectangle on screen that mouse will disappear if it is moved into }
91
Procedure SetMouseHideWindow(x1,y1,x2,y2:Longint);
95
LButton = 1; { left button }
96
RButton = 2; { right button }
97
MButton = 4; { middle button }
108
oldexitproc : pointer;
109
mousebuttonstate : byte;
111
function InitMouse : boolean;
114
InitMouse:=MouseFound;
120
Windows.ShowCursor(true);
126
Windows.ShowCursor(false);
129
function msghandler(Window: HWnd; AMessage:UInt; WParam : WParam; LParam: LParam): Longint; stdcall;
132
{ we catch the double click messages here too, }
133
{ even if they never appear because the graph }
134
{ windows doesn't have the cs_dblclks flags }
138
mousebuttonstate:=mousebuttonstate or LButton;
141
mousebuttonstate:=mousebuttonstate or RButton;
144
mousebuttonstate:=mousebuttonstate or MButton;
146
mousebuttonstate:=mousebuttonstate and not(LButton);
148
mousebuttonstate:=mousebuttonstate and not(RButton);
150
mousebuttonstate:=mousebuttonstate and not(MButton);
155
Function LPressed : Boolean;
158
LPressed:=(mousebuttonstate and LButton)<>0;
161
Function RPressed : Boolean;
164
RPressed:=(mousebuttonstate and RButton)<>0;
167
Function MPressed : Boolean;
170
MPressed:=(mousebuttonstate and MButton)<>0;
173
Procedure GetMouseState(var x,y,buttons : Longint);
179
buttons:=mousebuttonstate;
181
ScreenToClient(GraphWindow,@pos);
186
procedure myexitproc;
189
exitproc:=oldexitproc;
190
mousemessagehandler:=nil;
194
mousemessagehandler:=@msghandler;
195
oldexitproc:=exitproc;
196
exitproc:=@myexitproc;
198
MouseFound:=GetSystemMetrics(SM_MOUSEPRESENT)<>0;
201
$Log: winmouse.pp,v $
202
Revision 1.7 2005/02/14 17:13:32 peter