capturing the mouse in wxCanvasObject

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@8265 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Kevin Hock
2000-09-05 20:07:57 +00:00
parent 21156596eb
commit dc16900b10
2 changed files with 186 additions and 148 deletions

View File

@@ -65,6 +65,10 @@ public:
inline int GetWidth() { return m_area.width; } inline int GetWidth() { return m_area.width; }
inline int GetHeight() { return m_area.height; } inline int GetHeight() { return m_area.height; }
void CaptureMouse();
void ReleaseMouse();
bool IsCapturedMouse();
protected: protected:
wxCanvas *m_owner; wxCanvas *m_owner;
bool m_isControl; bool m_isControl;
@@ -108,7 +112,7 @@ private:
class wxCanvasLine: public wxCanvasObject class wxCanvasLine: public wxCanvasObject
{ {
public: public:
wxCanvasLine( double x1, double y1, double x1, double y1, wxCanvasLine( double x1, double y1, double x2, double y2,
unsigned char red, unsigned char green, unsigned char blue ); unsigned char red, unsigned char green, unsigned char blue );
virtual void Recreate(); virtual void Recreate();
@@ -238,15 +242,15 @@ public:
// ... and call this to tell all objets to recreate then // ... and call this to tell all objets to recreate then
virtual void Recreate(); virtual void Recreate();
void CaptureMouse( wxCanvasObject *obj );
void ReleaseMouse();
wxImage *GetBuffer() { return &m_buffer; } wxImage *GetBuffer() { return &m_buffer; }
bool NeedUpdate() { return m_needUpdate; } bool NeedUpdate() { return m_needUpdate; }
bool IsFrozen() { return m_frozen; } bool IsFrozen() { return m_frozen; }
void BlitBuffer( wxDC &dc ); void BlitBuffer( wxDC &dc );
void SetCaptureMouse( wxCanvasObject *obj );
private: private:
wxImage m_buffer; wxImage m_buffer;
bool m_needUpdate; bool m_needUpdate;

View File

@@ -98,6 +98,22 @@ bool wxCanvasObject::IsHit( int x, int y, int margin )
(y <= m_area.y+m_area.height+margin)); (y <= m_area.y+m_area.height+margin));
} }
void wxCanvasObject::CaptureMouse()
{
m_owner->SetCaptureMouse( this );
}
void wxCanvasObject::ReleaseMouse()
{
m_owner->SetCaptureMouse( NULL );
}
bool wxCanvasObject::IsCapturedMouse()
{
return m_owner->m_captureMouse==this;
}
void wxCanvasObject::Render( int clip_x, int clip_y, int clip_width, int clip_height ) void wxCanvasObject::Render( int clip_x, int clip_y, int clip_width, int clip_height )
{ {
} }
@@ -579,16 +595,18 @@ void wxCanvas::SetColour( unsigned char red, unsigned char green, unsigned char
} }
} }
void wxCanvas::CaptureMouse( wxCanvasObject *obj ) void wxCanvas::SetCaptureMouse( wxCanvasObject *obj )
{
if (obj)
{ {
wxWindow::CaptureMouse(); wxWindow::CaptureMouse();
m_captureMouse = obj; m_captureMouse = obj;
} }
else
void wxCanvas::ReleaseMouse()
{ {
m_captureMouse = (wxCanvasObject*) NULL;
wxWindow::ReleaseMouse(); wxWindow::ReleaseMouse();
m_captureMouse = NULL;
}
} }
void wxCanvas::Freeze() void wxCanvas::Freeze()
@@ -881,13 +899,28 @@ void wxCanvas::OnPaint(wxPaintEvent &event)
void wxCanvas::OnMouse(wxMouseEvent &event) void wxCanvas::OnMouse(wxMouseEvent &event)
{ {
// should we implement mouse capture ?
int x = event.GetX(); int x = event.GetX();
int y = event.GetY(); int y = event.GetY();
CalcUnscrolledPosition( x, y, &x, &y ); CalcUnscrolledPosition( x, y, &x, &y );
if (event.GetEventType() == wxEVT_MOTION) if (event.GetEventType() == wxEVT_MOTION)
{
if (m_captureMouse) //no matter what go to this one
{
wxMouseEvent child_event( wxEVT_MOTION );
child_event.SetEventObject(m_captureMouse);
child_event.m_x = x - m_captureMouse->GetX();
child_event.m_y = y - m_captureMouse->GetY();
child_event.m_leftDown = event.m_leftDown;
child_event.m_rightDown = event.m_rightDown;
child_event.m_middleDown = event.m_middleDown;
child_event.m_controlDown = event.m_controlDown;
child_event.m_shiftDown = event.m_shiftDown;
child_event.m_altDown = event.m_altDown;
child_event.m_metaDown = event.m_metaDown;
m_captureMouse->ProcessEvent( child_event );
}
else
{ {
wxNode *node = m_objects.Last(); wxNode *node = m_objects.Last();
while (node) while (node)
@@ -934,6 +967,7 @@ void wxCanvas::OnMouse(wxMouseEvent &event)
} }
node = node->Previous(); node = node->Previous();
} }
}
if (m_lastMouse) if (m_lastMouse)
{ {
wxMouseEvent child_event( wxEVT_LEAVE_WINDOW ); wxMouseEvent child_event( wxEVT_LEAVE_WINDOW );