Commit dc0d6e0d authored by Diederik van Arkel's avatar Diederik van Arkel

Initial commit MacOS Carbon version

parent 701a536e
#define Clean(a)
typedef struct clean_string *CleanString;
/* a string in Clean is:
struct clean_string {
int clean_string_length;
char clean_string_characters[clean_string_length];
};
The string does not end with a '\0' !
*/
/* CleanStringLength(clean_string) returns length of the clean_string in characters */
#define CleanStringLength(clean_string) (*(unsigned int *)(clean_string))
/* CleanStringCharacters(clean_string) returns a pointer to the characters of the clean_string */
#define CleanStringCharacters(clean_string) ((char*)(1+(unsigned int *)(clean_string)))
/* CleanStringSizeInts(string_length) return size of CleanString in integers */
#define CleanStringSizeInts(string_length) (1+(((unsigned int)(string_length)+3)>>2))
/* CleanStringVariable(clean_string,string_length) defines variable clean_string with length string_length,
before using the clean_string variable, cast to CleanString, except for the macros above */
#define CleanStringVariable(clean_string,string_length) unsigned int clean_string[CleanStringSizeInts(string_length)]
/* CleanStringSizeBytes(string_length) return size of CleanString in bytes */
#define CleanStringSizeBytes(string_length) (4+(((unsigned int)(string_length)+3) & -4))
This diff is collapsed.
This diff is collapsed.
#include <MacTypes.h>
#include <Files.h>
#include <Events.h>
#include <EPPC.h>
#include <AppleEvents.h>
#include <AERegistry.h>
static char *result_string;
static int n_free_result_string_characters;
static pascal OSErr DoAEOpenApplication (AppleEvent *theAppleEvent,AppleEvent *replyAppleEvent,long refCon)
{
return noErr;
}
static int has_required_parameters (AppleEvent *theAppleEvent)
{
Size actual_size;
DescType returned_type;
OSErr r;
r=AEGetAttributePtr (theAppleEvent,keyMissedKeywordAttr,typeWildCard,&returned_type,NULL,0,&actual_size);
if (r==errAEDescNotFound)
return noErr;
if (r==noErr)
r=errAEEventNotHandled;
return r;
}
static pascal OSErr DoAEOpenDocuments (AppleEvent *theAppleEvent,AppleEvent *replyAppleEvent, long refCon)
{
OSErr r;
AEDescList document_list;
if (n_free_result_string_characters<4){
n_free_result_string_characters=0;
result_string=NULL;
return 0;
}
result_string[0]='O';
result_string[1]='P';
result_string[2]='E';
result_string[3]='N';
result_string+=4;
n_free_result_string_characters-=4;
r=AEGetParamDesc (theAppleEvent,keyDirectObject,typeAEList,&document_list);
if (r==noErr){
r=has_required_parameters (theAppleEvent);
r = noErr;
if (r==noErr){
long n_items;
r=AECountItems (&document_list,&n_items);
if (r==noErr){
long i;
for (i=1; i<=n_items; ++i){
AEKeyword keyword;
DescType returned_type;
FSSpec fss;
Size actual_size;
r=AEGetNthPtr (&document_list,i,typeFSS,&keyword,&returned_type,&fss,sizeof (FSSpec),&actual_size);
if (r!=noErr)
break;
if (n_free_result_string_characters<sizeof (FSSpec)){
AEDisposeDesc (&document_list);
n_free_result_string_characters=0;
result_string=NULL;
return 0;
}
*(FSSpec*)result_string=fss;
result_string+=sizeof (FSSpec);
n_free_result_string_characters-=sizeof (FSSpec);
}
}
}
}
AEDisposeDesc (&document_list);
if (r!=noErr){
result_string=NULL;
n_free_result_string_characters=0;
}
return r;
}
static pascal OSErr DoAEPrintDocuments (AppleEvent *theAppleEvent,AppleEvent *replyAppleEvent,long refCon)
{
return errAEEventNotHandled;
}
static pascal OSErr DoAEQuitApplication (AppleEvent *theAppleEvent,AppleEvent *replyAppleEvent,long refCon)
{
if (n_free_result_string_characters>=4){
result_string[0]='Q';
result_string[1]='U';
result_string[2]='I';
result_string[3]='T';
result_string+=4;
n_free_result_string_characters-=4;
}
return noErr;
}
static pascal OSErr DoAEScript (AppleEvent *apple_event,AppleEvent *replyAppleEvent,long refCon)
{
DescType returned_type;
long actual_size;
int error;
if (n_free_result_string_characters>=6){
result_string[0]='S';
result_string[1]='C';
result_string[2]='R';
result_string[3]='I';
result_string[4]='P';
result_string[5]='T';
result_string+=6;
n_free_result_string_characters-=6;
}
error=AEGetParamPtr (apple_event,keyDirectObject,'TEXT',&returned_type,result_string,n_free_result_string_characters,&actual_size);
if (error!=noErr){
result_string=NULL;
n_free_result_string_characters=0;
} else {
n_free_result_string_characters-=actual_size;
result_string+=actual_size;
}
return error;
}
static pascal OSErr DoAEApplicationDied (AppleEvent *apple_event,AppleEvent *replyAppleEvent,long refCon)
{
DescType returned_type;
long actual_size;
int error;
if (n_free_result_string_characters>=7){
result_string[0]='A';
result_string[1]='P';
result_string[2]='P';
result_string[3]='D';
result_string[4]='I';
result_string[5]='E';
result_string[6]='D';
result_string+=7;
n_free_result_string_characters-=7;
}
error = AEGetParamPtr (apple_event,keyProcessSerialNumber,typeProcessSerialNumber,&returned_type,result_string,n_free_result_string_characters,&actual_size);
if (error==noErr){
n_free_result_string_characters-=actual_size;
result_string+=actual_size;
}
return error;
}
#define MAX_N_COMPILERS 32
static int compiler_finished[MAX_N_COMPILERS]={0};
static int compiler_exit_code[MAX_N_COMPILERS];
static int n_unknown_finished_compilers=0;
static pascal OSErr DoAEAnswer (AppleEvent *apple_event,AppleEvent *replyAppleEvent,long refCon)
{
DescType returned_type;
long actual_size;
int error;
if (n_free_result_string_characters>=6){
result_string[0]='A';
result_string[1]='N';
result_string[2]='S';
result_string[3]='W';
result_string[4]='E';
result_string[5]='R';
result_string+=6;
n_free_result_string_characters-=6;
}
{
int exit_code;
exit_code = 0;
actual_size=0;
error=AEGetParamPtr (apple_event,keyErrorNumber,typeLongInteger,&returned_type,&exit_code,4,&actual_size);
if (error==noErr)
*(int*)result_string=exit_code;
else
*(int*)result_string=error;
n_free_result_string_characters-=4;
result_string+=4;
if (exit_code>=2){
int compiler_n;
compiler_n=(exit_code>>1)-1;
if ((unsigned)compiler_n<(unsigned)MAX_N_COMPILERS){
compiler_finished[compiler_n]=1;
compiler_exit_code[compiler_n]=exit_code & 1;
}
} else
++n_unknown_finished_compilers;
#if 0
{
TargetID target_id;
ProcessSerialNumber psn;
ProcessInfoRec process_info;
error=AEGetAttributePtr (apple_event,keyOriginalAddressAttr,typeTargetID,&returned_type,&target_id,sizeof (target_id),&actual_size);
if (error==noErr)
error=GetProcessSerialNumberFromPortName (&target_id.recvrName/*name*/,&psn); /* recvrName */
if (error==noErr)
error=GetProcessInformation (&psn,&process_info);
if (error==noErr){
*(int*)result_string=process_info.processSignature;
} else
*(int*)result_string=error;
n_free_result_string_characters-=4;
result_string+=4;
error=AEGetAttributePtr (apple_event,keyAddressAttr,typeTargetID,&returned_type,&target_id,sizeof (target_id),&actual_size);
if (error==noErr)
error=GetProcessSerialNumberFromPortName (&target_id.recvrName/*name*/,&psn); /* recvrName */
if (error==noErr)
error=GetProcessInformation (&psn,&process_info);
if (error==noErr){
*(int*)result_string=process_info.processSignature;
} else
*(int*)result_string=error;
n_free_result_string_characters-=4;
result_string+=4;
}
#endif
error=AEGetParamPtr (apple_event,keyErrorString,typeChar,&returned_type,result_string,n_free_result_string_characters,&actual_size);
if (error==noErr){
n_free_result_string_characters-=actual_size;
result_string+=actual_size;
}
}
return 0;
}
int install_apple_event_handlers (void)
{
OSErr r;
r=AEInstallEventHandler (kCoreEventClass,kAEOpenApplication,NewAEEventHandlerProc (DoAEOpenApplication),0,false);
if (r==noErr)
r=AEInstallEventHandler (kCoreEventClass,kAEOpenDocuments,NewAEEventHandlerProc (DoAEOpenDocuments),0,false);
if (r==noErr)
r=AEInstallEventHandler (kCoreEventClass,kAEPrintDocuments,NewAEEventHandlerProc (DoAEPrintDocuments),0,false);
if (r==noErr)
r=AEInstallEventHandler (kCoreEventClass,kAEQuitApplication,NewAEEventHandlerProc (DoAEQuitApplication),0,false);
if (r==noErr)
r=AEInstallEventHandler (kCoreEventClass,kAEApplicationDied,NewAEEventHandlerProc (DoAEApplicationDied),0,false);
if (r==noErr)
r=AEInstallEventHandler (kCoreEventClass,kAEAnswer,NewAEEventHandlerProc (DoAEAnswer),0,false);
if (r==noErr)
r=AEInstallEventHandler (kAEMiscStandards,kAEDoScript,NewAEEventHandlerProc (DoAEScript),0,false);
return r;
}
#if 1
int search_appdied_event (void)
{
EventRecord theEvent;
if (EventAvail(kHighLevelEvent,&theEvent))
return ((((AEEventID)theEvent.where) == kAEApplicationDied) && (theEvent.message == kCoreEventClass))
return 0;
}
#else
static pascal Boolean AppDiedFilter (void *dataPtr, HighLevelEventMsg *msgBuff, const TargetID *sender)
{
if ((msgBuff->theMsgEvent.message == kCoreEventClass)
&& (((AEEventID)(msgBuff->theMsgEvent.where)) == (AEEventID)kAEApplicationDied)
)
return 1;
return 0;
}
int search_appdied_event (void)
{
OSErr r;
Boolean ret;
ret = GetSpecificHighLevelEvent(NewGetSpecificFilterUPP(AppDiedFilter), 0, &r);
return ret;
}
#endif
int handle_apple_event (EventRecord *event_p,long *clean_string)
{
char *string;
int string_length;
string_length=clean_string[1];
string=(char*)&clean_string[2];
result_string=string;
n_free_result_string_characters=string_length;
AEProcessAppleEvent (event_p);
if (result_string!=NULL)
string_length=result_string-string;
else
string_length=0;
result_string=NULL;
n_free_result_string_characters=0;
return string_length;
}
int get_finished_compiler_id_and_exit_code (int *exit_code_p)
{
int compiler_n;
if (n_unknown_finished_compilers>0){
--n_unknown_finished_compilers;
*exit_code_p=1;
return -1;
}
for (compiler_n=0; compiler_n<MAX_N_COMPILERS; ++compiler_n)
if (compiler_finished[compiler_n]){
*exit_code_p=compiler_exit_code[compiler_n];
compiler_finished[compiler_n]=0;
return compiler_n;
}
*exit_code_p=0;
return -1;
}
#include <Script.h>
/* vgl Inside Mac: Text p C-24 */
long getMenuEvent (long keycode)
{
unsigned long state = 0;
void *kchrPtr = (void *)GetScriptManagerVariable(smKCHRCache); // should update when script changes...
return KeyTranslate (kchrPtr,keycode,&state);
// *char1 = (state && 0x000000FF);
// *char2 = (state && 0x00FF0000) >> 16;
}
\ No newline at end of file
CarbonLib
GetControlData
SetControlData
\ No newline at end of file
This diff is collapsed.
CarbonLib
KeyTranslate
GetScriptManagerVariable
\ No newline at end of file
CarbonLib
SetControlViewSize
SetControl32BitMinimum
GetControl32BitMinimum
SetControl32BitMaximum
GetControl32BitMaximum
SetControl32BitValue
GetControl32BitValue
\ No newline at end of file
definition module controlclip
from controls import ControlHandle
from quickdraw import GrafPtr
import wstate
//trackClippedControl :: !OSWindowPtr !Rect !ControlHandle !Point2 !*OSToolbox -> (!Int,!*OSToolbox)
//trackRectArea :: !OSWindowPtr !Rect !Rect !*OSToolbox -> (!Bool,!*OSToolbox)
//trackCustomButton :: !OSWindowPtr !Rect !Rect !*OSToolbox -> (!Bool,!*OSToolbox)
//setClippedControlValue :: !OSWindowPtr !Rect !ControlHandle !Int !*OSToolbox -> *OSToolbox
//hiliteClippedControl :: !OSWindowPtr !Rect !ControlHandle !Int !*OSToolbox -> *OSToolbox
//scrollClippedRect :: !Vector2 !Rect !*OSToolbox -> (![Rect],!*OSToolbox)
/*
calcUpdateRgn :: ![Rect] !*OSToolbox -> (!OSRgnHandle,!*OSToolbox)
calcDialogClip :: !Rect !(Maybe Id) ![WElementHandle .ls .ps] !*OSToolbox -> (!OSRgnHandle,![WElementHandle .ls .ps],!*OSToolbox)
calcDialogClip` :: !Rect !(Maybe Id) ![WElementHandle`] !*OSToolbox -> (!OSRgnHandle,!*OSToolbox)
*/
//openClipDrawing :: !OSWindowPtr !*OSToolbox -> (!GrafPtr,!OSRgnHandle,!*OSToolbox)
//closeClipDrawing :: !GrafPtr !OSRgnHandle !*OSToolbox -> *OSToolbox
This diff is collapsed.
definition module controlkeyfocus
import windowhandle
from commondef import IdFun
getDeactivateKeyInputItem :: !OSWindowPtr !Rect !*KeyFocus !Point2 ![WElementHandle .ls .ps]
-> (!*KeyFocus,!IdFun *OSToolbox,![WElementHandle .ls .ps])
implementation module controlkeyfocus
import StdInt, StdBool, StdFunc
from quickdraw import GrafPtr, QEraseRect, QFrameRect, QClipRect
import textedit
import commondef, keyfocus, windowaccess
from windowaccess import getCompoundContentRect
from controlclip import openClipDrawing, closeClipDrawing
import ossystem
/* getDeactivateKeyInputItem yields the system feedback function (IdFun Toolbox) of the
window item that currently has the keyboard input focus. This function can then be
used to provide the proper feedback for deactivating that item.
*/
getDeactivateKeyInputItem :: !OSWindowPtr !Rect !*KeyFocus !Point2 ![WElementHandle .ls .ps]
-> (!*KeyFocus,!IdFun *OSToolbox,![WElementHandle .ls .ps])
getDeactivateKeyInputItem wPtr clipRect kf mousePos itemHs
# (opt_kfNr,kf) = getCurrentFocusItem kf
| isNothing opt_kfNr
= (kf,id,itemHs)
# (_,f,itemHs) = getDeactivateKeyInputItem` wPtr clipRect (fromJust opt_kfNr) mousePos itemHs
= (kf,f,itemHs)
where
getDeactivateKeyInputItem` :: !OSWindowPtr !Rect !Int !Point2 ![WElementHandle .ls .ps]
-> (!Bool,!IdFun *OSToolbox,![WElementHandle .ls .ps])
getDeactivateKeyInputItem` wPtr clipRect kfNr mousePos [itemH:itemHs]
# (found,f,itemH) = getDeactivate wPtr clipRect kfNr mousePos itemH
| found
= (found,f,[itemH:itemHs])
# (found,f,itemHs)= getDeactivateKeyInputItem` wPtr clipRect kfNr mousePos itemHs
= (found,f,[itemH:itemHs])
where
getDeactivate :: !OSWindowPtr !Rect !Int !Point2 !(WElementHandle .ls .ps) -> (!Bool,!IdFun *OSToolbox,!WElementHandle .ls .ps)
getDeactivate wPtr clipRect kfNr mousePos (WListLSHandle itemHs)
# (found,f,itemHs) = getDeactivateKeyInputItem` wPtr clipRect kfNr mousePos itemHs
= (found,f,WListLSHandle itemHs)
getDeactivate wPtr clipRect kfNr mousePos (WExtendLSHandle dExH=:{wExtendItems=itemHs})
# (found,f,itemHs) = getDeactivateKeyInputItem` wPtr clipRect kfNr mousePos itemHs
= (found,f,WExtendLSHandle {dExH & wExtendItems=itemHs})
getDeactivate wPtr clipRect kfNr mousePos (WChangeLSHandle dChH=:{wChangeItems=itemHs})
# (found,f,itemHs) = getDeactivateKeyInputItem` wPtr clipRect kfNr mousePos itemHs
= (found,f,WChangeLSHandle {dChH & wChangeItems=itemHs})
getDeactivate wPtr clipRect kfNr mousePos (WItemHandle itemH)
# (found,f,itemH) = getDeactivate` wPtr clipRect kfNr mousePos itemH
= (found,f,WItemHandle itemH)
where
getDeactivate` :: !OSWindowPtr !Rect !Int !Point2 !(WItemHandle .ls .ps) -> (!Bool,!IdFun *OSToolbox,!WItemHandle .ls .ps)
getDeactivate` wPtr clipRect kfNr mousePos itemH=:{wItemKind=IsEditControl,wItemPtr = hTE,wItemNr,wItemPos,wItemSize}
# itemH = itemH
| kfNr<>wItemNr
= (False,id,itemH)
| PointInRect mousePos ( marginRect)
= (True,id,itemH)
= (True,deactivateEditControl wPtr clipRect hTE marginRect,itemH)
where
itemRect = PosSizeToRect wItemPos wItemSize
(l,t, r,b) = toTuple4 itemRect
marginRect = fromTuple4 (l-3,t-3, r+3,b+3)
// hTE = itemH.wItemPtr
deactivateEditControl :: !OSWindowPtr !Rect !TEHandle !Rect !*OSToolbox -> *OSToolbox
deactivateEditControl wPtr clipRect hTE rect tb
# (port,rgn,tb) = openClipDrawing wPtr tb
tb = QClipRect clipRect tb
tb = TEDeactivate hTE tb
tb = QEraseRect rect tb
tb = QFrameRect rect tb
tb = TEUpdate rect hTE tb
tb = closeClipDrawing port rgn tb
= tb
getDeactivate` wPtr clipRect kfNr mousePos itemH=:{wItemKind=IsCustomControl,wItemNr}
= (kfNr==wItemNr,id,itemH)
getDeactivate` wPtr clipRect kfNr mousePos itemH=:{wItemKind=IsCompoundControl,wItems}
# (found,f,itemHs) = getDeactivateKeyInputItem` wPtr (IntersectRects clipRect1 clipRect) kfNr mousePos wItems
itemH = {itemH & wItems=itemHs}
= (found,f,itemH)
where
itemRect = PosSizeToRect itemH.wItemPos itemH.wItemSize
clipRect1 = getCompoundContentRect wMetrics (hasHScroll, hasVScroll) itemRect
info = getWItemCompoundInfo ( itemH.wItemInfo)
hasHScroll = isJust info.compoundHScroll
hasVScroll = isJust info.compoundVScroll
(wMetrics,_) = OSDefaultWindowMetrics OSNewToolbox
getDeactivate` _ _ _ _ itemH
= (False,id,itemH)
getDeactivateKeyInputItem` _ _ _ _ _
= (False,id,[])