home *** CD-ROM | disk | FTP | other *** search
- // gridsvw5.cpp : implementation of the CGridSample5View class
- //
-
- // 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 "gridsdoc.h"
- #include "gridsvw5.h"
- #include "dlguser.h"
- #include "mainfrm.h"
- #include "gridfrms.h"
-
- #include "gxtwnd.h"
-
-
- #ifdef _DEBUG
- #undef THIS_FILE
- static char BASED_CODE THIS_FILE[] = __FILE__;
- #endif
-
- //
- // CGridSample5View can be used as standalone, splitter or worksheet gridview
- // as you have already seen with CGridSampleView
- //
- // CGridSample5View illustrates applying controls to cells or deriving
- // and registerφng your own controls. It also illustrates how to
- // use comboboxes in column headers.
- //
- // CSimpleButton provides a button control you can use a prototype
- // for creating your own controls.
- //
- // CBitmapBtnEdit provides a sample how to use small buttons in a control
- //
- // CArrowRowHeader is a control you can apply to ro headers. It will
- // display an arrow if the row owns the current cell.
- //
-
- IMPLEMENT_DYNCREATE(CGridSample5View, CMyGridView)
- IMPLEMENT_CONTROL(CSimpleButton, CGXStatic)
- IMPLEMENT_CONTROL(CBitmapBtnEdit, CGXEditControl)
- IMPLEMENT_CONTROL(CArrowRowHeader, CGXControl)
- IMPLEMENT_CONTROL(COwnerDrawnComboBox, CGXComboBoxWnd)
- IMPLEMENT_CONTROL(CMyComboBox, CGXComboBox)
-
- static TCHAR BASED_CODE szInstruct[] =
- _T("This view shows standard and user defined controls and special headers. ")
- _T("You can apply controls to cells by calling Format->Cells->Control ")
- _T("or by changing the Control setting of a base style (Format->Styles).");
-
- #define new DEBUG_NEW
-
- /////////////////////////////////////////////////////////////////////////////
- // CSimpleButton control
-
- CSimpleButton::CSimpleButton(CGXGridCore* pGrid)
- : CGXStatic(pGrid)
- {
- m_bPressed = FALSE;
- }
-
- CSimpleButton::~CSimpleButton()
- {
- }
-
- void CSimpleButton::Draw(CDC* pDC, CRect rect, ROWCOL nRow, ROWCOL nCol, const CGXStyle& style, const CGXStyle* pStandardStyle)
- {
- WORD nState = 0;
-
- // Select font
- CFont* pOldFont = LoadFont(pDC, style, pStandardStyle);
-
- BOOL bActive = (m_nRow == nRow && m_nCol == nCol && !Grid()->IsPrinting()
- && Grid()->IsActiveFrame());
-
- if (bActive)
- {
- nState |= GX_BTNFOCUS;
-
- if (m_bPressed)
- nState |= GX_BTNPRESSED;
- }
-
-
- // start of drawing buttons technique 1 ->
-
- CRect rectText = GetCellRect(nRow, nCol, rect);
-
- // Background
- DrawBackground(pDC, rect, style);
-
- // Draw pressed or button look
- CRect r = CGXControl::GetCellRect(nRow, nCol, rect);
-
- if (nState & GX_BTNPRESSED)
- GXDrawEdge(pDC, r, BDR_SUNKENOUTER | BDR_SUNKENINNER);
- else
- GXDrawEdge(pDC, r, BDR_RAISEDOUTER | BDR_RAISEDINNER);
-
- // button text
- CRect faceRect(r.left+1, r.top+1, r.right-2, r.bottom-2);
- if (nState & GX_BTNPRESSED)
- faceRect += CPoint(1,1);
-
- // Draw static text
- pDC->SetBkMode(TRANSPARENT);
- pDC->SetTextColor(style.GetTextColor());
-
- CString sOutput;
- if (GetControlText(sOutput, nRow, nCol, NULL, style))
- GXDrawFocusText(pDC, faceRect, nState&GX_BTNFOCUS, sOutput);
-
- // <- end of technique 1
-
- /*
- // start of drawing buttons technique 2 ->
-
- DrawBackground(pDC, rect, style);
-
- GXDrawPushButton(pDC,
- rect.left, rect.top,
- rect.Width(), rect.Height(),
- w,
- style.GetValueRef());
-
- // <- end of technique 2
- */
-
- if (pOldFont)
- pDC->SelectObject(pOldFont);
- }
-
- BOOL CSimpleButton::LButtonDown(UINT nFlags, CPoint pt, UINT nHitState)
- {
- m_bMouseDown = TRUE;
- m_bPressed = TRUE;
- Refresh();
-
- // unreferenced:
- nFlags, pt, nHitState;
-
- return TRUE;
- }
-
- BOOL CSimpleButton::RButtonDown(UINT nFlags, CPoint pt, UINT nHitState)
- {
- m_bMouseDown = TRUE;
- m_bPressed = TRUE;
- Refresh();
-
- // unreferenced:
- nFlags, pt, nHitState;
-
- return TRUE;
- }
-
- BOOL CSimpleButton::LButtonUp(UINT nFlags, CPoint pt, UINT nHitState)
- {
- nFlags, pt;
-
- CRect rect = CGXControl::GetCellRect(m_nRow, m_nCol);
-
- if (m_bMouseDown && m_bPressed && rect.PtInRect(pt))
- OnClickedButton(NULL);
-
- m_bPressed = FALSE;
- m_bMouseDown = FALSE;
- Refresh();
-
- // unreferenced:
- nFlags, pt, nHitState;
-
- return TRUE;
- }
-
- BOOL CSimpleButton::RButtonUp(UINT nFlags, CPoint pt, UINT nHitState)
- {
- nFlags, pt;
-
- CRect rect = CGXControl::GetCellRect(m_nRow, m_nCol);
-
- if (m_bMouseDown && m_bPressed && rect.PtInRect(pt))
- AfxMessageBox(_T("Right button clicked!\n"));
-
- m_bPressed = FALSE;
- m_bMouseDown = FALSE;
- Refresh();
-
- // unreferenced:
- nFlags, pt, nHitState;
-
- return TRUE;
- }
-
- BOOL CSimpleButton::MouseMove(UINT nFlags, CPoint pt, UINT nHitState)
- {
- nFlags, pt;
-
- CRect rect = CGXControl::GetCellRect(m_nRow, m_nCol);
-
- BOOL bState = rect.PtInRect(pt);
-
- if (m_bMouseDown && bState != m_bPressed)
- {
- m_bPressed = bState;
- Refresh();
- }
-
- // unreferenced:
- nFlags, pt, nHitState;
-
- return TRUE;
- }
-
- BOOL CSimpleButton::KeyPressed(UINT nMessage, UINT nChar, UINT nRepCnt, UINT flags)
- {
- BOOL bRet = CGXControl::KeyPressed(nMessage, nChar, nRepCnt, flags);
-
- if (nChar == 32 && nMessage == WM_KEYDOWN)
- {
- // Draw pressed
- m_bPressed = TRUE;
- Refresh();
- return TRUE;
- }
- else if (nChar == 32 && nMessage == WM_KEYUP && m_bPressed)
- {
- // trigger event
- OnClickedButton(NULL);
-
- // Draw normal
- m_bPressed = FALSE;
- Refresh();
- return TRUE;
- }
-
- return bRet;
- }
-
- void CSimpleButton::InvertBorders(CDC* pDC, const CRect& r)
- {
- // I don't want an inverted frame
-
- // unreferenced:
- pDC, r;
- }
-
- void CSimpleButton::OnClickedButton(CGXChild* pChild)
- {
- // Unreferenced parameters:
- pChild;
-
- // display a message box with the text specified in
- // the user attribut "MessageText" (see the style-sheet)
-
- AfxMessageBox(Grid()->LookupStyleRowCol(m_nRow, m_nCol)
- .GetUserAttribute(IDS_ATTR_MSGTEXT));
- }
-
- /////////////////////////////////////////////////////////////////////////////
- // CBitmapBtnEdit control
-
- CBitmapBtnEdit::CBitmapBtnEdit(CGXGridCore* pGrid, UINT nID)
- : CGXEditControl(pGrid, nID)
- {
- // Use CGXDIBitmapButton instead of CGXBitmapButton
- AddChild(m_pButton = new CGXDIBitmapButtonChild(this));
- VERIFY(m_pButton->LoadBitmaps(IDB_BITMAP1));
-
- m_sizeBtn = CSize(14,14);
- }
-
- BEGIN_MESSAGE_MAP(CBitmapBtnEdit, CGXEditControl)
- //{{AFX_MSG_MAP(CBitmapBtnEdit)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
-
- CRect CBitmapBtnEdit::GetCellRect(ROWCOL nRow, ROWCOL nCol, LPRECT rectItem /* = NULL */, const CGXStyle* pStyle /*= NULL*/)
- {
- // compute the interior rectangle for the text
- // without buttons and borders
-
- CRect rect = CGXEditControl::GetCellRect(nRow, nCol, rectItem, pStyle);
-
- rect.left += m_sizeBtn.cx+3;
-
- return rect;
- }
-
- void CBitmapBtnEdit::OnInitChilds(ROWCOL nRow, ROWCOL nCol, const CRect& rect)
- {
- nRow, nCol;
-
- int nTop = (max(0, rect.Height() - m_sizeBtn.cy)) / 2;
-
- // init BitmapBtn button
- CRect rectBtn;
- rectBtn.IntersectRect(rect,
- CRect(rect.left+3,
- rect.top + nTop,
- rect.left+3+m_sizeBtn.cx,
- rect.top+ nTop + m_sizeBtn.cy)
- );
-
- m_pButton->SetRect(rectBtn);
- }
-
- void CBitmapBtnEdit::OnClickedButton(CGXChild* pChild)
- {
- pChild;
- AfxMessageBox(_T("You pressed the bitmap"));
- };
-
- BOOL CBitmapBtnEdit::OnValidate()
- {
- CString s;
- GetWindowText(s);
- if (_ttoi(s) > 100)
- {
- Grid()->SetWarningText(_T("Values greater 100 are invalid!"));
- return FALSE;
- }
- return TRUE;
- }
-
-
- /////////////////////////////////////////////////////////////////////////////
- // CArrowRowHeader
-
- CArrowRowHeader::CArrowRowHeader(CGXGridCore* pGrid)
- : CGXControl(pGrid)
- {
- }
-
- void CArrowRowHeader::Draw(CDC* pDC, CRect rect, ROWCOL nRow, ROWCOL nCol, const CGXStyle& style, const CGXStyle* pStandardStyle)
- {
- // no arrow needed when printing
- if (Grid()->IsPrinting())
- return;
-
- // Cell-Color
- COLORREF rgbText = style.GetTextColor();
- COLORREF rgbCell = style.GetInteriorRef().GetColor();
-
- BOOL bArrow = nRow > 0 && Grid()->IsCurrentCell(nRow);
-
- GXDrawButton(pDC, rect.left, rect.top,
- rect.Width(), rect.Height(), FALSE, rgbCell);
-
- const int nSize = 9;
-
- if (bArrow && rect.Width() > nSize && rect.Height() > nSize)
- {
- int x = rect.left + (rect.Width() - nSize) / 2;
- int y = rect.top + (rect.Height() - nSize) / 2;
-
- GXPatB(pDC, x++, y++, 1, 9, rgbText);
- GXPatB(pDC, x++, y++, 1, 7, rgbText);
- GXPatB(pDC, x++, y++, 1, 5, rgbText);
- GXPatB(pDC, x++, y++, 1, 3, rgbText);
- GXPatB(pDC, x++, y++, 1, 1, rgbText);
- }
-
- CGXControl::Draw(pDC, rect, nRow, nCol, style, pStandardStyle);
- }
-
- /////////////////////////////////////////////////////////////////////////////
- // CMyComboBox control
-
- CMyComboBox::CMyComboBox(CGXGridCore* pGrid, UINT nEditID, UINT nListBoxID, UINT nFlags)
- : CGXComboBox(pGrid, nEditID, nListBoxID, nFlags)
- {
- }
-
- void CMyComboBox::Init(ROWCOL nRow, ROWCOL nCol)
- {
- CGXComboBox::Init(nRow, nCol);
- }
-
- BOOL CMyComboBox::OnCommand(WPARAM wParam, LPARAM lParam)
- {
- #if _MFC_VER < 0x0300
- UINT nNotification = HIWORD(lParam);
- HWND hCtl = (HWND) LOWORD(lParam);
- #else
- UINT nNotification = HIWORD(wParam);
- HWND hCtl = (HWND) lParam;
- #endif
-
- if (hCtl == m_hWnd)
- {
- // Edit Control changed
- }
- else if (GetDroppedState())
- {
- // Listbox changed
- if (nNotification == LBN_SELCHANGE)
- TRACE0("Listbox changed\n" );
- else
- TRACE1("Listbox notification %d\n", nNotification );
- }
-
- return CGXComboBox::OnCommand(wParam, lParam);
- }
-
- /////////////////////////////////////////////////////////////////////////////
- // COwnerDrawnComboBox
-
- static COLORREF VGAColorsArray[20] = {
- RGB(0,0,0), // Black
- RGB(0,0,255), // Bright blue
- RGB(0,255,0), // Bright green
- RGB(0,255,255), // Cyan
- RGB(255,0,0), // Bright red
- RGB(255,0,255), // Magenta
- RGB(255,255,0), // Bright yellow
- RGB(255,255,255), // White
- RGB(0,0,128), // Dark blue
- RGB(0,128,0), // Dark green
- RGB(0,128,128), // Blue-green
- RGB(128,0,0), // Brown
- RGB(128,0,128), // Dark purple
- RGB(128,128,0), // Olive
- RGB(128,128,128), // Dark gray
- RGB(192,192,192), // Light gray
- RGB(192,220,192), // Pale green
- RGB(166,202,240), // Light blue
- RGB(255,251,240), // Off-white
- RGB(160,160,164), // Medium gray
- };
-
- COwnerDrawnComboBox::COwnerDrawnComboBox(CGXGridCore* pGrid)
- : CGXComboBoxWnd(pGrid)
- {
- m_bFillWithChoiceList = FALSE; // must be FALSE for ownderdrawn combobox
- m_bWantArrowKeys = FALSE; // pass arrow keys to Grid
- m_nIndexValue = 0; // 0 = Item 0, 1 = Item 1, ... n = Item N
-
- m_bSizeToContent = TRUE;
- // set m_nIndexValue = 1 if you want to have 1 = Item 0, 2 = Item 1, ... n = Item N+1
- }
-
- COwnerDrawnComboBox::~COwnerDrawnComboBox()
- {
- }
-
- void COwnerDrawnComboBox::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
- {
- CRect rc = lpDrawItemStruct->rcItem;
- COLORREF rgbColor = lpDrawItemStruct->itemData;
- CDC* pDC = CDC::FromHandle(lpDrawItemStruct->hDC);
-
- GXPatB(pDC, rc, rgbColor);
-
- if (lpDrawItemStruct->itemState & ODS_SELECTED)
- {
- CBrush br;
- br.CreateStockObject(BLACK_BRUSH);
- pDC->FrameRect(CRect(rc.left, rc.top, rc.right, rc.bottom), &br);
- }
- }
-
- void COwnerDrawnComboBox::MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct)
- {
- lpMeasureItemStruct->itemHeight = 20;
- }
-
- BEGIN_MESSAGE_MAP(COwnerDrawnComboBox, CGXComboBoxWnd)
- //{{AFX_MSG_MAP(COwnerDrawnComboBox)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
-
- BOOL COwnerDrawnComboBox::OnCommand(WPARAM wParam, LPARAM lParam)
- {
- #if _MFC_VER < 0x0300
- UINT nNotification = HIWORD(lParam);
- HWND hCtl = (HWND) LOWORD(lParam);
- #else
- UINT nNotification = HIWORD(wParam);
- HWND hCtl = (HWND) lParam;
- #endif
-
- if (hCtl == m_hWnd) // is it really this wnd?
- {
- if (nNotification == CBN_SELCHANGE
- || nNotification == CBN_EDITCHANGE)
- {
- TRACE0("Combobox changed\n");
- }
- }
-
- return CGXComboBoxWnd::OnCommand(wParam, lParam);
- }
-
- /////////////////////////////////////////////////////////////////////////////
- // CGridSample5View
-
- BEGIN_MESSAGE_MAP(CGridSample5View, CMyGridView)
- //{{AFX_MSG_MAP(CGridSample5View)
- ON_COMMAND(ID_VIEW_USERACTIONS, OnViewUseractions)
- ON_COMMAND(ID_VIEW_SPLITTERVIEW, OnViewSplitterview)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
-
- /////////////////////////////////////////////////////////////////////////////
- // CGridSample5View construction/destruction
-
- CGridSample5View::CGridSample5View()
- {
- // TODO: add construction code here
- }
-
- CGridSample5View::~CGridSample5View()
- {
- }
-
- BOOL CGridSample5View::ConnectParam()
- {
- // Note: this method is copied from CGridSampleView
- //
-
- BOOL bNew = FALSE;
-
- // Retrive the zero-based worksheet-id if used as worksheet
- if (GetParentTabWnd(this, TRUE))
- m_nViewID = GetParentTabViewID(this);
-
- // check if it is a new pane in a splitter window
- CSplitterWnd* pSplitterWnd = GetParentDynamicSplitter(this, TRUE);
- if (pSplitterWnd != NULL)
- {
- CGXGridView *pView = (CGXGridView *) pSplitterWnd->GetPane(0, 0);
- if (pView != this)
- m_nViewID = pView->GetViewID();
- }
-
- // check if parameter-object exist (in document)
- if (GetDocument()->GetParam(m_nViewID) == NULL)
- {
- // create a parameter-object on the heap
- GetDocument()->SetParam(m_nViewID, new CGXGridParam);
-
- bNew = TRUE; // this view needs initializing
- }
-
- // connect parameter-object with grid
- SetParam((CGXGridParam*) GetDocument()->GetParam(m_nViewID), FALSE);
-
- return bNew;
- }
-
- void CGridSample5View::SetupControls()
- {
- // Register all controls for the view
-
- // First, the simple control
- RegisterControl(IDS_CTRL_SIMPLE, new CSimpleButton(this));
-
- // With its MsgText to display when the button is pressed
- GetParam()->GetStylesMap()->AddUserAttribute(IDS_ATTR_MSGTEXT);
- // the Message Text is specified in OnInitialUpdate!
-
- // In OnInitialUpdate, I do set the default value for this attribute
- // by calling style->SetUserAttribute(IDS_ATTR_MSGTEXT, _T("You pressed the button"));
-
- RegisterControl(IDS_CTRL_EDITBTN, new CBitmapBtnEdit(this, IDS_CTRL_EDITBTN));
-
- RegisterControl(IDS_CTRL_ARROWHEADER, new CArrowRowHeader(this));
-
- RegisterControl(GX_IDS_CTRL_COMBOBOX, new CMyComboBox(this, 2001, 2002, 0));
-
- // CGXWndWrapper allows you to register any CWnd you want.
- CGXTabBeam* pBeam = new CGXTabBeam;
- pBeam->Create(WS_CHILD | WS_CLIPSIBLINGS, CRect(0,0,0,0), this, IDS_CTRL_TABBEAM);
- pBeam->InsertTab(FALSE, _T("Tab 1"));
- pBeam->InsertTab(FALSE, _T("Tab 2"));
- pBeam->InsertTab(FALSE, _T("Tab 3"));
- pBeam->AdjustTabSize(0);
- pBeam->AdjustTabSize(1);
- pBeam->AdjustTabSize(2);
- pBeam->DisplayScrollBtns(FALSE);
- RegisterControl(IDS_CTRL_TABBEAM, new CGXWndWrapper(this, pBeam, TRUE, TRUE, TRUE));
-
- // ownerdrawn CComboBox with CBS_DROPDOWNLIST style
- {
- CGXComboBoxWnd* pWnd = new COwnerDrawnComboBox(this);
- pWnd->Create(WS_VSCROLL | CBS_DROPDOWNLIST | CBS_OWNERDRAWFIXED, IDS_CTRL_OWNERDRAWNDROPDOWN);
- RegisterControl(IDS_CTRL_OWNERDRAWNDROPDOWN, pWnd);
-
- for (int n = 0; n < 20; n++)
- pWnd->AddString((LPCTSTR) VGAColorsArray[n]);
- }
- }
-
- /////////////////////////////////////////////////////////////////////////////
- // CGridSample5View drawing
-
- void CGridSample5View::OnInitialUpdate()
- {
- BOOL bNew = ConnectParam();
-
- CMyGridView::OnInitialUpdate(); // Creates all objects and links them to the grid
-
- // Register all controls for the view
- SetupControls();
-
- if (bNew)
- {
- // Don't create undo-information for the following commands
- GetParam()->EnableUndo(FALSE);
- // (at the end of this procedure, I will reenable it)
-
- // Apply Arrow-Header-Control to Row-Header-Style
- RowHeaderStyle()
- .SetControl(IDS_CTRL_ARROWHEADER)
- .SetEnabled(FALSE); // disables usage as current cell
-
- // Apply Dropdown-List-Control to Column-Header-Style
- ColHeaderStyle()
- .SetControl(GX_IDS_CTRL_CBS_DROPDOWNLIST)
- .SetInterior(GXSYSCOLOR(COLOR_BTNFACE))
- .SetHorizontalAlignment(DT_CENTER)
- .SetWrapText(FALSE)
- .SetVerticalAlignment(DT_VCENTER)
- .SetFont(CGXFont().SetBold(TRUE))
- .SetChoiceList(_T("Combo Box\none\ntwo\nthree\nfour\nfive\nsix\nseven\neight"))
- .SetValue(_T("Combo Box"))
- .SetDraw3dFrame(gxFrameRaised);
-
- SetRowHeight(0, 0, 30);
-
- // Cell (0,0) is treated like a normal column header
- // So, I do need to reset the style for the cell explicitly.
- SetStyleRange(CGXRange(0,0), CGXStyle()
- .SetControl(GX_IDS_CTRL_HEADER)
- .SetEnabled(FALSE) // disables usage as current cell
- .SetValue(_T(""))
- );
-
- // Turn off selecting whole columns when clicking on a column header
- GetParam()->EnableSelection((WORD) (GX_SELFULL & ~GX_SELCOL & ~GX_SELTABLE));
-
-
- // Apply default message text for simple control to standard style
- StandardStyle()
- .SetUserAttribute(IDS_ATTR_MSGTEXT, _T("You pressed the button"));
-
- // Number of rows and columns
- SetRowCount(100);
- SetColCount(20);
-
- // Turn off displaying vertical and horizontal lines
- CGXProperties* pProp = GetParam()->GetProperties();
-
- pProp->SetDisplayVertLines(FALSE);
- pProp->SetDisplayHorzLines(FALSE);
-
- pProp->SetPrintRowHeaders(FALSE); // no row headers when printing
-
- // Setup the table of controls
-
- SetRowHeight(5, 25, Height_LPtoDP(GX_NYHEIGHT)*2);
- // GX_NYHEIGHT is the logical height of a line
-
- SetColWidth(2, 2, Width_LPtoDP(GX_NXAVGWIDTH)*16);
- SetColWidth(3, 3, Width_LPtoDP(GX_NXAVGWIDTH)*16);
- // GX_NXAVGWIDTH is the average logical width of a char
-
- // Fill table
-
- // Background and interior borders
-
- SetStyleRange(CGXRange(5,2,24,3), CGXStyle()
- .SetBorders(gxBorderAll, CGXPen().SetStyle(PS_DOT))
- .SetInterior(GXSYSCOLOR(COLOR_BTNFACE))
- );
-
- // Alignment
-
- SetStyleRange(CGXRange(5,2,24,2), CGXStyle()
- .SetVerticalAlignment(DT_VCENTER)
- .SetHorizontalAlignment(DT_CENTER)
- .SetFont(CGXFont().SetBold(TRUE))
- );
-
- // Headers
-
- SetStyleRange(CGXRange(5,2,5,3), CGXStyle()
- .SetBorders(gxBorderBottom, CGXPen().SetWidth(2))
- .SetBorders(gxBorderTop, CGXPen().SetWidth(2))
- .SetFont(CGXFont().SetBold(TRUE).SetSize(12))
- .SetEnabled(FALSE) // disables usage as current cell
- .SetInterior(GXSYSCOLOR(COLOR_BTNFACE))
- .SetHorizontalAlignment(DT_CENTER)
- .SetVerticalAlignment(DT_VCENTER)
- );
-
-
- SetStyleRange(CGXRange(5,2), CGXStyle().SetValue(_T("Name")));
- SetStyleRange(CGXRange(5,3), CGXStyle().SetValue(_T("Control")));
- SetStyleRange(CGXRange(5,2,24,2), CGXStyle().SetEnabled(FALSE));
-
- // thick borders
-
- SetStyleRange(CGXRange(5,3,24,3), CGXStyle().SetBorders(gxBorderLeft, CGXPen().SetWidth(2)));
- SetStyleRange(CGXRange(5,2,24,2), CGXStyle().SetBorders(gxBorderLeft, CGXPen().SetWidth(2)));
- SetStyleRange(CGXRange(5,3,24,3), CGXStyle().SetBorders(gxBorderRight, CGXPen().SetWidth(2)));
- SetStyleRange(CGXRange(24,2,24,3), CGXStyle().SetBorders(gxBorderBottom, CGXPen().SetWidth(2)));
-
- // controls
-
- SetStyleRange(CGXRange(6,2), CGXStyle().SetValue(_T("CSimpleButton")));
- SetStyleRange(CGXRange(6,3), CGXStyle()
- .SetControl(IDS_CTRL_SIMPLE)
- .SetHorizontalAlignment(DT_CENTER)
- .SetVerticalAlignment(DT_VCENTER)
- .SetInterior(GXSYSCOLOR(COLOR_BTNFACE))
- .SetFont(CGXFont().SetBold(TRUE))
- .SetValue(_T("Simple"))
- );
-
- SetCoveredCellsRowCol(6, 4, 7, 5);
- SetStyleRange(CGXRange(6,4), _T("<- You can specify the message text with Format->Cells->User"));
-
- SetStyleRange(CGXRange(7,2), CGXStyle().SetValue(_T("CGXEditControl")));
- SetStyleRange(CGXRange(7,3), CGXStyle()
- .SetControl(GX_IDS_CTRL_EDIT)
- .SetValue(_T("Editable Text"))
- );
-
- SetStyleRange(CGXRange(8,2), CGXStyle().SetValue(_T("CGXSpinEdit")));
- SetStyleRange(CGXRange(8,3), CGXStyle()
- .SetControl(GX_IDS_CTRL_SPINEDIT)
- .SetValue(_T("0"))
- );
-
- SetStyleRange(CGXRange(9,2), CGXStyle().SetValue(_T("CGXHotSpotEdit")));
- SetStyleRange(CGXRange(9,3), CGXStyle()
- .SetControl(GX_IDS_CTRL_HOTSPOT)
- .SetValue(_T("Editable Text"))
- );
-
- SetStyleRange(CGXRange(10,2), CGXStyle().SetValue(_T("CGXCheckBox")));
- SetStyleRange(CGXRange(10,3), CGXStyle()
- .SetControl(GX_IDS_CTRL_CHECKBOX)
- .SetChoiceList(_T("Click Me!"))
- .SetVerticalAlignment(DT_VCENTER)
- );
-
- SetStyleRange(CGXRange(11,3), CGXStyle()
- .SetControl(GX_IDS_CTRL_CHECKBOX3D)
- .SetChoiceList(_T("Click Me!"))
- .SetInterior(GXSYSCOLOR(COLOR_BTNFACE))
- .SetVerticalAlignment(DT_VCENTER)
- );
-
-
- SetStyleRange(CGXRange(12,2), CGXStyle().SetValue(_T("CGXPushbutton")));
- SetStyleRange(CGXRange(12,3), CGXStyle()
- .SetControl(GX_IDS_CTRL_PUSHBTN)
- .SetChoiceList(_T("Push Me!"))
- );
-
- SetStyleRange(CGXRange(13,2), CGXStyle().SetValue(_T("CGXStatic")));
- SetStyleRange(CGXRange(13,3), CGXStyle()
- .SetControl(GX_IDS_CTRL_STATIC)
- .SetValue(_T("Text"))
- );
-
- SetCoveredCellsRowCol(14,2,15,2);
- SetStyleRange(CGXRange(14,2), CGXStyle().SetValue(_T("CGXRadioButton")));
- SetCoveredCellsRowCol(14,3,15,3);
- SetStyleRange(CGXRange(14,3), CGXStyle()
- .SetControl(GX_IDS_CTRL_RADIOBTN)
- .SetChoiceList(_T("one\ntwo\nthree\n"))
- );
- SetCoveredCellsRowCol(16,2,17,2);
- SetCoveredCellsRowCol(16,3,17,3);
- SetStyleRange(CGXRange(16,3), CGXStyle()
- .SetControl(GX_IDS_CTRL_RADIOBTN3D)
- .SetChoiceList(_T("one\ntwo\nthree\n"))
- .SetInterior(GXSYSCOLOR(COLOR_BTNFACE))
- );
-
- SetCoveredCellsRowCol(18,2,19,2);
- SetStyleRange(CGXRange(18,2), CGXStyle().SetValue(_T("CGXListBox")));
- SetCoveredCellsRowCol(18,3,19,3);
- SetStyleRange(CGXRange(18,3), CGXStyle()
- .SetControl(GX_IDS_CTRL_LISTBOX)
- .SetChoiceList(_T("one\ntwo\nthree\n"))
- );
-
- SetStyleRange(CGXRange(20,2), CGXStyle().SetValue(_T("CGXComboBox")));
- SetStyleRange(CGXRange(20,3), CGXStyle()
- .SetControl(GX_IDS_CTRL_COMBOBOX)
- .SetChoiceList(_T("one\ntwo\nthree\nfour\n"))
- .SetValue(_T("one"))
- );
-
- SetStyleRange(CGXRange(21,2), CGXStyle().SetValue(_T("CBitmapBtnEdit")));
- SetStyleRange(CGXRange(21,3), CGXStyle()
- .SetControl(IDS_CTRL_EDITBTN)
- .SetValue(_T("Editable Text with button"))
- );
-
- SetStyleRange(CGXRange(22,2), CGXStyle().SetValue(_T("CGXWndWrapper")));
- SetStyleRange(CGXRange(22,3), CGXStyle()
- .SetControl(IDS_CTRL_TABBEAM)
- );
-
- SetStyleRange(CGXRange(23,2), CGXStyle().SetValue(_T("COwnerDrawnComboBox")));
- SetStyleRange(CGXRange(23,3), CGXStyle()
- .SetControl(IDS_CTRL_OWNERDRAWNDROPDOWN)
- );
-
- // Instructions
-
- SetCoveredCellsRowCol(1, 1, 3, 5);
- SetStyleRange(CGXRange(1,1),
- CGXStyle()
- .SetWrapText(TRUE)
- .SetEnabled(FALSE)
- .SetFont(CGXFont().SetFaceName(_T("Times New Roman")))
- .SetInterior(RGB(255,251,240)) // Off-white
- .SetHorizontalAlignment(DT_CENTER)
- .SetVerticalAlignment(DT_VCENTER)
- .SetControl(GX_IDS_CTRL_STATIC)
- .SetBorders(gxBorderAll, CGXPen().SetWidth(2))
- .SetValue(szInstruct));
-
- // Enable creation of undo-information for user interactions
- GetParam()->EnableUndo(TRUE);
- }
-
- // Position the current cell
-
- SetCurrentCell(4, 1, FALSE /* avoid immediate updating */);
-
- // Enable Update-Hint-Mechanism
-
- EnableHints();
- }
-
- /////////////////////////////////////////////////////////////////////////////
- // CGridSample5View diagnostics
-
- #ifdef _DEBUG
- void CGridSample5View::AssertValid() const
- {
- CMyGridView::AssertValid();
- }
-
- void CGridSample5View::Dump(CDumpContext& dc) const
- {
- CMyGridView::Dump(dc);
- }
-
- CGridSampleDoc* CGridSample5View::GetDocument() // non-debug version is inline
- {
- ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CGridSampleDoc)));
- return (CGridSampleDoc*) m_pDocument;
- }
-
- #endif //_DEBUG
-
-
- /////////////////////////////////////////////////////////////////////////////
- // CGridSample5View message handlers
-
- // Menu handler for View->Splitter View
-
- void CGridSample5View::OnViewSplitterview()
- {
- CDocument* pDoc = GetDocument();
-
- CMyMultiDocTemplate* pTemplate
- = (CMyMultiDocTemplate*) ((CGridSampleApp*) AfxGetApp())->m_pSplitterTemplate;
-
- pTemplate->SetViewClass(GetRuntimeClass());
-
- CMDIChildWnd* pNewFrame
- = (CMDIChildWnd*) pTemplate->CreateNewFrame(GetDocument(), NULL);
-
- if (pNewFrame == NULL)
- return; // not created
-
- ASSERT(pNewFrame->IsKindOf(RUNTIME_CLASS(CSplitterMDIChildWnd)));
-
- CSplitterWnd& splitter = (CSplitterWnd&)
- ((CSplitterMDIChildWnd *) pNewFrame)->m_wndSplitter;
-
- CGridSample5View* pView = (CGridSample5View*)
- splitter.GetPane(0, 0);
-
- // Set view id to active tab view id
- pView->m_nViewID = m_nViewID;
-
- pTemplate->InitialUpdateFrame(pNewFrame, pDoc);
-
- pNewFrame->GetActiveView();
- ASSERT(pView);
- }
-
- // Menu handler for View->User Actions...
-
- void CGridSample5View::OnViewUseractions()
- {
- /*
- // just some performance checking
- ((CMDIChildWnd*) GetParentFrame())->MDIMaximize();
-
- OnViewZoomin();
- OnViewZoomin();
- OnViewZoomin();
-
- OnViewZoomout();
- OnViewZoomout();
- OnViewZoomout();
- OnViewZoomout();
- OnViewZoomout();
-
- OnViewZoomin();
- OnViewZoomin();
- OnViewZoomin();
- OnViewZoomin();
- OnViewZoomin();
-
- OnViewZoomout();
- OnViewZoomout();
- OnViewZoomout();
-
- ProcessKeys(this, WM_CHAR, 20, 1, 0);
- */
-
- // Note: this method is copied from CGridSampleView
- //
- // Shows a dialog with some attributes of the parameter-object
- // where you can experiment with some attributes
- // such as allowing the user to track columns, select cells
- // or use the grid as a listbox.
-
- // Transfer Current Cell's Data to grid
- if (!TransferCurrentCell())
- return;
-
- CUserActionsDialog dlg(GetParam());
-
- if (dlg.DoModal() == IDOK)
- {
- // Redraw the grid
- Redraw();
- }
- }
-