Exemple #1
0
void ZToolTip::GetPosAlignedWithParent(int& x, int& y, int nTextPixelWidth, int nTextPixelHeight)
{
	/// parameter x,y is return value

	MRECT pr = GetParent()->GetClientRect();

	MRECT tr;	//tooltip rect
	tr.w = nTextPixelWidth+ZTOOLTIP_WIDTH_GAP/2;
	tr.h = nTextPixelHeight+ZTOOLTIP_HEIGHT_GAP;

	if (m_alignMode & MAM_LEFT)
		tr.x = pr.x+(ZTOOLTIP_WIDTH_GAP/2+1);
	else if (m_alignMode & MAM_RIGHT)
		tr.x = pr.x+pr.w - tr.w;
	else if (m_alignMode & MAM_HCENTER)
		tr.x = pr.w/2 - tr.w/2;
	else
		tr.x = 0;
	

	if (m_alignMode & MAM_TOP)
		tr.y = pr.y-tr.h;
	else if (m_alignMode & MAM_BOTTOM)
		tr.y = pr.y+pr.h;
	else if (m_alignMode & MAM_VCENTER)
		tr.y = pr.h/2 - tr.h/2;
	else
		tr.y = 0;

	MRECT str = MClientToScreen(GetParent(), tr);
	
	int rightx = str.x+str.w;
	if (rightx > MGetWorkspaceWidth()) {
		int diff = rightx - MGetWorkspaceWidth();
		tr.x -= diff;
	}
	int leftx = str.x;
	if (leftx < 0)
		tr.x = 0;

	int bottomy = str.y+str.h;
	if (bottomy > MGetWorkspaceHeight()) {
		int diff = bottomy - MGetWorkspaceHeight();
		tr.y -= diff;
	}

	int topy = str.y;
	if (topy < 0)
		tr.y = 0;

	x = tr.x;
	y = tr.y;
}
Exemple #2
0
bool MFrame::OnEvent(MEvent* pEvent, MListener* pListener)
{
	if (IsFocusEnable() == false)
		return false;

	MRECT TitleBarRect(0, 0, m_Rect.w, MTITLEBAR_HEIGHT);
	MRECT WidgetRect(0, 0, m_Rect.w, m_Rect.h);
	MPOINT sp = MClientToScreen(this, pEvent->Pos);

	switch(pEvent->nMessage){
	case MWM_LBUTTONDOWN:

		if(m_bTitleBar==true && TitleBarRect.InPoint(pEvent->Pos)==true) {

			if ( m_BtnClose.m_Rect.InPoint(pEvent->Pos)==true)
			{
				m_BtnClose.m_bLButtonDown = true;
			}
			else if (m_BtnMinimize.m_Rect.InPoint(pEvent->Pos)==true)
			{
				m_BtnMinimize.m_bLButtonDown = true;
			}
			else
			{
				SetCapture();
				m_bDragWidget = true;
				MPOINT wp = MClientToScreen(GetParent(), MPOINT(m_Rect.x, m_Rect.y));
				sp.x -= wp.x;
				sp.y -= wp.y;
				m_DragPoint = sp;
			}
			return true;
		}
		else if(WidgetRect.InPoint(pEvent->Pos)==true){
			return true;
		}
		break;
	case MWM_LBUTTONUP:
		if (m_bTitleBar==true && m_BtnClose.m_Rect.InPoint(pEvent->Pos)==true)
		{
			if (m_BtnClose.m_bLButtonDown==true) OnCloseButtonClick();
		}
		else if (m_bTitleBar==true && m_BtnMinimize.m_Rect.InPoint(pEvent->Pos)==true)
		{
			if (m_BtnMinimize.m_bLButtonDown==true) OnMinimizeButtonClick();
		}

		m_BtnClose.m_bLButtonDown = m_BtnMinimize.m_bLButtonDown = false;

		if(m_bDragWidget==true){
			ReleaseCapture();
			m_bDragWidget = false;
			return true;
		}
		break;
	case MWM_MOUSEMOVE:
		if(m_bDragWidget==true){
			sp.x -= m_DragPoint.x;
			sp.y -= m_DragPoint.y;
			if(sp.x<0) sp.x = 0;
			if(sp.y<0) sp.y = 0;
			if(sp.x+m_Rect.w>MGetWorkspaceWidth()-1) sp.x = MGetWorkspaceWidth()-m_Rect.w-1;
			if(sp.y+m_Rect.h>MGetWorkspaceHeight()-1) sp.y = MGetWorkspaceHeight()-m_Rect.h-1;
			MPOINT p = MScreenToClient(GetParent(), sp);
			if (m_bMovable == true) {
				SetPosition(p.x, p.y);
			}
			
			return true;
		}
		else if(m_bTitleBar==true)
		{
			if(m_BtnClose.m_Rect.InPoint(pEvent->Pos)==true)
			{
				if(m_BtnClose.m_bMouseOver==false) m_BtnClose.m_bMouseOver = true;
			}
			else
			{
				if(m_BtnClose.m_bMouseOver==true) m_BtnClose.m_bMouseOver = false;
			}
			if(m_BtnMinimize.m_Rect.InPoint(pEvent->Pos)==true)
			{
				if(m_BtnMinimize.m_bMouseOver==false) m_BtnMinimize.m_bMouseOver = true;
			}
			else
			{
				if(m_BtnMinimize.m_bMouseOver==true) m_BtnMinimize.m_bMouseOver = false;
			}

		}
		break;
	case MWM_LBUTTONDBLCLK:
		break;
	}
	return false;
}