Exemplo n.º 1
0
static void OnMouseMessage( LCUI_Event ev, void *arg )
{
	MSG *msg = arg;
	LCUI_SysEventRec sys_ev;
	static POINT mouse_pos = {0, 0};
	sys_ev.type = LCUI_NONE;
	switch( msg->message ) {
	case WM_MOUSEMOVE: {
		POINT new_pos;
		GetCursorPos( &new_pos );
		ScreenToClient( msg->hwnd, &new_pos );
		sys_ev.motion.x = new_pos.x;
		sys_ev.motion.y = new_pos.y;
		sys_ev.motion.xrel = new_pos.x - mouse_pos.x;
		sys_ev.motion.yrel = new_pos.y - mouse_pos.y;
		mouse_pos.x = new_pos.x;
		mouse_pos.y = new_pos.y;
		sys_ev.type = LCUI_MOUSEMOVE;
		break;
	}
	case WM_LBUTTONDOWN:
		sys_ev.type = LCUI_MOUSEDOWN;
		sys_ev.button.button = 1;
		sys_ev.button.x = mouse_pos.x;
		sys_ev.button.y = mouse_pos.y;
		SetCapture( msg->hwnd );
		break;
	case WM_LBUTTONUP:
		sys_ev.type = LCUI_MOUSEUP;
		sys_ev.button.button = 1;
		sys_ev.button.x = mouse_pos.x;
		sys_ev.button.y = mouse_pos.y;
		ReleaseCapture();
		break;
	case WM_RBUTTONDOWN:
		sys_ev.type = LCUI_MOUSEDOWN;
		sys_ev.button.button = 2;
		sys_ev.button.x = mouse_pos.x;
		sys_ev.button.y = mouse_pos.y;
		SetCapture( msg->hwnd );
		break;
	case WM_RBUTTONUP:
		sys_ev.type = LCUI_MOUSEUP;
		sys_ev.button.button = 2;
		sys_ev.button.x = mouse_pos.x;
		sys_ev.button.y = mouse_pos.y;
		ReleaseCapture();
		break;
	case WM_MOUSEWHEEL:
		sys_ev.type = LCUI_MOUSEWHEEL;
		sys_ev.wheel.x = mouse_pos.x;
		sys_ev.wheel.y = mouse_pos.y;
		sys_ev.wheel.delta = GET_WHEEL_DELTA_WPARAM( msg->wParam );
		break;
	case WM_TOUCH: {
		UINT i, n = LOWORD( msg->wParam );
		PTOUCHINPUT inputs = NEW( TOUCHINPUT, n );
		HTOUCHINPUT handle = (HTOUCHINPUT)msg->lParam;
		if( inputs == NULL ) {
			break;
		}
		sys_ev.type = LCUI_TOUCH;
		sys_ev.touch.n_points = n;
		sys_ev.touch.points = NEW( LCUI_TouchPointRec, n );
		if( sys_ev.touch.points == NULL ) {
			free( inputs );
			break;
		}
		if( !GetTouchInputInfo( handle, n, inputs,
					sizeof( TOUCHINPUT ) ) ) {
			free( inputs );
			break;
		}
		for( i = 0; i < n; ++i ) {
			POINT pos;
			pos.x = inputs[i].x / 100;
			pos.y = inputs[i].y / 100;
			ScreenToClient( msg->hwnd, &pos );
			sys_ev.touch.points[i].x = pos.x;
			sys_ev.touch.points[i].y = pos.y;
			sys_ev.touch.points[i].id = inputs[i].dwID;
			if( inputs[i].dwFlags & TOUCHEVENTF_PRIMARY ) {
				sys_ev.touch.points[i].is_primary = TRUE;
			} else {
				sys_ev.touch.points[i].is_primary = FALSE;
			}
			if( inputs[i].dwFlags & TOUCHEVENTF_DOWN ) {
				sys_ev.touch.points[i].state = LCUI_TOUCHDOWN;
			} else if( inputs[i].dwFlags & TOUCHEVENTF_UP ) {
				sys_ev.touch.points[i].state = LCUI_TOUCHUP;
			} else if( inputs[i].dwFlags & TOUCHEVENTF_MOVE ) {
				sys_ev.touch.points[i].state = LCUI_TOUCHMOVE;
			}
		}
		free( inputs );
		if( !CloseTouchInputHandle( handle ) ) {
			break;
		}
		break;
	}
	default: break;
	}
	if( sys_ev.type != LCUI_NONE ) {
		LCUI_TriggerEvent( &sys_ev, NULL );
		LCUI_DestroyEvent( &sys_ev );
	}
}
Exemplo n.º 2
0
//
// creates a new balloon window
// Parameters:
//    strTitle    |  Title of balloon
//    strContent  |  Content of balloon
//    ptAnchor    |  point tail of balloon will be "anchor"ed to
//    unOptions   |  One or more of:
//                :     unCLOSE_ON_LBUTTON_UP   |  closes window on WM_LBUTTON_UP
//                :     unCLOSE_ON_MBUTTON_UP   |  closes window on WM_MBUTTON_UP
//                :     unCLOSE_ON_RBUTTON_UP   |  closes window on WM_RBUTTON_UP
//                :     unCLOSE_ON_LBUTTON_DOWN |  closes window on WM_LBUTTON_DOWN
//                :     unCLOSE_ON_MBUTTON_DOWN |  closes window on WM_MBUTTON_DOWN
//                :     unCLOSE_ON_RBUTTON_DOWN |  closes window on WM_RBUTTON_DOWN
//                :     unCLOSE_ON_MOUSE_MOVE   |  closes window when user moves mouse past threshhold
//                :     unCLOSE_ON_KEYPRESS     |  closes window on the next keypress message sent to this thread.    (!!! probably not thread safe !!!)
//                :     unDELETE_THIS_ON_CLOSE  |  deletes object when window is closed.  Used by LaunchBalloon(), use with care
//                :     unSHOW_CLOSE_BUTTON     |  shows close button in upper right
//                :     unSHOW_INNER_SHADOW     |  draw inner shadow in balloon
//                :     unSHOW_TOPMOST          |  place balloon above all other windows
//                :     unDISABLE_FADE          |  disable the fade-in/fade-out effects (overrides system and user settings)
//                :     unDISABLE_FADEIN        |  disable the fade-in effect
//                :     unDISABLE_FADEOUT       |  disable the fade-out effect
//    pParentWnd  |  Parent window.  If NULL will be set to AfxGetMainWnd() and anchor to screen
//    strURL      |  If not empty, when the balloon is clicked ShellExecute() will
//                |  be called, with strURL passed in.
//    unTimeout   |  If not 0, balloon will automatically close after unTimeout milliseconds.
//    hIcon       |  If not NULL, the icon indicated by hIcon will be displayed at top-left of the balloon.
//
// Returns:
//    TRUE if successful, else FALSE
//
BOOL CBalloonHelp::Create(const CString& strTitle, const CString& strContent, 
						  const CPoint& ptAnchor, unsigned int unOptions,
						  CWnd* pParentWnd /*=NULL*/,
						  const CString strURL /*= ""*/,
						  unsigned int unTimeout /*= 0*/,
						  HICON hIcon /*= NULL*/)
{
	m_strContent   = strContent;
	SetAnchorPoint(ptAnchor, pParentWnd);
	m_unOptions    = unOptions;
	m_strURL       = strURL;
	m_unTimeout    = unTimeout;
	
	if ( NULL != hIcon )
		SetIcon(hIcon);
	
	pParentWnd = GetSafeOwner(pParentWnd);
	if (NULL == pParentWnd)
		return FALSE;
	
	// if no fonts set, use defaults
	if ( NULL == m_pContentFont )
	{
		m_pContentFont = new CFont;
		if ( !m_pContentFont->CreateStockObject(DEFAULT_GUI_FONT) )
			return FALSE;
	}
	
	// title font defaults to bold version of content font
	if ( NULL == m_pTitleFont )
	{
		m_pTitleFont = new CFont;
		LOGFONT LogFont;
		m_pContentFont->GetLogFont(&LogFont);
		LogFont.lfWeight = FW_BOLD;
		if ( !m_pTitleFont->CreateFontIndirect(&LogFont) )
			return FALSE;
	}
	
	if ( !GetClassAtom() )  // couldn't register class
		return FALSE;
	
	// check system settings: if fade effects are disabled or unavailable, disable here too
	BOOL bFade = FALSE;
	::SystemParametersInfo(SPI_GETTOOLTIPANIMATION, 0, &bFade, 0);
	if (bFade)
		::SystemParametersInfo(SPI_GETTOOLTIPFADE, 0, &bFade, 0);
	if (!bFade || NULL == m_fnAnimateWindow)
		m_unOptions |= unDISABLE_FADE;
	
	// create invisible at arbitrary position; then position, set region, and finally show
	
	// the idea with WS_EX_TOOLWINDOW is, you can't switch to this using alt+tab
	DWORD dwExStyle = WS_EX_TOOLWINDOW;
	if ( m_unOptions&unSHOW_TOPMOST )      // make topmost, if requested
		dwExStyle |= WS_EX_TOPMOST;
	if ( !CreateEx(dwExStyle, _T("BalloonHelpClass"), strTitle, WS_POPUP, CRect(0,0,10,10), pParentWnd, 0, NULL) )
		return FALSE;
	PositionWindow();
	
	if ( (m_unOptions&unCLOSE_ON_MOUSE_MOVE)
		||(m_unOptions&unCLOSE_ON_LBUTTON_UP)
		||(m_unOptions&unCLOSE_ON_LBUTTON_DOWN)
		||(m_unOptions&unCLOSE_ON_MBUTTON_UP)
		||(m_unOptions&unCLOSE_ON_MBUTTON_DOWN)
		||(m_unOptions&unCLOSE_ON_RBUTTON_UP)
		||(m_unOptions&unCLOSE_ON_RBUTTON_DOWN) )
	{
		::GetCursorPos(&m_ptMouseOrig);
		SetMouseHook();
	}
	
	// these need to take effect even if the window receiving them
	// is not owned by this process.  So, if this process does not
	// already have the mouse captured, capture it!
	if ( (m_unOptions&unCLOSE_ON_LBUTTON_UP)
		||(m_unOptions&unCLOSE_ON_MBUTTON_UP)
		||(m_unOptions&unCLOSE_ON_RBUTTON_UP) )
	{
		// no, i don't particularly need or want to deal with a situation
		// where a balloon is being created and another program has captured
		// the mouse.  If you need it, it shouldn't be too hard, just do it here.
		if ( NULL == GetCapture() )
			SetCapture();
	}
	
	if ( m_unOptions&unCLOSE_ON_KEYPRESS )
		SetKeyboardHook();
	
	ShowBalloon();
	return TRUE;
}
Exemplo n.º 3
0
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	#ifndef WM_MOUSEWHEEL
	#define WM_MOUSEWHEEL 0x020A
	#endif
	#ifndef WHEEL_DELTA
	#define WHEEL_DELTA 120
	#endif

	irr::CIrrDeviceWin32* dev = 0;
	irr::SEvent event;

	static irr::s32 ClickCount=0;
	if (GetCapture() != hWnd && ClickCount > 0)
		ClickCount = 0;


	struct messageMap
	{
		irr::s32 group;
		UINT winMessage;
		irr::s32 irrMessage;
	};

	static messageMap mouseMap[] =
	{
		{0, WM_LBUTTONDOWN, irr::EMIE_LMOUSE_PRESSED_DOWN},
		{1, WM_LBUTTONUP,   irr::EMIE_LMOUSE_LEFT_UP},
		{0, WM_RBUTTONDOWN, irr::EMIE_RMOUSE_PRESSED_DOWN},
		{1, WM_RBUTTONUP,   irr::EMIE_RMOUSE_LEFT_UP},
		{0, WM_MBUTTONDOWN, irr::EMIE_MMOUSE_PRESSED_DOWN},
		{1, WM_MBUTTONUP,   irr::EMIE_MMOUSE_LEFT_UP},
		{2, WM_MOUSEMOVE,   irr::EMIE_MOUSE_MOVED},
		{3, WM_MOUSEWHEEL,  irr::EMIE_MOUSE_WHEEL},
		{-1, 0, 0}
	};

	// handle grouped events
	messageMap * m = mouseMap;
	while ( m->group >=0 && m->winMessage != message )
		m += 1;

	if ( m->group >= 0 )
	{
		if ( m->group == 0 )	// down
		{
			ClickCount++;
			SetCapture(hWnd);
		}
		else
		if ( m->group == 1 )	// up
		{
			ClickCount--;
			if (ClickCount<1)
			{
				ClickCount=0;
				ReleaseCapture();
			}
		}

		event.EventType = irr::EET_MOUSE_INPUT_EVENT;
		event.MouseInput.Event = (irr::EMOUSE_INPUT_EVENT) m->irrMessage;
		event.MouseInput.X = (short)LOWORD(lParam);
		event.MouseInput.Y = (short)HIWORD(lParam);
		event.MouseInput.Shift = ((LOWORD(wParam) & MK_SHIFT) != 0);
		event.MouseInput.Control = ((LOWORD(wParam) & MK_CONTROL) != 0);
		// left and right mouse buttons
		event.MouseInput.ButtonStates = wParam & ( MK_LBUTTON | MK_RBUTTON);
		// middle and extra buttons
		if (wParam & MK_MBUTTON)
			event.MouseInput.ButtonStates |= irr::EMBSM_MIDDLE;
#if(_WIN32_WINNT >= 0x0500)
		if (wParam & MK_XBUTTON1)
			event.MouseInput.ButtonStates |= irr::EMBSM_EXTRA1;
		if (wParam & MK_XBUTTON2)
			event.MouseInput.ButtonStates |= irr::EMBSM_EXTRA2;
#endif
		event.MouseInput.Wheel = 0.f;

		// wheel
		if ( m->group == 3 )
		{
			POINT p; // fixed by jox
			p.x = 0; p.y = 0;
			ClientToScreen(hWnd, &p);
			event.MouseInput.X -= p.x;
			event.MouseInput.Y -= p.y;
			event.MouseInput.Wheel = ((irr::f32)((short)HIWORD(wParam))) / (irr::f32)WHEEL_DELTA;
		}

		dev = getDeviceFromHWnd(hWnd);
		if (dev)
		{
			dev->postEventFromUser(event);

			if ( event.MouseInput.Event >= irr::EMIE_LMOUSE_PRESSED_DOWN && event.MouseInput.Event <= irr::EMIE_MMOUSE_PRESSED_DOWN )
			{
				irr::u32 clicks = dev->checkSuccessiveClicks(event.MouseInput.X, event.MouseInput.Y, event.MouseInput.Event);
				if ( clicks == 2 )
				{
					event.MouseInput.Event = (irr::EMOUSE_INPUT_EVENT)(irr::EMIE_LMOUSE_DOUBLE_CLICK + event.MouseInput.Event-irr::EMIE_LMOUSE_PRESSED_DOWN);
					dev->postEventFromUser(event);
				}
				else if ( clicks == 3 )
				{
					event.MouseInput.Event = (irr::EMOUSE_INPUT_EVENT)(irr::EMIE_LMOUSE_TRIPLE_CLICK + event.MouseInput.Event-irr::EMIE_LMOUSE_PRESSED_DOWN);
					dev->postEventFromUser(event);
				}
			}
		}
		return 0;
	}

	switch (message)
	{
	case WM_PAINT:
		{
			PAINTSTRUCT ps;
			BeginPaint(hWnd, &ps);
			EndPaint(hWnd, &ps);
		}
		return 0;

	case WM_ERASEBKGND:
		return 0;

	case WM_SYSKEYDOWN:
	case WM_SYSKEYUP:
	case WM_KEYDOWN:
	case WM_KEYUP:
		{
			BYTE allKeys[256];

			event.EventType = irr::EET_KEY_INPUT_EVENT;
			event.KeyInput.Key = (irr::EKEY_CODE)wParam;
			event.KeyInput.PressedDown = (message==WM_KEYDOWN || message == WM_SYSKEYDOWN);

			const UINT MY_MAPVK_VSC_TO_VK_EX = 3; // MAPVK_VSC_TO_VK_EX should be in SDK according to MSDN, but isn't in mine.
			if ( event.KeyInput.Key == irr::KEY_SHIFT )
			{
				// this will fail on systems before windows NT/2000/XP, not sure _what_ will return there instead.
				event.KeyInput.Key = (irr::EKEY_CODE)MapVirtualKey( ((lParam>>16) & 255), MY_MAPVK_VSC_TO_VK_EX );
			}
			if ( event.KeyInput.Key == irr::KEY_CONTROL )
			{
				event.KeyInput.Key = (irr::EKEY_CODE)MapVirtualKey( ((lParam>>16) & 255), MY_MAPVK_VSC_TO_VK_EX );
				// some keyboards will just return LEFT for both - left and right keys. So also check extend bit.
				if (lParam & 0x1000000)
					event.KeyInput.Key = irr::KEY_RCONTROL;
			}
			if ( event.KeyInput.Key == irr::KEY_MENU )
			{
				event.KeyInput.Key = (irr::EKEY_CODE)MapVirtualKey( ((lParam>>16) & 255), MY_MAPVK_VSC_TO_VK_EX );
				if (lParam & 0x1000000)
					event.KeyInput.Key = irr::KEY_RMENU;
			}
Exemplo n.º 4
0
LRESULT CALLBACK
viewproc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    int x = (signed short) LOWORD(lParam);
    int y = (signed short) HIWORD(lParam);
    glui32 key;

    switch (message)
    {
    case WM_ERASEBKGND:
    return 1; // don't erase; we'll repaint it all

    case WM_PAINT:
    {
        PAINTSTRUCT ps;

        /* make sure we have a fresh bitmap */
        if (!gli_drawselect)
            gli_windows_redraw();
        else
            gli_drawselect = FALSE;

        /* and blit it to the screen */
        hdc = BeginPaint(hwnd, &ps);
        winblit(ps.rcPaint);
        hdc = NULL;
        EndPaint(hwnd, &ps);

        return 0;
    }

    case WM_SIZE:
    {
        int newwid = LOWORD(lParam);
        int newhgt = HIWORD(lParam);

        if (newwid == 0 || newhgt == 0)
        break;

        if (newwid == gli_image_w && newhgt == gli_image_h)
        break;

        gli_image_w = newwid;
        gli_image_h = newhgt;

        gli_resize_mask(gli_image_w, gli_image_h);

        gli_image_s = ((gli_image_w * 3 + 3) / 4) * 4;
        if (gli_image_rgb)
        free(gli_image_rgb);
        gli_image_rgb = malloc(gli_image_s * gli_image_h);

        gli_force_redraw = 1;

        gli_windows_size_change();

        break;
    }

    case WM_LBUTTONDOWN:
    {
        SetFocus(hwndview);
        gli_input_handle_click(x, y);
        return 0;
    }

    case WM_LBUTTONUP:
    {
        gli_copyselect = FALSE;
        SetCursor(idc_arrow);
        return 0;
    }

    case WM_MBUTTONDOWN:
    case WM_RBUTTONDOWN:
    {
        SetFocus(hwndview);
        return 0;
    }

    case WM_MOUSEWHEEL:
    {
        if (GET_WHEEL_DELTA_WPARAM(wParam) > 0)
            gli_input_handle_key(keycode_MouseWheelUp);
        else
            gli_input_handle_key(keycode_MouseWheelDown);
    }

    case WM_CAPTURECHANGED:
    {
        gli_copyselect = FALSE;
        return 0;
    }

    case WM_MOUSEMOVE:
    {
        /* catch and release */
        RECT rect;
        POINT pt = { x, y };
        GetClientRect(hwnd, &rect);
        int hover = PtInRect(&rect, pt);

        if (!hover) {
            if (GetCapture() == hwnd)
                ReleaseCapture();
        } else {
            if (GetCapture() != hwnd ) {
                SetCapture(hwnd);
            }
            if (gli_copyselect) {
                SetCursor(idc_ibeam);
                gli_move_selection(x, y);
            } else {
                if (gli_get_hyperlink(x, y)) {
                    SetCursor(idc_hand);
                } else {
                    SetCursor(idc_arrow);
                }
            }
        }

        return 0;
    }

    case WM_COPY:
    {
        gli_copyselect = FALSE;
        SetCursor(idc_arrow);
        winclipsend();
        return 0;
    }

    case WM_PASTE:
    {
        SetFocus(hwndview);
        winclipreceive();
        return 0;
    }
    
    case WM_SYSKEYDOWN:
    {
        if (wParam == VK_RETURN && (HIWORD(lParam) & KF_ALTDOWN))
        {
            onfullscreen();
            return 0;
        }
        break;
    }

    case WM_KEYDOWN:
    {
        if (GetKeyState(VK_CONTROL) < 0)
        {
            switch (wParam)
            {
            case VK_LEFT: gli_input_handle_key(keycode_SkipWordLeft); break;
            case VK_RIGHT: gli_input_handle_key(keycode_SkipWordRight); break;
            }
        }
        else
        {
            switch (wParam)
            {
            case VK_PRIOR: gli_input_handle_key(keycode_PageUp); break;
            case VK_NEXT: gli_input_handle_key(keycode_PageDown); break;
            case VK_HOME: gli_input_handle_key(keycode_Home); break;
            case VK_END: gli_input_handle_key(keycode_End); break;
            case VK_LEFT: gli_input_handle_key(keycode_Left); break;
            case VK_RIGHT: gli_input_handle_key(keycode_Right); break;
            case VK_UP: gli_input_handle_key(keycode_Up); break;
            case VK_DOWN: gli_input_handle_key(keycode_Down); break;
            case VK_ESCAPE: gli_input_handle_key(keycode_Escape); break;
            case VK_DELETE: gli_input_handle_key(keycode_Erase); break;
            case VK_F1: gli_input_handle_key(keycode_Func1); break;
            case VK_F2: gli_input_handle_key(keycode_Func2); break;
            case VK_F3: gli_input_handle_key(keycode_Func3); break;
            case VK_F4: gli_input_handle_key(keycode_Func4); break;
            case VK_F5: gli_input_handle_key(keycode_Func5); break;
            case VK_F6: gli_input_handle_key(keycode_Func6); break;
            case VK_F7: gli_input_handle_key(keycode_Func7); break;
            case VK_F8: gli_input_handle_key(keycode_Func8); break;
            case VK_F9: gli_input_handle_key(keycode_Func9); break;
            case VK_F10: gli_input_handle_key(keycode_Func10); break;
            case VK_F11: gli_input_handle_key(keycode_Func11); break;
            case VK_F12: gli_input_handle_key(keycode_Func12); break;
            }
        }
        return 0;
    }

    /* unicode encoded chars, including escape, backspace etc... */
    case WM_UNICHAR:
        key = wParam;

        if (key == UNICODE_NOCHAR)
            return 1; /* yes, we like WM_UNICHAR */

        if (key == '\r' || key == '\n')
            gli_input_handle_key(keycode_Return);
        else if (key == '\b')
            gli_input_handle_key(keycode_Delete);
        else if (key == '\t')
            gli_input_handle_key(keycode_Tab);
        else if (key == 0x03 || key == 0x18)
            SendMessage(hwndview, WM_COPY, 0, 0);
        else if (key == 0x16)
            SendMessage(hwndview, WM_PASTE, 0, 0);
        else if (key != 27)
            gli_input_handle_key(key);

        return 0;

    case WM_CHAR:
        key = wParam;

        if (key == '\r' || key == '\n')
            gli_input_handle_key(keycode_Return);
        else if (key == '\b')
            gli_input_handle_key(keycode_Delete);
        else if (key == '\t')
            gli_input_handle_key(keycode_Tab);
        else if (key == 0x03 || key == 0x18)
            SendMessage(hwndview, WM_COPY, 0, 0);
        else if (key == 0x16)
            SendMessage(hwndview, WM_PASTE, 0, 0);
        else if (key != 27) {
            /* translate from ANSI code page to Unicode */
            char ansich = (char)key;
            wchar_t widebuf[2];
            int res = MultiByteToWideChar(CP_ACP, 0, &ansich, 1, widebuf, 2);
            if (res) {
                if (Uni_IsSurrogate1(widebuf[0]))
                    key = Uni_SurrogateToUTF32(widebuf[0], widebuf[1]);
                else
                    key = widebuf[0];
                gli_input_handle_key(key);
            }
        }

        return 0;
    }

    /* Pass on unhandled events to Windows */
    return DefWindowProc(hwnd, message, wParam, lParam);
}
Exemplo n.º 5
0
// Window callback function (handles window events)
//
static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
                                   WPARAM wParam, LPARAM lParam)
{
    _GLFWwindow* window = (_GLFWwindow*) GetWindowLongPtrW(hWnd, 0);

    switch (uMsg)
    {
        case WM_NCCREATE:
        {
            CREATESTRUCTW* cs = (CREATESTRUCTW*) lParam;
            SetWindowLongPtrW(hWnd, 0, (LONG_PTR) cs->lpCreateParams);
            break;
        }

        case WM_SETFOCUS:
        {
            if (window->cursorMode != GLFW_CURSOR_NORMAL)
                _glfwPlatformApplyCursorMode(window);

            _glfwInputWindowFocus(window, GL_TRUE);
            return 0;
        }

        case WM_KILLFOCUS:
        {
            if (window->cursorMode != GLFW_CURSOR_NORMAL)
                restoreCursor(window);

            if (window->monitor && window->autoIconify)
                _glfwPlatformIconifyWindow(window);

            _glfwInputWindowFocus(window, GL_FALSE);
            return 0;
        }

        case WM_SYSCOMMAND:
        {
            switch (wParam & 0xfff0)
            {
                case SC_SCREENSAVE:
                case SC_MONITORPOWER:
                {
                    if (window->monitor)
                    {
                        // We are running in full screen mode, so disallow
                        // screen saver and screen blanking
                        return 0;
                    }
                    else
                        break;
                }

                // User trying to access application menu using ALT?
                case SC_KEYMENU:
                    return 0;
            }
            break;
        }

        case WM_CLOSE:
        {
            _glfwInputWindowCloseRequest(window);
            return 0;
        }

        case WM_KEYDOWN:
        case WM_SYSKEYDOWN:
        {
            const int scancode = (lParam >> 16) & 0x1ff;
            const int key = translateKey(wParam, lParam);
            if (key == _GLFW_KEY_INVALID)
                break;

            _glfwInputKey(window, key, scancode, GLFW_PRESS, getKeyMods());
            break;
        }

        case WM_CHAR:
        {
            _glfwInputChar(window, (unsigned int) wParam, getKeyMods(), GL_TRUE);
            return 0;
        }

        case WM_SYSCHAR:
        {
            _glfwInputChar(window, (unsigned int) wParam, getKeyMods(), GL_FALSE);
            return 0;
        }

        case WM_UNICHAR:
        {
            // This message is not sent by Windows, but is sent by some
            // third-party input method engines

            if (wParam == UNICODE_NOCHAR)
            {
                // Returning TRUE here announces support for this message
                return TRUE;
            }

            _glfwInputChar(window, (unsigned int) wParam, getKeyMods(), GL_TRUE);
            return FALSE;
        }

        case WM_KEYUP:
        case WM_SYSKEYUP:
        {
            const int mods = getKeyMods();
            const int scancode = (lParam >> 16) & 0x1ff;
            const int key = translateKey(wParam, lParam);
            if (key == _GLFW_KEY_INVALID)
                break;

            if (wParam == VK_SHIFT)
            {
                // Release both Shift keys on Shift up event, as only one event
                // is sent even if both keys are released
                _glfwInputKey(window, GLFW_KEY_LEFT_SHIFT, scancode, GLFW_RELEASE, mods);
                _glfwInputKey(window, GLFW_KEY_RIGHT_SHIFT, scancode, GLFW_RELEASE, mods);
            }
            else if (wParam == VK_SNAPSHOT)
            {
                // Key down is not reported for the print screen key
                _glfwInputKey(window, key, scancode, GLFW_PRESS, mods);
                _glfwInputKey(window, key, scancode, GLFW_RELEASE, mods);
            }
            else
                _glfwInputKey(window, key, scancode, GLFW_RELEASE, mods);

            break;
        }

        case WM_LBUTTONDOWN:
        case WM_RBUTTONDOWN:
        case WM_MBUTTONDOWN:
        case WM_XBUTTONDOWN:
        {
            const int mods = getKeyMods();

            SetCapture(hWnd);

            if (uMsg == WM_LBUTTONDOWN)
                _glfwInputMouseClick(window, GLFW_MOUSE_BUTTON_LEFT, GLFW_PRESS, mods);
            else if (uMsg == WM_RBUTTONDOWN)
                _glfwInputMouseClick(window, GLFW_MOUSE_BUTTON_RIGHT, GLFW_PRESS, mods);
            else if (uMsg == WM_MBUTTONDOWN)
                _glfwInputMouseClick(window, GLFW_MOUSE_BUTTON_MIDDLE, GLFW_PRESS, mods);
            else
            {
                if (HIWORD(wParam) == XBUTTON1)
                    _glfwInputMouseClick(window, GLFW_MOUSE_BUTTON_4, GLFW_PRESS, mods);
                else if (HIWORD(wParam) == XBUTTON2)
                    _glfwInputMouseClick(window, GLFW_MOUSE_BUTTON_5, GLFW_PRESS, mods);

                return TRUE;
            }

            return 0;
        }

        case WM_LBUTTONUP:
        case WM_RBUTTONUP:
        case WM_MBUTTONUP:
        case WM_XBUTTONUP:
        {
            const int mods = getKeyMods();

            ReleaseCapture();

            if (uMsg == WM_LBUTTONUP)
                _glfwInputMouseClick(window, GLFW_MOUSE_BUTTON_LEFT, GLFW_RELEASE, mods);
            else if (uMsg == WM_RBUTTONUP)
                _glfwInputMouseClick(window, GLFW_MOUSE_BUTTON_RIGHT, GLFW_RELEASE, mods);
            else if (uMsg == WM_MBUTTONUP)
                _glfwInputMouseClick(window, GLFW_MOUSE_BUTTON_MIDDLE, GLFW_RELEASE, mods);
            else
            {
                if (HIWORD(wParam) == XBUTTON1)
                    _glfwInputMouseClick(window, GLFW_MOUSE_BUTTON_4, GLFW_RELEASE, mods);
                else if (HIWORD(wParam) == XBUTTON2)
                    _glfwInputMouseClick(window, GLFW_MOUSE_BUTTON_5, GLFW_RELEASE, mods);

                return TRUE;
            }

            return 0;
        }

        case WM_MOUSEMOVE:
        {
            const int x = GET_X_LPARAM(lParam);
            const int y = GET_Y_LPARAM(lParam);

            if (window->cursorMode == GLFW_CURSOR_DISABLED)
            {
                if (_glfw.cursorWindow != window)
                    break;

                _glfwInputCursorMotion(window,
                                       x - window->win32.cursorPosX,
                                       y - window->win32.cursorPosY);
            }
            else
                _glfwInputCursorMotion(window, x, y);

            window->win32.cursorPosX = x;
            window->win32.cursorPosY = y;

            if (!window->win32.cursorTracked)
            {
                TRACKMOUSEEVENT tme;
                ZeroMemory(&tme, sizeof(tme));
                tme.cbSize = sizeof(tme);
                tme.dwFlags = TME_LEAVE;
                tme.hwndTrack = window->win32.handle;
                TrackMouseEvent(&tme);

                window->win32.cursorTracked = GL_TRUE;
                _glfwInputCursorEnter(window, GL_TRUE);
            }

            return 0;
        }

        case WM_MOUSELEAVE:
        {
            window->win32.cursorTracked = GL_FALSE;
            _glfwInputCursorEnter(window, GL_FALSE);
            return 0;
        }

        case WM_MOUSEWHEEL:
        {
            _glfwInputScroll(window, 0.0, (SHORT) HIWORD(wParam) / (double) WHEEL_DELTA);
            return 0;
        }

        case WM_MOUSEHWHEEL:
        {
            // This message is only sent on Windows Vista and later
            // NOTE: The X-axis is inverted for consistency with OS X and X11.
            _glfwInputScroll(window, -((SHORT) HIWORD(wParam) / (double) WHEEL_DELTA), 0.0);
            return 0;
        }

        case WM_SIZE:
        {
            if (_glfw.cursorWindow == window)
            {
                if (window->cursorMode == GLFW_CURSOR_DISABLED)
                    updateClipRect(window);
            }

            if (!window->win32.iconified && wParam == SIZE_MINIMIZED)
            {
                window->win32.iconified = GL_TRUE;
                if (window->monitor)
                    leaveFullscreenMode(window);

                _glfwInputWindowIconify(window, GL_TRUE);
            }
            else if (window->win32.iconified &&
                     (wParam == SIZE_RESTORED || wParam == SIZE_MAXIMIZED))
            {
                window->win32.iconified = GL_FALSE;
                if (window->monitor)
                    enterFullscreenMode(window);

                _glfwInputWindowIconify(window, GL_FALSE);
            }

            _glfwInputFramebufferSize(window, LOWORD(lParam), HIWORD(lParam));
            _glfwInputWindowSize(window, LOWORD(lParam), HIWORD(lParam));
            return 0;
        }

        case WM_MOVE:
        {
            if (_glfw.cursorWindow == window)
            {
                if (window->cursorMode == GLFW_CURSOR_DISABLED)
                    updateClipRect(window);
            }

            // NOTE: This cannot use LOWORD/HIWORD recommended by MSDN, as
            // those macros do not handle negative window positions correctly
            _glfwInputWindowPos(window,
                                GET_X_LPARAM(lParam),
                                GET_Y_LPARAM(lParam));
            return 0;
        }

        case WM_PAINT:
        {
            _glfwInputWindowDamage(window);
            break;
        }

        case WM_ERASEBKGND:
        {
            return TRUE;
        }

        case WM_SETCURSOR:
        {
            if (_glfw.cursorWindow == window && LOWORD(lParam) == HTCLIENT)
            {
                if (window->cursorMode == GLFW_CURSOR_HIDDEN ||
                    window->cursorMode == GLFW_CURSOR_DISABLED)
                {
                    SetCursor(NULL);
                    return TRUE;
                }
                else if (window->cursor)
                {
                    SetCursor(window->cursor->win32.handle);
                    return TRUE;
                }
            }

            break;
        }

        case WM_DEVICECHANGE:
        {
            if (DBT_DEVNODES_CHANGED == wParam)
            {
                _glfwInputMonitorChange();
                return TRUE;
            }
            break;
        }

        case WM_DROPFILES:
        {
            HDROP drop = (HDROP) wParam;
            POINT pt;
            int i;

            const int count = DragQueryFileW(drop, 0xffffffff, NULL, 0);
            char** paths = calloc(count, sizeof(char*));

            // Move the mouse to the position of the drop
            DragQueryPoint(drop, &pt);
            _glfwInputCursorMotion(window, pt.x, pt.y);

            for (i = 0;  i < count;  i++)
            {
                const UINT length = DragQueryFileW(drop, i, NULL, 0);
                WCHAR* buffer = calloc(length + 1, sizeof(WCHAR));

                DragQueryFileW(drop, i, buffer, length + 1);
                paths[i] = _glfwCreateUTF8FromWideString(buffer);

                free(buffer);
            }

            _glfwInputDrop(window, count, (const char**) paths);

            for (i = 0;  i < count;  i++)
                free(paths[i]);
            free(paths);

            DragFinish(drop);
            return 0;
        }
    }

    return DefWindowProc(hWnd, uMsg, wParam, lParam);
}
void D3DLightingBasic::OnMouseDown(WPARAM btnState, int x, int y)
{
	mLastMousePos.x = x;
	mLastMousePos.y = y;
	SetCapture(m_hMainWnd);
}
Exemplo n.º 7
0
LRESULT CALLBACK PhpSearchWndSubclassProc(
    _In_ HWND hWnd,
    _In_ UINT uMsg,
    _In_ WPARAM wParam,
    _In_ LPARAM lParam,
    _In_ UINT_PTR uIdSubclass,
    _In_ ULONG_PTR dwRefData
    )
{
    PEDIT_CONTEXT context = (PEDIT_CONTEXT)dwRefData;

    switch (uMsg)
    {
    case WM_NCDESTROY:
        {
            PhpSearchFreeTheme(context);

            if (context->WindowFont)
                DeleteObject(context->WindowFont);

            RemoveWindowSubclass(hWnd, PhpSearchWndSubclassProc, uIdSubclass);
            PhFree(context);
        }
        break;
    case WM_ERASEBKGND:
        return 1;
    case WM_NCCALCSIZE:
        {
            LPNCCALCSIZE_PARAMS ncCalcSize = (NCCALCSIZE_PARAMS*)lParam;

            // Let Windows handle the non-client defaults.
            DefSubclassProc(hWnd, uMsg, wParam, lParam);

            // Deflate the client area to accommodate the custom button.
            ncCalcSize->rgrc[0].right -= context->CXWidth;
        }
        return 0;
    case WM_NCPAINT:
        {
            RECT windowRect;

            // Let Windows handle the non-client defaults.
            DefSubclassProc(hWnd, uMsg, wParam, lParam);

            // Get the screen coordinates of the window.
            GetWindowRect(hWnd, &windowRect);

            // Adjust the coordinates (start from 0,0).
            OffsetRect(&windowRect, -windowRect.left, -windowRect.top);

            // Get the position of the inserted button.
            PhpSearchGetButtonRect(context, &windowRect);

            // Draw the button.
            PhpSearchDrawButton(context, windowRect);
        }
        return 0;
    case WM_NCHITTEST:
        {
            POINT windowPoint;
            RECT windowRect;

            // Get the screen coordinates of the mouse.
            if (!GetCursorPos(&windowPoint))
                break;

            // Get the screen coordinates of the window.
            GetWindowRect(hWnd, &windowRect);

            // Get the position of the inserted button.
            PhpSearchGetButtonRect(context, &windowRect);

            // Check that the mouse is within the inserted button.
            if (PtInRect(&windowRect, windowPoint))
            {
                return HTBORDER;
            }
        }
        break;
    case WM_NCLBUTTONDOWN:
        {
            POINT windowPoint;
            RECT windowRect;

            // Get the screen coordinates of the mouse.
            if (!GetCursorPos(&windowPoint))
                break;

            // Get the screen coordinates of the window.
            GetWindowRect(hWnd, &windowRect);

            // Get the position of the inserted button.
            PhpSearchGetButtonRect(context, &windowRect);

            // Check that the mouse is within the inserted button.
            if (PtInRect(&windowRect, windowPoint))
            {
                context->Pushed = TRUE;

                SetCapture(hWnd);

                RedrawWindow(hWnd, NULL, NULL, RDW_FRAME | RDW_INVALIDATE);
            }
        }
        break;
    case WM_LBUTTONUP:
        {
            POINT windowPoint;
            RECT windowRect;

            // Get the screen coordinates of the mouse.
            if (!GetCursorPos(&windowPoint))
                break;

            // Get the screen coordinates of the window.
            GetWindowRect(hWnd, &windowRect);

            // Get the position of the inserted button.
            PhpSearchGetButtonRect(context, &windowRect);

            // Check that the mouse is within the inserted button.
            if (PtInRect(&windowRect, windowPoint))
            {
                // Forward click notification.
                //SendMessage(GetParent(context->WindowHandle), WM_COMMAND, MAKEWPARAM(context->CommandID, BN_CLICKED), 0);

                SetFocus(hWnd);
                Static_SetText(hWnd, L"");
            }

            if (GetCapture() == hWnd)
            {
                context->Pushed = FALSE;
                ReleaseCapture();
            }

            RedrawWindow(hWnd, NULL, NULL, RDW_FRAME | RDW_INVALIDATE);
        }
        break;
    case WM_CUT:
    case WM_CLEAR:
    case WM_PASTE:
    case WM_UNDO:
    case WM_KEYUP:
    case WM_SETTEXT:
    case WM_KILLFOCUS:
        RedrawWindow(hWnd, NULL, NULL, RDW_FRAME | RDW_INVALIDATE);
        break;
    case WM_SETTINGCHANGE:
    case WM_SYSCOLORCHANGE:
    case WM_THEMECHANGED:
        {
            PhpSearchFreeTheme(context);
            PhpSearchInitializeTheme(context);
            PhpSearchInitializeFont(context);

            // Reset the client area margins.
            SendMessage(hWnd, EM_SETMARGINS, EC_LEFTMARGIN, MAKELPARAM(0, 0));

            // Refresh the non-client area.
            SetWindowPos(hWnd, NULL, 0, 0, 0, 0, SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE | SWP_FRAMECHANGED);

            // Force the edit control to update its non-client area.
            RedrawWindow(hWnd, NULL, NULL, RDW_FRAME | RDW_INVALIDATE);
        }
        break;
    case WM_NCMOUSEMOVE:
        {
            POINT windowPoint;
            RECT windowRect;

            // Get the screen coordinates of the mouse.
            if (!GetCursorPos(&windowPoint))
                break;

            // Get the screen coordinates of the window.
            GetWindowRect(hWnd, &windowRect);

            // Get the position of the inserted button.
            PhpSearchGetButtonRect(context, &windowRect);

            // Check that the mouse is within the inserted button.
            if (PtInRect(&windowRect, windowPoint) && !context->Hot)
            {
                TRACKMOUSEEVENT trackMouseEvent;

                trackMouseEvent.cbSize = sizeof(TRACKMOUSEEVENT);
                trackMouseEvent.dwFlags = TME_LEAVE | TME_NONCLIENT;
                trackMouseEvent.hwndTrack = hWnd;
                trackMouseEvent.dwHoverTime = 0;

                context->Hot = TRUE;

                RedrawWindow(hWnd, NULL, NULL, RDW_FRAME | RDW_INVALIDATE);

                TrackMouseEvent(&trackMouseEvent);
            }
        }
        break;
    case WM_NCMOUSELEAVE:
        {
            if (context->Hot)
            {
                context->Hot = FALSE;
                RedrawWindow(hWnd, NULL, NULL, RDW_FRAME | RDW_INVALIDATE);
            }
        }
        break;
    case WM_MOUSEMOVE:
        {
            if ((wParam & MK_LBUTTON) && GetCapture() == hWnd)
            {
                POINT windowPoint;
                RECT windowRect;

                // Get the screen coordinates of the mouse.
                if (!GetCursorPos(&windowPoint))
                    break;

                // Get the screen coordinates of the window.
                GetWindowRect(hWnd, &windowRect);

                // Get the position of the inserted button.
                PhpSearchGetButtonRect(context, &windowRect);

                // Check that the mouse is within the inserted button.
                context->Pushed = PtInRect(&windowRect, windowPoint);

                RedrawWindow(hWnd, NULL, NULL, RDW_FRAME | RDW_INVALIDATE);
            }
        }
        break;
    }

    return DefSubclassProc(hWnd, uMsg, wParam, lParam);
}
int Docking_ProcessWindowMessage(WPARAM wParam,LPARAM lParam)
{
	APPBARDATA abd;
	static int draggingTitle;
	MSG *msg=(MSG*)wParam;

	if(msg->message==WM_DESTROY) 
		ModernWriteSettingByte(NULL,"CList","Docked",(BYTE)g_CluiData.fDocked);

	if(!g_CluiData.fDocked && msg->message!=WM_CREATE && msg->message!=WM_MOVING && msg->message!=WM_CREATEDOCKED && msg->message != WM_MOVE && msg->message != WM_SIZE) return 0;
	switch(msg->message) {
		case WM_CREATE:
			//if(GetSystemMetrics(SM_CMONITORS)>1) return 0;
			if(ModernGetSettingByte(NULL,"CList","Docked",0) && ModernGetSettingByte(NULL,"CLUI","DockToSides",SETTING_DOCKTOSIDES_DEFAULT)) 
			{
				PostMessage(msg->hwnd,WM_CREATEDOCKED,0,0);
			}
			draggingTitle=0;
			return 0;

		case WM_CREATEDOCKED:
			//we need to post a message just after creation to let main message function do some work
			g_CluiData.fDocked=(BOOL)ModernGetSettingByte(NULL,"CList","Docked",0);
			if(IsWindowVisible(msg->hwnd) && !IsIconic(msg->hwnd)) {
				RECT rc, rcMonitor;
				ZeroMemory(&abd,sizeof(abd));
				abd.cbSize=sizeof(abd);
				abd.hWnd=msg->hwnd;
				abd.lParam=0;
				abd.uCallbackMessage=WM_DOCKCALLBACK;
				SHAppBarMessage(ABM_NEW,&abd);
				GetWindowRect(msg->hwnd,&rc);
				Docking_GetMonitorRectFromWindow(msg->hwnd,&rcMonitor);
				Docking_AdjustPosition(msg->hwnd,&rcMonitor,&rc);
				MoveWindow(msg->hwnd,rc.left,rc.top,rc.right-rc.left,rc.bottom-rc.top,TRUE);
				g_CluiData.mutexPreventDockMoving=0;
				Sync(CLUIFrames_OnMoving,msg->hwnd,&rc);
				g_CluiData.mutexPreventDockMoving=1;
				ModernSkinButton_ReposButtons( msg->hwnd, SBRF_DO_NOT_DRAW, NULL );
			}
			break;
		case WM_CAPTURECHANGED:
			ModernSkinButton_ReposButtons(msg->hwnd, SBRF_DO_NOT_DRAW,NULL);
			return 0;
		case WM_ACTIVATE:
			ZeroMemory(&abd,sizeof(abd));
			abd.cbSize=sizeof(abd);
			abd.hWnd=msg->hwnd;
			SHAppBarMessage(ABM_ACTIVATE,&abd);
			return 0;
		case WM_SIZE:
			ModernSkinButton_ReposButtons( msg->hwnd, SBRF_DO_REDRAW_ALL, NULL );
			return 0;

		case WM_WINDOWPOSCHANGED:
			{
				if (g_CluiData.fDocked) ModernSkinButton_ReposButtons( msg->hwnd,SBRF_DO_NOT_DRAW, NULL );
				return 0;
				ZeroMemory(&abd,sizeof(abd));
				abd.cbSize=sizeof(abd);
				abd.hWnd=msg->hwnd;
				SHAppBarMessage(ABM_WINDOWPOSCHANGED,&abd);
				ModernSkinButton_ReposButtons( msg->hwnd, SBRF_DO_NOT_DRAW, NULL );
				return 0;
			}
		case WM_MOVING:
			{
				RECT rcMonitor;
				RECT rcWindow;
				RECT *rc;
				int dx=0;
				POINT ptCursor;
				if (g_CluiData.fDocked) return 0;
				// stop early
				BOOL bControlled = (BOOL)(GetAsyncKeyState(VK_CONTROL)&0x8000);

				// GetMessagePos() is no good, position is always unsigned
				GetCursorPos(&ptCursor);
				GetWindowRect(msg->hwnd,&rcWindow);
				dock_drag_dx=rcWindow.left-ptCursor.x;
				dock_drag_dy=rcWindow.top-ptCursor.y;
				Docking_GetMonitorRectFromPoint(ptCursor,&rcMonitor);

				if(((ptCursor.x<rcMonitor.left+EDGESENSITIVITY) 
					|| (ptCursor.x>=rcMonitor.right-EDGESENSITIVITY))
					&& ModernGetSettingByte(NULL,"CLUI","DockToSides",SETTING_DOCKTOSIDES_DEFAULT))
				{
					ZeroMemory(&abd,sizeof(abd));
					abd.cbSize=sizeof(abd);
					abd.hWnd=msg->hwnd;
					abd.lParam=0;
					abd.uCallbackMessage=WM_DOCKCALLBACK;
					SHAppBarMessage(ABM_NEW,&abd);
					if(ptCursor.x<rcMonitor.left+EDGESENSITIVITY) g_CluiData.fDocked=DOCKED_LEFT;
					else g_CluiData.fDocked=DOCKED_RIGHT;
					//	TempDock=1;				
					GetWindowRect(msg->hwnd,(LPRECT)msg->lParam);
					rc=(RECT*)msg->lParam;
					if (g_CluiData.fDocked==DOCKED_RIGHT)
						dx=(rc->right>rcMonitor.right)?rc->right-rcMonitor.right:0;
					else
						dx=(rc->left<rcMonitor.left)?rc->left-rcMonitor.left:0;
					OffsetRect(rc,-dx,0);
					Docking_AdjustPosition(msg->hwnd,(LPRECT)&rcMonitor,(LPRECT)msg->lParam);
					SendMessage(msg->hwnd,WM_SIZE,0,0);				
					g_CluiData.mutexPreventDockMoving=0;
					Sync(CLUIFrames_OnMoving,msg->hwnd,(LPRECT)msg->lParam);
					g_CluiData.mutexPreventDockMoving=1;
					mouse_event(MOUSEEVENTF_LEFTUP,0,0,0,0);
					ModernWriteSettingByte(NULL,"CList","Docked",(BYTE)g_CluiData.fDocked);
					ModernSkinButton_ReposButtons( msg->hwnd, SBRF_DO_NOT_DRAW, NULL );
					return TRUE;
				}
				return 0;
			}
		case WM_EXITSIZEMOVE:
			{
				RECT rcMonitor;
				RECT rcWindow;
				if (TempDock) TempDock=0;
				GetWindowRect(msg->hwnd,&rcWindow);
				Docking_GetMonitorRectFromWindow(msg->hwnd,&rcMonitor);
				Docking_AdjustPosition(msg->hwnd,&rcMonitor,&rcWindow);
				*((LRESULT*)lParam)=TRUE;
				g_CluiData.mutexPreventDockMoving=0;
				SetWindowPos(msg->hwnd,0,rcWindow.left,rcWindow.top,0,0,SWP_NOSIZE|SWP_NOZORDER|SWP_NOREDRAW|SWP_NOSENDCHANGING);
				Sync(CLUIFrames_OnMoving,msg->hwnd,&rcWindow);
				ModernSkinButton_ReposButtons( msg->hwnd, SBRF_DO_NOT_DRAW, NULL );//-=-=-=
				g_CluiData.mutexPreventDockMoving=1;		  
				return 1;
			}

		case WM_MOVE:
			{

				if(g_CluiData.fDocked && 0) {
					RECT rc, rcMonitor;
					Docking_GetMonitorRectFromWindow(msg->hwnd,&rcMonitor);
					GetWindowRect(msg->hwnd,&rc);
					Docking_AdjustPosition(msg->hwnd,&rcMonitor,&rc);
					MoveWindow(msg->hwnd,rc.left,rc.top,rc.right-rc.left,rc.bottom-rc.top,TRUE);
					Sync(CLUIFrames_OnMoving,msg->hwnd,&rc); 
					ModernSkinButton_ReposButtons(msg->hwnd, SBRF_DO_NOT_DRAW, NULL);//-=-=-=

					return 1;
				}
				ModernSkinButton_ReposButtons(msg->hwnd, SBRF_DO_ALT_DRAW, NULL);
				return 0;
			}
		case WM_SIZING:
			{

				/*RECT rcMonitor;
				Docking_GetMonitorRectFromWindow(msg->hwnd,&rcMonitor);
				Docking_AdjustPosition(msg->hwnd,&rcMonitor,(LPRECT)msg->lParam);
				*((LRESULT*)lParam)=TRUE;
				*/
				RECT rc;
				if (g_CluiData.fDocked) ModernSkinButton_ReposButtons(msg->hwnd, SBRF_DO_NOT_DRAW,NULL);
				return FALSE;
				rc=*(RECT*)(msg->lParam);
				g_CluiData.mutexPreventDockMoving=0;
				Sync(CLUIFrames_OnMoving,msg->hwnd,&rc);
				//-=-=-=		
				return TRUE;
			}
		case WM_SHOWWINDOW:
			{
				if(msg->lParam) return 0;
				BOOL toBeDocked = (BOOL) ModernGetSettingByte(NULL,"CLUI","DockToSides",SETTING_DOCKTOSIDES_DEFAULT);
				if((msg->wParam && g_CluiData.fDocked<0) || (!msg->wParam && g_CluiData.fDocked>0)) g_CluiData.fDocked=-g_CluiData.fDocked;
				ZeroMemory(&abd,sizeof(abd));
				abd.cbSize=sizeof(abd);
				abd.hWnd=msg->hwnd;
				if(msg->wParam) {
					RECT rc, rcMonitor;
					Docking_GetMonitorRectFromWindow(msg->hwnd,&rcMonitor);
					abd.lParam=0;
					abd.uCallbackMessage=WM_DOCKCALLBACK;
					SHAppBarMessage(ABM_NEW,&abd);
					GetWindowRect(msg->hwnd,&rc);
					Docking_AdjustPosition(msg->hwnd,&rcMonitor,&rc);
					MoveWindow(msg->hwnd,rc.left,rc.top,rc.right-rc.left,rc.bottom-rc.top,FALSE);
					Sync(CLUIFrames_OnMoving,msg->hwnd,&rc);
					ModernSkinButton_ReposButtons(msg->hwnd, SBRF_DO_NOT_DRAW,NULL);//-=-=-=
				}
				else {
					SHAppBarMessage(ABM_REMOVE,&abd);
				}
			}
			return 0;
		case WM_NCHITTEST:
			{	LONG result;
			result=DefWindowProc(msg->hwnd,WM_NCHITTEST,msg->wParam,msg->lParam);
			if(result==HTSIZE || result==HTTOP || result==HTTOPLEFT || result==HTTOPRIGHT ||
				result==HTBOTTOM || result==HTBOTTOMRIGHT || result==HTBOTTOMLEFT) {*((LRESULT*)lParam)=HTCLIENT; return TRUE;}
				if(g_CluiData.fDocked==DOCKED_LEFT && result==HTLEFT) {*((LRESULT*)lParam)=HTCLIENT; return TRUE;}
				if(g_CluiData.fDocked==DOCKED_RIGHT && result==HTRIGHT) {*((LRESULT*)lParam)=HTCLIENT; return TRUE;}


				return 0;
			}
		case WM_SYSCOMMAND:
			if((msg->wParam&0xFFF0)!=SC_MOVE) return 0;
			SetActiveWindow(msg->hwnd);
			SetCapture(msg->hwnd);
			draggingTitle=1;
			*((LRESULT*)lParam)=0;
			return TRUE;
		case WM_MOUSEMOVE:

			if(!draggingTitle) return 0;
			{	RECT rc;
			POINT pt;
			GetClientRect(msg->hwnd,&rc);
			if(((g_CluiData.fDocked==DOCKED_LEFT || g_CluiData.fDocked==-DOCKED_LEFT) && (short)LOWORD(msg->lParam)>rc.right) ||
				((g_CluiData.fDocked==DOCKED_RIGHT || g_CluiData.fDocked==-DOCKED_RIGHT) && (short)LOWORD(msg->lParam)<0)) {
					ReleaseCapture();
					draggingTitle=0;
					ZeroMemory(&abd,sizeof(abd));
					abd.cbSize=sizeof(abd);
					abd.hWnd=msg->hwnd;
					SHAppBarMessage(ABM_REMOVE,&abd);
					g_CluiData.fDocked=0;
					GetCursorPos(&pt);
					PostMessage(msg->hwnd,WM_NCLBUTTONDOWN,HTCAPTION,MAKELPARAM(pt.x,pt.y));
					SetWindowPos(msg->hwnd,0,pt.x-rc.right/2,pt.y-GetSystemMetrics(SM_CYFRAME)-GetSystemMetrics(SM_CYSMCAPTION)/2,ModernGetSettingDword(NULL,"CList","Width",0),ModernGetSettingDword(NULL,"CList","Height",0),SWP_NOZORDER);
					ModernWriteSettingByte(NULL,"CList","Docked",(BYTE)g_CluiData.fDocked);
					// ModernSkinButton_ReposButtons(msg->hwnd, SBRF_DO_NOT_DRAW, NULL);
				}
				return 1;
			}
		case WM_LBUTTONUP:
			if(draggingTitle) {
				ReleaseCapture();
				draggingTitle=0;
			}
			return 0;
		case WM_DOCKCALLBACK:
			switch(msg->wParam) {
		case ABN_WINDOWARRANGE:
			CLUI_ShowWindowMod(msg->hwnd,msg->lParam?SW_HIDE:SW_SHOW);
			{

				RECT rc, rcMonitor;
				Docking_GetMonitorRectFromWindow(msg->hwnd,&rcMonitor);
				GetWindowRect(msg->hwnd,&rc);
				Docking_AdjustPosition(msg->hwnd,&rcMonitor,&rc);
				Sync(CLUIFrames_OnMoving,msg->hwnd,&rc); //-=-=-=		
				ModernSkinButton_ReposButtons(msg->hwnd, SBRF_DO_NOT_DRAW, NULL);

				g_CluiData.mutexPreventDockMoving=1;
			}
			break;
			}
			return TRUE;
		case WM_DESTROY:
			if(g_CluiData.fDocked>0) {
				ZeroMemory(&abd,sizeof(abd));
				abd.cbSize=sizeof(abd);
				abd.hWnd=msg->hwnd;
				SHAppBarMessage(ABM_REMOVE,&abd);
				ModernSkinButton_ReposButtons(msg->hwnd, SBRF_DO_NOT_DRAW, NULL);
			}
			return 0;
	}
	return 0;
}
Exemplo n.º 9
0
LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	static POINT point;
	static POINT pointOld;
	static BOOL bCapture;
	static HFONT hFont;
	static TCHAR szText[1024];
	switch (msg)
	{
	case WM_CREATE:
		hFont = CreateFont(64, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, TEXT("メイリオ"));
		break;
	case WM_LBUTTONDOWN:
		if (!bCapture)
		{
			point.x = LOWORD(lParam);
			point.y = HIWORD(lParam);
			SetCapture(hWnd);
			bCapture = 1;
		}
		break;
	case WM_RBUTTONUP:
		if (bCapture)
		{
			ReleaseCapture();
			bCapture = 0;
		}
		SendMessage(hWnd, WM_CLOSE, 0, 0);
		break;
	case WM_PAINT:
	{
		PAINTSTRUCT ps;
		const HDC hdc = BeginPaint(hWnd, &ps);
		const HFONT hFontOld = (HFONT)SelectObject(hdc, hFont);
		RECT rect;
		GetClientRect(hWnd, &rect);
		DrawText(hdc, szText, -1, &rect, DT_WORDBREAK);
		SelectObject(hdc, hFontOld);
		EndPaint(hWnd, &ps);
	}
	break;
	case WM_MOUSEMOVE:
		if (bCapture)
		{
			const HDC hdc = GetDC(hWnd);
			const HPEN hPen = CreatePen(PS_SOLID, 1, RGB(255, 255, 255));
			const HPEN hPenOld = (HPEN)SelectObject(hdc, hPen);
			MoveToEx(hdc, point.x, point.y, 0);
			LineTo(hdc, pointOld.x, pointOld.y);
			SelectObject(hdc, hPenOld);
			DeleteObject(hPen);
			MoveToEx(hdc, point.x, point.y, 0);
			LineTo(hdc, LOWORD(lParam), HIWORD(lParam));
			const HFONT hFontOld = (HFONT)SelectObject(hdc, hFont);
			const double dAngle = atan2((double)(point.x - LOWORD(lParam)), (double)(point.y - HIWORD(lParam)));
			const double dDistance = sqrt((double)((point.x - LOWORD(lParam))*(point.x - LOWORD(lParam)) + (point.y - HIWORD(lParam))*(point.y - HIWORD(lParam))));
			swprintf_s(szText, 1024,
				TEXT("角度 %f 度\r\n")
				TEXT("角度 %f ラジアン\r\n")
				TEXT("距離 %f ピクセル\r\n"),
				(dAngle + PI / 2.0)*180.0 / PI,
				dAngle + PI / 2.0,
				dDistance + 1.0
				);
			RECT rect;
			GetClientRect(hWnd, &rect);
			DrawText(hdc, szText, -1, &rect, DT_WORDBREAK);
			SelectObject(hdc, hFontOld);
			ReleaseDC(hWnd, hdc);
			pointOld.x = LOWORD(lParam);
			pointOld.y = HIWORD(lParam);
		}
		break;
	case WM_LBUTTONUP:
		if (bCapture)
		{
			ReleaseCapture();
			bCapture = 0;
			InvalidateRect(hWnd, 0, 1);
		}
		break;
	case WM_KEYDOWN:
		if (wParam == VK_ESCAPE)
		{
			SendMessage(hWnd, WM_CLOSE, 0, 0);
		}
		else if (wParam == 'C')
		{
			if (GetKeyState(VK_CONTROL)<0)
			{
				const int nLen = lstrlen(szText);
				const HGLOBAL hMem = GlobalAlloc(GMEM_DDESHARE | GMEM_MOVEABLE, sizeof(TCHAR)*(nLen + 1));
				const LPTSTR lpszBuf = (LPTSTR)GlobalLock(hMem);
				lstrcpy(lpszBuf, szText);
				GlobalUnlock(hMem);
				OpenClipboard(NULL);
				EmptyClipboard();
				SetClipboardData(CF_UNICODETEXT, hMem);
				CloseClipboard();
			}
		}
		break;
	case WM_DESTROY:
		DeleteObject(hFont);
		PostQuitMessage(0);
		break;
	default:
		return DefWindowProc(hWnd, msg, wParam, lParam);
	}
	return 0;
}
Exemplo n.º 10
0
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
{
	static HWND last_focus=0;
	if(FALSE)
	//if(msg!=WM_MOUSEFIRST&&msg!=WM_NCHITTEST&&msg!=WM_SETCURSOR&&msg!=WM_ENTERIDLE&&msg!=WM_NOTIFY)
	if(msg!=WM_NCHITTEST&&msg!=WM_SETCURSOR&&msg!=WM_ENTERIDLE&&msg!=WM_MOUSEMOVE&&msg!=WM_NCMOUSEMOVE)
	{
		static DWORD tick=0;
		if((GetTickCount()-tick)>500)
			printf("--\n");
		print_msg(msg,lparam,wparam,hwnd);
		tick=GetTickCount();
	}
    switch(msg)
    {
	case WM_MENUSELECT:
		break;
	case WM_CREATE:
		{
			RECT rect={0};
			extern int keep_closed,trim_trailing,left_justify;
			get_ini_value("SETTINGS","KEEP_CLOSED",&keep_closed);
			get_ini_value("SETTINGS","TRIM_TRAILING",&trim_trailing);
			get_ini_value("SETTINGS","LEFT_JUSTIFY",&left_justify);
			load_icon(hwnd);

			load_window_size(hwnd,"MAIN_WINDOW");

			GetClientRect(hwnd,&rect);
			get_ini_value("SETTINGS","TREE_WIDTH",&tree_width);
			if(tree_width>rect.right-10 || tree_width<10){
				tree_width=rect.right/4;
				if(tree_width<12)
					tree_width=12;
			}

			ghmdiclient=create_mdiclient(hwnd,ghmenu,ghinstance);
			ghdbview=create_dbview(hwnd,ghinstance);
			ghstatusbar=CreateStatusWindow(WS_CHILD|WS_VISIBLE,"ready",hwnd,IDC_STATUS);
			create_status_bar_parts(hwnd,ghstatusbar);

			resize_main_window(hwnd,tree_width);
		}
		break;
	case WM_DROPFILES:
		process_drop(hwnd,wparam);
		break;
	case WM_COPYDATA:
		if(lparam!=0){
			COPYDATASTRUCT *cd=lparam;
			process_cmd_line(cd->lpData);
		}
		break;
	case WM_USER:
		debug_window_focus(lparam,"WM_USER");
		switch(wparam){
		case IDC_TREEVIEW:
			if(lparam!=0)
				SetFocus(lparam);
			break;
		case IDC_MDI_LISTVIEW:
			if(lparam!=0){
				last_focus=lparam;
				SetFocus(lparam);
			}
			break;
		case IDC_LV_EDIT:
			if(lparam!=0)
				last_focus=lparam;
			break;
		}
		break;
	case WM_USER+1:
		debug_window_focus(last_focus,"WMUSER+1");
		if(last_focus!=0)
			SetFocus(last_focus);
		break;
	case WM_NCACTIVATE:
		debug_window_focus(last_focus,"NCACTIVATE wparam=%08X",wparam);
		if(wparam==0){
			last_focus=GetFocus();
		}
		else{
			PostMessage(hwnd,WM_USER+1,0,0);
		}
		break;
	case WM_ACTIVATEAPP: //close any tooltip on app switch
		debug_window_focus(last_focus,"ACTIVATEAPP wparam=%08X",wparam);
		if(wparam){
			PostMessage(hwnd,WM_USER+1,0,0);
		}
		break;
	case WM_KILLFOCUS:
	case WM_RBUTTONDOWN:
	case WM_LBUTTONUP:
		if(main_drag){
			ReleaseCapture();
			main_drag=FALSE;
			write_ini_value("SETTINGS","TREE_WIDTH",tree_width);
		}
		break;
	case WM_LBUTTONDOWN:
		{
			int x=LOWORD(lparam);
			if(x>=(tree_width-10) && x<(tree_width+10)){
				SetCapture(hwnd);
				SetCursor(LoadCursor(NULL,IDC_SIZEWE));
				main_drag=TRUE;
			}
		}
		break;
	case WM_MOUSEFIRST:
		{
			int x=LOWORD(lparam);
			if(x>=(tree_width-10) && x<(tree_width+10))
				SetCursor(LoadCursor(NULL,IDC_SIZEWE));
			if(main_drag){
				RECT rect;
				GetClientRect(ghmainframe,&rect);
				if(x>10 && x<rect.right-10){
					tree_width=x;
					resize_main_window(hwnd,tree_width);
				}
			}
		}
		break;
	case WM_COMMAND:
		switch(LOWORD(wparam)){
		case IDM_OPEN:
			if((GetKeyState(VK_SHIFT)&0x8000) || GetKeyState(VK_CONTROL)&0x8000)
				task_open_db("");
			else{
				if(does_key_exist("SOFTWARE\\ODBC\\ODBC.INI\\ODBC Data Sources","Journal"))
					task_open_db("UID=dba;PWD=sql;DSN=Journal");
				else
					task_open_db("");
			}
			break;
		case IDM_CLOSE:
			{
			HANDLE hroot=0;
			if(tree_find_focused_root(&hroot)){
				char str[MAX_PATH]={0};
				tree_get_db_table(hroot,str,sizeof(str),0,0,0);
				if(str[0]!=0){
					set_status_bar_text(ghstatusbar,0,"closing %s",str);
					task_close_db(str);
				}
			}
			else
				set_status_bar_text(ghstatusbar,0,"select a DB");
			}
			break;
		case IDM_SETTINGS:
			DialogBox(ghinstance,MAKEINTRESOURCE(IDD_SETTINGS),hwnd,settings_proc);
			break;
		case IDM_RECENT:
			DialogBox(ghinstance,MAKEINTRESOURCE(IDD_RECENT),hwnd,recent_proc);
			break;
		case IDM_STOP_THREAD:
			{
				int click=MessageBox(hwnd,"Are you sure you want to terminate the task?","Warning",MB_OKCANCEL|MB_SYSTEMMODAL);
				if(click==IDOK){
					terminate_worker_thread();
					stop_thread_menu(FALSE);
				}
			}
			break;
		case IDM_QUERY:
			task_new_query();
			break;
		case IDC_EXECUTE_SQL:
			task_execute_query(NULL);
			break;
		case IDM_TILE_DIALOG:
			tile_select_dialog(hwnd);
			break;
		case IDM_WINDOW_TILE:
			mdi_tile_windows_vert();
			break;
		case IDM_WINDOW_CASCADE:
			mdi_cascade_win_vert();
			break;
		case IDM_WINDOW_LRTILE:
			mdi_tile_windows_horo();
			break;
		case IDM_REFRESH_ALL:
			refresh_all_dialog(hwnd);
			break;
		case IDM_REORDER:
			reorder_win_dialog(hwnd);
			break;
		}
		break;
	case WM_SIZE:
		resize_main_window(hwnd,tree_width);
		create_status_bar_parts(ghmainframe,ghstatusbar);
		return 0;
		break;
	case WM_QUERYENDSESSION:
		return 1; //ok to end session
		break;
	case WM_ENDSESSION:
		if(wparam){
			if(!(GetKeyState(VK_SHIFT)&0x8000))
				save_window_size(hwnd,"MAIN_WINDOW");
		}
		return 0;
	case WM_CLOSE:
        break;
	case WM_DESTROY:
		if(!(GetKeyState(VK_SHIFT)&0x8000))
			save_window_size(hwnd,"MAIN_WINDOW");
		PostQuitMessage(0);
        break;
    }
	return DefFrameProc(hwnd, ghmdiclient, msg, wparam, lparam);
}
Exemplo n.º 11
0
void DragUI( HWND hWnd, HWND hWnd1,UINT message, WPARAM wParam, LPARAM lParam,BOOL fIsCompWnd)
{
    POINT     pt;
    static    POINT ptdif,ptdif1;
    static    RECT drc,drc1;
    static    SIZE sz,sz1;
    DWORD     dwT;
	
    switch (message)
    {
	case WM_SETCURSOR:
		if ( HIWORD(lParam) == WM_LBUTTONDOWN
			|| HIWORD(lParam) == WM_RBUTTONDOWN ) 
		{
			GetCursorPos( &pt );
			SetCapture(hWnd);
			GetWindowRect(hWnd,&drc);
			ptdif.x = pt.x - drc.left;
			ptdif.y = pt.y - drc.top;
			sz.cx = drc.right - drc.left;
			sz.cy = drc.bottom - drc.top;

			if (IsWindow(hWnd1)) {
				GetWindowRect(hWnd1,&drc1);
				ptdif1.x = pt.x - drc1.left;
				ptdif1.y = pt.y - drc1.top;
				sz1.cx = drc1.right - drc1.left;
				sz1.cy = drc1.bottom - drc1.top;
			}

			SetWindowLong(hWnd,FIGWL_MOUSE,FIM_CAPUTURED);
		}
		break;
		
	case WM_MOUSEMOVE:
		dwT = GetWindowLong(hWnd,FIGWL_MOUSE);
		if (dwT & FIM_MOVED)
		{
			DrawUIBorder(&drc);
			if (IsWindow(hWnd1)) DrawUIBorder(&drc1);
			GetCursorPos( &pt );
			drc.left   = pt.x - ptdif.x;
			drc.top    = pt.y - ptdif.y;
			drc.right  = drc.left + sz.cx;
			drc.bottom = drc.top + sz.cy;
			if (IsWindow(hWnd1)) {
				drc1.left   = pt.x - ptdif1.x;
				drc1.top    = pt.y - ptdif1.y;
				drc1.right  = drc1.left + sz1.cx;
				drc1.bottom = drc1.top + sz1.cy;
			}
			DrawUIBorder(&drc);
			if (IsWindow(hWnd1)) DrawUIBorder(&drc1);
		}
		else if (dwT & FIM_CAPUTURED)
		{
			DrawUIBorder(&drc);
			if (IsWindow(hWnd1)) DrawUIBorder(&drc1);
			SetWindowLong(hWnd,FIGWL_MOUSE,dwT | FIM_MOVED);
		}
		break;
		
	case WM_LBUTTONUP:
	case WM_RBUTTONUP:
		dwT = GetWindowLong(hWnd,FIGWL_MOUSE);
		
		if (dwT & FIM_CAPUTURED)
		{
			ReleaseCapture();
			if (dwT & FIM_MOVED)
			{
				DrawUIBorder(&drc);
				if (IsWindow(hWnd1)) DrawUIBorder(&drc1);
				GetCursorPos( &pt );
				MoveWindow(hWnd,pt.x - ptdif.x,
					pt.y - ptdif.y,
					sz.cx,
					sz.cy,TRUE);

				if(fIsCompWnd) {
					HWND hUIWnd;
					LPARAM mylParam;

					*((LPWORD)(&mylParam)) = (WORD)(pt.x - ptdif.x);
					*((LPWORD)(&mylParam)+1) = (WORD)(pt.y - ptdif.y);

					hUIWnd = (HWND)GetWindowLong(hWnd,FIGWL_SVRWND);
					if (IsWindow(hUIWnd))
						SendMessage(hUIWnd,WM_UI_COMPMOVE,0,mylParam);
				}

				if (IsWindow(hWnd1)) {
					MoveWindow(hWnd1,pt.x - ptdif1.x,
						pt.y - ptdif1.y,
						sz1.cx,
						sz1.cy,TRUE);
				}
			}
		}
		break;
    }
}
Exemplo n.º 12
0
static LRESULT
PAGER_MouseMove (PAGER_INFO* infoPtr, INT keys, INT x, INT y)
{
    POINT clpt, pt;
    RECT wnrect;
    BOOL topLeft = FALSE;
    INT btnstate = 0;
    INT hit;
    HDC hdc;

    pt.x = x;
    pt.y = y;

    TRACE("[%p] to (%d,%d)\n", infoPtr->hwndSelf, x, y);
    ClientToScreen(infoPtr->hwndSelf, &pt);
    GetWindowRect(infoPtr->hwndSelf, &wnrect);
    if (PtInRect(&wnrect, pt)) {
	RECT topleft, bottomright, *rect = NULL;

	PAGER_GetButtonRects(infoPtr, &topleft, &bottomright, FALSE);

	clpt = pt;
	MapWindowPoints(0, infoPtr->hwndSelf, &clpt, 1);
	hit = PAGER_HitTest(infoPtr, &clpt);
	if ((hit == PGB_TOPORLEFT) && (infoPtr->TLbtnState == PGF_NORMAL))
	{
	    topLeft = TRUE;
	    rect = &topleft;
	    infoPtr->TLbtnState = PGF_HOT;
	    btnstate = infoPtr->TLbtnState;
	}
	else if ((hit == PGB_BOTTOMORRIGHT) && (infoPtr->BRbtnState == PGF_NORMAL))
	{
	    topLeft = FALSE;
	    rect = &bottomright;
	    infoPtr->BRbtnState = PGF_HOT;
	    btnstate = infoPtr->BRbtnState;
	}

	/* If in one of the buttons the capture and draw buttons */
	if (rect)
	{
            TRACE("[%p] draw btn (%s), Capture %s, style %08x\n",
                  infoPtr->hwndSelf, wine_dbgstr_rect(rect),
		  (infoPtr->bCapture) ? "TRUE" : "FALSE",
		  infoPtr->dwStyle);
	    if (!infoPtr->bCapture)
	    {
	        TRACE("[%p] SetCapture\n", infoPtr->hwndSelf);
	        SetCapture(infoPtr->hwndSelf);
	        infoPtr->bCapture = TRUE;
	    }
	    if (infoPtr->dwStyle & PGS_AUTOSCROLL)
		SetTimer(infoPtr->hwndSelf, TIMERID1, 0x3e, 0);
	    hdc = GetWindowDC(infoPtr->hwndSelf);
	    /* OffsetRect(wnrect, 0 | 1, 0 | 1) */
	    PAGER_DrawButton(hdc, infoPtr->clrBk, *rect,
			     infoPtr->dwStyle & PGS_HORZ, topLeft, btnstate);
	    ReleaseDC(infoPtr->hwndSelf, hdc);
	    return 0;
	}
    }

    /* If we think we are captured, then do release */
    if (infoPtr->bCapture && (WindowFromPoint(pt) != infoPtr->hwndSelf))
    {
    	NMHDR nmhdr;

        infoPtr->bCapture = FALSE;

        if (GetCapture() == infoPtr->hwndSelf)
        {
            ReleaseCapture();

            if (infoPtr->TLbtnState == PGF_GRAYED)
            {
                infoPtr->TLbtnState = PGF_INVISIBLE;
                SetWindowPos(infoPtr->hwndSelf, 0, 0, 0, 0, 0,
                             SWP_FRAMECHANGED | SWP_NOSIZE | SWP_NOMOVE |
                             SWP_NOZORDER | SWP_NOACTIVATE);
            }
            else if (infoPtr->TLbtnState == PGF_HOT)
            {
        	infoPtr->TLbtnState = PGF_NORMAL;
        	/* FIXME: just invalidate button rect */
                RedrawWindow(infoPtr->hwndSelf, NULL, NULL, RDW_FRAME | RDW_INVALIDATE);
            }

            if (infoPtr->BRbtnState == PGF_GRAYED)
            {
                infoPtr->BRbtnState = PGF_INVISIBLE;
                SetWindowPos(infoPtr->hwndSelf, 0, 0, 0, 0, 0,
                             SWP_FRAMECHANGED | SWP_NOSIZE | SWP_NOMOVE |
                             SWP_NOZORDER | SWP_NOACTIVATE);
            }
            else if (infoPtr->BRbtnState == PGF_HOT)
            {
        	infoPtr->BRbtnState = PGF_NORMAL;
        	/* FIXME: just invalidate button rect */
                RedrawWindow(infoPtr->hwndSelf, NULL, NULL, RDW_FRAME | RDW_INVALIDATE);
            }

            /* Notify parent of released mouse capture */
        	memset(&nmhdr, 0, sizeof(NMHDR));
        	nmhdr.hwndFrom = infoPtr->hwndSelf;
        	nmhdr.idFrom   = GetWindowLongPtrW(infoPtr->hwndSelf, GWLP_ID);
        	nmhdr.code = NM_RELEASEDCAPTURE;
		SendMessageW(infoPtr->hwndNotify, WM_NOTIFY, nmhdr.idFrom, (LPARAM)&nmhdr);
        }
        if (IsWindow(infoPtr->hwndSelf))
            KillTimer(infoPtr->hwndSelf, TIMERID1);
    }
    return 0;
}
Exemplo n.º 13
0
LONG WINAPI FaderWndProc( HWND hWnd, UINT iMessage, WPARAM wParam, LPARAM lParam )
/////////////////////////////////////////////////////////////////////////////
{
	PAINTSTRUCT	ps;
	PFADERINFO	pFI			= (PFADERINFO)GetWindowLong( hWnd, GWL_USERDATA );
	HWND		hParentWnd	= GetParent( hWnd );
	
	switch( iMessage ) 
	{
	case WM_GETDLGCODE:
		return( DLGC_WANTARROWS );

	case WM_SETFOCUS:
		if( pFI )
		{
			CreateCaret( hWnd, (HBITMAP)1, pFI->bmFader.bmWidth - 5, pFI->bmFader.bmHeight - CARET_OFFSET );
			SetCaretPos( pFI->nBitmapX + 2, pFI->nBitmapPos + (CARET_OFFSET/2) );
			ShowCaret( hWnd );
			pFI->bHasFocus = TRUE;
		}
		break;
		
	case WM_KILLFOCUS:
		if( pFI )
			pFI->bHasFocus = FALSE;
		HideCaret( hWnd );
		DestroyCaret();
		break;
		
	case WM_APPCOMMAND:
		switch( GET_APPCOMMAND_LPARAM(lParam) )
		{
		case APPCOMMAND_VOLUME_MUTE:
			PostMessage( hParentWnd, WM_VSCROLL, (WPARAM)SB_BOTTOM, (LPARAM)hWnd );
			return( TRUE );
		case APPCOMMAND_VOLUME_UP:
			PostMessage( hParentWnd, WM_VSCROLL, (WPARAM)SB_LINEUP, (LPARAM)hWnd );
			return( TRUE );
		case APPCOMMAND_VOLUME_DOWN:
			PostMessage( hParentWnd, WM_VSCROLL, (WPARAM)SB_LINEDOWN, (LPARAM)hWnd );
			return( TRUE );
		default:
			return( DefWindowProc( hWnd, iMessage, wParam, lParam ) );
		}
		break;

	case WM_KEYDOWN:		/* Keyboard Interface for Fader */
		switch( wParam ) 
		{
		case VK_TAB:
			// pass this on to the parent
			//PostMessage( hParentWnd, iMessage, wParam, lParam );
			break;

		case VK_RIGHT:
		case VK_DOWN:
			PostMessage( hParentWnd, WM_VSCROLL, (WPARAM)SB_LINEDOWN, (LPARAM)hWnd );
			break;
			
		case VK_LEFT:
		case VK_UP:
			PostMessage( hParentWnd, WM_VSCROLL, (WPARAM)SB_LINEUP, (LPARAM)hWnd );
			break;
			
		case VK_PRIOR:
			PostMessage( hParentWnd, WM_VSCROLL, (WPARAM)SB_PAGEUP, (LPARAM)hWnd );
			break;
			
		case VK_NEXT:
			PostMessage( hParentWnd, WM_VSCROLL, (WPARAM)SB_PAGEDOWN, (LPARAM)hWnd );
			break;
			
		case VK_HOME:
			PostMessage( hParentWnd, WM_VSCROLL, (WPARAM)SB_TOP, (LPARAM)hWnd );
			break;
			
		case VK_END:
			PostMessage( hParentWnd, WM_VSCROLL, (WPARAM)SB_BOTTOM, (LPARAM)hWnd );
			break;
			
		}
		break;
		
	case WM_LBUTTONUP:
		ReleaseCapture();
		if( pFI )
		{
			// we know this control has the focus
			SetCaretPos( pFI->nBitmapX + 2, pFI->nBitmapPos + (CARET_OFFSET/2) );
			ShowCaret( hWnd );
			pFI->bMouseDown = FALSE;
		}
		break;
		
	case WM_LBUTTONDOWN:
		SetFocus( hWnd );
		SetCapture( hWnd );
		HideCaret( hWnd );
		if( pFI )
		{
			pFI->bMouseDown = TRUE;		/* Fall Through */
		}
		
	case WM_MOUSEMOVE:
		//fwKeys = wParam;        // key flags 
		//xPos = LOWORD(lParam);  // horizontal position of cursor 
		//yPos = HIWORD(lParam);  // vertical position of cursor (zero at the top)

		if( pFI )
		{
			if( pFI->bMouseDown )
			{
				short	X = LOWORD( lParam );
				short	Y = HIWORD( lParam );
				WORD	wPos;
				int		nScale = pFI->nWindowY - pFI->bmFader.bmHeight;

				// make sure we don't go out of bounds
				if( Y > (pFI->nWindowY - (pFI->bmFader.bmHeight/2)) )
					Y = (pFI->nWindowY - (pFI->bmFader.bmHeight/2));
				
				if( Y < (pFI->bmFader.bmHeight/2) )
					Y = (pFI->bmFader.bmHeight/2);

				Y	-= (pFI->bmFader.bmHeight/2);

				if( Y > nScale )
					Y = nScale;

				wPos = pFI->nMax - (((int)Y * pFI->nMax) / nScale);

				PostMessage( hParentWnd, WM_VSCROLL, MAKELONG( SB_THUMBTRACK, wPos ), (LPARAM)hWnd );
			}
		}
		break;

	case WM_MOUSEWHEEL:
		{
		short	fwKeys = LOWORD( wParam );
		short	nZDelta = HIWORD( wParam );
		short	nX = LOWORD( lParam );
		short	nY = HIWORD( lParam );
		POINT	Point;
		HWND	hParent;
//		long	CntlID;

		// what window is the mouse currently above?

		Point.x = nX;
		Point.y = nY;

		hWnd = WindowFromPoint( Point );

		hParent = GetParent( hWnd );

		// if the parent of this window is not our parent, we are done
		if( hParent != hParentWnd )
			return( 0L );
		
		// is this one of our fader windows?
/***********
		CntlID = GetWindowLong( hWnd, GWL_ID );
		switch( CntlID )
		{
		case IDC_OUT1_VOLUME:
		case IDC_OUT2_VOLUME:
		case IDC_OUT3_VOLUME:
		case IDC_OUT4_VOLUME:
			break;
		default:
			return( 0L );
		}
***********/

		SetFocus( hWnd );
		HideCaret( hWnd );

		//sprintf( szBuffer, "fwKeys [%d] nZ [%d] nX [%d] nY [%d]", fwKeys, nZDelta, nX, nY );
		//SetDlgItemText( GetParent( hWnd ), IDC_STATUS, szBuffer );

		if( nZDelta > 0 )
			PostMessage( hParentWnd, WM_VSCROLL, (WPARAM)SB_LINEUP, (LPARAM)hWnd );
		else
			PostMessage( hParentWnd, WM_VSCROLL, (WPARAM)SB_LINEDOWN, (LPARAM)hWnd );
		}
		break;
		
	case WM_SIZE:
		if( pFI )
		{
			pFI->nWindowX = LOWORD( lParam );
			pFI->nWindowY = HIWORD( lParam );
			// Place the Knob at the top of the control
			pFI->nBitmapPos = pFI->nWindowY - pFI->bmFader.bmHeight - 2;
			pFI->nBitmapX = (pFI->nWindowX / 2) - (pFI->bmFader.bmWidth / 2);
		}
		break;
		
	case WM_CREATE:
		pFI = (PFADERINFO)malloc( sizeof( FADERINFO ) );
		SetWindowLong( hWnd, GWL_USERDATA, (DWORD)pFI );
		if( !pFI )
		{
			MessageBox( NULL, TEXT("Fader: malloc failed!"), TEXT("LynxONE Mixer"), MB_OK | MB_ICONSTOP | MB_TASKMODAL );
			break;
		}
		ZeroMemory( pFI, sizeof( FADERINFO ) );
		pFI->hFader = LoadBitmap( AfxGetInstanceHandle(), MAKEINTRESOURCE( IDB_FADER ) );
		pFI->hGradient = LoadBitmap( AfxGetInstanceHandle(), MAKEINTRESOURCE( IDB_GRADIENT ) );
		GetObject( pFI->hFader, sizeof( BITMAP ), (LPSTR)&pFI->bmFader );
		GetObject( pFI->hGradient, sizeof( BITMAP ), (LPSTR)&pFI->bmGradient );
		break;
		
	case WM_DESTROY:
		if( pFI )
		{
			DeleteObject( pFI->hFader );
			DeleteObject( pFI->hGradient );
			free( pFI );
		}
		SetWindowLong( hWnd, GWL_USERDATA, (DWORD)0 );
		break;
		
	case WM_PAINT:
		BeginPaint( hWnd, (LPPAINTSTRUCT)&ps );
		if( pFI )
			PaintControl( ps.hdc, pFI );
		EndPaint( hWnd, (LPPAINTSTRUCT)&ps );
		break;
		
	default:
		return( DefWindowProc( hWnd, iMessage, wParam, lParam ) );
	}
	return( 0L );
}
// callback function for the splitter window.
LRESULT	CALLBACK 
FrameWindowSplitter::WndProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam)
{
   // Get a pointer to the window class object.
    FrameWindowSplitter	*pFrameWindowSplitter = (FrameWindowSplitter *)GetWindowLongPtr(hwnd, GWLP_USERDATA);

	switch(message)
	{
    case WM_NCCREATE:
        // Get the initial creation pointer to the window object
		pFrameWindowSplitter = (FrameWindowSplitter *)((CREATESTRUCT *)lparam)->lpCreateParams;        
		pFrameWindowSplitter->m_hwnd = hwnd;
		SetWindowLongPtr(hwnd, GWLP_USERDATA,(LONG_PTR)pFrameWindowSplitter);
        break;

	case WM_PAINT:
		return pFrameWindowSplitter->OnPaint();
		
	case WM_MOUSEMOVE:
		pFrameWindowSplitter->MouseMove();
		return 0;

	case WM_LBUTTONDOWN:
		{
			MDIWindow * pcquerywnd = (MDIWindow*)GetWindowLongPtr(pFrameWindowSplitter->m_hwndparent, GWLP_USERDATA);
			if(pcquerywnd->m_isobjbrowvis == wyFalse)
				break;
			else
			{
                pFrameWindowSplitter->m_prevstyle = GetWindowLongPtr(pFrameWindowSplitter->m_hwndparent, GWL_STYLE);
                SetWindowLongPtr(pFrameWindowSplitter->m_hwndparent, GWL_STYLE, pFrameWindowSplitter->m_prevstyle & ~WS_CLIPCHILDREN);
                pFrameWindowSplitter->m_hwndprevfocus = GetFocus();
                SetFocus(hwnd);
				SetCapture(hwnd);

				/*	starting from v4.2 BETA we stop the repaining of the two custom tab controls 
					so that flicker does not happen */
				pFrameWindowSplitter->m_isdragged	= wyTrue;
                pFrameWindowSplitter->MouseMove(wyTrue);
			}
		}
		break;
		
	case WM_LBUTTONUP:
		ReleaseCapture();
		break;

	case WM_CAPTURECHANGED:
		if(pFrameWindowSplitter->m_isdragged)
		{
            SetWindowLongPtr(pFrameWindowSplitter->m_hwndparent, GWL_STYLE, pFrameWindowSplitter->m_prevstyle);
            pFrameWindowSplitter->EndDrag(wyTrue);
			pFrameWindowSplitter->Resizeall();
			InvalidateRect(hwnd, NULL, TRUE);
			UpdateWindow(hwnd);
			pFrameWindowSplitter->m_isdragged = wyFalse;

            if(pFrameWindowSplitter->m_hwndprevfocus)
            {
                SetFocus(pFrameWindowSplitter->m_hwndprevfocus);
                pFrameWindowSplitter->m_hwndprevfocus = NULL;
            }
		}
		break;
	}

	return(DefWindowProc(hwnd, message, wparam, lparam));
}
Exemplo n.º 15
0
bool
ListControl::OnMouseDown(PixelScalar x, PixelScalar y)
{
  // End any previous drag
  scroll_bar.DragEnd(this);
  drag_end();

  kinetic_timer.Cancel();

  RasterPoint Pos;
  Pos.x = x;
  Pos.y = y;

  // If possible -> Give focus to the Control
  const bool had_focus = !HasCursorKeys() || HasFocus();
  if (!had_focus)
    SetFocus();

  if (scroll_bar.IsInsideSlider(Pos)) {
    // if click is on scrollbar handle
    // -> start mouse drag
    scroll_bar.DragBegin(this, Pos.y);
  } else if (scroll_bar.IsInside(Pos)) {
    // if click in scroll bar up/down/pgup/pgdn
    if (scroll_bar.IsInsideUpArrow(Pos.y))
      // up
      MoveOrigin(-1);
    else if (scroll_bar.IsInsideDownArrow(Pos.y))
      // down
      MoveOrigin(1);
    else if (scroll_bar.IsAboveSlider(Pos.y))
      // page up
      MoveOrigin(-(int)items_visible);
    else if (scroll_bar.IsBelowSlider(Pos.y))
      // page down
      MoveOrigin(items_visible);
  } else {
    // if click in ListBox area
    // -> select appropriate item

    int index = ItemIndexAt(y);
    // If mouse was clicked outside the list items -> cancel
    if (index < 0)
      return false;

    drag_y = GetPixelOrigin() + y;
    drag_y_window = y;

    if (had_focus && (unsigned)index == GetCursorIndex() &&
        CanActivateItem()) {
      drag_mode = DragMode::CURSOR;
      Invalidate_item(cursor);
    } else {
      // If item was not selected before
      // -> select it
      SetCursorIndex(index);
      drag_mode = DragMode::SCROLL;
    }
    if (UsePixelPan())
      kinetic.MouseDown(GetPixelOrigin());
    SetCapture();
  }

  return true;
}
Exemplo n.º 16
0
HRESULT APIENTRY WindowProc(HWND hWnd, UINT uMsg, WPARAM wPrm, LPARAM lPrm) {
    static const uint8_t keys[256] = {
        KEY_NONE      , KEY_LMB       , KEY_RMB       , KEY_NONE      ,
        KEY_MMB       , KEY_NONE      , KEY_NONE      , KEY_NONE      ,
        KEY_BACKSPACE , KEY_TAB       , KEY_NONE      , KEY_NONE      ,
        KEY_NONE      , KEY_ENTER     , KEY_NONE      , KEY_NONE      ,
        KEY_NONE      , KEY_NONE      , KEY_NONE      , KEY_PAUSE     ,
        KEY_CAPSLOCK  , KEY_NONE      , KEY_NONE      , KEY_NONE      ,
        KEY_NONE      , KEY_NONE      , KEY_NONE      , KEY_ESC       ,
        KEY_NONE      , KEY_NONE      , KEY_NONE      , KEY_NONE      ,
        KEY_SPACE     , KEY_PAGEUP    , KEY_PAGEDOWN  , KEY_END       ,
        KEY_HOME      , KEY_LEFT      , KEY_UP        , KEY_RIGHT     ,
        KEY_DOWN      , KEY_NONE      , KEY_NONE      , KEY_NONE      ,
        KEY_PRTSCR    , KEY_INSERT    , KEY_DELETE    , KEY_NONE      ,
        KEY_0         , KEY_1         , KEY_2         , KEY_3         ,
        KEY_4         , KEY_5         , KEY_6         , KEY_7         ,
        KEY_8         , KEY_9         , KEY_NONE      , KEY_NONE      ,
        KEY_NONE      , KEY_NONE      , KEY_NONE      , KEY_NONE      ,
        KEY_NONE      , KEY_A         , KEY_B         , KEY_C         ,
        KEY_D         , KEY_E         , KEY_F         , KEY_G         ,
        KEY_H         , KEY_I         , KEY_J         , KEY_K         ,
        KEY_L         , KEY_M         , KEY_N         , KEY_O         ,
        KEY_P         , KEY_Q         , KEY_R         , KEY_S         ,
        KEY_T         , KEY_U         , KEY_V         , KEY_W         ,
        KEY_X         , KEY_Y         , KEY_Z         , KEY_LSYSTEM   ,
        KEY_RSYSTEM   , KEY_RMENU     , KEY_NONE      , KEY_NONE      ,
        KEY_NUM_0     , KEY_NUM_1     , KEY_NUM_2     , KEY_NUM_3     ,
        KEY_NUM_4     , KEY_NUM_5     , KEY_NUM_6     , KEY_NUM_7     ,
        KEY_NUM_8     , KEY_NUM_9     , KEY_NUM_MUL   , KEY_NUM_ADD   ,
        KEY_NUM_ENTER , KEY_NUM_SUB   , KEY_NUM_DEL   , KEY_NUM_DIV   ,
        KEY_F1        , KEY_F2        , KEY_F3        , KEY_F4        ,
        KEY_F5        , KEY_F6        , KEY_F7        , KEY_F8        ,
        KEY_F9        , KEY_F10       , KEY_F11       , KEY_F12       ,
        KEY_NONE      , KEY_NONE      , KEY_NONE      , KEY_NONE      ,
        KEY_NONE      , KEY_NONE      , KEY_NONE      , KEY_NONE      ,
        KEY_NONE      , KEY_NONE      , KEY_NONE      , KEY_NONE      ,
        KEY_NONE      , KEY_NONE      , KEY_NONE      , KEY_NONE      ,
        KEY_NONE      , KEY_NONE      , KEY_NONE      , KEY_NONE      ,
        KEY_NUM_LOCK  , KEY_SCRLOCK   , KEY_NONE      , KEY_NONE      ,
        KEY_NONE      , KEY_NONE      , KEY_NONE      , KEY_NONE      ,
        KEY_NONE      , KEY_NONE      , KEY_NONE      , KEY_NONE      ,
        KEY_NONE      , KEY_NONE      , KEY_NONE      , KEY_NONE      ,
        KEY_LSHIFT    , KEY_RSHIFT    , KEY_LCTRL     , KEY_RCTRL     ,
        KEY_LALT      , KEY_RALT      , KEY_NONE      , KEY_NONE      ,
        KEY_NONE      , KEY_NONE      , KEY_NONE      , KEY_NONE      ,
        KEY_NONE      , KEY_NONE      , KEY_NONE      , KEY_NONE      ,
        KEY_NONE      , KEY_NONE      , KEY_NONE      , KEY_NONE      ,
        KEY_NONE      , KEY_NONE      , KEY_NONE      , KEY_NONE      ,
        KEY_NONE      , KEY_NONE      , KEY_COLON     , KEY_EQUALS    ,
        KEY_LESS      , KEY_HYPHEN    , KEY_GREATER   , KEY_QUESTION  ,
        KEY_TILDE     , KEY_NONE      , KEY_NONE      , KEY_NONE      ,
        KEY_NONE      , KEY_NONE      , KEY_NONE      , KEY_NONE      ,
        KEY_NONE      , KEY_NONE      , KEY_NONE      , KEY_NONE      ,
        KEY_NONE      , KEY_NONE      , KEY_NONE      , KEY_NONE      ,
        KEY_NONE      , KEY_NONE      , KEY_NONE      , KEY_NONE      ,
        KEY_NONE      , KEY_NONE      , KEY_NONE      , KEY_NONE      ,
        KEY_NONE      , KEY_NONE      , KEY_NONE      , KEY_LBRACKET  ,
        KEY_PIPE      , KEY_RBRACKET  , KEY_QUOTE     , KEY_NONE      ,
        /** only KEY_NONE`s here... **/
    };
    INPUT vkey;
    POINT movp;

    switch (uMsg) {
        case WM_CREATE:
            SetWindowLongPtr(hWnd, GWLP_USERDATA, 0);
            return 0;

        case WM_HOTKEY:
            /** Emulate a PrtScr, since we`ve captured it, and now
                the system redirects all PrtScr keystrokes to us.
                This is indeed ugly, but it`s how Windows works... **/
            UnregisterHotKey(hWnd, IDHOT_SNAPWINDOW);
            UnregisterHotKey(hWnd, IDHOT_SNAPDESKTOP);
            vkey = (INPUT){INPUT_KEYBOARD};
            vkey.ki.wVk = VK_SNAPSHOT;
            SendInput(1, &vkey, sizeof(INPUT));
            RegisterHotKey(hWnd, IDHOT_SNAPDESKTOP, 0, VK_SNAPSHOT);
            RegisterHotKey(hWnd, IDHOT_SNAPWINDOW, 0, VK_SNAPSHOT);
            if (GetActiveWindow() != hWnd)
                break;
            wPrm = VK_SNAPSHOT;
        case WM_SYSKEYDOWN:
            uMsg = WM_KEYDOWN;
        case WM_SYSKEYUP:
        case WM_KEYDOWN:
        case WM_KEYUP:
            switch (wPrm) {
                case VK_SHIFT: /** [ MAPVK_VSC_TO_VK_EX ]-----v **/
                    wPrm = MapVirtualKey((lPrm >> 16) & 0xFF, 3); break;
                #define WIN_MKEY(a, b) wPrm = (lPrm & 0x01000000)? a : b
                case VK_MENU:    WIN_MKEY(VK_RMENU,     VK_LMENU);    break;
                case VK_CONTROL: WIN_MKEY(VK_RCONTROL,  VK_LCONTROL); break;
                case VK_RETURN:  WIN_MKEY(VK_SEPARATOR, VK_RETURN);   break;
                case VK_DELETE:  WIN_MKEY(VK_DELETE,    VK_DECIMAL);  break;
                case VK_INSERT:  WIN_MKEY(VK_INSERT,    VK_NUMPAD0);  break;
                case VK_END:     WIN_MKEY(VK_END,       VK_NUMPAD1);  break;
                case VK_DOWN:    WIN_MKEY(VK_DOWN,      VK_NUMPAD2);  break;
                case VK_NEXT:    WIN_MKEY(VK_NEXT,      VK_NUMPAD3);  break;
                case VK_LEFT:    WIN_MKEY(VK_LEFT,      VK_NUMPAD4);  break;
                case VK_CLEAR:   WIN_MKEY(VK_NUMPAD5,   VK_NUMPAD5);  break;
                case VK_RIGHT:   WIN_MKEY(VK_RIGHT,     VK_NUMPAD6);  break;
                case VK_HOME:    WIN_MKEY(VK_HOME,      VK_NUMPAD7);  break;
                case VK_UP:      WIN_MKEY(VK_UP,        VK_NUMPAD8);  break;
                case VK_PRIOR:   WIN_MKEY(VK_PRIOR,     VK_NUMPAD9);  break;
                #undef WIN_MKEY
            }
            cKbdInput((ENGC*)GetWindowLongPtr(hWnd, GWLP_USERDATA),
                       keys[wPrm & 0xFF], (uMsg == WM_KEYDOWN)? TRUE : FALSE);
            return 0;

        case WM_LBUTTONUP:
        case WM_MBUTTONUP:
        case WM_RBUTTONUP:
        case WM_LBUTTONDOWN:
        case WM_MBUTTONDOWN:
        case WM_RBUTTONDOWN:
            if ((uMsg == WM_LBUTTONDOWN)
            ||  (uMsg == WM_MBUTTONDOWN)
            ||  (uMsg == WM_RBUTTONDOWN))
                SetCapture(hWnd);
            else
                ReleaseCapture();
            GetCursorPos(&movp);
            ScreenToClient(hWnd, &movp);
            cMouseInput((ENGC*)GetWindowLongPtr(hWnd, GWLP_USERDATA), movp.x,
                         movp.y, ((uMsg == WM_LBUTTONDOWN)? 1 << 1 : 0) |
                                 ((uMsg == WM_MBUTTONDOWN)? 1 << 2 : 0) |
                                 ((uMsg == WM_RBUTTONDOWN)? 1 << 3 : 0));
            return 0;

        case WM_MOUSEMOVE:
            GetCursorPos(&movp);
            ScreenToClient(hWnd, &movp);
            cMouseInput((ENGC*)GetWindowLongPtr(hWnd, GWLP_USERDATA), movp.x,
                         movp.y, ((wPrm & MK_LBUTTON)? 2 : 0) |
                                 ((wPrm & MK_MBUTTON)? 4 : 0) |
                                 ((wPrm & MK_RBUTTON)? 8 : 0) | 1);
            return 0;

        case WM_SIZE: {
            ENGC *engc = (ENGC*)GetWindowLongPtr(hWnd, GWLP_USERDATA);

            if (engc && (wPrm != SIZE_MINIMIZED))
                cResizeWindow(engc, LOWORD(lPrm), HIWORD(lPrm));
            return 0;
        }
        case WM_CLOSE:
            PostQuitMessage(0);
            return 0;
    }
    return DefWindowProc(hWnd, uMsg, wPrm, lPrm);
}
Exemplo n.º 17
0
LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    static BOOL  fBlocking, fValidBox ;
    static POINT ptBeg, ptEnd, ptBoxBeg, ptBoxEnd ;
    HDC          hdc ;
    PAINTSTRUCT  ps ;

    switch (message)
    {
    case WM_LBUTTONDOWN :
        ptBeg.x = ptEnd.x = LOWORD (lParam) ;
        ptBeg.y = ptEnd.y = HIWORD (lParam) ;

        DrawBoxOutline (hwnd, ptBeg, ptEnd) ;

        SetCapture (hwnd) ;
        SetCursor (LoadCursor (NULL, IDC_CROSS)) ;

        fBlocking = TRUE ;
        return 0 ;

    case WM_MOUSEMOVE :
        if (fBlocking)
        {
            SetCursor (LoadCursor (NULL, IDC_CROSS)) ;

            DrawBoxOutline (hwnd, ptBeg, ptEnd) ;

            ptEnd.x = LOWORD (lParam) ;
            ptEnd.y = HIWORD (lParam) ;

            DrawBoxOutline (hwnd, ptBeg, ptEnd) ;
        }
        return 0 ;

    case WM_LBUTTONUP :
        if (fBlocking)
        {
            DrawBoxOutline (hwnd, ptBeg, ptEnd) ;

            ptBoxBeg   = ptBeg ;
            ptBoxEnd.x = LOWORD (lParam) ;
            ptBoxEnd.y = HIWORD (lParam) ;

            ReleaseCapture () ;
            SetCursor (LoadCursor (NULL, IDC_ARROW)) ;

            fBlocking = FALSE ;
            fValidBox  = TRUE ;

            InvalidateRect (hwnd, NULL, TRUE) ;
        }
        return 0 ;

    case WM_CHAR :
        if (fBlocking & (wParam == '\x1B'))     // i.e., Escape
        {
            DrawBoxOutline (hwnd, ptBeg, ptEnd) ;

            ReleaseCapture () ;
            SetCursor (LoadCursor (NULL, IDC_ARROW)) ;

            fBlocking = FALSE ;
        }
        return 0 ;

    case WM_PAINT :
        hdc = BeginPaint (hwnd, &ps) ;

        if (fValidBox)
        {
            SelectObject (hdc, GetStockObject (BLACK_BRUSH)) ;
            Rectangle (hdc, ptBoxBeg.x, ptBoxBeg.y,
                       ptBoxEnd.x, ptBoxEnd.y) ;
        }

        if (fBlocking)
        {
            SetROP2 (hdc, R2_NOT) ;
            SelectObject (hdc, GetStockObject (NULL_BRUSH)) ;
            Rectangle (hdc, ptBeg.x, ptBeg.y, ptEnd.x, ptEnd.y) ;
        }

        EndPaint (hwnd, &ps) ;
        return 0 ;

    case WM_DESTROY :
        PostQuitMessage (0) ;
        return 0 ;
    }
    return DefWindowProc (hwnd, message, wParam, lParam) ;
}
Exemplo n.º 18
0
	LRESULT CALLBACK DisplayProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) {
		static bool firstErase = true;

		switch (message) {
		case WM_ACTIVATE:
			if (wParam == WA_ACTIVE || wParam == WA_CLICKACTIVE) {
				g_activeWindow = WINDOW_MAINWINDOW;
			}
			break;

		case WM_SIZE:
			break;

		case WM_SETFOCUS:
			break;

		case WM_ERASEBKGND:
			if (firstErase) {
				firstErase = false;
				// Paint black on first erase while OpenGL stuff is loading
				return DefWindowProc(hWnd, message, wParam, lParam);
			}
			// Then never erase, let the OpenGL drawing take care of everything.
			return 1;

		// Poor man's touch - mouse input. We send the data  asynchronous touch events for minimal latency.
		case WM_LBUTTONDOWN:
			if (!touchHandler.hasTouch() ||
				(GetMessageExtraInfo() & MOUSEEVENTF_MASK_PLUS_PENTOUCH) != MOUSEEVENTF_FROMTOUCH_NOPEN)
			{
				// Hack: Take the opportunity to show the cursor.
				mouseButtonDown = true;

				float x = GET_X_LPARAM(lParam) * g_dpi_scale_x;
				float y = GET_Y_LPARAM(lParam) * g_dpi_scale_y;
				WindowsRawInput::SetMousePos(x, y);

				TouchInput touch;
				touch.id = 0;
				touch.flags = TOUCH_DOWN;
				touch.x = x;
				touch.y = y;
				NativeTouch(touch);
				SetCapture(hWnd);

				// Simulate doubleclick, doesn't work with RawInput enabled
				static double lastMouseDown;
				double now = real_time_now();
				if ((now - lastMouseDown) < 0.001 * GetDoubleClickTime()) {
					if (!g_Config.bShowTouchControls && !g_Config.bMouseControl && GetUIState() == UISTATE_INGAME && g_Config.bFullscreenOnDoubleclick) {
						SendToggleFullscreen(!g_Config.bFullScreen);
					}
					lastMouseDown = 0.0;
				} else {
					lastMouseDown = real_time_now();
				}
			}
			break;

		case WM_MOUSEMOVE:
			if (!touchHandler.hasTouch() ||
				(GetMessageExtraInfo() & MOUSEEVENTF_MASK_PLUS_PENTOUCH) != MOUSEEVENTF_FROMTOUCH_NOPEN)
			{
				// Hack: Take the opportunity to show the cursor.
				mouseButtonDown = (wParam & MK_LBUTTON) != 0;
				int cursorX = GET_X_LPARAM(lParam);
				int cursorY = GET_Y_LPARAM(lParam);
				if (abs(cursorX - prevCursorX) > 1 || abs(cursorY - prevCursorY) > 1) {
					hideCursor = false;
					SetTimer(hwndMain, TIMER_CURSORMOVEUPDATE, CURSORUPDATE_MOVE_TIMESPAN_MS, 0);
				}
				prevCursorX = cursorX;
				prevCursorY = cursorY;

				float x = (float)cursorX * g_dpi_scale_x;
				float y = (float)cursorY * g_dpi_scale_y;
				WindowsRawInput::SetMousePos(x, y);

				if (wParam & MK_LBUTTON) {
					TouchInput touch;
					touch.id = 0;
					touch.flags = TOUCH_MOVE;
					touch.x = x;
					touch.y = y;
					NativeTouch(touch);
				}
			}
			break;

		case WM_LBUTTONUP:
			if (!touchHandler.hasTouch() ||
				(GetMessageExtraInfo() & MOUSEEVENTF_MASK_PLUS_PENTOUCH) != MOUSEEVENTF_FROMTOUCH_NOPEN)
			{
				// Hack: Take the opportunity to hide the cursor.
				mouseButtonDown = false;

				float x = (float)GET_X_LPARAM(lParam) * g_dpi_scale_x;
				float y = (float)GET_Y_LPARAM(lParam) * g_dpi_scale_y;
				WindowsRawInput::SetMousePos(x, y);

				TouchInput touch;
				touch.id = 0;
				touch.flags = TOUCH_UP;
				touch.x = x;
				touch.y = y;
				NativeTouch(touch);
				ReleaseCapture();
			}
			break;

		case WM_TOUCH:
			{
				touchHandler.handleTouchEvent(hWnd, message, wParam, lParam);
				return 0;
			}

		default:
			return DefWindowProc(hWnd, message, wParam, lParam);
		}
		return 0;
	}
