Ticket #5525: splitView.patch

File splitView.patch, 2.6 KB (added by yourpalal, 11 years ago)

implement archiving of BSplitView class

  • headers/os/interface/SplitView.h

     
    11/*
    2  * Copyright 2006, Haiku, Inc. All rights reserved.
     2 * Copyright 2006-2010, Haiku, Inc. All rights reserved.
    33 * Distributed under the terms of the MIT License.
    44 */
    55#ifndef _SPLIT_VIEW_H
     
    1616                                    enum orientation orientation
    1717                                        = B_HORIZONTAL,
    1818                                    float spacing = 0.0f);
     19                                BSplitView(BMessage* from);
    1920    virtual                     ~BSplitView();
    2021
    2122            void                SetInsets(float left, float top, float right,
     
    5960    virtual void                SetLayout(BLayout* layout);
    6061                                    // overridden to avoid use
    6162
     63    virtual status_t            Archive(BMessage* into, bool deep = true) const;
     64    virtual status_t            AllArchived(BMessage* into) const;
     65    static  BArchivable*        Instantiate(BMessage* from);
     66
    6267protected:
    6368    virtual void                DrawSplitter(BRect frame,
    6469                                    const BRect& updateRect,
  • src/kits/interface/SplitView.cpp

     
    33 * All rights reserved. Distributed under the terms of the MIT License.
    44 */
    55
     6#include <Archivable.h>
    67#include <SplitView.h>
    78
    89#include <stdio.h>
     
    1213
    1314#include "SplitLayout.h"
    1415
     16namespace {
     17    const char* kSplitLayoutField = "BSplitView:layout";
     18}
    1519
     20
    1621BSplitView::BSplitView(enum orientation orientation, float spacing)
    1722    :
    1823    BView(NULL,
     
    2328}
    2429
    2530
     31BSplitView::BSplitView(BMessage* from)
     32    :
     33    BView(BUnarchiver::PrepareArchive(from)),
     34    fSplitLayout(NULL)
     35{
     36    BUnarchiver unarchiver(from);
     37    unarchiver.FindObject(kSplitLayoutField,
     38        BUnarchiver::B_DONT_ASSUME_OWNERSHIP, fSplitLayout);
     39}
     40
     41
    2642BSplitView::~BSplitView()
    2743{
    2844}
     
    216232}
    217233
    218234
     235status_t
     236BSplitView::Archive(BMessage* into, bool deep) const
     237{
     238    return BArchiver(into).Finish(BView::Archive(into, deep));
     239}
     240
     241
     242status_t
     243BSplitView::AllArchived(BMessage* into) const
     244{
     245    BArchiver archiver(into);
     246    status_t err = BView::AllArchived(into);
     247   
     248    if (err == B_OK && archiver.IsArchived(fSplitLayout))
     249        return archiver.AddArchivable(kSplitLayoutField, fSplitLayout);
     250
     251    return B_NAME_NOT_FOUND;
     252}
     253
     254
     255BArchivable*
     256BSplitView::Instantiate(BMessage* from)
     257{
     258    if (validate_instantiation(from, "BSplitView"))
     259        return new BSplitView(from);
     260    return NULL;
     261}
     262
     263
    219264void
    220265BSplitView::DrawSplitter(BRect frame, const BRect& updateRect,
    221266    enum orientation orientation, bool pressed)