SECListBoxEditor Class

class SECListBoxEditor: public CWnd

The SECListBoxEditor class provides the functionality of an editable list box. An editable list box is a Windows list box that enables the end user to interactively modify the items it contains.

Defined in: lstbxedt.h

Comments

The user can modify the ordering of list box items, create and delete items and edit the content of items. There are two ways to edit a list box item. First, you can in-place edit the text of the item by simply selecting the item and typing. Second, you can browse for a value by pressing the browse button located to the right of the item. A browse button is a push button labeled "..." which is only visible after the user double-clicks on an item. When pressed, the browse button pops up a dialog to allow the user to choose from a list (or tree) of possible values. After the user picks a new value and dismisses the dialog, the selected item is automatically replaced.

To support the creation, deletion and reordering of list box items, SECListBoxEditor adds several child controls, called command buttons, above the list box. The command buttons and their actions when pressed are shown below:

Command ButtonAction When Pressed
New ButtonA new list box item is created at the end of the list.
Delete ButtonThe selected list box item is removed.
Move-Up ButtonThe selected list box item is moved up one.
Move-Down ButtonThe selected list box item is moved down one.

The command buttons are optional and their creation can be individually controlled by using style flag passed into the initialization of the editable list box (See SECListBoxEditor:: Initialize.)

Several shortcut keys are also available: "Insert" to add an entry to end; "Delete" to remove currently selected item; "Escape" to discard changes for in-place edit; and "Return" to accept in-place edit changes.

The SECListBoxEditor can be used directly, or it can serve as a base class. Used directly, an SECListBoxEditor object supports item creation, deletion, reordering and in-place text editing. However, it cannot support browsing. If browsing is required, you must derive a class from SECListBoxEditor and override its OnBrowse method. Typically, an overridden OnBrowse method will pop up an application-specific modal dialog, accept the user’s choice and write the new value back to the selected list box item. Refer to the implementations of OnBrowse in  SECListBoxDirEditor and  SECListBoxFileEditor for examples of how this is done.

SECListBoxEditor now supports list boxes with the LBS_MULTIPLESEL style. Items can only be moved using the buttons or keyboard when a single item is selected (moving multiple items this way does not make sense). You can drag an item with the mouse with multiple items selected, and you the delete operation will delete all selected items.

See the LBEDIT sample in the \SAMPLES\TOOLKIT\STANDARD\CONTROLS\LBEDIT directory for a demonstration of the SECListBoxEditor class.

See Also

SECListBoxDirEditor  SECListBoxFileEditor

Class Members

Creation/Initialization

SECListBoxEditor()

Constructs an SECListBoxEditor object.

virtual BOOL  Initialize(CWnd* pwndParent, UINT uiID, int iFlags = LBE_DEFAULT)

Attaches an SECListBoxEditor object to an existing list box control.

Attributes

BOOL  IsEditing() const

Determines whether in-place editing is occurring at the moment.

void  SetEscape(BOOL bSet)

Sets escape key handling.

BOOL  GetEscape()

Retrieves escape key handling state.

CListBox*  GetListBoxPtr() const

Returns a pointer to the listbox control bound to this control.

virtual void  SetQuick(BOOL bQuick = TRUE)

Sets "quick mode".

BOOL  GetQuick() const

Retrieves the "quick mode" state.

Operations

virtual void  StopEditing()

Forces an end to active in-place editing.

void  ForcePaint()

Forces a repaint

Overridable

virtual void  OnEditingJustStarted()

Called when editing has started.

virtual void  OnEditingStopped()

Called when editing has stopped.

virtual void  OnItemRenamed(int nIndexRenamed,CString strOldName,CString strNewName)

Called after an item has been renamed.

virtual void  OnItemAdded(int nIndexNewItem,CString strTextInserted)

Called after an item has been added.

virtual void  OnItemMoved(int nOldIndex,int nNewIndex,CString strTextMoved,BOOL WasDragged)

Called after an item has been moved.

virtual BOOL  OnItemDelete(int nIndexToBeDeleted,CString strTextDeleted)

Called before an item is deleted.

virtual BOOL  DoAdd()

Adds an item to the listbox.

virtual BOOL  DoDelete()

Deletes the currently selected item from the listbox.

virtual BOOL  DoMoveDown()

Moves an item down in the listbox.

virtual BOOL  DoMoveUp()

Moves an item up in the listbox.

virtual BOOL  StartEditing(TCHAR c = NULL)

Begins editing mode.

virtual int  CalculateHeight()

Calculates the height of the control.

virtual void  CalculateButtonRectangles()

Calculates the button placements.

virtual void  RecycleTooltips()

Resets tooltips for the buttons.

virtual void  ResetEditorSizePos()

Resets the edit control size and position.

virtual void  SetButtonVisibility(int iFlags)

Changes the visibility status of the buttons.

virtual BOOL  EditCore(int iIndex, BOOL bDelOnCancel, LPCTSTR p = NULL)

Creates the edit control for editing

virtual void  MoveUpCore(int iIndex)

Moves an item in the list box up one position.

virtual BOOL  DeleteItem(int nItem)

Deletes an item in the listbox.

virtual void  SetSpacesToTab(int nSpaces = 1)

Sets the number of spaces to treat as a tab for "quick mode".

virtual void  OnBrowse()

Called when the browse button is clicked.

Implementation

int  GetChangedLine() const

Returns the index of an item before it changed.

int  GetNewLine() const

Returns the index of an item after it moved.

int  GetSpacesToTab() const

Gets the number of spaces to be treated as a tab for "quick mode".

Protected data members.

CButton  m_btnBrowse

Browse button (if used).

CToolTipCtrl  m_ToolTip

Tooltip control.

SECListBoxEdit*  m_pEdit

Pointer to editing control.

SECListBoxEditorHelper*  m_pHelper

Pointer to helper object.

CRect  m_rcButtons[NUM_BUTTONS]

Button rectangles

BOOL  m_bUseButton[NUM_BUTTONS]

Button existance boolean flags

int  m_iFlags

Flags controlling operation.

BOOL  m_bInitialized

Initialization flag.

int  m_calcdHeight

Calculated height.

BOOL  m_bAddInProgress

TRUE if a new item is being created.

CString  m_strRenameOldName

Item text before rename occurred.

BOOL  m_bEscape

TRUE if handling escape key

int  mnChangedLine

The index of an item before it is moved.

int  mnNewLine

The index of an item after it is moved.

BOOL  mbQuick

"Quick mode" flag.

int  mnSpaces

Number of spaces treated as a tab (quick mode).