Exemplo n.º 19
0
INT_PTR CALLBACK OptionsProc(HWND hdlg,UINT msg,WPARAM wparam,LPARAM lparam)
{	
	switch(msg){
	case WM_INITDIALOG:{
		DWORD style;
		g_opHdlg=hdlg;
		bOptionsInit=TRUE;
		TranslateDialogDefault(hdlg); 
		if(g_iButtonsCount!=db_get_b(NULL, PLGNAME,"ButtonsCount", 0))
		{
			LOGFONT logFont;
			HFONT hFont;
			bNeedRestart=TRUE;
			EnableWindow(GetDlgItem(hdlg,IDC_BUTTONSLIST),FALSE);
			EnableWindow(GetDlgItem(hdlg,IDC_BLISTADD),FALSE);
			EnableWindow(GetDlgItem(hdlg,IDC_BLISTREMOVE),FALSE);
			EnableWindow(GetDlgItem(hdlg,IDC_MENUTREE),FALSE);
			EnableWindow(GetDlgItem(hdlg,IDC_MTREEADD),FALSE);
			EnableWindow(GetDlgItem(hdlg,IDC_MTREEREMOVE),FALSE);
			EnableWindow(GetDlgItem(hdlg,IDC_MENUVALUE),FALSE);
			EnableWindow(GetDlgItem(hdlg,IDC_RCLICKVALUE),FALSE);
			EnableWindow(GetDlgItem(hdlg,IDC_BUTTONNAME),FALSE);
			EnableWindow(GetDlgItem(hdlg,IDC_INQMENU),FALSE);
			EnableWindow(GetDlgItem(hdlg,IDC_ISSERVNAME),FALSE);
			EnableWindow(GetDlgItem(hdlg,IDC_MENUNAME),FALSE);	
			ShowWindow(GetDlgItem(hdlg,IDC_WARNING),SW_SHOW);

			hFont = (HFONT)SendDlgItemMessage(hdlg, IDC_WARNING, WM_GETFONT, 0, 0);
			GetObject(hFont, sizeof(logFont), &logFont);
			logFont.lfWeight = FW_BOLD;
			hFont = CreateFontIndirect(&logFont);
			SendDlgItemMessage(hdlg, IDC_WARNING, WM_SETFONT, (WPARAM)hFont, 0);
			break;
		}

		g_iOPButtonsCount=g_iButtonsCount;

		hButtonsList=GetDlgItem(hdlg,IDC_BUTTONSLIST);
		hMenuTree=GetDlgItem(hdlg,IDC_MENUTREE);

		style = GetWindowLongPtr(hButtonsList,GWL_STYLE);
		style |=TVS_NOHSCROLL;
		SetWindowLongPtr(hButtonsList,GWL_STYLE, style);

		style = GetWindowLongPtr(hMenuTree,GWL_STYLE);
		style |=TVS_NOHSCROLL;			
		SetWindowLongPtr(hMenuTree,GWL_STYLE, style);
		BuildButtonsList(hButtonsList);

		if (!TreeView_GetCount(hButtonsList))
			EnableWindow(GetDlgItem(hdlg,IDC_RCLICKVALUE),FALSE);

		mir_subclassWindow( GetDlgItem(hdlg,IDC_BUTTONNAME), EditSubclassProc);
		mir_subclassWindow( GetDlgItem(hdlg,IDC_MENUNAME),   EditSubclassProc);

		EnableWindow(GetDlgItem(hdlg,IDC_MENUVALUE),FALSE);
		EnableWindow(GetDlgItem(hdlg,IDC_INQMENU),FALSE);
		EnableWindow(GetDlgItem(hdlg,IDC_ISSERVNAME),FALSE);
		CheckDlgButton(hdlg,IDC_RAUTOSEND,(g_bRClickAuto=db_get_b(NULL,PLGNAME,"RClickAuto",0)) ? BST_CHECKED : BST_UNCHECKED);
		CheckDlgButton(hdlg,IDC_LAUTOSEND,(g_bLClickAuto=db_get_b(NULL,PLGNAME,"LClickAuto",0)) ? BST_CHECKED : BST_UNCHECKED);
		CheckDlgButton(hdlg,IDC_ENABLEQUICKMENU,(g_bQuickMenu=db_get_b(NULL, PLGNAME,"QuickMenu", 1)) ? BST_CHECKED : BST_UNCHECKED);

		bOptionsInit=FALSE;
							 }break;

	case WM_LBUTTONUP:
		if(drag) {
			TVHITTESTINFO hti; 
			HTREEITEM htiAfter=NULL;
			ButtonData* bd=NULL;
			TVITEM tvi;
			RECT rc;
			BYTE height;
			BOOLEAN bAsChild = FALSE;

			TreeView_SetInsertMark(hMenuTree, NULL, 0 );
			ReleaseCapture();
			SetCursor( LoadCursor( NULL, IDC_ARROW ));

			hti.pt.x = ( SHORT )LOWORD( lparam );
			hti.pt.y = ( SHORT )HIWORD( lparam );
			ClientToScreen(hdlg,&hti.pt);
			ScreenToClient(hMenuTree,&hti.pt);
			TreeView_HitTest( hMenuTree, &hti );

			if(TreeView_GetParent(hMenuTree,hti.hItem)&&TreeView_GetChild(hMenuTree,hDragItem))
				break;

			if(TreeView_GetChild(hMenuTree,hti.hItem)&&TreeView_GetChild(hMenuTree,hDragItem))
				break;


			if ( hti.flags & TVHT_ABOVE ) {
				htiAfter = TVI_FIRST;
			}
			else
				if ( hti.flags & ( TVHT_NOWHERE|TVHT_BELOW )) {
					htiAfter = TVI_LAST;
				}
				else
					if ( hti.flags & ( TVHT_ONITEM|TVHT_ONITEMRIGHT )) {
						// check where over the item, the pointer is
						if ( !TreeView_GetItemRect( hMenuTree, hti.hItem, &rc, FALSE )) {
							drag=0;
							break;
						}
						height = ( BYTE )( rc.bottom - rc.top );

						if ( hti.pt.y - ( height / 3 ) < rc.top ) {
							HTREEITEM hItem = hti.hItem;

							if ( !( hti.hItem = TreeView_GetPrevSibling( hMenuTree, hItem )) ) {
								if ( !( hti.hItem = TreeView_GetParent(hMenuTree, hItem )))
									htiAfter = TVI_FIRST;
								else
									bAsChild = TRUE;
							}
						}
						else 
							if ( hti.pt.y + ( height / 3 ) <= rc.bottom ) {
								bAsChild = TRUE;
							}
					}	


					if(TreeView_GetChild(hMenuTree,hDragItem)&&bAsChild)
						break;


					if(hti.hItem){
						tvi.hItem=hti.hItem;
						tvi.mask=TVIF_PARAM |TVIF_HANDLE;
						TreeView_GetItem(hMenuTree,&tvi);
						if ((bd=(ButtonData*)tvi.lParam)&&(bd->fEntryOpType&QMF_EX_SEPARATOR))
							bAsChild = FALSE;
					}

					if(TreeView_GetParent(hMenuTree,hti.hItem))
						bAsChild = FALSE;


					MoveItem( hDragItem, htiAfter?htiAfter:hti.hItem, bAsChild );
					SendMessage(GetParent(hdlg),PSM_CHANGED,0,0);
					drag=0;

		}
		break; 

		///////////////////////////////////
		//From UserInfoEx by DeathAxe
		//
	case WM_MOUSEMOVE:
		{
			if (!drag) break;
			{
				TVHITTESTINFO hti;

				hti.pt.x=(short)LOWORD(lparam);
				hti.pt.y=(short)HIWORD(lparam);
				ClientToScreen(hdlg,&hti.pt);
				ScreenToClient(hMenuTree,&hti.pt);
				TreeView_HitTest(hMenuTree,&hti);
				if ( hti.flags & ( TVHT_ONITEM|TVHT_ONITEMRIGHT )) {
					RECT rc;
					BYTE height;

					if ( TreeView_GetItemRect(hMenuTree, hti.hItem, &rc, FALSE )) {
						height = ( BYTE )( rc.bottom - rc.top );

						if ( hti.pt.y - ( height / 3 ) < rc.top ) {
							SetCursor( LoadCursor( NULL, IDC_ARROW ));
							TreeView_SetInsertMark( hMenuTree, hti.hItem, 0 );
						}
						else
							if ( hti.pt.y + ( height / 3 ) > rc.bottom ) {
								SetCursor( LoadCursor( NULL, IDC_ARROW ));
								TreeView_SetInsertMark( hMenuTree, hti.hItem, 1 );
							}
							else {
								TreeView_SetInsertMark( hMenuTree, NULL, 0 );
								SetCursor( LoadCursor( GetModuleHandle(NULL), MAKEINTRESOURCE( 183 )) );
							}
					}
				}
				else {
					if ( hti.flags & TVHT_ABOVE ) SendMessage( hMenuTree, WM_VSCROLL, MAKEWPARAM( SB_LINEUP, 0 ), 0 );
					if ( hti.flags & TVHT_BELOW ) SendMessage( hMenuTree, WM_VSCROLL, MAKEWPARAM( SB_LINEDOWN, 0 ), 0 );
					TreeView_SetInsertMark( hMenuTree, NULL, 0 );
				}
			}
		}break;
		/////////////
	case WM_DESTROY:
		if (g_varhelpDlg)
			DestroyWindow(g_varhelpDlg);
		g_varhelpDlg=NULL;
		break;

	case WM_NOTIFY:
		switch(((LPNMHDR)lparam)->idFrom)	{
		case 0:
			if (((LPNMHDR)lparam)->code == PSN_APPLY ) {
				if (!bNeedRestart){
					SetMenuEntryProperties(hdlg);
					SaveMenuTree(hdlg); 
				}
				db_set_b(NULL,PLGNAME,"RClickAuto",(BYTE)(g_bRClickAuto=IsDlgButtonChecked(hdlg,IDC_RAUTOSEND)));
				db_set_b(NULL,PLGNAME,"LClickAuto",(BYTE)(g_bLClickAuto=IsDlgButtonChecked(hdlg,IDC_LAUTOSEND)));
				db_set_b(NULL,PLGNAME,"QuickMenu",(BYTE)(g_bQuickMenu=IsDlgButtonChecked(hdlg,IDC_ENABLEQUICKMENU)));
				return 1;
			}
			else if (((LPNMHDR)lparam)->code == PSN_RESET ) {
				if (!bNeedRestart)
					RestoreModuleData(hdlg);
				return 1;
			}
			break; 

		case IDC_MENUTREE:
			switch (((LPNMHDR)lparam)->code){
			case TVN_KEYDOWN:{
				TV_KEYDOWN* pTVKeyDown = (TV_KEYDOWN*) ((LPNMHDR)lparam);
				if ( pTVKeyDown->wVKey == VK_F2 )
					TreeView_EditLabel(hMenuTree,TreeView_GetSelection(hMenuTree));
				else if ( pTVKeyDown->wVKey == VK_DELETE )
					SendMessage(hdlg,WM_COMMAND,IDC_MTREEREMOVE,0);
								  }break;

			case TVN_BEGINLABELEDITA:
			case TVN_BEGINLABELEDITW:
				hwndEdit=TreeView_GetEditControl(hMenuTree);
				mir_subclassWindow(hwndEdit, LabelEditSubclassProc);
				break;

			case TVN_ENDLABELEDITA:
			case TVN_ENDLABELEDITW:
				{
					TVITEM tvi;
					ButtonData* bd=NULL;
					TCHAR strbuf[256];
					TCHAR szLabel[256];

					tvi.pszText = strbuf;
					tvi.cchTextMax = SIZEOF(strbuf);
					tvi.mask=TVIF_TEXT |TVIF_HANDLE|TVIF_PARAM;
					tvi.hItem=TreeView_GetSelection(hMenuTree);
					TreeView_GetItem(hMenuTree,&tvi);

					GetWindowText(hwndEdit, szLabel, SIZEOF(szLabel));
					hwndEdit=NULL;
					if (!_tcslen(szLabel)) break;
					if (bd = (ButtonData*)tvi.lParam){
						if (!_tcscmp(szLabel,_T("---"))) {
							if(TreeView_GetChild(hMenuTree,tvi.hItem))
								break;
							else{
								bd->fEntryOpType=QMF_EX_SEPARATOR;
								EnableWindow(GetDlgItem(hdlg,IDC_MENUVALUE),FALSE);
								EnableWindow(GetDlgItem(hdlg,IDC_ISSERVNAME),FALSE);
								SetDlgItemText(hdlg, IDC_MENUVALUE, _T(""));
							}
						}
						else {
							bd->fEntryOpType&=~QMF_EX_SEPARATOR;
							EnableWindow(GetDlgItem(hdlg,IDC_MENUVALUE),TRUE);
							EnableWindow(GetDlgItem(hdlg,IDC_ISSERVNAME),TRUE);
							SetDlgItemText(hdlg, IDC_MENUVALUE, bd->pszOpValue/*?bd->pszOpValue:bd->pszValue*/);
						}

						bd->pszOpName=mir_tstrdup(szLabel);

						tvi.pszText=szLabel;
						TreeView_SetItem(hMenuTree, &tvi);
						SendMessage(GetParent(hdlg),PSM_CHANGED,0,0);
					}
				}break;

			case NM_KILLFOCUS:
				TreeView_EndEditLabelNow(hButtonsList, 1);
				break;

			case TVN_BEGINDRAGA:
			case TVN_BEGINDRAGW:
				SetCapture(hdlg);
				drag=1;
				hDragItem=((LPNMTREEVIEW)lparam)->itemNew.hItem;
				TreeView_SelectItem(hMenuTree,hDragItem);
				break;

			case TVN_SELCHANGINGA:
			case TVN_SELCHANGINGW:
				{
					TVITEM tvi;
					HTREEITEM hti;
					ButtonData* bd;

					hti=TreeView_GetSelection(hMenuTree);

					if (hti==NULL)
						break;

					tvi.hItem=hti;
					tvi.mask=TVIF_HANDLE|TVIF_PARAM;
					TreeView_GetItem(hMenuTree,&tvi);

					if (tvi.lParam == 0)
						break;

					bd = ( ButtonData* )tvi.lParam;
					if (bd) {
						TCHAR szValue[256];
						GetDlgItemText(hdlg, IDC_MENUVALUE, szValue, SIZEOF(szValue));
						if(_tcslen(szValue))
						{
							if(bd->pszOpValue&&(bd->pszOpValue!=bd->pszValue))
								mir_free(bd->pszOpValue);
							bd->pszOpValue=mir_tstrdup(szValue);
						}
						bd->bOpInQMenu=IsDlgButtonChecked(hdlg,IDC_INQMENU);
						bd->bIsOpServName=IsDlgButtonChecked(hdlg,IDC_ISSERVNAME);
					}
				}break;
			case TVN_SELCHANGEDA:
			case TVN_SELCHANGEDW:
				{
					TVITEM tvi;
					HTREEITEM hti;
					ButtonData* bd=NULL;

					hti=TreeView_GetSelection(hMenuTree);

					if (hti==NULL)
						break;

					tvi.mask=TVIF_HANDLE|TVIF_PARAM;

					tvi.hItem=hti;
					TreeView_GetItem(hMenuTree,&tvi);


					bd = ( ButtonData* )tvi.lParam;
					if (bd) {
						if (!TreeView_GetChild(hMenuTree, tvi.hItem)&&!(bd->fEntryOpType&QMF_EX_SEPARATOR))
						{
							EnableWindow(GetDlgItem(hdlg,IDC_MENUVALUE),TRUE);
							EnableWindow(GetDlgItem(hdlg,IDC_ISSERVNAME),TRUE);
							EnableWindow(GetDlgItem(hdlg,IDC_INQMENU),TRUE);
							SetDlgItemText(hdlg, IDC_MENUVALUE, bd->pszOpValue/*?bd->pszOpValue:bd->pszValue*/);
						}
						else
						{
							EnableWindow(GetDlgItem(hdlg,IDC_MENUVALUE),FALSE);
							EnableWindow(GetDlgItem(hdlg,IDC_ISSERVNAME),FALSE);
							if (!(bd->fEntryOpType&QMF_EX_SEPARATOR))
								EnableWindow(GetDlgItem(hdlg,IDC_INQMENU),FALSE);
							SetDlgItemText(hdlg, IDC_MENUVALUE, _T(""));
						}
						CheckDlgButton(hdlg,IDC_INQMENU,bd->bOpInQMenu ? BST_CHECKED : BST_UNCHECKED);
						CheckDlgButton(hdlg,IDC_ISSERVNAME,bd->bIsOpServName ? BST_CHECKED : BST_UNCHECKED);
					}
				}
			}break;

		case IDC_BUTTONSLIST:
			switch (((LPNMHDR)lparam)->code) {
			case TVN_KEYDOWN:{
				TV_KEYDOWN* pTVKeyDown = (TV_KEYDOWN*) ((LPNMHDR)lparam);
				if ( pTVKeyDown->wVKey == VK_F2 )
					TreeView_EditLabel(hButtonsList,TreeView_GetSelection(hButtonsList));
				else if ( pTVKeyDown->wVKey == VK_DELETE )
					SendMessage(hdlg,WM_COMMAND,IDC_BLISTREMOVE,0);
								  }break;

			case TVN_BEGINLABELEDITA:
			case TVN_BEGINLABELEDITW:
				hwndEdit = TreeView_GetEditControl(hButtonsList);
				mir_subclassWindow(hwndEdit, LabelEditSubclassProc);
				break;

			case TVN_ENDLABELEDITA:
			case TVN_ENDLABELEDITW:
				{
					TVITEM tvi;
					TCHAR strbuf[128];
					TCHAR szLabel[128];

					tvi.pszText = strbuf;
					tvi.cchTextMax = SIZEOF(strbuf);
					tvi.mask=TVIF_TEXT |TVIF_HANDLE|TVIF_PARAM;
					tvi.hItem=TreeView_GetSelection(hButtonsList);
					TreeView_GetItem(hButtonsList,&tvi);

					GetWindowText(hwndEdit, szLabel, SIZEOF(szLabel));
					hwndEdit=NULL;
					if (!_tcslen(szLabel)) break;

					tvi.pszText=szLabel;
					((ListData*)tvi.lParam)->dwOPFlags|=QMF_RENAMED;	

					TreeView_SetItem(hButtonsList, &tvi);
					SendMessage(GetParent(hdlg),PSM_CHANGED,0,0);
				}break;

			case TVN_SELCHANGINGA:
			case TVN_SELCHANGINGW:
				SetMenuEntryProperties(hdlg);
				break;

			case TVN_SELCHANGEDA:
			case TVN_SELCHANGEDW:
				{
					TVITEM tvi;
					HTREEITEM hti;

					hti=TreeView_GetSelection(hButtonsList);

					if(hti==NULL||!TreeView_GetCount(hButtonsList)) {
						EnableWindow(GetDlgItem(hdlg,IDC_MENUVALUE),FALSE);
						EnableWindow(GetDlgItem(hdlg,IDC_ISSERVNAME),FALSE);
						EnableWindow(GetDlgItem(hdlg,IDC_INQMENU),FALSE);
						EnableWindow(GetDlgItem(hdlg,IDC_ISSERVNAME2),FALSE);
						SetDlgItemText(hdlg, IDC_MENUVALUE, _T(""));
						break;
					}

					tvi.mask=TVIF_HANDLE|TVIF_PARAM;
					tvi.hItem=hti;
					TreeView_GetItem(hButtonsList,&tvi);

					if(tvi.lParam==0) break;

					BuildMenuTree(hMenuTree,(SortedList *)((ListData*)tvi.lParam)->sl);

					SetDlgItemText(hdlg, IDC_MENUVALUE, _T(""));
					EnableWindow(GetDlgItem(hdlg,IDC_RCLICKVALUE),TRUE);
					EnableWindow(GetDlgItem(hdlg,IDC_ISSERVNAME2),TRUE);
					CheckDlgButton(hdlg,IDC_ISSERVNAME2,((ListData*)tvi.lParam)->bIsOpServName ? BST_CHECKED : BST_UNCHECKED);

					if (((ListData*)tvi.lParam)->ptszOPQValue) 
						SetDlgItemText(hdlg, IDC_RCLICKVALUE, ((ListData*)tvi.lParam)->ptszOPQValue);
					else
						SetDlgItemText(hdlg, IDC_RCLICKVALUE, _T(""));
				}break;
			}break;
		}
		break;

	case WM_COMMAND:
		switch(LOWORD(wparam)) {
		case IDC_VARHELP:
			if (!g_varhelpDlg)
				g_varhelpDlg=CreateDialog(hinstance,MAKEINTRESOURCE(IDD_HELPDIALOG), 0, HelpDlgProc);
			else
				//ShowWindow(g_varhelpDlg,SW_SHOWDEFAULT);
				SetWindowPos(g_varhelpDlg,0,0,0,0,0,SWP_SHOWWINDOW|SWP_NOMOVE|SWP_NOSIZE);
			break;
		case IDC_BLISTADD:
			{
				TVINSERTSTRUCT tvis;
				ListData* ld=NULL;
				TCHAR namebuff[MAX_PATH]={'\0'};
				int count=TreeView_GetCount(hButtonsList);
				if (count>10) break;
				if(g_iOPButtonsCount==99){
					MessageBox(NULL, TranslateT("Congratulation!\r\nYou have clicked this button 100 times!\r\nThere was access violation at this point...\r\nAnd now function for freeing resources must be called...\r\nBut no! there's only break :D"), TranslateT("You win!"),MB_OK);
					break;
				}

				ld = (ListData *)mir_alloc(sizeof(ListData));
				ButtonsList[g_iOPButtonsCount++]=ld;

				ld->sl=List_Create(0,1);
				ld->dwOPFlags=QMF_NEW;
				ld->bIsOpServName=0;
				ld->ptszButtonName=NULL;
				ld->ptszOPQValue=NULL;
				ld->ptszQValue=NULL;
				tvis.hParent = NULL;
				tvis.hInsertAfter = TVI_LAST;

				GetDlgItemText(hdlg, IDC_BUTTONNAME, namebuff, SIZEOF(namebuff));

				tvis.item.mask=TVIF_PARAM|TVIF_TEXT;
				tvis.item.pszText=(_tcslen(namebuff))?namebuff:TranslateT("New Button");
				tvis.item.lParam=(LPARAM)ld;
				TreeView_SelectItem(hButtonsList,TreeView_InsertItem(hButtonsList,&tvis));
			}break;

		case IDC_BLISTREMOVE:
			{ 
				TVITEM tvi;
				ListData* ld;

				if (!(tvi.hItem=TreeView_GetSelection(hButtonsList)))
					break;

				tvi.mask=TVIF_HANDLE|TVIF_PARAM;
				TreeView_GetItem(hButtonsList,&tvi);

				ld= (ListData*)tvi.lParam;

				ld->dwOPFlags|=QMF_DELETNEEDED;	

				TreeView_DeleteItem(hButtonsList,tvi.hItem);
				if (!TreeView_GetCount(hButtonsList)) {
					TreeView_DeleteAllItems(hMenuTree);
					EnableWindow(GetDlgItem(hdlg,IDC_MENUVALUE),FALSE);
					EnableWindow(GetDlgItem(hdlg,IDC_RCLICKVALUE),FALSE);
					EnableWindow(GetDlgItem(hdlg,IDC_ISSERVNAME),FALSE);
					EnableWindow(GetDlgItem(hdlg,IDC_INQMENU),FALSE);
					EnableWindow(GetDlgItem(hdlg,IDC_ISSERVNAME2),FALSE);
					SetDlgItemText(hdlg, IDC_MENUVALUE, _T(""));
					SetDlgItemText(hdlg, IDC_RCLICKVALUE, _T(""));
				}
			}break;

		case IDC_MTREEADD:
			{
				TVINSERTSTRUCT tvis;
				TVITEM tvi;
				ButtonData *bd=NULL;
				SortedList *sl=NULL;
				TCHAR namebuff[MAX_PATH]={'\0'};

				if (!TreeView_GetCount(hButtonsList)) break;
				if (!(tvi.hItem=TreeView_GetSelection(hButtonsList))) break;

				bd = (ButtonData *)mir_alloc(sizeof(ButtonData));
				memset(bd,0,sizeof(ButtonData));

				GetDlgItemText(hdlg, IDC_MENUNAME, namebuff, SIZEOF(namebuff));

				bd->dwOPPos=TreeView_GetCount(hMenuTree)-1;
				bd->pszOpName=_tcslen(namebuff)?mir_tstrdup(namebuff):mir_tstrdup(TranslateT("New Menu Entry"));
				bd->pszOpValue=mir_tstrdup(bd->pszOpName);
				bd->fEntryOpType=!_tcscmp(namebuff,_T("---"))?QMF_EX_SEPARATOR:0;
				bd->dwOPFlags=QMF_NEW;
				bd->pszName=NULL;
				bd->pszValue=NULL;


				tvi.mask=TVIF_HANDLE|TVIF_PARAM;

				TreeView_GetItem(hButtonsList,&tvi);

				sl=((ListData*)tvi.lParam)->sl;

				List_InsertPtr(sl,bd);

				tvis.hParent = NULL;
				tvis.hInsertAfter = TVI_LAST;
				tvis.item.mask=TVIF_PARAM|TVIF_TEXT;
				tvis.item.pszText=bd->pszOpName;
				tvis.item.lParam=(LPARAM)bd;
				TreeView_SelectItem(hMenuTree,TreeView_InsertItem(hMenuTree,&tvis));
			}break;

		case IDC_MTREEREMOVE:
			{
				TVITEM tvi;
				TVINSERTSTRUCT tvis;
				HTREEITEM hti=NULL;
				ButtonData *bd=NULL;
				tvi.mask=TVIF_HANDLE|TVIF_PARAM;
				if (!(tvi.hItem=TreeView_GetSelection(hMenuTree)))
					break;
				TreeView_GetItem(hMenuTree,&tvi);
				hti=tvi.hItem;

				bd= (ButtonData*)tvi.lParam;
				bd->dwOPFlags|=QMF_DELETNEEDED;			

				if(tvi.hItem=TreeView_GetChild(hMenuTree,tvi.hItem)) {
					TCHAR strbuf[128];
					while(tvi.hItem){
						tvis.hInsertAfter=hti;
						tvi.pszText = strbuf;
						tvi.cchTextMax = SIZEOF(strbuf);
						tvi.mask=TVIF_HANDLE|TVIF_PARAM|TVIF_TEXT;

						TreeView_GetItem(hMenuTree,&tvi); 
						tvis.hParent=NULL;
						tvis.item=tvi;
						TreeView_InsertItem(hMenuTree,&tvis);
						tvi.hItem=TreeView_GetNextSibling(hMenuTree,tvi.hItem);
					}
				}

				TreeView_DeleteItem(hMenuTree,hti);
				if (!TreeView_GetCount(hMenuTree)) {
					EnableWindow(GetDlgItem(hdlg,IDC_MENUVALUE),FALSE);
					EnableWindow(GetDlgItem(hdlg,IDC_ISSERVNAME),FALSE);
					EnableWindow(GetDlgItem(hdlg,IDC_INQMENU),FALSE);
					SetDlgItemText(hdlg, IDC_MENUVALUE, _T(""));
				}
			}break;
		}
		break;

	case WM_CLOSE:
		EndDialog(hdlg,0);
		return 0;
	}
	if (HIWORD(wparam)==BN_CLICKED && GetFocus()==(HWND)lparam)
		SendMessage(GetParent(hdlg),PSM_CHANGED,0,0);
	else if ((HIWORD(wparam) == EN_CHANGE)&&(GetFocus()==(HWND)lparam))
		if (!bOptionsInit)	SendMessage(GetParent(hdlg),PSM_CHANGED,0,0);

	return 0;
}
Exemplo n.º 20
0
/*-------------------------------*/
LRESULT CALLBACK WndProc(HWND hWnd, UINT komunikat, WPARAM wParam, LPARAM lParam)
{
    static BOOL bDragging;
    static int poz;
    POINT pkt;
    HIMAGELIST hDragImgList;
    static NOTIFYICONDATA nim;

    switch (komunikat)
    {
        case WM_CREATE:
            HWND hToolTip;
            HFONT hFont;
            TOOLINFO tinf;
            RECT rect;

            /*-----tworzenie kontrolek-----*/
            hList = CreateWindow("SysListView32", "lista_przyciskow", WS_VISIBLE | WS_CHILD | WS_BORDER |
                                 LVS_REPORT | LVS_SINGLESEL,0,0,493,230,hWnd,NULL,hInst, NULL);
            hRefresh = CreateWindow("button", "Odœwie¿ listê", WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON,
                                    135, 232, 100, 20, hWnd, NULL, hInst, NULL);
            hShow = CreateWindow("button", "Poka¿ przycisk", WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON,
                                 15, 232, 100, 20,/*255, 232, 100, 20,*/ hWnd, NULL, hInst, NULL);
            hInfo = CreateWindow("button", "O programie...", WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON,
                                 375, 232, 100, 20, hWnd, NULL, hInst, NULL);

            /*-----tworzenie i ustawianie czcionki dla przycisków-----*/
            hFont = CreateFont(14, 0, 0, 0, 0, false, false, false, DEFAULT_CHARSET,
                               OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
                               DEFAULT_PITCH, NULL);

            SendMessage(hRefresh, WM_SETFONT, (WPARAM) hFont, true);
            SendMessage(hShow, WM_SETFONT, (WPARAM) hFont, true);
            SendMessage(hInfo, WM_SETFONT, (WPARAM) hFont, true);

            ListView_SetExtendedListViewStyle(hList, LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES | LVS_EX_INFOTIP);

            /*-----ustawianie tooltipów-----*/
            hToolTip = CreateWindow(TOOLTIPS_CLASS, NULL, TTS_ALWAYSTIP | TTS_BALLOON, 0,0,0,0, hWnd, NULL, hInst, NULL);

            //Ustawianie parametrów wspó³nych dla ka¿dego tooltipa: tytu³, kolor.
            SendMessage(hToolTip, TTM_SETTITLE, TTI_INFO, (LPARAM)"Skrót");
            SendMessage(hToolTip, TTM_SETTIPTEXTCOLOR, (LPARAM)RGB(0, 0, 100), 0);
            SendMessage(hToolTip, TTM_SETTIPBKCOLOR, (LPARAM)RGB(250, 250, 250), 0);

            GetClientRect (hWnd, &rect);
            tinf.cbSize = sizeof(TOOLINFO);
            tinf.uFlags = TTF_SUBCLASS;
            tinf.hinst = hInst;
            tinf.uId = 0;
            tinf.rect.left = rect.left;
            tinf.rect.top = rect.top;
            tinf.rect.right = rect.right;
            tinf.rect.bottom = rect.bottom;

            tinf.hwnd = hRefresh;
            tinf.lpszText = "F5";
            SendMessage(hToolTip, TTM_ADDTOOL, 0, (LPARAM)&tinf);
            tinf.hwnd = hShow;
            tinf.lpszText = "dwuklik LPM";
            SendMessage(hToolTip, TTM_ADDTOOL, 0, (LPARAM)&tinf);
            tinf.hwnd = hInfo;
            tinf.lpszText = "F1";
            SendMessage(hToolTip, TTM_ADDTOOL, 0, (LPARAM)&tinf);

            /*-----ustawianie ikony programu w zasobniku systemowym-----*/
            nim.cbSize = sizeof(NOTIFYICONDATA);
            nim.hWnd = hWnd;
            nim.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP;
            nim.hIcon = ikona;
            nim.uCallbackMessage = WM_TRAY;
            nim.uID = 7;
            lstrcpyn(nim.szTip, "Manipulator by FeniX", sizeof(nim.szTip));
            Shell_NotifyIcon(NIM_ADD, &nim);
            refresh();
            break;
        case WM_KEYUP:  //obs³uga skrótów klawiaturowych dla konkretnych akcji
            switch (wParam)
            {
                case VK_F5:
                    SendMessage(hRefresh, BM_CLICK, 0, 0);
                    break;
                case VK_F1:
                    SendMessage(hInfo, BM_CLICK, 0, 0);
                    break;
                case VK_SPACE:
                    SendMessage(hShow, BM_CLICK, 0, 0);
                    break;
                case VK_ESCAPE:
                    ShowWindow(hWnd, SW_MINIMIZE);
                    break;
            }
            break;
        case WM_COMMAND:    //obs³uga zdarzeñ okien pochodnych okna g³ównego
            switch (HIWORD(wParam))
            {
                case BN_CLICKED:    //komunikat klikniêcia przycisku
                    if ((HWND)lParam == hRefresh)
                    {
                        refresh();
                        SetFocus(hList);
                    }
                    else if ((HWND)lParam == hInfo)
                    {
                        MessageBox(hWnd, "Autor:\nKonrad Gadzina <*****@*****.**>\n"
                                         "Grupa 1131, Informatyka, rok akad. 2008/2009"
                                         "\nPracownia In¿ynierii Oprogramowania M-74\n"
                                         "Instytut Informatyki Stosowanej\n"
                                         "Wydzia³ Mechaniczny, Politechnika Krakowska\nJêzyki i Techniki Programowania",
                                         "O programie", MB_OK);
                    }
                    else if ((HWND)lParam == hShow)
                    {
                        int poz;
                        char buf[10];
                        bool hidden;
                        TBBUTTON *ptbb, tbb;
                        NOTIFYICONDATA fake;  //potrzebne do "odswiezania" paska zadan i dopasowywania szerokosci przyciskow

                        ptbb = (TBBUTTON*)VirtualAllocEx(proces, NULL, sizeof(TBBUTTON), MEM_COMMIT, PAGE_READWRITE);
                        poz = ListView_GetNextItem(hList, (WPARAM)-1, LVNI_SELECTED);

                        SendMessage(hPasek, TB_GETBUTTON, (WPARAM)poz, (LPARAM)ptbb);
                        ReadProcessMemory(proces, (void*)ptbb, (void*)&tbb, sizeof(TBBUTTON), NULL);

                        hidden = SendMessage(hPasek, TB_ISBUTTONHIDDEN, (WPARAM)tbb.idCommand, 0);
                        SendMessage(hPasek, TB_HIDEBUTTON, (WPARAM)tbb.idCommand, (LPARAM)!hidden);

                        if (hidden)
                            SendMessage(hShow, WM_SETTEXT, 0, (LPARAM)"Ukryj przycisk");
                        else
                            SendMessage(hShow, WM_SETTEXT, 0, (LPARAM)"Poka¿ przycisk");

                        /*---dodawanie i usuwanie ikony do zasobnika, by pasek zadañ siê "odœwie¿y³"---*/
                        fake.cbSize = sizeof(NOTIFYICONDATA);
                        fake.hWnd = hWnd;
                        fake.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP;
                        fake.hIcon = ikona;
                        fake.uCallbackMessage = WM_TRAY;
                        fake.uID = 19;
                        lstrcpyn(fake.szTip, "Manipulator by FeniX", sizeof(fake.szTip));
                        Shell_NotifyIcon(NIM_ADD, &fake);
                        Shell_NotifyIcon(NIM_DELETE, &fake);

                        for (int i = 0; i<ile; i++)
                        {
                            SendMessage(hPasek, TB_GETBUTTON, (WPARAM)i, (LPARAM)ptbb);
                            ReadProcessMemory(proces, (void*)ptbb, (void*)&tbb, sizeof(TBBUTTON), NULL);
                            hidden = SendMessage(hPasek, TB_ISBUTTONHIDDEN, (WPARAM)tbb.idCommand, 0);

                            if (!hidden)
                                strcpy(buf, "[widoczny]");
                            else
                                strcpy(buf, "[ukryty]");
                            ListView_SetItemText(hList, i, 1, buf);
                        }
                        SetFocus(hList);

                        VirtualFreeEx(proces, ptbb, 0, MEM_RELEASE);
                    }
                    break;
            }
            break;
        case WM_TRAY:   //obs³uga klikniêcia na ikonkê programu w zasobniku systemowym
            switch ((UINT)lParam)
            {
                case WM_LBUTTONDOWN:
                    if (!IsWindowVisible(hWnd))
                    {
                        if (IsZoomed(hWnd))
                            ShowWindow(hWnd, SW_MAXIMIZE);
                        else
                            ShowWindow(hWnd, SW_RESTORE);
                        SetForegroundWindow(hWnd);
                    }
                    else if (GetForegroundWindow() == hWnd)
                        ShowWindow(hWnd, SW_HIDE);
                    else
                        SetForegroundWindow(hWnd);
                    break;
            }
            break;
        case WM_ACTIVATE:
            if (LOWORD(wParam) != WA_INACTIVE)
                refresh();
            break;
        case WM_SIZE:   //zdarzenie zmienienia rozmiaru
            int szer, wys;

            if (wParam & SIZE_MINIMIZED)
                ShowWindow(hWnd, SW_HIDE);

            szer = (int)LOWORD(lParam);
            wys = (int)HIWORD(lParam );

            /*
               Poni¿ze linijki pozwalaj¹ przestawiaæ kontrolki tak, by
               dopasowa ich pozycjê/rozmiar do rozmiaru okna g³ównego
            */
            MoveWindow(hList, 0, 0, szer, wys-23, false);
            MoveWindow(hShow, 20, wys-21, 120, 20, false);
            MoveWindow(hRefresh, szer-310, wys-21, 120, 20, false);
            MoveWindow(hInfo, szer-140, wys-21, 120, 20, false);
            break;
        case WM_SIZING: //zdarzenie zmieniania rozmiaru
            RECT* rc;
            rc = (RECT*)lParam;
            /*
               Poni¿sze linie pozwalaj¹ ograniczyc rozmiar okna - jako, ¿e to zdarzenie jest
               wywo³ywane w trakcie zmiany rozmiaru, warunki s¹ sprawdzane nie po puszczeniu
               przycisku myszy, a jeszcze w trakcie jego trzymania. Dziêki temu okno nie
               nigdy nie bêdzie mia³o rozmiarów mniejszych ni¿ 500x100 pikseli.
            */
            if (rc->right - rc->left <= 500)
                rc->right = rc->left + 500;
            if (rc->bottom - rc->top <= 100)
                rc->bottom = rc->top + 100;
            break;
        case WM_DESTROY:    //zdarzenie niszczenia okna
            CloseHandle(proces);
            Shell_NotifyIcon(NIM_DELETE, &nim);
            PostQuitMessage(0);
            break;

        case WM_NOTIFY: //obs³uga komunikatów od kontrolki ListView
            if (((LPNMHDR)lParam)->hwndFrom == hList && ((LPNMHDR)lParam)->code == (unsigned int)NM_DBLCLK)
                SendMessage(hShow, BM_CLICK, 0, 0);
            else if (((LPNMHDR)lParam)->hwndFrom == hList && ((LPNMHDR)lParam)->code == (unsigned int)NM_CLICK)
            {
                char buf[10];
                int poz = ListView_GetNextItem(hList, (WPARAM)-1, LVNI_SELECTED);

                ListView_GetItemText(hList, poz, 1, buf, 50);
                if (!strcmp(buf, "[ukryty]"))
                    SendMessage(hShow, WM_SETTEXT, 0, (LPARAM)"Poka¿ przycisk");
                else
                    SendMessage(hShow, WM_SETTEXT, 0, (LPARAM)"Ukryj przycisk");
            }
            else if (((LPNMHDR)lParam)->hwndFrom == hList && ((LPNMHDR)lParam)->code == LVN_KEYDOWN)
            {
                switch (((LV_KEYDOWN*)lParam)->wVKey)
                {
                case VK_F5:
                    SendMessage(hRefresh, BM_CLICK, 0, 0);
                    break;
                case VK_F1:
                    SendMessage(hInfo, BM_CLICK, 0, 0);
                    break;
                case VK_SPACE:
                    SendMessage(hShow, BM_CLICK, 0, 0);
                    break;
                case VK_ESCAPE:
                    ShowWindow(hWnd, SW_MINIMIZE);
                    break;
                }
            }
            /*------------------- obs³uga drag & drop na liœcie z przyciskami -------------------*/
            else if (((LPNMHDR)lParam)->hwndFrom == hList && ((LPNMHDR)lParam)->code == LVN_BEGINDRAG)
            {
                //wiadomoœæ wysy³ana do okna g³ównego, gdy rozpoczynamy drag & drop na liœcie
                //czyli ³apiemy element lewym przyciskiem myszy
                HIMAGELIST hOneImageList, hTempImageList;
                IMAGEINFO imginf;
                int x = 0, wys;
                pkt.x = 1;
                pkt.y = 1;

                poz = ListView_GetNextItem(hList, (WPARAM)-1, LVNI_SELECTED);  //pobieranie indexu zaznaczonego elementu
                item.iItem = poz;
                item.mask = LVIF_IMAGE | LVIF_INDENT | LVIF_PARAM; //ustawienie maski elementu listy do pobrania
                ListView_GetItem(hList, &item);    //pobieranie danego elementu do zmiennej item

                if (item.iIndent) //element z wciêciem nas nie interesuje
                    break;

                hDragImgList = ListView_CreateDragImage(hList, poz, &pkt); //tworzenie "duszka" do d&d
                ImageList_GetImageInfo(hDragImgList, 0, &imginf);
                wys = imginf.rcImage.bottom;

                while(true)    //dodawanie elementów danej grupy do "duszka" w pêtli
                {
                    if (++item.iItem >= ile)
                        break;
                    item.mask = LVIF_IMAGE | LVIF_INDENT | LVIF_PARAM; //ustawianie maski pobierania danych elementu
                    ListView_GetItem(hList, &item);
                    if(item.iIndent == 0) //je¿eli napotkano kolejny przycisk grupowy trzeba przerwaæ
                        break;

                    hOneImageList = ListView_CreateDragImage(hList, item.iItem, &pkt);
                    hTempImageList = ImageList_Merge(hDragImgList, 0, hOneImageList, 0, 0, wys);
                    ImageList_Destroy(hDragImgList);
                    ImageList_Destroy(hOneImageList);
                    hDragImgList = hTempImageList;
                    ImageList_GetImageInfo(hDragImgList, 0, &imginf);
                    wys = imginf.rcImage.bottom;
                }

                item.iItem = poz;
                item.mask = LVIF_IMAGE | LVIF_INDENT | LVIF_PARAM;
                ListView_GetItem(hList, &item);

                ImageList_BeginDrag(hDragImgList, 0, x, 0);
                pkt = ((NM_LISTVIEW*) ((LPNMHDR)lParam))->ptAction;
                ClientToScreen(hList, &pkt);
                ImageList_DragEnter(GetDesktopWindow(), pkt.x, pkt.y);
                bDragging = true;

                SetCapture(hWnd);
            }
            break;
        case WM_MOUSEMOVE:  //zdarzenie ruchu kursora myszy
            if (!bDragging) //je¿eli nie obs³gujemy akurat d&d na liœcie to nie trzeba nic robiæ
                break;

            pkt.x = LOWORD(lParam);
            pkt.y = HIWORD(lParam);
            ClientToScreen(hWnd, &pkt);
            ImageList_DragMove(pkt.x, pkt.y);
            break;
        case WM_LBUTTONUP:  //zdarzenie puszczenia lewego przycisku myszy
            if (!bDragging) //je¿eli nie obs³gujemy akurat d&d na liœcie to nie trzeba nic robiæ
                break;

            LVHITTESTINFO lvhti;
            char buf[256], sub[12];

            /*---puszczamy przycisk, wiêc przeci¹ganie siê koñczy---*/
            bDragging = false;
            ImageList_DragLeave(hList);
            ImageList_EndDrag();
            //ImageList_Destroy(hDragImgList);  //nie wiem czemu, ale ta linia wywo³uje b³¹d segfault przy uruchomieniu debuggera
            ReleaseCapture();


            /*---sprawdzanie, czy przeci¹gany element zosta³ upuszczony na inny element listy---*/
            lvhti.pt.x = LOWORD(lParam);
            lvhti.pt.y = HIWORD(lParam);
            ClientToScreen(hWnd, &lvhti.pt);
            ScreenToClient(hList, &lvhti.pt);
            ListView_HitTest(hList, &lvhti);
            if (lvhti.iItem == -1)
                break;
            if ((lvhti.flags & LVHT_ONITEMLABEL == 0) && (lvhti.flags & LVHT_ONITEMSTATEICON == 0))
                break;

            if (!item.iIndent) //je¿eli wciêcie = 0, to znaczy ¿e zajmujemy siê przyciskiem "grupowym"
            {
                poz = ListView_GetNextItem(hList, (WPARAM)-1, LVNI_SELECTED);

                if (lvhti.iItem > poz)
                    lvhti.iItem++;

                while (true)
                {
                    if (lvhti.iItem == poz || lvhti.iItem > ile-1 || lvhti.iItem < 0)
                        break;
                    item.iItem = lvhti.iItem;
                    item.iSubItem = 0;
                    item.mask = LVIF_STATE | LVIF_IMAGE | LVIF_INDENT | LVIF_TEXT | LVIF_PARAM;
                    item.stateMask = LVIS_SELECTED;
                    ListView_GetItem(hList, &item);
                    if (item.iIndent)
                    {
                        if (lvhti.iItem > poz)
                            lvhti.iItem++;
                        else if (lvhti.iItem < poz)
                            lvhti.iItem--;
                    }
                    else
                    {
                        if (lvhti.iItem > poz)
                            lvhti.iItem--;
                        break;
                    }
                }

                ListView_GetItemText(hList, poz, 0, buf, 256); //pobieranie tekstu danego elementu listy
                while (true)
                {
                    int tmp = poz;

                    item.iItem = poz;
                    item.iSubItem = 0;
                    item.cchTextMax = 256;
                    item.pszText = buf;
                    item.stateMask = ~LVIS_SELECTED;
                    item.mask = LVIF_STATE | LVIF_IMAGE | LVIF_INDENT | LVIF_TEXT | LVIF_PARAM;
                    ListView_GetItem(hList, &item);
                    ListView_GetItemText(hList, poz, 1, sub, 12);

                    SendMessage(hPasek, TB_MOVEBUTTON, (WPARAM)poz, (LPARAM)lvhti.iItem);
                    if (lvhti.iItem > poz && lvhti.iItem < ile)
                        lvhti.iItem++;
                    item.iItem = lvhti.iItem;

                    ListView_InsertItem(hList, &item);
                    ListView_SetItemText(hList, item.iItem, 1, sub);
                    if (lvhti.iItem < poz)
                        poz++;
                    ListView_DeleteItem(hList, poz);
                    if (lvhti.iItem > tmp)
                        lvhti.iItem--;
                    if (lvhti.iItem < tmp)
                        lvhti.iItem++;
                    ListView_GetItemText(hList, poz, 0, buf, 256);
                    item.iItem = poz;
                    item.iSubItem = 0;
                    item.cchTextMax = 256;
                    item.pszText = buf;
                    ListView_GetItem(hList, &item);
                    if (!item.iIndent || poz > ile-1)  //je¿eli
                        break;
                }
            }
            break;
        default:
            return DefWindowProc(hWnd, komunikat, wParam, lParam);
    }
    return 0;
}
Exemplo n.º 21
0
LRESULT WINAPI MsgProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam )
{
    switch( msg )
    {
        case WM_DESTROY:
            PostQuitMessage( 0 );
            break;

		// ************ KEYBOARD MESSAGES ************ //
		case WM_KEYDOWN:
			switch( wParam )
			{
			case VK_UP:
				kServ.OnUpPressed();
				break;
			case VK_DOWN:
				kServ.OnDownPressed();
				break;
			case VK_LEFT:
				kServ.OnLeftPressed();
				break;
			case VK_RIGHT:
				kServ.OnRightPressed();
				break;
			case VK_SPACE:
                kServ.OnSpacePressed();
				break;
			case VK_RETURN:
				kServ.OnEnterPressed();
				break;
			}
			break;
		case WM_KEYUP:
   			switch( wParam )
			{
			case VK_UP:
				kServ.OnUpReleased();
				break;
			case VK_DOWN:
				kServ.OnDownReleased();
				break;
			case VK_LEFT:
				kServ.OnLeftReleased();
				break;
			case VK_RIGHT:
				kServ.OnRightReleased();
				break;
			case VK_SPACE:
				kServ.OnSpaceReleased();
				break;
			case VK_RETURN:
				kServ.OnEnterReleased();
				break;
			}
			break;
		// ************ END KEYBOARD MESSAGES ************ //

		// ************ MOUSE MESSAGES ************ //
		case WM_MOUSEMOVE:
			{
				int x = (short)LOWORD( lParam );
				int y = (short)HIWORD( lParam );
				if( x > 0 && x < 800 && y > 0 && y < 600 )
				{
					mServ.OnMouseMove( x,y );
					if( !mServ.IsInWindow() )
					{
						SetCapture( hWnd );
						mServ.OnMouseEnter();
					}
				}
				else
				{
					if( wParam & (MK_LBUTTON | MK_RBUTTON) )
					{
						x = max( 0,x );
						x = min( 799,x );
						y = max( 0,y );
						y = min( 599,y );
						mServ.OnMouseMove( x,y );
					}
					else
					{
						ReleaseCapture();
						mServ.OnMouseLeave();
						mServ.OnLeftReleased();
						mServ.OnRightReleased();
					}
				}
			}
			break;
		case WM_LBUTTONDOWN:
			mServ.OnLeftPressed();
			break;
		case WM_RBUTTONDOWN:
			mServ.OnRightPressed();
			break;
		case WM_LBUTTONUP:
			mServ.OnLeftReleased();
			break;
		case WM_RBUTTONUP:
			mServ.OnRightReleased();
			break;
		// ************ END MOUSE MESSAGES ************ //
    }

    return DefWindowProc( hWnd, msg, wParam, lParam );
}
Exemplo n.º 22
0
int COXListPopup::Pick(CRect rect, CRect rectParent)
{
	AdjustDisplayRectangle(rect, rectParent);

	MoveWindow(rect);
	ShowWindow(SW_SHOWNA);
	SetCapture();

	// init message loop
	bool bBreak = false;
	int iReturnItemIdx = -1;
	while (!bBreak)
	{
		MSG msg;
		VERIFY(::GetMessage(&msg, NULL, 0, 0));
		if (msg.message == WM_LBUTTONUP)
		{
			// Get the item under the mouse cursor
			int xPos = GET_X_LPARAM(msg.lParam); 
			int yPos = GET_Y_LPARAM(msg.lParam);

			BOOL bOutside;
			UINT nIndex = ItemFromPoint(CPoint(xPos, yPos), bOutside);
			if (!bOutside)
				iReturnItemIdx = (int) nIndex;
			bBreak = true;
		}
		else if (msg.message == WM_KEYDOWN)
		{
			// Handle ESCAPE, UP, DOWN and ENTER
			if (msg.wParam == VK_ESCAPE)
				bBreak = true;
			else if (msg.wParam == VK_UP)
			{
				int iSel = GetCurSel();
				if (iSel == -1 || iSel == 0)
					SetCurSel(0);
				else
					SetCurSel(iSel - 1);
			}
			else if (msg.wParam == VK_DOWN)
			{
				// Move the selection 1 item down
				int iSel = GetCurSel();
				if (iSel == -1)
					SetCurSel(0);
				else if (iSel == GetCount() - 1)
				{
					// Do nothing
				}
				else
					SetCurSel(iSel + 1);
			}
			else if (msg.wParam == VK_RETURN)
			{
				iReturnItemIdx = GetCurSel();
				bBreak = true;
			}
		}
		else if (msg.message == WM_LBUTTONDOWN)
		{
			// Do nothing				
		}
		else if (msg.message == WM_MOUSEMOVE)
		{
			// Select the item under the mouse cursor
			int xPos = GET_X_LPARAM(msg.lParam); 
			int yPos = GET_Y_LPARAM(msg.lParam);

			BOOL bOutside;
			UINT nIndex = ItemFromPoint(CPoint(xPos, yPos), bOutside);
			if (!bOutside)
				SetCurSel((int) nIndex);
		}
		else
		{
			DispatchMessage(&msg);
		}
	}

	ReleaseCapture();
	ShowWindow(SW_HIDE);

	return iReturnItemIdx;
}
Exemplo n.º 23
0
LRESULT CALLBACK
winTopLevelWindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    POINT ptMouse;
    HDC hdcUpdate;
    PAINTSTRUCT ps;
    WindowPtr pWin = NULL;
    winPrivWinPtr pWinPriv = NULL;
    ScreenPtr s_pScreen = NULL;
    winPrivScreenPtr s_pScreenPriv = NULL;
    winScreenInfo *s_pScreenInfo = NULL;
    HWND hwndScreen = NULL;
    DrawablePtr pDraw = NULL;
    winWMMessageRec wmMsg;
    Bool fWMMsgInitialized = FALSE;
    static Bool s_fTracking = FALSE;
    Bool needRestack = FALSE;
    LRESULT ret;
    static Bool	hasEnteredSizeMove = FALSE;

    winDebugWin32Message("winTopLevelWindowProc", hwnd, message, wParam,
                         lParam);

    /* Check if the Windows window property for our X window pointer is valid */
    if ((pWin = GetProp(hwnd, WIN_WINDOW_PROP)) != NULL) {
        /* Our X window pointer is valid */

        /* Get pointers to the drawable and the screen */
        pDraw = &pWin->drawable;
        s_pScreen = pWin->drawable.pScreen;

        /* Get a pointer to our window privates */
        pWinPriv = winGetWindowPriv(pWin);

        /* Get pointers to our screen privates and screen info */
        s_pScreenPriv = pWinPriv->pScreenPriv;
        s_pScreenInfo = s_pScreenPriv->pScreenInfo;

        /* Get the handle for our screen-sized window */
        hwndScreen = s_pScreenPriv->hwndScreen;

        /* */
        wmMsg.msg = 0;
        wmMsg.hwndWindow = hwnd;
        wmMsg.iWindow = (Window) GetProp(hwnd, WIN_WID_PROP);

        wmMsg.iX = pDraw->x;
        wmMsg.iY = pDraw->y;
        wmMsg.iWidth = pDraw->width;
        wmMsg.iHeight = pDraw->height;

        fWMMsgInitialized = TRUE;

    }
