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:
Robert Roebling
1998-09-06 13:46:50 +00:00
parent 1573d8ed98
commit 868a28262c
39 changed files with 669 additions and 63 deletions

View File

@@ -60,6 +60,7 @@ class wxButton: public wxControl
void SetDefault(void);
void SetLabel( const wxString &label );
void Enable( bool enable );
void SetFont( const wxFont &font );
};
#endif // __GTKBUTTONH__

View File

@@ -59,6 +59,7 @@ class wxCheckBox: public wxControl
const wxString& name = wxCheckBoxNameStr );
void SetValue( bool state );
bool GetValue(void) const;
void SetFont( const wxFont &font );
};
#endif // __GTKCHECKBOXH__

View File

@@ -73,6 +73,7 @@ class wxChoice: public wxControl
void SetColumns( int n = 1 );
void SetSelection( int n );
void SetStringSelection( const wxString &string );
void SetFont( const wxFont &font );
};
#endif // __GTKCHOICEH__

View File

@@ -64,7 +64,6 @@ class wxComboBox: public wxControl
const wxValidator& validator = wxDefaultValidator,
const wxString& name = wxComboBoxNameStr);
// List functions
void Clear(void);
void Append( const wxString &item );
void Append( const wxString &item, char* clientData );
@@ -79,11 +78,9 @@ class wxComboBox: public wxControl
void SetSelection( int n );
void SetStringSelection( const wxString &string );
// Text field functions
wxString GetValue(void) const ;
void SetValue(const wxString& value);
// Clipboard operations
void Copy(void);
void Cut(void);
void Paste(void);
@@ -95,14 +92,17 @@ class wxComboBox: public wxControl
void Remove(long from, long to);
void SetSelection(long from, long to);
void SetEditable(bool editable);
void SetFont( const wxFont &font );
// implementation
bool m_alreadySent;
private:
wxList m_clientData;
public:
bool m_alreadySent;
};
#endif // __GTKCOMBOBOXH__

View File

@@ -74,12 +74,8 @@ class wxFont: public wxGDIObject
bool GetUnderlined(void) const;
wxFont( char *xFontName );
private:
friend wxDC;
friend wxPaintDC;
friend wxWindow;
// implementation
GdkFont* GetInternalFont(float scale = 1.0) const;

View File

@@ -82,6 +82,7 @@ class wxListBox: public wxControl
void SetSelection( int n, bool select = TRUE );
void SetString( int n, const wxString &string );
void SetStringSelection( const wxString &string, bool select = TRUE );
void SetFont( const wxFont &font );
virtual GtkWidget *GetConnectWidget(void);

View File

@@ -79,14 +79,16 @@ class wxRadioBox: public wxControl
virtual int Number(void) const;
int GetNumberOfRowsOrCols(void) const;
void SetNumberOfRowsOrCols( int n );
void SetFont( const wxFont &font );
// implementation
bool m_alreadySent;
private:
GtkRadioButton *m_radio;
public:
bool m_alreadySent;
};
#endif // __GTKRADIOBOXH__

View File

@@ -61,6 +61,7 @@ class wxRadioButton: public wxControl
virtual void SetLabel(const wxString& label);
virtual void SetValue(bool val);
virtual bool GetValue(void) const;
void SetFont( const wxFont &font );
};
#endif // __GTKRADIOBUTTONH__

View File

@@ -101,6 +101,10 @@ class wxTextCtrl: public wxControl, public streambuf
wxTextCtrl& operator<<(double d);
wxTextCtrl& operator<<(const char c);
void SetFont( const wxFont &font );
// implementation
virtual GtkWidget* GetConnectWidget(void);
virtual bool IsOwnGtkWindow( GdkWindow *window );

View File

@@ -271,6 +271,7 @@ public: // cannot get private going yet
float m_oldVerticalPos;
bool m_needParent;
bool m_hasScrolling;
bool m_hasOwnStyle;
bool m_hasVMT;
bool m_sizeSet;
bool m_resizing;

View File

@@ -60,6 +60,7 @@ class wxButton: public wxControl
void SetDefault(void);
void SetLabel( const wxString &label );
void Enable( bool enable );
void SetFont( const wxFont &font );
};
#endif // __GTKBUTTONH__

View File

@@ -59,6 +59,7 @@ class wxCheckBox: public wxControl
const wxString& name = wxCheckBoxNameStr );
void SetValue( bool state );
bool GetValue(void) const;
void SetFont( const wxFont &font );
};
#endif // __GTKCHECKBOXH__

View File

