diff --git a/src/helpers/gtab/GTab.h b/src/helpers/gtab/GTab.h index 4b193a12..0243fbfd 100644 --- a/src/helpers/gtab/GTab.h +++ b/src/helpers/gtab/GTab.h @@ -9,9 +9,7 @@ #include #include #include -#include #include -#include #include #include @@ -49,14 +47,13 @@ class GTabDropZone : Draggable { virtual bool DropZoneMouseMoved(BView* view, BPoint where, uint32 transit, const BMessage* dragMessage); - virtual bool DropZoneMessageReceived(BMessage* message); virtual void OnDropMessage(BMessage* message) = 0; - TabsContainer* Container() { return fTabsContainer; } + TabsContainer* Container() const { return fTabsContainer; } - void SetContainer(TabsContainer* container) { fTabsContainer = container; } + void SetContainer(TabsContainer* container) { fTabsContainer = container; } virtual void StopDragging(BView* view) { @@ -79,7 +76,8 @@ class GTabDropZone : Draggable { }; -class GTab : public BView , public GTabDropZone { + +class GTab : public BView, public GTabDropZone { public: GTab(const char* label); virtual ~GTab(); @@ -110,7 +108,7 @@ class GTab : public BView , public GTabDropZone { BLayoutItem* LayoutItem() const { return fLayoutItem; } void SetLayoutItem(BLayoutItem* layItem) { fLayoutItem = layItem; } - BString Label() { return fLabel; }; + BString Label() const { return fLabel; }; void SetLabel(const char* label) { fLabel.SetTo(label); } void OnDropMessage(BMessage* message) override; @@ -124,30 +122,29 @@ class GTab : public BView , public GTabDropZone { class GTabCloseButton : public GTab { public: - enum { kTVCloseTab = 'TVCt' }; - - GTabCloseButton(const char* label, const BHandler* handler); - - BSize MinSize() override; - BSize MaxSize() override; - void DrawContents(BView* owner, BRect frame, - const BRect& updateRect, bool isFront) override; - void MouseDown(BPoint where) override; - void MouseUp(BPoint where) override; - void MouseMoved(BPoint where, uint32 transit, - const BMessage* dragMessage) override; -private: - void DrawCloseButton(BView* owner, BRect butFrame, const BRect& updateRect, - bool isFront); + enum { kTVCloseTab = 'TVCt' }; - BRect RectCloseButton(); + GTabCloseButton(const char* label, const BHandler* handler); - void CloseButtonClicked(); + BSize MinSize() override; + BSize MaxSize() override; + void DrawContents(BView* owner, BRect frame, + const BRect& updateRect, bool isFront) override; + void MouseDown(BPoint where) override; + void MouseUp(BPoint where) override; + void MouseMoved(BPoint where, uint32 transit, + const BMessage* dragMessage) override; private: + void DrawCloseButton(BView* owner, BRect butFrame, const BRect& updateRect, + bool isFront); + + BRect RectCloseButton(); - bool fOverCloseRect; - bool fClicked; - const BHandler* fHandler; + void CloseButtonClicked(); +private: + bool fOverCloseRect; + bool fClicked; + const BHandler* fHandler; }; @@ -181,7 +178,9 @@ class TabButtonDropZone : public GTabButton, public GTabDropZone { public: TabButtonDropZone(BMessage* message, TabsContainer* container) - : GTabButton(" ", message), fRunner(nullptr) + : + GTabButton(" ", message), + fRunner(nullptr) { SetContainer(container); } @@ -201,18 +200,17 @@ class TabButtonDropZone : public GTabButton, public GTabDropZone { void MouseMoved(BPoint where, uint32 transit, const BMessage* dragMessage) override { - if (DropZoneMouseMoved(this, where, transit, dragMessage) == false) + if (!DropZoneMouseMoved(this, where, transit, dragMessage)) GTabButton::MouseMoved(where, transit, dragMessage); } void OnDropMessage(BMessage* message) override { - return; } void MessageReceived(BMessage* message) override { - switch(message->what) { + switch (message->what) { case kRunnerTick: if (fRunner != nullptr && IsEnabled()) { Invoke(); diff --git a/src/helpers/gtab/TabsContainer.cpp b/src/helpers/gtab/TabsContainer.cpp index 69bc1138..5398efc4 100644 --- a/src/helpers/gtab/TabsContainer.cpp +++ b/src/helpers/gtab/TabsContainer.cpp @@ -39,7 +39,7 @@ TabsContainer::AddTab(GTab* tab, int32 index) index = CountTabs(); BLayoutItem* item = GroupLayout()->AddView(index, tab); - tab->SetLayoutItem (item); + tab->SetLayoutItem(item); tab->SetContainer(this); @@ -59,7 +59,7 @@ TabsContainer::CountTabs() const GTab* -TabsContainer::TabAt(int32 index) +TabsContainer::TabAt(int32 index) const { if (index < 0 || index >= CountTabs()) return nullptr; @@ -69,7 +69,7 @@ TabsContainer::TabAt(int32 index) int32 -TabsContainer::IndexOfTab(GTab* tab) +TabsContainer::IndexOfTab(GTab* tab) const { if (fSelectedTab == nullptr) return -1; @@ -96,7 +96,7 @@ TabsContainer::RemoveTab(GTab* tab) delete tab->LayoutItem(); tab->SetLayoutItem(nullptr); - //fix tab visibility + // fix tab visibility // TODO: this could be further improved by shifting according to the free // available space. int32 shift = 0; @@ -129,7 +129,7 @@ TabsContainer::SelectTab(GTab* tab, bool invoke) fSelectedTab->SetIsFront(true); int32 index = IndexOfTab(fSelectedTab); - if (invoke && Message() && Target()) { + if (invoke && Message() != nullptr && Target() != nullptr) { BMessage msg = *Message(); msg.AddPointer("tab", fSelectedTab); msg.AddInt32("index", IndexOfTab(fSelectedTab)); @@ -141,10 +141,10 @@ TabsContainer::SelectTab(GTab* tab, bool invoke) } else { // let's ensure at least the tab's "middle point" // is visible. - float middle = fSelectedTab->Frame().right - (fSelectedTab->Frame().Width()/2.0f); + float middle = fSelectedTab->Frame().right - (fSelectedTab->Frame().Width() / 2.0f); if (middle > Bounds().right) { int32 shift = 0; - for (int32 i = fTabShift; i < CountTabs();i++) { + for (int32 i = fTabShift; i < CountTabs(); i++) { GTab* nextTab = TabAt(i); middle -= nextTab->Bounds().Width(); shift++; @@ -189,7 +189,7 @@ TabsContainer::MouseDownOnTab(GTab* tab, BPoint where, const int32 buttons) if(buttons & B_PRIMARY_MOUSE_BUTTON) { SelectTab(tab); } else if (buttons & B_TERTIARY_MOUSE_BUTTON) { - + // Nothing } } @@ -198,7 +198,7 @@ TabsContainer::MouseDownOnTab(GTab* tab, BPoint where, const int32 buttons) void TabsContainer::FrameResized(float w, float h) { - //Auto-scroll: + // Auto-scroll: if (fTabShift > 0) { int32 tox = 0; GTab* last = TabAt(CountTabs()-1); @@ -214,7 +214,7 @@ TabsContainer::FrameResized(float w, float h) if (tox != 0) ShiftTabs(tox); } - //end + // end _UpdateScrolls(); BGroupView::FrameResized(w,h); } @@ -235,7 +235,7 @@ TabsContainer::OnDropTab(GTab* toTab, BMessage* message) void TabsContainer::_PrintToStream() { - for (int32 i=0;iCountItems();i++) { + for (int32 i = 0; i < GroupLayout()->CountItems(); i++) { printf("%d) %s\n", i, GroupLayout()->ItemAt(i)->View()->Name()); } } diff --git a/src/helpers/gtab/TabsContainer.h b/src/helpers/gtab/TabsContainer.h index bf0512ef..8586767a 100644 --- a/src/helpers/gtab/TabsContainer.h +++ b/src/helpers/gtab/TabsContainer.h @@ -20,14 +20,11 @@ class TabsContainer : public BGroupView, public BInvoker { BMessage* message = nullptr); void AddTab(GTab* tab, int32 index = -1); - - int32 CountTabs() const; - - GTab* TabAt(int32 index); - GTab* RemoveTab(GTab* tab); //just remove, not delete. + int32 CountTabs() const; - int32 IndexOfTab(GTab* tab); + GTab* TabAt(int32 index) const; + int32 IndexOfTab(GTab* tab) const; void ShiftTabs(int32 delta); // 0 to refresh the current state @@ -38,7 +35,6 @@ class TabsContainer : public BGroupView, public BInvoker { void OnDropTab(GTab* toTab, BMessage* message); GTab* SelectedTab() const; - void SelectTab(GTab* tab, bool invoke = true); GTabView* GetGTabView() const { return fGTabView; }