size_t i = 0;
size_t len = text.length();
wxString line;
- wxRichTextParagraph* para = new wxRichTextParagraph(wxT(""), this, & style);
+ wxRichTextParagraph* para = new wxRichTextParagraph(wxEmptyString, this, & style);
if (paraStyle)
para->SetAttributes(*paraStyle);
wxRichTextPlainText* plainText = (wxRichTextPlainText*) para->GetChildren().GetFirst()->GetData();
plainText->SetText(line);
- para = new wxRichTextParagraph(wxT(""), this, & style);
+ para = new wxRichTextParagraph(wxEmptyString, this, & style);
if (paraStyle)
para->SetAttributes(*paraStyle);
currentStyle.SetParagraphStyleName(style.GetParagraphStyleName());
}
+ if (style.HasListStyleName() && !wxHasStyle(multipleStyleAttributes, wxTEXT_ATTR_LIST_STYLE_NAME))
+ {
+ if (currentStyle.HasListStyleName())
+ {
+ if (currentStyle.HasListStyleName() != style.HasListStyleName())
+ {
+ // Clash of style - mark as such
+ multipleStyleAttributes |= wxTEXT_ATTR_LIST_STYLE_NAME;
+ currentStyle.SetFlags(currentStyle.GetFlags() & ~wxTEXT_ATTR_LIST_STYLE_NAME);
+ }
+ }
+ else
+ currentStyle.SetListStyleName(style.GetListStyleName());
+ }
+
if (style.HasBulletStyle() && !wxHasStyle(multipleStyleAttributes, wxTEXT_ATTR_BULLET_STYLE))
{
if (currentStyle.HasBulletStyle())
}
}
+ if (style.HasBulletName() && !wxHasStyle(multipleStyleAttributes, wxTEXT_ATTR_BULLET_NAME))
+ {
+ if (currentStyle.HasBulletName())
+ {
+ if (currentStyle.HasBulletName() != style.HasBulletName())
+ {
+ // Clash of style - mark as such
+ multipleStyleAttributes |= wxTEXT_ATTR_BULLET_NAME;
+ currentStyle.SetFlags(currentStyle.GetFlags() & ~wxTEXT_ATTR_BULLET_NAME);
+ }
+ }
+ else
+ {
+ currentStyle.SetBulletName(style.GetBulletName());
+ }
+ }
+
return true;
}
if (para)
{
- if (!para->GetAttributes().GetParagraphStyleName().IsEmpty())
+ // Combine paragraph and list styles. If there is a list style in the original attributes,
+ // the current indentation overrides anything else and is used to find the item indentation.
+ // Also, for applying paragraph styles, consider having 2 modes: (1) we merge with what we have,
+ // thereby taking into account all user changes, (2) reset the style completely (except for indentation/list
+ // exception as above).
+ // Problem: when changing from one list style to another, there's a danger that the level info will get lost.
+ // So when changing a list style interactively, could retrieve level based on current style, then
+ // set appropriate indent and apply new style.
+
+ if (!para->GetAttributes().GetParagraphStyleName().IsEmpty() && !para->GetAttributes().GetListStyleName().IsEmpty())
+ {
+ int currentIndent = para->GetAttributes().GetLeftIndent();
+
+ wxRichTextParagraphStyleDefinition* paraDef = styleSheet->FindParagraphStyle(para->GetAttributes().GetParagraphStyleName());
+ wxRichTextListStyleDefinition* listDef = styleSheet->FindListStyle(para->GetAttributes().GetListStyleName());
+ if (paraDef && !listDef)
+ {
+ para->GetAttributes() = paraDef->GetStyle();
+ foundCount ++;
+ }
+ else if (listDef && !paraDef)
+ {
+ // Set overall style defined for the list style definition
+ para->GetAttributes() = listDef->GetStyle();
+
+ // Apply the style for this level
+ wxRichTextApplyStyle(para->GetAttributes(), * listDef->GetLevelAttributes(listDef->FindLevelForIndent(currentIndent)));
+ foundCount ++;
+ }
+ else if (listDef && paraDef)
+ {
+ // Combines overall list style, style for level, and paragraph style
+ para->GetAttributes() = listDef->CombineWithParagraphStyle(currentIndent, paraDef->GetStyle());
+ foundCount ++;
+ }
+ }
+ else if (para->GetAttributes().GetParagraphStyleName().IsEmpty() && !para->GetAttributes().GetListStyleName().IsEmpty())
+ {
+ int currentIndent = para->GetAttributes().GetLeftIndent();
+
+ wxRichTextListStyleDefinition* listDef = styleSheet->FindListStyle(para->GetAttributes().GetListStyleName());
+
+ // Overall list definition style
+ para->GetAttributes() = listDef->GetStyle();
+
+ // Style for this level
+ wxRichTextApplyStyle(para->GetAttributes(), * listDef->GetLevelAttributes(listDef->FindLevelForIndent(currentIndent)));
+
+ foundCount ++;
+ }
+ else if (!para->GetAttributes().GetParagraphStyleName().IsEmpty() && para->GetAttributes().GetListStyleName().IsEmpty())
{
wxRichTextParagraphStyleDefinition* def = styleSheet->FindParagraphStyle(para->GetAttributes().GetParagraphStyleName());
if (def)
return foundCount != 0;
}
+/// Set list style
+bool wxRichTextParagraphLayoutBox::SetListStyle(const wxRichTextRange& range, wxRichTextListStyleDefinition* def, int flags, int startFrom, int specifiedLevel)
+{
+ bool withUndo = ((flags & wxRICHTEXT_SETSTYLE_WITH_UNDO) != 0);
+ // bool applyMinimal = ((flags & wxRICHTEXT_SETSTYLE_OPTIMIZE) != 0);
+ bool specifyLevel = ((flags & wxRICHTEXT_SETSTYLE_SPECIFY_LEVEL) != 0);
+ bool renumber = ((flags & wxRICHTEXT_SETSTYLE_RENUMBER) != 0);
+
+ // Current number, if numbering
+ int n = startFrom;
+
+ wxASSERT (!specifyLevel || (specifyLevel && (specifiedLevel >= 0)));
+
+ // If we are associated with a control, make undoable; otherwise, apply immediately
+ // to the data.
+
+ bool haveControl = (GetRichTextCtrl() != NULL);
+
+ wxRichTextAction* action = NULL;
+
+ if (haveControl && withUndo)
+ {
+ action = new wxRichTextAction(NULL, _("Change List Style"), wxRICHTEXT_CHANGE_STYLE, & GetRichTextCtrl()->GetBuffer(), GetRichTextCtrl());
+ action->SetRange(range);
+ action->SetPosition(GetRichTextCtrl()->GetCaretPosition());
+ }
+
+ wxRichTextObjectList::compatibility_iterator node = m_children.GetFirst();
+ while (node)
+ {
+ wxRichTextParagraph* para = wxDynamicCast(node->GetData(), wxRichTextParagraph);
+ wxASSERT (para != NULL);
+
+ if (para && para->GetChildCount() > 0)
+ {
+ // Stop searching if we're beyond the range of interest
+ if (para->GetRange().GetStart() > range.GetEnd())
+ break;
+
+ if (!para->GetRange().IsOutside(range))
+ {
+ // We'll be using a copy of the paragraph to make style changes,
+ // not updating the buffer directly.
+ wxRichTextParagraph* newPara wxDUMMY_INITIALIZE(NULL);
+
+ if (haveControl && withUndo)
+ {
+ newPara = new wxRichTextParagraph(*para);
+ action->GetNewParagraphs().AppendChild(newPara);
+
+ // Also store the old ones for Undo
+ action->GetOldParagraphs().AppendChild(new wxRichTextParagraph(*para));
+ }
+ else
+ newPara = para;
+
+ if (def)
+ {
+ int thisIndent = newPara->GetAttributes().GetLeftIndent();
+ int thisLevel = specifyLevel ? specifiedLevel : def->FindLevelForIndent(thisIndent);
+
+ // How is numbering going to work?
+ // If we are renumbering, or numbering for the first time, we need to keep
+ // track of the number for each level. But we might be simply applying a different
+ // list style.
+ // In Word, applying a style to several paragraphs, even if at different levels,
+ // reverts the level back to the same one. So we could do the same here.
+ // Renumbering will need to be done when we promote/demote a paragraph.
+
+ // Apply the overall list style, and item style for this level
+ wxTextAttrEx listStyle(def->GetCombinedStyleForLevel(thisLevel));
+ wxRichTextApplyStyle(newPara->GetAttributes(), listStyle);
+
+ // Now we need to check numbering
+ if (renumber)
+ {
+ newPara->GetAttributes().SetBulletNumber(n);
+ }
+
+ n ++;
+ }
+ else if (!newPara->GetAttributes().GetListStyleName().IsEmpty())
+ {
+ // if def is NULL, remove list style, applying any associated paragraph style
+ // to restore the attributes
+
+ newPara->GetAttributes().SetListStyleName(wxEmptyString);
+ newPara->GetAttributes().SetLeftIndent(0, 0);
+
+ // Eliminate the main list-related attributes
+ newPara->GetAttributes().SetFlags(newPara->GetAttributes().GetFlags() & ~wxTEXT_ATTR_LEFT_INDENT & ~wxTEXT_ATTR_BULLET_STYLE & ~wxTEXT_ATTR_BULLET_NUMBER & ~wxTEXT_ATTR_BULLET_SYMBOL & wxTEXT_ATTR_LIST_STYLE_NAME);
+
+ wxRichTextStyleSheet* styleSheet = GetStyleSheet();
+ if (styleSheet && !newPara->GetAttributes().GetParagraphStyleName().IsEmpty())
+ {
+ wxRichTextParagraphStyleDefinition* def = styleSheet->FindParagraphStyle(newPara->GetAttributes().GetParagraphStyleName());
+ if (def)
+ {
+ newPara->GetAttributes() = def->GetStyle();
+ }
+ }
+ }
+ }
+ }
+
+ node = node->GetNext();
+ }
+
+ // Do action, or delay it until end of batch.
+ if (haveControl && withUndo)
+ GetRichTextCtrl()->GetBuffer().SubmitAction(action);
+
+ return true;
+}
+
+bool wxRichTextParagraphLayoutBox::SetListStyle(const wxRichTextRange& range, const wxString& defName, int flags, int startFrom, int specifiedLevel)
+{
+ if (GetStyleSheet())
+ {
+ wxRichTextListStyleDefinition* def = GetStyleSheet()->FindListStyle(defName);
+ if (def)
+ return SetListStyle(range, def, flags, startFrom, specifiedLevel);
+ }
+ return false;
+}
+
+/// Clear list for given range
+bool wxRichTextParagraphLayoutBox::ClearListStyle(const wxRichTextRange& range, int flags)
+{
+ return SetListStyle(range, NULL, flags);
+}
+
+/// Number/renumber any list elements in the given range
+bool wxRichTextParagraphLayoutBox::NumberList(const wxRichTextRange& range, wxRichTextListStyleDefinition* def, int flags, int startFrom, int specifiedLevel)
+{
+ return DoNumberList(range, range, 0, def, flags, startFrom, specifiedLevel);
+}
+
+/// Number/renumber any list elements in the given range. Also do promotion or demotion of items, if specified
+bool wxRichTextParagraphLayoutBox::DoNumberList(const wxRichTextRange& range, const wxRichTextRange& promotionRange, int promoteBy,
+ wxRichTextListStyleDefinition* def, int flags, int startFrom, int specifiedLevel)
+{
+ bool withUndo = ((flags & wxRICHTEXT_SETSTYLE_WITH_UNDO) != 0);
+ // bool applyMinimal = ((flags & wxRICHTEXT_SETSTYLE_OPTIMIZE) != 0);
+ bool specifyLevel = ((flags & wxRICHTEXT_SETSTYLE_SPECIFY_LEVEL) != 0);
+
+ bool renumber = ((flags & wxRICHTEXT_SETSTYLE_RENUMBER) != 0);
+
+ // Max number of levels
+ const int maxLevels = 10;
+
+ // The level we're looking at now
+ int currentLevel = -1;
+
+ // The item number for each level
+ int levels[maxLevels];
+ int i;
+
+ // Reset all numbering
+ for (i = 0; i < maxLevels; i++)
+ {
+ if (startFrom != -1)
+ levels[i] = startFrom;
+ else if (renumber) // start again
+ levels[i] = 1;
+ else
+ levels[i] = -1; // start from the number we found, if any
+ }
+
+ wxASSERT(!specifyLevel || (specifyLevel && (specifiedLevel >= 0)));
+
+ // If we are associated with a control, make undoable; otherwise, apply immediately
+ // to the data.
+
+ bool haveControl = (GetRichTextCtrl() != NULL);
+
+ wxRichTextAction* action = NULL;
+
+ if (haveControl && withUndo)
+ {
+ action = new wxRichTextAction(NULL, _("Renumber List"), wxRICHTEXT_CHANGE_STYLE, & GetRichTextCtrl()->GetBuffer(), GetRichTextCtrl());
+ action->SetRange(range);
+ action->SetPosition(GetRichTextCtrl()->GetCaretPosition());
+ }
+
+ wxRichTextObjectList::compatibility_iterator node = m_children.GetFirst();
+ while (node)
+ {
+ wxRichTextParagraph* para = wxDynamicCast(node->GetData(), wxRichTextParagraph);
+ wxASSERT (para != NULL);
+
+ if (para && para->GetChildCount() > 0)
+ {
+ // Stop searching if we're beyond the range of interest
+ if (para->GetRange().GetStart() > range.GetEnd())
+ break;
+
+ if (!para->GetRange().IsOutside(range))
+ {
+ // We'll be using a copy of the paragraph to make style changes,
+ // not updating the buffer directly.
+ wxRichTextParagraph* newPara wxDUMMY_INITIALIZE(NULL);
+
+ if (haveControl && withUndo)
+ {
+ newPara = new wxRichTextParagraph(*para);
+ action->GetNewParagraphs().AppendChild(newPara);
+
+ // Also store the old ones for Undo
+ action->GetOldParagraphs().AppendChild(new wxRichTextParagraph(*para));
+ }
+ else
+ newPara = para;
+
+ wxRichTextListStyleDefinition* defToUse = def;
+ if (!defToUse)
+ {
+ wxRichTextStyleSheet* sheet = GetStyleSheet();
+
+ if (sheet && !newPara->GetAttributes().GetListStyleName().IsEmpty())
+ defToUse = sheet->FindListStyle(newPara->GetAttributes().GetListStyleName());
+ }
+
+ if (defToUse)
+ {
+ int thisIndent = newPara->GetAttributes().GetLeftIndent();
+ int thisLevel = defToUse->FindLevelForIndent(thisIndent);
+
+ // If the paragraph doesn't have an indent, or we've specified a level to apply to all,
+ // change the level.
+ if (thisIndent == 0 || specifiedLevel != -1)
+ thisLevel = specifiedLevel;
+
+ // Do promotion if specified
+ if ((promoteBy != 0) && !para->GetRange().IsOutside(promotionRange))
+ {
+ thisLevel = thisLevel - promoteBy;
+ if (thisLevel < 0)
+ thisLevel = 0;
+ if (thisLevel > 9)
+ thisLevel = 9;
+ }
+
+ // Apply the overall list style, and item style for this level
+ wxTextAttrEx listStyle(defToUse->GetCombinedStyleForLevel(thisLevel));
+ wxRichTextApplyStyle(newPara->GetAttributes(), listStyle);
+
+ // OK, we've (re)applied the style, now let's get the numbering right.
+
+ if (currentLevel == -1)
+ currentLevel = thisLevel;
+
+ // Same level as before, do nothing except increment level's number afterwards
+ if (currentLevel == thisLevel)
+ {
+ }
+ // A deeper level: start renumbering all levels after current level
+ else if (thisLevel > currentLevel)
+ {
+ for (i = currentLevel+1; i <= thisLevel; i++)
+ {
+ levels[i] = 1;
+ }
+ currentLevel = thisLevel;
+ }
+ else if (thisLevel < currentLevel)
+ {
+ currentLevel = thisLevel;
+ }
+
+ // Use the current numbering if -1 and we have a bullet number already
+ if (levels[currentLevel] == -1)
+ {
+ if (newPara->GetAttributes().HasBulletNumber())
+ levels[currentLevel] = newPara->GetAttributes().GetBulletNumber();
+ else
+ levels[currentLevel] = 1;
+ }
+
+ newPara->GetAttributes().SetBulletNumber(levels[currentLevel]);
+
+ levels[currentLevel] ++;
+ }
+ }
+ }
+
+ node = node->GetNext();
+ }
+
+ // Do action, or delay it until end of batch.
+ if (haveControl && withUndo)
+ GetRichTextCtrl()->GetBuffer().SubmitAction(action);
+
+ return true;
+}
+
+bool wxRichTextParagraphLayoutBox::NumberList(const wxRichTextRange& range, const wxString& defName, int flags, int startFrom, int specifiedLevel)
+{
+ if (GetStyleSheet())
+ {
+ wxRichTextListStyleDefinition* def = NULL;
+ if (!defName.IsEmpty())
+ def = GetStyleSheet()->FindListStyle(defName);
+ return NumberList(range, def, flags, startFrom, specifiedLevel);
+ }
+ return false;
+}
+
+/// Promote the list items within the given range. promoteBy can be a positive or negative number, e.g. 1 or -1
+bool wxRichTextParagraphLayoutBox::PromoteList(int promoteBy, const wxRichTextRange& range, wxRichTextListStyleDefinition* def, int flags, int specifiedLevel)
+{
+ // TODO
+ // One strategy is to first work out the range within which renumbering must occur. Then could pass these two ranges
+ // to NumberList with a flag indicating promotion is required within one of the ranges.
+ // Find first and last paragraphs in range. Then for first, calculate new indentation and look back until we find
+ // a paragraph that either has no list style, or has one that is different or whose indentation is less.
+ // We start renumbering from the para after that different para we found. We specify that the numbering of that
+ // list position will start from 1.
+ // Similarly, we look after the last para in the promote range for an indentation that is less (or no list style).
+ // We can end the renumbering at this point.
+
+ // For now, only renumber within the promotion range.
+
+ return DoNumberList(range, range, promoteBy, def, flags, 1, specifiedLevel);
+}
+
+bool wxRichTextParagraphLayoutBox::PromoteList(int promoteBy, const wxRichTextRange& range, const wxString& defName, int flags, int specifiedLevel)
+{
+ if (GetStyleSheet())
+ {
+ wxRichTextListStyleDefinition* def = NULL;
+ if (!defName.IsEmpty())
+ def = GetStyleSheet()->FindListStyle(defName);
+ return PromoteList(promoteBy, range, def, flags, specifiedLevel);
+ }
+ return false;
+}
+
/*!
* wxRichTextParagraph
* This object represents a single paragraph (or in a straight text editor, a line).
{
// TODO
}
+ else if (attr.GetBulletStyle() & wxTEXT_ATTR_BULLET_STYLE_STANDARD)
+ {
+ wxTextAttrEx bulletAttr(GetCombinedAttributes());
+ if (bulletAttr.GetTextColour().Ok())
+ {
+ dc.SetPen(wxPen(bulletAttr.GetTextColour()));
+ dc.SetBrush(wxBrush(bulletAttr.GetTextColour()));
+ }
+ else
+ {
+ dc.SetPen(*wxBLACK_PEN);
+ dc.SetBrush(*wxBLACK_BRUSH);
+ }
+
+ wxFont font;
+ if (bulletAttr.GetFont().Ok())
+ font = bulletAttr.GetFont();
+ else
+ font = (*wxNORMAL_FONT);
+
+ dc.SetFont(font);
+
+ // Get line height from first line, if any
+ wxRichTextLine* line = m_cachedLines.GetFirst() ? (wxRichTextLine* ) m_cachedLines.GetFirst()->GetData() : (wxRichTextLine*) NULL;
+
+ wxPoint linePos;
+ int lineHeight wxDUMMY_INITIALIZE(0);
+ if (line)
+ {
+ lineHeight = line->GetSize().y;
+ linePos = line->GetPosition() + GetPosition();
+ }
+ else
+ {
+ lineHeight = dc.GetCharHeight();
+ linePos = GetPosition();
+ linePos.y += spaceBeforePara;
+ }
+
+ int charHeight = dc.GetCharHeight();
+
+ int bulletWidth = wxMax(2, (charHeight/3 + 1));
+ int bulletHeight = bulletWidth;
+
+ int x = GetPosition().x + leftIndent;
+ int y = linePos.y + (lineHeight - charHeight/2) - bulletHeight/2;
+
+ if (bulletAttr.GetBulletName() == wxT("standard/square"))
+ {
+ dc.DrawRectangle(x, y, bulletWidth, bulletHeight);
+ }
+ else // "standard/round", and catch-all
+ {
+ dc.DrawEllipse(x, y, bulletWidth, bulletHeight);
+ }
+ }
else
{
wxString bulletText = GetBulletText();
// Compensate for kerning difference
wxString stringFragment2(m_text.Mid(r1 - offset, fragmentLen+1));
wxString stringFragment3(m_text.Mid(r1 - offset + fragmentLen, 1));
-
+
wxCoord w1, h1, w2, h2, w3, h3;
dc.GetTextExtent(stringFragment, & w1, & h1);
dc.GetTextExtent(stringFragment2, & w2, & h2);
dc.GetTextExtent(stringFragment3, & w3, & h3);
-
+
int kerningDiff = (w1 + w3) - w2;
x = x - kerningDiff;
}
// Compensate for kerning difference
wxString stringFragment2(m_text.Mid(s1 - offset, fragmentLen+1));
wxString stringFragment3(m_text.Mid(s1 - offset + fragmentLen, 1));
-
+
wxCoord w1, h1, w2, h2, w3, h3;
dc.GetTextExtent(stringFragment, & w1, & h1);
dc.GetTextExtent(stringFragment2, & w2, & h2);
dc.GetTextExtent(stringFragment3, & w3, & h3);
-
+
int kerningDiff = (w1 + w3) - w2;
x = x - kerningDiff;
}
tabArray = textAttr.GetTabs();
int tabCount = tabArray.GetCount();
-
+
for (int i = 0; i < tabCount; ++i)
{
int pos = tabArray[i];
pos = ((wxRichTextPlainText*) this)->ConvertTenthsMMToPixels(dc, pos);
tabArray[i] = pos;
}
-
+
int nextTabPos = -1;
while (stringChunk.Find(wxT('\t')) >= 0)
m_suppressUndo = obj.m_suppressUndo;
}
+/// Push style sheet to top of stack
+bool wxRichTextBuffer::PushStyleSheet(wxRichTextStyleSheet* styleSheet)
+{
+ if (m_styleSheet)
+ styleSheet->InsertSheet(m_styleSheet);
+
+ SetStyleSheet(styleSheet);
+
+ return true;
+}
+
+/// Pop style sheet from top of stack
+wxRichTextStyleSheet* wxRichTextBuffer::PopStyleSheet()
+{
+ if (m_styleSheet)
+ {
+ wxRichTextStyleSheet* oldSheet = m_styleSheet;
+ m_styleSheet = oldSheet->GetNextSheet();
+ oldSheet->Unlink();
+
+ return oldSheet;
+ }
+ else
+ return NULL;
+}
+
/// Submit command to insert paragraphs
bool wxRichTextBuffer::InsertParagraphsWithUndo(long pos, const wxRichTextParagraphLayoutBox& paragraphs, wxRichTextCtrl* ctrl, int flags)
{
bool wxRichTextBuffer::BeginNumberedBullet(int bulletNumber, int leftIndent, int leftSubIndent, int bulletStyle)
{
wxTextAttrEx attr;
- attr.SetFlags(wxTEXT_ATTR_BULLET_STYLE|wxTEXT_ATTR_BULLET_NUMBER|wxTEXT_ATTR_LEFT_INDENT);
+ attr.SetFlags(wxTEXT_ATTR_BULLET_STYLE|wxTEXT_ATTR_LEFT_INDENT);
attr.SetBulletStyle(bulletStyle);
attr.SetBulletNumber(bulletNumber);
attr.SetLeftIndent(leftIndent, leftSubIndent);
bool wxRichTextBuffer::BeginSymbolBullet(wxChar symbol, int leftIndent, int leftSubIndent, int bulletStyle)
{
wxTextAttrEx attr;
- attr.SetFlags(wxTEXT_ATTR_BULLET_STYLE|wxTEXT_ATTR_BULLET_SYMBOL|wxTEXT_ATTR_LEFT_INDENT);
+ attr.SetFlags(wxTEXT_ATTR_BULLET_STYLE|wxTEXT_ATTR_LEFT_INDENT);
attr.SetBulletStyle(bulletStyle);
attr.SetLeftIndent(leftIndent, leftSubIndent);
attr.SetBulletSymbol(symbol);
return BeginStyle(attr);
}
+/// Begin standard bullet
+bool wxRichTextBuffer::BeginStandardBullet(const wxString& bulletName, int leftIndent, int leftSubIndent, int bulletStyle)
+{
+ wxTextAttrEx attr;
+ attr.SetFlags(wxTEXT_ATTR_BULLET_STYLE|wxTEXT_ATTR_LEFT_INDENT);
+ attr.SetBulletStyle(bulletStyle);
+ attr.SetLeftIndent(leftIndent, leftSubIndent);
+ attr.SetBulletName(bulletName);
+
+ return BeginStyle(attr);
+}
+
/// Begin named character style
bool wxRichTextBuffer::BeginCharacterStyle(const wxString& characterStyle)
{
return false;
}
+/// Begin named list style
+bool wxRichTextBuffer::BeginListStyle(const wxString& listStyle, int level, int number)
+{
+ if (GetStyleSheet())
+ {
+ wxRichTextListStyleDefinition* def = GetStyleSheet()->FindListStyle(listStyle);
+ if (def)
+ {
+ wxTextAttrEx attr(def->GetCombinedStyleForLevel(level));
+
+ attr.SetBulletNumber(number);
+
+ return BeginStyle(attr);
+ }
+ }
+ return false;
+}
+
/// Adds a handler to the end
void wxRichTextBuffer::AddHandler(wxRichTextFileHandler *handler)
{
/// Load a file
bool wxRichTextBuffer::LoadFile(const wxString& filename, int type)
+
+
{
wxRichTextFileHandler* handler = FindHandlerFilenameOrType(filename, type);
if (handler)
wxRichTextBuffer::CleanUpHandlers();
wxRichTextDecimalToRoman(-1);
wxRichTextParagraph::ClearDefaultTabs();
+ wxRichTextCtrl::ClearAvailableFontNames();
};
};
IMPLEMENT_DYNAMIC_CLASS(wxRichTextModule, wxModule)
+// If the richtext lib is dynamically loaded after the app has already started
+// (such as from wxPython) then the built-in module system will not init this
+// module. Provide this function to do it manually.
+void wxRichTextModuleInit()
+{
+ wxModule* module = new wxRichTextModule;
+ module->Init();
+ wxModule::RegisterModule(module);
+}
+
+
/*!
* Commands for undo/redo
*
/// Compare two attribute objects
bool wxTextAttrEq(const wxTextAttrEx& attr1, const wxTextAttrEx& attr2)
{
- return (
- attr1.GetTextColour() == attr2.GetTextColour() &&
- attr1.GetBackgroundColour() == attr2.GetBackgroundColour() &&
- attr1.GetFont() == attr2.GetFont() &&
- attr1.GetAlignment() == attr2.GetAlignment() &&
- attr1.GetLeftIndent() == attr2.GetLeftIndent() &&
- attr1.GetRightIndent() == attr2.GetRightIndent() &&
- attr1.GetLeftSubIndent() == attr2.GetLeftSubIndent() &&
- wxRichTextTabsEq(attr1.GetTabs(), attr2.GetTabs()) &&
- attr1.GetLineSpacing() == attr2.GetLineSpacing() &&
- attr1.GetParagraphSpacingAfter() == attr2.GetParagraphSpacingAfter() &&
- attr1.GetParagraphSpacingBefore() == attr2.GetParagraphSpacingBefore() &&
- attr1.GetBulletStyle() == attr2.GetBulletStyle() &&
- attr1.GetBulletNumber() == attr2.GetBulletNumber() &&
- attr1.GetBulletSymbol() == attr2.GetBulletSymbol() &&
- attr1.GetBulletFont() == attr2.GetBulletFont() &&
- attr1.GetCharacterStyleName() == attr2.GetCharacterStyleName() &&
- attr1.GetParagraphStyleName() == attr2.GetParagraphStyleName());
+ return (attr1 == attr2);
}
bool wxTextAttrEq(const wxTextAttrEx& attr1, const wxRichTextAttr& attr2)
attr1.GetBulletStyle() == attr2.GetBulletStyle() &&
attr1.GetBulletNumber() == attr2.GetBulletNumber() &&
attr1.GetBulletSymbol() == attr2.GetBulletSymbol() &&
+ attr1.GetBulletName() == attr2.GetBulletName() &&
attr1.GetBulletFont() == attr2.GetBulletFont() &&
attr1.GetCharacterStyleName() == attr2.GetCharacterStyleName() &&
- attr1.GetParagraphStyleName() == attr2.GetParagraphStyleName());
+ attr1.GetParagraphStyleName() == attr2.GetParagraphStyleName() &&
+ attr1.GetListStyleName() == attr2.GetListStyleName());
}
/// Compare two attribute objects, but take into account the flags
(attr1.GetParagraphStyleName() != attr2.GetParagraphStyleName()))
return false;
+ if ((flags & wxTEXT_ATTR_LIST_STYLE_NAME) &&
+ (attr1.GetListStyleName() != attr2.GetListStyleName()))
+ return false;
+
if ((flags & wxTEXT_ATTR_BULLET_STYLE) &&
(attr1.GetBulletStyle() != attr2.GetBulletStyle()))
return false;
return false;
if ((flags & wxTEXT_ATTR_BULLET_SYMBOL) &&
- (attr1.GetBulletSymbol() != attr2.GetBulletSymbol()))
+ (attr1.GetBulletSymbol() != attr2.GetBulletSymbol()) &&
+ (attr1.GetBulletFont() != attr2.GetBulletFont()))
return false;
- if ((flags & wxTEXT_ATTR_BULLET_SYMBOL) &&
- (attr1.GetBulletFont() != attr2.GetBulletFont()))
+ if ((flags & wxTEXT_ATTR_BULLET_NAME) &&
+ (attr1.GetBulletName() != attr2.GetBulletName()))
return false;
if ((flags & wxTEXT_ATTR_TABS) &&
(attr1.GetParagraphStyleName() != attr2.GetParagraphStyleName()))
return false;
+ if ((flags & wxTEXT_ATTR_LIST_STYLE_NAME) &&
+ (attr1.GetListStyleName() != attr2.GetListStyleName()))
+ return false;
+
if ((flags & wxTEXT_ATTR_BULLET_STYLE) &&
(attr1.GetBulletStyle() != attr2.GetBulletStyle()))
return false;
return false;
if ((flags & wxTEXT_ATTR_BULLET_SYMBOL) &&
- (attr1.GetBulletSymbol() != attr2.GetBulletSymbol()))
+ (attr1.GetBulletSymbol() != attr2.GetBulletSymbol()) &&
+ (attr1.GetBulletFont() != attr2.GetBulletFont()))
return false;
- if ((flags & wxTEXT_ATTR_BULLET_SYMBOL) &&
- (attr1.GetBulletFont() != attr2.GetBulletFont()))
+ if ((flags & wxTEXT_ATTR_BULLET_NAME) &&
+ (attr1.GetBulletName() != attr2.GetBulletName()))
return false;
if ((flags & wxTEXT_ATTR_TABS) &&
if (style.HasParagraphStyleName())
destStyle.SetParagraphStyleName(style.GetParagraphStyleName());
+ if (style.HasListStyleName())
+ destStyle.SetListStyleName(style.GetListStyleName());
+
if (style.HasBulletStyle())
- {
destStyle.SetBulletStyle(style.GetBulletStyle());
+
+ if (style.HasBulletSymbol())
+ {
destStyle.SetBulletSymbol(style.GetBulletSymbol());
destStyle.SetBulletFont(style.GetBulletFont());
}
+ if (style.HasBulletName())
+ destStyle.SetBulletName(style.GetBulletName());
+
if (style.HasBulletNumber())
destStyle.SetBulletNumber(style.GetBulletNumber());
destStyle.SetParagraphStyleName(style.GetParagraphStyleName());
}
+ if (style.HasListStyleName())
+ {
+ if (!(compareWith && compareWith->HasListStyleName() && compareWith->GetListStyleName() == style.GetListStyleName()))
+ destStyle.SetListStyleName(style.GetListStyleName());
+ }
+
if (style.HasBulletStyle())
{
if (!(compareWith && compareWith->HasBulletStyle() && compareWith->GetBulletStyle() == style.GetBulletStyle()))
destStyle.SetBulletNumber(style.GetBulletNumber());
}
+ if (style.HasBulletName())
+ {
+ if (!(compareWith && compareWith->HasBulletName() && compareWith->GetBulletName() == style.GetBulletName()))
+ destStyle.SetBulletName(style.GetBulletName());
+ }
+
return true;
}
m_lineSpacing = attr.m_lineSpacing;
m_characterStyleName = attr.m_characterStyleName;
m_paragraphStyleName = attr.m_paragraphStyleName;
+ m_listStyleName = attr.m_listStyleName;
m_bulletStyle = attr.m_bulletStyle;
m_bulletNumber = attr.m_bulletNumber;
m_bulletSymbol = attr.m_bulletSymbol;
m_bulletFont = attr.m_bulletFont;
+ m_bulletName = attr.m_bulletName;
}
// operators
m_lineSpacing = attr.GetLineSpacing();
m_characterStyleName = attr.GetCharacterStyleName();
m_paragraphStyleName = attr.GetParagraphStyleName();
+ m_listStyleName = attr.GetListStyleName();
m_bulletStyle = attr.GetBulletStyle();
m_bulletNumber = attr.GetBulletNumber();
m_bulletSymbol = attr.GetBulletSymbol();
+ m_bulletName = attr.GetBulletName();
m_bulletFont = attr.GetBulletFont();
if (attr.GetFont().Ok())
GetLineSpacing() == attr.GetLineSpacing() &&
GetCharacterStyleName() == attr.GetCharacterStyleName() &&
GetParagraphStyleName() == attr.GetParagraphStyleName() &&
+ GetListStyleName() == attr.GetListStyleName() &&
GetBulletStyle() == attr.GetBulletStyle() &&
GetBulletSymbol() == attr.GetBulletSymbol() &&
GetBulletNumber() == attr.GetBulletNumber() &&
GetBulletFont() == attr.GetBulletFont() &&
+ GetBulletName() == attr.GetBulletName() &&
m_fontSize == attr.m_fontSize &&
m_fontStyle == attr.m_fontStyle &&
attr.SetBulletStyle(m_bulletStyle);
attr.SetBulletNumber(m_bulletNumber);
attr.SetBulletSymbol(m_bulletSymbol);
+ attr.SetBulletName(m_bulletName);
attr.SetBulletFont(m_bulletFont);
attr.SetCharacterStyleName(m_characterStyleName);
attr.SetParagraphStyleName(m_paragraphStyleName);
+ attr.SetListStyleName(m_listStyleName);
attr.SetFlags(GetFlags()); // Important: set after SetFont and others, since they set flags
}
if (attr.HasParagraphStyleName())
newAttr.SetParagraphStyleName(attr.GetParagraphStyleName());
+ if (attr.HasListStyleName())
+ newAttr.SetListStyleName(attr.GetListStyleName());
+
if (attr.HasBulletStyle())
newAttr.SetBulletStyle(attr.GetBulletStyle());
if (attr.HasBulletNumber())
newAttr.SetBulletNumber(attr.GetBulletNumber());
+ if (attr.HasBulletName())
+ newAttr.SetBulletName(attr.GetBulletName());
+
if (attr.HasBulletSymbol())
{
newAttr.SetBulletSymbol(attr.GetBulletSymbol());
m_lineSpacing = attr.m_lineSpacing;
m_paragraphStyleName = attr.m_paragraphStyleName;
m_characterStyleName = attr.m_characterStyleName;
+ m_listStyleName = attr.m_listStyleName;
m_bulletStyle = attr.m_bulletStyle;
m_bulletNumber = attr.m_bulletNumber;
m_bulletSymbol = attr.m_bulletSymbol;
+ m_bulletName = attr.m_bulletName;
m_bulletFont = attr.m_bulletFont;
}
m_lineSpacing = 0;
m_bulletStyle = wxTEXT_ATTR_BULLET_STYLE_NONE;
m_bulletNumber = 0;
- m_bulletSymbol = 0;
m_bulletSymbol = wxT('*');
}
m_lineSpacing = attr.m_lineSpacing;
m_characterStyleName = attr.m_characterStyleName;
m_paragraphStyleName = attr.m_paragraphStyleName;
+ m_listStyleName = attr.m_listStyleName;
m_bulletStyle = attr.m_bulletStyle;
m_bulletNumber = attr.m_bulletNumber;
m_bulletSymbol = attr.m_bulletSymbol;
m_bulletFont = attr.m_bulletFont;
+ m_bulletName = attr.m_bulletName;
}
// Assignment from a wxTextAttr object.
wxTextAttr::operator= (attr);
}
+// Equality test
+bool wxTextAttrEx::operator== (const wxTextAttrEx& attr) const
+{
+ return (
+ GetTextColour() == attr.GetTextColour() &&
+ GetBackgroundColour() == attr.GetBackgroundColour() &&
+ GetFont() == attr.GetFont() &&
+ GetAlignment() == attr.GetAlignment() &&
+ GetLeftIndent() == attr.GetLeftIndent() &&
+ GetRightIndent() == attr.GetRightIndent() &&
+ GetLeftSubIndent() == attr.GetLeftSubIndent() &&
+ wxRichTextTabsEq(GetTabs(), attr.GetTabs()) &&
+ GetLineSpacing() == attr.GetLineSpacing() &&
+ GetParagraphSpacingAfter() == attr.GetParagraphSpacingAfter() &&
+ GetParagraphSpacingBefore() == attr.GetParagraphSpacingBefore() &&
+ GetBulletStyle() == attr.GetBulletStyle() &&
+ GetBulletNumber() == attr.GetBulletNumber() &&
+ GetBulletSymbol() == attr.GetBulletSymbol() &&
+ GetBulletName() == attr.GetBulletName() &&
+ GetBulletFont() == attr.GetBulletFont() &&
+ GetCharacterStyleName() == attr.GetCharacterStyleName() &&
+ GetParagraphStyleName() == attr.GetParagraphStyleName() &&
+ GetListStyleName() == attr.GetListStyleName());
+}
+
wxTextAttrEx wxTextAttrEx::CombineEx(const wxTextAttrEx& attr,
const wxTextAttrEx& attrDef,
const wxTextCtrlBase *text)
if (attr.HasParagraphStyleName())
newAttr.SetParagraphStyleName(attr.GetParagraphStyleName());
+ if (attr.HasListStyleName())
+ newAttr.SetListStyleName(attr.GetListStyleName());
+
if (attr.HasBulletStyle())
newAttr.SetBulletStyle(attr.GetBulletStyle());
if (attr.HasBulletNumber())
newAttr.SetBulletNumber(attr.GetBulletNumber());
+ if (attr.HasBulletName())
+ newAttr.SetBulletName(attr.GetBulletName());
+
if (attr.HasBulletSymbol())
{
newAttr.SetBulletSymbol(attr.GetBulletSymbol());
#endif
// wxUSE_RICHTEXT
-