// 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"
#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"
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 );
}
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)
m_editable = TRUE;
m_modified = FALSE;
- m_undos.DeleteContents( TRUE );
-
m_lang = wxSOURCE_LANG_NONE;
m_capturing = FALSE;
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,
style |= wxALWAYS_SHOW_SB;
wxTextCtrlBase::Create( parent, id, pos /* wxDefaultPosition */, size,
- style|wxVSCROLL|wxHSCROLL|wxNO_FULL_REPAINT_ON_RESIZE );
+ style | wxVSCROLL | wxHSCROLL);
SetBackgroundColour( *wxWHITE );
{
m_modified = FALSE;
- if ((GetWindowStyle() & wxTE_MULTILINE) == 0)
- {
- if (value == GetValue())
- return;
- }
-
+ wxString oldValue = GetValue();
+
m_cursorX = 0;
m_cursorY = 0;
ClearSelection();
}
}
}
+
+ // Don't need to refresh if the value hasn't changed
+ if ((GetWindowStyle() & wxTE_MULTILINE) == 0)
+ {
+ if (value == oldValue)
+ return;
+ }
MyAdjustScrollbars();
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()
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)
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)
{
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;
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;
}
+ 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;
{
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())
{
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;
}
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
long 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)
char bracket = ' ';
if (m_cursorX > 0)
- bracket = current[m_cursorX-1];
+ bracket = current[(size_t) (m_cursorX-1)];
if (bracket == ')' || bracket == ']' || bracket == '}')
{
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;
}
// 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)
return;
}
}
- else if (current[n] == bracket)
+ else if (current[(size_t) (n)] == bracket)
{
count++;
}
bracket = ' ';
if ((int)current.Len() > m_cursorX)
- bracket = current[m_cursorX];
+ bracket = current[(size_t) (m_cursorX)];
if (bracket == '(' || bracket == '[' || bracket == '{')
{
char antibracket = ')';
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;
}
// 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)
return;
}
}
- else if (current[n] == bracket)
+ else if (current[(size_t) (n)] == bracket)
{
count++;
}
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')) ||
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')) ||
{
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')) ||
{
if (p >= (int)line.Len()) break;
p++;
- ch = line[p];
+ ch = line[(size_t) (p)];
}
}
m_selEndX = p;
}
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] );
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;
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;
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 );
}
} 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++)
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++)
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();
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++)
}
default:
{
- if ( (event.KeyCode() >= 'a') &&
- (event.KeyCode() <= 'z') &&
+ if ( (event.GetKeyCode() >= 'a') &&
+ (event.GetKeyCode() <= 'z') &&
(event.AltDown()) )
{
// Alt-F etc.
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()
{
+ wxControl::OnInternalIdle();
+
m_ignoreInput = FALSE;
if (m_lang != wxSOURCE_LANG_NONE)
SearchForBrackets();
-
- event.Skip( TRUE );
}
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 );
}
}
{
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 );
// 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();
}
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;