Skip to content

Commit

Permalink
JXIntegerTable; bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jafl committed Feb 7, 2024
1 parent fd9e228 commit 022dfcb
Show file tree
Hide file tree
Showing 28 changed files with 760 additions and 235 deletions.
3 changes: 3 additions & 0 deletions libjcore/Make.files
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@
.cpp ./code/JTableSelection
.cpp ./code/JTableSelectionIterator
.cpp ./code/JStringTableData
.cpp ./code/JBufferTableData
.cpp ./code/JIntegerTableData
.cpp ./code/JIntegerBufferTableData
.cpp ./code/JFloatTableData
.cpp ./code/JFloatBufferTableData
.cpp ./code/JStyleTableData
Expand Down
188 changes: 188 additions & 0 deletions libjcore/code/JBufferTableData.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
/******************************************************************************
JBufferTableData.cpp
Class to buffer a table of values as JStrings so drawing the table
will be faster.
BASE CLASS = JStringTableData
Copyright (C) 1996 John Lindal.
******************************************************************************/

#include "JBufferTableData.h"
#include "JFloatTableData.h"
#include "JString.h"
#include "jAssert.h"

/******************************************************************************
Constructor
Derived class must call UpdateRect()!
******************************************************************************/

JBufferTableData::JBufferTableData
(
const JTableData* data
)
:
itsData(data)
{
AppendRows(data->GetRowCount());
AppendCols(data->GetColCount());

ListenTo(itsData);
}

/******************************************************************************
Destructor
******************************************************************************/

JBufferTableData::~JBufferTableData()
{
}

/******************************************************************************
Receive (virtual protected)
******************************************************************************/

void
JBufferTableData::Receive
(
JBroadcaster* sender,
const Message& message
)
{
auto* data = const_cast<JTableData*>(itsData);

// element data changed

if (sender == data && message.Is(JTableData::kRectChanged))
{
const auto* info = dynamic_cast<const JTableData::RectChanged*>(&message);
assert( info != nullptr );
UpdateRect(info->GetRect());
}

// rows changed

else if (sender == data && message.Is(JTableData::kRowsInserted))
{
const auto* info = dynamic_cast<const JTableData::RowsInserted*>(&message);
assert( info != nullptr );
InsertRows(info->GetFirstIndex(), info->GetCount());
UpdateRows(info->GetFirstIndex(), info->GetCount());
}

else if (sender == data && message.Is(JTableData::kRowDuplicated))
{
const auto* info = dynamic_cast<const JTableData::RowDuplicated*>(&message);
assert( info != nullptr );
DuplicateRow(info->GetOrigIndex(), info->GetNewIndex());
}

else if (sender == data && message.Is(JTableData::kRowsRemoved))
{
const auto* info = dynamic_cast<const JTableData::RowsRemoved*>(&message);
assert( info != nullptr );
RemoveNextRows(info->GetFirstIndex(), info->GetCount());
}

else if (sender == data && message.Is(JTableData::kRowMoved))
{
const auto* info = dynamic_cast<const JTableData::RowMoved*>(&message);
assert( info != nullptr );
MoveRow(info->GetOrigIndex(), info->GetNewIndex());
}

// columns changed

else if (sender == data && message.Is(JTableData::kColsInserted))
{
const auto* info = dynamic_cast<const JTableData::ColsInserted*>(&message);
assert( info != nullptr );
InsertCols(info->GetFirstIndex(), info->GetCount());
UpdateCols(info->GetFirstIndex(), info->GetCount());
}

else if (sender == data && message.Is(JTableData::kColDuplicated))
{
const auto* info = dynamic_cast<const JTableData::ColDuplicated*>(&message);
assert( info != nullptr );
DuplicateCol(info->GetOrigIndex(), info->GetNewIndex());
}

else if (sender == data && message.Is(JTableData::kColsRemoved))
{
const auto* info = dynamic_cast<const JTableData::ColsRemoved*>(&message);
assert( info != nullptr );
RemoveNextCols(info->GetFirstIndex(), info->GetCount());
}

else if (sender == data && message.Is(JTableData::kColMoved))
{
const auto* info = dynamic_cast<const JTableData::ColMoved*>(&message);
assert( info != nullptr );
MoveCol(info->GetOrigIndex(), info->GetNewIndex());
}

// something else

else
{
JStringTableData::Receive(sender, message);
}
}

/******************************************************************************
UpdateRect (protected)
******************************************************************************/

void
JBufferTableData::UpdateRect
(
const JRect& r
)
{
for (JIndex x=r.left; x < (JIndex) r.right; x++)
{
for (JIndex y=r.top; y < (JIndex) r.bottom; y++)
{
UpdateCell(JPoint(x,y));
}
}
}

/******************************************************************************
UpdateRows (protected)
******************************************************************************/

inline void
JBufferTableData::UpdateRows
(
const JIndex firstIndex,
const JSize count
)
{
UpdateRect(JRect(firstIndex, 1, firstIndex+count, GetColCount()+1));
}

/******************************************************************************
UpdateCols (protected)
******************************************************************************/

inline void
JBufferTableData::UpdateCols
(
const JIndex firstIndex,
const JSize count
)
{
UpdateRect(JRect(1, firstIndex, GetRowCount()+1, firstIndex+count));
}
43 changes: 43 additions & 0 deletions libjcore/code/JBufferTableData.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/******************************************************************************
JBufferTableData.h
Copyright (C) 1996 John Lindal.
******************************************************************************/

#ifndef _H_JBufferTableData
#define _H_JBufferTableData

#include "JStringTableData.h"

class JFloatTableData;

class JBufferTableData : public JStringTableData
{
public:

JBufferTableData(const JTableData* data);

~JBufferTableData() override;

protected:

void UpdateRect(const JRect& r);
void UpdateRows(const JIndex firstIndex, const JSize count);
void UpdateCols(const JIndex firstIndex, const JSize count);
virtual void UpdateCell(const JPoint& cell) = 0;

void Receive(JBroadcaster* sender, const Message& message) override;

private:

const JTableData* itsData;

private:

// not allowed

JBufferTableData(const JBufferTableData&) = delete;
};

#endif
4 changes: 4 additions & 0 deletions libjcore/code/JCoreLibVersion.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ static const char* kCurrentJCoreLibVersionStr = "4.1.0";
// JImage:
// Fixed ReadGD() to correctly apply a mask for true color png's.
// Added pure virtual CreateEmptyMask().
// Added JIntegerTableData, JIntegerBufferTableData.
// Fixed bug in JFloatTableData so it works when constructed with non-empty data.
// Fixed derived classes of JTableData to use JListIterator, since JList
// no longer supports Get/SetItem().

// version 4.0.0:
// *** Upgraded to C++20
Expand Down
Loading

0 comments on commit 022dfcb

Please sign in to comment.