• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Restricting NSWindow Movement
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Restricting NSWindow Movement


  • Subject: Re: Restricting NSWindow Movement
  • From: Rick Mann <email@hidden>
  • Date: Mon, 06 May 2013 14:41:34 -0700

Hi Tom,

I've been dealing with constraining window motion a bit lately. Unfortunately, Cocoa does not provide an easy way to do this (like Carbon did). You essentially have to handle the mouse events yourself, in an NSWindow subclass.

So, subclass NSWindow, and implement the following (I included some of the code I used):

- (void)
mouseDown: (NSEvent*) inEvent
{
    CGRect b = self.frame;
    b = [self convertRectFromScreen: b];
    CGPoint p = inEvent.locationInWindow;

    mDragOffset.x = b.origin.x - p.x;
    mDragOffset.y = b.origin.y - p.y;
}

- (void)
mouseDragged: (NSEvent*) inEvent;
{
    CGRect b = self.frame;
    b = [self convertRectFromScreen: b];

    CGPoint p = inEvent.locationInWindow;
    b.origin.x = p.x + mDragOffset.x;
    b.origin.y = p.y + mDragOffset.y;

    b = [self convertRectToScreen: b];
    [self setFrame: b display: true];

}

- (void)
mouseUp: (NSEvent*) inEvent;
{
    //  Nothing really needs be done here
}



On May 6, 2013, at 14:17 , Thomas Wetmore <email@hidden> wrote:

> Is there a way to restrict the movement of an NSWindow to a frame of another window (that may underly it) or to some other fixed rectangular sub-area on the screen?
>
> Searching the web there was a CocoaBuilder thread 12 years ago that indicates that it was unknown how to do this then, implying that optimization in the Window Manager was an issue, but holding out the possibility that a layer below Cocoa might allow it.
>
> The windowWillMove: delegate method does not allow vetoing the move. In contrast to the windowWillResize:toSize: delegate method that does allow resizing to be vetoed.
>
> If your answer to this question would be to ask me why I should want to do such a thing, please consider that that is not an answer.
>
> Thanks,
>
> Tom Wetmore
> _______________________________________________
>
> Cocoa-dev mailing list (email@hidden)
>
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>
> Help/Unsubscribe/Update your Subscription:
>
> This email sent to email@hidden


--
Rick




_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >Restricting NSWindow Movement (From: Thomas Wetmore <email@hidden>)

  • Prev by Date: Re: Restricting NSWindow Movement
  • Next by Date: Re: Restricting NSWindow Movement
  • Previous by thread: Re: Restricting NSWindow Movement
  • Next by thread: Re: Restricting NSWindow Movement
  • Index(es):
    • Date
    • Thread