Esempio n. 1
0
bool wxNotebook::SetPageImage( size_t page, int image )
{
    wxCHECK_MSG(page < GetPageCount(), false, "invalid notebook index");

    wxGtkNotebookPage* pageData = GetNotebookPage(page);
    if (image >= 0)
    {
        wxCHECK_MSG(HasImageList(), false, "invalid notebook imagelist");
        const wxBitmap* bitmap = GetImageList()->GetBitmapPtr(image);
        if (bitmap == NULL)
            return false;
        if (pageData->m_image)
        {
            gtk_image_set_from_pixbuf(
                GTK_IMAGE(pageData->m_image), bitmap->GetPixbuf());
        }
        else
        {
            pageData->m_image = gtk_image_new_from_pixbuf(bitmap->GetPixbuf());
            gtk_widget_show(pageData->m_image);
            gtk_box_pack_start(GTK_BOX(pageData->m_box),
                pageData->m_image, false, false, m_padding);
        }
    }
    else if (pageData->m_image)
    {
        gtk_widget_destroy(pageData->m_image);
        pageData->m_image = NULL;
    }
    pageData->m_imageIndex = image;

    return true;
}
Esempio n. 2
0
bool wxNotebook::SetPageImage(size_t nPage, int nImage)
{
    wxCHECK_MSG( IS_VALID_PAGE(nPage), false,
        wxT("SetPageImage: invalid notebook page") );
    wxCHECK_MSG( HasImageList() && nImage < GetImageList()->GetImageCount(), false,
        wxT("SetPageImage: invalid image index") );

    if ( nImage != m_images[nPage] )
    {
        // if the item didn't have an icon before or, on the contrary, did have
        // it but has lost it now, its size will change - but if the icon just
        // changes, it won't
        m_images[nPage] = nImage;

        MacSetupTabs() ;
    }

    return true;
}
Esempio n. 3
0
bool wxNotebook::SetPageImage(size_t n, int imageId)
{
    wxCHECK_MSG(n < GetPageCount(), false, "invalid notebook index");

    if (imageId >= 0)
    {
        wxCHECK_MSG(HasImageList(), false, "invalid notebook imagelist");
        const wxBitmap* bitmap = GetImageList()->GetBitmapPtr(imageId);
        if (bitmap == NULL)
            return false;
        // set the new image:
        m_qtTabWidget->setTabIcon( n, QIcon( *bitmap->GetHandle() ));
    }
    else
    {
        // remove the image using and empty qt icon:
        m_qtTabWidget->setTabIcon( n, QIcon() );
    }
    m_images[n] = imageId;
    return true;
}
Esempio n. 4
0
bool wxNotebook::InsertPage(size_t n, wxWindow *page, const wxString& text,
    bool bSelect, int imageId)
{
    // disable firing qt signals until wx structures are filled
    m_qtTabWidget->blockSignals(true);

    if (imageId != -1)
    {
        if (HasImageList())
        {
            const wxBitmap* bitmap = GetImageList()->GetBitmapPtr(imageId);
            m_qtTabWidget->insertTab( n, page->GetHandle(), QIcon( *bitmap->GetHandle() ), wxQtConvertString( text ));
        }
        else
        {
            wxFAIL_MSG("invalid notebook imagelist");
        }
    }
    else
    {
        m_qtTabWidget->insertTab( n, page->GetHandle(), wxQtConvertString( text ));
    }

    m_pages.Insert(page, n);
    m_images.insert(m_images.begin() + n, imageId);

    // reenable firing qt signals as internal wx initialization was completed
    m_qtTabWidget->blockSignals(false);

    if (bSelect && GetPageCount() > 1)
    {
        SetSelection( n );
    }

    return true;
}
Esempio n. 5
0
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 wxNotebook::AddChildGTK
    // why this has to be done.
    gtk_widget_unparent(win->m_widget);

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

    GtkNotebook *notebook = GTK_NOTEBOOK(m_widget);

    wxGtkNotebookPage* pageData = new wxGtkNotebookPage;

    m_pages.Insert(win, position);
    m_pagesData.Insert(position, pageData);

    // 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.
    pageData->m_imageIndex = imageId;

    pageData->m_box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 1);
    gtk_container_set_border_width(GTK_CONTAINER(pageData->m_box), 2);

    pageData->m_image = NULL;
    if (imageId != -1)
    {
        if (HasImageList())
        {
            const wxBitmap* bitmap = GetImageList()->GetBitmapPtr(imageId);
            pageData->m_image = gtk_image_new_from_pixbuf(bitmap->GetPixbuf());
            gtk_box_pack_start(GTK_BOX(pageData->m_box),
                pageData->m_image, false, false, m_padding);
        }
        else
        {
            wxFAIL_MSG("invalid notebook imagelist");
        }
    }

    /* set the label text */
    pageData->m_label = gtk_label_new(wxGTK_CONV(wxStripMenuCodes(text)));
    gtk_box_pack_end(GTK_BOX(pageData->m_box),
        pageData->m_label, false, false, m_padding);

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

    /* apply current style */
