#ifndef WX_PRECOMP
#include "wx/app.h"
- #include "wx/dynarray.h"
#endif // WX_PRECOMP
#include "wx/hashmap.h"
// helpers
// ============================================================================
-struct wxDfbPaintRequest
-{
- wxDfbPaintRequest(const wxRect& rect) : m_rect(rect) {}
- wxDfbPaintRequest(const wxDfbPaintRequest& r) : m_rect(r.m_rect) {}
-
- wxRect m_rect;
-};
-
-WX_DEFINE_ARRAY_PTR(wxDfbPaintRequest*, wxDfbQueuedPaintRequestsList);
-
// Queue of paint requests
class wxDfbQueuedPaintRequests
{
// Adds paint request to the queue
void Add(const wxRect& rect)
- { m_queue.push_back(new wxDfbPaintRequest(rect)); }
+ {
+ // We use a simple implementation here for now: all refresh requests
+ // are merged together into single rectangle that is superset of
+ // all the requested rectangles. This wastes some blitting and painting
+ // time, but OTOH, EVT_PAINT handler is called only once per window.
+ m_invalidated.Union(rect);
+ }
// Is the queue empty?
- bool IsEmpty() const { return m_queue.empty(); }
+ bool IsEmpty() const { return m_invalidated.IsEmpty(); }
// Empties the queue
- void Clear() { WX_CLEAR_ARRAY(m_queue); }
+ void Clear() { m_invalidated = wxRect(); }
- // Gets requests in the queue
- const wxDfbQueuedPaintRequestsList& GetRequests() const { return m_queue; }
+ // Gets the next request in the queue, returns true if there was one,
+ // false if the queue was empty
+ bool GetNext(wxRect& rect)
+ {
+ if ( m_invalidated.IsEmpty() )
+ return false;
+
+ rect = m_invalidated;
+ Clear(); // there's only one item in the queue
+ return true;
+ }
private:
- wxDfbQueuedPaintRequestsList m_queue;
+ // currently invalidated region
+ wxRect m_invalidated;
};
// ============================================================================
desc.width = size.x;
desc.height = size.y;
m_dfbwin = layer->CreateWindow(&desc);
- if ( !layer )
+ if ( !m_dfbwin )
return false;
// add the new TLW to DFBWindowID->wxTLW map:
{
m_isBeingDeleted = true;
- wxTopLevelWindows.DeleteObject(this);
-
- if ( wxTheApp->GetTopWindow() == this )
- wxTheApp->SetTopWindow(NULL);
-
- if ( wxTopLevelWindows.empty() && wxTheApp->GetExitOnFrameDelete() )
- {
- wxTheApp->ExitMainLoop();
- }
+ // destroy all children before we destroy the underlying DirectFB window,
+ // so that if any of them does something with the TLW, it will still work:
+ DestroyChildren();
+ // it's safe to delete the underlying DirectFB window now:
wxDELETE(m_toPaint);
+ if ( !m_dfbwin )
+ return;
+
// remove the TLW from DFBWindowID->wxTLW map:
DFBWindowID winid;
if ( m_dfbwin->GetID(&winid) )
gs_dfbWindowsMap.erase(winid);
+
+ m_dfbwin->Destroy();
+ m_dfbwin.Reset();
}
// ----------------------------------------------------------------------------
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:
if ( IsShown() )
DoRefreshWindow();
bool wxTopLevelWindowDFB::Show(bool show)
{
+ // NB: this calls wxWindow::Show() and so ensures DoRefreshWindow() is
+ // called on the window -- we'll need that below
if ( !wxTopLevelWindowBase::Show(show) )
return false;
- // hide/show the window by setting its opacity to 0/full:
- m_dfbwin->SetOpacity(show ? m_opacity : 0);
-
// If this is the first time Show was called, send size event,
// so that the frame can adjust itself (think auto layout or single child)
if ( !m_sizeSet )
GetEventHandler()->ProcessEvent(event);
}
- // FIXME_DFB: do this at all?
- if ( show && AcceptsFocus() )
- SetFocus();
- // FIXME_DFB -- don't do this for popup windows?
+ // make sure the window is fully painted, with all pending updates, before
+ // DFB WM shows it, otherwise it would attempt to show either empty (=
+ // black) window surface (if shown for the first time) or it would show
+ // window with outdated content; note that the window was already refreshed
+ // in the wxTopLevelWindowBase::Show() call above:
+ if ( show )
+ Update();
+
+ // hide/show the window by setting its opacity to 0/full:
+ m_dfbwin->SetOpacity(show ? m_opacity : 0);
+
+ 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;
}
return;
}
- const wxDfbQueuedPaintRequestsList& requests = m_toPaint->GetRequests();
-
// process queued paint requests:
wxRect winRect(wxPoint(0, 0), GetSize());
wxRect paintedRect;
// 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);
+#ifdef __WXDEBUG__
+ int requestsCount = 0;
+#endif
- for ( size_t i = 0; i < cnt; ++i )
+ wxRect request;
+ while ( m_toPaint->GetNext(request) )
{
- const wxDfbPaintRequest& request = *requests[i];
-
- wxRect clipped(request.m_rect);
+#ifdef __WXDEBUG__
+ requestsCount++;
+#endif
+ wxRect clipped(request);
clipped.Intersect(winRect);
if ( clipped.IsEmpty() )
continue; // nothing to refresh
GetDfbSurface()->FlipToFront(rptr);
wxLogTrace(TRACE_PAINT,
- _T("%p ('%s'): flipped surface: [%i,%i,%i,%i]"),
+ _T("%p ('%s'): processed %i paint requests, flipped surface: [%i,%i,%i,%i]"),
this, GetName().c_str(),
+ requestsCount,
paintedRect.x, paintedRect.y,
paintedRect.GetRight(), paintedRect.GetBottom());
}
void wxTopLevelWindowDFB::DoRefreshRect(const wxRect& rect)
{
- wxASSERT_MSG( rect.width > 0 && rect.height > 0, _T("invalid rect") );
+ // 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]"),
// 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_)
{
wxFAIL_MSG( _T("invalid event type") );
break;
}
+
+ default:
+ // we're not interested in them here
+ break;
}
if ( !recipient )