⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pagemous.cpp

📁 英文版的 想要的话可以下载了 为大家服务
💻 CPP
📖 第 1 页 / 共 2 页
字号:
        if (y <= rcB.top)           //Limit to top of page.
            y=rcB.top;

        m_rcl.top=y;
        }

    if (m_uSizingFlags & SIZINGBOTTOM)
        {
        if (y <= rcO.top+cxy)
            y=rcO.top+cxy;

        if (y >= rcB.bottom)         //Limit to bottom of page.
            y=rcB.bottom;

        m_rcl.bottom=y;
        }

    if (m_uSizingFlags & SIZINGLEFT)
        {
        if (x >= rcO.right-cxy)
            x=rcO.right-cxy;

        if (x <= rcB.left)           //Limit to left of page.
            x=rcB.left;

        m_rcl.left=x;
        }

    if (m_uSizingFlags & SIZINGRIGHT)
        {
        if (x <= rcO.left+cxy)
            x=rcO.left+cxy;

        if (x >= rcB.right)          //Limit to right of page.
            x=rcB.right;

        m_rcl.right=x;
        }


    //Draw the new
    RECTFROMRECTL(rc, m_rcl)
    DrawFocusRect(m_hDC, &rc);

    return;
    }




/*
 * CPage::OnTimer
 *
 * Purpose:
 *  Processes WM_TIMER messages to a page used to perform mouse
 *  debouncing.
 *
 * Parameters:
 *  uID             UINT timer ID.
 *
 * Return Value:
 *  None
 */

void CPage::OnTimer(UINT uID)
    {
    if (m_fSizePending || m_fDragPending)
        {
        BOOL        fSize=m_fSizePending;
        BOOL        fDrag=m_fDragPending;

        /*
         * Having this function called means the delay requirement
         * is satisfied.  Start tracking for sizing or dragging.
         */

        m_fSizePending=FALSE;
        m_fDragPending=FALSE;

        KillTimer(m_hWnd, IDTIMER_DEBOUNCE);
        m_fTimer=FALSE;

        if (fDrag)
            {
            POINT       pt;

            GetCursorPos(&pt);
            m_pPG->m_fDirty |= DragDrop(m_uKeysDown
                , m_ptDown.x, m_ptDown.y);
            return;
            }

        if (fSize)
            StartSizeTracking();
        }

    return;
    }





/*
 * CPage::StartSizeTracking
 *
 * Purpose:
 *  Begins sizing of a tenant when mouse debounce conditions are
 *  met.
 *
 * Parameters:
 *  uID             UINT timer ID.
 *
 * Return Value:
 *  None
 */

void CPage::StartSizeTracking(void)
    {
    RECT        rc;

    m_pTenantCur->RectGet(&m_rcl, TRUE);
    SetCapture(m_hWnd);
    m_fTracking=TRUE;

    m_hDC=GetDC(m_hWnd);

    //Place the rectangle exactly where it is on the screen.
    RECTFROMRECTL(rc, m_rcl)
    OffsetRect(&rc, -(int)m_pPG->m_xPos, -(int)m_pPG->m_yPos);
    RECTLFROMRECT(m_rcl, rc);
    m_rclOrg=m_rcl;

    DrawFocusRect(m_hDC, &rc);

    m_pPG->CalcBoundingRect(&rc, TRUE);
    RECTLFROMRECT(m_rclBounds, rc);
    return;
    }





/*
 * CPage::OnNCHitTest
 *
 * Purpose:
 *  Processes WM_NCHITTEST on a page so we can check for hits on the
 *  handles of the selected object for resizing.  We only save
 *  information for ourselves and do not interfere with normal
 *  hit-testing.
 *
 * Parameters:
 *  x, y            UINT device coordinates to check.
 *
 * Return Value:
 *  None
 */

