void GeometryListView::OnEditGeometry() // Called when user clicks "Edit" in the geometry list. { // Figure out which geometry item to edit. int index = GetSelectedItemIndex(); if (index < 0) { // No item selected, so we don't know what to delete... return; } if (index == 0) { // Can't edit null geometry. return; } // Get the geometry object to edit. Geometry* g = GetDocument()->GetGeometry(index); if (g == NULL) return; // Call edit dialog box. GeometryPropertiesDialog d; d.SetName(g->GetName()); d.SetFilename(g->GetFilename()); d.SetComment(g->GetComment()); if (d.DoModal() != IDCANCEL) { // Apply the changes. g->SetName(d.GetName()); g->SetFilename(d.GetFilename()); g->SetComment(d.GetComment()); GetDocument()->SetModifiedFlag(); GetDocument()->UpdateAllViews(NULL); } }
void GeometryListView::Update() // Rebuild the list of geometry resources. { // CPropertyPage::OnUpdate(pSender, lHint, pHint); // TODO: Add extra initialization here CTerrainDoc* doc = GetDocument(); Geometry* g = doc->GetGeometryList(); int GeometryCount = doc->GetGeometryCount(); CListCtrl* list = &m_ListControl /* (CListCtrl*) GetDlgItem(IDC_GEOMETRYLIST) */; if (list->m_hWnd == NULL) return; // Setup the column headings. while (list->DeleteColumn(0)) ; LV_COLUMN col; col.mask = LVCF_FMT | LVCF_SUBITEM | LVCF_TEXT | LVCF_WIDTH; col.fmt = LVCFMT_LEFT; // Name. col.pszText = "Name"; col.iSubItem = 0; col.cx = 75; list->InsertColumn(0, &col); // Filename. col.iSubItem = 1; col.pszText = "Filename"; col.cx = 100; list->InsertColumn(1, &col); // Comment. col.iSubItem = 2; col.pszText = "Comment"; col.cx = 170; list->InsertColumn(2, &col); // Set the list items. list->DeleteAllItems(); list->SetItemCount(GeometryCount); for (int i = 0; i < GeometryCount; i++, g = g->Next) { if (g == NULL) break; int index = list->InsertItem(i, g->GetName()); list->SetItemText(index, 1, g->GetFilename()); list->SetItemText(index, 2, g->GetComment()); list->SetItemData(index, i); } }