// GridItemControlsDlg.cpp // // (c)1998-2025 Codejock Software, All Rights Reserved. // // THIS SOURCE FILE IS THE PROPERTY OF CODEJOCK SOFTWARE AND IS NOT TO BE // RE-DISTRIBUTED BY ANY MEANS WHATSOEVER WITHOUT THE EXPRESSED WRITTEN // CONSENT OF CODEJOCK SOFTWARE. // // THIS SOURCE CODE CAN ONLY BE USED UNDER THE TERMS AND CONDITIONS OUTLINED // IN THE XTREME TOOLKIT PRO LICENSE AGREEMENT. CODEJOCK SOFTWARE GRANTS TO // YOU (ONE SOFTWARE DEVELOPER) THE LIMITED RIGHT TO USE THIS SOFTWARE ON A // SINGLE COMPUTER. // // CONTACT INFORMATION: // support@codejock.com // http://www.codejock.com // ///////////////////////////////////////////////////////////////////////////// #include "stdafx.h" #include "GridItemControls.h" #include "GridItemControlsDlg.h" #include "MessageRecord.h" #ifdef _DEBUG # define new DEBUG_NEW # undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif #define MAX_COLUMN 3 #define MAX_ROW 20 ///////////////////////////////////////////////////////////////////////////// // CGridItemControlsDlg dialog CGridItemControlsDlg::CGridItemControlsDlg(CWnd* pParent /*=NULL*/) : CXTPResizeDialog(CGridItemControlsDlg::IDD, pParent) { //{{AFX_DATA_INIT(CGridItemControlsDlg) // NOTE: the ClassWizard will add member initialization here //}}AFX_DATA_INIT // Note that LoadIcon does not require a subsequent DestroyIcon in Win32 m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); } void CGridItemControlsDlg::DoDataExchange(CDataExchange* pDX) { CXTPResizeDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CGridItemControlsDlg) //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CGridItemControlsDlg, CXTPResizeDialog) //{{AFX_MSG_MAP(CGridItemControlsDlg) ON_WM_SYSCOMMAND() ON_WM_PAINT() ON_WM_QUERYDRAGICON() ON_WM_DESTROY() //}}AFX_MSG_MAP ON_NOTIFY(XTP_NM_GRID_ITEMBUTTONCLICK, IDC_GRIDCTRL, OnItemButtonClick) END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CGridItemControlsDlg message handlers BOOL CGridItemControlsDlg::OnInitDialog() { CXTPResizeDialog::OnInitDialog(); // Add "About..." menu item to system menu. // IDM_ABOUTBOX must be in the system command range. _ASSERTE((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX); _ASSERTE(IDM_ABOUTBOX < 0xF000); CMenu* pSysMenu = GetSystemMenu(FALSE); if (pSysMenu != NULL) { CString strAboutMenu; strAboutMenu.LoadString(IDS_ABOUTBOX); if (!strAboutMenu.IsEmpty()) { pSysMenu->AppendMenu(MF_SEPARATOR); pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu); } } // Set the default font for all dialog controls. SendMessageToDescendants(WM_SETFONT, (WPARAM)(HFONT)XTPFontManager()->GetFont()); // Set the icon for this dialog. The framework does this automatically // when the application's main window is not a dialog SetIcon(m_hIcon, TRUE); // Set big icon SetIcon(m_hIcon, FALSE); // Set small icon // subclass the Grid control. m_wndGridCtrl.SubclassDlgItem(IDC_GRIDCTRL, this); // // Add images // int nWidth = 0; CString type = _T("RT_SVG"); CXTPImageManager* imgMgr = m_wndGridCtrl.GetImageManager(); nWidth = XTP_DPI_X(16); BOOL res = imgMgr->SetVectorIcon(type, IDR_SVG_GRID_SMALL_PARAGRAPH_ALIGN_LEFT, 0, nWidth); imgMgr->SetVectorIcon(type, IDR_SVG_GRID_SMALL_PARAGRAPH_ALIGN_JUSTIFIED, 1, nWidth); imgMgr->SetVectorIcon(type, IDR_SVG_GRID_SMALL_PARAGRAPH_ALIGN_RIGHT, 2, nWidth); imgMgr->SetVectorIcon(type, IDR_SVG_GRID_SMALL_CHARACTER_BOLD, 3, nWidth); imgMgr->SetVectorIcon(type, IDR_SVG_GRID_SMALL_CHARACTER_BLACK, 4, nWidth); imgMgr->SetVectorIcon(type, IDR_SVG_GRID_SMALL_CHARACTER_BLUE, 5, nWidth); imgMgr->SetVectorIcon(type, IDR_SVG_GRID_SMALL_CHARACTER_RED, 6, nWidth); nWidth = XTP_DPI_X(32); imgMgr->SetVectorIcon(type, IDR_SVG_GRID_LARGE_PARAGRAPH_ALIGN_LEFT, 0, nWidth); imgMgr->SetVectorIcon(type, IDR_SVG_GRID_LARGE_PARAGRAPH_ALIGN_JUSTIFIED, 1, nWidth); imgMgr->SetVectorIcon(type, IDR_SVG_GRID_LARGE_PARAGRAPH_ALIGN_RIGHT, 2, nWidth); imgMgr->SetVectorIcon(type, IDR_SVG_GRID_LARGE_CHARACTER_BOLD, 3, nWidth); imgMgr->SetVectorIcon(type, IDR_SVG_GRID_LARGE_CHARACTER_BLACK, 4, nWidth); imgMgr->SetVectorIcon(type, IDR_SVG_GRID_LARGE_CHARACTER_BLUE, 5, nWidth); imgMgr->SetVectorIcon(type, IDR_SVG_GRID_LARGE_CHARACTER_RED, 6, nWidth); int i, j; // add sample columns for (i = 0; i < MAX_COLUMN; i++) { CString strName; strName.Format(_T("Column %d"), i + 1); m_wndGridCtrl.AddColumn(new CXTPGridColumn(i, strName, 280)); } // add records for (i = 0; i < MAX_ROW; i++) { CString strItem[MAX_COLUMN]; for (j = 0; j < MAX_COLUMN; j++) { strItem[j].Format(_T("Row - %d, Col - %d"), i + 1, j + 1); } CXTPGridRecord* pRecord = m_wndGridCtrl.AddRecord( new CMessageRecord(strItem[0], strItem[1], strItem[2])); if (!pRecord) continue; for (j = 0; j < MAX_COLUMN; j++) { CXTPGridRecordItem* pItem = pRecord->GetItem(j); if (!pItem) continue; CXTPGridRecordItemControl* pButton = pItem->GetItemControls()->AddControl( xtpItemControlTypeButton); if (!pButton) continue; pButton->SetAlignment(xtpItemControlLeft); pButton->SetIconIndex(PBS_NORMAL, 0); pButton->SetIconIndex(PBS_PRESSED, 1); pButton->SetSize(CSize(22, 0)); pButton = pItem->GetItemControls()->AddControl(xtpItemControlTypeButton); if (!pButton) continue; pButton->SetAlignment(xtpItemControlRight); pButton->SetIconIndex(PBS_NORMAL, 4); pButton->SetIconIndex(PBS_PRESSED, 5); pButton->SetSize(CSize(22, 0)); pButton = pItem->GetItemControls()->AddControl(xtpItemControlTypeButton); if (!pButton) continue; pButton->SetAlignment(xtpItemControlRight); pButton->SetIconIndex(0, 3); pButton->SetSize(CSize(22, 0)); } } // define style attributes for the Grid control. m_wndGridCtrl.FocusSubItems(TRUE); m_wndGridCtrl.AllowEdit(TRUE); // after columns and data have been added call Populate to // populate all of the date for the control. m_wndGridCtrl.Populate(); #ifdef _XTP_INCLUDE_CONTROLS // Set control resizing. SetResize(IDC_GRIDCTRL, XTP_ANCHOR_TOPLEFT, XTP_ANCHOR_BOTTOMRIGHT); SetResize(IDOK, XTP_ANCHOR_BOTTOMRIGHT, XTP_ANCHOR_BOTTOMRIGHT); // Load window placement LoadPlacement(_T("CGridItemControlsDlg")); #endif return TRUE; // return TRUE unless you set the focus to a control } void CGridItemControlsDlg::OnSysCommand(UINT nID, LPARAM lParam) { if ((nID & 0xFFF0) == IDM_ABOUTBOX) { CAboutDlg dlgAbout; dlgAbout.DoModal(); } else { CXTPResizeDialog::OnSysCommand(nID, lParam); } } // If you add a minimize button to your dialog, you will need the code below // to draw the icon. For MFC applications using the document/view model, // this is automatically done for you by the framework. void CGridItemControlsDlg::OnPaint() { if (IsIconic()) { CPaintDC dc(this); // device context for painting SendMessage(WM_ICONERASEBKGND, (WPARAM)dc.GetSafeHdc(), 0); // Center icon in client rectangle int cxIcon = GetSystemMetrics(SM_CXICON); int cyIcon = GetSystemMetrics(SM_CYICON); CRect rect; GetClientRect(&rect); int x = (rect.Width() - cxIcon + 1) / 2; int y = (rect.Height() - cyIcon + 1) / 2; // Draw the icon dc.DrawIcon(x, y, m_hIcon); } else { CXTPResizeDialog::OnPaint(); } } // The system calls this to obtain the cursor to display while the user drags // the minimized window. HCURSOR CGridItemControlsDlg::OnQueryDragIcon() { return (HCURSOR)m_hIcon; } void CGridItemControlsDlg::OnDestroy() { CXTPResizeDialog::OnDestroy(); #ifdef _XTP_INCLUDE_CONTROLS // Save window placement SavePlacement(_T("CGridItemControlsDlg")); #endif } BOOL CGridItemControlsDlg::PreTranslateMessage(MSG* pMsg) { if (pMsg->message == WM_KEYDOWN && (pMsg->wParam == VK_ESCAPE || pMsg->wParam == VK_RETURN || pMsg->wParam == VK_TAB)) return FALSE; return CXTPResizeDialog::PreTranslateMessage(pMsg); } void CGridItemControlsDlg::OnItemButtonClick(NMHDR* pNotifyStruct, LRESULT*) { XTP_NM_GRIDITEMCONTROL* pItemNotify = (XTP_NM_GRIDITEMCONTROL*)pNotifyStruct; if (!(pItemNotify->pRow && pItemNotify->pItem && pItemNotify->pItemControl)) return; switch (pItemNotify->pItemControl->GetIndex()) { // button "Alignment" case 0: { int nIcon = pItemNotify->pItemControl->GetIconIndex(PBS_NORMAL); if (++nIcon > 2) nIcon = 0; pItemNotify->pItemControl->SetIconIndex(PBS_NORMAL, nIcon); if (++nIcon > 2) nIcon = 0; pItemNotify->pItemControl->SetIconIndex(PBS_PRESSED, nIcon); switch (pItemNotify->pItemControl->GetIconIndex(PBS_NORMAL)) { case 0: pItemNotify->pItem->SetAlignment(xtpColumnTextLeft); break; case 1: pItemNotify->pItem->SetAlignment(xtpColumnTextCenter); break; case 2: pItemNotify->pItem->SetAlignment(xtpColumnTextRight); break; } break; } // button "Color" case 1: { int nIcon = pItemNotify->pItemControl->GetIconIndex(PBS_NORMAL); if (++nIcon > 6) nIcon = 4; pItemNotify->pItemControl->SetIconIndex(PBS_NORMAL, nIcon); if (++nIcon > 6) nIcon = 4; pItemNotify->pItemControl->SetIconIndex(PBS_PRESSED, nIcon); switch (pItemNotify->pItemControl->GetIconIndex(PBS_NORMAL)) { case 4: pItemNotify->pItem->SetTextColor(RGB(0, 0, 0)); break; case 5: pItemNotify->pItem->SetTextColor(RGB(0, 0, 255)); break; case 6: pItemNotify->pItem->SetTextColor(RGB(255, 0, 0)); break; } break; } // button "Bold" case 2: { pItemNotify->pItem->SetBold(!pItemNotify->pItem->IsBold()); break; } } }