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 }
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 = GTKConvertMnemonics(label); 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; } } gtk_button_set_label(GTK_BUTTON(m_widget), wxGTK_CONV(labelGTK)); gtk_button_set_use_stock(GTK_BUTTON(m_widget), FALSE); ApplyWidgetStyle( false ); }
void wxMessageDialog::DoSetCustomLabel(wxString& var, const ButtonLabel& label) { int stockId = label.GetStockId(); if ( stockId == wxID_NONE ) { wxMessageDialogBase::DoSetCustomLabel(var, label); var = wxConvertMnemonicsToGTK(var); } else // stock label { var = wxGetStockGtkID(stockId); } }
static void wxGetGtkAccel(const wxMenuItem* item, guint* accel_key, GdkModifierType* accel_mods) { *accel_key = 0; const wxString string = GetGtkHotKey(*item); if (!string.empty()) gtk_accelerator_parse(wxGTK_CONV_SYS(string), accel_key, accel_mods); else { GtkStockItem stock_item; const char* stockid = wxGetStockGtkID(item->GetId()); if (stockid && gtk_stock_lookup(stockid, &stock_item)) { *accel_key = stock_item.keyval; *accel_mods = stock_item.modifier; } } }
GtkWidget *wxInfoBar::GTKAddButton(wxWindowID btnid, const wxString& label) { // as GTK+ lays out the buttons vertically, adding another button changes // our best size (at least in vertical direction) InvalidateBestSize(); GtkWidget* button = gtk_info_bar_add_button(GTK_INFO_BAR(m_widget), #ifdef __WXGTK4__ wxGTK_CONV(label.empty() ? wxConvertMnemonicsToGTK(wxGetStockLabel(btnid)) : label), #else label.empty() ? wxGetStockGtkID(btnid) : static_cast<const char*>(wxGTK_CONV(label)), #endif btnid); wxASSERT_MSG( button, "unexpectedly failed to add button to info bar" ); return button; }
GtkWidget *wxInfoBar::GTKAddButton(wxWindowID btnid, const wxString& label) { // as GTK+ lays out the buttons vertically, adding another button changes // our best size (at least in vertical direction) InvalidateBestSize(); GtkWidget *button = gtk_info_bar_add_button ( GTK_INFO_BAR(m_widget), (label.empty() ? GTKConvertMnemonics(wxGetStockGtkID(btnid)) : label).utf8_str(), btnid ); wxASSERT_MSG( button, "unexpectedly failed to add button to info bar" ); return button; }
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); wxAnyButton::SetLabel(label); // don't use label if it was explicitly disabled if ( HasFlag(wxBU_NOTEXT) ) return; #if !defined(__WXGTK3__) || !GTK_CHECK_VERSION(3,10,0) 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; } } #endif // GTK < 3.10 // this call is necessary if the button had been initially created without // a (text) label -- then we didn't use gtk_button_new_with_mnemonic() and // so "use-underline" GtkButton property remained unset gtk_button_set_use_underline(GTK_BUTTON(m_widget), TRUE); const wxString labelGTK = GTKConvertMnemonics(label); gtk_button_set_label(GTK_BUTTON(m_widget), wxGTK_CONV(labelGTK)); #if !defined(__WXGTK3__) || !GTK_CHECK_VERSION(3,10,0) gtk_button_set_use_stock(GTK_BUTTON(m_widget), FALSE); #endif // GTK < 3.10 GTKApplyWidgetStyle( false ); }
void wxMenu::GtkAppend(wxMenuItem* mitem, int pos) { GtkWidget *menuItem; switch (mitem->GetKind()) { case wxITEM_SEPARATOR: menuItem = gtk_separator_menu_item_new(); break; case wxITEM_CHECK: menuItem = gtk_check_menu_item_new_with_label(""); break; case wxITEM_RADIO: { // See if we need to create a new radio group for this item or // add it to an existing one. wxMenuItem* radioGroupItem = NULL; const size_t numItems = GetMenuItemCount(); const size_t n = pos == -1 ? numItems - 1 : size_t(pos); if (n != 0) { wxMenuItem* const itemPrev = FindItemByPosition(n - 1); if ( itemPrev->GetKind() == wxITEM_RADIO ) { // Appending an item after an existing radio item puts // it into the same radio group. radioGroupItem = itemPrev; } } if (radioGroupItem == NULL && n != numItems - 1) { wxMenuItem* const itemNext = FindItemByPosition(n + 1); if ( itemNext->GetKind() == wxITEM_RADIO ) { // Inserting an item before an existing radio item // also puts it into the existing radio group. radioGroupItem = itemNext; } } GSList* group = NULL; if ( radioGroupItem ) { group = gtk_radio_menu_item_get_group( GTK_RADIO_MENU_ITEM(radioGroupItem->GetMenuItem()) ); } menuItem = gtk_radio_menu_item_new_with_label(group, ""); } break; default: wxFAIL_MSG("unexpected menu item kind"); // fall through case wxITEM_NORMAL: const wxBitmap& bitmap = mitem->GetBitmap(); const char* stockid; if (bitmap.IsOk()) { // always use pixbuf, because pixmap mask does not // work with disabled images in some themes GtkWidget* image = gtk_image_new_from_pixbuf(bitmap.GetPixbuf()); menuItem = gtk_image_menu_item_new_with_label(""); gtk_widget_show(image); gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(menuItem), image); } else if ((stockid = wxGetStockGtkID(mitem->GetId())) != NULL) // use stock bitmap for this item if available on the assumption // that it never hurts to follow GTK+ conventions more closely menuItem = gtk_image_menu_item_new_from_stock(stockid, NULL); else menuItem = gtk_menu_item_new_with_label(""); break; } mitem->SetMenuItem(menuItem); gtk_menu_shell_insert(GTK_MENU_SHELL(m_menu), menuItem, pos); gtk_widget_show( menuItem ); if ( !mitem->IsSeparator() ) { mitem->SetGtkLabel(); g_signal_connect (menuItem, "select", G_CALLBACK(menuitem_select), mitem); g_signal_connect (menuItem, "deselect", G_CALLBACK(menuitem_deselect), mitem); if ( mitem->IsSubMenu() && mitem->GetKind() != wxITEM_RADIO && mitem->GetKind() != wxITEM_CHECK ) { gtk_menu_item_set_submenu( GTK_MENU_ITEM(menuItem), mitem->GetSubMenu()->m_menu ); gtk_widget_show( mitem->GetSubMenu()->m_menu ); } else { g_signal_connect(menuItem, "can_activate_accel", G_CALLBACK(can_activate_accel), this); g_signal_connect (menuItem, "activate", G_CALLBACK(menuitem_activate), mitem); } } }
bool wxMenu::GtkAppend(wxMenuItem *mitem, int pos) { GtkWidget *menuItem; GtkWidget* prevRadio = m_prevRadio; m_prevRadio = NULL; switch (mitem->GetKind()) { case wxITEM_SEPARATOR: menuItem = gtk_separator_menu_item_new(); break; case wxITEM_CHECK: menuItem = gtk_check_menu_item_new_with_label(""); break; case wxITEM_RADIO: { GSList* group = NULL; if (prevRadio) group = gtk_radio_menu_item_get_group(GTK_RADIO_MENU_ITEM(prevRadio)); menuItem = gtk_radio_menu_item_new_with_label(group, ""); m_prevRadio = menuItem; } break; default: wxFAIL_MSG("unexpected menu item kind"); // fall through case wxITEM_NORMAL: const wxBitmap& bitmap = mitem->GetBitmap(); const char* stockid; if (bitmap.IsOk()) { // always use pixbuf, because pixmap mask does not // work with disabled images in some themes GtkWidget* image = gtk_image_new_from_pixbuf(bitmap.GetPixbuf()); menuItem = gtk_image_menu_item_new_with_label(""); gtk_widget_show(image); gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(menuItem), image); } else if ((stockid = wxGetStockGtkID(mitem->GetId())) != NULL) // use stock bitmap for this item if available on the assumption // that it never hurts to follow GTK+ conventions more closely menuItem = gtk_image_menu_item_new_from_stock(stockid, NULL); else menuItem = gtk_menu_item_new_with_label(""); break; } mitem->SetMenuItem(menuItem); gtk_menu_shell_insert(GTK_MENU_SHELL(m_menu), menuItem, pos); gtk_widget_show( menuItem ); if ( !mitem->IsSeparator() ) { mitem->SetGtkLabel(); g_signal_connect (menuItem, "select", G_CALLBACK(menuitem_select), mitem); g_signal_connect (menuItem, "deselect", G_CALLBACK(menuitem_deselect), mitem); if ( mitem->IsSubMenu() && mitem->GetKind() != wxITEM_RADIO && mitem->GetKind() != wxITEM_CHECK ) { gtk_menu_item_set_submenu( GTK_MENU_ITEM(menuItem), mitem->GetSubMenu()->m_menu ); gtk_widget_show( mitem->GetSubMenu()->m_menu ); } else { g_signal_connect(menuItem, "can_activate_accel", G_CALLBACK(can_activate_accel), this); g_signal_connect (menuItem, "activate", G_CALLBACK(menuitem_activate), mitem); } } return true; }