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
+42 -15
View File
@@ -17,6 +17,7 @@
#include <Box.h> #include <Box.h>
#include <MenuBar.h> #include <MenuBar.h>
#include <MenuItem.h> #include <MenuItem.h>
#include <ScrollView.h>
#include <String.h> #include <String.h>
#include <Entry.h> #include <Entry.h>
#include <Path.h> #include <Path.h>
@@ -323,19 +324,12 @@ void
HeaderView::Draw(BRect updateRect) HeaderView::Draw(BRect updateRect)
{ {
BRect rect = Bounds(); BRect rect = Bounds();
rect.bottom -= 2;
SetHighColor(ui_color(B_SHINE_COLOR)); SetHighColor(ui_color(B_SHINE_COLOR));
StrokeLine(rect.LeftTop(), rect.LeftBottom()); StrokeLine(rect.LeftTop(), rect.LeftBottom());
StrokeLine(rect.LeftTop(), rect.RightTop()); StrokeLine(rect.LeftTop(), rect.RightTop());
rect.bottom++; // the gradient at the bottom is drawn by the BScrollView
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());
} }
@@ -345,7 +339,7 @@ HeaderView::GetPreferredSize(float *_width, float *_height)
if (_width) if (_width)
*_width = Bounds().Width(); *_width = Bounds().Width();
if (_height) 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) 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); 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; fIsDevice = (stat.st_mode & (S_IFBLK | S_IFCHR)) != 0;
rect = Bounds(); rect = Bounds();
rect.bottom = rect.top + 62; fHeaderView = new HeaderView(rect, ref, fIsDevice, attribute ? fAttribute.String() : NULL);
fHeaderView = new HeaderView(rect, ref, fIsDevice);
fHeaderView->ResizeToPreferred(); fHeaderView->ResizeToPreferred();
AddChild(fHeaderView); 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 void
ProbeView::AttachedToWindow() ProbeView::AttachedToWindow()
{ {
// Add menu to window // Add menu to window
BMenuBar *bar = Window()->KeyMenuBar(); BMenuBar *bar = Window()->KeyMenuBar();
if (bar == NULL) if (bar == NULL) {
return; // 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"); BMenu *menu = new BMenu("Edit");
menu->AddItem(new BMenuItem("Undo", NULL, 'Z', B_COMMAND_KEY)); menu->AddItem(new BMenuItem("Undo", NULL, 'Z', B_COMMAND_KEY));
+7 -3
View File
@@ -7,11 +7,11 @@
#include <View.h> #include <View.h>
#include <String.h>
#include <Path.h> #include <Path.h>
class BTextControl;
class BStringView; class BScrollView;
class BSlider;
class HeaderView; class HeaderView;
@@ -24,9 +24,13 @@ class ProbeView : public BView {
virtual void AttachedToWindow(); virtual void AttachedToWindow();
virtual void MessageReceived(BMessage *message); virtual void MessageReceived(BMessage *message);
void AddFileMenuItems(BMenu *menu, int32 index);
private: private:
BString fAttribute;
bool fIsDevice; bool fIsDevice;
HeaderView *fHeaderView; HeaderView *fHeaderView;
BScrollView *fScrollView;
}; };
#endif /* PROBE_WINDOW_H */ #endif /* PROBE_WINDOW_H */
+5 -8
View File
@@ -36,7 +36,7 @@ ProbeWindow::ProbeWindow(BRect rect, entry_ref *ref, const char *attribute)
} }
// add the menu // add the menu
BMenuBar *menuBar = new BMenuBar(BRect(0, 0, 0, 0), NULL); BMenuBar *menuBar = new BMenuBar(BRect(0, 0, 0, 0), NULL);
AddChild(menuBar); AddChild(menuBar);
@@ -53,11 +53,7 @@ ProbeWindow::ProbeWindow(BRect rect, entry_ref *ref, const char *attribute)
new BMessage(kMsgOpenFilePanel), 'O', B_COMMAND_KEY)); new BMessage(kMsgOpenFilePanel), 'O', B_COMMAND_KEY));
menu->AddSeparatorItem(); menu->AddSeparatorItem();
BMenuItem *item; // the ProbeView file menu items will be inserted here
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);
menu->AddSeparatorItem(); menu->AddSeparatorItem();
menu->AddItem(new BMenuItem("About DiskProbe" B_UTF8_ELLIPSIS, new BMessage(B_ABOUT_REQUESTED))); 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(); BRect rect = Bounds();
rect.top = menuBar->Bounds().Height() + 1; rect.top = menuBar->Bounds().Height() + 1;
BView *view = new ProbeView(rect, ref, attribute); ProbeView *probeView = new ProbeView(rect, ref, attribute);
AddChild(view); probeView->AddFileMenuItems(menu, menu->CountItems() - 4);
AddChild(probeView);
} }