]> git.saurik.com Git - wxWidgets.git/blobdiff - src/x11/app.cpp
Implemented two-window approach for pop-ups, since
[wxWidgets.git] / src / x11 / app.cpp
index 56b32f21aa1b0f9be3b882b36d7ccb0899c833f6..2de877dd5cc5d4dee34ad2354aaa8511500e46f5 100644 (file)
@@ -25,6 +25,7 @@
 #include "wx/log.h"
 #include "wx/intl.h"
 #include "wx/evtloop.h"
+#include "wx/timer.h"
 
 #include "wx/univ/theme.h"
 #include "wx/univ/renderer.h"
@@ -48,6 +49,7 @@
 extern wxList wxPendingDelete;
 
 wxHashTable *wxWidgetHashTable = NULL;
+wxHashTable *wxClientWidgetHashTable = NULL;
 
 wxApp *wxTheApp = NULL;
 
@@ -118,6 +120,7 @@ bool wxApp::Initialize()
 #endif
 
     wxWidgetHashTable = new wxHashTable(wxKEY_INTEGER);
+    wxClientWidgetHashTable = new wxHashTable(wxKEY_INTEGER);
 
     wxModule::RegisterModules();
     if (!wxModule::InitializeModules()) return FALSE;
@@ -133,6 +136,8 @@ void wxApp::CleanUp()
 
     delete wxWidgetHashTable;
     wxWidgetHashTable = NULL;
+    delete wxClientWidgetHashTable;
+    wxClientWidgetHashTable = NULL;
 
     wxModule::CleanUpModules();
 
@@ -144,7 +149,7 @@ void wxApp::CleanUp()
     wxTheColourDatabase = NULL;
 
     wxDeleteStockObjects();
-    
+
     wxDeleteStockLists();
 
     delete wxTheApp;
@@ -259,11 +264,11 @@ int wxEntryStart( int& argc, char *argv[] )
     {
         XSynchronize(xdisplay, True);
     }
-    
+
     wxApp::ms_display = (WXDisplay*) xdisplay;
-    
+
     XSelectInput( xdisplay, XDefaultRootWindow(xdisplay), PropertyChangeMask);
-        
+
     wxSetDetectableAutoRepeat( TRUE );
 
     if (!wxApp::Initialize())
@@ -427,22 +432,22 @@ struct wxExposeInfo
 static Bool expose_predicate (Display *display, XEvent *xevent, XPointer arg)
 {
     wxExposeInfo *info = (wxExposeInfo*) arg;
-    
+
     if (info->found_non_matching)
        return FALSE;
-    
+
     if (xevent->xany.type != Expose)
     {
         info->found_non_matching = TRUE;
         return FALSE;
     }
-    
+
     if (xevent->xexpose.window != info->window)
     {
         info->found_non_matching = TRUE;
         return FALSE;
     }
-    
+
     return TRUE;
 }
 #endif
@@ -458,7 +463,9 @@ bool wxApp::ProcessXEvent(WXEvent* _event)
 
     wxWindow* win = NULL;
     Window window = XEventGetWindow(event);
+#if 0
     Window actualWindow = window;
+#endif
 
     // Find the first wxWindow that corresponds to this event window
     // Because we're receiving events after a window
@@ -468,14 +475,100 @@ bool wxApp::ProcessXEvent(WXEvent* _event)
 
     win = wxGetWindowFromTable(window);
     if (!win)
-        return FALSE;
+    {
+#if wxUSE_TWO_WINDOWS
+        win = wxGetClientWindowFromTable(window);
+        if (!win)
+#endif
+            return FALSE;
+    }
 
 #ifdef __WXDEBUG__
     wxString windowClass = win->GetClassInfo()->GetClassName();
 #endif
