Post

Replies

Boosts

Views

Activity

Reply to Unexpected Pointer Changes
Based on a Stack Overflow question, - https://stackoverflow.com/questions/12079531/cant-change-the-mouse-cursor-of-a-nstextfield I've managed to get it to work by doing this: objective-c (void)mouseEntered:(NSEvent *)event {     self.mouseInRect = YES; } (void)mouseExited:(NSEvent *)event {     self.mouseInRect = NO; } (void)mouseMoved:(NSEvent *)event {     [super mouseMoved:event];     if (self.mouseInRect) {         [[NSCursor arrowCursor] set];     } }
Topic: UI Frameworks SubTopic: AppKit Tags:
May ’21
Reply to Unexpected Pointer Changes
Initially, I was relying on the automatic change. Then I added code to update the cursor. I get the same results either way. I am subclassing NSRulerView here. A plain old NSRulerView exhibits the same behavior though. Here's what I have... First, setup tracking area: objective-c (void)setFrame:(NSRect)frame {      NSLog(@"setFrame");     [super setFrame:frame];     NSArrayNSTrackingArea * *oldAreas = self.trackingAreas;     NSLog(@"frame = %f, %f, %f, %f", self.frame.origin.x, self.frame.origin.y, self.frame.size.width, self.frame.size.height);     if (oldAreas.count 0) {         NSLog(@"removing %li tracking areas", oldAreas.count);         for (NSTrackingArea *ta in oldAreas) {             [self removeTrackingArea:ta];         }     }     self.mouseTrackingArea = [[NSTrackingArea alloc] initWithRect:self.frame                                                           options:(NSTrackingMouseEnteredAndExited | NSTrackingMouseMoved | NSTrackingActiveInKeyWindow | NSTrackingCursorUpdate)                                                             owner:self                                                          userInfo:nil];     [self addTrackingArea:self.mouseTrackingArea]; } Handle mouse events: objective-c (void)mouseEntered:(NSEvent *)event {     NSLog(@"mouse entered");     [[NSCursor arrowCursor] set]; } (void)cursorUpdate:(NSEvent *)event {     NSLog(@"cursorUpdate");     [[NSCursor arrowCursor] set]; } Interestingly, the text "mouse entered" displays as soon as I move the mouse pointer into the targeted area, but the cursor change doesn't have any effect. Only when I enter the area from the right side, do I get the "cursorUpdate" message and that cursor change DOES take effect.
Topic: UI Frameworks SubTopic: AppKit Tags:
May ’21
Reply to Managing External Subviews and Layout
Yes, I could add child views to the NSSplitView which is already in the MainWindowController nib. In fact, I did that to start with and that eliminates the autolayout issue. With that implementation, I setup the autolayout in IB, just as you suggested, then instantiated A and B and added them as children to the views that already existed. And it works fine, of course. The reason I chose to not do it that way is to remove those extra unused views for efficiency. This is (getting to be) a rather complex app and I wanted to avoid having extra views lying around that don't really do anything. All that aside, I think my initial assumption was incorrect. The problem I thought I was going to run into is essentially this: SplitView is loaded from its nib and MainWindowController.viewDidLoad gets called. In viewDidLoad, I do a = [[A alloc] initWithNibName:]; b = [[B alloc] initWithNibName:]; I thought that when [[alloc] initWithNibName] returned, it was not guaranteed that those nibs would be loaded yet and so the views in them wouldn't be guaranteed to exist yet. If that were true, there would be no A.view or B.view to add to the SplitView or do autolayout with. Last night, I went ahead and implemented it anyway assuming that the nib would be loaded and the view would exist after the return of [alloc] initWithNibName:] and it works fine. I think I incorrectly inferred A.view and B.view wouldn't be guaranteed to exist yet, because of the existence of viewDidLoad. Or, was my initial assumption correct and I'm just getting lucky that A.view and B.view happen to exist immediately up return from [alloc] initWithNibName:]?
Topic: UI Frameworks SubTopic: AppKit Tags:
May ’21