#ifdef _DEBUG
    else if (message!=WM_CREATE)
    {
        winDebug("Warning: message 0x%x received when WIN_WINDOW_PROP NULL\n",message);
    }
#endif

    /* Branch on message type */
    switch (message) {
    case WM_CREATE:

        /* */
        SetProp(hwnd,
                WIN_WINDOW_PROP,
                (HANDLE) ((LPCREATESTRUCT) lParam)->lpCreateParams);

        /* */
        SetProp(hwnd,
                WIN_WID_PROP,
                (HANDLE) winGetWindowID(((LPCREATESTRUCT) lParam)->
                                        lpCreateParams));

        /*
         * Make X windows' Z orders sync with Windows windows because
         * there can be AlwaysOnTop windows overlapped on the window
         * currently being created.
         */
        winReorderWindowsMultiWindow();

        /* Fix a 'round title bar corner background should be transparent not black' problem when first painted */
        {
            RECT rWindow;
            HRGN hRgnWindow;

            GetWindowRect(hwnd, &rWindow);
            hRgnWindow = CreateRectRgnIndirect(&rWindow);
            SetWindowRgn(hwnd, hRgnWindow, TRUE);
        }

        SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)VCXSRV_SIGNATURE);

        return 0;

    case WM_INIT_SYS_MENU:
        /*
         * Add whatever the setup file wants to for this window
         */
        SetupSysMenu((unsigned long) hwnd);
        return 0;

    case WM_SYSCOMMAND:
        /*
         * Any window menu items go through here
         */
        if (HandleCustomWM_COMMAND((unsigned long) hwnd, LOWORD(wParam))) {
            /* Don't pass customized menus to DefWindowProc */
            return 0;
        }
        if (wParam == SC_RESTORE || wParam == SC_MAXIMIZE) {
            WINDOWPLACEMENT wndpl;

            wndpl.length = sizeof(wndpl);
            if (GetWindowPlacement(hwnd, &wndpl) &&
                    wndpl.showCmd == SW_SHOWMINIMIZED)
                needRestack = TRUE;
        }
        break;

    case WM_INITMENU:
        /* Checks/Unchecks any menu items before they are displayed */
        HandleCustomWM_INITMENU((unsigned long) hwnd, wParam);
        break;

    case WM_ERASEBKGND:
        /*
         * Pretend that we did erase the background but we don't care,
         * since we repaint the entire region anyhow
         * This avoids some flickering when resizing.
         */
        return TRUE;

    case WM_PAINT:
        /* Only paint if our window handle is valid */
        if (hwndScreen == NULL)
            break;

        /* BeginPaint gives us an hdc that clips to the invalidated region */
        hdcUpdate = BeginPaint(hwnd, &ps);
        /* Avoid the BitBlt's if the PAINTSTRUCT is bogus */
        if (ps.rcPaint.right == 0 && ps.rcPaint.bottom == 0 &&
                ps.rcPaint.left == 0 && ps.rcPaint.top == 0) {
            EndPaint(hwnd, &ps);
            return 0;
        }

