home *** CD-ROM | disk | FTP | other *** search
/ Chip 1998 February / CHIP_2_98.iso / software / pelne / optionp / msmqocm.cab / DRAWAREA.CPP < prev    next >
C/C++ Source or Header  |  1997-10-06  |  5KB  |  255 lines

  1. // drawarea.cpp : implementation file
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "disdraw.h"
  6. #include "drawdlg.h"
  7.  
  8. #ifdef _DEBUG
  9. #define new DEBUG_NEW
  10. #undef THIS_FILE
  11. static char THIS_FILE[] = __FILE__;
  12. #endif
  13.  
  14. /////////////////////////////////////////////////////////////////////////////
  15. // CDrawArea
  16.  
  17. CDrawArea::CDrawArea()
  18. {
  19. }
  20.  
  21. CDrawArea::~CDrawArea()
  22. {
  23. }
  24.  
  25.  
  26. BEGIN_MESSAGE_MAP(CDrawArea, CEdit)
  27.     //{{AFX_MSG_MAP(CDrawArea)
  28.     ON_WM_LBUTTONDOWN()
  29.     ON_WM_MOUSEMOVE()
  30.     ON_WM_PAINT()
  31.     ON_WM_RBUTTONUP()
  32.     ON_WM_CTLCOLOR_REFLECT()
  33.     ON_WM_KEYDOWN()
  34.     ON_WM_CHAR()
  35.     ON_WM_SETFOCUS()
  36.     ON_WM_SETCURSOR()
  37.     ON_WM_LBUTTONDBLCLK()
  38.     //}}AFX_MSG_MAP
  39. END_MESSAGE_MAP()
  40.  
  41. /////////////////////////////////////////////////////////////////////////////
  42. // CDrawArea message handlers
  43.  
  44. void CDrawArea::AddKeystroke(char *mbsKey)
  45. {
  46.     //
  47.     // The backspace keystroke should erase the last character
  48.     //
  49.     if (mbsKey[0] == VK_BACK)
  50.     {
  51.         int nStart, nEnd;
  52.         GetSel(nStart, nEnd);
  53.         SetSel(nEnd-1, nEnd);
  54.         mbsKey[0] = '\0';
  55.  
  56.         //
  57.         // Erasing a line feed should erase the preceding carriage return
  58.         //
  59.         CString strText;
  60.         GetWindowText(strText);
  61.         int iLength = strText.GetLength();
  62.         if (iLength > 0 && strText.GetAt(strText.GetLength() - 1) == '\n')
  63.             SetSel(nEnd-2, nEnd);
  64.     }
  65.  
  66.     //
  67.     // Append a line feed to a carriage return
  68.     //
  69.     else if (mbsKey[0] == VK_RETURN)
  70.         strcat(mbsKey, "\xa");
  71.  
  72.     //
  73.     // Store the new keystroke
  74.     //
  75.     ReplaceSel(mbsKey);
  76. }
  77.  
  78.  
  79. void CDrawArea::AddLine(LINE line)
  80. {
  81.     //
  82.     // Set the clipping region for the drawing
  83.     //
  84.     CClientDC dc(this);
  85.     RECT rect;
  86.     GetClientRect(&rect);
  87.     CRgn rgn;
  88.     rgn.CreateRectRgnIndirect(&rect); 
  89.     dc.SelectClipRgn(&rgn);
  90.  
  91.     //
  92.     // Draw the line and save it for redrawing
  93.     //
  94.     dc.MoveTo(line.ptStart);
  95.     dc.LineTo(line.ptEnd);
  96.     m_listLines.AddTail(line);
  97. }
  98.  
  99.  
  100. void CDrawArea::OnLButtonDown(UINT nFlags, CPoint point) 
  101. {
  102.     // TODO: Add your message handler code here and/or call default
  103.     
  104.     m_ptLast = point;
  105.     SetFocus();
  106. }
  107.  
  108.  
  109. void CDrawArea::OnMouseMove(UINT nFlags, CPoint point) 
  110. {
  111.     // TODO: Add your message handler code here and/or call default
  112.     
  113.     if (nFlags & MK_LBUTTON)
  114.     {
  115.         //
  116.         // Add the drawn line to the drawing
  117.         //
  118.         LINE line;
  119.         line.ptStart = m_ptLast;
  120.         line.ptEnd = point;
  121.         AddLine(line);
  122.  
  123.         //
  124.         // Send the line to the friend
  125.         //
  126.         ((CDisdrawDlg *)GetParent())->SendMouseMovement(line);
  127.  
  128.         //
  129.         // Remember the end point of the line 
  130.         //
  131.         m_ptLast = point;
  132.     }
  133. }
  134.  
  135.  
  136. void CDrawArea::OnPaint() 
  137. {
  138.     CPaintDC dc(this); // device context for painting
  139.     
  140.     // TODO: Add your message handler code here
  141.  
  142.     //
  143.     // Set the clipping region for the drawing
  144.     //
  145.     RECT rect;
  146.     GetClientRect(&rect);
  147.     CRgn rgn;
  148.     rgn.CreateRectRgnIndirect(&rect); 
  149.     dc.SelectClipRgn(&rgn);
  150.  
  151.     //
  152.     // Erase the drawing area
  153.     //
  154.     dc.FillSolidRect(&rect, GetSysColor(COLOR_MENU));
  155.  
  156.     //
  157.     // Redisplay the text
  158.     //
  159.     CString strText;
  160.     GetWindowText(strText);
  161.     dc.SelectStockObject(ANSI_VAR_FONT);
  162.     rect.top++;
  163.     rect.left++;
  164.     dc.DrawText(strText, &rect, DT_TOP | DT_WORDBREAK);
  165.  
  166.     //
  167.     // Redraw each line
  168.     //
  169.     LINE line;
  170.     POSITION posLine = m_listLines.GetHeadPosition();
  171.     while (posLine != NULL)
  172.     {
  173.         line = m_listLines.GetNext(posLine);
  174.         dc.MoveTo(line.ptStart);
  175.         dc.LineTo(line.ptEnd);
  176.     }
  177.  
  178.     // Do not call CEdit::OnPaint() for painting messages
  179. }
  180.  
  181.  
  182. void CDrawArea::OnRButtonUp(UINT nFlags, CPoint point) 
  183. {
  184.     // TODO: Add your message handler code here and/or call default
  185.     
  186.     //
  187.     // Clear the drawing area
  188.     //
  189.     SetSel(0, -1);
  190.     Clear();
  191.     m_listLines.RemoveAll();
  192.     RedrawWindow();
  193. }
  194.  
  195.  
  196. BOOL CDrawArea::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message) 
  197. {
  198.     // TODO: Add your message handler code here and/or call default
  199.     
  200.     return 0;
  201. }
  202.  
  203.  
  204. void CDrawArea::OnSetFocus(CWnd* pOldWnd) 
  205. {
  206.     CEdit::OnSetFocus(pOldWnd);
  207.     
  208.     // TODO: Add your message handler code here
  209.  
  210.     HideCaret();
  211. }
  212.  
  213.  
  214. HBRUSH CDrawArea::CtlColor(CDC* pDC, UINT nCtlColor) 
  215. {
  216.     // TODO: Change any attributes of the DC here
  217.     pDC->SetBkColor(GetSysColor(COLOR_MENU));
  218.     
  219.     // TODO: Return a non-NULL brush if the parent's handler should not be called
  220.     return HBRUSH((CBrush *)pDC->SelectStockObject(LTGRAY_BRUSH));
  221. }
  222.  
  223.  
  224. void CDrawArea::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) 
  225. {
  226.     // TODO: Add your message handler code here and/or call default
  227.  
  228.     switch (nChar)
  229.     {
  230.     case VK_LEFT:
  231.     case VK_RIGHT:
  232.     case VK_UP:
  233.     case VK_DOWN:    
  234.     case VK_HOME:    break;
  235.     default:        CEdit::OnKeyDown(nChar, nRepCnt, nFlags);
  236.     }
  237. }
  238.  
  239.  
  240. void CDrawArea::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags) 
  241. {
  242.     // TODO: Add your message handler code here and/or call default
  243.     ((CDisdrawDlg *)GetParent())->SendKeystroke(nChar);
  244.     
  245.     CEdit::OnChar(nChar, nRepCnt, nFlags);
  246.  
  247.     RedrawWindow();
  248. }
  249.  
  250.  
  251. void CDrawArea::OnLButtonDblClk(UINT nFlags, CPoint point) 
  252. {
  253.     // TODO: Add your message handler code here and/or call default
  254. }
  255.