]> git.saurik.com Git - wxWidgets.git/blobdiff - src/motif/window.cpp
avoiding a OS-Level set focus for a control that already has the focus
[wxWidgets.git] / src / motif / window.cpp
index 423526f7388d818c2475b688c39ceb4eab638ecb..207afc3ed056f31ce74a1d30f2b327fb8730f23e 100644 (file)
@@ -21,6 +21,9 @@
     #pragma implementation "window.h"
 #endif
 
+// For compilers that support precompilation, includes "wx.h".
+#include "wx/wxprec.h"
+
 #ifdef __VMS
 #define XtDisplay XTDISPLAY
 #define XtWindow XTWINDOW
@@ -754,7 +757,9 @@ int wxWindow::GetScrollPos(int orient) const
 int wxWindow::GetScrollRange(int orient) const
 {
     Widget scrollBar = (Widget)GetScrollbar((wxOrientation)orient);
-    wxCHECK_MSG( scrollBar, 0, "no such scrollbar" );
+    // CE scintilla windows don't always have these scrollbars 
+    // and it tends to pile up a whole bunch of asserts
+    //wxCHECK_MSG( scrollBar, 0, "no such scrollbar" );
 
     int range = 0;
     if (scrollBar) 
@@ -765,10 +770,11 @@ int wxWindow::GetScrollRange(int orient) const
 int wxWindow::GetScrollThumb(int orient) const
 {
     Widget scrollBar = (Widget)GetScrollbar((wxOrientation)orient);
-    wxCHECK_MSG( scrollBar, 0, "no such scrollbar" );
+    //wxCHECK_MSG( scrollBar, 0, "no such scrollbar" );
 
-    int thumb;
-    XtVaGetValues(scrollBar, XmNsliderSize, &thumb, NULL);
+    int thumb = 0;
+    if (scrollBar)
+        XtVaGetValues(scrollBar, XmNsliderSize, &thumb, NULL);
     return thumb;
 }
 
@@ -1069,6 +1075,12 @@ void wxWindow::DoSetToolTip(wxToolTip * WXUNUSED(tooltip))
 
 bool wxWindow::DoPopupMenu(wxMenu *menu, int x, int y)
 {
+    if ( x == -1 && y == -1 )
+    {
+        wxPoint mouse = ScreenToClient(wxGetMousePosition());
+        x = mouse.x; y = mouse.y;
+    }
+
     Widget widget = (Widget) GetMainWidget();
 
     /* The menuId field seems to be usused, so we'll use it to
@@ -1590,7 +1602,7 @@ void wxWindow::DoPaint()
       // otherwise we don't know how many pixels have been scrolled. We might
       // solve this in the future by defining virtual wxWindow functions to get
       // the scroll position in pixels. Or, each kind of scrolled window has to
-      // implement backing stores itself, using generic wxWindows code.
+      // implement backing stores itself, using generic wxWidgets code.
       wxScrolledWindow* scrolledWindow = wxDynamicCast(this, wxScrolledWindow);
       if ( scrolledWindow )
       {
@@ -1758,7 +1770,7 @@ bool wxWindow::ProcessAccelerator(wxKeyEvent& event)
 // ============================================================================
 
 // ----------------------------------------------------------------------------
-// function which maintain the global hash table mapping Widgets to wxWindows
+// function which maintain the global hash table mapping Widgets to wxWidgets
 // ----------------------------------------------------------------------------
 
 bool wxAddWindowToTable(Widget w, wxWindow *win)
@@ -1995,7 +2007,7 @@ static void wxCanvasInputEvent(Widget drawingArea,
                                XmDrawingAreaCallbackStruct * cbs)
 {
     wxWindow *canvas = wxGetWindowFromTable(drawingArea);
-    XEvent local_event;
+    XEvent* xevent = cbs->event;
 
     if (canvas==NULL)
         return;
@@ -2003,27 +2015,25 @@ static void wxCanvasInputEvent(Widget drawingArea,
     if (cbs->reason != XmCR_INPUT)
         return;
 
-    local_event = *(cbs->event);    // We must keep a copy!
-
-    switch (local_event.xany.type)
+    switch (xevent->xany.type)
     {
     case EnterNotify:
     case LeaveNotify:
     case ButtonPress:
     case ButtonRelease:
     case MotionNotify:
-    {
-        wxMouseEvent wxevent;
-        if(wxTranslateMouseEvent(wxevent, canvas, drawingArea, &local_event))
         {
-            canvas->GetEventHandler()->ProcessEvent(wxevent);
+            wxMouseEvent wxevent(0);
+            if (wxTranslateMouseEvent(wxevent, canvas, drawingArea, xevent))
+            {
+                canvas->GetEventHandler()->ProcessEvent(wxevent);
+            }
+            break;
         }
-        break;
-    }
     case KeyPress:
         {
             wxKeyEvent event (wxEVT_CHAR);
-            if (wxTranslateKeyEvent (event, canvas, (Widget) 0, &local_event))
+            if (wxTranslateKeyEvent (event, canvas, (Widget) 0, xevent))
             {
                 // Implement wxFrame::OnCharHook by checking ancestor.
                 wxWindow *parent = canvas;
@@ -2053,7 +2063,7 @@ static void wxCanvasInputEvent(Widget drawingArea,
     case KeyRelease:
         {
             wxKeyEvent event (wxEVT_KEY_UP);
-            if (wxTranslateKeyEvent (event, canvas, (Widget) 0, &local_event))
+            if (wxTranslateKeyEvent (event, canvas, (Widget) 0, xevent))
             {
                 canvas->GetEventHandler()->ProcessEvent (event);
             }
@@ -2061,7 +2071,7 @@ static void wxCanvasInputEvent(Widget drawingArea,
         }
     case FocusIn:
         {
-            if (local_event.xfocus.detail != NotifyPointer)
+            if (xevent->xfocus.detail != NotifyPointer)
             {
                 wxFocusEvent event(wxEVT_SET_FOCUS, canvas->GetId());
                 event.SetEventObject(canvas);
@@ -2071,7 +2081,7 @@ static void wxCanvasInputEvent(Widget drawingArea,
         }
     case FocusOut:
         {
-            if (local_event.xfocus.detail != NotifyPointer)
+            if (xevent->xfocus.detail != NotifyPointer)
             {
                 wxFocusEvent event(wxEVT_KILL_FOCUS, canvas->GetId());
                 event.SetEventObject(canvas);
@@ -2211,7 +2221,7 @@ void wxUniversalRepaintProc(Widget w, XtPointer WXUNUSED(c_data), XEvent *event,
 // ----------------------------------------------------------------------------
 
 bool wxTranslateMouseEvent(wxMouseEvent& wxevent, wxWindow *win,
-                           Widget widget, XEvent *xevent)
+                           Widget widget, const XEvent *xevent)
 {
     switch (xevent->xany.type)
     {
@@ -2226,6 +2236,8 @@ bool wxTranslateMouseEvent(wxMouseEvent& wxevent, wxWindow *win,
         case ButtonRelease:
         case MotionNotify:
         {
+            int eventx = xevent->xbutton.x, eventy = xevent->xbutton.y;
+
             wxEventType eventType = wxEVT_NULL;
 
             if (xevent->xany.type == LeaveNotify)
@@ -2239,6 +2251,18 @@ bool wxTranslateMouseEvent(wxMouseEvent& wxevent, wxWindow *win,
             else if (xevent->xany.type == MotionNotify)
             {
                 eventType = wxEVT_MOTION;
+
+                if (xevent->xmotion.is_hint == NotifyHint)
+                {
+                    Window root, child;
+                    int x_root, y_root;
+                    unsigned int state;
+                    Display *dpy = XtDisplay (widget);
+
+                    XQueryPointer (dpy, XtWindow (widget),
+                        &root, &child,
+                        &x_root, &y_root, &eventx, &eventy, &state);
+                }
             }
             else if (xevent->xany.type == ButtonPress)
             {
@@ -2315,7 +2339,7 @@ bool wxTranslateMouseEvent(wxMouseEvent& wxevent, wxWindow *win,
             int x2, y2;
             win->GetPosition(&x2, &y2);
 
-            // The button x/y must be translated to wxWindows
+            // The button x/y must be translated to wxWidgets
             // window space - the widget might be a label or button,
             // within a form.
             int dx = 0;
@@ -2326,8 +2350,8 @@ bool wxTranslateMouseEvent(wxMouseEvent& wxevent, wxWindow *win,
                 dy = y1;
             }
 
-            wxevent.m_x = xevent->xbutton.x + dx;
-            wxevent.m_y = xevent->xbutton.y + dy;
+            wxevent.m_x = eventx + dx;
+            wxevent.m_y = eventy + dy;
 
             wxevent.m_leftDown = ((eventType == wxEVT_LEFT_DOWN)
                 || (event_left_is_down (xevent)
@@ -2354,7 +2378,7 @@ bool wxTranslateMouseEvent(wxMouseEvent& wxevent, wxWindow *win,
 }
 
 bool wxTranslateKeyEvent(wxKeyEvent& wxevent, wxWindow *win,
-                         Widget WXUNUSED(widget), XEvent *xevent)
+                         Widget WXUNUSED(widget), const XEvent *xevent)
 {
     switch (xevent->xany.type)
     {