Beispiel #1
0
//*****************************************************************************
//
//! Handles messages for a slider widget.
//!
//! \param psWidget is a pointer to the slider widget.
//! \param ui32Msg is the message.
//! \param ui32Param1 is the first parameter to the message.
//! \param ui32Param2 is the second parameter to the message.
//!
//! This function receives messages intended for this slider widget and
//! processes them accordingly.  The processing of the message varies based on
//! the message in question.
//!
//! Unrecognized messages are handled by calling WidgetDefaultMsgProc().
//!
//! \return Returns a value appropriate to the supplied message.
//
//*****************************************************************************
int32_t
SliderMsgProc(tWidget *psWidget, uint32_t ui32Msg, uint32_t ui32Param1,
              uint32_t ui32Param2)
{
    //
    // Check the arguments.
    //
    ASSERT(psWidget);

    //
    // Determine which message is being sent.
    //
    switch(ui32Msg)
    {
        //
        // The widget paint request has been sent.
        //
        case WIDGET_MSG_PAINT:
        {
            //
            // Handle the widget paint request.
            //
            SliderPaint(psWidget, &(psWidget->sPosition));

            //
            // Return one to indicate that the message was successfully
            // processed.
            //
            return(1);
        }

        //
        // One of the pointer requests has been sent.
        //
        case WIDGET_MSG_PTR_DOWN:
        case WIDGET_MSG_PTR_MOVE:
        case WIDGET_MSG_PTR_UP:
        {
            //
            // Handle the pointer request, returning the appropriate value.
            //
            return(SliderClick(psWidget, ui32Msg, ui32Param1, ui32Param2));
        }

        //
        // An unknown request has been sent.
        //
        default:
        {
            //
            // Let the default message handler process this message.
            //
            return(WidgetDefaultMsgProc(psWidget, ui32Msg, ui32Param1,
                                        ui32Param2));
        }
    }
}
Beispiel #2
0
//*****************************************************************************
//
//! Handles pointer events for slider.
//!
//! \param pWidget is a pointer to the slider widget.
//! \param ulMsg is the pointer event message.
//! \param lX is the X coordinate of the pointer event.
//! \param lY is the Y coordinate of the pointer event.
//!
//! This function processes pointer event messages for a slider.  This is
//! called in response to a \b #WIDGET_MSG_PTR_DOWN, \b #WIDGET_MSG_PTR_MOVE,
//! and \b #WIDGET_MSG_PTR_UP messages.
//!
//! If the message is \b #WIDGET_MSG_PTR_MOVE or is \b #WIDGET_MSG_PTR_DOWN and
//! the coordinates are within the bounds of the slider, the slider value is
//! updated and, if changed, the slider's OnChange callback function is called.
//!
//! \return Returns 1 if the message was consumed by the slider and 0
//! otherwise.
//
//*****************************************************************************
static long
SliderClick(tWidget *pWidget, unsigned long ulMsg, long lX, long lY)
{
    tSliderWidget *pSlider;
    tRectangle sRedrawRect;
    short sPos;
    long lNewVal;

    //
    // Check the arguments.
    //
    ASSERT(pWidget);

    //
    // Convert the generic widget pointer into a slider widget pointer.
    //
    pSlider = (tSliderWidget *)pWidget;

    //
    // If the slider is locked, ignore all pointer messages.
    //
    if(pSlider->ulStyle & SL_STYLE_LOCKED)
    {
        return(0);
    }

    //
    // See if the given coordinates are within the extents of the slider.
    //
    if((ulMsg == WIDGET_MSG_PTR_MOVE) ||
       ((ulMsg == WIDGET_MSG_PTR_DOWN) &&
        (lX >= pWidget->sPosition.sXMin) &&
        (lX <= pWidget->sPosition.sXMax) &&
        (lY >= pWidget->sPosition.sYMin) &&
        (lY <= pWidget->sPosition.sYMax)))
    {
        //
        // Map the pointer position to a slider value.
        //
        lNewVal = SliderPositionToValue(pSlider,
                             (pSlider->ulStyle & SL_STYLE_VERTICAL) ? lY : lX);

        //
        // Convert back to ensure that the dirty rectangle we calculate here
        // uses the same values as will be used when the widget is next
        // painted.
        //
        sPos = SliderValueToPosition(pSlider, lNewVal);

        //
        // Did the value change?
        //
        if(lNewVal != pSlider->lValue)
        {
            //
            // Yes - the value changed so report it to the app and redraw the
            // slider.
            //
            if(pSlider->pfnOnChange)
            {
                (pSlider->pfnOnChange)(pWidget, lNewVal);
            }

            //
            // Determine the rectangle that we need to redraw to update the
            // slider to the new position.
            //
            if(pSlider->ulStyle & SL_STYLE_VERTICAL)
            {
                //
                // Vertical slider case.
                //
                sRedrawRect.sYMin = min(pSlider->sPos, sPos);
                sRedrawRect.sYMax = max(pSlider->sPos, sPos);
                sRedrawRect.sXMin = pWidget->sPosition.sXMin;
                sRedrawRect.sXMax = pWidget->sPosition.sXMax;
            }
            else
            {
                //
                // Horizontal slider case.
                //
                sRedrawRect.sXMin = min(pSlider->sPos, sPos);
                sRedrawRect.sXMax = max(pSlider->sPos, sPos);
                sRedrawRect.sYMin = pWidget->sPosition.sYMin;
                sRedrawRect.sYMax = pWidget->sPosition.sYMax;
            }

            //
            // Update the widget value and position.
            //
            pSlider->lValue = lNewVal;
            pSlider->sPos = sPos;

            //
            // Redraw the area of the control that has changed.
            //
            SliderPaint(pWidget, &sRedrawRect);
        }

        //
        // These coordinates are within the extents of the slider widget.
        //
        return(1);
    }

    //
    // These coordinates are not within the extents of the slider widget.
    //
    return(0);
}