Files
Aerofoil/PortabilityLayer/PLCore.h

298 lines
6.1 KiB
C
Raw Normal View History

2019-11-11 00:11:59 -05:00
#pragma once
#include "DataTypes.h"
#include "PLErrorCodes.h"
#include "SharedTypes.h"
#include "QDPort.h"
2019-12-21 18:40:17 -05:00
#include "QDGraf.h"
2019-12-29 06:38:18 -05:00
#include "ResTypeID.h"
#include "VirtualDirectory.h"
2019-12-29 23:14:37 -05:00
#include "PLHandle.h"
2019-11-11 00:11:59 -05:00
#ifdef _MSC_VER
#pragma warning(error:4311) // Pointer truncation to int
#endif
2020-02-18 20:53:54 -05:00
template<class T>
class ArrayView;
2020-02-23 20:21:04 -05:00
struct IGpCursor;
2019-12-31 03:55:17 -05:00
struct GpVOSEvent;
struct GpMouseInputEvent;
2019-12-31 03:55:17 -05:00
struct TimeTaggedVOSEvent;
2019-12-22 00:35:30 -05:00
2020-02-18 20:53:54 -05:00
2019-11-11 00:11:59 -05:00
namespace PortabilityLayer
{
struct MMHandleBlock;
2019-12-29 06:38:18 -05:00
class IOStream;
2020-01-05 02:33:03 -05:00
class Widget;
2019-11-11 00:11:59 -05:00
}
typedef uint8_t Boolean;
typedef uint8_t Byte;
typedef uint8_t UInt8;
typedef int16_t SInt16;
typedef int32_t Int32;
typedef uint32_t UInt32;
typedef size_t Size;
typedef unsigned char Str15[16];
typedef unsigned char Str31[32];
typedef unsigned char Str63[64];
typedef unsigned char Str27[28];
typedef unsigned char Str32[33];
typedef unsigned char Str255[256];
typedef unsigned char *StringPtr;
class PLPasStr;
2019-12-30 20:53:11 -05:00
struct DrawSurface;
2020-01-05 02:33:03 -05:00
2019-12-21 18:40:17 -05:00
struct Menu;
typedef void *Ptr;
2019-11-11 00:11:59 -05:00
#define PL_DEAD(n) ((void)0)
struct FinderInfoBlock
{
Int32 fdType;
Int32 fdCreator;
};
2019-12-12 23:37:40 -05:00
struct DirectoryFileListEntry
{
FinderInfoBlock finderInfo;
Str32 name;
DirectoryFileListEntry *nextEntry;
};
2019-11-11 00:11:59 -05:00
struct Cursor
{
};
2020-02-23 20:21:04 -05:00
namespace WindowChromeSides
{
enum WindowChromeSide
{
kTop,
kLeft,
kBottom,
kRight,
kCount
};
}
typedef WindowChromeSides::WindowChromeSide WindowChromeSide_t;
2019-11-11 00:11:59 -05:00
struct Window
{
Window();
2019-12-30 20:53:11 -05:00
DrawSurface *GetDrawSurface() const;
// Convenience method to convert a mouse event to local point
Point MouseToLocal(const GpMouseInputEvent &evt) const;
2020-01-05 02:33:03 -05:00
// Convenience method that returns a 16-bit precision X/Y
Point TopLeftCoord() const;
bool AddWidget(PortabilityLayer::Widget *widget);
2020-02-23 20:21:04 -05:00
ArrayView<PortabilityLayer::Widget*> GetWidgets() const;
2020-03-01 17:01:35 -05:00
PortabilityLayer::Widget *GetWidgetById() const;
bool ReplaceWidget(PortabilityLayer::Widget *oldWidget, PortabilityLayer::Widget *newWidget);
2020-01-05 02:33:03 -05:00
void FocusWidget(PortabilityLayer::Widget *widget);
PortabilityLayer::Widget *GetWidgetWithFocus() const;
2020-01-05 02:33:03 -05:00
void DrawControls();
bool IsHandlingTickEvents();
void OnTick();
2020-01-05 02:33:03 -05:00
2020-02-23 20:21:04 -05:00
DrawSurface *GetChromeSurface(WindowChromeSide_t aChromeSide) const;
2020-02-18 20:53:54 -05:00
DrawSurface m_surface; // Must be the first item until the immediate mode draw API is completely removed
2019-11-11 00:11:59 -05:00
2019-12-21 18:40:17 -05:00
// The port is always at 0,0
// These are the WM coordinates
int32_t m_wmX;
int32_t m_wmY;
protected:
~Window();
2020-01-05 02:33:03 -05:00
2020-02-23 20:21:04 -05:00
DrawSurface m_chromeSurfaces[WindowChromeSides::kCount];
2020-01-05 02:33:03 -05:00
PortabilityLayer::Widget **m_widgets;
size_t m_numWidgets;
size_t m_numTickReceivingWidgets;
2020-02-07 22:08:52 -05:00
PortabilityLayer::Widget *m_widgetWithFocus;
2019-11-11 00:11:59 -05:00
};
struct DateTimeRec
{
int month;
int hour;
int minute;
};
struct VersionRecord
{
Byte majorVer;
Byte minorVer;
Byte stage;
Byte rcVer;
short countryCode;
Str255 shortVersion;
Str255 unused;
};
struct ColorSpec
{
uint8_t r, g, b;
};
2019-12-29 06:38:18 -05:00
struct VFileSpec
2019-11-11 00:11:59 -05:00
{
2019-12-29 06:38:18 -05:00
PortabilityLayer::VirtualDirectory_t m_dir;
Str63 m_name;
2019-11-11 00:11:59 -05:00
};
2019-12-29 06:38:18 -05:00
struct VFileInfo
2019-11-11 00:11:59 -05:00
{
2019-12-29 06:38:18 -05:00
PortabilityLayer::ResTypeID m_type;
PortabilityLayer::ResTypeID m_creator;
};
2019-11-11 00:11:59 -05:00
struct HFileParam
{
int ioVRefNum;
long ioDirID;
const unsigned char *ioNamePtr;
void *ioCompletion;
};
struct EventRecord
{
Point where;
uint32_t when;
intptr_t message;
int what;
int modifiers;
};
typedef Window *WindowPtr;
typedef Cursor *CursPtr;
typedef Menu *MenuPtr;
typedef VersionRecord *VersRecPtr;
2019-12-29 23:14:37 -05:00
typedef THandle<Cursor> CursHandle;
typedef THandle<Menu> MenuHandle;
typedef THandle<VersionRecord> VersRecHndl;
2019-11-11 00:11:59 -05:00
typedef WindowPtr WindowRef; // wtf?
2019-12-31 03:55:17 -05:00
struct KeyDownStates;
2019-11-11 00:11:59 -05:00
2020-02-26 12:26:19 -05:00
namespace RegionIDs
2019-11-11 00:11:59 -05:00
{
2020-02-26 12:26:19 -05:00
enum RegionID
{
kNone,
kMenuBar = 1,
kContent,
kTitleBar,
kClose,
kExpand,
};
}
typedef RegionIDs::RegionID RegionID_t;
2019-11-11 00:11:59 -05:00
static const int everyEvent = -1;
static const int iBeamCursor = 1;
static const int watchCursor = 4;
static const Boolean TRUE = 1;
static const Boolean FALSE = 0;
#define nil nullptr
static const int nullEvent = 0;
//void FlushEvents(int eventMask, int stopMask);
void InitCursor();
void HideCursor();
void Delay(int ticks, UInt32 *endTickCount);
short FindWindow(Point point, WindowPtr *window); // Translates global coordinates to window coordinates, returns a region ID
bool TrackGoAway(WindowPtr window, Point point); // Returns true if the close box was actually clicked (?)
Int32 GrowWindow(WindowPtr window, Point start, Rect *size);
bool TrackBox(WindowPtr window, Point point, int part); // Returns true if grow/shrink box was clicked (part corresponds to type)
WindowPtr GetNewCWindow(int resID, void *storage, WindowPtr behind);
void SizeWindow(WindowPtr window, int width, int height, Boolean addToUpdateRegion);
void MoveWindow(WindowPtr window, int x, int y, Boolean moveToFront);
void ShowWindow(WindowPtr window);
long MenuSelect(Point point); // Breaks into menu select routine (in practice we'll just forward one from the queue?)
long MenuKey(intptr_t charCode);
2019-11-11 00:11:59 -05:00
long TickCount();
short LoWord(Int32 v);
short HiWord(Int32 v);
void NumToString(long number, unsigned char *str);
2019-12-29 06:38:18 -05:00
PLError_t AEProcessAppleEvent(EventRecord *evt);
2019-11-11 00:11:59 -05:00
void GetIndString(unsigned char *str, int stringsID, int fnameIndex); // Fetches a string resource of some sort
2019-12-29 06:38:18 -05:00
VFileSpec MakeVFileSpec(PortabilityLayer::VirtualDirectory_t dir, const PLPasStr &fileName);
PLError_t FSpGetFInfo(const VFileSpec &spec, VFileInfo &finfoOut);
DirectoryFileListEntry *GetDirectoryFiles(PortabilityLayer::VirtualDirectory_t dirID);
2019-12-12 23:37:40 -05:00
void DisposeDirectoryFiles(DirectoryFileListEntry *firstDFL);
void GetMouse(Window *window, Point *point);
2019-11-11 00:11:59 -05:00
Boolean Button(); // Returns true if there's a mouse down event in the queue
Boolean StillDown();
Boolean WaitMouseUp();
short Random();
void GetTime(DateTimeRec *dateTime);
void FlushEvents(int mask, int unknown);
Handle NewHandle(Size size);
long GetHandleSize(Handle handle);
2019-12-29 06:38:18 -05:00
PLError_t SetHandleSize(Handle hdl, Size newSize);
2019-11-11 00:11:59 -05:00
void *NewPtr(Size size);
void *NewPtrClear(Size size);
void DisposePtr(void *ptr);
2019-12-31 03:55:17 -05:00
bool WaitForEvent(TimeTaggedVOSEvent *evt, uint32_t ticks);
2019-11-11 00:11:59 -05:00
static const Boolean PL_TRUE = 1;
static const Boolean PL_FALSE = 0;
WindowPtr PL_GetPutInFrontWindowPtr();
2019-11-11 00:11:59 -05:00
void PL_NotYetImplemented();
void PL_NotYetImplemented_Minor();
2019-12-21 18:40:17 -05:00
void PL_NotYetImplemented_TODO(const char *category);
2019-11-11 00:11:59 -05:00
void PL_Init();