]> git.saurik.com Git - wxWidgets.git/blobdiff - src/x11/app.cpp
honour min/max size in wxMGL's wxWindow::DoSetSize
[wxWidgets.git] / src / x11 / app.cpp
index c20d365ad58b22d31f4c369d338377fd72fee508..ebcb2d9da1ce6ffc6571bc4ffe9246d85126cda2 100644 (file)
@@ -21,8 +21,6 @@
 #include "wx/brush.h"
 #include "wx/cursor.h"
 #include "wx/icon.h"
 #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"
 #include "wx/dialog.h"
 #include "wx/msgdlg.h"
 #include "wx/log.h"
@@ -62,6 +60,8 @@ wxApp *wxTheApp = NULL;
 
 wxHashTable *wxWidgetHashTable = NULL;
 
 
 wxHashTable *wxWidgetHashTable = NULL;
 
+static Window wxGetParentWindow(Window window);
+
 IMPLEMENT_DYNAMIC_CLASS(wxApp, wxEvtHandler)
 
 BEGIN_EVENT_TABLE(wxApp, wxEvtHandler)
 IMPLEMENT_DYNAMIC_CLASS(wxApp, wxEvtHandler)
 
 BEGIN_EVENT_TABLE(wxApp, wxEvtHandler)
@@ -73,8 +73,6 @@ typedef int (*XErrorHandlerFunc)(Display *, XErrorEvent *);
 
 XErrorHandlerFunc gs_pfnXErrorHandler = 0;
 
 
 XErrorHandlerFunc gs_pfnXErrorHandler = 0;
 
-static Window XGetParent(Window window);
-
 static int wxXErrorHandler(Display *dpy, XErrorEvent *xevent)
 {
     // just forward to the default handler for now
 static int wxXErrorHandler(Display *dpy, XErrorEvent *xevent)
 {
     // just forward to the default handler for now
@@ -298,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)))
     // 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?
 
     // TODO: shouldn't all the ProcessEvents below
     // be win->GetEventHandler()->ProcessEvent?
