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