paragui-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re[9]: [paragui-users] RICHEDIT


From: taurus
Subject: Re[9]: [paragui-users] RICHEDIT
Date: Fri, 13 Sep 2002 10:33:45 +0100

Hello Eric,

Thursday, September 12, 2002, 6:13:51 AM, you wrote:

>> BTW, sometime ago someone wanted to add text to the widget, without
>> re-parsing it. I`ve made it, so if anybody interested, I will post the
>> patch.

ER> Could you post your patch here ? It would be cool adding text without 
reparsing
ER> it. (unified diff please :)

Sorry, I don`t have time to do it properly, I`m sending a bit of
modified pgrichedit.cpp:


void PG_RichEdit::SetText(const std::string &text) {
        my_text = text;
>>      my_ParsedWords.clear(); //new line - clean all words
        ParseWords();
        CompleteLines();
}

void PG_RichEdit::SetText(const char *text) {
        PG_Widget::SetText(text);
>>        my_ParsedWords.clear();  //new line - clean all words
        ParseWords();
        CompleteLines();
}

//New function to *add* text
void PG_RichEdit::AddText(const std::string &text) {
        my_text = text;
        ParseWords();
        CompleteLines();
}

//New function to *add* text
void PG_RichEdit::AddText(const char *text) {
        PG_Widget::SetText(text);
        ParseWords();
        CompleteLines();
}

void PG_RichEdit::ParseWords() {
        size_t searchFrom = 0;
        std::string word;

>>        //my_ParsedWords.clear();  this line cleans the collection of
>>        //words, so I removed it here

        do {
                RichWordDescription wordDescr;
                Uint16 w, h, sw = 0;
                int bl, ls;
                bool space = false;

                searchFrom = GetWord(searchFrom, &word, &wordDescr.my_EndMark);

                int length = word.length();
                if (length > 0) {
                        if (word[length - 1] == ' ') {
                                space = true;
                                word.erase(length-1, 1);
                        }
                }
                PG_FontEngine::GetTextSize(word.c_str(), GetFont(), &w, &h, 
&bl, &ls, NULL, NULL, NULL);
                wordDescr.my_Width = w;
                if (space) {
                        word += ' ';
                        PG_FontEngine::GetTextSize(" ", GetFont(), &sw);
                }
                wordDescr.my_Word = word;
                wordDescr.my_EndSpaceWidth = sw;
                wordDescr.my_WidthAfterFormating = w + sw;
                wordDescr.my_Height = h;
                wordDescr.my_BaseLine = bl;
                wordDescr.my_LineSkip = ls;

                my_ParsedWords.push_back(wordDescr);

                if ((searchFrom != std::string::npos) && (searchFrom < 
my_text.length()))
                        searchFrom++;
                else
                        break;
>>                word = "" //bug fix for additional word in the end
>>                          //of the paragraph
        } while (true);
}



Kind regards,
       taurus                          

address@hidden

 ->> "If you will have a megaphone, you will never have to be alone..."






reply via email to

[Prev in Thread] Current Thread [Next in Thread]