void GridLayouter::CalculateRows() { if (m_calculated_rows) return; unsigned row_fillroom = max(0, m_grid_rect.height - (int)m_minimum_height); GrowIfNecessary(m_row_info, m_row_count, row_fillroom); unsigned row_surplus = max(0, (int)m_minimum_height - m_grid_rect.height); ShrinkIfNecessary(m_row_info, m_row_count, m_minimum_height, row_surplus); CalculatePositions(m_row_info, m_row_count, m_grid_rect.y); m_calculated_rows = TRUE; }
void GridLayouter::CalculateColumns() { if (m_calculated_columns) return; unsigned column_fillroom = max(0, m_grid_rect.width - (int)m_minimum_width); GrowIfNecessary(m_column_info, m_col_count, column_fillroom); unsigned column_surplus = max(0, (int)m_minimum_width - max(0, m_grid_rect.width)); ShrinkIfNecessary(m_column_info, m_col_count, m_minimum_width, column_surplus); CalculatePositions(m_column_info, m_col_count, m_grid_rect.x); m_calculated_columns = TRUE; }
//writes Key=value given section void CIniEx::SetValue(CString Section,CString Key,CString Value) { //file opened? ASSERT(!m_FileName.IsEmpty()); //if given key already existing, overwrite it int nIndex=LookupSection(&Section); int nKeyIndex; if (nIndex==-1) { //if key not exist grow arrays (if necessary) m_Changed=TRUE; m_SectionNo++; GrowIfNecessary(); m_Keys[m_SectionNo-1]=new CStringArray; m_Values[m_SectionNo-1]=new CStringArray; nIndex=m_SectionNo-1; m_Sections.SetAtGrow(m_SectionNo-1,Section); } //looking up keys for section nKeyIndex=LookupKey(nIndex,&Key); //if key exist -> overwrite it //if not add to end of array if (nKeyIndex!=-1) { if (CompareStrings(&m_Values[nIndex]->GetAt(nKeyIndex),&Value)!=0) m_Changed=TRUE; m_Values[nIndex]->SetAt(nKeyIndex,Value); } else //if not exist { m_Changed=TRUE; m_Keys[nIndex]->Add(Key); m_Values[nIndex]->Add(Value); } }
BOOL CIniEx::Open(LPCTSTR pFileName, BOOL writeWhenChange,/*=FALSE*/ BOOL createIfNotExist/*=TRUE*/, BOOL noCaseSensitive /*=FALSE*/, BOOL makeBackup /*=FALSE*/) { CFileException e; BOOL bRet; CString Line; CString sectionStr; //int nPlace; UINT mode=CFile::modeReadWrite; //if it's second ini file for this instance //we have to save it and delete member variables contents if (!m_FileName.IsEmpty()) { if( m_writeWhenChange ) WriteFile(); ResetContent(); } m_NoCaseSensitive=noCaseSensitive; m_writeWhenChange=writeWhenChange; m_makeBackup=makeBackup; CString tmpKey; CString tmpValue; if (createIfNotExist) mode= mode | CFile::modeCreate | CFile::modeNoTruncate; CStdioUnicodeFile::FILEENCODING encoding = CStdioUnicodeFile::GetFileEncoding( pFileName ); try { m_FileName=pFileName; //Grow the arrays as GrowSize(which given constructor) m_allocatedObjectCount = m_GrowSize; m_Keys=(CStringArray **)malloc( m_allocatedObjectCount * sizeof(CStringArray *) ); m_Values=(CStringArray **)malloc( m_allocatedObjectCount * sizeof(CStringArray *) ); for (int i=0;i<m_GrowSize;i++) { m_Keys[m_SectionNo+i]=NULL; m_Values[m_SectionNo+i]=NULL; } CStdioUnicodeFile file(encoding); #ifdef UNICODE switch(encoding) { case CStdioUnicodeFile::FILEENCODING_UTF16LE: case CStdioUnicodeFile::FILEENCODING_UTF8: case CStdioUnicodeFile::FILEENCODING_UTF8_WITHOUT_BOM: if(!file.Open(pFileName, mode | CFILEFLAG_UNICODEHELPER, &e)) { return false; } file.ReadBOM(); break; default: if(!file.Open(pFileName, mode, &e)) return false; } #else switch( encoding ) { case CStdioUnicodeFile::FILEENCODING_UTF16LE: case CStdioUnicodeFile::FILEENCODING_UTF8: CString strErr; strErr.Format( IDS_UNICODEFILE, pFileName ); AfxMessageBox( strErr ); return false; // cancel default: if( !file.Open( pFileName, mode, &e ) ) return false; } #endif for(;;) { //Read one line from given ini file bRet=file.ReadString(Line); if (!bRet) break; Line.TrimRight(); if (Line=="") continue; //if line's first character = '[' //and last character = ']' it's section if (Line.Left(1)=="[" && Line.Right(1)=="]") { m_Keys[m_SectionNo]=new CStringArray; m_Values[m_SectionNo]=new CStringArray; m_SectionNo++; GrowIfNecessary(); sectionStr=Line.Mid(1,Line.GetLength()-2); m_Sections.SetAtGrow(m_SectionNo-1,sectionStr); continue; } ParseLine( Line, tmpKey, tmpValue ); /*nPlace=Line.Find(_T("=")); if (nPlace==-1) { tmpKey=Line; tmpValue=""; } else { tmpKey=Line.Left(nPlace); tmpValue=Line.Mid(nPlace+1); }*/ // create Section of no one exists in file if( m_SectionNo == 0 ) { m_Keys[m_SectionNo]=new CStringArray; m_Values[m_SectionNo]=new CStringArray; m_SectionNo++; } m_Keys[m_SectionNo-1]->Add(tmpKey); m_Values[m_SectionNo-1]->Add(tmpValue); m_Sections.SetAtGrow(m_SectionNo-1,sectionStr); } m_NewLine = file.GetNewLine(); file.Close(); } catch (CFileException *e) { m_ErrStr.Format( _T("%d"), e->m_cause ); } return TRUE; }