-    
+
     switch (event->type)
     {
+        case Expose:
+        {
+#if wxUSE_TWO_WINDOWS
+            if (event->xexpose.window != (Window)win->GetClientWindow())
+            {
+                XEvent tmp_event;
+                wxExposeInfo info;
+                info.window = event->xexpose.window;
+                info.found_non_matching = FALSE;
+                while (XCheckIfEvent( wxGlobalDisplay(), &tmp_event, expose_predicate, (XPointer) &info ))
+                {
+                    // Don't worry about optimizing redrawing the border etc.
+                }
+                win->NeedUpdateNcAreaInIdle();
+            }
+            else
+#endif
+            {
+                win->GetUpdateRegion().Union( XExposeEventGetX(event), XExposeEventGetY(event),
+                                              XExposeEventGetWidth(event), XExposeEventGetHeight(event));
+                win->GetClearRegion().Union( XExposeEventGetX(event), XExposeEventGetY(event),
+                                         XExposeEventGetWidth(event), XExposeEventGetHeight(event));
+
+#if !wxUSE_NANOX
+                XEvent tmp_event;
+                wxExposeInfo info;
+                info.window = event->xexpose.window;
+                info.found_non_matching = FALSE;
+                while (XCheckIfEvent( wxGlobalDisplay(), &tmp_event, expose_predicate, (XPointer) &info ))
+                {
+                    win->GetUpdateRegion().Union( tmp_event.xexpose.x, tmp_event.xexpose.y,
+                                                  tmp_event.xexpose.width, tmp_event.xexpose.height );
+
+                    win->GetClearRegion().Union( tmp_event.xexpose.x, tmp_event.xexpose.y,
+                                                 tmp_event.xexpose.width, tmp_event.xexpose.height );
+                }
+#endif
+
+                // This simplifies the expose and clear areas to simple
+                // rectangles.
+                win->GetUpdateRegion() = win->GetUpdateRegion().GetBox();
+                win->GetClearRegion() = win->GetClearRegion().GetBox();
+
+                // If we only have one X11 window, always indicate
+                // that borders might have to be redrawn.
+                if (win->GetMainWindow() == win->GetClientWindow())
+                    win->NeedUpdateNcAreaInIdle();
+
+                // Only erase background, paint in idle time.
+                win->SendEraseEvents();
+                // win->Update();
+            }
+
+            return TRUE;
+        }
+
+#if !wxUSE_NANOX
+        case GraphicsExpose:
+        {
+            // wxLogDebug( "GraphicsExpose from %s", win->GetName().c_str(),
+            //                              event->xgraphicsexpose.x, event->xgraphicsexpose.y,
+            //                              event->xgraphicsexpose.width, event->xgraphicsexpose.height);
+
+            win->GetUpdateRegion().Union( event->xgraphicsexpose.x, event->xgraphicsexpose.y,
+                                          event->xgraphicsexpose.width, event->xgraphicsexpose.height);
+
+            win->GetClearRegion().Union( event->xgraphicsexpose.x, event->xgraphicsexpose.y,
+                                         event->xgraphicsexpose.width, event->xgraphicsexpose.height);
+
+            if (event->xgraphicsexpose.count == 0)
+            {
+                // Only erase background, paint in idle time.
+                win->SendEraseEvents();
+                // win->Update();
+            }
+
+            return TRUE;
+        }
+#endif
+
         case KeyPress:
         {
             if (!win->IsEnabled())
@@ -483,17 +576,17 @@ bool wxApp::ProcessXEvent(WXEvent* _event)
 
             wxKeyEvent keyEvent(wxEVT_KEY_DOWN);
             wxTranslateKeyEvent(keyEvent, win, window, event);
-                    
+
             // wxLogDebug( "OnKey from %s", win->GetName().c_str() );
-        
+
             // We didn't process wxEVT_KEY_DOWN, so send wxEVT_CHAR
             if (win->GetEventHandler()->ProcessEvent( keyEvent ))
                 return TRUE;
-                
+
             keyEvent.SetEventType(wxEVT_CHAR);
             if (win->GetEventHandler()->ProcessEvent( keyEvent ))
                 return TRUE;
-            
+
             if ( (keyEvent.m_keyCode == WXK_TAB) &&
                  win->GetParent() && (win->GetParent()->HasFlag( wxTAB_TRAVERSAL)) )
             {
@@ -516,7 +609,7 @@ bool wxApp::ProcessXEvent(WXEvent* _event)
 
             wxKeyEvent keyEvent(wxEVT_KEY_UP);
             wxTranslateKeyEvent(keyEvent, win, window, event);
-        
+
             return win->GetEventHandler()->ProcessEvent( keyEvent );
         }
         case ConfigureNotify:
@@ -525,11 +618,25 @@ bool wxApp::ProcessXEvent(WXEvent* _event)
             if (event->update.utype == GR_UPDATE_SIZE)
 #endif
             {
-                //wxLogDebug("ConfigureNotify: %s", windowClass.c_str());
-                wxSizeEvent sizeEvent( wxSize(XConfigureEventGetWidth(event), XConfigureEventGetHeight(event)), win->GetId() );
-                sizeEvent.SetEventObject( win );
-                
-                return win->GetEventHandler()->ProcessEvent( sizeEvent );
+                if (win->IsTopLevel())
+                {
+                    wxTopLevelWindow *tlw = (wxTopLevelWindow*) win;
+                    tlw->SetConfigureGeometry( XConfigureEventGetX(event), XConfigureEventGetY(event),
+                        XConfigureEventGetWidth(event), XConfigureEventGetHeight(event) );
+                }
+
+                if (win->IsTopLevel() && win->IsShown())
+                {
+                    wxTopLevelWindowX11 *tlw = (wxTopLevelWindowX11 *) win;
+                    tlw->SetNeedResizeInIdle();
+                }
+                else
+                {
+                    wxSizeEvent sizeEvent( wxSize(XConfigureEventGetWidth(event), XConfigureEventGetHeight(event)), win->GetId() );
+                    sizeEvent.SetEventObject( win );
+
+                    return win->GetEventHandler()->ProcessEvent( sizeEvent );
+                }
             }
             return FALSE;
             break;
@@ -558,21 +665,33 @@ bool wxApp::ProcessXEvent(WXEvent* _event)
             }
             return FALSE;
         }
