home *** CD-ROM | disk | FTP | other *** search
/ PC Media 7 / PC MEDIA CD07.iso / share / uwin / cassette / tapeview.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1994-06-29  |  5.7 KB  |  217 lines

  1. // Copyright (c) 1994, William Wagner
  2. // All Rights reserved.
  3. //
  4. // This source is a portion of a shareware program.  It may be distributed
  5. // only in its entirety.  The copyright statements must be included with any 
  6. // reproduction of this source.
  7. // 
  8.  
  9. // tapeview.cpp : implementation file
  10. //
  11.  
  12. #include "stdafx.h"
  13. #include "cassette.h"
  14.  
  15. #include "tapeview.h"
  16. #include "cassedoc.h"
  17.  
  18. #ifdef _DEBUG
  19. #undef THIS_FILE
  20. static char BASED_CODE THIS_FILE[] = __FILE__;
  21. #endif
  22.  
  23. /////////////////////////////////////////////////////////////////////////////
  24. // CTapeView
  25.  
  26. IMPLEMENT_DYNCREATE(CTapeView, CFormView)
  27.  
  28. //Create this object.  Initialize the base class, and 
  29. //initialize the brush handle.
  30. CTapeView::CTapeView()
  31.     : CFormView(CTapeView::IDD),
  32.     m_hCtlBrush (::CreateSolidBrush (RGB (192, 192, 192)))
  33. {
  34.     //{{AFX_DATA_INIT(CTapeView)
  35.     //}}AFX_DATA_INIT
  36. }
  37.  
  38. //Destroy this object.  Delete the control brush.
  39. CTapeView::~CTapeView()
  40. {
  41. ASSERT_VALID (this);
  42. DeleteObject (m_hCtlBrush);
  43. }
  44.  
  45. //Data Exchanger.  This transfers data between the document object,
  46. // and the form controls.  This view object acts as a conduit 
  47. // between them.
  48. void CTapeView::DoDataExchange(CDataExchange* pDX)
  49. {
  50.     ASSERT_VALID (this);
  51.     ASSERT_VALID (GetDocument ());
  52.     
  53.     CFormView::DoDataExchange(pDX);
  54.     DDX_Text(pDX, IDC_ALBUM1, GetDocument ()->m_csAlbum1);
  55.     DDV_MaxChars(pDX, GetDocument ()->m_csAlbum1, 256);
  56.     DDX_Text(pDX, IDC_ALBUM2, GetDocument ()->m_csAlbum2);
  57.     DDV_MaxChars(pDX, GetDocument ()->m_csAlbum2, 256);
  58.     DDX_Text(pDX, IDC_ARTIST1, GetDocument ()->m_csArtist1);
  59.     DDV_MaxChars(pDX, GetDocument ()->m_csArtist1, 128);
  60.     DDX_Text(pDX, IDC_ARTIST2, GetDocument ()->m_csArtist2);
  61.     DDV_MaxChars(pDX, GetDocument ()->m_csArtist2, 128);
  62.     DDX_Text(pDX, IDC_SONGS1, GetDocument ()->m_csSongs1);
  63.     DDV_MaxChars(pDX, GetDocument ()->m_csSongs1, 1024);
  64.     DDX_Text(pDX, IDC_SONGS2, GetDocument ()->m_csSongs2);
  65.     DDV_MaxChars(pDX, GetDocument ()->m_csSongs2, 1024);
  66.     DDX_Text(pDX, IDC_NOTES, GetDocument ()->m_csNotes);
  67.     DDV_MaxChars(pDX, GetDocument ()->m_csNotes, 1024);
  68.     //{{AFX_DATA_MAP(CTapeView)
  69.     //}}AFX_DATA_MAP
  70.  
  71.     //If this is changing data in the document, then 
  72.     //set the document modified flags.   
  73.        if (pDX->m_bSaveAndValidate)
  74.         GetDocument ()->SetModifiedFlag (TRUE);
  75.  
  76.     ASSERT_VALID (GetDocument ());
  77. }
  78.  
  79. //Get a pointer to this document.
  80. #ifdef _DEBUG
  81. CCassetteDoc* CTapeView::GetDocument() // non-debug version is inline
  82. {
  83. ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CCassetteDoc)));
  84. return (CCassetteDoc*) m_pDocument;
  85. }
  86. #endif
  87.  
  88. //Initial Update.  
  89. // Use the Data Exchange mechanism to transfer data from the 
  90. // document to the controls in the view.
  91. void CTapeView::OnInitialUpdate ()
  92. {
  93. ASSERT_VALID (this);
  94. UpdateData (FALSE);
  95. }
  96.  
  97. //Update Data
  98. // If one of the document members changed, update the data in the
  99. // view.
  100. void CTapeView::OnUpdate (CView*, LPARAM lHint, CObject*)
  101. {
  102. ASSERT_VALID (this);
  103.  
  104. switch (lHint)
  105.     {
  106.     case FONT_ALBUM_CHANGE:
  107.     case FONT_ARTIST_CHANGE:
  108.     case FONT_NOTES_CHANGE:
  109.     case FONT_SONGS_CHANGE:
  110.         break;
  111.         
  112.     case ALBUM1_CHANGE:
  113.     case ALBUM2_CHANGE:
  114.     case ARTIST1_CHANGE:
  115.     case ARTIST2_CHANGE:
  116.     case SONGS1_CHANGE:
  117.     case SONGS2_CHANGE:
  118.     case NOTES_CHANGE:
  119.     default:
  120.         UpdateData (FALSE);
  121.         break;
  122.     }
  123. }
  124.  
  125. BEGIN_MESSAGE_MAP(CTapeView, CFormView)
  126.     //{{AFX_MSG_MAP(CTapeView)
  127.     ON_WM_CTLCOLOR()
  128.     ON_EN_CHANGE(IDC_ALBUM1, OnChangeAlbum1)
  129.     ON_EN_CHANGE(IDC_ALBUM2, OnChangeAlbum2)
  130.     ON_EN_CHANGE(IDC_ARTIST1, OnChangeArtist1)
  131.     ON_EN_CHANGE(IDC_ARTIST2, OnChangeArtist2)
  132.     ON_EN_CHANGE(IDC_NOTES, OnChangeNotes)
  133.     ON_EN_CHANGE(IDC_SONGS1, OnChangeSongs1)
  134.     ON_EN_CHANGE(IDC_SONGS2, OnChangeSongs2)
  135.     //}}AFX_MSG_MAP
  136.    // Standard printing commands
  137. END_MESSAGE_MAP()
  138.  
  139. /////////////////////////////////////////////////////////////////////////////
  140. // CTapeView message handlers
  141.  
  142. //OnCtlColor.
  143. // This comes right out of the MFC tech notes.  The purpose is to
  144. // set the background color in the form window to gray.
  145. HBRUSH CTapeView::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
  146. {
  147. ASSERT_VALID (this);
  148. ASSERT_VALID (pDC);
  149. // ASSERT_VALID (pWnd);
  150. // That assert will always fail.  It is not a window yet.
  151.  
  152. COLORREF hCtlText = RGB (0, 0, 0);
  153.  
  154. LRESULT lResult;
  155. if (pWnd->SendChildNotifyLastMsg(&lResult))
  156.     return (HBRUSH)lResult;     // eat it
  157.  
  158. if (!GrayCtlColor(pDC->m_hDC, pWnd->GetSafeHwnd(), nCtlColor, m_hCtlBrush, hCtlText))
  159.     return (HBRUSH)Default();
  160. return m_hCtlBrush;
  161. }
  162.  
  163. ///////////////////////////////////////////////////////////////////////////
  164. //EN_CHANGE members.
  165. //
  166. // I am covering these with one block comment.  They all do the same
  167. // thing.  Get the data from the form.  Update all the views.
  168.  
  169. void CTapeView::OnChangeAlbum1()
  170. {
  171. ASSERT_VALID (this);
  172. UpdateData (TRUE);
  173. GetDocument ()->UpdateAllViews (this, ALBUM1_CHANGE, NULL);    
  174. }
  175.  
  176. void CTapeView::OnChangeAlbum2()
  177. {
  178. ASSERT_VALID (this);
  179. UpdateData (TRUE);
  180. GetDocument ()->UpdateAllViews (this, ALBUM2_CHANGE, NULL);    
  181. }
  182.  
  183. void CTapeView::OnChangeArtist1()
  184. {
  185. ASSERT_VALID (this);
  186. UpdateData (TRUE);
  187. GetDocument ()->UpdateAllViews (this, ARTIST1_CHANGE, NULL);    
  188. }
  189.  
  190. void CTapeView::OnChangeArtist2()
  191. {
  192. ASSERT_VALID (this);
  193. UpdateData (TRUE);
  194. GetDocument ()->UpdateAllViews (this, ARTIST2_CHANGE, NULL);    
  195. }
  196.  
  197. void CTapeView::OnChangeNotes()
  198. {
  199. ASSERT_VALID (this);
  200. UpdateData (TRUE);
  201. GetDocument ()->UpdateAllViews (this, NOTES_CHANGE, NULL);    
  202. }
  203.  
  204. void CTapeView::OnChangeSongs1()
  205. {
  206. ASSERT_VALID (this);
  207. UpdateData (TRUE);
  208. GetDocument ()->UpdateAllViews (this, SONGS1_CHANGE, NULL);    
  209. }
  210.  
  211. void CTapeView::OnChangeSongs2()
  212. {
  213. ASSERT_VALID (this);
  214. UpdateData (TRUE);
  215. GetDocument ()->UpdateAllViews (this, SONGS2_CHANGE, NULL);    
  216. }
  217.