]> git.saurik.com Git - wxWidgets.git/commitdiff
Implementation of wxSysColourChangedEvent on wxGTK
authorJulian Smart <julian@anthemion.co.uk>
Sat, 27 Oct 2007 17:38:39 +0000 (17:38 +0000)
committerJulian Smart <julian@anthemion.co.uk>
Sat, 27 Oct 2007 17:38:39 +0000 (17:38 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@49492 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/gtk/toplevel.h
src/gtk/toplevel.cpp
src/gtk/window.cpp

index f3d8c858fe12079374686e2b0ffe43a4f19d4aba..f6f1b7c5407f92c0feca50181f7cb06f69136e26 100644 (file)
@@ -16,6 +16,7 @@
 
 class WXDLLIMPEXP_CORE wxTopLevelWindowGTK : public wxTopLevelWindowBase
 {
 
 class WXDLLIMPEXP_CORE wxTopLevelWindowGTK : public wxTopLevelWindowBase
 {
+    DECLARE_EVENT_TABLE()
 public:
     // construction
     wxTopLevelWindowGTK() { Init(); }
 public:
     // construction
     wxTopLevelWindowGTK() { Init(); }
@@ -85,6 +86,9 @@ public:
     // GTK callbacks
     virtual void OnInternalIdle();
 
     // GTK callbacks
     virtual void OnInternalIdle();
 
+    // Respond to system colour change
+    void OnSysColourChanged(wxSysColourChangedEvent& event);
+
     // do *not* call this to iconize the frame, this is a private function!
     void SetIconizeState(bool iconic);
 
     // do *not* call this to iconize the frame, this is a private function!
     void SetIconizeState(bool iconic);
 
index 28503b6538653de13306bf2bdb14ef85ae1690bd..bae1558d8a7286a78f3e6926b11e2f6f7e5516b4 100644 (file)
@@ -452,6 +452,11 @@ static gboolean property_notify_event(
 }
 }
 
 }
 }
 
+BEGIN_EVENT_TABLE(wxTopLevelWindowGTK, wxTopLevelWindowBase)
+    EVT_SYS_COLOUR_CHANGED(wxTopLevelWindowGTK::OnSysColourChanged)
+END_EVENT_TABLE()
+
+
 // ----------------------------------------------------------------------------
 // wxTopLevelWindowGTK creation
 // ----------------------------------------------------------------------------
 // ----------------------------------------------------------------------------
 // wxTopLevelWindowGTK creation
 // ----------------------------------------------------------------------------
@@ -1282,3 +1287,16 @@ bool wxTopLevelWindowGTK::CanSetTransparent()
                            "Composite", &opcode, &event, &error);
 #endif
 }
                            "Composite", &opcode, &event, &error);
 #endif
 }
+
+void wxTopLevelWindowGTK::OnSysColourChanged(wxSysColourChangedEvent& event)
+{
+    // We don't know the order in which top-level windows will
+    // be notified, so we need to clear the system objects
+    // for each top-level window.
+    extern void wxClearGtkSystemObjects();
+    wxClearGtkSystemObjects();
+
+    // wxWindowBase::OnSysColourChanged will propagate event
+    // to children
+    event.Skip();
+}
index f7c8f27795c944853aa2d112400ec885e7286f65..fdfa1b8f63f3b61bdf3d5d054bc59d7103ead243 100644 (file)
@@ -2116,8 +2116,65 @@ gtk_window_grab_broken( GtkWidget*,
 }
 #endif
 
 }
 #endif
 
+//-----------------------------------------------------------------------------
+// "style_set"
+//-----------------------------------------------------------------------------
+
+static
+void gtk_window_style_set_callback( GtkWidget *WXUNUSED(widget),
+                               GtkStyle *previous_style,
+                               wxWindow* win )
+{
+    //wxLogDebug(wxT("gtk_window_style_set_callback"));
+    if (win && previous_style)
+    {
+        wxString name(win->GetName());
+        //wxLogDebug(wxT("gtk_window_style_set_callback %s"), name.c_str());
+        wxSysColourChangedEvent event;
+        event.SetEventObject(win);
+
+        win->GTKProcessEvent( event );
+    }
+}
+
 } // extern "C"
 
 } // extern "C"
 
+// Connect/disconnect style-set
+
+void wxConnectStyleSet(wxWindow* win)
+{
+    if (win->m_wxwindow)
+        g_signal_connect (win->m_wxwindow, "style_set",
+                              G_CALLBACK (gtk_window_style_set_callback), win);
+}
+
+void wxDisconnectStyleSet(wxWindow* win)
+{
+  if (win->m_wxwindow)
+      g_signal_handlers_disconnect_by_func (win->m_wxwindow,
+                                          (gpointer) gtk_window_style_set_callback,
+                                              win);
+}
+
+// Helper to suspend colour change event event processing while we change a widget's style
+class wxSuspendStyleEvents
+{
+public:
+  wxSuspendStyleEvents(wxWindow* win)
+  {
+    m_win = win;
+    if (win->IsTopLevel())
+      wxDisconnectStyleSet(win);
+  }
+  ~wxSuspendStyleEvents()
+  {
+    if (m_win->IsTopLevel())
+      wxConnectStyleSet(m_win);
+  }
+
+  wxWindow* m_win;
+};
+
 // ----------------------------------------------------------------------------
 // this wxWindowBase function is implemented here (in platform-specific file)
 // because it is static and so couldn't be made virtual
 // ----------------------------------------------------------------------------
 // this wxWindowBase function is implemented here (in platform-specific file)
 // because it is static and so couldn't be made virtual
@@ -2614,6 +2671,10 @@ void wxWindowGTK::ConnectWidget( GtkWidget *widget )
                       G_CALLBACK (gtk_window_enter_callback), this);
     g_signal_connect (widget, "leave_notify_event",
                       G_CALLBACK (gtk_window_leave_callback), this);
                       G_CALLBACK (gtk_window_enter_callback), this);
     g_signal_connect (widget, "leave_notify_event",
                       G_CALLBACK (gtk_window_leave_callback), this);
+
+    if (IsTopLevel() && m_wxwindow)
+        g_signal_connect (m_wxwindow, "style_set",
+                              G_CALLBACK (gtk_window_style_set_callback), this);
 }
 
 bool wxWindowGTK::Destroy()
 }
 
 bool wxWindowGTK::Destroy()
@@ -3918,6 +3979,8 @@ void wxWindowGTK::ApplyWidgetStyle(bool forceStyle)
 
 void wxWindowGTK::DoApplyWidgetStyle(GtkRcStyle *style)
 {
 
 void wxWindowGTK::DoApplyWidgetStyle(GtkRcStyle *style)
 {
+    wxSuspendStyleEvents s(this);
+
     if (m_wxwindow)
         gtk_widget_modify_style(m_wxwindow, style);
     else
     if (m_wxwindow)
         gtk_widget_modify_style(m_wxwindow, style);
     else