Ejemplo n.º 1
0
void wxStaticBitmap::DoSetBitmap()
{
    Widget widget = (Widget) m_mainWidget;
    int w2, h2;

    if (m_messageBitmapOriginal.Ok())
    {
        w2 = m_messageBitmapOriginal.GetWidth();
        h2 = m_messageBitmapOriginal.GetHeight();

        Pixmap pixmap;

        // Must re-make the bitmap to have its transparent areas drawn
        // in the current widget background colour.
        if (m_messageBitmapOriginal.GetMask())
        {
            int backgroundPixel;
            XtVaGetValues( widget, XmNbackground, &backgroundPixel,
                NULL);

            wxColour col;
            col.SetPixel(backgroundPixel);

            wxBitmap newBitmap = wxCreateMaskedBitmap(m_messageBitmapOriginal, col);
            m_messageBitmap = newBitmap;

            pixmap = (Pixmap) m_messageBitmap.GetDrawable();
        }
        else
        {
            m_bitmapCache.SetBitmap( m_messageBitmap );
            pixmap = (Pixmap)m_bitmapCache.GetLabelPixmap(widget);
        }

        XtVaSetValues (widget,
            XmNlabelPixmap, pixmap,
            XmNlabelType, XmPIXMAP,
            NULL);

        SetSize(w2, h2);
    }
    else
    {
        // Null bitmap: must not use current pixmap
        // since it is no longer valid.
        XtVaSetValues (widget,
            XmNlabelType, XmSTRING,
            XmNlabelPixmap, XmUNSPECIFIED_PIXMAP,
            NULL);
    }    
}
Ejemplo n.º 2
0
bool wxToolBar::Realize()
{
    if ( m_tools.GetCount() == 0 )
    {
        // nothing to do
        return true;
    }

    bool isVertical = GetWindowStyle() & wxTB_VERTICAL;

    // Separator spacing
    const int separatorSize = GetToolSeparation(); // 8;
    wxSize margins = GetToolMargins();
    int packing = GetToolPacking();
    int marginX = margins.x;
    int marginY = margins.y;

    int currentX = marginX;
    int currentY = marginY;

    int buttonHeight = 0, buttonWidth = 0;

    Widget button;
    Pixmap pixmap, insensPixmap;
    wxBitmap bmp, insensBmp;

    wxToolBarToolsList::compatibility_iterator node = m_tools.GetFirst();
    while ( node )
    {
        wxToolBarTool *tool = (wxToolBarTool *)node->GetData();

        switch ( tool->GetStyle() )
        {
            case wxTOOL_STYLE_CONTROL:
            {
                wxControl* control = tool->GetControl();
                wxSize sz = control->GetSize();
                wxPoint pos = control->GetPosition();
                // Allow a control to specify a y[x]-offset by setting
                // its initial position, but still don't allow it to
                // position itself above the top[left] margin.
                int controlY = (pos.y > 0) ? pos.y : currentY;
                int controlX = (pos.x > 0) ? pos.x : currentX;
                control->Move( isVertical ? controlX : currentX,
                               isVertical ? currentY : controlY );
                if ( isVertical )
                    currentY += sz.y + packing;
                else
                    currentX += sz.x + packing;

                break;
            }
            case wxTOOL_STYLE_SEPARATOR:
                // skip separators for vertical toolbars
                if( !isVertical )
                {
                    currentX += separatorSize;
                }
                break;

            case wxTOOL_STYLE_BUTTON:
                button = (Widget) 0;

                if ( tool->CanBeToggled() && !tool->GetButtonWidget() )
                {
                    button = XtVaCreateWidget("toggleButton",
                            xmToggleButtonWidgetClass, (Widget) m_mainWidget,
                            XmNx, currentX, XmNy, currentY,
                            XmNindicatorOn, False,
                            XmNshadowThickness, 2,
                            XmNborderWidth, 0,
                            XmNspacing, 0,
                            XmNmarginWidth, 0,
                            XmNmarginHeight, 0,
                            XmNmultiClick, XmMULTICLICK_KEEP,
                            XmNlabelType, XmPIXMAP,
                            NULL);
                    XtAddCallback ((Widget) button,
                                   XmNvalueChangedCallback,
                                   (XtCallbackProc) wxToolButtonCallback,
                                   (XtPointer) this);

                    XtVaSetValues ((Widget) button,
                                   XmNselectColor,
                                   m_backgroundColour.AllocColour
                                       (XtDisplay((Widget) button)),
                                   NULL);
                }
                else if( !tool->GetButtonWidget() )
                {
                    button = XtVaCreateWidget("button",
                            xmPushButtonWidgetClass, (Widget) m_mainWidget,
                            XmNx, currentX, XmNy, currentY,
                            XmNpushButtonEnabled, True,
                            XmNmultiClick, XmMULTICLICK_KEEP,
                            XmNlabelType, XmPIXMAP,
                            NULL);
                    XtAddCallback (button,
                                   XmNactivateCallback,
                                   (XtCallbackProc) wxToolButtonCallback,
                                   (XtPointer) this);
                }

                if( !tool->GetButtonWidget() )
                {
                    wxDoChangeBackgroundColour((WXWidget) button,
                                               m_backgroundColour, true);

                    tool->SetWidget(button);
                }
                else
                {
                    button = (Widget)tool->GetButtonWidget();
                    XtVaSetValues( button,
                                   XmNx, currentX, XmNy, currentY,
                                   NULL );
                }

                // For each button, if there is a mask, we must create
                // a new wxBitmap that has the correct background colour
                // for the button. Otherwise the background will just be
                // e.g. black if a transparent XPM has been loaded.
                bmp = tool->GetNormalBitmap();
                insensBmp = tool->GetDisabledBitmap();
                if ( bmp.GetMask() || insensBmp.GetMask() )
                {
                    WXPixel backgroundPixel;
                    XtVaGetValues(button, XmNbackground, &backgroundPixel,
                                  NULL);

                    wxColour col;
                    col.SetPixel(backgroundPixel);

                    if( bmp.IsOk() && bmp.GetMask() )
                    {
                        bmp = wxCreateMaskedBitmap(bmp, col);
                        tool->SetNormalBitmap(bmp);
                    }

                    if( insensBmp.IsOk() && insensBmp.GetMask() )
                    {
                        insensBmp = wxCreateMaskedBitmap(insensBmp, col);
                        tool->SetDisabledBitmap(insensBmp);
                    }
                }

                // Create a selected/toggled bitmap. If there isn't a 2nd
                // bitmap, we need to create it (with a darker, selected
                // background)
                WXPixel backgroundPixel;
                if ( tool->CanBeToggled() )
                    XtVaGetValues(button, XmNselectColor, &backgroundPixel,
                                  NULL);
                else
                    XtVaGetValues(button, XmNarmColor, &backgroundPixel,
                                  NULL);
                wxColour col;
                col.SetPixel(backgroundPixel);

                pixmap = (Pixmap) bmp.GetDrawable();
                {
                    wxBitmap tmp = tool->GetDisabledBitmap();

                    insensPixmap = tmp.IsOk() ?
                            (Pixmap)tmp.GetDrawable() :
                            tool->GetInsensPixmap();
                }

                if (tool->CanBeToggled())
                {
                    // Toggle button
                    Pixmap pixmap2 = tool->GetArmPixmap();
                    Pixmap insensPixmap2 = tool->GetInsensPixmap();

                    XtVaSetValues (button,
                            XmNfillOnSelect, True,
                            XmNlabelPixmap, pixmap,
                            XmNselectPixmap, pixmap2,
                            XmNlabelInsensitivePixmap, insensPixmap,
                            XmNselectInsensitivePixmap, insensPixmap2,
                            XmNlabelType, XmPIXMAP,
                            NULL);
                }
                else
                {
                    Pixmap pixmap2 = tool->GetArmPixmap();

                    // Normal button
                    XtVaSetValues(button,
                            XmNlabelPixmap, pixmap,
                            XmNlabelInsensitivePixmap, insensPixmap,
                            XmNarmPixmap, pixmap2,
                            NULL);
                }

                XtManageChild(button);

                {
                    Dimension width, height;
                    XtVaGetValues(button,
                                  XmNwidth, &width,
                                  XmNheight, & height,
                                  NULL);
                    if ( isVertical )
                        currentY += height + packing;
                    else
                        currentX += width + packing;
                    buttonHeight = wxMax(buttonHeight, height);
                    buttonWidth = wxMax(buttonWidth, width);
                }

                XtAddEventHandler (button, EnterWindowMask | LeaveWindowMask,
                        False, wxToolButtonPopupCallback, (XtPointer) this);

                break;
        }

        node = node->GetNext();
    }

    SetSize( -1, -1,
             isVertical ? buttonWidth + 2 * marginX : -1,
             isVertical ? -1 : buttonHeight +  2*marginY );

    return true;
}
Ejemplo n.º 3
0
void wxBitmapButton::DoSetBitmap()
{
    if (m_bmpNormalOriginal.Ok())
    {
        Pixmap pixmap = 0;
        Pixmap insensPixmap = 0;
        Pixmap armPixmap = 0;

        // Must re-make the bitmap to have its transparent areas drawn
        // in the current widget background colour.
        if (m_bmpNormalOriginal.GetMask())
        {
            WXPixel backgroundPixel;
            XtVaGetValues((Widget) m_mainWidget,
                          XmNbackground, &backgroundPixel,
                          NULL);

            wxColour col;
            col.SetPixel(backgroundPixel);

            wxBitmap newBitmap =
                wxCreateMaskedBitmap(m_bmpNormalOriginal, col);
            m_bmpNormal = newBitmap;
            m_bitmapCache.SetBitmap( m_bmpNormal );

            pixmap = (Pixmap) m_bmpNormal.GetDrawable();
        }
        else
        {
            m_bitmapCache.SetBitmap( m_bmpNormal );
            pixmap = (Pixmap) m_bitmapCache.GetLabelPixmap(m_mainWidget);
        }

        if (m_bmpDisabledOriginal.Ok())
        {
            if (m_bmpDisabledOriginal.GetMask())
            {
                WXPixel backgroundPixel;
                XtVaGetValues((Widget) m_mainWidget,
                              XmNbackground, &backgroundPixel,
                              NULL);

                wxColour col;
                col.SetPixel(backgroundPixel);

                wxBitmap newBitmap =
                    wxCreateMaskedBitmap(m_bmpDisabledOriginal, col);
                m_bmpDisabled = newBitmap;

                insensPixmap = (Pixmap) m_bmpDisabled.GetDrawable();
            }
            else
                insensPixmap = (Pixmap) m_bitmapCache.GetInsensPixmap(m_mainWidget);
        }
        else
            insensPixmap = (Pixmap) m_bitmapCache.GetInsensPixmap(m_mainWidget);

        // Now make the bitmap representing the armed state
        if (m_bmpSelectedOriginal.Ok())
        {
            if (m_bmpSelectedOriginal.GetMask())
            {
                WXPixel backgroundPixel;
                XtVaGetValues((Widget) m_mainWidget,
                              XmNarmColor, &backgroundPixel,
                              NULL);

                wxColour col;
                col.SetPixel(backgroundPixel);

                wxBitmap newBitmap =
                    wxCreateMaskedBitmap(m_bmpSelectedOriginal, col);
                m_bmpSelected = newBitmap;

                armPixmap = (Pixmap) m_bmpSelected.GetDrawable();
            }
            else
                armPixmap = (Pixmap) m_bitmapCache.GetArmPixmap(m_mainWidget);
        }
        else
            armPixmap = (Pixmap) m_bitmapCache.GetArmPixmap(m_mainWidget);

        XtVaSetValues ((Widget) m_mainWidget,
            XmNlabelPixmap, pixmap,
            XmNlabelInsensitivePixmap, insensPixmap,
            XmNarmPixmap, armPixmap,
            XmNlabelType, XmPIXMAP,
            NULL);
    }
    else
    {
        // Null bitmap: must not use current pixmap
        // since it is no longer valid.
        XtVaSetValues ((Widget) m_mainWidget,
            XmNlabelType, XmSTRING,
            XmNlabelPixmap, XmUNSPECIFIED_PIXMAP,
            XmNlabelInsensitivePixmap, XmUNSPECIFIED_PIXMAP,
            XmNarmPixmap, XmUNSPECIFIED_PIXMAP,
            NULL);
    }
}