Rogue Wave banner
Previous fileTop of DocumentContentsIndex pageNext file
Objective Grid User's Guide
Rogue Wave web site:  Home Page  |  Main Documentation Page

17.3 The CSliderCtrl Program

This section examines the tutorial code in detail.

17.3.1 The Declaration

As stated earlier, the grid control CGXSliderCtrl derives multiply from CGXControl, the abstract interface that the grid understands, and the CSliderCtrl. There is a second instance of CSliderCtrl as this class's member m_pStaticWnd. The reason we have two instances of CSliderCtrl is to aid control sharing among different cells. While, the multiply inherited control is always used to draw an active cell, the second instance, m_pStaticWnd is used to draw all the inactive cells. The CGXSliderCtrl is created using the construct and create paradigm, similar to the CSliderCtrl. We create both the inherited CSliderCtrl and the member CSliderCtrl in the CreateControl() function.

We will examine the rest of the functions with their implementation.

17.3.2 Activating and Deactivating the Control

Init() is a virtual function in the CGXControl class that will be called every time a cell becomes a current cell so that you can initialize the intrinsic state of the control before it becomes active.

//1

initializes the intrinsic state for this control.

    // Mouse hit
    BOOL CGXSliderCtrl::LButtonUp(UINT nFlags, CPoint pt,
                                  UINT nHitState)
    {
        // Unreferenced:
        nFlags, pt, nHitState;
    
        SetActive(TRUE);                          //1
        Refresh();                                //2
    
        CRect r = GetCellRect(m_nRow, m_nCol);
        pt.x -= r.left;
        pt.y -= r.top;
    
        PostMessage(WM_LBUTTONDOWN, MK_LBUTTON, MAKELONG(pt.x, pt.y));//3
        PostMessage(WM_LBUTTONUP, MK_LBUTTON, MAKELONG(pt.x, pt.y));
    
        // check child buttons
        CGXControl::LButtonUp(nFlags, pt, nHitState);
    
        return TRUE;
    }
    
    BOOL CGXSliderCtrl::Store()
    {
        // Calls SetStyleRange() and resets the modify flag
        ASSERT(m_pStyle);
    
        CString sValue;
        if (m_pStyle && GetModify() && GetValue(sValue))
        {
          SetActive(FALSE);
          SetModify(FALSE);
    
          return Grid()->SetValueRange(
            CGXRange(m_nRow, m_nCol),
            sValue,
            gxOverride,
            0, GX_INVALIDATE);
            // Cell will be automatically redrawn inactive
        }
    
        return TRUE;
    }
    

LbuttonUp() is another virtual in CGXControl that will be called by the grid whenever the user clicks on an inactive cell.

//1

Changes the state of the control to be active.

//2

Invalidates the cell rectangle and forces the cell to be drawn in the new active state.

//3

Posting the button down and up messages to the active control ensures immediate response from the active control.

Note that the active state is something you should maintain in your derived control. The member m_bActive and the virtual overrides SetActive() and GetActive() take care of this.

Store() is another CGXControl virtual function that will be called by the grid when the changes in the cell made by the user has to be stored in response to a user action. Note that you will have to maintain the dirty state of the control in the derived class. The member m_bModify and the virtuals GetModify() and SetModify() take care of this.

//1

Check if the cell is dirty; if it is, get the current position of the slider as a string to be stored as the value. GetValue() performs the conversion to a string.

//2

Clear the active state and the dirty flag.

//3

Store the new value into the grid using SetValueRange(). Note that you could instead use SetStyleRange() to make changes in other attributes of the cell's style.

17.3.3 Drawing the Active and Inactive State

//1

If this was called for the active cell, initialize the range for the active cell.

//2

If this was called for the inactive cell, initialize the range and position of the inactive cell.

//3

Move the corresponding control to this rectangle, invalidate it, and show it.

//4

Update the window so that it will be redrawn with its new settings.

//5

If called for the active state, set the focus to the active control.

//6

If called for the inactive state, hide the static control and validate the rectangle so that the grid will not try to redraw it.



Previous fileTop of DocumentContentsNo linkNext file

Copyright © Rogue Wave Software, Inc. All Rights Reserved.

The Rogue Wave name and logo, and Stingray, are registered trademarks of Rogue Wave Software. All other trademarks are the property of their respective owners.
Provide feedback to Rogue Wave about its documentation.