-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
28 changed files
with
760 additions
and
235 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.