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