OSXOperatingSystem.st
author Claus Gittinger <cg@exept.de>
Tue, 09 Jul 2019 20:55:17 +0200
changeset 24417 03b083548da2
parent 24378 c46855b3748f
child 24464 63a55c7a8813
permissions -rw-r--r--
#REFACTORING by exept class: Smalltalk class changed: #recursiveInstallAutoloadedClassesFrom:rememberIn:maxLevels:noAutoload:packageTop:showSplashInLevels: Transcript showCR:(... bindWith:...) -> Transcript showCR:... with:...
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
21452
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
     1
"
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
     2
 COPYRIGHT (c) 2013 by Claus Gittinger
21455
a657a28cab85 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21452
diff changeset
     3
	      All Rights Reserved
21452
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
     4
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
     5
 This software is furnished under a license and may be used
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
     6
 only in accordance with the terms of that license and with the
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
     8
 be provided or otherwise made available to, or used by, any
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
     9
 other person.  No title to or ownership of the software is
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
    10
 hereby transferred.
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
    11
"
17471
98c49f19bae1 class: OSXOperatingSystem
Claus Gittinger <cg@exept.de>
parents: 17428
diff changeset
    12
"{ Package: 'stx:libbasic' }"
98c49f19bae1 class: OSXOperatingSystem
Claus Gittinger <cg@exept.de>
parents: 17428
diff changeset
    13
98c49f19bae1 class: OSXOperatingSystem
Claus Gittinger <cg@exept.de>
parents: 17428
diff changeset
    14
"{ NameSpace: Smalltalk }"
14819
ff6be3d27a81 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    15
17471
98c49f19bae1 class: OSXOperatingSystem
Claus Gittinger <cg@exept.de>
parents: 17428
diff changeset
    16
UnixOperatingSystem subclass:#OSXOperatingSystem
98c49f19bae1 class: OSXOperatingSystem
Claus Gittinger <cg@exept.de>
parents: 17428
diff changeset
    17
	instanceVariableNames:''
21587
3ac571f08fbf hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents: 21585
diff changeset
    18
	classVariableNames:'NSApp'
17471
98c49f19bae1 class: OSXOperatingSystem
Claus Gittinger <cg@exept.de>
parents: 17428
diff changeset
    19
	poolDictionaries:''
98c49f19bae1 class: OSXOperatingSystem
Claus Gittinger <cg@exept.de>
parents: 17428
diff changeset
    20
	category:'OS-Unix'
98c49f19bae1 class: OSXOperatingSystem
Claus Gittinger <cg@exept.de>
parents: 17428
diff changeset
    21
!
98c49f19bae1 class: OSXOperatingSystem
Claus Gittinger <cg@exept.de>
parents: 17428
diff changeset
    22
21452
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
    23
!OSXOperatingSystem primitiveDefinitions!
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
    24
