author | Claus Gittinger <cg@exept.de> |
Sun, 05 Mar 2017 11:44:33 +0100 | |
changeset 21625 | 026eecef148d |
parent 21621 | 0712ebc6d6cf |
child 21627 | 213250371878 |
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 |
||
21621 | 362 |
generateKeyboardEvent:keyCode down:down |
363 |
"synthesize and send a keyboard event to the screen" |
|
364 |
%{ |
|
365 |
#ifndef NO_COCOA |
|
366 |
if (__isSmallInteger(keyCode)) { |
|
367 |
int evType; |
|
368 |
||
369 |
CGEventRef theEvent = CGEventCreateKeyboardEvent(NULL, __intVal(keyCode), (down==true)?1:0); |
|
370 |
CGEventSetType(theEvent, (down==true) ? kCGEventKeyDown:kCGEventKeyUp); |
|
371 |
CGEventPost(kCGHIDEventTap, theEvent); |
|
372 |
CFRelease(theEvent); |
|
373 |
RETURN(self); |
|
374 |
} |
|
375 |
#endif // NO_COCOA |
|
376 |
%}. |
|
377 |
self primitiveFailed |
|
378 |
||
379 |
" |
|
380 |
OperatingSystem generateKeyboardEvent:6 down:true. |
|
381 |
OperatingSystem generateKeyboardEvent:6 down:false. |
|
382 |
" |
|
383 |
||
384 |
"Created: / 02-03-2017 / 16:35:04 / cg" |
|
385 |
! |
|
386 |
||
387 |
generateMouseMoveEventX:screenX y:screenY |
|
388 |
"synthesize and send a mosue move event to the screen" |
|
389 |
%{ |
|
390 |
#ifndef NO_COCOA |
|
391 |
if (__bothSmallInteger(screenX, screenY)) { |
|
392 |
CGPoint pt; |
|
393 |
pt.x = __intVal(screenX); |
|
394 |
pt.y = __intVal(screenY); |
|
395 |
||
396 |
CGEventType evType; |
|
397 |
CGEventRef theEvent = CGEventCreateMouseEvent(NULL, kCGEventMouseMoved, pt, 0); |
|
398 |
CGEventSetType(theEvent, kCGEventMouseMoved); |
|
399 |
CGEventPost(kCGHIDEventTap, theEvent); |
|
400 |
CFRelease(theEvent); |
|
401 |
RETURN(self); |
|
402 |
} |
|
403 |
#endif // NO_COCOA |
|
404 |
%}. |
|
405 |
self primitiveFailed |
|
406 |
||
407 |
" |
|
408 |
OperatingSystem generateMouseMoveEventX:150 y:5. |
|
409 |
Delay waitFor:(1 seconds). |
|
410 |
OperatingSystem generateMouseMoveEventX:1050 y:150. |
|
411 |
" |
|
412 |
||
413 |
"Created: / 02-03-2017 / 20:01:51 / cg" |
|
414 |
! |
|
415 |
||
21587
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
416 |
getNSApp |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
417 |
%{ |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
418 |
#ifndef NO_COCOA |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
419 |
Class AppDelClass = NULL; |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
420 |
id NSApp = NULL; |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
421 |
|
21597 | 422 |
#if 0 /* not needed */ |
423 |
Class poolClass = objc_getClass("NSAutoreleasePool"); |
|
21594 | 424 |
if (poolClass == NULL) { |
21597 | 425 |
fprintf(stderr, "OSX: Unable to get NSAutoreleasePool\n"); |
426 |
RETURN(false); |
|
21594 | 427 |
} |
428 |
id pool = objc_msgSend(poolClass, sel_registerName("alloc")); |
|
429 |
if (pool == NULL) { |
|
21597 | 430 |
fprintf(stderr, "OSX: Unable to create NSAutoreleasePool\n"); |
431 |
RETURN(false); |
|
21594 | 432 |
} |
433 |
objc_msgSend(pool, sel_registerName("init")); |
|
21597 | 434 |
#endif |
21594 | 435 |
|
436 |
#if 0 /* not needed */ |
|
21587
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
437 |
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
|
438 |
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
|
439 |
objc_registerClassPair(AppDelClass); |
21594 | 440 |
#endif |
21587
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
441 |
|
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
442 |
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
|
443 |
if (NSApp == NULL) { |
21597 | 444 |
fprintf(stderr,"OSX: Failed to initialize NSApplication\n"); |
445 |
RETURN(false); |
|
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 |
@global(NSApp) = __MKEXTERNALADDRESS(NSApp); |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
448 |
|
21594 | 449 |
id req = objc_msgSend(NSApp,sel_getUid("requestUserAttention:"),0); |
450 |
objc_msgSend(NSApp,sel_getUid("cancelUserAttentionRequest:"),req); |
|
21587
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
451 |
|
21594 | 452 |
#if 0 /* not needed */ |
453 |
id appDelInst = objc_msgSend((id)objc_getClass("AppDelegate"), sel_getUid("alloc")); |
|
454 |
objc_msgSend(appDelInst, sel_getUid("init")); |
|
455 |
objc_msgSend(NSApp, sel_getUid("setDelegate:"), appDelInst); |
|
456 |
#endif |
|
457 |
||
21597 | 458 |
#if 0 /* not needed */ |
21594 | 459 |
objc_msgSend(pool, sel_registerName("release")); |
21597 | 460 |
#endif |
21587
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
461 |
RETURN(true); |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
462 |
#endif // NO_COCOA |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
463 |
%}. |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
464 |
self primitiveFailed |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
465 |
|
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
466 |
" |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
467 |
self getNSApp |
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 |
|
21594 | 470 |
"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
|
471 |
! |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
472 |
|
21591 | 473 |
receiveNextEvent |
21587
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
474 |
%{ |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
475 |
#ifndef NO_COCOA |
21591 | 476 |
CFMachPortRef eventTap; |
477 |
CGEventMask eventMask; |
|
478 |
CFRunLoopSourceRef runLoopSource; |
|
21587
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
479 |
|
21591 | 480 |
// Create an event tap. We are interested in key presses. |
481 |
eventMask = ((1 << kCGEventKeyDown) | (1 << kCGEventKeyUp)); |
|
482 |
eventTap = CGEventTapCreate(kCGSessionEventTap, kCGHeadInsertEventTap, 0, |
|
483 |
eventMask, NULL, myCGEventCallback); |
|
484 |
if (!eventTap) { |
|
485 |
fprintf(stderr, "failed to create event tap\n"); |
|
486 |
} else { |
|
487 |
fprintf(stderr, "ok\n"); |
|
488 |
||
489 |
// Create a run loop source. |
|
490 |
runLoopSource = CFMachPortCreateRunLoopSource( kCFAllocatorDefault, eventTap, 0); |
|
491 |
// Enable the event tap. |
|
492 |
CGEventTapEnable(eventTap, true); |
|
493 |
} |
|
494 |
||
21587
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
495 |
#endif // NO_COCOA |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
496 |
%}. |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
497 |
self primitiveFailed |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
498 |
|
21591 | 499 |
"Modified: / 28-02-2017 / 01:05:04 / cg" |
21452 | 500 |
! ! |
501 |
||
17297
a56ba300949c
Overriden openApplicationForDocument... to use desktop-specific "open" command.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17179
diff
changeset
|
502 |
!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
|
503 |
|
a56ba300949c
Overriden openApplicationForDocument... to use desktop-specific "open" command.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17179
diff
changeset
|
504 |
openApplicationHelperCommand |
a56ba300949c
Overriden openApplicationForDocument... to use desktop-specific "open" command.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17179
diff
changeset
|
505 |
"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
|
506 |
|
18279 | 507 |
(self canExecuteCommand: 'open') ifTrue:[ |
508 |
^ 'open' |
|
17297
a56ba300949c
Overriden openApplicationForDocument... to use desktop-specific "open" command.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17179
diff
changeset
|
509 |
]. |
a56ba300949c
Overriden openApplicationForDocument... to use desktop-specific "open" command.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17179
diff
changeset
|
510 |
^ nil |
a56ba300949c
Overriden openApplicationForDocument... to use desktop-specific "open" command.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17179
diff
changeset
|
511 |
|
a56ba300949c
Overriden openApplicationForDocument... to use desktop-specific "open" command.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17179
diff
changeset
|
512 |
"Created: / 13-01-2015 / 09:23:18 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
17427 | 513 |
! |
514 |
||
17428 | 515 |
openTerminalWithCommand:shellCommand inBackground:inBackground |
17427 | 516 |
"open a new terminal, which executes a command" |
517 |
||
17428 | 518 |
|cmd| |
519 |
||
520 |
cmd := 'osascript -e ''tell application "Terminal" to do script "%1"''' bindWith:shellCommand. |
|
521 |
||
522 |
inBackground ifTrue:[ |
|
18279 | 523 |
^ self |
524 |
startProcess:cmd |
|
525 |
inputFrom:nil |
|
526 |
outputTo:nil |
|
527 |
errorTo:nil |
|
528 |
auxFrom:nil |
|
529 |
environment:nil |
|
530 |
inDirectory:nil |
|
17428 | 531 |
] ifFalse:[ |
18279 | 532 |
^ self executeCommand:cmd |
17428 | 533 |
]. |
17427 | 534 |
|
535 |
" |
|
17428 | 536 |
OSXOperatingSystem openTerminalWithCommand:'ls -l' inBackground:true |
17427 | 537 |
" |
17297
a56ba300949c
Overriden openApplicationForDocument... to use desktop-specific "open" command.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17179
diff
changeset
|
538 |
! ! |
a56ba300949c
Overriden openApplicationForDocument... to use desktop-specific "open" command.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17179
diff
changeset
|
539 |
|
14819 | 540 |
!OSXOperatingSystem class methodsFor:'file queries'! |
541 |
||
542 |
caseSensitiveFilenames |
|
543 |
"return true, if the OS has caseSensitive file naming. |
|
544 |
On MSDOS, this will return false; |
|
19817 | 545 |
on a real OS, we return true. |
546 |
Be aware, that OSX can be configured to be either. |
|
547 |
Also, that it actually depends on the mounted volume" |
|
14819 | 548 |
|
18279 | 549 |
"/ actually, this is wrong and depends on the mounted volume; |
550 |
"/ so we need a query for a particular directory (and/or volume). |
|
14819 | 551 |
^ false |
552 |
||
553 |
"Modified: / 5.6.1998 / 18:35:18 / cg" |
|
16381 | 554 |
! |
555 |
||
16644 | 556 |
defaultPackagePath |
20639 | 557 |
"redefined to add /Application and /Library stuff" |
20642 | 558 |
"called by Smalltalk initSystemPath" |
559 |
"self defaultPackagePath" |
|
16644 | 560 |
|
21452 | 561 |
|path executablePath executableDir packagesDir |
20637 | 562 |
libDir appDir versionsDir vsnDirName vsnDir| |
16644 | 563 |
|
564 |
path := super defaultPackagePath. |
|
565 |
||
566 |
executablePath := OperatingSystem pathOfSTXExecutable. |
|
567 |
executablePath notNil ifTrue:[ |
|
21452 | 568 |
executableDir := executablePath asFilename directory. |
569 |
packagesDir := executableDir directory directory / 'Packages'. |
|
570 |
packagesDir exists ifTrue:[ |
|
571 |
packagesDir := packagesDir pathName. |
|
572 |
(path includes:packagesDir) ifFalse:[ |
|
573 |
path add:packagesDir. |
|
574 |
]. |
|
575 |
]. |
|
576 |
libDir := '/Library/Frameworks/SmalltalkX.framework' asFilename. |
|
577 |
libDir exists ifTrue:[ |
|
578 |
versionsDir := libDir / 'Versions'. |
|
579 |
versionsDir exists ifTrue:[ |
|
580 |
vsnDirName := '%1.%2.%3' |
|
581 |
bindWith:Smalltalk majorVersionNr |
|
582 |
with:Smalltalk minorVersionNr |
|
583 |
with:Smalltalk revisionNr. |
|
584 |
vsnDir := versionsDir / vsnDirName. |
|
585 |
vsnDir exists ifTrue:[ |
|
586 |
vsnDir := vsnDir pathName. |
|
587 |
(path includes:vsnDir) ifFalse:[ |
|
588 |
path add:vsnDir. |
|
589 |
]. |
|
590 |
]. |
|
591 |
]. |
|
592 |
]. |
|
593 |
appDir := '/Applications/SmalltalkX/' asFilename. |
|
594 |
appDir exists ifTrue:[ |
|
595 |
versionsDir := appDir / 'Versions'. |
|
596 |
versionsDir exists ifTrue:[ |
|
597 |
vsnDirName := '%1.%2.%3' |
|
598 |
bindWith:Smalltalk majorVersionNr |
|
599 |
with:Smalltalk minorVersionNr |
|
600 |
with:Smalltalk revisionNr. |
|
601 |
vsnDir := versionsDir / vsnDirName. |
|
602 |
vsnDir exists ifTrue:[ |
|
603 |
vsnDir := vsnDir pathName. |
|
604 |
(path includes:vsnDir) ifFalse:[ |
|
605 |
path add:vsnDir. |
|
606 |
]. |
|
607 |
]. |
|
608 |
]. |
|
609 |
]. |
|
16644 | 610 |
]. |
16647 | 611 |
^ path |
16644 | 612 |
! |
613 |
||
16677 | 614 |
getDriveList |
615 |
"return a list of volumes in the system." |
|
616 |
||
617 |
^ ('/Volumes' asFilename directoryContents) |
|
618 |
, super getDriveList |
|
619 |
! |
|
620 |
||
16381 | 621 |
getTrashDirectory |
622 |
"get the name of a trash folder (if the OS supports it), |
|
623 |
or nil, if not. |
|
624 |
Must be redefined to return non nil in concrete operating systems" |
|
625 |
||
626 |
^ '~/.Trash' |
|
16677 | 627 |
! |
628 |
||
629 |
pathNameForDrive:driveName |
|
630 |
"given a drive name, return the pathname to open it as a directory. |
|
631 |
For Windows, this is the driveName itself. |
|
632 |
For OSX, '/Volumes' is prepended. |
|
633 |
Other OSs might prepent the pount point (i.e. /mnt/)" |
|
634 |
||
16905 | 635 |
driveName isNil ifTrue:[^ nil]. |
16677 | 636 |
driveName asFilename isAbsolute ifTrue:[^ driveName]. |
637 |
^ '/Volumes/',driveName |
|
17177 | 638 |
! |
639 |
||
640 |
supportsVolumes |
|
18279 | 641 |
"return true if the os support a list of drives/volumes |
17179 | 642 |
(here we can return a list of mounted drives in /Volumes)" |
17177 | 643 |
|
644 |
^ true |
|
14819 | 645 |
! ! |
646 |
||
21452 | 647 |
!OSXOperatingSystem class methodsFor:'quartz - screen'! |
648 |
||
649 |
getFrameBufferImage:displayNr |
|
650 |
"returns the framebuffer as an image object" |
|
651 |
||
21580 | 652 |
^ self getFrameBufferImage:displayNr in:nil |
653 |
||
654 |
" |
|
655 |
self getFrameBufferImage:0 |
|
656 |
" |
|
657 |
||
658 |
"Modified: / 25-02-2017 / 10:57:17 / cg" |
|
659 |
! |
|
21452 | 660 |
|
21580 | 661 |
getFrameBufferImage:displayNr in:aRectangleOrNil |
21587
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
662 |
"returns the frameBuffer (if rect-arg is nil) |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
663 |
or part of the framebuffer (if non-nil) as an image object" |
21580 | 664 |
|
21587
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
665 |
|rx ry rwidth rheight bytesPerPixel bytesPerRow address pixels depth pad img ok| |
21580 | 666 |
|
667 |
aRectangleOrNil notNil ifTrue:[ |
|
21598 | 668 |
rx := aRectangleOrNil left. |
669 |
ry := aRectangleOrNil top. |
|
670 |
rwidth := aRectangleOrNil width. |
|
671 |
rheight := aRectangleOrNil height. |
|
21587
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
672 |
]. |
21452 | 673 |
%{ |
21596 | 674 |
#ifndef NO_COCOA |
21580 | 675 |
CGImageRef image_ref; |
676 |
CGDirectDisplayID displayID = CGMainDisplayID(); |
|
21587
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
677 |
|
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
678 |
ok = false; |
21580 | 679 |
if (rx == nil) { |
21598 | 680 |
image_ref = CGDisplayCreateImage(displayID); |
21580 | 681 |
} else { |
21598 | 682 |
CGRect rect; |
683 |
rect.origin.x = (CGFloat)__intVal(rx); |
|
684 |
rect.origin.y = (CGFloat)__intVal(ry); |
|
685 |
rect.size.width = (CGFloat)__intVal(rwidth); |
|
686 |
rect.size.height = (CGFloat)__intVal(rheight); |
|
687 |
image_ref = CGDisplayCreateImageForRect(displayID, rect); |
|
21580 | 688 |
} |
21587
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
689 |
|
21580 | 690 |
if (image_ref != NULL) { |
21598 | 691 |
CGDataProviderRef provider = CGImageGetDataProvider(image_ref); |
692 |
CFDataRef dataref = CGDataProviderCopyData(provider); |
|
693 |
size_t c_width = CGImageGetWidth(image_ref); |
|
694 |
size_t c_height = CGImageGetHeight(image_ref); |
|
695 |
size_t c_bytesPerRow = CGImageGetBytesPerRow(image_ref); |
|
696 |
size_t c_bytesPerPixel = CGImageGetBitsPerPixel(image_ref) / 8; |
|
697 |
unsigned char *c_pixels = (unsigned char *)CFDataGetBytePtr(dataref); |
|
21452 | 698 |
|
21598 | 699 |
if (c_bytesPerPixel == 4) { |
700 |
int row; |
|
701 |
pixels = __BYTEARRAY_UNINITIALIZED_NEW_INT(c_width * c_height * 3); |
|
702 |
unsigned char *srcRowPtr = c_pixels; |
|
703 |
unsigned char *dstRowPtr = __byteArrayVal(pixels); |
|
21587
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
704 |
|
21598 | 705 |
for (row=c_height; row>0; row--) { |
706 |
int col; |
|
707 |
unsigned int *pixSrcPtr = (int*)srcRowPtr; |
|
708 |
unsigned char *pixDstPtr = dstRowPtr; |
|
21587
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
709 |
|
21598 | 710 |
// swap abgr to argb |
711 |
for (col=c_width; col>0;col--) { |
|
712 |
unsigned int pix = *pixSrcPtr++; |
|
21452 | 713 |
|
21598 | 714 |
pix = ((pix >> 16) & 0x0000FF)|((pix << 16) & 0xFF0000)|(pix & 0x00FF00); |
715 |
pixDstPtr[0] = (pix >> 0); |
|
716 |
pixDstPtr[1] = (pix >> 8); |
|
717 |
pixDstPtr[2] = (pix >> 16); |
|
718 |
pixDstPtr += 3; |
|
719 |
} |
|
720 |
dstRowPtr += c_width * 3; |
|
721 |
srcRowPtr += c_bytesPerRow; |
|
722 |
} |
|
723 |
bytesPerPixel = __MKSMALLINT(3); |
|
724 |
bytesPerRow = __MKSMALLINT( c_width*3 ); |
|
725 |
ok = true; |
|
726 |
} else { |
|
727 |
// to be determined what we get... |
|
728 |
ok = false; |
|
729 |
} |
|
730 |
CFRelease(dataref); |
|
731 |
CGImageRelease(image_ref); |
|
21580 | 732 |
|
21598 | 733 |
rwidth = __MKUINT( c_width ); |
734 |
rheight = __MKUINT( c_height ); |
|
21580 | 735 |
} |
736 |
||
737 |
// the following is no longer supported by apple |
|
738 |
// CGDisplayBaseAddress is deprecated |
|
739 |
// |
|
740 |
// uint32_t rowBytes, rowUInt32s, *screen; |
|
741 |
// |
|
742 |
// CGDirectDisplayID targetDisplay = 0; |
|
743 |
// |
|
744 |
// screen = (uint32_t *)CGDisplayBaseAddress(targetDisplay); |
|
745 |
// rowBytes = CGDisplayBytesPerRow(targetDisplay); |
|
746 |
// rowUInt32s = rowBytes / 4; |
|
747 |
// rwidth = __MKUINT( CGDisplayPixelsWide(targetDisplay) ); |
|
748 |
// rheight = __MKUINT( CGDisplayPixelsHigh(targetDisplay) ); |
|
749 |
// |
|
21587
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
750 |
|
21596 | 751 |
#endif // NO_COCOA |
21452 | 752 |
|
753 |
%}. |
|
21587
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
754 |
(ok not or:[rwidth isNil]) ifTrue:[ |
21598 | 755 |
^ self primitiveFailed |
21452 | 756 |
]. |
757 |
depth := bytesPerPixel * 8. |
|
758 |
||
21587
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
759 |
"/ Transcript printf:'w:%d h:%d bpp:%d depth:%d bpr: %d\n' |
21580 | 760 |
"/ withAll:{ rwidth . rheight . bytesPerPixel . depth . bytesPerRow}. |
21452 | 761 |
|
21598 | 762 |
( #(24) includes:depth) ifFalse:[ |
763 |
"/ check what we get here... |
|
764 |
^ self primitiveFailed:'unsupported depth' |
|
21452 | 765 |
]. |
766 |
||
21580 | 767 |
img := Image extent:(rwidth @ rheight) depth:depth bits:pixels. |
21598 | 768 |
depth == 24 ifTrue:[ |
769 |
img bitsPerSample:#[8 8 8]. |
|
770 |
img samplesPerPixel:3. |
|
771 |
img photometric:#rgb. |
|
772 |
] ifFalse:[ |
|
773 |
depth == 16 ifTrue:[ |
|
774 |
"/ to be determined... |
|
775 |
img bitsPerSample:#[5 5 5]. |
|
776 |
img samplesPerPixel:3. |
|
777 |
img photometric:#rgb. |
|
778 |
]. |
|
779 |
]. |
|
21452 | 780 |
^ img |
21580 | 781 |
|
782 |
" |
|
783 |
self getFrameBufferImage:0 in:nil |
|
784 |
self getFrameBufferImage:0 in:(100@100 corner:301@303) |
|
21598 | 785 |
|
786 |
Delay waitFor:3 seconds. self getFrameBufferImage:0 in:nil |
|
21580 | 787 |
" |
788 |
||
789 |
"Created: / 25-02-2017 / 09:49:07 / cg" |
|
21598 | 790 |
"Modified (comment): / 28-02-2017 / 15:22:17 / cg" |
21625 | 791 |
! |
792 |
||
793 |
screenBounds:displayNr |
|
794 |
"returns the bounds of the screen. |
|
795 |
This is needed, because the dimension of the XQuartz screen does not include the dock." |
|
796 |
||
797 |
|rx ry rwidth rheight| |
|
798 |
||
799 |
%{ |
|
800 |
#ifndef NO_COCOA |
|
801 |
CGDirectDisplayID targetDisplay = 0; |
|
802 |
||
803 |
rx = ry = __MKSMALLINT(0); |
|
804 |
rwidth = __MKUINT( CGDisplayPixelsWide(targetDisplay) ); |
|
805 |
rheight = __MKUINT( CGDisplayPixelsHigh(targetDisplay) ); |
|
806 |
#endif // NO_COCOA |
|
807 |
%}. |
|
808 |
(rwidth isNil) ifTrue:[ |
|
809 |
^ self primitiveFailed |
|
810 |
]. |
|
811 |
^ rx@ry extent:(rwidth@rheight) |
|
812 |
||
813 |
" |
|
814 |
self screenBounds:0 |
|
815 |
" |
|
816 |
||
817 |
"Created: / 05-03-2017 / 11:10:08 / cg" |
|
21452 | 818 |
! ! |
819 |
||
14819 | 820 |
!OSXOperatingSystem class methodsFor:'documentation'! |
821 |
||
822 |
version |
|
19817 | 823 |
^ '$Header$' |
14819 | 824 |
! |
825 |
||
826 |
version_CVS |
|
19817 | 827 |
^ '$Header$' |
14819 | 828 |
! ! |
21598 | 829 |