Remove character limit in CEdit (#836)

dev-new-models
MatiRg 2016-09-25 19:13:04 +02:00 committed by krzys_h
parent 89bf0da30c
commit dc415c3d2a
9 changed files with 180 additions and 222 deletions

View File

@ -780,10 +780,10 @@ bool CRobotMain::ProcessEvent(Event &event)
if (event.type == EVENT_KEY_DOWN && if (event.type == EVENT_KEY_DOWN &&
event.GetData<KeyEventData>()->key == KEY(RETURN) && m_cmdEdit) event.GetData<KeyEventData>()->key == KEY(RETURN) && m_cmdEdit)
{ {
char cmd[50]; std::string cmd;
Ui::CEdit* pe = static_cast<Ui::CEdit*>(m_interface->SearchControl(EVENT_CMD)); Ui::CEdit* pe = static_cast<Ui::CEdit*>(m_interface->SearchControl(EVENT_CMD));
if (pe == nullptr) return false; if (pe == nullptr) return false;
pe->GetText(cmd, 50); cmd = pe->GetText(50);
pe->SetText(""); pe->SetText("");
pe->ClearState(Ui::STATE_VISIBLE); pe->ClearState(Ui::STATE_VISIBLE);
m_interface->SetFocus(nullptr); m_interface->SetFocus(nullptr);

View File

@ -131,7 +131,6 @@ Program* CProgramStorageObjectImpl::CloneProgram(Program* program)
// TODO: Is there any reason CScript doesn't have a function to get the program code directly? // TODO: Is there any reason CScript doesn't have a function to get the program code directly?
auto edit = MakeUnique<Ui::CEdit>(); auto edit = MakeUnique<Ui::CEdit>();
edit->SetMaxChar(Ui::EDITSTUDIOMAX);
program->script->PutScript(edit.get(), ""); program->script->PutScript(edit.get(), "");
newprog->script->GetScript(edit.get()); newprog->script->GetScript(edit.get());

View File

@ -105,9 +105,11 @@ void CScript::PutScript(Ui::CEdit* edit, const char* name)
bool CScript::GetScript(Ui::CEdit* edit) bool CScript::GetScript(Ui::CEdit* edit)
{ {
int len = edit->GetTextLength(); int len = edit->GetTextLength();
m_script = MakeUniqueArray<char>(len+1); m_script = MakeUniqueArray<char>(len+2);
std::string tmp = edit->GetText(len+1);
strncpy(m_script.get(), tmp.c_str(), len+1);
edit->GetText(m_script.get(), len+1);
edit->GetCursor(m_cursor2, m_cursor1); edit->GetCursor(m_cursor2, m_cursor1);
m_len = strlen(m_script.get()); m_len = strlen(m_script.get());
@ -592,13 +594,13 @@ void CScript::UpdateList(Ui::CList* list)
void CScript::ColorizeScript(Ui::CEdit* edit, int rangeStart, int rangeEnd) void CScript::ColorizeScript(Ui::CEdit* edit, int rangeStart, int rangeEnd)
{ {
if (rangeEnd > edit->GetMaxChar()) if (rangeEnd > edit->GetTextLength())
rangeEnd = edit->GetMaxChar(); rangeEnd = edit->GetTextLength();
edit->SetFormat(rangeStart, rangeEnd, Gfx::FONT_HIGHLIGHT_COMMENT); // anything not processed is a comment edit->SetFormat(rangeStart, rangeEnd, Gfx::FONT_HIGHLIGHT_COMMENT); // anything not processed is a comment
// NOTE: Images are registered as index in some array, and that can be 0 which normally ends the string! // NOTE: Images are registered as index in some array, and that can be 0 which normally ends the string!
std::string text = std::string(edit->GetText(), edit->GetMaxChar()); std::string text = edit->GetText();
text = text.substr(rangeStart, rangeEnd-rangeStart); text = text.substr(rangeStart, rangeEnd-rangeStart);
auto tokens = CBot::CBotToken::CompileTokens(text.c_str()); auto tokens = CBot::CBotToken::CompileTokens(text.c_str());
@ -927,7 +929,6 @@ bool CScript::SendScript(const char* text)
if ( !Compile() ) return false;*/ if ( !Compile() ) return false;*/
Ui::CEdit* edit = m_interface->CreateEdit(Math::Point(0.0f, 0.0f), Math::Point(0.0f, 0.0f), 0, EVENT_EDIT9); Ui::CEdit* edit = m_interface->CreateEdit(Math::Point(0.0f, 0.0f), Math::Point(0.0f, 0.0f), 0, EVENT_EDIT9);
edit->SetMaxChar(Ui::EDITSTUDIOMAX);
edit->SetAutoIndent(m_engine->GetEditIndentMode()); edit->SetAutoIndent(m_engine->GetEditIndentMode());
edit->SetText(text, true); edit->SetText(text, true);
GetScript(edit); GetScript(edit);
@ -947,7 +948,6 @@ bool CScript::ReadScript(const char* filename)
m_script.reset(); m_script.reset();
edit = m_interface->CreateEdit(Math::Point(0.0f, 0.0f), Math::Point(0.0f, 0.0f), 0, EVENT_EDIT9); edit = m_interface->CreateEdit(Math::Point(0.0f, 0.0f), Math::Point(0.0f, 0.0f), 0, EVENT_EDIT9);
edit->SetMaxChar(Ui::EDITSTUDIOMAX);
edit->SetAutoIndent(m_engine->GetEditIndentMode()); edit->SetAutoIndent(m_engine->GetEditIndentMode());
edit->ReadText(filename); edit->ReadText(filename);
GetScript(edit); GetScript(edit);
@ -966,7 +966,6 @@ bool CScript::WriteScript(const char* filename)
} }
Ui::CEdit* edit = m_interface->CreateEdit(Math::Point(0.0f, 0.0f), Math::Point(0.0f, 0.0f), 0, EVENT_EDIT9); Ui::CEdit* edit = m_interface->CreateEdit(Math::Point(0.0f, 0.0f), Math::Point(0.0f, 0.0f), 0, EVENT_EDIT9);
edit->SetMaxChar(Ui::EDITSTUDIOMAX);
edit->SetAutoIndent(m_engine->GetEditIndentMode()); edit->SetAutoIndent(m_engine->GetEditIndentMode());
edit->SetText(m_script.get()); edit->SetText(m_script.get());
edit->WriteText(filename); edit->WriteText(filename);

View File

@ -60,7 +60,6 @@ const float BIG_FONT = 1.6f;
//! Indicates whether a character is a space. //! Indicates whether a character is a space.
bool IsSpace(int character) bool IsSpace(int character)
@ -90,11 +89,11 @@ bool IsSep(int character)
//! Object's constructor. //! Object's constructor.
CEdit::CEdit() CEdit::CEdit()
: CControl(), : CControl(),
m_maxChar( std::numeric_limits<int>::max() ),
m_text(),
m_lineOffset(), m_lineOffset(),
m_lineIndent() m_lineIndent()
{ {
m_maxChar = 100;
m_text = std::vector<char>(m_maxChar+1, '\0');
m_len = 0; m_len = 0;
m_fontType = Gfx::FONT_COURIER; m_fontType = Gfx::FONT_COURIER;
@ -558,7 +557,7 @@ bool CEdit::IsLinkPos(Math::Point pos)
{ {
int i; int i;
if ( m_format.size() == 0 ) return false; if ( m_format.empty() ) return false;
i = MouseDetect(pos); i = MouseDetect(pos);
if ( i == -1 ) return false; if ( i == -1 ) return false;
@ -721,7 +720,7 @@ int CEdit::MouseDetect(Math::Point mouse)
{ {
len = m_lineOffset[i+1] - m_lineOffset[i]; len = m_lineOffset[i+1] - m_lineOffset[i];
if ( m_format.size() == 0 ) if ( m_format.empty() )
{ {
// c = m_engine->GetText()->Detect(m_text.data()+m_lineOffset[i], // c = m_engine->GetText()->Detect(m_text.data()+m_lineOffset[i],
// len, offset, m_fontSize, // len, offset, m_fontSize,
@ -1018,7 +1017,7 @@ void CEdit::Draw()
o1 = c1; if ( o1 < beg ) o1 = beg; o1 = c1; if ( o1 < beg ) o1 = beg;
o2 = c2; if ( o2 > beg+len ) o2 = beg+len; o2 = c2; if ( o2 > beg+len ) o2 = beg+len;
if ( m_format.size() == 0 ) if ( m_format.empty() )
{ {
start.x = ppos.x+m_engine->GetText()->GetStringWidth(std::string(m_text.data()+beg).substr(0, o1-beg), m_fontType, size); start.x = ppos.x+m_engine->GetText()->GetStringWidth(std::string(m_text.data()+beg).substr(0, o1-beg), m_fontType, size);
end.x = m_engine->GetText()->GetStringWidth(std::string(m_text.data()+o1).substr(0, o2-o1), m_fontType, size); end.x = m_engine->GetText()->GetStringWidth(std::string(m_text.data()+o1).substr(0, o2-o1), m_fontType, size);
@ -1052,7 +1051,7 @@ void CEdit::Draw()
eol = 2; // square (eot) eol = 2; // square (eot)
} }
if ( !m_bMulti || !m_bDisplaySpec ) eol = 0; if ( !m_bMulti || !m_bDisplaySpec ) eol = 0;
if ( m_format.size() == 0 ) if ( m_format.empty() )
{ {
m_engine->GetText()->DrawText(std::string(m_text.data()+beg).substr(0, len), m_fontType, size, ppos, m_dim.x, Gfx::TEXT_ALIGN_LEFT, eol); m_engine->GetText()->DrawText(std::string(m_text.data()+beg).substr(0, len), m_fontType, size, ppos, m_dim.x, Gfx::TEXT_ALIGN_LEFT, eol);
} }
@ -1093,7 +1092,7 @@ void CEdit::Draw()
len = m_cursor1 - m_lineOffset[i]; len = m_cursor1 - m_lineOffset[i];
if ( m_format.size() == 0 ) if ( m_format.empty() )
{ {
m_engine->GetText()->SizeText(std::string(m_text.data()+m_lineOffset[i]).substr(0, len), m_fontType, m_engine->GetText()->SizeText(std::string(m_text.data()+m_lineOffset[i]).substr(0, len), m_fontType,
size, pos, Gfx::TEXT_ALIGN_LEFT, size, pos, Gfx::TEXT_ALIGN_LEFT,
@ -1255,42 +1254,20 @@ void CEdit::DrawColor(Math::Point pos, Math::Point dim, Gfx::Color color)
// Give the text to edit. // Give the text to edit.
void CEdit::SetText(const char *text, bool bNew) void CEdit::SetText(const std::string& text, bool bNew)
{ {
int i, j, font; int i, j, font;
bool bBOL; bool bBOL;
if ( !bNew ) UndoMemorize(OPERUNDO_SPEC); if ( !bNew ) UndoMemorize(OPERUNDO_SPEC);
m_len = strlen(text); m_len = text.size();
if ( m_len > m_maxChar ) m_len = m_maxChar;
if ( m_format.size() == 0 ) if( m_len >= GetMaxChar() ) m_len = GetMaxChar();
{
if ( m_bAutoIndent ) m_text.resize( m_len + 1, '\0' );
{ m_format.resize( m_len + 1, m_fontType );
j = 0;
bBOL = true;
for ( i=0 ; i<m_len ; i++ )
{
if ( text[i] == '\t' )
{
if ( !bBOL ) m_text[j++] = ' ';
continue; // removes tabs
}
bBOL = ( text[i] == '\n' );
m_text[j++] = text[i];
}
m_len = j;
}
else
{
strncpy(m_text.data(), text, m_len);
}
}
else
{
font = m_fontType; font = m_fontType;
j = 0; j = 0;
bBOL = true; bBOL = true;
@ -1349,12 +1326,10 @@ void CEdit::SetText(const char *text, bool bNew)
m_text[j] = text[i]; m_text[j] = text[i];
m_format[j] = font; m_format[j] = font;
j ++; j ++;
font &= ~Gfx::FONT_MASK_TITLE; // reset title font &= ~Gfx::FONT_MASK_TITLE; // reset title
} }
} }
m_len = j; m_len = j;
}
if ( bNew ) UndoFlush(); if ( bNew ) UndoFlush();
@ -1364,23 +1339,21 @@ void CEdit::SetText(const char *text, bool bNew)
ColumnFix(); ColumnFix();
} }
// Returns a pointer to the edited text. // Returns a const reference to the edited text.
char* CEdit::GetText() const std::string& CEdit::GetText()
{ {
m_text[m_len] = 0; return m_text;
return m_text.data();
} }
// Returns the edited text. // Returns the edited text.
void CEdit::GetText(char *buffer, int max) std::string CEdit::GetText(int max)
{ {
if ( m_len < max ) max = m_len; if ( m_len < max ) max = m_len;
if ( m_len > max ) max = max-1; if ( m_len > max ) max = max-1;
strncpy(buffer, m_text.data(), max); return std::string( m_text, 0, max );
buffer[max] = 0;
} }
// Returns the length of the text. // Returns the length of the text.
@ -1437,15 +1410,15 @@ void CEdit::FreeImage()
// Read from a text file. // Read from a text file.
bool CEdit::ReadText(std::string filename, int addSize) bool CEdit::ReadText(std::string filename)
{ {
int len, i, j, n, font, iLines, iCount; int len, len2, i, j, n, font, iLines, iCount;
char iName[50]; char iName[50];
float iWidth; float iWidth;
InputSlot slot; InputSlot slot;
bool bInSoluce, bBOL; bool bInSoluce, bBOL;
if ( filename == "" ) return false; if ( filename.empty() ) return false;
CInputStream stream; CInputStream stream;
stream.open(filename); stream.open(filename);
@ -1457,26 +1430,22 @@ bool CEdit::ReadText(std::string filename, int addSize)
} }
len = stream.size(); len = stream.size();
len2 = len + 1;
m_maxChar = len+addSize+100;
m_len = len; m_len = len;
m_cursor1 = 0; m_cursor1 = 0;
m_cursor2 = 0; m_cursor2 = 0;
FreeImage(); FreeImage();
m_text = std::vector<char>(m_maxChar+1, '\0'); m_text = std::string(len2+1, '\0');
std::vector<char> buffer(m_maxChar+1, '\0'); std::vector<char> buffer(len2+1, '\0');
stream.read(buffer.data(), len); stream.read(buffer.data(), len);
m_format.clear(); m_format.clear();
m_format.reserve(m_maxChar+1); m_format.resize(len2+1, m_fontType);
for (i = 0; i <= m_maxChar+1; i++)
{
m_format.push_back(m_fontType);
}
stream.close(); stream.close();
@ -1922,14 +1891,10 @@ void CEdit::SetMaxChar(int max)
m_maxChar = max; m_maxChar = max;
m_text = std::vector<char>(m_maxChar+1, '\0'); m_text.resize( m_maxChar + 1, '\0' );
m_format.clear(); m_format.clear();
m_format.reserve(m_maxChar+1); m_format.resize(m_maxChar + 1, m_fontType);
for (int i = 0; i <= m_maxChar+1; i++)
{
m_format.push_back(m_fontType);
}
m_len = 0; m_len = 0;
m_cursor1 = 0; m_cursor1 = 0;
@ -2121,11 +2086,7 @@ void CEdit::SetMultiFont(bool bMulti)
if (bMulti) if (bMulti)
{ {
m_format.reserve(m_maxChar+1); m_format.resize( m_text.size() + 1, m_fontType );
for (int i = 0; i <= m_maxChar+1; i++)
{
m_format.push_back(m_fontType);
}
} }
} }
@ -2419,7 +2380,7 @@ void CEdit::MoveLine(int move, bool bWord, bool bSelect)
column -= indentLength*m_lineIndent[line]; column -= indentLength*m_lineIndent[line];
} }
if ( m_format.size() == 0 ) if ( m_format.empty() )
{ {
c = m_engine->GetText()->Detect(std::string(m_text.data()+m_lineOffset[line]), c = m_engine->GetText()->Detect(std::string(m_text.data()+m_lineOffset[line]),
m_fontType, m_fontSize, m_fontType, m_fontSize,
@ -2450,7 +2411,7 @@ void CEdit::ColumnFix()
line = GetCursorLine(m_cursor1); line = GetCursorLine(m_cursor1);
if ( m_format.size() == 0 ) if ( m_format.empty() )
{ {
m_column = m_engine->GetText()->GetStringWidth( m_column = m_engine->GetText()->GetStringWidth(
std::string(m_text.data()+m_lineOffset[line]), std::string(m_text.data()+m_lineOffset[line]),
@ -2706,7 +2667,10 @@ void CEdit::InsertOne(char character)
DeleteOne(0); // deletes the selected characters DeleteOne(0); // deletes the selected characters
} }
if ( m_len >= m_maxChar ) return; if ( m_len >= GetMaxChar() ) return;
m_text.resize( m_text.size() + 1, '\0' );
m_format.resize( m_format.size() + 1, m_fontType );
for ( i=m_len ; i>m_cursor1 ; i-- ) for ( i=m_len ; i>m_cursor1 ; i-- )
{ {
@ -2938,13 +2902,16 @@ bool CEdit::MinMaj(bool bMaj)
void CEdit::Justif() void CEdit::Justif()
{ {
float width, size, indentLength = 0.0f; float width, size, indentLength = 0.0f;
int i, j, line, indent; int i, j, k, line, indent;
bool bDual, bString, bRem; bool bDual, bString, bRem;
m_lineOffset.clear();
m_lineIndent.clear();
indent = 0; indent = 0;
m_lineTotal = 0; m_lineTotal = 0;
m_lineOffset[m_lineTotal] = 0; m_lineOffset.push_back( 0 );
m_lineIndent[m_lineTotal] = indent; m_lineIndent.push_back( indent );
m_lineTotal ++; m_lineTotal ++;
if ( m_bAutoIndent ) if ( m_bAutoIndent )
@ -2954,7 +2921,7 @@ void CEdit::Justif()
} }
bString = bRem = false; bString = bRem = false;
i = 0; i = k = 0;
while ( true ) while ( true )
{ {
bDual = false; bDual = false;
@ -2965,7 +2932,7 @@ void CEdit::Justif()
width -= indentLength*m_lineIndent[m_lineTotal-1]; width -= indentLength*m_lineIndent[m_lineTotal-1];
} }
if ( m_format.size() == 0 ) if ( m_format.empty() )
{ {
// TODO check if good // TODO check if good
@ -3014,26 +2981,27 @@ void CEdit::Justif()
if ( indent < 0 ) indent = 0; if ( indent < 0 ) indent = 0;
} }
m_lineOffset[m_lineTotal] = i; m_lineOffset.push_back( i );
m_lineIndent[m_lineTotal] = indent; m_lineIndent.push_back( indent );
m_lineTotal ++; m_lineTotal ++;
if ( bDual ) if ( bDual )
{ {
m_lineOffset[m_lineTotal] = i; m_lineOffset.push_back( i );
m_lineIndent[m_lineTotal] = indent; m_lineIndent.push_back( indent );
m_lineTotal ++; m_lineTotal ++;
} }
if ( m_lineTotal >= EDITLINEMAX-2 ) break; if ( k == i ) break;
k = i;
} }
if ( m_len > 0 && m_text[m_len-1] == '\n' ) if ( m_len > 0 && m_text[m_len-1] == '\n' )
{ {
m_lineOffset[m_lineTotal] = m_len; m_lineOffset.push_back( m_len );
m_lineIndent[m_lineTotal] = 0; m_lineIndent.push_back( 0 );
m_lineTotal ++; m_lineTotal ++;
} }
m_lineOffset[m_lineTotal] = m_len; m_lineOffset.push_back( m_len );
m_lineIndent[m_lineTotal] = 0; m_lineIndent.push_back( 0 );
if ( m_bAutoIndent ) if ( m_bAutoIndent )
{ {
@ -3168,7 +3136,7 @@ bool CEdit::UndoRecall()
bool CEdit::ClearFormat() bool CEdit::ClearFormat()
{ {
if ( m_format.size() == 0 ) if ( m_format.empty() )
{ {
SetMultiFont(true); SetMultiFont(true);
} }

View File

@ -34,21 +34,15 @@ namespace Ui
class CScroll; class CScroll;
//! maximum number of characters in CBOT edit
const int EDITSTUDIOMAX = 20000;
//! maximum total number of lines
const int EDITLINEMAX = 1000;
//! max number of levels preserves //! max number of levels preserves
const int EDITHISTORYMAX = 50; const int EDITHISTORYMAX = 50;
//! max number of successive undo //! max number of successive undo
const int EDITUNDOMAX = 20; const int EDITUNDOMAX = 20;
struct EditUndo struct EditUndo
{ {
//! original text //! original text
std::vector<char> text; std::string text;
//! length of the text //! length of the text
int len = 0; int len = 0;
//! offset cursor //! offset cursor
@ -124,12 +118,12 @@ public:
bool EventProcess(const Event &event) override; bool EventProcess(const Event &event) override;
void Draw() override; void Draw() override;
void SetText(const char *text, bool bNew=true); void SetText(const std::string& text, bool bNew=true);
void GetText(char *buffer, int max); std::string GetText(int max);
char* GetText(); const std::string& GetText();
int GetTextLength(); int GetTextLength();
bool ReadText(std::string filename, int addSize=0); bool ReadText(std::string filename);
bool WriteText(std::string filename); bool WriteText(std::string filename);
void SetMaxChar(int max); void SetMaxChar(int max);
@ -234,8 +228,8 @@ protected:
protected: protected:
std::unique_ptr<CScroll> m_scroll; // vertical scrollbar on the right std::unique_ptr<CScroll> m_scroll; // vertical scrollbar on the right
int m_maxChar; // max length of the buffer m_text int m_maxChar;
std::vector<char> m_text; // text (without zero terminator) std::string m_text; // text (without zero terminator)
std::vector<Gfx::FontMetaChar> m_format; // format characters std::vector<Gfx::FontMetaChar> m_format; // format characters
int m_len; // length used in m_text int m_len; // length used in m_text
int m_cursor1; // offset cursor int m_cursor1; // offset cursor
@ -256,14 +250,14 @@ protected:
int m_lineVisible; // total number of viewable lines int m_lineVisible; // total number of viewable lines
int m_lineFirst; // the first line displayed int m_lineFirst; // the first line displayed
int m_lineTotal; // number lines used (in m_lineOffset) int m_lineTotal; // number lines used (in m_lineOffset)
int m_lineOffset[EDITLINEMAX]; std::vector<int> m_lineOffset;
char m_lineIndent[EDITLINEMAX]; std::vector<char> m_lineIndent;
std::vector<ImageLine> m_image; std::vector<ImageLine> m_image;
std::vector<HyperLink> m_link; std::vector<HyperLink> m_link;
std::vector<HyperMarker> m_marker; std::vector<HyperMarker> m_marker;
int m_historyTotal; int m_historyTotal;
int m_historyCurrent; int m_historyCurrent;
HyperHistory m_history[EDITHISTORYMAX]; std::array<HyperHistory, EDITHISTORYMAX> m_history;
float m_time; // absolute time float m_time; // absolute time
float m_timeBlink; float m_timeBlink;
float m_timeLastClick; float m_timeLastClick;
@ -276,7 +270,7 @@ protected:
bool m_bUndoForce; bool m_bUndoForce;
OperUndo m_undoOper; OperUndo m_undoOper;
EditUndo m_undo[EDITUNDOMAX]; std::array<EditUndo, EDITUNDOMAX> m_undo;
}; };

View File

@ -298,13 +298,13 @@ void CEditValue::SetValue(float value, bool bSendMessage)
float CEditValue::GetValue() float CEditValue::GetValue()
{ {
char text[100]; std::string text;
float value = 0.0f; float value = 0.0f;
if ( m_edit != nullptr ) if ( m_edit != nullptr )
{ {
m_edit->GetText(text, 100); text = m_edit->GetText(100);
sscanf(text, "%f", &value); sscanf(text.c_str(), "%f", &value);
if ( m_type == EVT_100 ) if ( m_type == EVT_100 )
{ {

View File

@ -193,11 +193,10 @@ void CScreenIO::IODeleteScene()
} }
// clears filename only to leave letter or numbers // clears filename only to leave letter or numbers
std::string clearName(char *name) std::string clearName(std::string name)
{ {
std::string ret; std::string ret;
int len = strlen(name); for (int i = 0; i < static_cast<int>(name.size()); i++)
for (int i = 0; i < len; i++)
{ {
if (isalnum(name[i])) if (isalnum(name[i]))
{ {
@ -214,7 +213,7 @@ void CScreenIO::IOWriteScene()
CWindow* pw; CWindow* pw;
CList* pl; CList* pl;
CEdit* pe; CEdit* pe;
char info[100]; std::string info;
pw = static_cast<CWindow*>(m_interface->SearchControl(EVENT_WINDOW5)); pw = static_cast<CWindow*>(m_interface->SearchControl(EVENT_WINDOW5));
if ( pw == nullptr ) return; if ( pw == nullptr ) return;
@ -226,7 +225,7 @@ void CScreenIO::IOWriteScene()
int sel = pl->GetSelect(); int sel = pl->GetSelect();
if ( sel == -1 ) return; if ( sel == -1 ) return;
pe->GetText(info, 100); info = pe->GetText(100);
m_interface->DeleteControl(EVENT_WINDOW5); m_interface->DeleteControl(EVENT_WINDOW5);

View File

@ -232,7 +232,7 @@ void CScreenPlayerSelect::UpdateNameControl()
CList* pl; CList* pl;
CButton* pb; CButton* pb;
CEdit* pe; CEdit* pe;
char name[100]; std::string name;
int total, sel; int total, sel;
pw = static_cast<CWindow*>(m_interface->SearchControl(EVENT_WINDOW5)); pw = static_cast<CWindow*>(m_interface->SearchControl(EVENT_WINDOW5));
@ -244,7 +244,7 @@ void CScreenPlayerSelect::UpdateNameControl()
total = pl->GetTotal(); total = pl->GetTotal();
sel = pl->GetSelect(); sel = pl->GetSelect();
pe->GetText(name, 100); name = pe->GetText(100);
pb = static_cast<CButton*>(pw->SearchControl(EVENT_INTERFACE_NDELETE)); pb = static_cast<CButton*>(pw->SearchControl(EVENT_INTERFACE_NDELETE));
if ( pb != nullptr ) if ( pb != nullptr )
@ -255,13 +255,13 @@ void CScreenPlayerSelect::UpdateNameControl()
pb = static_cast<CButton*>(pw->SearchControl(EVENT_INTERFACE_NOK)); pb = static_cast<CButton*>(pw->SearchControl(EVENT_INTERFACE_NOK));
if ( pb != nullptr ) if ( pb != nullptr )
{ {
pb->SetState(STATE_ENABLE, name[0]!=0 || sel!=-1); pb->SetState(STATE_ENABLE, !name.empty() || sel!=-1);
} }
pb = static_cast<CButton*>(pw->SearchControl(EVENT_INTERFACE_PERSO)); pb = static_cast<CButton*>(pw->SearchControl(EVENT_INTERFACE_PERSO));
if ( pb != nullptr ) if ( pb != nullptr )
{ {
pb->SetState(STATE_ENABLE, name[0]!=0 || sel!=-1); pb->SetState(STATE_ENABLE, !name.empty() || sel!=-1);
} }
} }
@ -272,7 +272,7 @@ void CScreenPlayerSelect::UpdateNameList()
CWindow* pw; CWindow* pw;
CList* pl; CList* pl;
CEdit* pe; CEdit* pe;
char name[100]; std::string name;
int total, i; int total, i;
pw = static_cast<CWindow*>(m_interface->SearchControl(EVENT_WINDOW5)); pw = static_cast<CWindow*>(m_interface->SearchControl(EVENT_WINDOW5));
@ -282,7 +282,7 @@ void CScreenPlayerSelect::UpdateNameList()
pe = static_cast<CEdit*>(pw->SearchControl(EVENT_INTERFACE_NEDIT)); pe = static_cast<CEdit*>(pw->SearchControl(EVENT_INTERFACE_NEDIT));
if ( pe == nullptr ) return; if ( pe == nullptr ) return;
pe->GetText(name, 100); name = pe->GetText(100);
total = pl->GetTotal(); total = pl->GetTotal();
for ( i=0 ; i<total ; i++ ) for ( i=0 ; i<total ; i++ )
@ -339,7 +339,7 @@ void CScreenPlayerSelect::NameSelect()
CWindow* pw; CWindow* pw;
CList* pl; CList* pl;
CEdit* pe; CEdit* pe;
char name[100]; std::string name;
int sel; int sel;
pw = static_cast<CWindow*>(m_interface->SearchControl(EVENT_WINDOW5)); pw = static_cast<CWindow*>(m_interface->SearchControl(EVENT_WINDOW5));
@ -349,7 +349,7 @@ void CScreenPlayerSelect::NameSelect()
pe = static_cast<CEdit*>(pw->SearchControl(EVENT_INTERFACE_NEDIT)); pe = static_cast<CEdit*>(pw->SearchControl(EVENT_INTERFACE_NEDIT));
if ( pe == nullptr ) return; if ( pe == nullptr ) return;
pe->GetText(name, 100); name = pe->GetText(100);
sel = pl->GetSelect(); sel = pl->GetSelect();
if ( sel == -1 ) if ( sel == -1 )
@ -377,9 +377,9 @@ bool CScreenPlayerSelect::NameCreate()
pe = static_cast<CEdit*>(pw->SearchControl(EVENT_INTERFACE_NEDIT)); pe = static_cast<CEdit*>(pw->SearchControl(EVENT_INTERFACE_NEDIT));
if ( pe == nullptr ) return false; if ( pe == nullptr ) return false;
char name[100]; std::string name;
pe->GetText(name, 100); name = pe->GetText(100);
if ( name[0] == 0 ) if ( name.empty() )
{ {
m_sound->Play(SOUND_TZOING); m_sound->Play(SOUND_TZOING);
return false; return false;

View File

@ -436,8 +436,8 @@ void CStudio::SearchToken(CEdit* edit)
{ {
ObjectType type; ObjectType type;
int len, cursor1, cursor2, i, character, level; int len, cursor1, cursor2, i, character, level;
char* text; std::string text;
char token[100]; std::string token( 100, '\0');
text = edit->GetText(); text = edit->GetText();
len = edit->GetTextLength(); len = edit->GetTextLength();
@ -503,7 +503,7 @@ void CStudio::SearchToken(CEdit* edit)
} }
token[i] = 0; token[i] = 0;
m_helpFilename = GetHelpFilename(token); m_helpFilename = GetHelpFilename(token.c_str());
if ( m_helpFilename.length() == 0 ) if ( m_helpFilename.length() == 0 )
{ {
for ( i=0 ; i<OBJECT_MAX ; i++ ) for ( i=0 ; i<OBJECT_MAX ; i++ )
@ -512,30 +512,30 @@ void CStudio::SearchToken(CEdit* edit)
text = const_cast<char *>(GetObjectName(type)); text = const_cast<char *>(GetObjectName(type));
if ( text[0] != 0 ) if ( text[0] != 0 )
{ {
if ( strcmp(token, text) == 0 ) if ( token == text )
{ {
m_helpFilename = GetHelpFilename(type); m_helpFilename = GetHelpFilename(type);
SetInfoText(std::string(token), true); SetInfoText(token, true);
return; return;
} }
} }
text = const_cast<char *>(GetObjectAlias(type)); text = const_cast<char *>(GetObjectAlias(type));
if ( text[0] != 0 ) if ( text[0] != 0 )
{ {
if ( strcmp(token, text) == 0 ) if ( token == text )
{ {
m_helpFilename = GetHelpFilename(type); m_helpFilename = GetHelpFilename(type);
SetInfoText(std::string(token), true); SetInfoText(token, true);
return; return;
} }
} }
} }
} }
text = const_cast<char *>(GetHelpText(token)); text = const_cast<char *>(GetHelpText(token.c_str()));
if ( text[0] == 0 && m_helpFilename.length() > 0 ) if ( text[0] == 0 && m_helpFilename.length() > 0 )
{ {
SetInfoText(std::string(token), true); SetInfoText(token, true);
} }
else else
{ {
@ -606,7 +606,6 @@ void CStudio::StartEditScript(CScript *script, std::string name, Program* progra
edit->SetState(STATE_SHADOW); edit->SetState(STATE_SHADOW);
edit->SetInsideScroll(false); edit->SetInsideScroll(false);
//? if ( m_bRunning ) edit->SetEdit(false); //? if ( m_bRunning ) edit->SetEdit(false);
edit->SetMaxChar(EDITSTUDIOMAX);
edit->SetFontType(Gfx::FONT_COURIER); edit->SetFontType(Gfx::FONT_COURIER);
edit->SetFontStretch(1.0f); edit->SetFontStretch(1.0f);
edit->SetDisplaySpec(true); edit->SetDisplaySpec(true);
@ -1245,7 +1244,7 @@ void CStudio::AdjustDialog()
CEdit* pe; CEdit* pe;
Math::Point wpos, wdim, ppos, ddim; Math::Point wpos, wdim, ppos, ddim;
int nli, nch; int nli, nch;
char name[100]; std::string name;
pw = static_cast< CWindow* >(m_interface->SearchControl(EVENT_WINDOW9)); pw = static_cast< CWindow* >(m_interface->SearchControl(EVENT_WINDOW9));
if ( pw == nullptr ) return; if ( pw == nullptr ) return;
@ -1302,7 +1301,7 @@ void CStudio::AdjustDialog()
pe->SetDim(ddim); pe->SetDim(ddim);
nch = static_cast< int >((ddim.x*640.0f-22.0f)/8.0f); nch = static_cast< int >((ddim.x*640.0f-22.0f)/8.0f);
pe->GetText(name, 100); name = pe->GetText(100);
pe->SetMaxChar(nch); pe->SetMaxChar(nch);
name[nch] = 0; // truncates the text according to max name[nch] = 0; // truncates the text according to max
pe->SetText(name); pe->SetText(name);
@ -1467,7 +1466,7 @@ void CStudio::SetFilenameField(CEdit* edit, const std::string& filename)
name = name.substr(0, edit->GetMaxChar()); // truncates according to max length name = name.substr(0, edit->GetMaxChar()); // truncates according to max length
} }
} }
edit->SetText(name.c_str()); edit->SetText(name);
} }
// Updates the list after a change in name. // Updates the list after a change in name.
@ -1494,7 +1493,7 @@ void CStudio::UpdateDialogAction()
CWindow* pw; CWindow* pw;
CEdit* pe; CEdit* pe;
CButton* pb; CButton* pb;
char name[100]; std::string name;
int len, i; int len, i;
bool bError; bool bError;
@ -1505,8 +1504,8 @@ void CStudio::UpdateDialogAction()
pb = static_cast< CButton* >(pw->SearchControl(EVENT_DIALOG_OK)); pb = static_cast< CButton* >(pw->SearchControl(EVENT_DIALOG_OK));
if ( pb == nullptr ) return; if ( pb == nullptr ) return;
pe->GetText(name, 100); name = pe->GetText(100);
len = strlen(name); len = name.size();
if ( len == 0 ) if ( len == 0 )
{ {
bError = true; bError = true;
@ -1558,7 +1557,7 @@ void CStudio::UpdateDialogPublic()
if ( pl != nullptr ) if ( pl != nullptr )
{ {
// GetResource(RES_TEXT, RT_IO_LIST, name); // TODO: unused? // GetResource(RES_TEXT, RT_IO_LIST, name); // TODO: unused?
pl->SetName(SearchDirectory(false).c_str(), false); pl->SetName(SearchDirectory(false), false);
} }
} }
@ -1619,25 +1618,25 @@ bool CStudio::ReadProgram()
{ {
CWindow* pw; CWindow* pw;
CEdit* pe; CEdit* pe;
char filename[100]; std::string filename;
char dir[100]; std::string dir;
char* p; size_t p;
pw = static_cast< CWindow* >(m_interface->SearchControl(EVENT_WINDOW9)); pw = static_cast< CWindow* >(m_interface->SearchControl(EVENT_WINDOW9));
if ( pw == nullptr ) return false; if ( pw == nullptr ) return false;
pe = static_cast< CEdit* >(pw->SearchControl(EVENT_DIALOG_EDIT)); pe = static_cast< CEdit* >(pw->SearchControl(EVENT_DIALOG_EDIT));
if ( pe == nullptr ) return false; if ( pe == nullptr ) return false;
pe->GetText(filename, 100); filename = pe->GetText(100);
if ( filename[0] == 0 ) return false; if ( filename.empty() ) return false;
p = strstr(filename, ".txt"); p = filename.find(".txt");
if ( p == nullptr || p != filename+strlen(filename)-4 ) if ( p == std::string::npos )
{ {
strcat(filename, ".txt"); filename += ".txt";
} }
strcpy(dir, SearchDirectory(true).c_str()); dir = SearchDirectory(true);
strcat(dir, filename); dir += filename;
pw = static_cast< CWindow* >(m_interface->SearchControl(EVENT_WINDOW3)); pw = static_cast< CWindow* >(m_interface->SearchControl(EVENT_WINDOW3));
if ( pw == nullptr ) return false; if ( pw == nullptr ) return false;
@ -1657,32 +1656,32 @@ bool CStudio::WriteProgram()
{ {
CWindow* pw; CWindow* pw;
CEdit* pe; CEdit* pe;
char filename[100]; std::string filename;
char dir[100]; std::string dir;
char* p; size_t p;
pw = static_cast< CWindow* >(m_interface->SearchControl(EVENT_WINDOW9)); pw = static_cast< CWindow* >(m_interface->SearchControl(EVENT_WINDOW9));
if ( pw == nullptr ) return false; if ( pw == nullptr ) return false;
pe = static_cast< CEdit* >(pw->SearchControl(EVENT_DIALOG_EDIT)); pe = static_cast< CEdit* >(pw->SearchControl(EVENT_DIALOG_EDIT));
if ( pe == nullptr ) return false; if ( pe == nullptr ) return false;
pe->GetText(filename, 100); filename = pe->GetText(100);
if ( filename[0] == 0 ) return false; if ( filename.empty() ) return false;
p = strstr(filename, ".txt"); p = filename.find(".txt");
if ( p == nullptr || p != filename+strlen(filename)-4 ) if ( p == std::string::npos )
{ {
strcat(filename, ".txt"); filename += ".txt";
} }
strcpy(dir, SearchDirectory(true).c_str()); dir = SearchDirectory(true);
strcat(dir, filename); dir += filename;
pw = static_cast< CWindow* >(m_interface->SearchControl(EVENT_WINDOW3)); pw = static_cast< CWindow* >(m_interface->SearchControl(EVENT_WINDOW3));
if ( pw == nullptr ) return false; if ( pw == nullptr ) return false;
pe = static_cast< CEdit* >(pw->SearchControl(EVENT_STUDIO_EDIT)); pe = static_cast< CEdit* >(pw->SearchControl(EVENT_STUDIO_EDIT));
if ( pe == nullptr ) return false; if ( pe == nullptr ) return false;
if ( !pe->WriteText(std::string(dir)) ) return false; if ( !pe->WriteText(dir) ) return false;
m_script->SetFilename(filename); m_script->SetFilename(filename);
return true; return true;