1 { CarbonMouseInput
2
3 Copyright (C) 2008 Tom Gregorovic
4
5 This source is free software; you can redistribute it and/or modify it under the terms of the
6 GNU General Public License as published by the Free Software Foundation; either version 2 of the
7 License, or (at your option) any later version.
8
9 This code is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 General Public License for more details.
12
13 A copy of the GNU General Public License is available on the World Wide Web at
14 <http://www.gnu.org/copyleft/gpl.html>. You can also obtain it by writing to the Free Software
15 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16 }
17 unit CarbonMouseInput;
18
19 {$mode objfpc}{$H+}
20
21 interface
22
23 uses
24 Classes, SysUtils, Controls, Forms,
25 MacOSAll, CarbonProc,
26 MouseInputIntf;
27
28 type
29
30 { TCarbonMouseInput }
31
32 TCarbonMouseInput = class(TMouseInput)
33 protected
34 procedure DoDown(Button: TMouseButton); override;
35 procedure DoMove(ScreenX, ScreenY: Integer); override;
36 procedure DoUp(Button: TMouseButton); override;
37 end;
38
InitializeMouseInputnull39 function InitializeMouseInput: TMouseInput;
40
41
42 implementation
43
InitializeMouseInputnull44 function InitializeMouseInput: TMouseInput;
45 begin
46 Result := TCarbonMouseInput.Create;
47 end;
48
49 const
50 MouseButtonToCarbonButton: array [TMouseButton] of Integer =
51 (kCGMouseButtonLeft, kCGMouseButtonRight, kCGMouseButtonCenter,kCGMouseButtonLeft,kCGMouseButtonLeft);
52
53
54 { TCarbonMouseInput }
55
56 procedure TCarbonMouseInput.DoDown(Button: TMouseButton);
57 begin
58 CGPostMouseEvent(PointToHIPoint(Mouse.CursorPos), 0, 1, 1, MouseButtonToCarbonButton[Button]);
59 end;
60
61 procedure TCarbonMouseInput.DoMove(ScreenX, ScreenY: Integer);
62 begin
63 CGPostMouseEvent(GetHIPoint(ScreenX, ScreenY), 1, 1, 0, 0);
64 end;
65
66 procedure TCarbonMouseInput.DoUp(Button: TMouseButton);
67 begin
68 CGPostMouseEvent(PointToHIPoint(Mouse.CursorPos), 0, 1, 0, MouseButtonToCarbonButton[Button]);
69 end;
70
71 end.
72
73