Ticket #6407: patch
File patch, 78.1 KB (added by , 14 years ago) |
---|
-
src/preferences/keymap/KeymapWindow.cpp
508 508 .Add(new BStringView("system", B_TRANSLATE("System:"))) 509 509 .Add(systemScroller, 3) 510 510 .Add(new BStringView("user", B_TRANSLATE("User:"))) 511 .Add(userScroller); 511 .Add(userScroller) 512 .TopView(); 512 513 } 513 514 514 515 -
src/preferences/backgrounds/BackgroundsView.cpp
144 144 .AddGroup(B_VERTICAL, 20) 145 145 .AddGroup(B_HORIZONTAL, 0) 146 146 .AddGlue() 147 .AddGrid(0, 0 )147 .AddGrid(0, 0, 1) 148 148 .Add(fTopLeft, 0, 0) 149 149 .Add(fTop, 1, 0) 150 150 .Add(fTopRight, 2, 0) -
src/libs/alm/BALMLayout.cpp
20 20 * Creates new layout engine. 21 21 */ 22 22 BALMLayout::BALMLayout() 23 : BLayout(), 23 : 24 BAbstractLayout(), 24 25 LinearSpec() 25 26 { 26 27 fLayoutStyle = FIT_TO_SIZE; … … 189 190 { 190 191 InvalidateLayout(); 191 192 if (content != NULL) 192 View()->AddChild(content);193 TargetView()->AddChild(content); 193 194 Area* area = new Area(this, left, top, right, bottom, content, minContentSize); 194 195 fAreas->AddItem(area); 195 196 return area; … … 211 212 { 212 213 InvalidateLayout(); 213 214 if (content != NULL) 214 View()->AddChild(content);215 TargetView()->AddChild(content); 215 216 Area* area = new Area(this, row, column, content, minContentSize); 216 217 fAreas->AddItem(area); 217 218 return area; … … 234 235 { 235 236 InvalidateLayout(); 236 237 if (content != NULL) 237 View()->AddChild(content);238 TargetView()->AddChild(content); 238 239 Area* area = new Area(this, left, top, right, bottom, content, BSize(0, 0)); 239 240 area->SetDefaultBehavior(); 240 241 area->SetAutoPreferredContentSize(false); … … 256 257 { 257 258 InvalidateLayout(); 258 259 if (content != NULL) 259 View()->AddChild(content);260 TargetView()->AddChild(content); 260 261 Area* area = new Area(this, row, column, content, BSize(0, 0)); 261 262 area->SetDefaultBehavior(); 262 263 area->SetAutoPreferredContentSize(false); … … 435 436 436 437 437 438 /** 438 * Sets and gets minimum size.439 * Gets minimum size. 439 440 */ 440 BSize BALMLayout::MinSize() { 441 BSize 442 BALMLayout::BaseMinSize() { 441 443 if (fMinSize == Area::kUndefinedSize) 442 444 fMinSize = CalculateMinSize(); 443 445 return fMinSize; … … 445 447 446 448 447 449 /** 448 * Sets and gets maximum size.450 * Gets maximum size. 449 451 */ 450 452 BSize 451 BALMLayout:: MaxSize()453 BALMLayout::BaseMaxSize() 452 454 { 453 455 if (fMaxSize == Area::kUndefinedSize) 454 456 fMaxSize = CalculateMaxSize(); … … 457 459 458 460 459 461 /** 460 * Sets and gets preferred size.462 * Gets preferred size. 461 463 */ 462 464 BSize 463 BALMLayout:: PreferredSize()465 BALMLayout::BasePreferredSize() 464 466 { 465 467 if (fPreferredSize == Area::kUndefinedSize) 466 468 fPreferredSize = CalculatePreferredSize(); … … 472 474 * Gets the alignment. 473 475 */ 474 476 BAlignment 475 BALMLayout:: Alignment()477 BALMLayout::BaseAlignment() 476 478 { 477 479 BAlignment alignment; 478 480 alignment.SetHorizontal(B_ALIGN_HORIZONTAL_CENTER); … … 492 494 493 495 494 496 /** 495 * Sets whether the height of the layout depends on itswidth.497 * Gets height constraints for a given width. 496 498 */ 497 499 void 498 500 BALMLayout::GetHeightForWidth(float width, float* min, float* max, float* preferred) {} … … 503 505 * Resets minimum/maximum/preferred size. 504 506 */ 505 507 void 506 BALMLayout::InvalidateLayout( )508 BALMLayout::InvalidateLayout(bool children) 507 509 { 510 BLayout::InvalidateLayout(children); 508 511 fMinSize = Area::kUndefinedSize; 509 512 fMaxSize = Area::kUndefinedSize; 510 513 fPreferredSize = Area::kUndefinedSize; … … 516 519 * If no layout specification is given, a specification is reverse engineered automatically. 517 520 */ 518 521 void 519 BALMLayout:: LayoutView()522 BALMLayout::DerivedLayoutItems() 520 523 { 524 // TODO: modify to allow for viewlessness 521 525 // make sure that layout events occuring during layout are ignored 522 // i.e. activated is set to false during layout cal uclation526 // i.e. activated is set to false during layout calculation 523 527 if (!fActivated) 524 528 return; 525 529 fActivated = false; 526 530 527 if ( View() == NULL)531 if (Owner() == NULL) 528 532 return; 529 533 530 534 // reverse engineer a layout specification if none was given 531 535 //~ if (this == NULL) RecoverLayout(View()); 532 536 533 537 // if the layout engine is set to fit the GUI to the given size, 534 // then the given size is enforced by setting absolute positions for Right and Bottom 538 // then the given size is enforced by setting absolute positions 539 // for Right and Bottom 535 540 if (fLayoutStyle == FIT_TO_SIZE) { 536 Right()->SetRange(View()->Bounds().Width(), View()->Bounds().Width()); 537 Bottom()->SetRange(View()->Bounds().Height(), View()->Bounds().Height()); 541 BSize layoutSize(LayoutArea().Size()); 542 Right()->SetRange(layoutSize.width, layoutSize.width); 543 Bottom()->SetRange(layoutSize.height, layoutSize.height); 538 544 } 539 545 540 546 SolveLayout(); … … 554 560 // change the size of the GUI according to the calculated size 555 561 // if the layout engine was configured to do so 556 562 if (fLayoutStyle == ADJUST_SIZE) { 557 View()->ResizeTo(floor(Right()->Value() - Left()->Value() + 0.5),563 Owner()->ResizeTo(floor(Right()->Value() - Left()->Value() + 0.5), 558 564 floor(Bottom()->Value() - Top()->Value() + 0.5)); 559 565 } 560 566 -
src/kits/interface/AbstractLayout.cpp
1 /* 2 * Copyright 2010, Haiku, Inc. 3 * All rights reserved. Distributed under the terms of the MIT License. 4 */ 5 6 7 #include <AbstractLayout.h> 8 #include <LayoutUtils.h> 9 #include <Message.h> 10 #include <View.h> 11 #include <ViewPrivate.h> 12 13 14 namespace { 15 const char* const kSizesField = "BAbstractLayout:sizes"; 16 // kSizesField == {min, max, preferred} 17 const char* const kAlignmentField = "BAbstractLayout:alignment"; 18 const char* const kFrameField = "BAbstractLayout:frame"; 19 const char* const kVisibleField = "BAbstractLayout:visible"; 20 21 enum proxy_type { VIEW_PROXY_TYPE, DATA_PROXY_TYPE }; 22 } 23 24 25 struct BAbstractLayout::Proxy { 26 27 Proxy(proxy_type type) 28 : 29 type(type) 30 { 31 } 32 33 virtual BSize MinSize() const = 0; 34 virtual void SetMinSize(const BSize&) = 0; 35 36 virtual BSize MaxSize() const = 0; 37 virtual void SetMaxSize(const BSize&) = 0; 38 39 virtual BSize PreferredSize() const = 0; 40 virtual void SetPreferredSize(const BSize&) = 0; 41 42 virtual BAlignment Alignment() const = 0; 43 virtual void SetAlignment(const BAlignment&) = 0; 44 45 virtual BRect Frame() const = 0; 46 virtual void SetFrame(const BRect& frame) = 0; 47 48 virtual bool IsVisible(bool ancestorHidden) const = 0; 49 virtual void SetVisible(bool visible) = 0; 50 51 virtual status_t AddDataToArchive(BMessage* archive, 52 bool ancestorHidden) = 0; 53 virtual status_t RestoreDataFromArchive(const BMessage* archive) = 0; 54 55 proxy_type type; 56 }; 57 58 59 struct BAbstractLayout::DataProxy : Proxy { 60 61 DataProxy() 62 : 63 Proxy(DATA_PROXY_TYPE), 64 minSize(), 65 maxSize(), 66 preferredSize(), 67 alignment(), 68 frame(-1, -1, 0, 0), 69 visible(true) 70 { 71 } 72 73 BSize MinSize() const 74 { 75 return minSize; 76 } 77 78 void SetMinSize(const BSize& min) 79 { 80 minSize = min; 81 } 82 83 BSize MaxSize() const 84 { 85 return maxSize; 86 } 87 88 void SetMaxSize(const BSize& max) 89 { 90 maxSize = max; 91 } 92 93 BSize PreferredSize() const 94 { 95 return preferredSize; 96 } 97 98 void SetPreferredSize(const BSize& preferred) 99 { 100 preferredSize = preferred; 101 } 102 103 BAlignment Alignment() const 104 { 105 return this->alignment; 106 } 107 108 void SetAlignment(const BAlignment& align) 109 { 110 this->alignment = align; 111 } 112 113 BRect Frame() const 114 { 115 return frame; 116 } 117 118 void SetFrame(const BRect& frame) 119 { 120 if (frame == this->frame) 121 return; 122 this->frame = frame; 123 } 124 125 bool IsVisible(bool) const 126 { 127 return visible; 128 } 129 130 void SetVisible(bool visible) 131 { 132 this->visible = visible; 133 } 134 135 status_t AddDataToArchive(BMessage* archive, bool ancestorHidden) 136 { 137 status_t err = archive->AddSize(kSizesField, minSize); 138 if (err == B_OK) 139 err = archive->AddSize(kSizesField, maxSize); 140 if (err == B_OK) 141 err = archive->AddSize(kSizesField, preferredSize); 142 if (err == B_OK) 143 err = archive->AddAlignment(kAlignmentField, alignment); 144 if (err == B_OK) 145 err = archive->AddRect(kFrameField, frame); 146 if (err == B_OK) 147 err = archive->AddBool(kVisibleField, visible); 148 149 return err; 150 } 151 152 status_t RestoreDataFromArchive(const BMessage* archive) 153 { 154 status_t err = archive->FindSize(kSizesField, 0, &minSize); 155 if (err == B_OK) 156 err = archive->FindSize(kSizesField, 1, &maxSize); 157 if (err == B_OK) 158 err = archive->FindSize(kSizesField, 2, &preferredSize); 159 if (err == B_OK) 160 err = archive->FindAlignment(kAlignmentField, &alignment); 161 if (err == B_OK) 162 err = archive->FindRect(kFrameField, &frame); 163 if (err == B_OK) 164 err = archive->FindBool(kVisibleField, &visible); 165 166 return err; 167 } 168 169 BSize minSize; 170 BSize maxSize; 171 BSize preferredSize; 172 BAlignment alignment; 173 BRect frame; 174 bool visible; 175 }; 176 177 178 struct BAbstractLayout::ViewProxy : Proxy { 179 ViewProxy(BView* target) 180 : 181 Proxy(VIEW_PROXY_TYPE), 182 view(target) 183 { 184 } 185 186 BSize MinSize() const 187 { 188 return view->ExplicitMinSize(); 189 } 190 191 void SetMinSize(const BSize& min) 192 { 193 view->SetExplicitMinSize(min); 194 } 195 196 BSize MaxSize() const 197 { 198 return view->ExplicitMaxSize(); 199 } 200 201 void SetMaxSize(const BSize& min) 202 { 203 view->SetExplicitMaxSize(min); 204 } 205 206 BSize PreferredSize() const 207 { 208 return view->ExplicitPreferredSize(); 209 } 210 211 void SetPreferredSize(const BSize& preferred) 212 { 213 view->SetExplicitPreferredSize(preferred); 214 } 215 216 BAlignment Alignment() const 217 { 218 return view->ExplicitAlignment(); 219 } 220 221 void SetAlignment(const BAlignment& alignment) 222 { 223 view->SetExplicitAlignment(alignment); 224 } 225 226 BRect Frame() const 227 { 228 return view->Frame(); 229 } 230 231 void SetFrame(const BRect& frame) 232 { 233 view->MoveTo(frame.LeftTop()); 234 view->ResizeTo(frame.Width(), frame.Height()); 235 } 236 237 bool IsVisible(bool ancestorsVisible) const 238 { 239 int16 showLevel = BView::Private(view).ShowLevel(); 240 return (showLevel - (ancestorsVisible) ? 0 : 1) <= 0; 241 } 242 243 void SetVisible(bool visible) 244 { 245 // No need to check that we are not re-hiding, that is done 246 // for us. 247 if (visible) 248 view->Show(); 249 else 250 view->Hide(); 251 } 252 253 status_t AddDataToArchive(BMessage* archive, bool ancestorHidden) 254 { 255 return B_OK; 256 } 257 258 status_t RestoreDataFromArchive(const BMessage* archive) 259 { 260 return B_OK; 261 } 262 263 BView* view; 264 }; 265 266 267 BAbstractLayout::BAbstractLayout() 268 : 269 fExplicitData(new BAbstractLayout::DataProxy()) 270 { 271 } 272 273 274 BAbstractLayout::BAbstractLayout(BMessage* from) 275 : 276 BLayout(BUnarchiver::PrepareArchive(from)), 277 fExplicitData(new DataProxy()) 278 { 279 BUnarchiver(from).Finish(); 280 } 281 282 283 BAbstractLayout::~BAbstractLayout() 284 { 285 delete fExplicitData; 286 } 287 288 289 BSize 290 BAbstractLayout::MinSize() 291 { 292 return BLayoutUtils::ComposeSize(fExplicitData->MinSize(), BaseMinSize()); 293 } 294 295 296 BSize 297 BAbstractLayout::MaxSize() 298 { 299 return BLayoutUtils::ComposeSize(fExplicitData->MaxSize(), BaseMaxSize()); 300 } 301 302 303 BSize 304 BAbstractLayout::PreferredSize() 305 { 306 return BLayoutUtils::ComposeSize(fExplicitData->PreferredSize(), 307 BasePreferredSize()); 308 } 309 310 311 BAlignment 312 BAbstractLayout::Alignment() 313 { 314 return BLayoutUtils::ComposeAlignment(fExplicitData->Alignment(), 315 BaseAlignment()); 316 } 317 318 319 void 320 BAbstractLayout::SetExplicitMinSize(BSize size) 321 { 322 fExplicitData->SetMinSize(size); 323 } 324 325 326 void 327 BAbstractLayout::SetExplicitMaxSize(BSize size) 328 { 329 fExplicitData->SetMaxSize(size); 330 } 331 332 333 void 334 BAbstractLayout::SetExplicitPreferredSize(BSize size) 335 { 336 fExplicitData->SetPreferredSize(size); 337 } 338 339 340 void 341 BAbstractLayout::SetExplicitAlignment(BAlignment alignment) 342 { 343 fExplicitData->SetAlignment(alignment); 344 } 345 346 347 BSize 348 BAbstractLayout::BaseMinSize() 349 { 350 return BSize(0, 0); 351 } 352 353 354 BSize 355 BAbstractLayout::BaseMaxSize() 356 { 357 return BSize(B_SIZE_UNLIMITED, B_SIZE_UNLIMITED); 358 } 359 360 361 BSize 362 BAbstractLayout::BasePreferredSize() 363 { 364 return BSize(0, 0); 365 } 366 367 368 BAlignment 369 BAbstractLayout::BaseAlignment() 370 { 371 return BAlignment(B_ALIGN_USE_FULL_WIDTH, B_ALIGN_USE_FULL_HEIGHT); 372 } 373 374 375 BRect 376 BAbstractLayout::Frame() 377 { 378 return fExplicitData->Frame(); 379 } 380 381 382 void 383 BAbstractLayout::SetFrame(BRect frame) 384 { 385 if (frame != fExplicitData->Frame()) { 386 fExplicitData->SetFrame(frame); 387 if (!Owner()) 388 Relayout(); 389 } 390 } 391 392 393 bool 394 BAbstractLayout::IsVisible() 395 { 396 return fExplicitData->IsVisible(AncestorsVisible()); 397 } 398 399 400 void 401 BAbstractLayout::SetVisible(bool visible) 402 { 403 if (visible != fExplicitData->IsVisible(AncestorsVisible())) { 404 fExplicitData->SetVisible(visible); 405 if (Layout()) 406 Layout()->InvalidateLayout(false); 407 VisibilityChanged(visible); 408 } 409 } 410 411 412 status_t 413 BAbstractLayout::Archive(BMessage* into, bool deep) const 414 { 415 BArchiver archiver(into); 416 status_t err = BLayout::Archive(into, deep); 417 418 return archiver.Finish(err); 419 } 420 421 422 status_t 423 BAbstractLayout::AllUnarchived(const BMessage* from) 424 { 425 if (Owner()) { 426 ViewProxy* proxy = dynamic_cast<ViewProxy*>(fExplicitData); 427 if (!proxy) { 428 delete fExplicitData; 429 proxy = new ViewProxy(Owner()); 430 } 431 proxy->view = Owner(); 432 } else { 433 fExplicitData = new DataProxy(); 434 return fExplicitData->RestoreDataFromArchive(from); 435 } 436 437 return BLayout::AllUnarchived(from); 438 } 439 440 441 void 442 BAbstractLayout::OwnerChanged(BView* was) 443 { 444 if (was) { 445 static_cast<ViewProxy*>(fExplicitData)->view = Owner(); 446 return; 447 } 448 449 delete fExplicitData; 450 fExplicitData = new ViewProxy(Owner()); 451 } 452 453 454 void 455 BAbstractLayout::AncestorVisibilityChanged(bool shown) 456 { 457 if (AncestorsVisible() == shown) 458 return; 459 460 if (BView* owner = Owner()) { 461 if (shown) 462 owner->Show(); 463 else 464 owner->Hide(); 465 } 466 BLayout::AncestorVisibilityChanged(shown); 467 } 468 -
src/kits/interface/ViewLayoutItem.h
36 36 37 37 virtual BView* View(); 38 38 39 virtual void InvalidateLayout(); 39 virtual void InvalidateLayout(bool children = false); 40 virtual void Relayout(bool immediate = false); 40 41 41 42 virtual status_t Archive(BMessage* into, bool deep = true) const; 42 43 virtual status_t AllArchived(BMessage* into) const; 43 44 virtual status_t AllUnarchived(const BMessage* from); 44 45 static BArchivable* Instantiate(BMessage* from); 45 46 47 protected: 48 virtual void AncestorVisibilityChanged(bool shown); 49 46 50 private: 47 51 BView* fView; 52 int32 fAncestorsVisible; 48 53 }; 49 54 50 55 #endif // _VIEW_LAYOUT_ITEM_H -
src/kits/interface/View.cpp
648 648 err = unarchiver.FindObject(kLayoutField, layout); 649 649 if (err == B_OK && layout) { 650 650 fFlags |= B_SUPPORTS_LAYOUT; 651 fLayoutData->fLayout-> BLayout::SetView(this);651 fLayoutData->fLayout->SetOwner(this); 652 652 } 653 653 } 654 654 … … 997 997 fShowLevel++; 998 998 999 999 if (fShowLevel == 1 && fParent) 1000 fParent->InvalidateLayout();1000 _InvalidateParentLayout(); 1001 1001 } 1002 1002 1003 1003 … … 1012 1012 } 1013 1013 1014 1014 if (fShowLevel == 0 && fParent) 1015 fParent->InvalidateLayout();1015 _InvalidateParentLayout(); 1016 1016 } 1017 1017 1018 1018 … … 4020 4020 BView::RemoveSelf() 4021 4021 { 4022 4022 if (fParent && fParent->fLayoutData->fLayout) 4023 return fParent->fLayoutData->fLayout->RemoveView (this);4023 return fParent->fLayoutData->fLayout->RemoveViewRecursive(this); 4024 4024 4025 4025 return _RemoveSelf(); 4026 4026 } … … 4643 4643 if (layout == fLayoutData->fLayout) 4644 4644 return; 4645 4645 4646 if (layout && layout->Layout()) 4647 debugger("BView::SetLayout() failed, layout is already in use."); 4648 4646 4649 fFlags |= B_SUPPORTS_LAYOUT; 4647 4650 4648 4651 // unset and delete the old layout 4649 4652 if (fLayoutData->fLayout) { 4650 fLayoutData->fLayout->Set View(NULL);4653 fLayoutData->fLayout->SetOwner(NULL); 4651 4654 delete fLayoutData->fLayout; 4652 4655 } 4653 4656 4654 4657 fLayoutData->fLayout = layout; 4655 4658 4656 4659 if (fLayoutData->fLayout) { 4657 fLayoutData->fLayout->Set View(this);4660 fLayoutData->fLayout->SetOwner(this); 4658 4661 4659 4662 // add all children 4660 4663 int count = CountChildren(); … … 4676 4679 void 4677 4680 BView::InvalidateLayout(bool descendants) 4678 4681 { 4682 // printf("BView(%p)::InvalidateLayout(%i), valid: %i, inProgress: %i\n", 4683 // this, descendants, fLayoutData->fLayoutValid, 4684 // fLayoutData->fLayoutInProgress); 4685 4679 4686 if (fLayoutData->fMinMaxValid && !fLayoutData->fLayoutInProgress 4680 && fLayoutData->fLayoutInvalidationDisabled == 0) { 4681 if (fParent && fParent->fLayoutData->fMinMaxValid) 4682 fParent->InvalidateLayout(false); 4687 && fLayoutData->fLayoutInvalidationDisabled == 0) { 4683 4688 4684 4689 fLayoutData->fLayoutValid = false; 4685 4690 fLayoutData->fMinMaxValid = false; 4686 4691 4687 if (fLayoutData->fLayout)4688 fLayoutData->fLayout->InvalidateLayout();4689 4690 4692 if (descendants) { 4691 int count = CountChildren(); 4692 for (int i = 0; i < count; i++) 4693 ChildAt(i)->InvalidateLayout(descendants); 4693 for (BView* child = fFirstChild; 4694 child; child = child->fNextSibling) { 4695 child->InvalidateLayout(descendants); 4696 } 4694 4697 } 4695 4698 4699 if (fLayoutData->fLayout && fLayoutData->fLayout->InvalidationLegal()) 4700 fLayoutData->fLayout->InvalidateLayout(descendants); 4701 else if (!fLayoutData->fLayout && fParent) { 4702 _InvalidateParentLayout(); 4703 } 4704 4696 4705 if (fTopLevelView) { 4697 4706 // trigger layout process 4698 4707 if (fOwner) … … 4724 4733 } 4725 4734 4726 4735 4727 /*! \brief Service call for B Layoutderived classes reenabling4736 /*! \brief Service call for BView derived classes reenabling 4728 4737 InvalidateLayout() notifications. 4729 BView::InvalidateLayout() invokes InvalidateLayout() on its layout the first4730 time, but suppresses further calls until Layout()/Relayout() has been4731 invoked. This method will reenable the notification for the next call of4732 BView::InvalidateLayout().4733 4738 4734 If the layout caches internal layout information and updates those 4735 information also in methods other than LayoutView(), it has to invoke this 4739 BLayout & BView will avoid calling InvalidateLayout on views that have 4740 already been invalidated, but if the view caches internal layout information 4741 which it updates in methds other than DoLayout(), it has to invoke this 4736 4742 method, when it has done so, since otherwise the information might become 4737 4743 obsolete without the layout noticing. 4738 4744 */ … … 4763 4769 { 4764 4770 if (fLayoutData->fLayoutValid && !fLayoutData->fLayoutInProgress) { 4765 4771 fLayoutData->fNeedsRelayout = true; 4772 if (fLayoutData->fLayout) 4773 fLayoutData->fLayout->RequireLayout(); 4766 4774 4767 4775 // Layout() is recursive, that is if the parent view is currently laid 4768 4776 // out, we don't call layout() on this view, but wait for the parent's … … 4777 4785 BView::DoLayout() 4778 4786 { 4779 4787 if (fLayoutData->fLayout) 4780 fLayoutData->fLayout-> LayoutView();4788 fLayoutData->fLayout->_LayoutWithinContext(false, LayoutContext()); 4781 4789 } 4782 4790 4783 4791 … … 4881 4889 fLayoutData->fNeedsRelayout = false; 4882 4890 4883 4891 // layout children 4884 int32 childCount = CountChildren(); 4885 for (int32 i = 0; i < childCount; i++) { 4886 BView* child = ChildAt(i); 4892 for(BView* child = fFirstChild; child; child = child->fNextSibling) { 4887 4893 if (!child->IsHidden(child)) 4888 4894 child->_Layout(force, context); 4889 4895 } … … 4897 4903 } 4898 4904 4899 4905 4906 void 4907 BView::_LayoutLeft(BLayout* deleted) 4908 { 4909 // If our layout is added to another layout (via BLayout::AddItem()) 4910 // then we share ownership of our layout. In the event that our layout gets 4911 // deleted by the layout it has been added to, this method is called so 4912 // that we don't double-delete our layout. 4913 if (fLayoutData->fLayout == deleted) 4914 fLayoutData->fLayout = NULL; 4915 InvalidateLayout(); 4916 } 4917 4918 4919 void 4920 BView::_InvalidateParentLayout() 4921 { 4922 BLayout* layout = fLayoutData->fLayout; 4923 BLayout* layoutParent = layout ? layout->Layout() : NULL; 4924 if (layoutParent && layoutParent->InvalidationLegal()) { 4925 layout->Layout()->InvalidateLayout(); 4926 } else if (fParent && fParent->fLayoutData->fLayout) { 4927 fParent->fLayoutData->fLayout->InvalidateLayoutsForView(this); 4928 } else if (fParent) { 4929 fParent->InvalidateLayout(); 4930 } 4931 } 4932 4933 4900 4934 // #pragma mark - Private Functions 4901 4935 4902 4936 … … 5920 5954 } 5921 5955 } 5922 5956 } 5957 5958 5959 // #pragma mark - 5960 5961 5962 bool 5963 BView::Private::MinMaxValid() 5964 { 5965 return fView->fLayoutData->fMinMaxValid; 5966 } -
src/kits/interface/Layout.cpp
7 7 8 8 #include <Layout.h> 9 9 10 #include <algorithm> 11 #include <new> 10 12 #include <syslog.h> 11 #include <new>12 13 14 #include <LayoutContext.h> 13 15 #include <Message.h> 14 16 #include <View.h> 17 #include <ViewPrivate.h> 15 18 16 19 #include "ViewLayoutItem.h" 17 20 18 21 19 22 using std::nothrow; 23 using std::swap; 20 24 21 25 22 26 namespace { 27 // flags for our state 28 const uint32 B_LAYOUT_INVALID = 0x80000000UL; // needs layout 29 const uint32 B_LAYOUT_CACHE_INVALID = 0x40000000UL; // needs recalculation 30 const uint32 B_LAYOUT_REQUIRED = 0x20000000UL; // needs layout 31 const uint32 B_LAYOUT_IN_PROGRESS = 0x10000000UL; 32 const uint32 B_LAYOUT_ALL_CLEAR = 0UL; 33 34 // handy masks to check various states 35 const uint32 B_LAYOUT_INVALIDATION_ILLEGAL 36 = B_LAYOUT_CACHE_INVALID | B_LAYOUT_IN_PROGRESS; 37 const uint32 B_LAYOUT_NECESSARY 38 = B_LAYOUT_INVALID | B_LAYOUT_REQUIRED | B_LAYOUT_CACHE_INVALID; 39 const uint32 B_RELAYOUT_NOT_OK 40 = B_LAYOUT_INVALID | B_LAYOUT_IN_PROGRESS; 41 23 42 const char* const kLayoutItemField = "BLayout:items"; 24 43 } 25 44 26 45 27 46 BLayout::BLayout() 28 47 : 29 fView(NULL), 48 fState(B_LAYOUT_ALL_CLEAR), 49 fAncestorsVisible(true), 50 fInvalidationDisabled(0), 51 fContext(NULL), 52 fOwner(NULL), 53 fTarget(NULL), 30 54 fItems(20) 31 55 { 32 56 } … … 34 58 35 59 BLayout::BLayout(BMessage* from) 36 60 : 37 BArchivable(BUnarchiver::PrepareArchive(from)), 38 fView(NULL), 61 BLayoutItem(BUnarchiver::PrepareArchive(from)), 62 fState(B_LAYOUT_ALL_CLEAR), 63 fAncestorsVisible(true), 64 fInvalidationDisabled(0), 65 fContext(NULL), 66 fOwner(NULL), 67 fTarget(NULL), 39 68 fItems(20) 40 69 { 41 70 BUnarchiver unarchiver(from); … … 48 77 49 78 BLayout::~BLayout() 50 79 { 51 // this deletes all items 52 SetView(NULL); 80 // in case we have a view, but have been added to a layout as a BLayoutItem 81 // we will get deleted before our view, so we should tell it that we're 82 // going, so that we aren't double-freed. 83 if (fOwner && this == fOwner->GetLayout()) 84 fOwner->_LayoutLeft(this); 85 86 // removes and deletes all items 87 if (fTarget) 88 SetTarget(NULL); 53 89 } 54 90 55 91 56 92 BView* 57 BLayout:: View() const93 BLayout::Owner() const 58 94 { 59 return f View;95 return fOwner; 60 96 } 61 97 62 98 99 BView* 100 BLayout::TargetView() const 101 { 102 return fTarget; 103 } 104 105 106 BView* 107 BLayout::View() 108 { 109 return fOwner; 110 } 111 112 63 113 BLayoutItem* 64 114 BLayout::AddView(BView* child) 65 115 { … … 70 120 BLayoutItem* 71 121 BLayout::AddView(int32 index, BView* child) 72 122 { 73 if (BViewLayoutItem* item = new(nothrow) BViewLayoutItem(child)) { 74 if (AddItem(index, item)) 75 return item; 123 BLayoutItem* item = child->GetLayout(); 124 if (!item) 125 item = new(nothrow) BViewLayoutItem(child); 126 127 if (item && AddItem(index, item)) 128 return item; 129 130 if (!child->GetLayout()) 76 131 delete item; 77 }78 132 return NULL; 79 133 } 80 134 … … 89 143 bool 90 144 BLayout::AddItem(int32 index, BLayoutItem* item) 91 145 { 92 if (!f View|| !item || fItems.HasItem(item))146 if (!fTarget || !item || fItems.HasItem(item)) 93 147 return false; 94 148 95 149 // if the item refers to a BView, we make sure it is added to the parent 96 150 // view 97 151 bool addedView = false; 98 152 BView* view = item->View(); 99 if (view && view->fParent != f View100 && !(addedView = f View->_AddChild(view, NULL)))153 if (view && view->fParent != fTarget 154 && !(addedView = fTarget->_AddChild(view, NULL))) 101 155 return false; 102 156 103 157 // validate the index … … 106 160 107 161 if (fItems.AddItem(item, index) && ItemAdded(item, index)) { 108 162 item->SetLayout(this); 163 if (!fAncestorsVisible) 164 item->AncestorVisibilityChanged(fAncestorsVisible); 109 165 InvalidateLayout(); 110 166 return true; 111 167 } else { … … 160 216 // if the item refers to a BView, we make sure, it is removed from the 161 217 // parent view 162 218 BView* view = item->View(); 163 if (view && view->fParent == f View)219 if (view && view->fParent == fTarget) 164 220 view->_RemoveSelf(); 165 221 222 ItemRemoved(item, index); 166 223 item->SetLayout(NULL); 167 ItemRemoved(item, index);168 224 InvalidateLayout(); 169 225 170 226 return item; … … 206 262 } 207 263 208 264 265 bool 266 BLayout::AncestorsVisible() 267 { 268 return fAncestorsVisible; 269 } 270 271 209 272 void 210 BLayout::InvalidateLayout( )273 BLayout::InvalidateLayout(bool children) 211 274 { 212 if (fView) 213 fView->InvalidateLayout(); 275 // printf("BLayout(%p)::InvalidateLayout(%i) : state %x, disabled %li\n", 276 // this, children, (unsigned int)fState, fInvalidationDisabled); 277 278 if (!InvalidationLegal()) 279 return; 280 281 fState |= B_LAYOUT_NECESSARY; 282 283 if (children) { 284 for (int32 i = CountItems() - 1; i >= 0; i--) 285 ItemAt(i)->InvalidateLayout(children); 286 } 287 288 if (fOwner && BView::Private(fOwner).MinMaxValid()) 289 fOwner->InvalidateLayout(children); 290 291 if (BLayout* nestedIn = Layout()) { 292 if (nestedIn->InvalidationLegal()) 293 nestedIn->InvalidateLayout(); 294 } else if (fOwner) { 295 // If we weren't added as a BLayoutItem, we still have to invalidate 296 // whatever layout our owner is in. 297 BView* ownerParent = fOwner->fParent; 298 if (ownerParent) { 299 BLayout* layout = ownerParent->GetLayout(); 300 if (layout && layout->fNestedLayouts.CountItems() > 0) 301 layout->InvalidateLayoutsForView(fOwner); 302 else if (BView::Private(ownerParent).MinMaxValid()) 303 ownerParent->InvalidateLayout(false); 304 } 305 } 214 306 } 215 307 216 308 309 void 310 BLayout::RequireLayout() 311 { 312 fState |= B_LAYOUT_REQUIRED; 313 } 314 315 316 bool 317 BLayout::IsValid() 318 { 319 return (fState & B_LAYOUT_INVALID) == 0; 320 } 321 322 323 void 324 BLayout::DisableLayoutInvalidation() 325 { 326 fInvalidationDisabled++; 327 } 328 329 330 void 331 BLayout::EnableLayoutInvalidation() 332 { 333 if (fInvalidationDisabled > 0) 334 fInvalidationDisabled--; 335 } 336 337 338 void 339 BLayout::LayoutItems(bool force) 340 { 341 if ((fState & B_LAYOUT_NECESSARY) == 0 && !force) 342 return; 343 344 if (Layout() && (Layout()->fState & B_LAYOUT_IN_PROGRESS) != 0) 345 return; // wait for parent layout to lay us out. 346 347 if (fTarget && fTarget->LayoutContext()) 348 return; 349 350 BLayoutContext context; 351 _LayoutWithinContext(force, &context); 352 } 353 354 355 void 356 BLayout::Relayout(bool immediate) 357 { 358 if ((fState & B_RELAYOUT_NOT_OK) == 0 || immediate) { 359 fState |= B_LAYOUT_REQUIRED; 360 LayoutItems(false); 361 } 362 } 363 364 365 366 void 367 BLayout::_LayoutWithinContext(bool force, BLayoutContext* context) 368 { 369 // printf("BLayout(%p)::_LayoutWithinContext(%i, %p), state %x, fContext %p\n", 370 // this, force, context, (unsigned int)fState, fContext); 371 372 if ((fState & B_LAYOUT_NECESSARY) == 0 && !force) 373 return; 374 375 BLayoutContext* oldContext = fContext; 376 fContext = context; 377 378 if (fOwner && fOwner->LayoutContext() != context) { 379 // in this case, let our owner decide whether or not to have us 380 // do our layout, if they do, we won't end up here again. 381 fOwner->_Layout(force, context); 382 } else { 383 fState |= B_LAYOUT_IN_PROGRESS; 384 DerivedLayoutItems(); 385 // we must ensure that all items are laid out, layouts with a view will 386 // have their layout process triggered by their view, but nested 387 // view-less layouts must have their layout triggered here (if it hasn't 388 // already been triggered). 389 int32 nestedLayoutCount = fNestedLayouts.CountItems(); 390 for (int32 i = 0; i < nestedLayoutCount; i++) { 391 BLayout* layout = (BLayout*)fNestedLayouts.ItemAt(i); 392 if ((layout->fState & B_LAYOUT_NECESSARY) != 0) 393 layout->_LayoutWithinContext(force, context); 394 } 395 fState = B_LAYOUT_ALL_CLEAR; 396 } 397 398 fContext = oldContext; 399 } 400 401 402 BRect 403 BLayout::LayoutArea() 404 { 405 BRect area(Frame()); 406 if (fOwner) 407 area.OffsetTo(B_ORIGIN); 408 return area; 409 } 410 411 217 412 status_t 218 413 BLayout::Archive(BMessage* into, bool deep) const 219 414 { 220 415 BArchiver archiver(into); 221 status_t err = B Archivable::Archive(into, deep);416 status_t err = BLayoutItem::Archive(into, deep); 222 417 223 418 if (deep) { 224 419 int32 count = CountItems(); … … 242 437 BLayout::AllUnarchived(const BMessage* from) 243 438 { 244 439 BUnarchiver unarchiver(from); 245 status_t err = B Archivable::AllUnarchived(from);440 status_t err = BLayoutItem::AllUnarchived(from); 246 441 if (err != B_OK) 247 442 return err; 248 443 … … 304 499 305 500 306 501 void 307 BLayout:: SetView(BView* view)502 BLayout::OwnerChanged(BView* was) 308 503 { 309 if (view != fView) { 310 fView = NULL; 504 } 311 505 506 507 void 508 BLayout::AttachedToLayout() 509 { 510 if (!fOwner) { 511 Layout()->fNestedLayouts.AddItem(this); 512 SetTarget(Layout()->TargetView()); 513 } 514 } 515 516 517 void 518 BLayout::DetachedFromLayout(BLayout* from) 519 { 520 if (!fOwner) { 521 from->fNestedLayouts.RemoveItem(this); 522 SetTarget(NULL); 523 } 524 } 525 526 527 void 528 BLayout::AncestorVisibilityChanged(bool shown) 529 { 530 if (fAncestorsVisible == shown) 531 return; 532 533 fAncestorsVisible = shown; 534 VisibilityChanged(shown); 535 } 536 537 538 void 539 BLayout::VisibilityChanged(bool show) 540 { 541 if (fOwner) 542 return; 543 544 for (int32 i = CountItems() - 1; i >= 0; i--) 545 ItemAt(i)->AncestorVisibilityChanged(show); 546 } 547 548 549 void 550 BLayout::ResetLayoutInvalidation() 551 { 552 fState &= ~B_LAYOUT_CACHE_INVALID; 553 } 554 555 556 BLayoutContext* 557 BLayout::LayoutContext() 558 { 559 return fContext; 560 } 561 562 563 bool 564 BLayout::RemoveViewRecursive(BView* view) 565 { 566 bool removed = RemoveView(view); 567 for (int32 i = fNestedLayouts.CountItems() - 1; i >= 0; i--) { 568 BLayout* nested = (BLayout*)fNestedLayouts.ItemAt(i); 569 removed |= nested->RemoveViewRecursive(view); 570 } 571 return removed; 572 } 573 574 575 bool 576 BLayout::InvalidateLayoutsForView(BView* view) 577 { 578 bool found = false; 579 for (int32 i = fNestedLayouts.CountItems() - 1; i >= 0; i--) { 580 BLayout* layout = (BLayout*)fNestedLayouts.ItemAt(i); 581 found |= layout->InvalidateLayoutsForView(view); 582 } 583 584 if (found) 585 return found; 586 587 if (!InvalidationLegal()) 588 return false; 589 590 for (int32 i = CountItems() - 1; i >= 0; i--) { 591 if (ItemAt(i)->View() == view) { 592 InvalidateLayout(); 593 return true; 594 } 595 } 596 return found; 597 } 598 599 600 bool 601 BLayout::InvalidationLegal() 602 { 603 return fInvalidationDisabled <= 0 604 && (fState & B_LAYOUT_INVALIDATION_ILLEGAL) == 0; 605 } 606 607 608 void 609 BLayout::SetOwner(BView* owner) 610 { 611 if (fOwner == owner) 612 return; 613 614 SetTarget(owner); 615 swap(fOwner, owner); 616 617 OwnerChanged(owner); 618 // call hook 619 } 620 621 622 void 623 BLayout::SetTarget(BView* target) 624 { 625 if (fTarget != target) { 626 fTarget = NULL; 627 // only remove items, not views 628 312 629 // remove and delete all items 313 630 for (int32 i = CountItems() - 1; i >= 0; i--) 314 631 delete RemoveItem(i); 315 632 316 f View = view;633 fTarget = target; 317 634 318 635 InvalidateLayout(); 319 636 } -
src/kits/interface/ViewLayoutItem.cpp
11 11 12 12 #include <Layout.h> 13 13 #include <View.h> 14 #include <ViewPrivate.h> 14 15 15 16 16 17 namespace { … … 20 21 21 22 BViewLayoutItem::BViewLayoutItem(BView* view) 22 23 : 23 fView(view) 24 fView(view), 25 fAncestorsVisible(true) 24 26 { 25 27 } 26 28 … … 28 30 BViewLayoutItem::BViewLayoutItem(BMessage* from) 29 31 : 30 32 BLayoutItem(BUnarchiver::PrepareArchive(from)), 31 fView(NULL) 33 fView(NULL), 34 fAncestorsVisible(true) 32 35 { 33 36 BUnarchiver unarchiver(from); 34 37 unarchiver.Finish(unarchiver.FindObject<BView>(kViewField, 0, … … 100 103 bool 101 104 BViewLayoutItem::IsVisible() 102 105 { 103 return !fView->IsHidden(fView); 106 int16 showLevel = BView::Private(fView).ShowLevel(); 107 return showLevel - (fAncestorsVisible ? 0 : 1) <= 0; 104 108 } 105 109 106 110 … … 154 158 155 159 156 160 void 157 BViewLayoutItem::InvalidateLayout( )161 BViewLayoutItem::InvalidateLayout(bool children) 158 162 { 159 fView->InvalidateLayout( );163 fView->InvalidateLayout(children); 160 164 } 161 165 162 166 167 void 168 BViewLayoutItem::Relayout(bool immediate) 169 { 170 if (immediate) 171 fView->Layout(false); 172 else 173 fView->Relayout(); 174 } 175 176 163 177 status_t 164 178 BViewLayoutItem::Archive(BMessage* into, bool deep) const 165 179 { … … 204 218 return new(std::nothrow) BViewLayoutItem(from); 205 219 return NULL; 206 220 } 221 222 223 void 224 BViewLayoutItem::AncestorVisibilityChanged(bool shown) 225 { 226 if (fAncestorsVisible == shown) 227 return; 228 229 fAncestorsVisible = shown; 230 if (shown) 231 fView->Show(); 232 if (!shown) 233 fView->Hide(); 234 } 235 -
src/kits/interface/LayoutItem.cpp
8 8 9 9 #include <Layout.h> 10 10 #include <LayoutUtils.h> 11 #include <View.h> 11 12 13 #include <algorithm> 12 14 15 13 16 BLayoutItem::BLayoutItem() 14 17 : 15 18 fLayout(NULL), … … 30 33 31 34 BLayoutItem::~BLayoutItem() 32 35 { 36 if (fLayout) 37 fLayout->RemoveItem(this); 33 38 } 34 39 35 40 … … 64 69 65 70 66 71 void 67 BLayoutItem::InvalidateLayout( )72 BLayoutItem::InvalidateLayout(bool children) 68 73 { 69 74 if (fLayout) 70 fLayout->InvalidateLayout( );75 fLayout->InvalidateLayout(children); 71 76 } 72 77 73 78 79 void 80 BLayoutItem::Relayout(bool immediate) 81 { 82 BView* view = View(); 83 if (view && !immediate) 84 view->Relayout(); 85 else if (view && immediate) 86 view->Layout(false); 87 } 88 89 74 90 void* 75 91 BLayoutItem::LayoutData() const 76 92 { … … 144 160 void 145 161 BLayoutItem::SetLayout(BLayout* layout) 146 162 { 147 fLayout = layout; 163 if (layout == fLayout) 164 return; 165 166 std::swap(fLayout, layout); 167 if (layout) 168 DetachedFromLayout(layout); 169 170 if (fLayout) 171 AttachedToLayout(); 148 172 } 173 174 175 void 176 BLayoutItem::AttachedToLayout() 177 { 178 // hook method 179 } 180 181 182 void 183 BLayoutItem::DetachedFromLayout(BLayout* oldLayout) 184 { 185 // hook method 186 } 187 188 189 void 190 BLayoutItem::AncestorVisibilityChanged(bool shown) 191 { 192 // hook method 193 } 194 -
src/kits/interface/SplitLayout.h
6 6 #define _SPLIT_LAYOUT_H 7 7 8 8 9 #include < Layout.h>9 #include <AbstractLayout.h> 10 10 #include <Point.h> 11 11 12 12 … … 21 21 using BPrivate::Layout::LayoutInfo; 22 22 23 23 24 class BSplitLayout : public B Layout {24 class BSplitLayout : public BAbstractLayout { 25 25 public: 26 26 BSplitLayout(enum orientation orientation, 27 27 float spacing = 0.0f); … … 66 66 void SetCollapsible(int32 first, int32 last, 67 67 bool collapsible); 68 68 69 virtual BSize MinSize();70 virtual BSize MaxSize();71 virtual BSize PreferredSize();72 virtual BAlignment Alignment();69 virtual BSize BaseMinSize(); 70 virtual BSize BaseMaxSize(); 71 virtual BSize BasePreferredSize(); 72 virtual BAlignment BaseAlignment(); 73 73 74 74 virtual bool HasHeightForWidth(); 75 75 virtual void GetHeightForWidth(float width, float* min, 76 76 float* max, float* preferred); 77 77 78 virtual void InvalidateLayout( );78 virtual void InvalidateLayout(bool children = false); 79 79 80 virtual void LayoutView();80 virtual void DerivedLayoutItems(); 81 81 82 82 // interface for BSplitView 83 83 BRect SplitterItemFrame(int32 index) const; … … 106 106 class ValueRange; 107 107 class SplitterItem; 108 108 109 void _InvalidateLayout(bool invalidateView); 109 void _InvalidateLayout(bool invalidateView, 110 bool children = false); 110 111 void _InvalidateCachedHeightForWidth(); 111 112 112 113 SplitterItem* _SplitterItemAt(const BPoint& point, -
src/kits/interface/GroupLayoutBuilder.cpp
28 28 _PushLayout(fRootLayout); 29 29 } 30 30 31 32 31 // constructor 33 32 BGroupLayoutBuilder::BGroupLayoutBuilder(BGroupView* view) 34 33 : fRootLayout(view->GroupLayout()) … … 64 63 BView* 65 64 BGroupLayoutBuilder::TopView() const 66 65 { 67 return TopLayout()-> View();66 return TopLayout()->Owner(); 68 67 } 69 68 70 69 // GetTopView … … 72 71 BGroupLayoutBuilder::GetTopView(BView** _view) 73 72 { 74 73 if (BGroupLayout* layout = TopLayout()) 75 *_view = layout-> View();74 *_view = layout->Owner(); 76 75 else 77 76 *_view = NULL; 78 77 … … 181 180 return fRootLayout; 182 181 } 183 182 184 // cast operator BView*185 BGroupLayoutBuilder::operator BView*()186 {187 return fRootLayout->View();188 }189 190 183 // _PushLayout 191 184 bool 192 185 BGroupLayoutBuilder::_PushLayout(BGroupLayout* layout) -
src/kits/interface/CardLayout.cpp
17 17 18 18 BCardLayout::BCardLayout() 19 19 : 20 B Layout(),20 BAbstractLayout(), 21 21 fMin(0, 0), 22 22 fMax(B_SIZE_UNLIMITED, B_SIZE_UNLIMITED), 23 23 fPreferred(0, 0), … … 29 29 30 30 BCardLayout::BCardLayout(BMessage* from) 31 31 : 32 B Layout(BUnarchiver::PrepareArchive(from)),32 BAbstractLayout(BUnarchiver::PrepareArchive(from)), 33 33 fMin(0, 0), 34 34 fMax(B_SIZE_UNLIMITED, B_SIZE_UNLIMITED), 35 35 fPreferred(0, 0), … … 83 83 if (fVisibleItem != NULL) { 84 84 fVisibleItem->SetVisible(true); 85 85 86 LayoutView();86 Relayout(); 87 87 } 88 88 } 89 89 90 90 91 91 BSize 92 BCardLayout:: MinSize()92 BCardLayout::BaseMinSize() 93 93 { 94 94 _ValidateMinMax(); 95 95 return fMin; … … 97 97 98 98 99 99 BSize 100 BCardLayout:: MaxSize()100 BCardLayout::BaseMaxSize() 101 101 { 102 102 _ValidateMinMax(); 103 103 return fMax; … … 105 105 106 106 107 107 BSize 108 BCardLayout:: PreferredSize()108 BCardLayout::BasePreferredSize() 109 109 { 110 110 _ValidateMinMax(); 111 111 return fPreferred; … … 113 113 114 114 115 115 BAlignment 116 BCardLayout:: Alignment()116 BCardLayout::BaseAlignment() 117 117 { 118 118 return BAlignment(B_ALIGN_USE_FULL_WIDTH, B_ALIGN_USE_FULL_HEIGHT); 119 119 } … … 174 174 175 175 176 176 void 177 BCardLayout::InvalidateLayout( )177 BCardLayout::InvalidateLayout(bool children) 178 178 { 179 BLayout::InvalidateLayout( );179 BLayout::InvalidateLayout(children); 180 180 181 181 fMinMaxValid = false; 182 182 } 183 183 184 184 185 185 void 186 BCardLayout:: LayoutView()186 BCardLayout::DerivedLayoutItems() 187 187 { 188 188 _ValidateMinMax(); 189 189 190 BSize size = View()->Bounds().Size(); 191 size.width = max_c(size.width, fMin.width); 192 size.height = max_c(size.height, fMin.height); 190 BSize size(LayoutArea().Size()); 193 191 194 if (fVisibleItem != NULL) 195 fVisibleItem->AlignInFrame(BRect(0, 0, size.width, size.height)); 192 // this cannot be done when we are viewless, as our children 193 // would not get cut off in the right place. 194 if (Owner()) { 195 size.width = max_c(size.width, fMin.width); 196 size.height = max_c(size.height, fMin.height); 197 } 198 199 if (fVisibleItem != NULL) 200 fVisibleItem->AlignInFrame(BRect(LayoutArea().LeftTop(), size)); 196 201 } 197 202 198 203 … … 200 205 BCardLayout::Archive(BMessage* into, bool deep) const 201 206 { 202 207 BArchiver archiver(into); 203 status_t err = B Layout::Archive(into, deep);208 status_t err = BAbstractLayout::Archive(into, deep); 204 209 205 210 if (err == B_OK && deep) 206 211 err = into->AddInt32(kVisibleItemField, IndexOfItem(fVisibleItem)); … … 292 297 fPreferred.height = min_c(fPreferred.height, fMax.height); 293 298 294 299 fMinMaxValid = true; 295 296 if (BView* view = View()) 297 view->ResetLayoutInvalidation(); 300 ResetLayoutInvalidation(); 298 301 } -
src/kits/interface/Jamfile
31 31 SEARCH_SOURCE += [ FDirName $(SUBDIR) layouter ] ; 32 32 33 33 MergeObject <libbe>interface_kit.o : 34 AbstractLayout.cpp 34 35 AbstractLayoutItem.cpp 35 36 AffineTransform.cpp 36 37 Alert.cpp -
src/kits/interface/SplitLayout.cpp
196 196 197 197 BSplitLayout::BSplitLayout(BMessage* from) 198 198 : 199 B Layout(BUnarchiver::PrepareArchive(from)),199 BAbstractLayout(BUnarchiver::PrepareArchive(from)), 200 200 fSplitterItems(), 201 201 fVisibleItems(), 202 202 fMin(), … … 340 340 BLayoutItem* 341 341 BSplitLayout::AddView(BView* child) 342 342 { 343 return B Layout::AddView(child);343 return BAbstractLayout::AddView(child); 344 344 } 345 345 346 346 347 347 BLayoutItem* 348 348 BSplitLayout::AddView(int32 index, BView* child) 349 349 { 350 return B Layout::AddView(index, child);350 return BAbstractLayout::AddView(index, child); 351 351 } 352 352 353 353 … … 372 372 bool 373 373 BSplitLayout::AddItem(BLayoutItem* item) 374 374 { 375 return B Layout::AddItem(item);375 return BAbstractLayout::AddItem(item); 376 376 } 377 377 378 378 379 379 bool 380 380 BSplitLayout::AddItem(int32 index, BLayoutItem* item) 381 381 { 382 return B Layout::AddItem(index, item);382 return BAbstractLayout::AddItem(index, item); 383 383 } 384 384 385 385 … … 480 480 481 481 482 482 BSize 483 BSplitLayout:: MinSize()483 BSplitLayout::BaseMinSize() 484 484 { 485 485 _ValidateMinMax(); 486 486 … … 489 489 490 490 491 491 BSize 492 BSplitLayout:: MaxSize()492 BSplitLayout::BaseMaxSize() 493 493 { 494 494 _ValidateMinMax(); 495 495 … … 498 498 499 499 500 500 BSize 501 BSplitLayout:: PreferredSize()501 BSplitLayout::BasePreferredSize() 502 502 { 503 503 _ValidateMinMax(); 504 504 … … 507 507 508 508 509 509 BAlignment 510 BSplitLayout:: Alignment()510 BSplitLayout::BaseAlignment() 511 511 { 512 return BA lignment(B_ALIGN_USE_FULL_WIDTH, B_ALIGN_USE_FULL_HEIGHT);512 return BAbstractLayout::BaseAlignment(); 513 513 } 514 514 515 515 … … 536 536 537 537 538 538 void 539 BSplitLayout::InvalidateLayout( )539 BSplitLayout::InvalidateLayout(bool children) 540 540 { 541 _InvalidateLayout(true );541 _InvalidateLayout(true, children); 542 542 } 543 543 544 544 545 545 void 546 BSplitLayout:: LayoutView()546 BSplitLayout::DerivedLayoutItems() 547 547 { 548 548 _ValidateMinMax(); 549 549 550 550 // layout the elements 551 BSize size = _SubtractInsets( View()->Bounds().Size());551 BSize size = _SubtractInsets(LayoutArea().Size()); 552 552 fHorizontalLayouter->Layout(fHorizontalLayoutInfo, size.width); 553 553 554 554 Layouter* verticalLayouter; … … 647 647 return false; 648 648 649 649 // Things shouldn't be draggable, if we have a >= max layout. 650 BSize size = _SubtractInsets( View()->Frame().Size());650 BSize size = _SubtractInsets(LayoutArea().Size()); 651 651 if ((fOrientation == B_HORIZONTAL && size.width >= fMax.width) 652 652 || (fOrientation == B_VERTICAL && size.height >= fMax.height)) { 653 653 return false; … … 655 655 656 656 int32 index = -1; 657 657 if (_SplitterItemAt(point, &index) != NULL) { 658 fDraggingStartPoint = View()->ConvertToScreen(point);658 fDraggingStartPoint = Owner()->ConvertToScreen(point); 659 659 fDraggingStartValue = _SplitterValue(index); 660 660 fDraggingCurrentValue = fDraggingStartValue; 661 661 fDraggingSplitterIndex = index; … … 673 673 if (fDraggingSplitterIndex < 0) 674 674 return false; 675 675 676 point = View()->ConvertToScreen(point);676 point = Owner()->ConvertToScreen(point); 677 677 678 678 int32 valueDiff; 679 679 if (fOrientation == B_HORIZONTAL) … … 712 712 BSplitLayout::Archive(BMessage* into, bool deep) const 713 713 { 714 714 BArchiver archiver(into); 715 status_t err = B Layout::Archive(into, deep);715 status_t err = BAbstractLayout::Archive(into, deep); 716 716 717 717 if (err == B_OK) 718 718 err = into->AddBool(kIsVerticalField, fOrientation == B_VERTICAL); … … 811 811 812 812 813 813 void 814 BSplitLayout::_InvalidateLayout(bool invalidateView )814 BSplitLayout::_InvalidateLayout(bool invalidateView, bool children) 815 815 { 816 816 if (invalidateView) 817 B Layout::InvalidateLayout();817 BAbstractLayout::InvalidateLayout(children); 818 818 819 819 delete fHorizontalLayouter; 820 820 delete fVerticalLayouter; … … 929 929 info->max = item->MaxSize(); 930 930 931 931 if (item->HasHeightForWidth()) { 932 BSize size = _SubtractInsets( View()->Frame().Size());932 BSize size = _SubtractInsets(LayoutArea().Size()); 933 933 float minHeight, maxHeight; 934 934 item->GetHeightForWidth(size.width, &minHeight, &maxHeight, NULL); 935 935 info->min.height = max_c(info->min.height, minHeight); … … 958 958 item->AlignInFrame(info->layoutFrame); 959 959 960 960 // if the item became visible, we need to update its internal layout 961 if (visibilityChanged ) {962 if (BView* itemView = item->View())963 itemView->Layout(false);961 if (visibilityChanged && fOrientation != B_HORIZONTAL 962 && !HasHeightForWidth()) { 963 item->Relayout(true); 964 964 } 965 965 } 966 966 … … 1216 1216 } 1217 1217 1218 1218 // Just updating the splitter weights is fine in principle. The next 1219 // Layout View() will use the correct values. But, if our orientation is1219 // LayoutItems() will use the correct values. But, if our orientation is 1220 1220 // vertical, the cached height for width info needs to be flushed, or the 1221 1221 // obsolete cached values will be used. 1222 1222 if (fOrientation == B_VERTICAL) … … 1293 1293 if (fHeightForWidthItems.IsEmpty()) 1294 1294 fVerticalLayoutInfo = fVerticalLayouter->CreateLayoutInfo(); 1295 1295 1296 if (BView* view = View()) 1297 view->ResetLayoutInvalidation(); 1296 ResetLayoutInvalidation(); 1298 1297 } 1299 1298 1300 1299 -
src/kits/interface/TwoDimensionalLayout.cpp
258 258 259 259 BTwoDimensionalLayout::BTwoDimensionalLayout(BMessage* from) 260 260 : 261 B Layout(from),261 BAbstractLayout(from), 262 262 fLeftInset(0), 263 263 fRightInset(0), 264 264 fTopInset(0), … … 324 324 325 325 326 326 BSize 327 BTwoDimensionalLayout:: MinSize()327 BTwoDimensionalLayout::BaseMinSize() 328 328 { 329 329 _ValidateMinMax(); 330 330 return AddInsets(fLocalLayouter->MinSize()); … … 332 332 333 333 334 334 BSize 335 BTwoDimensionalLayout:: MaxSize()335 BTwoDimensionalLayout::BaseMaxSize() 336 336 { 337 337 _ValidateMinMax(); 338 338 return AddInsets(fLocalLayouter->MaxSize()); … … 340 340 341 341 342 342 BSize 343 BTwoDimensionalLayout:: PreferredSize()343 BTwoDimensionalLayout::BasePreferredSize() 344 344 { 345 345 _ValidateMinMax(); 346 346 return AddInsets(fLocalLayouter->PreferredSize()); … … 348 348 349 349 350 350 BAlignment 351 BTwoDimensionalLayout:: Alignment()351 BTwoDimensionalLayout::BaseAlignment() 352 352 { 353 return BA lignment(B_ALIGN_USE_FULL_WIDTH, B_ALIGN_USE_FULL_HEIGHT);353 return BAbstractLayout::BaseAlignment(); 354 354 } 355 355 356 356 … … 377 377 378 378 379 379 void 380 BTwoDimensionalLayout:: InvalidateLayout()380 BTwoDimensionalLayout::SetFrame(BRect frame) 381 381 { 382 BLayout::InvalidateLayout(); 383 384 fLocalLayouter->InvalidateLayout(); 382 BAbstractLayout::SetFrame(frame); 385 383 } 386 384 387 385 388 386 void 389 BTwoDimensionalLayout:: LayoutView()387 BTwoDimensionalLayout::InvalidateLayout(bool children) 390 388 { 391 _ValidateMinMax(); 392 393 // layout the horizontal/vertical elements 394 BSize size = SubtractInsets(View()->Frame().Size()); 395 396 #ifdef DEBUG_LAYOUT 397 printf("BTwoDimensionalLayout::LayoutView(%p): size: (%.1f, %.1f)\n", 398 View(), size.width, size.height); 399 #endif 400 401 fLocalLayouter->Layout(size); 402 403 // layout the items 404 int itemCount = CountItems(); 405 for (int i = 0; i < itemCount; i++) { 406 BLayoutItem* item = ItemAt(i); 407 if (item->IsVisible()) { 408 Dimensions itemDimensions; 409 GetItemDimensions(item, &itemDimensions); 410 BRect frame = fLocalLayouter->ItemFrame(itemDimensions); 411 frame.left += fLeftInset; 412 frame.top += fTopInset; 413 frame.right += fLeftInset; 414 frame.bottom += fTopInset; 415 { 416 #ifdef DEBUG_LAYOUT 417 printf(" frame for item %2d (view: %p): ", i, item->View()); 418 frame.PrintToStream(); 419 #endif 420 //BSize min(item->MinSize()); 421 //BSize max(item->MaxSize()); 422 //printf(" min: (%.1f, %.1f), max: (%.1f, %.1f)\n", min.width, min.height, 423 // max.width, max.height); 424 //if (item->HasHeightForWidth()) { 425 //float minHeight, maxHeight, preferredHeight; 426 //item->GetHeightForWidth(frame.Width(), &minHeight, &maxHeight, 427 // &preferredHeight); 428 //printf(" hfw: min: %.1f, max: %.1f, pref: %.1f\n", minHeight, maxHeight, 429 // preferredHeight); 430 //} 389 BLayout::InvalidateLayout(children); 390 fLocalLayouter->InvalidateLayout(); 431 391 } 432 392 433 item->AlignInFrame(frame);434 }435 //else436 //printf(" item %2d not visible", i);437 }438 }439 393 440 441 394 status_t 442 395 BTwoDimensionalLayout::Archive(BMessage* into, bool deep) const 443 396 { 444 397 BArchiver archiver(into); 445 status_t err = B Layout::Archive(into, deep);398 status_t err = BAbstractLayout::Archive(into, deep); 446 399 447 400 if (err == B_OK) { 448 401 BRect insets(fLeftInset, fTopInset, fRightInset, fBottomInset); … … 487 440 } 488 441 489 442 443 void 444 BTwoDimensionalLayout::DerivedLayoutItems() 445 { 446 _ValidateMinMax(); 447 448 // layout the horizontal/vertical elements 449 BSize size(SubtractInsets(LayoutArea().Size())); 450 451 #ifdef DEBUG_LAYOUT 452 printf("BTwoDimensionalLayout::DerivedLayoutItems(): view: %p" 453 " size: (%.1f, %.1f)\n", View(), size.Width(), size.Height()); 454 #endif 455 456 fLocalLayouter->Layout(size); 457 458 // layout the items 459 BPoint itemOffset(LayoutArea().LeftTop()); 460 int itemCount = CountItems(); 461 for (int i = 0; i < itemCount; i++) { 462 BLayoutItem* item = ItemAt(i); 463 if (item->IsVisible()) { 464 Dimensions itemDimensions; 465 GetItemDimensions(item, &itemDimensions); 466 BRect frame = fLocalLayouter->ItemFrame(itemDimensions); 467 frame.left += fLeftInset; 468 frame.top += fTopInset; 469 frame.right += fLeftInset; 470 frame.bottom += fTopInset; 471 frame.OffsetBy(itemOffset); 472 { 473 #ifdef DEBUG_LAYOUT 474 printf(" frame for item %2d (view: %p): ", i, item->View()); 475 frame.PrintToStream(); 476 #endif 477 //BSize min(item->MinSize()); 478 //BSize max(item->MaxSize()); 479 //printf(" min: (%.1f, %.1f), max: (%.1f, %.1f)\n", min.width, min.height, 480 // max.width, max.height); 481 //if (item->HasHeightForWidth()) { 482 //float minHeight, maxHeight, preferredHeight; 483 //item->GetHeightForWidth(frame.Width(), &minHeight, &maxHeight, 484 // &preferredHeight); 485 //printf(" hfw: min: %.1f, max: %.1f, pref: %.1f\n", minHeight, maxHeight, 486 // preferredHeight); 487 //} 488 } 489 490 item->AlignInFrame(frame); 491 } 492 //else 493 //printf(" item %2d not visible", i); 494 } 495 } 496 497 490 498 BSize 491 499 BTwoDimensionalLayout::AddInsets(BSize size) 492 500 { … … 547 555 BTwoDimensionalLayout::_ValidateMinMax() 548 556 { 549 557 fLocalLayouter->ValidateMinMax(); 550 551 if (BView* view = View())552 view->ResetLayoutInvalidation();553 558 } 554 559 555 560 556 BLayoutContext*557 BTwoDimensionalLayout::_CurrentLayoutContext()558 {559 BView* view = View();560 return (view ? view->LayoutContext() : NULL);561 }562 563 564 561 // #pragma mark - CompoundLayouter 565 562 566 563 … … 1060 1057 BTwoDimensionalLayout::LocalLayouter::Layout(BSize size) 1061 1058 { 1062 1059 DoHorizontalLayout(size.width); 1063 fVLayouter->Layout(size.height, this, fLayout-> _CurrentLayoutContext());1060 fVLayouter->Layout(size.height, this, fLayout->LayoutContext()); 1064 1061 } 1065 1062 1066 1063 … … 1092 1089 1093 1090 fHLayouter->ValidateMinMax(); 1094 1091 fVLayouter->ValidateMinMax(); 1092 fLayout->ResetLayoutInvalidation(); 1095 1093 } 1096 1094 1097 1095 1098 1096 void 1099 1097 BTwoDimensionalLayout::LocalLayouter::DoHorizontalLayout(float width) 1100 1098 { 1101 BLayoutContext* context = fLayout-> _CurrentLayoutContext();1099 BLayoutContext* context = fLayout->LayoutContext(); 1102 1100 if (fHorizontalLayoutContext != context 1103 1101 || width != fHorizontalLayoutWidth) { 1104 1102 _SetHorizontalLayoutContext(context, width); -
src/kits/interface/Window.cpp
543 543 } 544 544 545 545 546 void 547 BWindow::AddChild(BLayoutItem* child) 548 { 549 BAutolock locker(this); 550 if (locker.IsLocked()) 551 fTopView->AddChild(child); 552 } 553 554 546 555 bool 547 556 BWindow::RemoveChild(BView* child) 548 557 { -
src/kits/interface/GridLayoutBuilder.cpp
45 45 BView* 46 46 BGridLayoutBuilder::View() const 47 47 { 48 return fLayout-> View();48 return fLayout->Owner(); 49 49 } 50 50 51 51 // GetGridLayout … … 60 60 BGridLayoutBuilder& 61 61 BGridLayoutBuilder::GetView(BView** _view) 62 62 { 63 *_view = fLayout-> View();63 *_view = fLayout->Owner(); 64 64 return *this; 65 65 } 66 66 … … 112 112 return fLayout; 113 113 } 114 114 115 // cast operator BView*116 BGridLayoutBuilder::operator BView*()117 {118 return fLayout->View();119 } -
headers/os/interface/TwoDimensionalLayout.h
6 6 #define _TWO_DIMENSIONAL_LAYOUT_H 7 7 8 8 9 #include < Layout.h>9 #include <AbstractLayout.h> 10 10 11 11 class BLayoutContext; 12 12 13 13 14 class BTwoDimensionalLayout : public B Layout {14 class BTwoDimensionalLayout : public BAbstractLayout { 15 15 public: 16 16 BTwoDimensionalLayout(); 17 17 BTwoDimensionalLayout(BMessage* from); … … 25 25 void AlignLayoutWith(BTwoDimensionalLayout* other, 26 26 enum orientation orientation); 27 27 28 virtual BSize MinSize();29 virtual BSize MaxSize();30 virtual BSize PreferredSize();31 virtual BAlignment Alignment();28 virtual BSize BaseMinSize(); 29 virtual BSize BaseMaxSize(); 30 virtual BSize BasePreferredSize(); 31 virtual BAlignment BaseAlignment(); 32 32 33 33 virtual bool HasHeightForWidth(); 34 34 virtual void GetHeightForWidth(float width, float* min, 35 35 float* max, float* preferred); 36 36 37 virtual void InvalidateLayout();37 virtual void SetFrame(BRect frame); 38 38 39 virtual void LayoutView();39 virtual void InvalidateLayout(bool children = false); 40 40 41 41 virtual status_t Archive(BMessage* into, bool deep = true) const; 42 42 virtual status_t AllArchived(BMessage* into) const; … … 56 56 int32 height; 57 57 }; 58 58 59 virtual void DerivedLayoutItems(); 60 59 61 BSize AddInsets(BSize size); 60 62 void AddInsets(float* minHeight, float* maxHeight, 61 63 float* preferredHeight); … … 82 84 friend class LocalLayouter; 83 85 84 86 void _ValidateMinMax(); 85 BLayoutContext* _CurrentLayoutContext();86 87 87 88 protected: 88 89 float fLeftInset; -
headers/os/interface/Layout.h
8 8 9 9 #include <Alignment.h> 10 10 #include <Archivable.h> 11 #include <LayoutItem.h> 11 12 #include <List.h> 12 13 #include <Size.h> 13 14 14 15 16 class BLayoutContext; 15 17 class BLayoutItem; 16 18 class BView; 17 19 18 20 19 class BLayout : public B Archivable{21 class BLayout : public BLayoutItem { 20 22 public: 21 23 BLayout(); 22 24 BLayout(BMessage* archive); 23 25 virtual ~BLayout(); 24 26 25 BView* View() const; 27 BView* Owner() const; 28 BView* TargetView() const; 29 virtual BView* View(); // from BLayoutItem 26 30 31 // methods dealing with items 27 32 virtual BLayoutItem* AddView(BView* child); 28 33 virtual BLayoutItem* AddView(int32 index, BView* child); 29 34 … … 39 44 int32 IndexOfItem(const BLayoutItem* item) const; 40 45 int32 IndexOfView(BView* child) const; 41 46 42 virtual BSize MinSize() = 0; 43 virtual BSize MaxSize() = 0; 44 virtual BSize PreferredSize() = 0; 45 virtual BAlignment Alignment() = 0; 47 bool AncestorsVisible(); 46 48 47 virtual bool HasHeightForWidth() = 0; 48 virtual void GetHeightForWidth(float width, float* min, 49 float* max, float* preferred) = 0; 49 // Layouting related methods 50 50 51 virtual void InvalidateLayout(); 51 virtual void InvalidateLayout(bool children = false); 52 virtual void Relayout(bool immediate = false); 53 void RequireLayout(); 54 bool IsValid(); 55 void EnableLayoutInvalidation(); 56 void DisableLayoutInvalidation(); 52 57 53 virtual void LayoutView() = 0; 58 void LayoutItems(bool force = false); 59 BRect LayoutArea(); 60 BLayoutContext* LayoutContext(); 54 61 62 // Archiving methods 63 55 64 virtual status_t Archive(BMessage* into, bool deep = true) const; 56 65 virtual status_t AllUnarchived(const BMessage* from); 57 66 … … 59 68 int32 index) const; 60 69 virtual status_t ItemUnarchived(const BMessage* from, 61 70 BLayoutItem* item, int32 index); 71 62 72 protected: 73 // BLayout hook methods 63 74 virtual bool ItemAdded(BLayoutItem* item, int32 atIndex); 64 75 virtual void ItemRemoved(BLayoutItem* item, int32 fromIndex); 76 virtual void DerivedLayoutItems() = 0; 77 virtual void OwnerChanged(BView* was); 65 78 79 // BLayoutItem hook methods 80 virtual void AttachedToLayout(); 81 virtual void DetachedFromLayout(BLayout* layout); 82 virtual void AncestorVisibilityChanged(bool shown); 83 84 // To be called by sub-classes in SetVisible(). 85 void VisibilityChanged(bool show); 86 // To be called when layout data is known to be good 87 void ResetLayoutInvalidation(); 88 66 89 private: 67 90 friend class BView; 68 91 69 void SetView(BView* view); 92 bool RemoveViewRecursive(BView* view); 93 bool InvalidateLayoutsForView(BView* view); 94 bool InvalidationLegal(); 95 void SetOwner(BView* owner); 96 void SetTarget(BView* target); 70 97 71 BView* fView; 98 void _LayoutWithinContext(bool force, 99 BLayoutContext* context); 100 101 uint32 fState; 102 bool fAncestorsVisible; 103 int32 fInvalidationDisabled; 104 BLayoutContext* fContext; 105 BView* fOwner; 106 BView* fTarget; 72 107 BList fItems; 108 BList fNestedLayouts; 73 109 }; 74 110 75 111 -
headers/os/interface/LayoutBuilder.h
33 33 public: 34 34 inline void SetParent(ParentBuilder* parent); 35 35 // conceptually private 36 37 36 inline ParentBuilder& End(); 38 37 39 38 protected: … … 71 70 72 71 inline GroupBuilder AddGroup(enum orientation orientation, 73 72 float spacing = 0.0f, float weight = 1.0f); 73 inline GroupBuilder AddGroup(BGroupView* groupView, 74 float weight = 1.0f); 75 inline GroupBuilder AddGroup(BGroupLayout* groupLayout, 76 float weight = 1.0f); 77 74 78 inline GridBuilder AddGrid(float horizontalSpacing = 0.0f, 75 79 float verticalSpacing = 0.0f, 76 80 float weight = 1.0f); 81 inline GridBuilder AddGrid(BGridLayout* gridLayout, 82 float weight = 1.0f); 83 inline GridBuilder AddGrid(BGridView* gridView, 84 float weight = 1.0f); 85 77 86 inline SplitBuilder AddSplit(enum orientation orientation, 78 87 float spacing = 0.0f, float weight = 1.0f); 88 inline SplitBuilder AddSplit(BSplitView* splitView, 89 float weight = 1.0f); 79 90 80 91 inline ThisBuilder& AddGlue(float weight = 1.0f); 81 92 inline ThisBuilder& AddStrut(float size); … … 84 95 float bottom); 85 96 86 97 inline operator BGroupLayout*(); 87 inline operator BView*();88 98 89 99 private: 90 100 BGroupLayout* fLayout; … … 131 141 inline GroupBuilder AddGroup(enum orientation orientation, 132 142 float spacing, int32 column, int32 row, 133 143 int32 columnCount = 1, int32 rowCount = 1); 144 inline GroupBuilder AddGroup(BGroupView* groupView, int32 column, 145 int32 row, int32 columnCount = 1, 146 int32 rowCount = 1); 147 inline GroupBuilder AddGroup(BGroupLayout* groupLayout, 148 int32 column, int32 row, 149 int32 columnCount = 1, int32 rowCount = 1); 150 134 151 inline GridBuilder AddGrid(float horizontalSpacing, 135 152 float verticalSpacing, int32 column, 136 153 int32 row, int32 columnCount = 1, 137 154 int32 rowCount = 1); 155 inline GridBuilder AddGrid(BGridLayout* gridLayout, 156 int32 column, int32 row, 157 int32 columnCount = 1, int32 rowCount = 1); 158 inline GridBuilder AddGrid(BGridView* gridView, 159 int32 column, int32 row, 160 int32 columnCount = 1, int32 rowCount = 1); 161 138 162 inline SplitBuilder AddSplit(enum orientation orientation, 139 163 float spacing, int32 column, int32 row, 140 164 int32 columnCount = 1, int32 rowCount = 1); 165 inline SplitBuilder AddSplit(BSplitView* splitView, int32 column, 166 int32 row, int32 columnCount = 1, 167 int32 rowCount = 1); 141 168 142 169 inline ThisBuilder& SetColumnWeight(int32 column, float weight); 143 170 inline ThisBuilder& SetRowWeight(int32 row, float weight); … … 146 173 float bottom); 147 174 148 175 inline operator BGridLayout*(); 149 inline operator BView*();150 176 151 177 private: 152 178 BGridLayout* fLayout; … … 168 194 inline Split(BSplitView* view); 169 195 170 196 inline BSplitView* View() const; 171 inline ThisBuilder& GetView(BSplitView** _view); 197 inline ThisBuilder& GetView(BView** _view); 198 inline ThisBuilder& GetSplitView(BSplitView** _view); 172 199 173 200 inline ThisBuilder& Add(BView* view); 174 201 inline ThisBuilder& Add(BView* view, float weight); … … 177 204 178 205 inline GroupBuilder AddGroup(enum orientation orientation, 179 206 float spacing = 0.0f, float weight = 1.0f); 207 inline GroupBuilder AddGroup(BGroupView* groupView, 208 float weight = 1.0f); 209 inline GroupBuilder AddGroup(BGroupLayout* groupLayout, 210 float weight = 1.0f); 211 180 212 inline GridBuilder AddGrid(float horizontalSpacing = 0.0f, 181 213 float verticalSpacing = 0.0f, 182 214 float weight = 1.0f); 215 inline GridBuilder AddGrid(BGridView* gridView, 216 float weight = 1.0f); 217 inline GridBuilder AddGrid(BGridLayout* gridLayout, 218 float weight = 1.0f); 219 183 220 inline SplitBuilder AddSplit(enum orientation orientation, 184 221 float spacing = 0.0f, float weight = 1.0f); 222 inline SplitBuilder AddSplit(BSplitView* splitView, 223 float weight = 1.0f); 185 224 186 225 inline ThisBuilder& SetCollapsible(bool collapsible); 187 226 inline ThisBuilder& SetCollapsible(int32 index, bool collapsible); … … 244 283 { 245 284 window->SetLayout(fLayout); 246 285 247 fLayout-> View()->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));286 fLayout->Owner()->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); 248 287 // TODO: we get a white background if we don't do this 249 288 } 250 289 … … 277 316 BView* 278 317 Group<ParentBuilder>::View() const 279 318 { 280 return fLayout-> View();319 return fLayout->Owner(); 281 320 } 282 321 283 322 … … 294 333 typename Group<ParentBuilder>::ThisBuilder& 295 334 Group<ParentBuilder>::GetView(BView** _view) 296 335 { 297 *_view = fLayout-> View();336 *_view = fLayout->Owner(); 298 337 return *this; 299 338 } 300 339 … … 340 379 Group<ParentBuilder>::AddGroup(enum orientation orientation, float spacing, 341 380 float weight) 342 381 { 343 GroupBuilder builder( orientation, spacing);382 GroupBuilder builder(new BGroupLayout(orientation, spacing)); 344 383 builder.SetParent(this); 345 fLayout->Add View(builder.View(), weight);384 fLayout->AddItem(builder.Layout(), weight); 346 385 return builder; 347 386 } 348 387 349 388 350 389 template<typename ParentBuilder> 390 typename Group<ParentBuilder>::GroupBuilder 391 Group<ParentBuilder>::AddGroup(BGroupView* groupView, float weight) 392 { 393 GroupBuilder builder(groupView); 394 builder.SetParent(this); 395 fLayout->AddItem(builder.Layout(), weight); 396 return builder; 397 } 398 399 400 template<typename ParentBuilder> 401 typename Group<ParentBuilder>::GroupBuilder 402 Group<ParentBuilder>::AddGroup(BGroupLayout* groupLayout, float weight) 403 { 404 GroupBuilder builder(groupLayout); 405 builder.SetParent(this); 406 fLayout->AddItem(builder.Layout(), weight); 407 return builder; 408 } 409 410 411 template<typename ParentBuilder> 351 412 typename Group<ParentBuilder>::GridBuilder 352 Group<ParentBuilder>::AddGrid(float horizontalSpacing, float verticalSpacing,353 float weight)413 Group<ParentBuilder>::AddGrid(float horizontalSpacing, 414 float verticalSpacing, float weight) 354 415 { 355 GridBuilder builder( horizontalSpacing, verticalSpacing);416 GridBuilder builder(new BGridLayout(horizontalSpacing, verticalSpacing)); 356 417 builder.SetParent(this); 357 fLayout->Add View(builder.View(), weight);418 fLayout->AddItem(builder.Layout(), weight); 358 419 return builder; 359 420 } 360 421 361 422 362 423 template<typename ParentBuilder> 424 typename Group<ParentBuilder>::GridBuilder 425 Group<ParentBuilder>::AddGrid(BGridLayout* gridLayout, float weight) 426 { 427 GridBuilder builder(gridLayout); 428 builder.SetParent(this); 429 fLayout->AddItem(builder.Layout(), weight); 430 return builder; 431 } 432 433 434 template<typename ParentBuilder> 435 typename Group<ParentBuilder>::GridBuilder 436 Group<ParentBuilder>::AddGrid(BGridView* gridView, float weight) 437 { 438 GridBuilder builder(gridView); 439 builder.SetParent(this); 440 fLayout->AddItem(builder.Layout(), weight); 441 return builder; 442 } 443 444 445 template<typename ParentBuilder> 363 446 typename Group<ParentBuilder>::SplitBuilder 364 447 Group<ParentBuilder>::AddSplit(enum orientation orientation, float spacing, 365 448 float weight) … … 372 455 373 456 374 457 template<typename ParentBuilder> 458 typename Group<ParentBuilder>::SplitBuilder 459 Group<ParentBuilder>::AddSplit(BSplitView* splitView, float weight) 460 { 461 SplitBuilder builder(splitView); 462 builder.SetParent(this); 463 fLayout->AddView(builder.View(), weight); 464 return builder; 465 } 466 467 468 template<typename ParentBuilder> 375 469 typename Group<ParentBuilder>::ThisBuilder& 376 470 Group<ParentBuilder>::AddGlue(float weight) 377 471 { … … 410 504 } 411 505 412 506 413 template<typename ParentBuilder>414 Group<ParentBuilder>::operator BView*()415 {416 return fLayout->View();417 }418 419 420 507 // #pragma mark - Grid 421 508 422 509 … … 436 523 { 437 524 window->SetLayout(fLayout); 438 525 439 fLayout-> View()->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));526 fLayout->Owner()->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); 440 527 // TODO: we get a white background if we don't do this 441 528 } 442 529 … … 469 556 BView* 470 557 Grid<ParentBuilder>::View() const 471 558 { 472 return fLayout-> View();559 return fLayout->Owner(); 473 560 } 474 561 475 562 … … 486 573 typename Grid<ParentBuilder>::ThisBuilder& 487 574 Grid<ParentBuilder>::GetView(BView** _view) 488 575 { 489 *_view = fLayout-> View();576 *_view = fLayout->Owner(); 490 577 return *this; 491 578 } 492 579 … … 546 633 Grid<ParentBuilder>::AddGroup(enum orientation orientation, float spacing, 547 634 int32 column, int32 row, int32 columnCount, int32 rowCount) 548 635 { 549 GroupBuilder builder( orientation, spacing);636 GroupBuilder builder(new BGroupLayout(orientation, spacing)); 550 637 builder.SetParent(this); 551 fLayout->Add View(builder.View(), column, row, columnCount, rowCount);638 fLayout->AddItem(builder.Layout(), column, row, columnCount, rowCount); 552 639 return builder; 553 640 } 554 641 555 642 556 643 template<typename ParentBuilder> 644 typename Grid<ParentBuilder>::GroupBuilder 645 Grid<ParentBuilder>::AddGroup(BGroupView* groupView, int32 column, int32 row, 646 int32 columnCount, int32 rowCount) 647 { 648 GroupBuilder builder(groupView); 649 builder.SetParent(this); 650 fLayout->AddItem(builder.Layout(), column, row, columnCount, rowCount); 651 return builder; 652 } 653 654 655 template<typename ParentBuilder> 656 typename Grid<ParentBuilder>::GroupBuilder 657 Grid<ParentBuilder>::AddGroup(BGroupLayout* groupLayout, int32 column, 658 int32 row, int32 columnCount, int32 rowCount) 659 { 660 GroupBuilder builder(groupLayout); 661 builder.SetParent(this); 662 fLayout->AddItem(builder.Layout(), column, row, columnCount, rowCount); 663 return builder; 664 } 665 666 667 template<typename ParentBuilder> 557 668 typename Grid<ParentBuilder>::GridBuilder 558 669 Grid<ParentBuilder>::AddGrid(float horizontalSpacing, float verticalSpacing, 559 670 int32 column, int32 row, int32 columnCount, int32 rowCount) 560 671 { 561 GridBuilder builder( horizontalSpacing, verticalSpacing);672 GridBuilder builder(new BGridLayout(horizontalSpacing, verticalSpacing)); 562 673 builder.SetParent(this); 674 fLayout->AddItem(builder.Layout(), column, row, columnCount, rowCount); 675 return builder; 676 } 677 678 679 template<typename ParentBuilder> 680 typename Grid<ParentBuilder>::GridBuilder 681 Grid<ParentBuilder>::AddGrid(BGridView* gridView, int32 column, int32 row, 682 int32 columnCount, int32 rowCount) 683 { 684 GridBuilder builder(gridView); 685 builder.SetParent(this); 563 686 fLayout->AddView(builder.View(), column, row, columnCount, rowCount); 564 687 return builder; 565 688 } … … 574 697 builder.SetParent(this); 575 698 fLayout->AddView(builder.View(), column, row, columnCount, rowCount); 576 699 return builder; 577 } 700 } 578 701 579 702 580 703 template<typename ParentBuilder> 704 typename Grid<ParentBuilder>::SplitBuilder 705 Grid<ParentBuilder>::AddSplit(BSplitView* splitView, int32 column, int32 row, 706 int32 columnCount, int32 rowCount) 707 { 708 SplitBuilder builder(splitView); 709 builder.SetParent(this); 710 fLayout->AddView(builder.View(), column, row, columnCount, rowCount); 711 return builder; 712 } 713 714 715 template<typename ParentBuilder> 581 716 typename Grid<ParentBuilder>::ThisBuilder& 582 717 Grid<ParentBuilder>::SetColumnWeight(int32 column, float weight) 583 718 { … … 612 747 } 613 748 614 749 615 template<typename ParentBuilder>616 Grid<ParentBuilder>::operator BView*()617 {618 return fLayout->View();619 }620 621 622 750 // #pragma mark - Split 623 751 624 752 … … 648 776 649 777 template<typename ParentBuilder> 650 778 typename Split<ParentBuilder>::ThisBuilder& 651 Split<ParentBuilder>::GetView(B SplitView** _view)779 Split<ParentBuilder>::GetView(BView** _view) 652 780 { 653 781 *_view = fView; 654 782 return *this; … … 657 785 658 786 template<typename ParentBuilder> 659 787 typename Split<ParentBuilder>::ThisBuilder& 788 Split<ParentBuilder>::GetSplitView(BSplitView** _view) 789 { 790 *_view = fView; 791 return *this; 792 } 793 794 795 template<typename ParentBuilder> 796 typename Split<ParentBuilder>::ThisBuilder& 660 797 Split<ParentBuilder>::Add(BView* view) 661 798 { 662 799 fView->AddChild(view); … … 696 833 Split<ParentBuilder>::AddGroup(enum orientation orientation, float spacing, 697 834 float weight) 698 835 { 699 GroupBuilder builder( orientation, spacing);836 GroupBuilder builder(new BGroupLayout(orientation, spacing)); 700 837 builder.SetParent(this); 701 fView->AddChild(builder. View(), weight);838 fView->AddChild(builder.Layout(), weight); 702 839 return builder; 703 840 } 704 841 705 842 706 843 template<typename ParentBuilder> 844 typename Split<ParentBuilder>::GroupBuilder 845 Split<ParentBuilder>::AddGroup(BGroupView* groupView, float weight) 846 { 847 GroupBuilder builder(groupView); 848 builder.SetParent(this); 849 fView->AddChild(builder.Layout(), weight); 850 return builder; 851 } 852 853 854 template<typename ParentBuilder> 855 typename Split<ParentBuilder>::GroupBuilder 856 Split<ParentBuilder>::AddGroup(BGroupLayout* groupLayout, float weight) 857 { 858 GroupBuilder builder(groupLayout); 859 builder.SetParent(this); 860 fView->AddChild(builder.Layout(), weight); 861 return builder; 862 } 863 864 865 template<typename ParentBuilder> 707 866 typename Split<ParentBuilder>::GridBuilder 708 867 Split<ParentBuilder>::AddGrid(float horizontalSpacing, float verticalSpacing, 709 868 float weight) 710 869 { 711 GridBuilder builder( horizontalSpacing, verticalSpacing);870 GridBuilder builder(new BGridLayout(horizontalSpacing, verticalSpacing)); 712 871 builder.SetParent(this); 713 fView->AddChild(builder. View(), weight);872 fView->AddChild(builder.Layout(), weight); 714 873 return builder; 715 874 } 716 875 717 876 718 877 template<typename ParentBuilder> 878 typename Split<ParentBuilder>::GridBuilder 879 Split<ParentBuilder>::AddGrid(BGridView* gridView, float weight) 880 { 881 GridBuilder builder(gridView); 882 builder.SetParent(this); 883 fView->AddChild(builder.Layout(), weight); 884 return builder; 885 } 886 887 888 template<typename ParentBuilder> 889 typename Split<ParentBuilder>::GridBuilder 890 Split<ParentBuilder>::AddGrid(BGridLayout* layout, float weight) 891 { 892 GridBuilder builder(layout); 893 builder.SetParent(this); 894 fView->AddChild(builder.Layout(), weight); 895 return builder; 896 } 897 898 899 template<typename ParentBuilder> 719 900 typename Split<ParentBuilder>::SplitBuilder 720 901 Split<ParentBuilder>::AddSplit(enum orientation orientation, float spacing, 721 902 float weight) -
headers/os/interface/GridLayoutBuilder.h
16 16 BGridLayoutBuilder(BGridView* view); 17 17 18 18 BGridLayout* GridLayout() const; 19 BView* View() const;20 19 BGridLayoutBuilder& GetGridLayout(BGridLayout** _layout); 21 BGridLayoutBuilder& GetView(BView** _view); 20 BView* View() const; 21 BGridLayoutBuilder& GetView(BView** _view); 22 22 23 23 BGridLayoutBuilder& Add(BView* view, int32 column, int32 row, 24 24 int32 columnCount = 1, int32 rowCount = 1); … … 32 32 float bottom); 33 33 34 34 operator BGridLayout*(); 35 operator BView*();36 35 37 36 private: 38 37 BGridLayout* fLayout; -
headers/os/interface/GroupLayoutBuilder.h
1 1 /* 2 * Copyright 2006 , Haiku, Inc. All rights reserved.2 * Copyright 2006-2010, Haiku, Inc. All rights reserved. 3 3 * Distributed under the terms of the MIT License. 4 4 */ 5 5 #ifndef _GROUP_LAYOUT_BUILDER_H … … 39 39 float bottom); 40 40 41 41 operator BGroupLayout*(); 42 operator BView*();43 42 44 43 private: 45 44 bool _PushLayout(BGroupLayout* layout); -
headers/os/interface/CardLayout.h
5 5 #ifndef _CARD_LAYOUT_H 6 6 #define _CARD_LAYOUT_H 7 7 8 #include < Layout.h>8 #include <AbstractLayout.h> 9 9 10 10 11 class BCardLayout : public B Layout {11 class BCardLayout : public BAbstractLayout { 12 12 public: 13 13 BCardLayout(); 14 14 BCardLayout(BMessage* from); … … 19 19 void SetVisibleItem(int32 index); 20 20 void SetVisibleItem(BLayoutItem* item); 21 21 22 virtual BSize MinSize();23 virtual BSize MaxSize();24 virtual BSize PreferredSize();25 virtual BAlignment Alignment();22 virtual BSize BaseMinSize(); 23 virtual BSize BaseMaxSize(); 24 virtual BSize BasePreferredSize(); 25 virtual BAlignment BaseAlignment(); 26 26 27 27 virtual bool HasHeightForWidth(); 28 28 virtual void GetHeightForWidth(float width, float* min, 29 29 float* max, float* preferred); 30 30 31 virtual void InvalidateLayout(); 32 virtual void LayoutView(); 31 virtual void InvalidateLayout(bool children = false); 33 32 34 33 virtual status_t Archive(BMessage* into, bool deep = true) const; 35 34 virtual status_t AllUnarchived(const BMessage* from); 36 35 static BArchivable* Instantiate(BMessage* from); 37 36 38 37 protected: 38 virtual void DerivedLayoutItems(); 39 39 virtual bool ItemAdded(BLayoutItem* item, int32 atIndex); 40 40 virtual void ItemRemoved(BLayoutItem* item, int32 fromIndex); 41 41 -
headers/os/interface/Window.h
103 103 void Close() { Quit(); } 104 104 105 105 void AddChild(BView* child, BView* before = NULL); 106 void AddChild(BLayoutItem* child); 106 107 bool RemoveChild(BView* child); 107 108 int32 CountChildren() const; 108 109 BView* ChildAt(int32 index) const; -
headers/os/interface/View.h
562 562 void Layout(bool force); 563 563 void Relayout(); 564 564 565 class Private; 566 565 567 protected: 566 568 virtual void DoLayout(); 567 569 … … 580 582 581 583 private: 582 584 void _Layout(bool force, BLayoutContext* context); 585 void _LayoutLeft(BLayout* deleted); 586 void _InvalidateParentLayout(); 583 587 584 588 private: 585 589 // FBC padding and forbidden methods … … 595 599 private: 596 600 struct LayoutData; 597 601 602 friend class Private; 598 603 friend class BBitmap; 599 604 friend class BLayout; 600 605 friend class BPrintJob; -
headers/os/interface/LayoutItem.h
16 16 class BView; 17 17 18 18 19 class BLayoutItem : public BArchivable {19 class BLayoutItem : public BArchivable { 20 20 public: 21 21 BLayoutItem(); 22 22 BLayoutItem(BMessage* from); … … 46 46 47 47 virtual BView* View(); 48 48 49 virtual void InvalidateLayout(); 49 virtual void InvalidateLayout(bool children = false); 50 virtual void Relayout(bool immediate = false); 50 51 51 52 void* LayoutData() const; 52 53 void SetLayoutData(void* data); … … 57 58 virtual status_t AllArchived(BMessage* into) const; 58 59 virtual status_t AllUnarchived(const BMessage* from); 59 60 61 protected: 62 63 void SetLayout(BLayout* layout); 64 65 // hook methods 66 virtual void AttachedToLayout(); 67 virtual void DetachedFromLayout(BLayout* layout); 68 69 virtual void AncestorVisibilityChanged(bool shown); 70 60 71 private: 61 72 friend class BLayout; 62 73 63 void SetLayout(BLayout* layout);64 65 74 BLayout* fLayout; 66 75 void* fLayoutData; 67 76 }; -
headers/os/interface/AbstractLayout.h
1 /* 2 * Copyright 2010, Haiku, Inc. All rights reserved. 3 * Distributed under the terms of the MIT License. 4 */ 5 #ifndef _ABSTRACT_LAYOUT_H 6 #define _ABSTRACT_LAYOUT_H 7 8 #include <Alignment.h> 9 #include <Layout.h> 10 #include <Size.h> 11 12 class BAbstractLayout : public BLayout { 13 public: 14 BAbstractLayout(); 15 BAbstractLayout(BMessage* from); 16 virtual ~BAbstractLayout(); 17 18 virtual BSize MinSize(); 19 virtual BSize MaxSize(); 20 virtual BSize PreferredSize(); 21 virtual BAlignment Alignment(); 22 23 virtual void SetExplicitMinSize(BSize size); 24 virtual void SetExplicitMaxSize(BSize size); 25 virtual void SetExplicitPreferredSize(BSize size); 26 virtual void SetExplicitAlignment(BAlignment alignment); 27 28 virtual BSize BaseMinSize(); 29 virtual BSize BaseMaxSize(); 30 virtual BSize BasePreferredSize(); 31 virtual BAlignment BaseAlignment(); 32 33 virtual BRect Frame(); 34 virtual void SetFrame(BRect frame); 35 36 virtual bool IsVisible(); 37 virtual void SetVisible(bool visible); 38 39 virtual status_t Archive(BMessage* into, bool deep = true) const; 40 virtual status_t AllUnarchived(const BMessage* from); 41 42 protected: 43 virtual void OwnerChanged(BView* was); 44 virtual void AncestorVisibilityChanged(bool shown); 45 46 private: 47 struct Proxy; 48 struct ViewProxy; 49 struct DataProxy; 50 51 Proxy* fExplicitData; 52 }; 53 54 #endif // _ABSTRACT_LAYOUT_ITEM_H -
headers/libs/alm/BALMLayout.h
7 7 #ifndef BALM_LAYOUT_H 8 8 #define BALM_LAYOUT_H 9 9 10 #include <AbstractLayout.h> 10 11 #include <File.h> 11 #include <Layout.h>12 12 #include <List.h> 13 13 #include <Size.h> 14 14 #include <SupportDefs.h> … … 29 29 /** 30 30 * A GUI layout engine using the ALM. 31 31 */ 32 class BALMLayout : public B Layout, public LinearSpec {32 class BALMLayout : public BAbstractLayout, public LinearSpec { 33 33 34 34 public: 35 35 BALMLayout(); … … 70 70 bool RemoveItem(BLayoutItem* item); 71 71 BLayoutItem* RemoveItem(int32 index); 72 72 73 BSize MinSize();74 BSize MaxSize();75 BSize PreferredSize();76 BAlignment Alignment();73 BSize BaseMinSize(); 74 BSize BaseMaxSize(); 75 BSize BasePreferredSize(); 76 BAlignment BaseAlignment(); 77 77 bool HasHeightForWidth(); 78 78 void GetHeightForWidth(float width, float* min, 79 79 float* max, float* preferred); 80 void InvalidateLayout( );81 v oid LayoutView();80 void InvalidateLayout(bool children = false); 81 virtual void DerivedLayoutItems(); 82 82 83 83 char* PerformancePath() const; 84 84 void SetPerformancePath(char* path); -
headers/private/interface/ViewPrivate.h
16 16 #include <Rect.h> 17 17 #include <Region.h> 18 18 #include <ServerProtocolStructs.h> 19 #include <View.h> 19 20 20 21 const static uint32 kDeleteReplicant = 'JAHA'; 21 22 … … 48 49 }; 49 50 50 51 52 class BView::Private { 53 public: 54 Private(BView* view) 55 : 56 fView(view) 57 { 58 } 59 60 int16 ShowLevel() 61 { 62 return fView->fShowLevel; 63 } 64 65 bool MinMaxValid(); 66 67 BView* fView; 68 }; 69 70 51 71 namespace BPrivate { 52 72 53 73 class PortLink;