Implemented R5 compatible settings.

The number base type (hex or decimal) and the window frame is already
correctly maintained (font size is only displayed, but not yet changed).
I don't know the meaning of the last 4 bytes in DiskProbe_data, but
it's probably not that bad.


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@6714 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2004-02-24 08:52:35 +00:00
parent d11ec0829b
commit 7fff3ed096
11 changed files with 194 additions and 26 deletions
+3 -2
View File
@@ -13,7 +13,8 @@
#include <stdio.h> #include <stdio.h>
AttributeWindow::AttributeWindow(BRect rect, entry_ref *ref, const char *attribute) AttributeWindow::AttributeWindow(BRect rect, entry_ref *ref, const char *attribute,
const BMessage *settings)
: ProbeWindow(rect, ref), : ProbeWindow(rect, ref),
fAttribute(strdup(attribute)) fAttribute(strdup(attribute))
{ {
@@ -39,7 +40,7 @@ AttributeWindow::AttributeWindow(BRect rect, entry_ref *ref, const char *attribu
BRect rect = Bounds(); BRect rect = Bounds();
rect.top = menuBar->Bounds().Height() + 1; rect.top = menuBar->Bounds().Height() + 1;
ProbeView *probeView = new ProbeView(rect, ref, attribute); ProbeView *probeView = new ProbeView(rect, ref, attribute, settings);
probeView->AddFileMenuItems(menu, 0); probeView->AddFileMenuItems(menu, 0);
AddChild(probeView); AddChild(probeView);
+2 -1
View File
@@ -11,7 +11,8 @@
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 char *attribute = NULL,
const BMessage *settings = NULL);
virtual ~AttributeWindow(); virtual ~AttributeWindow();
bool Contains(const entry_ref &ref, const char *attribute); bool Contains(const entry_ref &ref, const char *attribute);
+14
View File
@@ -879,9 +879,23 @@ DataView::SetFont(const BFont *font, uint32 properties)
} }
float
DataView::FontSize() const
{
BFont font;
GetFont(&font);
return font.Size();
}
void void
DataView::SetFontSize(float point) DataView::SetFontSize(float point)
{ {
// ToDo: "fit" is not yet supported
if (point == 0.0f)
point = 12.0f;
BFont font = be_fixed_font; BFont font = be_fixed_font;
font.SetSize(point); font.SetSize(point);
+4 -2
View File
@@ -14,8 +14,8 @@
class DataEditor; class DataEditor;
enum base_type { enum base_type {
kHexBase, kHexBase = 16,
kDecimalBase kDecimalBase = 10
}; };
enum view_focus { enum view_focus {
@@ -46,7 +46,9 @@ class DataView : public BView {
virtual void SetFont(const BFont *font, uint32 properties = B_FONT_ALL); virtual void SetFont(const BFont *font, uint32 properties = B_FONT_ALL);
virtual void GetPreferredSize(float *_width, float *_height); virtual void GetPreferredSize(float *_width, float *_height);
float FontSize() const;
void SetFontSize(float point); void SetFontSize(float point);
void UpdateScroller(); void UpdateScroller();
void MakeVisible(int32 position); void MakeVisible(int32 position);
+129 -8
View File
@@ -6,6 +6,7 @@
#include "DiskProbe.h" #include "DiskProbe.h"
#include "DataEditor.h" #include "DataEditor.h"
#include "DataView.h"
#include "FileWindow.h" #include "FileWindow.h"
#include "AttributeWindow.h" #include "AttributeWindow.h"
#include "OpenWindow.h" #include "OpenWindow.h"
@@ -15,6 +16,7 @@
#include <Alert.h> #include <Alert.h>
#include <TextView.h> #include <TextView.h>
#include <FilePanel.h> #include <FilePanel.h>
#include <FindDirectory.h>
#include <Directory.h> #include <Directory.h>
#include <Entry.h> #include <Entry.h>
#include <Path.h> #include <Path.h>
@@ -27,6 +29,31 @@ static const char *kSignature = "application/x-vnd.OpenBeOS-DiskProbe";
static const uint32 kCascadeOffset = 20; static const uint32 kCascadeOffset = 20;
static const uint32 kMsgDiskProbeSettings = 'DPst';
struct disk_probe_settings {
BRect window_frame;
int32 base_type;
int32 font_size;
int32 unknown;
};
class Settings {
public:
Settings();
~Settings();
const BMessage &Message() const { return fMessage; }
void UpdateFrom(BMessage *message);
private:
status_t Open(BFile *file, int32 mode);
BMessage fMessage;
bool fUpdated;
};
class DiskProbe : public BApplication { class DiskProbe : public BApplication {
public: public:
@@ -45,25 +72,115 @@ class DiskProbe : public BApplication {
private: private:
status_t Probe(entry_ref &ref, const char *attribute = NULL); status_t Probe(entry_ref &ref, const char *attribute = NULL);
Settings fSettings;
BFilePanel *fFilePanel; BFilePanel *fFilePanel;
BWindow *fOpenWindow; BWindow *fOpenWindow;
uint32 fWindowCount; uint32 fWindowCount;
BRect fWindowPosition; BRect fWindowFrame;
}; };
//----------------- //-----------------
Settings::Settings()
:
fMessage(kMsgDiskProbeSettings),
fUpdated(false)
{
fMessage.AddRect("window_frame", BRect(50, 50, 550, 500));
fMessage.AddInt32("base_type", kHexBase);
fMessage.AddFloat("font_size", 12.0f);
BFile file;
if (Open(&file, B_READ_ONLY) != B_OK)
return;
// ToDo: load/save settings as flattened BMessage - but not yet,
// since that will break compatibility with R5's DiskProbe
disk_probe_settings settings;
if (file.Read(&settings, sizeof(settings)) == sizeof(settings)) {
#if B_HOST_IS_BENDIAN
// settings are saved in little endian
settings.window_frame.left = B_LENDIAN_TO_HOST_FLOAT(settings.window_frame.left);
settings.window_frame.top = B_LENDIAN_TO_HOST_FLOAT(settings.window_frame.top);
settings.window_frame.right = B_LENDIAN_TO_HOST_FLOAT(settings.window_frame.right);
settings.window_frame.bottom = B_LENDIAN_TO_HOST_FLOAT(settings.window_frame.bottom);
settings.base_type = B_LENDIAN_TO_HOST_INT32(settings.base_type);
settings.font_size = B_LENDIAN_TO_HOST_INT32(settings.font_size);
#endif
fMessage.ReplaceRect("window_frame", settings.window_frame);
fMessage.ReplaceInt32("base_type", settings.base_type);
fMessage.ReplaceFloat("font_size", (float)settings.font_size);
}
}
Settings::~Settings()
{
// only save the settings if something has changed
if (!fUpdated)
return;
BFile file;
if (Open(&file, B_CREATE_FILE | B_WRITE_ONLY) != B_OK)
return;
disk_probe_settings settings;
settings.window_frame = fMessage.FindRect("window_frame");
settings.base_type = fMessage.FindInt32("base_type");
settings.font_size = int32(fMessage.FindFloat("font_size") + 0.5f);
settings.unknown = 1;
// That's what DiskProbe R5 puts in there
file.Write(&settings, sizeof(settings));
}
status_t
Settings::Open(BFile *file, int32 mode)
{
BPath path;
if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) != B_OK)
return B_ERROR;
path.Append("DiskProbe_data");
return file->SetTo(path.Path(), mode);
}
void
Settings::UpdateFrom(BMessage *message)
{
BRect frame;
if (message->FindRect("window_frame", &frame) == B_OK)
fMessage.ReplaceRect("window_frame", frame);
int32 baseType;
if (message->FindInt32("base_type", &baseType) == B_OK)
fMessage.ReplaceInt32("base_type", baseType);
float fontSize;
if (message->FindFloat("font_size", &fontSize) == B_OK)
fMessage.ReplaceFloat("font_size", fontSize);
fUpdated = true;
}
// #pragma mark -
DiskProbe::DiskProbe() DiskProbe::DiskProbe()
: BApplication(kSignature), : BApplication(kSignature),
fOpenWindow(NULL), fOpenWindow(NULL),
fWindowCount(0), fWindowCount(0)
fWindowPosition(50, 50, 550, 500)
{ {
fFilePanel = new BFilePanel(); fFilePanel = new BFilePanel();
fWindowFrame = fSettings.Message().FindRect("window_frame");
// ToDo: maintain the window position on disk
} }
@@ -118,14 +235,14 @@ DiskProbe::Probe(entry_ref &ref, const char *attribute)
return status; return status;
// cascade window // cascade window
BRect rect = fWindowPosition; BRect rect = fWindowFrame;
rect.OffsetBy(probeWindows * kCascadeOffset, probeWindows * kCascadeOffset); rect.OffsetBy(probeWindows * kCascadeOffset, probeWindows * kCascadeOffset);
BWindow *window; BWindow *window;
if (attribute != NULL) if (attribute != NULL)
window = new AttributeWindow(rect, &ref, attribute); window = new AttributeWindow(rect, &ref, attribute, &fSettings.Message());
else else
window = new FileWindow(rect, &ref); window = new FileWindow(rect, &ref, &fSettings.Message());
window->Show(); window->Show();
fWindowCount++; fWindowCount++;
@@ -202,6 +319,10 @@ DiskProbe::MessageReceived(BMessage *message)
PostMessage(B_QUIT_REQUESTED); PostMessage(B_QUIT_REQUESTED);
break; break;
case kMsgSettingsChanged:
fSettings.UpdateFrom(message);
break;
case kMsgOpenFilePanel: case kMsgOpenFilePanel:
fFilePanel->Show(); fFilePanel->Show();
break; break;
+1
View File
@@ -13,5 +13,6 @@ static const uint32 kMsgOpenFilePanel = 'opFp';
static const uint32 kMsgOpenOpenWindow = 'opOw'; static const uint32 kMsgOpenOpenWindow = 'opOw';
static const uint32 kMsgOpenWindowClosed = 'clOw'; static const uint32 kMsgOpenWindowClosed = 'clOw';
static const uint32 kMsgWindowClosed = 'WiCl'; static const uint32 kMsgWindowClosed = 'WiCl';
static const uint32 kMsgSettingsChanged = 'SeCh';
#endif /* DISK_PROBE_H */ #endif /* DISK_PROBE_H */
+2 -2
View File
@@ -15,7 +15,7 @@
#include <Path.h> #include <Path.h>
FileWindow::FileWindow(BRect rect, entry_ref *ref) FileWindow::FileWindow(BRect rect, entry_ref *ref, const BMessage *settings)
: ProbeWindow(rect, ref) : ProbeWindow(rect, ref)
{ {
// Set alternative window title for devices // Set alternative window title for devices
@@ -59,7 +59,7 @@ FileWindow::FileWindow(BRect rect, entry_ref *ref)
BRect rect = Bounds(); BRect rect = Bounds();
rect.top = menuBar->Bounds().Height() + 1; rect.top = menuBar->Bounds().Height() + 1;
ProbeView *probeView = new ProbeView(rect, ref); ProbeView *probeView = new ProbeView(rect, ref, NULL, settings);
probeView->AddFileMenuItems(menu, menu->CountItems() - 4); probeView->AddFileMenuItems(menu, menu->CountItems() - 4);
AddChild(probeView); AddChild(probeView);
+1 -1
View File
@@ -11,7 +11,7 @@
class FileWindow : public ProbeWindow { class FileWindow : public ProbeWindow {
public: public:
FileWindow(BRect rect, entry_ref *ref); FileWindow(BRect rect, entry_ref *ref, const BMessage *settings = NULL);
virtual bool Contains(const entry_ref &ref, const char *attribute); virtual bool Contains(const entry_ref &ref, const char *attribute);
}; };
+32 -9
View File
@@ -6,6 +6,7 @@
#include "ProbeView.h" #include "ProbeView.h"
#include "DataView.h" #include "DataView.h"
#include "DiskProbe.h"
#define BEOS_R5_COMPATIBLE #define BEOS_R5_COMPATIBLE
// for SetLimits() // for SetLimits()
@@ -430,7 +431,7 @@ HeaderView::HeaderView(BRect frame, entry_ref *ref, DataEditor &editor)
rect.right += 100; rect.right += 100;
rect.OffsetBy(0, -2); rect.OffsetBy(0, -2);
// BTextControl oddities // BTextControl oddities
char buffer[16]; char buffer[16];
get_type_string(buffer, sizeof(buffer), editor.Type()); get_type_string(buffer, sizeof(buffer), editor.Type());
fTypeControl = new BTextControl(rect, B_EMPTY_STRING, NULL, buffer, new BMessage(kMsgPositionUpdate)); fTypeControl = new BTextControl(rect, B_EMPTY_STRING, NULL, buffer, new BMessage(kMsgPositionUpdate));
@@ -832,14 +833,22 @@ UpdateLooper::MessageReceived(BMessage *message)
// #pragma mark - // #pragma mark -
ProbeView::ProbeView(BRect rect, entry_ref *ref, const char *attribute) ProbeView::ProbeView(BRect rect, entry_ref *ref, const char *attribute, const BMessage *settings)
: BView(rect, "probeView", B_FOLLOW_ALL, B_WILL_DRAW) : BView(rect, "probeView", B_FOLLOW_ALL, B_WILL_DRAW)
{ {
fEditor.SetTo(*ref, attribute); fEditor.SetTo(*ref, attribute);
int32 baseType = kHexBase;
float fontSize = 12.0f;
if (settings != NULL) {
settings->FindInt32("base_type", &baseType);
settings->FindFloat("font_size", &fontSize);
}
rect = Bounds(); rect = Bounds();
fHeaderView = new HeaderView(rect, ref, fEditor); fHeaderView = new HeaderView(rect, ref, fEditor);
fHeaderView->ResizeToPreferred(); fHeaderView->ResizeToPreferred();
fHeaderView->SetBase((base_type)baseType);
AddChild(fHeaderView); AddChild(fHeaderView);
rect = fHeaderView->Frame(); rect = fHeaderView->Frame();
@@ -847,6 +856,8 @@ ProbeView::ProbeView(BRect rect, entry_ref *ref, const char *attribute)
rect.bottom = Bounds().bottom - B_H_SCROLL_BAR_HEIGHT; rect.bottom = Bounds().bottom - B_H_SCROLL_BAR_HEIGHT;
rect.right -= B_V_SCROLL_BAR_WIDTH; rect.right -= B_V_SCROLL_BAR_WIDTH;
fDataView = new DataView(rect, fEditor); fDataView = new DataView(rect, fEditor);
fDataView->SetBase((base_type)baseType);
fDataView->SetFontSize(fontSize);
fScrollView = new BScrollView("scroller", fDataView, B_FOLLOW_ALL, B_WILL_DRAW, true, true); fScrollView = new BScrollView("scroller", fDataView, B_FOLLOW_ALL, B_WILL_DRAW, true, true);
AddChild(fScrollView); AddChild(fScrollView);
@@ -1046,14 +1057,14 @@ ProbeView::AttachedToWindow()
subMenu = new BMenu("Base"); subMenu = new BMenu("Base");
message = new BMessage(kMsgBaseType); message = new BMessage(kMsgBaseType);
message->AddInt32("base", kDecimalBase); message->AddInt32("base_type", kDecimalBase);
subMenu->AddItem(item = new BMenuItem("Decimal", message, 'D', B_COMMAND_KEY)); subMenu->AddItem(item = new BMenuItem("Decimal", message, 'D', B_COMMAND_KEY));
item->SetTarget(this); item->SetTarget(this);
if (fHeaderView->Base() == kDecimalBase) if (fHeaderView->Base() == kDecimalBase)
item->SetMarked(true); item->SetMarked(true);
message = new BMessage(kMsgBaseType); message = new BMessage(kMsgBaseType);
message->AddInt32("base", kHexBase); message->AddInt32("base_type", kHexBase);
subMenu->AddItem(item = new BMenuItem("Hex", message, 'H', B_COMMAND_KEY)); subMenu->AddItem(item = new BMenuItem("Hex", message, 'H', B_COMMAND_KEY));
item->SetTarget(this); item->SetTarget(this);
if (fHeaderView->Base() == kHexBase) if (fHeaderView->Base() == kHexBase)
@@ -1073,15 +1084,22 @@ ProbeView::AttachedToWindow()
subMenu = new BMenu("Font Size"); subMenu = new BMenu("Font Size");
const int32 fontSizes[] = {9, 10, 12, 14, 18, 24, 36, 48}; const int32 fontSizes[] = {9, 10, 12, 14, 18, 24, 36, 48};
int32 fontSize = int32(fDataView->FontSize() + 0.5);
for (uint32 i = 0; i < sizeof(fontSizes) / sizeof(fontSizes[0]); i++) { for (uint32 i = 0; i < sizeof(fontSizes) / sizeof(fontSizes[0]); i++) {
char buffer[16]; char buffer[16];
snprintf(buffer, sizeof(buffer), "%ld", fontSizes[i]); snprintf(buffer, sizeof(buffer), "%ld", fontSizes[i]);
subMenu->AddItem(new BMenuItem(buffer, NULL)); subMenu->AddItem(item = new BMenuItem(buffer, NULL));
if (fontSizes[i] == fontSize)
item->SetMarked(true);
} }
subMenu->AddSeparatorItem(); subMenu->AddSeparatorItem();
subMenu->AddItem(new BMenuItem("Fit", NULL)); subMenu->AddItem(item = new BMenuItem("Fit", NULL));
if (fontSize == 0)
item->SetMarked(true);
subMenu->SetRadioMode(true);
menu->AddItem(new BMenuItem(subMenu)); menu->AddItem(new BMenuItem(subMenu));
bar->AddItem(menu); bar->AddItem(menu);
} }
@@ -1093,7 +1111,7 @@ ProbeView::AllAttached()
} }
void void
ProbeView::WindowActivated(bool active) ProbeView::WindowActivated(bool active)
{ {
if (active) if (active)
@@ -1101,7 +1119,7 @@ ProbeView::WindowActivated(bool active)
} }
void void
ProbeView::CheckClipboard() ProbeView::CheckClipboard()
{ {
if (!be_clipboard->Lock()) if (!be_clipboard->Lock())
@@ -1130,11 +1148,16 @@ ProbeView::MessageReceived(BMessage *message)
case kMsgBaseType: case kMsgBaseType:
{ {
int32 type; int32 type;
if (message->FindInt32("base", &type) != B_OK) if (message->FindInt32("base_type", &type) != B_OK)
break; break;
fHeaderView->SetBase((base_type)type); fHeaderView->SetBase((base_type)type);
fDataView->SetBase((base_type)type); fDataView->SetBase((base_type)type);
// update the applications settings
BMessage update(*message);
update.what = kMsgSettingsChanged;
be_app_messenger.SendMessage(&update);
break; break;
} }
+2 -1
View File
@@ -23,7 +23,8 @@ class UpdateLooper;
class ProbeView : public BView { class ProbeView : public BView {
public: public:
ProbeView(BRect rect, entry_ref *ref, const char *attribute = NULL); ProbeView(BRect rect, entry_ref *ref, const char *attribute = NULL,
const BMessage *settings = NULL);
virtual ~ProbeView(); virtual ~ProbeView();
virtual void DetachedFromWindow(); virtual void DetachedFromWindow();
+4
View File
@@ -39,6 +39,10 @@ ProbeWindow::MessageReceived(BMessage *message)
bool bool
ProbeWindow::QuitRequested() ProbeWindow::QuitRequested()
{ {
BMessage update(kMsgSettingsChanged);
update.AddRect("window_frame", Frame());
be_app_messenger.SendMessage(&update);
be_app_messenger.SendMessage(kMsgWindowClosed); be_app_messenger.SendMessage(kMsgWindowClosed);
return true; return true;
} }