#ifdef __WXGTK3__
    GTKApplyStyle(pageData->m_label, NULL);
#else
    GtkRcStyle *style = GTKCreateWidgetStyle();
    if ( style )
    {
        gtk_widget_modify_style(pageData->m_label, style);
        g_object_unref(style);
    }
#endif

    if (select && GetPageCount() > 1)
    {
        SetSelection( position );
    }

    InvalidateBestSize();
    return true;
}
Esempio n. 6
0
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( HasImageList() );

        const wxBitmap *bmp = GetImageList()->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;
}
Esempio n. 7
0
bool wxNotebook::SetPageImage( size_t page, int image )
{
    /* HvdH 28-12-98: now it works, but it's a bit of a kludge */

    wxGtkNotebookPage* nb_page = GetNotebookPage(page);

    if (!nb_page) return FALSE;

    /* Optimization posibility: return immediately if image unchanged.
     * Not enabled because it may break existing (stupid) code that
     * manipulates the imagelist to cycle images */

    /* if (image == nb_page->m_image) return true; */

    /* For different cases:
       1) no image -> no image
       2) image -> no image
       3) no image -> image
       4) image -> image */

    if (image == -1 && nb_page->m_image == -1)
        return true; /* Case 1): Nothing to do. */

    GtkWidget *pixmapwid = NULL;

    if (nb_page->m_image != -1)
    {
        /* Case 2) or 4). There is already an image in the gtkhbox. Let's find it */

        GList *child = gtk_container_children(GTK_CONTAINER(nb_page->m_box));
        while (child)
        {
            if (GTK_IS_PIXMAP(child->data))
            {
                pixmapwid = GTK_WIDGET(child->data);
                break;
            }
            child = child->next;
        }

        /* We should have the pixmap widget now */
        wxASSERT(pixmapwid != NULL);

        if (image == -1)
        {
            /* If there's no new widget, just remove the old from the box */
            gtk_container_remove(GTK_CONTAINER(nb_page->m_box), pixmapwid);
            nb_page->m_image = -1;

            return true; /* Case 2) */
        }
    }

    /* Only cases 3) and 4) left */
    wxASSERT( HasImageList() ); /* Just in case */

    /* Construct the new pixmap */
    const wxBitmap *bmp = GetImageList()->GetBitmapPtr(image);
    GdkPixmap *pixmap = bmp->GetPixmap();
    GdkBitmap *mask = NULL;
    if ( bmp->GetMask() )
    {
        mask = bmp->GetMask()->GetBitmap();
    }

    if (pixmapwid == NULL)
    {
        /* Case 3) No old pixmap. Create a new one and prepend it to the hbox */
        pixmapwid = gtk_pixmap_new (pixmap, mask );

        /* CHECKME: Are these pack flags okay? */
        gtk_box_pack_start(GTK_BOX(nb_page->m_box), pixmapwid, FALSE, FALSE, m_padding);
        gtk_widget_show(pixmapwid);
    }
    else
    {
        /* Case 4) Simply replace the pixmap */
        gtk_pixmap_set(GTK_PIXMAP(pixmapwid), pixmap, mask);
    }

    nb_page->m_image = image;

    return true;
}