corrections for event handling changes in wxWindows

renamed Cell and CellBox to LifeCell and LifeCellBox to avoid conflict
with Classic Mac OS Toolbox type


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@9297 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Gilles Depeyrot
2001-02-04 20:11:49 +00:00
parent 50dacf0581
commit 764835a5d5
4 changed files with 112 additions and 99 deletions

View File

@@ -40,7 +40,7 @@
// resources // resources
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
#if defined(__WXGTK__) || defined(__WXMOTIF__) #if defined(__WXGTK__) || defined(__WXMOTIF__) || defined(__WXMAC__)
// logo for the about dialog // logo for the about dialog
#include "bitmaps/life.xpm" #include "bitmaps/life.xpm"
#endif #endif

View File

@@ -54,7 +54,7 @@
#define CELLBOX 8 // cells in a cellbox (do not change!) #define CELLBOX 8 // cells in a cellbox (do not change!)
class CellBox class LifeCellBox
{ {
public: public:
// members // members
@@ -67,16 +67,16 @@ public:
wxUint32 m_old1, m_old2; // old values for m_live1, 2 wxUint32 m_old1, m_old2; // old values for m_live1, 2
wxUint32 m_on[8]; // neighbouring info wxUint32 m_on[8]; // neighbouring info
wxUint32 m_dead; // been dead for n generations wxUint32 m_dead; // been dead for n generations
CellBox *m_up, *m_dn, *m_lf, *m_rt; // neighbour CellBoxes LifeCellBox *m_up, *m_dn, *m_lf, *m_rt; // neighbour CellBoxes
CellBox *m_prev, *m_next; // in linked list LifeCellBox *m_prev, *m_next; // in linked list
CellBox *m_hprev, *m_hnext; // in hash table LifeCellBox *m_hprev, *m_hnext; // in hash table
}; };
// IsAlive: // IsAlive:
// Returns whether cell dx, dy in this box is alive // Returns whether cell dx, dy in this box is alive
// //
bool CellBox::IsAlive(int dx, int dy) const bool LifeCellBox::IsAlive(int dx, int dy) const
{ {
if (dy > 3) if (dy > 3)
return (m_live2 & 1 << ((dy - 4) * 8 + dx)); return (m_live2 & 1 << ((dy - 4) * 8 + dx));
@@ -88,7 +88,7 @@ bool CellBox::IsAlive(int dx, int dy) const
// Sets cell dx, dy in this box to 'alive', returns TRUE if // Sets cell dx, dy in this box to 'alive', returns TRUE if
// the previous value was different, FALSE if it was the same. // the previous value was different, FALSE if it was the same.
// //
bool CellBox::SetCell(int dx, int dy, bool alive) bool LifeCellBox::SetCell(int dx, int dy, bool alive)
{ {
if (IsAlive(dx, dy) != alive) if (IsAlive(dx, dy) != alive)
{ {
@@ -124,14 +124,14 @@ Life::Life()
// pattern data // pattern data
m_numcells = 0; m_numcells = 0;
m_boxes = new CellBox *[HASHSIZE]; m_boxes = new LifeCellBox *[HASHSIZE];
m_head = NULL; m_head = NULL;
m_available = NULL; m_available = NULL;
for (int i = 0; i < HASHSIZE; i++) for (int i = 0; i < HASHSIZE; i++)
m_boxes[i] = NULL; m_boxes[i] = NULL;
// state vars for BeginFind & FindMore // state vars for BeginFind & FindMore
m_cells = new Cell[ARRAYSIZE]; m_cells = new LifeCell[ARRAYSIZE];
m_ncells = 0; m_ncells = 0;
m_findmore = FALSE; m_findmore = FALSE;
m_changed = FALSE; m_changed = FALSE;
@@ -150,7 +150,7 @@ Life::~Life()
// //
void Life::Clear() void Life::Clear()
{ {
CellBox *c, *nc; LifeCellBox *c, *nc;
// clear the hash table pointers // clear the hash table pointers
for (int i = 0; i < HASHSIZE; i++) for (int i = 0; i < HASHSIZE; i++)
@@ -192,7 +192,7 @@ void Life::Clear()
// //
bool Life::IsAlive(wxInt32 x, wxInt32 y) bool Life::IsAlive(wxInt32 x, wxInt32 y)
{ {
CellBox *c = LinkBox(x, y, FALSE); LifeCellBox *c = LinkBox(x, y, FALSE);
return (c && c->IsAlive( x - c->m_x, y - c->m_y )); return (c && c->IsAlive( x - c->m_x, y - c->m_y ));
} }
@@ -202,7 +202,7 @@ bool Life::IsAlive(wxInt32 x, wxInt32 y)
// //
void Life::SetCell(wxInt32 x, wxInt32 y, bool alive) void Life::SetCell(wxInt32 x, wxInt32 y, bool alive)
{ {
CellBox *c = LinkBox(x, y); LifeCellBox *c = LinkBox(x, y);
wxUint32 dx = x - c->m_x; wxUint32 dx = x - c->m_x;
wxUint32 dy = y - c->m_y; wxUint32 dy = y - c->m_y;
@@ -257,15 +257,15 @@ void Life::SetPattern(const LifePattern& pattern)
// Creates a box in x, y, either taking it from the list // Creates a box in x, y, either taking it from the list
// of available boxes, or allocating a new one. // of available boxes, or allocating a new one.
// //
CellBox* Life::CreateBox(wxInt32 x, wxInt32 y, wxUint32 hv) LifeCellBox* Life::CreateBox(wxInt32 x, wxInt32 y, wxUint32 hv)
{ {
CellBox *c; LifeCellBox *c;
// if there are no available boxes, alloc a few more // if there are no available boxes, alloc a few more
if (!m_available) if (!m_available)
for (int i = 1; i <= ALLOCBOXES; i++) for (int i = 1; i <= ALLOCBOXES; i++)
{ {
c = new CellBox(); c = new LifeCellBox();
if (!c) if (!c)
{ {
@@ -289,7 +289,7 @@ CellBox* Life::CreateBox(wxInt32 x, wxInt32 y, wxUint32 hv)
m_available = c->m_next; m_available = c->m_next;
// reset everything // reset everything
memset((void *) c, 0, sizeof(CellBox)); memset((void *) c, 0, sizeof(LifeCellBox));
c->m_x = x; c->m_x = x;
c->m_y = y; c->m_y = y;
@@ -311,10 +311,10 @@ CellBox* Life::CreateBox(wxInt32 x, wxInt32 y, wxUint32 hv)
// it returns NULL or creates a new one, depending on the value // it returns NULL or creates a new one, depending on the value
// of the 'create' parameter. // of the 'create' parameter.
// //
CellBox* Life::LinkBox(wxInt32 x, wxInt32 y, bool create) LifeCellBox* Life::LinkBox(wxInt32 x, wxInt32 y, bool create)
{ {
wxUint32 hv; wxUint32 hv;
CellBox *c; LifeCellBox *c;
x &= 0xfffffff8; x &= 0xfffffff8;
y &= 0xfffffff8; y &= 0xfffffff8;
@@ -325,14 +325,14 @@ CellBox* Life::LinkBox(wxInt32 x, wxInt32 y, bool create)
if ((c->m_x == x) && (c->m_y == y)) return c; if ((c->m_x == x) && (c->m_y == y)) return c;
// if not found, and (create == TRUE), create a new one // if not found, and (create == TRUE), create a new one
return create? CreateBox(x, y, hv) : (CellBox*) NULL; return create? CreateBox(x, y, hv) : (LifeCellBox*) NULL;
} }
// KillBox: // KillBox:
// Removes this box from the list and the hash table and // Removes this box from the list and the hash table and
// puts it in the list of available boxes. // puts it in the list of available boxes.
// //
void Life::KillBox(CellBox *c) void Life::KillBox(LifeCellBox *c)
{ {
wxUint32 hv = HASH(c->m_x, c->m_y); wxUint32 hv = HASH(c->m_x, c->m_y);
@@ -365,7 +365,7 @@ void Life::KillBox(CellBox *c)
// Navigation // Navigation
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
Cell Life::FindCenter() LifeCell Life::FindCenter()
{ {
double sx, sy; double sx, sy;
int n; int n;
@@ -373,7 +373,7 @@ Cell Life::FindCenter()
sy = 0.0; sy = 0.0;
n = 0; n = 0;
CellBox *c; LifeCellBox *c;
for (c = m_head; c; c = c->m_next) for (c = m_head; c; c = c->m_next)
if (!c->m_dead) if (!c->m_dead)
{ {
@@ -388,18 +388,18 @@ Cell Life::FindCenter()
sy = (sy / n) + CELLBOX / 2; sy = (sy / n) + CELLBOX / 2;
} }
Cell cell; LifeCell cell;
cell.i = (wxInt32) sx; cell.i = (wxInt32) sx;
cell.j = (wxInt32) sy; cell.j = (wxInt32) sy;
return cell; return cell;
} }
Cell Life::FindNorth() LifeCell Life::FindNorth()
{ {
wxInt32 x = 0, y = 0; wxInt32 x = 0, y = 0;
bool first = TRUE; bool first = TRUE;
CellBox *c; LifeCellBox *c;
for (c = m_head; c; c = c->m_next) for (c = m_head; c; c = c->m_next)
if (!c->m_dead && ((first) || (c->m_y < y))) if (!c->m_dead && ((first) || (c->m_y < y)))
{ {
@@ -408,18 +408,18 @@ Cell Life::FindNorth()
first = FALSE; first = FALSE;
} }
Cell cell; LifeCell cell;
cell.i = first? 0 : x + CELLBOX / 2; cell.i = first? 0 : x + CELLBOX / 2;
cell.j = first? 0 : y + CELLBOX / 2; cell.j = first? 0 : y + CELLBOX / 2;
return cell; return cell;
} }
Cell Life::FindSouth() LifeCell Life::FindSouth()
{ {
wxInt32 x = 0, y = 0; wxInt32 x = 0, y = 0;
bool first = TRUE; bool first = TRUE;
CellBox *c; LifeCellBox *c;
for (c = m_head; c; c = c->m_next) for (c = m_head; c; c = c->m_next)
if (!c->m_dead && ((first) || (c->m_y > y))) if (!c->m_dead && ((first) || (c->m_y > y)))
{ {
@@ -428,18 +428,18 @@ Cell Life::FindSouth()
first = FALSE; first = FALSE;
} }
Cell cell; LifeCell cell;
cell.i = first? 0 : x + CELLBOX / 2; cell.i = first? 0 : x + CELLBOX / 2;
cell.j = first? 0 : y + CELLBOX / 2; cell.j = first? 0 : y + CELLBOX / 2;
return cell; return cell;
} }
Cell Life::FindWest() LifeCell Life::FindWest()
{ {
wxInt32 x = 0, y = 0; wxInt32 x = 0, y = 0;
bool first = TRUE; bool first = TRUE;
CellBox *c; LifeCellBox *c;
for (c = m_head; c; c = c->m_next) for (c = m_head; c; c = c->m_next)
if (!c->m_dead && ((first) || (c->m_x < x))) if (!c->m_dead && ((first) || (c->m_x < x)))
{ {
@@ -448,18 +448,18 @@ Cell Life::FindWest()
first = FALSE; first = FALSE;
} }
Cell cell; LifeCell cell;
cell.i = first? 0 : x + CELLBOX / 2; cell.i = first? 0 : x + CELLBOX / 2;
cell.j = first? 0 : y + CELLBOX / 2; cell.j = first? 0 : y + CELLBOX / 2;
return cell; return cell;
} }
Cell Life::FindEast() LifeCell Life::FindEast()
{ {
wxInt32 x = 0, y = 0; wxInt32 x = 0, y = 0;
bool first = TRUE; bool first = TRUE;
CellBox *c; LifeCellBox *c;
for (c = m_head; c; c = c->m_next) for (c = m_head; c; c = c->m_next)
if (!c->m_dead && ((first) || (c->m_x > x))) if (!c->m_dead && ((first) || (c->m_x > x)))
{ {
@@ -468,7 +468,7 @@ Cell Life::FindEast()
first = FALSE; first = FALSE;
} }
Cell cell; LifeCell cell;
cell.i = first? 0 : x + CELLBOX / 2; cell.i = first? 0 : x + CELLBOX / 2;
cell.j = first? 0 : y + CELLBOX / 2; cell.j = first? 0 : y + CELLBOX / 2;
return cell; return cell;
@@ -517,9 +517,9 @@ void Life::BeginFind(wxInt32 x0, wxInt32 y0, wxInt32 x1, wxInt32 y1, bool change
m_changed = changed; m_changed = changed;
} }
bool Life::FindMore(Cell *cells[], size_t *ncells) bool Life::FindMore(LifeCell *cells[], size_t *ncells)
{ {
CellBox *c; LifeCellBox *c;
*cells = m_cells; *cells = m_cells;
m_ncells = 0; m_ncells = 0;
@@ -592,7 +592,7 @@ extern int g_tab2[];
// //
bool Life::NextTic() bool Life::NextTic()
{ {
CellBox *c, *up, *dn, *lf, *rt; LifeCellBox *c, *up, *dn, *lf, *rt;
wxUint32 t1, t2, t3, t4; wxUint32 t1, t2, t3, t4;
bool changed = FALSE; bool changed = FALSE;
@@ -896,7 +896,7 @@ bool Life::NextTic()
} }
else else
{ {
CellBox *aux = c->m_next; LifeCellBox *aux = c->m_next;
if (c->m_dead++ > MAXDEAD) if (c->m_dead++ > MAXDEAD)
KillBox(c); KillBox(c);

View File

@@ -75,14 +75,14 @@ public:
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
// A struct used to pass cell coordinates around // A struct used to pass cell coordinates around
struct Cell struct LifeCell
{ {
wxInt32 i; wxInt32 i;
wxInt32 j; wxInt32 j;
}; };
// A private class that contains data about a block of cells // A private class that contains data about a block of cells
class CellBox; class LifeCellBox;
// A class that models a Life game instance // A class that models a Life game instance
class Life class Life
@@ -105,11 +105,11 @@ public:
bool NextTic(); bool NextTic();
// navigation // navigation
Cell FindNorth(); LifeCell FindNorth();
Cell FindSouth(); LifeCell FindSouth();
Cell FindWest(); LifeCell FindWest();
Cell FindEast(); LifeCell FindEast();
Cell FindCenter(); LifeCell FindCenter();
// The following functions find cells within a given viewport; either // The following functions find cells within a given viewport; either
// all alive cells, or only those cells which have changed since last // all alive cells, or only those cells which have changed since last
@@ -132,13 +132,13 @@ public:
void BeginFind(wxInt32 x0, wxInt32 y0, void BeginFind(wxInt32 x0, wxInt32 y0,
wxInt32 x1, wxInt32 y1, wxInt32 x1, wxInt32 y1,
bool changed); bool changed);
bool FindMore(Cell *cells[], size_t *ncells); bool FindMore(LifeCell *cells[], size_t *ncells);
private: private:
// cellbox-related // cellbox-related
CellBox *CreateBox(wxInt32 x, wxInt32 y, wxUint32 hv); LifeCellBox *CreateBox(wxInt32 x, wxInt32 y, wxUint32 hv);
CellBox *LinkBox(wxInt32 x, wxInt32 y, bool create = TRUE); LifeCellBox *LinkBox(wxInt32 x, wxInt32 y, bool create = TRUE);
void KillBox(CellBox *c); void KillBox(LifeCellBox *c);
// helper for BeginFind & FindMore // helper for BeginFind & FindMore
void DoLine(wxInt32 x, wxInt32 y, wxUint32 alive, wxUint32 old = 0); void DoLine(wxInt32 x, wxInt32 y, wxUint32 alive, wxUint32 old = 0);
@@ -150,13 +150,13 @@ private:
wxString m_description; // description wxString m_description; // description
// pattern data // pattern data
CellBox *m_head; // list of alive boxes LifeCellBox *m_head; // list of alive boxes
CellBox *m_available; // list of reusable dead boxes LifeCellBox *m_available; // list of reusable dead boxes
CellBox **m_boxes; // hash table of alive boxes LifeCellBox **m_boxes; // hash table of alive boxes
wxUint32 m_numcells; // population (number of alive cells) wxUint32 m_numcells; // population (number of alive cells)
// state vars for BeginFind & FindMore // state vars for BeginFind & FindMore
Cell *m_cells; // array of cells LifeCell *m_cells; // array of cells
size_t m_ncells; // number of valid entries in m_cells size_t m_ncells; // number of valid entries in m_cells
wxInt32 m_x, m_y, // counters and search mode wxInt32 m_x, m_y, // counters and search mode
m_x0, m_y0, m_x0, m_y0,

View File

@@ -41,7 +41,7 @@
// resources // resources
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
#if defined(__WXGTK__) || defined(__WXMOTIF__) #if defined(__WXGTK__) || defined(__WXMOTIF__) || defined(__WXMAC__)
// application icon // application icon
#include "mondrian.xpm" #include "mondrian.xpm"
@@ -503,7 +503,7 @@ void LifeFrame::OnZoom(wxCommandEvent& event)
void LifeFrame::OnNavigate(wxCommandEvent& event) void LifeFrame::OnNavigate(wxCommandEvent& event)
{ {
Cell c; LifeCell c;
switch (event.GetId()) switch (event.GetId())
{ {
@@ -772,7 +772,7 @@ void LifeCanvas::DrawChanged()
wxClientDC dc(this); wxClientDC dc(this);
size_t ncells; size_t ncells;
Cell *cells; LifeCell *cells;
bool done = FALSE; bool done = FALSE;
m_life->BeginFind(m_viewportX, m_life->BeginFind(m_viewportX,
@@ -824,7 +824,7 @@ void LifeCanvas::OnPaint(wxPaintEvent& event)
j1 = YToCell(y + h - 1); j1 = YToCell(y + h - 1);
size_t ncells; size_t ncells;
Cell *cells; LifeCell *cells;
bool done = FALSE; bool done = FALSE;
m_life->BeginFind(i0, j0, i1, j1, FALSE); m_life->BeginFind(i0, j0, i1, j1, FALSE);
@@ -1021,29 +1021,43 @@ void LifeCanvas::OnScroll(wxScrollWinEvent& event)
// calculate scroll increment // calculate scroll increment
int scrollinc = 0; int scrollinc = 0;
switch (type) if (type == wxEVT_SCROLLWIN_TOP)
{
case wxEVT_SCROLLWIN_TOP:
{ {
if (orient == wxHORIZONTAL) if (orient == wxHORIZONTAL)
scrollinc = -m_viewportW; scrollinc = -m_viewportW;
else else
scrollinc = -m_viewportH; scrollinc = -m_viewportH;
break;
} }
case wxEVT_SCROLLWIN_BOTTOM: else
if (type == wxEVT_SCROLLWIN_BOTTOM)
{ {
if (orient == wxHORIZONTAL) if (orient == wxHORIZONTAL)
scrollinc = m_viewportW; scrollinc = m_viewportW;
else else
scrollinc = m_viewportH; scrollinc = m_viewportH;
break;
} }
case wxEVT_SCROLLWIN_LINEUP: scrollinc = -1; break; else
case wxEVT_SCROLLWIN_LINEDOWN: scrollinc = +1; break; if (type == wxEVT_SCROLLWIN_LINEUP)
case wxEVT_SCROLLWIN_PAGEUP: scrollinc = -10; break; {
case wxEVT_SCROLLWIN_PAGEDOWN: scrollinc = +10; break; scrollinc = -1;
case wxEVT_SCROLLWIN_THUMBTRACK: }
else
if (type == wxEVT_SCROLLWIN_LINEDOWN)
{
scrollinc = +1;
}
else
if (type == wxEVT_SCROLLWIN_PAGEUP)
{
scrollinc = -10;
}
else
if (type == wxEVT_SCROLLWIN_PAGEDOWN)
{
scrollinc = -10;
}
else
if (type == wxEVT_SCROLLWIN_THUMBTRACK)
{ {
if (orient == wxHORIZONTAL) if (orient == wxHORIZONTAL)
{ {
@@ -1055,14 +1069,13 @@ void LifeCanvas::OnScroll(wxScrollWinEvent& event)
scrollinc = pos - m_thumbY; scrollinc = pos - m_thumbY;
m_thumbY = pos; m_thumbY = pos;
} }
break;
} }
case wxEVT_SCROLLWIN_THUMBRELEASE: else
if (type == wxEVT_SCROLLWIN_THUMBRELEASE)
{ {
m_thumbX = m_viewportW; m_thumbX = m_viewportW;
m_thumbY = m_viewportH; m_thumbY = m_viewportH;
} }
}
#if defined(__WXGTK__) || defined(__WXMOTIF__) #if defined(__WXGTK__) || defined(__WXMOTIF__)
// wxGTK and wxMotif update the thumb automatically (wxMSW doesn't); // wxGTK and wxMotif update the thumb automatically (wxMSW doesn't);