]> git.saurik.com Git - wxWidgets.git/blobdiff - src/gtk/control.cpp
added new files which were generated by bakefile but were not in cvs for some reason
[wxWidgets.git] / src / gtk / control.cpp
index 7f5b15bf08ccc30754cd3519b4fef327299915a3..afcd65c371cddc79074d76b6718b2854bfdc17c3 100644 (file)
@@ -4,13 +4,9 @@
 // Author:      Robert Roebling
 // Id:          $Id$
 // Copyright:   (c) 1998 Robert Roebling, Julian Smart and Vadim Zeitlin
-// Licence:     wxWidgets licence
+// Licence:     wxWindows licence
 /////////////////////////////////////////////////////////////////////////////
 
-#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
-#pragma implementation "control.h"
-#endif
-
 // For compilers that support precompilation, includes "wx.h".
 #include "wx/wxprec.h"
 
@@ -66,6 +62,7 @@ void wxControl::SetLabel( const wxString &label )
         }
         m_label << *pc;
     }
+    InvalidateBestSize();    
 }
 
 wxString wxControl::GetLabel() const
@@ -85,14 +82,23 @@ wxSize wxControl::DoGetBestSize() const
     (* GTK_WIDGET_CLASS( GTK_OBJECT_GET_CLASS(m_widget) )->size_request )
         (m_widget, &req );
 
-    return wxSize(req.width, req.height);
+    wxSize best(req.width, req.height);
+    CacheBestSize(best);
+    return best;
 }
 
 
 void wxControl::PostCreation(const wxSize& size)
 {
     wxWindow::PostCreation();
-    InheritAttributes();
+
+    // NB: GetBestSize needs to know the style, otherwise it will assume
+    //     default font and if the user uses a different font, determined
+    //     best size will be different (typically, smaller) than the desired
+    //     size. This call ensure that a style is available at the time
+    //     GetBestSize is called.
+    gtk_widget_ensure_style(m_widget);
+    
     ApplyWidgetStyle();
     SetInitialBestSize(size);
 }
@@ -193,7 +199,7 @@ wxControl::GetDefaultAttributesFromGTKWidget(GtkWidget* widget,
     if ( style && style->font_desc )
     {  
         wxNativeFontInfo info;  
-        info.description = style->font_desc;  
+        info.description = pango_font_description_copy(style->font_desc);
         attr.font = wxFont(info);  
     }  
     else  
@@ -221,44 +227,52 @@ wxControl::GetDefaultAttributesFromGTKWidget(GtkWidget* widget,
 
 //static
 wxVisualAttributes
-wxControl::GetDefaultAttributesFromGTKWidget(GtkWidget* (*widget_new)(void),
+wxControl::GetDefaultAttributesFromGTKWidget(wxGtkWidgetNew_t widget_new,
                                              bool useBase,
                                              int state)
 {
     wxVisualAttributes attr;
+    // NB: we need toplevel window so that GTK+ can find the right style
+    GtkWidget *wnd = gtk_window_new(GTK_WINDOW_TOPLEVEL);
     GtkWidget* widget = widget_new();
+    gtk_container_add(GTK_CONTAINER(wnd), widget);
     attr = GetDefaultAttributesFromGTKWidget(widget, useBase, state);
-    gtk_widget_destroy(widget);
+    gtk_widget_destroy(wnd);
     return attr;
 }
 
 //static
 wxVisualAttributes
-wxControl::GetDefaultAttributesFromGTKWidget(GtkWidget* (*widget_new)(const gchar*),
+wxControl::GetDefaultAttributesFromGTKWidget(wxGtkWidgetNewFromStr_t widget_new,
                                              bool useBase,
                                              int state)
 {
     wxVisualAttributes attr;
+    // NB: we need toplevel window so that GTK+ can find the right style
+    GtkWidget *wnd = gtk_window_new(GTK_WINDOW_TOPLEVEL);
     GtkWidget* widget = widget_new("");
+    gtk_container_add(GTK_CONTAINER(wnd), widget);
     attr = GetDefaultAttributesFromGTKWidget(widget, useBase, state);
-    gtk_widget_destroy(widget);
+    gtk_widget_destroy(wnd);
     return attr;
 }
 
 
 //static
 wxVisualAttributes
-wxControl::GetDefaultAttributesFromGTKWidget(GtkWidget* (*widget_new)(GtkAdjustment*),
+wxControl::GetDefaultAttributesFromGTKWidget(wxGtkWidgetNewFromAdj_t widget_new,
                                              bool useBase,
                                              int state)
 {
     wxVisualAttributes attr;
+    // NB: we need toplevel window so that GTK+ can find the right style
+    GtkWidget *wnd = gtk_window_new(GTK_WINDOW_TOPLEVEL);
     GtkWidget* widget = widget_new(NULL);
+    gtk_container_add(GTK_CONTAINER(wnd), widget);
     attr = GetDefaultAttributesFromGTKWidget(widget, useBase, state);
-    gtk_widget_destroy(widget);
+    gtk_widget_destroy(wnd);
     return attr;
 }
 
-
 #endif // wxUSE_CONTROLS