mouseDown Event / locationInWindows always returning (0,0)

  • Hi,

    I've a strange problem  under 10.5,

    I subclassed a NSView and declared in it :

    - (void)mouseDown:(NSEvent *)theEvent
    {         NSPoint p;

    p = [theEvent locationInWindow];
    }

    Under the debugger, the event is trapped and the function gets called,
    theEvent shows a correct mouseDownEvent type (1),
    the protected '_location' NSEvent member contains the right mouse
    coord, window is not nil, everything is OK
    BUT locationInWindow always return (0,0)
    I browsed the mailing list before posting and tried to make the same
    thing in a window subclassing, same result

    Has somebody a clue before I loose all my hairs? I'd appreciate a lot

    Regards
    Luc B
  • On Jan 8, 2008, at 3:53 PM, luc BARREDA wrote:

    > Hi,
    >
    > I've a strange problem  under 10.5,
    >
    > I subclassed a NSView and declared in it :
    >
    > - (void)mouseDown:(NSEvent *)theEvent
    > {         NSPoint p;
    >
    > p = [theEvent locationInWindow];
    > }
    >
    > Under the debugger, the event is trapped and the function gets
    > called, theEvent shows a correct mouseDownEvent type (1),
    > the protected '_location' NSEvent member contains the right mouse
    > coord, window is not nil, everything is OK
    > BUT locationInWindow always return (0,0)
    > I browsed the mailing list before posting and tried to make the same
    > thing in a window subclassing, same result
    >
    > Has somebody a clue before I loose all my hairs? I'd appreciate a lot

    How do you _know_ that it returning (0,0)?

    If you are just looking in the debugger at the value of "p", the
    compiler is free to see this and say "hey, they are setting a
    variable, and that variable is never used again, I can just plain not
    generate the code to set the variable and drop the return value and it
    won't change the result of the code, and it will save a few
    instructions and cache hits".

    Add an explicit

    NSLog(@"Point was %@", NSStringFromPoint(p));

    and see what value is printed out...

    Glenn Andreas                      <gandreas...>
      <http://www.gandreas.com/> wicked fun!
    quadrium | prime : build, mutate, evolve, animate : the next
    generation of fractal art
  • glenn andreas wrote:
    >
    > On Jan 8, 2008, at 3:53 PM, luc BARREDA wrote:
    >
    >> Hi,
    >>
    >> I've a strange problem  under 10.5,
    >>
    >> I subclassed a NSView and declared in it :
    >>
    >> - (void)mouseDown:(NSEvent *)theEvent
    >> {        NSPoint p;
    >>
    >> p = [theEvent locationInWindow];
    >> }
    >>
    >> Under the debugger, the event is trapped and the function gets
    >> called, theEvent shows a correct mouseDownEvent type (1),
    >> the protected '_location' NSEvent member contains the right mouse
    >> coord, window is not nil, everything is OK
    >> BUT locationInWindow always return (0,0)
    >> I browsed the mailing list before posting and tried to make the same
    >> thing in a window subclassing, same result
    >>
    >> Has somebody a clue before I loose all my hairs? I'd appreciate a lot
    >
    >
    > How do you _know_ that it returning (0,0)?
    >
    > If you are just looking in the debugger at the value of "p", the
    > compiler is free to see this and say "hey, they are setting a
    > variable, and that variable is never used again, I can just plain not
    > generate the code to set the variable and drop the return value and it
    > won't change the result of the code, and it will save a few
    > instructions and cache hits".
    Maybe when optimization is enabled, but in -O0 the compiler should not
    do this; I'd file a bug if it did. I'd hope that the OP is not debugging
    a release build.

    > Add an explicit
    >
    > NSLog(@"Point was %@", NSStringFromPoint(p));
    >
    > and see what value is printed out...
    >
    >
    > Glenn Andreas                      <gandreas...>
    > <http://www.gandreas.com/> wicked fun!
    > quadrium | prime : build, mutate, evolve, animate : the next
    > generation of fractal art
previous month january 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