Antoine Vignau fae5db3afd scsi-2 powa!
2024-08-15 21:27:35 +02:00

1 line
6.6 KiB
C

/***********************************************************************
*
* Menu.c
*
* Copyright (c)
* Apple Computer, Inc. 1986-1989
* All Rights Reserved.
*
* This file contains the code which implements
* menus in the scanner program.
*
***********************************************************************/
#include <control.h>
#include <types.h>
#include <quickdraw.h>
#include <qdaux.h>
#include <window.h>
#include <event.h>
#include <menu.h>
#include <desk.h>
#include <intmath.h>
#include <stdfile.h>
#include <gsos.h>
#include <memory.h>
#include <malloc.h>
#include "Scan.h"
extern WmTaskRec event;
extern unsigned int quitFlag;
extern GrafPortPtr previewWindow;
extern GrafPortPtr settingsWindowPtr;
extern GrafPortPtr openThisWindow();
SFReplyRec2 MyReply;
extern void doCloseTop();
void doQuitItem();
void doAboutBox();
void doOpenItem();
void doSaveItem();
void doSaveAsItem();
void doPrefItem();
void doSettingsItem();
void doPreviewItem();
/* array of procedure address to handle menu selections */
void (*menuProc[])() = {
doAboutBox, /* for Undo */
doAboutBox, /* for Cut */
doAboutBox, /* for Copy */
doAboutBox, /* for Paste */
doAboutBox, /* for Clear */
doCloseTop, /* for Close */
doAboutBox, /* for About (really!) */
doOpenItem, /* for Open */
doSaveItem, /* for Save */
doSaveAsItem, /* for Save As */
doPrefItem, /* for Preferences */
doAboutBox, /* for Print */
doQuitItem, /* for Quit */
doSettingsItem, /* for Settings (in Scan menu) */
doPreviewItem /* for Preview (in Scan Menu) */
};
/**********************************************************************/
void doQuitItem()
{
quitFlag++;
}
/**********************************************************************/
void doAboutBox()
{
AlertWindow(4, NULL, (long) AboutBox);
}
/**********************************************************************/
void doOpenItem()
{
AlertWindow(4, NULL, (long) AboutBox);
}
/**********************************************************************/
/**********************************************************************/
void doSaveItem()
{
AlertWindow(4, NULL, (long) AboutBox);
}
/**********************************************************************/
/**********************************************************************/
void doSaveAsItem()
{
extern int SavePic();
LocInfoHndl AuxHandle;
LocInfoPtr RefPtr;
ResultBuf255Ptr filename;
GrafPortPtr WhichWindow;
GSString255Ptr oldfilename;
char *windowName, **nameHndl;
int i, error;
RefPtr = (LocInfoPtr) GetWRefCon((WhichWindow = FrontWindow()));
nameHndl = (char **) GetWTitle(WhichWindow); /* get the current window title */
if((unsigned long) nameHndl & 0x80000000) { /* returned as a handle? */
windowName = *nameHndl; /* yes, dereference it */
nameHndl = NULL; /* then clear it so we don't dispose of it later */
} else
windowName = (char *) nameHndl; /* else must be a real pointer */
oldfilename = (GSString255Ptr) malloc(*windowName+2); /* convert to GSOS string */
memcpy(oldfilename->text, windowName+2, (oldfilename->length = *windowName-2));
MyReply.nameDesc = MyReply.nameDesc = 3; /* let StdFile allocate the memory for the names */
SFPutFile2 (25,30,
0,"\pSave picture as:",
0, oldfilename,
&MyReply);
if (MyReply.good) { /* <> 0 --> OK to save it */
filename = (ResultBuf255Ptr) *((ResultBuf255Ptr *) MyReply.pathRef);
if(error = /* assignment */ SavePic(&(filename->bufString), RefPtr)) /* save the picture */
ErrorWindow(0,NULL,error);
else {
filename = * ((ResultBuf255Ptr *) MyReply.nameRef); /* get pointer to filename result */
windowName = malloc((i = filename->bufString.length)+3); /* get the buffer */
windowName[0] = i + 2; /* set the new length (pascal string) */
memcpy(windowName+2,filename->bufString.text,i); /* copy the new name in */
windowName[1] = windowName[i+2] = ' ';
SetWTitle(windowName,WhichWindow); /* change the window name */
if(nameHndl) /* if name was returned as a pointer... */
free(nameHndl); /* then dispose of the old name */
}
}
DisposeHandle(MyReply.nameRef);
DisposeHandle(MyReply.pathRef);
free(oldfilename);
}
/**********************************************************************/
void doPrefItem()
{
AlertWindow(4, NULL, (long) AboutBox);
}
/**********************************************************************/
void doSettingsItem()
{
Pointer theArrayList[1];
static char subString[] = {"0000"};
CtlRecHndl ctlHandle;
extern void scrollAction();
extern int scanDevnum;
if(settingsWindowPtr == NULL) {
settingsWindowPtr = openThisWindow(SettingsWindow);
if(!scanDevnum) { /* if a scanner wasn't found during initialization */
HiliteControl(inactiveHilite, GetCtlHandleFromID(settingsWindowPtr,ScanButton)); /* disable the buttons */
HiliteControl(inactiveHilite, GetCtlHandleFromID(settingsWindowPtr,PreviewButton));
}
EnableMItem(CloseID);
SetCtlAction(scrollAction,GetCtlHandleFromID(NULL,BrightnessScroll));
SetCtlAction(scrollAction,GetCtlHandleFromID(NULL,ContrastScroll));
SetCtlAction(scrollAction,GetCtlHandleFromID(NULL,ThresholdScroll));
} else
SelectWindow(settingsWindowPtr);
}
/**********************************************************************/
void doPreviewItem()
{
openPreview();
}
/**********************************************************************/
void doMenu()
{
unsigned int menuNum, itemNum;
unsigned int *intPtr;
/* Procedure to handle all menu selections. Examines the event.TaskData
** menu item ID word from TaskMaster (from Event Manager) and calls the
** appropriate routine. While the routine is running the menu title is
** still highlighted. After the routine returns, we unhilight the
** menu title.
*/
intPtr = (unsigned *) &(event.wmTaskData);
menuNum = intPtr[1]; /* get high word of TaskData */
/* menuNum = HiWord(event.wmTaskData);
itemNum = LoWord(event.wmTaskData);*/
(*menuProc[*intPtr-250])(); /* call the menu handler */
HiliteMenu(0, menuNum); /* Unhighlight the menu title. */
}
/**********************************************************************/
void setupMenus()
{
/* Procedure to install our menu titles and their items in the system menu
** bar and to redraw it so we can see them.
*/
SetSysBar(NewMenuBar2(refIsResource, 0x0001L, NULL));
SetMenuBar(NULL);
FixAppleMenu(AppleMenuID); /* Add DAs to apple menu */
FixMenuBar(); /* Set sizes of menus */
DrawMenuBar(); /* ...and draw the menu bar! */
}