TextControl.h revision 8bc3ecb0
1/*
2 * Copyright 2006-2015, Haiku, Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
4 */
5#ifndef	_TEXT_CONTROL_H
6#define	_TEXT_CONTROL_H
7
8
9#include <Control.h>
10#include <TextView.h>
11
12
13class BLayoutItem;
14namespace BPrivate {
15	class _BTextInput_;
16}
17
18
19class BTextControl : public BControl {
20public:
21								BTextControl(BRect frame, const char* name,
22									const char* label, const char* initialText,
23									BMessage* message,
24									uint32 resizeMask
25										= B_FOLLOW_LEFT | B_FOLLOW_TOP,
26									uint32 flags = B_WILL_DRAW | B_NAVIGABLE);
27								BTextControl(const char* name,
28									const char* label, const char* initialText,
29									BMessage* message,
30									uint32 flags = B_WILL_DRAW | B_NAVIGABLE);
31								BTextControl(const char* label,
32									const char* initialText,
33									BMessage* message);
34	virtual						~BTextControl();
35
36								BTextControl(BMessage* archive);
37	static	BArchivable*		Instantiate(BMessage* archive);
38	virtual	status_t			Archive(BMessage* archive,
39									bool deep = true) const;
40
41	virtual	void				SetText(const char* text);
42			const char*			Text() const;
43			int32				TextLength() const;
44			void				MarkAsInvalid(bool invalid);
45
46	virtual	void				SetValue(int32 value);
47	virtual	status_t			Invoke(BMessage* message = NULL);
48
49			BTextView*			TextView() const;
50
51	virtual	void				SetModificationMessage(BMessage* message);
52			BMessage*			ModificationMessage() const;
53
54	virtual	void				SetAlignment(alignment label, alignment text);
55			void				GetAlignment(alignment* _label,
56									alignment* _text) const;
57	virtual	void				SetDivider(float position);
58			float				Divider() const;
59
60	virtual	void				Draw(BRect updateRect);
61	virtual	void				MouseDown(BPoint where);
62	virtual	void				AttachedToWindow();
63	virtual	void				MakeFocus(bool focus = true);
64	virtual	void				SetEnabled(bool enable);
65	virtual	void				FrameMoved(BPoint newPosition);
66	virtual	void				FrameResized(float newWidth, float newHeight);
67	virtual	void				WindowActivated(bool active);
68
69	virtual	void				GetPreferredSize(float* _width,
70									float* _height);
71	virtual	void				ResizeToPreferred();
72
73	virtual	void				MessageReceived(BMessage* message);
74	virtual	BHandler*			ResolveSpecifier(BMessage* message,
75									int32 index, BMessage* specifier,
76									int32 what, const char* property);
77
78	virtual	void				MouseUp(BPoint where);
79	virtual	void				MouseMoved(BPoint where, uint32 transit,
80									const BMessage* dragMessage);
81	virtual	void				DetachedFromWindow();
82
83	virtual	void				AllAttached();
84	virtual	void				AllDetached();
85	virtual	status_t			GetSupportedSuites(BMessage* data);
86	virtual	void				SetFlags(uint32 flags);
87
88	virtual	BSize				MinSize();
89	virtual	BSize				MaxSize();
90	virtual	BSize				PreferredSize();
91	virtual	BAlignment			LayoutAlignment();
92
93			BLayoutItem*		CreateLabelLayoutItem();
94			BLayoutItem*		CreateTextViewLayoutItem();
95
96protected:
97	virtual	status_t			AllArchived(BMessage* into) const;
98	virtual	status_t			AllUnarchived(const BMessage* from);
99
100	virtual	void				LayoutInvalidated(bool descendants);
101	virtual	void				DoLayout();
102
103	virtual	status_t			SetIcon(const BBitmap* icon, uint32 flags = 0);
104
105private:
106	// FBC padding and forbidden methods
107	virtual	status_t			Perform(perform_code d, void* arg);
108
109	virtual	void				_ReservedTextControl1();
110	virtual	void				_ReservedTextControl2();
111	virtual	void				_ReservedTextControl3();
112	virtual	void				_ReservedTextControl4();
113
114			BTextControl&		operator=(const BTextControl& other);
115
116private:
117	class LabelLayoutItem;
118	class TextViewLayoutItem;
119	struct LayoutData;
120
121	friend class _BTextInput_;
122	friend class LabelLayoutItem;
123	friend class TextViewLayoutItem;
124
125			void				_CommitValue();
126			void				_UpdateTextViewColors(bool enable);
127			void				_InitData(const char* label,
128									const BMessage* archive = NULL);
129			void				_InitText(const char* initialText,
130									const BMessage* archive = NULL);
131			void				_ValidateLayout();
132			void				_LayoutTextView();
133			void				_UpdateFrame();
134
135			void				_ValidateLayoutData();
136
137private:
138			BPrivate::_BTextInput_* fText;
139			BMessage*			fModificationMessage;
140			alignment			fLabelAlign;
141			float				fDivider;
142
143			LayoutData*			fLayoutData;
144			uint32				fLook;
145
146			uint32				_reserved[8];
147};
148
149
150#endif	// _TEXT_CONTROL_H
151