void wxToolBar::DoToggleTool(
  wxToolBarToolBase*                pTool
, bool                              WXUNUSED(bToggle)
)
{
    DrawTool(pTool);
} // end of wxToolBar::DoToggleTool
Beispiel #2
0
void wxToolBar::DrawTool(
  wxToolBarToolBase*                pTool
)
{
    wxClientDC                      vDc(this);

    DrawTool( vDc
             ,pTool
            );
} // end of wxToolBar::DrawTool
//
// Okay, so we've left the tool we're in ... we must check if the tool we're
// leaving was a 'sprung push button' and if so, spring it back to the up
// state.
//
void wxToolBar::SpringUpButton(
  int                               vId
)
{
    wxToolBarToolBase*              pTool = FindById(vId);

    if (pTool && pTool->CanBeToggled())
    {
        if (pTool->IsToggled())
            pTool->Toggle();

        DrawTool(pTool);
    }
} // end of wxToolBar::SpringUpButton
void wxToolBar::OnMouseEvent(
  wxMouseEvent&                     rEvent
)
{
    POINTL                          vPoint;
    HWND                            hWnd;
    wxCoord                         vX;
    wxCoord                         vY;
    HPOINTER                        hPtr = ::WinQuerySysPointer(HWND_DESKTOP, SPTR_ARROW, FALSE);

    ::WinSetPointer(HWND_DESKTOP, hPtr);
    ::WinQueryPointerPos(HWND_DESKTOP, &vPoint);
    hWnd = ::WinWindowFromPoint(HWND_DESKTOP, &vPoint, TRUE);
    if (hWnd != (HWND)GetHwnd())
    {
        m_vToolTimer.Stop();
        return;
    }

    rEvent.GetPosition(&vX, &vY);

    wxToolBarTool*            pTool = (wxToolBarTool *)FindToolForPosition( vX
                                                                           ,vY
                                                                          );

    if (rEvent.LeftDown())
    {
        CaptureMouse();
    }
    if (rEvent.LeftUp())
    {
        ReleaseMouse();
    }

    if (!pTool)
    {
        m_vToolTimer.Stop();
        if (m_nCurrentTool > -1)
        {
            if (rEvent.LeftIsDown())
                SpringUpButton(m_nCurrentTool);
            pTool = (wxToolBarTool *)FindById(m_nCurrentTool);
            if (pTool && !pTool->IsToggled())
            {
                RaiseTool( pTool, FALSE );
            }
            m_nCurrentTool = -1;
            OnMouseEnter(-1);
        }
        return;
    }
    if (!rEvent.IsButton())
    {
        if (pTool->GetId() != m_nCurrentTool)
        {
            //
            // If the left button is kept down and moved over buttons,
            // press those buttons.
            //
            if (rEvent.LeftIsDown() && pTool->IsEnabled())
            {
                SpringUpButton(m_nCurrentTool);
                if (pTool->CanBeToggled())
                {
                    pTool->Toggle();
                }
                DrawTool(pTool);
            }
            wxToolBarTool*          pOldTool = (wxToolBarTool*)FindById(m_nCurrentTool);

            if (pOldTool && !pTool->IsToggled())
                RaiseTool( pOldTool, FALSE );
            m_nCurrentTool = pTool->GetId();
            OnMouseEnter(m_nCurrentTool);
            if (!pTool->GetShortHelp().empty())
            {
                if (m_pToolTip)
                    delete m_pToolTip;
                m_pToolTip = new wxToolTip(pTool->GetShortHelp());
                m_vXMouse = (wxCoord)vPoint.x;
                m_vYMouse = (wxCoord)vPoint.y;
                m_vToolTimer.Start(1000L, TRUE);
            }
            if (!pTool->IsToggled())
                RaiseTool(pTool);
        }
        return;
    }

    // Left button pressed.
    if (rEvent.LeftDown() && pTool->IsEnabled())
    {
        if (pTool->CanBeToggled())
        {
            pTool->Toggle();
        }
        DrawTool(pTool);
    }
    else if (rEvent.RightDown())
    {
        OnRightClick( pTool->GetId()
                     ,vX
                     ,vY
                    );
    }

    //
    // Left Button Released.  Only this action confirms selection.
    // If the button is enabled and it is not a toggle tool and it is
    // in the pressed state, then raise the button and call OnLeftClick.
    //
    if (rEvent.LeftUp() && pTool->IsEnabled() )
    {
        //
        // Pass the OnLeftClick event to tool
        //
        if (!OnLeftClick( pTool->GetId()
                         ,pTool->IsToggled()) &&
                          pTool->CanBeToggled())
        {
            //
            // If it was a toggle, and OnLeftClick says No Toggle allowed,
            // then change it back
            //
            pTool->Toggle();
        }
        DrawTool(pTool);
    }
} // end of wxToolBar::OnMouseEvent
void wxToolBar::OnPaint (
  wxPaintEvent&                     WXUNUSED(rEvent)
)
{
    wxPaintDC                       vDc(this);

    PrepareDC(vDc);

    static int                      nCount = 0;

    //
    // Prevent reentry of OnPaint which would cause wxMemoryDC errors.
    //
    if (nCount > 0)
        return;
    nCount++;

    wxPMDCImpl *impl = (wxPMDCImpl*) vDc.GetImpl();
    ::WinFillRect(impl->GetHPS(), &impl->m_vRclPaint, GetBackgroundColour().GetPixel());
    for ( wxToolBarToolsList::compatibility_iterator node = m_tools.GetFirst();
          node;
          node = node->GetNext() )
    {
        wxToolBarTool*              pTool = (wxToolBarTool*)node->GetData();

        if (pTool->IsButton() )
            DrawTool(vDc, pTool);
        if (pTool->IsSeparator())
        {
            wxColour gray85(85, 85, 85);
            wxPen vDarkGreyPen( gray85, 1, wxSOLID );
            int nX;
            int nY;
            int nHeight = 0;
            int nWidth = 0;

            vDc.SetPen(vDarkGreyPen);
            if (HasFlag(wxTB_TEXT))
            {
                if (HasFlag(wxTB_TOP) || HasFlag(wxTB_BOTTOM))
                {
                    nX = pTool->m_vX;
                    nY = pTool->m_vY - (m_vTextY - 6);
                    nHeight = (m_vTextY - 2) + pTool->GetHeight();
                }
                else
                {
                    nX = pTool->m_vX + m_xMargin + 10;
                    nY = pTool->m_vY + m_vTextY + m_toolSeparation;
                    nWidth = pTool->GetWidth() > m_vTextX ? pTool->GetWidth() : m_vTextX;
                }
            }
            else
            {
                nX = pTool->m_vX;
                nY = pTool->m_vY;
                if (HasFlag(wxTB_TOP) || HasFlag(wxTB_BOTTOM))
                    nHeight = pTool->GetHeight() - 2;
                else
                {
                    nX += m_xMargin + 10;
                    nY +=  m_yMargin + m_toolSeparation;
                    nWidth = pTool->GetWidth();
                }
            }
            vDc.DrawLine(nX, nY, nX + nWidth, nY + nHeight);
        }
    }
    nCount--;
} // end of wxToolBar::OnPaint