home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
HyperLib 1997 Winter - Disc 1
/
HYPERLIB-1997-Winter-CD1.ISO.7z
/
HYPERLIB-1997-Winter-CD1.ISO
/
オンラインウェア
/
PRG
/
AESample.sit
/
AESample
/
sources
/
sample.dlog.c
< prev
next >
Wrap
Text File
|
1996-06-22
|
13KB
|
497 lines
/*
*--------------------------------------------------------------
* sample.dlog.c
*--------------------------------------------------------------
*/
#include <Palettes.h>
#include "sample.h"
#include "sample.menu.h"
#include "sample.subs.h"
#include "sample.send.h"
#include "sample.dlog.h"
#include "custom.wind.h"
#include "EmbossDraw.h"
/* command values */
enum constFillCommand {
kClearIt,
kFillIt
};
/* global dialog poiter for file view */
DialogRef gViewDialog;
/* custom event filter for modal dialog */
/*
*--------------------------------------------------------------
* type definitions for custom drawing routine
*--------------------------------------------------------------
*/
typedef struct {
RectPtr frame;
short active;
} DrawPrmRec, *DrawPrmPtr;
/*
*--------------------------------------------------------------
* static functions only used within this source
*--------------------------------------------------------------
*/
static Boolean SetUpMyViewDialog(void);
static void SetUpMyViewContents(Boolean);
static Boolean HiliteMyButton(DialogRef, const short);
static pascal void DrawEachBoldButton(short, short, GDHandle, long);
static void DrawDeepBoldButton(DrawPrmPtr, GDHandle);
static void DrawBMapBoldButton(DrawPrmPtr);
/*
*--------------------------------------------------------------
* static UPPs
*--------------------------------------------------------------
*/
static DeviceLoopDrawingUPP gBoldLoopUPP = nil;
/*
*--------------------------------------------------------------
* SetUpMyDialogs
*--------------------------------------------------------------
* setup dialogs
*--------------------------------------------------------------
*/
Boolean SetUpMyDialogs(void)
{
/*
setup other dialogs
*/
/* install button frame UPP */
gBoldLoopUPP = NewDeviceLoopDrawingProc(DrawEachBoldButton);
if (gBoldLoopUPP &&
SetUpMyViewDialog()
) return (true);
return (false);
}
/*
*--------------------------------------------------------------
* DoDialogs
*--------------------------------------------------------------
* handle modeless dialog events here
*--------------------------------------------------------------
*/
void DoDialogs(EventRecord *theEvent)
{
DialogRef aDialog;
short itemHit = -1;
switch (theEvent->what) {
case keyDown:
case autoKey:
aDialog = FrontWindow();
DoModelessDlgKeyDown(theEvent, &itemHit);
break;
case activateEvt:
aDialog = (DialogRef)theEvent->message;
if (aDialog == gViewDialog) {
FrameBoldButton(gViewDialog, ok);
}
break;
case updateEvt:
aDialog = (DialogRef)theEvent->message;
if (aDialog == gViewDialog) {
FrameBoldButton(gViewDialog, ok);
RaisedWindow(GetDialogWindow(gViewDialog));
}
break;
case osEvt:
DoOSEvent(theEvent);
break;
case diskEvt:
DoMountDisk(theEvent);
break;
}
/* StdFilterProc supports Button bolding */
if (DialogSelect(theEvent, &aDialog, &itemHit)) {
if (aDialog == gViewDialog) {
DoMyViewDialog(itemHit);
}
/*
handle other dialog events
*/
}
}
/*
*--------------------------------------------------------------
* DoModelessDlgKeyDown
*--------------------------------------------------------------
* handle modeless dialog key events
*--------------------------------------------------------------
*/
void DoModelessDlgKeyDown(EventRecord * theEvent, short *itemHit)
{
DialogRef aDialog = FrontWindow();
char charCode = theEvent->message & charCodeMask;
if (theEvent->modifiers & cmdKey) {
if (charCode == '.') {
*itemHit = cancel;
} else {
DoMenus(MenuKey(charCode));
}
} else {
switch (charCode) {
case kEnterKey:
case kReturnKey: *itemHit = ok; break;
case kDeleteKey:
case kEscapeKey: *itemHit = cancel; break;
}
}
if (*itemHit >= ok) {
if ((aDialog == gViewDialog) && (*itemHit >= diGetNew)) {
HiliteMyButton(aDialog, *itemHit);
} else {
HiliteMyButton(aDialog, *itemHit);
}
}
}
/*
*--------------------------------------------------------------
* SetUpMyViewDialog
*--------------------------------------------------------------
* setup file view modeless dialog
*--------------------------------------------------------------
*/
static Boolean SetUpMyViewDialog(void)
{
gViewDialog = GetNewDialog(dlogViewID, kInHeap, kFrontMost);
if (gViewDialog != nil) {
/* set dialog user item procedure */
SetDialogUserItemUPP(gViewDialog, diInfoRect, GrooveItemUPP);
return (true);
}
return (false);
}
/*
*--------------------------------------------------------------
* OpenMyViewDialog
*--------------------------------------------------------------
* show file view modeless dialog
*--------------------------------------------------------------
*/
void OpenMyViewDialog(const FSSpecPtr theSpec)
{
/* replace with the newly given spec */
gDocSpec = *theSpec;
/* setup dialog elements */
SetUpMyViewContents(kFillIt);
if (IsWindowVisible(gViewDialog) == false) {
ShowWindow(gViewDialog);
}
if (FrontWindow() != gViewDialog) {
SelectWindow(gViewDialog);
}
}
/*
*--------------------------------------------------------------
* DoMyViewDialog
*--------------------------------------------------------------
* handle file view modeless dialog events
*--------------------------------------------------------------
*/
void DoMyViewDialog(const short theItem)
{
switch (theItem) {
case diSendIt:
DoSendFile();
break;
case diClearIt:
SetUpMyViewContents(kClearIt);
break;
case diGetNew:
DoHoldFile();
break;
}
}
/*
*--------------------------------------------------------------
* SetUpMyViewContents
*--------------------------------------------------------------
* set contents of the view dialog
*--------------------------------------------------------------
*/
static void SetUpMyViewContents(Boolean theCommand)
{
FInfo itsFInfo;
Rect iRect;
Handle iHndl;
short iType;
Str15 vRefNStr, dirIDStr;
Str15 creatStr, fTypeStr;
if ((theCommand == kFillIt) &&
(FSpGetFInfo(&gDocSpec, &itsFInfo) == noErr)) {
/* set the new document info */
NumToString(gDocSpec.vRefNum, vRefNStr);
NumToString(gDocSpec.parID, dirIDStr);
creatStr[0] = (char)sizeof(OSType);
BlockMoveData(&itsFInfo.fdCreator, &creatStr[1], sizeof(OSType));
fTypeStr[0] = (char)sizeof(OSType);
BlockMoveData(&itsFInfo.fdType, &fTypeStr[1], sizeof(OSType));
/* activate buttons */
GetDialogItem(gViewDialog, diSendIt, &iType, &iHndl, &iRect);
HiliteControl((ControlRef)iHndl, 0);
GetDialogItem(gViewDialog, diClearIt, &iType, &iHndl, &iRect);
HiliteControl((ControlRef)iHndl, 0);
} else {
/* clear the current document info */
gDocSpec.name[0] = 0;
vRefNStr[0] = dirIDStr[0] = 0;
creatStr[0] = fTypeStr[0] = 0;
/* inactivate buttons */
GetDialogItem(gViewDialog, diSendIt, &iType, &iHndl, &iRect);
HiliteControl((ControlRef)iHndl, 255);
GetDialogItem(gViewDialog, diClearIt, &iType, &iHndl, &iRect);
HiliteControl((ControlRef)iHndl, 255);
}
/* set the info strings */
GetDialogItem(gViewDialog, diFileName, &iType, &iHndl, &iRect);
SetDialogItemText(iHndl, gDocSpec.name);
GetDialogItem(gViewDialog, diVRefNum, &iType, &iHndl, &iRect);
SetDialogItemText(iHndl, vRefNStr);
GetDialogItem(gViewDialog, diParentID, &iType, &iHndl, &iRect);
SetDialogItemText(iHndl, dirIDStr);
GetDialogItem(gViewDialog, diCreator, &iType, &iHndl, &iRect);
SetDialogItemText(iHndl, creatStr);
GetDialogItem(gViewDialog, diFileType, &iType, &iHndl, &iRect);
SetDialogItemText(iHndl, fTypeStr);
/* redraw button frame according to the button status */
FrameBoldButton(gViewDialog, ok);
}
/*
*--------------------------------------------------------------
* DoAboutMe
*--------------------------------------------------------------
* show about dialog
*--------------------------------------------------------------
*/
void DoAboutMe(void)
{
DialogRef aboutDialog = GetNewDialog(dlogAboutID, kInHeap, kFrontMost);
if (aboutDialog != nil) {
WindowRef thisWindow = GetDialogWindow(aboutDialog);
GrafPtr savePort;
short itemHit;
GetPort(&savePort);
SetPortWindowPort(thisWindow);
{ /* set the font, size and mode */
Str15 fntName;
short fntNum;
GetIndString(fntName, rFontNameID, iGenevaIndex);
GetFNum(fntName, &fntNum);
TextFont(fntNum);
TextSize(9);
TextMode(srcCopy);
}
ShowWindow(thisWindow);
SelectWindow(thisWindow);
RaisedWindow(thisWindow);
do {
ModalDialog(nil, &itemHit);
} while (itemHit > aboutWholeArea);
if (StillDown()) {
while (WaitMyMouseUp()) {
/* do nothing */
}
}
SetPort(savePort);
DisposeDialog(aboutDialog);
}
}
/*
*--------------------------------------------------------------
* HiliteMyButton
*--------------------------------------------------------------
* auto press button proc
*--------------------------------------------------------------
*/
static Boolean HiliteMyButton(DialogRef theDialog, const short theItem)
{
ControlRef aButton;
Rect iRect;
short iType;
GetDialogItem(theDialog, theItem, &iType, (Handle *)&aButton, &iRect);
if (iType < kStaticTextDialogItem) {
long endTick;
HiliteControl(aButton, inButton);
Delay(8, &endTick);
HiliteControl(aButton, 0);
return (true);
}
return (false);
}
/*
*--------------------------------------------------------------
* FrameBoldButton
*--------------------------------------------------------------
* frame bold round rect to default button
*--------------------------------------------------------------
*/
void FrameBoldButton(DialogRef theDialog, const short theItem)
{
#if !__powerpc
long oldA5 = SetA5(SetCurrentA5());
#endif
Rect bttnRect;
ControlRef aButton;
short aType;
/* get button's rectangle */
GetDialogItem(theDialog, theItem, &aType, (Handle *)&aButton, &bttnRect);
if ((aType == kButtonDialogItem) || (aType == kResourceControlDialogItem)) {
GrafPtr savedPort;
PenState saveState;
RgnHandle bttnRgn = NewRgn();
RgnHandle clipRgn = NewRgn();
/* set graphic port and pen */
GetPort(&savedPort);
SetGrafPortOfDialog(theDialog);
GetPenState(&saveState);
PenSize(3, 3);
/* set the drawing data record and call device loop */
InsetRect(&bttnRect, -4, -4);
RectRgn(bttnRgn, &bttnRect);
GetClip(clipRgn);
SectRgn(bttnRgn, clipRgn, bttnRgn);
/* draw the button */
if (EmptyRgn(bttnRgn) == false) {
DrawPrmRec drawData;
long gestaltAnswer;
OSErr result;
drawData.frame = &bttnRect;
drawData.active = (
(gNowBackGround == false) &&
(FrontWindow() == GetDialogWindow(theDialog)) &&
((*aButton)->contrlHilite != kControlInactivePart)
);
result = Gestalt(gestaltQuickdrawVersion, &gestaltAnswer);
if ((result == noErr) && (gestaltAnswer >= gestalt8BitQD)) {
/* call device loop to draw all devices in which the frame resides */
DeviceLoop(bttnRgn, gBoldLoopUPP, (long)&drawData, 0);
} else {
DrawBMapBoldButton(&drawData);
}
}
DisposeRgn(bttnRgn);
DisposeRgn(clipRgn);
SetPenState(&saveState);
SetPort(savedPort);
}
#if !__powerpc
(void)SetA5(oldA5);
#endif
}
/*
*--------------------------------------------------------------
* DrawEachBoldButton
*--------------------------------------------------------------
* bold frame drawing device loop callback
*--------------------------------------------------------------
*/
static pascal void DrawEachBoldButton(
short howDeep,
short theFlag,
GDHandle theDevice,
long userData)
{
#pragma unused (theFlag)
DrawPrmPtr drawParam = (DrawPrmPtr)userData;
if (howDeep > 1) {
DrawDeepBoldButton(drawParam, theDevice);
} else {
DrawBMapBoldButton(drawParam);
}
}
/*
*--------------------------------------------------------------
* DrawDeepBoldButton
*--------------------------------------------------------------
* bold rectangle drawing routine on the deep device
*--------------------------------------------------------------
*/
static void DrawDeepBoldButton(DrawPrmPtr theParam, GDHandle theDevice)
{
RGBColor foreColor, backColor, grayColor, boldColor;
GetForeColor(&foreColor);
GetBackColor(&backColor);
grayColor = foreColor;
if (GetGray(theDevice, &backColor, &grayColor)) {
if (theParam->active) {
boldColor.red = boldColor.green = 0;
boldColor.blue = 0x1111;
RGBForeColor(&boldColor);
} else {
RGBForeColor(&grayColor);
}
FrameRoundRect(theParam->frame, 16, 16);
RGBForeColor(&foreColor);
} else {
DrawBMapBoldButton(theParam);
}
}
/*
*--------------------------------------------------------------
* DrawBMapBoldButton
*--------------------------------------------------------------
* bold rectangle drawing routine on the bitmap device
*--------------------------------------------------------------
*/
static void DrawBMapBoldButton(DrawPrmPtr theParam)
{
long boldPat[2];
boldPat[0] = boldPat[1] = (theParam->active) ? 0xFFFFFFFF : 0xAA55AA55;
PenPat((PatPtr)boldPat);
FrameRoundRect(theParam->frame, 16, 16);
}