#ifdef XWIN_GLX_WINDOWS
        if (pWinPriv->fWglUsed) {
            /*
               For regions which are being drawn by GL, the shadow framebuffer doesn't have the
               correct bits, so don't bitblt from the shadow framebuffer

               XXX: For now, just leave it alone, but ideally we want to send an expose event to
               the window so it really redraws the affected region...
             */
            ValidateRect(hwnd, &(ps.rcPaint));
        }
        else
#endif
            /* Try to copy from the shadow buffer */
            if (!BitBlt(hdcUpdate,
                        ps.rcPaint.left, ps.rcPaint.top,
                        ps.rcPaint.right - ps.rcPaint.left,
                        ps.rcPaint.bottom - ps.rcPaint.top,
                        s_pScreenPriv->hdcShadow,
                        ps.rcPaint.left + pWin->drawable.x,
                        ps.rcPaint.top + pWin->drawable.y, SRCCOPY)) {
                LPVOID lpMsgBuf;

                /* Display a fancy error message */
                FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
                              FORMAT_MESSAGE_FROM_SYSTEM |
                              FORMAT_MESSAGE_IGNORE_INSERTS,
                              NULL,
                              GetLastError(),
                              MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
                              (LPTSTR) &lpMsgBuf, 0, NULL);

                ErrorF("winTopLevelWindowProc - BitBlt failed: %s\n",
                       (LPSTR) lpMsgBuf);
                LocalFree(lpMsgBuf);
            }

        /* EndPaint frees the DC */
        EndPaint(hwnd, &ps);
        return 0;

    case WM_MOUSEMOVE:
        /* Unpack the client area mouse coordinates */
        ptMouse.x = GET_X_LPARAM(lParam);
        ptMouse.y = GET_Y_LPARAM(lParam);

        /* Translate the client area mouse coordinates to screen coordinates */
        ClientToScreen(hwnd, &ptMouse);

        /* Screen Coords from (-X, -Y) -> Root Window (0, 0) */
        ptMouse.x -= GetSystemMetrics(SM_XVIRTUALSCREEN);
        ptMouse.y -= GetSystemMetrics(SM_YVIRTUALSCREEN);

        /* We can't do anything without privates */
        if (s_pScreenPriv == NULL || s_pScreenInfo->fIgnoreInput)
            break;

        /* Has the mouse pointer crossed screens? */
        if (s_pScreen != miPointerGetScreen(g_pwinPointer))
            miPointerSetScreen(g_pwinPointer, s_pScreenInfo->dwScreen,
                               ptMouse.x - s_pScreenInfo->dwXOffset,
                               ptMouse.y - s_pScreenInfo->dwYOffset);

        /* Are we tracking yet? */
        if (!s_fTracking) {
            TRACKMOUSEEVENT tme;

            /* Setup data structure */
            ZeroMemory(&tme, sizeof(tme));
            tme.cbSize = sizeof(tme);
            tme.dwFlags = TME_LEAVE;
            tme.hwndTrack = hwnd;

            /* Call the tracking function */
            if (!TrackMouseEvent(&tme))
                ErrorF("winTopLevelWindowProc - TrackMouseEvent failed\n");

            /* Flag that we are tracking now */
            s_fTracking = TRUE;
        }

        /* Hide or show the Windows mouse cursor */
        if (g_fSoftwareCursor && g_fCursor) {
            /* Hide Windows cursor */
            g_fCursor = FALSE;
            ShowCursor(FALSE);
        }

        /* Kill the timer used to poll mouse events */
        if (g_uipMousePollingTimerID != 0) {
            KillTimer(s_pScreenPriv->hwndScreen, WIN_POLLING_MOUSE_TIMER_ID);
            g_uipMousePollingTimerID = 0;
        }

        /* Deliver absolute cursor position to X Server */
        winEnqueueMotion(ptMouse.x - s_pScreenInfo->dwXOffset,
                         ptMouse.y - s_pScreenInfo->dwYOffset);

        return 0;

    case WM_NCMOUSEMOVE:
        /*
         * We break instead of returning 0 since we need to call
         * DefWindowProc to get the mouse cursor changes
         * and min/max/close button highlighting in Windows XP.
         * The Platform SDK says that you should return 0 if you
         * process this message, but it fails to mention that you
         * will give up any default functionality if you do return 0.
         */

        /* We can't do anything without privates */
        if (s_pScreenPriv == NULL || s_pScreenInfo->fIgnoreInput)
            break;

        /* Non-client mouse movement, show Windows cursor */
        if (g_fSoftwareCursor && !g_fCursor) {
            g_fCursor = TRUE;
            ShowCursor(TRUE);
        }

        winStartMousePolling(s_pScreenPriv);

        break;

    case WM_MOUSELEAVE:
        /* We can't do anything without privates */
        if (s_pScreenPriv == NULL || s_pScreenInfo->fIgnoreInput)
            break;
        /* Mouse has left our client area */

        /* Flag that we are no longer tracking */
        s_fTracking = FALSE;

        /* Show the mouse cursor, if necessary */
        if (g_fSoftwareCursor && !g_fCursor) {
            g_fCursor = TRUE;
            ShowCursor(TRUE);
        }

        winStartMousePolling(s_pScreenPriv);

        return 0;

    case WM_LBUTTONDBLCLK:
    case WM_LBUTTONDOWN:
        if (s_pScreenPriv == NULL || s_pScreenInfo->fIgnoreInput)
            break;
        g_fButton[0] = TRUE;
        SetCapture(hwnd);
        return winMouseButtonsHandle(s_pScreen, ButtonPress, Button1, wParam);

    case WM_LBUTTONUP:
        if (s_pScreenPriv == NULL || s_pScreenInfo->fIgnoreInput)
            break;
        g_fButton[0] = FALSE;
        ReleaseCapture();
        winStartMousePolling(s_pScreenPriv);
        return winMouseButtonsHandle(s_pScreen, ButtonRelease, Button1, wParam);

    case WM_MBUTTONDBLCLK:
    case WM_MBUTTONDOWN:
        if (s_pScreenPriv == NULL || s_pScreenInfo->fIgnoreInput)
            break;
        g_fButton[1] = TRUE;
        SetCapture(hwnd);
        return winMouseButtonsHandle(s_pScreen, ButtonPress, Button2, wParam);

    case WM_MBUTTONUP:
        if (s_pScreenPriv == NULL || s_pScreenInfo->fIgnoreInput)
            break;
        g_fButton[1] = FALSE;
        ReleaseCapture();
        winStartMousePolling(s_pScreenPriv);
        return winMouseButtonsHandle(s_pScreen, ButtonRelease, Button2, wParam);

    case WM_RBUTTONDBLCLK:
    case WM_RBUTTONDOWN:
        if (s_pScreenPriv == NULL || s_pScreenInfo->fIgnoreInput)
            break;
        g_fButton[2] = TRUE;
        SetCapture(hwnd);
        return winMouseButtonsHandle(s_pScreen, ButtonPress, Button3, wParam);

    case WM_RBUTTONUP:
        if (s_pScreenPriv == NULL || s_pScreenInfo->fIgnoreInput)
            break;
        g_fButton[2] = FALSE;
        ReleaseCapture();
        winStartMousePolling(s_pScreenPriv);
        return winMouseButtonsHandle(s_pScreen, ButtonRelease, Button3, wParam);

    case WM_XBUTTONDBLCLK:
    case WM_XBUTTONDOWN:
        if (s_pScreenPriv == NULL || s_pScreenInfo->fIgnoreInput)
            break;
        SetCapture(hwnd);
        return winMouseButtonsHandle(s_pScreen, ButtonPress, HIWORD(wParam) + 5,
                                     wParam);

    case WM_XBUTTONUP:
        if (s_pScreenPriv == NULL || s_pScreenInfo->fIgnoreInput)
            break;
        ReleaseCapture();
        winStartMousePolling(s_pScreenPriv);
        return winMouseButtonsHandle(s_pScreen, ButtonRelease,
                                     HIWORD(wParam) + 5, wParam);

    case WM_MOUSEWHEEL:
        if (SendMessage
                (hwnd, WM_NCHITTEST, 0,
                 MAKELONG(GET_X_LPARAM(lParam),
                          GET_Y_LPARAM(lParam))) == HTCLIENT) {
            /* Pass the message to the root window */
            SendMessage(hwndScreen, message, wParam, lParam);
            return 0;
        }
        else
            break;

    case WM_SETFOCUS:
        if (s_pScreenPriv == NULL || s_pScreenInfo->fIgnoreInput)
            break;

        {
            /* Get the parent window for transient handling */
            HWND hParent = GetParent(hwnd);

            if (hParent && IsIconic(hParent))
                ShowWindow(hParent, SW_RESTORE);
        }

        winRestoreModeKeyStates();

        /* Add the keyboard hook if possible */
        if (g_fKeyboardHookLL)
            g_fKeyboardHookLL = winInstallKeyboardHookLL();
        return 0;

    case WM_KILLFOCUS:
        /* Pop any pressed keys since we are losing keyboard focus */
        winKeybdReleaseKeys();

        /* Remove our keyboard hook if it is installed */
        winRemoveKeyboardHookLL();

        /* Revert the X focus as well, but only if the Windows focus is going to another window */
        if (!wParam && pWin)
            DeleteWindowFromAnyEvents(pWin, FALSE);

        return 0;

    case WM_SYSDEADCHAR:
    case WM_DEADCHAR:
        /*
         * NOTE: We do nothing with WM_*CHAR messages,
         * nor does the root window, so we can just toss these messages.
         */
        return 0;

    case WM_SYSKEYDOWN:
    case WM_KEYDOWN:

        /*
         * Don't pass Alt-F4 key combo to root window,
         * let Windows translate to WM_CLOSE and close this top-level window.
         *
         * NOTE: We purposely don't check the fUseWinKillKey setting because
         * it should only apply to the key handling for the root window,
         * not for top-level window-manager windows.
         *
         * ALSO NOTE: We do pass Ctrl-Alt-Backspace to the root window
         * because that is a key combo that no X app should be expecting to
         * receive, since it has historically been used to shutdown the X server.
         * Passing Ctrl-Alt-Backspace to the root window preserves that
         * behavior, assuming that -unixkill has been passed as a parameter.
         */
        if (wParam == VK_F4 && (GetKeyState(VK_MENU) & 0x8000))
            break;

