Added a ScrollView to let the window appear more complete :)

The gradient below the header is now drawn by the scroll view, and no longer
by the HeaderView.
The ProbeView can now add a BMenuBar to a window if there is none yet - it
will also create a file menu there and add its print menu items (which is
now in a separated method and called by the ProbeWindow, too).


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@6555 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler 2004-02-10 20:10:13 +00:00
parent f8e65da910
commit 416271b759
3 changed files with 54 additions and 26 deletions

View File

@ -17,6 +17,7 @@
#include <Box.h>
#include <MenuBar.h>
#include <MenuItem.h>
#include <ScrollView.h>
#include <String.h>
#include <Entry.h>
#include <Path.h>
@ -323,19 +324,12 @@ void
HeaderView::Draw(BRect updateRect)
{
BRect rect = Bounds();
rect.bottom -= 2;
SetHighColor(ui_color(B_SHINE_COLOR));
StrokeLine(rect.LeftTop(), rect.LeftBottom());
StrokeLine(rect.LeftTop(), rect.RightTop());
rect.bottom++;
SetHighColor(tint_color(ViewColor(), B_DARKEN_1_TINT));
StrokeLine(rect.LeftBottom(), rect.RightBottom());
rect.bottom++;
SetHighColor(tint_color(ViewColor(), B_DARKEN_2_TINT));
StrokeLine(rect.LeftBottom(), rect.RightBottom());
// the gradient at the bottom is drawn by the BScrollView
}
@ -345,7 +339,7 @@ HeaderView::GetPreferredSize(float *_width, float *_height)
if (_width)
*_width = Bounds().Width();
if (_height)
*_height = fPositionSlider->Frame().bottom + 4;
*_height = fPositionSlider->Frame().bottom + 2;
}
@ -353,7 +347,8 @@ HeaderView::GetPreferredSize(float *_width, float *_height)
ProbeView::ProbeView(BRect rect, entry_ref *ref, const char *attribute)
: BView(rect, "probeView", B_FOLLOW_ALL, B_WILL_DRAW)
: BView(rect, "probeView", B_FOLLOW_ALL, B_WILL_DRAW),
fAttribute(attribute)
{
BNode node(ref);
@ -369,10 +364,18 @@ ProbeView::ProbeView(BRect rect, entry_ref *ref, const char *attribute)
fIsDevice = (stat.st_mode & (S_IFBLK | S_IFCHR)) != 0;
rect = Bounds();
rect.bottom = rect.top + 62;
fHeaderView = new HeaderView(rect, ref, fIsDevice);
fHeaderView = new HeaderView(rect, ref, fIsDevice, attribute ? fAttribute.String() : NULL);
fHeaderView->ResizeToPreferred();
AddChild(fHeaderView);
rect = fHeaderView->Frame();
rect.top = rect.bottom + 3;
rect.bottom = Bounds().bottom - B_H_SCROLL_BAR_HEIGHT;
rect.right -= B_V_SCROLL_BAR_WIDTH;
BView *view = new BView(rect, "text", B_FOLLOW_NONE, B_WILL_DRAW);
fScrollView = new BScrollView("scroller", view, B_FOLLOW_ALL, B_WILL_DRAW, true, true);
AddChild(fScrollView);
}
@ -382,14 +385,38 @@ ProbeView::~ProbeView()
}
void
ProbeView::AddFileMenuItems(BMenu *menu, int32 index)
{
BMenuItem *item;
menu->AddItem(item = new BMenuItem("Page Setup" B_UTF8_ELLIPSIS, NULL), index++);
item->SetEnabled(false);
menu->AddItem(item = new BMenuItem("Print" B_UTF8_ELLIPSIS, NULL, 'P', B_COMMAND_KEY), index++);
item->SetEnabled(false);
}
void
ProbeView::AttachedToWindow()
{
// Add menu to window
BMenuBar *bar = Window()->KeyMenuBar();
if (bar == NULL)
return;
if (bar == NULL) {
// there is none? Well, but we really want to have one
bar = new BMenuBar(BRect(0, 0, 0, 0), NULL);
Window()->AddChild(bar);
MoveBy(0, bar->Bounds().Height());
ResizeBy(0, -bar->Bounds().Height());
BMenu *menu = new BMenu(fAttribute.Length() > 0 ? "Attribute" : fIsDevice ? "Device" : "File");
AddFileMenuItems(menu, 0);
menu->AddSeparatorItem();
menu->AddItem(new BMenuItem("Close", new BMessage(B_QUIT_REQUESTED), 'W', B_COMMAND_KEY));
bar->AddItem(menu);
}
BMenu *menu = new BMenu("Edit");
menu->AddItem(new BMenuItem("Undo", NULL, 'Z', B_COMMAND_KEY));

View File

@ -7,11 +7,11 @@
#include <View.h>
#include <String.h>
#include <Path.h>
class BTextControl;
class BStringView;
class BSlider;
class BScrollView;
class HeaderView;
@ -24,9 +24,13 @@ class ProbeView : public BView {
virtual void AttachedToWindow();
virtual void MessageReceived(BMessage *message);
void AddFileMenuItems(BMenu *menu, int32 index);
private:
BString fAttribute;
bool fIsDevice;
HeaderView *fHeaderView;
BScrollView *fScrollView;
};
#endif /* PROBE_WINDOW_H */

View File

@ -36,7 +36,7 @@ ProbeWindow::ProbeWindow(BRect rect, entry_ref *ref, const char *attribute)
}
// add the menu
BMenuBar *menuBar = new BMenuBar(BRect(0, 0, 0, 0), NULL);
AddChild(menuBar);
@ -53,11 +53,7 @@ ProbeWindow::ProbeWindow(BRect rect, entry_ref *ref, const char *attribute)
new BMessage(kMsgOpenFilePanel), 'O', B_COMMAND_KEY));
menu->AddSeparatorItem();
BMenuItem *item;
menu->AddItem(item = new BMenuItem("Page Setup" B_UTF8_ELLIPSIS, NULL));
item->SetEnabled(false);
menu->AddItem(item = new BMenuItem("Print" B_UTF8_ELLIPSIS, NULL, 'P', B_COMMAND_KEY));
item->SetEnabled(false);
// the ProbeView file menu items will be inserted here
menu->AddSeparatorItem();
menu->AddItem(new BMenuItem("About DiskProbe" B_UTF8_ELLIPSIS, new BMessage(B_ABOUT_REQUESTED)));
@ -71,8 +67,9 @@ ProbeWindow::ProbeWindow(BRect rect, entry_ref *ref, const char *attribute)
BRect rect = Bounds();
rect.top = menuBar->Bounds().Height() + 1;
BView *view = new ProbeView(rect, ref, attribute);
AddChild(view);
ProbeView *probeView = new ProbeView(rect, ref, attribute);
probeView->AddFileMenuItems(menu, menu->CountItems() - 4);
AddChild(probeView);
}