]> git.saurik.com Git - wxWidgets.git/blobdiff - src/x11/app.cpp
wxX11:
[wxWidgets.git] / src / x11 / app.cpp
index ef1b07b838980c49a83fc3c76cbe70740d61724e..e06786959fcc5808f3f45a089be4cbc946a1ea5c 100644 (file)
@@ -21,8 +21,6 @@
 #include "wx/brush.h"
 #include "wx/cursor.h"
 #include "wx/icon.h"
-#include "wx/palette.h"
-#include "wx/dc.h"
 #include "wx/dialog.h"
 #include "wx/msgdlg.h"
 #include "wx/log.h"
@@ -62,6 +60,8 @@ wxApp *wxTheApp = NULL;
 
 wxHashTable *wxWidgetHashTable = NULL;
 
+static Window wxGetParentWindow(Window window);
+
 IMPLEMENT_DYNAMIC_CLASS(wxApp, wxEvtHandler)
 
 BEGIN_EVENT_TABLE(wxApp, wxEvtHandler)
@@ -296,7 +296,7 @@ void wxApp::ProcessXEvent(WXEvent* _event)
     // TODO: may need to translate coordinates from actualWindow
     // to window, if the receiving window != wxWindow window
     while (window && !(win = wxGetWindowFromTable(window)))
-        window = XGetParent(window);
+        window = wxGetParentWindow(window);
 
     // TODO: shouldn't all the ProcessEvents below
     // be win->GetEventHandler()->ProcessEvent?