#ifdef WINDBG
        if (wParam == VK_ESCAPE) {
            /* Place for debug: put any tests and dumps here */
            WINDOWPLACEMENT windPlace;
            RECT rc;
            LPRECT pRect;

            windPlace.length = sizeof(WINDOWPLACEMENT);
            GetWindowPlacement(hwnd, &windPlace);
            pRect = &windPlace.rcNormalPosition;
            winDebug ("\nCYGWINDOWING Dump:\n"
                      "\tdrawable: (%hd, %hd) - %hdx%hd\n", pDraw->x,
                      pDraw->y, pDraw->width, pDraw->height);
            winDebug ("\twindPlace: (%ld, %ld) - %ldx%ld\n", pRect->left,
                      pRect->top, pRect->right - pRect->left,
                      pRect->bottom - pRect->top);
            if (GetClientRect(hwnd, &rc)) {
                pRect = &rc;
                winDebug ("\tClientRect: (%ld, %ld) - %ldx%ld\n", pRect->left,
                          pRect->top, pRect->right - pRect->left,
                          pRect->bottom - pRect->top);
            }
            if (GetWindowRect(hwnd, &rc)) {
                pRect = &rc;
                winDebug ("\tWindowRect: (%ld, %ld) - %ldx%ld\n", pRect->left,
                          pRect->top, pRect->right - pRect->left,
                          pRect->bottom - pRect->top);
            }
            winDebug ("\n");
        }
