From 6de67633bd522200a78993c8c57a1c983f68e211 Mon Sep 17 00:00:00 2001 From: Robert Roebling Date: Fri, 9 Nov 2007 20:57:39 +0000 Subject: [PATCH] More attempts to better support theme borders git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@49790 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- samples/toolbar/toolbar.cpp | 49 +++++++++++++++++++++++++++++++++---- src/gtk/renderer.cpp | 35 ++++++++++++++++++++++++++ src/gtk/win_gtk.cpp | 16 +++++++----- src/gtk/window.cpp | 32 +++++++++++------------- 4 files changed, 103 insertions(+), 29 deletions(-) diff --git a/samples/toolbar/toolbar.cpp b/samples/toolbar/toolbar.cpp index 829d602086..98cf74b127 100644 --- a/samples/toolbar/toolbar.cpp +++ b/samples/toolbar/toolbar.cpp @@ -88,21 +88,40 @@ class MyMiniControl: public wxControl { public: MyMiniControl( wxWindow *parent ) : - wxControl( parent, -1, wxDefaultPosition, wxSize(70,22), wxBORDER_SUNKEN, wxDefaultValidator, "MyMiniControl" ) + wxControl( parent, -1, wxDefaultPosition, wxSize(80,22), wxBORDER_SUNKEN, wxDefaultValidator, "MyMiniControl" ) { + m_hasFocus = false; } void OnPaint(wxPaintEvent &WXUNUSED(event)) { wxPaintDC dc(this); - dc.SetPen( *wxWHITE_PEN ); - dc.SetBrush( *wxGREEN_BRUSH ); + dc.SetPen( *wxTRANSPARENT_PEN ); + dc.SetBrush( *wxWHITE_BRUSH ); wxSize size = GetClientSize(); dc.DrawRectangle( 0,0,size.x,size.y ); + if (m_hasFocus) + dc.DrawText( "Focussed", 1,1 ); + } + void OnSetFocus(wxFocusEvent &WXUNUSED(event)) + { + m_hasFocus = true; + Refresh(); + } + void OnKillFocus(wxFocusEvent &WXUNUSED(event)) + { + m_hasFocus = false; + Refresh(); } virtual wxSize GetBestSize() { - return wxSize(70,22); + return wxSize(80,22); } + virtual bool AcceptsFocus() + { + return true; + } + + bool m_hasFocus; private: DECLARE_EVENT_TABLE() @@ -110,6 +129,8 @@ private: BEGIN_EVENT_TABLE(MyMiniControl, wxControl) EVT_PAINT(MyMiniControl::OnPaint) + EVT_SET_FOCUS(MyMiniControl::OnSetFocus) + EVT_KILL_FOCUS(MyMiniControl::OnKillFocus) END_EVENT_TABLE() @@ -318,7 +339,7 @@ bool MyApp::OnInit() // Create the main frame window MyFrame* frame = new MyFrame((wxFrame *) NULL, wxID_ANY, _T("wxToolBar Sample"), - wxPoint(100, 100), wxSize(550, 300)); + wxPoint(100, 100), wxSize(550, 500)); frame->Show(true); @@ -656,7 +677,25 @@ MyFrame::MyFrame(wxFrame* parent, m_panel->SetSizer(sizer); if (m_extraToolBar) sizer->Add(m_extraToolBar, 0, wxEXPAND, 0); + sizer->Add(0,0,6); sizer->Add(m_textWindow, 1, wxEXPAND, 0); + + wxControl *control; + control = new wxControl( m_panel, -1, wxPoint(30,20), wxSize(50,50), wxBORDER_SUNKEN ); + control = new wxControl( m_panel, -1, wxPoint(130,20), wxSize(50,50), wxBORDER_SIMPLE ); + control = new wxControl( m_panel, -1, wxPoint(230,20), wxSize(50,50), wxBORDER_RAISED ); + control = new wxControl( m_panel, -1, wxPoint(330,20), wxSize(50,50), wxBORDER_THEME ); + + wxScrolledWindow *scrolled; + scrolled = new wxScrolledWindow( m_panel, -1, wxPoint(30,120), wxSize(80,80), wxHSCROLL|wxVSCROLL | wxBORDER_SUNKEN ); + scrolled->SetVirtualSize(400,400); + scrolled->SetScrollRate(10,10); + scrolled = new wxScrolledWindow( m_panel, -1, wxPoint(130,120), wxSize(80,80), wxHSCROLL|wxVSCROLL | wxBORDER_SIMPLE ); + scrolled->SetVirtualSize(400,400); + scrolled->SetScrollRate(10,10); + scrolled = new wxScrolledWindow( m_panel, -1, wxPoint(230,120), wxSize(80,80), wxHSCROLL|wxVSCROLL | wxBORDER_RAISED ); + scrolled->SetVirtualSize(400,400); + scrolled->SetScrollRate(10,10); } void MyFrame::LayoutChildren() diff --git a/src/gtk/renderer.cpp b/src/gtk/renderer.cpp index 4eec03a12e..fa562f68c6 100644 --- a/src/gtk/renderer.cpp +++ b/src/gtk/renderer.cpp @@ -181,6 +181,41 @@ wxRendererGTK::GetTreeWidget() return s_tree; } +// used elsewhere +GtkWidget *GetEntryWidget() +{ + static GtkWidget *s_entry = NULL; + static GtkWidget *s_window = NULL; + + if ( !s_entry ) + { + s_window = gtk_window_new( GTK_WINDOW_POPUP ); + gtk_widget_realize( s_window ); + s_entry = gtk_entry_new(); + gtk_container_add( GTK_CONTAINER(s_window), s_entry ); + gtk_widget_realize( s_entry ); + } + + return s_entry; +} + +// used elsewhere +GtkWidget *GetScrolledWidget() +{ + static GtkWidget *s_entry = NULL; + static GtkWidget *s_window = NULL; + + if ( !s_entry ) + { + s_window = gtk_window_new( GTK_WINDOW_POPUP ); + gtk_widget_realize( s_window ); + s_entry = gtk_scrolled_window_new( NULL, NULL); + gtk_container_add( GTK_CONTAINER(s_window), s_entry ); + gtk_widget_realize( s_entry ); + } + + return s_entry; +} // This one just gets the button used by the column header. Although it's // still a gtk_button the themes will typically differentiate and draw them diff --git a/src/gtk/win_gtk.cpp b/src/gtk/win_gtk.cpp index 12b5be9290..de389d6211 100644 --- a/src/gtk/win_gtk.cpp +++ b/src/gtk/win_gtk.cpp @@ -9,6 +9,7 @@ #include "wx/defs.h" #include "wx/gtk/win_gtk.h" +#include "gtk/gtk.h" /* wxPizza is a custom GTK+ widget derived from GtkFixed. A custom widget @@ -166,6 +167,9 @@ static void realize(GtkWidget* widget) else gdk_window_reparent(widget->window, pizza->m_backing_window, border_x, border_y); gdk_window_resize(widget->window, w, h); + + widget->style = gtk_style_attach (widget->style, pizza->m_backing_window); + gtk_style_set_background (widget->style, pizza->m_backing_window, GTK_STATE_NORMAL); } } @@ -356,6 +360,8 @@ void wxPizza::scroll(int dx, int dy) } } +extern GtkWidget *GetEntryWidget(); + void wxPizza::get_border_widths(int& x, int& y) { x = y = 0; @@ -363,13 +369,11 @@ void wxPizza::get_border_widths(int& x, int& y) x = y = 1; else if (m_border_style) { - GtkWidget* widget = GTK_WIDGET(this); - if (widget->style) + GtkWidget *entry_widget = GetEntryWidget(); + if (entry_widget->style) { - x = widget->style->xthickness; - y = widget->style->ythickness; - x = 1; - y = 1; + x = entry_widget->style->xthickness; + y = entry_widget->style->ythickness; } } } diff --git a/src/gtk/window.cpp b/src/gtk/window.cpp index ff1855a547..21eaaf3f96 100644 --- a/src/gtk/window.cpp +++ b/src/gtk/window.cpp @@ -330,6 +330,9 @@ void wxgtk_window_size_request_callback(GtkWidget * WXUNUSED(widget), // "expose_event" of m_wxwindow //----------------------------------------------------------------------------- + +extern GtkWidget *GetEntryWidget(); + extern "C" { static gboolean gtk_window_expose_callback( GtkWidget *widget, @@ -360,10 +363,10 @@ gtk_window_expose_callback( GtkWidget *widget, if (win->HasFlag(wxBORDER_RAISED)) shadow = GTK_SHADOW_OUT; gtk_paint_shadow( - widget->style, gdk_event->window, GTK_STATE_NORMAL, - shadow, NULL, widget, "viewport", 0, 0, w, h); + GetEntryWidget()->style, gdk_event->window, GTK_STATE_NORMAL, + shadow, NULL, GetEntryWidget(), "entry", 0, 0, w, h); } - + return TRUE; } @@ -405,14 +408,13 @@ gtk_window_expose_callback( GtkWidget *widget, // "expose_event" from m_widget, for drawing border //----------------------------------------------------------------------------- -#if 0 -ndef __WXUNIVERSAL__ +#ifndef __WXUNIVERSAL__ extern "C" { static gboolean -expose_event_border(GtkWidget* widget, GdkEventExpose* event, wxWindow* win) +expose_event_border(GtkWidget* widget, GdkEventExpose* gdk_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) + if (win->m_wxwindow == win->m_widget && gdk_event->window == widget->window) return false; int x = 0; @@ -428,9 +430,9 @@ expose_event_border(GtkWidget* widget, GdkEventExpose* event, wxWindow* win) if (win->HasFlag(wxBORDER_SIMPLE)) { GdkGC* gc; - gc = gdk_gc_new(event->window); + gc = gdk_gc_new(gdk_event->window); gdk_gc_set_foreground(gc, &widget->style->black); - gdk_draw_rectangle(event->window, gc, false, x, y, w - 1, h - 1); + gdk_draw_rectangle(gdk_event->window, gc, false, x, y, w - 1, h - 1); g_object_unref(gc); } else @@ -439,8 +441,8 @@ expose_event_border(GtkWidget* widget, GdkEventExpose* event, wxWindow* win) if (win->HasFlag(wxBORDER_RAISED)) shadow = GTK_SHADOW_OUT; gtk_paint_shadow( - widget->style, event->window, GTK_STATE_NORMAL, - shadow, &event->area, widget, "entry", x, y, w, h); + GetEntryWidget()->style, gdk_event->window, GTK_STATE_NORMAL, + shadow, NULL, GetEntryWidget(), "viewport", x, y, w, h); } // no further painting is needed for border-only GdkWindow @@ -2439,8 +2441,7 @@ void wxWindowGTK::PostCreation() G_CALLBACK (gtk_wxwindow_commit_cb), this); // border drawing -#if 0 -ndef __WXUNIVERSAL__ +#ifndef __WXUNIVERSAL__ if (HasFlag(wxBORDER_SIMPLE | wxBORDER_RAISED | wxBORDER_SUNKEN)) { g_signal_connect(m_widget, "expose_event", @@ -3649,7 +3650,6 @@ void wxWindowGTK::GtkSendPaintEvents() } } -#if 0 if (GetThemeEnabled() && (GetBackgroundStyle() == wxBG_STYLE_SYSTEM)) { // find ancestor from which to steal background @@ -3703,11 +3703,7 @@ void wxWindowGTK::GtkSendPaintEvents() wxNcPaintEvent nc_paint_event( GetId() ); nc_paint_event.SetEventObject( this ); GetEventHandler()->ProcessEvent( nc_paint_event ); -#endif - if (GetName() == "MyMiniControl") - wxPrintf( "MyMini paint\n" ); - wxPaintEvent paint_event( GetId() ); paint_event.SetEventObject( this ); GetEventHandler()->ProcessEvent( paint_event ); -- 2.45.2