Make NSWindow with transparent title partially unchecked

I have a NSWindow

split screen like in Reminders. So I am using this code:

self.window.titlebarAppearsTransparent = true
self.window.styleMask |= NSFullSizeContentViewWindowMask

      

This works great. But inside the window I have a SplitView (like in the reminders app) and NSOutlineView

on the right side. The OutlineView goes up in the corner of the window.

Now the problem is this: clicking and dragging at the top of the OutlineView makes the window move. Is there anyway I can turn this off, but keeping the driving ability on the left side of the app?

+3


source to share


1 answer


Ok, you need to do two things:

First you need to configure so that your window is not movable. To do this, subclass your window and override isMovable

and return no. Or you call setMovable:

and don't ask it.

After that, you need to manually drag and drop by adding a view with the exact size and position of the area you want to drag. Alternatively, you can customize NSTrackingArea

. In any case, you need to override mouseDown:

and paste the code to move the window.

My words in code:



Objective-C

[self.window setMovable:false];

// OR (in NSWindow subclass)

- (BOOL)isMovable {
    return false;
}

//Mouse Down
- (void)mouseDown:(NSEvent *)theEvent {
    _initialLocation = [theEvent locationInWindow];

    NSPoint point;
    while (1) {
        theEvent = [[self window] nextEventMatchingMask: (NSLeftMouseDraggedMask | NSLeftMouseUpMask)];
        point =[theEvent locationInWindow];

        NSRect screenVisibleFrame = [[NSScreen mainScreen] visibleFrame];
        NSRect windowFrame = [self.window frame];
        NSPoint newOrigin = windowFrame.origin;

        // Get the mouse location in window coordinates.
        NSPoint currentLocation = point;
        // Update the origin with the difference between the new mouse location and the old mouse location.
        newOrigin.x += (currentLocation.x - _initialLocation.x);
        newOrigin.y += (currentLocation.y - _initialLocation.y);

        // Don't let window get dragged up under the menu bar
        if ((newOrigin.y + windowFrame.size.height) > (screenVisibleFrame.origin.y + screenVisibleFrame.size.height)) {
            newOrigin.y = screenVisibleFrame.origin.y + (screenVisibleFrame.size.height - windowFrame.size.height);
    }

    // Move the window to the new location
    [self.window setFrameOrigin:newOrigin];
    if ([theEvent type] == NSLeftMouseUp)
        break;
    }
}

      

initialLocation

is a property NSPoint

Note. I was looking for some things here and here

+1


source







All Articles