home *** CD-ROM | disk | FTP | other *** search
- // TextDeVw.cpp : implementation of the CTextDemoView class
- //
-
- #include "stdafx.h"
- #include "TextDemo.h"
-
- #include "TextDDoc.h"
- #include "TextDeVw.h"
-
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
-
- /////////////////////////////////////////////////////////////////////////////
- // CTextDemoView
-
- IMPLEMENT_DYNCREATE(CTextDemoView, CScrollView)
-
- BEGIN_MESSAGE_MAP(CTextDemoView, CScrollView)
- //{{AFX_MSG_MAP(CTextDemoView)
- ON_WM_KEYDOWN()
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
-
- /////////////////////////////////////////////////////////////////////////////
- // CTextDemoView construction/destruction
-
- CTextDemoView::CTextDemoView()
- {
- // TODO: add construction code here
-
- }
-
- CTextDemoView::~CTextDemoView()
- {
- }
-
- BOOL CTextDemoView::PreCreateWindow(CREATESTRUCT& cs)
- {
- // TODO: Modify the Window class or styles here by modifying
- // the CREATESTRUCT cs
-
- return CScrollView::PreCreateWindow(cs);
- }
-
- /////////////////////////////////////////////////////////////////////////////
- // CTextDemoView drawing
-
- void CTextDemoView::OnDraw(CDC* pDC)
- {
- CTextDemoDoc* pDoc = GetDocument();
- ASSERT_VALID(pDoc);
-
- // TODO: add draw code for native data here
-
- // return if font has not yet been created:
- if (pDoc->m_Font.m_hObject == NULL)
- return;
-
- RECT ClipRect;
- int LineHeight;
- TEXTMETRIC TM;
- int Y = MARGIN;
-
- // select font into device context object:
- pDC->SelectObject (&pDoc->m_Font);
-
- // obtain text metrics:
- pDC->GetTextMetrics (&TM);
- LineHeight = TM.tmHeight + TM.tmExternalLeading;
-
- // set text attributes:
- pDC->SetTextColor (pDoc->m_Color);
- pDC->SetBkMode (TRANSPARENT);
-
- // obtain coordinates of invalidated area:
- pDC->GetClipBox (&ClipRect);
-
- // display title line:
- pDC->TextOut (MARGIN, Y, "FONT PROPERTIES");
-
- // display text lines:
- for (int Line = 0; Line < NUMLINES; ++Line)
- {
- Y += LineHeight;
- if (Y + LineHeight >= ClipRect.top && Y <= ClipRect.bottom)
- pDC->TextOut (MARGIN, Y, pDoc->m_LineTable [Line]);
- }
- }
-
- /////////////////////////////////////////////////////////////////////////////
- // CTextDemoView diagnostics
-
- #ifdef _DEBUG
- void CTextDemoView::AssertValid() const
- {
- CScrollView::AssertValid();
- }
-
- void CTextDemoView::Dump(CDumpContext& dc) const
- {
- CScrollView::Dump(dc);
- }
-
- CTextDemoDoc* CTextDemoView::GetDocument() // non-debug version is inline
- {
- ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CTextDemoDoc)));
- return (CTextDemoDoc*)m_pDocument;
- }
- #endif //_DEBUG
-
- /////////////////////////////////////////////////////////////////////////////
- // CTextDemoView message handlers
-
- void CTextDemoView::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint)
- {
- // TODO: Add your specialized code here and/or call the base class
-
- CTextDemoDoc* PDoc = GetDocument();
-
- if (PDoc->m_Font.m_hObject == NULL) // font not yet created
- SetScrollSizes (MM_TEXT, CSize (0,0));
- else // font created
- {
- CClientDC ClientDC (this);
- int LineWidth = 0;
- SIZE Size;
- TEXTMETRIC TM;
-
- ClientDC.SelectObject (&PDoc->m_Font);
- ClientDC.GetTextMetrics (&TM);
-
- for (int Line = 0; Line < NUMLINES; ++Line)
- {
- Size = ClientDC.GetTextExtent
- (PDoc->m_LineTable [Line],
- PDoc->m_LineTable [Line].GetLength ());
- if (Size.cx > LineWidth)
- LineWidth = Size.cx;
- }
-
- Size.cx = LineWidth + MARGIN;
- Size.cy = (TM.tmHeight + TM.tmExternalLeading) * (NUMLINES + 1) + MARGIN;
-
- SetScrollSizes (MM_TEXT, Size);
- ScrollToPosition (CPoint (0, 0));
- }
-
- CScrollView::OnUpdate (pSender, lHint, pHint);
- }
-
- void CTextDemoView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
- {
- // TODO: Add your message handler code here and/or call default
-
- CSize DocSize = GetTotalSize ();
- RECT ClientRect;
- GetClientRect (&ClientRect);
-
- switch (nChar)
- {
- case VK_LEFT: // left arrow
- if (ClientRect.right < DocSize.cx)
- SendMessage (WM_HSCROLL, SB_LINEUP);
- break;
-
- case VK_RIGHT: // right arrow
- if (ClientRect.right < DocSize.cx)
- SendMessage (WM_HSCROLL, SB_LINEDOWN);
- break;
-
- case VK_UP: // up arrow
- if (ClientRect.bottom < DocSize.cy)
- SendMessage (WM_VSCROLL, SB_LINEUP);
- break;
-
- case VK_DOWN: // down arrow
- if (ClientRect.bottom < DocSize.cy)
- SendMessage (WM_VSCROLL, SB_LINEDOWN);
- break;
-
- case VK_HOME: // Home key
- if (::GetKeyState (VK_CONTROL) & 0x8000) // Ctrl pressed
- {
- if (ClientRect.bottom < DocSize.cy)
- SendMessage (WM_VSCROLL, SB_TOP);
- }
- else // Home key alone
- {
- if (ClientRect.right < DocSize.cx)
- SendMessage (WM_HSCROLL, SB_TOP);
- }
- break;
-
- case VK_END: // End key
- if (::GetKeyState (VK_CONTROL) & 0x8000) // Ctrl pressed
- {
- if (ClientRect.bottom < DocSize.cy)
- SendMessage (WM_VSCROLL, SB_BOTTOM);
- }
- else // End key alone
- {
- if (ClientRect.right < DocSize.cx)
- SendMessage (WM_HSCROLL, SB_BOTTOM);
- }
- break;
-
- case VK_PRIOR: // PgUp key
- if (ClientRect.bottom < DocSize.cy)
- SendMessage (WM_VSCROLL, SB_PAGEUP);
- break;
-
- case VK_NEXT: // PgDn key
- if (ClientRect.bottom < DocSize.cy)
- SendMessage (WM_VSCROLL, SB_PAGEDOWN);
- break;
- }
-
- CScrollView::OnKeyDown(nChar, nRepCnt, nFlags);
- }
-