Custom NSViews not highlighting

  • I have a custom NSView subclass in side of a scroll view. This
    subclass contains a bunch of NSViews which act as buttons with in. I
    want to be able to select an area of these buttons and have them all
    highlight (to show they are selected) I have no trouble getting the
    selection to draw, and according to my NSLog tracking the view's
    within the selection rectangle are being recognized correctly. The
    problem is I cannot get any form of a rectangle to appear around the
    edges of the button. Now originally the subviews acting as buttons
    had the following code:

    [self lockFocus];
      [[NSColor yellowColor]set];
      NSFrameRect([self bounds]);
    [self unlockFocus];

    this code would not highlight the button during mousedrag, nor when
    called after the mouse up. However if I called it from within the
    subview it would highlight correctly so this leads me to assume the
    code should have worked..

    Now still having no success, I added the following code to the master
    view. (the subclass that contains the buttons.)

    NSEnumerator * iter = [[self subviews]objectEnumerator];
    NSMutableArray * subviews = [[NSMutableArray alloc]init];
    id item = NULL;
    while(item = [iter nextObject]){
      NSRect intersection = NSIntersectionRect([selectionMarker
    selectedRect],[item bounds]);
      NSRect selection = [selectionMarker selectedRect];
      BOOL inside = NSContainsRect([selectionMarker selectedRect],[item
      if(inside || !NSIsEmptyRect(intersection)){
      [item lockFocus];
        [[NSColor yellowColor]set];
        NSFrameRect([item bounds]);
      [item unlockFocus];
      [subviews addObject:item];
      [item lockFocus];
        [[NSColor yellowColor]set];
        NSFrameRect([item bounds]);
      [item unlockFocus];
      [[NSRunLoop currentRunLoop] runUntilDate:[NSDate
    [self setNeedsDisplay:YES];
    return subviews;

    I can use NSLog to track that infact the 'buttons' are being
    correctly detected, and asked to highlight however no highlight ever
    appears. (I know a yellow box is ugly. I'll use the proper highlight
    in the end but before I worry about it I'd like to at least get it
    Now the button items all have the first responder methods and
    drawRect overriden, I don't know if this is causing the problem. If
    so, do I need to add a contingency for when the button has been

  • --- Development <development...> wrote:

    > -(void)highlight
    > {
    > [self lockFocus];
    > [[NSColor yellowColor]set];
    > NSFrameRect([self bounds]);
    > [self unlockFocus];
    > }

    Drawing in NSViews is supposed to be done from
    drawRect:. Move the drawing code into there and simply
    mark the view as needing display when it needs to be


    Check out the hottest 2008 models today at Yahoo! Autos.
previous month october 2007 next month
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31        
Go to today