@@ -306,13 +304,9 @@ void wxApp::ProcessXEvent(WXEvent* _event)
     {
         case KeyPress:
         {
     {
         case KeyPress:
         {
-            if (CheckForAccelerator(_event))
-            {
-                // Do nothing! We intercepted and processed the event as an
-                // accelerator.
+            if (win && !win->IsEnabled())
                 return;
                 return;
-            }
-            else
+
             {
                 if (win)
                 {
             {
                 if (win)
                 {
@@ -321,10 +315,10 @@ void wxApp::ProcessXEvent(WXEvent* _event)
         
                     // We didn't process wxEVT_KEY_DOWN, so send
                     // wxEVT_CHAR
         
                     // We didn't process wxEVT_KEY_DOWN, so send
                     // wxEVT_CHAR
-                    if (!win->ProcessEvent( keyEvent ))
+                    if (!win->GetEventHandler()->ProcessEvent( keyEvent ))
                     {
                         keyEvent.SetEventType(wxEVT_CHAR);
                     {
                         keyEvent.SetEventType(wxEVT_CHAR);
-                        win->ProcessEvent( keyEvent );
+                        win->GetEventHandler()->ProcessEvent( keyEvent );
                     }
 
                     // We intercepted and processed the key down event
                     }
 
                     // We intercepted and processed the key down event
@@ -335,12 +329,15 @@ void wxApp::ProcessXEvent(WXEvent* _event)
         }
         case KeyRelease:
         {
         }
         case KeyRelease:
         {
+            if (win && !win->IsEnabled())
+                return;
+
             if (win)
             {
                 wxKeyEvent keyEvent(wxEVT_KEY_UP);
                 wxTranslateKeyEvent(keyEvent, win, window, event);
         
             if (win)
             {
                 wxKeyEvent keyEvent(wxEVT_KEY_UP);
                 wxTranslateKeyEvent(keyEvent, win, window, event);
         
-                win->ProcessEvent( keyEvent );
+                win->GetEventHandler()->ProcessEvent( keyEvent );
             }
             return;
         }
             }
             return;
         }
@@ -349,6 +346,23 @@ void wxApp::ProcessXEvent(WXEvent* _event)
             HandlePropertyChange(_event);
             return;
         }
             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
         case ResizeRequest:
         {
             /* Terry Gitnick <terryg@scientech.com> - 1/21/98
@@ -372,7 +386,7 @@ void wxApp::ProcessXEvent(WXEvent* _event)
                 wxSizeEvent sizeEvent(sz, win->GetId());
                 sizeEvent.SetEventObject(win);
 
                 wxSizeEvent sizeEvent(sz, win->GetId());
                 sizeEvent.SetEventObject(win);
 
-                win->ProcessEvent( sizeEvent );
+                win->GetEventHandler()->ProcessEvent( sizeEvent );
             }
 
             return;
             }
 
             return;
@@ -381,13 +395,11 @@ void wxApp::ProcessXEvent(WXEvent* _event)
         {
             if (win)
             {
         {
             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
                 }
             }
 
                 }
             }
 
@@ -399,11 +411,14 @@ void wxApp::ProcessXEvent(WXEvent* _event)
         case ButtonRelease:
         case MotionNotify:
         {
         case ButtonRelease:
         case MotionNotify:
         {
+            if (win && !win->IsEnabled())
+                return;
+
             if (win)
             {
                 wxMouseEvent wxevent;
                 wxTranslateMouseEvent(wxevent, win, window, event);
             if (win)
             {
                 wxMouseEvent wxevent;
                 wxTranslateMouseEvent(wxevent, win, window, event);
-                win->ProcessEvent( wxevent );
+                win->GetEventHandler()->ProcessEvent( wxevent );
             }
             return;
         }
             }
             return;
         }
@@ -413,7 +428,7 @@ void wxApp::ProcessXEvent(WXEvent* _event)
                 {
                     wxFocusEvent focusEvent(wxEVT_SET_FOCUS, win->GetId());
                     focusEvent.SetEventObject(win);
                 {
                     wxFocusEvent focusEvent(wxEVT_SET_FOCUS, win->GetId());
                     focusEvent.SetEventObject(win);
-                    win->ProcessEvent(focusEvent);
+                    win->GetEventHandler()->ProcessEvent(focusEvent);
                 }
                 break;
             }
                 }
                 break;
             }
@@ -423,10 +438,16 @@ void wxApp::ProcessXEvent(WXEvent* _event)
                 {
                     wxFocusEvent focusEvent(wxEVT_KILL_FOCUS, win->GetId());
                     focusEvent.SetEventObject(win);
                 {
                     wxFocusEvent focusEvent(wxEVT_KILL_FOCUS, win->GetId());
                     focusEvent.SetEventObject(win);
-                    win->ProcessEvent(focusEvent);
+                    win->GetEventHandler()->ProcessEvent(focusEvent);
                 }
                 break;
             }
                 }
                 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;
         default:
         {
             break;
@@ -622,7 +643,7 @@ WXColormap wxApp::GetMainColormap(WXDisplay* display)
     return (WXColormap) c;
 }
 
     return (WXColormap) c;
 }
 
-static Window XGetParent(Window window)
+Window wxGetParentWindow(Window window)
 {
     Window parent, root = 0;
     unsigned int noChildren = 0;
 {
     Window parent, root = 0;
     unsigned int noChildren = 0;
@@ -633,41 +654,6 @@ static Window XGetParent(Window window)
         return (Window) 0;
 }
 
         return (Window) 0;
 }
 
-// Returns TRUE if an accelerator has been processed
-bool wxApp::CheckForAccelerator(WXEvent* event)
-{
-    XEvent* xEvent = (XEvent*) event;
-    if (xEvent->xany.type == KeyPress)
-    {
-        // Find a wxWindow for this window
-        // TODO: should get display for the window, not the current display
-        Window window = xEvent->xany.window;
-        wxWindow* win = NULL;
-
-        // Find the first wxWindow that corresponds to this event window
-        while (window && !(win = wxGetWindowFromTable(window)))
-            window = XGetParent(window);
-
-        if (!window || !win)
-            return FALSE;
-
-        wxKeyEvent keyEvent(wxEVT_CHAR);
-        wxTranslateKeyEvent(keyEvent, win, (Window) 0, xEvent);
-
-        // Now we have a wxKeyEvent and we have a wxWindow.
-        // Go up the hierarchy until we find a matching accelerator,
-        // or we get to the top.
-        while (win)
-        {
-            if (win->ProcessAccelerator(keyEvent))
-                return TRUE;
-            win = win->GetParent();
-        }
-        return FALSE;
-    }
-    return FALSE;
-}
-
 void wxExit()
 {
     int retValue = 0;
 void wxExit()
 {
     int retValue = 0;