%{
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
    25
22491
e3e465028518 string.h handling (OSX)
Claus Gittinger <cg@exept.de>
parents: 21731
diff changeset
    26
#ifdef __osx__
e3e465028518 string.h handling (OSX)
Claus Gittinger <cg@exept.de>
parents: 21731
diff changeset
    27
// mhm - how could they forget this????
e3e465028518 string.h handling (OSX)
Claus Gittinger <cg@exept.de>
parents: 21731
diff changeset
    28
# ifndef __XPC_IOS_SIMULATOR_AVAILABLE_STARTING
e3e465028518 string.h handling (OSX)
Claus Gittinger <cg@exept.de>
parents: 21731
diff changeset
    29
#  define __XPC_IOS_SIMULATOR_AVAILABLE_STARTING(version)
e3e465028518 string.h handling (OSX)
Claus Gittinger <cg@exept.de>
parents: 21731
diff changeset
    30
# endif
e3e465028518 string.h handling (OSX)
Claus Gittinger <cg@exept.de>
parents: 21731
diff changeset
    31
#endif
e3e465028518 string.h handling (OSX)
Claus Gittinger <cg@exept.de>
parents: 21731
diff changeset
    32
e3e465028518 string.h handling (OSX)
Claus Gittinger <cg@exept.de>
parents: 21731
diff changeset
    33
#ifndef __osx__
21452
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
    34
# define NO_QUARTZ
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
    35
# define NO_COCOA
22959
a88673d40f15 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22833
diff changeset
    36
# define NO_CARBON
24047
df6ad32114b1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 24028
diff changeset
    37
# define NO_COREGRAPHICS
21452
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
    38
#endif
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
    39
22833
60d71a4c5600 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 22655
diff changeset
    40
// #include <mach/clock.h>
60d71a4c5600 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 22655
diff changeset
    41
// #include <mach/mach.h>
60d71a4c5600 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 22655
diff changeset
    42
// #include <sys/time.h>
60d71a4c5600 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 22655
diff changeset
    43
// #include <mach/clock.h>
60d71a4c5600 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 22655
diff changeset
    44
21452
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
    45
#ifndef NO_COCOA
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
    46
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
    47
#   undef Array
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
    48
#   undef Number
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
    49
#   undef Method
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
    50
#   undef Point
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
    51
#   undef Rectangle
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
    52
#   undef Block
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
    53
#   undef String
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
    54
#   undef Character
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
    55
#   undef Message
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
    56
#   undef Object
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
    57
#   undef Context
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
    58
#   undef Time
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
    59
#   undef Date
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
    60
#   undef Set
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
    61
#   undef Signal
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
    62
#   undef Delay
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
    63
#   undef NameSpace
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
    64
#   undef Process
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
    65
#   undef Processor
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
    66
#   undef Class
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
    67
#   undef FixedPoint
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
    68
#   undef true
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
    69
#   undef false
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
    70
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
    71
#   undef INT
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
    72
#   undef UINT
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
    73
22491
e3e465028518 string.h handling (OSX)
Claus Gittinger <cg@exept.de>
parents: 21731
diff changeset
    74
# include <ApplicationServices/ApplicationServices.h>
e3e465028518 string.h handling (OSX)
Claus Gittinger <cg@exept.de>
parents: 21731
diff changeset
    75
# include <CoreFoundation/CoreFoundation.h>
21452
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
    76
// #include <Foundation/Foundation.h>
24047
df6ad32114b1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 24028
diff changeset
    77
# include <CoreGraphics/CGGeometry.h>
21595
10b14f01369b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21594
diff changeset
    78
10b14f01369b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21594
diff changeset
    79
// #include <CoreGraphics/CGEventTypes.h>
21452
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
    80
22491
e3e465028518 string.h handling (OSX)
Claus Gittinger <cg@exept.de>
parents: 21731
diff changeset
    81
# include <stdlib.h>
e3e465028518 string.h handling (OSX)
Claus Gittinger <cg@exept.de>
parents: 21731
diff changeset
    82
# include <stdio.h>
e3e465028518 string.h handling (OSX)
Claus Gittinger <cg@exept.de>
parents: 21731
diff changeset
    83
# include <IOKit/graphics/IOGraphicsLib.h>
21452
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
    84
22491
e3e465028518 string.h handling (OSX)
Claus Gittinger <cg@exept.de>
parents: 21731
diff changeset
    85
# include <objc/runtime.h>
e3e465028518 string.h handling (OSX)
Claus Gittinger <cg@exept.de>
parents: 21731
diff changeset
    86
# include <objc/message.h>
21452
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
    87
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
    88
#  ifdef __DEF_Array
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
    89
#   define Array __DEF_Array
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
    90
#  endif
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
    91
#  ifdef __DEF_Number
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
    92
#   define Number __DEF_Number
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
    93
#  endif
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
    94
#  ifdef __DEF_Method
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
    95
#   define Method __DEF_Method
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
    96
#  endif
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
    97
#  ifdef __DEF_Point
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
    98
#   define Point __DEF_Point
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
    99
#  endif
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   100
#  ifdef __DEF_Rectangle
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   101
#   define Rectangle __DEF_Rectangle
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   102
#  endif
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   103
#  ifdef __DEF_Block
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   104
#   define Block __DEF_Block
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   105
#  endif
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   106
#  ifdef __DEF_String
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   107
#   define String __DEF_String
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   108
#  endif
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   109
#  ifdef __DEF_Character
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   110
#   define Character __DEF_Character
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   111
#  endif
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   112
#  ifdef __DEF_Message
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   113
#   define Message __DEF_Message
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   114
#  endif
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   115
#  ifdef __DEF_Object
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   116
#   define Object __DEF_Object
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   117
#  endif
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   118
#  ifdef __DEF_Context
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   119
#   define Context __DEF_Context
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   120
#  endif
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   121
#  ifdef __DEF_Date
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   122
#   define Date __DEF_Date
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   123
#  endif
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   124
#  ifdef __DEF_Time
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   125
#   define Time __DEF_Time
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   126
#  endif
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   127
#  ifdef __DEF_Set
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   128
#   define Set __DEF_Set
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   129
#  endif
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   130
#  ifdef __DEF_Signal
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   131
#   define Signal __DEF_Signal
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   132
#  endif
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   133
#  ifdef __DEF_Delay
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   134
#   define Delay __DEF_Delay
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   135
#  endif
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   136
#  ifdef __DEF_NameSpace
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   137
#   define NameSpace __DEF_NameSpace
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   138
#  endif
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   139
#  ifdef __DEF_Process
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   140
#   define Process __DEF_Process
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   141
#  endif
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   142
#  ifdef __DEF_Processor
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   143
#   define Processor __DEF_Processor
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   144
#  endif
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   145
#  ifdef __DEF_Class
21587
3ac571f08fbf hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents: 21585
diff changeset
   146
#   define STX_Class __DEF_Class
21452
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   147
#  endif
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   148
#  ifdef __DEF_FixedPoint
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   149
#   define FixedPoint __DEF_FixedPoint
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   150
#  endif
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   151
#  ifdef __DEF_true
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   152
#   undef true
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   153
#   define true __DEF_true
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   154
#  endif
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   155
#  ifdef __DEF_false
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   156
#   undef false
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   157
#   define false __DEF_false
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   158
#  endif
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   159
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   160
#  define INT STX_INT
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   161
#  define UINT STX_UINT
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   162
21587
3ac571f08fbf hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents: 21585
diff changeset
   163
typedef struct CMPoint {
3ac571f08fbf hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents: 21585
diff changeset
   164
	double x;
3ac571f08fbf hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents: 21585
diff changeset
   165
	double y;
3ac571f08fbf hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents: 21585
diff changeset
   166
} CMPoint;
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
typedef struct CMSize {
3ac571f08fbf hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents: 21585
diff changeset
   169
	double width;
3ac571f08fbf hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents: 21585
diff changeset
   170
	double height;
3ac571f08fbf hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents: 21585
diff changeset
   171
} CMSize;
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
typedef struct CMRect {
3ac571f08fbf hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents: 21585
diff changeset
   174
	CMPoint origin;
3ac571f08fbf hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents: 21585
diff changeset
   175
	CMSize size;
3ac571f08fbf hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents: 21585
diff changeset
   176
} CMRect;
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
typedef struct AppDel {
3ac571f08fbf hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents: 21585
diff changeset
   179
	Class isa;
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
	// Will be an NSWindow later.
3ac571f08fbf hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents: 21585
diff changeset
   182
	id window;
3ac571f08fbf hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents: 21585
diff changeset
   183
} AppDelegate;
3ac571f08fbf hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents: 21585
diff changeset
   184
3ac571f08fbf hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents: 21585
diff changeset
   185
3ac571f08fbf hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents: 21585
diff changeset
   186
enum {
3ac571f08fbf hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents: 21585
diff changeset
   187
	NSBorderlessWindowMask          = 0,
3ac571f08fbf hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents: 21585
diff changeset
   188
	NSTitledWindowMask                      = 1 << 0,
3ac571f08fbf hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents: 21585
diff changeset
   189
	NSClosableWindowMask            = 1 << 1,
3ac571f08fbf hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents: 21585
diff changeset
   190
	NSMiniaturizableWindowMask      = 1 << 2,
3ac571f08fbf hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents: 21585
diff changeset
   191
	NSResizableWindowMask           = 1 << 3,
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
3ac571f08fbf hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents: 21585
diff changeset
   194
typedef id(*CMacsSimpleMessage)(id, SEL);
3ac571f08fbf hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents: 21585
diff changeset
   195
typedef void(*CMacsVoidMessage)(id, SEL);
3ac571f08fbf hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents: 21585
diff changeset
   196
typedef void(*CMacsVoidMessage1)(id, SEL, void *);
3ac571f08fbf hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents: 21585
diff changeset
   197
typedef id(*CMacsRectMessage1)(id, SEL, CMRect);
3ac571f08fbf hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents: 21585
diff changeset
   198
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
   199
3ac571f08fbf hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents: 21585
diff changeset
   200
extern CMacsSimpleMessage cmacs_simple_msgSend;
3ac571f08fbf hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents: 21585
diff changeset
   201
extern CMacsVoidMessage cmacs_void_msgSend;
3ac571f08fbf hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents: 21585
diff changeset
   202
extern CMacsVoidMessage1 cmacs_void_msgSend1;
3ac571f08fbf hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents: 21585
diff changeset
   203
extern CMacsRectMessage1 cmacs_rect_msgSend1;
3ac571f08fbf hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents: 21585
diff changeset
   204
extern CMacsWindowInitMessage cmacs_window_init_msgSend;
3ac571f08fbf hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents: 21585
diff changeset
   205
3ac571f08fbf hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents: 21585
diff changeset
   206
#endif // NO_COCOA
21452
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   207
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   208
%}
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   209
! !
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   210
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   211
!OSXOperatingSystem primitiveFunctions!
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   212
%{
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   213
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   214
#ifndef NO_COCOA
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   215
24047
df6ad32114b1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 24028
diff changeset
   216
struct ev {
df6ad32114b1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 24028
diff changeset
   217
    struct ev* nextEvent;
df6ad32114b1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 24028
diff changeset
   218
    CGEventType type;
df6ad32114b1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 24028
diff changeset
   219
    CGKeyCode keycode;
df6ad32114b1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 24028
diff changeset
   220
    int x,y;
df6ad32114b1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 24028
diff changeset
   221
    int button;
df6ad32114b1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 24028
diff changeset
   222
};
df6ad32114b1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 24028
diff changeset
   223
static struct ev *nextRecordedEvent = NULL;
df6ad32114b1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 24028
diff changeset
   224
static struct ev *lastRecordedEvent = NULL;
df6ad32114b1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 24028
diff changeset
   225
21452
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   226
CGEventRef
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   227
myCGEventCallback(CGEventTapProxy proxy, CGEventType type,
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   228
		  CGEventRef event, void *refcon)
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   229
{
24047
df6ad32114b1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 24028
diff changeset
   230
    if ((type == kCGEventKeyDown) || (type == kCGEventKeyUp)) {
df6ad32114b1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 24028
diff changeset
   231
	// The incoming keycode.
df6ad32114b1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 24028
diff changeset
   232
	CGKeyCode keycode = (CGKeyCode)CGEventGetIntegerValueField(event, kCGKeyboardEventKeycode);
df6ad32114b1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 24028
diff changeset
   233
    }
df6ad32114b1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 24028
diff changeset
   234
    if (type == kCGEventMouseMoved) {
df6ad32114b1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 24028
diff changeset
   235
	// loc = [NSEvent mouseLocation]
df6ad32114b1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 24028
diff changeset
   236
	// int x = loc.x;
df6ad32114b1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 24028
diff changeset
   237
	// int y = loc.y;
df6ad32114b1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 24028
diff changeset
   238
    }
21452
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   239
    // We must return the event for it to be useful.
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   240
    return event;
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   241
}
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   242
21587
3ac571f08fbf hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents: 21585
diff changeset
   243
BOOL
3ac571f08fbf hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents: 21585
diff changeset
   244
AppDel_didFinishLaunching(AppDelegate *self, SEL _cmd, id notification) {
3ac571f08fbf hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents: 21585
diff changeset
   245
//    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
   246
//
3ac571f08fbf hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents: 21585
diff changeset
   247
//    /// Create an instance of the window.
3ac571f08fbf hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents: 21585
diff changeset
   248
//    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
   249
//
3ac571f08fbf hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents: 21585
diff changeset
   250
//    /// Create an instance of our view class.
3ac571f08fbf hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents: 21585
diff changeset
   251
//    ///
3ac571f08fbf hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents: 21585
diff changeset
   252
//    /// 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
   253
//    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
   254
//
3ac571f08fbf hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents: 21585
diff changeset
   255
//    // 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
   256
//    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
   257
//    cmacs_simple_msgSend(self->window, sel_getUid("becomeFirstResponder"));
3ac571f08fbf hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents: 21585
diff changeset
   258
//
3ac571f08fbf hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents: 21585
diff changeset
   259
//    // 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
   260
//    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
   261
    return YES;
3ac571f08fbf hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents: 21585
diff changeset
   262
}
3ac571f08fbf hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents: 21585
diff changeset
   263
21452
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   264
#endif // NO_COCOA
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   265
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   266
%}
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   267
! !
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   268
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   269
!OSXOperatingSystem class methodsFor:'documentation'!
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   270
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   271
copyright
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   272
"
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   273
 COPYRIGHT (c) 2013 by Claus Gittinger
21455
a657a28cab85 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21452
diff changeset
   274
	      All Rights Reserved
21452
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   275
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   276
 This software is furnished under a license and may be used
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   277
 only in accordance with the terms of that license and with the
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   278
 inclusion of the above copyright notice.   This software may not
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   279
 be provided or otherwise made available to, or used by, any
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   280
 other person.  No title to or ownership of the software is
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   281
 hereby transferred.
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   282
"
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   283
!
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   284
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   285
documentation
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   286
"
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   287
    a small number of OS-X specific redefinitions here.
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   288
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   289
    [Author:]
21455
a657a28cab85 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21452
diff changeset
   290
	Claus Gittinger
21452
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   291
"
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   292
! !
17471
98c49f19bae1 class: OSXOperatingSystem
Claus Gittinger <cg@exept.de>
parents: 17428
diff changeset
   293
98c49f19bae1 class: OSXOperatingSystem
Claus Gittinger <cg@exept.de>
parents: 17428
diff changeset
   294
!OSXOperatingSystem class methodsFor:'initialization'!
98c49f19bae1 class: OSXOperatingSystem
Claus Gittinger <cg@exept.de>
parents: 17428
diff changeset
   295
98c49f19bae1 class: OSXOperatingSystem
Claus Gittinger <cg@exept.de>
parents: 17428
diff changeset
   296
initializeCodeset
98c49f19bae1 class: OSXOperatingSystem
Claus Gittinger <cg@exept.de>
parents: 17428
diff changeset
   297
    super initializeCodeset.
17493
25361a7bc7e7 class: OSXOperatingSystem
Claus Gittinger <cg@exept.de>
parents: 17471
diff changeset
   298
    Codeset := #'utf8-mac'.
17494
4734c3c6fe43 class: OSXOperatingSystem
Claus Gittinger <cg@exept.de>
parents: 17493
diff changeset
   299
    CodesetEncoder := nil.
17471
98c49f19bae1 class: OSXOperatingSystem
Claus Gittinger <cg@exept.de>
parents: 17428
diff changeset
   300
! !
14819
ff6be3d27a81 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   301
21452
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   302
!OSXOperatingSystem class methodsFor:'cocoa - events'!
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   303
21591
c89611bc4b5c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21587
diff changeset
   304
finishLaunching
c89611bc4b5c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21587
diff changeset
   305
    "tell the system, that I have finished my startup phase.
c89611bc4b5c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21587
diff changeset
   306
     OSX will stop bounding the launch icon then."
21596
ce0a09d20d18 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21595
diff changeset
   307
21591
c89611bc4b5c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21587
diff changeset
   308
    NSApp isNil ifTrue:[
21596
ce0a09d20d18 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21595
diff changeset
   309
	self getNSApp
21591
c89611bc4b5c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21587
diff changeset
   310
    ].
c89611bc4b5c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21587
diff changeset
   311
%{
c89611bc4b5c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21587
diff changeset
   312
#ifndef NO_COCOA
c89611bc4b5c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21587
diff changeset
   313
    id NSApp = __externalAddressVal(@global(NSApp));
24339
d1a2b7e3fb5e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 24095
diff changeset
   314
    extern int __stxNSAppIsRunning();
21591
c89611bc4b5c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21587
diff changeset
   315
24339
d1a2b7e3fb5e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 24095
diff changeset
   316
    if (!__stxNSAppIsRunning()) {
24095
ef0a44d99ecf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 24069
diff changeset
   317
	objc_msgSend(NSApp, sel_getUid("finishLaunching"));
ef0a44d99ecf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 24069
diff changeset
   318
    }
21591
c89611bc4b5c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21587
diff changeset
   319
    RETURN(self);
c89611bc4b5c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21587
diff changeset
   320
#endif // NO_COCOA
c89611bc4b5c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21587
diff changeset
   321
%}.
c89611bc4b5c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21587
diff changeset
   322
    "/ if compiled without COCOA support (which you should not),
c89611bc4b5c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21587
diff changeset
   323
    "/ the icon will probably continue to bounce...
c89611bc4b5c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21587
diff changeset
   324
    "/ ... but we do not want an error here.
21596
ce0a09d20d18 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21595
diff changeset
   325
21591
c89611bc4b5c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21587
diff changeset
   326
    "/ self primitiveFailed
c89611bc4b5c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21587
diff changeset
   327
c89611bc4b5c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21587
diff changeset
   328
    "
c89611bc4b5c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21587
diff changeset
   329
     self finishLaunching
c89611bc4b5c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21587
diff changeset
   330
    "
c89611bc4b5c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21587
diff changeset
   331
c89611bc4b5c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21587
diff changeset
   332
    "Modified: / 28-02-2017 / 10:59:15 / cg"
c89611bc4b5c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21587
diff changeset
   333
!
c89611bc4b5c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21587
diff changeset
   334
21587
3ac571f08fbf hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents: 21585
diff changeset
   335
generateButtonEvent:button down:down x:screenX y:screenY
3ac571f08fbf hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents: 21585
diff changeset
   336
    "synthesize and send a button event to the screen"
21584
6a39bcb8636b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21582
diff changeset
   337
%{
6a39bcb8636b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21582
diff changeset
   338
#ifndef NO_COCOA
21587
3ac571f08fbf hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents: 21585
diff changeset
   339
    if (__bothSmallInteger(screenX, screenY)
21584
6a39bcb8636b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21582
diff changeset
   340
     && __isSmallInteger(button)) {
21587
3ac571f08fbf hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents: 21585
diff changeset
   341
	CGPoint pt;
3ac571f08fbf hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents: 21585
diff changeset
   342
	pt.x = __intVal(screenX);
3ac571f08fbf hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents: 21585
diff changeset
   343
	pt.y = __intVal(screenY);
3ac571f08fbf hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents: 21585
diff changeset
   344
3ac571f08fbf hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents: 21585
diff changeset
   345
	CGEventType evType;
3ac571f08fbf hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents: 21585
diff changeset
   346
	CGMouseButton evButton = __intVal(button);
21584
6a39bcb8636b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21582
diff changeset
   347
21587
3ac571f08fbf hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents: 21585
diff changeset
   348
	switch (evButton) {
3ac571f08fbf hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents: 21585
diff changeset
   349
	    case 1:
3ac571f08fbf hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents: 21585
diff changeset
   350
		evType = (down == true) ? kCGEventLeftMouseDown : kCGEventLeftMouseUp;
3ac571f08fbf hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents: 21585
diff changeset
   351
		evButton = 0;
3ac571f08fbf hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents: 21585
diff changeset
   352
		break;
3ac571f08fbf hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents: 21585
diff changeset
   353
	    case 2:
3ac571f08fbf hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents: 21585
diff changeset
   354
		evType = (down == true) ? kCGEventRightMouseDown : kCGEventRightMouseUp;
3ac571f08fbf hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents: 21585
diff changeset
   355
		evButton = 1;
3ac571f08fbf hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents: 21585
diff changeset
   356
		break;
3ac571f08fbf hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents: 21585
diff changeset
   357
	    case 3:
3ac571f08fbf hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents: 21585
diff changeset
   358
		evType = (down == true) ? kCGEventOtherMouseDown : kCGEventOtherMouseUp;
3ac571f08fbf hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents: 21585
diff changeset
   359
		evButton = 2;
3ac571f08fbf hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents: 21585
diff changeset
   360
		break;
3ac571f08fbf hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents: 21585
diff changeset
   361
	    default:
3ac571f08fbf hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents: 21585
diff changeset
   362
		evType = (down == true) ? kCGEventOtherMouseDown : kCGEventOtherMouseUp;
3ac571f08fbf hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents: 21585
diff changeset
   363
		evButton = __intVal(button) - 1;
3ac571f08fbf hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents: 21585
diff changeset
   364
		break;
3ac571f08fbf hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents: 21585
diff changeset
   365
	}
3ac571f08fbf hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents: 21585
diff changeset
   366
3ac571f08fbf hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents: 21585
diff changeset
   367
	CGEventRef theEvent = CGEventCreateMouseEvent(NULL, evType, pt, evButton);
3ac571f08fbf hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents: 21585
diff changeset
   368
	CGEventSetType(theEvent, evType);
3ac571f08fbf hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents: 21585
diff changeset
   369
	CGEventPost(kCGHIDEventTap, theEvent);
3ac571f08fbf hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents: 21585
diff changeset
   370
	CFRelease(theEvent);
3ac571f08fbf hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents: 21585
diff changeset
   371
	RETURN(self);
21584
6a39bcb8636b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21582
diff changeset
   372
    }
6a39bcb8636b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21582
diff changeset
   373
#endif // NO_COCOA
6a39bcb8636b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21582
diff changeset
   374
%}.
6a39bcb8636b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21582
diff changeset
   375
    self primitiveFailed
6a39bcb8636b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21582
diff changeset
   376
6a39bcb8636b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21582
diff changeset
   377
    "
6a39bcb8636b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21582
diff changeset
   378
     OperatingSystem generateButtonEvent:1 down:true x:150 y:150.
6a39bcb8636b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21582
diff changeset
   379
     OperatingSystem generateButtonEvent:1 down:false x:150 y:150.
6a39bcb8636b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21582
diff changeset
   380
6a39bcb8636b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21582
diff changeset
   381
     OperatingSystem generateButtonEvent:2 down:true x:150 y:150.
6a39bcb8636b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21582
diff changeset
   382
     OperatingSystem generateButtonEvent:2 down:false x:150 y:150.
6a39bcb8636b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21582
diff changeset
   383
    "
6a39bcb8636b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21582
diff changeset
   384
6a39bcb8636b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21582
diff changeset
   385
    "Created: / 28-02-2017 / 00:15:18 / cg"
6a39bcb8636b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21582
diff changeset
   386
!
6a39bcb8636b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21582
diff changeset
   387
21621
0712ebc6d6cf #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21598
diff changeset
   388
generateKeyboardEvent:keyCode down:down
0712ebc6d6cf #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21598
diff changeset
   389
    "synthesize and send a keyboard event to the screen"
0712ebc6d6cf #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21598
diff changeset
   390
%{
0712ebc6d6cf #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21598
diff changeset
   391
#ifndef NO_COCOA
0712ebc6d6cf #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21598
diff changeset
   392
    if (__isSmallInteger(keyCode)) {
21627
213250371878 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21625
diff changeset
   393
	int evType;
213250371878 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21625
diff changeset
   394
213250371878 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21625
diff changeset
   395
	CGEventRef theEvent = CGEventCreateKeyboardEvent(NULL, __intVal(keyCode), (down==true)?1:0);
213250371878 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21625
diff changeset
   396
	CGEventSetType(theEvent, (down==true) ? kCGEventKeyDown:kCGEventKeyUp);
213250371878 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21625
diff changeset
   397
	CGEventPost(kCGHIDEventTap, theEvent);
213250371878 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21625
diff changeset
   398
	CFRelease(theEvent);
213250371878 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21625
diff changeset
   399
	RETURN(self);
21621
0712ebc6d6cf #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21598
diff changeset
   400
    }
0712ebc6d6cf #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21598
diff changeset
   401
#endif // NO_COCOA
0712ebc6d6cf #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21598
diff changeset
   402
%}.
0712ebc6d6cf #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21598
diff changeset
   403
    self primitiveFailed
0712ebc6d6cf #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21598
diff changeset
   404
0712ebc6d6cf #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21598
diff changeset
   405
    "
0712ebc6d6cf #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21598
diff changeset
   406
     OperatingSystem generateKeyboardEvent:6 down:true.
0712ebc6d6cf #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21598
diff changeset
   407
     OperatingSystem generateKeyboardEvent:6 down:false.
0712ebc6d6cf #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21598
diff changeset
   408
    "
0712ebc6d6cf #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21598
diff changeset
   409
0712ebc6d6cf #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21598
diff changeset
   410
    "Created: / 02-03-2017 / 16:35:04 / cg"
0712ebc6d6cf #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21598
diff changeset
   411
!
0712ebc6d6cf #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21598
diff changeset
   412
0712ebc6d6cf #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21598
diff changeset
   413
generateMouseMoveEventX:screenX y:screenY
24047
df6ad32114b1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 24028
diff changeset
   414
    "synthesize and send a mouse move event to the screen"
21621
0712ebc6d6cf #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21598
diff changeset
   415
%{
0712ebc6d6cf #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21598
diff changeset
   416
#ifndef NO_COCOA
0712ebc6d6cf #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21598
diff changeset
   417
    if (__bothSmallInteger(screenX, screenY)) {
21627
213250371878 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21625
diff changeset
   418
	CGPoint pt;
213250371878 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21625
diff changeset
   419
	pt.x = __intVal(screenX);
213250371878 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21625
diff changeset
   420
	pt.y = __intVal(screenY);
21621
0712ebc6d6cf #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21598
diff changeset
   421
21627
213250371878 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21625
diff changeset
   422
	CGEventType evType;
213250371878 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21625
diff changeset
   423
	CGEventRef theEvent = CGEventCreateMouseEvent(NULL, kCGEventMouseMoved, pt, 0);
213250371878 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21625
diff changeset
   424
	CGEventSetType(theEvent, kCGEventMouseMoved);
213250371878 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21625
diff changeset
   425
	CGEventPost(kCGHIDEventTap, theEvent);
213250371878 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21625
diff changeset
   426
	CFRelease(theEvent);
213250371878 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21625
diff changeset
   427
	RETURN(self);
21621
0712ebc6d6cf #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21598
diff changeset
   428
    }
0712ebc6d6cf #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21598
diff changeset
   429
#endif // NO_COCOA
0712ebc6d6cf #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21598
diff changeset
   430
%}.
0712ebc6d6cf #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21598
diff changeset
   431
    self primitiveFailed
0712ebc6d6cf #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21598
diff changeset
   432
0712ebc6d6cf #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21598
diff changeset
   433
    "
0712ebc6d6cf #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21598
diff changeset
   434
     OperatingSystem generateMouseMoveEventX:150 y:5.
0712ebc6d6cf #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21598
diff changeset
   435
     Delay waitFor:(1 seconds).
0712ebc6d6cf #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21598
diff changeset
   436
     OperatingSystem generateMouseMoveEventX:1050 y:150.
0712ebc6d6cf #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21598
diff changeset
   437
    "
0712ebc6d6cf #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21598
diff changeset
   438
0712ebc6d6cf #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21598
diff changeset
   439
    "Created: / 02-03-2017 / 20:01:51 / cg"
0712ebc6d6cf #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21598
diff changeset
   440
!
0712ebc6d6cf #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21598
diff changeset
   441
21587
3ac571f08fbf hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents: 21585
diff changeset
   442
getNSApp
23114
21306b85ca30 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 22970
diff changeset
   443
    "get the NSApplication instance and remember in the global named NSApp"
21306b85ca30 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 22970
diff changeset
   444
21587
3ac571f08fbf hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents: 21585
diff changeset
   445
%{
3ac571f08fbf hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents: 21585
diff changeset
   446
#ifndef NO_COCOA
3ac571f08fbf hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents: 21585
diff changeset
   447
    Class AppDelClass = NULL;
3ac571f08fbf hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents: 21585
diff changeset
   448
    id NSApp = NULL;
3ac571f08fbf hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents: 21585
diff changeset
   449
21731
81d141fee490 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21627
diff changeset
   450
# if 0 /* not needed */
21597
4af9c6c70126 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21596
diff changeset
   451
    Class poolClass = objc_getClass("NSAutoreleasePool");
21594
acb127ad113c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21591
diff changeset
   452
    if (poolClass == NULL) {
21597
4af9c6c70126 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21596
diff changeset
   453
	fprintf(stderr, "OSX: Unable to get NSAutoreleasePool\n");
4af9c6c70126 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21596
diff changeset
   454
	RETURN(false);
21594
acb127ad113c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21591
diff changeset
   455
    }
acb127ad113c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21591
diff changeset
   456
    id pool = objc_msgSend(poolClass, sel_registerName("alloc"));
acb127ad113c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21591
diff changeset
   457
    if (pool == NULL) {
21597
4af9c6c70126 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21596
diff changeset
   458
	fprintf(stderr, "OSX: Unable to create NSAutoreleasePool\n");
4af9c6c70126 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21596
diff changeset
   459
	RETURN(false);
21594
acb127ad113c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21591
diff changeset
   460
    }
acb127ad113c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21591
diff changeset
   461
    objc_msgSend(pool, sel_registerName("init"));
21731
81d141fee490 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21627
diff changeset
   462
# endif
21594
acb127ad113c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21591
diff changeset
   463
21731
81d141fee490 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21627
diff changeset
   464
# if 0 /* not needed */
21587
3ac571f08fbf hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents: 21585
diff changeset
   465
    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
   466
    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
   467
    objc_registerClassPair(AppDelClass);
21731
81d141fee490 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21627
diff changeset
   468
# endif
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
    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
   471
    if (NSApp == NULL) {
21597
4af9c6c70126 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21596
diff changeset
   472
	fprintf(stderr,"OSX: Failed to initialize NSApplication\n");
4af9c6c70126 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21596
diff changeset
   473
	RETURN(false);
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
    @global(NSApp) = __MKEXTERNALADDRESS(NSApp);
3ac571f08fbf hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents: 21585
diff changeset
   476
24069
6f4f9e93ca51 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 24047
diff changeset
   477
# if 0 /* not needed */
21594
acb127ad113c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21591
diff changeset
   478
    id req = objc_msgSend(NSApp,sel_getUid("requestUserAttention:"),0);
acb127ad113c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21591
diff changeset
   479
    objc_msgSend(NSApp,sel_getUid("cancelUserAttentionRequest:"),req);
24069
6f4f9e93ca51 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 24047
diff changeset
   480
# endif
21587
3ac571f08fbf hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents: 21585
diff changeset
   481
21731
81d141fee490 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21627
diff changeset
   482
# if 0 /* not needed */
21594
acb127ad113c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21591
diff changeset
   483
    id appDelInst = objc_msgSend((id)objc_getClass("AppDelegate"), sel_getUid("alloc"));
acb127ad113c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21591
diff changeset
   484
    objc_msgSend(appDelInst, sel_getUid("init"));
acb127ad113c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21591
diff changeset
   485
    objc_msgSend(NSApp, sel_getUid("setDelegate:"), appDelInst);
21731
81d141fee490 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21627
diff changeset
   486
# endif
21594
acb127ad113c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21591
diff changeset
   487
21731
81d141fee490 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21627
diff changeset
   488
# if 0 /* not needed */
21594
acb127ad113c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21591
diff changeset
   489
    objc_msgSend(pool, sel_registerName("release"));
21731
81d141fee490 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21627
diff changeset
   490
# endif
21587
3ac571f08fbf hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents: 21585
diff changeset
   491
    RETURN(true);
3ac571f08fbf hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents: 21585
diff changeset
   492
#endif // NO_COCOA
3ac571f08fbf hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents: 21585
diff changeset
   493
%}.
3ac571f08fbf hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents: 21585
diff changeset
   494
    self primitiveFailed
3ac571f08fbf hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents: 21585
diff changeset
   495
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 getNSApp
3ac571f08fbf hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents: 21585
diff changeset
   498
    "
3ac571f08fbf hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents: 21585
diff changeset
   499
21594
acb127ad113c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21591
diff changeset
   500
    "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
   501
!
3ac571f08fbf hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents: 21585
diff changeset
   502
21591
c89611bc4b5c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21587
diff changeset
   503
receiveNextEvent
21587
3ac571f08fbf hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents: 21585
diff changeset
   504
%{
3ac571f08fbf hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents: 21585
diff changeset
   505
#ifndef NO_COCOA
21591
c89611bc4b5c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21587
diff changeset
   506
    CFMachPortRef      eventTap;
c89611bc4b5c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21587
diff changeset
   507
    CGEventMask        eventMask;
c89611bc4b5c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21587
diff changeset
   508
    CFRunLoopSourceRef runLoopSource;
21587
3ac571f08fbf hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents: 21585
diff changeset
   509
21591
c89611bc4b5c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21587
diff changeset
   510
    // Create an event tap. We are interested in key presses.
24047
df6ad32114b1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 24028
diff changeset
   511
    // sigh: a global event tap requires root privileges
df6ad32114b1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 24028
diff changeset
   512
    eventMask = ((1 << kCGEventKeyDown)
df6ad32114b1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 24028
diff changeset
   513
		| (1 << kCGEventKeyUp)
df6ad32114b1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 24028
diff changeset
   514
		| (1 << kCGEventMouseMoved));
21591
c89611bc4b5c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21587
diff changeset
   515
    eventTap = CGEventTapCreate(kCGSessionEventTap, kCGHeadInsertEventTap, 0,
c89611bc4b5c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21587
diff changeset
   516
				eventMask, NULL, myCGEventCallback);
c89611bc4b5c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21587
diff changeset
   517
    if (!eventTap) {
c89611bc4b5c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21587
diff changeset
   518
	fprintf(stderr, "failed to create event tap\n");
c89611bc4b5c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21587
diff changeset
   519
    } else {
c89611bc4b5c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21587
diff changeset
   520
	fprintf(stderr, "ok\n");
c89611bc4b5c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21587
diff changeset
   521
c89611bc4b5c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21587
diff changeset
   522
	// Create a run loop source.
c89611bc4b5c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21587
diff changeset
   523
	runLoopSource = CFMachPortCreateRunLoopSource( kCFAllocatorDefault, eventTap, 0);
c89611bc4b5c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21587
diff changeset
   524
	// Enable the event tap.
c89611bc4b5c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21587
diff changeset
   525
	CGEventTapEnable(eventTap, true);
c89611bc4b5c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21587
diff changeset
   526
    }
c89611bc4b5c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21587
diff changeset
   527
21587
3ac571f08fbf hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents: 21585
diff changeset
   528
#endif // NO_COCOA
3ac571f08fbf hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents: 21585
diff changeset
   529
%}.
3ac571f08fbf hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents: 21585
diff changeset
   530
    self primitiveFailed
3ac571f08fbf hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents: 21585
diff changeset
   531
21591
c89611bc4b5c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21587
diff changeset
   532
    "Modified: / 28-02-2017 / 01:05:04 / cg"
21452
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   533
! !
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   534
17297
a56ba300949c Overriden openApplicationForDocument... to use desktop-specific "open" command.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17179
diff changeset
   535
!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
   536
22655
bf2c170bc0f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22491
diff changeset
   537
openApplicationForDocument:aFilenameOrString operation:operationSymbol
bf2c170bc0f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22491
diff changeset
   538
    "open a windows-shell/mac finder/desktop application to present the document contained in aFilenameOrString.
bf2c170bc0f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22491
diff changeset
   539
     This is typically used to present help-files, html documents, pdf documents etc.
bf2c170bc0f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22491
diff changeset
   540
     operationSymbol is one of:
22833
60d71a4c5600 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 22655
diff changeset
   541
	open
60d71a4c5600 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 22655
diff changeset
   542
	edit
60d71a4c5600 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 22655
diff changeset
   543
	explore
22655
bf2c170bc0f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22491
diff changeset
   544
    "
bf2c170bc0f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22491
diff changeset
   545
bf2c170bc0f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22491
diff changeset
   546
    |openCmd|
bf2c170bc0f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22491
diff changeset
   547
bf2c170bc0f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22491
diff changeset
   548
    (openCmd := self openApplicationHelperCommand) notNil ifTrue:[
22833
60d71a4c5600 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 22655
diff changeset
   549
	(operationSymbol = 'open') ifTrue:[
60d71a4c5600 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 22655
diff changeset
   550
	    self executeCommand:'open "',aFilenameOrString asFilename pathName,'"'
60d71a4c5600 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 22655
diff changeset
   551
	] ifFalse:[
60d71a4c5600 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 22655
diff changeset
   552
	    (operationSymbol = 'explore') ifTrue:[
60d71a4c5600 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 22655
diff changeset
   553
		self executeCommand:'open -R "',aFilenameOrString asFilename pathName,'"'
60d71a4c5600 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 22655
diff changeset
   554
	    ].
60d71a4c5600 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 22655
diff changeset
   555
	].
22655
bf2c170bc0f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22491
diff changeset
   556
    ].
bf2c170bc0f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22491
diff changeset
   557
!
bf2c170bc0f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22491
diff changeset
   558
17297
a56ba300949c Overriden openApplicationForDocument... to use desktop-specific "open" command.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17179
diff changeset
   559
openApplicationHelperCommand
a56ba300949c Overriden openApplicationForDocument... to use desktop-specific "open" command.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17179
diff changeset
   560
    "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
   561
18279
6d7174763909 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 17494
diff changeset
   562
    (self canExecuteCommand: 'open') ifTrue:[
6d7174763909 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 17494
diff changeset
   563
	^ 'open'
17297
a56ba300949c Overriden openApplicationForDocument... to use desktop-specific "open" command.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17179
diff changeset
   564
    ].
a56ba300949c Overriden openApplicationForDocument... to use desktop-specific "open" command.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17179
diff changeset
   565
    ^ nil
a56ba300949c Overriden openApplicationForDocument... to use desktop-specific "open" command.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17179
diff changeset
   566
a56ba300949c Overriden openApplicationForDocument... to use desktop-specific "open" command.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17179
diff changeset
   567
    "Created: / 13-01-2015 / 09:23:18 / Jan Vrany <jan.vrany@fit.cvut.cz>"
17427
1ee32c4f30e9 class: OSXOperatingSystem
Claus Gittinger <cg@exept.de>
parents: 17297
diff changeset
   568
!
1ee32c4f30e9 class: OSXOperatingSystem
Claus Gittinger <cg@exept.de>
parents: 17297
diff changeset
   569
17428
831e25b68d2c class: OSXOperatingSystem
Claus Gittinger <cg@exept.de>
parents: 17427
diff changeset
   570
openTerminalWithCommand:shellCommand inBackground:inBackground
17427
1ee32c4f30e9 class: OSXOperatingSystem
Claus Gittinger <cg@exept.de>
parents: 17297
diff changeset
   571
    "open a new terminal, which executes a command"
1ee32c4f30e9 class: OSXOperatingSystem
Claus Gittinger <cg@exept.de>
parents: 17297
diff changeset
   572
17428
831e25b68d2c class: OSXOperatingSystem
Claus Gittinger <cg@exept.de>
parents: 17427
diff changeset
   573
    |cmd|
831e25b68d2c class: OSXOperatingSystem
Claus Gittinger <cg@exept.de>
parents: 17427
diff changeset
   574
831e25b68d2c class: OSXOperatingSystem
Claus Gittinger <cg@exept.de>
parents: 17427
diff changeset
   575
    cmd := 'osascript -e ''tell application "Terminal" to do script "%1"''' bindWith:shellCommand.
831e25b68d2c class: OSXOperatingSystem
Claus Gittinger <cg@exept.de>
parents: 17427
diff changeset
   576
831e25b68d2c class: OSXOperatingSystem
Claus Gittinger <cg@exept.de>
parents: 17427
diff changeset
   577
    inBackground ifTrue:[
18279
6d7174763909 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 17494
diff changeset
   578
	^ self
6d7174763909 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 17494
diff changeset
   579
	    startProcess:cmd
6d7174763909 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 17494
diff changeset
   580
	    inputFrom:nil
6d7174763909 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 17494
diff changeset
   581
	    outputTo:nil
6d7174763909 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 17494
diff changeset
   582
	    errorTo:nil
6d7174763909 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 17494
diff changeset
   583
	    auxFrom:nil
6d7174763909 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 17494
diff changeset
   584
	    environment:nil
6d7174763909 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 17494
diff changeset
   585
	    inDirectory:nil
17428
831e25b68d2c class: OSXOperatingSystem
Claus Gittinger <cg@exept.de>
parents: 17427
diff changeset
   586
    ] ifFalse:[
18279
6d7174763909 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 17494
diff changeset
   587
	^ self executeCommand:cmd
17428
831e25b68d2c class: OSXOperatingSystem
Claus Gittinger <cg@exept.de>
parents: 17427
diff changeset
   588
    ].
17427
1ee32c4f30e9 class: OSXOperatingSystem
Claus Gittinger <cg@exept.de>
parents: 17297
diff changeset
   589
1ee32c4f30e9 class: OSXOperatingSystem
Claus Gittinger <cg@exept.de>
parents: 17297
diff changeset
   590
    "
17428
831e25b68d2c class: OSXOperatingSystem
Claus Gittinger <cg@exept.de>
parents: 17427
diff changeset
   591
     OSXOperatingSystem openTerminalWithCommand:'ls -l' inBackground:true
17427
1ee32c4f30e9 class: OSXOperatingSystem
Claus Gittinger <cg@exept.de>
parents: 17297
diff changeset
   592
    "
17297
a56ba300949c Overriden openApplicationForDocument... to use desktop-specific "open" command.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17179
diff changeset
   593
! !
a56ba300949c Overriden openApplicationForDocument... to use desktop-specific "open" command.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17179
diff changeset
   594
14819
ff6be3d27a81 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   595
!OSXOperatingSystem class methodsFor:'file queries'!
ff6be3d27a81 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   596
ff6be3d27a81 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   597
caseSensitiveFilenames
ff6be3d27a81 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   598
    "return true, if the OS has caseSensitive file naming.
ff6be3d27a81 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   599
     On MSDOS, this will return false;
19817
b2aaa648f81d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 18279
diff changeset
   600
     on a real OS, we return true.
b2aaa648f81d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 18279
diff changeset
   601
     Be aware, that OSX can be configured to be either.
b2aaa648f81d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 18279
diff changeset
   602
     Also, that it actually depends on the mounted volume"
14819
ff6be3d27a81 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   603
18279
6d7174763909 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 17494
diff changeset
   604
    "/ actually, this is wrong and depends on the mounted volume;
6d7174763909 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 17494
diff changeset
   605
    "/ so we need a query for a particular directory (and/or volume).
14819
ff6be3d27a81 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   606
    ^ false
ff6be3d27a81 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   607
ff6be3d27a81 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   608
    "Modified: / 5.6.1998 / 18:35:18 / cg"
16381
d47eab2e1e10 class: OSXOperatingSystem
Claus Gittinger <cg@exept.de>
parents: 15803
diff changeset
   609
!
d47eab2e1e10 class: OSXOperatingSystem
Claus Gittinger <cg@exept.de>
parents: 15803
diff changeset
   610
16644
c8e610a071c3 class: OSXOperatingSystem
Claus Gittinger <cg@exept.de>
parents: 16381
diff changeset
   611
defaultPackagePath
20639
3bf77812174f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20637
diff changeset
   612
    "redefined to add /Application and /Library stuff"
20642
56c52db3521a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20639
diff changeset
   613
    "called by Smalltalk initSystemPath"
56c52db3521a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20639
diff changeset
   614
    "self defaultPackagePath"
16644
c8e610a071c3 class: OSXOperatingSystem
Claus Gittinger <cg@exept.de>
parents: 16381
diff changeset
   615
21452
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   616
    |path executablePath executableDir packagesDir
20637
a9b41f05ca91 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19817
diff changeset
   617
     libDir appDir versionsDir vsnDirName vsnDir|
16644
c8e610a071c3 class: OSXOperatingSystem
Claus Gittinger <cg@exept.de>
parents: 16381
diff changeset
   618
c8e610a071c3 class: OSXOperatingSystem
Claus Gittinger <cg@exept.de>
parents: 16381
diff changeset
   619
    path := super defaultPackagePath.
c8e610a071c3 class: OSXOperatingSystem
Claus Gittinger <cg@exept.de>
parents: 16381
diff changeset
   620
c8e610a071c3 class: OSXOperatingSystem
Claus Gittinger <cg@exept.de>
parents: 16381
diff changeset
   621
    executablePath := OperatingSystem pathOfSTXExecutable.
c8e610a071c3 class: OSXOperatingSystem
Claus Gittinger <cg@exept.de>
parents: 16381
diff changeset
   622
    executablePath notNil ifTrue:[
21452
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   623
	executableDir := executablePath asFilename directory.
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   624
	packagesDir := executableDir directory directory / 'Packages'.
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   625
	packagesDir exists ifTrue:[
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   626
	    packagesDir := packagesDir pathName.
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   627
	    (path includes:packagesDir) ifFalse:[
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   628
		path add:packagesDir.
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   629
	    ].
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   630
	].
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   631
	libDir := '/Library/Frameworks/SmalltalkX.framework' asFilename.
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   632
	libDir exists ifTrue:[
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   633
	    versionsDir := libDir / 'Versions'.
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   634
	    versionsDir exists ifTrue:[
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   635
		vsnDirName := '%1.%2.%3'
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   636
				    bindWith:Smalltalk majorVersionNr
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   637
				    with:Smalltalk minorVersionNr
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   638
				    with:Smalltalk revisionNr.
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   639
		vsnDir := versionsDir / vsnDirName.
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   640
		vsnDir exists ifTrue:[
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   641
		    vsnDir := vsnDir pathName.
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   642
		    (path includes:vsnDir) ifFalse:[
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   643
			path add:vsnDir.
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   644
		    ].
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   645
		].
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   646
	    ].
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   647
	].
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   648
	appDir := '/Applications/SmalltalkX/' asFilename.
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   649
	appDir exists ifTrue:[
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   650
	    versionsDir := appDir / 'Versions'.
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   651
	    versionsDir exists ifTrue:[
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   652
		vsnDirName := '%1.%2.%3'
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   653
				    bindWith:Smalltalk majorVersionNr
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   654
				    with:Smalltalk minorVersionNr
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   655
				    with:Smalltalk revisionNr.
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   656
		vsnDir := versionsDir / vsnDirName.
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   657
		vsnDir exists ifTrue:[
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   658
		    vsnDir := vsnDir pathName.
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   659
		    (path includes:vsnDir) ifFalse:[
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   660
			path add:vsnDir.
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   661
		    ].
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   662
		].
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   663
	    ].
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   664
	].
16644
c8e610a071c3 class: OSXOperatingSystem
Claus Gittinger <cg@exept.de>
parents: 16381
diff changeset
   665
    ].
16647
4c196996c402 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 16644
diff changeset
   666
    ^ path
16644
c8e610a071c3 class: OSXOperatingSystem
Claus Gittinger <cg@exept.de>
parents: 16381
diff changeset
   667
!
c8e610a071c3 class: OSXOperatingSystem
Claus Gittinger <cg@exept.de>
parents: 16381
diff changeset
   668
22655
bf2c170bc0f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22491
diff changeset
   669
getDocumentsDirectory
bf2c170bc0f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22491
diff changeset
   670
    "return your documents directory.
bf2c170bc0f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22491
diff changeset
   671
     Under osx, that's the user's 'Documents' folder.
bf2c170bc0f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22491
diff changeset
   672
     The fallback for other OS's may return the user's home directory."
bf2c170bc0f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22491
diff changeset
   673
bf2c170bc0f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22491
diff changeset
   674
    "{ Pragma: +optSpace }"
bf2c170bc0f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22491
diff changeset
   675
bf2c170bc0f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22491
diff changeset
   676
    |home documentsFolder|
bf2c170bc0f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22491
diff changeset
   677
bf2c170bc0f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22491
diff changeset
   678
    (home := self getHomeDirectory) notNil ifTrue:[
22833
60d71a4c5600 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 22655
diff changeset
   679
	(documentsFolder := home asFilename / 'Documents') exists ifTrue:[
60d71a4c5600 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 22655
diff changeset
   680
	    ^ documentsFolder pathName
60d71a4c5600 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 22655
diff changeset
   681
	].
22655
bf2c170bc0f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22491
diff changeset
   682
    ].
bf2c170bc0f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22491
diff changeset
   683
    ^ home
bf2c170bc0f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22491
diff changeset
   684
bf2c170bc0f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22491
diff changeset
   685
    "
bf2c170bc0f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22491
diff changeset
   686
     OperatingSystem getDocumentsDirectory
bf2c170bc0f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22491
diff changeset
   687
    "
bf2c170bc0f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22491
diff changeset
   688
!
bf2c170bc0f1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22491
diff changeset
   689
16677
0f22d24efe9f class: OSXOperatingSystem
Claus Gittinger <cg@exept.de>
parents: 16647
diff changeset
   690
getDriveList
0f22d24efe9f class: OSXOperatingSystem
Claus Gittinger <cg@exept.de>
parents: 16647
diff changeset
   691
    "return a list of volumes in the system."
0f22d24efe9f class: OSXOperatingSystem
Claus Gittinger <cg@exept.de>
parents: 16647
diff changeset
   692
0f22d24efe9f class: OSXOperatingSystem
Claus Gittinger <cg@exept.de>
parents: 16647
diff changeset
   693
    ^ ('/Volumes' asFilename directoryContents)
0f22d24efe9f class: OSXOperatingSystem
Claus Gittinger <cg@exept.de>
parents: 16647
diff changeset
   694
      , super getDriveList
0f22d24efe9f class: OSXOperatingSystem
Claus Gittinger <cg@exept.de>
parents: 16647
diff changeset
   695
!
0f22d24efe9f class: OSXOperatingSystem
Claus Gittinger <cg@exept.de>
parents: 16647
diff changeset
   696
16381
d47eab2e1e10 class: OSXOperatingSystem
Claus Gittinger <cg@exept.de>
parents: 15803
diff changeset
   697
getTrashDirectory
d47eab2e1e10 class: OSXOperatingSystem
Claus Gittinger <cg@exept.de>
parents: 15803
diff changeset
   698
    "get the name of a trash folder (if the OS supports it),
d47eab2e1e10 class: OSXOperatingSystem
Claus Gittinger <cg@exept.de>
parents: 15803
diff changeset
   699
     or nil, if not.
d47eab2e1e10 class: OSXOperatingSystem
Claus Gittinger <cg@exept.de>
parents: 15803
diff changeset
   700
     Must be redefined to return non nil in concrete operating systems"
d47eab2e1e10 class: OSXOperatingSystem
Claus Gittinger <cg@exept.de>
parents: 15803
diff changeset
   701
d47eab2e1e10 class: OSXOperatingSystem
Claus Gittinger <cg@exept.de>
parents: 15803
diff changeset
   702
    ^ '~/.Trash'
16677
0f22d24efe9f class: OSXOperatingSystem
Claus Gittinger <cg@exept.de>
parents: 16647
diff changeset
   703
!
0f22d24efe9f class: OSXOperatingSystem
Claus Gittinger <cg@exept.de>
parents: 16647
diff changeset
   704
0f22d24efe9f class: OSXOperatingSystem
Claus Gittinger <cg@exept.de>
parents: 16647
diff changeset
   705
pathNameForDrive:driveName
0f22d24efe9f class: OSXOperatingSystem
Claus Gittinger <cg@exept.de>
parents: 16647
diff changeset
   706
    "given a drive name, return the pathname to open it as a directory.
0f22d24efe9f class: OSXOperatingSystem
Claus Gittinger <cg@exept.de>
parents: 16647
diff changeset
   707
     For Windows, this is the driveName itself.
0f22d24efe9f class: OSXOperatingSystem
Claus Gittinger <cg@exept.de>
parents: 16647
diff changeset
   708
     For OSX, '/Volumes' is prepended.
0f22d24efe9f class: OSXOperatingSystem
Claus Gittinger <cg@exept.de>
parents: 16647
diff changeset
   709
     Other OSs might prepent the pount point (i.e. /mnt/)"
0f22d24efe9f class: OSXOperatingSystem
Claus Gittinger <cg@exept.de>
parents: 16647
diff changeset
   710
16905
46653de3c189 class: OSXOperatingSystem
Claus Gittinger <cg@exept.de>
parents: 16677
diff changeset
   711
    driveName isNil ifTrue:[^ nil].
16677
0f22d24efe9f class: OSXOperatingSystem
Claus Gittinger <cg@exept.de>
parents: 16647
diff changeset
   712
    driveName asFilename isAbsolute ifTrue:[^ driveName].
0f22d24efe9f class: OSXOperatingSystem
Claus Gittinger <cg@exept.de>
parents: 16647
diff changeset
   713
    ^ '/Volumes/',driveName
17177
28ebbb908d3e class: OSXOperatingSystem
Claus Gittinger <cg@exept.de>
parents: 16905
diff changeset
   714
!
28ebbb908d3e class: OSXOperatingSystem
Claus Gittinger <cg@exept.de>
parents: 16905
diff changeset
   715
28ebbb908d3e class: OSXOperatingSystem
Claus Gittinger <cg@exept.de>
parents: 16905
diff changeset
   716
supportsVolumes
18279
6d7174763909 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 17494
diff changeset
   717
    "return true if the os support a list of drives/volumes
17179
d12edae8391b class: OSXOperatingSystem
Claus Gittinger <cg@exept.de>
parents: 17177
diff changeset
   718
     (here we can return a list of mounted drives in /Volumes)"
17177
28ebbb908d3e class: OSXOperatingSystem
Claus Gittinger <cg@exept.de>
parents: 16905
diff changeset
   719
28ebbb908d3e class: OSXOperatingSystem
Claus Gittinger <cg@exept.de>
parents: 16905
diff changeset
   720
    ^ true
14819
ff6be3d27a81 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   721
! !
ff6be3d27a81 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   722
21452
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   723
!OSXOperatingSystem class methodsFor:'quartz - screen'!
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   724
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   725
getFrameBufferImage:displayNr
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   726
    "returns the framebuffer as an image object"
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   727
21580
b0c093983502 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21455
diff changeset
   728
    ^ self getFrameBufferImage:displayNr in:nil
b0c093983502 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21455
diff changeset
   729
b0c093983502 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21455
diff changeset
   730
    "
b0c093983502 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21455
diff changeset
   731
     self getFrameBufferImage:0
b0c093983502 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21455
diff changeset
   732
    "
b0c093983502 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21455
diff changeset
   733
b0c093983502 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21455
diff changeset
   734
    "Modified: / 25-02-2017 / 10:57:17 / cg"
b0c093983502 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21455
diff changeset
   735
!
21452
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   736
21580
b0c093983502 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21455
diff changeset
   737
getFrameBufferImage:displayNr in:aRectangleOrNil
21587
3ac571f08fbf hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents: 21585
diff changeset
   738
    "returns the frameBuffer (if rect-arg is nil)
3ac571f08fbf hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents: 21585
diff changeset
   739
     or part of the framebuffer (if non-nil) as an image object"
21580
b0c093983502 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21455
diff changeset
   740
21587
3ac571f08fbf hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents: 21585
diff changeset
   741
    |rx ry rwidth rheight bytesPerPixel bytesPerRow address pixels depth pad img ok|
21580
b0c093983502 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21455
diff changeset
   742
b0c093983502 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21455
diff changeset
   743
    aRectangleOrNil notNil ifTrue:[
24377
2fbcb2fa6c43 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 24339
diff changeset
   744
        rx := aRectangleOrNil left.
2fbcb2fa6c43 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 24339
diff changeset
   745
        ry := aRectangleOrNil top.
2fbcb2fa6c43 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 24339
diff changeset
   746
        rwidth := aRectangleOrNil width.
2fbcb2fa6c43 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 24339
diff changeset
   747
        rheight := aRectangleOrNil height.
21587
3ac571f08fbf hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents: 21585
diff changeset
   748
    ].
21452
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   749
%{
21596
ce0a09d20d18 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21595
diff changeset
   750
#ifndef NO_COCOA
21580
b0c093983502 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21455
diff changeset
   751
    CGImageRef image_ref;
b0c093983502 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21455
diff changeset
   752
    CGDirectDisplayID displayID = CGMainDisplayID();
21587
3ac571f08fbf hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents: 21585
diff changeset
   753
3ac571f08fbf hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents: 21585
diff changeset
   754
    ok = false;
21580
b0c093983502 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21455
diff changeset
   755
    if (rx == nil) {
24377
2fbcb2fa6c43 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 24339
diff changeset
   756
        image_ref  = CGDisplayCreateImage(displayID);
21580
b0c093983502 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21455
diff changeset
   757
    } else {
24377
2fbcb2fa6c43 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 24339
diff changeset
   758
        CGRect rect;
2fbcb2fa6c43 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 24339
diff changeset
   759
        rect.origin.x = (CGFloat)__intVal(rx);
2fbcb2fa6c43 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 24339
diff changeset
   760
        rect.origin.y = (CGFloat)__intVal(ry);
2fbcb2fa6c43 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 24339
diff changeset
   761
        rect.size.width = (CGFloat)__intVal(rwidth);
2fbcb2fa6c43 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 24339
diff changeset
   762
        rect.size.height = (CGFloat)__intVal(rheight);
2fbcb2fa6c43 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 24339
diff changeset
   763
        image_ref  = CGDisplayCreateImageForRect(displayID, rect);
21580
b0c093983502 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21455
diff changeset
   764
    }
21587
3ac571f08fbf hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents: 21585
diff changeset
   765
21580
b0c093983502 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21455
diff changeset
   766
    if (image_ref != NULL) {
24377
2fbcb2fa6c43 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 24339
diff changeset
   767
        CGDataProviderRef provider = CGImageGetDataProvider(image_ref);
2fbcb2fa6c43 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 24339
diff changeset
   768
        CFDataRef dataref = CGDataProviderCopyData(provider);
2fbcb2fa6c43 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 24339
diff changeset
   769
        size_t c_width = CGImageGetWidth(image_ref);
2fbcb2fa6c43 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 24339
diff changeset
   770
        size_t c_height = CGImageGetHeight(image_ref);
2fbcb2fa6c43 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 24339
diff changeset
   771
        size_t c_bytesPerRow = CGImageGetBytesPerRow(image_ref);
2fbcb2fa6c43 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 24339
diff changeset
   772
        size_t c_bytesPerPixel = CGImageGetBitsPerPixel(image_ref) / 8;
2fbcb2fa6c43 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 24339
diff changeset
   773
        unsigned char *c_pixels = (unsigned char *)CFDataGetBytePtr(dataref);
21452
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   774
24377
2fbcb2fa6c43 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 24339
diff changeset
   775
        if (c_bytesPerPixel == 4) {
2fbcb2fa6c43 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 24339
diff changeset
   776
            int row;
2fbcb2fa6c43 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 24339
diff changeset
   777
            pixels = __BYTEARRAY_UNINITIALIZED_NEW_INT(c_width * c_height * 3);
2fbcb2fa6c43 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 24339
diff changeset
   778
            unsigned char *srcRowPtr = c_pixels;
2fbcb2fa6c43 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 24339
diff changeset
   779
            unsigned char *dstRowPtr = __byteArrayVal(pixels);
2fbcb2fa6c43 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 24339
diff changeset
   780
2fbcb2fa6c43 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 24339
diff changeset
   781
            for (row=c_height; row>0; row--) {
2fbcb2fa6c43 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 24339
diff changeset
   782
                int col = c_width;
2fbcb2fa6c43 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 24339
diff changeset
   783
                unsigned int *pixSrcPtr = (unsigned int*)srcRowPtr;
2fbcb2fa6c43 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 24339
diff changeset
   784
                unsigned char *pixDstPtr = dstRowPtr;
21587
3ac571f08fbf hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents: 21585
diff changeset
   785
24377
2fbcb2fa6c43 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 24339
diff changeset
   786
                // convert abgr to rgb
23954
e28c9c96d726 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23314
diff changeset
   787
#if (__POINTER_SIZE__ == 8) && defined(__LSBFIRST__)
24377
2fbcb2fa6c43 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 24339
diff changeset
   788
                if (((INT)pixSrcPtr & 7) == 0) {
2fbcb2fa6c43 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 24339
diff changeset
   789
                    // is aligned
2fbcb2fa6c43 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 24339
diff changeset
   790
                    for (; col > 4; col -= 4) {
2fbcb2fa6c43 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 24339
diff changeset
   791
                        // pick 4 pixels (16byte with 2 INT fetches) store as 12byte (4ints)
2fbcb2fa6c43 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 24339
diff changeset
   792
                        unsigned INT pix12 = ((unsigned INT*)pixSrcPtr)[0];
2fbcb2fa6c43 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 24339
diff changeset
   793
                        unsigned INT pix34 = ((unsigned INT*)pixSrcPtr)[1];
24378
c46855b3748f #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 24377
diff changeset
   794
                        unsigned int w;
c46855b3748f #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 24377
diff changeset
   795
                        
24377
2fbcb2fa6c43 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 24339
diff changeset
   796
                        pixSrcPtr += 4;
2fbcb2fa6c43 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 24339
diff changeset
   797
                        // a2 r2 g2 b2 a1 r1 g1 b1 => r1..g1..b1..r2..g2..b2
2fbcb2fa6c43 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 24339
diff changeset
   798
                        w = (pix12 >> 16) & 0xFF;         // r1
2fbcb2fa6c43 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 24339
diff changeset
   799
                        w |= ((pix12 >> 8) & 0xFF) << 8;  // g1
2fbcb2fa6c43 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 24339
diff changeset
   800
                        w |= (pix12 & 0xFF) << 16;        // b1
2fbcb2fa6c43 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 24339
diff changeset
   801
                        w |= ((pix12 >> 48) & 0xFF)<<24;  // r2 
2fbcb2fa6c43 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 24339
diff changeset
   802
                        ((int*)pixDstPtr)[0] = w;
2fbcb2fa6c43 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 24339
diff changeset
   803
                        w = (pix12 >> 40) & 0xFF;         // g2 
2fbcb2fa6c43 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 24339
diff changeset
   804
                        w |= ((pix12 >> 32) & 0xFF)<<8;   // b2 
2fbcb2fa6c43 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 24339
diff changeset
   805
                        w |= ((pix34 >> 16) & 0xFF)<<16;  // r3
2fbcb2fa6c43 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 24339
diff changeset
   806
                        w |= ((pix34 >> 8) & 0xFF) <<24;  // g3
2fbcb2fa6c43 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 24339
diff changeset
   807
                        ((int*)pixDstPtr)[1] = w;
2fbcb2fa6c43 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 24339
diff changeset
   808
                        w = (pix34 & 0xFF);               // b3
2fbcb2fa6c43 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 24339
diff changeset
   809
                        w |= ((pix34 >> 48) & 0xFF)<<8;   // r4 
2fbcb2fa6c43 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 24339
diff changeset
   810
                        w |= ((pix34 >> 40) & 0xFF)<<16;  // g2 
2fbcb2fa6c43 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 24339
diff changeset
   811
                        w |= ((pix12 >> 32) & 0xFF)<<24;  // b2 
2fbcb2fa6c43 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 24339
diff changeset
   812
                        ((int*)pixDstPtr)[2] = w;
2fbcb2fa6c43 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 24339
diff changeset
   813
                        pixDstPtr += 12;
2fbcb2fa6c43 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 24339
diff changeset
   814
                    }
2fbcb2fa6c43 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 24339
diff changeset
   815
                }
2fbcb2fa6c43 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 24339
diff changeset
   816
                for (; col > 2; col -= 2) {
2fbcb2fa6c43 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 24339
diff changeset
   817
                    // pick 2 pixels (8byte with one fetch) store as 6byte
2fbcb2fa6c43 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 24339
diff changeset
   818
                    unsigned INT pix12 = ((unsigned INT*)pixSrcPtr)[0];
2fbcb2fa6c43 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 24339
diff changeset
   819
                    pixSrcPtr += 2;
2fbcb2fa6c43 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 24339
diff changeset
   820
                    // a2 r2 g2 b2 a1 r1 g1 b1 => r1..g1..b1..r2..g2..b2
2fbcb2fa6c43 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 24339
diff changeset
   821
                    pixDstPtr[0] = (pix12 >> 16) & 0xFF;
2fbcb2fa6c43 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 24339
diff changeset
   822
                    pixDstPtr[1] = (pix12 >> 8) & 0xFF;
2fbcb2fa6c43 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 24339
diff changeset
   823
                    pixDstPtr[2] = pix12 & 0xFF;
2fbcb2fa6c43 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 24339
diff changeset
   824
                    pixDstPtr[3] = (pix12 >> 48) & 0xFF;
2fbcb2fa6c43 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 24339
diff changeset
   825
                    pixDstPtr[4] = (pix12 >> 40) & 0xFF;
2fbcb2fa6c43 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 24339
diff changeset
   826
                    pixDstPtr[5] = (pix12 >> 32) & 0xFF;
2fbcb2fa6c43 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 24339
diff changeset
   827
                    pixDstPtr += 6;
2fbcb2fa6c43 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 24339
diff changeset
   828
                }
23954
e28c9c96d726 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23314
diff changeset
   829
#endif
21452
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   830
24377
2fbcb2fa6c43 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 24339
diff changeset
   831
                for (; col>0;col--) {
2fbcb2fa6c43 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 24339
diff changeset
   832
                    unsigned int pix = *pixSrcPtr++;
23954
e28c9c96d726 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23314
diff changeset
   833
#if 0
24377
2fbcb2fa6c43 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 24339
diff changeset
   834
                    pix = ((pix >> 16) & 0x0000FF)|((pix << 16) & 0xFF0000)|(pix & 0x00FF00);
2fbcb2fa6c43 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 24339
diff changeset
   835
                    pixDstPtr[0] = (pix >> 0);
2fbcb2fa6c43 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 24339
diff changeset
   836
                    pixDstPtr[1] = (pix >> 8);
2fbcb2fa6c43 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 24339
diff changeset
   837
                    pixDstPtr[2] = (pix >> 16);
23954
e28c9c96d726 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23314
diff changeset
   838
#else
24377
2fbcb2fa6c43 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 24339
diff changeset
   839
                    pixDstPtr[0] = (pix >> 16) & 0xFF;
2fbcb2fa6c43 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 24339
diff changeset
   840
                    pixDstPtr[1] = (pix >> 8) & 0xFF;
2fbcb2fa6c43 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 24339
diff changeset
   841
                    pixDstPtr[2] = pix & 0xFF;
23954
e28c9c96d726 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23314
diff changeset
   842
#endif
24377
2fbcb2fa6c43 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 24339
diff changeset
   843
                    pixDstPtr += 3;
2fbcb2fa6c43 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 24339
diff changeset
   844
                }
2fbcb2fa6c43 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 24339
diff changeset
   845
                dstRowPtr += c_width * 3;
2fbcb2fa6c43 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 24339
diff changeset
   846
                srcRowPtr += c_bytesPerRow;
2fbcb2fa6c43 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 24339
diff changeset
   847
            }
2fbcb2fa6c43 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 24339
diff changeset
   848
            bytesPerPixel = __MKSMALLINT(3);
2fbcb2fa6c43 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 24339
diff changeset
   849
            bytesPerRow = __MKSMALLINT( c_width*3 );
2fbcb2fa6c43 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 24339
diff changeset
   850
            ok = true;
2fbcb2fa6c43 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 24339
diff changeset
   851
        } else {
2fbcb2fa6c43 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 24339
diff changeset
   852
            // to be determined what we get...
2fbcb2fa6c43 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 24339
diff changeset
   853
            ok = false;
2fbcb2fa6c43 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 24339
diff changeset
   854
        }
2fbcb2fa6c43 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 24339
diff changeset
   855
        CFRelease(dataref);
2fbcb2fa6c43 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 24339
diff changeset
   856
        CGImageRelease(image_ref);
21580
b0c093983502 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21455
diff changeset
   857
24377
2fbcb2fa6c43 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 24339
diff changeset
   858
        rwidth = __MKUINT( c_width );
2fbcb2fa6c43 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 24339
diff changeset
   859
        rheight = __MKUINT( c_height );
21580
b0c093983502 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21455
diff changeset
   860
    }
b0c093983502 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21455
diff changeset
   861
b0c093983502 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21455
diff changeset
   862
    // the following is no longer supported by apple
b0c093983502 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21455
diff changeset
   863
    // CGDisplayBaseAddress is deprecated
b0c093983502 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21455
diff changeset
   864
    //
b0c093983502 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21455
diff changeset
   865
    //    uint32_t rowBytes, rowUInt32s, *screen;
b0c093983502 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21455
diff changeset
   866
    //
b0c093983502 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21455
diff changeset
   867
    //    CGDirectDisplayID targetDisplay = 0;
b0c093983502 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21455
diff changeset
   868
    //
b0c093983502 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21455
diff changeset
   869
    //    screen = (uint32_t *)CGDisplayBaseAddress(targetDisplay);
b0c093983502 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21455
diff changeset
   870
    //    rowBytes = CGDisplayBytesPerRow(targetDisplay);
b0c093983502 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21455
diff changeset
   871
    //    rowUInt32s = rowBytes / 4;
b0c093983502 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21455
diff changeset
   872
    //    rwidth = __MKUINT( CGDisplayPixelsWide(targetDisplay) );
b0c093983502 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21455
diff changeset
   873
    //    rheight = __MKUINT( CGDisplayPixelsHigh(targetDisplay) );
b0c093983502 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21455
diff changeset
   874
    //
21587
3ac571f08fbf hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents: 21585
diff changeset
   875
21596
ce0a09d20d18 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21595
diff changeset
   876
#endif // NO_COCOA
21452
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   877
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   878
%}.
21587
3ac571f08fbf hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents: 21585
diff changeset
   879
    (ok not or:[rwidth isNil]) ifTrue:[
24377
2fbcb2fa6c43 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 24339
diff changeset
   880
        ^ self primitiveFailed
21452
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   881
    ].
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   882
    depth := bytesPerPixel * 8.
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   883
21587
3ac571f08fbf hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents: 21585
diff changeset
   884
    "/ Transcript printf:'w:%d h:%d bpp:%d depth:%d bpr: %d\n'
21580
b0c093983502 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21455
diff changeset
   885
    "/            withAll:{ rwidth . rheight . bytesPerPixel . depth . bytesPerRow}.
21452
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   886
21598
4eb1335fe937 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21597
diff changeset
   887
    ( #(24) includes:depth) ifFalse:[
24377
2fbcb2fa6c43 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 24339
diff changeset
   888
        "/ check what we get here...
2fbcb2fa6c43 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 24339
diff changeset
   889
        ^ self primitiveFailed:'unsupported depth'
21452
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   890
    ].
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   891
21580
b0c093983502 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21455
diff changeset
   892
    img := Image extent:(rwidth @ rheight) depth:depth bits:pixels.
21598
4eb1335fe937 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21597
diff changeset
   893
    depth == 24 ifTrue:[
24377
2fbcb2fa6c43 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 24339
diff changeset
   894
        img bitsPerSample:#[8 8 8].
2fbcb2fa6c43 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 24339
diff changeset
   895
        img samplesPerPixel:3.
2fbcb2fa6c43 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 24339
diff changeset
   896
        img photometric:#rgb.
21598
4eb1335fe937 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21597
diff changeset
   897
    ] ifFalse:[
24377
2fbcb2fa6c43 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 24339
diff changeset
   898
        depth == 16 ifTrue:[
2fbcb2fa6c43 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 24339
diff changeset
   899
            "/ to be determined...
2fbcb2fa6c43 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 24339
diff changeset
   900
            img bitsPerSample:#[5 5 5].
2fbcb2fa6c43 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 24339
diff changeset
   901
            img samplesPerPixel:3.
2fbcb2fa6c43 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 24339
diff changeset
   902
            img photometric:#rgb.
2fbcb2fa6c43 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 24339
diff changeset
   903
        ].
21627
213250371878 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21625
diff changeset
   904
    ].
21452
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   905
    ^ img
21580
b0c093983502 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21455
diff changeset
   906
b0c093983502 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21455
diff changeset
   907
    "
b0c093983502 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21455
diff changeset
   908
     self getFrameBufferImage:0 in:nil
b0c093983502 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21455
diff changeset
   909
     self getFrameBufferImage:0 in:(100@100 corner:301@303)
21598
4eb1335fe937 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21597
diff changeset
   910
4eb1335fe937 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21597
diff changeset
   911
     Delay waitFor:3 seconds. self getFrameBufferImage:0 in:nil
21580
b0c093983502 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21455
diff changeset
   912
    "
b0c093983502 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21455
diff changeset
   913
b0c093983502 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21455
diff changeset
   914
    "Created: / 25-02-2017 / 09:49:07 / cg"
21598
4eb1335fe937 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21597
diff changeset
   915
    "Modified (comment): / 28-02-2017 / 15:22:17 / cg"
24378
c46855b3748f #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 24377
diff changeset
   916
    "Modified: / 27-06-2019 / 15:21:51 / Claus Gittinger"
21625
026eecef148d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21621
diff changeset
   917
!
026eecef148d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21621
diff changeset
   918
24047
df6ad32114b1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 24028
diff changeset
   919
getMousePosition
df6ad32114b1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 24028
diff changeset
   920
    |xLoc yLoc|
df6ad32114b1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 24028
diff changeset
   921
df6ad32114b1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 24028
diff changeset
   922
%{
df6ad32114b1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 24028
diff changeset
   923
#ifndef NO_COREGRAPHICS
df6ad32114b1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 24028
diff changeset
   924
    CGEventRef event = CGEventCreate(NULL);
df6ad32114b1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 24028
diff changeset
   925
    CGPoint loc = CGEventGetLocation(event);
df6ad32114b1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 24028
diff changeset
   926
    CFRelease(event);
df6ad32114b1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 24028
diff changeset
   927
df6ad32114b1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 24028
diff changeset
   928
    xLoc = __MKFLOAT(loc.x);
df6ad32114b1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 24028
diff changeset
   929
    yLoc = __MKFLOAT(loc.y);
df6ad32114b1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 24028
diff changeset
   930
#endif // NO_COREGRAPHICS
df6ad32114b1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 24028
diff changeset
   931
%}.
df6ad32114b1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 24028
diff changeset
   932
    ^ xLoc @ yLoc
df6ad32114b1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 24028
diff changeset
   933
!
df6ad32114b1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 24028
diff changeset
   934
21627
213250371878 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21625
diff changeset
   935
getScreenBounds:displayNr
21625
026eecef148d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21621
diff changeset
   936
    "returns the bounds of the screen.
026eecef148d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21621
diff changeset
   937
     This is needed, because the dimension of the XQuartz screen does not include the dock."
026eecef148d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21621
diff changeset
   938
026eecef148d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21621
diff changeset
   939
    |rx ry rwidth rheight|
026eecef148d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21621
diff changeset
   940
026eecef148d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21621
diff changeset
   941
%{
026eecef148d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21621
diff changeset
   942
#ifndef NO_COCOA
026eecef148d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21621
diff changeset
   943
    CGDirectDisplayID targetDisplay = 0;
026eecef148d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21621
diff changeset
   944
026eecef148d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21621
diff changeset
   945
    rx = ry = __MKSMALLINT(0);
026eecef148d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21621
diff changeset
   946
    rwidth = __MKUINT( CGDisplayPixelsWide(targetDisplay) );
026eecef148d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21621
diff changeset
   947
    rheight = __MKUINT( CGDisplayPixelsHigh(targetDisplay) );
026eecef148d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21621
diff changeset
   948
#endif // NO_COCOA
026eecef148d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21621
diff changeset
   949
%}.
026eecef148d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21621
diff changeset
   950
    (rwidth isNil) ifTrue:[
21627
213250371878 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21625
diff changeset
   951
	^ self primitiveFailed
21625
026eecef148d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21621
diff changeset
   952
    ].
026eecef148d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21621
diff changeset
   953
    ^ rx@ry extent:(rwidth@rheight)
026eecef148d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21621
diff changeset
   954
026eecef148d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21621
diff changeset
   955
    "
21627
213250371878 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21625
diff changeset
   956
     self getScreenBounds:0
21625
026eecef148d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21621
diff changeset
   957
    "
026eecef148d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21621
diff changeset
   958
026eecef148d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21621
diff changeset
   959
    "Created: / 05-03-2017 / 11:10:08 / cg"
21452
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   960
! !
3435141db80f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20642
diff changeset
   961
22962
4352599df059 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22959
diff changeset
   962
!OSXOperatingSystem class methodsFor:'sound & voice'!
4352599df059 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22959
diff changeset
   963
23314
1f3913819f30 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23114
diff changeset
   964
canPlaySound
1f3913819f30 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23114
diff changeset
   965
    ^ true
1f3913819f30 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23114
diff changeset
   966
1f3913819f30 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23114
diff changeset
   967
    "Created: / 29-08-2018 / 09:35:52 / Claus Gittinger"
1f3913819f30 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23114
diff changeset
   968
!
1f3913819f30 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23114
diff changeset
   969
1f3913819f30 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23114
diff changeset
   970
canSpeak
1f3913819f30 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23114
diff changeset
   971
    ^ true
1f3913819f30 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23114
diff changeset
   972
1f3913819f30 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23114
diff changeset
   973
    "Created: / 29-08-2018 / 09:45:16 / Claus Gittinger"
1f3913819f30 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23114
diff changeset
   974
!
1f3913819f30 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23114
diff changeset
   975
22962
4352599df059 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22959
diff changeset
   976
playSound:soundFile
4352599df059 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22959
diff changeset
   977
    "use 'say ...'"
4352599df059 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22959
diff changeset
   978
4352599df059 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22959
diff changeset
   979
    ^ self executeCommand:('afplay "%1"' bindWith:soundFile asFilename pathName)
4352599df059 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22959
diff changeset
   980
4352599df059 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22959
diff changeset
   981
    "
4352599df059 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22959
diff changeset
   982
     self speak:'hello world'
4352599df059 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22959
diff changeset
   983
    "
4352599df059 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22959
diff changeset
   984
!
4352599df059 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22959
diff changeset
   985
22970
ff49ded84d3a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22966
diff changeset
   986
voiceCommandSpec
ff49ded84d3a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22966
diff changeset
   987
    ^ #(
23114
21306b85ca30 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 22970
diff changeset
   988
	"/ triples are:
21306b85ca30 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 22970
diff changeset
   989
	"/      -command
21306b85ca30 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 22970
diff changeset
   990
	"/      -commandline for default voice
21306b85ca30 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 22970
diff changeset
   991
	"/      -commandline for specific voice
21306b85ca30 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 22970
diff changeset
   992
	(
21306b85ca30 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 22970
diff changeset
   993
	    'say'
21306b85ca30 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 22970
diff changeset
   994
		'say "%2"'
21306b85ca30 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 22970
diff changeset
   995
		'say -v "%1" "%2"'
21306b85ca30 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 22970
diff changeset
   996
	)
21306b85ca30 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 22970
diff changeset
   997
    )
22966
57d20ca389c1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22962
diff changeset
   998
!
57d20ca389c1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22962
diff changeset
   999
57d20ca389c1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22962
diff changeset
  1000
voiceInfo
57d20ca389c1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22962
diff changeset
  1001
    "return a list of available voices plus info:
57d20ca389c1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22962
diff changeset
  1002
     for each available voice, a triple is returned, containing:
23114
21306b85ca30 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 22970
diff changeset
  1003
	voiceName language_territory comment/description
22966
57d20ca389c1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22962
diff changeset
  1004
    "
57d20ca389c1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22962
diff changeset
  1005
57d20ca389c1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22962
diff changeset
  1006
    ^ (PipeStream outputFromCommand:'say -v ?')
23114
21306b85ca30 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 22970
diff changeset
  1007
	asCollectionOfLines
21306b85ca30 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 22970
diff changeset
  1008
	    collect:[:l |
21306b85ca30 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 22970
diff changeset
  1009
		|s name lang comment|
21306b85ca30 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 22970
diff changeset
  1010
21306b85ca30 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 22970
diff changeset
  1011
		s := l readStream.
21306b85ca30 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 22970
diff changeset
  1012
		"/ skip forward for two separators
21306b85ca30 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 22970
diff changeset
  1013
		[
21306b85ca30 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 22970
diff changeset
  1014
		    [s next isLetterOrDigit] whileTrue:[].
21306b85ca30 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 22970
diff changeset
  1015
		    s peek isLetterOrDigit
21306b85ca30 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 22970
diff changeset
  1016
		] whileTrue.
21306b85ca30 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 22970
diff changeset
  1017
		name := l copyFrom:1 to:s position - 1.
21306b85ca30 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 22970
diff changeset
  1018
		s skipSeparators.
21306b85ca30 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 22970
diff changeset
  1019
		lang := s upToSeparator.
21306b85ca30 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 22970
diff changeset
  1020
		s skipSeparators.
21306b85ca30 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 22970
diff changeset
  1021
		s next == $# ifTrue:[
21306b85ca30 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 22970
diff changeset
  1022
		    s skipSeparators.
21306b85ca30 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 22970
diff changeset
  1023
		    comment := s upToEnd utf8Decoded.
21306b85ca30 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 22970
diff changeset
  1024
		].
21306b85ca30 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 22970
diff changeset
  1025
		{ name . lang . comment }
21306b85ca30 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 22970
diff changeset
  1026
	    ]
