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

  1. // -------------------------------------------------------------------------
  2. // Copyright @ 1997 TCK Software, Incorporated
  3. // All Rights Reserved
  4. // -------------------------------------------------------------------------
  5.  
  6. #include "stdafx.h"
  7. #include "testVF.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. // CTestHdr Constructor
  22. // -------------------------------------------------------------------------
  23. CTestHdr::CTestHdr()
  24. {
  25.     Height(40);
  26.  
  27.     m_chkSelectors.Init(this, IDVC_CHK_SELECTORS, _T("Selectors"), 5,5,80,20);
  28.     m_lblBackGround.Init(this, -1, _T("Background:"), 100,7,83,20);
  29.     m_lstBgOption.Init(this, IDVC_BG_OPTION, _T("Normal"), 185,5,90,20);
  30.     m_btnSetBmp.Init(this, IDVC_SET_BMP, _T("Set Bmp"), 290,5,80,20);
  31.     m_nBackStyle = 0;
  32.     m_chkSelectors.Checked(TRUE);
  33.  
  34.     m_lstBgOption.AddString(_T("Normal"));
  35.     m_lstBgOption.AddString(_T("Green Bar"));
  36.     m_lstBgOption.AddString(_T("Paper Pad"));
  37.     m_lstBgOption.AddString(_T("Flat Look"));
  38.     m_lstBgOption.AddString(_T("Bitmap"));
  39.  
  40.     AddCtl(&m_chkSelectors);
  41.     AddCtl(&m_lblBackGround);
  42.     AddCtl(&m_lstBgOption);
  43.     AddCtl(&m_btnSetBmp);
  44. }
  45.  
  46. // -------------------------------------------------------------------------
  47. // CTestFtr Constructor
  48. // -------------------------------------------------------------------------
  49. CTestFtr::CTestFtr()
  50. {
  51.     Height(35);
  52.  
  53.     m_lblGoodbye.Init(this, -1, _T("Footer:"), 80,5,60,20);
  54.     m_ftrEdit.Init(this, IDVC_FTREDIT, _T("Goodbye"), 150,5,100,20);
  55.  
  56.     m_ftrEdit.LimitText(20);                    // Set max chars for m_ftrEdit
  57.  
  58.     AddCtl(&m_lblGoodbye);
  59.     AddCtl(&m_ftrEdit);
  60. }
  61.  
  62.  
  63. // -------------------------------------------------------------------------
  64. // CTestRow Constructor
  65. // -------------------------------------------------------------------------
  66. CTestRow::CTestRow(CTestVF* pForm)
  67. {
  68.     m_lblSRow.Init(this, IDVC_LBLSROW, _T("lblSrow"), 10,5,60,20);
  69.     m_testval.Init(this, IDVC_TESTVAL, _T("Hello"), 80,5,100,20);
  70.     m_lstOption.Init(this, IDVC_OPTION, _T(""), 200,5,75,20);
  71.     m_btn1.Init(this, IDVC_BTN1, _T("Push"), 280,5,60,20);
  72.     m_check1.Init(this, IDVC_CHECK1, _T(""), 350,5,15,15);
  73.     m_anim1.Init(this, IDVC_ANIM1, pForm->GetPrintAnimImg(), 380,5,16,16);
  74.     m_anim1.Index(0);                // Default Picture
  75.     m_anim1.AnimIndex(1,6);            // Animation Sequence
  76.     // m_pictBtn1.Init(this, IDVC_PICTBTN1, pForm->GetTestImgList(), 430,5,16,16);
  77.     // m_pictBtn1.DownIdx(1);
  78.     m_pictCycle1.Init(this, IDVC_PICTCYCLE1, pForm->GetCycleImgList(), 410,5,16,16);
  79.     m_pictCycle1.PictCount(5);
  80.  
  81.     m_testval.LimitText(25);                // Set max chars for m_testval
  82.     // m_testval.Set3D(FALSE);                    // Turn 3d off
  83.     // m_testval.SetBorder(FALSE);                // Turn Border off
  84.     // m_check1.Set3D(FALSE);                    // Turn 3d off
  85.  
  86.     m_lstOption.AddString(_T("Option 1"));
  87.     m_lstOption.AddString(_T("Option 2"));
  88.     m_lstOption.AddString(_T("Option 3"));
  89.     m_lstOption.AddString(_T("Option 4"));
  90.     m_lstOption.AddString(_T("Option 5"));
  91.     m_lstOption.AddString(_T("Option 6"));
  92.  
  93.     AddCtl(&m_lblSRow);
  94.     AddCtl(&m_testval);
  95.     AddCtl(&m_lstOption);
  96.     AddCtl(&m_btn1);
  97.     AddCtl(&m_check1);
  98.     AddCtl(&m_anim1);
  99.     // AddCtl(&m_pictBtn1);
  100.     AddCtl(&m_pictCycle1);
  101.  
  102.     m_nBackStyle = 0;
  103.     m_nSRowId = 0;
  104. }
  105.  
  106. // -------------------------------------------------------------------------
  107. // GetBackBmp
  108. // -------------------------------------------------------------------------
  109. HBITMAP CTestRow::GetBackBmp()
  110. {
  111.     return ((CTestVF*)Form())->GetBackBmp(); 
  112. }
  113.  
  114. // -------------------------------------------------------------------------
  115. // GetBackPalette
  116. // -------------------------------------------------------------------------
  117. HPALETTE CTestRow::GetBackPaletteHandle()
  118. {
  119.     return ((CTestVF*)Form())->GetBackPalette(); 
  120. }
  121.  
  122.  
  123. // -------------------------------------------------------------------------
  124. // CTestRow Destructor
  125. // -------------------------------------------------------------------------
  126. CTestRow::~CTestRow()
  127. {
  128. }
  129.  
  130.  
  131. // -------------------------------------------------------------------------
  132. // CPersonRow Background Drawing
  133. // -------------------------------------------------------------------------
  134. void CTestRow::SetBG(int nBackStyle)
  135. {
  136.     SetStyle(nBackStyle);
  137.  
  138.     COLORREF clr = RGB(255,255,255);
  139.     BOOL bTransparent = FALSE;
  140.     BOOL bNoInactBorder = FALSE;
  141.  
  142.     if(nBackStyle == VROW_BG_FLAT)    clr = RGB(192,192,192);
  143.  
  144.     ResetCtl(m_testval,   bTransparent, bNoInactBorder, clr);
  145.     ResetCtl(m_lstOption, bTransparent, bNoInactBorder, clr);
  146. }
  147.  
  148.  
  149. // IMPLEMENT_DYNCREATE(CTestVF, VForm)
  150.  
  151. BEGIN_MESSAGE_MAP(CTestVF, VForm)
  152.     //{{AFX_MSG_MAP(CTestVF)
  153.     ON_WM_CREATE()
  154.     //}}AFX_MSG_MAP
  155. END_MESSAGE_MAP()
  156.  
  157. // -------------------------------------------------------------------------
  158. // CTestVF Constructor
  159. // -------------------------------------------------------------------------
  160. CTestVF::CTestVF()
  161. {
  162.     m_pFont = 0;                // use default font
  163.     m_pPalMH = 0;
  164.     m_nBackIdx = 0;
  165.     m_nRowHeight = 28;
  166.     m_nRowWidth = 430;
  167.     m_nRows = 400;                // Start at 400
  168.     m_nSRows = 0;
  169.     
  170.     // ------------- Header and footer with Something in them --------
  171.     CTestHdr *pHdr = new CTestHdr();
  172.     SetHeader(pHdr, FALSE);
  173.     CTestFtr *pFtr = new CTestFtr();
  174.     SetFooter(pFtr, FALSE);
  175.  
  176.     m_pFont = GetFonts()->GetOrAdd(_T("Arial"), 100);    
  177.  
  178.     if(!m_imgList.Create(IDB_IMG_TEST, 16, 0, RGB(0,255,255)))
  179.         TRACE(_T("CTestVF could not create image list\n"));
  180.     // m_imgList.SetBkColor(GetSysColor(COLOR_WINDOW));
  181.     if(!m_imgCycleList.Create(IDB_IMG_CYCLES, 16, 0, RGB(0,255,255)))
  182.         TRACE(_T("CTestVF could not create cycle image list\n"));
  183.     if(!m_imgPrintAnim.Create(IDB_IMG_PRINT_ANIM, 16, 0, RGB(0,255,255)))
  184.         TRACE(_T("CTestVF could not create print animation image list\n"));
  185. }
  186.  
  187. // -------------------------------------------------------------------------
  188. // CTestVF Destructor
  189. // -------------------------------------------------------------------------
  190. CTestVF::~CTestVF()
  191. {
  192.     // if(m_hBmpBack)    ::DeleteObject(m_hBmpBack);
  193. }
  194.  
  195. BOOL CTestVF::SetBackBmp(LPCTSTR szFile)
  196. {
  197.     BOOL bRet;
  198.  
  199.     m_bmpBack.DeleteObject();                // remove old
  200.     bRet = m_bmpBack.LoadFile(szFile);        // load new
  201.     // m_pWnd->ResetPalette();
  202.     if(m_pPalMH)
  203.         m_pPalMH->DoRealizePalette(TRUE);
  204.  
  205.     return bRet;
  206. /* 
  207.     LPVOID lpMsgBuf;
  208.     DWORD  dwError;
  209.     CString s1;
  210.     HBITMAP hBitmap=0;
  211.  
  212.     hBitmap = (HBITMAP)LoadImage(0, szFile, IMAGE_BITMAP, 
  213.         0, 0, LR_LOADFROMFILE | LR_CREATEDIBSECTION | LR_DEFAULTSIZE);
  214.  
  215.     if(!hBitmap)
  216.     {
  217.         dwError = GetLastError();
  218.  
  219.         ::FormatMessage( 
  220.             FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
  221.             NULL, dwError,
  222.             MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
  223.             (LPTSTR) &lpMsgBuf,    0, NULL);
  224.     
  225.         s1.Format(_T("Error loading bitmap:\n<%s>\n%s"), szFile, (LPTSTR)lpMsgBuf);
  226.         LocalFree( lpMsgBuf );
  227.  
  228.         MessageBox(s1,_T("VForm Demo"), MB_OK | MB_ICONEXCLAMATION);
  229.         return FALSE;
  230.     }
  231.  
  232.     if(m_hBmpBack)    ::DeleteObject(m_hBmpBack);    
  233.     m_hBmpBack = hBitmap;
  234.  
  235.     return TRUE;
  236. */
  237. }
  238.  
  239.  
  240. // -------------------------------------------------------------------------
  241. // Function to create a CTestRow
  242. // -------------------------------------------------------------------------
  243. VRow* CTestVF::InitRow()
  244. {
  245.     CTestRow *pRow = new CTestRow(this);
  246.     m_nSRows++;                        // One More Screen Row
  247.     pRow->SRowId(m_nSRows);
  248.     return(pRow); 
  249. }
  250.  
  251. // -------------------------------------------------------------------------
  252. // Called when a row needs to be put on the screen
  253. // -------------------------------------------------------------------------
  254. BOOL CTestVF::OnGetRow(VRow *pRow)
  255. {
  256.     CString s1;
  257.     CTestRow *r = (CTestRow*) pRow;
  258.     long idx;
  259.     CTestData *data;
  260.  
  261.     idx = r->RowId();
  262.     data = &m_data[idx];
  263.  
  264.     // if(idx > 100 && idx < 200)
  265.     //     r->m_testval.Visible(FALSE);
  266.     // else
  267.     //     r->m_testval.Visible(TRUE);
  268.  
  269.     // s1.Format(_T("%ld:%d"), r->RowId(), r->SRowId());
  270.     s1.Format(_T("%ld"), r->RowId());
  271.     r->m_lblSRow.SetWindowText(s1);
  272.  
  273.     r->m_testval.SetWindowText(data->m_name);
  274.     r->m_lstOption.SetWindowText(data->m_option);
  275.     r->m_check1.Checked(data->m_bCheck);
  276.     r->m_pictCycle1.Index(data->m_nCycleOpt);
  277.  
  278.     return TRUE;
  279. }
  280.  
  281. // -------------------------------------------------------------------------
  282. // Called when a row needs to be saved (in the data)
  283. // -------------------------------------------------------------------------
  284. BOOL CTestVF::OnSaveRow(VRow *pRow)
  285. {
  286.     CTestRow *r = (CTestRow*) pRow;
  287.     long idx;
  288.     CTestData *data;
  289.  
  290.     idx = r->RowId();
  291.     data = &m_data[idx];
  292.  
  293.     data->m_name = r->m_testval.Text();
  294.     data->m_bCheck = r->m_check1.Checked();
  295.     data->m_option = r->m_lstOption.Text();
  296.     data->m_nCycleOpt = r->m_pictCycle1.Index();
  297.  
  298.     return TRUE;
  299. }
  300.  
  301. // -------------------------------------------------------------------------
  302. // Called when row(s) needs to be deleted from the data
  303. // -------------------------------------------------------------------------
  304. BOOL CTestVF::OnDelete()
  305. {
  306.     CString s1, s2;
  307.     int i;
  308.     // CTestRow *r = (CTestRow*) pRow;
  309.  
  310.     long nNumSelected = m_selectedList.Count();
  311.     long nRowId = m_selectedList.First();
  312.  
  313.     s1.Format(_T("You have selected to delete %ld rows"), nNumSelected);
  314.     for(i=0; i<nNumSelected; i++)
  315.     {
  316.         if(i > 9)
  317.         {
  318.             s1 += _T("\n    too many to list...");
  319.             break;
  320.         }
  321.         s2.Format(_T("\n    %ld"), nRowId);
  322.         s1 += s2;
  323.         nRowId = m_selectedList.Next();
  324.     }
  325.     MessageBox(s1, _T("VForm Demo"));
  326.  
  327.     return TRUE;
  328. }
  329.  
  330. // -------------------------------------------------------------------------
  331. // Called when a row needs to be added to the data
  332. // -------------------------------------------------------------------------
  333. BOOL CTestVF::OnAddRow(VRow *pRow)
  334. {
  335.     CTestRow *r = (CTestRow*) pRow;
  336.     CString s1;
  337.  
  338.     long idx = r->RowId();
  339.     CTestData *data = &m_data[idx];
  340.  
  341.     data->m_name = r->m_testval.Text();
  342.     data->m_bCheck = r->m_check1.Checked();
  343.     data->m_option = r->m_lstOption.Text();
  344.  
  345.     s1.Format(_T("Successfully added record %ld"), idx);
  346.     MessageBox(s1, _T("Wow"));
  347.  
  348.     return TRUE;
  349. }
  350.  
  351. // -------------------------------------------------------------------------
  352. // Called when a row is initially being added
  353. // -------------------------------------------------------------------------
  354. void CTestVF::OnStartAdd(VRow *pRow)
  355. {
  356.     CString s1;
  357.     CTestRow *r = (CTestRow*) pRow;
  358.     long idx = r->RowId();
  359.     CTestData *data = &m_data[idx];
  360.  
  361.     s1.Format(_T("%ld:%d"), r->RowId(), r->SRowId());
  362.     r->m_lblSRow.SetWindowText(s1);
  363.  
  364.     r->m_testval.SetWindowText(_T("New Record"));
  365.     r->m_lstOption.SetWindowText(_T(""));
  366.     r->m_check1.Checked(TRUE);
  367.     r->m_pictCycle1.Index(0);
  368.  
  369.     // DrawRow(pRow, FALSE);
  370. }
  371.  
  372.  
  373. // -------------------------------------------------------------------------
  374. // Called when a button is clicked
  375. // -------------------------------------------------------------------------
  376. void CTestVF::OnClick(VRow *pRow, int nId)
  377. {
  378.     CString s1, sBmpFile;
  379.     CTestRow *r = (CTestRow*) pRow;
  380.     static _TCHAR szFilter[] = _T("Bitmaps (*.bmp)|*.bmp|All Files (*.*)|*.*||"); 
  381.  
  382.     switch(nId)
  383.     {
  384.     case IDVC_CHK_SELECTORS:
  385.         {
  386.             CTestHdr *pHdr = (CTestHdr *)Header();
  387.             if(pHdr->m_chkSelectors.Checked())
  388.                 UseSelectors(TRUE);
  389.             else
  390.                 UseSelectors(FALSE);
  391.             break;
  392.         }
  393.     case IDVC_BTN1:
  394.         s1.Format(_T("Row %ld"), pRow->RowId());
  395.         MessageBox(_T("You Clicked Me!"), s1, MB_OK);
  396.         break;
  397.     case IDVC_ANIM1:
  398.         // s1.Format(_T("Row %ld"), pRow->RowId());
  399.         // MessageBox(_T("You Clicked the Printer!"), s1, MB_OK);
  400.         r->m_anim1.Animate(2);        // Run animation sequence 2 times
  401.         break;
  402.     case IDVC_SET_BMP:
  403.         {
  404.             CFileDialog dlg(TRUE, _T("bmp"), sBmpFile, 
  405.                 OFN_SHAREAWARE | OFN_PATHMUSTEXIST, szFilter); 
  406.             if(dlg.DoModal() != IDOK)
  407.                 break;
  408.  
  409.             sBmpFile = dlg.GetPathName();
  410.             if(SetBackBmp(sBmpFile) && m_nBackIdx == 4)
  411.             {
  412.                 RefreshScreen(VFR_BOTH);
  413.             }
  414.             break;
  415.         }
  416.     }
  417. }
  418.  
  419.  
  420. // -------------------------------------------------------------------------
  421. // Called when list is closed is clicked
  422. // -------------------------------------------------------------------------
  423. BOOL CTestVF::OnEndList(VCtl* pCtl, CListBox* pLB)
  424. {
  425.     int nBgStyle=0;
  426.     CTestRow *pRow;
  427.     CTestHdr *pHdr;
  428.  
  429.     switch(pCtl->Id())
  430.     {
  431.     case IDVC_OPTION:
  432.         break;
  433.     case IDVC_BG_OPTION:
  434.         m_nBackIdx = pLB->GetCurSel();
  435.  
  436.         switch(m_nBackIdx)
  437.         {
  438.         case 0:    nBgStyle = VROW_BG_DEFAULT;        break;
  439.         case 1:    nBgStyle = VROW_BG_GREENBAR;    break;
  440.         case 2:    nBgStyle = VROW_BG_PAPER;        break;
  441.         case 3:    nBgStyle = VROW_BG_FLAT;        break;
  442.         case 4:    nBgStyle = VROW_BG_BMP;            break;
  443.         }
  444.  
  445.         // Reset detail rows to this style
  446.         pHdr = (CTestHdr *)Header();
  447.         pHdr->SetStyle(nBgStyle);
  448.  
  449.         pRow = (CTestRow *)m_pDtlRow;
  450.         pRow->SetBG(nBgStyle);
  451.         pRow = (CTestRow *)m_pTmpRow;
  452.         pRow->SetBG(nBgStyle);
  453.  
  454.         RefreshScreen(VFR_BOTH);
  455.         break;
  456.     }
  457.     return TRUE;
  458. }
  459.  
  460.  
  461.  
  462. // -------------------------------------------------------------------------
  463. //    Start a timer for the form
  464. // -------------------------------------------------------------------------
  465. int CTestVF::OnCreate(LPCREATESTRUCT lpCreateStruct) 
  466. {
  467.     if (VForm::OnCreate(lpCreateStruct) == -1)
  468.         return -1;
  469.     
  470.     m_nTimerId = SetTimer(ANIM_TIMER, 300, NULL);
  471.     if(m_nTimerId == 0)
  472.     {
  473.         TRACE(_T("CTestVF::OnCreate - Unable to SetTimer\n"));
  474.     }
  475.     
  476.     return 0;
  477. }
  478.  
  479.