1 | /* $Id: MouseImpl.h 27607 2010-03-22 18:13:07Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VirtualBox COM class implementation
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2008 Sun Microsystems, Inc.
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | *
|
---|
17 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
|
---|
18 | * Clara, CA 95054 USA or visit http://www.sun.com if you need
|
---|
19 | * additional information or have any questions.
|
---|
20 | */
|
---|
21 |
|
---|
22 | #ifndef ____H_MOUSEIMPL
|
---|
23 | #define ____H_MOUSEIMPL
|
---|
24 |
|
---|
25 | #include "VirtualBoxBase.h"
|
---|
26 | #include "ConsoleEvents.h"
|
---|
27 | #include "ConsoleImpl.h"
|
---|
28 | #include <VBox/pdmdrv.h>
|
---|
29 |
|
---|
30 | /** Maximum number of devices supported */
|
---|
31 | enum { MOUSE_MAX_DEVICES = 3 };
|
---|
32 | /** Mouse driver instance data. */
|
---|
33 | typedef struct DRVMAINMOUSE DRVMAINMOUSE, *PDRVMAINMOUSE;
|
---|
34 |
|
---|
35 | /** Simple mouse event class. */
|
---|
36 | class MouseEvent
|
---|
37 | {
|
---|
38 | public:
|
---|
39 | MouseEvent() : dx(0), dy(0), dz(0), dw(0), state(-1) {}
|
---|
40 | MouseEvent(int32_t _dx, int32_t _dy, int32_t _dz, int32_t _dw, int32_t _state) :
|
---|
41 | dx(_dx), dy(_dy), dz(_dz), dw(_dw), state(_state) {}
|
---|
42 | bool isValid()
|
---|
43 | {
|
---|
44 | return state != -1;
|
---|
45 | }
|
---|
46 | /* Note: dw is the horizontal scroll wheel */
|
---|
47 | int32_t dx, dy, dz, dw;
|
---|
48 | int32_t state;
|
---|
49 | };
|
---|
50 | // template instantiation
|
---|
51 | typedef ConsoleEventBuffer<MouseEvent> MouseEventBuffer;
|
---|
52 |
|
---|
53 | class ATL_NO_VTABLE Mouse :
|
---|
54 | public VirtualBoxBase
|
---|
55 | #ifndef VBOXBFE_WITHOUT_COM
|
---|
56 | ,
|
---|
57 | public VirtualBoxSupportErrorInfoImpl<Mouse, IMouse>,
|
---|
58 | public VirtualBoxSupportTranslation<Mouse>,
|
---|
59 | VBOX_SCRIPTABLE_IMPL(IMouse)
|
---|
60 | #endif
|
---|
61 | {
|
---|
62 | public:
|
---|
63 |
|
---|
64 | VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT (Mouse)
|
---|
65 |
|
---|
66 | DECLARE_NOT_AGGREGATABLE(Mouse)
|
---|
67 |
|
---|
68 | DECLARE_PROTECT_FINAL_CONSTRUCT()
|
---|
69 |
|
---|
70 | BEGIN_COM_MAP(Mouse)
|
---|
71 | COM_INTERFACE_ENTRY (ISupportErrorInfo)
|
---|
72 | COM_INTERFACE_ENTRY (IMouse)
|
---|
73 | COM_INTERFACE_ENTRY2 (IDispatch, IMouse)
|
---|
74 | END_COM_MAP()
|
---|
75 |
|
---|
76 | DECLARE_EMPTY_CTOR_DTOR (Mouse)
|
---|
77 |
|
---|
78 | HRESULT FinalConstruct();
|
---|
79 | void FinalRelease();
|
---|
80 |
|
---|
81 | // public initializer/uninitializer for internal purposes only
|
---|
82 | HRESULT init(Console *parent);
|
---|
83 | void uninit();
|
---|
84 |
|
---|
85 | // IMouse properties
|
---|
86 | STDMETHOD(COMGETTER(AbsoluteSupported)) (BOOL *absoluteSupported);
|
---|
87 | STDMETHOD(COMGETTER(RelativeSupported)) (BOOL *relativeSupported);
|
---|
88 | STDMETHOD(COMGETTER(NeedsHostCursor)) (BOOL *needsHostCursor);
|
---|
89 |
|
---|
90 | // IMouse methods
|
---|
91 | STDMETHOD(PutMouseEvent)(LONG dx, LONG dy, LONG dz, LONG dw,
|
---|
92 | LONG buttonState);
|
---|
93 | STDMETHOD(PutMouseEventAbsolute)(LONG x, LONG y, LONG dz, LONG dw,
|
---|
94 | LONG buttonState);
|
---|
95 |
|
---|
96 | // for VirtualBoxSupportErrorInfoImpl
|
---|
97 | static const wchar_t *getComponentName() { return L"Mouse"; }
|
---|
98 |
|
---|
99 | static const PDMDRVREG DrvReg;
|
---|
100 |
|
---|
101 | Console *getParent() const
|
---|
102 | {
|
---|
103 | return mParent;
|
---|
104 | }
|
---|
105 |
|
---|
106 | // for VMMDevInterface
|
---|
107 | void onVMMDevCanAbsChange(bool)
|
---|
108 | {
|
---|
109 | sendMouseCapsNotifications();
|
---|
110 | }
|
---|
111 |
|
---|
112 | void onVMMDevNeedsHostChange(bool needsHost)
|
---|
113 | {
|
---|
114 | fVMMDevNeedsHostCursor = needsHost;
|
---|
115 | sendMouseCapsNotifications();
|
---|
116 | }
|
---|
117 |
|
---|
118 | private:
|
---|
119 |
|
---|
120 | static DECLCALLBACK(void *) drvQueryInterface(PPDMIBASE pInterface, const char *pszIID);
|
---|
121 | static DECLCALLBACK(void) mouseReportModes (PPDMIMOUSECONNECTOR pInterface, bool fRel, bool fAbs);
|
---|
122 | static DECLCALLBACK(int) drvConstruct(PPDMDRVINS pDrvIns, PCFGMNODE pCfg, uint32_t fFlags);
|
---|
123 | static DECLCALLBACK(void) drvDestruct(PPDMDRVINS pDrvIns);
|
---|
124 |
|
---|
125 | HRESULT getVMMDevMouseCaps(uint32_t *pfCaps);
|
---|
126 | HRESULT setVMMDevMouseCaps(uint32_t fCaps);
|
---|
127 | HRESULT reportRelEventToMouseDev(int32_t dx, int32_t dy, int32_t dz,
|
---|
128 | int32_t dw, uint32_t fButtons);
|
---|
129 | HRESULT reportAbsEventToMouseDev(uint32_t mouseXAbs, uint32_t mouseYAbs,
|
---|
130 | int32_t dz, int32_t dw, uint32_t fButtons);
|
---|
131 | HRESULT reportAbsEventToVMMDev(uint32_t mouseXAbs, uint32_t mouseYAbs);
|
---|
132 | HRESULT convertDisplayWidth(LONG x, uint32_t *pcX);
|
---|
133 | HRESULT convertDisplayHeight(LONG y, uint32_t *pcY);
|
---|
134 |
|
---|
135 | void sendMouseCapsNotifications(void);
|
---|
136 |
|
---|
137 | #ifdef VBOXBFE_WITHOUT_COM
|
---|
138 | Console *mParent;
|
---|
139 | #else
|
---|
140 | Console * const mParent;
|
---|
141 | #endif
|
---|
142 | /** Pointer to the associated mouse driver. */
|
---|
143 | struct DRVMAINMOUSE *mpDrv[MOUSE_MAX_DEVICES];
|
---|
144 |
|
---|
145 | LONG uHostCaps;
|
---|
146 | bool fVMMDevCanAbs;
|
---|
147 | bool fVMMDevNeedsHostCursor;
|
---|
148 | uint32_t mLastAbsX;
|
---|
149 | uint32_t mLastAbsY;
|
---|
150 | uint32_t mLastButtons;
|
---|
151 | };
|
---|
152 |
|
---|
153 | #ifdef VBOXBFE_WITHOUT_COM
|
---|
154 | /** @todo make this a member of Console */
|
---|
155 | extern Mouse *gMouse;
|
---|
156 |
|
---|
157 | /** @todo can we get these from the API somehow? */
|
---|
158 | enum
|
---|
159 | {
|
---|
160 | MouseButtonState_LeftButton = 1,
|
---|
161 | MouseButtonState_RightButton = 2,
|
---|
162 | MouseButtonState_MiddleButton = 4,
|
---|
163 | MouseButtonState_XButton1 = 8,
|
---|
164 | MouseButtonState_XButton2 = 16,
|
---|
165 | };
|
---|
166 | #endif
|
---|
167 |
|
---|
168 | #endif // !____H_MOUSEIMPL
|
---|
169 | /* vi: set tabstop=4 shiftwidth=4 expandtab: */
|
---|