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