Tk-Components

Check-in [1554d3738e]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:aem changes
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:1554d3738e14f1b7afcae6c66c9ccd1c05351277
User & Date: kevin 2015-07-13 03:25:32
Context
2015-07-13
06:45
aem implementation now complete, need further testing and documentation before formal release check-in: 1d1a58d84a user: kevin tags: trunk
03:25
aem changes check-in: 1554d3738e user: kevin tags: trunk
2015-07-12
04:09
More updates to aem check-in: 19a8a45d31 user: kevin tags: trunk
Changes
Hide Diffs Unified Diffs Show Whitespace Changes Patch

Changes to aem/macosx/aem.c.

69
70
71
72
73
74
75
76

77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95

96
97
98
99
100
101

102




103
104
105
106
107
108
109
...
119
120
121
122
123
124
125






126
127


128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
OSErr TclAEHandler(const AppleEvent *theAppleEvent,
		   AppleEvent *reply, long refCon) {


  OSErr err = noErr;
  AEEventID	eventID;
  AEDesc directParameter;
  Tcl_DString as_arg;


  /* Get event ID to look up in CFDictionary. */
  err = AEGetAttributePtr(theAppleEvent, keyEventIDAttr, typeType, NULL, &eventID, sizeof(eventID), NULL );

  /* Get direct parameter, convert to char. */
  err = AEGetKeyDesc(theAppleEvent, keyDirectObject, typeUTF8Text, &directParameter);
  long size = AEGetDescDataSize(&directParameter);
  //  char *paramstring[size];
  UInt8 paramstring[size];
  if (size == 0) {
    paramstring[0] = "";
  }
			   
  AEGetDescData(&directParameter, paramstring, size);
  AEDisposeDesc(&directParameter);

  /*Need to convert paramstring to something Tcl can handle gracefully. Direct conversion of AE params to char does not seem to work well, produces garbage.*/

  CFStringRef arg = CFStringCreateWithBytes(0, paramstring, sizeof(paramstring),

					    kCFStringEncodingUTF8, false);
  int len; 
  len = CFStringGetMaximumSizeForEncoding(CFStringGetLength(arg), kCFStringEncodingUTF8);
  Tcl_DStringInit(&as_arg);
  Tcl_DStringSetLength(&as_arg, len);


  Tcl_DStringValue(&as_arg) = CFStringGetCStringPtr(arg, kCFStringEncodingUTF8);




   
  /*  Get command keyed to eventID from dict and pass to Tcl for execution. */
  CFTypeRef scriptName;
  stringeventID = UTCreateStringForOSType(eventID);
  scriptName = CFDictionaryGetValue(aeDict, stringeventID);
  CFStringRef cfcmd;
  if (scriptName == NULL) {
................................................................................
  }
 
  char *applescript_tcl_cmd;
  
  /* Convert the string reference into a C string. */
  applescript_tcl_cmd = CFStringGetCStringPtr(cfcmd, kCFStringEncodingUTF8);
  






  /* Eval the Tcl command. */
  Tcl_VarEval(AS_Interp, applescript_tcl_cmd, " ", Tcl_DStringValue(&as_arg), NULL);


 
  char *output;
  output = Tcl_GetString(Tcl_GetObjResult(AS_Interp));
  Tcl_SetResult(AS_Interp, output, NULL);
 
 
  /*  Pass results back to AppleScript, clean up. */
  err= AEPutParamPtr(reply, keyDirectObject, typeUTF8Text, output, strlen(output));
  if (err !=noErr) {
    fprintf(stderr, "Unable to execute %s\n", applescript_tcl_cmd);
  }
  CFRelease(scriptName);
  CFRelease(arg);
  return err;
}

  
/*Initalize the package in the tcl interpreter, create Tcl commands. */
int Aem_Init (Tcl_Interp *interp) {

 
  if (Tcl_InitStubs(interp, "8.5", 0) == NULL) {
    return TCL_ERROR;  
  }
  if (Tk_InitStubs(interp, "8.5", 0) == NULL) {
    return TCL_ERROR;
  }







|
>






|
|
|
|
|
|
|





|
>
|
<
|
|
<

>
|
>
>
>
>







 







>
>
>
>
>
>

<
>
>












<






<







69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98

99
100

101
102
103
104
105
106
107
108
109
110
111
112
113
114
...
124
125
126
127
128
129
130
131
132
133
134
135
136
137

138
139
140
141
142
143
144
145
146
147
148
149
150
151

152
153
154
155
156
157

158
159
160
161
162
163
164
OSErr TclAEHandler(const AppleEvent *theAppleEvent,
		   AppleEvent *reply, long refCon) {


  OSErr err = noErr;
  AEEventID	eventID;
  AEDesc directParameter;
  Tcl_DString as_cmd;
  char *as_arg; 

  /* Get event ID to look up in CFDictionary. */
  err = AEGetAttributePtr(theAppleEvent, keyEventIDAttr, typeType, NULL, &eventID, sizeof(eventID), NULL );

  /* Get direct parameter, convert to char. */
  err = AEGetKeyDesc(theAppleEvent, keyDirectObject, typeUTF8Text, &directParameter);

  long size = AEGetDescDataSize(&directParameter);
  Tcl_DStringInit(&as_cmd);
  
  if (size) {
    UInt8 paramstring[size];
 			   
    AEGetDescData(&directParameter, paramstring, size);
    AEDisposeDesc(&directParameter);

    /*Need to convert paramstring to something Tcl can handle gracefully. Direct conversion of AE params to char does not seem to work well, produces garbage.*/

    CFStringRef arg = CFStringCreateWithBytes(0, paramstring, sizeof(paramstring), kCFStringEncodingUTF8, false);
    
    // as_arg = CFStringGetCStringPtr(arg, kCFStringEncodingUTF8);

    CFIndex stringLengthIndex = CFStringGetLength(arg);
     CFStringGetCString(arg, as_arg, stringLengthIndex,  kCFStringEncodingUTF8);


     fprintf(stdout, "the arg is %s\n", as_arg);
    CFRelease(arg);
  } else {
    as_arg  = " ";
    fprintf(stdout, "the null arg is %s\n", as_arg);
  }
   
  /*  Get command keyed to eventID from dict and pass to Tcl for execution. */
  CFTypeRef scriptName;
  stringeventID = UTCreateStringForOSType(eventID);
  scriptName = CFDictionaryGetValue(aeDict, stringeventID);
  CFStringRef cfcmd;
  if (scriptName == NULL) {
................................................................................
  }
 
  char *applescript_tcl_cmd;
  
  /* Convert the string reference into a C string. */
  applescript_tcl_cmd = CFStringGetCStringPtr(cfcmd, kCFStringEncodingUTF8);
  
  /* Build the command to eval. */

  Tcl_DStringAppend(&as_cmd, applescript_tcl_cmd, -1);
  Tcl_DStringAppend(&as_cmd, " ", -1);
  /* Tcl_DStringAppend(&as_cmd, as_arg, -1); */
  
  /* Eval the Tcl command. */

  Tcl_Eval(AS_Interp, Tcl_DStringValue(&as_cmd));
  Tcl_DStringFree(&as_cmd);
 
  char *output;
  output = Tcl_GetString(Tcl_GetObjResult(AS_Interp));
  Tcl_SetResult(AS_Interp, output, NULL);
 
 
  /*  Pass results back to AppleScript, clean up. */
  err= AEPutParamPtr(reply, keyDirectObject, typeUTF8Text, output, strlen(output));
  if (err !=noErr) {
    fprintf(stderr, "Unable to execute %s\n", applescript_tcl_cmd);
  }
  CFRelease(scriptName); 

  return err;
}

  
/*Initalize the package in the tcl interpreter, create Tcl commands. */
int Aem_Init (Tcl_Interp *interp) {


  if (Tcl_InitStubs(interp, "8.5", 0) == NULL) {
    return TCL_ERROR;  
  }
  if (Tk_InitStubs(interp, "8.5", 0) == NULL) {
    return TCL_ERROR;
  }