xref: /haiku/src/apps/charactermap/CharacterView.h (revision 342a1b221b5bb385410f758df2c625b70cafdd03)
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 <PopUpMenu.h>
11 #include <View.h>
12 
13 
14 class CharacterView : public BView {
15 public:
16 							CharacterView(const char* name);
17 	virtual					~CharacterView();
18 
19 			void			SetTarget(BMessenger target, uint32 command);
20 
21 			void			SetCharacterFont(const BFont& font);
22 			const BFont&	CharacterFont() { return fCharacterFont; }
23 
24 			void			ShowPrivateBlocks(bool show);
25 			bool			IsShowingPrivateBlocks() const
26 								{ return fShowPrivateBlocks; }
27 
28 			void			ShowContainedBlocksOnly(bool show);
29 			bool			IsShowingContainedBlocksOnly() const
30 								{ return fShowContainedBlocksOnly; }
31 
32 			bool			IsShowingBlock(int32 blockIndex) const;
33 
34 			void			ScrollToBlock(int32 blockIndex);
35 			void			ScrollToCharacter(uint32 c);
36 			bool			IsCharacterVisible(uint32 c) const;
37 			bool			IsBlockVisible(int32 block) const;
38 
39 	static	void			UnicodeToUTF8(uint32 c, char* text,
40 								size_t textSize);
41 	static	void			UnicodeToUTF8Hex(uint32 c, char* text,
42 								size_t textSize);
43 
44 protected:
45 	virtual void			MessageReceived(BMessage* message);
46 
47 	virtual	void			AttachedToWindow();
48 	virtual	void			DetachedFromWindow();
49 
50 	virtual	BSize			MinSize();
51 
52 	virtual void			FrameResized(float width, float height);
53 	virtual void			MouseDown(BPoint where);
54 	virtual void			MouseUp(BPoint where);
55 	virtual void			MouseMoved(BPoint where, uint32 transit,
56 								const BMessage* dragMessage);
57 
58 	virtual void			Draw(BRect updateRect);
59 
60 	virtual void			DoLayout();
61 
62 private:
63 			int32			_BlockAt(BPoint point) const;
64 			bool 			_GetCharacterAt(BPoint point, uint32& character,
65 								BRect* _frame = NULL) const;
66 			void			_UpdateFontSize();
67 			void			_UpdateSize();
68 			bool			_GetTopmostCharacter(uint32& character,
69 								int32& offset) const;
70 			BRect			_FrameFor(uint32 character) const;
71 			void			_CopyToClipboard(const char* text);
72 			bool			_HasGlyphForCharacter(const char* character) const;
73 
74 private:
75 			BMessenger		fTarget;
76 			uint32			fTargetCommand;
77 			BPoint			fClickPoint;
78 			bool			fHasCharacter;
79 			uint32			fCurrentCharacter;
80 			BRect			fCurrentCharacterFrame;
81 			bool			fHasTopCharacter;
82 			uint32			fTopCharacter;
83 			int32			fTopOffset;
84 			BPopUpMenu*		fMenu;
85 
86 			bool			fShowPrivateBlocks;
87 			bool			fShowContainedBlocksOnly;
88 
89 			BRect			fDataRect;
90 			BFont			fCharacterFont;
91 			int32			fCharactersPerLine;
92 			int32			fCharacterWidth;
93 			int32			fCharacterHeight;
94 			int32			fCharacterBase;
95 			int32			fTitleHeight;
96 			int32			fTitleBase;
97 			int32			fGap;
98 			int32			fTitleGap;
99 			int32*			fTitleTops;
100 			unicode_block	fUnicodeBlocks;
101 };
102 
103 #endif	// CHARACTER_VIEW_H
104