Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

触摸屏如西沃上 不能通过触摸的方式 移动标题栏 #392

Open
shuilan0066 opened this issue Feb 25, 2022 · 3 comments
Open

Comments

@shuilan0066
Copy link

复现:
西沃 触摸屏
无法通过触摸方式 移动标题栏

@nmgwddj
Copy link
Collaborator

nmgwddj commented Feb 25, 2022

复现: 西沃 触摸屏 无法通过触摸方式 移动标题栏

这个问题可能得麻烦您提供一下调试的信息了,在 TOUCH MOVE 相关的事件中增加一些打印来协助排查一下问题,因为我们这边很难弄到相关设备。

@shuilan0066
Copy link
Author

经查, case WM_TOUCH: 这里没有判断点击的是否是标题栏
做如下修改后,就好了

` case WM_TOUCH:
{
unsigned int nNumInputs = (int)wParam;
TOUCHINPUT* pInputs = new TOUCHINPUT[nNumInputs];

	// 只关心第一个触摸位置
	if (nNumInputs >= 1 && GetTouchInputInfoWrapper((HTOUCHINPUT)lParam, nNumInputs, pInputs, sizeof(TOUCHINPUT)))
	{
		if (pInputs[0].dwID != 0)
		{
			POINT pt;
			pt.x = TOUCH_COORD_TO_PIXEL(pInputs[0].x);
			pt.y = TOUCH_COORD_TO_PIXEL(pInputs[0].y);
			ScreenToClient(m_hWnd, &pt);

			//................判断是否标题栏
			ui::UiRect rc = GetCaptionRect();
			UiRect rcClient;
			::GetClientRect(GetHWND(), &rcClient);
			rcClient.Deflate(m_shadow.GetShadowCorner());

			UiRect rcCaption = GetCaptionRect();
			if (pt.x >= rcClient.left + rcCaption.left && pt.x < rcClient.right - rcCaption.right \
				&& pt.y >= rcClient.top + rcCaption.top && pt.y < rcClient.top + rcCaption.bottom) {
				Control* pControl = FindControl(pt);
				if (pControl) {
					if (dynamic_cast<Button*>(pControl) || dynamic_cast<ButtonBox*>(pControl) || dynamic_cast<RichEdit*>(pControl))
						;
					else
					{
						CloseTouchInputHandleWrapper((HTOUCHINPUT)lParam);
						delete[] pInputs;
						break;
					}
				}
			}
			//..............................


			if (pInputs[0].dwFlags & TOUCHEVENTF_DOWN)
			{
				if (m_pEventClick != NULL || m_pEventPointer != NULL)
					break;

				::SetFocus(m_hWnd);
				m_ptLastTouchPos = pt;
				Control *pControl = FindControl(pt);
				if (pControl == NULL) break;
				if (pControl->GetWindow() != this) break;
				m_pEventTouch = pControl;
				pControl->SetFocus();
				SetCapture();

				pControl->HandleMessageTemplate(kEventTouchDown, 0, lParam, 0, pt);
			}
			else if (pInputs[0].dwFlags & TOUCHEVENTF_MOVE)
			{
				if (m_pEventClick != NULL || m_pEventPointer != NULL)
					break;

				if (m_ptLastTouchPos.x == pt.x && m_ptLastTouchPos.y == pt.y)
					break;

				m_ptLastTouchPos = pt;
				if (m_pEventTouch == NULL) break;

				if (!HandleMouseEnterLeave(pt, wParam, lParam)) break;

				m_pEventTouch->HandleMessageTemplate(kEventTouchMove, 0, 0, 0, pt);
			}
			else if (pInputs[0].dwFlags & TOUCHEVENTF_UP)
			{
				m_ptLastTouchPos = pt;
				ReleaseCapture();
				if (m_pEventTouch == NULL) break;

				m_pEventTouch->HandleMessageTemplate(kEventTouchUp, 0, lParam, 0, pt);
				m_pEventTouch = NULL;
			}
		}
	}

	CloseTouchInputHandleWrapper((HTOUCHINPUT)lParam);
	delete[] pInputs;
}
	break;`

