xref: /haiku/headers/os/interface/TextControl.h (revision 89755088d790ff4fe36f8aa77dacb2bd15507108)
1 /*
2  * Copyright 2006, 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 class BLayoutItem;
13 namespace BPrivate {
14 class _BTextInput_;
15 }
16 
17 class BTextControl : public BControl {
18 	public:
19 							BTextControl(BRect frame, const char* name,
20 								const char* label, const char* initialText,
21 								BMessage* message,
22 								uint32 resizeMode = B_FOLLOW_LEFT | B_FOLLOW_TOP,
23 								uint32 flags = B_WILL_DRAW | B_NAVIGABLE);
24 							BTextControl(const char* name,
25 								const char* label, const char* initialText,
26 								BMessage* message,
27 								uint32 flags = B_WILL_DRAW | B_NAVIGABLE);
28 							BTextControl(const char* label,
29 								const char* initialText,
30 								BMessage* message);
31 		virtual				~BTextControl();
32 
33 							BTextControl(BMessage* archive);
34 		static BArchivable*	Instantiate(BMessage* archive);
35 		virtual	status_t	Archive(BMessage* archive, bool deep = true) const;
36 
37 		virtual	void		SetText(const char* text);
38 		const char*			Text() const;
39 
40 		virtual	void		SetValue(int32 value);
41 		virtual	status_t	Invoke(BMessage* message = NULL);
42 
43 		BTextView*			TextView() const;
44 
45 		virtual	void		SetModificationMessage(BMessage* message);
46 		BMessage*			ModificationMessage() const;
47 
48 		virtual	void		SetAlignment(alignment label, alignment text);
49 		void				GetAlignment(alignment* _label, alignment* _text) const;
50 		virtual	void		SetDivider(float position);
51 		float				Divider() const;
52 
53 		virtual	void		Draw(BRect updateRect);
54 		virtual	void		MouseDown(BPoint where);
55 		virtual	void		AttachedToWindow();
56 		virtual	void		MakeFocus(bool focus = true);
57 		virtual	void		SetEnabled(bool enabled);
58 		virtual	void		FrameMoved(BPoint newPosition);
59 		virtual	void		FrameResized(float newWidth, float newHeight);
60 		virtual	void		WindowActivated(bool active);
61 
62 		virtual	void		GetPreferredSize(float* _width, float* _height);
63 		virtual	void		ResizeToPreferred();
64 
65 		virtual void		MessageReceived(BMessage* message);
66 		virtual BHandler*	ResolveSpecifier(BMessage* message, int32 index,
67 								BMessage* specifier, int32 what,
68 								const char* property);
69 
70 		virtual	void		MouseUp(BPoint point);
71 		virtual	void		MouseMoved(BPoint point, uint32 transit,
72 								const BMessage* dragMessage);
73 		virtual	void		DetachedFromWindow();
74 
75 		virtual void		AllAttached();
76 		virtual void		AllDetached();
77 		virtual status_t	GetSupportedSuites(BMessage* data);
78 		virtual void		SetFlags(uint32 flags);
79 
80 				BLayoutItem* CreateLabelLayoutItem();
81 				BLayoutItem* CreateTextViewLayoutItem();
82 
83 	private:
84 		class LabelLayoutItem;
85 		class TextViewLayoutItem;
86 
87 		friend class _BTextInput_;
88 		friend class LabelLayoutItem;
89 		friend class TextViewLayoutItem;
90 
91 		virtual status_t	Perform(perform_code d, void* arg);
92 
93 		virtual	void		_ReservedTextControl1();
94 		virtual	void		_ReservedTextControl2();
95 		virtual	void		_ReservedTextControl3();
96 		virtual	void		_ReservedTextControl4();
97 
98 		BTextControl&		operator=(const BTextControl& other);
99 
100 		void				_CommitValue();
101 		void				_UpdateTextViewColors(bool enabled);
102 		void				_InitData(const char* label, const char* initialText,
103 								BMessage* archive = NULL);
104 		void				_ValidateLayout();
105 		void				_LayoutTextView();
106 		void				_UpdateFrame();
107 
108 	private:
109 		BPrivate::_BTextInput_* fText;
110 		char*				fLabel;
111 		BMessage*			fModificationMessage;
112 		alignment			fLabelAlign;
113 		float				fDivider;
114 		float				fPreviousWidth;
115 		float				fPreviousHeight;
116 		BLayoutItem*		fLabelLayoutItem;
117 		BLayoutItem*		fTextViewLayoutItem;
118 
119 		uint32				_reserved[4];
120 
121 		bool				fClean;
122 		bool				fSkipSetFlags;
123 
124 		bool				_reserved1;
125 		bool				_reserved2;
126 };
127 
128 #endif	// _TEXT_CONTROL_H
129