src/video/cocoa/SDL_cocoawindow.h
author Sam Lantinga <slouken@libsdl.org>
Fri, 13 Sep 2013 17:42:31 -0700
changeset 7740 415bb39617a1
parent 7595 ede2237fcebf
child 7952 5ac1a895b313
permissions -rw-r--r--
Mac: Translate Ctrl-Left click to right click.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     1
/*
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5466
diff changeset
     2
  Simple DirectMedia Layer
6885
700f1b25f77f Happy New Year!
Sam Lantinga <slouken@libsdl.org>
parents: 6788
diff changeset
     3
  Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     4
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5466
diff changeset
     5
  This software is provided 'as-is', without any express or implied
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5466
diff changeset
     6
  warranty.  In no event will the authors be held liable for any damages
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5466
diff changeset
     7
  arising from the use of this software.
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     8
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5466
diff changeset
     9
  Permission is granted to anyone to use this software for any purpose,
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5466
diff changeset
    10
  including commercial applications, and to alter it and redistribute it
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5466
diff changeset
    11
  freely, subject to the following restrictions:
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    12
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5466
diff changeset
    13
  1. The origin of this software must not be misrepresented; you must not
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5466
diff changeset
    14
     claim that you wrote the original software. If you use this software
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5466
diff changeset
    15
     in a product, an acknowledgment in the product documentation would be
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5466
diff changeset
    16
     appreciated but is not required.
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5466
diff changeset
    17
  2. Altered source versions must be plainly marked as such, and must not be
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5466
diff changeset
    18
     misrepresented as being the original software.
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5466
diff changeset
    19
  3. This notice may not be removed or altered from any source distribution.
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    20
*/
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    21
#include "SDL_config.h"
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    22
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    23
#ifndef _SDL_cocoawindow_h
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    24
#define _SDL_cocoawindow_h
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    25
3400
4ec48602f1db iPhone interruption patch / SDL 1.3
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
    26
#import <Cocoa/Cocoa.h>
4ec48602f1db iPhone interruption patch / SDL 1.3
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
    27
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    28
typedef struct SDL_WindowData SDL_WindowData;
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    29
5374
dacb4f5e0dd3 We still want the delegate functionality for windowShouldClose()
Sam Lantinga <slouken@libsdl.org>
parents: 5371
diff changeset
    30
@interface Cocoa_WindowListener : NSResponder <NSWindowDelegate> {
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    31
    SDL_WindowData *_data;
7090
c4ac8be0065b Forgot to add this file to Mac crash fix.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6885
diff changeset
    32
    BOOL observingVisible;
7740
415bb39617a1 Mac: Translate Ctrl-Left click to right click.
Sam Lantinga <slouken@libsdl.org>
parents: 7595
diff changeset
    33
    BOOL wasCtrlLeft;
7090
c4ac8be0065b Forgot to add this file to Mac crash fix.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6885
diff changeset
    34
    BOOL wasVisible;
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    35
}
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    36
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    37
-(void) listen:(SDL_WindowData *) data;
7090
c4ac8be0065b Forgot to add this file to Mac crash fix.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6885
diff changeset
    38
-(void) pauseVisibleObservation;
c4ac8be0065b Forgot to add this file to Mac crash fix.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6885
diff changeset
    39
-(void) resumeVisibleObservation;
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    40
-(void) close;
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    41
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    42
/* Window delegate functionality */
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    43
-(BOOL) windowShouldClose:(id) sender;
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    44
-(void) windowDidExpose:(NSNotification *) aNotification;
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    45
-(void) windowDidMove:(NSNotification *) aNotification;
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    46
-(void) windowDidResize:(NSNotification *) aNotification;
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    47
-(void) windowDidMiniaturize:(NSNotification *) aNotification;
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    48
-(void) windowDidDeminiaturize:(NSNotification *) aNotification;
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    49
-(void) windowDidBecomeKey:(NSNotification *) aNotification;
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    50
-(void) windowDidResignKey:(NSNotification *) aNotification;
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    51
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    52
/* Window event handling */
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    53
-(void) mouseDown:(NSEvent *) theEvent;
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    54
-(void) rightMouseDown:(NSEvent *) theEvent;
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    55
-(void) otherMouseDown:(NSEvent *) theEvent;
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    56
-(void) mouseUp:(NSEvent *) theEvent;
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    57
-(void) rightMouseUp:(NSEvent *) theEvent;
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    58
-(void) otherMouseUp:(NSEvent *) theEvent;
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    59
-(void) mouseMoved:(NSEvent *) theEvent;
1957
c7803e4c21d3 Implemented Cocoa mouse wheel events
Sam Lantinga <slouken@libsdl.org>
parents: 1956
diff changeset
    60
-(void) mouseDragged:(NSEvent *) theEvent;
1958
5fc6fb0fb605 Added right/other drag code for Cocoa windows
Sam Lantinga <slouken@libsdl.org>
parents: 1957
diff changeset
    61
-(void) rightMouseDragged:(NSEvent *) theEvent;
5fc6fb0fb605 Added right/other drag code for Cocoa windows
Sam Lantinga <slouken@libsdl.org>
parents: 1957
diff changeset
    62
-(void) otherMouseDragged:(NSEvent *) theEvent;
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    63
-(void) scrollWheel:(NSEvent *) theEvent;
4673
c17ac64abb70 Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
    64
-(void) touchesBeganWithEvent:(NSEvent *) theEvent;
c17ac64abb70 Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
    65
-(void) touchesMovedWithEvent:(NSEvent *) theEvent;
c17ac64abb70 Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
    66
-(void) touchesEndedWithEvent:(NSEvent *) theEvent;
c17ac64abb70 Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
    67
-(void) touchesCancelledWithEvent:(NSEvent *) theEvent;
c17ac64abb70 Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
    68
c17ac64abb70 Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
    69
/* Touch event handling */
c17ac64abb70 Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
    70
typedef enum {
c17ac64abb70 Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
    71
    COCOA_TOUCH_DOWN,
c17ac64abb70 Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
    72
    COCOA_TOUCH_UP,
c17ac64abb70 Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
    73
    COCOA_TOUCH_MOVE,
c17ac64abb70 Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
    74
    COCOA_TOUCH_CANCELLED
c17ac64abb70 Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
    75
} cocoaTouchType;
c17ac64abb70 Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
    76
-(void) handleTouches:(cocoaTouchType)type withEvent:(NSEvent*) event;
c17ac64abb70 Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
    77
1936
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 1933
diff changeset
    78
@end
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 1933
diff changeset
    79
/* *INDENT-ON* */
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 1933
diff changeset
    80
7594
6abcf951af68 Mac: Don't -[NSOpenGLContext update] on (potentially) the wrong thread.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7507
diff changeset
    81
@class SDLOpenGLContext;
6abcf951af68 Mac: Don't -[NSOpenGLContext update] on (potentially) the wrong thread.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7507
diff changeset
    82
1936
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 1933
diff changeset
    83
struct SDL_WindowData
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    84
{
3685
64ce267332c6 Switched from SDL_WindowID and SDL_TextureID to SDL_Window* and SDL_Texture* for code simplicity and improved performance.
Sam Lantinga <slouken@libsdl.org>
parents: 3506
diff changeset
    85
    SDL_Window *window;
64ce267332c6 Switched from SDL_WindowID and SDL_TextureID to SDL_Window* and SDL_Texture* for code simplicity and improved performance.
Sam Lantinga <slouken@libsdl.org>
parents: 3506
diff changeset
    86
    NSWindow *nswindow;
7595
ede2237fcebf Mac: Support for multiple contexts per SDL_Window.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7594
diff changeset
    87
    NSMutableArray *nscontexts;
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents: 1936
diff changeset
    88
    SDL_bool created;
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    89
    Cocoa_WindowListener *listener;
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    90
    struct SDL_VideoData *videodata;
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    91
};
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    92
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    93
extern int Cocoa_CreateWindow(_THIS, SDL_Window * window);
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    94
extern int Cocoa_CreateWindowFrom(_THIS, SDL_Window * window,
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    95
                                  const void *data);
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    96
extern void Cocoa_SetWindowTitle(_THIS, SDL_Window * window);
5375
16877f74123c Implemented Cocoa_SetWindowIcon(), added SDL_ConvertSurfaceFormat()
Sam Lantinga <slouken@libsdl.org>
parents: 5374
diff changeset
    97
extern void Cocoa_SetWindowIcon(_THIS, SDL_Window * window, SDL_Surface * icon);
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    98
extern void Cocoa_SetWindowPosition(_THIS, SDL_Window * window);
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    99
extern void Cocoa_SetWindowSize(_THIS, SDL_Window * window);
6681
5a0396a933b5 SetMinimumWindowSize for OS X
stopiccot
parents: 6666
diff changeset
   100
extern void Cocoa_SetWindowMinimumSize(_THIS, SDL_Window * window);
6788
036f53f2f5aa Added SDL_SetWindowMaximumSize() and SDL_GetWindowMaximumSize()
Sam Lantinga <slouken@libsdl.org>
parents: 6681
diff changeset
   101
extern void Cocoa_SetWindowMaximumSize(_THIS, SDL_Window * window);
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   102
extern void Cocoa_ShowWindow(_THIS, SDL_Window * window);
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   103
extern void Cocoa_HideWindow(_THIS, SDL_Window * window);
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   104
extern void Cocoa_RaiseWindow(_THIS, SDL_Window * window);
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   105
extern void Cocoa_MaximizeWindow(_THIS, SDL_Window * window);
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   106
extern void Cocoa_MinimizeWindow(_THIS, SDL_Window * window);
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   107
extern void Cocoa_RestoreWindow(_THIS, SDL_Window * window);
6422
fd0ac1b56115 Added SDL_SetWindowBordered() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 6138
diff changeset
   108
extern void Cocoa_SetWindowBordered(_THIS, SDL_Window * window, SDL_bool bordered);
5305
75f5ff92ad08 Fixed a host of issues with Windows fullscreen modes. Toggling fullscreen OpenGL works now in my test environment.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   109
extern void Cocoa_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * display, SDL_bool fullscreen);
5466
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5404
diff changeset
   110
extern int Cocoa_SetWindowGammaRamp(_THIS, SDL_Window * window, const Uint16 * ramp);
006883d5fa51 Gamma support is back!
Sam Lantinga <slouken@libsdl.org>
parents: 5404
diff changeset
   111
extern int Cocoa_GetWindowGammaRamp(_THIS, SDL_Window * window, Uint16 * ramp);
6662
698c2e533a7e SDL no longer grabs the keyboard by default on X11.
Sam Lantinga <slouken@libsdl.org>
parents: 6422
diff changeset
   112
extern void Cocoa_SetWindowGrab(_THIS, SDL_Window * window, SDL_bool grabbed);
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   113
extern void Cocoa_DestroyWindow(_THIS, SDL_Window * window);
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   114
extern SDL_bool Cocoa_GetWindowWMInfo(_THIS, SDL_Window * window,
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   115
                                      struct SDL_SysWMinfo *info);
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   116
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   117
#endif /* _SDL_cocoawindow_h */
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   118
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   119
/* vi: set ts=4 sw=4 expandtab: */