BOOL CXTPSkinObjectFrame::IsSizeBox()
{
    HWND hWnd = m_hWnd;
    CXTPWindowRect rcChild(hWnd);

    int cxEdge = GetMetrics()->m_cxEdge;
    int cyEdge = GetMetrics()->m_cyEdge;

    while (hWnd)
    {
        if (GetWindowLong(hWnd, GWL_STYLE) & WS_SIZEBOX)
        {
            if ((GetWindowLong(hWnd, GWL_STYLE) & WS_MAXIMIZE))
                return FALSE;

            CPoint ptParent = CXTPClientRect(hWnd).BottomRight();
            ::ClientToScreen(hWnd, &ptParent);

            if ((rcChild.right + cxEdge < ptParent.x) ||
                    (rcChild.bottom + cyEdge < ptParent.y))
            {
                return FALSE;
            }

            return hWnd ? TRUE : FALSE;
        }

        if (((GetWindowLong(hWnd, GWL_STYLE) & WS_CHILD) == 0) || ((GetWindowLong(hWnd, GWL_STYLE) & WS_CAPTION) == WS_CAPTION))
            break;

        hWnd = ::GetParent(hWnd);
    }

    return FALSE;
}
示例#2
0
    void SLinearLayout::LayoutChildren(SWindow * pParent)
    {
        CRect rcParent = pParent->GetChildrenLayoutRect();
		        
        CSize *pSize = new CSize [pParent->GetChildrenCount()];
		SWindow ** pChilds = new SWindow * [pParent->GetChildrenCount()];
		int nChilds = 0;
		
        int offset = 0;
        float fWeight= 0.0f;

        {//assign width or height

            int iChild = 0;

			SWindow *pChild=pParent->GetNextLayoutChild(NULL);
            while(pChild)
            {
				SLinearLayoutParam *pLinearLayoutParam = pChild->GetLayoutParamT<SLinearLayoutParam>();

				int nScale = pChild->GetScale();

                CSize szChild(SIZE_WRAP_CONTENT,SIZE_WRAP_CONTENT);
                if(pLinearLayoutParam->IsMatchParent(Horz))
                    szChild.cx = rcParent.Width();
                else if(pLinearLayoutParam->IsSpecifiedSize(Horz))
                {
                    szChild.cx = pLinearLayoutParam->GetSpecifiedSize(Horz).toPixelSize(nScale);
                    szChild.cx += pLinearLayoutParam->extend_left.toPixelSize(nScale) + pLinearLayoutParam->extend_right.toPixelSize(nScale);
                }

                if(pLinearLayoutParam->IsMatchParent(Vert))
                    szChild.cy = rcParent.Height();
                else if(pLinearLayoutParam->IsSpecifiedSize(Vert))
                {
                    szChild.cy = pLinearLayoutParam->GetSpecifiedSize(Vert).toPixelSize(nScale);
                    szChild.cy += pLinearLayoutParam->extend_top.toPixelSize(nScale) + pLinearLayoutParam->extend_bottom.toPixelSize(nScale);
                }
                
                if(pLinearLayoutParam->weight > 0.0f)
                {
                    fWeight += pLinearLayoutParam->weight;
                }

                if(szChild.cx == SIZE_WRAP_CONTENT || szChild.cy == SIZE_WRAP_CONTENT)
                {
                    CSize szCalc = pChild->GetDesiredSize(szChild.cx,szChild.cy);
                    if(szChild.cx == SIZE_WRAP_CONTENT)
                    {
                        szChild.cx = szCalc.cx;
                        szChild.cx += pLinearLayoutParam->extend_left.toPixelSize(nScale) + pLinearLayoutParam->extend_right.toPixelSize(nScale);
                    }
                    if(szChild.cy == SIZE_WRAP_CONTENT) 
                    {
                        szChild.cy = szCalc.cy;
                        szChild.cy += pLinearLayoutParam->extend_top.toPixelSize(nScale) + pLinearLayoutParam->extend_bottom.toPixelSize(nScale);
                    }
                }

				pChilds[iChild] = pChild;
                pSize [iChild] = szChild;
                offset += m_orientation == Vert ? szChild.cy:szChild.cx;

				iChild++;
				pChild=pParent->GetNextLayoutChild(pChild);
            }

			nChilds = iChild;
        }

        int size = m_orientation == Vert? rcParent.Height():rcParent.Width();
        if(fWeight > 0.0f && size > offset)
        {//assign size by weight
            int nRemain = size - offset;
			for(int iChild = 0;iChild < nChilds;iChild ++)
            {
				SWindow *pChild = pChilds[iChild];

				SLinearLayoutParam *pLinearLayoutParam = pChild->GetLayoutParamT<SLinearLayoutParam>();

                if(pLinearLayoutParam->weight > 0.0f)
                {
                    LONG & szChild = m_orientation == Vert? pSize[iChild].cy:pSize[iChild].cx;
                    szChild += (int)(nRemain*pLinearLayoutParam->weight/fWeight);
                }
            }
        }
        {//assign position
            offset = 0;
			for(int iChild = 0;iChild < nChilds;iChild ++)
			{
				SWindow *pChild = pChilds[iChild];


                SLinearLayoutParam *pLinearLayoutParam = pChild->GetLayoutParamT<SLinearLayoutParam>();
				int nScale = pChild->GetScale();
                Gravity gravity = pLinearLayoutParam->gravity == G_Undefined? m_gravity:pLinearLayoutParam->gravity;
                if(gravity == G_Undefined) gravity = G_Left;

                if(m_orientation == Vert)
                {
                    CRect rcChild(CPoint(0,offset),pSize[iChild]);
                    rcChild.OffsetRect(rcParent.TopLeft());
                    if(gravity == G_Center)
                        rcChild.OffsetRect((rcParent.Width()-rcChild.Width())/2,0);
                    else if(gravity == G_Right)
                        rcChild.OffsetRect(rcParent.Width()-rcChild.Width(),0);
                    
                    CRect rcChild2 = rcChild;
                    rcChild2.DeflateRect(pLinearLayoutParam->extend_left.toPixelSize(nScale),
						pLinearLayoutParam->extend_top.toPixelSize(nScale),
						pLinearLayoutParam->extend_right.toPixelSize(nScale),
						pLinearLayoutParam->extend_bottom.toPixelSize(nScale)
						);

                    pChild->OnRelayout(rcChild2);

                    offset += rcChild.Height();
                }else
                {
                    CRect rcChild(CPoint(offset,0),pSize[iChild]);
                    rcChild.OffsetRect(rcParent.TopLeft());
                    if(gravity == G_Center)
                        rcChild.OffsetRect(0,(rcParent.Height()-rcChild.Height())/2);
                    else if(gravity == G_Right)
                        rcChild.OffsetRect(0,rcParent.Height()-rcChild.Height());

                    CRect rcChild2 = rcChild;
					rcChild2.DeflateRect(pLinearLayoutParam->extend_left.toPixelSize(nScale),
						pLinearLayoutParam->extend_top.toPixelSize(nScale),
						pLinearLayoutParam->extend_right.toPixelSize(nScale),
						pLinearLayoutParam->extend_bottom.toPixelSize(nScale));

                    pChild->OnRelayout(rcChild2);

                    offset += rcChild.Width();
                }

            }

        }

		delete []pChilds;
		delete []pSize;

    }