The Mouse and Cursor

You can do two basic things with a mouse: move it and click its button.[3]

Four different mouse events (actions) can be derived from these basic actions:

Clicking (single-clicking)

Pressing and releasing a mouse button (mouse down and mouse up) without changing the position of the mouse.

Clicking (or single-clicking) is used to select an object or location on the screen. For example, you can click a button or menu command to select some action, click an icon or filename in a list to select it for further action, click in a window to bring it in front of other windows, or click on a piece of text to select an insertion point.

Multiple-clicking

Pressing and releasing a mouse button two or three times in rapid succession without changing the position of the mouse.

Multiple-clicking extends the action of clicking. For example, you can click on a piece of text to select an insertion point, double-click to extend the action to select the nearest word, and triple-click to select the entire line or paragraph. Likewise, you can click a file icon in the Finder to select a file and double-click the icon to open the file in its associated application.

Dragging

Pressing and holding down a mouse button and then moving the mouse (and thus the cursor); release the mouse button to end.

Dragging is used primarily to move an object or define a range. For example, you can drag a window’s title bar to move the window, drag a file icon to reposition it in a Finder window, or drag the knob on a slider or scroller to select a value or scroll through a window. You can also use dragging to define a range of characters in a text area, or to select a group of graphics in a drawing area or icons in a file area. The last two operations use a technique known as rubberbanding , where a lightly drawn rectangle indicates the selection range.

Pressing

Pressing and holding down a mouse button in place; release the mouse button to end.

Pressing is used mainly as a substitute for repeated single-clicks. For example, you can repeatedly click a scroll button to move through the contents of a document window, or you can simply press the scroll button and let the window scroll.

The terminology we’ll use in this book is that one chooses menu commands, clicks or presses on buttons or icons, selects items in a list, drags icons across the desktop, and drags across items in a list (e.g., files in a Finder window).

Mouse Action Paradigms

It’s not crucial for users to know Aqua’s mouse action paradigm terminology, because most Aqua actions are fairly intuitive. However, Cocoa developers should understand these mouse action paradigms (patterns, archetypes) and the associated terminology. You need to be aware of the paradigms so that you don’t disrupt their naturalness for users of your applications. You also need to understand the terminology in order to properly use the procedures that come with Cocoa and to understand Apple’s documentation. Following are the four Aqua mouse action paradigms, and some examples of each:

Direct manipulation

A user drags a window’s title or resize bar to move or resize the window, clicks in a partially obscured window to move the window to the front, or drags a file’s icon to the Trash icon to delete it. The user directly manipulates these objects.

Target selection

A user drags across a sequence of characters to select them for a change in font, or drags a rectangle around several graphics objects to select them for copying. These objects have been selected for some targeted action.

Targeted action through controls

A user clicks a button to change a text font, drags a slider knob to change the size of an object, or clicks a menu command to make a panel appear. We’ll discuss control objects in depth later in this chapter.

Modal tool selection

A user clicks a pencil or rectangle icon in a palette of tools in a graphics editor to select a drawing tool, and the cursor changes to indicate the mode of drawing. The word “modal” implies that the application has distinct modes. When an application is in a modal state, some (or most) of its commands may be unavailable, or subsequent mouse actions may be specific to that mode.

Fortunately for developers, most responses to direct manipulation and target selection by the mouse are handled automatically by Cocoa objects and by Quartz. For example, a developer doesn’t have to do anything to make a button highlight or a window move in response to user actions; Cocoa button objects automatically highlight when clicked and Quartz handles all window movements directed by users. On the other hand, an action in response to a change in a control object (e.g., a button click, slider drag, or menu command) or a cursor change in response to a modal tool selection is usually handled explicitly by the developer.

Cursors

The Cocoa cursor is a graphics image 16 pixels square that moves with the mouse. (A pixel is the smallest addressable point on the computer’s bitmapped display.) Moving the mouse quickly moves the cursor farther than moving it slowly — even if the distance moved is the same. Picking up the mouse and placing it elsewhere does not change the position of the cursor.

The cursor can take many different shapes, depending on the context. Its shape can change in response to entering or exiting a window or graphics area and in response to tool or target selection. The most common cursors are shown in the following list. The hot spot , or the exact location (point) of the screen referred to by the cursor, depends on the type of cursor currently displayed.

Cursors Arrow

For selecting, clicking, etc.; the hot spot is at the tip of the arrow. This is the most common cursor.

Cursors Arrow with plus sign

Indicates that a copying operation is about to take place in the Finder or another application. The hot spot doesn’t matter, because this cursor appears only when the user is dragging another object.

Cursors Arrow with link

Indicates that a link (reference) operation is about to take place in the Finder or another application. As with the arrow-with-plus-sign cursor, the hot spot doesn’t matter.

Cursors I-beam

For text input positioning, editing, etc.; the hot spot is at the center.

Cursors Spinning disk

This "wait” cursor indicates that an application is performing an operation that must be completed before you can continue your work in that application; however, you may activate another application by clicking in one of its open windows or its icon in the Dock, and you won’t have to wait to use the new application. This is a huge user benefit provided by Unix. The hot spot is at the center.

Cursors Pencil

For drawing lines in a graphics editor or other such program; the hot spot is at the tip. Other, similar drawing cursors include the paintbrush, paint pot, etc.

Cursors Crosshair

For drawing shapes such as rectangles or circles in a graphics editor; the hot spot is at the center.



[3] Mac OS X also supports a two-button mouse with a scroll wheel. Under normal circumstances, the left button is used for selection and the right button brings up a context menu. If you have a mouse with a scroll wheel, moving the wheel will cause the view underneath the mouse to scroll. In the interest of brevity, this section considers only the standard Apple one-button mouse. Chapter 8 discusses mouse events in more detail.

Get Building Cocoa Applications: A Step by Step Guide now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.