Synch recent 3.4.2 changes to main trunk

This is merely a synchronization of recent changes for the
Macintosh Carbon port, which were committed to the 3.4.2
branch, to the main trunk.
This commit is contained in:
kmhugo
2003-08-30 00:45:58 +00:00
parent 2ea07652d8
commit 1282e5c623
24 changed files with 493 additions and 289 deletions

View File

@@ -2,6 +2,9 @@
#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,

View File

@@ -6,9 +6,11 @@
#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;
@@ -100,7 +102,7 @@ Point p;
*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 ()));
}
@@ -131,12 +133,12 @@ SavePosition (short kind, short top, short left)
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();
}
@@ -163,7 +165,7 @@ GetWinKind (WindowPtr win)
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;
}
@@ -190,32 +192,32 @@ GetWinKind (WindowPtr win)
Boolean
RetrieveWinPos (WindowPtr win, short *top, short *left)
{ return RetrievePosition (GetWinKind (win), top, left);
}
void
SaveWindowPos (WindowPtr win)
RetrieveWinPos(WindowPtr win, short *top, short *left)
{
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);
return RetrievePosition(GetWinKind (win), top, left);
}
void
SaveWindowSize (WindowPtr win)
SaveWindowPos(WindowPtr win)
{
Rect r;
GetWindowBounds(win, kWindowContentRgn, &r);
SavePosition(GetWinKind(win), r.top, r.left);
}
void
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);
}

View File

@@ -9,9 +9,11 @@
#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,...)

View File

@@ -8,12 +8,16 @@
#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"
/*
@@ -363,6 +367,18 @@ macseek (int fd, long where, short whence)
}
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) {

View File

@@ -9,6 +9,7 @@
#include "macwin.h"
#include "mactty.h"
#if !TARGET_API_MAC_CARBON
#include <OSUtils.h>
#include <files.h>
#include <Types.h>
@@ -17,6 +18,7 @@
#include <ToolUtils.h>
#include <Resources.h>
#include <Errors.h>
#endif
#ifndef O_RDONLY
#include <fcntl.h>

View File

@@ -28,12 +28,17 @@
#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 ********/
@@ -205,12 +210,12 @@ static short kAdjustWizardMenu = 1;
/******** 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);
@@ -239,9 +244,9 @@ 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();}
@@ -255,7 +260,7 @@ static int askselect[RSRC_ASK_MAX];
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},
@@ -280,7 +285,7 @@ ask_restring (const char *cstr, unsigned char *pstr)
/* 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;
@@ -298,7 +303,7 @@ ask_enable (WindowPtr wind, short item, int enable)
static pascal void
ask_redraw (WindowPtr wind, DialogItemIndex item)
ask_redraw (DialogRef wind, DialogItemIndex item)
{
short type;
Handle handle;
@@ -431,7 +436,7 @@ ask_redraw (WindowPtr wind, DialogItemIndex item)
static pascal Boolean
ask_filter (WindowPtr wind, EventRecord *event, DialogItemIndex *item)
ask_filter (DialogRef wind, EventRecord *event, DialogItemIndex *item)
{
short ch, key;
@@ -444,7 +449,7 @@ ask_filter (WindowPtr wind, EventRecord *event, DialogItemIndex *item)
/* 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
@@ -491,21 +496,21 @@ ask_filter (WindowPtr wind, EventRecord *event, DialogItemIndex *item)
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);
@@ -628,18 +633,18 @@ void mac_askname ()
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;
}
@@ -647,19 +652,19 @@ void mac_askname ()
} 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;
}
@@ -667,19 +672,19 @@ void mac_askname ()
} 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;
}
@@ -687,7 +692,7 @@ void mac_askname ()
} 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 */
@@ -695,14 +700,14 @@ void mac_askname ()
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 */
@@ -724,7 +729,7 @@ void mac_askname ()
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
@@ -806,22 +811,29 @@ void mac_askname ()
/*** 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++)
@@ -833,7 +845,9 @@ mustGetMenuAlerts()
ExitToShell();
}
alignAD(*hRct, mbarHgt);
#if !TARGET_API_MAC_CARBON
alignAD(*hRct, GetMBarHeight());
#endif
}
}
@@ -857,7 +871,7 @@ InitMenuRes()
static Boolean was_inited = 0;
short i, j;
menuListHandle mlHnd;
MenuHandle mHnd;
MenuHandle menu;
if (was_inited)
return;
@@ -865,30 +879,30 @@ InitMenuRes()
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();
@@ -899,7 +913,7 @@ void
AdjustMenus(short dimMenubar)
{
short newMenubar = mbarRegular;
WindowPeek peekWindow = (WindowPeek) FrontWindow();
WindowRef win = FrontWindow();
short i;
/*
@@ -908,20 +922,14 @@ AdjustMenus(short dimMenubar)
* }
*/
/* 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 */
@@ -949,7 +957,7 @@ AdjustMenus(short dimMenubar)
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);
}
}
@@ -962,25 +970,25 @@ AdjustMenus(short dimMenubar)
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;
@@ -988,19 +996,19 @@ AdjustMenus(short dimMenubar)
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;
}
@@ -1020,6 +1028,7 @@ DoMenuEvt(long menuEntry)
case menuApple:
if (menuItem == menuAppleAboutBox)
aboutNetHack();
#if !TARGET_API_MAC_CARBON
else
{
unsigned char daName[32];
@@ -1027,6 +1036,7 @@ DoMenuEvt(long menuEntry)
GetMenuItemText(MHND_APPLE, menuItem, * (Str255 *) daName);
(void) OpenDeskAcc(daName);
}
#endif
break;
/*
@@ -1064,7 +1074,9 @@ DoMenuEvt(long menuEntry)
break;
case menuEdit:
#if !TARGET_API_MAC_CARBON
(void) SystemEdit(menuItem - 1);
#endif
break;
default: /* get associated string and add to key queue */

