DiskProbe: improved initial window size.
* Also some automatic whitespace cleanup.
This commit is contained in:
@@ -1,30 +1,29 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2004-2009, Axel Dörfler, [email protected].
|
* Copyright 2004-2015, Axel Dörfler, [email protected].
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include "DataView.h"
|
#include "DataView.h"
|
||||||
#include "DataEditor.h"
|
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include <Window.h>
|
|
||||||
#include <ScrollBar.h>
|
|
||||||
#include <Autolock.h>
|
#include <Autolock.h>
|
||||||
|
#include <Beep.h>
|
||||||
#include <Clipboard.h>
|
#include <Clipboard.h>
|
||||||
#include <Mime.h>
|
#include <Mime.h>
|
||||||
#include <Beep.h>
|
#include <ScrollBar.h>
|
||||||
|
#include <Window.h>
|
||||||
|
|
||||||
|
#include "DataEditor.h"
|
||||||
|
|
||||||
#ifndef __HAIKU__
|
|
||||||
typedef uint32 addr_t;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static const uint32 kBlockSize = 16;
|
static const uint32 kBlockSize = 16;
|
||||||
|
// TODO: use variable spacing
|
||||||
static const uint32 kHorizontalSpace = 8;
|
static const uint32 kHorizontalSpace = 8;
|
||||||
static const uint32 kVerticalSpace = 4;
|
static const uint32 kVerticalSpace = 4;
|
||||||
|
static const uint32 kPositionLength = 4;
|
||||||
|
|
||||||
static const uint32 kBlockSpace = 3;
|
static const uint32 kBlockSpace = 3;
|
||||||
static const uint32 kHexByteWidth = 3;
|
static const uint32 kHexByteWidth = 3;
|
||||||
@@ -106,7 +105,6 @@ DataView::DataView(DataEditor &editor)
|
|||||||
fFitFontSize(false),
|
fFitFontSize(false),
|
||||||
fDragMessageSize(-1)
|
fDragMessageSize(-1)
|
||||||
{
|
{
|
||||||
fPositionLength = 4;
|
|
||||||
fStart = fEnd = 0;
|
fStart = fEnd = 0;
|
||||||
|
|
||||||
if (fEditor.Lock()) {
|
if (fEditor.Lock()) {
|
||||||
@@ -357,7 +355,7 @@ DataView::ConvertLine(char *line, off_t offset, const uint8 *buffer, size_t size
|
|||||||
}
|
}
|
||||||
|
|
||||||
line += sprintf(line, fBase == kHexBase ? "%0*" B_PRIxOFF": " : "%0*"
|
line += sprintf(line, fBase == kHexBase ? "%0*" B_PRIxOFF": " : "%0*"
|
||||||
B_PRIdOFF": ", (int)fPositionLength, offset);
|
B_PRIdOFF": ", (int)kPositionLength, offset);
|
||||||
|
|
||||||
for (uint32 i = 0; i < kBlockSize; i++) {
|
for (uint32 i = 0; i < kBlockSize; i++) {
|
||||||
if (i >= size) {
|
if (i >= size) {
|
||||||
@@ -412,7 +410,7 @@ BRect
|
|||||||
DataView::DataBounds(bool inView) const
|
DataView::DataBounds(bool inView) const
|
||||||
{
|
{
|
||||||
return BRect(0, 0,
|
return BRect(0, 0,
|
||||||
fCharWidth * (kBlockSize * 4 + fPositionLength + 6) + 2 * kHorizontalSpace,
|
fCharWidth * (kBlockSize * 4 + kPositionLength + 6) + 2 * kHorizontalSpace,
|
||||||
fFontHeight * (((inView ? fSizeInView : fDataSize) + kBlockSize - 1) / kBlockSize)
|
fFontHeight * (((inView ? fSizeInView : fDataSize) + kBlockSize - 1) / kBlockSize)
|
||||||
+ 2 * kVerticalSpace);
|
+ 2 * kVerticalSpace);
|
||||||
}
|
}
|
||||||
@@ -434,7 +432,7 @@ DataView::PositionAt(view_focus focus, BPoint point, view_focus *_newFocus)
|
|||||||
else if (point.y >= bounds.bottom - kVerticalSpace)
|
else if (point.y >= bounds.bottom - kVerticalSpace)
|
||||||
point.y = bounds.bottom - kVerticalSpace - 1;
|
point.y = bounds.bottom - kVerticalSpace - 1;
|
||||||
|
|
||||||
float left = fCharWidth * (fPositionLength + kBlockSpace) + kHorizontalSpace;
|
float left = fCharWidth * (kPositionLength + kBlockSpace) + kHorizontalSpace;
|
||||||
float hexWidth = fCharWidth * kBlockSize * kHexByteWidth;
|
float hexWidth = fCharWidth * kBlockSize * kHexByteWidth;
|
||||||
float width = fCharWidth;
|
float width = fCharWidth;
|
||||||
|
|
||||||
@@ -478,11 +476,11 @@ DataView::SelectionFrame(view_focus which, int32 start, int32 end)
|
|||||||
|
|
||||||
if (which == kHexFocus) {
|
if (which == kHexFocus) {
|
||||||
spacing = fCharWidth / 2;
|
spacing = fCharWidth / 2;
|
||||||
left = width * (fPositionLength + kBlockSpace);
|
left = width * (kPositionLength + kBlockSpace);
|
||||||
width *= kHexByteWidth;
|
width *= kHexByteWidth;
|
||||||
byteWidth *= 2;
|
byteWidth *= 2;
|
||||||
} else
|
} else
|
||||||
left = width * (fPositionLength + 2 * kBlockSpace + kHexByteWidth * kBlockSize);
|
left = width * (kPositionLength + 2 * kBlockSpace + kHexByteWidth * kBlockSize);
|
||||||
|
|
||||||
left += kHorizontalSpace;
|
left += kHorizontalSpace;
|
||||||
float startInLine = (start % kBlockSize) * width;
|
float startInLine = (start % kBlockSize) * width;
|
||||||
@@ -837,6 +835,18 @@ DataView::DataAt(int32 start)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*static*/ int32
|
||||||
|
DataView::WidthForFontSize(float size)
|
||||||
|
{
|
||||||
|
BFont font = be_fixed_font;
|
||||||
|
font.SetSize(size);
|
||||||
|
|
||||||
|
float charWidth = font.StringWidth("w");
|
||||||
|
return (int32)ceilf(charWidth * (kBlockSize * 4 + kPositionLength + 6)
|
||||||
|
+ 2 * kHorizontalSpace);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
DataView::SetBase(base_type type)
|
DataView::SetBase(base_type type)
|
||||||
{
|
{
|
||||||
@@ -942,24 +952,24 @@ DataView::FrameResized(float width, float height)
|
|||||||
if (fFitFontSize) {
|
if (fFitFontSize) {
|
||||||
// adapt the font size to fit in the view's bounds
|
// adapt the font size to fit in the view's bounds
|
||||||
float oldSize = FontSize();
|
float oldSize = FontSize();
|
||||||
BFont font = be_fixed_font;
|
|
||||||
float steps = 0.5f;
|
float steps = 0.5f;
|
||||||
|
|
||||||
float size;
|
float size;
|
||||||
for (size = 1.f; size < 100; size += steps) {
|
for (size = 1.f; size < 100; size += steps) {
|
||||||
font.SetSize(size);
|
int32 preferredWidth = WidthForFontSize(size);
|
||||||
float charWidth = font.StringWidth("w");
|
if (preferredWidth > width)
|
||||||
if (charWidth * (kBlockSize * 4 + fPositionLength + 6) + 2 * kHorizontalSpace > width)
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if (size > 6)
|
if (size > 6)
|
||||||
steps = 1.0f;
|
steps = 1.0f;
|
||||||
}
|
}
|
||||||
size -= steps;
|
size -= steps;
|
||||||
font.SetSize(size);
|
|
||||||
|
|
||||||
if (oldSize != size) {
|
if (oldSize != size) {
|
||||||
|
BFont font = be_fixed_font;
|
||||||
|
font.SetSize(size);
|
||||||
SetFont(&font);
|
SetFont(&font);
|
||||||
|
|
||||||
Invalidate();
|
Invalidate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2004-2009, Axel Dörfler, [email protected].
|
* Copyright 2004-2015, 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
|
||||||
@@ -13,17 +13,20 @@
|
|||||||
|
|
||||||
class DataEditor;
|
class DataEditor;
|
||||||
|
|
||||||
|
|
||||||
enum base_type {
|
enum base_type {
|
||||||
kHexBase = 16,
|
kHexBase = 16,
|
||||||
kDecimalBase = 10
|
kDecimalBase = 10
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
enum view_focus {
|
enum view_focus {
|
||||||
kNoFocus,
|
kNoFocus,
|
||||||
kHexFocus,
|
kHexFocus,
|
||||||
kAsciiFocus
|
kAsciiFocus
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class DataView : public BView {
|
class DataView : public BView {
|
||||||
public:
|
public:
|
||||||
DataView(DataEditor& editor);
|
DataView(DataEditor& editor);
|
||||||
@@ -65,6 +68,8 @@ public:
|
|||||||
|
|
||||||
const uint8* DataAt(int32 start);
|
const uint8* DataAt(int32 start);
|
||||||
|
|
||||||
|
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,
|
||||||
@@ -90,7 +95,6 @@ private:
|
|||||||
void Paste();
|
void Paste();
|
||||||
|
|
||||||
DataEditor& fEditor;
|
DataEditor& fEditor;
|
||||||
int32 fPositionLength;
|
|
||||||
uint8* fData;
|
uint8* fData;
|
||||||
size_t fDataSize;
|
size_t fDataSize;
|
||||||
off_t fFileSize;
|
off_t fFileSize;
|
||||||
|
|||||||
@@ -1,16 +1,13 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2004-2007, Axel Dörfler, [email protected]. All rights reserved.
|
* Copyright 2004-2015, Axel Dörfler, [email protected].
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include "DiskProbe.h"
|
#include "DiskProbe.h"
|
||||||
#include "DataEditor.h"
|
|
||||||
#include "DataView.h"
|
#include <stdio.h>
|
||||||
#include "FileWindow.h"
|
#include <string.h>
|
||||||
#include "AttributeWindow.h"
|
|
||||||
#include "OpenWindow.h"
|
|
||||||
#include "FindWindow.h"
|
|
||||||
|
|
||||||
#include <AboutWindow.h>
|
#include <AboutWindow.h>
|
||||||
#include <Alert.h>
|
#include <Alert.h>
|
||||||
@@ -21,17 +18,24 @@
|
|||||||
#include <Entry.h>
|
#include <Entry.h>
|
||||||
#include <FilePanel.h>
|
#include <FilePanel.h>
|
||||||
#include <FindDirectory.h>
|
#include <FindDirectory.h>
|
||||||
|
#include <LayoutUtils.h>
|
||||||
#include <Locale.h>
|
#include <Locale.h>
|
||||||
#include <Path.h>
|
#include <Path.h>
|
||||||
#include <Screen.h>
|
#include <Screen.h>
|
||||||
#include <TextView.h>
|
#include <TextView.h>
|
||||||
|
|
||||||
#include <stdio.h>
|
#include "DataEditor.h"
|
||||||
#include <string.h>
|
#include "DataView.h"
|
||||||
|
#include "FileWindow.h"
|
||||||
|
#include "AttributeWindow.h"
|
||||||
|
#include "OpenWindow.h"
|
||||||
|
#include "FindWindow.h"
|
||||||
|
|
||||||
|
|
||||||
#undef B_TRANSLATION_CONTEXT
|
#undef B_TRANSLATION_CONTEXT
|
||||||
#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';
|
||||||
@@ -45,11 +49,13 @@ struct disk_probe_settings {
|
|||||||
int32 flags;
|
int32 flags;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
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();
|
||||||
@@ -100,11 +106,16 @@ Settings::Settings()
|
|||||||
fMessage(kMsgDiskProbeSettings),
|
fMessage(kMsgDiskProbeSettings),
|
||||||
fUpdated(false)
|
fUpdated(false)
|
||||||
{
|
{
|
||||||
|
float fontSize = be_plain_font->Size();
|
||||||
|
int32 windowWidth = DataView::WidthForFontSize(fontSize) + 20;
|
||||||
|
// TODO: make scrollbar width variable
|
||||||
|
|
||||||
BScreen screen;
|
BScreen screen;
|
||||||
fMessage.AddRect("window_frame", BRect(50, 50, screen.Frame().Width() - 50,
|
fMessage.AddRect("window_frame", BLayoutUtils::AlignInFrame(screen.Frame(),
|
||||||
screen.Frame().Height() - 50));
|
BSize(windowWidth, windowWidth),
|
||||||
|
BAlignment(B_ALIGN_HORIZONTAL_CENTER, B_ALIGN_VERTICAL_CENTER)));
|
||||||
fMessage.AddInt32("base_type", kHexBase);
|
fMessage.AddInt32("base_type", kHexBase);
|
||||||
fMessage.AddFloat("font_size", 12.0f);
|
fMessage.AddFloat("font_size", fontSize);
|
||||||
fMessage.AddBool("case_sensitive", true);
|
fMessage.AddBool("case_sensitive", true);
|
||||||
fMessage.AddInt8("find_mode", kAsciiMode);
|
fMessage.AddInt8("find_mode", kAsciiMode);
|
||||||
|
|
||||||
@@ -135,17 +146,17 @@ Settings::Settings()
|
|||||||
&& settings.window_frame.Height() < screen.Frame().Height())
|
&& settings.window_frame.Height() < screen.Frame().Height())
|
||||||
fMessage.ReplaceRect("window_frame", settings.window_frame);
|
fMessage.ReplaceRect("window_frame", settings.window_frame);
|
||||||
|
|
||||||
if (settings.base_type == kHexBase
|
if (settings.base_type == kHexBase
|
||||||
|| settings.base_type == kDecimalBase)
|
|| settings.base_type == kDecimalBase)
|
||||||
fMessage.ReplaceInt32("base_type",
|
fMessage.ReplaceInt32("base_type",
|
||||||
B_LENDIAN_TO_HOST_INT32(settings.base_type));
|
B_LENDIAN_TO_HOST_INT32(settings.base_type));
|
||||||
if (settings.font_size >= 0 && settings.font_size <= 72)
|
if (settings.font_size >= 0 && settings.font_size <= 72)
|
||||||
fMessage.ReplaceFloat("font_size",
|
fMessage.ReplaceFloat("font_size",
|
||||||
float(B_LENDIAN_TO_HOST_INT32(settings.font_size)));
|
float(B_LENDIAN_TO_HOST_INT32(settings.font_size)));
|
||||||
|
|
||||||
fMessage.ReplaceBool("case_sensitive",
|
fMessage.ReplaceBool("case_sensitive",
|
||||||
settings.flags & kCaseSensitive);
|
settings.flags & kCaseSensitive);
|
||||||
fMessage.ReplaceInt8("find_mode",
|
fMessage.ReplaceInt8("find_mode",
|
||||||
settings.flags & kHexFindMode ? kHexMode : kAsciiMode);
|
settings.flags & kHexFindMode ? kHexMode : kAsciiMode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -188,7 +199,7 @@ Settings::~Settings()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
Settings::Open(BFile *file, int32 mode)
|
Settings::Open(BFile *file, int32 mode)
|
||||||
{
|
{
|
||||||
BPath path;
|
BPath path;
|
||||||
@@ -201,7 +212,7 @@ Settings::Open(BFile *file, int32 mode)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
Settings::UpdateFrom(BMessage *message)
|
Settings::UpdateFrom(BMessage *message)
|
||||||
{
|
{
|
||||||
BRect frame;
|
BRect frame;
|
||||||
@@ -396,12 +407,12 @@ DiskProbe::ArgvReceived(int32 argc, char **argv)
|
|||||||
path.SetTo(¤tDirectory, argv[i]);
|
path.SetTo(¤tDirectory, argv[i]);
|
||||||
|
|
||||||
status_t status;
|
status_t status;
|
||||||
entry_ref ref;
|
entry_ref ref;
|
||||||
BEntry entry;
|
BEntry entry;
|
||||||
|
|
||||||
if ((status = entry.SetTo(path.Path(), false)) != B_OK
|
if ((status = entry.SetTo(path.Path(), false)) != B_OK
|
||||||
|| (status = entry.GetRef(&ref)) != B_OK) {
|
|| (status = entry.GetRef(&ref)) != B_OK) {
|
||||||
fprintf(stderr, B_TRANSLATE("Could not open file \"%s\": %s\n"),
|
fprintf(stderr, B_TRANSLATE("Could not open file \"%s\": %s\n"),
|
||||||
path.Path(), strerror(status));
|
path.Path(), strerror(status));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user