from pyglet.libs.darwin.cocoapy import *

class PygletWindow_Implementation(object):
    PygletWindow = ObjCSubclass('NSWindow', 'PygletWindow')

    @PygletWindow.method('B')
    def canBecomeKeyWindow(self):
        return True

    # When the window is being resized, it enters into a mini event loop that
    # only looks at mouseDragged and mouseUp events, blocking everything else.
    # Among other things, this makes it impossible to run an NSTimer to call the
    # idle() function in order to update the view during the resize.  So we
    # override this method, called by the resizing event loop, and call the
    # idle() function from here.  This *almost* works.  I can't figure out what
    # is happening at the very beginning of a resize event.  The NSView's
    # viewWillStartLiveResize method is called and then nothing happens until
    # the mouse is dragged.  I think NSApplication's nextEventMatchingMask_etc
    # method is being called instead of this one.  I don't really feel like
    # subclassing NSApplication just to fix this.  Also, to prevent white flashes
    # while resizing, we must also call idle() from the view's reshape method.
    @PygletWindow.method('@'+NSUIntegerEncoding+'@@c')
    def nextEventMatchingMask_untilDate_inMode_dequeue_(self, mask, date, mode, dequeue):
        if self.inLiveResize():
            # Call the idle() method while we're stuck in a live resize event.
            from pyglet import app
            if app.event_loop is not None:
                app.event_loop.idle()
         
        send_super(self, 'nextEventMatchingMask:untilDate:inMode:dequeue:', 
                   mask, date, mode, dequeue, argtypes=[NSUInteger, c_void_p, c_void_p, c_bool])

    # Need this for set_size to not flash.
    @PygletWindow.method('d'+NSRectEncoding)
    def animationResizeTime_(self, newFrame):
        return 0.0


class PygletToolWindow_Implementation(object):
    PygletToolWindow = ObjCSubclass('NSPanel', 'PygletToolWindow')

    @PygletToolWindow.method('@'+NSUIntegerEncoding+'@@c')
    def nextEventMatchingMask_untilDate_inMode_dequeue_(self, mask, date, mode, dequeue):
        if self.inLiveResize():
            # Call the idle() method while we're stuck in a live resize event.
            from pyglet import app
            if app.event_loop is not None:
                app.event_loop.idle()
                
        send_super(self, 'nextEventMatchingMask:untilDate:inMode:dequeue:', 
                   mask, date, mode, dequeue, argtypes=[NSUInteger, c_void_p, c_void_p, c_bool])

    # Need this for set_size to not flash.
    @PygletToolWindow.method('d'+NSRectEncoding)
    def animationResizeTime_(self, newFrame):
        return 0.0

PygletWindow = ObjCClass('PygletWindow')
PygletToolWindow = ObjCClass('PygletToolWindow')

@@ -1205,33 +1205,33 @@
 egerEncoding+'@@
-c
+B
 ')%0A    def nextE
@@ -1543,32 +1543,40 @@
         %0A       
+ event =
  send_super(self
@@ -1640,32 +1640,40 @@
                 
+       
+ 
 mask, date, mode
@@ -1727,32 +1727,132 @@
 id_p, c_bool%5D)%0A%0A
+        if event.value == None:%0A            return 0%0A        else:%0A            return event.value%0A%0A%0A
     # Need this 
@@ -2160,17 +2160,17 @@
 ding+'@@
-c
+B
 ')%0A    d
@@ -2505,16 +2505,24 @@
 %0A       
+ event =
  send_su
@@ -2594,32 +2594,40 @@
                 
+       
+ 
 mask, date, mode
@@ -2685,24 +2685,123 @@
 , c_bool%5D)%0A%0A
+        if event.value == None:%0A            return 0%0A        else:%0A            return event.value%0A%0A
     # Need t

fix type error problems and missing return value during window resizing