Refactor XTab and YTab to share a common base, TabBase.
TabBase takes care of layout tracking etc..
This commit is contained in:
+22
-20
@@ -17,18 +17,14 @@ namespace BALM {
|
|||||||
class BALMLayout;
|
class BALMLayout;
|
||||||
|
|
||||||
|
|
||||||
/**
|
class TabBase {
|
||||||
* Vertical grid line (x-tab).
|
|
||||||
*/
|
|
||||||
class XTab : public Variable, public BReferenceable {
|
|
||||||
public:
|
|
||||||
virtual ~XTab();
|
|
||||||
|
|
||||||
protected:
|
|
||||||
friend class BALMLayout;
|
|
||||||
XTab(BALMLayout* layout);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
TabBase();
|
||||||
|
virtual ~TabBase();
|
||||||
|
|
||||||
|
friend class BALMLayout;
|
||||||
|
friend class XTab;
|
||||||
|
friend class YTab;
|
||||||
struct BALMLayoutList;
|
struct BALMLayoutList;
|
||||||
|
|
||||||
bool IsInLayout(BALMLayout* layout);
|
bool IsInLayout(BALMLayout* layout);
|
||||||
@@ -37,27 +33,33 @@ private:
|
|||||||
bool IsSuitableFor(BALMLayout* layout);
|
bool IsSuitableFor(BALMLayout* layout);
|
||||||
|
|
||||||
BALMLayoutList* fLayouts;
|
BALMLayoutList* fLayouts;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Vertical grid line (x-tab).
|
||||||
|
*/
|
||||||
|
class XTab : public Variable, public TabBase, public BReferenceable {
|
||||||
|
public:
|
||||||
|
virtual ~XTab();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
friend class BALMLayout;
|
||||||
|
XTab(BALMLayout* layout);
|
||||||
|
|
||||||
|
private:
|
||||||
uint32 _reserved[2];
|
uint32 _reserved[2];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class YTab : public Variable, public BReferenceable {
|
class YTab : public Variable, public TabBase, public BReferenceable {
|
||||||
public:
|
public:
|
||||||
virtual ~YTab();
|
virtual ~YTab();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
friend class BALMLayout;
|
friend class BALMLayout;
|
||||||
YTab(BALMLayout* layout);
|
YTab(BALMLayout* layout);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool IsInLayout(BALMLayout* layout);
|
|
||||||
bool AddedToLayout(BALMLayout* layout);
|
|
||||||
void LayoutLeaving(BALMLayout* layout);
|
|
||||||
bool IsSuitableFor(BALMLayout* layout);
|
|
||||||
|
|
||||||
XTab::BALMLayoutList* fLayouts;
|
|
||||||
|
|
||||||
uint32 _reserved[2];
|
uint32 _reserved[2];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
+26
-46
@@ -11,9 +11,10 @@
|
|||||||
|
|
||||||
|
|
||||||
using std::nothrow;
|
using std::nothrow;
|
||||||
|
using BALM::TabBase;
|
||||||
|
|
||||||
|
|
||||||
struct XTab::BALMLayoutList {
|
struct TabBase::BALMLayoutList {
|
||||||
BALMLayoutList(BALMLayout* _layout, BALMLayoutList* _next = NULL)
|
BALMLayoutList(BALMLayout* _layout, BALMLayoutList* _next = NULL)
|
||||||
:
|
:
|
||||||
next(_next),
|
next(_next),
|
||||||
@@ -50,34 +51,27 @@ struct XTab::BALMLayoutList {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
XTab::XTab(BALMLayout* layout)
|
TabBase::TabBase()
|
||||||
:
|
:
|
||||||
Variable(layout->Solver()),
|
fLayouts(NULL)
|
||||||
fLayouts(new BALMLayoutList(layout))
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
XTab::~XTab()
|
TabBase::~TabBase()
|
||||||
{
|
{
|
||||||
BALMLayoutList* layouts = fLayouts;
|
|
||||||
while (layouts) {
|
|
||||||
layouts->layout->fXTabList.RemoveItem(this);
|
|
||||||
layouts = layouts->next;
|
|
||||||
}
|
|
||||||
delete fLayouts;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
XTab::IsInLayout(BALMLayout* layout)
|
TabBase::IsInLayout(BALMLayout* layout)
|
||||||
{
|
{
|
||||||
return fLayouts->HasLayout(layout);
|
return fLayouts->HasLayout(layout);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
XTab::AddedToLayout(BALMLayout* layout)
|
TabBase::AddedToLayout(BALMLayout* layout)
|
||||||
{
|
{
|
||||||
BALMLayoutList* newHead = new (nothrow) BALMLayoutList(layout, fLayouts);
|
BALMLayoutList* newHead = new (nothrow) BALMLayoutList(layout, fLayouts);
|
||||||
if (newHead == NULL)
|
if (newHead == NULL)
|
||||||
@@ -88,66 +82,52 @@ XTab::AddedToLayout(BALMLayout* layout)
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
XTab::LayoutLeaving(BALMLayout* layout)
|
TabBase::LayoutLeaving(BALMLayout* layout)
|
||||||
{
|
{
|
||||||
fLayouts = fLayouts->Remove(layout);
|
fLayouts = fLayouts->Remove(layout);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
XTab::IsSuitableFor(BALMLayout* layout)
|
TabBase::IsSuitableFor(BALMLayout* layout)
|
||||||
{
|
{
|
||||||
return (fLayouts->layout->Solver() == layout->Solver());
|
return (fLayouts->layout->Solver() == layout->Solver());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
YTab::YTab(BALMLayout* layout)
|
XTab::XTab(BALMLayout* layout)
|
||||||
:
|
:
|
||||||
Variable(layout->Solver()),
|
Variable(layout->Solver())
|
||||||
fLayouts(new XTab::BALMLayoutList(layout))
|
|
||||||
{
|
{
|
||||||
|
AddedToLayout(layout);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
YTab::~YTab()
|
XTab::~XTab()
|
||||||
{
|
{
|
||||||
XTab::BALMLayoutList* layouts = fLayouts;
|
TabBase::BALMLayoutList* layouts = fLayouts;
|
||||||
while (layouts) {
|
while (layouts) {
|
||||||
layouts->layout->fYTabList.RemoveItem(this);
|
layouts->layout->fXTabList.RemoveItem(this);
|
||||||
layouts = layouts->next;
|
layouts = layouts->next;
|
||||||
}
|
}
|
||||||
delete fLayouts;
|
delete fLayouts;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool
|
YTab::YTab(BALMLayout* layout)
|
||||||
YTab::IsInLayout(BALMLayout* layout)
|
:
|
||||||
|
Variable(layout->Solver())
|
||||||
{
|
{
|
||||||
return fLayouts->HasLayout(layout);
|
AddedToLayout(layout);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool
|
YTab::~YTab()
|
||||||
YTab::AddedToLayout(BALMLayout* layout)
|
|
||||||
{
|
{
|
||||||
XTab::BALMLayoutList* newHead
|
TabBase::BALMLayoutList* layouts = fLayouts;
|
||||||
= new (nothrow) XTab::BALMLayoutList(layout, fLayouts);
|
while (layouts) {
|
||||||
if (newHead == NULL)
|
layouts->layout->fYTabList.RemoveItem(this);
|
||||||
return false;
|
layouts = layouts->next;
|
||||||
fLayouts = newHead;
|
}
|
||||||
return true;
|
delete fLayouts;
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
YTab::LayoutLeaving(BALMLayout* layout)
|
|
||||||
{
|
|
||||||
fLayouts = fLayouts->Remove(layout);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool
|
|
||||||
YTab::IsSuitableFor(BALMLayout* layout)
|
|
||||||
{
|
|
||||||
return (fLayouts->layout->Solver() == layout->Solver());
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user