X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/7947a48ab76aa402808b365d375788b0d8a56b64..61961a3cdfd73e2256fbaac6cfd9df4b2fcd720d:/src/richtext/richtextbuffer.cpp diff --git a/src/richtext/richtextbuffer.cpp b/src/richtext/richtextbuffer.cpp index 85725e4ee8..d3fe3cfdf3 100644 --- a/src/richtext/richtextbuffer.cpp +++ b/src/richtext/richtextbuffer.cpp @@ -24,13 +24,13 @@ #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" @@ -908,7 +908,7 @@ wxRichTextRange wxRichTextParagraphLayoutBox::AddParagraphs(const wxString& text wxRichTextRange range(-1, -1); size_t i = 0; - size_t len = text.Length(); + size_t len = text.length(); wxString line; while (i < len) { @@ -2266,7 +2266,7 @@ bool wxRichTextParagraph::InsertText(long pos, const wxString& text) 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)); @@ -2760,7 +2760,7 @@ bool wxRichTextParagraph::FindWrapPosition(const wxRichTextRange& range, wxDC& d 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; } } @@ -2955,27 +2955,13 @@ bool wxRichTextPlainText::Draw(wxDC& dc, const wxRichTextRange& range, const wxR // (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 @@ -2994,13 +2980,7 @@ bool wxRichTextPlainText::Draw(wxDC& dc, const wxRichTextRange& range, const wxR 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); } @@ -3014,18 +2994,7 @@ bool wxRichTextPlainText::Draw(wxDC& dc, const wxRichTextRange& range, const wxR 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); } @@ -3039,9 +3008,7 @@ bool wxRichTextPlainText::Draw(wxDC& dc, const wxRichTextRange& range, const wxR 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); } } @@ -3052,43 +3019,57 @@ bool wxRichTextPlainText::Draw(wxDC& dc, const wxRichTextRange& range, const wxR 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){ + 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); @@ -3100,7 +3081,8 @@ bool wxRichTextPlainText::DrawTabbedString(wxDC& dc,const wxRect& rect,wxString& } dc.GetTextExtent(str, & w, & h); - if(selected){ + if (selected) + { wxRect selRect(x, rect.y, w, rect.GetHeight()); dc.DrawRectangle(selRect); } @@ -3149,27 +3131,33 @@ bool wxRichTextPlainText::GetRangeSize(const wxRichTextRange& range, wxSize& siz 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()) + if (tab_array.IsEmpty()) { // create a default tab list at 10 mm each. - for( int i = 0; i < 20; ++i) + 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) + + 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')); @@ -3177,9 +3165,11 @@ bool wxRichTextPlainText::GetRangeSize(const wxRichTextRange& range, wxSize& siz 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){ + if (next_tab_pos > absolute_width) + { not_found = false; width = next_tab_pos - position.x; } @@ -3198,7 +3188,7 @@ bool wxRichTextPlainText::GetRangeSize(const wxRichTextRange& range, wxSize& siz 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); @@ -3218,7 +3208,7 @@ wxRichTextObject* wxRichTextPlainText::DoSplit(long pos) /// 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); } @@ -3343,7 +3333,7 @@ bool wxRichTextBuffer::InsertTextWithUndo(long pos, const wxString& text, wxRich 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); @@ -5286,7 +5276,7 @@ bool wxRichTextPlainTextHandler::DoSaveFile(wxRichTextBuffer *buffer, wxOutputSt 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 @@ -5485,7 +5475,7 @@ bool wxRichTextImageBlock::WriteHex(wxOutputStream& stream) 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;