home *** CD-ROM | disk | FTP | other *** search
- // formvw1.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 "formvw1.h"
-
- #include "gridsdoc.h"
-
- #ifndef _GXCTRL_H_
- #include "gxctrl.h"
- #endif
-
- #ifndef _GXPRPDLG_H_
- #include "gxprpdlg.h"
- #endif
-
- #ifndef _GXVW_H_
- #include "gxvw.h"
- #endif
-
-
- #ifdef _DEBUG
- #undef THIS_FILE
- static char BASED_CODE THIS_FILE[] = __FILE__;
- #endif
-
- /////////////////////////////////////////////////////////////////////////////
- // CSample1FormGridWnd grid control
-
- // validation routine
-
- BOOL CSample1FormGridWnd::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)
- {
- SetWarningText(_T("Please enter a value between 0 and 100!"));
- return FALSE;
- }
-
- return TRUE;
- }
-
- void CSample1FormGridWnd::OnInitialUpdate()
- {
- CGXGridWnd::OnInitialUpdate(); // Creates all objects and links them to the grid
-
- GetParam()->EnableUndo(FALSE);
-
- SetRowCount(256);
- SetColCount(52);
-
- SetStyleRange(CGXRange(2, 2), CGXStyle()
- .SetControl(GX_IDS_CTRL_TEXTFIT)
- .SetChoiceList(_T("one\ntwo\nthree\nfour\nfive\nsix\nseven\neight"))
- );
-
- GetParam()->EnableUndo(TRUE);
- }
-
- BEGIN_MESSAGE_MAP(CSample1FormGridWnd, CGXGridWnd)
- //{{AFX_MSG_MAP(CSample1FormGridWnd)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
-
- /////////////////////////////////////////////////////////////////////////////
- // CSample1FormView
-
- IMPLEMENT_DYNCREATE(CSample1FormView, CFormView)
-
- CSample1FormView::CSample1FormView()
- : CFormView(CSample1FormView::IDD)
- {
- //{{AFX_DATA_INIT(CSample1FormView)
- // NOTE: the ClassWizard will add member initialization here
- //}}AFX_DATA_INIT
- }
-
- CSample1FormView::~CSample1FormView()
- {
- }
-
- void CSample1FormView::DoDataExchange(CDataExchange* pDX)
- {
- CFormView::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CSample1FormView)
- // NOTE: the ClassWizard will add DDX and DDV calls here
- //}}AFX_DATA_MAP
-
- // validation routine for CGXGridWnd controls
- DDV_GXGridWnd(pDX, &m_wndGrid);
- }
-
-
- BEGIN_MESSAGE_MAP(CSample1FormView, CFormView)
- //{{AFX_MSG_MAP(CSample1FormView)
- ON_COMMAND(ID_FILE_HEADERFOOTER, OnFileHeaderfooter)
- ON_COMMAND(ID_FILE_PAGE_SETUP, OnFilePageSetup)
- ON_COMMAND(ID_VIEW_PROPERTIES, OnViewProperties)
- ON_COMMAND(ID_EDIT_FIND, OnEditFind)
- ON_COMMAND(ID_EDIT_REPLACE, OnEditReplace)
- ON_COMMAND(ID_EDIT_REPEAT, OnEditRepeat)
- //}}AFX_MSG_MAP
- ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
- ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
- END_MESSAGE_MAP()
-
-
-
- /////////////////////////////////////////////////////////////////////////////
- // CSample1FormView diagnostics
-
- #ifdef _DEBUG
- void CSample1FormView::AssertValid() const
- {
- CFormView::AssertValid();
- }
-
- void CSample1FormView::Dump(CDumpContext& dc) const
- {
- CFormView::Dump(dc);
- }
- #endif //_DEBUG
-
- /////////////////////////////////////////////////////////////////////////////
- // CSample1FormView message handlers
-
- //
- // Initialization of the grid
- //
-
- void CSample1FormView::OnInitialUpdate()
- {
- CFormView::OnInitialUpdate();
-
- m_wndGrid.SubclassDlgItem(IDC_FORMVW1_GRIDWND, this);
-
- m_wndGrid.Initialize();
-
- m_wndGrid.SetFocus();
- }
-
- // When a CFormView is deactivated, it stores a handle to the
- // control which did have the focus. This can cause problems
- // when the current cell of the CGXGridWnd was active and the
- // CFormView is reactivated. On Activation, CFormView passes
- // the focus directly to the current cell without notifying the
- // grid.
-
- // The following methods ensure that the CFormView stores a
- // handle to the parent grid window when the form view is
- // deactivated and the current cell was active.
-
- void CSample1FormView::OnActivateView(
- BOOL bActivate, CView* pActivateView, CView* pDeactiveView)
- {
- if (SaveFocusControl())
- return; // don't call base class when focus is already set
-
- // Note: I do call the CView base class member instead
- // of the CFormView member
- CView::OnActivateView(bActivate, pActivateView, pDeactiveView);
- }
-
- void CSample1FormView::OnActivateFrame(UINT nState, CFrameWnd* /*pFrameWnd*/)
- {
- if (nState == WA_INACTIVE)
- SaveFocusControl(); // save focus when frame loses activation
- }
-
- BOOL CSample1FormView::SaveFocusControl()
- {
- // save focus window if focus is on this window's controls
- HWND hWndFocus = ::GetFocus();
- if (hWndFocus != NULL && ::IsChild(m_hWnd, hWndFocus))
- {
- // if hWndFocus is a child of a CGXGridWnd, store
- // the handle for the parent grid window
-
- CWnd* pWnd = CWnd::FromHandle(hWndFocus);
- while (pWnd && !pWnd->IsKindOf(RUNTIME_CLASS(CGXGridWnd)))
- pWnd = pWnd->GetParent();
-
- if (pWnd)
- m_hWndFocus = pWnd->GetSafeHwnd();
- else
- m_hWndFocus = hWndFocus;
-
- return TRUE;
- }
- return FALSE;
- }
-
- //
- // Support for printing the grid
- //
-
- BOOL CSample1FormView::OnPreparePrinting(CPrintInfo* pInfo)
- {
- pInfo->SetMaxPage(0xffff);
-
- pInfo->m_pPD->m_pd.Flags &= ~PD_NOSELECTION;
- pInfo->m_pPD->m_pd.hInstance = AfxGetInstanceHandle();
-
- // default preparation
- return DoPreparePrinting(pInfo);
- }
-
- void CSample1FormView::OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo)
- {
- m_wndGrid.OnBeginPrinting(pDC, pInfo);
- }
-
- void CSample1FormView::OnEndPrinting(CDC* pDC, CPrintInfo* pInfo)
- {
- m_wndGrid.OnEndPrinting(pDC, pInfo);
- }
-
- void CSample1FormView::OnPrint(CDC* pDC, CPrintInfo* pInfo)
- {
- m_wndGrid.OnPrint(pDC, pInfo);
- }
-
-
- void CSample1FormView::OnPrepareDC(CDC* pDC, CPrintInfo* pInfo /* = NULL */)
- {
- if (pInfo)
- {
- // Adjust printer DC
- pDC->SetMapMode(MM_ANISOTROPIC);
- pDC->SetWindowExt(GXGetFontState()->m_nLogPixelsX, GXGetFontState()->m_nLogPixelsY);
-
- int nlogx = pDC->GetDeviceCaps(LOGPIXELSX);
- int nlogy = pDC->GetDeviceCaps(LOGPIXELSY);
-
- pDC->SetViewportExt(nlogx, nlogy);
-
- // Mapping: 72 pixels/unit (like MM_TEXT)
- }
- }
-
- /////////////////////////////////////////////////////////////////////////////
- // View menu handlers
-
- void CSample1FormView::OnViewProperties()
- {
- BOOL bSaveDefault = FALSE;
-
- CGXProperties* pPropertyObj = m_wndGrid.GetParam()->GetProperties();
- ASSERT(pPropertyObj->IsKindOf(RUNTIME_CLASS(CGXProperties)));
-
- CGXProperties* pNewSettings = new CGXProperties;
- *pNewSettings = *pPropertyObj;
-
- CGXDisplayPropertiesDialog dlg(pNewSettings, m_wndGrid.GetParam()->GetStylesMap(), &bSaveDefault, FALSE);
-
- int result = dlg.DoModal();
- if (result == IDOK)
- {
- *pPropertyObj = *pNewSettings;
- if (bSaveDefault)
- pPropertyObj->WriteProfile();
-
- // SetModifiedFlag();
- m_wndGrid.Redraw();
- }
-
- delete pNewSettings;
- }
-
- /////////////////////////////////////////////////////////////////////////////
- // File menu handlers
-
- void CSample1FormView::OnFilePageSetup()
- {
- BOOL bSaveDefault = FALSE;
-
- CGXProperties* pPropertyObj = m_wndGrid.GetParam()->GetProperties();
- ASSERT(pPropertyObj->IsKindOf(RUNTIME_CLASS(CGXProperties)));
-
- CGXProperties* pNewSettings = new CGXProperties;
- *pNewSettings = *pPropertyObj;
-
- CGXPrintPropertiesDialog dlg(pNewSettings, m_wndGrid.GetParam()->GetStylesMap(), &bSaveDefault, FALSE);
-
- int result = dlg.DoModal();
- if (result == IDOK)
- {
- *pPropertyObj = *pNewSettings;
- if (bSaveDefault)
- pPropertyObj->WriteProfile();
-
- // SetModifiedFlag();
- }
-
- delete pNewSettings;
- }
-
- void CSample1FormView::OnFileHeaderfooter()
- {
- BOOL bSaveDefault = FALSE;
-
- CGXProperties* pPropertyObj = m_wndGrid.GetParam()->GetProperties();
- ASSERT(pPropertyObj->IsKindOf(RUNTIME_CLASS(CGXProperties)));
-
- CGXProperties* pNewSettings = new CGXProperties;
- *pNewSettings = *pPropertyObj;
-
- CGXHeaderFooterDialog dlg(pNewSettings, &bSaveDefault);
-
- int result = dlg.DoModal();
- if (result == IDOK)
- {
- *pPropertyObj = *pNewSettings;
- if (bSaveDefault)
- pPropertyObj->WriteProfile();
-
- // SetModifiedFlag();
- }
-
- delete pNewSettings;
- }
-
- /////////////////////////////////////////////////////////////////////////////
- // Edit menu handlers
-
- void CSample1FormView::OnEditFind()
- {
- m_wndGrid.OnShowFindReplaceDialog(TRUE);
- }
-
- void CSample1FormView::OnEditReplace()
- {
- m_wndGrid.OnShowFindReplaceDialog(FALSE);
- }
-
- void CSample1FormView::OnEditRepeat()
- {
- if (!m_wndGrid.FindText())
- m_wndGrid.OnTextNotFound(GXGetLastFRState()->strFind);
- }
-
-