ShowImage: Use layouts for the main view area.

The main window itself is still not using them,
due to incompatibilities with the toolbar animation.

Fixes #18547.
This commit is contained in:
Augustin Cavalier
2023-08-25 19:34:34 -04:00
parent 692e2e45bb
commit 20e18366d6
6 changed files with 55 additions and 39 deletions
+4 -12
View File
@@ -29,10 +29,9 @@
const float kHorzSpacing = 5.f;
ShowImageStatusView::ShowImageStatusView(BScrollView* scrollView)
ShowImageStatusView::ShowImageStatusView()
:
BView(BRect(), "statusview", B_FOLLOW_BOTTOM | B_FOLLOW_LEFT, B_WILL_DRAW),
fScrollView(scrollView),
BView("statusview", B_WILL_DRAW),
fPreferredSize(0.0, 0.0)
{
memset(fCellWidth, 0, sizeof(fCellWidth));
@@ -45,9 +44,6 @@ ShowImageStatusView::AttachedToWindow()
SetFont(be_plain_font);
BPrivate::AdoptScrollBarFontSize(this);
BScrollBar* scrollBar = fScrollView->ScrollBar(B_HORIZONTAL);
MoveTo(0.0, scrollBar->Frame().top);
AdoptParentColors();
ResizeToPreferred();
@@ -206,7 +202,6 @@ ShowImageStatusView::_SetImageTypeText(const BString& imageType)
void
ShowImageStatusView::_ValidatePreferredSize()
{
float orgWidth = fPreferredSize.width;
// width
fPreferredSize.width = 0.f;
for (size_t i = 0; i < kStatusCellCount; i++) {
@@ -232,9 +227,6 @@ ShowImageStatusView::_ValidatePreferredSize()
if (fPreferredSize.height < scrollBarSize)
fPreferredSize.height = scrollBarSize;
float delta = fPreferredSize.width - orgWidth;
ResizeBy(delta, 0);
BScrollBar* scrollBar = fScrollView->ScrollBar(B_HORIZONTAL);
scrollBar->ResizeBy(-delta, 0);
scrollBar->MoveBy(delta, 0);
SetExplicitMinSize(fPreferredSize);
SetExplicitMaxSize(fPreferredSize);
}
+1 -2
View File
@@ -26,7 +26,7 @@ enum {
class ShowImageStatusView : public BView {
public:
ShowImageStatusView(BScrollView* scrollView);
ShowImageStatusView();
virtual void AttachedToWindow();
virtual void GetPreferredSize(float* _width, float* _height);
@@ -44,7 +44,6 @@ public:
void _SetPagesText(const BString& pages);
void _SetImageTypeText(const BString& imageType);
void _ValidatePreferredSize();
BScrollView* fScrollView;
BSize fPreferredSize;
BString fCellText[kStatusCellCount];
float fCellWidth[kStatusCellCount];
+2 -3
View File
@@ -172,10 +172,9 @@ PopUpMenu::~PopUpMenu()
// #pragma mark -
ShowImageView::ShowImageView(BRect rect, const char* name, uint32 resizingMode,
uint32 flags)
ShowImageView::ShowImageView(const char* name, uint32 flags)
:
BView(rect, name, resizingMode, flags),
BView(name, flags),
fBitmapOwner(NULL),
fBitmap(NULL),
fDisplayBitmap(NULL),
+1 -2
View File
@@ -31,8 +31,7 @@ class BitmapOwner;
class ShowImageView : public BView {
public:
ShowImageView(BRect rect, const char* name,
uint32 resizingMode, uint32 flags);
ShowImageView(const char* name, uint32 flags);
virtual ~ShowImageView();
virtual void AttachedToWindow();
+45 -18
View File
@@ -33,6 +33,7 @@
#include <Entry.h>
#include <File.h>
#include <FilePanel.h>
#include <GridLayout.h>
#include <Locale.h>
#include <Menu.h>
#include <MenuBar.h>
@@ -132,7 +133,7 @@ bs_printf(BString* string, const char* format, ...)
ShowImageWindow::ShowImageWindow(BRect frame, const entry_ref& ref,
const BMessenger& trackerMessenger)
:
BWindow(frame, "", B_DOCUMENT_WINDOW, B_AUTO_UPDATE_SIZE_LIMITS),
BWindow(frame, "", B_DOCUMENT_WINDOW, 0),
fNavigator(ref, trackerMessenger),
fSavePanel(NULL),
fBar(NULL),
@@ -171,7 +172,6 @@ ShowImageWindow::ShowImageWindow(BRect frame, const entry_ref& ref,
// Create the tool bar
BRect viewFrame = contentView->Bounds();
viewFrame.right -= be_control_look->GetScrollBarWidth(B_VERTICAL);
fToolBar = new BToolBar(viewFrame);
// Add the tool icons.
@@ -222,24 +222,51 @@ ShowImageWindow::ShowImageWindow(BRect frame, const entry_ref& ref,
fToolBarVisible = fShowToolBar;
viewFrame.bottom = contentView->Bounds().bottom;
viewFrame.bottom -= be_control_look->GetScrollBarWidth(B_HORIZONTAL);
// create the scroll area
fScrollArea = new BScrollView("image_scroller", NULL, 0,
false, false, B_PLAIN_BORDER);
BGridLayout* gridLayout = new BGridLayout(0, 0);
fScrollArea->SetLayout(gridLayout);
gridLayout->SetInsets(1, 1, -1, -1);
fScrollArea->MoveTo(viewFrame.LeftTop());
fScrollArea->ResizeTo(viewFrame.Size());
fScrollArea->SetResizingMode(B_FOLLOW_ALL);
contentView->AddChild(fScrollArea);
// create the image view
fImageView = new ShowImageView(viewFrame, "image_view", B_FOLLOW_ALL,
fImageView = new ShowImageView("image_view",
B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE | B_PULSE_NEEDED
| B_FRAME_EVENTS);
// wrap a scroll view around the view
fScrollView = new BScrollView("image_scroller", fImageView,
B_FOLLOW_ALL, 0, true, true, B_PLAIN_BORDER);
contentView->AddChild(fScrollView);
fImageView->SetExplicitMinSize(BSize(0, 0));
gridLayout->AddView(fImageView, 0, 0, 2, 1);
fStatusView = new ShowImageStatusView(fScrollView);
fScrollView->AddChild(fStatusView);
// create the scroll bars (wrapped to avoid double borders)
fVScrollBar = new BScrollBar(NULL, NULL, 0, 0, B_VERTICAL); {
BGroupView* vScrollBarContainer = new BGroupView(B_VERTICAL, 0);
vScrollBarContainer->GroupLayout()->AddView(fVScrollBar);
vScrollBarContainer->GroupLayout()->SetInsets(0, -1, 0, -1);
gridLayout->AddView(vScrollBarContainer, 2, 0);
}
fHScrollBar = new BScrollBar(NULL, NULL, 0, 0, B_HORIZONTAL); {
BGroupView* hScrollBarContainer = new BGroupView(B_VERTICAL, 0);
hScrollBarContainer->GroupLayout()->AddView(fHScrollBar);
hScrollBarContainer->GroupLayout()->SetInsets(0, -1, -1, -1);
gridLayout->AddView(hScrollBarContainer, 1, 1);
}
fVScrollBar->SetTarget(fImageView);
fHScrollBar->SetTarget(fImageView);
fStatusView = new ShowImageStatusView;
gridLayout->AddView(fStatusView, 0, 1);
// Update minimum window size
float toolBarMinWidth = fToolBar->MinSize().width;
SetSizeLimits(std::max(menuBarMinWidth, toolBarMinWidth), 100000, 100,
100000);
SetSizeLimits(std::max(menuBarMinWidth, toolBarMinWidth), 100000,
fBar->MinSize().height + gridLayout->MinSize().height, 100000);
// finish creating the window
if (_LoadImage() != B_OK) {
@@ -1040,8 +1067,8 @@ ShowImageWindow::MessageReceived(BMessage* message)
float offset;
if (message->FindFloat("offset", &offset) == B_OK) {
fToolBar->MoveBy(0, offset);
fScrollView->ResizeBy(0, -offset);
fScrollView->MoveBy(0, offset);
fScrollArea->ResizeBy(0, -offset);
fScrollArea->MoveBy(0, offset);
UpdateIfNeeded();
snooze(15000);
}
@@ -1059,8 +1086,8 @@ ShowImageWindow::MessageReceived(BMessage* message)
fToolBar->Hide();
BRect frame = fToolBar->Parent()->Bounds();
frame.top = fToolBar->Frame().bottom + 1;
fScrollView->MoveTo(fScrollView->Frame().left, frame.top);
fScrollView->ResizeTo(fScrollView->Bounds().Width(),
fScrollArea->MoveTo(fScrollArea->Frame().left, frame.top);
fScrollArea->ResizeTo(fScrollArea->Bounds().Width(),
frame.Height() + 1);
}
break;
@@ -1608,8 +1635,8 @@ ShowImageWindow::_SetToolBarVisible(bool visible, bool animate)
finalMessage.AddBool("show", visible);
PostMessage(&finalMessage, this);
} else {
fScrollView->ResizeBy(0, -diff);
fScrollView->MoveBy(0, diff);
fScrollArea->ResizeBy(0, -diff);
fScrollArea->MoveBy(0, diff);
fToolBar->MoveBy(0, diff);
if (!visible)
fToolBar->Hide();
+2 -2
View File
@@ -24,7 +24,6 @@ class BMenuBar;
class BMenuItem;
class BMessageRunner;
class BScrollBar;
class BScrollView;
class ProgressWindow;
class ShowImageView;
class ShowImageStatusView;
@@ -123,7 +122,8 @@ private:
BMenu* fRatingMenu;
BToolBar* fToolBar;
bool fToolBarVisible;
BScrollView* fScrollView;
BView* fScrollArea;
BScrollBar *fVScrollBar, *fHScrollBar;
ShowImageView* fImageView;
ShowImageStatusView* fStatusView;
ProgressWindow* fProgressWindow;