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