/////////////////////////////////////////////////////////////////////////////
-// Name: richtext/richtextbuffer.cpp
+// Name: src/richtext/richtextbuffer.cpp
// Purpose: Buffer for wxRichTextCtrl
// Author: Julian Smart
// Modified by:
#include "wx/wxprec.h"
#ifdef __BORLANDC__
- #pragma hdrstop
+ #pragma hdrstop
#endif
#if wxUSE_RICHTEXT
#include "wx/richtext/richtextbuffer.h"
#ifndef WX_PRECOMP
- #include "wx/wx.h"
+ #include "wx/dc.h"
+ #include "wx/intl.h"
+ #include "wx/log.h"
+ #include "wx/dataobj.h"
+ #include "wx/module.h"
#endif
#include "wx/filename.h"
#include "wx/clipbrd.h"
-#include "wx/dataobj.h"
#include "wx/wfstream.h"
-#include "wx/module.h"
#include "wx/mstream.h"
#include "wx/sstream.h"
wxRichTextRange range(-1, -1);
size_t i = 0;
- size_t len = text.Length();
+ size_t len = text.length();
wxString line;
while (i < len)
{
}
/// Get the text attributes for this position.
-bool wxRichTextParagraphLayoutBox::GetStyle(long position, wxTextAttrEx& style) const
+bool wxRichTextParagraphLayoutBox::GetStyle(long position, wxTextAttrEx& style)
{
wxRichTextObject* obj wxDUMMY_INITIALIZE(NULL);
}
/// Get the text attributes for this position.
-bool wxRichTextParagraphLayoutBox::GetStyle(long position, wxRichTextAttr& style) const
+bool wxRichTextParagraphLayoutBox::GetStyle(long position, wxRichTextAttr& style)
{
wxRichTextObject* obj wxDUMMY_INITIALIZE(NULL);
text + textObject->GetText().Mid(posInString);
textObject->SetText(newText);
- int textLength = text.Length();
+ int textLength = text.length();
textObject->SetRange(wxRichTextRange(textObject->GetRange().GetStart(),
textObject->GetRange().GetEnd() + textLength));
int spacePos = plainText.Find(wxT(' '), true);
if (spacePos != wxNOT_FOUND)
{
- int positionsFromEndOfString = plainText.Length() - spacePos - 1;
+ int positionsFromEndOfString = plainText.length() - spacePos - 1;
breakPosition = breakPosition - positionsFromEndOfString;
}
}
// (a) All selected.
if (selectionRange.GetStart() <= range.GetStart() && selectionRange.GetEnd() >= range.GetEnd())
- {/*
- // Draw all selected
- dc.SetBrush(*wxBLACK_BRUSH);
- dc.SetPen(*wxBLACK_PEN);
- wxCoord w, h;
- dc.GetTextExtent(stringChunk, & w, & h);
- wxRect selRect(x, rect.y, w, rect.GetHeight());
- dc.DrawRectangle(selRect);
- dc.SetTextForeground(*wxWHITE);
- dc.SetBackgroundMode(wxTRANSPARENT);
- dc.DrawText(stringChunk, x, y);*/
+ {
DrawTabbedString(dc, rect,stringChunk, x, y, true);
}
// (b) None selected.
else if (selectionRange.GetEnd() < range.GetStart() || selectionRange.GetStart() > range.GetEnd())
{
// Draw all unselected
- /*
- dc.SetTextForeground(GetAttributes().GetTextColour());
- dc.SetBackgroundMode(wxTRANSPARENT);
- dc.DrawText(stringChunk, x, y);*/
DrawTabbedString(dc, rect,stringChunk, x, y, false);
}
else
if (fragmentLen < 0)
wxLogDebug(wxT("Mid(%d, %d"), (int)(r1 - offset), (int)fragmentLen);
wxString stringFragment = m_text.Mid(r1 - offset, fragmentLen);
-/*
- dc.SetTextForeground(GetAttributes().GetTextColour());
- dc.DrawText(stringFragment, x, y);
- wxCoord w, h;
- dc.GetTextExtent(stringFragment, & w, & h);
- x += w;*/
DrawTabbedString(dc, rect,stringFragment, x, y, false);
}
if (fragmentLen < 0)
wxLogDebug(wxT("Mid(%d, %d"), (int)(s1 - offset), (int)fragmentLen);
wxString stringFragment = m_text.Mid(s1 - offset, fragmentLen);
-/*
- wxCoord w, h;
- dc.GetTextExtent(stringFragment, & w, & h);
- wxRect selRect(x, rect.y, w, rect.GetHeight());
-
- dc.SetBrush(*wxBLACK_BRUSH);
- dc.SetPen(*wxBLACK_PEN);
- dc.DrawRectangle(selRect);
- dc.SetTextForeground(*wxWHITE);
- dc.DrawText(stringFragment, x, y);
- x += w;*/
DrawTabbedString(dc, rect,stringFragment, x, y, true);
}
if (fragmentLen < 0)
wxLogDebug(wxT("Mid(%d, %d"), (int)(s2 - offset), (int)fragmentLen);
wxString stringFragment = m_text.Mid(s2 - offset, fragmentLen);
-/*
- dc.SetTextForeground(GetAttributes().GetTextColour());
- dc.DrawText(stringFragment, x, y);*/
+
DrawTabbedString(dc, rect,stringFragment, x, y, false);
}
}
return true;
}
-
+
bool wxRichTextPlainText::DrawTabbedString(wxDC& dc,const wxRect& rect,wxString& str, wxCoord& x, wxCoord& y, bool selected)
{
wxArrayInt tab_array = GetAttributes().GetTabs();
- if(tab_array.IsEmpty()){// create a default tab list at 10 mm each.
- for( int i = 0; i < 20; ++i){
+ if (tab_array.IsEmpty())
+ {
+ // create a default tab list at 10 mm each.
+ for (int i = 0; i < 20; ++i)
+ {
tab_array.Add(i*100);
}
}
int map_mode = dc.GetMapMode();
dc.SetMapMode(wxMM_LOMETRIC );
int num_tabs = tab_array.GetCount();
- for( int i = 0; i < num_tabs; ++i){
- tab_array[i] = dc.LogicalToDeviceXRel(tab_array[i]);
+ for (int i = 0; i < num_tabs; ++i)
+ {
+ tab_array[i] = dc.LogicalToDeviceXRel(tab_array[i]);
}
+
dc.SetMapMode(map_mode );
int next_tab_pos = -1;
int tab_pos = -1;
wxCoord w, h;
- if(selected){
+
+ if(selected)
+ {
dc.SetBrush(*wxBLACK_BRUSH);
dc.SetPen(*wxBLACK_PEN);
dc.SetTextForeground(*wxWHITE);
dc.SetBackgroundMode(wxTRANSPARENT);
}
- else{
+ else
+ {
dc.SetTextForeground(GetAttributes().GetTextColour());
dc.SetBackgroundMode(wxTRANSPARENT);
}
- while(str.Find(wxT('\t')) >= 0){// the string has a tab
+
+ while (str.Find(wxT('\t')) >= 0)
+ {
+ // the string has a tab
// break up the string at the Tab
wxString stringChunk = str.BeforeFirst(wxT('\t'));
str = str.AfterFirst(wxT('\t'));
dc.GetTextExtent(stringChunk, & w, & h);
tab_pos = x + w;
bool not_found = true;
- for( int i = 0; i < num_tabs && not_found; ++i){
+ for (int i = 0; i < num_tabs && not_found; ++i)
+ {
next_tab_pos = tab_array.Item(i);
- if( next_tab_pos > tab_pos){
+ if (next_tab_pos > tab_pos)
+ {
not_found = false;
- if(selected){
+ if (selected)
+ {
w = next_tab_pos - x;
wxRect selRect(x, rect.y, w, rect.GetHeight());
- dc.DrawRectangle(selRect);
+ dc.DrawRectangle(selRect);
}
dc.DrawText(stringChunk, x, y);
x = next_tab_pos;
}
}
}
-
+
dc.GetTextExtent(str, & w, & h);
- if(selected){
+ if (selected)
+ {
wxRect selRect(x, rect.y, w, rect.GetHeight());
- dc.DrawRectangle(selRect);
+ dc.DrawRectangle(selRect);
}
dc.DrawText(str, x, y);
x += w;
wxString stringChunk = m_text.Mid(startPos, (size_t) len);
wxCoord w, h;
int width = 0;
- if(stringChunk.Find(wxT('\t')) >= 0){// the string has a tab
+ if (stringChunk.Find(wxT('\t')) >= 0)
+ {
+ // the string has a tab
wxArrayInt tab_array = GetAttributes().GetTabs();
- if(tab_array.IsEmpty()){// create a default tab list at 10 mm each.
- for( int i = 0; i < 20; ++i){
+ if (tab_array.IsEmpty())
+ {
+ // create a default tab list at 10 mm each.
+ for (int i = 0; i < 20; ++i)
+ {
tab_array.Add(i*100);
}
}
+
int map_mode = dc.GetMapMode();
dc.SetMapMode(wxMM_LOMETRIC );
int num_tabs = tab_array.GetCount();
- for( int i = 0; i < num_tabs; ++i){
- tab_array[i] = dc.LogicalToDeviceXRel(tab_array[i]);
+
+ for (int i = 0; i < num_tabs; ++i)
+ {
+ tab_array[i] = dc.LogicalToDeviceXRel(tab_array[i]);
}
dc.SetMapMode(map_mode );
int next_tab_pos = -1;
-
- while(stringChunk.Find(wxT('\t')) >= 0){// the string has a tab
+
+ while (stringChunk.Find(wxT('\t')) >= 0)
+ {
+ // the string has a tab
// break up the string at the Tab
wxString stringFragment = stringChunk.BeforeFirst(wxT('\t'));
stringChunk = stringChunk.AfterFirst(wxT('\t'));
width += w;
int absolute_width = width + position.x;
bool not_found = true;
- for( int i = 0; i < num_tabs && not_found; ++i){
+ for (int i = 0; i < num_tabs && not_found; ++i)
+ {
next_tab_pos = tab_array.Item(i);
- if( next_tab_pos > absolute_width){
- not_found = false;
+ if (next_tab_pos > absolute_width)
+ {
+ not_found = false;
width = next_tab_pos - position.x;
}
}
dc.GetTextExtent(stringChunk, & w, & h, & descent);
width += w;
size = wxSize(width, dc.GetCharHeight());
-
+
return true;
}
wxRichTextObject* wxRichTextPlainText::DoSplit(long pos)
{
int index = pos - GetRange().GetStart();
- if (index < 0 || index >= (int) m_text.Length())
+ if (index < 0 || index >= (int) m_text.length())
return NULL;
wxString firstPart = m_text.Mid(0, index);
/// Calculate range
void wxRichTextPlainText::CalculateRange(long start, long& end)
{
- end = start + m_text.Length() - 1;
+ end = start + m_text.length() - 1;
m_range.SetRange(start, end);
}
action->SetPosition(pos);
// Set the range we'll need to delete in Undo
- action->SetRange(wxRichTextRange(pos, pos + text.Length() - 1));
+ action->SetRange(wxRichTextRange(pos, pos + text.length() - 1));
SubmitAction(action);
wxRichTextAttr wxRichTextAttr::Combine(const wxRichTextAttr& attr,
const wxRichTextAttr& attrDef,
const wxTextCtrlBase *text)
-{
+{
wxColour colFg = attr.GetTextColour();
if ( !colFg.Ok() )
{
if (attr.HasWeight())
newAttr.SetFontWeight(attr.GetFontWeight());
-
+
if (attr.HasSize())
newAttr.SetFontSize(attr.GetFontSize());
-
+
if (attr.HasItalic())
newAttr.SetFontStyle(attr.GetFontStyle());
-
+
if (attr.HasUnderlined())
newAttr.SetFontUnderlined(attr.GetFontUnderlined());
-
+
if (attr.HasFaceName())
newAttr.SetFontFaceName(attr.GetFontFaceName());
-
+
if (attr.HasAlignment())
newAttr.SetAlignment(attr.GetAlignment());
else if (attrDef.HasAlignment())
newAttr.SetRightIndent(attr.GetRightIndent());
else if (attrDef.HasRightIndent())
newAttr.SetRightIndent(attrDef.GetRightIndent());
-
+
// NEW ATTRIBUTES
-
+
if (attr.HasParagraphSpacingAfter())
newAttr.SetParagraphSpacingAfter(attr.GetParagraphSpacingAfter());
-
+
if (attr.HasParagraphSpacingBefore())
newAttr.SetParagraphSpacingBefore(attr.GetParagraphSpacingBefore());
if (attr.HasLineSpacing())
newAttr.SetLineSpacing(attr.GetLineSpacing());
-
+
if (attr.HasCharacterStyleName())
newAttr.SetCharacterStyleName(attr.GetCharacterStyleName());
-
+
if (attr.HasParagraphStyleName())
newAttr.SetParagraphStyleName(attr.GetParagraphStyleName());
-
+
if (attr.HasBulletStyle())
newAttr.SetBulletStyle(attr.GetBulletStyle());
if (attr.HasBulletNumber())
newAttr.SetBulletNumber(attr.GetBulletNumber());
-
+
if (attr.HasBulletSymbol())
newAttr.SetBulletSymbol(attr.GetBulletSymbol());
-
+
return newAttr;
}
wxTextAttrEx wxTextAttrEx::CombineEx(const wxTextAttrEx& attr,
const wxTextAttrEx& attrDef,
const wxTextCtrlBase *text)
-{
+{
wxTextAttrEx newAttr;
// If attr specifies the complete font, just use that font, overriding all
newAttr.SetRightIndent(attr.GetRightIndent());
else if (attrDef.HasRightIndent())
newAttr.SetRightIndent(attrDef.GetRightIndent());
-
+
// NEW ATTRIBUTES
-
+
if (attr.HasParagraphSpacingAfter())
newAttr.SetParagraphSpacingAfter(attr.GetParagraphSpacingAfter());
-
+
if (attr.HasParagraphSpacingBefore())
newAttr.SetParagraphSpacingBefore(attr.GetParagraphSpacingBefore());
if (attr.HasLineSpacing())
newAttr.SetLineSpacing(attr.GetLineSpacing());
-
+
if (attr.HasCharacterStyleName())
newAttr.SetCharacterStyleName(attr.GetCharacterStyleName());
-
+
if (attr.HasParagraphStyleName())
newAttr.SetParagraphStyleName(attr.GetParagraphStyleName());
-
+
if (attr.HasBulletStyle())
newAttr.SetBulletStyle(attr.GetBulletStyle());
if (attr.HasBulletNumber())
newAttr.SetBulletNumber(attr.GetBulletNumber());
-
+
if (attr.HasBulletSymbol())
newAttr.SetBulletSymbol(attr.GetBulletSymbol());
-
+
return newAttr;
}
wxString text = buffer->GetText();
wxCharBuffer buf = text.ToAscii();
- stream.Write((const char*) buf, text.Length());
+ stream.Write((const char*) buf, text.length());
return true;
}
#endif // wxUSE_STREAMS
hex = wxDecToHex(m_data[i]);
wxCharBuffer buf = hex.ToAscii();
- stream.Write((const char*) buf, hex.Length());
+ stream.Write((const char*) buf, hex.length());
}
return true;