-#if 1
+#if 0
+        case DestroyNotify:
+        {
+            printf( "destroy from %s\n", win->GetName().c_str() );
+            break;
+        }
+        case CreateNotify:
+        {
+            printf( "create from %s\n", win->GetName().c_str() );
+            break;
+        }
+        case MapRequest:
+        {
+            printf( "map request from %s\n", win->GetName().c_str() );
+            break;
+        }
         case ResizeRequest:
         {
-            /*
-            * If resize event, don't resize until the last resize event for this
-            * window is recieved. Prevents flicker as windows are resized.
-            */
-        
+            printf( "resize request from %s\n", win->GetName().c_str() );
+
             Display *disp = (Display*) wxGetDisplay();
             XEvent report;
-            
+
             //  to avoid flicker
             report = * event;
             while( XCheckTypedWindowEvent (disp, actualWindow, ResizeRequest, &report));
-            
+
             wxSize sz = win->GetSize();
             wxSizeEvent sizeEvent(sz, win->GetId());
             sizeEvent.SetEventObject(win);
@@ -592,58 +711,6 @@ bool wxApp::ProcessXEvent(WXEvent* _event)
             return FALSE;
             break;
         }
-#endif
-        case Expose:
-        {
-            //wxLogDebug("Expose: %s", windowClass.c_str());
-            win->GetUpdateRegion().Union( XExposeEventGetX(event), XExposeEventGetY(event),
-                                          XExposeEventGetWidth(event), XExposeEventGetHeight(event));
-                                              
-            win->GetClearRegion().Union( XExposeEventGetX(event), XExposeEventGetY(event),
-                                         XExposeEventGetWidth(event), XExposeEventGetHeight(event));
-                                              
-
-#if !wxUSE_NANOX
-            XEvent tmp_event;
-            wxExposeInfo info;
-            info.window = event->xexpose.window;
-            info.found_non_matching = FALSE;
-            while (XCheckIfEvent( wxGlobalDisplay(), &tmp_event, expose_predicate, (XPointer) &info ))
-            {
-                win->GetUpdateRegion().Union( tmp_event.xexpose.x, tmp_event.xexpose.y,
-                                              tmp_event.xexpose.width, tmp_event.xexpose.height );
-                                              
-                win->GetClearRegion().Union( tmp_event.xexpose.x, tmp_event.xexpose.y,
-                                             tmp_event.xexpose.width, tmp_event.xexpose.height );
-            }
-#endif
-
-            // Only erase background, paint in idle time.
-            win->SendEraseEvents();
-
-            return TRUE;
-        }
-#if !wxUSE_NANOX
-        case GraphicsExpose:
-        {
-            // wxLogDebug( "GraphicsExpose from %s", win->GetName().c_str(),
-            //                              event->xgraphicsexpose.x, event->xgraphicsexpose.y,
-            //                              event->xgraphicsexpose.width, event->xgraphicsexpose.height);
-                    
-            win->GetUpdateRegion().Union( event->xgraphicsexpose.x, event->xgraphicsexpose.y,
-                                          event->xgraphicsexpose.width, event->xgraphicsexpose.height);
-                                             
-            win->GetClearRegion().Union( event->xgraphicsexpose.x, event->xgraphicsexpose.y,
-                                         event->xgraphicsexpose.width, event->xgraphicsexpose.height);
-                                              
-            if (event->xgraphicsexpose.count == 0)
-            {
-                // Only erase background, paint in idle time.
-                win->SendEraseEvents();
-            }
-
-            return TRUE;
-        }
 #endif
         case EnterNotify:
         case LeaveNotify:
