Example #1
0
/// Helper for listbox and combo control
wxString wxRichTextStyleListBox::GetStyleToShowInIdleTime(wxRichTextCtrl* ctrl, wxRichTextStyleType styleType)
{
    int adjustedCaretPos = ctrl->GetAdjustedCaretPosition(ctrl->GetCaretPosition());

    wxString styleName;

    wxRichTextAttr attr;
    ctrl->GetStyle(adjustedCaretPos, attr);

    // Take into account current default style just chosen by user
    if (ctrl->IsDefaultStyleShowing())
    {
        wxRichTextApplyStyle(attr, ctrl->GetDefaultStyleEx());

        if ((styleType == wxRICHTEXT_STYLE_ALL || styleType == wxRICHTEXT_STYLE_CHARACTER) &&
                          !attr.GetCharacterStyleName().IsEmpty())
            styleName = attr.GetCharacterStyleName();
        else if ((styleType == wxRICHTEXT_STYLE_ALL || styleType == wxRICHTEXT_STYLE_PARAGRAPH) &&
                          !attr.GetParagraphStyleName().IsEmpty())
            styleName = attr.GetParagraphStyleName();
        else if ((styleType == wxRICHTEXT_STYLE_ALL || styleType == wxRICHTEXT_STYLE_LIST) &&
                          !attr.GetListStyleName().IsEmpty())
            styleName = attr.GetListStyleName();
        // TODO: when we have a concept of focused object (text box), we'll
        // use the paragraph style name of the focused object as the frame style name.
#if 0
        else if ((styleType == wxRICHTEXT_STYLE_ALL || styleType == wxRICHTEXT_STYLE_BOX) &&
                          !attr.GetBoxStyleName().IsEmpty())
            styleName = attr.GetBoxStyleName();
#endif
    }
    else if ((styleType == wxRICHTEXT_STYLE_ALL || styleType == wxRICHTEXT_STYLE_CHARACTER) &&
             !attr.GetCharacterStyleName().IsEmpty())
    {
        styleName = attr.GetCharacterStyleName();
    }
    else if ((styleType == wxRICHTEXT_STYLE_ALL || styleType == wxRICHTEXT_STYLE_PARAGRAPH) &&
             !attr.GetParagraphStyleName().IsEmpty())
    {
        styleName = attr.GetParagraphStyleName();
    }
    else if ((styleType == wxRICHTEXT_STYLE_ALL || styleType == wxRICHTEXT_STYLE_LIST) &&
             !attr.GetListStyleName().IsEmpty())
    {
        styleName = attr.GetListStyleName();
    }

    return styleName;
}
Example #2
0
/// Helper for listbox and combo control
wxString wxRichTextStyleListBox::GetStyleToShowInIdleTime(wxRichTextCtrl* ctrl, wxRichTextStyleType styleType)
{
    int adjustedCaretPos = ctrl->GetAdjustedCaretPosition(ctrl->GetCaretPosition());

    wxRichTextParagraph* para = ctrl->GetBuffer().GetParagraphAtPosition(adjustedCaretPos);
    wxRichTextObject* obj = ctrl->GetBuffer().GetLeafObjectAtPosition(adjustedCaretPos);

    wxString styleName;

    // Take into account current default style just chosen by user
    if (ctrl->IsDefaultStyleShowing())
    {
        wxTextAttrEx attr;

        ctrl->GetStyle(adjustedCaretPos, attr);
        wxRichTextApplyStyle(attr, ctrl->GetDefaultStyleEx());

        if ((styleType == wxRICHTEXT_STYLE_ALL || styleType == wxRICHTEXT_STYLE_CHARACTER) &&
                          !attr.GetCharacterStyleName().IsEmpty())
            styleName = attr.GetCharacterStyleName();
        else if ((styleType == wxRICHTEXT_STYLE_ALL || styleType == wxRICHTEXT_STYLE_PARAGRAPH) &&
                          !attr.GetParagraphStyleName().IsEmpty())
            styleName = attr.GetParagraphStyleName();
        else if ((styleType == wxRICHTEXT_STYLE_ALL || styleType == wxRICHTEXT_STYLE_LIST) &&
                          !attr.GetListStyleName().IsEmpty())
            styleName = attr.GetListStyleName();
    }
    else if (obj && (styleType == wxRICHTEXT_STYLE_ALL || styleType == wxRICHTEXT_STYLE_CHARACTER) &&
             !obj->GetAttributes().GetCharacterStyleName().IsEmpty())
    {
        styleName = obj->GetAttributes().GetCharacterStyleName();
    }
    else if (para && (styleType == wxRICHTEXT_STYLE_ALL || styleType == wxRICHTEXT_STYLE_PARAGRAPH) &&
             !para->GetAttributes().GetParagraphStyleName().IsEmpty())
    {
        styleName = para->GetAttributes().GetParagraphStyleName();
    }
    else if (para && (styleType == wxRICHTEXT_STYLE_ALL || styleType == wxRICHTEXT_STYLE_LIST) &&
             !para->GetAttributes().GetListStyleName().IsEmpty())
    {
        styleName = para->GetAttributes().GetListStyleName();
    }

    return styleName;
}