MyWindow.mm 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /******************************************************************************/
  2. #include "stdafx.h"
  3. #include "MyWindow.h"
  4. #include "MyApplication.h"
  5. /******************************************************************************/
  6. namespace EE
  7. {
  8. Bool PreventResizing;
  9. }
  10. /******************************************************************************/
  11. // WINDOW DELEGATE
  12. /******************************************************************************/
  13. @interface MyWindowDelegate : NSObject<NSWindowDelegate>
  14. {
  15. }
  16. @end
  17. @implementation MyWindowDelegate
  18. -(NSSize)windowWillResize:(NSWindow*)window toSize:(NSSize)newSize
  19. {
  20. if(!FlagTest(App.flag, APP_RESIZABLE) && [[NSApp currentEvent] type]==NSLeftMouseDragged)PreventResizing=true; // in case the app OS Window has resizable controls, but we don't want to support them, then we need to prevent resizing until dragging has finished
  21. return PreventResizing ? [window frame].size : newSize;
  22. }
  23. -(BOOL)windowShouldClose:(id)sender
  24. {
  25. if(!(App.flag&APP_NO_CLOSE))App.close();
  26. return NO;
  27. }
  28. -(void)windowDidMiniaturize :(NSNotification*)notification {App._minimized=true ; SetActive();}
  29. -(void)windowDidDeminiaturize:(NSNotification*)notification {App._minimized=false; SetActive();}
  30. @end
  31. /******************************************************************************/
  32. // WINDOW
  33. /******************************************************************************/
  34. @implementation MyWindow
  35. -(void)dealloc
  36. {
  37. [self.delegate release]; self.delegate=null;
  38. [super dealloc];
  39. }
  40. -(id)initWithContentRect:(NSRect)contentRect
  41. styleMask:(NSUInteger)windowStyle
  42. backing:(NSBackingStoreType)bufferingType
  43. defer:(BOOL)deferCreation
  44. {
  45. // FlagSet(windowStyle, (UInt)NSResizableWindowMask, FlagTest(App.flag, APP_RESIZABLE|APP_MAXIMIZABLE)); don't use because App is not set yet
  46. self=[super initWithContentRect:contentRect styleMask:windowStyle backing:bufferingType defer:deferCreation];
  47. self.collectionBehavior|=NSWindowCollectionBehaviorFullScreenNone; // this will set window maximize button to maximize instead of entering fullscreen
  48. MyWindowDelegate *window_delegate=[[MyWindowDelegate alloc] init]; [self setDelegate:window_delegate]; //[window_delegate release]; we can't release the delegate here, because it will stop working, instead we need to release it in 'dealloc'
  49. return self;
  50. }
  51. @end
  52. /******************************************************************************/