home *** CD-ROM | disk | FTP | other *** search
- // -------------------------------------------------------------------------
- // DynamicVF.cpp
- // -------------------------------------------------------------------------
-
- #include "stdafx.h"
- #include "DynamicVf.h"
- #include "resource.h"
- #include "VfbEx.h"
- #include "VfbLoad.h"
- #include "VfbExView.h"
-
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
-
-
- // -------------------------------------------------------------------------
- // TestData Constructor
- // -------------------------------------------------------------------------
- TestData::TestData()
- {
- }
-
- TestData& TestData::operator =(TestData &that)
- {
- // RemoveAll();
- m_fld.Copy(that.m_fld);
- return *this;
- }
-
- // -------------------------------------------------------------------------
- // Class DynamicVfDtl
- // -------------------------------------------------------------------------
- DynamicVfDtl::DynamicVfDtl()
- {
- }
-
- BEGIN_MESSAGE_MAP(DynamicVf, VForm)
- //{{AFX_MSG_MAP(DynamicVf)
- ON_WM_SIZE()
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
-
- // -------------------------------------------------------------------------
- // Class DynamicVf
- // -------------------------------------------------------------------------
- DynamicVf::DynamicVf()
- {
- m_nFldCnt = 0;
- m_bDropSource = FALSE;
-
- RowHeight(33);
- RowWidth(511);
- GridRowHeight(20);
- GridMode(FALSE);
-
- // Create header and add it to the VForm
- DynamicVfHdr *pHdr = new DynamicVfHdr();
- SetHeader(pHdr, FALSE);
-
- // Create detail rows NOW and add them to the VForm
- VRow *pDtlRow = new DynamicVfDtl();
- VRow *pTmpRow = new DynamicVfDtl();
- SetDetailRows(pDtlRow, pTmpRow, FALSE);
-
- // Create footer and add it to the VForm
- DynamicVfFtr *pFtr = new DynamicVfFtr();
- SetFooter(pFtr, FALSE);
-
- Font(VForm::GetFonts()->GetOrAdd(_T("Arial"),
- 100, FALSE, FALSE, FALSE));
- }
-
- // -------------------------------------------------------------------------
- // Function to create a DynamicVfDtl
- // -------------------------------------------------------------------------
- VRow* DynamicVf::InitRow()
- {
- // ----------- note - called from OnCreate ---------
- DynamicVfDtl *pRow = new DynamicVfDtl();
- return(pRow);
- }
-
-
- // -------------------------------------------------------------------------
- //
- // -------------------------------------------------------------------------
- BOOL DynamicVf::LoadVfbFile(LPCSTR szVfbFile)
- {
- BOOL rc;
- CVfBldrDoc myDoc;
-
- // Call base class implementation
- rc = VForm::LoadVfbFile(szVfbFile, &myDoc);
- m_bDropSource = myDoc.DropSource() ; // Set our DropSource flag
- return rc;
- }
-
- void DynamicVf::OnSize(UINT nType, int cx, int cy)
- {
- VForm::OnSize(nType, cx, cy);
-
- // This handles allowing for horz scroll size when dynamically
- // added by VForm (only on initial display if smaller than min size)
- CVfbExView* pView = (CVfbExView*) GetParent();
- pView->SetScrollByVForm();
- }
-
- // -------------------------------------------------------------------------
- //
- // -------------------------------------------------------------------------
- CPalette* DynamicVf::GetBackgroundPalette()
- {
- CPalette *pPal;
- VRow *pSection;
-
- pSection = DtlRow();
- if(pSection)
- {
- pPal = pSection->GetBackPalette();
- if(pPal) return pPal;
- }
-
- pSection = Header();
- if(pSection)
- {
- pPal = pSection->GetBackPalette();
- if(pPal) return pPal;
- }
-
- pSection = Footer();
- if(pSection)
- {
- pPal = pSection->GetBackPalette();
- if(pPal) return pPal;
- }
-
- return 0;
- }
-
-
- // -------------------------------------------------------------------------
- // Called when a row needs to be put on the screen
- // -------------------------------------------------------------------------
- BOOL DynamicVf::OnGetRow(VRow *pRow)
- {
- DynamicVfDtl *r = (DynamicVfDtl*)pRow;
- long idx = r->RowId();
- TestData *pData = &m_data[idx];
- int i, j;
- VCtl *pCtl;
-
- // Loop through fields - Get data for appropriate index
- j=0;
- for(i=0; i < r->CtlCount(); i++)
- {
- pCtl = r->GetCtlPtr(i);
- switch(pCtl->IsA())
- {
- case VCTL_EDIT: pCtl->Text(pData->m_fld[j++]); break;
- case VCTL_DROPDOWN: pCtl->Text(pData->m_fld[j++]); break;
- case VCTL_CHECKBOX:
- {
- VCheckBox *p = (VCheckBox *) pCtl;
- p->Checked(pData->m_fld[j++] == "Y");
- break;
- }
- case VCTL_RADIOLIST:
- {
- VRadioList *p = (VRadioList *) pCtl;
- int nItem = atoi(pData->m_fld[j++]);
- p->SelItem(nItem);
- break;
- }
- case VCTL_PICTCYCLE:
- {
- VPictCycle *p = (VPictCycle *) pCtl;
- int nIdx = atoi(pData->m_fld[j++]);
- p->Index(nIdx);
- break;
- }
- }
- }
-
- return TRUE; // Succesfully Gotten
- }
-
- // -------------------------------------------------------------------------
- // Called when a row needs to be saved (in the data)
- // -------------------------------------------------------------------------
- BOOL DynamicVf::OnSaveRow(VRow *pRow)
- {
- DynamicVfDtl *r = (DynamicVfDtl*)pRow;
- long idx = r->RowId();
- TestData *pData = &m_data[idx];
- int i, j;
- VCtl *pCtl;
- CString s1;
-
- // Loop through fields - Get data for appropriate index
- j=0;
- for(i=0; i < r->CtlCount(); i++)
- {
- pCtl = r->GetCtlPtr(i);
- switch(pCtl->IsA())
- {
- case VCTL_EDIT: pData->m_fld[j++] = pCtl->Text(); break;
- case VCTL_DROPDOWN: pData->m_fld[j++] = pCtl->Text(); break;
- case VCTL_CHECKBOX:
- {
- VCheckBox *p = (VCheckBox *) pCtl;
- pData->m_fld[j++] = p->Checked() ? "Y" : "N";
- break;
- }
- case VCTL_RADIOLIST:
- {
- VRadioList *p = (VRadioList *) pCtl;
- s1.Format("%d", p->SelItem());
- pData->m_fld[j++] = s1;
- break;
- }
- case VCTL_PICTCYCLE:
- {
- VPictCycle *p = (VPictCycle *) pCtl;
- s1.Format("%d", p->Index());
- pData->m_fld[j++] = s1;
- break;
- }
- }
- }
-
- return TRUE; // Succesfully Saved
- }
-
- // -------------------------------------------------------------------------
- //
- // -------------------------------------------------------------------------
- void DynamicVf::ResetFieldCount()
- {
- m_nFldCnt = CalcFieldCount(m_pDtlRow);
- }
-
- // -------------------------------------------------------------------------
- //
- // -------------------------------------------------------------------------
- int DynamicVf::CalcFieldCount(VRow *pRow)
- {
- int i, nCnt;
- VCtl *pCtl;
-
- // Loop through fields - Get data for appropriate index
- nCnt=0;
- for(i=0; i < pRow->CtlCount(); i++)
- {
- pCtl = pRow->GetCtlPtr(i);
- switch(pCtl->IsA())
- {
- case VCTL_EDIT:
- case VCTL_DROPDOWN:
- case VCTL_CHECKBOX:
- case VCTL_RADIOLIST:
- case VCTL_PICTCYCLE:
- nCnt++;
- break;
- }
- }
- return nCnt; // Succesfully Added
- }
-
-
- // -------------------------------------------------------------------------
- // Called when a row needs to added (to the data)
- // -------------------------------------------------------------------------
- BOOL DynamicVf::OnAddRow(VRow *pRow)
- {
- DynamicVfDtl *r = (DynamicVfDtl*)pRow;
- long idx = r->RowId();
- CString s1;
- TestData data;
- int i, j;
- VCtl *pCtl;
-
- m_data.SetAtGrow(idx, data);
- TestData *pData = &m_data[idx];
- pData->m_fld.SetSize(m_nFldCnt); // Grow the array to correct size
-
- // Loop through fields - Get data for appropriate index
- j=0;
- for(i=0; i < r->CtlCount(); i++)
- {
- pCtl = r->GetCtlPtr(i);
- switch(pCtl->IsA())
- {
- case VCTL_EDIT: pData->m_fld[j++] = pCtl->Text(); break;
- case VCTL_DROPDOWN: pData->m_fld[j++] = pCtl->Text(); break;
- case VCTL_CHECKBOX:
- {
- VCheckBox *p = (VCheckBox *) pCtl;
- pData->m_fld[j++] = p->Checked() ? "Y" : "N";
- break;
- }
- case VCTL_RADIOLIST:
- {
- VRadioList *p = (VRadioList *) pCtl;
- s1.Format("%d", p->SelItem());
- pData->m_fld[j++] = s1;
- break;
- }
- case VCTL_PICTCYCLE:
- {
- VPictCycle *p = (VPictCycle *) pCtl;
- s1.Format("%d", p->Index());
- pData->m_fld[j++] = s1;
- break;
- }
- }
- }
-
- return TRUE; // Succesfully Added
- }
-
- // -------------------------------------------------------------------------
- // OnStartAdd - Set default values for a new record/row
- // -------------------------------------------------------------------------
- void DynamicVf::OnStartAdd(VRow *pRow)
- {
- DynamicVfDtl *r = (DynamicVfDtl*)pRow;
- long idx = r->RowId();
- int i, j;
- VCtl *pCtl;
-
- // Loop through fields - Get data for appropriate index
- j=0;
- for(i=0; i < r->CtlCount(); i++)
- {
- pCtl = r->GetCtlPtr(i);
- switch(pCtl->IsA())
- {
- case VCTL_EDIT: pCtl->Text(""); break;
- case VCTL_DROPDOWN: pCtl->Text(""); break;
- case VCTL_CHECKBOX:
- {
- VCheckBox *p = (VCheckBox *) pCtl;
- p->Checked(FALSE);
- break;
- }
- case VCTL_RADIOLIST:
- {
- VRadioList *p = (VRadioList *) pCtl;
- p->SelItem(0);
- break;
- }
- case VCTL_PICTCYCLE:
- {
- VPictCycle *p = (VPictCycle *) pCtl;
- p->Index(0);
- break;
- }
- }
- }
- }
-
- // -------------------------------------------------------------------------
- // Called when row(s) needs to be deleted from the data
- // -------------------------------------------------------------------------
- BOOL DynamicVf::OnDelete()
- {
- CString s1;
- int rc, i;
- long nPriorCnt=0;
-
- long nNumSelected = m_selectedList.Count();
- long nRowId = m_selectedList.Last();
-
- s1.Format("You have selected to delete %ld rows", nNumSelected);
- s1 += "\nDo you wish to continue?";
- rc = AfxMessageBox(s1, MB_OKCANCEL | MB_ICONQUESTION);
- if(rc != IDOK)
- return TRUE; // We handled delete key
-
- for(i=0; i<nNumSelected; i++)
- {
- if(nRowId < CurRowId())
- nPriorCnt++; // Count prior rows deleted
- m_data.RemoveAt(nRowId); // Delete this row
- nRowId = m_selectedList.Prev(); // Get next row
- }
-
- // Reset our Row Count and move to appropriate new row
- // - by subtracting the number of rows deleted above us,
- // we stay on the same row.
- ResetNumRows(m_data.GetSize(), CurRowId() - nPriorCnt);
- return TRUE; // We handled delete key
- }
-
-
- // -------------------------------------------------------------------------
- // Called from OnLButtonDown
- // -------------------------------------------------------------------------
- BOOL DynamicVf::OnBeginDrag(long nRowId)
- {
- DROPEFFECT dEffect, retDEffect;
- CString s1;
-
- // Only begin drag if we are a drop source
- if(!m_bDropSource) return FALSE;
-
- s1.Format(_T("** VFB Example TEST DROP MSG **\r\n-- Dropped Row %ld --"), nRowId);
- dEffect = (::GetKeyState(VK_CONTROL) < 0) ? DROPEFFECT_COPY : DROPEFFECT_MOVE;
-
- retDEffect = VfuDoDragDrop(s1, dEffect);
-
- if(retDEffect == DROPEFFECT_NONE) return FALSE;
-
- return TRUE;
- }
-
- // -------------------------------------------------------------------------
- // Called when something is dropped on us
- // -------------------------------------------------------------------------
- BOOL DynamicVf::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\n%s"),
- nRowId, (LPCTSTR) sText);
-
- AfxMessageBox(s1, MB_OK | MB_ICONINFORMATION);
-
- return FALSE; // We do not accept the drop
- }
-
-
-