@nmgwddj
Copy link
Collaborator

nmgwddj commented Mar 3, 2022

经查, case WM_TOUCH: 这里没有判断点击的是否是标题栏 做如下修改后,就好了

` case WM_TOUCH: { unsigned int nNumInputs = (int)wParam; TOUCHINPUT* pInputs = new TOUCHINPUT[nNumInputs];

	// 只关心第一个触摸位置
	if (nNumInputs >= 1 && GetTouchInputInfoWrapper((HTOUCHINPUT)lParam, nNumInputs, pInputs, sizeof(TOUCHINPUT)))
	{
		if (pInputs[0].dwID != 0)
		{
			POINT pt;
			pt.x = TOUCH_COORD_TO_PIXEL(pInputs[0].x);
			pt.y = TOUCH_COORD_TO_PIXEL(pInputs[0].y);
			ScreenToClient(m_hWnd, &pt);

			//................判断是否标题栏
			ui::UiRect rc = GetCaptionRect();
			UiRect rcClient;
			::GetClientRect(GetHWND(), &rcClient);
			rcClient.Deflate(m_shadow.GetShadowCorner());

			UiRect rcCaption = GetCaptionRect();
			if (pt.x >= rcClient.left + rcCaption.left && pt.x < rcClient.right - rcCaption.right \
				&& pt.y >= rcClient.top + rcCaption.top && pt.y < rcClient.top + rcCaption.bottom) {
				Control* pControl = FindControl(pt);
				if (pControl) {
					if (dynamic_cast<Button*>(pControl) || dynamic_cast<ButtonBox*>(pControl) || dynamic_cast<RichEdit*>(pControl))
						;
					else
					{
						CloseTouchInputHandleWrapper((HTOUCHINPUT)lParam);
						delete[] pInputs;
						break;
					}
				}
			}
			//..............................


			if (pInputs[0].dwFlags & TOUCHEVENTF_DOWN)
			{
				if (m_pEventClick != NULL || m_pEventPointer != NULL)
					break;

				::SetFocus(m_hWnd);
				m_ptLastTouchPos = pt;
				Control *pControl = FindControl(pt);
				if (pControl == NULL) break;
				if (pControl->GetWindow() != this) break;
				m_pEventTouch = pControl;
				pControl->SetFocus();
				SetCapture();

				pControl->HandleMessageTemplate(kEventTouchDown, 0, lParam, 0, pt);
			}
			else if (pInputs[0].dwFlags & TOUCHEVENTF_MOVE)
			{
				if (m_pEventClick != NULL || m_pEventPointer != NULL)
					break;

				if (m_ptLastTouchPos.x == pt.x && m_ptLastTouchPos.y == pt.y)
					break;

				m_ptLastTouchPos = pt;
				if (m_pEventTouch == NULL) break;

				if (!HandleMouseEnterLeave(pt, wParam, lParam)) break;

				m_pEventTouch->HandleMessageTemplate(kEventTouchMove, 0, 0, 0, pt);
			}
			else if (pInputs[0].dwFlags & TOUCHEVENTF_UP)
			{
				m_ptLastTouchPos = pt;
				ReleaseCapture();
				if (m_pEventTouch == NULL) break;

				m_pEventTouch->HandleMessageTemplate(kEventTouchUp, 0, lParam, 0, pt);
				m_pEventTouch = NULL;
			}
		}
	}

	CloseTouchInputHandleWrapper((HTOUCHINPUT)lParam);
	delete[] pInputs;
}
	break;`

您可以将改动通过 PR 方式提交到 develop 分支。我们会有人来进行拉取测试,感谢您发现并解决 NIM duilib 的不足。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants