]> git.saurik.com Git - wxWidgets.git/blobdiff - src/dfb/toplevel.cpp
[ 1560860 ] wxComboCtrl EVT_TEXT filtering.
[wxWidgets.git] / src / dfb / toplevel.cpp
index 2a115daad182dabd3ba8b0fa806764ec86ead7be..db6224a74bbd9f481e1afadd5fa9596e680b66f9 100644 (file)
@@ -41,16 +41,36 @@ static wxDfbWindowsMap gs_dfbWindowsMap;
 
 struct wxDfbPaintRequest
 {
-    wxDfbPaintRequest(const wxRect& rect, bool eraseBackground)
-        : m_rect(rect), m_eraseBackground(eraseBackground) {}
-    wxDfbPaintRequest(const wxDfbPaintRequest& r)
-        : m_rect(r.m_rect), m_eraseBackground(r.m_eraseBackground) {}
+    wxDfbPaintRequest(const wxRect& rect) : m_rect(rect) {}
+    wxDfbPaintRequest(const wxDfbPaintRequest& r) : m_rect(r.m_rect) {}
 
     wxRect m_rect;
-    bool   m_eraseBackground;
 };
 
-WX_DEFINE_ARRAY_PTR(wxDfbPaintRequest*, wxDfbQueuedPaintRequests);
+WX_DEFINE_ARRAY_PTR(wxDfbPaintRequest*, wxDfbQueuedPaintRequestsList);
+
+// Queue of paint requests
+class wxDfbQueuedPaintRequests
+{
+public:
+    ~wxDfbQueuedPaintRequests() { Clear(); }
+
+    // Adds paint request to the queue
+    void Add(const wxRect& rect)
+        { m_queue.push_back(new wxDfbPaintRequest(rect)); }
+
+    // Is the queue empty?
+    bool IsEmpty() const { return m_queue.empty(); }
+
+    // Empties the queue
+    void Clear() { WX_CLEAR_ARRAY(m_queue); }
+
+    // Gets requests in the queue
+    const wxDfbQueuedPaintRequestsList& GetRequests() const { return m_queue; }
+
+private:
+    wxDfbQueuedPaintRequestsList m_queue;
+};
 
 // ============================================================================
 // wxTopLevelWindowDFB
@@ -68,6 +88,7 @@ void wxTopLevelWindowDFB::Init()
     m_sizeSet = false;
     m_opacity = 255;
     m_toPaint = new wxDfbQueuedPaintRequests;
+    m_isPainting = false;
 }
 
 bool wxTopLevelWindowDFB::Create(wxWindow *parent,
@@ -99,7 +120,7 @@ bool wxTopLevelWindowDFB::Create(wxWindow *parent,
         pos.y = 0;
 
     // create DirectFB window:
-    wxIDirectFBDisplayLayerPtr layer = wxDfbGetDisplayLayer();
+    wxIDirectFBDisplayLayerPtr layer(wxIDirectFB::Get()->GetDisplayLayer());
     wxCHECK_MSG( layer, false, _T("no display layer") );
 
     DFBWindowDescription desc;
@@ -125,7 +146,8 @@ bool wxTopLevelWindowDFB::Create(wxWindow *parent,
     if ( !m_dfbwin->SetOpacity(wxALPHA_TRANSPARENT) )
         return false;
 
-    wxWindow::Create(NULL, id, pos, size, style, name);
+    if ( !wxWindow::Create(NULL, id, pos, size, style, name) )
+        return false;
 
     SetParent(parent);
     if ( parent )
@@ -159,7 +181,6 @@ wxTopLevelWindowDFB::~wxTopLevelWindowDFB()
         wxTheApp->ExitMainLoop();
     }
 
-    WX_CLEAR_ARRAY(*m_toPaint);
     wxDELETE(m_toPaint);
 
     // remove the TLW from DFBWindowID->wxTLW map:
@@ -193,9 +214,14 @@ void wxTopLevelWindowDFB::DoMoveWindow(int x, int y, int width, int height)
     wxSize cursize = GetSize();
     if ( cursize.x != width || cursize.y != height )
     {
+        // changing window's size changes its surface:
+        InvalidateDfbSurface();
+
         m_dfbwin->Resize(width, height);
+
         // we must repaint the window after it changed size:
-        Refresh();
+        if ( IsShown() )
+            DoRefreshWindow();
     }
 }
 
@@ -254,10 +280,21 @@ bool wxTopLevelWindowDFB::Show(bool show)
         GetEventHandler()->ProcessEvent(event);
     }
 
-    // FIXME_DFB: do this at all?
-    if ( show && AcceptsFocus() )
-        SetFocus();
-        // FIXME_DFB -- don't do this for popup windows?
+    if ( show )
+    {
+        wxWindow *focused = wxWindow::FindFocus();
+        if ( focused && focused->GetTLW() == this )
+        {
+            SetDfbFocus();
+        }
+        else if ( AcceptsFocus() )
+        {
+            // FIXME: we should probably always call SetDfbFocus instead
+            // and call SetFocus() from wxActivateEvent/DWET_GOTFOCUS
+            // handler
+            SetFocus();
+        }
+    }
 
     return true;
 }
