void BTwoDimensionalLayout::LocalLayouter::AddConstraints( CompoundLayouter* compoundLayouter, Layouter* layouter) { enum orientation orientation = compoundLayouter->Orientation(); int itemCount = fLayout->CountItems(); if (itemCount > 0) { for (int i = 0; i < itemCount; i++) { BLayoutItem* item = fLayout->ItemAt(i); if (item->IsVisible()) { Dimensions itemDimensions; fLayout->GetItemDimensions(item, &itemDimensions); BSize min = item->MinSize(); BSize max = item->MaxSize(); BSize preferred = item->PreferredSize(); if (orientation == B_HORIZONTAL) { layouter->AddConstraints( itemDimensions.x, itemDimensions.width, min.width, max.width, preferred.width); if (item->HasHeightForWidth()) fHeightForWidthItems.AddItem(item); } else { layouter->AddConstraints( itemDimensions.y, itemDimensions.height, min.height, max.height, preferred.height); } } } // add column/row constraints ColumnRowConstraints constraints; int elementCount = CountElements(compoundLayouter); for (int element = 0; element < elementCount; element++) { fLayout->GetColumnRowConstraints(orientation, element, &constraints); layouter->SetWeight(element, constraints.weight); layouter->AddConstraints(element, 1, constraints.min, constraints.max, constraints.min); } } }
// _ValidateMinMax void BCardLayout::_ValidateMinMax() { if (fMinMaxValid) return; fMin.width = 0; fMin.height = 0; fMax.width = B_SIZE_UNLIMITED; fMax.height = B_SIZE_UNLIMITED; fPreferred.width = 0; fPreferred.height = 0; int32 itemCount = CountItems(); for (int32 i = 0; i < itemCount; i++) { BLayoutItem* item = ItemAt(i); BSize min = item->MinSize(); BSize max = item->MaxSize(); BSize preferred = item->PreferredSize(); fMin.width = max_c(fMin.width, min.width); fMin.height = max_c(fMin.height, min.height); fMax.width = min_c(fMax.width, max.width); fMax.height = min_c(fMax.height, max.height); fPreferred.width = max_c(fPreferred.width, preferred.width); fPreferred.height = max_c(fPreferred.height, preferred.height); } fMax.width = max_c(fMax.width, fMin.width); fMax.height = max_c(fMax.height, fMin.height); fPreferred.width = max_c(fPreferred.width, fMin.width); fPreferred.height = max_c(fPreferred.height, fMin.height); fPreferred.width = min_c(fPreferred.width, fMax.width); fPreferred.height = min_c(fPreferred.height, fMax.height); fMinMaxValid = true; if (BView* view = View()) view->ResetLayoutInvalidation(); }
void TFilePanel::RestoreState() { BNode defaultingNode; if (DefaultStateSourceNode(kDefaultFilePanelTemplate, &defaultingNode, false)) { AttributeStreamFileNode streamNodeSource(&defaultingNode); RestoreWindowState(&streamNodeSource); PoseView()->Init(&streamNodeSource); } else { RestoreWindowState(NULL); PoseView()->Init(NULL); } // Finish UI creation now that the PoseView is initialized BLayoutItem* item = fBorderedView->GroupLayout()->AddView(0, fPoseView->TitleView()); BSize minSize = item->MinSize(); BSize maxSize = item->MaxSize(); item->SetExplicitMinSize(BSize(minSize.Width(), kTitleViewHeight)); item->SetExplicitMaxSize(BSize(maxSize.Width(), kTitleViewHeight)); BRect rect(fBorderedView->Frame()); rect.right = rect.left + kCountViewWidth; rect.top = rect.bottom + 1; rect.bottom = rect.top + PoseView()->HScrollBar()->Bounds().Height() - 1; PoseView()->CountView()->MoveTo(rect.LeftTop()); PoseView()->CountView()->ResizeTo(rect.Size()); PoseView()->CountView()->SetResizingMode(B_FOLLOW_LEFT | B_FOLLOW_BOTTOM); fBackView->AddChild(PoseView()->CountView(), fBorderedView); PoseView()->HScrollBar()->MoveBy(kCountViewWidth + 1, 0); PoseView()->HScrollBar()->ResizeBy(-kCountViewWidth - 1, 0); // The Be Book states that the BTitleView will have a name of "TitleView", // and so some apps will try to grab it by that name and move it around. // They don't need to, because resizing "PoseView" (really the BorderedView) // will resize the BTitleView as well. So just create a dummy view here // so that they don't get NULL when trying to find the view. BView* dummyTitleView = new BView(BRect(), "TitleView", B_FOLLOW_NONE, 0); fBackView->AddChild(dummyTitleView); dummyTitleView->Hide(); }
void BSplitLayout::_ValidateMinMax() { if (fHorizontalLayouter != NULL) return; fLayoutValid = false; fVisibleItems.MakeEmpty(); fHeightForWidthItems.MakeEmpty(); _InvalidateCachedHeightForWidth(); // filter the visible items int32 itemCount = CountItems(); for (int32 i = 0; i < itemCount; i++) { BLayoutItem* item = ItemAt(i); if (item->IsVisible()) fVisibleItems.AddItem(item); // Add "height for width" items even, if they aren't visible. Otherwise // we may get our parent into trouble, since we could change from // "height for width" to "not height for width". if (item->HasHeightForWidth()) fHeightForWidthItems.AddItem(item); } itemCount = fVisibleItems.CountItems(); // create the layouters Layouter* itemLayouter = new SimpleLayouter(itemCount, 0); if (fOrientation == B_HORIZONTAL) { fHorizontalLayouter = itemLayouter; fVerticalLayouter = new OneElementLayouter(); } else { fHorizontalLayouter = new OneElementLayouter(); fVerticalLayouter = itemLayouter; } // tell the layouters about our constraints if (itemCount > 0) { for (int32 i = 0; i < itemCount; i++) { BLayoutItem* item = (BLayoutItem*)fVisibleItems.ItemAt(i); BSize min = item->MinSize(); BSize max = item->MaxSize(); BSize preferred = item->PreferredSize(); fHorizontalLayouter->AddConstraints(i, 1, min.width, max.width, preferred.width); fVerticalLayouter->AddConstraints(i, 1, min.height, max.height, preferred.height); float weight = ItemWeight(item); fHorizontalLayouter->SetWeight(i, weight); fVerticalLayouter->SetWeight(i, weight); } } fMin.width = fHorizontalLayouter->MinSize(); fMin.height = fVerticalLayouter->MinSize(); fMax.width = fHorizontalLayouter->MaxSize(); fMax.height = fVerticalLayouter->MaxSize(); fPreferred.width = fHorizontalLayouter->PreferredSize(); fPreferred.height = fVerticalLayouter->PreferredSize(); fHorizontalLayoutInfo = fHorizontalLayouter->CreateLayoutInfo(); if (fHeightForWidthItems.IsEmpty()) fVerticalLayoutInfo = fVerticalLayouter->CreateLayoutInfo(); ResetLayoutInvalidation(); }