blob: 8e295d01ee587f79d0fd5c84872a7fe16d73aafb (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
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;
}
|