home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 23 / IOPROG_23.ISO / SOFT / VFORM.ZIP / Samples / vfTest / pictVf.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-10-10  |  11.5 KB  |  368 lines

  1. // -------------------------------------------------------------------------
  2. // Copyright @ 1997 TCK Software, Incorporated
  3. // All Rights Reserved
  4. // -------------------------------------------------------------------------
  5.  
  6. #include "stdafx.h"
  7. #include "pictVf.h"
  8. #include "resource.h"
  9.  
  10. #ifdef _DEBUG
  11. #define new DEBUG_NEW
  12. #undef THIS_FILE
  13. static char THIS_FILE[] = __FILE__;
  14. #endif
  15.  
  16. #define ANIM_TIMER    101
  17.  
  18. // Static Data Members
  19.  
  20. // -------------------------------------------------------------------------
  21. // CPictHdr Constructor
  22. // -------------------------------------------------------------------------
  23. CPictHdr::CPictHdr(CPictVf* pForm)
  24. {
  25.     Height(35);
  26.  
  27.     m_pictBtn1.Init(this, ID_PVF_PICTBTN1, pForm->GetBtnImgList(), 5,5,24,22);
  28.     m_pictBtn2.Init(this, ID_PVF_PICTBTN2, pForm->GetBtnImgList(), 30,5,24,22);
  29.     m_pictBtn3.Init(this, ID_PVF_PICTBTN3, pForm->GetBtnImgList(), 55,5,24,22);
  30.     m_pictBtn4.Init(this, ID_PVF_PICTBTN4, pForm->GetBtnImgList(), 80,5,24,22);
  31.     m_pictBtn5.Init(this, ID_PVF_PICTBTN5, pForm->GetBtnImgList(), 105,5,24,22);
  32.     m_cycle1.Init(this, ID_PVF_CYCLE1, pForm->GetSwitchImg(), 130,7,22,22);
  33.     m_hdrText.Init(this, -1, _T("Click on the animated Buttons!"), 155,7,200,20);
  34.     m_pictBtn6.Init(this, ID_PVF_PICTBTN6, pForm->GetBtnImgList(), 350,5,24,22);
  35.     m_pictBtn7.Init(this, ID_PVF_PICTBTN7, pForm->GetBtnImgList(), 375,5,24,22);
  36.     m_cycle2.Init(this, ID_PVF_CYCLE2, pForm->GetLightedBtnImg(), 420,2,28,28);
  37.  
  38.     m_anim1.Init(this, ID_PVF_ANIM1, pForm->GetPrintAnimImg(), 550,2,32,32);
  39.     m_anim1.Index(0);                // Default Picture
  40.     m_anim1.AnimIndex(1,6);            // Animation Sequence
  41.     m_anim2.Init(this, ID_PVF_ANIM2, pForm->GetSolodexAnimImg(), 630,2,32,32);
  42.     m_anim2.Index(0);                // Default Picture
  43.     m_anim2.AnimIndex(1,5);            // Animation Sequence
  44.  
  45.     // m_pictCycle1.Init(this, ID_PVF_PICTCYCLE1, pForm->GetCycleImgList(), 410,5,16,16);
  46.     // m_pictCycle1.PictCount(5);
  47.  
  48.  
  49.     m_pictBtn1.UpIdx(0);
  50.     m_pictBtn1.DownIdx(1);
  51.     m_pictBtn2.UpIdx(2);
  52.     m_pictBtn2.DownIdx(3);
  53.     m_pictBtn3.UpIdx(4);
  54.     m_pictBtn3.DownIdx(5);
  55.     m_pictBtn4.UpIdx(6);
  56.     m_pictBtn4.DownIdx(7);
  57.     m_pictBtn5.UpIdx(8);
  58.     m_pictBtn5.DownIdx(9);
  59.     m_pictBtn6.UpIdx(10);
  60.     m_pictBtn6.DownIdx(11);
  61.     m_pictBtn7.UpIdx(12);
  62.     m_pictBtn7.DownIdx(13);
  63.  
  64.  
  65.     AddCtl(&m_pictBtn1);
  66.     AddCtl(&m_pictBtn2);
  67.     AddCtl(&m_pictBtn3);
  68.     AddCtl(&m_pictBtn4);
  69.     AddCtl(&m_pictBtn5);
  70.     AddCtl(&m_cycle1);
  71.     AddCtl(&m_hdrText);
  72.     AddCtl(&m_pictBtn6);
  73.     AddCtl(&m_pictBtn7);
  74.     AddCtl(&m_cycle2);
  75.     AddCtl(&m_anim1);
  76.     AddCtl(&m_anim2);
  77. }
  78.  
  79.  
  80. // -------------------------------------------------------------------------
  81. // CPictRow Constructor
  82. // -------------------------------------------------------------------------
  83. CPictRow::CPictRow()
  84. {
  85.     m_nameLbl.Init(this, -1,  _T("Name"),       10,7,65,20);
  86.     m_name.Init( this, IDPVF_NAME,  _T("xxx"),  75,5,150,20);
  87.     m_phoneLbl.Init(this, -1, _T("Phone"),      10,32,65,20);
  88.     m_phone.Init(this, IDPVF_PHONE, _T("xxx"),  75,30,100,20);
  89.     m_addr1Lbl.Init(this, -1, _T("Address 1"),  10,57,65,20);
  90.     m_addr1.Init(this, IDPVF_ADDR1, _T("xxx"),  75,55,250,20);
  91.     m_addr2Lbl.Init(this, -1, _T("Address 2"),  10,82,65,20);
  92.     m_addr2.Init(this, IDPVF_ADDR2, _T("xxx"),  75,80,250,20);
  93.     m_cityLbl.Init(this, -1,  _T("City"),       10,107,65,20);
  94.     m_city.Init( this, IDPVF_CITY,  _T("xxx"),  75,105,100,20);
  95.     m_stateLbl.Init(this, -1, _T("State"),      180,107,30,20);
  96.     m_state.Init(this, IDPVF_STATE, _T("xxx"),  215,105,30,20);
  97.     m_zipLbl.Init(this, -1,   _T("Zip"),        255,107,25,20);
  98.     m_zip.Init(  this, IDPVF_ZIP,   _T("xxx"),  275,105,50,20);
  99.     m_note.Init( this, IDPVF_NOTE,  _T("xxx"),  340,5,350,150);
  100.  
  101.     m_name.LimitText(45);            // Set max chars for name
  102.     m_phone.Type(TCKEDIT_MASK);
  103.     m_phone.Mask(_T("(###)###-####Z"));    // Set phone mask
  104.     m_zip.Type(TCKEDIT_MASK);
  105.     m_zip.Mask(_T("#####Z"));            // Set zip mask
  106.     m_note.LimitText(5000);            // Set max chars for note
  107.     m_note.MultiLine(TRUE);            // Use a multiline control for the text
  108.  
  109.     AddCtl(&m_nameLbl);
  110.     AddCtl(&m_name);
  111.     AddCtl(&m_phoneLbl);
  112.     AddCtl(&m_phone);
  113.     AddCtl(&m_addr1Lbl);
  114.     AddCtl(&m_addr1);
  115.     AddCtl(&m_addr2Lbl);
  116.     AddCtl(&m_addr2);
  117.     AddCtl(&m_cityLbl);
  118.     AddCtl(&m_city);
  119.     AddCtl(&m_stateLbl);
  120.     AddCtl(&m_state);
  121.     AddCtl(&m_zipLbl);
  122.     AddCtl(&m_zip);
  123.     AddCtl(&m_note);
  124.     SetStyle(VROW_BG_DEFAULT);
  125. }
  126.  
  127. // -------------------------------------------------------------------------
  128. // CPictData Constructor
  129. // -------------------------------------------------------------------------
  130. CPictData::CPictData()
  131. {
  132.     m_name  = _T("Gregory Hanks");
  133.     m_phone = _T("(555)435-6789");
  134.     m_addr1 = _T("200 West Striker Lane");
  135.     m_addr2 = _T("Suite 5040");
  136.     m_city  = _T("Los Angeles");
  137.     m_state = _T("CA");
  138.     m_zip   = _T("60345");
  139.     m_note  = _T("This is a Multi-Line Edit field\r\n\r\n");
  140.     m_note += _T("You may place as many lines of text\r\n");
  141.     m_note += _T("here as you would like.\r\n\r\n");
  142.     m_note += _T("Note that the arrow keys will be used by\r\n");
  143.     m_note += _T("the multi-line edit control while you are in it.\r\n");
  144.     m_note += _T("If you need to leave the edit control - use the tab key\r\n");
  145.     m_note += _T("or click on another control with the mouse.\r\n\r\n");
  146.     m_note += _T("Hopefully, this setup give us the best of both worlds!\r\n");
  147. }
  148.  
  149. // IMPLEMENT_DYNCREATE(CPictVf, VForm)
  150.  
  151. BEGIN_MESSAGE_MAP(CPictVf, VForm)
  152.     //{{AFX_MSG_MAP(CPictVf)
  153.     ON_WM_CREATE()
  154.     //}}AFX_MSG_MAP
  155. END_MESSAGE_MAP()
  156.  
  157. // -------------------------------------------------------------------------
  158. // CPictVf Constructor
  159. // -------------------------------------------------------------------------
  160. CPictVf::CPictVf()
  161. {
  162.     m_pFont = 0;                // use default font
  163.     m_nRowHeight = 160;            // Big row height
  164.     m_nRowWidth = 690;
  165.     m_nRows = 1;                // Just 1 rows
  166.     // AllowAdd(FALSE);
  167.  
  168.     // NOTE - image lists must be created BEFORE they are use (by header)
  169.     if(!m_imgBtnList.Create(IDB_IMG_BTNS, 24, 0, RGB(0,255,255)))
  170.         TRACE(_T("CPictVf could not create image list\n"));
  171.     if(!m_imgCycleList.Create(IDB_IMG_CYCLES, 16, 0, RGB(0,255,255)))
  172.         TRACE(_T("CPictVf could not create cycle image list\n"));
  173.     if(!m_imgPrintAnim.Create(IDB_IMG_BIGPRINT_ANIM, 32, 0, RGB(0,255,255)))
  174.         TRACE(_T("CPictVf could not create print animation image list\n"));
  175.     if(!m_imgSwitch.Create(IDB_IMG_SWITCH, 22, 0, RGB(0,255,255)))
  176.         TRACE(_T("CPictVf could not create switch image list\n"));
  177.     if(!m_imgLightedBtn.Create(IDB_IMG_LIGHTEDBTN, 28, 0, RGB(0,255,255)))
  178.         TRACE(_T("CPictVf could not create lighted button image list\n"));
  179.     if(!m_imgSolodexAnim.Create(IDB_IMG_SOLODEX, 32, 0, RGB(0,255,255)))
  180.         TRACE(_T("CPictVf could not create solodex image list\n"));
  181.  
  182.     
  183.     CPictHdr *pHdr = new CPictHdr(this);
  184.     SetHeader(pHdr, FALSE);
  185.     // SetFooter(pHdr, FALSE);                // lets put the header at the bottom
  186.  
  187.     m_pFont = GetFonts()->GetOrAdd(_T("Arial"), 100);    
  188. }
  189.  
  190. // -------------------------------------------------------------------------
  191. // Function to create a CPictRow
  192. // -------------------------------------------------------------------------
  193. VRow* CPictVf::InitRow()
  194. {
  195.     CPictRow *pRow = new CPictRow();
  196.     return(pRow); 
  197. }
  198.  
  199. // -------------------------------------------------------------------------
  200. // Called when a row needs to be put on the screen
  201. // -------------------------------------------------------------------------
  202. BOOL CPictVf::OnGetRow(VRow *pRow)
  203. {
  204.     CPictRow *r = (CPictRow*) pRow;
  205.     long idx = r->RowId();
  206.     CPictData *pData = &m_data[idx];
  207.  
  208.     r->m_name.Text(pData->m_name);
  209.     r->m_phone.Text(pData->m_phone);
  210.     r->m_addr1.Text(pData->m_addr1);
  211.     r->m_addr2.Text(pData->m_addr2);
  212.     r->m_city.Text(pData->m_city);
  213.     r->m_state.Text(pData->m_state);
  214.     r->m_zip.Text(pData->m_zip);
  215.     r->m_note.Text(pData->m_note);
  216.  
  217.     return TRUE;
  218. }
  219.  
  220. // -------------------------------------------------------------------------
  221. // Called when a row needs to be saved (in the data)
  222. // -------------------------------------------------------------------------
  223. BOOL CPictVf::OnSaveRow(VRow *pRow)
  224. {
  225.     CPictRow *r = (CPictRow*) pRow;
  226.     long idx;
  227.     CPictData *data;
  228.  
  229.     idx = r->RowId();
  230.     data = &m_data[idx];
  231.  
  232.     data->m_name  = r->m_name.Text();
  233.     data->m_phone = r->m_phone.Text();
  234.     data->m_addr1 = r->m_addr1.Text();
  235.     data->m_addr2 = r->m_addr2.Text();
  236.     data->m_city  = r->m_city.Text();
  237.     data->m_state = r->m_state.Text();
  238.     data->m_zip   = r->m_zip.Text();
  239.     data->m_note  = r->m_note.Text();
  240.     
  241.     return TRUE;
  242. }
  243.  
  244. // -------------------------------------------------------------------------
  245. // OnAddRow
  246. // -------------------------------------------------------------------------
  247. BOOL CPictVf::OnAddRow(VRow *pRow)
  248. {
  249.     CPictRow *r = (CPictRow*) pRow;
  250.     long idx;
  251.     CPictData *data;
  252.  
  253.     idx = r->RowId();
  254.     data = &m_data[idx];
  255.  
  256.     data->m_name  = r->m_name.Text();
  257.     data->m_phone = r->m_phone.Text();
  258.     data->m_addr1 = r->m_addr1.Text();
  259.     data->m_addr2 = r->m_addr2.Text();
  260.     data->m_city  = r->m_city.Text();
  261.     data->m_state = r->m_state.Text();
  262.     data->m_zip   = r->m_zip.Text();
  263.     data->m_note  = r->m_note.Text();
  264.     
  265.     return TRUE;
  266. }
  267.  
  268. // -------------------------------------------------------------------------
  269. // OnStartAdd
  270. // -------------------------------------------------------------------------
  271. void CPictVf::OnStartAdd(VRow *pRow)
  272. {
  273.     CPictRow *r = (CPictRow*) pRow;
  274.     long idx = r->RowId();
  275.     CPictData *data = &m_data[idx];
  276.  
  277.     r->m_name.Text(_T(""));
  278.     r->m_phone.Text(_T(""));
  279.     r->m_addr1.Text(_T(""));
  280.     r->m_addr2.Text(_T(""));
  281.     r->m_city.Text(_T(""));
  282.     r->m_state.Text(_T(""));
  283.     r->m_zip.Text(_T(""));
  284.     r->m_note.Text(_T("- New Customer -"));
  285. }
  286.  
  287. // -------------------------------------------------------------------------
  288. // Called when row(s) needs to be deleted from the data
  289. // -------------------------------------------------------------------------
  290. BOOL CPictVf::OnDelete()
  291. {
  292.     CString s1, s2;
  293.     int i;
  294.  
  295.     long nNumSelected = m_selectedList.Count();
  296.     long nRowId = m_selectedList.First();
  297.  
  298.     s1.Format(_T("You have selected to delete %ld rows"), nNumSelected);
  299.     s1 += _T("\n(*delete is not implemented for this screen)");
  300.     for(i=0; i<nNumSelected; i++)
  301.     {
  302.         if(i > 9)
  303.         {
  304.             s1 += _T("\n    too many to list...");
  305.             break;
  306.         }
  307.         s2.Format(_T("\n    %ld"), nRowId);
  308.         s1 += s2;
  309.         nRowId = m_selectedList.Next();
  310.     }
  311.     AfxMessageBox(s1);
  312.  
  313.     return TRUE;
  314. }
  315.  
  316.  
  317. // -------------------------------------------------------------------------
  318. // Called when a button is clicked
  319. // -------------------------------------------------------------------------
  320. void CPictVf::OnClick(VRow *pRow, int nId)
  321. {
  322.     CPictRow *r = (CPictRow*) pRow;
  323.     CPictHdr *pHdr = (CPictHdr *)Header();
  324.  
  325.     switch(nId)
  326.     {
  327.     case ID_PVF_PICTBTN1:
  328.         // AfxMessageBox(this, _T("Got a Click 1"));
  329.         break;
  330.     case ID_PVF_PICTBTN2:
  331.         // AfxMessageBox(this, _T("Got a Click 2"));
  332.         break;
  333.     case ID_PVF_PICTBTN3:
  334.         // AfxMessageBox(this, _T("Got a Click 3"));
  335.         break;
  336.     case ID_PVF_PICTBTN4:
  337.         // AfxMessageBox(this, _T("Got a Click 4"));
  338.         break;
  339.     case ID_PVF_PICTBTN5:
  340.         // AfxMessageBox(this, _T("Got a Click 4"));
  341.         break;
  342.     case ID_PVF_ANIM1:
  343.         pHdr->m_anim1.Animate(2);        // Run animation sequence 2 times
  344.         break;
  345.     case ID_PVF_ANIM2:
  346.         pHdr->m_anim2.Animate(2);        // Run animation sequence 2 times
  347.         break;
  348.     }
  349. }
  350.  
  351. // -------------------------------------------------------------------------
  352. //    Start a timer for the form
  353. // -------------------------------------------------------------------------
  354. int CPictVf::OnCreate(LPCREATESTRUCT lpCreateStruct) 
  355. {
  356.     if (VForm::OnCreate(lpCreateStruct) == -1)
  357.         return -1;
  358.     
  359.     m_nTimerId = SetTimer(ANIM_TIMER, 150, NULL);
  360.     if(m_nTimerId == 0)
  361.     {
  362.         TRACE(_T("CPictVf::OnCreate - Unable to SetTimer\n"));
  363.     }
  364.     
  365.     return 0;
  366. }
  367.  
  368.