// RightPaneWnd.cpp : implementation file // #include "stdafx.h" #include "Overlay.h" #include "RightPaneWnd.h" #include "MainFrm.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CRightPaneWnd IMPLEMENT_DYNCREATE(CRightPaneWnd, CView) CRightPaneWnd::CRightPaneWnd() { } CRightPaneWnd::~CRightPaneWnd() { L_DoubleBufferDestroyHandle(hDoubleBufferHandle); } BEGIN_MESSAGE_MAP(CRightPaneWnd, CView) //{{AFX_MSG_MAP(CRightPaneWnd) ON_MESSAGE(WM_DOREALIZE, OnDoRealize) ON_WM_ERASEBKGND() ON_WM_SIZE() ON_WM_HSCROLL() ON_WM_VSCROLL() ON_WM_CREATE() //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CRightPaneWnd drawing void CRightPaneWnd::OnDraw(CDC* pDC) { CDocument* pDoc = GetDocument(); CMainFrame* pFrame = (CMainFrame*) AfxGetApp()->GetMainWnd(); PaintBitmap(pDC); } ///////////////////////////////////////////////////////////////////////////// // CRightPaneWnd diagnostics #ifdef _DEBUG void CRightPaneWnd::AssertValid() const { CView::AssertValid(); } void CRightPaneWnd::Dump(CDumpContext& dc) const { CView::Dump(dc); } #endif //_DEBUG ///////////////////////////////////////////////////////////////////////////// // CRightPaneWnd message handlers L_VOID CRightPaneWnd::PaintBitmap(CDC* pDC) { CMainFrame* pFrame = (CMainFrame*) AfxGetApp()->GetMainWnd(); HPALETTE OldPalette=NULL; HDC hMemDC = NULL; CRect WindowRect; CRect rcClip; // Get the bounding rectangle for the whole window GetClientRect(WindowRect); // Start double buffering hMemDC = L_DoubleBufferBegin( hDoubleBufferHandle, pDC->m_hDC, WindowRect.Width(), WindowRect.Height()); { // Fill the background of the window FillRect(hMemDC, (LPRECT) WindowRect, GetSysColorBrush(COLOR_APPWORKSPACE)); // Any palette to select ? if (m_hPalette) { OldPalette = ::SelectPalette(hMemDC,m_hPalette, TRUE); RealizePalette(hMemDC); } GetClipBox(hMemDC,rcClip); if (rcClip.IsRectEmpty()) { GetClientRect(rcClip); } // If we have a bitmap then paint it if (pFrame->Bitmap.Flags.Allocated) { L_PaintDC( hMemDC, &pFrame->Bitmap, NULL, NULL, &rcView, &rcClip, SRCCOPY); } if (OldPalette) { ::SelectPalette(hMemDC,OldPalette, TRUE); } // End double buffering L_DoubleBufferEnd(hDoubleBufferHandle, pDC->m_hDC); } } BOOL CRightPaneWnd::OnEraseBkgnd(CDC* pDC) { // We don't do any painting code in here, we want // to make sure that all the panting is done inside PaintBitmap Invalidate(FALSE); return 0; } LONG CRightPaneWnd::OnDoRealize(WPARAM wParam, LPARAM lParam) { UINT nColorsChanged = 0; CDC* pdc; CWnd * pWnd=NULL; CMainFrame* pFrame = (CMainFrame*) AfxGetApp()->GetMainWnd(); if (!pFrame->Bitmap.Flags.Allocated) return 0; if(lParam) { if(((HWND) wParam) == m_hWnd) return(FALSE); } if(m_hPalette!=NULL) { DeleteObject(m_hPalette); m_hPalette=NULL; } pdc = GetDC(); m_hPalette = L_CreatePaintPalette(pdc->m_hDC,&pFrame->Bitmap); if(m_hPalette) { HPALETTE oldPalette = ::SelectPalette(pdc->m_hDC,m_hPalette, (BOOL) lParam); nColorsChanged = RealizePalette(pdc->m_hDC); if (nColorsChanged > 0) { Invalidate(); } ::SelectPalette(pdc->m_hDC,oldPalette, TRUE); } ReleaseDC(pdc); return ((LRESULT) (BOOL) (nColorsChanged > 0)); } void CRightPaneWnd::OnActivateView(BOOL bActivate, CView* pActivateView, CView* pDeactiveView) { // TODO: Add your specialized code here and/or call the base class if (bActivate) { OnDoRealize((WPARAM)AfxGetApp()->m_pMainWnd->m_hWnd, (LPARAM) FALSE); // same as SendMessage(WM_DOREALIZE); } CView::OnActivateView(bActivate, pActivateView, pDeactiveView); } void CRightPaneWnd::UpdateView() { CMainFrame* pFrame = (CMainFrame*) AfxGetApp()->GetMainWnd(); OnDoRealize((WPARAM)AfxGetApp()->m_pMainWnd->m_hWnd, (LPARAM) FALSE); SendMessage(WM_SIZE, 0, 0); RedrawWindow(); } void CRightPaneWnd::OnSize(UINT nType, int cx, int cy) { CView::OnSize(nType, cx, cy); L_INT nWidth, nHeight, nVScroll, nHScroll; DWORD dwStyle; CMainFrame* pFrame = (CMainFrame*) AfxGetApp()->GetMainWnd(); if (pFrame == NULL) return; if (!pFrame->Bitmap.Flags.Allocated) /* If Flags is not allocated */ { /* set width and height to ZERO */ nWidth = 0; nHeight = 0; } else /* If Flags allocated */ { /* Scale the Bitmap Width to new Width */ nWidth = BITMAPWIDTH(&pFrame->Bitmap); /* Scale the Bitmap Height to new Height */ nHeight = BITMAPHEIGHT(&pFrame->Bitmap); } /* Set client dimensions to current width and height */ cxClient = cx; cyClient = cy; dwStyle = GetWindowLong (m_hWnd, GWL_STYLE); /* Get Vertical scroll arrow width */ nVScroll = GetSystemMetrics (SM_CXVSCROLL); /* Get Horizontal scroll arrow width */ nHScroll = GetSystemMetrics (SM_CXHSCROLL); /* If Vertical scroll */ if (WS_VSCROLL & dwStyle) cxClient += nVScroll; /* If Horizontal scroll */ if (WS_HSCROLL & dwStyle) cyClient += nHScroll; /* If client width < current width */ if (cxClient < nWidth) { cyClient -= nHScroll; if (cyClient < nHeight) cxClient -= nVScroll; } /* If client height < current height */ else if (cyClient < nHeight) { cxClient -= nVScroll; if (cxClient < nWidth) cyClient -= nHScroll; } /* Set Horizontal scroll step = 1/10 of client width, if > 1 */ nHScrollStep = max (1, cxClient / SCROLL_RATIO); /* Set Vertical scroll step = 1/10 of client height, if > 1 */ nVScrollStep = max (1, cyClient / SCROLL_RATIO); /* Set vetical scroll range */ nVScrollMax = max (0, (nHeight - cyClient /*- 1*/)); /* Set vertical scroll position */ nVScrollPos = max (0, min (nVScrollPos, nVScrollMax)); /* Set horizontal scroll range */ nHScrollMax = max (0, (nWidth - cxClient /*- 1*/)); /* Set horizontal scroll position */ nHScrollPos = max (0, min (nHScrollPos, nHScrollMax)); /* If Flags allocated */ if (pFrame->Bitmap.Flags.Allocated) { /* Set rcView to new width and new height */ SetRect (&rcView, 0, 0, nWidth, nHeight); /* Set offset by current scroll position */ OffsetRect (&rcView, -nHScrollPos, -nVScrollPos); } /* Set horizontal scroll range = nHScrollMax */ ::SetScrollRange (m_hWnd, SB_HORZ, 0, nHScrollMax, FALSE); /* Set horintal scroll position */ ::SetScrollPos (m_hWnd, SB_HORZ, nHScrollPos, TRUE); /* Set vertical scroll range = nVScrollMax */ ::SetScrollRange (m_hWnd, SB_VERT, 0, nVScrollMax, FALSE); /* Set vertical scroll position */ ::SetScrollPos (m_hWnd, SB_VERT, nVScrollPos, TRUE); } L_INT CRightPaneWnd::ScaleDimension (L_INT nWidth, L_INT nFactor) { if (0 < nFactor) /* Zoom in Condition */ return (nWidth * (nFactor + 1)); else if (0 > nFactor) /* Zoom out Condition */ return (nWidth / (1 - nFactor)); else return nWidth; } void CRightPaneWnd::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) { CView::OnHScroll(nSBCode, nPos, pScrollBar); L_INT nScrollInc; /* Horizontal Increment for scroll */ switch (nSBCode) { /* Decrement by current scroll position */ case SB_LEFT: nScrollInc = -nHScrollPos; break; /* Increment by the difference between Max scroll and current scroll position */ case SB_RIGHT: nScrollInc = nHScrollMax - nHScrollPos; break; /* Decrement by one step */ case SB_LINELEFT: nScrollInc = -nHScrollStep; break; /* Increment by one step */ case SB_LINERIGHT: nScrollInc = nHScrollStep; break; /* Decrement by Maximum */ case SB_PAGELEFT: nScrollInc = -max (nHScrollStep, (cxClient - nHScrollStep)); break; /* Increment by Maximum */ case SB_PAGERIGHT: nScrollInc = max (nHScrollStep, (cxClient - nHScrollStep)); break; /* Increment by difference between current scroll position and THUMB position */ case SB_THUMBTRACK: case SB_THUMBPOSITION: nScrollInc = nPos - nHScrollPos; break; default: nScrollInc = 0; break; } nScrollInc = max (-nHScrollPos, min (nScrollInc, (nHScrollMax - nHScrollPos))); if (nScrollInc) { /* if Scroll increment is greater than nScrollInc, Increment scroll position by nScrollInc */ nHScrollPos += nScrollInc; /* Reposition the picture at (0, -nScrollInc) */ OffsetRect (&rcView, -nScrollInc, 0); /* Scroll left the window by nSrollInc */ ::ScrollWindow (m_hWnd, -nScrollInc, 0, NULL, NULL); /* Set new scroll position at current scroll position; */ ::SetScrollPos (m_hWnd, SB_HORZ, nHScrollPos, TRUE); /* Update window */ ::UpdateWindow (m_hWnd); } } void CRightPaneWnd::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) { CView::OnVScroll(nSBCode, nPos, pScrollBar); L_INT nScrollInc; /* Vertical Increment for Scroll */ switch (nSBCode) { case SB_BOTTOM: /* Increment by Difference between Max scroll and current scroll position */ nScrollInc = nVScrollMax - nVScrollPos; break; case SB_TOP: /* Decrement by current scroll position */ nScrollInc = -nVScrollPos; break; case SB_LINEDOWN: /* Increment by one step */ nScrollInc = nVScrollStep; break; case SB_LINEUP: /* Decrement by one step */ nScrollInc = -nVScrollStep; break; case SB_PAGEDOWN: /* Increment by Maximum */ nScrollInc = max (nVScrollStep, (cyClient - nVScrollStep)); break; case SB_PAGEUP: /* Decrement by Maximum */ nScrollInc = -max (nVScrollStep, (cyClient - nVScrollStep)); break; case SB_THUMBTRACK: case SB_THUMBPOSITION: /* Increment by Difference between Current scroll position and THUMB position */ nScrollInc = nPos - nVScrollPos; break; default: /* No increment */ nScrollInc = 0; break; } nScrollInc = max (-nVScrollPos, min (nScrollInc, (nVScrollMax - nVScrollPos))); if (nScrollInc) { /* if Scroll increment is greater than nScrollInc, Increment scroll position by nScrollInc */ nVScrollPos += nScrollInc; /* Reposition the picture at (0, -nScrollInc) */ OffsetRect (&rcView, 0, -nScrollInc); /* Scroll up the window by nSrollInc */ ::ScrollWindow (m_hWnd, 0, -nScrollInc, NULL, NULL); /* Set new scroll position at current scroll position */ ::SetScrollPos (m_hWnd, SB_VERT, nVScrollPos, TRUE); /* Update window */ ::UpdateWindow (m_hWnd); } } int CRightPaneWnd::OnCreate(LPCREATESTRUCT lpCreateStruct) { if (CView::OnCreate(lpCreateStruct) == -1) return -1; L_INT nRet; nRet = L_DoubleBufferCreateHandle(&hDoubleBufferHandle); nRet = L_DoubleBufferEnable(hDoubleBufferHandle, TRUE); return 0; }