22962
4352599df059 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22959
diff changeset
  1027
4352599df059 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22959
diff changeset
  1028
    "
22966
57d20ca389c1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22962
diff changeset
  1029
     OperatingSystem voiceInfo
22962
4352599df059 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22959
diff changeset
  1030
    "
23314
1f3913819f30 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23114
diff changeset
  1031
!
1f3913819f30 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23114
diff changeset
  1032
1f3913819f30 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23114
diff changeset
  1033
voiceMapping
1f3913819f30 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23114
diff changeset
  1034
    "return a mapping from common (OS-independent) voice names
1f3913819f30 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23114
diff changeset
  1035
     to OS-specific names or IDs.
1f3913819f30 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23114
diff changeset
  1036
     The speak:voiceName interface will recognize both.
1f3913819f30 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23114
diff changeset
  1037
     For portable programs, always use the OS-independent name and
1f3913819f30 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23114
diff changeset
  1038
     let every OS xlate to its internal name."
1f3913819f30 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23114
diff changeset
  1039
1f3913819f30 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23114
diff changeset
  1040
    |info map v|
1f3913819f30 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23114
diff changeset
  1041
1f3913819f30 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23114
diff changeset
  1042
    VoiceMapping notNil ifTrue:[^ VoiceMapping].
1f3913819f30 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23114
diff changeset
  1043
