Пример #1
0
XU32 XHTMLButton::Handle(XU32 nOpera, XU32 pData1, XU32 pData2)
{
	if(!IsVisiable()) return 0;
	switch(nOpera)
	{
	case XDO_SELECT:
	      return (XU32)XDomItem::SelectItem((SELECTMARK*)pData1);
	case XDO_HITTEST:
		{
		  XRect rect(m_nPosX,m_nPosY,m_nPosX+m_nWidth,m_nPosY+m_nHeight);
		  if(rect.PtInRect(pData1,pData2))
			  return (XU32)this;
		}
		 return 0;
	case XDO_GET_STYLE:
		{
			XU32 s=XDomBlock::Handle(nOpera,pData1,pData2)|DOM_SELECTABLE;
			return s;
		}break;
	case XDO_PAINT:
		 return Paint((DRAWCONTEXT*)pData1);
	case XDO_EVENT_ONKEYDOWN:
		 if(pData1!=XK_RETURN) break;
	case XDO_EVENT_ONMOUSEUP:
		 return OnMouseUp((XEVENTDATA*)pData2);
	case XDO_EVENT_ONMOUSEOUT:
		 return OnMouseLeave((XEVENTDATA*)pData2);
	case XDO_EVENT_ONMOUSEDOWN:
		 return OnMouseDown(*(XPoint*)pData1,(XEVENTDATA*)pData2);
//	case XDO_ADD_CHILD:
//		 return XDomNode::Handle(nOpera,pData1,pData2);
//	case XDO_GET_STYLE:
//		 return XDomInput::Handle(nOpera,pData1,pData2)|DOM_NODE;
	case XDO_LAYEROUT_CELLS:
		 return LayeroutCells((DRAWCONTEXT*)pData1,(CELLDATA*)pData2);
	case XDO_LAYEROUT_CELL:
		 return LayeroutCell((DRAWCONTEXT*)pData1,(CELLDATA*)pData2);
	}
	return XDomBlock::Handle(nOpera,pData1,pData2);
}
Пример #2
0
LRESULT DXApp::MsgProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	switch (message)
	{
	case WM_DESTROY:
		PostQuitMessage(0);
		return 0;
	case WM_LBUTTONDOWN:
		OnMouseDown(wParam, GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam));
		return 0;
	case WM_LBUTTONUP:
		OnMouseUp(wParam, GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam));
		return 0;
	case WM_KEYDOWN:
		KeyDown(wParam);
		return 0;
	case WM_KEYUP:
		KeyUp(wParam);
		return 0;
	}
	return DefWindowProc(hWnd, message, wParam, lParam);
}
Пример #3
0
 void OnLostFocus()
 {    
     OnMouseUp(0,0,0,0);
     pawsWidget::OnLostFocus();
 }    
