Important: The information in this document is obsolete and should not be used for new development.
Handling Events for Your Color Picker
The Color Picker Manager sends thekDrawPicker
request in response to an update event. Your color picker responds to this code by redrawing your color picker, as illustrated in Listing 2-20.Listing 2-20 Redrawing a color picker
pascal ComponentResult MyDrawPicker(PickerStorageHndl storage) { if((*storage)->visible) { MyDrawColorList(storage); MyDrawColorEditor(storage,true); } return noErr; }The Color Picker Manager calls the Event Manager functionBeginUpdate
before sending thekDrawPicker
request code and the Event Manager functionEndUpdate
after sending thekDrawPicker
request code.The Color Picker Manager sends the
kEvent
request code so that your color picker can handle events that the Dialog Manager does not handle. A color picker responds to thekEvent
request code by performing any event processing in addition to or instead of that normally performed by the Dialog Manager. Listing 2-21 illustrates how a color picker can perform such event processing.Listing 2-21 Responding to events before handing them to the Dialog Manager
pascal ComponentResult MyDoEvent(PickerStorageHndl storage, EventData *data) { OSErr err = noErr; /* initialize so events are not filtered */ data->handled = false; data->action = kDidNothing; if(data->event) { switch(data->event->what) { case nullEvent: DoIdle(storage,data); break; case mouseDown: err = DoMouseDown(storage,data); break; case keyDown: case autoKey: err = DoKeyDown(storage,data); break; case keyUp: err = DoKeyUp(storage,data); break; case activateEvt: if(data->event->modifiers & activeFlag) ActivatePicker(storage); else DeactivatePicker(storage); break; } } return err; }The Color Picker Manager sends thekItemHit
request code to inform your color picker of an event in one of its items. In turn, your color picker responds to the event for the item reported in theitemHit
field of anItemHitData
record, which is described in "Color Picker Manager Reference" (page 2-5) in Advanced Color Imaging Reference. Listing 2-22 illustrates how a color picker can perform such event processing.Listing 2-22 Responding to events in color picker items
pascal ComponentResult MyItemHit(PickerStorageHndl storage, ItemHitData *data) { #pragma unused(iMod) Handle theItem; short iType; Rect iBox; OSErr err = noErr; data->action = kDidNothing; GetDialogItem((*storage)->port, (*storage)->baseItem + data->itemHit, &iType, &theItem, &iBox); switch(data->itemHit) { case iRedText: case iGreenText: case iBlueText: /* don't udpate everything as the user types each key; update only after the user leaves an edit field */ if(data->iMod != kKeyDown && data->itemHit != kMouseDown) CheckCurrentWorld(storage,data->itemHit); break; case iOrigColor: err = DoListClick(storage,data); break; case iNewColor: break; } return err; }The Color Picker Manager sends thekEdit
request code to inform your color picker that the user has chosen one of the edit commands from the Edit menu (or typed its keyboard equivalent). If your color picker, rather than the Dialog Manager, needs to perform the editing command, your color picker should do so in response to this request code. For example, because the Dialog Manager does not perform the Undo command, yourMyDoEdit
function can instead. The editing command is passed to your function in the fieldtheEdit
of theEditData
record pointed to in thedata
parameter. Listing 2-23 illustrates how a color picker can respond to this result code.Listing 2-23 Handling events in the color picker's Edit menu
pascal ComponentResult MyDoEdit(PickerStorageHndl storage, EditData *data) { RGBColor rgb; switch(data->theEdit) { default: /* default behavior is appropriate */ data->action = kDidNothing; data->handled = false; break; case kUndo: rgb = (*storage)->lastRGB; (*storage)->lastRGB = (*storage)->color.color.rgb; (*storage)->color.color.rgb = rgb; /* update the other internal data and then redraw */ MySetSelectionColor(storage); MyUpdateColorText(storage); MyDrawColorRects(storage, false); data->action = kColorChanged; data->handled = true; break; } return noErr; }