#69 CZoomScrollImpl: some methods should be overridable

closed-fixed
None
5
2014-02-22
2007-04-06
Yury Bura
No

Methods list:
CZoomScrollImpl::PtInDevRect
CZoomScrollImpl::PrepareDC
CZoomScrollImpl::DeviceToClient
CZoomScrollImpl::CenterOnPoint

It's needed for overriding default behavior when the image is zoomed smaller than the client area.

Please see 'http://tech.groups.yahoo.com/group/wtl/message/14024' for additional information.

My example (based on Bob Starr's implementation):

class CMyView : public CZoomScrollWindowImpl<CMyView>
{
...
void PrepareDC(CDCHandle dc)
{
ATLASSERT(m_sizeAll.cx >= 0 && m_sizeAll.cy >= 0);
dc.SetMapMode(MM_ANISOTROPIC);
dc.SetWindowExt(m_sizeLogAll);

// If client area is larger than total device size,
// override scroll positions to place origin such that
// output is centered in the window
CPoint ptOffset(m_ptOffset);
CRect rcClient;
GetClientRect(&rcClient);
if (m_sizeAll.cx < rcClient.Width())
ptOffset.x = -((rcClient.Width() - m_sizeAll.cx) / 2);
if (m_sizeAll.cy < rcClient.Height())
ptOffset.y = -((rcClient.Height() - m_sizeAll.cy) / 2);

dc.SetViewportExt(m_sizeAll);
dc.SetViewportOrg(-ptOffset.x, -ptOffset.y);
}

BOOL PtInDevRect(POINT pt)
{
RECT rc = { 0, 0, m_sizeAll.cx, m_sizeAll.cy };

// If client area is larger than total device size,
// override scroll positions to place origin such that
// output is centered in the window
CPoint ptOffset(m_ptOffset);
CRect rcClient;
GetClientRect(&rcClient);
if (m_sizeAll.cx < rcClient.Width())
ptOffset.x = -((rcClient.Width() - m_sizeAll.cx) / 2);
if (m_sizeAll.cy < rcClient.Height())
ptOffset.y = -((rcClient.Height() - m_sizeAll.cy) / 2);

::OffsetRect(&rc, -ptOffset.x, -ptOffset.y);
return ::PtInRect(&rc, pt);
}

void ClientToDevice(POINT &pt)
{
// If client area is larger than total device size,
// override scroll positions to place origin such that
// output is centered in the window
CPoint ptOffset(m_ptOffset);
CRect rcClient;
GetClientRect(&rcClient);
if (m_sizeAll.cx < rcClient.Width())
ptOffset.x = -((rcClient.Width() - m_sizeAll.cx) / 2);
if (m_sizeAll.cy < rcClient.Height())
ptOffset.y = -((rcClient.Height() - m_sizeAll.cy) / 2);

pt.x += ptOffset.x;
pt.y += ptOffset.y;
}

void DeviceToClient(POINT &pt)
{
// If client area is larger than total device size,
// override scroll positions to place origin such that
// output is centered in the window
CPoint ptOffset(m_ptOffset);
CRect rcClient;
GetClientRect(&rcClient);
if (m_sizeAll.cx < rcClient.Width())
ptOffset.x = -((rcClient.Width() - m_sizeAll.cx) / 2);
if (m_sizeAll.cy < rcClient.Height())
ptOffset.y = -((rcClient.Height() - m_sizeAll.cy) / 2);

pt.x -= ptOffset.x;
pt.y -= ptOffset.y;
}

void CenterOnPoint(POINT pt)
{
// If client area is larger than total device size,
// override scroll positions to place origin such that
// output is centered in the window
CPoint ptOffset(m_ptOffset);
CRect rcClient;
GetClientRect(&rcClient);
if (m_sizeAll.cx < rcClient.Width())
ptOffset.x = -((rcClient.Width() - m_sizeAll.cx) / 2);
if (m_sizeAll.cy < rcClient.Height())
ptOffset.y = -((rcClient.Height() - m_sizeAll.cy) / 2);

int xOfs = pt.x - (rcClient.right / 2) + ptOffset.x;
if(xOfs < 0)
{
xOfs = 0;
}
else
{
int xMax = max((int)(m_sizeAll.cx - rcClient.right), 0);
if(xOfs > xMax)
xOfs = xMax;
}

int yOfs = pt.y - (rcClient.bottom / 2) + ptOffset.y;
if(yOfs < 0)
{
yOfs = 0;
}
else
{
int yMax = max((int)(m_sizeAll.cy - rcClient.bottom), 0);
if(yOfs > yMax)
yOfs = yMax;
}

CScrollImpl<CSPMainMapWndEx>::SetScrollOffset(xOfs, yOfs);
}
...
}

Please see also path file (including #1307749 CZoomScrollImpl: zoom scale max limit)

Discussion

  • Yury Bura
    Yury Bura
    2007-04-06

     
    Attachments
  • Yury Bura
    Yury Bura
    2007-04-06

    Logged In: YES
    user_id=1178943
    Originator: YES

    File Added: atlscrl.patch

     
    • assigned_to: nobody --> nenadstefanovic
     
    • assigned_to: nenadstefanovic --> lilsroro
     
  • Logged In: YES
    user_id=1025101
    Originator: NO

    Anything else here that should be added to the class (as an option)?

     
  • Yury Bura
    Yury Bura
    2007-05-04

    Logged In: YES
    user_id=1178943
    Originator: YES

    At the moment it is enough for me.
    Thanks a lot.

     
  • This was already done

     
    • status: open --> closed-fixed
    • Group: --> Next Release (example)