xref: /haiku/src/preferences/filetypes/StringView.h (revision d3d8b26997fac34a84981e6d2b649521de2cc45a)
1 /*
2  * Copyright 2006, Axel Dörfler, axeld@pinc-software.de. 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 <String.h>
10 #include <View.h>
11 
12 
13 class StringView : public BView {
14 	public:
15 		StringView(BRect frame, const char* name, const char* label,
16 			const char* text, uint32 resizeMask = B_FOLLOW_LEFT | B_FOLLOW_TOP,
17 			uint32 flags = B_WILL_DRAW | B_FRAME_EVENTS);
18 		virtual ~StringView();
19 
20 		virtual void Draw(BRect updateRect);
21 		virtual void AttachedToWindow();
22 
23 		virtual void FrameResized(float width, float height);
24 
25 		virtual void GetPreferredSize(float* _width, float* _height);
26 		virtual void ResizeToPreferred();
27 
28 		void SetEnabled(bool enabled);
29 		bool IsEnabled() const { return fEnabled; }
30 
31 		void SetLabel(const char* label);
32 		const char* Label() const { return fLabel.String(); }
33 
34 		void SetText(const char* text);
35 		const char* Text() const { return fText.String(); }
36 
37 		void SetDivider(float divider);
38 		float Divider() const { return fDivider; }
39 
40 		void SetAlignment(alignment labelAlignment, alignment textAlignment);
41 		void GetAlignment(alignment* _label, alignment* _text) const;
42 
43 	private:
44 		void _UpdateText();
45 
46 		BString		fLabel;
47 		BString 	fText;
48 		BString 	fTruncatedText;
49 		float		fDivider;
50 		alignment	fLabelAlignment;
51 		alignment	fTextAlignment;
52 		bool		fEnabled;
53 };
54 
55 #endif	// STRING_VIEW_H
56