Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
clehner committed Jul 24, 2014
0 parents commit e188eef
Show file tree
Hide file tree
Showing 14 changed files with 36 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Browsy
Browsy.NJ
1 change: 1 addition & 0 deletions Browsy.make
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# File: Browsy.make# Target: Browsy# Created: Saturday, July 7, 2012 01:10:12 AMMAKEFILE = Browsy.make¥MondoBuild¥ = {MAKEFILE} # Make blank to avoid rebuilds when makefile is modifiedSrcDir = :src:ObjDir = :build:Includes = ¶ -i :src: ¶ -i :include:Sym-68K = -sym offCOptions = {Includes} {Sym-68K} -model near -includes unix### Source Files ###SrcFiles = ¶ "{SrcDir}Browsy.r" ¶ "{SrcDir}main.c" ¶ "{SrcDir}menus.c" ¶ "{SrcDir}window.c" ¶ "{SrcDir}utils.c" ¶ "{SrcDir}uri.c"### Object Files ###ObjFiles-68K = ¶ "{ObjDir}main.c.o" ¶ "{ObjDir}menus.c.o" ¶ "{ObjDir}window.c.o" ¶ "{ObjDir}utils.c.o" ¶ "{ObjDir}uri.c.o"### Libraries ###LibFiles-68K = "{Libraries}MathLib.o" ¶ "{CLibraries}StdCLib.o" ¶ "{Libraries}MacRuntime.o" ¶ "{Libraries}IntEnv.o" ¶ "{Libraries}ToolLibs.o" ¶ "{Libraries}Interface.o" ¶ #"{SharedLibraries}MenusLib" ¶ :lib:tidy.o### Default Rules ###.c.o Ä .c {¥MondoBuild¥} {C} {depDir}{default}.c -o {targDir}{default}.c.o {COptions}### Build Rules ###Browsy ÄÄ {ObjFiles-68K} {LibFiles-68K} {¥MondoBuild¥} ILink ¶ -o {Targ} ¶ #-weaklib MenusLib ¶ {LibFiles-68K} ¶ {ObjFiles-68K} ¶ {Sym-68K} ¶ -mf -d ¶ -t 'APPL' ¶ -c 'WWW6' ¶ -model near ¶ -state rewrite ¶ -compact -pad 0 If "{Sym-68K}" =~ /-sym Å[nNuU]Å/ ILinkToSYM {Targ}.NJ -mf -sym 3.2 -c 'sade' EndBrowsy ÄÄ "{SrcDir}Browsy.rsrc" {¥MondoBuild¥} Rez "{SrcDir}Browsy.r" -o {Targ} {Includes} -append### Required Dependencies ###"{ObjDir}main.c.o" Ä "{SrcDir}main.c""{ObjDir}menus.c.o" Ä "{SrcDir}menus.c""{ObjDir}window.c.o" Ä "{SrcDir}window.c""{ObjDir}utils.c.o" Ä "{SrcDir}utils.c""{ObjDir}uri.c.o" Ä "{SrcDir}uri.c"### Optional Dependencies ###### Build this target to generate "include file" dependencies. ###Dependencies Ä $OutOfDate MakeDepend ¶ -append {MAKEFILE} ¶ -ignore "{CIncludes}" ¶ -ignore "{RIncludes}" ¶ -objdir "{ObjDir}" ¶ -objext .o ¶ {Includes} ¶ {SrcFiles}
Expand Down
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Browsy

A browser for System 6.

Currently this is mostly a UI concept, that can read local text files, manage
history, and allow the user to push buttons.

Build using MPW.

## TODO

