1 /* 2 ** Copyright 2004, Axel Dörfler, axeld@pinc-software.de. All rights reserved. 3 ** Distributed under the terms of the OpenBeOS License. 4 */ 5 #ifndef DATA_VIEW_H 6 #define DATA_VIEW_H 7 8 9 #include <View.h> 10 #include <String.h> 11 #include <Path.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, const BMessage *message); 39 virtual void MouseUp(BPoint where); 40 41 virtual void KeyDown(const char *bytes, int32 numBytes); 42 43 virtual void WindowActivated(bool active); 44 virtual void MakeFocus(bool focus); 45 virtual void FrameResized(float width, float height); 46 virtual void SetFont(const BFont *font, uint32 properties = B_FONT_ALL); 47 virtual void GetPreferredSize(float *_width, float *_height); 48 49 bool FontSizeFitsBounds() const { return fFitFontSize; } 50 float FontSize() const; 51 void SetFontSize(float point); 52 53 void UpdateScroller(); 54 55 void MakeVisible(int32 position); 56 void SetSelection(int32 start, int32 end, view_focus focus = kNoFocus); 57 void GetSelection(int32 &start, int32 &end); 58 void InvalidateRange(int32 start, int32 end); 59 60 base_type Base() const { return fBase; } 61 void SetBase(base_type type); 62 63 const uint8 *DataAt(int32 start); 64 65 private: 66 BRect DataBounds(bool inView = false) const; 67 BRect SelectionFrame(view_focus which, int32 start, int32 end); 68 int32 PositionAt(view_focus focus, BPoint point, view_focus *_newFocus = NULL); 69 70 void DrawSelectionFrame(view_focus which); 71 void DrawSelectionBlock(view_focus which); 72 void DrawSelection(); 73 void SetActive(bool active); 74 void SetFocus(view_focus which); 75 76 void UpdateFromEditor(BMessage *message = NULL); 77 void ConvertLine(char *line, off_t offset, const uint8 *buffer, size_t size); 78 79 void Copy(); 80 void Paste(); 81 82 DataEditor &fEditor; 83 int32 fPositionLength; 84 uint8 *fData; 85 size_t fDataSize; 86 off_t fFileSize; 87 size_t fSizeInView; 88 off_t fOffset; 89 float fAscent; 90 int32 fFontHeight; 91 float fCharWidth; 92 view_focus fFocus; 93 base_type fBase; 94 bool fIsActive; 95 int32 fStart, fEnd; 96 int32 fMouseSelectionStart; 97 int32 fBitPosition; 98 bool fFitFontSize; 99 }; 100 101 static const uint32 kMsgBaseType = 'base'; 102 static const uint32 kMsgUpdateData = 'updt'; 103 static const uint32 kMsgSetSelection = 'ssel'; 104 105 // observer notices 106 static const uint32 kDataViewCursorPosition = 'curs'; 107 static const uint32 kDataViewSelection = 'dsel'; 108 static const uint32 kDataViewPreferredSize = 'dvps'; 109 110 #endif /* DATA_VIEW_H */ 111