Skip to content

Commit

Permalink
Use Polymorphisim for getting the text value of a control
Browse files Browse the repository at this point in the history
  • Loading branch information
bradallred committed Dec 24, 2013
1 parent 1fffe72 commit 4e2051f
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 16 deletions.
1 change: 1 addition & 0 deletions gemrb/core/GUI/Control.h
Expand Up @@ -151,6 +151,7 @@ class GEM_EXPORT Control {
virtual bool IsPixelTransparent(unsigned short /*x*/, unsigned short /*y*/) {
return false;
}
virtual const char* QueryText() const { return NULL; }
/** Sets the animation picture ref */
void SetAnimPicture(Sprite2D* Picture);
/** Sets the Scroll Bar Pointer */
Expand Down
4 changes: 2 additions & 2 deletions gemrb/core/GUI/TextArea.cpp
Expand Up @@ -897,12 +897,12 @@ void TextArea::SelectText(const char *select)
}
}

const char* TextArea::QueryText()
const char* TextArea::QueryText() const
{
if ( Value<lines.size() ) {
return ( const char * ) lines[Value];
}
return ( const char *) "";
return "";
}

bool TextArea::SetEvent(int eventType, EventHandler handler)
Expand Down
2 changes: 1 addition & 1 deletion gemrb/core/GUI/TextArea.h
Expand Up @@ -118,7 +118,7 @@ class GEM_EXPORT TextArea : public Control {
/** Copies the current TextArea content to another TextArea control */
void CopyTo(TextArea* ta);
/** Returns the selected text */
const char* QueryText();
const char* QueryText() const;
/** Marks textarea for redraw with a new value */
void UpdateState(const char* VariableName, unsigned int Sum);
int SetScrollBar(Control *ptr);
Expand Down
2 changes: 1 addition & 1 deletion gemrb/core/GUI/TextEdit.cpp
Expand Up @@ -224,7 +224,7 @@ void TextEdit::SetBufferLength(ieWord buflen)
}

/** Simply returns the pointer to the text, don't modify it! */
const char* TextEdit::QueryText()
const char* TextEdit::QueryText() const
{
return ( const char * ) Buffer;
}
Expand Down
4 changes: 2 additions & 2 deletions gemrb/core/GUI/TextEdit.h
Expand Up @@ -66,8 +66,8 @@ class GEM_EXPORT TextEdit : public Control {
void SetBackGround(Sprite2D* back);
/** Sets the Text of the current control */
void SetText(const char* string);
/** Sets the Text of the current control */
const char* QueryText();
/** Gets the Text of the current control */
const char* QueryText() const;
/** Sets the buffer length */
void SetBufferLength(ieWord buflen);
/** Sets the alignment */
Expand Down
11 changes: 1 addition & 10 deletions gemrb/plugins/GUIScript/GUIScript.cpp
Expand Up @@ -1359,16 +1359,7 @@ static PyObject* GemRB_Control_QueryText(PyObject * /*self*/, PyObject* args)
if (!ctrl) {
return NULL;
}
switch(ctrl->ControlType) {
case IE_GUI_LABEL:
return PyString_FromString(((Label *) ctrl)->QueryText() );
case IE_GUI_EDIT:
return PyString_FromString(((TextEdit *) ctrl)->QueryText() );
case IE_GUI_TEXTAREA:
return PyString_FromString(((TextArea *) ctrl)->QueryText() );
default:
return RuntimeError("Invalid control type");
}
return PyString_FromString(ctrl->QueryText() ?: "");
}

PyDoc_STRVAR( GemRB_TextEdit_SetBufferLength__doc,
Expand Down

0 comments on commit 4e2051f

Please sign in to comment.