Пример #4
0
void GUIControl::Process()
{
	__super::Process();

	if(IsVisible() && IsEnabled())
	{
		if(PointInBox(mouseX, mouseY, GetX(), GetY(), GetWidth(), GetHeight()))
		{

			int cursor = GetLastCursorPos();
			SetLastCursorPos(1); // mouse is in

			// here
			// 0 - init
			// 1 - mouse was IN control
			// 2 - mouse was OUT control

			if(cursor == 0 || cursor == 2)
			{
				OnMouseEnter();
			}
			else
			{
				OnMouseMove();
			}

			if(mouse[0] || mouse[1])
			{
				if(GetLastPressState() == 0)
				{
					OnMouseDown();

					if(mouse[0])
						SetLastPressState(1);
					else if(mouse[1])
						SetLastPressState(2);
				}
			}
			else
			{
				int press_state = GetLastPressState();
				SetLastPressState(0);

				// here
				// 0 - init
				// 1 - left mouse down
				// 2 - right mouse down
				// 3 - all up

				if(press_state == 1)
				{
					OnLeftClick();
					OnMouseUp();
				}
				else if(press_state == 2)
				{
					OnRightClick();
					OnMouseUp();
				}
			}
		}
		else
		{
			int cursor = GetLastCursorPos();
			SetLastCursorPos(2); // mouse is out

			if(cursor == 1)
			{
				OnMouseLeave();
				SetLastPressState(0);
			}
		}


		// TODO:
		// fix it somehow :(
		if(IsFocused())
		{
			static UCHAR count = 0;
			int delay = 0;
			for(UCHAR i = 0; i < 255; i++)
			{			
				if(GetAsyncKeyState(i) & 0x8000)
				{
					count++;
					static int prev;
					count == 1 ? delay = KEY_FIRST_DELAY : delay = KEY_DELAY;

					if(current_time - prev >= delay)
					{
						if(i != VK_SHIFT)
						{
							OnKeyDown(i);
							prev = current_time;
						}
					}
				}
			}
		}
	}
}
Пример #5
0
bool
TopWindow::OnEvent(const SDL_Event &event)
{
  switch (event.type) {
    Window *w;

#if SDL_MAJOR_VERSION < 2
  case SDL_VIDEOEXPOSE:
    invalidated = false;
    Expose();
    return true;
#endif

  case SDL_KEYDOWN:
    w = GetFocusedWindow();
    if (w == nullptr)
      w = this;

    if (!w->IsEnabled())
      return false;

#if SDL_MAJOR_VERSION >= 2
    return w->OnKeyDown(event.key.keysym.sym);
#else
    return w->OnKeyDown(event.key.keysym.sym) ||
      (event.key.keysym.unicode != 0 &&
       w->OnCharacter(event.key.keysym.unicode));
#endif

#if SDL_MAJOR_VERSION >= 2
  case SDL_TEXTINPUT:
    w = GetFocusedWindow();
    if (w == nullptr)
      w = this;

    if (!w->IsEnabled())
      return false;

    if (event.text.text && *event.text.text) {
      std::pair<unsigned, const char *> next = NextUTF8(event.text.text);
      bool handled = w->OnCharacter(next.first);
      while (next.second) {
        next = NextUTF8(next.second);
        handled = w->OnCharacter(next.first) || handled;
      }
      return handled;
    } else
      return false;
#endif

  case SDL_KEYUP:
    w = GetFocusedWindow();
    if (w == nullptr)
      w = this;

    if (!w->IsEnabled())
      return false;

    return w->OnKeyUp(event.key.keysym.sym);

#ifdef HAVE_MULTI_TOUCH
  case SDL_FINGERDOWN:
    if (SDL_GetNumTouchFingers(event.tfinger.touchId) == 2)
      return OnMultiTouchDown();
    else
      return false;

  case SDL_FINGERUP:
    if (SDL_GetNumTouchFingers(event.tfinger.touchId) == 1)
      return OnMultiTouchUp();
    else
      return false;
#endif

  case SDL_MOUSEMOTION:
    // XXX keys
    return OnMouseMove(event.motion.x, event.motion.y, 0);

  case SDL_MOUSEBUTTONDOWN:
#if SDL_MAJOR_VERSION < 2
    if (event.button.button == SDL_BUTTON_WHEELUP)
      return OnMouseWheel(event.button.x, event.button.y, 1);
    else if (event.button.button == SDL_BUTTON_WHEELDOWN)
      return OnMouseWheel(event.button.x, event.button.y, -1);
#endif

    return double_click.Check(RasterPoint(event.button.x, event.button.y))
      ? OnMouseDouble(event.button.x, event.button.y)
      : OnMouseDown(event.button.x, event.button.y);

  case SDL_MOUSEBUTTONUP:
#if SDL_MAJOR_VERSION < 2
    if (event.button.button == SDL_BUTTON_WHEELUP ||
        event.button.button == SDL_BUTTON_WHEELDOWN)
      /* the wheel has already been handled in SDL_MOUSEBUTTONDOWN */
      return false;
#endif

    double_click.Moved(RasterPoint(event.button.x, event.button.y));

    return OnMouseUp(event.button.x, event.button.y);

  case SDL_QUIT:
    return OnClose();

#if SDL_MAJOR_VERSION < 2
  case SDL_VIDEORESIZE:
    Resize(event.resize.w, event.resize.h);
    return true;
#endif

#if SDL_MAJOR_VERSION >= 2
  case SDL_MOUSEWHEEL:
    int x, y;
    SDL_GetMouseState(&x, &y);
    return OnMouseWheel(x, y, event.wheel.y);

  case SDL_WINDOWEVENT:
    switch (event.window.event) {

    case SDL_WINDOWEVENT_RESIZED:
      Resize(event.window.data1, event.window.data2);
      return true;

    case SDL_WINDOWEVENT_RESTORED:
    case SDL_WINDOWEVENT_MOVED:
    case SDL_WINDOWEVENT_SHOWN:
    case SDL_WINDOWEVENT_MAXIMIZED:
      {
        SDL_Window* event_window = SDL_GetWindowFromID(event.window.windowID);
        if (event_window) {
          int w, h;
          SDL_GetWindowSize(event_window, &w, &h);
          if ((w >= 0) && (h >= 0)) {
            Resize(w, h);
          }
        }
      }
      return true;

    case SDL_WINDOWEVENT_EXPOSED:
      invalidated = false;
      Expose();
      return true;
    }
#endif
  }

  return false;
}
Пример #6
0
LRESULT D3DApp::MsgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	switch (msg)
	{
	// WM_ACTIVATE is sent when the window is activated or deactivated.  
	// We pause the game when the window is deactivated and unpause it 
	// when it becomes active.  
	case WM_ACTIVATE:
	{
		if (LOWORD(wParam) == WA_INACTIVE)
		{
			mAppPaused = true;
			mTimer.Stop();
		}
		else
		{
			mAppPaused = false;
			mTimer.Start();
		}
		return 0;
	}

	// WM_SIZE is sent when the user resizes the window.  
	case WM_SIZE:
	{
		// Save the new client area dimensions.
		mClientWidth = LOWORD(lParam);
		mClientHeight = HIWORD(lParam);
		if (mDevice)
		{
			if (wParam == SIZE_MINIMIZED)
			{
				mAppPaused = true;
				mMinimized = true;
				mMaximized = false;
			}
			else if (wParam == SIZE_MAXIMIZED)
			{
				mAppPaused = false;
				mMinimized = false;
				mMaximized = true;
				OnResize();
			}
			else if (wParam == SIZE_RESTORED)
			{
				// Restoring from minimized state?
				if (mMinimized)
				{
					mAppPaused = false;
					mMinimized = false;
					OnResize();
				}

				// Restoring from maximized state?
				else if (mMaximized)
				{
					mAppPaused = false;
					mMaximized = false;
					OnResize();
				}
				else // API call such as SetWindowPos or mSwapChain->SetFullscreenState.
				{
					OnResize();
				}
			}
		}
		return 0;
	}

	// WM_EXITSIZEMOVE is sent when the user grabs the resize bars.
	case WM_ENTERSIZEMOVE:
	{
		mAppPaused = true;
		mTimer.Stop();
		return 0;
	}

	// WM_EXITSIZEMOVE is sent when the user releases the resize bars.
	// Here we reset everything based on the new window dimensions.
	case WM_EXITSIZEMOVE:
	{
		mAppPaused = false;
		mTimer.Start();
		OnResize();
		return 0;
	}

	// WM_DESTROY is sent when the window is being destroyed.
	case WM_DESTROY:
	{
		PostQuitMessage(0);
		return 0;
	}

	// The WM_MENUCHAR message is sent when a menu is active and the user presses 
	// a key that does not correspond to any mnemonic or accelerator key. 
	case WM_MENUCHAR:
	{
		// Don't beep when we alt-enter.
		return MAKELRESULT(0, MNC_CLOSE);
	}

	// Catch this message so to prevent the window from becoming too small.
	case WM_GETMINMAXINFO:
	{
		((MINMAXINFO*)lParam)->ptMinTrackSize.x = 200;
		((MINMAXINFO*)lParam)->ptMinTrackSize.y = 200;
		return 0;
	}

	case WM_LBUTTONDOWN:
	case WM_MBUTTONDOWN:
	case WM_RBUTTONDOWN:
		OnMouseDown(wParam, GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam));
		return 0;

	case WM_LBUTTONUP:
	case WM_MBUTTONUP:
	case WM_RBUTTONUP:
		OnMouseUp(wParam, GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam));
		return 0;

	case WM_MOUSEMOVE:
		OnMouseMove(wParam, GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam));
		return 0;

	case WM_CHAR:
		OnKeyDown(wParam, lParam);
		return 0;
	}


	return DefWindowProc(hwnd, msg, wParam, lParam);
}
Пример #7
0
bool
TopWindow::OnEvent(const Event &event)
{
  switch (event.type) {
    Window *w;

  case Event::NOP:
  case Event::QUIT:
  case Event::TIMER:
  case Event::USER:
  case Event::CALLBACK:
    break;

  case Event::KEY_DOWN:
    w = GetFocusedWindow();
    if (w == nullptr)
      w = this;

    return w->OnKeyDown(event.param);

  case Event::KEY_UP:
    w = GetFocusedWindow();
    if (w == nullptr)
      w = this;

    return w->OnKeyUp(event.param);

  case Event::MOUSE_MOTION:
    // XXX keys
    return OnMouseMove(event.point.x, event.point.y, 0);

  case Event::MOUSE_DOWN:
    return double_click.Check(event.point)
      ? OnMouseDouble(event.point.x, event.point.y)
      : OnMouseDown(event.point.x, event.point.y);

  case Event::MOUSE_UP:
    double_click.Moved(event.point);

    return OnMouseUp(event.point.x, event.point.y);

  case Event::MOUSE_WHEEL:
    return OnMouseWheel(event.point.x, event.point.y, (int)event.param);

  case Event::POINTER_DOWN:
    return OnMultiTouchDown();

  case Event::POINTER_UP:
    return OnMultiTouchUp();

  case Event::RESIZE:
    if (!surface_valid)
      /* postpone the resize if we're paused; the real resize will be
         handled by TopWindow::refresh() as soon as XCSoar is
         resumed */
      return true;

    if (unsigned(event.point.x) == GetWidth() &&
        unsigned(event.point.y) == GetHeight())
      /* no-op */
      return true;

    /* it seems the first page flip after a display orientation change
       is ignored on Android (tested on a Dell Streak / Android
       2.2.2); let's do one dummy call before we really draw
       something */
    screen->Flip();

    Resize(event.point.x, event.point.y);
    return true;

  case Event::PAUSE:
    OnPause();
    return true;

  case Event::RESUME:
    OnResume();
    return true;
  }

  return false;
}
Пример #8
0
bool
TopWindow::OnEvent(const SDL_Event &event)
{
  switch (event.type) {
    Window *w;

#if SDL_MAJOR_VERSION < 2
  case SDL_VIDEOEXPOSE:
    invalidated = false;
    Expose();
    return true;
#endif

  case SDL_KEYDOWN:
    w = GetFocusedWindow();
    if (w == NULL)
      w = this;

    if (!w->IsEnabled())
      return false;

#if SDL_MAJOR_VERSION >= 2
    return w->OnKeyDown(event.key.keysym.sym);
#else
    return w->OnKeyDown(event.key.keysym.sym) ||
      (event.key.keysym.unicode != 0 &&
       w->OnCharacter(event.key.keysym.unicode));
#endif

#if SDL_MAJOR_VERSION >= 2
  case SDL_TEXTINPUT:
    w = GetFocusedWindow();
    if (w == NULL)
      w = this;

    if (!w->IsEnabled())
      return false;

    if (event.text.text && *event.text.text) {
      std::pair<unsigned, const char *> next = NextUTF8(event.text.text);
      bool handled = w->OnCharacter(next.first);
      while (next.second) {
        next = NextUTF8(next.second);
        handled = w->OnCharacter(next.first) || handled;
      }
      return handled;
    } else
      return false;
#endif

  case SDL_KEYUP:
    w = GetFocusedWindow();
    if (w == NULL)
      w = this;

    if (!w->IsEnabled())
      return false;

    return w->OnKeyUp(event.key.keysym.sym);

  case SDL_MOUSEMOTION:
    // XXX keys
    return OnMouseMove(event.motion.x, event.motion.y, 0);

  case SDL_MOUSEBUTTONDOWN:
#if SDL_MAJOR_VERSION < 2
    if (event.button.button == SDL_BUTTON_WHEELUP)
      return OnMouseWheel(event.button.x, event.button.y, 1);
    else if (event.button.button == SDL_BUTTON_WHEELDOWN)
      return OnMouseWheel(event.button.x, event.button.y, -1);
#endif

    return double_click.Check(RasterPoint(event.button.x, event.button.y))
      ? OnMouseDouble(event.button.x, event.button.y)
      : OnMouseDown(event.button.x, event.button.y);

  case SDL_MOUSEBUTTONUP:
#if SDL_MAJOR_VERSION < 2
    if (event.button.button == SDL_BUTTON_WHEELUP ||
        event.button.button == SDL_BUTTON_WHEELDOWN)
      /* the wheel has already been handled in SDL_MOUSEBUTTONDOWN */
      return false;
#endif

    double_click.Moved(RasterPoint(event.button.x, event.button.y));

    return OnMouseUp(event.button.x, event.button.y);

  case SDL_QUIT:
    return OnClose();

#if SDL_MAJOR_VERSION < 2
  case SDL_VIDEORESIZE:
    Resize(event.resize.w, event.resize.h);
    return true;
#endif

#if SDL_MAJOR_VERSION >= 2
  case SDL_MOUSEWHEEL:
    int x, y;
    SDL_GetMouseState(&x, &y);
    return OnMouseWheel(x, y, event.wheel.y);

  case SDL_WINDOWEVENT:
    switch (event.window.event) {

    case SDL_WINDOWEVENT_RESIZED:
      Resize(event.window.data1, event.window.data2);
      return true;

    case SDL_WINDOWEVENT_EXPOSED:
      invalidated = false;
      Expose();
      return true;
    }
#endif
  }

  return false;
}
Пример #9
0
LRESULT GenericWindow::HandleMessage (UINT msg, WPARAM wParam, LPARAM lParam) {
	switch (msg) {	
	case WM_MOUSEMOVE:
		if (!m_flagMouseTracking) {
			// register for mouse out message (TME_LEAVE)
			TRACKMOUSEEVENT trackMouseEvent;
			trackMouseEvent.cbSize = sizeof (trackMouseEvent);
			trackMouseEvent.dwFlags = TME_LEAVE;
			trackMouseEvent.dwHoverTime = 0;
			trackMouseEvent.hwndTrack = GetHandle ();
			m_flagMouseTracking = ::TrackMouseEvent (&trackMouseEvent);
		}
		OnMouseMove (0, -1, LOWORD(lParam), HIWORD(lParam));
		break;

	case WM_MOUSELEAVE:
		OnMouseLeave ();
		m_flagMouseTracking = FALSE;
		break;

	case WM_LBUTTONDOWN:
		OnMouseDown (0, 0, LOWORD(lParam), HIWORD(lParam));
		break;

	case WM_LBUTTONUP:
		OnMouseUp (0, 0, LOWORD(lParam), HIWORD(lParam));
		break;

	case WM_RBUTTONDOWN:
		OnMouseDown (0, 1, LOWORD(lParam), HIWORD(lParam));
		break;

	case WM_RBUTTONUP:
		OnMouseUp (0, 1, LOWORD(lParam), HIWORD(lParam));
		OnContextMenu ( );
		break;

	case WM_ERASEBKGND:
		// we'll erase the background during the WM_PAINT message as necessary
		// to support dynamic background color for views
		// return FALSE to indicate we didn't erase the background here.
		return FALSE;

	case WM_PAINT: 
		{
			PAINTSTRUCT ps;
			HDC hdc = ::BeginPaint (m_hWnd, &ps);

			// erase the background if required
			if (ps.fErase) {
				OnEraseBackground (hdc, ps);
				ps.fErase = FALSE;
			}

			OnPaint (hdc, ps);

			::EndPaint (m_hWnd, &ps);
		}
		break;

	case WM_CHAR:
		OnKeyPress ( (int)wParam, LOWORD(lParam) );
		break;

	case WM_KEYDOWN:
		OnKeyDown ( (int)wParam );
		break;

	case WM_KEYUP:
		OnKeyUp ( (int)wParam );
		break;

	case WM_NCDESTROY:
		OnPreDestroy ();
		m_hWnd = NULL;
		break;

	case WM_DESTROY:
		OnDestroy ();
		if (m_isMainWnd) {
			// ::MessageBox (0, _T("callling PostQuitMessage(0)"), _T(""), 0);
			::PostQuitMessage (0);
		}
		break;

	case WM_SIZE:
		{
			int cx, cy;
			cx = LOWORD(lParam);
			cy = HIWORD(lParam);
			OnResize (cx, cy);
		}
		break;

	case WM_SETFOCUS:
		OnGotFocus ();
		break;

	case WM_KILLFOCUS:
		OnLostFocus ();
		break;

	case WM_COMMAND:
		OnCommand ( LOWORD(wParam) );
		break;

	case WM_CONTEXTMENU:
		OnContextMenu ( );
		break;

	case WM_CLOSE:
		{
			BOOL cancel = FALSE;
			OnClose (cancel);
			if (cancel == FALSE) 
				DestroyWindow (m_hWnd);
		}
		break;

	case WM_DROPFILES:
		OnDropFiles ((HDROP)wParam);
		break;

	default:
		return ::DefWindowProc (m_hWnd, msg, wParam, lParam);
	}

	return 0;
}
Пример #10
0
	void AEEngine::i_OnMouseUp(int *param)
	{
		if(this->OnMouseUp!=NULL)
			OnMouseUp(param);
	}
