ProbeView accidently didn't listen to kDataViewPreferredSize events.

Implemented the "Fit" font size setting.


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@6773 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2004-02-27 17:14:53 +00:00
parent a7511f3654
commit 0a39d7d615
3 changed files with 59 additions and 16 deletions
+39 -5
View File
@@ -57,7 +57,8 @@ DataView::DataView(BRect rect, DataEditor &editor)
fEditor(editor), fEditor(editor),
fFocus(kHexFocus), fFocus(kHexFocus),
fBase(kHexBase), fBase(kHexBase),
fIsActive(true) fIsActive(true),
fFitFontSize(false)
{ {
fPositionLength = 4; fPositionLength = 4;
fStart = fEnd = 0; fStart = fEnd = 0;
@@ -816,6 +817,31 @@ DataView::UpdateScroller()
void void
DataView::FrameResized(float width, float height) 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)
break;
if (size > 6)
steps = 1.0f;
}
size -= steps;
font.SetSize(size);
if (oldSize != size) {
SetFont(&font);
Invalidate();
}
}
UpdateScroller(); UpdateScroller();
} }
@@ -1034,7 +1060,7 @@ DataView::SetFont(const BFont *font, uint32 properties)
return; return;
BView::SetFont(font, properties); BView::SetFont(font, properties);
font_height fontHeight; font_height fontHeight;
font->GetHeight(&fontHeight); font->GetHeight(&fontHeight);
@@ -1057,9 +1083,17 @@ DataView::FontSize() const
void void
DataView::SetFontSize(float point) DataView::SetFontSize(float point)
{ {
// ToDo: "fit" is not yet supported bool fit = (point == 0.0f);
if (point == 0.0f) if (fit) {
point = 12.0f; if (!fFitFontSize)
SendNotices(kDataViewPreferredSize);
fFitFontSize = fit;
FrameResized(Bounds().Width(), Bounds().Height());
return;
}
fFitFontSize = false;
BFont font = be_fixed_font; BFont font = be_fixed_font;
font.SetSize(point); font.SetSize(point);
+2
View File
@@ -46,6 +46,7 @@ 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);
bool FontSizeFitsBounds() const { return fFitFontSize; }
float FontSize() const; float FontSize() const;
void SetFontSize(float point); void SetFontSize(float point);
@@ -94,6 +95,7 @@ class DataView : public BView {
int32 fStart, fEnd; int32 fStart, fEnd;
int32 fMouseSelectionStart; int32 fMouseSelectionStart;
int32 fBitPosition; int32 fBitPosition;
bool fFitFontSize;
}; };
static const uint32 kMsgBaseType = 'base'; static const uint32 kMsgBaseType = 'base';
+18 -11
View File
@@ -921,13 +921,16 @@ ProbeView::UpdateSizeLimits()
if (Window() == NULL) if (Window() == NULL)
return; return;
float width, height; if (!fDataView->FontSizeFitsBounds()) {
fDataView->GetPreferredSize(&width, &height); float width, height;
fDataView->GetPreferredSize(&width, &height);
BRect frame = Window()->ConvertFromScreen(ConvertToScreen(fHeaderView->Frame())); BRect frame = Window()->ConvertFromScreen(ConvertToScreen(fHeaderView->Frame()));
Window()->SetSizeLimits(200, width + B_V_SCROLL_BAR_WIDTH, Window()->SetSizeLimits(200, width + B_V_SCROLL_BAR_WIDTH,
200, height + frame.bottom + 4 + B_H_SCROLL_BAR_HEIGHT); 200, height + frame.bottom + 4 + B_H_SCROLL_BAR_HEIGHT);
} else
Window()->SetSizeLimits(200, 32768, 200, 32768);
} }
@@ -941,6 +944,7 @@ ProbeView::DetachedFromWindow()
fEditor.StopWatching(this); fEditor.StopWatching(this);
fDataView->StopWatching(fHeaderView, kDataViewCursorPosition); fDataView->StopWatching(fHeaderView, kDataViewCursorPosition);
fDataView->StopWatching(this, kDataViewSelection); fDataView->StopWatching(this, kDataViewSelection);
fDataView->StopWatching(this, kDataViewPreferredSize);
be_clipboard->StopWatching(this); be_clipboard->StopWatching(this);
} }
@@ -1031,6 +1035,7 @@ ProbeView::AttachedToWindow()
fEditor.StartWatching(this); fEditor.StartWatching(this);
fDataView->StartWatching(fHeaderView, kDataViewCursorPosition); fDataView->StartWatching(fHeaderView, kDataViewCursorPosition);
fDataView->StartWatching(this, kDataViewSelection); fDataView->StartWatching(this, kDataViewSelection);
fDataView->StartWatching(this, kDataViewPreferredSize);
be_clipboard->StartWatching(this); be_clipboard->StartWatching(this);
// Add menu to window // Add menu to window
@@ -1161,8 +1166,11 @@ ProbeView::AttachedToWindow()
// Font Size // Font Size
subMenu = new BMenu("Font Size"); subMenu = new BMenu("Font Size");
subMenu->SetRadioMode(true);
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); int32 fontSize = int32(fDataView->FontSize() + 0.5);
if (fDataView->FontSizeFitsBounds())
fontSize = 0;
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]);
@@ -1172,12 +1180,12 @@ ProbeView::AttachedToWindow()
item->SetMarked(true); item->SetMarked(true);
} }
subMenu->AddSeparatorItem(); subMenu->AddSeparatorItem();
subMenu->AddItem(item = new BMenuItem("Fit", new BMessage(kMsgFontSize))); subMenu->AddItem(item = new BMenuItem("Fit", message = new BMessage(kMsgFontSize)));
message->AddFloat("font_size", 0.0f);
if (fontSize == 0) if (fontSize == 0)
item->SetMarked(true); item->SetMarked(true);
subMenu->SetTargetForItems(this); subMenu->SetTargetForItems(this);
subMenu->SetRadioMode(true);
menu->AddItem(new BMenuItem(subMenu)); menu->AddItem(new BMenuItem(subMenu));
bar->AddItem(menu); bar->AddItem(menu);
@@ -1407,10 +1415,9 @@ ProbeView::MessageReceived(BMessage *message)
case kMsgFontSize: case kMsgFontSize:
{ {
float size = 0.0f; float size;
message->FindFloat("font_size", &size); if (message->FindFloat("font_size", &size) != B_OK)
// if there is no "font_size" member, the size will break;
// be adapted to fit the window size (0)
fDataView->SetFontSize(size); fDataView->SetFontSize(size);