* Use the layout system to build the gui, fixes #4768.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@35099 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Karsten Heimrich
2010-01-16 16:14:57 +00:00
parent 0bce4bb917
commit 7284ad2919
2 changed files with 98 additions and 125 deletions
+92 -121
View File
@@ -1,5 +1,6 @@
/* /*
* Copyright 2004-2006, Jérôme DUVAL. All rights reserved. * Copyright 2004-2006, Jérôme DUVAL. All rights reserved.
* Copyright 2010, Karsten Heimrich. All rights reserved.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*/ */
@@ -15,8 +16,11 @@
#include <Box.h> #include <Box.h>
#include <Button.h> #include <Button.h>
#include <CheckBox.h> #include <CheckBox.h>
#include <ControlLook.h>
#include <Entry.h> #include <Entry.h>
#include <File.h> #include <File.h>
#include <GroupLayout.h>
#include <GroupLayoutBuilder.h>
#include <Menu.h> #include <Menu.h>
#include <MenuBar.h> #include <MenuBar.h>
#include <MenuItem.h> #include <MenuItem.h>
@@ -51,126 +55,60 @@ ExpanderWindow::ExpanderWindow(BRect frame, const entry_ref* ref,
fSettings(*settings), fSettings(*settings),
fPreferences(NULL) fPreferences(NULL)
{ {
// create menu bar BGroupLayout* layout = new BGroupLayout(B_VERTICAL);
fBar = new BMenuBar(BRect(0, 0, Bounds().right, 20), "menu_bar"); SetLayout(layout);
BMenu* menu = new BMenu("File");
BMenuItem* item;
menu->AddItem(item = new BMenuItem("About Expander" B_UTF8_ELLIPSIS,
new BMessage(B_ABOUT_REQUESTED)));
item->SetTarget(be_app_messenger);
menu->AddSeparatorItem();
menu->AddItem(fSourceItem = new BMenuItem("Set source" B_UTF8_ELLIPSIS,
new BMessage(MSG_SOURCE), 'O'));
menu->AddItem(fDestItem = new BMenuItem("Set destination" B_UTF8_ELLIPSIS,
new BMessage(MSG_DEST), 'D'));
menu->AddSeparatorItem();
menu->AddItem(fExpandItem = new BMenuItem("Expand", new BMessage(MSG_EXPAND),
'E'));
fExpandItem->SetEnabled(false);
menu->AddItem(fShowItem = new BMenuItem("Show contents",
new BMessage(MSG_SHOW), 'L'));
fShowItem->SetEnabled(false);
menu->AddSeparatorItem();
menu->AddItem(fStopItem = new BMenuItem("Stop", new BMessage(MSG_STOP), 'K'));
fStopItem->SetEnabled(false);
menu->AddSeparatorItem();
menu->AddItem(new BMenuItem("Close", new BMessage(B_QUIT_REQUESTED), 'W'));
fBar->AddItem(menu);
menu = new BMenu("Settings"); _AddMenuBar(layout);
menu->AddItem(fPreferencesItem = new BMenuItem("Settings" B_UTF8_ELLIPSIS,
new BMessage(MSG_PREFERENCES), 'S'));
fBar->AddItem(menu);
AddChild(fBar);
BRect rect = Bounds(); fDestButton = new BButton("Destination", new BMessage(MSG_DEST));
rect.top += fBar->Bounds().Height() + 1; fSourceButton = new BButton("Source", new BMessage(MSG_SOURCE));
BView* topView = new BView(rect, "background", B_FOLLOW_ALL, B_WILL_DRAW); fExpandButton = new BButton("Expand", new BMessage(MSG_EXPAND));
topView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
AddChild(topView);
// Buttons BSize size = fDestButton->PreferredSize();
size.width = max_c(size.width, fSourceButton->PreferredSize().width);
size.width = max_c(size.width, fExpandButton->PreferredSize().width);
rect = topView->Bounds().InsetByCopy(8, 8); fDestButton->SetExplicitMaxSize(size);
fDestButton = new BButton(rect, "destButton", "Destination", fSourceButton->SetExplicitMaxSize(size);
new BMessage(MSG_DEST), B_FOLLOW_LEFT | B_FOLLOW_TOP); fExpandButton->SetExplicitMaxSize(size);
fDestButton->ResizeToPreferred();
rect = fDestButton->Frame(); fListingText = new BTextView("listingText");
fDestButton->MoveBy(0, rect.Height() + 4);
fSourceButton = new BButton(rect, "sourceButton", "Source",
new BMessage(MSG_SOURCE), B_FOLLOW_LEFT | B_FOLLOW_TOP);
rect = fDestButton->Frame();
rect.OffsetBy(0, rect.Height() + 4);
fExpandButton = new BButton(rect, "expandButton", "Expand",
new BMessage(MSG_EXPAND), B_FOLLOW_LEFT | B_FOLLOW_TOP);
fExpandButton->SetEnabled(false);
// TextControls
rect = fSourceButton->Frame();
rect.left = rect.right + 8;
rect.right = frame.Width() - 8;
fSourceText = new BTextControl(rect, "sourceText", "", NULL,
new BMessage(MSG_SOURCETEXT), B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP);
fSourceText->SetDivider(0);
float width, height;
fSourceText->GetPreferredSize(&width, &height);
fSourceText->ResizeTo(rect.Width(), height);
float offset = (rect.Height() - fSourceText->Bounds().Height()) / 2;
fSourceText->MoveBy(0, offset);
topView->AddChild(fSourceButton);
topView->AddChild(fSourceText);
rect = fSourceText->Frame();
rect.OffsetBy(0, fSourceButton->Bounds().Height() + 4);
fDestText = new BTextControl(rect, "destText", "", NULL,
new BMessage(MSG_DESTTEXT), B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP);
fDestText->SetDivider(0);
topView->AddChild(fDestButton);
topView->AddChild(fDestText);
rect.OffsetBy(0, fSourceButton->Bounds().Height() + 4 + offset);
fShowContents = new BCheckBox(rect, "showContents", "Show contents",
new BMessage(MSG_SHOWCONTENTS), B_FOLLOW_RIGHT | B_FOLLOW_TOP);
fShowContents->ResizeToPreferred();
fShowContents->MoveTo(Bounds().right - 8 - fShowContents->Bounds().Width(),
rect.top);
topView->AddChild(fExpandButton);
topView->AddChild(fShowContents);
fShowContents->SetEnabled(false);
rect.left = fExpandButton->Frame().right + 8;
rect.right = fShowContents->Frame().left - 4;
fStatusView = new BStringView(rect, "statusView", "",
B_FOLLOW_LEFT | B_FOLLOW_TOP, B_WILL_DRAW | B_FRAME_EVENTS);
topView->AddChild(fStatusView);
ResizeTo(frame.Width(), topView->Frame().top + fExpandButton->Frame().bottom + 8);
SetSizeLimits(fExpandButton->Bounds().Width() * 3 + fShowContents->Bounds().Width() + 24,
32767.0f, Frame().Height(), Frame().Height());
rect = topView->Bounds();
rect.InsetBy(10, 0);
rect.top = rect.bottom + 2;
rect.bottom -= 10;
rect.right -= B_V_SCROLL_BAR_WIDTH;
BRect textRect = rect;
textRect.OffsetTo(B_ORIGIN);
textRect.InsetBy(1, 1);
fListingText = new BTextView(rect, "listingText", textRect,
be_fixed_font, NULL, B_FOLLOW_ALL, B_WILL_DRAW | B_FRAME_EVENTS);
fListingText->SetText(""); fListingText->SetText("");
fListingText->MakeEditable(false); fListingText->MakeEditable(false);
fListingScroll = new BScrollView("listingScroll", fListingText, BScrollView* scrollView = new BScrollView("", fListingText,
B_FOLLOW_ALL, B_WILL_DRAW | B_FRAME_EVENTS, false, true); B_INVALIDATE_AFTER_LAYOUT, false, true);
topView->AddChild(fListingScroll);
fListingScroll->Hide(); BView* topView = layout->View();
const float spacing = be_control_look->DefaultItemSpacing();
topView->AddChild(BGroupLayoutBuilder(B_VERTICAL, spacing)
.AddGroup(B_HORIZONTAL, spacing)
.AddGroup(B_VERTICAL, 5.0)
.Add(fDestButton)
.Add(fSourceButton)
.Add(fExpandButton)
.End()
.AddGroup(B_VERTICAL, spacing)
.Add(fSourceText = new BTextControl(NULL, NULL,
new BMessage(MSG_SOURCETEXT)))
.Add(fDestText = new BTextControl(NULL, NULL,
new BMessage(MSG_DESTTEXT)))
.AddGroup(B_HORIZONTAL, spacing)
.Add(fShowContents = new BCheckBox("Show contents",
new BMessage(MSG_SHOWCONTENTS)))
.Add(fStatusView = new BStringView(NULL, NULL))
.End()
.End()
.End()
.Add(scrollView)
.SetInsets(spacing, spacing, spacing, spacing)
);
size = topView->PreferredSize();
fSizeLimit = size.Height() - scrollView->PreferredSize().height - spacing;
ResizeTo(Bounds().Width(), fSizeLimit);
SetSizeLimits(size.Width(), 32767.0f, fSizeLimit, fSizeLimit);
// finish creating window
Show(); Show();
} }
@@ -517,6 +455,41 @@ ExpanderWindow::RefsReceived(BMessage* msg)
} }
} }
void
ExpanderWindow::_AddMenuBar(BLayout* layout)
{
fBar = new BMenuBar("menu_bar", B_ITEMS_IN_ROW, B_INVALIDATE_AFTER_LAYOUT);
BMenu* menu = new BMenu("File");
BMenuItem* item;
menu->AddItem(item = new BMenuItem("About Expander" B_UTF8_ELLIPSIS,
new BMessage(B_ABOUT_REQUESTED)));
item->SetTarget(be_app_messenger);
menu->AddSeparatorItem();
menu->AddItem(fSourceItem = new BMenuItem("Set source" B_UTF8_ELLIPSIS,
new BMessage(MSG_SOURCE), 'O'));
menu->AddItem(fDestItem = new BMenuItem("Set destination" B_UTF8_ELLIPSIS,
new BMessage(MSG_DEST), 'D'));
menu->AddSeparatorItem();
menu->AddItem(fExpandItem = new BMenuItem("Expand", new BMessage(MSG_EXPAND),
'E'));
fExpandItem->SetEnabled(false);
menu->AddItem(fShowItem = new BMenuItem("Show contents",
new BMessage(MSG_SHOW), 'L'));
fShowItem->SetEnabled(false);
menu->AddSeparatorItem();
menu->AddItem(fStopItem = new BMenuItem("Stop", new BMessage(MSG_STOP), 'K'));
fStopItem->SetEnabled(false);
menu->AddSeparatorItem();
menu->AddItem(new BMenuItem("Close", new BMessage(B_QUIT_REQUESTED), 'W'));
fBar->AddItem(menu);
menu = new BMenu("Settings");
menu->AddItem(fPreferencesItem = new BMenuItem("Settings" B_UTF8_ELLIPSIS,
new BMessage(MSG_PREFERENCES), 'S'));
fBar->AddItem(menu);
layout->AddView(fBar);
}
void void
ExpanderWindow::StartExpanding() ExpanderWindow::StartExpanding()
@@ -592,19 +565,20 @@ ExpanderWindow::_UpdateWindowSize(bool showContents)
float minWidth, maxWidth, minHeight, maxHeight; float minWidth, maxWidth, minHeight, maxHeight;
GetSizeLimits(&minWidth, &maxWidth, &minHeight, &maxHeight); GetSizeLimits(&minWidth, &maxWidth, &minHeight, &maxHeight);
float bottom = fExpandButton->Parent()->Frame().top + fExpandButton->Frame().bottom + 8; float bottom = fSizeLimit;
if (showContents) { if (showContents) {
font_height fontHeight; font_height fontHeight;
be_plain_font->GetHeight(&fontHeight); be_plain_font->GetHeight(&fontHeight);
float lineHeight = ceilf(fontHeight.ascent + fontHeight.descent + fontHeight.leading); float lineHeight = ceilf(fontHeight.ascent + fontHeight.descent
+ fontHeight.leading);
minHeight = bottom + 14 + 4 * lineHeight; minHeight = bottom + 5.0 * lineHeight;
maxHeight = 32767.0; maxHeight = 32767.0;
bottom = minHeight + 10 * lineHeight; bottom = minHeight + 10.0 * lineHeight;
} else { } else {
minHeight = bottom; minHeight = fSizeLimit;
maxHeight = bottom; maxHeight = fSizeLimit;
} }
SetSizeLimits(minWidth, maxWidth, minHeight, maxHeight); SetSizeLimits(minWidth, maxWidth, minHeight, maxHeight);
@@ -619,9 +593,6 @@ ExpanderWindow::StartListing()
fLargestDelta = 0.0f; fLargestDelta = 0.0f;
if (fListingScroll->IsHidden())
fListingScroll->Show();
if (!fSourceChanged) if (!fSourceChanged)
return; return;
+5 -3
View File
@@ -4,6 +4,7 @@
* *
* Authors: * Authors:
* Jérôme Duval * Jérôme Duval
* Karsten Heimrich <[email protected]>
*/ */
#ifndef EXPANDER_WINDOW_H #ifndef EXPANDER_WINDOW_H
#define EXPANDER_WINDOW_H #define EXPANDER_WINDOW_H
@@ -18,7 +19,7 @@
class BCheckBox; class BCheckBox;
class BMenu; class BMenu;
class BScrollView; class BLayout;
class BStringView; class BStringView;
class BTextControl; class BTextControl;
class BTextView; class BTextView;
@@ -37,10 +38,11 @@ public:
virtual void MessageReceived(BMessage* msg); virtual void MessageReceived(BMessage* msg);
virtual bool QuitRequested(); virtual bool QuitRequested();
void SetRef(const entry_ref* ref); // void SetRef(const entry_ref* ref);
void RefsReceived(BMessage* msg); void RefsReceived(BMessage* msg);
private: private:
void _AddMenuBar(BLayout* layout);
bool CanQuit(); bool CanQuit();
// returns true if the window can be closed safely, false if not // returns true if the window can be closed safely, false if not
void CloseWindowOrKeepOpen(); void CloseWindowOrKeepOpen();
@@ -77,7 +79,6 @@ private:
BTextControl* fDestText; BTextControl* fDestText;
BStringView* fStatusView; BStringView* fStatusView;
BTextView* fListingText; BTextView* fListingText;
BScrollView* fListingScroll;
ExpanderThread* fListingThread; ExpanderThread* fListingThread;
bool fListingStarted; bool fListingStarted;
@@ -90,6 +91,7 @@ private:
ExpanderRules fRules; ExpanderRules fRules;
float fLargestDelta; float fLargestDelta;
float fSizeLimit;
}; };
#endif /* EXPANDER_WINDOW_H */ #endif /* EXPANDER_WINDOW_H */