void CColumnDefMap::SaveSettings() { // Write column positions to registry // ColumnDefMap must have non-blank name and one (1) or more entries. // If no name or no entries then skip it. if (!GetName().IsEmpty() && this->getSize() > 0) { CAppRegistryKey appKey; CRegistryKey settings = appKey.createSubKey("Settings"); if (settings.isOpen()) { CRegistryKey registryKey = settings.createSubKey( GetName() ); // Grid Name if (registryKey.isOpen()) { for (int i = 0; i < this->getSize(); i++) { CColumnDef *cd = this->getAt(i); CString title = cd->GetTitle(); // Column Name int *ptr = cd->GetColIndexPtr(); int value = *ptr; if (registryKey.setValue(title, value)) { // okay } // else we silently suffer } } } } }
void CColumnDefMap::LoadSettings() { if (!GetName().IsEmpty()) { CAppRegistryKey appKey; CRegistryKey settings = appKey.createSubKey("Settings"); if (settings.isOpen()) { CRegistryKey registryKey = settings.createSubKey( GetName() ); if (registryKey.isOpen()) { for (int i = 0; i < this->getSize(); i++) { CColumnDef *cd = this->getAt(i); CString title = cd->GetTitle(); // Column Name int *ptr = cd->GetColIndexPtr(); int value; if (registryKey.getValue(title, value)) { *ptr = value; } } // Compensate // The number of fields present may have been reduced. This could // result in a hole in the numbering of active fields, as well as a column // number that is out of range for current list. Try to spot this and // if spotted then shuffle the fields down so we might preserve the // order for the rest of the fields. Failing this, teh Validate section // will just reassign everything to defaults. ///*rcf WELL ??? // Validate // The values are column indices, nothing should be less // than zero, and not greater than the number of columns // minus 1. And no two should be alike. If there is an // error, then just reset the whole thing to sequentially // numbered. bool error = false; for (int i = 0; i < this->getSize() && !error; i++) { CColumnDef *cdI = this->getAt(i); int *valI = cdI->GetColIndexPtr(); if (*valI < 0 || *valI >= this->getSize()) error = true; // Check no two alike for (int j = i+1; j < this->getSize() && !error; j++) { CColumnDef *cdJ = this->getAt(j); int *valJ = cdJ->GetColIndexPtr(); if (*valI == *valJ) error = true; } } // If error then reset to sequential numbering if (error) { for (int i = 0; i < this->getSize(); i++) { CColumnDef *cd = this->getAt(i); int *valI = cd->GetColIndexPtr(); *valI = i; } } } } } }