Ticket #5525: spaceLayoutItem.patch
File spaceLayoutItem.patch, 5.1 KB (added by , 14 years ago) |
---|
-
headers/os/interface/SpaceLayoutItem.h
12 12 public: 13 13 BSpaceLayoutItem(BSize minSize, BSize maxSize, 14 14 BSize preferredSize, BAlignment alignment); 15 BSpaceLayoutItem(BMessage* archive); 15 16 virtual ~BSpaceLayoutItem(); 16 17 17 18 static BSpaceLayoutItem* CreateGlue(); … … 34 35 virtual BRect Frame(); 35 36 virtual void SetFrame(BRect frame); 36 37 38 virtual status_t Archive(BMessage* into, bool deep = true) const; 39 static BArchivable* Instantiate(BMessage* from); 40 37 41 private: 38 42 BRect fFrame; 39 43 BSize fMinSize; -
src/kits/interface/SpaceLayoutItem.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 7 #include <new> 8 9 #include <Message.h> 6 10 #include <SpaceLayoutItem.h> 7 11 8 12 9 // constructor 13 namespace { 14 const char* kMinSizeField = "BSpaceLayoutItem:minsize"; 15 const char* kMaxSizeField = "BSpaceLayoutItem:maxsize"; 16 const char* kPreferredSizeField = "BSpaceLayoutItem:prefsize"; 17 const char* kAlignmentField = "BSpaceLayoutItem:alignment"; 18 const char* kFrameField = "BSpaceLayoutItem:frame"; 19 const char* kVisibleField = "BSpaceLayoutItem:visible"; 20 } 21 22 10 23 BSpaceLayoutItem::BSpaceLayoutItem(BSize minSize, BSize maxSize, 11 24 BSize preferredSize, BAlignment alignment) 12 : fFrame(), 13 fMinSize(minSize), 14 fMaxSize(maxSize), 15 fPreferredSize(preferredSize), 16 fAlignment(alignment), 17 fVisible(true) 25 : 26 fFrame(), 27 fMinSize(minSize), 28 fMaxSize(maxSize), 29 fPreferredSize(preferredSize), 30 fAlignment(alignment), 31 fVisible(true) 18 32 { 19 33 } 20 34 21 // destructor 35 36 BSpaceLayoutItem::BSpaceLayoutItem(BMessage* archive) 37 : 38 BLayoutItem(archive) 39 { 40 archive->FindSize(kMinSizeField, &fMinSize); 41 archive->FindSize(kMaxSizeField, &fMaxSize); 42 archive->FindSize(kPreferredSizeField, &fPreferredSize); 43 44 archive->FindAlignment(kAlignmentField, &fAlignment); 45 46 archive->FindRect(kFrameField, &fFrame); 47 archive->FindBool(kVisibleField, &fVisible); 48 } 49 50 22 51 BSpaceLayoutItem::~BSpaceLayoutItem() 23 52 { 24 53 } 25 54 26 // CreateGlue 55 27 56 BSpaceLayoutItem* 28 57 BSpaceLayoutItem::CreateGlue() { 29 58 return new BSpaceLayoutItem( … … 33 62 BAlignment(B_ALIGN_HORIZONTAL_CENTER, B_ALIGN_VERTICAL_CENTER)); 34 63 } 35 64 36 // CreateHorizontalStrut 65 37 66 BSpaceLayoutItem* 38 67 BSpaceLayoutItem::CreateHorizontalStrut(float width) { 39 68 return new BSpaceLayoutItem( … … 43 72 BAlignment(B_ALIGN_HORIZONTAL_CENTER, B_ALIGN_VERTICAL_CENTER)); 44 73 } 45 74 46 // CreateVerticalStrut 75 47 76 BSpaceLayoutItem* 48 77 BSpaceLayoutItem::CreateVerticalStrut(float height) { 49 78 return new BSpaceLayoutItem( … … 53 82 BAlignment(B_ALIGN_HORIZONTAL_CENTER, B_ALIGN_VERTICAL_CENTER)); 54 83 } 55 84 56 // MinSize 85 57 86 BSize 58 87 BSpaceLayoutItem::MinSize() 59 88 { 60 89 return fMinSize; 61 90 } 62 91 63 // MaxSize 92 64 93 BSize 65 94 BSpaceLayoutItem::MaxSize() 66 95 { 67 96 return fMaxSize; 68 97 } 69 98 70 // PreferredSize 99 71 100 BSize 72 101 BSpaceLayoutItem::PreferredSize() 73 102 { 74 103 return fPreferredSize; 75 104 } 76 105 77 // Alignment 106 78 107 BAlignment 79 108 BSpaceLayoutItem::Alignment() 80 109 { 81 110 return fAlignment; 82 111 } 83 112 84 // SetExplicitMinSize 113 85 114 void 86 115 BSpaceLayoutItem::SetExplicitMinSize(BSize size) 87 116 { … … 93 122 InvalidateLayout(); 94 123 } 95 124 96 // SetExplicitMaxSize 125 97 126 void 98 127 BSpaceLayoutItem::SetExplicitMaxSize(BSize size) 99 128 { … … 105 134 InvalidateLayout(); 106 135 } 107 136 108 // SetExplicitPreferredSize 137 109 138 void 110 139 BSpaceLayoutItem::SetExplicitPreferredSize(BSize size) 111 140 { … … 117 146 InvalidateLayout(); 118 147 } 119 148 120 // SetExplicitAlignment 149 121 150 void 122 151 BSpaceLayoutItem::SetExplicitAlignment(BAlignment alignment) 123 152 { … … 129 158 InvalidateLayout(); 130 159 } 131 160 132 // IsVisible 161 133 162 bool 134 163 BSpaceLayoutItem::IsVisible() 135 164 { 136 165 return fVisible; 137 166 } 138 167 139 // SetVisible 168 140 169 void 141 170 BSpaceLayoutItem::SetVisible(bool visible) 142 171 { 143 172 fVisible = visible; 144 173 } 145 174 146 // Frame 175 147 176 BRect 148 177 BSpaceLayoutItem::Frame() 149 178 { 150 179 return fFrame; 151 180 } 152 181 153 // SetFrame 182 154 183 void 155 BSpaceLayoutItem::SetFrame(BRect frame) 156 { 184 BSpaceLayoutItem::SetFrame(BRect frame) { 157 185 fFrame = frame; 158 186 } 187 188 189 status_t 190 BSpaceLayoutItem::Archive(BMessage* into, bool deep) const 191 { 192 status_t err = BLayoutItem::Archive(into, deep); 193 194 if (err == B_OK) 195 err = into->AddRect(kFrameField, fFrame); 196 197 if (err == B_OK) 198 err = into->AddSize(kMinSizeField, fMinSize); 199 200 if (err == B_OK) 201 err = into->AddSize(kMaxSizeField, fMaxSize); 202 203 if (err == B_OK) 204 err = into->AddSize(kPreferredSizeField, fPreferredSize); 205 206 if (err == B_OK) 207 err = into->AddAlignment(kAlignmentField, fAlignment); 208 209 if (err == B_OK) 210 err =into->AddBool(kVisibleField, fVisible); 211 212 return err; 213 } 214 215 216 217 BArchivable* 218 BSpaceLayoutItem::Instantiate(BMessage* from) 219 { 220 if (validate_instantiation(from, "BSpaceLayoutItem")) 221 return new(std::nothrow) BSpaceLayoutItem(from); 222 return NULL; 223 } 224