@@ -304,6 +304,9 @@ void wxApp::ProcessXEvent(WXEvent* _event)
     {
         case KeyPress:
         {
+            if (win && !win->IsEnabled())
+                return;
+
             if (CheckForAccelerator(_event))
             {
                 // Do nothing! We intercepted and processed the event as an
@@ -315,14 +318,14 @@ void wxApp::ProcessXEvent(WXEvent* _event)
                 if (win)
                 {
                     wxKeyEvent keyEvent(wxEVT_KEY_DOWN);
-                    wxTranslateKeyEvent(keyEvent, win, window, xEvent);
+                    wxTranslateKeyEvent(keyEvent, win, window, event);
         
                     // We didn't process wxEVT_KEY_DOWN, so send
-                    // wxEVT_KEY_CHAR
-                    if (!win->ProcessEvent( keyEvent ))
+                    // wxEVT_CHAR
+                    if (!win->GetEventHandler()->ProcessEvent( keyEvent ))
                     {
-                        keyEvent.SetEventType(wxEVT_KEY_CHAR);
-                        win->ProcessEvent( keyEvent );
+                        keyEvent.SetEventType(wxEVT_CHAR);
+                        win->GetEventHandler()->ProcessEvent( keyEvent );
                     }
 
                     // We intercepted and processed the key down event
@@ -333,12 +336,15 @@ void wxApp::ProcessXEvent(WXEvent* _event)
         }
         case KeyRelease:
         {
+            if (win && !win->IsEnabled())
+                return;
+
             if (win)
             {
                 wxKeyEvent keyEvent(wxEVT_KEY_UP);
                 wxTranslateKeyEvent(keyEvent, win, window, event);
         
-                win->ProcessEvent( keyEvent );
+                win->GetEventHandler()->ProcessEvent( keyEvent );
             }
             return;
         }
@@ -347,6 +353,23 @@ void wxApp::ProcessXEvent(WXEvent* _event)
             HandlePropertyChange(_event);
             return;
         }
+        case ClientMessage:
+        {           
+            Atom wm_delete_window = XInternAtom(wxGlobalDisplay(), "WM_DELETE_WINDOW", True);;
+            Atom wm_protocols = XInternAtom(wxGlobalDisplay(), "WM_PROTOCOLS", True);;
+
+            if (event->xclient.message_type == wm_protocols)
+            {
+                if (event->xclient.data.l[0] == wm_delete_window)
+                {
+                    if (win)
+                    {
+                        win->Close(FALSE);
+                    }
+                }
+            }
+            return;
+        }
         case ResizeRequest:
         {
             /* Terry Gitnick <terryg@scientech.com> - 1/21/98
@@ -354,7 +377,7 @@ void wxApp::ProcessXEvent(WXEvent* _event)
             * window is recieved. Prevents flicker as windows are resized.
             */
         
-            Display *disp = wxGetDisplay();
+            Display *disp = (Display*) wxGetDisplay();
             XEvent report;
             
             //  to avoid flicker
@@ -370,7 +393,7 @@ void wxApp::ProcessXEvent(WXEvent* _event)
                 wxSizeEvent sizeEvent(sz, win->GetId());
                 sizeEvent.SetEventObject(win);
 
-                win->ProcessEvent( wxevent );
+                win->GetEventHandler()->ProcessEvent( sizeEvent );
             }
 
             return;
@@ -379,13 +402,11 @@ void wxApp::ProcessXEvent(WXEvent* _event)
         {
             if (win)
             {
-                win->AddUpdateRect(event->xexpose.x, event->xexpose.y,
-                               event->xexpose.width, event->xexpose.height);
-            
-                if (event -> xexpose.count == 0)
+                win->GetUpdateRegion().Union( event->xexpose.x, event->xexpose.y,
+                                              event->xexpose.width, event->xexpose.height);
+                if (event->xexpose.count == 0)
                 {
-                    win->DoPaint();
-                    win->ClearUpdateRects();
+                    win->X11SendPaintEvents();  // TODO let an idle handler do that
                 }
             }
 
@@ -397,11 +418,14 @@ void wxApp::ProcessXEvent(WXEvent* _event)
         case ButtonRelease:
         case MotionNotify:
         {
+            if (win && !win->IsEnabled())
+                return;
+
             if (win)
             {
                 wxMouseEvent wxevent;
                 wxTranslateMouseEvent(wxevent, win, window, event);
-                win->ProcessEvent( wxevent );
+                win->GetEventHandler()->ProcessEvent( wxevent );
             }
             return;
         }
@@ -411,7 +435,7 @@ void wxApp::ProcessXEvent(WXEvent* _event)
                 {
                     wxFocusEvent focusEvent(wxEVT_SET_FOCUS, win->GetId());
                     focusEvent.SetEventObject(win);
-                    win->ProcessEvent(focusEvent);
+                    win->GetEventHandler()->ProcessEvent(focusEvent);
                 }
                 break;
             }
@@ -421,10 +445,16 @@ void wxApp::ProcessXEvent(WXEvent* _event)
                 {
                     wxFocusEvent focusEvent(wxEVT_KILL_FOCUS, win->GetId());
                     focusEvent.SetEventObject(win);
-                    win->ProcessEvent(focusEvent);
+                    win->GetEventHandler()->ProcessEvent(focusEvent);
                 }
                 break;
             }
+        case DestroyNotify:
+            {
+                // Do we want to process this (for top-level windows)?
+                // But we want to be able to veto closes, anyway
+                break;
+            }
         default:
         {
             break;
@@ -589,8 +619,8 @@ bool wxApp::OnInitGui()
             (const char*) className);
         exit(-1);
     }
-    XSelectInput(m_initialDisplay,
-        XDefaultRootWindow(m_initialDisplay),
+    XSelectInput((Display*) m_initialDisplay,
+        XDefaultRootWindow((Display*) m_initialDisplay),
         PropertyChangeMask);
 
 #ifdef __WXDEBUG__
@@ -620,11 +650,11 @@ WXColormap wxApp::GetMainColormap(WXDisplay* display)
     return (WXColormap) c;
 }
 
-static Window XGetParent(Window window)
+Window wxGetParentWindow(Window window)
 {
     Window parent, root = 0;
     unsigned int noChildren = 0;
-    if (XQueryTree(wxGetDisplay(), window, & root, & parent,
+    if (XQueryTree((Display*) wxGetDisplay(), window, & root, & parent,
         NULL, & noChildren))
         return parent;
     else
@@ -644,7 +674,7 @@ bool wxApp::CheckForAccelerator(WXEvent* event)
 
         // Find the first wxWindow that corresponds to this event window
         while (window && !(win = wxGetWindowFromTable(window)))
-            window = XGetParent(window);
+            window = wxGetWindowParent(window);
 
         if (!window || !win)
             return FALSE;
@@ -750,4 +780,4 @@ extern "C" XtAppContext wxGetAppContext()
 {
     return (XtAppContext)wxTheApp->GetAppContext();
 }
-#endif
\ No newline at end of file
+#endif