Ticket #5525: cardLayout.patch
File cardLayout.patch, 4.4 KB (added by , 14 years ago) |
---|
-
src/kits/interface/CardLayout.cpp
6 6 #include <CardLayout.h> 7 7 8 8 #include <LayoutItem.h> 9 #include <Message.h> 9 10 #include <View.h> 10 11 11 // constructor 12 13 namespace { 14 const char* kVisibleItemField = "BCardLayout:visibleItem"; 15 } 16 17 12 18 BCardLayout::BCardLayout() 13 : BLayout(), 14 fMin(0, 0), 15 fMax(B_SIZE_UNLIMITED, B_SIZE_UNLIMITED), 16 fPreferred(0, 0), 17 fVisibleItem(NULL), 18 fMinMaxValid(false) 19 : 20 BLayout(), 21 fMin(0, 0), 22 fMax(B_SIZE_UNLIMITED, B_SIZE_UNLIMITED), 23 fPreferred(0, 0), 24 fVisibleItem(NULL), 25 fMinMaxValid(false) 19 26 { 20 27 } 21 28 22 // destructor 29 30 BCardLayout::BCardLayout(BMessage* from) 31 : 32 BLayout(BUnarchiver::PrepareArchive(from)), 33 fMin(0, 0), 34 fMax(B_SIZE_UNLIMITED, B_SIZE_UNLIMITED), 35 fPreferred(0, 0), 36 fVisibleItem(NULL), 37 fMinMaxValid(false) 38 { 39 BUnarchiver(from).Finish(); 40 } 41 42 23 43 BCardLayout::~BCardLayout() 24 44 { 25 45 } 26 46 27 // VisibleItem 47 28 48 BLayoutItem* 29 49 BCardLayout::VisibleItem() const 30 50 { 31 51 return fVisibleItem; 32 52 } 33 53 34 // VisibleIndex 54 35 55 int32 36 56 BCardLayout::VisibleIndex() const 37 57 { 38 58 return IndexOfItem(fVisibleItem); 39 59 } 40 60 41 // SetVisibleItem 61 42 62 void 43 63 BCardLayout::SetVisibleItem(int32 index) 44 64 { 45 65 SetVisibleItem(ItemAt(index)); 46 66 } 47 67 48 // SetVisibleItem 68 49 69 void 50 70 BCardLayout::SetVisibleItem(BLayoutItem* item) 51 71 { … … 67 87 } 68 88 } 69 89 70 // MinSize 90 71 91 BSize 72 92 BCardLayout::MinSize() 73 93 { … … 75 95 return fMin; 76 96 } 77 97 78 // MaxSize 98 79 99 BSize 80 100 BCardLayout::MaxSize() 81 101 { … … 83 103 return fMax; 84 104 } 85 105 86 // PreferredSize 106 87 107 BSize 88 108 BCardLayout::PreferredSize() 89 109 { … … 91 111 return fPreferred; 92 112 } 93 113 94 // Alignment 114 95 115 BAlignment 96 116 BCardLayout::Alignment() 97 117 { 98 118 return BAlignment(B_ALIGN_USE_FULL_WIDTH, B_ALIGN_USE_FULL_HEIGHT); 99 119 } 100 120 101 // HasHeightForWidth 121 102 122 bool 103 123 BCardLayout::HasHeightForWidth() 104 124 { … … 111 131 return false; 112 132 } 113 133 114 // GetHeightForWidth 134 115 135 void 116 136 BCardLayout::GetHeightForWidth(float width, float* min, float* max, 117 137 float* preferred) … … 152 172 *preferred = preferredHeight; 153 173 } 154 174 155 // InvalidateLayout 175 156 176 void 157 177 BCardLayout::InvalidateLayout() 158 178 { … … 161 181 fMinMaxValid = false; 162 182 } 163 183 164 // LayoutView 184 165 185 void 166 186 BCardLayout::LayoutView() 167 187 { … … 175 195 fVisibleItem->AlignInFrame(BRect(0, 0, size.width, size.height)); 176 196 } 177 197 178 // ItemAdded 198 199 status_t 200 BCardLayout::Archive(BMessage* into, bool deep) const 201 { 202 BArchiver archiver(into); 203 status_t err = BLayout::Archive(into, deep); 204 205 if (err == B_OK && deep) 206 err = into->AddInt32(kVisibleItemField, IndexOfItem(fVisibleItem)); 207 208 return archiver.Finish(err); 209 } 210 211 212 status_t 213 BCardLayout::AllUnarchived(const BMessage* from) 214 { 215 status_t err = BLayout::AllUnarchived(from); 216 if (err != B_OK) 217 return err; 218 219 int32 visibleIndex; 220 err = from->FindInt32(kVisibleItemField, &visibleIndex); 221 if (err == B_OK) 222 SetVisibleItem(visibleIndex); 223 224 return err; 225 } 226 227 228 BArchivable* 229 BCardLayout::Instantiate(BMessage* from) 230 { 231 if (validate_instantiation(from, "BCardLayout")) 232 return new BCardLayout(from); 233 return NULL; 234 } 235 236 179 237 void 180 238 BCardLayout::ItemAdded(BLayoutItem* item) 181 239 { 182 240 item->SetVisible(false); 183 241 } 184 242 185 // ItemRemoved 243 186 244 void 187 245 BCardLayout::ItemRemoved(BLayoutItem* item) 188 246 { … … 192 250 } 193 251 } 194 252 195 // _ValidateMinMax 253 196 254 void 197 255 BCardLayout::_ValidateMinMax() 198 256 { -
headers/os/interface/CardLayout.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 _CARD_LAYOUT_H … … 11 11 class BCardLayout : public BLayout { 12 12 public: 13 13 BCardLayout(); 14 BCardLayout(BMessage* from); 14 15 virtual ~BCardLayout(); 15 16 16 17 BLayoutItem* VisibleItem() const; … … 30 31 virtual void InvalidateLayout(); 31 32 virtual void LayoutView(); 32 33 34 virtual status_t Archive(BMessage* into, bool deep = true) const; 35 virtual status_t AllUnarchived(const BMessage* from); 36 static BArchivable* Instantiate(BMessage* from); 37 33 38 protected: 34 39 virtual void ItemAdded(BLayoutItem* item); 35 40 virtual void ItemRemoved(BLayoutItem* item);