Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

wxWidgets and TinyXML

Name: Anonymous 2007-12-21 22:47

I'm having a bit of trouble saving formatted text from a wxRichTextBox control. I don't normally go to forums for help, but I'm depressed and cloudy-headed today and I feel like being called a faggot. Here's how I'm doing it now:


// Create the XML document and ready it to be appended.
   TiXmlDocument xmlDocument;
   TiXmlDeclaration* p_decDeclaration = new TiXmlDeclaration( "1.0", "", "" );
   xmlDocument.LinkEndChild( p_decDeclaration );

   // Create the story and body sections.
   TiXmlElement* p_xleStory = new TiXmlElement( "story" );
   xmlDocument.LinkEndChild( p_xleStory );
   TiXmlElement* p_xleStoryBody = new TiXmlElement( "body" );
   p_xleStory->LinkEndChild( p_xleStoryBody );

   // Parse the text box character by character, build strings of like-
   // formatted characters, and link them to the story's body text as
   // children nodes.
   //TiXmlText* p_xltBody = new TiXmlText( (char*)p_txtMain->GetValue().char_str() );
   //p_xleStoryBody->LinkEndChild( p_xltBodyLine );
   TiXmlText* p_xltBodyLine = NULL;
   wxString strChildBuffer;
   //TiXmlNode* p_xleBodyTextParentNew = NULL;
   TiXmlNode* p_xleBodyTextParent = p_xleStoryBody;
   for( unsigned long intCountPos = 1 ; intCountPos < p_txtMain->GetValue().Len() ; intCountPos++ ) {


      wxRichTextAttr atrCurrent;
      wxRichTextAttr atrPrevious;
      p_txtMain->GetStyle( intCountPos, atrCurrent );
      p_txtMain->GetStyle( intCountPos - 1, atrPrevious );

      // Using this arrangement, bold will always be "outermost".

      if( atrCurrent.HasFontWeight() == true && atrPrevious.HasFontWeight() == false ) {
         // Finish up the current child.
         p_xltBodyLine = new TiXmlText( (char*)strChildBuffer.char_str() );
         p_xleBodyTextParent->LinkEndChild( p_xltBodyLine );

         // Bold has just been turned on.
         TiXmlElement* p_xleBodyTextParentNew = new TiXmlElement( "strong" );
         p_xleBodyTextParent->LinkEndChild( p_xleBodyTextParentNew );
         p_xleBodyTextParent = p_xleBodyTextParentNew;

         // Clean up.
         strChildBuffer = _( "" );
         p_xltBodyLine = NULL;
      }

      if( atrCurrent.HasFontItalic() == true && atrPrevious.HasFontItalic() == false ) {
         // Finish up the current child.
         p_xltBodyLine = new TiXmlText( (char*)strChildBuffer.char_str() );
         p_xleBodyTextParent->LinkEndChild( p_xltBodyLine );

         // Italic text has just been turned on.
         TiXmlElement* p_xleBodyTextParentNew = new TiXmlElement( "em" );
         p_xleBodyTextParent->LinkEndChild( p_xleBodyTextParentNew );
         p_xleBodyTextParent = p_xleBodyTextParentNew;

         // Clean up.
         strChildBuffer = _( "" );
         p_xltBodyLine = NULL;
      }

      if( atrCurrent.HasFontItalic() == false && atrPrevious.HasFontItalic() == true ) {
         // Finish up the current child.
         p_xltBodyLine = new TiXmlText( (char*)strChildBuffer.char_str() );
         p_xleBodyTextParent->LinkEndChild( p_xltBodyLine );

         // Italic text has just been turned off.
         p_xleBodyTextParent = p_xleBodyTextParent->Parent();

         // Clean up.
         strChildBuffer = _( "" );
         p_xltBodyLine = NULL;
      }

      if( atrCurrent.HasFontWeight() == false && atrPrevious.HasFontWeight() == true ) {
         // Finish up the current child.
         p_xltBodyLine = new TiXmlText( (char*)strChildBuffer.char_str() );
         p_xleBodyTextParent->LinkEndChild( p_xltBodyLine );

         // Bold text has just been turned off.
         p_xleBodyTextParent = p_xleBodyTextParent->Parent();

         // Clean up.
         strChildBuffer = _( "" );
         p_xltBodyLine = NULL;
      }

      // Now that we've dealt with the last of that buffer, start building
      // anew.
      strChildBuffer.Append( p_txtMain->GetValue().Mid( intCountPos, intCountPos + 1 ) );
   }

   xmlDocument.SaveFile( (char*)strFilePathIn.char_str() );


Needless to say, it doesn't work. I don't think I understand the RichText control well enough, despite the documentation. Or my algorithm's just stupid. How would you do this, /prog/?

Name: Anonymous 2007-12-21 22:55

MY EYES

Name: Anonymous 2007-12-21 23:07

being called a faggot
The only cure for depression? I think so.

Name: Anonymous 2007-12-21 23:10

Break it up into functions, faggot. And never type "p_xl" again.

Name: Anonymous 2007-12-22 0:56

ENTERPRISE QUALITY

Name: Anonymous 2007-12-22 12:09

TiXmlDocument xmldocument; TiXmlDeclaration, p xltbodyline TiXmlElement,
story p decdeclaration new TiXmlDeclaration p xlebodytextparent Parent,
strchildbuffer p xlebodytextparent p xlebodytextparentnew new
TiXmlElement new TiXmlText, TiXmlElement, story p decdeclaration new
TiXmlElement, story p xlebodytextparent p char str, p xlestory
TiXmlElement p txtmain GetStyle, GetValue, Len, intcountpos atrprevious
p xltbodyline NULL.  TiXmlDocument xmldocument: TiXmlDeclaration, p
xlebodytextparent p decdeclaration new TiXmlElement body p txtmain
GetValue (Len, intcountpos intcountpos intcountpos p txtmain GetStyle
intcountpos intcountpos wxrichtextattr atrcurrent p xltbodyline NULL:
xlebodytextparent p xltbodyline p txtmain GetStyle intcountpos
atrprevious).

Name: Anonymous 2007-12-22 12:16

>>6
He didn't ask for VALID PERL CODE.

Name: Anonymous 2007-12-22 12:18

Hi. Have you noticed that you're just repeating the same crap over and over? Human beings suck at interpreting such things. Fix that and your problem will be solved almost automatically (probably even you will be able to do it).

Name: Anonymous 2007-12-22 15:06

>>8
repeating the same crap over and over
I can interpret /prog/ very well, thank you.

Name: Anonymous 2009-03-06 9:52

The NUMBER CHOOSEN BY   THE COMPUTER IS   locked down is   nice if people   are putting this   script together Couple   that with some   stuff changed Most.

Name: Anonymous 2011-01-31 21:26

<-- check em dubz

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List