Conditional mouseDownCanMoveWindow for NSView?

  • I have a single nsview that draws the main content area for my application
    and a bottom statusbar. This was done instead of using two different views
    so the user can move objects from the statusbar to the main content area,
    all with core animation effects. The view is not opaque. The problem I'm
    having, though, is that I want the user to be able to drag the window when
    the mouse is down on the statusbar, but not the main content area. In other
    words, if the mousedown is within the statusbar's rectangle I want to return
    YES for mouseDownCanMoveWindow. But if the mousedown is within the main
    content area rectangle, I want to return NO. I have already tried setting a
    flag in the mouseDown method and then returning that
    in mouseDownCanMoveWindow. But it doesn't work. I guess mouseDown is not
    called before mouseDownCanMoveWindow. Anyway, does anyone have any other
    suggestions for this?
    The only other thing I can think to do is setting a flag on mouseEnter and
    mouseExit of the statusbar rectangle, but that doesn't seem particularly
    elegant.

    Thanks,
    Dan
  • At 12:03 -0700 02/10/08, <cocoa-dev-request...> wrote:
    > From: "Daniel Weber" <dan.j.weber...>
    > Date: Thu, 2 Oct 2008 11:15:40 -0700
    > Message-ID: <8fd681110810021115hf4f68d8gaef42738845ca219...>
    >
    > I have a single nsview that draws the main content area for my application
    > and a bottom statusbar. This was done instead of using two different views
    > so the user can move objects from the statusbar to the main content area,
    > all with core animation effects. The view is not opaque. The problem I'm
    > having, though, is that I want the user to be able to drag the window when
    > the mouse is down on the statusbar, but not the main content area. In other
    > words, if the mousedown is within the statusbar's rectangle I want to return
    > YES for mouseDownCanMoveWindow. But if the mousedown is within the main
    > content area rectangle, I want to return NO. I have already tried setting a
    > flag in the mouseDown method and then returning that
    > in mouseDownCanMoveWindow. But it doesn't work. I guess mouseDown is not
    > called before mouseDownCanMoveWindow. Anyway, does anyone have any other
    > suggestions for this?

    I had that very same problem in RBSplitView. The only solution I found is to always return NO in mouseDownCanMoveWindow, then move the window "manually" inside mouseDown like this:

    - (void)mouseDown:(NSEvent*)theEvent {
    NSWindow* window = [self window];
    NSPoint where = [theEvent locationInWindow];
    if (...test for your rect here...) {
      where =  [window convertBaseToScreen:where];
      NSPoint origin = [window frame].origin;
    // Now we loop handling mouse events until we get a mouse up event.
      while ((theEvent = [NSApp nextEventMatchingMask:NSLeftMouseDownMask|NSLeftMouseDraggedMask|NSLeftMouseUpMask untilDate:[NSDate distantFuture] inMode:NSEventTrackingRunLoopMode dequeue:YES])&&([theEvent type]!=NSLeftMouseUp)) {
    // Set up a local autorelease pool for the loop to prevent buildup of temporary objects.
      NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
      NSPoint now = [window convertBaseToScreen:[theEvent locationInWindow]];
      origin.x += now.x-where.x;
      origin.y += now.y-where.y;
    // Move the window by the mouse displacement since the last event.
      [window setFrameOrigin:origin];
      where = now;
      [pool release];
      }
    }
    }

    --
    Rainer Brockerhoff  <rainer...>
    Belo Horizonte, Brazil
    "In the affairs of others even fools are wise
    In their own business even sages err."
    Weblog: http://www.brockerhoff.net/bb/viewtopic.php
  • Am Do,02.10.2008 um 20:15 schrieb Daniel Weber:

    > I have a single nsview that draws the main content area for my
    > application
    > and a bottom statusbar. This was done instead of using two different
    > views
    > so the user can move objects from the statusbar to the main content
    > area,
    > all with core animation effects. The view is not opaque. The problem
    > I'm
    > having, though, is that I want the user to be able to drag the
    > window when
    > the mouse is down on the statusbar, but not the main content area.
    > In other
    > words, if the mousedown is within the statusbar's rectangle I want
    > to return
    > YES for mouseDownCanMoveWindow. But if the mousedown is within the
    > main
    > content area rectangle, I want to return NO. I have already tried
    > setting a
    > flag in the mouseDown method and then returning that
    > in mouseDownCanMoveWindow. But it doesn't work. I guess mouseDown is
    > not
    > called before mouseDownCanMoveWindow. Anyway, does anyone have any
    > other
    > suggestions for this?
    > The only other thing I can think to do is setting a flag on
    > mouseEnter and
    > mouseExit of the statusbar rectangle, but that doesn't seem
    > particularly
    > elegant.
    >
    > Thanks,

    Maybe – I've never tried it, so it is just an idea – you can retrieve
    the mouse location in -mouseDownCanMoveWindow by using -currentEvent
    (NSApplication) and -locationInWindow (NSEvent).

    Cheers

    >
    > Dan

    Amin Negm-Awad
    <negm-awad...>
previous month october 2008 next month
MTWTFSS
    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