home *** CD-ROM | disk | FTP | other *** search
Text File | 1997-06-28 | 8.1 KB | 320 lines | [TEXT/CWIE] |
- // --------------------------------------------------------------------------------------
- // HackWindows.c
- //
- // Written by Don Arbow and Marc A. Raiser, EveryDay Objects, Inc.
- // in one day - June 26, 1997
- // --------------------------------------------------------------------------------------
-
- #include "HackWindows.h"
-
- #ifndef __LISTS__
- #include <Lists.h>
- #endif
-
- #ifndef __TOOLUTILS__
- #include <ToolUtils.h>
- #endif
-
- #include <Events.h>
-
- #include "FetchParseURL.h"
- /* === Constants === */
-
- #define WIND_Hack 128
-
- static WindowRef gWin;
-
-
- /* === Types === */
-
- typedef struct HackInfoRecord {
- ListHandle listBox;
- } HackInfoRecord, **HackInfoHandle;
-
-
- /* === Global Variables === */
-
- /* Bounds of the List box that displays the names of the dragged items */
- Rect listView = {10, 20, 170, 470};
-
-
- /* === Macros === */
-
- /* Extracts the ListHandle from a HackInfoHandle that's stored */
- /* in the refCon of a WindowRecord */
- #define GetListBox(w) (**((HackInfoHandle) GetWRefCon(w))).listBox
-
-
- /* ------------------------------------------------------------------------ */
- /* AddListItem */
- /* ------------------------------------------------------------------------ */
- /*
- * Adds a url item to the List box in a Window
- */
-
- OSErr AddListItem(Str255 url)
- {
- OSErr err = nil;
- ListHandle list = GetListBox(gWin);
-
- Cell newCell = { 0, 0 };
-
- /* Add file name to the beginning of the List box */
- SetPort(gWin);
-
- // if (!LSearch(url + 1, url[0], nil, &newCell, list)) {
- if (url[0]) {
- LSetDrawingMode(false, list);
- LAddRow(1, 0, list);
- LSetCell(url + 1, url[0], newCell, list);
- LSetDrawingMode(true, list);
- InvalRect(&listView);
- }
-
- return err;
- }
-
- /* ------------------------------------------------------------------------ */
- /* CreateWindow */
- /* ------------------------------------------------------------------------ */
- /*
- * Make a new window that contains a List box of url items
- */
-
- void CreateWindow(Str255 fileName)
- {
- WindowPtr theWindow;
-
- ListHandle theListBox;
- Rect listBounds = {0, 0, 0, 1};
- Point cellSize = {0, 0};
-
- HackInfoHandle hackInfo;
- RgnHandle receiveRgn;
- Rect receiveRect = listView;
-
- /* Make Toolbox window and store a HackInfoHandle */
- /* in the window's refCon */
-
- theWindow = GetNewWindow(WIND_Hack, nil, (WindowPtr) -1);
- hackInfo = (HackInfoHandle) NewHandle(sizeof(HackInfoRecord));
- SetWRefCon(theWindow, (long) hackInfo);
-
- SetWTitle(theWindow, fileName);
-
- /* Create a List Manager list and store it in */
- /* the HackInfoHandle */
-
- theListBox = LNew(&listView, &listBounds, cellSize, 0, theWindow,
- true, false, false, true);
- (**hackInfo).listBox = theListBox;
-
- /* Create a region coinciding with the List box */
-
- receiveRgn = NewRgn();
- RectRgn(receiveRgn, &receiveRect);
-
- /* Load information needed by our DragManagerModule. */
- /* We specify that our window can accept items of */
- /* flavorTypeHFS (file or folder) within a region */
- /* that coincides with the List box. And that our */
- /* ReceiveHFSDrag function should be called for each */
- /* item dragged and dropped into that region. */
-
- ShowWindow(theWindow);
-
- gWin = theWindow;
- }
-
- /* ------------------------------------------------------------------------ */
- /* DestroyWindow */
- /* ------------------------------------------------------------------------ */
- /*
- * Dispose of a Window
- *
- * We need to clean up our DragInfo, dispose of the List box, and
- * finally dispose of the Toolbox window.
- */
-
- void DestroyWindow(WindowPtr inWindow)
- {
- LDispose(GetListBox(inWindow));
- DisposeHandle((Handle) GetWRefCon(inWindow));
- DisposeWindow(inWindow);
- }
-
- /* ------------------------------------------------------------------------ */
- /* UpdateHackWindow */
- /* ------------------------------------------------------------------------ */
-
- void UpdateHackWindow(WindowPtr inWindow)
- {
- Rect boxFrame;
-
- GrafPtr savePort;
- GetPort(&savePort);
- SetPort(inWindow);
- BeginUpdate(inWindow);
-
- EraseRect(&inWindow->portRect);
-
- /* Draw List Box */
- LUpdate(inWindow->visRgn, GetListBox(inWindow));
-
- /* Draw Frame around List Box */
- boxFrame = listView;
- InsetRect(&boxFrame, -1, -1);
- FrameRect(&boxFrame);
-
- /* Draw caption under List Box */
- MoveTo(boxFrame.left + 30, boxFrame.bottom + 16);
- DrawString("\pMarc and Don's wonderful Subwoofer hack!!!!");
-
- EndUpdate(inWindow);
- SetPort(savePort);
- }
-
-
- /* ------------------------------------------------------------------------ */
- /* DoActivateWindow */
- /* ------------------------------------------------------------------------ */
-
- void ActivateHackWindow(WindowPtr inWindow)
- {
- SetPort(inWindow);
- LActivate(true, GetListBox(inWindow));
- }
-
-
- /* ------------------------------------------------------------------------ */
- /* DoDeactivateWindow */
- /* ------------------------------------------------------------------------ */
-
- void DeactivateHackWindow(WindowPtr inWindow)
- {
- SetPort(inWindow);
- LActivate(false, GetListBox(inWindow));
- }
-
-
- /* ------------------------------------------------------------------------ */
- /* DoDragWindow */
- /* ------------------------------------------------------------------------ */
-
- void DragHackWindow(EventRecord *inEvent, WindowPtr inWindow)
- {
- Rect screenRect = (**GetGrayRgn()).rgnBBox;
- InsetRect(&screenRect, 4, 4);
- DragWindow(inWindow, inEvent->where, &screenRect);
- }
-
-
- /* ------------------------------------------------------------------------ */
- /* DoGrowWindow */
- /* ------------------------------------------------------------------------ */
-
- void GrowHackWindow(EventRecord *inEvent, WindowPtr inWindow)
- {
- Rect sizeRect;
- long newSize;
-
- sizeRect.top = 100;
- sizeRect.left = 100;
- sizeRect.bottom = ((**GetGrayRgn()).rgnBBox).bottom;
- sizeRect.right = sizeRect.left + 300;
- newSize = GrowWindow(inWindow, inEvent->where, &sizeRect);
-
- if (newSize != 0) {
- SizeWindow(inWindow, LoWord(newSize), HiWord(newSize), true);
- AdjustWindowSize(inWindow);
- }
- }
-
-
- /* ------------------------------------------------------------------------ */
- /* DoZoomWindow */
- /* ------------------------------------------------------------------------ */
-
- void ZoomHackWindow(WindowPtr inWindow, short inDirection)
- {
- SetPort(inWindow);
- EraseRect(&inWindow->portRect);
- ZoomWindow(inWindow, inDirection, true);
- AdjustWindowSize(inWindow);
- }
-
-
- /* ------------------------------------------------------------------------ */
- /* DoClickWindow */
- /* ------------------------------------------------------------------------ */
-
- void ClickHackWindow(EventRecord *inEvent, WindowPtr inWindow)
- {
- Point mouseLocation;
- Cell cell = { 0, 0 };
- ListHandle list;
- Str255 url;
- short urlLen = 255;
- StandardFileReply sfFile;
- OSErr err = noErr;
-
- SetPort(inWindow);
-
- mouseLocation = inEvent->where;
- GlobalToLocal(&mouseLocation);
- // new url;
- list = GetListBox(inWindow);
-
- if (LClick(mouseLocation, inEvent->modifiers, list)) {
- // get the data;
-
- if (LGetSelect(true, &cell, list)) {
-
- LGetCell(url + 1, &urlLen, cell, list);
- url[0] = urlLen;
- }
-
- if (inEvent->modifiers & optionKey) {
- StandardPutFile("\pSave this link as a file named:", "\pindex.html", &sfFile);
- if (sfFile.sfGood) {
- p2cstr(url);
- err = URLDownload((char*)url, &sfFile.sfFile, kURLDisplayProgressFlag + kURLDisplayAuthFlag);
- if (err != noErr) {
- ShowError(err);
- }
- }
- } else {
- QueryURL(url);
- SetWTitle(inWindow, url);
- }
- }
- }
-
- void ClearList(void) {
-
- ListHandle list;
-
- list = GetListBox(gWin);
- LSetDrawingMode(false, list);
- LDelRow(0, 0, list);
- LSetDrawingMode(true, list);
- }
-
- /* ------------------------------------------------------------------------ */
- /* AdjustWindowSize */
- /* ------------------------------------------------------------------------ */
-
- void AdjustWindowSize(WindowPtr inWindow)
- {
- SetPort(inWindow);
- InvalRect(&inWindow->portRect);
- }
-
-
- /* ------------------------------------------------------------------------ */
- /* DoKeyWindow */
- /* ------------------------------------------------------------------------ */
-
- void KeyHackWindow(EventRecord *inEvent, WindowPtr inWindow)
- {
- }