1 /* 2 * Copyright 2004, Axel Dörfler, axeld@pinc-software.de. All rights reserved. 3 * Distributed under the terms of the MIT 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, int32 start, int32 end); 72 void DrawSelectionBlock(view_focus which); 73 void DrawSelection(bool frameOnly = false); 74 void SetActive(bool active); 75 void SetFocus(view_focus which); 76 77 void UpdateFromEditor(BMessage *message = NULL); 78 void ConvertLine(char *line, off_t offset, const uint8 *buffer, size_t size); 79 80 bool AcceptsDrop(const BMessage *message); 81 void InitiateDrag(view_focus focus); 82 void Copy(); 83 void Paste(); 84 85 DataEditor &fEditor; 86 int32 fPositionLength; 87 uint8 *fData; 88 size_t fDataSize; 89 off_t fFileSize; 90 size_t fSizeInView; 91 off_t fOffset; 92 float fAscent; 93 int32 fFontHeight; 94 float fCharWidth; 95 view_focus fFocus; 96 base_type fBase; 97 bool fIsActive; 98 int32 fStart, fEnd; 99 int32 fMouseSelectionStart; 100 int32 fKeySelectionStart; 101 int32 fBitPosition; 102 bool fFitFontSize; 103 int32 fDragMessageSize; 104 int32 fStoredStart, fStoredEnd; 105 }; 106 107 static const uint32 kMsgBaseType = 'base'; 108 static const uint32 kMsgUpdateData = 'updt'; 109 static const uint32 kMsgSetSelection = 'ssel'; 110 111 // observer notices 112 static const uint32 kDataViewCursorPosition = 'curs'; 113 static const uint32 kDataViewSelection = 'dsel'; 114 static const uint32 kDataViewPreferredSize = 'dvps'; 115 116 #endif /* DATA_VIEW_H */ 117