bool wxFontDialog::DoCreate(wxWindow *parent) { m_needParent = false; if (!PreCreation( parent, wxDefaultPosition, wxDefaultSize ) || !CreateBase( parent, -1, wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE, wxDefaultValidator, wxT("fontdialog") )) { wxFAIL_MSG( wxT("wxFontDialog creation failed") ); return false; } wxString m_message( _("Choose font") ); m_widget = gtk_font_selection_dialog_new( wxGTK_CONV( m_message ) ); if (parent) gtk_window_set_transient_for(GTK_WINDOW(m_widget), GTK_WINDOW(parent->m_widget)); GtkFontSelectionDialog *sel = GTK_FONT_SELECTION_DIALOG(m_widget); gtk_signal_connect( GTK_OBJECT(sel->ok_button), "clicked", GTK_SIGNAL_FUNC(gtk_fontdialog_ok_callback), (gpointer*)this ); // strange way to internationalize gtk_label_set( GTK_LABEL( BUTTON_CHILD(sel->ok_button) ), _("OK") ); gtk_signal_connect( GTK_OBJECT(sel->cancel_button), "clicked", GTK_SIGNAL_FUNC(gtk_fontdialog_cancel_callback), (gpointer*)this ); // strange way to internationalize gtk_label_set( GTK_LABEL( BUTTON_CHILD(sel->cancel_button) ), _("Cancel") ); gtk_signal_connect( GTK_OBJECT(m_widget), "delete_event", GTK_SIGNAL_FUNC(gtk_fontdialog_delete_callback), (gpointer)this ); wxFont font = m_fontData.GetInitialFont(); if( font.IsOk() ) { const wxNativeFontInfo *info = font.GetNativeFontInfo(); if ( info ) { const wxString& fontname = info->GetXFontName(); if ( !fontname ) font.GetInternalFont(); gtk_font_selection_dialog_set_font_name(sel, wxGTK_CONV(fontname)); } else { // this is not supposed to happen! wxFAIL_MSG(wxT("font is ok but no native font info?")); } } return true; }
bool wxButton::Create( wxWindow *parent, wxWindowID id, const wxString &label, const wxPoint &pos, const wxSize &size, long style, const wxValidator& validator, const wxString &name ) { m_needParent = true; m_acceptsFocus = true; if (!PreCreation( parent, pos, size ) || !CreateBase( parent, id, pos, size, style, validator, name )) { wxFAIL_MSG( wxT("wxButton creation failed") ); return false; } m_widget = gtk_button_new_with_label(""); float x_alignment = 0.5; if (HasFlag(wxBU_LEFT)) x_alignment = 0.0; else if (HasFlag(wxBU_RIGHT)) x_alignment = 1.0; float y_alignment = 0.5; if (HasFlag(wxBU_TOP)) y_alignment = 0.0; else if (HasFlag(wxBU_BOTTOM)) y_alignment = 1.0; if (GTK_IS_MISC(BUTTON_CHILD(m_widget))) gtk_misc_set_alignment (GTK_MISC (BUTTON_CHILD (m_widget)), x_alignment, y_alignment); SetLabel(label); if (style & wxNO_BORDER) gtk_button_set_relief( GTK_BUTTON(m_widget), GTK_RELIEF_NONE ); gtk_signal_connect_after( GTK_OBJECT(m_widget), "clicked", GTK_SIGNAL_FUNC(gtk_button_clicked_callback), (gpointer*)this ); gtk_signal_connect_after( GTK_OBJECT(m_widget), "style_set", GTK_SIGNAL_FUNC(gtk_button_style_set_callback), (gpointer*) this ); m_parent->DoAddChild( this ); PostCreation(size); return true; }
void wxBitmapButton::DoApplyWidgetStyle(GtkRcStyle *style) { if ( !BUTTON_CHILD(m_widget) ) return; wxButton::DoApplyWidgetStyle(style); }
void wxButton::SetLabel( const wxString &lbl ) { wxCHECK_RET( m_widget != NULL, wxT("invalid button") ); wxString label(lbl); if (label.empty() && wxIsStockID(m_windowId)) label = wxGetStockLabel(m_windowId); wxControl::SetLabel(label); #ifdef __WXGTK20__ if (wxIsStockID(m_windowId) && wxIsStockLabel(m_windowId, label)) { const char *stock = wxGetStockGtkID(m_windowId); if (stock) { gtk_button_set_label(GTK_BUTTON(m_widget), stock); gtk_button_set_use_stock(GTK_BUTTON(m_widget), TRUE); return; } } wxString label2 = PrepareLabelMnemonics(label); gtk_button_set_label(GTK_BUTTON(m_widget), wxGTK_CONV(label2)); gtk_button_set_use_stock(GTK_BUTTON(m_widget), FALSE); ApplyWidgetStyle( false ); #else gtk_label_set(GTK_LABEL(BUTTON_CHILD(m_widget)), wxGTK_CONV(GetLabel())); #endif }
wxString wxChoice::GetString(unsigned int n) const { wxCHECK_MSG( m_widget != NULL, wxEmptyString, wxT("invalid choice") ); GtkMenuShell *menu_shell = GTK_MENU_SHELL( gtk_option_menu_get_menu( GTK_OPTION_MENU(m_widget) ) ); unsigned int count = 0; GList *child = menu_shell->children; while (child) { GtkBin *bin = GTK_BIN( child->data ); if (count == n) { GtkLabel *label = NULL; if (bin->child) label = GTK_LABEL(bin->child); if (!label) label = GTK_LABEL( BUTTON_CHILD(m_widget) ); wxASSERT_MSG( label != NULL , wxT("wxChoice: invalid label") ); return wxString( label->label ); } child = child->next; count++; } wxFAIL_MSG( wxT("wxChoice: invalid index in GetString()") ); return wxEmptyString; }
int wxChoice::FindString( const wxString &string, bool bCase ) const { wxCHECK_MSG( m_widget != NULL, wxNOT_FOUND, wxT("invalid choice") ); // If you read this code once and you think you understand // it, then you are very wrong. Robert Roebling. GtkMenuShell *menu_shell = GTK_MENU_SHELL( gtk_option_menu_get_menu( GTK_OPTION_MENU(m_widget) ) ); int count = 0; GList *child = menu_shell->children; while (child) { GtkBin *bin = GTK_BIN( child->data ); GtkLabel *label = NULL; if (bin->child) label = GTK_LABEL(bin->child); if (!label) label = GTK_LABEL( BUTTON_CHILD(m_widget) ); wxASSERT_MSG( label != NULL , wxT("wxChoice: invalid label") ); wxString tmp( label->label ); if (string.IsSameAs( tmp, bCase )) return count; child = child->next; count++; } return wxNOT_FOUND; }
void wxChoice::SetString(unsigned int n, const wxString& str ) { wxCHECK_RET( m_widget != NULL, wxT("invalid choice") ); GtkMenuShell *menu_shell = GTK_MENU_SHELL( gtk_option_menu_get_menu( GTK_OPTION_MENU(m_widget) ) ); unsigned int count = 0; GList *child = menu_shell->children; while (child) { GtkBin *bin = GTK_BIN( child->data ); if (count == n) { GtkLabel *label = NULL; if (bin->child) label = GTK_LABEL(bin->child); if (!label) label = GTK_LABEL( BUTTON_CHILD(m_widget) ); wxASSERT_MSG( label != NULL , wxT("wxChoice: invalid label") ); gtk_label_set_text( label, wxGTK_CONV( str ) ); return; } child = child->next; count++; } }
int wxRadioBox::FindString( const wxString &find ) const { wxCHECK_MSG( m_widget != NULL, wxNOT_FOUND, wxT("invalid radiobox") ); int count = 0; wxList::compatibility_iterator node = m_boxes.GetFirst(); while (node) { GtkLabel *label = GTK_LABEL( BUTTON_CHILD(node->GetData()) ); #ifdef __WXGTK20__ wxString str( wxGTK_CONV_BACK( gtk_label_get_text(label) ) ); #else wxString str( label->label ); #endif if (find == str) return count; count++; node = node->GetNext(); } return wxNOT_FOUND; }
wxString wxRadioBox::GetStringSelection() const { wxCHECK_MSG( m_widget != NULL, wxEmptyString, wxT("invalid radiobox") ); wxList::compatibility_iterator node = m_boxes.GetFirst(); while (node) { GtkToggleButton *button = GTK_TOGGLE_BUTTON( node->GetData() ); if (button->active) { GtkLabel *label = GTK_LABEL( BUTTON_CHILD(node->GetData()) ); #ifdef __WXGTK20__ wxString str( wxGTK_CONV_BACK( gtk_label_get_text(label) ) ); #else wxString str( label->label ); #endif return str; } node = node->GetNext(); } wxFAIL_MSG( wxT("wxRadioBox none selected") ); return wxEmptyString; }
void wxToggleButton::SetLabel(const wxString& label) { wxCHECK_RET(m_widget != NULL, wxT("invalid toggle button")); wxControl::SetLabel(label); gtk_label_set(GTK_LABEL(BUTTON_CHILD(m_widget)), wxGTK_CONV( GetLabel() ) ); }
bool wxToggleBitmapButton::Enable(bool enable /*=TRUE*/) { if (!wxControl::Enable(enable)) return FALSE; gtk_widget_set_sensitive(BUTTON_CHILD(m_widget), enable); return TRUE; }
bool wxToggleButton::Enable(bool enable /*=true*/) { if (!wxControl::Enable(enable)) return false; gtk_widget_set_sensitive(BUTTON_CHILD(m_widget), enable); return true; }
bool wxCheckBox::Create(wxWindow *parent, wxWindowID id, const wxString &label, const wxPoint &pos, const wxSize &size, long style, const wxValidator& validator, const wxString &name ) { m_needParent = true; m_acceptsFocus = true; m_blockEvent = false; WXValidateStyle(&style); if (!PreCreation( parent, pos, size ) || !CreateBase( parent, id, pos, size, style, validator, name )) { wxFAIL_MSG( wxT("wxCheckBox creation failed") ); return false; } if ( style & wxALIGN_RIGHT ) { // VZ: as I don't know a way to create a right aligned checkbox with // GTK we will create a checkbox without label and a label at the // left of it m_widgetCheckbox = gtk_check_button_new(); m_widgetLabel = gtk_label_new(""); gtk_misc_set_alignment(GTK_MISC(m_widgetLabel), 0.0, 0.5); m_widget = gtk_hbox_new(FALSE, 0); gtk_box_pack_start(GTK_BOX(m_widget), m_widgetLabel, FALSE, FALSE, 3); gtk_box_pack_start(GTK_BOX(m_widget), m_widgetCheckbox, FALSE, FALSE, 3); gtk_widget_show( m_widgetLabel ); gtk_widget_show( m_widgetCheckbox ); } else { m_widgetCheckbox = gtk_check_button_new_with_label(""); m_widgetLabel = BUTTON_CHILD( m_widgetCheckbox ); m_widget = m_widgetCheckbox; } SetLabel( label ); gtk_signal_connect( GTK_OBJECT(m_widgetCheckbox), "toggled", GTK_SIGNAL_FUNC(gtk_checkbox_toggled_callback), (gpointer *)this ); m_parent->DoAddChild( this ); PostCreation(size); return true; }
bool wxRadioButton::Enable( bool enable ) { if ( !wxControl::Enable( enable ) ) return FALSE; gtk_widget_set_sensitive( BUTTON_CHILD(m_widget), enable ); return TRUE; }
void wxRadioBox::SetString( int item, const wxString& label ) { wxCHECK_RET( m_widget != NULL, wxT("invalid radiobox") ); wxList::compatibility_iterator node = m_boxes.Item( item ); wxCHECK_RET( node, wxT("radiobox wrong index") ); GtkLabel *g_label = GTK_LABEL( BUTTON_CHILD(node->GetData()) ); gtk_label_set( g_label, wxGTK_CONV( label ) ); }
wxString wxRadioBox::GetString(unsigned int n) const { wxCHECK_MSG( m_widget != NULL, wxEmptyString, wxT("invalid radiobox") ); wxList::compatibility_iterator node = m_boxes.Item( n ); wxCHECK_MSG( node, wxEmptyString, wxT("radiobox wrong index") ); GtkLabel *label = GTK_LABEL( BUTTON_CHILD(node->GetData()) ); wxString str( label->label ); return str; }
void wxRadioBox::DoApplyWidgetStyle(GtkRcStyle *style) { gtk_widget_modify_style( m_widget, style ); wxList::compatibility_iterator node = m_boxes.GetFirst(); while (node) { GtkWidget *widget = GTK_WIDGET( node->GetData() ); gtk_widget_modify_style( widget, style ); gtk_widget_modify_style( BUTTON_CHILD(node->GetData()), style ); node = node->GetNext(); } }
void wxButton::SetLabel( const wxString &lbl ) { wxCHECK_RET( m_widget != NULL, wxT("invalid button") ); wxString label(lbl); if (label.empty() && wxIsStockID(m_windowId)) label = wxGetStockLabel(m_windowId); wxControl::SetLabel(label); const wxString labelGTK = GTKRemoveMnemonics(label); gtk_label_set(GTK_LABEL(BUTTON_CHILD(m_widget)), wxGTK_CONV(labelGTK)); }
bool wxRadioBox::Enable( int item, bool enable ) { wxCHECK_MSG( m_widget != NULL, false, wxT("invalid radiobox") ); wxList::compatibility_iterator node = m_boxes.Item( item ); wxCHECK_MSG( node, false, wxT("radiobox wrong index") ); GtkButton *button = GTK_BUTTON( node->GetData() ); GtkLabel *label = GTK_LABEL( BUTTON_CHILD(button) ); gtk_widget_set_sensitive( GTK_WIDGET(button), enable ); gtk_widget_set_sensitive( GTK_WIDGET(label), enable ); return true; }
bool wxRadioBox::Enable( bool enable ) { if ( !wxControl::Enable( enable ) ) return false; wxList::compatibility_iterator node = m_boxes.GetFirst(); while (node) { GtkButton *button = GTK_BUTTON( node->GetData() ); GtkLabel *label = GTK_LABEL( BUTTON_CHILD(button) ); gtk_widget_set_sensitive( GTK_WIDGET(button), enable ); gtk_widget_set_sensitive( GTK_WIDGET(label), enable ); node = node->GetNext(); } return true; }
wxString wxRadioBox::GetString( int n ) const { wxCHECK_MSG( m_widget != NULL, wxEmptyString, wxT("invalid radiobox") ); wxList::compatibility_iterator node = m_boxes.Item( n ); wxCHECK_MSG( node, wxEmptyString, wxT("radiobox wrong index") ); GtkLabel *label = GTK_LABEL( BUTTON_CHILD(node->GetData()) ); #ifdef __WXGTK20__ wxString str( wxGTK_CONV_BACK( gtk_label_get_text(label) ) ); #else wxString str( label->label ); #endif return str; }
void wxToggleBitmapButton::OnSetBitmap() { if (!m_bitmap.IsOk()) return; GdkBitmap *mask = NULL; if (m_bitmap.GetMask()) mask = m_bitmap.GetMask()->GetBitmap(); GtkWidget *child = BUTTON_CHILD(m_widget); if (child == NULL) { // initial bitmap GtkWidget *pixmap = gtk_pixmap_new(m_bitmap.GetPixmap(), mask); gtk_widget_show(pixmap); gtk_container_add(GTK_CONTAINER(m_widget), pixmap); } else { // subsequent bitmaps GtkPixmap *g_pixmap = GTK_PIXMAP(child); gtk_pixmap_set(g_pixmap, m_bitmap.GetPixmap(), mask); } }
void wxBitmapButton::OnSetBitmap() { wxCHECK_RET( m_widget != NULL, wxT("invalid bitmap button") ); InvalidateBestSize(); wxBitmap the_one; if (!IsThisEnabled()) the_one = GetBitmapDisabled(); else if (m_isSelected) the_one = GetBitmapPressed(); else if (HasFocus()) the_one = GetBitmapFocus(); if (!the_one.IsOk()) { the_one = GetBitmapLabel(); if (!the_one.IsOk()) return; } GdkBitmap *mask = NULL; if (the_one.GetMask()) mask = the_one.GetMask()->GetBitmap(); GtkWidget *child = BUTTON_CHILD(m_widget); if (child == NULL) { // initial bitmap GtkWidget *pixmap; pixmap = gtk_pixmap_new(the_one.GetPixmap(), mask); gtk_widget_show(pixmap); gtk_container_add(GTK_CONTAINER(m_widget), pixmap); } else { // subsequent bitmaps GtkPixmap *pixmap = GTK_PIXMAP(child); gtk_pixmap_set(pixmap, the_one.GetPixmap(), mask); } }
void wxChoice::DoApplyWidgetStyle(GtkRcStyle *style) { GtkMenuShell *menu_shell = GTK_MENU_SHELL( gtk_option_menu_get_menu( GTK_OPTION_MENU(m_widget) ) ); gtk_widget_modify_style( m_widget, style ); gtk_widget_modify_style( GTK_WIDGET( menu_shell ), style ); GList *child = menu_shell->children; while (child) { gtk_widget_modify_style( GTK_WIDGET( child->data ), style ); GtkBin *bin = GTK_BIN( child->data ); GtkWidget *label = NULL; if (bin->child) label = bin->child; if (!label) label = BUTTON_CHILD(m_widget); gtk_widget_modify_style( label, style ); child = child->next; } }
bool wxButton::Create( wxWindow *parent, wxWindowID id, const wxString &label, const wxPoint &pos, const wxSize &size, long style, const wxValidator& validator, const wxString &name ) { m_needParent = TRUE; m_acceptsFocus = TRUE; if (!PreCreation( parent, pos, size ) || !CreateBase( parent, id, pos, size, style, validator, name )) { wxFAIL_MSG( wxT("wxButton creation failed") ); return FALSE; } /* wxString label2( label ); for (size_t i = 0; i < label2.Len(); i++) { if (label2.GetChar(i) == wxT('&')) label2.SetChar(i,wxT('_')); } GtkWidget *accel_label = gtk_accel_label_new( label2.mb_str() ); gtk_widget_show( accel_label ); m_widget = gtk_button_new(); gtk_container_add( GTK_CONTAINER(m_widget), accel_label ); gtk_accel_label_set_accel_widget( GTK_ACCEL_LABEL(accel_label), m_widget ); guint accel_key = gtk_label_parse_uline (GTK_LABEL(accel_label), label2.mb_str() ); gtk_accel_label_refetch( GTK_ACCEL_LABEL(accel_label) ); wxControl::SetLabel( label ); */ #ifdef __WXGTK20__ m_widget = gtk_button_new_with_mnemonic(""); #else m_widget = gtk_button_new_with_label(""); #endif float x_alignment = 0.5; if (HasFlag(wxBU_LEFT)) x_alignment = 0.0; else if (HasFlag(wxBU_RIGHT)) x_alignment = 1.0; float y_alignment = 0.5; if (HasFlag(wxBU_TOP)) y_alignment = 0.0; else if (HasFlag(wxBU_BOTTOM)) y_alignment = 1.0; #if __WXGTK24__ if (!gtk_check_version(2,4,0)) { gtk_button_set_alignment(GTK_BUTTON(m_widget), x_alignment, y_alignment); } else #endif { if (GTK_IS_MISC(BUTTON_CHILD(m_widget))) gtk_misc_set_alignment (GTK_MISC (BUTTON_CHILD (m_widget)), x_alignment, y_alignment); } SetLabel(label); if (style & wxNO_BORDER) gtk_button_set_relief( GTK_BUTTON(m_widget), GTK_RELIEF_NONE ); gtk_signal_connect_after( GTK_OBJECT(m_widget), "clicked", GTK_SIGNAL_FUNC(gtk_button_clicked_callback), (gpointer*)this ); gtk_signal_connect_after( GTK_OBJECT(m_widget), "style_set", GTK_SIGNAL_FUNC(gtk_button_style_set_callback), (gpointer*) this ); m_parent->DoAddChild( this ); PostCreation(size); return true; }
void wxToggleButton::DoApplyWidgetStyle(GtkRcStyle *style) { gtk_widget_modify_style(m_widget, style); gtk_widget_modify_style(BUTTON_CHILD(m_widget), style); }
void wxRadioButton::SetLabel( const wxString& label ) { wxCHECK_RET( m_widget != NULL, wxT("invalid radiobutton") ); GTKSetLabelForLabel(GTK_LABEL(BUTTON_CHILD(m_widget)), label); }