xref: /haiku/src/apps/charactermap/CharacterView.h (revision 5e96d7d537fbec23bad4ae9b4c8e7b02e769f0c6)
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			ScrollToBlock(int32 blockIndex);
34 			void			ScrollToCharacter(uint32 c);
35 			bool			IsCharacterVisible(uint32 c) const;
36 
37 	static	void			UnicodeToUTF8(uint32 c, char* text,
38 								size_t textSize);
39 	static	void			UnicodeToUTF8Hex(uint32 c, char* text,
40 								size_t textSize);
41 
42 protected:
43 	virtual void			MessageReceived(BMessage* message);
44 
45 	virtual	void			AttachedToWindow();
46 	virtual	void			DetachedFromWindow();
47 
48 	virtual	BSize			MinSize();
49 
50 	virtual void			FrameResized(float width, float height);
51 	virtual void			MouseDown(BPoint where);
52 	virtual void			MouseUp(BPoint where);
53 	virtual void			MouseMoved(BPoint where, uint32 transit,
54 								const BMessage* dragMessage);
55 
56 	virtual void			Draw(BRect updateRect);
57 
58 	virtual void			DoLayout();
59 
60 private:
61 			int32			_BlockAt(BPoint point) const;
62 			bool 			_GetCharacterAt(BPoint point, uint32& character,
63 								BRect* _frame = NULL) const;
64 			void			_UpdateFontSize();
65 			void			_UpdateSize();
66 			bool			_GetTopmostCharacter(uint32& character,
67 								int32& offset) const;
68 			BRect			_FrameFor(uint32 character) const;
69 			void			_CopyToClipboard(const char* text);
70 
71 private:
72 			BMessenger		fTarget;
73 			uint32			fTargetCommand;
74 			BPoint			fClickPoint;
75 			bool			fHasCharacter;
76 			uint32			fCurrentCharacter;
77 			BRect			fCurrentCharacterFrame;
78 			bool			fHasTopCharacter;
79 			uint32			fTopCharacter;
80 			int32			fTopOffset;
81 
82 			bool			fShowPrivateBlocks;
83 			bool			fShowContainedBlocksOnly;
84 
85 			BRect			fDataRect;
86 			BFont			fCharacterFont;
87 			int32			fCharactersPerLine;
88 			int32			fCharacterWidth;
89 			int32			fCharacterHeight;
90 			int32			fCharacterBase;
91 			int32			fTitleHeight;
92 			int32			fTitleBase;
93 			int32			fGap;
94 			int32			fTitleGap;
95 			int32*			fTitleTops;
96 };
97 
98 #endif	// CHARACTER_VIEW_H
99