X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/a336f999c2c432b1fc6c6324a70bdaab02c0886e..718970e5906a1fe0f84cc6ea9418cd79377767cd:/src/x11/textctrl.cpp?ds=sidebyside diff --git a/src/x11/textctrl.cpp b/src/x11/textctrl.cpp index cb596659a8..3b778c72a9 100644 --- a/src/x11/textctrl.cpp +++ b/src/x11/textctrl.cpp @@ -7,11 +7,12 @@ // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// -#ifdef __GNUG__ +#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) #pragma implementation "textctrl.h" #endif #include "wx/textctrl.h" + #include "wx/utils.h" #include "wx/intl.h" #include "wx/log.h" @@ -19,6 +20,7 @@ #include "wx/panel.h" #include "wx/clipbrd.h" #include "wx/tokenzr.h" +#include "wx/dcclient.h" #include "wx/univ/inphand.h" #include "wx/univ/renderer.h" @@ -52,7 +54,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( wxT("") ); else m_lines.Add( m_owner->m_lines[i].m_text ); } @@ -134,7 +136,6 @@ BEGIN_EVENT_TABLE(wxTextCtrl, wxControl) 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) @@ -156,8 +157,6 @@ void wxTextCtrl::Init() m_editable = TRUE; m_modified = FALSE; - m_undos.DeleteContents( TRUE ); - m_lang = wxSOURCE_LANG_NONE; m_capturing = FALSE; @@ -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, @@ -217,7 +221,7 @@ bool wxTextCtrl::Create( wxWindow *parent, style |= wxALWAYS_SHOW_SB; wxTextCtrlBase::Create( parent, id, pos /* wxDefaultPosition */, size, - style|wxVSCROLL|wxHSCROLL|wxNO_FULL_REPAINT_ON_RESIZE ); + style | wxVSCROLL | wxHSCROLL); SetBackgroundColour( *wxWHITE ); @@ -397,7 +401,7 @@ void wxTextCtrl::Clear() 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) @@ -469,184 +473,6 @@ 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" ); - } } void wxTextCtrl::WriteText(const wxString& text2) @@ -862,12 +688,12 @@ void wxTextCtrl::Copy() { 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()) @@ -972,12 +798,13 @@ 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; + + delete undo; + m_undos.Erase( node ); m_modified = TRUE; } @@ -1071,7 +898,7 @@ void wxTextCtrl::SearchForBrackets() char bracket = ' '; if (m_cursorX > 0) - bracket = current[(size_t) m_cursorX-1]; + bracket = current[(size_t) (m_cursorX-1)]; if (bracket == ')' || bracket == ']' || bracket == '}') { @@ -1092,13 +919,13 @@ void wxTextCtrl::SearchForBrackets() 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; @@ -1107,13 +934,13 @@ void wxTextCtrl::SearchForBrackets() } // 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; @@ -1121,7 +948,7 @@ void wxTextCtrl::SearchForBrackets() continue; } - if (current[n] == antibracket) + if (current[(size_t) (n)] == antibracket) { count--; if (count == 0) @@ -1135,7 +962,7 @@ void wxTextCtrl::SearchForBrackets() return; } } - else if (current[n] == bracket) + else if (current[(size_t) (n)] == bracket) { count++; } @@ -1147,7 +974,7 @@ void wxTextCtrl::SearchForBrackets() bracket = ' '; if ((int)current.Len() > m_cursorX) - bracket = current[m_cursorX]; + bracket = current[(size_t) (m_cursorX)]; if (bracket == '(' || bracket == '[' || bracket == '{') { char antibracket = ')'; @@ -1168,13 +995,13 @@ void wxTextCtrl::SearchForBrackets() 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; @@ -1183,13 +1010,13 @@ void wxTextCtrl::SearchForBrackets() } // 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; @@ -1197,7 +1024,7 @@ void wxTextCtrl::SearchForBrackets() continue; } - if (current[n] == antibracket) + if (current[(size_t) (n)] == antibracket) { count--; if (count == 0) @@ -1211,7 +1038,7 @@ void wxTextCtrl::SearchForBrackets() return; } } - else if (current[n] == bracket) + else if (current[(size_t) (n)] == bracket) { count++; } @@ -1515,7 +1342,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')) || @@ -1525,7 +1352,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')) || @@ -1533,7 +1360,7 @@ void wxTextCtrl::DoDClick() { p--; if (p == 0) break; - ch = line[p-1]; + ch = line[(size_t) (p-1)]; } } m_selStartX = p; @@ -1541,7 +1368,7 @@ void wxTextCtrl::DoDClick() 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')) || @@ -1549,7 +1376,7 @@ void wxTextCtrl::DoDClick() { if (p >= (int)line.Len()) break; p++; - ch = line[p]; + ch = line[(size_t) (p)]; } } m_selEndX = p; @@ -1575,7 +1402,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] ); @@ -1590,7 +1417,7 @@ wxString wxTextCtrl::GetNextToken( wxString &line, size_t &pos ) 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; @@ -1603,7 +1430,7 @@ wxString wxTextCtrl::GetNextToken( wxString &line, size_t &pos ) 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; @@ -1717,7 +1544,7 @@ 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 ); @@ -1748,7 +1575,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++) @@ -1757,7 +1584,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++) @@ -1766,7 +1593,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(); @@ -1776,7 +1603,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++) @@ -2115,8 +1942,8 @@ void wxTextCtrl::OnChar( wxKeyEvent &event ) } default: { - if ( (event.KeyCode() >= 'a') && - (event.KeyCode() <= 'z') && + if ( (event.GetKeyCode() >= 'a') && + (event.GetKeyCode() <= 'z') && (event.AltDown()) ) { // Alt-F etc. @@ -2124,13 +1951,13 @@ void wxTextCtrl::OnChar( wxKeyEvent &event ) 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; } } @@ -2139,14 +1966,14 @@ void wxTextCtrl::OnChar( wxKeyEvent &event ) event.Skip(); } -void wxTextCtrl::OnIdle( wxIdleEvent &event ) +void wxTextCtrl::OnInternalIdle() { + wxControl::OnInternalIdle(); + m_ignoreInput = FALSE; if (m_lang != wxSOURCE_LANG_NONE) SearchForBrackets(); - - event.Skip( TRUE ); } void wxTextCtrl::Indent() @@ -2169,7 +1996,7 @@ void wxTextCtrl::Indent() for (int i = startY; i <= endY; i++) { - m_lines[i].m_text.insert( 0u, " " ); + m_lines[i].m_text.insert( 0u, wxT(" ") ); RefreshLine( i ); } } @@ -2196,7 +2023,7 @@ void wxTextCtrl::Unindent() { 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 );