1 | /* $Id: MouseImpl.h 26935 2010-03-02 10:32:28Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VirtualBox VBoxBFE/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 | #ifndef VBOXBFE_WITHOUT_COM
|
---|
27 | # include "ConsoleEvents.h"
|
---|
28 | #endif
|
---|
29 | #include "ConsoleImpl.h"
|
---|
30 | #include <VBox/pdmdrv.h>
|
---|
31 |
|
---|
32 | /** Simple mouse event class. */
|
---|
33 | class MouseEvent
|
---|
34 | {
|
---|
35 | public:
|
---|
36 | MouseEvent() : dx(0), dy(0), dz(0), dw(0), state(-1) {}
|
---|
37 | MouseEvent(int32_t _dx, int32_t _dy, int32_t _dz, int32_t _dw, int32_t _state) :
|
---|
38 | dx(_dx), dy(_dy), dz(_dz), dw(_dw), state(_state) {}
|
---|
39 | bool isValid()
|
---|
40 | {
|
---|
41 | return state != -1;
|
---|
42 | }
|
---|
43 | /* Note: dw is the horizontal scroll wheel */
|
---|
44 | int32_t dx, dy, dz, dw;
|
---|
45 | int32_t state;
|
---|
46 | };
|
---|
47 | #ifndef VBOXBFE_WITHOUT_COM
|
---|
48 | // template instantiation
|
---|
49 | typedef ConsoleEventBuffer<MouseEvent> MouseEventBuffer;
|
---|
50 | #endif
|
---|
51 |
|
---|
52 | enum
|
---|
53 | {
|
---|
54 | MOUSE_DEVCAP_RELATIVE = 1,
|
---|
55 | MOUSE_DEVCAP_ABSOLUTE = 2
|
---|
56 | };
|
---|
57 |
|
---|
58 | class ATL_NO_VTABLE Mouse :
|
---|
59 | public VirtualBoxBase
|
---|
60 | #ifndef VBOXBFE_WITHOUT_COM
|
---|
61 | ,
|
---|
62 | public VirtualBoxSupportErrorInfoImpl<Mouse, IMouse>,
|
---|
63 | public VirtualBoxSupportTranslation<Mouse>,
|
---|
64 | VBOX_SCRIPTABLE_IMPL(IMouse)
|
---|
65 | #endif
|
---|
66 | {
|
---|
67 | public:
|
---|
68 |
|
---|
69 | #ifndef VBOXBFE_WITHOUT_COM
|
---|
70 | VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT (Mouse)
|
---|
71 |
|
---|
72 | DECLARE_NOT_AGGREGATABLE(Mouse)
|
---|
73 |
|
---|
74 | DECLARE_PROTECT_FINAL_CONSTRUCT()
|
---|
75 |
|
---|
76 | BEGIN_COM_MAP(Mouse)
|
---|
77 | COM_INTERFACE_ENTRY (ISupportErrorInfo)
|
---|
78 | COM_INTERFACE_ENTRY (IMouse)
|
---|
79 | COM_INTERFACE_ENTRY2 (IDispatch, IMouse)
|
---|
80 | END_COM_MAP()
|
---|
81 | #endif
|
---|
82 |
|
---|
83 | DECLARE_EMPTY_CTOR_DTOR (Mouse)
|
---|
84 |
|
---|
85 | HRESULT FinalConstruct();
|
---|
86 | void FinalRelease();
|
---|
87 |
|
---|
88 | // public initializer/uninitializer for internal purposes only
|
---|
89 | HRESULT init(Console *parent);
|
---|
90 | void uninit();
|
---|
91 |
|
---|
92 | // IMouse properties
|
---|
93 | STDMETHOD(COMGETTER(AbsoluteSupported)) (BOOL *absoluteSupported);
|
---|
94 | STDMETHOD(COMGETTER(RelativeSupported)) (BOOL *relativeSupported);
|
---|
95 | STDMETHOD(COMGETTER(NeedsHostCursor)) (BOOL *needsHostCursor);
|
---|
96 |
|
---|
97 | // IMouse methods
|
---|
98 | STDMETHOD(PutMouseEvent)(LONG dx, LONG dy, LONG dz, LONG dw,
|
---|
99 | LONG buttonState);
|
---|
100 | STDMETHOD(PutMouseEventAbsolute)(LONG x, LONG y, LONG dz, LONG dw,
|
---|
101 | LONG buttonState);
|
---|
102 |
|
---|
103 | // for VirtualBoxSupportErrorInfoImpl
|
---|
104 | static const wchar_t *getComponentName() { return L"Mouse"; }
|
---|
105 |
|
---|
106 | static const PDMDRVREG DrvReg;
|
---|
107 |
|
---|
108 | #ifndef VBOXBFE_WITHOUT_COM
|
---|
109 | Console *getParent() const
|
---|
110 | {
|
---|
111 | return mParent;
|
---|
112 | }
|
---|
113 | #endif
|
---|
114 |
|
---|
115 | // for VMMDevInterface
|
---|
116 | void onVMMDevCanAbsChange(bool canAbs)
|
---|
117 | {
|
---|
118 | fVMMDevCanAbs = canAbs;
|
---|
119 | sendMouseCapsCallback();
|
---|
120 | }
|
---|
121 |
|
---|
122 | void onVMMDevNeedsHostChange(bool needsHost)
|
---|
123 | {
|
---|
124 | fVMMDevNeedsHostCursor = needsHost;
|
---|
125 | sendMouseCapsCallback();
|
---|
126 | }
|
---|
127 |
|
---|
128 | private:
|
---|
129 |
|
---|
130 | static DECLCALLBACK(void *) drvQueryInterface(PPDMIBASE pInterface, const char *pszIID);
|
---|
131 | static DECLCALLBACK(void) mouseReportModes (PPDMIMOUSECONNECTOR pInterface, bool fRel, bool fAbs);
|
---|
132 | static DECLCALLBACK(int) drvConstruct(PPDMDRVINS pDrvIns, PCFGMNODE pCfg, uint32_t fFlags);
|
---|
133 | static DECLCALLBACK(void) drvDestruct(PPDMDRVINS pDrvIns);
|
---|
134 |
|
---|
135 | int getVMMDevMouseCaps(uint32_t *pfCaps);
|
---|
136 | int setVMMDevMouseCaps(uint32_t fCaps);
|
---|
137 | int reportRelEventToMouseDev(int32_t dx, int32_t dy, int32_t dz,
|
---|
138 | int32_t dw, uint32_t fButtons);
|
---|
139 | int reportAbsEventToMouseDev(uint32_t mouseXAbs, uint32_t mouseYAbs,
|
---|
140 | int32_t dz, int32_t dw, uint32_t fButtons);
|
---|
141 | int reportAbsEventToVMMDev(uint32_t mouseXAbs, uint32_t mouseYAbs);
|
---|
142 | int convertDisplayWidth(LONG x, uint32_t *pcX);
|
---|
143 | int convertDisplayHeight(LONG y, uint32_t *pcY);
|
---|
144 |
|
---|
145 | void sendMouseCapsCallback(void);
|
---|
146 |
|
---|
147 | #ifdef VBOXBFE_WITHOUT_COM
|
---|
148 | Console *mParent;
|
---|
149 | #else
|
---|
150 | const ComObjPtr<Console, ComWeakRef> mParent;
|
---|
151 | #endif
|
---|
152 | /** Pointer to the associated mouse driver. */
|
---|
153 | struct DRVMAINMOUSE *mpDrv;
|
---|
154 |
|
---|
155 | LONG uHostCaps;
|
---|
156 | LONG uDevCaps;
|
---|
157 | bool fVMMDevCanAbs;
|
---|
158 | bool fVMMDevNeedsHostCursor;
|
---|
159 | uint32_t mLastAbsX;
|
---|
160 | uint32_t mLastAbsY;
|
---|
161 | uint32_t mLastButtons;
|
---|
162 | };
|
---|
163 |
|
---|
164 | #ifdef VBOXBFE_WITHOUT_COM
|
---|
165 | extern Mouse *gMouse;
|
---|
166 | #endif
|
---|
167 |
|
---|
168 | #endif // !____H_MOUSEIMPL
|
---|
169 | /* vi: set tabstop=4 shiftwidth=4 expandtab: */
|
---|