Ticket #3161: tabview_layouted.diff

File tabview_layouted.diff, 5.3 KB (added by aljen, 15 years ago)
  • headers/os/interface/TabView.h

     
    6060
    6161        bool            IsSelected() const;
    6262virtual void            Select(BView *owner);
     63virtual void            Deselect(bool layouted);
    6364virtual void            Deselect();
    6465
    6566virtual void            SetEnabled(bool enabled);
     
    106107class BTabView : public BView
    107108{
    108109public:
     110                        BTabView(const char *name,
     111                            button_width width = B_WIDTH_AS_USUAL,
     112                            uint32 flags = B_FULL_UPDATE_ON_RESIZE |
     113                                 B_WILL_DRAW | B_NAVIGABLE_JUMP |
     114                                 B_FRAME_EVENTS | B_NAVIGABLE);
    109115                        BTabView(BRect frame, const char *name,
    110116                            button_width width = B_WIDTH_AS_USUAL,
    111117                            uint32 resizingMode = B_FOLLOW_ALL,
    112118                            uint32 flags = B_FULL_UPDATE_ON_RESIZE |
    113                                 B_WILL_DRAW | B_NAVIGABLE_JUMP |
    114                                 B_FRAME_EVENTS | B_NAVIGABLE);
     119                                 B_WILL_DRAW | B_NAVIGABLE_JUMP |
     120                                 B_FRAME_EVENTS | B_NAVIGABLE);
    115121                        ~BTabView();
    116122
    117123                        BTabView(BMessage *archive);
     
    150156virtual void            SetFlags(uint32 flags);
    151157virtual void            SetResizingMode(uint32 mode);
    152158
    153 virtual void            GetPreferredSize(float *width, float *height);
    154 virtual void            ResizeToPreferred();
     159virtual void            ResizeToPreferred();
     160virtual void            GetPreferredSize(float* _width, float* _height);
    155161
     162virtual BSize           MinSize();
     163virtual BSize           MaxSize();
     164virtual BSize           PreferredSize();
     165
    156166virtual BHandler        *ResolveSpecifier(BMessage *message, int32 index,
    157167                            BMessage *specifier, int32 what, const char *property);
    158168virtual status_t        GetSupportedSuites(BMessage *message);
     
    174184        BView           *ViewForTab(int32 tabIndex) const;
    175185
    176186private:
    177         void            _InitObject();
     187        void            _InitObject(bool layouted = false);
    178188
    179189virtual void            _ReservedTabView1();
    180190virtual void            _ReservedTabView2();
  • src/kits/interface/TabView.cpp

     
    1010
    1111#include <string.h>
    1212
     13#include <CardLayout.h>
     14#include <LayoutUtils.h>
    1315#include <List.h>
    1416#include <Message.h>
    1517#include <PropertyInfo.h>
     
    131133    if (!owner || !View() || !owner->Window())
    132134        return;
    133135
    134     owner->AddChild(fView);
     136    if (!owner->GetLayout())
     137        owner->AddChild(fView);
    135138    //fView->Show();
    136139
    137140    fSelected = true;
     
    139142
    140143
    141144void
    142 BTab::Deselect()
    143 {
    144     if (View())
     145BTab::Deselect(bool layouted)
     146{   
     147    if (View() && !layouted) {
    145148        View()->RemoveSelf();
     149    }
    146150
    147151    fSelected = false;
    148152}
    149153
    150154
    151155void
     156BTab::Deselect()
     157{
     158    Deselect(false);
     159}
     160
     161
     162void
    152163BTab::SetEnabled(bool enabled)
    153164{
    154165    fEnabled = enabled;
     
    329340
    330341//  #pragma mark -
    331342
     343BTabView::BTabView(const char *name, button_width width, uint32 flags)
     344    : BView(name, flags)
     345{
     346    SetFont(be_bold_font);
     347   
     348    _InitObject(true);
     349   
     350    fTabWidthSetting = width;
     351}
    332352
     353
    333354BTabView::BTabView(BRect frame, const char *name, button_width width,
    334355    uint32 resizingMode, uint32 flags)
    335356    : BView(frame, name, resizingMode, flags)
     
    669690        index = Selection();
    670691
    671692    BTab *tab = TabAt(Selection());
     693   
     694    bool layouted = fContainerView->GetLayout() ? true : false;
     695   
    672696    if (tab)
    673         tab->Deselect();
     697        tab->Deselect(layouted);
    674698
    675699    tab = TabAt(index);
    676700    if (tab && ContainerView()) {
     
    678702            fTabOffset = 0.0f;
    679703        tab->Select(ContainerView());
    680704        fSelection = index;
     705       
     706        if (layouted) {
     707            BCardLayout* layout =
     708                dynamic_cast<BCardLayout*>(fContainerView->GetLayout());
     709            layout->SetVisibleItem(index);
     710        }
    681711    }
    682712
    683713    Invalidate();
     
    917947}
    918948
    919949
     950BSize
     951BTabView::MinSize()
     952{
     953    BSize size = fContainerView->MinSize();
     954    size.height += TabHeight() + 6.0f;
     955    size.width += 6.0f;
     956    return BLayoutUtils::ComposeSize(ExplicitMinSize(), size);
     957}
     958
     959
     960BSize
     961BTabView::MaxSize()
     962{
     963    BSize size = fContainerView->MaxSize();
     964    size.height += TabHeight() + 6.0f;
     965    size.width += 6.0f;
     966    return BLayoutUtils::ComposeSize(ExplicitMaxSize(), size);
     967}
     968
     969
     970BSize
     971BTabView::PreferredSize()
     972{
     973    BSize size = fContainerView->PreferredSize();
     974    size.height += TabHeight() + 6.0f;
     975    size.width += 6.0f;
     976    return BLayoutUtils::ComposeSize(ExplicitPreferredSize(), size);
     977}
     978
     979
    920980void
    921981BTabView::ResizeToPreferred()
    922982{
     
    9571017        tab = new BTab(target);
    9581018    else
    9591019        tab->SetView(target);
     1020   
     1021    if (fContainerView->GetLayout())
     1022        fContainerView->GetLayout()->AddView(CountTabs(), target);
    9601023
    9611024    fTabList->AddItem(tab);
    9621025}
     
    9721035    if (tab == NULL)
    9731036        return NULL;
    9741037
    975     tab->Deselect();
     1038    bool layouted = fContainerView->GetLayout() ? true : false;
     1039   
     1040    tab->Deselect(layouted);
    9761041
    9771042    if (index <= fSelection && fSelection != 0)
    9781043        fSelection--;
     
    9871052    else
    9881053        SetFocusTab(fFocus, true);
    9891054
     1055    if (layouted)
     1056        fContainerView->GetLayout()->RemoveItem(index);
     1057   
    9901058    return tab;
    9911059}
    9921060
     
    10621130
    10631131
    10641132void
    1065 BTabView::_InitObject()
     1133BTabView::_InitObject(bool layouted)
    10661134{
    10671135    fTabList = new BList;
    10681136
     
    10881156    fContainerView = new BView(bounds, "view container", B_FOLLOW_ALL,
    10891157        B_WILL_DRAW);
    10901158
     1159    if (layouted) {
     1160        BCardLayout* layout = new BCardLayout();
     1161        fContainerView->SetLayout(layout);
     1162    }
     1163   
    10911164    fContainerView->SetViewColor(color);
    10921165    fContainerView->SetLowColor(color);
    10931166