@@ -73,6 +73,7 @@ class wxChoice: public wxControl
void SetColumns( int n = 1 );
void SetSelection( int n );
void SetStringSelection( const wxString &string );
void SetFont( const wxFont &font );
};
#endif // __GTKCHOICEH__

View File

@@ -64,7 +64,6 @@ class wxComboBox: public wxControl
const wxValidator& validator = wxDefaultValidator,
const wxString& name = wxComboBoxNameStr);
// List functions
void Clear(void);
void Append( const wxString &item );
void Append( const wxString &item, char* clientData );
@@ -79,11 +78,9 @@ class wxComboBox: public wxControl
void SetSelection( int n );
void SetStringSelection( const wxString &string );
// Text field functions
wxString GetValue(void) const ;
void SetValue(const wxString& value);
// Clipboard operations
void Copy(void);
void Cut(void);
void Paste(void);
@@ -95,14 +92,17 @@ class wxComboBox: public wxControl
void Remove(long from, long to);
void SetSelection(long from, long to);
void SetEditable(bool editable);
void SetFont( const wxFont &font );
// implementation
bool m_alreadySent;
private:
wxList m_clientData;
public:
bool m_alreadySent;
};
#endif // __GTKCOMBOBOXH__

View File

@@ -74,12 +74,8 @@ class wxFont: public wxGDIObject
bool GetUnderlined(void) const;
wxFont( char *xFontName );
private:
friend wxDC;
friend wxPaintDC;
friend wxWindow;
// implementation
GdkFont* GetInternalFont(float scale = 1.0) const;

View File

@@ -82,6 +82,7 @@ class wxListBox: public wxControl
void SetSelection( int n, bool select = TRUE );
void SetString( int n, const wxString &string );
void SetStringSelection( const wxString &string, bool select = TRUE );
void SetFont( const wxFont &font );
virtual GtkWidget *GetConnectWidget(void);

View File

@@ -79,14 +79,16 @@ class wxRadioBox: public wxControl
virtual int Number(void) const;
int GetNumberOfRowsOrCols(void) const;
void SetNumberOfRowsOrCols( int n );
void SetFont( const wxFont &font );
// implementation
bool m_alreadySent;
private:
GtkRadioButton *m_radio;
public:
bool m_alreadySent;
};
#endif // __GTKRADIOBOXH__

View File

@@ -61,6 +61,7 @@ class wxRadioButton: public wxControl
virtual void SetLabel(const wxString& label);
virtual void SetValue(bool val);
virtual bool GetValue(void) const;
void SetFont( const wxFont &font );
};
#endif // __GTKRADIOBUTTONH__

View File

@@ -101,6 +101,10 @@ class wxTextCtrl: public wxControl, public streambuf
wxTextCtrl& operator<<(double d);
wxTextCtrl& operator<<(const char c);
void SetFont( const wxFont &font );
// implementation
virtual GtkWidget* GetConnectWidget(void);
virtual bool IsOwnGtkWindow( GdkWindow *window );

View File

@@ -271,6 +271,7 @@ public: // cannot get private going yet
float m_oldVerticalPos;
bool m_needParent;
bool m_hasScrolling;
bool m_hasOwnStyle;
bool m_hasVMT;
bool m_sizeSet;
bool m_resizing;

View File

