home *** CD-ROM | disk | FTP | other *** search
- // -------------------------------------------------------------------------
- // Copyright @ 1997 TCK Software, Incorporated
- // All Rights Reserved
- // -------------------------------------------------------------------------
-
- #include "stdafx.h"
- #include "testVF.h"
- #include "resource.h"
-
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
-
- #define ANIM_TIMER 101
-
- // Static Data Members
-
- // -------------------------------------------------------------------------
- // CTestHdr Constructor
- // -------------------------------------------------------------------------
- CTestHdr::CTestHdr()
- {
- 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("Normal"), 185,5,90,20);
- m_btnSetBmp.Init(this, IDVC_SET_BMP, _T("Set Bmp"), 290,5,80,20);
- m_nBackStyle = 0;
- m_chkSelectors.Checked(TRUE);
-
- 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"));
-
- AddCtl(&m_chkSelectors);
- AddCtl(&m_lblBackGround);
- AddCtl(&m_lstBgOption);
- AddCtl(&m_btnSetBmp);
- }
-
- // -------------------------------------------------------------------------
- // CTestFtr Constructor
- // -------------------------------------------------------------------------
- CTestFtr::CTestFtr()
- {
- Height(35);
-
- m_lblGoodbye.Init(this, -1, _T("Footer:"), 80,5,60,20);
- m_ftrEdit.Init(this, IDVC_FTREDIT, _T("Goodbye"), 150,5,100,20);
-
- m_ftrEdit.LimitText(20); // Set max chars for m_ftrEdit
-
- AddCtl(&m_lblGoodbye);
- AddCtl(&m_ftrEdit);
- }
-
-
- // -------------------------------------------------------------------------
- // CTestRow Constructor
- // -------------------------------------------------------------------------
- CTestRow::CTestRow(CTestVF* pForm)
- {
- m_lblSRow.Init(this, IDVC_LBLSROW, _T("lblSrow"), 10,5,60,20);
- m_testval.Init(this, IDVC_TESTVAL, _T("Hello"), 80,5,100,20);
- m_lstOption.Init(this, IDVC_OPTION, _T(""), 200,5,75,20);
- m_btn1.Init(this, IDVC_BTN1, _T("Push"), 280,5,60,20);
- m_check1.Init(this, IDVC_CHECK1, _T(""), 350,5,15,15);
- m_anim1.Init(this, IDVC_ANIM1, pForm->GetPrintAnimImg(), 380,5,16,16);
- m_anim1.Index(0); // Default Picture
- m_anim1.AnimIndex(1,6); // Animation Sequence
- // m_pictBtn1.Init(this, IDVC_PICTBTN1, pForm->GetTestImgList(), 430,5,16,16);
- // m_pictBtn1.DownIdx(1);
- m_pictCycle1.Init(this, IDVC_PICTCYCLE1, pForm->GetCycleImgList(), 410,5,16,16);
- m_pictCycle1.PictCount(5);
-
- m_testval.LimitText(25); // Set max chars for m_testval
- // m_testval.Set3D(FALSE); // Turn 3d off
- // m_testval.SetBorder(FALSE); // Turn Border off
- // m_check1.Set3D(FALSE); // Turn 3d off
-
- m_lstOption.AddString(_T("Option 1"));
- m_lstOption.AddString(_T("Option 2"));
- m_lstOption.AddString(_T("Option 3"));
- m_lstOption.AddString(_T("Option 4"));
- m_lstOption.AddString(_T("Option 5"));
- m_lstOption.AddString(_T("Option 6"));
-
- AddCtl(&m_lblSRow);
- AddCtl(&m_testval);
- AddCtl(&m_lstOption);
- AddCtl(&m_btn1);
- AddCtl(&m_check1);
- AddCtl(&m_anim1);
- // AddCtl(&m_pictBtn1);
- AddCtl(&m_pictCycle1);
-
- m_nBackStyle = 0;
- m_nSRowId = 0;
- }
-
- // -------------------------------------------------------------------------
- // GetBackBmp
- // -------------------------------------------------------------------------
- HBITMAP CTestRow::GetBackBmp()
- {
- return ((CTestVF*)Form())->GetBackBmp();
- }
-
- // -------------------------------------------------------------------------
- // GetBackPalette
- // -------------------------------------------------------------------------
- HPALETTE CTestRow::GetBackPaletteHandle()
- {
- return ((CTestVF*)Form())->GetBackPalette();
- }
-
-
- // -------------------------------------------------------------------------
- // CTestRow Destructor
- // -------------------------------------------------------------------------
- CTestRow::~CTestRow()
- {
- }
-
-
- // -------------------------------------------------------------------------
- // CPersonRow Background Drawing
- // -------------------------------------------------------------------------
- void CTestRow::SetBG(int nBackStyle)
- {
- SetStyle(nBackStyle);
-
- COLORREF clr = RGB(255,255,255);
- BOOL bTransparent = FALSE;
- BOOL bNoInactBorder = FALSE;
-
- if(nBackStyle == VROW_BG_FLAT) clr = RGB(192,192,192);
-
- ResetCtl(m_testval, bTransparent, bNoInactBorder, clr);
- ResetCtl(m_lstOption, bTransparent, bNoInactBorder, clr);
- }
-
-
- // IMPLEMENT_DYNCREATE(CTestVF, VForm)
-
- BEGIN_MESSAGE_MAP(CTestVF, VForm)
- //{{AFX_MSG_MAP(CTestVF)
- ON_WM_CREATE()
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
-
- // -------------------------------------------------------------------------
- // CTestVF Constructor
- // -------------------------------------------------------------------------
- CTestVF::CTestVF()
- {
- m_pFont = 0; // use default font
- m_pPalMH = 0;
- m_nBackIdx = 0;
- m_nRowHeight = 28;
- m_nRowWidth = 430;
- m_nRows = 400; // Start at 400
- m_nSRows = 0;
-
- // ------------- Header and footer with Something in them --------
- CTestHdr *pHdr = new CTestHdr();
- SetHeader(pHdr, FALSE);
- CTestFtr *pFtr = new CTestFtr();
- SetFooter(pFtr, FALSE);
-
- m_pFont = GetFonts()->GetOrAdd(_T("Arial"), 100);
-
- if(!m_imgList.Create(IDB_IMG_TEST, 16, 0, RGB(0,255,255)))
- TRACE(_T("CTestVF 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("CTestVF could not create cycle image list\n"));
- if(!m_imgPrintAnim.Create(IDB_IMG_PRINT_ANIM, 16, 0, RGB(0,255,255)))
- TRACE(_T("CTestVF could not create print animation image list\n"));
- }
-
- // -------------------------------------------------------------------------
- // CTestVF Destructor
- // -------------------------------------------------------------------------
- CTestVF::~CTestVF()
- {
- // if(m_hBmpBack) ::DeleteObject(m_hBmpBack);
- }
-
- BOOL CTestVF::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;
- /*
- LPVOID lpMsgBuf;
- DWORD dwError;
- CString s1;
- HBITMAP hBitmap=0;
-
- hBitmap = (HBITMAP)LoadImage(0, szFile, IMAGE_BITMAP,
- 0, 0, LR_LOADFROMFILE | LR_CREATEDIBSECTION | LR_DEFAULTSIZE);
-
- if(!hBitmap)
- {
- dwError = GetLastError();
-
- ::FormatMessage(
- FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
- NULL, dwError,
- MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
- (LPTSTR) &lpMsgBuf, 0, NULL);
-
- s1.Format(_T("Error loading bitmap:\n<%s>\n%s"), szFile, (LPTSTR)lpMsgBuf);
- LocalFree( lpMsgBuf );
-
- MessageBox(s1,_T("VForm Demo"), MB_OK | MB_ICONEXCLAMATION);
- return FALSE;
- }
-
- if(m_hBmpBack) ::DeleteObject(m_hBmpBack);
- m_hBmpBack = hBitmap;
-
- return TRUE;
- */
- }
-
-
- // -------------------------------------------------------------------------
- // Function to create a CTestRow
- // -------------------------------------------------------------------------
- VRow* CTestVF::InitRow()
- {
- CTestRow *pRow = new CTestRow(this);
- m_nSRows++; // One More Screen Row
- pRow->SRowId(m_nSRows);
- return(pRow);
- }
-
- // -------------------------------------------------------------------------
- // Called when a row needs to be put on the screen
- // -------------------------------------------------------------------------
- BOOL CTestVF::OnGetRow(VRow *pRow)
- {
- CString s1;
- CTestRow *r = (CTestRow*) pRow;
- long idx;
- CTestData *data;
-
- idx = r->RowId();
- data = &m_data[idx];
-
- // if(idx > 100 && idx < 200)
- // r->m_testval.Visible(FALSE);
- // else
- // r->m_testval.Visible(TRUE);
-
- // s1.Format(_T("%ld:%d"), r->RowId(), r->SRowId());
- s1.Format(_T("%ld"), r->RowId());
- r->m_lblSRow.SetWindowText(s1);
-
- r->m_testval.SetWindowText(data->m_name);
- r->m_lstOption.SetWindowText(data->m_option);
- r->m_check1.Checked(data->m_bCheck);
- r->m_pictCycle1.Index(data->m_nCycleOpt);
-
- return TRUE;
- }
-
- // -------------------------------------------------------------------------
- // Called when a row needs to be saved (in the data)
- // -------------------------------------------------------------------------
- BOOL CTestVF::OnSaveRow(VRow *pRow)
- {
- CTestRow *r = (CTestRow*) pRow;
- long idx;
- CTestData *data;
-
- idx = r->RowId();
- data = &m_data[idx];
-
- data->m_name = r->m_testval.Text();
- data->m_bCheck = r->m_check1.Checked();
- data->m_option = r->m_lstOption.Text();
- data->m_nCycleOpt = r->m_pictCycle1.Index();
-
- return TRUE;
- }
-
- // -------------------------------------------------------------------------
- // Called when row(s) needs to be deleted from the data
- // -------------------------------------------------------------------------
- BOOL CTestVF::OnDelete()
- {
- CString s1, s2;
- int i;
- // CTestRow *r = (CTestRow*) pRow;
-
- long nNumSelected = m_selectedList.Count();
- long nRowId = m_selectedList.First();
-
- s1.Format(_T("You have selected to delete %ld rows"), nNumSelected);
- for(i=0; i<nNumSelected; i++)
- {
- if(i > 9)
- {
- s1 += _T("\n too many to list...");
- break;
- }
- s2.Format(_T("\n %ld"), nRowId);
- s1 += s2;
- nRowId = m_selectedList.Next();
- }
- MessageBox(s1, _T("VForm Demo"));
-
- return TRUE;
- }
-
- // -------------------------------------------------------------------------
- // Called when a row needs to be added to the data
- // -------------------------------------------------------------------------
- BOOL CTestVF::OnAddRow(VRow *pRow)
- {
- CTestRow *r = (CTestRow*) pRow;
- CString s1;
-
- long idx = r->RowId();
- CTestData *data = &m_data[idx];
-
- data->m_name = r->m_testval.Text();
- data->m_bCheck = r->m_check1.Checked();
- data->m_option = r->m_lstOption.Text();
-
- s1.Format(_T("Successfully added record %ld"), idx);
- MessageBox(s1, _T("Wow"));
-
- return TRUE;
- }
-
- // -------------------------------------------------------------------------
- // Called when a row is initially being added
- // -------------------------------------------------------------------------
- void CTestVF::OnStartAdd(VRow *pRow)
- {
- CString s1;
- CTestRow *r = (CTestRow*) pRow;
- long idx = r->RowId();
- CTestData *data = &m_data[idx];
-
- s1.Format(_T("%ld:%d"), r->RowId(), r->SRowId());
- r->m_lblSRow.SetWindowText(s1);
-
- r->m_testval.SetWindowText(_T("New Record"));
- r->m_lstOption.SetWindowText(_T(""));
- r->m_check1.Checked(TRUE);
- r->m_pictCycle1.Index(0);
-
- // DrawRow(pRow, FALSE);
- }
-
-
- // -------------------------------------------------------------------------
- // Called when a button is clicked
- // -------------------------------------------------------------------------
- void CTestVF::OnClick(VRow *pRow, int nId)
- {
- CString s1, sBmpFile;
- CTestRow *r = (CTestRow*) pRow;
- static _TCHAR szFilter[] = _T("Bitmaps (*.bmp)|*.bmp|All Files (*.*)|*.*||");
-
- switch(nId)
- {
- case IDVC_CHK_SELECTORS:
- {
- CTestHdr *pHdr = (CTestHdr *)Header();
- if(pHdr->m_chkSelectors.Checked())
- UseSelectors(TRUE);
- else
- UseSelectors(FALSE);
- break;
- }
- case IDVC_BTN1:
- s1.Format(_T("Row %ld"), pRow->RowId());
- MessageBox(_T("You Clicked Me!"), s1, MB_OK);
- break;
- case IDVC_ANIM1:
- // s1.Format(_T("Row %ld"), pRow->RowId());
- // MessageBox(_T("You Clicked the Printer!"), s1, MB_OK);
- r->m_anim1.Animate(2); // Run animation sequence 2 times
- 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;
- }
- }
- }
-
-
- // -------------------------------------------------------------------------
- // Called when list is closed is clicked
- // -------------------------------------------------------------------------
- BOOL CTestVF::OnEndList(VCtl* pCtl, CListBox* pLB)
- {
- int nBgStyle=0;
- CTestRow *pRow;
- CTestHdr *pHdr;
-
- switch(pCtl->Id())
- {
- case IDVC_OPTION:
- break;
- 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 = (CTestHdr *)Header();
- pHdr->SetStyle(nBgStyle);
-
- pRow = (CTestRow *)m_pDtlRow;
- pRow->SetBG(nBgStyle);
- pRow = (CTestRow *)m_pTmpRow;
- pRow->SetBG(nBgStyle);
-
- RefreshScreen(VFR_BOTH);
- break;
- }
- return TRUE;
- }
-
-
-
- // -------------------------------------------------------------------------
- // Start a timer for the form
- // -------------------------------------------------------------------------
- int CTestVF::OnCreate(LPCREATESTRUCT lpCreateStruct)
- {
- if (VForm::OnCreate(lpCreateStruct) == -1)
- return -1;
-
- m_nTimerId = SetTimer(ANIM_TIMER, 300, NULL);
- if(m_nTimerId == 0)
- {
- TRACE(_T("CTestVF::OnCreate - Unable to SetTimer\n"));
- }
-
- return 0;
- }
-
-