Ticket #5525: viewLayoutItem.patch
File viewLayoutItem.patch, 4.5 KB (added by , 14 years ago) |
---|
-
src/kits/interface/ViewLayoutItem.cpp
1 1 /* 2 * Copyright 2010, Haiku, Inc. 2 3 * Copyright 2006, Ingo Weinhold <bonefish@cs.tu-berlin.de>. 3 4 * All rights reserved. Distributed under the terms of the MIT License. 4 5 */ 5 6 6 7 #include "ViewLayoutItem.h" 7 8 9 #include <Layout.h> 8 10 #include <View.h> 9 11 12 #include <new> 10 13 11 // constructor 14 namespace { 15 const char* kViewField = "ViewLayoutItem:view"; 16 } 17 18 12 19 BViewLayoutItem::BViewLayoutItem(BView* view) 13 : fView(view) 20 : 21 fView(view) 14 22 { 15 23 } 16 24 17 // destructor 25 26 BViewLayoutItem::BViewLayoutItem(BMessage* from) 27 : 28 BLayoutItem(BUnarchiver::PrepareArchive(from)), 29 fView(NULL) 30 { 31 BUnarchiver unarchiver(from); 32 unarchiver.Finish(unarchiver.FindObject<BView>(kViewField, 0, 33 BUnarchiver::B_DONT_ASSUME_OWNERSHIP, fView)); 34 } 35 36 18 37 BViewLayoutItem::~BViewLayoutItem() 19 38 { 20 39 } 21 40 22 // MinSize 41 23 42 BSize 24 43 BViewLayoutItem::MinSize() 25 44 { 26 45 return fView->MinSize(); 27 46 } 28 47 29 // MaxSize 48 30 49 BSize 31 50 BViewLayoutItem::MaxSize() 32 51 { 33 52 return fView->MaxSize(); 34 53 } 35 54 36 // PreferredSize 55 37 56 BSize 38 57 BViewLayoutItem::PreferredSize() 39 58 { 40 59 return fView->PreferredSize(); 41 60 } 42 61 43 // Alignment 62 44 63 BAlignment 45 64 BViewLayoutItem::Alignment() 46 65 { 47 66 return fView->LayoutAlignment(); 48 67 } 49 68 50 // SetExplicitMinSize 69 51 70 void 52 71 BViewLayoutItem::SetExplicitMinSize(BSize size) 53 72 { 54 73 fView->SetExplicitMinSize(size); 55 74 } 56 75 57 // SetExplicitMaxSize 76 58 77 void 59 78 BViewLayoutItem::SetExplicitMaxSize(BSize size) 60 79 { 61 80 fView->SetExplicitMaxSize(size); 62 81 } 63 82 64 // SetExplicitPreferredSize 83 65 84 void 66 85 BViewLayoutItem::SetExplicitPreferredSize(BSize size) 67 86 { 68 87 fView->SetExplicitPreferredSize(size); 69 88 } 70 89 71 // SetExplicitAlignment 90 72 91 void 73 92 BViewLayoutItem::SetExplicitAlignment(BAlignment alignment) 74 93 { 75 94 fView->SetExplicitAlignment(alignment); 76 95 } 77 96 78 // IsVisible 97 79 98 bool 80 99 BViewLayoutItem::IsVisible() 81 100 { 82 101 return !fView->IsHidden(fView); 83 102 } 84 103 85 // SetVisible 104 86 105 void 87 106 BViewLayoutItem::SetVisible(bool visible) 88 107 { … … 94 113 } 95 114 } 96 115 97 // Frame 116 98 117 BRect 99 118 BViewLayoutItem::Frame() 100 119 { 101 120 return fView->Frame(); 102 121 } 103 122 104 // SetFrame 123 105 124 void 106 125 BViewLayoutItem::SetFrame(BRect frame) 107 126 { … … 109 128 fView->ResizeTo(frame.Width(), frame.Height()); 110 129 } 111 130 112 // HasHeightForWidth 131 113 132 bool 114 133 BViewLayoutItem::HasHeightForWidth() 115 134 { 116 135 return fView->HasHeightForWidth(); 117 136 } 118 137 119 // GetHeightForWidth 138 120 139 void 121 140 BViewLayoutItem::GetHeightForWidth(float width, float* min, float* max, 122 141 float* preferred) … … 124 143 fView->GetHeightForWidth(width, min, max, preferred); 125 144 } 126 145 127 // View 146 128 147 BView* 129 148 BViewLayoutItem::View() 130 149 { 131 150 return fView; 132 151 } 133 152 134 // InvalidateLayout 153 135 154 void 136 155 BViewLayoutItem::InvalidateLayout() 137 156 { 138 157 fView->InvalidateLayout(); 139 158 } 159 160 161 status_t 162 BViewLayoutItem::Archive(BMessage* into, bool deep) const 163 { 164 BArchiver archiver(into); 165 status_t err = BLayoutItem::Archive(into, deep); 166 167 return archiver.Finish(err); 168 } 169 170 171 status_t 172 BViewLayoutItem::AllArchived(BMessage* into) const 173 { 174 BArchiver archiver(into); 175 status_t err = BLayoutItem::AllArchived(into); 176 177 if (err == B_OK) { 178 if (archiver.IsArchived(fView)) 179 err = archiver.AddArchivable(kViewField, fView); 180 else 181 err = B_NAME_NOT_FOUND; 182 } 183 184 return err; 185 } 186 187 188 status_t 189 BViewLayoutItem::AllUnarchived(const BMessage* from) 190 { 191 if (!fView) 192 return B_ERROR; 193 194 return BLayoutItem::AllUnarchived(from); 195 } 196 197 198 BArchivable* 199 BViewLayoutItem::Instantiate(BMessage* from) 200 { 201 if (validate_instantiation(from, "BViewLayoutItem")) 202 return new(std::nothrow) BViewLayoutItem(from); 203 return NULL; 204 } -
src/kits/interface/ViewLayoutItem.h
1 1 /* 2 * Copyright 2006 , Haiku Inc.2 * Copyright 2006-2010, Haiku Inc. 3 3 * Distributed under the terms of the MIT License. 4 4 */ 5 5 #ifndef _VIEW_LAYOUT_ITEM_H … … 11 11 class BViewLayoutItem : public BLayoutItem { 12 12 public: 13 13 BViewLayoutItem(BView* view); 14 BViewLayoutItem(BMessage* from); 14 15 virtual ~BViewLayoutItem(); 15 16 16 17 virtual BSize MinSize(); … … 37 38 38 39 virtual void InvalidateLayout(); 39 40 41 virtual status_t Archive(BMessage* into, bool deep = true) const; 42 virtual status_t AllArchived(BMessage* into) const; 43 virtual status_t AllUnarchived(const BMessage* from); 44 static BArchivable* Instantiate(BMessage* from); 45 40 46 private: 41 47 BView* fView; 42 48 };