コード例 #1
0
ファイル: richtextstyles.cpp プロジェクト: hgwells/tive
// Get style for index
wxRichTextStyleDefinition* wxRichTextStyleListBox::GetStyle(size_t i) const
{
    if (!GetStyleSheet())
        return NULL;

    if (i >= m_styleNames.GetCount() /* || i < 0 */ )
        return NULL;

    return GetStyleSheet()->FindStyle(m_styleNames[i]);
}
コード例 #2
0
ファイル: richtextstyles.cpp プロジェクト: 3v1n0/wxWidgets
/// Updates the list
void wxRichTextStyleListBox::UpdateStyles()
{
    if (GetStyleSheet())
    {
        int oldSel = GetSelection();

        SetSelection(wxNOT_FOUND);

        m_styleNames.Clear();

        size_t i;
        if (GetStyleType() == wxRICHTEXT_STYLE_ALL || GetStyleType() == wxRICHTEXT_STYLE_PARAGRAPH)
        {
            for (i = 0; i < GetStyleSheet()->GetParagraphStyleCount(); i++)
                m_styleNames.Add(GetStyleSheet()->GetParagraphStyle(i)->GetName() + wxT("|P"));
        }
        if (GetStyleType() == wxRICHTEXT_STYLE_ALL || GetStyleType() == wxRICHTEXT_STYLE_CHARACTER)
        {
            for (i = 0; i < GetStyleSheet()->GetCharacterStyleCount(); i++)
                m_styleNames.Add(GetStyleSheet()->GetCharacterStyle(i)->GetName() + wxT("|C"));
        }
        if (GetStyleType() == wxRICHTEXT_STYLE_ALL || GetStyleType() == wxRICHTEXT_STYLE_LIST)
        {
            for (i = 0; i < GetStyleSheet()->GetListStyleCount(); i++)
                m_styleNames.Add(GetStyleSheet()->GetListStyle(i)->GetName() + wxT("|L"));
        }
        if (GetStyleType() == wxRICHTEXT_STYLE_ALL || GetStyleType() == wxRICHTEXT_STYLE_BOX)
        {
            for (i = 0; i < GetStyleSheet()->GetBoxStyleCount(); i++)
                m_styleNames.Add(GetStyleSheet()->GetBoxStyle(i)->GetName() + wxT("|B"));
        }

        m_styleNames.Sort();
        SetItemCount(m_styleNames.GetCount());

        Refresh();

        int newSel = -1;
        if (oldSel >= 0 && oldSel < (int) GetItemCount())
            newSel = oldSel;
        else if (GetItemCount() > 0)
            newSel = 0;

        if (newSel >= 0)
        {
            SetSelection(newSel);
            SendSelectedEvent();
        }
    }
    else
    {
        m_styleNames.Clear();
        SetSelection(wxNOT_FOUND);
        SetItemCount(0);
        Refresh();
    }
}
コード例 #3
0
ファイル: richtextstyles.cpp プロジェクト: hgwells/tive
/// Returns the HTML for this item
wxString wxRichTextStyleListBox::OnGetItem(size_t n) const
{
    if (!GetStyleSheet())
        return wxEmptyString;

    wxRichTextStyleDefinition* def = GetStyle(n);
    if (def)
        return CreateHTML(def);

    return wxEmptyString;
}
コード例 #4
0
void ElementStyle::UpdateDefinition()
{
	if (definition_dirty)
	{
		definition_dirty = false;
		
		ElementDefinition* new_definition = NULL;
		
		const StyleSheet* style_sheet = GetStyleSheet();
		if (style_sheet != NULL)
		{
			new_definition = style_sheet->GetElementDefinition(element);
		}
		
		// Switch the property definitions if the definition has changed.
		if (new_definition != definition || new_definition == NULL)
		{
			PropertyNameList properties;
			
			if (definition != NULL)
			{
				definition->GetDefinedProperties(properties, pseudo_classes);
				definition->RemoveReference();
			}
			
			definition = new_definition;
			
			if (definition != NULL)
				definition->GetDefinedProperties(properties, pseudo_classes);
			
			DirtyProperties(properties);
			element->GetElementDecoration()->ReloadDecorators();
		}
		else if (new_definition != NULL)
		{
			new_definition->RemoveReference();
		}
	}
	
	if (child_definition_dirty)
	{
		for (int i = 0; i < element->GetNumChildren(true); i++)
		{
			element->GetChild(i)->GetStyle()->UpdateDefinition();
		}
		
		child_definition_dirty = false;
	}
}
コード例 #5
0
ファイル: richtextstyles.cpp プロジェクト: hgwells/tive
/// Updates the list
void wxRichTextStyleListBox::UpdateStyles()
{
    if (GetStyleSheet())
    {
        SetSelection(wxNOT_FOUND);

        m_styleNames.Clear();

        size_t i;
        if (GetStyleType() == wxRICHTEXT_STYLE_ALL || GetStyleType() == wxRICHTEXT_STYLE_PARAGRAPH)
        {
            for (i = 0; i < GetStyleSheet()->GetParagraphStyleCount(); i++)
                m_styleNames.Add(GetStyleSheet()->GetParagraphStyle(i)->GetName());
        }
        if (GetStyleType() == wxRICHTEXT_STYLE_ALL || GetStyleType() == wxRICHTEXT_STYLE_CHARACTER)
        {
            for (i = 0; i < GetStyleSheet()->GetCharacterStyleCount(); i++)
                m_styleNames.Add(GetStyleSheet()->GetCharacterStyle(i)->GetName());
        }
        if (GetStyleType() == wxRICHTEXT_STYLE_ALL || GetStyleType() == wxRICHTEXT_STYLE_LIST)
        {
            for (i = 0; i < GetStyleSheet()->GetListStyleCount(); i++)
                m_styleNames.Add(GetStyleSheet()->GetListStyle(i)->GetName());
        }

        m_styleNames.Sort();
        SetItemCount(m_styleNames.GetCount());

        Refresh();

        if (GetItemCount() > 0)
        {
            SetSelection(0);
            SendSelectedEvent();
        }
    }
}
コード例 #6
0
ファイル: richtextstyles.cpp プロジェクト: 3v1n0/wxWidgets
// Get style for index
wxRichTextStyleDefinition* wxRichTextStyleListBox::GetStyle(size_t i) const
{
    if (!GetStyleSheet())
        return NULL;

    if (i >= m_styleNames.GetCount() /* || i < 0 */ )
        return NULL;

    wxString styleType = wxGetRichTextStyleType(m_styleNames[i]);
    wxString style = wxGetRichTextStyle(m_styleNames[i]);
    if (styleType == wxT("P"))
        return GetStyleSheet()->FindParagraphStyle(style);
    else if (styleType == wxT("C"))
        return GetStyleSheet()->FindCharacterStyle(style);
    else if (styleType == wxT("L"))
        return GetStyleSheet()->FindListStyle(style);
    else if (styleType == wxT("B"))
        return GetStyleSheet()->FindBoxStyle(style);
    else
        return GetStyleSheet()->FindStyle(style);
}
コード例 #7
0
ファイル: richtextstyles.cpp プロジェクト: hgwells/tive
/// Creates a suitable HTML fragment for a definition
wxString wxRichTextStyleListBox::CreateHTML(wxRichTextStyleDefinition* def) const
{
    // TODO: indicate list format for list style types

    wxString str;

    bool isCentred = false;

    wxRichTextAttr attr(def->GetStyleMergedWithBase(GetStyleSheet()));

    if (attr.HasAlignment() && attr.GetAlignment() == wxTEXT_ALIGNMENT_CENTRE)
        isCentred = true;

    if (isCentred)
        str << wxT("<center>");


    str << wxT("<table><tr>");

    if (attr.GetLeftIndent() > 0)
    {
        wxClientDC dc((wxWindow*) this);

        str << wxT("<td width=") << wxMin(50, (ConvertTenthsMMToPixels(dc, attr.GetLeftIndent())/2)) << wxT("></td>");
    }

    if (isCentred)
        str << wxT("<td nowrap align=\"center\">");
    else
        str << wxT("<td nowrap>");

#ifdef __WXMSW__
    int size = 3;
#else
    int size = 4;
#endif

    int stdFontSize = 12;
    int thisFontSize = ((attr.GetFlags() & wxTEXT_ATTR_FONT_SIZE) != 0) ? attr.GetFontSize() : stdFontSize;

    if (thisFontSize < stdFontSize)
        size ++;
    else if (thisFontSize > stdFontSize)
        size --;

    str += wxT("<font");

    str << wxT(" size=") << size;

    if (!attr.GetFontFaceName().IsEmpty())
        str << wxT(" face=\"") << attr.GetFontFaceName() << wxT("\"");

    if (attr.GetTextColour().Ok())
        str << wxT(" color=\"#") << ColourToHexString(attr.GetTextColour()) << wxT("\"");

    str << wxT(">");

    bool hasBold = false;
    bool hasItalic = false;
    bool hasUnderline = false;

    if (attr.GetFontWeight() == wxBOLD)
        hasBold = true;
    if (attr.GetFontStyle() == wxITALIC)
        hasItalic = true;
    if (attr.GetFontUnderlined())
        hasUnderline = true;

    if (hasBold)
        str << wxT("<b>");
    if (hasItalic)
        str << wxT("<i>");
    if (hasUnderline)
        str << wxT("<u>");

    str += def->GetName();

    if (hasUnderline)
        str << wxT("</u>");
    if (hasItalic)
        str << wxT("</i>");
    if (hasBold)
        str << wxT("</b>");

    if (isCentred)
        str << wxT("</centre>");

    str << wxT("</font>");

    str << wxT("</td></tr></table>");

    if (isCentred)
        str << wxT("</center>");

    return str;
}
コード例 #8
0
ファイル: richtextstyles.cpp プロジェクト: 3v1n0/wxWidgets
/// Creates a suitable HTML fragment for a definition
wxString wxRichTextStyleListBox::CreateHTML(wxRichTextStyleDefinition* def) const
{
    // TODO: indicate list format for list style types

    wxString str;

    bool isCentred = false;

    wxRichTextAttr attr(def->GetStyleMergedWithBase(GetStyleSheet()));

    if (attr.HasAlignment() && attr.GetAlignment() == wxTEXT_ALIGNMENT_CENTRE)
        isCentred = true;

    str << wxT("<html><head></head>");
    str << wxT("<body");
    if (attr.GetBackgroundColour().Ok())
        str << wxT(" bgcolor=\"#") << ColourToHexString(attr.GetBackgroundColour()) << wxT("\"");
    str << wxT(">");

    if (isCentred)
        str << wxT("<center>");

    str << wxT("<table");
    if (attr.GetBackgroundColour().Ok())
        str << wxT(" bgcolor=\"#") << ColourToHexString(attr.GetBackgroundColour()) << wxT("\"");

    str << wxT("><tr>");

    if (attr.GetLeftIndent() > 0)
    {
        wxClientDC dc((wxWindow*) this);

        str << wxT("<td width=") << wxMin(50, (ConvertTenthsMMToPixels(dc, attr.GetLeftIndent())/2)) << wxT("></td>");
    }

    if (isCentred)
        str << wxT("<td nowrap align=\"center\">");
    else
        str << wxT("<td nowrap>");

#ifdef __WXMSW__
    int size = 2;
#else
    int size = 3;
#endif

    // Guess a standard font size
    int stdFontSize = 0;

    // First see if we have a default/normal style to base the size on
    wxString normalTranslated(_("normal"));
    wxString defaultTranslated(_("default"));
    size_t i;
    for (i = 0; i < GetStyleSheet()->GetParagraphStyleCount(); i++)
    {
        wxRichTextStyleDefinition* d = GetStyleSheet()->GetParagraphStyle(i);
        wxString name = d->GetName().Lower();
        if (name.Find(wxT("normal")) != wxNOT_FOUND || name.Find(normalTranslated) != wxNOT_FOUND ||
            name.Find(wxT("default")) != wxNOT_FOUND || name.Find(defaultTranslated) != wxNOT_FOUND)
        {
            wxRichTextAttr attr2(d->GetStyleMergedWithBase(GetStyleSheet()));
            if (attr2.HasFontPointSize())
            {
                stdFontSize = attr2.GetFontSize();
                break;
            }
        }
    }

    if (stdFontSize == 0)
    {
        // Look at sizes up to 20 points, and see which is the most common
        wxArrayInt sizes;
        size_t maxSize = 20;
        for (i = 0; i <= maxSize; i++)
            sizes.Add(0);
        for (i = 0; i < m_styleNames.GetCount(); i++)
        {
            wxRichTextStyleDefinition* d = GetStyle(i);
            if (d)
            {
                wxRichTextAttr attr2(d->GetStyleMergedWithBase(GetStyleSheet()));
                if (attr2.HasFontPointSize())
                {
                    if (attr2.GetFontSize() <= (int) maxSize)
                        sizes[attr2.GetFontSize()] ++;
                }
            }
        }
        int mostCommonSize = 0;
        for (i = 0; i <= maxSize; i++)
        {
            if (sizes[i] > mostCommonSize)
                mostCommonSize = i;
        }
        if (mostCommonSize > 0)
            stdFontSize = mostCommonSize;
    }

    if (stdFontSize == 0)
        stdFontSize = 12;

    int thisFontSize = attr.HasFontPointSize() ? attr.GetFontSize() : stdFontSize;

    if (thisFontSize < stdFontSize)
        size --;
    else if (thisFontSize > stdFontSize)
        size ++;

    str += wxT("<font");

    str << wxT(" size=") << size;

    if (!attr.GetFontFaceName().IsEmpty())
        str << wxT(" face=\"") << attr.GetFontFaceName() << wxT("\"");

    if (attr.GetTextColour().IsOk() && attr.GetTextColour() != attr.GetBackgroundColour() && !(!attr.HasBackgroundColour() && attr.GetTextColour() == *wxWHITE))
        str << wxT(" color=\"#") << ColourToHexString(attr.GetTextColour()) << wxT("\"");

    if (attr.GetBackgroundColour().Ok())
        str << wxT(" bgcolor=\"#") << ColourToHexString(attr.GetBackgroundColour()) << wxT("\"");

    str << wxT(">");

    bool hasBold = false;
    bool hasItalic = false;
    bool hasUnderline = false;

    if (attr.GetFontWeight() == wxFONTWEIGHT_BOLD)
        hasBold = true;
    if (attr.GetFontStyle() == wxFONTSTYLE_ITALIC)
        hasItalic = true;
    if (attr.GetFontUnderlined())
        hasUnderline = true;

    if (hasBold)
        str << wxT("<b>");
    if (hasItalic)
        str << wxT("<i>");
    if (hasUnderline)
        str << wxT("<u>");

    wxString name(def->GetName());
    if (attr.HasTextEffects() && (attr.GetTextEffects() & (wxTEXT_ATTR_EFFECT_CAPITALS|wxTEXT_ATTR_EFFECT_SMALL_CAPITALS)))
        name = name.Upper();

    str += name;

    if (hasUnderline)
        str << wxT("</u>");
    if (hasItalic)
        str << wxT("</i>");
    if (hasBold)
        str << wxT("</b>");

    if (isCentred)
        str << wxT("</centre>");

    str << wxT("</font>");

    str << wxT("</td></tr></table>");

    if (isCentred)
        str << wxT("</center>");

    str << wxT("</body></html>");
    return str;
}