Ticket #5525: spaceLayoutItem.patch

File spaceLayoutItem.patch, 5.1 KB (added by yourpalal, 14 years ago)

implement archiving of BSpaceLayoutItem class

  • headers/os/interface/SpaceLayoutItem.h

     
    1212public:
    1313                                BSpaceLayoutItem(BSize minSize, BSize maxSize,
    1414                                    BSize preferredSize, BAlignment alignment);
     15                                BSpaceLayoutItem(BMessage* archive);
    1516    virtual                     ~BSpaceLayoutItem();
    1617
    1718    static  BSpaceLayoutItem*   CreateGlue();
     
    3435    virtual BRect               Frame();
    3536    virtual void                SetFrame(BRect frame);
    3637
     38    virtual status_t            Archive(BMessage* into, bool deep = true) const;
     39    static  BArchivable*        Instantiate(BMessage* from);
     40
    3741private:
    3842            BRect               fFrame;
    3943            BSize               fMinSize;
  • src/kits/interface/SpaceLayoutItem.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 */
    56
     7#include <new>
     8
     9#include <Message.h>
    610#include <SpaceLayoutItem.h>
    711
    812
    9 // constructor
     13namespace {
     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
    1023BSpaceLayoutItem::BSpaceLayoutItem(BSize minSize, BSize maxSize,
    1124    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)
    1832{
    1933}
    2034
    21 // destructor
     35
     36BSpaceLayoutItem::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
    2251BSpaceLayoutItem::~BSpaceLayoutItem()
    2352{
    2453}
    2554
    26 // CreateGlue
     55
    2756BSpaceLayoutItem*
    2857BSpaceLayoutItem::CreateGlue() {
    2958    return new BSpaceLayoutItem(
     
    3362        BAlignment(B_ALIGN_HORIZONTAL_CENTER, B_ALIGN_VERTICAL_CENTER));
    3463}
    3564
    36 // CreateHorizontalStrut
     65
    3766BSpaceLayoutItem*
    3867BSpaceLayoutItem::CreateHorizontalStrut(float width) {
    3968    return new BSpaceLayoutItem(
     
    4372        BAlignment(B_ALIGN_HORIZONTAL_CENTER, B_ALIGN_VERTICAL_CENTER));
    4473}
    4574
    46 // CreateVerticalStrut
     75
    4776BSpaceLayoutItem*
    4877BSpaceLayoutItem::CreateVerticalStrut(float height) {
    4978    return new BSpaceLayoutItem(
     
    5382        BAlignment(B_ALIGN_HORIZONTAL_CENTER, B_ALIGN_VERTICAL_CENTER));
    5483}
    5584
    56 // MinSize
     85
    5786BSize
    5887BSpaceLayoutItem::MinSize()
    5988{
    6089    return fMinSize;
    6190}
    6291
    63 // MaxSize
     92
    6493BSize
    6594BSpaceLayoutItem::MaxSize()
    6695{
    6796    return fMaxSize;
    6897}
    6998
    70 // PreferredSize
     99
    71100BSize
    72101BSpaceLayoutItem::PreferredSize()
    73102{
    74103    return fPreferredSize;
    75104}
    76105
    77 // Alignment
     106
    78107BAlignment
    79108BSpaceLayoutItem::Alignment()
    80109{
    81110    return fAlignment;
    82111}
    83112
    84 // SetExplicitMinSize
     113
    85114void
    86115BSpaceLayoutItem::SetExplicitMinSize(BSize size)
    87116{
     
    93122    InvalidateLayout();
    94123}
    95124
    96 // SetExplicitMaxSize
     125
    97126void
    98127BSpaceLayoutItem::SetExplicitMaxSize(BSize size)
    99128{
     
    105134    InvalidateLayout();
    106135}
    107136
    108 // SetExplicitPreferredSize
     137
    109138void
    110139BSpaceLayoutItem::SetExplicitPreferredSize(BSize size)
    111140{
     
    117146    InvalidateLayout();
    118147}
    119148
    120 // SetExplicitAlignment
     149
    121150void
    122151BSpaceLayoutItem::SetExplicitAlignment(BAlignment alignment)
    123152{
     
    129158    InvalidateLayout();
    130159}
    131160
    132 // IsVisible
     161
    133162bool
    134163BSpaceLayoutItem::IsVisible()
    135164{
    136165    return fVisible;
    137166}
    138167
    139 // SetVisible
     168
    140169void
    141170BSpaceLayoutItem::SetVisible(bool visible)
    142171{
    143172    fVisible = visible;
    144173}
    145174
    146 // Frame
     175
    147176BRect
    148177BSpaceLayoutItem::Frame()
    149178{
    150179    return fFrame;
    151180}
    152181
    153 // SetFrame
     182
    154183void
    155 BSpaceLayoutItem::SetFrame(BRect frame)
    156 {
     184BSpaceLayoutItem::SetFrame(BRect frame) {
    157185    fFrame = frame;
    158186}
     187
     188
     189status_t
     190BSpaceLayoutItem::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
     217BArchivable*
     218BSpaceLayoutItem::Instantiate(BMessage* from)
     219{
     220    if (validate_instantiation(from, "BSpaceLayoutItem"))
     221        return new(std::nothrow) BSpaceLayoutItem(from);
     222    return NULL;
     223}
     224