Skip to content

Commit

Permalink
MacOS
Browse files Browse the repository at this point in the history
git-svn-id: svn+ssh://yquem.inria.fr/net/yquem/devel/caml/svn/ocaml/trunk@2527 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
  • Loading branch information
doligez committed Nov 15, 1999
1 parent 8e651b7 commit 468ae44
Show file tree
Hide file tree
Showing 14 changed files with 276 additions and 111 deletions.
12 changes: 6 additions & 6 deletions Makefile.Mac.depend
Expand Up @@ -100,12 +100,12 @@
:parsing:longident.cmi :parsing:parsetree.cmi :typing:types.cmi
:typing:btype.cmo� :typing:path.cmi :typing:types.cmi :typing:btype.cmi
:typing:btype.cmx� :typing:path.cmx :typing:types.cmx :typing:btype.cmi
:typing:ctype.cmo� :parsing:asttypes.cmi :typing:btype.cmi :typing:env.cmi
:typing:ident.cmi :utils:misc.cmi :typing:path.cmi :typing:subst.cmi �
:typing:types.cmi :typing:ctype.cmi
:typing:ctype.cmx� :parsing:asttypes.cmi :typing:btype.cmx :typing:env.cmx �
:typing:ident.cmx :utils:misc.cmx :typing:path.cmx :typing:subst.cmx �
:typing:types.cmx :typing:ctype.cmi
:typing:ctype.cmo� :parsing:asttypes.cmi :typing:btype.cmi :utils:clflags.cmo
:typing:env.cmi :typing:ident.cmi :utils:misc.cmi :typing:path.cmi �
:typing:subst.cmi :typing:types.cmi :typing:ctype.cmi
:typing:ctype.cmx� :parsing:asttypes.cmi :typing:btype.cmx :utils:clflags.cmx �
:typing:env.cmx :typing:ident.cmx :utils:misc.cmx :typing:path.cmx �
:typing:subst.cmx :typing:types.cmx :typing:ctype.cmi
:typing:datarepr.cmo� :parsing:asttypes.cmi :utils:misc.cmi :typing:path.cmi �
:typing:predef.cmi :typing:types.cmi :typing:datarepr.cmi
:typing:datarepr.cmx� :parsing:asttypes.cmi :utils:misc.cmx :typing:path.cmx �
Expand Down
15 changes: 9 additions & 6 deletions byterun/macintosh.c
Expand Up @@ -11,17 +11,17 @@

/* $Id$ */

/* Macintosh-specific stuff */
/* MacOS-specific stuff */

#include <stdio.h>
#include <stdlib.h>

#include <CursorCtl.h>
#include <Files.h>
#include <IntEnv.h>
#include <MacTypes.h>
#include <stdio.h>
#include <stdlib.h>
#include <Strings.h>
#include <TextUtils.h>
#include <Timer.h>

#include "rotatecursor.h"

/* The user interface defaults to MPW tool. The standalone application
overrides the ui_* functions, as well as [main], [InitCursorCtl],
Expand All @@ -35,16 +35,19 @@ void ui_exit (int return_code)

int ui_read (int file_desc, char *buf, unsigned int length)
{
ROTATECURSOR_MAGIC ();
return read (file_desc, buf, length);
}

int ui_write (int file_desc, char *buf, unsigned int length)
{
ROTATECURSOR_MAGIC ();
return write (file_desc, buf, length);
}

void ui_print_stderr (char *format, void *arg)
{
ROTATECURSOR_MAGIC ();
fprintf (stderr, format, arg);
fflush (stderr);
}
Expand Down
7 changes: 0 additions & 7 deletions byterun/rotatecursor.c
Expand Up @@ -11,13 +11,6 @@

/* $Id$ */

/* Rotatecursor library, written by Damien Doligez
This file is in the public domain.
version 1.7
See rotatecursor.h for documentation.
*/

#include <CursorCtl.h>
#include <MacTypes.h>
#include <stdlib.h>
Expand Down
20 changes: 0 additions & 20 deletions byterun/rotatecursor.h
Expand Up @@ -11,26 +11,6 @@

/* $Id$ */

/* Rotatecursor library, written by Damien Doligez
This file is in the public domain.
version 1.7
The goal of this library is to help implement cooperative multitasking
for MPW tools: to make sure that your program calls RotateCursor often
enough (about 20 times per second) but not too often (to avoid a big
slowdown). It can also be used in applications as soon as you have
an implementation of InitCursorCtl and RotateCursor (which is not hard
to do).
Simplified usage:
1. #include this file where appropriate
2. Insert the following line in the inner loop(s) of your program:
ROTATECURSOR_MAGIC ();
The overhead of this macro is only a few CPU cycles, so it can be
used without problem even in a tight loop.
*/

#ifndef _rotatecursor_
#define _rotatecursor_

