macWindow.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #ifndef _TORQUE_MACWINDOW_H_
  23. #define _TORQUE_MACWINDOW_H_
  24. #include "windowManager/platformWindow.h"
  25. #include "windowManager/mac/macWindowManager.h"
  26. #include "windowManager/mac/macCursorController.h"
  27. #ifndef _GFXTARGET_H_
  28. #include "gfx/gfxTarget.h"
  29. #endif
  30. #ifndef _GFXSTRUCTS_H_
  31. #include "gfx/gfxStructs.h"
  32. #endif
  33. class MacWindow : public PlatformWindow
  34. {
  35. public:
  36. virtual ~MacWindow();
  37. virtual GFXDevice *getGFXDevice() { return mDevice; }
  38. virtual GFXWindowTarget *getGFXTarget() { return mTarget; }
  39. virtual void _setVideoMode(const GFXVideoMode &mode);
  40. virtual const GFXVideoMode &getVideoMode() { return mCurrentMode; }
  41. virtual WindowId getWindowId() { return mWindowId; }
  42. void setDisplay(CGDirectDisplayID display);
  43. CGDirectDisplayID getDisplay() { return mDisplay; }
  44. CGRect getMainDisplayBounds() { return mMainDisplayBounds; }
  45. CGRect getDisplayBounds() { return mDisplayBounds; }
  46. virtual bool clearFullscreen()
  47. {
  48. // TODO: properly drop out of full screen
  49. return true;
  50. }
  51. virtual bool isFullscreen() { return mFullscreen; }
  52. virtual PlatformWindow * getNextWindow() const;
  53. virtual void setMouseLocked( bool enable )
  54. {
  55. mShouldMouseLock = enable;
  56. if(isFocused())
  57. _doMouseLockNow();
  58. }
  59. virtual bool isMouseLocked() const { return mMouseLocked; }
  60. virtual bool shouldLockMouse() const { return mShouldMouseLock; }
  61. virtual bool setSize(const Point2I &newSize);
  62. virtual void setClientExtent( const Point2I newExtent );
  63. virtual const Point2I getClientExtent();
  64. virtual void setBounds( const RectI &newBounds );
  65. virtual const RectI getBounds() const;
  66. virtual void setPosition( const Point2I newPosition );
  67. virtual const Point2I getPosition();
  68. virtual void centerWindow();
  69. virtual Point2I clientToScreen( const Point2I& pos );
  70. virtual Point2I screenToClient( const Point2I& pos );
  71. virtual bool setCaption(const char *windowText);
  72. virtual const char *getCaption() { return mTitle; }
  73. virtual bool setType( S32 windowType ) { return true; }
  74. virtual void minimize();
  75. virtual void maximize();
  76. virtual void restore();
  77. virtual bool isMinimized();
  78. virtual bool isMaximized();
  79. virtual void show();
  80. virtual void close();
  81. virtual void hide();
  82. virtual bool isOpen();
  83. virtual bool isVisible();
  84. virtual bool isFocused();
  85. virtual void setFocus();
  86. virtual void clearFocus();
  87. virtual void* getPlatformDrawable() const;
  88. // TODO: These should be private, but GGMacView (an Obj-C class) needs access to these and we can't friend Obj-C classes
  89. bool _skipNextMouseEvent() { return mSkipMouseEvents != 0; }
  90. void _skipAnotherMouseEvent() { mSkipMouseEvents++; }
  91. void _skippedMouseEvent() { mSkipMouseEvents--; }
  92. /// Does the work of actually locking or unlocking the mouse, based on the
  93. /// value of shouldLockMouse().
  94. ///
  95. /// Disassociates the cursor movement from the mouse input and hides the mouse
  96. /// when locking. Re-associates cursor movement with mouse input and shows the
  97. /// mouse when unlocking.
  98. ///
  99. /// Returns true if we locked or unlocked the mouse. Returns false if the mouse
  100. /// was already in the correct state.
  101. void _doMouseLockNow();
  102. // Helper methods for doMouseLockNow
  103. void _associateMouse();
  104. void _dissociateMouse();
  105. void _centerMouse();
  106. // For GGMacView
  107. void _disassociateCocoaWindow();
  108. // Safari support methods
  109. static void setSafariWindow(NSWindow *window, S32 x = 0, S32 y = 0, S32 width = 0, S32 height = 0);
  110. static void hideBrowserWindow(bool hide);
  111. protected:
  112. virtual void _setFullscreen(bool fullScreen);
  113. private:
  114. friend class MacWindowManager;
  115. friend class MacCursorController;
  116. struct SafariWindowInfo
  117. {
  118. NSWindow* safariWindow; /* The Safari Browser Window */
  119. S32 x; /* Position of top left corner relative */
  120. S32 y; /* to a safari page. */
  121. U32 width; /* Maximum window size */
  122. U32 height;
  123. };
  124. MacWindow(U32 windowId, const char* windowText, Point2I clientExtent);
  125. void _initCocoaWindow(const char* windowText, Point2I clientExtent);
  126. void setWindowId(U32 newid) { mWindowId = newid;}
  127. void signalGainFocus();
  128. static SafariWindowInfo* sSafariWindowInfo;
  129. static MacWindow* sInstance;
  130. NSWindow* mCocoaWindow;
  131. GFXDevice *mDevice;
  132. GFXWindowTargetRef mTarget;
  133. GFXVideoMode mCurrentMode;
  134. MacWindow *mNextWindow;
  135. bool mMouseLocked;
  136. bool mShouldMouseLock;
  137. const char* mTitle;
  138. bool mMouseCaptured;
  139. MacWindowManager* mOwningWindowManager;
  140. U32 mSkipMouseEvents;
  141. bool mFullscreen;
  142. bool mShouldFullscreen;
  143. NSDictionary* mDefaultDisplayMode;
  144. void _onAppEvent(WindowId,S32);
  145. CGDirectDisplayID mDisplay;
  146. CGRect mDisplayBounds;
  147. CGRect mMainDisplayBounds;
  148. };
  149. #endif