Пример #11
0
LRESULT D3D11App::MsgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	switch (msg)
	{
		// WM_ACTIVATE is sent when the window is activated or deactivated.  
		// We pause the game when the window is deactivated and unpause it 
		// when it becomes active.  
	case WM_ACTIVATE:
/*
		if (LOWORD(wParam) == WA_INACTIVE)
		{
			mAppPaused = true;
			mTimer.Stop();
		}
		else
		{
			mAppPaused = false;
			mTimer.Start();
		}*/
		return 0;
		// WM_SIZE is sent when the user resizes the window.  
	case WM_SIZE:
		// Save the new client area dimensions.
		mClientWidth = LOWORD(lParam);
		mClientHeight = HIWORD(lParam);
		if (SwapChainPtr->GetState())
		{
			if (wParam == SIZE_MINIMIZED)
			{
				mAppPaused = true;
				mMinimized = true;
				mMaximized = false;
			}
			else if (wParam == SIZE_MAXIMIZED)
			{
				mAppPaused = false;
				mMinimized = false;
				mMaximized = true;
				OnResize();
			}
			else if (wParam == SIZE_RESTORED)
			{

				// Restoring from minimized state?
				if (mMinimized)
				{
					mAppPaused = false;
					mMinimized = false;
					OnResize();
				}

				// Restoring from maximized state?
				else if (mMaximized)
				{
					mAppPaused = false;
					mMaximized = false;
					OnResize();
				}
				else if (mResizing)
				{
					// If user is dragging the resize bars, we do not resize 
					// the buffers here because as the user continuously 
					// drags the resize bars, a stream of WM_SIZE messages are
					// sent to the window, and it would be pointless (and slow)
					// to resize for each WM_SIZE message received from dragging
					// the resize bars.  So instead, we reset after the user is 
					// done resizing the window and releases the resize bars, which 
					// sends a WM_EXITSIZEMOVE message.
				}
				else // API call such as SetWindowPos or mSwapChain->SetFullscreenState.
				{
					OnResize();
				}
			}
		}
		return 0;
		// WM_EXITSIZEMOVE is sent when the user grabs the resize bars.
	case WM_ENTERSIZEMOVE:
		mAppPaused = true;
		mResizing = true;
		mTimer.Stop();
		mClientWidthOld = mClientWidth;
		mClientHeightOld = mClientHeight;
		return 0;

		// WM_EXITSIZEMOVE is sent when the user releases the resize bars.
		// Here we reset everything based on the new window dimensions.
	case WM_EXITSIZEMOVE:

		mAppPaused = false;
		mResizing = false;
		mTimer.Start();
		if ((mClientWidthOld != mClientWidth) && (mClientHeightOld!= mClientHeight))
		{
			OnResize();
		}
		return 0;

/*
	case WM_PAINT:
		hDC = BeginPaint(hwnd, &paintStruct);
		EndPaint(hwnd, &paintStruct);
		break;*/
		// Catch this message so to prevent the window from becoming too small.
	case WM_GETMINMAXINFO:
		((MINMAXINFO*)lParam)->ptMinTrackSize.x = 200;
		((MINMAXINFO*)lParam)->ptMinTrackSize.y = 200;
		return 0;
	case WM_DESTROY:
		PostQuitMessage(0);
		break;
	case WM_LBUTTONDOWN:
	case WM_MBUTTONDOWN:
	case WM_RBUTTONDOWN:
		OnMouseDown(wParam, GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam));
		return 0;
	case WM_LBUTTONUP:
	case WM_MBUTTONUP:
	case WM_RBUTTONUP:
		OnMouseUp(wParam, GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam));
		return 0;
	case WM_MOUSEMOVE:
		OnMouseMove(wParam, GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam));
		return 0;
	case  WM_MOUSEWHEEL:
	{
		short zDelta = (short)HIWORD(wParam);
		OnMouseWheel(zDelta, GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam));
		return 0;
	}
	case  WM_LBUTTONDBLCLK:
		OnLButtonDblClk(wParam, GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam));
		return 0;
	default:
		return DefWindowProc(hwnd, msg, wParam, lParam);
	}

	return 0;
}
Пример #12
0
/*------------------------------------------------
  subclass procedure of the clock
--------------------------------------------------*/
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	switch(message) // for tooltip
	{
		case WM_MOUSEMOVE:
		case WM_LBUTTONDOWN:
		case WM_RBUTTONDOWN:
		case WM_MBUTTONDOWN:
		case WM_LBUTTONUP:
		case WM_RBUTTONUP:
		case WM_MBUTTONUP:
#if TC_ENABLE_WHEEL
		case WM_MOUSEWHEEL:
#endif
			OnTooltipMouseMsg(hwnd, message, wParam, lParam);
			break;
	}
	
	switch(message)
	{
		/* -------- drawing & sizing ------------- */
		
		case WM_PAINT:
		{
			PAINTSTRUCT ps;
			HDC hdc;
			if(g_bNoClock) break;
			hdc = BeginPaint(hwnd, &ps);
			OnPaint(hwnd, hdc, NULL);
			EndPaint(hwnd, &ps);
			return 0;
		}
		case WM_ERASEBKGND:
			break;
		
		case (WM_USER+100):        // a message requesting for clock size
			if(g_bNoClock) break;  // sent from parent window
			return OnCalcRect(hwnd);
		
		case WM_WINDOWPOSCHANGING:  // size arrangement
			if(g_bNoClock) break;
			OnWindowPosChanging(hwnd, (LPWINDOWPOS)lParam);
			break;
		
		case WM_SIZE:
			if(g_bNoClock) break;
			CreateClockDC(hwnd);    // create offscreen DC
			return 0;
		case WM_SYSCOLORCHANGE:
		case WM_THEMECHANGED:
			if(g_bNoClock) break;
			CreateClockDC(hwnd);   // create offscreen DC
			InvalidateRect(hwnd, NULL, FALSE);
#if TC_ENABLE_DESKTOPICON
			SetDesktopIcons();		// desktop.c
#endif
			return 0;
		case WM_WININICHANGE:
		case WM_TIMECHANGE:
		case (WM_USER+101):
		case WM_SETFOCUS:
		case WM_KILLFOCUS:
			if(g_bNoClock) break;
			InvalidateRect(hwnd, NULL, FALSE);
			return 0;
		
		/* -------- Timers ------------- */
		
		case WM_TIMER:
			switch (wParam)
			{
				case IDTIMER_MAIN:
					OnTimerMain(hwnd); return 0;
#if TC_ENABLE_SYSINFO
				case IDTIMER_SYSINFO:
					OnTimerSysInfo();		// sysinfo.c
#if TC_ENABLE_DESKTOPICON
					SetDesktopIcons();		// desktop.c
#endif
					return 0;
#endif
			}
			if(g_bNoClock) break;
			return 0;
		
		/* -------- Mouse messages ------------- */
		
		case WM_LBUTTONDOWN:   // mouse button is down
		case WM_RBUTTONDOWN:
		case WM_MBUTTONDOWN:
		case WM_XBUTTONDOWN:
			return OnMouseDown(hwnd, message, wParam, lParam);
		
		case WM_LBUTTONUP:    // mouse button is up
		case WM_RBUTTONUP:
		case WM_MBUTTONUP:
		case WM_XBUTTONUP:
			return OnMouseUp(hwnd, message, wParam, lParam);
		
		case WM_MOUSEMOVE:
			return 0;
		case WM_NCRBUTTONUP:
			return 0;
		case WM_CONTEXTMENU:
			PostMessage(g_hwndTClockMain, WM_CONTEXTMENU, wParam, lParam);
			return 0;
		case WM_NCHITTEST:     // not to pass to g_oldWndProc
			return DefWindowProc(hwnd, message, wParam, lParam);
		case WM_MOUSEACTIVATE:
			return MA_ACTIVATE;
#if TC_ENABLE_MOUSEDROP
		case WM_DROPFILES:     // files are dropped
			PostMessage(g_hwndTClockMain, WM_DROPFILES, wParam, lParam);
			return 0;
#endif
#if TC_ENABLE_WHEEL
		case WM_MOUSEWHEEL:  // the mouse wheel is rotated
			PostMessage(g_hwndTClockMain, WM_MOUSEWHEEL, wParam, lParam);
			return 0;
#endif
		
		case WM_NOTIFY: // tooltip
		{
			LRESULT res;
			if(OnTooltipNotify(hwnd, &res, (LPNMHDR)lParam)) return res;
			break;
		}
		
		/* messages sent from other program */
		
		case CLOCKM_EXIT:   // clean up all
			EndClock(hwnd);
			return 0;
		case CLOCKM_REFRESHCLOCK: // refresh the clock
			OnRefreshClock(hwnd);
			return 0;
		case CLOCKM_DELUSRSTR:    // clear user strings
			InitUserStr();
			return 0;
#if TC_ENABLE_TASKBAR
		case CLOCKM_REFRESHTASKBAR: // refresh other elements than clock
			OnRefreshTaskbar(hwnd);
			return 0;
#endif
#if TC_ENABLE_STARTMENU
		case CLOCKM_REFRESHSTARTMENU: // refresh Start menu
			OnRefreshStartMenu(hwnd);
			return 0;
#endif
		case CLOCKM_REFRESHTOOLTIP: // refresh tooltip
			OnRefreshTooltip(hwnd);
			return 0;
		case CLOCKM_BLINK: // blink the clock
			g_nBlink = 2;
			m_nBlinkSec = lParam;
			if(lParam) m_nBlinkTick = GetTickCount();
			return 0;
		case CLOCKM_COPY: // copy format to clipboard
			OnCopy(hwnd, NULL);
			return 0;
#if TC_ENABLE_VOLUME
		case CLOCKM_VOLCHANGE:
			OnVolumeChange(hwnd);
			return 0;
#endif
		
		case WM_COPYDATA:
			OnCopyData(hwnd, (HWND)wParam, (COPYDATASTRUCT*)lParam);
			return 0;
		
		/* WM_DESTROY is sent only when Win95+IE4/98/Me is shut down */
		
		case WM_DESTROY:
			OnDestroy(hwnd); // main2.c
			break;
	}
	
	return CallWindowProc(g_oldWndProc, hwnd, message, wParam, lParam);
}
Пример #13
0
bool
TopWindow::OnEvent(const SDL_Event &event)
{
  switch (event.type) {
    Window *w;

#if SDL_MAJOR_VERSION < 2
  case SDL_VIDEOEXPOSE:
    invalidated = false;
    Expose();
    return true;
#endif

  case SDL_KEYDOWN:
    w = GetFocusedWindow();
    if (w == nullptr)
      w = this;

    if (!w->IsEnabled())
      return false;

#if SDL_MAJOR_VERSION >= 2
    return w->OnKeyDown(event.key.keysym.sym);
#else
    return w->OnKeyDown(event.key.keysym.sym) ||
      (event.key.keysym.unicode != 0 &&
       w->OnCharacter(event.key.keysym.unicode));
#endif

#if SDL_MAJOR_VERSION >= 2
  case SDL_TEXTINPUT:
    w = GetFocusedWindow();
    if (w == nullptr)
      w = this;

    if (!w->IsEnabled())
      return false;

    if (*event.text.text) {
      std::pair<unsigned, const char *> next = NextUTF8(event.text.text);
      bool handled = w->OnCharacter(next.first);
      while (next.second) {
        next = NextUTF8(next.second);
        handled = w->OnCharacter(next.first) || handled;
      }
      return handled;
    } else
      return false;
#endif

  case SDL_KEYUP:
    w = GetFocusedWindow();
    if (w == nullptr)
      w = this;

    if (!w->IsEnabled())
      return false;

    return w->OnKeyUp(event.key.keysym.sym);

#ifdef HAVE_MULTI_TOUCH
  case SDL_FINGERDOWN:
    if (SDL_GetNumTouchFingers(event.tfinger.touchId) == 2)
      return OnMultiTouchDown();
    else
      return false;

  case SDL_FINGERUP:
    if (SDL_GetNumTouchFingers(event.tfinger.touchId) == 1)
      return OnMultiTouchUp();
    else
      return false;
#endif

  case SDL_MOUSEMOTION:
    // XXX keys
#ifdef HAVE_HIGHDPI_SUPPORT
    {
      auto x = event.motion.x;
      auto y = event.motion.y;
      PointToReal(x, y);
      return OnMouseMove(x, y, 0);
    }
#else
    return OnMouseMove(event.motion.x, event.motion.y, 0);
#endif

  case SDL_MOUSEBUTTONDOWN:
    {
#if SDL_MAJOR_VERSION < 2
      if (event.button.button == SDL_BUTTON_WHEELUP)
        return OnMouseWheel(event.button.x, event.button.y, 1);
      else if (event.button.button == SDL_BUTTON_WHEELDOWN)
        return OnMouseWheel(event.button.x, event.button.y, -1);
#endif

#ifdef HAVE_HIGHDPI_SUPPORT
      auto x = event.button.x;
      auto y = event.button.y;
      PointToReal(x, y);

      return double_click.Check(RasterPoint(x, y))
        ? OnMouseDouble(x, y)
        : OnMouseDown(x, y);
#else
      return double_click.Check(RasterPoint(event.button.x, event.button.y))
        ? OnMouseDouble(event.button.x, event.button.y)
        : OnMouseDown(event.button.x, event.button.y);
#endif
    }

  case SDL_MOUSEBUTTONUP:
    {
#if SDL_MAJOR_VERSION < 2
      if (event.button.button == SDL_BUTTON_WHEELUP ||
          event.button.button == SDL_BUTTON_WHEELDOWN)
        /* the wheel has already been handled in SDL_MOUSEBUTTONDOWN */
        return false;
#endif

#ifdef HAVE_HIGHDPI_SUPPORT
      auto x = event.button.x;
      auto y = event.button.y;
      PointToReal(x, y);

      double_click.Moved(RasterPoint(x, y));

      return OnMouseUp(x, y);
#else
      double_click.Moved(RasterPoint(event.button.x, event.button.y));

      return OnMouseUp(event.button.x, event.button.y);
#endif
    }

  case SDL_QUIT:
    return OnClose();

#if SDL_MAJOR_VERSION < 2
  case SDL_VIDEORESIZE:
    Resize(event.resize.w, event.resize.h);
    return true;
#endif

#if SDL_MAJOR_VERSION >= 2
  case SDL_MOUSEWHEEL:
    {
      int x, y;
      SDL_GetMouseState(&x, &y);
#ifdef HAVE_HIGHDPI_SUPPORT
      PointToReal(x, y);
#endif
      return OnMouseWheel(x, y, event.wheel.y);
    }

  case SDL_WINDOWEVENT:
    switch (event.window.event) {

    case SDL_WINDOWEVENT_RESIZED:
#ifndef HAVE_HIGHDPI_SUPPORT
      Resize(event.window.data1, event.window.data2);
      return true;
#endif
    case SDL_WINDOWEVENT_RESTORED:
    case SDL_WINDOWEVENT_MOVED:
    case SDL_WINDOWEVENT_SHOWN:
    case SDL_WINDOWEVENT_MAXIMIZED:
      {
        SDL_Window* event_window = SDL_GetWindowFromID(event.window.windowID);
        if (event_window) {
          int w, h;
          SDL_GetWindowSize(event_window, &w, &h);
          if ((w >= 0) && (h >= 0)) {
#ifdef HAVE_HIGHDPI_SUPPORT
            int real_w, real_h;
            SDL_GL_GetDrawableSize(event_window, &real_w, &real_h);
            point_to_real_x = static_cast<float>(real_w) /
                              static_cast<float>(w);
            point_to_real_y = static_cast<float>(real_h) /
                              static_cast<float>(h);
            Resize(real_w, real_h);
#else
            Resize(w, h);
#endif
          }

#if defined(__MACOSX__) && __MACOSX__
          SDL_SysWMinfo *wm_info =
              reinterpret_cast<SDL_SysWMinfo *>(alloca(sizeof(SDL_SysWMinfo)));
          SDL_VERSION(&wm_info->version);
          if ((SDL_GetWindowWMInfo(event_window, wm_info)) &&
              (wm_info->subsystem == SDL_SYSWM_COCOA)) {
            [wm_info->info.cocoa.window
                setCollectionBehavior:
                    NSWindowCollectionBehaviorFullScreenPrimary];
          }
          Invalidate();
#endif
        }
      }
      return true;

    case SDL_WINDOWEVENT_EXPOSED:
      invalidated = false;
      Expose();
      return true;
    }
#endif
  }
Пример #14
0
//***********************************************************************************************************
BOOL CBCGPBaseVisualCtrl::PreTranslateMessage(MSG* pMsg) 
{
	switch (pMsg->message)
	{
	case WM_KEYDOWN:
	case WM_SYSKEYDOWN:
	case WM_LBUTTONDOWN:
	case WM_RBUTTONDOWN:
	case WM_MBUTTONDOWN:
	case WM_LBUTTONUP:
	case WM_RBUTTONUP:
	case WM_MBUTTONUP:
	case WM_NCLBUTTONDOWN:
	case WM_NCRBUTTONDOWN:
	case WM_NCMBUTTONDOWN:
	case WM_NCLBUTTONUP:
	case WM_NCRBUTTONUP:
	case WM_NCMBUTTONUP:
	case WM_MOUSEMOVE:
		if (m_pToolTip->GetSafeHwnd () != NULL)
		{
			m_pToolTip->RelayEvent(pMsg);
		}
	}

	switch (pMsg->message)
	{
	case WM_LBUTTONDOWN:
	case WM_RBUTTONDOWN:
	case WM_MBUTTONDOWN:
		if (pMsg->hwnd == GetSafeHwnd())
		{
			if (!m_bIsPopup)
			{
				SetFocus();
			}

			CPoint pt (BCG_GET_X_LPARAM(pMsg->lParam), BCG_GET_Y_LPARAM(pMsg->lParam));
			if (OnMouseDown(pMsg->message == WM_LBUTTONDOWN ? 0 : pMsg->message == WM_RBUTTONDOWN ? 1 : 2, pt))
			{
#if !defined _BCGPCHART_STANDALONE
				if (CBCGPPopupMenu::GetActiveMenu() != NULL && ::IsWindow (CBCGPPopupMenu::GetActiveMenu()->m_hWnd))
				{
					CBCGPPopupMenu::GetActiveMenu()->SendMessage (WM_CLOSE);
				}
#endif
				SetCapture();
				m_bIsCaptured = TRUE;

				StartClickAndHold();
				return TRUE;
			}
		}
		break;

	case WM_LBUTTONUP:
	case WM_RBUTTONUP:
	case WM_MBUTTONUP:
		if (pMsg->hwnd == GetSafeHwnd())
		{
			CPoint pt (BCG_GET_X_LPARAM(pMsg->lParam), BCG_GET_Y_LPARAM(pMsg->lParam));
			OnMouseUp(pMsg->message == WM_LBUTTONUP ? 0 : pMsg->message == WM_RBUTTONUP ? 1 : 2, pt);

			if (m_bIsCaptured)
			{
				ReleaseCapture();
				m_bIsCaptured = FALSE;
			}

			StopClickAndHold();
		}
		break;

	case WM_LBUTTONDBLCLK:
	case WM_RBUTTONDBLCLK:
	case WM_MBUTTONDBLCLK:
		if (pMsg->hwnd == GetSafeHwnd())
		{
			CPoint pt (BCG_GET_X_LPARAM(pMsg->lParam), BCG_GET_Y_LPARAM(pMsg->lParam));
			OnMouseDblClick(pMsg->message == WM_LBUTTONDBLCLK ? 0 : pMsg->message == WM_RBUTTONDBLCLK ? 1 : 2, pt);
		}
		break;
	
	case WM_MOUSEWHEEL:
		{
			CPoint pt (BCG_GET_X_LPARAM(pMsg->lParam), BCG_GET_Y_LPARAM(pMsg->lParam));

			CWnd* pWnd = CWnd::FromHandle (pMsg->hwnd);
			if (pWnd != NULL)
			{
				pWnd->ScreenToClient(&pt);
			}

			if (OnMouseWheel(pt, HIWORD(pMsg->wParam)))
			{
				if (m_pToolTip->GetSafeHwnd () != NULL)
				{
					m_pToolTip->Pop();
				}

				return TRUE;
			}
		}
		break;

	case WM_MOUSEMOVE:
		{
			CPoint pt (BCG_GET_X_LPARAM(pMsg->lParam), BCG_GET_Y_LPARAM(pMsg->lParam));

			OnMouseMove(pt);

			if (!m_bIsTracked)
			{
				m_bIsTracked = TRUE;
				
				TRACKMOUSEEVENT trackmouseevent;
				trackmouseevent.cbSize = sizeof(trackmouseevent);
				trackmouseevent.dwFlags = TME_LEAVE;
				trackmouseevent.hwndTrack = GetSafeHwnd();
				trackmouseevent.dwHoverTime = HOVER_DEFAULT;
				::BCGPTrackMouse (&trackmouseevent);	
			}

			if (m_pToolTip->GetSafeHwnd () != NULL)
			{
				CString strToolTip;
				CString strDescr;

				OnGetToolTip(pt, strToolTip, strDescr);

				if (strToolTip != m_strLastDisplayedToolTip || strDescr != m_strLastDisplayedToolTipDescr)
				{
					if (m_bTooltipTrackingMode)
					{
						m_pToolTip->Update();
					}
					else
					{
						m_pToolTip->Pop ();
					}

					if (!strToolTip.IsEmpty() && !strDescr.IsEmpty())
					{
						m_bToolTipCleared = TRUE;
					}
				}
			}
		}
		break;

	case WM_CANCELMODE:
		if (m_bIsCaptured)
		{
			ReleaseCapture();
			m_bIsCaptured = FALSE;

			OnCancelMode();
		}

		StopClickAndHold();
		break;

	case WM_KEYDOWN:
		if (pMsg->wParam == VK_ESCAPE)
		{
			if (OnKeyboardDown((UINT)pMsg->wParam, (pMsg->lParam & 0xFFFF), 0))
			{
				return TRUE;
			}
		}
		break;

	case WM_TIMER:
		if (pMsg->hwnd == GetSafeHwnd() && pMsg->wParam == GetClickAndHoldID())
		{
			CPoint point;
			
			::GetCursorPos (&point);
			ScreenToClient (&point);

			if (GetClickAndHoldRect().PtInRect(point))
			{
				OnClickAndHoldEvent(GetClickAndHoldID(), point);
				return TRUE;
			}
		}
		break;
	}

	return CStatic::PreTranslateMessage(pMsg);
}
Пример #15
0
HRESULT GLWindow::HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam)
{
	if (bDummy)
		return DefWindowProc(m_hwnd, uMsg, wParam, lParam);
	
	int ll = (int)(short)LOWORD(lParam);
	int hl = (int)(short)HIWORD(lParam);

	OnMessage(uMsg, wParam, lParam);
	switch(uMsg)
	{
	case WM_CREATE:
		initRC();
		OnCreate();
		return 0;
	case WM_PAINT:
		this->Redraw();
		ValidateRect(m_hwnd, NULL);
		return 0;
	case WM_SIZE:
		OnSize(ll, hl);
		return 0;
	case WM_LBUTTONDOWN:
		OnMouseDown(MouseButton::LBUTTON, ll, hl);
		SetCapture(m_hwnd);
		return 0;
	case WM_MBUTTONDOWN:
		OnMouseDown(MouseButton::MBUTTON, ll, hl);
		SetCapture(m_hwnd);
		return 0;
	case WM_RBUTTONDOWN:
		OnMouseDown(MouseButton::RBUTTON, ll, hl);
		SetCapture(m_hwnd);
		return 0;
	case WM_LBUTTONUP:
		OnMouseUp(MouseButton::LBUTTON, ll, hl);
		ReleaseCapture();
		return 0;
	case WM_MBUTTONUP:
		OnMouseUp(MouseButton::MBUTTON, ll, hl);
		ReleaseCapture();
		return 0;
	case WM_RBUTTONUP:
		OnMouseUp(MouseButton::RBUTTON, ll, hl);
		ReleaseCapture();
		return 0;
	case WM_LBUTTONDBLCLK:
		OnMouseDblClick(MouseButton::LBUTTON, ll, hl);
		return 0;
	case WM_MBUTTONDBLCLK:
		OnMouseDblClick(MouseButton::MBUTTON, ll, hl);
		return 0;
	case WM_RBUTTONDBLCLK:
		OnMouseDblClick(MouseButton::RBUTTON, ll, hl);
		return 0;
	case WM_MOUSEMOVE:
		OnMouseMove(wParam, ll, hl);
		return 0;
	case WM_MOUSEWHEEL:
		OnMouseWheel(HIWORD(wParam), LOWORD(wParam), ll, hl);
		return 0;
	case WM_KEYDOWN:
		OnKeyDown(wParam);
		return 0;
	case WM_KEYUP:
		OnKeyUp(wParam);
		return 0;
	case WM_CHAR:
		OnChar(wParam);
		return 0;
	case WM_TIMER:
		OnTimer();
		return 0;
	case WM_ACTIVATE:
	{
		WORD active = LOWORD(wParam);
		if (active == WA_INACTIVE) {
			if (bFullScreen) {
				ShowWindow(m_hwnd, SW_SHOWMINIMIZED);
				ChangeDisplaySettings(NULL, 0);
			}
		} else {
			SetFocus(m_hwnd);
			if (bFullScreen) changeDisplaySettings();
		}
		return 0;
	}
	case WM_DESTROY:
		OnDestroy();
		delete m_rc;
		ReleaseDC(m_hwnd, m_hdc);
		return 0;
	}

	return DefWindowProc(m_hwnd, uMsg, wParam, lParam);
}
Пример #16
0
LRESULT CALLBACK WindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    switch (message)
    {
    case WM_COMMAND:
        if (OnCommand(hwnd, LOWORD(wParam)))
            break;
        else
            return DefWindowProc(hwnd, message, wParam, lParam);

    case WM_INITMENUPOPUP:
        InitializeMenuItems(reinterpret_cast<HMENU>(wParam));
        break;

    case WM_PAINT:
        OnPaint(hwnd);
        break;

    case WM_ERASEBKGND:
        return true;

    case WM_SIZE:
        OnSize(hwnd);
        break;

    case WM_WINDOWPOSCHANGED:
        {
            HMONITOR monitor = MonitorFromWindow(hwnd, MONITOR_DEFAULTTONULL);
            if (monitor != g_monitor)
            {
                g_monitor = monitor;
                if (g_renderer != NULL)
                    g_renderer->SetMonitor(g_monitor);

                InvalidateRect(hwnd, NULL, TRUE);
            }
        }
        return DefWindowProc(hwnd, message, wParam, lParam);

    case WM_LBUTTONDOWN:
        OnMouseDown(hwnd);
        break;

    case WM_MOUSEMOVE:
        OnMouseMove(hwnd);
        break;

    case WM_LBUTTONUP:
        OnMouseUp(hwnd);
        break;

    case WM_DESTROY:
        PostQuitMessage(0);
        break;

    default:
        return DefWindowProc(hwnd, message, wParam, lParam);
    }

    return 0;
}
Пример #17
0
//==========================================================================
//
// 引擎捕捉鼠标弹起消息后,将调用到本函数
// 参数 iMouseType:鼠标按键值,见 enum MouseTypes 定义
// 参数 fMouseX, fMouseY:为鼠标当前坐标
//
void dOnMouseUp( const int iMouseType, const float fMouseX, const float fMouseY )
{
	// 可以在此添加游戏需要的响应函数
	OnMouseUp(iMouseType, fMouseX, fMouseY);

}
Пример #18
0
INT_PTR GenericWindow::HandleDialogMessage (UINT msg, WPARAM wParam, LPARAM lParam) {
	switch (msg) {	
	case WM_MOUSEMOVE:
		if (!m_flagMouseTracking) {
			// register for mouse out message (TME_LEAVE)
			TRACKMOUSEEVENT trackMouseEvent;
			trackMouseEvent.cbSize = sizeof (trackMouseEvent);
			trackMouseEvent.dwFlags = TME_LEAVE;
			trackMouseEvent.dwHoverTime = 0;
			trackMouseEvent.hwndTrack = GetHandle ();
			m_flagMouseTracking = ::TrackMouseEvent (&trackMouseEvent);
		}
		OnMouseMove (0, 0, LOWORD(lParam), HIWORD(lParam));
		break;

	case WM_MOUSELEAVE:
		OnMouseLeave ();
		m_flagMouseTracking = FALSE;
		break;

	case WM_LBUTTONDOWN:
		OnMouseDown (0, 0, LOWORD(lParam), HIWORD(lParam));
		break;

	case WM_LBUTTONUP:
		OnMouseUp (0, 0, LOWORD(lParam), HIWORD(lParam));
		break;

	case WM_RBUTTONDOWN:
		OnMouseDown (0, 0, LOWORD(lParam), HIWORD(lParam));
		break;

	case WM_RBUTTONUP:
		OnMouseUp (0, 0, LOWORD(lParam), HIWORD(lParam));
		OnContextMenu ( );
		break;

	case WM_CHAR:
		OnKeyPress ( (int)wParam, LOWORD(lParam) );
		break;

	case WM_KEYDOWN:
		OnKeyDown ( (int)wParam );
		break;

	case WM_NCDESTROY:
		OnPreDestroy ();
		m_hWnd = NULL;
		break;

	case WM_DESTROY:
		OnDestroy ();
		break;

	case WM_SIZE:
		{
			int cx, cy;
			cx = LOWORD(lParam);
			cy = HIWORD(lParam);
			OnResize (cx, cy);
		}
		break;

	case WM_SETFOCUS:
		OnGotFocus ();
		break;

	case WM_KILLFOCUS:
		OnLostFocus ();
		break;

	case WM_COMMAND:
		OnCommand ( LOWORD(wParam) );
		break;

	case WM_CONTEXTMENU:
		OnContextMenu ( );
		break;

	default:
		return FALSE;
	}

	return TRUE;
}
Пример #19
0
int XWindow::RunModal()
{
    Prepare();

    // Trap XWindows "WM_DELETE_WINDOW" message
    Atom wmDeleteMessage = XInternAtom(windowDisplay, "WM_DELETE_WINDOW", false);
    XSetWMProtocols(windowDisplay, window, &wmDeleteMessage, 1);

    XkbEvent event;
    do {
        // Gets the new event
        int res = XNextEvent(windowDisplay, &event.core);
        if (window != event.core.xany.window) continue;

        // Processes the events
        if (event.type == ButtonPress) {
            WindowEventMouseButton e(&event.core.xbutton);
            OnMouseDown(&e);
        } else if (event.type == ButtonRelease) {
            WindowEventMouseButton e(&event.core.xbutton);
            OnMouseUp(&e);
        } else if (event.type == MotionNotify) {
            WindowEventMouseMove e(&event.core.xmotion);
            OnMouseMove(&e);
        } else if (event.type == EnterNotify) {
            WindowEventEnterLeave e(&event.core.xcrossing);
            OnMouseEnterLeave(&e);
        } else if (event.type == LeaveNotify) {
            WindowEventEnterLeave e(&event.core.xcrossing);
            OnMouseEnterLeave(&e);
        } else if (event.type == FocusIn) {
            WindowEventFocus e(&event.core.xfocus);
            OnFocus(&e);
        } else if (event.type == FocusOut) {
            WindowEventFocus e(&event.core.xfocus);
            OnFocus(&e);
        } else if (event.type == Expose && event.core.xexpose.count == 0) {
            WindowEventDraw e(gc, &event.core.xexpose);
            OnDraw(&e);
        } else if (event.type == VisibilityNotify) {
            WindowEventVisible e(&event.core.xvisibility);
            OnVisible(&e);
        } else if (event.type == UnmapNotify) {
            WindowEventShow e(false);
            OnShow(&e);
        } else if (event.type == MapNotify) {
            WindowEventShow e(true);
            OnShow(&e);
        } else if (event.type == ConfigureNotify) {
            bool generateWindowMoveEvent =
                area->GetX() != event.core.xconfigure.x ||
                area->GetY() != event.core.xconfigure.y;
            bool generateWindowResizeEvent =
                area->GetWidth() != event.core.xconfigure.width ||
                area->GetHeight() != event.core.xconfigure.height;

            *area = NRectangle(
                        event.core.xconfigure.x, event.core.xconfigure.y,
                        event.core.xconfigure.width, event.core.xconfigure.height);
            borderwidth = event.core.xconfigure.border_width;

            if (generateWindowMoveEvent) {
                WindowEventMove e(&event.core.xconfigure);
                OnMove(&e);
            }
            if (generateWindowResizeEvent) {
                gc->Resize(area->GetWidth(), area->GetHeight());	// Resize XWindowGraphics
                WindowEventResize e(&event.core.xconfigure);
                OnResize(&e);
            }
        } else if (event.type == ColormapNotify) {
            WindowEventColormap e(&event.core.xcolormap);
            OnColormap(&e);
        } else if (event.type == KeyPress) {
            WindowEventKey e(&event.core.xkey);
            OnKeyPress(&e);
        } else if (event.type == KeyRelease) {
            WindowEventKey e(&event.core.xkey);
            OnKeyRelease(&e);
        } else if (event.type == XDisplay::Default().XkbBaseEvent() + XkbEventCode) {
            // XkbEvents
            if (event.any.xkb_type == XkbMapNotify) {
                WindowEventKeymap e(&event.map);
                OnKeymap(&e);
            } else if (event.any.xkb_type == XkbNewKeyboardNotify) {
                WindowEventKeyboardMapping e(&event.new_kbd);
                OnKeyboardMapping(&e);
            } else if (event.any.xkb_type == XkbStateNotifyMask) {
                int kk = 1;
            }
        } else if (event.type == ClientMessage) {
            if (event.core.xclient.data.l[0] == wmDeleteMessage)
                break;
        } else if (event.type != 28 && event.type != 21) {
            int kk = 1;
        }

        // Locks the collection of delegations
        windowMutex->Lock();
        for (int i=0; i<delegationsToExecute->Count(); i++) {
            // Retrieve delegation and parameters
            void **item = (void **)(*delegationsToExecute)[i];
            NDelegation *d = (NDelegation *)item[0];
            void *params = item[1];

            // Execute delegation
            try {
                d->Execute(params);
            } catch (Exception *e) {
                delete e;
            }

            // Deletes delegation and item array
            delete d;
            delete item;
        }

        // Clear delegations collection and unlocks the mutex
        delegationsToExecute->Clear();
        windowMutex->Unlock();
    } while (true);

    Dispose();
}
Пример #20
0
LRESULT D3DApp::MsgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	switch (msg)
	{
	case WM_ACTIVATE:
		if (LOWORD(wParam) == WA_INACTIVE)
		{
			mAppPaused = TRUE;
			mTimer.Stop();
		}
		else {
			mAppPaused = FALSE;
			mTimer.Start();
		}
		return 0;
	case WM_SIZE:
		mClientWidth = LOWORD(lParam);
		mClientHeight = HIWORD(lParam);
		if (md3dDevice)
		{
			if (wParam == SIZE_MINIMIZED)
			{
				mAppPaused = TRUE;
				mMinimized = TRUE;
				mMaximized = FALSE;
			}
			else if (wParam == SIZE_MAXIMIZED)
			{
				mAppPaused = FALSE;
				mMinimized = FALSE;
				mMaximized = TRUE;
				OnResize();
			}
			else if (wParam == SIZE_RESTORED)
			{
				if (mMinimized)
				{
					mAppPaused = FALSE;
					mMinimized = FALSE;
					OnResize();
				}
				else if (mMaximized)
				{
					mAppPaused = FALSE;
					mMaximized = FALSE;
					OnResize();
				}
				else if (mResizing)
				{

				}
				else {
					OnResize();
				}
			}
		}
		return 0;
	case WM_ENTERSIZEMOVE:
		mAppPaused = TRUE;
		mResizing = TRUE;
		mTimer.Stop();
		return 0;
	case WM_EXITSIZEMOVE:
		mAppPaused = FALSE;
		mResizing = FALSE;
		mTimer.Start();
		OnResize();
		return 0;
	case WM_DESTROY:
		PostQuitMessage(0);
		return 0;
	case WM_MENUCHAR:
		return MAKELRESULT(0, MNC_CLOSE);
	case WM_LBUTTONDOWN:
	case WM_MBUTTONDOWN:
	case WM_RBUTTONDOWN:
		OnMouseDown(wParam, GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam));
		return 0;
	case WM_LBUTTONUP:
	case WM_MBUTTONUP:
	case WM_RBUTTONUP:
		OnMouseUp(wParam, GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam));
		return 0;
	case WM_MOUSEMOVE:
		OnMouseMove(wParam, GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam));
		return 0;
	default:
		break;
	}
	return DefWindowProc(hwnd, msg, wParam, lParam);
}
Пример #21
0
// --------------------------------------------------------
// Handles messages that are sent to our window by the
// operating system.  Ignoring these messages would cause
// our program to hang and Windows would think it was
// unresponsive.
// --------------------------------------------------------
LRESULT DirectXGameCore::ProcessMessage(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	switch( msg )
	{
	case WM_ACTIVATEAPP:
		DirectX::Keyboard::ProcessMessage(msg, wParam, lParam);
		DirectX::Mouse::ProcessMessage(msg, wParam, lParam);
		return 0;

	case WM_KEYDOWN:
	case WM_SYSKEYDOWN:
	case WM_KEYUP:
	case WM_SYSKEYUP:
		DirectX::Keyboard::ProcessMessage(msg, wParam, lParam);
		return 0;
	// WM_ACTIVATE is sent when the window is activated or deactivated.
	// We're using this to keep track of focus, if that's useful to you.
	case WM_ACTIVATE:
		if( LOWORD(wParam) == WA_INACTIVE )
		{
			hasFocus = false;
		}
		else
		{
			hasFocus = true;
		}
		return 0;

	// WM_SIZE is sent when the user resizes the window.  
	case WM_SIZE:
		// Save the new client area dimensions.
		windowWidth  = LOWORD(lParam);
		windowHeight = HIWORD(lParam);
		if( device )
		{
			if( wParam == SIZE_MINIMIZED )
			{
				hasFocus = false;
				minimized = true;
				maximized = false;
			}
			else if( wParam == SIZE_MAXIMIZED )
			{
				hasFocus = true;
				minimized = false;
				maximized = true;
				OnResize();
			}
			else if( wParam == SIZE_RESTORED )
			{
				// Restoring from minimized state?
				if( minimized )
				{
					hasFocus = true;
					minimized = false;
					OnResize();
				}

				// Restoring from maximized state?
				else if( maximized )
				{
					hasFocus = true;
					maximized = false;
					OnResize();
				}
				else if( resizing )
				{
					// If user is dragging the resize bars, we do not resize 
					// the buffers here because as the user continuously 
					// drags the resize bars, a stream of WM_SIZE messages are
					// sent to the window, and it would be pointless (and slow)
					// to resize for each WM_SIZE message received from dragging
					// the resize bars.  So instead, we reset after the user is 
					// done resizing the window and releases the resize bars, which 
					// sends a WM_EXITSIZEMOVE message.
				}
				else // API call such as SetWindowPos or mSwapChain->SetFullscreenState.
				{
					OnResize();
				}
			}
		}
		return 0;

	// WM_EXITSIZEMOVE is sent when the user grabs the resize bars.
	case WM_ENTERSIZEMOVE:
		resizing = true;
		return 0;

	// WM_EXITSIZEMOVE is sent when the user releases the resize bars.
	// Here we reset everything based on the new window dimensions.
	case WM_EXITSIZEMOVE:
		resizing = false;
		OnResize();
		return 0;

	// WM_DESTROY is sent when the window is being destroyed.
	case WM_DESTROY:
		PostQuitMessage(0);
		return 0;

	// The WM_MENUCHAR message is sent when a menu is active and the user presses 
	// a key that does not correspond to any mnemonic or accelerator key. 
	case WM_MENUCHAR:
		// Don't beep when we alt-enter.
		return MAKELRESULT(0, MNC_CLOSE);

	// Catch this message so to prevent the window from becoming too small.
	case WM_GETMINMAXINFO:
		((MINMAXINFO*)lParam)->ptMinTrackSize.x = 200;
		((MINMAXINFO*)lParam)->ptMinTrackSize.y = 200; 
		return 0;

	// Messages that correspond to mouse button being pressed while the cursor
	// is currently over our window
	case WM_LBUTTONDOWN:
	case WM_MBUTTONDOWN:
	case WM_RBUTTONDOWN:
		OnMouseDown(wParam, GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam));
		DirectX::Mouse::ProcessMessage(msg, wParam, lParam);
		return 0;

	// Messages that correspond to mouse button being released while the cursor
	// is currently over our window
	case WM_LBUTTONUP:
	case WM_MBUTTONUP:
	case WM_RBUTTONUP:
		OnMouseUp(wParam, GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam));
		DirectX::Mouse::ProcessMessage(msg, wParam, lParam);
		return 0;

	// Message that occurs while the mouse moves over the window or while
	// we're currently capturing it
	case WM_MOUSEMOVE:
		OnMouseMove(wParam, GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam));
		// fall through
	case WM_MOUSEWHEEL:
	case WM_INPUT:
	case WM_MOUSEHOVER:
	case WM_XBUTTONDOWN:
	case WM_XBUTTONUP:
		DirectX::Mouse::ProcessMessage(msg, wParam, lParam);
		return 0;
	}

	// Some other message was sent, so call the default window procedure for it
	return DefWindowProc(hwnd, msg, wParam, lParam);
}
Пример #22
0
void CGetBlackOutDlg::OnMouseDown( UINT nflags, CPoint point)
{
	if (mWon) return;
	int x,y,cx,cy,i,piece;
	x=y=cx=cy=piece=0;
	for(i = 0 ; i < mBoard.numpieces(); i++) {
		x = mBoard.pborder() + 
			(mBoard.piece(i)->xpos() * (mBoard.pper() + mBoard.pborder()));
		y = mBoard.pborder() + 
			(mBoard.piece(i)->ypos() * (mBoard.pper() + mBoard.pborder()));
		cx = (mBoard.piece(i)->width() * mBoard.pper());
		if (mBoard.piece(i)->width() == 2)
			cx += mBoard.pborder();

		cy = (mBoard.piece(i)->height() * mBoard.pper());
		if (mBoard.piece(i)->height() == 2)
			cy += mBoard.pborder();
		CRect piecerect(x,y,x+cx,y+cy);
		if (piecerect.PtInRect(point)) {
			piece=i;
			i=mBoard.numpieces();
			mMoving = TRUE;
			mMouseStartPoint = point;
			mPieceMoving = piece;
			break;
		}
	}
	int moves = 0;
	if (mMoving) {
		int x,y,sx,sy,sx2,sy2;
		x=y=sx=sy=sx2=sy2=0;
		x = -mBoard.pper(); y = 0;
		if (mBoard.canmove(mPieceMoving,x,y)) {
			moves++;
			sx=x;sy=y;
		}
		x = mBoard.pper(); y = 0;
		if (mBoard.canmove(mPieceMoving,x,y)) {
			moves++;
			if (moves < 2) {
				sx=x;sy=y;
			} else {
				sx2=x;sy2=y;
			}
		}
		x = 0; y = mBoard.pper();
		if (mBoard.canmove(mPieceMoving,x,y)) {
			moves++;
			if (moves < 2) {
				sx=x;sy=y;
			} else {
				sx2=x;sy2=y;
			}
		}
		x = 0; y = -mBoard.pper();
		if (mBoard.canmove(mPieceMoving,x,y)) {
			moves++;
			if (moves < 2) {
				sx=x;sy=y;
			} else {
				sx2=x;sy2=y;
			}
		}

		if (moves == 1) {
			CPoint delta(point);
			delta += CPoint(sx,sy);
			OnMouseMove(0, delta);
			OnMouseUp(0,CPoint());
		} else if (moves == 2) {
			CRect piecerect(mBoard.piece(mPieceMoving)->mPieceRect);
			int deltax, deltay;deltax=deltay=0;
			if (abs(sx) == mBoard.pper() 
					&& abs(sx2) == mBoard.pper()) {
				CRect lhalf(piecerect);
				CRect rhalf(piecerect);
				lhalf.BottomRight().x -= lhalf.Width() / 2;
				rhalf.TopLeft().x = lhalf.BottomRight().x;
				if (lhalf.PtInRect(point)) {
					deltax = sx2;
				} else {
					deltax = sx;
				}
				CPoint delta(point);
				delta += CPoint(deltax,deltay);
				OnMouseMove(0, delta);
				OnMouseUp(0,CPoint());
			} else if (abs(sy) == mBoard.pper() 
					&& abs(sy2) == mBoard.pper()) {
				CRect thalf(piecerect);
				CRect bhalf(piecerect);
				thalf.BottomRight().y -= thalf.Height() / 2;
				bhalf.TopLeft().y = thalf.BottomRight().y;
				if (thalf.PtInRect(point)) {
					deltay = sy;
				} else {
					deltay = sy2;
				}
				CPoint delta(point);
				delta += CPoint(deltax,deltay);
				OnMouseMove(0, delta);
				OnMouseUp(0,CPoint());
			} else if (
					sx == mBoard.pper()
					&& sy2 == mBoard.pper()
					||
					sx2 == mBoard.pper()
					&& sy == mBoard.pper()
					) {
				if (distance(topright(piecerect),point)
					< distance(point, bottomleft(piecerect))) {
					deltay = sy2;
				} else {
					deltax = sx;
				}
				CPoint delta(point);
				delta += CPoint(deltax,deltay);
				OnMouseMove(0, delta);
				OnMouseUp(0,CPoint());		
			} else if (
				sx == -mBoard.pper()
				&& sy2 == mBoard.pper()
				||
				sx2 == -mBoard.pper()
				&& sy == mBoard.pper()
				) {
				if (distance(topleft(piecerect),point)
					< distance(point, bottomright(piecerect))) {
					deltay = sy2;
				} else {
					deltax = sx;
				}
				CPoint delta(point);
				delta += CPoint(deltax,deltay);
				OnMouseMove(0, delta);
				OnMouseUp(0,CPoint());		
			} else if (
				sx == mBoard.pper()
				&& sy2 == -mBoard.pper()
				||
				sx2 == mBoard.pper()
				&& sy == -mBoard.pper()
				) {
				if (distance(topleft(piecerect),point)
					< distance(point, bottomright(piecerect))) {
					deltax = sx;
				} else {
					deltay = sy2;
				}
				CPoint delta(point);
				delta += CPoint(deltax,deltay);
				OnMouseMove(0, delta);
				OnMouseUp(0,CPoint());	
			} else if (
				sx == -mBoard.pper()
				&& sy2 == -mBoard.pper()
				||
				sx2 == -mBoard.pper()
				&& sy == -mBoard.pper()
				) {
				if (distance(topright(piecerect),point)
					< distance(point, bottomleft(piecerect))) {
					deltax = sx;
				} else {
					deltay = sy2;
				}
				CPoint delta(point);
				delta += CPoint(deltax,deltay);
				OnMouseMove(0, delta);
				OnMouseUp(0,CPoint());	
			}			
		}
	}


}
Пример #23
0
bool
TopWindow::OnEvent(const Event &event)
{
  switch (event.type) {
    Window *w;

  case Event::NOP:
  case Event::TIMER:
  case Event::USER:
  case Event::CALLBACK:
    break;

  case Event::CLOSE:
    OnClose();
    break;

  case Event::KEY_DOWN:
    w = GetFocusedWindow();
    if (w == nullptr)
      w = this;

    return w->OnKeyDown(event.param);

  case Event::KEY_UP:
    w = GetFocusedWindow();
    if (w == nullptr)
      w = this;

    return w->OnKeyUp(event.param);

  case Event::MOUSE_MOTION:
#ifdef DRAW_MOUSE_CURSOR
    /* redraw to update the mouse cursor position */
    Invalidate();
#endif

    // XXX keys
    return OnMouseMove(event.point.x, event.point.y, 0);

  case Event::MOUSE_DOWN:
    return double_click.Check(event.point)
      ? OnMouseDouble(event.point.x, event.point.y)
      : OnMouseDown(event.point.x, event.point.y);

  case Event::MOUSE_UP:
    double_click.Moved(event.point);

    return OnMouseUp(event.point.x, event.point.y);

  case Event::MOUSE_WHEEL:
    return OnMouseWheel(event.point.x, event.point.y, (int)event.param);

#ifdef USE_X11
  case Event::RESIZE:
    if (unsigned(event.point.x) == GetWidth() &&
        unsigned(event.point.y) == GetHeight())
      /* no-op */
      return true;

    Resize(event.point.x, event.point.y);
    return true;

  case Event::EXPOSE:
    Invalidate();
    return true;
#endif
  }

  return false;
}
Пример #24
0
LRESULT
Window::OnMessage(HWND _hWnd, UINT message,
                       WPARAM wParam, LPARAM lParam)
{
  switch (message) {
  case WM_CREATE:
    OnCreate();
    return 0;

  case WM_DESTROY:
    OnDestroy();
    return 0;

  case WM_SIZE:
    OnResize({LOWORD(lParam), HIWORD(lParam)});
    return 0;

  case WM_MOUSEMOVE:
    if (OnMouseMove(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam), wParam))
      return 0;
    break;

  case WM_LBUTTONDOWN:
    if (OnMouseDown(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam))) {
      /* true returned: message was handled */
      ResetUserIdle();
      return 0;
    }
    break;

  case WM_LBUTTONUP:
    if (OnMouseUp(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam))) {
      /* true returned: message was handled */
      ResetUserIdle();
      return 0;
    }
    break;

  case WM_LBUTTONDBLCLK:
    if (!double_clicks)
      /* instead of disabling CS_DBLCLKS (which would affect all
         instances of a window class), we just translate
         WM_LBUTTONDBLCLK to WM_LBUTTONDOWN here; this even works for
         built-in window class such as BUTTON */
      return OnMessage(_hWnd, WM_LBUTTONDOWN, wParam, lParam);

    if (OnMouseDouble(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam))) {
      /* true returned: message was handled */
      ResetUserIdle();
      return 0;
    }

    break;

