User forums > General (but related to Code::Blocks)

Compile errors

<< < (2/2)

Ceniza:
Well, that error happened so many times to me, but it was with an older version of wxWidgets IIRC.

The problem is operator [] for wxString is overloaded for both int and size_t, and GetInsertionPoint() returns long. The compiler doesn't know if it should convert that long to int or to size_t, then the ambiguity.

Try this:


--- Code: ---m_pTextCtrl->GetValue()[static_cast<int>(m_pTextCtrl->GetInsertionPoint())];
--- End code ---

If that doesn't help, then try:


--- Code: ---int insertionPoint = m_pTextCtrl->GetInsertionPoint();
m_pTextCtrl->GetValue()[insertionPoint];
--- End code ---

sethjackson:
Ok I get it now. Here is my code. Compiles with no erros now. Thanks Ceniza and mandrav. :)


--- Code: ---wxString MainFrame::TextToHTML()
{
    const wxString sOO = "00";
    const wxString s8O = "80";
    const wxString sFF = "FF";

    wxString htmlString;

    htmlString << "<html><head><title></title></head><body><tt>";

    long max = m_pTextCtrl->GetLastPosition();

    wxTextAttr style, oldStyle;

    wxChar ch;

    for(long pos = 0; pos < max; pos++)
    {
        m_pTextCtrl->GetStyle(pos, style);

       //if(style != oldStyle)
       //{
            if(pos > 0)
            {
                htmlString << "</font>";
            }

            wxString sR, sG, sB;

            wxColour colour = style.GetTextColour();

            sR.Printf("%02X", colour.Red());
            sG.Printf("%02X", colour.Green());
            sB.Printf("%02X", colour.Blue());

            htmlString << "<font color = \"#" << sR << sG << sB << "\">"; ;
        //}

        if (m_pTextCtrl->GetInsertionPoint() == max)
        {
            return htmlString;
        }

        else
        {
            ch = m_pTextCtrl->GetValue()[static_cast<int>(pos)];
        }

        switch(ch)
        {
            case '\n':
            {
                htmlString << "\n<br>";
            }
            break;

            case '<':
            {
                htmlString << "&lt;";
            }
            break;

            case '&':
            {
                htmlString << "&amp;";
            }
            break;

            case ' ':
            {
                htmlString << "&nbsp;";
            }
            break;

            default:
            {
                htmlString << ch;
            }
            break;
        }

        oldStyle = style;
    }

    htmlString << "</font></tt></body></html>";

    return htmlString;
}

--- End code ---


One more question. :)

Is there any way to compare wxTextAttr's? I need to check if one is different than the other. What is the best way of doing this?
See the commented out part. :)

sethjackson:
Ah nevermind here is the code. :)


--- Code: ---wxString MainFrame::TextToHTML()
{
    wxString htmlString;

    htmlString << "<html><head><title></title></head><body>";

    long max = m_pTextCtrl->GetLastPosition();

    wxTextAttr style, oldStyle;

    wxChar ch;

    for(long pos = 0; pos < max; pos++)
    {
        ch = m_pTextCtrl->GetValue()[static_cast<int>(pos)];

        switch(ch)
        {
            case '\n':
            {
                htmlString << "<br />";
            }
            break;

            case '<':
            {
                htmlString << "&lt;";
            }
            break;

            case '&':
            {
                htmlString << "&amp;";
            }
            break;

            case ' ':
            {
                htmlString << "&nbsp;";
            }
            break;

            default:
            {
                htmlString << ch;
            }
            break;
        }

        oldStyle = style;
    }

    htmlString << "</body></html>";

    return htmlString;
}

--- End code ---

Navigation

[0] Message Index

[*] Previous page

Go to full version