- Implement scrolling
- Fetch pages over HTTP
- Parse HTML and maybe CSS
- Render pages
- Move build system to the [MPW Emulator](https://github.com/ksherlock/mpw)
(maybe)

Parsing and rendering code could be taken from another browser project such as netsurf or Dillo.

Network connectivity could be implemented using GUSI, which provides a UNIX-like
API, or by handling the Macintosh TCP stuff directly, which might allow for more
control over responsiveness.
1 change: 1 addition & 0 deletions page.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<!doctype html><html><head> <title>Cool Page</title></head><body>Outside paragraph<br>After Line break<br>It is <b>Bold</b>, <i>Italic</i>, <u>Underline</u><p>In paragraph</p><p>Second paragraph</p><p>Paragraph without closing tag<p>Another paragraph without closing tag<h1>First Heading</h1><p>Another paragraph</p><h2>Second Heading</h2><p>Meow paragraph</p><h3>Unordered list</h3><ul> <li>List item 1</li> <li>List item 2</li></ul><h3>Ordered list</h3><ol> <li>List item 1</li> <li>List item 2</li></ol><h3>Definition list</h3><dl> <dt>Term 1</dt> <dd>Definition 1</dd> <dt>Term 2</dt> <dd>Definition 3</dd></dl><h4>Fourth heading</h4><p><a href="index.html">Link to Home Page</a></p><h5>Fifth heading</h5><h2>Form</h2><form action="page2.html" method="get">Plain input: <input name="plain">Input text: <input type="text" name="text" value="meow" size="5"><br>Password: <input type="password" name="password"><br>Checkboxes:<br><input type="checkbox" name="checkbox1" value="meow"> Meow<br><input type="checkbox" name="checkbox2" value="pizza"> Pizza<br>Select ice cream flavor: <select name="icecream"> <option name="vanilla">Vanilla</option> <option name="chocolate" selected>Chocolate</option> <option>Cherry</option></select>Scoops:<br><input type="radio" name="scoops" value="1"> 1<br><input type="radio" name="scoops" value="2"> 2<br><input type="radio" name="scoops" value="3"> 3<br>Todo: <i>multi select</i><br>Textarea:<br><textarea>Type text here</textarea><br>Submit button: <input type="submit" value="Go"><br>Reset button: <input type="reset"></form><h2>HTML entities</h2><p>&amp;amp: "&amp;"<br>&amp;nbsp: "&nbsp;"<br><h2>More Stuff</h2><pre>Preformatted text</pre><address>Address</address>
Expand Down
1 change: 1 addition & 0 deletions src/Browsy.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
const short defaultALRT = 129;Boolean HasColorQD;Boolean Sys7;Boolean HasWNE;typedef struct HistoryItem { char *title; char *address; struct HistoryItem *prev; struct HistoryItem *next;} HistoryItem;// utilstypedef short SICN[16];typedef SICN **SICNHand;void PlotSICN(Rect *theRect, SICNHand theSICN, long theIndex);Boolean WNE(EventMask eventMask, EventRecord *theEvent, UInt32 sleep, RgnHandle mouseRgn);char *GetFilePathName(int vRefNum, Str255 fName);int GetFilePathVolRef(char *pathFileName);StringPtr GetFilePathFileName(char *pathFileName);char *url_encode(char *str);char *url_decode(char *str);char *url_sanitize(char *str);//void PlotSICN(Rect *theRect, Handle theSICN, long theIndex);void CtoP(char *cstr, unsigned char *pstr);
Expand Down
1 change: 1 addition & 0 deletions src/Browsy.r
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include "Browsy.rsrc";
Binary file added src/Browsy.rsrc.bin
Binary file not shown.
1 change: 1 addition & 0 deletions src/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include <MacWindows.h>#include <Events.h>#include <Dialogs.h>#include <ToolUtils.h>#include <Sound.h>#include <Traps.h>#include <AppleEvents.h>#include "Browsy.h"#include "window.h"void Initialize();void MainLoop();void CheckEnvironment();void DoIdle();void Terminate();void HandleEvent(EventRecord *event);void HandleUpdateEvt(EventRecord *event);void HandleKeyDown(EventRecord *event, WindowPtr topWin);void HandleMouseDown(EventRecord *event, WindowPtr topWin);void HandleActivate(EventRecord *event);void InitAppleEvents();//void HandleNullEvent(EventRecord *event);QDGlobals qd;void main() { Initialize(); // todo: open specified files // else open empty window PageWindowNavigateHome(NewPageWindow()); MainLoop(); Terminate();}void Initialize() { InitGraf(&qd.thePort); InitFonts(); InitWindows(); InitMenus(); TEInit(); InitDialogs(nil); InitCursor(); CheckEnvironment(); SetupMenus(); InitAppleEvents(); InitPageWindows();}void CheckEnvironment() { SysEnvRec sEnv; OSErr oe; oe = SysEnvirons(1,&sEnv); Sys7 = sEnv.systemVersion >= 0x0700; HasColorQD = sEnv.hasColorQD; HasWNE = (NGetTrapAddress(_WaitNextEvent, ToolTrap) != NGetTrapAddress(_Unimplemented, ToolTrap));}void MainLoop() { EventRecord event; Boolean ok; while (true) { ok = WNE(everyEvent, &event, 10L, nil); if (ok) { HandleEvent(&event); } else { // idle } DoIdle(); }}void DoIdle() { PageWindow *topPWin = GetPageWindow(FrontWindow()); if (topPWin) { PageWindowIdle(topPWin); }}void Terminate() { ExitToShell();}void HandleEvent(EventRecord *event) { WindowPtr topWin = FrontWindow(); switch (event->what) { case mouseDown: HandleMouseDown(event, topWin); break; case keyDown: case autoKey: HandleKeyDown(event, topWin); break; case updateEvt: HandleUpdateEvt(event); break; case diskEvt: //HandleDiskEvt(event); break; case activateEvt: HandleActivate(event); break; case mouseMovedMessage: //HandleMouseMoved(event); break; case mouseUp: //HandleMouseUp(event); break; case nullEvent: //HandleNullEvent(event); break; }}void HandleMouseDown(EventRecord *event, WindowPtr topWin) { WindowPtr win; PageWindow* pWin; short windowCode = FindWindow(event->where, &win); Rect oldPort; switch (windowCode) { case inMenuBar: //AdjustMenus(); HandleMenu(MenuSelect(event->where)); break; case inSysWindow: SystemClick(event, win); break; case inDrag: DragWindow(win, event->where, &qd.screenBits.bounds); break; case inZoomIn: case inZoomOut: if (TrackBox(win, event->where, windowCode)) { SetPort(win); oldPort = win->portRect; EraseRect(&win->portRect); ZoomWindow(win, windowCode, false); //AdjustScrollBars(win, true); //DrawPage(win); InvalRect(&win->portRect); pWin = GetPageWindow(win); if (pWin) { PageWindowResized(pWin, oldPort); } } break; case inGrow: { long size; Rect r = qd.screenBits.bounds; //GrafPtr oldPort = 0; //GetPort(&oldPort); r.top = 100; r.left = 150; r.bottom -= (GetMBarHeight()<<1); r.right -= 20; //SetRect(&r, MaxWindowWidth+SBarSize-1, 64, //MaxWindowWidth+SBarSize-1, gMaxHeight); if (win != topWin) { SelectWindow(win); } oldPort = win->portRect; size = GrowWindow(win, event->where, &r); SizeWindow(win, LoWord(size), HiWord(size), true); pWin = GetPageWindow(win); if (pWin) { PageWindowResized(pWin, oldPort); } //DrawPage(win); SetPort(win); InvalRect(&win->portRect); //SetPort(oldPort); } break; case inContent: if (win != topWin) { SelectWindow(win); // todo: draw } else { pWin = GetPageWindow(win); if (pWin) { PageWindowMouseDown(pWin, event->where, event->modifiers); } } break; case inGoAway: if (TrackGoAway(win, event->where)) { if (event->modifiers & optionKey) { CloseAll(); } else { pWin = GetPageWindow(win); ClosePageWindow(pWin); } } break; }}void HandleKeyDown(EventRecord *event, WindowPtr topWin) { PageWindow *pWin; char theChar = (char)(event->message & charCodeMask); if (event->modifiers & cmdKey) { HandleMenu(MenuKey(theChar)); } else { pWin = GetPageWindow(topWin); PageWindowKeyDown(pWin, theChar); }}void HandleUpdateEvt(EventRecord *event) { WindowPtr win = (WindowPtr)(event->message); PageWindow *pWin = GetPageWindow(win); BeginUpdate(win); if (pWin) { UpdatePageWindow(pWin); } EndUpdate(win);}void HandleActivate(EventRecord *event) { WindowPtr win = (WindowPtr) event->message; PageWindow *pWin = GetPageWindow(win); if (!pWin) return; if (event->modifiers & activeFlag) { PageWindowActivate(pWin); } else { PageWindowDeactivate(pWin); }}/*void HandleNullEvent(EventRecord *event) { WindowPtr win = (WindowPtr) event->message; PageWindow *pWin = GetPageWindow(win); if (!pWin) return; PageWindowNullEvent(pWin, event);}*/Boolean GotRequiredParams(AppleEvent *event) { DescType returnedType; Size actualSize; OSErr err; err = AEGetAttributePtr (event, keyMissedKeywordAttr, typeWildCard, &returnedType, NULL, 0, &actualSize); return err == errAEDescNotFound; } /* CAppleEvent::GotRequiredParams */void HandleOpenAE(AppleEvent *event, AppleEvent *reply, long refCon) {#pragma unused(reply, refCon) Handle docList = NULL; long i, itemCount; FSRef myFSRef; AEDescList theList; OSErr oe; //PageWindow *pwin = GetPageWindow(FrontWindow()); if ((oe = AEGetParamDesc( event, keyDirectObject, typeAEList, &theList)) != noErr) { //DebugStr("\pAEGetParamDesc"); return; } /*if (!GotRequiredParams(event)) { //DebugStr("\pGotRequiredParams"); return; }*/ if ((oe = AECountItems( &theList, &itemCount)) != noErr) { //DebugStr("\pAECountItems"); return; } for (i = 1; i <= itemCount; i++) { //oe = AEGetNthPtr( &theList, i, typeFSRef, &aeKeyword, &actualType, //(Ptr) &myFSRef, sizeof( FSRef), &actualSize); oe = AEGetNthPtr( &theList, i, typeFSRef, NULL, NULL, &myFSRef, sizeof(FSRef), NULL); if (oe == noErr) { NewPageWindow(); //OpenEditWindow(&myFSS); } } AEDisposeDesc(&theList); // event was handled successfully}pascal OSErr HandleAppleEvent(AppleEvent *event,AppleEvent *reply, long refCon) { #pragma unused(reply, refCon) DescType actualType; Size actualSize; DescType eventClass, eventID; OSErr oe; if ((oe = AEGetAttributePtr( (AppleEvent*) event, keyEventClassAttr, typeType, &actualType, (Ptr) &eventClass, sizeof(eventClass), &actualSize)) != noErr) return oe; if ((oe = AEGetAttributePtr( (AppleEvent*) event, keyEventIDAttr, typeType, &actualType, (Ptr) &eventID, sizeof(eventID), &actualSize)) != noErr) return oe; if (eventClass == kCoreEventClass) { switch (eventID) { case kAEOpenApplication: if (GotRequiredParams(event)) { } break; case kAEOpenDocuments: //HandleOpenEvent(event); break; case kAEPrintDocuments: break; case kAEQuitApplication: if (GotRequiredParams(event)) { Terminate(); } break; } } return noErr;}void InitAppleEvents() { if (Sys7) { AEInstallEventHandler(typeWildCard, typeWildCard, (AEEventHandlerUPP) NewAEEventHandlerProc((ProcPtr) HandleAppleEvent), 0, FALSE); AEInstallEventHandler(kCoreEventClass, kAEOpenDocuments, NewAEEventHandlerUPP(HandleOpenAE), 0, FALSE); //(EventHandlerProcPtr) AppleEventHandler, 0, FALSE); }}
Expand Down
1 change: 1 addition & 0 deletions src/menus.c
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include <Resources.h>#include <AppleEvents.h>#include <StandardFile.h>#include <ToolUtils.h>#include <Sound.h>#include <Menus.h>#include <Devices.h>#include <Events.h>#include <Scrap.h>#include "Browsy.h"#include "window.h"static void ShowAbout();const short defaultMenubar = 128;const short aboutDialog = 128;enum {appleMenu=128, fileMenu, editMenu, navigateMenu, historyMenu};enum { fileNewItem=1, fileOpenItem, fileOpenURLItem, fileCloseItem=5, fileSaveAsItem, filePageSetupItem=8, filePrintItem, fileQuitItem=11, editUndoItem=1, editCutItem=3, editCopyItem, editPasteItem, editClearItem, editSelectAllItem=8, navigateBackItem=1, navigateForwardItem, navigateHomeItem, navigateStopItem=5, navigateReloadItem};QDGlobals qd;void SetupMenus() { MenuHandle menu; Handle menubar = GetNewMBar(defaultMenubar); SetMenuBar(menubar); menu = GetMenuHandle(appleMenu); AppendResMenu(menu, 'DRVR'); DrawMenuBar();}void HandleMenu(long menuAction) { short menu = HiWord(menuAction); short item = LoWord(menuAction); MenuHandle mh = GetMenuHandle(menu); WindowPtr topWin = FrontWindow(); PageWindow* pWin = GetPageWindow(topWin); WindowPeek peek; Str255 name; GrafPtr savePort = 0; if (menuAction <= 0) { return; } switch(menu) { case appleMenu: if (item == 1) { ShowAbout(); } else { GetPort(&savePort); GetMenuItemText(mh, item, name); OpenDeskAcc(name); SetPort(savePort); } break; case fileMenu: switch(item) { case fileNewItem: pWin = NewPageWindow(); break; case fileQuitItem: // todo: wait for mactcp and name resolver Terminate(); break; case fileOpenItem: PageWindowOpenFile(pWin); break; case fileOpenURLItem: if (!pWin) { pWin = NewPageWindow(); } PageWindowFocusTE(pWin, pWin->addressBarTE); TESetSelect(0, (*pWin->addressBarTE)->teLength, pWin->addressBarTE); break; case fileCloseItem: peek = (WindowPeek)topWin; if (peek->windowKind < 0) { CloseDeskAcc(peek->windowKind); } else if (peek->goAwayFlag) { if (pWin) { ClosePageWindow(pWin); } } break; case fileSaveAsItem: PageWindowSaveAs(pWin); break; case filePageSetupItem: SysBeep(5); break; case filePrintItem: SysBeep(5); break; } break; case editMenu: { TEHandle te; Boolean inPage; // give to desk accessories first if (SystemEdit(item-1)) { break; } if (!pWin) { break; } te = pWin->focusTE; inPage = te == pWin->contentTE; switch (item) { case editUndoItem: // todo break; case editCutItem: if (te && !inPage) { TECut(te); if (!inPage) { ZeroScrap(); TEToScrap(); } } else { SysBeep(5); } break; case editCopyItem: if (te) { TECopy(te); if (!inPage) { ZeroScrap(); TEToScrap(); } } break; case editPasteItem: if (te && !inPage) { TEFromScrap(); TEPaste(te); } else { SysBeep(5); } break; case editClearItem: if (te && !inPage) { TEDelete(te); } else { SysBeep(5); } break; case editSelectAllItem: if (te) { TESetSelect(0, (*te)->teLength, te); } break; } break; } case navigateMenu: switch(item) { case navigateBackItem: //PageWindowNavigateBack(pWin); PageWindowNavigateHistory(pWin, -1); break; case navigateForwardItem: //PageWindowNavigateForward(pWin); PageWindowNavigateHistory(pWin, 1); break; case navigateHomeItem: PageWindowNavigateHome(pWin); break; case navigateStopItem: //PageWindowStop(pWin); break; case navigateReloadItem: PageWindowNavigateHistory(pWin, 0); //PageWindowReload(pWin); break; } break; } HiliteMenu(0);}// Browser6static pascal Boolean aboutFilter( DialogPtr theDialog, EventRecord *theEvent, short *itemHit){ if (theDialog) { switch (theEvent->what) { case mouseDown: if (itemHit) { *itemHit=1; } return 1; } } return 0;}static void ShowAbout() { DialogPtr dlg = GetNewDialog(aboutDialog, nil, (WindowPtr)-1L); short item; ModalDialog(aboutFilter, &item); DisposeDialog(dlg);}
Expand Down
Loading

0 comments on commit e188eef

Please sign in to comment.