Patch from KO to allow the renderer to be able to draw onto a wxGCDC

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_8_BRANCH@47869 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robin Dunn
2007-08-04 02:27:24 +00:00
parent d916510cb3
commit 48ad659aa2

View File

@@ -110,6 +110,27 @@ private:
static GtkWidget *GetHeaderButtonWidget(); static GtkWidget *GetHeaderButtonWidget();
}; };
GdkWindow* wxGetGdkWindowForDC(wxWindow* win, wxDC& dc)
{
// The way to get a GdkWindow* from a wxWindow is to use
// GTK_PIZZA(win->m_wxwindow)->bin_window, but this approach
// won't work when drawing to a wxMemoryDC as it has its own
// GdkWindow* for its bitmap. wxWindowDC's GetGDKWindow() was
// designed to create a solution for all DCs, but we can't
// implement it with wxGCDC since it doesn't retain its wxWindow.
// So, to work around this, we use GetGDKWindow whenever possible
// and use bin_window for wxGCDC.
GdkWindow* gdk_window = NULL;
if ( dc.IsKindOf( CLASSINFO(wxGCDC) ) )
gdk_window = GTK_PIZZA(win->m_wxwindow)->bin_window;
else
gdk_window = dc.GetGDKWindow();
wxASSERT_MSG( gdk_window,
wxT("cannot use wxRendererNative on wxDC of this type") );
return gdk_window;
}
// ============================================================================ // ============================================================================
// implementation // implementation
// ============================================================================ // ============================================================================
@@ -217,9 +238,7 @@ wxRendererGTK::DrawHeaderButton(wxWindow *win,
GtkWidget *button = GetHeaderButtonWidget(); GtkWidget *button = GetHeaderButtonWidget();
GdkWindow* gdk_window = dc.GetGDKWindow(); GdkWindow* gdk_window = wxGetGdkWindowForDC(win, dc);
wxASSERT_MSG( gdk_window,
wxT("cannot use wxRendererNative on wxDC of this type") );
int x_diff = 0; int x_diff = 0;
if (win->GetLayoutDirection() == wxLayout_RightToLeft) if (win->GetLayoutDirection() == wxLayout_RightToLeft)
@@ -247,9 +266,7 @@ wxRendererGTK::DrawTreeItemButton(wxWindow* win,
{ {
GtkWidget *tree = GetTreeWidget(); GtkWidget *tree = GetTreeWidget();
GdkWindow* gdk_window = dc.GetGDKWindow(); GdkWindow* gdk_window = wxGetGdkWindowForDC(win, dc);
wxASSERT_MSG( gdk_window,
wxT("cannot use wxRendererNative on wxDC of this type") );
GtkStateType state; GtkStateType state;
if ( flags & wxCONTROL_CURRENT ) if ( flags & wxCONTROL_CURRENT )
@@ -330,9 +347,7 @@ wxRendererGTK::DrawSplitterSash(wxWindow *win,
return; return;
} }
GdkWindow* gdk_window = dc.GetGDKWindow(); GdkWindow* gdk_window = wxGetGdkWindowForDC(win, dc);
wxASSERT_MSG( gdk_window,
wxT("cannot use wxRendererNative on wxDC of this type") );
wxCoord full_size = GetGtkSplitterFullSize(); wxCoord full_size = GetGtkSplitterFullSize();
@@ -382,21 +397,14 @@ wxRendererGTK::DrawSplitterSash(wxWindow *win,
} }
void void
wxRendererGTK::DrawDropArrow(wxWindow *WXUNUSED(win), wxRendererGTK::DrawDropArrow(wxWindow *win,
wxDC& dc, wxDC& dc,
const wxRect& rect, const wxRect& rect,
int flags) int flags)
{ {
GtkWidget *button = GetButtonWidget(); GtkWidget *button = GetButtonWidget();
// If we give GTK_PIZZA(win->m_wxwindow)->bin_window as GdkWindow* gdk_window = wxGetGdkWindowForDC(win, dc);
// a window for gtk_paint_xxx function, then it won't
// work for wxMemoryDC. So that is why we assume wxDC
// is wxWindowDC (wxClientDC, wxMemoryDC and wxPaintDC
// are derived from it) and use its m_window.
GdkWindow* gdk_window = dc.GetGDKWindow();
wxASSERT_MSG( gdk_window,
wxT("cannot use wxRendererNative on wxDC of this type") );
// draw arrow so that there is even space horizontally // draw arrow so that there is even space horizontally
// on both sides // on both sides
@@ -449,17 +457,14 @@ wxRendererGTK::DrawComboBoxDropButton(wxWindow *win,
} }
void void
wxRendererGTK::DrawCheckBox(wxWindow *WXUNUSED(win), wxRendererGTK::DrawCheckBox(wxWindow *win,
wxDC& dc, wxDC& dc,
const wxRect& rect, const wxRect& rect,
int flags ) int flags )
{ {
GtkWidget *button = GetCheckButtonWidget(); GtkWidget *button = GetCheckButtonWidget();
// for reason why we do this, see DrawDropArrow GdkWindow* gdk_window = wxGetGdkWindowForDC(win, dc);
GdkWindow* gdk_window = dc.GetGDKWindow();
wxASSERT_MSG( gdk_window,
wxT("cannot use wxRendererNative on wxDC of this type") );
GtkStateType state; GtkStateType state;
@@ -488,17 +493,14 @@ wxRendererGTK::DrawCheckBox(wxWindow *WXUNUSED(win),
} }
void void
wxRendererGTK::DrawPushButton(wxWindow *WXUNUSED(win), wxRendererGTK::DrawPushButton(wxWindow* win,
wxDC& dc, wxDC& dc,
const wxRect& rect, const wxRect& rect,
int flags) int flags)
{ {
GtkWidget *button = GetButtonWidget(); GtkWidget *button = GetButtonWidget();
// for reason why we do this, see DrawDropArrow GdkWindow* gdk_window = wxGetGdkWindowForDC(win, dc);
GdkWindow* gdk_window = dc.GetGDKWindow();
wxASSERT_MSG( gdk_window,
wxT("cannot use wxRendererNative on wxDC of this type") );
// draw button // draw button
GtkStateType state; GtkStateType state;
@@ -531,9 +533,7 @@ wxRendererGTK::DrawItemSelectionRect(wxWindow *win,
const wxRect& rect, const wxRect& rect,
int flags ) int flags )
{ {
GdkWindow* gdk_window = dc.GetGDKWindow(); GdkWindow* gdk_window = wxGetGdkWindowForDC(win, dc);
wxASSERT_MSG( gdk_window,
wxT("cannot use wxRendererNative on wxDC of this type") );
int x_diff = 0; int x_diff = 0;
if (win->GetLayoutDirection() == wxLayout_RightToLeft) if (win->GetLayoutDirection() == wxLayout_RightToLeft)