// **************************************************************************** // // Function Name: RNameAddress::FormatNameAddress( ) // // Description: Perform the formatting described in the format string to // the given inputs and put the result into output // // Returns: Nothing // // Exceptions: kMemory // // **************************************************************************** // void RNameAddress::FormatNameAddress( RMBCString& output, const RMBCString& format, const RMBCString& firstName, const RMBCString& lastName, const RMBCString& address, const RMBCString& city, const RMBCString& state, const RMBCString& zip, const RMBCString& country ) { output.Empty( ); RMBCStringIterator iterator = format.Start( ); RMBCStringIterator iteratorEnd = format.End( ); for ( ; iterator != iteratorEnd; ++iterator ) { RCharacter ch = ( *iterator ); if ( ch == kFormatIdentifierTag ) { ++iterator; TpsAssert( iterator!=iteratorEnd, "Format Identifier found at end of stream" ); ch = ( *iterator ); if ( ch == kFormatIdentifierTag ) output += kFormatIdentifierTag; else if ( ch == kFirstNameIdentifierTag ) output += firstName; else if ( ch == kLastNameIdentifierTag ) output += lastName; else if ( ch == kAddressIdentifierTag ) output += address; else if ( ch == kCityIdentifierTag ) output += city; else if ( ch == kStateIdentifierTag ) output += state; else if ( ch == kZipIdentifierTag ) output += zip; else if ( ch == kCountryIdentifierTag ) output += country; else { TpsAssertAlways( "Unknown format tag found" ); } } else { if ( ch == kSpaceTag ) output += ch; else if ( ch == kReturnTag ) output += ch; else if ( ch == kTabTag ) output += ch; else if ( ch == kCommaTag ) output += ch; else { //TpsAssertAlways( "Unsupported Character, If it is necessary add it to the MergeField info and here" ); output += ch; } } } }
// **************************************************************************** // // Function Name: RFont::GetStringWidth( ) // // Description: Return the width of the given string of characters // // Returns: The requested string size // // Exceptions: Nothing // // **************************************************************************** // YFontSize RFont::GetStringWidth( const RMBCString& string ) const { YFontSize size = 0; RDataObjectLocker locker( m_pWidthsTable ); for ( RMBCStringIterator cz = string.Start(); cz != string.End(); ++cz ) size += m_pWidthsTable->GetCharacterWidth( *cz ); return size; }
// **************************************************************************** // // Function Name: RNameAddress::FormatNameAddress( ) // // Description: Perform the formatting described in the format string to // the given inputs and put the result into address // // Returns: Nothing // // Exceptions: kMemory // // **************************************************************************** // void RNameAddress::FormatNameAddress( RMergeFieldContainer& output, const RMBCString& format, YMergeId firstName, YMergeId lastName, YMergeId address, YMergeId city, YMergeId state, YMergeId zip, YMergeId country ) { output.Empty( ); RMBCStringIterator iterator = format.Start( ); RMBCStringIterator iteratorEnd = format.End( ); for ( ; iterator != iteratorEnd; ++iterator ) { RCharacter ch = ( *iterator ); if ( ch == kFormatIdentifierTag ) { ++iterator; TpsAssert( iterator!=iteratorEnd, "Format Identifier found at end of stream" ); ch = ( *iterator ); if ( ch == kFirstNameIdentifierTag ) output.InsertAtEnd( firstName ); else if ( ch == kLastNameIdentifierTag ) output.InsertAtEnd( lastName ); else if ( ch == kAddressIdentifierTag ) output.InsertAtEnd( address ); else if ( ch == kCityIdentifierTag ) output.InsertAtEnd( city ); else if ( ch == kStateIdentifierTag ) output.InsertAtEnd( state ); else if ( ch == kZipIdentifierTag ) output.InsertAtEnd( zip ); else if ( ch == kCountryIdentifierTag ) output.InsertAtEnd( country ); else { TpsAssertAlways( "Unknown format tag found" ); } } else { if ( ch == kSpaceTag ) output.InsertAtEnd( kMergeFieldSpace ); else if ( ch == kReturnTag ) output.InsertAtEnd( kMergeFieldReturn ); else if ( ch == kTabTag ) output.InsertAtEnd( kMergeFieldTab ); else if ( ch == kCommaTag ) output.InsertAtEnd( kMergeFieldComma ); else { TpsAssertAlways( "Unsupported Character, If it is necessary add it to the MergeField info and here" ); } } } }
// **************************************************************************** // // Function Name: RNumberDialog::GetSmartNumberSuffix // // Description: Return internationally correct suffix for given string // embedded number // // Returns: suffix // // Exceptions: None // // **************************************************************************** RMBCString RNumberDialog::GetSmartNumberSuffix( const RMBCString& rNumber ) { int nNumber = atoi( (LPCSZ)rNumber ); TpsAssert( nNumber >= 0 , "Number string invalid. Negative numbers not supported." ); TpsAssert( nNumber <= kMaxNumber, "Number string invalid. Too large."); TpsAssert( rNumber.GetStringLength() <= kMaxNumNumbers, "Number string too long" ); if( nNumber == 0 && rNumber.GetStringLength() > 1 ) { TpsAssertAlways( "Invalid number string." ); } // // Only interested in the last two digits of number (ie. Suffix for 12 is the // same as suffix for 112) int nMeaningfulDigits = atoi( (LPCSZ)rNumber ); if( rNumber.GetStringLength() > 2 ) { // If the number is three digits or greater, just get the last two digits.. char sDigitConvert[3]; //strncpy( sDigitConvert, (LPCSZ)rNumber[ rNumber.GetStringLength() - 2 ], 2 ); sDigitConvert[ 0 ] = rNumber[ rNumber.GetStringLength() - 2 ]; sDigitConvert[ 1 ] = rNumber[ rNumber.GetStringLength() - 1 ]; sDigitConvert[ 2 ] = 0; nMeaningfulDigits = atoi( sDigitConvert ); } // // To be safe for all languages we define suffixes for every number up to // 20, then just define suffixes for the second digit for numbers greater // than that. if( nMeaningfulDigits < kNumberOfSuffixesDefinedFromZero ) { /*!!!!!!!!!!!! NOTE !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ // Smart number ids from 0-19 MUST be sequential or the proper suffix will // NOT be used!!!!!! -MWH int nFirstSuffixInResource = IDS_SMARTNUM_SUFFIX_0; return ::GetResourceManager().GetResourceString( nFirstSuffixInResource + nMeaningfulDigits ); } else { // // Number is greater than 20, need to get last digit suffix RMBCString rLastDigit(""); rLastDigit += rNumber[rNumber.GetStringLength()-1]; int nLastDigit = atoi( (LPCSZ)rLastDigit ); /*!!!!!!!!!!!! NOTE !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ // Smart number two digit ids MUST be sequential or the proper suffix will // NOT be used!!!!!! -MWH int nFirst2DigitSuffixInResource = IDS_SMARTNUM_2DIGIT_SUFFIX_0; return ::GetResourceManager().GetResourceString( nFirst2DigitSuffixInResource + nLastDigit ); } }
// **************************************************************************** // // Function Name: RMergeData::SaveAsFile( ) // // Description: Make this MergeData takes its values from a choosen file // // Returns: Nothing // // Exceptions: None // // **************************************************************************** // BOOLEAN RMergeData::SaveAsFile( ) { try { RMBCString fileName; #ifdef _WINDOWS RMBCString fileExtension; RMBCString fileFilter; ReturnFileExtension( fileExtension, TRUE ); ReturnFileFilter( fileFilter, TRUE ); CFileDialog dialog( FALSE, (LPCTSTR)fileExtension, NULL, OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT, (LPCTSTR)fileFilter, NULL ); if ( dialog.DoModal( ) == IDCANCEL ) return FALSE; fileName = dialog.GetPathName( ); #else // MAC #endif // _WINDOWS if ( fileName.GetStringLength() > 0 ) { RMBCString oldFileName = m_FileName; m_FileName = fileName; if ( !SaveFile( ) ) { m_FileName = oldFileName; return FALSE; } } } catch( YException exception ) { ::ReportException( exception ); return FALSE; } catch( ... ) { ::ReportException( kUnknownError ); return FALSE; } return TRUE; }
// **************************************************************************** // // Function Name: RHLSpellCheckInterface::RHLSpellCheckInterface() // // Description: Replace the current word with the given replacement // // Returns: TRUE if sucessful // // Exceptions: None // // **************************************************************************** BOOLEAN RHLSpellCheckInterface::ReplaceWord( const RMBCString& original, const RMBCString& replacement ) { RMBCString newText; RMBCStringIterator iterator = m_Text.Start( ); RMBCStringIterator iteratorEnd = m_Text.End( ); // Empty the new string ( just to be paranoid ); newText.Empty( ); // Copy the text before the word int nLength = 0; while ( nLength++ < m_nWordStart ) { newText += (*iterator); ++iterator; } // add the replacement word newText += replacement; // skip over the original word iterator += original.GetStringLength( ); // add the remaining string while ( iterator != iteratorEnd ) { newText += (*iterator); ++iterator; } m_pDocument->SetHeadlineText( newText ); m_Text = newText; m_nWordEnd = m_nWordStart + replacement.GetStringLength(); // Invalidate the render cache TpsAssertIsObject( RComponentView, m_pDocument->GetActiveView( ) ); RComponentView* pView = static_cast< RComponentView* >( m_pDocument->GetActiveView( ) ); pView->InvalidateRenderCache( ); return TRUE; }
// **************************************************************************** // // Function Name: RFont::GetStringWidth( ) // // Description: Return the width of the given string of characters // // Returns: The requested string size // // Exceptions: Nothing // // **************************************************************************** // YFontSize RFont::GetStringWidth( const RMBCString& string, BOOLEAN fKern ) const { YFontSize size = GetStringWidth( string ); RMBCStringIterator cz; RCharacter character, next; if ( fKern ) { cz = string.Start(); character = *cz; ++cz; while ( cz != string.End() ) { next = *cz; size += GetKernAmount( character, next ); character = next; ++cz; } } return size; }
// **************************************************************************** // // Function Name: RNumberDialog::StripSmartNumber // // Description: Strip the smart number suffix if there is one. // // Returns: pointer to ContextData // // Exceptions: None // // **************************************************************************** // void RNumberDialog::StripSmartNumber( RMBCString& rNumber ) { char* pStrippedNumber = new char[ rNumber.GetStringLength() + 1 ]; try { strcpy( pStrippedNumber, (LPCSZ)rNumber ); for( int nIdx = 0; nIdx < rNumber.GetStringLength(); nIdx++ ) { if( !isdigit( pStrippedNumber[nIdx] ) ) { pStrippedNumber[nIdx] = 0; break; } } } catch( ... ) { delete [] pStrippedNumber; throw; } rNumber = RMBCString( pStrippedNumber ); delete [] pStrippedNumber; }
// **************************************************************************** // // Function Name: RMergeData::ReadTabDelimitedString( ) // // Description: Read a string that is tab delimited from the storage. // Eat the delimeter character also (eof, cr/lf, tab). // // Returns: Nothing // // Exceptions: Any File Exception, will not send through on kEndOfFile // // **************************************************************************** // RMergeData::EDataDelimiter RMergeData::ReadTabDelimitedString( RStorage& storage, RMBCString& string ) { EDataDelimiter delimiter = kTab; try { uBYTE ubChar( 0 ); RCharacter character; // First, make sure the string is empty string.Empty( ); // Loop until I hit a EOF, TAB, CR, or LF while ( 1 ) { storage >> ubChar; if ( (ubChar == '\t') || (ubChar == '\r') || (ubChar == '\n') ) break; // Check for multi-Byte character = ubChar; if ( character.IsLead( ) ) { UntestedCode( ); uBYTE lead = ubChar; uBYTE trail; storage >> trail; character = RCharacter( lead, trail ); } string += character; } // If I found a CR or a LF, make sure the other is not also present. if ( (ubChar == '\r') || (ubChar == '\n') ) { storage >> ubChar; // If character is NOT a CR or LF, rewind one character if ( !((ubChar == '\r') || (ubChar == '\n')) ) storage.SeekRelative( -1 ); delimiter = kEOL; }
// **************************************************************************** // // Function Name: RHLSpellCheckInterface::GetContext() // // Description: Return the context around the last word returned // // Returns: Nothing // // Exceptions: None // // **************************************************************************** void RHLSpellCheckInterface::GetContext( RMBCString& context, int& nWordStart ) { // Empty the context context.Empty( ); RMBCStringIterator iterator = m_Text.Start( ); RMBCStringIterator iteratorEnd = m_Text.End( ); nWordStart = m_nWordStart; int nStartContext = (m_nWordStart>kContextSize/2)? m_nWordStart-(kContextSize/2) : 0; iterator += nStartContext; // Fill in at least kContextSize characters int nLength = 0; while ( iterator != iteratorEnd ) { context += (*iterator); ++iterator; if ( ++nLength == kContextSize ) break; } }
// **************************************************************************** // // Function Name: RHLSpellCheckInterface::FindNextWord() // // Description: Return the next word in the component // // Returns: TRUE if word found, FALSE if no more words // // Exceptions: None // // **************************************************************************** BOOLEAN RHLSpellCheckInterface::FindNextWord( RMBCString& word ) { // Empty the word word.Empty( ); RMBCStringIterator iterator = m_Text.Start( ); RMBCStringIterator iteratorEnd = m_Text.End( ); // Advance to current word position iterator += m_nWordEnd; m_nWordStart = m_nWordEnd; // Try to find a word start. while ( iterator != iteratorEnd ) { if ( !(*iterator).IsSpace( ) ) break; ++m_nWordStart; ++iterator; } if ( iterator == iteratorEnd ) return FALSE; // Find the word end m_nWordEnd = m_nWordStart; while ( iterator != iteratorEnd ) { ++m_nWordEnd; if ( (*iterator).IsSpace( ) ) break; word += (*iterator); ++iterator; } return TRUE; }
// **************************************************************************** // // Function Name: ParseAndPutInListBox // // Description: Parses tokens out of passed in string, and loads tokens into listbox. // // Returns: void // // Exceptions: None // // **************************************************************************** void ParseAndPutInComboBox( RMBCString& rListToParse, CComboBox& cComboBox ) { char* pList = NULL; pList = new char[ rListToParse.GetStringLength() + 1 ]; try { cComboBox.ResetContent(); strcpy( pList, rListToParse ); char* pListItem = NULL; pListItem = strtok( pList, kListFieldSeperator ); while( pListItem ) { cComboBox.AddString( pListItem ); pListItem = strtok( NULL, kListFieldSeperator ); } } catch(...) { delete pList; throw; } delete pList; }
// **************************************************************************** // // Function Name: RStandaloneDocument::OpenPlaceholder( ) // // Description: Opens a placeholder file to prevent the document from being // deleted // // Returns: Nothing // // Exceptions: None // // **************************************************************************** // void RStandaloneDocument::OpenPlaceholder( const RMBCString& filename ) { if( !filename.IsEmpty( ) ) { try { // delete the existing placeholder and open the new doc delete m_pDocumentStorage; m_pDocumentStorage = NULL; // Changed from kReadWrite to kRead so that revert to saved // would work under Windows 95. REVIEW BDR - this change // may allow the user to delete an open document from the NT // Explorer, however only Win95 is important now. 6/9/97 m_pDocumentStorage = new RChunkStorage( filename, kRead, kPlaceholder ); m_pDocumentStorage->SetSaveOnClose( FALSE ); } catch( ... ) { // it is ok to fail while opening a placeholder; // this can happen if the doc is already open NULL; } } }