I have the same problem.
I’m writing an application similar to OGL. I’ve found that with overlapping child windows, the window at the BACK receives mouse events.
Also, wxWindow::Raise lowers the window and wxWindow::Lower raises the window!
In the doc’s it says that raise and lower are only for managed windows, but for overlapped child windows they do the opposite!
I think this is a bug. I’m running wxPython on WindowsXP. David Hurwitz reported something similar on the wxWindows list.
Below is wxPython sample code that shows this. The red shape prints to stdout when it receives mouse move, up, or down. In the area where it overlaps the white rectangle, the white rectangle receives the messages because it’s behind. Also try uncommenting the raise line, and the red rectangle will be at the back. And receive messages even where it is overlapped!
from wxPython.wx import *
RECT_SHAPE, MONITOR_SHAPE, PANEL_SHAPE = range(3)
class _Shape(wxWindow):
def __init__(self, parent, pos, size, caption, color):
wxWindow.__init__(self, parent, -1, pos, size)
self.parent_ = parent
self.caption = caption
self.color = color
EVT_PAINT(self, self.OnPaint)
class _MoveShape(_Shape):
def __init__(self, parent, pos, size, caption, color):
_Shape.__init__(self, parent, pos, size, caption, color)
EVT_MOTION(self, self.OnMouseMove)
EVT_LEFT_DOWN(self, self.OnMouseDown)
EVT_LEFT_UP(self, self.OnMouseUp)
def OnMouseMove(self, event):
event.Skip()
print 'mov'
def OnMouseDown(self, event):
event.Skip()
print 'down'
def OnMouseUp(self, event):
event.Skip()
print 'up'
class RectShape(_MoveShape):
def __init__(self, parent, pos, size, caption='shape', color='red'):
_MoveShape.__init__(self, parent, pos, size, caption, color)
self.type = RECT_SHAPE
def OnPaint(self, event):
event.Skip()
dc = wxPaintDC(self);
dc.SetBrush(wxBrush(self.color, wxSOLID))
w, h = self.GetSizeTuple()
dc.DrawRectangle(0, 0, w, h)
tw, th = dc.GetTextExtent(self.caption)
dc.DrawText(self.caption, w/2-tw/2, h/2-th/2)
class PanelShape(_Shape):
def __init__(self, parent, pos, size, caption='shape', color='white'):
_Shape.__init__(self, parent, pos, size, caption, color)
self.type = PANEL_SHAPE
def OnPaint(self, event):
event.Skip()
dc = wxPaintDC(self);
dc.SetBrush(wxBrush(self.color, wxSOLID))
w, h = self.GetSizeTuple()
dc.DrawRectangle(0, 0, w, h)
tw, th = dc.GetTextExtent(self.caption)
dc.DrawText(self.caption, w/2-tw/2, h/2-th/2)
class PanelCanvas(wxPanel):
def __init__(self, parent, pos, size):
wxPanel.__init__(self, parent, -1, pos, size)
self.shapes = []
self.panel = panel = PanelShape(self, [0, 0], [80, 80], 'panel')
shape = RectShape(self, [55, 55], [50, 50])
shape.Raise()
class demo:
def __init__(self):
app = wxPySimpleApp()
self.f = wxFrame(None, -1, 'f')
self.f.Show(true)
PanelCanvas(self.f, [0, 0], [500, 500])
EVT_MOTION(self.f, self.OnMouseMotion)
EVT_LEFT_UP(self.f, self.OnLeftUp)
EVT_CLOSE(self.f, self.OnClose)
app.MainLoop()
def OnMouseMotion(self, event):
pt = self.f.ClientToScreenXY(event.m_x, event.m_y)
def OnLeftUp(self, event):
pass
def OnClose(self, evt):
self.f.Destroy()
if name == ‘main’: demo()
Matthew Sherborne
···
----- Original Message -----
From: “David Hurwitz” hurwitz@ncbi.nlm.nih.gov
To: wx-users@lists.wxwindows.org
Sent: Tuesday, April 09, 2002 9:09 AM
Subject: question about order of windows
I’m a new user of wxWindows, and this is my first time writing to
this list. Thanks in advance for any help.I’m working with multiple wxWindows inside another wxWindow. I’m
having difficulty controlling which window receives the mouse events.
i.e. which window is on top of which window. The appearance of the
windows is just fine, but since I can’t seem to control where the mouse
events go I see funny behavior. For example, I can change the location
or borders of a window, though it appears to be obscured by another.I’m not sure it matters, but the parent window is a wxScrolledWindow,
and the children are wxSashWindow’s. Also, the parent window
is attached to a wxSplitterWindow.Since I’m new user, I realize only now that perhaps I should be using
MDIParentFrame and MDIChildFrames. Is that my only solutions?
Or is there another way I can control which window gets the mouse
events? Also, will the MDIChildFrames work when used in a
wxSplitterWindow? I suppose it should but I haven’t seen examples
like that.Thanks in advance.
David Hurwitz
NCBI/NLM/NIH
wx-users mailing list
wx-users@lists.wxwindows.org
http://lists.wxwindows.org/mailman/listinfo/wx-users