#endif

        /* Pass the message to the root window */
        return winWindowProc(hwndScreen, message, wParam, lParam);

    case WM_SYSKEYUP:
    case WM_KEYUP:

        /* Pass the message to the root window */
        return winWindowProc(hwndScreen, message, wParam, lParam);

    case WM_HOTKEY:

        /* Pass the message to the root window */
        SendMessage(hwndScreen, message, wParam, lParam);
        return 0;

    case WM_ACTIVATE:

        /* Pass the message to the root window */
        SendMessage(hwndScreen, message, wParam, lParam);

        if (LOWORD(wParam) != WA_INACTIVE) {
            /* Raise the window to the top in Z order */
            /* ago: Activate does not mean putting it to front! */
            /*
               wmMsg.msg = WM_WM_RAISE;
               if (fWMMsgInitialized)
               winSendMessageToWM (s_pScreenPriv->pWMInfo, &wmMsg);
             */

            /* Tell our Window Manager thread to activate the window */
            wmMsg.msg = WM_WM_ACTIVATE;
            if (fWMMsgInitialized && pWin->realized && !pWin->overrideRedirect /* for OOo menus */)
                winSendMessageToWM (s_pScreenPriv->pWMInfo, &wmMsg);
        }
        /* Prevent the mouse wheel from stalling when another window is minimized */
        if (HIWORD(wParam) == 0 && LOWORD(wParam) == WA_ACTIVE &&
                (HWND) lParam != NULL && (HWND) lParam != (HWND) GetParent(hwnd))
            SetFocus(hwnd);
        return 0;

    case WM_ACTIVATEAPP:
        /*
         * This message is also sent to the root window
         * so we do nothing for individual multiwindow windows
         */
        break;

    case WM_CLOSE:
        /* Removep AppUserModelID property */
        winSetAppUserModelID(hwnd, NULL);
        /* Branch on if the window was killed in X already */
        if (pWinPriv->fXKilled) {
            /* Window was killed, go ahead and destroy the window */
            DestroyWindow(hwnd);
        }
        else {
            /* Tell our Window Manager thread to kill the window */
            wmMsg.msg = WM_WM_KILL;
            if (fWMMsgInitialized)
                winSendMessageToWM(s_pScreenPriv->pWMInfo, &wmMsg);
        }
        return 0;

    case WM_DESTROY:

        /* Branch on if the window was killed in X already */
        if (pWinPriv && !pWinPriv->fXKilled) {
            winDebug ("winTopLevelWindowProc - WM_DESTROY - WM_WM_KILL\n");

            /* Tell our Window Manager thread to kill the window */
            wmMsg.msg = WM_WM_KILL;
            if (fWMMsgInitialized)
                winSendMessageToWM(s_pScreenPriv->pWMInfo, &wmMsg);
        }

        RemoveProp(hwnd, WIN_WINDOW_PROP);
        RemoveProp(hwnd, WIN_WID_PROP);
        RemoveProp(hwnd, WIN_NEEDMANAGE_PROP);

        break;

    case WM_MOVE:
        /* Adjust the X Window to the moved Windows window */
        if (!hasEnteredSizeMove) winAdjustXWindow (pWin, hwnd);
        /* else: Wait for WM_EXITSIZEMOVE */
        return 0;

    case WM_SHOWWINDOW:
        /* Bail out if the window is being hidden */
        if (!wParam)
            return 0;

        /* */
        if (!pWin->overrideRedirect) {
            HWND zstyle = HWND_NOTOPMOST;

            /* Flag that this window needs to be made active when clicked */
            SetProp(hwnd, WIN_NEEDMANAGE_PROP, (HANDLE) 1);

            /* Set the transient style flags */
            if (GetParent(hwnd))
                SetWindowLongPtr(hwnd, GWL_STYLE,
                                 WS_POPUP | WS_OVERLAPPED | WS_SYSMENU |
                                 WS_CLIPCHILDREN | WS_CLIPSIBLINGS);
            /* Set the window standard style flags */
            else
                SetWindowLongPtr(hwnd, GWL_STYLE,
                                 (WS_POPUP | WS_OVERLAPPEDWINDOW |
                                  WS_CLIPCHILDREN | WS_CLIPSIBLINGS)
                                 & ~WS_CAPTION & ~WS_SIZEBOX);

            winUpdateWindowPosition(hwnd, &zstyle);

            {
                WinXWMHints hints;

                if (winMultiWindowGetWMHints(pWin, &hints)) {
                    /*
                       Give the window focus, unless it has an InputHint
                       which is FALSE (this is used by e.g. glean to
                       avoid every test window grabbing the focus)
                     */
                    if (!((hints.flags & InputHint) && (!hints.input))) {
                        SetForegroundWindow(hwnd);
                    }
                }
            }
            wmMsg.msg = WM_WM_MAP3;
        }
        else {                  /* It is an overridden window so make it top of Z stack */

            HWND forHwnd = GetForegroundWindow();
            winDebug ("overridden window is shown\n");
            if (forHwnd != NULL) {
                if (GetWindowLongPtr(forHwnd, GWLP_USERDATA) & (LONG_PTR)
                        VCXSRV_SIGNATURE) {
                    if (GetWindowLongPtr(forHwnd, GWL_EXSTYLE) & WS_EX_TOPMOST)
                        SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, 0, 0,
                                     SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
                    else
                        SetWindowPos(hwnd, HWND_NOTOPMOST, 0, 0, 0, 0,
                                     SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
                }
            }
            wmMsg.msg = WM_WM_MAP2;
        }

        /* Tell our Window Manager thread to map the window */
        if (fWMMsgInitialized)
            winSendMessageToWM(s_pScreenPriv->pWMInfo, &wmMsg);

        winStartMousePolling(s_pScreenPriv);

        return 0;

    case WM_SIZING:
        /* Need to legalize the size according to WM_NORMAL_HINTS */
        /* for applications like xterm */
        return ValidateSizing(hwnd, pWin, wParam, lParam);

    case WM_WINDOWPOSCHANGING:
    {
        /*
          When window is moved or resized, force it to be redrawn, so that
          any OpenGL content is re-drawn correctly, rather than copying bits
          (which seem to be wrong, either because we are copying the wrong
          window in the window heirarchy, or because we don't have the bits
          drawn by OpenGL at all)

          XXX: really this should check if any child has fWglUsed set, but
          that might be expensive to check....
         */
        if (g_fNativeGl)
        {
            LPWINDOWPOS pWinPos = (LPWINDOWPOS)lParam;
            pWinPos->flags |= SWP_NOCOPYBITS;
        }
    }
    break;

    case WM_WINDOWPOSCHANGED:
    {
        LPWINDOWPOS pWinPos = (LPWINDOWPOS) lParam;

        if (!(pWinPos->flags & SWP_NOZORDER)) {
#if CYGWINDOWING_DEBUG
            winDebug("\twindow z order was changed\n");
#endif
            if (pWinPos->hwndInsertAfter == HWND_TOP
                    || pWinPos->hwndInsertAfter == HWND_TOPMOST
                    || pWinPos->hwndInsertAfter == HWND_NOTOPMOST) {
#if CYGWINDOWING_DEBUG
                winDebug("\traise to top\n");
#endif
                /* Raise the window to the top in Z order */
                winRaiseWindow(pWin);
            }
            else if (pWinPos->hwndInsertAfter == HWND_BOTTOM) {
            }
            else {
                /* Check if this window is top of X windows. */
                HWND hWndAbove = NULL;
                DWORD dwCurrentProcessID = GetCurrentProcessId();
                DWORD dwWindowProcessID = 0;

                for (hWndAbove = pWinPos->hwndInsertAfter;
                        hWndAbove != NULL;
                        hWndAbove = GetNextWindow(hWndAbove, GW_HWNDPREV)) {
                    /* Ignore other XWin process's window */
                    GetWindowThreadProcessId(hWndAbove, &dwWindowProcessID);

                    if ((dwWindowProcessID == dwCurrentProcessID)
                            && GetProp(hWndAbove, WIN_WINDOW_PROP)
                            && !IsWindowVisible(hWndAbove)
                            && !IsIconic(hWndAbove))        /* ignore minimized windows */
                        break;
                }
                /* If this is top of X windows in Windows stack,
                   raise it in X stack. */
                if (hWndAbove == NULL) {
#if CYGWINDOWING_DEBUG
                    winDebug("\traise to top\n");
#endif
                    winRaiseWindow(pWin);
                }
            }
        }
    }
        /*
         * Pass the message to DefWindowProc to let the function
         * break down WM_WINDOWPOSCHANGED to WM_MOVE and WM_SIZE.
         */
    break;

    case WM_ENTERSIZEMOVE:
        hasEnteredSizeMove = TRUE;
        return 0;

    case WM_EXITSIZEMOVE:
        /* Adjust the X Window to the moved Windows window */
        hasEnteredSizeMove = FALSE;
        winAdjustXWindow (pWin, hwnd);
        return 0;

    case WM_SIZE:
        /* see dix/window.c */
#ifdef WINDBG
    {
        char buf[64];

        switch (wParam) {
        case SIZE_MINIMIZED:
            strcpy(buf, "SIZE_MINIMIZED");
            break;
        case SIZE_MAXIMIZED:
            strcpy(buf, "SIZE_MAXIMIZED");
            break;
        case SIZE_RESTORED:
            strcpy(buf, "SIZE_RESTORED");
            break;
        default:
            strcpy(buf, "UNKNOWN_FLAG");
        }
        winDebug ("winTopLevelWindowProc - WM_SIZE to %dx%d (%s) - %d ms\n",
                  (int) LOWORD(lParam), (int) HIWORD(lParam), buf,
                  (int) (GetTickCount()));
    }
#endif
    if (!hasEnteredSizeMove)
    {
        /* Adjust the X Window to the moved Windows window */
        winAdjustXWindow (pWin, hwnd);
        if (wParam == SIZE_MINIMIZED) winReorderWindowsMultiWindow();
    }
        /* else: wait for WM_EXITSIZEMOVE */
        return 0; /* end of WM_SIZE handler */

    case WM_STYLECHANGED:
        /* when the style changes, adjust the window size so the client area remains the same */
    {
        LONG x,y;
        DrawablePtr pDraw = &pWin->drawable;
        x =  pDraw->x - wBorderWidth(pWin);
        y = pDraw->y - wBorderWidth(pWin);
        winPositionWindowMultiWindow(pWin, x, y);
    }
    return 0;

    case WM_MOUSEACTIVATE:

        /* Check if this window needs to be made active when clicked */
        if (!GetProp(pWinPriv->hWnd, WIN_NEEDMANAGE_PROP)) {
            winDebug ("winTopLevelWindowProc - WM_MOUSEACTIVATE - "
                      "MA_NOACTIVATE\n");

            /* */
            return MA_NOACTIVATE;
        }
        break;

    case WM_SETCURSOR:
        if (LOWORD(lParam) == HTCLIENT) {
            if (!g_fSoftwareCursor)
                SetCursor(s_pScreenPriv->cursor.handle);
            return TRUE;
        }
        break;

    default:
        break;
    }

    ret = DefWindowProc(hwnd, message, wParam, lParam);
    /*
     * If the window was minized we get the stack change before the window is restored
     * and so it gets lost. Ensure there stacking order is correct.
     */
    if (needRestack)
        winReorderWindowsMultiWindow();
    return ret;
}
Exemplo n.º 24
0
long WINPROC EXPORT SpinControl(
	HWND     hWindow,
	unsigned message,
	WPARAM   wParam,
	LPARAM   lParam)
{
	int    y;
	RECT   ClientRect;
	PAINTSTRUCT ps;
	HDC    hDC;
	BOOL   bDown;
	DWORD  dwStyle;
	long   lReturn;
	static BOOL bTrack, bInTopRect, bInBottomRect;

	switch ( message )
	{
		case WM_GETDLGCODE:
			return( DLGC_WANTARROWS );

		case WM_ERASEBKGND:
		break; // handle ERASEBKGND and do nothing; PAINT covers everything

		case WM_PAINT:
			hDC = BeginPaint( hWindow, &ps );
			GetClientRect( hWindow, &ClientRect );

			y = ClientRect.bottom;
			ClientRect.bottom =
				1 + ( ClientRect.top + ClientRect.bottom + 1 ) / 2;

			if ( ClientRect.bottom & 1 )
				ClientRect.bottom++; // make sure its even

			bDown = bInTopRect && bTrack;
			DrawSpin( hDC, &ClientRect, 1, bDown );
			ClientRect.top = ClientRect.bottom;
			ClientRect.bottom = y;
			bDown = bInBottomRect && bTrack;
			DrawSpin( hDC, &ClientRect, 0, bDown );
//			dwStyle = GetWindowLong(GetDlgItem( GetParent(hWindow),
//			GET_WINDOW_ID(hWindow) ), GWL_STYLE);
//			if ( WS_NOTENABLED & dwStyle )
//				GrayWindow( hDC, hWindow, -1L );
			EndPaint( hWindow, &ps );
		break;

   	case WM_LBUTTONDOWN:
			dwStyle = GetWindowLong(GetDlgItem( GetParent(hWindow),
			GET_WINDOW_ID(hWindow) ), GWL_STYLE);
			if ( WS_NOTENABLED & dwStyle )
				break;
			if ( bTrack )
				break;
			SetCapture( hWindow ); bTrack = TRUE;
			SetFocus( GetDlgItem( GetParent(hWindow),
				GET_WINDOW_ID(hWindow) ) );
			GetClientRect( hWindow, &ClientRect );
			ClientRect.bottom =
				( ClientRect.top + ClientRect.bottom + 1 ) / 2;
			bInTopRect = PtInRect( &ClientRect, MAKEPOINT(lParam) );
			bInBottomRect = !bInTopRect;
			InvalidateRect( hWindow, NULL, FALSE );
			UpdateWindow( hWindow );
			SetTimer( hWindow, bTrack, 500, NULL );
		break;

		case WM_LBUTTONUP:
			if ( !bTrack )
				break;
			KillTimer( hWindow, bTrack );
			ReleaseCapture(); bTrack = FALSE;
			InvalidateRect( hWindow, NULL, FALSE );
			UpdateWindow( hWindow );
			HandleSpinValue( hWindow, bInTopRect, bInBottomRect );
		break;

		case WM_TIMER:
			if ( !bTrack )
				break;
			KillTimer( hWindow, bTrack );
			SetTimer( hWindow, bTrack, 100, NULL );
			HandleSpinValue( hWindow, bInTopRect, bInBottomRect );
		break;

		case WM_LBUTTONDBLCLK:
		break;

		case WM_MOUSEMOVE:
			if ( !bTrack )
				break;
			GetClientRect( hWindow, &ClientRect );
			y = ClientRect.bottom;
			ClientRect.bottom = ( ClientRect.top + ClientRect.bottom ) / 2;
			if ( bInTopRect == !PtInRect( &ClientRect, MAKEPOINT(lParam) ) )
			{
				bInTopRect = !bInTopRect;
				InvalidateRect( hWindow, NULL, FALSE );
				UpdateWindow( hWindow );
			}
			ClientRect.top = ClientRect.bottom;
			ClientRect.bottom = y;
			if ( bInBottomRect == !PtInRect( &ClientRect, MAKEPOINT(lParam) ) )
			{
				bInBottomRect = !bInBottomRect;
				InvalidateRect( hWindow, NULL, FALSE );
				UpdateWindow( hWindow );
			}
		break;

		case WM_ENABLE:
		case WM_SETTEXT:
			lReturn = DefWindowProc( hWindow, message, wParam, lParam );
			InvalidateRect( hWindow, NULL, FALSE );
			UpdateWindow(hWindow);
			return(lReturn);
		break;

		case WM_DESTROY:
			if ( !bTrack )
				break;
			ReleaseCapture();
			bTrack = NO;
		break;

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

	return( TRUE );
}
Exemplo n.º 25
0
static LRESULT APIENTRY LevelControlWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
	LevelControlData *lcd = (LevelControlData *)GetWindowLongPtr(hwnd, 0);

	switch(msg) {

	case WM_NCCREATE:
		if (!(lcd = new LevelControlData))
			return FALSE;
		memset(lcd,0,sizeof(LevelControlData));

		lcd->nTabs		= 3;
		lcd->iPos[0]	= 0;
		lcd->rgbTab[0]	= 0xFFFFFF;
		lcd->rgbLow		= 0x000000;
		lcd->rgbHigh	= 0xFFFFFF;
		lcd->iMovingTab	= -1;

		SetWindowLongPtr(hwnd, 0, (LONG_PTR)lcd);
		return TRUE;

	case WM_CREATE:
	case WM_SIZE:
		LevelControlResize(hwnd, lcd);
		break;

	case WM_DESTROY:
		delete lcd;
		SetWindowLongPtr(hwnd, 0, 0);
		break;

	case WM_PAINT:
		{
			PAINTSTRUCT ps;
			HDC hdc;
			int i, x, w, h;
			RECT r;

			hdc = BeginPaint(hwnd, &ps);

			w = lcd->w;
			h = lcd->rColorBand.bottom - lcd->rColorBand.top;

			if (RectVisible(hdc, &lcd->rColorBand)) {
				int dr, dg, db;
				int xlo, xhi;
				RECT rClip;

				dr = (signed long)(lcd->rgbHigh&0xff) - (signed long)(lcd->rgbLow&0xff);
				dg = ((signed long)(lcd->rgbHigh&0xff00) - (signed long)(lcd->rgbLow&0xff00))>>8;
				db = ((signed long)(lcd->rgbHigh&0xff0000) - (signed long)(lcd->rgbLow&0xff0000))>>16;

				r = lcd->rColorBand;
				xlo = 0;
				xhi = w;

				i = GetClipBox(hdc, &rClip);

				if (i!=ERROR && i!=NULLREGION) {
					RECT rClip2;

					IntersectRect(&rClip2, &r, &rClip);

					xlo = rClip2.left - r.left;
					xhi = rClip2.right - r.left;
				}

				for(x=xlo; x<xhi; x++) {
					HBRUSH hbr;
					COLORREF cr;

					r.left = lcd->rColorBand.left + x;
					r.right = r.left+1;

					cr	= lcd->rgbLow
						+  ((dr*x + w/2)/w)
						+ (((dg*x + w/2)/w) << 8)
						+ (((db*x + w/2)/w) << 16);

					if (hbr = CreateSolidBrush(cr)) {
						FillRect(hdc, &r, hbr);
						DeleteObject(hbr);
					}
				}
			}

			for(i=0; i<lcd->nTabs; i++) {
				POINT pt[3];
				HBRUSH hbr;
				HGDIOBJ hgoOld;

				pt[0].x = lcd->iPixPos[i];
				pt[1].x = lcd->iPixPos[i]+lcd->iTabW;
				pt[2].x = lcd->iPixPos[i]+2*lcd->iTabW;
				pt[0].y = pt[2].y = lcd->rColorBand.bottom+lcd->iTabH-1;
				pt[1].y = lcd->rColorBand.bottom;

				if (hbr = CreateSolidBrush(lcd->rgbTab[i]))
					hgoOld = SelectObject(hdc, hbr);

				Polygon(hdc, pt, 3);

				if (hbr)
					DeleteObject(SelectObject(hdc, hgoOld));
			}

			EndPaint(hwnd, &ps);
		}
		break;

	case WM_LBUTTONDOWN:
		{
			int x = LOWORD(lParam);
			int y = HIWORD(lParam);

			if (y >= lcd->rColorBand.bottom && y<lcd->rColorBand.bottom+lcd->iTabH) {
				int i;
				int best_tab = -1, best_dx = 100;

				for(i=0; i<lcd->nTabs; i++) {
					int dx = (x-lcd->iTabW) - lcd->iPixPos[i];
					int adx = abs(dx);

					// Pick the closest tab to cursor; if tabs are on the same
					// position, pick the lowest tab if mouse is to the left and
					// the highest tab if mouse is to the right

					if (adx < 8 && (best_tab == -1 || adx < best_dx ||
						(adx == best_dx && dx>0))) {

						best_dx = adx;
						best_tab = i;
					}

				}
				if (best_tab >= 0) {
					SetCapture(hwnd);
					lcd->iMovingTab = best_tab;
					lcd->iMovingOffset = x - lcd->iPixPos[best_tab];
				}
			}
		}
		break;

	case WM_LBUTTONUP:
		if (lcd->iMovingTab>=0) {
			ReleaseCapture();
			lcd->iMovingTab = -1;
		}
		break;

	case WM_MOUSEMOVE:
		if (lcd->iMovingTab>=0) {
			int pos, pixpos;
			RECT r;

			pixpos = (int)(signed short)LOWORD(lParam) - lcd->iMovingOffset;
			pos = LevelPixelToRatio(pixpos, lcd->w);

			// clip position against spectrum

			if (pixpos<0) {
				pos = 0;
				pixpos = 0;
			} else if (pixpos >= lcd->rColorBand.right - lcd->rColorBand.left) {
				pixpos = lcd->rColorBand.right - lcd->rColorBand.left - 1;
				pos = 0xFFFF;
			}

			// don't let tabs pass each other

			if (lcd->iMovingTab>0 && pos < lcd->iPos[lcd->iMovingTab-1]) {
				pos = lcd->iPos[lcd->iMovingTab-1];
				pixpos = lcd->iPixPos[lcd->iMovingTab-1];
			} else if (lcd->iMovingTab < lcd->nTabs-1 && pos > lcd->iPos[lcd->iMovingTab+1]) {
				pos = lcd->iPos[lcd->iMovingTab+1];
				pixpos = lcd->iPixPos[lcd->iMovingTab+1];
			}

			// render changes

			r.left = lcd->iPixPos[lcd->iMovingTab];
			r.right = lcd->iPixPos[lcd->iMovingTab]+2*lcd->iTabW+1;
			r.top = lcd->rColorBand.bottom;
			r.bottom = r.top + lcd->iTabH;

			InvalidateRect(hwnd, &r, TRUE);

			lcd->iPos[lcd->iMovingTab] = pos;
			lcd->iPixPos[lcd->iMovingTab] = pixpos;

			r.left = pixpos;
			r.right = pixpos+2*lcd->iTabW+1;

			InvalidateRect(hwnd, &r, TRUE);

			UpdateWindow(hwnd);

			// send notification message to parent window

			NMVLTABCHANGE nmvltc;

			nmvltc.hdr.code		= VLCN_TABCHANGE;
			nmvltc.hdr.hwndFrom	= hwnd;
			nmvltc.hdr.idFrom	= GetWindowLong(hwnd, GWL_ID);
			nmvltc.iTab			= lcd->iMovingTab;
			nmvltc.iNewPos		= pos;

			SendMessage(GetParent(hwnd), WM_NOTIFY, nmvltc.hdr.idFrom, (LPARAM)&nmvltc);
		}
		break;

	case VLCM_SETTABCOUNT:
		lcd->nTabs = lParam;
		if (wParam)
			InvalidateRect(hwnd, &lcd->rTabBand, TRUE);
		break;

	case VLCM_SETTABCOLOR:
		lcd->rgbTab[LOWORD(wParam)] = lParam;
		if (HIWORD(wParam))
			InvalidateRect(hwnd, &lcd->rTabBand, TRUE);
		break;

	case VLCM_MOVETABPOS:
	case VLCM_SETTABPOS:
		lcd->iPos[LOWORD(wParam)] = lParam;
		lcd->iPixPos[LOWORD(wParam)] = LevelRatioToPixel(lParam, lcd->w);
		if (HIWORD(wParam))
			InvalidateRect(hwnd, &lcd->rTabBand, TRUE);

		if (msg == VLCM_MOVETABPOS) {
			NMVLTABCHANGE nmvltc;

			nmvltc.hdr.code		= VLCN_TABCHANGE;
			nmvltc.hdr.hwndFrom	= hwnd;
			nmvltc.hdr.idFrom	= GetWindowLong(hwnd, GWL_ID);
			nmvltc.iTab			= LOWORD(wParam);
			nmvltc.iNewPos		= lParam;

			SendMessage(GetParent(hwnd), WM_NOTIFY, nmvltc.hdr.idFrom, (LPARAM)&nmvltc);
		}
		break;

	case VLCM_SETGRADIENT:
		lcd->rgbLow = wParam;
		lcd->rgbHigh = lParam;
		InvalidateRect(hwnd, &lcd->rColorBand, FALSE);
		break;

	default:
		return DefWindowProc(hwnd, msg, wParam, lParam);
	}
Exemplo n.º 26
0
void CBGridCtrl::OnLButtonDown(UINT nFlags, CPoint point)
{
    HWND hOldFocusWnd = ::GetFocus();

	nFlags=1;
	BOOL m_IsSort=FALSE;
	if(m_SortColumn!=-1)
       m_IsSort=TRUE;
	if(m_idCurrentCell.row>0)
	   m_CurrSortCell=m_idCurrentCell ;
	m_CurrrSortClick=FALSE;
    m_BeforeRow=m_idCurrentCell.row;




    m_LeftClickDownPoint = point;
    m_LeftClickDownCell = GetCellFromPt(point);
    if (!IsValid(m_LeftClickDownCell)) return;

    m_SelectionStartCell = (nFlags & MK_SHIFT)? m_idCurrentCell : m_LeftClickDownCell;

    SetFocus();        
    if (m_LeftClickDownCell == m_idCurrentCell)
    {
        m_MouseMode = MOUSE_PREPARE_EDIT;
		return;
    } else {
        SetFocusCell(-1,-1);
        SetFocusCell(max(m_LeftClickDownCell.row, m_nFixedRows),
                    max(m_LeftClickDownCell.col, m_nFixedCols));//Do not modify the contents of this file.
    }

   
    if (m_bAllowDragAndDrop && hOldFocusWnd == GetSafeHwnd() && 
        GetItemState(m_LeftClickDownCell.row, m_LeftClickDownCell.col) & GVNI_SELECTED)
    {
        m_MouseMode = MOUSE_PREPARE_DRAG;
        return;
    }


    SetCapture();
// 股票列表视图的列变量定义,以及自定义列的表达式计算

    if (m_MouseMode == MOUSE_OVER_COL_DIVIDE) 
    {
        m_MouseMode = MOUSE_SIZING_COL;
        CPoint start;
        if (!GetCellOrigin(0, m_LeftClickDownCell.col, &start)) return;

        CRect rect;
        GetClientRect(rect);
        CRect invertedRect(point.x, rect.top, point.x + 2, rect.bottom);

        CDC* pDC = GetDC();
        if (pDC) {
            pDC->InvertRect(&invertedRect);
            ReleaseDC(pDC);//Do not modify the contents of this file.
        }

        if (point.x - start.x <= m_nResizeCaptureRange)       
            if (!GetCellOrigin(0, --m_LeftClickDownCell.col, &start)) return;

        rect.left = start.x;
        ClientToScreen(rect);
        ClipCursor(rect);
    }
    else if (m_MouseMode == MOUSE_OVER_ROW_DIVIDE)
    {
        m_MouseMode = MOUSE_SIZING_ROW;
        CPoint start;
        if (!GetCellOrigin(m_LeftClickDownCell, &start)) return;

        CRect rect;
        GetClientRect(rect);
        CRect invertedRect(rect.left, point.y, rect.right, point.y + 2);

        CDC* pDC = GetDC();
        if (pDC) {
            pDC->InvertRect(&invertedRect);
            ReleaseDC(pDC);
        }

        if (point.y - start.y <= m_nResizeCaptureRange)           
            if (!GetCellOrigin(--m_LeftClickDownCell.row, 0, &start)) return;

        rect.top = start.y;
        ClientToScreen(rect);
        ClipCursor(rect);//Do not modify the contents of this file.
    }
    else 
    {    
        
		if (m_LeftClickDownCell.row < GetFixedRowCount())
		{
		
	        m_CurrrSortClick=TRUE;
            OnFixedRowClick(m_LeftClickDownCell);// NOTE: the ClassWizard will add member functions here
		}
        else if (m_LeftClickDownCell.col < GetFixedColumnCount())
		{
	        m_CurrrSortClick=FALSE;
			OnFixedColumnClick(m_LeftClickDownCell);
		}
        else
        {
	        m_CurrrSortClick=FALSE;// NOTE: the ClassWizard will add member functions here
            m_MouseMode = m_bListMode? MOUSE_SELECT_ROW : MOUSE_SELECT_CELLS;
            OnSelecting(m_LeftClickDownCell);
        }

        m_nTimerID = SetTimer(WM_LBUTTONDOWN, m_nTimerInterval, 0);
    }   
    m_LastMousePoint = point;
    m_CurrSortCell=m_idCurrentCell ;
}
Exemplo n.º 27
0
/*******************************************************************************
 *
 *  FUNCTION: ChildWndProc(HWND, unsigned, WORD, LONG)
 *
 *  PURPOSE:  Processes messages for the child windows.
 *
 *  WM_COMMAND  - process the application menu
 *  WM_PAINT    - Paint the main window
 *  WM_DESTROY  - post a quit message and return
 *
 */
LRESULT CALLBACK ChildWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    switch (message) {
    case WM_CREATE:
        g_pChildWnd = HeapAlloc(GetProcessHeap(), 0, sizeof(ChildWnd));
        if (!g_pChildWnd) return 0;
        LoadStringW(hInst, IDS_REGISTRY_ROOT_NAME, g_pChildWnd->szPath, MAX_PATH);
        g_pChildWnd->nSplitPos = 250;
        g_pChildWnd->hWnd = hWnd;
        g_pChildWnd->hTreeWnd = CreateTreeView(hWnd, g_pChildWnd->szPath, TREE_WINDOW);
        g_pChildWnd->hListWnd = CreateListView(hWnd, LIST_WINDOW/*, g_pChildWnd->szPath*/);
        g_pChildWnd->nFocusPanel = 1;
        SetFocus(g_pChildWnd->hTreeWnd);
        get_last_key(g_pChildWnd->hTreeWnd);
        break;
    case WM_COMMAND:
        if (!_CmdWndProc(hWnd, message, wParam, lParam)) {
            goto def;
        }
        break;
    case WM_PAINT:
        OnPaint(hWnd);
        return 0;
    case WM_SETCURSOR:
        if (LOWORD(lParam) == HTCLIENT) {
            POINT pt;
            GetCursorPos(&pt);
            ScreenToClient(hWnd, &pt);
            if (pt.x>=g_pChildWnd->nSplitPos-SPLIT_WIDTH/2 && pt.x<g_pChildWnd->nSplitPos+SPLIT_WIDTH/2+1) {
                SetCursor(LoadCursorW(0, (LPCWSTR)IDC_SIZEWE));
                return TRUE;
            }
        }
        goto def;
    case WM_DESTROY:
        set_last_key(g_pChildWnd->hTreeWnd);
        HeapFree(GetProcessHeap(), 0, g_pChildWnd);
        g_pChildWnd = NULL;
        PostQuitMessage(0);
        break;
    case WM_LBUTTONDOWN: {
            RECT rt;
            int x = (short)LOWORD(lParam);
            GetClientRect(hWnd, &rt);
            if (x>=g_pChildWnd->nSplitPos-SPLIT_WIDTH/2 && x<g_pChildWnd->nSplitPos+SPLIT_WIDTH/2+1) {
                last_split = g_pChildWnd->nSplitPos;
                draw_splitbar(hWnd, last_split);
                SetCapture(hWnd);
            }
            break;
        }

    /* WM_RBUTTONDOWN sets the splitbar the same way as WM_LBUTTONUP */
    case WM_LBUTTONUP:
    case WM_RBUTTONDOWN:
        if (GetCapture() == hWnd) {
            finish_splitbar(hWnd, LOWORD(lParam));
        }
        break;

    case WM_CAPTURECHANGED:
        if (GetCapture()==hWnd && last_split>=0)
            draw_splitbar(hWnd, last_split);
        break;

    case WM_KEYDOWN:
        if (wParam == VK_ESCAPE)
            if (GetCapture() == hWnd) {
                RECT rt;
                draw_splitbar(hWnd, last_split);
                GetClientRect(hWnd, &rt);
                ResizeWnd(rt.right, rt.bottom);
                last_split = -1;
                ReleaseCapture();
                SetCursor(LoadCursorW(0, (LPCWSTR)IDC_ARROW));
            }
        break;

    case WM_MOUSEMOVE:
        if (GetCapture() == hWnd) {
            RECT rt;
            int x = LOWORD(lParam);
            HDC hdc = GetDC(hWnd);
            GetClientRect(hWnd, &rt);
            rt.left = last_split-SPLIT_WIDTH/2;
            rt.right = last_split+SPLIT_WIDTH/2+1;
            InvertRect(hdc, &rt);
            last_split = x;
            rt.left = x-SPLIT_WIDTH/2;
            rt.right = x+SPLIT_WIDTH/2+1;
            InvertRect(hdc, &rt);
            ReleaseDC(hWnd, hdc);
        }
        break;

    case WM_SETFOCUS:
        if (g_pChildWnd != NULL) {
            SetFocus(g_pChildWnd->nFocusPanel? g_pChildWnd->hListWnd: g_pChildWnd->hTreeWnd);
        }
        break;

    case WM_TIMER:
        break;

    case WM_NOTIFY:
        if (((int)wParam == TREE_WINDOW) && (g_pChildWnd != NULL)) {
            switch (((LPNMHDR)lParam)->code) {
            case TVN_ITEMEXPANDINGW:
                return !OnTreeExpanding(g_pChildWnd->hTreeWnd, (NMTREEVIEWW*)lParam);
            case TVN_SELCHANGEDW:
                OnTreeSelectionChanged(g_pChildWnd->hTreeWnd, g_pChildWnd->hListWnd,
                    ((NMTREEVIEWW *)lParam)->itemNew.hItem, TRUE);
                break;
	    case NM_SETFOCUS:
		g_pChildWnd->nFocusPanel = 0;
		break;
            case NM_RCLICK: {
		POINT pt;
                GetCursorPos(&pt);
		TrackPopupMenu(GetSubMenu(hPopupMenus, PM_NEW),
			       TPM_RIGHTBUTTON, pt.x, pt.y, 0, hFrameWnd, NULL);
		break;
            }
            case TVN_BEGINLABELEDITW: {
                HKEY hRootKey;
                LPWSTR path = GetItemPath(g_pChildWnd->hTreeWnd, 0, &hRootKey);
                if (!path || !*path) return 1;
                return 0;
            }
	    case TVN_ENDLABELEDITW: {
		HKEY hRootKey;
	        LPNMTVDISPINFOW dispInfo = (LPNMTVDISPINFOW)lParam;
		LPWSTR path = GetItemPath(g_pChildWnd->hTreeWnd, 0, &hRootKey);
	        BOOL res = RenameKey(hWnd, hRootKey, path, dispInfo->item.pszText);
		if (res) {
		    TVITEMEXW item;
                    LPWSTR fullPath = GetPathFullPath(g_pChildWnd->hTreeWnd,
                     dispInfo->item.pszText);
		    item.mask = TVIF_HANDLE | TVIF_TEXT;
		    item.hItem = (HTREEITEM)SendMessageW(g_pChildWnd->hTreeWnd, TVM_GETNEXTITEM, TVGN_CARET, 0);
		    item.pszText = dispInfo->item.pszText;
                    SendMessageW( g_pChildWnd->hTreeWnd, TVM_SETITEMW, 0, (LPARAM)&item );
                    SendMessageW(hStatusBar, SB_SETTEXTW, 0, (LPARAM)fullPath);
                    HeapFree(GetProcessHeap(), 0, fullPath);
		}
                HeapFree(GetProcessHeap(), 0, path);
		return res;
	    }
            default:
                return 0; /* goto def; */
            }
        } else
            if (((int)wParam == LIST_WINDOW) && (g_pChildWnd != NULL)) {
		if (((LPNMHDR)lParam)->code == NM_SETFOCUS) {
		    g_pChildWnd->nFocusPanel = 1;
		} else if (!SendMessageW(g_pChildWnd->hListWnd, WM_NOTIFY_REFLECT, wParam, lParam)) {
                    goto def;
                }
            }
        break;

    case WM_SIZE:
        if (wParam != SIZE_MINIMIZED && g_pChildWnd != NULL) {
            ResizeWnd(LOWORD(lParam), HIWORD(lParam));
        }
        /* fall through */
default: def:
        return DefWindowProcW(hWnd, message, wParam, lParam);
    }
    return 0;
}
Exemplo n.º 28
0
/*
 * SnapPicture - minimize the image editor and prepare to snap the picture
 */
