public override string HandleEvent(SystemEvent e, ref bool updateVisuals)
{
idConsole.Warning("TODO: EditWindow HandleEvent");
/* TODO: static char buffer[ MAX_EDITFIELD ];
const char *ret = "";
if ( wrap ) {
// need to call this to allow proper focus and capturing on embedded children
ret = idWindow::HandleEvent( event, updateVisuals );
if ( ret && *ret ) {
return ret;
}
}
if ( ( event->evType != SE_CHAR && event->evType != SE_KEY ) ) {
return ret;
}
idStr::Copynz( buffer, text.c_str(), sizeof( buffer ) );
int key = event->evValue;
int len = text.Length();
if ( event->evType == SE_CHAR ) {
if ( event->evValue == Sys_GetConsoleKey( false ) || event->evValue == Sys_GetConsoleKey( true ) ) {
return "";
}
if ( updateVisuals ) {
*updateVisuals = true;
}
if ( maxChars && len > maxChars ) {
len = maxChars;
}
if ( ( key == K_ENTER || key == K_KP_ENTER ) && event->evValue2 ) {
RunScript( ON_ACTION );
RunScript( ON_ENTER );
return cmd;
}
if ( key == K_ESCAPE ) {
RunScript( ON_ESC );
return cmd;
}
if ( readonly ) {
return "";
}
if ( key == 'h' - 'a' + 1 || key == K_BACKSPACE ) { // ctrl-h is backspace
if ( cursorPos > 0 ) {
if ( cursorPos >= len ) {
buffer[len - 1] = 0;
cursorPos = len - 1;
} else {
memmove( &buffer[ cursorPos - 1 ], &buffer[ cursorPos ], len + 1 - cursorPos);
cursorPos--;
}
text = buffer;
UpdateCvar( false );
RunScript( ON_ACTION );
}
return "";
}
//
// ignore any non printable chars (except enter when wrap is enabled)
//
if ( wrap && (key == K_ENTER || key == K_KP_ENTER) ) {
} else if ( !idStr::CharIsPrintable( key ) ) {
return "";
}
if ( numeric ) {
if ( ( key < '0' || key > '9' ) && key != '.' ) {
return "";
}
}
if ( dc->GetOverStrike() ) {
if ( maxChars && cursorPos >= maxChars ) {
return "";
}
} else {
if ( ( len == MAX_EDITFIELD - 1 ) || ( maxChars && len >= maxChars ) ) {
return "";
}
memmove( &buffer[ cursorPos + 1 ], &buffer[ cursorPos ], len + 1 - cursorPos );
}
buffer[ cursorPos ] = key;
text = buffer;
UpdateCvar( false );
RunScript( ON_ACTION );
if ( cursorPos < len + 1 ) {
cursorPos++;
}
EnsureCursorVisible();
} else if ( event->evType == SE_KEY && event->evValue2 ) {
if ( updateVisuals ) {
*updateVisuals = true;
}
if ( key == K_DEL ) {
if ( readonly ) {
return ret;
}
if ( cursorPos < len ) {
memmove( &buffer[cursorPos], &buffer[cursorPos + 1], len - cursorPos);
text = buffer;
UpdateCvar( false );
RunScript( ON_ACTION );
}
return ret;
}
if ( key == K_RIGHTARROW ) {
if ( cursorPos < len ) {
if ( idKeyInput::IsDown( K_CTRL ) ) {
// skip to next word
while( ( cursorPos < len ) && ( buffer[ cursorPos ] != ' ' ) ) {
cursorPos++;
}
while( ( cursorPos < len ) && ( buffer[ cursorPos ] == ' ' ) ) {
cursorPos++;
}
} else {
if ( cursorPos < len ) {
cursorPos++;
}
}
}
EnsureCursorVisible();
return ret;
}
if ( key == K_LEFTARROW ) {
if ( idKeyInput::IsDown( K_CTRL ) ) {
// skip to previous word
while( ( cursorPos > 0 ) && ( buffer[ cursorPos - 1 ] == ' ' ) ) {
cursorPos--;
}
while( ( cursorPos > 0 ) && ( buffer[ cursorPos - 1 ] != ' ' ) ) {
cursorPos--;
}
} else {
if ( cursorPos > 0 ) {
cursorPos--;
}
}
EnsureCursorVisible();
return ret;
}
if ( key == K_HOME ) {
if ( idKeyInput::IsDown( K_CTRL ) || cursorLine <= 0 || ( cursorLine >= breaks.Num() ) ) {
cursorPos = 0;
} else {
cursorPos = breaks[cursorLine];
}
EnsureCursorVisible();
return ret;
}
if ( key == K_END ) {
if ( idKeyInput::IsDown( K_CTRL ) || (cursorLine < -1) || ( cursorLine >= breaks.Num() - 1 ) ) {
cursorPos = len;
} else {
cursorPos = breaks[cursorLine + 1] - 1;
}
EnsureCursorVisible();
return ret;
}
if ( key == K_INS ) {
if ( !readonly ) {
dc->SetOverStrike( !dc->GetOverStrike() );
}
return ret;
}
if ( key == K_DOWNARROW ) {
if ( idKeyInput::IsDown( K_CTRL ) ) {
scroller->SetValue( scroller->GetValue() + 1.0f );
} else {
if ( cursorLine < breaks.Num() - 1 ) {
int offset = cursorPos - breaks[cursorLine];
cursorPos = breaks[cursorLine + 1] + offset;
EnsureCursorVisible();
}
}
}
if (key == K_UPARROW ) {
if ( idKeyInput::IsDown( K_CTRL ) ) {
scroller->SetValue( scroller->GetValue() - 1.0f );
} else {
if ( cursorLine > 0 ) {
int offset = cursorPos - breaks[cursorLine];
cursorPos = breaks[cursorLine - 1] + offset;
EnsureCursorVisible();
}
}
}
if ( key == K_ENTER || key == K_KP_ENTER ) {
RunScript( ON_ACTION );
RunScript( ON_ENTER );
return cmd;
}
if ( key == K_ESCAPE ) {
RunScript( ON_ESC );
return cmd;
}
} else if ( event->evType == SE_KEY && !event->evValue2 ) {
if ( key == K_ENTER || key == K_KP_ENTER ) {
RunScript( ON_ENTERRELEASE );
return cmd;
} else {
RunScript( ON_ACTIONRELEASE );
}
}
return ret;*/
return string.Empty;
}