void SetDefault(void);
void SetLabel( const wxString &label );
void Enable( bool enable );
+ void SetFont( const wxFont &font );
};
#endif // __GTKBUTTONH__
const wxString& name = wxCheckBoxNameStr );
void SetValue( bool state );
bool GetValue(void) const;
+ void SetFont( const wxFont &font );
};
#endif // __GTKCHECKBOXH__
void SetColumns( int n = 1 );
void SetSelection( int n );
void SetStringSelection( const wxString &string );
+ void SetFont( const wxFont &font );
};
#endif // __GTKCHOICEH__
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 );
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);
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__
bool GetUnderlined(void) const;
wxFont( char *xFontName );
-
- private:
-
- friend wxDC;
- friend wxPaintDC;
- friend wxWindow;
+
+ // implementation
GdkFont* GetInternalFont(float scale = 1.0) const;
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);
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__
virtual void SetLabel(const wxString& label);
virtual void SetValue(bool val);
virtual bool GetValue(void) const;
+ void SetFont( const wxFont &font );
};
#endif // __GTKRADIOBUTTONH__
wxTextCtrl& operator<<(double d);
wxTextCtrl& operator<<(const char c);
+ void SetFont( const wxFont &font );
+
+ // implementation
+
virtual GtkWidget* GetConnectWidget(void);
virtual bool IsOwnGtkWindow( GdkWindow *window );
float m_oldVerticalPos;
bool m_needParent;
bool m_hasScrolling;
+ bool m_hasOwnStyle;
bool m_hasVMT;
bool m_sizeSet;
bool m_resizing;
void SetDefault(void);
void SetLabel( const wxString &label );
void Enable( bool enable );
+ void SetFont( const wxFont &font );
};
#endif // __GTKBUTTONH__
const wxString& name = wxCheckBoxNameStr );
void SetValue( bool state );
bool GetValue(void) const;
+ void SetFont( const wxFont &font );
};
#endif // __GTKCHECKBOXH__
void SetColumns( int n = 1 );
void SetSelection( int n );
void SetStringSelection( const wxString &string );
+ void SetFont( const wxFont &font );
};
#endif // __GTKCHOICEH__
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 );
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);
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__
bool GetUnderlined(void) const;
wxFont( char *xFontName );
-
- private:
-
- friend wxDC;
- friend wxPaintDC;
- friend wxWindow;
+
+ // implementation
GdkFont* GetInternalFont(float scale = 1.0) const;
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);
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__
virtual void SetLabel(const wxString& label);
virtual void SetValue(bool val);
virtual bool GetValue(void) const;
+ void SetFont( const wxFont &font );
};
#endif // __GTKRADIOBUTTONH__
wxTextCtrl& operator<<(double d);
wxTextCtrl& operator<<(const char c);
+ void SetFont( const wxFont &font );
+
+ // implementation
+
virtual GtkWidget* GetConnectWidget(void);
virtual bool IsOwnGtkWindow( GdkWindow *window );
float m_oldVerticalPos;
bool m_needParent;
bool m_hasScrolling;
+ bool m_hasOwnStyle;
bool m_hasVMT;
bool m_sizeSet;
bool m_resizing;
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;
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;
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;
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)
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 ) :
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]));
}
(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);
(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);
(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 );
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);
}
m_listbox->Delete( idx );
break;
}
+ case ID_LISTBOX_FONT:
+ {
+ m_listbox->SetFont( *wxITALIC_FONT );
+ break;
+ }
}
}
m_choice->Delete( idx );
break;
}
+ case ID_CHOICE_FONT:
+ {
+ m_choice->SetFont( *wxITALIC_FONT );
+ break;
+ }
}
}
m_combo->Delete( idx );
break;
}
+ case ID_COMBO_FONT:
+ {
+ m_combo->SetFont( *wxITALIC_FONT );
+ break;
+ }
}
}
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();
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 );
+}
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 );
+}
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 );
}
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++;
{
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;
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;
+ }
+}
{
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 );
{
}
+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;
+ }
+}
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 );
// 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++;
}
// 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);
}
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;
+ }
+}
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;
+ }
+}
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 );
+}
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 );
+}
#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
//-----------------------------------------------------------------------------
m_isEnabled = TRUE;
m_pDropTarget = (wxDropTarget *) NULL;
m_resizing = FALSE;
+ m_hasOwnStyle = FALSE;
}
bool wxWindow::Create( wxWindow *parent, wxWindowID id,
m_pDropTarget = (wxDropTarget *) NULL;
m_resizing = FALSE;
m_windowValidator = (wxValidator *) NULL;
+ m_hasOwnStyle = FALSE;
}
void wxWindow::PostCreation(void)
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)
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 );
+}
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 );
+}
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 );
}
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++;
{
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;
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;
+ }
+}
{
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 );
{
}
+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;
+ }
+}
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 );
// 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++;
}
// 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);
}
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;
+ }
+}
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;
+ }
+}
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 );
+}
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 );
+}
#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
//-----------------------------------------------------------------------------
m_isEnabled = TRUE;
m_pDropTarget = (wxDropTarget *) NULL;
m_resizing = FALSE;
+ m_hasOwnStyle = FALSE;
}
bool wxWindow::Create( wxWindow *parent, wxWindowID id,
m_pDropTarget = (wxDropTarget *) NULL;
m_resizing = FALSE;
m_windowValidator = (wxValidator *) NULL;
+ m_hasOwnStyle = FALSE;
}
void wxWindow::PostCreation(void)
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)