From 9242a80a84fa5c96dbadec9594177875aeeec1ac Mon Sep 17 00:00:00 2001 From: Kirill Volinsky Date: Tue, 10 Jul 2012 18:37:21 +0000 Subject: only added MyDetails and Skins. not adopted yet git-svn-id: http://svn.miranda-ng.org/main/trunk@892 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/Skins/SkinLib/TextFieldState.cpp | 65 ++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 plugins/Skins/SkinLib/TextFieldState.cpp (limited to 'plugins/Skins/SkinLib/TextFieldState.cpp') 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; +} -- cgit v1.2.3