xref: /haiku/src/apps/charactermap/CharacterView.h (revision 53d31fb972311f2292d4098d81cb73acd3389dc7)
1 /*
2  * Copyright 2009, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
3  * Distributed under the terms of the MIT License.
4  */
5 #ifndef CHARACTER_VIEW_H
6 #define CHARACTER_VIEW_H
7 
8 
9 #include <Messenger.h>
10 #include <View.h>
11 
12 
13 class CharacterView : public BView {
14 public:
15 							CharacterView(const char* name);
16 	virtual					~CharacterView();
17 
18 			void			SetTarget(BMessenger target, uint32 command);
19 
20 			void			SetCharacterFont(const BFont& font);
21 			const BFont&	CharacterFont() { return fCharacterFont; }
22 
23 			void			ShowPrivateBlocks(bool show);
24 			bool			IsShowingPrivateBlocks() const
25 								{ return fShowPrivateBlocks; }
26 
27 			void			ShowContainedBlocksOnly(bool show);
28 			bool			IsShowingContainedBlocksOnly() const
29 								{ return fShowContainedBlocksOnly; }
30 
31 			bool			IsShowingBlock(int32 blockIndex) const;
32 
33 			void			ScrollTo(int32 blockIndex);
34 
35 	static	void			UnicodeToUTF8(uint32 c, char* text,
36 								size_t textSize);
37 	static	void			UnicodeToUTF8Hex(uint32 c, char* text,
38 								size_t textSize);
39 
40 protected:
41 	virtual	void			AttachedToWindow();
42 	virtual	void			DetachedFromWindow();
43 
44 	virtual	BSize			MinSize();
45 
46 	virtual void			FrameResized(float width, float height);
47 	virtual void			MouseDown(BPoint where);
48 	virtual void			MouseUp(BPoint where);
49 	virtual void			MouseMoved(BPoint where, uint32 transit,
50 								const BMessage* dragMessage);
51 
52 	virtual void			Draw(BRect updateRect);
53 
54 	virtual void			DoLayout();
55 
56 private:
57 			int32			_BlockAt(BPoint point);
58 			bool 			_GetCharacterAt(BPoint point, uint32& character,
59 								BRect* _frame = NULL);
60 			void			_UpdateSize();
61 
62 private:
63 			BMessenger		fTarget;
64 			uint32			fTargetCommand;
65 			BPoint			fClickPoint;
66 			bool			fHasCharacter;
67 			uint32			fCurrentCharacter;
68 			BRect			fCurrentCharacterFrame;
69 
70 			bool			fShowPrivateBlocks;
71 			bool			fShowContainedBlocksOnly;
72 
73 			BRect			fDataRect;
74 			BFont			fCharacterFont;
75 			int32			fCharactersPerLine;
76 			int32			fCharacterWidth;
77 			int32			fCharacterHeight;
78 			int32			fCharacterBase;
79 			int32			fTitleHeight;
80 			int32			fTitleBase;
81 			int32			fGap;
82 			int32			fTitleGap;
83 			int32*			fTitleTops;
84 };
85 
86 #endif	// CHARACTER_VIEW_H
87