Skip to content

Commit

Permalink
Further style fixes. Added some more const
Browse files Browse the repository at this point in the history
  • Loading branch information
jackburton79 committed Jan 13, 2025
1 parent 7d91a4d commit 245c540
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 49 deletions.
60 changes: 29 additions & 31 deletions src/helpers/gtab/GTab.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@
#include <GridLayout.h>
#include <LayoutBuilder.h>
#include <MessageRunner.h>
#include <Rect.h>
#include <Size.h>
#include <View.h>

#include <cstdio>
#include <typeinfo>
Expand Down Expand Up @@ -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)
{
Expand All @@ -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();
Expand Down Expand Up @@ -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;
Expand All @@ -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;
};


Expand Down Expand Up @@ -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);
}
Expand All @@ -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();
Expand Down
22 changes: 11 additions & 11 deletions src/helpers/gtab/TabsContainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -59,7 +59,7 @@ TabsContainer::CountTabs() const


GTab*
TabsContainer::TabAt(int32 index)
TabsContainer::TabAt(int32 index) const
{
if (index < 0 || index >= CountTabs())
return nullptr;
Expand All @@ -69,7 +69,7 @@ TabsContainer::TabAt(int32 index)


int32
TabsContainer::IndexOfTab(GTab* tab)
TabsContainer::IndexOfTab(GTab* tab) const
{
if (fSelectedTab == nullptr)
return -1;
Expand All @@ -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;
Expand Down Expand Up @@ -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));
Expand All @@ -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++;
Expand Down Expand Up @@ -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
}
}

Expand All @@ -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);
Expand All @@ -214,7 +214,7 @@ TabsContainer::FrameResized(float w, float h)
if (tox != 0)
ShiftTabs(tox);
}
//end
// end
_UpdateScrolls();
BGroupView::FrameResized(w,h);
}
Expand All @@ -235,7 +235,7 @@ TabsContainer::OnDropTab(GTab* toTab, BMessage* message)
void
TabsContainer::_PrintToStream()
{
for (int32 i=0;i<GroupLayout()->CountItems();i++) {
for (int32 i = 0; i < GroupLayout()->CountItems(); i++) {
printf("%d) %s\n", i, GroupLayout()->ItemAt(i)->View()->Name());
}
}
Expand Down
10 changes: 3 additions & 7 deletions src/helpers/gtab/TabsContainer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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; }
Expand Down

0 comments on commit 245c540

Please sign in to comment.