コード例 #1
0
ファイル: bmpbuttn.cpp プロジェクト: chromylei/third_party
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);
    }
}
コード例 #2
0
bool wxBitmapButton::OS2OnDraw( WXDRAWITEMSTRUCT* pItem)
{
    PUSERBUTTON  pUser     = (PUSERBUTTON)pItem;
    bool         bAutoDraw = (GetWindowStyleFlag() & wxBU_AUTODRAW) != 0;

    if (!pUser)
        return false;

    wxBitmap   bitmap;
    bool       bIsSelected = pUser->fsState & BDS_HILITED;
    wxClientDC vDc(this);

    if (bIsSelected)
        bitmap = GetBitmapPressed();
    else if (pUser->fsState & BDS_DEFAULT)
        bitmap = GetBitmapFocus();
    else if (pUser->fsState & BDS_DISABLED)
        bitmap = GetBitmapDisabled();

    if (!bitmap.IsOk() )
    {
        bitmap = GetBitmapLabel();
        if (!bitmap.IsOk() )
            return false;
    }


    //
    // Centre the bitmap in the control area
    //
    int                             nX1        = 0;
    int                             nY1        = 0;
    wxPMDCImpl                      *impl = (wxPMDCImpl*) vDc.GetImpl();
    int                             nWidth     = impl->m_vRclPaint.xRight - impl->m_vRclPaint.xLeft;
    int                             nHeight    = impl->m_vRclPaint.yTop - impl->m_vRclPaint.yBottom;
    int                             nBmpWidth  = bitmap.GetWidth();
    int                             nBmpHeight = bitmap.GetHeight();

    nX1 = (nWidth - nBmpWidth) / 2;
    nY1 = (nHeight - nBmpHeight) / 2;

    if (bIsSelected && bAutoDraw)
    {
        nX1++;
        nY1++;
    }

    //
    // Draw the button face
    //
    DrawFace( vDc, bIsSelected );

    //
    // Draw the bitmap
    //
    vDc.DrawBitmap( bitmap, nX1, nY1, true );

    //
    // Draw focus / disabled state, if auto-drawing
    //
    if ((pUser->fsState == BDS_DISABLED) && bAutoDraw)
    {
        DrawButtonDisable( vDc, bitmap );
    }
    else if ((pUser->fsState == BDS_DEFAULT) && bAutoDraw)
    {
        DrawButtonFocus(vDc);
    }
    return true;
} // end of wxBitmapButton::OS2OnDraw