uuUndo/DSDialogs.c

1 line
20 KiB
C
Raw Normal View History

2015-02-06 08:56:41 +00:00
#include <Aliases.h> #include <Drag.h> #include <FragLoad.h> #include <GestaltEqu.h> #include <QDOffscreen.h> #include "DSGlobals.h" #include "DSDialogs.h" #include "DSUtilsASG.h" enum { kPrefsDLOG = 149, kPrefsExtensionText = 1, kPrefsCreatorTypeText, kPrefsIconText, kPrefsListUser, kPrefsNewButton, kPrefsEditButton, kPrefsDeleteButton, kPrefsExtensionText2, kPrefsExtensionEdit, kPrefsExtensionStatic, kPrefsCreatorText, kPrefsCreatorEdit, kPrefsCreatorStatic, kPrefsTypeText, kPrefsTypeEdit, kPrefsTypeStatic, kPrefsApplicationText, kPrefsApplicationStatic, kPrefsIconText2, kPrefsIconUser, kPrefsDragAndDropText, kPrefsExampleButton, kPrefsTrashMenu }; static void InitPrefsList(void); static void AllocateIconGWorld(void); static void SetUpForDragging(void); static void UpdateSelection(void); static void UpdateButtons(void); static pascal void ListUserItem(DialogPtr theDialog, short theItem); static pascal void IconUserItem(DialogPtr theDialog, short theItem); static OSErr FindIcon(OSType creator, OSType type); static void EraseGWorld(GWorldPtr theGWorld); static void StartEditing(void); static void StopEditing(void); static void SaveChanges(void); static void SaveResults(void); static void SetExampleType(OSType creator, OSType type); static pascal OSErr DragTracker(DragTrackingMessage message, WindowPtr theWindow, void *handlerRefCon, DragReference theDragRef); static pascal OSErr DragReceiver(WindowPtr theWindow, void *handlerRefCon, DragReference theDragRef); static Boolean IsValidDrag(DragReference theDragRef, HFSFlavor *theFile); static UserItemUPP gListUserItem = nil, gIconUserItem = nil; static DragTrackingHandlerUPP gDragTracker = nil; static DragReceiveHandlerUPP gDragReceiver = nil; static DialogPtr gPrefsDialog = nil; static ListHandle gPrefsList = nil; static GWorldPtr gTheGWorld = nil; static OSErr gIconType = kLargeIcon; static Rect gIconBounds = { 0, 0, 32, 32 }; static Boolean gEditing = false; static Str255 gApplicationName; static char gIconBuffer[1024]; void OpenUserDialog(short menuID, short menuItem) { if (gPrefsDialog) { SelectWindow(gPrefsDialog); return; } gPrefsDialog = GetNewDialog(kPrefsDLOG, nil, (WindowPtr)-1); if (gPrefsDialog) { SetWindowPosition(gPrefsDialog, (*gPrefs)->prefsLoc); ShowWindow(gPrefsDialog); InitPrefsList(); if (gPrefsList) { AllocateIconGWorld(); if (!gIconUserItem) gIconUserItem = NewUserItemProc(IconUserItem); SetItemHandle(gPrefsDialog, kPrefsIconUser, (Handle)gIconUserItem); EnableItem(GetMHandle(kFileNum), 2); SetUpForDragging(); StopEditing(); UpdateSelection(); UpdateButtons(); SetCtlValue((ControlHandle)GetItemHandle(gPrefsDialog, kPrefsTrashMenu), (*gPrefs)->trashSource + 1); } } } void InitPrefsList(void) { Rect itemRect, listRect = { 0, 0, 0, 1 }; Handle itemHandle; Point cellSize; short itemType; GetDItem(gPrefsDialog, kPrefsListUser, &itemType, &itemHandle, &itemRect); itemRect.right -= 16; cellSize.v = 32 + 2; cellSize.h = itemRect.right - itemRect.left; gPrefsList = LNew(&itemRect, &listRect, cellSize, 128, gPrefsDialog, false, false, false, true); if (gPrefsList) { int count = *(short *)*gMapResource, offset = 0; Cell theCell = { 0, 0 }; (*gPrefsList)->selFlags = lOnlyOne + lNoNilHilite; LAddRow(count, 32767, gPrefsList); offset += 2; while (count--) { char data[16]; BlockMove(*gMapResource + offset, data, 16); LSetCell(data, 16, theCell, gPrefsList); theCell.v++; offset += 16; } } if (!gListUserItem) gListUserItem = NewUserItemProc(ListUserItem); SetItemHandle(gPrefsDialog, kPrefsListUser, (Handle)gListUserItem); LDoDraw(true, gPrefsList); } void AllocateIconGWorld(void) { short depth; if (((CGrafPtr)gPrefsDialog)->portVersion & 0xc000) { GDHandle mostDevice; GrafPtr oldPort; Rect globalRect; GetPort(&oldPort); SetPort(gPrefsDialog); globalRect = gPrefsDialog->portRect; LocalToGlobal((Point *)&globalRect.top); LocalToGlobal((Point *)&globalRect.bottom); mostDevice = GetMaxDevice(&globalRect); depth = (*(*mo