home *** CD-ROM | disk | FTP | other *** search
- // dlgsamp2.cpp : implementation file
- //
-
- // This is a part of the Objective Grid C++ Library.
- // Copyright (C) 1995,1996 ClassWorks, Stefan Hoenig.
- // All rights reserved.
- //
- // This source code is only intended as a supplement to
- // the Objective Grid Classes Reference and related
- // electronic documentation provided with the library.
- // See these sources for detailed information regarding
- // the Objective Grid product.
- //
-
- #include "stdafx.h"
- #include "gridapp.h"
- #include "dlgsamp2.h"
-
- #ifndef _GXWND_H_
- #include "gxwnd.h"
- #endif
-
- #ifndef _GXCTRL_H_
- #include "gxctrl.h"
- #endif
-
- #ifdef _DEBUG
- #undef THIS_FILE
- static char BASED_CODE THIS_FILE[] = __FILE__;
- #endif
-
- #define new DEBUG_NEW
-
- /////////////////////////////////////////////////////////////////////////////
- // CSample2Dialog
- //
- // CSample1Dialog is based on the IDD_DLGSAMP2 dialog template.
- // I have dragged an user control into the dialog template and
- // set the control class to "CGXTabWnd".
- //
- // CGXTabWnd is a registered window class. Registration is
- // automatically done in CGridSampleApp::InitInstance which
- // calls the method GXRegisterClass().
- //
- // The macro GetTabWnd() returns a pointer to the tab window.
- // OnInitDialog creates several grid windows and attaches these
- // windows to the tabwindow.
- //
- // CSample2GridWnd is a derived grid control. It shows you
- // how to do custom cell validation.
- //
- // In DoDataExchange, I have added the line
- // DDV_GXTabWnd(pDX, GetTabWnd());
- // which enables control validation in the dialog.
-
- #define GetTabWnd() ((CGXTabWnd*) GetDlgItem(IDC_TABWND2))
-
- /////////////////////////////////////////////////////////////////////////////
- // CSample2GridWnd grid control
-
- // validation routine
-
- BOOL CSample2GridWnd::OnValidateCell(ROWCOL nRow, ROWCOL nCol)
- {
- CString s;
-
- // retrieve text from current cell
- CGXControl* pControl = GetControl(nRow, nCol);
- pControl->GetCurrentText(s);
-
- if (_ttol(s) < 0 || _ttol(s) > 100)
- {
- TCHAR sz[255];
- wsprintf(sz, _T("Please enter a value between 0 and 100!"));
-
- ScrollCellInView(nRow, nCol);
-
- // Display message box
- if (m_bLockActivateGrid)
- {
- AfxMessageBox(sz);
-
- // m_bWarningTextDisplayed is looked up in OnLButtonHitRowCol
- // if you set this TRUE, OnLButtonHitRowCol will cancel any further mouse processing
- m_bWarningTextDisplayed = TRUE;
-
- // If you want the current cell to be undone, call
- // TransferCurrentCell(FALSE);
-
- // This is only a sample. You might also display a message box
- // and ask the user if he wants to retry or ignore the value or
- // you could also call pControl->SetCurrentText() to change
- // the value.
- // pControl->SetCurrentText("22");
- }
-
- // else do nothing, the focus will go back to the current cell
-
- return FALSE;
- }
-
- return TRUE;
- }
-
- BEGIN_MESSAGE_MAP(CSample2GridWnd, CGXGridWnd)
- //{{AFX_MSG_MAP(CSample2GridWnd)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
-
- /////////////////////////////////////////////////////////////////////////////
- // CSample2Dialog dialog
-
- CSample2Dialog::CSample2Dialog(CWnd* pParent /*=NULL*/)
- : CDialog(CSample2Dialog::IDD, pParent)
- {
- //{{AFX_DATA_INIT(CSample2Dialog)
- m_nEdit = 0;
- m_nVal2 = 0;
- //}}AFX_DATA_INIT
- }
-
- void CSample2Dialog::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CSample2Dialog)
- DDX_Text(pDX, IDC_EDIT1, m_nEdit);
- DDV_MinMaxInt(pDX, m_nEdit, 0, 100);
- DDX_Text(pDX, IDC_EDIT2, m_nVal2);
- DDV_MinMaxInt(pDX, m_nVal2, 0, 100);
- //}}AFX_DATA_MAP
-
- // validation routine for CGXTabWnd controls
- DDV_GXTabWnd(pDX, GetTabWnd());
- }
-
- BEGIN_MESSAGE_MAP(CSample2Dialog, CDialog)
- //{{AFX_MSG_MAP(CSample2Dialog)
- ON_WM_NCACTIVATE()
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
-
-
- /////////////////////////////////////////////////////////////////////////////
- // CSample2Dialog message handlers
-
- BOOL CSample2Dialog::OnInitDialog()
- {
- CDialog::OnInitDialog();
-
- m_grid1.Create(0, CRect(0,0,1,1), GetTabWnd(), GetTabWnd()->GetNextID());
- m_grid2.Create(0, CRect(0,0,1,1), GetTabWnd(), GetTabWnd()->GetNextID());
- m_grid3.Create(0, CRect(0,0,1,1), GetTabWnd(), GetTabWnd()->GetNextID());
-
- GetTabWnd()->AttachWnd(&m_grid1, _T("Grid 1"));
- GetTabWnd()->AttachWnd(&m_grid2, _T("Grid 2"));
- GetTabWnd()->AttachWnd(&m_grid3, _T("Grid 3"));
-
- m_grid1.Initialize();
- m_grid2.Initialize();
- m_grid3.Initialize();
-
- m_grid1.SetRowCount(256);
- m_grid2.SetRowCount(256);
- m_grid3.SetRowCount(256);
-
- m_grid1.SetColCount(52);
- m_grid2.SetColCount(52);
- m_grid3.SetColCount(52);
-
- m_grid1.SetCurrentCell(1,1);
- m_grid2.SetCurrentCell(1,1);
- m_grid3.SetCurrentCell(1,1);
-
- GetTabWnd()->SetFocus();
-
- return FALSE; // return TRUE unless you set the focus to a control
- }
-
- BOOL CSample2Dialog::OnNcActivate(BOOL bActive)
- {
- if (CGXGridCombo::GetComboBoxDropDown())
- return TRUE;
-
- return CDialog::OnNcActivate(bActive);
- }
-