#include <gadget/Devices/KeyboardMouseDevice/InputWindowWin32.h>
Inheritance diagram for gadget::InputWindowWin32:


Public Member Functions | |
| InputWindowWin32 () | |
| virtual | ~InputWindowWin32 () |
| virtual bool | config (jccl::ConfigElementPtr e) |
| Config method. | |
| void | controlLoop (void *nullParam) |
| Main thread of control for this active object. | |
| bool | startSampling () |
| Create a win32 window and start a thread processing it's messages. | |
| bool | stopSampling () |
| StopSampling. | |
| bool | sample () |
| Process the current window events. | |
| void | updateData () |
| Do nothing since we are only sending events to a KeyboardMouseDevice. | |
| void | operator delete (void *p) |
| Invokes the global scope delete operator. | |
Static Public Member Functions | |
| static std::string | getElementType () |
| Returns the string rep of the element type used to config this device. | |
Protected Member Functions | |
| void | destroy () |
| Deletes this object. | |
| virtual void | processEvent (UINT, UINT, LONG) |
| void | createWindowWin32 () |
Windows utility functions | |
| char * | checkArgs (char *look_for) |
| BOOL | MenuInit (HINSTANCE hInstance) |
Protected Attributes | |
| HINSTANCE | m_hInst |
| std::string | mRemoteDisplayName |
| Name of the remote display window (index in registry). | |
| int | mScreen |
| Screen ID. | |
| int | mX |
| Origin X-coordinate. | |
| int | mY |
| Origin X-coordinate. | |
| bool | mExitFlag |
| Should we exit? | |
| bool | mControlLoopDone |
Friends | |
| LONG APIENTRY | MenuWndProc (HWND, UINT, UINT, LONG) |
| Window function for the main application window. | |
Definition at line 55 of file InputWindowWin32.h.
| gadget::InputWindowWin32::InputWindowWin32 | ( | ) | [inline] |
Definition at line 59 of file InputWindowWin32.h.
00060 : mControlLoopDone(false) 00061 , mExitFlag(false) 00062 { 00063 mBlocking = true; 00064 }
| virtual gadget::InputWindowWin32::~InputWindowWin32 | ( | ) | [inline, virtual] |
| bool gadget::InputWindowWin32::config | ( | jccl::ConfigElementPtr | e | ) | [virtual] |
Config method.
This baselevel config will fill the base datamembers when found in the jccl::ConfigElementPtr such as instance name.
Reimplemented from gadget::Input.
Definition at line 49 of file InputWindowWin32.cpp.
References gadget::Input::config(), gadget::InputArea::config(), gadgetDBG_INPUT_MGR(), gadget::InputAreaWin32::mHeight, gadget::InputAreaWin32::mWidth, mX, and mY.
00050 { 00051 unsigned required_definition_ver(1); 00052 00053 if(e->getVersion() < required_definition_ver) 00054 { 00055 vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_CRITICAL_LVL) 00056 << clrOutBOLD(clrRED, "ERROR") 00057 << " [gadget::InputWindowWin32::config()] Element named '" 00058 << e->getName() << "'" << std::endl << vprDEBUG_FLUSH; 00059 vprDEBUG_NEXT(gadgetDBG_INPUT_MGR, vprDBG_CRITICAL_LVL) 00060 << "is version " << e->getVersion() 00061 << ", but we require at least version " << required_definition_ver 00062 << ". Ignoring...\n" << vprDEBUG_FLUSH; 00063 return false; 00064 } 00065 00066 if ( !(InputArea::config(e) && Input::config(e)) ) 00067 { 00068 return false; 00069 } 00070 00071 const char neg_one_STRING[] = "-1"; 00072 00073 // Get size and position 00074 mWidth = e->getProperty<int>("size", 0); 00075 mHeight = e->getProperty<int>("size", 1); 00076 00077 // Sanity checks. 00078 if (mWidth == 0) mWidth = 400; 00079 if (mHeight == 0) mHeight = 400; 00080 00081 mX = e->getProperty<int>("origin", 0); 00082 mY = e->getProperty<int>("origin", 1); 00083 00084 // Get the X display string 00085 int x_disp_num = e->getProperty<int>("display_number"); 00086 jccl::ConfigElementPtr disp_sys_elt = 00087 gadget::InputManager::instance()->getDisplaySystemElement(); 00088 00089 return true; 00090 }
| void gadget::InputWindowWin32::controlLoop | ( | void * | nullParam | ) |
Main thread of control for this active object.
Definition at line 92 of file InputWindowWin32.cpp.
References createWindowWin32(), gadgetDBG_INPUT_MGR(), gadget::InputArea::Lock_LockKey, gadget::InputAreaWin32::lockMouse(), mControlLoopDone, mExitFlag, gadget::InputArea::mLockState, gadget::InputArea::mSleepTimeMS, gadget::InputAreaWin32::mWinHandle, and sample().
Referenced by startSampling().
00093 { 00094 mControlLoopDone = false; 00095 00096 // Open the window... 00097 // The Window has to be created in the same thread that 00098 // we run the message pump because all window messages 00099 // dispatched are dispatched to the thread that created 00100 // the window. (And we want to receive the messages 00101 // in the spawned thread) 00102 this->createWindowWin32(); 00103 00104 // If we have initial locked, then we need to lock the system 00105 if ( mLockState == Lock_LockKey ) // Means that we are in the initially locked state 00106 { 00107 vprDEBUG(gadgetDBG_INPUT_MGR,vprDBG_STATE_LVL) 00108 << "[gadget::InputWindowWin32::controlLoop()] " 00109 << "Mouse set to initial lock. Locking it now.\n" 00110 << vprDEBUG_FLUSH; 00111 this->lockMouse(); // Lock the mouse 00112 } 00113 00114 // When there are messages, process them all. Otherwise, 00115 // sleep for a while... 00116 mExitFlag = false; 00117 while ( !mExitFlag ) 00118 { 00119 this->sample(); 00120 00121 // Sleep for a user-specified sleep amount of time. 00122 vpr::System::msleep( mSleepTimeMS ); 00123 } 00124 00125 // Clean up, send a message to the window to close. 00126 ::CloseWindow(mWinHandle); 00127 mControlLoopDone = true; 00128 }
| bool gadget::InputWindowWin32::startSampling | ( | ) | [virtual] |
Create a win32 window and start a thread processing it's messages.
Implements gadget::Input.
Definition at line 130 of file InputWindowWin32.cpp.
References controlLoop(), gadgetDBG_INPUT_MGR(), mExitFlag, and gadget::Input::mThread.
00131 { 00132 if ( mThread != NULL ) 00133 { 00134 vprDEBUG(vprDBG_ERROR,vprDBG_CRITICAL_LVL) 00135 << clrOutNORM(clrRED,"ERROR:") 00136 << "[gadget::InputWindowWin32::startSampling()] " 00137 << "startSampling called, when already sampling.\n" 00138 << vprDEBUG_FLUSH; 00139 vprASSERT(mThread == NULL); 00140 return false; 00141 } 00142 00143 vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_CONFIG_LVL) 00144 << "gadget::InputWindowWin32::startSampling() : ready to go.." 00145 << std::endl << vprDEBUG_FLUSH; 00146 00147 // Create a new thread to handle the control 00148 mExitFlag = false; 00149 vpr::ThreadMemberFunctor<InputWindowWin32>* memberFunctor = 00150 new vpr::ThreadMemberFunctor<InputWindowWin32>(this, 00151 &InputWindowWin32::controlLoop, 00152 (void*) this); 00153 00154 mThread = new vpr::Thread(memberFunctor); 00155 00156 // Ensure that we have a valid thread. 00157 if ( ! mThread->valid() ) 00158 { 00159 return false; 00160 } 00161 00162 return true; 00163 }
| bool gadget::InputWindowWin32::stopSampling | ( | ) | [virtual] |
StopSampling.
Reverse the effects of StartSampling().
Implements gadget::Input.
Definition at line 165 of file InputWindowWin32.cpp.
References mExitFlag, gadget::Input::mThread, and gadget::InputAreaWin32::mWinHandle.
00166 { 00167 if ( mThread != NULL ) 00168 { 00169 mExitFlag = true; 00170 ::PostMessage( mWinHandle, WM_USER, 0, 0 );// send a dummy message to the window to close 00171 mThread->join(); 00172 delete mThread; 00173 mThread = NULL; 00174 } 00175 return true; 00176 }
| bool gadget::InputWindowWin32::sample | ( | ) | [virtual] |
Process the current window events.
Implements gadget::Input.
Definition at line 280 of file InputWindowWin32.cpp.
References gadget::InputAreaWin32::handleEvents().
Referenced by controlLoop().
00281 { 00282 // Handle all input events. 00283 handleEvents(); 00284 00285 return true; 00286 }
| void gadget::InputWindowWin32::updateData | ( | ) | [inline, virtual] |
Do nothing since we are only sending events to a KeyboardMouseDevice.
Implements gadget::Input.
Definition at line 96 of file InputWindowWin32.h.
| std::string gadget::InputWindowWin32::getElementType | ( | ) | [static] |
Returns the string rep of the element type used to config this device.
This string is used by the device factory to look up device drivers based up the type of element it is trying to load.
Reimplemented from gadget::Input.
Definition at line 288 of file InputWindowWin32.cpp.
| void gadget::InputWindowWin32::operator delete | ( | void * | p | ) | [inline] |
Invokes the global scope delete operator.
This is required for proper releasing of memory in DLLs on Win32.
Definition at line 105 of file InputWindowWin32.h.
| void gadget::InputWindowWin32::destroy | ( | ) | [inline, protected, virtual] |
Deletes this object.
This is an implementation of the pure virtual gadget::Input::destroy() method.
Implements gadget::Input.
Definition at line 115 of file InputWindowWin32.h.
| virtual void gadget::InputWindowWin32::processEvent | ( | UINT | , | |
| UINT | , | |||
| LONG | ||||
| ) | [inline, protected, virtual] |
| void gadget::InputWindowWin32::createWindowWin32 | ( | ) | [protected] |
Definition at line 204 of file InputWindowWin32.cpp.
References gadget::InputAreaWin32::doInternalError(), m_hInst, MenuInit(), gadget::InputAreaWin32::mHeight, gadget::Input::mInstName, gadget::InputAreaWin32::mWidth, gadget::InputAreaWin32::mWinHandle, mX, and mY.
Referenced by controlLoop().
00205 { 00206 int root_height; 00207 00208 InitCommonControls(); 00209 00210 m_hInst = GetModuleHandle(NULL); // Just try to get the application's handle 00211 MenuInit(m_hInst); 00212 00213 root_height = GetSystemMetrics(SM_CYSCREEN); 00214 00215 /* Create the app. window */ 00216 mWinHandle = CreateWindow("Gadgeteer Event Window", mInstName.c_str(), 00217 WS_OVERLAPPEDWINDOW, mX, 00218 root_height - mY - mHeight, mWidth, mHeight, 00219 (HWND) NULL, NULL, m_hInst, (LPSTR) NULL); 00220 ShowWindow(mWinHandle,SW_SHOW); 00221 UpdateWindow(mWinHandle); 00222 00223 // Attach a pointer to the device for use from the WNDPROC 00224 SetWindowLongPtr(mWinHandle, GWLP_USERDATA, (LPARAM)this); 00225 00226 if ( NULL == mWinHandle ) 00227 { 00228 doInternalError("Could not create InputWindowWin32!"); 00229 } 00230 }
| char* gadget::InputWindowWin32::checkArgs | ( | char * | look_for | ) | [protected] |
| BOOL gadget::InputWindowWin32::MenuInit | ( | HINSTANCE | hInstance | ) | [protected] |
Definition at line 232 of file InputWindowWin32.cpp.
References LIBNAME, and MenuWndProc.
Referenced by createWindowWin32().
00233 { 00234 HANDLE hMemory; 00235 PWNDCLASS pWndClass; 00236 BOOL bSuccess; 00237 00238 /* Initialize the menu window class */ 00239 hMemory = LocalAlloc(LPTR, sizeof(WNDCLASS)); 00240 if ( !hMemory ) 00241 { 00242 MessageBox(NULL, ("<MenuInit> Not enough memory."), NULL, 00243 MB_OK | MB_ICONHAND); 00244 return(FALSE); 00245 } 00246 00247 pWndClass = (PWNDCLASS) LocalLock(hMemory); 00248 00249 pWndClass->style = 0; 00250 pWndClass->lpfnWndProc = (WNDPROC) MenuWndProc; 00251 pWndClass->hInstance = hInstance; 00252 pWndClass->hIcon = LoadIcon(hInstance, "GADGETEER_ICON"); 00253 pWndClass->hCursor = (HCURSOR) LoadCursor(NULL, IDC_ARROW); 00254 pWndClass->hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH); 00255 pWndClass->lpszMenuName = ("MenuMenu"), 00256 pWndClass->lpszClassName = ("Gadgeteer Event Window"); 00257 00258 #ifdef _DEBUG 00259 # define LIBNAME "gadget_d.dll" 00260 #else 00261 # define LIBNAME "gadget.dll" 00262 #endif 00263 00264 if (pWndClass->hIcon == NULL) 00265 { 00266 HINSTANCE hDLLInstance = LoadLibrary( LIBNAME ); 00267 if (hDLLInstance != NULL) 00268 { 00269 pWndClass->hIcon = LoadIcon(hDLLInstance, "GADGETEER_ICON"); 00270 } 00271 } 00272 00273 bSuccess = RegisterClass(pWndClass); 00274 LocalUnlock(hMemory); 00275 LocalFree(hMemory); 00276 00277 return bSuccess; 00278 }
| LONG APIENTRY MenuWndProc | ( | HWND | hWnd, | |
| UINT | message, | |||
| UINT | wParam, | |||
| LONG | lParam | |||
| ) | [friend] |
Window function for the main application window.
Processes all the menu selections and oter messages.
Definition at line 181 of file InputWindowWin32.cpp.
Referenced by MenuInit().
00182 { 00183 switch ( message ) 00184 { 00185 // Catch the ALT key so that it does not open the system menu. 00186 case WM_SYSKEYDOWN: 00187 case WM_SYSKEYUP: 00188 break; 00189 case WM_SYSCOMMAND: 00190 return DefWindowProc(hWnd, message, wParam, lParam); 00191 break; 00192 case WM_DESTROY: 00193 PostQuitMessage(0); 00194 break; 00195 // Make sure that the resize event stays around until it is processed. 00196 case WM_SIZE: 00197 break; 00198 default: 00199 return DefWindowProc(hWnd, message, wParam, lParam); 00200 } 00201 return 0; 00202 }
HINSTANCE gadget::InputWindowWin32::m_hInst [protected] |
std::string gadget::InputWindowWin32::mRemoteDisplayName [protected] |
Name of the remote display window (index in registry).
Definition at line 143 of file InputWindowWin32.h.
int gadget::InputWindowWin32::mScreen [protected] |
int gadget::InputWindowWin32::mX [protected] |
Origin X-coordinate.
Definition at line 146 of file InputWindowWin32.h.
Referenced by config(), and createWindowWin32().
int gadget::InputWindowWin32::mY [protected] |
Origin X-coordinate.
Definition at line 147 of file InputWindowWin32.h.
Referenced by config(), and createWindowWin32().
bool gadget::InputWindowWin32::mExitFlag [protected] |
Should we exit?
Definition at line 148 of file InputWindowWin32.h.
Referenced by controlLoop(), startSampling(), and stopSampling().
bool gadget::InputWindowWin32::mControlLoopDone [protected] |
1.5.1