Ticket #3161: tabview_layouted.2.diff

File tabview_layouted.2.diff, 5.0 KB (added by aljen, 16 months ago)
  • headers/os/interface/TabView.h

     
    106106class BTabView : public BView 
    107107{ 
    108108public: 
     109                        BTabView(const char *name, 
     110                            button_width width = B_WIDTH_AS_USUAL, 
     111                            uint32 flags = B_FULL_UPDATE_ON_RESIZE | 
     112                                 B_WILL_DRAW | B_NAVIGABLE_JUMP | 
     113                                 B_FRAME_EVENTS | B_NAVIGABLE); 
    109114                        BTabView(BRect frame, const char *name, 
    110115                            button_width width = B_WIDTH_AS_USUAL,  
    111116                            uint32 resizingMode = B_FOLLOW_ALL, 
    112117                            uint32 flags = B_FULL_UPDATE_ON_RESIZE | 
    113                                 B_WILL_DRAW | B_NAVIGABLE_JUMP | 
    114                                 B_FRAME_EVENTS | B_NAVIGABLE); 
     118                                 B_WILL_DRAW | B_NAVIGABLE_JUMP | 
     119                                 B_FRAME_EVENTS | B_NAVIGABLE); 
    115120                        ~BTabView(); 
    116121 
    117122                        BTabView(BMessage *archive); 
     
    150155virtual void            SetFlags(uint32 flags); 
    151156virtual void            SetResizingMode(uint32 mode); 
    152157 
    153 virtual void            GetPreferredSize(float *width, float *height); 
    154 virtual void            ResizeToPreferred(); 
     158virtual void            ResizeToPreferred(); 
     159virtual void            GetPreferredSize(float* _width, float* _height); 
    155160 
     161virtual BSize           MinSize(); 
     162virtual BSize           MaxSize(); 
     163virtual BSize           PreferredSize(); 
     164 
    156165virtual BHandler        *ResolveSpecifier(BMessage *message, int32 index, 
    157166                            BMessage *specifier, int32 what, const char *property); 
    158167virtual status_t        GetSupportedSuites(BMessage *message); 
     
    174183        BView           *ViewForTab(int32 tabIndex) const; 
    175184 
    176185private: 
    177         void            _InitObject(); 
     186        void            _InitObject(bool layouted = false); 
    178187 
    179188virtual void            _ReservedTabView1(); 
    180189virtual 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; 
     
    141144void 
    142145BTab::Deselect() 
    143146{ 
    144     if (View()) 
    145         View()->RemoveSelf(); 
    146  
     147    if (View()) { 
     148        bool removeView = false; 
     149        BView* container = View()->Parent(); 
     150        if (container) 
     151            removeView = 
     152                dynamic_cast<BCardLayout*>(container->GetLayout()) == NULL; 
     153        if (removeView) 
     154            View()->RemoveSelf(); 
     155    } 
     156     
    147157    fSelected = false; 
    148158} 
    149159 
     
    329339 
    330340//  #pragma mark - 
    331341 
     342BTabView::BTabView(const char *name, button_width width, uint32 flags) 
     343    : BView(name, flags) 
     344{ 
     345    SetFont(be_bold_font); 
     346     
     347    _InitObject(true); 
     348     
     349    fTabWidthSetting = width; 
     350} 
    332351 
     352 
    333353BTabView::BTabView(BRect frame, const char *name, button_width width,  
    334354    uint32 resizingMode, uint32 flags) 
    335355    : BView(frame, name, resizingMode, flags) 
     
    669689        index = Selection(); 
    670690 
    671691    BTab *tab = TabAt(Selection()); 
     692     
     693    bool layouted = fContainerView->GetLayout() ? true : false; 
     694     
    672695    if (tab) 
    673696        tab->Deselect(); 
    674697 
     
    678701            fTabOffset = 0.0f; 
    679702        tab->Select(ContainerView()); 
    680703        fSelection = index; 
     704         
     705        if (layouted) { 
     706            BCardLayout* layout = 
     707                dynamic_cast<BCardLayout*>(fContainerView->GetLayout()); 
     708            if (layout) 
     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 
     1038    bool layouted = fContainerView->GetLayout() ? true : false; 
     1039     
    9751040    tab->Deselect(); 
    9761041 
    9771042    if (index <= fSelection && fSelection != 0) 
     
    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        if (layout) 
     1162            fContainerView->SetLayout(layout); 
     1163    } 
     1164     
    10911165    fContainerView->SetViewColor(color); 
    10921166    fContainerView->SetLowColor(color); 
    10931167