Exemplo n.º 1
0
wxCheckListBoxItem::wxCheckListBoxItem (
  wxCheckListBox*                   pParent
, size_t                            nIndex
)
: wxOwnerDrawn( wxEmptyString
               ,TRUE // checkable
              )
{
    m_bChecked = FALSE;
    m_pParent  = pParent;
    m_nIndex   = nIndex;

    //
    // We don't initialize m_nCheckHeight/Width vars because it's
    // done in OnMeasure while they are used only in OnDraw and we
    // know that there will always be OnMeasure before OnDraw
    //
    SetMarginWidth(GetDefaultMarginWidth());
} // end of wxCheckListBoxItem::wxCheckListBoxItem
Exemplo n.º 2
0
bool wxMenuItem::OnMeasureItem( size_t* pWidth, size_t* pHeight )
{
    wxMemoryDC vDC;

    wxString  sStr = GetName();

    //
    // If we have a valid accel string, then pad out
    // the menu string so that the menu and accel string are not
    // placed on top of each other.
    wxString accel = GetItemLabel().AfterFirst(wxT('\t'));
    if (!accel.empty() )
    {
        sStr.Pad(sStr.length()%8);
        sStr += accel;
    }
    vDC.SetFont(GetFont());
    vDC.GetTextExtent( sStr
                      ,(wxCoord *)pWidth
                      ,(wxCoord *)pHeight
                     );
    if (!accel.empty())
    {
        //
        // Measure the accelerator string, and add its width to
        // the total item width, plus 16 (Accelerators are right justified,
        // with the right edge of the text rectangle 16 pixels left of
        // the right edge of the menu)
        //
        int                         nAccelWidth;
        int                         nAccelHeight;

        vDC.GetTextExtent( m_strAccel
                          ,&nAccelWidth
                          ,&nAccelHeight
                         );
        *pWidth += nAccelWidth;
    }

    //
    // Add space at the end of the menu for the submenu expansion arrow.
    // This will also allow offsetting the accel string from the right edge
    //
    *pWidth = (size_t)(*pWidth + GetDefaultMarginWidth() * 1.5);

    //
    // JACS: items still look too tightly packed, so adding 5 pixels.
    //
    (*pHeight) += 5;

    //
    // Ray Gilbert's changes - Corrects the problem of a BMP
    // being placed next to text in a menu item, and the BMP does
    // not match the size expected by the system.  This will
    // resize the space so the BMP will fit.  Without this, BMPs
    // must be no larger or smaller than 16x16.
    //
    if (m_bmpChecked.IsOk())
    {
        //
        // Is BMP height larger than text height?
        //
        size_t                      nAdjustedHeight = m_bmpChecked.GetHeight() +
                                                      wxSystemSettings::GetMetric(wxSYS_EDGE_Y);
        if (*pHeight < nAdjustedHeight)
            *pHeight = nAdjustedHeight;

        //
        // Does BMP encroach on default check menu position?
        //
        size_t                      nAdjustedWidth = m_bmpChecked.GetWidth() +
                                                     (wxSystemSettings::GetMetric(wxSYS_EDGE_X) * 2);

        //
        // Do we need to widen margin to fit BMP?
        //
        if ((size_t)GetMarginWidth() < nAdjustedWidth)
            SetMarginWidth(nAdjustedWidth);

        //
        // Add the size of the bitmap to our total size...
        //
        *pWidth += GetMarginWidth();
    }

    //
    // Add the size of the bitmap to our total size - even if we don't have
    // a bitmap we leave room for one...
    //
    *pWidth += GetMarginWidth();

    //
    // Make sure that this item is at least as
    // tall as the user's system settings specify
    //
    const size_t heightStd = 6; // FIXME: get value from the system
    if ( *pHeight < heightStd )
      *pHeight = heightStd;
    m_nHeight = *pHeight;                // remember height for use in OnDrawItem
    return true;
} // end of wxOwnerDrawn::OnMeasureItem
Exemplo n.º 3
0
bool wxCheckListBoxItem::OnDrawItem (
  wxDC&                             rDc
, const wxRect&                     rRect
, wxODAction                        eAct
, wxODStatus                        eStat
)
{
    wxRect                          vRect = rRect;

    ::WinQueryWindowRect( m_pParent->GetHWND()
                         ,&rDc.m_vRclPaint
                        );
    if (IsChecked())
        eStat = (wxOwnerDrawn::wxODStatus)(eStat | wxOwnerDrawn::wxODChecked);

    //
    // Unfortunately PM doesn't quite get the text position exact.  We need to alter
    // it down and to the right, just a little bit.  The coords in rRect are OS/2
    // coords not wxWidgets coords.
    //
    vRect.x += 5;
    vRect.y -= 3;
    if (wxOwnerDrawn::OnDrawItem( rDc
                                 ,vRect
                                 ,eAct
                                 ,eStat))
    {
        size_t                      nCheckWidth  = GetDefaultMarginWidth();
        size_t                      nCheckHeight = m_pParent->GetItemHeight();
        int                         nParentHeight;
        int                         nX = rRect.GetX();
        int                         nY = rRect.GetY();
        int                         nOldY = nY;
        wxColour                    vColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW));
        wxPen                       vPenBack;
        wxPen                       vPenGray;
        wxPen                       vPenPrev;

        m_pParent->GetSize( NULL
                           ,&nParentHeight
                          );

        nY = nParentHeight - nY - nCheckHeight;
        vPenBack = wxPen(vColour, 1, wxSOLID);
        vPenGray = wxPen(wxColour(127, 127, 127), 1, wxSOLID);

        //
        // Erase the 1-pixel border
        //
        rDc.SetPen(vPenBack);
        rDc.DrawRectangle( nX
                          ,nY
                          ,nCheckWidth
                          ,nCheckHeight
                         );

        //
        // Now we draw the smaller rectangle
        //
        nY++;
        nCheckWidth  -= 2;
        nCheckHeight -= 2;

        //
        // Draw hollow gray rectangle
        //
        rDc.SetPen(vPenGray);
        rDc.DrawRectangle( nX
                          ,nY
                          ,nCheckWidth
                          ,nCheckHeight
                         );

        nX++;
        if (IsChecked())
        {
            //
            // Draw the check by loading the sys standard bitmap and drawing it
            //
            HBITMAP                 hChkBmp = ::WinGetSysBitmap( HWND_DESKTOP
                                                                ,SBMP_MENUCHECK
                                                               );
            POINTL                  vPoint = {nX, nOldY + 3};

            ::WinDrawBitmap( rDc.GetHPS()
                            ,hChkBmp
                            ,NULL
                            ,&vPoint
                            ,NULL
                            ,NULL
                            ,DBM_NORMAL
                           );
        }
        return TRUE;
    }
    return FALSE;
} // end of wxCheckListBoxItem::OnDrawItem