View File

@@ -17,8 +17,12 @@
#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)

View File

@@ -12,7 +12,9 @@
#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 */
@@ -103,6 +105,7 @@ dispose_ptr (void *ptr) {
}
#if 0 /* Use alloc.c instead */
/*
* Allocate a pointer using the set memory-allocator
*/
@@ -111,6 +114,7 @@ alloc_ptr (void **ptr, long size) {
*ptr = NewPtr (size);
return MemError ();
}
#endif
/*
@@ -185,6 +189,7 @@ free_bits (tty_record *record) {
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) {
@@ -197,6 +202,7 @@ free_bits (tty_record *record) {
}
}
}
#endif
}
return s_err;
}
@@ -207,14 +213,16 @@ free_bits (tty_record *record) {
* 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 ();
@@ -222,11 +230,15 @@ Boolean was_allocated = !!*window;
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;
@@ -243,8 +255,8 @@ Boolean was_allocated = !!*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;
}
@@ -287,11 +299,15 @@ RECORD_EXISTS (record);
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);
}
@@ -348,6 +364,7 @@ short s_err;
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);
@@ -361,6 +378,7 @@ short s_err;
ClipRect (&(record->its_bits.bounds));
SetPortBits (&(record->its_bits));
}
#endif
}
return s_err;
}
@@ -427,9 +445,9 @@ static void
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);
}
}
@@ -438,18 +456,21 @@ select_onscreen_window (tty_record *record) {
* 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);
@@ -506,6 +527,7 @@ RECORD_EXISTS (record);
}
#if 0
/*
* Update TTY according to new color environment for the window
*/
@@ -526,6 +548,7 @@ Rect r_screen;
}
return 0;
}
#endif
/*
@@ -600,7 +623,7 @@ short get_invalid_region (WindowPtr window, Rect *inval_rect) {
*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
@@ -835,12 +858,13 @@ RECORD_EXISTS (record);
* 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);

View File

@@ -8,14 +8,17 @@
#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;
@@ -126,7 +129,7 @@ MacFlags macFlags;
/*
* The screen layouts on the small 512x342 screen need special cares.
*/
Boolean small_screen;
Boolean small_screen = 0;
#ifdef NHW_BASE
# undef NHW_BASE
@@ -285,6 +288,8 @@ InitMac(void) {
long l;
Str255 volName;
#if !TARGET_API_MAC_CARBON
if (LMGetDefltStack() < 50 * 1024L) {
SetApplLimit ((void *) ((long) LMGetCurStackBase() - (50 * 1024L)));
}
@@ -298,6 +303,7 @@ InitMac(void) {
InitMenus ();
InitDialogs (0L);
TEInit ();
#endif
memset (&macFlags, 0, sizeof(macFlags));
if (!Gestalt (gestaltOSAttr, & l)) {
@@ -330,12 +336,13 @@ InitMac(void) {
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;
@@ -345,16 +352,19 @@ InitMac(void) {
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
@@ -362,6 +372,7 @@ InitMac(void) {
*/
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] == ':') {
@@ -403,27 +414,31 @@ set_tty_font_name (int window_type, char *font_name) {
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);
@@ -450,7 +465,7 @@ short val, lin, win_height;
HiliteControl (aWin->scrollBar, val);
val = GetControlValue (aWin->scrollBar);
if (val != aWin->scrollPos) {
InvalRect (&(theWindow->portRect));
InvalWindowRect(theWindow, &wrect);
aWin->scrollPos = val;
}
}
@@ -464,14 +479,22 @@ short val, lin, win_height;
* 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 */
@@ -544,7 +567,8 @@ SanePositions (void) {
}
}
}
return 0;
#endif
return (0);
}
@@ -566,12 +590,11 @@ mac_create_nhwindow (int kind) {
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!");
@@ -608,8 +631,8 @@ got1 :
}
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);
@@ -621,8 +644,7 @@ got1 :
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];
@@ -651,11 +673,13 @@ got1 :
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;
}
@@ -664,9 +688,14 @@ got1 :
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 ();
@@ -688,6 +717,13 @@ mac_init_nhwindows (int *argcp, char **argv) {
*/
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;
}
@@ -709,12 +745,13 @@ mac_clear_nhwindow (winid win) {
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 */
@@ -761,7 +798,7 @@ mac_clear_nhwindow (winid win) {
aWin->y_curs = 0;
aWin->x_curs = 0;
aWin->drawn = FALSE;
InvalRect (&r);
InvalWindowRect(theWindow, &r);
}
@@ -773,9 +810,15 @@ ClosingWindowChar(const int c) {
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);
}
@@ -784,11 +827,18 @@ in_topl_mode(void) {
#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;
}
@@ -813,7 +863,7 @@ enter_topl_mode(char *query) {
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;
@@ -913,7 +963,7 @@ static void
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);
@@ -925,12 +975,12 @@ topl_flash_resp(int resp_idx) {
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);
}
@@ -946,14 +996,14 @@ topl_set_resp(char *resp, char def) {
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);
@@ -1020,8 +1070,20 @@ topl_resp_key(char ch) {
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,
@@ -1029,7 +1091,7 @@ adjust_window_pos(NhWindow *aWin, short width, short height) {
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;
@@ -1050,6 +1112,8 @@ adjust_window_pos(NhWindow *aWin, short width, short height) {
MoveWindow(theWindow, pos.h, pos.v, false);
if (aWin->scrollBar)
DrawScrollbar (aWin);
#endif
return;
}
@@ -1083,7 +1147,7 @@ mac_display_nhwindow (winid win, BOOLEAN_P f) {
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);
@@ -1146,12 +1210,12 @@ mac_destroy_nhwindow (winid win) {
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;
@@ -1214,8 +1278,11 @@ GeneralKey (EventRecord *theEvent, WindowPtr theWindow) {
* 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;
@@ -1290,13 +1357,13 @@ macKeyMenu (EventRecord *theEvent, WindowPtr theWindow) {
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 */
@@ -1314,11 +1381,15 @@ macKeyMenu (EventRecord *theEvent, WindowPtr theWindow) {
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;
@@ -1329,8 +1400,6 @@ macClickMenu (EventRecord *theEvent, WindowPtr theWindow) {
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;
@@ -1338,11 +1407,13 @@ macClickMenu (EventRecord *theEvent, WindowPtr theWindow) {
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 */
}
@@ -1408,7 +1479,7 @@ static void
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;
@@ -1437,7 +1508,9 @@ macClickMessage (EventRecord *theEvent, WindowPtr theWindow) {
InvertRect(&frame);
while (WaitMouseUp()) {
#if !TARGET_API_MAC_CARBON
SystemTask();
#endif
GetMouse(&mouse);
if (PtInRect(mouse, &frame) != in_btn) {
in_btn = !in_btn;
@@ -1471,9 +1544,11 @@ macClickTerm (EventRecord *theEvent, WindowPtr theWindow) {
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;
@@ -1492,12 +1567,14 @@ MoveScrollBar (ControlHandle theBar, short part) {
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;
@@ -1517,36 +1594,39 @@ MoveScrollBar (ControlHandle theBar, short part) {
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);
}
}
}
@@ -1563,7 +1643,7 @@ filter_scroll_key(const int ch, NhWindow *aWin) {
part = kControlDownButtonPart;
}
if (part) {
SetPort(aWin->its_window);
SetPortWindowPort(aWin->its_window);
MoveScrollBar(aWin->scrollBar, part);
return 0;
}
@@ -1577,7 +1657,7 @@ mac_doprev_message(void) {
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;
@@ -1591,15 +1671,18 @@ macDoNull (EventRecord *theEvent, WindowPtr theWindow) {
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);
@@ -1609,16 +1692,19 @@ draw_growicon_vert_only(WindowPtr wind) {
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);
@@ -1717,7 +1803,7 @@ macUpdateMessage (EventRecord *theEvent, WindowPtr 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);
@@ -1752,15 +1838,18 @@ macUpdateMenu (EventRecord *theEvent, WindowPtr theWindow) {
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;
@@ -1807,7 +1896,7 @@ macCursorTerm (EventRecord *theEvent, WindowPtr theWindow, RgnHandle mouseRgn) {
Rect r = {0, 0, 1, 1};
GetPort (&gp);
SetPort (theWindow);
SetPortWindowPort(theWindow);
if (cursor_locked)
dir = (char *)0;
@@ -1826,7 +1915,7 @@ macCursorTerm (EventRecord *theEvent, WindowPtr theWindow, RgnHandle mouseRgn) {
HUnlock ((Handle) ch);
} else {
SetCursor(&qd.arrow);
SetCursor(&qdarrow);
}
OffsetRect (&r, theEvent->where.h, theEvent->where.v);
RectRgn (mouseRgn, &r);
@@ -1841,7 +1930,7 @@ GeneralCursor (EventRecord *theEvent, WindowPtr theWindow, RgnHandle mouseRgn) {
#endif
Rect r = {-1, -1, 2, 2};
SetCursor(&qd.arrow);
SetCursor(&qdarrow);
OffsetRect (&r, theEvent->where.h, theEvent->where.v);
RectRgn (mouseRgn, &r);
}
@@ -1865,7 +1954,7 @@ HandleKey (EventRecord *theEvent) {
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);
@@ -1898,10 +1987,10 @@ HandleClick (EventRecord *theEvent) {
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);
@@ -1910,10 +1999,10 @@ HandleClick (EventRecord *theEvent) {
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 ();
@@ -1922,9 +2011,9 @@ HandleClick (EventRecord *theEvent) {
case inDrag :
if (not_inSelect) {
SetCursor(&qd.arrow);
SetCursor(&qdarrow);
DragWindow (theWindow, theEvent->where, &r);
SaveWindowPos (theWindow);
SaveWindowPos(theWindow);
} else {
nhbell ();
}
@@ -1932,15 +2021,17 @@ HandleClick (EventRecord *theEvent) {
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);
}
@@ -1957,8 +2048,10 @@ HandleClick (EventRecord *theEvent) {
DoMenuEvt (MenuSelect (theEvent->where));
break;
#if !TARGET_API_MAC_CARBON
case inSysWindow :
SystemClick(theEvent, theWindow);
#endif
default :
break;
}
@@ -1969,6 +2062,8 @@ static void
HandleUpdate (EventRecord *theEvent) {
WindowPtr theWindow = (WindowPtr) theEvent->message;
NhWindow *aWin = GetNhWin (theWindow);
Rect r;
char existing_update_region = FALSE;
Rect rect;
@@ -1977,9 +2072,11 @@ HandleUpdate (EventRecord *theEvent) {
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) {
@@ -1992,24 +2089,23 @@ HandleUpdate (EventRecord *theEvent) {
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);
}
}
}
@@ -2029,12 +2125,14 @@ HandleEvent (EventRecord *theEvent) {
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;
@@ -2054,8 +2152,8 @@ mac_get_nh_event(void) {
if (!iflags.window_inited)
return;
(void) WaitNextEvent (everyEvent, &anEvent, 0, gMouseRgn);
HandleEvent (&anEvent);
(void) WaitNextEvent (everyEvent, &anEvent, -1, gMouseRgn);
HandleEvent(&anEvent);
}
@@ -2163,8 +2261,9 @@ mac_putstr (winid win, int attr, const char *str) {
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;
@@ -2237,7 +2336,7 @@ mac_putstr (winid win, int attr, const char *str) {
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)
@@ -2255,7 +2354,7 @@ mac_curs (winid win, int x, int y) {
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;
@@ -2492,7 +2591,6 @@ try_key_queue (char *bufp) {
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,

View File

@@ -30,8 +30,6 @@ get_line_from_key_queue (char * bufp) {
static void
topl_getlin(const char *query, char *bufp, Boolean ext) {
int q_len = strlen(query);
if (get_line_from_key_queue (bufp))
return;

View File

@@ -2,13 +2,18 @@
/* 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;

View File

@@ -8,7 +8,9 @@
#include "mactty.h"
#include "wintty.h"
#if !TARGET_API_MAC_CARBON
#include <Palettes.h>
#endif
#define MT_WINDOW 135
#define MT_WIDTH 80
@@ -157,9 +159,9 @@ static char color_buf [5 * (CLR_MAX + 5) + 1];
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 ++) {
@@ -167,9 +169,9 @@ static char color_buf [5 * (CLR_MAX + 5) + 1];
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);
}
@@ -183,7 +185,7 @@ extern struct DisplayDesc *ttyDisplay; /* the tty display descriptor */
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];
@@ -227,11 +229,11 @@ short hor, vert;
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)
@@ -300,18 +302,18 @@ has_color (int color) {
#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) {