1 /* 2 * Copyright 2004-2009, Axel Dörfler, axeld@pinc-software.de. 3 * Distributed under the terms of the MIT License. 4 */ 5 #ifndef DATA_VIEW_H 6 #define DATA_VIEW_H 7 8 9 #include <Path.h> 10 #include <String.h> 11 #include <View.h> 12 13 14 class DataEditor; 15 16 enum base_type { 17 kHexBase = 16, 18 kDecimalBase = 10 19 }; 20 21 enum view_focus { 22 kNoFocus, 23 kHexFocus, 24 kAsciiFocus 25 }; 26 27 class DataView : public BView { 28 public: 29 DataView(BRect rect, DataEditor& editor); 30 virtual ~DataView(); 31 32 virtual void DetachedFromWindow(); 33 virtual void AttachedToWindow(); 34 virtual void MessageReceived(BMessage* message); 35 virtual void Draw(BRect updateRect); 36 37 virtual void MouseDown(BPoint where); 38 virtual void MouseMoved(BPoint where, uint32 transit, 39 const BMessage* message); 40 virtual void MouseUp(BPoint where); 41 42 virtual void KeyDown(const char* bytes, int32 numBytes); 43 44 virtual void WindowActivated(bool active); 45 virtual void MakeFocus(bool focus); 46 virtual void FrameResized(float width, float height); 47 virtual void SetFont(const BFont* font, 48 uint32 properties = B_FONT_ALL); 49 virtual void GetPreferredSize(float* _width, float* _height); 50 51 bool FontSizeFitsBounds() const { return fFitFontSize; } 52 float FontSize() const; 53 void SetFontSize(float point); 54 55 void UpdateScroller(); 56 57 void MakeVisible(int32 position); 58 void SetSelection(int32 start, int32 end, 59 view_focus focus = kNoFocus); 60 void GetSelection(int32& start, int32& end); 61 void InvalidateRange(int32 start, int32 end); 62 63 base_type Base() const { return fBase; } 64 void SetBase(base_type type); 65 66 const uint8* DataAt(int32 start); 67 68 private: 69 BRect DataBounds(bool inView = false) const; 70 BRect SelectionFrame(view_focus which, int32 start, 71 int32 end); 72 int32 PositionAt(view_focus focus, BPoint point, 73 view_focus* _newFocus = NULL); 74 75 void DrawSelectionFrame(view_focus which); 76 void DrawSelectionBlock(view_focus which, int32 start, 77 int32 end); 78 void DrawSelectionBlock(view_focus which); 79 void DrawSelection(bool frameOnly = false); 80 void SetActive(bool active); 81 void SetFocus(view_focus which); 82 83 void UpdateFromEditor(BMessage* message = NULL); 84 void ConvertLine(char* line, off_t offset, 85 const uint8* buffer, size_t size); 86 87 bool AcceptsDrop(const BMessage* message); 88 void InitiateDrag(view_focus focus); 89 void Copy(); 90 void Paste(); 91 92 DataEditor& fEditor; 93 int32 fPositionLength; 94 uint8* fData; 95 size_t fDataSize; 96 off_t fFileSize; 97 size_t fSizeInView; 98 off_t fOffset; 99 float fAscent; 100 int32 fFontHeight; 101 float fCharWidth; 102 view_focus fFocus; 103 base_type fBase; 104 bool fIsActive; 105 int32 fStart, fEnd; 106 int32 fMouseSelectionStart; 107 int32 fKeySelectionStart; 108 int32 fBitPosition; 109 bool fFitFontSize; 110 int32 fDragMessageSize; 111 int32 fStoredStart, fStoredEnd; 112 }; 113 114 static const uint32 kMsgBaseType = 'base'; 115 static const uint32 kMsgUpdateData = 'updt'; 116 static const uint32 kMsgSetSelection = 'ssel'; 117 118 // observer notices 119 static const uint32 kDataViewCursorPosition = 'curs'; 120 static const uint32 kDataViewSelection = 'dsel'; 121 static const uint32 kDataViewPreferredSize = 'dvps'; 122 123 extern bool is_valid_utf8(uint8* data, size_t size); 124 125 #endif /* DATA_VIEW_H */ 126