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