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