void SnapPicture( void )
{
    img_node    *node;
    POINT       pt;
    HWND        hwnd;
    RECT        cliprect;

    node = GetCurrentNode();
    if( node == NULL ) {
        return;
    }

    firstTime = 2;

    GetCursorPos( &pt );

    if( DoesRectExist( &cliprect ) ) {
        snapWidth = cliprect.right - cliprect.left;
        snapHeight = cliprect.bottom - cliprect.top;
        topLeft.x = cliprect.left;
        topLeft.y = cliprect.top;
        rectExists = TRUE;
    } else {
        snapWidth = node->width;
        snapHeight = node->height;
        topLeft.x = 0;
        topLeft.y = 0;
        rectExists = FALSE;
    }

    if( IsZoomed( HMainWindow ) ) {
        previousState = SW_SHOWMAXIMIZED;
    } else {
        previousState = SW_SHOWNORMAL;
    }

    snapWindow = node->hwnd;
#ifdef __NT__
    hwnd = hwnd;

    RegisterSnapClass( Instance );
    ShowWindow( HMainWindow, SW_SHOWMINIMIZED );
    ShowWindow( HMainWindow, SW_HIDE );
    InvalidateRect( HWND_DESKTOP, NULL, TRUE );
    // force the desktop window to be redrawn
    RedrawWindow( HWND_DESKTOP, NULL, NULL,
                  RDW_ERASE | RDW_UPDATENOW | RDW_ERASENOW |
                  RDW_ALLCHILDREN | RDW_INVALIDATE );
    SetDeskTopHook( deskTopWindowHook );
    deskTopWindow = DisplayDesktop( HMainWindow );
#else
    SetCapture( node->hwnd );
    ShowWindow( HMainWindow, SW_SHOWMINIMIZED );
    ShowWindow( HMainWindow, SW_HIDE );

    hwnd = WindowFromPoint( pt );
#if 0
    if( hwnd == GetDesktopWindow() ) {
        return;
    }
#endif
    // this code makes sure that the window under the cursor is redrawn
    // Why? gets rid of the XOR turd
    RedrawWindow( hwnd, NULL, NULL,
                  RDW_ERASE | RDW_UPDATENOW | RDW_ALLCHILDREN | RDW_INVALIDATE );
#endif

    prevToolType = SetToolType( IMGED_SNAP );
    prevCursor = SetCursor( NULL );

#ifdef __NT__
    SetCapture( node->hwnd );
#endif

    PostMessage( node->hwnd, WM_MOUSEMOVE, (WPARAM)0, MAKELPARAM( pt.x, pt.y ) );
    Yield();

} /* SnapPicture */
Exemplo n.º 29
0
/***********************************************************************
 *           UPDOWN_HandleMouseEvent
 *
 * Handle a mouse event for the updown.
 * 'pt' is the location of the mouse event in client or
 * windows coordinates.
 */
