btrfs: Attempt to fix GCC2 build.
[haiku.git] / src / apps / diskprobe / DataView.h
blobc48907f0f79f070491068b50fddc2ca24fb647fd
1 /*
2 * Copyright 2004-2015, 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
9 #include <Path.h>
10 #include <String.h>
11 #include <View.h>
14 class DataEditor;
17 enum base_type {
18 kHexBase = 16,
19 kDecimalBase = 10
23 enum view_focus {
24 kNoFocus,
25 kHexFocus,
26 kAsciiFocus
30 class DataView : public BView {
31 public:
32 DataView(DataEditor& editor);
33 virtual ~DataView();
35 virtual void DetachedFromWindow();
36 virtual void AttachedToWindow();
37 virtual void MessageReceived(BMessage* message);
38 virtual void Draw(BRect updateRect);
40 virtual void MouseDown(BPoint where);
41 virtual void MouseMoved(BPoint where, uint32 transit,
42 const BMessage* message);
43 virtual void MouseUp(BPoint where);
45 virtual void KeyDown(const char* bytes, int32 numBytes);
47 virtual void WindowActivated(bool active);
48 virtual void MakeFocus(bool focus);
49 virtual void FrameResized(float width, float height);
50 virtual void SetFont(const BFont* font,
51 uint32 properties = B_FONT_ALL);
52 virtual void GetPreferredSize(float* _width, float* _height);
54 bool FontSizeFitsBounds() const { return fFitFontSize; }
55 float FontSize() const;
56 void SetFontSize(float point);
58 void UpdateScroller();
60 void MakeVisible(int32 position);
61 void SetSelection(int32 start, int32 end,
62 view_focus focus = kNoFocus);
63 void GetSelection(int32& start, int32& end);
64 void InvalidateRange(int32 start, int32 end);
66 base_type Base() const { return fBase; }
67 void SetBase(base_type type);
69 const uint8* DataAt(int32 start);
71 static int32 WidthForFontSize(float size);
73 private:
74 BRect DataBounds(bool inView = false) const;
75 BRect SelectionFrame(view_focus which, int32 start,
76 int32 end);
77 int32 PositionAt(view_focus focus, BPoint point,
78 view_focus* _newFocus = NULL);
80 void DrawSelectionFrame(view_focus which);
81 void DrawSelectionBlock(view_focus which, int32 start,
82 int32 end);
83 void DrawSelectionBlock(view_focus which);
84 void DrawSelection(bool frameOnly = false);
85 void SetActive(bool active);
86 void SetFocus(view_focus which);
88 void UpdateFromEditor(BMessage* message = NULL);
89 void ConvertLine(char* line, off_t offset,
90 const uint8* buffer, size_t size);
92 bool AcceptsDrop(const BMessage* message);
93 void InitiateDrag(view_focus focus);
94 void Copy();
95 void Paste();
97 DataEditor& fEditor;
98 uint8* fData;
99 size_t fDataSize;
100 off_t fFileSize;
101 size_t fSizeInView;
102 off_t fOffset;
103 float fAscent;
104 int32 fFontHeight;
105 float fCharWidth;
106 view_focus fFocus;
107 base_type fBase;
108 bool fIsActive;
109 int32 fStart, fEnd;
110 int32 fMouseSelectionStart;
111 int32 fKeySelectionStart;
112 int32 fBitPosition;
113 bool fFitFontSize;
114 int32 fDragMessageSize;
115 int32 fStoredStart, fStoredEnd;
118 static const uint32 kMsgBaseType = 'base';
119 static const uint32 kMsgUpdateData = 'updt';
120 static const uint32 kMsgSetSelection = 'ssel';
122 // observer notices
123 static const uint32 kDataViewCursorPosition = 'curs';
124 static const uint32 kDataViewSelection = 'dsel';
125 static const uint32 kDataViewPreferredSize = 'dvps';
127 extern bool is_valid_utf8(uint8* data, size_t size);
129 #endif /* DATA_VIEW_H */