Hide

SftTree/DLL 7.5 - Tree Control

Display
Print

RecalcHorizontalExtent

Recalculates the optimal horizontal scrolling extent.

C

void WINAPI SftTree_RecalcHorizontalExtent(HWND hwndCtl);
void WINAPI SftTreeSplit_RecalcHorizontalExtent(HWND hwndCtl);

C++

void CSftTree::RecalcHorizontalExtent(int limit = 0, BOOL fVisibleOnly = FALSE);
void CSftTreeSplit::RecalcHorizontalExtent(int limit = 0, BOOL fVisibleOnly = FALSE);

Parameters

hwndCtl

The window handle of the tree control.

limit

Defines the maximum number of items to be considered for width calculation. Specify a number less than or equal to 0 to consider all items. If a tree control contains many items, scanning all items may be extremely slow, as each cell's width needs to be calculated. Using an application defined maximum number, the calculation can be limited to limit items. This results in better response time, yet some items which are not within the number of scanned items may still be clipped.

fVisibleOnly

Specify TRUE to limit the width calculation to visible items only. Items which are not visible because their parent items are collapsed are not included in the width calculation.

Comments

The RecalcHorizontalExtent function recalculates the optimal horizontal scrolling extent.

By default, a tree control does not handle horizontal scrolling, even if the WS_HSCROLL window style is defined. To start horizontal scrolling, an application should use RecalcHorizontalExtent or SetHorizontalExtent.

The SftTree_RecalcHorizontalExtent function does not support the parameters limit and fVisibleOnly. Use the SetCalcLimit and SetCalcVisibleOnly functions to supply this information before calling SftTree_RecalcHorizontalExtent.

Based on the definition of the last column, different algorithms are used to calculate the optimal scrolling extent. Using SetOpenEnded, the last column can be defined as open-ended. An open-ended last column will display the complete text specified for the last (or only) column and never truncate any data. A fixed-width last column is defined with a specified width and any data which doesn't fit is truncated.

Open-ended Last Column

Recalculating the best horizontal scrolling extent can be a costly operation (in terms of elapsed time). When updating a tree control, it is best to delay using RecalcHorizontalExtent as much as possible. It is best done after all items have been added, their levels have been set and all necessary pictures and tree control attributes have been defined, because most changes to the tree control can invalidate the optimal horizontal scrolling extent calculated.

When calculating the optimal scrolling extent, each item will be analyzed and its length calculated using the item's cell text component and its level. The widest item determines the horizontal scrolling extent. If the text component is not available for this calculation because it is supplied by a drawing callback routine, then this function calculates the widest item without considering the text component. It is up to the application to increase the calculated horizontal scrolling extent by using SetHorizontalExtent.

Fixed-Width Last Column

Recalculating the best horizontal scrolling extent is a very quick operation. The width of all columns and some initial overhead (based on the highest level number found) is calculated to determine the horizontal scrolling extent. No item text is analyzed.

Examples

C

        /* control attributes.                                                          */
        /*------------------------------------------------------------------------------*/

        /* Make row header width optimal, so text and pictures are */
        /* not clipped horizontally.                               */
        SftTree_MakeRowHeaderOptimal(g_hwndTree);/* Make row header width optimal */

        SftTree_MakeColumnOptimal(g_hwndTree, 0);/* Only make the first column optimal */
        SftTree_RecalcHorizontalExtent(g_hwndTree);/* Update horizontal scroll bar */

        SftTree_SetCaretIndex(g_hwndTree, 0);
        SftTree_SetCurSel(g_hwndTree, 0);
        CopyPictureFromCurrentItem(g_hwndTree);

        // Set a timer so we can update our progress bars every once in a while
        SetTimer(hwnd, TIMERID, 333, NULL);

C++

    /* control attributes.                                                          */
    /*------------------------------------------------------------------------------*/
    
    /* Make row header width optimal, so text and pictures are  */
    /* not clipped horizontally.                               */
    m_Tree.MakeRowHeaderOptimal(0, FALSE);/* Make row header width optimal */

    m_Tree.MakeColumnOptimal(0);/* Only make the first column optimal */
    m_Tree.RecalcHorizontalExtent(0, FALSE);/* Update horizontal scroll bar */

    m_Tree.SetCaretIndex(0);
    m_Tree.SetCurSel(0);
    CopyPictureFromCurrentItem();

    // Set a timer so we can update our progress bars every once in a while
    SetTimer(TIMERID, 333, NULL);

See Also C/C++ API | Categories | Notifications