DiskProbe: Coding style cleanup

* Not complete, no functional changes intended.
This commit is contained in:
Axel Dörfler
2018-11-03 14:07:00 +00:00
parent 49135c955b
commit e85413ad6c
13 changed files with 568 additions and 479 deletions
+19 -15
View File
@@ -1,31 +1,35 @@
/* /*
** Copyright 2004, Axel Dörfler, [email protected]. All rights reserved. * Copyright 2004-2018, Axel Dörfler, [email protected].
** Distributed under the terms of the MIT License. * All rights reserved. Distributed under the terms of the MIT license.
*/ */
#ifndef ATTRIBUTE_WINDOW_H #ifndef ATTRIBUTE_WINDOW_H
#define ATTRIBUTE_WINDOW_H #define ATTRIBUTE_WINDOW_H
#include "ProbeWindow.h" #include "ProbeWindow.h"
class ProbeView; class ProbeView;
class TypeEditorView; class TypeEditorView;
class AttributeWindow : public ProbeWindow { class AttributeWindow : public ProbeWindow {
public: public:
AttributeWindow(BRect rect, entry_ref *ref, const char *attribute = NULL, AttributeWindow(BRect rect, entry_ref* ref,
const BMessage *settings = NULL); const char* attribute = NULL,
virtual ~AttributeWindow(); const BMessage* settings = NULL);
virtual ~AttributeWindow();
virtual void MessageReceived(BMessage *message); virtual void MessageReceived(BMessage* message);
virtual bool QuitRequested(); virtual bool QuitRequested();
virtual bool Contains(const entry_ref &ref, const char *attribute); virtual bool Contains(const entry_ref& ref,
const char* attribute);
private: private:
ProbeView *fProbeView; ProbeView* fProbeView;
TypeEditorView *fTypeEditorView; TypeEditorView* fTypeEditorView;
char *fAttribute; char* fAttribute;
}; };
#endif /* ATTRIBUTE_WINDOW_H */ #endif /* ATTRIBUTE_WINDOW_H */
+97 -75
View File
@@ -1,6 +1,6 @@
/* /*
* Copyright 2004-2007, Axel Dörfler, [email protected]. All rights reserved. * Copyright 2004-2018, Axel Dörfler, [email protected].
* Distributed under the terms of the MIT License. * All rights reserved. Distributed under the terms of the MIT license.
*/ */
#ifndef DATA_EDITOR_H #ifndef DATA_EDITOR_H
#define DATA_EDITOR_H #define DATA_EDITOR_H
@@ -11,6 +11,7 @@
#include <Locker.h> #include <Locker.h>
#include <ObjectList.h> #include <ObjectList.h>
class BHandler; class BHandler;
class BLooper; class BLooper;
class BMessage; class BMessage;
@@ -21,109 +22,130 @@ class StateWatcher;
class DataEditor : public BLocker { class DataEditor : public BLocker {
public: public:
DataEditor(); DataEditor();
DataEditor(entry_ref &ref, const char *attribute = NULL); DataEditor(entry_ref& ref,
DataEditor(BEntry &entry, const char *attribute = NULL); const char* attribute = NULL);
DataEditor(const DataEditor &editor); DataEditor(BEntry& entry,
~DataEditor(); const char* attribute = NULL);
DataEditor(const DataEditor& editor);
virtual ~DataEditor();
status_t SetTo(const char *path, const char *attribute = NULL); status_t SetTo(const char* path,
status_t SetTo(entry_ref &ref, const char *attribute = NULL); const char* attribute = NULL);
status_t SetTo(BEntry &entry, const char *attribute = NULL); status_t SetTo(entry_ref &ref,
const char* attribute = NULL);
status_t SetTo(BEntry &entry,
const char* attribute = NULL);
status_t Save(); status_t Save();
bool IsReadOnly() const { return fIsReadOnly; } bool IsReadOnly() const { return fIsReadOnly; }
bool IsDevice() const { return fIsDevice; } bool IsDevice() const { return fIsDevice; }
bool IsAttribute() const { return fAttribute != NULL; } bool IsAttribute() const
bool IsModified() const { return fLastChange != fFirstChange; } { return fAttribute != NULL; }
bool IsModified() const
{ return fLastChange != fFirstChange; }
const char *Attribute() const { return fAttribute; } const char* Attribute() const { return fAttribute; }
type_code Type() const { return fType; } type_code Type() const { return fType; }
status_t InitCheck(); status_t InitCheck();
status_t Replace(off_t offset, const uint8 *data, size_t length); status_t Replace(off_t offset, const uint8* data,
status_t Remove(off_t offset, off_t length); size_t length);
status_t Insert(off_t offset, const uint8 *data, size_t length); status_t Remove(off_t offset, off_t length);
status_t Insert(off_t offset, const uint8* data,
size_t length);
status_t MoveBy(int32 bytes); status_t MoveBy(int32 bytes);
status_t MoveTo(off_t offset); status_t MoveTo(off_t offset);
status_t Undo(); status_t Undo();
status_t Redo(); status_t Redo();
bool CanUndo() const; bool CanUndo() const;
bool CanRedo() const; bool CanRedo() const;
status_t SetFileSize(off_t size); status_t SetFileSize(off_t size);
off_t FileSize() const { return fSize; } off_t FileSize() const { return fSize; }
status_t SetViewOffset(off_t offset); status_t SetViewOffset(off_t offset);
off_t ViewOffset() const { return fViewOffset; } off_t ViewOffset() const { return fViewOffset; }
status_t SetViewSize(size_t size); status_t SetViewSize(size_t size);
size_t ViewSize() const { return fViewSize; } size_t ViewSize() const { return fViewSize; }
status_t SetBlockSize(size_t size); status_t SetBlockSize(size_t size);
size_t BlockSize() const { return fBlockSize; } size_t BlockSize() const { return fBlockSize; }
status_t UpdateIfNeeded(bool *_updated = NULL); status_t UpdateIfNeeded(bool* _updated = NULL);
status_t ForceUpdate(); status_t ForceUpdate();
status_t GetViewBuffer(const uint8 **_buffer); status_t GetViewBuffer(const uint8** _buffer);
status_t StartWatching(BMessenger target); status_t StartWatching(BMessenger target);
status_t StartWatching(BHandler *handler, BLooper *looper = NULL); status_t StartWatching(BHandler* handler,
void StopWatching(BMessenger target); BLooper* looper = NULL);
void StopWatching(BHandler *handler, BLooper *looper = NULL); void StopWatching(BMessenger target);
void StopWatching(BHandler* handler,
BLooper* looper = NULL);
off_t Find(off_t startPosition, const uint8 *data, size_t dataSize, off_t Find(off_t startPosition, const uint8* data,
bool caseInsensitive, bool cyclic, size_t dataSize, bool caseInsensitive,
BMessenger progressMessenger, volatile bool *stop = NULL); bool cyclic, BMessenger progressMessenger,
volatile bool* stop = NULL);
BFile &File() { return fFile; } BFile& File() { return fFile; }
const entry_ref &AttributeRef() const { return fAttributeRef; } const entry_ref& AttributeRef() const { return fAttributeRef; }
const entry_ref &Ref() const { return fRef; } const entry_ref& Ref() const { return fRef; }
private: private:
friend class StateWatcher; friend class StateWatcher;
status_t SetViewOffset(off_t offset, bool sendNotices); status_t SetViewOffset(off_t offset, bool sendNotices);
status_t SetViewSize(size_t size, bool sendNotices); status_t SetViewSize(size_t size, bool sendNotices);
void SendNotices(uint32 what, BMessage *message = NULL); void SendNotices(uint32 what,
void SendNotices(DataChange *change); BMessage* message = NULL);
status_t Update(); void SendNotices(DataChange* change);
void AddChange(DataChange *change); status_t Update();
void ApplyChanges(); void AddChange(DataChange* change);
void RemoveRedos(); void ApplyChanges();
void RemoveRedos();
BObjectList<BMessenger> fObservers; private:
BObjectList<BMessenger> fObservers;
entry_ref fRef, fAttributeRef; entry_ref fRef;
BFile fFile; entry_ref fAttributeRef;
const char *fAttribute; BFile fFile;
type_code fType; const char* fAttribute;
bool fIsDevice, fIsReadOnly; type_code fType;
off_t fRealSize, fSize; bool fIsDevice;
bool fIsReadOnly;
off_t fRealSize;
off_t fSize;
BObjectList<DataChange> fChanges; BObjectList<DataChange> fChanges;
DataChange *fFirstChange; DataChange* fFirstChange;
DataChange *fLastChange; DataChange* fLastChange;
int32 fChangesFromSaved; int32 fChangesFromSaved;
uint8 *fView; uint8* fView;
off_t fRealViewOffset, fViewOffset; off_t fRealViewOffset;
size_t fRealViewSize, fViewSize; off_t fViewOffset;
bool fNeedsUpdate; size_t fRealViewSize;
size_t fViewSize;
bool fNeedsUpdate;
size_t fBlockSize; size_t fBlockSize;
}; };
static const uint32 kMsgDataEditorStateChange = 'deSC'; static const uint32 kMsgDataEditorStateChange = 'deSC';
static const uint32 kMsgDataEditorUpdate = 'deUp'; static const uint32 kMsgDataEditorUpdate = 'deUp';
static const uint32 kMsgDataEditorParameterChange = 'dePC'; static const uint32 kMsgDataEditorParameterChange = 'dePC';
static const uint32 kMsgDataEditorFindProgress = 'deFP'; static const uint32 kMsgDataEditorFindProgress = 'deFP';
#endif /* DATA_EDITOR_H */ #endif /* DATA_EDITOR_H */
+75 -69
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright 2004-2015, Axel Dörfler, [email protected]. * Copyright 2004-2018, Axel Dörfler, [email protected].
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*/ */
#ifndef DATA_VIEW_H #ifndef DATA_VIEW_H
@@ -29,92 +29,97 @@ enum view_focus {
class DataView : public BView { class DataView : public BView {
public: public:
DataView(DataEditor& editor); DataView(DataEditor& editor);
virtual ~DataView(); virtual ~DataView();
virtual void DetachedFromWindow(); virtual void DetachedFromWindow();
virtual void AttachedToWindow(); virtual void AttachedToWindow();
virtual void MessageReceived(BMessage* message); virtual void MessageReceived(BMessage* message);
virtual void Draw(BRect updateRect); virtual void Draw(BRect updateRect);
virtual void MouseDown(BPoint where); virtual void MouseDown(BPoint where);
virtual void MouseMoved(BPoint where, uint32 transit, virtual void MouseMoved(BPoint where, uint32 transit,
const BMessage* message); const BMessage* message);
virtual void MouseUp(BPoint where); virtual void MouseUp(BPoint where);
virtual void KeyDown(const char* bytes, int32 numBytes); virtual void KeyDown(const char* bytes, int32 numBytes);
virtual void WindowActivated(bool active); virtual void WindowActivated(bool active);
virtual void MakeFocus(bool focus); virtual void MakeFocus(bool focus);
virtual void FrameResized(float width, float height); virtual void FrameResized(float width, float height);
virtual void SetFont(const BFont* font, virtual void SetFont(const BFont* font,
uint32 properties = B_FONT_ALL); uint32 properties = B_FONT_ALL);
virtual void GetPreferredSize(float* _width, float* _height); virtual void GetPreferredSize(float* _width, float* _height);
bool FontSizeFitsBounds() const { return fFitFontSize; } bool FontSizeFitsBounds() const
float FontSize() const; { return fFitFontSize; }
void SetFontSize(float point); float FontSize() const;
void SetFontSize(float point);
void UpdateScroller(); void UpdateScroller();
void MakeVisible(int32 position); void MakeVisible(int32 position);
void SetSelection(int32 start, int32 end, void SetSelection(int32 start, int32 end,
view_focus focus = kNoFocus); view_focus focus = kNoFocus);
void GetSelection(int32& start, int32& end); void GetSelection(int32& start, int32& end);
void InvalidateRange(int32 start, int32 end); void InvalidateRange(int32 start, int32 end);
base_type Base() const { return fBase; } base_type Base() const { return fBase; }
void SetBase(base_type type); void SetBase(base_type type);
const uint8* DataAt(int32 start); const uint8* DataAt(int32 start);
static int32 WidthForFontSize(float size); static int32 WidthForFontSize(float size);
private: private:
BRect DataBounds(bool inView = false) const; BRect DataBounds(bool inView = false) const;
BRect SelectionFrame(view_focus which, int32 start, BRect SelectionFrame(view_focus which, int32 start,
int32 end); int32 end);
int32 PositionAt(view_focus focus, BPoint point, int32 PositionAt(view_focus focus, BPoint point,
view_focus* _newFocus = NULL); view_focus* _newFocus = NULL);
void DrawSelectionFrame(view_focus which); void DrawSelectionFrame(view_focus which);
void DrawSelectionBlock(view_focus which, int32 start, void DrawSelectionBlock(view_focus which,
int32 end); int32 start, int32 end);
void DrawSelectionBlock(view_focus which); void DrawSelectionBlock(view_focus which);
void DrawSelection(bool frameOnly = false); void DrawSelection(bool frameOnly = false);
void SetActive(bool active); void SetActive(bool active);
void SetFocus(view_focus which); void SetFocus(view_focus which);
void UpdateFromEditor(BMessage* message = NULL); void UpdateFromEditor(BMessage* message = NULL);
void ConvertLine(char* line, off_t offset, void ConvertLine(char* line, off_t offset,
const uint8* buffer, size_t size); const uint8* buffer, size_t size);
bool AcceptsDrop(const BMessage* message); bool AcceptsDrop(const BMessage* message);
void InitiateDrag(view_focus focus); void InitiateDrag(view_focus focus);
void Copy(); void Copy();
void Paste(); void Paste();
DataEditor& fEditor; private:
uint8* fData; DataEditor& fEditor;
size_t fDataSize; uint8* fData;
off_t fFileSize; size_t fDataSize;
size_t fSizeInView; off_t fFileSize;
off_t fOffset; size_t fSizeInView;
float fAscent; off_t fOffset;
int32 fFontHeight; float fAscent;
float fCharWidth; int32 fFontHeight;
view_focus fFocus; float fCharWidth;
base_type fBase; view_focus fFocus;
bool fIsActive; base_type fBase;
int32 fStart, fEnd; bool fIsActive;
int32 fMouseSelectionStart; int32 fStart;
int32 fKeySelectionStart; int32 fEnd;
int32 fBitPosition; int32 fMouseSelectionStart;
bool fFitFontSize; int32 fKeySelectionStart;
int32 fDragMessageSize; int32 fBitPosition;
int32 fStoredStart, fStoredEnd; bool fFitFontSize;
int32 fDragMessageSize;
int32 fStoredStart;
int32 fStoredEnd;
}; };
static const uint32 kMsgBaseType = 'base'; static const uint32 kMsgBaseType = 'base';
static const uint32 kMsgUpdateData = 'updt'; static const uint32 kMsgUpdateData = 'updt';
static const uint32 kMsgSetSelection = 'ssel'; static const uint32 kMsgSetSelection = 'ssel';
@@ -126,4 +131,5 @@ static const uint32 kDataViewPreferredSize = 'dvps';
extern bool is_valid_utf8(uint8* data, size_t size); extern bool is_valid_utf8(uint8* data, size_t size);
#endif /* DATA_VIEW_H */ #endif /* DATA_VIEW_H */
+62 -58
View File
@@ -1,6 +1,6 @@
/* /*
* Copyright 2004-2015, Axel Dörfler, [email protected]. * Copyright 2004-2018, Axel Dörfler, [email protected].
* Distributed under the terms of the MIT License. * All rights reserved. Distributed under the terms of the MIT license.
*/ */
@@ -36,7 +36,7 @@
#define B_TRANSLATION_CONTEXT "DiskProbe" #define B_TRANSLATION_CONTEXT "DiskProbe"
const char *kSignature = "application/x-vnd.Haiku-DiskProbe"; const char* kSignature = "application/x-vnd.Haiku-DiskProbe";
static const uint32 kMsgDiskProbeSettings = 'DPst'; static const uint32 kMsgDiskProbeSettings = 'DPst';
static const uint32 kCascadeOffset = 20; static const uint32 kCascadeOffset = 20;
@@ -51,50 +51,54 @@ struct disk_probe_settings {
enum disk_probe_flags { enum disk_probe_flags {
kCaseSensitive = 0x01, // this flag alone is R5 DiskProbe settings compatible kCaseSensitive = 0x01,
// this flag alone is R5 DiskProbe settings compatible
kHexFindMode = 0x02, kHexFindMode = 0x02,
}; };
class Settings { class Settings {
public: public:
Settings(); Settings();
~Settings(); ~Settings();
const BMessage &Message() const { return fMessage; } const BMessage& Message() const { return fMessage; }
void UpdateFrom(BMessage *message); void UpdateFrom(BMessage* message);
private: private:
status_t Open(BFile *file, int32 mode); status_t Open(BFile* file, int32 mode);
BMessage fMessage; private:
bool fUpdated; BMessage fMessage;
bool fUpdated;
}; };
class DiskProbe : public BApplication { class DiskProbe : public BApplication {
public: public:
DiskProbe(); DiskProbe();
virtual ~DiskProbe(); virtual ~DiskProbe();
virtual void ReadyToRun(); virtual void ReadyToRun();
virtual void RefsReceived(BMessage *message); virtual void RefsReceived(BMessage* message);
virtual void ArgvReceived(int32 argc, char **argv); virtual void ArgvReceived(int32 argc, char** argv);
virtual void MessageReceived(BMessage *message); virtual void MessageReceived(BMessage* message);
virtual bool QuitRequested(); virtual bool QuitRequested();
private: private:
status_t Probe(BEntry &entry, const char *attribute = NULL); status_t Probe(BEntry& entry,
const char* attribute = NULL);
Settings fSettings; private:
BFilePanel *fFilePanel; Settings fSettings;
BWindow *fOpenWindow; BFilePanel* fFilePanel;
FindWindow *fFindWindow; BWindow* fOpenWindow;
uint32 fWindowCount; FindWindow* fFindWindow;
BRect fWindowFrame; uint32 fWindowCount;
BMessenger fFindTarget; BRect fWindowFrame;
BMessenger fFindTarget;
}; };
@@ -123,7 +127,7 @@ Settings::Settings()
if (Open(&file, B_READ_ONLY) != B_OK) if (Open(&file, B_READ_ONLY) != B_OK)
return; return;
// ToDo: load/save settings as flattened BMessage - but not yet, // TODO: load/save settings as flattened BMessage - but not yet,
// since that will break compatibility with R5's DiskProbe // since that will break compatibility with R5's DiskProbe
disk_probe_settings settings; disk_probe_settings settings;
@@ -200,7 +204,7 @@ Settings::~Settings()
status_t status_t
Settings::Open(BFile *file, int32 mode) Settings::Open(BFile* file, int32 mode)
{ {
BPath path; BPath path;
if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) != B_OK) if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) != B_OK)
@@ -213,7 +217,7 @@ Settings::Open(BFile *file, int32 mode)
void void
Settings::UpdateFrom(BMessage *message) Settings::UpdateFrom(BMessage* message)
{ {
BRect frame; BRect frame;
if (message->FindRect("window_frame", &frame) == B_OK) if (message->FindRect("window_frame", &frame) == B_OK)
@@ -271,27 +275,26 @@ DiskProbe::ReadyToRun()
} }
/** Opens a window containing the file pointed to by the entry_ref. /*! Opens a window containing the file pointed to by the entry_ref.
* This function will fail if that file doesn't exist or could not This function will fail if that file doesn't exist or could not
* be opened. be opened.
* It will check if there already is a window that probes the It will check if there already is a window that probes the
* file in question and will activate it in that case. file in question and will activate it in that case.
* This function must be called with the application looper locked. This function must be called with the application looper locked.
*/ */
status_t status_t
DiskProbe::Probe(BEntry &entry, const char *attribute) DiskProbe::Probe(BEntry& entry, const char* attribute)
{ {
entry_ref ref; entry_ref ref;
status_t status = entry.GetRef(&ref); status_t status = entry.GetRef(&ref);
if (status < B_OK) if (status < B_OK)
return status; return status;
ProbeWindow *lastWindow(NULL); ProbeWindow* lastWindow(NULL);
// Do we already have that window open? // Do we already have that window open?
for (int32 i = CountWindows(); i-- > 0; ) { for (int32 i = CountWindows(); i-- > 0; ) {
ProbeWindow *window = dynamic_cast<ProbeWindow *>(WindowAt(i)); ProbeWindow* window = dynamic_cast<ProbeWindow*>(WindowAt(i));
if (window == NULL) if (window == NULL)
continue; continue;
@@ -318,16 +321,17 @@ DiskProbe::Probe(BEntry &entry, const char *attribute)
rect.OffsetBy(kCascadeOffset, kCascadeOffset); rect.OffsetBy(kCascadeOffset, kCascadeOffset);
BWindow *window; BWindow* window;
if (attribute != NULL) if (attribute != NULL) {
window = new AttributeWindow(rect, &ref, attribute, &fSettings.Message()); window = new AttributeWindow(rect, &ref, attribute,
else &fSettings.Message());
} else
window = new FileWindow(rect, &ref, &fSettings.Message()); window = new FileWindow(rect, &ref, &fSettings.Message());
window->Show(); window->Show();
/* adjust the cascading... we can only do this after the window was created // Adjust the cascading... we can only do this after the window was created
* to adjust to the real size */ // to adjust to the real size.
rect.right = window->Frame().right; rect.right = window->Frame().right;
rect.bottom = window->Frame().bottom; rect.bottom = window->Frame().bottom;
@@ -352,14 +356,14 @@ DiskProbe::Probe(BEntry &entry, const char *attribute)
void void
DiskProbe::RefsReceived(BMessage *message) DiskProbe::RefsReceived(BMessage* message)
{ {
bool traverseLinks = (modifiers() & B_SHIFT_KEY) == 0; bool traverseLinks = (modifiers() & B_SHIFT_KEY) == 0;
int32 index = 0; int32 index = 0;
entry_ref ref; entry_ref ref;
while (message->FindRef("refs", index++, &ref) == B_OK) { while (message->FindRef("refs", index++, &ref) == B_OK) {
const char *attribute = NULL; const char* attribute = NULL;
if (message->FindString("attributes", index - 1, &attribute) == B_OK) if (message->FindString("attributes", index - 1, &attribute) == B_OK)
traverseLinks = false; traverseLinks = false;
@@ -389,9 +393,9 @@ DiskProbe::RefsReceived(BMessage *message)
void void
DiskProbe::ArgvReceived(int32 argc, char **argv) DiskProbe::ArgvReceived(int32 argc, char** argv)
{ {
BMessage *message = CurrentMessage(); BMessage* message = CurrentMessage();
BDirectory currentDirectory; BDirectory currentDirectory;
if (message) if (message)
@@ -425,7 +429,7 @@ DiskProbe::ArgvReceived(int32 argc, char **argv)
void void
DiskProbe::MessageReceived(BMessage *message) DiskProbe::MessageReceived(BMessage* message)
{ {
switch (message->what) { switch (message->what) {
case kMsgOpenOpenWindow: case kMsgOpenOpenWindow:
@@ -472,8 +476,8 @@ DiskProbe::MessageReceived(BMessage *message)
if (fFindWindow == NULL) { if (fFindWindow == NULL) {
// open it! // open it!
fFindWindow = new FindWindow(fWindowFrame.OffsetByCopy(80, 80), *message, fFindWindow = new FindWindow(fWindowFrame.OffsetByCopy(80, 80),
target, &fSettings.Message()); *message, target, &fSettings.Message());
fFindWindow->Show(); fFindWindow->Show();
} else } else
fFindWindow->Activate(); fFindWindow->Activate();
@@ -506,7 +510,7 @@ DiskProbe::QuitRequested()
int int
main(int argc, char **argv) main(int argc, char** argv)
{ {
DiskProbe probe; DiskProbe probe;
+6 -5
View File
@@ -1,7 +1,7 @@
/* /*
** Copyright 2004, Axel Dörfler, [email protected]. All rights reserved. * Copyright 2004-2018, Axel Dörfler, [email protected].
** Distributed under the terms of the MIT License. * All rights reserved. Distributed under the terms of the MIT license.
*/ */
#ifndef DISK_PROBE_H #ifndef DISK_PROBE_H
#define DISK_PROBE_H #define DISK_PROBE_H
@@ -9,7 +9,7 @@
#include <SupportDefs.h> #include <SupportDefs.h>
extern const char *kSignature; extern const char* kSignature;
static const uint32 kMsgOpenFilePanel = 'opFp'; static const uint32 kMsgOpenFilePanel = 'opFp';
static const uint32 kMsgOpenOpenWindow = 'opOw'; static const uint32 kMsgOpenOpenWindow = 'opOw';
@@ -22,4 +22,5 @@ static const uint32 kMsgFindWindowClosed = 'clFw';
static const uint32 kMsgFindTarget = 'FTgt'; static const uint32 kMsgFindTarget = 'FTgt';
static const uint32 kMsgFind = 'find'; static const uint32 kMsgFind = 'find';
#endif /* DISK_PROBE_H */ #endif /* DISK_PROBE_H */
+14 -10
View File
@@ -1,25 +1,29 @@
/* /*
** Copyright 2004, Axel Dörfler, [email protected]. All rights reserved. * Copyright 2004-2018, Axel Dörfler, [email protected].
** Distributed under the terms of the MIT License. * All rights reserved. Distributed under the terms of the MIT license.
*/ */
#ifndef FILE_WINDOW_H #ifndef FILE_WINDOW_H
#define FILE_WINDOW_H #define FILE_WINDOW_H
#include "ProbeWindow.h" #include "ProbeWindow.h"
class ProbeView; class ProbeView;
class FileWindow : public ProbeWindow { class FileWindow : public ProbeWindow {
public: public:
FileWindow(BRect rect, entry_ref *ref, const BMessage *settings = NULL); FileWindow(BRect rect, entry_ref* ref,
const BMessage* settings = NULL);
virtual bool QuitRequested(); virtual bool QuitRequested();
virtual bool Contains(const entry_ref &ref, const char *attribute); virtual bool Contains(const entry_ref& ref,
const char* attribute);
private: private:
ProbeView *fProbeView; ProbeView* fProbeView;
}; };
#endif /* FILE_WINDOW_H */ #endif /* FILE_WINDOW_H */
+19 -16
View File
@@ -1,6 +1,6 @@
/* /*
* Copyright 2004-2006, Axel Dörfler, [email protected]. All rights reserved. * Copyright 2004-2018, Axel Dörfler, [email protected].
* Distributed under the terms of the MIT License. * All rights reserved. Distributed under the terms of the MIT license.
*/ */
#ifndef FIND_WINDOW_H #ifndef FIND_WINDOW_H
#define FIND_WINDOW_H #define FIND_WINDOW_H
@@ -9,6 +9,7 @@
#include <Window.h> #include <Window.h>
#include <Messenger.h> #include <Messenger.h>
class BCheckBox; class BCheckBox;
class BMenu; class BMenu;
@@ -22,23 +23,25 @@ enum find_mode {
class FindWindow : public BWindow { class FindWindow : public BWindow {
public: public:
FindWindow(BRect rect, BMessage &previous, BMessenger &target, FindWindow(BRect rect, BMessage& previous,
const BMessage *settings = NULL); BMessenger& target,
virtual ~FindWindow(); const BMessage* settings = NULL);
virtual ~FindWindow();
virtual void WindowActivated(bool active); virtual void WindowActivated(bool active);
virtual void MessageReceived(BMessage *message); virtual void MessageReceived(BMessage* message);
virtual bool QuitRequested(); virtual bool QuitRequested();
virtual void Show(); virtual void Show();
void SetTarget(BMessenger &target); void SetTarget(BMessenger& target);
private: private:
BMessenger fTarget; BMessenger fTarget;
FindTextView *fTextView; FindTextView* fTextView;
BCheckBox *fCaseCheckBox; BCheckBox* fCaseCheckBox;
BMenu *fMenu; BMenu* fMenu;
}; };
#endif /* FIND_WINDOW_H */ #endif /* FIND_WINDOW_H */
+4 -2
View File
@@ -1,6 +1,6 @@
/* /*
* Copyright 2004-2006, Axel Dörfler, [email protected]. All rights reserved. * Copyright 2004-2018, Axel Dörfler, [email protected].
* Distributed under the terms of the MIT License. * All rights reserved. Distributed under the terms of the MIT license.
*/ */
#ifndef OPEN_WINDOW_H #ifndef OPEN_WINDOW_H
#define OPEN_WINDOW_H #define OPEN_WINDOW_H
@@ -8,6 +8,7 @@
#include <Window.h> #include <Window.h>
class BEntry; class BEntry;
class BMenu; class BMenu;
@@ -27,4 +28,5 @@ private:
BMenu* fDevicesMenu; BMenu* fDevicesMenu;
}; };
#endif /* OPEN_WINDOW_H */ #endif /* OPEN_WINDOW_H */
+170 -153
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright 2004-2015, Axel Dörfler, [email protected]. * Copyright 2004-2018, Axel Dörfler, [email protected].
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*/ */
@@ -73,138 +73,148 @@ static const uint32 kMsgStopFind = 'sfnd';
class IconView : public BView { class IconView : public BView {
public: public:
IconView(const entry_ref *ref, bool isDevice); IconView(const entry_ref* ref, bool isDevice);
virtual ~IconView(); virtual ~IconView();
virtual void AttachedToWindow(); virtual void AttachedToWindow();
virtual void Draw(BRect updateRect); virtual void Draw(BRect updateRect);
void UpdateIcon(); void UpdateIcon();
private: private:
entry_ref fRef; entry_ref fRef;
bool fIsDevice; bool fIsDevice;
BBitmap *fBitmap; BBitmap* fBitmap;
}; };
class PositionSlider : public BSlider { class PositionSlider : public BSlider {
public: public:
PositionSlider(const char *name, BMessage *message, off_t size, PositionSlider(const char* name,
uint32 blockSize); BMessage* message, off_t size,
virtual ~PositionSlider(); uint32 blockSize);
virtual ~PositionSlider();
#ifdef DRAW_SLIDER_BAR #ifdef DRAW_SLIDER_BAR
virtual void DrawBar(); virtual void DrawBar();
#endif #endif
off_t Position() const; off_t Position() const;
off_t Size() const { return fSize; } off_t Size() const { return fSize; }
uint32 BlockSize() const { return fBlockSize; } uint32 BlockSize() const { return fBlockSize; }
virtual void SetPosition(float position); virtual void SetPosition(float position);
void SetPosition(off_t position); void SetPosition(off_t position);
void SetSize(off_t size); void SetSize(off_t size);
void SetBlockSize(uint32 blockSize); void SetBlockSize(uint32 blockSize);
private: private:
void Reset(); void Reset();
static const int32 kMaxSliderLimit = 0x7fffff80; private:
// this is the maximum value that BSlider seem to work with fine static const int32 kMaxSliderLimit = 0x7fffff80;
// this is the maximum value that BSlider seem to work with fine
off_t fSize; off_t fSize;
uint32 fBlockSize; uint32 fBlockSize;
}; };
class HeaderView : public BGridView, public BInvoker { class HeaderView : public BGridView, public BInvoker {
public: public:
HeaderView(const entry_ref *ref, DataEditor &editor); HeaderView(const entry_ref* ref,
virtual ~HeaderView(); DataEditor& editor);
virtual ~HeaderView();
virtual void AttachedToWindow(); virtual void AttachedToWindow();
virtual void DetachedFromWindow(); virtual void DetachedFromWindow();
virtual void MessageReceived(BMessage *message); virtual void MessageReceived(BMessage* message);
base_type Base() const { return fBase; } base_type Base() const { return fBase; }
void SetBase(base_type); void SetBase(base_type);
off_t CursorOffset() const { return fPosition % fBlockSize; } off_t CursorOffset() const
off_t Position() const { return fPosition; } { return fPosition % fBlockSize; }
uint32 BlockSize() const { return fBlockSize; } off_t Position() const { return fPosition; }
void SetTo(off_t position, uint32 blockSize); uint32 BlockSize() const { return fBlockSize; }
void SetTo(off_t position, uint32 blockSize);
void UpdateIcon(); void UpdateIcon();
private: private:
void FormatValue(char *buffer, size_t bufferSize, off_t value); void FormatValue(char* buffer, size_t bufferSize,
void UpdatePositionViews(bool all = true); off_t value);
void UpdateOffsetViews(bool all = true); void UpdatePositionViews(bool all = true);
void UpdateFileSizeView(); void UpdateOffsetViews(bool all = true);
void NotifyTarget(); void UpdateFileSizeView();
void NotifyTarget();
const char *fAttribute; private:
off_t fFileSize; const char* fAttribute;
uint32 fBlockSize; off_t fFileSize;
base_type fBase; uint32 fBlockSize;
off_t fPosition; base_type fBase;
off_t fLastPosition; off_t fPosition;
off_t fLastPosition;
BTextControl *fTypeControl; BTextControl* fTypeControl;
BTextControl *fPositionControl; BTextControl* fPositionControl;
BStringView *fPathView; BStringView* fPathView;
BStringView *fSizeView; BStringView* fSizeView;
BTextControl *fOffsetControl; BTextControl* fOffsetControl;
BTextControl *fFileOffsetControl; BTextControl* fFileOffsetControl;
PositionSlider *fPositionSlider; PositionSlider* fPositionSlider;
IconView *fIconView; IconView* fIconView;
BButton *fStopButton; BButton* fStopButton;
}; };
class TypeMenuItem : public BMenuItem { class TypeMenuItem : public BMenuItem {
public: public:
TypeMenuItem(const char *name, const char *type, BMessage *message); TypeMenuItem(const char* name, const char* type,
BMessage* message);
virtual void GetContentSize(float *_width, float *_height); virtual void GetContentSize(float* _width, float* _height);
virtual void DrawContent(); virtual void DrawContent();
private: private:
BString fType; BString fType;
}; };
class EditorLooper : public BLooper { class EditorLooper : public BLooper {
public: public:
EditorLooper(const char *name, DataEditor &editor, BMessenger messenger); EditorLooper(const char* name,
virtual ~EditorLooper(); DataEditor& editor, BMessenger messenger);
virtual ~EditorLooper();
virtual void MessageReceived(BMessage *message); virtual void MessageReceived(BMessage* message);
bool FindIsRunning() const { return !fQuitFind; } bool FindIsRunning() const { return !fQuitFind; }
void Find(off_t startAt, const uint8 *data, size_t dataSize, void Find(off_t startAt, const uint8* data,
bool caseInsensitive, BMessenger progressMonitor); size_t dataSize, bool caseInsensitive,
void QuitFind(); BMessenger progressMonitor);
void QuitFind();
private: private:
DataEditor &fEditor; DataEditor& fEditor;
BMessenger fMessenger; BMessenger fMessenger;
volatile bool fQuitFind; volatile bool fQuitFind;
}; };
class TypeView : public BView { class TypeView : public BView {
public: public:
TypeView(BRect rect, const char* name, int32 index, TypeView(BRect rect, const char* name,
DataEditor& editor, int32 resizingMode); int32 index, DataEditor& editor,
virtual ~TypeView(); int32 resizingMode);
virtual ~TypeView();
virtual void FrameResized(float width, float height); virtual void FrameResized(float width, float height);
private: private:
BView* fTypeEditorView; BView* fTypeEditorView;
}; };
@@ -212,7 +222,7 @@ class TypeView : public BView {
static void static void
get_type_string(char *buffer, size_t bufferSize, type_code type) get_type_string(char* buffer, size_t bufferSize, type_code type)
{ {
for (int32 i = 0; i < 4; i++) { for (int32 i = 0; i < 4; i++) {
buffer[i] = type >> (24 - 8 * i); buffer[i] = type >> (24 - 8 * i);
@@ -228,7 +238,7 @@ get_type_string(char *buffer, size_t bufferSize, type_code type)
// #pragma mark - IconView // #pragma mark - IconView
IconView::IconView(const entry_ref *ref, bool isDevice) IconView::IconView(const entry_ref* ref, bool isDevice)
: BView(NULL, B_WILL_DRAW), : BView(NULL, B_WILL_DRAW),
fRef(*ref), fRef(*ref),
fIsDevice(isDevice), fIsDevice(isDevice),
@@ -309,9 +319,10 @@ IconView::UpdateIcon()
// #pragma mark - PositionSlider // #pragma mark - PositionSlider
PositionSlider::PositionSlider(const char *name, BMessage *message, PositionSlider::PositionSlider(const char* name, BMessage* message,
off_t size, uint32 blockSize) off_t size, uint32 blockSize)
: BSlider(name, NULL, message, 0, kMaxSliderLimit, B_HORIZONTAL, :
BSlider(name, NULL, message, 0, kMaxSliderLimit, B_HORIZONTAL,
B_TRIANGLE_THUMB), B_TRIANGLE_THUMB),
fSize(size), fSize(size),
fBlockSize(blockSize) fBlockSize(blockSize)
@@ -334,7 +345,7 @@ PositionSlider::~PositionSlider()
void void
PositionSlider::DrawBar() PositionSlider::DrawBar()
{ {
BView *view = OffscreenView(); BView* view = OffscreenView();
BRect barFrame = BarFrame(); BRect barFrame = BarFrame();
BRect frame = barFrame.InsetByCopy(1, 1); BRect frame = barFrame.InsetByCopy(1, 1);
@@ -471,7 +482,7 @@ PositionSlider::SetBlockSize(uint32 blockSize)
// #pragma mark - HeaderView // #pragma mark - HeaderView
HeaderView::HeaderView(const entry_ref *ref, DataEditor &editor) HeaderView::HeaderView(const entry_ref* ref, DataEditor& editor)
: BGridView("probeHeader", B_USE_SMALL_SPACING, B_USE_SMALL_SPACING), : BGridView("probeHeader", B_USE_SMALL_SPACING, B_USE_SMALL_SPACING),
fAttribute(editor.Attribute()), fAttribute(editor.Attribute()),
fFileSize(editor.FileSize()), fFileSize(editor.FileSize()),
@@ -495,7 +506,7 @@ HeaderView::HeaderView(const entry_ref *ref, DataEditor &editor)
boldFont.SetSize(plainFont.Size() * 0.83); boldFont.SetSize(plainFont.Size() * 0.83);
plainFont.SetSize(plainFont.Size() * 0.83); plainFont.SetSize(plainFont.Size() * 0.83);
BStringView *stringView = new BStringView( BStringView* stringView = new BStringView(
B_EMPTY_STRING, editor.IsAttribute() B_EMPTY_STRING, editor.IsAttribute()
? B_TRANSLATE("Attribute: ") : editor.IsDevice() ? B_TRANSLATE("Attribute: ") : editor.IsDevice()
? B_TRANSLATE("Device: ") : B_TRANSLATE("File: ")); ? B_TRANSLATE("Device: ") : B_TRANSLATE("File: "));
@@ -620,7 +631,7 @@ HeaderView::AttachedToWindow()
fFileOffsetControl->SetTarget(this); fFileOffsetControl->SetTarget(this);
fPositionSlider->SetTarget(this); fPositionSlider->SetTarget(this);
BMessage *message; BMessage* message;
Window()->AddShortcut(B_HOME, B_COMMAND_KEY, Window()->AddShortcut(B_HOME, B_COMMAND_KEY,
message = new BMessage(kMsgPositionUpdate), this); message = new BMessage(kMsgPositionUpdate), this);
message->AddInt64("block", 0); message->AddInt64("block", 0);
@@ -654,7 +665,7 @@ HeaderView::UpdateIcon()
void void
HeaderView::FormatValue(char *buffer, size_t bufferSize, off_t value) HeaderView::FormatValue(char* buffer, size_t bufferSize, off_t value)
{ {
snprintf(buffer, bufferSize, fBase == kHexBase ? "0x%" B_PRIxOFF : "%" snprintf(buffer, bufferSize, fBase == kHexBase ? "0x%" B_PRIxOFF : "%"
B_PRIdOFF, value); B_PRIdOFF, value);
@@ -740,7 +751,7 @@ HeaderView::NotifyTarget()
void void
HeaderView::MessageReceived(BMessage *message) HeaderView::MessageReceived(BMessage* message)
{ {
switch (message->what) { switch (message->what) {
case B_OBSERVER_NOTICE_CHANGE: { case B_OBSERVER_NOTICE_CHANGE: {
@@ -910,16 +921,17 @@ HeaderView::MessageReceived(BMessage *message)
It is used to display the attribute and type in the attributes menu. It is used to display the attribute and type in the attributes menu.
It does not mix nicely with short cuts. It does not mix nicely with short cuts.
*/ */
TypeMenuItem::TypeMenuItem(const char *name, const char *type, TypeMenuItem::TypeMenuItem(const char* name, const char* type,
BMessage *message) BMessage* message)
: BMenuItem(name, message), :
BMenuItem(name, message),
fType(type) fType(type)
{ {
} }
void void
TypeMenuItem::GetContentSize(float *_width, float *_height) TypeMenuItem::GetContentSize(float* _width, float* _height)
{ {
BMenuItem::GetContentSize(_width, _height); BMenuItem::GetContentSize(_width, _height);
@@ -963,7 +975,7 @@ TypeMenuItem::DrawContent()
this looper. this looper.
Also, it will run the find action in the editor. Also, it will run the find action in the editor.
*/ */
EditorLooper::EditorLooper(const char *name, DataEditor &editor, EditorLooper::EditorLooper(const char* name, DataEditor& editor,
BMessenger target) BMessenger target)
: BLooper(name), : BLooper(name),
fEditor(editor), fEditor(editor),
@@ -981,7 +993,7 @@ EditorLooper::~EditorLooper()
void void
EditorLooper::MessageReceived(BMessage *message) EditorLooper::MessageReceived(BMessage* message)
{ {
switch (message->what) { switch (message->what) {
case kMsgPositionUpdate: case kMsgPositionUpdate:
@@ -1038,8 +1050,8 @@ EditorLooper::MessageReceived(BMessage *message)
bool caseInsensitive = !message->FindBool("case_sensitive"); bool caseInsensitive = !message->FindBool("case_sensitive");
ssize_t dataSize; ssize_t dataSize;
const uint8 *data; const uint8* data;
if (message->FindData("data", B_RAW_TYPE, (const void **)&data, if (message->FindData("data", B_RAW_TYPE, (const void**)&data,
&dataSize) == B_OK) &dataSize) == B_OK)
Find(startAt, data, dataSize, caseInsensitive, progressMonitor); Find(startAt, data, dataSize, caseInsensitive, progressMonitor);
} }
@@ -1052,7 +1064,7 @@ EditorLooper::MessageReceived(BMessage *message)
void void
EditorLooper::Find(off_t startAt, const uint8 *data, size_t dataSize, EditorLooper::Find(off_t startAt, const uint8* data, size_t dataSize,
bool caseInsensitive, BMessenger progressMonitor) bool caseInsensitive, BMessenger progressMonitor)
{ {
fQuitFind = false; fQuitFind = false;
@@ -1062,7 +1074,7 @@ EditorLooper::Find(off_t startAt, const uint8 *data, size_t dataSize,
bigtime_t startTime = system_time(); bigtime_t startTime = system_time();
off_t foundAt = fEditor.Find(startAt, data, dataSize, caseInsensitive, off_t foundAt = fEditor.Find(startAt, data, dataSize, caseInsensitive,
true, progressMonitor, &fQuitFind); true, progressMonitor, &fQuitFind);
if (foundAt >= B_OK) { if (foundAt >= B_OK) {
fEditor.SetViewOffset(foundAt); fEditor.SetViewOffset(foundAt);
@@ -1151,8 +1163,8 @@ TypeView::FrameResized(float width, float height)
// #pragma mark - ProbeView // #pragma mark - ProbeView
ProbeView::ProbeView(entry_ref *ref, const char *attribute, ProbeView::ProbeView(entry_ref* ref, const char* attribute,
const BMessage *settings) const BMessage* settings)
: BView("probeView", B_WILL_DRAW), : BView("probeView", B_WILL_DRAW),
fPrintSettings(NULL), fPrintSettings(NULL),
fTypeView(NULL), fTypeView(NULL),
@@ -1209,7 +1221,7 @@ ProbeView::DetachedFromWindow()
void void
ProbeView::_UpdateAttributesMenu(BMenu *menu) ProbeView::_UpdateAttributesMenu(BMenu* menu)
{ {
// remove old contents // remove old contents
@@ -1241,7 +1253,7 @@ ProbeView::_UpdateAttributesMenu(BMenu *menu)
break; break;
} }
BMessage *message = new BMessage(B_REFS_RECEIVED); BMessage* message = new BMessage(B_REFS_RECEIVED);
message->AddRef("refs", &fEditor.AttributeRef()); message->AddRef("refs", &fEditor.AttributeRef());
message->AddString("attributes", attribute); message->AddString("attributes", attribute);
@@ -1252,7 +1264,7 @@ ProbeView::_UpdateAttributesMenu(BMenu *menu)
if (menu->CountItems() == 0) { if (menu->CountItems() == 0) {
// if there are no attributes, add an item to the menu // if there are no attributes, add an item to the menu
// that says so // that says so
BMenuItem *item = new BMenuItem(B_TRANSLATE_COMMENT("none", BMenuItem* item = new BMenuItem(B_TRANSLATE_COMMENT("none",
"No attributes"), NULL); "No attributes"), NULL);
item->SetEnabled(false); item->SetEnabled(false);
menu->AddItem(item); menu->AddItem(item);
@@ -1276,7 +1288,7 @@ ProbeView::AddSaveMenuItems(BMenu* menu, int32 index)
void void
ProbeView::AddPrintMenuItems(BMenu* menu, int32 index) ProbeView::AddPrintMenuItems(BMenu* menu, int32 index)
{ {
BMenuItem *item; BMenuItem* item;
menu->AddItem(item = new BMenuItem(B_TRANSLATE("Page setup" B_UTF8_ELLIPSIS), menu->AddItem(item = new BMenuItem(B_TRANSLATE("Page setup" B_UTF8_ELLIPSIS),
new BMessage(kMsgPageSetup)), index++); new BMessage(kMsgPageSetup)), index++);
item->SetTarget(this); item->SetTarget(this);
@@ -1343,45 +1355,47 @@ ProbeView::AttachedToWindow()
// Add menu to window // Add menu to window
BMenuBar *bar = Window()->KeyMenuBar(); BMenuBar* bar = Window()->KeyMenuBar();
if (bar == NULL) { if (bar == NULL) {
// there is none? Well, but we really want to have one // there is none? Well, but we really want to have one
bar = new BMenuBar(""); bar = new BMenuBar("");
Window()->AddChild(bar); Window()->AddChild(bar);
BMenu *menu = new BMenu(fEditor.IsAttribute() BMenu* menu = new BMenu(fEditor.IsAttribute()
? B_TRANSLATE("Attribute") : fEditor.IsDevice() ? B_TRANSLATE("Device") : B_TRANSLATE("File")); ? B_TRANSLATE("Attribute") : fEditor.IsDevice()
? B_TRANSLATE("Device") : B_TRANSLATE("File"));
AddSaveMenuItems(menu, 0); AddSaveMenuItems(menu, 0);
menu->AddSeparatorItem(); menu->AddSeparatorItem();
AddPrintMenuItems(menu, menu->CountItems()); AddPrintMenuItems(menu, menu->CountItems());
menu->AddSeparatorItem(); menu->AddSeparatorItem();
menu->AddItem(new BMenuItem(B_TRANSLATE("Close"), new BMessage(B_CLOSE_REQUESTED), menu->AddItem(new BMenuItem(B_TRANSLATE("Close"),
'W')); new BMessage(B_CLOSE_REQUESTED), 'W'));
bar->AddItem(menu); bar->AddItem(menu);
} }
// "Edit" menu // "Edit" menu
BMenu *menu = new BMenu(B_TRANSLATE("Edit")); BMenu* menu = new BMenu(B_TRANSLATE("Edit"));
BMenuItem *item; BMenuItem* item;
menu->AddItem(fUndoMenuItem = new BMenuItem(B_TRANSLATE("Undo"), new BMessage(B_UNDO), menu->AddItem(fUndoMenuItem = new BMenuItem(B_TRANSLATE("Undo"),
'Z')); new BMessage(B_UNDO), 'Z'));
fUndoMenuItem->SetEnabled(fEditor.CanUndo()); fUndoMenuItem->SetEnabled(fEditor.CanUndo());
fUndoMenuItem->SetTarget(fDataView); fUndoMenuItem->SetTarget(fDataView);
menu->AddItem(fRedoMenuItem = new BMenuItem(B_TRANSLATE("Redo"), new BMessage(B_REDO), menu->AddItem(fRedoMenuItem = new BMenuItem(B_TRANSLATE("Redo"),
'Z', B_SHIFT_KEY)); new BMessage(B_REDO), 'Z', B_SHIFT_KEY));
fRedoMenuItem->SetEnabled(fEditor.CanRedo()); fRedoMenuItem->SetEnabled(fEditor.CanRedo());
fRedoMenuItem->SetTarget(fDataView); fRedoMenuItem->SetTarget(fDataView);
menu->AddSeparatorItem(); menu->AddSeparatorItem();
menu->AddItem(item = new BMenuItem(B_TRANSLATE("Copy"), new BMessage(B_COPY), 'C')); menu->AddItem(item = new BMenuItem(B_TRANSLATE("Copy"),
new BMessage(B_COPY), 'C'));
item->SetTarget(NULL, Window()); item->SetTarget(NULL, Window());
menu->AddItem(fPasteMenuItem = new BMenuItem(B_TRANSLATE("Paste"), new BMessage(B_PASTE), menu->AddItem(fPasteMenuItem = new BMenuItem(B_TRANSLATE("Paste"),
'V')); new BMessage(B_PASTE), 'V'));
fPasteMenuItem->SetTarget(NULL, Window()); fPasteMenuItem->SetTarget(NULL, Window());
_CheckClipboard(); _CheckClipboard();
menu->AddItem(item = new BMenuItem(B_TRANSLATE("Select all"), new BMessage(B_SELECT_ALL), menu->AddItem(item = new BMenuItem(B_TRANSLATE("Select all"),
'A')); new BMessage(B_SELECT_ALL), 'A'));
item->SetTarget(NULL, Window()); item->SetTarget(NULL, Window());
menu->AddSeparatorItem(); menu->AddSeparatorItem();
menu->AddItem(item = new BMenuItem(B_TRANSLATE("Find" B_UTF8_ELLIPSIS), menu->AddItem(item = new BMenuItem(B_TRANSLATE("Find" B_UTF8_ELLIPSIS),
@@ -1396,19 +1410,21 @@ ProbeView::AttachedToWindow()
// "Block" menu // "Block" menu
menu = new BMenu(B_TRANSLATE("Block")); menu = new BMenu(B_TRANSLATE("Block"));
BMessage *message = new BMessage(kMsgPositionUpdate); BMessage* message = new BMessage(kMsgPositionUpdate);
message->AddInt32("delta", 1); message->AddInt32("delta", 1);
menu->AddItem(item = new BMenuItem(B_TRANSLATE("Next"), message, B_RIGHT_ARROW)); menu->AddItem(item = new BMenuItem(B_TRANSLATE("Next"), message,
B_RIGHT_ARROW));
item->SetTarget(fHeaderView); item->SetTarget(fHeaderView);
message = new BMessage(kMsgPositionUpdate); message = new BMessage(kMsgPositionUpdate);
message->AddInt32("delta", -1); message->AddInt32("delta", -1);
menu->AddItem(item = new BMenuItem(B_TRANSLATE("Previous"), message, B_LEFT_ARROW)); menu->AddItem(item = new BMenuItem(B_TRANSLATE("Previous"), message,
B_LEFT_ARROW));
item->SetTarget(fHeaderView); item->SetTarget(fHeaderView);
menu->AddItem(item = new BMenuItem(B_TRANSLATE("Back"), new BMessage(kMsgLastPosition), menu->AddItem(item = new BMenuItem(B_TRANSLATE("Back"),
'J')); new BMessage(kMsgLastPosition), 'J'));
item->SetTarget(fHeaderView); item->SetTarget(fHeaderView);
BMenu *subMenu = new BMenu(B_TRANSLATE("Selection")); BMenu* subMenu = new BMenu(B_TRANSLATE("Selection"));
message = new BMessage(kMsgPositionUpdate); message = new BMessage(kMsgPositionUpdate);
message->AddInt64("block", 0); message->AddInt64("block", 0);
subMenu->AddItem(fNativeMenuItem = new BMenuItem("", message, 'K')); subMenu->AddItem(fNativeMenuItem = new BMenuItem("", message, 'K'));
@@ -1565,7 +1581,7 @@ void
ProbeView::_UpdateSelectionMenuItems(int64 start, int64 end) ProbeView::_UpdateSelectionMenuItems(int64 start, int64 end)
{ {
int64 position = 0; int64 position = 0;
const uint8 *data = fDataView->DataAt(start); const uint8* data = fDataView->DataAt(start);
if (data == NULL) { if (data == NULL) {
fNativeMenuItem->SetEnabled(false); fNativeMenuItem->SetEnabled(false);
fSwappedMenuItem->SetEnabled(false); fSwappedMenuItem->SetEnabled(false);
@@ -1620,11 +1636,11 @@ void
ProbeView::_UpdateBookmarkMenuItems() ProbeView::_UpdateBookmarkMenuItems()
{ {
for (int32 i = 2; i < fBookmarkMenu->CountItems(); i++) { for (int32 i = 2; i < fBookmarkMenu->CountItems(); i++) {
BMenuItem *item = fBookmarkMenu->ItemAt(i); BMenuItem* item = fBookmarkMenu->ItemAt(i);
if (item == NULL) if (item == NULL)
break; break;
BMessage *message = item->Message(); BMessage* message = item->Message();
if (message == NULL) if (message == NULL)
break; break;
@@ -1656,10 +1672,10 @@ ProbeView::_AddBookmark(off_t position)
off_t block = position / fEditor.BlockSize(); off_t block = position / fEditor.BlockSize();
off_t bookmark = -1; off_t bookmark = -1;
BMenuItem *item; BMenuItem* item;
int32 i; int32 i;
for (i = 2; (item = fBookmarkMenu->ItemAt(i)) != NULL; i++) { for (i = 2; (item = fBookmarkMenu->ItemAt(i)) != NULL; i++) {
BMessage *message = item->Message(); BMessage* message = item->Message();
if (message != NULL && message->FindInt64("block", &bookmark) == B_OK) { if (message != NULL && message->FindInt64("block", &bookmark) == B_OK) {
if (block <= bookmark) if (block <= bookmark)
break; break;
@@ -1676,7 +1692,7 @@ ProbeView::_AddBookmark(off_t position)
else else
snprintf(buffer, sizeof(buffer), B_TRANSLATE("Block %Ld (0x%Lx)"), block, block); snprintf(buffer, sizeof(buffer), B_TRANSLATE("Block %Ld (0x%Lx)"), block, block);
BMessage *message; BMessage* message;
item = new BMenuItem(buffer, message = new BMessage(kMsgPositionUpdate)); item = new BMenuItem(buffer, message = new BMessage(kMsgPositionUpdate));
item->SetTarget(fHeaderView); item->SetTarget(fHeaderView);
if (count < 12) if (count < 12)
@@ -1737,9 +1753,9 @@ ProbeView::_CheckClipboard()
return; return;
bool hasData = false; bool hasData = false;
BMessage *clip; BMessage* clip;
if ((clip = be_clipboard->Data()) != NULL) { if ((clip = be_clipboard->Data()) != NULL) {
const void *data; const void* data;
ssize_t size; ssize_t size;
if (clip->FindData(B_FILE_MIME_TYPE, B_MIME_TYPE, &data, &size) == B_OK if (clip->FindData(B_FILE_MIME_TYPE, B_MIME_TYPE, &data, &size) == B_OK
|| clip->FindData("text/plain", B_MIME_TYPE, &data, &size) == B_OK) || clip->FindData("text/plain", B_MIME_TYPE, &data, &size) == B_OK)
@@ -1848,7 +1864,7 @@ ProbeView::QuitRequested()
void void
ProbeView::MessageReceived(BMessage *message) ProbeView::MessageReceived(BMessage* message)
{ {
switch (message->what) { switch (message->what) {
case B_SAVE_REQUESTED: case B_SAVE_REQUESTED:
@@ -1961,13 +1977,14 @@ ProbeView::MessageReceived(BMessage *message)
case kMsgFind: case kMsgFind:
{ {
const uint8 *data; const uint8* data;
ssize_t size; ssize_t size;
if (message->FindData("data", B_RAW_TYPE, (const void **)&data, &size) != B_OK) { if (message->FindData("data", B_RAW_TYPE, (const void**)&data,
&size) != B_OK) {
// search again for last pattern // search again for last pattern
BMessage *itemMessage = fFindAgainMenuItem->Message(); BMessage* itemMessage = fFindAgainMenuItem->Message();
if (itemMessage == NULL if (itemMessage == NULL || itemMessage->FindData("data",
|| itemMessage->FindData("data", B_RAW_TYPE, (const void **)&data, &size) != B_OK) { B_RAW_TYPE, (const void**)&data, &size) != B_OK) {
// this shouldn't ever happen, but well... // this shouldn't ever happen, but well...
beep(); beep();
break; break;
@@ -2000,7 +2017,7 @@ ProbeView::MessageReceived(BMessage *message)
break; break;
case B_ATTR_CHANGED: case B_ATTR_CHANGED:
{ {
const char *name; const char* name;
if (message->FindString("attr", &name) != B_OK) if (message->FindString("attr", &name) != B_OK)
break; break;
@@ -2008,9 +2025,9 @@ ProbeView::MessageReceived(BMessage *message)
if (!strcmp(name, fEditor.Attribute())) if (!strcmp(name, fEditor.Attribute()))
fEditor.ForceUpdate(); fEditor.ForceUpdate();
} else { } else {
BMenuBar *bar = Window()->KeyMenuBar(); BMenuBar* bar = Window()->KeyMenuBar();
if (bar != NULL) { if (bar != NULL) {
BMenuItem *item = bar->FindItem("Attributes"); BMenuItem* item = bar->FindItem("Attributes");
if (item != NULL && item->Submenu() != NULL) if (item != NULL && item->Submenu() != NULL)
_UpdateAttributesMenu(item->Submenu()); _UpdateAttributesMenu(item->Submenu());
} }
+48 -44
View File
@@ -1,6 +1,6 @@
/* /*
* Copyright 2004-2008, Axel Dörfler, axeld@pinc-software.de. All rights reserved. * Copyright 2004-2018, Axel Dörfler, axeld@pinc-software.de.
* Distributed under the terms of the MIT License. * All rights reserved. Distributed under the terms of the MIT license.
*/ */
#ifndef PROBE_VIEW_H #ifndef PROBE_VIEW_H
#define PROBE_VIEW_H #define PROBE_VIEW_H
@@ -23,55 +23,59 @@ class EditorLooper;
class ProbeView : public BView { class ProbeView : public BView {
public: public:
ProbeView(entry_ref* ref, const char* attribute = NULL, ProbeView(entry_ref* ref,
const BMessage* settings = NULL); const char* attribute = NULL,
virtual ~ProbeView(); const BMessage* settings = NULL);
virtual ~ProbeView();
virtual void DetachedFromWindow(); virtual void DetachedFromWindow();
virtual void AttachedToWindow(); virtual void AttachedToWindow();
virtual void AllAttached(); virtual void AllAttached();
virtual void WindowActivated(bool active); virtual void WindowActivated(bool active);
virtual void MessageReceived(BMessage* message); virtual void MessageReceived(BMessage* message);
void AddSaveMenuItems(BMenu* menu, int32 index); void AddSaveMenuItems(BMenu* menu, int32 index);
void AddPrintMenuItems(BMenu* menu, int32 index); void AddPrintMenuItems(BMenu* menu, int32 index);
void AddViewAsMenuItems(); void AddViewAsMenuItems();
bool QuitRequested(); bool QuitRequested();
DataEditor& Editor() { return fEditor; } DataEditor& Editor() { return fEditor; }
private: private:
void _UpdateAttributesMenu(BMenu* menu); void _UpdateAttributesMenu(BMenu* menu);
void _UpdateSelectionMenuItems(int64 start, int64 end); void _UpdateSelectionMenuItems(int64 start,
void _UpdateBookmarkMenuItems(); int64 end);
void _AddBookmark(off_t position); void _UpdateBookmarkMenuItems();
void _RemoveTypeEditor(); void _AddBookmark(off_t position);
void _SetTypeEditor(int32 index); void _RemoveTypeEditor();
void _CheckClipboard(); void _SetTypeEditor(int32 index);
status_t _PageSetup(); void _CheckClipboard();
void _Print(); status_t _PageSetup();
status_t _Save(); void _Print();
status_t _Save();
DataEditor fEditor; private:
EditorLooper* fEditorLooper; DataEditor fEditor;
HeaderView* fHeaderView; EditorLooper* fEditorLooper;
DataView* fDataView; HeaderView* fHeaderView;
BScrollView* fScrollView; DataView* fDataView;
BMenuItem* fPasteMenuItem; BScrollView* fScrollView;
BMenuItem* fUndoMenuItem; BMenuItem* fPasteMenuItem;
BMenuItem* fRedoMenuItem; BMenuItem* fUndoMenuItem;
BMenuItem* fNativeMenuItem; BMenuItem* fRedoMenuItem;
BMenuItem* fSwappedMenuItem; BMenuItem* fNativeMenuItem;
BMenuItem* fSaveMenuItem; BMenuItem* fSwappedMenuItem;
BMessage* fPrintSettings; BMenuItem* fSaveMenuItem;
BMenu* fBookmarkMenu; BMessage* fPrintSettings;
BView* fTypeView; BMenu* fBookmarkMenu;
BView* fTypeView;
BMenuItem* fFindAgainMenuItem; BMenuItem* fFindAgainMenuItem;
const uint8* fLastSearch; const uint8* fLastSearch;
size_t fLastSearchSize; size_t fLastSearchSize;
}; };
#endif /* PROBE_VIEW_H */ #endif /* PROBE_VIEW_H */
+22 -7
View File
@@ -1,18 +1,33 @@
/* /*
* Copyright 2004-2006, Axel Dörfler, axeld@pinc-software.de. All rights reserved. * Copyright 2004-2018, Axel Dörfler, axeld@pinc-software.de.
* Distributed under the terms of the MIT License. * All rights reserved. Distributed under the terms of the MIT license.
*/ */
/*! Abstract base class for probe windows. It only provides the following
functionality:
- Access to the basic entry_ref
- Common BWindow flags
- Stores size in settings on QuitRequested()
- Redirects drops to BApplication
- Notifies BApplication about closed window
- Forwards mouse wheel to the DataView
- Contains() checks whether or not the ref/attribute is what this
window contains
*/
#include "ProbeWindow.h" #include "ProbeWindow.h"
#include "DiskProbe.h"
#include <Application.h> #include <Application.h>
#include <View.h> #include <View.h>
#include "DiskProbe.h"
ProbeWindow::ProbeWindow(BRect rect, entry_ref *ref)
: BWindow(rect, ref->name, B_DOCUMENT_WINDOW, ProbeWindow::ProbeWindow(BRect rect, entry_ref* ref)
:
BWindow(rect, ref->name, B_DOCUMENT_WINDOW,
B_ASYNCHRONOUS_CONTROLS | B_AUTO_UPDATE_SIZE_LIMITS), B_ASYNCHRONOUS_CONTROLS | B_AUTO_UPDATE_SIZE_LIMITS),
fRef(*ref) fRef(*ref)
{ {
@@ -25,11 +40,11 @@ ProbeWindow::~ProbeWindow()
void void
ProbeWindow::MessageReceived(BMessage *message) ProbeWindow::MessageReceived(BMessage* message)
{ {
switch (message->what) { switch (message->what) {
case B_MOUSE_WHEEL_CHANGED: case B_MOUSE_WHEEL_CHANGED:
if (BView *view = FindView("dataView")) if (BView* view = FindView("dataView"))
view->MessageReceived(message); view->MessageReceived(message);
break; break;
+16 -14
View File
@@ -1,7 +1,7 @@
/* /*
** Copyright 2004, Axel Dörfler, axeld@pinc-software.de. All rights reserved. * Copyright 2004-2018, Axel Dörfler, axeld@pinc-software.de.
** Distributed under the terms of the MIT License. * All rights reserved. Distributed under the terms of the MIT license.
*/ */
#ifndef PROBE_WINDOW_H #ifndef PROBE_WINDOW_H
#define PROBE_WINDOW_H #define PROBE_WINDOW_H
@@ -11,20 +11,22 @@
class ProbeWindow : public BWindow { class ProbeWindow : public BWindow {
public: public:
ProbeWindow(BRect rect, entry_ref *ref); ProbeWindow(BRect rect, entry_ref* ref);
virtual ~ProbeWindow(); virtual ~ProbeWindow();
virtual void MessageReceived(BMessage *message); virtual void MessageReceived(BMessage* message);
virtual bool QuitRequested(); virtual bool QuitRequested();
virtual bool Contains(const entry_ref &ref, const char *attribute) = 0; virtual bool Contains(const entry_ref& ref,
const char* attribute) = 0;
protected: protected:
const entry_ref &Ref() const { return fRef; } const entry_ref& Ref() const { return fRef; }
private: private:
entry_ref fRef; entry_ref fRef;
}; };
#endif /* PROBE_WINDOW_H */ #endif /* PROBE_WINDOW_H */
+16 -11
View File
@@ -1,6 +1,6 @@
/* /*
* Copyright 2004-2008, Axel Dörfler, axeld@pinc-software.de. All rights reserved. * Copyright 2004-2018, Axel Dörfler, axeld@pinc-software.de.
* Distributed under the terms of the MIT License. * All rights reserved. Distributed under the terms of the MIT license.
*/ */
#ifndef TYPE_EDITORS_H #ifndef TYPE_EDITORS_H
#define TYPE_EDITORS_H #define TYPE_EDITORS_H
@@ -8,26 +8,31 @@
#include <View.h> #include <View.h>
class DataEditor; class DataEditor;
class TypeEditorView : public BView { class TypeEditorView : public BView {
public: public:
TypeEditorView(BRect rect, const char* name, uint32 resizingMode, TypeEditorView(BRect rect, const char* name,
uint32 flags, DataEditor& editor); uint32 resizingMode, uint32 flags,
TypeEditorView(const char* name, uint32 flags, DataEditor& editor); DataEditor& editor);
~TypeEditorView(); TypeEditorView(const char* name, uint32 flags,
DataEditor& editor);
virtual ~TypeEditorView();
virtual void CommitChanges(); virtual void CommitChanges();
virtual bool TypeMatches(); virtual bool TypeMatches();
protected: protected:
DataEditor& fEditor; DataEditor& fEditor;
}; };
extern TypeEditorView* GetTypeEditorFor(BRect rect, DataEditor& editor); extern TypeEditorView* GetTypeEditorFor(BRect rect, DataEditor& editor);
extern status_t GetNthTypeEditor(int32 index, const char** _name); extern status_t GetNthTypeEditor(int32 index, const char** _name);
extern TypeEditorView* GetTypeEditorAt(int32 index, BRect rect, extern TypeEditorView* GetTypeEditorAt(int32 index, BRect rect,
DataEditor& editor); DataEditor& editor);
#endif /* TYPE_EDITORS_H */ #endif /* TYPE_EDITORS_H */