Ticket #5525: abstractItem.patch
File abstractItem.patch, 4.0 KB (added by , 14 years ago) |
---|
-
headers/os/interface/AbstractLayoutItem.h
13 13 class BAbstractLayoutItem : public BLayoutItem { 14 14 public: 15 15 BAbstractLayoutItem(); 16 BAbstractLayoutItem(BMessage* from); 16 17 virtual ~BAbstractLayoutItem(); 17 18 18 19 virtual BSize MinSize(); … … 30 31 virtual BSize BasePreferredSize(); 31 32 virtual BAlignment BaseAlignment(); 32 33 34 virtual status_t Archive(BMessage* into, bool deep = true) const; 35 33 36 private: 34 37 BSize fMinSize; 35 38 BSize fMaxSize; -
src/kits/interface/AbstractLayoutItem.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 */ … … 6 7 #include <AbstractLayoutItem.h> 7 8 8 9 #include <LayoutUtils.h> 10 #include <Message.h> 9 11 10 12 11 // constructor 13 namespace { 14 const char* kMinSizeField = "BAbstractLayoutItem:minSize"; 15 const char* kMaxSizeField = "BAbstractLayoutItem:maxSize"; 16 const char* kPreferredSizeField = "BAbstractLayoutItem:preferredSize"; 17 const char* kAlignmentField = "BAbstractLayoutItem:alignment"; 18 } 19 20 12 21 BAbstractLayoutItem::BAbstractLayoutItem() 13 : fMinSize(), 14 fMaxSize(), 15 fPreferredSize(), 16 fAlignment() 22 : 23 fMinSize(), 24 fMaxSize(), 25 fPreferredSize(), 26 fAlignment() 17 27 { 18 28 } 19 29 20 // destructor 30 31 BAbstractLayoutItem::BAbstractLayoutItem(BMessage* from) 32 : 33 BLayoutItem(from), 34 fMinSize(), 35 fMaxSize(), 36 fPreferredSize(), 37 fAlignment() 38 { 39 from->FindSize(kMinSizeField, &fMinSize); 40 from->FindSize(kMaxSizeField, &fMaxSize); 41 from->FindSize(kPreferredSizeField, &fPreferredSize); 42 from->FindAlignment(kAlignmentField, &fAlignment); 43 } 44 21 45 BAbstractLayoutItem::~BAbstractLayoutItem() 22 46 { 23 47 } 24 48 25 // MinSize26 49 BSize 27 50 BAbstractLayoutItem::MinSize() 28 51 { 29 52 return BLayoutUtils::ComposeSize(fMinSize, BaseMinSize()); 30 53 } 31 54 32 // MaxSize33 55 BSize 34 56 BAbstractLayoutItem::MaxSize() 35 57 { 36 58 return BLayoutUtils::ComposeSize(fMaxSize, BaseMaxSize()); 37 59 } 38 60 39 // PreferredSize40 61 BSize 41 62 BAbstractLayoutItem::PreferredSize() 42 63 { 43 64 return BLayoutUtils::ComposeSize(fMaxSize, BasePreferredSize()); 44 65 } 45 66 46 // Alignment47 67 BAlignment 48 68 BAbstractLayoutItem::Alignment() 49 69 { 50 70 return BLayoutUtils::ComposeAlignment(fAlignment, BaseAlignment()); 51 71 } 52 72 53 // SetExplicitMinSize54 73 void 55 74 BAbstractLayoutItem::SetExplicitMinSize(BSize size) 56 75 { 57 76 fMinSize = size; 58 77 } 59 78 60 // SetExplicitMaxSize61 79 void 62 80 BAbstractLayoutItem::SetExplicitMaxSize(BSize size) 63 81 { 64 82 fMaxSize = size; 65 83 } 66 84 67 // SetExplicitPreferredSize68 85 void 69 86 BAbstractLayoutItem::SetExplicitPreferredSize(BSize size) 70 87 { 71 88 fPreferredSize = size; 72 89 } 73 90 74 // SetExplicitAlignment75 91 void 76 92 BAbstractLayoutItem::SetExplicitAlignment(BAlignment alignment) 77 93 { 78 94 fAlignment = alignment; 79 95 } 80 96 81 // BaseMinSize82 97 BSize 83 98 BAbstractLayoutItem::BaseMinSize() 84 99 { 85 100 return BSize(0, 0); 86 101 } 87 102 88 // BaseMaxSize89 103 BSize 90 104 BAbstractLayoutItem::BaseMaxSize() 91 105 { 92 106 return BSize(B_SIZE_UNLIMITED, B_SIZE_UNLIMITED); 93 107 } 94 108 95 // BasePreferredSize96 109 BSize 97 110 BAbstractLayoutItem::BasePreferredSize() 98 111 { 99 112 return BSize(0, 0); 100 113 } 101 114 102 // BaseAlignment103 115 BAlignment 104 116 BAbstractLayoutItem::BaseAlignment() 105 117 { 106 118 return BAlignment(B_ALIGN_HORIZONTAL_CENTER, B_ALIGN_VERTICAL_CENTER); 107 119 } 120 121 122 status_t 123 BAbstractLayoutItem::Archive(BMessage* into, bool deep) const 124 { 125 BArchiver archiver(into); 126 status_t err = BLayoutItem::Archive(into, deep); 127 128 if (err == B_OK) 129 err = into->AddSize(kMinSizeField, fMinSize); 130 131 if (err == B_OK) 132 err = into->AddSize(kMaxSizeField, fMaxSize); 133 134 if (err == B_OK) 135 err = into->AddSize(kPreferredSizeField, fPreferredSize); 136 137 if (err == B_OK) 138 err = into->AddAlignment(kAlignmentField, fAlignment); 139 140 return archiver.Finish(err); 141 } 142