Hi,

I've been playing around for an hour with blinking cursor/caret support
in NSTextView.

Here's my patch for NSTextView.h and for NSTextView.m.

I've done some testing and it works very well. _flipCursorColor should be
a little bit optimized and I'll do it if the patch is OK.

Thanks a lot!

Ludo

-- 
Live as if you were to die tomorrow.
Learn as if you were to live forever.
 - Gandhi
126a127,128
> 
>   NSTimer *_cursor_timer;
439a442,445
> 
> // Blinking cursor support
> - (void) _flipCursorColor;
> 
201a202,221
> - (void) _flipCursorColor
> {
>   NSRect aRect;
> 
>   if ( [_caret_color isEqual: [NSColor blackColor]] )
>     {
>       ASSIGN(_caret_color, [NSColor whiteColor]); 
>     }
>   else
>     {
>       ASSIGN(_caret_color, [NSColor blackColor]); 
>     }
>   
>   // To optimize
>   aRect = [self rectForCharacterRange: NSMakeRange(0, [[self string] length])];
>   
>   [self setNeedsDisplayInRect: aRect
>       avoidAdditionalLayout: YES];
> }
> 
235a256,264
>   // We start our timer for our blinking cursor
>   _cursor_timer = [NSTimer scheduledTimerWithTimeInterval: 0.5
>                          target: self
>                          selector: @selector(_flipCursorColor)
>                          userInfo: nil
>                          repeats: YES];
>   RETAIN(_cursor_timer);
>   
> 
297a327,334
>   
>   /* We stop our timer */
>   if (_cursor_timer)
>     {
>       [_cursor_timer invalidate];
>       RELEASE(_cursor_timer);
>     }
>   
382a420,427
>   /* If we have a range length > 0, we must stop the timer */
>   if (_selected_range.length > 0 && _cursor_timer != nil)
>     {
>       [_cursor_timer invalidate];
>       RELEASE(_cursor_timer);
>       _cursor_timer = nil;
>     }
>   
1557c1602,1612
<       /* TODO: Restart blinking timer */
---
>       /* If we had a timer running, which whould not be the case, we don't
>        * restart it. */
>       if (_cursor_timer == nil)
>       {
>         _cursor_timer = [NSTimer scheduledTimerWithTimeInterval: 0.5
>                                  target: self
>                                  selector: @selector(_flipCursorColor)
>                                  userInfo: nil
>                                  repeats: YES];
>         RETAIN(_cursor_timer);
>       }
2476c2531,2538
<       //<!> stop timed entry
---
>       
>       /* We stop our timer */
>       if (_cursor_timer)
>       {
>         [_cursor_timer invalidate];
>         RELEASE(_cursor_timer);
>         _cursor_timer = nil;
>       }
2516a2579,2589
>   /* We restart our timer if it's stopped */
>   if (_cursor_timer == nil)
>     {
>       _cursor_timer = [NSTimer scheduledTimerWithTimeInterval: 0.5
>                              target: self
>                              selector: @selector(_flipCursorColor)
>                              userInfo: nil
>                              repeats: YES];
>       RETAIN(_cursor_timer);
>     }
> 
2531c2604,2610
<   //<!> stop timed entry
---
>   
>   if (_cursor_timer)
>     {
>       [_cursor_timer invalidate];
>       RELEASE(_cursor_timer);
>       _cursor_timer = nil;
>     }

Reply via email to