@@ -57,11 +57,13 @@ class MyPanel: public wxPanel
void OnComboButtons( wxCommandEvent &event );
void OnRadio( wxCommandEvent &event );
void OnRadioButtons( wxCommandEvent &event );
void OnSetFont( wxCommandEvent &event );
wxListBox *m_listbox;
wxChoice *m_choice;
wxComboBox *m_combo;
wxRadioBox *m_radio;
wxButton *m_fontButton;
wxTextCtrl *m_text;
wxNotebook *m_notebook;
@@ -137,6 +139,7 @@ const ID_LISTBOX_SEL_STR = 132;
const ID_LISTBOX_CLEAR = 133;
const ID_LISTBOX_APPEND = 134;
const ID_LISTBOX_DELETE = 135;
const ID_LISTBOX_FONT = 136;
const ID_CHOICE = 120;
const ID_CHOICE_SEL_NUM = 121;
@@ -144,6 +147,7 @@ const ID_CHOICE_SEL_STR = 122;
const ID_CHOICE_CLEAR = 123;
const ID_CHOICE_APPEND = 124;
const ID_CHOICE_DELETE = 125;
const ID_CHOICE_FONT = 126;
const ID_COMBO = 140;
const ID_COMBO_SEL_NUM = 141;
@@ -151,12 +155,16 @@ const ID_COMBO_SEL_STR = 142;
const ID_COMBO_CLEAR = 143;
const ID_COMBO_APPEND = 144;
const ID_COMBO_DELETE = 145;
const ID_COMBO_FONT = 146;
const ID_TEXT = 150;
const ID_RADIOBOX = 160;
const ID_RADIOBOX_SEL_NUM = 161;
const ID_RADIOBOX_SEL_STR = 162;
const ID_RADIOBOX_FONT = 163;
const ID_SET_FONT = 170;
BEGIN_EVENT_TABLE(MyPanel, wxPanel)
EVT_SIZE ( MyPanel::OnSize)
@@ -166,21 +174,26 @@ BEGIN_EVENT_TABLE(MyPanel, wxPanel)
EVT_BUTTON (ID_LISTBOX_CLEAR, MyPanel::OnListBoxButtons)
EVT_BUTTON (ID_LISTBOX_APPEND, MyPanel::OnListBoxButtons)
EVT_BUTTON (ID_LISTBOX_DELETE, MyPanel::OnListBoxButtons)
EVT_BUTTON (ID_LISTBOX_FONT, MyPanel::OnListBoxButtons)
EVT_CHOICE (ID_CHOICE, MyPanel::OnChoice)
EVT_BUTTON (ID_CHOICE_SEL_NUM, MyPanel::OnChoiceButtons)
EVT_BUTTON (ID_CHOICE_SEL_STR, MyPanel::OnChoiceButtons)
EVT_BUTTON (ID_CHOICE_CLEAR, MyPanel::OnChoiceButtons)
EVT_BUTTON (ID_CHOICE_APPEND, MyPanel::OnChoiceButtons)
EVT_BUTTON (ID_CHOICE_DELETE, MyPanel::OnChoiceButtons)
EVT_BUTTON (ID_CHOICE_FONT, MyPanel::OnChoiceButtons)
EVT_CHOICE (ID_COMBO, MyPanel::OnCombo)
EVT_BUTTON (ID_COMBO_SEL_NUM, MyPanel::OnComboButtons)
EVT_BUTTON (ID_COMBO_SEL_STR, MyPanel::OnComboButtons)
EVT_BUTTON (ID_COMBO_CLEAR, MyPanel::OnComboButtons)
EVT_BUTTON (ID_COMBO_APPEND, MyPanel::OnComboButtons)
EVT_BUTTON (ID_COMBO_DELETE, MyPanel::OnComboButtons)
EVT_BUTTON (ID_COMBO_FONT, MyPanel::OnComboButtons)
EVT_RADIOBOX (ID_RADIOBOX, MyPanel::OnRadio)
EVT_BUTTON (ID_RADIOBOX_SEL_NUM, MyPanel::OnRadioButtons)
EVT_BUTTON (ID_RADIOBOX_SEL_STR, MyPanel::OnRadioButtons)
EVT_BUTTON (ID_RADIOBOX_FONT, MyPanel::OnRadioButtons)
EVT_BUTTON (ID_SET_FONT, MyPanel::OnSetFont)
END_EVENT_TABLE()
MyPanel::MyPanel( wxFrame *frame, int x, int y, int w, int h ) :
@@ -212,9 +225,15 @@ MyPanel::MyPanel( wxFrame *frame, int x, int y, int w, int h ) :
wxASSERT( WXSIZEOF(aIconNames) == Image_Max ); // keep in sync
// fill the image list
#ifdef __WXMSW__
wxString strIconDir = "icons/";
#else
wxString strIconDir = "../icons/";
#endif
wxImageList *imagelist = new wxImageList(32, 32);
for ( size_t n = 0; n < Image_Max; n++ ) {
for ( size_t n = 0; n < Image_Max; n++ )
{
imagelist->Add(wxBitmap(strIconDir + aIconNames[n]));
}
@@ -227,6 +246,7 @@ MyPanel::MyPanel( wxFrame *frame, int x, int y, int w, int h ) :
(void)new wxButton( panel, ID_LISTBOX_CLEAR, "Clear", wxPoint(180,80), wxSize(100,30) );
(void)new wxButton( panel, ID_LISTBOX_APPEND, "Append 'Hi!'", wxPoint(300,80), wxSize(100,30) );
(void)new wxButton( panel, ID_LISTBOX_DELETE, "Delete selected item", wxPoint(180,130), wxSize(140,30) );
(void)new wxButton( panel, ID_LISTBOX_FONT, "Set Italic font", wxPoint(180,180), wxSize(140,30) );
m_notebook->AddPage(panel, "wxList", FALSE, Image_List);
panel = new wxPanel(m_notebook);
@@ -236,6 +256,7 @@ MyPanel::MyPanel( wxFrame *frame, int x, int y, int w, int h ) :
(void)new wxButton( panel, ID_CHOICE_CLEAR, "Clear", wxPoint(180,80), wxSize(100,30) );
(void)new wxButton( panel, ID_CHOICE_APPEND, "Append 'Hi!'", wxPoint(300,80), wxSize(100,30) );
(void)new wxButton( panel, ID_CHOICE_DELETE, "Delete selected item", wxPoint(180,130), wxSize(140,30) );
(void)new wxButton( panel, ID_CHOICE_FONT, "Set Italic font", wxPoint(180,180), wxSize(140,30) );
m_notebook->AddPage(panel, "wxChoice", FALSE, Image_Choice);
panel = new wxPanel(m_notebook);
@@ -245,6 +266,7 @@ MyPanel::MyPanel( wxFrame *frame, int x, int y, int w, int h ) :
(void)new wxButton( panel, ID_COMBO_CLEAR, "Clear", wxPoint(180,80), wxSize(100,30) );
(void)new wxButton( panel, ID_COMBO_APPEND, "Append 'Hi!'", wxPoint(300,80), wxSize(100,30) );
(void)new wxButton( panel, ID_COMBO_DELETE, "Delete selected item", wxPoint(180,130), wxSize(140,30) );
(void)new wxButton( panel, ID_COMBO_FONT, "Set Italic font", wxPoint(180,180), wxSize(140,30) );
m_notebook->AddPage(panel, "wxComboBox", FALSE, Image_Combo);
wxTextCtrl *text = new wxTextCtrl( m_notebook, ID_TEXT, "Write text here.", wxPoint(10,10), wxSize(120,100), wxTE_MULTILINE );
@@ -254,6 +276,8 @@ MyPanel::MyPanel( wxFrame *frame, int x, int y, int w, int h ) :
m_radio = new wxRadioBox( panel, ID_RADIOBOX, "This", wxPoint(10,10), wxSize(-1,-1), 4, choices );
(void)new wxButton( panel, ID_RADIOBOX_SEL_NUM, "Select #2", wxPoint(200,30), wxSize(100,30) );
(void)new wxButton( panel, ID_RADIOBOX_SEL_STR, "Select 'This'", wxPoint(200,80), wxSize(100,30) );
(void)new wxButton( panel, ID_RADIOBOX_FONT, "Set Italic font", wxPoint(200,130), wxSize(160,30) );
m_fontButton = new wxButton( panel, ID_SET_FONT, "Set more Italic font", wxPoint(200,180), wxSize(160,30) );
m_notebook->AddPage(panel, "wxRadioBox", FALSE, Image_Radio);
}
@@ -304,6 +328,11 @@ void MyPanel::OnListBoxButtons( wxCommandEvent &event )
m_listbox->Delete( idx );
break;
}
case ID_LISTBOX_FONT:
{
m_listbox->SetFont( *wxITALIC_FONT );
break;
}
}
}
@@ -344,6 +373,11 @@ void MyPanel::OnChoiceButtons( wxCommandEvent &event )
m_choice->Delete( idx );
break;
}
case ID_CHOICE_FONT:
{
m_choice->SetFont( *wxITALIC_FONT );
break;
}
}
}
@@ -384,6 +418,11 @@ void MyPanel::OnComboButtons( wxCommandEvent &event )
m_combo->Delete( idx );
break;
}
case ID_COMBO_FONT:
{
m_combo->SetFont( *wxITALIC_FONT );
break;
}
}
}
@@ -408,9 +447,20 @@ void MyPanel::OnRadioButtons( wxCommandEvent &event )
m_radio->SetStringSelection( "This" );
break;
}
case ID_RADIOBOX_FONT:
{
m_radio->SetFont( *wxITALIC_FONT );
break;
}
}
}
void MyPanel::OnSetFont( wxCommandEvent &WXUNUSED(event) )
{
m_fontButton->SetFont( *wxITALIC_FONT );
m_text->SetFont( *wxITALIC_FONT );
}
MyPanel::~MyPanel()
{
delete m_notebook->GetImageList();

View File

@@ -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 );
}

View File

@@ -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 );
}

View File

@@ -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;
}
}

View File

@@ -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;
}
}

View File

@@ -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;
}
}

View File

@@ -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;
}
}

View File

@@ -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 );
}

View File

@@ -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 );
}

View File

@@ -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)

View File

@@ -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 );
}

View File

@@ -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 );
}

View File

@@ -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;
}
}

View File

@@ -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;
}
}

View File

@@ -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;
}
}

View File

@@ -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;
}
}

View File

@@ -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 );
}

View File

@@ -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 );
}

View File

@@ -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)