home *** CD-ROM | disk | FTP | other *** search
/ Mastering MFC Development / MMD.ISO / samples / c06 / tabbed / tabbview.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1997-02-20  |  3.2 KB  |  124 lines

  1. // TabbView.cpp : implementation of the CTabbedColorPhraseView class
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "Tabbed.h"
  6.  
  7. #include "ClrLstBx.H"
  8. #include "ColorTab.H"
  9. #include "PhrasTab.H"
  10.  
  11. #include "TabbeDoc.h"
  12. #include "TabbView.h"
  13.  
  14. #ifdef _DEBUG
  15. #define new DEBUG_NEW
  16. #undef THIS_FILE
  17. static char THIS_FILE[] = __FILE__;
  18. #endif
  19.  
  20. /////////////////////////////////////////////////////////////////////////////
  21. // CTabbedColorPhraseView
  22.  
  23. IMPLEMENT_DYNCREATE(CTabbedColorPhraseView, CView)
  24.  
  25. BEGIN_MESSAGE_MAP(CTabbedColorPhraseView, CView)
  26.     //{{AFX_MSG_MAP(CTabbedColorPhraseView)
  27.     ON_COMMAND(ID_MODIFY_SHOWTABBEDDIALOGBOX, OnModifyShowtabbeddialogbox)
  28.     //}}AFX_MSG_MAP
  29. END_MESSAGE_MAP()
  30.  
  31. /////////////////////////////////////////////////////////////////////////////
  32. // CTabbedColorPhraseView construction/destruction
  33.  
  34. CTabbedColorPhraseView::CTabbedColorPhraseView()
  35. {
  36. }
  37.  
  38. CTabbedColorPhraseView::~CTabbedColorPhraseView()
  39. {
  40. }
  41.  
  42. BOOL CTabbedColorPhraseView::PreCreateWindow(CREATESTRUCT& cs)
  43. {
  44.     return CView::PreCreateWindow(cs);
  45. }
  46.  
  47. /////////////////////////////////////////////////////////////////////////////
  48. // CTabbedColorPhraseView drawing
  49.  
  50. void CTabbedColorPhraseView::OnDraw(CDC* pDC)
  51. {
  52.     CTabbedColorPhraseDoc* pDoc = GetDocument();
  53.     ASSERT_VALID(pDoc);
  54.  
  55.     CRect r;
  56.     GetClientRect(&r);
  57.     int x = r.right / 2, y = r.bottom / 2;
  58.  
  59.     pDC->SetTextColor(pDoc->GetColor());
  60.     pDC->SetTextAlign (TA_CENTER | TA_BASELINE);
  61.     pDC->TextOut (x, y, pDoc->GetPhrase());
  62. }
  63.  
  64. /////////////////////////////////////////////////////////////////////////////
  65. // CTabbedColorPhraseView diagnostics
  66.  
  67. #ifdef _DEBUG
  68. void CTabbedColorPhraseView::AssertValid() const
  69. {
  70.     CView::AssertValid();
  71. }
  72.  
  73. void CTabbedColorPhraseView::Dump(CDumpContext& dc) const
  74. {
  75.     CView::Dump(dc);
  76. }
  77.  
  78. CTabbedColorPhraseDoc* CTabbedColorPhraseView::GetDocument() // non-debug version is inline
  79. {
  80.     ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CTabbedColorPhraseDoc)));
  81.     return (CTabbedColorPhraseDoc*)m_pDocument;
  82. }
  83. #endif //_DEBUG
  84.  
  85. /////////////////////////////////////////////////////////////////////////////
  86. // CTabbedColorPhraseView message handlers
  87.  
  88. void CTabbedColorPhraseView::OnModifyShowtabbeddialogbox() 
  89. {
  90.     CTabbedColorPhraseDoc* pDoc = GetDocument();
  91.     ASSERT_VALID(pDoc);
  92.  
  93.     // Create each property page object and initialize
  94.     // as appropriate.
  95.     CPhraseTab phraseTab;
  96.     phraseTab.m_phrase = pDoc->GetPhrase();
  97.     
  98.     CColorTab colorTab;
  99.     colorTab.m_color = pDoc->GetColor();
  100.  
  101.     // Create the property sheet object and give it a title.
  102.     CPropertySheet cps("Modify Phrase or Color");
  103.  
  104.     // Add the largest property page first.
  105.     cps.AddPage(&phraseTab);
  106.     cps.AddPage(&colorTab);
  107.     
  108.     // Since this is being displayed modally instead of
  109.     // modelessly, remove the Apply button, which appears
  110.     // by default on Property Sheets.
  111.     cps.m_psh.dwFlags |= PSH_NOAPPLYNOW;
  112.     
  113.     // If the user clicks on OK and either color or phrase
  114.     // has changed, update the document and invalidate the view.
  115.     if (IDOK == cps.DoModal())
  116.         if (pDoc->GetPhrase() != phraseTab.m_phrase ||
  117.              pDoc->GetColor() != colorTab.m_color)
  118.         {
  119.             pDoc->SetColor(colorTab.m_color);
  120.             pDoc->SetPhrase(phraseTab.m_phrase);
  121.             Invalidate();
  122.         }
  123. }
  124.