Expand Down
9 changes: 4 additions & 5 deletions maccaml/drag.c
Expand Up @@ -110,7 +110,7 @@ static pascal OSErr MyTrackingHandler (DragTrackingMessage message, WindowPtr w,

static OSErr ToplevelReceiveDrag (DragReference drag, WEReference we)
{
GrafPtr (saveport);
GrafPtr saveport;
short readonly = 0;
Boolean canaccept;
OSErr err;
Expand All @@ -124,8 +124,7 @@ static OSErr ToplevelReceiveDrag (DragReference drag, WEReference we)
Size sz, curlen;
long dest, selstart, selend = -1;

GetPort (&saveport);
SetPortWindowPort (winToplevel);
PushWindowPort (winToplevel);

readonly = WEFeatureFlag (weFReadOnly, weBitTest, we);
if (readonly) WEFeatureFlag (weFReadOnly, weBitClear, we);
Expand Down Expand Up @@ -174,14 +173,14 @@ static OSErr ToplevelReceiveDrag (DragReference drag, WEReference we)
WESetSelection (dest + curlen, dest + curlen, we);

DisposeHandle (h);
SetPort (saveport);
PopPort;
return noErr;

failed:
if (h != NULL) DisposeHandle (h);
if (selend != -1) WESetSelection (selstart, selend, we);
if (readonly) WEFeatureFlag (weFReadOnly, weBitSet, we);
SetPort (saveport);
PopPort;
return err;
}

Expand Down
5 changes: 2 additions & 3 deletions maccaml/events.c
Expand Up @@ -154,13 +154,12 @@ static void DoMouseUp (EventRecord *e)
if (FrontWindow () != winGraphics) return;
partCode = FindWindow (e->where, &w);
if (partCode != inContent) return;
GetPort (&saveport);
SetPort (winGraphics);
PushWindowPort (winGraphics);
hitpt = e->where;
GlobalToLocal (&hitpt);
ScrollCalcGraph (winGraphics, &r);
if (PtInRect (hitpt, &r)) GraphGotEvent (e);
SetPort (saveport);
PopPort;
return;
}

Expand Down
13 changes: 5 additions & 8 deletions maccaml/graph.c
Expand Up @@ -184,11 +184,9 @@ void GraphGotEvent (EventRecord *evt)
Point pt = evt->where;
GraphEvent grevt;

GetPort (&saveport);
SetPort (winGraphics);
PushWindowPort (winGraphics);
GlobalToLocal (&pt);
SetPort (saveport);

PopPort;

