X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/968602f8909896da801e9460bfbbde9a33fd5f18..07aaf32633ecf18ec3edfbb41793a112914792d0:/src/x11/textctrl.cpp?ds=sidebyside diff --git a/src/x11/textctrl.cpp b/src/x11/textctrl.cpp index 6fd8e22899..d37b667068 100644 --- a/src/x11/textctrl.cpp +++ b/src/x11/textctrl.cpp @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: textctrl.cpp +// Name: src/x11/textctrl.cpp // Purpose: // Author: Robert Roebling // Id: $Id$ @@ -7,16 +7,20 @@ // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// -#ifdef __GNUG__ -#pragma implementation "textctrl.h" -#endif +// for compilers that support precompilation, includes "wx.h". +#include "wx/wxprec.h" #include "wx/textctrl.h" -#include "wx/utils.h" -#include "wx/intl.h" -#include "wx/log.h" -#include "wx/settings.h" -#include "wx/panel.h" + +#ifndef WX_PRECOMP + #include "wx/intl.h" + #include "wx/log.h" + #include "wx/utils.h" + #include "wx/panel.h" + #include "wx/dcclient.h" + #include "wx/settings.h" +#endif + #include "wx/clipbrd.h" #include "wx/tokenzr.h" @@ -35,10 +39,10 @@ wxSourceUndoStep::wxSourceUndoStep( wxSourceUndo type, int y1, int y2, wxTextCtr m_y1 = y1; m_y2 = y2; m_owner = owner; - + m_cursorX = m_owner->GetCursorX(); m_cursorY = m_owner->GetCursorY(); - + if (m_type == wxSOURCE_UNDO_LINE) { m_text = m_owner->m_lines[m_y1].m_text; @@ -52,7 +56,7 @@ wxSourceUndoStep::wxSourceUndoStep( wxSourceUndo type, int y1, int y2, wxTextCtr for (int i = m_y1; i < m_y2+2; i++) { if (i >= (int)m_owner->m_lines.GetCount()) - m_lines.Add( "" ); + m_lines.Add( wxEmptyString ); else m_lines.Add( m_owner->m_lines[i].m_text ); } @@ -127,17 +131,14 @@ WX_DEFINE_OBJARRAY(wxSourceLineArray); // wxTextCtrl //----------------------------------------------------------------------------- -IMPLEMENT_DYNAMIC_CLASS(wxTextCtrl,wxControl) - -BEGIN_EVENT_TABLE(wxTextCtrl, wxControl) +BEGIN_EVENT_TABLE(wxTextCtrl, wxTextCtrlBase) EVT_PAINT(wxTextCtrl::OnPaint) EVT_ERASE_BACKGROUND(wxTextCtrl::OnEraseBackground) EVT_CHAR(wxTextCtrl::OnChar) EVT_MOUSE_EVENTS(wxTextCtrl::OnMouse) - EVT_IDLE(wxTextCtrl::OnIdle) EVT_KILL_FOCUS(wxTextCtrl::OnKillFocus) EVT_SET_FOCUS(wxTextCtrl::OnSetFocus) - + EVT_MENU(wxID_CUT, wxTextCtrl::OnCut) EVT_MENU(wxID_COPY, wxTextCtrl::OnCopy) EVT_MENU(wxID_PASTE, wxTextCtrl::OnPaste) @@ -153,36 +154,34 @@ END_EVENT_TABLE() void wxTextCtrl::Init() { - m_editable = TRUE; - m_modified = FALSE; - - m_undos.DeleteContents( TRUE ); - + m_editable = true; + m_modified = false; + m_lang = wxSOURCE_LANG_NONE; - - m_capturing = FALSE; - + + m_capturing = false; + m_cursorX = 0; m_cursorY = 0; - + m_longestLine = 0; - + m_bracketX = -1; m_bracketY = -1; - - m_overwrite = FALSE; - m_ignoreInput = FALSE; - + + m_overwrite = false; + m_ignoreInput = false; + ClearSelection(); - + m_keywordColour = wxColour( 10, 140, 10 ); - + m_defineColour = *wxRED; - + m_variableColour = wxColour( 50, 120, 150 ); - + m_commentColour = wxColour( 130, 130, 130 ); - + m_stringColour = wxColour( 10, 140, 10 ); } @@ -201,6 +200,11 @@ wxTextCtrl::wxTextCtrl( wxWindow *parent, Create( parent, id, value, pos, size, style, validator, name ); } +wxTextCtrl::~wxTextCtrl() +{ + WX_CLEAR_LIST(wxList, m_undos); +} + bool wxTextCtrl::Create( wxWindow *parent, wxWindowID id, const wxString &value, @@ -212,19 +216,19 @@ bool wxTextCtrl::Create( wxWindow *parent, { if ((style & wxBORDER_MASK) == 0) style |= wxBORDER_SUNKEN; - + if ((style & wxTE_MULTILINE) != 0) style |= wxALWAYS_SHOW_SB; - + wxTextCtrlBase::Create( parent, id, pos /* wxDefaultPosition */, size, - style|wxVSCROLL|wxHSCROLL|wxNO_FULL_REPAINT_ON_RESIZE ); - + style | wxVSCROLL | wxHSCROLL); + SetBackgroundColour( *wxWHITE ); - + SetCursor( wxCursor( wxCURSOR_IBEAM ) ); - + m_editable = ((m_windowStyle & wxTE_READONLY) == 0); - + if (HasFlag(wxTE_PASSWORD)) m_sourceFont = wxFont( 12, wxMODERN, wxNORMAL, wxNORMAL ); else @@ -234,7 +238,7 @@ bool wxTextCtrl::Create( wxWindow *parent, dc.SetFont( m_sourceFont ); m_lineHeight = dc.GetCharHeight(); m_charWidth = dc.GetCharWidth(); - + SetValue( value ); wxSize size_best( DoGetBestSize() ); @@ -245,11 +249,13 @@ bool wxTextCtrl::Create( wxWindow *parent, new_size.y = size_best.y; if ((new_size.x != size.x) || (new_size.y != size.y)) SetSize( new_size.x, new_size.y ); - + // We create an input handler since it might be useful CreateInputHandler(wxINP_HANDLER_TEXTCTRL); - - return TRUE; + + MyAdjustScrollbars(); + + return true; } //----------------------------------------------------------------------------- @@ -265,29 +271,25 @@ wxString wxTextCtrl::GetValue() const if (i+1 < m_lines.GetCount()) ret += wxT('\n'); } - + return ret; } -void wxTextCtrl::SetValue(const wxString& value) +void wxTextCtrl::DoSetValue(const wxString& value, int flags) { - m_modified = TRUE; + m_modified = false; + + wxString oldValue = GetValue(); - if ((GetWindowStyle() & wxTE_MULTILINE) == 0) - { - if (value == GetValue()) - return; - } - m_cursorX = 0; m_cursorY = 0; ClearSelection(); m_lines.Clear(); m_longestLine = 0; - if (value.IsEmpty()) + if (value.empty()) { - m_lines.Add( new wxSourceLine( wxT("") ) ); + m_lines.Add( new wxSourceLine( wxEmptyString ) ); } else { @@ -300,7 +302,7 @@ void wxTextCtrl::SetValue(const wxString& value) { wxSourceLine *sl = new wxSourceLine( value.Mid( begin, value.Len()-begin ) ); m_lines.Add( sl ); - + // if (sl->m_text.Len() > m_longestLine) // m_longestLine = sl->m_text.Len(); int ww = 0; @@ -308,14 +310,14 @@ void wxTextCtrl::SetValue(const wxString& value) ww /= m_charWidth; if (ww > m_longestLine) m_longestLine = ww; - + break; } else { wxSourceLine *sl = new wxSourceLine( value.Mid( begin, pos-begin ) ); m_lines.Add( sl ); - + // if (sl->m_text.Len() > m_longestLine) // m_longestLine = sl->m_text.Len(); int ww = 0; @@ -323,30 +325,40 @@ void wxTextCtrl::SetValue(const wxString& value) ww /= m_charWidth; if (ww > m_longestLine) m_longestLine = ww; - + begin = pos+1; } } } - + + // Don't need to refresh if the value hasn't changed + if ((GetWindowStyle() & wxTE_MULTILINE) == 0) + { + if (value == oldValue) + return; + } + MyAdjustScrollbars(); - + Refresh(); + + if ( flags & SetValue_SendEvent ) + SendTextUpdatedEvent(); } int wxTextCtrl::GetLineLength(long lineNo) const { if (lineNo >= (long)m_lines.GetCount()) return 0; - + return m_lines[lineNo].m_text.Len(); } wxString wxTextCtrl::GetLineText(long lineNo) const { if (lineNo >= (long)m_lines.GetCount()) - return wxT(""); - + return wxEmptyString; + return m_lines[lineNo].m_text; } @@ -367,21 +379,32 @@ bool wxTextCtrl::IsEditable() const void wxTextCtrl::GetSelection(long* from, long* to) const { + if (m_selStartX == -1 || m_selStartY == -1 || + m_selEndX == -1 || m_selEndY == -1) + { + *from = GetInsertionPoint(); + *to = GetInsertionPoint(); + } + else + { + *from = XYToPosition(m_selStartX, m_selStartY); + *to = XYToPosition(m_selEndX, m_selEndY); + } } void wxTextCtrl::Clear() { - m_modified = TRUE; + m_modified = true; m_cursorX = 0; m_cursorY = 0; ClearSelection(); - + m_lines.Clear(); - m_lines.Add( new wxSourceLine( wxT("") ) ); - + m_lines.Add( new wxSourceLine( wxEmptyString ) ); + SetScrollbars( m_charWidth, m_lineHeight, 0, 0, 0, 0 ); Refresh(); - m_undos.Clear(); + WX_CLEAR_LIST(wxList, m_undos); } void wxTextCtrl::Replace(long from, long to, const wxString& value) @@ -390,7 +413,6 @@ void wxTextCtrl::Replace(long from, long to, const wxString& value) void wxTextCtrl::Remove(long from, long to) { - } void wxTextCtrl::DiscardEdits() @@ -409,16 +431,16 @@ int wxTextCtrl::PosToPixel( int line, int pos ) if (line >= (int)m_lines.GetCount()) return 0; if (pos < 0) return 0; - + wxString text = m_lines[line].m_text; - - if (text.IsEmpty()) return 0; - + + if (text.empty()) return 0; + if (pos < (int)text.Len()) text.Remove( pos, text.Len()-pos ); - + int w = 0; - + GetTextExtent( text, &w, NULL, NULL, NULL ); return w; @@ -427,218 +449,40 @@ int wxTextCtrl::PosToPixel( int line, int pos ) int wxTextCtrl::PixelToPos( int line, int pixel ) { if (pixel < 2) return 0; - + if (line >= (int)m_lines.GetCount()) return 0; - + wxString text = m_lines[line].m_text; - + int w = 0; int res = text.Len(); while (res > 0) { GetTextExtent( text, &w, NULL, NULL, NULL ); - + if (w < pixel) return res; - + res--; text.Remove( res,1 ); } - + return 0; } void wxTextCtrl::SetLanguage( wxSourceLanguage lang ) { m_lang = lang; - - m_keywords.Clear(); - if (m_lang == wxSOURCE_LANG_PYTHON) - { - m_keywords.Add( "class" ); - m_keywords.Add( "__init__" ); - m_keywords.Add( "return" ); - m_keywords.Add( "def" ); - m_keywords.Add( "try" ); - m_keywords.Add( "except" ); - m_keywords.Add( "if" ); - m_keywords.Add( "else" ); - m_keywords.Add( "finally" ); - m_keywords.Add( "for" ); - m_keywords.Add( "if" ); - m_keywords.Add( "elif" ); - m_keywords.Add( "in" ); - m_keywords.Add( "and" ); - m_keywords.Add( "del" ); - m_keywords.Add( "is" ); - m_keywords.Add( "raise" ); - m_keywords.Add( "assert" ); - m_keywords.Add( "lambda" ); - m_keywords.Add( "break" ); - m_keywords.Add( "global" ); - m_keywords.Add( "not" ); - m_keywords.Add( "or" ); - m_keywords.Add( "while" ); - m_keywords.Add( "continue" ); - m_keywords.Add( "exec" ); - m_keywords.Add( "pass" ); - m_keywords.Add( "print" ); - } else - if (m_lang == wxSOURCE_LANG_PERL) - { - m_keywords.Add( "main" ); - m_keywords.Add( "sub" ); - m_keywords.Add( "shift" ); - m_keywords.Add( "push" ); - m_keywords.Add( "split" ); - m_keywords.Add( "join" ); - m_keywords.Add( "chop" ); - m_keywords.Add( "grep" ); - m_keywords.Add( "open" ); - m_keywords.Add( "print" ); - m_keywords.Add( "sprint" ); - m_keywords.Add( "printf" ); - m_keywords.Add( "sprintf" ); - m_keywords.Add( "my" ); - m_keywords.Add( "local" ); - m_keywords.Add( "exit" ); - m_keywords.Add( "die" ); - m_keywords.Add( "return" ); - m_keywords.Add( "for" ); - m_keywords.Add( "foreach" ); - m_keywords.Add( "while" ); - m_keywords.Add( "unless" ); - m_keywords.Add( "if" ); - m_keywords.Add( "next" ); - m_keywords.Add( "last" ); - m_keywords.Add( "else" ); - m_keywords.Add( "elsif" ); - m_keywords.Add( "ne" ); - m_keywords.Add( "qe" ); - } - else - if (m_lang == wxSOURCE_LANG_CPP) - { - m_keywords.Add( "class" ); - m_keywords.Add( "return" ); - m_keywords.Add( "if" ); - m_keywords.Add( "then" ); - m_keywords.Add( "else" ); - m_keywords.Add( "struct" ); - m_keywords.Add( "enum" ); - m_keywords.Add( "while" ); - m_keywords.Add( "do" ); - m_keywords.Add( "for" ); - m_keywords.Add( "continue" ); - m_keywords.Add( "break" ); - m_keywords.Add( "switch" ); - m_keywords.Add( "case" ); - m_keywords.Add( "goto" ); - m_keywords.Add( "label" ); - m_keywords.Add( "inline" ); - m_keywords.Add( "operator" ); - m_keywords.Add( "virtual" ); - m_keywords.Add( "private" ); - m_keywords.Add( "public" ); - m_keywords.Add( "protected" ); - m_keywords.Add( "friend" ); - m_keywords.Add( "exception" ); - m_keywords.Add( "throw" ); - m_keywords.Add( "catch" ); - m_keywords.Add( "delete" ); - m_keywords.Add( "new" ); - m_keywords.Add( "default" ); - m_keywords.Add( "overload" ); - m_keywords.Add( "using" ); - m_keywords.Add( "template" ); - m_keywords.Add( "try" ); - m_keywords.Add( "typedef" ); - m_keywords.Add( "union" ); - m_keywords.Add( "volatile" ); - m_keywords.Add( "asm" ); - } - - m_defines.Clear(); - - if (m_lang == wxSOURCE_LANG_PYTHON) - { - m_defines.Add( "from" ); - m_defines.Add( "import" ); - } else - if (m_lang == wxSOURCE_LANG_PERL) - { - m_defines.Add( "use" ); - m_defines.Add( "do" ); - m_defines.Add( "package" ); - m_defines.Add( "defined" ); - } else - if (m_lang == wxSOURCE_LANG_CPP) - { - m_defines.Add( "#define" ); - m_defines.Add( "#if" ); - m_defines.Add( "#ifndef" ); - m_defines.Add( "#ifdef" ); - m_defines.Add( "#else" ); - m_defines.Add( "#elif" ); - m_defines.Add( "#endif" ); - m_defines.Add( "#pragma" ); - m_defines.Add( "#include" ); - } - - m_variables.Clear(); - - if (m_lang == wxSOURCE_LANG_PYTHON) - { - m_variables.Add( "nil" ); - m_variables.Add( "None" ); - m_variables.Add( "self" ); - m_variables.Add( "false" ); - m_variables.Add( "true" ); - } else - if (m_lang == wxSOURCE_LANG_PERL) - { - m_variables.Add( "undef" ); - m_variables.Add( "class" ); - m_variables.Add( "this" ); - m_variables.Add( "IN" ); - m_variables.Add( "OUT" ); - m_variables.Add( "STDIN" ); - m_variables.Add( "STDOUT" ); - m_variables.Add( "STDERR" ); - } else - if (m_lang == wxSOURCE_LANG_CPP) - { - m_variables.Add( "int" ); - m_variables.Add( "bool" ); - m_variables.Add( "void" ); - m_variables.Add( "long" ); - m_variables.Add( "short" ); - m_variables.Add( "const" ); - m_variables.Add( "signed" ); - m_variables.Add( "unsigned" ); - m_variables.Add( "char" ); - m_variables.Add( "size_t" ); - m_variables.Add( "wchar_t" ); - m_variables.Add( "NULL" ); - m_variables.Add( "this" ); - m_variables.Add( "TRUE" ); - m_variables.Add( "FALSE" ); - m_variables.Add( "float" ); - m_variables.Add( "double" ); - m_variables.Add( "register" ); - m_variables.Add( "extern" ); - m_variables.Add( "static" ); - m_variables.Add( "sizeof" ); - } + m_keywords.Clear(); } void wxTextCtrl::WriteText(const wxString& text2) { - if (text2.IsEmpty()) return; + if (text2.empty()) return; + + m_modified = true; - m_modified = TRUE; - wxString text( text2 ); wxArrayString lines; int pos; @@ -649,11 +493,11 @@ void wxTextCtrl::WriteText(const wxString& text2) } lines.Add( text ); int count = (int)lines.GetCount(); - + wxString tmp1( m_lines[m_cursorY].m_text ); wxString tmp2( tmp1 ); int len = (int)tmp1.Len(); - + if (len < m_cursorX) { wxString tmp; @@ -667,11 +511,11 @@ void wxTextCtrl::WriteText(const wxString& text2) tmp1.Remove( m_cursorX ); tmp2.Remove( 0, m_cursorX ); tmp1.Append( lines[0] ); - + if (count == 1) { m_undos.Append( new wxSourceUndoStep( wxSOURCE_UNDO_LINE, m_cursorY, m_cursorY, this ) ); - + tmp1.Append( tmp2 ); m_lines[m_cursorY].m_text = tmp1; RefreshLine( m_cursorY ); @@ -679,13 +523,13 @@ void wxTextCtrl::WriteText(const wxString& text2) else { m_undos.Append( new wxSourceUndoStep( wxSOURCE_UNDO_PASTE, m_cursorY, m_cursorY+count-1, this ) ); - + m_lines[m_cursorY].m_text = tmp1; int i; for (i = 1; i < count; i++) m_lines.Insert( new wxSourceLine( lines[i] ), m_cursorY+i ); m_lines[m_cursorY+i-1].m_text.Append( tmp2 ); - + MyAdjustScrollbars(); RefreshDown( m_cursorY ); } @@ -693,10 +537,10 @@ void wxTextCtrl::WriteText(const wxString& text2) void wxTextCtrl::AppendText(const wxString& text2) { - if (text2.IsEmpty()) return; + if (text2.empty()) return; + + m_modified = true; - m_modified = TRUE; - wxString text( text2 ); wxArrayString lines; int pos; @@ -707,28 +551,28 @@ void wxTextCtrl::AppendText(const wxString& text2) } lines.Add( text ); int count = (int)lines.GetCount(); - + size_t y = m_lines.GetCount()-1; wxString tmp( m_lines[y].m_text ); tmp.Append( lines[0] ); - + if (count == 1) { m_undos.Append( new wxSourceUndoStep( wxSOURCE_UNDO_LINE, y, y, this ) ); - + m_lines[y].m_text = tmp; RefreshLine( y ); } else { m_undos.Append( new wxSourceUndoStep( wxSOURCE_UNDO_PASTE, y, y+count-1, this ) ); - + m_lines[y].m_text = tmp; int i; for (i = 1; i < count; i++) m_lines.Insert( new wxSourceLine( lines[i] ), y+i ); - + MyAdjustScrollbars(); RefreshDown( y ); } @@ -736,27 +580,28 @@ void wxTextCtrl::AppendText(const wxString& text2) bool wxTextCtrl::SetStyle(long start, long end, const wxTextAttr& style) { - return FALSE; + return false; } long wxTextCtrl::XYToPosition(long x, long y) const { long ret = 0; - + for (size_t i = 0; i < m_lines.GetCount(); i++) { if (i < (size_t)y) { - ret += m_lines[i].m_text.Len(); + // Add one for the end-of-line character + ret += m_lines[i].m_text.Len() + 1; continue; } - - if ((size_t)x < m_lines[i].m_text.Len()) + + if ((size_t)x < (m_lines[i].m_text.Len()+1)) return (ret + x); else - return (ret + m_lines[i].m_text.Len()); + return (ret + m_lines[i].m_text.Len() + 1); } - + return ret; } @@ -772,26 +617,32 @@ bool wxTextCtrl::PositionToXY(long pos, long *x, long *y) const long xx = 0; long yy = 0; - + for (size_t i = 0; i < m_lines.GetCount(); i++) { - pos -= m_lines[i].m_text.Len(); - if (pos <= 0) + //pos -= m_lines[i].m_text.Len(); + //if (pos <= 0) + + // Add one for the end-of-line character. (In Windows, + // there are _two_ positions for each end of line.) + if (pos <= ((int)m_lines[i].m_text.Len())) { - xx = -pos; + xx = pos; if (x) *x = xx; if (y) *y = yy; - return TRUE; + return true; } + pos -= (m_lines[i].m_text.Len() + 1); yy++; } - + // Last pos - xx = m_lines[ m_lines.GetCount()-1 ].m_text.Len(); + //xx = m_lines[ m_lines.GetCount()-1 ].m_text.Len(); + xx = pos; if (x) *x = xx; if (y) *y = yy; - - return FALSE; + + return false; } void wxTextCtrl::ShowPosition(long pos) @@ -801,14 +652,14 @@ void wxTextCtrl::ShowPosition(long pos) void wxTextCtrl::Copy() { if (!HasSelection()) return; - + wxString sel; - + int selStartY = m_selStartY; int selEndY = m_selEndY; int selStartX = m_selStartX; int selEndX = m_selEndX; - + if ((selStartY > selEndY) || ((selStartY == selEndY) && (selStartX > selEndX))) { @@ -819,32 +670,32 @@ void wxTextCtrl::Copy() selStartY = selEndY; selEndY = tmp; } - + if (selStartY == selEndY) { sel = m_lines[selStartY].m_text; - + if (selStartX >= (int)sel.Len()) return; if (selEndX > (int)sel.Len()) selEndX = sel.Len(); - + sel.Remove( selEndX, sel.Len()-selEndX ); sel.Remove( 0, selStartX ); } else { wxString tmp( m_lines[selStartY].m_text ); - + if (selStartX < (int)tmp.Len()) { tmp.Remove( 0, selStartX ); sel = tmp; - sel.Append( "\n" ); + sel.Append( wxT("\n") ); } for (int i = selStartY+1; i < selEndY; i++) { sel.Append( m_lines[i].m_text ); - sel.Append( "\n" ); + sel.Append( wxT("\n") ); } tmp = m_lines[selEndY].m_text; if (selEndX > (int)tmp.Len()) @@ -855,7 +706,7 @@ void wxTextCtrl::Copy() sel.Append( tmp ); } } - + if (wxTheClipboard->Open()) { wxTheClipboard->SetData( new wxTextDataObject( sel ) ); @@ -865,34 +716,34 @@ void wxTextCtrl::Copy() void wxTextCtrl::Cut() { - Copy(); - - Delete(); + Copy(); + + Delete(); } void wxTextCtrl::Paste() { Delete(); - + if (!wxTheClipboard->Open()) return; - + if (!wxTheClipboard->IsSupported( wxDF_TEXT )) { wxTheClipboard->Close(); - + return; } - + wxTextDataObject data; - + bool ret = wxTheClipboard->GetData( data ); - + wxTheClipboard->Close(); - + if (!ret) return; - - m_modified = TRUE; - + + m_modified = true; + wxString text( data.GetText() ); wxArrayString lines; int pos; @@ -903,11 +754,11 @@ void wxTextCtrl::Paste() } lines.Add( text ); int count = (int)lines.GetCount(); - + wxString tmp1( m_lines[m_cursorY].m_text ); wxString tmp2( tmp1 ); int len = (int)tmp1.Len(); - + if (len < m_cursorX) { wxString tmp; @@ -921,11 +772,11 @@ void wxTextCtrl::Paste() tmp1.Remove( m_cursorX ); tmp2.Remove( 0, m_cursorX ); tmp1.Append( lines[0] ); - + if (count == 1) { m_undos.Append( new wxSourceUndoStep( wxSOURCE_UNDO_LINE, m_cursorY, m_cursorY, this ) ); - + tmp1.Append( tmp2 ); m_lines[m_cursorY].m_text = tmp1; RefreshLine( m_cursorY ); @@ -933,13 +784,13 @@ void wxTextCtrl::Paste() else { m_undos.Append( new wxSourceUndoStep( wxSOURCE_UNDO_PASTE, m_cursorY, m_cursorY+count-1, this ) ); - + m_lines[m_cursorY].m_text = tmp1; int i; for (i = 1; i < count; i++) m_lines.Insert( new wxSourceLine( lines[i] ), m_cursorY+i ); m_lines[m_cursorY+i-1].m_text.Append( tmp2 ); - + MyAdjustScrollbars(); RefreshDown( m_cursorY ); } @@ -948,23 +799,32 @@ void wxTextCtrl::Paste() void wxTextCtrl::Undo() { if (m_undos.GetCount() == 0) return; - - wxNode *node = m_undos.Nth( m_undos.GetCount()-1 ); - wxSourceUndoStep *undo = (wxSourceUndoStep*) node->Data(); - + + wxList::compatibility_iterator node = m_undos.Item( m_undos.GetCount()-1 ); + wxSourceUndoStep *undo = (wxSourceUndoStep*) node->GetData(); + undo->Undo(); - - delete node; - - m_modified = TRUE; + + delete undo; + m_undos.Erase( node ); + + m_modified = true; } void wxTextCtrl::SetInsertionPoint(long pos) { + ClearSelection(); + long x, y; + PositionToXY(pos, & x, & y); + m_cursorX = x; + m_cursorY = y; + // TODO: scroll to this position if necessary + Refresh(); } void wxTextCtrl::SetInsertionPointEnd() { + SetInsertionPoint(GetLastPosition()); } long wxTextCtrl::GetInsertionPoint() const @@ -972,10 +832,12 @@ long wxTextCtrl::GetInsertionPoint() const return XYToPosition( m_cursorX, m_cursorY ); } -long wxTextCtrl::GetLastPosition() const +wxTextPos wxTextCtrl::GetLastPosition() const { size_t lineCount = m_lines.GetCount() - 1; - return XYToPosition( m_lines[lineCount].m_text.Len()-1, lineCount ); + // It's the length of the line, not the length - 1, + // because there's a position after the last character. + return XYToPosition( m_lines[lineCount].m_text.Len(), lineCount ); } void wxTextCtrl::SetSelection(long from, long to) @@ -989,25 +851,25 @@ void wxTextCtrl::SetEditable(bool editable) bool wxTextCtrl::Enable( bool enable ) { - return FALSE; + return false; } bool wxTextCtrl::SetFont(const wxFont& font) { wxTextCtrlBase::SetFont( font ); - + m_sourceFont = font; - + wxClientDC dc(this); dc.SetFont( m_sourceFont ); m_lineHeight = dc.GetCharHeight(); m_charWidth = dc.GetCharWidth(); - + // TODO: recalc longest lines - + MyAdjustScrollbars(); - - return TRUE; + + return true; } bool wxTextCtrl::SetForegroundColour(const wxColour& colour) @@ -1028,26 +890,26 @@ void wxTextCtrl::SearchForBrackets() { int oldBracketY = m_bracketY; int oldBracketX = m_bracketX; - + if (m_cursorY < 0 || m_cursorY >= (int)m_lines.GetCount()) return; - + wxString current = m_lines[m_cursorY].m_text; - + // reverse search first char bracket = ' '; - + if (m_cursorX > 0) - bracket = current[m_cursorX-1]; - + bracket = current[(size_t) (m_cursorX-1)]; + if (bracket == ')' || bracket == ']' || bracket == '}') { char antibracket = '('; if (bracket == ']') antibracket = '['; if (bracket == '}') antibracket = '{'; - + int count = 1; - + int endY = m_cursorY-60; if (endY < 0) endY = 0; for (int y = m_cursorY; y >= endY; y--) @@ -1055,40 +917,40 @@ void wxTextCtrl::SearchForBrackets() current = m_lines[y].m_text; if (y == m_cursorY) current.erase(m_cursorX-1,current.Len()-m_cursorX+1); - + for (int n = current.Len()-1; n >= 0; n--) { // ignore chars - if (current[n] == '\'') + if (current[(size_t) (n)] == '\'') { for (int m = n-1; m >= 0; m--) { - if (current[m] == '\'') + if (current[(size_t) (m)] == '\'') { - if (m == 0 || current[m-1] != '\\') + if (m == 0 || current[(size_t) (m-1)] != '\\') break; } n = m-1; } continue; } - + // ignore strings - if (current[n] == '\"') + if (current[(size_t) (n)] == '\"') { for (int m = n-1; m >= 0; m--) { - if (current[m] == '\"') + if (current[(size_t) (m)] == '\"') { - if (m == 0 || current[m-1] != '\\') + if (m == 0 || current[(size_t) (m-1)] != '\\') break; } n = m-1; } continue; } - - if (current[n] == antibracket) + + if (current[(size_t) (n)] == antibracket) { count--; if (count == 0) @@ -1102,27 +964,27 @@ void wxTextCtrl::SearchForBrackets() return; } } - else if (current[n] == bracket) + else if (current[(size_t) (n)] == bracket) { count++; } } } } - + // then forward bracket = ' '; if ((int)current.Len() > m_cursorX) - bracket = current[m_cursorX]; + bracket = current[(size_t) (m_cursorX)]; if (bracket == '(' || bracket == '[' || bracket == '{') { char antibracket = ')'; if (bracket == '[') antibracket = ']'; if (bracket == '{') antibracket = '}'; - + int count = 1; - + int endY = m_cursorY+60; if (endY > (int)(m_lines.GetCount()-1)) endY = m_lines.GetCount()-1; for (int y = m_cursorY; y <= endY; y++) @@ -1131,40 +993,40 @@ void wxTextCtrl::SearchForBrackets() int start = 0; if (y == m_cursorY) start = m_cursorX+1; - + for (int n = start; n < (int)current.Len(); n++) { // ignore chars - if (current[n] == '\'') + if (current[(size_t) (n)] == '\'') { for (int m = n+1; m < (int)current.Len(); m++) { - if (current[m] == '\'') + if (current[(size_t) (m)] == '\'') { - if (m == 0 || (current[m-1] != '\\') || (m >= 2 && current[m-2] == '\\')) + if (m == 0 || (current[(size_t) (m-1)] != '\\') || (m >= 2 && current[(size_t) (m-2)] == '\\')) break; } n = m+1; } continue; } - + // ignore strings - if (current[n] == '\"') + if (current[(size_t) (n)] == '\"') { for (int m = n+1; m < (int)current.Len(); m++) { - if (current[m] == '\"') + if (current[(size_t) (m)] == '\"') { - if (m == 0 || (current[m-1] != '\\') || (m >= 2 && current[m-2] == '\\')) + if (m == 0 || (current[(size_t) (m-1)] != '\\') || (m >= 2 && current[(size_t) (m-2)] == '\\')) break; } n = m+1; } continue; } - - if (current[n] == antibracket) + + if (current[(size_t) (n)] == antibracket) { count--; if (count == 0) @@ -1178,14 +1040,14 @@ void wxTextCtrl::SearchForBrackets() return; } } - else if (current[n] == bracket) + else if (current[(size_t) (n)] == bracket) { count++; } } } } - + if (oldBracketY != -1) { m_bracketY = -1; @@ -1196,14 +1058,14 @@ void wxTextCtrl::SearchForBrackets() void wxTextCtrl::Delete() { if (!HasSelection()) return; - - m_modified = TRUE; - + + m_modified = true; + int selStartY = m_selStartY; int selEndY = m_selEndY; int selStartX = m_selStartX; int selEndX = m_selEndX; - + if ((selStartY > selEndY) || ((selStartY == selEndY) && (selStartX > selEndX))) { @@ -1214,13 +1076,13 @@ void wxTextCtrl::Delete() selStartY = selEndY; selEndY = tmp; } - + int len = (int)m_lines[selStartY].m_text.Len(); - + if (selStartY == selEndY) { m_undos.Append( new wxSourceUndoStep( wxSOURCE_UNDO_LINE, selStartY, selStartY, this ) ); - + wxString tmp( m_lines[selStartY].m_text ); if (selStartX < len) { @@ -1236,25 +1098,25 @@ void wxTextCtrl::Delete() else { m_undos.Append( new wxSourceUndoStep( wxSOURCE_UNDO_DELETE, selStartY, selEndY, this ) ); - + if (selStartX < len) m_lines[selStartY].m_text.Remove( selStartX ); - + for (int i = 0; i < selEndY-selStartY-1; i++) m_lines.RemoveAt( selStartY+1 ); - + if (selEndX < (int)m_lines[selStartY+1].m_text.Len()) m_lines[selStartY+1].m_text.Remove( 0, selEndX ); else m_lines[selStartY+1].m_text.Remove( 0 ); - + m_lines[selStartY].m_text.Append( m_lines[selStartY+1].m_text ); m_lines.RemoveAt( selStartY+1 ); - + ClearSelection(); MoveCursor( selStartX, selStartY ); MyAdjustScrollbars(); - + RefreshDown( selStartY ); } } @@ -1262,25 +1124,25 @@ void wxTextCtrl::Delete() void wxTextCtrl::DeleteLine() { if (HasSelection()) return; - + if (m_cursorY < 0 || m_cursorY >= (int)m_lines.GetCount()-1) return; // TODO - + m_undos.Append( new wxSourceUndoStep( wxSOURCE_UNDO_DELETE, m_cursorY, m_cursorY+1, this ) ); - + m_lines.RemoveAt( m_cursorY ); m_cursorX = 0; if (m_cursorY >= (int)m_lines.GetCount()) m_cursorY--; - + MyAdjustScrollbars(); RefreshDown( m_cursorY ); } void wxTextCtrl::DoChar( char c ) { - m_modified = TRUE; - + m_modified = true; + m_undos.Append( new wxSourceUndoStep( wxSOURCE_UNDO_LINE, m_cursorY, m_cursorY, this ) ); - + wxString tmp( m_lines[m_cursorY].m_text ); tmp.Trim(); if (m_cursorX >= (int)tmp.Len()) @@ -1297,15 +1159,15 @@ void wxTextCtrl::DoChar( char c ) else tmp.insert( m_cursorX, 1, c ); } - + m_lines[m_cursorY].m_text = tmp; - + // if (tmp.Len() > m_longestLine) // { // m_longestLine = tmp.Len(); // MyAdjustScrollbars(); // } - + int ww = 0; GetTextExtent( tmp, &ww, NULL, NULL, NULL ); ww /= m_charWidth; @@ -1316,29 +1178,29 @@ void wxTextCtrl::DoChar( char c ) } m_cursorX++; - + int y = m_cursorY*m_lineHeight; // int x = (m_cursorX-1)*m_charWidth; int x = PosToPixel( m_cursorY, m_cursorX-1 ); CalcScrolledPosition( x, y, &x, &y ); wxRect rect( x+2, y+2, 10000, m_lineHeight ); - Refresh( TRUE, &rect ); + Refresh( true, &rect ); // refresh whole line for syntax colour highlighting rect.x = 0; - Refresh( FALSE, &rect ); - + Refresh( false, &rect ); + int size_x = 0; int size_y = 0; GetClientSize( &size_x, &size_y ); size_x /= m_charWidth; - + int view_x = 0; int view_y = 0; GetViewStart( &view_x, &view_y ); - + //int xx = m_cursorX; int xx = PosToPixel( m_cursorY, m_cursorX ) / m_charWidth; - + if (xx < view_x) Scroll( xx, -1 ); else if (xx > view_x+size_x-1) @@ -1347,14 +1209,14 @@ void wxTextCtrl::DoChar( char c ) void wxTextCtrl::DoBack() { - m_modified = TRUE; - + m_modified = true; + if (m_cursorX == 0) { if (m_cursorY == 0) return; - + m_undos.Append( new wxSourceUndoStep( wxSOURCE_UNDO_BACK, m_cursorY-1, m_cursorY, this ) ); - + wxString tmp1( m_lines[m_cursorY-1].m_text ); tmp1.Trim(); wxString tmp2( m_lines[m_cursorY].m_text ); @@ -1364,34 +1226,34 @@ void wxTextCtrl::DoBack() tmp1.Append( tmp2 ); m_lines[m_cursorY].m_text = tmp1; m_lines.RemoveAt( m_cursorY+1 ); - + MyAdjustScrollbars(); RefreshDown( m_cursorY-1 ); } else { m_undos.Append( new wxSourceUndoStep( wxSOURCE_UNDO_LINE, m_cursorY, m_cursorY, this ) ); - + if (m_cursorX <= (int)m_lines[m_cursorY].m_text.Len()) m_lines[m_cursorY].m_text.Remove( m_cursorX-1, 1 ); m_cursorX--; - + int y = m_cursorY*m_lineHeight; // int x = m_cursorX*m_charWidth; int x = PosToPixel( m_cursorY, m_cursorX ); CalcScrolledPosition( x, y, &x, &y ); wxRect rect( x+2, y+2, 10000, m_lineHeight ); - Refresh( TRUE, &rect ); + Refresh( true, &rect ); // refresh whole line for syntax colour highlighting rect.x = 0; - Refresh( FALSE, &rect ); + Refresh( false, &rect ); } } void wxTextCtrl::DoDelete() { - m_modified = TRUE; - + m_modified = true; + wxString tmp( m_lines[m_cursorY].m_text ); tmp.Trim(); int len = (int)tmp.Len(); @@ -1400,43 +1262,43 @@ void wxTextCtrl::DoDelete() if (m_cursorY == (int)m_lines.GetCount()-1) return; m_undos.Append( new wxSourceUndoStep( wxSOURCE_UNDO_DELETE, m_cursorY, m_cursorY+1, this ) ); - + for (int i = 0; i < (m_cursorX-len); i++) tmp += ' '; - + tmp += m_lines[m_cursorY+1].m_text; - + m_lines[m_cursorY] = tmp; m_lines.RemoveAt( m_cursorY+1 ); - + MyAdjustScrollbars(); RefreshDown( m_cursorY ); } else { m_undos.Append( new wxSourceUndoStep( wxSOURCE_UNDO_LINE, m_cursorY, m_cursorY, this ) ); - + tmp.Remove( m_cursorX, 1 ); m_lines[m_cursorY].m_text = tmp; - + int y = m_cursorY*m_lineHeight; // int x = m_cursorX*m_charWidth; int x = PosToPixel( m_cursorY, m_cursorX ); CalcScrolledPosition( x, y, &x, &y ); wxRect rect( x+2, y+2, 10000, m_lineHeight ); - Refresh( TRUE, &rect ); + Refresh( true, &rect ); // refresh whole line for syntax colour highlighting rect.x = 0; - Refresh( FALSE, &rect ); + Refresh( false, &rect ); } } void wxTextCtrl::DoReturn() { - m_modified = TRUE; - + m_modified = true; + m_undos.Append( new wxSourceUndoStep( wxSOURCE_UNDO_ENTER, m_cursorY, m_cursorY, this ) ); - + wxString tmp( m_lines[m_cursorY].m_text ); size_t indent = tmp.find_first_not_of( ' ' ); if (indent == wxSTRING_MAXLEN) indent = 0; @@ -1445,11 +1307,11 @@ void wxTextCtrl::DoReturn() { int cursorX = indent; int cursorY = m_cursorY + 1; - + wxString new_tmp; for (size_t i = 0; i < indent; i++) new_tmp.Append( ' ' ); m_lines.Insert( new wxSourceLine( new_tmp ), cursorY ); - + MyAdjustScrollbars(); MoveCursor( cursorX, cursorY ); RefreshDown( m_cursorY ); @@ -1459,18 +1321,18 @@ void wxTextCtrl::DoReturn() wxString tmp1( tmp ); tmp1.Remove( m_cursorX, tmp.Len()-m_cursorX ); m_lines[m_cursorY].m_text = tmp1; - + wxString tmp2( tmp ); tmp2.Remove( 0, m_cursorX ); - + int cursorX = indent; int cursorY = m_cursorY + 1; - + wxString new_tmp; for (size_t i = 0; i < indent; i++) new_tmp.Append( ' ' ); new_tmp.Append( tmp2 ); m_lines.Insert( new wxSourceLine( new_tmp ), cursorY ); - + MyAdjustScrollbars(); MoveCursor( cursorX, cursorY ); RefreshDown( m_cursorY-1 ); @@ -1482,7 +1344,7 @@ void wxTextCtrl::DoDClick() wxString line( m_lines[ m_cursorY ].m_text ); if (m_cursorX >= (int)line.Len()) return; int p = m_cursorX; - char ch = line[p]; + char ch = line[(size_t) (p)]; if (((ch >= 'a') && (ch <= 'z')) || ((ch >= 'A') && (ch <= 'Z')) || ((ch >= '0') && (ch <= '9')) || @@ -1492,7 +1354,7 @@ void wxTextCtrl::DoDClick() m_selEndY = m_cursorY; if (p > 0) { - ch = line[p-1]; + ch = line[(size_t) (p-1)]; while (((ch >= 'a') && (ch <= 'z')) || ((ch >= 'A') && (ch <= 'Z')) || ((ch >= '0') && (ch <= '9')) || @@ -1500,15 +1362,15 @@ void wxTextCtrl::DoDClick() { p--; if (p == 0) break; - ch = line[p-1]; + ch = line[(size_t) (p-1)]; } } m_selStartX = p; - + p = m_cursorX; if (p < (int)line.Len()) { - ch = line[p]; + ch = line[(size_t) (p)]; while (((ch >= 'a') && (ch <= 'z')) || ((ch >= 'A') && (ch <= 'Z')) || ((ch >= '0') && (ch <= '9')) || @@ -1516,7 +1378,7 @@ void wxTextCtrl::DoDClick() { if (p >= (int)line.Len()) break; p++; - ch = line[p]; + ch = line[(size_t) (p)]; } } m_selEndX = p; @@ -1542,7 +1404,7 @@ wxString wxTextCtrl::GetNextToken( wxString &line, size_t &pos ) } else { - if ((line[p] == '/') && (p+1 < len) && (line[p+1] == '/')) + if ((line[p] == '/') && (p+1 < len) && (line[(size_t) (p+1)] == '/')) { for (size_t q = p; q < len; q++) ret.Append( line[q] ); @@ -1550,33 +1412,33 @@ wxString wxTextCtrl::GetNextToken( wxString &line, size_t &pos ) return ret; } } - + if (line[p] == '"') { ret.Append( line[p] ); for (size_t q = p+1; q < len; q++) { ret.Append( line[q] ); - if ((line[q] == '"') && ((line[q-1] != '\\') || (q >= 2 && line[q-2] == '\\'))) + if ((line[q] == '"') && ((line[(size_t) (q-1)] != '\\') || (q >= 2 && line[(size_t) (q-2)] == '\\'))) break; } pos = p; return ret; } - + if (line[p] == '\'') { ret.Append( line[p] ); for (size_t q = p+1; q < len; q++) { ret.Append( line[q] ); - if ((line[q] == '\'') && ((line[q-1] != '\\') || (q >= 2 && line[q-2] == '\\'))) + if ((line[q] == '\'') && ((line[(size_t) (q-1)] != '\\') || (q >= 2 && line[(size_t) (q-2)] == '\\'))) break; } pos = p; return ret; } - + if (((line[p] >= 'a') && (line[p] <= 'z')) || ((line[p] >= 'A') && (line[p] <= 'Z')) || (line[p] == '_') || @@ -1603,7 +1465,7 @@ wxString wxTextCtrl::GetNextToken( wxString &line, size_t &pos ) return ret; } } - + return ret; } @@ -1624,9 +1486,9 @@ void wxTextCtrl::DrawLinePart( wxDC &dc, int x, int y, const wxString &toDraw, c pos++; if (pos == len) return; } - + size_t start = pos; - + wxString current; current += toDraw[pos]; pos++; @@ -1635,7 +1497,7 @@ void wxTextCtrl::DrawLinePart( wxDC &dc, int x, int y, const wxString &toDraw, c current += toDraw[pos]; pos++; } - + int xx = 0; wxString tmp = origin.Left( start ); GetTextExtent( tmp, &xx, NULL, NULL, NULL ); @@ -1651,7 +1513,7 @@ void wxTextCtrl::DrawLine( wxDC &dc, int x, int y, const wxString &line2, int li int selEndY = m_selEndY; int selStartX = m_selStartX; int selEndX = m_selEndX; - + if ((selStartY > selEndY) || ((selStartY == selEndY) && (selStartX > selEndX))) { @@ -1676,7 +1538,7 @@ void wxTextCtrl::DrawLine( wxDC &dc, int x, int y, const wxString &line2, int li wxString comment( ' ', line.Len() ); wxString my_string( ' ', line.Len() ); wxString selection( ' ', line.Len() ); - + if (m_lang != wxSOURCE_LANG_NONE) { if (lineNum == m_bracketY) @@ -1684,17 +1546,17 @@ void wxTextCtrl::DrawLine( wxDC &dc, int x, int y, const wxString &line2, int li wxString red( ' ', line.Len() ); if (m_bracketX < (int)line.Len()) { - red.SetChar( m_bracketX, line[m_bracketX] ); + red.SetChar( m_bracketX, line[(size_t) (m_bracketX)] ); line.SetChar( m_bracketX, ' ' ); dc.SetTextForeground( *wxRED ); dc.DrawText( red, x, y ); dc.SetTextForeground( *wxBLACK ); } } - + size_t pos = 0; wxString token( GetNextToken( line, pos ) ); - while (!token.IsNull()) + while ( !token.empty() ) { if (m_keywords.Index( token ) != wxNOT_FOUND) { @@ -1715,7 +1577,7 @@ void wxTextCtrl::DrawLine( wxDC &dc, int x, int y, const wxString &line2, int li } } else if ((m_variables.Index( token ) != wxNOT_FOUND) || - ((token.Len() > 2) && (token[0] == 'w') && (token[1] == 'x'))) + ((token.Len() > 2) && (token[(size_t) (0)] == 'w') && (token[(size_t) (1)] == 'x'))) { size_t end_pos = pos + token.Len(); for (size_t i = pos; i < end_pos; i++) @@ -1724,7 +1586,7 @@ void wxTextCtrl::DrawLine( wxDC &dc, int x, int y, const wxString &line2, int li line[i] = ' '; } } else - if ((token.Len() >= 2) && (token[0] == '/') && (token[1] == '/') && (m_lang == wxSOURCE_LANG_CPP)) + if ((token.Len() >= 2) && (token[(size_t) (0)] == '/') && (token[(size_t) (1)] == '/') && (m_lang == wxSOURCE_LANG_CPP)) { size_t end_pos = pos + token.Len(); for (size_t i = pos; i < end_pos; i++) @@ -1733,7 +1595,7 @@ void wxTextCtrl::DrawLine( wxDC &dc, int x, int y, const wxString &line2, int li line[i] = ' '; } } else - if ((token[0] == '#') && + if ((token[(size_t) (0)] == '#') && ((m_lang == wxSOURCE_LANG_PYTHON) || (m_lang == wxSOURCE_LANG_PERL))) { size_t end_pos = pos + token.Len(); @@ -1743,7 +1605,7 @@ void wxTextCtrl::DrawLine( wxDC &dc, int x, int y, const wxString &line2, int li line[i] = ' '; } } else - if ((token[0] == '"') || (token[0] == '\'')) + if ((token[(size_t) (0)] == '"') || (token[(size_t) (0)] == '\'')) { size_t end_pos = pos + token.Len(); for (size_t i = pos; i < end_pos; i++) @@ -1768,7 +1630,7 @@ void wxTextCtrl::DrawLine( wxDC &dc, int x, int y, const wxString &line2, int li DrawLinePart( dc, x, y, my_string, line2, m_stringColour ); return; } - + if (selStartY == selEndY) { // int xx = selStartX*m_charWidth; @@ -1776,7 +1638,7 @@ void wxTextCtrl::DrawLine( wxDC &dc, int x, int y, const wxString &line2, int li // int ww = (selEndX-selStartX)*m_charWidth; int ww = PosToPixel( lineNum, selEndX ) - xx; dc.DrawRectangle( xx+2, lineNum*m_lineHeight+2, ww, m_lineHeight ); - + for (size_t i = (size_t)selStartX; i < (size_t)selEndX; i++) { selection[i] = line[i]; @@ -1786,7 +1648,7 @@ void wxTextCtrl::DrawLine( wxDC &dc, int x, int y, const wxString &line2, int li if ((lineNum > selStartY) && (lineNum < selEndY)) { dc.DrawRectangle( 0+2, lineNum*m_lineHeight+2, 10000, m_lineHeight ); - + for (size_t i = 0; i < line.Len(); i++) { selection[i] = line[i]; @@ -1798,7 +1660,7 @@ void wxTextCtrl::DrawLine( wxDC &dc, int x, int y, const wxString &line2, int li // int xx = selStartX*m_charWidth; int xx = PosToPixel( lineNum, selStartX ); dc.DrawRectangle( xx+2, lineNum*m_lineHeight+2, 10000, m_lineHeight ); - + for (size_t i = (size_t)selStartX; i < line.Len(); i++) { selection[i] = line[i]; @@ -1810,14 +1672,14 @@ void wxTextCtrl::DrawLine( wxDC &dc, int x, int y, const wxString &line2, int li // int ww = selEndX*m_charWidth; int ww = PosToPixel( lineNum, selEndX ); dc.DrawRectangle( 0+2, lineNum*m_lineHeight+2, ww, m_lineHeight ); - + for (size_t i = 0; i < (size_t)selEndX; i++) { selection[i] = line[i]; line[i] = ' '; } } - + DrawLinePart( dc, x, y, line, line2, *wxBLACK ); DrawLinePart( dc, x, y, selection, line2, *wxWHITE ); DrawLinePart( dc, x, y, keyword, line2, m_keywordColour ); @@ -1830,25 +1692,25 @@ void wxTextCtrl::DrawLine( wxDC &dc, int x, int y, const wxString &line2, int li void wxTextCtrl::OnPaint( wxPaintEvent &event ) { wxPaintDC dc(this); - + if (m_lines.GetCount() == 0) return; - + PrepareDC( dc ); - + dc.SetFont( m_sourceFont ); - + int scroll_y = 0; GetViewStart( NULL, &scroll_y ); - + // We have a inner border of two pixels // around the text, so scroll units do // not correspond to lines. if (scroll_y > 0) scroll_y--; - + int size_x = 0; int size_y = 0; GetClientSize( &size_x, &size_y ); - + dc.SetPen( *wxTRANSPARENT_PEN ); dc.SetBrush( wxBrush( wxTHEME_COLOUR(HIGHLIGHT), wxSOLID ) ); int upper = wxMin( (int)m_lines.GetCount(), scroll_y+(size_y/m_lineHeight)+2 ); @@ -1862,7 +1724,7 @@ void wxTextCtrl::OnPaint( wxPaintEvent &event ) if (IsExposed(x,y,w,h)) DrawLine( dc, 0+2, i*m_lineHeight+2, m_lines[i].m_text, i ); } - + if (m_editable && (FindFocus() == this)) { ///dc.SetBrush( *wxRED_BRUSH ); @@ -1877,34 +1739,34 @@ void wxTextCtrl::OnMouse( wxMouseEvent &event ) { if (m_lines.GetCount() == 0) return; - + #if 0 // there is no middle button on iPAQs if (event.MiddleDown()) { - Paste( TRUE ); + Paste( true ); return; } #endif - + if (event.LeftDClick()) { DoDClick(); return; } - + if (event.LeftDown()) - { - m_capturing = TRUE; + { + m_capturing = true; CaptureMouse(); } - + if (event.LeftUp()) - { - m_capturing = FALSE; + { + m_capturing = false; ReleaseMouse(); } - if (event.LeftDown() || + if (event.LeftDown() || (event.LeftIsDown() && m_capturing)) { int x = event.GetX(); @@ -1913,8 +1775,8 @@ void wxTextCtrl::OnMouse( wxMouseEvent &event ) y /= m_lineHeight; // x /= m_charWidth; x = PixelToPos( y, x ); - MoveCursor( - wxMin( 1000, wxMax( 0, x ) ), + MoveCursor( + wxMin( 1000, wxMax( 0, x ) ), wxMin( (int)m_lines.GetCount()-1, wxMax( 0, y ) ), event.ShiftDown() || !event.LeftDown() ); } @@ -1925,30 +1787,30 @@ void wxTextCtrl::OnChar( wxKeyEvent &event ) if (m_lines.GetCount() == 0) return; if (!m_editable) return; - + int size_x = 0; int size_y = 0; GetClientSize( &size_x, &size_y ); size_x /= m_charWidth; size_y /= m_lineHeight; size_y--; - + if (event.ShiftDown()) { switch (event.GetKeyCode()) { - case '4': event.m_keyCode = WXK_LEFT; break; - case '8': event.m_keyCode = WXK_UP; break; - case '6': event.m_keyCode = WXK_RIGHT; break; - case '2': event.m_keyCode = WXK_DOWN; break; - case '9': event.m_keyCode = WXK_PRIOR; break; - case '3': event.m_keyCode = WXK_NEXT; break; - case '7': event.m_keyCode = WXK_HOME; break; - case '1': event.m_keyCode = WXK_END; break; - case '0': event.m_keyCode = WXK_INSERT; break; + case '4': event.m_keyCode = WXK_LEFT; break; + case '8': event.m_keyCode = WXK_UP; break; + case '6': event.m_keyCode = WXK_RIGHT; break; + case '2': event.m_keyCode = WXK_DOWN; break; + case '9': event.m_keyCode = WXK_PAGEUP; break; + case '3': event.m_keyCode = WXK_PAGEDOWN; break; + case '7': event.m_keyCode = WXK_HOME; break; + case '1': event.m_keyCode = WXK_END; break; + case '0': event.m_keyCode = WXK_INSERT; break; } } - + switch (event.GetKeyCode()) { case WXK_UP: @@ -1956,7 +1818,7 @@ void wxTextCtrl::OnChar( wxKeyEvent &event ) if (m_ignoreInput) return; if (m_cursorY > 0) MoveCursor( m_cursorX, m_cursorY-1, event.ShiftDown() ); - m_ignoreInput = TRUE; + m_ignoreInput = true; return; } case WXK_DOWN: @@ -1964,7 +1826,7 @@ void wxTextCtrl::OnChar( wxKeyEvent &event ) if (m_ignoreInput) return; if (m_cursorY < (int)(m_lines.GetCount()-1)) MoveCursor( m_cursorX, m_cursorY+1, event.ShiftDown() ); - m_ignoreInput = TRUE; + m_ignoreInput = true; return; } case WXK_LEFT: @@ -1979,7 +1841,7 @@ void wxTextCtrl::OnChar( wxKeyEvent &event ) if (m_cursorY > 0) MoveCursor( m_lines[m_cursorY-1].m_text.Len(), m_cursorY-1, event.ShiftDown() ); } - m_ignoreInput = TRUE; + m_ignoreInput = true; return; } case WXK_RIGHT: @@ -1987,7 +1849,7 @@ void wxTextCtrl::OnChar( wxKeyEvent &event ) if (m_ignoreInput) return; if (m_cursorX < 1000) MoveCursor( m_cursorX+1, m_cursorY, event.ShiftDown() ); - m_ignoreInput = TRUE; + m_ignoreInput = true; return; } case WXK_HOME: @@ -2010,14 +1872,14 @@ void wxTextCtrl::OnChar( wxKeyEvent &event ) { if (m_ignoreInput) return; MoveCursor( m_cursorX, wxMin( (int)(m_lines.GetCount()-1), m_cursorY+size_y ), event.ShiftDown() ); - m_ignoreInput = TRUE; + m_ignoreInput = true; return; } - case WXK_PRIOR: + case WXK_PAGEUP: { if (m_ignoreInput) return; MoveCursor( m_cursorX, wxMax( 0, m_cursorY-size_y ), event.ShiftDown() ); - m_ignoreInput = TRUE; + m_ignoreInput = true; return; } case WXK_INSERT: @@ -2032,20 +1894,20 @@ void wxTextCtrl::OnChar( wxKeyEvent &event ) } case WXK_RETURN: { - if (m_windowStyle & wxPROCESS_ENTER) + if (m_windowStyle & wxTE_PROCESS_ENTER) { wxCommandEvent event(wxEVT_COMMAND_TEXT_ENTER, m_windowId); event.SetEventObject(this); event.SetString(GetValue()); - if (GetEventHandler()->ProcessEvent(event)) return; + if (HandleWindowEvent(event)) return; } - + if (IsSingleLine()) { event.Skip(); return; } - + if (HasSelection()) Delete(); DoReturn(); @@ -2056,7 +1918,7 @@ void wxTextCtrl::OnChar( wxKeyEvent &event ) if (HasSelection()) Delete(); bool save_overwrite = m_overwrite; - m_overwrite = FALSE; + m_overwrite = false; int i = 4-(m_cursorX % 4); if (i == 0) i = 4; for (int c = 0; c < i; c++) @@ -2080,40 +1942,40 @@ void wxTextCtrl::OnChar( wxKeyEvent &event ) DoDelete(); return; } - default: + default: { - if ( (event.KeyCode() >= 'a') && - (event.KeyCode() <= 'z') && + if ( (event.GetKeyCode() >= 'a') && + (event.GetKeyCode() <= 'z') && (event.AltDown()) ) { // Alt-F etc. event.Skip(); return; } - - if ( (event.KeyCode() >= 32) && - (event.KeyCode() <= 255) && + + if ( (event.GetKeyCode() >= 32) && + (event.GetKeyCode() <= 255) && !(event.ControlDown() && !event.AltDown()) ) // filters out Ctrl-X but leaves Alt-Gr { if (HasSelection()) Delete(); - DoChar( (char) event.KeyCode() ); + DoChar( (char) event.GetKeyCode() ); return; } } } - + event.Skip(); } -void wxTextCtrl::OnIdle( wxIdleEvent &event ) +void wxTextCtrl::OnInternalIdle() { - m_ignoreInput = FALSE; - + wxControl::OnInternalIdle(); + + m_ignoreInput = false; + if (m_lang != wxSOURCE_LANG_NONE) SearchForBrackets(); - - event.Skip( TRUE ); } void wxTextCtrl::Indent() @@ -2131,12 +1993,12 @@ void wxTextCtrl::Indent() endY = tmp; } } - + m_undos.Append( new wxSourceUndoStep( wxSOURCE_UNDO_LINE, startY, endY, this ) ); - + for (int i = startY; i <= endY; i++) { - m_lines[i].m_text.insert( 0u, " " ); + m_lines[i].m_text.insert( 0u, wxT(" ") ); RefreshLine( i ); } } @@ -2156,14 +2018,14 @@ void wxTextCtrl::Unindent() endY = tmp; } } - + m_undos.Append( new wxSourceUndoStep( wxSOURCE_UNDO_LINE, startY, endY, this ) ); - + for (int i = startY; i <= endY; i++) { for (int n = 0; n < 4; n++) { - if (m_lines[i].m_text[0u] == ' ') + if (m_lines[i].m_text[0u] == wxT(' ')) m_lines[i].m_text.erase(0u,1u); } RefreshLine( i ); @@ -2188,7 +2050,7 @@ void wxTextCtrl::RefreshLine( int n ) int x = 0; CalcScrolledPosition( x, y, &x, &y ); wxRect rect( 0+2, y+2, 10000, m_lineHeight ); - Refresh( TRUE, &rect ); + Refresh( true, &rect ); } void wxTextCtrl::RefreshDown( int n ) @@ -2210,9 +2072,9 @@ void wxTextCtrl::RefreshDown( int n ) int y = n*m_lineHeight; int x = 0; CalcScrolledPosition( x, y, &x, &y ); - + wxRect rect( 0+2, y+2, 10000, size_y ); - Refresh( TRUE, &rect ); + Refresh( true, &rect ); } } @@ -2222,24 +2084,25 @@ void wxTextCtrl::MoveCursor( int new_x, int new_y, bool shift, bool centre ) // if (IsSingleLine() || (m_lang == wxSOURCE_LANG_NONE)) { - if (new_x > m_lines[new_y].m_text.Len()) + if (new_x > (int) (m_lines[new_y].m_text.Len())) new_x = m_lines[new_y].m_text.Len(); } if ((new_x == m_cursorX) && (new_y == m_cursorY)) return; - bool no_cursor_refresh = FALSE; + bool no_cursor_refresh = false; bool has_selection = HasSelection(); if (shift) { int x,y,w,h; - + bool erase_background = true; + if (!has_selection) { m_selStartX = m_cursorX; m_selStartY = m_cursorY; - + x = 0; w = 10000; if (new_y > m_selStartY) @@ -2264,8 +2127,8 @@ void wxTextCtrl::MoveCursor( int new_x, int new_y, bool shift, bool centre ) y = new_y*m_lineHeight; h = (-new_y+m_selStartY+1)*m_lineHeight; } - - no_cursor_refresh = TRUE; + + no_cursor_refresh = true; m_cursorX = new_x; m_cursorY = new_y; } @@ -2298,24 +2161,30 @@ void wxTextCtrl::MoveCursor( int new_x, int new_y, bool shift, bool centre ) { y = m_selEndY*m_lineHeight; h = (new_y-m_selEndY+1) * m_lineHeight; + + erase_background = ((m_selEndY < m_selStartY) || + ((m_selEndY == m_selStartY) && (m_selEndX < m_selStartX))); } else { y = new_y*m_lineHeight; h = (-new_y+m_selEndY+1) * m_lineHeight; + + erase_background = ((m_selEndY > m_selStartY) || + ((m_selEndY == m_selStartY) && (m_selEndX > m_selStartX))); } - no_cursor_refresh = TRUE; + no_cursor_refresh = true; m_cursorX = new_x; m_cursorY = new_y; } } - + m_selEndX = new_x; m_selEndY = new_y; - + CalcScrolledPosition( x, y, &x, &y ); wxRect rect( x+2, y+2, w, h ); - Refresh( TRUE, &rect ); + Refresh( erase_background, &rect ); } else { @@ -2327,27 +2196,27 @@ void wxTextCtrl::MoveCursor( int new_x, int new_y, bool shift, bool centre ) m_selEndY = -1; m_selStartX = -1; m_selStartY = -1; - + if (ry1 > ry2) { int tmp = ry2; ry2 = ry1; ry1 = tmp; } - + int x = 0; int y = ry1*m_lineHeight; CalcScrolledPosition( x, y, &x, &y ); wxRect rect( 0, y+2, 10000, (ry2-ry1+1)*m_lineHeight ); - - Refresh( TRUE, &rect ); + + Refresh( true, &rect ); } } - + /* - printf( "startx %d starty %d endx %d endy %d\n", + printf( "startx %d starty %d endx %d endy %d\n", m_selStartX, m_selStartY, m_selEndX, m_selEndY ); - + printf( "has %d\n", (int)HasSelection() ); */ @@ -2358,11 +2227,11 @@ void wxTextCtrl::MoveCursor( int new_x, int new_y, bool shift, bool centre ) int y = m_cursorY*m_lineHeight; CalcScrolledPosition( x, y, &x, &y ); wxRect rect( x+2, y+2, 4, m_lineHeight+2 ); - + m_cursorX = new_x; m_cursorY = new_y; - - Refresh( TRUE, &rect ); + + Refresh( true, &rect ); if (FindFocus() == this) { @@ -2376,17 +2245,17 @@ void wxTextCtrl::MoveCursor( int new_x, int new_y, bool shift, bool centre ) dc.DrawRectangle( xx+2, m_cursorY*m_lineHeight+2, 2, m_lineHeight ); } } - + int size_x = 0; int size_y = 0; GetClientSize( &size_x, &size_y ); size_x /= m_charWidth; size_y /= m_lineHeight; - + int view_x = 0; int view_y = 0; GetViewStart( &view_x, &view_y ); - + if (centre) { int sy = m_cursorY - (size_y/2); @@ -2400,10 +2269,10 @@ void wxTextCtrl::MoveCursor( int new_x, int new_y, bool shift, bool centre ) else if (m_cursorY > view_y+size_y-1) Scroll( -1, m_cursorY-size_y+1 ); } - + //int xx = m_cursorX; int xx = PosToPixel( m_cursorY, m_cursorX ) / m_charWidth; - + if (xx < view_x) Scroll( xx, -1 ); else if (xx > view_x+size_x-1) @@ -2420,13 +2289,13 @@ void wxTextCtrl::MyAdjustScrollbars() int height = 0; GetClientSize( NULL, &height ); height -= 4; - if (height >= m_lines.GetCount() *m_lineHeight) + if (height >= (int)m_lines.GetCount() *m_lineHeight) y_range = 0; - + int view_x = 0; int view_y = 0; GetViewStart( &view_x, &view_y ); - + SetScrollbars( m_charWidth, m_lineHeight, m_longestLine+2, y_range, view_x, view_y ); } @@ -2489,13 +2358,13 @@ wxSize wxTextCtrl::DoGetBestSize() const if (IsSingleLine()) { wxSize ret(80, m_lineHeight + 4); - + if (HasFlag(wxBORDER_SUNKEN) || HasFlag(wxBORDER_RAISED)) ret.y += 4; - + if (HasFlag(wxBORDER_SIMPLE)) ret.y += 2; - + return ret; } else @@ -2504,18 +2373,6 @@ wxSize wxTextCtrl::DoGetBestSize() const } } -// ---------------------------------------------------------------------------- -// freeze/thaw -// ---------------------------------------------------------------------------- - -void wxTextCtrl::Freeze() -{ -} - -void wxTextCtrl::Thaw() -{ -} - void wxTextCtrl::OnSetFocus( wxFocusEvent& event ) { // To hide or show caret, as appropriate @@ -2536,13 +2393,12 @@ bool wxTextCtrl::ScrollLines(int lines) { wxFAIL_MSG( "wxTextCtrl::ScrollLines not implemented"); - return FALSE; + return false; } bool wxTextCtrl::ScrollPages(int pages) { wxFAIL_MSG( "wxTextCtrl::ScrollPages not implemented"); - - return FALSE; -} + return false; +}