#ifdef WM_MOUSEWHEEL
  case WM_MOUSEWHEEL:
    if (OnMouseWheel(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam),
                       GET_WHEEL_DELTA_WPARAM(wParam))) {
      /* true returned: message was handled */
      ResetUserIdle();
      return 0;
    }
    break;
#endif

  case WM_KEYDOWN:
    if (OnKeyDown(wParam)) {
      /* true returned: message was handled */
      ResetUserIdle();
      return 0;
    }
    break;

  case WM_KEYUP:
    if (OnKeyUp(wParam)) {
      /* true returned: message was handled */
      ResetUserIdle();
      return 0;
    }
    break;

  case WM_CHAR:
    if (OnCharacter((TCHAR)wParam))
      /* true returned: message was handled */
      return 0;

    break;

  case WM_COMMAND:
    if (OnCommand(LOWORD(wParam), HIWORD(wParam))) {
      /* true returned: message was handled */
      ResetUserIdle();
      return 0;
    }
    break;

  case WM_CANCELMODE:
    OnCancelMode();
    /* pass on to DefWindowProc(), there may be more to do */
    break;

  case WM_SETFOCUS:
    OnSetFocus();
    /* pass on to DefWindowProc() so the underlying window class knows
       it's focused */
    break;

  case WM_KILLFOCUS:
    OnKillFocus();
    /* pass on to DefWindowProc() so the underlying window class knows
       it's not focused anymore */
    break;

  case WM_TIMER:
    if (OnTimer(*(WindowTimer *)wParam))
      return 0;
    break;

  case WM_PAINT:
    if (custom_painting) {
      PaintCanvas canvas(*this);
      OnPaint(canvas, canvas.get_dirty());
      return 0;
    }
    break;

  case WM_GETDLGCODE:
    if (OnKeyCheck(wParam))
      return DLGC_WANTMESSAGE;
    break;
  }

  if (message >= WM_USER && message <= 0x7FFF && OnUser(message - WM_USER))
    return 0;

  return OnUnhandledMessage(_hWnd, message, wParam, lParam);
}
Пример #25
0
void UIElement::CheckInput()
{
	if (interactive)
	{
		int mouseX, mouseY;
		App->input->GetMousePosition(mouseX, mouseY);
		int elementX = GetWorldRect().x;
		int elementY = GetWorldRect().y;

		if (App->gui->debugMode)
		{
			int colX = GetWorldRect().x;
			int colY = GetWorldRect().y;
			App->render->DrawQuad(SDL_Rect{ colX - App->render->camera.x, colY - App->render->camera.y, collider.w, collider.h }, 255, 0, 0, 50, false);
		}
		if (mouseX > elementX && mouseX < elementX + collider.w && mouseY >elementY && mouseY < elementY + collider.h)
		{
			if (!mouseWasIn)
			{
				//LOG("%s - Mouse Enter", name.GetString());
				mouseWasIn = true;
				App->gui->SetHovering(this);
				OnMouseEnter();
				if (listener)
				{
					listener->OnGUI(MOUSE_ENTER, this);
				}

				App->gui->inputRecieved = true;
			}

			if (App->input->GetMouseButtonDown(SDL_BUTTON_LEFT) == KEY_DOWN)
			{
				//LOG("%s - Mouse Down", name.GetString());
				mouseWasClicked = true;
				OnMouseDown();
				if (listener)
				{
					listener->OnGUI(MOUSE_DOWN, this);
				}

				App->gui->inputRecieved = true;
				App->gui->SetFocus(this);
			}
			else if (App->input->GetMouseButtonDown(SDL_BUTTON_LEFT) == KEY_UP)
			{
				if (mouseWasClicked)
				{
					//LOG("%s - Mouse Up", name.GetString());
					mouseWasClicked = false;
					OnMouseUp();
					if (listener)
					{
						listener->OnGUI(MOUSE_UP, this);
					}
					App->gui->inputRecieved = true;
				}
				else if (App->gui->GetFocus())
				{
					if(App->gui->GetFocus()->mouseWasClicked)
					{
						App->gui->GetFocus()->OnMouseUp();
					}
				}


			}
		}
		else
		{
		//	if (mouseWasClicked)
		//		mouseWasClicked = false;
			if (mouseWasIn)
			{
				//LOG("%s - Mouse Exit", name.GetString());
				mouseWasIn = false;
				OnMouseExit();
				App->gui->SetHovering(NULL);
				if (listener)
				{
					listener->OnGUI(MOUSE_EXIT, this);
				}

				App->gui->inputRecieved = true;
			}
		}
		if (App->gui->GetFocus() == this)
		{
			if (App->input->GetKey(SDL_SCANCODE_RETURN) == KEY_DOWN)
			{
				//LOG("%s - Return down", name.GetString());
				if (listener)
				{
					listener->OnGUI(RETURN_DOWN, this);
				}
			}
		}
	}
}
Пример #26
0
bool
TopWindow::OnEvent(const SDL_Event &event)
{
  switch (event.type) {
    Window *w;

  case SDL_VIDEOEXPOSE:
    Invalidated_lock.Lock();
    Invalidated = false;
    Invalidated_lock.Unlock();

    Expose();
    return true;

  case SDL_KEYDOWN:
    w = GetFocusedWindow();
    if (w == NULL)
      w = this;

    if (!w->IsEnabled())
      return false;

    return w->OnKeyDown(event.key.keysym.sym);

  case SDL_KEYUP:
    w = GetFocusedWindow();
    if (w == NULL)
      w = this;

    if (!w->IsEnabled())
      return false;

    return w->OnKeyUp(event.key.keysym.sym);

  case SDL_MOUSEMOTION:
    // XXX keys
    return OnMouseMove(event.motion.x, event.motion.y, 0);

  case SDL_MOUSEBUTTONDOWN:
    if (event.button.button == SDL_BUTTON_WHEELUP)
      return OnMouseWheel(event.button.x, event.button.y, 1);
    else if (event.button.button == SDL_BUTTON_WHEELDOWN)
      return OnMouseWheel(event.button.x, event.button.y, -1);

    return double_click.Check(RasterPoint{PixelScalar(event.button.x),
                                          PixelScalar(event.button.y)})
      ? OnMouseDouble(event.button.x, event.button.y)
      : OnMouseDown(event.button.x, event.button.y);

  case SDL_MOUSEBUTTONUP:
    if (event.button.button == SDL_BUTTON_WHEELUP ||
        event.button.button == SDL_BUTTON_WHEELDOWN)
      /* the wheel has already been handled in SDL_MOUSEBUTTONDOWN */
      return false;

    double_click.Moved(RasterPoint{PixelScalar(event.button.x),
                                   PixelScalar(event.button.y)});

    return OnMouseUp(event.button.x, event.button.y);

  case SDL_QUIT:
    return OnClose();

  case SDL_VIDEORESIZE:
    Resize(event.resize.w, event.resize.h);
    return true;
  }

  return false;
}
Пример #27
0
void CModifiedButtonWidget::OnMouseEvent( CMouseEvent* event )
{
	// logger << event->GetButtons() << std::endl;
	switch( event->GetType() )
	{
	case types::mouse_button_down:
		
		if( event->GetButtons() & myClickableButtons ) 
		{
			mySpriteHandler->PlayAnimation( GetSprite(), "mouse_button_down" );
			myClicked = true;
			OnMouseDown( myParam );
		}

		if( myDragable && event->GetButtons() & myDragableButtons )
		{
			// mySpriteHandler->PlayAnimation( GetSprite(), "mouse_on_drag" );
			myDragging = true;
			myDragOffset = types::point( this->GetRect().x, this->GetRect().y ) - event->GetPosition();
			IMouse::AddConstantEventListeners( this );
		}

		if( myDoubleClickable && event->GetButtons() & myDoubleClickableButtons && myDoubleClicking == true )
		{
			if( myDoubleClickTimer.GetTime() < double_click_time )
				OnDoubleClick( myParam );
			myDoubleClicking = false;
		}
		else if( myDoubleClickable && event->GetButtons() & myDoubleClickableButtons && myDoubleClicking == false )
		{
			myDoubleClickTimer.Reset();
			myDoubleClickTimer.Resume();
			myDoubleClicking = true;
		}
		else if ( myDoubleClickable && event->GetButtons() & !myDoubleClickableButtons )
		{
			myDoubleClicking = false;
		}



		break;

	case types::mouse_button_up:
		if( myClicked && event->GetButtons() & myClickableButtons ) 
		{
			mySpriteHandler->PlayAnimation( GetSprite(), "mouse_button_up" );
			OnClick( myParam );

			myClicked = false;
			OnMouseUp( myParam );
		}

		if( myDragable && event->GetButtons() & myDragableButtons )
		{
			// mySpriteHandler->PlayAnimation( GetSprite(), "mouse_on_drag" );
			myDragging = false;
			IMouse::RemoveConstantEventListeners( this );
			OnDragEnd();
		}

		myClicked = false;
		break;

	case types::mouse_move:

		if( myDragging )
		{
			types::point where_to = event->GetPosition() + myDragOffset;

			// Fixed 12-09-2007 by Pete
			//--------------------------------------------------------------------------
			// BUGBUG: This should be the commented line, but the signal-slot 
			// doesn't support three parameters at the current time
			// OnDrag( where_to.x - GetRect().x, where_to.y - GetRect().y, myParam );

			if( config::automatic_dragging )
				MoveBy( types::point( where_to.x - GetRect().x, where_to.y - GetRect().y ) );	

			OnDrag( where_to.x - GetRect().x, where_to.y - GetRect().y, myParam );
		}

		// myDoubleClicking = false;
		break;

	case types::mouse_over:
		{
			const std::string animation = mySelectionOn?"select_mouse_over":"mouse_over";
			mySpriteHandler->PlayAnimation( GetSprite(), animation );
			OnMouseOver( myParam );
		}
		break;

	case types::mouse_out:
		{
			const std::string animation = mySelectionOn?"select_mouse_out":"mouse_out";
			mySpriteHandler->PlayAnimation( GetSprite(), animation );
			myClicked = false;
			myDoubleClicking = false;
			OnMouseOut( myParam );
		}
		break;

	default:
		break;
	}

}
Пример #28
0
LRESULT D3D11App::MsgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	switch (msg)
	{
	// Window being destroyed
	case WM_DESTROY:
		::PostQuitMessage(0);
		return 0;

	// Window activated or deactivated (in focus or not)
	case WM_ACTIVATE:
		if(LOWORD(wParam) == WA_INACTIVE)
		{
			mAppPaused = true;
			mTimer.stop();
		}
		else
		{
			mAppPaused = false;
			mTimer.start();
		}
		return 0;

	// Window is resized
	case WM_SIZE:
		// Get the new client area dimensions
		mcWidth = LOWORD(lParam);
		mcHeight = HIWORD(lParam);

		if (mDirect3D->GetDevice())
		{
			if (wParam == SIZE_MINIMIZED)
			{
				mAppPaused = true;
				mMinimized = true;
				mMaximized = false;
			}

			else if(wParam == SIZE_MAXIMIZED)
			{
				mAppPaused = false;
				mMinimized = false;
				mMaximized = true;
				OnResize();
			}

			else if(wParam == SIZE_RESTORED)
			{

				// If we are restoring from minimized state
				if (mMinimized)
				{
					mAppPaused = false;
					mMinimized = false;
					OnResize();
				}

				// If we are restoring from maximized state
				else if (mMaximized)
				{
					mAppPaused = false;
					mMaximized = false;
					OnResize();
				}
				else if(mResizing)
				{
					// If user is dragging the resize bars, we do not resize 
					// the buffers here because as the user continuously 
					// drags the resize bars, a stream of WM_SIZE messages are
					// sent to the window, and it would be pointless (and slow)
					// to resize for each WM_SIZE message received from dragging
					// the resize bars.  So instead, we reset after the user is 
					// done resizing the window and releases the resize bars, which 
					// sends a WM_EXITSIZEMOVE message.
				}
				else // API call such as SetWindowPos or mSwapChain->SetFullscreenState.
				{
					OnResize();
				}
			}
		}
		return 0;

	// If the user grabs the resize bars
	case WM_ENTERSIZEMOVE:
		mAppPaused = true;
		mResizing  = true;
		mTimer.stop();
		return 0;

	// If the user releases the resize bars
	// Here we reset everything based on the new window dimensions.
	case WM_EXITSIZEMOVE:
		mAppPaused = false;
		mResizing  = false;
		mTimer.start();
		OnResize();
		return 0;

	// The WM_MENUCHAR message is sent when a menu is active and the user presses 
	// a key that does not correspond to any mnemonic or accelerator key. 
	case WM_MENUCHAR:
		// Don't beep when we alt-enter.
		return MAKELRESULT(0, MNC_CLOSE);

	// Catch this message so to prevent the window from becoming too small.
	case WM_GETMINMAXINFO:
		((MINMAXINFO*)lParam)->ptMinTrackSize.x = 200;
		((MINMAXINFO*)lParam)->ptMinTrackSize.y = 200; 
		return 0;

	case WM_LBUTTONDOWN:
	case WM_MBUTTONDOWN:
	case WM_RBUTTONDOWN:
		OnMouseDown(wParam, GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam));
		return 0;
	case WM_LBUTTONUP:
	case WM_MBUTTONUP:
	case WM_RBUTTONUP:
		OnMouseUp(wParam, GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam));
		return 0;
	case WM_MOUSEMOVE:
		OnMouseMove(wParam, GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam));
		return 0;

	case WM_SYSCOMMAND:
		// ALT + ENTER
		if (SC_KEYMENU == (wParam & 0xFFF0))
		{
		}
		return 0;
	}

	return ::DefWindowProc(hWnd, msg, wParam, lParam);
}
Пример #29
0
LRESULT D3DApp::MsgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	if (msg == WM_SETCURSOR && LOWORD(lParam) == HTCLIENT && !mCursorOn)
	{
		SetCursor(NULL);

		return TRUE;
	}
	switch( msg )
	{
	// WM_ACTIVATE is sent when the window is activated or deactivated.  
	// We pause the game when the window is deactivated and unpause it 
	// when it becomes active.  

	case WM_ACTIVATE:
		if( LOWORD(wParam) == WA_INACTIVE )
		{
			mAppPaused = true;
			mTimer.Stop();
		}
		else
		{
			mAppPaused = false;
			mTimer.Start();
		}
		return 0;

	// WM_SIZE is sent when the user resizes the window.  
	case WM_SIZE:
		// Save the new client area dimensions.
		mClientWidth  = LOWORD(lParam);
		mClientHeight = HIWORD(lParam);
		if( md3dDevice )
		{
			if( wParam == SIZE_MINIMIZED )
			{
				if (mFullScreen)mSwapChain->SetFullscreenState(false, NULL);
				mAppPaused = true;
				mMinimized = true;
				mMaximized = false;
			}
			else if( wParam == SIZE_MAXIMIZED )
			{
				if (mFullScreen)mSwapChain->SetFullscreenState(true, NULL);
				mAppPaused = false;
				mMinimized = false;
				mMaximized = true;
				OnResize();
			}
			else if( wParam == SIZE_RESTORED )
			{
				
				// Restoring from minimized state?
				if( mMinimized )
				{
					if(mFullScreen)mSwapChain->SetFullscreenState(true, NULL);
					mAppPaused = false;
					mMinimized = false;
					OnResize();
				}

				// Restoring from maximized state?
				else if( mMaximized )
				{
					mAppPaused = false;
					mMaximized = false;
					OnResize();
				}
				else if( mResizing )
				{
					// If user is dragging the resize bars, we do not resize 
					// the buffers here because as the user continuously 
					// drags the resize bars, a stream of WM_SIZE messages are
					// sent to the window, and it would be pointless (and slow)
					// to resize for each WM_SIZE message received from dragging
					// the resize bars.  So instead, we reset after the user is 
					// done resizing the window and releases the resize bars, which 
					// sends a WM_EXITSIZEMOVE message.
				}
				else // API call such as SetWindowPos or mSwapChain->SetFullscreenState.
				{
					OnResize();
				}
			}
		}
		return 0;

	// WM_EXITSIZEMOVE is sent when the user grabs the resize bars.
	case WM_ENTERSIZEMOVE:
		mAppPaused = true;
		mResizing  = true;
		mTimer.Stop();
		return 0;

	// WM_EXITSIZEMOVE is sent when the user releases the resize bars.
	// Here we reset everything based on the new window dimensions.
	case WM_EXITSIZEMOVE:
		mAppPaused = false;
		mResizing  = false;
		mTimer.Start();
		OnResize();
		return 0;
 
	// WM_DESTROY is sent when the window is being destroyed.
	case WM_DESTROY:
		PostQuitMessage(0);
		return 0;

	// The WM_MENUCHAR message is sent when a menu is active and the user presses 
	// a key that does not correspond to any mnemonic or accelerator key. 
	case WM_MENUCHAR:
        // Don't beep when we alt-enter.
        return MAKELRESULT(0, MNC_CLOSE);

	// Catch this message so to prevent the window from becoming too small.
	case WM_GETMINMAXINFO:
		((MINMAXINFO*)lParam)->ptMinTrackSize.x = 200;
		((MINMAXINFO*)lParam)->ptMinTrackSize.y = 200; 
		return 0;

	case WM_LBUTTONDOWN:
	case WM_MBUTTONDOWN:
	case WM_RBUTTONDOWN:
		OnMouseDown(wParam, GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam));
		return 0;
	case WM_LBUTTONUP:
	case WM_MBUTTONUP:
	case WM_RBUTTONUP:
		OnMouseUp(wParam, GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam));
		return 0;
	case WM_MOUSEMOVE:
		OnMouseMove(wParam, GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam));
		return 0;
	case WM_KEYUP:
		OnKeyUP(wParam);
		if (wParam == VK_ESCAPE)
		{
			PostQuitMessage(0);
			return 0;
		}
		break;
	}

	return DefWindowProc(hwnd, msg, wParam, lParam);
}
Пример #30
0
LRESULT CALLBACK Widget::WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	MsgProcResult result;
	switch(msg)
	{
	case WM_PAINT:
		{
			PAINTSTRUCT ps;
			HDC hDC;
			if(wParam == 0) hDC = BeginPaint(hWnd, &ps);
			else hDC = (HDC)wParam;
			Gdiplus::Graphics g(hDC);
			OnPaint(&g, ps.rcPaint);
			if(wParam == 0) EndPaint(hWnd, &ps);
		} break;


	case WM_LBUTTONDOWN:
	case WM_RBUTTONDOWN:
	case WM_MBUTTONDOWN:
	{
		mIsMouseDown = true;
		SetCapture(hWnd);
		mMouseLastPos = POINT{GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)};
		MouseEvent ev(this, mMouseLastPos, 1, wParam,
					  msg == WM_LBUTTONDOWN ? MouseButton::Left :
					  msg == WM_RBUTTONDOWN ? MouseButton::Right :
					  msg == WM_MBUTTONDOWN ? MouseButton::Middle :
					  MouseButton::None);
		SignalMouseDown.emit(ev);
		OnMouseDown(ev);
	} break;

	case WM_LBUTTONUP:
	case WM_RBUTTONUP:
	case WM_MBUTTONUP:
	{
		mIsMouseDown = false;
		ReleaseCapture();
		mMouseLastPos = POINT{GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)};
		MouseEvent ev(this, mMouseLastPos, 1, wParam,
					  msg == WM_LBUTTONUP ? MouseButton::Left :
					  msg == WM_RBUTTONUP ? MouseButton::Right :
					  msg == WM_MBUTTONUP ? MouseButton::Middle :
					  MouseButton::None);
		SignalMouseUp.emit(ev);
		OnMouseUp(ev);

		if(!mHasDragged)
		{
			SignalMouseClick.emit(ev);
			OnMouseClick(ev);
		}
		else
			mHasDragged = false;
	} break;

	case WM_LBUTTONDBLCLK:
	case WM_MBUTTONDBLCLK:
	case WM_RBUTTONDBLCLK:
	{
		MouseEvent ev(this, POINT{GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)}, 2, wParam,
					  msg == WM_LBUTTONDBLCLK ? MouseButton::Left :
					  msg == WM_MBUTTONDBLCLK ? MouseButton::Right :
					  msg == WM_RBUTTONDBLCLK ? MouseButton::Middle :
					  MouseButton::None);
		SignalMouseDoubleClick.emit(ev);
		OnMouseDoubleClick(ev);
	} break;

	case WM_MOUSEMOVE:
	{
		POINT mouseNewPos = POINT{GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)};
		MouseEvent ev(this, mouseNewPos, 0, wParam, MouseButton::None, mMouseLastPos);
		mMouseLastPos = mouseNewPos;
		if(mIsMouseDown)
		{
			mHasDragged = true;
			SignalMouseDrag.emit(ev);
			OnMouseDrag(ev);
		}
		else
		{
			SignalMouseMove.emit(ev);
			OnMouseMove(ev);
		}
	} break;

	case WM_MOUSEWHEEL:
	{
		POINT pt = POINT{GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)};
		ScreenToClient(mhWnd, &pt);
		MouseEvent ev(this, pt, 0, GET_KEYSTATE_WPARAM(wParam), MouseButton::None, mMouseLastPos, GET_WHEEL_DELTA_WPARAM(wParam)/WHEEL_DELTA);
		SignalMouseWheel.emit(ev);
		OnMouseWheel(ev);
	} break;

	case WM_SIZE:
	{
		int width = LOWORD(lParam);
		int height = HIWORD(lParam);
		SignalResize.emit(width, height);
		if(mLayout)
			mLayout->Apply(this);
		OnResize(width, height);
	} break;

	case WM_COMMAND:
	{
		HWND hCtrl = reinterpret_cast<HWND>(lParam);
		if(hCtrl != nullptr)
		{
			Widget* child = Widget::FromHandle(hCtrl);
			if(child != nullptr)				
				child->OnCommand(HIWORD(wParam));
		}
	} break;

	case WM_NOTIFY:
	{
		LPNMHDR lpnmhdr = reinterpret_cast<LPNMHDR>(lParam);
		Widget* child = Widget::FromHandle(lpnmhdr->hwndFrom);
		if(child != nullptr)
			result = child->OnNotify(lpnmhdr);
	} break;

	}

	if(result.ReturnDefault())
		return CallDefaultProc(hWnd, msg, wParam, lParam);
	else
		return result.Value();
}