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 73 private: 74 BMessenger fTarget; 75 uint32 fTargetCommand; 76 BPoint fClickPoint; 77 bool fHasCharacter; 78 uint32 fCurrentCharacter; 79 BRect fCurrentCharacterFrame; 80 bool fHasTopCharacter; 81 uint32 fTopCharacter; 82 int32 fTopOffset; 83 BPopUpMenu* fMenu; 84 85 bool fShowPrivateBlocks; 86 bool fShowContainedBlocksOnly; 87 88 BRect fDataRect; 89 BFont fCharacterFont; 90 int32 fCharactersPerLine; 91 int32 fCharacterWidth; 92 int32 fCharacterHeight; 93 int32 fCharacterBase; 94 int32 fTitleHeight; 95 int32 fTitleBase; 96 int32 fGap; 97 int32 fTitleGap; 98 int32* fTitleTops; 99 unicode_block fUnicodeBlocks; 100 }; 101 102 #endif // CHARACTER_VIEW_H 103