Added SetFont to most controls and controls sample
(recompile) Added tiny bit of documentation to window.cpp git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@676 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -103,3 +103,26 @@ void wxButton::Enable( bool enable )
|
||||
gtk_widget_set_sensitive( label, enable );
|
||||
}
|
||||
|
||||
void wxButton::SetFont( const wxFont &font )
|
||||
{
|
||||
m_font = font;
|
||||
|
||||
GtkButton *bin = GTK_BUTTON( m_widget );
|
||||
GtkWidget *label = bin->child;
|
||||
|
||||
GtkStyle *style = (GtkStyle*) NULL;
|
||||
if (!m_hasOwnStyle)
|
||||
{
|
||||
m_hasOwnStyle = TRUE;
|
||||
style = gtk_style_copy( gtk_widget_get_style( label ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
style = gtk_widget_get_style( label );
|
||||
}
|
||||
|
||||
gdk_font_unref( style->font );
|
||||
style->font = gdk_font_ref( m_font.GetInternalFont( 1.0 ) );
|
||||
|
||||
gtk_widget_set_style( label, style );
|
||||
}
|
||||
|
@@ -89,3 +89,26 @@ bool wxCheckBox::GetValue(void) const
|
||||
return tb->active;
|
||||
}
|
||||
|
||||
void wxCheckBox::SetFont( const wxFont &font )
|
||||
{
|
||||
m_font = font;
|
||||
|
||||
GtkButton *bin = GTK_BUTTON( m_widget );
|
||||
GtkWidget *label = bin->child;
|
||||
|
||||
GtkStyle *style = (GtkStyle*) NULL;
|
||||
if (!m_hasOwnStyle)
|
||||
{
|
||||
m_hasOwnStyle = TRUE;
|
||||
style = gtk_style_copy( gtk_widget_get_style( label ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
style = gtk_widget_get_style( label );
|
||||
}
|
||||
|
||||
gdk_font_unref( style->font );
|
||||
style->font = gdk_font_ref( m_font.GetInternalFont( 1.0 ) );
|
||||
|
||||
gtk_widget_set_style( label, style );
|
||||
}
|
||||
|
@@ -92,8 +92,18 @@ void wxChoice::Append( const wxString &item )
|
||||
GtkWidget *menu = gtk_option_menu_get_menu( GTK_OPTION_MENU(m_widget) );
|
||||
GtkWidget *menu_item;
|
||||
menu_item = gtk_menu_item_new_with_label( item );
|
||||
|
||||
if (m_hasOwnStyle)
|
||||
{
|
||||
GtkBin *bin = GTK_BIN( menu_item );
|
||||
gtk_widget_set_style( bin->child,
|
||||
gtk_style_ref(
|
||||
gtk_widget_get_style( m_widget ) ) );
|
||||
}
|
||||
|
||||
gtk_signal_connect( GTK_OBJECT( menu_item ), "activate",
|
||||
GTK_SIGNAL_FUNC(gtk_choice_clicked_callback), (gpointer*)this );
|
||||
|
||||
gtk_menu_append( GTK_MENU(menu), menu_item );
|
||||
gtk_widget_show( menu_item );
|
||||
}
|
||||
@@ -123,10 +133,10 @@ int wxChoice::FindString( const wxString &string ) const
|
||||
GtkBin *bin = GTK_BIN( child->data );
|
||||
GtkLabel *label = (GtkLabel *) NULL;
|
||||
if (bin->child) label = GTK_LABEL(bin->child);
|
||||
if (!label) label = GTK_LABEL( GTK_BUTTON(m_widget)->child );
|
||||
|
||||
wxASSERT_MSG( label != NULL , "wxChoice: invalid label" );
|
||||
|
||||
if (!label) label = GTK_LABEL( GTK_BUTTON(m_widget)->child );
|
||||
if (string == label->label) return count;
|
||||
child = child->next;
|
||||
count++;
|
||||
@@ -172,10 +182,10 @@ wxString wxChoice::GetString( int n ) const
|
||||
{
|
||||
GtkLabel *label = (GtkLabel *) NULL;
|
||||
if (bin->child) label = GTK_LABEL(bin->child);
|
||||
if (!label) label = GTK_LABEL( GTK_BUTTON(m_widget)->child );
|
||||
|
||||
wxASSERT_MSG( label != NULL , "wxChoice: invalid label" );
|
||||
|
||||
if (!label) label = GTK_LABEL( GTK_BUTTON(m_widget)->child );
|
||||
return label->label;
|
||||
}
|
||||
child = child->next;
|
||||
@@ -227,3 +237,23 @@ void wxChoice::SetStringSelection( const wxString &string )
|
||||
if (n != -1) SetSelection( n );
|
||||
}
|
||||
|
||||
void wxChoice::SetFont( const wxFont &font )
|
||||
{
|
||||
wxWindow::SetFont( font );
|
||||
|
||||
GtkMenuShell *menu_shell = GTK_MENU_SHELL( gtk_option_menu_get_menu( GTK_OPTION_MENU(m_widget) ) );
|
||||
GList *child = menu_shell->children;
|
||||
while (child)
|
||||
{
|
||||
GtkBin *bin = GTK_BIN( child->data );
|
||||
GtkWidget *label = (GtkWidget *) NULL;
|
||||
if (bin->child) label = bin->child;
|
||||
if (!label) label = GTK_BUTTON(m_widget)->child;
|
||||
|
||||
gtk_widget_set_style( label,
|
||||
gtk_style_ref(
|
||||
gtk_widget_get_style( m_widget ) ) );
|
||||
|
||||
child = child->next;
|
||||
}
|
||||
}
|
||||
|
@@ -136,8 +136,15 @@ void wxComboBox::Append( const wxString &item, char *clientData )
|
||||
{
|
||||
GtkWidget *list = GTK_COMBO(m_widget)->list;
|
||||
|
||||
GtkWidget *list_item;
|
||||
list_item = gtk_list_item_new_with_label( item );
|
||||
GtkWidget *list_item = gtk_list_item_new_with_label( item );
|
||||
|
||||
if (m_hasOwnStyle)
|
||||
{
|
||||
GtkBin *bin = GTK_BIN( list_item );
|
||||
gtk_widget_set_style( bin->child,
|
||||
gtk_style_ref(
|
||||
gtk_widget_get_style( m_widget ) ) );
|
||||
}
|
||||
|
||||
gtk_signal_connect( GTK_OBJECT(list_item), "select",
|
||||
GTK_SIGNAL_FUNC(gtk_combo_clicked_callback), (gpointer)this );
|
||||
@@ -374,4 +381,27 @@ void wxComboBox::SetEditable( bool WXUNUSED(editable) )
|
||||
{
|
||||
}
|
||||
|
||||
void wxComboBox::SetFont( const wxFont &font )
|
||||
{
|
||||
wxWindow::SetFont( font );
|
||||
|
||||
GtkWidget *entry = GTK_COMBO(m_widget)->entry;
|
||||
|
||||
gtk_widget_set_style( entry,
|
||||
gtk_style_ref(
|
||||
gtk_widget_get_style( m_widget ) ) );
|
||||
|
||||
GtkWidget *list = GTK_COMBO(m_widget)->list;
|
||||
|
||||
GList *child = GTK_LIST(list)->children;
|
||||
while (child)
|
||||
{
|
||||
GtkBin *bin = (GtkBin*) child->data;
|
||||
gtk_widget_set_style( bin->child,
|
||||
gtk_style_ref(
|
||||
gtk_widget_get_style( m_widget ) ) );
|
||||
|
||||
child = child->next;
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -130,8 +130,15 @@ void wxListBox::Append( const wxString &item )
|
||||
|
||||
void wxListBox::Append( const wxString &item, char *clientData )
|
||||
{
|
||||
GtkWidget *list_item;
|
||||
list_item = gtk_list_item_new_with_label( item );
|
||||
GtkWidget *list_item = gtk_list_item_new_with_label( item );
|
||||
|
||||
if (m_hasOwnStyle)
|
||||
{
|
||||
GtkBin *bin = GTK_BIN( list_item );
|
||||
gtk_widget_set_style( bin->child,
|
||||
gtk_style_ref(
|
||||
gtk_widget_get_style( m_widget ) ) );
|
||||
}
|
||||
|
||||
gtk_signal_connect( GTK_OBJECT(list_item), "select",
|
||||
GTK_SIGNAL_FUNC(gtk_listitem_select_callback), (gpointer)this );
|
||||
@@ -230,7 +237,8 @@ int wxListBox::GetSelections(wxArrayInt& aSelections) const
|
||||
// get the number of selected items first
|
||||
GList *child = m_list->children;
|
||||
int count = 0;
|
||||
for ( child = m_list->children; child != NULL; child = child->next ) {
|
||||
for ( child = m_list->children; child != NULL; child = child->next )
|
||||
{
|
||||
if ( GTK_WIDGET(child->data)->state == GTK_STATE_SELECTED )
|
||||
count++;
|
||||
}
|
||||
@@ -241,7 +249,8 @@ int wxListBox::GetSelections(wxArrayInt& aSelections) const
|
||||
// now fill the list
|
||||
aSelections.Alloc(count); // optimization attempt
|
||||
int i = 0;
|
||||
for ( child = m_list->children; child != NULL; child = child->next, i++ ) {
|
||||
for ( child = m_list->children; child != NULL; child = child->next, i++ )
|
||||
{
|
||||
if ( GTK_WIDGET(child->data)->state == GTK_STATE_SELECTED )
|
||||
aSelections.Add(i);
|
||||
}
|
||||
@@ -377,5 +386,19 @@ GtkWidget *wxListBox::GetConnectWidget(void)
|
||||
return GTK_WIDGET(m_list);
|
||||
}
|
||||
|
||||
void wxListBox::SetFont( const wxFont &font )
|
||||
{
|
||||
wxWindow::SetFont( font );
|
||||
|
||||
GList *child = m_list->children;
|
||||
while (child)
|
||||
{
|
||||
GtkBin *bin = (GtkBin*) child->data;
|
||||
gtk_widget_set_style( bin->child,
|
||||
gtk_style_ref(
|
||||
gtk_widget_get_style( m_widget ) ) );
|
||||
child = child->next;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@@ -279,3 +279,19 @@ void wxRadioBox::SetNumberOfRowsOrCols( int WXUNUSED(n) )
|
||||
wxFAIL_MSG("wxRadioBox::SetNumberOfRowsOrCols not implemented.");
|
||||
}
|
||||
|
||||
void wxRadioBox::SetFont( const wxFont &font )
|
||||
{
|
||||
wxWindow::SetFont( font );
|
||||
|
||||
GSList *item = gtk_radio_button_group( m_radio );
|
||||
while (item)
|
||||
{
|
||||
GtkButton *button = GTK_BUTTON( item->data );
|
||||
|
||||
gtk_widget_set_style( button->child,
|
||||
gtk_style_ref(
|
||||
gtk_widget_get_style( m_widget ) ) );
|
||||
|
||||
item = item->next;
|
||||
}
|
||||
}
|
||||
|
@@ -86,4 +86,27 @@ bool wxRadioButton::GetValue(void) const
|
||||
return GTK_TOGGLE_BUTTON(m_widget)->active;
|
||||
}
|
||||
|
||||
void wxRadioButton::SetFont( const wxFont &font )
|
||||
{
|
||||
m_font = font;
|
||||
|
||||
GtkButton *bin = GTK_BUTTON( m_widget );
|
||||
GtkWidget *label = bin->child;
|
||||
|
||||
GtkStyle *style = (GtkStyle*) NULL;
|
||||
if (!m_hasOwnStyle)
|
||||
{
|
||||
m_hasOwnStyle = TRUE;
|
||||
style = gtk_style_copy( gtk_widget_get_style( label ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
style = gtk_widget_get_style( label );
|
||||
}
|
||||
|
||||
gdk_font_unref( style->font );
|
||||
style->font = gdk_font_ref( m_font.GetInternalFont( 1.0 ) );
|
||||
|
||||
gtk_widget_set_style( label, style );
|
||||
}
|
||||
|
||||
|
@@ -429,5 +429,25 @@ bool wxTextCtrl::IsOwnGtkWindow( GdkWindow *window )
|
||||
return (window == GTK_ENTRY(m_text)->text_area);
|
||||
}
|
||||
|
||||
void wxTextCtrl::SetFont( const wxFont &font )
|
||||
{
|
||||
m_font = font;
|
||||
|
||||
GtkStyle *style = (GtkStyle*) NULL;
|
||||
if (!m_hasOwnStyle)
|
||||
{
|
||||
m_hasOwnStyle = TRUE;
|
||||
style = gtk_style_copy( gtk_widget_get_style( m_text ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
style = gtk_widget_get_style( m_text );
|
||||
}
|
||||
|
||||
gdk_font_unref( style->font );
|
||||
style->font = gdk_font_ref( m_font.GetInternalFont( 1.0 ) );
|
||||
|
||||
gtk_widget_set_style( m_text, style );
|
||||
}
|
||||
|
||||
|
||||
|
@@ -34,6 +34,80 @@
|
||||
#include "wx/gtk/win_gtk.h"
|
||||
#include "gdk/gdkprivate.h"
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// documentation on internals
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
/*
|
||||
I have been asked several times about writing some documentation about
|
||||
the GTK port of wxWindows, especially its internal structures. Obviously,
|
||||
you cannot understand wxGTK without knowing a little about the GTK, but
|
||||
some more information about what the wxWindow, which is the base class
|
||||
for all other window classes, does seems required as well.
|
||||
|
||||
What does wxWindow do? It contains the common interface for the following
|
||||
jobs of its descentants:
|
||||
|
||||
1) Define the rudimentary behaviour common to all window classes, such as
|
||||
resizing, intercepting user input so as to make it possible to use these
|
||||
events for special purposes in a derived class, window names etc.
|
||||
|
||||
2) Provide the possibility to contain and manage children, if the derived
|
||||
class is allowed to contain children, which holds true for those window
|
||||
classes, which do not display a native GTK widget. To name them, these
|
||||
classes are wxPanel, wxScrolledWindow, wxDialog, wxFrame. The MDI frame-
|
||||
work classes are a special case and are handled a bit differently from
|
||||
the rest.
|
||||
|
||||
3) Provide the possibility to draw into a client area of a window. This,
|
||||
too, only holds true for classes that do not display a native GTK widget
|
||||
as above.
|
||||
|
||||
4) Provide the entire mechanism for scrolling widgets. This actaul inter-
|
||||
face for this is usually in wxScrolledWidget, but the GTK implementation
|
||||
is in this class.
|
||||
|
||||
5) A multitude of helper or extra methods for special purposes, such as
|
||||
Drag'n'Drop, managing validators etc.
|
||||
|
||||
Normally one might expect, that one wxWindows class would always contain
|
||||
one GTK widget. Under GTK, there is no such allround widget that has all
|
||||
the functionality. Moreover, the GTK defines a client area as a different
|
||||
widget from the actual widget you are handling. Last but not least some
|
||||
special classes (e.g. wxFrame) handle different categories of widgets and
|
||||
still have the possibility to draw something in the client area.
|
||||
It was therefore required to write a special purpose GTK widget, that would
|
||||
represent a client area in the sense of wxWindows capable to do the jobs
|
||||
2), 3) and 4). I have written this class and it resides in win_gtk.c of
|
||||
this directory.
|
||||
|
||||
All windows must have a widget, with which they interact with other under-
|
||||
lying GTK widget. It is this widget, e.g. that has to be resized etc and
|
||||
thw wxWindow class has a member variable called m_widget which holds a
|
||||
pointer to this widget. When the window class displays a GTK native widget,
|
||||
this is the only GTK widget the class manages. When the class has a client
|
||||
area for drawing into and for containing children it must have at least
|
||||
one more GTK widget to handle (of the type GtkMyFixed, defined in win_gtk.c),
|
||||
but there can be any number of widgets, handled by a class (e.g. the frame
|
||||
class handles three). 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 GtkMyFixed.
|
||||
|
||||
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 GtkMyFixed 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-
|
||||
cepted and sent to the wxWindows class. If not, all input to the widget
|
||||
that gets pointed to by m_widget gets intercepted and sent to the class.
|
||||
|
||||
*/
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// data
|
||||
//-----------------------------------------------------------------------------
|
||||
@@ -753,6 +827,7 @@ wxWindow::wxWindow()
|
||||
m_isEnabled = TRUE;
|
||||
m_pDropTarget = (wxDropTarget *) NULL;
|
||||
m_resizing = FALSE;
|
||||
m_hasOwnStyle = FALSE;
|
||||
}
|
||||
|
||||
bool wxWindow::Create( wxWindow *parent, wxWindowID id,
|
||||
@@ -937,6 +1012,7 @@ void wxWindow::PreCreation( wxWindow *parent, wxWindowID id,
|
||||
m_pDropTarget = (wxDropTarget *) NULL;
|
||||
m_resizing = FALSE;
|
||||
m_windowValidator = (wxValidator *) NULL;
|
||||
m_hasOwnStyle = FALSE;
|
||||
}
|
||||
|
||||
void wxWindow::PostCreation(void)
|
||||
@@ -1851,15 +1927,21 @@ bool wxWindow::IsOwnGtkWindow( GdkWindow *window )
|
||||
void wxWindow::SetFont( const wxFont &font )
|
||||
{
|
||||
m_font = font;
|
||||
/*
|
||||
create new style
|
||||
copy old style values to new one
|
||||
set font in new style
|
||||
-> takes to many resources
|
||||
GtkStyle *style = (GtkStyle*) NULL;
|
||||
if (!m_hasOwnStyle)
|
||||
{
|
||||
m_hasOwnStyle = TRUE;
|
||||
style = gtk_style_copy( gtk_widget_get_style( m_widget ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
style = gtk_widget_get_style( m_widget );
|
||||
}
|
||||
|
||||
GtkStyle *style = gtk_style_new();
|
||||
...
|
||||
*/
|
||||
gdk_font_unref( style->font );
|
||||
style->font = gdk_font_ref( m_font.GetInternalFont( 1.0 ) );
|
||||
|
||||
gtk_widget_set_style( m_widget, style );
|
||||
}
|
||||
|
||||
wxFont *wxWindow::GetFont(void)
|
||||
|
@@ -103,3 +103,26 @@ void wxButton::Enable( bool enable )
|
||||
gtk_widget_set_sensitive( label, enable );
|
||||
}
|
||||
|
||||
void wxButton::SetFont( const wxFont &font )
|
||||
{
|
||||
m_font = font;
|
||||
|
||||
GtkButton *bin = GTK_BUTTON( m_widget );
|
||||
GtkWidget *label = bin->child;
|
||||
|
||||
GtkStyle *style = (GtkStyle*) NULL;
|
||||
if (!m_hasOwnStyle)
|
||||
{
|
||||
m_hasOwnStyle = TRUE;
|
||||
style = gtk_style_copy( gtk_widget_get_style( label ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
style = gtk_widget_get_style( label );
|
||||
}
|
||||
|
||||
gdk_font_unref( style->font );
|
||||
style->font = gdk_font_ref( m_font.GetInternalFont( 1.0 ) );
|
||||
|
||||
gtk_widget_set_style( label, style );
|
||||
}
|
||||
|
@@ -89,3 +89,26 @@ bool wxCheckBox::GetValue(void) const
|
||||
return tb->active;
|
||||
}
|
||||
|
||||
void wxCheckBox::SetFont( const wxFont &font )
|
||||
{
|
||||
m_font = font;
|
||||
|
||||
GtkButton *bin = GTK_BUTTON( m_widget );
|
||||
GtkWidget *label = bin->child;
|
||||
|
||||
GtkStyle *style = (GtkStyle*) NULL;
|
||||
if (!m_hasOwnStyle)
|
||||
{
|
||||
m_hasOwnStyle = TRUE;
|
||||
style = gtk_style_copy( gtk_widget_get_style( label ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
style = gtk_widget_get_style( label );
|
||||
}
|
||||
|
||||
gdk_font_unref( style->font );
|
||||
style->font = gdk_font_ref( m_font.GetInternalFont( 1.0 ) );
|
||||
|
||||
gtk_widget_set_style( label, style );
|
||||
}
|
||||
|
@@ -92,8 +92,18 @@ void wxChoice::Append( const wxString &item )
|
||||
GtkWidget *menu = gtk_option_menu_get_menu( GTK_OPTION_MENU(m_widget) );
|
||||
GtkWidget *menu_item;
|
||||
menu_item = gtk_menu_item_new_with_label( item );
|
||||
|
||||
if (m_hasOwnStyle)
|
||||
{
|
||||
GtkBin *bin = GTK_BIN( menu_item );
|
||||
gtk_widget_set_style( bin->child,
|
||||
gtk_style_ref(
|
||||
gtk_widget_get_style( m_widget ) ) );
|
||||
}
|
||||
|
||||
gtk_signal_connect( GTK_OBJECT( menu_item ), "activate",
|
||||
GTK_SIGNAL_FUNC(gtk_choice_clicked_callback), (gpointer*)this );
|
||||
|
||||
gtk_menu_append( GTK_MENU(menu), menu_item );
|
||||
gtk_widget_show( menu_item );
|
||||
}
|
||||
@@ -123,10 +133,10 @@ int wxChoice::FindString( const wxString &string ) const
|
||||
GtkBin *bin = GTK_BIN( child->data );
|
||||
GtkLabel *label = (GtkLabel *) NULL;
|
||||
if (bin->child) label = GTK_LABEL(bin->child);
|
||||
if (!label) label = GTK_LABEL( GTK_BUTTON(m_widget)->child );
|
||||
|
||||
wxASSERT_MSG( label != NULL , "wxChoice: invalid label" );
|
||||
|
||||
if (!label) label = GTK_LABEL( GTK_BUTTON(m_widget)->child );
|
||||
if (string == label->label) return count;
|
||||
child = child->next;
|
||||
count++;
|
||||
@@ -172,10 +182,10 @@ wxString wxChoice::GetString( int n ) const
|
||||
{
|
||||
GtkLabel *label = (GtkLabel *) NULL;
|
||||
if (bin->child) label = GTK_LABEL(bin->child);
|
||||
if (!label) label = GTK_LABEL( GTK_BUTTON(m_widget)->child );
|
||||
|
||||
wxASSERT_MSG( label != NULL , "wxChoice: invalid label" );
|
||||
|
||||
if (!label) label = GTK_LABEL( GTK_BUTTON(m_widget)->child );
|
||||
return label->label;
|
||||
}
|
||||
child = child->next;
|
||||
@@ -227,3 +237,23 @@ void wxChoice::SetStringSelection( const wxString &string )
|
||||
if (n != -1) SetSelection( n );
|
||||
}
|
||||
|
||||
void wxChoice::SetFont( const wxFont &font )
|
||||
{
|
||||
wxWindow::SetFont( font );
|
||||
|
||||
GtkMenuShell *menu_shell = GTK_MENU_SHELL( gtk_option_menu_get_menu( GTK_OPTION_MENU(m_widget) ) );
|
||||
GList *child = menu_shell->children;
|
||||
while (child)
|
||||
{
|
||||
GtkBin *bin = GTK_BIN( child->data );
|
||||
GtkWidget *label = (GtkWidget *) NULL;
|
||||
if (bin->child) label = bin->child;
|
||||
if (!label) label = GTK_BUTTON(m_widget)->child;
|
||||
|
||||
gtk_widget_set_style( label,
|
||||
gtk_style_ref(
|
||||
gtk_widget_get_style( m_widget ) ) );
|
||||
|
||||
child = child->next;
|
||||
}
|
||||
}
|
||||
|
@@ -136,8 +136,15 @@ void wxComboBox::Append( const wxString &item, char *clientData )
|
||||
{
|
||||
GtkWidget *list = GTK_COMBO(m_widget)->list;
|
||||
|
||||
GtkWidget *list_item;
|
||||
list_item = gtk_list_item_new_with_label( item );
|
||||
GtkWidget *list_item = gtk_list_item_new_with_label( item );
|
||||
|
||||
if (m_hasOwnStyle)
|
||||
{
|
||||
GtkBin *bin = GTK_BIN( list_item );
|
||||
gtk_widget_set_style( bin->child,
|
||||
gtk_style_ref(
|
||||
gtk_widget_get_style( m_widget ) ) );
|
||||
}
|
||||
|
||||
gtk_signal_connect( GTK_OBJECT(list_item), "select",
|
||||
GTK_SIGNAL_FUNC(gtk_combo_clicked_callback), (gpointer)this );
|
||||
@@ -374,4 +381,27 @@ void wxComboBox::SetEditable( bool WXUNUSED(editable) )
|
||||
{
|
||||
}
|
||||
|
||||
void wxComboBox::SetFont( const wxFont &font )
|
||||
{
|
||||
wxWindow::SetFont( font );
|
||||
|
||||
GtkWidget *entry = GTK_COMBO(m_widget)->entry;
|
||||
|
||||
gtk_widget_set_style( entry,
|
||||
gtk_style_ref(
|
||||
gtk_widget_get_style( m_widget ) ) );
|
||||
|
||||
GtkWidget *list = GTK_COMBO(m_widget)->list;
|
||||
|
||||
GList *child = GTK_LIST(list)->children;
|
||||
while (child)
|
||||
{
|
||||
GtkBin *bin = (GtkBin*) child->data;
|
||||
gtk_widget_set_style( bin->child,
|
||||
gtk_style_ref(
|
||||
gtk_widget_get_style( m_widget ) ) );
|
||||
|
||||
child = child->next;
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -130,8 +130,15 @@ void wxListBox::Append( const wxString &item )
|
||||
|
||||
void wxListBox::Append( const wxString &item, char *clientData )
|
||||
{
|
||||
GtkWidget *list_item;
|
||||
list_item = gtk_list_item_new_with_label( item );
|
||||
GtkWidget *list_item = gtk_list_item_new_with_label( item );
|
||||
|
||||
if (m_hasOwnStyle)
|
||||
{
|
||||
GtkBin *bin = GTK_BIN( list_item );
|
||||
gtk_widget_set_style( bin->child,
|
||||
gtk_style_ref(
|
||||
gtk_widget_get_style( m_widget ) ) );
|
||||
}
|
||||
|
||||
gtk_signal_connect( GTK_OBJECT(list_item), "select",
|
||||
GTK_SIGNAL_FUNC(gtk_listitem_select_callback), (gpointer)this );
|
||||
@@ -230,7 +237,8 @@ int wxListBox::GetSelections(wxArrayInt& aSelections) const
|
||||
// get the number of selected items first
|
||||
GList *child = m_list->children;
|
||||
int count = 0;
|
||||
for ( child = m_list->children; child != NULL; child = child->next ) {
|
||||
for ( child = m_list->children; child != NULL; child = child->next )
|
||||
{
|
||||
if ( GTK_WIDGET(child->data)->state == GTK_STATE_SELECTED )
|
||||
count++;
|
||||
}
|
||||
@@ -241,7 +249,8 @@ int wxListBox::GetSelections(wxArrayInt& aSelections) const
|
||||
// now fill the list
|
||||
aSelections.Alloc(count); // optimization attempt
|
||||
int i = 0;
|
||||
for ( child = m_list->children; child != NULL; child = child->next, i++ ) {
|
||||
for ( child = m_list->children; child != NULL; child = child->next, i++ )
|
||||
{
|
||||
if ( GTK_WIDGET(child->data)->state == GTK_STATE_SELECTED )
|
||||
aSelections.Add(i);
|
||||
}
|
||||
@@ -377,5 +386,19 @@ GtkWidget *wxListBox::GetConnectWidget(void)
|
||||
return GTK_WIDGET(m_list);
|
||||
}
|
||||
|
||||
void wxListBox::SetFont( const wxFont &font )
|
||||
{
|
||||
wxWindow::SetFont( font );
|
||||
|
||||
GList *child = m_list->children;
|
||||
while (child)
|
||||
{
|
||||
GtkBin *bin = (GtkBin*) child->data;
|
||||
gtk_widget_set_style( bin->child,
|
||||
gtk_style_ref(
|
||||
gtk_widget_get_style( m_widget ) ) );
|
||||
child = child->next;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@@ -279,3 +279,19 @@ void wxRadioBox::SetNumberOfRowsOrCols( int WXUNUSED(n) )
|
||||
wxFAIL_MSG("wxRadioBox::SetNumberOfRowsOrCols not implemented.");
|
||||
}
|
||||
|
||||
void wxRadioBox::SetFont( const wxFont &font )
|
||||
{
|
||||
wxWindow::SetFont( font );
|
||||
|
||||
GSList *item = gtk_radio_button_group( m_radio );
|
||||
while (item)
|
||||
{
|
||||
GtkButton *button = GTK_BUTTON( item->data );
|
||||
|
||||
gtk_widget_set_style( button->child,
|
||||
gtk_style_ref(
|
||||
gtk_widget_get_style( m_widget ) ) );
|
||||
|
||||
item = item->next;
|
||||
}
|
||||
}
|
||||
|
@@ -86,4 +86,27 @@ bool wxRadioButton::GetValue(void) const
|
||||
return GTK_TOGGLE_BUTTON(m_widget)->active;
|
||||
}
|
||||
|
||||
void wxRadioButton::SetFont( const wxFont &font )
|
||||
{
|
||||
m_font = font;
|
||||
|
||||
GtkButton *bin = GTK_BUTTON( m_widget );
|
||||
GtkWidget *label = bin->child;
|
||||
|
||||
GtkStyle *style = (GtkStyle*) NULL;
|
||||
if (!m_hasOwnStyle)
|
||||
{
|
||||
m_hasOwnStyle = TRUE;
|
||||
style = gtk_style_copy( gtk_widget_get_style( label ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
style = gtk_widget_get_style( label );
|
||||
}
|
||||
|
||||
gdk_font_unref( style->font );
|
||||
style->font = gdk_font_ref( m_font.GetInternalFont( 1.0 ) );
|
||||
|
||||
gtk_widget_set_style( label, style );
|
||||
}
|
||||
|
||||
|
@@ -429,5 +429,25 @@ bool wxTextCtrl::IsOwnGtkWindow( GdkWindow *window )
|
||||
return (window == GTK_ENTRY(m_text)->text_area);
|
||||
}
|
||||
|
||||
void wxTextCtrl::SetFont( const wxFont &font )
|
||||
{
|
||||
m_font = font;
|
||||
|
||||
GtkStyle *style = (GtkStyle*) NULL;
|
||||
if (!m_hasOwnStyle)
|
||||
{
|
||||
m_hasOwnStyle = TRUE;
|
||||
style = gtk_style_copy( gtk_widget_get_style( m_text ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
style = gtk_widget_get_style( m_text );
|
||||
}
|
||||
|
||||
gdk_font_unref( style->font );
|
||||
style->font = gdk_font_ref( m_font.GetInternalFont( 1.0 ) );
|
||||
|
||||
gtk_widget_set_style( m_text, style );
|
||||
}
|
||||
|
||||
|
||||
|
@@ -34,6 +34,80 @@
|
||||
#include "wx/gtk/win_gtk.h"
|
||||
#include "gdk/gdkprivate.h"
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// documentation on internals
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
/*
|
||||
I have been asked several times about writing some documentation about
|
||||
the GTK port of wxWindows, especially its internal structures. Obviously,
|
||||
you cannot understand wxGTK without knowing a little about the GTK, but
|
||||
some more information about what the wxWindow, which is the base class
|
||||
for all other window classes, does seems required as well.
|
||||
|
||||
What does wxWindow do? It contains the common interface for the following
|
||||
jobs of its descentants:
|
||||
|
||||
1) Define the rudimentary behaviour common to all window classes, such as
|
||||
resizing, intercepting user input so as to make it possible to use these
|
||||
events for special purposes in a derived class, window names etc.
|
||||
|
||||
2) Provide the possibility to contain and manage children, if the derived
|
||||
class is allowed to contain children, which holds true for those window
|
||||
classes, which do not display a native GTK widget. To name them, these
|
||||
classes are wxPanel, wxScrolledWindow, wxDialog, wxFrame. The MDI frame-
|
||||
work classes are a special case and are handled a bit differently from
|
||||
the rest.
|
||||
|
||||
3) Provide the possibility to draw into a client area of a window. This,
|
||||
too, only holds true for classes that do not display a native GTK widget
|
||||
as above.
|
||||
|
||||
4) Provide the entire mechanism for scrolling widgets. This actaul inter-
|
||||
face for this is usually in wxScrolledWidget, but the GTK implementation
|
||||
is in this class.
|
||||
|
||||
5) A multitude of helper or extra methods for special purposes, such as
|
||||
Drag'n'Drop, managing validators etc.
|
||||
|
||||
Normally one might expect, that one wxWindows class would always contain
|
||||
one GTK widget. Under GTK, there is no such allround widget that has all
|
||||
the functionality. Moreover, the GTK defines a client area as a different
|
||||
widget from the actual widget you are handling. Last but not least some
|
||||
special classes (e.g. wxFrame) handle different categories of widgets and
|
||||
still have the possibility to draw something in the client area.
|
||||
It was therefore required to write a special purpose GTK widget, that would
|
||||
represent a client area in the sense of wxWindows capable to do the jobs
|
||||
2), 3) and 4). I have written this class and it resides in win_gtk.c of
|
||||
this directory.
|
||||
|
||||
All windows must have a widget, with which they interact with other under-
|
||||
lying GTK widget. It is this widget, e.g. that has to be resized etc and
|
||||
thw wxWindow class has a member variable called m_widget which holds a
|
||||
pointer to this widget. When the window class displays a GTK native widget,
|
||||
this is the only GTK widget the class manages. When the class has a client
|
||||
area for drawing into and for containing children it must have at least
|
||||
one more GTK widget to handle (of the type GtkMyFixed, defined in win_gtk.c),
|
||||
but there can be any number of widgets, handled by a class (e.g. the frame
|
||||
class handles three). 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 GtkMyFixed.
|
||||
|
||||
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 GtkMyFixed 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-
|
||||
cepted and sent to the wxWindows class. If not, all input to the widget
|
||||
that gets pointed to by m_widget gets intercepted and sent to the class.
|
||||
|
||||
*/
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// data
|
||||
//-----------------------------------------------------------------------------
|
||||
@@ -753,6 +827,7 @@ wxWindow::wxWindow()
|
||||
m_isEnabled = TRUE;
|
||||
m_pDropTarget = (wxDropTarget *) NULL;
|
||||
m_resizing = FALSE;
|
||||
m_hasOwnStyle = FALSE;
|
||||
}
|
||||
|
||||
bool wxWindow::Create( wxWindow *parent, wxWindowID id,
|
||||
@@ -937,6 +1012,7 @@ void wxWindow::PreCreation( wxWindow *parent, wxWindowID id,
|
||||
m_pDropTarget = (wxDropTarget *) NULL;
|
||||
m_resizing = FALSE;
|
||||
m_windowValidator = (wxValidator *) NULL;
|
||||
m_hasOwnStyle = FALSE;
|
||||
}
|
||||
|
||||
void wxWindow::PostCreation(void)
|
||||
@@ -1851,15 +1927,21 @@ bool wxWindow::IsOwnGtkWindow( GdkWindow *window )
|
||||
void wxWindow::SetFont( const wxFont &font )
|
||||
{
|
||||
m_font = font;
|
||||
/*
|
||||
create new style
|
||||
copy old style values to new one
|
||||
set font in new style
|
||||
-> takes to many resources
|
||||
GtkStyle *style = (GtkStyle*) NULL;
|
||||
if (!m_hasOwnStyle)
|
||||
{
|
||||
m_hasOwnStyle = TRUE;
|
||||
style = gtk_style_copy( gtk_widget_get_style( m_widget ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
style = gtk_widget_get_style( m_widget );
|
||||
}
|
||||
|
||||
GtkStyle *style = gtk_style_new();
|
||||
...
|
||||
*/
|
||||
gdk_font_unref( style->font );
|
||||
style->font = gdk_font_ref( m_font.GetInternalFont( 1.0 ) );
|
||||
|
||||
gtk_widget_set_style( m_widget, style );
|
||||
}
|
||||
|
||||
wxFont *wxWindow::GetFont(void)
|
||||
|
Reference in New Issue
Block a user