1f3913819f30 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23114
diff changeset
  1044
    info := self voiceInfo.
1f3913819f30 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23114
diff changeset
  1045
    map := OrderedCollection new.
1f3913819f30 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23114
diff changeset
  1046
    v := info detect:[:entry | #('Tom' 'Alex' 'Fred' 'Bruce' 'Ralph' 'Daniel') includes:entry first] ifNone:nil.
1f3913819f30 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23114
diff changeset
  1047
    map add:( 'male' -> (v ? #(nil)) first ).
1f3913819f30 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23114
diff changeset
  1048
    v := info detect:[:entry | #('Samantha' 'Fiona' 'Karen' 'Moira') includes:entry first] ifNone:nil.
1f3913819f30 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23114
diff changeset
  1049
    map add:( 'female' -> (v ? #(nil)) first ).
1f3913819f30 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23114
diff changeset
  1050
    v := info detect:[:entry | #('Zarvox') includes:entry first] ifNone:nil.
1f3913819f30 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23114
diff changeset
  1051
    map add:( 'computer' -> (v ? #(nil)) first ).
1f3913819f30 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23114
diff changeset
  1052
    map add:( 'default' -> nil ).
1f3913819f30 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23114
diff changeset
  1053
    VoiceMapping := map.
1f3913819f30 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23114
diff changeset
  1054
    ^ VoiceMapping
24047
df6ad32114b1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 24028
diff changeset
  1055
23314
1f3913819f30 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23114
diff changeset
  1056
    "on OSX, this could be:
24047
df6ad32114b1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 24028
diff changeset
  1057
	^ {
df6ad32114b1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 24028
diff changeset
  1058
	    'male' -> 'Alex' .
df6ad32114b1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 24028
diff changeset
  1059
	    'female' -> 'Fiona' .
df6ad32114b1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 24028
diff changeset
  1060
	    'computer' -> 'Zarvox' .
df6ad32114b1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 24028
diff changeset
  1061
	    'default' -> 'Fiona'
df6ad32114b1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 24028
diff changeset
  1062
	}
23314
1f3913819f30 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23114
diff changeset
  1063
    "
1f3913819f30 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23114
diff changeset
  1064
1f3913819f30 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23114
diff changeset
  1065
    "
1f3913819f30 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23114
diff changeset
  1066
     OperatingSystem voiceMapping
1f3913819f30 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23114
diff changeset
  1067
    "
1f3913819f30 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23114
diff changeset
  1068
1f3913819f30 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23114
diff changeset
  1069
    "Created: / 29-08-2018 / 09:55:00 / Claus Gittinger"
22962
4352599df059 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22959
diff changeset
  1070
! !
4352599df059 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22959
diff changeset
  1071
22833
60d71a4c5600 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 22655
diff changeset
  1072
!OSXOperatingSystem class methodsFor:'time and date'!
60d71a4c5600 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 22655
diff changeset
  1073
60d71a4c5600 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 22655
diff changeset
  1074
getOSTimeWithNanos
60d71a4c5600 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 22655
diff changeset
  1075
    "This returns the OS time as a 2-element vector with milliseconds (as before)
60d71a4c5600 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 22655
diff changeset
  1076
     plus nanoseconds.
60d71a4c5600 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 22655
diff changeset
  1077
     The base of the returned value is not consistent across
60d71a4c5600 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 22655
diff changeset
  1078
     different OS's - some return the number of nanoseconds since jan, 1st 1970;
60d71a4c5600 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 22655
diff changeset
  1079
     others since 1900. The Time classes are prepared for this, and
60d71a4c5600 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 22655
diff changeset
  1080
     convert as appropriate (by using my fromOSTime: conversion methods).
60d71a4c5600 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 22655
diff changeset
  1081
60d71a4c5600 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 22655
diff changeset
  1082
     Don't use this method in application code since it is an internal (private)
60d71a4c5600 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 22655
diff changeset
  1083
     interface. For compatibility use instances of Time, Date or Timestamp to work with."
60d71a4c5600 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 22655
diff changeset
  1084
60d71a4c5600 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 22655
diff changeset
  1085
    |seconds millis nanos|
60d71a4c5600 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 22655
diff changeset
  1086
%{
24047
df6ad32114b1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 24028
diff changeset
  1087
// all of the experiments below only provide 1us resolution on my machine
df6ad32114b1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 24028
diff changeset
  1088
// Not sure if that has to do with the OSX version (high sierra)
22833
60d71a4c5600 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 22655
diff changeset
  1089
// therefore, it is disabled, and we fall back to the inherited method,
60d71a4c5600 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 22655
diff changeset
  1090
// which returns microsecond resolution nanos anyway.
60d71a4c5600 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 22655
diff changeset
  1091
#if 0
60d71a4c5600 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 22655
diff changeset
  1092
    unsigned long _secs, _millis, _nanos;
60d71a4c5600 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 22655
diff changeset
  1093
60d71a4c5600 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 22655
diff changeset
  1094
# if defined(CLOCK_REALTIME) && !defined(NO_CLOCK_GETTIME)
60d71a4c5600 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 22655
diff changeset
  1095
    struct timespec ts;
60d71a4c5600 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 22655
diff changeset
  1096
    static int has_clock_gettime = 1;
60d71a4c5600 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 22655
diff changeset
  1097
    unsigned long _secs, _millis, _nanos;
60d71a4c5600 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 22655
diff changeset
  1098
60d71a4c5600 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 22655
diff changeset
  1099
    if (has_clock_gettime) {
60d71a4c5600 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 22655
diff changeset
  1100
	if (clock_gettime(CLOCK_REALTIME, &ts) != -1) {
60d71a4c5600 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 22655
diff changeset
  1101
	    _secs = ts.tv_sec;
60d71a4c5600 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 22655
diff changeset
  1102
	    _millis = ts.tv_nsec / 1000000;
60d71a4c5600 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 22655
diff changeset
  1103
	    _nanos = ts.tv_nsec % 1000000;
60d71a4c5600 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 22655
diff changeset
  1104
60d71a4c5600 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 22655
diff changeset
  1105
	    seconds = __MKUINT(_secs);
60d71a4c5600 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 22655
diff changeset
  1106
	    millis = __MKUINT(_millis);
60d71a4c5600 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 22655
diff changeset
  1107
	    nanos = __MKUINT(_nanos);
60d71a4c5600 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 22655
diff changeset
  1108
	} else {
60d71a4c5600 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 22655
diff changeset
  1109
	    /*
60d71a4c5600 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 22655
diff changeset
  1110
	     * clock_gettime is not implemented in the kernel
60d71a4c5600 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 22655
diff changeset
  1111
	     * fall through to alternative implementation
60d71a4c5600 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 22655
diff changeset
  1112
	     */
60d71a4c5600 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 22655
diff changeset
  1113
	    has_clock_gettime = 0;
60d71a4c5600 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 22655
diff changeset
  1114
	}
60d71a4c5600 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 22655
diff changeset
  1115
    }
60d71a4c5600 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 22655
diff changeset
  1116
# else
60d71a4c5600 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 22655
diff changeset
  1117
#  if 0
60d71a4c5600 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 22655
diff changeset
  1118
    // althoug documented, my osx doesn't have it...
60d71a4c5600 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 22655
diff changeset
  1119
    uint32_t secpart;
60d71a4c5600 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 22655
diff changeset
  1120
    uint32_t nsecpart;
60d71a4c5600 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 22655
diff changeset
  1121
60d71a4c5600 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 22655
diff changeset
  1122
    clock_get_calendar_nanotime(&secpart, &nsecpart);
60d71a4c5600 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 22655
diff changeset
  1123
60d71a4c5600 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 22655
diff changeset
  1124
    _secs = secpart;
60d71a4c5600 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 22655
diff changeset
  1125
    _millis = nsecpart / 1000000;
60d71a4c5600 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 22655
diff changeset
  1126
    _nanos = nsecpart % 1000000;
60d71a4c5600 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 22655
diff changeset
  1127
#  else
60d71a4c5600 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 22655
diff changeset
  1128
    // OS X does not have clock_gettime, use host_get_clock_service
60d71a4c5600 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 22655
diff changeset
  1129
    clock_serv_t cclock;
60d71a4c5600 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 22655
diff changeset
  1130
    mach_timespec_t mts;
60d71a4c5600 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 22655
diff changeset
  1131
    host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &cclock);
60d71a4c5600 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 22655
diff changeset
  1132
    clock_get_time(cclock, &mts);
60d71a4c5600 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 22655
diff changeset
  1133
    mach_port_deallocate(mach_task_self(), cclock);
60d71a4c5600 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 22655
diff changeset
  1134
60d71a4c5600 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 22655
diff changeset
  1135
    _secs = mts.tv_sec;
60d71a4c5600 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 22655
diff changeset
  1136
    _millis = mts.tv_nsec / 1000000;
60d71a4c5600 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 22655
diff changeset
  1137
    _nanos = mts.tv_nsec % 1000000;
60d71a4c5600 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 22655
diff changeset
  1138
#  endif
60d71a4c5600 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 22655
diff changeset
  1139
60d71a4c5600 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 22655
diff changeset
  1140
    seconds = __MKUINT(_secs);
60d71a4c5600 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 22655
diff changeset
  1141
    millis = __MKUINT(_millis);
60d71a4c5600 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 22655
diff changeset
  1142
    nanos = __MKUINT(_nanos);
60d71a4c5600 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 22655
diff changeset
  1143
# endif
60d71a4c5600 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 22655
diff changeset
  1144
#endif
60d71a4c5600 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 22655
diff changeset
  1145
%}.
60d71a4c5600 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 22655
diff changeset
  1146
    seconds notNil ifTrue:[
60d71a4c5600 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 22655
diff changeset
  1147
	^ { ((seconds * 1000) + millis) . nanos }
60d71a4c5600 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 22655
diff changeset
  1148
    ].
60d71a4c5600 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 22655
diff changeset
  1149
60d71a4c5600 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 22655
diff changeset
  1150
    ^ super getOSTimeWithNanos.
60d71a4c5600 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 22655
diff changeset
  1151
! !
60d71a4c5600 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 22655
diff changeset
  1152
14819
ff6be3d27a81 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1153
!OSXOperatingSystem class methodsFor:'documentation'!
ff6be3d27a81 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1154
ff6be3d27a81 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1155
version
19817
b2aaa648f81d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 18279
diff changeset
  1156
    ^ '$Header$'
14819
ff6be3d27a81 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1157
!
ff6be3d27a81 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1158
ff6be3d27a81 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1159
version_CVS
19817
b2aaa648f81d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 18279
diff changeset
  1160
    ^ '$Header$'
14819
ff6be3d27a81 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1161
! !
24377
2fbcb2fa6c43 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 24339
diff changeset
  1162