void CPage::OnNCHitTest(UINT x, UINT y)
    {
    RECT        rc;
    RECTL       rcl;
    int         iMid1, iMid2;
    int         xHit, yHit;
    POINT       pt;
    int         x0, y0;

    /*
     * Ignore this message if it occurs during tracking to adjust
     * for the behavior of oddball mouse drivers.
     */
    if (m_fSizePending || m_fTracking)
        return;

    //Default: don't start sizing on a click, don't hit an object.
    m_uSizingFlags=0;
    m_uHTCode=HTNOWHERE;

    if (NULL==m_pTenantCur)
        return;

    //Convert device points to our coordinates
    m_pTenantCur->RectGet(&rcl, FALSE);
    RECTFROMRECTL(rc, rcl);
    RectConvertMappings(&rc, NULL, TRUE);
    OffsetRect(&rc, -(int)m_pPG->m_xPos, -(int)m_pPG->m_yPos);

    SETPOINT(pt, x, y);
    ScreenToClient(m_hWnd, &pt);
    x0=pt.x;
    y0=pt.y;

    if (x0 < rc.left || x0 > rc.right)
        return;

    if (y0 < rc.top || y0 > rc.bottom)
        return;

    //It's at least in the object.
    m_uHTCode=HTCLIENT;

    //Check for hits in horizontal regions
    xHit=NOVALUE;
    iMid1=rc.left+((rc.right-rc.left-CXYHANDLE) >> 1);
    iMid2=rc.left+((rc.right-rc.left+CXYHANDLE) >> 1);

    if (x0 >= rc.left && x0 <= rc.left+CXYHANDLE)
        xHit=XLEFT;
    else if (x0 >= iMid1 && x0 <= iMid2)
        xHit=XMID;
    else if (x0 >= rc.right-CXYHANDLE && x0 <= rc.right)
        xHit=XRIGHT;

    //Don't exit yet if we didn't hit a handle--might hit a y edge.

    //Check for hits in vertical regions
    yHit=NOVALUE;
    iMid1=rc.top+((rc.bottom-rc.top-CXYHANDLE) >> 1);
    iMid2=rc.top+((rc.bottom-rc.top+CXYHANDLE) >> 1);

    if (y0 >= rc.top && y0 <= rc.top+CXYHANDLE)
        yHit=YTOP;
    else if (y0 >= iMid1 && y0 <= iMid2)
        yHit=YMID;
    else if (y0 >= rc.bottom-CXYHANDLE && y0 <= rc.bottom)
        yHit=YBOT;

    /*
     * If we hit any edge, but didn't hit a handle, then one of xHit
     * and yHit will be NOVALUE and the other something else.  When
     * we hit an edge on the 'something else' then we're on a drag
     * point.
     */

    if ((NOVALUE==xHit && NOVALUE==yHit)
        || (XMID==xHit && YMID==yHit)
        || (NOVALUE==xHit && YMID==yHit)
        || (XMID==xHit && NOVALUE==yHit))
        return;

    if ((NOVALUE==xHit && (YTOP==yHit || YBOT==yHit))
        || ((XLEFT==xHit || XRIGHT==xHit) && NOVALUE==yHit))
        {
        m_uHTCode=HTCAPTION;
        return;
        }

    //We hit a handle, so save our HT code
    m_uSizingFlags=g_rguSizingFlags[xHit+(yHit*3)];
    m_uHTCode=g_rgHTCode[xHit+(yHit*3)];
    return;
    }





/*
 * CPage::SetCursor
 *
 * Purpose:
 *  Processes WM_SETCURSOR using the code from OnNCHitTest.
 *
 * Parameters:
 *  x, y            UINT device coordinates to check.
 *
 * Return Value:
 *  LRESULT         HT* code for Windows.
 */

BOOL CPage::OnSetCursor(UINT uHTCode)
    {
    HCURSOR     hCur;
    UINT        iCur;

    /*
     * We really just ignore uHTCode and use the one we saved
     * in OnNCHitTest.
     */

    switch (m_uHTCode)
        {
        case HTTOP:
        case HTBOTTOM:
            iCur=IDC_VARROWS;
            break;

        case HTLEFT:
        case HTRIGHT:
            iCur=IDC_HARROWS;
            break;


        case HTTOPLEFT:
        case HTBOTTOMRIGHT:
            iCur=IDC_NWSEARROWS;
            break;

        case HTTOPRIGHT:
        case HTBOTTOMLEFT:
            iCur=IDC_NESWARROWS;
            break;

        case HTCAPTION:
            iCur=IDC_SMALLARROWS;
            break;

        default:
            return FALSE;
        }

    hCur=UICursorLoad(iCur);
    SetCursor(hCur);

    return TRUE;
    }





/*
 * CPage::TenantFromPoint
 * (Protected)
 *
 * Purpose:
 *  Finds the tenant under the given device coordinates on this
 *  page.
 *
 * Parmeters:
 *  x, y            UINT coordinates.
 *  ppTenant        PCTenant * in which to return the pointer.
 *
 * Return Value:
 *  UINT            Index of the matched tenant, NOVALUE if not
 *                  found.
 */

