summaryrefslogtreecommitdiff
path: root/plugins/Skins/SkinLib/TextFieldState.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/Skins/SkinLib/TextFieldState.cpp')
-rw-r--r--plugins/Skins/SkinLib/TextFieldState.cpp65
1 files changed, 65 insertions, 0 deletions
diff --git a/plugins/Skins/SkinLib/TextFieldState.cpp b/plugins/Skins/SkinLib/TextFieldState.cpp
new file mode 100644
index 0000000000..8e295d01ee
--- /dev/null
+++ b/plugins/Skins/SkinLib/TextFieldState.cpp
@@ -0,0 +1,65 @@
+#include "globals.h"
+#include "TextFieldState.h"
+
+
+TextFieldState::TextFieldState(DialogState *dialog, TextField *field)
+ : FieldState(dialog, field), font(field->getFont(), field->getFontColor()), textSet(false)
+{
+}
+
+TextFieldState::~TextFieldState()
+{
+}
+
+TextField * TextFieldState::getField() const
+{
+ return (TextField *) FieldState::getField();
+}
+
+
+Size TextFieldState::getPreferedSize() const
+{
+ HDC hdc = CreateCompatibleDC(NULL);
+
+ HFONT newFont = getFont()->getHFONT();
+ HFONT oldFont = (HFONT) SelectObject(hdc, newFont);
+
+ RECT rc = {0};
+ const TCHAR *text = getText();
+ DrawText(hdc, text, -1, &rc, DT_CALCRECT | DT_NOPREFIX | DT_EXPANDTABS | DT_SINGLELINE);
+
+ SelectObject(hdc, oldFont);
+
+ DeleteDC(hdc);
+
+ return Size(rc.right - rc.left, rc.bottom - rc.top);
+}
+
+const TCHAR * TextFieldState::getText() const
+{
+ if (textSet)
+ return text.c_str();
+
+ return getField()->getText();
+}
+
+void TextFieldState::setText(const TCHAR *text)
+{
+ this->text = text;
+ textSet = true;
+}
+
+FontState * TextFieldState::getFont()
+{
+ return &font;
+}
+
+const FontState * TextFieldState::getFont() const
+{
+ return &font;
+}
+
+bool TextFieldState::isEmpty() const
+{
+ return lstrlen(getText()) <= 0;
+}