xref: /haiku/headers/os/interface/StringView.h (revision ed24eb5ff12640d052171c6a7feba37fab8a75d1)
1 /*
2  * Copyright 2001-2015, Haiku, Inc. All rights reserved.
3  * Distributed under the terms of the MIT License.
4  */
5 #ifndef _STRING_VIEW_H
6 #define _STRING_VIEW_H
7 
8 
9 #include <View.h>
10 
11 
12 class BStringView : public BView {
13 public:
14 								BStringView(BRect frame, const char* name,
15 									const char* text, uint32 resizingMode
16 										= B_FOLLOW_LEFT_TOP,
17 									uint32 flags = B_WILL_DRAW);
18 								BStringView(const char* name, const char* text,
19 									uint32 flags = B_WILL_DRAW);
20 								BStringView(BMessage* archive);
21 	virtual 					~BStringView();
22 
23 	static	BArchivable*		Instantiate(BMessage* archive);
24 	virtual	status_t			Archive(BMessage* archive,
25 									bool deep = true) const;
26 
27 			void				SetText(const char* text);
28 			const char*			Text() const;
29 			void				SetAlignment(alignment flag);
30 			alignment			Alignment() const;
31 			void				SetTruncation(uint32 truncationMode);
32 			uint32				Truncation() const;
33 
34 	virtual	void				AttachedToWindow();
35 	virtual	void				DetachedFromWindow();
36 	virtual	void				AllAttached();
37 	virtual	void				AllDetached();
38 
39 	virtual	void				MakeFocus(bool focus = true);
40 
41 	virtual void				GetPreferredSize(float* _width,
42 									float* _height);
43 	virtual	BSize				MinSize();
44 	virtual	BSize				MaxSize();
45 	virtual	BSize				PreferredSize();
46 	virtual	void				ResizeToPreferred();
47 	virtual	BAlignment			LayoutAlignment();
48 	virtual	void				FrameMoved(BPoint newPosition);
49 	virtual	void				FrameResized(float newWidth, float newHeight);
50 
51 	virtual	void				Draw(BRect bounds);
52 
53 	virtual	void				MessageReceived(BMessage* message);
54 	virtual	void				MouseDown(BPoint point);
55 	virtual	void				MouseUp(BPoint point);
56 	virtual	void				MouseMoved(BPoint point, uint32 transit,
57 									const BMessage* dragMessage);
58 
59 	virtual	BHandler*			ResolveSpecifier(BMessage* message,
60 									int32 index, BMessage* specifier,
61 									int32 form, const char* property);
62 	virtual	status_t			GetSupportedSuites(BMessage* data);
63 
64 	virtual	void				SetFont(const BFont* font,
65 									uint32 mask = B_FONT_ALL);
66 
67 protected:
68 	virtual	void				LayoutInvalidated(bool descendants = false);
69 
70 private:
71 	// FBC padding and forbidden methods
72 	virtual	status_t			Perform(perform_code code, void* data);
73 
74 	virtual	void				_ReservedStringView1();
75 	virtual	void				_ReservedStringView2();
76 	virtual	void				_ReservedStringView3();
77 
78 			BStringView&		operator=(const BStringView& other);
79 
80 private:
81 			BSize				_ValidatePreferredSize();
82 			float				_StringWidth(const char* text);
83 
84 private:
85 			char*				fText;
86 			uint32				fTruncation;
87 			alignment			fAlign;
88 			BSize				fPreferredSize;
89 };
90 
91 
92 #endif // _STRING_VIEW_H
93