UINT CPage::TenantFromPoint(UINT x, UINT y, PCTenant *ppTenant)
    {
    PCTenant    pTenant;
    RECTL       rcl;
    UINT        i;
    int         x0, y0;

    x0=x+m_pPG->m_xPos;
    y0=y+m_pPG->m_yPos;

    for (i=0; i < m_cTenants; i++)
        {
        if (!TenantGet(i, &pTenant, FALSE))
            continue;

        pTenant->RectGet(&rcl, TRUE);

        //Essentially Perform PointInRECTL
        if (x0 >= rcl.left && x0 <= rcl.right)
            {
            if (y0 <=rcl.bottom && y0 >=rcl.top)
                {
                *ppTenant=pTenant;
                return i;
                }
            }
        }

    *ppTenant=NULL;
    return NOVALUE;
    }







/*
 * CPage::DragDrop
 *
 * Purpose:
 *  Performs drag-drop operations from the page window
 *
 * Parmeters:
 *  uKeys           UINT state of the keyboard
 *  x, y            UINT mouse coordinates of the starting click.
 *
 * Return Value:
 *  BOOL            TRUE if we modified the page, FALSE otherwise.
 */

BOOL CPage::DragDrop(UINT uKeys, UINT x, UINT y)
    {
    LPDROPSOURCE    pIDropSource;
    LPDATAOBJECT    pIDataObject;
    HRESULT         hr;
    DWORD           dwEffect;
    POINTL          ptl;
    SIZEL           szl;
    RECTL           rcl;
    RECT            rc, rcT;

    pIDropSource=new CDropSource();

    if (NULL==pIDropSource)
        return FALSE;

    pIDropSource->AddRef();
    m_pPG->m_fDragSource=TRUE;


    /*
     * Store a pick point with the data indicating the offset from
     * the upper left of the rectangle where we grabbed it.  This is
     * so the UI feedback in IDropTarget lines up with this tenant.
     */

    m_pTenantCur->RectGet(&rcl, TRUE);
    ptl.x=x+m_pPG->m_xPos-rcl.left;
    ptl.y=y+m_pPG->m_yPos-rcl.top;
    pIDataObject=TransferObjectCreate(&ptl);

    if (NULL==pIDataObject)
        {
        pIDropSource->Release();
        return FALSE;
        }

    m_pPG->m_fMoveInPage=FALSE;

    dwEffect=DROPEFFECT_COPY | DROPEFFECT_MOVE;
    hr=DoDragDrop(pIDataObject, pIDropSource
        , DROPEFFECT_COPY | DROPEFFECT_MOVE, &dwEffect);

    pIDataObject->Release();
    pIDropSource->Release();

    m_pPG->m_fDragSource=FALSE;

    //No drop-no action.
    if (DRAGDROP_S_DROP!=GetScode(hr) || DROPEFFECT_NONE==dwEffect)
        return FALSE;

    /*
     * If m_pPG->m_fMoveInPage is set, then we just change the
     * coordinates on m_pTenantCur and we're done.
     */
    if (m_pPG->m_fMoveInPage)
        {
        m_pTenantCur->Invalidate();

        /*
         * Clip to page boundaries.  We know that ptDrop has to be
         * in the page somewhere or we would not have dropped
         * (effect was NONE).  So first make sure that ptDrop is
         * within 3*CXYHANDLE of the right or bottom, and if so,
         * pull it out to 3*CXYHANDLE.  Then we can just clip the
         * size to the page rectangle and we'll always be sure to
         * have at least a sizeable object.
         */
        m_pTenantCur->SizeGet(&szl, TRUE);
        SetRect(&rc, (int)m_pPG->m_ptDrop.x, (int)m_pPG->m_ptDrop.y
            , 0, 0);
        RectConvertMappings(&rc, NULL, TRUE);

        m_pPG->CalcBoundingRect(&rcT, FALSE);
        OffsetRect(&rcT, (int)m_pPG->m_xPos, (int)m_pPG->m_yPos);

        if (rc.left >= rcT.right-3*CXYHANDLE)
            rc.left=rcT.right-3*CXYHANDLE;

        if (rc.top >= rcT.bottom-3*CXYHANDLE)
            rc.top=rcT.bottom-3*CXYHANDLE;

        rc.right=rc.left+(int)szl.cx;
        rc.bottom=rc.top+(int)szl.cy;
        IntersectRect(&rc, &rc, &rcT);

        RECTLFROMRECT(rcl, rc);

        m_pTenantCur->RectSet(&rcl, TRUE, FALSE);
        m_pTenantCur->Repaint();
        return TRUE;
        }

    /*
     * Otherwise we may have to delete the old tenant if the effect
     * was move.  This will not happen in the move in page case.
     */

    if (DROPEFFECT_MOVE==dwEffect)
        {
        TenantDestroy();
        return TRUE;
        }

    //Copy is a clean operation
    return FALSE;
    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -