CGWindow.h
  1  /* Copyright (c) 2006-2007 Christopher J. W. Lloyd
  2  
  3  Permission is hereby granted, free of charge, to any person obtaining a copy of
  4  this software and associated documentation files (the "Software"), to deal in
  5  the Software without restriction, including without limitation the rights to
  6  use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
  7  the Software, and to permit persons to whom the Software is furnished to do so,
  8  subject to the following conditions:
  9  
 10  The above copyright notice and this permission notice shall be included in all
 11  copies or substantial portions of the Software.
 12  
 13  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 14  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
 15  FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
 16  COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
 17  IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 18  CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
 19  
 20  #include <CoreFoundation/CoreFoundation.h>
 21  #import <CoreGraphics/CGSubWindow.h>
 22  #import <CoreGraphics/CGWindowLevel.h>
 23  #import <CoreGraphics/CGImage.h>
 24  #ifdef __OBJC__
 25  #import <Foundation/Foundation.h>
 26  #endif
 27  #import <OpenGL/CGLTypes.h>
 28  
 29  extern const CFStringRef kCGWindowAlpha;
 30  extern const CFStringRef kCGWindowBounds;
 31  extern const CFStringRef kCGWindowLayer;
 32  extern const CFStringRef kCGWindowName;
 33  extern const CFStringRef kCGWindowOwnerName;
 34  extern const CFStringRef kCGWindowOwnerPID;
 35  
 36  #ifdef __OBJC__
 37  @class CGEvent;
 38  #endif
 39  
 40  typedef enum {
 41      CGSBackingStoreRetained = 0,
 42      CGSBackingStoreNonretained = 1,
 43      CGSBackingStoreBuffered = 2
 44  } CGSBackingStoreType;
 45  
 46  typedef CF_OPTIONS(uint32_t, CGWindowListOption) {
 47      kCGWindowListOptionAll                 = 0,
 48      kCGWindowListOptionOnScreenOnly        = (1 << 0),
 49      kCGWindowListOptionOnScreenAboveWindow = (1 << 1),
 50      kCGWindowListOptionOnScreenBelowWindow = (1 << 2),
 51      kCGWindowListOptionIncludingWindow     = (1 << 3),
 52      kCGWindowListExcludeDesktopElements    = (1 << 4),
 53  };
 54  
 55  typedef CF_OPTIONS(uint32_t, CGWindowImageOption) {
 56      kCGWindowImageDefault             = 0,
 57      kCGWindowImageBoundsIgnoreFraming = (1 << 0),
 58      kCGWindowImageShouldBeOpaque      = (1 << 1),
 59      kCGWindowImageOnlyShadows         = (1 << 2),
 60      kCGWindowImageBestResolution      = (1 << 3),
 61      kCGWindowImageNominalResolution   = (1 << 4),
 62  };
 63  
 64  typedef uint32_t CGWindowID;
 65  
 66  #ifdef __OBJC__
 67  @interface CGWindow : NSObject
 68  
 69  - (void) setDelegate: delegate;
 70  - delegate;
 71  
 72  - (void) invalidate;
 73  - (void) syncDelegateProperties;
 74  
 75  // Goes in private interface
 76  //- (O2Context *)cgContext;
 77  - (CGLContextObj) cglContext;
 78  
 79  - (NSUInteger) styleMask;
 80  
 81  - (void) setLevel: (int) value;
 82  - (void) setStyleMask: (NSUInteger) mask;
 83  - (void) setTitle: (NSString *) title;
 84  - (void) setFrame: (CGRect) frame;
 85  - (void) setOpaque: (BOOL) value;
 86  - (void) setAlphaValue: (CGFloat) value;
 87  - (void) setHasShadow: (BOOL) value;
 88  
 89  - (void) sheetOrderFrontFromFrame: (NSRect) frame
 90                        aboveWindow: (CGWindow *) aboveWindow;
 91  - (void) sheetOrderOutToFrame: (NSRect) frame;
 92  
 93  - (void) showWindowForAppActivation: (NSRect) frame;
 94  - (void) hideWindowForAppDeactivation: (NSRect) frame;
 95  
 96  - (void) hideWindow;
 97  - (void) showWindowWithoutActivation;
 98  
 99  + windowWithWindowNumber: (NSInteger) windowNumber;
100  
101  - (NSInteger) windowNumber;
102  
103  - (void) placeAboveWindow: (NSInteger) otherNumber;
104  - (void) placeBelowWindow: (NSInteger) otherNumber;
105  
106  - (void) makeKey;
107  - (void) makeMain;
108  - (void) captureEvents;
109  - (void) miniaturize;
110  - (void) deminiaturize;
111  - (BOOL) isMiniaturized;
112  
113  - (void) disableFlushWindow;
114  - (void) enableFlushWindow;
115  - (void) flushBuffer;
116  
117  - (NSPoint) mouseLocationOutsideOfEventStream;
118  
119  - (void) sendEvent: (CGEvent *) event;
120  
121  - (void) addEntriesToDeviceDictionary: (NSDictionary *) entries;
122  - (void) flashWindow;
123  
124  - (void) addCGLContext: (CGLContextObj) cglContext;
125  - (void) removeCGLContext: (CGLContextObj) cglContext;
126  
127  - (void) flushCGLContext: (CGLContextObj) cglContext;
128  
129  - (CGSubWindow *) createSubWindowWithFrame: (CGRect) frame;
130  
131  @end
132  
133  @interface NSObject (CGWindow_delegate)
134  
135  - (void) platformWindow: (CGWindow *) window
136             frameChanged: (NSRect) frame
137                  didSize: (BOOL) didSize;
138  - (NSSize) platformWindow: (CGWindow *) window
139          frameSizeWillChange: (NSSize) size;
140  - (void) platformWindowWillBeginSizing: (CGWindow *) window;
141  - (void) platformWindowDidEndSizing: (CGWindow *) window;
142  - (void) platformWindowExitMove: (CGWindow *) window;
143  
144  - (void) platformWindow: (CGWindow *) window needsDisplayInRect: (NSRect) rect;
145  - (void) platformWindowStyleChanged: (CGWindow *) window;
146  - (void) platformWindowWillClose: (CGWindow *) window;
147  
148  - (void) platformWindowWillMove: (CGWindow *) window;
149  - (void) platformWindowDidMove: (CGWindow *) window;
150  
151  - (void) platformWindowDeminiaturized: (CGWindow *) window;
152  - (void) platformWindowMiniaturized: (CGWindow *) window;
153  - (void) platformWindowActivated: (CGWindow *) window
154                   displayIfNeeded: (BOOL) displayIfNeeded;
155  - (void) platformWindowDeactivated: (CGWindow *) window
156             checkForAppDeactivation: (BOOL) checkForApp;
157  
158  - (void) platformWindowExposed: (CGWindow *) window inRect: (NSRect) rect;
159  
160  - (BOOL) platformWindowIgnoreModalMessages: (CGWindow *) window;
161  
162  - (BOOL) platformWindowSetCursorEvent: (CGWindow *) window;
163  
164  - (void) platformWindowDidInvalidateCGContext: (CGWindow *) window;
165  
166  - (void) platformWindowShouldZoom: (CGWindow *) window;
167  
168  @end
169  #endif
170  
171  CF_IMPLICIT_BRIDGING_ENABLED
172  
173  COREGRAPHICS_EXPORT CFArrayRef CGWindowListCreate(CGWindowListOption option, CGWindowID relativeToWindow);
174  COREGRAPHICS_EXPORT CFArrayRef CGWindowListCreateDescriptionFromArray(CFArrayRef windowArray);
175  COREGRAPHICS_EXPORT CGImageRef CGWindowListCreateImageFromArray(CGRect screenBounds, CFArrayRef  windowArray, CGWindowImageOption imageOption);
176  
177  COREGRAPHICS_EXPORT CFArrayRef CGWindowListCreate(CGWindowListOption option, CGWindowID relativeToWindow);
178  COREGRAPHICS_EXPORT CGImageRef CGWindowListCreateImage(CGRect screenBounds,
179                                                         CGWindowListOption listOption,
180                                                         CGWindowID windowID,
181                                                         CGWindowImageOption imageOption);
182  
183  CF_IMPLICIT_BRIDGING_DISABLED