Getting Contents of wxRichTextCtrl

If you are using wxDev-C++ for your wxWidgets design, please ask your questions here instead of in IDE Related.
Post Reply
Budee
In need of some credit
In need of some credit
Posts: 3
Joined: Fri Mar 21, 2008 1:23 pm

Getting Contents of wxRichTextCtrl

Post by Budee » Sat Mar 22, 2008 4:46 pm

I'm trying to store the contents I made including the edits I made into a file. Same problem here. http://forums.wxwidgets.org/viewtopic.p ... extcontrol but instead I want to know how to implement things on my program as a file dialog(Opening and Saving).

Here is my Save and Open File Code:

Code: Select all

void JMCFrm::Mnusave1004Click(wxCommandEvent& WXUNUSED(event))
{
    wxString path;
    wxString filename;
    wxArrayInt fileTypes;

    wxString filter = wxRichTextBuffer::GetExtWildcard(false, true, &fileTypes);

    wxFileDialog dialog(this,
        _("Choose a filename"),
        path,
        filename,
        _T("All Files(*.*)|*.*"),
        wxFD_SAVE);

    if (dialog.ShowModal() == wxID_OK)
    {
        wxString path = dialog.GetPath();

        if (!path.empty())
        {
            int filterIndex = dialog.GetFilterIndex();
            int fileType = (filterIndex < (int) fileTypes.GetCount())
                           ? fileTypes[filterIndex]
                           : wxRICHTEXT_TYPE_TEXT;
            WxRichTextCtrl1->DoSaveFile(path, fileType);
        }
    }
}

void JMCFrm::Mnuopen1005Click(wxCommandEvent& event)
{
    wxString path;
    wxString filename;
    wxArrayInt fileTypes;

    wxString filter = wxRichTextBuffer::GetExtWildcard(false, false, & fileTypes);
    if (!filter.empty())
        filter += wxT("|");
    filter += wxT("All files (*.*)|*.*");

    wxFileDialog dialog(this,
        _("Choose a filename"),
        path,
        filename,
        filter,
        wxFD_OPEN);

    if (dialog.ShowModal() == wxID_OK)
    {
        wxString path = dialog.GetPath();

        if (!path.empty())
        {
            int filterIndex = dialog.GetFilterIndex();
            int fileType = (filterIndex < (int) fileTypes.GetCount())
                           ? fileTypes[filterIndex]
                           : wxRICHTEXT_TYPE_TEXT;
            WxRichTextCtrl1->LoadFile(path, fileType);
        }
    }
}
This code lets me save and open files, but whenever I save and open my file it only retains the text and not the color, style, etc.

protocol
Moderator
Moderator
Posts: 680
Joined: Wed Jan 18, 2006 6:13 pm
Location: Dallas, TX
Contact:

Post by protocol » Sun Apr 06, 2008 12:46 am

Nice reference link.
http://forums.wxwidgets.org/viewtopic.php?p=63401#63401

Try: wxRICHTEXT_TYPE_HTML

Code: Select all

    // Add extra handlers for XML & HTML (plain text is implicitly added)
    wxRichTextBuffer::AddHandler(new wxRichTextXMLHandler);
    wxRichTextBuffer::AddHandler(new wxRichTextHTMLHandler);
wxRICHTEXT_TYPE_TEXT is plain text, with no styles.

regards.
/* UIKit && wxWidgets 2.8 && Cocoa && .Net */
QuRegExmm
wxPCRE & ObjPCRE - Regex It!

Post Reply