Beispiel #1
0
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
}
Beispiel #2
0
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 );
}
Beispiel #3
0
int wxComboBox::DoInsert(const wxString &item, unsigned int pos)
{
    wxCHECK_MSG( !(GetWindowStyle() & wxCB_SORT), -1,
                    wxT("can't insert into sorted list"));

    wxCHECK_MSG( m_widget != NULL, -1, wxT("invalid combobox") );
    wxCHECK_MSG( IsValidInsert(pos), -1, wxT("invalid index") );

    unsigned int count = GetCount();

    if (pos == count)
        return Append(item);

#ifdef __WXGTK24__
    if (!gtk_check_version(2,4,0))
    {
        GtkComboBox* combobox = GTK_COMBO_BOX( m_widget );
        gtk_combo_box_insert_text( combobox, pos, wxGTK_CONV( item ) );
    }
    else
#endif
    {
        DisableEvents();

        GtkWidget *list = GTK_COMBO(m_widget)->list;
        GtkWidget *list_item = gtk_list_item_new_with_label( wxGTK_CONV( item ) );

        GList *gitem_list = g_list_alloc ();
        gitem_list->data = list_item;
        gtk_list_insert_items( GTK_LIST (list), gitem_list, pos );

        if (GTK_WIDGET_REALIZED(m_widget))
        {
            gtk_widget_realize( list_item );
            gtk_widget_realize( GTK_BIN(list_item)->child );

            ApplyWidgetStyle();
        }

        gtk_widget_show( list_item );

        EnableEvents();
    }

    count = GetCount();

    if ( m_clientDataList.GetCount() < count )
        m_clientDataList.Insert( pos, (wxObject*) NULL );
    if ( m_clientObjectList.GetCount() < count )
        m_clientObjectList.Insert( pos, (wxObject*) NULL );

    InvalidateBestSize();

    return pos;
}
Beispiel #4
0
void wxControl::PostCreation(const wxSize& size)
{
    wxWindow::PostCreation();

    // NB: GetBestSize needs to know the style, otherwise it will assume
    //     default font and if the user uses a different font, determined
    //     best size will be different (typically, smaller) than the desired
    //     size. This call ensure that a style is available at the time
    //     GetBestSize is called.
    gtk_widget_ensure_style(m_widget);

    ApplyWidgetStyle();
    SetInitialSize(size);
}
Beispiel #5
0
void wxMenuBar::Init(size_t n, wxMenu *menus[], const wxString titles[], long style)
{
    // the parent window is known after wxFrame::SetMenu()
    m_needParent = false;
    m_style = style;
    m_invokingWindow = (wxWindow*) NULL;

    if (!PreCreation( (wxWindow*) NULL, wxDefaultPosition, wxDefaultSize ) ||
        !CreateBase( (wxWindow*) NULL, -1, wxDefaultPosition, wxDefaultSize, style, wxDefaultValidator, wxT("menubar") ))
    {
        wxFAIL_MSG( wxT("wxMenuBar creation failed") );
        return;
    }

    m_menubar = gtk_menu_bar_new();
    m_accel = gtk_accel_group_new();

    if (style & wxMB_DOCKABLE)
    {
        m_widget = gtk_handle_box_new();
        gtk_container_add( GTK_CONTAINER(m_widget), GTK_WIDGET(m_menubar) );
        gtk_widget_show( GTK_WIDGET(m_menubar) );
    }
    else
    {
        m_widget = GTK_WIDGET(m_menubar);
    }

    PostCreation();

    ApplyWidgetStyle();

    for (size_t i = 0; i < n; ++i )
        Append(menus[i], titles[i]);

    // VZ: for some reason connecting to menus "deactivate" doesn't work (we
    //     don't get it when the menu is dismissed by clicking outside the
    //     toolbar) so we connect to the global one, even if it means that we
    //     can't pass the menu which was closed in wxMenuEvent object
    gtk_signal_connect( GTK_OBJECT(GTK_MENU_SHELL(m_menubar)),
                        "deactivate",
                        GTK_SIGNAL_FUNC(gtk_menu_close_callback),
                        (gpointer)this );

}
Beispiel #6
0
int wxChoice::GtkAddHelper(GtkWidget *menu, unsigned int pos, const wxString& item)
{
    wxCHECK_MSG(pos<=m_clientList.GetCount(), -1, wxT("invalid index"));

    GtkWidget *menu_item = gtk_menu_item_new_with_label( wxGTK_CONV( item ) );

    size_t index;
    if ( m_strings )
    {
        // sorted control, need to insert at the correct index
        index = m_strings->Add(item);

        gtk_menu_insert( GTK_MENU(menu), menu_item, index );

        if ( index )
        {
            m_clientList.Insert( m_clientList.Item(index - 1),
                                 NULL );
        }
        else
        {
            m_clientList.Insert( NULL );
        }
    }
    else
    {
        // don't call wxChoice::GetCount() from here because it doesn't work
        // if we're called from ctor (and GtkMenuShell is still NULL)

        // normal control, just append
        if (pos == m_clientList.GetCount())
        {
            gtk_menu_append( GTK_MENU(menu), menu_item );
            m_clientList.Append( NULL );
            index = m_clientList.GetCount() - 1;
        }
        else
        {
            gtk_menu_insert( GTK_MENU(menu), menu_item, pos );
            m_clientList.Insert( pos, NULL );
            index = pos;
        }
    }

    if (GTK_WIDGET_REALIZED(m_widget))
    {
        gtk_widget_realize( menu_item );
        gtk_widget_realize( GTK_BIN(menu_item)->child );

        ApplyWidgetStyle();
    }

    // The best size of a wxChoice should probably
    // be changed everytime the control has been
    // changed, but at least after adding an item
    // it has to change. Adapted from Matt Ownby.
    InvalidateBestSize();

    gtk_signal_connect_after( GTK_OBJECT( menu_item ), "activate",
      GTK_SIGNAL_FUNC(gtk_choice_clicked_callback), (gpointer*)this );

    gtk_widget_show( menu_item );

    // return the index of the item in the control
    return index;
}