コード例 #1
0
ファイル: combobox.cpp プロジェクト: czxxjtu/wxPython-1
int wxComboBox::DoAppend( const wxString &item )
{
    wxCHECK_MSG( m_widget != NULL, -1, wxT("invalid combobox") );

#ifdef __WXGTK24__
    if (!gtk_check_version(2,4,0))
    {
        GtkComboBox* combobox = GTK_COMBO_BOX( m_widget );
        gtk_combo_box_append_text( combobox,  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 ) );

        gtk_container_add( GTK_CONTAINER(list), list_item );

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

        // Apply current widget style to the new list_item
        GtkRcStyle *style = CreateWidgetStyle();
        if (style)
        {
            gtk_widget_modify_style( GTK_WIDGET( list_item ), style );
            GtkBin *bin = GTK_BIN( list_item );
            GtkWidget *label = GTK_WIDGET( bin->child );
            gtk_widget_modify_style( label, style );
            gtk_rc_style_unref( style );
        }

        gtk_widget_show( list_item );

        EnableEvents();
    }

    const unsigned int count = GetCount();

    if ( m_clientDataList.GetCount() < count )
        m_clientDataList.Append( (wxObject*) NULL );
    if ( m_clientObjectList.GetCount() < count )
        m_clientObjectList.Append( (wxObject*) NULL );

    InvalidateBestSize();

    return count - 1;
}
コード例 #2
0
ファイル: combobox.cpp プロジェクト: beanhome/dev
int wxComboBox::DoInsertItems(const wxArrayStringsAdapter& items,
                              unsigned int pos,
                              void **clientData,
                              wxClientDataType type)
{
    wxCHECK_MSG( m_widget != NULL, -1, wxT("invalid combobox") );

    DisableEvents();

    GtkWidget *list = GTK_COMBO(m_widget)->list;

    GtkRcStyle *style = CreateWidgetStyle();

    const unsigned int count = items.GetCount();
    for( unsigned int i = 0; i < count; ++i, ++pos )
    {
        GtkWidget *
            list_item = gtk_list_item_new_with_label( wxGTK_CONV( items[i] ) );

        if ( pos == GetCount() )
        {
            gtk_container_add( GTK_CONTAINER(list), list_item );
        }
        else // insert, not append
        {
            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 );

            if (style)
            {
                gtk_widget_modify_style( GTK_WIDGET( list_item ), style );
                GtkBin *bin = GTK_BIN( list_item );
                GtkWidget *label = GTK_WIDGET( bin->child );
                gtk_widget_modify_style( label, style );
            }

        }

        gtk_widget_show( list_item );

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

        AssignNewItemClientData(pos, clientData, i, type);
    }

    if ( style )
        gtk_rc_style_unref( style );

    EnableEvents();

    InvalidateBestSize();

    return pos - 1;
}
コード例 #3
0
ファイル: listbox.cpp プロジェクト: Bluehorn/wxPython
void wxListBox::GtkAddItem( const wxString &item, int pos )
{
    wxCHECK_RET( m_list != NULL, wxT("invalid listbox") );

    GtkWidget *list_item;

    wxString label(item);
#if wxUSE_CHECKLISTBOX
    if (m_hasCheckBoxes)
    {
        label.Prepend(wxCHECKLBOX_STRING);
    }
#endif // wxUSE_CHECKLISTBOX

    list_item = gtk_list_item_new_with_label( wxGTK_CONV( label ) );

    GList *gitem_list = g_list_alloc ();
    gitem_list->data = list_item;

    if (pos == -1)
        gtk_list_append_items( GTK_LIST (m_list), gitem_list );
    else
        gtk_list_insert_items( GTK_LIST (m_list), gitem_list, pos );

    gtk_signal_connect_after( GTK_OBJECT(list_item), "select",
      GTK_SIGNAL_FUNC(gtk_listitem_select_callback), (gpointer)this );

    if (HasFlag(wxLB_MULTIPLE) || HasFlag(wxLB_EXTENDED))
        gtk_signal_connect_after( GTK_OBJECT(list_item), "deselect",
          GTK_SIGNAL_FUNC(gtk_listitem_deselect_callback), (gpointer)this );

    gtk_signal_connect( GTK_OBJECT(list_item),
                        "button_press_event",
                        (GtkSignalFunc)gtk_listbox_button_press_callback,
                        (gpointer) this );

    gtk_signal_connect_after( GTK_OBJECT(list_item),
                        "button_release_event",
                        (GtkSignalFunc)gtk_listbox_button_release_callback,
                        (gpointer) this );

    gtk_signal_connect( GTK_OBJECT(list_item),
                           "key_press_event",
                           (GtkSignalFunc)gtk_listbox_key_press_callback,
                           (gpointer)this );


    gtk_signal_connect( GTK_OBJECT(list_item), "focus_in_event",
            GTK_SIGNAL_FUNC(gtk_listitem_focus_in_callback), (gpointer)this );

    gtk_signal_connect( GTK_OBJECT(list_item), "focus_out_event",
            GTK_SIGNAL_FUNC(gtk_listitem_focus_out_callback), (gpointer)this );

    ConnectWidget( list_item );

    if (GTK_WIDGET_REALIZED(m_widget))
    {
        gtk_widget_show( list_item );

        gtk_widget_realize( list_item );
        gtk_widget_realize( GTK_BIN(list_item)->child );

#if wxUSE_TOOLTIPS
        if (m_tooltip) m_tooltip->Apply( this );
#endif
    }

    // Apply current widget style to the new list_item
    GtkRcStyle *style = CreateWidgetStyle();
    if (style)
    {
        gtk_widget_modify_style( GTK_WIDGET( list_item ), style );
        GtkBin *bin = GTK_BIN( list_item );
        gtk_widget_modify_style( GTK_WIDGET( bin->child ), style );
        gtk_rc_style_unref( style );
    }
}
コード例 #4
0
ファイル: notebook.cpp プロジェクト: beanhome/dev
bool wxNotebook::InsertPage( size_t position,
                             wxNotebookPage* win,
                             const wxString& text,
                             bool select,
                             int imageId )
{
    wxCHECK_MSG( m_widget != NULL, FALSE, wxT("invalid notebook") );

    wxCHECK_MSG( win->GetParent() == this, FALSE,
               wxT("Can't add a page whose parent is not the notebook!") );

    wxCHECK_MSG( position <= GetPageCount(), FALSE,
                 wxT("invalid page index in wxNotebookPage::InsertPage()") );

    // Hack Alert! (Part II): See above in wxInsertChildInNotebook callback
    // why this has to be done.  NOTE: using gtk_widget_unparent here does not
    // work as it seems to undo too much and will cause errors in the
    // gtk_notebook_insert_page below, so instead just clear the parent by
    // hand here.
    win->m_widget->parent = NULL;

    // don't receive switch page during addition
    gtk_signal_disconnect_by_func( GTK_OBJECT(m_widget),
      GTK_SIGNAL_FUNC(gtk_notebook_page_change_callback), (gpointer) this );

    if (m_themeEnabled)
        win->SetThemeEnabled(true);

    GtkNotebook *notebook = GTK_NOTEBOOK(m_widget);

    wxGtkNotebookPage *nb_page = new wxGtkNotebookPage();

    if ( position == GetPageCount() )
        m_pagesData.Append( nb_page );
    else
        m_pagesData.Insert( position, nb_page );

    m_pages.Insert(win, position);

    nb_page->m_box = gtk_hbox_new( FALSE, 1 );
    gtk_container_border_width( GTK_CONTAINER(nb_page->m_box), 2 );

    gtk_signal_connect( GTK_OBJECT(win->m_widget), "size_allocate",
      GTK_SIGNAL_FUNC(gtk_page_size_callback), (gpointer)win );

    gtk_notebook_insert_page( notebook, win->m_widget, nb_page->m_box, position );

    nb_page->m_page = (GtkNotebookPage*) g_list_last(notebook->children)->data;

    /* set the label image */
    nb_page->m_image = imageId;

    if (imageId != -1)
    {
        wxASSERT( m_imageList != NULL );

        const wxBitmap *bmp = m_imageList->GetBitmapPtr(imageId);
        GdkPixmap *pixmap = bmp->GetPixmap();
        GdkBitmap *mask = NULL;
        if ( bmp->GetMask() )
        {
            mask = bmp->GetMask()->GetBitmap();
        }

        GtkWidget *pixmapwid = gtk_pixmap_new (pixmap, mask );

        gtk_box_pack_start(GTK_BOX(nb_page->m_box), pixmapwid, FALSE, FALSE, m_padding);

        gtk_widget_show(pixmapwid);
    }

    /* set the label text */

    nb_page->m_text = text;
    if (nb_page->m_text.empty()) nb_page->m_text = wxEmptyString;

    nb_page->m_label = GTK_LABEL( gtk_label_new(wxGTK_CONV(nb_page->m_text)) );
    gtk_box_pack_end( GTK_BOX(nb_page->m_box), GTK_WIDGET(nb_page->m_label), FALSE, FALSE, m_padding );

    /* apply current style */
    GtkRcStyle *style = CreateWidgetStyle();
    if ( style )
    {
        gtk_widget_modify_style(GTK_WIDGET(nb_page->m_label), style);
        gtk_rc_style_unref(style);
    }

    /* show the label */
    gtk_widget_show( GTK_WIDGET(nb_page->m_label) );
    if (select && (m_pagesData.GetCount() > 1))
    {
      SetSelection( position );
    }

    gtk_signal_connect( GTK_OBJECT(m_widget), "switch_page",
      GTK_SIGNAL_FUNC(gtk_notebook_page_change_callback), (gpointer)this );

    InvalidateBestSize();
    return true;
}
コード例 #5
0
ファイル: notebook.cpp プロジェクト: EdgarTx/wx
bool wxNotebook::InsertPage( size_t position,
                             wxNotebookPage* win,
                             const wxString& text,
                             bool select,
                             int imageId )
{
    wxCHECK_MSG( m_widget != NULL, false, wxT("invalid notebook") );

    wxCHECK_MSG( win->GetParent() == this, false,
               wxT("Can't add a page whose parent is not the notebook!") );

    wxCHECK_MSG( position <= GetPageCount(), false,
                 _T("invalid page index in wxNotebookPage::InsertPage()") );

    // Hack Alert! (Part II): See above in wxInsertChildInNotebook callback
    // why this has to be done.  NOTE: using gtk_widget_unparent here does not
    // work as it seems to undo too much and will cause errors in the
    // gtk_notebook_insert_page below, so instead just clear the parent by
    // hand here.
    win->m_widget->parent = NULL;

    if (m_themeEnabled)
        win->SetThemeEnabled(true);

    GtkNotebook *notebook = GTK_NOTEBOOK(m_widget);

    wxGtkNotebookPage *nb_page = new wxGtkNotebookPage();

    if ( position == GetPageCount() )
        m_pagesData.Append( nb_page );
    else
        m_pagesData.Insert( position, nb_page );

    m_pages.Insert(win, position);

    // set the label image and text
    // this must be done before adding the page, as GetPageText
    // and GetPageImage will otherwise return wrong values in
    // the page-changed event that results from inserting the
    // first page.
    nb_page->m_image = imageId;
    nb_page->m_text = wxStripMenuCodes(text);

    nb_page->m_box = gtk_hbox_new( FALSE, 1 );
    gtk_container_set_border_width((GtkContainer*)nb_page->m_box, 2);

    g_signal_connect (win->m_widget, "size_allocate",
                      G_CALLBACK (gtk_page_size_callback), win);

    gtk_notebook_insert_page(notebook, win->m_widget, nb_page->m_box, position);

    nb_page->m_page = gtk_notebook_get_nth_page(notebook, position);

    if (imageId != -1)
    {
        wxASSERT( m_imageList != NULL );

        const wxBitmap *bmp = m_imageList->GetBitmapPtr(imageId);
        GtkWidget* pixmapwid = gtk_image_new_from_pixbuf(bmp->GetPixbuf());
        gtk_box_pack_start(GTK_BOX(nb_page->m_box), pixmapwid, FALSE, FALSE, m_padding);
        gtk_widget_show(pixmapwid);
    }

    /* set the label text */
    nb_page->m_label = GTK_LABEL( gtk_label_new(wxGTK_CONV(nb_page->m_text)) );
    gtk_box_pack_end( GTK_BOX(nb_page->m_box), GTK_WIDGET(nb_page->m_label), FALSE, FALSE, m_padding );

    /* apply current style */
    GtkRcStyle *style = CreateWidgetStyle();
    if ( style )
    {
        gtk_widget_modify_style(GTK_WIDGET(nb_page->m_label), style);
        gtk_rc_style_unref(style);
    }

    /* show the label */
    gtk_widget_show( GTK_WIDGET(nb_page->m_label) );

    if (select && (m_pagesData.GetCount() > 1))
    {
        SetSelection( position );
    }

    InvalidateBestSize();
    return true;
}