xref: /haiku/src/preferences/locale/LanguageListView.h (revision 83b1a68c52ba3e0e8796282759f694b7fdddf06d)
1 /*
2  * Copyright 2006-2010, Haiku Inc. All rights reserved.
3  * Distributed under the terms of the MIT License.
4  *
5  * Authors:
6  *		Stephan Aßmus <superstippi@gmx.de>
7  *		Adrien Destugues <pulkomandy@gmail.com>
8  *		Axel Dörfler, axeld@pinc-software.de
9  *		Oliver Tappe <zooey@hirschkaefer.de>
10  */
11 #ifndef LANGUAGE_LIST_VIEW_H
12 #define LANGUAGE_LIST_VIEW_H
13 
14 
15 #include <OutlineListView.h>
16 #include <StringItem.h>
17 #include <String.h>
18 
19 
20 class LanguageListItem : public BStringItem {
21 public:
22 								LanguageListItem(const char* text,
23 									const char* id, const char* languageCode);
24 								LanguageListItem(
25 									const LanguageListItem& other);
26 
27 			const BString&		ID() const { return fID; }
28 			const BString&		Code() const { return fCode; }
29 
30 	virtual	void				DrawItem(BView* owner, BRect frame,
31 									bool complete = false);
32 
33 protected:
34 			void				DrawItemWithTextOffset(BView* owner,
35 									BRect frame, bool complete,
36 									float textOffset);
37 
38 private:
39 			BString				fID;
40 			BString				fCode;
41 };
42 
43 
44 class LanguageListItemWithFlag : public LanguageListItem {
45 public:
46 								LanguageListItemWithFlag(const char* text,
47 									const char* id, const char* languageCode,
48 									const char* countryCode = NULL);
49 								LanguageListItemWithFlag(
50 									const LanguageListItemWithFlag& other);
51 	virtual						~LanguageListItemWithFlag();
52 
53 	virtual void				Update(BView* owner, const BFont* font);
54 
55 	virtual	void				DrawItem(BView* owner, BRect frame,
56 									bool complete = false);
57 
58 private:
59 			BString				fCountryCode;
60 			BBitmap*			fIcon;
61 };
62 
63 
64 class LanguageListView : public BOutlineListView {
65 public:
66 								LanguageListView(const char* name,
67 									list_view_type type);
68 	virtual						~LanguageListView();
69 
70 			LanguageListItem*	ItemForLanguageID(const char* code,
71 									int32* _index = NULL) const;
72 			LanguageListItem*	ItemForLanguageCode(const char* code,
73 									int32* _index = NULL) const;
74 
75 			void				SetDeleteMessage(BMessage* message);
76 			void				SetDragMessage(BMessage* message);
77 			void				SetGlobalDropTargetIndicator(bool isGlobal);
78 
79 	virtual	void				Draw(BRect updateRect);
80 	virtual	bool 				InitiateDrag(BPoint point, int32 index,
81 									bool wasSelected);
82 	virtual	void 				MouseMoved(BPoint where, uint32 transit,
83 									const BMessage* dragMessage);
84 	virtual void				MouseUp(BPoint point);
85 	virtual	void 				AttachedToWindow();
86 	virtual	void 				MessageReceived(BMessage* message);
87 	virtual	void				KeyDown(const char* bytes, int32 numBytes);
88 
89 private:
90 			bool				_AcceptsDragMessage(
91 									const BMessage* message) const;
92 
93 private:
94 			int32				fDropIndex;
95 			BRect				fDropTargetHighlightFrame;
96 			bool				fGlobalDropTargetIndicator;
97 			BMessage*			fDeleteMessage;
98 			BMessage*			fDragMessage;
99 };
100 
101 
102 #endif	// LANGUAGE_LIST_VIEW_H
103