From: andrew7 <bd...@us...> - 2006-11-30 00:32:55
|
Update of /cvsroot/smartwin/SmartWin/include/io In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv16440/include/io Modified Files: InDialog.h html_get.h html_put.h textbox_stream.h Log Message: Add unicode support Index: textbox_stream.h =================================================================== RCS file: /cvsroot/smartwin/SmartWin/include/io/textbox_stream.h,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- textbox_stream.h 5 May 2006 17:14:40 -0000 1.5 +++ textbox_stream.h 30 Nov 2006 00:32:51 -0000 1.6 @@ -83,10 +83,8 @@ itsBuff[0] = getAsyncKey(); n = 1; - itsTextBox->setSelection( ( long ) itsTextBox->getText().size() ); - SmartUtil::tstring addstr( ( char * ) itsBuff, 1 ); - adjustLineTerm( addstr ); - itsTextBox->replaceSelection( addstr ); + std::string addstr( itsBuff, 1 ); + appendTextBox( addstr ); } else { @@ -127,7 +125,19 @@ return c; } - void adjustLineTerm( SmartUtil::tstring & str ) + + // Output of data to text box. + virtual std::streamsize xsputn( int_type * data, std::streamsize _Count ) + { + std::string addstr( (char *)data, _Count ); + appendTextBox( addstr ); + + return( _Count ); // Number of characters copied. + } + + private: + + void adjustLineTerm( std::string & str ) { size_t pos_n = str.find( '\n' ); if ( - 1 != pos_n ) @@ -143,21 +153,17 @@ } } - // Output of data to text box. - virtual std::streamsize xsputn( int_type * data, std::streamsize _Count ) - { - itsTextBox->setSelection( ( long ) itsTextBox->getText().size() ); - SmartUtil::tstring addstr( ( char * ) data, _Count ); + void appendTextBox( std::string & addstr ) + { adjustLineTerm( addstr ); - itsTextBox->replaceSelection( addstr ); + SmartUtil::tstring tadd= SmartUtil::Ascii2CurrentBuild::doConvert( addstr, SmartUtil::ConversionCodepage::UTF8 ); + itsTextBox->setSelection( ( long ) itsTextBox->getText().size() ); + itsTextBox->replaceSelection( tadd ); itsTextBox->showCaret(); - - return( _Count ); // Number of characters copied. } - private: char getAsyncKey() { Index: html_put.h =================================================================== RCS file: /cvsroot/smartwin/SmartWin/include/io/html_put.h,v retrieving revision 1.9 retrieving revision 1.10 diff -u -d -r1.9 -r1.10 --- html_put.h 9 Oct 2006 01:11:05 -0000 1.9 +++ html_put.h 30 Nov 2006 00:32:51 -0000 1.10 @@ -49,20 +49,20 @@ class html_put { private: - iostream & itsIo; + SmartUtil::tiostream & itsIo; public: - html_put( iostream & io ) + html_put( SmartUtil::tiostream & io ) : itsIo( io ) { - itsIo << "<html> <head> <title> </title> </head>\n<body> <form>\n"; + itsIo << _T("<html> <head> <title> </title> </head>\n<body> <form>\n"); } //------------------------------------------------------------------------- ~html_put() { - itsIo << "\n</form> </body>\n</html>\n"; + itsIo << _T("\n</form> </body>\n</html>\n"); } //------------------------------------------------------------------------- @@ -72,7 +72,7 @@ // void string_put( SmartUtil::tstring txt ) { - itsIo << "<p>" << endl << txt << endl << "</p>" << endl; + itsIo << _T("<p>") << endl << txt << endl << _T("</p>") << endl; } //------------------------------------------------------------------------- @@ -102,8 +102,8 @@ // void putTaggedText( const SmartUtil::tstring & tag, SmartUtil::tstring & taggedValue ) { - itsIo << "<input type=text name=\"" << tag << "\"" - << " value=\"" << taggedValue << "\" >\n"; + itsIo << _T("<input type=text name=\"") << tag << _T("\"") + << _T(" value=\"") << taggedValue << _T("\" >\n"); } //------------------------------------------------------------------------- Index: html_get.h =================================================================== RCS file: /cvsroot/smartwin/SmartWin/include/io/html_get.h,v retrieving revision 1.10 retrieving revision 1.11 diff -u -d -r1.10 -r1.11 --- html_get.h 9 Oct 2006 01:11:05 -0000 1.10 +++ html_get.h 30 Nov 2006 00:32:51 -0000 1.11 @@ -53,22 +53,22 @@ class html_get { private: - iostream & itsIo; + SmartUtil::tiostream & itsIo; public: // Constructor parses until it finds a <form> tag. // - html_get( iostream & io, bool & ok ) + html_get( SmartUtil::tiostream & io, bool & ok ) : itsIo( io ) { ok = false; - string tag; + SmartUtil::tstring tag; do { itsIo >> tag; if ( 0 == tag.size() ) return; - } while ( "<form>" != tag ); + } while ( _T("<form>") != tag ); ok = true; } @@ -79,11 +79,11 @@ // bool get_string( SmartUtil::tstring & text ) { - string tag; + SmartUtil::tstring tag; itsIo >> tag; - if ( "<p>" != tag ) return false; + if ( _T("<p>") != tag ) return false; - return( parse_until( "</p>", text ) ); + return( parse_until( _T("</p>"), text ) ); } //------------------------------------------------------------------------- @@ -119,16 +119,16 @@ // bool getTaggedText( const SmartUtil::tstring & tagExpected, SmartUtil::tstring & value ) { - string tag, checkname; + SmartUtil::tstring tag, checkname; itsIo >> tag; - if ( "<input" != tag ) return false; + if ( _T("<input") != tag ) return false; itsIo >> tag; - if ( "type=text" != tag ) return false; + if ( _T("type=text") != tag ) return false; itsIo >> tag; - SmartUtil::tstring taglabel= "name=\""; - taglabel += tagExpected; taglabel += "\""; + SmartUtil::tstring taglabel= _T("name=\""); + taglabel += tagExpected; taglabel += _T("\""); if ( taglabel != tag ) return false; @@ -136,7 +136,7 @@ if ( ! parse_quoted_string_value( tag, value ) ) return false; - itsIo >> tag; if ( ">" != tag ) return false; + itsIo >> tag; if ( _T(">") != tag ) return false; return true; } @@ -150,18 +150,18 @@ // bool get_val_of_text( int & value ) { - string tag, checkname; + SmartUtil::tstring tag, checkname; itsIo >> tag; - if ( "<input" != tag ) return false; + if ( _T("<input") != tag ) return false; itsIo >> tag; - if ( "type=text" != tag ) return false; + if ( _T("type=text") != tag ) return false; itsIo >> tag; // value="43" if ( ! parse_quoted_numeric_value( tag, value ) ) return false; - itsIo >> tag; if ( ">" != tag ) return false; + itsIo >> tag; if ( _T(">") != tag ) return false; return true; } @@ -206,33 +206,33 @@ template< class Parent, class MessageMapPolicy > bool get( SmartWin::WidgetComboBox< Parent, MessageMapPolicy > * inComboBox ) { - string tag, value; + SmartUtil::tstring tag, value; itsIo >> tag; - if ( "<select>" != tag ) return false; + if ( _T("<select>") != tag ) return false; inComboBox->removeAllItems(); int dex = 0; bool selected = false; itsIo >> tag; - while ( "</select>" != tag ) + while ( _T("</select>") != tag ) { - if ( "<option" != tag ) return false; + if ( _T("<option") != tag ) return false; // Skip until > itsIo >> value >> tag; - if ( ">" != tag ) + if ( _T(">") != tag ) { - if ( "selected" == tag ) + if ( _T("selected") == tag ) { selected = true; // Remember this index was selected. itsIo >> tag; - if ( ">" != tag ) return false; + if ( _T(">") != tag ) return false; } else return false; // wanted ">" or "selected" } - if ( ! parse_until( "</option>", value ) ) + if ( ! parse_until( _T("</option>"), value ) ) return false; // Add the data string to the ComboBox @@ -258,21 +258,21 @@ template< class Parent, class MessageMapPolicy > bool get( SmartWin::WidgetCheckBox< Parent, MessageMapPolicy > * inCheckBox ) { - string tag, checkname; + SmartUtil::tstring tag, checkname; itsIo >> tag; - if ( "<input" != tag ) return false; + if ( _T("<input") != tag ) return false; itsIo >> tag; - if ( "type=checkbox" != tag ) return false; + if ( _T("type=checkbox") != tag ) return false; itsIo >> tag; - if ( "value=" == tag ) + if ( _T("value=") == tag ) { inCheckBox->setChecked( false ); } else { - if ( "checked" == tag ) + if ( _T("checked") == tag ) { inCheckBox->setChecked(); } @@ -280,10 +280,10 @@ return false; // wanted "value=" or "checked" } - if ( ! parse_until( ">", checkname ) ) //Discard until > + if ( ! parse_until( _T(">"), checkname ) ) //Discard until > return false; - if ( ! parse_until( "</input>", checkname ) ) // grab until </input> + if ( ! parse_until( _T("</input>"), checkname ) ) // grab until </input> return false; inCheckBox->setText( checkname ); @@ -297,9 +297,9 @@ template< class Parent, class MessageMapPolicy > bool get( SmartWin::WidgetDataGrid< Parent, MessageMapPolicy > * inWidgetDataGrid ) { - string tag; + SmartUtil::tstring tag; itsIo >> tag; - if ( "<table>" != tag ) return false; + if ( _T("<table>") != tag ) return false; bool end_table; vector< SmartUtil::tstring > colnames, rowvals; @@ -331,9 +331,9 @@ template< class Parent, class MessageMapPolicy > bool get( SmartWin::WidgetTreeView< Parent, MessageMapPolicy > * wtv ) { - string tag; + SmartUtil::tstring tag; itsIo >> tag; - if ( "<ul>" != tag ) return false; + if ( _T("<ul>") != tag ) return false; wtv->DeleteAllItems(); @@ -382,31 +382,31 @@ { end_table = false; - string tag, data, token, endtag; + SmartUtil::tstring tag, data, token, endtag; itsIo >> tag; - if ( tag != "<tr>" ) + if ( tag != _T("<tr>") ) { - end_table = tag == "</table>"; + end_table = tag == _T("</table>"); return( false ); } while ( true ) { itsIo >> tag; - if ( ( tag != "<td>" ) && ( tag != "<th>" ) ) + if ( ( tag != _T("<td>") ) && ( tag != _T("<th>") ) ) { - return ( tag == "</tr>" ); + return ( tag == _T("</tr>") ); } itsIo >> data; - if ( data == "</td>" ) + if ( data == _T("</td>") ) { - data = ""; + data = _T(""); } else { itsIo >> endtag; - while ( ( endtag != "</td>" ) && ( endtag != "</th>" ) ) + while ( ( endtag != _T("</td>") ) && ( endtag != _T("</th>") ) ) { data += _T( " " ); data += endtag; @@ -427,18 +427,18 @@ bool html_get_treenode( SmartWin::WidgetTreeView< Parent, MessageMapPolicy > * wtv, TreeViewNode node, int & dex ) { - string tag; + SmartUtil::tstring tag; TreeViewNode childnode; do { itsIo >> tag; - if ( "<li>" == tag ) + if ( _T("<li>") == tag ) { // Parse data in: <li> data </li> - string data; - if ( ! parse_until( "</li>", data ) ) + SmartUtil::tstring data; + if ( ! parse_until( _T("</li>"), data ) ) { return false; } @@ -448,7 +448,7 @@ continue; } - if ( "<ul>" == tag ) + if ( _T("<ul>") == tag ) { if ( html_get_treenode( wtv, childnode, dex ) ) { @@ -460,7 +460,7 @@ } } - if ( "</ul>" == tag ) + if ( _T("</ul>") == tag ) { break; } @@ -476,10 +476,10 @@ // Parses whitespace seperated text until the endtag occurs. // arbitrary whitespace is represented by one space. // - bool parse_until( string endtag, string & data ) + bool parse_until( SmartUtil::tstring endtag, SmartUtil::tstring & data ) { data.clear(); - string moredata; + SmartUtil::tstring moredata; while ( true ) { itsIo >> moredata; @@ -506,7 +506,7 @@ // Given a valstr of: value="valstring" // set inquotes to be: valstring // - bool parse_quoted_string_value( const string & valstr, string & inquotes ) + bool parse_quoted_string_value( const SmartUtil::tstring & valstr, SmartUtil::tstring & inquotes ) { string::size_type first_num = valstr.find( '"' ); if ( first_num == string::npos ) return false; @@ -523,13 +523,13 @@ // Extract the number from a string: value="12" // - bool parse_quoted_numeric_value( const string & valstr, int & val ) + bool parse_quoted_numeric_value( const SmartUtil::tstring & valstr, int & val ) { - string inquotes; + SmartUtil::tstring inquotes; bool ok= parse_quoted_string_value( valstr, inquotes ); if ( ! ok ) return false; - stringstream ss( inquotes ); + SmartUtil::tstringstream ss( inquotes ); ss >> val; return true; } Index: InDialog.h =================================================================== RCS file: /cvsroot/smartwin/SmartWin/include/io/InDialog.h,v retrieving revision 1.11 retrieving revision 1.12 diff -u -d -r1.11 -r1.12 --- InDialog.h 9 Oct 2006 01:11:05 -0000 1.11 +++ InDialog.h 30 Nov 2006 00:32:51 -0000 1.12 @@ -62,7 +62,7 @@ bool bool1= true; COLORREF background= RGB( 20, 40, 80 ); - ChoiceString cs( "scissors|rock|paper", 2 ); + ChoiceString cs( _T("scissors|rock|paper"), 2 ); FileString loadFs( "C:\\path\\gumbo.txt" ); loadFs.addFilter( "JPG files", "*.jpg" ); @@ -446,8 +446,10 @@ // Catch failure to pass in a supported type // so that itsPrompts and itsVariables stay coherent. + // Although type().name() is a mem leak, this is a fatal error anyhow. + // SmartUtil::tstring msg( _T("InDialog unsupported type: ") ); - msg += itsVariables.at( b ).type().name(); + appendTo( msg, itsVariables.at( b ).type().name() ); addPromptAndText( itsPrompts.at( b ), msg, 0 ); } @@ -646,10 +648,10 @@ float fract = maxLabel.x / (float)(maxLabel.x + maxInputArea.x); int rowWidth= 2 * pos_size.size.x; pos_sizeLabel= pos_size; - pos_sizeLabel.size.x= rowWidth * fract; + pos_sizeLabel.size.x= (long)(rowWidth * fract); pos_sizeInput= pos_size; - pos_sizeInput.size.x= rowWidth * (1.0 - fract); + pos_sizeInput.size.x= (long) (rowWidth * (1.0 - fract)); } // Allocate space for each widget in the dialog @@ -749,6 +751,17 @@ return valid; } + + void appendTo( SmartUtil::tstring & dest, const char * zeroTermTxt ) + { + const char * beg= zeroTermTxt; + const char * end= zeroTermTxt + strlen(zeroTermTxt); + dest += SmartUtil::tstring( beg, end ); + } + + + + // The OK button has been pressed, so transfer all the values back into the // variables. But don't exit the dialog until all rows satisfy their // constraints. |