Get(Class)DefaultAttributes() for wxGTK controls

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@27115 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robin Dunn
2004-05-06 17:26:25 +00:00
parent 3cfd077ff8
commit 9d522606d0
84 changed files with 852 additions and 34 deletions

View File

@@ -232,5 +232,12 @@ wxSize wxButton::DoGetBestSize() const
return ret;
}
// static
wxVisualAttributes
wxButton::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))
{
return GetDefaultAttributesFromGTKWidget(gtk_button_new);
}
#endif // wxUSE_BUTTON

View File

@@ -216,4 +216,11 @@ wxSize wxCheckBox::DoGetBestSize() const
return wxControl::DoGetBestSize();
}
// static
wxVisualAttributes
wxCheckBox::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))
{
return GetDefaultAttributesFromGTKWidget(gtk_check_button_new);
}
#endif

View File

@@ -574,6 +574,13 @@ bool wxChoice::IsOwnGtkWindow( GdkWindow *window )
#endif
}
// static
wxVisualAttributes
wxChoice::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))
{
return GetDefaultAttributesFromGTKWidget(gtk_option_menu_new);
}
#endif // wxUSE_CHOICE

View File

@@ -779,4 +779,11 @@ wxSize wxComboBox::DoGetBestSize() const
return ret;
}
// static
wxVisualAttributes
wxComboBox::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))
{
return GetDefaultAttributesFromGTKWidget(gtk_combo_new, true);
}
#endif

View File

@@ -19,6 +19,8 @@
#if wxUSE_CONTROLS
#include "wx/control.h"
#include "wx/fontutil.h"
#include "wx/settings.h"
#include <gtk/gtk.h>
@@ -140,5 +142,123 @@ wxString wxControl::PrepareLabelMnemonics( const wxString &label ) const
}
#endif
wxVisualAttributes wxControl::GetDefaultAttributes() const
{
return GetDefaultAttributesFromGTKWidget(m_widget,
UseGTKStyleBase());
}
#define SHIFT (8*(sizeof(short int)-sizeof(char)))
// static
wxVisualAttributes
wxControl::GetDefaultAttributesFromGTKWidget(GtkWidget* widget,
bool useBase,
int state)
{
GtkStyle* style;
wxVisualAttributes attr;
style = gtk_rc_get_style(widget);
if (!style)
style = gtk_widget_get_default_style();
if (!style)
{
return wxWindow::GetClassDefaultAttributes(wxWINDOW_VARIANT_NORMAL);
}
if (state == -1)
state = GTK_STATE_NORMAL;
// get the style's colours
attr.colFg = wxColour(style->fg[state].red >> SHIFT,
style->fg[state].green >> SHIFT,
style->fg[state].blue >> SHIFT);
if (useBase)
attr.colBg = wxColour(style->base[state].red >> SHIFT,
style->base[state].green >> SHIFT,
style->base[state].blue >> SHIFT);
else
attr.colBg = wxColour(style->bg[state].red >> SHIFT,
style->bg[state].green >> SHIFT,
style->bg[state].blue >> SHIFT);
// get the style's font
#ifdef __WXGTK20__
if ( !style->font_desc )
style = gtk_widget_get_default_style();
if ( style && style->font_desc )
{
wxNativeFontInfo info;
info.description = style->font_desc;
attr.font = wxFont(info);
}
else
{
GtkSettings *settings = gtk_settings_get_default();
gchar *font_name = NULL;
g_object_get ( settings,
"gtk-font-name",
&font_name,
NULL);
if (!font_name)
attr.font = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT );
else
attr.font = wxFont(wxString::FromAscii(font_name));
g_free (font_name);
}
#else
// TODO: isn't there a way to get a standard gtk 1.2 font?
attr.font = wxFont( 12, wxSWISS, wxNORMAL, wxNORMAL );
#endif
return attr;
}
//static
wxVisualAttributes
wxControl::GetDefaultAttributesFromGTKWidget(GtkWidget* (*widget_new)(void),
bool useBase,
int state)
{
wxVisualAttributes attr;
GtkWidget* widget = widget_new();
attr = GetDefaultAttributesFromGTKWidget(widget, useBase, state);
gtk_widget_destroy(widget);
return attr;
}
//static
wxVisualAttributes
wxControl::GetDefaultAttributesFromGTKWidget(GtkWidget* (*widget_new)(const gchar*),
bool useBase,
int state)
{
wxVisualAttributes attr;
GtkWidget* widget = widget_new("");
attr = GetDefaultAttributesFromGTKWidget(widget, useBase, state);
gtk_widget_destroy(widget);
return attr;
}
//static
wxVisualAttributes
wxControl::GetDefaultAttributesFromGTKWidget(GtkWidget* (*widget_new)(GtkAdjustment*),
bool useBase,
int state)
{
wxVisualAttributes attr;
GtkWidget* widget = widget_new(NULL);
attr = GetDefaultAttributesFromGTKWidget(widget, useBase, state);
gtk_widget_destroy(widget);
return attr;
}
#endif // wxUSE_CONTROLS

