E int FDECL(macread, (int,void *,unsigned));
E int FDECL(macwrite, (int,void *,unsigned));
E long FDECL(macseek, (int,long,short));
+E int FDECL(macunlink, (const char *));
/* ### macsnd.c ### */
#ifndef __powerc
# define MAC68K /* 68K mac (non-powerpc) */
#endif
+#ifndef TARGET_API_MAC_CARBON
+# define TARGET_API_MAC_CARBON 0
+#endif
+
+#ifndef __MACH__
#define RANDOM
+#endif
#define NO_SIGNAL /* You wouldn't believe our signals ... */
#define FILENAME 256
#define NO_TERMS /* For tty port (see wintty.h) */
* Try and keep the number of files here to an ABSOLUTE minimum !
* include the relevant files in the relevant .c files instead !
*/
-#include <MacTypes.h>
+#if TARGET_API_MAC_CARBON
+ /* Avoid including <CarbonCore/fp.h> -- it has a conflicting expl() */
+# define __FP__
+# include <Carbon/Carbon.h>
+#else
+# include <MacTypes.h>
+#endif
/*
* We could use the PSN under sys 7 here ...
* MPW. With MPW, we make them into MPW tools, which use unix IO. SPEC_LEV
* and DGN_COMP are defined when compiling for LevComp and DgnComp respectively.
*/
-#if !((defined(__SC__) || defined(__MRC__)) && (defined(SPEC_LEV) || defined(DGN_COMP)))
+#if !((defined(__SC__) || defined(__MRC__) || defined(__MACH__)) && (defined(SPEC_LEV) || defined(DGN_COMP)))
# define creat maccreat
# define open macopen
# define close macclose
/* ### mmodal.c ### */
-extern void FlashButton(WindowPtr, short);
+extern void FlashButton(DialogRef, short);
extern char queued_resp(char *resp);
extern char topl_yn_function(const char *query, const char *resp, char def);
extern int get_line_from_key_queue(char *bufp);
#undef red /* undef internal color const strings from decl */
#undef green
#undef blue
-#include <windows.h>
+#if !TARGET_API_MAC_CARBON
+# include <windows.h>
+#endif
/*
* Error code returned when it's probably our fault, or
#undef red /* undef internal color const strings from decl */
#undef green
#undef blue
+
+#ifndef __MACH__
#include <windows.h>
#include <dialogs.h>
+#endif
/* more headers */
#ifdef THINK_C
#define PLAYER_NAME_RES_ID 1001
/* fake some things if we don't have universal headers.. */
-#ifndef NewUserItemProc
+#if 0 /*ndef NewUserItemProc*/
typedef pascal void (*UserItemProcPtr)(WindowPtr theWindow, short itemNo);
typedef UserItemProcPtr UserItemUPP;
#define NewUserItemProc(p) (UserItemUPP)(p)
#include "mactty.h"
# endif
-#include <QDOffscreen.h>
-#include <Gestalt.h>
-#include <Errors.h>
+#if !TARGET_API_MAC_CARBON
+# include <QDOffscreen.h>
+# include <Gestalt.h>
+# include <Errors.h>
+#endif
#define TA_TO_RGB(ta,rgb) (((rgb).red=(((ta)>>16)&0xff)*257),((rgb).green=(((ta)>>8)&0xff)*257),\
((rgb).blue=((ta)&0xff)*257)),rgb
#endif
#endif
+#ifdef MAC
+# define unlink macunlink
+#endif
+
#ifdef USER_SOUNDS
extern char *sounddir;
#endif
}
#endif
}
+#ifndef MAC
gottype:
+#endif
#endif
for(sroom = &rooms[0]; ; sroom++){
if(sroom->hx < 0) return;
void
initoptions()
{
+#ifndef MAC
char *opts;
+#endif
int i;
/* initialize the random number generator */
#include "date.h"
#include "patchlevel.h"
+resource 'plst' (0, purgeable) {
+};
+
resource 'vers' (1, purgeable) {
VERSION_MAJOR, (VERSION_MINOR<<4) | PATCHLEVEL, final, EDITLEVEL, verUS,
VERSION_STRING,
#include "mactty.h"
#include "macwin.h"
+#if !TARGET_API_MAC_CARBON
#include <Folders.h>
#include <TextUtils.h>
#include <Resources.h>
+#endif
static Boolean winFileInit = 0;
*left = p.h;
*top = p.v;
dprintf ("Retrieve Kind %d Pt (%d,%d)", kind, p.h, p.v);
- return PtInRgn (p, GetGrayRgn ());
+ return (PtInRgn (p, GetGrayRgn ()));
}
dprintf ("Save bad kind %d", kind);
return;
}
- InitWinFile ();
- savePos [kind].validPos = 1;
- savePos [kind].top = top;
- savePos [kind].left = left;
- dprintf ("Save kind %d pt (%d,%d)", kind, left, top);
- FlushWinFile ();
+ InitWinFile();
+ savePos[kind].validPos = 1;
+ savePos[kind].top = top;
+ savePos[kind].left = left;
+ dprintf("Save kind %d pt (%d,%d)", kind, left, top);
+ FlushWinFile();
}
if (!CheckNhWin (win)) {
return -1;
}
- kind = ((WindowPeek) win)->windowKind - WIN_BASE_KIND;
+ kind = GetWindowKind(win) - WIN_BASE_KIND;
if (kind < 0 || kind > NHW_TEXT) {
return -1;
}
Boolean
-RetrieveWinPos (WindowPtr win, short *top, short *left)
-{ return RetrievePosition (GetWinKind (win), top, left);
+RetrieveWinPos(WindowPtr win, short *top, short *left)
+{
+ return RetrievePosition(GetWinKind (win), top, left);
}
void
-SaveWindowPos (WindowPtr win)
+SaveWindowPos(WindowPtr win)
{
- GrafPtr gp;
- Point p = { 0, 0 };
-
- GetPort (&gp);
- SetPort (win);
- LocalToGlobal (&p);
- AddPt (*(Point *) &(win->portRect), &p); /* Adjust for origin */
- SetPort (gp);
- SavePosition (GetWinKind (win), p.v, p.h);
+ Rect r;
+
+
+ GetWindowBounds(win, kWindowContentRgn, &r);
+ SavePosition(GetWinKind(win), r.top, r.left);
}
void
-SaveWindowSize (WindowPtr win)
+SaveWindowSize(WindowPtr win)
{
short width, height;
+ Rect r;
+
- width = win->portRect.right - win->portRect.left;
- height = win->portRect.bottom - win->portRect.top;
- SaveSize (GetWinKind (win), height, width);
+ GetWindowBounds(win, kWindowContentRgn, &r);
+ width = r.right - r.left;
+ height = r.bottom - r.top;
+ SaveSize(GetWinKind (win), height, width);
}
#include "hack.h"
#include "macwin.h"
+#if !TARGET_API_MAC_CARBON
#include <Dialogs.h>
#include <TextUtils.h>
#include <Resources.h>
+#endif
void error(const char *format,...)
#include "hack.h"
#include "macwin.h"
+
+#ifndef __MACH__
#include <files.h>
#include <errors.h>
#include <resources.h>
#include <memory.h>
#include <TextUtils.h>
#include <ToolUtils.h>
+#endif
+
#include "dlb.h"
/*
}
+int
+macunlink(const char *name)
+{
+ Str255 pname;
+
+
+ C2P(name, pname);
+ return (HDelete(theDirs.dataRefNum, theDirs.dataDirID, pname) == noErr ? 0 : -1);
+}
+
+
+
/* ---------------------------------------------------------------------- */
boolean rsrc_dlb_init(void) {
#include "macwin.h"
#include "mactty.h"
+#if !TARGET_API_MAC_CARBON
#include <OSUtils.h>
#include <files.h>
#include <Types.h>
#include <ToolUtils.h>
#include <Resources.h>
#include <Errors.h>
+#endif
#ifndef O_RDONLY
#include <fcntl.h>
#include "patchlevel.h"
/******** Toolbox Defines ********/
+#if !TARGET_API_MAC_CARBON
#include <Menus.h>
#include <Devices.h>
#include <Resources.h>
#include <TextUtils.h>
#include <ToolUtils.h>
#include <Sound.h>
+#endif
+
+/* Borrowed from the Mac tty port */
+extern WindowPtr _mt_window;
/******** Local Defines ********/
/******** Prototypes ********/
+#if !TARGET_API_MAC_CARBON
static void alignAD(Rect *, short);
+#endif
static void mustGetMenuAlerts(void);
static void menuError(short);
-static pascal void drawANUserItem(WindowPtr, short);
static void aboutNetHack(void);
-static void optionEditor(void);
static void askSave(void);
static void askQuit(void);
#define CH_ESCAPE 0x001b
static void ask_restring(const char *cstr, unsigned char *pstr);
-static void ask_enable(WindowPtr wind, short item, int enable);
-static pascal void ask_redraw(WindowPtr wind, DialogItemIndex item);
-static pascal Boolean ask_filter(WindowPtr wind, EventRecord *event, DialogItemIndex *item);
+static void ask_enable(DialogRef wind, short item, int enable);
+static pascal void ask_redraw(DialogRef wind, DialogItemIndex item);
+static pascal Boolean ask_filter(DialogRef wind, EventRecord *event, DialogItemIndex *item);
#define noresource(t,n) {SysBeep(3); ExitToShell();}
#define fatal(s) {SysBeep(3); ExitToShell();}
static RGBColor
blackcolor = {0x0000, 0x0000, 0x0000},
- indentcolor = {0x4000, 0x4000, 0x4000},
+// indentcolor = {0x4000, 0x4000, 0x4000},
darkcolor = {0x8000, 0x8000, 0x8000},
backcolor = {0xdddd, 0xdddd, 0xdddd},
lightcolor = {0xffff, 0xffff, 0xffff},
/* Enable the dialog item with the given index */
static void
-ask_enable (WindowPtr wind, short item, int enable)
+ask_enable (DialogRef wind, short item, int enable)
{
short type;
Handle handle;
static pascal void
-ask_redraw (WindowPtr wind, DialogItemIndex item)
+ask_redraw (DialogRef wind, DialogItemIndex item)
{
short type;
Handle handle;
static pascal Boolean
-ask_filter (WindowPtr wind, EventRecord *event, DialogItemIndex *item)
+ask_filter (DialogRef wind, EventRecord *event, DialogItemIndex *item)
{
short ch, key;
/* Handle equivalents for OK */
if ((ch == CH_RETURN) || (key == KEY_RETURN) ||
(ch == CH_ENTER) || (key == KEY_ENTER)) {
- if ((*((DialogRecord *)wind)->textH)->teLength) {
+ if (GetDialogTextEditHandle(wind)[0]->teLength) {
FlashButton(wind, RSRC_ASK_PLAY);
*item = RSRC_ASK_PLAY;
} else
void mac_askname ()
{
GrafPtr oldport;
- WindowPtr askdialog;
+ DialogRef askdialog;
short i, j, item, type;
Handle handle;
Rect rect;
Str255 str;
Point pt;
- UserItemUPP redraw = NewUserItemProc(ask_redraw);
- ModalFilterUPP filter = NewModalFilterProc(ask_filter);
+ UserItemUPP redraw = NewUserItemUPP(ask_redraw);
+ ModalFilterUPP filter = NewModalFilterUPP(ask_filter);
/* Create the dialog */
- if (!(askdialog = GetNewDialog(RSRC_ASK, NULL, (WindowPtr)-1)))
+ if (!(askdialog = GetNewDialog(RSRC_ASK, NULL, (WindowRef)-1)))
noresource('DLOG', RSRC_ASK);
GetPort(&oldport);
- SetPort(askdialog);
+ SetPortDialogPort(askdialog);
/* Initialize the name text item */
ask_restring(plname, str);
do {
/* Adjust the Play button */
ask_enable(askdialog, RSRC_ASK_PLAY,
- (*((DialogRecord *)askdialog)->textH)->teLength);
+ GetDialogTextEditHandle(askdialog)[0]->teLength);
/* Adjust the race popup menu */
i = j = currrace;
do {
if (validrace(currrole, j)) {
- EnableItem(askmenu[RSRC_ASK_RACE], j+1);
- CheckItem(askmenu[RSRC_ASK_RACE], j+1,
+ EnableMenuItem(askmenu[RSRC_ASK_RACE], j+1);
+ CheckMenuItem(askmenu[RSRC_ASK_RACE], j+1,
currrace == j);
} else {
- DisableItem(askmenu[RSRC_ASK_RACE], j+1);
- CheckItem(askmenu[RSRC_ASK_RACE], j+1, FALSE);
+ DisableMenuItem(askmenu[RSRC_ASK_RACE], j+1);
+ CheckMenuItem(askmenu[RSRC_ASK_RACE], j+1, FALSE);
if ((currrace == j) && !races[++currrace].noun)
currrace = 0;
}
} while (i != j);
if (currrace != i) {
GetDialogItem(askdialog, RSRC_ASK_RACE, &type, &handle, &rect);
- InvalRect(&rect);
+ InvalWindowRect(GetDialogWindow(askdialog), &rect);
}
/* Adjust the gender popup menu */
i = j = currgend;
do {
if (validgend(currrole, currrace, j)) {
- EnableItem(askmenu[RSRC_ASK_GEND], j+1);
- CheckItem(askmenu[RSRC_ASK_GEND], j+1,
+ EnableMenuItem(askmenu[RSRC_ASK_GEND], j+1);
+ CheckMenuItem(askmenu[RSRC_ASK_GEND], j+1,
currgend == j);
} else {
- DisableItem(askmenu[RSRC_ASK_GEND], j+1);
- CheckItem(askmenu[RSRC_ASK_GEND], j+1, FALSE);
+ DisableMenuItem(askmenu[RSRC_ASK_GEND], j+1);
+ CheckMenuItem(askmenu[RSRC_ASK_GEND], j+1, FALSE);
if ((currgend == j) && (++currgend >= ROLE_GENDERS))
currgend = 0;
}
} while (i != j);
if (currgend != i) {
GetDialogItem(askdialog, RSRC_ASK_GEND, &type, &handle, &rect);
- InvalRect(&rect);
+ InvalWindowRect(GetDialogWindow(askdialog), &rect);
}
/* Adjust the alignment popup menu */
i = j = curralign;
do {
if (validalign(currrole, currrace, j)) {
- EnableItem(askmenu[RSRC_ASK_ALIGN], j+1);
- CheckItem(askmenu[RSRC_ASK_ALIGN], j+1,
+ EnableMenuItem(askmenu[RSRC_ASK_ALIGN], j+1);
+ CheckMenuItem(askmenu[RSRC_ASK_ALIGN], j+1,
curralign == j);
} else {
- DisableItem(askmenu[RSRC_ASK_ALIGN], j+1);
- CheckItem(askmenu[RSRC_ASK_ALIGN], j+1, FALSE);
+ DisableMenuItem(askmenu[RSRC_ASK_ALIGN], j+1);
+ CheckMenuItem(askmenu[RSRC_ASK_ALIGN], j+1, FALSE);
if ((curralign == j) && (++curralign >= ROLE_ALIGNS))
curralign = 0;
}
} while (i != j);
if (curralign != i) {
GetDialogItem(askdialog, RSRC_ASK_ALIGN, &type, &handle, &rect);
- InvalRect(&rect);
+ InvalWindowRect(GetDialogWindow(askdialog), &rect);
}
/* Adjust the role popup menu */
ask_restring((currgend && roles[i].name.f) ?
roles[i].name.f : roles[i].name.m, str);
SetMenuItemText(askmenu[RSRC_ASK_ROLE], i+1, str);
- CheckItem(askmenu[RSRC_ASK_ROLE], i+1, currrole == i);
+ CheckMenuItem(askmenu[RSRC_ASK_ROLE], i+1, currrole == i);
}
/* Adjust the mode popup menu */
- CheckItem(askmenu[RSRC_ASK_MODE], 1, currmode == 0);
- CheckItem(askmenu[RSRC_ASK_MODE], 2, currmode == 1);
+ CheckMenuItem(askmenu[RSRC_ASK_MODE], 1, currmode == 0);
+ CheckMenuItem(askmenu[RSRC_ASK_MODE], 2, currmode == 1);
#ifdef WIZARD
- CheckItem(askmenu[RSRC_ASK_MODE], 3, currmode == 2);
+ CheckMenuItem(askmenu[RSRC_ASK_MODE], 3, currmode == 2);
#endif
/* Wait for an action on an item */
if (!!(i = PopUpMenuSelect(askmenu[item], pt.v, pt.h,
askselect[item] + 1)))
askselect[item] = LoWord(i) - 1;
- InvalRect(&rect);
+ InvalWindowRect(GetDialogWindow(askdialog), &rect);
break;
case RSRC_ASK_NAME:
#if 0
/*** Menu bar routines ***/
+#if !TARGET_API_MAC_CARBON
static void
alignAD(Rect *pRct, short vExempt)
{
+ BitMap qbitmap;
+
+
+ GetQDGlobalsScreenBits(&qbitmap);
(*pRct).right -= (*pRct).left; /* width */
(*pRct).bottom -= (*pRct).top; /* height */
- (*pRct).left = (qd.screenBits.bounds.right - (*pRct).right) / 2;
- (*pRct).top = (qd.screenBits.bounds.bottom - (*pRct).bottom - vExempt) / 2;
+ (*pRct).left = (qbitmap.bounds.right - (*pRct).right) / 2;
+ (*pRct).top = (qbitmap.bounds.bottom - (*pRct).bottom - vExempt) / 2;
(*pRct).top += vExempt;
(*pRct).right += (*pRct).left;
(*pRct).bottom += (*pRct).top;
}
+#endif
+
static void
mustGetMenuAlerts()
{
- short i, mbarHgt = GetMBarHeight();
+ short i;
Rect **hRct;
for (i = alrt_Menu_start; i < alrt_Menu_limit; i++)
ExitToShell();
}
- alignAD(*hRct, mbarHgt);
+#if !TARGET_API_MAC_CARBON
+ alignAD(*hRct, GetMBarHeight());
+#endif
}
}
static Boolean was_inited = 0;
short i, j;
menuListHandle mlHnd;
- MenuHandle mHnd;
+ MenuHandle menu;
if (was_inited)
return;
mustGetMenuAlerts();
- for (i = listMenubar; i <= listSubmenu; i++)
- {
+ for (i = listMenubar; i <= listSubmenu; i++) {
if (! (mlHnd = (menuListHandle) GetResource('MNU#', (menuBarListID + i))))
menuError(errGetMenuList);
- pMenuList[i] = *mlHnd;
+ pMenuList[i] = (menuListPtr) NewPtr(GetHandleSize((Handle) mlHnd));
+ *pMenuList[i] = **mlHnd;
- for (j = 0; j < (**mlHnd).numMenus; j++)
+ for (j = 0; j < pMenuList[i]->numMenus; j++)
{
- if (! (mHnd = (MenuHandle) GetMenu((**mlHnd).mref[j].mresID))) {
+ if (! (menu = (MenuHandle) GetMenu((**mlHnd).mref[j].mresID))) {
Str31 d;
NumToString ((**mlHnd).mref[j].mresID, d);
menuError(errGetMenu);
}
- (**mlHnd).mref[j].mhnd = mHnd;
- * ((short *) *mHnd) = j + (**mlHnd).firstMenuID; /* consecutive IDs */
+ pMenuList[i]->mref[j].mhnd = menu;
+ SetMenuID(menu, j + (**mlHnd).firstMenuID); /* consecutive IDs */
/* expand apple menu */
if ((i == listMenubar) && (j == menuApple)) {
- AppendResMenu(mHnd, 'DRVR');
+ AppendResMenu(menu, 'DRVR');
}
- InsertMenu(mHnd, ((i == listSubmenu) ? hierMenu : 0));
+ InsertMenu(menu, ((i == listSubmenu) ? hierMenu : 0));
}
}
DrawMenuBar();
AdjustMenus(short dimMenubar)
{
short newMenubar = mbarRegular;
- WindowPeek peekWindow = (WindowPeek) FrontWindow();
+ WindowRef win = FrontWindow();
short i;
/*
* }
*/
/* determine the new menubar state */
- if (dimMenubar) {
+ if (dimMenubar)
newMenubar = mbarDim;
- } else if (! peekWindow) {
+ else if (!win)
newMenubar = mbarNoWindows;
- } else if (peekWindow->windowKind < 0) {
+ else if (GetWindowKind(win) < 0)
newMenubar = mbarDA;
- } else {
- while (peekWindow && (peekWindow->windowKind != WKND_MAP)) {
- peekWindow = peekWindow->nextWindow;
- }
- if ((! peekWindow) || (! peekWindow->visible)) {
- newMenubar = mbarNoMap;
- }
- }
+ else if (!IsWindowVisible(_mt_window))
+ newMenubar = mbarNoMap;
if (newMenubar != mbarRegular)
; /* we've already found its state */
SetMenuItemText(MHND_FILE, menuFilePlayMode, "\pExplore");
- for (i = CountMItems(MHND_WIZ); i > menuWizardAttributes; i--)
+ for (i = CountMenuItems(MHND_WIZ); i > menuWizardAttributes; i--)
DeleteMenuItem(MHND_WIZ, i);
}
}
case mbarDim:
/* disable all menus (except the apple menu) */
for (i = menuFile; i < NUM_MBAR; i++)
- DisableItem(MBARHND(i), 0);
+ DisableMenuItem(MBARHND(i), 0);
break;
case mbarNoWindows:
case mbarDA:
case mbarNoMap:
/* enable the file menu, but ... */
- EnableItem(MHND_FILE, 0);
+ EnableMenuItem(MHND_FILE, 0);
/* ... disable the window commands! */
for (i = menuFileRedraw; i <= menuFileEnterExplore; i++)
- DisableItem(MHND_FILE, i);
+ DisableMenuItem(MHND_FILE, i);
/* ... and disable the rest of the menus */
for (i = menuEdit; i < NUM_MBAR; i++)
- DisableItem(MBARHND(i), 0);
+ DisableMenuItem(MBARHND(i), 0);
if (theMenubar == mbarDA)
- EnableItem(MHND_EDIT, 0);
+ EnableMenuItem(MHND_EDIT, 0);
break;
case mbarSpecial:
/* enable all menus ... */
for (i = menuFile; i < NUM_MBAR; i++)
- EnableItem(MBARHND(i), 0);
+ EnableMenuItem(MBARHND(i), 0);
/* ... except the unused Edit menu */
- DisableItem(MHND_EDIT, 0);
+ DisableMenuItem(MHND_EDIT, 0);
/* ... enable the window commands */
for (i = menuFileRedraw; i <= menuFileEnterExplore; i++)
- EnableItem(MHND_FILE, i);
+ EnableMenuItem(MHND_FILE, i);
if (theMenubar == mbarRegular)
- DisableItem(MHND_FILE, menuFilePlayMode);
+ DisableMenuItem(MHND_FILE, menuFilePlayMode);
else
- DisableItem(MHND_FILE, menuFileEnterExplore);
+ DisableMenuItem(MHND_FILE, menuFileEnterExplore);
break;
}
case menuApple:
if (menuItem == menuAppleAboutBox)
aboutNetHack();
+#if !TARGET_API_MAC_CARBON
else
{
unsigned char daName[32];
GetMenuItemText(MHND_APPLE, menuItem, * (Str255 *) daName);
(void) OpenDeskAcc(daName);
}
+#endif
break;
/*
break;
case menuEdit:
+#if !TARGET_API_MAC_CARBON
(void) SystemEdit(menuItem - 1);
+#endif
break;
default: /* get associated string and add to key queue */
#include "hack.h"
#include "mactty.h"
#include "macwin.h"
-#include <Sound.h>
-#include <Resources.h>
+#if !TARGET_API_MAC_CARBON
+# include <Sound.h>
+# include <Resources.h>
+#else
+# define freqDurationCmd 40
+#endif
#define SND_BUFFER(s) (&(*s)[20])
#define SND_LEN(s) (GetHandleSize(s)-42)
#include "hack.h" /* to get flags */
#include "mttypriv.h"
+#if !TARGET_API_MAC_CARBON
#include <Resources.h>
+#endif
char game_active = 0; /* flag to window rendering routines not to use ppat */
}
+#if 0 /* Use alloc.c instead */
/*
* Allocate a pointer using the set memory-allocator
*/
*ptr = NewPtr (size);
return MemError ();
}
+#endif
/*
if (record->uses_gworld) {
s_err = deallocate_gworld (record);
+#if !TARGET_API_MAC_CARBON
} else {
s_err = dispose_ptr (record->its_bits.baseAddr);
if (!s_err) {
}
}
}
+#endif
}
return s_err;
}
* Otherwise, do nothing.
*/
-short create_tty (WindowPtr *window, short resource_id, Boolean in_color) {
-tty_record * record;
-Boolean was_allocated = !!*window;
+short
+create_tty (WindowRef *window, short resource_id, Boolean in_color)
+{
+ tty_record * record;
+ Boolean was_allocated = !!*window;
if (in_color) {
- *window = GetNewCWindow (resource_id, (Ptr) *window, (WindowPtr) -1L);
+ *window = GetNewCWindow (resource_id, (Ptr) *window, (WindowRef) -1L);
} else {
- *window = GetNewWindow (resource_id, (Ptr) *window, (WindowPtr) -1L);
+ *window = GetNewWindow (resource_id, (Ptr) *window, (WindowRef) -1L);
}
if (!*window) {
return mem_err ();
record = (tty_record *) NewPtrClear (sizeof (tty_record));
if (!record) {
+#if !TARGET_API_MAC_CARBON
if (was_allocated) {
CloseWindow (*window);
} else {
+#endif
DisposeWindow (*window);
+#if !TARGET_API_MAC_CARBON
}
+#endif
return mem_err ();
}
record->its_window = *window;
if (in_color) {
GDHandle gh;
- SetPort (*window);
- GetGWorld ( &(record ->its_window_world), &gh);
+ SetPortWindowPort(*window);
+ GetGWorld(&(record->its_window_world), &gh);
} else {
record->its_window_world = (GWorldPtr)0;
}
s_err = free_bits (record);
if (!s_err) {
+#if !TARGET_API_MAC_CARBON
if (record->was_allocated) {
CloseWindow (window);
} else {
+#endif
DisposeWindow (window);
+#if !TARGET_API_MAC_CARBON
}
+#endif
s_err = dispose_ptr (record);
}
if (record->uses_gworld) {
s_err = allocate_offscreen_world (record);
+#if !TARGET_API_MAC_CARBON
} else {
s_err = alloc_ptr ((void **) &(record->its_bits.baseAddr),
record->its_bits.rowBytes * record->its_bits.bounds.bottom);
ClipRect (&(record->its_bits.bounds));
SetPortBits (&(record->its_bits));
}
+#endif
}
return s_err;
}
select_onscreen_window (tty_record *record) {
if (record->uses_gworld) {
use_port (record, record->its_window_world);
- SetPort (record->its_window);
+ SetPortWindowPort(record->its_window);
} else {
- use_port (record, record->its_window);
+ use_port(record, record->its_window);
}
}
* Do bits copy depending on if we're using color or not
*/
static void
-copy_bits (tty_record *record, Rect *bounds, short xfer_mode, RgnHandle mask_rgn) {
-GWorldFlags pix_state;
-BitMap * source;
+copy_bits(tty_record *record, Rect *bounds, short xfer_mode, RgnHandle mask_rgn)
+{
+ GWorldFlags pix_state;
+ BitMap * source;
if (record->uses_gworld) {
pix_state = GetPixelsState (GetGWorldPixMap (record->offscreen_world));
LockPixels (GetGWorldPixMap (record->offscreen_world));
- source = (BitMap *) &record->offscreen_world->portPixMap;
+ source = (BitMapPtr) *GetGWorldPixMap(record->offscreen_world);
}
else source = &record->its_bits;
-
- CopyBits (source, &(record->its_window->portBits), bounds, bounds, xfer_mode, mask_rgn);
+
+ SetPortWindowPort(record->its_window);
+ CopyBits(source, GetPortBitMapForCopyBits(GetWindowPort(record->its_window)),
+ bounds, bounds, xfer_mode, mask_rgn);
if (record->uses_gworld) {
SetPixelsState (GetGWorldPixMap (record->offscreen_world), pix_state);
}
+#if 0
/*
* Update TTY according to new color environment for the window
*/
}
return 0;
}
+#endif
/*
*inval_rect = record->invalid_rect;
#else
if (EmptyRgn (record->invalid_part)) {
- return return general_failure;
+ return general_failure;
}
*inval_rect = (*(record->invalid_part))->rgnBBox;
#endif
* Add a null-terminated string of characters
*/
short
-add_tty_string (WindowPtr window, const char *string) {
-register const unsigned char * start_c;
-register const unsigned char * the_c;
-register unsigned char ch, is_control, tty_wrap;
-register short max_x, pos_x;
-RECORD_EXISTS (record);
+add_tty_string(WindowPtr window, const char *string)
+{
+ register const unsigned char * start_c;
+ register const unsigned char * the_c;
+ register unsigned char ch, is_control = 0, tty_wrap;
+ register short max_x, pos_x;
+ RECORD_EXISTS (record);
if (record->curs_state != 0)
curs_pos (record, record->x_curs, record->y_curs, 0);
#include "mactty.h"
#include "wintty.h"
+#if !TARGET_API_MAC_CARBON
#include <LowMem.h>
#include <AppleEvents.h>
#include <Gestalt.h>
#include <TextUtils.h>
#include <DiskInit.h>
#include <ControlDefinitions.h>
+#endif
NhWindow *theWindows = (NhWindow *) 0;
+Cursor qdarrow;
/* Borrowed from the Mac tty port */
extern WindowPtr _mt_window;
/*
* The screen layouts on the small 512x342 screen need special cares.
*/
-Boolean small_screen;
+Boolean small_screen = 0;
#ifdef NHW_BASE
# undef NHW_BASE
long l;
Str255 volName;
+
+#if !TARGET_API_MAC_CARBON
if (LMGetDefltStack() < 50 * 1024L) {
SetApplLimit ((void *) ((long) LMGetCurStackBase() - (50 * 1024L)));
}
InitMenus ();
InitDialogs (0L);
TEInit ();
+#endif
memset (&macFlags, 0, sizeof(macFlags));
if (!Gestalt (gestaltOSAttr, & l)) {
macFlags.standardFile = (l & (1 << gestaltStandardFile58)) ? 1 : 0;
gMouseRgn = NewRgn ();
- InitCursor ();
+ InitCursor();
+ GetQDGlobalsArrow(&qdarrow);
ObscureCursor ();
- MoveScrollUPP = NewControlActionProc(MoveScrollBar);
+ MoveScrollUPP = NewControlActionUPP(MoveScrollBar);
- /* set up base fonts for all window types */
+ /* Set up base fonts for all window types */
GetFNum ("\pHackFont", &i);
if (i == 0)
i = kFontIDMonaco;
i = kFontIDGeneva;
win_fonts [NHW_MESSAGE] = i;
win_fonts [NHW_TEXT] = kFontIDGeneva;
-
+
macFlags.hasAE = 0;
if(!Gestalt(gestaltAppleEventsAttr, &l) && (l & (1L << gestaltAppleEventsPresent))){
if (AEInstallEventHandler (kCoreEventClass, typeWildCard,
- NewAEEventHandlerProc (AppleEventHandler),
+ NewAEEventHandlerUPP(AppleEventHandler),
0,
FALSE) == noErr)
macFlags.hasAE = 1;
}
+#if TARGET_API_MAC_CARBON
+ HGetVol(volName, &theDirs.dataRefNum, &theDirs.dataDirID);
+#else
/*
* We should try to get this data from a rsrc, in the profile file
* the user double-clicked... This data should be saved with the
*/
GetVol (volName, &theDirs.dataRefNum );
GetWDInfo (theDirs.dataRefNum, &theDirs.dataRefNum, &theDirs.dataDirID, &l);
+#endif
if (volName [0] > 31) volName [0] = 31;
for (l = 1; l <= volName [0]; l++) {
if (volName [l] == ':') {
static void
-DrawScrollbar (NhWindow *aWin) {
-WindowPtr theWindow = aWin->its_window;
-Rect r = theWindow->portRect;
-Boolean vis;
-short val, lin, win_height;
+DrawScrollbar (NhWindow *aWin)
+{
+ WindowPtr theWindow = aWin->its_window;
+ Rect crect, wrect;
+ Boolean vis;
+ short val, lin, win_height;
- if (!aWin->scrollBar) {
+
+ if (!aWin->scrollBar)
return;
- }
- win_height = r.bottom - r.top;
+ GetControlBounds(aWin->scrollBar, &crect);
+ GetWindowBounds(aWin->its_window, kWindowContentRgn, &wrect);
+ OffsetRect(&wrect, -wrect.left, -wrect.top);
+ win_height = wrect.bottom - wrect.top;
- if ((*aWin->scrollBar)->contrlRect.top != r.top - 1 ||
- (*aWin->scrollBar)->contrlRect.left != r.right - SBARWIDTH) {
- MoveControl (aWin->scrollBar, r.right - SBARWIDTH, r.top - 1);
+ if (crect.top != wrect.top - 1 ||
+ crect.left != wrect.right - SBARWIDTH) {
+ MoveControl (aWin->scrollBar, wrect.right - SBARWIDTH, wrect.top - 1);
}
- if ((*aWin->scrollBar)->contrlRect.bottom != r.bottom - SBARHEIGHT ||
- (*aWin->scrollBar)->contrlRect.right != r.right + 1) {
+ if (crect.bottom != wrect.bottom - SBARHEIGHT ||
+ crect.right != wrect.right + 1) {
SizeControl (aWin->scrollBar, SBARWIDTH+1, win_height - SBARHEIGHT + 2);
}
vis = (win_height > (50 + SBARHEIGHT));
- if (vis != (*aWin->scrollBar)->contrlVis) {
+ if (vis != IsControlVisible(aWin->scrollBar)) {
/* current status != control */
if (vis)/* if visible, show */
ShowControl (aWin->scrollBar);
HiliteControl (aWin->scrollBar, val);
val = GetControlValue (aWin->scrollBar);
if (val != aWin->scrollPos) {
- InvalRect (&(theWindow->portRect));
+ InvalWindowRect(theWindow, &wrect);
aWin->scrollPos = val;
}
}
* This function could be overloaded with any amount of intelligence...
*/
int
-SanePositions (void) {
+SanePositions (void)
+{
+#if TARGET_API_MAC_CARBON
+ ConstrainWindowToScreen(_mt_window, kWindowStructureRgn,
+ kWindowConstrainMoveRegardlessOfFit, NULL, NULL);
+#else
short left, top, width, height;
int ix, numText = 0, numMenu = 0;
- int mbar_height = GetMBarHeight ();
- Rect screenArea = qd.thePort->portBits.bounds;
+ int mbar_height = GetMBarHeight();
+ BitMap qbitmap;
+ Rect screenArea;
WindowPtr theWindow;
NhWindow *nhWin;
+
+ screenArea = GetQDGlobalsScreenBits(&qbitmap)->bounds;
OffsetRect (&screenArea, - screenArea.left, - screenArea.top);
/* Map Window */
}
}
}
- return 0;
+#endif
+ return (0);
}
if (i >= NUM_MACWINDOWS) {
error ("cre_win: Win full; freeing extras");
for (i = 0; i < NUM_MACWINDOWS; i ++) {
- WindowPeek w = (WindowPeek) theWindows [i].its_window;
- if (w->visible || i == WIN_INVEN ||
- w->windowKind != WIN_BASE_KIND + NHW_MENU &&
- w->windowKind != WIN_BASE_KIND + NHW_TEXT)
+ if (IsWindowVisible(theWindows [i].its_window) || i == WIN_INVEN ||
+ GetWindowKind(theWindows [i].its_window) != WIN_BASE_KIND + NHW_MENU &&
+ GetWindowKind(theWindows [i].its_window) != WIN_BASE_KIND + NHW_TEXT)
continue;
- mac_destroy_nhwindow (i);
+ mac_destroy_nhwindow(i);
goto got1;
}
error ("cre_win: Out of ids!");
}
aWin->its_window = GetNewWindow (WIN_BASE_RES + kind, (WindowPtr) 0L, (WindowPtr) -1L);
- ((WindowPeek) aWin->its_window)->windowKind = WIN_BASE_KIND + kind;
- SetWRefCon (aWin->its_window, (long) aWin);
+ SetWindowKind(aWin->its_window, WIN_BASE_KIND + kind);
+ SetWRefCon(aWin->its_window, (long) aWin);
if (!(aWin->windowText = NewHandle (TEXT_BLOCK))) {
error ("cre_win: NewHandle fail(%ld)", (long) TEXT_BLOCK);
DisposeWindow (aWin->its_window);
aWin->drawn = TRUE;
mac_clear_nhwindow (i);
- /*HARDCODED*/
- SetPort (aWin->its_window);
+ SetPortWindowPort(aWin->its_window);
if (kind == NHW_MESSAGE) {
aWin->font_number = win_fonts [NHW_MESSAGE];
aWin->char_width = fi.widMax;
if (kind == NHW_MENU || kind == NHW_TEXT || kind == NHW_MESSAGE) {
- Rect r = aWin->its_window->portRect;
+ Rect r;
+
+ GetWindowBounds(aWin->its_window, kWindowContentRgn, &r);
+ r.right -= (r.left - 1);
r.left = r.right - SBARWIDTH;
- r.bottom -= SBARHEIGHT;
- r.top -= 1;
- r.right += 1;
+ r.bottom -= (r.top + SBARHEIGHT);
+ r.top = -1;
aWin->scrollBar = NewControl (aWin->its_window, &r, "\p", (r.bottom > r.top + 50), 0, 0, 0, 16, 0L);
aWin->scrollPos = 0;
}
void
-mac_init_nhwindows (int *argcp, char **argv) {
+mac_init_nhwindows (int *argcp, char **argv)
+{
+#if !TARGET_API_MAC_CARBON
Rect scr = (*GetGrayRgn())->rgnBBox;
small_screen = scr.bottom - scr.top <= (iflags.large_font ? 12*40 : 9*40);
+#endif
+ Rect r;
+
InitMenuRes ();
*/
mac_create_nhwindow(NHW_BASE);
tty_create_nhwindow(NHW_MESSAGE);
+ RetrievePosition(kMessageWindow, &r.top, &r.left);
+ RetrieveSize(kMessageWindow, r.top, r.left, &r.bottom, &r.right);
+ MoveWindow(theWindows[NHW_MESSAGE].its_window, r.left, r.top, false);
+ SizeWindow(theWindows[NHW_MESSAGE].its_window, r.right, r.bottom, true);
+ ConstrainWindowToScreen(theWindows[NHW_MESSAGE].its_window, kWindowStructureRgn,
+ kWindowConstrainMoveRegardlessOfFit, NULL, NULL);
+ return;
}
if (!aWin->drawn)
return;
- SetPort (theWindow);
- r = theWindow->portRect;
+ SetPortWindowPort(theWindow);
+ GetWindowBounds(theWindow, kWindowContentRgn, &r);
+ OffsetRect(&r, -r.left, -r.top);
if (aWin->scrollBar)
r.right -= SBARWIDTH;
- switch (((WindowPeek) theWindow)->windowKind - WIN_BASE_KIND) {
+ switch (GetWindowKind(theWindow) - WIN_BASE_KIND) {
case NHW_MESSAGE :
if (aWin->scrollPos == aWin->y_size - 1) /* if no change since last clear */
return; /* don't bother with redraw */
aWin->y_curs = 0;
aWin->x_curs = 0;
aWin->drawn = FALSE;
- InvalRect (&r);
+ InvalWindowRect(theWindow, &r);
}
static Boolean
-in_topl_mode(void) {
- return WIN_MESSAGE != WIN_ERR && top_line &&
- (*top_line)->viewRect.left < theWindows[WIN_MESSAGE].its_window->portRect.right;
+in_topl_mode(void)
+{
+ Rect rect;
+
+
+ GetWindowBounds(theWindows[WIN_MESSAGE].its_window, kWindowContentRgn, &rect);
+ OffsetRect(&rect, -rect.left, -rect.top);
+ return (WIN_MESSAGE != WIN_ERR && top_line &&
+ (*top_line)->viewRect.left < rect.right);
}
#define BTN_H (SBARHEIGHT-3)
static void
-topl_resp_rect(int resp_idx, Rect *r) {
+topl_resp_rect(int resp_idx, Rect *r)
+{
+ Rect rect;
+
+
+ GetWindowBounds(theWindows[WIN_MESSAGE].its_window, kWindowContentRgn, &rect);
+ OffsetRect(&rect, -rect.left, -rect.top);
r->left = (BTN_IND + BTN_W) * resp_idx + BTN_IND;
r->right = r->left + BTN_W;
- r->bottom = theWindows[WIN_MESSAGE].its_window->portRect.bottom - 1;
+ r->bottom = rect.bottom - 1;
r->top = r->bottom - BTN_H;
+ return;
}
void
leave_topl_mode(char *answer) {
- char *ap, *bp;
+ unsigned char *ap, *bp;
int ans_len = (*top_line)->teLength - topl_query_len;
NhWindow *aWin = theWindows + WIN_MESSAGE;
topl_flash_resp(int resp_idx) {
unsigned long dont_care;
Rect frame;
- SetPort(theWindows[WIN_MESSAGE].its_window);
+ SetPortWindowPort(theWindows[WIN_MESSAGE].its_window);
topl_resp_rect(resp_idx, &frame);
InsetRect(&frame, 1, 1);
InvertRect(&frame);
static void
topl_set_def(int new_def_idx) {
Rect frame;
- SetPort(theWindows[WIN_MESSAGE].its_window);
+ SetPortWindowPort(theWindows[WIN_MESSAGE].its_window);
topl_resp_rect(topl_def_idx, &frame);
- InvalRect(&frame);
+ InvalWindowRect(theWindows[WIN_MESSAGE].its_window, &frame);
topl_def_idx = new_def_idx;
topl_resp_rect(new_def_idx, &frame);
- InvalRect(&frame);
+ InvalWindowRect(theWindows[WIN_MESSAGE].its_window, &frame);
}
def = CHAR_ANY;
}
- SetPort(theWindows[WIN_MESSAGE].its_window);
+ SetPortWindowPort(theWindows[WIN_MESSAGE].its_window);
r_len1 = strlen(resp);
r_len = strlen(topl_resp);
if (r_len < r_len1)
r_len = r_len1;
topl_resp_rect(0, &frame);
frame.right = (BTN_IND + BTN_W) * r_len;
- InvalRect(&frame);
+ InvalWindowRect(theWindows[WIN_MESSAGE].its_window, &frame);
strcpy(topl_resp, resp);
loc = strchr (resp, def);
static void
-adjust_window_pos(NhWindow *aWin, short width, short height) {
- WindowPtr theWindow = aWin->its_window;
+adjust_window_pos(NhWindow *aWin, short width, short height)
+{
+ WindowRef theWindow = aWin->its_window;
+#if TARGET_API_MAC_CARBON
+ Rect r;
+
+
+ GetWindowBounds(theWindow, kWindowContentRgn, &r);
+ RetrieveWinPos(theWindow, &r.top, &r.left);
+ MoveWindow(theWindow, r.left, r.top, false);
+ SizeWindow(theWindow, width, height, true);
+ ConstrainWindowToScreen(theWindow, kWindowStructureRgn,
+ kWindowConstrainMoveRegardlessOfFit, NULL, NULL);
+#else
Rect scr_r = (*GetGrayRgn())->rgnBBox;
const Rect win_ind = {2, 2, 3, 3};
const short min_w = theWindow->portRect.right - theWindow->portRect.left,
Point pos;
short max_h;
- SetPort(theWindow);
+ SetPortWindowPort(theWindow);
if (!RetrieveWinPos(theWindow, &pos.v, &pos.h)) {
pos.v = 0; /* take window's existing position */
pos.h = 0;
MoveWindow(theWindow, pos.h, pos.v, false);
if (aWin->scrollBar)
DrawScrollbar (aWin);
+#endif
+ return;
}
putstr (win, flags.standout ? ATR_INVERSE : ATR_NONE, " --More--");
}
- if (!((WindowPeek) theWindow)->visible) {
+ if (!IsWindowVisible(theWindow)) {
if (win != WIN_MESSAGE)
adjust_window_pos(aWin, aWin->x_size + SBARWIDTH+1, aWin->y_size *aWin->row_height);
WIN_MESSAGE = WIN_ERR;
}
- kind = ((WindowPeek) theWindow)->windowKind - WIN_BASE_KIND;
+ kind = GetWindowKind(theWindow) - WIN_BASE_KIND;
- if ((!((WindowPeek) theWindow)->visible || (kind != NHW_MENU && kind != NHW_TEXT))) {
+ if ((!IsWindowVisible(theWindow) || (kind != NHW_MENU && kind != NHW_TEXT))) {
DisposeWindow (theWindow);
if (aWin->windowText) {
- DisposeHandle (aWin->windowText);
+ DisposeHandle(aWin->windowText);
}
aWin->its_window = (WindowPtr) 0;
aWin->windowText = (Handle) 0;
* ClickMenu, and UpdateMenu. Takes the NhWindow and a line ref relative to the scrollbar.
*/
static void ToggleMenuSelect (NhWindow *aWin, int line) {
- Rect r = aWin->its_window->portRect;
+ Rect r;
+
+ GetWindowBounds(aWin->its_window, kWindowContentRgn, &r);
+ OffsetRect(&r, -r.left, -r.top);
if (aWin->scrollBar)
r.right -= SBARWIDTH;
r.top = line * aWin->row_height;
MacMHMenuItem *mi;
int l, ch = theEvent->message & 0xff;
- if (aWin) {
+ if (aWin && aWin->menuInfo) {
HLock ((char**)aWin->menuInfo);
for (l = 0, mi = *aWin->menuInfo; l < aWin->miLen; l++, mi++) {
if (mi->accelerator == ch) {
ToggleMenuListItemSelected (aWin, l);
if (mi->line >= aWin->scrollPos && mi->line <= aWin->y_size) {
- SetPort(theWindow);
+ SetPortWindowPort(theWindow);
ToggleMenuSelect (aWin, mi->line - aWin->scrollPos);
}
/* Dismiss window if only picking one item */
static void
-macClickMenu (EventRecord *theEvent, WindowPtr theWindow) {
+macClickMenu (EventRecord *theEvent, WindowRef theWindow) {
Point p;
- NhWindow *aWin = GetNhWin (theWindow);
+ NhWindow *aWin = GetNhWin(theWindow);
+ Rect wrect;
- if (aWin->scrollBar && (*aWin->scrollBar)->contrlVis) {
+
+ GetWindowBounds(theWindow, kWindowContentRgn, &wrect);
+ OffsetRect(&wrect, -wrect.left, -wrect.top);
+ if (aWin->scrollBar && IsControlVisible(aWin->scrollBar)) {
short code;
ControlHandle theBar;
DoScrollBar (p, code, theBar, aWin);
return;
}
- if (p.h >= theWindow->portRect.right - SBARWIDTH)
- return;
}
if (inSelect != WIN_ERR && aWin->how != PICK_NONE) {
short currentRow = -1, previousRow = -1;
Boolean majorSelectState, firstRow = TRUE;
do {
+#if !TARGET_API_MAC_CARBON
SystemTask ();
+#endif
GetMouse (&p);
currentRow = p.v / aWin->row_height;
- if (p.h < theWindow->portRect.left || p.h > theWindow->portRect.right ||
- p.v < 0 || p.v > theWindow->portRect.bottom || currentRow >= aWin->y_size) {
+ if (p.h < wrect.left || p.h > wrect.right ||
+ p.v < 0 || p.v > wrect.bottom || currentRow >= aWin->y_size) {
continue; /* not in window range */
}
macClickText (EventRecord *theEvent, WindowPtr theWindow) {
NhWindow *aWin = GetNhWin (theWindow);
- if (aWin->scrollBar && (*aWin->scrollBar)->contrlVis) {
+ if (aWin->scrollBar && IsControlVisible(aWin->scrollBar)) {
short code;
Point p = theEvent->where;
ControlHandle theBar;
InvertRect(&frame);
while (WaitMouseUp()) {
+#if !TARGET_API_MAC_CARBON
SystemTask();
+#endif
GetMouse(&mouse);
if (PtInRect(mouse, &frame) != in_btn) {
in_btn = !in_btn;
if (strchr(topl_resp, *click_to_cmd(where.h, where.v, clicked_mod)))
nhbell();
else {
+#if !TARGET_API_MAC_CARBON
if (cursor_locked)
while (WaitMouseUp())
SystemTask();
+#endif
gClickedToMove = TRUE;
clicked_pos = where;
if (!part)
return;
- theWin = (*theBar)->contrlOwner;
+ theWin = GetControlOwner(theBar);
+ GetWindowBounds(theWin, kWindowContentRgn, &r);
+ OffsetRect(&r, -r.left, -r.top);
winToScroll = (NhWindow*)(GetWRefCon(theWin));
now = GetControlValue (theBar);
-
+
if (part == kControlPageUpPart || part == kControlPageDownPart)
- amtToScroll = (theWin->portRect.bottom - theWin->portRect.top) / winToScroll->row_height;
+ amtToScroll = (r.bottom - r.top) / winToScroll->row_height;
else
amtToScroll = 1;
SetControlValue (theBar, now + amtToScroll);
winToScroll->scrollPos = now + amtToScroll;
- r = theWin->portRect;
r.right -= SBARWIDTH;
if (winToScroll == theWindows + WIN_MESSAGE)
r.bottom -= SBARHEIGHT;
rgn = NewRgn ();
ScrollRect (&r, 0, -amtToScroll * winToScroll->row_height, rgn);
if (rgn) {
- InvalRgn (rgn);
- BeginUpdate (theWin);
+ InvalWindowRgn(theWin, rgn);
+ BeginUpdate(theWin);
}
- winUpdateFuncs [((WindowPeek)theWin)->windowKind - WIN_BASE_KIND] (&fake, theWin);
+ winUpdateFuncs [GetWindowKind(theWin) - WIN_BASE_KIND] (&fake, theWin);
if (rgn) {
- EndUpdate (theWin);
- DisposeRgn (rgn);
+ EndUpdate(theWin);
+ DisposeRgn(rgn);
}
}
static void
-DoScrollBar (Point p, short code, ControlHandle theBar, NhWindow *aWin) {
+DoScrollBar (Point p, short code, ControlHandle theBar, NhWindow *aWin)
+{
ControlActionUPP func = NULL;
+ Rect rect;
if (code == kControlUpButtonPart || code == kControlPageUpPart ||
code == kControlDownButtonPart || code == kControlPageDownPart)
func = MoveScrollUPP;
- (void) TrackControl (theBar, p, func);
+ (void) TrackControl(theBar, p, func);
if (!func) {
if (aWin->scrollPos != GetControlValue (theBar)) {
aWin->scrollPos = GetControlValue (theBar);
- InvalRect (&(aWin->its_window)->portRect);
+ GetWindowBounds(aWin->its_window, kWindowContentRgn, &rect);
+ OffsetRect(&rect, -rect.left, -rect.top);
+ InvalWindowRect(aWin->its_window, &rect);
}
}
}
part = kControlDownButtonPart;
}
if (part) {
- SetPort(aWin->its_window);
+ SetPortWindowPort(aWin->its_window);
MoveScrollBar(aWin->scrollBar, part);
return 0;
}
if (WIN_MESSAGE) {
NhWindow *winToScroll = &theWindows[WIN_MESSAGE];
mac_display_nhwindow(WIN_MESSAGE, FALSE);
- SetPort(winToScroll->its_window);
+ SetPortWindowPort(winToScroll->its_window);
MoveScrollBar(winToScroll->scrollBar, kControlUpButtonPart);
}
return 0;
static void
-draw_growicon_vert_only(WindowPtr wind) {
+draw_growicon_vert_only(WindowPtr wind)
+{
GrafPtr org_port;
RgnHandle org_clip = NewRgn();
- Rect r = wind->portRect;
- r.left = r.right - SBARWIDTH;
+ Rect r;
GetPort(&org_port);
- SetPort(wind);
+ SetPortWindowPort(wind);
GetClip(org_clip);
+ GetWindowBounds(wind, kWindowContentRgn, &r);
+ OffsetRect(&r, -r.left, -r.top);
+ r.left = r.right - SBARWIDTH;
ClipRect(&r);
DrawGrowIcon(wind);
SetClip(org_clip);
static short
-macUpdateMessage (EventRecord *theEvent, WindowPtr theWindow) {
+macUpdateMessage (EventRecord *theEvent, WindowPtr theWindow)
+{
RgnHandle org_clip = NewRgn(), clip = NewRgn();
- Rect r = theWindow->portRect;
- NhWindow *aWin = GetNhWin (theWindow);
+ Rect r;
+ NhWindow *aWin = GetNhWin(theWindow);
int l;
if (!theEvent)
return 0;
GetClip(org_clip);
+ GetWindowBounds(theWindow, kWindowContentRgn, &r);
+ OffsetRect(&r, -r.left, -r.top);
DrawControls(theWindow);
DrawGrowIcon(theWindow);
TETextBox (*aWin->windowText, aWin->windowTextLen, &r, teJustLeft);
HUnlock (aWin->windowText);
-#if 1
+#if !TARGET_API_MAC_CARBON
r.bottom = r.top + aWin->save_lin * aWin->row_height;
r.top = r.bottom - 1;
FillRect(&r, (void *) &qd.gray);
static short
GeneralUpdate (EventRecord *theEvent, WindowPtr theWindow) {
- Rect r = theWindow->portRect;
- Rect r2 = r;
+ Rect r, r2;
NhWindow *aWin = GetNhWin (theWindow);
RgnHandle h;
Boolean vis;
+
if (!theEvent)
return 0;
+ GetWindowBounds(theWindow, kWindowContentRgn, &r);
+ OffsetRect(&r, -r.left, -r.top);
+ r2 = r;
r2.left = r2.right - SBARWIDTH;
r2.right += 1;
r2.top -= 1;
Rect r = {0, 0, 1, 1};
GetPort (&gp);
- SetPort (theWindow);
+ SetPortWindowPort(theWindow);
if (cursor_locked)
dir = (char *)0;
HUnlock ((Handle) ch);
} else {
- SetCursor(&qd.arrow);
+ SetCursor(&qdarrow);
}
OffsetRect (&r, theEvent->where.h, theEvent->where.v);
RectRgn (mouseRgn, &r);
#endif
Rect r = {-1, -1, 2, 2};
- SetCursor(&qd.arrow);
+ SetCursor(&qdarrow);
OffsetRect (&r, theEvent->where.h, theEvent->where.v);
RectRgn (mouseRgn, &r);
}
dispatchKey :
if (theWindow) {
- int kind = ((WindowPeek)theWindow)->windowKind - WIN_BASE_KIND;
+ int kind = GetWindowKind(theWindow) - WIN_BASE_KIND;
winKeyFuncs [kind] (theEvent, theWindow);
} else {
GeneralKey (theEvent, (WindowPtr) 0);
unsigned long l;
WindowPtr theWindow;
NhWindow *aWin;
- Rect r = (*GetGrayRgn ())->rgnBBox;
+ Rect r;
Boolean not_inSelect;
- InsetRect (&r, 4, 4);
+ InsetRect(GetRegionBounds(GetGrayRgn(), &r), 4, 4);
code = FindWindow (theEvent->where, &theWindow);
aWin = GetNhWin (theWindow);
switch (code) {
case inContent :
if (not_inSelect) {
- int kind = ((WindowPeek)theWindow)->windowKind - WIN_BASE_KIND;
+ int kind = GetWindowKind(theWindow) - WIN_BASE_KIND;
winCursorFuncs [kind] (theEvent, theWindow, gMouseRgn);
SelectWindow (theWindow);
- SetPort (theWindow);
+ SetPortWindowPort(theWindow);
winClickFuncs [kind] (theEvent, theWindow);
} else {
nhbell ();
case inDrag :
if (not_inSelect) {
- SetCursor(&qd.arrow);
+ SetCursor(&qdarrow);
DragWindow (theWindow, theEvent->where, &r);
- SaveWindowPos (theWindow);
+ SaveWindowPos(theWindow);
} else {
nhbell ();
}
case inGrow :
if (not_inSelect) {
- SetCursor(&qd.arrow);
+ SetCursor(&qdarrow);
SetRect (&r, 80, 2 * aWin->row_height + 1, r.right, r.bottom);
if (aWin == theWindows + WIN_MESSAGE)
r.top += SBARHEIGHT;
l = GrowWindow (theWindow, theEvent->where, &r);
SizeWindow (theWindow, l & 0xffff, l >> 16, FALSE);
- SaveWindowSize (theWindow);
- SetPort (theWindow);
- InvalRect (&(theWindow->portRect));
+ SaveWindowSize(theWindow);
+ SetPortWindowPort(theWindow);
+ GetWindowBounds(theWindow, kWindowContentRgn, &r);
+ OffsetRect(&r, -r.left, -r.top);
+ InvalWindowRect(theWindow, &r);
if (aWin->scrollBar) {
DrawScrollbar (aWin);
}
DoMenuEvt (MenuSelect (theEvent->where));
break;
+#if !TARGET_API_MAC_CARBON
case inSysWindow :
SystemClick(theEvent, theWindow);
+#endif
default :
break;
}
HandleUpdate (EventRecord *theEvent) {
WindowPtr theWindow = (WindowPtr) theEvent->message;
NhWindow *aWin = GetNhWin (theWindow);
+ Rect r;
+
char existing_update_region = FALSE;
Rect rect;
existing_update_region = (get_invalid_region (theWindow, &rect) == noErr);
}
BeginUpdate (theWindow);
- SetPort (theWindow);
- EraseRect (&(theWindow->portRect));
- winUpdateFuncs [((WindowPeek)theWindow)->windowKind - WIN_BASE_KIND]
+ SetPortWindowPort(theWindow);
+ GetWindowBounds(theWindow, kWindowContentRgn, &r);
+ OffsetRect(&r, -r.left, -r.top);
+ EraseRect(&r);
+ winUpdateFuncs [GetWindowKind(theWindow) - WIN_BASE_KIND]
(theEvent, theWindow);
if (theWindow == _mt_window && existing_update_region) {
static void
DoOsEvt (EventRecord *theEvent) {
- WindowPtr wp;
+ WindowRef win;
short code;
if ((theEvent->message & 0xff000000) == 0xfa000000) {
/* Mouse Moved */
- code = FindWindow (theEvent->where, &wp);
+ code = FindWindow (theEvent->where, &win);
if (code != inContent) {
Rect r = {-1, -1, 2, 2};
- SetCursor(&qd.arrow);
+ SetCursor(&qdarrow);
OffsetRect (&r, theEvent->where.h, theEvent->where.v);
RectRgn (gMouseRgn, &r);
-
} else {
- int kind = ((WindowPeek)wp)->windowKind - WIN_BASE_KIND;
+ int kind = GetWindowKind(win) - WIN_BASE_KIND;
if (kind >= 0 && kind <= NHW_TEXT) {
- winCursorFuncs [kind] (theEvent, wp, gMouseRgn);
+ winCursorFuncs [kind] (theEvent, win, gMouseRgn);
}
}
}
case mouseDown :
HandleClick (theEvent);
break;
+#if !TARGET_API_MAC_CARBON
case diskEvt :
if ((theEvent->message & 0xffff0000) != 0) {
Point p = {150, 150};
(void) DIBadMount (p, theEvent->message);
}
break;
+#endif
case osEvt :
DoOsEvt (theEvent);
break;
if (!iflags.window_inited)
return;
- (void) WaitNextEvent (everyEvent, &anEvent, 0, gMouseRgn);
- HandleEvent (&anEvent);
+ (void) WaitNextEvent (everyEvent, &anEvent, -1, gMouseRgn);
+ HandleEvent(&anEvent);
}
in_putstr ++;
slen = strlen (str);
- SetPort (aWin->its_window);
- r = aWin->its_window->portRect;
+ SetPortWindowPort(aWin->its_window);
+ GetWindowBounds(aWin->its_window, kWindowContentRgn, &r);
+ OffsetRect(&r, -r.left, -r.top);
if (win == WIN_MESSAGE) {
r.right -= SBARWIDTH;
r.bottom -= SBARHEIGHT;
SetControlMaximum (aWin->scrollBar, aWin->y_size);
SetControlValue(aWin->scrollBar, min);
}
- InvalRect (&r);
+ InvalWindowRect(aWin->its_window, &r);
}
else /* Message has a fixed width, other windows base on content */
if (maxWidth > aWin->x_size)
return;
}
- SetPort (aWin->its_window);
+ SetPortWindowPort(aWin->its_window);
MoveTo (x * aWin->char_width, (y * aWin->row_height) + aWin->ascent_height);
aWin->x_curs = x;
aWin->y_curs = y;
struct window_procs mac_procs = {
"mac",
WC_COLOR | WC_HILITE_PET |
- WC_LARGE_FONT | /* obsolete */
WC_FONT_MAP | WC_FONT_MENU | WC_FONT_MESSAGE | WC_FONT_STATUS | WC_FONT_TEXT |
WC_FONTSIZ_MAP | WC_FONTSIZ_MENU | WC_FONTSIZ_MESSAGE | WC_FONTSIZ_STATUS | WC_FONTSIZ_TEXT,
0L,
static void
topl_getlin(const char *query, char *bufp, Boolean ext) {
- int q_len = strlen(query);
-
if (get_line_from_key_queue (bufp))
return;
/* Copyright (c) Jon W{tte, Hao-Yang Wang, Jonathan Handler 1992. */
/* NetHack may be freely redistributed. See license for details. */
-#include <Dialogs.h>
+#if !TARGET_API_MAC_CARBON
+# include <Dialogs.h>
+# include <ControlDefinitions.h>
+#else
+# include <Carbon/Carbon.h>
+#endif
+
#include "macpopup.h"
-#include <ControlDefinitions.h>
/* Flash a dialog button when its accelerator key is pressed */
void
-FlashButton (WindowPtr wind, short item) {
+FlashButton(DialogRef wind, short item) {
short type;
Handle handle;
Rect rect;
#include "mactty.h"
#include "wintty.h"
+#if !TARGET_API_MAC_CARBON
#include <Palettes.h>
+#endif
#define MT_WINDOW 135
#define MT_WIDTH 80
sprintf (ptr, "%s%s%x%x%x", count ? "/" : "" ,
flag ? "-" : "" ,
- (_mt_colors [count] [flag] >> 20) & 0xf ,
- (_mt_colors [count] [flag] >> 12) & 0xf ,
- (_mt_colors [count] [flag] >> 4) & 0xf);
+ (int)(_mt_colors [count] [flag] >> 20) & 0xf ,
+ (int)(_mt_colors [count] [flag] >> 12) & 0xf ,
+ (int)(_mt_colors [count] [flag] >> 4) & 0xf);
ptr += strlen (ptr);
}
for (count = 0; count < 5; count ++) {
sprintf (ptr, "/%s%x%x%x" ,
flag ? "-" : "" ,
- (_mt_attrs [count] [flag] >> 20) & 0xf ,
- (_mt_attrs [count] [flag] >> 12) & 0xf ,
- (_mt_attrs [count] [flag] >> 4) & 0xf);
+ (int)(_mt_attrs [count] [flag] >> 20) & 0xf ,
+ (int)(_mt_attrs [count] [flag] >> 12) & 0xf ,
+ (int)(_mt_attrs [count] [flag] >> 4) & 0xf);
ptr += strlen (ptr);
}
char kill_char = CHAR_ESC;
char erase_char = CHAR_BS;
-WindowPtr _mt_window = (WindowPtr) 0;
+WindowRef _mt_window = (WindowRef) 0;
static Boolean _mt_in_color = 0;
extern short win_fonts [NHW_TEXT + 1];
if (create_tty (&_mt_window, WIN_BASE_KIND + NHW_MAP, _mt_in_color) != noErr)
error("_mt_init_stuff: Couldn't create tty.");
- ((WindowPeek) _mt_window)->windowKind = (WIN_BASE_KIND + NHW_MAP);
- SelectWindow (_mt_window);
- SetPort (_mt_window);
- SetOrigin (-1, -1);
-
+ SetWindowKind(_mt_window, WIN_BASE_KIND + NHW_MAP);
+ SelectWindow(_mt_window);
+ SetPortWindowPort(_mt_window);
+ SetOrigin(-1, -1);
+
font_size = iflags.wc_fontsiz_map ? iflags.wc_fontsiz_map :
(iflags.large_font && !small_screen) ? 12 : 9;
if (init_tty_number (_mt_window, win_fonts [NHW_MAP], font_size, CO, LI) != noErr)
#if defined(__SC__) || defined(__MRC__)
# pragma unused(color)
#endif
-Rect r;
-Point p = {0, 0};
-GDHandle gh;
+ Rect r;
+// Point p = {0, 0};
+ GDHandle gh;
- if (!_mt_in_color) {
+
+ if (!_mt_in_color)
return 0;
- }
- r = _mt_window->portRect;
- SetPort (_mt_window);
- LocalToGlobal (&p);
- OffsetRect (&r, p.h, p.v);
+ GetWindowBounds(_mt_window, kWindowContentRgn, &r);
+// SetPortWindowPort(_mt_window);
+// LocalToGlobal (&p);
+// OffsetRect (&r, p.h, p.v);
gh = GetMaxDevice (&r);
if (!gh) {
#include "config.h"
#include "dlb.h"
+/* Macintosh-specific code */
+#if defined(__APPLE__) && defined(__MACH__)
+ /* MacOS X has Unix-style files and processes */
+# undef MAC
+#endif
#ifdef MAC
# if defined(__SC__) || defined(__MRC__)
# define MPWTOOL
# if defined(__SC__) || defined(__MRC__)
# define MPWTOOL
# define PREFIX ":dungeon:" /* place output files here */
-#include <CursorCtl.h>
+# include <CursorCtl.h>
# else
-# define PREFIX ":lib:" /* place output files here */
+# if !defined(__MACH__)
+# define PREFIX ":lib:" /* place output files here */
+# endif
# endif
#endif
# define DATA_TEMPLATE "NH:slib/%s"
# define DATA_IN_TEMPLATE "NH:dat/%s"
#else /* not AMIGA */
-# ifdef MAC
+# if defined(MAC) && !defined(__MACH__)
+ /* MacOS 9 or earlier */
# define INCLUDE_TEMPLATE ":include:%s"
# define SOURCE_TEMPLATE ":src:%s"
# define DGN_TEMPLATE ":dat:%s" /* where dungeon.pdf file goes */