home *** CD-ROM | disk | FTP | other *** search
- // -------------------------------------------------------------------------
- // Copyright @ 1997 TCK Software, Incorporated
- // All Rights Reserved
- // -------------------------------------------------------------------------
-
- #include "stdafx.h"
- #include "personVF.h"
- #include "resource.h"
-
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
-
- #define ANIM_TIMER 102
-
-
- // Static Data Members
-
- // -------------------------------------------------------------------------
- // CPersonHdr Constructor
- // -------------------------------------------------------------------------
- CPersonRptHdr::CPersonRptHdr()
- {
- Height(40);
- m_rptHeading.Init(this, -1, _T("Customer Report"), 20,5,300,33);
- m_line.Init(this, -1, 10,37,800,3);
-
- CFont *pFont = VForm::GetFonts()->GetOrAdd(_T("Arial"), 200);
- m_rptHeading.Font(pFont);
-
- AddCtl(&m_rptHeading);
- AddCtl(&m_line);
- }
-
- // -------------------------------------------------------------------------
- // CPersonFtr Constructor
- // -------------------------------------------------------------------------
- CPersonRptFtr::CPersonRptFtr()
- {
- Height(40);
- m_line.Init(this, -1, 10,2,800,3);
- m_rptFooter.Init(this, -1, _T("--- Report Footer ---"), 20,5,300,35);
- m_rptPageNo.Init(this, -1, _T(""), 700,5,100,100);
-
- CFont *pFont = VForm::GetFonts()->GetOrAdd(_T("Arial"), 160);
- m_rptFooter.Font(pFont);
- m_rptPageNo.Name(_T("PAGENO")); // Use the Special Name
-
- AddCtl(&m_line);
- AddCtl(&m_rptFooter);
- AddCtl(&m_rptPageNo);
- }
-
-
- // -------------------------------------------------------------------------
- // CPersonRptDtl Constructor
- // -------------------------------------------------------------------------
- CPersonRptDtl::CPersonRptDtl()
- {
- m_name.Init(this, IDVC_NAME, _T(""), 20,3,150,20);
- m_phone.Init(this, IDVC_PHONE, _T(""), 180,3,120,20);
- // m_address.Init(this, IDVC_ADDRESS, _T(""), 250,3,250,20);
- // m_city.Init(this, IDVC_CITY, _T(""), 250,25,150,20);
- // m_state.Init(this, IDVC_STATE, _T(""), 410,25,30,20);
- // m_zip.Init(this, IDVC_ZIP, _T(""), 450,25,80,20);
- m_chkFriend.Init(this, IDVC_FRIENDCHECK, _T(""), 300,3,20,20);
-
- AddCtl(&m_name);
- AddCtl(&m_phone);
- // AddCtl(&m_address);
- // AddCtl(&m_city);
- // AddCtl(&m_state);
- // AddCtl(&m_zip);
- AddCtl(&m_chkFriend);
- }
-
-
-
- // -------------------------------------------------------------------------
- // CPersonHdr Constructor
- // -------------------------------------------------------------------------
- CPersonHdr::CPersonHdr()
- {
- Height(40);
- m_chkSelectors.Init(this, IDVC_CHK_SELECTORS, _T("Selectors"), 5,5,80,20);
- m_lblBackGround.Init(this, -1, _T("Background:"), 100,7,83,20);
- m_lstBgOption.Init(this, IDVC_BG_OPTION, _T("Bitmap"), 180,5,90,20);
- m_btnSetBmp.Init(this, IDVC_SET_BMP, _T("Set Bmp"), 280,5,70,20);
- m_chkShadow.Init(this, IDVC_CHK_SHADOW, _T("Shadow"), 365,5,70,20);
- m_lstBoxStyle.Init(this, IDVC_BOX_STYLE, _T("Normal"), 365,5,70,20);
- m_rdoInactBorder.Init(this, IDVC_RDO_INACTBORDER, _T(""), 445,2,145,38);
- m_chkTransparent.Init(this, IDVC_CHK_TRANSPARENT, _T("Transparent"), 590,5,90,20);
- m_nBackStyle = 0;
- m_chkSelectors.Checked(TRUE);
- m_chkShadow.Checked(TRUE);
- m_chkTransparent.Checked(TRUE);
- m_rdoInactBorder.AddString(_T("Inactive Border On"));
- m_rdoInactBorder.AddString(_T("Inactive Border Off"));
-
- m_lstBgOption.AddString(_T("Normal"));
- m_lstBgOption.AddString(_T("Green Bar"));
- m_lstBgOption.AddString(_T("Paper Pad"));
- m_lstBgOption.AddString(_T("Flat Look"));
- m_lstBgOption.AddString(_T("Bitmap"));
-
- m_lstBoxStyle.AddString(_T("Normal"));
- m_lstBoxStyle.AddString(_T("Shadow"));
- m_lstBoxStyle.AddString(_T("Indented"));
- m_lstBoxStyle.AddString(_T("Bumped"));
-
- // A few special attribute examples
- // m_chkSelectors.Disable();
- // m_lstBgOption.Disable();
- // m_btnSetBmp.Disable();
-
- AddCtl(&m_chkSelectors);
- AddCtl(&m_lblBackGround);
- AddCtl(&m_lstBgOption);
- AddCtl(&m_btnSetBmp);
- AddCtl(&m_lstBoxStyle);
- AddCtl(&m_rdoInactBorder);
- AddCtl(&m_chkTransparent);
- }
-
- // -------------------------------------------------------------------------
- // CPersonFtr Constructor
- // -------------------------------------------------------------------------
- CPersonFtr::CPersonFtr()
- {
- Height(40);
- m_chkGridMode.Init(this, IDVC_CHK_GRID_MODE, _T("Grid Mode"), 5,5,80,20);
- m_lblGridStyle.Init(this, -1, _T("Grid Style"), 100,7,60,20);
- m_lstGridStyle.Init(this, IDVC_LST_GRID_STYLE, _T("Flat"), 160,5,90,20);
- m_chkLiveResizing.Init(this, IDVC_CHK_LIVE_RESIZING, _T("Live Resizing"), 270,5,100,20);
- m_chkSnapResize.Init(this, IDVC_CHK_SNAP_RESIZE, _T("Snap Resize"), 380,5,100,20);
- m_chkGridMode.Checked(TRUE);
- m_chkLiveResizing.Checked(TRUE);
- m_chkSnapResize.Checked(FALSE);
-
- m_lstGridStyle.AddString(_T("Flat"));
- m_lstGridStyle.AddString(_T("No Lines"));
- m_lstGridStyle.AddString(_T("Sunken"));
- m_lstGridStyle.AddString(_T("Raised"));
- m_lstGridStyle.AddString(_T("Vert Lines"));
- m_lstGridStyle.AddString(_T("Horz Lines"));
- m_lstGridStyle.AddString(_T("Alternating"));
-
- AddCtl(&m_chkGridMode);
- AddCtl(&m_lblGridStyle);
- AddCtl(&m_lstGridStyle);
- AddCtl(&m_chkLiveResizing);
- // AddCtl(&m_chkSnapResize);
- }
-
-
- // -------------------------------------------------------------------------
- // CPersonRow Constructor
- // -------------------------------------------------------------------------
- CPersonRow::CPersonRow(CPersonVF* pForm)
- {
- m_recno.Init(this, IDVC_RECNO, _T(""), 50,5,30,20);
- m_name.Init(this, IDVC_NAME, _T(""), 90,3,100,20);
- m_phone.Init(this, IDVC_PHONE, _T(""), 90,25,90,20);
- m_address.Init(this, IDVC_ADDRESS, _T(""), 250,3,250,20);
- m_city.Init(this, IDVC_CITY, _T(""), 250,25,150,20);
- m_state.Init(this, IDVC_STATE, _T(""), 410,25,30,20);
- m_zip.Init(this, IDVC_ZIP, _T(""), 450,25,80,20);
- m_chkFriend.Init(this, IDVC_FRIENDCHECK, _T("Friend"), 535,5,60,20);
- m_btnTest.Init(this, IDVC_TESTBUTTON, _T("Click"), 535,25,50,20);
-
- SetTransparent(TRUE);
-
- // ------ Set Grid Captions --------
- m_name.GridCaption(_T("Name"));
- m_phone.GridCaption(_T("Phone"));
- m_address.GridCaption(_T("Address"));
- m_city.GridCaption(_T("City"));
- m_state.GridCaption(_T("State"));
- m_zip.GridCaption(_T("Zip"));
- m_chkFriend.GridCaption(_T("Friend"));
- m_btnTest.GridCaption(_T(""));
- m_btnTest.UseInGrid(TRUE);
-
- // ------ Set Control Names (so we can remember settings) --------
- m_name.Name(_T("Name"));
- m_phone.Name(_T("Phone"));
- m_address.Name(_T("Address"));
- m_city.Name(_T("City"));
- m_state.Name(_T("State"));
- m_zip.Name(_T("Zip"));
- m_chkFriend.Name(_T("Friend"));
- m_btnTest.Name(_T("ButtonTest"));
-
- m_name.LimitText(PERS_NAME);
- m_address.LimitText(PERS_ADDR);
- m_city.LimitText(PERS_CITY);
- m_state.LimitText(PERS_STATE);
- m_zip.LimitText(PERS_ZIP);
- m_phone.LimitText(PERS_PHONE);
- m_phone.Type(TCKEDIT_MASK);
- m_phone.Mask(_T("(###)###-####Z"));
- // m_phone.SaveMaskChars(FALSE);
- m_phone.ForeColor(RGB(255,0,0));
- // m_phone.AutoTab(TRUE); // Auto tab when full
- // m_phone.PromptInclude(FALSE); // If you dont want the mask chars
-
- // A few special attribute examples
- // m_name.MultiLine(TRUE);
- // m_city.Disable();
- SetIconPosition(5, 0);
-
- AddCtl(&m_recno);
- AddCtl(&m_name);
- AddCtl(&m_phone);
- AddCtl(&m_address);
- AddCtl(&m_city);
- AddCtl(&m_state);
- AddCtl(&m_zip);
- AddCtl(&m_chkFriend);
- AddCtl(&m_btnTest);
-
- SetForm(pForm); // We need the form set BEFORE calling SetBG
- SetEffect(VEFFECT_NORMAL);
- SetNoInactBorder(FALSE); // Initially use inactive borders
- SetBG(VROW_BG_BMP); // Initially use the Bitmap Background
- }
-
- // -------------------------------------------------------------------------
- // GetBackBmp
- // -------------------------------------------------------------------------
- HBITMAP CPersonRow::GetBackBmp()
- {
- return ((CPersonVF*)Form())->GetBackBmp();
- }
-
- // -------------------------------------------------------------------------
- // GetBackPalette
- // -------------------------------------------------------------------------
- HPALETTE CPersonRow::GetBackPaletteHandle()
- {
- return ((CPersonVF*)Form())->GetBackPalette();
- }
-
- // -------------------------------------------------------------------------
- // CPersonRow SetEffect
- // -------------------------------------------------------------------------
- void CPersonRow::SetEffect(int nEffect)
- {
- int nEffectDepth = (nEffect == VEFFECT_SHADOW) ? 2 : 0;
-
- m_name.Effect(nEffect);
- m_phone.Effect(nEffect);
- m_address.Effect(nEffect);
- m_city.Effect(nEffect);
- m_state.Effect(nEffect);
- m_zip.Effect(nEffect);
-
- m_name.EffectDepth(nEffectDepth);
- m_phone.EffectDepth(nEffectDepth);
- m_address.EffectDepth(nEffectDepth);
- m_city.EffectDepth(nEffectDepth);
- m_state.EffectDepth(nEffectDepth);
- m_zip.EffectDepth(nEffectDepth);
-
- SetBG(m_nBackStyle); // Switch us BACK from the gray (possibly)
- }
-
- // -------------------------------------------------------------------------
- // CPersonRow InactiveBorder
- // -------------------------------------------------------------------------
- void CPersonRow::SetNoInactBorder(BOOL bFlag)
- {
- m_name.NoInactiveBorder(bFlag);
- m_phone.NoInactiveBorder(bFlag);
- m_address.NoInactiveBorder(bFlag);
- m_city.NoInactiveBorder(bFlag);
- m_state.NoInactiveBorder(bFlag);
- m_zip.NoInactiveBorder(bFlag);
- }
-
- void CPersonRow::SetTransparent(BOOL bFlag)
- {
- m_name.SetTransparent(bFlag);
- m_phone.SetTransparent(bFlag);
- m_address.SetTransparent(bFlag);
- m_city.SetTransparent(bFlag);
- m_state.SetTransparent(bFlag);
- m_zip.SetTransparent(bFlag);
- }
-
-
- // -------------------------------------------------------------------------
- // CPersonRow Background Drawing
- // -------------------------------------------------------------------------
- void CPersonRow::SetBG(int nBackStyle)
- {
- SetStyle(nBackStyle);
-
- // These just look better in light gray
- CPersonVF* pForm = (CPersonVF *)Form();
- if(pForm->GetEffect() == VEFFECT_SUNKEN ||
- pForm->GetEffect() == VEFFECT_RAISED)
- {
- m_name.BackColor(RGB(192,192,192));
- m_phone.BackColor(RGB(192,192,192));
- m_address.BackColor(RGB(192,192,192));
- m_city.BackColor(RGB(192,192,192));
- m_state.BackColor(RGB(192,192,192));
- m_zip.BackColor(RGB(192,192,192));
- }
- else
- {
- m_name.BackColorIdx(COLOR_WINDOW);
- m_phone.BackColorIdx(COLOR_WINDOW);
- m_address.BackColorIdx(COLOR_WINDOW);
- m_city.BackColorIdx(COLOR_WINDOW);
- m_state.BackColorIdx(COLOR_WINDOW);
- m_zip.BackColorIdx(COLOR_WINDOW);
- }
- }
-
-
- // IMPLEMENT_DYNCREATE(CPersonVF, VForm)
-
- BEGIN_MESSAGE_MAP(CPersonVF, VForm)
- //{{AFX_MSG_MAP(CPersonVF)
- ON_WM_CREATE()
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
-
- // -------------------------------------------------------------------------
- // CPersonVF Constructor
- // -------------------------------------------------------------------------
- CPersonVF::CPersonVF()
- {
- m_pFont;
- m_pPalMH = 0;
- m_nBackIdx = 4; // Bitmap
- m_hIcon = AfxGetApp()->LoadIcon(IDI_POINTHAND);
- RowHeight(50);
- RowWidth(680);
- m_nRows = 0; // Start at 400
- m_nEffect = VEFFECT_NORMAL;
-
- GridHdrHeight(20); // Use thin header height - for grid
- GridMode(TRUE);
- GridStyle(VFGRID_FLAT);
- AllowRowSizing(TRUE);
- GridFrozenColCount(1);
- GridHdrContextMenu(IDR_GRIDHDRMENU);
- AllowAdd(TRUE);
- // ReadOnly(TRUE); // No input allowed
-
- UseAsDropTarget(TRUE); // Use as a drop Target
-
- // ------------- Header and footer with NOTHING in them --------
- // m_nHeaderHeight = 40; // Test out header
- // m_nFooterHeight = 35; // Test out footer
-
- // ------------- Header and footer with Something in them --------
- CPersonHdr *pHdr = new CPersonHdr();
- SetHeader(pHdr, FALSE);
- CPersonFtr *pFtr = new CPersonFtr();
- SetFooter(pFtr, FALSE);
-
- // We will just use this one report format for now
- UseRptForm(TRUE); // Use actual report form for printing
- m_rptHdr.DeleteByForm(FALSE); // Form should not delete these
- m_rptDtl.DeleteByForm(FALSE); // Form should not delete these
- m_rptFtr.DeleteByForm(FALSE); // Form should not delete these
- // SetRptHdr(&m_rptHdr);
- // SetRptDtl(&m_rptDtl);
- // SetRptFtr(&m_rptFtr);
-
- m_pFont = GetFonts()->GetOrAdd(_T("Arial"), 100);
-
- if(!m_imgList.Create(IDB_IMG_TEST, 16, 0, RGB(0,255,255)))
- TRACE(_T("CPersonVF could not create image list\n"));
- // m_imgList.SetBkColor(GetSysColor(COLOR_WINDOW));
- if(!m_imgCycleList.Create(IDB_IMG_CYCLES, 16, 0, RGB(0,255,255)))
- TRACE(_T("CPersonVF could not create cycle image list\n"));
- if(!m_imgPrintAnim.Create(IDB_IMG_PRINT_ANIM, 16, 0, RGB(0,255,255)))
- TRACE(_T("CPersonVF could not create print animation image list\n"));
-
- SetBackBmp(_T("Clouds.bmp"));
-
- m_personDB.FileName(_T("person.dat"));
- if(!m_personDB.OpenOrCreate())
- {
- MessageBox(_T("Error opening/creating person.dat"), _T("VForm Demo"),
- MB_OK | MB_ICONEXCLAMATION);
- }
- SetPersonDB(&m_personDB);
- }
-
- // -------------------------------------------------------------------------
- // CPersonVF Destructor
- // -------------------------------------------------------------------------
- CPersonVF::~CPersonVF()
- {
- CString s1 = GetGridSettings();
- AfxGetApp()->WriteProfileString("GridSettings", "Person", s1);
- }
-
- void CPersonVF::SetPersonDB(CPersonDB *pDB)
- {
- m_pPersonDB = pDB;
- int nRecords = m_pPersonDB->GetCount();
- ResetNumRows(nRecords, 0);
- }
-
-
- BOOL CPersonVF::SetBackBmp(LPCTSTR szFile)
- {
- BOOL bRet;
-
- m_bmpBack.DeleteObject(); // remove old
- bRet = m_bmpBack.LoadFile(szFile); // load new
- // m_pWnd->ResetPalette();
- if(m_pPalMH)
- m_pPalMH->DoRealizePalette(TRUE);
-
- return bRet;
- }
-
-
- // -------------------------------------------------------------------------
- // Function to create a CPersonRow
- // -------------------------------------------------------------------------
- VRow* CPersonVF::InitRow()
- {
- CPersonRow *pRow = new CPersonRow(this);
- pRow->SetIcon(m_hIcon);
- return(pRow);
- }
-
- // -------------------------------------------------------------------------
- // Called when a row needs to be put on the screen
- // -------------------------------------------------------------------------
- BOOL CPersonVF::OnGetRow(VRow *pRow)
- {
- CString s1;
- CPersonRow *r = (CPersonRow*) pRow;
- long idx = r->RowId();
- CPerson data;
-
- if(!m_pPersonDB->GetRec(idx, data))
- return FALSE;
-
- if(data.IsDeleted())
- {
- r->m_recno.Visible(FALSE);
- r->m_name.Visible(FALSE);
- r->m_phone.Visible(FALSE);
- r->m_address.Visible(FALSE);
- r->m_city.Visible(FALSE);
- r->m_state.Visible(FALSE);
- r->m_zip.Visible(FALSE);
- r->m_chkFriend.Visible(FALSE);
- }
- else
- {
- r->m_recno.Visible(TRUE);
- r->m_name.Visible(TRUE);
- r->m_phone.Visible(TRUE);
- r->m_address.Visible(TRUE);
- r->m_city.Visible(TRUE);
- r->m_state.Visible(TRUE);
- r->m_zip.Visible(TRUE);
- r->m_chkFriend.Visible(TRUE);
- }
-
- r->m_bDeleted = data.IsDeleted();
-
- // s1.Format(_T("%ld:%d"), r->RowId(), r->SRowId());
- s1.Format(_T("%ld"), idx+1);
- r->m_recno.SetWindowText(s1);
-
- r->m_name.SetWindowText(data.m_name);
- r->m_phone.SetWindowText(data.m_phone);
- r->m_address.SetWindowText(data.m_address);
- r->m_city.SetWindowText(data.m_city);
- r->m_state.SetWindowText(data.m_state);
- r->m_zip.SetWindowText(data.m_zip);
- if(data.m_bFriend == 'Y')
- r->m_chkFriend.Checked(TRUE);
- else
- r->m_chkFriend.Checked(FALSE);
-
- return TRUE;
- }
-
- // -------------------------------------------------------------------------
- // Called when a row needs to be put on a report
- // -------------------------------------------------------------------------
- BOOL CPersonVF::OnGetRptRow(VRow *pRow)
- {
- CString s1;
- CPersonRow *r = (CPersonRow*) pRow;
- long idx = r->RowId();
- CPerson data;
-
- if(!m_pPersonDB->GetRec(idx, data))
- return FALSE;
-
- // We dont care if this was deleted!
- // if(data.IsDeleted())
-
- r->m_bDeleted = data.IsDeleted();
-
- s1.Format(_T("%ld"), idx+1);
- r->m_recno.SetWindowText(s1);
-
- r->m_name.SetWindowText(data.m_name);
- r->m_phone.SetWindowText(data.m_phone);
- r->m_address.SetWindowText(data.m_address);
- r->m_city.SetWindowText(data.m_city);
- r->m_state.SetWindowText(data.m_state);
- r->m_zip.SetWindowText(data.m_zip);
- if(data.m_bFriend == 'Y')
- r->m_chkFriend.Checked(TRUE);
- else
- r->m_chkFriend.Checked(FALSE);
-
- return TRUE;
- }
-
-
- /* -----------
- // -------------------------------------------------------------------------
- // Called when a row needs to be put on a report
- // -------------------------------------------------------------------------
- BOOL CPersonVF::OnGetRptRow(VRow *pRow)
- {
- CString s1;
- CPersonRptDtl *r = (CPersonRptDtl*) pRow;
- long idx = r->RowId();
- CPerson data;
-
- if(!m_pPersonDB->GetRec(idx, data))
- return FALSE;
-
- if(data.IsDeleted())
- {
- r->m_name.Visible(FALSE);
- r->m_phone.Visible(FALSE);
- r->m_chkFriend.Visible(FALSE);
- }
- else
- {
- r->m_name.Visible(TRUE);
- r->m_phone.Visible(TRUE);
- r->m_chkFriend.Visible(TRUE);
- }
-
- r->m_name.SetWindowText(data.m_name);
- r->m_phone.SetWindowText(data.m_phone);
- if(data.m_bFriend == 'Y')
- r->m_chkFriend.Checked(TRUE);
- else
- r->m_chkFriend.Checked(FALSE);
-
- return TRUE;
- }
- -------------- */
-
-
- // -------------------------------------------------------------------------
- // Called when a row needs to be saved (in the data)
- // -------------------------------------------------------------------------
- BOOL CPersonVF::OnSaveRow(VRow *pRow)
- {
- CPersonRow *r = (CPersonRow*) pRow;
- long idx = r->RowId();
- CPerson data;
-
- /*
- if(!m_pPersonDB->GetRec(idx, data))
- return FALSE;
-
- if(data.IsDeleted())
- return FALSE;
- */
-
- _tcscpy(data.m_name, r->m_name.Text());
- _tcscpy(data.m_phone, r->m_phone.Text());
- _tcscpy(data.m_address, r->m_address.Text());
- _tcscpy(data.m_city, r->m_city.Text());
- _tcscpy(data.m_state, r->m_state.Text());
- _tcscpy(data.m_zip, r->m_zip.Text());
- data.m_bFriend = r->m_chkFriend.Checked() ? 'Y' : 'N';
-
- data.m_deleted = 'N';
-
- if(!m_pPersonDB->UpdateRec(idx, data))
- return FALSE;
-
- return TRUE;
- }
-
- // -------------------------------------------------------------------------
- // Called when row(s) needs to be deleted from the data
- // -------------------------------------------------------------------------
- BOOL CPersonVF::OnDelete()
- {
- CString s1, s2;
- int i;
- CPerson data;
-
- long nNumSelected = m_selectedList.Count();
- long nRowId = m_selectedList.First();
-
- s1.Format(_T("You have selected to delete %ld records\nContinue?"), nNumSelected);
- i = AfxMessageBox(s1, MB_ICONEXCLAMATION | MB_YESNO);
- if(i != IDYES)
- return TRUE; // Dont let delete key pass through
-
- for(i=0; i<nNumSelected; i++)
- {
- if(!m_pPersonDB->GetRec(nRowId, data))
- {
- TRACE(_T("Error getting record %d\n"), nRowId);
- continue;
- }
- if(!data.IsDeleted())
- {
- data.m_deleted = 'Y';
- if(!m_pPersonDB->UpdateRec(nRowId, data))
- TRACE(_T("Error deleting record %d\n"), nRowId);
- }
- nRowId = m_selectedList.Next();
- }
-
- if(!m_personDB.Pack())
- MessageBox(_T("Error Packing Database"), _T("Error"));
-
- ResetNumRows(m_personDB.GetCount());
- RefreshData(); // Updates Current Row
- // RefreshScreen(VFR_BOTH); // Updates all rows except current
- return TRUE;
- }
-
- // -------------------------------------------------------------------------
- // Called when a row needs to be added to the data
- // -------------------------------------------------------------------------
- BOOL CPersonVF::OnAddRow(VRow *pRow)
- {
- CPersonRow *r = (CPersonRow*) pRow;
- int idx;
- CPerson data;
-
- idx = r->RowId();
-
- _tcscpy(data.m_name, r->m_name.Text());
- _tcscpy(data.m_phone, r->m_phone.Text());
- _tcscpy(data.m_address, r->m_address.Text());
- _tcscpy(data.m_city, r->m_city.Text());
- _tcscpy(data.m_state, r->m_state.Text());
- _tcscpy(data.m_zip, r->m_zip.Text());
- data.m_bFriend = r->m_chkFriend.Checked() ? 'Y' : 'N';
- data.m_deleted = 'N';
-
- if(!m_pPersonDB->AddRec(idx, data))
- return FALSE;
-
- return TRUE;
- }
-
- // -------------------------------------------------------------------------
- // Called when a row is initially being added
- // -------------------------------------------------------------------------
- void CPersonVF::OnStartAdd(VRow *pRow)
- {
- CString s1;
- CPersonRow *r = (CPersonRow*) pRow;
- long idx;
- // CPerson data;
-
- idx = r->RowId();
-
- s1.Format(_T("%ld"), idx+1);
- r->m_recno.SetWindowText(s1);
-
- r->m_name.SetWindowText(_T(""));
- r->m_phone.SetWindowText(_T(""));
- r->m_address.SetWindowText(_T(""));
- r->m_city.SetWindowText(_T(""));
- r->m_state.SetWindowText(_T(""));
- r->m_zip.SetWindowText(_T(""));
- r->m_chkFriend.Checked(FALSE);
- }
-
-
- // -------------------------------------------------------------------------
- // Called when a button is clicked
- // -------------------------------------------------------------------------
- void CPersonVF::OnClick(VRow *pRow, int nId)
- {
- CString s1, sBmpFile;
- BOOL bFlag;
- CPersonRow *pPersonRow = (CPersonRow*) pRow;
- static _TCHAR szFilter[] = _T("Bitmaps (*.bmp)|*.bmp|All Files (*.*)|*.*||");
-
- switch(nId)
- {
- case IDVC_CHK_SELECTORS:
- {
- CPersonHdr *pHdr = (CPersonHdr *)Header();
- if(pHdr->m_chkSelectors.Checked())
- UseSelectors(TRUE);
- else
- UseSelectors(FALSE);
- break;
- }
- case IDVC_SET_BMP:
- {
- CFileDialog dlg(TRUE, _T("bmp"), sBmpFile,
- OFN_SHAREAWARE | OFN_PATHMUSTEXIST, szFilter);
- if(dlg.DoModal() != IDOK)
- break;
-
- sBmpFile = dlg.GetPathName();
- if(SetBackBmp(sBmpFile) && m_nBackIdx == 4)
- {
- RefreshScreen(VFR_BOTH);
- }
- break;
- }
- case IDVC_CHK_TRANSPARENT:
- {
- CPersonHdr *pHdr = (CPersonHdr *)Header();
- bFlag = (pHdr->m_chkTransparent.Checked()) ? TRUE : FALSE;
- // Reset detail rows to this style
- pPersonRow = (CPersonRow *)m_pDtlRow;
- pPersonRow->SetTransparent(bFlag);
- pPersonRow = (CPersonRow *)m_pTmpRow;
- pPersonRow->SetTransparent(bFlag);
-
- RefreshScreen(VFR_BOTH);
- break;
- }
- case IDVC_RDO_INACTBORDER:
- {
- CPersonHdr *pHdr = (CPersonHdr *)Header();
- bFlag = (pHdr->m_rdoInactBorder.SelItem() == 0) ? FALSE: TRUE;
- pPersonRow = (CPersonRow *)m_pDtlRow;
- pPersonRow->SetNoInactBorder(bFlag);
- pPersonRow = (CPersonRow *)m_pTmpRow;
- pPersonRow->SetNoInactBorder(bFlag);
- RefreshScreen(VFR_BOTH);
- break;
- }
- case IDVC_TESTBUTTON:
- {
- AfxMessageBox(_T("Click on Test Button"), MB_OK | MB_ICONINFORMATION);
- break;
- }
- case IDVC_CHK_GRID_MODE:
- {
- CPersonFtr *pFtr = (CPersonFtr *)Footer();
- if(pFtr->m_chkGridMode.Checked())
- GridMode(TRUE);
- else
- GridMode(FALSE);
- break;
- }
- case IDVC_CHK_LIVE_RESIZING:
- {
- CPersonFtr *pFtr = (CPersonFtr *)Footer();
- if(pFtr->m_chkLiveResizing.Checked())
- LiveAdjust(TRUE);
- else
- LiveAdjust(FALSE);
- break;
- }
- case IDVC_CHK_SNAP_RESIZE:
- {
- CPersonFtr *pFtr = (CPersonFtr *)Footer();
- if(pFtr->m_chkSnapResize.Checked())
- SnapResize(TRUE);
- else
- SnapResize(FALSE);
- break;
- }
- }
- }
-
- // -------------------------------------------------------------------------
- // Called from OnLButtonDown
- // -------------------------------------------------------------------------
- BOOL CPersonVF::OnBeginDrag(long nRowId)
- {
- DROPEFFECT dEffect, retDEffect;
- CString s1;
- CPerson data;
-
- if(!m_pPersonDB->GetRec(nRowId, data)) return FALSE; // No drag started
-
- s1.Format(_T("Name: %s Phone: %s"), data.m_name, data.m_phone);
- dEffect = (::GetKeyState(VK_CONTROL) < 0) ? DROPEFFECT_COPY : DROPEFFECT_MOVE;
-
- retDEffect = VfuDoDragDrop(s1, dEffect);
-
- if(retDEffect == DROPEFFECT_NONE) return FALSE; // No drag started
-
- // Note: "Dropee" handles all operations
- if(retDEffect == DROPEFFECT_MOVE)
- {
- // ... Remove the row from this VForm
- }
- if(retDEffect == DROPEFFECT_COPY)
- {
- // ... Do whatever you want
- // AfxMessageBox("Got COPY Drop effect", "Notice");
- }
-
- return TRUE; // We did start a drag operation
- }
-
- // -------------------------------------------------------------------------
- // Called when something is dropped on us
- // -------------------------------------------------------------------------
- BOOL CPersonVF::OnDrop(long nRowId, COleDataObject* pDataObject,
- DROPEFFECT dropEffect)
- {
- CString sText, s1;
-
- if(!VfuGetDropText(pDataObject, sText))
- s1.Format(_T("You dropped on row %ld!"), nRowId);
- else
- s1.Format(_T("You dropped the following on row %ld!\n%s"),
- nRowId, (LPCTSTR) sText);
-
- AfxMessageBox(s1, MB_OK | MB_ICONINFORMATION);
-
- return FALSE; // We do not accept the drop
- }
-
-
- // -------------------------------------------------------------------------
- // Called when list is closed is clicked
- // -------------------------------------------------------------------------
- BOOL CPersonVF::OnEndList(VCtl* pCtl, CListBox* pLB)
- {
- CPersonRow *pRow;
- CPersonHdr *pHdr;
- int i;
- int nBgStyle = VROW_BG_DEFAULT;
-
- switch(pCtl->Id())
- {
- case IDVC_BG_OPTION:
- m_nBackIdx = pLB->GetCurSel();
-
- switch(m_nBackIdx)
- {
- case 0: nBgStyle = VROW_BG_DEFAULT; break;
- case 1: nBgStyle = VROW_BG_GREENBAR; break;
- case 2: nBgStyle = VROW_BG_PAPER; break;
- case 3: nBgStyle = VROW_BG_FLAT; break;
- case 4: nBgStyle = VROW_BG_BMP; break;
- }
-
- // Reset detail rows to this style
- pHdr = (CPersonHdr *)Header();
- pHdr->SetStyle(nBgStyle);
-
- pRow = (CPersonRow *)m_pDtlRow;
- pRow->SetBG(nBgStyle);
- pRow = (CPersonRow *)m_pTmpRow;
- pRow->SetBG(nBgStyle);
-
- RefreshScreen(VFR_BOTH);
- break;
- case IDVC_BOX_STYLE:
- i = pLB->GetCurSel();
-
- switch(i)
- {
- case 0: m_nEffect = VEFFECT_NORMAL; break;
- case 1: m_nEffect = VEFFECT_SHADOW; break;
- case 2: m_nEffect = VEFFECT_SUNKEN; break;
- case 3: m_nEffect = VEFFECT_RAISED; break;
- default: m_nEffect = VEFFECT_NORMAL; break;
- }
-
- // Reset detail rows to this style
- pRow = (CPersonRow *)m_pDtlRow;
- pRow->SetEffect(m_nEffect);
- pRow = (CPersonRow *)m_pTmpRow;
- pRow->SetEffect(m_nEffect);
-
- RefreshScreen(VFR_BOTH);
- break;
- case IDVC_LST_GRID_STYLE:
- i = pLB->GetCurSel();
- switch(i)
- {
- case 0: GridStyle(VFGRID_FLAT); break;
- case 1: GridStyle(VFGRID_NOLINES); break;
- case 2: GridStyle(VFGRID_SUNKEN); break;
- case 3: GridStyle(VFGRID_RAISED); break;
- case 4: GridStyle(VFGRID_VERTLINES); break;
- case 5: GridStyle(VFGRID_HORZLINES); break;
- case 6: GridStyle(VFGRID_ALTERNATING); break;
- default: GridStyle(VFGRID_FLAT); break;
- }
- if(GridMode()) RefreshScreen(VFR_BOTH);
- break;
- }
-
- return TRUE;
- }
-
- // -------------------------------------------------------------------------
- // Called when a button is clicked
- // -------------------------------------------------------------------------
- BOOL CPersonVF::OnGridRowColor(VRow *pRow, COLORREF &clrRow)
- {
- if(pRow->RowId() == 5)
- {
- clrRow = RGB(0, 255, 0);
- return TRUE;
- }
-
- return FALSE;
- }
-
- // -------------------------------------------------------------------------
- // Called when a row is double clicked
- // -------------------------------------------------------------------------
- BOOL CPersonVF::OnDblClkRow(long nRowId, UINT nFlags, CPoint point)
- {
- CString s1;
- s1.Format(_T("You double-clicked on row %ld"), nRowId);
- AfxMessageBox(s1);
- return TRUE;
- }
-
- BOOL CPersonVF::OnDblClkHeader(UINT nFlags, CPoint point)
- {
- AfxMessageBox(_T("You double-clicked the header"));
- return TRUE;
- }
- BOOL CPersonVF::OnDblClkDetail(UINT nFlags, CPoint point)
- {
- AfxMessageBox(_T("You double-clicked the detail section (not on a row)"));
- return TRUE;
- }
- BOOL CPersonVF::OnDblClkFooter(UINT nFlags, CPoint point)
- {
- AfxMessageBox(_T("You double-clicked the footer"));
- return TRUE;
- }
-
-
-
- // -------------------------------------------------------------------------
- // Start a timer for the form
- // -------------------------------------------------------------------------
- int CPersonVF::OnCreate(LPCREATESTRUCT lpCreateStruct)
- {
- if (VForm::OnCreate(lpCreateStruct) == -1)
- return -1;
-
- // m_nTimerId = SetTimer(ANIM_TIMER, 300, NULL);
- // if(m_nTimerId == 0)
- // {
- // TRACE(_T("CPersonVF::OnCreate - Unable to SetTimer\n"));
- // }
-
- return 0;
- }
-
-