View File

@@ -112,5 +112,22 @@ void wxGauge::ApplyWidgetStyle()
gtk_widget_set_style( m_widget, m_widgetStyle );
}
wxVisualAttributes wxGauge::GetDefaultAttributes() const
{
// Visible gauge colours use a different colour state
return GetDefaultAttributesFromGTKWidget(m_widget,
UseGTKStyleBase(),
GTK_STATE_ACTIVE);
}
// static
wxVisualAttributes
wxGauge::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))
{
return GetDefaultAttributesFromGTKWidget(gtk_progress_bar_new,
false, GTK_STATE_ACTIVE);
}
#endif // wxUSE_GAUGE

View File

@@ -1087,5 +1087,13 @@ void wxListBox::FixUpMouseEvent(GtkWidget *widget, wxCoord& x, wxCoord& y)
y += widget->allocation.y;
}
// static
wxVisualAttributes
wxListBox::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))
{
return GetDefaultAttributesFromGTKWidget(gtk_list_new, true);
}
#endif // wxUSE_LISTBOX

View File

@@ -866,6 +866,13 @@ bool wxNotebook::SetFont(const wxFont& font)
return rc;
}
// static
wxVisualAttributes
wxNotebook::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))
{
return GetDefaultAttributesFromGTKWidget(gtk_notebook_new);
}
//-----------------------------------------------------------------------------
// wxNotebookEvent
//-----------------------------------------------------------------------------

View File

@@ -752,5 +752,16 @@ void wxRadioBox::OnInternalIdle()
}
}
// static
wxVisualAttributes
wxRadioBox::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))
{
wxVisualAttributes attr;
GtkWidget* widget = gtk_radio_button_new_with_label(NULL, "");
attr = GetDefaultAttributesFromGTKWidget(widget);
gtk_widget_destroy(widget);
return attr;
}
#endif // wxUSE_RADIOBOX

View File

@@ -233,4 +233,16 @@ wxSize wxRadioButton::DoGetBestSize() const
return wxControl::DoGetBestSize();
}
// static
wxVisualAttributes
wxRadioButton::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))
{
wxVisualAttributes attr;
GtkWidget* widget = gtk_radio_button_new_with_label(NULL, "");
attr = GetDefaultAttributesFromGTKWidget(widget);
gtk_widget_destroy(widget);
return attr;
}
#endif

View File

@@ -336,4 +336,11 @@ wxSize wxScrollBar::DoGetBestSize() const
return wxControl::DoGetBestSize();
}
// static
wxVisualAttributes
wxScrollBar::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))
{
return GetDefaultAttributesFromGTKWidget(gtk_vscrollbar_new);
}
#endif

View File

@@ -286,4 +286,11 @@ void wxSlider::GtkEnableEvents()
(gpointer) this );
}
// static
wxVisualAttributes
wxSlider::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))
{
return GetDefaultAttributesFromGTKWidget(gtk_vscale_new);
}
#endif

View File

@@ -236,4 +236,13 @@ wxSize wxSpinButton::DoGetBestSize() const
return wxSize(15, 26);
}
// static
wxVisualAttributes
wxSpinButton::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))
{
// TODO: overload to accept functions like gtk_spin_button_new?
// Until then use a similar type
return GetDefaultAttributesFromGTKWidget(gtk_button_new);
}
#endif

View File

@@ -310,5 +310,14 @@ wxSize wxSpinCtrl::DoGetBestSize() const
return wxSize(95, ret.y);
}
// static
wxVisualAttributes
wxSpinCtrl::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))
{
// TODO: overload to accept functions like gtk_spin_button_new?
// Until then use a similar type
return GetDefaultAttributesFromGTKWidget(gtk_entry_new, true);
}
#endif
// wxUSE_SPINCTRL

View File

@@ -117,5 +117,13 @@ void wxStaticBitmap::SetBitmap( const wxBitmap &bitmap )
}
}
// static
wxVisualAttributes
wxStaticBitmap::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))
{
// TODO: overload to allow using gtk_pixmap_new?
return GetDefaultAttributesFromGTKWidget(gtk_label_new);
}
#endif // wxUSE_STATBMP

View File

@@ -97,4 +97,11 @@ void wxStaticBox::ApplyWidgetStyle()
gtk_widget_set_style( m_widget, m_widgetStyle );
}
// static
wxVisualAttributes
wxStaticBox::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))
{
return GetDefaultAttributesFromGTKWidget(gtk_frame_new);
}
#endif // wxUSE_STATBOX

View File

