1 /* 2 * Copyright 2006, Ingo Weinhold <bonefish@cs.tu-berlin.de>. 3 * All rights reserved. Distributed under the terms of the MIT License. 4 */ 5 6 #include <LayoutItem.h> 7 8 #include <Layout.h> 9 #include <LayoutUtils.h> 10 11 12 // constructor 13 BLayoutItem::BLayoutItem() 14 : fLayout(NULL), 15 fLayoutData(NULL) 16 { 17 } 18 19 // destructor 20 BLayoutItem::~BLayoutItem() 21 { 22 } 23 24 // Layout 25 BLayout* 26 BLayoutItem::Layout() const 27 { 28 return fLayout; 29 } 30 31 // HasHeightForWidth 32 bool 33 BLayoutItem::HasHeightForWidth() 34 { 35 // no "height for width" by default 36 return false; 37 } 38 39 // GetHeightForWidth 40 void 41 BLayoutItem::GetHeightForWidth(float width, float* min, float* max, 42 float* preferred) 43 { 44 // no "height for width" by default 45 } 46 47 // View 48 BView* 49 BLayoutItem::View() 50 { 51 return NULL; 52 } 53 54 // InvalidateLayout 55 void 56 BLayoutItem::InvalidateLayout() 57 { 58 if (fLayout) 59 fLayout->InvalidateLayout(); 60 } 61 62 // LayoutData 63 void* 64 BLayoutItem::LayoutData() const 65 { 66 return fLayoutData; 67 } 68 69 // SetLayoutData 70 void 71 BLayoutItem::SetLayoutData(void* data) 72 { 73 fLayoutData = data; 74 } 75 76 // AlignInFrame 77 void 78 BLayoutItem::AlignInFrame(BRect frame) 79 { 80 BSize maxSize = MaxSize(); 81 BAlignment alignment = Alignment(); 82 83 if (HasHeightForWidth()) { 84 // The item has height for width, so we do the horizontal alignment 85 // ourselves and restrict the height max constraint respectively. 86 if (maxSize.width < frame.Width() 87 && alignment.horizontal != B_ALIGN_USE_FULL_WIDTH) { 88 frame.left += (int)((frame.Width() - maxSize.width) 89 * alignment.horizontal); 90 frame.right = frame.left + maxSize.width; 91 } 92 alignment.horizontal = B_ALIGN_USE_FULL_WIDTH; 93 94 float minHeight; 95 GetHeightForWidth(frame.Width(), &minHeight, NULL, NULL); 96 97 frame.bottom = frame.top + max_c(frame.Height(), minHeight); 98 maxSize.height = minHeight; 99 } 100 101 SetFrame(BLayoutUtils::AlignInFrame(frame, maxSize, alignment)); 102 } 103 104 // SetLayout 105 void 106 BLayoutItem::SetLayout(BLayout* layout) 107 { 108 fLayout = layout; 109 } 110