home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / C++ / Applications / Lookup 1.0d2 / Sources / CLookupWindow.cp < prev    next >
Encoding:
Text File  |  1995-09-12  |  2.8 KB  |  135 lines  |  [TEXT/CWIE]

  1. /*
  2.     CLookupWindow.cp
  3.     
  4.     Copyright © 1995 Alastair Rankine.
  5.     All Rights Reserved.
  6. */
  7.  
  8. #include "CLookupWindow.h"
  9. #include "ResourceIDs.h"
  10. #include "MessageIDs.h"
  11. #include "CAddEntryAction.h"
  12. #include "CChangeEntryAction.h"
  13. #include "CEntryList.h"
  14. #include "CEntry.h"
  15.  
  16. void CLookupWindow::Register()
  17. {
  18.     URegistrar::RegisterClass(kClassID, (ClassCreatorFunc)CreateFromStream);
  19. }
  20.  
  21. CLookupWindow::CLookupWindow(LStream *inStream)
  22.     : LWindow(inStream)
  23.     , mDocument(nil)
  24.     , mField1(nil)
  25.     , mField2(nil)
  26.     , mField3(nil)
  27.     , mField4(nil)
  28.     , mList(nil)
  29. {
  30. }
  31. void CLookupWindow::FinishCreateSelf()// Override
  32. {
  33.     LPane::FinishCreateSelf();
  34.     
  35.     mDocument = (CLookupDocument *)mSuperCommander;
  36.     Assert_(mDocument);
  37.     
  38.     mField1 = (LEditField *)FindPaneByID(kField1ID);
  39.     Assert_(mField1);
  40.     
  41.     mField2 = (LEditField *)FindPaneByID(kField2ID);
  42.     Assert_(mField2);
  43.     
  44.     mField3 = (LEditField *)FindPaneByID(kField3ID);
  45.     Assert_(mField3);
  46.     
  47.     mField4 = (LEditField *)FindPaneByID(kField4ID);
  48.     Assert_(mField4);
  49.     
  50.     LControl * addButton = (LControl *)FindPaneByID(kNewButtonID);
  51.     Assert_(addButton);
  52.     addButton->AddListener(this);
  53.     
  54.     mChangeButton = (LControl *)FindPaneByID(kChangeButtonID);
  55.     Assert_(mChangeButton);
  56.     mChangeButton->AddListener(this);
  57.  
  58.     mList = (CEntryList *)FindPaneByID(kListID);
  59.     Assert_(mList);
  60.     mList->AddListener(this);
  61.     mList->SetLookupDocument(mDocument);
  62.  
  63.     SetLatentSub(mList);
  64. }
  65.  
  66. void CLookupWindow::ListenToMessage(MessageT inMessage, void * inParam)
  67. {
  68.     switch(inMessage)
  69.     {
  70.         case msg_AddButton:
  71.         {
  72.             CEntry data;
  73.             
  74.             GetFieldData(data);
  75.             Assert_(mDocument);
  76.             PostAction(new CAddEntryAction(*mDocument, data));
  77.             break;
  78.         }
  79.         case msg_ChangeButton:
  80.         {
  81.             CEntry data;
  82.             
  83.             GetFieldData(data);
  84.             Assert_(mDocument);
  85.             Assert_(mList);
  86.             PostAction(new CChangeEntryAction(*mDocument, mList->GetSelection(), data));
  87.             break;
  88.         }
  89.         case msg_CellSelected:
  90.         {
  91.             Assert_(mDocument);
  92.             const CEntry ** theEntry = (const CEntry **)inParam;
  93.             Assert_(theEntry);
  94.             SetFieldData(*theEntry? **theEntry : sEmptyEntry);
  95.  
  96.             mChangeButton->Enable();
  97.             break;
  98.         }
  99.         case msg_CellDeselected:
  100.         {
  101.             SetFieldData(sEmptyEntry);
  102.  
  103.             mChangeButton->Disable();
  104.             break;
  105.         }
  106.         default:
  107.             break;
  108.     }
  109. }
  110. void CLookupWindow::SetFieldData(const CEntry & record)
  111. {
  112.     mField1->SetDescriptor(record.GetField(0).ToPString());
  113.     mField2->SetDescriptor(record.GetField(1).ToPString());
  114.     mField3->SetDescriptor(record.GetField(2).ToPString());
  115.     mField4->SetDescriptor(record.GetField(3).ToPString());
  116. }
  117.  
  118. void CLookupWindow::GetFieldData(CEntry & rec)
  119. {
  120.     Str255 buf;
  121.     
  122.     rec.SetField(0, mField1->GetDescriptor(buf));
  123.     rec.SetField(1, mField2->GetDescriptor(buf));
  124.     rec.SetField(2, mField3->GetDescriptor(buf));
  125.     rec.SetField(3, mField4->GetDescriptor(buf));
  126. }
  127.  
  128.  
  129. CLookupWindow * CLookupWindow::CreateFromStream(LStream *inStream)
  130. {
  131.     return new CLookupWindow(inStream);
  132. }
  133.  
  134.  
  135.