@@ -79,4 +79,11 @@ bool wxStaticLine::Create( wxWindow *parent, wxWindowID id,
return TRUE;
}
// static
wxVisualAttributes
wxStaticLine::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))
{
return GetDefaultAttributesFromGTKWidget(gtk_vseparator_new);
}
#endif

View File

@@ -199,4 +199,11 @@ bool wxStaticText::SetForegroundColour(const wxColour& colour)
return true;
}
// static
wxVisualAttributes
wxStaticText::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))
{
return GetDefaultAttributesFromGTKWidget(gtk_label_new);
}
#endif // wxUSE_STATTEXT

View File

@@ -703,4 +703,22 @@ void wxToolBar::OnInternalIdle()
UpdateWindowUI(wxUPDATE_UI_FROMIDLE);
}
// ----------------------------------------------------------------------------
// static
wxVisualAttributes
wxToolBar::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))
{
#ifdef __WXGTK20__
return GetDefaultAttributesFromGTKWidget(gtk_toolbar_new);
#else
wxVisualAttributes attr;
GtkWidget* widget = gtk_toolbar_new(GTK_ORIENTATION_HORIZONTAL, GTK_TOOLBAR_BOTH);
attr = GetDefaultAttributesFromGTKWidget(widget);
gtk_widget_destroy(widget);
return attr;
#endif
}
#endif // wxUSE_TOOLBAR_NATIVE

View File

@@ -303,7 +303,7 @@ bool wxTextCtrl::Create( wxWindow *parent,
gtk_container_add( GTK_CONTAINER(m_widget), m_text );
// Global settings which can be overridden by tags, I guess.
if (HasFlag( wxHSCROLL ))
if (HasFlag( wxHSCROLL ) || HasFlag( wxTE_DONTWRAP ))
gtk_text_view_set_wrap_mode( GTK_TEXT_VIEW( m_text ), GTK_WRAP_NONE );
else
gtk_text_view_set_wrap_mode( GTK_TEXT_VIEW( m_text ), GTK_WRAP_WORD );
@@ -415,16 +415,16 @@ bool wxTextCtrl::Create( wxWindow *parent,
#ifdef __WXGTK20__
else
gtk_text_view_set_editable( GTK_TEXT_VIEW( m_text), FALSE);
}
#else
}
else
{
if (multi_line)
gtk_text_set_editable( GTK_TEXT(m_text), 1 );
}
#endif
}
// We want to be notified about text changes.
#ifdef __WXGTK20__
if (multi_line)
@@ -434,26 +434,21 @@ bool wxTextCtrl::Create( wxWindow *parent,
}
else
#endif
{
gtk_signal_connect( GTK_OBJECT(m_text), "changed",
GTK_SIGNAL_FUNC(gtk_text_changed_callback), (gpointer)this);
}
// we don't set a valid background colour, because the window
// manager should use a default one
m_backgroundColour = wxColour();
wxColour colFg = parent->GetForegroundColour();
SetForegroundColour( colFg );
m_cursor = wxCursor( wxCURSOR_IBEAM );
wxTextAttr attrDef( colFg, m_backgroundColour, parent->GetFont() );
wxTextAttr attrDef(GetForegroundColour(), GetBackgroundColour(), GetFont());
SetDefaultStyle( attrDef );
return TRUE;
}
void wxTextCtrl::CalculateScrollbar()
{
#ifndef __WXGTK20__
@@ -1522,11 +1517,11 @@ bool wxTextCtrl::SetStyle( long start, long end, const wxTextAttr& style )
void wxTextCtrl::ApplyWidgetStyle()
{
if (m_windowStyle & wxTE_MULTILINE)
{
// how ?
}
else
// if (m_windowStyle & wxTE_MULTILINE)
// {
// // how ?
// }
// else
{
SetWidgetStyle();
gtk_widget_set_style( m_text, m_widgetStyle );
@@ -1724,3 +1719,10 @@ bool wxTextCtrl::ScrollPages(int pages)
#endif
}
// static
wxVisualAttributes
wxTextCtrl::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))
{
return GetDefaultAttributesFromGTKWidget(gtk_entry_new, true);
}

View File

@@ -207,6 +207,16 @@ wxSize wxToggleBitmapButton::DoGetBestSize() const
}
return best;
}
// static
wxVisualAttributes
wxToggleBitmapButton::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))
{
return GetDefaultAttributesFromGTKWidget(gtk_toggle_button_new);
}
// ------------------------------------------------------------------------
// wxToggleButton
// ------------------------------------------------------------------------
@@ -339,5 +349,12 @@ wxSize wxToggleButton::DoGetBestSize() const
return ret;
}
// static
wxVisualAttributes
wxToggleButton::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))
{
return GetDefaultAttributesFromGTKWidget(gtk_toggle_button_new);
}
#endif // wxUSE_TOGGLEBTN