From 08f53168acef5006826b22c11fe562432193d854 Mon Sep 17 00:00:00 2001 From: Paul Cornett Date: Tue, 6 Nov 2007 18:14:15 +0000 Subject: [PATCH] New "pizza" widget implementation. Window border widths now match the GtkStyle they are drawn with. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@49687 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- Makefile.in | 16 +- build/bakefiles/files.bkl | 2 +- include/wx/gtk/win_gtk.h | 94 +++--------- include/wx/gtk/window.h | 2 + include/wx/gtk1/window.h | 2 + src/aui/dockart.cpp | 5 +- src/generic/graphicc.cpp | 2 +- src/generic/statusbr.cpp | 9 +- src/gtk/app.cpp | 1 - src/gtk/dcclient.cpp | 4 +- src/gtk/glcanvas.cpp | 4 +- src/gtk/popupwin.cpp | 12 +- src/gtk/renderer.cpp | 1 - src/gtk/toplevel.cpp | 5 +- src/gtk/window.cpp | 306 +++++++++++++++----------------------- src/gtk1/window.cpp | 8 + src/unix/mediactrl.cpp | 10 +- 17 files changed, 184 insertions(+), 299 deletions(-) diff --git a/Makefile.in b/Makefile.in index 59eb959205..d025e6cd4f 100644 --- a/Makefile.in +++ b/Makefile.in @@ -15622,8 +15622,8 @@ monodll_sound_sdl.o: $(srcdir)/src/unix/sound_sdl.cpp $(MONODLL_ODEP) @COND_TOOLKIT_GTK_TOOLKIT_VERSION__USE_GUI_1@monodll_utilsgtk.o: $(srcdir)/src/gtk1/utilsgtk.cpp $(MONODLL_ODEP) @COND_TOOLKIT_GTK_TOOLKIT_VERSION__USE_GUI_1@ $(CXXC) -c -o $@ $(MONODLL_CXXFLAGS) $(srcdir)/src/gtk1/utilsgtk.cpp -@COND_TOOLKIT_GTK_TOOLKIT_VERSION_2_USE_GUI_1@monodll_win_gtk.o: $(srcdir)/src/gtk/win_gtk.c $(MONODLL_ODEP) -@COND_TOOLKIT_GTK_TOOLKIT_VERSION_2_USE_GUI_1@ $(CCC) -c -o $@ $(MONODLL_CFLAGS) $(srcdir)/src/gtk/win_gtk.c +@COND_TOOLKIT_GTK_TOOLKIT_VERSION_2_USE_GUI_1@monodll_win_gtk.o: $(srcdir)/src/gtk/win_gtk.cpp $(MONODLL_ODEP) +@COND_TOOLKIT_GTK_TOOLKIT_VERSION_2_USE_GUI_1@ $(CXXC) -c -o $@ $(MONODLL_CXXFLAGS) $(srcdir)/src/gtk/win_gtk.cpp @COND_TOOLKIT_GTK_TOOLKIT_VERSION__USE_GUI_1@monodll_win_gtk.o: $(srcdir)/src/gtk1/win_gtk.c $(MONODLL_ODEP) @COND_TOOLKIT_GTK_TOOLKIT_VERSION__USE_GUI_1@ $(CCC) -c -o $@ $(MONODLL_CFLAGS) $(srcdir)/src/gtk1/win_gtk.c @@ -20074,8 +20074,8 @@ monolib_sound_sdl.o: $(srcdir)/src/unix/sound_sdl.cpp $(MONOLIB_ODEP) @COND_TOOLKIT_GTK_TOOLKIT_VERSION__USE_GUI_1@monolib_utilsgtk.o: $(srcdir)/src/gtk1/utilsgtk.cpp $(MONOLIB_ODEP) @COND_TOOLKIT_GTK_TOOLKIT_VERSION__USE_GUI_1@ $(CXXC) -c -o $@ $(MONOLIB_CXXFLAGS) $(srcdir)/src/gtk1/utilsgtk.cpp -@COND_TOOLKIT_GTK_TOOLKIT_VERSION_2_USE_GUI_1@monolib_win_gtk.o: $(srcdir)/src/gtk/win_gtk.c $(MONOLIB_ODEP) -@COND_TOOLKIT_GTK_TOOLKIT_VERSION_2_USE_GUI_1@ $(CCC) -c -o $@ $(MONOLIB_CFLAGS) $(srcdir)/src/gtk/win_gtk.c +@COND_TOOLKIT_GTK_TOOLKIT_VERSION_2_USE_GUI_1@monolib_win_gtk.o: $(srcdir)/src/gtk/win_gtk.cpp $(MONOLIB_ODEP) +@COND_TOOLKIT_GTK_TOOLKIT_VERSION_2_USE_GUI_1@ $(CXXC) -c -o $@ $(MONOLIB_CXXFLAGS) $(srcdir)/src/gtk/win_gtk.cpp @COND_TOOLKIT_GTK_TOOLKIT_VERSION__USE_GUI_1@monolib_win_gtk.o: $(srcdir)/src/gtk1/win_gtk.c $(MONOLIB_ODEP) @COND_TOOLKIT_GTK_TOOLKIT_VERSION__USE_GUI_1@ $(CCC) -c -o $@ $(MONOLIB_CFLAGS) $(srcdir)/src/gtk1/win_gtk.c @@ -25084,8 +25084,8 @@ coredll_win32.o: $(srcdir)/src/univ/themes/win32.cpp $(COREDLL_ODEP) @COND_TOOLKIT_GTK_TOOLKIT_VERSION__USE_GUI_1@coredll_utilsgtk.o: $(srcdir)/src/gtk1/utilsgtk.cpp $(COREDLL_ODEP) @COND_TOOLKIT_GTK_TOOLKIT_VERSION__USE_GUI_1@ $(CXXC) -c -o $@ $(COREDLL_CXXFLAGS) $(srcdir)/src/gtk1/utilsgtk.cpp -@COND_TOOLKIT_GTK_TOOLKIT_VERSION_2_USE_GUI_1@coredll_win_gtk.o: $(srcdir)/src/gtk/win_gtk.c $(COREDLL_ODEP) -@COND_TOOLKIT_GTK_TOOLKIT_VERSION_2_USE_GUI_1@ $(CCC) -c -o $@ $(COREDLL_CFLAGS) $(srcdir)/src/gtk/win_gtk.c +@COND_TOOLKIT_GTK_TOOLKIT_VERSION_2_USE_GUI_1@coredll_win_gtk.o: $(srcdir)/src/gtk/win_gtk.cpp $(COREDLL_ODEP) +@COND_TOOLKIT_GTK_TOOLKIT_VERSION_2_USE_GUI_1@ $(CXXC) -c -o $@ $(COREDLL_CXXFLAGS) $(srcdir)/src/gtk/win_gtk.cpp @COND_TOOLKIT_GTK_TOOLKIT_VERSION__USE_GUI_1@coredll_win_gtk.o: $(srcdir)/src/gtk1/win_gtk.c $(COREDLL_ODEP) @COND_TOOLKIT_GTK_TOOLKIT_VERSION__USE_GUI_1@ $(CCC) -c -o $@ $(COREDLL_CFLAGS) $(srcdir)/src/gtk1/win_gtk.c @@ -28153,8 +28153,8 @@ corelib_win32.o: $(srcdir)/src/univ/themes/win32.cpp $(CORELIB_ODEP) @COND_TOOLKIT_GTK_TOOLKIT_VERSION__USE_GUI_1@corelib_utilsgtk.o: $(srcdir)/src/gtk1/utilsgtk.cpp $(CORELIB_ODEP) @COND_TOOLKIT_GTK_TOOLKIT_VERSION__USE_GUI_1@ $(CXXC) -c -o $@ $(CORELIB_CXXFLAGS) $(srcdir)/src/gtk1/utilsgtk.cpp -@COND_TOOLKIT_GTK_TOOLKIT_VERSION_2_USE_GUI_1@corelib_win_gtk.o: $(srcdir)/src/gtk/win_gtk.c $(CORELIB_ODEP) -@COND_TOOLKIT_GTK_TOOLKIT_VERSION_2_USE_GUI_1@ $(CCC) -c -o $@ $(CORELIB_CFLAGS) $(srcdir)/src/gtk/win_gtk.c +@COND_TOOLKIT_GTK_TOOLKIT_VERSION_2_USE_GUI_1@corelib_win_gtk.o: $(srcdir)/src/gtk/win_gtk.cpp $(CORELIB_ODEP) +@COND_TOOLKIT_GTK_TOOLKIT_VERSION_2_USE_GUI_1@ $(CXXC) -c -o $@ $(CORELIB_CXXFLAGS) $(srcdir)/src/gtk/win_gtk.cpp @COND_TOOLKIT_GTK_TOOLKIT_VERSION__USE_GUI_1@corelib_win_gtk.o: $(srcdir)/src/gtk1/win_gtk.c $(CORELIB_ODEP) @COND_TOOLKIT_GTK_TOOLKIT_VERSION__USE_GUI_1@ $(CCC) -c -o $@ $(CORELIB_CFLAGS) $(srcdir)/src/gtk1/win_gtk.c diff --git a/build/bakefiles/files.bkl b/build/bakefiles/files.bkl index 6b640e9861..cde7bbdadc 100644 --- a/build/bakefiles/files.bkl +++ b/build/bakefiles/files.bkl @@ -984,7 +984,7 @@ IMPORTANT: please read docs/tech/tn0016.txt before modifying this file! src/gtk/tooltip.cpp src/gtk/toplevel.cpp src/gtk/utilsgtk.cpp - src/gtk/win_gtk.c + src/gtk/win_gtk.cpp src/gtk/window.cpp diff --git a/include/wx/gtk/win_gtk.h b/include/wx/gtk/win_gtk.h index a6c5180f4e..696530f9cd 100644 --- a/include/wx/gtk/win_gtk.h +++ b/include/wx/gtk/win_gtk.h @@ -1,88 +1,34 @@ /* /////////////////////////////////////////////////////////////////////////// // Name: win_gtk.h -// Purpose: wxWidgets's GTK base widget = GtkPizza +// Purpose: native GTK+ widget for wxWindow // Author: Robert Roebling // Id: $Id$ // Copyright: (c) 1998 Robert Roebling // Licence: wxWindows licence /////////////////////////////////////////////////////////////////////////// */ +#ifndef _WX_GTK_PIZZA_H_ +#define _WX_GTK_PIZZA_H_ -#ifndef __GTK_PIZZA_H__ -#define __GTK_PIZZA_H__ +#include -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ +#define WX_PIZZA(obj) G_TYPE_CHECK_INSTANCE_CAST(obj, wxPizza::type(), wxPizza) +#define WX_IS_PIZZA(obj) G_TYPE_CHECK_INSTANCE_TYPE(obj, wxPizza::type()) -#include - -#include "wx/dlimpexp.h" - -#define GTK_PIZZA(obj) GTK_CHECK_CAST (obj, gtk_pizza_get_type (), GtkPizza) -#define GTK_IS_PIZZA(obj) GTK_CHECK_TYPE (obj, gtk_pizza_get_type ()) - -typedef struct _GtkPizza GtkPizza; - -struct _GtkPizza +struct WXDLLIMPEXP_CORE wxPizza { - GtkContainer container; - GList *children; - - guint m_xoffset; - guint m_yoffset; - - gboolean m_noscroll; - - GdkWindow *bin_window; + static GtkWidget* New(long windowStyle = 0); + static GType type(); + void move(GtkWidget* widget, int x, int y); + void scroll(int dx, int dy); + void get_border_widths(int& x, int& y); + + GtkFixed m_fixed; + GdkWindow* m_backing_window; + int m_scroll_x; + int m_scroll_y; + int m_border_style; + bool m_is_scrollable; }; -WXDLLIMPEXP_CORE -GtkType gtk_pizza_get_type (void); -WXDLLIMPEXP_CORE -GtkWidget* gtk_pizza_new (void); -WXDLLIMPEXP_CORE -GtkWidget* gtk_pizza_new_no_scroll (void); - -/* accessors */ - -WXDLLIMPEXP_CORE -gint gtk_pizza_get_xoffset (GtkPizza *pizza); -WXDLLIMPEXP_CORE -gint gtk_pizza_get_yoffset (GtkPizza *pizza); -WXDLLIMPEXP_CORE -void gtk_pizza_set_xoffset (GtkPizza *pizza, gint xoffset); -WXDLLIMPEXP_CORE -void gtk_pizza_set_yoffset (GtkPizza *pizza, gint yoffset); - - -WXDLLIMPEXP_CORE -gint gtk_pizza_get_rtl_offset (GtkPizza *pizza); - - -WXDLLIMPEXP_CORE -void gtk_pizza_scroll (GtkPizza *pizza, - gint dx, - gint dy); - -WXDLLIMPEXP_CORE -void gtk_pizza_put (GtkPizza *pizza, - GtkWidget *widget, - gint x, - gint y, - gint width, - gint height); - -WXDLLIMPEXP_CORE -void gtk_pizza_set_size (GtkPizza *pizza, - GtkWidget *widget, - gint x, - gint y, - gint width, - gint height); -#ifdef __cplusplus -} -#endif /* __cplusplus */ - - -#endif /* __GTK_PIZZA_H__ */ +#endif // _WX_GTK_PIZZA_H_ diff --git a/include/wx/gtk/window.h b/include/wx/gtk/window.h index 6ed61b72cc..3becd7bb5c 100644 --- a/include/wx/gtk/window.h +++ b/include/wx/gtk/window.h @@ -184,6 +184,8 @@ public: // fire off capture lost events. void GTKReleaseMouseAndNotify(); + GdkWindow* GTKGetDrawingWindow() const; + protected: // Override GTKWidgetNeedsMnemonic and return true if your // needs to set its mnemonic widget, such as for a diff --git a/include/wx/gtk1/window.h b/include/wx/gtk1/window.h index f80dd7b645..1fb59e507e 100644 --- a/include/wx/gtk1/window.h +++ b/include/wx/gtk1/window.h @@ -110,6 +110,8 @@ public: virtual bool IsDoubleBuffered() const { return false; } + GdkWindow* GTKGetDrawingWindow() const; + // implementation // -------------- diff --git a/src/aui/dockart.cpp b/src/aui/dockart.cpp index 5103cc80e9..34393e5315 100644 --- a/src/aui/dockart.cpp +++ b/src/aui/dockart.cpp @@ -41,7 +41,6 @@ #ifdef __WXGTK__ #include -#include "wx/gtk/win_gtk.h" #include "wx/renderer.h" #endif @@ -467,12 +466,12 @@ void wxAuiDefaultDockArt::DrawSash(wxDC& dc, wxWindow *window, int orientation, if (!window) return; if (!window->m_wxwindow) return; - if (!GTK_PIZZA(window->m_wxwindow)->bin_window) return; + if (!GTK_WIDGET_DRAWABLE(window->m_wxwindow)) return; gtk_paint_handle ( window->m_wxwindow->style, - GTK_PIZZA(window->m_wxwindow)->bin_window, + window->GTKGetDrawingWindow(), // flags & wxCONTROL_CURRENT ? GTK_STATE_PRELIGHT : GTK_STATE_NORMAL, GTK_STATE_NORMAL, GTK_SHADOW_NONE, diff --git a/src/generic/graphicc.cpp b/src/generic/graphicc.cpp index f40b1c5845..79e6e9387d 100644 --- a/src/generic/graphicc.cpp +++ b/src/generic/graphicc.cpp @@ -33,7 +33,7 @@ #endif #ifdef __WXGTK__ -#include "wx/gtk/win_gtk.h" +#include #endif #include "wx/graphics.h" diff --git a/src/generic/statusbr.cpp b/src/generic/statusbr.cpp index 44fa9ad078..d5330414b0 100644 --- a/src/generic/statusbr.cpp +++ b/src/generic/statusbr.cpp @@ -27,7 +27,6 @@ #ifdef __WXGTK20__ #include - #include "wx/gtk/win_gtk.h" #endif // we only have to do it here when we use wxStatusBarGeneric in addition to the @@ -204,7 +203,7 @@ void wxStatusBarGeneric::OnPaint(wxPaintEvent& WXUNUSED(event) ) if (GetLayoutDirection() == wxLayout_RightToLeft) { gtk_paint_resize_grip( m_widget->style, - GTK_PIZZA(m_wxwindow)->bin_window, + GTKGetDrawingWindow(), (GtkStateType) GTK_WIDGET_STATE (m_widget), NULL, m_widget, @@ -215,7 +214,7 @@ void wxStatusBarGeneric::OnPaint(wxPaintEvent& WXUNUSED(event) ) else { gtk_paint_resize_grip( m_widget->style, - GTK_PIZZA(m_wxwindow)->bin_window, + GTKGetDrawingWindow(), (GtkStateType) GTK_WIDGET_STATE (m_widget), NULL, m_widget, @@ -423,7 +422,7 @@ void wxStatusBarGeneric::OnLeftDown(wxMouseEvent& event) if (!GTK_IS_WINDOW (ancestor)) return; - GdkWindow *source = GTK_PIZZA(m_wxwindow)->bin_window; + GdkWindow *source = GTKGetDrawingWindow(); int org_x = 0; int org_y = 0; @@ -470,7 +469,7 @@ void wxStatusBarGeneric::OnRightDown(wxMouseEvent& event) if (!GTK_IS_WINDOW (ancestor)) return; - GdkWindow *source = GTK_PIZZA(m_wxwindow)->bin_window; + GdkWindow *source = GTKGetDrawingWindow(); int org_x = 0; int org_y = 0; diff --git a/src/gtk/app.cpp b/src/gtk/app.cpp index e23081e0cc..62cf72b0be 100644 --- a/src/gtk/app.cpp +++ b/src/gtk/app.cpp @@ -26,7 +26,6 @@ #include #endif -#include "wx/gtk/win_gtk.h" #include "wx/gtk/private.h" #include "wx/apptrait.h" diff --git a/src/gtk/dcclient.cpp b/src/gtk/dcclient.cpp index 3845198b4a..ff4289883b 100644 --- a/src/gtk/dcclient.cpp +++ b/src/gtk/dcclient.cpp @@ -28,7 +28,6 @@ #include "wx/fontutil.h" #include "wx/scrolwin.h" -#include "wx/gtk/win_gtk.h" #include "wx/gtk/private.h" #include @@ -311,8 +310,7 @@ wxWindowDC::wxWindowDC( wxWindow *window ) m_layout = pango_layout_new( m_context ); m_fontdesc = pango_font_description_copy( widget->style->font_desc ); - GtkPizza *pizza = GTK_PIZZA( widget ); - m_window = pizza->bin_window; + m_window = widget->window; // Window not realized ? if (!m_window) diff --git a/src/gtk/glcanvas.cpp b/src/gtk/glcanvas.cpp index 3fc37ba80e..df96d5d8c8 100644 --- a/src/gtk/glcanvas.cpp +++ b/src/gtk/glcanvas.cpp @@ -26,8 +26,6 @@ #include #include -#include "wx/gtk/win_gtk.h" - #if WXWIN_COMPATIBILITY_2_8 //----------------------------------------------------------------------------- @@ -234,7 +232,7 @@ bool wxGLCanvas::Create(wxWindow *parent, Window wxGLCanvas::GetXWindow() const { - GdkWindow *window = GTK_PIZZA(m_wxwindow)->bin_window; + GdkWindow *window = m_wxwindow->window; return window ? GDK_WINDOW_XWINDOW(window) : 0; } diff --git a/src/gtk/popupwin.cpp b/src/gtk/popupwin.cpp index 2dafe977bb..e82b1a4b25 100644 --- a/src/gtk/popupwin.cpp +++ b/src/gtk/popupwin.cpp @@ -109,12 +109,10 @@ gtk_dialog_realized_callback( GtkWidget * WXUNUSED(widget), wxPopupWindow *win ) static void wxInsertChildInPopupWin(wxWindowGTK* parent, wxWindowGTK* child) { - gtk_pizza_put( GTK_PIZZA(parent->m_wxwindow), - child->m_widget, - child->m_x, - child->m_y, - child->m_width, - child->m_height ); + gtk_widget_set_size_request( + child->m_widget, child->m_width, child->m_height); + gtk_fixed_put( + GTK_FIXED(parent->m_wxwindow), child->m_widget, child->m_x, child->m_y); if (parent->HasFlag(wxTAB_TRAVERSAL)) { @@ -165,7 +163,7 @@ bool wxPopupWindow::Create( wxWindow *parent, int style ) g_signal_connect (m_widget, "delete_event", G_CALLBACK (gtk_dialog_delete_callback), this); - m_wxwindow = gtk_pizza_new(); + m_wxwindow = wxPizza::New(m_windowStyle); gtk_widget_show( m_wxwindow ); GTK_WIDGET_UNSET_FLAGS( m_wxwindow, GTK_CAN_FOCUS ); diff --git a/src/gtk/renderer.cpp b/src/gtk/renderer.cpp index d4c273d979..4eec03a12e 100644 --- a/src/gtk/renderer.cpp +++ b/src/gtk/renderer.cpp @@ -33,7 +33,6 @@ #endif #include -#include "wx/gtk/win_gtk.h" // ---------------------------------------------------------------------------- // wxRendererGTK: our wxRendererNative implementation diff --git a/src/gtk/toplevel.cpp b/src/gtk/toplevel.cpp index acaec2299a..7ad3b37a46 100644 --- a/src/gtk/toplevel.cpp +++ b/src/gtk/toplevel.cpp @@ -557,7 +557,7 @@ bool wxTopLevelWindowGTK::Create( wxWindow *parent, gtk_container_add( GTK_CONTAINER(m_widget), m_mainWidget ); // m_wxwindow is the client area - m_wxwindow = gtk_pizza_new_no_scroll(); + m_wxwindow = wxPizza::New(); gtk_widget_show( m_wxwindow ); gtk_container_add( GTK_CONTAINER(m_mainWidget), m_wxwindow ); @@ -1105,8 +1105,7 @@ bool wxTopLevelWindowGTK::SetShape(const wxRegion& region) GdkWindow *window = NULL; if (m_wxwindow) { - window = GTK_PIZZA(m_wxwindow)->bin_window; - do_shape_combine_region(window, region); + do_shape_combine_region(m_wxwindow->window, region); } window = m_widget->window; return do_shape_combine_region(window, region); diff --git a/src/gtk/window.cpp b/src/gtk/window.cpp index 9134aedf1a..030666ca70 100644 --- a/src/gtk/window.cpp +++ b/src/gtk/window.cpp @@ -112,19 +112,19 @@ can find in m_widget (defined in wxWindow) When the class has a client area for drawing into and for containing children - it has to handle the client area widget (of the type GtkPizza, defined in - win_gtk.c), but there could be any number of widgets, handled by a class + it has to handle the client area widget (of the type wxPizza, defined in + win_gtk.cpp), but there could be any number of widgets, handled by a class. The common rule for all windows is only, that the widget that interacts with the rest of GTK must be referenced in m_widget and all other widgets must be children of this widget on the GTK level. The top-most widget, which also represents the client area, must be in the m_wxwindow field and must be of - the type GtkPizza. + the type wxPizza. As I said, the window classes that display a GTK native widget only have one widget, so in the case of e.g. the wxButton class m_widget holds a pointer to a GtkButton widget. But windows with client areas (for drawing and children) have a m_widget field that is a pointer to a GtkScrolled- - Window and a m_wxwindow field that is pointer to a GtkPizza and this + Window and a m_wxwindow field that is pointer to a wxPizza and this one is (in the GTK sense) a child of the GtkScrolledWindow. If the m_wxwindow field is set, then all input to this widget is inter- @@ -138,10 +138,10 @@ clicking on a scrollbar belonging to scrolled window will inevitably move the window. In wxWidgets, the scrollbar will only emit an event, send this to (normally) a wxScrolledWindow and that class will call ScrollWindow() - which actually moves the window and its sub-windows. Note that GtkPizza + which actually moves the window and its sub-windows. Note that wxPizza memorizes how much it has been scrolled but that wxWidgets forgets this so that the two coordinates systems have to be kept in synch. This is done - in various places using the pizza->xoffset and pizza->yoffset values. + in various places using the pizza->m_scroll_x and pizza->m_scroll_y values. III) @@ -312,92 +312,6 @@ static void GetScrollbarWidth(GtkWidget* widget, int& w, int& h) } } -static void draw_frame( GtkWidget *widget, wxWindowGTK *win ) -{ - // wxUniversal widgets draw the borders and scrollbars themselves -#ifndef __WXUNIVERSAL__ - if (!win->m_hasVMT) - return; - - int dx = 0; - int dy = 0; - if (GTK_WIDGET_NO_WINDOW (widget)) - { - dx += widget->allocation.x; - dy += widget->allocation.y; - } - - int x = dx; - int y = dy; - - int dw = 0; - int dh = 0; - if (win->m_hasScrolling) - { - GetScrollbarWidth(widget, dw, dh); - - if (win->GetLayoutDirection() == wxLayout_RightToLeft) - { - // This is actually wrong for old GTK+ version - // which do not display the scrollbar on the - // left side in RTL - x += dw; - } - } - - int w = widget->allocation.width-dw; - int h = widget->allocation.height-dh; - - if (win->HasFlag(wxRAISED_BORDER)) - { - gtk_paint_shadow (widget->style, - widget->window, - GTK_STATE_NORMAL, - GTK_SHADOW_OUT, - NULL, NULL, NULL, // FIXME: No clipping? - x, y, w, h ); - return; - } - - if (win->HasFlag(wxSUNKEN_BORDER)) - { - gtk_paint_shadow (widget->style, - widget->window, - GTK_STATE_NORMAL, - GTK_SHADOW_IN, - NULL, NULL, NULL, // FIXME: No clipping? - x, y, w, h ); - return; - } - - if (win->HasFlag(wxSIMPLE_BORDER)) - { - GdkGC *gc; - gc = gdk_gc_new( widget->window ); - gdk_gc_set_foreground( gc, &widget->style->black ); - gdk_draw_rectangle( widget->window, gc, FALSE, x, y, w-1, h-1 ); - g_object_unref (gc); - return; - } -#endif // __WXUNIVERSAL__ -} - -//----------------------------------------------------------------------------- -// "expose_event" of m_widget -//----------------------------------------------------------------------------- - -extern "C" { -static gboolean -gtk_window_own_expose_callback( GtkWidget *widget, - GdkEventExpose *gdk_event, - wxWindowGTK *win ) -{ - if (gdk_event->count == 0) - draw_frame(widget, win); - return false; -} -} - //----------------------------------------------------------------------------- // "size_request" of m_widget //----------------------------------------------------------------------------- @@ -471,18 +385,9 @@ gtk_window_expose_callback( GtkWidget *widget, { DEBUG_MAIN_THREAD - // This callback gets called in drawing-idle time under - // GTK 2.0, so we don't need to defer anything to idle - // time anymore. - - GtkPizza *pizza = GTK_PIZZA( widget ); - if (gdk_event->window != pizza->bin_window) - { - // block expose events on GTK_WIDGET(pizza)->window, - // all drawing is done on pizza->bin_window - return true; - } - + // if this event is for the border-only GdkWindow + if (gdk_event->window != widget->window) + return false; #if 0 if (win->GetName()) @@ -518,6 +423,53 @@ gtk_window_expose_callback( GtkWidget *widget, } } +//----------------------------------------------------------------------------- +// "expose_event" from m_widget, for drawing border +//----------------------------------------------------------------------------- + +#ifndef __WXUNIVERSAL__ +extern "C" { +static gboolean +expose_event_border(GtkWidget* widget, GdkEventExpose* event, wxWindow* win) +{ + // if this event is not for the GdkWindow the border is drawn on + if (win->m_wxwindow == win->m_widget && event->window == widget->window) + return false; + + int x = 0; + int y = 0; + // GtkScrolledWindow is GTK_NO_WINDOW + if (GTK_WIDGET_NO_WINDOW(widget)) + { + x = widget->allocation.x; + y = widget->allocation.y; + } + int w = win->m_wxwindow->allocation.width; + int h = win->m_wxwindow->allocation.height; + if (win->HasFlag(wxBORDER_SIMPLE)) + { + GdkGC* gc; + gc = gdk_gc_new(event->window); + gdk_gc_set_foreground(gc, &widget->style->black); + gdk_draw_rectangle(event->window, gc, false, x, y, w - 1, h - 1); + g_object_unref(gc); + } + else + { + GtkShadowType shadow = GTK_SHADOW_IN; + if (win->HasFlag(wxBORDER_RAISED)) + shadow = GTK_SHADOW_OUT; + gtk_paint_shadow( + widget->style, event->window, GTK_STATE_NORMAL, + shadow, &event->area, widget, NULL, x, y, w, h); + } + + // no further painting is needed for border-only GdkWindow + return win->m_wxwindow == win->m_widget; +} +} +#endif // !__WXUNIVERSAL__ + //----------------------------------------------------------------------------- // "key_press_event" from any window //----------------------------------------------------------------------------- @@ -1244,7 +1196,7 @@ template void InitMouseEvent(wxWindowGTK *win, if ((win->m_wxwindow) && (win->GetLayoutDirection() == wxLayout_RightToLeft)) { // origin in the upper right corner - int window_width = gtk_pizza_get_rtl_offset( GTK_PIZZA(win->m_wxwindow) ); + int window_width = win->m_wxwindow->allocation.width; event.m_x = window_width - event.m_x; } @@ -1294,9 +1246,9 @@ wxWindowGTK *FindWindowForMouseEvent(wxWindowGTK *win, wxCoord& x, wxCoord& y) if (win->m_wxwindow) { - GtkPizza *pizza = GTK_PIZZA(win->m_wxwindow); - xx += gtk_pizza_get_xoffset( pizza ); - yy += gtk_pizza_get_yoffset( pizza ); + wxPizza* pizza = WX_PIZZA(win->m_wxwindow); + xx += pizza->m_scroll_x; + yy += pizza->m_scroll_y; } wxWindowList::compatibility_iterator node = win->GetChildren().GetFirst(); @@ -1863,8 +1815,7 @@ wx_window_focus_callback(GtkWidget *widget, GtkDirectionType WXUNUSED(direction), wxWindowGTK *win) { - // the default handler for focus signal in GtkPizza (or, rather, in - // GtkScrolledWindow from which GtkPizza inherits this behaviour) sets + // the default handler for focus signal in GtkScrolledWindow sets // focus to the window itself even if it doesn't accept focus, i.e. has no // GTK_CAN_FOCUS in its style -- work around this by forcibly preventing // the signal from reaching gtk_scrolled_window_focus() if we don't have @@ -2031,15 +1982,14 @@ gtk_scrollbar_button_release_event(GtkRange* range, GdkEventButton*, wxWindow* w //----------------------------------------------------------------------------- static void -gtk_window_realized_callback( GtkWidget *m_widget, wxWindow *win ) +gtk_window_realized_callback(GtkWidget* widget, wxWindow* win) { DEBUG_MAIN_THREAD if (win->m_imData) { - GtkPizza *pizza = GTK_PIZZA( m_widget ); gtk_im_context_set_client_window( win->m_imData->context, - pizza->bin_window ); + widget->window); } // We cannot set colours and fonts before the widget @@ -2068,9 +2018,10 @@ size_allocate(GtkWidget*, GtkAllocation* alloc, wxWindow* win) int h = alloc->height; if (win->m_wxwindow) { - const int border = GTK_CONTAINER(win->m_wxwindow)->border_width; - w -= 2 * border; - h -= 2 * border; + int border_x, border_y; + WX_PIZZA(win->m_wxwindow)->get_border_widths(border_x, border_y); + w -= 2 * border_x; + h -= 2 * border_y; if (w < 0) w = 0; if (h < 0) h = 0; } @@ -2197,16 +2148,14 @@ static void wxInsertChildInWindow( wxWindowGTK* parent, wxWindowGTK* child ) { /* the window might have been scrolled already, do we have to adapt the position */ - GtkPizza *pizza = GTK_PIZZA(parent->m_wxwindow); - child->m_x += gtk_pizza_get_xoffset( pizza ); - child->m_y += gtk_pizza_get_yoffset( pizza ); + wxPizza* pizza = WX_PIZZA(parent->m_wxwindow); + child->m_x += pizza->m_scroll_x; + child->m_y += pizza->m_scroll_y; - gtk_pizza_put( GTK_PIZZA(parent->m_wxwindow), - child->m_widget, - child->m_x, - child->m_y, - child->m_width, - child->m_height ); + gtk_widget_set_size_request( + child->m_widget, child->m_width, child->m_height); + gtk_fixed_put( + GTK_FIXED(parent->m_wxwindow), child->m_widget, child->m_x, child->m_y); } //----------------------------------------------------------------------------- @@ -2337,31 +2286,13 @@ bool wxWindowGTK::Create( wxWindow *parent, return false; } + m_wxwindow = wxPizza::New(m_windowStyle); if (!HasFlag(wxHSCROLL) && !HasFlag(wxVSCROLL)) - { - m_wxwindow = gtk_pizza_new_no_scroll(); - -#ifndef __WXUNIVERSAL__ - if (HasFlag(wxSIMPLE_BORDER)) - gtk_container_set_border_width((GtkContainer*)m_wxwindow, 1); - else if (HasFlag(wxRAISED_BORDER) || HasFlag(wxSUNKEN_BORDER)) - gtk_container_set_border_width((GtkContainer*)m_wxwindow, 2); -#endif // __WXUNIVERSAL__ - m_widget = m_wxwindow; - } else { - m_wxwindow = gtk_pizza_new(); - -#ifndef __WXUNIVERSAL__ - if (HasFlag(wxSIMPLE_BORDER)) - gtk_container_set_border_width((GtkContainer*)m_wxwindow, 1); - else if (HasFlag(wxRAISED_BORDER) || HasFlag(wxSUNKEN_BORDER)) - gtk_container_set_border_width((GtkContainer*)m_wxwindow, 2); -#endif // __WXUNIVERSAL__ - m_widget = gtk_scrolled_window_new( (GtkAdjustment *) NULL, (GtkAdjustment *) NULL ); + gtk_container_set_resize_mode(GTK_CONTAINER(m_widget), GTK_RESIZE_QUEUE); GtkScrolledWindow *scrolledWindow = GTK_SCROLLED_WINDOW(m_widget); @@ -2516,7 +2447,7 @@ void wxWindowGTK::PostCreation() G_CALLBACK (gtk_window_expose_callback), this); if (GetLayoutDirection() == wxLayout_LeftToRight) - gtk_widget_set_redraw_on_allocate( GTK_WIDGET(m_wxwindow), HasFlag( wxFULL_REPAINT_ON_RESIZE ) ); + gtk_widget_set_redraw_on_allocate(m_wxwindow, HasFlag(wxFULL_REPAINT_ON_RESIZE)); } // Create input method handler @@ -2528,9 +2459,14 @@ void wxWindowGTK::PostCreation() g_signal_connect (m_imData->context, "commit", G_CALLBACK (gtk_wxwindow_commit_cb), this); - // these are called when the "sunken" or "raised" borders are drawn - g_signal_connect (m_widget, "expose_event", - G_CALLBACK (gtk_window_own_expose_callback), this); + // border drawing +#ifndef __WXUNIVERSAL__ + if (HasFlag(wxBORDER_SIMPLE | wxBORDER_RAISED | wxBORDER_SUNKEN)) + { + g_signal_connect(m_widget, "expose_event", + G_CALLBACK(expose_event_border), this); + } +#endif } // focus handling @@ -2684,9 +2620,9 @@ bool wxWindowGTK::Destroy() void wxWindowGTK::DoMoveWindow(int x, int y, int width, int height) { + gtk_widget_set_size_request(m_widget, width, height); // inform the parent to perform the move - gtk_pizza_set_size( GTK_PIZZA(m_parent->m_wxwindow), m_widget, x, y, width, height ); - + WX_PIZZA(m_parent->m_wxwindow)->move(m_widget, x, y); } void wxWindowGTK::ConstrainSize() @@ -2740,9 +2676,9 @@ void wxWindowGTK::DoSetSize( int x, int y, int width, int height, int sizeFlags if (m_parent->m_wxwindow) { - GtkPizza *pizza = GTK_PIZZA(m_parent->m_wxwindow); - m_x = x + gtk_pizza_get_xoffset(pizza); - m_y = y + gtk_pizza_get_yoffset(pizza); + wxPizza* pizza = WX_PIZZA(m_parent->m_wxwindow); + m_x = x + pizza->m_scroll_x; + m_y = y + pizza->m_scroll_y; int left_border = 0; int right_border = 0; @@ -2838,7 +2774,7 @@ void wxWindowGTK::OnInternalIdle() if (m_wxwindow && (m_wxwindow != m_widget)) { - GdkWindow *window = GTK_PIZZA(m_wxwindow)->bin_window; + GdkWindow *window = m_wxwindow->window; if (window) gdk_window_set_cursor( window, cursor.GetCursor() ); @@ -2894,9 +2830,10 @@ void wxWindowGTK::DoGetClientSize( int *width, int *height ) const if (m_hasScrolling) GetScrollbarWidth(m_widget, dw, dh); - const int border = GTK_CONTAINER(m_wxwindow)->border_width; - dw += 2 * border; - dh += 2 * border; + int border_x, border_y; + WX_PIZZA(m_wxwindow)->get_border_widths(border_x, border_y); + dw += 2 * border_x; + dh += 2 * border_y; w -= dw; h -= dh; @@ -2918,16 +2855,16 @@ void wxWindowGTK::DoGetPosition( int *x, int *y ) const int dy = 0; if (!IsTopLevel() && m_parent && m_parent->m_wxwindow) { - GtkPizza *pizza = GTK_PIZZA(m_parent->m_wxwindow); - dx = gtk_pizza_get_xoffset( pizza ); - dy = gtk_pizza_get_yoffset( pizza ); + wxPizza* pizza = WX_PIZZA(m_parent->m_wxwindow); + dx = pizza->m_scroll_x; + dy = pizza->m_scroll_y; } if (m_x == -1 && m_y == -1) { GdkWindow *source = (GdkWindow *) NULL; if (m_wxwindow) - source = GTK_PIZZA(m_wxwindow)->bin_window; + source = m_wxwindow->window; else source = m_widget->window; @@ -2957,7 +2894,7 @@ void wxWindowGTK::DoClientToScreen( int *x, int *y ) const GdkWindow *source = (GdkWindow *) NULL; if (m_wxwindow) - source = GTK_PIZZA(m_wxwindow)->bin_window; + source = m_wxwindow->window; else source = m_widget->window; @@ -2994,7 +2931,7 @@ void wxWindowGTK::DoScreenToClient( int *x, int *y ) const GdkWindow *source = (GdkWindow *) NULL; if (m_wxwindow) - source = GTK_PIZZA(m_wxwindow)->bin_window; + source = m_wxwindow->window; else source = m_widget->window; @@ -3394,7 +3331,7 @@ wxWindowGTK::AdjustForLayoutDirection(wxCoord x, wxCoord WXUNUSED(width), wxCoord WXUNUSED(widthTotal)) const { - // We now mirrors the coordinates of RTL windows in GtkPizza + // We now mirror the coordinates of RTL windows in wxPizza return x; } @@ -3577,7 +3514,7 @@ void wxWindowGTK::WarpPointer( int x, int y ) GdkWindow *window = (GdkWindow*) NULL; if (m_wxwindow) - window = GTK_PIZZA(m_wxwindow)->bin_window; + window = m_wxwindow->window; else window = GetConnectWidget()->window; @@ -3638,7 +3575,7 @@ void wxWindowGTK::Refresh(bool WXUNUSED(eraseBackground), if (m_wxwindow) { - if (!GTK_PIZZA(m_wxwindow)->bin_window) return; + if (m_wxwindow->window == NULL) return; GdkRectangle gdk_rect, *p; @@ -3658,7 +3595,7 @@ void wxWindowGTK::Refresh(bool WXUNUSED(eraseBackground), p = NULL; } - gdk_window_invalidate_rect( GTK_PIZZA(m_wxwindow)->bin_window, p, TRUE ); + gdk_window_invalidate_rect(m_wxwindow->window, p, true); } } @@ -3675,8 +3612,8 @@ void wxWindowGTK::Update() void wxWindowGTK::GtkUpdate() { - if (m_wxwindow && GTK_PIZZA(m_wxwindow)->bin_window) - gdk_window_process_updates( GTK_PIZZA(m_wxwindow)->bin_window, FALSE ); + if (m_wxwindow && m_wxwindow->window) + gdk_window_process_updates(m_wxwindow->window, false); if (m_widget && m_widget->window && (m_wxwindow != m_widget)) gdk_window_process_updates( m_widget->window, FALSE ); @@ -3724,8 +3661,7 @@ void wxWindowGTK::GtkSendPaintEvents() m_updateRegion.Clear(); gint width; - gdk_window_get_geometry( GTK_PIZZA(m_wxwindow)->bin_window, - NULL, NULL, &width, NULL, NULL ); + gdk_drawable_get_size(m_wxwindow->window, &width, NULL); wxRegionIterator upd( m_nativeUpdateRegion ); while (upd) @@ -3743,9 +3679,6 @@ void wxWindowGTK::GtkSendPaintEvents() } } - // widget to draw on - GtkPizza *pizza = GTK_PIZZA (m_wxwindow); - if (GetThemeEnabled() && (GetBackgroundStyle() == wxBG_STYLE_SYSTEM)) { // find ancestor from which to steal background @@ -3765,7 +3698,7 @@ void wxWindowGTK::GtkSendPaintEvents() rect.height = upd.GetHeight(); gtk_paint_flat_box( parent->m_widget->style, - pizza->bin_window, + m_wxwindow->window, (GtkStateType)GTK_WIDGET_STATE(m_wxwindow), GTK_SHADOW_NONE, &rect, @@ -3992,7 +3925,7 @@ bool wxWindowGTK::SetBackgroundStyle(wxBackgroundStyle style) GdkWindow *window; if ( m_wxwindow ) { - window = GTK_PIZZA(m_wxwindow)->bin_window; + window = m_wxwindow->window; } else { @@ -4065,7 +3998,7 @@ bool wxWindowGTK::GTKIsOwnWindow(GdkWindow *window) const GdkWindow *wxWindowGTK::GTKGetWindow(wxArrayGdkWindows& WXUNUSED(windows)) const { - return m_wxwindow ? GTK_PIZZA(m_wxwindow)->bin_window : m_widget->window; + return m_wxwindow ? m_wxwindow->window : m_widget->window; } bool wxWindowGTK::SetFont( const wxFont &font ) @@ -4088,7 +4021,7 @@ void wxWindowGTK::DoCaptureMouse() GdkWindow *window = (GdkWindow*) NULL; if (m_wxwindow) - window = GTK_PIZZA(m_wxwindow)->bin_window; + window = m_wxwindow->window; else window = GetConnectWidget()->window; @@ -4121,7 +4054,7 @@ void wxWindowGTK::DoReleaseMouse() GdkWindow *window = (GdkWindow*) NULL; if (m_wxwindow) - window = GTK_PIZZA(m_wxwindow)->bin_window; + window = m_wxwindow->window; else window = GetConnectWidget()->window; @@ -4297,10 +4230,7 @@ void wxWindowGTK::ScrollWindow( int dx, int dy, const wxRect* WXUNUSED(rect) ) m_clipPaintRegion = true; - if (GetLayoutDirection() == wxLayout_RightToLeft) - gtk_pizza_scroll( GTK_PIZZA(m_wxwindow), dx, -dy ); - else - gtk_pizza_scroll( GTK_PIZZA(m_wxwindow), -dx, -dy ); + WX_PIZZA(m_wxwindow)->scroll(dx, dy); m_clipPaintRegion = false; @@ -4408,3 +4338,11 @@ void wxRemoveGrab(wxWindow* window) { gtk_grab_remove( (GtkWidget*) window->GetHandle() ); } + +GdkWindow* wxWindowGTK::GTKGetDrawingWindow() const +{ + GdkWindow* window = NULL; + if (m_wxwindow) + window = m_wxwindow->window; + return window; +} diff --git a/src/gtk1/window.cpp b/src/gtk1/window.cpp index d2ad366660..889718e44b 100644 --- a/src/gtk1/window.cpp +++ b/src/gtk1/window.cpp @@ -4224,3 +4224,11 @@ void wxWinModule::OnExit() if (g_eraseGC) gdk_gc_unref( g_eraseGC ); } + +GdkWindow* wxWindowGTK::GTKGetDrawingWindow() const +{ + GdkWindow* window = NULL; + if (m_wxwindow) + window = GTK_PIZZA(m_wxwindow)->bin_window; + return window; +} diff --git a/src/unix/mediactrl.cpp b/src/unix/mediactrl.cpp index 7f4ad8b491..c3e72b52d1 100644 --- a/src/unix/mediactrl.cpp +++ b/src/unix/mediactrl.cpp @@ -37,7 +37,7 @@ #include "wx/thread.h" // wxMutex/wxMutexLocker #ifdef __WXGTK__ -# include "wx/gtk/win_gtk.h" + #include # include // for GDK_WINDOW_XWINDOW #endif @@ -282,7 +282,7 @@ static gboolean gtk_window_expose_callback(GtkWidget *widget, if(event->count > 0) return FALSE; - GdkWindow *window = GTK_PIZZA(be->GetControl()->m_wxwindow)->bin_window; + GdkWindow *window = be->GetControl()->GTKGetDrawingWindow(); // I've seen this reccommended somewhere... // TODO: Is this needed? Maybe it is just cruft... @@ -320,7 +320,7 @@ static gboolean gtk_window_expose_callback(GtkWidget *widget, //----------------------------------------------------------------------------- #ifdef __WXGTK__ extern "C" { -static gint gtk_window_realize_callback(GtkWidget* theWidget, +static gint gtk_window_realize_callback(GtkWidget*, wxGStreamerMediaBackend* be) { DEBUG_MAIN_THREAD // TODO: Is this neccessary? @@ -333,7 +333,7 @@ static gint gtk_window_realize_callback(GtkWidget* theWidget, wxYield(); // FIXME: RN: X Server gets an error/crash if I don't do // this or a messagebox beforehand?!?!?? - GdkWindow *window = GTK_PIZZA(theWidget)->bin_window; + GdkWindow *window = be->GetControl()->GTKGetDrawingWindow(); wxASSERT(window); gst_x_overlay_set_xwindow_id( GST_X_OVERLAY(be->m_xoverlay), @@ -737,7 +737,7 @@ void wxGStreamerMediaBackend::SetupXOverlay() else { wxYield(); // see realize callback... - GdkWindow *window = GTK_PIZZA(m_ctrl->m_wxwindow)->bin_window; + GdkWindow *window = m_ctrl->m_wxwindow->GTKGetDrawingWindow(); wxASSERT(window); #endif -- 2.45.2