home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.mactech.com 2010
/
ftp.mactech.com.tar
/
ftp.mactech.com
/
machack
/
Hacks96
/
FontMancer.sit
/
FontMancer
/
Common
/
StandardEvent.c
< prev
next >
Wrap
C/C++ Source or Header
|
1996-06-21
|
7KB
|
320 lines
#include "FontMancer.h"
#include "FontDisplay.h"
#include "Standard.h"
#include "StandardEvent.h"
#include "StandardMenu.h"
#include "Display.h"
#include "AEHandler.h"
extern Boolean gInBackground;
extern Boolean gQuit;
extern Boolean gDManager;
extern WindowPtr gMainWindow;
extern long gLastKeyTime;
extern Str255 gListNavString;
void CtlHandleToItem(ControlHandle ctlHandle, short *itemHit)
{
FMStuff *FMStore;
ControlHandle checkHandle;
FMStore = (FMStuff *) GetWRefCon(gMainWindow);
*itemHit = 0;
checkHandle = FMStore->ctlHandles[*itemHit];
while ((ctlHandle != checkHandle) & (*itemHit <= iSizePopUp)) {
(*itemHit)++;
checkHandle = FMStore->ctlHandles[*itemHit];
}
if (*itemHit > iSizePopUp)
*itemHit = -1;
}
short PlainButtonCheck(ControlHandle ctlHandle)
{
FMStuff *FMStore;
FMStore = (FMStuff *) GetWRefCon(gMainWindow);
if (ctlHandle == FMStore->ctlHandles[iPlainButton])
return(GetControlValue(ctlHandle));
else
return(0);
}
void ActivateControls(short activate)
{
FMStuff *FMStore;
short hiliteCode,loop;
FMStore = (FMStuff *) GetWRefCon(gMainWindow);
hiliteCode = activate ? 0 : 255;
for (loop=iPlainButton; loop <=iSizePopUp; loop++)
HiliteControl(FMStore->ctlHandles[loop],hiliteCode);
}
void DoContentClick(EventRecord *event)
{
Point cursorLoc;
WindowPtr theWindow = FrontWindow();
FMStuff *FMStore;
SetPt(&cursorLoc,event->where.h,event->where.v);
GlobalToLocal(&cursorLoc);
FMStore = (FMStuff *) GetWRefCon(theWindow);
if (PtInRect(cursorLoc,&(FMStore->itemRects[iButtonRect])))
DoButtonClick(event);
if (PtInRect(cursorLoc,&(FMStore->itemRects[iListRect])))
HandleListSelect(event);
}
void DoButtonClick(EventRecord *event)
{
ControlHandle ctlHandle;
Point cursorLoc;
short itemHit;
SetPt(&cursorLoc,event->where.h,event->where.v);
GlobalToLocal(&cursorLoc);
if (!(FindControl(cursorLoc,gMainWindow,&ctlHandle))) return;
if (PlainButtonCheck(ctlHandle)) return;
if (TrackControl(ctlHandle,cursorLoc,(ControlActionUPP) -1L)) {
CtlHandleToItem(ctlHandle,&itemHit);
switch (itemHit) {
case iPlainButton:
SetPlainDisplay();
break;
case iBoldButton:
SetBoldDisplay();
break;
case iItalicButton:
SetItalicDisplay();
break;
case iUnderlineButton:
SetUnderlineDisplay();
break;
case iOutlineButton:
SetOutlineDisplay();
break;
case iShadowButton:
SetShadowDisplay();
break;
case iSizePopUp:
HandleSizePopUp();
break;
};
}
}
void DoKeyPress(EventRecord *event)
{
FMStuff *FMStore;
Point newCell,oldCell = {0,0};
Rect cellRect,ignoreRect;
ListHandle theList;
FMStore = (FMStuff *) GetWRefCon(gMainWindow);
theList = FMStore->fontList;
HLock((Handle) theList);
LGetSelect(TRUE,&oldCell,theList);
SetPt(&newCell,oldCell.h,oldCell.v);
GetNewCell(event,FMStore->fontList, &newCell);
LSetSelect(FALSE,oldCell,theList);
LSetSelect(TRUE,newCell,theList);
LRect(&cellRect,newCell,theList);
LAutoScroll(theList);
HUnlock((Handle) theList);
SetDisplayFont(newCell,FMStore);
UpdateSampleRect(FMStore);
}
void GetNewCell(EventRecord *event, ListHandle theList, Point *cell)
{
short listRows;
char key;
key = event->message & charCodeMask;
if (!gLastKeyTime)
gLastKeyTime = event->when;
listRows = ((**theList).dataBounds.bottom - (**theList).dataBounds.top) - 1;
switch(key) {
case kUpArrow:
if (cell->v)
cell->v -= 1;
break;
case kDownArrow:
if (cell->v != listRows)
cell->v += 1;
break;
case kPageUp:
cell->v -= 5;
if (cell->v < 0)
cell->v = 0;
break;
case kPageDown:
cell->v += 5;
if (cell->v > listRows)
cell->v = listRows;
break;
case kHome:
cell->v = 0;
break;
case kEnd:
cell->v = listRows;
break;
default:
if (event->when - gLastKeyTime >= 120)
gListNavString[0] = 0;
gLastKeyTime = event->when;
if (gListNavString[0] < 255)
gListNavString[++gListNavString[0]] = key;
SetPt(cell,0,0);
LSearch(&gListNavString[1],gListNavString[0],NewListSearchProc(CustomListSearch),cell,theList);
if (cell->v > listRows)
cell->v = listRows;
break;
}
}
pascal short CustomListSearch(char *cellData, char *testData, short cellLen, short testLen)
{
short result, index;
char cellChar, testChar;
result = index = 0;
while ((index < testLen) && !result) {
cellChar = cellData[index];
testChar = testData[index];
if (cellChar >= 'a' && cellChar <='z')
cellChar -= 0x20;
if (testChar >= 'a' && testChar <='z')
testChar -= 0x20;
if ((cellChar != testChar) && (cellChar < testChar))
result = 1;
if ((index == 0) && (cellChar > testChar))
break;
index++;
}
return(result);
}
void HandleEvent(EventRecord *event)
{
switch(event->what) {
case mouseDown:
HandleMouseDown(event);
break;
case keyDown:
case autoKey:
HandleKeyPress(event);
break;
case diskEvt:
HandleDiskInsert(event);
break;
case osEvt:
HandleOSEvent(event);
break;
case updateEvt:
HandleUpdate(event);
break;
case kHighLevelEvent:
AEProcessAppleEvent(event);
break;
}
}
void HandleDiskInsert(EventRecord *event)
{
Point aPoint = {100, 100};
if (HiWrd(event->message) != noErr)
(void) DIBadMount(aPoint,event->message);
}
void HandleKeyPress(EventRecord *event)
{
char key;
key = event->message & charCodeMask;
if (event->modifiers & cmdKey)
HandleMenuCommand(MenuKey(key));
else
DoKeyPress(event);
}
void HandleMouseDown(EventRecord *event)
{
WindowPtr theWindow;
short part = FindWindow(event->where, &theWindow);
switch (part) {
case inMenuBar:
HandleMenuCommand(MenuSelect(event->where));
break;
case inSysWindow:
SystemClick(event,theWindow);
break;
case inContent:
if (theWindow != FrontWindow())
SelectWindow(theWindow);
else
DoContentClick(event);
break;
case inDrag:
DragWindow(theWindow,event->where,&qd.screenBits.bounds);
break;
}
}
void HandleOSEvent(EventRecord *event)
{
switch ((event->message >> 24) & 0x0FF) {
case suspendResumeMessage:
gInBackground = (event->message & resumeFlag) == 0;
DoActivateMainWindow();
break;
}
}
void DoActivateMainWindow()
{
WindowPtr OldPort;
FMStuff *FMStore;
FMStore = (FMStuff *) GetWRefCon(gMainWindow);
GetPort(&OldPort);
SetPort(gMainWindow);
if (gInBackground) {
ActivateControls(FALSE);
LActivate(FALSE,FMStore->fontList);
}
else {
SelectWindow(gMainWindow);
ActivateControls(TRUE);
LActivate(TRUE,FMStore->fontList);
}
SetPort(OldPort);
}
void HandleUpdate(EventRecord *event)
{
WindowPtr theWindow = (WindowPtr) event->message;
WindowPtr oldPort;
FMStuff *FMStore;
GetPort(&oldPort);
SetPort(theWindow);
FMStore = (FMStuff *) GetWRefCon(theWindow);
BeginUpdate(theWindow);
UpdateFontList(theWindow);
UpdateControls(theWindow,theWindow->visRgn);
UpdateMisc(theWindow);
EndUpdate(theWindow);
SetPort(oldPort);
}