def ChopText(dc, text, max_size):
    """
    Chops the input `text` if its size does not fit in `max_size`, by cutting the
    text and adding ellipsis at the end.

    :param `dc`: a :class:`wx.DC` device context;
    :param `text`: the text to chop;
    :param `max_size`: the maximum size in which the text should fit.

    :note: This method is used exclusively when :class:`CustomTreeCtrl` has the ``TR_ELLIPSIZE_LONG_ITEMS``
     style set.

    .. versionadded:: 0.9.3
    """
    x, y, dummy = dc.GetFullMultiLineTextExtent(text)
    if x <= max_size:
        return text
    textLen = len(text)
    last_good_length = 0
    for i in range(textLen, -1, -1):
        s = text[0:i]
        s += '...'
        x, y = dc.GetTextExtent(s)
        last_good_length = i
        if x < max_size:
            break
    ret = text[0:last_good_length] + '...'
    return ret