@@ -653,7 +720,7 @@ bool wxApp::ProcessXEvent(WXEvent* _event)
         {
             if (!win->IsEnabled())
                 return FALSE;
-                
+
             // Here we check if the top level window is
             // disabled, which is one aspect of modality.
             wxWindow *tlw = win;
@@ -661,7 +728,7 @@ bool wxApp::ProcessXEvent(WXEvent* _event)
                 tlw = tlw->GetParent();
             if (tlw && !tlw->IsEnabled())
                 return FALSE;
-                
+
             if (event->type == ButtonPress)
             {
                 if ((win != wxWindow::FindFocus()) && win->AcceptsFocus())
@@ -670,11 +737,11 @@ bool wxApp::ProcessXEvent(WXEvent* _event)
                     // and not here. TODO.
                     g_prevFocus = wxWindow::FindFocus();
                     g_nextFocus = win;
-                    
+
                     win->SetFocus();
                 }
             }
-            
+
 #if !wxUSE_NANOX
             if (event->type == LeaveNotify || event->type == EnterNotify)
             {
@@ -695,12 +762,12 @@ bool wxApp::ProcessXEvent(WXEvent* _event)
 #endif
                 {
                     // wxLogDebug( "FocusIn from %s of type %s", win->GetName().c_str(), win->GetClassInfo()->GetClassName() );
-                    
+
                     wxFocusEvent focusEvent(wxEVT_SET_FOCUS, win->GetId());
                     focusEvent.SetEventObject(win);
                     focusEvent.SetWindow( g_prevFocus );
                     g_prevFocus = NULL;
-                    
+
                     return win->GetEventHandler()->ProcessEvent(focusEvent);
                 }
                 return FALSE;
@@ -714,7 +781,7 @@ bool wxApp::ProcessXEvent(WXEvent* _event)
 #endif
                 {
                     // wxLogDebug( "FocusOut from %s of type %s", win->GetName().c_str(), win->GetClassInfo()->GetClassName() );
-                    
+
                     wxFocusEvent focusEvent(wxEVT_KILL_FOCUS, win->GetId());
                     focusEvent.SetEventObject(win);
                     focusEvent.SetWindow( g_nextFocus );
@@ -724,15 +791,6 @@ bool wxApp::ProcessXEvent(WXEvent* _event)
                 return FALSE;
                 break;
             }
-#ifndef wxUSE_NANOX
-         case DestroyNotify:
-            {
-                // Do we want to process this (for top-level windows)?
-                // But we want to be able to veto closes, anyway
-                return FALSE;
-                break;
-            }
-#endif
         default:
         {
 #ifdef __WXDEBUG__
@@ -860,7 +918,7 @@ bool wxApp::SendIdleEvents(wxWindow* win)
 
         node = node->Next();
     }
-    
+
     return needMore;
 }
 
@@ -889,10 +947,10 @@ bool wxApp::OnInitGui()
     // now we don't want to try popping up a dialog
     // for error messages.
     delete wxLog::SetActiveTarget(new wxLogStderr);
-    
+
     if (!wxAppBase::OnInitGui())
     return FALSE;
-    
+
     GetMainColormap( wxApp::GetDisplay() );
 
     m_maxRequestSize = XMaxRequestSize( (Display*) wxApp::GetDisplay() );
@@ -919,7 +977,7 @@ WXColormap wxApp::GetMainColormap(WXDisplay* display)
 Window wxGetWindowParent(Window window)
 {
     wxASSERT_MSG( window, "invalid window" );
-    
+
     return (Window) 0;
 
     Window parent, root = 0;
@@ -977,24 +1035,40 @@ bool wxApp::Yield(bool onlyIfNeeded)
 
     s_inYield = TRUE;
 
+    // Make sure we have an event loop object,
+    // or Pending/Dispatch will fail
+    wxEventLoop* eventLoop = wxEventLoop::GetActive();
+    wxEventLoop* newEventLoop = NULL;
+    if (!eventLoop)
+    {
+        newEventLoop = new wxEventLoop;
+        wxEventLoop::SetActive(newEventLoop);
+    }
+
     while (wxTheApp && wxTheApp->Pending())
         wxTheApp->Dispatch();
 
+#if wxUSE_TIMER
+    wxTimer::NotifyTimers();
+#endif
+    ProcessIdle();
+
+    if (newEventLoop)
+    {
+        wxEventLoop::SetActive(NULL);
+        delete newEventLoop;
+    }
+
     s_inYield = FALSE;
 
     return TRUE;
 }
 
-wxIcon wxApp::GetStdIcon(int which) const
-{
-    return wxTheme::Get()->GetRenderer()->GetStdIcon(which);
-}
-
 void wxApp::OnAssert(const wxChar *file, int line, const wxChar *msg)
 {
     // While the GUI isn't working that well, just print out the
     // message.
-#if 0    
+#if 0
     wxAppBase::OnAssert(file, line, msg);
 #else
     wxString msg2;