Ticket #5525: abstractItem.patch

File abstractItem.patch, 4.0 KB (added by yourpalal, 11 years ago)

implement archiving of BAbstractLayoutItem

  • headers/os/interface/AbstractLayoutItem.h

     
    1313class BAbstractLayoutItem : public BLayoutItem {
    1414public:
    1515                                BAbstractLayoutItem();
     16                                BAbstractLayoutItem(BMessage* from);
    1617    virtual                     ~BAbstractLayoutItem();
    1718
    1819    virtual BSize               MinSize();
     
    3031    virtual BSize               BasePreferredSize();
    3132    virtual BAlignment          BaseAlignment();
    3233
     34    virtual status_t            Archive(BMessage* into, bool deep = true) const;
     35
    3336private:
    3437            BSize               fMinSize;
    3538            BSize               fMaxSize;
  • src/kits/interface/AbstractLayoutItem.cpp

     
    11/*
     2 * Copyright 2010, Haiku, Inc.
    23 * Copyright 2006, Ingo Weinhold <bonefish@cs.tu-berlin.de>.
    34 * All rights reserved. Distributed under the terms of the MIT License.
    45 */
     
    67#include <AbstractLayoutItem.h>
    78
    89#include <LayoutUtils.h>
     10#include <Message.h>
    911
    1012
    11 // constructor
     13namespace {
     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
    1221BAbstractLayoutItem::BAbstractLayoutItem()
    13     : fMinSize(),
    14       fMaxSize(),
    15       fPreferredSize(),
    16       fAlignment()
     22    :
     23    fMinSize(),
     24    fMaxSize(),
     25    fPreferredSize(),
     26    fAlignment()
    1727{
    1828}
    1929
    20 // destructor
     30
     31BAbstractLayoutItem::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
    2145BAbstractLayoutItem::~BAbstractLayoutItem()
    2246{
    2347}
    2448
    25 // MinSize
    2649BSize
    2750BAbstractLayoutItem::MinSize()
    2851{
    2952    return BLayoutUtils::ComposeSize(fMinSize, BaseMinSize());
    3053}
    3154
    32 // MaxSize
    3355BSize
    3456BAbstractLayoutItem::MaxSize()
    3557{
    3658    return BLayoutUtils::ComposeSize(fMaxSize, BaseMaxSize());
    3759}
    3860
    39 // PreferredSize
    4061BSize
    4162BAbstractLayoutItem::PreferredSize()
    4263{
    4364    return BLayoutUtils::ComposeSize(fMaxSize, BasePreferredSize());
    4465}
    4566
    46 // Alignment
    4767BAlignment
    4868BAbstractLayoutItem::Alignment()
    4969{
    5070    return BLayoutUtils::ComposeAlignment(fAlignment, BaseAlignment());
    5171}
    5272
    53 // SetExplicitMinSize
    5473void
    5574BAbstractLayoutItem::SetExplicitMinSize(BSize size)
    5675{
    5776    fMinSize = size;
    5877}
    5978
    60 // SetExplicitMaxSize
    6179void
    6280BAbstractLayoutItem::SetExplicitMaxSize(BSize size)
    6381{
    6482    fMaxSize = size;
    6583}
    6684
    67 // SetExplicitPreferredSize
    6885void
    6986BAbstractLayoutItem::SetExplicitPreferredSize(BSize size)
    7087{
    7188    fPreferredSize = size;
    7289}
    7390
    74 // SetExplicitAlignment
    7591void
    7692BAbstractLayoutItem::SetExplicitAlignment(BAlignment alignment)
    7793{
    7894    fAlignment = alignment;
    7995}
    8096
    81 // BaseMinSize
    8297BSize
    8398BAbstractLayoutItem::BaseMinSize()
    8499{
    85100    return BSize(0, 0);
    86101}
    87102
    88 // BaseMaxSize
    89103BSize
    90104BAbstractLayoutItem::BaseMaxSize()
    91105{
    92106    return BSize(B_SIZE_UNLIMITED, B_SIZE_UNLIMITED);
    93107}
    94108
    95 // BasePreferredSize
    96109BSize
    97110BAbstractLayoutItem::BasePreferredSize()
    98111{
    99112    return BSize(0, 0);
    100113}
    101114
    102 // BaseAlignment
    103115BAlignment
    104116BAbstractLayoutItem::BaseAlignment()
    105117{
    106118    return BAlignment(B_ALIGN_HORIZONTAL_CENTER, B_ALIGN_VERTICAL_CENTER);
    107119}
     120
     121
     122status_t
     123BAbstractLayoutItem::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