@@ -335,31 +372,48 @@ wxIDirectFBSurfacePtr wxTopLevelWindowDFB::ObtainDfbSurface() const
 
 void wxTopLevelWindowDFB::HandleQueuedPaintRequests()
 {
-    wxDfbQueuedPaintRequests& toPaint = *m_toPaint;
-    if ( toPaint.empty() )
+    if ( m_toPaint->IsEmpty() )
         return; // nothing to do
 
+    if ( IsFrozen() || !IsShown() )
+    {
+        // nothing to do if the window is frozen or hidden; clear the queue
+        // and return (note that it's OK to clear the queue even if the window
+        // is frozen, because Thaw() calls Refresh()):
+        m_toPaint->Clear();
+        return;
+    }
+
+    const wxDfbQueuedPaintRequestsList& requests = m_toPaint->GetRequests();
+
     // process queued paint requests:
     wxRect winRect(wxPoint(0, 0), GetSize());
     wxRect paintedRect;
 
-    size_t cnt = toPaint.size();
+    // important note: all DCs created from now until m_isPainting is reset to
+    // false will not update the front buffer as this flag indicates that we'll
+    // blit the entire back buffer to front soon
+    m_isPainting = true;
+
+    size_t cnt = requests.size();
+    wxLogTrace(TRACE_PAINT, _T("%p ('%s'): processing %i paint requests"),
+               this, GetName().c_str(), cnt);
+
     for ( size_t i = 0; i < cnt; ++i )
     {
-        const wxDfbPaintRequest& request = *toPaint[i];
+        const wxDfbPaintRequest& request = *requests[i];
 
         wxRect clipped(request.m_rect);
-
-        wxLogTrace(TRACE_PAINT,
-                   _T("%p ('%s'): processing paint request [x=%i,y=%i,w=%i,h=%i]"),
-                   this, GetName().c_str(),
-                   clipped.x, clipped.y, clipped.width, clipped.height);
-
         clipped.Intersect(winRect);
         if ( clipped.IsEmpty() )
             continue; // nothing to refresh
 
-        PaintWindow(clipped, request.m_eraseBackground);
+        wxLogTrace(TRACE_PAINT,
+                   _T("%p ('%s'): processing paint request [%i,%i,%i,%i]"),
+                   this, GetName().c_str(),
+                   clipped.x, clipped.y, clipped.GetRight(), clipped.GetBottom());
+
+        PaintWindow(clipped);
 
         // remember rectangle covering all repainted areas:
         if ( paintedRect.IsEmpty() )
@@ -368,23 +422,53 @@ void wxTopLevelWindowDFB::HandleQueuedPaintRequests()
             paintedRect.Union(clipped);
     }
 
-    WX_CLEAR_ARRAY(toPaint);
+    m_isPainting = false;
+
+    m_toPaint->Clear();
 
     if ( paintedRect.IsEmpty() )
         return; // no painting occurred, no need to flip
 
-    // flip the surface to make the changes visible:
+    // Flip the surface to make the changes visible. Note that the rectangle we
+    // flip is *superset* of the union of repainted rectangles (created as
+    // "rectangles union" by wxRect::Union) and so some parts of the back
+    // buffer that we didn't touch in this HandleQueuedPaintRequests call will
+    // be copied to the front buffer as well. This is safe/correct thing to do
+    // *only* because wx always use wxIDirectFBSurface::FlipToFront() and so
+    // the back and front buffers contain the same data.
+    //
+    // Note that we do _not_ split m_toPaint into disjoint rectangles and
+    // do FlipToFront() for each of them, because that could result in visible
+    // updating of the screen; instead, we prefer to flip everything at once.
+
     DFBRegion r = {paintedRect.GetLeft(), paintedRect.GetTop(),
                    paintedRect.GetRight(), paintedRect.GetBottom()};
     DFBRegion *rptr = (winRect == paintedRect) ? NULL : &r;
 
-    GetDfbSurface()->Flip(rptr, DSFLIP_NONE);
+    GetDfbSurface()->FlipToFront(rptr);
+
+    wxLogTrace(TRACE_PAINT,
+               _T("%p ('%s'): flipped surface: [%i,%i,%i,%i]"),
+               this, GetName().c_str(),
+               paintedRect.x, paintedRect.y,
+               paintedRect.GetRight(), paintedRect.GetBottom());
 }
 
-void wxTopLevelWindowDFB::DoRefreshRect(const wxRect& rect, bool eraseBack)
+void wxTopLevelWindowDFB::DoRefreshRect(const wxRect& rect)
 {
-    // defer paiting until idle time or until Update() is called:
-    m_toPaint->push_back(new wxDfbPaintRequest(rect, eraseBack));
+    // don't overlap outside of the window (NB: 'rect' is in window coords):
+    wxRect r(rect);
+    r.Intersect(wxRect(GetSize()));
+    if ( r.IsEmpty() )
+        return;
+
+    wxLogTrace(TRACE_PAINT,
+               _T("%p ('%s'): [TLW] refresh rect [%i,%i,%i,%i]"),
+               this, GetName().c_str(),
+               rect.x, rect.y, rect.GetRight(), rect.GetBottom());
+
+    // defer painting until idle time or until Update() is called:
+    m_toPaint->Add(rect);
 }
 
 void wxTopLevelWindowDFB::Update()
@@ -396,6 +480,15 @@ void wxTopLevelWindowDFB::Update()
 // events handling
 // ---------------------------------------------------------------------------
 
+void wxTopLevelWindowDFB::SetDfbFocus()
+{
+    wxCHECK_RET( IsShown(), _T("cannot set focus to hidden window") );
+    wxASSERT_MSG( FindFocus() && FindFocus()->GetTLW() == this,
+                  _T("setting DirectFB focus to unexpected window") );
+
+    GetDirectFBWindow()->RequestFocus();
+}
+
 /* static */
 void wxTopLevelWindowDFB::HandleDFBWindowEvent(const wxDFBWindowEvent& event_)
 {