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

  1. // -------------------------------------------------------------------------
  2. // Copyright @ 1997 TCK Software, Incorporated
  3. // All Rights Reserved
  4. // -------------------------------------------------------------------------
  5.  
  6. #include "stdafx.h"
  7. #include "personVF.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    102
  17.  
  18.  
  19. // Static Data Members
  20.  
  21. // -------------------------------------------------------------------------
  22. // CPersonHdr Constructor
  23. // -------------------------------------------------------------------------
  24. CPersonRptHdr::CPersonRptHdr()
  25. {
  26.     Height(40);
  27.     m_rptHeading.Init(this, -1, _T("Customer Report"), 20,5,300,33);
  28.     m_line.Init(this, -1, 10,37,800,3);
  29.  
  30.     CFont *pFont = VForm::GetFonts()->GetOrAdd(_T("Arial"), 200);
  31.     m_rptHeading.Font(pFont);
  32.     
  33.     AddCtl(&m_rptHeading);
  34.     AddCtl(&m_line);
  35. }
  36.  
  37. // -------------------------------------------------------------------------
  38. // CPersonFtr Constructor
  39. // -------------------------------------------------------------------------
  40. CPersonRptFtr::CPersonRptFtr()
  41. {
  42.     Height(40);
  43.     m_line.Init(this, -1, 10,2,800,3);
  44.     m_rptFooter.Init(this, -1, _T("--- Report Footer ---"), 20,5,300,35);
  45.     m_rptPageNo.Init(this, -1, _T(""), 700,5,100,100);
  46.  
  47.     CFont *pFont = VForm::GetFonts()->GetOrAdd(_T("Arial"), 160);
  48.     m_rptFooter.Font(pFont);
  49.     m_rptPageNo.Name(_T("PAGENO"));            // Use the Special Name
  50.  
  51.     AddCtl(&m_line);
  52.     AddCtl(&m_rptFooter);
  53.     AddCtl(&m_rptPageNo);
  54. }
  55.  
  56.  
  57. // -------------------------------------------------------------------------
  58. // CPersonRptDtl Constructor
  59. // -------------------------------------------------------------------------
  60. CPersonRptDtl::CPersonRptDtl()
  61. {
  62.     m_name.Init(this, IDVC_NAME,       _T(""), 20,3,150,20);
  63.     m_phone.Init(this, IDVC_PHONE,     _T(""), 180,3,120,20);
  64.     // m_address.Init(this, IDVC_ADDRESS, _T(""), 250,3,250,20);
  65.     // m_city.Init(this, IDVC_CITY,       _T(""), 250,25,150,20);
  66.     // m_state.Init(this, IDVC_STATE,     _T(""), 410,25,30,20);
  67.     // m_zip.Init(this, IDVC_ZIP,         _T(""), 450,25,80,20);
  68.     m_chkFriend.Init(this, IDVC_FRIENDCHECK, _T(""), 300,3,20,20);
  69.  
  70.     AddCtl(&m_name);
  71.     AddCtl(&m_phone);
  72.     // AddCtl(&m_address);
  73.     // AddCtl(&m_city);
  74.     // AddCtl(&m_state);
  75.     // AddCtl(&m_zip);
  76.     AddCtl(&m_chkFriend);
  77. }
  78.  
  79.  
  80.  
  81. // -------------------------------------------------------------------------
  82. // CPersonHdr Constructor
  83. // -------------------------------------------------------------------------
  84. CPersonHdr::CPersonHdr()
  85. {
  86.     Height(40);
  87.     m_chkSelectors.Init(this, IDVC_CHK_SELECTORS, _T("Selectors"), 5,5,80,20);
  88.     m_lblBackGround.Init(this, -1, _T("Background:"), 100,7,83,20);
  89.     m_lstBgOption.Init(this, IDVC_BG_OPTION, _T("Bitmap"), 180,5,90,20);
  90.     m_btnSetBmp.Init(this, IDVC_SET_BMP, _T("Set Bmp"), 280,5,70,20);
  91.     m_chkShadow.Init(this, IDVC_CHK_SHADOW, _T("Shadow"), 365,5,70,20);
  92.     m_lstBoxStyle.Init(this, IDVC_BOX_STYLE, _T("Normal"), 365,5,70,20);
  93.     m_rdoInactBorder.Init(this, IDVC_RDO_INACTBORDER, _T(""), 445,2,145,38);
  94.     m_chkTransparent.Init(this, IDVC_CHK_TRANSPARENT, _T("Transparent"), 590,5,90,20);
  95.     m_nBackStyle = 0;
  96.     m_chkSelectors.Checked(TRUE);
  97.     m_chkShadow.Checked(TRUE);
  98.     m_chkTransparent.Checked(TRUE);
  99.     m_rdoInactBorder.AddString(_T("Inactive Border On"));
  100.     m_rdoInactBorder.AddString(_T("Inactive Border Off"));
  101.  
  102.     m_lstBgOption.AddString(_T("Normal"));
  103.     m_lstBgOption.AddString(_T("Green Bar"));
  104.     m_lstBgOption.AddString(_T("Paper Pad"));
  105.     m_lstBgOption.AddString(_T("Flat Look"));
  106.     m_lstBgOption.AddString(_T("Bitmap"));
  107.  
  108.     m_lstBoxStyle.AddString(_T("Normal"));
  109.     m_lstBoxStyle.AddString(_T("Shadow"));
  110.     m_lstBoxStyle.AddString(_T("Indented"));
  111.     m_lstBoxStyle.AddString(_T("Bumped"));
  112.  
  113.     // A few special attribute examples
  114.     // m_chkSelectors.Disable();
  115.     // m_lstBgOption.Disable();
  116.     // m_btnSetBmp.Disable();
  117.     
  118.     AddCtl(&m_chkSelectors);
  119.     AddCtl(&m_lblBackGround);
  120.     AddCtl(&m_lstBgOption);
  121.     AddCtl(&m_btnSetBmp);
  122.     AddCtl(&m_lstBoxStyle);
  123.     AddCtl(&m_rdoInactBorder);
  124.     AddCtl(&m_chkTransparent);
  125. }
  126.  
  127. // -------------------------------------------------------------------------
  128. // CPersonFtr Constructor
  129. // -------------------------------------------------------------------------
  130. CPersonFtr::CPersonFtr()
  131. {
  132.     Height(40);
  133.     m_chkGridMode.Init(this, IDVC_CHK_GRID_MODE, _T("Grid Mode"), 5,5,80,20);
  134.     m_lblGridStyle.Init(this, -1, _T("Grid Style"), 100,7,60,20);
  135.     m_lstGridStyle.Init(this, IDVC_LST_GRID_STYLE, _T("Flat"), 160,5,90,20);
  136.     m_chkLiveResizing.Init(this, IDVC_CHK_LIVE_RESIZING, _T("Live Resizing"), 270,5,100,20);
  137.     m_chkSnapResize.Init(this, IDVC_CHK_SNAP_RESIZE, _T("Snap Resize"), 380,5,100,20);
  138.     m_chkGridMode.Checked(TRUE);
  139.     m_chkLiveResizing.Checked(TRUE);
  140.     m_chkSnapResize.Checked(FALSE);
  141.  
  142.     m_lstGridStyle.AddString(_T("Flat"));
  143.     m_lstGridStyle.AddString(_T("No Lines"));
  144.     m_lstGridStyle.AddString(_T("Sunken"));
  145.     m_lstGridStyle.AddString(_T("Raised"));
  146.     m_lstGridStyle.AddString(_T("Vert Lines"));
  147.     m_lstGridStyle.AddString(_T("Horz Lines"));
  148.     m_lstGridStyle.AddString(_T("Alternating"));
  149.  
  150.     AddCtl(&m_chkGridMode);
  151.     AddCtl(&m_lblGridStyle);
  152.     AddCtl(&m_lstGridStyle);
  153.     AddCtl(&m_chkLiveResizing);
  154.     // AddCtl(&m_chkSnapResize);
  155. }
  156.  
  157.  
  158. // -------------------------------------------------------------------------
  159. // CPersonRow Constructor
  160. // -------------------------------------------------------------------------
  161. CPersonRow::CPersonRow(CPersonVF* pForm)
  162. {
  163.     m_recno.Init(this,   IDVC_RECNO,      _T(""), 50,5,30,20);
  164.     m_name.Init(this,    IDVC_NAME,       _T(""), 90,3,100,20);
  165.     m_phone.Init(this,   IDVC_PHONE,      _T(""), 90,25,90,20);
  166.     m_address.Init(this, IDVC_ADDRESS,    _T(""), 250,3,250,20);
  167.     m_city.Init(this,    IDVC_CITY,       _T(""), 250,25,150,20);
  168.     m_state.Init(this,   IDVC_STATE,      _T(""), 410,25,30,20);
  169.     m_zip.Init(this,     IDVC_ZIP,        _T(""), 450,25,80,20);
  170.     m_chkFriend.Init(this, IDVC_FRIENDCHECK, _T("Friend"), 535,5,60,20);
  171.     m_btnTest.Init(this, IDVC_TESTBUTTON, _T("Click"), 535,25,50,20);
  172.  
  173.     SetTransparent(TRUE);
  174.  
  175.     // ------ Set Grid Captions --------
  176.     m_name.GridCaption(_T("Name"));
  177.     m_phone.GridCaption(_T("Phone"));
  178.     m_address.GridCaption(_T("Address"));
  179.     m_city.GridCaption(_T("City"));
  180.     m_state.GridCaption(_T("State"));
  181.     m_zip.GridCaption(_T("Zip"));
  182.     m_chkFriend.GridCaption(_T("Friend"));
  183.     m_btnTest.GridCaption(_T(""));
  184.     m_btnTest.UseInGrid(TRUE);
  185.  
  186.     // ------ Set Control Names (so we can remember settings) --------
  187.     m_name.Name(_T("Name"));
  188.     m_phone.Name(_T("Phone"));
  189.     m_address.Name(_T("Address"));
  190.     m_city.Name(_T("City"));
  191.     m_state.Name(_T("State"));
  192.     m_zip.Name(_T("Zip"));
  193.     m_chkFriend.Name(_T("Friend"));
  194.     m_btnTest.Name(_T("ButtonTest"));
  195.  
  196.     m_name.LimitText(PERS_NAME);
  197.     m_address.LimitText(PERS_ADDR);
  198.     m_city.LimitText(PERS_CITY);
  199.     m_state.LimitText(PERS_STATE);
  200.     m_zip.LimitText(PERS_ZIP);
  201.     m_phone.LimitText(PERS_PHONE);
  202.     m_phone.Type(TCKEDIT_MASK);
  203.     m_phone.Mask(_T("(###)###-####Z"));
  204.     // m_phone.SaveMaskChars(FALSE);
  205.     m_phone.ForeColor(RGB(255,0,0));
  206.     // m_phone.AutoTab(TRUE);            // Auto tab when full
  207.     // m_phone.PromptInclude(FALSE);    // If you dont want the mask chars
  208.  
  209.     // A few special attribute examples
  210.     // m_name.MultiLine(TRUE);
  211.     // m_city.Disable();
  212.     SetIconPosition(5, 0);
  213.  
  214.     AddCtl(&m_recno);
  215.     AddCtl(&m_name);
  216.     AddCtl(&m_phone);
  217.     AddCtl(&m_address);
  218.     AddCtl(&m_city);
  219.     AddCtl(&m_state);
  220.     AddCtl(&m_zip);
  221.     AddCtl(&m_chkFriend);
  222.     AddCtl(&m_btnTest);
  223.  
  224.     SetForm(pForm);                // We need the form set BEFORE calling SetBG
  225.     SetEffect(VEFFECT_NORMAL);
  226.     SetNoInactBorder(FALSE);    // Initially use inactive borders
  227.     SetBG(VROW_BG_BMP);            // Initially use the Bitmap Background
  228. }
  229.  
  230. // -------------------------------------------------------------------------
  231. // GetBackBmp
  232. // -------------------------------------------------------------------------
  233. HBITMAP CPersonRow::GetBackBmp()
  234. {
  235.     return ((CPersonVF*)Form())->GetBackBmp(); 
  236. }
  237.  
  238. // -------------------------------------------------------------------------
  239. // GetBackPalette
  240. // -------------------------------------------------------------------------
  241. HPALETTE CPersonRow::GetBackPaletteHandle()
  242. {
  243.     return ((CPersonVF*)Form())->GetBackPalette(); 
  244. }
  245.  
  246. // -------------------------------------------------------------------------
  247. // CPersonRow SetEffect
  248. // -------------------------------------------------------------------------
  249. void CPersonRow::SetEffect(int nEffect)
  250. {
  251.     int nEffectDepth = (nEffect == VEFFECT_SHADOW) ? 2 : 0;
  252.  
  253.     m_name.Effect(nEffect);
  254.     m_phone.Effect(nEffect);
  255.     m_address.Effect(nEffect);
  256.     m_city.Effect(nEffect);
  257.     m_state.Effect(nEffect);
  258.     m_zip.Effect(nEffect);
  259.  
  260.     m_name.EffectDepth(nEffectDepth);
  261.     m_phone.EffectDepth(nEffectDepth);
  262.     m_address.EffectDepth(nEffectDepth);
  263.     m_city.EffectDepth(nEffectDepth);
  264.     m_state.EffectDepth(nEffectDepth);
  265.     m_zip.EffectDepth(nEffectDepth);
  266.  
  267.     SetBG(m_nBackStyle);        // Switch us BACK from the gray (possibly)
  268. }
  269.  
  270. // -------------------------------------------------------------------------
  271. // CPersonRow InactiveBorder
  272. // -------------------------------------------------------------------------
  273. void CPersonRow::SetNoInactBorder(BOOL bFlag)
  274. {
  275.     m_name.NoInactiveBorder(bFlag);
  276.     m_phone.NoInactiveBorder(bFlag);
  277.     m_address.NoInactiveBorder(bFlag);
  278.     m_city.NoInactiveBorder(bFlag);
  279.     m_state.NoInactiveBorder(bFlag);
  280.     m_zip.NoInactiveBorder(bFlag);
  281. }
  282.  
  283. void CPersonRow::SetTransparent(BOOL bFlag)
  284. {
  285.     m_name.SetTransparent(bFlag);
  286.     m_phone.SetTransparent(bFlag);
  287.     m_address.SetTransparent(bFlag);
  288.     m_city.SetTransparent(bFlag);
  289.     m_state.SetTransparent(bFlag);
  290.     m_zip.SetTransparent(bFlag);
  291. }
  292.  
  293.  
  294. // -------------------------------------------------------------------------
  295. // CPersonRow Background Drawing
  296. // -------------------------------------------------------------------------
  297. void CPersonRow::SetBG(int nBackStyle)
  298. {
  299.     SetStyle(nBackStyle);
  300.  
  301.     // These just look better in light gray
  302.     CPersonVF* pForm = (CPersonVF *)Form();
  303.     if(pForm->GetEffect() == VEFFECT_SUNKEN || 
  304.         pForm->GetEffect() == VEFFECT_RAISED)
  305.     {
  306.         m_name.BackColor(RGB(192,192,192));
  307.         m_phone.BackColor(RGB(192,192,192));
  308.         m_address.BackColor(RGB(192,192,192));
  309.         m_city.BackColor(RGB(192,192,192));
  310.         m_state.BackColor(RGB(192,192,192));
  311.         m_zip.BackColor(RGB(192,192,192));
  312.     }
  313.     else
  314.     {
  315.         m_name.BackColorIdx(COLOR_WINDOW);
  316.         m_phone.BackColorIdx(COLOR_WINDOW);
  317.         m_address.BackColorIdx(COLOR_WINDOW);
  318.         m_city.BackColorIdx(COLOR_WINDOW);
  319.         m_state.BackColorIdx(COLOR_WINDOW);
  320.         m_zip.BackColorIdx(COLOR_WINDOW);
  321.     }
  322. }
  323.  
  324.  
  325. // IMPLEMENT_DYNCREATE(CPersonVF, VForm)
  326.  
  327. BEGIN_MESSAGE_MAP(CPersonVF, VForm)
  328.     //{{AFX_MSG_MAP(CPersonVF)
  329.     ON_WM_CREATE()
  330.     //}}AFX_MSG_MAP
  331. END_MESSAGE_MAP()
  332.  
  333. // -------------------------------------------------------------------------
  334. // CPersonVF Constructor
  335. // -------------------------------------------------------------------------
  336. CPersonVF::CPersonVF()
  337. {
  338.     m_pFont;
  339.     m_pPalMH = 0;
  340.     m_nBackIdx = 4;                // Bitmap
  341.     m_hIcon = AfxGetApp()->LoadIcon(IDI_POINTHAND);
  342.     RowHeight(50);
  343.     RowWidth(680);
  344.     m_nRows = 0;                // Start at 400
  345.     m_nEffect = VEFFECT_NORMAL;
  346.  
  347.     GridHdrHeight(20);            // Use thin header height - for grid
  348.     GridMode(TRUE);
  349.     GridStyle(VFGRID_FLAT);
  350.     AllowRowSizing(TRUE);
  351.     GridFrozenColCount(1);
  352.     GridHdrContextMenu(IDR_GRIDHDRMENU);
  353.     AllowAdd(TRUE);
  354.     // ReadOnly(TRUE);            // No input allowed
  355.  
  356.     UseAsDropTarget(TRUE);        // Use as a drop Target
  357.     
  358.     // ------------- Header and footer with NOTHING in them --------
  359.     // m_nHeaderHeight = 40;        // Test out header
  360.     // m_nFooterHeight = 35;        // Test out footer
  361.  
  362.     // ------------- Header and footer with Something in them --------
  363.     CPersonHdr *pHdr = new CPersonHdr();
  364.     SetHeader(pHdr, FALSE);
  365.     CPersonFtr *pFtr = new CPersonFtr();
  366.     SetFooter(pFtr, FALSE);
  367.  
  368.     // We will just use this one report format for now
  369.     UseRptForm(TRUE);                // Use actual report form for printing
  370.     m_rptHdr.DeleteByForm(FALSE);    // Form should not delete these
  371.     m_rptDtl.DeleteByForm(FALSE);    // Form should not delete these
  372.     m_rptFtr.DeleteByForm(FALSE);    // Form should not delete these
  373.     // SetRptHdr(&m_rptHdr);
  374.     // SetRptDtl(&m_rptDtl);
  375.     // SetRptFtr(&m_rptFtr);
  376.     
  377.     m_pFont = GetFonts()->GetOrAdd(_T("Arial"), 100);
  378.  
  379.     if(!m_imgList.Create(IDB_IMG_TEST, 16, 0, RGB(0,255,255)))
  380.         TRACE(_T("CPersonVF could not create image list\n"));
  381.     // m_imgList.SetBkColor(GetSysColor(COLOR_WINDOW));
  382.     if(!m_imgCycleList.Create(IDB_IMG_CYCLES, 16, 0, RGB(0,255,255)))
  383.         TRACE(_T("CPersonVF could not create cycle image list\n"));
  384.     if(!m_imgPrintAnim.Create(IDB_IMG_PRINT_ANIM, 16, 0, RGB(0,255,255)))
  385.         TRACE(_T("CPersonVF could not create print animation image list\n"));
  386.  
  387.     SetBackBmp(_T("Clouds.bmp"));
  388.  
  389.       m_personDB.FileName(_T("person.dat"));
  390.      if(!m_personDB.OpenOrCreate())
  391.       {
  392.           MessageBox(_T("Error opening/creating person.dat"), _T("VForm Demo"),
  393.               MB_OK | MB_ICONEXCLAMATION);
  394.       }
  395.       SetPersonDB(&m_personDB);
  396. }
  397.  
  398. // -------------------------------------------------------------------------
  399. // CPersonVF Destructor
  400. // -------------------------------------------------------------------------
  401. CPersonVF::~CPersonVF()
  402. {
  403.     CString s1 = GetGridSettings();
  404.     AfxGetApp()->WriteProfileString("GridSettings", "Person", s1);
  405. }
  406.  
  407. void CPersonVF::SetPersonDB(CPersonDB *pDB)
  408. {
  409.     m_pPersonDB = pDB;
  410.     int nRecords = m_pPersonDB->GetCount();
  411.     ResetNumRows(nRecords, 0);
  412. }
  413.  
  414.  
  415. BOOL CPersonVF::SetBackBmp(LPCTSTR szFile)
  416. {
  417.     BOOL bRet;
  418.  
  419.     m_bmpBack.DeleteObject();                // remove old
  420.     bRet = m_bmpBack.LoadFile(szFile);        // load new
  421.     // m_pWnd->ResetPalette();
  422.     if(m_pPalMH)
  423.         m_pPalMH->DoRealizePalette(TRUE);
  424.  
  425.     return bRet;
  426. }
  427.  
  428.  
  429. // -------------------------------------------------------------------------
  430. // Function to create a CPersonRow
  431. // -------------------------------------------------------------------------
  432. VRow* CPersonVF::InitRow()
  433. {
  434.     CPersonRow *pRow = new CPersonRow(this);
  435.     pRow->SetIcon(m_hIcon);
  436.     return(pRow); 
  437. }
  438.  
  439. // -------------------------------------------------------------------------
  440. // Called when a row needs to be put on the screen
  441. // -------------------------------------------------------------------------
  442. BOOL CPersonVF::OnGetRow(VRow *pRow)
  443. {
  444.     CString s1;
  445.     CPersonRow *r = (CPersonRow*) pRow;
  446.     long idx = r->RowId();
  447.     CPerson data;
  448.  
  449.     if(!m_pPersonDB->GetRec(idx, data))
  450.         return FALSE;
  451.  
  452.     if(data.IsDeleted())
  453.     {
  454.          r->m_recno.Visible(FALSE);
  455.         r->m_name.Visible(FALSE);
  456.         r->m_phone.Visible(FALSE);
  457.         r->m_address.Visible(FALSE);
  458.         r->m_city.Visible(FALSE);
  459.         r->m_state.Visible(FALSE);
  460.         r->m_zip.Visible(FALSE);
  461.         r->m_chkFriend.Visible(FALSE);
  462.     }
  463.     else
  464.     {
  465.          r->m_recno.Visible(TRUE);
  466.         r->m_name.Visible(TRUE);
  467.         r->m_phone.Visible(TRUE);
  468.         r->m_address.Visible(TRUE);
  469.         r->m_city.Visible(TRUE);
  470.         r->m_state.Visible(TRUE);
  471.         r->m_zip.Visible(TRUE);
  472.         r->m_chkFriend.Visible(TRUE);
  473.     }
  474.  
  475.     r->m_bDeleted = data.IsDeleted();
  476.  
  477.     // s1.Format(_T("%ld:%d"), r->RowId(), r->SRowId());
  478.     s1.Format(_T("%ld"), idx+1);
  479.     r->m_recno.SetWindowText(s1);
  480.  
  481.     r->m_name.SetWindowText(data.m_name);
  482.     r->m_phone.SetWindowText(data.m_phone);
  483.     r->m_address.SetWindowText(data.m_address);
  484.     r->m_city.SetWindowText(data.m_city);
  485.     r->m_state.SetWindowText(data.m_state);
  486.     r->m_zip.SetWindowText(data.m_zip);
  487.     if(data.m_bFriend == 'Y')
  488.         r->m_chkFriend.Checked(TRUE);
  489.     else
  490.         r->m_chkFriend.Checked(FALSE);
  491.  
  492.     return TRUE;
  493. }
  494.  
  495. // -------------------------------------------------------------------------
  496. // Called when a row needs to be put on a report
  497. // -------------------------------------------------------------------------
  498. BOOL CPersonVF::OnGetRptRow(VRow *pRow)
  499. {
  500.     CString s1;
  501.     CPersonRow *r = (CPersonRow*) pRow;
  502.     long idx = r->RowId();
  503.     CPerson data;
  504.  
  505.     if(!m_pPersonDB->GetRec(idx, data))
  506.         return FALSE;
  507.  
  508.     // We dont care if this was deleted!
  509.     // if(data.IsDeleted())
  510.  
  511.     r->m_bDeleted = data.IsDeleted();
  512.  
  513.     s1.Format(_T("%ld"), idx+1);
  514.     r->m_recno.SetWindowText(s1);
  515.  
  516.     r->m_name.SetWindowText(data.m_name);
  517.     r->m_phone.SetWindowText(data.m_phone);
  518.     r->m_address.SetWindowText(data.m_address);
  519.     r->m_city.SetWindowText(data.m_city);
  520.     r->m_state.SetWindowText(data.m_state);
  521.     r->m_zip.SetWindowText(data.m_zip);
  522.     if(data.m_bFriend == 'Y')
  523.         r->m_chkFriend.Checked(TRUE);
  524.     else
  525.         r->m_chkFriend.Checked(FALSE);
  526.  
  527.     return TRUE;
  528. }
  529.  
  530.  
  531. /* -----------
  532. // -------------------------------------------------------------------------
  533. // Called when a row needs to be put on a report
  534. // -------------------------------------------------------------------------
  535. BOOL CPersonVF::OnGetRptRow(VRow *pRow)
  536. {
  537.     CString s1;
  538.     CPersonRptDtl *r = (CPersonRptDtl*) pRow;
  539.     long idx = r->RowId();
  540.     CPerson data;
  541.  
  542.     if(!m_pPersonDB->GetRec(idx, data))
  543.         return FALSE;
  544.  
  545.     if(data.IsDeleted())
  546.     {
  547.         r->m_name.Visible(FALSE);
  548.         r->m_phone.Visible(FALSE);
  549.         r->m_chkFriend.Visible(FALSE);
  550.     }
  551.     else
  552.     {
  553.         r->m_name.Visible(TRUE);
  554.         r->m_phone.Visible(TRUE);
  555.         r->m_chkFriend.Visible(TRUE);
  556.     }
  557.  
  558.     r->m_name.SetWindowText(data.m_name);
  559.     r->m_phone.SetWindowText(data.m_phone);
  560.     if(data.m_bFriend == 'Y')
  561.         r->m_chkFriend.Checked(TRUE);
  562.     else
  563.         r->m_chkFriend.Checked(FALSE);
  564.  
  565.     return TRUE;
  566. }
  567. -------------- */
  568.  
  569.  
  570. // -------------------------------------------------------------------------
  571. // Called when a row needs to be saved (in the data)
  572. // -------------------------------------------------------------------------
  573. BOOL CPersonVF::OnSaveRow(VRow *pRow)
  574. {
  575.     CPersonRow *r = (CPersonRow*) pRow;
  576.     long idx = r->RowId();
  577.     CPerson    data;
  578.  
  579.     /* 
  580.     if(!m_pPersonDB->GetRec(idx, data))
  581.         return FALSE;
  582.  
  583.     if(data.IsDeleted())
  584.         return FALSE;
  585.     */
  586.  
  587.     _tcscpy(data.m_name,    r->m_name.Text());
  588.     _tcscpy(data.m_phone,   r->m_phone.Text());
  589.     _tcscpy(data.m_address, r->m_address.Text());
  590.     _tcscpy(data.m_city,    r->m_city.Text());
  591.     _tcscpy(data.m_state,   r->m_state.Text());
  592.     _tcscpy(data.m_zip,     r->m_zip.Text());
  593.     data.m_bFriend = r->m_chkFriend.Checked() ? 'Y' : 'N';
  594.  
  595.     data.m_deleted = 'N';
  596.  
  597.     if(!m_pPersonDB->UpdateRec(idx, data))
  598.         return FALSE;
  599.  
  600.     return TRUE;
  601. }
  602.  
  603. // -------------------------------------------------------------------------
  604. // Called when row(s) needs to be deleted from the data
  605. // -------------------------------------------------------------------------
  606. BOOL CPersonVF::OnDelete()
  607. {
  608.     CString s1, s2;
  609.     int i;
  610.     CPerson    data;
  611.  
  612.     long nNumSelected = m_selectedList.Count();
  613.     long nRowId = m_selectedList.First();
  614.  
  615.     s1.Format(_T("You have selected to delete %ld records\nContinue?"), nNumSelected);
  616.     i = AfxMessageBox(s1, MB_ICONEXCLAMATION | MB_YESNO);
  617.     if(i != IDYES)
  618.         return TRUE;                // Dont let delete key pass through
  619.  
  620.     for(i=0; i<nNumSelected; i++)
  621.     {
  622.         if(!m_pPersonDB->GetRec(nRowId, data))
  623.         {
  624.             TRACE(_T("Error getting record %d\n"), nRowId);
  625.             continue;
  626.         }
  627.         if(!data.IsDeleted())
  628.         {
  629.             data.m_deleted = 'Y';
  630.             if(!m_pPersonDB->UpdateRec(nRowId, data))
  631.                 TRACE(_T("Error deleting record %d\n"), nRowId);
  632.         }
  633.         nRowId = m_selectedList.Next();
  634.     }
  635.  
  636.     if(!m_personDB.Pack())
  637.         MessageBox(_T("Error Packing Database"), _T("Error"));
  638.  
  639.     ResetNumRows(m_personDB.GetCount());
  640.     RefreshData();                    // Updates Current Row
  641.     // RefreshScreen(VFR_BOTH);        // Updates all rows except current
  642.     return TRUE;
  643. }
  644.  
  645. // -------------------------------------------------------------------------
  646. // Called when a row needs to be added to the data
  647. // -------------------------------------------------------------------------
  648. BOOL CPersonVF::OnAddRow(VRow *pRow)
  649. {
  650.     CPersonRow *r = (CPersonRow*) pRow;
  651.     int idx;
  652.     CPerson    data;
  653.  
  654.     idx = r->RowId();
  655.  
  656.     _tcscpy(data.m_name, r->m_name.Text());
  657.     _tcscpy(data.m_phone, r->m_phone.Text());
  658.     _tcscpy(data.m_address, r->m_address.Text());
  659.     _tcscpy(data.m_city, r->m_city.Text());
  660.     _tcscpy(data.m_state, r->m_state.Text());
  661.     _tcscpy(data.m_zip, r->m_zip.Text());
  662.     data.m_bFriend = r->m_chkFriend.Checked() ? 'Y' : 'N';
  663.     data.m_deleted = 'N';
  664.  
  665.     if(!m_pPersonDB->AddRec(idx, data))
  666.         return FALSE;
  667.  
  668.     return TRUE;
  669. }
  670.  
  671. // -------------------------------------------------------------------------
  672. // Called when a row is initially being added
  673. // -------------------------------------------------------------------------
  674. void CPersonVF::OnStartAdd(VRow *pRow)
  675. {
  676.     CString s1;
  677.     CPersonRow *r = (CPersonRow*) pRow;
  678.     long idx;
  679.     // CPerson   data;
  680.  
  681.     idx = r->RowId();
  682.     
  683.     s1.Format(_T("%ld"), idx+1);
  684.     r->m_recno.SetWindowText(s1);
  685.  
  686.     r->m_name.SetWindowText(_T(""));
  687.     r->m_phone.SetWindowText(_T(""));
  688.     r->m_address.SetWindowText(_T(""));
  689.     r->m_city.SetWindowText(_T(""));
  690.     r->m_state.SetWindowText(_T(""));
  691.     r->m_zip.SetWindowText(_T(""));
  692.     r->m_chkFriend.Checked(FALSE);
  693. }
  694.  
  695.  
  696. // -------------------------------------------------------------------------
  697. // Called when a button is clicked
  698. // -------------------------------------------------------------------------
  699. void CPersonVF::OnClick(VRow *pRow, int nId)
  700. {
  701.     CString s1, sBmpFile;
  702.     BOOL bFlag;
  703.     CPersonRow *pPersonRow = (CPersonRow*) pRow;
  704.     static _TCHAR szFilter[] = _T("Bitmaps (*.bmp)|*.bmp|All Files (*.*)|*.*||"); 
  705.  
  706.     switch(nId)
  707.     {
  708.     case IDVC_CHK_SELECTORS:
  709.         {
  710.             CPersonHdr *pHdr = (CPersonHdr *)Header();
  711.             if(pHdr->m_chkSelectors.Checked())
  712.                 UseSelectors(TRUE);
  713.             else
  714.                 UseSelectors(FALSE);
  715.             break;
  716.         }
  717.     case IDVC_SET_BMP:
  718.         {
  719.             CFileDialog dlg(TRUE, _T("bmp"), sBmpFile, 
  720.                 OFN_SHAREAWARE | OFN_PATHMUSTEXIST, szFilter); 
  721.             if(dlg.DoModal() != IDOK)
  722.                 break;
  723.  
  724.             sBmpFile = dlg.GetPathName();
  725.             if(SetBackBmp(sBmpFile) && m_nBackIdx == 4)
  726.             {
  727.                 RefreshScreen(VFR_BOTH);
  728.             }
  729.             break;
  730.         }
  731.     case IDVC_CHK_TRANSPARENT:
  732.         {
  733.             CPersonHdr *pHdr = (CPersonHdr *)Header();
  734.             bFlag = (pHdr->m_chkTransparent.Checked()) ? TRUE : FALSE;
  735.             // Reset detail rows to this style
  736.             pPersonRow = (CPersonRow *)m_pDtlRow;
  737.             pPersonRow->SetTransparent(bFlag);
  738.             pPersonRow = (CPersonRow *)m_pTmpRow;
  739.             pPersonRow->SetTransparent(bFlag);
  740.             
  741.             RefreshScreen(VFR_BOTH);
  742.             break;
  743.         }
  744.     case IDVC_RDO_INACTBORDER:
  745.         {
  746.             CPersonHdr *pHdr = (CPersonHdr *)Header();
  747.             bFlag = (pHdr->m_rdoInactBorder.SelItem() == 0) ? FALSE: TRUE;
  748.             pPersonRow = (CPersonRow *)m_pDtlRow;
  749.             pPersonRow->SetNoInactBorder(bFlag);
  750.             pPersonRow = (CPersonRow *)m_pTmpRow;
  751.             pPersonRow->SetNoInactBorder(bFlag);
  752.             RefreshScreen(VFR_BOTH);
  753.             break;
  754.         }
  755.     case IDVC_TESTBUTTON:
  756.         {
  757.             AfxMessageBox(_T("Click on Test Button"), MB_OK | MB_ICONINFORMATION);
  758.             break;
  759.         }
  760.     case IDVC_CHK_GRID_MODE:
  761.         {
  762.             CPersonFtr *pFtr = (CPersonFtr *)Footer();
  763.             if(pFtr->m_chkGridMode.Checked())
  764.                 GridMode(TRUE);
  765.             else
  766.                 GridMode(FALSE);
  767.             break;
  768.         }
  769.     case IDVC_CHK_LIVE_RESIZING:
  770.         {
  771.             CPersonFtr *pFtr = (CPersonFtr *)Footer();
  772.             if(pFtr->m_chkLiveResizing.Checked())
  773.                 LiveAdjust(TRUE);
  774.             else
  775.                 LiveAdjust(FALSE);
  776.             break;
  777.         }
  778.     case IDVC_CHK_SNAP_RESIZE:
  779.         {
  780.             CPersonFtr *pFtr = (CPersonFtr *)Footer();
  781.             if(pFtr->m_chkSnapResize.Checked())
  782.                 SnapResize(TRUE);
  783.             else
  784.                 SnapResize(FALSE);
  785.             break;
  786.         }
  787.     }
  788. }
  789.  
  790. // -------------------------------------------------------------------------
  791. // Called from OnLButtonDown
  792. // -------------------------------------------------------------------------
  793. BOOL CPersonVF::OnBeginDrag(long nRowId)
  794. {
  795.     DROPEFFECT dEffect, retDEffect;
  796.     CString s1;
  797.     CPerson data;
  798.  
  799.     if(!m_pPersonDB->GetRec(nRowId, data)) return FALSE;    // No drag started
  800.  
  801.     s1.Format(_T("Name: %s  Phone: %s"), data.m_name, data.m_phone);
  802.     dEffect = (::GetKeyState(VK_CONTROL) < 0) ? DROPEFFECT_COPY : DROPEFFECT_MOVE;
  803.  
  804.     retDEffect = VfuDoDragDrop(s1, dEffect);
  805.  
  806.     if(retDEffect == DROPEFFECT_NONE)    return FALSE;        // No drag started
  807.  
  808.     // Note: "Dropee" handles all operations
  809.     if(retDEffect == DROPEFFECT_MOVE)
  810.     {
  811.         // ... Remove the row from this VForm
  812.     }
  813.     if(retDEffect == DROPEFFECT_COPY)
  814.     {
  815.         // ... Do whatever you want
  816.         // AfxMessageBox("Got COPY Drop effect", "Notice");
  817.     }
  818.  
  819.     return TRUE;        // We did start a drag operation
  820. }
  821.  
  822. // -------------------------------------------------------------------------
  823. // Called when something is dropped on us
  824. // -------------------------------------------------------------------------
  825. BOOL CPersonVF::OnDrop(long nRowId, COleDataObject* pDataObject, 
  826.                        DROPEFFECT dropEffect)
  827. {
  828.     CString sText, s1; 
  829.  
  830.     if(!VfuGetDropText(pDataObject, sText))
  831.         s1.Format(_T("You dropped on row %ld!"), nRowId);
  832.     else
  833.         s1.Format(_T("You dropped the following on row %ld!\n%s"), 
  834.                 nRowId, (LPCTSTR) sText);
  835.  
  836.     AfxMessageBox(s1, MB_OK | MB_ICONINFORMATION);
  837.  
  838.     return FALSE;        // We do not accept the drop
  839. }
  840.  
  841.  
  842. // -------------------------------------------------------------------------
  843. // Called when list is closed is clicked
  844. // -------------------------------------------------------------------------
  845. BOOL CPersonVF::OnEndList(VCtl* pCtl, CListBox* pLB)
  846. {
  847.     CPersonRow *pRow;
  848.     CPersonHdr *pHdr;
  849.     int i;
  850.     int nBgStyle = VROW_BG_DEFAULT;
  851.  
  852.     switch(pCtl->Id())
  853.     {
  854.     case IDVC_BG_OPTION:
  855.         m_nBackIdx = pLB->GetCurSel();
  856.  
  857.         switch(m_nBackIdx)
  858.         {
  859.         case 0:    nBgStyle = VROW_BG_DEFAULT;        break;
  860.         case 1:    nBgStyle = VROW_BG_GREENBAR;    break;
  861.         case 2:    nBgStyle = VROW_BG_PAPER;        break;
  862.         case 3:    nBgStyle = VROW_BG_FLAT;        break;
  863.         case 4:    nBgStyle = VROW_BG_BMP;            break;
  864.         }
  865.  
  866.         // Reset detail rows to this style
  867.         pHdr = (CPersonHdr *)Header();
  868.         pHdr->SetStyle(nBgStyle);
  869.  
  870.         pRow = (CPersonRow *)m_pDtlRow;
  871.         pRow->SetBG(nBgStyle);
  872.         pRow = (CPersonRow *)m_pTmpRow;
  873.         pRow->SetBG(nBgStyle);
  874.  
  875.         RefreshScreen(VFR_BOTH);
  876.         break;
  877.     case IDVC_BOX_STYLE:
  878.         i = pLB->GetCurSel();
  879.  
  880.         switch(i)
  881.         {
  882.         case 0:        m_nEffect = VEFFECT_NORMAL;        break;
  883.         case 1:        m_nEffect = VEFFECT_SHADOW;        break;
  884.         case 2:        m_nEffect = VEFFECT_SUNKEN;        break;
  885.         case 3:        m_nEffect = VEFFECT_RAISED;        break;
  886.         default:    m_nEffect = VEFFECT_NORMAL;        break;
  887.         }
  888.  
  889.         // Reset detail rows to this style
  890.         pRow = (CPersonRow *)m_pDtlRow;
  891.         pRow->SetEffect(m_nEffect);
  892.         pRow = (CPersonRow *)m_pTmpRow;
  893.         pRow->SetEffect(m_nEffect);
  894.  
  895.         RefreshScreen(VFR_BOTH);
  896.         break;
  897.     case IDVC_LST_GRID_STYLE:
  898.         i = pLB->GetCurSel();
  899.         switch(i)
  900.         {
  901.         case 0:        GridStyle(VFGRID_FLAT); break;
  902.         case 1:        GridStyle(VFGRID_NOLINES); break;
  903.         case 2:        GridStyle(VFGRID_SUNKEN); break;
  904.         case 3:        GridStyle(VFGRID_RAISED); break;
  905.         case 4:        GridStyle(VFGRID_VERTLINES); break;
  906.         case 5:        GridStyle(VFGRID_HORZLINES); break;
  907.         case 6:        GridStyle(VFGRID_ALTERNATING); break;
  908.         default:    GridStyle(VFGRID_FLAT); break;
  909.         }
  910.         if(GridMode()) RefreshScreen(VFR_BOTH);
  911.         break;
  912.     }
  913.  
  914.     return TRUE;
  915. }
  916.  
  917. // -------------------------------------------------------------------------
  918. // Called when a button is clicked
  919. // -------------------------------------------------------------------------
  920. BOOL CPersonVF::OnGridRowColor(VRow *pRow, COLORREF &clrRow)
  921. {
  922.     if(pRow->RowId() == 5)
  923.     {    
  924.         clrRow = RGB(0, 255, 0);
  925.         return TRUE;
  926.     }
  927.         
  928.     return FALSE;
  929. }
  930.  
  931. // -------------------------------------------------------------------------
  932. // Called when a row is double clicked
  933. // -------------------------------------------------------------------------
  934. BOOL CPersonVF::OnDblClkRow(long nRowId, UINT nFlags, CPoint point)
  935. {
  936.     CString s1;
  937.     s1.Format(_T("You double-clicked on row %ld"), nRowId);
  938.     AfxMessageBox(s1);
  939.     return TRUE;
  940. }
  941.  
  942. BOOL CPersonVF::OnDblClkHeader(UINT nFlags, CPoint point)
  943. {
  944.     AfxMessageBox(_T("You double-clicked the header"));
  945.     return TRUE;
  946. }
  947. BOOL CPersonVF::OnDblClkDetail(UINT nFlags, CPoint point)
  948. {
  949.     AfxMessageBox(_T("You double-clicked the detail section (not on a row)"));
  950.     return TRUE;
  951. }
  952. BOOL CPersonVF::OnDblClkFooter(UINT nFlags, CPoint point)
  953. {
  954.     AfxMessageBox(_T("You double-clicked the footer"));
  955.     return TRUE;
  956. }
  957.  
  958.  
  959.  
  960. // -------------------------------------------------------------------------
  961. //    Start a timer for the form
  962. // -------------------------------------------------------------------------
  963. int CPersonVF::OnCreate(LPCREATESTRUCT lpCreateStruct) 
  964. {
  965.     if (VForm::OnCreate(lpCreateStruct) == -1)
  966.         return -1;
  967.     
  968.     // m_nTimerId = SetTimer(ANIM_TIMER, 300, NULL);
  969.     // if(m_nTimerId == 0)
  970.     // {
  971.     //    TRACE(_T("CPersonVF::OnCreate - Unable to SetTimer\n"));
  972.     // }
  973.  
  974.     return 0;
  975. }
  976.  
  977.