By Andrew Stone of Stone Design
April 1990
Recently, I had the task of including a graphic view in a window with other tools and controls in it. Since I want- ed the cursor to change to the cursor appropriate for this view, a cross hair, I had to install my own cursor rect to let the window server know to change the cursor to a cross when entering the drawing view. Had this been a scrollView or a clipView, it is a simple one line task:

[scrollView setDocCursor:crossCursor];

This is very useful if you are using the scrolling text view from IB, and want it to be read only: you might want to set the cursor to an arrow to show it is not edit- able.[Downside: users can’t conveniently grab the text for copying.]

[scrollView setDocCursor:NXArrow];

But my challenge was for a non-scrollable, what you see is all you get, view. The window will maintain a list of the cursor rects in it, and you could call the [window resetCursorRects] method to reset the cursor in your view. However, this is horribly inefficient and according to the 1.0p docs, “To be optimized...” It turned out to be quite simple, and most elegantly terse:

First, override the resetCursorRects method in your custom view. This is called for each subview in the win- dow when the application sends the window a resetCur- sorRects message. Upon receiving this message, we respond with the visible portion of our view and the de- sired cursor:
- resetCursorRects
{

    return [self addCursorRect:&bounds cursor:[currentGraphic
cursor]];
}
And, then alert the window when things have changed. In the case of a subClass of GraphicView, when we change tools on the tool palette:
- setCurrentGraphic:sender
{

    [super setCurrentGraphic:sender];
    [window invalidateCursorRectsForView:self];
    return self;
}

The beauty of the NeXTStep Environment is that after spending hours debugging some bizarre postscript anom- aly and getting tremendously concerned for the future of our providers of black equipment, you tackle a task in six lines and six minutes what you feared would take several hundreds of each.





Stone Design's Create(tm)
2005-06-29 23:40:57 -0500