switch (evt->what){
case mouseDown:
Expand Down Expand Up @@ -314,7 +312,7 @@ static void gr_check_open (void)
in one major GC cycle. The GC will speed up to match this allocation
speed.
*/
#define Max_image_mem 1000000 /* XXX Should use 20% of total memory */
#define Max_image_mem 1000000 /* XXX Should use user pref. */

#define Transparent (-1)

Expand Down Expand Up @@ -974,8 +972,7 @@ value gr_wait_event (value veventlist)
Point pt;

gr_check_open();
GetPort (&saveport);
SetPort (winGraphics);
PushWindowPort (winGraphics);

while (veventlist != Val_int (0)) {
switch (Int_val(Field (veventlist, 0))) {
Expand Down Expand Up @@ -1017,7 +1014,7 @@ value gr_wait_event (value veventlist)
/* Restore the grafport now because GetAndProcessEvents may longjmp
directly out of here.
*/
SetPort (saveport);
PopPort;
while (1){
latestevent.valid = 0;
enter_blocking_section ();
Expand Down
11 changes: 10 additions & 1 deletion maccaml/main.h
Expand Up @@ -29,9 +29,11 @@
#include <Fonts.h>
#include <Gestalt.h>
#include <LowMem.h>
#include <MacTypes.h>
#include <MacWindows.h>
#include <Menus.h>
#include <Power.h>
#include <Printing.h>
#include <Processes.h>
#include <QDOffscreen.h>
#include <QuickDraw.h>
Expand All @@ -44,7 +46,6 @@
#include <Strings.h>
#include <TextUtils.h>
#include <ToolUtils.h>
#include <Types.h>

#include ":WASTE-1.2:WASTE C/C++ Headers:WASTE.h"

Expand Down Expand Up @@ -240,3 +241,11 @@ void WinGraphicsStdState (Rect *r);
void WinToplevelStdState (Rect *r);
void WinUpdate (WindowPtr w);
void WinUpdateStatus (WindowPtr w);

/* useful macros */

/* PushPort and PopPort assume that there is a local variable [saveport] */
#define PushPort(p) do{ GetPort (&saveport); SetPort (p); }while(0)
#define PushWindowPort(w) \
do{ GetPort (&saveport); SetPortWindowPort (w); }while(0)
#define PopPort do{ SetPort (saveport); }while(0)
105 changes: 105 additions & 0 deletions maccaml/print.c
Expand Up @@ -13,6 +13,111 @@

#include "main.h"

static short (*get_npages) (THPrint printrec);
static short (*draw_page) (THPrint printrec, TPPrPort port, int pagenum);

static THPrint curjobprintrec = NULL;

/*
dojobdialog = 0 -> no job dialog (use default settings)
dojobdialog = 1 -> use job dialog
dojobdialog = 2 -> no job dialog (use previous dialog settings)
*/
static short print_loop (int dojobdialog, THPrint docprintrec)
{
short ncopies, fstpage, lstpage, npages;
OSErr err;
GrafPtr saveport;
TPPrPort printerport;
TPrStatus prstatus;
int copy, page, pgrun;

GetPort (&saveport);

PrOpen ();
err = PrError (); if (err != noErr) goto failed_PrOpen;

PrValidate (docprintrec);
err = PrError (); if (err != noErr) goto failed_PrValidate;

npages = (*get_npages) (docprintrec);
switch (dojobdialog){
case 0:
if (curjobprintrec != NULL) DisposeHandle ((Handle) curjobprintrec);
curjobprintrec = (THPrint) NewHandle (sizeof (TPrint));
if (curjobprintrec == NULL) goto failed_alloc_curjobprintrec;
PrintDefault (curjobprintrec);
PrJobMerge (curjobprintrec, docprintrec);
break;
case 1:
err = PrJobDialog (docprintrec);
if (err) goto failed_PrJobDialog;
if (curjobprintrec != NULL) DisposeHandle ((Handle) curjobprintrec);
curjobprintrec = docprintrec;
HandToHand ((Handle *) &curjobprintrec);
if (curjobprintrec == NULL) goto failed_alloc_curjobprintrec;
break;
case 2:
PrJobMerge (curjobprintrec, docprintrec);
break;
}
ncopies = (*docprintrec)->prJob.iCopies;
fstpage = (*docprintrec)->prJob.iFstPage;
lstpage = (*docprintrec)->prJob.iLstPage;
if (lstpage > npages) lstpage = npages;

/* XXX Should display a status dialog box and use a IdleProc function */

for (copy = 0; copy < ncopies; copy++){
printerport = PrOpenDoc (docprintrec, NULL, NULL);
err = PrError (); if (err != noErr) goto failed_PrOpenDoc;
pgrun = 0;
for (page = fstpage; page <= lstpage; page++){
if (pgrun >= iPFMaxPgs){
PrCloseDoc (printerport);
err = PrError (); if (err != noErr) goto failed_PrCloseDoc;
if ((*docprintrec)->prJob.bJDocLoop == bSpoolLoop){
PrPicFile (docprintrec, NULL, NULL, NULL, &prstatus);
}
printerport = PrOpenDoc (docprintrec, NULL, NULL);
err = PrError (); if (err != noErr) goto failed_PrOpenDoc;
pgrun = 0;
}
PrOpenPage (printerport, NULL);
err = PrError (); if (err != noErr) goto failed_PrOpenPage;
err = (*draw_page) (docprintrec, printerport, page);
if (err != noErr) goto failed_draw_page;
PrClosePage (printerport);
++ pgrun;
}
PrCloseDoc (printerport);
err = PrError (); if (err != noErr) goto failed_PrCloseDoc;
if ((*docprintrec)->prJob.bJDocLoop == bSpoolLoop){
PrPicFile (docprintrec, NULL, NULL, NULL, &prstatus);
}
}
PrClose ();
/*XXX close status dialog box here */
SetPort (saveport);
return noErr;

failed_draw_page:
PrClosePage (printerport);
/* fall through */
failed_PrOpenPage:
PrCloseDoc (printerport);
/* fall through */
failed_PrOpenDoc:
failed_PrCloseDoc:
failed_alloc_curjobprintrec:
failed_PrJobDialog:
failed_PrValidate:
PrClose ();
/* fall through */
failed_PrOpen:
return err;
}

void FilePageSetup (void)
{
XXX ();
Expand Down
10 changes: 4 additions & 6 deletions maccaml/scroll.c
Expand Up @@ -51,8 +51,7 @@ void AdjustScrollBars (WindowPtr w)
long xmax, xval, ymax, yval;
long h;

GetPort (&saveport);
SetPort (w);
PushWindowPort (w);

st = WinGetStatus (w);
Assert (st != NULL);
Expand Down Expand Up @@ -83,7 +82,7 @@ void AdjustScrollBars (WindowPtr w)

if (xval > xmax || yval > ymax) AdjustView (st);

SetPort (saveport);
PopPort;
}

/* Callback procedure for auto-scrolling the text. (called by WASTE) */
Expand Down Expand Up @@ -258,8 +257,7 @@ void ScrollNewSize (WindowPtr w)

Assert (st != NULL);

GetPort (&saveport);
SetPort (w);
PushWindowPort (w);

bar = (*st)->scrollbars[H];
r.left = port.left - 1;
Expand Down Expand Up @@ -297,7 +295,7 @@ void ScrollNewSize (WindowPtr w)

AdjustScrollBars (w);

SetPort (saveport);
PopPort;
}

/* Return 1 if the vertical scroll bar is at its max setting, 0 otherwise.
Expand Down

0 comments on commit 468ae44

Please sign in to comment.