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.
|
||||
*/
|
||||
|
||||
|
||||
#include "DataView.h"
|
||||
#include "DataEditor.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <Window.h>
|
||||
#include <ScrollBar.h>
|
||||
#include <Autolock.h>
|
||||
#include <Beep.h>
|
||||
#include <Clipboard.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;
|
||||
// TODO: use variable spacing
|
||||
static const uint32 kHorizontalSpace = 8;
|
||||
static const uint32 kVerticalSpace = 4;
|
||||
static const uint32 kPositionLength = 4;
|
||||
|
||||
static const uint32 kBlockSpace = 3;
|
||||
static const uint32 kHexByteWidth = 3;
|
||||
@@ -106,7 +105,6 @@ DataView::DataView(DataEditor &editor)
|
||||
fFitFontSize(false),
|
||||
fDragMessageSize(-1)
|
||||
{
|
||||
fPositionLength = 4;
|
||||
fStart = fEnd = 0;
|
||||
|
||||
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*"
|
||||
B_PRIdOFF": ", (int)fPositionLength, offset);
|
||||
B_PRIdOFF": ", (int)kPositionLength, offset);
|
||||
|
||||
for (uint32 i = 0; i < kBlockSize; i++) {
|
||||
if (i >= size) {
|
||||
@@ -412,7 +410,7 @@ BRect
|
||||
DataView::DataBounds(bool inView) const
|
||||
{
|
||||
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)
|
||||
+ 2 * kVerticalSpace);
|
||||
}
|
||||
@@ -434,7 +432,7 @@ DataView::PositionAt(view_focus focus, BPoint point, view_focus *_newFocus)
|
||||
else if (point.y >= bounds.bottom - kVerticalSpace)
|
||||
point.y = bounds.bottom - kVerticalSpace - 1;
|
||||
|
||||
float left = fCharWidth * (fPositionLength + kBlockSpace) + kHorizontalSpace;
|
||||
float left = fCharWidth * (kPositionLength + kBlockSpace) + kHorizontalSpace;
|
||||
float hexWidth = fCharWidth * kBlockSize * kHexByteWidth;
|
||||
float width = fCharWidth;
|
||||
|
||||
@@ -478,11 +476,11 @@ DataView::SelectionFrame(view_focus which, int32 start, int32 end)
|
||||
|
||||
if (which == kHexFocus) {
|
||||
spacing = fCharWidth / 2;
|
||||
left = width * (fPositionLength + kBlockSpace);
|
||||
left = width * (kPositionLength + kBlockSpace);
|
||||
width *= kHexByteWidth;
|
||||
byteWidth *= 2;
|
||||
} else
|
||||
left = width * (fPositionLength + 2 * kBlockSpace + kHexByteWidth * kBlockSize);
|
||||
left = width * (kPositionLength + 2 * kBlockSpace + kHexByteWidth * kBlockSize);
|
||||
|
||||
left += kHorizontalSpace;
|
||||
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
|
||||
DataView::SetBase(base_type type)
|
||||
{
|
||||
@@ -942,24 +952,24 @@ DataView::FrameResized(float width, float height)
|
||||
if (fFitFontSize) {
|
||||
// adapt the font size to fit in the view's bounds
|
||||
float oldSize = FontSize();
|
||||
BFont font = be_fixed_font;
|
||||
float steps = 0.5f;
|
||||
|
||||
float size;
|
||||
for (size = 1.f; size < 100; size += steps) {
|
||||
font.SetSize(size);
|
||||
float charWidth = font.StringWidth("w");
|
||||
if (charWidth * (kBlockSize * 4 + fPositionLength + 6) + 2 * kHorizontalSpace > width)
|
||||
int32 preferredWidth = WidthForFontSize(size);
|
||||
if (preferredWidth > width)
|
||||
break;
|
||||
|
||||
if (size > 6)
|
||||
steps = 1.0f;
|
||||
}
|
||||
size -= steps;
|
||||
font.SetSize(size);
|
||||
|
||||
if (oldSize != size) {
|
||||
BFont font = be_fixed_font;
|
||||
font.SetSize(size);
|
||||
SetFont(&font);
|
||||
|
||||
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.
|
||||
*/
|
||||
#ifndef DATA_VIEW_H
|
||||
@@ -13,17 +13,20 @@
|
||||
|
||||
class DataEditor;
|
||||
|
||||
|
||||
enum base_type {
|
||||
kHexBase = 16,
|
||||
kDecimalBase = 10
|
||||
};
|
||||
|
||||
|
||||
enum view_focus {
|
||||
kNoFocus,
|
||||
kHexFocus,
|
||||
kAsciiFocus
|
||||
};
|
||||
|
||||
|
||||
class DataView : public BView {
|
||||
public:
|
||||
DataView(DataEditor& editor);
|
||||
@@ -65,6 +68,8 @@ public:
|
||||
|
||||
const uint8* DataAt(int32 start);
|
||||
|
||||
static int32 WidthForFontSize(float size);
|
||||
|
||||
private:
|
||||
BRect DataBounds(bool inView = false) const;
|
||||
BRect SelectionFrame(view_focus which, int32 start,
|
||||
@@ -90,7 +95,6 @@ private:
|
||||
void Paste();
|
||||
|
||||
DataEditor& fEditor;
|
||||
int32 fPositionLength;
|
||||
uint8* fData;
|
||||
size_t fDataSize;
|
||||
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.
|
||||
*/
|
||||
|
||||
|
||||
#include "DiskProbe.h"
|
||||
#include "DataEditor.h"
|
||||
#include "DataView.h"
|
||||
#include "FileWindow.h"
|
||||
#include "AttributeWindow.h"
|
||||
#include "OpenWindow.h"
|
||||
#include "FindWindow.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <AboutWindow.h>
|
||||
#include <Alert.h>
|
||||
@@ -21,17 +18,24 @@
|
||||
#include <Entry.h>
|
||||
#include <FilePanel.h>
|
||||
#include <FindDirectory.h>
|
||||
#include <LayoutUtils.h>
|
||||
#include <Locale.h>
|
||||
#include <Path.h>
|
||||
#include <Screen.h>
|
||||
#include <TextView.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "DataEditor.h"
|
||||
#include "DataView.h"
|
||||
#include "FileWindow.h"
|
||||
#include "AttributeWindow.h"
|
||||
#include "OpenWindow.h"
|
||||
#include "FindWindow.h"
|
||||
|
||||
|
||||
#undef B_TRANSLATION_CONTEXT
|
||||
#define B_TRANSLATION_CONTEXT "DiskProbe"
|
||||
|
||||
|
||||
const char *kSignature = "application/x-vnd.Haiku-DiskProbe";
|
||||
|
||||
static const uint32 kMsgDiskProbeSettings = 'DPst';
|
||||
@@ -45,11 +49,13 @@ struct disk_probe_settings {
|
||||
int32 flags;
|
||||
};
|
||||
|
||||
|
||||
enum disk_probe_flags {
|
||||
kCaseSensitive = 0x01, // this flag alone is R5 DiskProbe settings compatible
|
||||
kHexFindMode = 0x02,
|
||||
};
|
||||
|
||||
|
||||
class Settings {
|
||||
public:
|
||||
Settings();
|
||||
@@ -100,11 +106,16 @@ Settings::Settings()
|
||||
fMessage(kMsgDiskProbeSettings),
|
||||
fUpdated(false)
|
||||
{
|
||||
float fontSize = be_plain_font->Size();
|
||||
int32 windowWidth = DataView::WidthForFontSize(fontSize) + 20;
|
||||
// TODO: make scrollbar width variable
|
||||
|
||||
BScreen screen;
|
||||
fMessage.AddRect("window_frame", BRect(50, 50, screen.Frame().Width() - 50,
|
||||
screen.Frame().Height() - 50));
|
||||
fMessage.AddRect("window_frame", BLayoutUtils::AlignInFrame(screen.Frame(),
|
||||
BSize(windowWidth, windowWidth),
|
||||
BAlignment(B_ALIGN_HORIZONTAL_CENTER, B_ALIGN_VERTICAL_CENTER)));
|
||||
fMessage.AddInt32("base_type", kHexBase);
|
||||
fMessage.AddFloat("font_size", 12.0f);
|
||||
fMessage.AddFloat("font_size", fontSize);
|
||||
fMessage.AddBool("case_sensitive", true);
|
||||
fMessage.AddInt8("find_mode", kAsciiMode);
|
||||
|
||||
@@ -135,17 +146,17 @@ Settings::Settings()
|
||||
&& settings.window_frame.Height() < screen.Frame().Height())
|
||||
fMessage.ReplaceRect("window_frame", settings.window_frame);
|
||||
|
||||
if (settings.base_type == kHexBase
|
||||
if (settings.base_type == kHexBase
|
||||
|| settings.base_type == kDecimalBase)
|
||||
fMessage.ReplaceInt32("base_type",
|
||||
fMessage.ReplaceInt32("base_type",
|
||||
B_LENDIAN_TO_HOST_INT32(settings.base_type));
|
||||
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)));
|
||||
|
||||
fMessage.ReplaceBool("case_sensitive",
|
||||
fMessage.ReplaceBool("case_sensitive",
|
||||
settings.flags & kCaseSensitive);
|
||||
fMessage.ReplaceInt8("find_mode",
|
||||
fMessage.ReplaceInt8("find_mode",
|
||||
settings.flags & kHexFindMode ? kHexMode : kAsciiMode);
|
||||
}
|
||||
}
|
||||
@@ -188,7 +199,7 @@ Settings::~Settings()
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
status_t
|
||||
Settings::Open(BFile *file, int32 mode)
|
||||
{
|
||||
BPath path;
|
||||
@@ -201,7 +212,7 @@ Settings::Open(BFile *file, int32 mode)
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
void
|
||||
Settings::UpdateFrom(BMessage *message)
|
||||
{
|
||||
BRect frame;
|
||||
@@ -396,12 +407,12 @@ DiskProbe::ArgvReceived(int32 argc, char **argv)
|
||||
path.SetTo(¤tDirectory, argv[i]);
|
||||
|
||||
status_t status;
|
||||
entry_ref ref;
|
||||
entry_ref ref;
|
||||
BEntry entry;
|
||||
|
||||
if ((status = entry.SetTo(path.Path(), false)) != 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));
|
||||
continue;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user