static void UPDOWN_HandleMouseEvent (UPDOWN_INFO *infoPtr, UINT msg, INT x, INT y)
{
    POINT pt = { x, y };
    RECT rect;
    int temp, arrow;
    TRACKMOUSEEVENT tme;

    TRACE("msg %04x point %s\n", msg, wine_dbgstr_point(&pt));

    switch(msg)
    {
        case WM_LBUTTONDOWN:  /* Initialise mouse tracking */

            /* If the buddy is an edit, will set focus to it */
	    if (UPDOWN_IsBuddyEdit(infoPtr)) SetFocus(infoPtr->Buddy);

            /* Now see which one is the 'active' arrow */
            arrow = UPDOWN_GetArrowFromPoint (infoPtr, &rect, pt);

            /* Update the flags if we are in/out */
            infoPtr->Flags &= ~(FLAG_MOUSEIN | FLAG_ARROW);
            if (arrow)
                infoPtr->Flags |= FLAG_MOUSEIN | arrow;
            else
                if (infoPtr->AccelIndex != -1) infoPtr->AccelIndex = 0;

	    if (infoPtr->Flags & FLAG_ARROW) {

            	/* Update the CurVal if necessary */
            	UPDOWN_GetBuddyInt (infoPtr);

            	/* Set up the correct flags */
            	infoPtr->Flags |= FLAG_PRESSED;

            	/* repaint the control */
	    	InvalidateRect (infoPtr->Self, NULL, FALSE);

            	/* process the click */
		temp = (infoPtr->AccelCount && infoPtr->AccelVect) ? infoPtr->AccelVect[0].nInc : 1;
            	UPDOWN_DoAction (infoPtr, temp, infoPtr->Flags & FLAG_ARROW);

            	/* now capture all mouse messages */
            	SetCapture (infoPtr->Self);

            	/* and startup the first timer */
            	SetTimer(infoPtr->Self, TIMER_AUTOREPEAT, INITIAL_DELAY, 0);
	    }
            break;

	case WM_MOUSEMOVE:
            /* save the flags to see if any got modified */
            temp = infoPtr->Flags;

            /* Now see which one is the 'active' arrow */
            arrow = UPDOWN_GetArrowFromPoint (infoPtr, &rect, pt);

            /* Update the flags if we are in/out */
	    infoPtr->Flags &= ~(FLAG_MOUSEIN | FLAG_ARROW);
            if(arrow) {
	        infoPtr->Flags |=  FLAG_MOUSEIN | arrow;
            } else {
	        if(infoPtr->AccelIndex != -1) infoPtr->AccelIndex = 0;
            }

            /* If state changed, redraw the control */
            if(temp != infoPtr->Flags)
		 InvalidateRect (infoPtr->Self, NULL, FALSE);

            /* Set up tracking so the mousein flags can be reset when the 
             * mouse leaves the control */
            tme.cbSize = sizeof( tme );
            tme.dwFlags = TME_LEAVE;
            tme.hwndTrack = infoPtr->Self;
            TrackMouseEvent (&tme);

            break;
        case WM_MOUSELEAVE:
	    infoPtr->Flags &= ~(FLAG_MOUSEIN | FLAG_ARROW);
            InvalidateRect (infoPtr->Self, NULL, FALSE);
            break;

	default:
	    ERR("Impossible case (msg=%x)!\n", msg);
    }

}
Exemplo n.º 30
0
void	FPSCamera::Update( float _DeltaTime, float _TranslationSpeed, float _RotationSpeed, float _SpeedBoostWithShift )
{

	//////////////////////////////////////////////////////////////////////////
	// Handle mouse manipulation
	//
	if ( gs_WindowInfos.Events.Mouse.dbuttons[0] > 0 )
	{	// Button down
		SetCapture( gs_WindowInfos.hWnd );

		m_ButtonDownMouseX = gs_WindowInfos.Events.Mouse.x;
		m_ButtonDownMouseY = gs_WindowInfos.Events.Mouse.y;
		m_ButtonDownPosition = m_Position;
		m_ButtonDownTarget = m_Target;
	}
	else if ( gs_WindowInfos.Events.Mouse.dbuttons[0] < 0 )
	{	// Button up
		ReleaseCapture();
	}

	if ( gs_WindowInfos.Events.Mouse.buttons[0] != 0 )
	{
		int		MouseDx = gs_WindowInfos.Events.Mouse.x - m_ButtonDownMouseX;
		int		MouseDy = gs_WindowInfos.Events.Mouse.y - m_ButtonDownMouseY;
		float	DAngleX = (_RotationSpeed * TWOPI) * MouseDx / RESX;
		float	DAngleY = (_RotationSpeed * PI) * MouseDy / RESY;

		NjFloat3	At = m_ButtonDownTarget - m_ButtonDownPosition;
		float		Distance2Target = At.Length();
		At = At / Distance2Target;

		float	Theta = asinf( At.y );
		float	Phi = atan2f( At.x, At.z );

		Theta = CLAMP( Theta - DAngleY, -0.99f * HALFPI, +0.99f * HALFPI );	// Never completly up or down to avoid gimbal lock
		Phi -= DAngleX;

		NjFloat3	NewAt( sinf(Phi)*cosf(Theta), sinf(Theta), cosf(Phi)*cos(Theta) );

		m_Target = m_Position + Distance2Target * NewAt;

// 		Vector3	Euler = GetEuler( m_ButtonDownTransform );
// 		Matrix	CamRotYMatrix = Matrix.RotationY( fAngleY + Euler.Y );
// 		Matrix	CamRotXMatrix = Matrix.RotationX( fAngleX + Euler.X );
// 		Matrix	CamRotZMatrix = Matrix.RotationZ( Euler.Z );
// 
// 		Matrix	RotateMatrix = CamRotXMatrix * CamRotYMatrix * CamRotZMatrix;
	}

	NjFloat3	At = (m_Target - m_Position).Normalize();
	NjFloat3	Right = (At ^ m_Up).Normalize();
	NjFloat3	Up = Right ^ At;

	//////////////////////////////////////////////////////////////////////////
	// Handle keyboard manipulation
	//
	float		Speed = _DeltaTime * _TranslationSpeed;
	if ( gs_WindowInfos.Events.Keyboard.State[KEY_LSHIFT] )
		Speed *= _SpeedBoostWithShift;

	NjFloat3	Delta = NjFloat3::Zero;
	if ( gs_WindowInfos.pKeys['Q'] )
	{	// Strafe left
		Delta = Delta - Speed * Right;
	}
	if ( gs_WindowInfos.pKeys['D'] )
	{	// Strafe right
		Delta = Delta + Speed * Right;
	}
	if ( gs_WindowInfos.pKeys['Z'] )
	{	// Forward
		Delta = Delta + Speed * At;
	}
	if ( gs_WindowInfos.pKeys['S'] )
	{	// Backward
		Delta = Delta - Speed * At;
	}
	if ( gs_WindowInfos.pKeys[' '] )
	{	// Up
		Delta = Delta + Speed * Up;
	}
	if ( gs_WindowInfos.Events.Keyboard.State[KEY_LCONTROL] )
	{	// Down
		Delta = Delta - Speed * Up;
	}

	m_Position = m_Position + Delta;
	m_Target = m_Target + Delta;

	//////////////////////////////////////////////////////////////////////////
	// Rebuild camera matrix
	m_Camera.LookAt( m_Position, m_Target, m_Up );
}