1/*
2 * Copyright 2006, Haiku.
3 * Distributed under the terms of the MIT License.
4 *
5 * Authors:
6 *		Stephan Aßmus <superstippi@gmx.de>
7 */
8
9#include "TextInputValueView.h"
10
11#include <stdio.h>
12
13#include <Message.h>
14#include <String.h>
15
16#include "NummericalTextView.h"
17#include "PropertyItemView.h"
18
19enum {
20	MSG_VALUE_CHANGED	= 'vchd',
21};
22
23// constructor
24TextInputValueView::TextInputValueView()
25	: PropertyEditorView()
26{
27}
28
29// destructor
30TextInputValueView::~TextInputValueView()
31{
32}
33
34// AttachedToWindow
35void
36TextInputValueView::AttachedToWindow()
37{
38	TextView()->SetMessage(new BMessage(MSG_VALUE_CHANGED));
39	TextView()->SetTarget(this);
40}
41
42// Draw
43void
44TextInputValueView::Draw(BRect updateRect)
45{
46	BRect b(Bounds());
47	if (TextView()->IsFocus())
48		SetLowColor(ui_color(B_KEYBOARD_NAVIGATION_COLOR));
49	StrokeRect(b, B_SOLID_LOW);
50}
51
52// FrameResized
53void
54TextInputValueView::FrameResized(float width, float height)
55{
56	BRect b(Bounds());
57	b.InsetBy(1.0, 1.0);
58	TextView()->MoveTo(b.LeftTop());
59	TextView()->ResizeTo(b.Width(), b.Height());
60	BRect tr(TextView()->Bounds());
61	tr.InsetBy(4.0, 1.0);
62	TextView()->SetTextRect(tr);
63}
64
65// MakeFocus
66void
67TextInputValueView::MakeFocus(bool focused)
68{
69	TextView()->MakeFocus(focused);
70}
71
72// MessageReceived
73void
74TextInputValueView::MessageReceived(BMessage* message)
75{
76	switch (message->what) {
77		case MSG_VALUE_CHANGED:
78			ValueChanged();
79			break;
80		default:
81			PropertyEditorView::MessageReceived(message);
82	}
83}
84
85// SetEnabled
86void
87TextInputValueView::SetEnabled(bool enabled)
88{
89	TextView()->MakeEditable(enabled);
90
91	rgb_color textColor = TextView()->LowColor();
92	if (enabled)
93		textColor = tint_color(textColor, B_DARKEN_MAX_TINT);
94	else
95		textColor = tint_color(textColor, B_DISABLED_LABEL_TINT);
96	TextView()->SetFontAndColor(NULL, 0, &textColor);
97}
98
99// IsFocused
100bool
101TextInputValueView::IsFocused() const
102{
103	return TextView()->IsFocus();
104}
105
106
107