Matrix Selection Modes

Since users frequently press the mouse button while the cursor is within the NSMatrix and then drag the mouse around, NSMatrix offers several methods that determine how it tracks the mouse. setMode: lets you choose among four “selection modes” that broadly determine how the matrix tracks the mouse. The setAllowsEmptySelection: and setSelectionByRect: methods let you refine how those modes work.

The setMode: method lets you choose one of these four modes:

setAllowsEmptySelection: has an effect only if the selection mode is NSRadioModeMatrix. It lets you choose whether, in a group of radio buttons, it’s allowed for none of them to be on. For example, say the user clicks on the one radio button in a matrix that’s on. If allowsEmptySelection is YES, that button turns off and none of the radio buttons is on. If allowsEmptySelection is NO, the button remains on, and the only way to turn it off is to click another button.

setSelectionByRect: sets whether the user can select a range of cells by dragging the mouse. If isSelectionByRect is NO, dragging over a range selects only the last cell only. If isSelectionByRect is YES, dragging over a range selects all the cells the user drags over.