/* OSGLUWIN.c Copyright (C) 2009 Philip Cummins, Weston Pawlowski, Bradford L. Barrett, Paul C. Pratt, Fabio Concas You can redistribute this file and/or modify it under the terms of version 2 of the GNU General Public License as published by the Free Software Foundation. You should have received a copy of the license along with this file; see the file COPYING. This file is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the license for more details.*/ /* Operating System GLUe for microsoft WINdows All operating system dependent code for the Microsoft Windows platform should go here. This code is descended from Weston Pawlowski's Windows port of vMac, by Philip Cummins. Adapted by Fabio Concas to run on Pocket PC 2003 devices. The main entry point '_tWinMain' is at the end of this file.*/ #include "CNFGRAPI.h"#include "SYSDEPNS.h"#include "ENDIANAC.h" #include "MYOSGLUE.h" /* --- adapting to API/ABI version differences --- */ #ifdef UNICODE#define MyUseUni 1#else#define MyUseUni 0#endif #ifdef _WIN32_WCE#define UseWinCE 1#else#define UseWinCE 0#endif #define My_CSIDL_APPDATA 0x001a typedef BOOL (WINAPI *SHGetSpecialFolderPathProcPtr) ( HWND hwndOwner, LPTSTR lpszPath, int nFolder, BOOL fCreate);LOCALVAR SHGetSpecialFolderPathProcPtr MySHGetSpecialFolderPath = NULL;LOCALVAR blnr DidSHGetSpecialFolderPath = falseblnr; LOCALFUNC blnr HaveMySHGetSpecialFolderPath(void){ if (! DidSHGetSpecialFolderPath) { HMODULE hLibModule = LoadLibrary(TEXT("shell32.dll")); if (NULL != hLibModule) { MySHGetSpecialFolderPath = (SHGetSpecialFolderPathProcPtr) GetProcAddress(hLibModule,#if MyUseUni TEXT("SHGetSpecialFolderPathW")#else TEXT("SHGetSpecialFolderPathA")#endif ); /* FreeLibrary(hLibModule); */ } DidSHGetSpecialFolderPath = trueblnr; } return (MySHGetSpecialFolderPath != NULL);} /* --- end of adapting to API/ABI version differences --- */ #include "STRCONST.h" #if MyUseUni#define NeedCell2UnicodeMap 1#else#define NeedCell2WinAsciiMap 1#endif #include "INTLCHAR.h" LOCALPROC NativeStrFromCStr(LPTSTR r, char *s, blnr AddEllipsis){ ui3b ps[ClStrMaxLength]; int i; int L; ClStrFromSubstCStr(&L, ps, s); for (i = 0; i < L; ++i) { r[i] = (TCHAR)#if MyUseUni Cell2UnicodeMap[ps[i]];#else Cell2WinAsciiMap[ps[i]];#endif } if (AddEllipsis) {#if MyUseUni r[L] = 0x2026; ++L;#else r[L] = '.'; ++L; r[L] = '.'; ++L; r[L] = '.'; ++L;#endif } r[L] = 0;} LOCALFUNC LPTSTR FindLastTerm(LPTSTR s, TCHAR delim){ TCHAR c; LPTSTR p0 = s; LPTSTR p = (LPTSTR)nullpr; while ((c = *p0++) != (TCHAR)('\0')) { if (c == delim) { p = p0; } } return p;} LOCALVAR HINSTANCE AppInstance; LOCALFUNC blnr GetAppDir(LPTSTR pathName)/* be sure at least _MAX_PATH long! */{ if (GetModuleFileName(AppInstance, pathName, _MAX_PATH) == 0) { /* MacMsg("error", "GetModuleFileName failed", falseblnr); */ } else { LPTSTR p = FindLastTerm(pathName, (TCHAR)('\\')); if (p == nullpr) { /* MacMsg("error", "strrchr failed", falseblnr); */ } else { *--p = (TCHAR)('\0'); return trueblnr; } } return falseblnr;} /* --- sending debugging info to file --- */ #if dbglog_HAVE LOCALVAR HANDLE dbglog_File = INVALID_HANDLE_VALUE; LOCALFUNC blnr dbglog_open0(void){ TCHAR pathName[_MAX_PATH]; TCHAR Child0[] = TEXT("\\dbglog.txt"); size_t newlen; if (GetAppDir(pathName)) { newlen = _tcslen(pathName) + _tcslen(Child0); if (newlen + 1 < _MAX_PATH) { _tcscat(pathName, Child0); dbglog_File = CreateFile( pathName, /* pointer to name of the file */ GENERIC_READ + GENERIC_WRITE, /* access (read-write) mode */ 0, /* share mode */ NULL, /* pointer to security descriptor */ OPEN_ALWAYS, /* how to create */ FILE_ATTRIBUTE_NORMAL, /* file attributes */ NULL /* handle to file with attributes to copy */ ); if (INVALID_HANDLE_VALUE == dbglog_File) { /* report error (how?) */ } else if (SetFilePointer( dbglog_File, /* handle of file */ 0, /* number of bytes to move file pointer */ nullpr, /* address of high-order word of distance to move */ FILE_BEGIN /* how to move */ ) != 0) { /* report error (how?) */ } } } return (INVALID_HANDLE_VALUE != dbglog_File);} LOCALPROC dbglog_write0(char *s, uimr L){ DWORD BytesWritten; if (INVALID_HANDLE_VALUE != dbglog_File) { if (! WriteFile(dbglog_File, /* handle of file to read */ (LPVOID)s, /* address of buffer that receives data */ (DWORD)L, /* number of bytes to read */ &BytesWritten, /* address of number of bytes read */ nullpr) /* address of structure for data */ || ((ui5b)BytesWritten != L)) { /* report error (how?) */ } }} LOCALPROC dbglog_close0(void){ if (INVALID_HANDLE_VALUE != dbglog_File) { if (! SetEndOfFile(dbglog_File)) { /* report error (how?) */ } (void) CloseHandle(dbglog_File); dbglog_File = INVALID_HANDLE_VALUE; }} #endif #include "COMOSGLU.h" #ifndef InstallFileIcons#define InstallFileIcons 0#endif /* Resource Ids */ #define IDI_VMAC 256#if InstallFileIcons#define IDI_ROM 257#define IDI_DISK 258#endif /* --- some simple utilities --- */ #define TestBit(i, p) (((unsigned long)(i) & PowOf2(p)) != 0) GLOBALOSGLUPROC MyMoveBytes(anyp srcPtr, anyp destPtr, si5b byteCount){/* must work even if blocks overlap in memory*/ (void) memcpy((char *)destPtr, (char *)srcPtr, byteCount);} /* --- Parameter buffers --- */ #if IncludePbufsLOCALVAR HGLOBAL PbufDat[NumPbufs];#endif #if IncludePbufsLOCALFUNC tMacErr PbufNewFromHandle(HGLOBAL h, ui5b count, tPbuf *r){ tPbuf i; tMacErr err; if (! FirstFreePbuf(&i)) { (void) GlobalFree(h); err = mnvm_miscErr; } else { *r = i; PbufDat[i] = h; PbufNewNotify(i, count); err = mnvm_noErr; } return err;}#endif #if IncludePbufsGLOBALOSGLUFUNC tMacErr PbufNew(ui5b count, tPbuf *r){ HGLOBAL h; tMacErr err = mnvm_miscErr; h = GlobalAlloc(GMEM_DDESHARE | GMEM_ZEROINIT, count); if (h != NULL) { /* need to clear h */ err = PbufNewFromHandle(h, count, r); } return err;}#endif #if IncludePbufsGLOBALOSGLUPROC PbufDispose(tPbuf i){ (void) GlobalFree(PbufDat[i]); PbufDisposeNotify(i);}#endif #if IncludePbufsLOCALPROC UnInitPbufs(void){ tPbuf i; for (i = 0; i < NumPbufs; ++i) { if (PbufIsAllocated(i)) { PbufDispose(i); } }}#endif #if IncludePbufs#define PbufHaveLock 1#endif #if IncludePbufsLOCALFUNC ui3p PbufLock(tPbuf i){ HGLOBAL h = PbufDat[i]; return (ui3p)GlobalLock(h);}#endif #if IncludePbufsLOCALPROC PbufUnlock(tPbuf i){ (void) GlobalUnlock(PbufDat[i]);}#endif #if IncludePbufsGLOBALOSGLUPROC PbufTransfer(ui3p Buffer, tPbuf i, ui5r offset, ui5r count, blnr IsWrite){ HGLOBAL h = PbufDat[i]; ui3p p0 = GlobalLock(h); if (p0 != NULL) { void *p = p0 + offset; if (IsWrite) { (void) memcpy(p, Buffer, count); } else { (void) memcpy(Buffer, p, count); } } (void) GlobalUnlock(h);}#endif /* --- control mode and internationalization --- */ #include "CONTROLM.h" /* --- main window info --- */ LOCALVAR HWND MainWnd = NULL; LOCALVAR int WndX;LOCALVAR int WndY; #if UseWinCELOCALVAR short oldOrientation;LOCALVAR unsigned long oldDisplayOrientation;#endif #if VarFullScreenLOCALVAR blnr UseFullScreen = (WantInitFullScreen != 0);#endif #if EnableMagnifyLOCALVAR blnr UseMagnify = (WantInitMagnify != 0);#endif #if MayFullScreenLOCALVAR short hOffset;LOCALVAR short vOffset;#endif /* cursor hiding */ LOCALVAR blnr HaveCursorHidden = falseblnr;LOCALVAR blnr WantCursorHidden = falseblnr; LOCALPROC ForceShowCursor(void){ if (HaveCursorHidden) { HaveCursorHidden = falseblnr; (void) ShowCursor(TRUE); SetCursor(LoadCursor(NULL, IDC_ARROW)); }} /* cursor moving */ LOCALFUNC blnr MyMoveMouse(si4b h, si4b v){ POINT NewMousePos; ui5b difftime; blnr IsOk; DWORD StartTime = GetTickCount(); LONG x = h; LONG y = v; #if VarFullScreen if (UseFullScreen)#endif#if MayFullScreen { x -= ViewHStart; y -= ViewVStart; }#endif #if EnableMagnify if (UseMagnify) { x *= MyWindowScale; y *= MyWindowScale; }#endif #if VarFullScreen if (UseFullScreen)#endif#if MayFullScreen { x += hOffset; y += vOffset; }#endif x += WndX; y += WndY; do { (void) SetCursorPos(x, y); if (! GetCursorPos(&NewMousePos)) { IsOk = falseblnr; } else { IsOk = (x == NewMousePos.x) && (y == NewMousePos.y); } difftime = (ui5b)(GetTickCount() - StartTime); } while ((! IsOk) && (difftime < 100)); return IsOk;} #if EnableFSMouseMotionLOCALPROC StartSaveMouseMotion(void){ if (! HaveMouseMotion) { if (MyMoveMouse(ViewHStart + (ViewHSize / 2), ViewVStart + (ViewVSize / 2))) { SavedMouseH = ViewHStart + (ViewHSize / 2); SavedMouseV = ViewVStart + (ViewVSize / 2); HaveMouseMotion = trueblnr; } }}#endif #if EnableFSMouseMotionLOCALPROC StopSaveMouseMotion(void){ if (HaveMouseMotion) { (void) MyMoveMouse(CurMouseH, CurMouseV); HaveMouseMotion = falseblnr; }}#endif LOCALVAR blnr MyMouseCaptured = falseblnr; LOCALPROC MyMouseCaptureSet(blnr v){ if (v != MyMouseCaptured) { if (v) { (void) SetCapture(MainWnd); } else { (void) ReleaseCapture(); } MyMouseCaptured = v;Lines 1–500 of 6216. Load more
/* OSGLUWIN.c Copyright (C) 2009 Philip Cummins, Weston Pawlowski, Bradford L. Barrett, Paul C. Pratt, Fabio Concas You can redistribute this file and/or modify it under the terms of version 2 of the GNU General Public License as published by the Free Software Foundation. You should have received a copy of the license along with this file; see the file COPYING. This file is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the license for more details. */ /* Operating System GLUe for microsoft WINdows All operating system dependent code for the Microsoft Windows platform should go here. This code is descended from Weston Pawlowski's Windows port of vMac, by Philip Cummins. Adapted by Fabio Concas to run on Pocket PC 2003 devices. The main entry point '_tWinMain' is at the end of this file. */ #include "CNFGRAPI.h" #include "SYSDEPNS.h" #include "ENDIANAC.h" #include "MYOSGLUE.h" /* --- adapting to API/ABI version differences --- */ #ifdef UNICODE #define MyUseUni 1 #else #define MyUseUni 0 #endif #ifdef _WIN32_WCE #define UseWinCE 1 #else #define UseWinCE 0 #endif #define My_CSIDL_APPDATA 0x001a typedef BOOL (WINAPI *SHGetSpecialFolderPathProcPtr) ( HWND hwndOwner, LPTSTR lpszPath, int nFolder, BOOL fCreate ); LOCALVAR SHGetSpecialFolderPathProcPtr MySHGetSpecialFolderPath = NULL; LOCALVAR blnr DidSHGetSpecialFolderPath = falseblnr; LOCALFUNC blnr HaveMySHGetSpecialFolderPath(void) { if (! DidSHGetSpecialFolderPath) { HMODULE hLibModule = LoadLibrary(TEXT("shell32.dll")); if (NULL != hLibModule) { MySHGetSpecialFolderPath = (SHGetSpecialFolderPathProcPtr) GetProcAddress(hLibModule, #if MyUseUni TEXT("SHGetSpecialFolderPathW") #else TEXT("SHGetSpecialFolderPathA") #endif ); /* FreeLibrary(hLibModule); */ } DidSHGetSpecialFolderPath = trueblnr; } return (MySHGetSpecialFolderPath != NULL); } /* --- end of adapting to API/ABI version differences --- */ #include "STRCONST.h" #if MyUseUni #define NeedCell2UnicodeMap 1 #else #define NeedCell2WinAsciiMap 1 #endif #include "INTLCHAR.h" LOCALPROC NativeStrFromCStr(LPTSTR r, char *s, blnr AddEllipsis) { ui3b ps[ClStrMaxLength]; int i; int L; ClStrFromSubstCStr(&L, ps, s); for (i = 0; i < L; ++i) { r[i] = (TCHAR) #if MyUseUni Cell2UnicodeMap[ps[i]]; #else Cell2WinAsciiMap[ps[i]]; #endif } if (AddEllipsis) { #if MyUseUni r[L] = 0x2026; ++L; #else r[L] = '.'; ++L; r[L] = '.'; ++L; r[L] = '.'; ++L; #endif } r[L] = 0; } LOCALFUNC LPTSTR FindLastTerm(LPTSTR s, TCHAR delim) { TCHAR c; LPTSTR p0 = s; LPTSTR p = (LPTSTR)nullpr; while ((c = *p0++) != (TCHAR)('\0')) { if (c == delim) { p = p0; } } return p; } LOCALVAR HINSTANCE AppInstance; LOCALFUNC blnr GetAppDir(LPTSTR pathName) /* be sure at least _MAX_PATH long! */ { if (GetModuleFileName(AppInstance, pathName, _MAX_PATH) == 0) { /* MacMsg("error", "GetModuleFileName failed", falseblnr); */ } else { LPTSTR p = FindLastTerm(pathName, (TCHAR)('\\')); if (p == nullpr) { /* MacMsg("error", "strrchr failed", falseblnr); */ } else { *--p = (TCHAR)('\0'); return trueblnr; } } return falseblnr; } /* --- sending debugging info to file --- */ #if dbglog_HAVE LOCALVAR HANDLE dbglog_File = INVALID_HANDLE_VALUE; LOCALFUNC blnr dbglog_open0(void) { TCHAR pathName[_MAX_PATH]; TCHAR Child0[] = TEXT("\\dbglog.txt"); size_t newlen; if (GetAppDir(pathName)) { newlen = _tcslen(pathName) + _tcslen(Child0); if (newlen + 1 < _MAX_PATH) { _tcscat(pathName, Child0); dbglog_File = CreateFile( pathName, /* pointer to name of the file */ GENERIC_READ + GENERIC_WRITE, /* access (read-write) mode */ 0, /* share mode */ NULL, /* pointer to security descriptor */ OPEN_ALWAYS, /* how to create */ FILE_ATTRIBUTE_NORMAL, /* file attributes */ NULL /* handle to file with attributes to copy */ ); if (INVALID_HANDLE_VALUE == dbglog_File) { /* report error (how?) */ } else if (SetFilePointer( dbglog_File, /* handle of file */ 0, /* number of bytes to move file pointer */ nullpr, /* address of high-order word of distance to move */ FILE_BEGIN /* how to move */ ) != 0) { /* report error (how?) */ } } } return (INVALID_HANDLE_VALUE != dbglog_File); } LOCALPROC dbglog_write0(char *s, uimr L) { DWORD BytesWritten; if (INVALID_HANDLE_VALUE != dbglog_File) { if (! WriteFile(dbglog_File, /* handle of file to read */ (LPVOID)s, /* address of buffer that receives data */ (DWORD)L, /* number of bytes to read */ &BytesWritten, /* address of number of bytes read */ nullpr) /* address of structure for data */ || ((ui5b)BytesWritten != L)) { /* report error (how?) */ } } } LOCALPROC dbglog_close0(void) { if (INVALID_HANDLE_VALUE != dbglog_File) { if (! SetEndOfFile(dbglog_File)) { /* report error (how?) */ } (void) CloseHandle(dbglog_File); dbglog_File = INVALID_HANDLE_VALUE; } } #endif #include "COMOSGLU.h" #ifndef InstallFileIcons #define InstallFileIcons 0 #endif /* Resource Ids */ #define IDI_VMAC 256 #if InstallFileIcons #define IDI_ROM 257 #define IDI_DISK 258 #endif /* --- some simple utilities --- */ #define TestBit(i, p) (((unsigned long)(i) & PowOf2(p)) != 0) GLOBALOSGLUPROC MyMoveBytes(anyp srcPtr, anyp destPtr, si5b byteCount) { /* must work even if blocks overlap in memory */ (void) memcpy((char *)destPtr, (char *)srcPtr, byteCount); } /* --- Parameter buffers --- */ #if IncludePbufs LOCALVAR HGLOBAL PbufDat[NumPbufs]; #endif #if IncludePbufs LOCALFUNC tMacErr PbufNewFromHandle(HGLOBAL h, ui5b count, tPbuf *r) { tPbuf i; tMacErr err; if (! FirstFreePbuf(&i)) { (void) GlobalFree(h); err = mnvm_miscErr; } else { *r = i; PbufDat[i] = h; PbufNewNotify(i, count); err = mnvm_noErr; } return err; } #endif #if IncludePbufs GLOBALOSGLUFUNC tMacErr PbufNew(ui5b count, tPbuf *r) { HGLOBAL h; tMacErr err = mnvm_miscErr; h = GlobalAlloc(GMEM_DDESHARE | GMEM_ZEROINIT, count); if (h != NULL) { /* need to clear h */ err = PbufNewFromHandle(h, count, r); } return err; } #endif #if IncludePbufs GLOBALOSGLUPROC PbufDispose(tPbuf i) { (void) GlobalFree(PbufDat[i]); PbufDisposeNotify(i); } #endif #if IncludePbufs LOCALPROC UnInitPbufs(void) { tPbuf i; for (i = 0; i < NumPbufs; ++i) { if (PbufIsAllocated(i)) { PbufDispose(i); } } } #endif #if IncludePbufs #define PbufHaveLock 1 #endif #if IncludePbufs LOCALFUNC ui3p PbufLock(tPbuf i) { HGLOBAL h = PbufDat[i]; return (ui3p)GlobalLock(h); } #endif #if IncludePbufs LOCALPROC PbufUnlock(tPbuf i) { (void) GlobalUnlock(PbufDat[i]); } #endif #if IncludePbufs GLOBALOSGLUPROC PbufTransfer(ui3p Buffer, tPbuf i, ui5r offset, ui5r count, blnr IsWrite) { HGLOBAL h = PbufDat[i]; ui3p p0 = GlobalLock(h); if (p0 != NULL) { void *p = p0 + offset; if (IsWrite) { (void) memcpy(p, Buffer, count); } else { (void) memcpy(Buffer, p, count); } } (void) GlobalUnlock(h); } #endif /* --- control mode and internationalization --- */ #include "CONTROLM.h" /* --- main window info --- */ LOCALVAR HWND MainWnd = NULL; LOCALVAR int WndX; LOCALVAR int WndY; #if UseWinCE LOCALVAR short oldOrientation; LOCALVAR unsigned long oldDisplayOrientation; #endif #if VarFullScreen LOCALVAR blnr UseFullScreen = (WantInitFullScreen != 0); #endif #if EnableMagnify LOCALVAR blnr UseMagnify = (WantInitMagnify != 0); #endif #if MayFullScreen LOCALVAR short hOffset; LOCALVAR short vOffset; #endif /* cursor hiding */ LOCALVAR blnr HaveCursorHidden = falseblnr; LOCALVAR blnr WantCursorHidden = falseblnr; LOCALPROC ForceShowCursor(void) { if (HaveCursorHidden) { HaveCursorHidden = falseblnr; (void) ShowCursor(TRUE); SetCursor(LoadCursor(NULL, IDC_ARROW)); } } /* cursor moving */ LOCALFUNC blnr MyMoveMouse(si4b h, si4b v) { POINT NewMousePos; ui5b difftime; blnr IsOk; DWORD StartTime = GetTickCount(); LONG x = h; LONG y = v; #if VarFullScreen if (UseFullScreen) #endif #if MayFullScreen { x -= ViewHStart; y -= ViewVStart; } #endif #if EnableMagnify if (UseMagnify) { x *= MyWindowScale; y *= MyWindowScale; } #endif #if VarFullScreen if (UseFullScreen) #endif #if MayFullScreen { x += hOffset; y += vOffset; } #endif x += WndX; y += WndY; do { (void) SetCursorPos(x, y); if (! GetCursorPos(&NewMousePos)) { IsOk = falseblnr; } else { IsOk = (x == NewMousePos.x) && (y == NewMousePos.y); } difftime = (ui5b)(GetTickCount() - StartTime); } while ((! IsOk) && (difftime < 100)); return IsOk; } #if EnableFSMouseMotion LOCALPROC StartSaveMouseMotion(void) { if (! HaveMouseMotion) { if (MyMoveMouse(ViewHStart + (ViewHSize / 2), ViewVStart + (ViewVSize / 2))) { SavedMouseH = ViewHStart + (ViewHSize / 2); SavedMouseV = ViewVStart + (ViewVSize / 2); HaveMouseMotion = trueblnr; } } } #endif #if EnableFSMouseMotion LOCALPROC StopSaveMouseMotion(void) { if (HaveMouseMotion) { (void) MyMoveMouse(CurMouseH, CurMouseV); HaveMouseMotion = falseblnr; } } #endif LOCALVAR blnr MyMouseCaptured = falseblnr; LOCALPROC MyMouseCaptureSet(blnr v) { if (v != MyMouseCaptured) { if (v) { (void) SetCapture(MainWnd); } else { (void) ReleaseCapture(); } MyMouseCaptured = v;