From be412c5782814aae322957031a22befd735f8161 Mon Sep 17 00:00:00 2001 From: Marcio T Date: Mon, 29 Nov 2021 11:53:38 -0700 Subject: [PATCH] Integrated help viewer. --- mac-cpp-source/Iomega Tester.cpp | 1 + mac-cpp-source/macos/text_box.cpp | 1 + mac-cpp-source/macos/text_box.h | 1 + mac-cpp-source/tip/tip.cpp | 21 +- mac-cpp-source/tip/tip.h | 104 +++++----- mac-cpp-source/tip/tip_aspi.cpp | 12 +- mac-cpp-source/tip/tip_main.cpp | 312 ++++++++++++++++++++++-------- mac-cpp-source/utils/ctype.h | 1 + 8 files changed, 310 insertions(+), 143 deletions(-) create mode 100644 mac-cpp-source/macos/text_box.cpp create mode 100644 mac-cpp-source/macos/text_box.h create mode 100644 mac-cpp-source/utils/ctype.h diff --git a/mac-cpp-source/Iomega Tester.cpp b/mac-cpp-source/Iomega Tester.cpp index b9c926c..01b6799 100644 --- a/mac-cpp-source/Iomega Tester.cpp +++ b/mac-cpp-source/Iomega Tester.cpp @@ -27,6 +27,7 @@ void main() { SIOUXSetTitle("\pIomega Tester Beta (" __DATE__ ")"); + print_help(); do { diff --git a/mac-cpp-source/macos/text_box.cpp b/mac-cpp-source/macos/text_box.cpp new file mode 100644 index 0000000..e5587eb --- /dev/null +++ b/mac-cpp-source/macos/text_box.cpp @@ -0,0 +1 @@ +/************************************************************ text_box.cpp AUTHOR: Marcio Luis Teixeira CREATED: 3/16/95 LAST REVISION: 11/29/2021 (c) 1994-2021 by Marcio Luis Teixeira. All rights reserved. *************************************************************/ #include "text_box.h" #include #include TBHandle gCurTB; static pascal void TBScrollProc( ControlHandle cntl, short part ); static void TBGetRects(const Rect *r, Rect *viewRect, Rect *destRect, Rect *scrollRect); #define kSlowScrollSpeed 12 TBHandle TBNew( WindowPtr wind, const Rect *r ) { TBHandle tb; Rect destRect; Rect viewRect; Rect scrollRect; SetPort( wind ); TextFont( geneva ); tb = (TBHandle) NewHandle( sizeof( TBRec ) ); if( tb == NULL ) return NULL; HLock( (Handle) tb ); TBRec &my = **tb; my.frame = *r; TBGetRects(r, &viewRect, &destRect, &scrollRect); my.tbox = TEStylNew( &destRect, &viewRect ); if (my.tbox == NULL) { DisposeHandle( (Handle) tb ); return NULL; } my.scroll = NewControl( wind, &scrollRect, "\p", TRUE, 0, 0, 0, scrollBarProc, 1 ); if (my.scroll == NULL) { TEDispose( my.tbox ); DisposeHandle( (Handle) tb ); return NULL; } my.lastV = 0; my.maxV = 0; TEActivate( my.tbox ); HUnlock( (Handle) tb ); return tb; } void TBDispose( TBHandle tb ) { HLock( (Handle) tb ); TBRec &my = **tb; DisposeControl( my.scroll ); TEDispose( my.tbox ); DisposeHandle( (Handle) tb ); } void TBUpdate( TBHandle tb ) { HLock( (Handle) tb ); TBRec &my = **tb; TEUpdate( &(*my.tbox)->viewRect, my.tbox ); FrameRect( &my.frame ); HUnlock( (Handle) tb ); } void TBGetRects(const Rect *r, Rect *viewRect, Rect *destRect, Rect *scrollRect) { *viewRect = *r; viewRect->right -= 16; *destRect = *viewRect; InsetRect( viewRect, 1, 1 ); InsetRect( destRect, 4, 4 ); *scrollRect = *r; scrollRect->right--; scrollRect->left = scrollRect->right - 16; } void TBResize( TBHandle tb, const Rect *r ) { Rect destRect; Rect viewRect; Rect scrollRect; TBSetScroll( tb, 0 ); HLock( (Handle) tb ); TBRec &my = **tb; my.frame = *r; TBGetRects(r, &viewRect, &destRect, &scrollRect); (*my.tbox)->destRect = destRect; (*my.tbox)->viewRect = viewRect; TECalText( my.tbox ); MoveControl( my.scroll, scrollRect.left, scrollRect.top ); SizeControl( my.scroll, scrollRect.right - scrollRect.left, scrollRect.bottom - scrollRect.top ); my.maxV = TEGetHeight( 0, 32767, my.tbox ); my.maxV -= my.frame.bottom - my.frame.top - 30; SetCtlMax( my.scroll, my.maxV ); HUnlock( (Handle) tb ); } bool TBMouseDown( TBHandle tb, Point where, WindowPtr whichWindow ) { if (!PtInRect( where, &(*tb)->frame )) { return false; } HLock( (Handle) tb ); TBRec &my = **tb; ControlHandle whichCntl; short partCode = FindControl(where, whichWindow, &whichCntl); if (partCode) { if( partCode == inThumb ) partCode = TrackControl( whichCntl, where, (ControlActionUPP) -1L ); else { ControlActionUPP tbAction; tbAction = NewControlActionProc( TBScrollProc ); gCurTB = tb; partCode = TrackControl( whichCntl, where, tbAction ); DisposeRoutineDescriptor( tbAction ); } if (partCode == inThumb) { const short newV = GetCtlValue( my.scroll ); TBSetScroll( tb, newV ); } } HUnlock( (Handle) tb ); return true; } static pascal void TBScrollProc( ControlHandle cntl, short part ) { short newV; short max; short height; long lastTicks; TBRec &my = **gCurTB; newV = my.lastV; height = my.frame.bottom - my.frame.top; switch( part ) { case inDownButton: newV += kSlowScrollSpeed; break; case inUpButton: newV -= kSlowScrollSpeed; break; case inPageUp: newV -= height; break; case inPageDown: newV += height; break; } TBSetScroll( gCurTB, newV ); for( lastTicks = TickCount(); lastTicks == TickCount(); ); } void TBSetScroll( TBHandle tb, short scroll ) { TBRec &my = **tb; if( scroll < 0 ) scroll = 0; if( scroll > my.maxV ) scroll = my.maxV; SetCtlValue( my.scroll, scroll ); TEScroll( 0, my.lastV - scroll, my.tbox ); my.lastV = scroll; } OSErr TBReadSimpleText( TBHandle tb, const FSSpec *docSpec) { short fRefNum; TBSetScroll(tb, 0); HLock( (Handle) tb ); TBRec &my = **tb; // Load the text from the data fork OSErr err = FSpOpenDF(docSpec, fsRdPerm, &fRefNum); if(err != noErr) return err; long dataSize; GetEOF(fRefNum, &dataSize); if(dataSize > 31767) { dataSize = 31767; } Ptr data = NewPtr(dataSize); if(!data) { FSClose(fRefNum); return memFullErr; } err = FSRead(fRefNum, &dataSize, data); if(err != noErr) { FSClose(fRefNum); DisposePtr(data); return err; } // Set the text and clean up TESetText(data, dataSize, my.tbox); FSClose(fRefNum); DisposePtr(data); // Load the style information from the resource fork fRefNum = FSpOpenResFile(docSpec, fsRdPerm); if (fRefNum != -1) { short oldResFile = CurResFile(); UseResFile(fRefNum); Handle hStyle = Get1Resource('styl', 128); if (hStyle) { HNoPurge(hStyle); TEUseStyleScrap(0, dataSize, (StScrpHandle) hStyle, true, my.tbox); TECalText(my.tbox); ReleaseResource(hStyle); } UseResFile(oldResFile); CloseResFile(fRefNum); } // Adjust the scrollbar max my.lastV = 0; my.maxV = TEGetHeight( 0, 32767, my.tbox ); my.maxV -= my.frame.bottom - my.frame.top - 30; if( my.maxV < 0 ) my.maxV = 0; SetCtlMax( my.scroll, my.maxV ); HUnlock( (Handle) tb ); return noErr; } \ No newline at end of file diff --git a/mac-cpp-source/macos/text_box.h b/mac-cpp-source/macos/text_box.h new file mode 100644 index 0000000..09ae904 --- /dev/null +++ b/mac-cpp-source/macos/text_box.h @@ -0,0 +1 @@ +/************************************************************ Text Box.h AUTHOR: Marcio Luis Teixeira CREATED: 3/16/95 LAST REVISION: 11/29/2021 (c) 1994-2021 by Marcio Luis Teixeira. All rights reserved. *************************************************************/ #include "ctype.h" typedef struct { TEHandle tbox; Rect frame; ControlHandle scroll; short lastV; short maxV; } TBRec, *TBPtr, **TBHandle; TBHandle TBNew( WindowPtr wind, const Rect *r ); void TBDispose( TBHandle html ); void TBUpdate( TBHandle html ); void TBResize( TBHandle html, const Rect *r ); void TBSetScroll( TBHandle html, short scroll ); bool TBMouseDown( TBHandle html, Point where, WindowPtr whichWindow ); OSErr TBReadSimpleText( TBHandle tb, const FSSpec *docSpec); \ No newline at end of file diff --git a/mac-cpp-source/tip/tip.cpp b/mac-cpp-source/tip/tip.cpp index 29e7f90..cbf2846 100644 --- a/mac-cpp-source/tip/tip.cpp +++ b/mac-cpp-source/tip/tip.cpp @@ -28,6 +28,11 @@ void WinMain(int Device) { CurrentDevice = Device; // test for an Iomega device EnumerateIomegaDevices(CurrentDevice); + // Disable testing button when no drives present (added by mlt) + if (!DriveCount) { + EnableWindow(hTestButton, false); + SetRichEditText(szASPITrouble); + } // now startup the timer for real-time features StartApplicationTimer(); } @@ -37,7 +42,7 @@ void WinMain(int Device) { * * This is the system's main window procedure *******************************************************************************/ -void WndProc(long iMessage, long wParam) { +void WndProc(long iMessage, uint16_t wParam) { // ------------------------------------------------------------------------- // WM_PAINT // ------------------------------------------------------------------------- @@ -102,11 +107,15 @@ void WndProc(long iMessage, long wParam) { } BtnList tipBtns[] = { - {IDB_TEST, szPressToStart, 200, 301, 160, 24, true}, // Added by MLT - {IDB_BACK, szBack, 185-28, 301, 80, 24, false}, - {IDB_NEXT, szNext, 264-28, 301, 80, 24, false}, - {IDB_QUIT, szQuit, 367+35, 301, 45, 24, true}, - {0, 0, 0, 0, 0, 0, 0} + {IDB_BACK, szBack, 157, 301, 80, 24}, + {IDB_NEXT, szNext, 236, 301, 80, 24}, + {IDB_QUIT, szQuit, 402, 301, 45, 24}, + // For Mac TIP only + {IDB_TEST, szPressToStart, 157, 301, 150, 24}, + {IDB_EXPL, "Explain", 330, 301, 60, 24}, + {IDB_OKAY, "Okay", 380, 301, 65, 24}, + {IDB_READ, "Open in SimpleText...", 210, 301, 160, 24}, + {0, 0, 0, 0, 0, 0} }; /******************************************************************************* diff --git a/mac-cpp-source/tip/tip.h b/mac-cpp-source/tip/tip.h index 006b6df..68a57be 100644 --- a/mac-cpp-source/tip/tip.h +++ b/mac-cpp-source/tip/tip.h @@ -1,5 +1,4 @@ - -typedef Boolean bool; +#include "ctype.h" extern WindowPtr tipWindow; @@ -38,25 +37,27 @@ extern long SingleTransferLBA; // ----------------------- Macintosh Compatibility ----------------------- enum AlertTypes { - ERR_DLG, - YN_DLG + ERR_DLG, + YN_DLG }; enum { - BACK_COLOR = -1, - BLACK_COLOR = 0x000000, - LTGRAY_COLOR = 0xc0c0c0, - GRAY_COLOR = 0x808080, - WHITE_COLOR = 0xffffff, - BLUE_COLOR = 0x0000ff, - RED_COLOR = 0xff0000, - GREEN_COLOR = 0x00ff00, + BACK_COLOR = -1, + BLACK_COLOR = 0x000000, + LTGRAY_COLOR = 0xc0c0c0, + GRAY_COLOR = 0x808080, + WHITE_COLOR = 0xffffff, + BLUE_COLOR = 0x0000ff, + RED_COLOR = 0xff0000, + GREEN_COLOR = 0x00ff00, }; #define BDR_SUNKENOUTER 1 #define BF_RECT 1 #define WM_PAINT 1 #define WM_COMMAND 2 +#define SW_SHOW 1 +#define SW_HIDE 2 void SetColor(long color); void SetColor(long color, long monoColor); @@ -70,6 +71,7 @@ void TextOut(int x, int y, const char *str); void TextOutCentered(int x, int y, int w, int h, const char *str); void SetWindowText(int id, const char *str); void EnableWindow(int id, bool enabled); +void ShowWindow(int id, int state); void InvalidateRect(int id); void Rectangle(int left, int top, int right, int bottom); void DrawEdge(Rect *qrc, int edge, int grfFlags); @@ -77,45 +79,44 @@ void StartApplicationTimer(); void StopApplicationTimer(); void PostQuitMessage(); unsigned long GetSystemTime(); +bool PrepareDC(int which); -#define GetDC(h) {GrafPtr oldPort; \ - GetPort(&oldPort); \ - SetPort(tipWindow); \ - if(h == hTestMonitor) SetOrigin(-20, -10); \ - if(h == hMainWnd) SetOrigin(0, 40); +#define GetDC(h) {GrafPtr oldPort; \ + GetPort(&oldPort); \ + if(PrepareDC(h)) { -#define ReleaseDC(h) SetOrigin(0,0); \ - SetPort(oldPort);} +#define ReleaseDC(h) } SetOrigin(0,0); \ + SetPort(oldPort);} -// ------------------------------ Cartridge Status ------------------------------- +// ------------------------------ Cartridge Status ------------------------------- enum { - DISK_STATUS_UNKNOWN = 1, - DISK_AT_SPEED = 2, - DISK_SPINNING_UP = 3, - DISK_NOT_PRESENT = 4, - DISK_SPUN_DOWN = 5, - DISK_STALLED = 6, - DISK_Z_TRACK_FAILURE = 7, - DISK_PROTECTED = 8, - DISK_LOW_SPARES = 9, - DISK_TEST_UNDERWAY = 10, - DISK_TEST_FAILURE = 11, + DISK_STATUS_UNKNOWN = 1, + DISK_AT_SPEED = 2, + DISK_SPINNING_UP = 3, + DISK_NOT_PRESENT = 4, + DISK_SPUN_DOWN = 5, + DISK_STALLED = 6, + DISK_Z_TRACK_FAILURE = 7, + DISK_PROTECTED = 8, + DISK_LOW_SPARES = 9, + DISK_TEST_UNDERWAY = 10, + DISK_TEST_FAILURE = 11, - LAST_CART_STATUS = 11 + LAST_CART_STATUS = 11 }; // ---------------------------- Testing Phase Status ----------------------------- enum { - UNTESTED = 0, - READY_TO_TEST = 1, - TESTING_STARTUP = 2, - READING_DATA = 3, - WRITING_PATT = 4, - READING_PATT = 5, - WRITING_DATA = 6 + UNTESTED = 0, + READY_TO_TEST = 1, + TESTING_STARTUP = 2, + READING_DATA = 3, + WRITING_PATT = 4, + READING_PATT = 5, + WRITING_DATA = 6 }; /******************************************************************************* @@ -195,18 +196,31 @@ extern const char *szNext; extern const char *szQuit; enum { - hMainWnd, - hTestMonitor, - hTestButton, - hExitButton + hMainWnd, + hTestMonitor, + hTestButton, + hExitButton, + // Extras added by MLT + hExplainWnd }; #define IDB_BACK 0xFF00 #define IDB_NEXT 0xFF01 #define IDB_QUIT 0xFF02 #define IDB_TEST 0xFF03 +#define IDB_EXPL 0xFF04 +#define IDB_OKAY 0xFF05 +#define IDB_READ 0xFF06 -typedef struct {long id; const char *name; int x; int y; int w; int h; bool visible;} BtnList; +typedef struct { + int id; + const char *name; + int x; + int y; + int w; + int h; + ControlHandle hndl; +} BtnList; extern BtnList tipBtns[]; /******************************************************************************* @@ -233,7 +247,7 @@ void AllowProgramExit(); void ErrorSound(); void ProcessPendingMessages(); void WinMain(int Device); -void WndProc(long iMessage, long wParam); +void WndProc(long iMessage, uint16_t wParam); void TestMonitorWndProc(); void ApplicationTimerProc(); void TestButtonClicked(); diff --git a/mac-cpp-source/tip/tip_aspi.cpp b/mac-cpp-source/tip/tip_aspi.cpp index 042ffe0..34ac595 100644 --- a/mac-cpp-source/tip/tip_aspi.cpp +++ b/mac-cpp-source/tip/tip_aspi.cpp @@ -107,7 +107,7 @@ long Side_1_SparesCount; // ZIP has counts for both sides long Initial_Side_0_Spares; long Initial_Side_1_Spares; -long TestingPhase; // 0 = not testing, no data ... +long TestingPhase = 0; // 0 = not testing, no data ... long PercentComplete; long FirstLBASector; long NumberOfLBAs; @@ -523,12 +523,6 @@ void SetCartridgeStatusToEAX(long eax) { return; } LastCartridgeStatus = CartridgeStatus; - // Disable testing button when no drives present - if (!DriveCount) { - // MLT: Added this check. - SetRichEditText(szASPITrouble); - goto DisableActions; - } /**************************************************************************/ // Set the text of the "action initiate button" @@ -544,7 +538,7 @@ void SetCartridgeStatusToEAX(long eax) { esi = szPressToStop; break; case DISK_NOT_PRESENT: - //SetRichEditText(szNotRunning); + SetRichEditText(szNotRunning); goto DisableActions; case DISK_AT_SPEED: eax = GetSpareSectorCounts(true); // update the Cart Condition @@ -813,7 +807,7 @@ void TestTheDisk() { StopApplicationTimer(); PreventProgramExit(); - //SetRichEditText(szRunning); + SetRichEditText(szRunning); CartridgeStatus = DISK_TEST_UNDERWAY; TestingPhase = TESTING_STARTUP; // inhibit stopping now SetWindowText(hTestButton, szPressToStop); diff --git a/mac-cpp-source/tip/tip_main.cpp b/mac-cpp-source/tip/tip_main.cpp index 9e2a30a..14ca0e5 100644 --- a/mac-cpp-source/tip/tip_main.cpp +++ b/mac-cpp-source/tip/tip_main.cpp @@ -11,44 +11,63 @@ #include "pstring.h" #include "LaunchLib.h" #include "mac_vol.h" +#include "text_box.h" #include "tip.h" -WindowPtr tipWindow; +enum TipPage { + kTestingPage, + kExplainPage, +} page; -static int gDone; -static bool AllowColor; -static bool timerEnabled = true; -static ControlHandle testBtn = 0; -static ControlHandle exitBtn = 0; +static int gDone; +static bool allowColor; +static bool inited = false; +static bool timerEnabled = false; +static WindowPtr tipWindow; +static TBHandle richText; +static const char *textFileName; void NewTipWindow(); -void DestroyTipWindow(); +void DisposeTipWindow(); void DoEvent(EventRecord &event, RgnHandle *cursorRgn); void DoUpdate(WindowPtr window); void DoMouseDown(EventRecord &event); void DoMouseMove(EventRecord &event, RgnHandle *cursorRegion); void DoDiskEvent(EventRecord &event); +void SetPage(TipPage page); +ControlHandle FindControl(int id); +OSErr GetExplanationFSSpec(const char *name, FSSpec *docSpec); +void OpenExplanationInSimpleText(); + +#define SET_POINT(x,y) {y,x}; + +const Point mainWndOrigin = SET_POINT(0, 40); void run_tip(int id) { - WinMain(id); RgnHandle cursorRgn = NewRgn(); - SetRichEditText(szInstructions); NewTipWindow(); EnableWindow(hTestButton, false); + SetRichEditText(szInstructions); gDone = false; do { EventRecord event; if (WaitNextEvent(everyEvent, &event, GetCaretTime(), cursorRgn)) { DoEvent(event, &cursorRgn); + if(!inited && page == kTestingPage) { + printf("Starting tip\n"); + // Start TIP as soon as the user dismisses the intro screen + inited = true; + WinMain(id); + } } if(timerEnabled) { ApplicationTimerProc(); } } while (!gDone); - DestroyTipWindow(); + DisposeTipWindow(); DisposeRgn(cursorRgn); } @@ -57,56 +76,83 @@ void NewTipWindow() { SysEnvRec theWorld; error = SysEnvirons(1, &theWorld); - AllowColor = theWorld.hasColorQD; + allowColor = theWorld.hasColorQD; + + const int wndHeight = 336 - 35; + const int wndWidth = 467; Rect rect = qd.screenBits.bounds; rect.left = 8; rect.top = GetMBarHeight() + rect.left + 16; - rect.bottom = rect.top + 336 - 35; - rect.right = rect.left + 467; + rect.bottom = rect.top + wndHeight; + rect.right = rect.left + wndWidth; Str255 title; StrToPascal(title, szWindowTitle); - tipWindow = AllowColor ? + tipWindow = allowColor ? NewCWindow(NULL,&rect, title, true, 0, (WindowPtr)-1, true, 0) : NewWindow(NULL,&rect, title, true, 0, (WindowPtr)-1, true, 0); GetDC(hMainWnd); - if (AllowColor) { - SetColor(BACK_COLOR); - RGBColor bgColor; - GetForeColor(&bgColor); - RGBBackColor(&bgColor); - } TextSize(10); + // Create the controls + for(int i = 0; tipBtns[i].name; i++) { - if (!tipBtns[i].visible) continue; SetRect(&rect, tipBtns[i].x, - tipBtns[i].y, + tipBtns[i].y - mainWndOrigin.v, tipBtns[i].x + tipBtns[i].w, - tipBtns[i].y + tipBtns[i].h + tipBtns[i].y + tipBtns[i].h - mainWndOrigin.v ); - StrToPascal(title, tipBtns[i].name); - ControlHandle h = NewControl(tipWindow, &rect, title, true, 0, 0, 0, 0, tipBtns[i].id); - if(tipBtns[i].id == IDB_TEST) { - testBtn = h; - } - if(tipBtns[i].id == IDB_QUIT) { - exitBtn = h; - } + tipBtns[i].hndl = NewControl(tipWindow, &rect, title, true, 0, 0, 0, 0, tipBtns[i].id); } - ReleaseDC(hMainWnd); + + page = kExplainPage; + GetDC(hExplainWnd); + + // Create the text edit widget + SetRect(&rect, 15, 15, 447, 250); + richText = TBNew(tipWindow, &rect); + + ReleaseDC(hExplainWnd); + + SetPage(kTestingPage); } -void DestroyTipWindow() { +void DisposeTipWindow() { + TBDispose(richText); DisposeWindow(tipWindow); } +ControlHandle FindControl(int id) { + for(int i = 0; tipBtns[i].name; i++) { + if (tipBtns[i].id == id) + return tipBtns[i].hndl; + } + return 0; +} + +bool PrepareDC(int which) { + SetPort(tipWindow); + switch(which) { + case hExplainWnd: + if(page != kExplainPage) return false; + break; + case hTestMonitor: + if(page != kTestingPage) return false; + SetOrigin(-20, -10); + break; + case hMainWnd: + SetOrigin(mainWndOrigin.h, mainWndOrigin.v); + break; + } + return true; +} + void DoEvent(EventRecord &event, RgnHandle *cursorRgn) { if(!SIOUXHandleOneEvent(&event)) { // If SIOUX didn't handle the event, then handle it ourselves @@ -117,23 +163,31 @@ void DoEvent(EventRecord &event, RgnHandle *cursorRgn) { case osEvt: DoMouseMove(event, cursorRgn); break; } } - } void DoUpdate(WindowPtr window) { BeginUpdate(window); SetPort(window); - EraseRect(&window->portRect); + SetColor(BACK_COLOR); + PaintRect(&window->portRect); GetDC(hMainWnd); WndProc(WM_PAINT, 0); - DrawControls(window); ReleaseDC(hMainWnd); GetDC(hTestMonitor); TestMonitorWndProc(); ReleaseDC(hTestMonitor); + GetDC(hExplainWnd); + SetColor(BLACK_COLOR); + EraseRect(&(*richText)->frame); + TBUpdate(richText); + DrawEdge(&(*richText)->frame, BDR_SUNKENOUTER, BF_RECT); + ReleaseDC(hExplainWnd); + + UpdateControls(window, window->visRgn); + EndUpdate(window); } @@ -150,24 +204,34 @@ void DoMouseDown(EventRecord &event) { SelectWindow(thisWindow); } else if(thisWindow == tipWindow) { - long id = 0; Point mouse = event.where; - GetDC(hMainWnd); + GrafPtr oldPort; + GetPort(&oldPort); + SetPort(thisWindow); GlobalToLocal(&mouse); - if(FindControl(mouse, thisWindow, &thisControl) == inButton) { - if(TrackControl(thisControl, mouse, 0) == inButton) { - id = GetControlReference(thisControl); + const bool hitButton = (!TBMouseDown(richText, mouse, thisWindow)) && + (FindControl(mouse, thisWindow, &thisControl) == inButton) && + (TrackControl(thisControl, mouse, 0) == inButton); + SetPort(oldPort); + if(hitButton) { + int id = GetControlReference(thisControl); + switch(id) { + case IDB_OKAY: + SetPage(kTestingPage); + break; + case IDB_EXPL: + SetPage(kExplainPage); + break; + case IDB_READ: + OpenExplanationInSimpleText(); + break; + default: + WndProc(WM_COMMAND, id); + break; } } - ReleaseDC(hMainWnd); - if(id) { - WndProc(WM_COMMAND, id); - } } break; - case inDrag: - DragWindow(thisWindow, event.where, &(*GetGrayRgn())->rgnBBox); - break; case inGrow: //DoGrowWindow(thisWindow, event); break; @@ -222,6 +286,35 @@ void StrToPascal(Str255 pStr, const char *str) { strncpy((char*)pStr + 1, str, 255); } +void SetPage(TipPage newPage) { + if(page == newPage) return; + page = newPage; + switch(page) { + case kTestingPage: + ShowWindow(IDB_TEST, SW_SHOW); + ShowWindow(IDB_BACK, SW_HIDE); + ShowWindow(IDB_NEXT, SW_HIDE); + ShowWindow(IDB_EXPL, SW_SHOW); + ShowWindow(IDB_OKAY, SW_HIDE); + ShowWindow(IDB_QUIT, SW_SHOW); + ShowWindow(IDB_READ, SW_HIDE); + HideControl((*richText)->scroll); + break; + case kExplainPage: + ShowWindow(IDB_TEST, SW_HIDE); + ShowWindow(IDB_BACK, SW_HIDE); + ShowWindow(IDB_NEXT, SW_HIDE); + ShowWindow(IDB_EXPL, SW_HIDE); + ShowWindow(IDB_OKAY, SW_SHOW); + ShowWindow(IDB_QUIT, SW_HIDE); + ShowWindow(IDB_READ, SW_SHOW); + ShowControl((*richText)->scroll); + TBSetScroll(richText, 0); + break; + } + InvalidateRect(hMainWnd); +} + /******************************************************************************* * SHOW ALERT BOX *******************************************************************************/ @@ -241,6 +334,55 @@ int ShowAlert(AlertTypes type, const char* format, ...) { return 0; } +/******************************************************************************* + * GET EXPLANATION FSSPEC + * + * Returns the FSSpec for an explanation file + *******************************************************************************/ +OSErr GetExplanationFSSpec(const char *name, FSSpec *docSpec) { + Str255 docName; + StrToPascal(docName, name); + + Str255 pathName; + pstrcpy(pathName, "\p:tip-doc:"); + pstrcat(pathName, docName); + + OSErr err = FSMakeFSSpec(0, 0, pathName, docSpec); + if(err) { + ShowAlert(ERR_DLG, "Can't find the \"%s\" file. Make sure it is inside the \"tip-doc\" folder.", name); + } + return err; +} + +/******************************************************************************* + * OPEN EXPLANATION IN SIMPLE TEXT + * + * Opens the currently selected TIP explanation file using SimpleText + * + * This uses code from Thomas Tempelmann's C libraries + * + * http://www.tempel.org/macdev/index.html + *******************************************************************************/ +void OpenExplanationInSimpleText() { + FSSpec docSpec; + FSSpec appSpec; + + OSErr err = GetExplanationFSSpec(textFileName, &docSpec); + if(err != noErr) return; + + err = FindApplicationFromDocument(&docSpec, &appSpec); + if(err) { + ShowAlert(ERR_DLG, "Can't find an application to open \"%s\". Is \"SimpleText\" installed?", textFileName); + return; + } + + err = LaunchApplicationWithDocument(&appSpec, &docSpec, false); + if(err) { + ShowAlert(ERR_DLG, "Can't open \"%s\". If \"%#s\" is already running, please close it.", textFileName, appSpec.name); + return; + } +} + /******************************************************************************* * SET RICH EDIT TEXT * @@ -252,38 +394,28 @@ int ShowAlert(AlertTypes type, const char* format, ...) { *******************************************************************************/ void SetRichEditText(const char *name) { - static const char *lastName = 0; - if(name == lastName) return; - lastName = name; + short fRefNum = 0; - if(ShowAlert(YN_DLG, "Would you like to read the document \"%s\" now?", name) == 2) { - return; - } - Str255 docName; - StrToPascal(docName, name); + // Don't reload a file that is already loaded - Str255 pathName; - pstrcpy(pathName, "\p:tip-doc:"); - pstrcat(pathName, docName); + if(textFileName == name) return; + textFileName = name; + + printf("Loading explanation file \"%s\"\n", name); + + // Get the specification for the explanation file FSSpec docSpec; - FSSpec appSpec; - OSErr err = FSMakeFSSpec(0, 0, pathName, &docSpec); - if(err) { - ShowAlert(ERR_DLG, "Can't find the \"%s\" file. Make sure it is inside the \"tip-doc\" folder.", name); - return; + OSErr err = GetExplanationFSSpec(textFileName, &docSpec); + if(err != noErr) return; + + // Load the text from the data fork + + if (name != szRunning && name != szNotRunning) { + SetPage(kExplainPage); } - err = FindApplicationFromDocument(&docSpec, &appSpec); - if(err) { - ShowAlert(ERR_DLG, "Can't find an application to open \"%s\". Is \"SimpleText\" installed?", name); - return; - } - err = LaunchApplicationWithDocument(&appSpec, &docSpec, false); - if(err) { - ShowAlert(ERR_DLG, "Can't open \"%s\". If \"%#s\" is already running, please close it.", name, appSpec.name); - return; - } + TBReadSimpleText(richText, &docSpec); } /******************************************************************************* @@ -291,7 +423,7 @@ void SetRichEditText(const char *name) { *******************************************************************************/ void SetColor(long color) { - if (AllowColor) { + if (allowColor) { if(color == BACK_COLOR) color = LTGRAY_COLOR; // Use colors when available RGBColor rgbColor; @@ -325,7 +457,7 @@ void SetColor(long color) { } void SetColor(long color, long monoColor) { - if (AllowColor) { + if (allowColor) { SetColor(color); } else { SetColor(monoColor); @@ -342,7 +474,7 @@ void DrawLed(int x, int y, long color) { // Draw the LED SetColor(color); PaintOval(&ledRect); - if (AllowColor) { + if (allowColor) { // Draw a recessed outline SetColor(BLACK_COLOR); FrameOval(&ledRect); @@ -372,7 +504,7 @@ void DrawLed(int x, int y, long color) { *******************************************************************************/ void DrawEdge(Rect *qrc, int edge, int grfFlags) { - if(edge == BDR_SUNKENOUTER && AllowColor) { + if(edge == BDR_SUNKENOUTER && allowColor) { // Draw a sunken rectangle SetColor(GRAY_COLOR); MoveTo(qrc->left,qrc->bottom-1); @@ -453,9 +585,10 @@ unsigned long GetSystemTime() { void SetWindowText(int id, const char *str) { Str255 pStr; StrToPascal(pStr, str); - if(testBtn && id == hTestButton) { + ControlHandle hCntl = FindControl(id); + if(hCntl) { GetDC(hMainWnd); - SetCTitle(testBtn, pStr); + SetCTitle(hCntl, pStr); ReleaseDC(hMainWnd); } } @@ -464,9 +597,7 @@ void SetWindowText(int id, const char *str) { * ENABLE WINDOW *******************************************************************************/ void EnableWindow(int id, bool enabled) { - ControlHandle hCntl = 0; - if(id == hTestButton) hCntl = testBtn; - if(id == hExitButton) hCntl = exitBtn; + ControlHandle hCntl = FindControl(id); if(hCntl) { GetDC(hMainWnd); HiliteControl(hCntl, enabled ? 0 : 255); @@ -474,6 +605,21 @@ void EnableWindow(int id, bool enabled) { } } +/******************************************************************************* + * SHOW WINDOW + *******************************************************************************/ +void ShowWindow(int id, int state) { + ControlHandle hCntl = FindControl(id); + if(hCntl) { + GetDC(hMainWnd); + if(state == SW_SHOW) + ShowControl(hCntl); + else + HideControl(hCntl); + ReleaseDC(hMainWnd); + } +} + /******************************************************************************* * INVALIDATE RECT *******************************************************************************/ diff --git a/mac-cpp-source/utils/ctype.h b/mac-cpp-source/utils/ctype.h new file mode 100644 index 0000000..bb1578a --- /dev/null +++ b/mac-cpp-source/utils/ctype.h @@ -0,0 +1 @@ +typedef Boolean bool; typedef unsigned short uint16_t; \ No newline at end of file