SHEETREPORT.CPP
上传用户:lvjun8202
上传日期:2013-04-30
资源大小:797k
文件大小:19k
- /************************************
- REVISION LOG ENTRY
- Revision By: Mihai Filimon
- Revised on 7/21/98 10:12:24 AM
- Comments: SheetAlpha.cpp: implementation of the CSheetReport class.
- ************************************/
- #include "stdafx.h"
- #include "SheetReport.h"
- //////////////////////////////////////////////////////////////////////
- // Construction/Destruction
- //////////////////////////////////////////////////////////////////////
- #define IDTIMERWAITTODRAG 1000
- #define WAITTODRAG 500
- #define IDTIMERSCROLL 1001
- #define IDTIMERSPLASH 1002
- #define WAITSCROLL 10
- BEGIN_MESSAGE_MAP(CSheetReport, CSheetsWnd)
- //{{AFX_MSG_MAP(CSheetReport)
- ON_WM_LBUTTONDOWN()
- ON_WM_CREATE()
- ON_WM_HSCROLL()
- ON_WM_MOUSEMOVE()
- ON_WM_LBUTTONUP()
- ON_WM_SETCURSOR()
- ON_WM_TIMER()
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- // Function name : CSheetReport::CSheetReport
- // Description : Default constructor of object
- // Return type :
- CSheetReport::CSheetReport()
- {
- m_nActive = -1;
- m_fDXScrollBar = (double)2 / 5;
- m_nDXSplitter = 5;
- m_bCaptured = FALSE;
- }
- // Function name : CSheetReport::~CSheetReport
- // Description : Destructor of this object
- // Return type :
- CSheetReport::~CSheetReport()
- {
- int nCount = m_arrViews.GetSize();
- for (int i = 0; i < nCount; i++)
- delete m_arrViews.GetAt(i);
- m_arrViews.RemoveAll();
- }
- // Function name : CSheetReport::GetFirstView overridable
- // Description : See CSheetsWnd::GetFirstView
- // Return type : CWnd*
- CWnd* CSheetReport::GetFirstView()
- {
- m_nFind = -1;
- return GetNextView();
- }
- // Function name : CSheetReport::GetNextView overridable
- // Description : See CSheetsWnd::GetNextView
- // Return type : CWnd*
- CWnd* CSheetReport::GetNextView()
- {
- if (++m_nFind < m_arrViews.GetSize())
- return m_arrViews[m_nFind];
- return NULL;
- }
- // Function name : CSheetReport::GetActiveView overridable
- // Description : See: CSheetsWnd::GetActiveView
- // Return type : CWnd*
- CWnd* CSheetReport::GetActiveView()
- {
- if ((m_nActive>=0) && (m_nActive < m_arrViews.GetSize()))
- {
- m_nFind = m_nActive;
- return m_arrViews[m_nActive];
- }
- return NULL;
- }
- // Function name : CSheetReport::SetActiveView
- // Description : Sets the active view
- // Return type : void
- // Argument : CWnd* pView
- void CSheetReport::SetActiveView(CWnd* pView)
- {
- // CSheetsWnd::SetActiveView(pView);
- CWnd* pOldActiveView = GetActiveView(), *pParent = GetParent();
- if (pView)
- if (pView != pOldActiveView)
- {
- // pParent->SendMessage(GetMessagePageChanging(), (WPARAM)pOldActiveView, (LPARAM)pView);
- if (!pOldActiveView || (pOldActiveView && pOldActiveView->m_hWnd != pView->m_hWnd))
- {
- pView->ShowWindow(SW_SHOW);
- if (pOldActiveView)
- pOldActiveView->ShowWindow(SW_HIDE);
- // Invalidate();
- // pParent->SendMessage(GetMessagePageChanged(), (WPARAM)pView, 0);
- }
- ((COutputReport *)pView)->m_nHasAlert = 0;
- // ((COutputReport *)pView)->SetSel();
- }
- if (pView)
- {
- CWnd* pParent = GetParent();
- int n = GetPageIndex(pView);
- pParent->SendMessage(GetMessagePageChanging(), (WPARAM)GetActiveView(), (LPARAM)pView);
- {
- if (n != m_nActive)
- {
- m_nActive = n;
- Invalidate();
- pParent->SendMessage(GetMessagePageChanged(), (WPARAM)pView, 0);
- }
- }
- }
- }
- // Function name : CSheetReport::GetViewTitle overridable
- // Description : See CSheetsWnd::GetViewTitle
- // Return type : CString
- // Argument : CWnd* pView
- CString CSheetReport::GetViewTitle(CWnd* pView)
- {
- CString result = ((COutputReport*) pView)->m_strName;
- if (result.IsEmpty())
- result = _T("Sheet");
- return result;
- // return CSheetsWnd::GetViewTitle(pView);
- }
- // Function name : CSheetReport::OnLButtonDown
- // Description : When user click in one of the pages..., it's different by CSheetsWnd::OnLButtonDown,
- // because in that object pages are not childs of parent object!
- // Return type : void
- // Argument : UINT nFlags
- // Argument : CPoint point
- void CSheetReport::OnLButtonDown(UINT nFlags, CPoint point)
- {
- SetFocus();
- if (GetSplitterRect().PtInRect(point))
- {
- m_bPointCaptured = point;
- m_bCaptured = TRUE;
- SetCapture();
- }
- BeginDrag(point);
- CSheetsWnd::OnLButtonDown (nFlags, point);
- }
- // Function name : CSheetReport::OnMouseMove
- // Description : When user move mouse and drag the splitter...
- // Return type : void
- // Argument : UINT nFlags
- // Argument : CPoint point
- void CSheetReport::OnMouseMove(UINT nFlags, CPoint point)
- {
- if (m_bCaptured)
- {
- CRect rect; GetClientRect(rect);
- m_fDXScrollBar = 1 - (double)point.x / rect.Width();
- Resize(GetParent()->m_hWnd);
- Invalidate();
- }
- TrackDrag(point);
-
- CSheetsWnd::OnMouseMove(nFlags, point);
- }
- // Function name : CSheetReport::OnLButtonUp
- // Description : Release the capture if object is captured. Remember spliter
- // Return type : void
- // Argument : UINT nFlags
- // Argument : CPoint point
- void CSheetReport::OnLButtonUp(UINT nFlags, CPoint point)
- {
- if (m_bCaptured)
- {
- m_bCaptured = FALSE;
- ReleaseCapture();
- }
- EndDrag(point);
-
- CSheetsWnd::OnLButtonUp(nFlags, point);
- }
- // Function name : CSheetReport::OnSetCursor
- // Description : When user scan splitter rect must be LR cursor.
- // Return type : BOOL
- // Argument : CWnd* pWnd
- // Argument : UINT nHitTest
- // Argument : UINT message
- BOOL CSheetReport::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
- {
- CPoint p;
- if (GetCursorPos(&p))
- {
- ScreenToClient(&p);
- if (GetSplitterRect().PtInRect(p))
- if (!m_sPageDrag.IsDragging())
- {
- ::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_SIZEWE));
- return TRUE;
- }
- }
-
- return CSheetsWnd::OnSetCursor(pWnd, nHitTest, message);
- }
- // Function name : CSheetReport::RecalcDrawRect
- // Description : If something occurs in that object, like scroll bar, splitter then
- // m_DrawRect member variable, must be overwrite, for painting message.
- // Return type : void
- void CSheetReport::RecalcDrawRect()
- {
- CRect rect; GetClientRect(rect);
- if (m_sbHorz.IsWindowVisible())
- {
- m_sbHorz.GetWindowRect(rect);
- ScreenToClient(rect);
- rect.right = rect.left;
- }
- m_DrawRect.right = rect.right - (bSplitter() ? m_nDXSplitter : 0);
- }
- // Function name : CSheetReport::Resize
- // Description : Do not call base Resize, because it's not the same situation
- // Return type : void
- // Argument : HWND hWndParent
- void CSheetReport::Resize(HWND hWndParent)
- {
- CRect rect = GetRect(hWndParent);
- MoveWindow(rect);
- rect.bottom = rect.top;
- rect.top = 0;
- int nIndex = 0;
- CWnd* pChild;// = GetFirstView();
- while (nIndex<m_arrViews.GetSize())
- {
- pChild = m_arrViews[nIndex];
- pChild->MoveWindow(rect);
- nIndex++;
- }
-
- GetWindowRect(rect);
- ScreenToClient(rect);
- CRect rectBtns; m_btns.GetWindowRect(rectBtns);
- ScreenToClient(rectBtns);
- rect.left = min(max(rectBtns.right + GetSplitterRect().Width(), rect.right - (int)((double)rect.Width() * m_fDXScrollBar)), rect.Width() - 8);
- m_sbHorz.MoveWindow(rect);
- RecalcDrawRect();
- Invalidate();
- }
- // Function name : CSheetReport::OnCreate
- // Description : Create a new scrollbar, for substitute an just in case that parent object
- // need a horizontal scroll bar
- // Return type : int
- // Argument : LPCREATESTRUCT lpCreateStruct
- int CSheetReport::OnCreate(LPCREATESTRUCT lpCreateStruct)
- {
- if (CSheetsWnd::OnCreate(lpCreateStruct) == -1)
- return -1;
-
- m_sbHorz.Create(WS_CHILD | SBS_HORZ, CRect(0,0,0,0), this, IDBTNS + 1);
- SetTimer(IDTIMERSPLASH,1000,NULL);
- return 0;
- }
- // Function name : CSheetReport::Draw
- // Description : Draw the pages of object, like CSheetsWnd::Draw() and complete the image of splitter.
- // Return type : void
- // Argument : CDC * pDC
- void CSheetReport::Draw(CDC * pDC)
- {
- CSheetsWnd::Draw(pDC);
- CRect rSplitter = GetSplitterRect();
- if (!rSplitter.IsRectEmpty())
- {
- pDC->FillRect(rSplitter, &CBrush(RGB(192,192,192)));
- static CPen pWhite(PS_SOLID,1,RGB(255,255,255));
- static CPen pGray(PS_SOLID,1,RGB(128,128,128));
- pDC->SelectObject(&pGray);
- CPoint p = rSplitter.TopLeft() + CPoint(1,1);
- p += CPoint(2,0);
- pDC->MoveTo(p);
- p += CPoint(0,rSplitter.Height() - 2);
- pDC->LineTo(p);
- p += CPoint(-2,0);
- pDC->LineTo(p);
- pDC->SelectObject(&pWhite);
- p += CPoint(0,-(rSplitter.Height() - 2));
- pDC->LineTo(p);
- p += CPoint(2,0);
- pDC->LineTo(p);
- }
- }
- // Function name : CSheetReport::ShowScrollBar
- // Description : Show or hide the scroll bar.m_sbHorz
- // Return type : void
- // Argument : BOOL bShow
- void CSheetReport::ShowScrollBar(BOOL bShow)
- {
- m_sbHorz.ShowWindow(bShow ? SW_SHOW : SW_HIDE);
- RecalcDrawRect();
- Invalidate();
- }
- // Function name : CSheetReport::OnHScroll
- // Description : If the control receive a scroll message from m_sbHorz, then treat this
- // Return type : void
- // Argument : UINT nSBCode
- // Argument : UINT nPos
- // Argument : CScrollBar* pScrollBar
- void CSheetReport::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
- {
- if (pScrollBar->m_hWnd == m_sbHorz.m_hWnd)
- {
- CWnd* pParent = GetActiveView();
- ASSERT (pParent && GetParent()->m_hWnd);
- switch (nSBCode)
- {
- case SB_THUMBTRACK:
- {
- int npp = m_sbHorz.GetScrollPos();
- int n = nPos - npp;
- UINT nCode = n < 0 ? SB_LINELEFT : SB_LINERIGHT;
- int nStep = n < 0 ? -1 : 1;
- n = abs(n);
- for (int i = 0; i < n; i++ )
- {
- pParent->SendMessage(WM_HSCROLL, MAKELONG(nCode,1), (long)pScrollBar->m_hWnd);
- npp = npp + nStep;
- m_sbHorz.SetScrollPos(npp);
- }
- break;
- }
- default:
- {
- pParent->SendMessage(WM_HSCROLL, MAKELONG(nSBCode,nPos), (long)pScrollBar->m_hWnd);
- int x = m_sbHorz.GetScrollPos();
- int min = 0;
- int max = 1024;
- int page = 10;
- CWnd * pWnd = GetActiveView();
- if(pWnd && pWnd->GetSafeHwnd())
- {
- pWnd->GetScrollRange(SB_HORZ,&min,&max);
- CRect rc;
- pWnd->GetClientRect(&rc);
- page = rc.Width();
- }
- switch (nSBCode)
- {
- case SB_TOP:
- x = 0;
- break;
- case SB_BOTTOM:
- x = INT_MAX;
- break;
- case SB_LINEUP:
- x -= 1;
- break;
- case SB_LINEDOWN:
- x += 1;
- break;
- case SB_PAGEUP:
- x -= page;
- break;
- case SB_PAGEDOWN:
- x += page;
- break;
- case SB_THUMBTRACK:
- x = nPos;
- break;
- }
-
- if(x>max)
- x = max;
- m_sbHorz.SetScrollPos(x);//pParent->GetScrollPos(SB_HORZ));
- break;
- }
- }
- }
-
- CSheetsWnd::OnHScroll(nSBCode, nPos, pScrollBar);
- }
- // Function name : CSheetReport::bSplitter
- // Description : Return TRUE if splitter is showen in object, Private function.
- // Return type : BOOL
- BOOL CSheetReport::bSplitter()
- {
- return !(GetSplitterRect().IsRectEmpty());
- }
- // Function name : CSheetReport::EraseExclude
- // Description : When WM_ERASEBKGND occurs, then CSheetsWnd::OnEraseBkGnd,
- // require a rect that will be excluded from area erased.
- // Return type : CRect
- CRect CSheetReport::EraseExclude()
- {
- CRect rSplitter = GetSplitterRect();
- return m_DrawRect + CRect(0,0, rSplitter.IsRectEmpty() ? 0 : m_nDXSplitter,0);
- }
- // Function name : CSheetReport::GetSplitterRect
- // Description : If user want no splitter, must override this function, and return empty rect
- // Return type : CRect
- CRect CSheetReport::GetSplitterRect()
- {
- CRect result(0,0,0,0);
- if (m_sbHorz.IsWindowVisible())
- result = CRect(m_DrawRect.right, m_DrawRect.top, m_DrawRect.right + m_nDXSplitter, m_DrawRect.bottom);
- return result;
- }
- // Function name : CSheetReport::GetScrollBar
- // Description : Return the scroll bar of this object, created in OnCreate function
- // Return type : CScrollBar&
- CScrollBar& CSheetReport::GetScrollBar()
- {
- return m_sbHorz;
- }
- // Function name : CSheetReport::GetPageIndex
- // Description : Search for a pags with title lpszTitle, and return its position
- // Return type : int
- // Argument : LPCTSTR lpszTitle
- int CSheetReport::GetPageIndex(CWnd * pWnd)
- {
- int n = -1;
- for (int i = 0; i < m_arrViews.GetSize(); i++)
- {
- if (pWnd == m_arrViews[i])
- {
- n = i;
- break;
- }
- }
- return n;
- }
- // Function name : CSheetReport::AddPage
- // Description : Add a new page to object, and return index position
- // Return type : int
- // Argument : LPCTSTR lpszTitle
- int CSheetReport::AddPage(LPCTSTR lpszTitle)
- {
- COutputReport * pWnd = new COutputReport();
- pWnd->m_strName = lpszTitle;
- if(!pWnd->Create(NULL,"123",WS_CHILD|WS_VISIBLE,CRect(0,0,100,100),GetParent(),100))
- {
- delete pWnd;
- return -1;
- }
- static COLORREF rgbText[16] =
- {
- RGB(0,128,0),
- RGB(0,0,255),
- RGB(255,255,0),
- RGB(255,0,0),
- RGB(0,0,128),
- RGB(255,0,255),
- RGB(0,255,255),
- RGB(0,0,0),
- RGB(0,0,0),
- RGB(0,0,0),
- RGB(0,0,0),
- RGB(0,0,0),
- RGB(0,0,0),
- RGB(0,0,0),
- RGB(0,0,0),
- RGB(255,255,255)
- };
- pWnd->SetColourTable(rgbText);
- //CShowCase
- /* if(!pWnd->Create(WS_CHILD|WS_VISIBLE|ES_MULTILINE|ES_AUTOVSCROLL|WS_VSCROLL|ES_AUTOHSCROLL,CRect(0,0,0,0),GetParent(),1111))
- {
- delete pWnd;
- return -1;
- }
- */
- // pWnd->SetBackgroundColor(FALSE,RGB(0,0,0));
- //C
- /* if(!pWnd->Create(NULL,"",WS_CHILD|WS_VISIBLE|WS_VSCROLL,CRect(0,0,0,0),GetParent(),1111))
- {
- delete pWnd;
- return -1;
- }
- */
- // LOGFONT LogFont;
- // m_fontSys.GetLogFont( &LogFont );
- //// pWnd->SetFont(&m_fontSys);
- //// pWnd->SetReadOnly();
- // pWnd->SetWindowText(lpszTitle);
- pWnd->ShowWindow(SW_HIDE);
- //// pWnd->Initialize();
- /* pWnd->SetCaseSensitive(FALSE);
- pWnd->SetStringQuotes(_T("""));
- pWnd->SetSLComment(_T('''));
- pWnd->SetSLComment(_T("rem"));
- */
- // pWnd->AddKeywords(szKeywords);
- // pWnd->AddConstants(szConstants);
-
- int nResult = m_arrViews.Add(pWnd);
- pWnd->m_nChildID = nResult;
- Invalidate();
- return nResult;
- }
- // Function name : CSheetReport::RemovePage
- // Description : Remove page with title lpszTitle if founded
- // Return type : void
- // Argument : LPCTSTR lpszTitle
- void CSheetReport::RemovePage(LPCTSTR lpszTitle)
- {
- int nPage = GetPageIndex(lpszTitle);
- if (nPage >= 0)
- {
- COutputReport * pWnd = m_arrViews.GetAt(nPage);
- m_arrViews.RemoveAt(nPage);
- delete pWnd;
- Invalidate();
- }
- }
- // Function name : CSheetReport::RemovePage
- // Description : Remove page by position
- // Return type : void
- // Argument : int nPage
- void CSheetReport::RemovePage(int nPage)
- {
- COutputReport * pWnd = m_arrViews.GetAt(nPage);
- m_arrViews.RemoveAt(nPage);
- delete pWnd;
- Invalidate();
- }
- // Function name : CSheetReport::BeginDrag
- // Description : Start the dragging page if is case
- // Return type : void
- // Argument : CPoint ptn
- void CSheetReport::BeginDrag(CPoint ptn)
- {
- if (GetDrawRect().PtInRect(ptn))
- if (CWnd* pView = GetViewFromPoint(ptn))
- {
- m_sPageDrag.SetTrackDrag(pView);
- SetTimer(IDTIMERWAITTODRAG, WAITTODRAG, NULL);
- SetTimer(IDTIMERSCROLL,WAITSCROLL,NULL);
- }
- }
- // Function name : CSheetReport::TrackDrag
- // Description : Continue the dragging page
- // Return type : void
- // Argument : CPoint ptn
- void CSheetReport::TrackDrag(CPoint ptn)
- {
- if (m_sPageDrag.IsDragging())
- {
- m_sPageDrag.SetTrackDrag(GetViewFromPoint(ptn));
- m_sPageDrag.Draw(this);
- }
- }
- // Function name : CSheetReport::EndDrag
- // Description : Stop the draging page
- // Return type : void
- // Argument : CPoint ptn
- void CSheetReport::EndDrag(CPoint ptn)
- {
- KillTimer(IDTIMERWAITTODRAG);
- if (m_sPageDrag.IsDragging())
- {
- KillTimer(IDTIMERSCROLL);
- m_sPageDrag.SetTrackDrag(GetViewFromPoint(ptn));
- CDragPage sPageDrag(m_sPageDrag);
- // Reset the current values drag
- m_sPageDrag.Reset();
- ReleaseCapture();
- // Draw
- m_sPageDrag.Draw(this);
- // If case, change pages between them
- if (sPageDrag.GetTrackDrag() && sPageDrag.GetStartDrag())
- if (sPageDrag.GetTrackDrag() != sPageDrag.GetStartDrag())
- {
- int nS = GetPageIndex(sPageDrag.GetStartDrag());
- int nE = GetPageIndex(sPageDrag.GetTrackDrag());
- COutputReport * s = m_arrViews.GetAt(nS);
- COutputReport * e = m_arrViews.GetAt(nE);
- m_arrViews.SetAt(nS,e);
- m_arrViews.SetAt(nE,s);
- m_nActive = nE;
- Invalidate();
- }
- }
- }
- // Function name : CSheetReport::OnTimer
- // Description : Wait starting to drag
- // Return type : void
- // Argument : UINT nIDEvent
- void CSheetReport::OnTimer(UINT nIDEvent)
- {
- CPoint p;
- if (GetCursorPos(&p))
- {
- ScreenToClient(&p);
- switch (nIDEvent)
- {
- case IDTIMERWAITTODRAG:
- {
- if (CWnd* pViewTrackDrag = m_sPageDrag.GetTrackDrag())
- if (GetViewFromPoint(p) == pViewTrackDrag)
- {
- m_sPageDrag.Set(TRUE, pViewTrackDrag);
- m_sPageDrag.Draw(this);
- SetCapture();
- }
- KillTimer(IDTIMERWAITTODRAG);
- break;
- }
- case IDTIMERSCROLL:
- {
- if (m_sPageDrag.IsDragging())
- if (!m_DrawRect.PtInRect(p))
- if (p.y > m_DrawRect.top)
- if (p.y < m_DrawRect.bottom)
- {
- m_sPageDrag.SetTrackDrag(GetViewFromPoint(p));
- m_sPageDrag.Draw(this);
- SendMessage(WM_HSCROLL, MAKEWPARAM(p.x < m_DrawRect.left ? SB_LINELEFT : SB_LINERIGHT, 0), (LPARAM)m_btns.m_hWnd);
- }
- break;
- }
- }
- }
- if(nIDEvent == IDTIMERSPLASH)
- {
- int nIndex = 0;
- COutputReport* pChild;
- while (nIndex<m_arrViews.GetSize())
- {
- pChild = m_arrViews[nIndex];
- if(pChild->m_nHasAlert)
- {
- pChild->m_nSplashCnt = !pChild->m_nSplashCnt;
- InvalidateRect(GetPageRect(pChild));
- }
- nIndex++;
- }
- }
- CSheetsWnd::OnTimer(nIDEvent);
- }
- int CSheetReport::GetPageIndex(LPCTSTR lpszTitle)
- {
- int n = -1;
- CString str;
- for (int i = 0; i < m_arrViews.GetSize(); i++)
- {
- str = m_arrViews[i]->m_strName;
- if (str.CompareNoCase(lpszTitle) == 0)
- {
- n = i;
- break;
- }
- }
- return n;
- }
- int CSheetReport::AddPage(CWnd *pWnd)
- {
- int nResult = m_arrViews.Add((COutputReport*)pWnd);
- Invalidate();
- return nResult;
- }
- COutputReport * CSheetReport::GetPageAt(int nIndex)
- {
- if (nIndex < m_arrViews.GetSize() && nIndex>=0)
- return m_arrViews[nIndex];
- return NULL;
- }
- void CSheetReport::Splash(int nPage)
- {
- COutputReport * pView = GetPageAt(nPage);
- Splash(pView);
- }
- CBrush * CSheetReport::GetPageBkBrush(int nPage)
- {
- COutputReport * pView = GetPageAt(nPage);
- return GetPageBkBrush(pView);
- }
- CBrush * CSheetReport::GetPageBkBrush(CWnd *pView)
- {
- static CBrush br(RGB(0,255,0));
- static CBrush br1(RGB(255,0,0));
- static CBrush br2(RGB(255,255,0));
- static CBrush br3(RGB(0,0,255));
- if(pView)
- if(((COutputReport *)pView)->m_nHasAlert && ((COutputReport *)pView)->m_nSplashCnt)
- {
- switch(((COutputReport *)pView)->m_nChildID)
- {
- case 0:
- return &br;
- break;
- case 1:
- return &br1;
- break;
- case 2:
- return &br2;
- break;
- default:
- return &br3;
- break;
- }
- }
- return CSheetsWnd::GetPageBkBrush(pView);
- }
- void CSheetReport::Splash(CWnd *pView)
- {
- ((COutputReport*)pView)->m_nSplashCnt = 1;
- InvalidateRect(GetPageRect(pView));
- }