author | Claus Gittinger <cg@exept.de> |
Tue, 28 Feb 2017 13:45:47 +0100 | |
changeset 21594 | acb127ad113c |
parent 21591 | c89611bc4b5c |
child 21595 | 10b14f01369b |
permissions | -rw-r--r-- |
21452 | 1 |
" |
2 |
COPYRIGHT (c) 2013 by Claus Gittinger |
|
21455 | 3 |
All Rights Reserved |
21452 | 4 |
|
5 |
This software is furnished under a license and may be used |
|
6 |
only in accordance with the terms of that license and with the |
|
7 |
inclusion of the above copyright notice. This software may not |
|
8 |
be provided or otherwise made available to, or used by, any |
|
9 |
other person. No title to or ownership of the software is |
|
10 |
hereby transferred. |
|
11 |
" |
|
17471 | 12 |
"{ Package: 'stx:libbasic' }" |
13 |
||
14 |
"{ NameSpace: Smalltalk }" |
|
14819 | 15 |
|
17471 | 16 |
UnixOperatingSystem subclass:#OSXOperatingSystem |
17 |
instanceVariableNames:'' |
|
21587
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
18 |
classVariableNames:'NSApp' |
17471 | 19 |
poolDictionaries:'' |
20 |
category:'OS-Unix' |
|
21 |
! |
|
22 |
||
21452 | 23 |
!OSXOperatingSystem primitiveDefinitions! |
24 |
%{ |
|
25 |
||
21587
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
26 |
#undef NO_COCOA |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
27 |
|
21452 | 28 |
#ifndef __OSX__ |
29 |
# define NO_QUARTZ |
|
30 |
# define NO_COCOA |
|
31 |
#endif |
|
32 |
||
33 |
#ifndef NO_COCOA |
|
34 |
||
35 |
# undef Array |
|
36 |
# undef Number |
|
37 |
# undef Method |
|
38 |
# undef Point |
|
39 |
# undef Rectangle |
|
40 |
# undef Block |
|
41 |
# undef String |
|
42 |
# undef Character |
|
43 |
# undef Message |
|
44 |
# undef Object |
|
45 |
# undef Context |
|
46 |
# undef Time |
|
47 |
# undef Date |
|
48 |
# undef Set |
|
49 |
# undef Signal |
|
50 |
# undef Delay |
|
51 |
# undef NameSpace |
|
52 |
# undef Process |
|
53 |
# undef Processor |
|
54 |
# undef Class |
|
55 |
# undef FixedPoint |
|
56 |
# undef true |
|
57 |
# undef false |
|
58 |
||
59 |
# undef INT |
|
60 |
# undef UINT |
|
61 |
||
62 |
#include <ApplicationServices/ApplicationServices.h> |
|
63 |
#include <CoreFoundation/CoreFoundation.h> |
|
64 |
// #include <Foundation/Foundation.h> |
|
21587
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
65 |
#include <CoreGraphics/CGEventTypes.h> |
21452 | 66 |
|
67 |
#include <stdlib.h> |
|
68 |
#include <stdio.h> |
|
69 |
#include <IOKit/graphics/IOGraphicsLib.h> |
|
70 |
||
71 |
#include <objc/runtime.h> |
|
72 |
#include <objc/message.h> |
|
73 |
||
74 |
# ifdef __DEF_Array |
|
75 |
# define Array __DEF_Array |
|
76 |
# endif |
|
77 |
# ifdef __DEF_Number |
|
78 |
# define Number __DEF_Number |
|
79 |
# endif |
|
80 |
# ifdef __DEF_Method |
|
81 |
# define Method __DEF_Method |
|
82 |
# endif |
|
83 |
# ifdef __DEF_Point |
|
84 |
# define Point __DEF_Point |
|
85 |
# endif |
|
86 |
# ifdef __DEF_Rectangle |
|
87 |
# define Rectangle __DEF_Rectangle |
|
88 |
# endif |
|
89 |
# ifdef __DEF_Block |
|
90 |
# define Block __DEF_Block |
|
91 |
# endif |
|
92 |
# ifdef __DEF_String |
|
93 |
# define String __DEF_String |
|
94 |
# endif |
|
95 |
# ifdef __DEF_Character |
|
96 |
# define Character __DEF_Character |
|
97 |
# endif |
|
98 |
# ifdef __DEF_Message |
|
99 |
# define Message __DEF_Message |
|
100 |
# endif |
|
101 |
# ifdef __DEF_Object |
|
102 |
# define Object __DEF_Object |
|
103 |
# endif |
|
104 |
# ifdef __DEF_Context |
|
105 |
# define Context __DEF_Context |
|
106 |
# endif |
|
107 |
# ifdef __DEF_Date |
|
108 |
# define Date __DEF_Date |
|
109 |
# endif |
|
110 |
# ifdef __DEF_Time |
|
111 |
# define Time __DEF_Time |
|
112 |
# endif |
|
113 |
# ifdef __DEF_Set |
|
114 |
# define Set __DEF_Set |
|
115 |
# endif |
|
116 |
# ifdef __DEF_Signal |
|
117 |
# define Signal __DEF_Signal |
|
118 |
# endif |
|
119 |
# ifdef __DEF_Delay |
|
120 |
# define Delay __DEF_Delay |
|
121 |
# endif |
|
122 |
# ifdef __DEF_NameSpace |
|
123 |
# define NameSpace __DEF_NameSpace |
|
124 |
# endif |
|
125 |
# ifdef __DEF_Process |
|
126 |
# define Process __DEF_Process |
|
127 |
# endif |
|
128 |
# ifdef __DEF_Processor |
|
129 |
# define Processor __DEF_Processor |
|
130 |
# endif |
|
131 |
# ifdef __DEF_Class |
|
21587
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
132 |
# define STX_Class __DEF_Class |
21452 | 133 |
# endif |
134 |
# ifdef __DEF_FixedPoint |
|
135 |
# define FixedPoint __DEF_FixedPoint |
|
136 |
# endif |
|
137 |
# ifdef __DEF_true |
|
138 |
# undef true |
|
139 |
# define true __DEF_true |
|
140 |
# endif |
|
141 |
# ifdef __DEF_false |
|
142 |
# undef false |
|
143 |
# define false __DEF_false |
|
144 |
# endif |
|
145 |
||
146 |
# define INT STX_INT |
|
147 |
# define UINT STX_UINT |
|
148 |
||
21587
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
149 |
typedef struct CMPoint { |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
150 |
double x; |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
151 |
double y; |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
152 |
} CMPoint; |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
153 |
|
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
154 |
typedef struct CMSize { |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
155 |
double width; |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
156 |
double height; |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
157 |
} CMSize; |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
158 |
|
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
159 |
typedef struct CMRect { |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
160 |
CMPoint origin; |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
161 |
CMSize size; |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
162 |
} CMRect; |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
163 |
|
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
164 |
typedef struct AppDel { |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
165 |
Class isa; |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
166 |
|
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
167 |
// Will be an NSWindow later. |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
168 |
id window; |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
169 |
} AppDelegate; |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
170 |
|
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
171 |
|
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
172 |
enum { |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
173 |
NSBorderlessWindowMask = 0, |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
174 |
NSTitledWindowMask = 1 << 0, |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
175 |
NSClosableWindowMask = 1 << 1, |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
176 |
NSMiniaturizableWindowMask = 1 << 2, |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
177 |
NSResizableWindowMask = 1 << 3, |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
178 |
}; |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
179 |
|
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
180 |
typedef id(*CMacsSimpleMessage)(id, SEL); |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
181 |
typedef void(*CMacsVoidMessage)(id, SEL); |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
182 |
typedef void(*CMacsVoidMessage1)(id, SEL, void *); |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
183 |
typedef id(*CMacsRectMessage1)(id, SEL, CMRect); |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
184 |
typedef id(*CMacsWindowInitMessage)(id, SEL, CMRect, int, int, bool); |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
185 |
|
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
186 |
extern CMacsSimpleMessage cmacs_simple_msgSend; |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
187 |
extern CMacsVoidMessage cmacs_void_msgSend; |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
188 |
extern CMacsVoidMessage1 cmacs_void_msgSend1; |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
189 |
extern CMacsRectMessage1 cmacs_rect_msgSend1; |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
190 |
extern CMacsWindowInitMessage cmacs_window_init_msgSend; |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
191 |
|
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
192 |
#endif // NO_COCOA |
21452 | 193 |
|
194 |
%} |
|
195 |
! ! |
|
196 |
||
197 |
!OSXOperatingSystem primitiveFunctions! |
|
198 |
%{ |
|
199 |
||
200 |
#ifndef NO_COCOA |
|
201 |
||
202 |
CGEventRef |
|
203 |
myCGEventCallback(CGEventTapProxy proxy, CGEventType type, |
|
204 |
CGEventRef event, void *refcon) |
|
205 |
{ |
|
206 |
// Paranoid sanity check. |
|
207 |
if ((type != kCGEventKeyDown) && (type != kCGEventKeyUp)) |
|
208 |
return event; |
|
209 |
||
210 |
// The incoming keycode. |
|
211 |
CGKeyCode keycode = (CGKeyCode)CGEventGetIntegerValueField(event, kCGKeyboardEventKeycode); |
|
212 |
||
213 |
//Keypress code goes here. |
|
214 |
||
215 |
// We must return the event for it to be useful. |
|
216 |
return event; |
|
217 |
} |
|
218 |
||
21587
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
219 |
BOOL |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
220 |
AppDel_didFinishLaunching(AppDelegate *self, SEL _cmd, id notification) { |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
221 |
// self->window = cmacs_simple_msgSend((id)objc_getClass("NSWindow"), sel_getUid("alloc")); |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
222 |
// |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
223 |
// /// Create an instance of the window. |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
224 |
// self->window = cmacs_window_init_msgSend(self->window, sel_getUid("initWithContentRect:styleMask:backing:defer:"), (CMRect){0,0,1024,460}, (NSTitledWindowMask | NSClosableWindowMask | NSResizableWindowMask | NSMiniaturizableWindowMask), 0, false); |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
225 |
// |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
226 |
// /// Create an instance of our view class. |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
227 |
// /// |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
228 |
// /// Relies on the view having declared a constructor that allocates a class pair for it. |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
229 |
// id view = cmacs_rect_msgSend1(cmacs_simple_msgSend((id)objc_getClass("View"), sel_getUid("alloc")), sel_getUid("initWithFrame:"), (CMRect){ 0, 0, 320, 480 }); |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
230 |
// |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
231 |
// // here we simply add the view to the window. |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
232 |
// cmacs_void_msgSend1(self->window, sel_getUid("setContentView:"), view); |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
233 |
// cmacs_simple_msgSend(self->window, sel_getUid("becomeFirstResponder")); |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
234 |
// |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
235 |
// // Shows our window in the bottom-left hand corner of the screen. |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
236 |
// cmacs_void_msgSend1(self->window, sel_getUid("makeKeyAndOrderFront:"), self); |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
237 |
return YES; |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
238 |
} |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
239 |
|
21452 | 240 |
#endif // NO_COCOA |
241 |
||
242 |
%} |
|
243 |
! ! |
|
244 |
||
245 |
!OSXOperatingSystem class methodsFor:'documentation'! |
|
246 |
||
247 |
copyright |
|
248 |
" |
|
249 |
COPYRIGHT (c) 2013 by Claus Gittinger |
|
21455 | 250 |
All Rights Reserved |
21452 | 251 |
|
252 |
This software is furnished under a license and may be used |
|
253 |
only in accordance with the terms of that license and with the |
|
254 |
inclusion of the above copyright notice. This software may not |
|
255 |
be provided or otherwise made available to, or used by, any |
|
256 |
other person. No title to or ownership of the software is |
|
257 |
hereby transferred. |
|
258 |
" |
|
259 |
! |
|
260 |
||
261 |
documentation |
|
262 |
" |
|
263 |
a small number of OS-X specific redefinitions here. |
|
264 |
||
265 |
[Author:] |
|
21455 | 266 |
Claus Gittinger |
21452 | 267 |
" |
268 |
! ! |
|
17471 | 269 |
|
270 |
!OSXOperatingSystem class methodsFor:'initialization'! |
|
271 |
||
272 |
initializeCodeset |
|
273 |
super initializeCodeset. |
|
17493 | 274 |
Codeset := #'utf8-mac'. |
17494 | 275 |
CodesetEncoder := nil. |
17471 | 276 |
! ! |
14819 | 277 |
|
21452 | 278 |
!OSXOperatingSystem class methodsFor:'cocoa - events'! |
279 |
||
21591 | 280 |
finishLaunching |
281 |
"tell the system, that I have finished my startup phase. |
|
282 |
OSX will stop bounding the launch icon then." |
|
283 |
||
284 |
NSApp isNil ifTrue:[ |
|
285 |
self getNSApp |
|
286 |
]. |
|
287 |
%{ |
|
288 |
#ifndef NO_COCOA |
|
289 |
id NSApp = __externalAddressVal(@global(NSApp)); |
|
290 |
||
291 |
objc_msgSend(NSApp, sel_getUid("finishLaunching")); |
|
292 |
RETURN(self); |
|
293 |
#endif // NO_COCOA |
|
294 |
%}. |
|
295 |
"/ if compiled without COCOA support (which you should not), |
|
296 |
"/ the icon will probably continue to bounce... |
|
297 |
"/ ... but we do not want an error here. |
|
298 |
||
299 |
"/ self primitiveFailed |
|
300 |
||
301 |
" |
|
302 |
self finishLaunching |
|
303 |
" |
|
304 |
||
305 |
"Modified: / 28-02-2017 / 10:59:15 / cg" |
|
306 |
! |
|
307 |
||
21587
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
308 |
generateButtonEvent:button down:down x:screenX y:screenY |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
309 |
"synthesize and send a button event to the screen" |
21584 | 310 |
%{ |
311 |
#ifndef NO_COCOA |
|
21587
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
312 |
if (__bothSmallInteger(screenX, screenY) |
21584 | 313 |
&& __isSmallInteger(button)) { |
21587
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
314 |
CGPoint pt; |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
315 |
pt.x = __intVal(screenX); |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
316 |
pt.y = __intVal(screenY); |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
317 |
|
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
318 |
CGEventType evType; |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
319 |
CGMouseButton evButton = __intVal(button); |
21584 | 320 |
|
21587
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
321 |
switch (evButton) { |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
322 |
case 1: |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
323 |
evType = (down == true) ? kCGEventLeftMouseDown : kCGEventLeftMouseUp; |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
324 |
evButton = 0; |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
325 |
break; |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
326 |
case 2: |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
327 |
evType = (down == true) ? kCGEventRightMouseDown : kCGEventRightMouseUp; |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
328 |
evButton = 1; |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
329 |
break; |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
330 |
case 3: |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
331 |
evType = (down == true) ? kCGEventOtherMouseDown : kCGEventOtherMouseUp; |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
332 |
evButton = 2; |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
333 |
break; |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
334 |
default: |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
335 |
evType = (down == true) ? kCGEventOtherMouseDown : kCGEventOtherMouseUp; |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
336 |
evButton = __intVal(button) - 1; |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
337 |
break; |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
338 |
} |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
339 |
|
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
340 |
CGEventRef theEvent = CGEventCreateMouseEvent(NULL, evType, pt, evButton); |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
341 |
CGEventSetType(theEvent, evType); |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
342 |
CGEventPost(kCGHIDEventTap, theEvent); |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
343 |
CFRelease(theEvent); |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
344 |
RETURN(self); |
21584 | 345 |
} |
346 |
#endif // NO_COCOA |
|
347 |
%}. |
|
348 |
self primitiveFailed |
|
349 |
||
350 |
" |
|
351 |
OperatingSystem generateButtonEvent:1 down:true x:150 y:150. |
|
352 |
OperatingSystem generateButtonEvent:1 down:false x:150 y:150. |
|
353 |
||
354 |
OperatingSystem generateButtonEvent:2 down:true x:150 y:150. |
|
355 |
OperatingSystem generateButtonEvent:2 down:false x:150 y:150. |
|
356 |
" |
|
357 |
||
358 |
"Created: / 28-02-2017 / 00:15:18 / cg" |
|
359 |
! |
|
360 |
||
21587
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
361 |
getNSApp |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
362 |
%{ |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
363 |
#ifndef NO_COCOA |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
364 |
Class AppDelClass = NULL; |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
365 |
id NSApp = NULL; |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
366 |
|
21594 | 367 |
id poolClass = objc_getClass("NSAutoreleasePool"); |
368 |
if (poolClass == NULL) { |
|
369 |
fprintf(stderr, "OSX: Unable to get NSAutoreleasePool\n"); |
|
370 |
RETURN(false); |
|
371 |
} |
|
372 |
id pool = objc_msgSend(poolClass, sel_registerName("alloc")); |
|
373 |
if (pool == NULL) { |
|
374 |
fprintf(stderr, "OSX: Unable to create NSAutoreleasePool\n"); |
|
375 |
RETURN(false); |
|
376 |
} |
|
377 |
objc_msgSend(pool, sel_registerName("init")); |
|
378 |
||
379 |
#if 0 /* not needed */ |
|
21587
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
380 |
AppDelClass = objc_allocateClassPair((Class)objc_getClass("NSObject"), "AppDelegate", 0); |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
381 |
class_addMethod(AppDelClass, sel_getUid("applicationDidFinishLaunching:"), (IMP)AppDel_didFinishLaunching, "i@:@"); |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
382 |
objc_registerClassPair(AppDelClass); |
21594 | 383 |
#endif |
21587
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
384 |
|
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
385 |
NSApp = objc_msgSend((id)objc_getClass("NSApplication"), sel_getUid("sharedApplication")); |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
386 |
if (NSApp == NULL) { |
21594 | 387 |
fprintf(stderr,"OSX: Failed to initialize NSApplication\n"); |
388 |
RETURN(false); |
|
21587
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
389 |
} |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
390 |
@global(NSApp) = __MKEXTERNALADDRESS(NSApp); |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
391 |
|
21594 | 392 |
id req = objc_msgSend(NSApp,sel_getUid("requestUserAttention:"),0); |
393 |
objc_msgSend(NSApp,sel_getUid("cancelUserAttentionRequest:"),req); |
|
21587
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
394 |
|
21594 | 395 |
#if 0 /* not needed */ |
396 |
id appDelInst = objc_msgSend((id)objc_getClass("AppDelegate"), sel_getUid("alloc")); |
|
397 |
objc_msgSend(appDelInst, sel_getUid("init")); |
|
398 |
objc_msgSend(NSApp, sel_getUid("setDelegate:"), appDelInst); |
|
399 |
#endif |
|
400 |
||
401 |
objc_msgSend(pool, sel_registerName("release")); |
|
21587
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
402 |
RETURN(true); |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
403 |
#endif // NO_COCOA |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
404 |
%}. |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
405 |
self primitiveFailed |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
406 |
|
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
407 |
" |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
408 |
self getNSApp |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
409 |
" |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
410 |
|
21594 | 411 |
"Modified: / 28-02-2017 / 13:45:39 / cg" |
21587
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
412 |
! |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
413 |
|
21591 | 414 |
receiveNextEvent |
21587
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
415 |
%{ |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
416 |
#ifndef NO_COCOA |
21591 | 417 |
CFMachPortRef eventTap; |
418 |
CGEventMask eventMask; |
|
419 |
CFRunLoopSourceRef runLoopSource; |
|
21587
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
420 |
|
21591 | 421 |
// Create an event tap. We are interested in key presses. |
422 |
eventMask = ((1 << kCGEventKeyDown) | (1 << kCGEventKeyUp)); |
|
423 |
eventTap = CGEventTapCreate(kCGSessionEventTap, kCGHeadInsertEventTap, 0, |
|
424 |
eventMask, NULL, myCGEventCallback); |
|
425 |
if (!eventTap) { |
|
426 |
fprintf(stderr, "failed to create event tap\n"); |
|
427 |
} else { |
|
428 |
fprintf(stderr, "ok\n"); |
|
429 |
||
430 |
// Create a run loop source. |
|
431 |
runLoopSource = CFMachPortCreateRunLoopSource( kCFAllocatorDefault, eventTap, 0); |
|
432 |
// Enable the event tap. |
|
433 |
CGEventTapEnable(eventTap, true); |
|
434 |
} |
|
435 |
||
21587
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
436 |
#endif // NO_COCOA |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
437 |
%}. |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
438 |
self primitiveFailed |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
439 |
|
21591 | 440 |
"Modified: / 28-02-2017 / 01:05:04 / cg" |
21452 | 441 |
! ! |
442 |
||
17297
a56ba300949c
Overriden openApplicationForDocument... to use desktop-specific "open" command.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17179
diff
changeset
|
443 |
!OSXOperatingSystem class methodsFor:'dummy shell operations'! |
a56ba300949c
Overriden openApplicationForDocument... to use desktop-specific "open" command.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17179
diff
changeset
|
444 |
|
a56ba300949c
Overriden openApplicationForDocument... to use desktop-specific "open" command.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17179
diff
changeset
|
445 |
openApplicationHelperCommand |
a56ba300949c
Overriden openApplicationForDocument... to use desktop-specific "open" command.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17179
diff
changeset
|
446 |
"Return a command line helper to open a default application for file or URL" |
a56ba300949c
Overriden openApplicationForDocument... to use desktop-specific "open" command.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17179
diff
changeset
|
447 |
|
18279 | 448 |
(self canExecuteCommand: 'open') ifTrue:[ |
449 |
^ 'open' |
|
17297
a56ba300949c
Overriden openApplicationForDocument... to use desktop-specific "open" command.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17179
diff
changeset
|
450 |
]. |
a56ba300949c
Overriden openApplicationForDocument... to use desktop-specific "open" command.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17179
diff
changeset
|
451 |
^ nil |
a56ba300949c
Overriden openApplicationForDocument... to use desktop-specific "open" command.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17179
diff
changeset
|
452 |
|
a56ba300949c
Overriden openApplicationForDocument... to use desktop-specific "open" command.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17179
diff
changeset
|
453 |
"Created: / 13-01-2015 / 09:23:18 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
17427 | 454 |
! |
455 |
||
17428 | 456 |
openTerminalWithCommand:shellCommand inBackground:inBackground |
17427 | 457 |
"open a new terminal, which executes a command" |
458 |
||
17428 | 459 |
|cmd| |
460 |
||
461 |
cmd := 'osascript -e ''tell application "Terminal" to do script "%1"''' bindWith:shellCommand. |
|
462 |
||
463 |
inBackground ifTrue:[ |
|
18279 | 464 |
^ self |
465 |
startProcess:cmd |
|
466 |
inputFrom:nil |
|
467 |
outputTo:nil |
|
468 |
errorTo:nil |
|
469 |
auxFrom:nil |
|
470 |
environment:nil |
|
471 |
inDirectory:nil |
|
17428 | 472 |
] ifFalse:[ |
18279 | 473 |
^ self executeCommand:cmd |
17428 | 474 |
]. |
17427 | 475 |
|
476 |
" |
|
17428 | 477 |
OSXOperatingSystem openTerminalWithCommand:'ls -l' inBackground:true |
17427 | 478 |
" |
17297
a56ba300949c
Overriden openApplicationForDocument... to use desktop-specific "open" command.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17179
diff
changeset
|
479 |
! ! |
a56ba300949c
Overriden openApplicationForDocument... to use desktop-specific "open" command.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17179
diff
changeset
|
480 |
|
14819 | 481 |
!OSXOperatingSystem class methodsFor:'file queries'! |
482 |
||
483 |
caseSensitiveFilenames |
|
484 |
"return true, if the OS has caseSensitive file naming. |
|
485 |
On MSDOS, this will return false; |
|
19817 | 486 |
on a real OS, we return true. |
487 |
Be aware, that OSX can be configured to be either. |
|
488 |
Also, that it actually depends on the mounted volume" |
|
14819 | 489 |
|
18279 | 490 |
"/ actually, this is wrong and depends on the mounted volume; |
491 |
"/ so we need a query for a particular directory (and/or volume). |
|
14819 | 492 |
^ false |
493 |
||
494 |
"Modified: / 5.6.1998 / 18:35:18 / cg" |
|
16381 | 495 |
! |
496 |
||
16644 | 497 |
defaultPackagePath |
20639 | 498 |
"redefined to add /Application and /Library stuff" |
20642 | 499 |
"called by Smalltalk initSystemPath" |
500 |
"self defaultPackagePath" |
|
16644 | 501 |
|
21452 | 502 |
|path executablePath executableDir packagesDir |
20637 | 503 |
libDir appDir versionsDir vsnDirName vsnDir| |
16644 | 504 |
|
505 |
path := super defaultPackagePath. |
|
506 |
||
507 |
executablePath := OperatingSystem pathOfSTXExecutable. |
|
508 |
executablePath notNil ifTrue:[ |
|
21452 | 509 |
executableDir := executablePath asFilename directory. |
510 |
packagesDir := executableDir directory directory / 'Packages'. |
|
511 |
packagesDir exists ifTrue:[ |
|
512 |
packagesDir := packagesDir pathName. |
|
513 |
(path includes:packagesDir) ifFalse:[ |
|
514 |
path add:packagesDir. |
|
515 |
]. |
|
516 |
]. |
|
517 |
libDir := '/Library/Frameworks/SmalltalkX.framework' asFilename. |
|
518 |
libDir exists ifTrue:[ |
|
519 |
versionsDir := libDir / 'Versions'. |
|
520 |
versionsDir exists ifTrue:[ |
|
521 |
vsnDirName := '%1.%2.%3' |
|
522 |
bindWith:Smalltalk majorVersionNr |
|
523 |
with:Smalltalk minorVersionNr |
|
524 |
with:Smalltalk revisionNr. |
|
525 |
vsnDir := versionsDir / vsnDirName. |
|
526 |
vsnDir exists ifTrue:[ |
|
527 |
vsnDir := vsnDir pathName. |
|
528 |
(path includes:vsnDir) ifFalse:[ |
|
529 |
path add:vsnDir. |
|
530 |
]. |
|
531 |
]. |
|
532 |
]. |
|
533 |
]. |
|
534 |
appDir := '/Applications/SmalltalkX/' asFilename. |
|
535 |
appDir exists ifTrue:[ |
|
536 |
versionsDir := appDir / 'Versions'. |
|
537 |
versionsDir exists ifTrue:[ |
|
538 |
vsnDirName := '%1.%2.%3' |
|
539 |
bindWith:Smalltalk majorVersionNr |
|
540 |
with:Smalltalk minorVersionNr |
|
541 |
with:Smalltalk revisionNr. |
|
542 |
vsnDir := versionsDir / vsnDirName. |
|
543 |
vsnDir exists ifTrue:[ |
|
544 |
vsnDir := vsnDir pathName. |
|
545 |
(path includes:vsnDir) ifFalse:[ |
|
546 |
path add:vsnDir. |
|
547 |
]. |
|
548 |
]. |
|
549 |
]. |
|
550 |
]. |
|
16644 | 551 |
]. |
16647 | 552 |
^ path |
16644 | 553 |
! |
554 |
||
16677 | 555 |
getDriveList |
556 |
"return a list of volumes in the system." |
|
557 |
||
558 |
^ ('/Volumes' asFilename directoryContents) |
|
559 |
, super getDriveList |
|
560 |
! |
|
561 |
||
16381 | 562 |
getTrashDirectory |
563 |
"get the name of a trash folder (if the OS supports it), |
|
564 |
or nil, if not. |
|
565 |
Must be redefined to return non nil in concrete operating systems" |
|
566 |
||
567 |
^ '~/.Trash' |
|
16677 | 568 |
! |
569 |
||
570 |
pathNameForDrive:driveName |
|
571 |
"given a drive name, return the pathname to open it as a directory. |
|
572 |
For Windows, this is the driveName itself. |
|
573 |
For OSX, '/Volumes' is prepended. |
|
574 |
Other OSs might prepent the pount point (i.e. /mnt/)" |
|
575 |
||
16905 | 576 |
driveName isNil ifTrue:[^ nil]. |
16677 | 577 |
driveName asFilename isAbsolute ifTrue:[^ driveName]. |
578 |
^ '/Volumes/',driveName |
|
17177 | 579 |
! |
580 |
||
581 |
supportsVolumes |
|
18279 | 582 |
"return true if the os support a list of drives/volumes |
17179 | 583 |
(here we can return a list of mounted drives in /Volumes)" |
17177 | 584 |
|
585 |
^ true |
|
14819 | 586 |
! ! |
587 |
||
21452 | 588 |
!OSXOperatingSystem class methodsFor:'quartz - screen'! |
589 |
||
590 |
getFrameBufferImage:displayNr |
|
591 |
"returns the framebuffer as an image object" |
|
592 |
||
21580 | 593 |
^ self getFrameBufferImage:displayNr in:nil |
594 |
||
595 |
" |
|
596 |
self getFrameBufferImage:0 |
|
597 |
" |
|
598 |
||
599 |
"Modified: / 25-02-2017 / 10:57:17 / cg" |
|
600 |
! |
|
21452 | 601 |
|
21580 | 602 |
getFrameBufferImage:displayNr in:aRectangleOrNil |
21587
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
603 |
"returns the frameBuffer (if rect-arg is nil) |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
604 |
or part of the framebuffer (if non-nil) as an image object" |
21580 | 605 |
|
21587
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
606 |
|rx ry rwidth rheight bytesPerPixel bytesPerRow address pixels depth pad img ok| |
21580 | 607 |
|
608 |
aRectangleOrNil notNil ifTrue:[ |
|
21587
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
609 |
rx := aRectangleOrNil left. |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
610 |
ry := aRectangleOrNil top. |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
611 |
rwidth := aRectangleOrNil width. |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
612 |
rheight := aRectangleOrNil height. |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
613 |
]. |
21452 | 614 |
%{ |
615 |
#ifndef NO_QUARTZ |
|
21580 | 616 |
CGImageRef image_ref; |
617 |
CGDirectDisplayID displayID = CGMainDisplayID(); |
|
21587
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
618 |
|
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
619 |
ok = false; |
21580 | 620 |
if (rx == nil) { |
21587
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
621 |
image_ref = CGDisplayCreateImage(displayID); |
21580 | 622 |
} else { |
21587
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
623 |
CGRect rect; |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
624 |
rect.origin.x = (CGFloat)__intVal(rx); |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
625 |
rect.origin.y = (CGFloat)__intVal(ry); |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
626 |
rect.size.width = (CGFloat)__intVal(rwidth); |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
627 |
rect.size.height = (CGFloat)__intVal(rheight); |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
628 |
image_ref = CGDisplayCreateImageForRect(displayID, rect); |
21580 | 629 |
} |
21587
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
630 |
|
21580 | 631 |
if (image_ref != NULL) { |
21587
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
632 |
CGDataProviderRef provider = CGImageGetDataProvider(image_ref); |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
633 |
CFDataRef dataref = CGDataProviderCopyData(provider); |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
634 |
size_t c_width = CGImageGetWidth(image_ref); |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
635 |
size_t c_height = CGImageGetHeight(image_ref); |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
636 |
size_t c_bytesPerRow = CGImageGetBytesPerRow(image_ref); |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
637 |
size_t c_bytesPerPixel = CGImageGetBitsPerPixel(image_ref) / 8; |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
638 |
unsigned char *c_pixels = CFDataGetBytePtr(dataref); |
21452 | 639 |
|
21587
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
640 |
pixels = __BYTEARRAY_UNINITIALIZED_NEW_INT(c_width * c_height * c_bytesPerPixel); |
21452 | 641 |
|
21587
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
642 |
if (c_bytesPerPixel == 4) { |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
643 |
int row; |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
644 |
unsigned char *srcRowPtr = c_pixels; |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
645 |
unsigned char *dstRowPtr = __byteArrayVal(pixels); |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
646 |
|
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
647 |
for (row=c_height; row>0; row--) { |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
648 |
int col; |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
649 |
unsigned int *pixSrcPtr = (int*)srcRowPtr; |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
650 |
unsigned int *pixDstPtr = (int*)dstRowPtr; |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
651 |
|
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
652 |
// swap abgr to argb |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
653 |
for (col=c_width; col>0;col--) { |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
654 |
unsigned int pix = *pixSrcPtr++; |
21452 | 655 |
|
21587
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
656 |
pix = ((pix >> 16) & 0x0000FF)|((pix << 16) & 0xFF0000)|(pix & 0x00FF00); |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
657 |
*pixDstPtr++ = pix; |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
658 |
} |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
659 |
dstRowPtr += c_width * c_bytesPerPixel; |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
660 |
srcRowPtr += c_bytesPerRow; |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
661 |
} |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
662 |
ok = true; |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
663 |
} else { |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
664 |
// to be determined what we get... |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
665 |
ok = false; |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
666 |
} |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
667 |
CFRelease(dataref); |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
668 |
CGImageRelease(image_ref); |
21580 | 669 |
|
21587
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
670 |
rwidth = __MKUINT( c_width ); |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
671 |
rheight = __MKUINT( c_height ); |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
672 |
bytesPerPixel = __MKUINT( c_bytesPerPixel ); |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
673 |
bytesPerRow = __MKUINT( c_bytesPerRow ); |
21580 | 674 |
} |
675 |
||
676 |
// the following is no longer supported by apple |
|
677 |
// CGDisplayBaseAddress is deprecated |
|
678 |
// |
|
679 |
// uint32_t rowBytes, rowUInt32s, *screen; |
|
680 |
// |
|
681 |
// CGDirectDisplayID targetDisplay = 0; |
|
682 |
// |
|
683 |
// screen = (uint32_t *)CGDisplayBaseAddress(targetDisplay); |
|
684 |
// rowBytes = CGDisplayBytesPerRow(targetDisplay); |
|
685 |
// rowUInt32s = rowBytes / 4; |
|
686 |
// rwidth = __MKUINT( CGDisplayPixelsWide(targetDisplay) ); |
|
687 |
// rheight = __MKUINT( CGDisplayPixelsHigh(targetDisplay) ); |
|
688 |
// |
|
21587
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
689 |
|
21452 | 690 |
#endif // NO_QUARTZ |
691 |
||
692 |
%}. |
|
21587
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
693 |
(ok not or:[rwidth isNil]) ifTrue:[ |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
694 |
^ self primitiveFailed |
21452 | 695 |
]. |
696 |
depth := bytesPerPixel * 8. |
|
697 |
||
21587
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
698 |
"/ Transcript printf:'w:%d h:%d bpp:%d depth:%d bpr: %d\n' |
21580 | 699 |
"/ withAll:{ rwidth . rheight . bytesPerPixel . depth . bytesPerRow}. |
21452 | 700 |
|
21580 | 701 |
( #(16 32) includes:depth) ifFalse:[ |
21587
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
702 |
"/ check what we get here... |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
703 |
^ self primitiveFailed:'unsupported depth' |
21452 | 704 |
]. |
705 |
||
21580 | 706 |
img := Image extent:(rwidth @ rheight) depth:depth bits:pixels. |
707 |
||
708 |
img bitsPerSample:#[8 8 8 8]. |
|
709 |
img samplesPerPixel:4. |
|
21452 | 710 |
img photometric:#rgb. |
711 |
^ img |
|
21580 | 712 |
|
713 |
" |
|
714 |
self getFrameBufferImage:0 in:nil |
|
715 |
self getFrameBufferImage:0 in:(100@100 corner:301@303) |
|
716 |
" |
|
717 |
||
718 |
"Created: / 25-02-2017 / 09:49:07 / cg" |
|
21582 | 719 |
"Modified: / 27-02-2017 / 02:01:24 / cg" |
21452 | 720 |
! ! |
721 |
||
14819 | 722 |
!OSXOperatingSystem class methodsFor:'documentation'! |
723 |
||
724 |
version |
|
19817 | 725 |
^ '$Header$' |
14819 | 726 |
! |
727 |
||
728 |
version_CVS |
|
19817 | 729 |
^ '$Header$' |
14819 | 730 |
! ! |
21591 | 731 |